@bigpixelrocket/uiok 0.1.4 → 0.2.1

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.
Files changed (146) hide show
  1. package/CHANGELOG.md +95 -1
  2. package/README.md +1 -1
  3. package/dist/activity/ActivityBar.d.ts +21 -8
  4. package/dist/activity/ActivityBar.js +15 -5
  5. package/dist/activity/activity.css +53 -6
  6. package/dist/button/Button.d.ts +10 -6
  7. package/dist/button/Button.js +6 -1
  8. package/dist/button/button.css +201 -33
  9. package/dist/charts/Line.logic.d.ts +6 -0
  10. package/dist/charts/Line.logic.js +9 -0
  11. package/dist/charts/LineChart.js +11 -4
  12. package/dist/charts/Pie.logic.d.ts +89 -1
  13. package/dist/charts/Pie.logic.js +272 -2
  14. package/dist/charts/PieChart.d.ts +2 -1
  15. package/dist/charts/PieChart.js +12 -5
  16. package/dist/charts/PieFill.d.ts +15 -0
  17. package/dist/charts/PieFill.js +33 -0
  18. package/dist/charts/ResultChart.d.ts +2 -2
  19. package/dist/charts/ResultChart.js +173 -47
  20. package/dist/charts/ResultChart.logic.d.ts +60 -4
  21. package/dist/charts/ResultChart.logic.js +105 -6
  22. package/dist/charts/Scatter.logic.d.ts +18 -4
  23. package/dist/charts/Scatter.logic.js +98 -22
  24. package/dist/charts/ScatterChart.js +19 -5
  25. package/dist/charts/charts.css +233 -116
  26. package/dist/charts/seriesColour.d.ts +2 -0
  27. package/dist/charts/seriesColour.js +1 -1
  28. package/dist/datetime/DateTimePicker.d.ts +12 -2
  29. package/dist/datetime/DateTimePicker.js +61 -16
  30. package/dist/datetime/DateTimePicker.logic.d.ts +29 -0
  31. package/dist/datetime/DateTimePicker.logic.js +25 -0
  32. package/dist/datetime/datetime.css +89 -49
  33. package/dist/dialog/ConfirmDialog.d.ts +69 -20
  34. package/dist/dialog/ConfirmDialog.js +39 -12
  35. package/dist/dialog/DialogLayer.d.ts +25 -0
  36. package/dist/dialog/DialogLayer.js +24 -0
  37. package/dist/dialog/DialogLegend.d.ts +2 -1
  38. package/dist/dialog/DialogLegend.js +10 -5
  39. package/dist/dialog/DialogLegend.logic.d.ts +15 -3
  40. package/dist/dialog/DialogLegend.logic.js +8 -4
  41. package/dist/dialog/DialogLists.d.ts +157 -0
  42. package/dist/dialog/DialogLists.js +137 -0
  43. package/dist/dialog/ModalDialog.d.ts +20 -15
  44. package/dist/dialog/ModalDialog.js +22 -7
  45. package/dist/dialog/dialog.css +570 -127
  46. package/dist/dialog/index.d.ts +7 -1
  47. package/dist/dialog/index.js +7 -1
  48. package/dist/field/Check.d.ts +15 -0
  49. package/dist/field/Check.js +23 -0
  50. package/dist/field/field.css +812 -0
  51. package/dist/field/index.d.ts +10 -0
  52. package/dist/field/index.js +10 -0
  53. package/dist/field/labelHelp.d.ts +33 -0
  54. package/dist/field/labelHelp.js +22 -0
  55. package/dist/filter/FilterIcon.js +2 -1
  56. package/dist/filter/filter.css +72 -20
  57. package/dist/grid/DataGrid.d.ts +19 -2
  58. package/dist/grid/DataGrid.js +122 -41
  59. package/dist/grid/DataGrid.logic.d.ts +15 -3
  60. package/dist/grid/DataGrid.logic.js +18 -5
  61. package/dist/grid/grid.css +481 -56
  62. package/dist/icon/Spinner.d.ts +16 -0
  63. package/dist/icon/Spinner.js +13 -0
  64. package/dist/icon/index.d.ts +5 -0
  65. package/dist/icon/index.js +5 -0
  66. package/dist/icon/sizes.d.ts +19 -0
  67. package/dist/icon/sizes.js +19 -0
  68. package/dist/index.d.ts +2 -0
  69. package/dist/index.js +2 -0
  70. package/dist/keychord/KeyChord.d.ts +12 -1
  71. package/dist/keychord/KeyChord.js +2 -2
  72. package/dist/keychord/index.d.ts +1 -1
  73. package/dist/keychord/keychord.css +87 -9
  74. package/dist/labels/dialog.d.ts +12 -1
  75. package/dist/labels/dialog.js +3 -1
  76. package/dist/labels/selectAll.d.ts +4 -4
  77. package/dist/labels/selectAll.js +1 -1
  78. package/dist/legend/KeyLegendStrip.js +1 -1
  79. package/dist/legend/legend.css +82 -57
  80. package/dist/listing/Listing.d.ts +17 -10
  81. package/dist/listing/Listing.js +33 -26
  82. package/dist/listing/listing.css +1665 -237
  83. package/dist/menu/menu.css +227 -67
  84. package/dist/menu/useBellBeat.js +2 -2
  85. package/dist/namecut/NameCut.d.ts +3 -1
  86. package/dist/namecut/NameCut.js +152 -5
  87. package/dist/namecut/NameCut.logic.d.ts +5 -3
  88. package/dist/namecut/NameCut.logic.js +20 -5
  89. package/dist/namecut/namecut.css +27 -7
  90. package/dist/pager/Pager.d.ts +12 -4
  91. package/dist/pager/Pager.js +21 -7
  92. package/dist/pager/pager.css +41 -30
  93. package/dist/palette/Palette.js +2 -1
  94. package/dist/palette/palette.css +121 -60
  95. package/dist/pane/PaneActions.d.ts +56 -14
  96. package/dist/pane/PaneActions.js +64 -16
  97. package/dist/pane/PaneFrame.d.ts +37 -5
  98. package/dist/pane/PaneFrame.js +246 -11
  99. package/dist/pane/index.d.ts +4 -2
  100. package/dist/pane/index.js +4 -2
  101. package/dist/pane/toolWords.d.ts +14 -0
  102. package/dist/pane/toolWords.js +26 -0
  103. package/dist/pane/useToolbarFit.d.ts +25 -0
  104. package/dist/pane/useToolbarFit.js +95 -0
  105. package/dist/run/RunHeader.d.ts +5 -3
  106. package/dist/run/RunHeader.js +11 -8
  107. package/dist/run/run.css +64 -79
  108. package/dist/segmented/SegmentedChoice.d.ts +18 -2
  109. package/dist/segmented/SegmentedChoice.js +18 -7
  110. package/dist/segmented/segmented.css +62 -22
  111. package/dist/selectall/SelectAllBar.d.ts +4 -3
  112. package/dist/selectall/SelectAllBar.js +4 -3
  113. package/dist/selectall/selectall.css +17 -12
  114. package/dist/shell/shell.css +1073 -0
  115. package/dist/styles.css +620 -22
  116. package/dist/surface/surface.css +154 -0
  117. package/dist/tabs/PageTabs.d.ts +10 -5
  118. package/dist/tabs/PageTabs.js +126 -37
  119. package/dist/tabs/tabs.css +131 -51
  120. package/dist/terminal/Terminal.js +3 -1
  121. package/dist/terminal/Terminal.logic.d.ts +5 -4
  122. package/dist/terminal/Terminal.logic.js +9 -4
  123. package/dist/terminal/TerminalMenu.d.ts +4 -1
  124. package/dist/terminal/TerminalMenu.js +12 -5
  125. package/dist/terminal/ghostty/contrast.logic.d.ts +45 -0
  126. package/dist/terminal/ghostty/contrast.logic.js +130 -0
  127. package/dist/terminal/ghostty/core.d.ts +6 -0
  128. package/dist/terminal/ghostty/renderer.d.ts +9 -2
  129. package/dist/terminal/ghostty/renderer.js +91 -14
  130. package/dist/terminal/ghostty/surface.d.ts +8 -0
  131. package/dist/terminal/ghostty/surface.js +27 -1
  132. package/dist/terminal/terminal.css +87 -61
  133. package/dist/text/text.css +16 -7
  134. package/dist/themes/catalog.js +4 -3
  135. package/dist/themes/themes.generated.css +1307 -264
  136. package/dist/themes/tokens.d.ts +69 -14
  137. package/dist/themes/tokens.js +920 -97
  138. package/dist/tokens.css +239 -0
  139. package/dist/tooltip/Tooltip.d.ts +6 -0
  140. package/dist/tooltip/Tooltip.js +48 -6
  141. package/dist/tooltip/Tooltip.logic.d.ts +89 -12
  142. package/dist/tooltip/Tooltip.logic.js +142 -20
  143. package/dist/tooltip/index.d.ts +1 -1
  144. package/dist/tooltip/index.js +1 -1
  145. package/dist/tooltip/tooltip.css +39 -9
  146. 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: 13 }) }));
