@remirror/extension-yjs 1.0.30 → 2.0.1
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/dist/declarations/src/yjs-extension.d.ts +6 -2
- package/dist/remirror-extension-yjs.browser.cjs.js +13 -136
- package/dist/remirror-extension-yjs.browser.esm.js +15 -138
- package/dist/remirror-extension-yjs.cjs.dev.js +13 -136
- package/dist/remirror-extension-yjs.cjs.prod.js +13 -136
- package/dist/remirror-extension-yjs.esm.js +15 -138
- package/package.json +7 -8
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Doc } from 'yjs';
|
|
2
|
-
import { AcceptUndefined,
|
|
2
|
+
import { AcceptUndefined, EditorState, KeyBindingProps, NonChainableCommandFunction, OnSetOptionsProps, PlainExtension, ProsemirrorPlugin, Selection, Shape, Static } from '@remirror/core';
|
|
3
|
+
import { DecorationAttrs } from '@remirror/pm/view';
|
|
3
4
|
export interface ColorDef {
|
|
4
5
|
light: string;
|
|
5
6
|
dark: string;
|
|
@@ -41,6 +42,10 @@ export interface YjsOptions<Provider extends YjsRealtimeProvider = YjsRealtimePr
|
|
|
41
42
|
* See https://github.com/yjs/y-prosemirror#remote-cursors
|
|
42
43
|
*/
|
|
43
44
|
cursorBuilder?: (user: Shape) => HTMLElement;
|
|
45
|
+
/**
|
|
46
|
+
* Generator for the selection attributes
|
|
47
|
+
*/
|
|
48
|
+
selectionBuilder?: (user: Shape) => DecorationAttrs;
|
|
44
49
|
/**
|
|
45
50
|
* By default all editor bindings use the awareness 'cursor' field to
|
|
46
51
|
* propagate cursor information.
|
|
@@ -77,7 +82,6 @@ export declare class YjsExtension extends PlainExtension<YjsOptions> {
|
|
|
77
82
|
getBinding(): {
|
|
78
83
|
mapping: Map<any, any>;
|
|
79
84
|
} | undefined;
|
|
80
|
-
onView(): Dispose | void;
|
|
81
85
|
/**
|
|
82
86
|
* Create the yjs plugins.
|
|
83
87
|
*/
|
|
@@ -3,107 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var _applyDecoratedDescriptor = require('@babel/runtime/helpers/applyDecoratedDescriptor');
|
|
6
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
7
|
-
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
8
6
|
var yProsemirror = require('y-prosemirror');
|
|
9
7
|
var yjs = require('yjs');
|
|
10
8
|
var core = require('@remirror/core');
|
|
11
|
-
var extensionAnnotation = require('@remirror/extension-annotation');
|
|
12
9
|
var messages = require('@remirror/messages');
|
|
13
10
|
|
|
14
11
|
var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2;
|
|
15
|
-
|
|
16
|
-
var _excluded = ["from", "to"],
|
|
17
|
-
_excluded2 = ["from", "to"];
|
|
18
|
-
|
|
19
|
-
class YjsAnnotationStore {
|
|
20
|
-
constructor(doc, pmName, mapName, getMapping) {
|
|
21
|
-
this.doc = doc;
|
|
22
|
-
this.getMapping = getMapping;
|
|
23
|
-
this.type = doc.getXmlFragment(pmName);
|
|
24
|
-
this.map = doc.getMap(mapName);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
addAnnotation(_ref) {
|
|
28
|
-
var from = _ref.from,
|
|
29
|
-
to = _ref.to,
|
|
30
|
-
data = _objectWithoutProperties(_ref, _excluded);
|
|
31
|
-
|
|
32
|
-
// XXX: Why is this cast needed?
|
|
33
|
-
var storedData = _objectSpread(_objectSpread({}, data), {}, {
|
|
34
|
-
from: this.absolutePositionToRelativePosition(from),
|
|
35
|
-
to: this.absolutePositionToRelativePosition(to)
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
this.map.set(data.id, storedData);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
updateAnnotation(id, updateData) {
|
|
42
|
-
var existing = this.map.get(id);
|
|
43
|
-
|
|
44
|
-
if (!existing) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
this.map.set(id, _objectSpread(_objectSpread({}, updateData), {}, {
|
|
49
|
-
from: existing.from,
|
|
50
|
-
to: existing.to
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
removeAnnotations(ids) {
|
|
55
|
-
yjs.transact(this.doc, () => {
|
|
56
|
-
ids.forEach(id => this.map.delete(id));
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
setAnnotations(annotations) {
|
|
61
|
-
yjs.transact(this.doc, () => {
|
|
62
|
-
this.map.clear();
|
|
63
|
-
annotations.forEach(annotation => this.addAnnotation(annotation));
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
formatAnnotations() {
|
|
68
|
-
var result = [];
|
|
69
|
-
this.map.forEach(_ref2 => {
|
|
70
|
-
var relFrom = _ref2.from,
|
|
71
|
-
relTo = _ref2.to,
|
|
72
|
-
data = _objectWithoutProperties(_ref2, _excluded2);
|
|
73
|
-
|
|
74
|
-
var from = this.relativePositionToAbsolutePosition(relFrom);
|
|
75
|
-
var to = this.relativePositionToAbsolutePosition(relTo);
|
|
76
|
-
|
|
77
|
-
if (!from || !to) {
|
|
78
|
-
return;
|
|
79
|
-
} // XXX: Why is this cast needed?
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
result.push(_objectSpread(_objectSpread({}, data), {}, {
|
|
83
|
-
from,
|
|
84
|
-
to
|
|
85
|
-
}));
|
|
86
|
-
});
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
absolutePositionToRelativePosition(pos) {
|
|
91
|
-
var mapping = this.getMapping();
|
|
92
|
-
return yProsemirror.absolutePositionToRelativePosition(pos, this.type, mapping);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
relativePositionToAbsolutePosition(relPos) {
|
|
96
|
-
var mapping = this.getMapping();
|
|
97
|
-
return yProsemirror.relativePositionToAbsolutePosition(this.doc, this.type, relPos, mapping);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* The YJS extension is the recommended extension for creating a collaborative
|
|
103
|
-
* editor.
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
12
|
var YjsExtension = (_dec = core.extension({
|
|
108
13
|
defaultOptions: {
|
|
109
14
|
getProvider: () => {
|
|
@@ -115,6 +20,7 @@ var YjsExtension = (_dec = core.extension({
|
|
|
115
20
|
destroyProvider: defaultDestroyProvider,
|
|
116
21
|
syncPluginOptions: undefined,
|
|
117
22
|
cursorBuilder: yProsemirror.defaultCursorBuilder,
|
|
23
|
+
selectionBuilder: yProsemirror.defaultSelectionBuilder,
|
|
118
24
|
cursorStateField: 'cursor',
|
|
119
25
|
getSelection: state => state.selection,
|
|
120
26
|
disableUndo: false,
|
|
@@ -125,23 +31,23 @@ var YjsExtension = (_dec = core.extension({
|
|
|
125
31
|
defaultPriority: core.ExtensionPriority.High
|
|
126
32
|
}), _dec2 = core.command({
|
|
127
33
|
disableChaining: true,
|
|
128
|
-
description:
|
|
129
|
-
var t =
|
|
34
|
+
description: _ref => {
|
|
35
|
+
var t = _ref.t;
|
|
130
36
|
return t(messages.ExtensionHistoryMessages.UNDO_DESCRIPTION);
|
|
131
37
|
},
|
|
132
|
-
label:
|
|
133
|
-
var t =
|
|
38
|
+
label: _ref2 => {
|
|
39
|
+
var t = _ref2.t;
|
|
134
40
|
return t(messages.ExtensionHistoryMessages.UNDO_LABEL);
|
|
135
41
|
},
|
|
136
42
|
icon: 'arrowGoBackFill'
|
|
137
43
|
}), _dec3 = core.command({
|
|
138
44
|
disableChaining: true,
|
|
139
|
-
description:
|
|
140
|
-
var t =
|
|
45
|
+
description: _ref3 => {
|
|
46
|
+
var t = _ref3.t;
|
|
141
47
|
return t(messages.ExtensionHistoryMessages.REDO_DESCRIPTION);
|
|
142
48
|
},
|
|
143
|
-
label:
|
|
144
|
-
var t =
|
|
49
|
+
label: _ref4 => {
|
|
50
|
+
var t = _ref4.t;
|
|
145
51
|
return t(messages.ExtensionHistoryMessages.REDO_LABEL);
|
|
146
52
|
},
|
|
147
53
|
icon: 'arrowGoForwardFill'
|
|
@@ -174,36 +80,6 @@ var YjsExtension = (_dec = core.extension({
|
|
|
174
80
|
|
|
175
81
|
return binding;
|
|
176
82
|
}
|
|
177
|
-
|
|
178
|
-
onView() {
|
|
179
|
-
try {
|
|
180
|
-
var annotationStore = new YjsAnnotationStore(this.provider.doc, 'prosemirror', 'annotations', () => {
|
|
181
|
-
var _this$getBinding;
|
|
182
|
-
|
|
183
|
-
return (_this$getBinding = this.getBinding()) === null || _this$getBinding === void 0 ? void 0 : _this$getBinding.mapping;
|
|
184
|
-
});
|
|
185
|
-
this.store.manager.getExtension(extensionAnnotation.AnnotationExtension).setOptions({
|
|
186
|
-
getStore: () => annotationStore
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
var handler = (_update, _origin, _doc, yjsTr) => {
|
|
190
|
-
var _this$store$commands$, _this$store$commands;
|
|
191
|
-
|
|
192
|
-
// Ignore own changes
|
|
193
|
-
if (yjsTr.local) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
(_this$store$commands$ = (_this$store$commands = this.store.commands).redrawAnnotations) === null || _this$store$commands$ === void 0 ? void 0 : _this$store$commands$.call(_this$store$commands);
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
this.provider.doc.on('update', handler);
|
|
201
|
-
return () => {
|
|
202
|
-
this.provider.doc.off('update', handler);
|
|
203
|
-
};
|
|
204
|
-
} catch (_unused) {// AnnotationExtension isn't present in editor
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
83
|
/**
|
|
208
84
|
* Create the yjs plugins.
|
|
209
85
|
*/
|
|
@@ -217,13 +93,14 @@ var YjsExtension = (_dec = core.extension({
|
|
|
217
93
|
cursorStateField = _this$options.cursorStateField,
|
|
218
94
|
disableUndo = _this$options.disableUndo,
|
|
219
95
|
protectedNodes = _this$options.protectedNodes,
|
|
220
|
-
trackedOrigins = _this$options.trackedOrigins
|
|
96
|
+
trackedOrigins = _this$options.trackedOrigins,
|
|
97
|
+
selectionBuilder = _this$options.selectionBuilder;
|
|
221
98
|
var yDoc = this.provider.doc;
|
|
222
99
|
var type = yDoc.getXmlFragment('prosemirror');
|
|
223
100
|
var plugins = [yProsemirror.ySyncPlugin(type, syncPluginOptions), yProsemirror.yCursorPlugin(this.provider.awareness, {
|
|
224
101
|
cursorBuilder,
|
|
225
|
-
|
|
226
|
-
|
|
102
|
+
getSelection,
|
|
103
|
+
selectionBuilder
|
|
227
104
|
}, cursorStateField)];
|
|
228
105
|
|
|
229
106
|
if (!disableUndo) {
|
|
@@ -1,105 +1,10 @@
|
|
|
1
1
|
import _applyDecoratedDescriptor from '@babel/runtime/helpers/esm/applyDecoratedDescriptor';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { defaultCursorBuilder, ySyncPluginKey, ySyncPlugin, yCursorPlugin, defaultDeleteFilter, yUndoPlugin, yUndoPluginKey, undo, redo, absolutePositionToRelativePosition, relativePositionToAbsolutePosition } from 'y-prosemirror';
|
|
5
|
-
import { UndoManager, transact } from 'yjs';
|
|
2
|
+
import { defaultCursorBuilder, defaultSelectionBuilder, ySyncPluginKey, ySyncPlugin, yCursorPlugin, defaultDeleteFilter, yUndoPlugin, yUndoPluginKey, undo, redo } from 'y-prosemirror';
|
|
3
|
+
import { UndoManager } from 'yjs';
|
|
6
4
|
import { extension, invariant, ErrorConstant, ExtensionPriority, command, keyBinding, NamedShortcut, PlainExtension, isFunction, isEmptyObject, nonChainable, convertCommand } from '@remirror/core';
|
|
7
|
-
import { AnnotationExtension } from '@remirror/extension-annotation';
|
|
8
5
|
import { ExtensionHistoryMessages } from '@remirror/messages';
|
|
9
6
|
|
|
10
7
|
var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2;
|
|
11
|
-
|
|
12
|
-
var _excluded = ["from", "to"],
|
|
13
|
-
_excluded2 = ["from", "to"];
|
|
14
|
-
|
|
15
|
-
class YjsAnnotationStore {
|
|
16
|
-
constructor(doc, pmName, mapName, getMapping) {
|
|
17
|
-
this.doc = doc;
|
|
18
|
-
this.getMapping = getMapping;
|
|
19
|
-
this.type = doc.getXmlFragment(pmName);
|
|
20
|
-
this.map = doc.getMap(mapName);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
addAnnotation(_ref) {
|
|
24
|
-
var from = _ref.from,
|
|
25
|
-
to = _ref.to,
|
|
26
|
-
data = _objectWithoutProperties(_ref, _excluded);
|
|
27
|
-
|
|
28
|
-
// XXX: Why is this cast needed?
|
|
29
|
-
var storedData = _objectSpread(_objectSpread({}, data), {}, {
|
|
30
|
-
from: this.absolutePositionToRelativePosition(from),
|
|
31
|
-
to: this.absolutePositionToRelativePosition(to)
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
this.map.set(data.id, storedData);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
updateAnnotation(id, updateData) {
|
|
38
|
-
var existing = this.map.get(id);
|
|
39
|
-
|
|
40
|
-
if (!existing) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
this.map.set(id, _objectSpread(_objectSpread({}, updateData), {}, {
|
|
45
|
-
from: existing.from,
|
|
46
|
-
to: existing.to
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
removeAnnotations(ids) {
|
|
51
|
-
transact(this.doc, () => {
|
|
52
|
-
ids.forEach(id => this.map.delete(id));
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
setAnnotations(annotations) {
|
|
57
|
-
transact(this.doc, () => {
|
|
58
|
-
this.map.clear();
|
|
59
|
-
annotations.forEach(annotation => this.addAnnotation(annotation));
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
formatAnnotations() {
|
|
64
|
-
var result = [];
|
|
65
|
-
this.map.forEach(_ref2 => {
|
|
66
|
-
var relFrom = _ref2.from,
|
|
67
|
-
relTo = _ref2.to,
|
|
68
|
-
data = _objectWithoutProperties(_ref2, _excluded2);
|
|
69
|
-
|
|
70
|
-
var from = this.relativePositionToAbsolutePosition(relFrom);
|
|
71
|
-
var to = this.relativePositionToAbsolutePosition(relTo);
|
|
72
|
-
|
|
73
|
-
if (!from || !to) {
|
|
74
|
-
return;
|
|
75
|
-
} // XXX: Why is this cast needed?
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
result.push(_objectSpread(_objectSpread({}, data), {}, {
|
|
79
|
-
from,
|
|
80
|
-
to
|
|
81
|
-
}));
|
|
82
|
-
});
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
absolutePositionToRelativePosition(pos) {
|
|
87
|
-
var mapping = this.getMapping();
|
|
88
|
-
return absolutePositionToRelativePosition(pos, this.type, mapping);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
relativePositionToAbsolutePosition(relPos) {
|
|
92
|
-
var mapping = this.getMapping();
|
|
93
|
-
return relativePositionToAbsolutePosition(this.doc, this.type, relPos, mapping);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* The YJS extension is the recommended extension for creating a collaborative
|
|
99
|
-
* editor.
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
8
|
var YjsExtension = (_dec = extension({
|
|
104
9
|
defaultOptions: {
|
|
105
10
|
getProvider: () => {
|
|
@@ -111,6 +16,7 @@ var YjsExtension = (_dec = extension({
|
|
|
111
16
|
destroyProvider: defaultDestroyProvider,
|
|
112
17
|
syncPluginOptions: undefined,
|
|
113
18
|
cursorBuilder: defaultCursorBuilder,
|
|
19
|
+
selectionBuilder: defaultSelectionBuilder,
|
|
114
20
|
cursorStateField: 'cursor',
|
|
115
21
|
getSelection: state => state.selection,
|
|
116
22
|
disableUndo: false,
|
|
@@ -121,23 +27,23 @@ var YjsExtension = (_dec = extension({
|
|
|
121
27
|
defaultPriority: ExtensionPriority.High
|
|
122
28
|
}), _dec2 = command({
|
|
123
29
|
disableChaining: true,
|
|
124
|
-
description:
|
|
125
|
-
var t =
|
|
30
|
+
description: _ref => {
|
|
31
|
+
var t = _ref.t;
|
|
126
32
|
return t(ExtensionHistoryMessages.UNDO_DESCRIPTION);
|
|
127
33
|
},
|
|
128
|
-
label:
|
|
129
|
-
var t =
|
|
34
|
+
label: _ref2 => {
|
|
35
|
+
var t = _ref2.t;
|
|
130
36
|
return t(ExtensionHistoryMessages.UNDO_LABEL);
|
|
131
37
|
},
|
|
132
38
|
icon: 'arrowGoBackFill'
|
|
133
39
|
}), _dec3 = command({
|
|
134
40
|
disableChaining: true,
|
|
135
|
-
description:
|
|
136
|
-
var t =
|
|
41
|
+
description: _ref3 => {
|
|
42
|
+
var t = _ref3.t;
|
|
137
43
|
return t(ExtensionHistoryMessages.REDO_DESCRIPTION);
|
|
138
44
|
},
|
|
139
|
-
label:
|
|
140
|
-
var t =
|
|
45
|
+
label: _ref4 => {
|
|
46
|
+
var t = _ref4.t;
|
|
141
47
|
return t(ExtensionHistoryMessages.REDO_LABEL);
|
|
142
48
|
},
|
|
143
49
|
icon: 'arrowGoForwardFill'
|
|
@@ -170,36 +76,6 @@ var YjsExtension = (_dec = extension({
|
|
|
170
76
|
|
|
171
77
|
return binding;
|
|
172
78
|
}
|
|
173
|
-
|
|
174
|
-
onView() {
|
|
175
|
-
try {
|
|
176
|
-
var annotationStore = new YjsAnnotationStore(this.provider.doc, 'prosemirror', 'annotations', () => {
|
|
177
|
-
var _this$getBinding;
|
|
178
|
-
|
|
179
|
-
return (_this$getBinding = this.getBinding()) === null || _this$getBinding === void 0 ? void 0 : _this$getBinding.mapping;
|
|
180
|
-
});
|
|
181
|
-
this.store.manager.getExtension(AnnotationExtension).setOptions({
|
|
182
|
-
getStore: () => annotationStore
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
var handler = (_update, _origin, _doc, yjsTr) => {
|
|
186
|
-
var _this$store$commands$, _this$store$commands;
|
|
187
|
-
|
|
188
|
-
// Ignore own changes
|
|
189
|
-
if (yjsTr.local) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
(_this$store$commands$ = (_this$store$commands = this.store.commands).redrawAnnotations) === null || _this$store$commands$ === void 0 ? void 0 : _this$store$commands$.call(_this$store$commands);
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
this.provider.doc.on('update', handler);
|
|
197
|
-
return () => {
|
|
198
|
-
this.provider.doc.off('update', handler);
|
|
199
|
-
};
|
|
200
|
-
} catch (_unused) {// AnnotationExtension isn't present in editor
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
79
|
/**
|
|
204
80
|
* Create the yjs plugins.
|
|
205
81
|
*/
|
|
@@ -213,13 +89,14 @@ var YjsExtension = (_dec = extension({
|
|
|
213
89
|
cursorStateField = _this$options.cursorStateField,
|
|
214
90
|
disableUndo = _this$options.disableUndo,
|
|
215
91
|
protectedNodes = _this$options.protectedNodes,
|
|
216
|
-
trackedOrigins = _this$options.trackedOrigins
|
|
92
|
+
trackedOrigins = _this$options.trackedOrigins,
|
|
93
|
+
selectionBuilder = _this$options.selectionBuilder;
|
|
217
94
|
var yDoc = this.provider.doc;
|
|
218
95
|
var type = yDoc.getXmlFragment('prosemirror');
|
|
219
96
|
var plugins = [ySyncPlugin(type, syncPluginOptions), yCursorPlugin(this.provider.awareness, {
|
|
220
97
|
cursorBuilder,
|
|
221
|
-
|
|
222
|
-
|
|
98
|
+
getSelection,
|
|
99
|
+
selectionBuilder
|
|
223
100
|
}, cursorStateField)];
|
|
224
101
|
|
|
225
102
|
if (!disableUndo) {
|
|
@@ -3,107 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var _applyDecoratedDescriptor = require('@babel/runtime/helpers/applyDecoratedDescriptor');
|
|
6
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
7
|
-
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
8
6
|
var yProsemirror = require('y-prosemirror');
|
|
9
7
|
var yjs = require('yjs');
|
|
10
8
|
var core = require('@remirror/core');
|
|
11
|
-
var extensionAnnotation = require('@remirror/extension-annotation');
|
|
12
9
|
var messages = require('@remirror/messages');
|
|
13
10
|
|
|
14
11
|
var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2;
|
|
15
|
-
|
|
16
|
-
var _excluded = ["from", "to"],
|
|
17
|
-
_excluded2 = ["from", "to"];
|
|
18
|
-
|
|
19
|
-
class YjsAnnotationStore {
|
|
20
|
-
constructor(doc, pmName, mapName, getMapping) {
|
|
21
|
-
this.doc = doc;
|
|
22
|
-
this.getMapping = getMapping;
|
|
23
|
-
this.type = doc.getXmlFragment(pmName);
|
|
24
|
-
this.map = doc.getMap(mapName);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
addAnnotation(_ref) {
|
|
28
|
-
var from = _ref.from,
|
|
29
|
-
to = _ref.to,
|
|
30
|
-
data = _objectWithoutProperties(_ref, _excluded);
|
|
31
|
-
|
|
32
|
-
// XXX: Why is this cast needed?
|
|
33
|
-
var storedData = _objectSpread(_objectSpread({}, data), {}, {
|
|
34
|
-
from: this.absolutePositionToRelativePosition(from),
|
|
35
|
-
to: this.absolutePositionToRelativePosition(to)
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
this.map.set(data.id, storedData);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
updateAnnotation(id, updateData) {
|
|
42
|
-
var existing = this.map.get(id);
|
|
43
|
-
|
|
44
|
-
if (!existing) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
this.map.set(id, _objectSpread(_objectSpread({}, updateData), {}, {
|
|
49
|
-
from: existing.from,
|
|
50
|
-
to: existing.to
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
removeAnnotations(ids) {
|
|
55
|
-
yjs.transact(this.doc, () => {
|
|
56
|
-
ids.forEach(id => this.map.delete(id));
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
setAnnotations(annotations) {
|
|
61
|
-
yjs.transact(this.doc, () => {
|
|
62
|
-
this.map.clear();
|
|
63
|
-
annotations.forEach(annotation => this.addAnnotation(annotation));
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
formatAnnotations() {
|
|
68
|
-
var result = [];
|
|
69
|
-
this.map.forEach(_ref2 => {
|
|
70
|
-
var relFrom = _ref2.from,
|
|
71
|
-
relTo = _ref2.to,
|
|
72
|
-
data = _objectWithoutProperties(_ref2, _excluded2);
|
|
73
|
-
|
|
74
|
-
var from = this.relativePositionToAbsolutePosition(relFrom);
|
|
75
|
-
var to = this.relativePositionToAbsolutePosition(relTo);
|
|
76
|
-
|
|
77
|
-
if (!from || !to) {
|
|
78
|
-
return;
|
|
79
|
-
} // XXX: Why is this cast needed?
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
result.push(_objectSpread(_objectSpread({}, data), {}, {
|
|
83
|
-
from,
|
|
84
|
-
to
|
|
85
|
-
}));
|
|
86
|
-
});
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
absolutePositionToRelativePosition(pos) {
|
|
91
|
-
var mapping = this.getMapping();
|
|
92
|
-
return yProsemirror.absolutePositionToRelativePosition(pos, this.type, mapping);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
relativePositionToAbsolutePosition(relPos) {
|
|
96
|
-
var mapping = this.getMapping();
|
|
97
|
-
return yProsemirror.relativePositionToAbsolutePosition(this.doc, this.type, relPos, mapping);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* The YJS extension is the recommended extension for creating a collaborative
|
|
103
|
-
* editor.
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
12
|
var YjsExtension = (_dec = core.extension({
|
|
108
13
|
defaultOptions: {
|
|
109
14
|
getProvider: () => {
|
|
@@ -115,6 +20,7 @@ var YjsExtension = (_dec = core.extension({
|
|
|
115
20
|
destroyProvider: defaultDestroyProvider,
|
|
116
21
|
syncPluginOptions: undefined,
|
|
117
22
|
cursorBuilder: yProsemirror.defaultCursorBuilder,
|
|
23
|
+
selectionBuilder: yProsemirror.defaultSelectionBuilder,
|
|
118
24
|
cursorStateField: 'cursor',
|
|
119
25
|
getSelection: state => state.selection,
|
|
120
26
|
disableUndo: false,
|
|
@@ -125,23 +31,23 @@ var YjsExtension = (_dec = core.extension({
|
|
|
125
31
|
defaultPriority: core.ExtensionPriority.High
|
|
126
32
|
}), _dec2 = core.command({
|
|
127
33
|
disableChaining: true,
|
|
128
|
-
description:
|
|
129
|
-
var t =
|
|
34
|
+
description: _ref => {
|
|
35
|
+
var t = _ref.t;
|
|
130
36
|
return t(messages.ExtensionHistoryMessages.UNDO_DESCRIPTION);
|
|
131
37
|
},
|
|
132
|
-
label:
|
|
133
|
-
var t =
|
|
38
|
+
label: _ref2 => {
|
|
39
|
+
var t = _ref2.t;
|
|
134
40
|
return t(messages.ExtensionHistoryMessages.UNDO_LABEL);
|
|
135
41
|
},
|
|
136
42
|
icon: 'arrowGoBackFill'
|
|
137
43
|
}), _dec3 = core.command({
|
|
138
44
|
disableChaining: true,
|
|
139
|
-
description:
|
|
140
|
-
var t =
|
|
45
|
+
description: _ref3 => {
|
|
46
|
+
var t = _ref3.t;
|
|
141
47
|
return t(messages.ExtensionHistoryMessages.REDO_DESCRIPTION);
|
|
142
48
|
},
|
|
143
|
-
label:
|
|
144
|
-
var t =
|
|
49
|
+
label: _ref4 => {
|
|
50
|
+
var t = _ref4.t;
|
|
145
51
|
return t(messages.ExtensionHistoryMessages.REDO_LABEL);
|
|
146
52
|
},
|
|
147
53
|
icon: 'arrowGoForwardFill'
|
|
@@ -174,36 +80,6 @@ var YjsExtension = (_dec = core.extension({
|
|
|
174
80
|
|
|
175
81
|
return binding;
|
|
176
82
|
}
|
|
177
|
-
|
|
178
|
-
onView() {
|
|
179
|
-
try {
|
|
180
|
-
var annotationStore = new YjsAnnotationStore(this.provider.doc, 'prosemirror', 'annotations', () => {
|
|
181
|
-
var _this$getBinding;
|
|
182
|
-
|
|
183
|
-
return (_this$getBinding = this.getBinding()) === null || _this$getBinding === void 0 ? void 0 : _this$getBinding.mapping;
|
|
184
|
-
});
|
|
185
|
-
this.store.manager.getExtension(extensionAnnotation.AnnotationExtension).setOptions({
|
|
186
|
-
getStore: () => annotationStore
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
var handler = (_update, _origin, _doc, yjsTr) => {
|
|
190
|
-
var _this$store$commands$, _this$store$commands;
|
|
191
|
-
|
|
192
|
-
// Ignore own changes
|
|
193
|
-
if (yjsTr.local) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
(_this$store$commands$ = (_this$store$commands = this.store.commands).redrawAnnotations) === null || _this$store$commands$ === void 0 ? void 0 : _this$store$commands$.call(_this$store$commands);
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
this.provider.doc.on('update', handler);
|
|
201
|
-
return () => {
|
|
202
|
-
this.provider.doc.off('update', handler);
|
|
203
|
-
};
|
|
204
|
-
} catch (_unused) {// AnnotationExtension isn't present in editor
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
83
|
/**
|
|
208
84
|
* Create the yjs plugins.
|
|
209
85
|
*/
|
|
@@ -217,13 +93,14 @@ var YjsExtension = (_dec = core.extension({
|
|
|
217
93
|
cursorStateField = _this$options.cursorStateField,
|
|
218
94
|
disableUndo = _this$options.disableUndo,
|
|
219
95
|
protectedNodes = _this$options.protectedNodes,
|
|
220
|
-
trackedOrigins = _this$options.trackedOrigins
|
|
96
|
+
trackedOrigins = _this$options.trackedOrigins,
|
|
97
|
+
selectionBuilder = _this$options.selectionBuilder;
|
|
221
98
|
var yDoc = this.provider.doc;
|
|
222
99
|
var type = yDoc.getXmlFragment('prosemirror');
|
|
223
100
|
var plugins = [yProsemirror.ySyncPlugin(type, syncPluginOptions), yProsemirror.yCursorPlugin(this.provider.awareness, {
|
|
224
101
|
cursorBuilder,
|
|
225
|
-
|
|
226
|
-
|
|
102
|
+
getSelection,
|
|
103
|
+
selectionBuilder
|
|
227
104
|
}, cursorStateField)];
|
|
228
105
|
|
|
229
106
|
if (!disableUndo) {
|
|
@@ -3,107 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var _applyDecoratedDescriptor = require('@babel/runtime/helpers/applyDecoratedDescriptor');
|
|
6
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
7
|
-
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
8
6
|
var yProsemirror = require('y-prosemirror');
|
|
9
7
|
var yjs = require('yjs');
|
|
10
8
|
var core = require('@remirror/core');
|
|
11
|
-
var extensionAnnotation = require('@remirror/extension-annotation');
|
|
12
9
|
var messages = require('@remirror/messages');
|
|
13
10
|
|
|
14
11
|
var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2;
|
|
15
|
-
|
|
16
|
-
var _excluded = ["from", "to"],
|
|
17
|
-
_excluded2 = ["from", "to"];
|
|
18
|
-
|
|
19
|
-
class YjsAnnotationStore {
|
|
20
|
-
constructor(doc, pmName, mapName, getMapping) {
|
|
21
|
-
this.doc = doc;
|
|
22
|
-
this.getMapping = getMapping;
|
|
23
|
-
this.type = doc.getXmlFragment(pmName);
|
|
24
|
-
this.map = doc.getMap(mapName);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
addAnnotation(_ref) {
|
|
28
|
-
var from = _ref.from,
|
|
29
|
-
to = _ref.to,
|
|
30
|
-
data = _objectWithoutProperties(_ref, _excluded);
|
|
31
|
-
|
|
32
|
-
// XXX: Why is this cast needed?
|
|
33
|
-
var storedData = _objectSpread(_objectSpread({}, data), {}, {
|
|
34
|
-
from: this.absolutePositionToRelativePosition(from),
|
|
35
|
-
to: this.absolutePositionToRelativePosition(to)
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
this.map.set(data.id, storedData);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
updateAnnotation(id, updateData) {
|
|
42
|
-
var existing = this.map.get(id);
|
|
43
|
-
|
|
44
|
-
if (!existing) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
this.map.set(id, _objectSpread(_objectSpread({}, updateData), {}, {
|
|
49
|
-
from: existing.from,
|
|
50
|
-
to: existing.to
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
removeAnnotations(ids) {
|
|
55
|
-
yjs.transact(this.doc, () => {
|
|
56
|
-
ids.forEach(id => this.map.delete(id));
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
setAnnotations(annotations) {
|
|
61
|
-
yjs.transact(this.doc, () => {
|
|
62
|
-
this.map.clear();
|
|
63
|
-
annotations.forEach(annotation => this.addAnnotation(annotation));
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
formatAnnotations() {
|
|
68
|
-
var result = [];
|
|
69
|
-
this.map.forEach(_ref2 => {
|
|
70
|
-
var relFrom = _ref2.from,
|
|
71
|
-
relTo = _ref2.to,
|
|
72
|
-
data = _objectWithoutProperties(_ref2, _excluded2);
|
|
73
|
-
|
|
74
|
-
var from = this.relativePositionToAbsolutePosition(relFrom);
|
|
75
|
-
var to = this.relativePositionToAbsolutePosition(relTo);
|
|
76
|
-
|
|
77
|
-
if (!from || !to) {
|
|
78
|
-
return;
|
|
79
|
-
} // XXX: Why is this cast needed?
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
result.push(_objectSpread(_objectSpread({}, data), {}, {
|
|
83
|
-
from,
|
|
84
|
-
to
|
|
85
|
-
}));
|
|
86
|
-
});
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
absolutePositionToRelativePosition(pos) {
|
|
91
|
-
var mapping = this.getMapping();
|
|
92
|
-
return yProsemirror.absolutePositionToRelativePosition(pos, this.type, mapping);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
relativePositionToAbsolutePosition(relPos) {
|
|
96
|
-
var mapping = this.getMapping();
|
|
97
|
-
return yProsemirror.relativePositionToAbsolutePosition(this.doc, this.type, relPos, mapping);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* The YJS extension is the recommended extension for creating a collaborative
|
|
103
|
-
* editor.
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
12
|
var YjsExtension = (_dec = core.extension({
|
|
108
13
|
defaultOptions: {
|
|
109
14
|
getProvider: () => {
|
|
@@ -112,6 +17,7 @@ var YjsExtension = (_dec = core.extension({
|
|
|
112
17
|
destroyProvider: defaultDestroyProvider,
|
|
113
18
|
syncPluginOptions: undefined,
|
|
114
19
|
cursorBuilder: yProsemirror.defaultCursorBuilder,
|
|
20
|
+
selectionBuilder: yProsemirror.defaultSelectionBuilder,
|
|
115
21
|
cursorStateField: 'cursor',
|
|
116
22
|
getSelection: state => state.selection,
|
|
117
23
|
disableUndo: false,
|
|
@@ -122,23 +28,23 @@ var YjsExtension = (_dec = core.extension({
|
|
|
122
28
|
defaultPriority: core.ExtensionPriority.High
|
|
123
29
|
}), _dec2 = core.command({
|
|
124
30
|
disableChaining: true,
|
|
125
|
-
description:
|
|
126
|
-
var t =
|
|
31
|
+
description: _ref => {
|
|
32
|
+
var t = _ref.t;
|
|
127
33
|
return t(messages.ExtensionHistoryMessages.UNDO_DESCRIPTION);
|
|
128
34
|
},
|
|
129
|
-
label:
|
|
130
|
-
var t =
|
|
35
|
+
label: _ref2 => {
|
|
36
|
+
var t = _ref2.t;
|
|
131
37
|
return t(messages.ExtensionHistoryMessages.UNDO_LABEL);
|
|
132
38
|
},
|
|
133
39
|
icon: 'arrowGoBackFill'
|
|
134
40
|
}), _dec3 = core.command({
|
|
135
41
|
disableChaining: true,
|
|
136
|
-
description:
|
|
137
|
-
var t =
|
|
42
|
+
description: _ref3 => {
|
|
43
|
+
var t = _ref3.t;
|
|
138
44
|
return t(messages.ExtensionHistoryMessages.REDO_DESCRIPTION);
|
|
139
45
|
},
|
|
140
|
-
label:
|
|
141
|
-
var t =
|
|
46
|
+
label: _ref4 => {
|
|
47
|
+
var t = _ref4.t;
|
|
142
48
|
return t(messages.ExtensionHistoryMessages.REDO_LABEL);
|
|
143
49
|
},
|
|
144
50
|
icon: 'arrowGoForwardFill'
|
|
@@ -171,36 +77,6 @@ var YjsExtension = (_dec = core.extension({
|
|
|
171
77
|
|
|
172
78
|
return binding;
|
|
173
79
|
}
|
|
174
|
-
|
|
175
|
-
onView() {
|
|
176
|
-
try {
|
|
177
|
-
var annotationStore = new YjsAnnotationStore(this.provider.doc, 'prosemirror', 'annotations', () => {
|
|
178
|
-
var _this$getBinding;
|
|
179
|
-
|
|
180
|
-
return (_this$getBinding = this.getBinding()) === null || _this$getBinding === void 0 ? void 0 : _this$getBinding.mapping;
|
|
181
|
-
});
|
|
182
|
-
this.store.manager.getExtension(extensionAnnotation.AnnotationExtension).setOptions({
|
|
183
|
-
getStore: () => annotationStore
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
var handler = (_update, _origin, _doc, yjsTr) => {
|
|
187
|
-
var _this$store$commands$, _this$store$commands;
|
|
188
|
-
|
|
189
|
-
// Ignore own changes
|
|
190
|
-
if (yjsTr.local) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
(_this$store$commands$ = (_this$store$commands = this.store.commands).redrawAnnotations) === null || _this$store$commands$ === void 0 ? void 0 : _this$store$commands$.call(_this$store$commands);
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
this.provider.doc.on('update', handler);
|
|
198
|
-
return () => {
|
|
199
|
-
this.provider.doc.off('update', handler);
|
|
200
|
-
};
|
|
201
|
-
} catch (_unused) {// AnnotationExtension isn't present in editor
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
80
|
/**
|
|
205
81
|
* Create the yjs plugins.
|
|
206
82
|
*/
|
|
@@ -214,13 +90,14 @@ var YjsExtension = (_dec = core.extension({
|
|
|
214
90
|
cursorStateField = _this$options.cursorStateField,
|
|
215
91
|
disableUndo = _this$options.disableUndo,
|
|
216
92
|
protectedNodes = _this$options.protectedNodes,
|
|
217
|
-
trackedOrigins = _this$options.trackedOrigins
|
|
93
|
+
trackedOrigins = _this$options.trackedOrigins,
|
|
94
|
+
selectionBuilder = _this$options.selectionBuilder;
|
|
218
95
|
var yDoc = this.provider.doc;
|
|
219
96
|
var type = yDoc.getXmlFragment('prosemirror');
|
|
220
97
|
var plugins = [yProsemirror.ySyncPlugin(type, syncPluginOptions), yProsemirror.yCursorPlugin(this.provider.awareness, {
|
|
221
98
|
cursorBuilder,
|
|
222
|
-
|
|
223
|
-
|
|
99
|
+
getSelection,
|
|
100
|
+
selectionBuilder
|
|
224
101
|
}, cursorStateField)];
|
|
225
102
|
|
|
226
103
|
if (!disableUndo) {
|
|
@@ -1,105 +1,10 @@
|
|
|
1
1
|
import _applyDecoratedDescriptor from '@babel/runtime/helpers/esm/applyDecoratedDescriptor';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { defaultCursorBuilder, ySyncPluginKey, ySyncPlugin, yCursorPlugin, defaultDeleteFilter, yUndoPlugin, yUndoPluginKey, undo, redo, absolutePositionToRelativePosition, relativePositionToAbsolutePosition } from 'y-prosemirror';
|
|
5
|
-
import { UndoManager, transact } from 'yjs';
|
|
2
|
+
import { defaultCursorBuilder, defaultSelectionBuilder, ySyncPluginKey, ySyncPlugin, yCursorPlugin, defaultDeleteFilter, yUndoPlugin, yUndoPluginKey, undo, redo } from 'y-prosemirror';
|
|
3
|
+
import { UndoManager } from 'yjs';
|
|
6
4
|
import { extension, invariant, ErrorConstant, ExtensionPriority, command, keyBinding, NamedShortcut, PlainExtension, isFunction, isEmptyObject, nonChainable, convertCommand } from '@remirror/core';
|
|
7
|
-
import { AnnotationExtension } from '@remirror/extension-annotation';
|
|
8
5
|
import { ExtensionHistoryMessages } from '@remirror/messages';
|
|
9
6
|
|
|
10
7
|
var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2;
|
|
11
|
-
|
|
12
|
-
var _excluded = ["from", "to"],
|
|
13
|
-
_excluded2 = ["from", "to"];
|
|
14
|
-
|
|
15
|
-
class YjsAnnotationStore {
|
|
16
|
-
constructor(doc, pmName, mapName, getMapping) {
|
|
17
|
-
this.doc = doc;
|
|
18
|
-
this.getMapping = getMapping;
|
|
19
|
-
this.type = doc.getXmlFragment(pmName);
|
|
20
|
-
this.map = doc.getMap(mapName);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
addAnnotation(_ref) {
|
|
24
|
-
var from = _ref.from,
|
|
25
|
-
to = _ref.to,
|
|
26
|
-
data = _objectWithoutProperties(_ref, _excluded);
|
|
27
|
-
|
|
28
|
-
// XXX: Why is this cast needed?
|
|
29
|
-
var storedData = _objectSpread(_objectSpread({}, data), {}, {
|
|
30
|
-
from: this.absolutePositionToRelativePosition(from),
|
|
31
|
-
to: this.absolutePositionToRelativePosition(to)
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
this.map.set(data.id, storedData);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
updateAnnotation(id, updateData) {
|
|
38
|
-
var existing = this.map.get(id);
|
|
39
|
-
|
|
40
|
-
if (!existing) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
this.map.set(id, _objectSpread(_objectSpread({}, updateData), {}, {
|
|
45
|
-
from: existing.from,
|
|
46
|
-
to: existing.to
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
removeAnnotations(ids) {
|
|
51
|
-
transact(this.doc, () => {
|
|
52
|
-
ids.forEach(id => this.map.delete(id));
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
setAnnotations(annotations) {
|
|
57
|
-
transact(this.doc, () => {
|
|
58
|
-
this.map.clear();
|
|
59
|
-
annotations.forEach(annotation => this.addAnnotation(annotation));
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
formatAnnotations() {
|
|
64
|
-
var result = [];
|
|
65
|
-
this.map.forEach(_ref2 => {
|
|
66
|
-
var relFrom = _ref2.from,
|
|
67
|
-
relTo = _ref2.to,
|
|
68
|
-
data = _objectWithoutProperties(_ref2, _excluded2);
|
|
69
|
-
|
|
70
|
-
var from = this.relativePositionToAbsolutePosition(relFrom);
|
|
71
|
-
var to = this.relativePositionToAbsolutePosition(relTo);
|
|
72
|
-
|
|
73
|
-
if (!from || !to) {
|
|
74
|
-
return;
|
|
75
|
-
} // XXX: Why is this cast needed?
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
result.push(_objectSpread(_objectSpread({}, data), {}, {
|
|
79
|
-
from,
|
|
80
|
-
to
|
|
81
|
-
}));
|
|
82
|
-
});
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
absolutePositionToRelativePosition(pos) {
|
|
87
|
-
var mapping = this.getMapping();
|
|
88
|
-
return absolutePositionToRelativePosition(pos, this.type, mapping);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
relativePositionToAbsolutePosition(relPos) {
|
|
92
|
-
var mapping = this.getMapping();
|
|
93
|
-
return relativePositionToAbsolutePosition(this.doc, this.type, relPos, mapping);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* The YJS extension is the recommended extension for creating a collaborative
|
|
99
|
-
* editor.
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
8
|
var YjsExtension = (_dec = extension({
|
|
104
9
|
defaultOptions: {
|
|
105
10
|
getProvider: () => {
|
|
@@ -111,6 +16,7 @@ var YjsExtension = (_dec = extension({
|
|
|
111
16
|
destroyProvider: defaultDestroyProvider,
|
|
112
17
|
syncPluginOptions: undefined,
|
|
113
18
|
cursorBuilder: defaultCursorBuilder,
|
|
19
|
+
selectionBuilder: defaultSelectionBuilder,
|
|
114
20
|
cursorStateField: 'cursor',
|
|
115
21
|
getSelection: state => state.selection,
|
|
116
22
|
disableUndo: false,
|
|
@@ -121,23 +27,23 @@ var YjsExtension = (_dec = extension({
|
|
|
121
27
|
defaultPriority: ExtensionPriority.High
|
|
122
28
|
}), _dec2 = command({
|
|
123
29
|
disableChaining: true,
|
|
124
|
-
description:
|
|
125
|
-
var t =
|
|
30
|
+
description: _ref => {
|
|
31
|
+
var t = _ref.t;
|
|
126
32
|
return t(ExtensionHistoryMessages.UNDO_DESCRIPTION);
|
|
127
33
|
},
|
|
128
|
-
label:
|
|
129
|
-
var t =
|
|
34
|
+
label: _ref2 => {
|
|
35
|
+
var t = _ref2.t;
|
|
130
36
|
return t(ExtensionHistoryMessages.UNDO_LABEL);
|
|
131
37
|
},
|
|
132
38
|
icon: 'arrowGoBackFill'
|
|
133
39
|
}), _dec3 = command({
|
|
134
40
|
disableChaining: true,
|
|
135
|
-
description:
|
|
136
|
-
var t =
|
|
41
|
+
description: _ref3 => {
|
|
42
|
+
var t = _ref3.t;
|
|
137
43
|
return t(ExtensionHistoryMessages.REDO_DESCRIPTION);
|
|
138
44
|
},
|
|
139
|
-
label:
|
|
140
|
-
var t =
|
|
45
|
+
label: _ref4 => {
|
|
46
|
+
var t = _ref4.t;
|
|
141
47
|
return t(ExtensionHistoryMessages.REDO_LABEL);
|
|
142
48
|
},
|
|
143
49
|
icon: 'arrowGoForwardFill'
|
|
@@ -170,36 +76,6 @@ var YjsExtension = (_dec = extension({
|
|
|
170
76
|
|
|
171
77
|
return binding;
|
|
172
78
|
}
|
|
173
|
-
|
|
174
|
-
onView() {
|
|
175
|
-
try {
|
|
176
|
-
var annotationStore = new YjsAnnotationStore(this.provider.doc, 'prosemirror', 'annotations', () => {
|
|
177
|
-
var _this$getBinding;
|
|
178
|
-
|
|
179
|
-
return (_this$getBinding = this.getBinding()) === null || _this$getBinding === void 0 ? void 0 : _this$getBinding.mapping;
|
|
180
|
-
});
|
|
181
|
-
this.store.manager.getExtension(AnnotationExtension).setOptions({
|
|
182
|
-
getStore: () => annotationStore
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
var handler = (_update, _origin, _doc, yjsTr) => {
|
|
186
|
-
var _this$store$commands$, _this$store$commands;
|
|
187
|
-
|
|
188
|
-
// Ignore own changes
|
|
189
|
-
if (yjsTr.local) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
(_this$store$commands$ = (_this$store$commands = this.store.commands).redrawAnnotations) === null || _this$store$commands$ === void 0 ? void 0 : _this$store$commands$.call(_this$store$commands);
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
this.provider.doc.on('update', handler);
|
|
197
|
-
return () => {
|
|
198
|
-
this.provider.doc.off('update', handler);
|
|
199
|
-
};
|
|
200
|
-
} catch (_unused) {// AnnotationExtension isn't present in editor
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
79
|
/**
|
|
204
80
|
* Create the yjs plugins.
|
|
205
81
|
*/
|
|
@@ -213,13 +89,14 @@ var YjsExtension = (_dec = extension({
|
|
|
213
89
|
cursorStateField = _this$options.cursorStateField,
|
|
214
90
|
disableUndo = _this$options.disableUndo,
|
|
215
91
|
protectedNodes = _this$options.protectedNodes,
|
|
216
|
-
trackedOrigins = _this$options.trackedOrigins
|
|
92
|
+
trackedOrigins = _this$options.trackedOrigins,
|
|
93
|
+
selectionBuilder = _this$options.selectionBuilder;
|
|
217
94
|
var yDoc = this.provider.doc;
|
|
218
95
|
var type = yDoc.getXmlFragment('prosemirror');
|
|
219
96
|
var plugins = [ySyncPlugin(type, syncPluginOptions), yCursorPlugin(this.provider.awareness, {
|
|
220
97
|
cursorBuilder,
|
|
221
|
-
|
|
222
|
-
|
|
98
|
+
getSelection,
|
|
99
|
+
selectionBuilder
|
|
223
100
|
}, cursorStateField)];
|
|
224
101
|
|
|
225
102
|
if (!disableUndo) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remirror/extension-yjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Realtime collaboration with yjs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"remirror",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"./package.json": "./package.json",
|
|
33
33
|
"./types/*": "./dist/declarations/src/*.d.ts"
|
|
34
34
|
},
|
|
35
|
-
"main": "
|
|
36
|
-
"module": "
|
|
35
|
+
"main": "dist/remirror-extension-yjs.cjs.js",
|
|
36
|
+
"module": "dist/remirror-extension-yjs.esm.js",
|
|
37
37
|
"browser": {
|
|
38
38
|
"./dist/remirror-extension-yjs.cjs.js": "./dist/remirror-extension-yjs.browser.cjs.js",
|
|
39
39
|
"./dist/remirror-extension-yjs.esm.js": "./dist/remirror-extension-yjs.browser.esm.js"
|
|
@@ -44,19 +44,18 @@
|
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/runtime": "^7.13.10",
|
|
47
|
-
"@remirror/core": "^1.4.
|
|
48
|
-
"@remirror/extension-annotation": "^1.1.21",
|
|
47
|
+
"@remirror/core": "^1.4.4",
|
|
49
48
|
"@remirror/messages": "^1.0.6",
|
|
50
|
-
"y-prosemirror": "^1.0.
|
|
49
|
+
"y-prosemirror": "^1.0.19",
|
|
51
50
|
"y-protocols": "^1.0.5"
|
|
52
51
|
},
|
|
53
52
|
"devDependencies": {
|
|
54
|
-
"@remirror/pm": "^1.0.
|
|
53
|
+
"@remirror/pm": "^1.0.19",
|
|
55
54
|
"y-webrtc": "^10.2.2",
|
|
56
55
|
"yjs": "^13.5.23"
|
|
57
56
|
},
|
|
58
57
|
"peerDependencies": {
|
|
59
|
-
"@remirror/pm": "^1.0.
|
|
58
|
+
"@remirror/pm": "^1.0.18",
|
|
60
59
|
"yjs": "^13.4.0"
|
|
61
60
|
},
|
|
62
61
|
"publishConfig": {
|