-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathindex.jsx
52 lines (45 loc) · 1.56 KB
/
index.jsx
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
import React from "react"
import { createRoot } from "react-dom/client"
import { EditorState } from "prosemirror-state"
import { ProseMirror, ProseMirrorDoc, reactKeys } from "@handlewithcare/react-prosemirror"
import { exampleSetup } from 'prosemirror-example-setup'
import { schema } from "prosemirror-schema-basic"
import {keymap} from "prosemirror-keymap"
import {baseKeymap} from "prosemirror-commands"
import * as Y from 'yjs'
import { WebsocketProvider } from 'y-websocket'
import { ySyncPlugin, yCursorPlugin, yUndoPlugin, undo, redo, initProseMirrorDoc } from 'y-prosemirror'
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)
'prosemirror-demo-2024/06',
ydoc
)
function App () {
const yXmlFragment = ydoc.getXmlFragment('prosemirror')
const { doc, mapping } = initProseMirrorDoc(yXmlFragment, schema)
const defaultState = EditorState.create({
doc,
schema,
plugins: [
ySyncPlugin(yXmlFragment, { mapping }),
yCursorPlugin(provider.awareness),
yUndoPlugin(),
keymap({
'Mod-z': undo,
'Mod-y': redo,
'Mod-Shift-z': redo
}),
keymap(baseKeymap),
reactKeys(),
].concat(exampleSetup({ schema }))
});
return (
<ProseMirror defaultState={defaultState}>
<ProseMirrorDoc />
</ProseMirror>
);
}
const root = createRoot(document.getElementById('root'))
root.render(<App />)