@knotx/plugins-history 0.2.8 → 0.2.10
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.
- package/dist/index.cjs +31 -11
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +32 -12
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -78,9 +78,9 @@ class History extends (_a = core.BasePlugin, _canUndo_dec = [decorators.register
|
|
|
78
78
|
super(...arguments);
|
|
79
79
|
__runInitializers(_init, 5, this);
|
|
80
80
|
__publicField(this, "name", "history");
|
|
81
|
+
__publicField(this, "isUndoRedo", false);
|
|
81
82
|
__publicField(this, "history", []);
|
|
82
83
|
__publicField(this, "currentIndex", -1);
|
|
83
|
-
__publicField(this, "isUndoRedo", false);
|
|
84
84
|
__publicField(this, "maxHistory");
|
|
85
85
|
__publicField(this, "tagMap", /* @__PURE__ */ new Map());
|
|
86
86
|
__publicField(this, "operationBuffer", {});
|
|
@@ -180,6 +180,9 @@ class History extends (_a = core.BasePlugin, _canUndo_dec = [decorators.register
|
|
|
180
180
|
return operation;
|
|
181
181
|
}
|
|
182
182
|
pushHistory(state) {
|
|
183
|
+
if (Object.values(state.value).every((operations) => operations.every(core.isEmptyBatchOperation))) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
183
186
|
if (this.currentIndex < this.history.length - 1) {
|
|
184
187
|
this.history = this.history.slice(0, this.currentIndex + 1);
|
|
185
188
|
}
|
|
@@ -206,10 +209,13 @@ class History extends (_a = core.BasePlugin, _canUndo_dec = [decorators.register
|
|
|
206
209
|
const dataManager = this.dataManagers.get(key);
|
|
207
210
|
if (!dataManager)
|
|
208
211
|
return;
|
|
209
|
-
this.reverseOperation(
|
|
212
|
+
const reverseOperations = this.reverseOperation({
|
|
210
213
|
type: "batch",
|
|
211
214
|
operations: core.flattenOperations(operations)
|
|
212
215
|
});
|
|
216
|
+
if (reverseOperations) {
|
|
217
|
+
dataManager.dispatch(reverseOperations);
|
|
218
|
+
}
|
|
213
219
|
});
|
|
214
220
|
this.currentIndex--;
|
|
215
221
|
this.updateCanUndoRedo();
|
|
@@ -284,28 +290,42 @@ class History extends (_a = core.BasePlugin, _canUndo_dec = [decorators.register
|
|
|
284
290
|
}
|
|
285
291
|
return stateIndex;
|
|
286
292
|
}
|
|
287
|
-
reverseOperation(
|
|
293
|
+
reverseOperation(operation) {
|
|
288
294
|
switch (operation.type) {
|
|
289
295
|
case "add":
|
|
290
|
-
|
|
291
|
-
break;
|
|
296
|
+
return { type: "remove", id: operation.data.id };
|
|
292
297
|
case "remove":
|
|
293
298
|
if (operation.removedNode) {
|
|
294
|
-
|
|
299
|
+
return { type: "add", data: operation.removedNode };
|
|
295
300
|
}
|
|
296
301
|
break;
|
|
297
302
|
case "update":
|
|
298
303
|
if (operation.originalData) {
|
|
299
|
-
|
|
304
|
+
return {
|
|
300
305
|
type: "update",
|
|
301
306
|
id: operation.id,
|
|
302
307
|
data: operation.originalData
|
|
303
|
-
}
|
|
308
|
+
};
|
|
304
309
|
}
|
|
305
310
|
break;
|
|
306
|
-
case "batch":
|
|
307
|
-
|
|
308
|
-
|
|
311
|
+
case "batch": {
|
|
312
|
+
const operations = [];
|
|
313
|
+
for (const op of operation.operations.reverse()) {
|
|
314
|
+
const reverseOperation = this.reverseOperation(op);
|
|
315
|
+
if (reverseOperation) {
|
|
316
|
+
operations.push(reverseOperation);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (operations.length > 0) {
|
|
320
|
+
return {
|
|
321
|
+
type: "batch",
|
|
322
|
+
operations
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
return void 0;
|
|
326
|
+
}
|
|
327
|
+
default:
|
|
328
|
+
return void 0;
|
|
309
329
|
}
|
|
310
330
|
}
|
|
311
331
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -11,6 +11,7 @@ declare module '@knotx/core' {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
interface IHistory {
|
|
14
|
+
isUndoRedo: boolean;
|
|
14
15
|
undo: () => void;
|
|
15
16
|
redo: () => void;
|
|
16
17
|
addTag: (tag: string) => void;
|
|
@@ -33,9 +34,9 @@ interface HistoryConfig {
|
|
|
33
34
|
}
|
|
34
35
|
declare class History<T extends Record<string, IData> = Record<string, any>> extends BasePlugin<'history', HistoryConfig> {
|
|
35
36
|
name: "history";
|
|
37
|
+
isUndoRedo: boolean;
|
|
36
38
|
private history;
|
|
37
39
|
private currentIndex;
|
|
38
|
-
private isUndoRedo;
|
|
39
40
|
private maxHistory;
|
|
40
41
|
private tagMap;
|
|
41
42
|
private operationBuffer;
|
package/dist/index.d.mts
CHANGED
|
@@ -11,6 +11,7 @@ declare module '@knotx/core' {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
interface IHistory {
|
|
14
|
+
isUndoRedo: boolean;
|
|
14
15
|
undo: () => void;
|
|
15
16
|
redo: () => void;
|
|
16
17
|
addTag: (tag: string) => void;
|
|
@@ -33,9 +34,9 @@ interface HistoryConfig {
|
|
|
33
34
|
}
|
|
34
35
|
declare class History<T extends Record<string, IData> = Record<string, any>> extends BasePlugin<'history', HistoryConfig> {
|
|
35
36
|
name: "history";
|
|
37
|
+
isUndoRedo: boolean;
|
|
36
38
|
private history;
|
|
37
39
|
private currentIndex;
|
|
38
|
-
private isUndoRedo;
|
|
39
40
|
private maxHistory;
|
|
40
41
|
private tagMap;
|
|
41
42
|
private operationBuffer;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ declare module '@knotx/core' {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
interface IHistory {
|
|
14
|
+
isUndoRedo: boolean;
|
|
14
15
|
undo: () => void;
|
|
15
16
|
redo: () => void;
|
|
16
17
|
addTag: (tag: string) => void;
|
|
@@ -33,9 +34,9 @@ interface HistoryConfig {
|
|
|
33
34
|
}
|
|
34
35
|
declare class History<T extends Record<string, IData> = Record<string, any>> extends BasePlugin<'history', HistoryConfig> {
|
|
35
36
|
name: "history";
|
|
37
|
+
isUndoRedo: boolean;
|
|
36
38
|
private history;
|
|
37
39
|
private currentIndex;
|
|
38
|
-
private isUndoRedo;
|
|
39
40
|
private maxHistory;
|
|
40
41
|
private tagMap;
|
|
41
42
|
private operationBuffer;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isDraftOperation, isInitOperation, flattenOperations, BasePlugin } from '@knotx/core';
|
|
1
|
+
import { isDraftOperation, isInitOperation, isEmptyBatchOperation, flattenOperations, BasePlugin } from '@knotx/core';
|
|
2
2
|
import { register, inject, OnInit, OnDestroy } from '@knotx/decorators';
|
|
3
3
|
import { Subject, tap, debounceTime, pipe } from 'rxjs';
|
|
4
4
|
|
|
@@ -76,9 +76,9 @@ class History extends (_a = BasePlugin, _canUndo_dec = [register("canUndo")], _c
|
|
|
76
76
|
super(...arguments);
|
|
77
77
|
__runInitializers(_init, 5, this);
|
|
78
78
|
__publicField(this, "name", "history");
|
|
79
|
+
__publicField(this, "isUndoRedo", false);
|
|
79
80
|
__publicField(this, "history", []);
|
|
80
81
|
__publicField(this, "currentIndex", -1);
|
|
81
|
-
__publicField(this, "isUndoRedo", false);
|
|
82
82
|
__publicField(this, "maxHistory");
|
|
83
83
|
__publicField(this, "tagMap", /* @__PURE__ */ new Map());
|
|
84
84
|
__publicField(this, "operationBuffer", {});
|
|
@@ -178,6 +178,9 @@ class History extends (_a = BasePlugin, _canUndo_dec = [register("canUndo")], _c
|
|
|
178
178
|
return operation;
|
|
179
179
|
}
|
|
180
180
|
pushHistory(state) {
|
|
181
|
+
if (Object.values(state.value).every((operations) => operations.every(isEmptyBatchOperation))) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
181
184
|
if (this.currentIndex < this.history.length - 1) {
|
|
182
185
|
this.history = this.history.slice(0, this.currentIndex + 1);
|
|
183
186
|
}
|
|
@@ -204,10 +207,13 @@ class History extends (_a = BasePlugin, _canUndo_dec = [register("canUndo")], _c
|
|
|
204
207
|
const dataManager = this.dataManagers.get(key);
|
|
205
208
|
if (!dataManager)
|
|
206
209
|
return;
|
|
207
|
-
this.reverseOperation(
|
|
210
|
+
const reverseOperations = this.reverseOperation({
|
|
208
211
|
type: "batch",
|
|
209
212
|
operations: flattenOperations(operations)
|
|
210
213
|
});
|
|
214
|
+
if (reverseOperations) {
|
|
215
|
+
dataManager.dispatch(reverseOperations);
|
|
216
|
+
}
|
|
211
217
|
});
|
|
212
218
|
this.currentIndex--;
|
|
213
219
|
this.updateCanUndoRedo();
|
|
@@ -282,28 +288,42 @@ class History extends (_a = BasePlugin, _canUndo_dec = [register("canUndo")], _c
|
|
|
282
288
|
}
|
|
283
289
|
return stateIndex;
|
|
284
290
|
}
|
|
285
|
-
reverseOperation(
|
|
291
|
+
reverseOperation(operation) {
|
|
286
292
|
switch (operation.type) {
|
|
287
293
|
case "add":
|
|
288
|
-
|
|
289
|
-
break;
|
|
294
|
+
return { type: "remove", id: operation.data.id };
|
|
290
295
|
case "remove":
|
|
291
296
|
if (operation.removedNode) {
|
|
292
|
-
|
|
297
|
+
return { type: "add", data: operation.removedNode };
|
|
293
298
|
}
|
|
294
299
|
break;
|
|
295
300
|
case "update":
|
|
296
301
|
if (operation.originalData) {
|
|
297
|
-
|
|
302
|
+
return {
|
|
298
303
|
type: "update",
|
|
299
304
|
id: operation.id,
|
|
300
305
|
data: operation.originalData
|
|
301
|
-
}
|
|
306
|
+
};
|
|
302
307
|
}
|
|
303
308
|
break;
|
|
304
|
-
case "batch":
|
|
305
|
-
|
|
306
|
-
|
|
309
|
+
case "batch": {
|
|
310
|
+
const operations = [];
|
|
311
|
+
for (const op of operation.operations.reverse()) {
|
|
312
|
+
const reverseOperation = this.reverseOperation(op);
|
|
313
|
+
if (reverseOperation) {
|
|
314
|
+
operations.push(reverseOperation);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (operations.length > 0) {
|
|
318
|
+
return {
|
|
319
|
+
type: "batch",
|
|
320
|
+
operations
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
return void 0;
|
|
324
|
+
}
|
|
325
|
+
default:
|
|
326
|
+
return void 0;
|
|
307
327
|
}
|
|
308
328
|
}
|
|
309
329
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/plugins-history",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "History Plugin for Knotx",
|
|
5
5
|
"author": "boenfu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"rxjs": "^7.8.1",
|
|
32
|
-
"@knotx/core": "0.2.
|
|
33
|
-
"@knotx/decorators": "0.2.
|
|
32
|
+
"@knotx/core": "0.2.8",
|
|
33
|
+
"@knotx/decorators": "0.2.8"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@knotx/build-config": "0.2.
|
|
37
|
-
"@knotx/eslint-config": "0.2.
|
|
38
|
-
"@knotx/typescript-config": "0.2.
|
|
36
|
+
"@knotx/build-config": "0.2.8",
|
|
37
|
+
"@knotx/eslint-config": "0.2.8",
|
|
38
|
+
"@knotx/typescript-config": "0.2.8"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "unbuild",
|