@textbus/collaborate 3.1.13 → 3.1.14

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.
@@ -22,6 +22,10 @@ export declare abstract class CustomUndoManagerConfig {
22
22
  abstract captureTransaction?(arg0: Transaction): boolean;
23
23
  abstract deleteFilter?(arg0: Item): boolean;
24
24
  }
25
+ interface CollaborateHistorySelectionPosition {
26
+ before: CursorPosition | null;
27
+ after: CursorPosition | null;
28
+ }
25
29
  export declare class Collaborate implements History {
26
30
  protected stackSize: number;
27
31
  protected rootComponentRef: RootComponentRef;
@@ -55,7 +59,7 @@ export declare class Collaborate implements History {
55
59
  protected contentMap: ContentMap;
56
60
  protected updateRemoteActions: Array<UpdateItem>;
57
61
  protected noRecord: {};
58
- protected historyItems: Array<CursorPosition | null>;
62
+ protected historyItems: Array<CollaborateHistorySelectionPosition>;
59
63
  protected index: number;
60
64
  constructor(stackSize: number, rootComponentRef: RootComponentRef, controller: Controller, scheduler: Scheduler, registry: Registry, selection: Selection, starter: Starter, undoManagerConfig: CustomUndoManagerConfig);
61
65
  listen(): void;
@@ -137,7 +137,10 @@ let Collaborate = class Collaborate {
137
137
  }
138
138
  });
139
139
  this.manager = manager;
140
- // manager.on()
140
+ let beforePosition = null;
141
+ this.subscriptions.push(this.scheduler.onLocalChangeBefore.subscribe(() => {
142
+ beforePosition = this.getRelativeCursorLocation();
143
+ }));
141
144
  manager.on('stack-item-added', event => {
142
145
  if (event.type === 'undo') {
143
146
  if (event.origin === manager) {
@@ -145,7 +148,10 @@ let Collaborate = class Collaborate {
145
148
  }
146
149
  else {
147
150
  this.historyItems.length = this.index;
148
- this.historyItems.push(this.getRelativeCursorLocation());
151
+ this.historyItems.push({
152
+ before: beforePosition,
153
+ after: this.getRelativeCursorLocation()
154
+ });
149
155
  this.index++;
150
156
  }
151
157
  }
@@ -161,10 +167,12 @@ let Collaborate = class Collaborate {
161
167
  }
162
168
  this.changeEvent.next();
163
169
  });
164
- manager.on('stack-item-popped', () => {
165
- const position = this.historyItems[this.index - 1];
166
- if (position) {
167
- const selection = this.getAbstractSelection(position);
170
+ manager.on('stack-item-popped', (ev) => {
171
+ const index = ev.type === 'undo' ? this.index : this.index - 1;
172
+ const position = this.historyItems[index] || null;
173
+ const p = ev.type === 'undo' ? position === null || position === void 0 ? void 0 : position.before : position === null || position === void 0 ? void 0 : position.after;
174
+ if (p) {
175
+ const selection = this.getAbstractSelection(p);
168
176
  if (selection) {
169
177
  this.selection.setBaseAndExtent(selection.anchorSlot, selection.anchorOffset, selection.focusSlot, selection.focusOffset);
170
178
  return;
@@ -172,10 +180,7 @@ let Collaborate = class Collaborate {
172
180
  }
173
181
  this.selection.unSelect();
174
182
  });
175
- this.subscriptions.push(this.scheduler.onDocFirstChangeFromLocal.subscribe(() => {
176
- this.historyItems.push(this.getRelativeCursorLocation());
177
- this.index++;
178
- }), this.selection.onChange.subscribe(() => {
183
+ this.subscriptions.push(this.selection.onChange.subscribe(() => {
179
184
  const paths = this.selection.getPaths();
180
185
  this.selectionChangeEvent.next(paths);
181
186
  }), this.scheduler.onDocChanged.pipe(map(item => {
package/bundles/index.js CHANGED
@@ -139,7 +139,10 @@ exports.Collaborate = class Collaborate {
139
139
  }
140
140
  });
141
141
  this.manager = manager;
142
- // manager.on()
142
+ let beforePosition = null;
143
+ this.subscriptions.push(this.scheduler.onLocalChangeBefore.subscribe(() => {
144
+ beforePosition = this.getRelativeCursorLocation();
145
+ }));
143
146
  manager.on('stack-item-added', event => {
144
147
  if (event.type === 'undo') {
145
148
  if (event.origin === manager) {
@@ -147,7 +150,10 @@ exports.Collaborate = class Collaborate {
147
150
  }
148
151
  else {
149
152
  this.historyItems.length = this.index;
150
- this.historyItems.push(this.getRelativeCursorLocation());
153
+ this.historyItems.push({
154
+ before: beforePosition,
155
+ after: this.getRelativeCursorLocation()
156
+ });
151
157
  this.index++;
152
158
  }
153
159
  }
@@ -163,10 +169,12 @@ exports.Collaborate = class Collaborate {
163
169
  }
164
170
  this.changeEvent.next();
165
171
  });
166
- manager.on('stack-item-popped', () => {
167
- const position = this.historyItems[this.index - 1];
168
- if (position) {
169
- const selection = this.getAbstractSelection(position);
172
+ manager.on('stack-item-popped', (ev) => {
173
+ const index = ev.type === 'undo' ? this.index : this.index - 1;
174
+ const position = this.historyItems[index] || null;
175
+ const p = ev.type === 'undo' ? position === null || position === void 0 ? void 0 : position.before : position === null || position === void 0 ? void 0 : position.after;
176
+ if (p) {
177
+ const selection = this.getAbstractSelection(p);
170
178
  if (selection) {
171
179
  this.selection.setBaseAndExtent(selection.anchorSlot, selection.anchorOffset, selection.focusSlot, selection.focusOffset);
172
180
  return;
@@ -174,10 +182,7 @@ exports.Collaborate = class Collaborate {
174
182
  }
175
183
  this.selection.unSelect();
176
184
  });
177
- this.subscriptions.push(this.scheduler.onDocFirstChangeFromLocal.subscribe(() => {
178
- this.historyItems.push(this.getRelativeCursorLocation());
179
- this.index++;
180
- }), this.selection.onChange.subscribe(() => {
185
+ this.subscriptions.push(this.selection.onChange.subscribe(() => {
181
186
  const paths = this.selection.getPaths();
182
187
  this.selectionChangeEvent.next(paths);
183
188
  }), this.scheduler.onDocChanged.pipe(stream.map(item => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/collaborate",
3
- "version": "3.1.13",
3
+ "version": "3.1.14",
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.1.13",
30
+ "@textbus/core": "^3.1.14",
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": "55f6225a13070e5dd341cff13a3afc9e43dc104e"
53
+ "gitHead": "1f3f8dffa66c941bcfda75215e662c24584a2546"
54
54
  }