architwin 1.16.9 → 1.17.0

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,17 @@
1
+ export declare class ActionPartitionHistory {
2
+ private history;
3
+ private index;
4
+ private current;
5
+ addToHistory(partition: any): void;
6
+ undo(): any;
7
+ redo(): any;
8
+ getCurrent(): any;
9
+ setCurrent(partition: any): any;
10
+ getAllHistory(): {
11
+ history: any[];
12
+ index: number;
13
+ };
14
+ clearHistory(): void;
15
+ canUndo(): boolean;
16
+ canRedo(): boolean;
17
+ }
@@ -0,0 +1,62 @@
1
+ import log from "loglevel";
2
+ export class ActionPartitionHistory {
3
+ constructor() {
4
+ this.history = []; // all recorded partition states
5
+ this.index = -1; // current pointer
6
+ this.current = null; // fallback for "original" state
7
+ }
8
+ addToHistory(partition) {
9
+ const newPartition = structuredClone(partition);
10
+ if (this.index < this.history.length - 1) {
11
+ this.history = this.history.slice(0, this.index + 1);
12
+ }
13
+ if (this.history.length === 0 ||
14
+ JSON.stringify(this.history[this.history.length - 1]) !== JSON.stringify(newPartition)) {
15
+ this.history.push(newPartition);
16
+ this.index = this.history.length - 1;
17
+ log.info("newPartition", newPartition, this.current, this.history.length);
18
+ }
19
+ }
20
+ undo() {
21
+ if (!this.canUndo())
22
+ return null;
23
+ this.index--;
24
+ if (this.index < 0)
25
+ return this.current ? this.current : null;
26
+ return this.getCurrent();
27
+ }
28
+ redo() {
29
+ if (!this.canRedo())
30
+ return null;
31
+ this.index++;
32
+ return this.getCurrent();
33
+ }
34
+ getCurrent() {
35
+ if (this.index >= 0 && this.index < this.history.length) {
36
+ return structuredClone(this.history[this.index]);
37
+ }
38
+ return this.current ? this.current : null;
39
+ }
40
+ setCurrent(partition) {
41
+ this.current = structuredClone(partition); // or _.cloneDeep(partition)
42
+ return this.current;
43
+ }
44
+ getAllHistory() {
45
+ return {
46
+ history: this.history.map(p => structuredClone(p)),
47
+ index: this.index,
48
+ };
49
+ }
50
+ clearHistory() {
51
+ this.history = [];
52
+ this.index = -1;
53
+ this.current = null;
54
+ console.log("History cleared.");
55
+ }
56
+ canUndo() {
57
+ return this.index >= 0;
58
+ }
59
+ canRedo() {
60
+ return this.index < this.history.length - 1;
61
+ }
62
+ }