@textbus/collaborate 2.0.0-alpha.38 → 2.0.0-alpha.41

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,3 @@
1
1
  export * from './collaborate-cursor';
2
- export * from './collaborate-history';
3
2
  export * from './local-to-remote';
4
3
  export * from './remote-to-local';
@@ -1,5 +1,4 @@
1
1
  export * from './collaborate-cursor';
2
- export * from './collaborate-history';
3
2
  export * from './local-to-remote';
4
3
  export * from './remote-to-local';
5
4
  //# sourceMappingURL=_api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_api.js","sourceRoot":"","sources":["../../src/collab/_api.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"_api.js","sourceRoot":"","sources":["../../src/collab/_api.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA","sourcesContent":["export * from './collaborate-cursor'\nexport * from './local-to-remote'\nexport * from './remote-to-local'\n"]}
@@ -10,7 +10,16 @@ export interface SelectionRect {
10
10
  y: number;
11
11
  width: number;
12
12
  height: number;
13
+ }
14
+ export interface SelectionInfo {
13
15
  color: string;
16
+ username: string;
17
+ rects: SelectionRect[];
18
+ }
19
+ export interface RemoteSelectionCursor {
20
+ cursor: HTMLElement;
21
+ anchor: HTMLElement;
22
+ userTip: HTMLElement;
14
23
  }
