@bigpixelrocket/uiok 0.2.2 → 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 (57) hide show
  1. package/CHANGELOG.md +37 -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/dialog/ConfirmDialog.d.ts +7 -1
  8. package/dist/dialog/ConfirmDialog.js +9 -4
  9. package/dist/dialog/DialogLists.d.ts +8 -1
  10. package/dist/dialog/DialogLists.js +3 -2
  11. package/dist/field/field.css +110 -2
  12. package/dist/filter/filter.css +16 -0
  13. package/dist/grid/DataGrid.d.ts +10 -2
  14. package/dist/grid/DataGrid.js +47 -13
  15. package/dist/grid/DataGrid.logic.d.ts +16 -0
  16. package/dist/grid/DataGrid.logic.js +28 -0
  17. package/dist/grid/grid.css +128 -4
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.js +1 -0
  20. package/dist/labels/UiokLabels.d.ts +3 -0
  21. package/dist/labels/UiokLabels.js +3 -1
  22. package/dist/labels/index.d.ts +1 -0
  23. package/dist/labels/index.js +1 -0
  24. package/dist/labels/keys.js +2 -0
  25. package/dist/labels/paneTabs.d.ts +27 -0
  26. package/dist/labels/paneTabs.js +10 -0
  27. package/dist/labels/selectAll.d.ts +4 -1
  28. package/dist/labels/selectAll.js +1 -1
  29. package/dist/legend/KeyLegendStrip.d.ts +9 -1
  30. package/dist/legend/KeyLegendStrip.js +119 -5
  31. package/dist/legend/legend.css +52 -0
  32. package/dist/listing/Listing.d.ts +23 -5
  33. package/dist/listing/Listing.js +11 -8
  34. package/dist/listing/listing.css +106 -3
  35. package/dist/pane/PaneActions.d.ts +3 -1
  36. package/dist/pane/PaneActions.js +6 -5
  37. package/dist/pane/PaneTabs.d.ts +92 -0
  38. package/dist/pane/PaneTabs.js +326 -0
  39. package/dist/pane/PaneTabs.logic.d.ts +97 -0
  40. package/dist/pane/PaneTabs.logic.js +158 -0
  41. package/dist/pane/index.d.ts +5 -1
  42. package/dist/pane/index.js +5 -1
  43. package/dist/pane/panetabs.css +408 -0
  44. package/dist/pane/useTabDrag.d.ts +49 -0
  45. package/dist/pane/useTabDrag.js +306 -0
  46. package/dist/segmented/SegmentedChoice.d.ts +8 -1
  47. package/dist/segmented/SegmentedChoice.js +7 -4
  48. package/dist/styles.css +8 -0
  49. package/dist/surface/GroupSwatch.d.ts +22 -0
  50. package/dist/surface/GroupSwatch.js +15 -0
  51. package/dist/surface/Tag.d.ts +26 -0
  52. package/dist/surface/Tag.js +12 -0
  53. package/dist/surface/index.d.ts +7 -0
  54. package/dist/surface/index.js +7 -0
  55. package/dist/surface/surface.css +116 -1
  56. package/dist/themes/tokens.js +12 -1
  57. package/package.json +1 -1
@@ -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';
@@ -6,6 +6,7 @@ import { type LegendLabels } from './legend.js';
6
6
  import { type ListingLabels } from './listing.js';
7
7
  import { type PagerLabels } from './pager.js';
8
8
  import { type PaletteLabels } from './palette.js';
9
+ import { type PaneTabsLabels } from './paneTabs.js';
9
10
  import { type SelectAllLabels } from './selectAll.js';
10
11
  import { type TerminalLabels } from './terminal.js';
11
12
  /**
@@ -36,6 +37,8 @@ export interface UiokLabels {
36
37
  readonly selectAll: SelectAllLabels;
37
38
  /** A terminal's menu, its failure line, and its input's fallback name (`@bigpixelrocket/uiok/terminal`). */
38
39
  readonly terminal: TerminalLabels;
40
+ /** A pane's tab strip: New Tab, close and picked names, and the folded tabs' count and menu (`PaneTabs`). */
41
+ readonly paneTabs: PaneTabsLabels;
39
42
  }
40
43
  /** The English labels every component falls back to without a `UiokProvider`. */
