canvas-editor-engine 1.0.84 → 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.
@@ -1,5 +1,8 @@
1
+ import { IHistoryLine } from "../types/history";
1
2
  export default class ThroughHistoryService {
2
- static current(): import("../types/history").IHistoryLine;
3
+ static cache: IHistoryLine[];
4
+ static current(): IHistoryLine;
3
5
  static undo(): void;
4
6
  static redo(): void;
7
+ static clearCache(): void;
5
8
  }
@@ -2,16 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const store_1 = require("../store/store");
4
4
  class ThroughHistoryService {
5
+ static cache = [];
5
6
  static current() {
6
7
  const history = store_1.default.store.historyState.historyLines;
7
8
  const lastIndex = history.length - 1;
8
9
  return history[lastIndex];
9
10
  }
10
11
  static undo() {
12
+ store_1.default.store.historyState.reduce('UNDO');
11
13
  }
12
14
  ;
13
15
  static redo() {
16
+ store_1.default.store.historyState.reduce('REDO', ThroughHistoryService.cache.shift());
14
17
  }
15
18
  ;
19
+ static clearCache() {
20
+ ThroughHistoryService.cache = [];
21
+ }
16
22
  }
17
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(name: 'SET_HISTORY' | 'UPDATE_HISTORY', payload: IHistoryLine | IHistoryState): void;
12
+ reduce(name: TReducerNames, payload?: IHistoryLine | IHistoryState): void;
13
13
  emerge(completeIt: (history: IHistoryState['historyLines']) => void): void;
14
14
  reset(): void;
15
15
  }
@@ -14,24 +14,20 @@ class HistoryState {
14
14
  this.reset();
15
15
  }
16
16
  reduce(name, payload) {
17
- // let isUpdate = false;
18
- // if (!!(payload as IHistoryState)?.historyLines) {
19
- // this._historyLines = (payload as IHistoryState).historyLines;
20
- // isUpdate = true;
21
- // }
22
- // if (!!(payload as IHistoryLine)?.view) {
23
- // this._historyLines.push(payload as IHistoryLine);
24
- // isUpdate = true;
25
- // }
26
- // if (isUpdate && !!this._emergeCompleteIt) {
27
- // this._emergeCompleteIt(this._historyLines);
28
- // }
29
17
  const reducer = new Reducer();
30
- if (name === 'SET_HISTORY') {
31
- reducer.setHistoryLines(payload, this);
32
- }
33
- if (name === 'UPDATE_HISTORY') {
34
- reducer.updateHistoryLines(payload, this);
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;
35
31
  }
36
32
  }
37
33
  emerge(completeIt) {
@@ -63,4 +59,10 @@ class Reducer {
63
59
  state._emergeCompleteIt(state._historyLines);
64
60
  }
65
61
  }
62
+ popHistoryLines(state) {
63
+ state._historyLines.pop();
64
+ if (!!state._emergeCompleteIt) {
65
+ state._emergeCompleteIt(state._historyLines);
66
+ }
67
+ }
66
68
  }
@@ -3,3 +3,4 @@ export interface IHistoryLine {
3
3
  stateValue: any;
4
4
  view: string;
5
5
  }
6
+ export type TReducerNames = 'SET_HISTORY' | 'UPDATE_HISTORY' | 'UNDO' | 'REDO';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvas-editor-engine",
3
- "version": "1.0.84",
3
+ "version": "1.0.85",
4
4
  "description": "CanvasEditorEngine library, use: [typescript] [canvas]",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",