editable icon indicating copy to clipboard operation
editable copied to clipboard

使用yjs开启协同之后,如何将自定义的数据渲染到编辑器中,开启协同的时候好像编辑器重置了,该如何自定义内容

Open Jedi1820 opened this issue 2 years ago • 8 comments

Jedi1820 avatar Jan 22 '24 01:01 Jedi1820

  1. 可以从服务端初始化内容
  2. 连接后,可以使用api清楚掉编辑内的所有内容,然后再插入你要的内容,这样就修改了服务端,其它客户端也会同步到对应的内容

big-camel avatar Jan 22 '24 01:01 big-camel

你指的是server端的startServer这个方法吗,这个方法需要提前内置内容才可以吧,我想实现的在编辑器开启协同之后,通过外部接口或者其他地方获取的数据渲染到编辑器中,如果使用服务端的方法,该如何动态传递给他 @big-camel

Jedi1820 avatar Jan 22 '24 01:01 Jedi1820

api清除掉编辑内的所有内容,然后再插入内容,这个该如何操作 @big-camel

Jedi1820 avatar Jan 22 '24 01:01 Jedi1820

import startServer from '@editablejs/yjs-websocket/server'

startServer({
  initialValue: {
    children: [
      // 启用标题插件下的默认值
      {
        type: 'title',
        children: [{ text: '' }],
      },
      {
        type: 'paragraph',
        children: [{ text: '' }],
      },
    ],
  },
})

你可以看下api或者源代码

big-camel avatar Jan 22 '24 01:01 big-camel

这一段看到了,这一段是在服务端的😂,没找到在编辑器段可以直接修改的api

Jedi1820 avatar Jan 22 '24 02:01 Jedi1820

先设置 selection 为全选,可以调用删除相关的api(deleteForward deleteBackward) 或者 insertFragment 插入新的

big-camel avatar Jan 22 '24 02:01 big-camel

如何主动获取到协同编辑的所有协作者的信息,有api可以使用吗

Jedi1820 avatar Jan 22 '24 05:01 Jedi1820

const remoteClients = useRemoteStates<CursorData>(editor)

big-camel avatar Jan 22 '24 05:01 big-camel