@textbus/collaborate 5.0.0-alpha.1 → 5.0.0-alpha.3

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.
@@ -1,4 +1,4 @@
1
- import { History, RootComponentRef, Scheduler, Selection } from '@textbus/core';
1
+ import { History, RootComponentRef, Scheduler } from '@textbus/core';
2
2
  import { Observable } from '@tanbo/stream';
3
3
  import { Item, Transaction } from 'yjs';
4
4
  import { Collaborate } from './collaborate';
@@ -10,7 +10,6 @@ export declare class CollabHistory implements History {
10
10
  private rootComponentRef;
11
11
  private collaborate;
12
12
  private scheduler;
13
- private selection;
14
13
  private stackSize;
15
14
  private undoManagerConfig;
16
15
  onBack: Observable<void>;
@@ -27,7 +26,7 @@ export declare class CollabHistory implements History {
27
26
  private forwardEvent;
28
27
  private changeEvent;
29
28
  private pushEvent;
30
- constructor(rootComponentRef: RootComponentRef, collaborate: Collaborate, scheduler: Scheduler, selection: Selection, stackSize: number, undoManagerConfig: CustomUndoManagerConfig);
29
+ constructor(rootComponentRef: RootComponentRef, collaborate: Collaborate, scheduler: Scheduler, stackSize: number, undoManagerConfig: CustomUndoManagerConfig);
31
30
  listen(): void;
32
31
  back(): void;
33
32
  forward(): void;
@@ -4,11 +4,13 @@ import { Doc as YDoc } from 'yjs';
4
4
  import { SyncConnector } from './base/_api';
5
5
  export interface CollaborateConfig {
6
6
  createConnector(yDoc: YDoc): SyncConnector;
7
+ onlyLoad?: boolean;
7
8
  }
8
9
  export declare class CollaborateModule implements Module {
9
10
  config: CollaborateConfig;
10
11
  private subscription;
11
12
  providers: Provider[];
13
+ private timer;
12
14
  constructor(config: CollaborateConfig);
13
15
  setup(textbus: Textbus): Promise<(() => void) | void> | (() => void) | void;
14
16
  onDestroy(textbus: Textbus): void;
@@ -521,6 +521,8 @@ let Collaborate = class Collaborate {
521
521
  return;
522
522
  }
523
523
  const content = subDocument.getText('content');
524
+ const data = subDocument.getMap('data');
525
+ this.syncLocalMapToSharedMap(localSlot.data, data);
524
526
  this.initSharedSlotByLocalSlot(content, localSlot);
525
527
  this.syncSlot(content, localSlot);
526
528
  this.addSubModelEvent.next({
@@ -572,11 +574,13 @@ let Collaborate = class Collaborate {
572
574
  const schema = sharedSlot.getAttribute('schema');
573
575
  if (type === 'async') {
574
576
  const metadata = sharedSlot.getAttribute('metadata');
575
- const slot = new AsyncSlot(schema || [], {});
577
+ const slot = new AsyncSlot(schema || [], {}, {});
576
578
  this.syncSharedMapToLocalMap(metadata, slot.metadata);
577
579
  const loadedSubDocument = this.subModelLoader.getLoadedModelBySlot(slot);
578
580
  if (loadedSubDocument) {
579
581
  const subContent = loadedSubDocument.getText('content');
582
+ const data = loadedSubDocument.getMap('data');
583
+ this.syncLocalMapToSharedMap(slot, data);
580
584
  this.syncRootSlot(loadedSubDocument, subContent, slot);
581
585
  this.addSubModelEvent.next({
582
586
  yDoc: loadedSubDocument,
@@ -946,7 +950,7 @@ let CollabHistory = class CollabHistory {
946
950
  var _a;
947
951
  return ((_a = this.manager) === null || _a === void 0 ? void 0 : _a.canRedo()) || false;
948
952
  }
949
- constructor(rootComponentRef, collaborate, scheduler, selection, stackSize, undoManagerConfig) {
953
+ constructor(rootComponentRef, collaborate, scheduler, stackSize, undoManagerConfig) {
950
954
  Object.defineProperty(this, "rootComponentRef", {
951
955
  enumerable: true,
952
956
  configurable: true,
@@ -965,12 +969,6 @@ let CollabHistory = class CollabHistory {
965
969
  writable: true,
966
970
  value: scheduler
967
971
  });
968
- Object.defineProperty(this, "selection", {
969
- enumerable: true,
970
- configurable: true,
971
- writable: true,
972
- value: selection
973
- });
974
972
  Object.defineProperty(this, "stackSize", {
975
973
  enumerable: true,
976
974
  configurable: true,
@@ -1157,12 +1155,11 @@ let CollabHistory = class CollabHistory {
1157
1155
  };
1158
1156
  CollabHistory = __decorate([
1159
1157
  Injectable(),
1160
- __param(4, Inject(HISTORY_STACK_SIZE)),
1161
- __param(5, Optional()),
1158
+ __param(3, Inject(HISTORY_STACK_SIZE)),
1159
+ __param(4, Optional()),
1162
1160
  __metadata("design:paramtypes", [RootComponentRef,
1163
1161
  Collaborate,
1164
- Scheduler,
1165
- Selection, Number, CustomUndoManagerConfig])
1162
+ Scheduler, Number, CustomUndoManagerConfig])
1166
1163
  ], CollabHistory);
1167
1164
 
1168
1165
  /**
@@ -1644,10 +1641,17 @@ class CollaborateModule {
1644
1641
  }
1645
1642
  ]
1646
1643
  });
1644
+ Object.defineProperty(this, "timer", {
1645
+ enumerable: true,
1646
+ configurable: true,
1647
+ writable: true,
1648
+ value: null
1649
+ });
1647
1650
  }
1648
1651
  setup(textbus) {
1649
1652
  const messageBus = textbus.get(MessageBus, null);
1650
1653
  const connector = textbus.get(SyncConnector);
1654
+ const collab = textbus.get(Collaborate);
1651
1655
  if (messageBus) {
1652
1656
  const selection = textbus.get(Selection);
1653
1657
  connector.setLocalStateField('message', messageBus.get(textbus));
@@ -1659,13 +1663,33 @@ class CollaborateModule {
1659
1663
  messageBus.consume(states, textbus);
1660
1664
  }));
1661
1665
  }
1662
- return connector.onLoad.toPromise();
1666
+ return connector.onLoad.toPromise().then(() => {
1667
+ if (!this.config.onlyLoad) {
1668
+ return;
1669
+ }
1670
+ const root = collab.yDoc.getMap('RootComponent');
1671
+ if (root.has('state')) {
1672
+ return;
1673
+ }
1674
+ return new Promise(resolve => {
1675
+ const testing = () => {
1676
+ if (root.has('state')) {
1677
+ resolve();
1678
+ }
1679
+ else {
1680
+ this.timer = setTimeout(testing, 1000);
1681
+ }
1682
+ };
1683
+ this.timer = setTimeout(testing, 1000);
1684
+ });
1685
+ });
1663
1686
  }
1664
1687
  onDestroy(textbus) {
1665
1688
  this.subscription.unsubscribe();
1666
1689
  textbus.get(Collaborate).destroy();
1667
1690
  textbus.get(History).destroy();
1668
1691
  textbus.get(SyncConnector).onDestroy();
1692
+ clearTimeout(this.timer);
1669
1693
  }
1670
1694
  }
1671
1695
 
@@ -1707,10 +1731,17 @@ class MultipleDocumentCollaborateModule {
1707
1731
  }
1708
1732
  ]
1709
1733
  });
1734
+ Object.defineProperty(this, "timer", {
1735
+ enumerable: true,
1736
+ configurable: true,
1737
+ writable: true,
1738
+ value: null
1739
+ });
1710
1740
  }
1711
1741
  setup(textbus) {
1712
1742
  const messageBus = textbus.get(MessageBus, null);
1713
1743
  const connector = textbus.get(SyncConnector);
1744
+ const collab = textbus.get(Collaborate);
1714
1745
  if (messageBus) {
1715
1746
  const selection = textbus.get(Selection);
1716
1747
  connector.setLocalStateField('message', messageBus.get(textbus));
@@ -1722,13 +1753,33 @@ class MultipleDocumentCollaborateModule {
1722
1753
  messageBus.consume(states, textbus);
1723
1754
  }));
1724
1755
  }
1725
- return connector.onLoad.toPromise();
1756
+ return connector.onLoad.toPromise().then(() => {
1757
+ if (!this.config.onlyLoad) {
1758
+ return;
1759
+ }
1760
+ const root = collab.yDoc.getMap('RootComponent');
1761
+ if (root.has('state')) {
1762
+ return;
1763
+ }
1764
+ return new Promise(resolve => {
1765
+ const testing = () => {
1766
+ if (root.has('state')) {
1767
+ resolve();
1768
+ }
1769
+ else {
1770
+ this.timer = setTimeout(testing, 1000);
1771
+ }
1772
+ };
1773
+ this.timer = setTimeout(testing, 1000);
1774
+ });
1775
+ });
1726
1776
  }
1727
1777
  onDestroy(textbus) {
1728
1778
  this.subscription.unsubscribe();
1729
1779
  textbus.get(Collaborate).destroy();
1730
1780
  textbus.get(History).destroy();
1731
1781
  textbus.get(SyncConnector).onDestroy();
1782
+ clearTimeout(this.timer);
1732
1783
  }
1733
1784
  }
1734
1785
 
package/bundles/index.js CHANGED
@@ -523,6 +523,8 @@ exports.Collaborate = class Collaborate {
523
523
  return;
524
524
  }
525
525
  const content = subDocument.getText('content');
526
+ const data = subDocument.getMap('data');
527
+ this.syncLocalMapToSharedMap(localSlot.data, data);
526
528
  this.initSharedSlotByLocalSlot(content, localSlot);
527
529
  this.syncSlot(content, localSlot);
528
530
  this.addSubModelEvent.next({
@@ -574,11 +576,13 @@ exports.Collaborate = class Collaborate {
574
576
  const schema = sharedSlot.getAttribute('schema');
575
577
  if (type === 'async') {
576
578
  const metadata = sharedSlot.getAttribute('metadata');
577
- const slot = new core.AsyncSlot(schema || [], {});
579
+ const slot = new core.AsyncSlot(schema || [], {}, {});
578
580
  this.syncSharedMapToLocalMap(metadata, slot.metadata);
579
581
  const loadedSubDocument = this.subModelLoader.getLoadedModelBySlot(slot);
580
582
  if (loadedSubDocument) {
581
583
  const subContent = loadedSubDocument.getText('content');
584
+ const data = loadedSubDocument.getMap('data');
585
+ this.syncLocalMapToSharedMap(slot, data);
582
586
  this.syncRootSlot(loadedSubDocument, subContent, slot);
583
587
  this.addSubModelEvent.next({
584
588
  yDoc: loadedSubDocument,
@@ -948,7 +952,7 @@ exports.CollabHistory = class CollabHistory {
948
952
  var _a;
949
953
  return ((_a = this.manager) === null || _a === void 0 ? void 0 : _a.canRedo()) || false;
950
954
  }
951
- constructor(rootComponentRef, collaborate, scheduler, selection, stackSize, undoManagerConfig) {
955
+ constructor(rootComponentRef, collaborate, scheduler, stackSize, undoManagerConfig) {
952
956
  Object.defineProperty(this, "rootComponentRef", {
953
957
  enumerable: true,
954
958
  configurable: true,
@@ -967,12 +971,6 @@ exports.CollabHistory = class CollabHistory {
967
971
  writable: true,
968
972
  value: scheduler
969
973
  });
970
- Object.defineProperty(this, "selection", {
971
- enumerable: true,
972
- configurable: true,
973
- writable: true,
974
- value: selection
975
- });
976
974
  Object.defineProperty(this, "stackSize", {
977
975
  enumerable: true,
978
976
  configurable: true,
@@ -1159,12 +1157,11 @@ exports.CollabHistory = class CollabHistory {
1159
1157
  };
1160
1158
  exports.CollabHistory = __decorate([
1161
1159
  core$1.Injectable(),
1162
- __param(4, core$1.Inject(core.HISTORY_STACK_SIZE)),
1163
- __param(5, core$1.Optional()),
1160
+ __param(3, core$1.Inject(core.HISTORY_STACK_SIZE)),
1161
+ __param(4, core$1.Optional()),
1164
1162
  __metadata("design:paramtypes", [core.RootComponentRef,
1165
1163
  exports.Collaborate,
1166
- core.Scheduler,
1167
- core.Selection, Number, CustomUndoManagerConfig])
1164
+ core.Scheduler, Number, CustomUndoManagerConfig])
1168
1165
  ], exports.CollabHistory);
1169
1166
 
1170
1167
  /**
@@ -1646,10 +1643,17 @@ class CollaborateModule {
1646
1643
  }
1647
1644
  ]
1648
1645
  });
1646
+ Object.defineProperty(this, "timer", {
1647
+ enumerable: true,
1648
+ configurable: true,
1649
+ writable: true,
1650
+ value: null
1651
+ });
1649
1652
  }
1650
1653
  setup(textbus) {
1651
1654
  const messageBus = textbus.get(MessageBus, null);
1652
1655
  const connector = textbus.get(SyncConnector);
1656
+ const collab = textbus.get(exports.Collaborate);
1653
1657
  if (messageBus) {
1654
1658
  const selection = textbus.get(core.Selection);
1655
1659
  connector.setLocalStateField('message', messageBus.get(textbus));
@@ -1661,13 +1665,33 @@ class CollaborateModule {
1661
1665
  messageBus.consume(states, textbus);
1662
1666
  }));
1663
1667
  }
1664
- return connector.onLoad.toPromise();
1668
+ return connector.onLoad.toPromise().then(() => {
1669
+ if (!this.config.onlyLoad) {
1670
+ return;
1671
+ }
1672
+ const root = collab.yDoc.getMap('RootComponent');
1673
+ if (root.has('state')) {
1674
+ return;
1675
+ }
1676
+ return new Promise(resolve => {
1677
+ const testing = () => {
1678
+ if (root.has('state')) {
1679
+ resolve();
1680
+ }
1681
+ else {
1682
+ this.timer = setTimeout(testing, 1000);
1683
+ }
1684
+ };
1685
+ this.timer = setTimeout(testing, 1000);
1686
+ });
1687
+ });
1665
1688
  }
1666
1689
  onDestroy(textbus) {
1667
1690
  this.subscription.unsubscribe();
1668
1691
  textbus.get(exports.Collaborate).destroy();
1669
1692
  textbus.get(core.History).destroy();
1670
1693
  textbus.get(SyncConnector).onDestroy();
1694
+ clearTimeout(this.timer);
1671
1695
  }
1672
1696
  }
1673
1697
 
@@ -1709,10 +1733,17 @@ class MultipleDocumentCollaborateModule {
1709
1733
  }
1710
1734
  ]
1711
1735
  });
1736
+ Object.defineProperty(this, "timer", {
1737
+ enumerable: true,
1738
+ configurable: true,
1739
+ writable: true,
1740
+ value: null
1741
+ });
1712
1742
  }
1713
1743
  setup(textbus) {
1714
1744
  const messageBus = textbus.get(MessageBus, null);
1715
1745
  const connector = textbus.get(SyncConnector);
1746
+ const collab = textbus.get(exports.Collaborate);
1716
1747
  if (messageBus) {
1717
1748
  const selection = textbus.get(core.Selection);
1718
1749
  connector.setLocalStateField('message', messageBus.get(textbus));
@@ -1724,13 +1755,33 @@ class MultipleDocumentCollaborateModule {
1724
1755
  messageBus.consume(states, textbus);
1725
1756
  }));
1726
1757
  }
1727
- return connector.onLoad.toPromise();
1758
+ return connector.onLoad.toPromise().then(() => {
1759
+ if (!this.config.onlyLoad) {
1760
+ return;
1761
+ }
1762
+ const root = collab.yDoc.getMap('RootComponent');
1763
+ if (root.has('state')) {
1764
+ return;
1765
+ }
1766
+ return new Promise(resolve => {
1767
+ const testing = () => {
1768
+ if (root.has('state')) {
1769
+ resolve();
1770
+ }
1771
+ else {
1772
+ this.timer = setTimeout(testing, 1000);
1773
+ }
1774
+ };
1775
+ this.timer = setTimeout(testing, 1000);
1776
+ });
1777
+ });
1728
1778
  }
1729
1779
  onDestroy(textbus) {
1730
1780
  this.subscription.unsubscribe();
1731
1781
  textbus.get(exports.Collaborate).destroy();
1732
1782
  textbus.get(core.History).destroy();
1733
1783
  textbus.get(SyncConnector).onDestroy();
1784
+ clearTimeout(this.timer);
1734
1785
  }
1735
1786
  }
1736
1787
 
@@ -9,6 +9,7 @@ export declare class MultipleDocumentCollaborateModule implements Module {
9
9
  config: MultipleDocCollaborateConfig;
10
10
  private subscription;
11
11
  providers: Provider[];
12
+ private timer;
12
13
  constructor(config: MultipleDocCollaborateConfig);
13
14
  setup(textbus: Textbus): Promise<(() => void) | void> | (() => void) | void;
14
15
  onDestroy(textbus: Textbus): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/collaborate",
3
- "version": "5.0.0-alpha.1",
3
+ "version": "5.0.0-alpha.3",
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",
@@ -27,16 +27,16 @@
27
27
  "dependencies": {
28
28
  "@hocuspocus/provider": "^2.15.2",
29
29
  "@tanbo/stream": "^1.2.7",
30
- "@textbus/core": "^5.0.0-alpha.1",
30
+ "@textbus/core": "^5.0.0-alpha.3",
31
31
  "@viewfly/core": "^2.0.0-alpha.3",
32
32
  "y-websocket": "^2.1.0",
33
33
  "yjs": "^13.6.23"
34
34
  },
35
35
  "devDependencies": {
36
- "@rollup/plugin-commonjs": "^23.0.2",
37
- "@rollup/plugin-typescript": "^9.0.2",
36
+ "@rollup/plugin-commonjs": "^28.0.2",
37
+ "@rollup/plugin-typescript": "^12.1.2",
38
38
  "rimraf": "^3.0.2",
39
- "rollup": "^3.2.5",
39
+ "rollup": "4.22.4",
40
40
  "tslib": "^2.4.1"
41
41
  },
42
42
  "author": {
@@ -50,5 +50,5 @@
50
50
  "bugs": {
51
51
  "url": "https://github.com/textbus/textbus.git/issues"
52
52
  },
53
- "gitHead": "97fad583844a41a761a107ff8500039c178ec321"
53
+ "gitHead": "4635f5529f7a807e59d11a933ed27c114e6106e6"
54
54
  }