@textbus/collaborate 2.0.0-alpha.38 → 2.0.0-alpha.39
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/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
package/src/collaborate.ts
CHANGED
|
@@ -7,17 +7,40 @@ import {
|
|
|
7
7
|
Translator,
|
|
8
8
|
Registry,
|
|
9
9
|
Selection,
|
|
10
|
-
SelectionPaths
|
|
10
|
+
SelectionPaths,
|
|
11
|
+
History, Renderer
|
|
11
12
|
} from '@textbus/core'
|
|
12
|
-
import { Doc as YDoc } from 'yjs'
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
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, RemoteSelection } from './collab/_api'
|
|
16
17
|
|
|
17
18
|
@Injectable()
|
|
18
|
-
export class Collaborate {
|
|
19
|
+
export class Collaborate implements History {
|
|
19
20
|
onSelectionChange: Observable<SelectionPaths>
|
|
20
21
|
yDoc = new YDoc()
|
|
22
|
+
onBack: Observable<void>
|
|
23
|
+
onForward: Observable<void>
|
|
24
|
+
onChange: Observable<any>
|
|
25
|
+
onPush: Observable<void>
|
|
26
|
+
|
|
27
|
+
get canBack() {
|
|
28
|
+
return this.manager?.canUndo()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get canForward() {
|
|
32
|
+
return this.manager?.canRedo()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private localToRemote = new LocalToRemote()
|
|
36
|
+
private remoteToLocal = new RemoteToLocal(this.translator, this.registry)
|
|
37
|
+
|
|
38
|
+
private backEvent = new Subject<void>()
|
|
39
|
+
private forwardEvent = new Subject<void>()
|
|
40
|
+
private changeEvent = new Subject<void>()
|
|
41
|
+
private pushEvent = new Subject<void>()
|
|
42
|
+
|
|
43
|
+
private manager!: UndoManager
|
|
21
44
|
|
|
22
45
|
private subscriptions: Subscription[] = []
|
|
23
46
|
private updateFromSelf = true
|
|
@@ -27,17 +50,21 @@ export class Collaborate {
|
|
|
27
50
|
constructor(private rootComponentRef: RootComponentRef,
|
|
28
51
|
private collaborateCursor: CollaborateCursor,
|
|
29
52
|
private translator: Translator,
|
|
53
|
+
private renderer: Renderer,
|
|
30
54
|
private registry: Registry,
|
|
31
55
|
private selection: Selection,
|
|
32
|
-
private collaborateHistory: CollaborateHistory,
|
|
33
56
|
private starter: Starter) {
|
|
34
57
|
this.onSelectionChange = this.selectionChangeEvent.asObservable()
|
|
58
|
+
this.onBack = this.backEvent.asObservable()
|
|
59
|
+
this.onForward = this.forwardEvent.asObservable()
|
|
60
|
+
this.onChange = this.changeEvent.asObservable()
|
|
61
|
+
this.onPush = this.pushEvent.asObservable()
|
|
35
62
|
}
|
|
36
63
|
|
|
37
64
|
setup() {
|
|
38
65
|
this.subscriptions.push(
|
|
39
66
|
this.starter.onReady.subscribe(() => {
|
|
40
|
-
this.
|
|
67
|
+
this.listen2()
|
|
41
68
|
}),
|
|
42
69
|
this.selection.onChange.subscribe(() => {
|
|
43
70
|
const paths = this.selection.getPaths()
|
|
@@ -50,22 +77,39 @@ export class Collaborate {
|
|
|
50
77
|
this.collaborateCursor.draw(paths)
|
|
51
78
|
}
|
|
52
79
|
|
|
80
|
+
listen() {
|
|
81
|
+
//
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
back() {
|
|
85
|
+
if (this.canBack) {
|
|
86
|
+
this.manager.undo()
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
forward() {
|
|
91
|
+
if (this.canForward) {
|
|
92
|
+
this.manager.redo()
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
53
96
|
destroy() {
|
|
54
97
|
this.subscriptions.forEach(i => i.unsubscribe())
|
|
55
98
|
}
|
|
56
99
|
|
|
57
|
-
private
|
|
58
|
-
const root = this.yDoc.
|
|
100
|
+
private listen2() {
|
|
101
|
+
const root = this.yDoc.getText('content')
|
|
59
102
|
const slot = this.rootComponentRef.component.slots.get(0)!
|
|
60
|
-
this.
|
|
103
|
+
this.manager = new UndoManager(root)
|
|
61
104
|
root.observeDeep((events, transaction) => {
|
|
62
105
|
if (transaction.origin === this.yDoc) {
|
|
63
106
|
return
|
|
64
107
|
}
|
|
65
108
|
this.updateFromSelf = false
|
|
66
109
|
|
|
67
|
-
remoteToLocal(events, slot
|
|
68
|
-
|
|
110
|
+
this.remoteToLocal.transform(events, slot)
|
|
111
|
+
this.renderer.render()
|
|
112
|
+
this.selection.restore()
|
|
69
113
|
this.updateFromSelf = true
|
|
70
114
|
})
|
|
71
115
|
const operations: Operation[] = []
|
|
@@ -81,10 +125,12 @@ export class Collaborate {
|
|
|
81
125
|
).subscribe(() => {
|
|
82
126
|
this.yDoc.transact(() => {
|
|
83
127
|
operations.forEach(operation => {
|
|
84
|
-
localToRemote(operation, root)
|
|
128
|
+
this.localToRemote.transform(operation, root)
|
|
85
129
|
})
|
|
86
130
|
operations.length = 0
|
|
87
131
|
}, this.yDoc)
|
|
132
|
+
this.renderer.render()
|
|
133
|
+
this.selection.restore()
|
|
88
134
|
})
|
|
89
135
|
)
|
|
90
136
|
}
|
package/tsconfig-build.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"declaration": true,
|
|
4
|
+
"useDefineForClassFields": true,
|
|
4
5
|
"emitDecoratorMetadata": true,
|
|
5
6
|
"experimentalDecorators": true,
|
|
6
7
|
"allowSyntheticDefaultImports": true,
|
|
@@ -10,6 +11,7 @@
|
|
|
10
11
|
"module": "es2020",
|
|
11
12
|
"moduleResolution": "node",
|
|
12
13
|
"sourceMap": true,
|
|
14
|
+
"inlineSources": true,
|
|
13
15
|
"noImplicitAny": false,
|
|
14
16
|
"suppressImplicitAnyIndexErrors": true,
|
|
15
17
|
"outDir": "bundles/",
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { History } from '@textbus/core';
|
|
2
|
-
import { Observable } from '@tanbo/stream';
|
|
3
|
-
import { Array as YArray } from 'yjs';
|
|
4
|
-
export declare class CollaborateHistory implements History {
|
|
5
|
-
onBack: Observable<void>;
|
|
6
|
-
onForward: Observable<void>;
|
|
7
|
-
onChange: Observable<any>;
|
|
8
|
-
onPush: Observable<void>;
|
|
9
|
-
get canBack(): boolean;
|
|
10
|
-
get canForward(): boolean;
|
|
11
|
-
private backEvent;
|
|
12
|
-
private forwardEvent;
|
|
13
|
-
private changeEvent;
|
|
14
|
-
private pushEvent;
|
|
15
|
-
private manager;
|
|
16
|
-
constructor();
|
|
17
|
-
init(yArray: YArray<any>): void;
|
|
18
|
-
listen(): void;
|
|
19
|
-
back(): void;
|
|
20
|
-
forward(): void;
|
|
21
|
-
destroy(): void;
|
|
22
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
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;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Injectable } from '@tanbo/di';
|
|
11
|
-
import { Subject } from '@tanbo/stream';
|
|
12
|
-
import { UndoManager } from 'yjs';
|
|
13
|
-
let CollaborateHistory = class CollaborateHistory {
|
|
14
|
-
constructor() {
|
|
15
|
-
this.backEvent = new Subject();
|
|
16
|
-
this.forwardEvent = new Subject();
|
|
17
|
-
this.changeEvent = new Subject();
|
|
18
|
-
this.pushEvent = new Subject();
|
|
19
|
-
this.onBack = this.backEvent.asObservable();
|
|
20
|
-
this.onForward = this.forwardEvent.asObservable();
|
|
21
|
-
this.onChange = this.changeEvent.asObservable();
|
|
22
|
-
this.onPush = this.pushEvent.asObservable();
|
|
23
|
-
}
|
|
24
|
-
get canBack() {
|
|
25
|
-
var _a;
|
|
26
|
-
return (_a = this.manager) === null || _a === void 0 ? void 0 : _a.canUndo();
|
|
27
|
-
}
|
|
28
|
-
get canForward() {
|
|
29
|
-
var _a;
|
|
30
|
-
return (_a = this.manager) === null || _a === void 0 ? void 0 : _a.canRedo();
|
|
31
|
-
}
|
|
32
|
-
init(yArray) {
|
|
33
|
-
this.manager = new UndoManager(yArray);
|
|
34
|
-
}
|
|
35
|
-
listen() {
|
|
36
|
-
//
|
|
37
|
-
}
|
|
38
|
-
back() {
|
|
39
|
-
//
|
|
40
|
-
}
|
|
41
|
-
forward() {
|
|
42
|
-
//
|
|
43
|
-
}
|
|
44
|
-
destroy() {
|
|
45
|
-
//
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
CollaborateHistory = __decorate([
|
|
49
|
-
Injectable(),
|
|
50
|
-
__metadata("design:paramtypes", [])
|
|
51
|
-
], CollaborateHistory);
|
|
52
|
-
export { CollaborateHistory };
|
|
53
|
-
//# sourceMappingURL=collaborate-history.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collaborate-history.js","sourceRoot":"","sources":["../../src/collab/collaborate-history.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,OAAO,EAAc,OAAO,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,WAAW,EAAmB,MAAM,KAAK,CAAA;AAGlD,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAsB7B;QAPQ,cAAS,GAAG,IAAI,OAAO,EAAQ,CAAA;QAC/B,iBAAY,GAAG,IAAI,OAAO,EAAQ,CAAA;QAClC,gBAAW,GAAG,IAAI,OAAO,EAAQ,CAAA;QACjC,cAAS,GAAG,IAAI,OAAO,EAAQ,CAAA;QAKrC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,CAAA;QAC3C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAA;QACjD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAA;QAC/C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,CAAA;IAC7C,CAAC;IArBD,IAAI,OAAO;;QACT,OAAO,MAAA,IAAI,CAAC,OAAO,0CAAE,OAAO,EAAE,CAAA;IAChC,CAAC;IAED,IAAI,UAAU;;QACZ,OAAO,MAAA,IAAI,CAAC,OAAO,0CAAE,OAAO,EAAE,CAAA;IAChC,CAAC;IAiBD,IAAI,CAAC,MAAmB;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAA;IACxC,CAAC;IAED,MAAM;QACJ,EAAE;IACJ,CAAC;IAED,IAAI;QACF,EAAE;IACJ,CAAC;IAED,OAAO;QACL,EAAE;IACJ,CAAC;IAED,OAAO;QACL,EAAE;IACJ,CAAC;CACF,CAAA;AAhDY,kBAAkB;IAD9B,UAAU,EAAE;;GACA,kBAAkB,CAgD9B;SAhDY,kBAAkB"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@tanbo/di'
|
|
2
|
-
import { History } from '@textbus/core'
|
|
3
|
-
import { Observable, Subject } from '@tanbo/stream'
|
|
4
|
-
import { UndoManager, Array as YArray } from 'yjs'
|
|
5
|
-
|
|
6
|
-
@Injectable()
|
|
7
|
-
export class CollaborateHistory implements History {
|
|
8
|
-
onBack: Observable<void>
|
|
9
|
-
onForward: Observable<void>
|
|
10
|
-
onChange: Observable<any>
|
|
11
|
-
onPush: Observable<void>
|
|
12
|
-
|
|
13
|
-
get canBack() {
|
|
14
|
-
return this.manager?.canUndo()
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get canForward() {
|
|
18
|
-
return this.manager?.canRedo()
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
private backEvent = new Subject<void>()
|
|
23
|
-
private forwardEvent = new Subject<void>()
|
|
24
|
-
private changeEvent = new Subject<void>()
|
|
25
|
-
private pushEvent = new Subject<void>()
|
|
26
|
-
|
|
27
|
-
private manager!: UndoManager
|
|
28
|
-
|
|
29
|
-
constructor() {
|
|
30
|
-
this.onBack = this.backEvent.asObservable()
|
|
31
|
-
this.onForward = this.forwardEvent.asObservable()
|
|
32
|
-
this.onChange = this.changeEvent.asObservable()
|
|
33
|
-
this.onPush = this.pushEvent.asObservable()
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
init(yArray: YArray<any>) {
|
|
37
|
-
this.manager = new UndoManager(yArray)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
listen() {
|
|
41
|
-
//
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
back() {
|
|
45
|
-
//
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
forward() {
|
|
49
|
-
//
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
destroy() {
|
|
53
|
-
//
|
|
54
|
-
}
|
|
55
|
-
}
|