@nu-grid/nuxt 0.2.0 → 0.3.1

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.
Files changed (69) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/runtime/cell-types/date/index.d.ts +1 -1
  3. package/dist/runtime/cell-types/date/index.js +15 -1
  4. package/dist/runtime/cell-types/index.d.ts +2 -1
  5. package/dist/runtime/cell-types/index.js +3 -0
  6. package/dist/runtime/cell-types/number/NumberFilter.vue +1 -1
  7. package/dist/runtime/cell-types/percentage/PercentageEditor.d.vue.ts +15 -0
  8. package/dist/runtime/cell-types/percentage/PercentageEditor.vue +56 -0
  9. package/dist/runtime/cell-types/percentage/PercentageEditor.vue.d.ts +15 -0
  10. package/dist/runtime/cell-types/percentage/PercentageFilter.d.vue.ts +7 -0
  11. package/dist/runtime/cell-types/percentage/PercentageFilter.vue +79 -0
  12. package/dist/runtime/cell-types/percentage/PercentageFilter.vue.d.ts +7 -0
  13. package/dist/runtime/cell-types/percentage/index.d.ts +10 -0
  14. package/dist/runtime/cell-types/percentage/index.js +38 -0
  15. package/dist/runtime/components/NuGrid.d.vue.ts +8 -5
  16. package/dist/runtime/components/NuGrid.vue +46 -10
  17. package/dist/runtime/components/NuGrid.vue.d.ts +8 -5
  18. package/dist/runtime/components/_internal/NuGridBase.vue +129 -83
  19. package/dist/runtime/components/_internal/NuGridCellContent.vue +21 -1
  20. package/dist/runtime/components/_internal/NuGridColumnMenu.vue +2 -2
  21. package/dist/runtime/components/_internal/NuGridGroup.vue +23 -16
  22. package/dist/runtime/components/_internal/NuGridGroupCheckbox.vue +1 -1
  23. package/dist/runtime/components/_internal/NuGridRow.vue +12 -4
  24. package/dist/runtime/components/_internal/NuGridSplitGroup.vue +23 -17
  25. package/dist/runtime/composables/_internal/column-flex-style.d.ts +22 -0
  26. package/dist/runtime/composables/_internal/column-flex-style.js +84 -0
  27. package/dist/runtime/composables/_internal/index.d.ts +1 -0
  28. package/dist/runtime/composables/_internal/index.js +1 -0
  29. package/dist/runtime/composables/_internal/useNuGridAddRow.js +5 -1
  30. package/dist/runtime/composables/_internal/useNuGridAutosize.d.ts +6 -3
  31. package/dist/runtime/composables/_internal/useNuGridAutosize.js +91 -9
  32. package/dist/runtime/composables/_internal/useNuGridCellEditing.js +3 -2
  33. package/dist/runtime/composables/_internal/useNuGridColumnResize.d.ts +17 -7
  34. package/dist/runtime/composables/_internal/useNuGridColumnResize.js +219 -8
  35. package/dist/runtime/composables/_internal/useNuGridCore.d.ts +1 -1
  36. package/dist/runtime/composables/_internal/useNuGridCore.js +16 -5
  37. package/dist/runtime/composables/_internal/useNuGridFocus.js +1 -1
  38. package/dist/runtime/composables/_internal/useNuGridRowSelection.js +1 -1
  39. package/dist/runtime/composables/_internal/useNuGridStatePersistence.d.ts +14 -1
  40. package/dist/runtime/composables/_internal/useNuGridStatePersistence.js +66 -3
  41. package/dist/runtime/composables/_internal/useNuGridUI.d.ts +147 -31
  42. package/dist/runtime/config/_internal/options-defaults.d.ts +2 -4
  43. package/dist/runtime/config/_internal/options-defaults.js +3 -4
  44. package/dist/runtime/config/_internal/prop-utils.d.ts +7 -1
  45. package/dist/runtime/config/_internal/prop-utils.js +20 -6
  46. package/dist/runtime/config/presets.js +2 -2
  47. package/dist/runtime/themes/nuGridTheme.d.ts +3 -1
  48. package/dist/runtime/themes/nuGridTheme.js +9 -5
  49. package/dist/runtime/themes/nuGridThemeCompact.d.ts +3 -1
  50. package/dist/runtime/themes/nuGridThemeCompact.js +8 -4
  51. package/dist/runtime/types/_internal/contexts/resize.d.ts +1 -0
  52. package/dist/runtime/types/_internal/contexts/ui-config.d.ts +4 -2
  53. package/dist/runtime/types/autosize.d.ts +4 -1
  54. package/dist/runtime/types/column.d.ts +41 -3
  55. package/dist/runtime/types/index.d.ts +2 -1
  56. package/dist/runtime/types/option-groups.d.ts +26 -8
  57. package/dist/runtime/types/props.d.ts +34 -9
  58. package/dist/runtime/types/resize.d.ts +2 -0
  59. package/dist/runtime/types/slots.d.ts +32 -0
  60. package/dist/runtime/types/slots.js +0 -0
  61. package/dist/runtime/types/tanstack-table.d.ts +3 -2
  62. package/dist/runtime/utils/index.d.ts +1 -0
  63. package/dist/runtime/utils/index.js +1 -0
  64. package/dist/runtime/utils/inferCellDataType.d.ts +27 -0
  65. package/dist/runtime/utils/inferCellDataType.js +91 -0
  66. package/package.json +5 -5
  67. package/dist/runtime/components/NuGridGroup.d.vue.ts +0 -20
  68. package/dist/runtime/components/NuGridGroup.vue +0 -650
  69. package/dist/runtime/components/NuGridGroup.vue.d.ts +0 -20
