@axure/y-prosemirror 1.3.7-fork.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +205 -0
- package/dist/src/lib.d.ts +114 -0
- package/dist/src/plugins/cursor-plugin.d.ts +17 -0
- package/dist/src/plugins/keys.d.ts +20 -0
- package/dist/src/plugins/sync-plugin.d.ts +148 -0
- package/dist/src/plugins/undo-plugin.d.ts +33 -0
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/y-prosemirror.d.ts +5 -0
- package/dist/y-prosemirror.cjs +2268 -0
- package/dist/y-prosemirror.cjs.map +1 -0
- package/package.json +89 -0
- package/src/lib.js +440 -0
- package/src/plugins/cursor-plugin.js +267 -0
- package/src/plugins/keys.js +23 -0
- package/src/plugins/sync-plugin.js +1350 -0
- package/src/plugins/undo-plugin.js +126 -0
- package/src/utils.js +20 -0
- package/src/y-prosemirror.js +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Kevin Jahns <kevin.jahns@protonmail.com>.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# y-prosemirror
|
|
2
|
+
|
|
3
|
+
> [ProseMirror](http://prosemirror.net/) Binding for [Yjs](https://github.com/yjs/yjs) - [Demo](https://demos.yjs.dev/prosemirror/prosemirror.html)
|
|
4
|
+
|
|
5
|
+
This binding maps a Y.XmlFragment to the ProseMirror state.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
* Sync ProseMirror state
|
|
10
|
+
* Shared Cursors
|
|
11
|
+
* Shared Undo / Redo (each client has its own undo-/redo-history)
|
|
12
|
+
* Successfully recovers when concurrents edit result in an invalid document schema
|
|
13
|
+
|
|
14
|
+
### Example
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import { ySyncPlugin, yCursorPlugin, yUndoPlugin, undo, redo, initProseMirrorDoc } from 'y-prosemirror'
|
|
18
|
+
import { exampleSetup } from 'prosemirror-example-setup'
|
|
19
|
+
import { keymap } from 'prosemirror-keymap'
|
|
20
|
+
..
|
|
21
|
+
|
|
22
|
+
const type = ydocument.get('prosemirror', Y.XmlFragment)
|
|
23
|
+
const { doc, mapping } = initProseMirrorDoc(type, schema)
|
|
24
|
+
|
|
25
|
+
const prosemirrorView = new EditorView(document.querySelector('#editor'), {
|
|
26
|
+
state: EditorState.create({
|
|
27
|
+
doc,
|
|
28
|
+
schema,
|
|
29
|
+
plugins: [
|
|
30
|
+
ySyncPlugin(type, { mapping }),
|
|
31
|
+
yCursorPlugin(provider.awareness),
|
|
32
|
+
yUndoPlugin(),
|
|
33
|
+
keymap({
|
|
34
|
+
'Mod-z': undo,
|
|
35
|
+
'Mod-y': redo,
|
|
36
|
+
'Mod-Shift-z': redo
|
|
37
|
+
})
|
|
38
|
+
].concat(exampleSetup({ schema }))
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Also look [here](https://github.com/yjs/yjs-demos/tree/master/prosemirror) for a working example.
|
|
44
|
+
|
|
45
|
+
#### Remote Cursors
|
|
46
|
+
|
|
47
|
+
The shared cursors depend on the Awareness instance that is exported by most providers. The [Awareness protocol](https://github.com/yjs/y-protocols#awareness-protocol) handles non-permanent data like the number of users, their user names, their cursor location, and their colors. You can change the name and color of the user like this:
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
example.binding.awareness.setLocalStateField('user', { color: '#008833', name: 'My real name' })
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
In order to render cursor information you need to embed custom CSS for the user icon. This is a template that you can use for styling cursor information.
|
|
54
|
+
|
|
55
|
+
```css
|
|
56
|
+
/* this is a rough fix for the first cursor position when the first paragraph is empty */
|
|
57
|
+
.ProseMirror > .ProseMirror-yjs-cursor:first-child {
|
|
58
|
+
margin-top: 16px;
|
|
59
|
+
}
|
|
60
|
+
.ProseMirror p:first-child, .ProseMirror h1:first-child, .ProseMirror h2:first-child, .ProseMirror h3:first-child, .ProseMirror h4:first-child, .ProseMirror h5:first-child, .ProseMirror h6:first-child {
|
|
61
|
+
margin-top: 16px
|
|
62
|
+
}
|
|
63
|
+
/* This gives the remote user caret. The colors are automatically overwritten*/
|
|
64
|
+
.ProseMirror-yjs-cursor {
|
|
65
|
+
position: relative;
|
|
66
|
+
margin-left: -1px;
|
|
67
|
+
margin-right: -1px;
|
|
68
|
+
border-left: 1px solid black;
|
|
69
|
+
border-right: 1px solid black;
|
|
70
|
+
border-color: orange;
|
|
71
|
+
word-break: normal;
|
|
72
|
+
pointer-events: none;
|
|
73
|
+
}
|
|
74
|
+
/* This renders the username above the caret */
|
|
75
|
+
.ProseMirror-yjs-cursor > div {
|
|
76
|
+
position: absolute;
|
|
77
|
+
top: -1.05em;
|
|
78
|
+
left: -1px;
|
|
79
|
+
font-size: 13px;
|
|
80
|
+
background-color: rgb(250, 129, 0);
|
|
81
|
+
font-family: serif;
|
|
82
|
+
font-style: normal;
|
|
83
|
+
font-weight: normal;
|
|
84
|
+
line-height: normal;
|
|
85
|
+
user-select: none;
|
|
86
|
+
color: white;
|
|
87
|
+
padding-left: 2px;
|
|
88
|
+
padding-right: 2px;
|
|
89
|
+
white-space: nowrap;
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
You can also overwrite the default Widget dom by specifying a cursor builder in the yCursorPlugin
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
/**
|
|
97
|
+
* This function receives the remote users "user" awareness state.
|
|
98
|
+
*/
|
|
99
|
+
export const myCursorBuilder = user => {
|
|
100
|
+
const cursor = document.createElement('span')
|
|
101
|
+
cursor.classList.add('ProseMirror-yjs-cursor')
|
|
102
|
+
cursor.setAttribute('style', `border-color: ${user.color}`)
|
|
103
|
+
const userDiv = document.createElement('div')
|
|
104
|
+
userDiv.setAttribute('style', `background-color: ${user.color}`)
|
|
105
|
+
userDiv.insertBefore(document.createTextNode(user.name), null)
|
|
106
|
+
cursor.insertBefore(userDiv, null)
|
|
107
|
+
return cursor
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const prosemirrorView = new EditorView(document.querySelector('#editor'), {
|
|
111
|
+
state: EditorState.create({
|
|
112
|
+
schema,
|
|
113
|
+
plugins: [
|
|
114
|
+
ySyncPlugin(type),
|
|
115
|
+
yCursorPlugin(provider.awareness, { cursorBuilder: myCursorBuilder }),
|
|
116
|
+
yUndoPlugin(),
|
|
117
|
+
keymap({
|
|
118
|
+
'Mod-z': undo,
|
|
119
|
+
'Mod-y': redo,
|
|
120
|
+
'Mod-Shift-z': redo
|
|
121
|
+
})
|
|
122
|
+
].concat(exampleSetup({ schema }))
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### Utilities
|
|
128
|
+
|
|
129
|
+
The package includes a number of utility methods for converting back and forth between
|
|
130
|
+
a Y.Doc and Prosemirror compatible data structures. These can be useful for persisting
|
|
131
|
+
to a datastore or for importing existing documents.
|
|
132
|
+
|
|
133
|
+
> _Note_: Serializing and deserializing to JSON will not store collaboration history
|
|
134
|
+
> steps and as such should not be used as the primary storage. You will still need
|
|
135
|
+
> to store the Y.Doc binary update format.
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
import { prosemirrorToYDoc } from 'y-prosemirror'
|
|
139
|
+
|
|
140
|
+
// Pass JSON previously output from Prosemirror
|
|
141
|
+
const doc = Node.fromJSON(schema, {
|
|
142
|
+
type: "doc",
|
|
143
|
+
content: [...]
|
|
144
|
+
})
|
|
145
|
+
const ydoc = prosemirrorToYDoc(doc)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Because JSON is a common usecase there is an equivalent method that skips the need
|
|
149
|
+
to create a Prosemirror Node.
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
import { prosemirrorJSONToYDoc } from 'y-prosemirror'
|
|
153
|
+
|
|
154
|
+
// Pass JSON previously output from Prosemirror
|
|
155
|
+
const ydoc = prosemirrorJSONToYDoc(schema, {
|
|
156
|
+
type: "doc",
|
|
157
|
+
content: [...]
|
|
158
|
+
})
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
```js
|
|
162
|
+
import { yDocToProsemirror } from 'y-prosemirror'
|
|
163
|
+
|
|
164
|
+
// apply binary updates from elsewhere
|
|
165
|
+
const ydoc = new Y.Doc()
|
|
166
|
+
ydoc.applyUpdate(update)
|
|
167
|
+
|
|
168
|
+
const node = yDocToProsemirror(schema, ydoc)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Because JSON is a common usecase there is an equivalent method that outputs JSON
|
|
172
|
+
directly, this method does not require the Prosemirror schema.
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
import { yDocToProsemirrorJSON } from 'y-prosemirror'
|
|
176
|
+
|
|
177
|
+
// apply binary updates from elsewhere
|
|
178
|
+
const ydoc = new Y.Doc()
|
|
179
|
+
ydoc.applyUpdate(update)
|
|
180
|
+
|
|
181
|
+
const node = yDocToProsemirrorJSON(ydoc)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Undo/Redo
|
|
185
|
+
|
|
186
|
+
The package exports `undo` and `redo` commands which can be used in place of
|
|
187
|
+
[prosemirror-history](https://prosemirror.net/docs/ref/#history) by mapping the
|
|
188
|
+
mod-Z/Y keys - see [ProseMirror](https://github.com/yjs/yjs-demos/blob/main/prosemirror/prosemirror.js#L29)
|
|
189
|
+
and [Tiptap](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-collaboration/src/collaboration.ts)
|
|
190
|
+
examples.
|
|
191
|
+
|
|
192
|
+
Undo and redo are be scoped to the local client, so one peer won't undo another's
|
|
193
|
+
changes. See [Y.UndoManager](https://docs.yjs.dev/api/undo-manager) for more details.
|
|
194
|
+
|
|
195
|
+
Just like prosemirror-history, you can set a transaction's `addToHistory` meta property
|
|
196
|
+
to false to prevent that transaction from being rolled back by undo. This can be helpful for programmatic
|
|
197
|
+
document changes that aren't initiated by the user.
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
tr.setMeta("addToHistory", false);
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### License
|
|
204
|
+
|
|
205
|
+
[The MIT License](./LICENSE) © Kevin Jahns
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility method to convert a Prosemirror Doc Node into a Y.Doc.
|
|
3
|
+
*
|
|
4
|
+
* This can be used when importing existing content to Y.Doc for the first time,
|
|
5
|
+
* note that this should not be used to rehydrate a Y.Doc from a database once
|
|
6
|
+
* collaboration has begun as all history will be lost
|
|
7
|
+
*
|
|
8
|
+
* @param {Node} doc
|
|
9
|
+
* @param {string} xmlFragment
|
|
10
|
+
* @return {Y.Doc}
|
|
11
|
+
*/
|
|
12
|
+
export function prosemirrorToYDoc(doc: Node, xmlFragment?: string): Y.Doc;
|
|
13
|
+
/**
|
|
14
|
+
* Utility method to update an empty Y.XmlFragment with content from a Prosemirror Doc Node.
|
|
15
|
+
*
|
|
16
|
+
* This can be used when importing existing content to Y.Doc for the first time,
|
|
17
|
+
* note that this should not be used to rehydrate a Y.Doc from a database once
|
|
18
|
+
* collaboration has begun as all history will be lost
|
|
19
|
+
*
|
|
20
|
+
* Note: The Y.XmlFragment does not need to be part of a Y.Doc document at the time that this
|
|
21
|
+
* method is called, but it must be added before any other operations are performed on it.
|
|
22
|
+
*
|
|
23
|
+
* @param {Node} doc prosemirror document.
|
|
24
|
+
* @param {Y.XmlFragment} [xmlFragment] If supplied, an xml fragment to be
|
|
25
|
+
* populated from the prosemirror state; otherwise a new XmlFragment will be created.
|
|
26
|
+
* @return {Y.XmlFragment}
|
|
27
|
+
*/
|
|
28
|
+
export function prosemirrorToYXmlFragment(doc: Node, xmlFragment?: Y.XmlFragment): Y.XmlFragment;
|
|
29
|
+
/**
|
|
30
|
+
* Utility method to convert Prosemirror compatible JSON into a Y.Doc.
|
|
31
|
+
*
|
|
32
|
+
* This can be used when importing existing content to Y.Doc for the first time,
|
|
33
|
+
* note that this should not be used to rehydrate a Y.Doc from a database once
|
|
34
|
+
* collaboration has begun as all history will be lost
|
|
35
|
+
*
|
|
36
|
+
* @param {Schema} schema
|
|
37
|
+
* @param {any} state
|
|
38
|
+
* @param {string} xmlFragment
|
|
39
|
+
* @return {Y.Doc}
|
|
40
|
+
*/
|
|
41
|
+
export function prosemirrorJSONToYDoc(schema: Schema, state: any, xmlFragment?: string): Y.Doc;
|
|
42
|
+
/**
|
|
43
|
+
* Utility method to convert Prosemirror compatible JSON to a Y.XmlFragment
|
|
44
|
+
*
|
|
45
|
+
* This can be used when importing existing content to Y.Doc for the first time,
|
|
46
|
+
* note that this should not be used to rehydrate a Y.Doc from a database once
|
|
47
|
+
* collaboration has begun as all history will be lost
|
|
48
|
+
*
|
|
49
|
+
* @param {Schema} schema
|
|
50
|
+
* @param {any} state
|
|
51
|
+
* @param {Y.XmlFragment} [xmlFragment] If supplied, an xml fragment to be
|
|
52
|
+
* populated from the prosemirror state; otherwise a new XmlFragment will be created.
|
|
53
|
+
* @return {Y.XmlFragment}
|
|
54
|
+
*/
|
|
55
|
+
export function prosemirrorJSONToYXmlFragment(schema: Schema, state: any, xmlFragment?: Y.XmlFragment): Y.XmlFragment;
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead
|
|
58
|
+
*
|
|
59
|
+
* Utility method to convert a Y.Doc to a Prosemirror Doc node.
|
|
60
|
+
*
|
|
61
|
+
* @param {Schema} schema
|
|
62
|
+
* @param {Y.Doc} ydoc
|
|
63
|
+
* @return {Node}
|
|
64
|
+
*/
|
|
65
|
+
export function yDocToProsemirror(schema: Schema, ydoc: Y.Doc): Node;
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead
|
|
69
|
+
*
|
|
70
|
+
* Utility method to convert a Y.XmlFragment to a Prosemirror Doc node.
|
|
71
|
+
*
|
|
72
|
+
* @param {Schema} schema
|
|
73
|
+
* @param {Y.XmlFragment} xmlFragment
|
|
74
|
+
* @return {Node}
|
|
75
|
+
*/
|
|
76
|
+
export function yXmlFragmentToProsemirror(schema: Schema, xmlFragment: Y.XmlFragment): Node;
|
|
77
|
+
/**
|
|
78
|
+
*
|
|
79
|
+
* @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead
|
|
80
|
+
*
|
|
81
|
+
* Utility method to convert a Y.Doc to Prosemirror compatible JSON.
|
|
82
|
+
*
|
|
83
|
+
* @param {Y.Doc} ydoc
|
|
84
|
+
* @param {string} xmlFragment
|
|
85
|
+
* @return {Record<string, any>}
|
|
86
|
+
*/
|
|
87
|
+
export function yDocToProsemirrorJSON(ydoc: Y.Doc, xmlFragment?: string): Record<string, any>;
|
|
88
|
+
/**
|
|
89
|
+
* @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead
|
|
90
|
+
*
|
|
91
|
+
* Utility method to convert a Y.Doc to Prosemirror compatible JSON.
|
|
92
|
+
*
|
|
93
|
+
* @param {Y.XmlFragment} xmlFragment The fragment, which must be part of a Y.Doc.
|
|
94
|
+
* @return {Record<string, any>}
|
|
95
|
+
*/
|
|
96
|
+
export function yXmlFragmentToProsemirrorJSON(xmlFragment: Y.XmlFragment): Record<string, any>;
|
|
97
|
+
export function setMeta(view: any, key: any, value: any): void;
|
|
98
|
+
export function absolutePositionToRelativePosition(pos: number, type: Y.XmlFragment, mapping: ProsemirrorMapping): any;
|
|
99
|
+
export function relativePositionToAbsolutePosition(y: Y.Doc, documentType: Y.XmlFragment, relPos: any, mapping: ProsemirrorMapping): null | number;
|
|
100
|
+
export function yXmlFragmentToProseMirrorFragment(yXmlFragment: Y.XmlFragment, schema: Schema): Fragment;
|
|
101
|
+
export function yXmlFragmentToProseMirrorRootNode(yXmlFragment: Y.XmlFragment, schema: Schema): Node;
|
|
102
|
+
export function initProseMirrorDoc(yXmlFragment: Y.XmlFragment, schema: Schema): {
|
|
103
|
+
doc: Node;
|
|
104
|
+
meta: import("./plugins/sync-plugin.js").BindingMetadata;
|
|
105
|
+
mapping: import("./plugins/sync-plugin.js").ProsemirrorMapping;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Either a node if type is YXmlElement or an Array of text nodes if YXmlText
|
|
109
|
+
*/
|
|
110
|
+
export type ProsemirrorMapping = Map<Y.AbstractType<any>, Node | Array<Node>>;
|
|
111
|
+
import { Node } from 'prosemirror-model';
|
|
112
|
+
import * as Y from 'yjs';
|
|
113
|
+
import { Schema } from 'prosemirror-model';
|
|
114
|
+
import { Fragment } from 'prosemirror-model';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function defaultAwarenessStateFilter(currentClientId: number, userClientId: number, _user: any): boolean;
|
|
2
|
+
export function defaultCursorBuilder(user: any): HTMLElement;
|
|
3
|
+
export function defaultSelectionBuilder(user: any): import('prosemirror-view').DecorationAttrs;
|
|
4
|
+
export function createDecorations(state: any, awareness: Awareness, awarenessFilter: (arg0: number, arg1: number, arg2: any) => boolean, createCursor: (user: {
|
|
5
|
+
name: string;
|
|
6
|
+
color: string;
|
|
7
|
+
}, clientId: number) => Element, createSelection: (user: {
|
|
8
|
+
name: string;
|
|
9
|
+
color: string;
|
|
10
|
+
}, clientId: number) => import('prosemirror-view').DecorationAttrs): any;
|
|
11
|
+
export function yCursorPlugin(awareness: Awareness, { awarenessStateFilter, cursorBuilder, selectionBuilder, getSelection }?: {
|
|
12
|
+
awarenessStateFilter?: (arg0: any, arg1: any, arg2: any) => boolean;
|
|
13
|
+
cursorBuilder?: (user: any, clientId: number) => HTMLElement;
|
|
14
|
+
selectionBuilder?: (user: any, clientId: number) => import('prosemirror-view').DecorationAttrs;
|
|
15
|
+
getSelection?: (arg0: any) => any;
|
|
16
|
+
}, cursorStateField?: string): any;
|
|
17
|
+
import { Awareness } from "y-protocols/awareness";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The unique prosemirror plugin key for syncPlugin
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export const ySyncPluginKey: PluginKey<any>;
|
|
7
|
+
/**
|
|
8
|
+
* The unique prosemirror plugin key for undoPlugin
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
* @type {PluginKey<import('./undo-plugin').UndoPluginState>}
|
|
12
|
+
*/
|
|
13
|
+
export const yUndoPluginKey: PluginKey<import('./undo-plugin').UndoPluginState>;
|
|
14
|
+
/**
|
|
15
|
+
* The unique prosemirror plugin key for cursorPlugin
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export const yCursorPluginKey: PluginKey<any>;
|
|
20
|
+
import { PluginKey } from 'prosemirror-state';
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
export function createEmptyMeta(): BindingMetadata;
|
|
2
|
+
export function isVisible(item: Y.Item, snapshot?: Y.Snapshot): boolean;
|
|
3
|
+
export function ySyncPlugin(yXmlFragment: Y.XmlFragment, { colors, colorMapping, permanentUserData, onFirstRender, mapping }?: YSyncOpts): any;
|
|
4
|
+
export function getRelativeSelection(pmbinding: ProsemirrorBinding, state: import('prosemirror-state').EditorState): {
|
|
5
|
+
type: any;
|
|
6
|
+
anchor: any;
|
|
7
|
+
head: any;
|
|
8
|
+
};
|
|
9
|
+
export function createRecoverableSelection(pmbinding: any, state: any): RecoverableSelection;
|
|
10
|
+
export class RecoverableSelection {
|
|
11
|
+
constructor(pmbinding: any, selection: any, recoverMode?: boolean);
|
|
12
|
+
records: any[];
|
|
13
|
+
pmbinding: any;
|
|
14
|
+
selection: any;
|
|
15
|
+
recoverMode: boolean;
|
|
16
|
+
restore(pmbinding: any, doc: any): any;
|
|
17
|
+
valid(): boolean;
|
|
18
|
+
map(pos: any): any;
|
|
19
|
+
mapResult(pos: any): {
|
|
20
|
+
deleted: boolean;
|
|
21
|
+
pos: any;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export class RecoveryMapping {
|
|
25
|
+
constructor(pmbinding: any, records: any);
|
|
26
|
+
pmbinding: any;
|
|
27
|
+
records: any;
|
|
28
|
+
map(pos: any): any;
|
|
29
|
+
mapResult(pos: any): {
|
|
30
|
+
deleted: boolean;
|
|
31
|
+
pos: any;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Binding for prosemirror.
|
|
36
|
+
*
|
|
37
|
+
* @protected
|
|
38
|
+
*/
|
|
39
|
+
export class ProsemirrorBinding {
|
|
40
|
+
/**
|
|
41
|
+
* @param {Y.XmlFragment} yXmlFragment The bind source
|
|
42
|
+
* @param {ProsemirrorMapping} mapping
|
|
43
|
+
*/
|
|
44
|
+
constructor(yXmlFragment: Y.XmlFragment, mapping?: ProsemirrorMapping);
|
|
45
|
+
type: Y.XmlFragment;
|
|
46
|
+
/**
|
|
47
|
+
* this will be set once the view is created
|
|
48
|
+
* @type {any}
|
|
49
|
+
*/
|
|
50
|
+
prosemirrorView: any;
|
|
51
|
+
mux: import("lib0/mutex").mutex;
|
|
52
|
+
mapping: ProsemirrorMapping;
|
|
53
|
+
/**
|
|
54
|
+
* Is overlapping mark - i.e. mark does not exclude itself.
|
|
55
|
+
*
|
|
56
|
+
* @type {Map<import('prosemirror-model').MarkType, boolean>}
|
|
57
|
+
*/
|
|
58
|
+
isOMark: Map<import('prosemirror-model').MarkType, boolean>;
|
|
59
|
+
_observeFunction: any;
|
|
60
|
+
/**
|
|
61
|
+
* @type {Y.Doc}
|
|
62
|
+
*/
|
|
63
|
+
doc: Y.Doc;
|
|
64
|
+
/**
|
|
65
|
+
* last selection as relative positions in the Yjs model
|
|
66
|
+
*/
|
|
67
|
+
beforePatchSelection: RecoverableSelection;
|
|
68
|
+
/**
|
|
69
|
+
* current selection as relative positions in the Yjs model
|
|
70
|
+
*/
|
|
71
|
+
beforeTransactionSelection: RecoverableSelection;
|
|
72
|
+
lastProsemirrorState: any;
|
|
73
|
+
beforeAllTransactions: () => void;
|
|
74
|
+
afterAllTransactions: () => void;
|
|
75
|
+
_domSelectionInView: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Create a transaction for changing the prosemirror state.
|
|
78
|
+
*
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
get _tr(): any;
|
|
82
|
+
_isLocalCursorInView(): boolean;
|
|
83
|
+
_isDomSelectionInView(): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* @param {Y.Snapshot} snapshot
|
|
86
|
+
* @param {Y.Snapshot} prevSnapshot
|
|
87
|
+
*/
|
|
88
|
+
renderSnapshot(snapshot: Y.Snapshot, prevSnapshot: Y.Snapshot): void;
|
|
89
|
+
unrenderSnapshot(): void;
|
|
90
|
+
_forceRerender(): void;
|
|
91
|
+
/**
|
|
92
|
+
* @param {Y.Snapshot|Uint8Array} snapshot
|
|
93
|
+
* @param {Y.Snapshot|Uint8Array} prevSnapshot
|
|
94
|
+
* @param {Object} pluginState
|
|
95
|
+
*/
|
|
96
|
+
_renderSnapshot(snapshot: Y.Snapshot | Uint8Array, prevSnapshot: Y.Snapshot | Uint8Array, pluginState: any): void;
|
|
97
|
+
/**
|
|
98
|
+
* @param {Array<Y.YEvent<any>>} events
|
|
99
|
+
* @param {Y.Transaction} transaction
|
|
100
|
+
*/
|
|
101
|
+
_typeChanged(events: Array<Y.YEvent<any>>, transaction: Y.Transaction): void;
|
|
102
|
+
/**
|
|
103
|
+
* @param {import('prosemirror-model').Node} doc
|
|
104
|
+
*/
|
|
105
|
+
_prosemirrorChanged(doc: import('prosemirror-model').Node): void;
|
|
106
|
+
/**
|
|
107
|
+
* View is ready to listen to changes. Register observers.
|
|
108
|
+
* @param {any} prosemirrorView
|
|
109
|
+
*/
|
|
110
|
+
initView(prosemirrorView: any): void;
|
|
111
|
+
destroy(): void;
|
|
112
|
+
}
|
|
113
|
+
export function createNodeFromYElement(el: Y.XmlElement, schema: any, meta: BindingMetadata, snapshot?: Y.Snapshot, prevSnapshot?: Y.Snapshot, computeYChange?: (arg0: 'removed' | 'added', arg1: Y.ID) => any): PModel.Node | null;
|
|
114
|
+
export function yattr2markname(attrName: string): string;
|
|
115
|
+
export function attributesToMarks(attrs: {
|
|
116
|
+
[x: string]: any;
|
|
117
|
+
}, schema: import('prosemirror-model').Schema): PModel.Mark[];
|
|
118
|
+
export function updateYFragment(y: {
|
|
119
|
+
transact: Function;
|
|
120
|
+
}, yDomFragment: Y.XmlFragment, pNode: any, meta: BindingMetadata): void;
|
|
121
|
+
export type BindingMetadata = {
|
|
122
|
+
mapping: ProsemirrorMapping;
|
|
123
|
+
/**
|
|
124
|
+
* - is overlapping mark
|
|
125
|
+
*/
|
|
126
|
+
isOMark: Map<import('prosemirror-model').MarkType, boolean>;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Either a node if type is YXmlElement or an Array of text nodes if YXmlText
|
|
130
|
+
*/
|
|
131
|
+
export type ProsemirrorMapping = Map<Y.AbstractType<any>, PModel.Node | Array<PModel.Node>>;
|
|
132
|
+
export type ColorDef = {
|
|
133
|
+
light: string;
|
|
134
|
+
dark: string;
|
|
135
|
+
};
|
|
136
|
+
export type YSyncOpts = {
|
|
137
|
+
colors?: Array<ColorDef>;
|
|
138
|
+
colorMapping?: Map<string, ColorDef>;
|
|
139
|
+
permanentUserData?: Y.PermanentUserData | null;
|
|
140
|
+
mapping?: ProsemirrorMapping;
|
|
141
|
+
/**
|
|
142
|
+
* Fired when the content from Yjs is initially rendered to ProseMirror
|
|
143
|
+
*/
|
|
144
|
+
onFirstRender?: Function;
|
|
145
|
+
};
|
|
146
|
+
export type NormalizedPNodeContent = Array<Array<PModel.Node> | PModel.Node>;
|
|
147
|
+
import * as Y from 'yjs';
|
|
148
|
+
import * as PModel from 'prosemirror-model';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function undo(state: import('prosemirror-state').EditorState): boolean;
|
|
2
|
+
export function redo(state: import('prosemirror-state').EditorState): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Undo the last user action if there are undo operations available
|
|
5
|
+
* @type {import('prosemirror-state').Command}
|
|
6
|
+
*/
|
|
7
|
+
export const undoCommand: import('prosemirror-state').Command;
|
|
8
|
+
/**
|
|
9
|
+
* Redo the last user action if there are redo operations available
|
|
10
|
+
* @type {import('prosemirror-state').Command}
|
|
11
|
+
*/
|
|
12
|
+
export const redoCommand: import('prosemirror-state').Command;
|
|
13
|
+
export const defaultProtectedNodes: Set<string>;
|
|
14
|
+
export function defaultDeleteFilter(item: import('yjs').Item, protectedNodes: Set<string>): boolean;
|
|
15
|
+
export function yUndoPlugin({ protectedNodes, trackedOrigins, undoManager }?: {
|
|
16
|
+
protectedNodes?: Set<string>;
|
|
17
|
+
trackedOrigins?: any[];
|
|
18
|
+
undoManager?: import('yjs').UndoManager | null;
|
|
19
|
+
}): Plugin<{
|
|
20
|
+
undoManager: UndoManager;
|
|
21
|
+
prevSel: any;
|
|
22
|
+
hasUndoOps: boolean;
|
|
23
|
+
hasRedoOps: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
export type UndoPluginState = {
|
|
26
|
+
undoManager: import('yjs').UndoManager;
|
|
27
|
+
prevSel: ReturnType<typeof createRecoverableSelection> | null;
|
|
28
|
+
hasUndoOps: boolean;
|
|
29
|
+
hasRedoOps: boolean;
|
|
30
|
+
};
|
|
31
|
+
import { UndoManager } from 'yjs';
|
|
32
|
+
import { Plugin } from 'prosemirror-state';
|
|
33
|
+
import { createRecoverableSelection } from './sync-plugin.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function hashOfJSON(json: any): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * from "./plugins/cursor-plugin.js";
|
|
2
|
+
export * from "./plugins/undo-plugin.js";
|
|
3
|
+
export * from "./plugins/keys.js";
|
|
4
|
+
export { ySyncPlugin, isVisible, getRelativeSelection, ProsemirrorBinding, updateYFragment } from "./plugins/sync-plugin.js";
|
|
5
|
+
export { absolutePositionToRelativePosition, relativePositionToAbsolutePosition, setMeta, prosemirrorJSONToYDoc, yDocToProsemirrorJSON, yDocToProsemirror, prosemirrorToYDoc, prosemirrorJSONToYXmlFragment, yXmlFragmentToProsemirrorJSON, yXmlFragmentToProsemirror, prosemirrorToYXmlFragment, yXmlFragmentToProseMirrorRootNode, yXmlFragmentToProseMirrorFragment, initProseMirrorDoc } from "./lib.js";
|