@textbus/collaborate 3.0.0-alpha.61 → 3.0.0-alpha.63

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  import { Observable, Subject, Subscription } from '@tanbo/stream';
2
2
  import { AbstractSelection, ComponentInstance, Controller, Registry, History, RootComponentRef, Scheduler, Selection, SelectionPaths, Slot, Starter } from '@textbus/core';
3
- import { Array as YArray, Doc as YDoc, Map as YMap, RelativePosition, Text as YText, Transaction, UndoManager } from 'yjs';
3
+ import { Array as YArray, Doc as YDoc, Map as YMap, RelativePosition, Text as YText, Transaction, UndoManager, Item } from 'yjs';
4
4
  interface CursorPosition {
5
5
  anchor: RelativePosition;
6
6
  focus: RelativePosition;
@@ -18,6 +18,10 @@ interface UpdateItem {
18
18
  record: boolean;
19
19
  action(): void;
20
20
  }
21
+ export declare abstract class CustomUndoManagerConfig {
22
+ abstract captureTransaction?(arg0: Transaction): boolean;
23
+ abstract deleteFilter?(arg0: Item): boolean;
24
+ }
21
25
  export declare class Collaborate implements History {
22
26
  protected stackSize: number;
23
27
  protected rootComponentRef: RootComponentRef;
@@ -26,6 +30,7 @@ export declare class Collaborate implements History {
26
30
  protected registry: Registry;
27
31
  protected selection: Selection;
28
32
  protected starter: Starter;
33
+ protected undoManagerConfig: CustomUndoManagerConfig;
29
34
  onLocalChangesApplied: Observable<void>;
30
35
  yDoc: YDoc;
31
36
  onBack: Observable<void>;
@@ -52,7 +57,7 @@ export declare class Collaborate implements History {
52
57
  protected noRecord: {};
53
58
  protected historyItems: Array<CursorPosition | null>;
54
59
  protected index: number;
55
- constructor(stackSize: number, rootComponentRef: RootComponentRef, controller: Controller, scheduler: Scheduler, registry: Registry, selection: Selection, starter: Starter);
60
+ constructor(stackSize: number, rootComponentRef: RootComponentRef, controller: Controller, scheduler: Scheduler, registry: Registry, selection: Selection, starter: Starter, undoManagerConfig: CustomUndoManagerConfig);
56
61
  listen(): void;
57
62
  back(): void;
58
63
  forward(): void;
@@ -1,5 +1,5 @@
1
1
  import { makeError, HISTORY_STACK_SIZE, ChangeOrigin, Slot, RootComponentRef, Controller, Scheduler, Registry, Selection, Starter, History } from '@textbus/core';
2
- import { Injectable, Inject } from '@tanbo/di';
2
+ import { Injectable, Inject, Optional } from '@tanbo/di';
3
3
  import { Subject, map, filter } from '@tanbo/stream';
4
4
  import { Doc, UndoManager, Array, createAbsolutePositionFromRelativePosition, createRelativePositionFromTypeIndex, Map, Text } from 'yjs';
5
5
 
@@ -72,6 +72,8 @@ class ContentMap {
72
72
  }
73
73
  }
74
74
  }
75
+ class CustomUndoManagerConfig {
76
+ }
75
77
  let Collaborate = class Collaborate {
76
78
  get canBack() {
77
79
  var _a;
@@ -81,7 +83,7 @@ let Collaborate = class Collaborate {
81
83
  var _a;
82
84
  return ((_a = this.manager) === null || _a === void 0 ? void 0 : _a.canRedo()) || false;
83
85
  }
84
- constructor(stackSize, rootComponentRef, controller, scheduler, registry, selection, starter) {
86
+ constructor(stackSize, rootComponentRef, controller, scheduler, registry, selection, starter, undoManagerConfig) {
85
87
  this.stackSize = stackSize;
86
88
  this.rootComponentRef = rootComponentRef;
87
89
  this.controller = controller;
@@ -89,6 +91,7 @@ let Collaborate = class Collaborate {
89
91
  this.registry = registry;
90
92
  this.selection = selection;
91
93
  this.starter = starter;
94
+ this.undoManagerConfig = undoManagerConfig;
92
95
  this.yDoc = new Doc();
93
96
  this.backEvent = new Subject();
94
97
  this.forwardEvent = new Subject();
@@ -117,8 +120,21 @@ let Collaborate = class Collaborate {
117
120
  listen() {
118
121
  const root = this.yDoc.getMap('RootComponent');
119
122
  const rootComponent = this.rootComponentRef.component;
123
+ const undoManagerConfig = this.undoManagerConfig || {};
120
124
  const manager = new UndoManager(root, {
121
- trackedOrigins: new Set([this.yDoc])
125
+ trackedOrigins: new Set([this.yDoc]),
126
+ captureTransaction(arg) {
127
+ if (undoManagerConfig.captureTransaction) {
128
+ return undoManagerConfig.captureTransaction(arg);
129
+ }
130
+ return true;
131
+ },
132
+ deleteFilter(item) {
133
+ if (undoManagerConfig.deleteFilter) {
134
+ return undoManagerConfig.deleteFilter(item);
135
+ }
136
+ return true;
137
+ }
122
138
  });
123
139
  this.manager = manager;
124
140
  manager.on('stack-item-added', event => {
@@ -724,12 +740,14 @@ let Collaborate = class Collaborate {
724
740
  Collaborate = __decorate([
725
741
  Injectable(),
726
742
  __param(0, Inject(HISTORY_STACK_SIZE)),
743
+ __param(7, Optional()),
727
744
  __metadata("design:paramtypes", [Number, RootComponentRef,
728
745
  Controller,
729
746
  Scheduler,
730
747
  Registry,
731
748
  Selection,
732
- Starter])
749
+ Starter,
750
+ CustomUndoManagerConfig])
733
751
  ], Collaborate);
734
752
  function remoteFormatsToLocal(registry, attrs) {
735
753
  const formats = [];
@@ -754,4 +772,4 @@ const collaborateModule = {
754
772
  ]
755
773
  };
756
774
 
757
- export { Collaborate, collaborateModule };
775
+ export { Collaborate, CustomUndoManagerConfig, collaborateModule };
package/bundles/index.js CHANGED
@@ -74,6 +74,8 @@ class ContentMap {
74
74
  }
75
75
  }
76
76
  }
77
+ class CustomUndoManagerConfig {
78
+ }
77
79
  exports.Collaborate = class Collaborate {
78
80
  get canBack() {
79
81
  var _a;
@@ -83,7 +85,7 @@ exports.Collaborate = class Collaborate {
83
85
  var _a;
84
86
  return ((_a = this.manager) === null || _a === void 0 ? void 0 : _a.canRedo()) || false;
85
87
  }
86
- constructor(stackSize, rootComponentRef, controller, scheduler, registry, selection, starter) {
88
+ constructor(stackSize, rootComponentRef, controller, scheduler, registry, selection, starter, undoManagerConfig) {
87
89
  this.stackSize = stackSize;
88
90
  this.rootComponentRef = rootComponentRef;
89
91
  this.controller = controller;
@@ -91,6 +93,7 @@ exports.Collaborate = class Collaborate {
91
93
  this.registry = registry;
92
94
  this.selection = selection;
93
95
  this.starter = starter;
96
+ this.undoManagerConfig = undoManagerConfig;
94
97
  this.yDoc = new yjs.Doc();
95
98
  this.backEvent = new stream.Subject();
96
99
  this.forwardEvent = new stream.Subject();
@@ -119,8 +122,21 @@ exports.Collaborate = class Collaborate {
119
122
  listen() {
120
123
  const root = this.yDoc.getMap('RootComponent');
121
124
  const rootComponent = this.rootComponentRef.component;
125
+ const undoManagerConfig = this.undoManagerConfig || {};
122
126
  const manager = new yjs.UndoManager(root, {
123
- trackedOrigins: new Set([this.yDoc])
127
+ trackedOrigins: new Set([this.yDoc]),
128
+ captureTransaction(arg) {
129
+ if (undoManagerConfig.captureTransaction) {
130
+ return undoManagerConfig.captureTransaction(arg);
131
+ }
132
+ return true;
133
+ },
134
+ deleteFilter(item) {
135
+ if (undoManagerConfig.deleteFilter) {
136
+ return undoManagerConfig.deleteFilter(item);
137
+ }
138
+ return true;
139
+ }
124
140
  });
125
141
  this.manager = manager;
126
142
  manager.on('stack-item-added', event => {
@@ -726,12 +742,14 @@ exports.Collaborate = class Collaborate {
726
742
  exports.Collaborate = __decorate([
727
743
  di.Injectable(),
728
744
  __param(0, di.Inject(core.HISTORY_STACK_SIZE)),
745
+ __param(7, di.Optional()),
729
746
  __metadata("design:paramtypes", [Number, core.RootComponentRef,
730
747
  core.Controller,
731
748
  core.Scheduler,
732
749
  core.Registry,
733
750
  core.Selection,
734
- core.Starter])
751
+ core.Starter,
752
+ CustomUndoManagerConfig])
735
753
  ], exports.Collaborate);
736
754
  function remoteFormatsToLocal(registry, attrs) {
737
755
  const formats = [];
@@ -756,4 +774,5 @@ const collaborateModule = {
756
774
  ]
757
775
  };
758
776
 
777
+ exports.CustomUndoManagerConfig = CustomUndoManagerConfig;
759
778
  exports.collaborateModule = collaborateModule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/collaborate",
3
- "version": "3.0.0-alpha.61",
3
+ "version": "3.0.0-alpha.63",
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,7 +27,7 @@
27
27
  "dependencies": {
28
28
  "@tanbo/di": "^1.1.4",
29
29
  "@tanbo/stream": "^1.1.9",
30
- "@textbus/core": "^3.0.0-alpha.61",
30
+ "@textbus/core": "^3.0.0-alpha.63",
31
31
  "reflect-metadata": "^0.1.13",
32
32
  "y-protocols": "^1.0.5",
33
33
  "yjs": "^13.5.39"
@@ -50,5 +50,5 @@
50
50
  "bugs": {
51
51
  "url": "https://github.com/textbus/textbus.git/issues"
52
52
  },
53
- "gitHead": "c0f71b405d8cda435160e49485cc1f9f41acfeb4"
53
+ "gitHead": "9c0f1a319c7bd73094c8b670af401f3da06533f1"
54
54
  }