@liberation-data/desk 0.40.1 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +61 -8
  2. package/dist/css/controls.css +21 -2
  3. package/dist/css/dock.css +1 -1
  4. package/dist/css/looks.css +50 -4
  5. package/dist/css/tokens.css +1 -0
  6. package/dist/css/windows.css +165 -6
  7. package/dist/desk.css +238 -13
  8. package/dist/react/Desktop.d.ts +12 -3
  9. package/dist/react/Desktop.d.ts.map +1 -1
  10. package/dist/react/Desktop.js +20 -10
  11. package/dist/react/Desktop.js.map +1 -1
  12. package/dist/react/MenuBar.d.ts +9 -2
  13. package/dist/react/MenuBar.d.ts.map +1 -1
  14. package/dist/react/MenuBar.js +15 -0
  15. package/dist/react/MenuBar.js.map +1 -1
  16. package/dist/react/arrange.d.ts +6 -0
  17. package/dist/react/arrange.d.ts.map +1 -1
  18. package/dist/react/arrange.js +21 -0
  19. package/dist/react/arrange.js.map +1 -1
  20. package/dist/react/hostMenu.d.ts +6 -0
  21. package/dist/react/hostMenu.d.ts.map +1 -1
  22. package/dist/react/hostMenu.js +1 -0
  23. package/dist/react/hostMenu.js.map +1 -1
  24. package/dist/react/index.d.ts +3 -1
  25. package/dist/react/index.d.ts.map +1 -1
  26. package/dist/react/index.js +2 -1
  27. package/dist/react/index.js.map +1 -1
  28. package/dist/react/tabs.d.ts +7 -1
  29. package/dist/react/tabs.d.ts.map +1 -1
  30. package/dist/react/tabs.js +13 -8
  31. package/dist/react/tabs.js.map +1 -1
  32. package/dist/react/widgets.d.ts +33 -0
  33. package/dist/react/widgets.d.ts.map +1 -0
  34. package/dist/react/widgets.js +213 -0
  35. package/dist/react/widgets.js.map +1 -0
  36. package/llms.txt +33 -7
  37. package/package.json +2 -2
  38. package/src/css/controls.css +21 -2
  39. package/src/css/dock.css +1 -1
  40. package/src/css/looks.css +50 -4
  41. package/src/css/tokens.css +1 -0
  42. package/src/css/windows.css +165 -6
  43. package/src/react/Desktop.tsx +33 -11
  44. package/src/react/MenuBar.tsx +20 -2
  45. package/src/react/arrange.ts +23 -0
  46. package/src/react/hostMenu.ts +7 -0
  47. package/src/react/index.ts +3 -1
  48. package/src/react/tabs.tsx +23 -10
  49. package/src/react/widgets.tsx +265 -0
@@ -15,7 +15,7 @@
15
15
  }
16
16
 
17
17
  .desk-window {
18
- /* Filled windows fill the stage inside its padding, layered in the order they were used. */
18
+ /* Windows are placed inside the stage's padding; filled ones, below, fill it to its edges, layered in the order they were used. */
19
19
  position: absolute;
20
20
  top: var(--desk-padding);
21
21
  right: var(--desk-padding);
@@ -54,6 +54,18 @@
54
54
  grid-area: 1 / 1;
55
55
  }
56
56
 
57
+ /*
58
+ * A filled window takes the whole desk, as a zoomed window does on a Mac: no margin, no corners, no shadow. The
59
+ * stage's padding stays for the windows that are arranged or free, and for a filled one that is capped and sits
60
+ * in the middle of the room.
61
+ */
62
+ .desk-window[data-mode="filled"]:not([data-centred]) {
63
+ inset: 0 0 var(--desk-inset-bottom) 0;
64
+ border-color: transparent;
65
+ border-radius: 0;
66
+ box-shadow: none;
67
+ }
68
+
57
69
  .desk-window[data-mode="floating"] {
58
70
  right: auto;
59
71
  bottom: auto;
@@ -173,16 +185,18 @@
173
185
  color: var(--desk-muted);
174
186
  }