11
+ return (_jsx("span", { "aria-hidden": true, className: "filter-icon", children: _jsx(ListFilter, { size: ICON_MD }) }));
11
12
  }
@@ -1,42 +1,94 @@
1
- /* ---- Filter field marks (FilterIcon, FilterEscape) ----
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 key that leaves a filter field (FilterEscape), drawn as a plain key
7
- cap; the field's mark is .filter-icon. */
8
- .listing-root .filter-escape {
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: 8px;
44
+ margin-left: var(--space-4);
12
45
  padding: 0;
13
46
  border: none;
14
- border-radius: 4px;
47
+ border-radius: var(--radius-sm);
15
48
  background: none;
16
- cursor: pointer;
49
+ cursor: default;
17
50
  }
18
51
 
19
- .listing-root .filter-escape .keychord {
20
- box-sizing: border-box;
21
- height: 16px;
22
- padding: 0 4px;
23
- border: 1px solid var(--border-strong);
24
- border-radius: 4px;
25
- background: var(--bg-panel);
26
- color: var(--text);
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:hover:enabled:not([aria-disabled='true']) .keychord {
30
- border-color: color-mix(in srgb, var(--accent) 50%, var(--border-strong));
31
- background: linear-gradient(var(--hover-wash), transparent) var(--bg-panel);
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: 20px;
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
  }
@@ -9,6 +9,13 @@ export interface DataGridColumn {
9
9
  readonly align?: 'right';
10
10
  /** Names the column across reorders, so its width follows it; its index when absent. */
11
11
  readonly id?: string;
12
+ /**
13
+ * False keeps the header a plain label while the grid sorts (a value with
14
+ * no order, such as a JSON document or a point): no sort control, no room
15
+ * for the sort mark, no `aria-sort`, and a click on it never asks
16
+ * `onSort`. Sortable when absent or true.
17
+ */
18
+ readonly sortable?: boolean;
12
19
  }
13
20
  /** The column a grid is sorted by, and which way. */
14
21
  export interface DataGridSort {
@@ -87,7 +94,10 @@ export interface DataGridProps {
87
94
  readonly sort?: DataGridSort | null;
88
95
  /** The columns the rows are sorted by, in order, each header numbered while there are several. */
89
96
  readonly sorts?: readonly DataGridSortMark[];
90
- /** Makes each header a control that asks to sort by its column; the caller orders the rows. */
97
+ /**
98
+ * Makes each header a control that asks to sort by its column, except a
99
+ * column with `sortable: false`; the caller orders the rows.
100
+ */
91
101
  readonly onSort?: (column: number, click: DataGridSortClick) => void;
92
102
  /** Lets a header be dragged to another column's place; the caller reorders `columns`. */
93
103
  readonly onReorder?: (from: number, to: number) => void;
@@ -124,6 +134,13 @@ export interface DataGridProps {
124
134
  * returns null.
125
135
  */
126
136
  readonly editorContainer?: (grid: HTMLElement) => Element | null;
137
+ /**
138
+ * What the grid says when it has no rows (a sentence such as "No rows
139
+ * match the filter", or a sentence and an action), drawn dim where the
140
+ * first row would be, in the grid's cell type, in the empty well under the
141
+ * header. The well stays blank without it.
142
+ */
143
+ readonly empty?: ReactNode;
127
144
  }
128
145
  /**
129
146
  * A grid of rows of any count, drawn a screenful at a time under a header
@@ -146,4 +163,4 @@ export interface DataGridProps {
146
163
  * a double-click starting an edit, a link cell's single click waits a
147
164
  * moment, so a double-click edits it rather than following it.
148
165
  */
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;
166
+ 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;
@@ -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 { describedTooltip } from '../tooltip/Tooltip.logic.js';
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);
@@ -60,11 +87,16 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
60
87
  window.clearTimeout(pendingLink.current);
61
88
  }, []);
