@bigpixelrocket/uiok 0.0.0-stage → 0.1.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/CHANGELOG.md +38 -0
- package/LICENSE +21 -0
- package/NOTICE +569 -0
- package/README.md +44 -2
- package/dist/VisuallyHidden.d.ts +13 -0
- package/dist/VisuallyHidden.js +13 -0
- package/dist/activity/ActivityBar.d.ts +29 -0
- package/dist/activity/ActivityBar.js +21 -0
- package/dist/activity/activity.css +43 -0
- package/dist/activity/index.d.ts +2 -0
- package/dist/activity/index.js +2 -0
- package/dist/button/Button.d.ts +26 -0
- package/dist/button/Button.js +14 -0
- package/dist/button/IconButton.d.ts +18 -0
- package/dist/button/IconButton.js +14 -0
- package/dist/button/button.css +95 -0
- package/dist/button/index.d.ts +3 -0
- package/dist/button/index.js +3 -0
- package/dist/charts/Drawing.d.ts +27 -0
- package/dist/charts/Drawing.js +117 -0
- package/dist/charts/Drawing.logic.d.ts +2 -0
- package/dist/charts/Drawing.logic.js +22 -0
- package/dist/charts/Line.logic.d.ts +33 -0
- package/dist/charts/Line.logic.js +72 -0
- package/dist/charts/LineChart.d.ts +34 -0
- package/dist/charts/LineChart.js +100 -0
- package/dist/charts/Pie.logic.d.ts +16 -0
- package/dist/charts/Pie.logic.js +28 -0
- package/dist/charts/PieChart.d.ts +20 -0
- package/dist/charts/PieChart.js +16 -0
- package/dist/charts/ResultChart.d.ts +47 -0
- package/dist/charts/ResultChart.js +175 -0
- package/dist/charts/ResultChart.logic.d.ts +42 -0
- package/dist/charts/ResultChart.logic.js +165 -0
- package/dist/charts/Scatter.logic.d.ts +55 -0
- package/dist/charts/Scatter.logic.js +134 -0
- package/dist/charts/ScatterChart.d.ts +36 -0
- package/dist/charts/ScatterChart.js +99 -0
- package/dist/charts/charts.css +310 -0
- package/dist/charts/index.d.ts +14 -0
- package/dist/charts/index.js +11 -0
- package/dist/charts/seriesColour.d.ts +2 -0
- package/dist/charts/seriesColour.js +8 -0
- package/dist/clock/index.d.ts +2 -0
- package/dist/clock/index.js +2 -0
- package/dist/clock/useClock.d.ts +14 -0
- package/dist/clock/useClock.js +57 -0
- package/dist/datetime/DateTimePicker.d.ts +50 -0
- package/dist/datetime/DateTimePicker.js +98 -0
- package/dist/datetime/DateTimePicker.logic.d.ts +59 -0
- package/dist/datetime/DateTimePicker.logic.js +103 -0
- package/dist/datetime/datetime.css +115 -0
- package/dist/datetime/index.d.ts +7 -0
- package/dist/datetime/index.js +7 -0
- package/dist/dialog/ConfirmDialog.d.ts +73 -0
- package/dist/dialog/ConfirmDialog.js +30 -0
- package/dist/dialog/DialogLegend.d.ts +21 -0
- package/dist/dialog/DialogLegend.js +28 -0
- package/dist/dialog/DialogLegend.logic.d.ts +145 -0
- package/dist/dialog/DialogLegend.logic.js +71 -0
- package/dist/dialog/ModalDialog.d.ts +101 -0
- package/dist/dialog/ModalDialog.js +184 -0
- package/dist/dialog/dialog.css +283 -0
- package/dist/dialog/index.d.ts +8 -0
- package/dist/dialog/index.js +8 -0
- package/dist/filter/FilterEscape.d.ts +16 -0
- package/dist/filter/FilterEscape.js +15 -0
- package/dist/filter/FilterIcon.d.ts +8 -0
- package/dist/filter/FilterIcon.js +11 -0
- package/dist/filter/filter.css +42 -0
- package/dist/filter/index.d.ts +3 -0
- package/dist/filter/index.js +3 -0
- package/dist/grid/DataGrid.d.ts +149 -0
- package/dist/grid/DataGrid.js +373 -0
- package/dist/grid/DataGrid.logic.d.ts +57 -0
- package/dist/grid/DataGrid.logic.js +121 -0
- package/dist/grid/grid.css +206 -0
- package/dist/grid/index.d.ts +7 -0
- package/dist/grid/index.js +7 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +32 -0
- package/dist/keyboard/BrowserKeys.d.ts +15 -0
- package/dist/keyboard/BrowserKeys.js +28 -0
- package/dist/keyboard/KeyChord.logic.d.ts +25 -0
- package/dist/keyboard/KeyChord.logic.js +50 -0
- package/dist/keyboard/Keyboard.logic.d.ts +84 -0
- package/dist/keyboard/Keyboard.logic.js +137 -0
- package/dist/keyboard/OverlayWatch.d.ts +28 -0
- package/dist/keyboard/OverlayWatch.js +119 -0
- package/dist/keyboard/PageSelectAll.d.ts +14 -0
- package/dist/keyboard/PageSelectAll.js +22 -0
- package/dist/keyboard/index.d.ts +9 -0
- package/dist/keyboard/index.js +9 -0
- package/dist/keychord/KeyChord.d.ts +16 -0
- package/dist/keychord/KeyChord.js +55 -0
- package/dist/keychord/index.d.ts +2 -0
- package/dist/keychord/index.js +2 -0
- package/dist/keychord/keychord.css +41 -0
- package/dist/labels/UiokLabels.d.ts +41 -0
- package/dist/labels/UiokLabels.js +31 -0
- package/dist/labels/UiokProvider.d.ts +44 -0
- package/dist/labels/UiokProvider.js +54 -0
- package/dist/labels/charts.d.ts +34 -0
- package/dist/labels/charts.js +15 -0
- package/dist/labels/dateTime.d.ts +32 -0
- package/dist/labels/dateTime.js +14 -0
- package/dist/labels/dialog.d.ts +18 -0
- package/dist/labels/dialog.js +6 -0
- package/dist/labels/index.d.ts +13 -0
- package/dist/labels/index.js +13 -0
- package/dist/labels/keys.d.ts +28 -0
- package/dist/labels/keys.js +53 -0
- package/dist/labels/legend.d.ts +21 -0
- package/dist/labels/legend.js +7 -0
- package/dist/labels/listing.d.ts +16 -0
- package/dist/labels/listing.js +8 -0
- package/dist/labels/pager.d.ts +32 -0
- package/dist/labels/pager.js +20 -0
- package/dist/labels/palette.d.ts +17 -0
- package/dist/labels/palette.js +6 -0
- package/dist/labels/selectAll.d.ts +15 -0
- package/dist/labels/selectAll.js +6 -0
- package/dist/labels/terminal.d.ts +25 -0
- package/dist/labels/terminal.js +9 -0
- package/dist/legend/KeyLegend.logic.d.ts +84 -0
- package/dist/legend/KeyLegend.logic.js +109 -0
- package/dist/legend/KeyLegendStrip.d.ts +36 -0
- package/dist/legend/KeyLegendStrip.js +82 -0
- package/dist/legend/index.d.ts +3 -0
- package/dist/legend/index.js +3 -0
- package/dist/legend/legend.css +148 -0
- package/dist/listing/CurrentDot.d.ts +15 -0
- package/dist/listing/CurrentDot.js +13 -0
- package/dist/listing/Listing.d.ts +230 -0
- package/dist/listing/Listing.js +265 -0
- package/dist/listing/PathParts.logic.d.ts +17 -0
- package/dist/listing/PathParts.logic.js +18 -0
- package/dist/listing/index.d.ts +10 -0
- package/dist/listing/index.js +10 -0
- package/dist/listing/listing.css +867 -0
- package/dist/menu/MenuQuery.logic.d.ts +69 -0
- package/dist/menu/MenuQuery.logic.js +75 -0
- package/dist/menu/fuzzyMatch.d.ts +31 -0
- package/dist/menu/fuzzyMatch.js +296 -0
- package/dist/menu/index.d.ts +9 -0
- package/dist/menu/index.js +9 -0
- package/dist/menu/menu.css +203 -0
- package/dist/menu/useBellBeat.d.ts +8 -0
- package/dist/menu/useBellBeat.js +26 -0
- package/dist/namecut/NameCut.d.ts +22 -0
- package/dist/namecut/NameCut.js +28 -0
- package/dist/namecut/NameCut.logic.d.ts +51 -0
- package/dist/namecut/NameCut.logic.js +120 -0
- package/dist/namecut/index.d.ts +3 -0
- package/dist/namecut/index.js +3 -0
- package/dist/namecut/namecut.css +67 -0
- package/dist/pager/Pager.d.ts +37 -0
- package/dist/pager/Pager.js +38 -0
- package/dist/pager/Pager.logic.d.ts +13 -0
- package/dist/pager/Pager.logic.js +63 -0
- package/dist/pager/index.d.ts +7 -0
- package/dist/pager/index.js +7 -0
- package/dist/pager/pager.css +62 -0
- package/dist/palette/Palette.d.ts +79 -0
- package/dist/palette/Palette.js +60 -0
- package/dist/palette/index.d.ts +6 -0
- package/dist/palette/index.js +6 -0
- package/dist/palette/palette.css +159 -0
- package/dist/pane/PaneActions.d.ts +104 -0
- package/dist/pane/PaneActions.js +62 -0
- package/dist/pane/PaneFrame.d.ts +51 -0
- package/dist/pane/PaneFrame.js +28 -0
- package/dist/pane/PaneKeys.d.ts +41 -0
- package/dist/pane/PaneKeys.js +104 -0
- package/dist/pane/PaneKeys.logic.d.ts +95 -0
- package/dist/pane/PaneKeys.logic.js +109 -0
- package/dist/pane/index.d.ts +11 -0
- package/dist/pane/index.js +11 -0
- package/dist/pane/usePaneKeys.d.ts +141 -0
- package/dist/pane/usePaneKeys.js +313 -0
- package/dist/run/RunHeader.d.ts +50 -0
- package/dist/run/RunHeader.js +31 -0
- package/dist/run/RunProgress.logic.d.ts +29 -0
- package/dist/run/RunProgress.logic.js +34 -0
- package/dist/run/index.d.ts +3 -0
- package/dist/run/index.js +3 -0
- package/dist/run/run.css +190 -0
- package/dist/segmented/SegmentedChoice.d.ts +22 -0
- package/dist/segmented/SegmentedChoice.js +31 -0
- package/dist/segmented/index.d.ts +2 -0
- package/dist/segmented/index.js +2 -0
- package/dist/segmented/segmented.css +49 -0
- package/dist/selectall/CheckRange.logic.d.ts +8 -0
- package/dist/selectall/CheckRange.logic.js +23 -0
- package/dist/selectall/SelectAllBar.d.ts +25 -0
- package/dist/selectall/SelectAllBar.js +24 -0
- package/dist/selectall/index.d.ts +7 -0
- package/dist/selectall/index.js +7 -0
- package/dist/selectall/selectall.css +31 -0
- package/dist/store/KeepUnchanged.logic.d.ts +19 -0
- package/dist/store/KeepUnchanged.logic.js +33 -0
- package/dist/store/SameProps.d.ts +15 -0
- package/dist/store/SameProps.js +46 -0
- package/dist/store/ValueStore.d.ts +17 -0
- package/dist/store/ValueStore.js +23 -0
- package/dist/store/index.d.ts +8 -0
- package/dist/store/index.js +8 -0
- package/dist/store/useStableHandlers.d.ts +13 -0
- package/dist/store/useStableHandlers.js +22 -0
- package/dist/styles.css +85 -0
- package/dist/tabs/PageTabs.d.ts +38 -0
- package/dist/tabs/PageTabs.js +33 -0
- package/dist/tabs/index.d.ts +2 -0
- package/dist/tabs/index.js +2 -0
- package/dist/tabs/tabs.css +64 -0
- package/dist/terminal/Terminal.d.ts +104 -0
- package/dist/terminal/Terminal.js +309 -0
- package/dist/terminal/Terminal.logic.d.ts +66 -0
- package/dist/terminal/Terminal.logic.js +156 -0
- package/dist/terminal/TerminalMenu.d.ts +36 -0
- package/dist/terminal/TerminalMenu.js +87 -0
- package/dist/terminal/TerminalMenu.logic.d.ts +78 -0
- package/dist/terminal/TerminalMenu.logic.js +68 -0
- package/dist/terminal/TerminalScrollback.d.ts +10 -0
- package/dist/terminal/TerminalScrollback.js +11 -0
- package/dist/terminal/ghostty/LICENSE +21 -0
- package/dist/terminal/ghostty/core.d.ts +315 -0
- package/dist/terminal/ghostty/core.js +1189 -0
- package/dist/terminal/ghostty/fallbackColors.d.ts +12 -0
- package/dist/terminal/ghostty/fallbackColors.js +23 -0
- package/dist/terminal/ghostty/fonts/LICENSE +21 -0
- package/dist/terminal/ghostty/fonts/SymbolsNerdFontMono-Regular.woff2 +0 -0
- package/dist/terminal/ghostty/keyCodes.logic.d.ts +20 -0
- package/dist/terminal/ghostty/keyCodes.logic.js +249 -0
- package/dist/terminal/ghostty/links.logic.d.ts +39 -0
- package/dist/terminal/ghostty/links.logic.js +84 -0
- package/dist/terminal/ghostty/renderer.d.ts +98 -0
- package/dist/terminal/ghostty/renderer.js +481 -0
- package/dist/terminal/ghostty/runtime.d.ts +126 -0
- package/dist/terminal/ghostty/runtime.js +346 -0
- package/dist/terminal/ghostty/spriteGlyphs.logic.d.ts +64 -0
- package/dist/terminal/ghostty/spriteGlyphs.logic.js +546 -0
- package/dist/terminal/ghostty/surface.d.ts +285 -0
- package/dist/terminal/ghostty/surface.js +1565 -0
- package/dist/terminal/ghostty/surface.logic.d.ts +181 -0
- package/dist/terminal/ghostty/surface.logic.js +392 -0
- package/dist/terminal/ghostty/vendor/LICENSE +21 -0
- package/dist/terminal/ghostty/vendor/ghostty-effects.wasm +0 -0
- package/dist/terminal/ghostty/vendor/ghostty-vt.wasm +0 -0
- package/dist/terminal/index.d.ts +12 -0
- package/dist/terminal/index.js +12 -0
- package/dist/terminal/terminal.css +169 -0
- package/dist/text/MarkedText.d.ts +14 -0
- package/dist/text/MarkedText.js +11 -0
- package/dist/text/highlightSegments.d.ts +13 -0
- package/dist/text/highlightSegments.js +29 -0
- package/dist/text/index.d.ts +3 -0
- package/dist/text/index.js +3 -0
- package/dist/text/text.css +11 -0
- package/dist/themes/attributes.d.ts +21 -0
- package/dist/themes/attributes.js +41 -0
- package/dist/themes/catalog.d.ts +125 -0
- package/dist/themes/catalog.js +940 -0
- package/dist/themes/color.d.ts +29 -0
- package/dist/themes/color.js +52 -0
- package/dist/themes/ids.d.ts +139 -0
- package/dist/themes/ids.js +59 -0
- package/dist/themes/index.d.ts +12 -0
- package/dist/themes/index.js +12 -0
- package/dist/themes/themes.generated.css +1830 -0
- package/dist/themes/tokens.d.ts +189 -0
- package/dist/themes/tokens.js +462 -0
- package/dist/tooltip/Tooltip.d.ts +21 -0
- package/dist/tooltip/Tooltip.js +105 -0
- package/dist/tooltip/Tooltip.logic.d.ts +49 -0
- package/dist/tooltip/Tooltip.logic.js +50 -0
- package/dist/tooltip/index.d.ts +3 -0
- package/dist/tooltip/index.js +3 -0
- package/dist/tooltip/tooltip.css +45 -0
- package/package.json +91 -4
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
/** A column of the grid. */
|
|
3
|
+
export interface DataGridColumn {
|
|
4
|
+
/** The header's words, which also size the column's first width. */
|
|
5
|
+
readonly label: string;
|
|
6
|
+
/** What hovering the header says, beyond the label (a column's type). */
|
|
7
|
+
readonly tip?: string;
|
|
8
|
+
/** Numbers read right-aligned. */
|
|
9
|
+
readonly align?: 'right';
|
|
10
|
+
/** Names the column across reorders, so its width follows it; its index when absent. */
|
|
11
|
+
readonly id?: string;
|
|
12
|
+
}
|
|
13
|
+
/** The column a grid is sorted by, and which way. */
|
|
14
|
+
export interface DataGridSort {
|
|
15
|
+
/** The column's index in `columns`. */
|
|
16
|
+
readonly column: number;
|
|
17
|
+
/** Which way it sorts, as `aria-sort` names it. */
|
|
18
|
+
readonly direction: 'ascending' | 'descending';
|
|
19
|
+
}
|
|
20
|
+
/** A column's place in a sort of several columns, which its header numbers. */
|
|
21
|
+
export interface DataGridSortMark extends DataGridSort {
|
|
22
|
+
/** Its place in the sort, from 1; shown only while several columns sort. */
|
|
23
|
+
readonly position: number;
|
|
24
|
+
}
|
|
25
|
+
/** What a header click adds to a sort: Shift adds the column, Option or Control takes it out. */
|
|
26
|
+
export interface DataGridSortClick {
|
|
27
|
+
/** Shift without Option: add the column to the sort rather than sort by it alone. */
|
|
28
|
+
readonly add: boolean;
|
|
29
|
+
/** Option or Control: take the column out of the sort. */
|
|
30
|
+
readonly remove: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* What a cell shows: its text, a class for its look, and what hovering it
|
|
34
|
+
* says. `className` and `content` are the hooks for values the grid knows
|
|
35
|
+
* nothing about: a missing value drawn apart from the text, bytes shown by
|
|
36
|
+
* their size, a value edited but not saved yet (`cell-edited`, which the
|
|
37
|
+
* grid's stylesheet washes in the warning colour).
|
|
38
|
+
*/
|
|
39
|
+
export interface DataGridCell {
|
|
40
|
+
/** The cell's text: what it draws, and what its accessible name reads. */
|
|
41
|
+
readonly text: string;
|
|
42
|
+
/** Classes added to the cell, for a look of the caller's own. */
|
|
43
|
+
readonly className?: string;
|
|
44
|
+
/** What hovering the cell says, also its accessible description. */
|
|
45
|
+
readonly tip?: string;
|
|
46
|
+
/** Makes the cell's text a link that runs this (a linked record, a download); Return runs it too. */
|
|
47
|
+
readonly onOpen?: () => void;
|
|
48
|
+
/**
|
|
49
|
+
* What the cell draws in place of its text (a link, an image, coloured
|
|
50
|
+
* code); `text` stays what the cell's name reads. A cell with `content`
|
|
51
|
+
* draws no link of its own.
|
|
52
|
+
*/
|
|
53
|
+
readonly content?: ReactNode;
|
|
54
|
+
}
|
|
55
|
+
/** The editor a caller draws over one cell while it edits it inline. */
|
|
56
|
+
export interface DataGridEditor {
|
|
57
|
+
/** The edited cell's row. */
|
|
58
|
+
readonly row: number;
|
|
59
|
+
/** The edited cell's column. */
|
|
60
|
+
readonly column: number;
|
|
61
|
+
/** The editor itself: a field, its buttons. */
|
|
62
|
+
readonly node: ReactNode;
|
|
63
|
+
}
|
|
64
|
+
/** Props for {@link DataGrid}. */
|
|
65
|
+
export interface DataGridProps {
|
|
66
|
+
/** The grid's accessible name ("Orders"). */
|
|
67
|
+
readonly label: string;
|
|
68
|
+
/** The columns, in the order they draw. */
|
|
69
|
+
readonly columns: readonly DataGridColumn[];
|
|
70
|
+
/** How many rows the grid holds, read or not. */
|
|
71
|
+
readonly rowCount: number;
|
|
72
|
+
/** A cell's look, or null while its row has not been read. */
|
|
73
|
+
readonly cell: (row: number, column: number) => DataGridCell | null;
|
|
74
|
+
/** The text Copy puts on the clipboard for a cell; null copies nothing. */
|
|
75
|
+
readonly copyText: (row: number, column: number) => string | null;
|
|
76
|
+
/** Asks for rows `[from, to)` the grid is about to draw. */
|
|
77
|
+
readonly onNeedRows?: (from: number, to: number) => void;
|
|
78
|
+
/** Controls at a row's start, before its cells (a checkbox, Copy, Delete). */
|
|
79
|
+
readonly rowLead?: (row: number) => ReactNode;
|
|
80
|
+
/** The width of the lead's column, the same on every row, in pixels. */
|
|
81
|
+
readonly leadWidth?: number;
|
|
82
|
+
/** A control at a row's end, after its cells (Stop on a list of running jobs). */
|
|
83
|
+
readonly rowAction?: (row: number) => ReactNode;
|
|
84
|
+
/** The width of the row's end column, in pixels; as wide as it asks when absent. */
|
|
85
|
+
readonly actionWidth?: number;
|
|
86
|
+
/** The column the rows are sorted by, which its header marks. */
|
|
87
|
+
readonly sort?: DataGridSort | null;
|
|
88
|
+
/** The columns the rows are sorted by, in order, each header numbered while there are several. */
|
|
89
|
+
readonly sorts?: readonly DataGridSortMark[];
|
|
90
|
+
/** Makes each header a control that asks to sort by its column; the caller orders the rows. */
|
|
91
|
+
readonly onSort?: (column: number, click: DataGridSortClick) => void;
|
|
92
|
+
/** Lets a header be dragged to another column's place; the caller reorders `columns`. */
|
|
93
|
+
readonly onReorder?: (from: number, to: number) => void;
|
|
94
|
+
/**
|
|
95
|
+
* A double-click on a header, its name included (copy its name). Its
|
|
96
|
+
* first click sorts as any click does; the second click of the pair
|
|
97
|
+
* never sorts again, so the sort is not turned back.
|
|
98
|
+
*/
|
|
99
|
+
readonly onHeaderDoubleClick?: (column: number) => void;
|
|
100
|
+
/** The columns marked, which draw lit. */
|
|
101
|
+
readonly markedColumns?: ReadonlySet<number>;
|
|
102
|
+
/** A click on a header beside its sort control marks or unmarks its column. */
|
|
103
|
+
readonly onMarkColumn?: (column: number) => void;
|
|
104
|
+
/** Whether a row is marked, which draws it lit. */
|
|
105
|
+
readonly rowMarked?: (row: number) => boolean;
|
|
106
|
+
/** A click on a row's cells, or Space on the cursor's row, marks or unmarks it. */
|
|
107
|
+
readonly onMarkRow?: (row: number) => void;
|
|
108
|
+
/** Lights the row under the pointer. */
|
|
109
|
+
readonly pointer?: boolean;
|
|
110
|
+
/** The tallest the grid grows before it scrolls, in pixels; 420 unless given. */
|
|
111
|
+
readonly maxHeight?: number;
|
|
112
|
+
/** Whether a cell takes an inline edit; none does without it. */
|
|
113
|
+
readonly editable?: (row: number, column: number) => boolean;
|
|
114
|
+
/** What starts an edit with the pointer; a double-click unless given. */
|
|
115
|
+
readonly editTrigger?: 'click' | 'double-click';
|
|
116
|
+
/** Asks to edit a cell, which the caller answers by drawing `editor` over it. */
|
|
117
|
+
readonly onEdit?: (row: number, column: number) => void;
|
|
118
|
+
/** The editor drawn over the cell being edited. */
|
|
119
|
+
readonly editor?: DataGridEditor | null;
|
|
120
|
+
/**
|
|
121
|
+
* The element the editor's layer is drawn into, given the grid's own
|
|
122
|
+
* element: an ancestor whose styles the editor needs (`(grid) =>
|
|
123
|
+
* grid.closest('.app-root')`). `document.body` unless given or when it
|
|
124
|
+
* returns null.
|
|
125
|
+
*/
|
|
126
|
+
readonly editorContainer?: (grid: HTMLElement) => Element | null;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* A grid of rows of any count, drawn a screenful at a time under a header
|
|
130
|
+
* that stays put while they scroll, each column as wide as its first rows
|
|
131
|
+
* ask and resizable by its header's edge. One cell is the cursor, which a
|
|
132
|
+
* click or the arrows move (⌘ and an arrow go to an edge, Page Up and Page
|
|
133
|
+
* Down by a screen), and the page's Copy (⌘C, or an Edit menu's Copy) puts
|
|
134
|
+
* its `copyText` on the clipboard; Return runs the cursor cell's link. Read
|
|
135
|
+
* only: a cell's look and text come from `cell`, and a row not read yet
|
|
136
|
+
* draws empty while `onNeedRows` asks for it.
|
|
137
|
+
*
|
|
138
|
+
* What a caller adds, each only where it passes its handler: headers that
|
|
139
|
+
* sort (Shift adds a column to the sort, Option or Control takes it out),
|
|
140
|
+
* that drag to a new place, that copy their name on a double-click, and
|
|
141
|
+
* that mark their column on a click; controls at each row's start and end;
|
|
142
|
+
* rows that mark on a click or Space; the row under the pointer lit; and
|
|
143
|
+
* inline edit: a click or a double-click on an editable cell (`editTrigger`),
|
|
144
|
+
* or Return on the cursor cell when it holds no link, asks to edit it
|
|
145
|
+
* (`onEdit`), and the caller's editor draws over that cell (`editor`). With
|
|
146
|
+
* a double-click starting an edit, a link cell's single click waits a
|
|
147
|
+
* moment, so a double-click edits it rather than following it.
|
|
148
|
+
*/
|
|
149
|
+
export declare function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows, rowLead, leadWidth, rowAction, actionWidth, sort, sorts, onSort, onReorder, onHeaderDoubleClick, markedColumns, onMarkColumn, rowMarked, onMarkRow, pointer, maxHeight, editable, editTrigger, onEdit, editor, editorContainer }: DataGridProps): ReactElement;
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useLayoutEffect, useReducer, useRef, useState } from 'react';
|
|
3
|
+
import { createPortal, flushSync } from 'react-dom';
|
|
4
|
+
import { dropPlace, gridMove, initialWidth, movedCell, resizedWidth, visibleRows, windowHolds } from './DataGrid.logic.js';
|
|
5
|
+
import { describedTooltip } from '../tooltip/Tooltip.logic.js';
|
|
6
|
+
/** Every row's height, so the grid can place any row without measuring it. */
|
|
7
|
+
const ROW_HEIGHT = 22;
|
|
8
|
+
/** The viewport height before it is measured (or where it never is). */
|
|
9
|
+
const FALLBACK_VIEWPORT = 400;
|
|
10
|
+
/** A character's width in the grid's monospace face, for first column widths. */
|
|
11
|
+
const CHAR_WIDTH = 7.8;
|
|
12
|
+
/** How far a header moves under the pointer before it is dragged rather than clicked. */
|
|
13
|
+
const DRAG_THRESHOLD = 5;
|
|
14
|
+
/** How long a link's click waits for a second click that edits its cell instead. */
|
|
15
|
+
const LINK_WAIT_MS = 300;
|
|
16
|
+
/**
|
|
17
|
+
* A grid of rows of any count, drawn a screenful at a time under a header
|
|
18
|
+
* that stays put while they scroll, each column as wide as its first rows
|
|
19
|
+
* ask and resizable by its header's edge. One cell is the cursor, which a
|
|
20
|
+
* click or the arrows move (⌘ and an arrow go to an edge, Page Up and Page
|
|
21
|
+
* Down by a screen), and the page's Copy (⌘C, or an Edit menu's Copy) puts
|
|
22
|
+
* its `copyText` on the clipboard; Return runs the cursor cell's link. Read
|
|
23
|
+
* only: a cell's look and text come from `cell`, and a row not read yet
|
|
24
|
+
* draws empty while `onNeedRows` asks for it.
|
|
25
|
+
*
|
|
26
|
+
* What a caller adds, each only where it passes its handler: headers that
|
|
27
|
+
* sort (Shift adds a column to the sort, Option or Control takes it out),
|
|
28
|
+
* that drag to a new place, that copy their name on a double-click, and
|
|
29
|
+
* that mark their column on a click; controls at each row's start and end;
|
|
30
|
+
* rows that mark on a click or Space; the row under the pointer lit; and
|
|
31
|
+
* inline edit: a click or a double-click on an editable cell (`editTrigger`),
|
|
32
|
+
* or Return on the cursor cell when it holds no link, asks to edit it
|
|
33
|
+
* (`onEdit`), and the caller's editor draws over that cell (`editor`). With
|
|
34
|
+
* a double-click starting an edit, a link cell's single click waits a
|
|
35
|
+
* moment, so a double-click edits it rather than following it.
|
|
36
|
+
*/
|
|
37
|
+
export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows, rowLead, leadWidth = 0, rowAction, actionWidth, sort, sorts, onSort, onReorder, onHeaderDoubleClick, markedColumns, onMarkColumn, rowMarked, onMarkRow, pointer = false, maxHeight = 420, editable, editTrigger = 'double-click', onEdit, editor = null, editorContainer }) {
|
|
38
|
+
const id = useId();
|
|
39
|
+
const viewport = useRef(null);
|
|
40
|
+
const header = useRef(null);
|
|
41
|
+
/** Where the grid stood when it last scrolled; kept while it is out of layout (a hidden pane). */
|
|
42
|
+
const scrollTop = useRef(0);
|
|
43
|
+
/** Which way it last scrolled, which the rows drawn lean toward. */
|
|
44
|
+
const direction = useRef(0);
|
|
45
|
+
const [viewportHeight, setViewportHeight] = useState(FALLBACK_VIEWPORT);
|
|
46
|
+
/** The rows the last commit drew, and the facts the scroll listener judges them by. */
|
|
47
|
+
const committed = useRef(null);
|
|
48
|
+
const [, redraw] = useReducer((version) => version + 1, 0);
|
|
49
|
+
const [cursor, setCursor] = useState(null);
|
|
50
|
+
const [dragging, setDragging] = useState(null);
|
|
51
|
+
/** A drag just ended, so the click it ends with sorts nothing. */
|
|
52
|
+
const dragged = useRef(false);
|
|
53
|
+
/** Where the cell being edited sits in the window, which its editor is drawn over. */
|
|
54
|
+
const [editorBox, setEditorBox] = useState(null);
|
|
55
|
+
/** A link's click waiting to see whether a double-click edits its cell instead. */
|
|
56
|
+
const pendingLink = useRef(null);
|
|
57
|
+
const canEdit = (row, column) => onEdit !== undefined && (editable?.(row, column) ?? false);
|
|
58
|
+
useEffect(() => () => {
|
|
59
|
+
if (pendingLink.current !== null)
|
|
60
|
+
window.clearTimeout(pendingLink.current);
|
|
61
|
+
}, []);
|
|
62
|
+
const keyOf = (column, index) => column.id ?? String(index);
|
|
63
|
+
const [widths, setWidths] = useState(() => new Map(columns.map((column, index) => [
|
|
64
|
+
keyOf(column, index),
|
|
65
|
+
initialWidth(column.label, Array.from({ length: Math.min(rowCount, 20) }, (_, row) => cell(row, index)?.text ?? ''), CHAR_WIDTH)
|
|
66
|
+
])));
|
|
67
|
+
const widthOf = (column, index) => widths.get(keyOf(column, index)) ?? initialWidth(column.label, [], CHAR_WIDTH);
|
|
68
|
+
// The rows drawn last while they still cover where the grid stands, a fresh window otherwise.
|
|
69
|
+
const held = committed.current;
|
|
70
|
+
const { from, to } = held !== null &&
|
|
71
|
+
windowHolds(held, scrollTop.current, viewportHeight, ROW_HEIGHT, rowCount, direction.current)
|
|
72
|
+
? held
|
|
73
|
+
: visibleRows(scrollTop.current, viewportHeight, ROW_HEIGHT, rowCount, undefined, direction.current);
|
|
74
|
+
const template = [
|
|
75
|
+
rowLead === undefined ? null : `${leadWidth}px`,
|
|
76
|
+
...columns.map((column, index) => `${widthOf(column, index)}px`),
|
|
77
|
+
rowAction === undefined ? null : actionWidth === undefined ? 'max-content' : `${actionWidth}px`
|
|
78
|
+
]
|
|
79
|
+
.filter((part) => part !== null)
|
|
80
|
+
.join(' ');
|
|
81
|
+
const page = Math.max(1, Math.floor(viewportHeight / ROW_HEIGHT) - 1);
|
|
82
|
+
const marks = sorts ?? (sort === null || sort === undefined ? [] : [{ ...sort, position: 1 }]);
|
|
83
|
+
useLayoutEffect(() => {
|
|
84
|
+
const element = viewport.current;
|
|
85
|
+
if (element === null || typeof ResizeObserver === 'undefined')
|
|
86
|
+
return;
|
|
87
|
+
const observer = new ResizeObserver(() => {
|
|
88
|
+
if (element.clientHeight > 0)
|
|
89
|
+
setViewportHeight(element.clientHeight);
|
|
90
|
+
});
|
|
91
|
+
observer.observe(element);
|
|
92
|
+
return () => observer.disconnect();
|
|
93
|
+
}, []);
|
|
94
|
+
useLayoutEffect(() => {
|
|
95
|
+
committed.current = { from, to, viewportHeight, rowCount };
|
|
96
|
+
});
|
|
97
|
+
// A listener of its own rather than React's `onScroll`, whose dispatch
|
|
98
|
+
// commits on every scroll event; a scroll draws again only once the rows
|
|
99
|
+
// drawn no longer keep the overscan ahead of the viewport (`windowHolds`).
|
|
100
|
+
// A turn finds only the quarter behind on its new side, so its rows are
|
|
101
|
+
// drawn before the frame it scrolled in paints.
|
|
102
|
+
useLayoutEffect(() => {
|
|
103
|
+
const element = viewport.current;
|
|
104
|
+
if (element === null)
|
|
105
|
+
return;
|
|
106
|
+
const follow = () => {
|
|
107
|
+
let turned = false;
|
|
108
|
+
if (element.clientHeight > 0 && element.scrollTop !== scrollTop.current) {
|
|
109
|
+
const next = element.scrollTop > scrollTop.current ? 1 : -1;
|
|
110
|
+
turned = direction.current === -next;
|
|
111
|
+
direction.current = next;
|
|
112
|
+
scrollTop.current = element.scrollTop;
|
|
113
|
+
}
|
|
114
|
+
const drawn = committed.current;
|
|
115
|
+
if (drawn === null ||
|
|
116
|
+
!windowHolds(drawn, scrollTop.current, drawn.viewportHeight, ROW_HEIGHT, drawn.rowCount, direction.current)) {
|
|
117
|
+
if (turned)
|
|
118
|
+
flushSync(redraw);
|
|
119
|
+
else
|
|
120
|
+
redraw();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
element.addEventListener('scroll', follow, { passive: true });
|
|
124
|
+
return () => element.removeEventListener('scroll', follow);
|
|
125
|
+
}, []);
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
onNeedRows?.(from, to);
|
|
128
|
+
}, [from, to, onNeedRows]);
|
|
129
|
+
// Copy answers the page's own copy event (⌘C, or an Edit menu's Copy).
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
const onCopy = (event) => {
|
|
132
|
+
const element = viewport.current;
|
|
133
|
+
if (cursor === null || element === null || !element.contains(document.activeElement))
|
|
134
|
+
return;
|
|
135
|
+
const text = copyText(cursor.row, cursor.column);
|
|
136
|
+
if (text === null || event.clipboardData === null)
|
|
137
|
+
return;
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
event.clipboardData.setData('text/plain', text);
|
|
140
|
+
};
|
|
141
|
+
window.addEventListener('copy', onCopy);
|
|
142
|
+
return () => window.removeEventListener('copy', onCopy);
|
|
143
|
+
}, [cursor, copyText]);
|
|
144
|
+
const editorRow = editor?.row ?? null;
|
|
145
|
+
const editorColumn = editor?.column ?? null;
|
|
146
|
+
// The editor is drawn over its cell in a layer of its own, so the grid's
|
|
147
|
+
// scrolling box never cuts it; it follows the cell as the grid or the page
|
|
148
|
+
// scrolls. With no editor open, rows drawn again set nothing.
|
|
149
|
+
useLayoutEffect(() => {
|
|
150
|
+
if (editorRow === null || editorColumn === null)
|
|
151
|
+
return;
|
|
152
|
+
const place = () => {
|
|
153
|
+
const target = document.getElementById(`${id}-${editorRow}-${editorColumn}`);
|
|
154
|
+
const box = target?.getBoundingClientRect();
|
|
155
|
+
setEditorBox(box === undefined ? null : { left: box.left, top: box.top, width: box.width });
|
|
156
|
+
};
|
|
157
|
+
place();
|
|
158
|
+
window.addEventListener('scroll', place, true);
|
|
159
|
+
window.addEventListener('resize', place);
|
|
160
|
+
return () => {
|
|
161
|
+
window.removeEventListener('scroll', place, true);
|
|
162
|
+
window.removeEventListener('resize', place);
|
|
163
|
+
setEditorBox(null);
|
|
164
|
+
};
|
|
165
|
+
}, [id, editorRow, editorColumn, from, to]);
|
|
166
|
+
/** Scrolls a row into the viewport, below the header. */
|
|
167
|
+
const reveal = (row) => {
|
|
168
|
+
const element = viewport.current;
|
|
169
|
+
if (element === null)
|
|
170
|
+
return;
|
|
171
|
+
const top = row * ROW_HEIGHT;
|
|
172
|
+
const shown = element.clientHeight - ROW_HEIGHT;
|
|
173
|
+
if (top < element.scrollTop)
|
|
174
|
+
element.scrollTop = top;
|
|
175
|
+
else if (top + ROW_HEIGHT > element.scrollTop + shown) {
|
|
176
|
+
element.scrollTop = top + ROW_HEIGHT - shown;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const onKeyDown = (event) => {
|
|
180
|
+
if (event.target !== event.currentTarget)
|
|
181
|
+
return;
|
|
182
|
+
if (event.ctrlKey || event.altKey || event.shiftKey)
|
|
183
|
+
return;
|
|
184
|
+
if (event.key === 'Enter' && cursor !== null) {
|
|
185
|
+
const open = cell(cursor.row, cursor.column)?.onOpen;
|
|
186
|
+
if (open !== undefined) {
|
|
187
|
+
event.preventDefault();
|
|
188
|
+
open();
|
|
189
|
+
}
|
|
190
|
+
else if (canEdit(cursor.row, cursor.column)) {
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
onEdit?.(cursor.row, cursor.column);
|
|
193
|
+
}
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (event.key === ' ' && cursor !== null && onMarkRow !== undefined && !event.metaKey) {
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
onMarkRow(cursor.row);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const move = gridMove(event.key, event.metaKey);
|
|
202
|
+
const next = move === null ? null : movedCell(cursor, move, rowCount, columns.length, page);
|
|
203
|
+
if (next === null)
|
|
204
|
+
return;
|
|
205
|
+
event.preventDefault();
|
|
206
|
+
setCursor(next);
|
|
207
|
+
reveal(next.row);
|
|
208
|
+
};
|
|
209
|
+
const onResizeStart = (event, column) => {
|
|
210
|
+
if (event.button !== 0)
|
|
211
|
+
return;
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
event.stopPropagation();
|
|
214
|
+
const target = event.currentTarget;
|
|
215
|
+
const startX = event.clientX;
|
|
216
|
+
const key = keyOf(columns[column] ?? { label: '' }, column);
|
|
217
|
+
const startWidth = widthOf(columns[column] ?? { label: '' }, column);
|
|
218
|
+
target.setPointerCapture(event.pointerId);
|
|
219
|
+
const onMove = (move) => {
|
|
220
|
+
setWidths((held) => new Map(held).set(key, resizedWidth(startWidth, move.clientX - startX)));
|
|
221
|
+
};
|
|
222
|
+
const onUp = () => {
|
|
223
|
+
target.removeEventListener('pointermove', onMove);
|
|
224
|
+
target.removeEventListener('pointerup', onUp);
|
|
225
|
+
target.removeEventListener('lostpointercapture', onUp);
|
|
226
|
+
};
|
|
227
|
+
target.addEventListener('pointermove', onMove);
|
|
228
|
+
target.addEventListener('pointerup', onUp);
|
|
229
|
+
target.addEventListener('lostpointercapture', onUp);
|
|
230
|
+
};
|
|
231
|
+
/** The columns' left and right edges in the header, for where a dragged header lands. */
|
|
232
|
+
const headingEdges = () => [...(header.current?.querySelectorAll('[role="columnheader"]') ?? [])].map((element) => {
|
|
233
|
+
const box = element.getBoundingClientRect();
|
|
234
|
+
return { left: box.left, right: box.right };
|
|
235
|
+
});
|
|
236
|
+
const onHeadingPointerDown = (event, column) => {
|
|
237
|
+
if (onReorder === undefined || event.button !== 0 || columns.length < 2)
|
|
238
|
+
return;
|
|
239
|
+
const target = event.currentTarget;
|
|
240
|
+
const startX = event.clientX;
|
|
241
|
+
let moving = false;
|
|
242
|
+
const onMove = (move) => {
|
|
243
|
+
if (!moving && Math.abs(move.clientX - startX) < DRAG_THRESHOLD)
|
|
244
|
+
return;
|
|
245
|
+
if (!moving) {
|
|
246
|
+
moving = true;
|
|
247
|
+
target.setPointerCapture(event.pointerId);
|
|
248
|
+
}
|
|
249
|
+
setDragging({ from: column, to: dropPlace(move.clientX, headingEdges(), column) });
|
|
250
|
+
};
|
|
251
|
+
const onUp = (up) => {
|
|
252
|
+
target.removeEventListener('pointermove', onMove);
|
|
253
|
+
target.removeEventListener('pointerup', onUp);
|
|
254
|
+
target.removeEventListener('pointercancel', onCancel);
|
|
255
|
+
if (!moving)
|
|
256
|
+
return;
|
|
257
|
+
dragged.current = true;
|
|
258
|
+
setDragging(null);
|
|
259
|
+
const place = dropPlace(up.clientX, headingEdges(), column);
|
|
260
|
+
if (place !== column)
|
|
261
|
+
onReorder(column, place);
|
|
262
|
+
};
|
|
263
|
+
const onCancel = () => {
|
|
264
|
+
target.removeEventListener('pointermove', onMove);
|
|
265
|
+
target.removeEventListener('pointerup', onUp);
|
|
266
|
+
target.removeEventListener('pointercancel', onCancel);
|
|
267
|
+
setDragging(null);
|
|
268
|
+
};
|
|
269
|
+
target.addEventListener('pointermove', onMove);
|
|
270
|
+
target.addEventListener('pointerup', onUp);
|
|
271
|
+
target.addEventListener('pointercancel', onCancel);
|
|
272
|
+
};
|
|
273
|
+
/** Swallows the click a drag ends with. */
|
|
274
|
+
const draggedClick = (event) => {
|
|
275
|
+
if (!dragged.current)
|
|
276
|
+
return false;
|
|
277
|
+
dragged.current = false;
|
|
278
|
+
event.stopPropagation();
|
|
279
|
+
return true;
|
|
280
|
+
};
|
|
281
|
+
const cellId = (row, column) => `${id}-${row}-${column}`;
|
|
282
|
+
const rows = [];
|
|
283
|
+
for (let row = from; row < to; row += 1) {
|
|
284
|
+
const marked = rowMarked?.(row) ?? false;
|
|
285
|
+
rows.push(_jsxs("div", { "aria-rowindex": row + 2, "aria-selected": onMarkRow === undefined ? undefined : marked, className: marked ? 'data-grid-row marked' : 'data-grid-row', role: "row", style: { gridTemplateColumns: template, transform: `translateY(${row * ROW_HEIGHT}px)` }, children: [rowLead !== undefined && _jsx("div", { className: "data-grid-lead", children: rowLead(row) }), columns.map((column, index) => {
|
|
286
|
+
const shown = cell(row, index);
|
|
287
|
+
const current = cursor?.row === row && cursor.column === index;
|
|
288
|
+
const editing = editor !== null && editor.row === row && editor.column === index;
|
|
289
|
+
const edits = canEdit(row, index);
|
|
290
|
+
return (_jsxs("div", { "aria-colindex": index + 1, "aria-selected": current, className: [
|
|
291
|
+
'data-grid-cell',
|
|
292
|
+
column.align === 'right' ? 'align-right' : '',
|
|
293
|
+
current ? 'cursor' : '',
|
|
294
|
+
markedColumns?.has(index) === true ? 'marked' : '',
|
|
295
|
+
editing ? 'editing' : '',
|
|
296
|
+
shown?.className ?? ''
|
|
297
|
+
]
|
|
298
|
+
.filter(Boolean)
|
|
299
|
+
.join(' '), id: cellId(row, index), onClick: () => {
|
|
300
|
+
if (edits && editTrigger === 'click' && !editing)
|
|
301
|
+
onEdit?.(row, index);
|
|
302
|
+
else
|
|
303
|
+
onMarkRow?.(row);
|
|
304
|
+
}, onDoubleClick: () => {
|
|
305
|
+
if (!edits || editTrigger !== 'double-click' || editing)
|
|
306
|
+
return;
|
|
307
|
+
if (pendingLink.current !== null)
|
|
308
|
+
window.clearTimeout(pendingLink.current);
|
|
309
|
+
pendingLink.current = null;
|
|
310
|
+
onEdit?.(row, index);
|
|
311
|
+
}, onPointerDown: () => setCursor({ row, column: index }), role: "gridcell", ...describedTooltip(shown?.tip ?? null), children: [shown?.content !== undefined ? (shown.content) : shown?.onOpen === undefined ? ((shown?.text ?? '')) : (_jsx("button", { className: "data-grid-link", onClick: (event) => {
|
|
312
|
+
event.stopPropagation();
|
|
313
|
+
const open = shown.onOpen;
|
|
314
|
+
if (edits && editTrigger === 'double-click') {
|
|
315
|
+
if (event.detail > 1)
|
|
316
|
+
return;
|
|
317
|
+
// A second click within the system's double-click time edits instead.
|
|
318
|
+
pendingLink.current = window.setTimeout(() => {
|
|
319
|
+
pendingLink.current = null;
|
|
320
|
+
open?.();
|
|
321
|
+
}, LINK_WAIT_MS);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
open?.();
|
|
325
|
+
}, onMouseDown: (event) => {
|
|
326
|
+
// A press leaves focus on the grid, so its keys keep working.
|
|
327
|
+
event.preventDefault();
|
|
328
|
+
viewport.current?.focus({ preventScroll: true });
|
|
329
|
+
}, tabIndex: -1, type: "button", children: shown.text })), editing &&
|
|
330
|
+
editorBox !== null &&
|
|
331
|
+
createPortal(_jsx("div", { className: "data-grid-editor", onClick: (event) => event.stopPropagation(), onDoubleClick: (event) => event.stopPropagation(), onPointerDown: (event) => event.stopPropagation(), style: {
|
|
332
|
+
left: editorBox.left - 1,
|
|
333
|
+
top: editorBox.top - 1,
|
|
334
|
+
minWidth: editorBox.width + 2,
|
|
335
|
+
// It keeps inside the window, however far right its cell lies.
|
|
336
|
+
maxWidth: Math.max(160, window.innerWidth - editorBox.left - 8)
|
|
337
|
+
}, children: editor.node }),
|
|
338
|
+
// Where the caller says, so its styles reach the editor.
|
|
339
|
+
(viewport.current === null ? null : editorContainer?.(viewport.current)) ??
|
|
340
|
+
document.body)] }, keyOf(column, index)));
|
|
341
|
+
}), rowAction !== undefined && _jsx("div", { className: "data-grid-action", children: rowAction(row) })] }, row));
|
|
342
|
+
}
|
|
343
|
+
return (_jsxs("div", { "aria-activedescendant": cursor === null ? undefined : cellId(cursor.row, cursor.column), "aria-colcount": columns.length, "aria-label": label, "aria-multiselectable": onMarkRow === undefined ? undefined : true, "aria-rowcount": rowCount + 1, className: pointer ? 'data-grid pointer' : 'data-grid', onKeyDown: onKeyDown, ref: viewport, role: "grid", style: { maxHeight: maxHeight }, tabIndex: 0, children: [_jsxs("div", { "aria-rowindex": 1, className: "data-grid-header", ref: header, role: "row", style: { gridTemplateColumns: template }, children: [rowLead !== undefined && _jsx("div", { className: "data-grid-lead" }), columns.map((column, index) => {
|
|
344
|
+
const mark = marks.find((entry) => entry.column === index);
|
|
345
|
+
return (_jsxs("div", { "aria-colindex": index + 1, "aria-sort": mark?.direction, className: [
|
|
346
|
+
'data-grid-heading',
|
|
347
|
+
column.align === 'right' ? 'align-right' : '',
|
|
348
|
+
markedColumns?.has(index) === true ? 'marked' : '',
|
|
349
|
+
dragging?.from === index ? 'dragging' : '',
|
|
350
|
+
dragging !== null && dragging.to === index && dragging.from !== index
|
|
351
|
+
? dragging.to < dragging.from
|
|
352
|
+
? 'drop-before'
|
|
353
|
+
: 'drop-after'
|
|
354
|
+
: '',
|
|
355
|
+
onReorder === undefined ? '' : 'draggable'
|
|
356
|
+
]
|
|
357
|
+
.filter(Boolean)
|
|
358
|
+
.join(' '), onClick: (event) => {
|
|
359
|
+
if (draggedClick(event))
|
|
360
|
+
return;
|
|
361
|
+
onMarkColumn?.(index);
|
|
362
|
+
}, onDoubleClick: () => onHeaderDoubleClick?.(index), onPointerDown: (event) => onHeadingPointerDown(event, index), role: "columnheader", ...describedTooltip(column.tip ?? null), children: [onSort === undefined ? (_jsx("span", { className: "data-grid-label", children: column.label })) : (_jsxs("button", { className: "data-grid-label data-grid-sort", onClick: (event) => {
|
|
363
|
+
event.stopPropagation();
|
|
364
|
+
// A double-click's second click (`detail` 2) leaves the sort its first made.
|
|
365
|
+
if (draggedClick(event) || event.detail > 1)
|
|
366
|
+
return;
|
|
367
|
+
onSort(index, {
|
|
368
|
+
add: event.shiftKey && !event.altKey,
|
|
369
|
+
remove: event.altKey || event.ctrlKey
|
|
370
|
+
});
|
|
371
|
+
}, type: "button", children: [column.label, mark !== undefined && (_jsxs("span", { "aria-hidden": true, className: "data-grid-arrow", children: [mark.direction === 'ascending' ? '▲' : '▼', marks.length > 1 && _jsx("small", { children: mark.position })] }))] })), _jsx("span", { "aria-hidden": true, className: "data-grid-resize", onPointerDown: (event) => onResizeStart(event, index) })] }, keyOf(column, index)));
|
|
372
|
+
}), rowAction !== undefined && _jsx("div", { className: "data-grid-action" })] }), _jsx("div", { className: "data-grid-body", role: "rowgroup", style: { height: rowCount * ROW_HEIGHT }, children: rows })] }));
|
|
373
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** A grid's cursor cell, by row and column index. */
|
|
2
|
+
export interface GridCell {
|
|
3
|
+
readonly row: number;
|
|
4
|
+
readonly column: number;
|
|
5
|
+
}
|
|
6
|
+
/** Which way a grid last scrolled: 1 down, -1 up, 0 not yet. */
|
|
7
|
+
export type ScrollDirection = -1 | 0 | 1;
|
|
8
|
+
/**
|
|
9
|
+
* The rows a viewport draws, `[from, to)`, with `overscan` rows beyond each
|
|
10
|
+
* edge. A grid scrolling one way draws as many rows in all, a quarter of
|
|
11
|
+
* them behind and the rest ahead, so it can keep the rows drawn for a few
|
|
12
|
+
* rows' scroll (`windowHolds`) with `overscan` still ahead.
|
|
13
|
+
*/
|
|
14
|
+
export declare function visibleRows(scrollTop: number, viewportHeight: number, rowHeight: number, rowCount: number, overscan?: number, direction?: ScrollDirection): {
|
|
15
|
+
readonly from: number;
|
|
16
|
+
readonly to: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Whether the rows drawn, `[from, to)`, still serve a viewport scrolled to
|
|
20
|
+
* `scrollTop` that last moved `direction`: they cover it with `overscan`
|
|
21
|
+
* rows to spare ahead of it (beyond both edges before any scroll), or reach
|
|
22
|
+
* that end of the grid, and none lies past its last row. A scroll inside
|
|
23
|
+
* them draws nothing again, and every screen painted has as many rows ahead
|
|
24
|
+
* as a grid drawn again on every scroll would.
|
|
25
|
+
*/
|
|
26
|
+
export declare function windowHolds(drawn: {
|
|
27
|
+
readonly from: number;
|
|
28
|
+
readonly to: number;
|
|
29
|
+
}, scrollTop: number, viewportHeight: number, rowHeight: number, rowCount: number, direction: ScrollDirection, overscan?: number): boolean;
|
|
30
|
+
/** The keys that move a grid's cursor cell. */
|
|
31
|
+
export type GridMove = 'up' | 'down' | 'left' | 'right' | 'page-up' | 'page-down' | 'row-start' | 'row-end' | 'start' | 'end';
|
|
32
|
+
/** The move a key asks of a grid's cursor, or null for a key it leaves alone. */
|
|
33
|
+
export declare function gridMove(key: string, meta: boolean): GridMove | null;
|
|
34
|
+
/**
|
|
35
|
+
* Where a move takes the cursor among `rows` by `columns` cells, stopping
|
|
36
|
+
* at every edge; a page moves `page` rows. No cursor yet starts on the
|
|
37
|
+
* first cell. Null when the grid has no cells.
|
|
38
|
+
*/
|
|
39
|
+
export declare function movedCell(cursor: GridCell | null, move: GridMove, rows: number, columns: number, page: number): GridCell | null;
|
|
40
|
+
/** The narrowest a column can be dragged. */
|
|
41
|
+
export declare const MINIMUM_COLUMN_WIDTH = 40;
|
|
42
|
+
/** A column's width after its edge is dragged by `delta` pixels from `start`. */
|
|
43
|
+
export declare const resizedWidth: (start: number, delta: number) => number;
|
|
44
|
+
/**
|
|
45
|
+
* A column's first width from what it holds: its label and up to the first
|
|
46
|
+
* rows' texts, at `charWidth` pixels a character, between 60 and 360 pixels.
|
|
47
|
+
*/
|
|
48
|
+
export declare function initialWidth(label: string, samples: readonly string[], charWidth: number): number;
|
|
49
|
+
/**
|
|
50
|
+
* Where a header dragged from `from` lands with the pointer at `x`, among
|
|
51
|
+
* the header cells' edges: the column under the pointer, the first left of
|
|
52
|
+
* them all, the last right of them all.
|
|
53
|
+
*/
|
|
54
|
+
export declare function dropPlace(x: number, edges: readonly {
|
|
55
|
+
readonly left: number;
|
|
56
|
+
readonly right: number;
|
|
57
|
+
}[], from: number): number;
|