@textbus/platform-browser 4.0.0-alpha.28 → 4.0.0-alpha.30

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.
@@ -42,7 +42,7 @@ export declare class BrowserModule implements Module {
42
42
  * @param textbus
43
43
  */
44
44
  readDocumentByComponentLiteral(data: ComponentLiteral, rootComponent: ComponentConstructor, textbus: Textbus): Component;
45
- setup(): () => void;
45
+ setup(textbus: Textbus): () => void;
46
46
  onAfterStartup(textbus: Textbus): void;
47
47
  private static createLayout;
48
48
  }
@@ -1,15 +1,7 @@
1
- import { Selection, SelectionPaths, AbstractSelection, Scheduler, Textbus } from '@textbus/core';
1
+ import { Selection, AbstractSelection, Scheduler, Textbus } from '@textbus/core';
2
+ import { UserActivity } from '@textbus/collaborate';
2
3
  import { SelectionBridge } from './selection-bridge';
3
4
  import { Rect } from './_utils/uikit';
4
- /**
5
- * 远程用户及光标位置信息
6
- */
7
- export interface RemoteSelection {
8
- id: string;
9
- color: string;
10
- username: string;
11
- paths: SelectionPaths;
12
- }
13
5
  export interface SelectionRect extends Rect {
14
6
  color: string;
15
7
  username: string;
@@ -33,6 +25,7 @@ export declare class CollaborateCursor {
33
25
  private nativeSelection;
34
26
  private scheduler;
35
27
  private selection;
28
+ private userActivity;
36
29
  private awarenessDelegate?;
37
30
  private host;
38
31
  private canvasContainer;
@@ -43,7 +36,8 @@ export declare class CollaborateCursor {
43
36
  private subscription;
44
37
  private currentSelection;
45
38
  private container;
46
- constructor(textbus: Textbus, nativeSelection: SelectionBridge, scheduler: Scheduler, selection: Selection, awarenessDelegate?: CollaborateSelectionAwarenessDelegate | undefined);
39
+ constructor(textbus: Textbus, nativeSelection: SelectionBridge, scheduler: Scheduler, selection: Selection, userActivity: UserActivity, awarenessDelegate?: CollaborateSelectionAwarenessDelegate | undefined);
40
+ init(): void;
47
41
  /**
48
42
  * 刷新协作光标,由于 Textbus 只会绘制可视区域的光标,当可视区域发生变化时,需要重新绘制
49
43
  */
@@ -53,7 +47,7 @@ export declare class CollaborateCursor {
53
47
  * 根据远程用户光标位置,绘制协作光标
54
48
  * @param paths
55
49
  */
56
- draw(paths: RemoteSelection[]): void;
50
+ private draw;
57
51
  protected drawUserCursor(rects: SelectionRect[]): void;
58
52
  private getUserCursor;
59
53
  }
@@ -2,6 +2,7 @@ import 'reflect-metadata';
2
2
  import { Slot, Textbus, ViewAdapter, createBidirectionalMapping, Component, VElement, VTextNode, Controller, Selection, RootComponentRef, ContentType, Event, invokeListener, Keyboard, Commander, Scheduler, makeError, NativeSelectionBridge, FocusManager, Registry } from '@textbus/core';
3
3
  import { Subject, filter, fromEvent, Subscription, distinctUntilChanged, merge, map, Observable } from '@tanbo/stream';
4
4
  import { InjectionToken, Injectable, Inject, Optional } from '@viewfly/core';
5
+ import { UserActivity } from '@textbus/collaborate';
5
6
 
6
7
  function createElement(tagName, options = {}) {
7
8
  const el = document.createElement(tagName);
@@ -1568,10 +1569,11 @@ class CollaborateSelectionAwarenessDelegate {
1568
1569
  * 协作光标绘制类
1569
1570
  */
1570
1571
  let CollaborateCursor = class CollaborateCursor {
1571
- constructor(textbus, nativeSelection, scheduler, selection, awarenessDelegate) {
1572
+ constructor(textbus, nativeSelection, scheduler, selection, userActivity, awarenessDelegate) {
1572
1573
  this.nativeSelection = nativeSelection;
1573
1574
  this.scheduler = scheduler;
1574
1575
  this.selection = selection;
1576
+ this.userActivity = userActivity;
1575
1577
  this.awarenessDelegate = awarenessDelegate;
1576
1578
  this.host = createElement('div', {
1577
1579
  styles: {
@@ -1640,6 +1642,13 @@ let CollaborateCursor = class CollaborateCursor {
1640
1642
  this.refresh();
1641
1643
  }));
1642
1644
  }
1645
+ init() {
1646
+ if (this.userActivity) {
1647
+ this.subscription.add(this.userActivity.onStateChange.subscribe(v => {
1648
+ this.draw(v);
1649
+ }));
1650
+ }
1651
+ }
1643
1652
  /**
1644
1653
  * 刷新协作光标,由于 Textbus 只会绘制可视区域的光标,当可视区域发生变化时,需要重新绘制
1645
1654
  */
@@ -1662,10 +1671,10 @@ let CollaborateCursor = class CollaborateCursor {
1662
1671
  this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
1663
1672
  const users = [];
1664
1673
  paths.filter(i => {
1665
- return i.paths.anchor.length && i.paths.focus.length;
1674
+ return i.selection.anchor.length && i.selection.focus.length;
1666
1675
  }).forEach(item => {
1667
- const anchorPaths = [...item.paths.anchor];
1668
- const focusPaths = [...item.paths.focus];
1676
+ const anchorPaths = [...item.selection.anchor];
1677
+ const focusPaths = [...item.selection.focus];
1669
1678
  const anchorOffset = anchorPaths.pop();
1670
1679
  const anchorSlot = this.selection.findSlotByPaths(anchorPaths);
1671
1680
  const focusOffset = focusPaths.pop();
@@ -1813,10 +1822,12 @@ let CollaborateCursor = class CollaborateCursor {
1813
1822
  CollaborateCursor = __decorate([
1814
1823
  Injectable(),
1815
1824
  __param(4, Optional()),
1825
+ __param(5, Optional()),
1816
1826
  __metadata("design:paramtypes", [Textbus,
1817
1827
  SelectionBridge,
1818
1828
  Scheduler,
1819
1829
  Selection,
1830
+ UserActivity,
1820
1831
  CollaborateSelectionAwarenessDelegate])
1821
1832
  ], CollaborateCursor);
1822
1833
 
@@ -2381,13 +2392,16 @@ class BrowserModule {
2381
2392
  const registry = textbus.get(Registry);
2382
2393
  return registry.createComponentByFactory(data, rootComponent);
2383
2394
  }
2384
- setup() {
2395
+ setup(textbus) {
2385
2396
  const host = this.config.renderTo();
2386
2397
  if (!(host instanceof HTMLElement)) {
2387
2398
  throw browserErrorFn('view container is not a HTMLElement');
2388
2399
  }
2400
+ const cursor = textbus.get(CollaborateCursor);
2401
+ cursor.init();
2389
2402
  host.append(this.workbench);
2390
2403
  return () => {
2404
+ cursor.destroy();
2391
2405
  this.workbench.remove();
2392
2406
  };
2393
2407
  }
package/bundles/index.js CHANGED
@@ -4,6 +4,7 @@ require('reflect-metadata');
4
4
  var core$1 = require('@textbus/core');
5
5
  var stream = require('@tanbo/stream');
6
6
  var core = require('@viewfly/core');
7
+ var collaborate = require('@textbus/collaborate');
7
8
 
8
9
  function createElement(tagName, options = {}) {
9
10
  const el = document.createElement(tagName);
@@ -1570,10 +1571,11 @@ class CollaborateSelectionAwarenessDelegate {
1570
1571
  * 协作光标绘制类
1571
1572
  */
1572
1573
  exports.CollaborateCursor = class CollaborateCursor {
1573
- constructor(textbus, nativeSelection, scheduler, selection, awarenessDelegate) {
1574
+ constructor(textbus, nativeSelection, scheduler, selection, userActivity, awarenessDelegate) {
1574
1575
  this.nativeSelection = nativeSelection;
1575
1576
  this.scheduler = scheduler;
1576
1577
  this.selection = selection;
1578
+ this.userActivity = userActivity;
1577
1579
  this.awarenessDelegate = awarenessDelegate;
1578
1580
  this.host = createElement('div', {
1579
1581
  styles: {
@@ -1642,6 +1644,13 @@ exports.CollaborateCursor = class CollaborateCursor {
1642
1644
  this.refresh();
1643
1645
  }));
1644
1646
  }
1647
+ init() {
1648
+ if (this.userActivity) {
1649
+ this.subscription.add(this.userActivity.onStateChange.subscribe(v => {
1650
+ this.draw(v);
1651
+ }));
1652
+ }
1653
+ }
1645
1654
  /**
1646
1655
  * 刷新协作光标,由于 Textbus 只会绘制可视区域的光标,当可视区域发生变化时,需要重新绘制
1647
1656
  */
@@ -1664,10 +1673,10 @@ exports.CollaborateCursor = class CollaborateCursor {
1664
1673
  this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
1665
1674
  const users = [];
1666
1675
  paths.filter(i => {
1667
- return i.paths.anchor.length && i.paths.focus.length;
1676
+ return i.selection.anchor.length && i.selection.focus.length;
1668
1677
  }).forEach(item => {
1669
- const anchorPaths = [...item.paths.anchor];
1670
- const focusPaths = [...item.paths.focus];
1678
+ const anchorPaths = [...item.selection.anchor];
1679
+ const focusPaths = [...item.selection.focus];
1671
1680
  const anchorOffset = anchorPaths.pop();
1672
1681
  const anchorSlot = this.selection.findSlotByPaths(anchorPaths);
1673
1682
  const focusOffset = focusPaths.pop();
@@ -1815,10 +1824,12 @@ exports.CollaborateCursor = class CollaborateCursor {
1815
1824
  exports.CollaborateCursor = __decorate([
1816
1825
  core.Injectable(),
1817
1826
  __param(4, core.Optional()),
1827
+ __param(5, core.Optional()),
1818
1828
  __metadata("design:paramtypes", [core$1.Textbus,
1819
1829
  exports.SelectionBridge,
1820
1830
  core$1.Scheduler,
1821
1831
  core$1.Selection,
1832
+ collaborate.UserActivity,
1822
1833
  CollaborateSelectionAwarenessDelegate])
1823
1834
  ], exports.CollaborateCursor);
1824
1835
 
@@ -2383,13 +2394,16 @@ class BrowserModule {
2383
2394
  const registry = textbus.get(core$1.Registry);
2384
2395
  return registry.createComponentByFactory(data, rootComponent);
2385
2396
  }
2386
- setup() {
2397
+ setup(textbus) {
2387
2398
  const host = this.config.renderTo();
2388
2399
  if (!(host instanceof HTMLElement)) {
2389
2400
  throw browserErrorFn('view container is not a HTMLElement');
2390
2401
  }
2402
+ const cursor = textbus.get(exports.CollaborateCursor);
2403
+ cursor.init();
2391
2404
  host.append(this.workbench);
2392
2405
  return () => {
2406
+ cursor.destroy();
2393
2407
  this.workbench.remove();
2394
2408
  };
2395
2409
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/platform-browser",
3
- "version": "4.0.0-alpha.28",
3
+ "version": "4.0.0-alpha.30",
4
4
  "description": "Textbus is a rich text editor and framework that is highly customizable and extensible to achieve rich wysiwyg effects.",
5
5
  "main": "./bundles/index.js",
6
6
  "module": "./bundles/index.esm.js",
@@ -26,7 +26,8 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@tanbo/stream": "^1.2.3",
29
- "@textbus/core": "^4.0.0-alpha.28",
29
+ "@textbus/collaborate": "^4.0.0-alpha.30",
30
+ "@textbus/core": "^4.0.0-alpha.30",
30
31
  "@viewfly/core": "^0.6.0",
31
32
  "reflect-metadata": "^0.1.13"
32
33
  },
@@ -48,5 +49,5 @@
48
49
  "bugs": {
49
50
  "url": "https://github.com/textbus/textbus.git/issues"
50
51
  },
51
- "gitHead": "afb457beb39742c7e00f78b71cd24e13443bae56"
52
+ "gitHead": "9b14d8cf2a2473f31a36b51ee3d988ddecf776fb"
52
53
  }