62
89
  const keyOf = (column, index) => column.id ?? String(index);
90
+ /** Whether a column's header is a sort control: the grid sorts and the column allows it. */
91
+ const sortsBy = (column) => onSort !== undefined && column.sortable !== false;
92
+ /** The room a column's heading keeps beside its label for the sort mark. */
93
+ const labelRoom = (column) => (sortsBy(column) ? SORT_MARK_ROOM : 0);
63
94
  const [widths, setWidths] = useState(() => new Map(columns.map((column, index) => [
64
95
  keyOf(column, index),
65
- initialWidth(column.label, Array.from({ length: Math.min(rowCount, 20) }, (_, row) => cell(row, index)?.text ?? ''), CHAR_WIDTH)
96
+ initialWidth(column.label, Array.from({ length: Math.min(rowCount, 20) }, (_, row) => cell(row, index)?.text ?? ''), CHAR_WIDTH, labelRoom(column))
66
97
  ])));
67
- const widthOf = (column, index) => widths.get(keyOf(column, index)) ?? initialWidth(column.label, [], CHAR_WIDTH);
98
+ const widthOf = (column, index) => widths.get(keyOf(column, index)) ??
99
+ initialWidth(column.label, [], CHAR_WIDTH, labelRoom(column));
68
100
  // The rows drawn last while they still cover where the grid stands, a fresh window otherwise.