175
187
 
176
- /* The note gives up the spare room; the (i) keeps its place at the end of the bar. */
177
188
  /*
178
- * The (i) is the bar's last word, at its trailing end, with or without a note before it. It sits in its popover's
179
- * anchor, so the anchor is what the bar lays out: a margin on the button inside it would move nothing.
189
+ * The (i) is on the bar's far edge, opposite the controls: here, on a Mac, it is the bar's last word, after
190
+ * the note and the actions. Whatever comes before it takes the spare room, and it follows. It sits in its
191
+ * popover's anchor, so the anchor is what the bar lays out: a margin on the button inside it would move
192
+ * nothing. The other looks put it first, and say so in looks.css.
180
193
  */
181
194
  .desk-titlebar > .desk-popover-anchor:has(> .desk-window-info) {
182
195
  margin-left: auto;
183
196
  }
184
197
 
185
- .desk-window-note ~ .desk-popover-anchor:has(> .desk-window-info) {
198
+ .desk-window-note ~ .desk-popover-anchor:has(> .desk-window-info),
199
+ .desk-window-actions ~ .desk-popover-anchor:has(> .desk-window-info) {
186
200
  margin-left: var(--desk-space-2);
187
201
  }
188
202
 
@@ -231,6 +245,12 @@
231
245
  margin-left: var(--desk-space-3);
232
246
  }
233
247
 
248
+ /* The count has taken the spare room, so what follows it keeps to it rather than splitting the room. */
249
+ .desk-window-progress ~ .desk-window-actions,
250
+ .desk-window-progress ~ .desk-popover-anchor:has(> .desk-window-info) {
251
+ margin-left: var(--desk-space-2);
252
+ }
253
+
234
254
  .desk-titlebar[data-progress] .desk-title,
235
255
  .desk-titlebar[data-progress] .desk-window-note {
236
256
  max-width: none;
@@ -258,7 +278,13 @@
258
278
  .desk-window-progress-fill { transition: none; }
259
279
  }
260
280
 
261
- .desk-popover-anchor:has(> .desk-window-info) + .desk-window-actions,
281
+ /* Narrower still, the count keeps its words and lets the track go, so the bar's far edge stays on the bar. */
282
+ @container (max-width: 400px) {
283
+ .desk-window-progress-track {
284
+ display: none;
285
+ }
286
+ }
287
+
262
288
  .desk-window-note + .desk-window-actions {
263
289
  margin-left: var(--desk-space-1);
264
290
  }
@@ -399,6 +425,139 @@
399
425
  right: var(--desk-padding);
400
426
  }
401
427
 
