@textbus/collaborate 5.2.3 → 5.2.4
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/index.esm.js +2372 -1351
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2374 -1338
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -1,1416 +1,2437 @@
|
|
|
1
|
-
import { Injectable, Inject, Optional } from
|
|
2
|
-
import { makeError,
|
|
3
|
-
import { Subject, map, filter, Subscription } from
|
|
4
|
-
import {
|
|
5
|
-
import { HocuspocusProvider } from
|
|
6
|
-
import { WebsocketProvider } from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (decorator = decorators[i])
|
|
12
|
-
result = decorator(result) || result;
|
|
13
|
-
return result;
|
|
14
|
-
};
|
|
15
|
-
var __decorateParam$1 = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
16
|
-
class CustomUndoManagerConfig {
|
|
17
|
-
}
|
|
18
|
-
const collabHistoryErrorFn = makeError("CollabHistory");
|
|
19
|
-
let CollabHistory = class {
|
|
20
|
-
constructor(rootComponentRef, collaborate, scheduler, stackSize, undoManagerConfig) {
|
|
21
|
-
this.rootComponentRef = rootComponentRef;
|
|
22
|
-
this.collaborate = collaborate;
|
|
23
|
-
this.scheduler = scheduler;
|
|
24
|
-
this.stackSize = stackSize;
|
|
25
|
-
this.undoManagerConfig = undoManagerConfig;
|
|
26
|
-
this.onBack = this.backEvent.asObservable();
|
|
27
|
-
this.onForward = this.forwardEvent.asObservable();
|
|
28
|
-
this.onChange = this.changeEvent.asObservable();
|
|
29
|
-
this.onPush = this.pushEvent.asObservable();
|
|
30
|
-
}
|
|
31
|
-
rootComponentRef;
|
|
32
|
-
collaborate;
|
|
33
|
-
scheduler;
|
|
34
|
-
stackSize;
|
|
35
|
-
undoManagerConfig;
|
|
36
|
-
onBack;
|
|
37
|
-
onForward;
|
|
38
|
-
onChange;
|
|
39
|
-
onPush;
|
|
40
|
-
get canBack() {
|
|
41
|
-
return this.manager?.canUndo() || false;
|
|
42
|
-
}
|
|
43
|
-
get canForward() {
|
|
44
|
-
return this.manager?.canRedo() || false;
|
|
45
|
-
}
|
|
46
|
-
manager = null;
|
|
47
|
-
historyItems = [];
|
|
48
|
-
index = 0;
|
|
49
|
-
subscriptions = [];
|
|
50
|
-
backEvent = new Subject();
|
|
51
|
-
forwardEvent = new Subject();
|
|
52
|
-
changeEvent = new Subject();
|
|
53
|
-
pushEvent = new Subject();
|
|
54
|
-
listen() {
|
|
55
|
-
const root = this.collaborate.yDoc.getMap("RootComponent");
|
|
56
|
-
const rootComponent = this.rootComponentRef.component;
|
|
57
|
-
this.collaborate.syncRootComponent(this.collaborate.yDoc, root, rootComponent);
|
|
58
|
-
const undoManagerConfig = this.undoManagerConfig || {};
|
|
59
|
-
const manager = new UndoManager(root, {
|
|
60
|
-
trackedOrigins: /* @__PURE__ */ new Set([this.collaborate.yDoc]),
|
|
61
|
-
captureTransaction(arg) {
|
|
62
|
-
if (undoManagerConfig.captureTransaction) {
|
|
63
|
-
return undoManagerConfig.captureTransaction(arg);
|
|
64
|
-
}
|
|
65
|
-
return true;
|
|
66
|
-
},
|
|
67
|
-
deleteFilter(item) {
|
|
68
|
-
if (undoManagerConfig.deleteFilter) {
|
|
69
|
-
return undoManagerConfig.deleteFilter(item);
|
|
70
|
-
}
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
this.manager = manager;
|
|
75
|
-
let beforePosition = null;
|
|
76
|
-
this.subscriptions.push(
|
|
77
|
-
this.scheduler.onLocalChangeBefore.subscribe(() => {
|
|
78
|
-
beforePosition = this.collaborate.getRelativeCursorLocation();
|
|
79
|
-
}),
|
|
80
|
-
this.collaborate.onAddSubModel.subscribe(() => {
|
|
81
|
-
throw collabHistoryErrorFn("single document does not support submodels.");
|
|
82
|
-
})
|
|
83
|
-
);
|
|
84
|
-
manager.on("stack-item-added", (event) => {
|
|
85
|
-
if (event.type === "undo") {
|
|
86
|
-
if (event.origin === manager) {
|
|
87
|
-
this.index++;
|
|
88
|
-
} else {
|
|
89
|
-
this.historyItems.length = this.index;
|
|
90
|
-
this.historyItems.push({
|
|
91
|
-
before: beforePosition,
|
|
92
|
-
after: this.collaborate.getRelativeCursorLocation()
|
|
93
|
-
});
|
|
94
|
-
this.index++;
|
|
95
|
-
}
|
|
96
|
-
} else {
|
|
97
|
-
this.index--;
|
|
98
|
-
}
|
|
99
|
-
if (manager.undoStack.length > this.stackSize) {
|
|
100
|
-
this.historyItems.shift();
|
|
101
|
-
manager.undoStack.shift();
|
|
102
|
-
}
|
|
103
|
-
if (event.origin === this.collaborate.yDoc) {
|
|
104
|
-
this.pushEvent.next();
|
|
105
|
-
}
|
|
106
|
-
this.changeEvent.next();
|
|
107
|
-
});
|
|
108
|
-
manager.on("stack-item-popped", (ev) => {
|
|
109
|
-
const index = ev.type === "undo" ? this.index : this.index - 1;
|
|
110
|
-
const position = this.historyItems[index] || null;
|
|
111
|
-
const p = ev.type === "undo" ? position?.before : position?.after;
|
|
112
|
-
this.collaborate.restoreCursorPosition(p);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
back() {
|
|
116
|
-
if (this.canBack) {
|
|
117
|
-
this.manager?.undo();
|
|
118
|
-
this.backEvent.next();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
forward() {
|
|
122
|
-
if (this.canForward) {
|
|
123
|
-
this.manager?.redo();
|
|
124
|
-
this.forwardEvent.next();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
clear() {
|
|
128
|
-
const last = this.historyItems.pop();
|
|
129
|
-
this.historyItems = last ? [last] : [];
|
|
130
|
-
this.index = last ? 1 : 0;
|
|
131
|
-
this.manager?.clear();
|
|
132
|
-
this.changeEvent.next();
|
|
133
|
-
}
|
|
134
|
-
destroy() {
|
|
135
|
-
this.index = 0;
|
|
136
|
-
this.historyItems = [];
|
|
137
|
-
this.subscriptions.forEach((i) => i.unsubscribe());
|
|
138
|
-
if (this.manager) {
|
|
139
|
-
this.manager.destroy();
|
|
140
|
-
this.manager.captureTransaction = () => true;
|
|
141
|
-
this.manager.deleteFilter = () => true;
|
|
142
|
-
this.manager.trackedOrigins = /* @__PURE__ */ new Set([null]);
|
|
1
|
+
import { Injectable, Inject, Optional } from '@viewfly/core';
|
|
2
|
+
import { makeError, Slot, ChangeOrigin, observe, AsyncSlot, AsyncComponent, Component, Scheduler, Registry, Selection, HISTORY_STACK_SIZE, RootComponentRef, History } from '@textbus/core';
|
|
3
|
+
import { Subject, map, filter, Subscription } from '@tanbo/stream';
|
|
4
|
+
import { Doc, createAbsolutePositionFromRelativePosition, createRelativePositionFromTypeIndex, Map, Array as Array$1, Text, UndoManager } from 'yjs';
|
|
5
|
+
import { HocuspocusProvider } from '@hocuspocus/provider';
|
|
6
|
+
import { WebsocketProvider } from 'y-websocket';
|
|
7
|
+
|
|
8
|
+
function _assert_this_initialized$2(self) {
|
|
9
|
+
if (self === void 0) {
|
|
10
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
143
11
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
var __decorateClass$2 = (decorators, target, key, kind) => {
|
|
154
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
|
|
155
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
156
|
-
if (decorator = decorators[i])
|
|
157
|
-
result = decorator(result) || result;
|
|
158
|
-
return result;
|
|
159
|
-
};
|
|
160
|
-
const collaborateErrorFn = makeError("Collaborate");
|
|
161
|
-
class SlotMap {
|
|
162
|
-
slotAndYTextMap = /* @__PURE__ */ new WeakMap();
|
|
163
|
-
yTextAndSlotMap = /* @__PURE__ */ new WeakMap();
|
|
164
|
-
set(key, value) {
|
|
165
|
-
if (key instanceof Slot) {
|
|
166
|
-
this.slotAndYTextMap.set(key, value);
|
|
167
|
-
this.yTextAndSlotMap.set(value, key);
|
|
168
|
-
} else {
|
|
169
|
-
this.slotAndYTextMap.set(value, key);
|
|
170
|
-
this.yTextAndSlotMap.set(key, value);
|
|
12
|
+
return self;
|
|
13
|
+
}
|
|
14
|
+
function _call_super$2(_this, derived, args) {
|
|
15
|
+
derived = _get_prototype_of$2(derived);
|
|
16
|
+
return _possible_constructor_return$2(_this, _is_native_reflect_construct$2() ? Reflect.construct(derived, args || [], _get_prototype_of$2(_this).constructor) : derived.apply(_this, args));
|
|
17
|
+
}
|
|
18
|
+
function _class_call_check$9(instance, Constructor) {
|
|
19
|
+
if (!(instance instanceof Constructor)) {
|
|
20
|
+
throw new TypeError("Cannot call a class as a function");
|
|
171
21
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
22
|
+
}
|
|
23
|
+
function _defineProperties$8(target, props) {
|
|
24
|
+
for(var i = 0; i < props.length; i++){
|
|
25
|
+
var descriptor = props[i];
|
|
26
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
27
|
+
descriptor.configurable = true;
|
|
28
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
29
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
176
30
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
31
|
+
}
|
|
32
|
+
function _create_class$8(Constructor, protoProps, staticProps) {
|
|
33
|
+
if (protoProps) _defineProperties$8(Constructor.prototype, protoProps);
|
|
34
|
+
return Constructor;
|
|
35
|
+
}
|
|
36
|
+
function _get_prototype_of$2(o) {
|
|
37
|
+
_get_prototype_of$2 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
38
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
39
|
+
};
|
|
40
|
+
return _get_prototype_of$2(o);
|
|
41
|
+
}
|
|
42
|
+
function _inherits$2(subClass, superClass) {
|
|
43
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
44
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
192
45
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
selection;
|
|
206
|
-
subModelLoader;
|
|
207
|
-
yDoc = new Doc();
|
|
208
|
-
slotMap = new SlotMap();
|
|
209
|
-
onAddSubModel;
|
|
210
|
-
subscriptions = [];
|
|
211
|
-
updateFromRemote = false;
|
|
212
|
-
addSubModelEvent = new Subject();
|
|
213
|
-
updateRemoteActions = /* @__PURE__ */ new WeakMap();
|
|
214
|
-
noRecord = {};
|
|
215
|
-
syncRootComponent(yDoc, sharedComponent, localComponent) {
|
|
216
|
-
this.initSyncEvent(yDoc);
|
|
217
|
-
this.syncComponent(yDoc, sharedComponent, localComponent);
|
|
218
|
-
}
|
|
219
|
-
syncRootSlot(yDoc, sharedSlot, localSlot) {
|
|
220
|
-
if (sharedSlot.length) {
|
|
221
|
-
localSlot.retain(0);
|
|
222
|
-
localSlot.delete(localSlot.length);
|
|
223
|
-
localSlot.cleanAttributes();
|
|
224
|
-
localSlot.cleanFormats();
|
|
225
|
-
this.initLocalSlotBySharedSlot(sharedSlot, localSlot);
|
|
226
|
-
} else {
|
|
227
|
-
yDoc.transact(() => {
|
|
228
|
-
this.initSharedSlotByLocalSlot(sharedSlot, localSlot);
|
|
229
|
-
});
|
|
46
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
47
|
+
constructor: {
|
|
48
|
+
value: subClass,
|
|
49
|
+
writable: true,
|
|
50
|
+
configurable: true
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
if (superClass) _set_prototype_of$2(subClass, superClass);
|
|
54
|
+
}
|
|
55
|
+
function _possible_constructor_return$2(self, call) {
|
|
56
|
+
if (call && (_type_of$3(call) === "object" || typeof call === "function")) {
|
|
57
|
+
return call;
|
|
230
58
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
};
|
|
247
|
-
|
|
59
|
+
return _assert_this_initialized$2(self);
|
|
60
|
+
}
|
|
61
|
+
function _set_prototype_of$2(o, p) {
|
|
62
|
+
_set_prototype_of$2 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
63
|
+
o.__proto__ = p;
|
|
64
|
+
return o;
|
|
65
|
+
};
|
|
66
|
+
return _set_prototype_of$2(o, p);
|
|
67
|
+
}
|
|
68
|
+
function _type_of$3(obj) {
|
|
69
|
+
"@swc/helpers - typeof";
|
|
70
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
71
|
+
}
|
|
72
|
+
function _is_native_reflect_construct$2() {
|
|
73
|
+
try {
|
|
74
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
75
|
+
} catch (_) {}
|
|
76
|
+
return (_is_native_reflect_construct$2 = function() {
|
|
77
|
+
return !!result;
|
|
78
|
+
})();
|
|
79
|
+
}
|
|
80
|
+
function _ts_decorate$3(decorators, target, key, desc) {
|
|
81
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
82
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
83
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
84
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
85
|
+
}
|
|
86
|
+
var subModelLoaderErrorFn = makeError('subModelLoaderError');
|
|
87
|
+
/**
|
|
88
|
+
* 子文档加载器
|
|
89
|
+
*/ var SubModelLoader = function SubModelLoader() {
|
|
90
|
+
_class_call_check$9(this, SubModelLoader);
|
|
91
|
+
};
|
|
92
|
+
var NonSubModelLoader = /*#__PURE__*/ function(SubModelLoader) {
|
|
93
|
+
_inherits$2(NonSubModelLoader, SubModelLoader);
|
|
94
|
+
function NonSubModelLoader() {
|
|
95
|
+
_class_call_check$9(this, NonSubModelLoader);
|
|
96
|
+
return _call_super$2(this, NonSubModelLoader, arguments);
|
|
248
97
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
98
|
+
_create_class$8(NonSubModelLoader, [
|
|
99
|
+
{
|
|
100
|
+
key: "createSubModelBySlot",
|
|
101
|
+
value: function createSubModelBySlot() {
|
|
102
|
+
throw subModelLoaderErrorFn('single document does not support async slot.');
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
key: "createSubModelByComponent",
|
|
107
|
+
value: function createSubModelByComponent() {
|
|
108
|
+
throw subModelLoaderErrorFn('single document does not support async component.');
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
key: "loadSubModelByComponent",
|
|
113
|
+
value: function loadSubModelByComponent() {
|
|
114
|
+
throw subModelLoaderErrorFn('single document does not support async component.');
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
key: "loadSubModelBySlot",
|
|
119
|
+
value: function loadSubModelBySlot() {
|
|
120
|
+
throw subModelLoaderErrorFn('single document does not support async slot.');
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
key: "getLoadedModelBySlot",
|
|
125
|
+
value: function getLoadedModelBySlot() {
|
|
126
|
+
throw subModelLoaderErrorFn('single document does not support async slot.');
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
key: "getLoadedModelByComponent",
|
|
131
|
+
value: function getLoadedModelByComponent() {
|
|
132
|
+
throw subModelLoaderErrorFn('single document does not support async component.');
|
|
133
|
+
}
|
|
272
134
|
}
|
|
273
|
-
|
|
135
|
+
]);
|
|
136
|
+
return NonSubModelLoader;
|
|
137
|
+
}(SubModelLoader);
|
|
138
|
+
NonSubModelLoader = _ts_decorate$3([
|
|
139
|
+
Injectable()
|
|
140
|
+
], NonSubModelLoader);
|
|
141
|
+
|
|
142
|
+
function _array_like_to_array(arr, len) {
|
|
143
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
144
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
145
|
+
return arr2;
|
|
146
|
+
}
|
|
147
|
+
function _array_with_holes(arr) {
|
|
148
|
+
if (Array.isArray(arr)) return arr;
|
|
149
|
+
}
|
|
150
|
+
function _array_without_holes(arr) {
|
|
151
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
152
|
+
}
|
|
153
|
+
function _class_call_check$8(instance, Constructor) {
|
|
154
|
+
if (!(instance instanceof Constructor)) {
|
|
155
|
+
throw new TypeError("Cannot call a class as a function");
|
|
274
156
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
157
|
+
}
|
|
158
|
+
function _defineProperties$7(target, props) {
|
|
159
|
+
for(var i = 0; i < props.length; i++){
|
|
160
|
+
var descriptor = props[i];
|
|
161
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
162
|
+
descriptor.configurable = true;
|
|
163
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
164
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
281
165
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
166
|
+
}
|
|
167
|
+
function _create_class$7(Constructor, protoProps, staticProps) {
|
|
168
|
+
if (protoProps) _defineProperties$7(Constructor.prototype, protoProps);
|
|
169
|
+
return Constructor;
|
|
170
|
+
}
|
|
171
|
+
function _define_property$8(obj, key, value) {
|
|
172
|
+
if (key in obj) {
|
|
173
|
+
Object.defineProperty(obj, key, {
|
|
174
|
+
value: value,
|
|
175
|
+
enumerable: true,
|
|
176
|
+
configurable: true,
|
|
177
|
+
writable: true
|
|
178
|
+
});
|
|
179
|
+
} else {
|
|
180
|
+
obj[key] = value;
|
|
290
181
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (update.record === item.record) {
|
|
316
|
-
update.actions.push(item.action);
|
|
317
|
-
} else {
|
|
318
|
-
update = {
|
|
319
|
-
record: item.record,
|
|
320
|
-
actions: [item.action]
|
|
321
|
-
};
|
|
322
|
-
updates.push(update);
|
|
323
|
-
}
|
|
182
|
+
return obj;
|
|
183
|
+
}
|
|
184
|
+
function _instanceof$1(left, right) {
|
|
185
|
+
"@swc/helpers - instanceof";
|
|
186
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
187
|
+
return !!right[Symbol.hasInstance](left);
|
|
188
|
+
} else {
|
|
189
|
+
return left instanceof right;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function _iterable_to_array(iter) {
|
|
193
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
194
|
+
}
|
|
195
|
+
function _iterable_to_array_limit(arr, i) {
|
|
196
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
197
|
+
if (_i == null) return;
|
|
198
|
+
var _arr = [];
|
|
199
|
+
var _n = true;
|
|
200
|
+
var _d = false;
|
|
201
|
+
var _s, _e;
|
|
202
|
+
try {
|
|
203
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
204
|
+
_arr.push(_s.value);
|
|
205
|
+
if (i && _arr.length === i) break;
|
|
324
206
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
207
|
+
} catch (err) {
|
|
208
|
+
_d = true;
|
|
209
|
+
_e = err;
|
|
210
|
+
} finally{
|
|
211
|
+
try {
|
|
212
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
213
|
+
} finally{
|
|
214
|
+
if (_d) throw _e;
|
|
332
215
|
}
|
|
333
|
-
})
|
|
334
|
-
);
|
|
335
|
-
}
|
|
336
|
-
syncComponent(yDoc, sharedComponent, localComponent) {
|
|
337
|
-
let state = sharedComponent.get("state");
|
|
338
|
-
if (!state) {
|
|
339
|
-
state = new Map();
|
|
340
|
-
this.syncLocalMapToSharedMap(localComponent.state, state);
|
|
341
|
-
yDoc.transact(() => {
|
|
342
|
-
sharedComponent.set("state", state);
|
|
343
|
-
});
|
|
344
|
-
} else {
|
|
345
|
-
Object.keys(localComponent.state).forEach((key) => {
|
|
346
|
-
Reflect.deleteProperty(localComponent.state, key);
|
|
347
|
-
});
|
|
348
|
-
this.syncSharedMapToLocalMap(state, localComponent.state);
|
|
349
216
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
const index = localSlot.index;
|
|
403
|
-
localSlot.delete(action.delete);
|
|
404
|
-
if (this.selection.isSelected && !(tr.origin instanceof UndoManager)) {
|
|
405
|
-
if (localSlot === this.selection.anchorSlot && this.selection.anchorOffset >= index) {
|
|
406
|
-
this.selection.setAnchor(localSlot, this.selection.startOffset - action.delete);
|
|
407
|
-
}
|
|
408
|
-
if (localSlot === this.selection.focusSlot && this.selection.focusOffset >= index) {
|
|
409
|
-
this.selection.setFocus(localSlot, this.selection.focusOffset - action.delete);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
};
|
|
416
|
-
sharedSlot.observe(syncRemote);
|
|
417
|
-
const sub = localSlot.onContentChange.subscribe((actions) => {
|
|
418
|
-
this.runLocalUpdate(sharedSlot.doc, true, () => {
|
|
419
|
-
let offset = 0;
|
|
420
|
-
let length = 0;
|
|
421
|
-
for (const action of actions) {
|
|
422
|
-
if (action.type === "retain") {
|
|
423
|
-
const formats = action.formats;
|
|
424
|
-
if (formats) {
|
|
425
|
-
const keys = Object.keys(formats);
|
|
426
|
-
let length2 = keys.length;
|
|
427
|
-
keys.forEach((key) => {
|
|
428
|
-
const formatter = this.registry.getFormatter(key);
|
|
429
|
-
if (!formatter) {
|
|
430
|
-
length2--;
|
|
431
|
-
Reflect.deleteProperty(formats, key);
|
|
217
|
+
return _arr;
|
|
218
|
+
}
|
|
219
|
+
function _non_iterable_rest() {
|
|
220
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
221
|
+
}
|
|
222
|
+
function _non_iterable_spread() {
|
|
223
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
224
|
+
}
|
|
225
|
+
function _sliced_to_array(arr, i) {
|
|
226
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
227
|
+
}
|
|
228
|
+
function _to_consumable_array(arr) {
|
|
229
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
230
|
+
}
|
|
231
|
+
function _type_of$2(obj) {
|
|
232
|
+
"@swc/helpers - typeof";
|
|
233
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
234
|
+
}
|
|
235
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
236
|
+
if (!o) return;
|
|
237
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
238
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
239
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
240
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
241
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
242
|
+
}
|
|
243
|
+
function _ts_decorate$2(decorators, target, key, desc) {
|
|
244
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
245
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
246
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
247
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
248
|
+
}
|
|
249
|
+
function _ts_metadata$2(k, v) {
|
|
250
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
251
|
+
}
|
|
252
|
+
var collaborateErrorFn = makeError('Collaborate');
|
|
253
|
+
var SlotMap = /*#__PURE__*/ function() {
|
|
254
|
+
function SlotMap() {
|
|
255
|
+
_class_call_check$8(this, SlotMap);
|
|
256
|
+
_define_property$8(this, "slotAndYTextMap", new WeakMap());
|
|
257
|
+
_define_property$8(this, "yTextAndSlotMap", new WeakMap());
|
|
258
|
+
}
|
|
259
|
+
_create_class$7(SlotMap, [
|
|
260
|
+
{
|
|
261
|
+
key: "set",
|
|
262
|
+
value: function set(key, value) {
|
|
263
|
+
if (_instanceof$1(key, Slot)) {
|
|
264
|
+
this.slotAndYTextMap.set(key, value);
|
|
265
|
+
this.yTextAndSlotMap.set(value, key);
|
|
266
|
+
} else {
|
|
267
|
+
this.slotAndYTextMap.set(value, key);
|
|
268
|
+
this.yTextAndSlotMap.set(key, value);
|
|
432
269
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
sharedSlot.insert(0, "\n", delta[0]?.attributes);
|
|
462
|
-
}
|
|
463
|
-
} else if (action.type === "attrSet") {
|
|
464
|
-
sharedSlot.setAttribute(action.name, action.value);
|
|
465
|
-
} else if (action.type === "attrDelete") {
|
|
466
|
-
sharedSlot.removeAttribute(action.name);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
});
|
|
471
|
-
this.slotMap.set(localSlot, sharedSlot);
|
|
472
|
-
localSlot.__changeMarker__.addDetachCallback(() => {
|
|
473
|
-
this.slotMap.delete(localSlot);
|
|
474
|
-
sharedSlot.unobserve(syncRemote);
|
|
475
|
-
sub.unsubscribe();
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
destroy() {
|
|
479
|
-
this.subscriptions.forEach((i) => i.unsubscribe());
|
|
480
|
-
this.subscriptions = [];
|
|
481
|
-
}
|
|
482
|
-
syncSharedMapToLocalMap(sharedMap, localMap) {
|
|
483
|
-
sharedMap.forEach((value, key) => {
|
|
484
|
-
localMap[key] = this.createLocalModelBySharedByModel(value);
|
|
485
|
-
});
|
|
486
|
-
this.syncObject(sharedMap, localMap);
|
|
487
|
-
}
|
|
488
|
-
createLocalMapBySharedMap(sharedMap) {
|
|
489
|
-
const localMap = observe({});
|
|
490
|
-
this.syncSharedMapToLocalMap(sharedMap, localMap);
|
|
491
|
-
return localMap;
|
|
492
|
-
}
|
|
493
|
-
createLocalArrayBySharedArray(sharedArray) {
|
|
494
|
-
const localArray = observe([]);
|
|
495
|
-
localArray.push(...sharedArray.map((item) => this.createLocalModelBySharedByModel(item)));
|
|
496
|
-
this.syncArray(sharedArray, localArray);
|
|
497
|
-
return localArray;
|
|
498
|
-
}
|
|
499
|
-
syncLocalMapToSharedMap(localMap, sharedMap) {
|
|
500
|
-
Object.entries(localMap).forEach(([key, value]) => {
|
|
501
|
-
sharedMap.set(key, this.createSharedModelByLocalModel(value));
|
|
502
|
-
});
|
|
503
|
-
this.syncObject(sharedMap, localMap);
|
|
504
|
-
}
|
|
505
|
-
createSharedMapByLocalMap(localMap) {
|
|
506
|
-
const sharedMap = new Map();
|
|
507
|
-
this.syncLocalMapToSharedMap(localMap, sharedMap);
|
|
508
|
-
return sharedMap;
|
|
509
|
-
}
|
|
510
|
-
createSharedArrayByLocalArray(localArray) {
|
|
511
|
-
const sharedArray = new Array$1();
|
|
512
|
-
localArray.forEach((value) => {
|
|
513
|
-
sharedArray.push([this.createSharedModelByLocalModel(value)]);
|
|
514
|
-
});
|
|
515
|
-
this.syncArray(sharedArray, localArray);
|
|
516
|
-
return sharedArray;
|
|
517
|
-
}
|
|
518
|
-
createSharedSlotByLocalSlot(localSlot) {
|
|
519
|
-
const sharedSlot = new Text();
|
|
520
|
-
const isAsyncSlot = localSlot instanceof AsyncSlot;
|
|
521
|
-
sharedSlot.setAttribute("schema", [...localSlot.schema]);
|
|
522
|
-
sharedSlot.setAttribute("type", isAsyncSlot ? "async" : "sync");
|
|
523
|
-
if (isAsyncSlot) {
|
|
524
|
-
let isDestroyed = false;
|
|
525
|
-
const sharedMetadata = this.createSharedMapByLocalMap(localSlot.metadata);
|
|
526
|
-
sharedSlot.setAttribute("metadata", sharedMetadata);
|
|
527
|
-
this.subModelLoader.createSubModelBySlot(localSlot).then((subDocument) => {
|
|
528
|
-
if (isDestroyed) {
|
|
529
|
-
return;
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
key: "get",
|
|
274
|
+
value: function get(key) {
|
|
275
|
+
if (_instanceof$1(key, Slot)) {
|
|
276
|
+
return this.slotAndYTextMap.get(key) || null;
|
|
277
|
+
}
|
|
278
|
+
return this.yTextAndSlotMap.get(key) || null;
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
key: "delete",
|
|
283
|
+
value: function _delete(key) {
|
|
284
|
+
if (_instanceof$1(key, Slot)) {
|
|
285
|
+
var v = this.slotAndYTextMap.get(key);
|
|
286
|
+
this.slotAndYTextMap.delete(key);
|
|
287
|
+
if (v) {
|
|
288
|
+
this.yTextAndSlotMap.delete(v);
|
|
289
|
+
}
|
|
290
|
+
} else {
|
|
291
|
+
var v1 = this.yTextAndSlotMap.get(key);
|
|
292
|
+
this.yTextAndSlotMap.delete(key);
|
|
293
|
+
if (v1) {
|
|
294
|
+
this.slotAndYTextMap.delete(v1);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
530
298
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
this
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
this
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
299
|
+
]);
|
|
300
|
+
return SlotMap;
|
|
301
|
+
}();
|
|
302
|
+
var Collaborate = /*#__PURE__*/ function() {
|
|
303
|
+
function Collaborate(scheduler, registry, selection, subModelLoader) {
|
|
304
|
+
_class_call_check$8(this, Collaborate);
|
|
305
|
+
_define_property$8(this, "scheduler", void 0);
|
|
306
|
+
_define_property$8(this, "registry", void 0);
|
|
307
|
+
_define_property$8(this, "selection", void 0);
|
|
308
|
+
_define_property$8(this, "subModelLoader", void 0);
|
|
309
|
+
_define_property$8(this, "yDoc", void 0);
|
|
310
|
+
_define_property$8(this, "slotMap", void 0);
|
|
311
|
+
_define_property$8(this, "onAddSubModel", void 0);
|
|
312
|
+
_define_property$8(this, "subscriptions", void 0);
|
|
313
|
+
_define_property$8(this, "updateFromRemote", void 0);
|
|
314
|
+
_define_property$8(this, "addSubModelEvent", void 0);
|
|
315
|
+
_define_property$8(this, "updateRemoteActions", void 0);
|
|
316
|
+
_define_property$8(this, "noRecord", void 0);
|
|
317
|
+
this.scheduler = scheduler;
|
|
318
|
+
this.registry = registry;
|
|
319
|
+
this.selection = selection;
|
|
320
|
+
this.subModelLoader = subModelLoader;
|
|
321
|
+
this.yDoc = new Doc();
|
|
322
|
+
this.slotMap = new SlotMap();
|
|
323
|
+
this.subscriptions = [];
|
|
324
|
+
this.updateFromRemote = false;
|
|
325
|
+
this.addSubModelEvent = new Subject();
|
|
326
|
+
this.updateRemoteActions = new WeakMap();
|
|
327
|
+
this.noRecord = {};
|
|
328
|
+
this.onAddSubModel = this.addSubModelEvent.asObservable();
|
|
547
329
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
330
|
+
_create_class$7(Collaborate, [
|
|
331
|
+
{
|
|
332
|
+
key: "syncRootComponent",
|
|
333
|
+
value: function syncRootComponent(yDoc, sharedComponent, localComponent) {
|
|
334
|
+
this.initSyncEvent(yDoc);
|
|
335
|
+
this.syncComponent(yDoc, sharedComponent, localComponent);
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
key: "syncRootSlot",
|
|
340
|
+
value: function syncRootSlot(yDoc, sharedSlot, localSlot) {
|
|
341
|
+
var _this = this;
|
|
342
|
+
if (sharedSlot.length) {
|
|
343
|
+
localSlot.retain(0);
|
|
344
|
+
localSlot.delete(localSlot.length);
|
|
345
|
+
localSlot.cleanAttributes();
|
|
346
|
+
localSlot.cleanFormats();
|
|
347
|
+
this.initLocalSlotBySharedSlot(sharedSlot, localSlot);
|
|
348
|
+
} else {
|
|
349
|
+
yDoc.transact(function() {
|
|
350
|
+
_this.initSharedSlotByLocalSlot(sharedSlot, localSlot);
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
this.initSyncEvent(yDoc);
|
|
354
|
+
this.syncSlot(sharedSlot, localSlot);
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
key: "getAbstractSelection",
|
|
359
|
+
value: function getAbstractSelection(position) {
|
|
360
|
+
var anchorPosition = createAbsolutePositionFromRelativePosition(position.anchor.position, position.anchor.doc);
|
|
361
|
+
var focusPosition = createAbsolutePositionFromRelativePosition(position.focus.position, position.focus.doc);
|
|
362
|
+
if (anchorPosition && focusPosition) {
|
|
363
|
+
var focusSlot = this.slotMap.get(focusPosition.type);
|
|
364
|
+
var anchorSlot = this.slotMap.get(anchorPosition.type);
|
|
365
|
+
if (focusSlot && anchorSlot) {
|
|
366
|
+
return {
|
|
367
|
+
anchorSlot: anchorSlot,
|
|
368
|
+
anchorOffset: anchorPosition.index,
|
|
369
|
+
focusSlot: focusSlot,
|
|
370
|
+
focusOffset: focusPosition.index
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
key: "getRelativeCursorLocation",
|
|
379
|
+
value: function getRelativeCursorLocation() {
|
|
380
|
+
var _this_selection = this.selection, anchorSlot = _this_selection.anchorSlot, anchorOffset = _this_selection.anchorOffset, focusSlot = _this_selection.focusSlot, focusOffset = _this_selection.focusOffset;
|
|
381
|
+
if (anchorSlot) {
|
|
382
|
+
var anchorYText = this.slotMap.get(anchorSlot);
|
|
383
|
+
if (anchorYText) {
|
|
384
|
+
var anchorPosition = createRelativePositionFromTypeIndex(anchorYText, anchorOffset);
|
|
385
|
+
if (focusSlot) {
|
|
386
|
+
var focusYText = this.slotMap.get(focusSlot);
|
|
387
|
+
if (focusYText) {
|
|
388
|
+
var focusPosition = createRelativePositionFromTypeIndex(focusYText, focusOffset);
|
|
389
|
+
return {
|
|
390
|
+
focus: {
|
|
391
|
+
doc: focusYText.doc,
|
|
392
|
+
position: focusPosition
|
|
393
|
+
},
|
|
394
|
+
anchor: {
|
|
395
|
+
doc: anchorYText.doc,
|
|
396
|
+
position: anchorPosition
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
key: "restoreCursorPosition",
|
|
408
|
+
value: function restoreCursorPosition(position) {
|
|
409
|
+
if (!position) {
|
|
410
|
+
this.selection.unSelect();
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
var selection = this.getAbstractSelection(position);
|
|
414
|
+
if (selection) {
|
|
415
|
+
this.selection.setBaseAndExtent(selection.anchorSlot, selection.anchorOffset, selection.focusSlot, selection.focusOffset);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
key: "initSyncEvent",
|
|
421
|
+
value: function initSyncEvent(yDoc) {
|
|
422
|
+
var _this = this;
|
|
423
|
+
this.subscriptions.push(this.scheduler.onDocChanged.pipe(map(function(item) {
|
|
424
|
+
return item.filter(function(i) {
|
|
425
|
+
return i.from !== ChangeOrigin.Remote;
|
|
426
|
+
});
|
|
427
|
+
}), filter(function(item) {
|
|
428
|
+
return item.length;
|
|
429
|
+
})).subscribe(function() {
|
|
430
|
+
var updates = [];
|
|
431
|
+
var update = null;
|
|
432
|
+
var updateRemoteActions = _this.updateRemoteActions.get(yDoc) || [];
|
|
433
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
434
|
+
try {
|
|
435
|
+
for(var _iterator = updateRemoteActions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
436
|
+
var item = _step.value;
|
|
437
|
+
if (!update) {
|
|
438
|
+
update = {
|
|
439
|
+
record: item.record,
|
|
440
|
+
actions: []
|
|
441
|
+
};
|
|
442
|
+
updates.push(update);
|
|
443
|
+
}
|
|
444
|
+
if (update.record === item.record) {
|
|
445
|
+
update.actions.push(item.action);
|
|
446
|
+
} else {
|
|
447
|
+
update = {
|
|
448
|
+
record: item.record,
|
|
449
|
+
actions: [
|
|
450
|
+
item.action
|
|
451
|
+
]
|
|
452
|
+
};
|
|
453
|
+
updates.push(update);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
} catch (err) {
|
|
457
|
+
_didIteratorError = true;
|
|
458
|
+
_iteratorError = err;
|
|
459
|
+
} finally{
|
|
460
|
+
try {
|
|
461
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
462
|
+
_iterator.return();
|
|
463
|
+
}
|
|
464
|
+
} finally{
|
|
465
|
+
if (_didIteratorError) {
|
|
466
|
+
throw _iteratorError;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
_this.updateRemoteActions.delete(yDoc);
|
|
471
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
472
|
+
try {
|
|
473
|
+
var _loop = function() {
|
|
474
|
+
var item = _step1.value;
|
|
475
|
+
yDoc.transact(function() {
|
|
476
|
+
item.actions.forEach(function(fn) {
|
|
477
|
+
fn();
|
|
478
|
+
});
|
|
479
|
+
}, item.record ? yDoc : _this.noRecord);
|
|
480
|
+
};
|
|
481
|
+
for(var _iterator1 = updates[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true)_loop();
|
|
482
|
+
} catch (err) {
|
|
483
|
+
_didIteratorError1 = true;
|
|
484
|
+
_iteratorError1 = err;
|
|
485
|
+
} finally{
|
|
486
|
+
try {
|
|
487
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
488
|
+
_iterator1.return();
|
|
489
|
+
}
|
|
490
|
+
} finally{
|
|
491
|
+
if (_didIteratorError1) {
|
|
492
|
+
throw _iteratorError1;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}));
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
key: "syncComponent",
|
|
501
|
+
value: function syncComponent(yDoc, sharedComponent, localComponent) {
|
|
502
|
+
var state = sharedComponent.get('state');
|
|
503
|
+
if (!state) {
|
|
504
|
+
state = new Map();
|
|
505
|
+
this.syncLocalMapToSharedMap(localComponent.state, state);
|
|
506
|
+
yDoc.transact(function() {
|
|
507
|
+
sharedComponent.set('state', state);
|
|
508
|
+
});
|
|
509
|
+
} else {
|
|
510
|
+
Object.keys(localComponent.state).forEach(function(key) {
|
|
511
|
+
Reflect.deleteProperty(localComponent.state, key);
|
|
512
|
+
});
|
|
513
|
+
this.syncSharedMapToLocalMap(state, localComponent.state);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
key: "syncSlot",
|
|
519
|
+
value: function syncSlot(sharedSlot, localSlot) {
|
|
520
|
+
var _this = this;
|
|
521
|
+
var syncRemote = function syncRemote(ev, tr) {
|
|
522
|
+
_this.runRemoteUpdate(tr, function() {
|
|
523
|
+
localSlot.retain(0);
|
|
524
|
+
ev.keysChanged.forEach(function(key) {
|
|
525
|
+
var change = ev.keys.get(key);
|
|
526
|
+
if (!change) {
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
var updateType = change.action;
|
|
530
|
+
if (updateType === 'update' || updateType === 'add') {
|
|
531
|
+
var attribute = _this.registry.getAttribute(key);
|
|
532
|
+
if (attribute) {
|
|
533
|
+
localSlot.setAttribute(attribute, sharedSlot.getAttribute(key));
|
|
534
|
+
}
|
|
535
|
+
} else if (updateType === 'delete') {
|
|
536
|
+
var attribute1 = _this.registry.getAttribute(key);
|
|
537
|
+
if (attribute1) {
|
|
538
|
+
localSlot.removeAttribute(attribute1);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
ev.delta.forEach(function(action) {
|
|
543
|
+
if (Reflect.has(action, 'retain')) {
|
|
544
|
+
if (action.attributes) {
|
|
545
|
+
var formats = remoteFormatsToLocal(_this.registry, action.attributes);
|
|
546
|
+
if (formats.length) {
|
|
547
|
+
localSlot.retain(action.retain, formats);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
localSlot.retain(localSlot.index + action.retain);
|
|
551
|
+
} else if (action.insert) {
|
|
552
|
+
var index = localSlot.index;
|
|
553
|
+
var length = 1;
|
|
554
|
+
if (typeof action.insert === 'string') {
|
|
555
|
+
length = action.insert.length;
|
|
556
|
+
localSlot.insert(action.insert, remoteFormatsToLocal(_this.registry, action.attributes));
|
|
557
|
+
} else {
|
|
558
|
+
var sharedComponent = action.insert;
|
|
559
|
+
var component = _this.createLocalComponentBySharedComponent(sharedComponent);
|
|
560
|
+
localSlot.insert(component);
|
|
561
|
+
}
|
|
562
|
+
if (_this.selection.isSelected && !_instanceof$1(tr.origin, UndoManager)) {
|
|
563
|
+
if (localSlot === _this.selection.anchorSlot && _this.selection.anchorOffset > index) {
|
|
564
|
+
_this.selection.setAnchor(localSlot, _this.selection.anchorOffset + length);
|
|
565
|
+
}
|
|
566
|
+
if (localSlot === _this.selection.focusSlot && _this.selection.focusOffset > index) {
|
|
567
|
+
_this.selection.setFocus(localSlot, _this.selection.focusOffset + length);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
} else if (action.delete) {
|
|
571
|
+
var index1 = localSlot.index;
|
|
572
|
+
localSlot.delete(action.delete);
|
|
573
|
+
if (_this.selection.isSelected && !_instanceof$1(tr.origin, UndoManager)) {
|
|
574
|
+
if (localSlot === _this.selection.anchorSlot && _this.selection.anchorOffset >= index1) {
|
|
575
|
+
_this.selection.setAnchor(localSlot, _this.selection.startOffset - action.delete);
|
|
576
|
+
}
|
|
577
|
+
if (localSlot === _this.selection.focusSlot && _this.selection.focusOffset >= index1) {
|
|
578
|
+
_this.selection.setFocus(localSlot, _this.selection.focusOffset - action.delete);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
};
|
|
585
|
+
sharedSlot.observe(syncRemote);
|
|
586
|
+
var sub = localSlot.onContentChange.subscribe(function(actions) {
|
|
587
|
+
_this.runLocalUpdate(sharedSlot.doc, true, function() {
|
|
588
|
+
var offset = 0;
|
|
589
|
+
var length = 0;
|
|
590
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
591
|
+
try {
|
|
592
|
+
var _loop = function() {
|
|
593
|
+
var action = _step.value;
|
|
594
|
+
if (action.type === 'retain') {
|
|
595
|
+
var formats = action.formats;
|
|
596
|
+
if (formats) {
|
|
597
|
+
var keys = Object.keys(formats);
|
|
598
|
+
var length1 = keys.length;
|
|
599
|
+
keys.forEach(function(key) {
|
|
600
|
+
var formatter = _this.registry.getFormatter(key);
|
|
601
|
+
if (!formatter) {
|
|
602
|
+
length1--;
|
|
603
|
+
Reflect.deleteProperty(formats, key);
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
if (length1) {
|
|
607
|
+
sharedSlot.format(offset, action.offset, formats);
|
|
608
|
+
}
|
|
609
|
+
} else {
|
|
610
|
+
offset = action.offset;
|
|
611
|
+
}
|
|
612
|
+
} else if (action.type === 'contentInsert') {
|
|
613
|
+
var delta = sharedSlot.toDelta();
|
|
614
|
+
var isEmpty = delta.length === 1 && delta[0].insert === Slot.emptyPlaceholder;
|
|
615
|
+
if (typeof action.content === 'string') {
|
|
616
|
+
length = action.content.length;
|
|
617
|
+
sharedSlot.insert(offset, action.content, action.formats || {});
|
|
618
|
+
} else {
|
|
619
|
+
length = 1;
|
|
620
|
+
var sharedComponent = _this.createSharedComponentByLocalComponent(action.ref);
|
|
621
|
+
sharedSlot.insertEmbed(offset, sharedComponent, action.formats || {});
|
|
622
|
+
}
|
|
623
|
+
if (isEmpty && offset === 0) {
|
|
624
|
+
sharedSlot.delete(sharedSlot.length - 1, 1);
|
|
625
|
+
}
|
|
626
|
+
offset += length;
|
|
627
|
+
} else if (action.type === 'delete') {
|
|
628
|
+
var delta1 = sharedSlot.toDelta();
|
|
629
|
+
if (sharedSlot.length) {
|
|
630
|
+
sharedSlot.delete(offset, action.count);
|
|
631
|
+
}
|
|
632
|
+
if (sharedSlot.length === 0) {
|
|
633
|
+
var _delta_;
|
|
634
|
+
sharedSlot.insert(0, '\n', (_delta_ = delta1[0]) === null || _delta_ === void 0 ? void 0 : _delta_.attributes);
|
|
635
|
+
}
|
|
636
|
+
} else if (action.type === 'attrSet') {
|
|
637
|
+
sharedSlot.setAttribute(action.name, action.value);
|
|
638
|
+
} else if (action.type === 'attrDelete') {
|
|
639
|
+
sharedSlot.removeAttribute(action.name);
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
for(var _iterator = actions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
643
|
+
} catch (err) {
|
|
644
|
+
_didIteratorError = true;
|
|
645
|
+
_iteratorError = err;
|
|
646
|
+
} finally{
|
|
647
|
+
try {
|
|
648
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
649
|
+
_iterator.return();
|
|
650
|
+
}
|
|
651
|
+
} finally{
|
|
652
|
+
if (_didIteratorError) {
|
|
653
|
+
throw _iteratorError;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
});
|
|
659
|
+
this.slotMap.set(localSlot, sharedSlot);
|
|
660
|
+
localSlot.__changeMarker__.addDetachCallback(function() {
|
|
661
|
+
_this.slotMap.delete(localSlot);
|
|
662
|
+
sharedSlot.unobserve(syncRemote);
|
|
663
|
+
sub.unsubscribe();
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
key: "destroy",
|
|
669
|
+
value: function destroy() {
|
|
670
|
+
this.subscriptions.forEach(function(i) {
|
|
671
|
+
return i.unsubscribe();
|
|
672
|
+
});
|
|
673
|
+
this.subscriptions = [];
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
key: "syncSharedMapToLocalMap",
|
|
678
|
+
value: function syncSharedMapToLocalMap(sharedMap, localMap) {
|
|
679
|
+
var _this = this;
|
|
680
|
+
sharedMap.forEach(function(value, key) {
|
|
681
|
+
localMap[key] = _this.createLocalModelBySharedByModel(value);
|
|
682
|
+
});
|
|
683
|
+
this.syncObject(sharedMap, localMap);
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
key: "createLocalMapBySharedMap",
|
|
688
|
+
value: function createLocalMapBySharedMap(sharedMap) {
|
|
689
|
+
var localMap = observe({});
|
|
690
|
+
this.syncSharedMapToLocalMap(sharedMap, localMap);
|
|
691
|
+
return localMap;
|
|
692
|
+
}
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
key: "createLocalArrayBySharedArray",
|
|
696
|
+
value: function createLocalArrayBySharedArray(sharedArray) {
|
|
697
|
+
var _this = this;
|
|
698
|
+
var _localArray;
|
|
699
|
+
var localArray = observe([]);
|
|
700
|
+
(_localArray = localArray).push.apply(_localArray, _to_consumable_array(sharedArray.map(function(item) {
|
|
701
|
+
return _this.createLocalModelBySharedByModel(item);
|
|
702
|
+
})));
|
|
703
|
+
this.syncArray(sharedArray, localArray);
|
|
704
|
+
return localArray;
|
|
705
|
+
}
|
|
706
|
+
},
|
|
707
|
+
{
|
|
708
|
+
key: "syncLocalMapToSharedMap",
|
|
709
|
+
value: function syncLocalMapToSharedMap(localMap, sharedMap) {
|
|
710
|
+
var _this = this;
|
|
711
|
+
Object.entries(localMap).forEach(function(param) {
|
|
712
|
+
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
713
|
+
sharedMap.set(key, _this.createSharedModelByLocalModel(value));
|
|
714
|
+
});
|
|
715
|
+
this.syncObject(sharedMap, localMap);
|
|
716
|
+
}
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
key: "createSharedMapByLocalMap",
|
|
720
|
+
value: function createSharedMapByLocalMap(localMap) {
|
|
721
|
+
var sharedMap = new Map();
|
|
722
|
+
this.syncLocalMapToSharedMap(localMap, sharedMap);
|
|
723
|
+
return sharedMap;
|
|
724
|
+
}
|
|
725
|
+
},
|
|
726
|
+
{
|
|
727
|
+
key: "createSharedArrayByLocalArray",
|
|
728
|
+
value: function createSharedArrayByLocalArray(localArray) {
|
|
729
|
+
var _this = this;
|
|
730
|
+
var sharedArray = new Array$1();
|
|
731
|
+
localArray.forEach(function(value) {
|
|
732
|
+
sharedArray.push([
|
|
733
|
+
_this.createSharedModelByLocalModel(value)
|
|
734
|
+
]);
|
|
735
|
+
});
|
|
736
|
+
this.syncArray(sharedArray, localArray);
|
|
737
|
+
return sharedArray;
|
|
738
|
+
}
|
|
739
|
+
},
|
|
740
|
+
{
|
|
741
|
+
key: "createSharedSlotByLocalSlot",
|
|
742
|
+
value: function createSharedSlotByLocalSlot(localSlot) {
|
|
743
|
+
var _this = this;
|
|
744
|
+
var sharedSlot = new Text();
|
|
745
|
+
var isAsyncSlot = _instanceof$1(localSlot, AsyncSlot);
|
|
746
|
+
sharedSlot.setAttribute('schema', _to_consumable_array(localSlot.schema));
|
|
747
|
+
sharedSlot.setAttribute('type', isAsyncSlot ? 'async' : 'sync');
|
|
748
|
+
if (isAsyncSlot) {
|
|
749
|
+
var isDestroyed = false;
|
|
750
|
+
var sharedMetadata = this.createSharedMapByLocalMap(localSlot.metadata);
|
|
751
|
+
sharedSlot.setAttribute('metadata', sharedMetadata);
|
|
752
|
+
this.subModelLoader.createSubModelBySlot(localSlot).then(function(subDocument) {
|
|
753
|
+
if (isDestroyed) {
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
var content = subDocument.getText('content');
|
|
757
|
+
var state = subDocument.getMap('state');
|
|
758
|
+
_this.syncLocalMapToSharedMap(localSlot.state, state);
|
|
759
|
+
_this.initSharedSlotByLocalSlot(content, localSlot);
|
|
760
|
+
_this.syncSlot(content, localSlot);
|
|
761
|
+
_this.addSubModelEvent.next({
|
|
762
|
+
yDoc: subDocument,
|
|
763
|
+
yType: content
|
|
764
|
+
});
|
|
765
|
+
_this.initSyncEvent(subDocument);
|
|
766
|
+
localSlot.loader.markAsLoaded();
|
|
767
|
+
});
|
|
768
|
+
localSlot.__changeMarker__.addDetachCallback(function() {
|
|
769
|
+
isDestroyed = true;
|
|
770
|
+
});
|
|
771
|
+
return sharedSlot;
|
|
772
|
+
}
|
|
773
|
+
var sharedSlotState = new Map();
|
|
774
|
+
this.syncLocalMapToSharedMap(localSlot.state, sharedSlotState);
|
|
775
|
+
sharedSlot.setAttribute('state', sharedSlotState);
|
|
776
|
+
var sharedContent = new Text();
|
|
777
|
+
this.initSharedSlotByLocalSlot(sharedContent, localSlot);
|
|
778
|
+
sharedSlot.insertEmbed(0, sharedContent);
|
|
779
|
+
this.syncSlot(sharedContent, localSlot);
|
|
780
|
+
return sharedSlot;
|
|
781
|
+
}
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
key: "initSharedSlotByLocalSlot",
|
|
785
|
+
value: function initSharedSlotByLocalSlot(sharedContent, localSlot) {
|
|
786
|
+
var _this = this;
|
|
787
|
+
var offset = 0;
|
|
788
|
+
localSlot.toDelta().forEach(function(i) {
|
|
789
|
+
var formats = {};
|
|
790
|
+
if (i.formats) {
|
|
791
|
+
i.formats.forEach(function(item) {
|
|
792
|
+
formats[item[0].name] = item[1];
|
|
793
|
+
});
|
|
794
|
+
} else {
|
|
795
|
+
formats = null;
|
|
796
|
+
}
|
|
797
|
+
if (typeof i.insert === 'string') {
|
|
798
|
+
sharedContent.insert(offset, i.insert, formats);
|
|
799
|
+
} else {
|
|
800
|
+
var sharedComponent = _this.createSharedComponentByLocalComponent(i.insert);
|
|
801
|
+
sharedContent.insertEmbed(offset, sharedComponent, formats);
|
|
802
|
+
}
|
|
803
|
+
offset += i.insert.length;
|
|
804
|
+
});
|
|
805
|
+
localSlot.getAttributes().forEach(function(item) {
|
|
806
|
+
sharedContent.setAttribute(item[0].name, item[1]);
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
},
|
|
810
|
+
{
|
|
811
|
+
key: "createLocalSlotBySharedSlot",
|
|
812
|
+
value: function createLocalSlotBySharedSlot(sharedSlot) {
|
|
813
|
+
var _this = this;
|
|
814
|
+
var _contentDelta_;
|
|
815
|
+
var type = sharedSlot.getAttribute('type');
|
|
816
|
+
var schema = sharedSlot.getAttribute('schema');
|
|
817
|
+
if (type === 'async') {
|
|
818
|
+
var metadata = sharedSlot.getAttribute('metadata');
|
|
819
|
+
var slot = new AsyncSlot(schema || [], {}, {});
|
|
820
|
+
this.syncSharedMapToLocalMap(metadata, slot.metadata);
|
|
821
|
+
var loadedSubDocument = this.subModelLoader.getLoadedModelBySlot(slot);
|
|
822
|
+
if (loadedSubDocument) {
|
|
823
|
+
var subContent = loadedSubDocument.getText('content');
|
|
824
|
+
var data = loadedSubDocument.getMap('state');
|
|
825
|
+
this.syncSharedMapToLocalMap(data, slot.state);
|
|
826
|
+
this.syncRootSlot(loadedSubDocument, subContent, slot);
|
|
827
|
+
this.addSubModelEvent.next({
|
|
828
|
+
yDoc: loadedSubDocument,
|
|
829
|
+
yType: subContent
|
|
830
|
+
});
|
|
831
|
+
slot.loader.markAsLoaded();
|
|
832
|
+
return slot;
|
|
833
|
+
}
|
|
834
|
+
var isDestroyed = false;
|
|
835
|
+
slot.loader.onRequestLoad.toPromise().then(function() {
|
|
836
|
+
return _this.subModelLoader.loadSubModelBySlot(slot);
|
|
837
|
+
}).then(function(subDocument) {
|
|
838
|
+
if (isDestroyed) {
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
var subContent = subDocument.getText('content');
|
|
842
|
+
var state = subDocument.getMap('state');
|
|
843
|
+
_this.syncSharedMapToLocalMap(state, slot.state);
|
|
844
|
+
_this.syncRootSlot(subDocument, subContent, slot);
|
|
845
|
+
_this.addSubModelEvent.next({
|
|
846
|
+
yDoc: subDocument,
|
|
847
|
+
yType: subContent
|
|
848
|
+
});
|
|
849
|
+
slot.loader.markAsLoaded();
|
|
850
|
+
});
|
|
851
|
+
slot.__changeMarker__.addDetachCallback(function() {
|
|
852
|
+
isDestroyed = true;
|
|
853
|
+
});
|
|
854
|
+
return slot;
|
|
855
|
+
}
|
|
856
|
+
var contentDelta = sharedSlot.toDelta();
|
|
857
|
+
var content = (_contentDelta_ = contentDelta[0]) === null || _contentDelta_ === void 0 ? void 0 : _contentDelta_.insert;
|
|
858
|
+
if (!_instanceof$1(content, Text)) {
|
|
859
|
+
throw collaborateErrorFn('shared slot content type is not `YText`.');
|
|
860
|
+
}
|
|
861
|
+
var localSlot = new Slot(schema || [], {});
|
|
862
|
+
var sharedSlotState = sharedSlot.getAttribute('state');
|
|
863
|
+
this.syncSharedMapToLocalMap(sharedSlotState, localSlot.state);
|
|
864
|
+
this.initLocalSlotBySharedSlot(content, localSlot);
|
|
865
|
+
this.syncSlot(content, localSlot);
|
|
866
|
+
return localSlot;
|
|
867
|
+
}
|
|
868
|
+
},
|
|
869
|
+
{
|
|
870
|
+
key: "initLocalSlotBySharedSlot",
|
|
871
|
+
value: function initLocalSlotBySharedSlot(content, localSlot) {
|
|
872
|
+
var _this = this;
|
|
873
|
+
var delta = content.toDelta();
|
|
874
|
+
var attrs = content.getAttributes();
|
|
875
|
+
Object.keys(attrs).forEach(function(key) {
|
|
876
|
+
var attribute = _this.registry.getAttribute(key);
|
|
877
|
+
if (attribute) {
|
|
878
|
+
localSlot.setAttribute(attribute, attrs[key]);
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
882
|
+
try {
|
|
883
|
+
for(var _iterator = delta[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
884
|
+
var action = _step.value;
|
|
885
|
+
if (action.insert) {
|
|
886
|
+
if (typeof action.insert === 'string') {
|
|
887
|
+
var formats = remoteFormatsToLocal(this.registry, action.attributes);
|
|
888
|
+
localSlot.insert(action.insert, formats);
|
|
889
|
+
} else {
|
|
890
|
+
var sharedComponent = action.insert;
|
|
891
|
+
var component = this.createLocalComponentBySharedComponent(sharedComponent);
|
|
892
|
+
localSlot.insert(component, remoteFormatsToLocal(this.registry, action.attributes));
|
|
893
|
+
}
|
|
894
|
+
} else {
|
|
895
|
+
throw collaborateErrorFn('unexpected delta action.');
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
} catch (err) {
|
|
899
|
+
_didIteratorError = true;
|
|
900
|
+
_iteratorError = err;
|
|
901
|
+
} finally{
|
|
902
|
+
try {
|
|
903
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
904
|
+
_iterator.return();
|
|
905
|
+
}
|
|
906
|
+
} finally{
|
|
907
|
+
if (_didIteratorError) {
|
|
908
|
+
throw _iteratorError;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
},
|
|
914
|
+
{
|
|
915
|
+
key: "createSharedModelByLocalModel",
|
|
916
|
+
value: function createSharedModelByLocalModel(localModel) {
|
|
917
|
+
if (_instanceof$1(localModel, Slot)) {
|
|
918
|
+
return this.createSharedSlotByLocalSlot(localModel);
|
|
919
|
+
}
|
|
920
|
+
if (Array.isArray(localModel)) {
|
|
921
|
+
return this.createSharedArrayByLocalArray(localModel);
|
|
922
|
+
}
|
|
923
|
+
if ((typeof localModel === "undefined" ? "undefined" : _type_of$2(localModel)) === 'object' && localModel !== null) {
|
|
924
|
+
return this.createSharedMapByLocalMap(localModel);
|
|
925
|
+
}
|
|
926
|
+
return localModel;
|
|
927
|
+
}
|
|
928
|
+
},
|
|
929
|
+
{
|
|
930
|
+
key: "createLocalModelBySharedByModel",
|
|
931
|
+
value: function createLocalModelBySharedByModel(sharedModel) {
|
|
932
|
+
if (_instanceof$1(sharedModel, Map)) {
|
|
933
|
+
return this.createLocalMapBySharedMap(sharedModel);
|
|
934
|
+
}
|
|
935
|
+
if (_instanceof$1(sharedModel, Array$1)) {
|
|
936
|
+
return this.createLocalArrayBySharedArray(sharedModel);
|
|
937
|
+
}
|
|
938
|
+
if (_instanceof$1(sharedModel, Text)) {
|
|
939
|
+
return this.createLocalSlotBySharedSlot(sharedModel);
|
|
940
|
+
}
|
|
941
|
+
return sharedModel;
|
|
942
|
+
}
|
|
943
|
+
},
|
|
944
|
+
{
|
|
945
|
+
key: "createSharedComponentByLocalComponent",
|
|
946
|
+
value: function createSharedComponentByLocalComponent(component) {
|
|
947
|
+
var _this = this;
|
|
948
|
+
var sharedComponent = new Map();
|
|
949
|
+
sharedComponent.set('name', component.name);
|
|
950
|
+
if (_instanceof$1(component, AsyncComponent)) {
|
|
951
|
+
sharedComponent.set('type', 'async');
|
|
952
|
+
var sharedMetadata = this.createSharedMapByLocalMap(component.metadata);
|
|
953
|
+
sharedComponent.set('metadata', sharedMetadata);
|
|
954
|
+
var state = component.state;
|
|
955
|
+
var isDestroyed = false;
|
|
956
|
+
state.__changeMarker__.addDetachCallback(function() {
|
|
957
|
+
isDestroyed = true;
|
|
958
|
+
});
|
|
959
|
+
this.subModelLoader.createSubModelByComponent(component).then(function(subDocument) {
|
|
960
|
+
if (isDestroyed) {
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
var state = subDocument.getMap('state');
|
|
964
|
+
_this.syncComponent(subDocument, state, component);
|
|
965
|
+
_this.addSubModelEvent.next({
|
|
966
|
+
yType: state,
|
|
967
|
+
yDoc: subDocument
|
|
968
|
+
});
|
|
969
|
+
_this.initSyncEvent(subDocument);
|
|
970
|
+
component.loader.markAsLoaded();
|
|
971
|
+
});
|
|
972
|
+
return sharedComponent;
|
|
973
|
+
}
|
|
974
|
+
var sharedState = this.createSharedMapByLocalMap(component.state);
|
|
975
|
+
sharedComponent.set('state', sharedState);
|
|
976
|
+
sharedComponent.set('type', 'sync');
|
|
977
|
+
return sharedComponent;
|
|
978
|
+
}
|
|
979
|
+
},
|
|
980
|
+
{
|
|
981
|
+
key: "createLocalComponentBySharedComponent",
|
|
982
|
+
value: function createLocalComponentBySharedComponent(yMap) {
|
|
983
|
+
var _this = this;
|
|
984
|
+
var componentName = yMap.get('name');
|
|
985
|
+
var type = yMap.get('type');
|
|
986
|
+
var instance;
|
|
987
|
+
if (type === 'async') {
|
|
988
|
+
instance = this.registry.createComponentByData(componentName, {}, {});
|
|
989
|
+
if (_instanceof$1(instance, AsyncComponent)) {
|
|
990
|
+
var sharedMetadata = yMap.get('metadata');
|
|
991
|
+
this.syncSharedMapToLocalMap(sharedMetadata, instance.metadata);
|
|
992
|
+
var loadedSubDocument = this.subModelLoader.getLoadedModelByComponent(instance);
|
|
993
|
+
if (loadedSubDocument) {
|
|
994
|
+
var state = loadedSubDocument.getMap('state');
|
|
995
|
+
this.syncComponent(loadedSubDocument, state, instance);
|
|
996
|
+
this.addSubModelEvent.next({
|
|
997
|
+
yType: state,
|
|
998
|
+
yDoc: loadedSubDocument
|
|
999
|
+
});
|
|
1000
|
+
instance.loader.markAsLoaded();
|
|
1001
|
+
return instance;
|
|
1002
|
+
}
|
|
1003
|
+
var state1 = instance.state;
|
|
1004
|
+
var isDestroyed = false;
|
|
1005
|
+
instance.loader.onRequestLoad.toPromise().then(function() {
|
|
1006
|
+
return _this.subModelLoader.loadSubModelByComponent(instance);
|
|
1007
|
+
}).then(function(subDocument) {
|
|
1008
|
+
if (isDestroyed) {
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
var state = subDocument.getMap('state');
|
|
1012
|
+
_this.syncComponent(subDocument, state, instance);
|
|
1013
|
+
_this.addSubModelEvent.next({
|
|
1014
|
+
yType: state,
|
|
1015
|
+
yDoc: subDocument
|
|
1016
|
+
});
|
|
1017
|
+
instance.loader.markAsLoaded();
|
|
1018
|
+
});
|
|
1019
|
+
state1.__changeMarker__.addDetachCallback(function() {
|
|
1020
|
+
isDestroyed = true;
|
|
1021
|
+
});
|
|
1022
|
+
} else if (_instanceof$1(instance, Component)) {
|
|
1023
|
+
throw collaborateErrorFn("component name `".concat(componentName, "` is not a async component."));
|
|
1024
|
+
}
|
|
1025
|
+
} else {
|
|
1026
|
+
var sharedState = yMap.get('state');
|
|
1027
|
+
var state2 = this.createLocalMapBySharedMap(sharedState);
|
|
1028
|
+
instance = this.registry.createComponentByData(componentName, state2);
|
|
1029
|
+
}
|
|
1030
|
+
if (instance) {
|
|
1031
|
+
return instance;
|
|
1032
|
+
}
|
|
1033
|
+
throw collaborateErrorFn("cannot find component factory `".concat(componentName, "`."));
|
|
1034
|
+
}
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
key: "syncArray",
|
|
1038
|
+
value: /**
|
|
1039
|
+
* 双向同步数组
|
|
1040
|
+
* @param sharedArray
|
|
1041
|
+
* @param localArray
|
|
1042
|
+
* @private
|
|
1043
|
+
*/ function syncArray(sharedArray, localArray) {
|
|
1044
|
+
var _this = this;
|
|
1045
|
+
function logError(type) {
|
|
1046
|
+
console.error(collaborateErrorFn("".concat(type, " error, length exceeded, path in ").concat(localArray.__changeMarker__.getPaths().join('/'))));
|
|
1047
|
+
}
|
|
1048
|
+
var sub = localArray.__changeMarker__.onSelfChange.subscribe(function(actions) {
|
|
1049
|
+
_this.runLocalUpdate(sharedArray.doc, !localArray.__changeMarker__.irrevocableUpdate, function() {
|
|
1050
|
+
var index = 0;
|
|
1051
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1052
|
+
try {
|
|
1053
|
+
for(var _iterator = actions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1054
|
+
var action = _step.value;
|
|
1055
|
+
switch(action.type){
|
|
1056
|
+
case 'retain':
|
|
1057
|
+
index = action.offset;
|
|
1058
|
+
break;
|
|
1059
|
+
case 'insert':
|
|
1060
|
+
{
|
|
1061
|
+
var ref = action.ref;
|
|
1062
|
+
if (!Array.isArray(ref)) {
|
|
1063
|
+
throw collaborateErrorFn('The insertion action must have a reference value.');
|
|
1064
|
+
}
|
|
1065
|
+
var data = ref.map(function(item) {
|
|
1066
|
+
return _this.createSharedModelByLocalModel(item);
|
|
1067
|
+
});
|
|
1068
|
+
if (index <= sharedArray.length) {
|
|
1069
|
+
sharedArray.insert(index, data);
|
|
1070
|
+
} else {
|
|
1071
|
+
sharedArray.insert(sharedArray.length, data);
|
|
1072
|
+
logError('insert');
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
break;
|
|
1076
|
+
case 'delete':
|
|
1077
|
+
if (action.count <= 0) {
|
|
1078
|
+
break;
|
|
1079
|
+
}
|
|
1080
|
+
if (index < sharedArray.length) {
|
|
1081
|
+
sharedArray.delete(index, action.count);
|
|
1082
|
+
} else {
|
|
1083
|
+
logError('delete');
|
|
1084
|
+
}
|
|
1085
|
+
break;
|
|
1086
|
+
case 'setIndex':
|
|
1087
|
+
if (action.index < sharedArray.length) {
|
|
1088
|
+
sharedArray.delete(action.index, 1);
|
|
1089
|
+
sharedArray.insert(action.index, [
|
|
1090
|
+
_this.createSharedModelByLocalModel(action.ref)
|
|
1091
|
+
]);
|
|
1092
|
+
} else {
|
|
1093
|
+
sharedArray.insert(sharedArray.length, [
|
|
1094
|
+
_this.createSharedModelByLocalModel(action.ref)
|
|
1095
|
+
]);
|
|
1096
|
+
logError('setIndex');
|
|
1097
|
+
}
|
|
1098
|
+
break;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
} catch (err) {
|
|
1102
|
+
_didIteratorError = true;
|
|
1103
|
+
_iteratorError = err;
|
|
1104
|
+
} finally{
|
|
1105
|
+
try {
|
|
1106
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1107
|
+
_iterator.return();
|
|
1108
|
+
}
|
|
1109
|
+
} finally{
|
|
1110
|
+
if (_didIteratorError) {
|
|
1111
|
+
throw _iteratorError;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
});
|
|
1117
|
+
var syncRemote = function syncRemote(ev, tr) {
|
|
1118
|
+
_this.runRemoteUpdate(tr, function() {
|
|
1119
|
+
var index = 0;
|
|
1120
|
+
ev.delta.forEach(function(action) {
|
|
1121
|
+
if (Reflect.has(action, 'retain')) {
|
|
1122
|
+
index += action.retain;
|
|
1123
|
+
} else if (action.insert) {
|
|
1124
|
+
var _localArray;
|
|
1125
|
+
var data = action.insert.map(function(item) {
|
|
1126
|
+
return _this.createLocalModelBySharedByModel(item);
|
|
1127
|
+
});
|
|
1128
|
+
(_localArray = localArray).splice.apply(_localArray, [
|
|
1129
|
+
index,
|
|
1130
|
+
0
|
|
1131
|
+
].concat(_to_consumable_array(data)));
|
|
1132
|
+
index += data.length;
|
|
1133
|
+
} else if (action.delete) {
|
|
1134
|
+
localArray.splice(index, action.delete);
|
|
1135
|
+
}
|
|
1136
|
+
});
|
|
1137
|
+
});
|
|
1138
|
+
};
|
|
1139
|
+
sharedArray.observe(syncRemote);
|
|
1140
|
+
localArray.__changeMarker__.addDetachCallback(function() {
|
|
1141
|
+
sub.unsubscribe();
|
|
1142
|
+
sharedArray.unobserve(syncRemote);
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
},
|
|
1146
|
+
{
|
|
1147
|
+
key: "syncObject",
|
|
1148
|
+
value: /**
|
|
1149
|
+
* 双向同步对象
|
|
1150
|
+
* @param sharedObject
|
|
1151
|
+
* @param localObject
|
|
1152
|
+
* @private
|
|
1153
|
+
*/ function syncObject(sharedObject, localObject) {
|
|
1154
|
+
var _this = this;
|
|
1155
|
+
var syncRemote = function syncRemote(ev, tr) {
|
|
1156
|
+
_this.runRemoteUpdate(tr, function() {
|
|
1157
|
+
ev.changes.keys.forEach(function(item, key) {
|
|
1158
|
+
if (item.action === 'add' || item.action === 'update') {
|
|
1159
|
+
var value = sharedObject.get(key);
|
|
1160
|
+
localObject[key] = _this.createLocalModelBySharedByModel(value);
|
|
1161
|
+
} else {
|
|
1162
|
+
Reflect.deleteProperty(localObject, key);
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1165
|
+
});
|
|
1166
|
+
};
|
|
1167
|
+
sharedObject.observe(syncRemote);
|
|
1168
|
+
var sub = localObject.__changeMarker__.onSelfChange.subscribe(function(actions) {
|
|
1169
|
+
_this.runLocalUpdate(sharedObject.doc, !localObject.__changeMarker__.irrevocableUpdate, function() {
|
|
1170
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1171
|
+
try {
|
|
1172
|
+
for(var _iterator = actions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1173
|
+
var action = _step.value;
|
|
1174
|
+
switch(action.type){
|
|
1175
|
+
case 'propSet':
|
|
1176
|
+
{
|
|
1177
|
+
var subModel = _this.createSharedModelByLocalModel(action.ref);
|
|
1178
|
+
sharedObject.set(action.key, subModel);
|
|
1179
|
+
if (sharedObject.size === 0) {
|
|
1180
|
+
// 奇怪的 bug,设置了子模型,但子模型会标记为 deleted,导致设置后无效
|
|
1181
|
+
console.error(collaborateErrorFn("prop set error, key is ".concat(action.key)));
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
break;
|
|
1185
|
+
case 'propDelete':
|
|
1186
|
+
sharedObject.delete(action.key);
|
|
1187
|
+
break;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
} catch (err) {
|
|
1191
|
+
_didIteratorError = true;
|
|
1192
|
+
_iteratorError = err;
|
|
1193
|
+
} finally{
|
|
1194
|
+
try {
|
|
1195
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1196
|
+
_iterator.return();
|
|
1197
|
+
}
|
|
1198
|
+
} finally{
|
|
1199
|
+
if (_didIteratorError) {
|
|
1200
|
+
throw _iteratorError;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
});
|
|
1205
|
+
});
|
|
1206
|
+
localObject.__changeMarker__.addDetachCallback(function() {
|
|
1207
|
+
sharedObject.unobserve(syncRemote);
|
|
1208
|
+
sub.unsubscribe();
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
},
|
|
1212
|
+
{
|
|
1213
|
+
key: "runLocalUpdate",
|
|
1214
|
+
value: function runLocalUpdate(yDoc, record, fn) {
|
|
1215
|
+
if (this.updateFromRemote || !yDoc) {
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
var changeList = this.updateRemoteActions.get(yDoc);
|
|
1219
|
+
if (!changeList) {
|
|
1220
|
+
changeList = [];
|
|
1221
|
+
this.updateRemoteActions.set(yDoc, changeList);
|
|
1222
|
+
}
|
|
1223
|
+
changeList.push({
|
|
1224
|
+
record: record,
|
|
1225
|
+
action: fn
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
},
|
|
1229
|
+
{
|
|
1230
|
+
key: "runRemoteUpdate",
|
|
1231
|
+
value: function runRemoteUpdate(tr, fn) {
|
|
1232
|
+
if (tr.origin === tr.doc) {
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
this.updateFromRemote = true;
|
|
1236
|
+
if (_instanceof$1(tr.origin, UndoManager)) {
|
|
1237
|
+
this.scheduler.historyApplyTransact(fn);
|
|
1238
|
+
} else {
|
|
1239
|
+
this.scheduler.remoteUpdateTransact(fn);
|
|
1240
|
+
}
|
|
1241
|
+
this.updateFromRemote = false;
|
|
1242
|
+
}
|
|
606
1243
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
1244
|
+
]);
|
|
1245
|
+
return Collaborate;
|
|
1246
|
+
}();
|
|
1247
|
+
Collaborate = _ts_decorate$2([
|
|
1248
|
+
Injectable(),
|
|
1249
|
+
_ts_metadata$2("design:type", Function),
|
|
1250
|
+
_ts_metadata$2("design:paramtypes", [
|
|
1251
|
+
typeof Scheduler === "undefined" ? Object : Scheduler,
|
|
1252
|
+
typeof Registry === "undefined" ? Object : Registry,
|
|
1253
|
+
typeof Selection === "undefined" ? Object : Selection,
|
|
1254
|
+
typeof SubModelLoader === "undefined" ? Object : SubModelLoader
|
|
1255
|
+
])
|
|
1256
|
+
], Collaborate);
|
|
1257
|
+
function remoteFormatsToLocal(registry, attrs) {
|
|
1258
|
+
var formats = [];
|
|
1259
|
+
if (attrs) {
|
|
1260
|
+
Object.keys(attrs).forEach(function(key) {
|
|
1261
|
+
var formatter = registry.getFormatter(key);
|
|
1262
|
+
if (formatter) {
|
|
1263
|
+
formats.push([
|
|
1264
|
+
formatter,
|
|
1265
|
+
attrs[key]
|
|
1266
|
+
]);
|
|
1267
|
+
}
|
|
614
1268
|
});
|
|
615
|
-
slot.loader.markAsLoaded();
|
|
616
|
-
});
|
|
617
|
-
slot.__changeMarker__.addDetachCallback(() => {
|
|
618
|
-
isDestroyed = true;
|
|
619
|
-
});
|
|
620
|
-
return slot;
|
|
621
1269
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
1270
|
+
return formats;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
function _class_call_check$7(instance, Constructor) {
|
|
1274
|
+
if (!(instance instanceof Constructor)) {
|
|
1275
|
+
throw new TypeError("Cannot call a class as a function");
|
|
626
1276
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
const delta = content.toDelta();
|
|
636
|
-
const attrs = content.getAttributes();
|
|
637
|
-
Object.keys(attrs).forEach((key) => {
|
|
638
|
-
const attribute = this.registry.getAttribute(key);
|
|
639
|
-
if (attribute) {
|
|
640
|
-
localSlot.setAttribute(attribute, attrs[key]);
|
|
641
|
-
}
|
|
642
|
-
});
|
|
643
|
-
for (const action of delta) {
|
|
644
|
-
if (action.insert) {
|
|
645
|
-
if (typeof action.insert === "string") {
|
|
646
|
-
const formats = remoteFormatsToLocal(this.registry, action.attributes);
|
|
647
|
-
localSlot.insert(action.insert, formats);
|
|
648
|
-
} else {
|
|
649
|
-
const sharedComponent = action.insert;
|
|
650
|
-
const component = this.createLocalComponentBySharedComponent(sharedComponent);
|
|
651
|
-
localSlot.insert(component, remoteFormatsToLocal(this.registry, action.attributes));
|
|
652
|
-
}
|
|
653
|
-
} else {
|
|
654
|
-
throw collaborateErrorFn("unexpected delta action.");
|
|
655
|
-
}
|
|
1277
|
+
}
|
|
1278
|
+
function _defineProperties$6(target, props) {
|
|
1279
|
+
for(var i = 0; i < props.length; i++){
|
|
1280
|
+
var descriptor = props[i];
|
|
1281
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
1282
|
+
descriptor.configurable = true;
|
|
1283
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
1284
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
656
1285
|
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
if (
|
|
660
|
-
|
|
1286
|
+
}
|
|
1287
|
+
function _create_class$6(Constructor, protoProps, staticProps) {
|
|
1288
|
+
if (protoProps) _defineProperties$6(Constructor.prototype, protoProps);
|
|
1289
|
+
return Constructor;
|
|
1290
|
+
}
|
|
1291
|
+
function _define_property$7(obj, key, value) {
|
|
1292
|
+
if (key in obj) {
|
|
1293
|
+
Object.defineProperty(obj, key, {
|
|
1294
|
+
value: value,
|
|
1295
|
+
enumerable: true,
|
|
1296
|
+
configurable: true,
|
|
1297
|
+
writable: true
|
|
1298
|
+
});
|
|
1299
|
+
} else {
|
|
1300
|
+
obj[key] = value;
|
|
661
1301
|
}
|
|
662
|
-
|
|
663
|
-
|
|
1302
|
+
return obj;
|
|
1303
|
+
}
|
|
1304
|
+
function _ts_decorate$1(decorators, target, key, desc) {
|
|
1305
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1306
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1307
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1308
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1309
|
+
}
|
|
1310
|
+
function _ts_metadata$1(k, v) {
|
|
1311
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1312
|
+
}
|
|
1313
|
+
function _ts_param$1(paramIndex, decorator) {
|
|
1314
|
+
return function(target, key) {
|
|
1315
|
+
decorator(target, key, paramIndex);
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
var CustomUndoManagerConfig = function CustomUndoManagerConfig() {
|
|
1319
|
+
_class_call_check$7(this, CustomUndoManagerConfig);
|
|
1320
|
+
};
|
|
1321
|
+
var collabHistoryErrorFn = makeError('CollabHistory');
|
|
1322
|
+
var CollabHistory = /*#__PURE__*/ function() {
|
|
1323
|
+
function CollabHistory(rootComponentRef, collaborate, scheduler, stackSize, undoManagerConfig) {
|
|
1324
|
+
_class_call_check$7(this, CollabHistory);
|
|
1325
|
+
_define_property$7(this, "rootComponentRef", void 0);
|
|
1326
|
+
_define_property$7(this, "collaborate", void 0);
|
|
1327
|
+
_define_property$7(this, "scheduler", void 0);
|
|
1328
|
+
_define_property$7(this, "stackSize", void 0);
|
|
1329
|
+
_define_property$7(this, "undoManagerConfig", void 0);
|
|
1330
|
+
_define_property$7(this, "onBack", void 0);
|
|
1331
|
+
_define_property$7(this, "onForward", void 0);
|
|
1332
|
+
_define_property$7(this, "onChange", void 0);
|
|
1333
|
+
_define_property$7(this, "onPush", void 0);
|
|
1334
|
+
_define_property$7(this, "manager", void 0);
|
|
1335
|
+
_define_property$7(this, "historyItems", void 0);
|
|
1336
|
+
_define_property$7(this, "index", void 0);
|
|
1337
|
+
_define_property$7(this, "subscriptions", void 0);
|
|
1338
|
+
_define_property$7(this, "backEvent", void 0);
|
|
1339
|
+
_define_property$7(this, "forwardEvent", void 0);
|
|
1340
|
+
_define_property$7(this, "changeEvent", void 0);
|
|
1341
|
+
_define_property$7(this, "pushEvent", void 0);
|
|
1342
|
+
this.rootComponentRef = rootComponentRef;
|
|
1343
|
+
this.collaborate = collaborate;
|
|
1344
|
+
this.scheduler = scheduler;
|
|
1345
|
+
this.stackSize = stackSize;
|
|
1346
|
+
this.undoManagerConfig = undoManagerConfig;
|
|
1347
|
+
this.manager = null;
|
|
1348
|
+
this.historyItems = [];
|
|
1349
|
+
this.index = 0;
|
|
1350
|
+
this.subscriptions = [];
|
|
1351
|
+
this.backEvent = new Subject();
|
|
1352
|
+
this.forwardEvent = new Subject();
|
|
1353
|
+
this.changeEvent = new Subject();
|
|
1354
|
+
this.pushEvent = new Subject();
|
|
1355
|
+
this.onBack = this.backEvent.asObservable();
|
|
1356
|
+
this.onForward = this.forwardEvent.asObservable();
|
|
1357
|
+
this.onChange = this.changeEvent.asObservable();
|
|
1358
|
+
this.onPush = this.pushEvent.asObservable();
|
|
664
1359
|
}
|
|
665
|
-
|
|
666
|
-
|
|
1360
|
+
_create_class$6(CollabHistory, [
|
|
1361
|
+
{
|
|
1362
|
+
key: "canBack",
|
|
1363
|
+
get: function get() {
|
|
1364
|
+
var _this_manager;
|
|
1365
|
+
return ((_this_manager = this.manager) === null || _this_manager === void 0 ? void 0 : _this_manager.canUndo()) || false;
|
|
1366
|
+
}
|
|
1367
|
+
},
|
|
1368
|
+
{
|
|
1369
|
+
key: "canForward",
|
|
1370
|
+
get: function get() {
|
|
1371
|
+
var _this_manager;
|
|
1372
|
+
return ((_this_manager = this.manager) === null || _this_manager === void 0 ? void 0 : _this_manager.canRedo()) || false;
|
|
1373
|
+
}
|
|
1374
|
+
},
|
|
1375
|
+
{
|
|
1376
|
+
key: "listen",
|
|
1377
|
+
value: function listen() {
|
|
1378
|
+
var _this = this;
|
|
1379
|
+
var root = this.collaborate.yDoc.getMap('RootComponent');
|
|
1380
|
+
var rootComponent = this.rootComponentRef.component;
|
|
1381
|
+
this.collaborate.syncRootComponent(this.collaborate.yDoc, root, rootComponent);
|
|
1382
|
+
var undoManagerConfig = this.undoManagerConfig || {};
|
|
1383
|
+
var manager = new UndoManager(root, {
|
|
1384
|
+
trackedOrigins: new Set([
|
|
1385
|
+
this.collaborate.yDoc
|
|
1386
|
+
]),
|
|
1387
|
+
captureTransaction: function captureTransaction(arg) {
|
|
1388
|
+
if (undoManagerConfig.captureTransaction) {
|
|
1389
|
+
return undoManagerConfig.captureTransaction(arg);
|
|
1390
|
+
}
|
|
1391
|
+
return true;
|
|
1392
|
+
},
|
|
1393
|
+
deleteFilter: function deleteFilter(item) {
|
|
1394
|
+
if (undoManagerConfig.deleteFilter) {
|
|
1395
|
+
return undoManagerConfig.deleteFilter(item);
|
|
1396
|
+
}
|
|
1397
|
+
return true;
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1400
|
+
this.manager = manager;
|
|
1401
|
+
var beforePosition = null;
|
|
1402
|
+
this.subscriptions.push(this.scheduler.onLocalChangeBefore.subscribe(function() {
|
|
1403
|
+
beforePosition = _this.collaborate.getRelativeCursorLocation();
|
|
1404
|
+
}), this.collaborate.onAddSubModel.subscribe(function() {
|
|
1405
|
+
throw collabHistoryErrorFn('single document does not support submodels.');
|
|
1406
|
+
}));
|
|
1407
|
+
manager.on('stack-item-added', function(event) {
|
|
1408
|
+
if (event.type === 'undo') {
|
|
1409
|
+
if (event.origin === manager) {
|
|
1410
|
+
_this.index++;
|
|
1411
|
+
} else {
|
|
1412
|
+
_this.historyItems.length = _this.index;
|
|
1413
|
+
_this.historyItems.push({
|
|
1414
|
+
before: beforePosition,
|
|
1415
|
+
after: _this.collaborate.getRelativeCursorLocation()
|
|
1416
|
+
});
|
|
1417
|
+
_this.index++;
|
|
1418
|
+
}
|
|
1419
|
+
} else {
|
|
1420
|
+
_this.index--;
|
|
1421
|
+
}
|
|
1422
|
+
if (manager.undoStack.length > _this.stackSize) {
|
|
1423
|
+
_this.historyItems.shift();
|
|
1424
|
+
manager.undoStack.shift();
|
|
1425
|
+
}
|
|
1426
|
+
if (event.origin === _this.collaborate.yDoc) {
|
|
1427
|
+
_this.pushEvent.next();
|
|
1428
|
+
}
|
|
1429
|
+
_this.changeEvent.next();
|
|
1430
|
+
});
|
|
1431
|
+
manager.on('stack-item-popped', function(ev) {
|
|
1432
|
+
var index = ev.type === 'undo' ? _this.index : _this.index - 1;
|
|
1433
|
+
var position = _this.historyItems[index] || null;
|
|
1434
|
+
var p = ev.type === 'undo' ? position === null || position === void 0 ? void 0 : position.before : position === null || position === void 0 ? void 0 : position.after;
|
|
1435
|
+
_this.collaborate.restoreCursorPosition(p);
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
},
|
|
1439
|
+
{
|
|
1440
|
+
key: "back",
|
|
1441
|
+
value: function back() {
|
|
1442
|
+
if (this.canBack) {
|
|
1443
|
+
var _this_manager;
|
|
1444
|
+
(_this_manager = this.manager) === null || _this_manager === void 0 ? void 0 : _this_manager.undo();
|
|
1445
|
+
this.backEvent.next();
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
},
|
|
1449
|
+
{
|
|
1450
|
+
key: "forward",
|
|
1451
|
+
value: function forward() {
|
|
1452
|
+
if (this.canForward) {
|
|
1453
|
+
var _this_manager;
|
|
1454
|
+
(_this_manager = this.manager) === null || _this_manager === void 0 ? void 0 : _this_manager.redo();
|
|
1455
|
+
this.forwardEvent.next();
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
},
|
|
1459
|
+
{
|
|
1460
|
+
key: "clear",
|
|
1461
|
+
value: function clear() {
|
|
1462
|
+
var _this_manager;
|
|
1463
|
+
var last = this.historyItems.pop();
|
|
1464
|
+
this.historyItems = last ? [
|
|
1465
|
+
last
|
|
1466
|
+
] : [];
|
|
1467
|
+
this.index = last ? 1 : 0;
|
|
1468
|
+
(_this_manager = this.manager) === null || _this_manager === void 0 ? void 0 : _this_manager.clear();
|
|
1469
|
+
this.changeEvent.next();
|
|
1470
|
+
}
|
|
1471
|
+
},
|
|
1472
|
+
{
|
|
1473
|
+
key: "destroy",
|
|
1474
|
+
value: function destroy() {
|
|
1475
|
+
this.index = 0;
|
|
1476
|
+
this.historyItems = [];
|
|
1477
|
+
this.subscriptions.forEach(function(i) {
|
|
1478
|
+
return i.unsubscribe();
|
|
1479
|
+
});
|
|
1480
|
+
if (this.manager) {
|
|
1481
|
+
this.manager.destroy();
|
|
1482
|
+
this.manager.captureTransaction = function() {
|
|
1483
|
+
return true;
|
|
1484
|
+
};
|
|
1485
|
+
this.manager.deleteFilter = function() {
|
|
1486
|
+
return true;
|
|
1487
|
+
};
|
|
1488
|
+
this.manager.trackedOrigins = new Set([
|
|
1489
|
+
null
|
|
1490
|
+
]);
|
|
1491
|
+
}
|
|
1492
|
+
this.manager = null;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
]);
|
|
1496
|
+
return CollabHistory;
|
|
1497
|
+
}();
|
|
1498
|
+
CollabHistory = _ts_decorate$1([
|
|
1499
|
+
Injectable(),
|
|
1500
|
+
_ts_param$1(3, Inject(HISTORY_STACK_SIZE)),
|
|
1501
|
+
_ts_param$1(4, Optional()),
|
|
1502
|
+
_ts_metadata$1("design:type", Function),
|
|
1503
|
+
_ts_metadata$1("design:paramtypes", [
|
|
1504
|
+
typeof RootComponentRef === "undefined" ? Object : RootComponentRef,
|
|
1505
|
+
typeof Collaborate === "undefined" ? Object : Collaborate,
|
|
1506
|
+
typeof Scheduler === "undefined" ? Object : Scheduler,
|
|
1507
|
+
Number,
|
|
1508
|
+
typeof CustomUndoManagerConfig === "undefined" ? Object : CustomUndoManagerConfig
|
|
1509
|
+
])
|
|
1510
|
+
], CollabHistory);
|
|
1511
|
+
|
|
1512
|
+
function _class_call_check$6(instance, Constructor) {
|
|
1513
|
+
if (!(instance instanceof Constructor)) {
|
|
1514
|
+
throw new TypeError("Cannot call a class as a function");
|
|
667
1515
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
1516
|
+
}
|
|
1517
|
+
function _defineProperties$5(target, props) {
|
|
1518
|
+
for(var i = 0; i < props.length; i++){
|
|
1519
|
+
var descriptor = props[i];
|
|
1520
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
1521
|
+
descriptor.configurable = true;
|
|
1522
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
1523
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
673
1524
|
}
|
|
674
|
-
|
|
675
|
-
|
|
1525
|
+
}
|
|
1526
|
+
function _create_class$5(Constructor, protoProps, staticProps) {
|
|
1527
|
+
if (protoProps) _defineProperties$5(Constructor.prototype, protoProps);
|
|
1528
|
+
return Constructor;
|
|
1529
|
+
}
|
|
1530
|
+
function _define_property$6(obj, key, value) {
|
|
1531
|
+
if (key in obj) {
|
|
1532
|
+
Object.defineProperty(obj, key, {
|
|
1533
|
+
value: value,
|
|
1534
|
+
enumerable: true,
|
|
1535
|
+
configurable: true,
|
|
1536
|
+
writable: true
|
|
1537
|
+
});
|
|
1538
|
+
} else {
|
|
1539
|
+
obj[key] = value;
|
|
676
1540
|
}
|
|
677
|
-
|
|
678
|
-
|
|
1541
|
+
return obj;
|
|
1542
|
+
}
|
|
1543
|
+
/**
|
|
1544
|
+
* 协作消息总线,用于同步各终端消息
|
|
1545
|
+
*/ var MessageBus = /*#__PURE__*/ function() {
|
|
1546
|
+
function MessageBus() {
|
|
1547
|
+
_class_call_check$6(this, MessageBus);
|
|
1548
|
+
_define_property$6(this, "onSync", void 0);
|
|
1549
|
+
_define_property$6(this, "syncEvent", new Subject());
|
|
1550
|
+
this.onSync = this.syncEvent.asObservable();
|
|
679
1551
|
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
sharedComponent.set("metadata", sharedMetadata);
|
|
689
|
-
const state = component.state;
|
|
690
|
-
let isDestroyed = false;
|
|
691
|
-
state.__changeMarker__.addDetachCallback(() => {
|
|
692
|
-
isDestroyed = true;
|
|
693
|
-
});
|
|
694
|
-
this.subModelLoader.createSubModelByComponent(component).then((subDocument) => {
|
|
695
|
-
if (isDestroyed) {
|
|
696
|
-
return;
|
|
1552
|
+
_create_class$5(MessageBus, [
|
|
1553
|
+
{
|
|
1554
|
+
/**
|
|
1555
|
+
* 立即同步消息
|
|
1556
|
+
*/ key: "sync",
|
|
1557
|
+
value: function sync() {
|
|
1558
|
+
this.syncEvent.next();
|
|
1559
|
+
}
|
|
697
1560
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
component.loader.markAsLoaded();
|
|
706
|
-
});
|
|
707
|
-
return sharedComponent;
|
|
1561
|
+
]);
|
|
1562
|
+
return MessageBus;
|
|
1563
|
+
}();
|
|
1564
|
+
|
|
1565
|
+
function _class_call_check$5(instance, Constructor) {
|
|
1566
|
+
if (!(instance instanceof Constructor)) {
|
|
1567
|
+
throw new TypeError("Cannot call a class as a function");
|
|
708
1568
|
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
});
|
|
731
|
-
instance.loader.markAsLoaded();
|
|
732
|
-
return instance;
|
|
733
|
-
}
|
|
734
|
-
const state = instance.state;
|
|
735
|
-
let isDestroyed = false;
|
|
736
|
-
instance.loader.onRequestLoad.toPromise().then(() => {
|
|
737
|
-
return this.subModelLoader.loadSubModelByComponent(instance);
|
|
738
|
-
}).then((subDocument) => {
|
|
739
|
-
if (isDestroyed) {
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
const state2 = subDocument.getMap("state");
|
|
743
|
-
this.syncComponent(subDocument, state2, instance);
|
|
744
|
-
this.addSubModelEvent.next({
|
|
745
|
-
yType: state2,
|
|
746
|
-
yDoc: subDocument
|
|
747
|
-
});
|
|
748
|
-
instance.loader.markAsLoaded();
|
|
749
|
-
});
|
|
750
|
-
state.__changeMarker__.addDetachCallback(() => {
|
|
751
|
-
isDestroyed = true;
|
|
1569
|
+
}
|
|
1570
|
+
function _defineProperties$4(target, props) {
|
|
1571
|
+
for(var i = 0; i < props.length; i++){
|
|
1572
|
+
var descriptor = props[i];
|
|
1573
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
1574
|
+
descriptor.configurable = true;
|
|
1575
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
1576
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
function _create_class$4(Constructor, protoProps, staticProps) {
|
|
1580
|
+
if (protoProps) _defineProperties$4(Constructor.prototype, protoProps);
|
|
1581
|
+
return Constructor;
|
|
1582
|
+
}
|
|
1583
|
+
function _define_property$5(obj, key, value) {
|
|
1584
|
+
if (key in obj) {
|
|
1585
|
+
Object.defineProperty(obj, key, {
|
|
1586
|
+
value: value,
|
|
1587
|
+
enumerable: true,
|
|
1588
|
+
configurable: true,
|
|
1589
|
+
writable: true
|
|
752
1590
|
});
|
|
753
|
-
} else if (instance instanceof Component) {
|
|
754
|
-
throw collaborateErrorFn(`component name \`${componentName}\` is not a async component.`);
|
|
755
|
-
}
|
|
756
1591
|
} else {
|
|
757
|
-
|
|
758
|
-
const state = this.createLocalMapBySharedMap(sharedState);
|
|
759
|
-
instance = this.registry.createComponentByData(componentName, state);
|
|
1592
|
+
obj[key] = value;
|
|
760
1593
|
}
|
|
761
|
-
|
|
762
|
-
|
|
1594
|
+
return obj;
|
|
1595
|
+
}
|
|
1596
|
+
function _instanceof(left, right) {
|
|
1597
|
+
"@swc/helpers - instanceof";
|
|
1598
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1599
|
+
return !!right[Symbol.hasInstance](left);
|
|
1600
|
+
} else {
|
|
1601
|
+
return left instanceof right;
|
|
763
1602
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
1603
|
+
}
|
|
1604
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
1605
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1606
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1607
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1608
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1609
|
+
}
|
|
1610
|
+
function _ts_metadata(k, v) {
|
|
1611
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1612
|
+
}
|
|
1613
|
+
function _ts_param(paramIndex, decorator) {
|
|
1614
|
+
return function(target, key) {
|
|
1615
|
+
decorator(target, key, paramIndex);
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
var MultipleDocCollabHistory = /*#__PURE__*/ function() {
|
|
1619
|
+
function MultipleDocCollabHistory(collaborate, scheduler, rootComponentRef, stackSize, undoManagerConfig) {
|
|
1620
|
+
_class_call_check$5(this, MultipleDocCollabHistory);
|
|
1621
|
+
_define_property$5(this, "collaborate", void 0);
|
|
1622
|
+
_define_property$5(this, "scheduler", void 0);
|
|
1623
|
+
_define_property$5(this, "rootComponentRef", void 0);
|
|
1624
|
+
_define_property$5(this, "stackSize", void 0);
|
|
1625
|
+
_define_property$5(this, "undoManagerConfig", void 0);
|
|
1626
|
+
_define_property$5(this, "onChange", void 0);
|
|
1627
|
+
_define_property$5(this, "onBack", void 0);
|
|
1628
|
+
_define_property$5(this, "onForward", void 0);
|
|
1629
|
+
_define_property$5(this, "onPush", void 0);
|
|
1630
|
+
_define_property$5(this, "isListen", void 0);
|
|
1631
|
+
_define_property$5(this, "changeEvent", void 0);
|
|
1632
|
+
_define_property$5(this, "backEvent", void 0);
|
|
1633
|
+
_define_property$5(this, "forwardEvent", void 0);
|
|
1634
|
+
_define_property$5(this, "pushEvent", void 0);
|
|
1635
|
+
_define_property$5(this, "actionStack", void 0);
|
|
1636
|
+
_define_property$5(this, "index", void 0);
|
|
1637
|
+
_define_property$5(this, "stackItem", void 0);
|
|
1638
|
+
_define_property$5(this, "timer", void 0);
|
|
1639
|
+
_define_property$5(this, "beforePosition", void 0);
|
|
1640
|
+
_define_property$5(this, "subscription", void 0);
|
|
1641
|
+
_define_property$5(this, "subDocs", void 0);
|
|
1642
|
+
_define_property$5(this, "listenerCaches", void 0);
|
|
1643
|
+
this.collaborate = collaborate;
|
|
1644
|
+
this.scheduler = scheduler;
|
|
1645
|
+
this.rootComponentRef = rootComponentRef;
|
|
1646
|
+
this.stackSize = stackSize;
|
|
1647
|
+
this.undoManagerConfig = undoManagerConfig;
|
|
1648
|
+
this.isListen = false;
|
|
1649
|
+
this.changeEvent = new Subject();
|
|
1650
|
+
this.backEvent = new Subject();
|
|
1651
|
+
this.forwardEvent = new Subject();
|
|
1652
|
+
this.pushEvent = new Subject();
|
|
1653
|
+
this.actionStack = [];
|
|
1654
|
+
this.index = 0;
|
|
1655
|
+
this.stackItem = null;
|
|
1656
|
+
this.timer = null;
|
|
1657
|
+
this.beforePosition = null;
|
|
1658
|
+
this.subscription = new Subscription();
|
|
1659
|
+
this.subDocs = new Set();
|
|
1660
|
+
this.listenerCaches = new Set();
|
|
1661
|
+
this.onChange = this.changeEvent.asObservable();
|
|
1662
|
+
this.onBack = this.backEvent.asObservable();
|
|
1663
|
+
this.onForward = this.forwardEvent.asObservable();
|
|
1664
|
+
this.onPush = this.pushEvent.asObservable();
|
|
775
1665
|
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
1666
|
+
_create_class$4(MultipleDocCollabHistory, [
|
|
1667
|
+
{
|
|
1668
|
+
key: "canBack",
|
|
1669
|
+
get: function get() {
|
|
1670
|
+
return this.actionStack.length > 0 && this.index > 0;
|
|
1671
|
+
}
|
|
1672
|
+
},
|
|
1673
|
+
{
|
|
1674
|
+
key: "canForward",
|
|
1675
|
+
get: function get() {
|
|
1676
|
+
return this.actionStack.length > 0 && this.index < this.actionStack.length;
|
|
1677
|
+
}
|
|
1678
|
+
},
|
|
1679
|
+
{
|
|
1680
|
+
key: "listen",
|
|
1681
|
+
value: function listen() {
|
|
1682
|
+
var _this = this;
|
|
1683
|
+
this.isListen = true;
|
|
1684
|
+
var root = this.collaborate.yDoc.getMap('RootComponent');
|
|
1685
|
+
var rootComponent = this.rootComponentRef.component;
|
|
1686
|
+
this.collaborate.syncRootComponent(this.collaborate.yDoc, root, rootComponent);
|
|
1687
|
+
this.listenItem(root, this.collaborate.yDoc);
|
|
1688
|
+
this.subscription.add(this.collaborate.onAddSubModel.subscribe(function(param) {
|
|
1689
|
+
var yType = param.yType, yDoc = param.yDoc;
|
|
1690
|
+
if (_this.subDocs.has(yType)) {
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
_this.subDocs.add(yType);
|
|
1694
|
+
if (_this.isListen) {
|
|
1695
|
+
_this.listenItem(yType, yDoc);
|
|
1696
|
+
}
|
|
1697
|
+
}), this.scheduler.onLocalChangeBefore.subscribe(function() {
|
|
1698
|
+
_this.beforePosition = _this.collaborate.getRelativeCursorLocation();
|
|
1699
|
+
}));
|
|
1700
|
+
}
|
|
1701
|
+
},
|
|
1702
|
+
{
|
|
1703
|
+
key: "forward",
|
|
1704
|
+
value: function forward() {
|
|
1705
|
+
if (!this.canForward) {
|
|
1706
|
+
return;
|
|
789
1707
|
}
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
1708
|
+
clearTimeout(this.timer);
|
|
1709
|
+
var item = this.actionStack[this.index];
|
|
1710
|
+
if (item) {
|
|
1711
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1712
|
+
try {
|
|
1713
|
+
for(var _iterator = item.undoManagers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1714
|
+
var i = _step.value;
|
|
1715
|
+
i.redo();
|
|
1716
|
+
}
|
|
1717
|
+
} catch (err) {
|
|
1718
|
+
_didIteratorError = true;
|
|
1719
|
+
_iteratorError = err;
|
|
1720
|
+
} finally{
|
|
1721
|
+
try {
|
|
1722
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1723
|
+
_iterator.return();
|
|
1724
|
+
}
|
|
1725
|
+
} finally{
|
|
1726
|
+
if (_didIteratorError) {
|
|
1727
|
+
throw _iteratorError;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
this.collaborate.restoreCursorPosition(item.after);
|
|
1732
|
+
}
|
|
1733
|
+
this.index++;
|
|
1734
|
+
this.forwardEvent.next();
|
|
1735
|
+
this.changeEvent.next();
|
|
1736
|
+
}
|
|
1737
|
+
},
|
|
1738
|
+
{
|
|
1739
|
+
key: "back",
|
|
1740
|
+
value: function back() {
|
|
1741
|
+
if (!this.canBack) {
|
|
1742
|
+
return;
|
|
1743
|
+
}
|
|
1744
|
+
clearTimeout(this.timer);
|
|
1745
|
+
var historyStackItem;
|
|
1746
|
+
if (this.stackItem) {
|
|
1747
|
+
historyStackItem = this.stackItem;
|
|
1748
|
+
this.stackItem = null;
|
|
795
1749
|
} else {
|
|
796
|
-
|
|
797
|
-
|
|
1750
|
+
this.index--;
|
|
1751
|
+
historyStackItem = this.actionStack[this.index];
|
|
1752
|
+
}
|
|
1753
|
+
var len = historyStackItem.undoManagers.length;
|
|
1754
|
+
while(len > 0){
|
|
1755
|
+
len--;
|
|
1756
|
+
historyStackItem.undoManagers[len].undo();
|
|
1757
|
+
}
|
|
1758
|
+
if (historyStackItem) {
|
|
1759
|
+
var beforePosition = historyStackItem.before;
|
|
1760
|
+
this.collaborate.restoreCursorPosition(beforePosition);
|
|
1761
|
+
this.backEvent.next();
|
|
1762
|
+
this.changeEvent.next();
|
|
798
1763
|
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
1764
|
+
}
|
|
1765
|
+
},
|
|
1766
|
+
{
|
|
1767
|
+
key: "clear",
|
|
1768
|
+
value: function clear() {
|
|
1769
|
+
this.actionStack = [];
|
|
1770
|
+
this.stackItem = null;
|
|
1771
|
+
this.index = 0;
|
|
1772
|
+
this.beforePosition = null;
|
|
1773
|
+
clearTimeout(this.timer);
|
|
1774
|
+
this.listenerCaches.forEach(function(undoManager) {
|
|
1775
|
+
undoManager.clear();
|
|
1776
|
+
});
|
|
1777
|
+
this.changeEvent.next();
|
|
1778
|
+
}
|
|
1779
|
+
},
|
|
1780
|
+
{
|
|
1781
|
+
key: "destroy",
|
|
1782
|
+
value: function destroy() {
|
|
1783
|
+
this.clear();
|
|
1784
|
+
this.beforePosition = this.stackItem = null;
|
|
1785
|
+
this.subscription.unsubscribe();
|
|
1786
|
+
this.listenerCaches.forEach(function(undoManager) {
|
|
1787
|
+
undoManager.destroy();
|
|
1788
|
+
});
|
|
1789
|
+
this.subDocs.clear();
|
|
1790
|
+
this.listenerCaches.clear();
|
|
1791
|
+
}
|
|
1792
|
+
},
|
|
1793
|
+
{
|
|
1794
|
+
key: "listenItem",
|
|
1795
|
+
value: function listenItem(yType, yDoc) {
|
|
1796
|
+
var _this = this;
|
|
1797
|
+
var undoManagerConfig = this.undoManagerConfig || {};
|
|
1798
|
+
var undoManager = new UndoManager(yType, {
|
|
1799
|
+
trackedOrigins: new Set([
|
|
1800
|
+
yDoc
|
|
1801
|
+
]),
|
|
1802
|
+
captureTimeout: 0,
|
|
1803
|
+
captureTransaction: function captureTransaction(arg) {
|
|
1804
|
+
if (undoManagerConfig.captureTransaction) {
|
|
1805
|
+
return undoManagerConfig.captureTransaction(arg);
|
|
1806
|
+
}
|
|
1807
|
+
return true;
|
|
1808
|
+
},
|
|
1809
|
+
deleteFilter: function deleteFilter(item) {
|
|
1810
|
+
if (undoManagerConfig.deleteFilter) {
|
|
1811
|
+
return undoManagerConfig.deleteFilter(item);
|
|
1812
|
+
}
|
|
1813
|
+
return true;
|
|
1814
|
+
}
|
|
1815
|
+
});
|
|
1816
|
+
undoManager.on('stack-item-added', function(event) {
|
|
1817
|
+
if (event.type === 'undo' && !_instanceof(event.origin, UndoManager)) {
|
|
1818
|
+
if (_this.index != _this.actionStack.length) {
|
|
1819
|
+
var redoStack = _this.actionStack.slice(_this.index);
|
|
1820
|
+
redoStack.forEach(function(item) {
|
|
1821
|
+
item.undoManagers.forEach(function(i) {
|
|
1822
|
+
i.clear(false, true);
|
|
1823
|
+
});
|
|
1824
|
+
});
|
|
1825
|
+
_this.actionStack.length = _this.index;
|
|
1826
|
+
_this.changeEvent.next();
|
|
1827
|
+
}
|
|
1828
|
+
if (_this.stackItem === null) {
|
|
1829
|
+
_this.stackItem = {
|
|
1830
|
+
before: _this.beforePosition,
|
|
1831
|
+
after: null,
|
|
1832
|
+
undoManagers: []
|
|
1833
|
+
};
|
|
1834
|
+
_this.timer = setTimeout(function() {
|
|
1835
|
+
if (_this.actionStack.length >= _this.stackSize) {
|
|
1836
|
+
_this.actionStack.shift();
|
|
1837
|
+
} else {
|
|
1838
|
+
_this.index++;
|
|
1839
|
+
}
|
|
1840
|
+
// this.beforePosition = this.collaborate.getRelativeCursorLocation()
|
|
1841
|
+
_this.stackItem.after = _this.beforePosition;
|
|
1842
|
+
_this.actionStack.push(_this.stackItem);
|
|
1843
|
+
_this.stackItem = null;
|
|
1844
|
+
_this.pushEvent.next();
|
|
1845
|
+
_this.changeEvent.next();
|
|
1846
|
+
}, 500);
|
|
1847
|
+
}
|
|
1848
|
+
_this.stackItem.undoManagers.push(undoManager);
|
|
1849
|
+
}
|
|
1850
|
+
});
|
|
1851
|
+
this.listenerCaches.add(undoManager);
|
|
1852
|
+
}
|
|
821
1853
|
}
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
1854
|
+
]);
|
|
1855
|
+
return MultipleDocCollabHistory;
|
|
1856
|
+
}();
|
|
1857
|
+
MultipleDocCollabHistory = _ts_decorate([
|
|
1858
|
+
Injectable(),
|
|
1859
|
+
_ts_param(3, Inject(HISTORY_STACK_SIZE)),
|
|
1860
|
+
_ts_param(4, Optional()),
|
|
1861
|
+
_ts_metadata("design:type", Function),
|
|
1862
|
+
_ts_metadata("design:paramtypes", [
|
|
1863
|
+
typeof Collaborate === "undefined" ? Object : Collaborate,
|
|
1864
|
+
typeof Scheduler === "undefined" ? Object : Scheduler,
|
|
1865
|
+
typeof RootComponentRef === "undefined" ? Object : RootComponentRef,
|
|
1866
|
+
Number,
|
|
1867
|
+
typeof CustomUndoManagerConfig === "undefined" ? Object : CustomUndoManagerConfig
|
|
1868
|
+
])
|
|
1869
|
+
], MultipleDocCollabHistory);
|
|
1870
|
+
|
|
1871
|
+
function _class_call_check$4(instance, Constructor) {
|
|
1872
|
+
if (!(instance instanceof Constructor)) {
|
|
1873
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
function _define_property$4(obj, key, value) {
|
|
1877
|
+
if (key in obj) {
|
|
1878
|
+
Object.defineProperty(obj, key, {
|
|
1879
|
+
value: value,
|
|
1880
|
+
enumerable: true,
|
|
1881
|
+
configurable: true,
|
|
1882
|
+
writable: true
|
|
839
1883
|
});
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
*
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
1884
|
+
} else {
|
|
1885
|
+
obj[key] = value;
|
|
1886
|
+
}
|
|
1887
|
+
return obj;
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* 协作通信通用接口
|
|
1891
|
+
*/ var SyncConnector = function SyncConnector() {
|
|
1892
|
+
_class_call_check$4(this, SyncConnector);
|
|
1893
|
+
/**
|
|
1894
|
+
* 当文档加载完成时触发的观察者
|
|
1895
|
+
*/ _define_property$4(this, "onLoad", void 0);
|
|
1896
|
+
/**
|
|
1897
|
+
* 当文档 awareness 状态变更时触发的观察者
|
|
1898
|
+
*/ _define_property$4(this, "onStateChange", void 0);
|
|
1899
|
+
_define_property$4(this, "loadEvent", new Subject());
|
|
1900
|
+
_define_property$4(this, "stateChangeEvent", new Subject());
|
|
1901
|
+
this.onLoad = this.loadEvent.asObservable();
|
|
1902
|
+
this.onStateChange = this.stateChangeEvent.asObservable();
|
|
1903
|
+
};
|
|
1904
|
+
|
|
1905
|
+
function _assert_this_initialized$1(self) {
|
|
1906
|
+
if (self === void 0) {
|
|
1907
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
1908
|
+
}
|
|
1909
|
+
return self;
|
|
1910
|
+
}
|
|
1911
|
+
function _call_super$1(_this, derived, args) {
|
|
1912
|
+
derived = _get_prototype_of$1(derived);
|
|
1913
|
+
return _possible_constructor_return$1(_this, _is_native_reflect_construct$1() ? Reflect.construct(derived, [], _get_prototype_of$1(_this).constructor) : derived.apply(_this, args));
|
|
1914
|
+
}
|
|
1915
|
+
function _class_call_check$3(instance, Constructor) {
|
|
1916
|
+
if (!(instance instanceof Constructor)) {
|
|
1917
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
function _defineProperties$3(target, props) {
|
|
1921
|
+
for(var i = 0; i < props.length; i++){
|
|
1922
|
+
var descriptor = props[i];
|
|
1923
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
1924
|
+
descriptor.configurable = true;
|
|
1925
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
1926
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
function _create_class$3(Constructor, protoProps, staticProps) {
|
|
1930
|
+
if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
|
|
1931
|
+
return Constructor;
|
|
1932
|
+
}
|
|
1933
|
+
function _define_property$3(obj, key, value) {
|
|
1934
|
+
if (key in obj) {
|
|
1935
|
+
Object.defineProperty(obj, key, {
|
|
1936
|
+
value: value,
|
|
1937
|
+
enumerable: true,
|
|
1938
|
+
configurable: true,
|
|
1939
|
+
writable: true
|
|
864
1940
|
});
|
|
865
|
-
|
|
1941
|
+
} else {
|
|
1942
|
+
obj[key] = value;
|
|
1943
|
+
}
|
|
1944
|
+
return obj;
|
|
1945
|
+
}
|
|
1946
|
+
function _get_prototype_of$1(o) {
|
|
1947
|
+
_get_prototype_of$1 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
1948
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
866
1949
|
};
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
break;
|
|
881
|
-
case "propDelete":
|
|
882
|
-
sharedObject.delete(action.key);
|
|
883
|
-
break;
|
|
884
|
-
}
|
|
1950
|
+
return _get_prototype_of$1(o);
|
|
1951
|
+
}
|
|
1952
|
+
function _inherits$1(subClass, superClass) {
|
|
1953
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
1954
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
1955
|
+
}
|
|
1956
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
1957
|
+
constructor: {
|
|
1958
|
+
value: subClass,
|
|
1959
|
+
writable: true,
|
|
1960
|
+
configurable: true
|
|
885
1961
|
}
|
|
886
|
-
});
|
|
887
|
-
});
|
|
888
|
-
localObject.__changeMarker__.addDetachCallback(function() {
|
|
889
|
-
sharedObject.unobserve(syncRemote);
|
|
890
|
-
sub.unsubscribe();
|
|
891
1962
|
});
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
1963
|
+
if (superClass) _set_prototype_of$1(subClass, superClass);
|
|
1964
|
+
}
|
|
1965
|
+
function _object_spread(target) {
|
|
1966
|
+
for(var i = 1; i < arguments.length; i++){
|
|
1967
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
1968
|
+
var ownKeys = Object.keys(source);
|
|
1969
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
1970
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
1971
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
1972
|
+
}));
|
|
1973
|
+
}
|
|
1974
|
+
ownKeys.forEach(function(key) {
|
|
1975
|
+
_define_property$3(target, key, source[key]);
|
|
1976
|
+
});
|
|
901
1977
|
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
return;
|
|
1978
|
+
return target;
|
|
1979
|
+
}
|
|
1980
|
+
function ownKeys(object, enumerableOnly) {
|
|
1981
|
+
var keys = Object.keys(object);
|
|
1982
|
+
if (Object.getOwnPropertySymbols) {
|
|
1983
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
1984
|
+
keys.push.apply(keys, symbols);
|
|
910
1985
|
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
1986
|
+
return keys;
|
|
1987
|
+
}
|
|
1988
|
+
function _object_spread_props(target, source) {
|
|
1989
|
+
source = source != null ? source : {};
|
|
1990
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
1991
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
914
1992
|
} else {
|
|
915
|
-
|
|
1993
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
1994
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
1995
|
+
});
|
|
916
1996
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
Object.
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
var
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
}
|
|
984
|
-
isListen = false;
|
|
985
|
-
changeEvent = new Subject();
|
|
986
|
-
backEvent = new Subject();
|
|
987
|
-
forwardEvent = new Subject();
|
|
988
|
-
pushEvent = new Subject();
|
|
989
|
-
actionStack = [];
|
|
990
|
-
index = 0;
|
|
991
|
-
stackItem = null;
|
|
992
|
-
timer = null;
|
|
993
|
-
beforePosition = null;
|
|
994
|
-
subscription = new Subscription();
|
|
995
|
-
subDocs = /* @__PURE__ */ new Set();
|
|
996
|
-
listenerCaches = /* @__PURE__ */ new Set();
|
|
997
|
-
listen() {
|
|
998
|
-
this.isListen = true;
|
|
999
|
-
const root = this.collaborate.yDoc.getMap("RootComponent");
|
|
1000
|
-
const rootComponent = this.rootComponentRef.component;
|
|
1001
|
-
this.collaborate.syncRootComponent(this.collaborate.yDoc, root, rootComponent);
|
|
1002
|
-
this.listenItem(root, this.collaborate.yDoc);
|
|
1003
|
-
this.subscription.add(
|
|
1004
|
-
this.collaborate.onAddSubModel.subscribe(({ yType, yDoc }) => {
|
|
1005
|
-
if (this.subDocs.has(yType)) {
|
|
1006
|
-
return;
|
|
1007
|
-
}
|
|
1008
|
-
this.subDocs.add(yType);
|
|
1009
|
-
if (this.isListen) {
|
|
1010
|
-
this.listenItem(yType, yDoc);
|
|
1997
|
+
return target;
|
|
1998
|
+
}
|
|
1999
|
+
function _possible_constructor_return$1(self, call) {
|
|
2000
|
+
if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
|
|
2001
|
+
return call;
|
|
2002
|
+
}
|
|
2003
|
+
return _assert_this_initialized$1(self);
|
|
2004
|
+
}
|
|
2005
|
+
function _set_prototype_of$1(o, p) {
|
|
2006
|
+
_set_prototype_of$1 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
2007
|
+
o.__proto__ = p;
|
|
2008
|
+
return o;
|
|
2009
|
+
};
|
|
2010
|
+
return _set_prototype_of$1(o, p);
|
|
2011
|
+
}
|
|
2012
|
+
function _type_of$1(obj) {
|
|
2013
|
+
"@swc/helpers - typeof";
|
|
2014
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
2015
|
+
}
|
|
2016
|
+
function _is_native_reflect_construct$1() {
|
|
2017
|
+
try {
|
|
2018
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
2019
|
+
} catch (_) {}
|
|
2020
|
+
return (_is_native_reflect_construct$1 = function() {
|
|
2021
|
+
return !!result;
|
|
2022
|
+
})();
|
|
2023
|
+
}
|
|
2024
|
+
var HocuspocusConnector = /*#__PURE__*/ function(SyncConnector) {
|
|
2025
|
+
_inherits$1(HocuspocusConnector, SyncConnector);
|
|
2026
|
+
function HocuspocusConnector(config) {
|
|
2027
|
+
_class_call_check$3(this, HocuspocusConnector);
|
|
2028
|
+
var _this;
|
|
2029
|
+
_this = _call_super$1(this, HocuspocusConnector), _define_property$3(_this, "provide", void 0);
|
|
2030
|
+
_this.provide = new HocuspocusProvider(_object_spread_props(_object_spread({}, config), {
|
|
2031
|
+
onSynced: function onSynced(data) {
|
|
2032
|
+
var _config_onSynced;
|
|
2033
|
+
(_config_onSynced = config.onSynced) === null || _config_onSynced === void 0 ? void 0 : _config_onSynced.call(config, data);
|
|
2034
|
+
_this.loadEvent.next();
|
|
2035
|
+
},
|
|
2036
|
+
onAwarenessUpdate: function onAwarenessUpdate(data) {
|
|
2037
|
+
var _config_onAwarenessUpdate;
|
|
2038
|
+
(_config_onAwarenessUpdate = config.onAwarenessUpdate) === null || _config_onAwarenessUpdate === void 0 ? void 0 : _config_onAwarenessUpdate.call(config, data);
|
|
2039
|
+
var states = data.states.map(function(state) {
|
|
2040
|
+
return {
|
|
2041
|
+
clientId: state.clientId,
|
|
2042
|
+
message: state.message
|
|
2043
|
+
};
|
|
2044
|
+
});
|
|
2045
|
+
_this.stateChangeEvent.next(states);
|
|
2046
|
+
}
|
|
2047
|
+
}));
|
|
2048
|
+
return _this;
|
|
2049
|
+
}
|
|
2050
|
+
_create_class$3(HocuspocusConnector, [
|
|
2051
|
+
{
|
|
2052
|
+
key: "setLocalStateField",
|
|
2053
|
+
value: function setLocalStateField(key, data) {
|
|
2054
|
+
this.provide.setAwarenessField(key, data);
|
|
2055
|
+
}
|
|
2056
|
+
},
|
|
2057
|
+
{
|
|
2058
|
+
key: "onDestroy",
|
|
2059
|
+
value: function onDestroy() {
|
|
2060
|
+
this.provide.disconnect();
|
|
2061
|
+
this.provide.destroy();
|
|
2062
|
+
}
|
|
1011
2063
|
}
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
if (!this.canForward) {
|
|
1020
|
-
return;
|
|
2064
|
+
]);
|
|
2065
|
+
return HocuspocusConnector;
|
|
2066
|
+
}(SyncConnector);
|
|
2067
|
+
|
|
2068
|
+
function _assert_this_initialized(self) {
|
|
2069
|
+
if (self === void 0) {
|
|
2070
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
1021
2071
|
}
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
2072
|
+
return self;
|
|
2073
|
+
}
|
|
2074
|
+
function _call_super(_this, derived, args) {
|
|
2075
|
+
derived = _get_prototype_of(derived);
|
|
2076
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
2077
|
+
}
|
|
2078
|
+
function _class_call_check$2(instance, Constructor) {
|
|
2079
|
+
if (!(instance instanceof Constructor)) {
|
|
2080
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1029
2081
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
2082
|
+
}
|
|
2083
|
+
function _defineProperties$2(target, props) {
|
|
2084
|
+
for(var i = 0; i < props.length; i++){
|
|
2085
|
+
var descriptor = props[i];
|
|
2086
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
2087
|
+
descriptor.configurable = true;
|
|
2088
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
2089
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
1037
2090
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
if (
|
|
1041
|
-
|
|
1042
|
-
|
|
2091
|
+
}
|
|
2092
|
+
function _create_class$2(Constructor, protoProps, staticProps) {
|
|
2093
|
+
if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
|
|
2094
|
+
return Constructor;
|
|
2095
|
+
}
|
|
2096
|
+
function _define_property$2(obj, key, value) {
|
|
2097
|
+
if (key in obj) {
|
|
2098
|
+
Object.defineProperty(obj, key, {
|
|
2099
|
+
value: value,
|
|
2100
|
+
enumerable: true,
|
|
2101
|
+
configurable: true,
|
|
2102
|
+
writable: true
|
|
2103
|
+
});
|
|
1043
2104
|
} else {
|
|
1044
|
-
|
|
1045
|
-
historyStackItem = this.actionStack[this.index];
|
|
1046
|
-
}
|
|
1047
|
-
let len = historyStackItem.undoManagers.length;
|
|
1048
|
-
while (len > 0) {
|
|
1049
|
-
len--;
|
|
1050
|
-
historyStackItem.undoManagers[len].undo();
|
|
2105
|
+
obj[key] = value;
|
|
1051
2106
|
}
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
2107
|
+
return obj;
|
|
2108
|
+
}
|
|
2109
|
+
function _get_prototype_of(o) {
|
|
2110
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
2111
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
2112
|
+
};
|
|
2113
|
+
return _get_prototype_of(o);
|
|
2114
|
+
}
|
|
2115
|
+
function _inherits(subClass, superClass) {
|
|
2116
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
2117
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
1057
2118
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
this.beforePosition = null;
|
|
1064
|
-
clearTimeout(this.timer);
|
|
1065
|
-
this.listenerCaches.forEach((undoManager) => {
|
|
1066
|
-
undoManager.clear();
|
|
1067
|
-
});
|
|
1068
|
-
this.changeEvent.next();
|
|
1069
|
-
}
|
|
1070
|
-
destroy() {
|
|
1071
|
-
this.clear();
|
|
1072
|
-
this.beforePosition = this.stackItem = null;
|
|
1073
|
-
this.subscription.unsubscribe();
|
|
1074
|
-
this.listenerCaches.forEach((undoManager) => {
|
|
1075
|
-
undoManager.destroy();
|
|
1076
|
-
});
|
|
1077
|
-
this.subDocs.clear();
|
|
1078
|
-
this.listenerCaches.clear();
|
|
1079
|
-
}
|
|
1080
|
-
listenItem(yType, yDoc) {
|
|
1081
|
-
const undoManagerConfig = this.undoManagerConfig || {};
|
|
1082
|
-
const undoManager = new UndoManager(yType, {
|
|
1083
|
-
trackedOrigins: /* @__PURE__ */ new Set([yDoc]),
|
|
1084
|
-
captureTimeout: 0,
|
|
1085
|
-
captureTransaction(arg) {
|
|
1086
|
-
if (undoManagerConfig.captureTransaction) {
|
|
1087
|
-
return undoManagerConfig.captureTransaction(arg);
|
|
1088
|
-
}
|
|
1089
|
-
return true;
|
|
1090
|
-
},
|
|
1091
|
-
deleteFilter(item) {
|
|
1092
|
-
if (undoManagerConfig.deleteFilter) {
|
|
1093
|
-
return undoManagerConfig.deleteFilter(item);
|
|
2119
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
2120
|
+
constructor: {
|
|
2121
|
+
value: subClass,
|
|
2122
|
+
writable: true,
|
|
2123
|
+
configurable: true
|
|
1094
2124
|
}
|
|
1095
|
-
return true;
|
|
1096
|
-
}
|
|
1097
2125
|
});
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
2126
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
2127
|
+
}
|
|
2128
|
+
function _possible_constructor_return(self, call) {
|
|
2129
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
2130
|
+
return call;
|
|
2131
|
+
}
|
|
2132
|
+
return _assert_this_initialized(self);
|
|
2133
|
+
}
|
|
2134
|
+
function _set_prototype_of(o, p) {
|
|
2135
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
2136
|
+
o.__proto__ = p;
|
|
2137
|
+
return o;
|
|
2138
|
+
};
|
|
2139
|
+
return _set_prototype_of(o, p);
|
|
2140
|
+
}
|
|
2141
|
+
function _type_of(obj) {
|
|
2142
|
+
"@swc/helpers - typeof";
|
|
2143
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
2144
|
+
}
|
|
2145
|
+
function _is_native_reflect_construct() {
|
|
2146
|
+
try {
|
|
2147
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
2148
|
+
} catch (_) {}
|
|
2149
|
+
return (_is_native_reflect_construct = function() {
|
|
2150
|
+
return !!result;
|
|
2151
|
+
})();
|
|
2152
|
+
}
|
|
2153
|
+
var YWebsocketConnector = /*#__PURE__*/ function(SyncConnector) {
|
|
2154
|
+
_inherits(YWebsocketConnector, SyncConnector);
|
|
2155
|
+
function YWebsocketConnector(url, roomName, yDoc) {
|
|
2156
|
+
_class_call_check$2(this, YWebsocketConnector);
|
|
2157
|
+
var _this;
|
|
2158
|
+
_this = _call_super(this, YWebsocketConnector), _define_property$2(_this, "provide", void 0), _define_property$2(_this, "onSync", function(is) {
|
|
2159
|
+
if (is) {
|
|
2160
|
+
_this.loadEvent.next();
|
|
2161
|
+
}
|
|
2162
|
+
}), _define_property$2(_this, "onUpdate", function() {
|
|
2163
|
+
var syncStates = [];
|
|
2164
|
+
_this.provide.awareness.getStates().forEach(function(state, id) {
|
|
2165
|
+
syncStates.push({
|
|
2166
|
+
clientId: id,
|
|
2167
|
+
message: state.message
|
|
2168
|
+
});
|
|
1105
2169
|
});
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
2170
|
+
_this.stateChangeEvent.next(syncStates);
|
|
2171
|
+
});
|
|
2172
|
+
_this.onLoad = _this.loadEvent.asObservable();
|
|
2173
|
+
_this.onStateChange = _this.stateChangeEvent.asObservable();
|
|
2174
|
+
_this.provide = new WebsocketProvider(url, roomName, yDoc);
|
|
2175
|
+
_this.provide.once('sync', _this.onSync);
|
|
2176
|
+
_this.provide.awareness.on('update', _this.onUpdate);
|
|
2177
|
+
return _this;
|
|
2178
|
+
}
|
|
2179
|
+
_create_class$2(YWebsocketConnector, [
|
|
2180
|
+
{
|
|
2181
|
+
key: "setLocalStateField",
|
|
2182
|
+
value: function setLocalStateField(key, data) {
|
|
2183
|
+
this.provide.awareness.setLocalStateField(key, data);
|
|
2184
|
+
}
|
|
2185
|
+
},
|
|
2186
|
+
{
|
|
2187
|
+
key: "onDestroy",
|
|
2188
|
+
value: function onDestroy() {
|
|
2189
|
+
this.provide.awareness.off('update', this.onUpdate);
|
|
2190
|
+
this.provide.disconnect();
|
|
2191
|
+
this.provide.destroy();
|
|
2192
|
+
}
|
|
1128
2193
|
}
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
var
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
loadSubModelByComponent() {
|
|
1159
|
-
throw subModelLoaderErrorFn("single document does not support async component.");
|
|
1160
|
-
}
|
|
1161
|
-
loadSubModelBySlot() {
|
|
1162
|
-
throw subModelLoaderErrorFn("single document does not support async slot.");
|
|
1163
|
-
}
|
|
1164
|
-
getLoadedModelBySlot() {
|
|
1165
|
-
throw subModelLoaderErrorFn("single document does not support async slot.");
|
|
1166
|
-
}
|
|
1167
|
-
getLoadedModelByComponent() {
|
|
1168
|
-
throw subModelLoaderErrorFn("single document does not support async component.");
|
|
1169
|
-
}
|
|
1170
|
-
};
|
|
1171
|
-
NonSubModelLoader = __decorateClass([
|
|
1172
|
-
Injectable()
|
|
1173
|
-
], NonSubModelLoader);
|
|
1174
|
-
class SyncConnector {
|
|
1175
|
-
/**
|
|
1176
|
-
* 当文档加载完成时触发的观察者
|
|
1177
|
-
*/
|
|
1178
|
-
onLoad;
|
|
1179
|
-
/**
|
|
1180
|
-
* 当文档 awareness 状态变更时触发的观察者
|
|
1181
|
-
*/
|
|
1182
|
-
onStateChange;
|
|
1183
|
-
loadEvent = new Subject();
|
|
1184
|
-
stateChangeEvent = new Subject();
|
|
1185
|
-
constructor() {
|
|
1186
|
-
this.onLoad = this.loadEvent.asObservable();
|
|
1187
|
-
this.onStateChange = this.stateChangeEvent.asObservable();
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
class HocuspocusConnector extends SyncConnector {
|
|
1191
|
-
provide;
|
|
1192
|
-
constructor(config) {
|
|
1193
|
-
super();
|
|
1194
|
-
this.provide = new HocuspocusProvider({
|
|
1195
|
-
...config,
|
|
1196
|
-
onSynced: (data) => {
|
|
1197
|
-
config.onSynced?.(data);
|
|
1198
|
-
this.loadEvent.next();
|
|
1199
|
-
},
|
|
1200
|
-
onAwarenessUpdate: (data) => {
|
|
1201
|
-
config.onAwarenessUpdate?.(data);
|
|
1202
|
-
const states = data.states.map((state) => {
|
|
1203
|
-
return {
|
|
1204
|
-
clientId: state.clientId,
|
|
1205
|
-
message: state.message
|
|
1206
|
-
};
|
|
2194
|
+
]);
|
|
2195
|
+
return YWebsocketConnector;
|
|
2196
|
+
}(SyncConnector);
|
|
2197
|
+
|
|
2198
|
+
function _class_call_check$1(instance, Constructor) {
|
|
2199
|
+
if (!(instance instanceof Constructor)) {
|
|
2200
|
+
throw new TypeError("Cannot call a class as a function");
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
function _defineProperties$1(target, props) {
|
|
2204
|
+
for(var i = 0; i < props.length; i++){
|
|
2205
|
+
var descriptor = props[i];
|
|
2206
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
2207
|
+
descriptor.configurable = true;
|
|
2208
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
2209
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
function _create_class$1(Constructor, protoProps, staticProps) {
|
|
2213
|
+
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
|
|
2214
|
+
return Constructor;
|
|
2215
|
+
}
|
|
2216
|
+
function _define_property$1(obj, key, value) {
|
|
2217
|
+
if (key in obj) {
|
|
2218
|
+
Object.defineProperty(obj, key, {
|
|
2219
|
+
value: value,
|
|
2220
|
+
enumerable: true,
|
|
2221
|
+
configurable: true,
|
|
2222
|
+
writable: true
|
|
1207
2223
|
});
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
});
|
|
1211
|
-
}
|
|
1212
|
-
setLocalStateField(key, data) {
|
|
1213
|
-
this.provide.setAwarenessField(key, data);
|
|
1214
|
-
}
|
|
1215
|
-
onDestroy() {
|
|
1216
|
-
this.provide.disconnect();
|
|
1217
|
-
this.provide.destroy();
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
class YWebsocketConnector extends SyncConnector {
|
|
1221
|
-
provide;
|
|
1222
|
-
onSync = (is) => {
|
|
1223
|
-
if (is) {
|
|
1224
|
-
this.loadEvent.next();
|
|
2224
|
+
} else {
|
|
2225
|
+
obj[key] = value;
|
|
1225
2226
|
}
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
providers = [
|
|
1261
|
-
Collaborate,
|
|
1262
|
-
CollabHistory,
|
|
1263
|
-
{
|
|
1264
|
-
provide: History,
|
|
1265
|
-
useExisting: CollabHistory
|
|
1266
|
-
},
|
|
1267
|
-
{
|
|
1268
|
-
provide: SyncConnector,
|
|
1269
|
-
useFactory: (collab) => {
|
|
1270
|
-
return this.config.createConnector(collab.yDoc);
|
|
1271
|
-
},
|
|
1272
|
-
deps: [Collaborate]
|
|
1273
|
-
},
|
|
1274
|
-
{
|
|
1275
|
-
provide: SubModelLoader,
|
|
1276
|
-
useClass: NonSubModelLoader
|
|
2227
|
+
return obj;
|
|
2228
|
+
}
|
|
2229
|
+
var CollaborateModule = /*#__PURE__*/ function() {
|
|
2230
|
+
function CollaborateModule(config) {
|
|
2231
|
+
var _this = this;
|
|
2232
|
+
_class_call_check$1(this, CollaborateModule);
|
|
2233
|
+
_define_property$1(this, "config", void 0);
|
|
2234
|
+
_define_property$1(this, "subscription", void 0);
|
|
2235
|
+
_define_property$1(this, "providers", void 0);
|
|
2236
|
+
_define_property$1(this, "timer", void 0);
|
|
2237
|
+
this.config = config;
|
|
2238
|
+
this.subscription = new Subscription();
|
|
2239
|
+
this.providers = [
|
|
2240
|
+
Collaborate,
|
|
2241
|
+
CollabHistory,
|
|
2242
|
+
{
|
|
2243
|
+
provide: History,
|
|
2244
|
+
useExisting: CollabHistory
|
|
2245
|
+
},
|
|
2246
|
+
{
|
|
2247
|
+
provide: SyncConnector,
|
|
2248
|
+
useFactory: function useFactory(collab) {
|
|
2249
|
+
return _this.config.createConnector(collab.yDoc);
|
|
2250
|
+
},
|
|
2251
|
+
deps: [
|
|
2252
|
+
Collaborate
|
|
2253
|
+
]
|
|
2254
|
+
},
|
|
2255
|
+
{
|
|
2256
|
+
provide: SubModelLoader,
|
|
2257
|
+
useClass: NonSubModelLoader
|
|
2258
|
+
}
|
|
2259
|
+
];
|
|
2260
|
+
this.timer = null;
|
|
1277
2261
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
2262
|
+
_create_class$1(CollaborateModule, [
|
|
2263
|
+
{
|
|
2264
|
+
key: "setup",
|
|
2265
|
+
value: function setup(textbus) {
|
|
2266
|
+
var _this = this;
|
|
2267
|
+
var messageBus = textbus.get(MessageBus, null);
|
|
2268
|
+
var connector = textbus.get(SyncConnector);
|
|
2269
|
+
var collab = textbus.get(Collaborate);
|
|
2270
|
+
if (messageBus) {
|
|
2271
|
+
var selection = textbus.get(Selection);
|
|
2272
|
+
connector.setLocalStateField('message', messageBus.get(textbus));
|
|
2273
|
+
this.subscription.add(messageBus.onSync.subscribe(function() {
|
|
2274
|
+
connector.setLocalStateField('message', messageBus.get(textbus));
|
|
2275
|
+
}), selection.onChange.subscribe(function() {
|
|
2276
|
+
connector.setLocalStateField('message', messageBus.get(textbus));
|
|
2277
|
+
}), connector.onStateChange.subscribe(function(states) {
|
|
2278
|
+
messageBus.consume(states, textbus);
|
|
2279
|
+
}));
|
|
2280
|
+
}
|
|
2281
|
+
return connector.onLoad.toPromise().then(function() {
|
|
2282
|
+
if (!_this.config.onlyLoad) {
|
|
2283
|
+
return;
|
|
2284
|
+
}
|
|
2285
|
+
var root = collab.yDoc.getMap('RootComponent');
|
|
2286
|
+
if (root.has('state')) {
|
|
2287
|
+
return;
|
|
2288
|
+
}
|
|
2289
|
+
return new Promise(function(resolve) {
|
|
2290
|
+
var testing = function testing1() {
|
|
2291
|
+
if (root.has('state')) {
|
|
2292
|
+
resolve();
|
|
2293
|
+
} else {
|
|
2294
|
+
_this.timer = setTimeout(testing, 1000);
|
|
2295
|
+
}
|
|
2296
|
+
};
|
|
2297
|
+
_this.timer = setTimeout(testing, 1000);
|
|
2298
|
+
});
|
|
2299
|
+
});
|
|
2300
|
+
}
|
|
2301
|
+
},
|
|
2302
|
+
{
|
|
2303
|
+
key: "onDestroy",
|
|
2304
|
+
value: function onDestroy(textbus) {
|
|
2305
|
+
this.subscription.unsubscribe();
|
|
2306
|
+
textbus.get(Collaborate).destroy();
|
|
2307
|
+
textbus.get(History).destroy();
|
|
2308
|
+
textbus.get(SyncConnector).onDestroy();
|
|
2309
|
+
clearTimeout(this.timer);
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
]);
|
|
2313
|
+
return CollaborateModule;
|
|
2314
|
+
}();
|
|
2315
|
+
|
|
2316
|
+
function _class_call_check(instance, Constructor) {
|
|
2317
|
+
if (!(instance instanceof Constructor)) {
|
|
2318
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1298
2319
|
}
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
return new Promise((resolve) => {
|
|
1308
|
-
const testing = () => {
|
|
1309
|
-
if (root.has("state")) {
|
|
1310
|
-
resolve();
|
|
1311
|
-
} else {
|
|
1312
|
-
this.timer = setTimeout(testing, 1e3);
|
|
1313
|
-
}
|
|
1314
|
-
};
|
|
1315
|
-
this.timer = setTimeout(testing, 1e3);
|
|
1316
|
-
});
|
|
1317
|
-
});
|
|
1318
|
-
}
|
|
1319
|
-
onDestroy(textbus) {
|
|
1320
|
-
this.subscription.unsubscribe();
|
|
1321
|
-
textbus.get(Collaborate).destroy();
|
|
1322
|
-
textbus.get(History).destroy();
|
|
1323
|
-
textbus.get(SyncConnector).onDestroy();
|
|
1324
|
-
clearTimeout(this.timer);
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
class MultipleDocumentCollaborateModule {
|
|
1328
|
-
constructor(config) {
|
|
1329
|
-
this.config = config;
|
|
1330
|
-
}
|
|
1331
|
-
config;
|
|
1332
|
-
subscription = new Subscription();
|
|
1333
|
-
providers = [
|
|
1334
|
-
Collaborate,
|
|
1335
|
-
MultipleDocCollabHistory,
|
|
1336
|
-
{
|
|
1337
|
-
provide: History,
|
|
1338
|
-
useExisting: MultipleDocCollabHistory
|
|
1339
|
-
},
|
|
1340
|
-
{
|
|
1341
|
-
provide: SyncConnector,
|
|
1342
|
-
useFactory: (collab) => {
|
|
1343
|
-
return this.config.createConnector(collab.yDoc);
|
|
1344
|
-
},
|
|
1345
|
-
deps: [Collaborate]
|
|
1346
|
-
},
|
|
1347
|
-
{
|
|
1348
|
-
provide: SubModelLoader,
|
|
1349
|
-
useFactory: () => {
|
|
1350
|
-
return this.config.subModelLoader;
|
|
1351
|
-
}
|
|
2320
|
+
}
|
|
2321
|
+
function _defineProperties(target, props) {
|
|
2322
|
+
for(var i = 0; i < props.length; i++){
|
|
2323
|
+
var descriptor = props[i];
|
|
2324
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
2325
|
+
descriptor.configurable = true;
|
|
2326
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
2327
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
1352
2328
|
}
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
if (
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
})
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
}),
|
|
1369
|
-
connector.onStateChange.subscribe((states) => {
|
|
1370
|
-
messageBus.consume(states, textbus);
|
|
1371
|
-
})
|
|
1372
|
-
);
|
|
2329
|
+
}
|
|
2330
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
2331
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
2332
|
+
return Constructor;
|
|
2333
|
+
}
|
|
2334
|
+
function _define_property(obj, key, value) {
|
|
2335
|
+
if (key in obj) {
|
|
2336
|
+
Object.defineProperty(obj, key, {
|
|
2337
|
+
value: value,
|
|
2338
|
+
enumerable: true,
|
|
2339
|
+
configurable: true,
|
|
2340
|
+
writable: true
|
|
2341
|
+
});
|
|
2342
|
+
} else {
|
|
2343
|
+
obj[key] = value;
|
|
1373
2344
|
}
|
|
1374
|
-
return
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
2345
|
+
return obj;
|
|
2346
|
+
}
|
|
2347
|
+
var MultipleDocumentCollaborateModule = /*#__PURE__*/ function() {
|
|
2348
|
+
function MultipleDocumentCollaborateModule(config) {
|
|
2349
|
+
var _this = this;
|
|
2350
|
+
_class_call_check(this, MultipleDocumentCollaborateModule);
|
|
2351
|
+
_define_property(this, "config", void 0);
|
|
2352
|
+
_define_property(this, "subscription", void 0);
|
|
2353
|
+
_define_property(this, "providers", void 0);
|
|
2354
|
+
_define_property(this, "timer", void 0);
|
|
2355
|
+
this.config = config;
|
|
2356
|
+
this.subscription = new Subscription();
|
|
2357
|
+
this.providers = [
|
|
2358
|
+
Collaborate,
|
|
2359
|
+
MultipleDocCollabHistory,
|
|
2360
|
+
{
|
|
2361
|
+
provide: History,
|
|
2362
|
+
useExisting: MultipleDocCollabHistory
|
|
2363
|
+
},
|
|
2364
|
+
{
|
|
2365
|
+
provide: SyncConnector,
|
|
2366
|
+
useFactory: function useFactory(collab) {
|
|
2367
|
+
return _this.config.createConnector(collab.yDoc);
|
|
2368
|
+
},
|
|
2369
|
+
deps: [
|
|
2370
|
+
Collaborate
|
|
2371
|
+
]
|
|
2372
|
+
},
|
|
2373
|
+
{
|
|
2374
|
+
provide: SubModelLoader,
|
|
2375
|
+
useFactory: function useFactory() {
|
|
2376
|
+
return _this.config.subModelLoader;
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
];
|
|
2380
|
+
this.timer = null;
|
|
2381
|
+
}
|
|
2382
|
+
_create_class(MultipleDocumentCollaborateModule, [
|
|
2383
|
+
{
|
|
2384
|
+
key: "setup",
|
|
2385
|
+
value: function setup(textbus) {
|
|
2386
|
+
var _this = this;
|
|
2387
|
+
var messageBus = textbus.get(MessageBus, null);
|
|
2388
|
+
var connector = textbus.get(SyncConnector);
|
|
2389
|
+
var collab = textbus.get(Collaborate);
|
|
2390
|
+
if (messageBus) {
|
|
2391
|
+
var selection = textbus.get(Selection);
|
|
2392
|
+
connector.setLocalStateField('message', messageBus.get(textbus));
|
|
2393
|
+
this.subscription.add(messageBus.onSync.subscribe(function() {
|
|
2394
|
+
connector.setLocalStateField('message', messageBus.get(textbus));
|
|
2395
|
+
}), selection.onChange.subscribe(function() {
|
|
2396
|
+
connector.setLocalStateField('message', messageBus.get(textbus));
|
|
2397
|
+
}), connector.onStateChange.subscribe(function(states) {
|
|
2398
|
+
messageBus.consume(states, textbus);
|
|
2399
|
+
}));
|
|
2400
|
+
}
|
|
2401
|
+
return connector.onLoad.toPromise().then(function() {
|
|
2402
|
+
if (!_this.config.onlyLoad) {
|
|
2403
|
+
return;
|
|
2404
|
+
}
|
|
2405
|
+
var root = collab.yDoc.getMap('RootComponent');
|
|
2406
|
+
if (root.has('state')) {
|
|
2407
|
+
return;
|
|
2408
|
+
}
|
|
2409
|
+
return new Promise(function(resolve) {
|
|
2410
|
+
var testing = function testing1() {
|
|
2411
|
+
if (root.has('state')) {
|
|
2412
|
+
resolve();
|
|
2413
|
+
} else {
|
|
2414
|
+
_this.timer = setTimeout(testing, 1000);
|
|
2415
|
+
}
|
|
2416
|
+
};
|
|
2417
|
+
_this.timer = setTimeout(testing, 1000);
|
|
2418
|
+
});
|
|
2419
|
+
});
|
|
2420
|
+
}
|
|
2421
|
+
},
|
|
2422
|
+
{
|
|
2423
|
+
key: "onDestroy",
|
|
2424
|
+
value: function onDestroy(textbus) {
|
|
2425
|
+
this.subscription.unsubscribe();
|
|
2426
|
+
textbus.get(Collaborate).destroy();
|
|
2427
|
+
textbus.get(History).destroy();
|
|
2428
|
+
textbus.get(SyncConnector).onDestroy();
|
|
2429
|
+
clearTimeout(this.timer);
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
]);
|
|
2433
|
+
return MultipleDocumentCollaborateModule;
|
|
2434
|
+
}();
|
|
2435
|
+
|
|
2436
|
+
export { CollabHistory, Collaborate, CollaborateModule, CustomUndoManagerConfig, HocuspocusConnector, MessageBus, MultipleDocCollabHistory, MultipleDocumentCollaborateModule, NonSubModelLoader, SubModelLoader, SyncConnector, YWebsocketConnector };
|
|
1416
2437
|
//# sourceMappingURL=index.esm.js.map
|