69
101
  const held = committed.current;
70
102
  const { from, to } = held !== null &&
@@ -79,7 +111,8 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
79
111
  .filter((part) => part !== null)
80
112
  .join(' ');
81
113
  const page = Math.max(1, Math.floor(viewportHeight / ROW_HEIGHT) - 1);
82
- const marks = sorts ?? (sort === null || sort === undefined ? [] : [{ ...sort, position: 1 }]);
114
+ // A column that does not sort shows no mark, whatever the sort names, and is not counted.
115
+ const marks = (sorts ?? (sort === null || sort === undefined ? [] : [{ ...sort, position: 1 }])).filter((mark) => columns[mark.column]?.sortable !== false);
83
116
  useLayoutEffect(() => {
84
117
  const element = viewport.current;
85
118
  if (element === null || typeof ResizeObserver === 'undefined')
@@ -91,6 +124,22 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
91
124
  observer.observe(element);
92
125
  return () => observer.disconnect();
93
126
  }, []);
127
+ // The well fades its inline edges only while the columns overflow it by
128
+ // the fade's width or more, measured as it or the columns resize.
129
+ useLayoutEffect(() => {
130
+ const element = viewport.current;
131
+ if (element === null)
132
+ return;
133
+ const measure = () => setFades(element.scrollWidth - element.clientWidth >= FADE_MIN_OVERFLOW);
134
+ measure();
135
+ if (typeof ResizeObserver === 'undefined')
136
+ return;
137
+ const observer = new ResizeObserver(measure);
138
+ observer.observe(element);
139
+ if (header.current !== null)
140
+ observer.observe(header.current);
141
+ return () => observer.disconnect();
142
+ }, [template]);
94
143
  useLayoutEffect(() => {
95
144
  committed.current = { from, to, viewportHeight, rowCount };
96
145
  });
@@ -152,7 +201,17 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
152
201
  const place = () => {
153
202
  const target = document.getElementById(`${id}-${editorRow}-${editorColumn}`);
154
203
  const box = target?.getBoundingClientRect();
155
- setEditorBox(box === undefined ? null : { left: box.left, top: box.top, width: box.width });
204
+ const well = frame.current?.getBoundingClientRect();
205
+ setEditorBox(box === undefined
206
+ ? null
207
+ : {
208
+ left: box.left,
209
+ top: box.top,
210
+ width: box.width,
211
+ well: well === undefined
212
+ ? { left: 0, right: window.innerWidth }
213
+ : { left: well.left, right: well.right }
214
+ });
156
215
  };
157
216
  place();
158
217
  window.addEventListener('scroll', place, true);
@@ -163,6 +222,16 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
163
222
  setEditorBox(null);
164
223
  };
165
224
  }, [id, editorRow, editorColumn, from, to]);
