-
-
Notifications
You must be signed in to change notification settings - Fork 121
/
quill.js
64 lines (56 loc) · 1.79 KB
/
quill.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* eslint-env browser */
import * as Y from 'yjs'
import { WebsocketProvider } from 'y-websocket'
import { QuillBinding } from 'y-quill'
import Quill from 'quill'
import QuillCursors from 'quill-cursors'
Quill.register('modules/cursors', QuillCursors)
window.addEventListener('load', () => {
const ydoc = new Y.Doc()
const provider = new WebsocketProvider(
'wss://demos.yjs.dev/ws', // use the public ws server
// `ws${location.protocol.slice(4)}//${location.host}/ws`, // alternatively: use the local ws server (run `npm start` in root directory)
'quill-demo-2024/06',
ydoc
)
const ytext = ydoc.getText('quill')
const editorContainer = document.createElement('div')
editorContainer.setAttribute('id', 'editor')
document.body.insertBefore(editorContainer, null)
const editor = new Quill(editorContainer, {
modules: {
cursors: true,
toolbar: [
[{ header: [1, 2, false] }],
['bold', 'italic', 'underline'],
['image', 'code-block']
],
history: {
userOnly: true
}
},
placeholder: 'Start collaborating...',
theme: 'snow' // or 'bubble'
})
const binding = new QuillBinding(ytext, editor, provider.awareness)
/*
// Define user name and user name
// Check the quill-cursors package on how to change the way cursors are rendered
provider.awareness.setLocalStateField('user', {
name: 'Typing Jimmy',
color: 'blue'
})
*/
const connectBtn = document.getElementById('y-connect-btn')
connectBtn.addEventListener('click', () => {
if (provider.shouldConnect) {
provider.disconnect()
connectBtn.textContent = 'Connect'
} else {
provider.connect()
connectBtn.textContent = 'Disconnect'
}
})
// @ts-ignore
window.example = { provider, ydoc, ytext, binding, Y }
})