15
24
  export declare class CollaborateCursor {
16
25
  private container;
@@ -19,7 +28,10 @@ export declare class CollaborateCursor {
19
28
  private selection;
20
29
  private canvas;
21
30
  private context;
22
- private onRectChange;
31
+ private tooltips;
32
+ private onRectsChange;
23
33
  constructor(container: HTMLElement, document: Document, nativeSelection: SelectionBridge, selection: Selection);
24
34
  draw(paths: RemoteSelection[]): void;
35
+ private drawUserCursor;
36
+ private getUserCursor;
25
37
  }
@@ -16,36 +16,93 @@ import { Selection } from '@textbus/core';
16
16
  import { Subject } from '@tanbo/stream';
17
17
  let CollaborateCursor = class CollaborateCursor {
18
18
  constructor(container, document, nativeSelection, selection) {
19
- this.container = container;
20
- this.document = document;
21
- this.nativeSelection = nativeSelection;
22
- this.selection = selection;
23
- this.canvas = createElement('canvas', {
24
- styles: {
25
- position: 'absolute',
26
- opacity: 0.5,
27
- left: 0,
28
- top: 0,
29
- width: '100%',
30
- height: '100%',
31
- pointerEvents: 'none'
32
- }
19
+ Object.defineProperty(this, "container", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: container
24
+ });
25
+ Object.defineProperty(this, "document", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: document
30
+ });
31
+ Object.defineProperty(this, "nativeSelection", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: nativeSelection
36
+ });
37
+ Object.defineProperty(this, "selection", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: selection
42
+ });
43
+ Object.defineProperty(this, "canvas", {
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true,
47
+ value: createElement('canvas', {
48
+ styles: {
49
+ position: 'absolute',
50
+ opacity: 0.5,
51
+ left: 0,
52
+ top: 0,
53
+ width: '100%',
54
+ height: '100%',
55
+ pointerEvents: 'none'
56
+ }
57
+ })
58
+ });
59
+ Object.defineProperty(this, "context", {
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true,
63
+ value: this.canvas.getContext('2d')
64
+ });
65
+ Object.defineProperty(this, "tooltips", {
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true,
69
+ value: createElement('div', {
70
+ styles: {
71
+ position: 'absolute',
72
+ left: 0,
73
+ top: 0,
74
+ width: '100%',
75
+ height: '100%',
76
+ pointerEvents: 'none',
77
+ fontSize: '12px'
78
+ }
79
+ })
80
+ });
81
+ Object.defineProperty(this, "onRectsChange", {
82
+ enumerable: true,
83
+ configurable: true,
84
+ writable: true,
85
+ value: new Subject()
33
86
  });
34
- this.context = this.canvas.getContext('2d');
35
- this.onRectChange = new Subject();
36
87
  container.appendChild(this.canvas);
37
- this.onRectChange.subscribe(rect => {
38
- this.context.fillStyle = rect.color;
39
- this.context.beginPath();
40
- this.context.rect(Math.ceil(rect.x), Math.ceil(rect.y), Math.ceil(rect.width), Math.ceil(rect.height));
41
- this.context.fill();
42
- this.context.closePath();
88
+ container.appendChild(this.tooltips);
89
+ this.onRectsChange.subscribe(info => {
90
+ const color = info.color;
91
+ const rects = info.rects;
92
+ for (const rect of rects) {
93
+ this.context.fillStyle = color;
94
+ this.context.beginPath();
95
+ this.context.rect(rect.x, rect.y, rect.width, rect.height);
96
+ this.context.fill();
97
+ this.context.closePath();
98
+ }
43
99
  });
44
100
  }
45
101
  draw(paths) {
46
102
  this.canvas.width = this.container.offsetWidth;
47
103
  this.canvas.height = this.container.offsetHeight;
48
104
  this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
105
+ const users = [];
49
106
  paths.filter(i => {
50
107
  return i.paths.start.length && i.paths.end.length;
51
108
  }).forEach(item => {
@@ -65,34 +122,123 @@ let CollaborateCursor = class CollaborateCursor {
65
122
  nativeRange.setStart(position.start.node, position.start.offset);
66
123
  nativeRange.setEnd(position.end.node, position.end.offset);
67
124
  const rects = nativeRange.getClientRects();
68
- let prev = {};
125
+ const selectionRects = [];
69
126
  for (let i = rects.length - 1; i >= 0; i--) {
70
127
  const rect = rects[i];
71
- if (prev.y === rect.y) {
72
- continue;
73
- }
74
- prev = rect;
75
- this.onRectChange.next({
128
+ selectionRects.push({
76
129
  x: rect.x,
77
130
  y: rect.y,
78
131
  width: rect.width,
79
132
  height: rect.height,
80
- color: item.color
81
133
  });
82
134
  }
83
135
  if (rects.length === 0) {
84
136
  const rect = nativeRange.getBoundingClientRect();
85
- this.onRectChange.next({
86
- x: rect.x,
87
- y: rect.y,
88
- width: 1,
89
- height: rect.height,
90
- color: item.color
91
- });
137
+ if (rect.x !== 0 || rect.y !== 0 || rect.width !== 0 || rect.height !== 0) {
138
+ selectionRects.push({
139
+ x: rect.x,
140
+ y: rect.y,
141
+ width: 1,
142
+ height: rect.height,
143
+ });
144
+ }
92
145
  }
146
+ const info = Object.assign(Object.assign({}, item), { rects: selectionRects });
147
+ this.onRectsChange.next(info);
148
+ users.push(info);
149
+ }
150
+ }
151
+ });
152
+ this.drawUserCursor(users);
153
+ }
154
+ drawUserCursor(users) {
155
+ for (let i = 0; i < users.length; i++) {
156
+ const user = users[i];
157
+ const last = user.rects[user.rects.length - 1];
158
+ const { cursor, userTip, anchor } = this.getUserCursor(i);
159
+ if (!last) {
160
+ cursor.style.display = 'none';
161
+ }
162
+ else {
163
+ Object.assign(cursor.style, {
164
+ left: last.x + last.width + 'px',
165
+ top: last.y + 'px',
166
+ width: '2px',
167
+ height: last.height + 'px',
168
+ background: user.color,
169
+ display: 'block'
170
+ });
171
+ anchor.style.background = user.color;
172
+ userTip.innerText = user.username;
173
+ userTip.style.background = user.color;
174
+ }
175
+ }
176
+ for (let i = users.length; i < this.tooltips.children.length; i++) {
177
+ this.tooltips.removeChild(this.tooltips.children[i]);
178
+ }
179
+ }
180
+ getUserCursor(index) {
181
+ let child = this.tooltips.children[index];
182
+ if (child) {
183
+ const anchor = child.children[0];
184
+ return {
185
+ cursor: child,
186
+ anchor,
187
+ userTip: anchor.children[0]
188
+ };
189
+ }
190
+ const userTip = createElement('span', {
191
+ styles: {
192
+ position: 'absolute',
193
+ display: 'none',
194
+ left: '50%',
195
+ transform: 'translateX(-50%)',
196
+ marginBottom: '2px',
197
+ bottom: '100%',
198
+ whiteSpace: 'nowrap',
199
+ color: '#fff',
200
+ boxShadow: '0 1px 2px rgba(0,0,0,.1)',
201
+ borderRadius: '3px',
202
+ padding: '3px 5px',
203
+ pointerEvents: 'none',
204
+ }
205
+ });
206
+ const anchor = createElement('span', {
207
+ styles: {
208
+ position: 'absolute',
209
+ top: '-2px',
210
+ left: '-2px',
211
+ width: '6px',
212
+ height: '6px',
213
+ pointerEvents: 'auto',
214
+ pointer: 'cursor',
215
+ },
216
+ children: [userTip],
217
+ on: {
218
+ mouseenter() {
219
+ anchor.style.transform = 'scale(1.2)';
220
+ userTip.style.display = 'block';
221
+ },
222
+ mouseleave() {
223
+ userTip.style.display = 'none';
224
+ anchor.style.transform = '';
93
225
  }
94
226
  }
95
227
  });
228
+ child = createElement('span', {
229
+ styles: {
230
+ position: 'absolute',
231
+ },
232
+ children: [
233
+ anchor
234
+ ]
235
+ });
236
+ this.tooltips.append(child);
237
+ return {
238
+ cursor: child,
239
+ anchor,
240
+ userTip
241
+ };
96
242
  }
97
243
  };
98
244
  CollaborateCursor = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"collaborate-cursor.js","sourceRoot":"","sources":["../../src/collab/collaborate-cursor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACtG,OAAO,EAAE,SAAS,EAAkB,MAAM,eAAe,CAAA;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAiBvC,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAgB5B,YAA8C,SAAsB,EACrB,QAAkB,EAC7C,eAAgC,EAChC,SAAoB;QAHM,cAAS,GAAT,SAAS,CAAa;QACrB,aAAQ,GAAR,QAAQ,CAAU;QAC7C,oBAAe,GAAf,eAAe,CAAiB;QAChC,cAAS,GAAT,SAAS,CAAW;QAlBhC,WAAM,GAAG,aAAa,CAAC,QAAQ,EAAE;YACvC,MAAM,EAAE;gBACN,QAAQ,EAAE,UAAU;gBACpB,OAAO,EAAE,GAAG;gBACZ,IAAI,EAAE,CAAC;gBACP,GAAG,EAAE,CAAC;gBACN,KAAK,EAAE,MAAM;gBACb,MAAM,EAAE,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AAiB","sourcesContent":["import { Inject, Injectable } from '@tanbo/di'\nimport { createElement, EDITABLE_DOCUMENT, EDITOR_CONTAINER, SelectionBridge } from '@textbus/browser'\nimport { Selection, SelectionPaths } from '@textbus/core'\nimport { Subject } from '@tanbo/stream'\n\nexport interface RemoteSelection {\n color: string\n username: string\n paths: SelectionPaths\n}\n\nexport interface SelectionRect {\n x: number\n y: number\n width: number\n height: number\n}\n\nexport interface SelectionInfo {\n color: string\n username: string\n rects: SelectionRect[]\n}\n\nexport interface RemoteSelectionCursor {\n cursor: HTMLElement\n anchor: HTMLElement\n userTip: HTMLElement\n}\n\n@Injectable()\nexport class CollaborateCursor {\n private canvas = createElement('canvas', {\n styles: {\n position: 'absolute',\n opacity: 0.5,\n left: 0,\n top: 0,\n width: '100%',\n height: '100%',\n pointerEvents: 'none'\n }\n }) as HTMLCanvasElement\n private context = this.canvas.getContext('2d')!\n private tooltips = createElement('div', {\n styles: {\n position: 'absolute',\n left: 0,\n top: 0,\n width: '100%',\n height: '100%',\n pointerEvents: 'none',\n fontSize: '12px'\n }\n })\n\n private onRectsChange = new Subject<SelectionInfo>()\n\n constructor(@Inject(EDITOR_CONTAINER) private container: HTMLElement,\n @Inject(EDITABLE_DOCUMENT) private document: Document,\n private nativeSelection: SelectionBridge,\n private selection: Selection) {\n container.appendChild(this.canvas)\n container.appendChild(this.tooltips)\n this.onRectsChange.subscribe(info => {\n const color = info.color\n const rects = info.rects\n for (const rect of rects) {\n this.context.fillStyle = color\n this.context.beginPath()\n this.context.rect(rect.x, rect.y, rect.width, rect.height)\n this.context.fill()\n this.context.closePath()\n }\n })\n }\n\n draw(paths: RemoteSelection[]) {\n this.canvas.width = this.container.offsetWidth\n this.canvas.height = this.container.offsetHeight\n this.context.clearRect(0, 0, this.canvas.width, this.canvas.height)\n\n const users: SelectionInfo[] = []\n\n paths.filter(i => {\n return i.paths.start.length && i.paths.end.length\n }).forEach(item => {\n const startOffset = item.paths.start.pop()!\n const startSlot = this.selection.findSlotByPaths(item.paths.start)\n const endOffset = item.paths.end.pop()!\n const endSlot = this.selection.findSlotByPaths(item.paths.end)\n\n if (startSlot && endSlot) {\n const position = this.nativeSelection.getPositionByRange({\n startOffset,\n endOffset,\n startSlot,\n endSlot\n })\n if (position.start && position.end) {\n const nativeRange = this.document.createRange()\n nativeRange.setStart(position.start.node, position.start.offset)\n nativeRange.setEnd(position.end.node, position.end.offset)\n\n const rects = nativeRange.getClientRects()\n const selectionRects: SelectionRect[] = []\n for (let i = rects.length - 1; i >= 0; i--) {\n const rect = rects[i]\n selectionRects.push({\n x: rect.x,\n y: rect.y,\n width: rect.width,\n height: rect.height,\n })\n }\n\n if (rects.length === 0) {\n const rect = nativeRange.getBoundingClientRect()\n if (rect.x !== 0 || rect.y !== 0 || rect.width !== 0 || rect.height !== 0) {\n selectionRects.push({\n x: rect.x,\n y: rect.y,\n width: 1,\n height: rect.height,\n })\n }\n }\n const info: SelectionInfo = {\n ...item,\n rects: selectionRects\n }\n this.onRectsChange.next(info)\n\n users.push(info)\n }\n }\n })\n this.drawUserCursor(users)\n }\n\n private drawUserCursor(users: SelectionInfo[]) {\n for (let i = 0; i < users.length; i++) {\n const user = users[i]\n const last = user.rects[user.rects.length - 1]\n\n const {cursor, userTip, anchor} = this.getUserCursor(i)\n if (!last) {\n cursor.style.display = 'none'\n } else {\n Object.assign(cursor.style, {\n left: last.x + last.width + 'px',\n top: last.y + 'px',\n width: '2px',\n height: last.height + 'px',\n background: user.color,\n display: 'block'\n })\n anchor.style.background = user.color\n userTip.innerText = user.username\n userTip.style.background = user.color\n }\n }\n\n for (let i = users.length; i < this.tooltips.children.length; i++) {\n this.tooltips.removeChild(this.tooltips.children[i])\n }\n }\n\n private getUserCursor(index: number): RemoteSelectionCursor {\n let child: HTMLElement = this.tooltips.children[index] as HTMLElement\n if (child) {\n const anchor = child.children[0] as HTMLElement\n return {\n cursor: child,\n anchor,\n userTip: anchor.children[0] as HTMLElement\n }\n }\n const userTip = createElement('span', {\n styles: {\n position: 'absolute',\n display: 'none',\n left: '50%',\n transform: 'translateX(-50%)',\n marginBottom: '2px',\n bottom: '100%',\n whiteSpace: 'nowrap',\n color: '#fff',\n boxShadow: '0 1px 2px rgba(0,0,0,.1)',\n borderRadius: '3px',\n padding: '3px 5px',\n pointerEvents: 'none',\n }\n })\n\n const anchor = createElement('span', {\n styles: {\n position: 'absolute',\n top: '-2px',\n left: '-2px',\n width: '6px',\n height: '6px',\n pointerEvents: 'auto',\n pointer: 'cursor',\n },\n children: [userTip],\n on: {\n mouseenter() {\n anchor.style.transform = 'scale(1.2)'\n userTip.style.display = 'block'\n },\n mouseleave() {\n userTip.style.display = 'none'\n anchor.style.transform = ''\n }\n }\n })\n child = createElement('span', {\n styles: {\n position: 'absolute',\n },\n children: [\n anchor\n ]\n })\n this.tooltips.append(child)\n return {\n cursor: child,\n anchor,\n userTip\n }\n }\n}\n"]}
@@ -1,3 +1,11 @@
1
1
  import { Operation } from '@textbus/core';
2
- import { Array as YArray } from 'yjs';
3
- export declare function localToRemote(operation: Operation, root: YArray<any>): void;
2
+ import { Text as YText } from 'yjs';
3
+ export declare class LocalToRemote {
4
+ transform(operation: Operation, root: YText): void;
5
+ private applyComponentOperationToSharedComponent;
6
+ private applySlotOperationToSharedSlot;
7
+ private mergeActionsToSharedSlot;
8
+ private makeSharedSlotBySlotLiteral;
9
+ private makeSharedComponentByComponentLiteral;
10
+ private getSharedComponentByIndex;
11
+ }