@krak-stack/registry 0.1.10 → 0.1.11
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.
|
@@ -143,6 +143,7 @@ export type DataTableMessages = PaginationMessages & {
|
|
|
143
143
|
listOthers: (count: number) => string;
|
|
144
144
|
selectAllRows: string;
|
|
145
145
|
selectRow: string;
|
|
146
|
+
selected: string;
|
|
146
147
|
};
|
|
147
148
|
export type DataTableMessageOverrides = Partial<DataTableMessages>;
|
|
148
149
|
export declare const dataTableMessages: (overrides?: DataTableMessageOverrides) => {
|
|
@@ -177,6 +178,7 @@ export declare const dataTableMessages: (overrides?: DataTableMessageOverrides)
|
|
|
177
178
|
listOthers: (count: number) => string;
|
|
178
179
|
selectAllRows: string;
|
|
179
180
|
selectRow: string;
|
|
181
|
+
selected: string;
|
|
180
182
|
} | {
|
|
181
183
|
pageSize: string;
|
|
182
184
|
results: (count: number) => string;
|
|
@@ -209,6 +211,7 @@ export declare const dataTableMessages: (overrides?: DataTableMessageOverrides)
|
|
|
209
211
|
listOthers: (count: number) => string;
|
|
210
212
|
selectAllRows: string;
|
|
211
213
|
selectRow: string;
|
|
214
|
+
selected: string;
|
|
212
215
|
};
|
|
213
216
|
export interface DataTableGroupingField<TData> {
|
|
214
217
|
id: string;
|
|
@@ -253,6 +256,14 @@ export type DataTableRowAction<TData> = {
|
|
|
253
256
|
onClick: (data: TData) => void;
|
|
254
257
|
visible?: (data: TData) => boolean;
|
|
255
258
|
};
|
|
259
|
+
export type DataTableBulkAction<TData> = {
|
|
260
|
+
id?: string;
|
|
261
|
+
name: string;
|
|
262
|
+
icon?: ReactNode;
|
|
263
|
+
variant?: "default" | "destructive" | undefined;
|
|
264
|
+
onClick: (rows: TData[]) => void;
|
|
265
|
+
visible?: (rows: TData[]) => boolean;
|
|
266
|
+
};
|
|
256
267
|
export type DataTableGroupAction = {
|
|
257
268
|
name: string;
|
|
258
269
|
icon?: ReactNode;
|
|
@@ -285,6 +296,10 @@ export interface DataTableColumnVisibilityFeature {
|
|
|
285
296
|
default?: ColumnVisibilityState;
|
|
286
297
|
}
|
|
287
298
|
export interface DataTableSelectionFeature<TData> {
|
|
299
|
+
bulkActions?: false | {
|
|
300
|
+
label?: string;
|
|
301
|
+
items: readonly DataTableBulkAction<TData>[];
|
|
302
|
+
};
|
|
288
303
|
getRowId: (row: TData) => string;
|
|
289
304
|
isRowSelectable?: (row: TData) => boolean;
|
|
290
305
|
onSelectionChange?: (rows: TData[]) => void;
|
|
@@ -1964,7 +1964,8 @@ var messages3 = {
|
|
|
1964
1964
|
resizeColumn: (column) => `Resize ${column} column`,
|
|
1965
1965
|
listOthers: (count) => count === 1 ? "and 1 other" : `and ${count} others`,
|
|
1966
1966
|
selectAllRows: "Select all rows on this page",
|
|
1967
|
-
selectRow: "Select row"
|
|
1967
|
+
selectRow: "Select row",
|
|
1968
|
+
selected: "Selected"
|
|
1968
1969
|
},
|
|
1969
1970
|
fr: {
|
|
1970
1971
|
...paginationMessages("fr"),
|
|
@@ -1990,7 +1991,8 @@ var messages3 = {
|
|
|
1990
1991
|
resizeColumn: (column) => `Redimensionner la colonne ${column}`,
|
|
1991
1992
|
listOthers: (count) => count === 1 ? "et 1 autre" : `et ${count} autres`,
|
|
1992
1993
|
selectAllRows: "Sélectionner toutes les lignes de cette page",
|
|
1993
|
-
selectRow: "Sélectionner la ligne"
|
|
1994
|
+
selectRow: "Sélectionner la ligne",
|
|
1995
|
+
selected: "Sélectionnés"
|
|
1994
1996
|
}
|
|
1995
1997
|
};
|
|
1996
1998
|
var dataTableMessages = (overrides) => ({
|
|
@@ -2086,6 +2088,59 @@ var DataTableRowActions = ({
|
|
|
2086
2088
|
]
|
|
2087
2089
|
});
|
|
2088
2090
|
};
|
|
2091
|
+
var DataTableBulkActions = ({
|
|
2092
|
+
actions,
|
|
2093
|
+
label,
|
|
2094
|
+
selectedLabel: selectedLabel2,
|
|
2095
|
+
rows
|
|
2096
|
+
}) => {
|
|
2097
|
+
const visibleActions = actions.filter((action) => !action.visible || action.visible(rows));
|
|
2098
|
+
if (visibleActions.length === 0)
|
|
2099
|
+
return null;
|
|
2100
|
+
return /* @__PURE__ */ jsxs8(DropdownMenu, {
|
|
2101
|
+
children: [
|
|
2102
|
+
/* @__PURE__ */ jsx17(DropdownMenuTrigger, {
|
|
2103
|
+
render: /* @__PURE__ */ jsxs8(Button, {
|
|
2104
|
+
className: "h-9",
|
|
2105
|
+
size: "sm",
|
|
2106
|
+
variant: "default",
|
|
2107
|
+
children: [
|
|
2108
|
+
selectedLabel2,
|
|
2109
|
+
/* @__PURE__ */ jsx17(Badge, {
|
|
2110
|
+
className: "bg-primary-foreground/15 text-primary-foreground min-w-5 justify-center rounded-full border-0 px-1.5 tabular-nums",
|
|
2111
|
+
variant: "secondary",
|
|
2112
|
+
children: rows.length
|
|
2113
|
+
}),
|
|
2114
|
+
/* @__PURE__ */ jsx17(ChevronRight2, {
|
|
2115
|
+
className: "rotate-90"
|
|
2116
|
+
})
|
|
2117
|
+
]
|
|
2118
|
+
})
|
|
2119
|
+
}),
|
|
2120
|
+
/* @__PURE__ */ jsx17(DropdownMenuContent, {
|
|
2121
|
+
align: "start",
|
|
2122
|
+
className: "w-max max-w-56",
|
|
2123
|
+
children: /* @__PURE__ */ jsxs8(DropdownMenuGroup, {
|
|
2124
|
+
children: [
|
|
2125
|
+
/* @__PURE__ */ jsx17(DropdownMenuLabel, {
|
|
2126
|
+
children: label
|
|
2127
|
+
}),
|
|
2128
|
+
/* @__PURE__ */ jsx17(DropdownMenuSeparator, {}),
|
|
2129
|
+
visibleActions.map((action) => /* @__PURE__ */ jsxs8(DropdownMenuItem, {
|
|
2130
|
+
className: "whitespace-nowrap",
|
|
2131
|
+
onClick: () => action.onClick(rows),
|
|
2132
|
+
...action.variant ? { variant: action.variant } : {},
|
|
2133
|
+
children: [
|
|
2134
|
+
action.icon,
|
|
2135
|
+
action.name
|
|
2136
|
+
]
|
|
2137
|
+
}, action.id ?? action.name))
|
|
2138
|
+
]
|
|
2139
|
+
})
|
|
2140
|
+
})
|
|
2141
|
+
]
|
|
2142
|
+
});
|
|
2143
|
+
};
|
|
2089
2144
|
var buildGroupedSections = (rows, fields, depth = 0, parentKey = "") => {
|
|
2090
2145
|
if (fields.length === 0) {
|
|
2091
2146
|
return [];
|
|
@@ -2640,6 +2695,7 @@ var exportTableToJson = (table, rows, fileName = "data.json") => {
|
|
|
2640
2695
|
};
|
|
2641
2696
|
var DataTableToolbar = ({
|
|
2642
2697
|
activeGrouping,
|
|
2698
|
+
bulkActions,
|
|
2643
2699
|
exportBaseName,
|
|
2644
2700
|
exportRows,
|
|
2645
2701
|
grouping,
|
|
@@ -2647,6 +2703,7 @@ var DataTableToolbar = ({
|
|
|
2647
2703
|
onRefresh,
|
|
2648
2704
|
onToggleGrouping,
|
|
2649
2705
|
onViewChange,
|
|
2706
|
+
selectedRows,
|
|
2650
2707
|
showColumnVisibility,
|
|
2651
2708
|
showExport,
|
|
2652
2709
|
showGallery,
|
|
@@ -2657,7 +2714,7 @@ var DataTableToolbar = ({
|
|
|
2657
2714
|
}) => {
|
|
2658
2715
|
const [refreshSpinCount, setRefreshSpinCount] = useState(0);
|
|
2659
2716
|
const [searchInput, setSearchInput] = useState(table.state.globalFilter);
|
|
2660
|
-
const hasToolbar = Boolean(showSearch || grouping?.fields.length || showSorting || showGallery || showColumnVisibility || onRefresh || showExport);
|
|
2717
|
+
const hasToolbar = Boolean(showSearch || grouping?.fields.length || showSorting || showGallery || showColumnVisibility || onRefresh || showExport || selectedRows.length > 0 && bulkActions?.items.length);
|
|
2661
2718
|
useEffect2(() => {
|
|
2662
2719
|
setSearchInput(table.state.globalFilter);
|
|
2663
2720
|
}, [table.state.globalFilter]);
|
|
@@ -2702,6 +2759,12 @@ var DataTableToolbar = ({
|
|
|
2702
2759
|
/* @__PURE__ */ jsxs8("div", {
|
|
2703
2760
|
className: "-m-1 flex items-center gap-2 overflow-x-auto p-1",
|
|
2704
2761
|
children: [
|
|
2762
|
+
bulkActions && selectedRows.length > 0 ? /* @__PURE__ */ jsx17(DataTableBulkActions, {
|
|
2763
|
+
actions: bulkActions.items,
|
|
2764
|
+
label: bulkActions.label ?? labels2.actions,
|
|
2765
|
+
rows: selectedRows,
|
|
2766
|
+
selectedLabel: labels2.selected
|
|
2767
|
+
}) : null,
|
|
2705
2768
|
grouping?.fields.length ? /* @__PURE__ */ jsxs8(DropdownMenu, {
|
|
2706
2769
|
children: [
|
|
2707
2770
|
/* @__PURE__ */ jsx17(DropdownMenuTrigger, {
|
|
@@ -2871,6 +2934,7 @@ function DataTable({
|
|
|
2871
2934
|
const showSorting = features?.sorting ?? true;
|
|
2872
2935
|
const selectionFeature = features?.selection === false ? undefined : features?.selection;
|
|
2873
2936
|
const selectable = !!selectionFeature;
|
|
2937
|
+
const bulkActions = selectionFeature?.bulkActions === false ? undefined : selectionFeature?.bulkActions;
|
|
2874
2938
|
const isServerMode = paginationFeature !== false && paginationFeature.mode === "server";
|
|
2875
2939
|
const serverRowCount = isServerMode ? paginationFeature.rowCount : undefined;
|
|
2876
2940
|
const location = useRouterState({
|
|
@@ -3035,6 +3099,7 @@ function DataTable({
|
|
|
3035
3099
|
const activeGroupingFields = useMemo(() => activeGrouping.map((groupId) => grouping?.fields.find((field) => field.id === groupId)).filter((field) => !!field), [activeGrouping, grouping]);
|
|
3036
3100
|
const hasActiveGrouping = activeGroupingFields.length > 0;
|
|
3037
3101
|
const filteredRows = table.getPrePaginatedRowModel().rows;
|
|
3102
|
+
const selectedRows = selectionFeature ? data.filter((row) => rowSelection[selectionFeature.getRowId(row)]) : [];
|
|
3038
3103
|
const exportRows = exportFeature && exportFeature.scope === "filteredRows" ? filteredRows : table.getRowModel().rows;
|
|
3039
3104
|
const bodyRows = hasActiveGrouping ? filteredRows : table.getRowModel().rows;
|
|
3040
3105
|
const sortableRowIds = bodyRows.map((row) => getSortableRowId(row.id));
|
|
@@ -3193,6 +3258,7 @@ function DataTable({
|
|
|
3193
3258
|
children: [
|
|
3194
3259
|
/* @__PURE__ */ jsx17(DataTableToolbar, {
|
|
3195
3260
|
activeGrouping,
|
|
3261
|
+
bulkActions,
|
|
3196
3262
|
exportBaseName,
|
|
3197
3263
|
exportRows,
|
|
3198
3264
|
grouping,
|
|
@@ -3200,6 +3266,7 @@ function DataTable({
|
|
|
3200
3266
|
onRefresh,
|
|
3201
3267
|
onToggleGrouping: toggleGroupingField,
|
|
3202
3268
|
onViewChange: setView,
|
|
3269
|
+
selectedRows,
|
|
3203
3270
|
showColumnVisibility,
|
|
3204
3271
|
showExport,
|
|
3205
3272
|
showGallery,
|