41
44
  export declare const DEFAULT_LABELS: UiokLabels;
@@ -14,6 +14,7 @@ import { DEFAULT_LEGEND_LABELS } from './legend.js';
14
14
  import { DEFAULT_LISTING_LABELS } from './listing.js';
15
15
  import { DEFAULT_PAGER_LABELS } from './pager.js';
16
16
  import { DEFAULT_PALETTE_LABELS } from './palette.js';
17
+ import { DEFAULT_PANE_TABS_LABELS } from './paneTabs.js';
17
18
  import { DEFAULT_SELECT_ALL_LABELS } from './selectAll.js';
18
19
  import { DEFAULT_TERMINAL_LABELS } from './terminal.js';
19
20
  /** The English labels every component falls back to without a `UiokProvider`. */
@@ -27,5 +28,6 @@ export const DEFAULT_LABELS = {
27
28
  pager: DEFAULT_PAGER_LABELS,
28
29
  palette: DEFAULT_PALETTE_LABELS,
29
30
  selectAll: DEFAULT_SELECT_ALL_LABELS,
30
- terminal: DEFAULT_TERMINAL_LABELS
31
+ terminal: DEFAULT_TERMINAL_LABELS,
32
+ paneTabs: DEFAULT_PANE_TABS_LABELS
31
33
  };
@@ -7,6 +7,7 @@ export { DEFAULT_LEGEND_LABELS, type LegendLabels } from './legend.js';
7
7
  export { DEFAULT_LISTING_LABELS, type ListingLabels, type SortDirection } from './listing.js';
8
8
  export { DEFAULT_PAGER_LABELS, type PagerLabels, type PagerStep } from './pager.js';
9
9
  export { DEFAULT_PALETTE_LABELS, type PaletteLabels } from './palette.js';
10
+ export { DEFAULT_PANE_TABS_LABELS, type PaneTabsLabels } from './paneTabs.js';
10
11
  export { DEFAULT_SELECT_ALL_LABELS, type SelectAllLabels } from './selectAll.js';
11
12
  export { DEFAULT_TERMINAL_LABELS, type TerminalLabels } from './terminal.js';
12
13
  export { DEFAULT_LABELS, type UiokLabels } from './UiokLabels.js';
@@ -7,6 +7,7 @@ export { DEFAULT_LEGEND_LABELS } from './legend.js';
7
7
  export { DEFAULT_LISTING_LABELS } from './listing.js';
8
8
  export { DEFAULT_PAGER_LABELS } from './pager.js';
9
9
  export { DEFAULT_PALETTE_LABELS } from './palette.js';
10
+ export { DEFAULT_PANE_TABS_LABELS } from './paneTabs.js';
10
11
  export { DEFAULT_SELECT_ALL_LABELS } from './selectAll.js';
11
12
  export { DEFAULT_TERMINAL_LABELS } from './terminal.js';
12
13
  export { DEFAULT_LABELS } from './UiokLabels.js';
