@toolbox-web/grid-react 0.14.0 → 0.15.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.
- package/features/undo-redo.d.ts +25 -7
- package/features/undo-redo.d.ts.map +1 -1
- package/features/undo-redo.js +71 -21
- package/package.json +1 -1
package/features/undo-redo.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UndoRedoAction } from '@toolbox-web/grid/plugins/undo-redo';
|
|
2
2
|
/**
|
|
3
3
|
* Undo/Redo methods returned from useGridUndoRedo.
|
|
4
4
|
*/
|
|
5
5
|
export interface UndoRedoMethods {
|
|
6
6
|
/**
|
|
7
7
|
* Undo the last edit action.
|
|
8
|
-
* @returns The undone action, or null if nothing to undo
|
|
8
|
+
* @returns The undone action (or compound action), or null if nothing to undo
|
|
9
9
|
*/
|
|
10
|
-
undo: () =>
|
|
10
|
+
undo: () => UndoRedoAction | null;
|
|
11
11
|
/**
|
|
12
12
|
* Redo the last undone action.
|
|
13
|
-
* @returns The redone action, or null if nothing to redo
|
|
13
|
+
* @returns The redone action (or compound action), or null if nothing to redo
|
|
14
14
|
*/
|
|
15
|
-
redo: () =>
|
|
15
|
+
redo: () => UndoRedoAction | null;
|
|
16
16
|
/**
|
|
17
17
|
* Check if there are any actions that can be undone.
|
|
18
18
|
*/
|
|
@@ -28,11 +28,29 @@ export interface UndoRedoMethods {
|
|
|
28
28
|
/**
|
|
29
29
|
* Get a copy of the current undo stack.
|
|
30
30
|
*/
|
|
31
|
-
getUndoStack: () =>
|
|
31
|
+
getUndoStack: () => UndoRedoAction[];
|
|
32
32
|
/**
|
|
33
33
|
* Get a copy of the current redo stack.
|
|
34
34
|
*/
|
|
35
|
-
getRedoStack: () =>
|
|
35
|
+
getRedoStack: () => UndoRedoAction[];
|
|
36
|
+
/**
|
|
37
|
+
* Manually record an edit action.
|
|
38
|
+
* If a transaction is active, the action is buffered; otherwise it's pushed to the undo stack.
|
|
39
|
+
*/
|
|
40
|
+
recordEdit: (rowIndex: number, field: string, oldValue: unknown, newValue: unknown) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Begin a transaction. All edits recorded until `endTransaction()` are grouped
|
|
43
|
+
* into a single compound action for undo/redo.
|
|
44
|
+
* @throws If a transaction is already active
|
|
45
|
+
*/
|
|
46
|
+
beginTransaction: () => void;
|
|
47
|
+
/**
|
|
48
|
+
* End the active transaction and push the compound action to the undo stack.
|
|
49
|
+
* If only one edit was recorded, it's pushed as a plain EditAction.
|
|
50
|
+
* If no edits were recorded, the transaction is discarded.
|
|
51
|
+
* @throws If no transaction is active
|
|
52
|
+
*/
|
|
53
|
+
endTransaction: () => void;
|
|
36
54
|
}
|
|
37
55
|
/**
|
|
38
56
|
* Hook for programmatic undo/redo control.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undo-redo.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/features/undo-redo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAGH,OAAO,EAAkB,KAAK,
|
|
1
|
+
{"version":3,"file":"undo-redo.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/features/undo-redo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAGH,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAU1F;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,IAAI,EAAE,MAAM,cAAc,GAAG,IAAI,CAAC;IAElC;;;OAGG;IACH,IAAI,EAAE,MAAM,cAAc,GAAG,IAAI,CAAC;IAElC;;OAEG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC;IAEvB;;OAEG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC;IAEvB;;OAEG;IACH,YAAY,EAAE,MAAM,IAAI,CAAC;IAEzB;;OAEG;IACH,YAAY,EAAE,MAAM,cAAc,EAAE,CAAC;IAErC;;OAEG;IACH,YAAY,EAAE,MAAM,cAAc,EAAE,CAAC;IAErC;;;OAGG;IACH,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IAE5F;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,IAAI,CAAC;IAE7B;;;;;OAKG;IACH,cAAc,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAAe,IAAI,eAAe,CA6GjD"}
|
package/features/undo-redo.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { UndoRedoPlugin as
|
|
2
|
-
import { useContext as
|
|
3
|
-
import { G as
|
|
4
|
-
import { r as
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
return new
|
|
1
|
+
import { UndoRedoPlugin as r } from "@toolbox-web/grid/plugins/undo-redo";
|
|
2
|
+
import { useContext as k, useCallback as d } from "react";
|
|
3
|
+
import { G as m } from "../chunks/data-grid-O97pdLCY.js";
|
|
4
|
+
import { r as E } from "../chunks/feature-registry-Y3KvnN54.js";
|
|
5
|
+
E("undoRedo", (e) => {
|
|
6
|
+
const n = typeof e == "boolean" ? {} : e ?? {};
|
|
7
|
+
return new r(n);
|
|
8
8
|
});
|
|
9
|
-
function
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
return
|
|
9
|
+
function S() {
|
|
10
|
+
const e = k(m), n = d(() => e?.current?.getPlugin(r), [e]), i = d(() => {
|
|
11
|
+
const o = n();
|
|
12
|
+
return o ? o.undo() : (console.warn(
|
|
13
13
|
`[tbw-grid:undoRedo] UndoRedoPlugin not found.
|
|
14
14
|
|
|
15
15
|
→ Enable undo/redo on the grid:
|
|
16
16
|
<DataGrid editing="dblclick" undoRedo />`
|
|
17
17
|
), null);
|
|
18
|
-
}, [
|
|
19
|
-
const
|
|
20
|
-
return
|
|
18
|
+
}, [n]), u = d(() => {
|
|
19
|
+
const o = n();
|
|
20
|
+
return o ? o.redo() : (console.warn(
|
|
21
21
|
`[tbw-grid:undoRedo] UndoRedoPlugin not found.
|
|
22
22
|
|
|
23
23
|
→ Enable undo/redo on the grid:
|
|
24
24
|
<DataGrid editing="dblclick" undoRedo />`
|
|
25
25
|
), null);
|
|
26
|
-
}, [
|
|
27
|
-
const
|
|
28
|
-
if (!
|
|
26
|
+
}, [n]), c = d(() => n()?.canUndo() ?? !1, [n]), l = d(() => n()?.canRedo() ?? !1, [n]), a = d(() => {
|
|
27
|
+
const o = n();
|
|
28
|
+
if (!o) {
|
|
29
29
|
console.warn(
|
|
30
30
|
`[tbw-grid:undoRedo] UndoRedoPlugin not found.
|
|
31
31
|
|
|
@@ -34,10 +34,60 @@ function k() {
|
|
|
34
34
|
);
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
}, [
|
|
39
|
-
|
|
37
|
+
o.clearHistory();
|
|
38
|
+
}, [n]), g = d(() => n()?.getUndoStack() ?? [], [n]), s = d(() => n()?.getRedoStack() ?? [], [n]), R = d(
|
|
39
|
+
(o, p, w, U) => {
|
|
40
|
+
const t = n();
|
|
41
|
+
if (!t) {
|
|
42
|
+
console.warn(
|
|
43
|
+
`[tbw-grid:undoRedo] UndoRedoPlugin not found.
|
|
44
|
+
|
|
45
|
+
→ Enable undo/redo on the grid:
|
|
46
|
+
<DataGrid editing="dblclick" undoRedo />`
|
|
47
|
+
);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
t.recordEdit(o, p, w, U);
|
|
51
|
+
},
|
|
52
|
+
[n]
|
|
53
|
+
), b = d(() => {
|
|
54
|
+
const o = n();
|
|
55
|
+
if (!o) {
|
|
56
|
+
console.warn(
|
|
57
|
+
`[tbw-grid:undoRedo] UndoRedoPlugin not found.
|
|
58
|
+
|
|
59
|
+
→ Enable undo/redo on the grid:
|
|
60
|
+
<DataGrid editing="dblclick" undoRedo />`
|
|
61
|
+
);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
o.beginTransaction();
|
|
65
|
+
}, [n]), f = d(() => {
|
|
66
|
+
const o = n();
|
|
67
|
+
if (!o) {
|
|
68
|
+
console.warn(
|
|
69
|
+
`[tbw-grid:undoRedo] UndoRedoPlugin not found.
|
|
70
|
+
|
|
71
|
+
→ Enable undo/redo on the grid:
|
|
72
|
+
<DataGrid editing="dblclick" undoRedo />`
|
|
73
|
+
);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
o.endTransaction();
|
|
77
|
+
}, [n]);
|
|
78
|
+
return {
|
|
79
|
+
undo: i,
|
|
80
|
+
redo: u,
|
|
81
|
+
canUndo: c,
|
|
82
|
+
canRedo: l,
|
|
83
|
+
clearHistory: a,
|
|
84
|
+
getUndoStack: g,
|
|
85
|
+
getRedoStack: s,
|
|
86
|
+
recordEdit: R,
|
|
87
|
+
beginTransaction: b,
|
|
88
|
+
endTransaction: f
|
|
89
|
+
};
|
|
40
90
|
}
|
|
41
91
|
export {
|
|
42
|
-
|
|
92
|
+
S as useGridUndoRedo
|
|
43
93
|
};
|