@remirror/extension-yjs 1.0.22 → 1.0.25

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.
@@ -1,5 +1,5 @@
1
1
  import type { Doc } from 'yjs';
2
- import { AcceptUndefined, Dispose, EditorState, KeyBindingProps, NonChainableCommandFunction, OnSetOptionsProps, PlainExtension, ProsemirrorPlugin, Selection, Shape } from '@remirror/core';
2
+ import { AcceptUndefined, Dispose, EditorState, KeyBindingProps, NonChainableCommandFunction, OnSetOptionsProps, PlainExtension, ProsemirrorPlugin, Selection, Shape, Static } from '@remirror/core';
3
3
  export interface ColorDef {
4
4
  light: string;
5
5
  dark: string;
@@ -54,13 +54,14 @@ export interface YjsOptions<Provider extends YjsRealtimeProvider = YjsRealtimePr
54
54
  * @default `(state) => state.selection`
55
55
  */
56
56
  getSelection?: (state: EditorState) => Selection;
57
+ disableUndo?: Static<boolean>;
57
58
  /**
58
59
  * Names of nodes in the editor which should be protected.
59
60
  *
60
61
  * @default `new Set('paragraph')`
61
62
  */
62
- protectedNodes?: Set<string>;
63
- trackedOrigins?: any[];
63
+ protectedNodes?: Static<Set<string>>;
64
+ trackedOrigins?: Static<any[]>;
64
65
  }
65
66
  /**
66
67
  * The YJS extension is the recommended extension for creating a collaborative
@@ -90,19 +91,17 @@ export declare class YjsExtension extends PlainExtension<YjsOptions> {
90
91
  */
91
92
  onDestroy(): void;
92
93
  /**
93
- * Undo within a collaborative editor.
94
- *
95
- * This should be used instead of the built in `undo` command.
94
+ * Undo that last Yjs transaction(s)
96
95
  *
97
96
  * This command does **not** support chaining.
97
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
98
98
  */
99
99
  yUndo(): NonChainableCommandFunction;
100
100
  /**
101
- * Redo, within a collaborative editor.
102
- *
103
- * This should be used instead of the built in `redo` command.
101
+ * Redo the last transaction undone with a previous `yUndo` command.
104
102
  *
105
103
  * This command does **not** support chaining.
104
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
106
105
  */
107
106
  yRedo(): NonChainableCommandFunction;