@@ -1,13 +1,173 @@
1
- import { onUnmounted, ref } from "vue";
1
+ import { nextTick, onMounted, onUnmounted, ref, watch } from "vue";
2
2
  function isTouchStartEvent(e) {
3
3
  return e.type === "touchstart";
4
4
  }
5
- export function useNuGridColumnResize(props, tableApi) {
5
+ export function useNuGridColumnResize(props, tableApi, tableRef) {
6
6
  const resizingGroupId = ref(null);
7
7
  const resizingColumnId = ref(null);
8
+ const manuallyResizedColumns = ref(/* @__PURE__ */ new Set());
9
+ const resizeStartSizes = /* @__PURE__ */ new Map();
10
+ function syncColumnWidthsFromDOM(columnIds) {
11
+ if (!tableRef.value) return;
12
+ const newSizing = {};
13
+ const tbody = tableRef.value.querySelector("[data-tbody]");
14
+ const firstRow = tbody?.querySelector("[data-row-id]");
15
+ for (const columnId of columnIds) {
16
+ let measuredWidth = 0;
17
+ if (firstRow) {
18
+ const bodyCell = firstRow.querySelector(`[data-column-id="${columnId}"]`);
19
+ if (bodyCell) {
20
+ const rect = bodyCell.getBoundingClientRect();
21
+ measuredWidth = rect.width;
22
+ }
23
+ }
24
+ if (measuredWidth === 0) {
25
+ const headerCell = tableRef.value.querySelector(
26
+ `[data-column-id="${columnId}"]`
27
+ );
28
+ if (headerCell) {
29
+ const rect = headerCell.getBoundingClientRect();
30
+ measuredWidth = rect.width;
31
+ }
32
+ }
33
+ if (measuredWidth > 0) {
34
+ newSizing[columnId] = measuredWidth;
35
+ }
36
+ }
37
+ if (Object.keys(newSizing).length > 0) {
38
+ tableApi.setColumnSizing((old) => ({
39
+ ...old,
40
+ ...newSizing
41
+ }));
42
+ }
43
+ }
44
+ let stateWasRestored = false;
45
+ function syncInitialFlexWidths(forceSync = false) {
46
+ if (props.layout?.autoSize !== "fill") return;
47
+ if (!tableRef.value) return;
48
+ if (stateWasRestored && !forceSync) {
49
+ stateWasRestored = false;
50
+ return;
51
+ }
52
+ if (!forceSync) {
53
+ const currentSizing = tableApi.getState().columnSizing;
54
+ const restoredColumnIds = Object.keys(currentSizing);
55
+ if (restoredColumnIds.length > 0) {
56
+ manuallyResizedColumns.value = new Set(restoredColumnIds);
57
+ return;
58
+ }
59
+ }
60
+ const allColumns = tableApi.getVisibleLeafColumns();
61
+ const flexColumns = allColumns.filter((col) => {
62
+ const colDef = col.columnDef;
63
+ return colDef.grow !== false;
64
+ }).map((col) => col.id);
65
+ if (flexColumns.length === 0) return;
66
+ syncColumnWidthsFromDOM(flexColumns);
67
+ manuallyResizedColumns.value = new Set(flexColumns);
68
+ }
69
+ function getContainerWidth() {
70
+ if (!tableRef.value) return 0;
71
+ const rootEl = tableRef.value.parentElement;
72
+ return rootEl?.getBoundingClientRect().width ?? 0;
73
+ }
74
+ function getSizingAsRatios() {
75
+ const containerWidth = getContainerWidth();
76
+ if (containerWidth === 0) return {};
77
+ const currentSizing = tableApi.getState().columnSizing;
78
+ const ratios = {};
79
+ for (const [columnId, pixelWidth] of Object.entries(currentSizing)) {
80
+ ratios[columnId] = pixelWidth / containerWidth;
81
+ }
82
+ return ratios;
83
+ }
84
+ function applySizingFromRatios(ratios) {
85
+ const containerWidth = getContainerWidth();
86
+ if (containerWidth === 0) return;
87
+ const pixelSizing = {};
88
+ const columnIds = [];
89
+ for (const [columnId, ratio] of Object.entries(ratios)) {
90
+ pixelSizing[columnId] = Math.round(ratio * containerWidth);
91
+ columnIds.push(columnId);
92
+ }
93
+ if (Object.keys(pixelSizing).length > 0) {
94
+ stateWasRestored = true;
95
+ tableApi.setColumnSizing((old) => ({
96
+ ...old,
97
+ ...pixelSizing
98
+ }));
99
+ manuallyResizedColumns.value = /* @__PURE__ */ new Set([...manuallyResizedColumns.value, ...columnIds]);
100
+ }
101
+ }
102
+ function applyRestoredSizing(sizing) {
103
+ if (Object.keys(sizing).length === 0) return;
104
+ stateWasRestored = true;
105
+ manuallyResizedColumns.value = /* @__PURE__ */ new Set([
106
+ ...manuallyResizedColumns.value,
107
+ ...Object.keys(sizing)
108
+ ]);
109
+ }
110
+ let lastContainerWidth = 0;
111
+ let resizeObserver = null;
112
+ let rafId = null;
113
+ function handleContainerResize(entries) {
114
+ const entry = entries[0];
115
+ if (!entry) return;
116
+ const newWidth = entry.contentRect.width;
117
+ if (Math.abs(newWidth - lastContainerWidth) > 1) {
118
+ lastContainerWidth = newWidth;
119
+ if (rafId !== null) {
120
+ cancelAnimationFrame(rafId);
121
+ }
122
+ rafId = requestAnimationFrame(() => {
123
+ rafId = null;
124
+ manuallyResizedColumns.value = /* @__PURE__ */ new Set();
125
+ nextTick(() => {
126
+ syncInitialFlexWidths(true);
127
+ });
128
+ });
129
+ }
130
+ }
131
+ onMounted(() => {
132
+ nextTick(() => {
133
+ nextTick(() => {
134
+ syncInitialFlexWidths();
135
+ if (tableRef.value && typeof ResizeObserver !== "undefined") {
136
+ const rootEl = tableRef.value.parentElement;
137
+ if (rootEl) {
138
+ lastContainerWidth = rootEl.getBoundingClientRect().width;
139
+ resizeObserver = new ResizeObserver(handleContainerResize);
140
+ resizeObserver.observe(rootEl);
141
+ }
142
+ }
143
+ });
144
+ });
145
+ });
146
+ watch(
147
+ () => props.layout?.autoSize,
148
+ (newValue, oldValue) => {
149
+ if (newValue === "fill" && oldValue !== "fill") {
150
+ manuallyResizedColumns.value = /* @__PURE__ */ new Set();
151
+ nextTick(() => {
152
+ nextTick(() => {
153
+ syncInitialFlexWidths();
154
+ });
155
+ });
156
+ }
157
+ }
158
+ );
159
+ onUnmounted(() => {
160
+ if (resizeObserver) {
161
+ resizeObserver.disconnect();
162
+ resizeObserver = null;
163
+ }
164
+ if (rafId !== null) {
165
+ cancelAnimationFrame(rafId);
166
+ }
167
+ });
8
168
  function getResizeHandler(header) {
9
- if (props.layout?.maintainWidth) {
10
- return createMaintainWidthResizeHandler(header, tableApi);
169
+ if (props.layout?.resizeMode === "shift") {
170
+ return createShiftResizeHandler(header, tableApi, manuallyResizedColumns);
11
171
  }
12
172
  return header.getResizeHandler();
13
173
  }
@@ -17,6 +177,37 @@ export function useNuGridColumnResize(props, tableApi) {
17
177
  event.stopPropagation();
18
178
  document.body.classList.add("is-resizing-column");
19
179
  resizingColumnId.value = header.column.id;
180
+ if (props.layout?.autoSize === "fill") {
181
+ const allColumns = tableApi.getVisibleLeafColumns();
182
+ const columnsToSync = allColumns.filter((col) => {
183
+ const colDef = col.columnDef;
184
+ return colDef.grow !== false && !manuallyResizedColumns.value.has(col.id);
185
+ }).map((col) => col.id);
186
+ syncColumnWidthsFromDOM(columnsToSync);
187
+ const newSet = new Set(manuallyResizedColumns.value);
188
+ newSet.add(header.column.id);
189
+ if (props.layout?.resizeMode === "shift") {
190
+ const currentIndex = allColumns.findIndex((col) => col.id === header.column.id);
191
+ if (currentIndex >= 0 && currentIndex < allColumns.length - 1) {
192
+ const nextColumn = allColumns[currentIndex + 1];
193
+ if (nextColumn) {
194
+ newSet.add(nextColumn.id);
195
+ }
196
+ }
197
+ }
198
+ manuallyResizedColumns.value = newSet;
199
+ }
200
+ resizeStartSizes.set(header.column.id, header.column.getSize());
201
+ if (props.layout?.resizeMode === "shift") {
202
+ const allColumns = tableApi.getVisibleLeafColumns();
203
+ const currentIndex = allColumns.findIndex((col) => col.id === header.column.id);
204
+ if (currentIndex >= 0 && currentIndex < allColumns.length - 1) {
205
+ const nextColumn = allColumns[currentIndex + 1];
206
+ if (nextColumn) {
207
+ resizeStartSizes.set(nextColumn.id, nextColumn.getSize());
208
+ }
209
+ }
210
+ }
20
211
  resizeHandler(event);
21
212
  }
22
213
  }
@@ -28,11 +219,25 @@ export function useNuGridColumnResize(props, tableApi) {
28
219
  document.body.classList.add("is-resizing-column");
29
220
  resizingColumnId.value = null;
30
221
  resizingGroupId.value = header.id;
31
- const resizeHandler = createGroupResizeHandler(header, tableApi);
222
+ const leafHeaders = header.getLeafHeaders();
223
+ for (const leafHeader of leafHeaders) {
224
+ resizeStartSizes.set(leafHeader.column.id, leafHeader.column.getSize());
225
+ }
226
+ const resizeHandler = createGroupResizeHandler(header, tableApi, manuallyResizedColumns);
32
227
  resizeHandler(event);
33
228
  }
34
229
  function handleResizeEnd() {
35
230
  document.body.classList.remove("is-resizing-column");
231
+ for (const [columnId, startSize] of resizeStartSizes) {
232
+ const column = tableApi.getColumn(columnId);
233
+ if (column) {
234
+ const currentSize = column.getSize();
235
+ if (Math.abs(currentSize - startSize) > 1) {
236
+ manuallyResizedColumns.value = /* @__PURE__ */ new Set([...manuallyResizedColumns.value, columnId]);
237
+ }
238
+ }
239
+ }
240
+ resizeStartSizes.clear();
36
241
  resizingColumnId.value = null;
37
242
  resizingGroupId.value = null;
38
243
  }
@@ -51,10 +256,16 @@ export function useNuGridColumnResize(props, tableApi) {
51
256
  handleGroupResizeStart,
52
257
  handleResizeEnd,
53
258
  resizingGroupId,
54
- resizingColumnId
259
+ resizingColumnId,
260
+ manuallyResizedColumns,
261
+ // State persistence helpers
262
+ getContainerWidth,
263
+ getSizingAsRatios,
264
+ applySizingFromRatios,
265
+ applyRestoredSizing
55
266
  };
56
267
  }
57
- export function createMaintainWidthResizeHandler(header, table) {
268
+ export function createShiftResizeHandler(header, table, _manuallyResizedColumns) {
58
269
  return (e) => {
59
270
  const column = table.getColumn(header.column.id);
60
271
  const canResize = column?.getCanResize();
@@ -209,7 +420,7 @@ export function createMaintainWidthResizeHandler(header, table) {
209
420
  }));
210
421
  };
211
422
  }
