@toolbox-web/grid-vue 0.6.0 → 0.7.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
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
|
* Composable for programmatic undo/redo control.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undo-redo.d.ts","sourceRoot":"","sources":["../../../../libs/grid-vue/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-vue/src/features/undo-redo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAGH,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAY1F;;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,CA+FjD"}
|
package/features/undo-redo.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { UndoRedoPlugin as
|
|
2
|
-
import { inject as
|
|
3
|
-
import { r as
|
|
4
|
-
import { G as
|
|
5
|
-
|
|
6
|
-
function
|
|
7
|
-
const
|
|
1
|
+
import { UndoRedoPlugin as e } from "@toolbox-web/grid/plugins/undo-redo";
|
|
2
|
+
import { inject as l, ref as c } from "vue";
|
|
3
|
+
import { r as g } from "../chunks/feature-registry-BgEOysSJ.js";
|
|
4
|
+
import { G as a } from "../chunks/use-grid-DwjXrO19.js";
|
|
5
|
+
g("undoRedo", (d) => d === !0 ? new e() : new e(d ?? void 0));
|
|
6
|
+
function w() {
|
|
7
|
+
const d = l(a, c(null)), o = () => d.value?.getPlugin(e);
|
|
8
8
|
return {
|
|
9
9
|
undo: () => {
|
|
10
10
|
const n = o();
|
|
@@ -40,10 +40,49 @@ function s() {
|
|
|
40
40
|
n.clearHistory();
|
|
41
41
|
},
|
|
42
42
|
getUndoStack: () => o()?.getUndoStack() ?? [],
|
|
43
|
-
getRedoStack: () => o()?.getRedoStack() ?? []
|
|
43
|
+
getRedoStack: () => o()?.getRedoStack() ?? [],
|
|
44
|
+
recordEdit: (n, i, t, u) => {
|
|
45
|
+
const r = o();
|
|
46
|
+
if (!r) {
|
|
47
|
+
console.warn(
|
|
48
|
+
`[tbw-grid:undoRedo] UndoRedoPlugin not found.
|
|
49
|
+
|
|
50
|
+
→ Enable undo/redo on the grid:
|
|
51
|
+
<TbwGrid editing="dblclick" undoRedo />`
|
|
52
|
+
);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
r.recordEdit(n, i, t, u);
|
|
56
|
+
},
|
|
57
|
+
beginTransaction: () => {
|
|
58
|
+
const n = o();
|
|
59
|
+
if (!n) {
|
|
60
|
+
console.warn(
|
|
61
|
+
`[tbw-grid:undoRedo] UndoRedoPlugin not found.
|
|
62
|
+
|
|
63
|
+
→ Enable undo/redo on the grid:
|
|
64
|
+
<TbwGrid editing="dblclick" undoRedo />`
|
|
65
|
+
);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
n.beginTransaction();
|
|
69
|
+
},
|
|
70
|
+
endTransaction: () => {
|
|
71
|
+
const n = o();
|
|
72
|
+
if (!n) {
|
|
73
|
+
console.warn(
|
|
74
|
+
`[tbw-grid:undoRedo] UndoRedoPlugin not found.
|
|
75
|
+
|
|
76
|
+
→ Enable undo/redo on the grid:
|
|
77
|
+
<TbwGrid editing="dblclick" undoRedo />`
|
|
78
|
+
);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
n.endTransaction();
|
|
82
|
+
}
|
|
44
83
|
};
|
|
45
84
|
}
|
|
46
85
|
export {
|
|
47
|
-
|
|
86
|
+
w as useGridUndoRedo
|
|
48
87
|
};
|
|
49
88
|
//# sourceMappingURL=undo-redo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undo-redo.js","sources":["../../../../libs/grid-vue/src/features/undo-redo.ts"],"sourcesContent":["/**\n * Undo/Redo feature for @toolbox-web/grid-vue\n *\n * Import this module to enable the `undoRedo` prop on TbwGrid.\n * Also exports `useGridUndoRedo()` composable for programmatic undo/redo control.\n *\n * @example\n * ```vue\n * <script setup>\n * import '@toolbox-web/grid-vue/features/undo-redo';\n * </script>\n *\n * <template>\n * <TbwGrid editing=\"dblclick\" undoRedo />\n * </template>\n * ```\n *\n * @example Using the composable\n * ```vue\n * <script setup>\n * import { useGridUndoRedo } from '@toolbox-web/grid-vue/features/undo-redo';\n *\n * const { undo, redo, canUndo, canRedo } = useGridUndoRedo();\n * </script>\n *\n * <template>\n * <button @click=\"undo\" :disabled=\"!canUndo()\">Undo</button>\n * <button @click=\"redo\" :disabled=\"!canRedo()\">Redo</button>\n * </template>\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { DataGridElement } from '@toolbox-web/grid';\nimport { UndoRedoPlugin, type
|
|
1
|
+
{"version":3,"file":"undo-redo.js","sources":["../../../../libs/grid-vue/src/features/undo-redo.ts"],"sourcesContent":["/**\n * Undo/Redo feature for @toolbox-web/grid-vue\n *\n * Import this module to enable the `undoRedo` prop on TbwGrid.\n * Also exports `useGridUndoRedo()` composable for programmatic undo/redo control.\n *\n * @example\n * ```vue\n * <script setup>\n * import '@toolbox-web/grid-vue/features/undo-redo';\n * </script>\n *\n * <template>\n * <TbwGrid editing=\"dblclick\" undoRedo />\n * </template>\n * ```\n *\n * @example Using the composable\n * ```vue\n * <script setup>\n * import { useGridUndoRedo } from '@toolbox-web/grid-vue/features/undo-redo';\n *\n * const { undo, redo, canUndo, canRedo } = useGridUndoRedo();\n * </script>\n *\n * <template>\n * <button @click=\"undo\" :disabled=\"!canUndo()\">Undo</button>\n * <button @click=\"redo\" :disabled=\"!canRedo()\">Redo</button>\n * </template>\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { DataGridElement } from '@toolbox-web/grid';\nimport { UndoRedoPlugin, type UndoRedoAction } from '@toolbox-web/grid/plugins/undo-redo';\nimport { inject, ref } from 'vue';\nimport { registerFeature } from '../lib/feature-registry';\nimport { GRID_ELEMENT_KEY } from '../lib/use-grid';\n\nregisterFeature('undoRedo', (config) => {\n if (config === true) {\n return new UndoRedoPlugin();\n }\n return new UndoRedoPlugin(config ?? undefined);\n});\n\n/**\n * Undo/Redo methods returned from useGridUndoRedo.\n */\nexport interface UndoRedoMethods {\n /**\n * Undo the last edit action.\n * @returns The undone action (or compound action), or null if nothing to undo\n */\n undo: () => UndoRedoAction | null;\n\n /**\n * Redo the last undone action.\n * @returns The redone action (or compound action), or null if nothing to redo\n */\n redo: () => UndoRedoAction | null;\n\n /**\n * Check if there are any actions that can be undone.\n */\n canUndo: () => boolean;\n\n /**\n * Check if there are any actions that can be redone.\n */\n canRedo: () => boolean;\n\n /**\n * Clear all undo/redo history.\n */\n clearHistory: () => void;\n\n /**\n * Get a copy of the current undo stack.\n */\n getUndoStack: () => UndoRedoAction[];\n\n /**\n * Get a copy of the current redo stack.\n */\n getRedoStack: () => UndoRedoAction[];\n\n /**\n * Manually record an edit action.\n * If a transaction is active, the action is buffered; otherwise it's pushed to the undo stack.\n */\n recordEdit: (rowIndex: number, field: string, oldValue: unknown, newValue: unknown) => void;\n\n /**\n * Begin a transaction. All edits recorded until `endTransaction()` are grouped\n * into a single compound action for undo/redo.\n * @throws If a transaction is already active\n */\n beginTransaction: () => void;\n\n /**\n * End the active transaction and push the compound action to the undo stack.\n * If only one edit was recorded, it's pushed as a plain EditAction.\n * If no edits were recorded, the transaction is discarded.\n * @throws If no transaction is active\n */\n endTransaction: () => void;\n}\n\n/**\n * Composable for programmatic undo/redo control.\n *\n * Must be used within a component that contains a TbwGrid with undoRedo and editing enabled.\n *\n * @example\n * ```vue\n * <script setup>\n * import { useGridUndoRedo } from '@toolbox-web/grid-vue/features/undo-redo';\n *\n * const { undo, redo, canUndo, canRedo, clearHistory } = useGridUndoRedo();\n * </script>\n *\n * <template>\n * <div class=\"toolbar\">\n * <button @click=\"undo\" :disabled=\"!canUndo()\">Undo</button>\n * <button @click=\"redo\" :disabled=\"!canRedo()\">Redo</button>\n * <button @click=\"clearHistory\">Clear History</button>\n * </div>\n * </template>\n * ```\n */\nexport function useGridUndoRedo(): UndoRedoMethods {\n const gridElement = inject(GRID_ELEMENT_KEY, ref(null));\n\n const getPlugin = (): UndoRedoPlugin | undefined => {\n const grid = gridElement.value as DataGridElement | null;\n return grid?.getPlugin(UndoRedoPlugin);\n };\n\n return {\n undo: () => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:undoRedo] UndoRedoPlugin not found.\\n\\n` +\n ` → Enable undo/redo on the grid:\\n` +\n ` <TbwGrid editing=\"dblclick\" undoRedo />`,\n );\n return null;\n }\n return plugin.undo();\n },\n\n redo: () => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:undoRedo] UndoRedoPlugin not found.\\n\\n` +\n ` → Enable undo/redo on the grid:\\n` +\n ` <TbwGrid editing=\"dblclick\" undoRedo />`,\n );\n return null;\n }\n return plugin.redo();\n },\n\n canUndo: () => getPlugin()?.canUndo() ?? false,\n\n canRedo: () => getPlugin()?.canRedo() ?? false,\n\n clearHistory: () => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:undoRedo] UndoRedoPlugin not found.\\n\\n` +\n ` → Enable undo/redo on the grid:\\n` +\n ` <TbwGrid editing=\"dblclick\" undoRedo />`,\n );\n return;\n }\n plugin.clearHistory();\n },\n\n getUndoStack: () => getPlugin()?.getUndoStack() ?? [],\n\n getRedoStack: () => getPlugin()?.getRedoStack() ?? [],\n\n recordEdit: (rowIndex: number, field: string, oldValue: unknown, newValue: unknown) => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:undoRedo] UndoRedoPlugin not found.\\n\\n` +\n ` → Enable undo/redo on the grid:\\n` +\n ` <TbwGrid editing=\"dblclick\" undoRedo />`,\n );\n return;\n }\n plugin.recordEdit(rowIndex, field, oldValue, newValue);\n },\n\n beginTransaction: () => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:undoRedo] UndoRedoPlugin not found.\\n\\n` +\n ` → Enable undo/redo on the grid:\\n` +\n ` <TbwGrid editing=\"dblclick\" undoRedo />`,\n );\n return;\n }\n plugin.beginTransaction();\n },\n\n endTransaction: () => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:undoRedo] UndoRedoPlugin not found.\\n\\n` +\n ` → Enable undo/redo on the grid:\\n` +\n ` <TbwGrid editing=\"dblclick\" undoRedo />`,\n );\n return;\n }\n plugin.endTransaction();\n },\n };\n}\n"],"names":["registerFeature","config","UndoRedoPlugin","useGridUndoRedo","gridElement","inject","GRID_ELEMENT_KEY","ref","getPlugin","plugin","rowIndex","field","oldValue","newValue"],"mappings":";;;;AAwCAA,EAAgB,YAAY,CAACC,MACvBA,MAAW,KACN,IAAIC,EAAA,IAEN,IAAIA,EAAeD,KAAU,MAAS,CAC9C;AAuFM,SAASE,IAAmC;AACjD,QAAMC,IAAcC,EAAOC,GAAkBC,EAAI,IAAI,CAAC,GAEhDC,IAAY,MACHJ,EAAY,OACZ,UAAUF,CAAc;AAGvC,SAAO;AAAA,IACL,MAAM,MAAM;AACV,YAAMO,IAASD,EAAA;AACf,aAAKC,IAQEA,EAAO,KAAA,KAPZ,QAAQ;AAAA,QACN;AAAA;AAAA;AAAA;AAAA,MAAA,GAIK;AAAA,IAGX;AAAA,IAEA,MAAM,MAAM;AACV,YAAMA,IAASD,EAAA;AACf,aAAKC,IAQEA,EAAO,KAAA,KAPZ,QAAQ;AAAA,QACN;AAAA;AAAA;AAAA;AAAA,MAAA,GAIK;AAAA,IAGX;AAAA,IAEA,SAAS,MAAMD,KAAa,aAAa;AAAA,IAEzC,SAAS,MAAMA,KAAa,aAAa;AAAA,IAEzC,cAAc,MAAM;AAClB,YAAMC,IAASD,EAAA;AACf,UAAI,CAACC,GAAQ;AACX,gBAAQ;AAAA,UACN;AAAA;AAAA;AAAA;AAAA,QAAA;AAIF;AAAA,MACF;AACA,MAAAA,EAAO,aAAA;AAAA,IACT;AAAA,IAEA,cAAc,MAAMD,KAAa,aAAA,KAAkB,CAAA;AAAA,IAEnD,cAAc,MAAMA,KAAa,aAAA,KAAkB,CAAA;AAAA,IAEnD,YAAY,CAACE,GAAkBC,GAAeC,GAAmBC,MAAsB;AACrF,YAAMJ,IAASD,EAAA;AACf,UAAI,CAACC,GAAQ;AACX,gBAAQ;AAAA,UACN;AAAA;AAAA;AAAA;AAAA,QAAA;AAIF;AAAA,MACF;AACA,MAAAA,EAAO,WAAWC,GAAUC,GAAOC,GAAUC,CAAQ;AAAA,IACvD;AAAA,IAEA,kBAAkB,MAAM;AACtB,YAAMJ,IAASD,EAAA;AACf,UAAI,CAACC,GAAQ;AACX,gBAAQ;AAAA,UACN;AAAA;AAAA;AAAA;AAAA,QAAA;AAIF;AAAA,MACF;AACA,MAAAA,EAAO,iBAAA;AAAA,IACT;AAAA,IAEA,gBAAgB,MAAM;AACpB,YAAMA,IAASD,EAAA;AACf,UAAI,CAACC,GAAQ;AACX,gBAAQ;AAAA,UACN;AAAA;AAAA;AAAA;AAAA,QAAA;AAIF;AAAA,MACF;AACA,MAAAA,EAAO,eAAA;AAAA,IACT;AAAA,EAAA;AAEJ;"}
|