108
107
  /**
@@ -117,9 +117,11 @@ var YjsExtension = (_dec = core.extension({
117
117
  cursorBuilder: yProsemirror.defaultCursorBuilder,
118
118
  cursorStateField: 'cursor',
119
119
  getSelection: state => state.selection,
120
+ disableUndo: false,
120
121
  protectedNodes: new Set('paragraph'),
121
122
  trackedOrigins: []
122
123
  },
124
+ staticKeys: ['disableUndo', 'protectedNodes', 'trackedOrigins'],
123
125
  defaultPriority: core.ExtensionPriority.High
124
126
  }), _dec2 = core.command({
125
127
  disableChaining: true,
@@ -213,21 +215,28 @@ var YjsExtension = (_dec = core.extension({
213
215
  cursorBuilder = _this$options.cursorBuilder,
214
216
  getSelection = _this$options.getSelection,
215
217
  cursorStateField = _this$options.cursorStateField,
218
+ disableUndo = _this$options.disableUndo,
216
219
  protectedNodes = _this$options.protectedNodes,
217
220
  trackedOrigins = _this$options.trackedOrigins;
218
221
  var yDoc = this.provider.doc;
219
222
  var type = yDoc.getXmlFragment('prosemirror');
220
- var undoManager = new yjs.UndoManager(type, {
221
- trackedOrigins: new Set([yProsemirror.ySyncPluginKey, ...trackedOrigins]),
222
- deleteFilter: item => yProsemirror.defaultDeleteFilter(item, protectedNodes)
223
- });
224
- return [yProsemirror.ySyncPlugin(type, syncPluginOptions), yProsemirror.yCursorPlugin(this.provider.awareness, {
223
+ var plugins = [yProsemirror.ySyncPlugin(type, syncPluginOptions), yProsemirror.yCursorPlugin(this.provider.awareness, {
225
224
  cursorBuilder,
226
225
  cursorStateField,
227
226
  getSelection
228
- }, cursorStateField), yProsemirror.yUndoPlugin({
229
- undoManager
230
- })];
227
+ }, cursorStateField)];
228
+
229
+ if (!disableUndo) {
230
+ var undoManager = new yjs.UndoManager(type, {
231
+ trackedOrigins: new Set([yProsemirror.ySyncPluginKey, ...trackedOrigins]),
232
+ deleteFilter: item => yProsemirror.defaultDeleteFilter(item, protectedNodes)
233
+ });
234
+ plugins.push(yProsemirror.yUndoPlugin({
235
+ undoManager
236
+ }));
237
+ }
238
+
239
+ return plugins;
231
240
  }
232
241
  /**
233
242
  * This managers the updates of the collaboration provider.
@@ -237,14 +246,7 @@ var YjsExtension = (_dec = core.extension({
237
246
  onSetOptions(props) {
238
247
  var changes = props.changes,
239
248
  pickChanged = props.pickChanged;
240
- var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions', 'protectedNodes', 'trackedOrigins']);
241
-
242
- if (changes.protectedNodes.changed || changes.trackedOrigins.changed) {
243
- // Cannot change these, as we would need a new undo manager instance, and for that
244
- // we would need to unregister the previous instance from the document to avoid
245
- // memory leaks.
246
- throw new Error("Cannot change \"protectedNodes\" or \"trackedOrigins\" options");
247
- }
249
+ var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions']);
248
250
 
249
251
  if (changes.getProvider.changed) {
250
252
  this._provider = undefined;
@@ -277,16 +279,19 @@ var YjsExtension = (_dec = core.extension({
277
279
  this._provider = undefined;
278
280
  }
279
281
  /**
280
- * Undo within a collaborative editor.
281
- *
282
- * This should be used instead of the built in `undo` command.
282
+ * Undo that last Yjs transaction(s)
283
283
  *
284
284
  * This command does **not** support chaining.
285
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
285
286
  */
286
287
 
287
288
 
