@remirror/extension-yjs 1.0.19 → 1.0.23

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.
@@ -3,6 +3,8 @@
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');
6
8
  var yProsemirror = require('y-prosemirror');
7
9
  var yjs = require('yjs');
8
10
  var core = require('@remirror/core');
@@ -10,6 +12,98 @@ var extensionAnnotation = require('@remirror/extension-annotation');
10
12
  var messages = require('@remirror/messages');
11
13
 
12
14
  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
+
13
107
  var YjsExtension = (_dec = core.extension({
14
108
  defaultOptions: {
15
109
  getProvider: () => {
@@ -20,29 +114,31 @@ var YjsExtension = (_dec = core.extension({
20
114
  cursorBuilder: yProsemirror.defaultCursorBuilder,
21
115
  cursorStateField: 'cursor',
22
116
  getSelection: state => state.selection,
117
+ disableUndo: false,
23
118
  protectedNodes: new Set('paragraph'),
24
119
  trackedOrigins: []
25
120
  },
121
+ staticKeys: ['disableUndo', 'protectedNodes', 'trackedOrigins'],
26
122
  defaultPriority: core.ExtensionPriority.High
27
123
  }), _dec2 = core.command({
28
124
  disableChaining: true,
29
- description: _ref => {
30
- var t = _ref.t;
125
+ description: _ref3 => {
126
+ var t = _ref3.t;
31
127
  return t(messages.ExtensionHistoryMessages.UNDO_DESCRIPTION);
32
128
  },
33
- label: _ref2 => {
34
- var t = _ref2.t;
129
+ label: _ref4 => {
130
+ var t = _ref4.t;
35
131
  return t(messages.ExtensionHistoryMessages.UNDO_LABEL);
36
132
  },
37
133
  icon: 'arrowGoBackFill'
38
134
  }), _dec3 = core.command({
39
135
  disableChaining: true,
40
- description: _ref3 => {
41
- var t = _ref3.t;
136
+ description: _ref5 => {
137
+ var t = _ref5.t;
42
138
  return t(messages.ExtensionHistoryMessages.REDO_DESCRIPTION);
43
139
  },
44
- label: _ref4 => {
45
- var t = _ref4.t;
140
+ label: _ref6 => {
141
+ var t = _ref6.t;
46
142
  return t(messages.ExtensionHistoryMessages.REDO_LABEL);
47
143
  },
48
144
  icon: 'arrowGoForwardFill'
@@ -67,14 +163,27 @@ var YjsExtension = (_dec = core.extension({
67
163
  return (_this$_provider = this._provider) !== null && _this$_provider !== void 0 ? _this$_provider : this._provider = getLazyValue(getProvider);
68
164
  }
69
165
 
166
+ getBinding() {
167
+ var state = this.store.getState();
168
+
169
+ var _ySyncPluginKey$getSt = yProsemirror.ySyncPluginKey.getState(state),
170
+ binding = _ySyncPluginKey$getSt.binding;
171
+
172
+ return binding;
173
+ }
174
+
70
175
  onView() {
71
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
+ });
72
182
  this.store.manager.getExtension(extensionAnnotation.AnnotationExtension).setOptions({
73
- getMap: () => this.provider.doc.getMap('annotations'),
74
- transformPosition: this.absolutePositionToRelativePosition.bind(this),
75
- transformPositionBeforeRender: this.relativePositionToAbsolutePosition.bind(this)
183
+ getStore: () => annotationStore
76
184
  });
77
- this.provider.doc.on('update', (_update, _origin, _doc, yjsTr) => {
185
+
186
+ var handler = (_update, _origin, _doc, yjsTr) => {
78
187
  var _this$store$commands$, _this$store$commands;
79
188
 
80
189
  // Ignore own changes
@@ -83,7 +192,12 @@ var YjsExtension = (_dec = core.extension({
83
192
  }
84
193
 
85
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);
86
- });
195
+ };
196
+
197
+ this.provider.doc.on('update', handler);
198
+ return () => {
199
+ this.provider.doc.off('update', handler);
200
+ };
87
201
  } catch (_unused) {// AnnotationExtension isn't present in editor
88
202
  }
89
203
  }
@@ -98,21 +212,28 @@ var YjsExtension = (_dec = core.extension({
98
212
  cursorBuilder = _this$options.cursorBuilder,
99
213
  getSelection = _this$options.getSelection,
100
214
  cursorStateField = _this$options.cursorStateField,
215
+ disableUndo = _this$options.disableUndo,
101
216
  protectedNodes = _this$options.protectedNodes,
102
217
  trackedOrigins = _this$options.trackedOrigins;
103
218
  var yDoc = this.provider.doc;
104
219
  var type = yDoc.getXmlFragment('prosemirror');
105
- var undoManager = new yjs.UndoManager(type, {
106
- trackedOrigins: new Set([yProsemirror.ySyncPluginKey, ...trackedOrigins]),
107
- deleteFilter: item => yProsemirror.defaultDeleteFilter(item, protectedNodes)
108
- });
109
- return [yProsemirror.ySyncPlugin(type, syncPluginOptions), yProsemirror.yCursorPlugin(this.provider.awareness, {
220
+ var plugins = [yProsemirror.ySyncPlugin(type, syncPluginOptions), yProsemirror.yCursorPlugin(this.provider.awareness, {
110
221
  cursorBuilder,
111
222
  cursorStateField,
112
223
  getSelection
113
- }, cursorStateField), yProsemirror.yUndoPlugin({
114
- undoManager
115
- })];
224
+ }, cursorStateField)];
225
+
226
+ if (!disableUndo) {
227
+ var undoManager = new yjs.UndoManager(type, {
228
+ trackedOrigins: new Set([yProsemirror.ySyncPluginKey, ...trackedOrigins]),
229
+ deleteFilter: item => yProsemirror.defaultDeleteFilter(item, protectedNodes)
230
+ });
231
+ plugins.push(yProsemirror.yUndoPlugin({
232
+ undoManager
233
+ }));
234
+ }
235
+
236
+ return plugins;
116
237
  }
117
238
  /**
118
239
  * This managers the updates of the collaboration provider.
@@ -122,14 +243,7 @@ var YjsExtension = (_dec = core.extension({
122
243
  onSetOptions(props) {
123
244
  var changes = props.changes,
124
245
  pickChanged = props.pickChanged;
125
- var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions', 'protectedNodes', 'trackedOrigins']);
126
-
127
- if (changes.protectedNodes.changed || changes.trackedOrigins.changed) {
128
- // Cannot change these, as we would need a new undo manager instance, and for that
129
- // we would need to unregister the previous instance from the document to avoid
130
- // memory leaks.
131
- throw new Error("Cannot change \"protectedNodes\" or \"trackedOrigins\" options");
132
- }
246
+ var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions']);
133
247
 
134
248
  if (changes.getProvider.changed) {
135
249
  this._provider = undefined;
@@ -162,16 +276,19 @@ var YjsExtension = (_dec = core.extension({
162
276
  this._provider = undefined;
163
277
  }
164
278
  /**
165
- * Undo within a collaborative editor.
166
- *
167
- * This should be used instead of the built in `undo` command.
279
+ * Undo that last Yjs transaction(s)
168
280
  *
169
281
  * This command does **not** support chaining.
282
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
170
283
  */
171
284
 
172
285
 
173
286
  yUndo() {
174
287
  return core.nonChainable(props => {
288
+ if (this.options.disableUndo) {
289
+ return false;
290
+ }
291
+
175
292
  var state = props.state,
176
293
  dispatch = props.dispatch;
177
294
  var undoManager = yProsemirror.yUndoPluginKey.getState(state).undoManager;
@@ -188,16 +305,19 @@ var YjsExtension = (_dec = core.extension({
188
305
  });
189
306
  }
190
307
  /**
191
- * Redo, within a collaborative editor.
192
- *
193
- * This should be used instead of the built in `redo` command.
308
+ * Redo the last transaction undone with a previous `yUndo` command.
194
309
  *
195
310
  * This command does **not** support chaining.
311
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
196
312
  */
197
313
 
198
314
 
199
315
  yRedo() {
200
316
  return core.nonChainable(props => {
317
+ if (this.options.disableUndo) {
318
+ return false;
319
+ }
320
+
201
321
  var state = props.state,
202
322
  dispatch = props.dispatch;
203
323
  var undoManager = yProsemirror.yUndoPluginKey.getState(state).undoManager;
@@ -230,26 +350,6 @@ var YjsExtension = (_dec = core.extension({
230
350
  return this.yRedo()(props);
231
351
  }
232
352
 
233
- absolutePositionToRelativePosition(pos) {
234
- var state = this.store.getState();
235
-
236
- var _ySyncPluginKey$getSt = yProsemirror.ySyncPluginKey.getState(state),
237
- type = _ySyncPluginKey$getSt.type,
238
- binding = _ySyncPluginKey$getSt.binding;
239
-
240
- return yProsemirror.absolutePositionToRelativePosition(pos, type, binding.mapping);
241
- }
242
-
243
- relativePositionToAbsolutePosition(relPos) {
244
- var state = this.store.getState();
245
-
246
- var _ySyncPluginKey$getSt2 = yProsemirror.ySyncPluginKey.getState(state),
247
- type = _ySyncPluginKey$getSt2.type,
248
- binding = _ySyncPluginKey$getSt2.binding;
249
-
250
- return yProsemirror.relativePositionToAbsolutePosition(this.provider.doc, type, relPos, binding.mapping);
251
- }
252
-
253
353
  }, (_applyDecoratedDescriptor(_class2.prototype, "yUndo", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "yUndo"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "yRedo", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "yRedo"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "undoShortcut", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "undoShortcut"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "redoShortcut", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "redoShortcut"), _class2.prototype)), _class2)) || _class);
254
354
  /**
255
355
  * The default destroy provider method.
@@ -1,11 +1,105 @@
1
1
  import _applyDecoratedDescriptor from '@babel/runtime/helpers/esm/applyDecoratedDescriptor';
2
- import { defaultCursorBuilder, ySyncPluginKey, defaultDeleteFilter, ySyncPlugin, yCursorPlugin, yUndoPlugin, yUndoPluginKey, undo, redo, absolutePositionToRelativePosition, relativePositionToAbsolutePosition } from 'y-prosemirror';
3
- import { UndoManager } from 'yjs';
2
+ import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
3
+ import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
4
+ import { defaultCursorBuilder, ySyncPluginKey, ySyncPlugin, yCursorPlugin, defaultDeleteFilter, yUndoPlugin, yUndoPluginKey, undo, redo, absolutePositionToRelativePosition, relativePositionToAbsolutePosition } from 'y-prosemirror';
5
+ import { UndoManager, transact } from 'yjs';
4
6
  import { extension, invariant, ErrorConstant, ExtensionPriority, command, keyBinding, NamedShortcut, PlainExtension, isFunction, isEmptyObject, nonChainable, convertCommand } from '@remirror/core';
5
7
  import { AnnotationExtension } from '@remirror/extension-annotation';
6
8
  import { ExtensionHistoryMessages } from '@remirror/messages';
7
9
 
8
10
  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
+
9
103
  var YjsExtension = (_dec = extension({
10
104
  defaultOptions: {
11
105
  getProvider: () => {
@@ -19,29 +113,31 @@ var YjsExtension = (_dec = extension({
19
113
  cursorBuilder: defaultCursorBuilder,
20
114
  cursorStateField: 'cursor',
21
115
  getSelection: state => state.selection,
116
+ disableUndo: false,
22
117
  protectedNodes: new Set('paragraph'),
23
118
  trackedOrigins: []
24
119
  },
120
+ staticKeys: ['disableUndo', 'protectedNodes', 'trackedOrigins'],
25
121
  defaultPriority: ExtensionPriority.High
26
122
  }), _dec2 = command({
27
123
  disableChaining: true,
28
- description: _ref => {
29
- var t = _ref.t;
124
+ description: _ref3 => {
125
+ var t = _ref3.t;
30
126
  return t(ExtensionHistoryMessages.UNDO_DESCRIPTION);
31
127
  },
32
- label: _ref2 => {
33
- var t = _ref2.t;
128
+ label: _ref4 => {
129
+ var t = _ref4.t;
34
130
  return t(ExtensionHistoryMessages.UNDO_LABEL);
35
131
  },
36
132
  icon: 'arrowGoBackFill'
37
133
  }), _dec3 = command({
38
134
  disableChaining: true,
39
- description: _ref3 => {
40
- var t = _ref3.t;
135
+ description: _ref5 => {
136
+ var t = _ref5.t;
41
137
  return t(ExtensionHistoryMessages.REDO_DESCRIPTION);
42
138
  },
43
- label: _ref4 => {
44
- var t = _ref4.t;
139
+ label: _ref6 => {
140
+ var t = _ref6.t;
45
141
  return t(ExtensionHistoryMessages.REDO_LABEL);
46
142
  },
47
143
  icon: 'arrowGoForwardFill'
@@ -66,14 +162,27 @@ var YjsExtension = (_dec = extension({
66
162
  return (_this$_provider = this._provider) !== null && _this$_provider !== void 0 ? _this$_provider : this._provider = getLazyValue(getProvider);
67
163
  }
68
164
 
165
+ getBinding() {
166
+ var state = this.store.getState();
167
+
168
+ var _ySyncPluginKey$getSt = ySyncPluginKey.getState(state),
169
+ binding = _ySyncPluginKey$getSt.binding;
170
+
171
+ return binding;
172
+ }
173
+
69
174
  onView() {
70
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
+ });
71
181
  this.store.manager.getExtension(AnnotationExtension).setOptions({
72
- getMap: () => this.provider.doc.getMap('annotations'),
73
- transformPosition: this.absolutePositionToRelativePosition.bind(this),
74
- transformPositionBeforeRender: this.relativePositionToAbsolutePosition.bind(this)
182
+ getStore: () => annotationStore
75
183
  });
76
- this.provider.doc.on('update', (_update, _origin, _doc, yjsTr) => {
184
+
185
+ var handler = (_update, _origin, _doc, yjsTr) => {
77
186
  var _this$store$commands$, _this$store$commands;
78
187
 
79
188
  // Ignore own changes
@@ -82,7 +191,12 @@ var YjsExtension = (_dec = extension({
82
191
  }
83
192
 
84
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);
85
- });
194
+ };
195
+
196
+ this.provider.doc.on('update', handler);
197
+ return () => {
198
+ this.provider.doc.off('update', handler);
199
+ };
86
200
  } catch (_unused) {// AnnotationExtension isn't present in editor
87
201
  }
88
202
  }
@@ -97,21 +211,28 @@ var YjsExtension = (_dec = extension({
97
211
  cursorBuilder = _this$options.cursorBuilder,
98
212
  getSelection = _this$options.getSelection,
99
213
  cursorStateField = _this$options.cursorStateField,
214
+ disableUndo = _this$options.disableUndo,
100
215
  protectedNodes = _this$options.protectedNodes,
101
216
  trackedOrigins = _this$options.trackedOrigins;
102
217
  var yDoc = this.provider.doc;
103
218
  var type = yDoc.getXmlFragment('prosemirror');
104
- var undoManager = new UndoManager(type, {
105
- trackedOrigins: new Set([ySyncPluginKey, ...trackedOrigins]),
106
- deleteFilter: item => defaultDeleteFilter(item, protectedNodes)
107
- });
108
- return [ySyncPlugin(type, syncPluginOptions), yCursorPlugin(this.provider.awareness, {
219
+ var plugins = [ySyncPlugin(type, syncPluginOptions), yCursorPlugin(this.provider.awareness, {
109
220
  cursorBuilder,
110
221
  cursorStateField,
111
222
  getSelection
112
- }, cursorStateField), yUndoPlugin({
113
- undoManager
114
- })];
223
+ }, cursorStateField)];
224
+
225
+ if (!disableUndo) {
226
+ var undoManager = new UndoManager(type, {
227
+ trackedOrigins: new Set([ySyncPluginKey, ...trackedOrigins]),
228
+ deleteFilter: item => defaultDeleteFilter(item, protectedNodes)
229
+ });
230
+ plugins.push(yUndoPlugin({
231
+ undoManager
232
+ }));
233
+ }
234
+
235
+ return plugins;
115
236
  }
116
237
  /**
117
238
  * This managers the updates of the collaboration provider.
@@ -121,14 +242,7 @@ var YjsExtension = (_dec = extension({
121
242
  onSetOptions(props) {
122
243
  var changes = props.changes,
123
244
  pickChanged = props.pickChanged;
124
- var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions', 'protectedNodes', 'trackedOrigins']);
125
-
126
- if (changes.protectedNodes.changed || changes.trackedOrigins.changed) {
127
- // Cannot change these, as we would need a new undo manager instance, and for that
128
- // we would need to unregister the previous instance from the document to avoid
129
- // memory leaks.
130
- throw new Error("Cannot change \"protectedNodes\" or \"trackedOrigins\" options");
131
- }
245
+ var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions']);
132
246
 
133
247
  if (changes.getProvider.changed) {
134
248
  this._provider = undefined;
@@ -161,16 +275,19 @@ var YjsExtension = (_dec = extension({
161
275
  this._provider = undefined;
162
276
  }
163
277
  /**
164
- * Undo within a collaborative editor.
165
- *
166
- * This should be used instead of the built in `undo` command.
278
+ * Undo that last Yjs transaction(s)
167
279
  *
168
280
  * This command does **not** support chaining.
281
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
169
282
  */
170
283
 
171
284
 
172
285
  yUndo() {
173
286
  return nonChainable(props => {
287
+ if (this.options.disableUndo) {
288
+ return false;
289
+ }
290
+
174
291
  var state = props.state,
175
292
  dispatch = props.dispatch;
176
293
  var undoManager = yUndoPluginKey.getState(state).undoManager;
@@ -187,16 +304,19 @@ var YjsExtension = (_dec = extension({
187
304
  });
188
305
  }
189
306
  /**
190
- * Redo, within a collaborative editor.
191
- *
192
- * This should be used instead of the built in `redo` command.
307
+ * Redo the last transaction undone with a previous `yUndo` command.
193
308
  *
194
309
  * This command does **not** support chaining.
310
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
195
311
  */
196
312
 
197
313
 
198
314
  yRedo() {
199
315
  return nonChainable(props => {
316
+ if (this.options.disableUndo) {
317
+ return false;
318
+ }
319
+
200
320
  var state = props.state,
201
321
  dispatch = props.dispatch;
202
322
  var undoManager = yUndoPluginKey.getState(state).undoManager;
@@ -229,26 +349,6 @@ var YjsExtension = (_dec = extension({
229
349
  return this.yRedo()(props);
230
350
  }
231
351
 
232
- absolutePositionToRelativePosition(pos) {
233
- var state = this.store.getState();
234
-
235
- var _ySyncPluginKey$getSt = ySyncPluginKey.getState(state),
236
- type = _ySyncPluginKey$getSt.type,
237
- binding = _ySyncPluginKey$getSt.binding;
238
-
239
- return absolutePositionToRelativePosition(pos, type, binding.mapping);
240
- }
241
-
242
- relativePositionToAbsolutePosition(relPos) {
243
- var state = this.store.getState();
244
-
245
- var _ySyncPluginKey$getSt2 = ySyncPluginKey.getState(state),
246
- type = _ySyncPluginKey$getSt2.type,
247
- binding = _ySyncPluginKey$getSt2.binding;
248
-
249
- return relativePositionToAbsolutePosition(this.provider.doc, type, relPos, binding.mapping);
250
- }
251
-
252
352
  }, (_applyDecoratedDescriptor(_class2.prototype, "yUndo", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "yUndo"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "yRedo", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "yRedo"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "undoShortcut", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "undoShortcut"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "redoShortcut", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "redoShortcut"), _class2.prototype)), _class2)) || _class);
253
353
  /**
254
354
  * The default destroy provider method.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remirror/extension-yjs",
3
- "version": "1.0.19",
3
+ "version": "1.0.23",
4
4
  "description": "Realtime collaboration with yjs",
5
5
  "keywords": [
6
6
  "remirror",
@@ -44,14 +44,14 @@
44
44
  ],
45
45
  "dependencies": {
46
46
  "@babel/runtime": "^7.13.10",
47
- "@remirror/core": "^1.3.3",
48
- "@remirror/extension-annotation": "^1.1.10",
47
+ "@remirror/core": "^1.3.5",
48
+ "@remirror/extension-annotation": "^1.1.14",
49
49
  "@remirror/messages": "^1.0.6",
50
50
  "y-prosemirror": "^1.0.14",
51
51
  "y-protocols": "^1.0.5"
52
52
  },
53
53
  "devDependencies": {
54
- "@remirror/pm": "^1.0.10",
54
+ "@remirror/pm": "^1.0.11",
55
55
  "y-webrtc": "^10.2.2",
56
56
  "yjs": "^13.5.23"
57
57
  },