@bigpixelrocket/uiok 0.1.4 → 0.2.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 +88 -1
- package/README.md +1 -1
- package/dist/activity/ActivityBar.d.ts +21 -8
- package/dist/activity/ActivityBar.js +15 -5
- package/dist/activity/activity.css +53 -6
- package/dist/button/Button.d.ts +10 -6
- package/dist/button/Button.js +6 -1
- package/dist/button/button.css +201 -33
- package/dist/charts/Line.logic.d.ts +6 -0
- package/dist/charts/Line.logic.js +9 -0
- package/dist/charts/LineChart.js +11 -4
- package/dist/charts/Pie.logic.d.ts +89 -1
- package/dist/charts/Pie.logic.js +272 -2
- package/dist/charts/PieChart.d.ts +2 -1
- package/dist/charts/PieChart.js +12 -5
- package/dist/charts/PieFill.d.ts +15 -0
- package/dist/charts/PieFill.js +33 -0
- package/dist/charts/ResultChart.d.ts +2 -2
- package/dist/charts/ResultChart.js +173 -47
- package/dist/charts/ResultChart.logic.d.ts +60 -4
- package/dist/charts/ResultChart.logic.js +105 -6
- package/dist/charts/Scatter.logic.d.ts +18 -4
- package/dist/charts/Scatter.logic.js +98 -22
- package/dist/charts/ScatterChart.js +19 -5
- package/dist/charts/charts.css +233 -116
- package/dist/charts/seriesColour.d.ts +2 -0
- package/dist/charts/seriesColour.js +1 -1
- package/dist/datetime/DateTimePicker.d.ts +12 -2
- package/dist/datetime/DateTimePicker.js +61 -16
- package/dist/datetime/DateTimePicker.logic.d.ts +29 -0
- package/dist/datetime/DateTimePicker.logic.js +25 -0
- package/dist/datetime/datetime.css +89 -49
- package/dist/dialog/ConfirmDialog.d.ts +69 -20
- package/dist/dialog/ConfirmDialog.js +39 -12
- package/dist/dialog/DialogLayer.d.ts +25 -0
- package/dist/dialog/DialogLayer.js +24 -0
- package/dist/dialog/DialogLegend.d.ts +2 -1
- package/dist/dialog/DialogLegend.js +10 -5
- package/dist/dialog/DialogLegend.logic.d.ts +15 -3
- package/dist/dialog/DialogLegend.logic.js +8 -4
- package/dist/dialog/DialogLists.d.ts +157 -0
- package/dist/dialog/DialogLists.js +137 -0
- package/dist/dialog/ModalDialog.d.ts +20 -15
- package/dist/dialog/ModalDialog.js +22 -7
- package/dist/dialog/dialog.css +570 -127
- package/dist/dialog/index.d.ts +7 -1
- package/dist/dialog/index.js +7 -1
- package/dist/field/Check.d.ts +15 -0
- package/dist/field/Check.js +23 -0
- package/dist/field/field.css +812 -0
- package/dist/field/index.d.ts +10 -0
- package/dist/field/index.js +10 -0
- package/dist/field/labelHelp.d.ts +33 -0
- package/dist/field/labelHelp.js +22 -0
- package/dist/filter/FilterIcon.js +2 -1
- package/dist/filter/filter.css +72 -20
- package/dist/grid/DataGrid.d.ts +8 -1
- package/dist/grid/DataGrid.js +115 -40
- package/dist/grid/DataGrid.logic.d.ts +15 -3
- package/dist/grid/DataGrid.logic.js +18 -5
- package/dist/grid/grid.css +481 -56
- package/dist/icon/Spinner.d.ts +16 -0
- package/dist/icon/Spinner.js +13 -0
- package/dist/icon/index.d.ts +5 -0
- package/dist/icon/index.js +5 -0
- package/dist/icon/sizes.d.ts +19 -0
- package/dist/icon/sizes.js +19 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/keychord/KeyChord.d.ts +12 -1
- package/dist/keychord/KeyChord.js +2 -2
- package/dist/keychord/index.d.ts +1 -1
- package/dist/keychord/keychord.css +87 -9
- package/dist/labels/dialog.d.ts +12 -1
- package/dist/labels/dialog.js +3 -1
- package/dist/labels/selectAll.d.ts +4 -4
- package/dist/labels/selectAll.js +1 -1
- package/dist/legend/KeyLegendStrip.js +1 -1
- package/dist/legend/legend.css +82 -57
- package/dist/listing/Listing.d.ts +17 -10
- package/dist/listing/Listing.js +33 -26
- package/dist/listing/listing.css +1665 -237
- package/dist/menu/menu.css +227 -67
- package/dist/menu/useBellBeat.js +2 -2
- package/dist/namecut/NameCut.d.ts +3 -1
- package/dist/namecut/NameCut.js +152 -5
- package/dist/namecut/NameCut.logic.d.ts +5 -3
- package/dist/namecut/NameCut.logic.js +20 -5
- package/dist/namecut/namecut.css +27 -7
- package/dist/pager/Pager.d.ts +12 -4
- package/dist/pager/Pager.js +21 -7
- package/dist/pager/pager.css +41 -30
- package/dist/palette/Palette.js +2 -1
- package/dist/palette/palette.css +121 -60
- package/dist/pane/PaneActions.d.ts +56 -14
- package/dist/pane/PaneActions.js +64 -16
- package/dist/pane/PaneFrame.d.ts +37 -5
- package/dist/pane/PaneFrame.js +246 -11
- package/dist/pane/index.d.ts +4 -2
- package/dist/pane/index.js +4 -2
- package/dist/pane/toolWords.d.ts +14 -0
- package/dist/pane/toolWords.js +26 -0
- package/dist/pane/useToolbarFit.d.ts +25 -0
- package/dist/pane/useToolbarFit.js +95 -0
- package/dist/run/RunHeader.d.ts +5 -3
- package/dist/run/RunHeader.js +11 -8
- package/dist/run/run.css +64 -79
- package/dist/segmented/SegmentedChoice.d.ts +18 -2
- package/dist/segmented/SegmentedChoice.js +18 -7
- package/dist/segmented/segmented.css +62 -22
- package/dist/selectall/SelectAllBar.d.ts +4 -3
- package/dist/selectall/SelectAllBar.js +4 -3
- package/dist/selectall/selectall.css +17 -12
- package/dist/shell/shell.css +1073 -0
- package/dist/styles.css +620 -22
- package/dist/surface/surface.css +154 -0
- package/dist/tabs/PageTabs.d.ts +10 -5
- package/dist/tabs/PageTabs.js +126 -37
- package/dist/tabs/tabs.css +131 -51
- package/dist/terminal/Terminal.js +3 -1
- package/dist/terminal/Terminal.logic.d.ts +5 -4
- package/dist/terminal/Terminal.logic.js +9 -4
- package/dist/terminal/TerminalMenu.d.ts +4 -1
- package/dist/terminal/TerminalMenu.js +12 -5
- package/dist/terminal/ghostty/contrast.logic.d.ts +45 -0
- package/dist/terminal/ghostty/contrast.logic.js +130 -0
- package/dist/terminal/ghostty/core.d.ts +6 -0
- package/dist/terminal/ghostty/renderer.d.ts +9 -2
- package/dist/terminal/ghostty/renderer.js +91 -14
- package/dist/terminal/ghostty/surface.d.ts +8 -0
- package/dist/terminal/ghostty/surface.js +27 -1
- package/dist/terminal/terminal.css +87 -61
- package/dist/text/text.css +16 -7
- package/dist/themes/catalog.js +4 -3
- package/dist/themes/themes.generated.css +1307 -264
- package/dist/themes/tokens.d.ts +69 -14
- package/dist/themes/tokens.js +920 -97
- package/dist/tokens.css +239 -0
- package/dist/tooltip/Tooltip.d.ts +6 -0
- package/dist/tooltip/Tooltip.js +48 -6
- package/dist/tooltip/Tooltip.logic.d.ts +89 -12
- package/dist/tooltip/Tooltip.logic.js +142 -20
- package/dist/tooltip/index.d.ts +1 -1
- package/dist/tooltip/index.js +1 -1
- package/dist/tooltip/tooltip.css +39 -9
- package/package.json +3 -3
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form controls. The look is class-based on native elements (`field.css`:
|
|
3
|
+
* `.field`, `.check`, `.switch`, `.field-label`, `.field-note`,
|
|
4
|
+
* `.field-problem`, `.field-group`, `.field-choice`, `.field-grid`), so most
|
|
5
|
+
* forms need no component; `Check` adds the mixed state a checkbox can only
|
|
6
|
+
* reach from script, and `labelHelp` puts a control's help in its label's
|
|
7
|
+
* tooltip.
|
|
8
|
+
*/
|
|
9
|
+
export { Check, type CheckProps } from './Check.js';
|
|
10
|
+
export { labelHelp, type LabelHelp } from './labelHelp.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form controls. The look is class-based on native elements (`field.css`:
|
|
3
|
+
* `.field`, `.check`, `.switch`, `.field-label`, `.field-note`,
|
|
4
|
+
* `.field-problem`, `.field-group`, `.field-choice`, `.field-grid`), so most
|
|
5
|
+
* forms need no component; `Check` adds the mixed state a checkbox can only
|
|
6
|
+
* reach from script, and `labelHelp` puts a control's help in its label's
|
|
7
|
+
* tooltip.
|
|
8
|
+
*/
|
|
9
|
+
export { Check } from './Check.js';
|
|
10
|
+
export { labelHelp } from './labelHelp.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type TooltipAttributes } from '../tooltip/Tooltip.logic.js';
|
|
2
|
+
/** The two halves of a field's help: what its label wears and what its control wears. */
|
|
3
|
+
export interface LabelHelp {
|
|
4
|
+
/**
|
|
5
|
+
* Spread on the `.field-label`: the help as the label's hover tooltip,
|
|
6
|
+
* opening above the label (or at its end where there is no room above),
|
|
7
|
+
* and `data-label-help`, which draws the help cue: a dashed underline.
|
|
8
|
+
*/
|
|
9
|
+
readonly label: TooltipAttributes;
|
|
10
|
+
/**
|
|
11
|
+
* Spread on the control the label names: the help as its accessible
|
|
12
|
+
* description, so a screen reader hears it when the control takes focus.
|
|
13
|
+
* A description on the label itself is never read, since a label only
|
|
14
|
+
* gives its control a name.
|
|
15
|
+
*/
|
|
16
|
+
readonly control: {
|
|
17
|
+
readonly 'aria-description'?: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Help that explains a control, kept off the form: a desktop form shows a
|
|
22
|
+
* label and its control, and says what the control does in the label's
|
|
23
|
+
* tooltip instead of a sentence under the field. The same words reach a
|
|
24
|
+
* screen reader through the control. Without help both halves are empty,
|
|
25
|
+
* so a row may pass its optional note straight through. A line that says
|
|
26
|
+
* what the current choice does ("The next check is at 14:00.") stays a
|
|
27
|
+
* `.field-note` under the control, since it changes with the choice. A
|
|
28
|
+
* label with help shows a cue (a dashed underline, as any word that holds
|
|
29
|
+
* a tooltip), and its tooltip opens above it, never over its control. The
|
|
30
|
+
* tooltip opens under the pointer only, so help a user must read to fill
|
|
31
|
+
* the field stays visible as a `.field-note` instead.
|
|
32
|
+
*/
|
|
33
|
+
export declare function labelHelp(help: string | null | undefined): LabelHelp;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { tooltip } from '../tooltip/Tooltip.logic.js';
|
|
2
|
+
/**
|
|
3
|
+
* Help that explains a control, kept off the form: a desktop form shows a
|
|
4
|
+
* label and its control, and says what the control does in the label's
|
|
5
|
+
* tooltip instead of a sentence under the field. The same words reach a
|
|
6
|
+
* screen reader through the control. Without help both halves are empty,
|
|
7
|
+
* so a row may pass its optional note straight through. A line that says
|
|
8
|
+
* what the current choice does ("The next check is at 14:00.") stays a
|
|
9
|
+
* `.field-note` under the control, since it changes with the choice. A
|
|
10
|
+
* label with help shows a cue (a dashed underline, as any word that holds
|
|
11
|
+
* a tooltip), and its tooltip opens above it, never over its control. The
|
|
12
|
+
* tooltip opens under the pointer only, so help a user must read to fill
|
|
13
|
+
* the field stays visible as a `.field-note` instead.
|
|
14
|
+
*/
|
|
15
|
+
export function labelHelp(help) {
|
|
16
|
+
return help
|
|
17
|
+
? {
|
|
18
|
+
label: { ...tooltip(help, null, { side: 'above' }), 'data-label-help': '' },
|
|
19
|
+
control: { 'aria-description': help }
|
|
20
|
+
}
|
|
21
|
+
: { label: {}, control: {} };
|
|
22
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { ListFilter } from 'lucide-react';
|
|
3
|
+
import { ICON_MD } from '../icon/index.js';
|
|
3
4
|
/**
|
|
4
5
|
* The mark at the start of a filter field, the same over a listing, in a
|
|
5
6
|
* menu, and in a palette. It is as wide as the icon column of the rows the
|
|
@@ -7,5 +8,5 @@ import { ListFilter } from 'lucide-react';
|
|
|
7
8
|
* Decorative: the field's own label names it.
|
|
8
9
|
*/
|
|
9
10
|
export function FilterIcon() {
|
|
10
|
-
return (_jsx("span", { "aria-hidden": true, className: "filter-icon", children: _jsx(ListFilter, { size:
|
|
11
|
+
return (_jsx("span", { "aria-hidden": true, className: "filter-icon", children: _jsx(ListFilter, { size: ICON_MD }) }));
|
|
11
12
|
}
|
package/dist/filter/filter.css
CHANGED
|
@@ -1,42 +1,94 @@
|
|
|
1
|
-
/* ---- Filter field
|
|
1
|
+
/* ---- Filter field (FilterIcon, FilterEscape, .filter-field) ----
|
|
2
2
|
|
|
3
3
|
Drawn inside the listing scope (.listing-root), where a filter field sits
|
|
4
4
|
over the rows it narrows. */
|
|
5
5
|
|
|
6
|
-
/* The
|
|
7
|
-
|
|
8
|
-
.
|
|
6
|
+
/* The field: one bar as tall as the pane's path bar, the mark in the row's
|
|
7
|
+
icon column, the query in the rows' monospace, and the esc cap at the far
|
|
8
|
+
end. It has no outline of its own; while it holds the keys its foot turns
|
|
9
|
+
to a 2px accent edge, the same mark as a current tab's underline. A host
|
|
10
|
+
that draws its own row keeps working: these rules apply only under
|
|
11
|
+
.filter-field. */
|
|
12
|
+
:where(.listing-root) .filter-field {
|
|
13
|
+
display: flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
box-sizing: border-box;
|
|
16
|
+
height: var(--pane-path-height);
|
|
17
|
+
padding: 0 var(--space-3) 0 var(--pane-row-inset);
|
|
18
|
+
border-bottom: var(--line) solid var(--border);
|
|
19
|
+
font: var(--font-size-body) var(--font-mono);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
:where(.listing-root) .filter-field:focus-within {
|
|
23
|
+
box-shadow: inset 0 calc(-1 * var(--line-strong)) 0 var(--accent);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
:where(.listing-root) .filter-field input {
|
|
27
|
+
flex: 1;
|
|
28
|
+
min-width: 0;
|
|
29
|
+
margin: 0;
|
|
30
|
+
padding: 0;
|
|
31
|
+
border: 0;
|
|
32
|
+
outline: none;
|
|
33
|
+
background: none;
|
|
34
|
+
color: var(--text);
|
|
35
|
+
font: inherit;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* The key that leaves a filter field (FilterEscape), drawn as the shared key
|
|
39
|
+
cap (keychord.css); the field's mark is .filter-icon. */
|
|
40
|
+
:where(.listing-root) .filter-escape {
|
|
41
|
+
position: relative;
|
|
9
42
|
flex: none;
|
|
10
43
|
display: inline-flex;
|
|
11
|
-
margin-left:
|
|
44
|
+
margin-left: var(--space-4);
|
|
12
45
|
padding: 0;
|
|
13
46
|
border: none;
|
|
14
|
-
border-radius:
|
|
47
|
+
border-radius: var(--radius-sm);
|
|
15
48
|
background: none;
|
|
16
|
-
cursor:
|
|
49
|
+
cursor: default;
|
|
17
50
|
}
|
|
18
51
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
52
|
+
/* The cap is glyph-sized (18px, a key cap's height, not a control height);
|
|
53
|
+
its hit area grows to --hit-target around it. */
|
|
54
|
+
:where(.listing-root) .filter-escape::after {
|
|
55
|
+
position: absolute;
|
|
56
|
+
inset: min(0px, calc((100% - var(--hit-target)) / 2));
|
|
57
|
+
content: '';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* Hover and press answer as every quiet control does, on the cap itself:
|
|
61
|
+
the frosted wash and ring, then the pressed wash and shadow inside the
|
|
62
|
+
same ring. The cap's own panel
|
|
63
|
+
ground stays under the wash, since the cap is opaque. */
|
|
64
|
+
:where(.listing-root) .filter-escape:hover:enabled:not([aria-disabled='true']) .keychord {
|
|
65
|
+
background: linear-gradient(var(--hover-wash), var(--hover-wash)) var(--surface);
|
|
66
|
+
box-shadow: var(--hover-frost);
|
|
27
67
|
}
|
|
28
68
|
|
|
29
|
-
.listing-root .filter-escape:
|
|
30
|
-
|
|
31
|
-
|
|
69
|
+
:where(.listing-root) .filter-escape:active:enabled:not([aria-disabled='true']) .keychord {
|
|
70
|
+
background: linear-gradient(var(--pressed-wash), var(--pressed-wash)) var(--surface);
|
|
71
|
+
box-shadow:
|
|
72
|
+
var(--shadow-pressed),
|
|
73
|
+
inset 0 0 0 var(--line) var(--border-strong);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
:where(.listing-root) .filter-escape .keychord {
|
|
77
|
+
transition: var(--transition-control);
|
|
32
78
|
}
|
|
33
79
|
|
|
34
80
|
/* A filter field's mark (FilterIcon), as wide as a row's icon column so the
|
|
35
|
-
query starts over the names.
|
|
81
|
+
query starts over the names. It rests dim and lights with the accent only
|
|
82
|
+
while the field narrows the list: while it holds the keys or holds a
|
|
83
|
+
query. */
|
|
36
84
|
:where(.listing-root) .filter-icon {
|
|
37
85
|
flex: none;
|
|
38
86
|
display: inline-flex;
|
|
39
87
|
align-items: center;
|
|
40
|
-
width:
|
|
88
|
+
width: var(--icon-column);
|
|
89
|
+
color: var(--text-dim);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
:where(.listing-root) :is(:focus-within, :has(> input:not(:placeholder-shown))) > .filter-icon {
|
|
41
93
|
color: var(--accent);
|
|
42
94
|
}
|
package/dist/grid/DataGrid.d.ts
CHANGED
|
@@ -124,6 +124,13 @@ export interface DataGridProps {
|
|
|
124
124
|
* returns null.
|
|
125
125
|
*/
|
|
126
126
|
readonly editorContainer?: (grid: HTMLElement) => Element | null;
|
|
127
|
+
/**
|
|
128
|
+
* What the grid says when it has no rows (a sentence such as "No rows
|
|
129
|
+
* match the filter", or a sentence and an action), drawn dim where the
|
|
130
|
+
* first row would be, in the grid's cell type, in the empty well under the
|
|
131
|
+
* header. The well stays blank without it.
|
|
132
|
+
*/
|
|
133
|
+
readonly empty?: ReactNode;
|
|
127
134
|
}
|
|
128
135
|
/**
|
|
129
136
|
* A grid of rows of any count, drawn a screenful at a time under a header
|
|
@@ -146,4 +153,4 @@ export interface DataGridProps {
|
|
|
146
153
|
* a double-click starting an edit, a link cell's single click waits a
|
|
147
154
|
* moment, so a double-click edits it rather than following it.
|
|
148
155
|
*/
|
|
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;
|
|
156
|
+
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, empty }: DataGridProps): ReactElement;
|
package/dist/grid/DataGrid.js
CHANGED
|
@@ -1,18 +1,37 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useId, useLayoutEffect, useReducer, useRef, useState } from 'react';
|
|
3
|
+
import { ChevronDown, ChevronUp } from 'lucide-react';
|
|
3
4
|
import { createPortal, flushSync } from 'react-dom';
|
|
4
|
-
import { dropPlace, gridMove, initialWidth, movedCell, resizedWidth, visibleRows, windowHolds } from './DataGrid.logic.js';
|
|
5
|
-
import {
|
|
5
|
+
import { dropPlace, editorLeft, gridMove, initialWidth, movedCell, resizedWidth, visibleRows, windowHolds } from './DataGrid.logic.js';
|
|
6
|
+
import { ICON_SM } from '../icon/index.js';
|
|
7
|
+
import { cutTooltip, describedTooltip } from '../tooltip/Tooltip.logic.js';
|
|
6
8
|
/** Every row's height, so the grid can place any row without measuring it. */
|
|
7
9
|
const ROW_HEIGHT = 22;
|
|
8
10
|
/** The viewport height before it is measured (or where it never is). */
|
|
9
11
|
const FALLBACK_VIEWPORT = 400;
|
|
10
12
|
/** A character's width in the grid's monospace face, for first column widths. */
|
|
11
13
|
const CHAR_WIDTH = 7.8;
|
|
14
|
+
/**
|
|
15
|
+
* The room a sortable column's heading keeps beside its label for the sort
|
|
16
|
+
* mark: the chevron (ICON_SM), its gap (`--space-2`), and one digit of its
|
|
17
|
+
* place in a sort of several, so a heading sized to its label is not cut
|
|
18
|
+
* when it is sorted.
|
|
19
|
+
*/
|
|
20
|
+
const SORT_MARK_ROOM = ICON_SM + 4 + CHAR_WIDTH;
|
|
12
21
|
/** How far a header moves under the pointer before it is dragged rather than clicked. */
|
|
13
22
|
const DRAG_THRESHOLD = 5;
|
|
14
23
|
/** How long a link's click waits for a second click that edits its cell instead. */
|
|
15
24
|
const LINK_WAIT_MS = 300;
|
|
25
|
+
/** How far inside the grid's frame an editor wider than its cell ends (--space-4). */
|
|
26
|
+
const EDITOR_MARGIN = 8;
|
|
27
|
+
/** The narrowest an editor's layer is held to, however narrow the grid. */
|
|
28
|
+
const EDITOR_MIN_WIDTH = 160;
|
|
29
|
+
/**
|
|
30
|
+
* The least the columns overflow the well before it fades its inline edges:
|
|
31
|
+
* the fade's own width (`--scroll-fade-size` on `.scroll-fade-x`, 12px), so
|
|
32
|
+
* a sliver of overflow never fades a whole column's edge to hide it.
|
|
33
|
+
*/
|
|
34
|
+
const FADE_MIN_OVERFLOW = 12;
|
|
16
35
|
/**
|
|
17
36
|
* A grid of rows of any count, drawn a screenful at a time under a header
|
|
18
37
|
* that stays put while they scroll, each column as wide as its first rows
|
|
@@ -34,15 +53,21 @@ const LINK_WAIT_MS = 300;
|
|
|
34
53
|
* a double-click starting an edit, a link cell's single click waits a
|
|
35
54
|
* moment, so a double-click edits it rather than following it.
|
|
36
55
|
*/
|
|
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 }) {
|
|
56
|
+
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, empty }) {
|
|
38
57
|
const id = useId();
|
|
39
58
|
const viewport = useRef(null);
|
|
59
|
+
/** The frame around the scrolling well, which an editor's layer keeps inside. */
|
|
60
|
+
const frame = useRef(null);
|
|
61
|
+
/** The open editor's layer, measured to keep it inside the frame. */
|
|
62
|
+
const editorLayer = useRef(null);
|
|
40
63
|
const header = useRef(null);
|
|
41
64
|
/** Where the grid stood when it last scrolled; kept while it is out of layout (a hidden pane). */
|
|
42
65
|
const scrollTop = useRef(0);
|
|
43
66
|
/** Which way it last scrolled, which the rows drawn lean toward. */
|
|
44
67
|
const direction = useRef(0);
|
|
45
68
|
const [viewportHeight, setViewportHeight] = useState(FALLBACK_VIEWPORT);
|
|
69
|
+
/** Whether the columns overflow the well by at least the fade's width. */
|
|
70
|
+
const [fades, setFades] = useState(false);
|
|
46
71
|
/** The rows the last commit drew, and the facts the scroll listener judges them by. */
|
|
47
72
|
const committed = useRef(null);
|
|
48
73
|
const [, redraw] = useReducer((version) => version + 1, 0);
|
|
@@ -52,6 +77,8 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
|
|
|
52
77
|
const dragged = useRef(false);
|
|
53
78
|
/** Where the cell being edited sits in the window, which its editor is drawn over. */
|
|
54
79
|
const [editorBox, setEditorBox] = useState(null);
|
|
80
|
+
/** Where the editor's layer starts once measured against the frame. */
|
|
81
|
+
const [editorShift, setEditorShift] = useState(null);
|
|
55
82
|
/** A link's click waiting to see whether a double-click edits its cell instead. */
|
|
56
83
|
const pendingLink = useRef(null);
|
|
57
84
|
const canEdit = (row, column) => onEdit !== undefined && (editable?.(row, column) ?? false);
|
|
@@ -62,9 +89,10 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
|
|
|
62
89
|
const keyOf = (column, index) => column.id ?? String(index);
|
|
63
90
|
const [widths, setWidths] = useState(() => new Map(columns.map((column, index) => [
|
|
64
91
|
keyOf(column, index),
|
|
65
|
-
initialWidth(column.label, Array.from({ length: Math.min(rowCount, 20) }, (_, row) => cell(row, index)?.text ?? ''), CHAR_WIDTH)
|
|
92
|
+
initialWidth(column.label, Array.from({ length: Math.min(rowCount, 20) }, (_, row) => cell(row, index)?.text ?? ''), CHAR_WIDTH, onSort === undefined ? 0 : SORT_MARK_ROOM)
|
|
66
93
|
])));
|
|
67
|
-
const widthOf = (column, index) => widths.get(keyOf(column, index)) ??
|
|
94
|
+
const widthOf = (column, index) => widths.get(keyOf(column, index)) ??
|
|
95
|
+
initialWidth(column.label, [], CHAR_WIDTH, onSort === undefined ? 0 : SORT_MARK_ROOM);
|
|
68
96
|
// The rows drawn last while they still cover where the grid stands, a fresh window otherwise.
|
|
69
97
|
const held = committed.current;
|
|
70
98
|
const { from, to } = held !== null &&
|
|
@@ -91,6 +119,22 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
|
|
|
91
119
|
observer.observe(element);
|
|
92
120
|
return () => observer.disconnect();
|
|
93
121
|
}, []);
|
|
122
|
+
// The well fades its inline edges only while the columns overflow it by
|
|
123
|
+
// the fade's width or more, measured as it or the columns resize.
|
|
124
|
+
useLayoutEffect(() => {
|
|
125
|
+
const element = viewport.current;
|
|
126
|
+
if (element === null)
|
|
127
|
+
return;
|
|
128
|
+
const measure = () => setFades(element.scrollWidth - element.clientWidth >= FADE_MIN_OVERFLOW);
|
|
129
|
+
measure();
|
|
130
|
+
if (typeof ResizeObserver === 'undefined')
|
|
131
|
+
return;
|
|
132
|
+
const observer = new ResizeObserver(measure);
|
|
133
|
+
observer.observe(element);
|
|
134
|
+
if (header.current !== null)
|
|
135
|
+
observer.observe(header.current);
|
|
136
|
+
return () => observer.disconnect();
|
|
137
|
+
}, [template]);
|
|
94
138
|
useLayoutEffect(() => {
|
|
95
139
|
committed.current = { from, to, viewportHeight, rowCount };
|
|
96
140
|
});
|
|
@@ -152,7 +196,17 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
|
|
|
152
196
|
const place = () => {
|
|
153
197
|
const target = document.getElementById(`${id}-${editorRow}-${editorColumn}`);
|
|
154
198
|
const box = target?.getBoundingClientRect();
|
|
155
|
-
|
|
199
|
+
const well = frame.current?.getBoundingClientRect();
|
|
200
|
+
setEditorBox(box === undefined
|
|
201
|
+
? null
|
|
202
|
+
: {
|
|
203
|
+
left: box.left,
|
|
204
|
+
top: box.top,
|
|
205
|
+
width: box.width,
|
|
206
|
+
well: well === undefined
|
|
207
|
+
? { left: 0, right: window.innerWidth }
|
|
208
|
+
: { left: well.left, right: well.right }
|
|
209
|
+
});
|
|
156
210
|
};
|
|
157
211
|
place();
|
|
158
212
|
window.addEventListener('scroll', place, true);
|
|
@@ -163,6 +217,16 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
|
|
|
163
217
|
setEditorBox(null);
|
|
164
218
|
};
|
|
165
219
|
}, [id, editorRow, editorColumn, from, to]);
|
|
220
|
+
// A layer wider than its cell (a field with buttons beside it) that would
|
|
221
|
+
// cross the frame's right edge moves left to end inside it, measured
|
|
222
|
+
// before it paints; it follows whatever the caller's editor draws.
|
|
223
|
+
useLayoutEffect(() => {
|
|
224
|
+
const layer = editorLayer.current;
|
|
225
|
+
const next = editorBox === null || layer === null
|
|
226
|
+
? null
|
|
227
|
+
: editorLeft(editorBox.left - 1, layer.getBoundingClientRect().width, editorBox.well, EDITOR_MARGIN);
|
|
228
|
+
setEditorShift((held) => (held === next ? held : next));
|
|
229
|
+
}, [editorBox, editor]);
|
|
166
230
|
/** Scrolls a row into the viewport, below the header. */
|
|
167
231
|
const reveal = (row) => {
|
|
168
232
|
const element = viewport.current;
|
|
@@ -328,46 +392,57 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
|
|
|
328
392
|
viewport.current?.focus({ preventScroll: true });
|
|
329
393
|
}, tabIndex: -1, type: "button", children: shown.text })), editing &&
|
|
330
394
|
editorBox !== null &&
|
|
331
|
-
createPortal(_jsx("div", { className: "data-grid-editor", onClick: (event) => event.stopPropagation(), onDoubleClick: (event) => event.stopPropagation(), onPointerDown: (event) => event.stopPropagation(), style: {
|
|
332
|
-
|
|
395
|
+
createPortal(_jsx("div", { className: "data-grid-editor", onClick: (event) => event.stopPropagation(), onDoubleClick: (event) => event.stopPropagation(), onPointerDown: (event) => event.stopPropagation(), ref: editorLayer, style: {
|
|
396
|
+
'--data-grid-editor-cell': `${editorBox.width + 2}px`,
|
|
397
|
+
left: editorShift ?? editorBox.left - 1,
|
|
333
398
|
top: editorBox.top - 1,
|
|
334
399
|
minWidth: editorBox.width + 2,
|
|
335
|
-
// It keeps inside the
|
|
336
|
-
maxWidth: Math.max(
|
|
400
|
+
// It keeps inside the grid's frame and the window.
|
|
401
|
+
maxWidth: Math.max(EDITOR_MIN_WIDTH, Math.min(editorBox.well.right - editorBox.well.left, window.innerWidth) -
|
|
402
|
+
2 * EDITOR_MARGIN)
|
|
337
403
|
}, children: editor.node }),
|
|
338
404
|
// Where the caller says, so its styles reach the editor.
|
|
339
405
|
(viewport.current === null ? null : editorContainer?.(viewport.current)) ??
|
|
340
406
|
document.body)] }, keyOf(column, index)));
|
|
341
407
|
}), rowAction !== undefined && _jsx("div", { className: "data-grid-action", children: rowAction(row) })] }, row));
|
|
342
408
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
: '',
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
|
|
409
|
+
// The frame draws the border and corners; the well inside it scrolls, so
|
|
410
|
+
// the fade on columns past the frame (`.scroll-fade-x`, while they overflow
|
|
411
|
+
// by the fade's width) never erases them.
|
|
412
|
+
return (_jsx("div", { className: pointer ? 'data-grid pointer' : 'data-grid', ref: frame,
|
|
413
|
+
// The frame's own height, border included; the well fills what is left.
|
|
414
|
+
style: { maxHeight: maxHeight }, children: _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: fades ? 'data-grid-scroll scroll-fade-x' : 'data-grid-scroll', onKeyDown: onKeyDown, ref: viewport, role: "grid", 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) => {
|
|
415
|
+
const mark = marks.find((entry) => entry.column === index);
|
|
416
|
+
return (_jsxs("div", { "aria-colindex": index + 1, "aria-sort": mark?.direction, className: [
|
|
417
|
+
'data-grid-heading',
|
|
418
|
+
column.align === 'right' ? 'align-right' : '',
|
|
419
|
+
markedColumns?.has(index) === true ? 'marked' : '',
|
|
420
|
+
dragging?.from === index ? 'dragging' : '',
|
|
421
|
+
dragging !== null && dragging.to === index && dragging.from !== index
|
|
422
|
+
? dragging.to < dragging.from
|
|
423
|
+
? 'drop-before'
|
|
424
|
+
: 'drop-after'
|
|
425
|
+
: '',
|
|
426
|
+
onReorder === undefined ? '' : 'draggable'
|
|
427
|
+
]
|
|
428
|
+
.filter(Boolean)
|
|
429
|
+
.join(' '), onClick: (event) => {
|
|
430
|
+
if (draggedClick(event))
|
|
431
|
+
return;
|
|
432
|
+
onMarkColumn?.(index);
|
|
433
|
+
}, onDoubleClick: () => onHeaderDoubleClick?.(index), onPointerDown: (event) => onHeadingPointerDown(event, index), role: "columnheader", ...(column.tip === undefined
|
|
434
|
+
? onSort === undefined
|
|
435
|
+
? cutTooltip(column.label)
|
|
436
|
+
: {}
|
|
437
|
+
: describedTooltip(column.tip)), children: [onSort === undefined ? (_jsx("span", { className: "data-grid-label", children: column.label })) : (_jsxs("button", { className: "data-grid-label data-grid-sort", onClick: (event) => {
|
|
438
|
+
event.stopPropagation();
|
|
439
|
+
// A double-click's second click (`detail` 2) leaves the sort its first made.
|
|
440
|
+
if (draggedClick(event) || event.detail > 1)
|
|
441
|
+
return;
|
|
442
|
+
onSort(index, {
|
|
443
|
+
add: event.shiftKey && !event.altKey,
|
|
444
|
+
remove: event.altKey || event.ctrlKey
|
|
445
|
+
});
|
|
446
|
+
}, type: "button", children: [_jsx("span", { className: "data-grid-sort-name", ...(column.tip === undefined ? cutTooltip(column.label) : {}), children: column.label }), mark !== undefined && (_jsxs("span", { "aria-hidden": true, className: "data-grid-arrow", children: [mark.direction === 'ascending' ? (_jsx(ChevronUp, { size: ICON_SM })) : (_jsx(ChevronDown, { size: ICON_SM })), 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)));
|
|
447
|
+
}), rowAction !== undefined && _jsx("div", { className: "data-grid-action" })] }), _jsx("div", { className: rowCount === 0 ? 'data-grid-body empty' : 'data-grid-body', role: "rowgroup", style: rowCount === 0 ? undefined : { height: rowCount * ROW_HEIGHT }, children: rowCount === 0 && empty !== undefined ? (_jsx("div", { className: "data-grid-empty", role: "row", children: _jsx("div", { "aria-colspan": columns.length, role: "gridcell", children: empty }) })) : (rows) })] }) }));
|
|
373
448
|
}
|
|
@@ -42,10 +42,12 @@ export declare const MINIMUM_COLUMN_WIDTH = 40;
|
|
|
42
42
|
/** A column's width after its edge is dragged by `delta` pixels from `start`. */
|
|
43
43
|
export declare const resizedWidth: (start: number, delta: number) => number;
|
|
44
44
|
/**
|
|
45
|
-
* A column's first width from what it holds: its label
|
|
46
|
-
*
|
|
45
|
+
* A column's first width from what it holds: its label, with `labelRoom`
|
|
46
|
+
* pixels beside it for what the heading draws there (a sort mark), and up
|
|
47
|
+
* to the first rows' texts, at `charWidth` pixels a character, between 60
|
|
48
|
+
* and 360 pixels.
|
|
47
49
|
*/
|
|
48
|
-
export declare function initialWidth(label: string, samples: readonly string[], charWidth: number): number;
|
|
50
|
+
export declare function initialWidth(label: string, samples: readonly string[], charWidth: number, labelRoom?: number): number;
|
|
49
51
|
/**
|
|
50
52
|
* Where a header dragged from `from` lands with the pointer at `x`, among
|
|
51
53
|
* the header cells' edges: the column under the pointer, the first left of
|
|
@@ -55,3 +57,13 @@ export declare function dropPlace(x: number, edges: readonly {
|
|
|
55
57
|
readonly left: number;
|
|
56
58
|
readonly right: number;
|
|
57
59
|
}[], from: number): number;
|
|
60
|
+
/**
|
|
61
|
+
* Where the inline editor's layer starts, in window pixels: over its cell
|
|
62
|
+
* (`left`), unless a layer wider than the cell would cross the well's right
|
|
63
|
+
* edge, when it moves left to end `margin` inside it, never past the well's
|
|
64
|
+
* left edge.
|
|
65
|
+
*/
|
|
66
|
+
export declare function editorLeft(left: number, width: number, well: {
|
|
67
|
+
readonly left: number;
|
|
68
|
+
readonly right: number;
|
|
69
|
+
}, margin: number): number;
|
|
@@ -99,12 +99,14 @@ export const MINIMUM_COLUMN_WIDTH = 40;
|
|
|
99
99
|
/** A column's width after its edge is dragged by `delta` pixels from `start`. */
|
|
100
100
|
export const resizedWidth = (start, delta) => Math.max(MINIMUM_COLUMN_WIDTH, Math.round(start + delta));
|
|
101
101
|
/**
|
|
102
|
-
* A column's first width from what it holds: its label
|
|
103
|
-
*
|
|
102
|
+
* A column's first width from what it holds: its label, with `labelRoom`
|
|
103
|
+
* pixels beside it for what the heading draws there (a sort mark), and up
|
|
104
|
+
* to the first rows' texts, at `charWidth` pixels a character, between 60
|
|
105
|
+
* and 360 pixels.
|
|
104
106
|
*/
|
|
105
|
-
export function initialWidth(label, samples, charWidth) {
|
|
106
|
-
const longest = Math.max(label.length, ...samples.map((text) => Math.min(text.length, 60)));
|
|
107
|
-
return Math.min(360, Math.max(60, Math.round(longest
|
|
107
|
+
export function initialWidth(label, samples, charWidth, labelRoom = 0) {
|
|
108
|
+
const longest = Math.max(label.length * charWidth + labelRoom, ...samples.map((text) => Math.min(text.length, 60) * charWidth));
|
|
109
|
+
return Math.min(360, Math.max(60, Math.round(longest + 20)));
|
|
108
110
|
}
|
|
109
111
|
/**
|
|
110
112
|
* Where a header dragged from `from` lands with the pointer at `x`, among
|
|
@@ -119,3 +121,14 @@ export function dropPlace(x, edges, from) {
|
|
|
119
121
|
return at;
|
|
120
122
|
return x < (edges[0]?.left ?? 0) ? 0 : edges.length - 1;
|
|
121
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Where the inline editor's layer starts, in window pixels: over its cell
|
|
126
|
+
* (`left`), unless a layer wider than the cell would cross the well's right
|
|
127
|
+
* edge, when it moves left to end `margin` inside it, never past the well's
|
|
128
|
+
* left edge.
|
|
129
|
+
*/
|
|
130
|
+
export function editorLeft(left, width, well, margin) {
|
|
131
|
+
if (left + width <= well.right)
|
|
132
|
+
return left;
|
|
133
|
+
return Math.max(well.left, Math.min(left, well.right - margin - width));
|
|
134
|
+
}
|