@remirror/extension-yjs 1.0.31 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import type { Doc } from 'yjs';
2
- import { AcceptUndefined, Dispose, EditorState, KeyBindingProps, NonChainableCommandFunction, OnSetOptionsProps, PlainExtension, ProsemirrorPlugin, Selection, Shape, Static } from '@remirror/core';
2
+ import { AcceptUndefined, EditorState, KeyBindingProps, NonChainableCommandFunction, OnSetOptionsProps, PlainExtension, ProsemirrorPlugin, Selection, Shape, Static } from '@remirror/core';
3
3
  import { DecorationAttrs } from '@remirror/pm/view';
4
4
  export interface ColorDef {
5
5
  light: string;
@@ -82,7 +82,6 @@ export declare class YjsExtension extends PlainExtension<YjsOptions> {
82
82
  getBinding(): {
83
83
  mapping: Map<any, any>;
84
84
  } | undefined;
85
- onView(): Dispose | void;
86
85
  /**
87
86
  * Create the yjs plugins.
88
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: () => {
@@ -126,23 +31,23 @@ var YjsExtension = (_dec = core.extension({
126
31
  defaultPriority: core.ExtensionPriority.High
127
32
  }), _dec2 = core.command({
128
33
  disableChaining: true,
129
- description: _ref3 => {
130
- var t = _ref3.t;
34
+ description: _ref => {
35
+ var t = _ref.t;
131
36
  return t(messages.ExtensionHistoryMessages.UNDO_DESCRIPTION);
132
37
  },
133
- label: _ref4 => {
134
- var t = _ref4.t;
38
+ label: _ref2 => {
39
+ var t = _ref2.t;
135
40
  return t(messages.ExtensionHistoryMessages.UNDO_LABEL);
136
41
  },
137
42
  icon: 'arrowGoBackFill'
138
43
  }), _dec3 = core.command({
139
44
  disableChaining: true,
140
- description: _ref5 => {
141
- var t = _ref5.t;
45
+ description: _ref3 => {
46
+ var t = _ref3.t;
142
47
  return t(messages.ExtensionHistoryMessages.REDO_DESCRIPTION);
143
48
  },
144
- label: _ref6 => {
145
- var t = _ref6.t;
49
+ label: _ref4 => {
50
+ var t = _ref4.t;
146
51
  return t(messages.ExtensionHistoryMessages.REDO_LABEL);
147
52
  },
148
53
  icon: 'arrowGoForwardFill'
@@ -175,36 +80,6 @@ var YjsExtension = (_dec = core.extension({
175
80
 
176
81
  return binding;
177
82
  }
178
-
179
- onView() {
180
- try {
181
- var annotationStore = new YjsAnnotationStore(this.provider.doc, 'prosemirror', 'annotations', () => {
182
- var _this$getBinding;
183
-
184
- return (_this$getBinding = this.getBinding()) === null || _this$getBinding === void 0 ? void 0 : _this$getBinding.mapping;
185
- });
186
- this.store.manager.getExtension(extensionAnnotation.AnnotationExtension).setOptions({
187
- getStore: () => annotationStore
188
- });
189
-
190
- var handler = (_update, _origin, _doc, yjsTr) => {
191
- var _this$store$commands$, _this$store$commands;
192
-
193
- // Ignore own changes
194
- if (yjsTr.local) {
195
- return;
196
- }
197
-
198
- (_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);
199
- };
200
-
201
- this.provider.doc.on('update', handler);
202
- return () => {
203
- this.provider.doc.off('update', handler);
204
- };
205
- } catch (_unused) {// AnnotationExtension isn't present in editor
206
- }
207
- }
208
83
  /**
209
84
  * Create the yjs plugins.
210
85
  */
@@ -1,105 +1,10 @@
1
1
  import _applyDecoratedDescriptor from '@babel/runtime/helpers/esm/applyDecoratedDescriptor';
2
- import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
3
- import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
4
- import { defaultCursorBuilder, defaultSelectionBuilder, 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: () => {
@@ -122,23 +27,23 @@ var YjsExtension = (_dec = extension({
122
27
  defaultPriority: ExtensionPriority.High
123
28
  }), _dec2 = command({
124
29
  disableChaining: true,
125
- description: _ref3 => {
126
- var t = _ref3.t;
30
+ description: _ref => {
31
+ var t = _ref.t;
127
32
  return t(ExtensionHistoryMessages.UNDO_DESCRIPTION);
128
33
  },
129
- label: _ref4 => {
130
- var t = _ref4.t;
34
+ label: _ref2 => {
35
+ var t = _ref2.t;
131
36
  return t(ExtensionHistoryMessages.UNDO_LABEL);
132
37
  },
133
38
  icon: 'arrowGoBackFill'
134
39
  }), _dec3 = command({
135
40
  disableChaining: true,
136
- description: _ref5 => {
137
- var t = _ref5.t;
41
+ description: _ref3 => {
42
+ var t = _ref3.t;
138
43
  return t(ExtensionHistoryMessages.REDO_DESCRIPTION);
139
44
  },
140
- label: _ref6 => {
141
- var t = _ref6.t;
45
+ label: _ref4 => {
46
+ var t = _ref4.t;
142
47
  return t(ExtensionHistoryMessages.REDO_LABEL);
143
48
  },
144
49
  icon: 'arrowGoForwardFill'
@@ -171,36 +76,6 @@ var YjsExtension = (_dec = extension({
171
76
 
172
77
  return binding;
173
78
  }
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(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
79
  /**
205
80
  * Create the yjs plugins.
206
81
  */
@@ -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: () => {
@@ -126,23 +31,23 @@ var YjsExtension = (_dec = core.extension({
126
31
  defaultPriority: core.ExtensionPriority.High
127
32
  }), _dec2 = core.command({
128
33
  disableChaining: true,
129
- description: _ref3 => {
130
- var t = _ref3.t;
34
+ description: _ref => {
35
+ var t = _ref.t;
131
36
  return t(messages.ExtensionHistoryMessages.UNDO_DESCRIPTION);
132
37
  },
133
- label: _ref4 => {
134
- var t = _ref4.t;
38
+ label: _ref2 => {
39
+ var t = _ref2.t;
135
40
  return t(messages.ExtensionHistoryMessages.UNDO_LABEL);
136
41
  },
137
42
  icon: 'arrowGoBackFill'
138
43
  }), _dec3 = core.command({
139
44
  disableChaining: true,
140
- description: _ref5 => {
141
- var t = _ref5.t;
45
+ description: _ref3 => {
46
+ var t = _ref3.t;
142
47
  return t(messages.ExtensionHistoryMessages.REDO_DESCRIPTION);
143
48
  },
144
- label: _ref6 => {
145
- var t = _ref6.t;
49
+ label: _ref4 => {
50
+ var t = _ref4.t;
146
51
  return t(messages.ExtensionHistoryMessages.REDO_LABEL);
147
52
  },
148
53
  icon: 'arrowGoForwardFill'
@@ -175,36 +80,6 @@ var YjsExtension = (_dec = core.extension({
175
80
 
176
81
  return binding;
177
82
  }
178
-
179
- onView() {
180
- try {
181
- var annotationStore = new YjsAnnotationStore(this.provider.doc, 'prosemirror', 'annotations', () => {
182
- var _this$getBinding;
183
-
184
- return (_this$getBinding = this.getBinding()) === null || _this$getBinding === void 0 ? void 0 : _this$getBinding.mapping;
185
- });
186
- this.store.manager.getExtension(extensionAnnotation.AnnotationExtension).setOptions({
187
- getStore: () => annotationStore
188
- });
189
-
190
- var handler = (_update, _origin, _doc, yjsTr) => {
191
- var _this$store$commands$, _this$store$commands;
192
-
193
- // Ignore own changes
194
- if (yjsTr.local) {
195
- return;
196
- }
197
-
198
- (_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);
199
- };
200
-
201
- this.provider.doc.on('update', handler);
202
- return () => {
203
- this.provider.doc.off('update', handler);
204
- };
205
- } catch (_unused) {// AnnotationExtension isn't present in editor
206
- }
207
- }
208
83
  /**
209
84
  * Create the yjs plugins.
210
85
  */
@@ -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: () => {
@@ -123,23 +28,23 @@ var YjsExtension = (_dec = core.extension({
123
28
  defaultPriority: core.ExtensionPriority.High
124
29
  }), _dec2 = core.command({
125
30
  disableChaining: true,
126
- description: _ref3 => {
127
- var t = _ref3.t;
31
+ description: _ref => {
32
+ var t = _ref.t;
128
33
  return t(messages.ExtensionHistoryMessages.UNDO_DESCRIPTION);
129
34
  },
130
- label: _ref4 => {
131
- var t = _ref4.t;
35
+ label: _ref2 => {
36
+ var t = _ref2.t;
132
37
  return t(messages.ExtensionHistoryMessages.UNDO_LABEL);
133
38
  },
134
39
  icon: 'arrowGoBackFill'
135
40
  }), _dec3 = core.command({
136
41
  disableChaining: true,
137
- description: _ref5 => {
138
- var t = _ref5.t;
42
+ description: _ref3 => {
43
+ var t = _ref3.t;
139
44
  return t(messages.ExtensionHistoryMessages.REDO_DESCRIPTION);
140
45
  },
141
- label: _ref6 => {
142
- var t = _ref6.t;
46
+ label: _ref4 => {
47
+ var t = _ref4.t;
143
48
  return t(messages.ExtensionHistoryMessages.REDO_LABEL);
144
49
  },
145
50
  icon: 'arrowGoForwardFill'
@@ -172,36 +77,6 @@ var YjsExtension = (_dec = core.extension({
172
77
 
173
78
  return binding;
174
79
  }
175
-
176
- onView() {
177
- try {
178
- var annotationStore = new YjsAnnotationStore(this.provider.doc, 'prosemirror', 'annotations', () => {
179
- var _this$getBinding;
180
-
181
- return (_this$getBinding = this.getBinding()) === null || _this$getBinding === void 0 ? void 0 : _this$getBinding.mapping;
182
- });
183
- this.store.manager.getExtension(extensionAnnotation.AnnotationExtension).setOptions({
184
- getStore: () => annotationStore
185
- });
186
-
187
- var handler = (_update, _origin, _doc, yjsTr) => {
188
- var _this$store$commands$, _this$store$commands;
189
-
190
- // Ignore own changes
191
- if (yjsTr.local) {
192
- return;
193
- }
194
-
195
- (_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);
196
- };
197
-
198
- this.provider.doc.on('update', handler);
199
- return () => {
200
- this.provider.doc.off('update', handler);
201
- };
202
- } catch (_unused) {// AnnotationExtension isn't present in editor
203
- }
204
- }
205
80
  /**
206
81
  * Create the yjs plugins.
207
82
  */
@@ -1,105 +1,10 @@
1
1
  import _applyDecoratedDescriptor from '@babel/runtime/helpers/esm/applyDecoratedDescriptor';
2
- import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
3
- import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
4
- import { defaultCursorBuilder, defaultSelectionBuilder, 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: () => {
@@ -122,23 +27,23 @@ var YjsExtension = (_dec = extension({
122
27
  defaultPriority: ExtensionPriority.High
123
28
  }), _dec2 = command({
124
29
  disableChaining: true,
125
- description: _ref3 => {
126
- var t = _ref3.t;
30
+ description: _ref => {
31
+ var t = _ref.t;
127
32
  return t(ExtensionHistoryMessages.UNDO_DESCRIPTION);
128
33
  },
129
- label: _ref4 => {
130
- var t = _ref4.t;
34
+ label: _ref2 => {
35
+ var t = _ref2.t;
131
36
  return t(ExtensionHistoryMessages.UNDO_LABEL);
132
37
  },
133
38
  icon: 'arrowGoBackFill'
134
39
  }), _dec3 = command({
135
40
  disableChaining: true,
136
- description: _ref5 => {
137
- var t = _ref5.t;
41
+ description: _ref3 => {
42
+ var t = _ref3.t;
138
43
  return t(ExtensionHistoryMessages.REDO_DESCRIPTION);
139
44
  },
140
- label: _ref6 => {
141
- var t = _ref6.t;
45
+ label: _ref4 => {
46
+ var t = _ref4.t;
142
47
  return t(ExtensionHistoryMessages.REDO_LABEL);
143
48
  },
144
49
  icon: 'arrowGoForwardFill'
@@ -171,36 +76,6 @@ var YjsExtension = (_dec = extension({
171
76
 
172
77
  return binding;
173
78
  }
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(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
79
  /**
205
80
  * Create the yjs plugins.
206
81
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remirror/extension-yjs",
3
- "version": "1.0.31",
3
+ "version": "2.0.2",
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": "./dist/remirror-extension-yjs.cjs.js",
36
- "module": "./dist/remirror-extension-yjs.esm.js",
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,14 +44,13 @@
44
44
  ],
45
45
  "dependencies": {
46
46
  "@babel/runtime": "^7.13.10",
47
- "@remirror/core": "^1.4.3",
48
- "@remirror/extension-annotation": "^1.1.21",
47
+ "@remirror/core": "^1.4.5",
49
48
  "@remirror/messages": "^1.0.6",
50
49
  "y-prosemirror": "^1.0.19",
51
50
  "y-protocols": "^1.0.5"
52
51
  },
53
52
  "devDependencies": {
54
- "@remirror/pm": "^1.0.18",
53
+ "@remirror/pm": "^1.0.19",
55
54
  "y-webrtc": "^10.2.2",
56
55
  "yjs": "^13.5.23"
57
56
  },