@vritti/quantum-ui 0.6.8 → 0.6.10
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/DangerZoneSkeleton.js +16 -2
- package/dist/DangerZoneSkeleton.js.map +1 -1
- package/dist/QuantityField.js +323 -105
- package/dist/QuantityField.js.map +1 -1
- package/dist/Spinner.js +8 -2
- package/dist/Spinner.js.map +1 -1
- package/dist/assets/quantum-ui.css +88 -0
- package/dist/components/QuantityField.js +1 -1
- package/dist/hooks/index.js +2 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/index13.js +2 -1
- package/dist/index13.js.map +1 -1
- package/dist/lib/components/DangerZone/DangerZone.d.ts +3 -1
- package/dist/lib/components/DangerZone/DangerZone.d.ts.map +1 -1
- package/dist/lib/components/DataTable/DataTable.d.ts.map +1 -1
- package/dist/lib/components/DataTable/components/DataTablePagination.d.ts.map +1 -1
- package/dist/lib/components/DataTable/components/DataTableSelectionBar.d.ts +3 -2
- package/dist/lib/components/DataTable/components/DataTableSelectionBar.d.ts.map +1 -1
- package/dist/lib/components/DataTable/components/RowActions.d.ts +2 -0
- package/dist/lib/components/DataTable/components/RowActions.d.ts.map +1 -1
- package/dist/lib/components/DataTable/hooks/useDataTable.d.ts +4 -1
- package/dist/lib/components/DataTable/hooks/useDataTable.d.ts.map +1 -1
- package/dist/lib/components/DataTable/index.d.ts +1 -1
- package/dist/lib/components/DataTable/index.d.ts.map +1 -1
- package/dist/lib/components/DataTable/types.d.ts +13 -1
- package/dist/lib/components/DataTable/types.d.ts.map +1 -1
- package/dist/lib/components/DataTable/utils.d.ts +2 -2
- package/dist/lib/components/DataTable/utils.d.ts.map +1 -1
- package/dist/lib/components/QuantityField/QuantityField.d.ts +6 -1
- package/dist/lib/components/QuantityField/QuantityField.d.ts.map +1 -1
- package/dist/lib/components/QuantityField/index.d.ts +1 -1
- package/dist/lib/components/QuantityField/index.d.ts.map +1 -1
- package/dist/lib/components/QuantityField/quantity.d.ts +14 -0
- package/dist/lib/components/QuantityField/quantity.d.ts.map +1 -1
- package/dist/lib/utils/format.d.ts +4 -0
- package/dist/lib/utils/format.d.ts.map +1 -1
- package/dist/popover.js +5 -2
- package/dist/popover.js.map +1 -1
- package/dist/shadcn/shadcnPopover/index.d.ts +1 -1
- package/dist/shadcn/shadcnPopover/index.d.ts.map +1 -1
- package/dist/shadcn/shadcnPopover/popover.d.ts +2 -1
- package/dist/shadcn/shadcnPopover/popover.d.ts.map +1 -1
- package/dist/useConfirm.js +1 -26
- package/dist/useConfirm.js.map +1 -1
- package/dist/useDataTable.js +172 -27
- package/dist/useDataTable.js.map +1 -1
- package/dist/useDialog.js +28 -0
- package/dist/useDialog.js.map +1 -0
- package/dist/utils/format.js +14 -6
- package/dist/utils/format.js.map +1 -1
- package/package.json +1 -1
- package/dist/Spinner2.js +0 -10
- package/dist/Spinner2.js.map +0 -1
package/dist/useDataTable.js
CHANGED
|
@@ -2,7 +2,8 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
2
2
|
import { c as cn } from './utils.js';
|
|
3
3
|
import { S as Skeleton } from './Skeleton.js';
|
|
4
4
|
import { u as useFormatters } from './useFormatters.js';
|
|
5
|
-
import {
|
|
5
|
+
import { u as useConfirm } from './useConfirm.js';
|
|
6
|
+
import { u as useDialog } from './useDialog.js';
|
|
6
7
|
import { B as Button } from './Button.js';
|
|
7
8
|
import { D as Dialog, a as DialogActions } from './Dialog.js';
|
|
8
9
|
import { D as DropdownMenu } from './DropdownMenu.js';
|
|
@@ -605,7 +606,7 @@ DataTableFilters.displayName = "DataTableFilters";
|
|
|
605
606
|
|
|
606
607
|
function DataTablePagination({
|
|
607
608
|
table,
|
|
608
|
-
pageSizeOptions = [10, 20, 30, 50],
|
|
609
|
+
pageSizeOptions = [10, 20, 30, 50, 100],
|
|
609
610
|
className
|
|
610
611
|
}) {
|
|
611
612
|
const [pageInputValue, setPageInputValue] = useState(null);
|
|
@@ -19286,6 +19287,7 @@ function getSelectionColumn() {
|
|
|
19286
19287
|
{
|
|
19287
19288
|
checked: table.getIsAllPageRowsSelected() || table.getIsSomePageRowsSelected() && "indeterminate",
|
|
19288
19289
|
onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value),
|
|
19290
|
+
disabled: !table.getRowModel().rows.some((row) => row.getCanSelect()),
|
|
19289
19291
|
"aria-label": "Select all"
|
|
19290
19292
|
}
|
|
19291
19293
|
),
|
|
@@ -19294,6 +19296,7 @@ function getSelectionColumn() {
|
|
|
19294
19296
|
{
|
|
19295
19297
|
checked: row.getIsSelected(),
|
|
19296
19298
|
onCheckedChange: (value) => row.toggleSelected(!!value),
|
|
19299
|
+
disabled: !row.getCanSelect(),
|
|
19297
19300
|
"aria-label": "Select row"
|
|
19298
19301
|
}
|
|
19299
19302
|
),
|
|
@@ -19315,7 +19318,7 @@ function downloadBlob(blob, filename) {
|
|
|
19315
19318
|
}
|
|
19316
19319
|
function transformRows(rows, config) {
|
|
19317
19320
|
return rows.map((row) => {
|
|
19318
|
-
const transformed = config.transformExportRow ? config.transformExportRow(row
|
|
19321
|
+
const transformed = config.transformExportRow ? config.transformExportRow(row) : row;
|
|
19319
19322
|
const picked = {};
|
|
19320
19323
|
for (const col of config.columns) {
|
|
19321
19324
|
picked[col.label] = String(transformed[col.key] ?? "");
|
|
@@ -19342,8 +19345,10 @@ function exportSelectedRows(rows, config, format) {
|
|
|
19342
19345
|
downloadBlob(new Blob([buf]), `${config.filename}.${ext}`);
|
|
19343
19346
|
}
|
|
19344
19347
|
|
|
19348
|
+
const ALL_MATCHING_EXPORT_TIP = "All matching rows are not loaded here — tick the rows to export instead";
|
|
19345
19349
|
function DataTableSelectionBar({
|
|
19346
19350
|
table,
|
|
19351
|
+
selection,
|
|
19347
19352
|
children,
|
|
19348
19353
|
className,
|
|
19349
19354
|
importExport,
|
|
@@ -19351,8 +19356,8 @@ function DataTableSelectionBar({
|
|
|
19351
19356
|
exportLockTip
|
|
19352
19357
|
}) {
|
|
19353
19358
|
const meta = table.options.meta;
|
|
19354
|
-
const
|
|
19355
|
-
const
|
|
19359
|
+
const count = selection.count;
|
|
19360
|
+
const offersAllMatching = selection.canSelectAllMatching && !selection.allMatching && table.getIsAllPageRowsSelected() && selection.matchingCount > count;
|
|
19356
19361
|
const singular = meta?.singular ?? "row";
|
|
19357
19362
|
const plural = meta?.plural ?? "rows";
|
|
19358
19363
|
if (count === 0) return null;
|
|
@@ -19365,20 +19370,27 @@ function DataTableSelectionBar({
|
|
|
19365
19370
|
};
|
|
19366
19371
|
return /* @__PURE__ */ jsxs("div", { className: cn("flex items-center gap-2 px-4 py-3 border-b", className), children: [
|
|
19367
19372
|
/* @__PURE__ */ jsxs("span", { className: "text-sm font-medium mr-2", children: [
|
|
19373
|
+
selection.allMatching ? "All " : "",
|
|
19368
19374
|
count,
|
|
19369
19375
|
" ",
|
|
19370
19376
|
count === 1 ? singular : plural,
|
|
19371
19377
|
" selected"
|
|
19372
19378
|
] }),
|
|
19379
|
+
offersAllMatching && /* @__PURE__ */ jsxs(Button, { variant: "link", size: "sm", className: "h-8 px-1", onClick: selection.selectAllMatching, children: [
|
|
19380
|
+
"Select all ",
|
|
19381
|
+
selection.matchingCount,
|
|
19382
|
+
" matching"
|
|
19383
|
+
] }),
|
|
19384
|
+
selection.allMatching && /* @__PURE__ */ jsx(Button, { variant: "link", size: "sm", className: "h-8 px-1", onClick: selection.clear, children: "Clear selection" }),
|
|
19373
19385
|
children,
|
|
19374
|
-
/* @__PURE__ */ jsx("div", { className: "ml-auto flex items-center gap-2", children: exportHidden ? null : exportLockTip ? /* @__PURE__ */ jsx(
|
|
19386
|
+
/* @__PURE__ */ jsx("div", { className: "ml-auto flex items-center gap-2", children: exportHidden ? null : exportLockTip || selection.allMatching ? /* @__PURE__ */ jsx(
|
|
19375
19387
|
Button,
|
|
19376
19388
|
{
|
|
19377
19389
|
variant: "outline",
|
|
19378
19390
|
size: "sm",
|
|
19379
19391
|
className: "h-8 text-sm",
|
|
19380
19392
|
disabled: true,
|
|
19381
|
-
disabledTip: exportLockTip,
|
|
19393
|
+
disabledTip: exportLockTip ?? ALL_MATCHING_EXPORT_TIP,
|
|
19382
19394
|
startAdornment: /* @__PURE__ */ jsx(Download, { className: "h-4 w-4" }),
|
|
19383
19395
|
children: "Export Selected"
|
|
19384
19396
|
}
|
|
@@ -19396,31 +19408,31 @@ function DataTableSelectionBar({
|
|
|
19396
19408
|
type: "item",
|
|
19397
19409
|
id: "csv",
|
|
19398
19410
|
label: "CSV (.csv)",
|
|
19399
|
-
onClick: () => exportSelectedRows(
|
|
19411
|
+
onClick: () => exportSelectedRows(selection.rows, exportConfig, "csv")
|
|
19400
19412
|
},
|
|
19401
19413
|
{
|
|
19402
19414
|
type: "item",
|
|
19403
19415
|
id: "xlsx",
|
|
19404
19416
|
label: "Excel (.xlsx)",
|
|
19405
|
-
onClick: () => exportSelectedRows(
|
|
19417
|
+
onClick: () => exportSelectedRows(selection.rows, exportConfig, "xlsx")
|
|
19406
19418
|
},
|
|
19407
19419
|
{
|
|
19408
19420
|
type: "item",
|
|
19409
19421
|
id: "xls",
|
|
19410
19422
|
label: "Excel 97-2004 (.xls)",
|
|
19411
|
-
onClick: () => exportSelectedRows(
|
|
19423
|
+
onClick: () => exportSelectedRows(selection.rows, exportConfig, "xls")
|
|
19412
19424
|
},
|
|
19413
19425
|
{
|
|
19414
19426
|
type: "item",
|
|
19415
19427
|
id: "ods",
|
|
19416
19428
|
label: "OpenDocument (.ods)",
|
|
19417
|
-
onClick: () => exportSelectedRows(
|
|
19429
|
+
onClick: () => exportSelectedRows(selection.rows, exportConfig, "ods")
|
|
19418
19430
|
},
|
|
19419
19431
|
{
|
|
19420
19432
|
type: "item",
|
|
19421
19433
|
id: "tsv",
|
|
19422
19434
|
label: "TSV (.tsv)",
|
|
19423
|
-
onClick: () => exportSelectedRows(
|
|
19435
|
+
onClick: () => exportSelectedRows(selection.rows, exportConfig, "tsv")
|
|
19424
19436
|
}
|
|
19425
19437
|
]
|
|
19426
19438
|
}
|
|
@@ -19651,6 +19663,24 @@ const DirectAction = ({ action, disabledAll }) => {
|
|
|
19651
19663
|
}
|
|
19652
19664
|
);
|
|
19653
19665
|
};
|
|
19666
|
+
function withConfirm(action, confirm) {
|
|
19667
|
+
const { onClick } = action;
|
|
19668
|
+
if (!action.confirm || action.dialog || !onClick) return action;
|
|
19669
|
+
const options = {
|
|
19670
|
+
title: `${action.label}?`,
|
|
19671
|
+
confirmLabel: action.label,
|
|
19672
|
+
variant: action.variant ?? "default",
|
|
19673
|
+
...action.confirm === true ? {} : action.confirm
|
|
19674
|
+
};
|
|
19675
|
+
return {
|
|
19676
|
+
...action,
|
|
19677
|
+
onClick: () => {
|
|
19678
|
+
void confirm(options).then((accepted) => {
|
|
19679
|
+
if (accepted) onClick();
|
|
19680
|
+
});
|
|
19681
|
+
}
|
|
19682
|
+
};
|
|
19683
|
+
}
|
|
19654
19684
|
function toDropdownItems(actions, disabledAll) {
|
|
19655
19685
|
return actions.map((action) => {
|
|
19656
19686
|
if (action.dialog) {
|
|
@@ -19677,12 +19707,14 @@ function toDropdownItems(actions, disabledAll) {
|
|
|
19677
19707
|
}
|
|
19678
19708
|
const RowActions = ({ actions, disabledAll }) => {
|
|
19679
19709
|
const gate = usePermissionGate();
|
|
19710
|
+
const confirm = useConfirm();
|
|
19680
19711
|
const resolved = actions.map((action) => {
|
|
19681
|
-
|
|
19682
|
-
|
|
19683
|
-
|
|
19684
|
-
if (result.
|
|
19685
|
-
return
|
|
19712
|
+
const confirmed = withConfirm(action, confirm);
|
|
19713
|
+
if (!confirmed.permission) return confirmed;
|
|
19714
|
+
const result = gate(confirmed.permission);
|
|
19715
|
+
if (!result.granted) return { ...confirmed, hidden: true };
|
|
19716
|
+
if (result.locked) return { ...confirmed, disabled: true, lockTip: lockedTip(result) };
|
|
19717
|
+
return confirmed;
|
|
19686
19718
|
});
|
|
19687
19719
|
const visible = resolved.filter((a) => !a.hidden);
|
|
19688
19720
|
if (visible.length === 0) return null;
|
|
@@ -23740,6 +23772,7 @@ function GroupBracket({ children }) {
|
|
|
23740
23772
|
function buildNoResultsDescription(flags) {
|
|
23741
23773
|
const parts = [];
|
|
23742
23774
|
if (flags.hasActiveSearch) parts.push("your search");
|
|
23775
|
+
if (flags.hasActiveContext) parts.push("the context");
|
|
23743
23776
|
if (flags.hasActiveFilters) parts.push("your filters");
|
|
23744
23777
|
if (flags.hasActiveView) parts.push("this view");
|
|
23745
23778
|
const joined = parts.length === 1 ? parts[0] : `${parts.slice(0, -1).join(", ")} and ${parts[parts.length - 1]}`;
|
|
@@ -23761,7 +23794,7 @@ function DataTable({
|
|
|
23761
23794
|
selectedRowId,
|
|
23762
23795
|
permission
|
|
23763
23796
|
}) {
|
|
23764
|
-
const { table, isLoading: isLoadingProp, isFetching, isSyncing, isError, error, refetch } = instance;
|
|
23797
|
+
const { table, isLoading: isLoadingProp, isFetching, isSyncing, isError, error, refetch, selection } = instance;
|
|
23765
23798
|
const [filtersOpen, setFiltersOpen] = useState(false);
|
|
23766
23799
|
const importDialog = useDialog();
|
|
23767
23800
|
const headerScrollRef = useRef(null);
|
|
@@ -23801,18 +23834,23 @@ function DataTable({
|
|
|
23801
23834
|
const showImport = !!importExport?.importEndpoint && importGate.granted;
|
|
23802
23835
|
const showExport = !!importExport?.exportEndpoint && exportGate.granted;
|
|
23803
23836
|
const showToolbar = searchConfig || visibilityEnabled || toolbarActions || filters || contextBar || enableViews && slug || showImport || showExport;
|
|
23837
|
+
const setContext = meta?.setContext;
|
|
23838
|
+
const defaultContext = meta?.defaultContext ?? NO_FILTERS;
|
|
23839
|
+
const requiredContext = useMemo(() => new Set(defaultContext.map((c) => c.field)), [defaultContext]);
|
|
23840
|
+
const clearableContext = useMemo(
|
|
23841
|
+
() => (contextFilters ?? NO_FILTERS).filter((condition) => !requiredContext.has(condition.field)),
|
|
23842
|
+
[contextFilters, requiredContext]
|
|
23843
|
+
);
|
|
23804
23844
|
const search = meta?.search ?? null;
|
|
23805
23845
|
const hasActiveView = !!activeViewId;
|
|
23806
23846
|
const hasActiveFilters = hasActiveView ? !!meta?.isFiltersDirty : appliedFilterCount > 0;
|
|
23807
23847
|
const hasActiveSearch = hasActiveView ? !!meta?.isSearchDirty : !!(search?.value && search.value.trim() !== "");
|
|
23808
|
-
const
|
|
23848
|
+
const hasActiveContext = clearableContext.length > 0;
|
|
23849
|
+
const isFiltered = hasActiveSearch || hasActiveFilters || hasActiveContext || hasActiveView;
|
|
23809
23850
|
const filtersBaseline = meta?.activeViewState?.filters.panel ?? NO_FILTERS;
|
|
23810
23851
|
const searchBaseline = meta?.activeViewState?.search ?? null;
|
|
23811
23852
|
const onSearchChange = (s) => meta?.setSearch?.(s);
|
|
23812
|
-
const selectedCount =
|
|
23813
|
-
const setContext = meta?.setContext;
|
|
23814
|
-
const defaultContext = meta?.defaultContext ?? NO_FILTERS;
|
|
23815
|
-
const requiredContext = useMemo(() => new Set(defaultContext.map((c) => c.field)), [defaultContext]);
|
|
23853
|
+
const selectedCount = selection.count;
|
|
23816
23854
|
const boundContextBar = contextBar && setContext ? bindFilters(contextBar, {
|
|
23817
23855
|
conditions: contextFilters ?? NO_FILTERS,
|
|
23818
23856
|
onChange: setContext,
|
|
@@ -23854,10 +23892,26 @@ function DataTable({
|
|
|
23854
23892
|
{
|
|
23855
23893
|
icon: emptyStateConfig?.icon,
|
|
23856
23894
|
title: "No results found",
|
|
23857
|
-
description: buildNoResultsDescription({
|
|
23895
|
+
description: buildNoResultsDescription({
|
|
23896
|
+
hasActiveSearch,
|
|
23897
|
+
hasActiveFilters,
|
|
23898
|
+
hasActiveContext,
|
|
23899
|
+
hasActiveView
|
|
23900
|
+
}),
|
|
23858
23901
|
action: /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
23859
23902
|
hasActiveSearch && /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => meta?.setSearch?.(searchBaseline), children: "Clear Search" }),
|
|
23860
23903
|
hasActiveFilters && /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => meta?.setFilters?.(filtersBaseline), children: "Clear Filters" }),
|
|
23904
|
+
hasActiveContext && setContext && /* @__PURE__ */ jsx(
|
|
23905
|
+
Button,
|
|
23906
|
+
{
|
|
23907
|
+
variant: "outline",
|
|
23908
|
+
size: "sm",
|
|
23909
|
+
onClick: () => {
|
|
23910
|
+
for (const condition of clearableContext) setContext(condition.field, null);
|
|
23911
|
+
},
|
|
23912
|
+
children: "Clear Context"
|
|
23913
|
+
}
|
|
23914
|
+
),
|
|
23861
23915
|
hasActiveView && slug && /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => loadViewState(slug, EMPTY_TABLE_STATE, null, true), children: "Clear View" })
|
|
23862
23916
|
] })
|
|
23863
23917
|
}
|
|
@@ -24014,10 +24068,11 @@ function DataTable({
|
|
|
24014
24068
|
DataTableSelectionBar,
|
|
24015
24069
|
{
|
|
24016
24070
|
table,
|
|
24071
|
+
selection,
|
|
24017
24072
|
importExport,
|
|
24018
24073
|
exportHidden: !exportGate.granted,
|
|
24019
24074
|
exportLockTip: exportGate.locked ? lockedTip(exportGate) : void 0,
|
|
24020
|
-
children: selectActions?.(table.getFilteredSelectedRowModel().rows)
|
|
24075
|
+
children: selectActions?.(table.getFilteredSelectedRowModel().rows, selection)
|
|
24021
24076
|
}
|
|
24022
24077
|
)
|
|
24023
24078
|
},
|
|
@@ -24355,7 +24410,15 @@ function useAutoUpsert(slug, isReady, onStatePush) {
|
|
|
24355
24410
|
}
|
|
24356
24411
|
|
|
24357
24412
|
const NO_CONDITIONS = [];
|
|
24413
|
+
const NO_ROW_SELECTION = {};
|
|
24414
|
+
function rowIdsOf(rows) {
|
|
24415
|
+
const ids = rows.map((row) => row?.id);
|
|
24416
|
+
if (!ids.every((id) => typeof id === "string" || typeof id === "number")) return null;
|
|
24417
|
+
const unique = new Set(ids.map(String));
|
|
24418
|
+
return unique.size === ids.length ? [...unique] : null;
|
|
24419
|
+
}
|
|
24358
24420
|
const NO_FIELDS = [];
|
|
24421
|
+
const NO_ROWS = [];
|
|
24359
24422
|
function leafColumnIds(columns) {
|
|
24360
24423
|
return columns.flatMap((column) => {
|
|
24361
24424
|
if ("columns" in column && column.columns) return leafColumnIds(column.columns);
|
|
@@ -24382,6 +24445,8 @@ function useDataTable({
|
|
|
24382
24445
|
query,
|
|
24383
24446
|
enableMultiSort = true,
|
|
24384
24447
|
enableRowSelection = true,
|
|
24448
|
+
enableSelectAllMatching = false,
|
|
24449
|
+
getRowId,
|
|
24385
24450
|
enableHiding = true,
|
|
24386
24451
|
enableSorting = true,
|
|
24387
24452
|
enableColumnResizing = true,
|
|
@@ -24519,13 +24584,38 @@ function useDataTable({
|
|
|
24519
24584
|
]
|
|
24520
24585
|
);
|
|
24521
24586
|
const isSyncing = useAutoUpsert(slug, isReady, onStatePush);
|
|
24522
|
-
const data = serverState?.result ??
|
|
24587
|
+
const data = serverState?.result ?? NO_ROWS;
|
|
24523
24588
|
const totalRows = serverState?.count;
|
|
24589
|
+
const ownIds = useMemo(() => getRowId ? null : rowIdsOf(data), [getRowId, data]);
|
|
24590
|
+
const resolveRowId = useCallback(
|
|
24591
|
+
(row, index) => getRowId ? getRowId(row) : ownIds?.[index] ?? String(index),
|
|
24592
|
+
[getRowId, ownIds]
|
|
24593
|
+
);
|
|
24594
|
+
const [rowSelection, setRowSelection] = useState(NO_ROW_SELECTION);
|
|
24595
|
+
const [allMatching, setAllMatching] = useState(false);
|
|
24596
|
+
const [excludedIds, setExcludedIds] = useState(() => /* @__PURE__ */ new Set());
|
|
24597
|
+
const clearSelection = useCallback(() => {
|
|
24598
|
+
setAllMatching(false);
|
|
24599
|
+
setExcludedIds(/* @__PURE__ */ new Set());
|
|
24600
|
+
setRowSelection(NO_ROW_SELECTION);
|
|
24601
|
+
}, []);
|
|
24602
|
+
const selectAllMatching = useCallback(() => {
|
|
24603
|
+
setExcludedIds(/* @__PURE__ */ new Set());
|
|
24604
|
+
setAllMatching(true);
|
|
24605
|
+
}, []);
|
|
24606
|
+
const selectionScope = JSON.stringify([activeState.filters, activeState.search]);
|
|
24607
|
+
const scopeRef = useRef(selectionScope);
|
|
24608
|
+
useLayoutEffect(() => {
|
|
24609
|
+
if (scopeRef.current === selectionScope) return;
|
|
24610
|
+
scopeRef.current = selectionScope;
|
|
24611
|
+
clearSelection();
|
|
24612
|
+
}, [selectionScope, clearSelection]);
|
|
24524
24613
|
const table = useReactTable({
|
|
24525
24614
|
data,
|
|
24526
24615
|
columns,
|
|
24527
24616
|
state: {
|
|
24528
24617
|
sorting,
|
|
24618
|
+
rowSelection,
|
|
24529
24619
|
columnVisibility,
|
|
24530
24620
|
columnOrder,
|
|
24531
24621
|
columnSizing,
|
|
@@ -24535,6 +24625,20 @@ function useDataTable({
|
|
|
24535
24625
|
pageSize: activeState.pagination.limit
|
|
24536
24626
|
}
|
|
24537
24627
|
},
|
|
24628
|
+
getRowId: resolveRowId,
|
|
24629
|
+
onRowSelectionChange: (updater) => {
|
|
24630
|
+
const next = typeof updater === "function" ? updater(rowSelection) : updater;
|
|
24631
|
+
if (allMatching) {
|
|
24632
|
+
if (Object.values(next).every((ticked) => !ticked)) return clearSelection();
|
|
24633
|
+
setExcludedIds((previous) => {
|
|
24634
|
+
const excluded = new Set(previous);
|
|
24635
|
+
for (const id of Object.keys(rowSelection)) if (!next[id]) excluded.add(id);
|
|
24636
|
+
for (const [id, ticked] of Object.entries(next)) if (ticked) excluded.delete(id);
|
|
24637
|
+
return excluded;
|
|
24638
|
+
});
|
|
24639
|
+
}
|
|
24640
|
+
setRowSelection(next);
|
|
24641
|
+
},
|
|
24538
24642
|
onSortingChange: handleSortingChange,
|
|
24539
24643
|
onPaginationChange: (updater) => {
|
|
24540
24644
|
const current = {
|
|
@@ -24580,6 +24684,46 @@ function useDataTable({
|
|
|
24580
24684
|
enableHiding,
|
|
24581
24685
|
meta
|
|
24582
24686
|
});
|
|
24687
|
+
useLayoutEffect(() => {
|
|
24688
|
+
if (!allMatching || data.length === 0) return;
|
|
24689
|
+
const ticked = {};
|
|
24690
|
+
for (const row of table.getRowModel().rows)
|
|
24691
|
+
if (row.getCanSelect() && !excludedIds.has(row.id)) ticked[row.id] = true;
|
|
24692
|
+
setRowSelection((previous) => deepEqual(previous, ticked) ? previous : ticked);
|
|
24693
|
+
}, [allMatching, excludedIds, data, table]);
|
|
24694
|
+
const matchingCount = serverState?.selectableCount ?? totalRows ?? 0;
|
|
24695
|
+
const tickedIds = useMemo(
|
|
24696
|
+
() => Object.entries(rowSelection).flatMap(([id, ticked]) => ticked ? [id] : []),
|
|
24697
|
+
[rowSelection]
|
|
24698
|
+
);
|
|
24699
|
+
const seenRows = useRef(/* @__PURE__ */ new Map());
|
|
24700
|
+
const tickedRows = useMemo(() => {
|
|
24701
|
+
data.forEach((row, index) => seenRows.current.set(resolveRowId(row, index), row));
|
|
24702
|
+
return tickedIds.flatMap((id) => seenRows.current.get(id) ?? []);
|
|
24703
|
+
}, [data, resolveRowId, tickedIds]);
|
|
24704
|
+
const selection = useMemo(
|
|
24705
|
+
() => ({
|
|
24706
|
+
allMatching,
|
|
24707
|
+
ids: allMatching ? [] : tickedIds,
|
|
24708
|
+
rows: allMatching ? [] : tickedRows,
|
|
24709
|
+
excludedIds: allMatching ? [...excludedIds] : [],
|
|
24710
|
+
count: allMatching ? Math.max(0, matchingCount - excludedIds.size) : tickedIds.length,
|
|
24711
|
+
matchingCount,
|
|
24712
|
+
canSelectAllMatching: enableSelectAllMatching,
|
|
24713
|
+
selectAllMatching,
|
|
24714
|
+
clear: clearSelection
|
|
24715
|
+
}),
|
|
24716
|
+
[
|
|
24717
|
+
allMatching,
|
|
24718
|
+
tickedIds,
|
|
24719
|
+
tickedRows,
|
|
24720
|
+
excludedIds,
|
|
24721
|
+
matchingCount,
|
|
24722
|
+
enableSelectAllMatching,
|
|
24723
|
+
selectAllMatching,
|
|
24724
|
+
clearSelection
|
|
24725
|
+
]
|
|
24726
|
+
);
|
|
24583
24727
|
return {
|
|
24584
24728
|
table,
|
|
24585
24729
|
isLoading: query?.isLoading ?? false,
|
|
@@ -24589,7 +24733,8 @@ function useDataTable({
|
|
|
24589
24733
|
error: query?.error,
|
|
24590
24734
|
refetch: query?.refetch,
|
|
24591
24735
|
contextValue,
|
|
24592
|
-
isLoaded: isReady
|
|
24736
|
+
isLoaded: isReady,
|
|
24737
|
+
selection
|
|
24593
24738
|
};
|
|
24594
24739
|
}
|
|
24595
24740
|
|