@bigcapitalhq/blueprintjs-react-table 0.0.0-stage → 0.3.0
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/README.md +456 -2
- package/dist/blueprintjs-react-table.cjs +6 -0
- package/dist/blueprintjs-react-table.cjs.map +1 -0
- package/dist/blueprintjs-react-table.js +2533 -0
- package/dist/blueprintjs-react-table.js.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/types/components/BP_Table.d.ts +219 -0
- package/dist/types/components/body/TableBody.d.ts +29 -0
- package/dist/types/components/body/TableBodyCell.d.ts +18 -0
- package/dist/types/components/body/TableGhostCell.d.ts +20 -0
- package/dist/types/components/body/TableGhostCells.d.ts +33 -0
- package/dist/types/components/body/TableRowHeaderCell.d.ts +19 -0
- package/dist/types/components/body/TableRowHeaders.d.ts +28 -0
- package/dist/types/components/body/TableRowSelectionCell.d.ts +18 -0
- package/dist/types/components/common/LoadableContent.d.ts +19 -0
- package/dist/types/components/common/cell-selection.d.ts +57 -0
- package/dist/types/components/common/cellCoordinates.d.ts +29 -0
- package/dist/types/components/common/classes.d.ts +108 -0
- package/dist/types/components/common/dimensions.d.ts +26 -0
- package/dist/types/components/common/menu-context.d.ts +81 -0
- package/dist/types/components/common/pinning.d.ts +44 -0
- package/dist/types/components/common/region.d.ts +89 -0
- package/dist/types/components/common/table-selection-context.d.ts +3 -0
- package/dist/types/components/container/TableContainer.d.ts +30 -0
- package/dist/types/components/head/TableColumnHeaderMenu.d.ts +9 -0
- package/dist/types/components/head/TableColumnHeaders.d.ts +12 -0
- package/dist/types/components/head/TableHead.d.ts +13 -0
- package/dist/types/components/head/TableHeadCell.d.ts +10 -0
- package/dist/types/components/head/TableMenu.d.ts +6 -0
- package/dist/types/components/head/TableRowSelectionHeaderCell.d.ts +13 -0
- package/dist/types/components/head/table-column-reorder-context.d.ts +3 -0
- package/dist/types/components/layers/TableRegionLayer.d.ts +18 -0
- package/dist/types/components/layers/TableReorderGuides.d.ts +17 -0
- package/dist/types/components/layers/TableResizeGuides.d.ts +24 -0
- package/dist/types/components/pagination/TablePaginationBar.d.ts +30 -0
- package/dist/types/components/pagination/constants.d.ts +4 -0
- package/dist/types/components/pagination/withPagination.d.ts +51 -0
- package/dist/types/components/quadrant/TableQuadrant.d.ts +48 -0
- package/dist/types/components/quadrant/TableQuadrantStack.d.ts +38 -0
- package/dist/types/components/quadrant/quadrant-type.d.ts +10 -0
- package/dist/types/hooks/use-bp-table-instance.d.ts +33 -0
- package/dist/types/hooks/use-cell-selection.d.ts +62 -0
- package/dist/types/hooks/use-column-header-height.d.ts +24 -0
- package/dist/types/hooks/use-column-reorder.d.ts +20 -0
- package/dist/types/hooks/use-freeze-pinning.d.ts +25 -0
- package/dist/types/hooks/use-ghost-cells.d.ts +43 -0
- package/dist/types/hooks/use-row-resizing.d.ts +57 -0
- package/dist/types/hooks/use-row-virtualizer.d.ts +26 -0
- package/dist/types/hooks/use-uncontrolled.d.ts +19 -0
- package/dist/types/index.d.ts +25 -0
- package/dist/types/types.d.ts +76 -0
- package/package.json +83 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { CSSProperties, MutableRefObject, UIEventHandler, WheelEventHandler } from 'react';
|
|
2
|
+
import type { BP_GhostCells } from '../../hooks/use-ghost-cells.js';
|
|
3
|
+
import type { BP_RowVirtualizer } from '../../hooks/use-row-virtualizer.js';
|
|
4
|
+
import type { RowResizingApi } from '../../hooks/use-row-resizing.js';
|
|
5
|
+
import type { BP_RowData, BP_TableInstance } from '../../types.js';
|
|
6
|
+
import { QuadrantType } from './quadrant-type.js';
|
|
7
|
+
export type TableQuadrantProps<TData extends BP_RowData> = {
|
|
8
|
+
quadrantType: QuadrantType;
|
|
9
|
+
table: BP_TableInstance<TData>;
|
|
10
|
+
rowHeaderWidth: number;
|
|
11
|
+
/** Whether to render the row headers (the row-number column) and corner menu. */
|
|
12
|
+
enableRowHeader?: boolean;
|
|
13
|
+
/** Effective (measured) height of the column-header area. */
|
|
14
|
+
columnHeaderHeight: number;
|
|
15
|
+
/** Ref used to measure the rendered column-header height (TOP quadrant only). */
|
|
16
|
+
columnHeaderMeasureRef?: MutableRefObject<HTMLDivElement | null>;
|
|
17
|
+
enableSorting?: boolean;
|
|
18
|
+
areCellsLoading: boolean;
|
|
19
|
+
areColumnHeadersLoading: boolean;
|
|
20
|
+
areRowHeadersLoading: boolean;
|
|
21
|
+
rowResizing: RowResizingApi;
|
|
22
|
+
rowVirtualizer?: BP_RowVirtualizer;
|
|
23
|
+
ghosts?: BP_GhostCells;
|
|
24
|
+
scrollContainerRef: MutableRefObject<HTMLDivElement | null>;
|
|
25
|
+
/** Only provided for the main quadrant, whose scrollbar is visible. */
|
|
26
|
+
onScroll?: UIEventHandler<HTMLDivElement>;
|
|
27
|
+
/** Provided for every non-main quadrant; forwards wheel gestures to the main quadrant. */
|
|
28
|
+
onWheel?: WheelEventHandler<HTMLDivElement>;
|
|
29
|
+
style?: CSSProperties;
|
|
30
|
+
/** Width of the row-selection checkboxes column; `0` hides the column. */
|
|
31
|
+
selectionColumnWidth?: number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* One quadrant of the table. The quadrant type determines which regions it
|
|
35
|
+
* renders:
|
|
36
|
+
*
|
|
37
|
+
* - `MAIN` renders the scrollable ("center") columns and rows. It is the only
|
|
38
|
+
* quadrant with visible scrollbars and the only one that handles keyboard
|
|
39
|
+
* focus; the other quadrants sync their scroll offsets from it.
|
|
40
|
+
* - `TOP` renders the column headers and the frozen ("top") rows.
|
|
41
|
+
* - `LEFT` renders the row headers and the frozen ("start") columns.
|
|
42
|
+
* - `TOP_LEFT` renders the corner menu, the frozen column headers, the frozen
|
|
43
|
+
* row headers, and the cells frozen in both directions.
|
|
44
|
+
*
|
|
45
|
+
* Each quadrant's content is padded with spacers so the quadrants that scroll
|
|
46
|
+
* share the main quadrant's scroll ranges.
|
|
47
|
+
*/
|
|
48
|
+
export declare function TableQuadrant<TData extends BP_RowData>({ quadrantType, table, rowHeaderWidth, enableRowHeader, columnHeaderHeight, columnHeaderMeasureRef, enableSorting, areCellsLoading, areColumnHeadersLoading, areRowHeadersLoading, rowResizing, rowVirtualizer, ghosts, scrollContainerRef, onScroll, onWheel, style, selectionColumnWidth, }: TableQuadrantProps<TData>): import("react").JSX.Element;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
import type { CellSelectionApi } from '../../hooks/use-cell-selection.js';
|
|
3
|
+
import type { RowResizingApi } from '../../hooks/use-row-resizing.js';
|
|
4
|
+
import type { BP_GhostCells } from '../../hooks/use-ghost-cells.js';
|
|
5
|
+
import type { BP_RowData, BP_TableInstance } from '../../types.js';
|
|
6
|
+
export type TableQuadrantStackProps<TData extends BP_RowData> = {
|
|
7
|
+
table: BP_TableInstance<TData>;
|
|
8
|
+
rowHeaderWidth: number;
|
|
9
|
+
/** Whether to render the row headers (the row-number column) and corner menu. */
|
|
10
|
+
enableRowHeader?: boolean;
|
|
11
|
+
/** Effective (measured) height of the column-header area. */
|
|
12
|
+
columnHeaderHeight: number;
|
|
13
|
+
/** Ref to attach to the rendered TOP quadrant's column-header area. */
|
|
14
|
+
columnHeaderMeasureRef: MutableRefObject<HTMLDivElement | null>;
|
|
15
|
+
enableColumnReordering?: boolean;
|
|
16
|
+
enableSorting?: boolean;
|
|
17
|
+
areCellsLoading: boolean;
|
|
18
|
+
areColumnHeadersLoading: boolean;
|
|
19
|
+
areRowHeadersLoading: boolean;
|
|
20
|
+
selection: CellSelectionApi;
|
|
21
|
+
rowResizing: RowResizingApi;
|
|
22
|
+
ghosts?: BP_GhostCells;
|
|
23
|
+
enableRowVirtualization?: boolean;
|
|
24
|
+
overscanRowCount?: number;
|
|
25
|
+
/** Ref to the main quadrant's scroll container (the interactive one). */
|
|
26
|
+
scrollContainerRef: MutableRefObject<HTMLDivElement | null>;
|
|
27
|
+
/** Width of the row-selection checkboxes column; `0` hides the column. */
|
|
28
|
+
selectionColumnWidth?: number;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The table's quadrant stack: four clipped quadrants (main, top, left,
|
|
32
|
+
* top-left) overlaid on top of each other. Frozen columns and rows, the column
|
|
33
|
+
* headers, and the row headers are rendered by the frozen quadrants and stay in
|
|
34
|
+
* place, while the main quadrant scrolls. The frozen quadrants' offsets follow
|
|
35
|
+
* the main quadrant's scroll position, and wheel gestures over them are
|
|
36
|
+
* forwarded to the main quadrant.
|
|
37
|
+
*/
|
|
38
|
+
export declare function TableQuadrantStack<TData extends BP_RowData>({ table, rowHeaderWidth, enableRowHeader, columnHeaderHeight, columnHeaderMeasureRef, enableColumnReordering, enableSorting, areCellsLoading, areColumnHeadersLoading, areRowHeadersLoading, selection, rowResizing, ghosts, enableRowVirtualization, overscanRowCount, scrollContainerRef, selectionColumnWidth, }: TableQuadrantStackProps<TData>): import("react").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare enum QuadrantType {
|
|
2
|
+
/** The main quadrant beneath any frozen rows or columns. */
|
|
3
|
+
MAIN = "main",
|
|
4
|
+
/** The top quadrant, containing column headers and frozen rows. */
|
|
5
|
+
TOP = "top",
|
|
6
|
+
/** The left quadrant, containing row headers and frozen columns. */
|
|
7
|
+
LEFT = "left",
|
|
8
|
+
/** The top-left quadrant, containing the headers and cells common to both the frozen columns and frozen rows. */
|
|
9
|
+
TOP_LEFT = "top-left"
|
|
10
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BP_RowData, BP_TableFeatures, BP_TableInstance, BP_TableOptions } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The feature registry `BP_Table` uses by default: column sizing/resizing,
|
|
4
|
+
* ordering, visibility, pinning, row pinning, row selection, cell selection,
|
|
5
|
+
* and sorting. It is exported so layers built on top of `BP_Table` (such as
|
|
6
|
+
* the `withPagination` HOC) can compose additional features without having to
|
|
7
|
+
* replace the defaults.
|
|
8
|
+
*
|
|
9
|
+
* Compose it with `tableFeatures()`:
|
|
10
|
+
*
|
|
11
|
+
* tableFeatures({ ...DEFAULT_BP_TABLE_FEATURES, rowPaginationFeature, paginatedRowModel: createPaginatedRowModel() })
|
|
12
|
+
*/
|
|
13
|
+
export declare const DEFAULT_BP_TABLE_FEATURES: {
|
|
14
|
+
columnSizingFeature: import("@tanstack/table-core").TableFeature;
|
|
15
|
+
columnResizingFeature: import("@tanstack/table-core").TableFeature;
|
|
16
|
+
columnOrderingFeature: import("@tanstack/table-core").TableFeature;
|
|
17
|
+
columnVisibilityFeature: import("@tanstack/table-core").TableFeature;
|
|
18
|
+
columnPinningFeature: import("@tanstack/table-core").TableFeature;
|
|
19
|
+
rowPinningFeature: import("@tanstack/table-core").TableFeature;
|
|
20
|
+
rowSelectionFeature: import("@tanstack/table-core").TableFeature;
|
|
21
|
+
cellSelectionFeature: import("@tanstack/table-core").TableFeature;
|
|
22
|
+
rowSortingFeature: import("@tanstack/table-core").TableFeature;
|
|
23
|
+
sortedRowModel: (table: import("@tanstack/table-core").Table<any, any>) => () => import("@tanstack/table-core").RowModel<any, any>;
|
|
24
|
+
sortFns: {
|
|
25
|
+
alphanumeric: import("@tanstack/table-core").CreatedSortFn<any, any>;
|
|
26
|
+
alphanumericCaseSensitive: import("@tanstack/table-core").CreatedSortFn<any, any>;
|
|
27
|
+
basic: import("@tanstack/table-core").CreatedSortFn<any, any>;
|
|
28
|
+
datetime: import("@tanstack/table-core").CreatedSortFn<any, any>;
|
|
29
|
+
text: import("@tanstack/table-core").CreatedSortFn<any, any>;
|
|
30
|
+
textCaseSensitive: import("@tanstack/table-core").CreatedSortFn<any, any>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export declare const useBPTableInstance: <TData extends BP_RowData>(definedTableOptions: BP_TableOptions<BP_TableFeatures, TData>) => BP_TableInstance<TData>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type KeyboardEvent as ReactKeyboardEvent, type MouseEvent as ReactMouseEvent, type MutableRefObject, type PointerEvent as ReactPointerEvent, type ReactElement } from 'react';
|
|
2
|
+
import type { BP_RowData, BP_TableInstance } from '../types.js';
|
|
3
|
+
import { type BP_BodyContextMenuRenderer } from '../components/common/menu-context.js';
|
|
4
|
+
import { RegionCardinality, type FocusedCellCoordinates, type FocusedRegion, type Region, type StyledRegionGroup } from '../components/common/region.js';
|
|
5
|
+
export type CellSelectionOptions<TData extends BP_RowData> = {
|
|
6
|
+
table: BP_TableInstance<TData>;
|
|
7
|
+
/** Resolved absolute top offset of the row at the given index. */
|
|
8
|
+
getRowTop: (index: number) => number;
|
|
9
|
+
/** Resolved height of the row at the given index. */
|
|
10
|
+
getRowHeight: (index: number) => number;
|
|
11
|
+
scrollContainerRef: MutableRefObject<HTMLDivElement | null>;
|
|
12
|
+
/** Width of the frozen row-header column. */
|
|
13
|
+
rowHeaderWidth: number;
|
|
14
|
+
/** Effective height of the column-header area. */
|
|
15
|
+
columnHeaderHeight: number;
|
|
16
|
+
bodyContextMenuRenderer?: BP_BodyContextMenuRenderer<TData>;
|
|
17
|
+
enableBodyContextMenu?: boolean;
|
|
18
|
+
enableFocusedCell?: boolean;
|
|
19
|
+
onFocusedCell?: (cell: FocusedCellCoordinates) => void;
|
|
20
|
+
onFocusedRegion?: (region: FocusedRegion) => void;
|
|
21
|
+
selectedRegions?: Region[] | undefined;
|
|
22
|
+
onSelection?: (regions: Region[]) => void;
|
|
23
|
+
selectionModes?: RegionCardinality[];
|
|
24
|
+
};
|
|
25
|
+
export type CellSelectionApi = {
|
|
26
|
+
/**
|
|
27
|
+
* Styled region groups for the selection overlays: the selected regions
|
|
28
|
+
* (resolved from the cell selection plugin's bounds) and, when
|
|
29
|
+
* `enableFocusedCell` is on, the focused cell.
|
|
30
|
+
*/
|
|
31
|
+
regionGroups: StyledRegionGroup[];
|
|
32
|
+
isSelectionModeEnabled: (cardinality: RegionCardinality) => boolean;
|
|
33
|
+
handleKeyDown: (event: ReactKeyboardEvent<HTMLDivElement>) => void;
|
|
34
|
+
/** Focuses the scroll container so keyboard navigation keeps working. */
|
|
35
|
+
handleBodyPointerDown: (event: ReactPointerEvent<HTMLElement>) => void;
|
|
36
|
+
handleColumnHeaderMouseDown: (index: number, event: ReactMouseEvent) => void;
|
|
37
|
+
handleRowHeaderMouseDown: (index: number, event: ReactMouseEvent) => void;
|
|
38
|
+
handleMenuMouseDown: (event: ReactMouseEvent) => void;
|
|
39
|
+
/** Whether a body context menu renderer is configured and enabled. */
|
|
40
|
+
isBodyContextMenuEnabled: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Applies Blueprint's right-click semantics before a body context menu
|
|
43
|
+
* opens: when the right-clicked cell is not part of the current selection,
|
|
44
|
+
* the selection (and the active cell) move to that cell.
|
|
45
|
+
*/
|
|
46
|
+
handleBodyContextMenu: (event: ReactMouseEvent<HTMLElement>) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Builds the menu context for the right-click event and invokes the
|
|
49
|
+
* configured body context menu renderer.
|
|
50
|
+
*/
|
|
51
|
+
renderBodyContextMenu: (event: ReactMouseEvent<HTMLElement>) => ReactElement | undefined;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Cell-range selection and focused-cell navigation built on TanStack Table's
|
|
55
|
+
* `cellSelectionFeature`. The plugin owns the selection state (drag, shift
|
|
56
|
+
* extend, Ctrl/Cmd multi-range); this hook adds the Blueprint layer on top:
|
|
57
|
+
* full-row/column/table selection from the headers and corner menu, keyboard
|
|
58
|
+
* navigation, scroll-into-view, right-click context menu semantics, and the
|
|
59
|
+
* controlled `selectedRegions` / `onSelection` props translated to and from
|
|
60
|
+
* the plugin's state.
|
|
61
|
+
*/
|
|
62
|
+
export declare function useCellSelection<TData extends BP_RowData>({ table, getRowTop, getRowHeight, scrollContainerRef, rowHeaderWidth, columnHeaderHeight, bodyContextMenuRenderer, enableBodyContextMenu, enableFocusedCell, onFocusedCell, onFocusedRegion, selectedRegions: controlledSelectedRegions, onSelection, selectionModes, }: CellSelectionOptions<TData>): CellSelectionApi;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
export type ColumnHeaderHeightOptions = {
|
|
3
|
+
/** Minimum height for the column-header area (the `columnHeaderHeight` prop). */
|
|
4
|
+
minHeight: number;
|
|
5
|
+
/** Number of header rows, used for the pre-measurement estimate. */
|
|
6
|
+
headerRowCount: number;
|
|
7
|
+
};
|
|
8
|
+
export type ColumnHeaderHeightResult = {
|
|
9
|
+
/** Attach to the rendered column-header area to measure its height. */
|
|
10
|
+
ref: MutableRefObject<HTMLDivElement | null>;
|
|
11
|
+
/** Effective height of the column-header area. */
|
|
12
|
+
height: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Resolves the effective height of the column-header area.
|
|
16
|
+
*
|
|
17
|
+
* Column headers can be taller than a single row (grouped columns render
|
|
18
|
+
* additional header rows, and custom header content can grow a row), so the
|
|
19
|
+
* rendered height is measured with a `ResizeObserver` and used as the source of
|
|
20
|
+
* truth for layout. Until the first measurement, an estimate of
|
|
21
|
+
* `headerRowCount * DEFAULT_COLUMN_HEADER_HEIGHT` keeps the layout stable, and
|
|
22
|
+
* the `minHeight` prop continues to act as a floor.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useColumnHeaderHeight({ minHeight, headerRowCount, }: ColumnHeaderHeightOptions): ColumnHeaderHeightResult;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MutableRefObject, PointerEvent as ReactPointerEvent } from 'react';
|
|
2
|
+
import type { Column } from '@tanstack/react-table';
|
|
3
|
+
import type { BP_RowData, BP_TableFeatures, BP_TableInstance } from '../types.js';
|
|
4
|
+
export type ColumnReorderStartHandler = <TData extends BP_RowData>(column: Column<BP_TableFeatures, TData>, event: ReactPointerEvent<Element>) => void;
|
|
5
|
+
export type ColumnReorderContextValue = {
|
|
6
|
+
enableColumnReordering: boolean;
|
|
7
|
+
reorderingColumnId: string | null;
|
|
8
|
+
startReorder: ColumnReorderStartHandler;
|
|
9
|
+
};
|
|
10
|
+
export declare function useColumnReorder<TData extends BP_RowData>(table: BP_TableInstance<TData>, enableColumnReordering: boolean,
|
|
11
|
+
/** Ref to the quadrant stack element; its left edge is the grid's x-origin. */
|
|
12
|
+
gridRef: MutableRefObject<HTMLDivElement | null>,
|
|
13
|
+
/** Ref to the main quadrant's scroll container (source of scroll offsets). */
|
|
14
|
+
scrollContainerRef: MutableRefObject<HTMLDivElement | null>,
|
|
15
|
+
/** Width of the frozen row-header column. */
|
|
16
|
+
rowHeaderWidth: number): {
|
|
17
|
+
contextValue: ColumnReorderContextValue;
|
|
18
|
+
guideIndex: number | null;
|
|
19
|
+
reorderingColumnId: string | null;
|
|
20
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BP_RowData, BP_TableInstance } from '../types.js';
|
|
2
|
+
export type FreezePinningOptions<TData extends BP_RowData> = {
|
|
3
|
+
table: BP_TableInstance<TData>;
|
|
4
|
+
/**
|
|
5
|
+
* Number of leftmost columns that should be frozen. The pinned column ids are
|
|
6
|
+
* derived from the table's current visible leaf columns (in natural order),
|
|
7
|
+
* so freezing stays correct across column reordering and column visibility.
|
|
8
|
+
*/
|
|
9
|
+
numFrozenColumns: number;
|
|
10
|
+
/**
|
|
11
|
+
* Number of topmost rows that should be frozen. The pinned row ids are
|
|
12
|
+
* derived from the table's current row model, so freezing follows sorting.
|
|
13
|
+
*/
|
|
14
|
+
numFrozenRows: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Derives TanStack's column/row pinning state from the `numFrozenColumns` /
|
|
18
|
+
* `numFrozenRows` props, mirroring Blueprint's frozen columns and rows.
|
|
19
|
+
*
|
|
20
|
+
* The pinning state is the source of truth for the frozen regions (see
|
|
21
|
+
* `pinning.ts`), so power users can also drive it directly through TanStack's
|
|
22
|
+
* `columnPinning` / `rowPinning` state and `column.pin()` / `row.pin()` APIs.
|
|
23
|
+
* The hook is a no-op when both counts match the current state.
|
|
24
|
+
*/
|
|
25
|
+
export declare function useFreezePinning<TData extends BP_RowData>({ table, numFrozenColumns, numFrozenRows, }: FreezePinningOptions<TData>): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Describes the empty "ghost" cells rendered beyond the table's data rows and
|
|
4
|
+
* columns when `enableGhostCells` is enabled and the content is smaller than
|
|
5
|
+
* the viewport (mirroring Blueprint's `enableGhostCells` table prop).
|
|
6
|
+
*/
|
|
7
|
+
export type BP_GhostCells = {
|
|
8
|
+
/** Number of empty columns rendered to the right of the data columns. */
|
|
9
|
+
columnCount: number;
|
|
10
|
+
/** Number of empty rows rendered below the data rows. */
|
|
11
|
+
rowCount: number;
|
|
12
|
+
/** Width of each ghost column, in pixels. */
|
|
13
|
+
columnWidth: number;
|
|
14
|
+
/** Height of each ghost row, in pixels. */
|
|
15
|
+
rowHeight: number;
|
|
16
|
+
};
|
|
17
|
+
export type GhostCellsOptions = {
|
|
18
|
+
/** Whether ghost cells are enabled on the table. */
|
|
19
|
+
enableGhostCells: boolean;
|
|
20
|
+
/** Default row height; ghost rows use this height. */
|
|
21
|
+
rowHeight: number;
|
|
22
|
+
/** Width of the row-header column, subtracted from the viewport width. */
|
|
23
|
+
rowHeaderWidth: number;
|
|
24
|
+
/** Height of the column-header rows, subtracted from the viewport height. */
|
|
25
|
+
columnHeaderHeight: number;
|
|
26
|
+
/** Total width of all visible columns combined. */
|
|
27
|
+
totalWidth: number;
|
|
28
|
+
/** Total height of all rows combined. */
|
|
29
|
+
totalHeight: number;
|
|
30
|
+
/** The table's scroll container, used to measure the visible viewport. */
|
|
31
|
+
scrollContainerRef: MutableRefObject<HTMLDivElement | null>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Measures the table's scroll container and computes the ghost cells needed to
|
|
35
|
+
* fill leftover viewport space. Returns `undefined` when ghost cells are
|
|
36
|
+
* disabled or when the content overflows (or exactly fits) both axes.
|
|
37
|
+
*/
|
|
38
|
+
export declare function useGhostCells({ enableGhostCells, rowHeight, rowHeaderWidth, columnHeaderHeight, totalWidth, totalHeight, scrollContainerRef, }: GhostCellsOptions): BP_GhostCells | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Total width of the table's column area including ghost columns. Used to size
|
|
41
|
+
* the column-header rows so ghost header cells fit next to the data columns.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getGhostedTableWidth(totalWidth: number, ghosts?: BP_GhostCells): number;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { MouseEvent as ReactMouseEvent, TouchEvent as ReactTouchEvent } from 'react';
|
|
2
|
+
/** Minimum height a row can be resized to (mirrors Blueprint's MIN_ROW_HEIGHT). */
|
|
3
|
+
export declare const DEFAULT_MIN_ROW_HEIGHT = 6;
|
|
4
|
+
/** Maximum height a row can be resized to (mirrors Blueprint's MAX_ROW_HEIGHT). */
|
|
5
|
+
export declare const DEFAULT_MAX_ROW_HEIGHT = 100;
|
|
6
|
+
/** Event types emitted by the row header resize handle. */
|
|
7
|
+
export type RowResizeStartEvent = ReactMouseEvent<Element> | ReactTouchEvent<Element>;
|
|
8
|
+
/** Handler invoked when a resize drag starts from a row header's resize handle. */
|
|
9
|
+
export type RowResizeStartHandler = (index: number, event: RowResizeStartEvent) => void;
|
|
10
|
+
export type RowResizingOptions = {
|
|
11
|
+
/** Default height for rows that don't have an explicit height. */
|
|
12
|
+
rowHeight: number;
|
|
13
|
+
/** Number of rows in the table. */
|
|
14
|
+
rowCount: number;
|
|
15
|
+
/**
|
|
16
|
+
* Controlled per-row heights, indexed by row index. When provided, the
|
|
17
|
+
* table's row heights are fully owned by the caller, who updates them via
|
|
18
|
+
* `onRowHeightChanged`. Entries of `undefined` fall back to `rowHeight`.
|
|
19
|
+
*/
|
|
20
|
+
rowHeights?: Array<number | undefined>;
|
|
21
|
+
/** Initial per-row heights for the uncontrolled mode. */
|
|
22
|
+
defaultRowHeights?: Array<number | undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* If `true`, rows can be resized by dragging the horizontal handle at the
|
|
25
|
+
* bottom of each row header.
|
|
26
|
+
*
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
enableRowResizing?: boolean;
|
|
30
|
+
/** Minimum height a row can be resized to. @default 6 */
|
|
31
|
+
minRowHeight?: number;
|
|
32
|
+
/** Maximum height a row can be resized to. @default 100 */
|
|
33
|
+
maxRowHeight?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Listener invoked whenever a row's height changes. Fires continuously
|
|
36
|
+
* during a resize drag (and once more when it ends), in both the controlled
|
|
37
|
+
* and uncontrolled modes.
|
|
38
|
+
*/
|
|
39
|
+
onRowHeightChanged?: (index: number, height: number) => void;
|
|
40
|
+
};
|
|
41
|
+
export type RowResizingApi = {
|
|
42
|
+
/** Whether row resizing is enabled. */
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
/** Resolved height of the row at `index`. */
|
|
45
|
+
getRowHeight: (index: number) => number;
|
|
46
|
+
/** Resolved absolute top offset of the row at `index` within the body. */
|
|
47
|
+
getRowTop: (index: number) => number;
|
|
48
|
+
/** Total height of all rows combined. */
|
|
49
|
+
totalHeight: number;
|
|
50
|
+
/** Index of the row currently being resized, or `null`. */
|
|
51
|
+
resizingRowIndex: number | null;
|
|
52
|
+
/** Absolute top of the horizontal resize guide while resizing, or `null`. */
|
|
53
|
+
resizingGuideTop: number | null;
|
|
54
|
+
/** Begins resizing the row at `index`. Wire to the row header resize handle. */
|
|
55
|
+
startRowResize: RowResizeStartHandler;
|
|
56
|
+
};
|
|
57
|
+
export declare function useRowResizing({ rowHeight, rowCount, rowHeights, defaultRowHeights, enableRowResizing, minRowHeight, maxRowHeight, onRowHeightChanged, }: RowResizingOptions): RowResizingApi;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Virtualizer } from '@tanstack/react-virtual';
|
|
2
|
+
import { type MutableRefObject } from 'react';
|
|
3
|
+
import type { BP_RowData, BP_TableInstance } from '../types.js';
|
|
4
|
+
export declare const DEFAULT_OVERSCAN_ROW_COUNT = 5;
|
|
5
|
+
export type BP_RowVirtualizer = Virtualizer<HTMLDivElement, HTMLDivElement>;
|
|
6
|
+
export type RowVirtualizerOptions<TData extends BP_RowData> = {
|
|
7
|
+
table: BP_TableInstance<TData>;
|
|
8
|
+
/** Effective height of the column-header area above the scrollable body. */
|
|
9
|
+
columnHeaderHeight: number;
|
|
10
|
+
/** Number of frozen rows rendered above the scrollable body. */
|
|
11
|
+
frozenRowCount: number;
|
|
12
|
+
/** Resolved height of the frozen rows rendered above the scrollable body. */
|
|
13
|
+
frozenRowsHeight: number;
|
|
14
|
+
/** Resolved height of the row at the given absolute index (used to estimate item sizes). */
|
|
15
|
+
getRowHeight: (index: number) => number;
|
|
16
|
+
scrollContainerRef: MutableRefObject<HTMLDivElement | null>;
|
|
17
|
+
enableRowVirtualization: boolean;
|
|
18
|
+
overscanRowCount: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Virtualizes the scrollable ("center") rows only. Frozen rows are always
|
|
22
|
+
* rendered (they are expected to be few) and are excluded from the virtualizer,
|
|
23
|
+
* so virtual item indices are offsets into the center rows; callers map them to
|
|
24
|
+
* absolute row indices with `getFrozenRowCount`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function useRowVirtualizer<TData extends BP_RowData>({ table, columnHeaderHeight, frozenRowCount, frozenRowsHeight, getRowHeight, scrollContainerRef, enableRowVirtualization, overscanRowCount, }: RowVirtualizerOptions<TData>): BP_RowVirtualizer | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type UseUncontrolledInput<T> = {
|
|
2
|
+
/** Value for controlled state. */
|
|
3
|
+
value?: T;
|
|
4
|
+
/** Initial value for uncontrolled state. */
|
|
5
|
+
initialValue?: T;
|
|
6
|
+
/** Final value for uncontrolled state when value and initialValue are not provided. */
|
|
7
|
+
finalValue?: T;
|
|
8
|
+
/** Controlled state onChange handler. */
|
|
9
|
+
onChange?: (value: T) => void;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Owns a piece of state that can be driven either by the caller (controlled) or
|
|
13
|
+
* by the component itself (uncontrolled), mirroring the common React
|
|
14
|
+
* controlled/uncontrolled convention.
|
|
15
|
+
*
|
|
16
|
+
* Returns the resolved value, a setter that notifies `onChange` in both modes,
|
|
17
|
+
* and whether the state is currently controlled (`value` was provided).
|
|
18
|
+
*/
|
|
19
|
+
export declare function useUncontrolled<T>({ value, initialValue, finalValue, onChange, }: UseUncontrolledInput<T>): [T, (value: T) => void, boolean];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public entry point for the `blueprintjs-react-table` package.
|
|
3
|
+
*
|
|
4
|
+
* Exports the `BP_Table` component and all public types used in its props,
|
|
5
|
+
* the `withPagination` HOC that layers row pagination on top of `BP_Table`,
|
|
6
|
+
* as well as the region / focus / selection types used by the focus and
|
|
7
|
+
* selection APIs.
|
|
8
|
+
*
|
|
9
|
+
* Importing the component does not inject any CSS. Include the compiled
|
|
10
|
+
* stylesheet once in your app:
|
|
11
|
+
*
|
|
12
|
+
* import 'blueprintjs-react-table/styles.css';
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export { BP_Table } from './components/BP_Table.js';
|
|
16
|
+
export type { BP_TableProps } from './components/BP_Table.js';
|
|
17
|
+
export { withPagination } from './components/pagination/withPagination.js';
|
|
18
|
+
export type { BP_PaginatedTableProps, BP_PaginationOptions, } from './components/pagination/withPagination.js';
|
|
19
|
+
export { TablePaginationBar } from './components/pagination/TablePaginationBar.js';
|
|
20
|
+
export type { TablePaginationBarProps } from './components/pagination/TablePaginationBar.js';
|
|
21
|
+
export { DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, } from './components/pagination/constants.js';
|
|
22
|
+
export { DEFAULT_BP_TABLE_FEATURES } from './hooks/use-bp-table-instance.js';
|
|
23
|
+
export type { BP_BodyContextMenuRenderer, BP_MenuContext, } from './components/common/menu-context.js';
|
|
24
|
+
export * from './types.js';
|
|
25
|
+
export * from './components/common/region.js';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type HTMLProps, type MutableRefObject } from 'react';
|
|
2
|
+
import { ColumnPinningState, ColumnVisibilityState, RowData, RowPinningState, RowSelectionState, TableFeatures, TableOptions, TableState, ReactTable, type CellData } from '@tanstack/react-table';
|
|
3
|
+
declare module '@tanstack/react-table' {
|
|
4
|
+
/**
|
|
5
|
+
* Extra metadata supported on column definitions, applied by `BP_Table` when
|
|
6
|
+
* rendering the table's cells.
|
|
7
|
+
*/
|
|
8
|
+
interface ColumnMeta<in out TFeatures extends TableFeatures, in out TData extends RowData, TValue extends CellData = CellData> {
|
|
9
|
+
/**
|
|
10
|
+
* Additional class name(s) applied to this column's body cells, e.g.
|
|
11
|
+
* `meta: { bodyCellClassName: 'my-cell' }`. Useful for styling cell
|
|
12
|
+
* contents (centering editors, removing cell padding, and so on).
|
|
13
|
+
*/
|
|
14
|
+
bodyCellClassName?: string;
|
|
15
|
+
/** Additional class name(s) applied to this column's header cells. */
|
|
16
|
+
headCellClassName?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Additional class name(s) applied to this column's footer cells.
|
|
19
|
+
* Reserved for forward compatibility: the table does not render footers
|
|
20
|
+
* yet, so this option currently has no effect.
|
|
21
|
+
*/
|
|
22
|
+
footerCellClassName?: string;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export type LiteralUnion<T extends U, U = string> = (Record<never, never> & U) | T;
|
|
26
|
+
export type Prettify<T> = {
|
|
27
|
+
[K in keyof T]: T[K];
|
|
28
|
+
} & unknown;
|
|
29
|
+
export type Xor<A, B> = Prettify<{
|
|
30
|
+
[k in keyof A]?: never;
|
|
31
|
+
} & B> | Prettify<{
|
|
32
|
+
[k in keyof B]?: never;
|
|
33
|
+
} & A>;
|
|
34
|
+
/**
|
|
35
|
+
* Standard HTML attributes accepted for the table's outer container element:
|
|
36
|
+
* React's `HTMLProps`, minus a handful of attributes reserved by the table API,
|
|
37
|
+
* plus a `ref` to the container element.
|
|
38
|
+
*/
|
|
39
|
+
export type HTMLPropsRef<T extends HTMLElement> = {
|
|
40
|
+
ref?: MutableRefObject<null | T> | null;
|
|
41
|
+
} & Omit<HTMLProps<T>, 'color' | 'data' | 'label' | 'ref' | 'size' | 'style' | 'type'>;
|
|
42
|
+
export type BP_DensityState = 'lg' | 'md' | 'sm' | 'xl' | 'xs';
|
|
43
|
+
export type BP_RowData<T = unknown> = Record<string, T>;
|
|
44
|
+
/**
|
|
45
|
+
* Loading options that can be passed to the table to render skeleton
|
|
46
|
+
* placeholders in the corresponding table regions.
|
|
47
|
+
*/
|
|
48
|
+
export declare enum TableLoadingOption {
|
|
49
|
+
CELLS = "cells",
|
|
50
|
+
COLUMN_HEADERS = "column-header",
|
|
51
|
+
ROW_HEADERS = "row-header"
|
|
52
|
+
}
|
|
53
|
+
/** Returns true if the supplied loading option is present in the given array. */
|
|
54
|
+
export declare function hasLoadingOption<T extends string>(loadingOptions: readonly T[], loadingOption: T): boolean;
|
|
55
|
+
/** Which regions of the table are currently showing a loading placeholder. */
|
|
56
|
+
export type TableLoading = {
|
|
57
|
+
areCellsLoading: boolean;
|
|
58
|
+
areColumnHeadersLoading: boolean;
|
|
59
|
+
areRowHeadersLoading: boolean;
|
|
60
|
+
};
|
|
61
|
+
export type BP_CellValue = unknown;
|
|
62
|
+
export type BP_DefinedTableOptions<TFeatures extends TableFeatures, TData extends RowData> = Omit<TableOptions<TFeatures, TData>, 'features'>;
|
|
63
|
+
export type BP_TableOptions<TFeatures extends TableFeatures, TData extends RowData> = BP_DefinedTableOptions<TFeatures, TData> & {
|
|
64
|
+
features?: TableFeatures;
|
|
65
|
+
};
|
|
66
|
+
export type BP_TableFeatures = TableFeatures;
|
|
67
|
+
export type BP_TableState = TableState<BP_TableFeatures>;
|
|
68
|
+
/** Maps column ids to their visibility (`true` = visible, `false` = hidden). */
|
|
69
|
+
export type BP_VisibilityState = ColumnVisibilityState;
|
|
70
|
+
/** Maps frozen ("start") and right-pinned ("end") column ids. */
|
|
71
|
+
export type BP_ColumnPinningState = ColumnPinningState;
|
|
72
|
+
/** Maps frozen ("top") and bottom-pinned ("bottom") row ids. */
|
|
73
|
+
export type BP_RowPinningState = RowPinningState;
|
|
74
|
+
/** Maps row ids to their selection (`true` = selected), driven by the row-selection checkboxes. */
|
|
75
|
+
export type BP_RowSelectionState = RowSelectionState;
|
|
76
|
+
export type BP_TableInstance<TData extends BP_RowData = BP_RowData> = ReactTable<BP_TableFeatures, TData>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,85 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigcapitalhq/blueprintjs-react-table",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "A Blueprint.js-styled data table for React, built on TanStack Table v9 with row virtualization, quadrant layout, and Blueprint-style focus & selection.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/blueprintjs-react-table.cjs",
|
|
7
|
+
"module": "./dist/blueprintjs-react-table.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"private": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/types/index.d.ts",
|
|
13
|
+
"import": "./dist/blueprintjs-react-table.js",
|
|
14
|
+
"require": "./dist/blueprintjs-react-table.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./styles.css": "./dist/styles.css",
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": [
|
|
26
|
+
"**/*.css"
|
|
27
|
+
],
|
|
28
|
+
"keywords": [
|
|
29
|
+
"react",
|
|
30
|
+
"table",
|
|
31
|
+
"blueprint",
|
|
32
|
+
"blueprintjs",
|
|
33
|
+
"tanstack-table",
|
|
34
|
+
"datagrid",
|
|
35
|
+
"virtualized",
|
|
36
|
+
"typescript"
|
|
37
|
+
],
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/bigcapitalhq/blueprintjs-tanstack-table.git"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"dev": "vite",
|
|
44
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && vite build --config vite.lib.config.ts --emptyOutDir false && node scripts/fix-dts.mjs",
|
|
45
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
46
|
+
"preview": "vite preview",
|
|
47
|
+
"storybook": "storybook dev -p 6006",
|
|
48
|
+
"build-storybook": "storybook build",
|
|
49
|
+
"prepublishOnly": "npm run build"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"classnames": "^2.5.1"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@blueprintjs/core": "^6.18.0",
|
|
56
|
+
"@blueprintjs/icons": "^6.13.0",
|
|
57
|
+
"@tanstack/react-table": "^9.0.0",
|
|
58
|
+
"@tanstack/react-virtual": "^3.14.9",
|
|
59
|
+
"react": "^18.2.0",
|
|
60
|
+
"react-dom": "^18.2.0"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@blueprintjs/core": "^6.18.0",
|
|
64
|
+
"@blueprintjs/icons": "^6.13.0",
|
|
65
|
+
"@storybook/addon-essentials": "^8.6.18",
|
|
66
|
+
"@storybook/react-vite": "^8.6.18",
|
|
67
|
+
"@tanstack/react-table": "^9.0.0",
|
|
68
|
+
"@tanstack/react-virtual": "^3.14.9",
|
|
69
|
+
"@types/react": "^18.2.55",
|
|
70
|
+
"@types/react-dom": "^18.2.19",
|
|
71
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
72
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
73
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
74
|
+
"eslint": "^8.56.0",
|
|
75
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
76
|
+
"eslint-plugin-react-refresh": "^0.4.5",
|
|
77
|
+
"eslint-plugin-storybook": "^0.11.6",
|
|
78
|
+
"react": "^18.2.0",
|
|
79
|
+
"react-dom": "^18.2.0",
|
|
80
|
+
"sass": "^1.102.0",
|
|
81
|
+
"storybook": "^8.6.18",
|
|
82
|
+
"typescript": "^5.2.2",
|
|
83
|
+
"vite": "^5.1.0"
|
|
84
|
+
}
|
|
85
|
+
}
|