@bigpixelrocket/uiok 0.2.1 → 0.2.3

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 (64) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/dist/button/TextLink.d.ts +27 -0
  3. package/dist/button/TextLink.js +15 -0
  4. package/dist/button/button.css +48 -0
  5. package/dist/button/index.d.ts +2 -1
  6. package/dist/button/index.js +2 -1
  7. package/dist/charts/Line.logic.d.ts +15 -1
  8. package/dist/charts/Line.logic.js +37 -4
  9. package/dist/charts/LineChart.d.ts +42 -2
  10. package/dist/charts/LineChart.js +41 -9
  11. package/dist/charts/Scatter.logic.js +7 -2
  12. package/dist/charts/charts.css +35 -5
  13. package/dist/charts/index.d.ts +1 -1
  14. package/dist/dialog/ConfirmDialog.d.ts +7 -1
  15. package/dist/dialog/ConfirmDialog.js +9 -4
  16. package/dist/dialog/DialogLists.d.ts +8 -1
  17. package/dist/dialog/DialogLists.js +3 -2
  18. package/dist/field/field.css +110 -2
  19. package/dist/filter/filter.css +16 -0
  20. package/dist/grid/DataGrid.d.ts +10 -2
  21. package/dist/grid/DataGrid.js +47 -13
  22. package/dist/grid/DataGrid.logic.d.ts +16 -0
  23. package/dist/grid/DataGrid.logic.js +28 -0
  24. package/dist/grid/grid.css +128 -4
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.js +1 -0
  27. package/dist/labels/UiokLabels.d.ts +3 -0
  28. package/dist/labels/UiokLabels.js +3 -1
  29. package/dist/labels/index.d.ts +1 -0
  30. package/dist/labels/index.js +1 -0
  31. package/dist/labels/keys.js +2 -0
  32. package/dist/labels/paneTabs.d.ts +27 -0
  33. package/dist/labels/paneTabs.js +10 -0
  34. package/dist/labels/selectAll.d.ts +4 -1
  35. package/dist/labels/selectAll.js +1 -1
  36. package/dist/legend/KeyLegendStrip.d.ts +9 -1
  37. package/dist/legend/KeyLegendStrip.js +119 -5
  38. package/dist/legend/legend.css +52 -0
  39. package/dist/listing/Listing.d.ts +23 -5
  40. package/dist/listing/Listing.js +11 -8
  41. package/dist/listing/listing.css +106 -3
  42. package/dist/pane/PaneActions.d.ts +3 -1
  43. package/dist/pane/PaneActions.js +6 -5
  44. package/dist/pane/PaneTabs.d.ts +92 -0
  45. package/dist/pane/PaneTabs.js +326 -0
  46. package/dist/pane/PaneTabs.logic.d.ts +97 -0
  47. package/dist/pane/PaneTabs.logic.js +158 -0
  48. package/dist/pane/index.d.ts +5 -1
  49. package/dist/pane/index.js +5 -1
  50. package/dist/pane/panetabs.css +408 -0
  51. package/dist/pane/useTabDrag.d.ts +49 -0
  52. package/dist/pane/useTabDrag.js +306 -0
  53. package/dist/segmented/SegmentedChoice.d.ts +8 -1
  54. package/dist/segmented/SegmentedChoice.js +7 -4
  55. package/dist/styles.css +8 -0
  56. package/dist/surface/GroupSwatch.d.ts +22 -0
  57. package/dist/surface/GroupSwatch.js +15 -0
  58. package/dist/surface/Tag.d.ts +26 -0
  59. package/dist/surface/Tag.js +12 -0
  60. package/dist/surface/index.d.ts +7 -0
  61. package/dist/surface/index.js +7 -0
  62. package/dist/surface/surface.css +116 -1
  63. package/dist/themes/tokens.js +13 -1
  64. package/package.json +1 -1
@@ -18,6 +18,9 @@
18
18
  focus edge.
19
19
  - .switch on a checkbox with role="switch": a pill track and its knob.
20
20
  - .range on an input of type range: a thin trough, its filled part, a knob.
21
+ - .field-editor on a container: the field's well round an editor the
22
+ page brings (a code editor), with its hover, focus edge, invalid,
23
+ read-only, and changed looks.
21
24
  - .field-label, .field-note, .field-problem: the words around a field,
22
25
  in the interface face; .field-group stacks them, .field-choice puts a
23
26
  check or switch beside its words, .field-grid lays label and value
@@ -164,14 +167,16 @@
164
167
  inset 0 1px 0 var(--well-shade);
165
168
  }
166
169
 
