@zvndev/yable-react 0.5.0 → 0.5.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.
- package/dist/index.cjs +367 -341
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +142 -116
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var yableCore = require('@zvndev/yable-core');
|
|
4
|
-
var
|
|
4
|
+
var React4 = require('react');
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var reactDom = require('react-dom');
|
|
7
7
|
var rowDragging = require('@zvndev/yable-core/features/rowDragging');
|
|
8
8
|
|
|
9
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var React4__default = /*#__PURE__*/_interopDefault(React4);
|
|
12
12
|
|
|
13
13
|
// src/index.ts
|
|
14
|
-
var YableContext =
|
|
14
|
+
var YableContext = React4.createContext({});
|
|
15
15
|
function useYableDefaults() {
|
|
16
|
-
return
|
|
16
|
+
return React4.useContext(YableContext);
|
|
17
17
|
}
|
|
18
18
|
function YableProvider({
|
|
19
19
|
children,
|
|
@@ -131,7 +131,7 @@ function shallowEqual(a, b) {
|
|
|
131
131
|
}
|
|
132
132
|
function useTable(options) {
|
|
133
133
|
const providerDefaults = useYableDefaults();
|
|
134
|
-
const optionsWithDefaults =
|
|
134
|
+
const optionsWithDefaults = React4.useMemo(() => {
|
|
135
135
|
const profile = resolveYableProfile(
|
|
136
136
|
options.config ?? providerDefaults.config,
|
|
137
137
|
options.configProfile ?? providerDefaults.tableProfile
|
|
@@ -156,7 +156,7 @@ function useTable(options) {
|
|
|
156
156
|
providerDefaults.defaultColumnDef,
|
|
157
157
|
providerDefaults.tableProfile
|
|
158
158
|
]);
|
|
159
|
-
const [state, setState] =
|
|
159
|
+
const [state, setState] = React4.useState(() => ({
|
|
160
160
|
sorting: [],
|
|
161
161
|
columnFilters: [],
|
|
162
162
|
globalFilter: "",
|
|
@@ -193,26 +193,26 @@ function useTable(options) {
|
|
|
193
193
|
...options.initialState,
|
|
194
194
|
...options.state
|
|
195
195
|
}));
|
|
196
|
-
const stateRef =
|
|
196
|
+
const stateRef = React4.useRef(state);
|
|
197
197
|
stateRef.current = state;
|
|
198
|
-
const prevOptionsRef =
|
|
199
|
-
const stableOptions =
|
|
198
|
+
const prevOptionsRef = React4.useRef(optionsWithDefaults);
|
|
199
|
+
const stableOptions = React4.useMemo(() => {
|
|
200
200
|
if (shallowEqual(prevOptionsRef.current, optionsWithDefaults)) {
|
|
201
201
|
return prevOptionsRef.current;
|
|
202
202
|
}
|
|
203
203
|
prevOptionsRef.current = optionsWithDefaults;
|
|
204
204
|
return optionsWithDefaults;
|
|
205
205
|
}, [optionsWithDefaults]);
|
|
206
|
-
const onStateChangeRef =
|
|
206
|
+
const onStateChangeRef = React4.useRef(options.onStateChange);
|
|
207
207
|
onStateChangeRef.current = options.onStateChange;
|
|
208
|
-
const resolvedState =
|
|
208
|
+
const resolvedState = React4.useMemo(
|
|
209
209
|
() => ({
|
|
210
210
|
...state,
|
|
211
211
|
...stableOptions.state
|
|
212
212
|
}),
|
|
213
213
|
[state, stableOptions.state]
|
|
214
214
|
);
|
|
215
|
-
const onStateChange =
|
|
215
|
+
const onStateChange = React4.useCallback((updater) => {
|
|
216
216
|
const latest = onStateChangeRef.current;
|
|
217
217
|
if (latest) {
|
|
218
218
|
latest(updater);
|
|
@@ -220,7 +220,7 @@ function useTable(options) {
|
|
|
220
220
|
setState((prev) => yableCore.functionalUpdate(updater, prev));
|
|
221
221
|
}
|
|
222
222
|
}, []);
|
|
223
|
-
const resolvedOptions =
|
|
223
|
+
const resolvedOptions = React4.useMemo(
|
|
224
224
|
() => ({
|
|
225
225
|
...stableOptions,
|
|
226
226
|
state: resolvedState,
|
|
@@ -228,7 +228,7 @@ function useTable(options) {
|
|
|
228
228
|
}),
|
|
229
229
|
[stableOptions, resolvedState, onStateChange]
|
|
230
230
|
);
|
|
231
|
-
const tableRef =
|
|
231
|
+
const tableRef = React4.useRef(null);
|
|
232
232
|
if (!tableRef.current) {
|
|
233
233
|
tableRef.current = yableCore.createTable(resolvedOptions);
|
|
234
234
|
} else {
|
|
@@ -241,7 +241,7 @@ function useTable(options) {
|
|
|
241
241
|
})
|
|
242
242
|
);
|
|
243
243
|
}
|
|
244
|
-
|
|
244
|
+
React4.useEffect(() => {
|
|
245
245
|
const table = tableRef.current;
|
|
246
246
|
if (!table) return;
|
|
247
247
|
const unsubscribers = [
|
|
@@ -267,7 +267,7 @@ function useTable(options) {
|
|
|
267
267
|
options.onRowContextMenu,
|
|
268
268
|
options.onRowDoubleClick
|
|
269
269
|
]);
|
|
270
|
-
|
|
270
|
+
React4.useEffect(() => {
|
|
271
271
|
return () => {
|
|
272
272
|
if (tableRef.current) {
|
|
273
273
|
tableRef.current.events.removeAllListeners();
|
|
@@ -292,26 +292,26 @@ function useServerTable({
|
|
|
292
292
|
getRowId,
|
|
293
293
|
...tableOptions
|
|
294
294
|
}) {
|
|
295
|
-
const [rows, setRows] =
|
|
296
|
-
const [cursor, setCursor] =
|
|
297
|
-
const [hasMore, setHasMore] =
|
|
298
|
-
const [rowCount, setRowCount] =
|
|
299
|
-
const [pageCount, setPageCount] =
|
|
300
|
-
const [sorting, setSorting] =
|
|
301
|
-
const [columnFilters, setColumnFilters] =
|
|
302
|
-
const [globalFilter, setGlobalFilter] =
|
|
303
|
-
const [pagination, setPagination] =
|
|
304
|
-
const [loading, setLoading] =
|
|
305
|
-
const [error, setError] =
|
|
306
|
-
const abortRef =
|
|
307
|
-
const cursorRef =
|
|
308
|
-
const fetchDataRef =
|
|
309
|
-
const updateRowRef =
|
|
310
|
-
const resolveRowId =
|
|
295
|
+
const [rows, setRows] = React4.useState(initialRows);
|
|
296
|
+
const [cursor, setCursor] = React4.useState(initialCursor);
|
|
297
|
+
const [hasMore, setHasMore] = React4.useState(initialHasMore);
|
|
298
|
+
const [rowCount, setRowCount] = React4.useState(initialRowCount);
|
|
299
|
+
const [pageCount, setPageCount] = React4.useState(initialPageCount);
|
|
300
|
+
const [sorting, setSorting] = React4.useState(initialSorting);
|
|
301
|
+
const [columnFilters, setColumnFilters] = React4.useState(initialColumnFilters);
|
|
302
|
+
const [globalFilter, setGlobalFilter] = React4.useState(initialGlobalFilter);
|
|
303
|
+
const [pagination, setPagination] = React4.useState(initialPagination);
|
|
304
|
+
const [loading, setLoading] = React4.useState(false);
|
|
305
|
+
const [error, setError] = React4.useState(null);
|
|
306
|
+
const abortRef = React4.useRef(null);
|
|
307
|
+
const cursorRef = React4.useRef(cursor);
|
|
308
|
+
const fetchDataRef = React4.useRef(fetchData);
|
|
309
|
+
const updateRowRef = React4.useRef(updateRow);
|
|
310
|
+
const resolveRowId = React4.useCallback(
|
|
311
311
|
(row, index) => getRowId?.(row, index) ?? String(row.id ?? index),
|
|
312
312
|
[getRowId]
|
|
313
313
|
);
|
|
314
|
-
const runFetch =
|
|
314
|
+
const runFetch = React4.useCallback(
|
|
315
315
|
async (mode) => {
|
|
316
316
|
abortRef.current?.abort();
|
|
317
317
|
const abort = new AbortController();
|
|
@@ -341,12 +341,12 @@ function useServerTable({
|
|
|
341
341
|
},
|
|
342
342
|
[columnFilters, globalFilter, pagination, sorting]
|
|
343
343
|
);
|
|
344
|
-
const refresh =
|
|
345
|
-
const loadMore =
|
|
344
|
+
const refresh = React4.useCallback(() => runFetch("replace"), [runFetch]);
|
|
345
|
+
const loadMore = React4.useCallback(async () => {
|
|
346
346
|
if (!hasMore || loading) return;
|
|
347
347
|
await runFetch("append");
|
|
348
348
|
}, [hasMore, loading, runFetch]);
|
|
349
|
-
const patchRow =
|
|
349
|
+
const patchRow = React4.useCallback(
|
|
350
350
|
async (rowId, patch) => {
|
|
351
351
|
const previousRow = rows.find((row, index) => resolveRowId(row, index) === rowId);
|
|
352
352
|
setRows(
|
|
@@ -378,20 +378,20 @@ function useServerTable({
|
|
|
378
378
|
},
|
|
379
379
|
[resolveRowId, rows]
|
|
380
380
|
);
|
|
381
|
-
|
|
381
|
+
React4.useEffect(() => {
|
|
382
382
|
fetchDataRef.current = fetchData;
|
|
383
383
|
}, [fetchData]);
|
|
384
|
-
|
|
384
|
+
React4.useEffect(() => {
|
|
385
385
|
updateRowRef.current = updateRow;
|
|
386
386
|
}, [updateRow]);
|
|
387
|
-
|
|
387
|
+
React4.useEffect(() => {
|
|
388
388
|
if (!autoLoad) return;
|
|
389
389
|
void refresh();
|
|
390
390
|
}, [autoLoad, refresh]);
|
|
391
|
-
|
|
391
|
+
React4.useEffect(() => {
|
|
392
392
|
cursorRef.current = cursor;
|
|
393
393
|
}, [cursor]);
|
|
394
|
-
|
|
394
|
+
React4.useEffect(() => () => abortRef.current?.abort(), []);
|
|
395
395
|
const table = useTable({
|
|
396
396
|
...tableOptions,
|
|
397
397
|
data: rows,
|
|
@@ -428,7 +428,7 @@ function useServerTable({
|
|
|
428
428
|
setHasMore(true);
|
|
429
429
|
}
|
|
430
430
|
});
|
|
431
|
-
return
|
|
431
|
+
return React4.useMemo(
|
|
432
432
|
() => ({
|
|
433
433
|
table,
|
|
434
434
|
rows,
|
|
@@ -528,25 +528,25 @@ function useTablePersistence(options) {
|
|
|
528
528
|
version = 0,
|
|
529
529
|
storage: customStorage
|
|
530
530
|
} = options;
|
|
531
|
-
const storage =
|
|
532
|
-
const initialState =
|
|
531
|
+
const storage = React4.useMemo(() => resolveStorage(customStorage), [customStorage]);
|
|
532
|
+
const initialState = React4.useMemo(
|
|
533
533
|
() => readState(storage, key, version, persistedKeys),
|
|
534
534
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- intentionally read only on mount
|
|
535
535
|
[]
|
|
536
536
|
);
|
|
537
|
-
const [state, setState] =
|
|
538
|
-
const timerRef =
|
|
539
|
-
const keyRef =
|
|
537
|
+
const [state, setState] = React4.useState(initialState);
|
|
538
|
+
const timerRef = React4.useRef(null);
|
|
539
|
+
const keyRef = React4.useRef(key);
|
|
540
540
|
keyRef.current = key;
|
|
541
|
-
const versionRef =
|
|
541
|
+
const versionRef = React4.useRef(version);
|
|
542
542
|
versionRef.current = version;
|
|
543
|
-
const persistedKeysRef =
|
|
543
|
+
const persistedKeysRef = React4.useRef(persistedKeys);
|
|
544
544
|
persistedKeysRef.current = persistedKeys;
|
|
545
|
-
const debounceRef =
|
|
545
|
+
const debounceRef = React4.useRef(debounceMs);
|
|
546
546
|
debounceRef.current = debounceMs;
|
|
547
|
-
const storageRef =
|
|
547
|
+
const storageRef = React4.useRef(storage);
|
|
548
548
|
storageRef.current = storage;
|
|
549
|
-
const onStateChange =
|
|
549
|
+
const onStateChange = React4.useCallback((updater) => {
|
|
550
550
|
setState((prev) => {
|
|
551
551
|
const next = yableCore.functionalUpdate(updater, prev);
|
|
552
552
|
if (timerRef.current !== null) {
|
|
@@ -563,14 +563,14 @@ function useTablePersistence(options) {
|
|
|
563
563
|
return next;
|
|
564
564
|
});
|
|
565
565
|
}, []);
|
|
566
|
-
|
|
566
|
+
React4.useEffect(() => {
|
|
567
567
|
return () => {
|
|
568
568
|
if (timerRef.current !== null) {
|
|
569
569
|
clearTimeout(timerRef.current);
|
|
570
570
|
}
|
|
571
571
|
};
|
|
572
572
|
}, []);
|
|
573
|
-
const clearPersistedState =
|
|
573
|
+
const clearPersistedState = React4.useCallback(() => {
|
|
574
574
|
const s = storageRef.current;
|
|
575
575
|
if (s) {
|
|
576
576
|
try {
|
|
@@ -599,10 +599,10 @@ function useVirtualization({
|
|
|
599
599
|
}) {
|
|
600
600
|
const hasPretextHeights = !!(pretextHeights && pretextPrefixSums && pretextHeights.length >= totalRows);
|
|
601
601
|
const isFixedHeight = typeof rowHeight === "number" && !hasPretextHeights;
|
|
602
|
-
const heightCacheRef =
|
|
603
|
-
const heightCacheVersionRef =
|
|
604
|
-
const [heightCacheVersion, setHeightCacheVersion] =
|
|
605
|
-
const getRowHeight =
|
|
602
|
+
const heightCacheRef = React4.useRef(/* @__PURE__ */ new Map());
|
|
603
|
+
const heightCacheVersionRef = React4.useRef(0);
|
|
604
|
+
const [heightCacheVersion, setHeightCacheVersion] = React4.useState(0);
|
|
605
|
+
const getRowHeight = React4.useCallback(
|
|
606
606
|
(index) => {
|
|
607
607
|
if (hasPretextHeights) return pretextHeights[index];
|
|
608
608
|
if (isFixedHeight) return rowHeight;
|
|
@@ -616,9 +616,9 @@ function useVirtualization({
|
|
|
616
616
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
617
617
|
[rowHeight, isFixedHeight, hasPretextHeights, pretextHeights, heightCacheVersion]
|
|
618
618
|
);
|
|
619
|
-
const [scrollState, setScrollState] =
|
|
620
|
-
const rafRef =
|
|
621
|
-
|
|
619
|
+
const [scrollState, setScrollState] = React4.useState({ scrollTop: 0, containerHeight: 0 });
|
|
620
|
+
const rafRef = React4.useRef(null);
|
|
621
|
+
React4.useEffect(() => {
|
|
622
622
|
const container = containerRef.current;
|
|
623
623
|
if (!container) return;
|
|
624
624
|
setScrollState({
|
|
@@ -662,24 +662,24 @@ function useVirtualization({
|
|
|
662
662
|
}
|
|
663
663
|
};
|
|
664
664
|
}, [containerRef, totalRows]);
|
|
665
|
-
|
|
665
|
+
React4.useEffect(() => {
|
|
666
666
|
if (!isFixedHeight) {
|
|
667
667
|
heightCacheRef.current.clear();
|
|
668
668
|
}
|
|
669
669
|
}, [totalRows, isFixedHeight]);
|
|
670
|
-
|
|
670
|
+
React4.useEffect(() => {
|
|
671
671
|
if (!isFixedHeight && columnSizingHash !== void 0) {
|
|
672
672
|
heightCacheRef.current.clear();
|
|
673
673
|
heightCacheVersionRef.current += 1;
|
|
674
674
|
setHeightCacheVersion(heightCacheVersionRef.current);
|
|
675
675
|
}
|
|
676
676
|
}, [columnSizingHash]);
|
|
677
|
-
const invalidateRowHeights =
|
|
677
|
+
const invalidateRowHeights = React4.useCallback(() => {
|
|
678
678
|
heightCacheRef.current.clear();
|
|
679
679
|
heightCacheVersionRef.current += 1;
|
|
680
680
|
setHeightCacheVersion(heightCacheVersionRef.current);
|
|
681
681
|
}, []);
|
|
682
|
-
const scrollTo =
|
|
682
|
+
const scrollTo = React4.useCallback(
|
|
683
683
|
(index) => {
|
|
684
684
|
const container = containerRef.current;
|
|
685
685
|
if (!container || totalRows === 0) return;
|
|
@@ -706,7 +706,7 @@ function useVirtualization({
|
|
|
706
706
|
pretextPrefixSums
|
|
707
707
|
]
|
|
708
708
|
);
|
|
709
|
-
const totalHeight =
|
|
709
|
+
const totalHeight = React4.useMemo(() => {
|
|
710
710
|
if (totalRows === 0) return 0;
|
|
711
711
|
if (hasPretextHeights && pretextPrefixSums) return pretextPrefixSums[totalRows];
|
|
712
712
|
if (isFixedHeight) return totalRows * rowHeight;
|
|
@@ -855,18 +855,18 @@ function useColumnVirtualization({
|
|
|
855
855
|
enabled = true,
|
|
856
856
|
sizingKey
|
|
857
857
|
}) {
|
|
858
|
-
const [scrollState, setScrollState] =
|
|
858
|
+
const [scrollState, setScrollState] = React4.useState({
|
|
859
859
|
scrollLeft: 0,
|
|
860
860
|
containerWidth: 0
|
|
861
861
|
});
|
|
862
|
-
const rafRef =
|
|
863
|
-
const sizes =
|
|
862
|
+
const rafRef = React4.useRef(null);
|
|
863
|
+
const sizes = React4.useMemo(
|
|
864
864
|
() => columns.map((column) => column.getSize()),
|
|
865
865
|
// `sizingKey` is an explicit invalidation hook for stable Column objects whose getSize value changed.
|
|
866
866
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
867
867
|
[columns, sizingKey]
|
|
868
868
|
);
|
|
869
|
-
const offsets =
|
|
869
|
+
const offsets = React4.useMemo(() => {
|
|
870
870
|
const next = new Array(columns.length + 1);
|
|
871
871
|
next[0] = 0;
|
|
872
872
|
for (let i = 0; i < columns.length; i++) {
|
|
@@ -875,7 +875,7 @@ function useColumnVirtualization({
|
|
|
875
875
|
return next;
|
|
876
876
|
}, [columns.length, sizes]);
|
|
877
877
|
const totalWidth = offsets[offsets.length - 1] ?? 0;
|
|
878
|
-
|
|
878
|
+
React4.useEffect(() => {
|
|
879
879
|
const container = containerRef.current;
|
|
880
880
|
if (!container) return;
|
|
881
881
|
setScrollState({
|
|
@@ -922,7 +922,7 @@ function useColumnVirtualization({
|
|
|
922
922
|
resizeObserver?.disconnect();
|
|
923
923
|
};
|
|
924
924
|
}, [containerRef]);
|
|
925
|
-
const scrollToIndex =
|
|
925
|
+
const scrollToIndex = React4.useCallback(
|
|
926
926
|
(index) => {
|
|
927
927
|
const container = containerRef.current;
|
|
928
928
|
if (!container || columns.length === 0) return;
|
|
@@ -1010,12 +1010,12 @@ function usePretextMeasurement({
|
|
|
1010
1010
|
minRowHeight = 32,
|
|
1011
1011
|
enabled = true
|
|
1012
1012
|
}) {
|
|
1013
|
-
const [pretext, setPretext] =
|
|
1014
|
-
const [ready, setReady] =
|
|
1015
|
-
const prepareTimeRef =
|
|
1016
|
-
const layoutTimeRef =
|
|
1013
|
+
const [pretext, setPretext] = React4.useState(null);
|
|
1014
|
+
const [ready, setReady] = React4.useState(false);
|
|
1015
|
+
const prepareTimeRef = React4.useRef(0);
|
|
1016
|
+
const layoutTimeRef = React4.useRef(0);
|
|
1017
1017
|
const columnWidthsKey = columns.map((c) => `${c.columnId}:${c.width}`).join("|");
|
|
1018
|
-
|
|
1018
|
+
React4.useEffect(() => {
|
|
1019
1019
|
if (!enabled) return;
|
|
1020
1020
|
let cancelled = false;
|
|
1021
1021
|
loadPretext().then((mod) => {
|
|
@@ -1025,8 +1025,8 @@ function usePretextMeasurement({
|
|
|
1025
1025
|
cancelled = true;
|
|
1026
1026
|
};
|
|
1027
1027
|
}, [enabled]);
|
|
1028
|
-
const preparedCacheRef =
|
|
1029
|
-
const preparedCells =
|
|
1028
|
+
const preparedCacheRef = React4.useRef(/* @__PURE__ */ new Map());
|
|
1029
|
+
const preparedCells = React4.useMemo(() => {
|
|
1030
1030
|
if (!pretext || !enabled || data.length === 0 || columns.length === 0) return null;
|
|
1031
1031
|
const cache = preparedCacheRef.current;
|
|
1032
1032
|
const start = performance.now();
|
|
@@ -1053,7 +1053,7 @@ function usePretextMeasurement({
|
|
|
1053
1053
|
data,
|
|
1054
1054
|
columns.map((c) => `${c.columnId}:${c.font}:${c.fixedHeight ? "F" : "T"}`).join("|")
|
|
1055
1055
|
]);
|
|
1056
|
-
const measurement =
|
|
1056
|
+
const measurement = React4.useMemo(() => {
|
|
1057
1057
|
if (!pretext || !preparedCells) {
|
|
1058
1058
|
return { rowHeights: null, prefixSums: null, totalHeight: 0 };
|
|
1059
1059
|
}
|
|
@@ -1094,7 +1094,7 @@ function usePretextMeasurement({
|
|
|
1094
1094
|
totalHeight: prefixSums[data.length]
|
|
1095
1095
|
};
|
|
1096
1096
|
}, [pretext, preparedCells, columnWidthsKey, minRowHeight, data.length]);
|
|
1097
|
-
|
|
1097
|
+
React4.useEffect(() => {
|
|
1098
1098
|
if (measurement.rowHeights) setReady(true);
|
|
1099
1099
|
}, [measurement.rowHeights]);
|
|
1100
1100
|
return {
|
|
@@ -1143,7 +1143,7 @@ function CellCurrency({
|
|
|
1143
1143
|
}) {
|
|
1144
1144
|
const raw = context.getValue();
|
|
1145
1145
|
const num = typeof raw === "number" ? raw : Number(raw);
|
|
1146
|
-
const formatter =
|
|
1146
|
+
const formatter = React4.useMemo(
|
|
1147
1147
|
() => new Intl.NumberFormat(locale, {
|
|
1148
1148
|
style: "currency",
|
|
1149
1149
|
currency,
|
|
@@ -1220,7 +1220,7 @@ function CellNumeric({
|
|
|
1220
1220
|
}) {
|
|
1221
1221
|
const raw = context.getValue();
|
|
1222
1222
|
const num = typeof raw === "number" ? raw : Number(raw);
|
|
1223
|
-
const formatter =
|
|
1223
|
+
const formatter = React4.useMemo(
|
|
1224
1224
|
() => new Intl.NumberFormat(locale, {
|
|
1225
1225
|
minimumFractionDigits: decimals,
|
|
1226
1226
|
maximumFractionDigits: decimals
|
|
@@ -1474,7 +1474,7 @@ function useAutoMeasurements({
|
|
|
1474
1474
|
shouldMeasureColumn = defaultShouldMeasure
|
|
1475
1475
|
}) {
|
|
1476
1476
|
const widthKey = columns.map((c) => `${getColumnId2(c) ?? "?"}:${getColumnWidth(c)}`).join("|");
|
|
1477
|
-
return
|
|
1477
|
+
return React4.useMemo(() => {
|
|
1478
1478
|
const result = [];
|
|
1479
1479
|
for (const col of columns) {
|
|
1480
1480
|
const id = getColumnId2(col);
|
|
@@ -1511,7 +1511,7 @@ function useTableRowHeights({
|
|
|
1511
1511
|
defaultRecipe,
|
|
1512
1512
|
getColumnWidth
|
|
1513
1513
|
});
|
|
1514
|
-
const accessorMap =
|
|
1514
|
+
const accessorMap = React4.useMemo(() => {
|
|
1515
1515
|
const map = /* @__PURE__ */ new Map();
|
|
1516
1516
|
for (const col of columns) {
|
|
1517
1517
|
const id = col.id ?? col.accessorKey;
|
|
@@ -1528,7 +1528,7 @@ function useTableRowHeights({
|
|
|
1528
1528
|
}
|
|
1529
1529
|
return map;
|
|
1530
1530
|
}, [columns]);
|
|
1531
|
-
const getCellText =
|
|
1531
|
+
const getCellText = React4.useMemo(
|
|
1532
1532
|
() => (row, columnId) => {
|
|
1533
1533
|
const get = accessorMap.get(columnId);
|
|
1534
1534
|
if (!get) return "";
|
|
@@ -1547,10 +1547,10 @@ function useTableRowHeights({
|
|
|
1547
1547
|
});
|
|
1548
1548
|
return { ...result, measurements };
|
|
1549
1549
|
}
|
|
1550
|
-
var TableContext =
|
|
1550
|
+
var TableContext = React4.createContext(null);
|
|
1551
1551
|
var TableProvider = TableContext.Provider;
|
|
1552
1552
|
function useTableContext() {
|
|
1553
|
-
const ctx =
|
|
1553
|
+
const ctx = React4.useContext(TableContext);
|
|
1554
1554
|
if (!ctx) {
|
|
1555
1555
|
throw new Error(
|
|
1556
1556
|
"[yable E001] useTableContext must be used within a <Table> component. Did you forget to pass the `table` prop?"
|
|
@@ -1611,7 +1611,7 @@ function formatValue(value) {
|
|
|
1611
1611
|
return JSON.stringify(value);
|
|
1612
1612
|
}
|
|
1613
1613
|
function SetFilter({ column, className }) {
|
|
1614
|
-
const [open, setOpen] =
|
|
1614
|
+
const [open, setOpen] = React4.useState(false);
|
|
1615
1615
|
const filterValue = column.getFilterValue();
|
|
1616
1616
|
const selectedValues = Array.isArray(filterValue) ? filterValue : filterValue == null || filterValue === "" ? [] : [filterValue];
|
|
1617
1617
|
const facetedUniqueValues = column.getFacetedUniqueValues();
|
|
@@ -1808,10 +1808,10 @@ function TableHeader({
|
|
|
1808
1808
|
}) {
|
|
1809
1809
|
const headerGroups = table.getHeaderGroups();
|
|
1810
1810
|
const visibleColumns = table.getVisibleLeafColumns();
|
|
1811
|
-
const theadRef =
|
|
1812
|
-
const reorderEndRef =
|
|
1813
|
-
const [drag, setDrag] =
|
|
1814
|
-
const commitReorder =
|
|
1811
|
+
const theadRef = React4.useRef(null);
|
|
1812
|
+
const reorderEndRef = React4.useRef(0);
|
|
1813
|
+
const [drag, setDrag] = React4.useState(null);
|
|
1814
|
+
const commitReorder = React4.useCallback(
|
|
1815
1815
|
(d) => {
|
|
1816
1816
|
if (d.toIndex === d.fromIndex || d.toIndex === d.fromIndex + 1) return;
|
|
1817
1817
|
const order = table.getState().columnOrder;
|
|
@@ -1825,7 +1825,7 @@ function TableHeader({
|
|
|
1825
1825
|
},
|
|
1826
1826
|
[table]
|
|
1827
1827
|
);
|
|
1828
|
-
const beginReorder =
|
|
1828
|
+
const beginReorder = React4.useCallback(
|
|
1829
1829
|
(e, columnId) => {
|
|
1830
1830
|
if (e.button !== 0) return;
|
|
1831
1831
|
const thead = theadRef.current;
|
|
@@ -1917,7 +1917,7 @@ function TableHeader({
|
|
|
1917
1917
|
},
|
|
1918
1918
|
[visibleColumns, table, commitReorder]
|
|
1919
1919
|
);
|
|
1920
|
-
const transformFor =
|
|
1920
|
+
const transformFor = React4.useCallback(
|
|
1921
1921
|
(columnId) => {
|
|
1922
1922
|
if (!drag) return 0;
|
|
1923
1923
|
const i = visibleColumns.findIndex((c) => c.id === columnId);
|
|
@@ -1965,7 +1965,7 @@ function TableHeader({
|
|
|
1965
1965
|
function FloatingFilterCell({
|
|
1966
1966
|
column
|
|
1967
1967
|
}) {
|
|
1968
|
-
const style =
|
|
1968
|
+
const style = React4.useMemo(() => {
|
|
1969
1969
|
const next = {
|
|
1970
1970
|
width: column.getSize(),
|
|
1971
1971
|
minWidth: column.columnDef.minSize,
|
|
@@ -2003,7 +2003,7 @@ function HeaderCell({
|
|
|
2003
2003
|
const canReorder = column.getCanReorder() && !header.isPlaceholder;
|
|
2004
2004
|
const pinned = column.getIsPinned();
|
|
2005
2005
|
const headerContent = header.isPlaceholder ? null : typeof column.columnDef.header === "function" ? column.columnDef.header(header.getContext()) : column.columnDef.header ?? header.id;
|
|
2006
|
-
const style =
|
|
2006
|
+
const style = React4.useMemo(() => {
|
|
2007
2007
|
const s = {
|
|
2008
2008
|
width: header.getSize(),
|
|
2009
2009
|
minWidth: column.columnDef.minSize,
|
|
@@ -2022,8 +2022,8 @@ function HeaderCell({
|
|
|
2022
2022
|
}
|
|
2023
2023
|
return s;
|
|
2024
2024
|
}, [header, column, pinned, isDragSource, dragTransform]);
|
|
2025
|
-
const lastResizeEndRef =
|
|
2026
|
-
const startResize =
|
|
2025
|
+
const lastResizeEndRef = React4.useRef(0);
|
|
2026
|
+
const startResize = React4.useCallback(
|
|
2027
2027
|
(e) => {
|
|
2028
2028
|
e.stopPropagation();
|
|
2029
2029
|
const onEnd = () => {
|
|
@@ -2038,17 +2038,17 @@ function HeaderCell({
|
|
|
2038
2038
|
},
|
|
2039
2039
|
[header]
|
|
2040
2040
|
);
|
|
2041
|
-
const handleResizeClick =
|
|
2041
|
+
const handleResizeClick = React4.useCallback((e) => {
|
|
2042
2042
|
e.stopPropagation();
|
|
2043
2043
|
}, []);
|
|
2044
|
-
const handleContentPointerDown =
|
|
2044
|
+
const handleContentPointerDown = React4.useCallback(
|
|
2045
2045
|
(e) => {
|
|
2046
2046
|
if (!canReorder || pinned) return;
|
|
2047
2047
|
onReorderPointerDown(e, column.id);
|
|
2048
2048
|
},
|
|
2049
2049
|
[canReorder, pinned, onReorderPointerDown, column.id]
|
|
2050
2050
|
);
|
|
2051
|
-
const handleHeaderClick =
|
|
2051
|
+
const handleHeaderClick = React4.useCallback(
|
|
2052
2052
|
(e) => {
|
|
2053
2053
|
table.events.emit("header:click", {
|
|
2054
2054
|
column,
|
|
@@ -2063,7 +2063,7 @@ function HeaderCell({
|
|
|
2063
2063
|
},
|
|
2064
2064
|
[canSort, column, header, table.events, reorderEndRef]
|
|
2065
2065
|
);
|
|
2066
|
-
const handleHeaderContextMenu =
|
|
2066
|
+
const handleHeaderContextMenu = React4.useCallback(
|
|
2067
2067
|
(e) => {
|
|
2068
2068
|
table.events.emit("header:contextmenu", {
|
|
2069
2069
|
column,
|
|
@@ -2193,13 +2193,39 @@ function CellStatusBadge(props) {
|
|
|
2193
2193
|
}
|
|
2194
2194
|
);
|
|
2195
2195
|
}
|
|
2196
|
+
function FillHandle({
|
|
2197
|
+
rowIndex,
|
|
2198
|
+
columnIndex,
|
|
2199
|
+
onMouseDown
|
|
2200
|
+
}) {
|
|
2201
|
+
const handleMouseDown = React4.useCallback(
|
|
2202
|
+
(e) => {
|
|
2203
|
+
e.preventDefault();
|
|
2204
|
+
e.stopPropagation();
|
|
2205
|
+
onMouseDown(rowIndex, columnIndex, e);
|
|
2206
|
+
},
|
|
2207
|
+
[rowIndex, columnIndex, onMouseDown]
|
|
2208
|
+
);
|
|
2209
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2210
|
+
"div",
|
|
2211
|
+
{
|
|
2212
|
+
className: "yable-fill-handle",
|
|
2213
|
+
onMouseDown: handleMouseDown,
|
|
2214
|
+
role: "presentation",
|
|
2215
|
+
"aria-hidden": "true",
|
|
2216
|
+
title: "Drag to fill",
|
|
2217
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "yable-fill-handle-dot" })
|
|
2218
|
+
}
|
|
2219
|
+
);
|
|
2220
|
+
}
|
|
2196
2221
|
function TableCell({
|
|
2197
2222
|
cell,
|
|
2198
2223
|
table,
|
|
2199
2224
|
rowIndex,
|
|
2200
2225
|
columnIndex,
|
|
2201
2226
|
isFocused,
|
|
2202
|
-
isTabStop
|
|
2227
|
+
isTabStop,
|
|
2228
|
+
onFillHandleMouseDown
|
|
2203
2229
|
}) {
|
|
2204
2230
|
const column = cell.column;
|
|
2205
2231
|
const isEditing = cell.getIsEditing();
|
|
@@ -2248,7 +2274,7 @@ function TableCell({
|
|
|
2248
2274
|
} else {
|
|
2249
2275
|
content = overrideValue !== void 0 ? overrideValue : cell.renderValue();
|
|
2250
2276
|
}
|
|
2251
|
-
const handleClick =
|
|
2277
|
+
const handleClick = React4.useCallback(
|
|
2252
2278
|
(e) => {
|
|
2253
2279
|
table.events.emit("cell:click", {
|
|
2254
2280
|
cell,
|
|
@@ -2262,7 +2288,7 @@ function TableCell({
|
|
|
2262
2288
|
},
|
|
2263
2289
|
[cell, column, isAlwaysEditable, isEditing, isMultiCellSelection, table]
|
|
2264
2290
|
);
|
|
2265
|
-
const handleDoubleClick =
|
|
2291
|
+
const handleDoubleClick = React4.useCallback(
|
|
2266
2292
|
(e) => {
|
|
2267
2293
|
table.events.emit("cell:dblclick", {
|
|
2268
2294
|
cell,
|
|
@@ -2273,7 +2299,7 @@ function TableCell({
|
|
|
2273
2299
|
},
|
|
2274
2300
|
[table, cell]
|
|
2275
2301
|
);
|
|
2276
|
-
const handleContextMenu =
|
|
2302
|
+
const handleContextMenu = React4.useCallback(
|
|
2277
2303
|
(e) => {
|
|
2278
2304
|
table.events.emit("cell:contextmenu", {
|
|
2279
2305
|
cell,
|
|
@@ -2284,11 +2310,11 @@ function TableCell({
|
|
|
2284
2310
|
},
|
|
2285
2311
|
[table, cell]
|
|
2286
2312
|
);
|
|
2287
|
-
const handleFocus =
|
|
2313
|
+
const handleFocus = React4.useCallback(() => {
|
|
2288
2314
|
if (!keyboardNavigationEnabled) return;
|
|
2289
2315
|
table.setFocusedCell({ rowIndex, columnIndex });
|
|
2290
2316
|
}, [columnIndex, keyboardNavigationEnabled, rowIndex, table]);
|
|
2291
|
-
const handleMouseDown =
|
|
2317
|
+
const handleMouseDown = React4.useCallback(
|
|
2292
2318
|
(e) => {
|
|
2293
2319
|
if (e.button !== 0) return;
|
|
2294
2320
|
if (!cellSelectionEnabled) return;
|
|
@@ -2301,12 +2327,12 @@ function TableCell({
|
|
|
2301
2327
|
},
|
|
2302
2328
|
[cellSelectionEnabled, columnIndex, rowIndex, table]
|
|
2303
2329
|
);
|
|
2304
|
-
const handleMouseEnter =
|
|
2330
|
+
const handleMouseEnter = React4.useCallback(() => {
|
|
2305
2331
|
if (!cellSelectionEnabled) return;
|
|
2306
2332
|
if (!table.getState().cellSelection?.isDragging) return;
|
|
2307
2333
|
table.updateCellRangeSelection({ rowIndex, columnIndex });
|
|
2308
2334
|
}, [cellSelectionEnabled, columnIndex, rowIndex, table]);
|
|
2309
|
-
const handleMouseUp =
|
|
2335
|
+
const handleMouseUp = React4.useCallback(() => {
|
|
2310
2336
|
if (!table.getState().cellSelection?.isDragging) return;
|
|
2311
2337
|
table.endCellRangeSelection();
|
|
2312
2338
|
}, [table]);
|
|
@@ -2315,6 +2341,7 @@ function TableCell({
|
|
|
2315
2341
|
const cellStyleDef = column.columnDef.cellStyle;
|
|
2316
2342
|
const userStyle = typeof cellStyleDef === "function" ? cellStyleDef(cell.getContext()) : cellStyleDef;
|
|
2317
2343
|
const mergedStyle = userStyle ? { ...style, ...userStyle } : style;
|
|
2344
|
+
const showFillHandle = isFocused && Boolean(table.options.enableFillHandle) && onFillHandleMouseDown != null;
|
|
2318
2345
|
const classNames = [
|
|
2319
2346
|
"yable-td",
|
|
2320
2347
|
isFocused && "yable-cell--focused",
|
|
@@ -2368,6 +2395,14 @@ function TableCell({
|
|
|
2368
2395
|
onRetry: () => void table.retryCommit(cell.row.id, column.id),
|
|
2369
2396
|
onDismiss: () => table.dismissCommit(cell.row.id, column.id)
|
|
2370
2397
|
}
|
|
2398
|
+
),
|
|
2399
|
+
showFillHandle && onFillHandleMouseDown && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2400
|
+
FillHandle,
|
|
2401
|
+
{
|
|
2402
|
+
rowIndex,
|
|
2403
|
+
columnIndex,
|
|
2404
|
+
onMouseDown: onFillHandleMouseDown
|
|
2405
|
+
}
|
|
2371
2406
|
)
|
|
2372
2407
|
]
|
|
2373
2408
|
}
|
|
@@ -2380,7 +2415,7 @@ function isInteractiveClickTarget(element) {
|
|
|
2380
2415
|
);
|
|
2381
2416
|
return interactive !== null;
|
|
2382
2417
|
}
|
|
2383
|
-
var ErrorBoundary = class extends
|
|
2418
|
+
var ErrorBoundary = class extends React4__default.default.Component {
|
|
2384
2419
|
constructor(props) {
|
|
2385
2420
|
super(props);
|
|
2386
2421
|
this.state = { hasError: false, error: null };
|
|
@@ -2426,7 +2461,7 @@ var ErrorBoundary = class extends React3__default.default.Component {
|
|
|
2426
2461
|
return this.props.children;
|
|
2427
2462
|
}
|
|
2428
2463
|
};
|
|
2429
|
-
var CellErrorBoundary = class extends
|
|
2464
|
+
var CellErrorBoundary = class extends React4__default.default.Component {
|
|
2430
2465
|
constructor(props) {
|
|
2431
2466
|
super(props);
|
|
2432
2467
|
this.state = { hasError: false, error: null };
|
|
@@ -2499,7 +2534,8 @@ function MasterDetail({
|
|
|
2499
2534
|
function TableBody({
|
|
2500
2535
|
table,
|
|
2501
2536
|
clickableRows,
|
|
2502
|
-
colgroup
|
|
2537
|
+
colgroup,
|
|
2538
|
+
onFillHandleMouseDown
|
|
2503
2539
|
}) {
|
|
2504
2540
|
const rows = table.getRowModel().rows;
|
|
2505
2541
|
const visibleColumns = table.getVisibleLeafColumns();
|
|
@@ -2512,14 +2548,14 @@ function TableBody({
|
|
|
2512
2548
|
const pendingValues = table.getState().editing.pendingValues ?? {};
|
|
2513
2549
|
const options = table.options;
|
|
2514
2550
|
const enableVirtualization = options.enableVirtualization ?? false;
|
|
2515
|
-
const scrollContainerRef =
|
|
2551
|
+
const scrollContainerRef = React4.useRef(null);
|
|
2516
2552
|
const rowHeight = options.rowHeight ?? 40;
|
|
2517
2553
|
const overscan = options.overscan ?? 5;
|
|
2518
2554
|
const estimateRowHeight = options.estimateRowHeight;
|
|
2519
2555
|
const pretextHeights = options.pretextHeights ?? null;
|
|
2520
2556
|
const pretextPrefixSums = options.pretextPrefixSums ?? null;
|
|
2521
2557
|
const columnSizing = table.getState().columnSizing;
|
|
2522
|
-
const columnSizingHash =
|
|
2558
|
+
const columnSizingHash = React4.useMemo(() => {
|
|
2523
2559
|
const entries = Object.entries(columnSizing);
|
|
2524
2560
|
if (entries.length === 0) return 0;
|
|
2525
2561
|
let h = 0;
|
|
@@ -2542,7 +2578,7 @@ function TableBody({
|
|
|
2542
2578
|
columnSizingHash
|
|
2543
2579
|
});
|
|
2544
2580
|
const cellSelectionKey = cellSelection.range ? `${cellSelection.range.start.rowIndex}:${cellSelection.range.start.columnIndex}:${cellSelection.range.end.rowIndex}:${cellSelection.range.end.columnIndex}:${cellSelection.isDragging ? "dragging" : "idle"}` : `none:${cellSelection.isDragging ? "dragging" : "idle"}`;
|
|
2545
|
-
|
|
2581
|
+
React4.useEffect(() => {
|
|
2546
2582
|
const handleWindowMouseUp = () => {
|
|
2547
2583
|
if (table.getState().cellSelection?.isDragging) {
|
|
2548
2584
|
table.endCellRangeSelection();
|
|
@@ -2568,7 +2604,8 @@ function TableBody({
|
|
|
2568
2604
|
cellSelectionKey,
|
|
2569
2605
|
pendingValuesKey: getPendingValuesKey(pendingValues[row.id]),
|
|
2570
2606
|
clickable: clickableRows,
|
|
2571
|
-
pinnedPosition
|
|
2607
|
+
pinnedPosition,
|
|
2608
|
+
onFillHandleMouseDown
|
|
2572
2609
|
},
|
|
2573
2610
|
row.id
|
|
2574
2611
|
);
|
|
@@ -2637,6 +2674,7 @@ function TableBody({
|
|
|
2637
2674
|
cellSelectionKey,
|
|
2638
2675
|
pendingValuesKey: getPendingValuesKey(pendingValues[row.id]),
|
|
2639
2676
|
clickable: clickableRows,
|
|
2677
|
+
onFillHandleMouseDown,
|
|
2640
2678
|
virtualStyle: {
|
|
2641
2679
|
position: "absolute",
|
|
2642
2680
|
top: 0,
|
|
@@ -2671,11 +2709,12 @@ function TableRowInner({
|
|
|
2671
2709
|
pendingValuesKey: _pendingValuesKey,
|
|
2672
2710
|
clickable,
|
|
2673
2711
|
pinnedPosition,
|
|
2674
|
-
virtualStyle
|
|
2712
|
+
virtualStyle,
|
|
2713
|
+
onFillHandleMouseDown
|
|
2675
2714
|
}) {
|
|
2676
2715
|
const allCells = row.getAllCells();
|
|
2677
2716
|
const visibleCells = visibleColumns.map((column) => allCells.find((cell) => cell.column.id === column.id)).filter((cell) => cell != null);
|
|
2678
|
-
const handleClick =
|
|
2717
|
+
const handleClick = React4.useCallback(
|
|
2679
2718
|
(e) => {
|
|
2680
2719
|
if (table.options.enableRowClickSelection && row.getCanSelect() && !isInteractiveClickTarget2(e.target)) {
|
|
2681
2720
|
row.toggleSelected();
|
|
@@ -2689,7 +2728,7 @@ function TableRowInner({
|
|
|
2689
2728
|
},
|
|
2690
2729
|
[clickable, table, row]
|
|
2691
2730
|
);
|
|
2692
|
-
const handleDoubleClick =
|
|
2731
|
+
const handleDoubleClick = React4.useCallback(
|
|
2693
2732
|
(e) => {
|
|
2694
2733
|
table.events.emit("row:dblclick", {
|
|
2695
2734
|
row,
|
|
@@ -2698,7 +2737,7 @@ function TableRowInner({
|
|
|
2698
2737
|
},
|
|
2699
2738
|
[table.events, row]
|
|
2700
2739
|
);
|
|
2701
|
-
const handleContextMenu =
|
|
2740
|
+
const handleContextMenu = React4.useCallback(
|
|
2702
2741
|
(e) => {
|
|
2703
2742
|
table.events.emit("row:contextmenu", {
|
|
2704
2743
|
row,
|
|
@@ -2751,7 +2790,8 @@ function TableRowInner({
|
|
|
2751
2790
|
rowIndex,
|
|
2752
2791
|
columnIndex,
|
|
2753
2792
|
isFocused,
|
|
2754
|
-
isTabStop
|
|
2793
|
+
isTabStop,
|
|
2794
|
+
onFillHandleMouseDown
|
|
2755
2795
|
}
|
|
2756
2796
|
)
|
|
2757
2797
|
},
|
|
@@ -2785,7 +2825,7 @@ function areRowPropsEqual(prev, next) {
|
|
|
2785
2825
|
if (prev.table !== next.table) return false;
|
|
2786
2826
|
return true;
|
|
2787
2827
|
}
|
|
2788
|
-
var MemoizedTableRow =
|
|
2828
|
+
var MemoizedTableRow = React4__default.default.memo(TableRowInner, areRowPropsEqual);
|
|
2789
2829
|
function getPendingValuesKey(values) {
|
|
2790
2830
|
if (!values) return "";
|
|
2791
2831
|
return Object.keys(values).sort().map((key) => `${key}:${String(values[key])}`).join("|");
|
|
@@ -3003,8 +3043,8 @@ function StatusDivider() {
|
|
|
3003
3043
|
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "yable-status-bar-divider", "aria-hidden": "true" });
|
|
3004
3044
|
}
|
|
3005
3045
|
function PanelGroup({ children }) {
|
|
3006
|
-
const items =
|
|
3007
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: items.map((child, i) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3046
|
+
const items = React4__default.default.Children.toArray(children).filter(Boolean);
|
|
3047
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: items.map((child, i) => /* @__PURE__ */ jsxRuntime.jsxs(React4__default.default.Fragment, { children: [
|
|
3008
3048
|
i > 0 && /* @__PURE__ */ jsxRuntime.jsx(StatusDivider, {}),
|
|
3009
3049
|
child
|
|
3010
3050
|
] }, i)) });
|
|
@@ -3141,8 +3181,8 @@ function VisibilityIcon({ visible }) {
|
|
|
3141
3181
|
] });
|
|
3142
3182
|
}
|
|
3143
3183
|
function ColumnsPanel({ table }) {
|
|
3144
|
-
const [search, setSearch] =
|
|
3145
|
-
const [draggedId, setDraggedId] =
|
|
3184
|
+
const [search, setSearch] = React4.useState("");
|
|
3185
|
+
const [draggedId, setDraggedId] = React4.useState(null);
|
|
3146
3186
|
const allColumns = table.getAllLeafColumns();
|
|
3147
3187
|
const columnOrder = table.getState().columnOrder;
|
|
3148
3188
|
const columns = columnOrder && columnOrder.length > 0 ? [...allColumns].sort((a, b) => {
|
|
@@ -3155,25 +3195,25 @@ function ColumnsPanel({ table }) {
|
|
|
3155
3195
|
const header = typeof col.columnDef.header === "string" ? col.columnDef.header : col.id;
|
|
3156
3196
|
return header.toLowerCase().includes(search.toLowerCase());
|
|
3157
3197
|
}) : columns;
|
|
3158
|
-
const handleToggleAll =
|
|
3198
|
+
const handleToggleAll = React4.useCallback(
|
|
3159
3199
|
(visible) => {
|
|
3160
3200
|
table.toggleAllColumnsVisible(visible);
|
|
3161
3201
|
},
|
|
3162
3202
|
[table]
|
|
3163
3203
|
);
|
|
3164
|
-
const handleDragStart =
|
|
3204
|
+
const handleDragStart = React4.useCallback((e, columnId) => {
|
|
3165
3205
|
setDraggedId(columnId);
|
|
3166
3206
|
e.dataTransfer.effectAllowed = "move";
|
|
3167
3207
|
e.dataTransfer.setData("text/plain", columnId);
|
|
3168
3208
|
}, []);
|
|
3169
|
-
const handleDragOver =
|
|
3209
|
+
const handleDragOver = React4.useCallback((e) => {
|
|
3170
3210
|
e.preventDefault();
|
|
3171
3211
|
e.dataTransfer.dropEffect = "move";
|
|
3172
3212
|
}, []);
|
|
3173
|
-
const handleDragEnd =
|
|
3213
|
+
const handleDragEnd = React4.useCallback(() => {
|
|
3174
3214
|
setDraggedId(null);
|
|
3175
3215
|
}, []);
|
|
3176
|
-
const handleDrop =
|
|
3216
|
+
const handleDrop = React4.useCallback(
|
|
3177
3217
|
(e, targetId) => {
|
|
3178
3218
|
e.preventDefault();
|
|
3179
3219
|
if (!draggedId || draggedId === targetId) return;
|
|
@@ -3298,7 +3338,7 @@ function FiltersPanel({
|
|
|
3298
3338
|
const globalFilter = table.getState().globalFilter;
|
|
3299
3339
|
const hasFilters = columnFilters.length > 0 || Boolean(globalFilter);
|
|
3300
3340
|
const filterCount = columnFilters.length + (globalFilter ? 1 : 0);
|
|
3301
|
-
const handleRemoveColumnFilter =
|
|
3341
|
+
const handleRemoveColumnFilter = React4.useCallback(
|
|
3302
3342
|
(columnId) => {
|
|
3303
3343
|
table.setColumnFilters(
|
|
3304
3344
|
(prev) => prev.filter((f) => f.id !== columnId)
|
|
@@ -3306,7 +3346,7 @@ function FiltersPanel({
|
|
|
3306
3346
|
},
|
|
3307
3347
|
[table]
|
|
3308
3348
|
);
|
|
3309
|
-
const handleClearAll =
|
|
3349
|
+
const handleClearAll = React4.useCallback(() => {
|
|
3310
3350
|
table.resetColumnFilters(true);
|
|
3311
3351
|
table.resetGlobalFilter(true);
|
|
3312
3352
|
}, [table]);
|
|
@@ -3400,8 +3440,8 @@ function Sidebar({
|
|
|
3400
3440
|
activePanel,
|
|
3401
3441
|
onPanelChange
|
|
3402
3442
|
}) {
|
|
3403
|
-
const sidebarRef =
|
|
3404
|
-
const handleKeyDown =
|
|
3443
|
+
const sidebarRef = React4.useRef(null);
|
|
3444
|
+
const handleKeyDown = React4.useCallback(
|
|
3405
3445
|
(e) => {
|
|
3406
3446
|
if (e.key === "Escape" && open) {
|
|
3407
3447
|
onClose();
|
|
@@ -3409,7 +3449,7 @@ function Sidebar({
|
|
|
3409
3449
|
},
|
|
3410
3450
|
[open, onClose]
|
|
3411
3451
|
);
|
|
3412
|
-
|
|
3452
|
+
React4.useEffect(() => {
|
|
3413
3453
|
document.addEventListener("keydown", handleKeyDown);
|
|
3414
3454
|
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
3415
3455
|
}, [handleKeyDown]);
|
|
@@ -3491,11 +3531,11 @@ function Sidebar({
|
|
|
3491
3531
|
);
|
|
3492
3532
|
}
|
|
3493
3533
|
function ContextMenuItem({ item, onClose }) {
|
|
3494
|
-
const [submenuOpen, setSubmenuOpen] =
|
|
3495
|
-
const itemRef =
|
|
3496
|
-
const submenuRef =
|
|
3497
|
-
const timerRef =
|
|
3498
|
-
|
|
3534
|
+
const [submenuOpen, setSubmenuOpen] = React4.useState(false);
|
|
3535
|
+
const itemRef = React4.useRef(null);
|
|
3536
|
+
const submenuRef = React4.useRef(null);
|
|
3537
|
+
const timerRef = React4.useRef(void 0);
|
|
3538
|
+
React4.useEffect(() => {
|
|
3499
3539
|
return () => clearTimeout(timerRef.current);
|
|
3500
3540
|
}, []);
|
|
3501
3541
|
if (item.separator) {
|
|
@@ -3579,8 +3619,8 @@ function ContextMenu({
|
|
|
3579
3619
|
targetColumnId,
|
|
3580
3620
|
customItems
|
|
3581
3621
|
}) {
|
|
3582
|
-
const menuRef =
|
|
3583
|
-
|
|
3622
|
+
const menuRef = React4.useRef(null);
|
|
3623
|
+
React4.useEffect(() => {
|
|
3584
3624
|
if (!menuRef.current) return;
|
|
3585
3625
|
const rect = menuRef.current.getBoundingClientRect();
|
|
3586
3626
|
const vw = window.innerWidth;
|
|
@@ -3592,11 +3632,11 @@ function ContextMenu({
|
|
|
3592
3632
|
menuRef.current.style.top = `${y - rect.height}px`;
|
|
3593
3633
|
}
|
|
3594
3634
|
}, [x, y]);
|
|
3595
|
-
|
|
3635
|
+
React4.useEffect(() => {
|
|
3596
3636
|
const firstItem = menuRef.current?.querySelector('[role="menuitem"]');
|
|
3597
3637
|
firstItem?.focus();
|
|
3598
3638
|
}, []);
|
|
3599
|
-
const handleKeyDown =
|
|
3639
|
+
const handleKeyDown = React4.useCallback(
|
|
3600
3640
|
(e) => {
|
|
3601
3641
|
if (e.key === "Escape") {
|
|
3602
3642
|
onClose();
|
|
@@ -3774,12 +3814,12 @@ function ContextMenu({
|
|
|
3774
3814
|
] });
|
|
3775
3815
|
}
|
|
3776
3816
|
function useContextMenu() {
|
|
3777
|
-
const [isOpen, setIsOpen] =
|
|
3778
|
-
const [x, setX] =
|
|
3779
|
-
const [y, setY] =
|
|
3780
|
-
const [targetTable, setTargetTable] =
|
|
3781
|
-
const [targetColumnId, setTargetColumnId] =
|
|
3782
|
-
const open =
|
|
3817
|
+
const [isOpen, setIsOpen] = React4.useState(false);
|
|
3818
|
+
const [x, setX] = React4.useState(0);
|
|
3819
|
+
const [y, setY] = React4.useState(0);
|
|
3820
|
+
const [targetTable, setTargetTable] = React4.useState(null);
|
|
3821
|
+
const [targetColumnId, setTargetColumnId] = React4.useState(void 0);
|
|
3822
|
+
const open = React4.useCallback(
|
|
3783
3823
|
(clientX, clientY, table, columnId) => {
|
|
3784
3824
|
setX(clientX);
|
|
3785
3825
|
setY(clientY);
|
|
@@ -3789,12 +3829,12 @@ function useContextMenu() {
|
|
|
3789
3829
|
},
|
|
3790
3830
|
[]
|
|
3791
3831
|
);
|
|
3792
|
-
const close =
|
|
3832
|
+
const close = React4.useCallback(() => {
|
|
3793
3833
|
setIsOpen(false);
|
|
3794
3834
|
setTargetTable(null);
|
|
3795
3835
|
setTargetColumnId(void 0);
|
|
3796
3836
|
}, []);
|
|
3797
|
-
|
|
3837
|
+
React4.useEffect(() => {
|
|
3798
3838
|
if (!isOpen) return;
|
|
3799
3839
|
const handleKeyDown = (e) => {
|
|
3800
3840
|
if (e.key === "Escape") close();
|
|
@@ -3818,7 +3858,7 @@ function useKeyboardNavigation(table, options = {}) {
|
|
|
3818
3858
|
const activeCell = table.getState().editing.activeCell;
|
|
3819
3859
|
const focusedRowIndex = focusedCell?.rowIndex ?? null;
|
|
3820
3860
|
const focusedColumnIndex = focusedCell?.columnIndex ?? null;
|
|
3821
|
-
const focusCellElement =
|
|
3861
|
+
const focusCellElement = React4.useCallback(
|
|
3822
3862
|
(container, cell) => {
|
|
3823
3863
|
const element = getCellElement(container, cell);
|
|
3824
3864
|
if (!element) return false;
|
|
@@ -3833,7 +3873,7 @@ function useKeyboardNavigation(table, options = {}) {
|
|
|
3833
3873
|
},
|
|
3834
3874
|
[]
|
|
3835
3875
|
);
|
|
3836
|
-
const handleKeyDown =
|
|
3876
|
+
const handleKeyDown = React4.useCallback(
|
|
3837
3877
|
(event) => {
|
|
3838
3878
|
if (!enabled || table.options.enableKeyboardNavigation === false) return;
|
|
3839
3879
|
const target = event.target;
|
|
@@ -3907,7 +3947,7 @@ function useKeyboardNavigation(table, options = {}) {
|
|
|
3907
3947
|
},
|
|
3908
3948
|
[activeCell, containerRef, enabled, table]
|
|
3909
3949
|
);
|
|
3910
|
-
|
|
3950
|
+
React4.useEffect(() => {
|
|
3911
3951
|
if (!enabled || table.options.enableKeyboardNavigation === false) return;
|
|
3912
3952
|
const container = containerRef?.current;
|
|
3913
3953
|
if (!container) return;
|
|
@@ -3916,7 +3956,7 @@ function useKeyboardNavigation(table, options = {}) {
|
|
|
3916
3956
|
container.removeEventListener("keydown", handleKeyDown);
|
|
3917
3957
|
};
|
|
3918
3958
|
}, [containerRef, enabled, handleKeyDown, table.options.enableKeyboardNavigation]);
|
|
3919
|
-
|
|
3959
|
+
React4.useEffect(() => {
|
|
3920
3960
|
if (!enabled || table.options.enableKeyboardNavigation === false) return;
|
|
3921
3961
|
if (focusedRowIndex === null || focusedColumnIndex === null) return;
|
|
3922
3962
|
if (activeCell) return;
|
|
@@ -4007,6 +4047,85 @@ function isEditableTarget(element) {
|
|
|
4007
4047
|
}
|
|
4008
4048
|
return element.isContentEditable;
|
|
4009
4049
|
}
|
|
4050
|
+
function useFillHandle(table, options = {}) {
|
|
4051
|
+
const { enabled = true } = options;
|
|
4052
|
+
const [dragState, setDragState] = React4.useState({
|
|
4053
|
+
isDragging: false,
|
|
4054
|
+
sourceCell: null,
|
|
4055
|
+
currentCell: null
|
|
4056
|
+
});
|
|
4057
|
+
const dragRef = React4.useRef(dragState);
|
|
4058
|
+
dragRef.current = dragState;
|
|
4059
|
+
const onFillHandleMouseDown = React4.useCallback(
|
|
4060
|
+
(rowIndex, columnIndex, e) => {
|
|
4061
|
+
if (!enabled) return;
|
|
4062
|
+
e.preventDefault();
|
|
4063
|
+
e.stopPropagation();
|
|
4064
|
+
setDragState({
|
|
4065
|
+
isDragging: true,
|
|
4066
|
+
sourceCell: { rowIndex, columnIndex },
|
|
4067
|
+
currentCell: { rowIndex, columnIndex }
|
|
4068
|
+
});
|
|
4069
|
+
},
|
|
4070
|
+
[enabled]
|
|
4071
|
+
);
|
|
4072
|
+
React4.useEffect(() => {
|
|
4073
|
+
if (!dragState.isDragging) return;
|
|
4074
|
+
const handleMouseMove = (e) => {
|
|
4075
|
+
const target = document.elementFromPoint(e.clientX, e.clientY);
|
|
4076
|
+
if (!target) return;
|
|
4077
|
+
const td = target.closest("td[data-column-id]");
|
|
4078
|
+
const tr = target.closest("tr[data-row-id]");
|
|
4079
|
+
if (!td || !tr) return;
|
|
4080
|
+
const columnId = td.getAttribute("data-column-id");
|
|
4081
|
+
const rowId = tr.getAttribute("data-row-id");
|
|
4082
|
+
if (!columnId || !rowId) return;
|
|
4083
|
+
const rows = table.getRowModel().rows;
|
|
4084
|
+
const columns = table.getVisibleLeafColumns();
|
|
4085
|
+
const rowIndex = rows.findIndex((r) => r.id === rowId);
|
|
4086
|
+
const columnIndex = columns.findIndex((c) => c.id === columnId);
|
|
4087
|
+
if (rowIndex === -1 || columnIndex === -1) return;
|
|
4088
|
+
setDragState((prev) => ({
|
|
4089
|
+
...prev,
|
|
4090
|
+
currentCell: { rowIndex, columnIndex }
|
|
4091
|
+
}));
|
|
4092
|
+
};
|
|
4093
|
+
const handleMouseUp = () => {
|
|
4094
|
+
const current = dragRef.current;
|
|
4095
|
+
if (current.sourceCell && current.currentCell) {
|
|
4096
|
+
const source = current.sourceCell;
|
|
4097
|
+
const target = current.currentCell;
|
|
4098
|
+
if (source.rowIndex !== target.rowIndex || source.columnIndex !== target.columnIndex) {
|
|
4099
|
+
const sourceRange = {
|
|
4100
|
+
startRow: source.rowIndex,
|
|
4101
|
+
startCol: source.columnIndex,
|
|
4102
|
+
endRow: source.rowIndex,
|
|
4103
|
+
endCol: source.columnIndex
|
|
4104
|
+
};
|
|
4105
|
+
const targetRange = {
|
|
4106
|
+
startRow: Math.min(source.rowIndex, target.rowIndex),
|
|
4107
|
+
startCol: Math.min(source.columnIndex, target.columnIndex),
|
|
4108
|
+
endRow: Math.max(source.rowIndex, target.rowIndex),
|
|
4109
|
+
endCol: Math.max(source.columnIndex, target.columnIndex)
|
|
4110
|
+
};
|
|
4111
|
+
table.fillRange(sourceRange, targetRange);
|
|
4112
|
+
}
|
|
4113
|
+
}
|
|
4114
|
+
setDragState({
|
|
4115
|
+
isDragging: false,
|
|
4116
|
+
sourceCell: null,
|
|
4117
|
+
currentCell: null
|
|
4118
|
+
});
|
|
4119
|
+
};
|
|
4120
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
4121
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
4122
|
+
return () => {
|
|
4123
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
|
4124
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
4125
|
+
};
|
|
4126
|
+
}, [dragState.isDragging, table]);
|
|
4127
|
+
return { dragState, onFillHandleMouseDown };
|
|
4128
|
+
}
|
|
4010
4129
|
function filterHeaderGroups(groups, visibleColumnIds) {
|
|
4011
4130
|
return groups.map((group) => ({
|
|
4012
4131
|
...group,
|
|
@@ -4069,12 +4188,12 @@ function Table({
|
|
|
4069
4188
|
const resolvedFloatingFilters = floatingFilters ?? profileTableProps?.floatingFilters;
|
|
4070
4189
|
const resolvedColumnVirtualization = columnVirtualization ?? profileTableProps?.columnVirtualization;
|
|
4071
4190
|
const resolvedColumnVirtualizationOverscan = columnVirtualizationOverscan ?? profileTableProps?.columnVirtualizationOverscan;
|
|
4072
|
-
const [sidebarOpen, setSidebarOpen] =
|
|
4073
|
-
const [sidebarPanel, setSidebarPanel] =
|
|
4191
|
+
const [sidebarOpen, setSidebarOpen] = React4.useState(false);
|
|
4192
|
+
const [sidebarPanel, setSidebarPanel] = React4.useState(
|
|
4074
4193
|
resolvedDefaultSidebarPanel ?? "columns"
|
|
4075
4194
|
);
|
|
4076
|
-
const containerRef =
|
|
4077
|
-
const horizontalScrollRef =
|
|
4195
|
+
const containerRef = React4.useRef(null);
|
|
4196
|
+
const horizontalScrollRef = React4.useRef(null);
|
|
4078
4197
|
const isRtl = direction === "rtl";
|
|
4079
4198
|
const classNames = [
|
|
4080
4199
|
"yable",
|
|
@@ -4104,7 +4223,7 @@ function Table({
|
|
|
4104
4223
|
enabled: canVirtualizeColumns,
|
|
4105
4224
|
sizingKey: allVisibleColumnSizeSignature
|
|
4106
4225
|
});
|
|
4107
|
-
const renderTable =
|
|
4226
|
+
const renderTable = React4.useMemo(() => {
|
|
4108
4227
|
if (!canVirtualizeColumns || !columnVirtualState.isVirtualized) {
|
|
4109
4228
|
return table;
|
|
4110
4229
|
}
|
|
@@ -4130,13 +4249,16 @@ function Table({
|
|
|
4130
4249
|
const showColumnVirtualizationShell = canVirtualizeColumns;
|
|
4131
4250
|
const contextMenu = useContextMenu();
|
|
4132
4251
|
useKeyboardNavigation(table, { containerRef });
|
|
4133
|
-
const
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
const
|
|
4137
|
-
const
|
|
4138
|
-
const
|
|
4139
|
-
|
|
4252
|
+
const { onFillHandleMouseDown } = useFillHandle(table, {
|
|
4253
|
+
enabled: Boolean(table.options.enableFillHandle)
|
|
4254
|
+
});
|
|
4255
|
+
const [announcement, setAnnouncement] = React4.useState("");
|
|
4256
|
+
const prevSortingRef = React4.useRef(table.getState().sorting);
|
|
4257
|
+
const prevFilterCountRef = React4.useRef(rows.length);
|
|
4258
|
+
const prevHasFiltersRef = React4.useRef(isFiltered);
|
|
4259
|
+
const prevPaginationRef = React4.useRef(table.getState().pagination);
|
|
4260
|
+
const isFirstRenderRef = React4.useRef(true);
|
|
4261
|
+
React4.useEffect(() => {
|
|
4140
4262
|
if (isFirstRenderRef.current) {
|
|
4141
4263
|
isFirstRenderRef.current = false;
|
|
4142
4264
|
return;
|
|
@@ -4174,7 +4296,7 @@ function Table({
|
|
|
4174
4296
|
}
|
|
4175
4297
|
}
|
|
4176
4298
|
});
|
|
4177
|
-
const handleContextMenu =
|
|
4299
|
+
const handleContextMenu = React4.useCallback(
|
|
4178
4300
|
(e) => {
|
|
4179
4301
|
e.preventDefault();
|
|
4180
4302
|
const targetEl = e.target?.closest?.("[data-column-id]");
|
|
@@ -4189,7 +4311,7 @@ function Table({
|
|
|
4189
4311
|
0
|
|
4190
4312
|
);
|
|
4191
4313
|
const colgroup = visibleLeafColumns.length === 0 ? null : /* @__PURE__ */ jsxRuntime.jsx("colgroup", { children: visibleLeafColumns.map((col) => /* @__PURE__ */ jsxRuntime.jsx("col", { style: { width: col.getSize() } }, col.id)) });
|
|
4192
|
-
const outerTableStyle =
|
|
4314
|
+
const outerTableStyle = React4.useMemo(() => {
|
|
4193
4315
|
if (columnVirtualState.isVirtualized) {
|
|
4194
4316
|
return {
|
|
4195
4317
|
width: columnVirtualState.visibleWidth,
|
|
@@ -4217,7 +4339,15 @@ function Table({
|
|
|
4217
4339
|
children: [
|
|
4218
4340
|
colgroup,
|
|
4219
4341
|
/* @__PURE__ */ jsxRuntime.jsx(TableHeader, { table: renderTable, floatingFilters: resolvedFloatingFilters }),
|
|
4220
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4342
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4343
|
+
TableBody,
|
|
4344
|
+
{
|
|
4345
|
+
table: renderTable,
|
|
4346
|
+
clickableRows: resolvedClickableRows,
|
|
4347
|
+
colgroup,
|
|
4348
|
+
onFillHandleMouseDown
|
|
4349
|
+
}
|
|
4350
|
+
),
|
|
4221
4351
|
footer && /* @__PURE__ */ jsxRuntime.jsx(TableFooter, { table: renderTable })
|
|
4222
4352
|
]
|
|
4223
4353
|
}
|
|
@@ -4539,12 +4669,12 @@ function GlobalFilter({
|
|
|
4539
4669
|
}) {
|
|
4540
4670
|
const locale = yableCore.getDefaultLocale();
|
|
4541
4671
|
const resolvedPlaceholder = placeholder ?? locale.searchPlaceholder;
|
|
4542
|
-
const [value, setValue] =
|
|
4672
|
+
const [value, setValue] = React4.useState(
|
|
4543
4673
|
table.getState().globalFilter ?? ""
|
|
4544
4674
|
);
|
|
4545
|
-
const timerRef =
|
|
4546
|
-
const inputRef =
|
|
4547
|
-
const handleChange =
|
|
4675
|
+
const timerRef = React4.useRef(void 0);
|
|
4676
|
+
const inputRef = React4.useRef(null);
|
|
4677
|
+
const handleChange = React4.useCallback(
|
|
4548
4678
|
(e) => {
|
|
4549
4679
|
const newValue = e.target.value;
|
|
4550
4680
|
setValue(newValue);
|
|
@@ -4559,13 +4689,13 @@ function GlobalFilter({
|
|
|
4559
4689
|
},
|
|
4560
4690
|
[table, debounce]
|
|
4561
4691
|
);
|
|
4562
|
-
const handleClear =
|
|
4692
|
+
const handleClear = React4.useCallback(() => {
|
|
4563
4693
|
setValue("");
|
|
4564
4694
|
table.setGlobalFilter("");
|
|
4565
4695
|
clearTimeout(timerRef.current);
|
|
4566
4696
|
inputRef.current?.focus();
|
|
4567
4697
|
}, [table]);
|
|
4568
|
-
const handleKeyDown =
|
|
4698
|
+
const handleKeyDown = React4.useCallback(
|
|
4569
4699
|
(e) => {
|
|
4570
4700
|
if (e.key === "Escape" && value) {
|
|
4571
4701
|
e.preventDefault();
|
|
@@ -4574,10 +4704,10 @@ function GlobalFilter({
|
|
|
4574
4704
|
},
|
|
4575
4705
|
[value, handleClear]
|
|
4576
4706
|
);
|
|
4577
|
-
|
|
4707
|
+
React4.useEffect(() => {
|
|
4578
4708
|
return () => clearTimeout(timerRef.current);
|
|
4579
4709
|
}, []);
|
|
4580
|
-
|
|
4710
|
+
React4.useEffect(() => {
|
|
4581
4711
|
const externalValue = table.getState().globalFilter ?? "";
|
|
4582
4712
|
if (externalValue !== value) {
|
|
4583
4713
|
setValue(externalValue);
|
|
@@ -4622,7 +4752,7 @@ function CellInput({
|
|
|
4622
4752
|
className
|
|
4623
4753
|
}) {
|
|
4624
4754
|
const { table, row, column, cell } = context;
|
|
4625
|
-
const inputRef =
|
|
4755
|
+
const inputRef = React4.useRef(null);
|
|
4626
4756
|
const isEditing = cell.getIsEditing();
|
|
4627
4757
|
const isAlwaysEditable = cell.getIsAlwaysEditable();
|
|
4628
4758
|
const pending = table.getPendingValue(row.id, column.id);
|
|
@@ -4647,7 +4777,7 @@ function CellInput({
|
|
|
4647
4777
|
}
|
|
4648
4778
|
}
|
|
4649
4779
|
};
|
|
4650
|
-
|
|
4780
|
+
React4.useEffect(() => {
|
|
4651
4781
|
if ((isEditing || autoFocus) && inputRef.current) {
|
|
4652
4782
|
inputRef.current.focus();
|
|
4653
4783
|
inputRef.current.select();
|
|
@@ -4683,8 +4813,8 @@ function CellSelect({
|
|
|
4683
4813
|
const isAlwaysEditable = cell.getIsAlwaysEditable();
|
|
4684
4814
|
const pending = table.getPendingValue(row.id, column.id);
|
|
4685
4815
|
const currentValue = pending !== void 0 ? pending : cell.getValue();
|
|
4686
|
-
const commitTimerRef =
|
|
4687
|
-
|
|
4816
|
+
const commitTimerRef = React4.useRef(null);
|
|
4817
|
+
React4.useEffect(() => {
|
|
4688
4818
|
return () => {
|
|
4689
4819
|
if (commitTimerRef.current !== null) {
|
|
4690
4820
|
clearTimeout(commitTimerRef.current);
|
|
@@ -4765,7 +4895,7 @@ function CellDatePicker({
|
|
|
4765
4895
|
className
|
|
4766
4896
|
}) {
|
|
4767
4897
|
const { table, row, column, cell } = context;
|
|
4768
|
-
const inputRef =
|
|
4898
|
+
const inputRef = React4.useRef(null);
|
|
4769
4899
|
const isEditing = cell.getIsEditing();
|
|
4770
4900
|
const isAlwaysEditable = cell.getIsAlwaysEditable();
|
|
4771
4901
|
const pending = table.getPendingValue(row.id, column.id);
|
|
@@ -4779,7 +4909,7 @@ function CellDatePicker({
|
|
|
4779
4909
|
table.commitEdit();
|
|
4780
4910
|
}
|
|
4781
4911
|
};
|
|
4782
|
-
|
|
4912
|
+
React4.useEffect(() => {
|
|
4783
4913
|
if (isEditing && inputRef.current) {
|
|
4784
4914
|
inputRef.current.focus();
|
|
4785
4915
|
}
|
|
@@ -4814,7 +4944,7 @@ function formatDateValue(value, type) {
|
|
|
4814
4944
|
}
|
|
4815
4945
|
function useClipboard(table, options = {}) {
|
|
4816
4946
|
const { enabled = true, containerRef, onCopy, onCut, onPaste, ...clipboardOptions } = options;
|
|
4817
|
-
const handleCopy =
|
|
4947
|
+
const handleCopy = React4.useCallback(
|
|
4818
4948
|
(e) => {
|
|
4819
4949
|
if (isEditableTarget2(e.target)) return;
|
|
4820
4950
|
e.preventDefault();
|
|
@@ -4826,7 +4956,7 @@ function useClipboard(table, options = {}) {
|
|
|
4826
4956
|
},
|
|
4827
4957
|
[table, clipboardOptions, onCopy]
|
|
4828
4958
|
);
|
|
4829
|
-
const handleCut =
|
|
4959
|
+
const handleCut = React4.useCallback(
|
|
4830
4960
|
(e) => {
|
|
4831
4961
|
if (isEditableTarget2(e.target)) return;
|
|
4832
4962
|
e.preventDefault();
|
|
@@ -4838,7 +4968,7 @@ function useClipboard(table, options = {}) {
|
|
|
4838
4968
|
},
|
|
4839
4969
|
[table, clipboardOptions, onCut]
|
|
4840
4970
|
);
|
|
4841
|
-
const handlePaste =
|
|
4971
|
+
const handlePaste = React4.useCallback(
|
|
4842
4972
|
(e) => {
|
|
4843
4973
|
if (isEditableTarget2(e.target)) return;
|
|
4844
4974
|
e.preventDefault();
|
|
@@ -4883,7 +5013,7 @@ function useClipboard(table, options = {}) {
|
|
|
4883
5013
|
},
|
|
4884
5014
|
[table, clipboardOptions, onPaste]
|
|
4885
5015
|
);
|
|
4886
|
-
|
|
5016
|
+
React4.useEffect(() => {
|
|
4887
5017
|
if (!enabled) return;
|
|
4888
5018
|
const container = containerRef?.current ?? document;
|
|
4889
5019
|
container.addEventListener("copy", handleCopy);
|
|
@@ -4905,110 +5035,6 @@ function isEditableTarget2(el) {
|
|
|
4905
5035
|
if (el.isContentEditable) return true;
|
|
4906
5036
|
return false;
|
|
4907
5037
|
}
|
|
4908
|
-
function useFillHandle(table, options = {}) {
|
|
4909
|
-
const { enabled = true } = options;
|
|
4910
|
-
const [dragState, setDragState] = React3.useState({
|
|
4911
|
-
isDragging: false,
|
|
4912
|
-
sourceCell: null,
|
|
4913
|
-
currentCell: null
|
|
4914
|
-
});
|
|
4915
|
-
const dragRef = React3.useRef(dragState);
|
|
4916
|
-
dragRef.current = dragState;
|
|
4917
|
-
const onFillHandleMouseDown = React3.useCallback(
|
|
4918
|
-
(rowIndex, columnIndex, e) => {
|
|
4919
|
-
if (!enabled) return;
|
|
4920
|
-
e.preventDefault();
|
|
4921
|
-
e.stopPropagation();
|
|
4922
|
-
setDragState({
|
|
4923
|
-
isDragging: true,
|
|
4924
|
-
sourceCell: { rowIndex, columnIndex },
|
|
4925
|
-
currentCell: { rowIndex, columnIndex }
|
|
4926
|
-
});
|
|
4927
|
-
},
|
|
4928
|
-
[enabled]
|
|
4929
|
-
);
|
|
4930
|
-
React3.useEffect(() => {
|
|
4931
|
-
if (!dragState.isDragging) return;
|
|
4932
|
-
const handleMouseMove = (e) => {
|
|
4933
|
-
const target = document.elementFromPoint(e.clientX, e.clientY);
|
|
4934
|
-
if (!target) return;
|
|
4935
|
-
const td = target.closest("td[data-column-id]");
|
|
4936
|
-
const tr = target.closest("tr[data-row-id]");
|
|
4937
|
-
if (!td || !tr) return;
|
|
4938
|
-
const columnId = td.getAttribute("data-column-id");
|
|
4939
|
-
const rowId = tr.getAttribute("data-row-id");
|
|
4940
|
-
if (!columnId || !rowId) return;
|
|
4941
|
-
const rows = table.getRowModel().rows;
|
|
4942
|
-
const columns = table.getVisibleLeafColumns();
|
|
4943
|
-
const rowIndex = rows.findIndex((r) => r.id === rowId);
|
|
4944
|
-
const columnIndex = columns.findIndex((c) => c.id === columnId);
|
|
4945
|
-
if (rowIndex === -1 || columnIndex === -1) return;
|
|
4946
|
-
setDragState((prev) => ({
|
|
4947
|
-
...prev,
|
|
4948
|
-
currentCell: { rowIndex, columnIndex }
|
|
4949
|
-
}));
|
|
4950
|
-
};
|
|
4951
|
-
const handleMouseUp = () => {
|
|
4952
|
-
const current = dragRef.current;
|
|
4953
|
-
if (current.sourceCell && current.currentCell) {
|
|
4954
|
-
const source = current.sourceCell;
|
|
4955
|
-
const target = current.currentCell;
|
|
4956
|
-
if (source.rowIndex !== target.rowIndex || source.columnIndex !== target.columnIndex) {
|
|
4957
|
-
const sourceRange = {
|
|
4958
|
-
startRow: source.rowIndex,
|
|
4959
|
-
startCol: source.columnIndex,
|
|
4960
|
-
endRow: source.rowIndex,
|
|
4961
|
-
endCol: source.columnIndex
|
|
4962
|
-
};
|
|
4963
|
-
const targetRange = {
|
|
4964
|
-
startRow: Math.min(source.rowIndex, target.rowIndex),
|
|
4965
|
-
startCol: Math.min(source.columnIndex, target.columnIndex),
|
|
4966
|
-
endRow: Math.max(source.rowIndex, target.rowIndex),
|
|
4967
|
-
endCol: Math.max(source.columnIndex, target.columnIndex)
|
|
4968
|
-
};
|
|
4969
|
-
table.fillRange(sourceRange, targetRange);
|
|
4970
|
-
}
|
|
4971
|
-
}
|
|
4972
|
-
setDragState({
|
|
4973
|
-
isDragging: false,
|
|
4974
|
-
sourceCell: null,
|
|
4975
|
-
currentCell: null
|
|
4976
|
-
});
|
|
4977
|
-
};
|
|
4978
|
-
document.addEventListener("mousemove", handleMouseMove);
|
|
4979
|
-
document.addEventListener("mouseup", handleMouseUp);
|
|
4980
|
-
return () => {
|
|
4981
|
-
document.removeEventListener("mousemove", handleMouseMove);
|
|
4982
|
-
document.removeEventListener("mouseup", handleMouseUp);
|
|
4983
|
-
};
|
|
4984
|
-
}, [dragState.isDragging, table]);
|
|
4985
|
-
return { dragState, onFillHandleMouseDown };
|
|
4986
|
-
}
|
|
4987
|
-
function FillHandle({
|
|
4988
|
-
rowIndex,
|
|
4989
|
-
columnIndex,
|
|
4990
|
-
onMouseDown
|
|
4991
|
-
}) {
|
|
4992
|
-
const handleMouseDown = React3.useCallback(
|
|
4993
|
-
(e) => {
|
|
4994
|
-
e.preventDefault();
|
|
4995
|
-
e.stopPropagation();
|
|
4996
|
-
onMouseDown(rowIndex, columnIndex, e);
|
|
4997
|
-
},
|
|
4998
|
-
[rowIndex, columnIndex, onMouseDown]
|
|
4999
|
-
);
|
|
5000
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
5001
|
-
"div",
|
|
5002
|
-
{
|
|
5003
|
-
className: "yable-fill-handle",
|
|
5004
|
-
onMouseDown: handleMouseDown,
|
|
5005
|
-
role: "presentation",
|
|
5006
|
-
"aria-hidden": "true",
|
|
5007
|
-
title: "Drag to fill",
|
|
5008
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "yable-fill-handle-dot" })
|
|
5009
|
-
}
|
|
5010
|
-
);
|
|
5011
|
-
}
|
|
5012
5038
|
function GripIcon() {
|
|
5013
5039
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
5014
5040
|
"svg",
|
|
@@ -5041,7 +5067,7 @@ function DragHandle({
|
|
|
5041
5067
|
isDragging && "yable-row-drag-handle--dragging",
|
|
5042
5068
|
className
|
|
5043
5069
|
].filter(Boolean).join(" ");
|
|
5044
|
-
const handleDragStart =
|
|
5070
|
+
const handleDragStart = React4.useCallback(
|
|
5045
5071
|
(e) => {
|
|
5046
5072
|
if (e.dataTransfer && e.currentTarget instanceof HTMLElement) {
|
|
5047
5073
|
e.dataTransfer.effectAllowed = "move";
|
|
@@ -5070,10 +5096,10 @@ function useRowDrag({
|
|
|
5070
5096
|
onDataChange,
|
|
5071
5097
|
onReorder
|
|
5072
5098
|
}) {
|
|
5073
|
-
const [dragState, setDragState] =
|
|
5074
|
-
const dragRowIdRef =
|
|
5075
|
-
const dragRowIndexRef =
|
|
5076
|
-
const getRowDragProps =
|
|
5099
|
+
const [dragState, setDragState] = React4.useState(rowDragging.getInitialRowDragState);
|
|
5100
|
+
const dragRowIdRef = React4.useRef(null);
|
|
5101
|
+
const dragRowIndexRef = React4.useRef(-1);
|
|
5102
|
+
const getRowDragProps = React4.useCallback(
|
|
5077
5103
|
(rowId, rowIndex) => {
|
|
5078
5104
|
return {
|
|
5079
5105
|
draggable: true,
|
|
@@ -5172,7 +5198,7 @@ function useRowDrag({
|
|
|
5172
5198
|
},
|
|
5173
5199
|
[data, dragState, onDataChange, onReorder, table]
|
|
5174
5200
|
);
|
|
5175
|
-
const getDragHandleProps =
|
|
5201
|
+
const getDragHandleProps = React4.useCallback(
|
|
5176
5202
|
(rowId) => ({
|
|
5177
5203
|
onDragStart: (e) => {
|
|
5178
5204
|
e.dataTransfer.effectAllowed = "move";
|
|
@@ -5199,7 +5225,7 @@ function TreeToggle({
|
|
|
5199
5225
|
const isExpanded = row.getIsExpanded();
|
|
5200
5226
|
const canToggle = showToggle !== void 0 ? showToggle : hasChildren;
|
|
5201
5227
|
const indent = depth * indentWidth;
|
|
5202
|
-
const handleClick =
|
|
5228
|
+
const handleClick = React4.useCallback(
|
|
5203
5229
|
(e) => {
|
|
5204
5230
|
e.stopPropagation();
|
|
5205
5231
|
if (canToggle) {
|
|
@@ -5269,7 +5295,7 @@ function ExpandIcon({
|
|
|
5269
5295
|
className
|
|
5270
5296
|
].filter(Boolean).join(" ");
|
|
5271
5297
|
const label = ariaLabel ?? (isExpanded ? "Collapse details" : "Expand details");
|
|
5272
|
-
const handleClick =
|
|
5298
|
+
const handleClick = React4.useCallback(
|
|
5273
5299
|
(e) => {
|
|
5274
5300
|
e.stopPropagation();
|
|
5275
5301
|
onClick(e);
|
|
@@ -5334,20 +5360,20 @@ function PivotConfigPanel({
|
|
|
5334
5360
|
aggregationOptions = DEFAULT_AGGREGATION_OPTIONS,
|
|
5335
5361
|
className
|
|
5336
5362
|
}) {
|
|
5337
|
-
const [dragSource, setDragSource] =
|
|
5363
|
+
const [dragSource, setDragSource] = React4.useState(null);
|
|
5338
5364
|
const usedFields = /* @__PURE__ */ new Set([
|
|
5339
5365
|
...rowFields.map((f) => f.field),
|
|
5340
5366
|
...columnFields.map((f) => f.field),
|
|
5341
5367
|
...valueFields.map((f) => f.field)
|
|
5342
5368
|
]);
|
|
5343
5369
|
const unplacedFields = availableFields.filter((f) => !usedFields.has(f.field));
|
|
5344
|
-
const handleDragStart =
|
|
5370
|
+
const handleDragStart = React4.useCallback(
|
|
5345
5371
|
(field, zone) => {
|
|
5346
5372
|
setDragSource({ field, zone });
|
|
5347
5373
|
},
|
|
5348
5374
|
[]
|
|
5349
5375
|
);
|
|
5350
|
-
const handleDrop =
|
|
5376
|
+
const handleDrop = React4.useCallback(
|
|
5351
5377
|
(targetZone) => {
|
|
5352
5378
|
if (!dragSource) return;
|
|
5353
5379
|
const { field, zone: sourceZone } = dragSource;
|
|
@@ -5390,7 +5416,7 @@ function PivotConfigPanel({
|
|
|
5390
5416
|
onValueFieldsChange
|
|
5391
5417
|
]
|
|
5392
5418
|
);
|
|
5393
|
-
const handleAggregationChange =
|
|
5419
|
+
const handleAggregationChange = React4.useCallback(
|
|
5394
5420
|
(field, aggregation) => {
|
|
5395
5421
|
onValueFieldsChange(
|
|
5396
5422
|
valueFields.map(
|
|
@@ -5400,7 +5426,7 @@ function PivotConfigPanel({
|
|
|
5400
5426
|
},
|
|
5401
5427
|
[valueFields, onValueFieldsChange]
|
|
5402
5428
|
);
|
|
5403
|
-
const handleRemoveField =
|
|
5429
|
+
const handleRemoveField = React4.useCallback(
|
|
5404
5430
|
(field, zone) => {
|
|
5405
5431
|
if (zone === "rows") {
|
|
5406
5432
|
onRowFieldsChange(rowFields.filter((f) => f.field !== field));
|
|
@@ -5590,8 +5616,8 @@ function Tooltip({
|
|
|
5590
5616
|
content,
|
|
5591
5617
|
customComponent
|
|
5592
5618
|
}) {
|
|
5593
|
-
const tooltipRef =
|
|
5594
|
-
|
|
5619
|
+
const tooltipRef = React4.useRef(null);
|
|
5620
|
+
React4.useEffect(() => {
|
|
5595
5621
|
if (!visible || !tooltipRef.current) return;
|
|
5596
5622
|
const el = tooltipRef.current;
|
|
5597
5623
|
const rect = el.getBoundingClientRect();
|
|
@@ -5656,16 +5682,16 @@ function Tooltip({
|
|
|
5656
5682
|
}
|
|
5657
5683
|
function useTooltip(options = {}) {
|
|
5658
5684
|
const { delay = 500, placement = "top", enabled = true } = options;
|
|
5659
|
-
const [visible, setVisible] =
|
|
5660
|
-
const [position, setPosition] =
|
|
5685
|
+
const [visible, setVisible] = React4.useState(false);
|
|
5686
|
+
const [position, setPosition] = React4.useState({
|
|
5661
5687
|
x: 0,
|
|
5662
5688
|
y: 0,
|
|
5663
5689
|
placement
|
|
5664
5690
|
});
|
|
5665
|
-
const [content, setContent] =
|
|
5666
|
-
const timerRef =
|
|
5667
|
-
const targetRef =
|
|
5668
|
-
const show =
|
|
5691
|
+
const [content, setContent] = React4.useState("");
|
|
5692
|
+
const timerRef = React4.useRef(void 0);
|
|
5693
|
+
const targetRef = React4.useRef(null);
|
|
5694
|
+
const show = React4.useCallback(
|
|
5669
5695
|
(target, tooltipContent) => {
|
|
5670
5696
|
if (!enabled || !tooltipContent) return;
|
|
5671
5697
|
targetRef.current = target;
|
|
@@ -5712,12 +5738,12 @@ function useTooltip(options = {}) {
|
|
|
5712
5738
|
},
|
|
5713
5739
|
[delay, placement, enabled]
|
|
5714
5740
|
);
|
|
5715
|
-
const hide =
|
|
5741
|
+
const hide = React4.useCallback(() => {
|
|
5716
5742
|
clearTimeout(timerRef.current);
|
|
5717
5743
|
setVisible(false);
|
|
5718
5744
|
targetRef.current = null;
|
|
5719
5745
|
}, []);
|
|
5720
|
-
|
|
5746
|
+
React4.useEffect(() => {
|
|
5721
5747
|
return () => clearTimeout(timerRef.current);
|
|
5722
5748
|
}, []);
|
|
5723
5749
|
return {
|
|
@@ -5939,10 +5965,10 @@ function FlashCell({
|
|
|
5939
5965
|
}
|
|
5940
5966
|
function useCellFlash(table, options = {}) {
|
|
5941
5967
|
const { duration = 700 } = options;
|
|
5942
|
-
const [flashes, setFlashes] =
|
|
5943
|
-
const prevDataRef =
|
|
5944
|
-
const timersRef =
|
|
5945
|
-
const clearFlash =
|
|
5968
|
+
const [flashes, setFlashes] = React4.useState(/* @__PURE__ */ new Map());
|
|
5969
|
+
const prevDataRef = React4.useRef([]);
|
|
5970
|
+
const timersRef = React4.useRef(/* @__PURE__ */ new Map());
|
|
5971
|
+
const clearFlash = React4.useCallback((key) => {
|
|
5946
5972
|
setFlashes((prev) => {
|
|
5947
5973
|
const next = new Map(prev);
|
|
5948
5974
|
next.delete(key);
|
|
@@ -5950,7 +5976,7 @@ function useCellFlash(table, options = {}) {
|
|
|
5950
5976
|
});
|
|
5951
5977
|
timersRef.current.delete(key);
|
|
5952
5978
|
}, []);
|
|
5953
|
-
|
|
5979
|
+
React4.useEffect(() => {
|
|
5954
5980
|
const currentData = table.options.data;
|
|
5955
5981
|
const prevData = prevDataRef.current;
|
|
5956
5982
|
if (prevData.length > 0 && currentData !== prevData) {
|
|
@@ -5979,14 +6005,14 @@ function useCellFlash(table, options = {}) {
|
|
|
5979
6005
|
}
|
|
5980
6006
|
prevDataRef.current = currentData;
|
|
5981
6007
|
}, [table.options.data, table, duration, clearFlash]);
|
|
5982
|
-
|
|
6008
|
+
React4.useEffect(() => {
|
|
5983
6009
|
return () => {
|
|
5984
6010
|
for (const timer of timersRef.current.values()) {
|
|
5985
6011
|
clearTimeout(timer);
|
|
5986
6012
|
}
|
|
5987
6013
|
};
|
|
5988
6014
|
}, []);
|
|
5989
|
-
const getFlash =
|
|
6015
|
+
const getFlash = React4.useCallback(
|
|
5990
6016
|
(rowId, columnId) => {
|
|
5991
6017
|
return flashes.get(`${rowId}:${columnId}`);
|
|
5992
6018
|
},
|
|
@@ -5996,9 +6022,9 @@ function useCellFlash(table, options = {}) {
|
|
|
5996
6022
|
}
|
|
5997
6023
|
function useRowAnimation(_table, options = {}) {
|
|
5998
6024
|
const { enabled = false, duration = 250, easing = "ease" } = options;
|
|
5999
|
-
const prevPositionsRef =
|
|
6000
|
-
const animatingRef =
|
|
6001
|
-
const capturePositions =
|
|
6025
|
+
const prevPositionsRef = React4.useRef(/* @__PURE__ */ new Map());
|
|
6026
|
+
const animatingRef = React4.useRef(false);
|
|
6027
|
+
const capturePositions = React4.useCallback(
|
|
6002
6028
|
(containerEl) => {
|
|
6003
6029
|
if (!enabled || !containerEl) return;
|
|
6004
6030
|
const positions = /* @__PURE__ */ new Map();
|
|
@@ -6016,7 +6042,7 @@ function useRowAnimation(_table, options = {}) {
|
|
|
6016
6042
|
},
|
|
6017
6043
|
[enabled]
|
|
6018
6044
|
);
|
|
6019
|
-
const animateRows =
|
|
6045
|
+
const animateRows = React4.useCallback(
|
|
6020
6046
|
(containerEl) => {
|
|
6021
6047
|
if (!enabled || !containerEl || animatingRef.current) return;
|
|
6022
6048
|
const prevPositions = prevPositionsRef.current;
|
|
@@ -6138,8 +6164,8 @@ function sanitizeCSS(css) {
|
|
|
6138
6164
|
}
|
|
6139
6165
|
function usePrintLayout(_table, options = {}) {
|
|
6140
6166
|
const { title, additionalCSS } = options;
|
|
6141
|
-
const isPrintingRef =
|
|
6142
|
-
const preparePrint =
|
|
6167
|
+
const isPrintingRef = React4.useRef(false);
|
|
6168
|
+
const preparePrint = React4.useCallback(() => {
|
|
6143
6169
|
const yableEl = document.querySelector(".yable");
|
|
6144
6170
|
if (yableEl) {
|
|
6145
6171
|
yableEl.classList.add("yable-print-mode");
|
|
@@ -6181,23 +6207,23 @@ function usePrintLayout(_table, options = {}) {
|
|
|
6181
6207
|
}
|
|
6182
6208
|
function useTheme(options = {}) {
|
|
6183
6209
|
const { defaultTheme = "default", defaultColorScheme = "auto" } = options;
|
|
6184
|
-
const [theme, setThemeState] =
|
|
6185
|
-
const [colorScheme, setColorSchemeState] =
|
|
6186
|
-
const containerRef =
|
|
6187
|
-
const setTheme =
|
|
6210
|
+
const [theme, setThemeState] = React4.useState(defaultTheme);
|
|
6211
|
+
const [colorScheme, setColorSchemeState] = React4.useState(defaultColorScheme);
|
|
6212
|
+
const containerRef = React4.useRef(null);
|
|
6213
|
+
const setTheme = React4.useCallback((newTheme) => {
|
|
6188
6214
|
setThemeState(newTheme);
|
|
6189
6215
|
}, []);
|
|
6190
|
-
const setColorScheme =
|
|
6216
|
+
const setColorScheme = React4.useCallback((scheme) => {
|
|
6191
6217
|
setColorSchemeState(scheme);
|
|
6192
6218
|
}, []);
|
|
6193
|
-
const toggleColorScheme =
|
|
6219
|
+
const toggleColorScheme = React4.useCallback(() => {
|
|
6194
6220
|
setColorSchemeState((prev) => {
|
|
6195
6221
|
if (prev === "auto") return "dark";
|
|
6196
6222
|
if (prev === "dark") return "light";
|
|
6197
6223
|
return "auto";
|
|
6198
6224
|
});
|
|
6199
6225
|
}, []);
|
|
6200
|
-
|
|
6226
|
+
React4.useEffect(() => {
|
|
6201
6227
|
const target = containerRef.current ?? document.documentElement;
|
|
6202
6228
|
if (colorScheme === "auto") {
|
|
6203
6229
|
target.removeAttribute("data-yable-theme");
|
|
@@ -6205,8 +6231,8 @@ function useTheme(options = {}) {
|
|
|
6205
6231
|
target.setAttribute("data-yable-theme", colorScheme);
|
|
6206
6232
|
}
|
|
6207
6233
|
}, [colorScheme]);
|
|
6208
|
-
const [systemDark, setSystemDark] =
|
|
6209
|
-
|
|
6234
|
+
const [systemDark, setSystemDark] = React4.useState(false);
|
|
6235
|
+
React4.useEffect(() => {
|
|
6210
6236
|
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
6211
6237
|
setSystemDark(mq.matches);
|
|
6212
6238
|
const handler = (e) => setSystemDark(e.matches);
|