@toolbox-web/grid-react 0.9.0 → 0.11.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,16 +1,59 @@
1
+ import { ExportFormat, ExportParams } from '@toolbox-web/grid/plugins/export';
1
2
  /**
2
- * Export feature for @toolbox-web/grid-react
3
+ * Export methods returned from useGridExport.
4
+ */
5
+ export interface ExportMethods {
6
+ /**
7
+ * Export grid data to CSV file.
8
+ * @param filename - Optional filename (defaults to 'export.csv')
9
+ * @param params - Optional export parameters
10
+ */
11
+ exportToCsv: (filename?: string, params?: Partial<ExportParams>) => void;
12
+ /**
13
+ * Export grid data to Excel file (XML Spreadsheet format).
14
+ * @param filename - Optional filename (defaults to 'export.xlsx')
15
+ * @param params - Optional export parameters
16
+ */
17
+ exportToExcel: (filename?: string, params?: Partial<ExportParams>) => void;
18
+ /**
19
+ * Export grid data to JSON file.
20
+ * @param filename - Optional filename (defaults to 'export.json')
21
+ * @param params - Optional export parameters
22
+ */
23
+ exportToJson: (filename?: string, params?: Partial<ExportParams>) => void;
24
+ /**
25
+ * Check if an export is currently in progress.
26
+ */
27
+ isExporting: () => boolean;
28
+ /**
29
+ * Get information about the last export.
30
+ */
31
+ getLastExport: () => {
32
+ format: ExportFormat;
33
+ timestamp: Date;
34
+ } | null;
35
+ }
36
+ /**
37
+ * Hook for programmatic export control.
3
38
  *
4
- * Import this module to enable the `export` prop on DataGrid.
39
+ * Must be used within a DataGrid component tree with the export feature enabled.
5
40
  *
6
41
  * @example
7
42
  * ```tsx
8
- * import '@toolbox-web/grid-react/features/export';
43
+ * import { useGridExport } from '@toolbox-web/grid-react/features/export';
9
44
  *
10
- * <DataGrid export />
11
- * ```
45
+ * function ExportToolbar() {
46
+ * const { exportToCsv, exportToExcel, exportToJson, isExporting } = useGridExport();
12
47
  *
13
- * @packageDocumentation
48
+ * return (
49
+ * <div>
50
+ * <button onClick={() => exportToCsv()} disabled={isExporting()}>CSV</button>
51
+ * <button onClick={() => exportToExcel()} disabled={isExporting()}>Excel</button>
52
+ * <button onClick={() => exportToJson()} disabled={isExporting()}>JSON</button>
53
+ * </div>
54
+ * );
55
+ * }
56
+ * ```
14
57
  */
15
- export {};
58
+ export declare function useGridExport(): ExportMethods;
16
59
  //# sourceMappingURL=export.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/features/export.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
