@undevy-org/tablewright 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/hooks/table-orchestration/use-column-filter-stats.js +38 -0
- package/dist/es/hooks/table-orchestration/use-column-gaps.js +35 -0
- package/dist/es/hooks/table-orchestration/use-filtered-rows.js +32 -0
- package/dist/es/hooks/table-orchestration/use-orchestration-actions.js +182 -0
- package/dist/es/hooks/table-orchestration/use-responsive-columns.js +35 -0
- package/dist/es/hooks/useTableOrchestration.js +69 -264
- package/dist/tablewright.cjs +389 -289
- package/dist/types/hooks/table-orchestration/use-column-filter-stats.d.ts +6 -0
- package/dist/types/hooks/table-orchestration/use-column-gaps.d.ts +17 -0
- package/dist/types/hooks/table-orchestration/use-filtered-rows.d.ts +15 -0
- package/dist/types/hooks/table-orchestration/use-orchestration-actions.d.ts +49 -0
- package/dist/types/hooks/table-orchestration/use-responsive-columns.d.ts +10 -0
- package/dist/types/hooks/table-orchestration-store.d.ts +2 -0
- package/dist/types/hooks/useTableOrchestration.d.ts +2 -0
- package/package.json +1 -1
- package/dist/types/hooks/useDemoTheme.d.ts +0 -8
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ColumnFilterConfig, FilterStatsSlice } from "../../components/data-table/filter-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* `all` stats come from every row; `filtered` from the filtered rows, or
|
|
4
|
+
* `null` while no column filter or search is applied.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useColumnFilterStats<TRow extends object>(rows: TRow[], filteredRows: TRow[], filterConfigs: Record<string, ColumnFilterConfig>, isFiltered: boolean): Record<string, FilterStatsSlice>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { VisibilityState } from "@tanstack/react-table";
|
|
2
|
+
import type { ColumnGap, ColumnGroup } from "../../components/data-table/filter-types.js";
|
|
3
|
+
import type { ColumnMetaDef } from "../../components/data-table/types.js";
|
|
4
|
+
/** Column id of the gap indicator column placed after `afterColumnId` (`null` = at the start). */
|
|
5
|
+
export declare function gapColumnId(afterColumnId: string | null): string;
|
|
6
|
+
/** Gap indicators for hidden columns, plus column meta/widths extended with the gap columns. */
|
|
7
|
+
export declare function useColumnGaps({ columnGroups, toggleableColumnIds, columnVisibility, columnMeta, widths, }: {
|
|
8
|
+
columnGroups: ColumnGroup[] | undefined;
|
|
9
|
+
toggleableColumnIds: readonly string[];
|
|
10
|
+
columnVisibility: VisibilityState;
|
|
11
|
+
columnMeta: Record<string, ColumnMetaDef>;
|
|
12
|
+
widths: Record<string, number>;
|
|
13
|
+
}): {
|
|
14
|
+
columnGaps: ColumnGap[];
|
|
15
|
+
extendedColumnMeta: Record<string, ColumnMetaDef>;
|
|
16
|
+
extendedWidths: Record<string, number>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ActiveFilter, ViewPreset } from "../../components/data-table/filter-types.js";
|
|
2
|
+
/** Rows after the preset's custom filter, the submitted search and column filters, then sorted. */
|
|
3
|
+
export declare function useFilteredRows<TRow extends object, TViewKey extends string>({ rows, activePreset, searchQuery, columnFilters, currentSort, filterRow, getSearchText, getSortValue, }: {
|
|
4
|
+
rows: TRow[];
|
|
5
|
+
activePreset: ViewPreset<TRow, TViewKey>;
|
|
6
|
+
searchQuery: string;
|
|
7
|
+
columnFilters: ActiveFilter[];
|
|
8
|
+
currentSort: {
|
|
9
|
+
columnId: string;
|
|
10
|
+
direction: "asc" | "desc";
|
|
11
|
+
} | null;
|
|
12
|
+
filterRow: (row: TRow, filter: ActiveFilter) => boolean;
|
|
13
|
+
getSearchText: (row: TRow) => string;
|
|
14
|
+
getSortValue: (row: TRow, columnId: string) => string | number;
|
|
15
|
+
}): TRow[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { VisibilityState } from "@tanstack/react-table";
|
|
2
|
+
import type { ActiveFilterValue, ColumnFilterConfig, ViewPreset } from "../../components/data-table/filter-types.js";
|
|
3
|
+
import type { ColumnMetaDef } from "../../components/data-table/types.js";
|
|
4
|
+
import { type TableOrchestrationStoreApi } from "../table-orchestration-store.js";
|
|
5
|
+
/**
|
|
6
|
+
* Store actions bound into stable callbacks with the hook's public signatures
|
|
7
|
+
* (`handleX` / React-style setters). Each callback's deps are exactly what it
|
|
8
|
+
* reads, so identities only change when those inputs do.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useOrchestrationActions<TRow extends object, TViewKey extends string>({ store, viewPresets, filterConfigs, columnMeta, setWidths, defaultViewKey, paginatedRows, allOnPageSelected, getRowId, }: {
|
|
11
|
+
store: TableOrchestrationStoreApi<TViewKey>;
|
|
12
|
+
viewPresets: ViewPreset<TRow, TViewKey>[];
|
|
13
|
+
filterConfigs: Record<string, ColumnFilterConfig>;
|
|
14
|
+
columnMeta: Record<string, ColumnMetaDef>;
|
|
15
|
+
setWidths: (updater: (prev: Record<string, number>) => Record<string, number>) => void;
|
|
16
|
+
defaultViewKey: TViewKey;
|
|
17
|
+
paginatedRows: TRow[];
|
|
18
|
+
allOnPageSelected: boolean;
|
|
19
|
+
getRowId: (row: TRow) => string;
|
|
20
|
+
}): {
|
|
21
|
+
handleSearchSubmit: (e: React.FormEvent) => void;
|
|
22
|
+
handleHeaderSort: (columnId: string, direction: "asc" | "desc") => void;
|
|
23
|
+
handleViewChange: (key: TViewKey) => void;
|
|
24
|
+
handleAddColumnFilter: (columnId: string) => void;
|
|
25
|
+
handleOpenExistingFilter: (columnId: string) => void;
|
|
26
|
+
handleRequestOpenHandled: () => void;
|
|
27
|
+
handleRemoveColumnFilter: (columnId: string) => void;
|
|
28
|
+
handleChangeColumnFilter: (columnId: string, value: ActiveFilterValue) => void;
|
|
29
|
+
handleSetColumnFilter: (columnId: string, value: ActiveFilterValue) => void;
|
|
30
|
+
handleHeaderFilterClick: (columnId: string) => void;
|
|
31
|
+
handleHideColumn: (columnId: string) => void;
|
|
32
|
+
handleResetColumns: () => void;
|
|
33
|
+
handleRemoveSort: () => void;
|
|
34
|
+
handleRemoveCustomFilter: () => void;
|
|
35
|
+
handleClearAll: () => void;
|
|
36
|
+
handleRefresh: () => void;
|
|
37
|
+
handleToggleRowSelection: (id: string) => void;
|
|
38
|
+
handleToggleHeaderCheck: () => void;
|
|
39
|
+
handleExpandRow: (row: TRow, e: React.MouseEvent) => void;
|
|
40
|
+
handleExpandGap: (hiddenIds: string[]) => void;
|
|
41
|
+
handlePageChange: (p: number) => void;
|
|
42
|
+
handleRowsPerPageChange: (value: number) => void;
|
|
43
|
+
setSearchInput: (v: string) => void;
|
|
44
|
+
setColumnVisibility: import("react").Dispatch<import("react").SetStateAction<VisibilityState>>;
|
|
45
|
+
setDensity: (v: "normal" | "dense") => void;
|
|
46
|
+
setSelectedIds: import("react").Dispatch<import("react").SetStateAction<Set<string>>>;
|
|
47
|
+
setColumnsMenuOpen: (v: boolean) => void;
|
|
48
|
+
setSelectedRowId: (v: string | null) => void;
|
|
49
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Responsive column collapse (P1/P2/P3). Only P3 columns collapse below
|
|
3
|
+
* `wideBreakpoint`; `isCompact` flips below `compactBreakpoint` so consumers
|
|
4
|
+
* can switch to a card layout. Both start at their "wide" values so the first
|
|
5
|
+
* client render matches server HTML.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useResponsiveColumns(columnPriorities: Record<string, 2 | 3> | undefined, wideBreakpoint: number, compactBreakpoint: number): {
|
|
8
|
+
responsiveHiddenColumnIds: ReadonlySet<string>;
|
|
9
|
+
isCompact: boolean;
|
|
10
|
+
};
|
|
@@ -14,6 +14,7 @@ export interface TableOrchestrationState<TViewKey extends string = string> {
|
|
|
14
14
|
page: number;
|
|
15
15
|
rowsPerPage: number;
|
|
16
16
|
density: "normal" | "dense";
|
|
17
|
+
/** @deprecated Demo-only: it only spins for a fixed time (700 ms by default) and refetches nothing. Keep refresh state in your data layer (e.g. your query's `isFetching`). Will be removed in a future minor release. */
|
|
17
18
|
isRefreshing: boolean;
|
|
18
19
|
selectedIds: Set<string>;
|
|
19
20
|
activeView: TViewKey;
|
|
@@ -43,6 +44,7 @@ export interface TableOrchestrationActions<TViewKey extends string = string> {
|
|
|
43
44
|
setPage: (p: number) => void;
|
|
44
45
|
setRowsPerPage: (n: number) => void;
|
|
45
46
|
setDensity: (v: "normal" | "dense") => void;
|
|
47
|
+
/** @deprecated Demo-only: it only spins for a fixed time (700 ms by default) and refetches nothing. Keep refresh state in your data layer (e.g. your query's `isFetching`). Will be removed in a future minor release. */
|
|
46
48
|
startRefresh: (durationMs?: number) => void;
|
|
47
49
|
setSelectedIds: (next: Set<string> | ((prev: Set<string>) => Set<string>)) => void;
|
|
48
50
|
toggleRowSelection: (id: string) => void;
|
|
@@ -53,6 +53,7 @@ export interface TableOrchestrationReturn<TRow extends object, TViewKey extends
|
|
|
53
53
|
rowsPerPage: number;
|
|
54
54
|
density: "normal" | "dense";
|
|
55
55
|
setDensity: (v: "normal" | "dense") => void;
|
|
56
|
+
/** @deprecated Demo-only: it only spins for a fixed time (700 ms by default) and refetches nothing. Keep refresh state in your data layer (e.g. your query's `isFetching`). Will be removed in a future minor release. */
|
|
56
57
|
isRefreshing: boolean;
|
|
57
58
|
selectedIds: Set<string>;
|
|
58
59
|
setSelectedIds: React.Dispatch<React.SetStateAction<Set<string>>>;
|
|
@@ -101,6 +102,7 @@ export interface TableOrchestrationReturn<TRow extends object, TViewKey extends
|
|
|
101
102
|
handleRemoveSort: () => void;
|
|
102
103
|
handleRemoveCustomFilter: () => void;
|
|
103
104
|
handleClearAll: () => void;
|
|
105
|
+
/** @deprecated Demo-only: it only spins for a fixed time (700 ms by default) and refetches nothing. Keep refresh state in your data layer (e.g. your query's `isFetching`). Will be removed in a future minor release. */
|
|
104
106
|
handleRefresh: () => void;
|
|
105
107
|
handleToggleRowSelection: (id: string) => void;
|
|
106
108
|
handleToggleHeaderCheck: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@undevy-org/tablewright",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "React data-table and application-shell components: filters, drawers, row controls, sortable and resizable columns, built on Radix UI and TanStack Table.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export type DemoTheme = "light" | "dark";
|
|
2
|
-
/**
|
|
3
|
-
* Theme state for story demos that render a live theme switch (e.g.
|
|
4
|
-
* SidebarAccountMenu). Callers apply the returned theme to a `data-theme`
|
|
5
|
-
* attribute on a wrapper element around their own content — this hook only
|
|
6
|
-
* owns the state and its localStorage persistence, not the DOM write.
|
|
7
|
-
*/
|
|
8
|
-
export declare function useDemoTheme(): [DemoTheme, (theme: DemoTheme) => void];
|