288
289
  yUndo() {
289
290
  return core.nonChainable(props => {
291
+ if (this.options.disableUndo) {
292
+ return false;
293
+ }
294
+
290
295
  var state = props.state,
291
296
  dispatch = props.dispatch;
292
297
  var undoManager = yProsemirror.yUndoPluginKey.getState(state).undoManager;
@@ -303,16 +308,19 @@ var YjsExtension = (_dec = core.extension({
303
308
  });
304
309
  }
305
310
  /**
306
- * Redo, within a collaborative editor.
307
- *
308
- * This should be used instead of the built in `redo` command.
311
+ * Redo the last transaction undone with a previous `yUndo` command.
309
312
  *
310
313
  * This command does **not** support chaining.
314
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
311
315
  */
312
316
 
313
317
 
314
318
  yRedo() {
315
319
  return core.nonChainable(props => {
320
+ if (this.options.disableUndo) {
321
+ return false;
322
+ }
323
+
316
324
  var state = props.state,
317
325
  dispatch = props.dispatch;
318
326
  var undoManager = yProsemirror.yUndoPluginKey.getState(state).undoManager;
@@ -1,7 +1,7 @@
1
1
  import _applyDecoratedDescriptor from '@babel/runtime/helpers/esm/applyDecoratedDescriptor';
2
2
  import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
3
3
  import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
4
- import { defaultCursorBuilder, ySyncPluginKey, defaultDeleteFilter, ySyncPlugin, yCursorPlugin, yUndoPlugin, yUndoPluginKey, undo, redo, absolutePositionToRelativePosition, relativePositionToAbsolutePosition } from 'y-prosemirror';
4
+ import { defaultCursorBuilder, ySyncPluginKey, ySyncPlugin, yCursorPlugin, defaultDeleteFilter, yUndoPlugin, yUndoPluginKey, undo, redo, absolutePositionToRelativePosition, relativePositionToAbsolutePosition } from 'y-prosemirror';
5
5
  import { UndoManager, transact } from 'yjs';
6
6
  import { extension, invariant, ErrorConstant, ExtensionPriority, command, keyBinding, NamedShortcut, PlainExtension, isFunction, isEmptyObject, nonChainable, convertCommand } from '@remirror/core';
7
7
  import { AnnotationExtension } from '@remirror/extension-annotation';
@@ -113,9 +113,11 @@ var YjsExtension = (_dec = extension({
113
113
  cursorBuilder: defaultCursorBuilder,
114
114
  cursorStateField: 'cursor',
115
115
  getSelection: state => state.selection,
116
+ disableUndo: false,
116
117
  protectedNodes: new Set('paragraph'),
117
118
  trackedOrigins: []
118
119
  },
120
+ staticKeys: ['disableUndo', 'protectedNodes', 'trackedOrigins'],
119
121
  defaultPriority: ExtensionPriority.High
120
122
  }), _dec2 = command({
121
123
  disableChaining: true,
@@ -209,21 +211,28 @@ var YjsExtension = (_dec = extension({
209
211
  cursorBuilder = _this$options.cursorBuilder,
210
212
  getSelection = _this$options.getSelection,
211
213
  cursorStateField = _this$options.cursorStateField,
214
+ disableUndo = _this$options.disableUndo,
212
215
  protectedNodes = _this$options.protectedNodes,
213
216
  trackedOrigins = _this$options.trackedOrigins;
214
217
  var yDoc = this.provider.doc;
215
218
  var type = yDoc.getXmlFragment('prosemirror');
216
- var undoManager = new UndoManager(type, {
217
- trackedOrigins: new Set([ySyncPluginKey, ...trackedOrigins]),
218
- deleteFilter: item => defaultDeleteFilter(item, protectedNodes)
219
- });
220
- return [ySyncPlugin(type, syncPluginOptions), yCursorPlugin(this.provider.awareness, {
219
+ var plugins = [ySyncPlugin(type, syncPluginOptions), yCursorPlugin(this.provider.awareness, {
221
220
  cursorBuilder,
222
221
  cursorStateField,
223
222
  getSelection
224
- }, cursorStateField), yUndoPlugin({
225
- undoManager
226
- })];
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;
227
236
  }
228
237
  /**
229
238
  * This managers the updates of the collaboration provider.
@@ -233,14 +242,7 @@ var YjsExtension = (_dec = extension({
233
242
  onSetOptions(props) {
234
243
  var changes = props.changes,
235
244
  pickChanged = props.pickChanged;
236
- var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions', 'protectedNodes', 'trackedOrigins']);
237
-
238
- if (changes.protectedNodes.changed || changes.trackedOrigins.changed) {
239
- // Cannot change these, as we would need a new undo manager instance, and for that
240
- // we would need to unregister the previous instance from the document to avoid
241
- // memory leaks.
242
- throw new Error("Cannot change \"protectedNodes\" or \"trackedOrigins\" options");
243
- }
245
+ var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions']);
244
246
 
245
247
  if (changes.getProvider.changed) {
246
248
  this._provider = undefined;
@@ -273,16 +275,19 @@ var YjsExtension = (_dec = extension({
273
275
  this._provider = undefined;
274
276
  }
275
277
  /**
276
- * Undo within a collaborative editor.
277
- *
278
- * This should be used instead of the built in `undo` command.
278
+ * Undo that last Yjs transaction(s)
279
279
  *
280
280
  * This command does **not** support chaining.
281
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
281
282
  */
282
283
 
283
284
 
284
285
  yUndo() {
285
286
  return nonChainable(props => {
287
+ if (this.options.disableUndo) {
288
+ return false;
289
+ }
290
+
286
291
  var state = props.state,
287
292
  dispatch = props.dispatch;
288
293
  var undoManager = yUndoPluginKey.getState(state).undoManager;
@@ -299,16 +304,19 @@ var YjsExtension = (_dec = extension({
299
304
  });
300
305
  }
301
306
  /**
302
- * Redo, within a collaborative editor.
303
- *
304
- * This should be used instead of the built in `redo` command.
307
+ * Redo the last transaction undone with a previous `yUndo` command.
305
308
  *
306
309
  * This command does **not** support chaining.
310
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
307
311
  */
308
312
 
309
313
 
310
314
  yRedo() {
311
315
  return nonChainable(props => {
316
+ if (this.options.disableUndo) {
317
+ return false;
318
+ }
319
+
312
320
  var state = props.state,
313
321
  dispatch = props.dispatch;
314
322
  var undoManager = yUndoPluginKey.getState(state).undoManager;
@@ -117,9 +117,11 @@ var YjsExtension = (_dec = core.extension({
117
117
  cursorBuilder: yProsemirror.defaultCursorBuilder,
118
118
  cursorStateField: 'cursor',
119
119
  getSelection: state => state.selection,
120
+ disableUndo: false,
120
121
  protectedNodes: new Set('paragraph'),
121
122
  trackedOrigins: []
122
123
  },
124
+ staticKeys: ['disableUndo', 'protectedNodes', 'trackedOrigins'],
123
125
  defaultPriority: core.ExtensionPriority.High
124
126
  }), _dec2 = core.command({
125
127
  disableChaining: true,
@@ -213,21 +215,28 @@ var YjsExtension = (_dec = core.extension({
213
215
  cursorBuilder = _this$options.cursorBuilder,
214
216
  getSelection = _this$options.getSelection,
215
217
  cursorStateField = _this$options.cursorStateField,
218
+ disableUndo = _this$options.disableUndo,
216
219
  protectedNodes = _this$options.protectedNodes,
217
220
  trackedOrigins = _this$options.trackedOrigins;
218
221
  var yDoc = this.provider.doc;
219
222
  var type = yDoc.getXmlFragment('prosemirror');
220
- var undoManager = new yjs.UndoManager(type, {
221
- trackedOrigins: new Set([yProsemirror.ySyncPluginKey, ...trackedOrigins]),
222
- deleteFilter: item => yProsemirror.defaultDeleteFilter(item, protectedNodes)
223
- });
224
- return [yProsemirror.ySyncPlugin(type, syncPluginOptions), yProsemirror.yCursorPlugin(this.provider.awareness, {
223
+ var plugins = [yProsemirror.ySyncPlugin(type, syncPluginOptions), yProsemirror.yCursorPlugin(this.provider.awareness, {
225
224
  cursorBuilder,
226
225
  cursorStateField,
227
226
  getSelection
228
- }, cursorStateField), yProsemirror.yUndoPlugin({
229
- undoManager
230
- })];
227
+ }, cursorStateField)];
228
+
229
+ if (!disableUndo) {
230
+ var undoManager = new yjs.UndoManager(type, {
231
+ trackedOrigins: new Set([yProsemirror.ySyncPluginKey, ...trackedOrigins]),
232
+ deleteFilter: item => yProsemirror.defaultDeleteFilter(item, protectedNodes)
233
+ });
234
+ plugins.push(yProsemirror.yUndoPlugin({
235
+ undoManager
236
+ }));
237
+ }
238
+
239
+ return plugins;
231
240
  }
232
241
  /**
233
242
  * This managers the updates of the collaboration provider.
@@ -237,14 +246,7 @@ var YjsExtension = (_dec = core.extension({
237
246
  onSetOptions(props) {
238
247
  var changes = props.changes,
239
248
  pickChanged = props.pickChanged;
240
- var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions', 'protectedNodes', 'trackedOrigins']);
241
-
242
- if (changes.protectedNodes.changed || changes.trackedOrigins.changed) {
243
- // Cannot change these, as we would need a new undo manager instance, and for that
244
- // we would need to unregister the previous instance from the document to avoid
245
- // memory leaks.
246
- throw new Error("Cannot change \"protectedNodes\" or \"trackedOrigins\" options");
247
- }
249
+ var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions']);
248
250
 
249
251
  if (changes.getProvider.changed) {
250
252
  this._provider = undefined;
@@ -277,16 +279,19 @@ var YjsExtension = (_dec = core.extension({
277
279
  this._provider = undefined;
278
280
  }
279
281
  /**
280
- * Undo within a collaborative editor.
281
- *
282
- * This should be used instead of the built in `undo` command.
282
+ * Undo that last Yjs transaction(s)
283
283
  *
284
284
  * This command does **not** support chaining.
285
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
285
286
  */
286
287
 
287
288
 
288
289
  yUndo() {
289
290
  return core.nonChainable(props => {
291
+ if (this.options.disableUndo) {
292
+ return false;
293
+ }
294
+
290
295
  var state = props.state,
291
296
  dispatch = props.dispatch;
292
297
  var undoManager = yProsemirror.yUndoPluginKey.getState(state).undoManager;
@@ -303,16 +308,19 @@ var YjsExtension = (_dec = core.extension({
303
308
  });
304
309
  }
305
310
  /**
306
- * Redo, within a collaborative editor.
307
- *
308
- * This should be used instead of the built in `redo` command.
311
+ * Redo the last transaction undone with a previous `yUndo` command.
309
312
  *
310
313
  * This command does **not** support chaining.
314
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
311
315
  */
312
316
 
313
317
 
314
318
  yRedo() {
315
319
  return core.nonChainable(props => {
320
+ if (this.options.disableUndo) {
321
+ return false;
322
+ }
323
+
316
324
  var state = props.state,
317
325
  dispatch = props.dispatch;
318
326
  var undoManager = yProsemirror.yUndoPluginKey.getState(state).undoManager;
@@ -114,9 +114,11 @@ var YjsExtension = (_dec = core.extension({
114
114
  cursorBuilder: yProsemirror.defaultCursorBuilder,
115
115
  cursorStateField: 'cursor',
116
116
  getSelection: state => state.selection,
117
+ disableUndo: false,
117
118
  protectedNodes: new Set('paragraph'),
118
119
  trackedOrigins: []
119
120
  },
121
+ staticKeys: ['disableUndo', 'protectedNodes', 'trackedOrigins'],
120
122
  defaultPriority: core.ExtensionPriority.High
121
123
  }), _dec2 = core.command({
122
124
  disableChaining: true,
@@ -210,21 +212,28 @@ var YjsExtension = (_dec = core.extension({
210
212
  cursorBuilder = _this$options.cursorBuilder,
211
213
  getSelection = _this$options.getSelection,
212
214
  cursorStateField = _this$options.cursorStateField,
215
+ disableUndo = _this$options.disableUndo,
213
216
  protectedNodes = _this$options.protectedNodes,
214
217
  trackedOrigins = _this$options.trackedOrigins;
215
218
  var yDoc = this.provider.doc;
216
219
  var type = yDoc.getXmlFragment('prosemirror');
217
- var undoManager = new yjs.UndoManager(type, {
218
- trackedOrigins: new Set([yProsemirror.ySyncPluginKey, ...trackedOrigins]),
219
- deleteFilter: item => yProsemirror.defaultDeleteFilter(item, protectedNodes)
220
- });
221
- return [yProsemirror.ySyncPlugin(type, syncPluginOptions), yProsemirror.yCursorPlugin(this.provider.awareness, {
220
+ var plugins = [yProsemirror.ySyncPlugin(type, syncPluginOptions), yProsemirror.yCursorPlugin(this.provider.awareness, {
222
221
  cursorBuilder,
223
222
  cursorStateField,
224
223
  getSelection
225
- }, cursorStateField), yProsemirror.yUndoPlugin({
226
- undoManager
227
- })];
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;
228
237
  }
229
238
  /**
230
239
  * This managers the updates of the collaboration provider.
@@ -234,14 +243,7 @@ var YjsExtension = (_dec = core.extension({
234
243
  onSetOptions(props) {
235
244
  var changes = props.changes,
236
245
  pickChanged = props.pickChanged;
237
- var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions', 'protectedNodes', 'trackedOrigins']);
238
-
239
- if (changes.protectedNodes.changed || changes.trackedOrigins.changed) {
240
- // Cannot change these, as we would need a new undo manager instance, and for that
241
- // we would need to unregister the previous instance from the document to avoid
242
- // memory leaks.
243
- throw new Error("Cannot change \"protectedNodes\" or \"trackedOrigins\" options");
244
- }
246
+ var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions']);
245
247
 
246
248
  if (changes.getProvider.changed) {
247
249
  this._provider = undefined;
@@ -274,16 +276,19 @@ var YjsExtension = (_dec = core.extension({
274
276
  this._provider = undefined;
275
277
  }
276
278
  /**
277
- * Undo within a collaborative editor.
278
- *
279
- * This should be used instead of the built in `undo` command.
279
+ * Undo that last Yjs transaction(s)
280
280
  *
281
281
  * This command does **not** support chaining.
282
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
282
283
  */
283
284
 
284
285
 
285
286
  yUndo() {
286
287
  return core.nonChainable(props => {
288
+ if (this.options.disableUndo) {
289
+ return false;
290
+ }
291
+
287
292
  var state = props.state,
288
293
  dispatch = props.dispatch;
289
294
  var undoManager = yProsemirror.yUndoPluginKey.getState(state).undoManager;
@@ -300,16 +305,19 @@ var YjsExtension = (_dec = core.extension({
300
305
  });
301
306
  }
302
307
  /**
303
- * Redo, within a collaborative editor.
304
- *
305
- * This should be used instead of the built in `redo` command.
308
+ * Redo the last transaction undone with a previous `yUndo` command.
306
309
  *
307
310
  * This command does **not** support chaining.
311
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
308
312
  */
309
313
 
310
314
 
311
315
  yRedo() {
312
316
  return core.nonChainable(props => {
317
+ if (this.options.disableUndo) {
318
+ return false;
319
+ }
320
+
313
321
  var state = props.state,
314
322
  dispatch = props.dispatch;
315
323
  var undoManager = yProsemirror.yUndoPluginKey.getState(state).undoManager;
@@ -1,7 +1,7 @@
1
1
  import _applyDecoratedDescriptor from '@babel/runtime/helpers/esm/applyDecoratedDescriptor';
2
2
  import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
3
3
  import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
4
- import { defaultCursorBuilder, ySyncPluginKey, defaultDeleteFilter, ySyncPlugin, yCursorPlugin, yUndoPlugin, yUndoPluginKey, undo, redo, absolutePositionToRelativePosition, relativePositionToAbsolutePosition } from 'y-prosemirror';
4
+ import { defaultCursorBuilder, ySyncPluginKey, ySyncPlugin, yCursorPlugin, defaultDeleteFilter, yUndoPlugin, yUndoPluginKey, undo, redo, absolutePositionToRelativePosition, relativePositionToAbsolutePosition } from 'y-prosemirror';
5
5
  import { UndoManager, transact } from 'yjs';
6
6
  import { extension, invariant, ErrorConstant, ExtensionPriority, command, keyBinding, NamedShortcut, PlainExtension, isFunction, isEmptyObject, nonChainable, convertCommand } from '@remirror/core';
7
7
  import { AnnotationExtension } from '@remirror/extension-annotation';
@@ -113,9 +113,11 @@ var YjsExtension = (_dec = extension({
113
113
  cursorBuilder: defaultCursorBuilder,
114
114
  cursorStateField: 'cursor',
115
115
  getSelection: state => state.selection,
116
+ disableUndo: false,
116
117
  protectedNodes: new Set('paragraph'),
117
118
  trackedOrigins: []
118
119
  },
120
+ staticKeys: ['disableUndo', 'protectedNodes', 'trackedOrigins'],
119
121
  defaultPriority: ExtensionPriority.High
120
122
  }), _dec2 = command({
121
123
  disableChaining: true,
@@ -209,21 +211,28 @@ var YjsExtension = (_dec = extension({
209
211
  cursorBuilder = _this$options.cursorBuilder,
210
212
  getSelection = _this$options.getSelection,
211
213
  cursorStateField = _this$options.cursorStateField,
214
+ disableUndo = _this$options.disableUndo,
212
215
  protectedNodes = _this$options.protectedNodes,
213
216
  trackedOrigins = _this$options.trackedOrigins;
214
217
  var yDoc = this.provider.doc;
215
218
  var type = yDoc.getXmlFragment('prosemirror');
216
- var undoManager = new UndoManager(type, {
217
- trackedOrigins: new Set([ySyncPluginKey, ...trackedOrigins]),
218
- deleteFilter: item => defaultDeleteFilter(item, protectedNodes)
219
- });
220
- return [ySyncPlugin(type, syncPluginOptions), yCursorPlugin(this.provider.awareness, {
219
+ var plugins = [ySyncPlugin(type, syncPluginOptions), yCursorPlugin(this.provider.awareness, {
221
220
  cursorBuilder,
222
221
  cursorStateField,
223
222
  getSelection
224
- }, cursorStateField), yUndoPlugin({
225
- undoManager
226
- })];
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;
227
236
  }
228
237
  /**
229
238
  * This managers the updates of the collaboration provider.
@@ -233,14 +242,7 @@ var YjsExtension = (_dec = extension({
233
242
  onSetOptions(props) {
234
243
  var changes = props.changes,
235
244
  pickChanged = props.pickChanged;
236
- var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions', 'protectedNodes', 'trackedOrigins']);
237
-
238
- if (changes.protectedNodes.changed || changes.trackedOrigins.changed) {
239
- // Cannot change these, as we would need a new undo manager instance, and for that
240
- // we would need to unregister the previous instance from the document to avoid
241
- // memory leaks.
242
- throw new Error("Cannot change \"protectedNodes\" or \"trackedOrigins\" options");
243
- }
245
+ var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions']);
244
246
 
245
247
  if (changes.getProvider.changed) {
246
248
  this._provider = undefined;
@@ -273,16 +275,19 @@ var YjsExtension = (_dec = extension({
273
275
  this._provider = undefined;
274
276
  }
275
277
  /**
276
- * Undo within a collaborative editor.
277
- *
278
- * This should be used instead of the built in `undo` command.
278
+ * Undo that last Yjs transaction(s)
279
279
  *
280
280
  * This command does **not** support chaining.
281
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
281
282
  */
282
283
 
283
284
 
284
285
  yUndo() {
285
286
  return nonChainable(props => {
287
+ if (this.options.disableUndo) {
288
+ return false;
289
+ }
290
+
286
291
  var state = props.state,
287
292
  dispatch = props.dispatch;
288
293
  var undoManager = yUndoPluginKey.getState(state).undoManager;
@@ -299,16 +304,19 @@ var YjsExtension = (_dec = extension({
299
304
  });
300
305
  }
301
306
  /**
302
- * Redo, within a collaborative editor.
303
- *
304
- * This should be used instead of the built in `redo` command.
307
+ * Redo the last transaction undone with a previous `yUndo` command.
305
308
  *
306
309
  * This command does **not** support chaining.
310
+ * This command is a no-op and always returns `false` when the `disableUndo` option is set.
307
311
  */
308
312
 
309
313
 
310
314
  yRedo() {
311
315
  return nonChainable(props => {
316
+ if (this.options.disableUndo) {
317
+ return false;
318
+ }
319
+
312
320
  var state = props.state,
313
321
  dispatch = props.dispatch;
314
322
  var undoManager = yUndoPluginKey.getState(state).undoManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remirror/extension-yjs",
3
- "version": "1.0.22",
3
+ "version": "1.0.25",
4
4
  "description": "Realtime collaboration with yjs",
5
5
  "keywords": [
6
6
  "remirror",
@@ -44,8 +44,8 @@
44
44
  ],
45
45
  "dependencies": {
46
46
  "@babel/runtime": "^7.13.10",
47
- "@remirror/core": "^1.3.4",
48
- "@remirror/extension-annotation": "^1.1.13",
47
+ "@remirror/core": "^1.3.6",
48
+ "@remirror/extension-annotation": "^1.1.16",
49
49
  "@remirror/messages": "^1.0.6",
50
50
  "y-prosemirror": "^1.0.14",
51
51
  "y-protocols": "^1.0.5"