1
+ {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/features/export.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,EAAgB,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAUtG;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,WAAW,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;IAEzE;;;;OAIG;IACH,aAAa,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;IAE3E;;;;OAIG;IACH,YAAY,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;IAE1E;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;IAE3B;;OAEG;IACH,aAAa,EAAE,MAAM;QAAE,MAAM,EAAE,YAAY,CAAC;QAAC,SAAS,EAAE,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;CACvE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,aAAa,IAAI,aAAa,CAuE7C"}
@@ -1,6 +1,66 @@
1
- import { ExportPlugin as t } from "@toolbox-web/grid/plugins/export";
2
- import { r as e } from "../chunks/feature-registry-Y3KvnN54.js";
3
- e("export", (r) => {
4
- const o = typeof r == "boolean" ? {} : r ?? {};
5
- return new t(o);
1
+ import { ExportPlugin as p } from "@toolbox-web/grid/plugins/export";
2
+ import { useContext as a, useCallback as n } from "react";
3
+ import { G as c } from "../chunks/data-grid-GKyKxE6c.js";
4
+ import { r as f } from "../chunks/feature-registry-Y3KvnN54.js";
5
+ f("export", (i) => {
6
+ const t = typeof i == "boolean" ? {} : i ?? {};
7
+ return new p(t);
6
8
  });
9
+ function w() {
10
+ const i = a(c), t = n(() => i?.current?.getPlugin(p), [i]), x = n(
11
+ (e, o) => {
12
+ const r = t();
13
+ if (!r) {
14
+ console.warn(
15
+ `[tbw-grid:export] ExportPlugin not found.
16
+
17
+ → Enable export on the grid:
18
+ <DataGrid export />`
19
+ );
20
+ return;
21
+ }
22
+ r.exportCsv({ ...o, fileName: e ?? o?.fileName ?? "export.csv" });
23
+ },
24
+ [t]
25
+ ), l = n(
26
+ (e, o) => {
27
+ const r = t();
28
+ if (!r) {
29
+ console.warn(
30
+ `[tbw-grid:export] ExportPlugin not found.
31
+
32
+ → Enable export on the grid:
33
+ <DataGrid export />`
34
+ );
35
+ return;
36
+ }
37
+ r.exportExcel({ ...o, fileName: e ?? o?.fileName ?? "export.xlsx" });
38
+ },
39
+ [t]
40
+ ), s = n(
41
+ (e, o) => {
42
+ const r = t();
43
+ if (!r) {
44
+ console.warn(
45
+ `[tbw-grid:export] ExportPlugin not found.
46
+
47
+ → Enable export on the grid:
48
+ <DataGrid export />`
49
+ );
50
+ return;
51
+ }
52
+ r.exportJson({ ...o, fileName: e ?? o?.fileName ?? "export.json" });
53
+ },
54
+ [t]
55
+ ), u = n(() => t()?.isExporting() ?? !1, [t]), g = n(() => t()?.getLastExport() ?? null, [t]);
56
+ return {
57
+ exportToCsv: x,
58
+ exportToExcel: l,
59
+ exportToJson: s,
60
+ isExporting: u,
61
+ getLastExport: g
62
+ };
63
+ }
64
+ export {
65
+ w as useGridExport
66
+ };
@@ -1,16 +1,71 @@
1
+ import { FilterModel } from '@toolbox-web/grid/plugins/filtering';
1
2
  /**
2
- * Filtering feature for @toolbox-web/grid-react
3
+ * Filtering methods returned from useGridFiltering.
4
+ */
5
+ export interface FilteringMethods {
6
+ /**
7
+ * Set a filter on a specific field.
8
+ * @param field - The field name to filter
9
+ * @param filter - Filter configuration, or null to remove
10
+ */
11
+ setFilter: (field: string, filter: Omit<FilterModel, 'field'> | null) => void;
12
+ /**
13
+ * Get the current filter for a field.
14
+ */
15
+ getFilter: (field: string) => FilterModel | undefined;
16
+ /**
17
+ * Get all active filters.
18
+ */
19
+ getFilters: () => FilterModel[];
20
+ /**
21
+ * Set all filters at once (replaces existing).
22
+ */
23
+ setFilterModel: (filters: FilterModel[]) => void;
24
+ /**
25
+ * Clear all active filters.
26
+ */
27
+ clearAllFilters: () => void;
28
+ /**
29
+ * Clear filter for a specific field.
30
+ */
31
+ clearFieldFilter: (field: string) => void;
32
+ /**
33
+ * Check if a field has an active filter.
34
+ */
35
+ isFieldFiltered: (field: string) => boolean;
36
+ /**
37
+ * Get the count of rows after filtering.
38
+ */
39
+ getFilteredRowCount: () => number;
40
+ /**
41
+ * Get unique values for a field (for building filter dropdowns).
42
+ */
43
+ getUniqueValues: (field: string) => unknown[];
44
+ }
45
+ /**
46
+ * Hook for programmatic filter control.
3
47
  *
4
- * Import this module to enable the `filtering` prop on DataGrid.
48
+ * Must be used within a DataGrid component tree with filtering enabled.
5
49
  *
6
50
  * @example
7
51
  * ```tsx
8
- * import '@toolbox-web/grid-react/features/filtering';
52
+ * import { useGridFiltering } from '@toolbox-web/grid-react/features/filtering';
9
53
  *
10
- * <DataGrid filtering={{ debounceMs: 200 }} />
11
- * ```
54
+ * function QuickFilters() {
55
+ * const { setFilter, clearAllFilters, getFilteredRowCount, isFieldFiltered } = useGridFiltering();
12
56
  *
13
- * @packageDocumentation
57
+ * return (
58
+ * <div>
59
+ * <input
60
+ * placeholder="Filter by name..."
61
+ * onChange={(e) => setFilter('name', e.target.value ? { operator: 'contains', value: e.target.value } : null)}
62
+ * />
63
+ * <span>{getFilteredRowCount()} rows</span>
64
+ * <button onClick={clearAllFilters}>Clear All</button>
65
+ * </div>
66
+ * );
67
+ * }
68
+ * ```
14
69
  */
15
- export {};
70
+ export declare function useGridFiltering(): FilteringMethods;
16
71
  //# sourceMappingURL=filtering.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/features/filtering.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
1
+ {"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/features/filtering.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAUxF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;IAE9E;;OAEG;IACH,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,WAAW,GAAG,SAAS,CAAC;IAEtD;;OAEG;IACH,UAAU,EAAE,MAAM,WAAW,EAAE,CAAC;IAEhC;;OAEG;IACH,cAAc,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,IAAI,CAAC;IAEjD;;OAEG;IACH,eAAe,EAAE,MAAM,IAAI,CAAC;IAE5B;;OAEG;IACH,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1C;;OAEG;IACH,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAE5C;;OAEG;IACH,mBAAmB,EAAE,MAAM,MAAM,CAAC;IAElC;;OAEG;IACH,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,EAAE,CAAC;CAC/C;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,gBAAgB,IAAI,gBAAgB,CA0FnD"}
@@ -1,6 +1,82 @@
1
- import { FilteringPlugin as t } from "@toolbox-web/grid/plugins/filtering";
2
- import { r as o } from "../chunks/feature-registry-Y3KvnN54.js";
3
- o("filtering", (r) => {
4
- const e = typeof r == "boolean" ? {} : r ?? {};
5
- return new t(e);
1
+ import { FilteringPlugin as o } from "@toolbox-web/grid/plugins/filtering";
2
+ import { useContext as w, useCallback as i } from "react";
3
+ import { G as b } from "../chunks/data-grid-GKyKxE6c.js";
4
+ import { r as m } from "../chunks/feature-registry-Y3KvnN54.js";
5
+ m("filtering", (r) => {
6
+ const t = typeof r == "boolean" ? {} : r ?? {};
7
+ return new o(t);
6
8
  });
9
+ function h() {
10
+ const r = w(b), t = i(() => r?.current?.getPlugin(o), [r]), g = i(
11
+ (e, n) => {
12
+ const l = t();
13
+ if (!l) {
14
+ console.warn(
15
+ `[tbw-grid:filtering] FilteringPlugin not found.
16
+
17
+ → Enable filtering on the grid:
18
+ <DataGrid filtering />`
19
+ );
20
+ return;
21
+ }
22
+ l.setFilter(e, n);
23
+ },
24
+ [t]
25
+ ), s = i((e) => t()?.getFilter(e), [t]), u = i(() => t()?.getFilters() ?? [], [t]), d = i(
26
+ (e) => {
27
+ const n = t();
28
+ if (!n) {
29
+ console.warn(
30
+ `[tbw-grid:filtering] FilteringPlugin not found.
31
+
32
+ → Enable filtering on the grid:
33
+ <DataGrid filtering />`
34
+ );
35
+ return;
36
+ }
37
+ n.setFilterModel(e);
38
+ },
39
+ [t]
40
+ ), a = i(() => {
41
+ const e = t();
42
+ if (!e) {
43
+ console.warn(
44
+ `[tbw-grid:filtering] FilteringPlugin not found.
45
+
46
+ → Enable filtering on the grid:
47
+ <DataGrid filtering />`
48
+ );
49
+ return;
50
+ }
51
+ e.clearAllFilters();
52
+ }, [t]), f = i(
53
+ (e) => {
54
+ const n = t();
55
+ if (!n) {
56
+ console.warn(
57
+ `[tbw-grid:filtering] FilteringPlugin not found.
58
+
59
+ → Enable filtering on the grid:
60
+ <DataGrid filtering />`
61
+ );
62
+ return;
63
+ }
64
+ n.clearFieldFilter(e);
65
+ },
66
+ [t]
67
+ ), c = i((e) => t()?.isFieldFiltered(e) ?? !1, [t]), F = i(() => t()?.getFilteredRowCount() ?? 0, [t]), p = i((e) => t()?.getUniqueValues(e) ?? [], [t]);
68
+ return {
69
+ setFilter: g,
70
+ getFilter: s,
71
+ getFilters: u,
72
+ setFilterModel: d,
73
+ clearAllFilters: a,
74
+ clearFieldFilter: f,
75
+ isFieldFiltered: c,
76
+ getFilteredRowCount: F,
77
+ getUniqueValues: p
78
+ };
79
+ }
80
+ export {
81
+ h as useGridFiltering
82
+ };
@@ -1,16 +1,43 @@
1
+ import { PrintParams } from '@toolbox-web/grid/plugins/print';
1
2
  /**
2
- * Print feature for @toolbox-web/grid-react
3
+ * Print methods returned from useGridPrint.
4
+ */
5
+ export interface PrintMethods {
6
+ /**
7
+ * Print the grid.
8
+ * Opens browser print dialog after preparing the grid for printing.
9
+ * @param params - Optional print parameters
10
+ */
11
+ print: (params?: PrintParams) => Promise<void>;
12
+ /**
13
+ * Check if a print operation is currently in progress.
14
+ */
15
+ isPrinting: () => boolean;
16
+ }
17
+ /**
18
+ * Hook for programmatic print control.
3
19
  *
4
- * Import this module to enable the `print` prop on DataGrid.
20
+ * Must be used within a DataGrid component tree with print enabled.
5
21
  *
6
22
  * @example
7
23
  * ```tsx
8
- * import '@toolbox-web/grid-react/features/print';
24
+ * import { useGridPrint } from '@toolbox-web/grid-react/features/print';
9
25
  *
10
- * <DataGrid print />
11
- * ```
26
+ * function PrintToolbar() {
27
+ * const { print, isPrinting } = useGridPrint();
12
28
  *
13
- * @packageDocumentation
29
+ * const handlePrint = async () => {
30
+ * await print({ title: 'My Report', isolate: true });
31
+ * console.log('Print dialog closed');
32
+ * };
33
+ *
34
+ * return (
35
+ * <button onClick={handlePrint} disabled={isPrinting()}>
36
+ * {isPrinting() ? 'Printing...' : 'Print Report'}
37
+ * </button>
38
+ * );
39
+ * }
40
+ * ```
14
41
  */
15
- export {};
42
+ export declare function useGridPrint(): PrintMethods;
16
43
  //# sourceMappingURL=print.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"print.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/features/print.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
1
+ {"version":3,"file":"print.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/features/print.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAYhF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/C;;OAEG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,YAAY,IAAI,YAAY,CAyB3C"}
package/features/print.js CHANGED
@@ -1,3 +1,27 @@
1
- import { PrintPlugin as e } from "@toolbox-web/grid/plugins/print";
2
- import { r as t } from "../chunks/feature-registry-Y3KvnN54.js";
3
- t("print", (r) => r === !0 ? new e() : new e(r ?? void 0));
1
+ import { PrintPlugin as i } from "@toolbox-web/grid/plugins/print";
2
+ import { useContext as g, useCallback as n } from "react";
3
+ import { G as a } from "../chunks/data-grid-GKyKxE6c.js";
4
+ import { r as p } from "../chunks/feature-registry-Y3KvnN54.js";
5
+ p("print", (r) => r === !0 ? new i() : new i(r ?? void 0));
6
+ function m() {
7
+ const r = g(a), t = n(() => r?.current?.getPlugin(i), [r]), u = n(
8
+ async (e) => {
9
+ const o = t();
10
+ if (!o) {
11
+ console.warn(
12
+ `[tbw-grid:print] PrintPlugin not found.
13
+
14
+ → Enable print on the grid:
15
+ <DataGrid print />`
16
+ );
17
+ return;
18
+ }
19
+ await o.print(e);
20
+ },
21
+ [t]
22
+ ), s = n(() => t()?.isPrinting() ?? !1, [t]);
23
+ return { print: u, isPrinting: s };
24
+ }
25
+ export {
26
+ m as useGridPrint
27
+ };
@@ -1,16 +1,56 @@
1
+ import { CellRange, SelectionResult } from '@toolbox-web/grid/plugins/selection';
1
2
  /**
2
- * Selection feature for @toolbox-web/grid-react
3
+ * Selection methods returned from useGridSelection.
3
4
  *
4
- * Import this module to enable the `selection` prop on DataGrid.
5
+ * Uses React context to access the grid ref - works reliably regardless of
6
+ * when the grid mounts or conditional rendering.
7
+ */
8
+ export interface SelectionMethods {
9
+ /**
10
+ * Select all rows (row mode) or all cells (range mode).
11
+ */
12
+ selectAll: () => void;
13
+ /**
14
+ * Clear all selection.
15
+ */
16
+ clearSelection: () => void;
17
+ /**
18
+ * Get the current selection state.
19
+ * Use this to derive selected rows, indices, etc.
20
+ */
21
+ getSelection: () => SelectionResult | null;
22
+ /**
23
+ * Check if a specific cell is selected.
24
+ */
25
+ isCellSelected: (row: number, col: number) => boolean;
26
+ /**
27
+ * Set selection ranges programmatically.
28
+ */
29
+ setRanges: (ranges: CellRange[]) => void;
30
+ }
31
+ /**
32
+ * Hook for programmatic selection control.
33
+ *
34
+ * Must be used within a DataGrid component tree with the selection feature enabled.
35
+ * Uses React context, so it works reliably regardless of when the grid mounts.
5
36
  *
6
37
  * @example
7
38
  * ```tsx
8
- * import '@toolbox-web/grid-react/features/selection';
39
+ * import { useGridSelection } from '@toolbox-web/grid-react/features/selection';
9
40
  *
10
- * <DataGrid selection="range" />
11
- * ```
41
+ * function ExportSelectedButton() {
42
+ * const { getSelection, clearSelection } = useGridSelection();
43
+ *
44
+ * const handleExport = () => {
45
+ * const selection = getSelection();
46
+ * if (!selection) return;
47
+ * // Derive rows from selection.ranges and grid.rows
48
+ * clearSelection();
49
+ * };
12
50
  *
13
- * @packageDocumentation
51
+ * return <button onClick={handleExport}>Export Selected</button>;
52
+ * }
53
+ * ```
14
54
  */
15
- export {};
55
+ export declare function useGridSelection<TRow = unknown>(): SelectionMethods;
16
56
  //# sourceMappingURL=selection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/features/selection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
1
+ {"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/features/selection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,EAAmB,KAAK,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAc5G;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,SAAS,EAAE,MAAM,IAAI,CAAC;IAEtB;;OAEG;IACH,cAAc,EAAE,MAAM,IAAI,CAAC;IAE3B;;;OAGG;IACH,YAAY,EAAE,MAAM,eAAe,GAAG,IAAI,CAAC;IAE3C;;OAEG;IACH,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IAEtD;;OAEG;IACH,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,GAAG,OAAO,KAAK,gBAAgB,CAkEnE"}
@@ -1,3 +1,48 @@
1
- import { SelectionPlugin as r } from "@toolbox-web/grid/plugins/selection";
2
- import { r as t } from "../chunks/feature-registry-Y3KvnN54.js";
3
- t("selection", (e) => e === "cell" || e === "row" || e === "range" ? new r({ mode: e }) : new r(e ?? void 0));
1
+ import { SelectionPlugin as i } from "@toolbox-web/grid/plugins/selection";
2
+ import { useContext as w, useCallback as o } from "react";
3
+ import { G as S } from "../chunks/data-grid-GKyKxE6c.js";
4
+ import { r as C } from "../chunks/feature-registry-Y3KvnN54.js";
5
+ C("selection", (e) => e === "cell" || e === "row" || e === "range" ? new i({ mode: e }) : new i(e ?? void 0));
6
+ function P() {
7
+ const e = w(S), t = o(() => e?.current?.getPlugin(i), [e]), g = o(() => {
8
+ const n = t();
9
+ if (!n) {
10
+ console.warn(
11
+ `[tbw-grid:selection] SelectionPlugin not found.
12
+
13
+ → Enable selection on the grid:
14
+ <DataGrid selection="range" />`
15
+ );
16
+ return;
17
+ }
18
+ const r = e?.current, u = n.config?.mode;
19
+ if (u === "row") {
20
+ const s = r?.rows?.length ?? 0, l = /* @__PURE__ */ new Set();
21
+ for (let c = 0; c < s; c++) l.add(c);
22
+ n.selected = l, n.requestAfterRender?.();
23
+ } else if (u === "range") {
24
+ const s = r?.rows?.length ?? 0, l = r?._columns?.length ?? 0;
25
+ s > 0 && l > 0 && n.setRanges([{ from: { row: 0, col: 0 }, to: { row: s - 1, col: l - 1 } }]);
26
+ }
27
+ }, [t, e]), d = o(() => {
28
+ t()?.clearSelection();
29
+ }, [t]), a = o(() => t()?.getSelection() ?? null, [t]), m = o(
30
+ (n, r) => t()?.isCellSelected(n, r) ?? !1,
31
+ [t]
32
+ ), f = o(
33
+ (n) => {
34
+ t()?.setRanges(n);
35
+ },
36
+ [t]
37
+ );
38
+ return {
39
+ selectAll: g,
40
+ clearSelection: d,
41
+ getSelection: a,
42
+ isCellSelected: m,
43
+ setRanges: f
44
+ };
45
+ }
46
+ export {
47
+ P as useGridSelection
48
+ };
@@ -1,18 +1,60 @@
1
+ import { EditAction } from '@toolbox-web/grid/plugins/undo-redo';
1
2
  /**
2
- * Undo/Redo feature for @toolbox-web/grid-react
3
+ * Undo/Redo methods returned from useGridUndoRedo.
4
+ */
5
+ export interface UndoRedoMethods {
6
+ /**
7
+ * Undo the last edit action.
8
+ * @returns The undone action, or null if nothing to undo
9
+ */
10
+ undo: () => EditAction | null;
11
+ /**
12
+ * Redo the last undone action.
13
+ * @returns The redone action, or null if nothing to redo
14
+ */
15
+ redo: () => EditAction | null;
16
+ /**
17
+ * Check if there are any actions that can be undone.
18
+ */
19
+ canUndo: () => boolean;
20
+ /**
21
+ * Check if there are any actions that can be redone.
22
+ */
23
+ canRedo: () => boolean;
24
+ /**
25
+ * Clear all undo/redo history.
26
+ */
27
+ clearHistory: () => void;
28
+ /**
29
+ * Get a copy of the current undo stack.
30
+ */
31
+ getUndoStack: () => EditAction[];
32
+ /**
33
+ * Get a copy of the current redo stack.
34
+ */
35
+ getRedoStack: () => EditAction[];
36
+ }
37
+ /**
38
+ * Hook for programmatic undo/redo control.
3
39
  *
4
- * Import this module to enable the `undoRedo` prop on DataGrid.
5
- * Requires the editing feature to be enabled.
40
+ * Must be used within a DataGrid component tree with undoRedo and editing enabled.
6
41
  *
7
42
  * @example
8
43
  * ```tsx
9
- * import '@toolbox-web/grid-react/features/editing';
10
- * import '@toolbox-web/grid-react/features/undo-redo';
44
+ * import { useGridUndoRedo } from '@toolbox-web/grid-react/features/undo-redo';
11
45
  *
12
- * <DataGrid editing="dblclick" undoRedo={{ maxHistorySize: 100 }} />
13
- * ```
46
+ * function UndoRedoControls() {
47
+ * const { undo, redo, canUndo, canRedo, clearHistory } = useGridUndoRedo();
14
48
  *
15
- * @packageDocumentation
49
+ * return (
50
+ * <div>
51
+ * <button onClick={undo} disabled={!canUndo()}>Undo</button>
52
+ * <button onClick={redo} disabled={!canRedo()}>Redo</button>
53
+ * <button onClick={clearHistory}>Clear History</button>
54
+ * </div>
55
+ * );
56
+ * }
57
+ * ```
16
58
  */
17
- export {};
59
+ export declare function useGridUndoRedo(): UndoRedoMethods;
18
60
  //# sourceMappingURL=undo-redo.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"undo-redo.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/features/undo-redo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG"}
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,6 +1,43 @@
1
- import { UndoRedoPlugin as r } from "@toolbox-web/grid/plugins/undo-redo";
2
- import { r as t } from "../chunks/feature-registry-Y3KvnN54.js";
3
- t("undoRedo", (o) => {
4
- const e = typeof o == "boolean" ? {} : o ?? {};
5
- return new r(e);
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-GKyKxE6c.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);
6
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(
13
+ `[tbw-grid:undoRedo] UndoRedoPlugin not found.
14
+
15
+ → Enable undo/redo on the grid:
16
+ <DataGrid editing="dblclick" undoRedo />`
17
+ ), null);
18
+ }, [o]), i = e(() => {
19
+ const n = o();
20
+ return n ? n.redo() : (console.warn(
21
+ `[tbw-grid:undoRedo] UndoRedoPlugin not found.
22
+
23
+ → Enable undo/redo on the grid:
24
+ <DataGrid editing="dblclick" undoRedo />`
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) {
29
+ console.warn(
30
+ `[tbw-grid:undoRedo] UndoRedoPlugin not found.
31
+
32
+ → Enable undo/redo on the grid:
33
+ <DataGrid editing="dblclick" undoRedo />`
34
+ );
35
+ return;
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 };
40
+ }
41
+ export {
42
+ k as useGridUndoRedo
43
+ };