@toolbox-web/grid 1.22.0 → 1.23.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/README.md +20 -10
- package/all.js +2 -2
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +88 -1
- package/lib/core/grid.d.ts.map +1 -1
- package/lib/core/types.d.ts +61 -0
- package/lib/core/types.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/EditingPlugin.d.ts +132 -1
- package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
- package/lib/plugins/editing/editors.d.ts.map +1 -1
- package/lib/plugins/editing/index.d.ts +1 -0
- package/lib/plugins/editing/index.d.ts.map +1 -1
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/editing/internal/dirty-tracking.d.ts +90 -0
- package/lib/plugins/editing/internal/dirty-tracking.d.ts.map +1 -0
- package/lib/plugins/editing/types.d.ts +82 -0
- package/lib/plugins/editing/types.d.ts.map +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/FilteringPlugin.d.ts +17 -4
- package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts +52 -7
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts.map +1 -1
- package/lib/plugins/undo-redo/history.d.ts +11 -4
- package/lib/plugins/undo-redo/history.d.ts.map +1 -1
- package/lib/plugins/undo-redo/index.d.ts +1 -1
- package/lib/plugins/undo-redo/index.d.ts.map +1 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/undo-redo/types.d.ts +20 -3
- package/lib/plugins/undo-redo/types.d.ts.map +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/public.d.ts +1 -1
- package/public.d.ts.map +1 -1
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/filtering.umd.js +1 -1
- package/umd/plugins/filtering.umd.js.map +1 -1
- package/umd/plugins/undo-redo.umd.js +1 -1
- package/umd/plugins/undo-redo.umd.js.map +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseGridPlugin, GridElement, PluginDependency } from '../../core/plugin/base-plugin';
|
|
2
|
-
import {
|
|
2
|
+
import { UndoRedoAction, UndoRedoConfig } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Undo/Redo Plugin for tbw-grid
|
|
5
5
|
*
|
|
@@ -34,11 +34,14 @@ import { EditAction, UndoRedoConfig } from './types';
|
|
|
34
34
|
*
|
|
35
35
|
* | Method | Signature | Description |
|
|
36
36
|
* |--------|-----------|-------------|
|
|
37
|
-
* | `undo` | `() =>
|
|
38
|
-
* | `redo` | `() =>
|
|
37
|
+
* | `undo` | `() => UndoRedoAction \| null` | Undo the last edit (or compound) |
|
|
38
|
+
* | `redo` | `() => UndoRedoAction \| null` | Redo the last undone edit (or compound) |
|
|
39
39
|
* | `canUndo` | `() => boolean` | Check if undo is available |
|
|
40
40
|
* | `canRedo` | `() => boolean` | Check if redo is available |
|
|
41
41
|
* | `clearHistory` | `() => void` | Clear the entire history stack |
|
|
42
|
+
* | `recordEdit` | `(rowIndex, field, old, new) => void` | Manually record a cell edit |
|
|
43
|
+
* | `beginTransaction` | `() => void` | Start grouping edits into a compound |
|
|
44
|
+
* | `endTransaction` | `() => void` | Finalize and push the compound action |
|
|
42
45
|
*
|
|
43
46
|
* @example Basic Usage with EditingPlugin
|
|
44
47
|
* ```ts
|
|
@@ -65,6 +68,7 @@ import { EditAction, UndoRedoConfig } from './types';
|
|
|
65
68
|
* @internal Extends BaseGridPlugin
|
|
66
69
|
*/
|
|
67
70
|
export declare class UndoRedoPlugin extends BaseGridPlugin<UndoRedoConfig> {
|
|
71
|
+
#private;
|
|
68
72
|
/**
|
|
69
73
|
* Plugin dependencies - UndoRedoPlugin requires EditingPlugin to track edits.
|
|
70
74
|
*
|
|
@@ -105,18 +109,59 @@ export declare class UndoRedoPlugin extends BaseGridPlugin<UndoRedoConfig> {
|
|
|
105
109
|
* @param newValue - The value after the edit
|
|
106
110
|
*/
|
|
107
111
|
recordEdit(rowIndex: number, field: string, oldValue: unknown, newValue: unknown): void;
|
|
112
|
+
/**
|
|
113
|
+
* Begin grouping subsequent edits into a single compound action.
|
|
114
|
+
*
|
|
115
|
+
* While a transaction is active, all `recordEdit()` calls (both manual
|
|
116
|
+
* and auto-recorded from `cell-edit-committed`) are buffered instead of
|
|
117
|
+
* pushed to the undo stack. Call `endTransaction()` to finalize the group.
|
|
118
|
+
*
|
|
119
|
+
* **Typical usage** — group a user edit with its cascaded side-effects:
|
|
120
|
+
*
|
|
121
|
+
* ```ts
|
|
122
|
+
* grid.addEventListener('cell-commit', (e) => {
|
|
123
|
+
* const undoRedo = grid.getPluginByName('undoRedo');
|
|
124
|
+
* undoRedo.beginTransaction();
|
|
125
|
+
*
|
|
126
|
+
* // Record cascaded updates (these won't auto-record)
|
|
127
|
+
* const oldB = row.fieldB;
|
|
128
|
+
* undoRedo.recordEdit(rowIndex, 'fieldB', oldB, computedB);
|
|
129
|
+
* grid.updateRow(rowId, { fieldB: computedB });
|
|
130
|
+
*
|
|
131
|
+
* // End after the auto-recorded original edit is captured
|
|
132
|
+
* queueMicrotask(() => undoRedo.endTransaction());
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @throws Error if a transaction is already in progress
|
|
137
|
+
*/
|
|
138
|
+
beginTransaction(): void;
|
|
139
|
+
/**
|
|
140
|
+
* Finalize the current transaction, wrapping all buffered edits into a
|
|
141
|
+
* single compound action on the undo stack.
|
|
142
|
+
*
|
|
143
|
+
* - If the buffer contains multiple edits, they are wrapped in a `CompoundEditAction`.
|
|
144
|
+
* - If the buffer contains a single edit, it is pushed as a regular `EditAction`.
|
|
145
|
+
* - If the buffer is empty, this is a no-op.
|
|
146
|
+
*
|
|
147
|
+
* Undoing a compound action reverts all edits in reverse order; redoing
|
|
148
|
+
* replays them in forward order.
|
|
149
|
+
*
|
|
150
|
+
* @throws Error if no transaction is in progress
|
|
151
|
+
*/
|
|
152
|
+
endTransaction(): void;
|
|
108
153
|
/**
|
|
109
154
|
* Programmatically undo the last action.
|
|
110
155
|
*
|
|
111
156
|
* @returns The undone action, or null if nothing to undo
|
|
112
157
|
*/
|
|
113
|
-
undo():
|
|
158
|
+
undo(): UndoRedoAction | null;
|
|
114
159
|
/**
|
|
115
160
|
* Programmatically redo the last undone action.
|
|
116
161
|
*
|
|
117
162
|
* @returns The redone action, or null if nothing to redo
|
|
118
163
|
*/
|
|
119
|
-
redo():
|
|
164
|
+
redo(): UndoRedoAction | null;
|
|
120
165
|
/**
|
|
121
166
|
* Check if there are any actions that can be undone.
|
|
122
167
|
*/
|
|
@@ -132,10 +177,10 @@ export declare class UndoRedoPlugin extends BaseGridPlugin<UndoRedoConfig> {
|
|
|
132
177
|
/**
|
|
133
178
|
* Get a copy of the current undo stack.
|
|
134
179
|
*/
|
|
135
|
-
getUndoStack():
|
|
180
|
+
getUndoStack(): UndoRedoAction[];
|
|
136
181
|
/**
|
|
137
182
|
* Get a copy of the current redo stack.
|
|
138
183
|
*/
|
|
139
|
-
getRedoStack():
|
|
184
|
+
getRedoStack(): UndoRedoAction[];
|
|
140
185
|
}
|
|
141
186
|
//# sourceMappingURL=UndoRedoPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UndoRedoPlugin.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/undo-redo/UndoRedoPlugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"UndoRedoPlugin.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/undo-redo/UndoRedoPlugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAYxG,OAAO,KAAK,EAAc,cAAc,EAAE,cAAc,EAAkB,MAAM,SAAS,CAAC;AAE1F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,qBAAa,cAAe,SAAQ,cAAc,CAAC,cAAc,CAAC;;IAChE;;;;;OAKG;IACH,gBAAyB,YAAY,EAAE,gBAAgB,EAAE,CAEvD;IAEF,gBAAgB;IAChB,QAAQ,CAAC,IAAI,cAAc;IAE3B,gBAAgB;IAChB,cAAuB,aAAa,IAAI,OAAO,CAAC,cAAc,CAAC,CAI9D;IAGD,OAAO,CAAC,SAAS,CAAwB;IACzC,OAAO,CAAC,SAAS,CAAwB;IA8FzC;;;OAGG;IACM,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI;IAiBxC;;;OAGG;IACM,MAAM,IAAI,IAAI;IAMvB;;;;;OAKG;IACM,SAAS,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO;IAyDjD;;;;;;;;OAQG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI;IAkBvF;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,gBAAgB,IAAI,IAAI;IAOxB;;;;;;;;;;;;OAYG;IACH,cAAc,IAAI,IAAI;IAmBtB;;;;OAIG;IACH,IAAI,IAAI,cAAc,GAAG,IAAI;IAY7B;;;;OAIG;IACH,IAAI,IAAI,cAAc,GAAG,IAAI;IAY7B;;OAEG;IACH,OAAO,IAAI,OAAO;IAIlB;;OAEG;IACH,OAAO,IAAI,OAAO;IAIlB;;OAEG;IACH,YAAY,IAAI,IAAI;IAOpB;;OAEG;IACH,YAAY,IAAI,cAAc,EAAE;IAIhC;;OAEG;IACH,YAAY,IAAI,cAAc,EAAE;CAIjC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EditAction, UndoRedoState } from './types';
|
|
1
|
+
import { CompoundEditAction, EditAction, UndoRedoAction, UndoRedoState } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Push a new action onto the undo stack.
|
|
4
4
|
* Clears the redo stack since new actions invalidate redo history.
|
|
@@ -8,7 +8,7 @@ import { EditAction, UndoRedoState } from './types';
|
|
|
8
8
|
* @param maxSize - Maximum history size
|
|
9
9
|
* @returns New state with the action added
|
|
10
10
|
*/
|
|
11
|
-
export declare function pushAction(state: UndoRedoState, action:
|
|
11
|
+
export declare function pushAction(state: UndoRedoState, action: UndoRedoAction, maxSize: number): UndoRedoState;
|
|
12
12
|
/**
|
|
13
13
|
* Undo the most recent action.
|
|
14
14
|
* Moves the action from undo stack to redo stack.
|
|
@@ -18,7 +18,7 @@ export declare function pushAction(state: UndoRedoState, action: EditAction, max
|
|
|
18
18
|
*/
|
|
19
19
|
export declare function undo(state: UndoRedoState): {
|
|
20
20
|
newState: UndoRedoState;
|
|
21
|
-
action:
|
|
21
|
+
action: UndoRedoAction | null;
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
24
|
* Redo the most recently undone action.
|
|
@@ -29,7 +29,7 @@ export declare function undo(state: UndoRedoState): {
|
|
|
29
29
|
*/
|
|
30
30
|
export declare function redo(state: UndoRedoState): {
|
|
31
31
|
newState: UndoRedoState;
|
|
32
|
-
action:
|
|
32
|
+
action: UndoRedoAction | null;
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
35
35
|
* Check if there are any actions that can be undone.
|
|
@@ -61,4 +61,11 @@ export declare function clearHistory(): UndoRedoState;
|
|
|
61
61
|
* @returns A new EditAction object
|
|
62
62
|
*/
|
|
63
63
|
export declare function createEditAction(rowIndex: number, field: string, oldValue: unknown, newValue: unknown): EditAction;
|
|
64
|
+
/**
|
|
65
|
+
* Create a compound action grouping multiple edits into a single undo/redo unit.
|
|
66
|
+
*
|
|
67
|
+
* @param actions - The individual edit actions to group (in chronological order)
|
|
68
|
+
* @returns A CompoundEditAction wrapping all provided edits
|
|
69
|
+
*/
|
|
70
|
+
export declare function createCompoundAction(actions: EditAction[]): CompoundEditAction;
|
|
64
71
|
//# sourceMappingURL=history.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/undo-redo/history.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/undo-redo/history.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7F;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa,CAYvG;AAED;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG;IAC1C,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;CAC/B,CAqBA;AAED;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG;IAC1C,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;CAC/B,CAqBA;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAErD;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAErD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,aAAa,CAE5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,UAAU,CASlH;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,kBAAkB,CAM9E"}
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module Plugins/Undo-Redo
|
|
6
6
|
*/
|
|
7
|
-
export type { EditAction, UndoRedoConfig, UndoRedoDetail } from './types';
|
|
7
|
+
export type { CompoundEditAction, EditAction, UndoRedoAction, UndoRedoConfig, UndoRedoDetail } from './types';
|
|
8
8
|
export { UndoRedoPlugin } from './UndoRedoPlugin';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/undo-redo/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/undo-redo/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,YAAY,EAAE,kBAAkB,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9G,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const t='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',e={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:t,filterActive:t,print:"🖨️"};class n{static dependencies;static manifest;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const n=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...e,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),n=parseInt(e,10);if(!isNaN(n))return n}return 200}resolveIcon(t,e){return void 0!==e?e:this.gridIcons[t]}setIcon(t,e){"string"==typeof e?t.innerHTML=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}warn(t){console.warn(`[tbw-grid:${this.name}] ${t}`)}}function o(t){if(0===t.undoStack.length)return{newState:t,action:null};const e=[...t.undoStack],n=e.pop();return n?{newState:{undoStack:e,redoStack:[...t.redoStack,n]},action:n}:{newState:t,action:null}}function r(t){if(0===t.redoStack.length)return{newState:t,action:null};const e=[...t.redoStack],n=e.pop();return n?{newState:{undoStack:[...t.undoStack,n],redoStack:e},action:n}:{newState:t,action:null}}class
|
|
1
|
+
document.createElement("template").innerHTML='<div class="cell" role="gridcell" part="cell"></div>';document.createElement("template").innerHTML='<div class="data-grid-row" role="row" part="row"></div>';const t='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',e={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:t,filterActive:t,print:"🖨️"};class n{static dependencies;static manifest;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const n=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...e,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),n=parseInt(e,10);if(!isNaN(n))return n}return 200}resolveIcon(t,e){return void 0!==e?e:this.gridIcons[t]}setIcon(t,e){"string"==typeof e?t.innerHTML=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}warn(t){console.warn(`[tbw-grid:${this.name}] ${t}`)}}function o(t,e,n){const o=[...t.undoStack,e];for(;o.length>n;)o.shift();return{undoStack:o,redoStack:[]}}function i(t){if(0===t.undoStack.length)return{newState:t,action:null};const e=[...t.undoStack],n=e.pop();return n?{newState:{undoStack:e,redoStack:[...t.redoStack,n]},action:n}:{newState:t,action:null}}function r(t){if(0===t.redoStack.length)return{newState:t,action:null};const e=[...t.redoStack],n=e.pop();return n?{newState:{undoStack:[...t.undoStack,n],redoStack:e},action:n}:{newState:t,action:null}}class a extends n{static dependencies=[{name:"editing",required:!0,reason:"UndoRedoPlugin tracks cell edit history"}];name="undoRedo";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];#e=!1;#n=null;#o(t,e){const n=this.rows[t.rowIndex];if(n){try{const o=this.grid.getRowId(n);if(o)return void this.grid.updateRow(o,{[t.field]:e})}catch{}n[t.field]=e}}#i(t){const e=this.grid,n=e._visibleColumns?.findIndex(e=>e.field===t.field)??-1;if(n<0)return;e._focusRow=t.rowIndex,e._focusCol=n;const o=e.findRenderedRowElement?.(t.rowIndex);if(!o)return;const i=o.querySelector(`.cell[data-col="${n}"]`);if(i?.classList.contains("editing")){const t=i.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');t?.focus({preventScroll:!0})}}#r(t,e){if(this.#e=!0,"compound"===t.type){const n="undo"===e?[...t.actions].reverse():t.actions;for(const t of n)this.#o(t,"undo"===e?t.oldValue:t.newValue)}else this.#o(t,"undo"===e?t.oldValue:t.newValue);this.#e=!1}#a(t){const e="compound"===t.type?t.actions[t.actions.length-1]:t;e&&this.#i(e)}attach(t){super.attach(t),this.on("cell-edit-committed",t=>{this.#e||this.recordEdit(t.rowIndex,t.field,t.oldValue,t.newValue)})}detach(){this.undoStack=[],this.redoStack=[],this.#n=null}onKeyDown(t){const e=(t.ctrlKey||t.metaKey)&&"z"===t.key&&!t.shiftKey,n=(t.ctrlKey||t.metaKey)&&("y"===t.key||"z"===t.key&&t.shiftKey);if(e){t.preventDefault();const e=i({undoStack:this.undoStack,redoStack:this.redoStack});return e.action&&(this.#r(e.action,"undo"),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.emit("undo",{action:e.action,type:"undo"}),this.#a(e.action),this.requestRenderWithFocus()),!0}if(n){t.preventDefault();const e=r({undoStack:this.undoStack,redoStack:this.redoStack});return e.action&&(this.#r(e.action,"redo"),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.emit("redo",{action:e.action,type:"redo"}),this.#a(e.action),this.requestRenderWithFocus()),!0}return!1}recordEdit(t,e,n,i){const r=function(t,e,n,o){return{type:"cell-edit",rowIndex:t,field:e,oldValue:n,newValue:o,timestamp:Date.now()}}(t,e,n,i);if(this.#n)return void this.#n.push(r);const a=o({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=a.undoStack,this.redoStack=a.redoStack}beginTransaction(){if(this.#n)throw new Error("UndoRedoPlugin: Transaction already in progress. Call endTransaction() first.");this.#n=[]}endTransaction(){const t=this.#n;if(!t)throw new Error("UndoRedoPlugin: No transaction in progress. Call beginTransaction() first.");if(this.#n=null,0===t.length)return;const e=1===t.length?t[0]:{type:"compound",actions:t,timestamp:Date.now()};const n=o({undoStack:this.undoStack,redoStack:this.redoStack},e,this.config.maxHistorySize??100);this.undoStack=n.undoStack,this.redoStack=n.redoStack}undo(){const t=i({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#r(t.action,"undo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.#a(t.action),this.requestRenderWithFocus()),t.action}redo(){const t=r({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#r(t.action,"redo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.#a(t.action),this.requestRenderWithFocus()),t.action}canUndo(){return{undoStack:this.undoStack,redoStack:this.redoStack}.undoStack.length>0}canRedo(){return{undoStack:this.undoStack,redoStack:this.redoStack}.redoStack.length>0}clearHistory(){const t={undoStack:[],redoStack:[]};this.undoStack=t.undoStack,this.redoStack=t.redoStack,this.#n=null}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}export{a as UndoRedoPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|