@remirror/extension-yjs 2.0.4 → 3.0.0-beta.10

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,250 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _applyDecoratedDescriptor = require('@babel/runtime/helpers/applyDecoratedDescriptor');
6
- var yProsemirror = require('y-prosemirror');
7
- var yjs = require('yjs');
8
- var core = require('@remirror/core');
9
- var messages = require('@remirror/messages');
10
-
11
- var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2;
12
- var YjsExtension = (_dec = core.extension({
13
- defaultOptions: {
14
- getProvider: () => {
15
- process.env.NODE_ENV !== "production" ? core.invariant(false, {
16
- code: core.ErrorConstant.EXTENSION,
17
- message: 'You must provide a YJS Provider to the `YjsExtension`.'
18
- }) : core.invariant(false) ;
19
- },
20
- destroyProvider: defaultDestroyProvider,
21
- syncPluginOptions: undefined,
22
- cursorBuilder: yProsemirror.defaultCursorBuilder,
23
- selectionBuilder: yProsemirror.defaultSelectionBuilder,
24
- cursorStateField: 'cursor',
25
- getSelection: state => state.selection,
26
- disableUndo: false,
27
- protectedNodes: new Set('paragraph'),
28
- trackedOrigins: []
29
- },
30
- staticKeys: ['disableUndo', 'protectedNodes', 'trackedOrigins'],
31
- defaultPriority: core.ExtensionPriority.High
32
- }), _dec2 = core.command({
33
- disableChaining: true,
34
- description: _ref => {
35
- var t = _ref.t;
36
- return t(messages.ExtensionHistoryMessages.UNDO_DESCRIPTION);
37
- },
38
- label: _ref2 => {
39
- var t = _ref2.t;
40
- return t(messages.ExtensionHistoryMessages.UNDO_LABEL);
41
- },
42
- icon: 'arrowGoBackFill'
43
- }), _dec3 = core.command({
44
- disableChaining: true,
45
- description: _ref3 => {
46
- var t = _ref3.t;
47
- return t(messages.ExtensionHistoryMessages.REDO_DESCRIPTION);
48
- },
49
- label: _ref4 => {
50
- var t = _ref4.t;
51
- return t(messages.ExtensionHistoryMessages.REDO_LABEL);
52
- },
53
- icon: 'arrowGoForwardFill'
54
- }), _dec4 = core.keyBinding({
55
- shortcut: core.NamedShortcut.Undo,
56
- command: 'yUndo'
57
- }), _dec5 = core.keyBinding({
58
- shortcut: core.NamedShortcut.Redo,
59
- command: 'yRedo'
60
- }), _dec(_class = (_class2 = class YjsExtension extends core.PlainExtension {
61
- get name() {
62
- return 'yjs';
63
- }
64
-
65
- /**
66
- * The provider that is being used for the editor.
67
- */
68
- get provider() {
69
- var _this$_provider;
70
-
71
- var getProvider = this.options.getProvider;
72
- return (_this$_provider = this._provider) !== null && _this$_provider !== void 0 ? _this$_provider : this._provider = getLazyValue(getProvider);
73
- }
74
-
75
- getBinding() {
76
- var state = this.store.getState();
77
-
78
- var _ySyncPluginKey$getSt = yProsemirror.ySyncPluginKey.getState(state),
79
- binding = _ySyncPluginKey$getSt.binding;
80
-
81
- return binding;
82
- }
83
- /**
84
- * Create the yjs plugins.
85
- */
86
-
87
-
88
- createExternalPlugins() {
89
- var _this$options = this.options,
90
- syncPluginOptions = _this$options.syncPluginOptions,
91
- cursorBuilder = _this$options.cursorBuilder,
92
- getSelection = _this$options.getSelection,
93
- cursorStateField = _this$options.cursorStateField,
94
- disableUndo = _this$options.disableUndo,
95
- protectedNodes = _this$options.protectedNodes,
96
- trackedOrigins = _this$options.trackedOrigins,
97
- selectionBuilder = _this$options.selectionBuilder;
98
- var yDoc = this.provider.doc;
99
- var type = yDoc.getXmlFragment('prosemirror');
100
- var plugins = [yProsemirror.ySyncPlugin(type, syncPluginOptions), yProsemirror.yCursorPlugin(this.provider.awareness, {
101
- cursorBuilder,
102
- getSelection,
103
- selectionBuilder
104
- }, cursorStateField)];
105
-
106
- if (!disableUndo) {
107
- var undoManager = new yjs.UndoManager(type, {
108
- trackedOrigins: new Set([yProsemirror.ySyncPluginKey, ...trackedOrigins]),
109
- deleteFilter: item => yProsemirror.defaultDeleteFilter(item, protectedNodes)
110
- });
111
- plugins.push(yProsemirror.yUndoPlugin({
112
- undoManager
113
- }));
114
- }
115
-
116
- return plugins;
117
- }
118
- /**
119
- * This managers the updates of the collaboration provider.
120
- */
121
-
122
-
123
- onSetOptions(props) {
124
- var changes = props.changes,
125
- pickChanged = props.pickChanged;
126
- var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions']);
127
-
128
- if (changes.getProvider.changed) {
129
- this._provider = undefined;
130
- var previousProvider = getLazyValue(changes.getProvider.previousValue); // Check whether the values have changed.
131
-
132
- if (changes.destroyProvider.changed) {
133
- var _changes$destroyProvi, _changes$destroyProvi2;
134
-
135
- (_changes$destroyProvi = (_changes$destroyProvi2 = changes.destroyProvider).previousValue) === null || _changes$destroyProvi === void 0 ? void 0 : _changes$destroyProvi.call(_changes$destroyProvi2, previousProvider);
136
- } else {
137
- this.options.destroyProvider(previousProvider);
138
- }
139
- }
140
-
141
- if (!core.isEmptyObject(changedPluginOptions)) {
142
- this.store.updateExtensionPlugins(this);
143
- }
144
- }
145
- /**
146
- * Remove the provider from the manager.
147
- */
148
-
149
-
150
- onDestroy() {
151
- if (!this._provider) {
152
- return;
153
- }
154
-
155
- this.options.destroyProvider(this._provider);
156
- this._provider = undefined;
157
- }
158
- /**
159
- * Undo that last Yjs transaction(s)
160
- *
161
- * This command does **not** support chaining.
162
- * This command is a no-op and always returns `false` when the `disableUndo` option is set.
163
- */
164
-
165
-
166
- yUndo() {
167
- return core.nonChainable(props => {
168
- if (this.options.disableUndo) {
169
- return false;
170
- }
171
-
172
- var state = props.state,
173
- dispatch = props.dispatch;
174
- var undoManager = yProsemirror.yUndoPluginKey.getState(state).undoManager;
175
-
176
- if (undoManager.undoStack.length === 0) {
177
- return false;
178
- }
179
-
180
- if (!dispatch) {
181
- return true;
182
- }
183
-
184
- return core.convertCommand(yProsemirror.undo)(props);
185
- });
186
- }
187
- /**
188
- * Redo the last transaction undone with a previous `yUndo` command.
189
- *
190
- * This command does **not** support chaining.
191
- * This command is a no-op and always returns `false` when the `disableUndo` option is set.
192
- */
193
-
194
-
195
- yRedo() {
196
- return core.nonChainable(props => {
197
- if (this.options.disableUndo) {
198
- return false;
199
- }
200
-
201
- var state = props.state,
202
- dispatch = props.dispatch;
203
- var undoManager = yProsemirror.yUndoPluginKey.getState(state).undoManager;
204
-
205
- if (undoManager.redoStack.length === 0) {
206
- return false;
207
- }
208
-
209
- if (!dispatch) {
210
- return true;
211
- }
212
-
213
- return core.convertCommand(yProsemirror.redo)(props);
214
- });
215
- }
216
- /**
217
- * Handle the undo keybinding.
218
- */
219
-
220
-
221
- undoShortcut(props) {
222
- return this.yUndo()(props);
223
- }
224
- /**
225
- * Handle the redo keybinding for the editor.
226
- */
227
-
228
-
229
- redoShortcut(props) {
230
- return this.yRedo()(props);
231
- }
232
-
233
- }, (_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);
234
- /**
235
- * The default destroy provider method.
236
- */
237
-
238
- function defaultDestroyProvider(provider) {
239
- var doc = provider.doc;
240
- provider.disconnect();
241
- provider.destroy();
242
- doc.destroy();
243
- }
244
-
245
- function getLazyValue(lazyValue) {
246
- return core.isFunction(lazyValue) ? lazyValue() : lazyValue;
247
- }
248
-
249
- exports.YjsExtension = YjsExtension;
250
- exports.defaultDestroyProvider = defaultDestroyProvider;
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- if (process.env.NODE_ENV === "production") {
4
- module.exports = require("./remirror-extension-yjs.cjs.prod.js");
5
- } else {
6
- module.exports = require("./remirror-extension-yjs.cjs.dev.js");
7
- }
@@ -1,247 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _applyDecoratedDescriptor = require('@babel/runtime/helpers/applyDecoratedDescriptor');
6
- var yProsemirror = require('y-prosemirror');
7
- var yjs = require('yjs');
8
- var core = require('@remirror/core');
9
- var messages = require('@remirror/messages');
10
-
11
- var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2;
12
- var YjsExtension = (_dec = core.extension({
13
- defaultOptions: {
14
- getProvider: () => {
15
- core.invariant(false) ;
16
- },
17
- destroyProvider: defaultDestroyProvider,
18
- syncPluginOptions: undefined,
19
- cursorBuilder: yProsemirror.defaultCursorBuilder,
20
- selectionBuilder: yProsemirror.defaultSelectionBuilder,
21
- cursorStateField: 'cursor',
22
- getSelection: state => state.selection,
23
- disableUndo: false,
24
- protectedNodes: new Set('paragraph'),
25
- trackedOrigins: []
26
- },
27
- staticKeys: ['disableUndo', 'protectedNodes', 'trackedOrigins'],
28
- defaultPriority: core.ExtensionPriority.High
29
- }), _dec2 = core.command({
30
- disableChaining: true,
31
- description: _ref => {
32
- var t = _ref.t;
33
- return t(messages.ExtensionHistoryMessages.UNDO_DESCRIPTION);
34
- },
35
- label: _ref2 => {
36
- var t = _ref2.t;
37
- return t(messages.ExtensionHistoryMessages.UNDO_LABEL);
38
- },
39
- icon: 'arrowGoBackFill'
40
- }), _dec3 = core.command({
41
- disableChaining: true,
42
- description: _ref3 => {
43
- var t = _ref3.t;
44
- return t(messages.ExtensionHistoryMessages.REDO_DESCRIPTION);
45
- },
46
- label: _ref4 => {
47
- var t = _ref4.t;
48
- return t(messages.ExtensionHistoryMessages.REDO_LABEL);
49
- },
50
- icon: 'arrowGoForwardFill'
51
- }), _dec4 = core.keyBinding({
52
- shortcut: core.NamedShortcut.Undo,
53
- command: 'yUndo'
54
- }), _dec5 = core.keyBinding({
55
- shortcut: core.NamedShortcut.Redo,
56
- command: 'yRedo'
57
- }), _dec(_class = (_class2 = class YjsExtension extends core.PlainExtension {
58
- get name() {
59
- return 'yjs';
60
- }
61
-
62
- /**
63
- * The provider that is being used for the editor.
64
- */
65
- get provider() {
66
- var _this$_provider;
67
-
68
- var getProvider = this.options.getProvider;
69
- return (_this$_provider = this._provider) !== null && _this$_provider !== void 0 ? _this$_provider : this._provider = getLazyValue(getProvider);
70
- }
71
-
72
- getBinding() {
73
- var state = this.store.getState();
74
-
75
- var _ySyncPluginKey$getSt = yProsemirror.ySyncPluginKey.getState(state),
76
- binding = _ySyncPluginKey$getSt.binding;
77
-
78
- return binding;
79
- }
80
- /**
81
- * Create the yjs plugins.
82
- */
83
-
84
-
85
- createExternalPlugins() {
86
- var _this$options = this.options,
87
- syncPluginOptions = _this$options.syncPluginOptions,
88
- cursorBuilder = _this$options.cursorBuilder,
89
- getSelection = _this$options.getSelection,
90
- cursorStateField = _this$options.cursorStateField,
91
- disableUndo = _this$options.disableUndo,
92
- protectedNodes = _this$options.protectedNodes,
93
- trackedOrigins = _this$options.trackedOrigins,
94
- selectionBuilder = _this$options.selectionBuilder;
95
- var yDoc = this.provider.doc;
96
- var type = yDoc.getXmlFragment('prosemirror');
97
- var plugins = [yProsemirror.ySyncPlugin(type, syncPluginOptions), yProsemirror.yCursorPlugin(this.provider.awareness, {
98
- cursorBuilder,
99
- getSelection,
100
- selectionBuilder
101
- }, cursorStateField)];
102
-
103
- if (!disableUndo) {
104
- var undoManager = new yjs.UndoManager(type, {
105
- trackedOrigins: new Set([yProsemirror.ySyncPluginKey, ...trackedOrigins]),
106
- deleteFilter: item => yProsemirror.defaultDeleteFilter(item, protectedNodes)
107
- });
108
- plugins.push(yProsemirror.yUndoPlugin({
109
- undoManager
110
- }));
111
- }
112
-
113
- return plugins;
114
- }
115
- /**
116
- * This managers the updates of the collaboration provider.
117
- */
118
-
119
-
120
- onSetOptions(props) {
121
- var changes = props.changes,
122
- pickChanged = props.pickChanged;
123
- var changedPluginOptions = pickChanged(['cursorBuilder', 'cursorStateField', 'getProvider', 'getSelection', 'syncPluginOptions']);
124
-
125
- if (changes.getProvider.changed) {
126
- this._provider = undefined;
127
- var previousProvider = getLazyValue(changes.getProvider.previousValue); // Check whether the values have changed.
128
-
129
- if (changes.destroyProvider.changed) {
130
- var _changes$destroyProvi, _changes$destroyProvi2;
131
-
132
- (_changes$destroyProvi = (_changes$destroyProvi2 = changes.destroyProvider).previousValue) === null || _changes$destroyProvi === void 0 ? void 0 : _changes$destroyProvi.call(_changes$destroyProvi2, previousProvider);
133
- } else {
134
- this.options.destroyProvider(previousProvider);
135
- }
136
- }
137
-
138
- if (!core.isEmptyObject(changedPluginOptions)) {
139
- this.store.updateExtensionPlugins(this);
140
- }
141
- }
142
- /**
143
- * Remove the provider from the manager.
144
- */
145
-
146
-
147
- onDestroy() {
148
- if (!this._provider) {
149
- return;
150
- }
151
-
152
- this.options.destroyProvider(this._provider);
153
- this._provider = undefined;
154
- }
155
- /**
156
- * Undo that last Yjs transaction(s)
157
- *
158
- * This command does **not** support chaining.
159
- * This command is a no-op and always returns `false` when the `disableUndo` option is set.
160
- */
161
-
162
-
163
- yUndo() {
164
- return core.nonChainable(props => {
165
- if (this.options.disableUndo) {
166
- return false;
167
- }
168
-
169
- var state = props.state,
170
- dispatch = props.dispatch;
171
- var undoManager = yProsemirror.yUndoPluginKey.getState(state).undoManager;
172
-
173
- if (undoManager.undoStack.length === 0) {
174
- return false;
175
- }
176
-
177
- if (!dispatch) {
178
- return true;
179
- }
180
-
181
- return core.convertCommand(yProsemirror.undo)(props);
182
- });
183
- }
184
- /**
185
- * Redo the last transaction undone with a previous `yUndo` command.
186
- *
187
- * This command does **not** support chaining.
188
- * This command is a no-op and always returns `false` when the `disableUndo` option is set.
189
- */
190
-
191
-
192
- yRedo() {
193
- return core.nonChainable(props => {
194
- if (this.options.disableUndo) {
195
- return false;
196
- }
197
-
198
- var state = props.state,
199
- dispatch = props.dispatch;
200
- var undoManager = yProsemirror.yUndoPluginKey.getState(state).undoManager;
201
-
202
- if (undoManager.redoStack.length === 0) {
203
- return false;
204
- }
205
-
206
- if (!dispatch) {
207
- return true;
208
- }
209
-
210
- return core.convertCommand(yProsemirror.redo)(props);
211
- });
212
- }
213
- /**
214
- * Handle the undo keybinding.
215
- */
216
-
217
-
218
- undoShortcut(props) {
219
- return this.yUndo()(props);
220
- }
221
- /**
222
- * Handle the redo keybinding for the editor.
223
- */
224
-
225
-
226
- redoShortcut(props) {
227
- return this.yRedo()(props);
228
- }
229
-
230
- }, (_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);
231
- /**
232
- * The default destroy provider method.
233
- */
234
-
235
- function defaultDestroyProvider(provider) {
236
- var doc = provider.doc;
237
- provider.disconnect();
238
- provider.destroy();
239
- doc.destroy();
240
- }
241
-
242
- function getLazyValue(lazyValue) {
243
- return core.isFunction(lazyValue) ? lazyValue() : lazyValue;
244
- }
245
-
246
- exports.YjsExtension = YjsExtension;
247
- exports.defaultDestroyProvider = defaultDestroyProvider;