212
- export function createGroupResizeHandler(header, table) {
423
+ export function createGroupResizeHandler(header, table, _manuallyResizedColumns) {
213
424
  return (e) => {
214
425
  ;
215
426
  e.persist?.();
@@ -6,7 +6,7 @@ import type { NuGridRowSelectionMode, NuGridStates, PinnableHeader, UseNuGridCol
6
6
  /**
7
7
  * Shared logic for processing columns with default cell renderers
8
8
  */
9
- export declare function useNuGridColumns<T extends TableData>(propsColumns: Ref<NuGridColumn<T>[] | undefined>, data: Ref<T[]>, rowSelectionMode?: Ref<NuGridRowSelectionMode<T>>, actionMenuOptions?: Ref<NuGridActionMenuOptions<T> | undefined | false>, columnVisibilityState?: Ref<VisibilityState>): UseNuGridColumnsReturn<T>;
9
+ export declare function useNuGridColumns<T extends TableData>(propsColumns: Ref<NuGridColumn<T>[] | undefined>, data: Ref<T[]>, rowSelectionMode?: Ref<NuGridRowSelectionMode<T>>, actionMenuOptions?: Ref<NuGridActionMenuOptions<T> | undefined | false>, columnVisibilityState?: Ref<VisibilityState>, dataTypeInference?: Ref<boolean>): UseNuGridColumnsReturn<T>;
10
10
  /**
11
11
  * Helper function to update state values
12
12
  */
@@ -11,18 +11,20 @@ import { createReusableTemplate, reactiveOmit } from "@vueuse/core";
11
11
  import { upperFirst } from "scule";
12
12
  import { computed, watch } from "vue";
13
13
  import { nuGridDefaults } from "../../config/_internal/index.js";
14
+ import { extractColumnValues, inferCellDataType } from "../../utils/inferCellDataType.js";
14
15
  import { nuGridCellTypeRegistry } from "../useNuGridCellTypeRegistry.js";
15
16
  import { useNuGridActionMenu } from "./useNuGridActionMenu.js";
16
17
  import { useNuGridRowSelection } from "./useNuGridRowSelection.js";
17
- export function useNuGridColumns(propsColumns, data, rowSelectionMode, actionMenuOptions, columnVisibilityState) {
18
+ export function useNuGridColumns(propsColumns, data, rowSelectionMode, actionMenuOptions, columnVisibilityState, dataTypeInference) {
18
19
  const rowSelection = rowSelectionMode ? useNuGridRowSelection(rowSelectionMode, columnVisibilityState) : null;
19
20
  const actionMenu = actionMenuOptions ? useNuGridActionMenu(actionMenuOptions, columnVisibilityState) : null;
20
21
  const columns = computed(() => {
22
+ const inferenceEnabled = dataTypeInference?.value !== false;
21
23
  const cols = propsColumns.value ?? Object.keys(data.value[0] ?? {}).map((accessorKey) => ({
22
24
  accessorKey,
23
25
  header: upperFirst(accessorKey)
24
26
  }));
25
- let processedCols = processColumns(cols);
27
+ let processedCols = processColumns(cols, inferenceEnabled);
26
28
  if (rowSelection) {
27
29
  processedCols = rowSelection.prependSelectionColumn(processedCols);
28
30
  }
@@ -32,14 +34,23 @@ export function useNuGridColumns(propsColumns, data, rowSelectionMode, actionMen
32
34
  return processedCols;
33
35
  });
34
36
  const pluginCache = /* @__PURE__ */ new Map();
35
- function processColumns(columns2) {
37
+ function processColumns(columns2, inferenceEnabled) {
36
38
  return columns2.map((column) => {
37
39
  const col = { ...column };
38
40
  if ("columns" in col && col.columns) {
39
- col.columns = processColumns(col.columns);
41
+ col.columns = processColumns(col.columns, inferenceEnabled);
42
+ }
43
+ const accessorKey = col.accessorKey;
44
+ if (inferenceEnabled && col.cellDataType === void 0 && accessorKey && data.value.length > 0) {
45
+ const values = extractColumnValues(data.value, accessorKey);
46
+ const inferredType = inferCellDataType(values, accessorKey);
47
+ if (inferredType) {
48
+ ;
49
+ col.cellDataType = inferredType;
50
+ }
40
51
  }
41
52
  const cellDataType = col.cellDataType;
42
- if (cellDataType) {
53
+ if (cellDataType && cellDataType !== false) {
43
54
  let plugin = pluginCache.get(cellDataType);
44
55
  if (plugin === void 0) {
45
56
  plugin = nuGridCellTypeRegistry.get(cellDataType);
@@ -9,7 +9,7 @@ export function useNuGridFocus(props, tableApi, rows, navigableRows, tableRef, r
9
9
  const cmdArrows = usePropWithDefault(props, "focus", "cmdArrows");
10
10
  const alignOnModel = usePropWithDefault(props, "focus", "alignOnModel");
11
11
  const enableEditing = usePropWithDefault(props, "editing", "enabled");
12
- const rowSelectionMode = computed(() => props.selection ?? false);
12
+ const rowSelectionMode = computed(() => props.rowSelection ?? false);
13
13
  const focusedCell = ref(null);
14
14
  const gridHasFocus = ref(false);
15
15
  let pointerDownInsideGrid = false;
@@ -2,7 +2,7 @@ import { computed, h, ref, watch } from "vue";
2
2
  import NuGridCellCheckbox from "../../components/NuGridCellCheckbox.vue";
3
3
  import { getDefaults } from "../../config/_internal/index.js";
4
4
  import { nuGridCellTypeRegistry } from "../useNuGridCellTypeRegistry.js";
5
- const selectionDefaults = getDefaults("selection");
5
+ const selectionDefaults = getDefaults("rowSelection");
6
6
  const selectionTotalsCache = /* @__PURE__ */ new WeakMap();
7
7
  function createSelectionColumn(modeRef, enabledRef, rowSelectionEnabledRef, columnDef) {
8
8
  const defaultColumn = {
@@ -10,6 +10,8 @@ export interface NuGridStateSnapshot {
10
10
  columnPinning?: ColumnPinningState;
11
11
  columnSizing?: ColumnSizingState;
12
12
  columnSizingInfo?: ColumnSizingInfoState;
13
+ /** Column sizing stored as ratios (0-1) relative to container width for resolution-independent persistence */
14
+ columnSizingRatios?: Record<string, number>;
13
15
  rowSelection?: RowSelectionState;
14
16
  rowPinning?: RowPinningState;
15
17
  sorting?: SortingState;
@@ -17,11 +19,22 @@ export interface NuGridStateSnapshot {
17
19
  expanded?: ExpandedState;
18
20
  pagination?: PaginationState;
19
21
  }
22
+ export interface NuGridStatePersistenceHelpers {
23
+ /** Get current container width for ratio calculations */
24
+ getContainerWidth: () => number;
25
+ /** Get current sizing as ratios */
26
+ getSizingAsRatios: () => Record<string, number>;
27
+ /** Apply sizing from ratios and mark columns as manually resized */
28
+ applySizingFromRatios: (ratios: Record<string, number>) => void;
29
+ }
20
30
  /**
21
31
  * Composable for persisting and restoring NuGrid state to/from localStorage and cookies
22
32
  * Handles all state initialization, restoration, and persistence logic
23
33
  */
24
- export declare function useNuGridStatePersistence<T extends TableData = TableData>(states: NuGridStates, enabled: boolean, storageId: string | undefined, onStateChanged?: (state: NuGridStateSnapshot) => void, eventEmitter?: NuGridEventEmitter<T>): {
34
+ export declare function useNuGridStatePersistence<T extends TableData = TableData>(states: NuGridStates, enabled: boolean, storageId: string | undefined, onStateChanged?: (state: NuGridStateSnapshot) => void, eventEmitter?: NuGridEventEmitter<T>, resizeHelpers?: NuGridStatePersistenceHelpers): {
25
35
  getState: () => {};
26
36
  setState: (_snapshot: NuGridStateSnapshot) => void;
37
+ clearState: () => void;
38
+ applyPendingRatios: () => void;
39
+ setResizeHelpers: (_helpers: NuGridStatePersistenceHelpers) => void;
27
40
  };
@@ -1,17 +1,25 @@
1
1
  import { useCookie } from "#imports";
2
2
  import { StorageSerializers, useStorage } from "@vueuse/core";
3
3
  import { nextTick, onMounted, watch } from "vue";
4
- export function useNuGridStatePersistence(states, enabled, storageId, onStateChanged, eventEmitter) {
4
+ export function useNuGridStatePersistence(states, enabled, storageId, onStateChanged, eventEmitter, resizeHelpers) {
5
5
  const emitStateChanged = (state) => {
6
6
  if (eventEmitter?.stateChanged) {
7
7
  eventEmitter.stateChanged(state);
8
8
  }
9
9
  onStateChanged?.(state);
10
10
  };
11
+ let pendingRatios = null;
12
+ let helpers = resizeHelpers;
11
13
  if (!enabled || !storageId) {
12
14
  return {
13
15
  getState: () => ({}),
14
16
  setState: (_snapshot) => {
17
+ },
18
+ clearState: () => {
19
+ },
20
+ applyPendingRatios: () => {
21
+ },
22
+ setResizeHelpers: (_helpers) => {
15
23
  }
16
24
  };
17
25
  }
@@ -75,6 +83,12 @@ export function useNuGridStatePersistence(states, enabled, storageId, onStateCha
75
83
  }
76
84
  if (hasKeys(states.columnSizingState.value)) {
77
85
  snapshot.columnSizing = states.columnSizingState.value;
86
+ if (helpers?.getSizingAsRatios) {
87
+ const ratios = helpers.getSizingAsRatios();
88
+ if (hasKeys(ratios)) {
89
+ snapshot.columnSizingRatios = ratios;
90
+ }
91
+ }
78
92
  }
79
93
  if (hasKeys(states.columnSizingInfoState.value)) {
80
94
  snapshot.columnSizingInfo = states.columnSizingInfoState.value;
@@ -129,7 +143,12 @@ export function useNuGridStatePersistence(states, enabled, storageId, onStateCha
129
143
  if (snapshot.columnPinning !== void 0) {
130
144
  states.columnPinningState.value = snapshot.columnPinning;
131
145
  }
132
- if (snapshot.columnSizing !== void 0) {
146
+ if (snapshot.columnSizingRatios !== void 0 && hasKeys(snapshot.columnSizingRatios)) {
147
+ pendingRatios = snapshot.columnSizingRatios;
148
+ if (snapshot.columnSizing !== void 0) {
149
+ states.columnSizingState.value = snapshot.columnSizing;
150
+ }
151
+ } else if (snapshot.columnSizing !== void 0) {
133
152
  states.columnSizingState.value = snapshot.columnSizing;
134
153
  }
135
154
  if (snapshot.columnSizingInfo !== void 0) {
@@ -154,6 +173,12 @@ export function useNuGridStatePersistence(states, enabled, storageId, onStateCha
154
173
  states.paginationState.value = snapshot.pagination;
155
174
  }
156
175
  }
176
+ function applyPendingRatios() {
177
+ if (pendingRatios && helpers?.applySizingFromRatios) {
178
+ helpers.applySizingFromRatios(pendingRatios);
179
+ pendingRatios = null;
180
+ }
181
+ }
157
182
  function setState(snapshot) {
158
183
  try {
159
184
  isRestoring = true;
@@ -236,8 +261,46 @@ export function useNuGridStatePersistence(states, enabled, storageId, onStateCha
236
261
  watchersActive = true;
237
262
  initialActivationComplete = true;
238
263
  }
264
+ function setResizeHelpers(newHelpers) {
265
+ helpers = newHelpers;
266
+ }
267
+ function clearState() {
268
+ try {
269
+ isRestoring = true;
270
+ if (storedState) {
271
+ storedState.value = null;
272
+ }
273
+ if (cookieStateRef) {
274
+ cookieStateRef.value = null;
275
+ }
276
+ states.globalFilterState.value = "";
277
+ states.columnFiltersState.value = [];
278
+ states.columnOrderState.value = [];
279
+ states.columnVisibilityState.value = {};
280
+ states.columnPinningState.value = {};
281
+ states.columnSizingState.value = {};
282
+ states.columnSizingInfoState.value = {};
283
+ states.rowSelectionState.value = {};
284
+ states.rowPinningState.value = {};
285
+ states.sortingState.value = [];
286
+ states.groupingState.value = [];
287
+ states.expandedState.value = {};
288
+ states.paginationState.value = { pageIndex: 0, pageSize: 10 };
289
+ pendingRatios = null;
290
+ emitStateChanged({});
291
+ nextTick(() => {
292
+ isRestoring = false;
293
+ });
294
+ } catch (error) {
295
+ console.warn("[NuGrid State] Failed to clear state:", error);
296
+ isRestoring = false;
297
+ }
298
+ }
239
299
  return {
240
300
  getState,
241
- setState
301
+ setState,
302
+ clearState,
303
+ applyPendingRatios,
304
+ setResizeHelpers
242
305
  };
243
306
  }