@knotx/plugins-history 0.2.8 → 0.2.9
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 +27 -10
- package/dist/index.js +27 -10
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -206,10 +206,13 @@ class History extends (_a = core.BasePlugin, _canUndo_dec = [decorators.register
|
|
|
206
206
|
const dataManager = this.dataManagers.get(key);
|
|
207
207
|
if (!dataManager)
|
|
208
208
|
return;
|
|
209
|
-
this.reverseOperation(
|
|
209
|
+
const reverseOperations = this.reverseOperation({
|
|
210
210
|
type: "batch",
|
|
211
211
|
operations: core.flattenOperations(operations)
|
|
212
212
|
});
|
|
213
|
+
if (reverseOperations) {
|
|
214
|
+
dataManager.dispatch(reverseOperations);
|
|
215
|
+
}
|
|
213
216
|
});
|
|
214
217
|
this.currentIndex--;
|
|
215
218
|
this.updateCanUndoRedo();
|
|
@@ -284,28 +287,42 @@ class History extends (_a = core.BasePlugin, _canUndo_dec = [decorators.register
|
|
|
284
287
|
}
|
|
285
288
|
return stateIndex;
|
|
286
289
|
}
|
|
287
|
-
reverseOperation(
|
|
290
|
+
reverseOperation(operation) {
|
|
288
291
|
switch (operation.type) {
|
|
289
292
|
case "add":
|
|
290
|
-
|
|
291
|
-
break;
|
|
293
|
+
return { type: "remove", id: operation.data.id };
|
|
292
294
|
case "remove":
|
|
293
295
|
if (operation.removedNode) {
|
|
294
|
-
|
|
296
|
+
return { type: "add", data: operation.removedNode };
|
|
295
297
|
}
|
|
296
298
|
break;
|
|
297
299
|
case "update":
|
|
298
300
|
if (operation.originalData) {
|
|
299
|
-
|
|
301
|
+
return {
|
|
300
302
|
type: "update",
|
|
301
303
|
id: operation.id,
|
|
302
304
|
data: operation.originalData
|
|
303
|
-
}
|
|
305
|
+
};
|
|
304
306
|
}
|
|
305
307
|
break;
|
|
306
|
-
case "batch":
|
|
307
|
-
|
|
308
|
-
|
|
308
|
+
case "batch": {
|
|
309
|
+
const operations = [];
|
|
310
|
+
for (const op of operation.operations.reverse()) {
|
|
311
|
+
const reverseOperation = this.reverseOperation(op);
|
|
312
|
+
if (reverseOperation) {
|
|
313
|
+
operations.push(reverseOperation);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (operations.length > 0) {
|
|
317
|
+
return {
|
|
318
|
+
type: "batch",
|
|
319
|
+
operations
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return void 0;
|
|
323
|
+
}
|
|
324
|
+
default:
|
|
325
|
+
return void 0;
|
|
309
326
|
}
|
|
310
327
|
}
|
|
311
328
|
/**
|
package/dist/index.js
CHANGED
|
@@ -204,10 +204,13 @@ class History extends (_a = BasePlugin, _canUndo_dec = [register("canUndo")], _c
|
|
|
204
204
|
const dataManager = this.dataManagers.get(key);
|
|
205
205
|
if (!dataManager)
|
|
206
206
|
return;
|
|
207
|
-
this.reverseOperation(
|
|
207
|
+
const reverseOperations = this.reverseOperation({
|
|
208
208
|
type: "batch",
|
|
209
209
|
operations: flattenOperations(operations)
|
|
210
210
|
});
|
|
211
|
+
if (reverseOperations) {
|
|
212
|
+
dataManager.dispatch(reverseOperations);
|
|
213
|
+
}
|
|
211
214
|
});
|
|
212
215
|
this.currentIndex--;
|
|
213
216
|
this.updateCanUndoRedo();
|
|
@@ -282,28 +285,42 @@ class History extends (_a = BasePlugin, _canUndo_dec = [register("canUndo")], _c
|
|
|
282
285
|
}
|
|
283
286
|
return stateIndex;
|
|
284
287
|
}
|
|
285
|
-
reverseOperation(
|
|
288
|
+
reverseOperation(operation) {
|
|
286
289
|
switch (operation.type) {
|
|
287
290
|
case "add":
|
|
288
|
-
|
|
289
|
-
break;
|
|
291
|
+
return { type: "remove", id: operation.data.id };
|
|
290
292
|
case "remove":
|
|
291
293
|
if (operation.removedNode) {
|
|
292
|
-
|
|
294
|
+
return { type: "add", data: operation.removedNode };
|
|
293
295
|
}
|
|
294
296
|
break;
|
|
295
297
|
case "update":
|
|
296
298
|
if (operation.originalData) {
|
|
297
|
-
|
|
299
|
+
return {
|
|
298
300
|
type: "update",
|
|
299
301
|
id: operation.id,
|
|
300
302
|
data: operation.originalData
|
|
301
|
-
}
|
|
303
|
+
};
|
|
302
304
|
}
|
|
303
305
|
break;
|
|
304
|
-
case "batch":
|
|
305
|
-
|
|
306
|
-
|
|
306
|
+
case "batch": {
|
|
307
|
+
const operations = [];
|
|
308
|
+
for (const op of operation.operations.reverse()) {
|
|
309
|
+
const reverseOperation = this.reverseOperation(op);
|
|
310
|
+
if (reverseOperation) {
|
|
311
|
+
operations.push(reverseOperation);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (operations.length > 0) {
|
|
315
|
+
return {
|
|
316
|
+
type: "batch",
|
|
317
|
+
operations
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
return void 0;
|
|
321
|
+
}
|
|
322
|
+
default:
|
|
323
|
+
return void 0;
|
|
307
324
|
}
|
|
308
325
|
}
|
|
309
326
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/plugins-history",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
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/
|
|
33
|
-
"@knotx/
|
|
32
|
+
"@knotx/decorators": "0.2.7",
|
|
33
|
+
"@knotx/core": "0.2.7"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@knotx/build-config": "0.2.7",
|
|
37
36
|
"@knotx/eslint-config": "0.2.7",
|
|
38
|
-
"@knotx/typescript-config": "0.2.7"
|
|
37
|
+
"@knotx/typescript-config": "0.2.7",
|
|
38
|
+
"@knotx/build-config": "0.2.7"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "unbuild",
|