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.
@@ -0,0 +1,8 @@
1
+ import { IHistoryLine } from "../types/history";
2
+ export default class ThroughHistoryService {
3
+ static cache: IHistoryLine[];
4
+ static current(): IHistoryLine;
5
+ static undo(): void;
6
+ static redo(): void;
7
+ static clearCache(): void;
8
+ }
@@ -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(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
  }
@@ -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
- this._historyLines = payload.historyLines;
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
- this._historyLines.push(payload);
55
+ state._historyLines.push(payload);
24
56
  isUpdate = true;
25
57
  }
26
- console.log('isUpdate && !!this._emergeCompleteIt', isUpdate && !!this._emergeCompleteIt);
27
- if (isUpdate && !!this._emergeCompleteIt) {
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
- emerge(completeIt) {
33
- console.log('completeIt', completeIt);
34
- this._emergeCompleteIt = completeIt;
35
- }
36
- reset() {
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;
@@ -53,7 +53,7 @@ class ImageState {
53
53
  size: this._size,
54
54
  tempImageData: this._tempImageData,
55
55
  };
56
- store_1.default.store.historyState.reduce({
56
+ store_1.default.store.historyState.reduce('UPDATE_HISTORY', {
57
57
  view: title,
58
58
  stateName: 'image',
59
59
  stateValue,
@@ -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.83",
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",