@toolbox-web/grid-react 0.13.2 → 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.
@@ -1,18 +1,18 @@
1
- import { EditAction } from '@toolbox-web/grid/plugins/undo-redo';
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: () => EditAction | null;
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: () => EditAction | null;
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: () => EditAction[];
31
+ getUndoStack: () => UndoRedoAction[];
32
32
  /**
33
33
  * Get a copy of the current redo stack.
34
34
  */
35
- getRedoStack: () => EditAction[];
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,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAUtF;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,IAAI,EAAE,MAAM,UAAU,GAAG,IAAI,CAAC;IAE9B;;;OAGG;IACH,IAAI,EAAE,MAAM,UAAU,GAAG,IAAI,CAAC;IAE9B;;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,UAAU,EAAE,CAAC;IAEjC;;OAEG;IACH,YAAY,EAAE,MAAM,UAAU,EAAE,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAAe,IAAI,eAAe,CAwDjD"}
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"}
@@ -1,31 +1,31 @@
1
- import { UndoRedoPlugin as t } from "@toolbox-web/grid/plugins/undo-redo";
2
- import { useContext as g, useCallback as e } from "react";
3
- import { G as R } from "../chunks/data-grid-O97pdLCY.js";
4
- import { r as f } from "../chunks/feature-registry-Y3KvnN54.js";
5
- f("undoRedo", (d) => {
6
- const o = typeof d == "boolean" ? {} : d ?? {};
7
- return new t(o);
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 k() {
10
- const d = g(R), o = e(() => d?.current?.getPlugin(t), [d]), r = e(() => {
11
- const n = o();
12
- return n ? n.undo() : (console.warn(
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
- }, [o]), i = e(() => {
19
- const n = o();
20
- return n ? n.redo() : (console.warn(
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
- }, [o]), u = e(() => o()?.canUndo() ?? !1, [o]), c = e(() => o()?.canRedo() ?? !1, [o]), l = e(() => {
27
- const n = o();
28
- if (!n) {
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
- n.clearHistory();
38
- }, [o]), a = e(() => o()?.getUndoStack() ?? [], [o]), s = e(() => o()?.getRedoStack() ?? [], [o]);
39
- return { undo: r, redo: i, canUndo: u, canRedo: c, clearHistory: l, getUndoStack: a, getRedoStack: s };
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
- k as useGridUndoRedo
92
+ S as useGridUndoRedo
43
93
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolbox-web/grid-react",
3
- "version": "0.13.2",
3
+ "version": "0.15.0",
4
4
  "description": "React adapter for @toolbox-web/grid data grid component",
5
5
  "type": "module",
6
6
  "main": "./index.js",