canvas-editor-engine 1.0.83 → 1.0.85
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/services/through-history.service.d.ts +8 -0
- package/dist/services/through-history.service.js +23 -0
- package/dist/store/history.state.d.ts +2 -2
- package/dist/store/history.state.js +42 -14
- package/dist/store/image.state.js +1 -1
- package/dist/types/history.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const store_1 = require("../store/store");
|
|
4
|
+
class ThroughHistoryService {
|
|
5
|
+
static cache = [];
|
|
6
|
+
static current() {
|
|
7
|
+
const history = store_1.default.store.historyState.historyLines;
|
|
8
|
+
const lastIndex = history.length - 1;
|
|
9
|
+
return history[lastIndex];
|
|
10
|
+
}
|
|
11
|
+
static undo() {
|
|
12
|
+
store_1.default.store.historyState.reduce('UNDO');
|
|
13
|
+
}
|
|
14
|
+
;
|
|
15
|
+
static redo() {
|
|
16
|
+
store_1.default.store.historyState.reduce('REDO', ThroughHistoryService.cache.shift());
|
|
17
|
+
}
|
|
18
|
+
;
|
|
19
|
+
static clearCache() {
|
|
20
|
+
ThroughHistoryService.cache = [];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.default = ThroughHistoryService;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StateService } from "../services/store.service";
|
|
2
|
-
import { IHistoryLine } from "../types/history";
|
|
2
|
+
import { IHistoryLine, TReducerNames } from "../types/history";
|
|
3
3
|
export interface IHistoryState {
|
|
4
4
|
historyLines: IHistoryLine[];
|
|
5
5
|
}
|
|
@@ -9,7 +9,7 @@ export declare class HistoryState implements StateService {
|
|
|
9
9
|
private _historyLines;
|
|
10
10
|
get historyLines(): IHistoryState['historyLines'];
|
|
11
11
|
constructor();
|
|
12
|
-
reduce(
|
|
12
|
+
reduce(name: TReducerNames, payload?: IHistoryLine | IHistoryState): void;
|
|
13
13
|
emerge(completeIt: (history: IHistoryState['historyLines']) => void): void;
|
|
14
14
|
reset(): void;
|
|
15
15
|
}
|
|
@@ -13,28 +13,56 @@ class HistoryState {
|
|
|
13
13
|
constructor() {
|
|
14
14
|
this.reset();
|
|
15
15
|
}
|
|
16
|
-
reduce(payload) {
|
|
16
|
+
reduce(name, payload) {
|
|
17
|
+
const reducer = new Reducer();
|
|
18
|
+
switch (name) {
|
|
19
|
+
case 'SET_HISTORY':
|
|
20
|
+
reducer.setHistoryLines(payload, this);
|
|
21
|
+
break;
|
|
22
|
+
case 'UPDATE_HISTORY':
|
|
23
|
+
reducer.updateHistoryLines(payload, this);
|
|
24
|
+
break;
|
|
25
|
+
case 'REDO':
|
|
26
|
+
reducer.updateHistoryLines(payload, this);
|
|
27
|
+
break;
|
|
28
|
+
case 'UNDO':
|
|
29
|
+
reducer.popHistoryLines(this);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
emerge(completeIt) {
|
|
34
|
+
this._emergeCompleteIt = completeIt;
|
|
35
|
+
}
|
|
36
|
+
reset() {
|
|
37
|
+
this.reduce('SET_HISTORY', this.default);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.HistoryState = HistoryState;
|
|
41
|
+
class Reducer {
|
|
42
|
+
setHistoryLines(payload, state) {
|
|
17
43
|
let isUpdate = false;
|
|
18
44
|
if (!!payload?.historyLines) {
|
|
19
|
-
|
|
45
|
+
state._historyLines = payload.historyLines;
|
|
20
46
|
isUpdate = true;
|
|
21
47
|
}
|
|
48
|
+
if (isUpdate && !!state._emergeCompleteIt) {
|
|
49
|
+
state._emergeCompleteIt(state._historyLines);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
updateHistoryLines(payload, state) {
|
|
53
|
+
let isUpdate = false;
|
|
22
54
|
if (!!payload?.view) {
|
|
23
|
-
|
|
55
|
+
state._historyLines.push(payload);
|
|
24
56
|
isUpdate = true;
|
|
25
57
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
console.log("this._emergeCompleteIt", this._emergeCompleteIt);
|
|
29
|
-
this._emergeCompleteIt(this._historyLines);
|
|
58
|
+
if (isUpdate && !!state._emergeCompleteIt) {
|
|
59
|
+
state._emergeCompleteIt(state._historyLines);
|
|
30
60
|
}
|
|
31
61
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.reduce(this.default);
|
|
62
|
+
popHistoryLines(state) {
|
|
63
|
+
state._historyLines.pop();
|
|
64
|
+
if (!!state._emergeCompleteIt) {
|
|
65
|
+
state._emergeCompleteIt(state._historyLines);
|
|
66
|
+
}
|
|
38
67
|
}
|
|
39
68
|
}
|
|
40
|
-
exports.HistoryState = HistoryState;
|
package/dist/types/history.d.ts
CHANGED