@textbus/collaborate 2.0.0-alpha.38 → 2.0.0-alpha.39
Sign up to get free protection for your applications and to get access to all the features.
- package/bundles/collab/_api.d.ts +0 -1
- package/bundles/collab/_api.js +0 -1
- package/bundles/collab/_api.js.map +1 -1
- package/bundles/collab/collaborate-cursor.js +51 -16
- package/bundles/collab/collaborate-cursor.js.map +1 -1
- package/bundles/collab/local-to-remote.d.ts +10 -2
- package/bundles/collab/local-to-remote.js +136 -157
- package/bundles/collab/local-to-remote.js.map +1 -1
- package/bundles/collab/remote-to-local.d.ts +10 -1
- package/bundles/collab/remote-to-local.js +132 -117
- package/bundles/collab/remote-to-local.js.map +1 -1
- package/bundles/collaborate.d.ts +22 -6
- package/bundles/collaborate.js +180 -24
- package/bundles/collaborate.js.map +1 -1
- package/bundles/public-api.js.map +1 -1
- package/package.json +4 -4
- package/src/collab/_api.ts +0 -1
- package/src/collab/local-to-remote.ts +133 -159
- package/src/collab/remote-to-local.ts +125 -114
- package/src/collaborate.ts +60 -14
- package/tsconfig-build.json +2 -0
- package/bundles/collab/collaborate-history.d.ts +0 -22
- package/bundles/collab/collaborate-history.js +0 -53
- package/bundles/collab/collaborate-history.js.map +0 -1
- package/src/collab/collaborate-history.ts +0 -55
@@ -1,143 +1,158 @@
|
|
1
|
-
import { YArrayEvent, YMapEvent } from 'yjs';
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
if (path.length) {
|
10
|
-
const componentIndex = path.shift()[0];
|
11
|
-
const component = slot.getContentAtIndex(componentIndex);
|
12
|
-
applySharedComponentToComponent(ev, path, component, translator, registry);
|
13
|
-
return;
|
14
|
-
}
|
15
|
-
apply(ev, slot, translator);
|
16
|
-
});
|
17
|
-
}
|
18
|
-
function applySharedComponentToComponent(ev, path, component, translator, registry) {
|
19
|
-
if (path.length) {
|
20
|
-
const childPath = path.shift();
|
21
|
-
const slot = component.slots.get(childPath[0]);
|
22
|
-
applySharedSlotToSlot(ev, path, slot, translator, registry, childPath[1] === 'formats');
|
23
|
-
return;
|
24
|
-
}
|
25
|
-
if (ev instanceof YMapEvent) {
|
26
|
-
ev.keysChanged.forEach(key => {
|
27
|
-
if (key === 'state') {
|
28
|
-
const state = ev.target.get('state');
|
29
|
-
component.updateState(draft => {
|
30
|
-
Object.assign(draft, state);
|
31
|
-
});
|
32
|
-
}
|
1
|
+
import { YArrayEvent, YMapEvent, YTextEvent } from 'yjs';
|
2
|
+
export class RemoteToLocal {
|
3
|
+
constructor(translator, registry) {
|
4
|
+
Object.defineProperty(this, "translator", {
|
5
|
+
enumerable: true,
|
6
|
+
configurable: true,
|
7
|
+
writable: true,
|
8
|
+
value: translator
|
33
9
|
});
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
slots.retain(action.retain);
|
40
|
-
}
|
41
|
-
else if (action.insert) {
|
42
|
-
action.insert.forEach(item => {
|
43
|
-
slots.insert(translator.createSlot(item.toJSON()));
|
44
|
-
});
|
45
|
-
}
|
46
|
-
else if (action.delete) {
|
47
|
-
slots.retain(slots.index);
|
48
|
-
slots.delete(action.delete);
|
49
|
-
}
|
10
|
+
Object.defineProperty(this, "registry", {
|
11
|
+
enumerable: true,
|
12
|
+
configurable: true,
|
13
|
+
writable: true,
|
14
|
+
value: registry
|
50
15
|
});
|
51
16
|
}
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
applySharedComponentToComponent(ev, path, component, translator, registry);
|
58
|
-
return;
|
59
|
-
}
|
60
|
-
if (ev instanceof YArrayEvent) {
|
61
|
-
ev.delta.forEach(action => {
|
62
|
-
if (Reflect.has(action, 'retain')) {
|
63
|
-
slot.retain(action.retain);
|
64
|
-
}
|
65
|
-
else if (action.insert) {
|
66
|
-
action.insert.forEach(item => {
|
67
|
-
if (typeof item === 'string') {
|
68
|
-
slot.insert(item);
|
69
|
-
}
|
70
|
-
else {
|
71
|
-
slot.insert(translator.createComponent(item.toJSON()));
|
72
|
-
}
|
73
|
-
});
|
17
|
+
transform(events, slot) {
|
18
|
+
events.forEach(ev => {
|
19
|
+
const path = [];
|
20
|
+
for (let i = 0; i < ev.path.length; i += 2) {
|
21
|
+
path.push(ev.path.slice(i, i + 2));
|
74
22
|
}
|
75
|
-
|
76
|
-
|
77
|
-
slot.
|
23
|
+
if (path.length) {
|
24
|
+
const componentIndex = path.shift()[0];
|
25
|
+
const component = slot.getContentAtIndex(componentIndex);
|
26
|
+
this.applySharedComponentToComponent(ev, path, component);
|
27
|
+
return;
|
78
28
|
}
|
29
|
+
this.applySharedSlotToSlot(ev, path, slot);
|
79
30
|
});
|
80
31
|
}
|
81
|
-
|
82
|
-
if (
|
83
|
-
const
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
if (formatter.type !== FormatType.Block) {
|
88
|
-
slot.applyFormat(formatter, {
|
89
|
-
startIndex: 0,
|
90
|
-
endIndex: slot.length,
|
91
|
-
value: null
|
92
|
-
});
|
93
|
-
}
|
94
|
-
formats.forEach(item => {
|
95
|
-
if (formatter.type === FormatType.Block) {
|
96
|
-
slot.applyFormat(formatter, item.value);
|
97
|
-
}
|
98
|
-
else {
|
99
|
-
slot.applyFormat(formatter, item);
|
100
|
-
}
|
101
|
-
});
|
102
|
-
});
|
32
|
+
applySharedComponentToComponent(ev, path, component) {
|
33
|
+
if (path.length) {
|
34
|
+
const childPath = path.shift();
|
35
|
+
const slot = component.slots.get(childPath[0]);
|
36
|
+
this.applySharedSlotToSlot(ev, path, slot);
|
37
|
+
return;
|
103
38
|
}
|
104
|
-
|
39
|
+
if (ev instanceof YMapEvent) {
|
105
40
|
ev.keysChanged.forEach(key => {
|
106
41
|
if (key === 'state') {
|
107
42
|
const state = ev.target.get('state');
|
108
|
-
|
43
|
+
component.updateState(draft => {
|
109
44
|
Object.assign(draft, state);
|
110
45
|
});
|
111
46
|
}
|
112
47
|
});
|
113
48
|
}
|
49
|
+
else if (ev instanceof YArrayEvent) {
|
50
|
+
const slots = component.slots;
|
51
|
+
ev.delta.forEach(action => {
|
52
|
+
if (Reflect.has(action, 'retain')) {
|
53
|
+
slots.retain(action.retain);
|
54
|
+
}
|
55
|
+
else if (action.insert) {
|
56
|
+
action.insert.forEach(item => {
|
57
|
+
slots.insert(this.translator.createSlot(item.toJSON()));
|
58
|
+
});
|
59
|
+
}
|
60
|
+
else if (action.delete) {
|
61
|
+
slots.retain(slots.index);
|
62
|
+
slots.delete(action.delete);
|
63
|
+
}
|
64
|
+
});
|
65
|
+
}
|
114
66
|
}
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
action.insert.
|
123
|
-
|
124
|
-
|
67
|
+
applySharedSlotToSlot(ev, path, slot) {
|
68
|
+
if (path.length) {
|
69
|
+
path.shift();
|
70
|
+
const delta = ev.target.parent.toDelta();
|
71
|
+
let componentIndex = 0;
|
72
|
+
for (let i = 0; i < delta.length; i++) {
|
73
|
+
const action = delta[i];
|
74
|
+
if (action.insert === ev.target) {
|
75
|
+
break;
|
76
|
+
}
|
77
|
+
componentIndex += typeof action.insert === 'string' ? action.insert.length : 1;
|
78
|
+
}
|
79
|
+
const component = slot.getContentAtIndex(componentIndex);
|
80
|
+
this.applySharedComponentToComponent(ev, path, component);
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
if (ev instanceof YTextEvent) {
|
84
|
+
slot.retain(0);
|
85
|
+
ev.delta.forEach(action => {
|
86
|
+
if (Reflect.has(action, 'retain')) {
|
87
|
+
if (action.attributes) {
|
88
|
+
slot.retain(action.retain, Object.keys(action.attributes).map(key => {
|
89
|
+
return [this.registry.getFormatter(key), action.attributes[key]];
|
90
|
+
}));
|
91
|
+
}
|
92
|
+
slot.retain(action.retain);
|
93
|
+
}
|
94
|
+
else if (action.insert) {
|
95
|
+
if (typeof action.insert === 'string') {
|
96
|
+
slot.insert(action.insert, action.attributes ? Object.keys(action.attributes).map(key => {
|
97
|
+
return [this.registry.getFormatter(key), action.attributes[key]];
|
98
|
+
}) : []);
|
125
99
|
}
|
126
100
|
else {
|
127
|
-
const
|
128
|
-
const component = translator.createComponent(json);
|
101
|
+
const component = this.createComponentBySharedComponent(action.insert);
|
129
102
|
slot.insert(component);
|
130
103
|
}
|
131
|
-
}
|
132
|
-
|
133
|
-
|
134
|
-
|
104
|
+
}
|
105
|
+
else if (action.delete) {
|
106
|
+
slot.retain(slot.index);
|
107
|
+
slot.delete(action.delete);
|
108
|
+
}
|
109
|
+
else if (action.attributes) {
|
110
|
+
slot.updateState(draft => {
|
111
|
+
Object.assign(draft, action.attributes);
|
112
|
+
});
|
113
|
+
}
|
114
|
+
});
|
115
|
+
}
|
116
|
+
else {
|
117
|
+
throw new Error('xxx');
|
118
|
+
}
|
119
|
+
}
|
120
|
+
createComponentBySharedComponent(yMap) {
|
121
|
+
const slots = yMap.get('slots');
|
122
|
+
const componentLiteral = {
|
123
|
+
state: yMap.get('state'),
|
124
|
+
name: yMap.get('name'),
|
125
|
+
slots: slots.map(sharedSlot => {
|
126
|
+
return this.createSlotBySharedSlot(sharedSlot).toJSON();
|
127
|
+
})
|
128
|
+
};
|
129
|
+
return this.translator.createComponent(componentLiteral);
|
130
|
+
}
|
131
|
+
createSlotBySharedSlot(sharedSlot) {
|
132
|
+
const content = sharedSlot.get('content');
|
133
|
+
const delta = content.toDelta();
|
134
|
+
const slot = this.translator.createSlot({
|
135
|
+
schema: sharedSlot.get('schema'),
|
136
|
+
state: sharedSlot.get('state'),
|
137
|
+
formats: {},
|
138
|
+
content: []
|
139
|
+
});
|
140
|
+
for (const action of delta) {
|
141
|
+
if (action.insert) {
|
142
|
+
if (typeof action.insert === 'string') {
|
143
|
+
slot.insert(action.insert, action.attributes ? Object.keys(action.attributes).map(key => {
|
144
|
+
return [this.registry.getFormatter(key), action.attributes[key]];
|
145
|
+
}) : []);
|
146
|
+
}
|
147
|
+
else {
|
148
|
+
slot.insert(this.createComponentBySharedComponent(action.insert));
|
149
|
+
}
|
135
150
|
}
|
136
|
-
else
|
137
|
-
|
138
|
-
slot.delete(action.delete);
|
151
|
+
else {
|
152
|
+
throw new Error('xxx');
|
139
153
|
}
|
140
|
-
}
|
154
|
+
}
|
155
|
+
return slot;
|
141
156
|
}
|
142
157
|
}
|
143
158
|
//# sourceMappingURL=remote-to-local.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"remote-to-local.js","sourceRoot":"","sources":["../../src/collab/remote-to-local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAU,SAAS,EAAE,MAAM,KAAK,CAAA;AACjE,OAAO,EAAqB,UAAU,EAA8B,MAAM,eAAe,CAAA;AAIzF,MAAM,UAAU,aAAa,CAAC,MAAgB,EAAE,IAAU,EAAE,UAAsB,EAAE,QAAkB;IACpG,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QAClB,MAAM,IAAI,GAAU,EAAE,CAAA;QAEtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;YAC1C,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAqB,CAAC,CAAA;SACvD;QAED,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,EAAG,CAAC,CAAC,CAAW,CAAA;YACjD,MAAM,SAAS,GAAG,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAsB,CAAA;YAC7E,+BAA+B,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAA;YAC1E,OAAM;SACP;QAED,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,CAAA;IAC7B,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,+BAA+B,CAAC,EAAU,EAAE,IAAW,E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,CAAC,CAAA;iBACT;qBAAM;oBACL,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;iBAClE;aACF;iBAAM;gBACL,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;aACvB;SACF;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { Map as YMap, YArrayEvent, YEvent, YMapEvent, Text as YText, YTextEvent, Array as YArray } from 'yjs'\nimport { ComponentInstance, ComponentLiteral, Registry, Slot, Translator } from '@textbus/core'\n\ntype YPath = [number, string][]\n\nexport class RemoteToLocal {\n constructor(private translator: Translator,\n private registry: Registry) {\n }\n\n transform(events: YEvent[], slot: Slot) {\n events.forEach(ev => {\n const path: YPath = []\n\n for (let i = 0; i < ev.path.length; i += 2) {\n path.push(ev.path.slice(i, i + 2) as [number, string])\n }\n\n if (path.length) {\n const componentIndex = path.shift()![0] as number\n const component = slot.getContentAtIndex(componentIndex) as ComponentInstance\n this.applySharedComponentToComponent(ev, path, component)\n return\n }\n\n this.applySharedSlotToSlot(ev, path, slot)\n })\n }\n\n private applySharedComponentToComponent(ev: YEvent, path: YPath, component: ComponentInstance) {\n if (path.length) {\n const childPath = path.shift()!\n const slot = component.slots.get(childPath[0])!\n this.applySharedSlotToSlot(ev, path, slot)\n return\n }\n if (ev instanceof YMapEvent) {\n ev.keysChanged.forEach(key => {\n if (key === 'state') {\n const state = (ev.target as YMap<any>).get('state')\n component.updateState(draft => {\n Object.assign(draft, state)\n })\n }\n })\n } else if (ev instanceof YArrayEvent) {\n const slots = component.slots\n ev.delta.forEach(action => {\n if (Reflect.has(action, 'retain')) {\n slots.retain(action.retain!)\n } else if (action.insert) {\n (action.insert as Array<any>).forEach(item => {\n slots.insert(this.translator.createSlot(item.toJSON())!)\n })\n } else if (action.delete) {\n slots.retain(slots.index)\n slots.delete(action.delete)\n }\n })\n }\n }\n\n private applySharedSlotToSlot(ev: YEvent, path: YPath, slot: Slot) {\n if (path.length) {\n path.shift()\n const delta = (ev.target.parent as YText).toDelta()\n let componentIndex = 0\n for (let i = 0; i < delta.length; i++) {\n const action = delta[i]\n if (action.insert === ev.target) {\n break\n }\n componentIndex += typeof action.insert === 'string' ? action.insert.length : 1\n }\n const component = slot.getContentAtIndex(componentIndex) as ComponentInstance\n this.applySharedComponentToComponent(ev, path, component)\n return\n }\n\n if (ev instanceof YTextEvent) {\n slot.retain(0)\n ev.delta.forEach(action => {\n if (Reflect.has(action, 'retain')) {\n if (action.attributes) {\n slot.retain(action.retain!, Object.keys(action.attributes).map(key => {\n return [this.registry.getFormatter(key)!, action.attributes![key]]\n }))\n }\n slot.retain(action.retain!)\n } else if (action.insert) {\n if (typeof action.insert === 'string') {\n slot.insert(action.insert, action.attributes ? Object.keys(action.attributes).map(key => {\n return [this.registry.getFormatter(key)!, action.attributes![key]]\n }) : [])\n } else {\n const component = this.createComponentBySharedComponent(action.insert as YMap<any>)\n slot.insert(component)\n }\n } else if (action.delete) {\n slot.retain(slot.index)\n slot.delete(action.delete)\n } else if (action.attributes) {\n slot.updateState(draft => {\n Object.assign(draft, action.attributes)\n })\n }\n })\n } else {\n throw new Error('xxx')\n }\n }\n\n private createComponentBySharedComponent(yMap: YMap<any>): ComponentInstance {\n const slots = yMap.get('slots') as YArray<YMap<any>>\n const componentLiteral: ComponentLiteral = {\n state: yMap.get('state'),\n name: yMap.get('name'),\n slots: slots.map(sharedSlot => {\n return this.createSlotBySharedSlot(sharedSlot).toJSON()\n })\n }\n return this.translator.createComponent(componentLiteral)!\n }\n\n private createSlotBySharedSlot(sharedSlot: YMap<any>): Slot {\n const content = sharedSlot.get('content') as YText\n const delta = content.toDelta()\n\n const slot = this.translator.createSlot({\n schema: sharedSlot.get('schema'),\n state: sharedSlot.get('state'),\n formats: {},\n content: []\n })\n\n for (const action of delta) {\n if (action.insert) {\n if (typeof action.insert === 'string') {\n slot.insert(action.insert, action.attributes ? Object.keys(action.attributes).map(key => {\n return [this.registry.getFormatter(key)!, action.attributes![key]]\n }) : [])\n } else {\n slot.insert(this.createComponentBySharedComponent(action.insert))\n }\n } else {\n throw new Error('xxx')\n }\n }\n return slot\n }\n}\n"]}
|
package/bundles/collaborate.d.ts
CHANGED
@@ -1,23 +1,39 @@
|
|
1
1
|
import { Observable } from '@tanbo/stream';
|
2
|
-
import { RootComponentRef, Starter, Translator, Registry, Selection, SelectionPaths } from '@textbus/core';
|
2
|
+
import { RootComponentRef, Starter, Translator, Registry, Selection, SelectionPaths, History, Renderer } from '@textbus/core';
|
3
3
|
import { Doc as YDoc } from 'yjs';
|
4
|
-
import {
|
5
|
-
export declare class Collaborate {
|
4
|
+
import { CollaborateCursor, RemoteSelection } from './collab/_api';
|
5
|
+
export declare class Collaborate implements History {
|
6
6
|
private rootComponentRef;
|
7
7
|
private collaborateCursor;
|
8
8
|
private translator;
|
9
|
+
private renderer;
|
9
10
|
private registry;
|
10
11
|
private selection;
|
11
|
-
private collaborateHistory;
|
12
12
|
private starter;
|
13
13
|
onSelectionChange: Observable<SelectionPaths>;
|
14
14
|
yDoc: YDoc;
|
15
|
+
onBack: Observable<void>;
|
16
|
+
onForward: Observable<void>;
|
17
|
+
onChange: Observable<any>;
|
18
|
+
onPush: Observable<void>;
|
19
|
+
get canBack(): boolean;
|
20
|
+
get canForward(): boolean;
|
21
|
+
private localToRemote;
|
22
|
+
private remoteToLocal;
|
23
|
+
private backEvent;
|
24
|
+
private forwardEvent;
|
25
|
+
private changeEvent;
|
26
|
+
private pushEvent;
|
27
|
+
private manager;
|
15
28
|
private subscriptions;
|
16
29
|
private updateFromSelf;
|
17
30
|
private selectionChangeEvent;
|
18
|
-
constructor(rootComponentRef: RootComponentRef, collaborateCursor: CollaborateCursor, translator: Translator, registry: Registry, selection: Selection,
|
31
|
+
constructor(rootComponentRef: RootComponentRef, collaborateCursor: CollaborateCursor, translator: Translator, renderer: Renderer, registry: Registry, selection: Selection, starter: Starter);
|
19
32
|
setup(): void;
|
20
33
|
updateRemoteSelection(paths: RemoteSelection[]): void;
|
34
|
+
listen(): void;
|
35
|
+
back(): void;
|
36
|
+
forward(): void;
|
21
37
|
destroy(): void;
|
22
|
-
private
|
38
|
+
private listen2;
|
23
39
|
}
|
package/bundles/collaborate.js
CHANGED
@@ -9,29 +9,168 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
};
|
10
10
|
import { Injectable } from '@tanbo/di';
|
11
11
|
import { debounceTime, filter, Subject, tap } from '@tanbo/stream';
|
12
|
-
import { RootComponentRef, Starter, Translator, Registry, Selection } from '@textbus/core';
|
13
|
-
import { Doc as YDoc } from 'yjs';
|
14
|
-
import {
|
15
|
-
import {
|
16
|
-
import {
|
12
|
+
import { RootComponentRef, Starter, Translator, Registry, Selection, Renderer } from '@textbus/core';
|
13
|
+
import { Doc as YDoc, UndoManager } from 'yjs';
|
14
|
+
import { LocalToRemote } from './collab/local-to-remote';
|
15
|
+
import { RemoteToLocal } from './collab/remote-to-local';
|
16
|
+
import { CollaborateCursor } from './collab/_api';
|
17
17
|
let Collaborate = class Collaborate {
|
18
|
-
constructor(rootComponentRef, collaborateCursor, translator, registry, selection,
|
19
|
-
this
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
this
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
constructor(rootComponentRef, collaborateCursor, translator, renderer, registry, selection, starter) {
|
19
|
+
Object.defineProperty(this, "rootComponentRef", {
|
20
|
+
enumerable: true,
|
21
|
+
configurable: true,
|
22
|
+
writable: true,
|
23
|
+
value: rootComponentRef
|
24
|
+
});
|
25
|
+
Object.defineProperty(this, "collaborateCursor", {
|
26
|
+
enumerable: true,
|
27
|
+
configurable: true,
|
28
|
+
writable: true,
|
29
|
+
value: collaborateCursor
|
30
|
+
});
|
31
|
+
Object.defineProperty(this, "translator", {
|
32
|
+
enumerable: true,
|
33
|
+
configurable: true,
|
34
|
+
writable: true,
|
35
|
+
value: translator
|
36
|
+
});
|
37
|
+
Object.defineProperty(this, "renderer", {
|
38
|
+
enumerable: true,
|
39
|
+
configurable: true,
|
40
|
+
writable: true,
|
41
|
+
value: renderer
|
42
|
+
});
|
43
|
+
Object.defineProperty(this, "registry", {
|
44
|
+
enumerable: true,
|
45
|
+
configurable: true,
|
46
|
+
writable: true,
|
47
|
+
value: registry
|
48
|
+
});
|
49
|
+
Object.defineProperty(this, "selection", {
|
50
|
+
enumerable: true,
|
51
|
+
configurable: true,
|
52
|
+
writable: true,
|
53
|
+
value: selection
|
54
|
+
});
|
55
|
+
Object.defineProperty(this, "starter", {
|
56
|
+
enumerable: true,
|
57
|
+
configurable: true,
|
58
|
+
writable: true,
|
59
|
+
value: starter
|
60
|
+
});
|
61
|
+
Object.defineProperty(this, "onSelectionChange", {
|
62
|
+
enumerable: true,
|
63
|
+
configurable: true,
|
64
|
+
writable: true,
|
65
|
+
value: void 0
|
66
|
+
});
|
67
|
+
Object.defineProperty(this, "yDoc", {
|
68
|
+
enumerable: true,
|
69
|
+
configurable: true,
|
70
|
+
writable: true,
|
71
|
+
value: new YDoc()
|
72
|
+
});
|
73
|
+
Object.defineProperty(this, "onBack", {
|
74
|
+
enumerable: true,
|
75
|
+
configurable: true,
|
76
|
+
writable: true,
|
77
|
+
value: void 0
|
78
|
+
});
|
79
|
+
Object.defineProperty(this, "onForward", {
|
80
|
+
enumerable: true,
|
81
|
+
configurable: true,
|
82
|
+
writable: true,
|
83
|
+
value: void 0
|
84
|
+
});
|
85
|
+
Object.defineProperty(this, "onChange", {
|
86
|
+
enumerable: true,
|
87
|
+
configurable: true,
|
88
|
+
writable: true,
|
89
|
+
value: void 0
|
90
|
+
});
|
91
|
+
Object.defineProperty(this, "onPush", {
|
92
|
+
enumerable: true,
|
93
|
+
configurable: true,
|
94
|
+
writable: true,
|
95
|
+
value: void 0
|
96
|
+
});
|
97
|
+
Object.defineProperty(this, "localToRemote", {
|
98
|
+
enumerable: true,
|
99
|
+
configurable: true,
|
100
|
+
writable: true,
|
101
|
+
value: new LocalToRemote()
|
102
|
+
});
|
103
|
+
Object.defineProperty(this, "remoteToLocal", {
|
104
|
+
enumerable: true,
|
105
|
+
configurable: true,
|
106
|
+
writable: true,
|
107
|
+
value: new RemoteToLocal(this.translator, this.registry)
|
108
|
+
});
|
109
|
+
Object.defineProperty(this, "backEvent", {
|
110
|
+
enumerable: true,
|
111
|
+
configurable: true,
|
112
|
+
writable: true,
|
113
|
+
value: new Subject()
|
114
|
+
});
|
115
|
+
Object.defineProperty(this, "forwardEvent", {
|
116
|
+
enumerable: true,
|
117
|
+
configurable: true,
|
118
|
+
writable: true,
|
119
|
+
value: new Subject()
|
120
|
+
});
|
121
|
+
Object.defineProperty(this, "changeEvent", {
|
122
|
+
enumerable: true,
|
123
|
+
configurable: true,
|
124
|
+
writable: true,
|
125
|
+
value: new Subject()
|
126
|
+
});
|
127
|
+
Object.defineProperty(this, "pushEvent", {
|
128
|
+
enumerable: true,
|
129
|
+
configurable: true,
|
130
|
+
writable: true,
|
131
|
+
value: new Subject()
|
132
|
+
});
|
133
|
+
Object.defineProperty(this, "manager", {
|
134
|
+
enumerable: true,
|
135
|
+
configurable: true,
|
136
|
+
writable: true,
|
137
|
+
value: void 0
|
138
|
+
});
|
139
|
+
Object.defineProperty(this, "subscriptions", {
|
140
|
+
enumerable: true,
|
141
|
+
configurable: true,
|
142
|
+
writable: true,
|
143
|
+
value: []
|
144
|
+
});
|
145
|
+
Object.defineProperty(this, "updateFromSelf", {
|
146
|
+
enumerable: true,
|
147
|
+
configurable: true,
|
148
|
+
writable: true,
|
149
|
+
value: true
|
150
|
+
});
|
151
|
+
Object.defineProperty(this, "selectionChangeEvent", {
|
152
|
+
enumerable: true,
|
153
|
+
configurable: true,
|
154
|
+
writable: true,
|
155
|
+
value: new Subject()
|
156
|
+
});
|
30
157
|
this.onSelectionChange = this.selectionChangeEvent.asObservable();
|
158
|
+
this.onBack = this.backEvent.asObservable();
|
159
|
+
this.onForward = this.forwardEvent.asObservable();
|
160
|
+
this.onChange = this.changeEvent.asObservable();
|
161
|
+
this.onPush = this.pushEvent.asObservable();
|
162
|
+
}
|
163
|
+
get canBack() {
|
164
|
+
var _a;
|
165
|
+
return (_a = this.manager) === null || _a === void 0 ? void 0 : _a.canUndo();
|
166
|
+
}
|
167
|
+
get canForward() {
|
168
|
+
var _a;
|
169
|
+
return (_a = this.manager) === null || _a === void 0 ? void 0 : _a.canRedo();
|
31
170
|
}
|
32
171
|
setup() {
|
33
172
|
this.subscriptions.push(this.starter.onReady.subscribe(() => {
|
34
|
-
this.
|
173
|
+
this.listen2();
|
35
174
|
}), this.selection.onChange.subscribe(() => {
|
36
175
|
const paths = this.selection.getPaths();
|
37
176
|
this.selectionChangeEvent.next(paths);
|
@@ -40,19 +179,34 @@ let Collaborate = class Collaborate {
|
|
40
179
|
updateRemoteSelection(paths) {
|
41
180
|
this.collaborateCursor.draw(paths);
|
42
181
|
}
|
182
|
+
listen() {
|
183
|
+
//
|
184
|
+
}
|
185
|
+
back() {
|
186
|
+
if (this.canBack) {
|
187
|
+
this.manager.undo();
|
188
|
+
}
|
189
|
+
}
|
190
|
+
forward() {
|
191
|
+
if (this.canForward) {
|
192
|
+
this.manager.redo();
|
193
|
+
}
|
194
|
+
}
|
43
195
|
destroy() {
|
44
196
|
this.subscriptions.forEach(i => i.unsubscribe());
|
45
197
|
}
|
46
|
-
|
47
|
-
const root = this.yDoc.
|
198
|
+
listen2() {
|
199
|
+
const root = this.yDoc.getText('content');
|
48
200
|
const slot = this.rootComponentRef.component.slots.get(0);
|
49
|
-
this.
|
201
|
+
this.manager = new UndoManager(root);
|
50
202
|
root.observeDeep((events, transaction) => {
|
51
203
|
if (transaction.origin === this.yDoc) {
|
52
204
|
return;
|
53
205
|
}
|
54
206
|
this.updateFromSelf = false;
|
55
|
-
remoteToLocal(events, slot
|
207
|
+
this.remoteToLocal.transform(events, slot);
|
208
|
+
this.renderer.render();
|
209
|
+
this.selection.restore();
|
56
210
|
this.updateFromSelf = true;
|
57
211
|
});
|
58
212
|
const operations = [];
|
@@ -63,10 +217,12 @@ let Collaborate = class Collaborate {
|
|
63
217
|
}), debounceTime(1)).subscribe(() => {
|
64
218
|
this.yDoc.transact(() => {
|
65
219
|
operations.forEach(operation => {
|
66
|
-
localToRemote(operation, root);
|
220
|
+
this.localToRemote.transform(operation, root);
|
67
221
|
});
|
68
222
|
operations.length = 0;
|
69
223
|
}, this.yDoc);
|
224
|
+
this.renderer.render();
|
225
|
+
this.selection.restore();
|
70
226
|
}));
|
71
227
|
}
|
72
228
|
};
|
@@ -75,9 +231,9 @@ Collaborate = __decorate([
|
|
75
231
|
__metadata("design:paramtypes", [RootComponentRef,
|
76
232
|
CollaborateCursor,
|
77
233
|
Translator,
|
234
|
+
Renderer,
|
78
235
|
Registry,
|
79
236
|
Selection,
|
80
|
-
CollaborateHistory,
|
81
237
|
Starter])
|
82
238
|
], Collaborate);
|
83
239
|
export { Collaborate };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"collaborate.js","sourceRoot":"","sources":["../src/collaborate.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAc,OAAO,EAAgB,GAAG,EAAE,MAAM,eAAe,CAAA;AAC5F,OAAO,EACL,gBAAgB,EAChB,OAAO,EAEP,UAAU,EACV,QAAQ,EACR,SAAS,
|
1
|
+
{"version":3,"file":"collaborate.js","sourceRoot":"","sources":["../src/collaborate.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAc,OAAO,EAAgB,GAAG,EAAE,MAAM,eAAe,CAAA;AAC5F,OAAO,EACL,gBAAgB,EAChB,OAAO,EAEP,UAAU,EACV,QAAQ,EACR,SAAS,EAEA,QAAQ,EAClB,MAAM,eAAe,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AAa,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;gBAC/C,CAAC,CAAC,CAAA;gBACF,UAAU,CAAC,MAAM,GAAG,CAAC,CAAA;YACvB,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;YACb,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAA;YACtB,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAA;QAC1B,CAAC,CAAC,CACH,CAAA;IACH,CAAC;CACF,CAAA;AAtHY,WAAW;IADvB,UAAU,EAAE;qCAgC2B,gBAAgB;QACf,iBAAiB;QACxB,UAAU;QACZ,QAAQ;QACR,QAAQ;QACP,SAAS;QACX,OAAO;GArCzB,WAAW,CAsHvB;SAtHY,WAAW","sourcesContent":["import { Injectable } from '@tanbo/di'\nimport { debounceTime, filter, Observable, Subject, Subscription, tap } from '@tanbo/stream'\nimport {\n RootComponentRef,\n Starter,\n Operation,\n Translator,\n Registry,\n Selection,\n SelectionPaths,\n History, Renderer\n} from '@textbus/core'\nimport { Doc as YDoc, UndoManager } from 'yjs'\nimport { LocalToRemote } from './collab/local-to-remote'\nimport { RemoteToLocal } from './collab/remote-to-local'\nimport { CollaborateCursor, RemoteSelection } from './collab/_api'\n\n@Injectable()\nexport class Collaborate implements History {\n onSelectionChange: Observable<SelectionPaths>\n yDoc = new YDoc()\n onBack: Observable<void>\n onForward: Observable<void>\n onChange: Observable<any>\n onPush: Observable<void>\n\n get canBack() {\n return this.manager?.canUndo()\n }\n\n get canForward() {\n return this.manager?.canRedo()\n }\n\n private localToRemote = new LocalToRemote()\n private remoteToLocal = new RemoteToLocal(this.translator, this.registry)\n\n private backEvent = new Subject<void>()\n private forwardEvent = new Subject<void>()\n private changeEvent = new Subject<void>()\n private pushEvent = new Subject<void>()\n\n private manager!: UndoManager\n\n private subscriptions: Subscription[] = []\n private updateFromSelf = true\n\n private selectionChangeEvent = new Subject<SelectionPaths>()\n\n constructor(private rootComponentRef: RootComponentRef,\n private collaborateCursor: CollaborateCursor,\n private translator: Translator,\n private renderer: Renderer,\n private registry: Registry,\n private selection: Selection,\n private starter: Starter) {\n this.onSelectionChange = this.selectionChangeEvent.asObservable()\n this.onBack = this.backEvent.asObservable()\n this.onForward = this.forwardEvent.asObservable()\n this.onChange = this.changeEvent.asObservable()\n this.onPush = this.pushEvent.asObservable()\n }\n\n setup() {\n this.subscriptions.push(\n this.starter.onReady.subscribe(() => {\n this.listen2()\n }),\n this.selection.onChange.subscribe(() => {\n const paths = this.selection.getPaths()\n this.selectionChangeEvent.next(paths)\n })\n )\n }\n\n updateRemoteSelection(paths: RemoteSelection[]) {\n this.collaborateCursor.draw(paths)\n }\n\n listen() {\n //\n }\n\n back() {\n if (this.canBack) {\n this.manager.undo()\n }\n }\n\n forward() {\n if (this.canForward) {\n this.manager.redo()\n }\n }\n\n destroy() {\n this.subscriptions.forEach(i => i.unsubscribe())\n }\n\n private listen2() {\n const root = this.yDoc.getText('content')\n const slot = this.rootComponentRef.component.slots.get(0)!\n this.manager = new UndoManager(root)\n root.observeDeep((events, transaction) => {\n if (transaction.origin === this.yDoc) {\n return\n }\n this.updateFromSelf = false\n\n this.remoteToLocal.transform(events, slot)\n this.renderer.render()\n this.selection.restore()\n this.updateFromSelf = true\n })\n const operations: Operation[] = []\n this.subscriptions.push(\n this.rootComponentRef.component.changeMarker.onChange.pipe(\n filter(() => {\n return this.updateFromSelf\n }),\n tap(op => {\n operations.push(op)\n }),\n debounceTime(1)\n ).subscribe(() => {\n this.yDoc.transact(() => {\n operations.forEach(operation => {\n this.localToRemote.transform(operation, root)\n })\n operations.length = 0\n }, this.yDoc)\n this.renderer.render()\n this.selection.restore()\n })\n )\n }\n}\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../src/public-api.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA"}
|
1
|
+
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../src/public-api.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA","sourcesContent":["export * from './collab/_api'\nexport * from './collaborate'\n"]}
|