167
- .field[data-tone] {
170
+ .field[data-tone],
171
+ .field-editor[data-tone] {
168
172
  --field-tone-bar: var(--line-strong);
169
173
  }
170
174
 
171
175
  /* Right to left the bar stands on the right, the leading edge. The rule
172
176
  reads the dir attribute, as the listing's do: bundlers' CSS minifiers
173
177
  rewrite the direction pseudo-class into a list of languages. */
174
- .field[data-tone]:where([dir='rtl'] *, [dir='rtl']) {
178
+ .field[data-tone]:where([dir='rtl'] *, [dir='rtl']),
179
+ .field-editor[data-tone]:where([dir='rtl'] *, [dir='rtl']) {
175
180
  --field-tone-bar: calc(-1 * var(--line-strong));
176
181
  }
177
182
 
@@ -286,6 +291,96 @@ select.field option {
286
291
  color: var(--text);
287
292
  }
288
293
 
294
+ /* A list box's chosen rows, which the rule above would paint away: the
295
+ selection's colours while the list holds the keys, the quiet fill when
296
+ it does not (as a listing's selection goes quiet), and the fill with
297
+ quiet words when the list is off. A gradient, since a browser keeps its
298
+ own colour for a chosen option's background-color. */
299
+ select.field:is([multiple], [size]:not([size='1'])) option:checked {
300
+ background: linear-gradient(var(--selected-bg), var(--selected-bg));
301
+ color: var(--on-selected);
302
+ }
303
+
304
+ select.field:is([multiple], [size]:not([size='1'])):not(:focus) option:checked {
305
+ background: linear-gradient(var(--fill), var(--fill));
306
+ color: var(--text);
307
+ }
308
+
309
+ select.field:is([multiple], [size]:not([size='1'])):disabled option:checked {
310
+ background: linear-gradient(var(--fill), var(--fill));
311
+ color: var(--text-on-surface);
312
+ }
313
+
314
+ /* A field that holds no value (SQL NULL): its placeholder in the missing
315
+ value's look, dim italic, as a grid's NULL cell. */
316
+ .field.value-null::placeholder {
317
+ color: var(--text-dim);
318
+ font-style: italic;
319
+ }
320
+
321
+ /* -- A field's frame round an editor -- */
322
+
323
+ /* An editor the page brings (a code editor) that stands in a form as a
324
+ field does takes the field's well on its container: the outline,
325
+ corners, ground, and well shade, the hover lift, the accent focus edge
326
+ while anything inside holds the keys, the danger outline when invalid,
327
+ and the accent outline and bar of a changed value (data-tone="accent").
328
+ Read-only (.read-only) recesses the ground and draws no focus edge: the
329
+ value is there to read and copy. The editor fills the frame, which
330
+ clips it to the corners. */
331
+ .field-editor {
332
+ box-sizing: border-box;
333
+ min-width: 0;
334
+ overflow: hidden;
335
+ border: var(--line) solid var(--control-border);
336
+ border-radius: var(--radius-md);
337
+ box-shadow: inset 0 1px 0 var(--well-shade);
338
+ background: var(--ground);
339
+ color: var(--text);
340
+ transition:
341
+ border-color var(--duration-fast),
342
+ outline-color var(--duration-fast);
343
+ }
344
+
345
+ .field-editor:hover:not(
346
+ :focus-within,
347
+ [aria-invalid='true'],
348
+ [data-tone],
349
+ .read-only,
350
+ [aria-disabled='true']
351
+ ) {
352
+ border-color: var(--text);
353
+ }
354
+
355
+ .field-editor:focus-within {
356
+ border-color: var(--accent);
357
+ outline: var(--line) solid var(--accent);
358
+ outline-offset: var(--focus-offset-flush);
359
+ }
360
+
361
+ .field-editor[aria-invalid='true'] {
362
+ border-color: var(--danger);
363
+ }
364
+
365
+ .field-editor[aria-invalid='true']:focus-within {
366
+ outline-color: var(--danger);
367
+ }
368
+
369
+ .field-editor[data-tone='accent']:not([aria-invalid='true']) {
370
+ border-color: var(--accent);
371
+ box-shadow:
372
+ inset var(--field-tone-bar) 0 0 0 var(--accent),
373
+ inset 0 1px 0 var(--well-shade);
374
+ }
375
+
376
+ .field-editor.read-only,
377
+ .field-editor.read-only:focus-within {
378
+ border-color: var(--border-strong);
379
+ outline: none;
380
+ box-shadow: none;
381
+ background: var(--surface-recessed);
382
+ }
383
+
289
384
  /* -- Checkbox and radio -- */
290
385
 
291
386
  /* The on fill and the mark drawn on it: the accent, or a tone's. A mixed
@@ -711,6 +806,19 @@ select.field option {
711
806
  var(--font-ui);
712
807
  }
713
808
 
809
+ /* A group whose choices stand in columns (a long list of short choices):
810
+ --field-columns columns of equal width, 2 unless the host sets it; the
811
+ legend and any note span them all. */
812
+ .field-columns {
813
+ display: grid;
814
+ grid-template-columns: repeat(var(--field-columns, 2), minmax(0, 1fr));
815
+ gap: var(--space-2) var(--space-6);
816
+ }
817
+
818
+ .field-columns > :is(legend, .field-note, .field-problem) {
819
+ grid-column: 1 / -1;
820
+ }
821
+
714
822
  /* A check, radio, or switch with its words beside it; the whole label is
715
823
  the target. The words wrap rather than run out of the column. */
716
824
  .field-choice {
@@ -92,3 +92,19 @@
92
92
  :where(.listing-root) :is(:focus-within, :has(> input:not(:placeholder-shown))) > .filter-icon {
93
93
  color: var(--accent);
94
94
  }
95
+
96
+ /* A query the field refuses (its input aria-invalid="true", with the
97
+ reason in a problem line or a tooltip the input names): the field's foot
98
+ and its focus edge turn to --danger, and so does its lit mark, in place
99
+ of the divider and the accent. */
100
+ :where(.listing-root) .filter-field:has(input[aria-invalid='true']) {
101
+ border-bottom-color: var(--danger);
102
+ }
103
+
104
+ :where(.listing-root) .filter-field:has(input[aria-invalid='true']):focus-within {
105
+ box-shadow: inset 0 calc(-1 * var(--line-strong)) 0 var(--danger);
106
+ }
107
+
108
+ :where(.listing-root) .filter-field:has(input[aria-invalid='true']) > .filter-icon {
109
+ color: var(--danger);
110
+ }
@@ -86,6 +86,13 @@ export interface DataGridProps {
86
86
  readonly rowLead?: (row: number) => ReactNode;
87
87
  /** The width of the lead's column, the same on every row, in pixels. */
88
88
  readonly leadWidth?: number;
89
+ /**
90
+ * How many leading columns stay in view while the grid scrolls sideways
91
+ * (a key, a name), after the row's lead, which stays with them; a hairline
92
+ * marks the pin edge, and a header dragged to a new place never crosses
93
+ * it. None when absent or 0.
94
+ */
95
+ readonly pinnedColumns?: number;
89
96
  /** A control at a row's end, after its cells (Stop on a list of running jobs). */
90
97
  readonly rowAction?: (row: number) => ReactNode;
91
98
  /** The width of the row's end column, in pixels; as wide as it asks when absent. */
@@ -155,7 +162,8 @@ export interface DataGridProps {
155
162
  * What a caller adds, each only where it passes its handler: headers that
156
163
  * sort (Shift adds a column to the sort, Option or Control takes it out),
157
164
  * that drag to a new place, that copy their name on a double-click, and
158
- * that mark their column on a click; controls at each row's start and end;
165
+ * that mark their column on a click; leading columns pinned in view while
166
+ * the rest scroll sideways (`pinnedColumns`); controls at each row's start and end;
159
167
  * rows that mark on a click or Space; the row under the pointer lit; and
160
168
  * inline edit: a click or a double-click on an editable cell (`editTrigger`),
161
169
  * or Return on the cursor cell when it holds no link, asks to edit it
@@ -163,4 +171,4 @@ export interface DataGridProps {
163
171
  * a double-click starting an edit, a link cell's single click waits a
164
172
  * moment, so a double-click edits it rather than following it.
165
173
  */
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;
174
+ export declare function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows, rowLead, leadWidth, pinnedColumns, rowAction, actionWidth, sort, sorts, onSort, onReorder, onHeaderDoubleClick, markedColumns, onMarkColumn, rowMarked, onMarkRow, pointer, maxHeight, editable, editTrigger, onEdit, editor, editorContainer, empty }: DataGridProps): ReactElement;
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useId, useLayoutEffect, useReducer, useRef, useState } from 'react';
3
3
  import { ChevronDown, ChevronUp } from 'lucide-react';
4
4
  import { createPortal, flushSync } from 'react-dom';
5
- import { dropPlace, editorLeft, gridMove, initialWidth, movedCell, resizedWidth, visibleRows, windowHolds } from './DataGrid.logic.js';
5
+ import { dropPlace, editorLeft, gridMove, initialWidth, movedCell, pinnedDropPlace, resizedWidth, revealedScrollLeft, visibleRows, windowHolds } from './DataGrid.logic.js';
6
6
  import { ICON_SM } from '../icon/index.js';
7
7
  import { cutTooltip, describedTooltip } from '../tooltip/Tooltip.logic.js';
8
8
  /** Every row's height, so the grid can place any row without measuring it. */
@@ -45,7 +45,8 @@ const FADE_MIN_OVERFLOW = 12;
45
45
  * What a caller adds, each only where it passes its handler: headers that
46
46
  * sort (Shift adds a column to the sort, Option or Control takes it out),
47
47
  * that drag to a new place, that copy their name on a double-click, and
48
- * that mark their column on a click; controls at each row's start and end;
48
+ * that mark their column on a click; leading columns pinned in view while
49
+ * the rest scroll sideways (`pinnedColumns`); controls at each row's start and end;
49
50
  * rows that mark on a click or Space; the row under the pointer lit; and
50
51
  * inline edit: a click or a double-click on an editable cell (`editTrigger`),
51
52
  * or Return on the cursor cell when it holds no link, asks to edit it
@@ -53,7 +54,7 @@ const FADE_MIN_OVERFLOW = 12;
53
54
  * a double-click starting an edit, a link cell's single click waits a
54
55
  * moment, so a double-click edits it rather than following it.
55
56
  */
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 }) {
57
+ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows, rowLead, leadWidth = 0, pinnedColumns = 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 }) {
57
58
  const id = useId();
58
59
  const viewport = useRef(null);
59
60
  /** The frame around the scrolling well, which an editor's layer keeps inside. */
@@ -111,6 +112,22 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
111
112
  .filter((part) => part !== null)
112
113
  .join(' ');
113
114
  const page = Math.max(1, Math.floor(viewportHeight / ROW_HEIGHT) - 1);
115
+ /** The columns pinned, never more than there are. */
116
+ const pinned = Math.max(0, Math.min(Math.floor(pinnedColumns), columns.length));
117
+ /** Where each column starts from the rows' start, the lead included, and where the last ends. */
118
+ const starts = columns.reduce((edges, column, index) => [...edges, (edges[index] ?? 0) + widthOf(column, index)], [rowLead === undefined ? 0 : leadWidth]);
119
+ /** How wide the part that stays in view is: the lead and the pinned columns. */
120
+ const pinnedWidth = pinned === 0 ? 0 : (starts[pinned] ?? 0);
121
+ /** A pinned column's or lead's class and sticky offset; nothing for one that scrolls. */
122
+ const pinning = (index) => {
123
+ if (pinned === 0 || (index !== 'lead' && index >= pinned))
124
+ return { className: '' };
125
+ return {
126
+ className: index === pinned - 1 ? 'pinned pin-edge' : 'pinned',
127
+ style: { insetInlineStart: index === 'lead' ? 0 : starts[index] }
128
+ };
129
+ };
130
+ const leadPin = pinning('lead');
114
131
  // A column that does not sort shows no mark, whatever the sort names, and is not counted.
115
132
  const marks = (sorts ?? (sort === null || sort === undefined ? [] : [{ ...sort, position: 1 }])).filter((mark) => columns[mark.column]?.sortable !== false);
116
133
  useLayoutEffect(() => {
@@ -232,11 +249,21 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
232
249
  : editorLeft(editorBox.left - 1, layer.getBoundingClientRect().width, editorBox.well, EDITOR_MARGIN);
233
250
  setEditorShift((held) => (held === next ? held : next));
234
251
  }, [editorBox, editor]);
235
- /** Scrolls a row into the viewport, below the header. */
236
- const reveal = (row) => {
252
+ /**
253
+ * Scrolls a cell into the viewport: its row below the header, its column
254
+ * past the pinned ones. The sideways scroll is measured from the rows'
255
+ * start: a right-to-left well's scrollLeft runs from 0 down, so it is
256
+ * read and written with its sign turned.
257
+ */
258
+ const reveal = (row, column) => {
237
259
  const element = viewport.current;
238
260
  if (element === null)
239
261
  return;
262
+ const sign = getComputedStyle(element).direction === 'rtl' ? -1 : 1;
263
+ const from = sign * element.scrollLeft;
264
+ const to = revealedScrollLeft(from, element.clientWidth, starts[column] ?? 0, starts[column + 1] ?? 0, pinnedWidth);
265
+ if (to !== from)
266
+ element.scrollLeft = sign * to;
240
267
  const top = row * ROW_HEIGHT;
241
268
  const shown = element.clientHeight - ROW_HEIGHT;
242
269
  if (top < element.scrollTop)
@@ -273,7 +300,7 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
273
300
  return;
274
301
  event.preventDefault();
275
302
  setCursor(next);
276
- reveal(next.row);
303
+ reveal(next.row, next.column);
277
304
  };
278
305
  const onResizeStart = (event, column) => {
279
306
  if (event.button !== 0)
@@ -315,7 +342,10 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
315
342
  moving = true;
316
343
  target.setPointerCapture(event.pointerId);
317
344
  }
318
- setDragging({ from: column, to: dropPlace(move.clientX, headingEdges(), column) });
345
+ setDragging({
346
+ from: column,
347
+ to: pinnedDropPlace(dropPlace(move.clientX, headingEdges(), column), column, pinned)
348
+ });
319
349
  };
320
350
  const onUp = (up) => {
321
351
  target.removeEventListener('pointermove', onMove);
@@ -325,7 +355,7 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
325
355
  return;
326
356
  dragged.current = true;
327
357
  setDragging(null);
328
- const place = dropPlace(up.clientX, headingEdges(), column);
358
+ const place = pinnedDropPlace(dropPlace(up.clientX, headingEdges(), column), column, pinned);
329
359
  if (place !== column)
330
360
  onReorder(column, place);
331
361
  };
@@ -351,8 +381,9 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
351
381
  const rows = [];
352
382
  for (let row = from; row < to; row += 1) {
353
383
  const marked = rowMarked?.(row) ?? false;
354
- 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) => {
384
+ 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', leadPin.className].filter(Boolean).join(' '), style: leadPin.style, children: rowLead(row) })), columns.map((column, index) => {
355
385
  const shown = cell(row, index);
386
+ const pin = pinning(index);
356
387
  const current = cursor?.row === row && cursor.column === index;
357
388
  const editing = editor !== null && editor.row === row && editor.column === index;
358
389
  const edits = canEdit(row, index);
@@ -362,6 +393,7 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
362
393
  current ? 'cursor' : '',
363
394
  markedColumns?.has(index) === true ? 'marked' : '',
364
395
  editing ? 'editing' : '',
396
+ pin.className,
365
397
  shown?.className ?? ''
366
398
  ]
367
399
  .filter(Boolean)
@@ -377,7 +409,7 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
377
409
  window.clearTimeout(pendingLink.current);
378
410
  pendingLink.current = null;
379
411
  onEdit?.(row, index);
380
- }, 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) => {
412
+ }, onPointerDown: () => setCursor({ row, column: index }), role: "gridcell", style: pin.style, ...describedTooltip(shown?.tip ?? null), children: [shown?.content !== undefined ? (shown.content) : shown?.onOpen === undefined ? ((shown?.text ?? '')) : (_jsx("button", { className: "data-grid-link", onClick: (event) => {
381
413
  event.stopPropagation();
382
414
  const open = shown.onOpen;
383
415
  if (edits && editTrigger === 'double-click') {
@@ -416,8 +448,9 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
416
448
  // by the fade's width) never erases them.
417
449
  return (_jsx("div", { className: pointer ? 'data-grid pointer' : 'data-grid', ref: frame,
418
450
  // 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) => {
451
+ 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', leadPin.className].filter(Boolean).join(' '), style: leadPin.style })), columns.map((column, index) => {
420
452
  const sortable = sortsBy(column);
453
+ const pin = pinning(index);
421
454
  const mark = marks.find((entry) => entry.column === index);
422
455
  return (_jsxs("div", { "aria-colindex": index + 1, "aria-sort": mark?.direction, className: [
423
456
  'data-grid-heading',
@@ -429,14 +462,15 @@ export function DataGrid({ label, columns, rowCount, cell, copyText, onNeedRows,
429
462
  ? 'drop-before'
430
463
  : 'drop-after'
431
464
  : '',
432
- onReorder === undefined ? '' : 'draggable'
465
+ onReorder === undefined ? '' : 'draggable',
466
+ pin.className
433
467
  ]
434
468
  .filter(Boolean)
435
469
  .join(' '), onClick: (event) => {
436
470
  if (draggedClick(event))
437
471
  return;
438
472
  onMarkColumn?.(index);
439
- }, onDoubleClick: () => onHeaderDoubleClick?.(index), onPointerDown: (event) => onHeadingPointerDown(event, index), role: "columnheader", ...(column.tip === undefined
473
+ }, onDoubleClick: () => onHeaderDoubleClick?.(index), onPointerDown: (event) => onHeadingPointerDown(event, index), role: "columnheader", style: pin.style, ...(column.tip === undefined
440
474
  ? sortable
441
475
  ? {}
442
476
  : cutTooltip(column.label)
@@ -57,6 +57,22 @@ export declare function dropPlace(x: number, edges: readonly {
57
57
  readonly left: number;
58
58
  readonly right: number;
59
59
  }[], from: number): number;
60
+ /**
61
+ * Where a header dragged from `from` may land, given `place` under the
62
+ * pointer, in a grid whose first `pinned` columns stay in view: a pinned
63
+ * column stays among the pinned ones and any other among the rest, so a
64
+ * reorder never crosses the pin edge.
65
+ */
66
+ export declare function pinnedDropPlace(place: number, from: number, pinned: number): number;
67
+ /**
68
+ * Where a well scrolled sideways to `scrollLeft`, `width` pixels wide, scrolls
69
+ * to show a column spanning `left` to `right` (from the rows' start), when
70
+ * the first `pinned` pixels stay in view over whatever scrolls under them:
71
+ * the least scroll that shows the column whole past the pinned ones, its
72
+ * start first when it is wider than the room. A column inside the pinned
73
+ * part, or one already in view, leaves the scroll where it is.
74
+ */
75
+ export declare function revealedScrollLeft(scrollLeft: number, width: number, left: number, right: number, pinned?: number): number;
60
76
  /**
61
77
  * Where the inline editor's layer starts, in window pixels: over its cell
62
78
  * (`left`), unless a layer wider than the cell would cross the well's right
@@ -121,6 +121,34 @@ export function dropPlace(x, edges, from) {
121
121
  return at;
122
122
  return x < (edges[0]?.left ?? 0) ? 0 : edges.length - 1;
123
123
  }
124
+ /**
125
+ * Where a header dragged from `from` may land, given `place` under the
126
+ * pointer, in a grid whose first `pinned` columns stay in view: a pinned
127
+ * column stays among the pinned ones and any other among the rest, so a
128
+ * reorder never crosses the pin edge.
129
+ */
130
+ export function pinnedDropPlace(place, from, pinned) {
131
+ if (pinned <= 0)
132
+ return place;
133
+ return from < pinned ? Math.min(place, pinned - 1) : Math.max(place, pinned);
134
+ }
135
+ /**
136
+ * Where a well scrolled sideways to `scrollLeft`, `width` pixels wide, scrolls
137
+ * to show a column spanning `left` to `right` (from the rows' start), when
138
+ * the first `pinned` pixels stay in view over whatever scrolls under them:
139
+ * the least scroll that shows the column whole past the pinned ones, its
140
+ * start first when it is wider than the room. A column inside the pinned
141
+ * part, or one already in view, leaves the scroll where it is.
142
+ */
143
+ export function revealedScrollLeft(scrollLeft, width, left, right, pinned = 0) {
144
+ if (width <= 0 || left < pinned)
145
+ return scrollLeft;
146
+ if (left < scrollLeft + pinned)
147
+ return Math.max(0, left - pinned);
148
+ if (right > scrollLeft + width)
149
+ return Math.max(0, Math.min(left - pinned, right - width));
150
+ return scrollLeft;
151
+ }
124
152
  /**
125
153
  * Where the inline editor's layer starts, in window pixels: over its cell
126
154
  * (`left`), unless a layer wider than the cell would cross the well's right
@@ -11,7 +11,12 @@
11
11
  The frame fills the width it is given, as a desktop table view fills its
12
12
  pane: the header band and the rows run on past the last column, which
13
13
  leaves the slack as an empty filler. A grid that is a pane's whole body
14
- drops the frame with one scoped rule of the host's (docs/components/grid.md). */
14
+ drops the frame with one scoped rule of the host's (docs/components/grid.md).
15
+
16
+ Pinned columns (pinnedColumns) stick to the well's start while the rest
17
+ scroll under them, so each paints its row's tint over the bare ground
18
+ (--data-grid-row-tint, which each row state sets), and a hairline in
19
+ --border-strong marks the pin edge. */
15
20
  .data-grid {
16
21
  position: relative;
17
22
  display: flex;
@@ -194,6 +199,8 @@
194
199
  }
195
200
 
196
201
  .data-grid-row:nth-child(even) {
202
+ --data-grid-row-tint: var(--row-zebra);
203
+
197
204
  background: var(--row-zebra);
198
205
  }
199
206
 
@@ -223,6 +230,37 @@
223
230
  border-right: none;
224
231
  }
225
232
 
233
+ /* A pinned column, and the lead before it, stand over the columns that
234
+ scroll under them, on an opaque ground: the header's, or the bare ground
235
+ under the row's tint. Each cell state below paints over it. */
236
+ .data-grid-header > .pinned,
237
+ .data-grid-row > .pinned {
238
+ position: sticky;
239
+ z-index: var(--z-raised);
240
+ }
241
+
242
+ .data-grid-header > .pinned {
243
+ background: var(--surface-header);
244
+ }
245
+
246
+ .data-grid-row > .pinned {
247
+ background: linear-gradient(
248
+ var(--data-grid-row-tint, transparent),
249
+ var(--data-grid-row-tint, transparent)
250
+ )
251
+ var(--ground);
252
+ }
253
+
254
+ /* The pin edge: a stronger hairline than a column's, down the header and
255
+ every row, so what scrolls is seen to pass under the pinned columns. */
256
+ .data-grid-row > .pin-edge {
257
+ border-right-color: var(--border-strong);
258
+ }
259
+
260
+ .data-grid-heading.pin-edge .data-grid-resize:not(:hover, :active) {
261
+ border-right-color: var(--border-strong);
262
+ }
263
+
226
264
  .data-grid-cell.align-right,
227
265
  .data-grid-heading.align-right {
228
266
  text-align: right;
@@ -328,10 +366,14 @@
328
366
  from the cursor cell's ring and from the zebra rows; the bar is drawn
329
367
  over the lead and the first cell, whatever fills them. */
330
368
  .data-grid.pointer .data-grid-row:not(.marked):hover {
369
+ --data-grid-row-tint: var(--row-hover);
370
+
331
371
  background: var(--row-hover);
332
372
  }
333
373
 
334
374
  .data-grid-row.marked {
375
+ --data-grid-row-tint: var(--marked-bg);
376
+
335
377
  background: var(--marked-bg);
336
378
  }
337
379
 
@@ -399,6 +441,34 @@
399
441
  content: '';
400
442
  }
401
443
 
444
+ /* With pinned columns the bar stays in view on the row's first part (its
445
+ lead or first pinned cell), which would cover a bar on the row itself;
446
+ on a cursor cell there it joins the cursor's ring. */
447
+ .data-grid-row.marked:has(> .pinned)::before {
448
+ content: none;
449
+ }
450
+
451
+ .data-grid-row.marked > .pinned:first-child {
452
+ box-shadow: inset var(--line-strong) 0 0 var(--data-grid-bar, var(--marked-bar));
453
+ }
454
+
455
+ .data-grid-row.marked > .data-grid-cell.pinned.cursor:first-child {
456
+ box-shadow:
457
+ inset var(--line-strong) 0 0 var(--data-grid-bar, var(--marked-bar)),
458
+ inset 0 0 0 var(--line) var(--data-grid-ring, var(--accent));
459
+ }
460
+
461
+ .data-grid-row.marked > .pinned:first-child:where([dir='rtl'] *, [dir='rtl']) {
462
+ box-shadow: inset calc(-1 * var(--line-strong)) 0 0 var(--data-grid-bar, var(--marked-bar));
463
+ }
464
+
465
+ .data-grid-row.marked
466
+ > .data-grid-cell.pinned.cursor:first-child:where([dir='rtl'] *, [dir='rtl']) {
467
+ box-shadow:
468
+ inset calc(-1 * var(--line-strong)) 0 0 var(--data-grid-bar, var(--marked-bar)),
469
+ inset 0 0 0 var(--line) var(--data-grid-ring, var(--accent));
470
+ }
471
+
402
472
  /* A cell whose state replaces its row's paints its tint over the bare
403
473
  ground, not over the row's tint, so the text sits on the one ground its
404
474
  colour is floored on. */
@@ -414,15 +484,31 @@
414
484
  background: var(--accent-wash);
415
485
  }
416
486
 
487
+ /* A pinned marked column lays the same tint over its opaque ground. */
488
+ .data-grid-cell.marked:where(.pinned) {
489
+ background:
490
+ linear-gradient(var(--accent-wash), var(--accent-wash)),
491
+ linear-gradient(var(--data-grid-row-tint, transparent), var(--data-grid-row-tint, transparent))
492
+ var(--ground);
493
+ }
494
+
495
+ .data-grid-heading.marked:where(.pinned) {
496
+ background: linear-gradient(var(--accent-wash), var(--accent-wash)) var(--surface-header);
497
+ }
498
+
417
499
  .data-grid-heading.marked {
418
500
  box-shadow: inset 0 calc(-1 * var(--line-strong)) 0 var(--accent);
419
501
  color: var(--text);
420
502
  }
421
503
 
422
- .data-grid-row.marked .data-grid-cell.marked:not(.cursor, .cell-edited) {
504
+ .data-grid-row.marked .data-grid-cell.marked:not(.cursor, .cell-edited, .cell-removed) {
423
505
  background: none;
424
506
  }
425
507
 
508
+ .data-grid-row.marked .data-grid-cell.marked.pinned:not(.cursor, .cell-edited, .cell-removed) {
509
+ background: linear-gradient(var(--data-grid-row-tint), var(--data-grid-row-tint)) var(--ground);
510
+ }
511
+
426
512
  /* A header that drags to a new place, and where it lands. The pointer
427
513
  stays the arrow while it drags, as a desktop table's column does; the
428
514
  heading in the hand fades and lifts, and the accent bar marks where it
@@ -454,6 +540,10 @@
454
540
  .listing-root:has(.pane.active) .pane:not(.active, .active .pane) .data-grid
455
541
  )
456
542
  :is(.data-grid-row.marked, .data-grid-cell.marked, .data-grid-heading.marked) {
543
+ --data-grid-row-tint: var(--fill);
544
+ --data-grid-bar: var(--control-border-strong);
545
+ --data-grid-ring: var(--control-border-strong);
546
+
457
547
  background: var(--fill);
458
548
  }
459
549
 
@@ -478,11 +568,24 @@
478
568
  .listing-root:has(.pane.active) .pane:not(.active, .active .pane) .data-grid
479
569
  )
480
570
  .data-grid-row
481
- .data-grid-cell.cursor:not(.cell-edited) {
571
+ .data-grid-cell.cursor:not(.cell-edited, .cell-removed) {
482
572
  background: transparent;
483
573
  box-shadow: inset 0 0 0 var(--line) var(--control-border-strong);
484
574
  }
485
575
 
576
+ :where(
577
+ :root[data-window-inactive] .data-grid,
578
+ .listing-root:has(.pane.active) .pane:not(.active, .active .pane) .data-grid
579
+ )
580
+ .data-grid-row
581
+ .data-grid-cell.cursor.pinned:not(.cell-edited, .cell-removed) {
582
+ background: linear-gradient(
583
+ var(--data-grid-row-tint, transparent),
584
+ var(--data-grid-row-tint, transparent)
585
+ )
586
+ var(--ground);
587
+ }
588
+
486
589
  :where(
487
590
  :root[data-window-inactive] .data-grid,
488
591
  .listing-root:has(.pane.active) .pane:not(.active, .active .pane) .data-grid
@@ -600,6 +703,18 @@
600
703
  linear-gradient(var(--warning-wash-strong), var(--warning-wash-strong)) var(--ground);
601
704
  }
602
705
 
706
+ /* A row a save will delete (a cell whose className holds cell-removed),
707
+ the fourth of the cell-state family: each cell struck out, quiet, on the
708
+ danger wash over the bare ground, whatever row it sits in. The cursor's
709
+ ring and a marked row's bar draw over it. */
710
+ .data-grid-cell.cell-removed,
711
+ .data-grid-row.marked .data-grid-cell.cell-removed {
712
+ background: linear-gradient(var(--danger-wash), var(--danger-wash)) var(--ground);
713
+ color: var(--text-on-surface);
714
+ text-decoration: line-through;
715
+ text-decoration-color: var(--danger);
716
+ }
717
+
603
718
  /* Values that are not text: a missing value (SQL NULL) set apart from the
604
719
  word, and bytes shown by their kind and size. The classes are hooks a
605
720
  caller sets through a cell's className. On a row or cell in a state the
@@ -612,7 +727,7 @@
612
727
 
613
728
  .data-grid.pointer .data-grid-row:hover .data-grid-cell.cell-null,
614
729
  .data-grid-row.marked .data-grid-cell.cell-null,
615
- .data-grid-cell.cell-null:is(.cursor, .marked, .cell-edited) {
730
+ .data-grid-cell.cell-null:is(.cursor, .marked, .cell-edited, .cell-removed) {
616
731
  color: var(--text-on-surface);
617
732
  }
618
733
 
@@ -629,3 +744,12 @@
629
744
  box-shadow: none;
630
745
  color: transparent;
631
746
  }
747
+
748
+ /* A pinned cell under an editor keeps its opaque ground. */
749
+ .data-grid .data-grid-row .data-grid-cell.cursor.editing.pinned {
750
+ background: linear-gradient(
751
+ var(--data-grid-row-tint, transparent),
752
+ var(--data-grid-row-tint, transparent)
753
+ )
754
+ var(--ground);
755
+ }
package/dist/index.d.ts CHANGED
@@ -28,6 +28,7 @@ export * from './run/index.js';
28
28
  export * from './segmented/index.js';
29
29
  export * from './selectall/index.js';
30
30
  export * from './store/index.js';
31
+ export * from './surface/index.js';
31
32
  export * from './tabs/index.js';
32
33
  export * from './text/index.js';
33
34
  export * from './themes/index.js';
package/dist/index.js CHANGED
@@ -28,6 +28,7 @@ export * from './run/index.js';
28
28
  export * from './segmented/index.js';
29
29
  export * from './selectall/index.js';
30
30
  export * from './store/index.js';
31
+ export * from './surface/index.js';
31
32
  export * from './tabs/index.js';
32
33
  export * from './text/index.js';
33
34
  export * from './themes/index.js';