225
+ // A layer wider than its cell (a field with buttons beside it) that would
226
+ // cross the frame's right edge moves left to end inside it, measured
227
+ // before it paints; it follows whatever the caller's editor draws.
228
+ useLayoutEffect(() => {
229
+ const layer = editorLayer.current;
230
+ const next = editorBox === null || layer === null
231
+ ? null
232
+ : editorLeft(editorBox.left - 1, layer.getBoundingClientRect().width, editorBox.well, EDITOR_MARGIN);
233
+ setEditorShift((held) => (held === next ? held : next));
234
+ }, [editorBox, editor]);
166
235
  /** Scrolls a row into the viewport, below the header. */
167
236
  const reveal = (row) => {
168
237
  const element = viewport.current;
@@ -328,46 +397,58 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
328
397
  viewport.current?.focus({ preventScroll: true });
329
398
  }, tabIndex: -1, type: "button", children: shown.text })), editing &&
330
399
  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,
400
+ createPortal(_jsx("div", { className: "data-grid-editor", onClick: (event) => event.stopPropagation(), onDoubleClick: (event) => event.stopPropagation(), onPointerDown: (event) => event.stopPropagation(), ref: editorLayer, style: {
401
+ '--data-grid-editor-cell': `${editorBox.width + 2}px`,
402
+ left: editorShift ?? editorBox.left - 1,
333
403
  top: editorBox.top - 1,
334
404
  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)
405
+ // It keeps inside the grid's frame and the window.
406
+ maxWidth: Math.max(EDITOR_MIN_WIDTH, Math.min(editorBox.well.right - editorBox.well.left, window.innerWidth) -
407
+ 2 * EDITOR_MARGIN)
337
408
  }, children: editor.node }),
338
409
  // Where the caller says, so its styles reach the editor.
339
410
  (viewport.current === null ? null : editorContainer?.(viewport.current)) ??
340
411
  document.body)] }, keyOf(column, index)));
341
412
  }), rowAction !== undefined && _jsx("div", { className: "data-grid-action", children: rowAction(row) })] }, row));
342
413
  }
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 })] }));
414
+ // The frame draws the border and corners; the well inside it scrolls, so
415
+ // the fade on columns past the frame (`.scroll-fade-x`, while they overflow
416
+ // by the fade's width) never erases them.
417
+ return (_jsx("div", { className: pointer ? 'data-grid pointer' : 'data-grid', ref: frame,
418
+ // The frame's own height, border included; the well fills what is left.
419
+ 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) => {
420
+ const sortable = sortsBy(column);
421
+ const mark = marks.find((entry) => entry.column === index);
422
+ return (_jsxs("div", { "aria-colindex": index + 1, "aria-sort": mark?.direction, className: [
423
+ 'data-grid-heading',
424
+ column.align === 'right' ? 'align-right' : '',
425
+ markedColumns?.has(index) === true ? 'marked' : '',
426
+ dragging?.from === index ? 'dragging' : '',
427
+ dragging !== null && dragging.to === index && dragging.from !== index
428
+ ? dragging.to < dragging.from
429
+ ? 'drop-before'
430
+ : 'drop-after'
431
+ : '',
432
+ onReorder === undefined ? '' : 'draggable'
433
+ ]
434
+ .filter(Boolean)
435
+ .join(' '), onClick: (event) => {
436
+ if (draggedClick(event))
437
+ return;
438
+ onMarkColumn?.(index);
439
+ }, onDoubleClick: () => onHeaderDoubleClick?.(index), onPointerDown: (event) => onHeadingPointerDown(event, index), role: "columnheader", ...(column.tip === undefined
440
+ ? sortable
441
+ ? {}
442
+ : cutTooltip(column.label)
443
+ : describedTooltip(column.tip)), children: [onSort === undefined || !sortable ? (_jsx("span", { className: "data-grid-label", children: column.label })) : (_jsxs("button", { className: "data-grid-label data-grid-sort", onClick: (event) => {
444
+ event.stopPropagation();
445
+ // A double-click's second click (`detail` 2) leaves the sort its first made.
446
+ if (draggedClick(event) || event.detail > 1)
447
+ return;
448
+ onSort(index, {
449
+ add: event.shiftKey && !event.altKey,
450
+ remove: event.altKey || event.ctrlKey
451
+ });
452
+ }, 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)));
453
+ }), 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
454
  }
@@ -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 and up to the first
46
- * rows' texts, at `charWidth` pixels a character, between 60 and 360 pixels.
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 and up to the first
103
- * rows' texts, at `charWidth` pixels a character, between 60 and 360 pixels.
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 * charWidth + 20)));
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
+ }