428
+ /* ── Widgets: glances in a corner of the stage, behind the windows unless the person keeps one in front ── */
429
+
430
+ /* As big as the stage, to ask its size. No z-index, so each widget stands behind or in front on its own. */
431
+ .desk-widgets {
432
+ container: desk-widgets / size;
433
+ position: absolute;
434
+ inset: 0;
435
+ pointer-events: none;
436
+ }
437
+
438
+ /*
439
+ * A margin of padding for the focus ring, which a list that scrolls would clip. Too many for the desk, and it
440
+ * scrolls: it takes the pointer, as a scroller without it is passed over by the wheel, a finger and its scrollbar.
441
+ */
442
+ .desk-widget-list {
443
+ position: absolute;
444
+ pointer-events: auto;
445
+ box-sizing: border-box;
446
+ width: calc(var(--desk-widget-width) + 2 * var(--desk-space-1));
447
+ max-height: calc(100% - 2 * (var(--desk-padding) - var(--desk-space-1)) - var(--desk-inset-bottom));
448
+ padding: var(--desk-space-1);
449
+ display: flex;
450
+ flex-direction: column;
451
+ gap: var(--desk-space-2);
452
+ overflow: hidden auto;
453
+ scrollbar-width: thin;
454
+ }
455
+
456
+ .desk-widgets[data-corner^="top"] > .desk-widget-list {
457
+ top: calc(var(--desk-padding) - var(--desk-space-1));
458
+ }
459
+
460
+ .desk-widgets[data-corner^="bottom"] > .desk-widget-list {
461
+ bottom: calc(var(--desk-padding) - var(--desk-space-1) + var(--desk-inset-bottom));
462
+ }
463
+
464
+ .desk-widgets[data-corner$="left"] > .desk-widget-list {
465
+ left: calc(var(--desk-padding) - var(--desk-space-1));
466
+ }
467
+
468
+ .desk-widgets[data-corner$="right"] > .desk-widget-list {
469
+ right: calc(var(--desk-padding) - var(--desk-space-1));
470
+ }
471
+
472
+ /* Behind: on the desk surface, over what the app draws on an empty desk; windows start at 10. */
473
+ .desk-widget {
474
+ flex: none;
475
+ box-sizing: border-box;
476
+ position: relative;
477
+ z-index: 1;
478
+ min-height: 44px;
479
+ padding: 0;
480
+ border: 1px solid var(--desk-rule);
481
+ border-radius: var(--desk-radius);
482
+ background: var(--desk-surface);
483
+ color: var(--desk-ink);
484
+ font-family: var(--desk-font);
485
+ font-size: var(--desk-text-body);
486
+ text-align: start;
487
+ overflow: clip;
488
+ overflow-wrap: anywhere;
489
+ user-select: none;
490
+ }
491
+
492
+ /* Its words, on an opaque surface. */
493
+ .desk-widget-surface {
494
+ display: block;
495
+ box-sizing: border-box;
496
+ min-height: 42px;
497
+ padding: var(--desk-space-2) var(--desk-space-3);
498
+ }
499
+
500
+ /* In front, by choice: a frame of the dock's glass round that surface, as a stack's panel. No shadow: the list clips it. */
501
+ .desk-widget[data-front] {
502
+ z-index: 800;
503
+ padding: var(--desk-space-1);
504
+ background: var(--desk-dock-glass);
505
+ backdrop-filter: blur(28px) saturate(170%);
506
+ -webkit-backdrop-filter: blur(28px) saturate(170%);
507
+ }
508
+
509
+ .desk-widget[data-front] > .desk-widget-surface {
510
+ /* The frame comes out of the padding: ticking one keeps its size. */
511
+ min-height: calc(42px - 2 * var(--desk-space-1));
512
+ padding: calc(var(--desk-space-2) - var(--desk-space-1)) calc(var(--desk-space-3) - var(--desk-space-1));
513
+ border-radius: max(0px, calc(var(--desk-radius) - var(--desk-space-1)));
514
+ background: var(--desk-surface);
515
+ }
516
+
517
+ button.desk-widget {
518
+ cursor: pointer;
519
+ transition: border-color .12s var(--desk-ease);
520
+ }
521
+
522
+ button.desk-widget:hover {
523
+ border-color: color-mix(in srgb, var(--desk-accent) 45%, var(--desk-rule));
524
+ }
525
+
526
+ .desk-widget:focus-visible {
527
+ outline: 2px solid var(--desk-accent);
528
+ outline-offset: 2px;
529
+ }
530
+
531
+ /* A tour pointing at them moves nothing, and its ring fits in that margin too. */
532
+ .desk-widget-list[data-desk-tour-pointed] {
533
+ position: absolute;
534
+ }
535
+
536
+ .desk-widget[data-desk-tour-pointed] {
537
+ outline-offset: 2px;
538
+ }
539
+
540
+ .desk-widget-unseen {
541
+ position: absolute;
542
+ width: 1px;
543
+ height: 1px;
544
+ overflow: hidden;
545
+ clip-path: inset(50%);
546
+ white-space: nowrap;
547
+ }
548
+
549
+ /* A desk this small belongs to the windows. */
550
+ @container desk-widgets (max-width: 640px) or (max-height: 400px) {
551
+ .desk-widget-list,
552
+ .desk-widgets > .desk-widget-unseen {
553
+ display: none;
554
+ }
555
+ }
556
+
557
+ @media (forced-colors: active) {
558
+ button.desk-widget:hover { border-color: Highlight; }
559
+ }
560
+
402
561
  /* ── The inside of a window: controls that stay, content that scrolls ── */
