Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Jedi1820 opened this issue Jan 22, 2024 · 8 comments
Assignees
Labels

Comments

@Jedi1820
Copy link

No description provided.

@big-camel
Copy link
Member

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

@Jedi1820
Copy link
Author

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

@Jedi1820
Copy link
Author

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

@big-camel
Copy link
Member

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

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

你可以看下api或者源代码

@Jedi1820
Copy link
Author

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

@big-camel
Copy link
Member

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

@Jedi1820
Copy link
Author

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

@big-camel
Copy link
Member

const remoteClients = useRemoteStates<CursorData>(editor)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants