@iris-ui-kit/react 0.3.0 → 0.3.2
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/dist/admin.cjs +11 -7
- package/dist/admin.cjs.map +1 -1
- package/dist/admin.js +1 -1
- package/dist/async.cjs +16 -7
- package/dist/async.cjs.map +1 -1
- package/dist/async.d.cts +7 -6
- package/dist/async.d.ts +7 -6
- package/dist/async.js +1 -1
- package/dist/{chunk-KRFZ5KL4.js → chunk-2Z45RXJA.js} +13 -9
- package/dist/chunk-2Z45RXJA.js.map +1 -0
- package/dist/{chunk-TO7YVSAI.js → chunk-3KYNBLRY.js} +18 -9
- package/dist/chunk-3KYNBLRY.js.map +1 -0
- package/dist/{chunk-QKDOW7FG.js → chunk-EB5VUIPA.js} +20 -15
- package/dist/chunk-EB5VUIPA.js.map +1 -0
- package/dist/chunk-JANOOAZ5.js +942 -0
- package/dist/chunk-JANOOAZ5.js.map +1 -0
- package/dist/{chunk-QZJXMCRR.js → chunk-VLWZSOTH.js} +2 -2
- package/dist/chunk-VLWZSOTH.js.map +1 -0
- package/dist/data.cjs.map +1 -1
- package/dist/data.d.cts +2 -2
- package/dist/data.d.ts +2 -2
- package/dist/data.js +1 -1
- package/dist/grid.cjs +1007 -0
- package/dist/grid.cjs.map +1 -0
- package/dist/grid.d.cts +324 -0
- package/dist/grid.d.ts +324 -0
- package/dist/grid.js +5 -0
- package/dist/grid.js.map +1 -0
- package/dist/index.cjs +7159 -4602
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +294 -9
- package/dist/index.d.ts +294 -9
- package/dist/index.js +4735 -3148
- package/dist/index.js.map +1 -1
- package/dist/skeletons.cjs +18 -13
- package/dist/skeletons.cjs.map +1 -1
- package/dist/skeletons.js +1 -1
- package/package.json +19 -14
- package/dist/chunk-KRFZ5KL4.js.map +0 -1
- package/dist/chunk-QKDOW7FG.js.map +0 -1
- package/dist/chunk-QZJXMCRR.js.map +0 -1
- package/dist/chunk-TO7YVSAI.js.map +0 -1
package/dist/grid.cjs
ADDED
|
@@ -0,0 +1,1007 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React4 = require('react');
|
|
5
|
+
var grid = require('@iris-ui-kit/core/grid');
|
|
6
|
+
var core = require('@iris-ui-kit/core');
|
|
7
|
+
|
|
8
|
+
function _interopNamespace(e) {
|
|
9
|
+
if (e && e.__esModule) return e;
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var React4__namespace = /*#__PURE__*/_interopNamespace(React4);
|
|
27
|
+
|
|
28
|
+
// src/grid/useGridCore.ts
|
|
29
|
+
function useGridCore(options = {}) {
|
|
30
|
+
const coreRef = React4__namespace.useRef(null);
|
|
31
|
+
const ownershipRef = React4__namespace.useRef(null);
|
|
32
|
+
if (coreRef.current === null) {
|
|
33
|
+
const core2 = grid.createGridCore(options);
|
|
34
|
+
const ownership2 = { committed: false };
|
|
35
|
+
coreRef.current = core2;
|
|
36
|
+
ownershipRef.current = ownership2;
|
|
37
|
+
queueMicrotask(() => {
|
|
38
|
+
if (!ownership2.committed) core2.destroy();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const core = coreRef.current;
|
|
42
|
+
const ownership = ownershipRef.current;
|
|
43
|
+
const lifecycleGeneration = React4__namespace.useRef(0);
|
|
44
|
+
React4__namespace.useInsertionEffect(() => {
|
|
45
|
+
ownership.committed = true;
|
|
46
|
+
}, [core, ownership]);
|
|
47
|
+
React4__namespace.useEffect(() => {
|
|
48
|
+
const generation = ++lifecycleGeneration.current;
|
|
49
|
+
core.ready();
|
|
50
|
+
return () => {
|
|
51
|
+
queueMicrotask(() => {
|
|
52
|
+
if (lifecycleGeneration.current === generation) core.destroy();
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
}, [core]);
|
|
56
|
+
return core;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/grid/legacyGridOptions.ts
|
|
60
|
+
function toGridColumnsOptions(props) {
|
|
61
|
+
return {
|
|
62
|
+
visibility: props.columnVisibility,
|
|
63
|
+
visibilityControlled: true,
|
|
64
|
+
onVisibilityChange: props.onColumnVisibilityChange,
|
|
65
|
+
order: props.columnOrder,
|
|
66
|
+
orderControlled: true,
|
|
67
|
+
onOrderChange: props.onColumnOrderChange,
|
|
68
|
+
widths: props.columnWidths,
|
|
69
|
+
defaultWidths: props.defaultColumnWidths,
|
|
70
|
+
onWidthsChange: props.onColumnWidthsChange,
|
|
71
|
+
pinned: props.pinnedColumns,
|
|
72
|
+
onPinnedChange: props.onColumnPinnedChange
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function toGridRowsOptions(props) {
|
|
76
|
+
const rows = props.data ?? [];
|
|
77
|
+
return {
|
|
78
|
+
initialRows: props.keepSource ? [...rows] : rows,
|
|
79
|
+
options: {
|
|
80
|
+
...props.rowKeyField === void 0 ? {} : { rowKeyField: props.rowKeyField },
|
|
81
|
+
...props.getRowKey === void 0 ? {} : { getRowKey: props.getRowKey },
|
|
82
|
+
...props.getChildren === void 0 ? {} : { getChildren: props.getChildren },
|
|
83
|
+
...props.setChildren === void 0 ? {} : { setChildren: props.setChildren },
|
|
84
|
+
onBeforeRowsChange: props.beforeChange,
|
|
85
|
+
onRowsChange: props.onChange
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function toGridSelectionOptions(props) {
|
|
90
|
+
return {
|
|
91
|
+
mode: props.selectable === "single" ? "single" : "multiple",
|
|
92
|
+
value: props.selection,
|
|
93
|
+
defaultValue: props.defaultSelection,
|
|
94
|
+
onChange: props.onSelectionChange
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function toGridExpansionOptions(props) {
|
|
98
|
+
return {
|
|
99
|
+
mode: "multiple",
|
|
100
|
+
defaultValue: (props.defaultExpandedRowKeys ?? []).map(String),
|
|
101
|
+
onChange: props.onChange
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function toGridPaginationOptions(props) {
|
|
105
|
+
const state = props.state;
|
|
106
|
+
const onChange = state ? (change) => {
|
|
107
|
+
props.request?.({ page: change.page, pageSize: change.pageSize });
|
|
108
|
+
props.proxyConfig?.onPageChange?.(change.page, change.pageSize);
|
|
109
|
+
} : void 0;
|
|
110
|
+
return {
|
|
111
|
+
page: state?.page,
|
|
112
|
+
pageSize: state?.pageSize,
|
|
113
|
+
total: state?.total,
|
|
114
|
+
defaultPage: props.proxyConfig?.defaultPage,
|
|
115
|
+
defaultPageSize: props.proxyConfig?.pageSize,
|
|
116
|
+
onChange
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function toGridSortingOptions(props) {
|
|
120
|
+
return {
|
|
121
|
+
leafColumns: props.columns,
|
|
122
|
+
sort: props.sort,
|
|
123
|
+
defaultSort: props.defaultSort,
|
|
124
|
+
onSortChange: props.onSortChange,
|
|
125
|
+
multiSort: props.multiSort,
|
|
126
|
+
multiSortState: props.multiSortState,
|
|
127
|
+
defaultMultiSort: props.defaultMultiSort,
|
|
128
|
+
onMultiSortChange: props.onMultiSortChange,
|
|
129
|
+
formulaTables: props.formulaTables
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function toGridFilteringOptions(props) {
|
|
133
|
+
return {
|
|
134
|
+
columns: props.columns,
|
|
135
|
+
getValue: props.getValue,
|
|
136
|
+
filters: props.filters,
|
|
137
|
+
defaultFilters: props.defaultFilters,
|
|
138
|
+
onFiltersChange: props.onFiltersChange,
|
|
139
|
+
filterValues: props.filterValues,
|
|
140
|
+
defaultFilterValues: props.defaultFilterValues,
|
|
141
|
+
onFilterValuesChange: props.onFilterValuesChange,
|
|
142
|
+
controlled: true,
|
|
143
|
+
formFilters: props.formFilters,
|
|
144
|
+
query: props.query,
|
|
145
|
+
proxy: Boolean(props.proxy),
|
|
146
|
+
remote: props.remoteFilter
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function useStore(store) {
|
|
150
|
+
return React4.useSyncExternalStore(
|
|
151
|
+
store.subscribe,
|
|
152
|
+
store.getState,
|
|
153
|
+
store.getState
|
|
154
|
+
// SSR fallback — same as client snapshot in our case.
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
function useStoreSelector(store, selector, isEqual) {
|
|
158
|
+
const [slice, setSlice] = React4__namespace.useState(() => selector(store.getState()));
|
|
159
|
+
const selRef = React4__namespace.useRef(selector);
|
|
160
|
+
selRef.current = selector;
|
|
161
|
+
const eqRef = React4__namespace.useRef(isEqual);
|
|
162
|
+
eqRef.current = isEqual;
|
|
163
|
+
React4__namespace.useEffect(() => {
|
|
164
|
+
const read = (s) => selRef.current(s);
|
|
165
|
+
const eq = (a, b) => (eqRef.current ?? Object.is)(a, b);
|
|
166
|
+
setSlice((prev) => {
|
|
167
|
+
const next = read(store.getState());
|
|
168
|
+
return eq(prev, next) ? prev : next;
|
|
169
|
+
});
|
|
170
|
+
return store.subscribeWith(read, setSlice, eq);
|
|
171
|
+
}, [store]);
|
|
172
|
+
return slice;
|
|
173
|
+
}
|
|
174
|
+
function useGridFeature(core, name, modelMethod, create) {
|
|
175
|
+
const feature = React4__namespace.useRef(null);
|
|
176
|
+
if (feature.current === null) feature.current = create();
|
|
177
|
+
if (!core.hasFeature(name)) core.use(feature.current);
|
|
178
|
+
return core.invoke(modelMethod);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/grid/useGridColumns.ts
|
|
182
|
+
var EMPTY_VISIBILITY = {};
|
|
183
|
+
var EMPTY_ORDER = [];
|
|
184
|
+
var EMPTY_WIDTHS = {};
|
|
185
|
+
var EMPTY_PINNED = {};
|
|
186
|
+
function visibilitySignature(visibility) {
|
|
187
|
+
return visibility ? JSON.stringify(Object.keys(visibility).map((key) => [key, visibility[key]])) : "";
|
|
188
|
+
}
|
|
189
|
+
function cloneColumnsState(state) {
|
|
190
|
+
return {
|
|
191
|
+
visibility: { ...state.visibility },
|
|
192
|
+
order: [...state.order],
|
|
193
|
+
widths: { ...state.widths },
|
|
194
|
+
pinned: { ...state.pinned }
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function useGridColumns(core, options = {}) {
|
|
198
|
+
const latest = React4__namespace.useRef(options);
|
|
199
|
+
latest.current = options;
|
|
200
|
+
const model = useGridFeature(
|
|
201
|
+
core,
|
|
202
|
+
"columns",
|
|
203
|
+
"getColumnsModel",
|
|
204
|
+
() => grid.createGridColumnsFeature({
|
|
205
|
+
defaultVisibility: options.visibility ?? options.defaultVisibility,
|
|
206
|
+
defaultOrder: options.order ?? options.defaultOrder,
|
|
207
|
+
defaultWidths: options.widths ?? options.defaultWidths,
|
|
208
|
+
defaultPinned: options.pinned ?? options.defaultPinned,
|
|
209
|
+
onVisibilityChange: (visibility) => latest.current.onVisibilityChange?.(visibility),
|
|
210
|
+
onOrderChange: (order) => latest.current.onOrderChange?.(order),
|
|
211
|
+
onWidthsChange: (widths) => latest.current.onWidthsChange?.(widths),
|
|
212
|
+
onPinnedChange: (key, side) => latest.current.onPinnedChange?.(key, side)
|
|
213
|
+
})
|
|
214
|
+
);
|
|
215
|
+
const internal = useStore(model.store);
|
|
216
|
+
const visibilityControlled = options.visibilityControlled ?? options.visibility !== void 0;
|
|
217
|
+
const orderControlled = options.orderControlled ?? options.order !== void 0;
|
|
218
|
+
const widthsControlled = options.widths !== void 0;
|
|
219
|
+
const pinnedControlled = options.pinned !== void 0;
|
|
220
|
+
const visibilityVersion = visibilitySignature(
|
|
221
|
+
visibilityControlled ? options.visibility : void 0
|
|
222
|
+
);
|
|
223
|
+
const lastUncontrolledVisibility = React4__namespace.useRef({
|
|
224
|
+
...options.defaultVisibility ?? EMPTY_VISIBILITY
|
|
225
|
+
});
|
|
226
|
+
const lastUncontrolledOrder = React4__namespace.useRef([...options.defaultOrder ?? EMPTY_ORDER]);
|
|
227
|
+
const lastUncontrolledWidths = React4__namespace.useRef({
|
|
228
|
+
...options.defaultWidths ?? EMPTY_WIDTHS
|
|
229
|
+
});
|
|
230
|
+
const lastUncontrolledPinned = React4__namespace.useRef({
|
|
231
|
+
...options.defaultPinned ?? EMPTY_PINNED
|
|
232
|
+
});
|
|
233
|
+
const wasVisibilityControlled = React4__namespace.useRef(visibilityControlled);
|
|
234
|
+
const wasOrderControlled = React4__namespace.useRef(orderControlled);
|
|
235
|
+
const wasWidthsControlled = React4__namespace.useRef(widthsControlled);
|
|
236
|
+
const wasPinnedControlled = React4__namespace.useRef(pinnedControlled);
|
|
237
|
+
const enteringVisibilityControlled = visibilityControlled && !wasVisibilityControlled.current;
|
|
238
|
+
const enteringOrderControlled = orderControlled && !wasOrderControlled.current;
|
|
239
|
+
const enteringWidthsControlled = widthsControlled && !wasWidthsControlled.current;
|
|
240
|
+
const enteringPinnedControlled = pinnedControlled && !wasPinnedControlled.current;
|
|
241
|
+
if (enteringVisibilityControlled || enteringOrderControlled || enteringWidthsControlled || enteringPinnedControlled) {
|
|
242
|
+
const liveState = model.store.getState();
|
|
243
|
+
if (enteringVisibilityControlled) {
|
|
244
|
+
lastUncontrolledVisibility.current = { ...liveState.visibility };
|
|
245
|
+
}
|
|
246
|
+
if (enteringOrderControlled) lastUncontrolledOrder.current = [...liveState.order];
|
|
247
|
+
if (enteringWidthsControlled) lastUncontrolledWidths.current = { ...liveState.widths };
|
|
248
|
+
if (enteringPinnedControlled) lastUncontrolledPinned.current = { ...liveState.pinned };
|
|
249
|
+
}
|
|
250
|
+
if (!visibilityControlled && !wasVisibilityControlled.current) {
|
|
251
|
+
lastUncontrolledVisibility.current = { ...internal.visibility };
|
|
252
|
+
}
|
|
253
|
+
if (!orderControlled && !wasOrderControlled.current) {
|
|
254
|
+
lastUncontrolledOrder.current = [...internal.order];
|
|
255
|
+
}
|
|
256
|
+
if (!widthsControlled && !wasWidthsControlled.current) {
|
|
257
|
+
lastUncontrolledWidths.current = { ...internal.widths };
|
|
258
|
+
}
|
|
259
|
+
if (!pinnedControlled && !wasPinnedControlled.current) {
|
|
260
|
+
lastUncontrolledPinned.current = { ...internal.pinned };
|
|
261
|
+
}
|
|
262
|
+
const state = cloneColumnsState({
|
|
263
|
+
visibility: visibilityControlled ? { ...options.visibility ?? EMPTY_VISIBILITY } : wasVisibilityControlled.current ? lastUncontrolledVisibility.current : internal.visibility,
|
|
264
|
+
order: orderControlled ? [...options.order ?? EMPTY_ORDER] : wasOrderControlled.current ? lastUncontrolledOrder.current : internal.order,
|
|
265
|
+
// Removing a controlled order must restore the last uncontrolled/default
|
|
266
|
+
// snapshot rather than exposing a rejected controlled proposal. Widths
|
|
267
|
+
// use the same handoff policy below.
|
|
268
|
+
// Removing a controlled width map must restore the last uncontrolled or
|
|
269
|
+
// default snapshot immediately; otherwise one render leaks the rejected
|
|
270
|
+
// controlled widths before the silent model rebase runs.
|
|
271
|
+
widths: widthsControlled ? { ...options.widths } : wasWidthsControlled.current ? lastUncontrolledWidths.current : internal.widths,
|
|
272
|
+
pinned: pinnedControlled ? { ...options.pinned } : wasPinnedControlled.current ? lastUncontrolledPinned.current : internal.pinned
|
|
273
|
+
});
|
|
274
|
+
React4__namespace.useEffect(() => {
|
|
275
|
+
if (visibilityControlled) model.syncVisibility(options.visibility ?? {});
|
|
276
|
+
else if (wasVisibilityControlled.current)
|
|
277
|
+
model.syncVisibility(lastUncontrolledVisibility.current);
|
|
278
|
+
wasVisibilityControlled.current = visibilityControlled;
|
|
279
|
+
}, [model, options.visibility, visibilityControlled, visibilityVersion]);
|
|
280
|
+
React4__namespace.useEffect(() => {
|
|
281
|
+
if (orderControlled) model.syncOrder(options.order ?? []);
|
|
282
|
+
else if (wasOrderControlled.current) model.syncOrder(lastUncontrolledOrder.current);
|
|
283
|
+
wasOrderControlled.current = orderControlled;
|
|
284
|
+
}, [model, options.order, orderControlled]);
|
|
285
|
+
React4__namespace.useEffect(() => {
|
|
286
|
+
if (widthsControlled) model.syncWidths(options.widths ?? {});
|
|
287
|
+
else if (wasWidthsControlled.current) model.syncWidths(lastUncontrolledWidths.current);
|
|
288
|
+
wasWidthsControlled.current = widthsControlled;
|
|
289
|
+
}, [model, options.widths, widthsControlled]);
|
|
290
|
+
React4__namespace.useEffect(() => {
|
|
291
|
+
if (pinnedControlled) model.syncPinned(options.pinned ?? {});
|
|
292
|
+
else if (wasPinnedControlled.current) model.syncPinned(lastUncontrolledPinned.current);
|
|
293
|
+
wasPinnedControlled.current = pinnedControlled;
|
|
294
|
+
}, [model, options.pinned, pinnedControlled]);
|
|
295
|
+
const rebaseVisibility = React4__namespace.useCallback(() => {
|
|
296
|
+
if (latest.current.visibilityControlled ?? latest.current.visibility !== void 0) {
|
|
297
|
+
model.syncVisibility(latest.current.visibility ?? {});
|
|
298
|
+
} else if (wasVisibilityControlled.current) {
|
|
299
|
+
model.syncVisibility(lastUncontrolledVisibility.current);
|
|
300
|
+
}
|
|
301
|
+
}, [model]);
|
|
302
|
+
const rebaseOrder = React4__namespace.useCallback(() => {
|
|
303
|
+
if (latest.current.orderControlled ?? latest.current.order !== void 0) {
|
|
304
|
+
model.syncOrder(latest.current.order ?? []);
|
|
305
|
+
}
|
|
306
|
+
}, [model]);
|
|
307
|
+
const rebaseWidths = React4__namespace.useCallback(() => {
|
|
308
|
+
if (latest.current.widths !== void 0) model.syncWidths(latest.current.widths);
|
|
309
|
+
else if (wasWidthsControlled.current) model.syncWidths(lastUncontrolledWidths.current);
|
|
310
|
+
}, [model]);
|
|
311
|
+
const rebasePinned = React4__namespace.useCallback(() => {
|
|
312
|
+
if (latest.current.pinned !== void 0) model.syncPinned(latest.current.pinned);
|
|
313
|
+
else if (wasPinnedControlled.current) model.syncPinned(lastUncontrolledPinned.current);
|
|
314
|
+
}, [model]);
|
|
315
|
+
const setVisibility = React4__namespace.useCallback(
|
|
316
|
+
(visibility) => {
|
|
317
|
+
rebaseVisibility();
|
|
318
|
+
model.setVisibility(visibility);
|
|
319
|
+
},
|
|
320
|
+
[model, rebaseVisibility]
|
|
321
|
+
);
|
|
322
|
+
const toggleVisibility = React4__namespace.useCallback(
|
|
323
|
+
(key) => {
|
|
324
|
+
rebaseVisibility();
|
|
325
|
+
model.toggleVisibility(key);
|
|
326
|
+
},
|
|
327
|
+
[model, rebaseVisibility]
|
|
328
|
+
);
|
|
329
|
+
const setOrder = React4__namespace.useCallback(
|
|
330
|
+
(order) => {
|
|
331
|
+
rebaseOrder();
|
|
332
|
+
model.setOrder(order);
|
|
333
|
+
},
|
|
334
|
+
[model, rebaseOrder]
|
|
335
|
+
);
|
|
336
|
+
const clearOrder = React4__namespace.useCallback(() => {
|
|
337
|
+
rebaseOrder();
|
|
338
|
+
model.setOrder(void 0);
|
|
339
|
+
}, [model, rebaseOrder]);
|
|
340
|
+
const setWidths = React4__namespace.useCallback(
|
|
341
|
+
(widths) => {
|
|
342
|
+
rebaseWidths();
|
|
343
|
+
model.setWidths(widths);
|
|
344
|
+
},
|
|
345
|
+
[model, rebaseWidths]
|
|
346
|
+
);
|
|
347
|
+
const setWidth = React4__namespace.useCallback(
|
|
348
|
+
(key, width) => {
|
|
349
|
+
rebaseWidths();
|
|
350
|
+
model.setWidth(key, width);
|
|
351
|
+
},
|
|
352
|
+
[model, rebaseWidths]
|
|
353
|
+
);
|
|
354
|
+
const resetWidths = React4__namespace.useCallback(() => {
|
|
355
|
+
rebaseWidths();
|
|
356
|
+
model.setWidths({});
|
|
357
|
+
}, [model, rebaseWidths]);
|
|
358
|
+
const setPinned = React4__namespace.useCallback(
|
|
359
|
+
(key, side) => {
|
|
360
|
+
rebasePinned();
|
|
361
|
+
model.setPinned(key, side);
|
|
362
|
+
},
|
|
363
|
+
[model, rebasePinned]
|
|
364
|
+
);
|
|
365
|
+
return {
|
|
366
|
+
model,
|
|
367
|
+
state,
|
|
368
|
+
controlled: {
|
|
369
|
+
visibility: visibilityControlled,
|
|
370
|
+
order: orderControlled,
|
|
371
|
+
widths: widthsControlled,
|
|
372
|
+
pinned: pinnedControlled
|
|
373
|
+
},
|
|
374
|
+
setVisibility,
|
|
375
|
+
toggleVisibility,
|
|
376
|
+
setOrder,
|
|
377
|
+
clearOrder,
|
|
378
|
+
setWidths,
|
|
379
|
+
setWidth,
|
|
380
|
+
resetWidths,
|
|
381
|
+
setPinned
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
function defaultValue(row, column) {
|
|
385
|
+
return row[column.dataIndex ?? column.key];
|
|
386
|
+
}
|
|
387
|
+
function defaultSetValue(row, column, value) {
|
|
388
|
+
return { ...row, [column.dataIndex ?? column.key]: value };
|
|
389
|
+
}
|
|
390
|
+
function resolveCommitOptions(options) {
|
|
391
|
+
if (typeof options === "function") return options();
|
|
392
|
+
return options ?? {};
|
|
393
|
+
}
|
|
394
|
+
function useGridClipboard(core, options) {
|
|
395
|
+
const latest = React4__namespace.useRef(options);
|
|
396
|
+
latest.current = options;
|
|
397
|
+
const model = useGridFeature(
|
|
398
|
+
core,
|
|
399
|
+
"clipboard",
|
|
400
|
+
"getClipboardModel",
|
|
401
|
+
() => grid.createGridClipboardFeature({
|
|
402
|
+
getRows: () => latest.current.getRows?.() ?? core.invoke("getRows"),
|
|
403
|
+
getColumns: () => latest.current.getColumns(),
|
|
404
|
+
rowKeyField: latest.current.rowKeyField,
|
|
405
|
+
overflowRows: (context) => latest.current.overflowRows?.(context),
|
|
406
|
+
resolveValue: (row, column) => {
|
|
407
|
+
const resolve = latest.current.resolveValue;
|
|
408
|
+
return resolve ? resolve(row, column) : defaultValue(row, column);
|
|
409
|
+
},
|
|
410
|
+
parseValue: (text, row, column) => {
|
|
411
|
+
const parse = latest.current.parseValue;
|
|
412
|
+
return parse ? parse(text, row, column) : text;
|
|
413
|
+
},
|
|
414
|
+
setValue: (row, column, value) => latest.current.setValue?.(row, column, value) ?? defaultSetValue(row, column, value),
|
|
415
|
+
isCellEditable: (row, column, rowIndex, columnIndex) => latest.current.isCellEditable?.(row, column, rowIndex, columnIndex) ?? true,
|
|
416
|
+
reconcileRows: (sourceRows, previousRows, rows) => latest.current.reconcileRows?.(sourceRows, previousRows, rows) ?? rows,
|
|
417
|
+
commitOptions: () => resolveCommitOptions(latest.current.commitOptions),
|
|
418
|
+
onCopy: (change) => latest.current.onCopy?.(change),
|
|
419
|
+
onPaste: (change) => latest.current.onPaste?.(change)
|
|
420
|
+
})
|
|
421
|
+
);
|
|
422
|
+
const serialize = React4__namespace.useCallback(
|
|
423
|
+
(format, copyWithFormat) => model.serialize(
|
|
424
|
+
format ?? latest.current.copyFormat ?? "tsv",
|
|
425
|
+
copyWithFormat ?? latest.current.copyWithFormat ?? false
|
|
426
|
+
),
|
|
427
|
+
[model]
|
|
428
|
+
);
|
|
429
|
+
const paste = React4__namespace.useCallback(
|
|
430
|
+
(text, range) => model.paste(text, range),
|
|
431
|
+
[model]
|
|
432
|
+
);
|
|
433
|
+
return { core, model, serialize, paste };
|
|
434
|
+
}
|
|
435
|
+
function cloneFilters(filters) {
|
|
436
|
+
return { ...filters ?? {} };
|
|
437
|
+
}
|
|
438
|
+
function cloneFilterValues(filterValues) {
|
|
439
|
+
return Object.fromEntries(
|
|
440
|
+
Object.entries(filterValues ?? {}).map(([key, values]) => [key, [...values]])
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
function useGridFiltering(core$1, data, options) {
|
|
444
|
+
const latest = React4__namespace.useRef(options);
|
|
445
|
+
latest.current = options;
|
|
446
|
+
const filtersControlled = options.controlled === true || options.filters !== void 0;
|
|
447
|
+
const valuesControlled = options.controlled === true || options.filterValues !== void 0;
|
|
448
|
+
const model = useGridFeature(
|
|
449
|
+
core$1,
|
|
450
|
+
"filtering",
|
|
451
|
+
"getFilteringModel",
|
|
452
|
+
() => grid.createGridFilteringFeature({
|
|
453
|
+
defaultFilters: filtersControlled ? options.filters ?? {} : options.defaultFilters,
|
|
454
|
+
defaultFilterValues: valuesControlled ? options.filterValues ?? {} : options.defaultFilterValues,
|
|
455
|
+
onFiltersChange: (next) => latest.current.onFiltersChange?.(next),
|
|
456
|
+
onFilterValuesChange: (next) => latest.current.onFilterValuesChange?.(next)
|
|
457
|
+
})
|
|
458
|
+
);
|
|
459
|
+
const internalState = useStore(model.store);
|
|
460
|
+
const filtersSignature = JSON.stringify(options.filters);
|
|
461
|
+
const filterValuesSignature = JSON.stringify(options.filterValues);
|
|
462
|
+
const wasFiltersControlled = React4__namespace.useRef(filtersControlled);
|
|
463
|
+
const uncontrolledFilters = React4__namespace.useRef({});
|
|
464
|
+
const hasUncontrolledFilters = React4__namespace.useRef(!filtersControlled);
|
|
465
|
+
const lastControlledFilters = React4__namespace.useRef(cloneFilters(options.filters));
|
|
466
|
+
const wasFilterValuesControlled = React4__namespace.useRef(valuesControlled);
|
|
467
|
+
const uncontrolledFilterValues = React4__namespace.useRef({});
|
|
468
|
+
const hasUncontrolledFilterValues = React4__namespace.useRef(!valuesControlled);
|
|
469
|
+
const lastControlledFilterValues = React4__namespace.useRef(
|
|
470
|
+
cloneFilterValues(options.filterValues)
|
|
471
|
+
);
|
|
472
|
+
const leavingFiltersControlled = wasFiltersControlled.current && !filtersControlled;
|
|
473
|
+
const leavingFilterValuesControlled = wasFilterValuesControlled.current && !valuesControlled;
|
|
474
|
+
if (!filtersControlled && !leavingFiltersControlled) {
|
|
475
|
+
uncontrolledFilters.current = cloneFilters(internalState.filters);
|
|
476
|
+
hasUncontrolledFilters.current = true;
|
|
477
|
+
}
|
|
478
|
+
if (!valuesControlled && !leavingFilterValuesControlled) {
|
|
479
|
+
uncontrolledFilterValues.current = cloneFilterValues(internalState.filterValues);
|
|
480
|
+
hasUncontrolledFilterValues.current = true;
|
|
481
|
+
}
|
|
482
|
+
if (filtersControlled && !wasFiltersControlled.current) {
|
|
483
|
+
uncontrolledFilters.current = cloneFilters(internalState.filters);
|
|
484
|
+
hasUncontrolledFilters.current = true;
|
|
485
|
+
}
|
|
486
|
+
if (valuesControlled && !wasFilterValuesControlled.current) {
|
|
487
|
+
uncontrolledFilterValues.current = cloneFilterValues(internalState.filterValues);
|
|
488
|
+
hasUncontrolledFilterValues.current = true;
|
|
489
|
+
}
|
|
490
|
+
if (filtersControlled) lastControlledFilters.current = cloneFilters(options.filters);
|
|
491
|
+
if (valuesControlled) {
|
|
492
|
+
lastControlledFilterValues.current = cloneFilterValues(options.filterValues);
|
|
493
|
+
}
|
|
494
|
+
const filters = cloneFilters(
|
|
495
|
+
filtersControlled ? options.filters : leavingFiltersControlled ? hasUncontrolledFilters.current ? uncontrolledFilters.current : lastControlledFilters.current : internalState.filters
|
|
496
|
+
);
|
|
497
|
+
const filterValues = cloneFilterValues(
|
|
498
|
+
valuesControlled ? options.filterValues : leavingFilterValuesControlled ? hasUncontrolledFilterValues.current ? uncontrolledFilterValues.current : lastControlledFilterValues.current : internalState.filterValues
|
|
499
|
+
);
|
|
500
|
+
React4__namespace.useEffect(() => {
|
|
501
|
+
if (filtersControlled) {
|
|
502
|
+
const next = cloneFilters(options.filters);
|
|
503
|
+
lastControlledFilters.current = cloneFilters(next);
|
|
504
|
+
model.syncFilters(next);
|
|
505
|
+
} else if (wasFiltersControlled.current) {
|
|
506
|
+
const restore = hasUncontrolledFilters.current ? uncontrolledFilters.current : lastControlledFilters.current;
|
|
507
|
+
uncontrolledFilters.current = cloneFilters(restore);
|
|
508
|
+
hasUncontrolledFilters.current = true;
|
|
509
|
+
model.syncFilters(restore);
|
|
510
|
+
}
|
|
511
|
+
wasFiltersControlled.current = filtersControlled;
|
|
512
|
+
}, [filtersControlled, model, options.filters, filtersSignature]);
|
|
513
|
+
React4__namespace.useEffect(() => {
|
|
514
|
+
if (valuesControlled) {
|
|
515
|
+
const next = cloneFilterValues(options.filterValues);
|
|
516
|
+
lastControlledFilterValues.current = cloneFilterValues(next);
|
|
517
|
+
model.syncFilterValues(next);
|
|
518
|
+
} else if (wasFilterValuesControlled.current) {
|
|
519
|
+
const restore = hasUncontrolledFilterValues.current ? uncontrolledFilterValues.current : lastControlledFilterValues.current;
|
|
520
|
+
uncontrolledFilterValues.current = cloneFilterValues(restore);
|
|
521
|
+
hasUncontrolledFilterValues.current = true;
|
|
522
|
+
model.syncFilterValues(restore);
|
|
523
|
+
}
|
|
524
|
+
wasFilterValuesControlled.current = valuesControlled;
|
|
525
|
+
}, [model, options.filterValues, valuesControlled, filterValuesSignature]);
|
|
526
|
+
const filteredData = React4__namespace.useMemo(() => {
|
|
527
|
+
if (options.remote) return data;
|
|
528
|
+
const merged = options.proxy ? { ...filters } : core.mergeFormFilters(filters, options.formFilters ?? {});
|
|
529
|
+
for (const [key, value] of Object.entries(options.query?.filters ?? {})) {
|
|
530
|
+
if (value !== "") merged[key] = value;
|
|
531
|
+
}
|
|
532
|
+
return core.filterTableRows(data, options.columns, {
|
|
533
|
+
getValue: options.getValue,
|
|
534
|
+
filters: merged,
|
|
535
|
+
filterValues,
|
|
536
|
+
additionalFilterValues: options.query?.inValues ? [options.query.inValues] : void 0,
|
|
537
|
+
filterRules: options.query?.rules
|
|
538
|
+
});
|
|
539
|
+
}, [
|
|
540
|
+
data,
|
|
541
|
+
filterValues,
|
|
542
|
+
filters,
|
|
543
|
+
options.columns,
|
|
544
|
+
options.formFilters,
|
|
545
|
+
options.getValue,
|
|
546
|
+
options.proxy,
|
|
547
|
+
options.query,
|
|
548
|
+
options.remote
|
|
549
|
+
]);
|
|
550
|
+
return { core: core$1, model, filters, filterValues, filteredData };
|
|
551
|
+
}
|
|
552
|
+
function useGridEditing(core, options) {
|
|
553
|
+
const latest = React4__namespace.useRef(options);
|
|
554
|
+
latest.current = options;
|
|
555
|
+
const model = useGridFeature(
|
|
556
|
+
core,
|
|
557
|
+
"editing",
|
|
558
|
+
"getEditingModel",
|
|
559
|
+
() => grid.createGridEditingFeature({
|
|
560
|
+
getRowKey: (row, index) => latest.current.getRowKey(row, index),
|
|
561
|
+
getRowIndex: (rowKey, row, rootRows) => latest.current.getRowIndex?.(rowKey, row, rootRows),
|
|
562
|
+
getRules: (columnKey) => latest.current.getRules?.(columnKey),
|
|
563
|
+
getValue: (row, columnKey) => {
|
|
564
|
+
const getValue = latest.current.getValue;
|
|
565
|
+
return getValue ? getValue(row, columnKey) : row[columnKey];
|
|
566
|
+
},
|
|
567
|
+
setValue: (row, columnKey, value) => latest.current.setValue?.(row, columnKey, value) ?? { ...row, [columnKey]: value },
|
|
568
|
+
coerce: (draft, row, columnKey) => {
|
|
569
|
+
const coerce = latest.current.coerce;
|
|
570
|
+
return coerce ? coerce(draft, row, columnKey) : draft;
|
|
571
|
+
},
|
|
572
|
+
validate: (value, row, columnKey) => latest.current.validate?.(value, row, columnKey) ?? null,
|
|
573
|
+
isEditable: (row, columnKey) => latest.current.isEditable?.(row, columnKey) ?? true,
|
|
574
|
+
missingRowMessage: options.missingRowMessage,
|
|
575
|
+
commitOptions: () => {
|
|
576
|
+
const configured = latest.current.commitOptions;
|
|
577
|
+
return typeof configured === "function" ? configured() : configured ?? {};
|
|
578
|
+
},
|
|
579
|
+
onStateChange: (state2) => latest.current.onStateChange?.(state2),
|
|
580
|
+
onValidation: (validation) => latest.current.onValidation?.(validation),
|
|
581
|
+
onCommit: (commit) => latest.current.onCommit?.(commit)
|
|
582
|
+
})
|
|
583
|
+
);
|
|
584
|
+
const state = useStoreSelector(model.store, () => model.getState());
|
|
585
|
+
return {
|
|
586
|
+
core,
|
|
587
|
+
model,
|
|
588
|
+
state,
|
|
589
|
+
startCellEdit: (rowKey, columnKey, initialDraft) => model.start(rowKey, columnKey, initialDraft),
|
|
590
|
+
setCellDraft: (value) => model.setDraft(value),
|
|
591
|
+
cancelCellEdit: () => model.cancelEdit(),
|
|
592
|
+
commitCellEdit: (value) => model.commitEdit(value),
|
|
593
|
+
isCellEditing: (rowKey, columnKey) => model.isEditing(rowKey, columnKey)
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function useGridExpansion(core, options = {}) {
|
|
597
|
+
const latest = React4__namespace.useRef(options);
|
|
598
|
+
latest.current = options;
|
|
599
|
+
const model = useGridFeature(
|
|
600
|
+
core,
|
|
601
|
+
"expansion",
|
|
602
|
+
"getExpansionModel",
|
|
603
|
+
() => grid.createGridExpansionFeature({
|
|
604
|
+
mode: options.mode,
|
|
605
|
+
defaultExpanded: options.defaultValue,
|
|
606
|
+
getKeys: () => latest.current.getKeys?.() ?? [],
|
|
607
|
+
onChange: (keys) => latest.current.onChange?.(keys)
|
|
608
|
+
})
|
|
609
|
+
);
|
|
610
|
+
const expandedKeys = useStore(model.store);
|
|
611
|
+
return { core, model, expandedKeys: [...expandedKeys] };
|
|
612
|
+
}
|
|
613
|
+
function controlledState(options) {
|
|
614
|
+
return {
|
|
615
|
+
...options.page !== void 0 ? { page: options.page } : {},
|
|
616
|
+
...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
|
|
617
|
+
...options.total !== void 0 ? { total: options.total } : {}
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
function useGridPagination(core, options = {}) {
|
|
621
|
+
const latest = React4__namespace.useRef(options);
|
|
622
|
+
latest.current = options;
|
|
623
|
+
const model = useGridFeature(
|
|
624
|
+
core,
|
|
625
|
+
"pagination",
|
|
626
|
+
"getPaginationModel",
|
|
627
|
+
() => grid.createGridPaginationFeature({
|
|
628
|
+
defaultPage: options.page ?? options.defaultPage,
|
|
629
|
+
defaultPageSize: options.pageSize ?? options.defaultPageSize,
|
|
630
|
+
defaultTotal: options.total ?? options.defaultTotal,
|
|
631
|
+
onChange: (change) => latest.current.onChange?.(change)
|
|
632
|
+
})
|
|
633
|
+
);
|
|
634
|
+
const internal = useStore(model.store);
|
|
635
|
+
const projectionRef = React4__namespace.useRef(null);
|
|
636
|
+
if (projectionRef.current === null) {
|
|
637
|
+
projectionRef.current = grid.createGridPaginationProjection(model, controlledState(options));
|
|
638
|
+
}
|
|
639
|
+
const projection = projectionRef.current;
|
|
640
|
+
const controlled = options.page !== void 0 || options.pageSize !== void 0 || options.total !== void 0;
|
|
641
|
+
const controlledProps = controlledState(options);
|
|
642
|
+
const pagination = projection.project(internal, controlledProps);
|
|
643
|
+
React4__namespace.useEffect(() => {
|
|
644
|
+
projection.sync(controlledState(options));
|
|
645
|
+
return () => projection.dispose();
|
|
646
|
+
}, [options.page, options.pageSize, options.total, projection]);
|
|
647
|
+
const rebase = React4__namespace.useCallback(() => {
|
|
648
|
+
projection.sync(controlledState(latest.current));
|
|
649
|
+
}, [projection]);
|
|
650
|
+
const setPage = React4__namespace.useCallback(
|
|
651
|
+
(page) => {
|
|
652
|
+
rebase();
|
|
653
|
+
model.setPage(page);
|
|
654
|
+
},
|
|
655
|
+
[model, rebase]
|
|
656
|
+
);
|
|
657
|
+
const setPageSize = React4__namespace.useCallback(
|
|
658
|
+
(pageSize) => {
|
|
659
|
+
rebase();
|
|
660
|
+
model.setPageSize(pageSize);
|
|
661
|
+
},
|
|
662
|
+
[model, rebase]
|
|
663
|
+
);
|
|
664
|
+
const setPagination = React4__namespace.useCallback(
|
|
665
|
+
(page, pageSize) => {
|
|
666
|
+
rebase();
|
|
667
|
+
model.set(page, pageSize);
|
|
668
|
+
},
|
|
669
|
+
[model, rebase]
|
|
670
|
+
);
|
|
671
|
+
return { model, pagination, controlled, setPage, setPageSize, setPagination };
|
|
672
|
+
}
|
|
673
|
+
function useGridRange(core, options = {}) {
|
|
674
|
+
const latest = React4__namespace.useRef(options);
|
|
675
|
+
latest.current = options;
|
|
676
|
+
const model = useGridFeature(
|
|
677
|
+
core,
|
|
678
|
+
"range",
|
|
679
|
+
"getRangeModel",
|
|
680
|
+
() => grid.createGridRangeFeature({
|
|
681
|
+
onChange: (change) => latest.current.onChange?.(change)
|
|
682
|
+
})
|
|
683
|
+
);
|
|
684
|
+
const state = React4__namespace.useSyncExternalStore(model.subscribe, model.getState, model.getState);
|
|
685
|
+
const range = React4__namespace.useMemo(() => model.getRange(), [model, state]);
|
|
686
|
+
return { core, model, state, range };
|
|
687
|
+
}
|
|
688
|
+
function sameKeys(left, right) {
|
|
689
|
+
return left.length === right.length && left.every(
|
|
690
|
+
(key, index) => key === right[index] || key !== key && right[index] !== right[index]
|
|
691
|
+
);
|
|
692
|
+
}
|
|
693
|
+
function useGridSelection(core, options = {}) {
|
|
694
|
+
const latest = React4__namespace.useRef(options);
|
|
695
|
+
latest.current = options;
|
|
696
|
+
const model = useGridFeature(
|
|
697
|
+
core,
|
|
698
|
+
"selection",
|
|
699
|
+
"getSelectionModel",
|
|
700
|
+
() => grid.createGridSelectionFeature({
|
|
701
|
+
mode: options.mode,
|
|
702
|
+
defaultSelected: options.value ?? options.defaultValue,
|
|
703
|
+
getKeys: () => latest.current.getKeys?.() ?? [],
|
|
704
|
+
onChange: (keys) => latest.current.onChange?.(keys)
|
|
705
|
+
})
|
|
706
|
+
);
|
|
707
|
+
const internalSelection = useStore(model.store);
|
|
708
|
+
const controlled = options.value !== void 0;
|
|
709
|
+
const wasControlled = React4__namespace.useRef(controlled);
|
|
710
|
+
const uncontrolledSnapshot = React4__namespace.useRef([]);
|
|
711
|
+
const hasUncontrolledSnapshot = React4__namespace.useRef(!controlled);
|
|
712
|
+
const lastControlledSnapshot = React4__namespace.useRef([...options.value ?? []]);
|
|
713
|
+
const leavingControlled = wasControlled.current && !controlled;
|
|
714
|
+
if (controlled && !wasControlled.current) {
|
|
715
|
+
uncontrolledSnapshot.current = [...model.store.getState()];
|
|
716
|
+
hasUncontrolledSnapshot.current = true;
|
|
717
|
+
}
|
|
718
|
+
if (!controlled && !leavingControlled) {
|
|
719
|
+
uncontrolledSnapshot.current = [...internalSelection];
|
|
720
|
+
hasUncontrolledSnapshot.current = true;
|
|
721
|
+
}
|
|
722
|
+
if (controlled) lastControlledSnapshot.current = [...options.value ?? []];
|
|
723
|
+
const uncontrolledValue = leavingControlled ? hasUncontrolledSnapshot.current ? uncontrolledSnapshot.current : lastControlledSnapshot.current : internalSelection;
|
|
724
|
+
React4__namespace.useEffect(() => {
|
|
725
|
+
if (controlled) {
|
|
726
|
+
const next = options.value ?? [];
|
|
727
|
+
lastControlledSnapshot.current = [...next];
|
|
728
|
+
if (!sameKeys(model.get(), next)) model.sync(next);
|
|
729
|
+
} else if (wasControlled.current) {
|
|
730
|
+
const next = hasUncontrolledSnapshot.current ? uncontrolledSnapshot.current : lastControlledSnapshot.current;
|
|
731
|
+
if (!hasUncontrolledSnapshot.current) {
|
|
732
|
+
uncontrolledSnapshot.current = [...next];
|
|
733
|
+
hasUncontrolledSnapshot.current = true;
|
|
734
|
+
}
|
|
735
|
+
if (!sameKeys(model.get(), next)) model.sync(next);
|
|
736
|
+
}
|
|
737
|
+
wasControlled.current = controlled;
|
|
738
|
+
}, [controlled, model, options.value ? [...options.value] : void 0]);
|
|
739
|
+
const rebase = React4__namespace.useCallback(() => {
|
|
740
|
+
if (latest.current.value !== void 0) model.sync(latest.current.value);
|
|
741
|
+
}, [model]);
|
|
742
|
+
return {
|
|
743
|
+
core,
|
|
744
|
+
model,
|
|
745
|
+
selection: [...controlled ? options.value ?? [] : uncontrolledValue],
|
|
746
|
+
controlled,
|
|
747
|
+
rebase
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
function useGridRows(core, initialRows, options = {}) {
|
|
751
|
+
const latest = React4__namespace.useRef(options);
|
|
752
|
+
latest.current = options;
|
|
753
|
+
const model = useGridFeature(
|
|
754
|
+
core,
|
|
755
|
+
"rows",
|
|
756
|
+
"getRowsModel",
|
|
757
|
+
() => grid.createGridRowsFeature({
|
|
758
|
+
defaultRows: initialRows,
|
|
759
|
+
cloneDefaultRows: options.cloneDefaultRows,
|
|
760
|
+
rowKeyField: options.rowKeyField,
|
|
761
|
+
getRowKey: (row, index) => latest.current.getRowKey?.(row, index),
|
|
762
|
+
getChildren: options.getChildren ? (row) => latest.current.getChildren?.(row) : void 0,
|
|
763
|
+
setChildren: options.setChildren ? (row, children) => latest.current.setChildren?.(row, children) : void 0,
|
|
764
|
+
onBeforeRowsChange: (transaction) => latest.current.onBeforeRowsChange?.(transaction),
|
|
765
|
+
onRowsChange: (transaction) => latest.current.onRowsChange?.(transaction)
|
|
766
|
+
})
|
|
767
|
+
);
|
|
768
|
+
const rows = useStoreSelector(model.store, (current) => [...current]);
|
|
769
|
+
return { model, rows };
|
|
770
|
+
}
|
|
771
|
+
function cloneSort(sort) {
|
|
772
|
+
return sort ? { ...sort } : null;
|
|
773
|
+
}
|
|
774
|
+
function cloneSorts(sorts) {
|
|
775
|
+
return sorts.map((sort) => ({ ...sort }));
|
|
776
|
+
}
|
|
777
|
+
function useGridSorting(core$1, data, options) {
|
|
778
|
+
const latest = React4__namespace.useRef(options);
|
|
779
|
+
latest.current = options;
|
|
780
|
+
const model = useGridFeature(
|
|
781
|
+
core$1,
|
|
782
|
+
"sorting",
|
|
783
|
+
"getSortingModel",
|
|
784
|
+
() => grid.createGridSortingFeature({
|
|
785
|
+
mode: options.multiSort ? "multiple" : "single",
|
|
786
|
+
defaultSort: options.sort !== void 0 ? options.sort : options.defaultSort,
|
|
787
|
+
defaultMultiSort: options.multiSortState !== void 0 ? options.multiSortState : options.defaultMultiSort,
|
|
788
|
+
onSortChange: (next) => latest.current.onSortChange?.(next),
|
|
789
|
+
onMultiSortChange: (next) => latest.current.onMultiSortChange?.(next)
|
|
790
|
+
})
|
|
791
|
+
);
|
|
792
|
+
const internalState = useStore(model.store);
|
|
793
|
+
const sortControlled = options.sort !== void 0;
|
|
794
|
+
const multiControlled = options.multiSortState !== void 0;
|
|
795
|
+
const sortSignature = JSON.stringify(options.sort);
|
|
796
|
+
const multiSortSignature = JSON.stringify(options.multiSortState);
|
|
797
|
+
const wasSortControlled = React4__namespace.useRef(sortControlled);
|
|
798
|
+
const uncontrolledSort = React4__namespace.useRef(null);
|
|
799
|
+
const hasUncontrolledSort = React4__namespace.useRef(!sortControlled);
|
|
800
|
+
const lastControlledSort = React4__namespace.useRef(cloneSort(options.sort ?? null));
|
|
801
|
+
const wasMultiSortControlled = React4__namespace.useRef(multiControlled);
|
|
802
|
+
const uncontrolledMultiSort = React4__namespace.useRef([]);
|
|
803
|
+
const hasUncontrolledMultiSort = React4__namespace.useRef(!multiControlled);
|
|
804
|
+
const lastControlledMultiSort = React4__namespace.useRef(
|
|
805
|
+
cloneSorts(options.multiSortState ?? [])
|
|
806
|
+
);
|
|
807
|
+
const leavingSortControlled = wasSortControlled.current && !sortControlled;
|
|
808
|
+
const leavingMultiSortControlled = wasMultiSortControlled.current && !multiControlled;
|
|
809
|
+
const enteringSortControlled = sortControlled && !wasSortControlled.current;
|
|
810
|
+
const enteringMultiSortControlled = multiControlled && !wasMultiSortControlled.current;
|
|
811
|
+
if (enteringSortControlled || enteringMultiSortControlled) {
|
|
812
|
+
const liveState = model.store.getState();
|
|
813
|
+
if (enteringSortControlled) {
|
|
814
|
+
uncontrolledSort.current = cloneSort(liveState.sort);
|
|
815
|
+
hasUncontrolledSort.current = true;
|
|
816
|
+
}
|
|
817
|
+
if (enteringMultiSortControlled) {
|
|
818
|
+
uncontrolledMultiSort.current = cloneSorts(liveState.multiSort);
|
|
819
|
+
hasUncontrolledMultiSort.current = true;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
if (!sortControlled && !leavingSortControlled) {
|
|
823
|
+
uncontrolledSort.current = cloneSort(internalState.sort);
|
|
824
|
+
hasUncontrolledSort.current = true;
|
|
825
|
+
}
|
|
826
|
+
if (!multiControlled && !leavingMultiSortControlled) {
|
|
827
|
+
uncontrolledMultiSort.current = cloneSorts(internalState.multiSort);
|
|
828
|
+
hasUncontrolledMultiSort.current = true;
|
|
829
|
+
}
|
|
830
|
+
if (sortControlled) lastControlledSort.current = cloneSort(options.sort ?? null);
|
|
831
|
+
if (multiControlled) {
|
|
832
|
+
lastControlledMultiSort.current = cloneSorts(options.multiSortState ?? []);
|
|
833
|
+
}
|
|
834
|
+
const sortState = sortControlled ? cloneSort(options.sort ?? null) : cloneSort(
|
|
835
|
+
leavingSortControlled ? hasUncontrolledSort.current ? uncontrolledSort.current : lastControlledSort.current : internalState.sort
|
|
836
|
+
);
|
|
837
|
+
const multiSortState = multiControlled ? cloneSorts(options.multiSortState ?? []) : cloneSorts(
|
|
838
|
+
leavingMultiSortControlled ? hasUncontrolledMultiSort.current ? uncontrolledMultiSort.current : lastControlledMultiSort.current : internalState.multiSort
|
|
839
|
+
);
|
|
840
|
+
React4__namespace.useEffect(() => {
|
|
841
|
+
if (sortControlled) {
|
|
842
|
+
const next = options.sort ?? null;
|
|
843
|
+
lastControlledSort.current = cloneSort(next);
|
|
844
|
+
model.syncSort(next);
|
|
845
|
+
} else if (wasSortControlled.current) {
|
|
846
|
+
const restore = hasUncontrolledSort.current ? uncontrolledSort.current : lastControlledSort.current;
|
|
847
|
+
if (!hasUncontrolledSort.current) {
|
|
848
|
+
uncontrolledSort.current = cloneSort(restore);
|
|
849
|
+
hasUncontrolledSort.current = true;
|
|
850
|
+
}
|
|
851
|
+
model.syncSort(restore);
|
|
852
|
+
}
|
|
853
|
+
wasSortControlled.current = sortControlled;
|
|
854
|
+
}, [model, options.sort, sortControlled, sortSignature]);
|
|
855
|
+
React4__namespace.useEffect(() => {
|
|
856
|
+
if (multiControlled) {
|
|
857
|
+
const next = cloneSorts(options.multiSortState ?? []);
|
|
858
|
+
lastControlledMultiSort.current = cloneSorts(next);
|
|
859
|
+
model.syncMultiSort(next);
|
|
860
|
+
} else if (wasMultiSortControlled.current) {
|
|
861
|
+
const restore = hasUncontrolledMultiSort.current ? uncontrolledMultiSort.current : lastControlledMultiSort.current;
|
|
862
|
+
uncontrolledMultiSort.current = cloneSorts(restore);
|
|
863
|
+
hasUncontrolledMultiSort.current = true;
|
|
864
|
+
model.syncMultiSort(restore);
|
|
865
|
+
}
|
|
866
|
+
wasMultiSortControlled.current = multiControlled;
|
|
867
|
+
}, [model, multiControlled, options.multiSortState, multiSortSignature]);
|
|
868
|
+
const setSort = React4__namespace.useCallback(
|
|
869
|
+
(next) => {
|
|
870
|
+
if (latest.current.sort !== void 0) model.syncSort(latest.current.sort ?? null);
|
|
871
|
+
model.setSort(next);
|
|
872
|
+
},
|
|
873
|
+
[model]
|
|
874
|
+
);
|
|
875
|
+
const cycleSort = React4__namespace.useCallback(
|
|
876
|
+
(column) => {
|
|
877
|
+
if (!column.sortable) return;
|
|
878
|
+
if (latest.current.sort !== void 0) model.syncSort(latest.current.sort ?? null);
|
|
879
|
+
model.cycleSort(column.key);
|
|
880
|
+
},
|
|
881
|
+
[model]
|
|
882
|
+
);
|
|
883
|
+
const setMultiSort = React4__namespace.useCallback(
|
|
884
|
+
(next) => {
|
|
885
|
+
if (latest.current.multiSortState !== void 0) {
|
|
886
|
+
model.syncMultiSort(latest.current.multiSortState);
|
|
887
|
+
}
|
|
888
|
+
model.setMultiSort(next);
|
|
889
|
+
},
|
|
890
|
+
[model]
|
|
891
|
+
);
|
|
892
|
+
const cycleMultiSort = React4__namespace.useCallback(
|
|
893
|
+
(column) => {
|
|
894
|
+
if (!column.sortable) return;
|
|
895
|
+
if (latest.current.multiSortState !== void 0) {
|
|
896
|
+
model.syncMultiSort(latest.current.multiSortState);
|
|
897
|
+
}
|
|
898
|
+
model.cycleMultiSort(column.key);
|
|
899
|
+
},
|
|
900
|
+
[model]
|
|
901
|
+
);
|
|
902
|
+
const getValue = React4__namespace.useCallback(
|
|
903
|
+
(row, column) => {
|
|
904
|
+
if (column.sortBy !== void 0) return row[column.sortBy];
|
|
905
|
+
return core.resolveTableColumnValue(row, column, options.formulaTables);
|
|
906
|
+
},
|
|
907
|
+
[options.formulaTables]
|
|
908
|
+
);
|
|
909
|
+
const sortComparator = React4__namespace.useMemo(
|
|
910
|
+
() => core.createTableSortComparator(sortState, options.leafColumns, getValue),
|
|
911
|
+
[getValue, options.leafColumns, sortState]
|
|
912
|
+
);
|
|
913
|
+
const multiSortComparator = React4__namespace.useMemo(
|
|
914
|
+
() => core.createTableMultiSortComparator(multiSortState, options.leafColumns, getValue),
|
|
915
|
+
[getValue, options.leafColumns, multiSortState]
|
|
916
|
+
);
|
|
917
|
+
const sortedData = React4__namespace.useMemo(
|
|
918
|
+
() => core.sortTableRows(data, options.leafColumns, {
|
|
919
|
+
mode: options.multiSort ? "multiple" : "single",
|
|
920
|
+
sort: sortState,
|
|
921
|
+
multiSort: multiSortState,
|
|
922
|
+
getValue
|
|
923
|
+
}),
|
|
924
|
+
[data, getValue, multiSortState, options.leafColumns, options.multiSort, sortState]
|
|
925
|
+
);
|
|
926
|
+
return {
|
|
927
|
+
core: core$1,
|
|
928
|
+
model,
|
|
929
|
+
sortState,
|
|
930
|
+
cycleSort,
|
|
931
|
+
setSort,
|
|
932
|
+
sortComparator,
|
|
933
|
+
sortedData,
|
|
934
|
+
multiSortState,
|
|
935
|
+
cycleMultiSort,
|
|
936
|
+
setMultiSort,
|
|
937
|
+
multiSortComparator
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
var useIsomorphicLayoutEffect = typeof window === "undefined" || typeof document === "undefined" ? React4__namespace.useEffect : React4__namespace.useLayoutEffect;
|
|
941
|
+
function useGridVirtual(core, options) {
|
|
942
|
+
const latest = React4__namespace.useRef(options);
|
|
943
|
+
latest.current = options;
|
|
944
|
+
const model = useGridFeature(
|
|
945
|
+
core,
|
|
946
|
+
"virtual",
|
|
947
|
+
"getVirtualModel",
|
|
948
|
+
() => grid.createGridVirtualFeature({
|
|
949
|
+
count: options.items.length,
|
|
950
|
+
estimateSize: (index) => {
|
|
951
|
+
const estimate = latest.current.estimateSize;
|
|
952
|
+
return typeof estimate === "function" ? estimate(index) : estimate;
|
|
953
|
+
},
|
|
954
|
+
viewportSize: options.viewportSize,
|
|
955
|
+
scrollOffset: options.scrollOffset,
|
|
956
|
+
buffer: options.buffer,
|
|
957
|
+
fixedSize: typeof options.estimateSize === "number" ? options.estimateSize : null,
|
|
958
|
+
getItemKey: (index) => {
|
|
959
|
+
const item = latest.current.items[index];
|
|
960
|
+
const keyOf = latest.current.getItemKey;
|
|
961
|
+
return item !== void 0 && keyOf ? keyOf(item, index) : index;
|
|
962
|
+
},
|
|
963
|
+
onRangeChange: (change) => latest.current.onRangeChange?.(change)
|
|
964
|
+
})
|
|
965
|
+
);
|
|
966
|
+
useIsomorphicLayoutEffect(() => {
|
|
967
|
+
model.setCount(options.items.length);
|
|
968
|
+
}, [model, options.items, options.getItemKey]);
|
|
969
|
+
useIsomorphicLayoutEffect(() => {
|
|
970
|
+
model.setBuffer(options.buffer ?? 0);
|
|
971
|
+
}, [model, options.buffer]);
|
|
972
|
+
useIsomorphicLayoutEffect(() => {
|
|
973
|
+
model.setEstimateSize(
|
|
974
|
+
options.estimateSize,
|
|
975
|
+
typeof options.estimateSize === "number" ? options.estimateSize : null
|
|
976
|
+
);
|
|
977
|
+
}, [model, options.estimateSize]);
|
|
978
|
+
useIsomorphicLayoutEffect(() => {
|
|
979
|
+
if (options.viewportSize !== void 0) model.setViewportSize(options.viewportSize);
|
|
980
|
+
}, [model, options.viewportSize]);
|
|
981
|
+
useIsomorphicLayoutEffect(() => {
|
|
982
|
+
if (options.scrollOffset !== void 0) model.setScroll(options.scrollOffset);
|
|
983
|
+
}, [model, options.scrollOffset]);
|
|
984
|
+
return { model };
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
exports.toGridColumnsOptions = toGridColumnsOptions;
|
|
988
|
+
exports.toGridExpansionOptions = toGridExpansionOptions;
|
|
989
|
+
exports.toGridFilteringOptions = toGridFilteringOptions;
|
|
990
|
+
exports.toGridPaginationOptions = toGridPaginationOptions;
|
|
991
|
+
exports.toGridRowsOptions = toGridRowsOptions;
|
|
992
|
+
exports.toGridSelectionOptions = toGridSelectionOptions;
|
|
993
|
+
exports.toGridSortingOptions = toGridSortingOptions;
|
|
994
|
+
exports.useGridClipboard = useGridClipboard;
|
|
995
|
+
exports.useGridColumns = useGridColumns;
|
|
996
|
+
exports.useGridCore = useGridCore;
|
|
997
|
+
exports.useGridEditing = useGridEditing;
|
|
998
|
+
exports.useGridExpansion = useGridExpansion;
|
|
999
|
+
exports.useGridFiltering = useGridFiltering;
|
|
1000
|
+
exports.useGridPagination = useGridPagination;
|
|
1001
|
+
exports.useGridRange = useGridRange;
|
|
1002
|
+
exports.useGridRows = useGridRows;
|
|
1003
|
+
exports.useGridSelection = useGridSelection;
|
|
1004
|
+
exports.useGridSorting = useGridSorting;
|
|
1005
|
+
exports.useGridVirtual = useGridVirtual;
|
|
1006
|
+
//# sourceMappingURL=grid.cjs.map
|
|
1007
|
+
//# sourceMappingURL=grid.cjs.map
|