403
562
 
404
563
  /* Two panels in one window, and the edge between them that moves. */
@@ -5,7 +5,9 @@ import { focusedId, isMinimized, onDesk } from '../core/desk.js'
5
5
  import type { Desk } from '../core/desk.js'
6
6
  import type { Look } from '../core/look.js'
7
7
  import type { DeskWindow, Frame, WindowId, WindowLimits } from '../core/types.js'
8
- import { arrangement } from './arrange.js'
8
+ import { Widgets, widgetsKeptClear } from './widgets.js'
9
+ import type { Widget, WidgetCorner } from './widgets.js'
10
+ import { arrangement, areaAround } from './arrange.js'
9
11
  import { InfoTip } from './infoTip.js'
10
12
  import { useDesk, useDeskState, useLook, WindowContext } from './context.js'
11
13
  import { WindowBoundary } from './windowBoundary.js'
@@ -32,8 +34,8 @@ export interface DesktopProps {
32
34
  */
33
35
  readonly limits?: (id: WindowId) => WindowLimits | null
34
36
  /**
35
- * What this window is, behind an (i) at the end of its title bar — the same place in every window,
36
- * so a person who wonders what they are looking at always knows where to ask. Explanation only: a
37
+ * What this window is, behind an (i) on the far edge of its title bar, opposite the controls — the
38
+ * same place in every window, so a person who wonders what they are looking at always knows where to ask. Explanation only: a
37
39
  * warning, or anything that changes what someone is about to do, belongs in the window itself.
38
40
  */
39
41
  readonly info?: (id: WindowId) => ReactNode
@@ -50,9 +52,19 @@ export interface DesktopProps {
50
52
  * window at a time; anything with a pointer gets the layered `desktop`.
51
53
  */
52
54
  readonly layout?: DeskLayout | 'auto'
55
+ /**
56
+ * Glances stacked in a corner of the desk, clear of the dock: behind the windows, unless the person keeps
57
+ * one in front from the Window menu (`widgetMenuItems`). Not shown in the fullscreen layout, or on a desk
58
+ * too small to spare the room.
59
+ */
60
+ readonly widgets?: readonly Widget[]
61
+ /** The corner they stand in: `top-right` unless said. Keep it clear in the app's default layout. */
62
+ readonly widgetCorner?: WidgetCorner
53
63
  readonly className?: string
54
64
  }
55
65
 
66
+ const NO_WIDGETS: readonly Widget[] = []
67
+
56
68
  /** Touch-first: a coarse pointer that cannot hover. A tablet with a trackpad reports otherwise. */
57
69
  const TOUCH = '(pointer: coarse) and (hover: none)'
58
70
 
@@ -94,7 +106,7 @@ const halfFrame = (stage: HTMLElement, side: 'start' | 'end'): Frame => {
94
106
  return { x: side === 'start' ? area.x : area.x + width + area.gap, y: area.y, width, height: area.height }
95
107
  }
96
108
 
97
- export function Desktop({ renderWindow, title, note, info, actions, limits, empty, loading, failed, layout = 'auto', className }: DesktopProps) {
109
+ export function Desktop({ renderWindow, title, note, info, actions, limits, empty, loading, failed, layout = 'auto', widgets = NO_WIDGETS, widgetCorner = 'top-right', className }: DesktopProps) {
98
110
  const desk = useDesk()
99
111
  const state = useDeskState()
100
112
  const stage = useRef<HTMLDivElement>(null)
@@ -189,6 +201,8 @@ export function Desktop({ renderWindow, title, note, info, actions, limits, empt
189
201
  data-layout={mode}
190
202
  {...{ [STAGE_ATTRIBUTE]: '' }}
191
203
  >
204
+ {/* Still there with none to draw, so one taken away while it had the keyboard can hand it on. */}
205
+ <Widgets widgets={mode === 'desktop' ? widgets : NO_WIDGETS} corner={widgetCorner} />
192
206
  {onDesk(state).length === 0 && empty}
193
207
  {state.windows.map(window => (
194
208
  <WindowView
@@ -328,7 +342,10 @@ function arrangeNow(desk: Desk, element: HTMLElement) {
328
342
  const windows = onDesk(state)
329
343
  const stack = state.stack.filter(id => !isMinimized(state, id))
330
344
  const [focused, previous] = [stack.at(-1), stack.at(-2)]
331
- if (windows.length === 1) {
345
+ // Widgets kept in front have their corner; the windows are laid out in the rest.
346
+ const area = arrangementArea(element)
347
+ const clear = widgetsKeptClear(element, area.gap)
348
+ if (windows.length === 1 && !clear) {
332
349
  if (focused) desk.fill(focused)
333
350
  return
334
351
  }
@@ -336,7 +353,7 @@ function arrangeNow(desk: Desk, element: HTMLElement) {
336
353
  windows.map(w => w.id),
337
354
  focused ?? null,
338
355
  previous ?? null,
339
- arrangementArea(element),
356
+ clear ? areaAround(area, clear) : area,
340
357
  { minWidth: MIN_WIDTH, minHeight: MIN_HEIGHT },
341
358
  )
342
359
  desk.placeAll(frames)
@@ -457,13 +474,14 @@ function WindowView({ window, layout, hidden, minimized, depth, focused, title,
457
474
  * the desk, being arranged into a cell and being dragged wider all end at the same place, and the
458
475
  * window sits in the middle of whatever room it was given rather than pinned to a corner of it.
459
476
  */
477
+ // Filled and capped: it sits in the middle of the room, not in the corner of it.
478
+ const centred = Boolean(limits && (limits.maxWidth || limits.maxHeight) && !frame)
460
479
  const capped: CSSProperties = {
461
480
  ...(limits?.maxWidth ? { maxWidth: limits.maxWidth } : {}),
462
481
  ...(limits?.maxHeight ? { maxHeight: limits.maxHeight } : {}),
463
482
  ...(limits?.minWidth ? { minWidth: limits.minWidth } : {}),
464
483
  ...(limits?.minHeight ? { minHeight: limits.minHeight } : {}),
465
- // Filled and capped: it sits in the middle of the room, not in the corner of it.
466
- ...(limits && (limits.maxWidth || limits.maxHeight) && !frame ? { margin: 'auto' } : {}),
484
+ ...(centred ? { margin: 'auto' } : {}),
467
485
  }
468
486
  const style: CSSProperties | undefined =
469
487
  layout !== 'desktop'
@@ -489,7 +507,11 @@ function WindowView({ window, layout, hidden, minimized, depth, focused, title,
489
507
  )
490
508
  const windowNote = note != null && note !== false && <p className="desk-window-note">{note}</p>
491
509
 
492
- // At the end of a Mac bar, beside the note; at the start of the others, whose end is the controls'.
510
+ /*
511
+ * The (i) is on the bar's far edge, opposite the controls: last on a Mac bar, whose start is the
512
+ * controls', and first on the others, whose end is. It is put there in the document, not moved there
513
+ * by CSS, so Tab reaches it where it is seen, and it is in the same corner of every window of a look.
514
+ */
493
515
  const windowInfo = info != null && info !== false && (
494
516
  <InfoTip
495
517
  className="desk-window-info"
@@ -508,6 +530,7 @@ function WindowView({ window, layout, hidden, minimized, depth, focused, title,
508
530
  {...{ [WINDOW_ATTRIBUTE]: window.id }}
509
531
  className="desk-window"
510
532
  data-mode={layout === 'fullscreen' ? 'fullscreen' : live ? 'floating' : window.mode}
533
+ data-centred={centred || undefined}
511
534
  data-hidden={hidden || undefined}
512
535
  data-minimized={minimized || undefined}
513
536
  inert={hidden || undefined}
@@ -545,9 +568,8 @@ function WindowView({ window, layout, hidden, minimized, depth, focused, title,
545
568
  {windowNote}
546
569
  </>
547
570
  )}
548
- {look === 'mac' && windowInfo}
549
571
  {actions && <div className="desk-window-actions">{actions}</div>}
550
- {look !== 'mac' && controls}
572
+ {look === 'mac' ? windowInfo : controls}
551
573
  </header>
552
574
  <div className="desk-body">{children}</div>
553
575
  {layout === 'desktop' && (
@@ -9,6 +9,8 @@ import type { Desk } from '../core/desk.js'
9
9
  import type { DeskState, WindowId } from '../core/types.js'
10
10
  import { useDesk, useDeskState } from './context.js'
11
11
  import { hasModKey, hostMenuModel, sameHostModel } from './hostMenu.js'
12
+ import { isWidgetInFront, setWidgetInFront, useWidgetsInFront } from './widgets.js'
13
+ import type { Widget } from './widgets.js'
12
14
  import type { HostMenu, MenuHost } from './hostMenu.js'
13
15
 
14
16
  /*
@@ -77,6 +79,21 @@ export function windowMenuItems(state: DeskState, focus: (id: WindowId) => void,
77
79
  )
78
80
  }
79
81
 
82
+ /**
83
+ * "Widgets in front", and an item for each widget, ticked while it is kept in front of the windows: the
84
+ * section a Window menu carries, after a separator. Nothing at all when the app has no widgets, so the
85
+ * section is not there either. Choosing one brings it in front or sends it back, and that is remembered.
86
+ */
87
+ export function widgetMenuItems(widgets: readonly Widget[]): MenuItem[] {
88
+ if (!widgets.length) return []
89
+ return [
90
+ menuHeader('Widgets in front'),
91
+ ...widgets.map(({ id, label }) =>
92
+ menuAction(label, () => setWidgetInFront(id, !isWidgetInFront(id)), { checked: () => isWidgetInFront(id) }),
93
+ ),
94
+ ]
95
+ }
96
+
80
97
  export interface MenuBarProps {
81
98
  /** Menus on the leading side, in order. The first is conventionally the app's own. */
82
99
  readonly menus: readonly Menu[]
@@ -90,8 +107,8 @@ export interface MenuBarProps {
90
107
  * A native menu bar to put the menus in instead. The bar then draws nothing: it publishes the
91
108
  * menus and status menus to the host as data, again whenever they change or focus moves, and runs
92
109
  * the item the host says was chosen. Anything that should reach the host is a menu or a status
93
- * menu, since `leading` and `trailing` cannot cross. Every item's shortcut crosses, an action's
94
- * included, so a host that binds it runs the action, which the drawn bar only shows. Enablement
110
+ * menu, since `leading` and `trailing` cannot cross. An action's shortcut crosses `showOnly`, a label
111
+ * for a key the app binds, as the drawn bar treats it. Enablement
95
112
  * that changes through app state alone, with no render or focus move, shows stale until the next.
96
113
  */
97
114
  readonly host?: MenuHost
@@ -182,6 +199,7 @@ export function MenuBar(props: MenuBarProps) {
182
199
  function HostedMenuBar({ menus, status = [], host, shortcuts = true }: MenuBarProps & { readonly host: MenuHost }) {
183
200
  const desk = useDesk()
184
201
  useDeskState() // a menu that lists the open windows changes when they do
202
+ useWidgetsInFront() // and one that ticks the widgets in front, when one is ticked
185
203
  const apple = useMemo(isApplePlatform, [])
186
204
  const model = hostMenuModel(menus, status, command => canPerform(desk, command))
187
205
 
@@ -80,3 +80,26 @@ export function arrangement(
80
80
  ),
81
81
  }
82
82
  }
83
+
84
+ /**
85
+ * The area without a rectangle in one of its corners, such as the one widgets kept in front stand in, so
86
+ * windows laid out in it tile around them. Windows are rectangles, so the corner takes a whole column or a
87
+ * whole row with it: whichever leaves more room. A rectangle that misses the area leaves it as it is.
88
+ */
89
+ export function areaAround(area: Area, clear: Frame): Area {
90
+ const right = area.x + area.width
91
+ const bottom = area.y + area.height
92
+ const left = Math.max(area.x, clear.x)
93
+ const top = Math.max(area.y, clear.y)
94
+ const end = Math.min(right, clear.x + clear.width)
95
+ const foot = Math.min(bottom, clear.y + clear.height)
96
+ if (end <= left || foot <= top) return area
97
+ // A rectangle in a corner touches two sides; the room left beside it, and above or below it.
98
+ const column =
99
+ left > area.x ? { ...area, width: left - area.x }
100
+ : { ...area, x: end, width: right - end }
101
+ const row =
102
+ top > area.y ? { ...area, height: top - area.y }
103
+ : { ...area, y: foot, height: bottom - foot }
104
+ return column.width * column.height >= row.width * row.height ? column : row
105
+ }
@@ -25,6 +25,12 @@ export interface HostMenuItem {
25
25
  readonly detail?: string
26
26
  /** In desk's format: 'mod+k', 'mod+alt+a', 'alt+]'. */
27
27
  readonly shortcut?: string
28
+ /**
29
+ * The page handles this item's shortcut itself, so a host draws it beside the item and gives it
30
+ * no key (Electron: `registerAccelerator: false`). Set on an action's shortcut, which the drawn
31
+ * bar only shows too: binding it as well would fire the action twice.
32
+ */
33
+ readonly showOnly?: boolean
28
34
  /** Defaults to true. */
29
35
  readonly enabled?: boolean
30
36
  /** Absent means the item is not checkable. */
@@ -83,6 +89,7 @@ function itemModel(item: MenuItem, id: string, canPerform: (command: CommandId)
83
89
  label: item.label,
84
90
  ...(item.detail === undefined ? {} : { detail: item.detail }),
85
91
  ...(item.shortcut === undefined ? {} : { shortcut: item.shortcut }),
92
+ ...(item.shortcut !== undefined && item.type === 'action' ? { showOnly: true } : {}),
86
93
  enabled: item.type === 'command' ? canPerform(item.command) : !read(item.disabled),
87
94
  ...(checked === undefined ? {} : { checked }),
88
95
  }
@@ -17,6 +17,8 @@ export { DeskProvider, useDesk, useDeskState, useLook, useWindowId, useWindowRou
17
17
  export type { DeskProviderProps } from './context.js'
18
18
  export { useCanPerform, useCommand, usePerform, useShortcuts } from './commands.js'
19
19
  export type { UseCommandOptions } from './commands.js'
20
+ export { isWidgetInFront, setWidgetInFront, useWidgetsInFront } from './widgets.js'
21
+ export type { Widget, WidgetCorner } from './widgets.js'
20
22
  export { Desktop } from './Desktop.js'
21
23
  export type { DeskLayout, DesktopProps } from './Desktop.js'
22
24
  export { useService, useServiceValue } from './services.js'
@@ -87,7 +89,7 @@ export { Composer, Thread } from './conversation.js'
87
89
  export type { ComposerProps, Message, ThreadProps } from './conversation.js'
88
90
  export { Alert, Popover, Sheet, ToastProvider, useToast } from './overlays.js'
89
91
  export type { AlertProps, PopoverProps, PopoverTriggerProps, SheetProps, Toast, ToastInput } from './overlays.js'
90
- export { MenuBar, menuAction, menuCommand, menuHeader, menuSeparator, windowMenuItems } from './MenuBar.js'
92
+ export { MenuBar, menuAction, menuCommand, menuHeader, menuSeparator, widgetMenuItems, windowMenuItems } from './MenuBar.js'
91
93
  export { useContextMenu } from './contextMenu.js'
92
94
  export type { ContextMenuOptions, ContextMenuResult, ContextMenuTargetProps } from './contextMenu.js'
93
95
  export type { Menu, MenuBarProps, MenuItem } from './MenuBar.js'
@@ -18,7 +18,13 @@ export interface Tab<T extends string> {
18
18
  readonly label: string
19
19
  /** A count or a state beside the label, e.g. the 3 in "Needs review 3". */
20
20
  readonly badge?: ReactNode
21
- readonly disabled?: boolean
21
+ /**
22
+ * True when the view can't be chosen, or a string saying why, e.g. "Waiting for the aerial photo". With a
23
+ * reason the tab stays in the accessibility tree as unavailable (`aria-disabled`) and is described by the
24
+ * reason: the arrow keys stop on it, so a screen reader hears why it is grey, and a pointer sees it on hover.
25
+ * It is never selected. Plain `true` is passed by the arrow keys.
26
+ */
27
+ readonly disabled?: boolean | string
22
28
  }
23
29
 
24
30
  export interface TabsProps<T extends string> {
@@ -48,15 +54,17 @@ export function Tabs<T extends string>({ tabs, value, onChange, label, actions,
48
54
 
49
55
  const move = (event: KeyboardEvent<HTMLDivElement>) => {
50
56
  const key = KEYS[event.key as keyof typeof KEYS]
51
- const usable = tabs.filter(t => !t.disabled)
52
- if (key === undefined || !usable.length) return
57
+ // A tab disabled with a reason is a stop, so the reason is heard; one disabled plainly is passed by.
58
+ const stops = tabs.filter(t => t.disabled !== true)
59
+ if (key === undefined || !stops.length) return
53
60
  event.preventDefault()
54
- const at = usable.findIndex(t => t.value === value)
55
- const next = key === 'first' ? usable[0]
56
- : key === 'last' ? usable[usable.length - 1]
57
- : usable[(at + key + usable.length) % usable.length]
61
+ const focused = (event.target as HTMLElement).closest<HTMLElement>('[role="tab"]')?.dataset.value ?? value
62
+ const at = stops.findIndex(t => t.value === focused)
63
+ const next = key === 'first' ? stops[0]
64
+ : key === 'last' ? stops[stops.length - 1]
65
+ : stops[(at + key + stops.length) % stops.length]
58
66
  if (!next) return
59
- onChange(next.value)
67
+ if (!next.disabled) onChange(next.value)
60
68
  strip.current?.querySelector<HTMLButtonElement>(`[data-value="${CSS.escape(next.value)}"]`)?.focus()
61
69
  }
62
70
 
@@ -66,6 +74,7 @@ export function Tabs<T extends string>({ tabs, value, onChange, label, actions,
66
74
  <div ref={strip} role="tablist" aria-label={label} className="desk-tablist" onKeyDown={move}>
67
75
  {tabs.map(tab => {
68
76
  const selected = tab.value === value
77
+ const why = typeof tab.disabled === 'string' && tab.disabled ? tab.disabled : undefined
69
78
  return (
70
79
  <button
71
80
  key={tab.value}
@@ -77,11 +86,15 @@ export function Tabs<T extends string>({ tabs, value, onChange, label, actions,
77
86
  data-value={tab.value}
78
87
  className="desk-tab"
79
88
  tabIndex={selected ? 0 : -1}
80
- disabled={tab.disabled}
81
- onClick={() => onChange(tab.value)}
89
+ disabled={tab.disabled === true}
90
+ aria-disabled={why ? true : undefined}
91
+ aria-describedby={why ? `${tabId(tab.value)}-why` : undefined}
92
+ title={why}
93
+ onClick={() => { if (!tab.disabled) onChange(tab.value) }}
82
94
  >
83
95
  {tab.label}
84
96
  {tab.badge != null && <span className="desk-tab-badge">{tab.badge}</span>}
97
+ {why && <span id={`${tabId(tab.value)}-why`} className="desk-tab-why" aria-hidden="true">{why}</span>}
85
98
  </button>
86
99
  )
87
100
  })}