@@ -12,6 +12,7 @@ export const DEFAULT_KEY_LABELS = {
12
12
  ArrowLeft: 'Left',
13
13
  ArrowRight: 'Right',
14
14
  Backspace: 'Backspace',
15
+ Delete: 'Delete',
15
16
  Enter: 'Return',
16
17
  Escape: 'Escape',
17
18
  Tab: 'Tab',
@@ -40,6 +41,7 @@ export const DEFAULT_KEY_LABELS = {
40
41
  ArrowLeft: '←',
41
42
  ArrowRight: '→',
42
43
  Backspace: '⌫',
44
+ Delete: '⌦',
43
45
  Enter: '↩',
44
46
  Escape: '⎋',
45
47
  Tab: '⇥',
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The words a pane's tab strip repeats whatever its tabs hold: New Tab, a
3
+ * tab's close control and picked state, the pinned and unsaved marks, and
4
+ * the folded tabs' count and menu. A tab's name and tooltip are its own.
5
+ */
6
+ export interface PaneTabsLabels {
7
+ /** The New Tab button's accessible name and tooltip: "New Tab". */
8
+ readonly newTab: string;
9
+ /** A tab's close control, given the tab's name: "Close orders". */
10
+ readonly close: (name: string) => string;
11
+ /** A tab picked beside the one in front, given its name: "orders, picked". */
12
+ readonly picked: (name: string) => string;
13
+ /** What a pinned tab's description adds: "Pinned". */
14
+ readonly pinned: string;
15
+ /** What a tab holding changes not saved adds, its mark's meaning: "Changes not saved". */
16
+ readonly notSaved: string;
17
+ /**
18
+ * The folded tabs' count, its tooltip and description, given how many
19
+ * tabs folded and how many of them hold changes not saved:
20
+ * "6 tabs folded here, 1 with changes not saved".
21
+ */
22
+ readonly folded: (count: number, dirty: number) => string;
23
+ /** The heading of the folded tabs' menu, and the count's accessible name: "Folded here". */
24
+ readonly foldedHeading: string;
25
+ }
26
+ /** English tab strip words: the `paneTabs` group `UiokProvider` starts from. */
27
+ export declare const DEFAULT_PANE_TABS_LABELS: PaneTabsLabels;
@@ -0,0 +1,10 @@
1
+ /** English tab strip words: the `paneTabs` group `UiokProvider` starts from. */
2
+ export const DEFAULT_PANE_TABS_LABELS = {
3
+ newTab: 'New Tab',
4
+ close: (name) => `Close ${name}`,
5
+ picked: (name) => `${name}, picked`,
6
+ pinned: 'Pinned',
7
+ notSaved: 'Changes not saved',
8
+ folded: (count, dirty) => `${count.toLocaleString('en-US')} ${count === 1 ? 'tab' : 'tabs'} folded here${dirty > 0 ? `, ${dirty.toLocaleString('en-US')} with changes not saved` : ''}`,
9
+ foldedHeading: 'Folded here'
10
+ };
@@ -6,7 +6,10 @@
6
6
  export interface SelectAllLabels {
7
7
  /** The checkbox that checks or clears every row: "Check all". */
8
8
  readonly checkAll: string;
9
- /** How many rows are checked, said before the bulk actions as a status line says it: "3 of 8 selected". */
9
+ /**
10
+ * How many rows are checked, said before the bulk actions as a status line
11
+ * says it: "3 of 8 selected", "1,000 of 20,000 selected".
12
+ */
10
13
  readonly selected: (checked: number, total: number) => string;
11
14
  /** The bar's accessible name when the caller gives none: "With selected". */
12
15
  readonly label: string;
@@ -1,6 +1,6 @@
1
1
  /** English select-all words: the `selectAll` group `UiokProvider` starts from. */
2
2
  export const DEFAULT_SELECT_ALL_LABELS = {
3
3
  checkAll: 'Check all',
4
- selected: (checked, total) => `${checked} of ${total} selected`,
4
+ selected: (checked, total) => `${checked.toLocaleString('en-US')} of ${total.toLocaleString('en-US')} selected`,
5
5
  label: 'With selected'
6
6
  };
@@ -20,6 +20,14 @@ export interface KeyLegendStripProps {
20
20
  * Without it no verbs fold, and each keeps a place of its own.
21
21
  */
22
22
  readonly pairLabel?: (pair: LegendPair) => string;
23
+ /**
24
+ * What the strip does with places that do not fit. `'drop'`, the default,
25
+ * leaves them off, so the strip ends on its last whole place. `'more'`
26
+ * folds them into a "+N" chip at the strip's end, its room kept whether or
27
+ * not anything folds, whose list names each folded verb with its whole
28
+ * chord and runs the one chosen.
29
+ */
30
+ readonly overflow?: 'drop' | 'more';
23
31
  }
24
32
  /**
25
33
  * A key legend strip along a window's bottom edge: a dock of fn and the four
@@ -33,4 +41,4 @@ export interface KeyLegendStripProps {
33
41
  * them. Its own name, its verb group's name, and a paired cap's name come
34
42
  * from `UiokLabels.legend`, chords in words from `UiokLabels.keys`.
35
43
  */
36
- export declare function KeyLegendStrip({ verbs, pairLabel }: KeyLegendStripProps): ReactElement;
44
+ export declare function KeyLegendStrip({ verbs, pairLabel, overflow }: KeyLegendStripProps): ReactElement;
@@ -1,11 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { ArrowBigUp, ChevronUp, Command, Option } from 'lucide-react';
3
- import { useEffect, useState } from 'react';
3
+ import { useEffect, useLayoutEffect, useRef, useState } from 'react';
4
4
  import { chordGlyphs, chordSpoken } from '../keyboard/KeyChord.logic.js';
5
5
  import { KeyChord } from '../keychord/KeyChord.js';
6
6
  import { useLabels } from '../labels/UiokProvider.js';
7
7
  import { tooltip } from '../tooltip/Tooltip.logic.js';
8
- import { legendUnits } from './KeyLegend.logic.js';
8
+ import { legendUnits, moreLabel, moreListAction } from './KeyLegend.logic.js';
9
9
  /** The dock's keys, as they sit at the keyboard's left edge: Shift on its row, then Control, Option, Command. */
10
10
  const DOCK = [
11
11
  { mod: 'shift', Icon: ArrowBigUp },
@@ -55,6 +55,33 @@ function useHeldModifiers() {
55
55
  const keepFocus = (event) => event.preventDefault();
56
56
  /** For a strip given no pair labels: no verb is read as one of a pair, so no label is asked for. */
57
57
  const UNPAIRED = { pairLabel: (pair) => pair, pairOf: () => undefined };
58
+ /**
59
+ * How many places at the tail of `row` wrapped onto the line the strip
60
+ * never shows: every child whose top sits below the first child's. Read
61
+ * again whenever the row changes size or its places change.
62
+ */
63
+ function useWrappedCount(row, places) {
64
+ const [count, setCount] = useState(0);
65
+ useLayoutEffect(() => {
66
+ if (row === null) {
67
+ return undefined;
68
+ }
69
+ const read = () => {
70
+ const children = [...row.children];
71
+ const top = children[0]?.offsetTop ?? 0;
72
+ const wrapped = children.filter((child) => child.offsetTop > top).length;
73
+ setCount((current) => (current === wrapped ? current : wrapped));
74
+ };
75
+ read();
76
+ if (typeof ResizeObserver === 'undefined') {
77
+ return undefined;
78
+ }
79
+ const observer = new ResizeObserver(read);
80
+ observer.observe(row);
81
+ return () => observer.disconnect();
82
+ }, [row, places]);
83
+ return count;
84
+ }
58
85
  /**
59
86
  * A key legend strip along a window's bottom edge: a dock of fn and the four
60
87
  * modifiers at the left, lit while held, then the verbs the keyboard offers
@@ -67,16 +94,103 @@ const UNPAIRED = { pairLabel: (pair) => pair, pairOf: () => undefined };
67
94
  * them. Its own name, its verb group's name, and a paired cap's name come
68
95
  * from `UiokLabels.legend`, chords in words from `UiokLabels.keys`.
69
96
  */
70
- export function KeyLegendStrip({ verbs, pairLabel }) {
97
+ export function KeyLegendStrip({ verbs, pairLabel, overflow = 'drop' }) {
71
98
  const { keys, legend } = useLabels();
72
99
  const held = useHeldModifiers();
73
100
  const units = legendUnits(verbs, pairLabel === undefined ? UNPAIRED : { pairLabel });
101
+ const [row, setRow] = useState(null);
102
+ const placesKey = units
103
+ .map((unit) => unit.label + chordGlyphs(unit.entries[0].chord, keys))
104
+ .join('\n');
105
+ const wrapped = useWrappedCount(overflow === 'more' ? row : null, placesKey);
106
+ const folded = overflow === 'more' && wrapped > 0 ? units.slice(units.length - wrapped) : [];
107
+ const foldedVerbs = folded.flatMap((unit) => unit.entries);
74
108
  const place = (unit) => {
75
109
  const [first, second] = unit.entries;
76
110
  if (second === undefined) {
77
- return (_jsxs("button", { onClick: first.run, onMouseDown: keepFocus, tabIndex: -1, type: "button", children: [_jsx(KeyChord, { chord: first.chord }), " ", first.label] }, first.label + chordGlyphs(first.chord, keys)));
111
+ return (_jsxs("button", { onClick: first.run, onMouseDown: keepFocus, tabIndex: -1, type: "button", ...tooltip(first.label, first.chord), children: [_jsx(KeyChord, { chord: first.chord }), " ", first.label] }, first.label + chordGlyphs(first.chord, keys)));
78
112
  }
79
113
  return (_jsxs("span", { className: "keylegend-pair", children: [unit.entries.map((entry) => (_jsx("button", { "aria-label": legend.capName(chordSpoken(entry.chord, keys), entry.label), className: "keylegend-cap", onClick: entry.run, onMouseDown: keepFocus, tabIndex: -1, type: "button", ...tooltip(entry.label, entry.chord), children: _jsx(KeyChord, { chord: entry.chord }) }, entry.chord.key))), _jsx("span", { "aria-hidden": true, className: "keylegend-pair-label", children: unit.label })] }, unit.label + chordGlyphs(first.chord, keys)));
80
114
  };
81
- return (_jsxs("footer", { "aria-label": legend.label, className: "keylegend", "data-fn": "false", "data-layer": "none", children: [_jsxs("span", { "aria-hidden": true, className: "keylegend-dock", children: [_jsx("span", { className: "keylegend-key keylegend-dock-fn", children: "fn" }), DOCK.map(({ mod, Icon }) => (_jsx("span", { className: held.has(mod) ? 'keylegend-key held' : 'keylegend-key', children: _jsx(Icon, { className: "key-icon" }) }, mod)))] }), _jsx("span", { className: "keylegend-row", children: _jsx("span", { "aria-label": legend.verbs, className: "keylegend-verbs", role: "group", children: units.map(place) }) })] }));
115
+ return (_jsxs("footer", { "aria-label": legend.label, className: "keylegend", "data-fn": "false", "data-layer": "none", children: [_jsxs("span", { "aria-hidden": true, className: "keylegend-dock", children: [_jsx("span", { className: "keylegend-key keylegend-dock-fn", children: "fn" }), DOCK.map(({ mod, Icon }) => (_jsx("span", { className: held.has(mod) ? 'keylegend-key held' : 'keylegend-key', children: _jsx(Icon, { className: "key-icon" }) }, mod)))] }), _jsxs("span", { className: "keylegend-row", children: [_jsx("span", { "aria-label": legend.verbs, className: "keylegend-verbs", ref: setRow, role: "group", children: units.map(place) }), overflow === 'more' ? (_jsx(LegendMore, { keys: keys, legend: legend, verbs: foldedVerbs })) : null] })] }));
116
+ }
117
+ /**
118
+ * The "+N" chip at a folding strip's end and its list above it. The chip
119
+ * keeps its room while nothing is folded (hidden, so the strip never jumps
120
+ * when the first place folds). Its list is a compact menu: the keys of
121
+ * `moreListAction`, a click or Return runs the verb and closes the list, and
122
+ * the focus goes back to where it was before the list opened, as a verb
123
+ * button's press keeps it, so the keyboard stays on what it was driving.
124
+ */
125
+ function LegendMore({ verbs, keys, legend }) {
126
+ const [open, setOpen] = useState(false);
127
+ const [cursor, setCursor] = useState(0);
128
+ const chip = useRef(null);
129
+ const list = useRef(null);
130
+ const returnRef = useRef(null);
131
+ const label = moreLabel(verbs.length, legend);
132
+ const shown = verbs.length > 0;
133
+ useEffect(() => {
134
+ if (!shown) {
135
+ setOpen(false);
136
+ }
137
+ }, [shown]);
138
+ useEffect(() => {
139
+ if (open) {
140
+ list.current?.focus();
141
+ }
142
+ }, [open]);
143
+ useEffect(() => {
144
+ if (!open) {
145
+ return undefined;
146
+ }
147
+ const away = (event) => {
148
+ const target = event.target;
149
+ if (target !== null && !list.current?.contains(target) && !chip.current?.contains(target)) {
150
+ setOpen(false);
151
+ }
152
+ };
153
+ document.addEventListener('pointerdown', away);
154
+ return () => document.removeEventListener('pointerdown', away);
155
+ }, [open]);
156
+ const close = () => {
157
+ const back = returnRef.current;
158
+ returnRef.current = null;
159
+ setOpen(false);
160
+ if (back instanceof HTMLElement && back.isConnected) {
161
+ back.focus({ preventScroll: true });
162
+ }
163
+ };
164
+ const run = (verb) => {
165
+ close();
166
+ verb?.run();
167
+ };
168
+ const onKeyDown = (event) => {
169
+ const action = moreListAction(event.nativeEvent, cursor, verbs.length);
170
+ if (action === null) {
171
+ return;
172
+ }
173
+ event.preventDefault();
174
+ event.stopPropagation();
175
+ if (action.kind === 'close') {
176
+ close();
177
+ }
178
+ else if (action.kind === 'cursor') {
179
+ setCursor(action.row);
180
+ }
181
+ else {
182
+ run(verbs[action.row]);
183
+ }
184
+ };
185
+ return (_jsxs("span", { className: "keylegend-more-place", children: [_jsx("button", { "aria-expanded": open, "aria-haspopup": "menu", "aria-label": label.spoken, "aria-hidden": shown ? undefined : true, className: "keylegend-more quiet-control", "data-empty": shown ? undefined : 'true', disabled: !shown, onClick: () => {
186
+ if (open) {
187
+ close();
188
+ return;
189
+ }
190
+ returnRef.current = document.activeElement;
191
+ setCursor(0);
192
+ setOpen(true);
193
+ },
194
+ // A press must not take the focus from what the keyboard was driving.
195
+ onMouseDown: keepFocus, ref: chip, tabIndex: -1, type: "button", ...tooltip(label.spoken), children: label.text }), open && shown ? (_jsx("div", { "aria-label": label.spoken, className: "folder-menu folder-menu-compact keylegend-more-list", "data-overlay": true, onKeyDown: onKeyDown, ref: list, role: "menu", tabIndex: -1, children: verbs.map((verb, index) => (_jsxs("button", { "aria-label": `${chordSpoken(verb.chord, keys)} ${verb.label}`, className: index === cursor ? 'folder-menu-option cursor' : 'folder-menu-option', onClick: () => run(verb), onMouseDown: keepFocus, onPointerEnter: () => setCursor(index), role: "menuitem", tabIndex: -1, type: "button", children: [_jsx("span", { "aria-hidden": true, className: "row-icon" }), _jsx("span", { className: "row-name", children: verb.label }), _jsx(KeyChord, { chord: verb.chord })] }, verb.label + chordGlyphs(verb.chord, keys)))) })) : null] }));
82
196
  }
@@ -171,3 +171,55 @@
171
171
  background: var(--accent-wash);
172
172
  color: var(--accent-text);
173
173
  }
174
+
175
+ /* The overflow chip (overflow="more"): the places that wrapped off the
176
+ line, counted ("+3") at the strip's end. It keeps its room while nothing
177
+ is folded, so the first place to fold never moves the others; then it is
178
+ hidden and out of reach. Its list is the compact menu, opened above it
179
+ and ending at its right edge. Hover and press come from .quiet-control. */
180
+ .keylegend-more-place {
181
+ position: relative;
182
+ flex: none;
183
+ margin-left: var(--space-2);
184
+ }
185
+
186
+ .keylegend-more {
187
+ display: inline-flex;
188
+ align-items: center;
189
+ justify-content: center;
190
+ min-width: var(--control-height);
191
+ height: var(--control-height-sm);
192
+ padding: 0 var(--space-3);
193
+ background: none;
194
+ border: none;
195
+ border-radius: var(--radius-sm);
196
+ color: var(--text-dim);
197
+ font: inherit;
198
+ font-size: var(--font-size-small);
199
+ font-variant-numeric: tabular-nums;
200
+ white-space: nowrap;
201
+ cursor: default;
202
+ }
203
+
204
+ .keylegend-more[data-empty] {
205
+ visibility: hidden;
206
+ }
207
+
208
+ /* Two classes, so it wins over the menu sheet's own place (.folder-menu
209
+ opens below and from the left), which loads after this one. */
210
+ .keylegend-more-place > .keylegend-more-list {
211
+ top: auto;
212
+ bottom: calc(100% + var(--space-2));
213
+ left: auto;
214
+ right: 0;
215
+ width: max-content;
216
+ min-width: 200px;
217
+ }
218
+
219
+ /* Right to left, the chip ends the strip on the left: the list ends there
220
+ too. :dir() follows the nearest direction, so an LTR footer inside an RTL
221
+ page keeps the left-to-right place. */
222
+ .keylegend-more-place > .keylegend-more-list:dir(rtl) {
223
+ left: 0;
224
+ right: auto;
225
+ }