先安装相关的组件
npm i yjs y-websocket y-quill quill quill-cursors我们通过y-websocket来搭建一个用户协同的数据交换服务器,启动命令
PORT=1234 node ./node_modules/y-websocket/bin/server.cjs
前端html代码
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet"> <div id="editor" />前端js代码
import Quill from 'quill'
import QuillCursors from 'quill-cursors'
import * as Y from 'yjs'
import { QuillBinding } from 'y-quill'
import { WebsocketProvider } from 'y-websocket'
Quill.register('modules/cursors', QuillCursors);
const quill = new Quill(document.querySelector('#editor'), {
modules: {
cursors: true,
toolbar: [
// adding some basic Quill content features
[{ header: [1, 2, false] }],
['bold', 'italic', 'underline'],
['image', 'code-block']
],
history: {
// Local undo shouldn't undo changes
// from remote users
userOnly: true
}
},
placeholder: 'Start collaborating...',
theme: 'snow' // 'bubble' is also great
})
// A Yjs document holds the shared data
const ydoc = new Y.Doc()
// Define a shared text type on the document
const ytext = ydoc.getText('quill')
// Create an editor-binding which
// "binds" the quill editor to a Y.Text type.
const binding = new QuillBinding(ytext, quill)
// connect to the public demo server (not in production!)
const provider = new WebsocketProvider(
'wss://demos.yjs.dev:1234', 'quill-demo-room', ydoc
)
最终效果

详细官方教程:https://docs.yjs.dev/getting-started/a-collaborative-editor
网友回复
claude mythos这么厉害为啥不公开发布给所有人使用?
linux stream如何限制单个目录最大容量?
哪有免费的千问qwen3.6-plus的api可以使用?
python如何自动根据视频图片等素材自动按照要求剪辑视频生成剪映草稿?
gemma4与开源的qwen3.5哪个更厉害?
wan2.7 video与seedance2哪个更好?
claude code 51万行代码泄露被迫开源在哪能找到源码?
有没有免费的虚拟局域网工具可以将互联网设备组成一个大的局域网?
全球顶尖大模型这么强,为啥AGI 测试集体溃败 人类满分 AI 最高仅 0.37%?
听说字节seedance3的视频生成长度可达到10分钟?


