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