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