@liberation-data/desk 0.43.0 → 0.45.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 (197) hide show
  1. package/README.md +238 -10
  2. package/dist/core/desk.d.ts +2 -0
  3. package/dist/core/desk.d.ts.map +1 -1
  4. package/dist/core/desk.js +11 -2
  5. package/dist/core/desk.js.map +1 -1
  6. package/dist/core/hosted.d.ts +222 -0
  7. package/dist/core/hosted.d.ts.map +1 -0
  8. package/dist/core/hosted.js +166 -0
  9. package/dist/core/hosted.js.map +1 -0
  10. package/dist/core/index.d.ts +9 -1
  11. package/dist/core/index.d.ts.map +1 -1
  12. package/dist/core/index.js +5 -1
  13. package/dist/core/index.js.map +1 -1
  14. package/dist/core/location.d.ts +8 -1
  15. package/dist/core/location.d.ts.map +1 -1
  16. package/dist/core/location.js +18 -2
  17. package/dist/core/location.js.map +1 -1
  18. package/dist/core/preferences.d.ts +27 -0
  19. package/dist/core/preferences.d.ts.map +1 -0
  20. package/dist/core/preferences.js +121 -0
  21. package/dist/core/preferences.js.map +1 -0
  22. package/dist/core/scheme.d.ts +9 -3
  23. package/dist/core/scheme.d.ts.map +1 -1
  24. package/dist/core/scheme.js +13 -4
  25. package/dist/core/scheme.js.map +1 -1
  26. package/dist/core/theme.d.ts +41 -0
  27. package/dist/core/theme.d.ts.map +1 -0
  28. package/dist/core/theme.js +56 -0
  29. package/dist/core/theme.js.map +1 -0
  30. package/dist/core/themeChange.d.ts +25 -0
  31. package/dist/core/themeChange.d.ts.map +1 -0
  32. package/dist/core/themeChange.js +49 -0
  33. package/dist/core/themeChange.js.map +1 -0
  34. package/dist/core/types.d.ts +5 -0
  35. package/dist/core/types.d.ts.map +1 -1
  36. package/dist/css/apps.css +52 -1
  37. package/dist/css/shell.css +100 -0
  38. package/dist/css/tokens.css +10 -0
  39. package/dist/css/windows.css +28 -0
  40. package/dist/desk.css +90 -1
  41. package/dist/fx/fx.d.ts.map +1 -1
  42. package/dist/fx/fx.js +7 -31
  43. package/dist/fx/fx.js.map +1 -1
  44. package/dist/host/checkChrome.d.ts +20 -0
  45. package/dist/host/checkChrome.d.ts.map +1 -0
  46. package/dist/host/checkChrome.js +219 -0
  47. package/dist/host/checkChrome.js.map +1 -0
  48. package/dist/host/checkTheme.d.ts +35 -0
  49. package/dist/host/checkTheme.d.ts.map +1 -0
  50. package/dist/host/checkTheme.js +128 -0
  51. package/dist/host/checkTheme.js.map +1 -0
  52. package/dist/host/index.d.ts +7 -0
  53. package/dist/host/index.d.ts.map +1 -0
  54. package/dist/host/index.js +8 -0
  55. package/dist/host/index.js.map +1 -0
  56. package/dist/host/router.d.ts +99 -0
  57. package/dist/host/router.d.ts.map +1 -0
  58. package/dist/host/router.js +279 -0
  59. package/dist/host/router.js.map +1 -0
  60. package/dist/react/Desktop.d.ts.map +1 -1
  61. package/dist/react/Desktop.js +11 -14
  62. package/dist/react/Desktop.js.map +1 -1
  63. package/dist/react/Dock.d.ts +23 -4
  64. package/dist/react/Dock.d.ts.map +1 -1
  65. package/dist/react/Dock.js +17 -29
  66. package/dist/react/Dock.js.map +1 -1
  67. package/dist/react/MenuBar.d.ts +1 -1
  68. package/dist/react/MenuBar.d.ts.map +1 -1
  69. package/dist/react/MenuBar.js +20 -4
  70. package/dist/react/MenuBar.js.map +1 -1
  71. package/dist/react/app.d.ts +65 -12
  72. package/dist/react/app.d.ts.map +1 -1
  73. package/dist/react/app.js +79 -21
  74. package/dist/react/app.js.map +1 -1
  75. package/dist/react/appFrame.d.ts +11 -7
  76. package/dist/react/appFrame.d.ts.map +1 -1
  77. package/dist/react/appFrame.js +24 -6
  78. package/dist/react/appFrame.js.map +1 -1
  79. package/dist/react/appPanels.d.ts +4 -1
  80. package/dist/react/appPanels.d.ts.map +1 -1
  81. package/dist/react/appPanels.js +76 -28
  82. package/dist/react/appPanels.js.map +1 -1
  83. package/dist/react/appearance.d.ts +7 -1
  84. package/dist/react/appearance.d.ts.map +1 -1
  85. package/dist/react/appearance.js +32 -53
  86. package/dist/react/appearance.js.map +1 -1
  87. package/dist/react/context.d.ts +25 -1
  88. package/dist/react/context.d.ts.map +1 -1
  89. package/dist/react/context.js +73 -14
  90. package/dist/react/context.js.map +1 -1
  91. package/dist/react/dockStatus.d.ts +19 -0
  92. package/dist/react/dockStatus.d.ts.map +1 -0
  93. package/dist/react/dockStatus.js +25 -0
  94. package/dist/react/dockStatus.js.map +1 -0
  95. package/dist/react/frameMenus.d.ts +28 -0
  96. package/dist/react/frameMenus.d.ts.map +1 -0
  97. package/dist/react/frameMenus.js +85 -0
  98. package/dist/react/frameMenus.js.map +1 -0
  99. package/dist/react/hostApp.d.ts +15 -0
  100. package/dist/react/hostApp.d.ts.map +1 -0
  101. package/dist/react/hostApp.js +77 -0
  102. package/dist/react/hostApp.js.map +1 -0
  103. package/dist/react/hostDock.d.ts +25 -0
  104. package/dist/react/hostDock.d.ts.map +1 -0
  105. package/dist/react/hostDock.js +98 -0
  106. package/dist/react/hostDock.js.map +1 -0
  107. package/dist/react/hostMenu.d.ts +2 -36
  108. package/dist/react/hostMenu.d.ts.map +1 -1
  109. package/dist/react/hostMenu.js.map +1 -1
  110. package/dist/react/hosted.d.ts +28 -0
  111. package/dist/react/hosted.d.ts.map +1 -0
  112. package/dist/react/hosted.js +53 -0
  113. package/dist/react/hosted.js.map +1 -0
  114. package/dist/react/index.d.ts +10 -5
  115. package/dist/react/index.d.ts.map +1 -1
  116. package/dist/react/index.js +6 -3
  117. package/dist/react/index.js.map +1 -1
  118. package/dist/react/mediaQuery.d.ts +3 -0
  119. package/dist/react/mediaQuery.d.ts.map +1 -0
  120. package/dist/react/mediaQuery.js +11 -0
  121. package/dist/react/mediaQuery.js.map +1 -0
  122. package/dist/react/shell.d.ts +13 -1
  123. package/dist/react/shell.d.ts.map +1 -1
  124. package/dist/react/shell.js +19 -3
  125. package/dist/react/shell.js.map +1 -1
  126. package/dist/react/sidebar.d.ts +6 -1
  127. package/dist/react/sidebar.d.ts.map +1 -1
  128. package/dist/react/sidebar.js +6 -3
  129. package/dist/react/sidebar.js.map +1 -1
  130. package/dist/react/windowDescription.d.ts +7 -0
  131. package/dist/react/windowDescription.d.ts.map +1 -1
  132. package/dist/react/windowDescription.js +9 -0
  133. package/dist/react/windowDescription.js.map +1 -1
  134. package/dist/react/windowMenus.d.ts +19 -0
  135. package/dist/react/windowMenus.d.ts.map +1 -0
  136. package/dist/react/windowMenus.js +88 -0
  137. package/dist/react/windowMenus.js.map +1 -0
  138. package/dist/shell/HostShell.d.ts +53 -0
  139. package/dist/shell/HostShell.d.ts.map +1 -0
  140. package/dist/shell/HostShell.js +116 -0
  141. package/dist/shell/HostShell.js.map +1 -0
  142. package/dist/shell/index.d.ts +7 -0
  143. package/dist/shell/index.d.ts.map +1 -0
  144. package/dist/shell/index.js +9 -0
  145. package/dist/shell/index.js.map +1 -0
  146. package/dist/shell/keys.d.ts +47 -0
  147. package/dist/shell/keys.d.ts.map +1 -0
  148. package/dist/shell/keys.js +68 -0
  149. package/dist/shell/keys.js.map +1 -0
  150. package/dist/shell/motion.d.ts +72 -0
  151. package/dist/shell/motion.d.ts.map +1 -0
  152. package/dist/shell/motion.js +118 -0
  153. package/dist/shell/motion.js.map +1 -0
  154. package/llms.txt +57 -20
  155. package/package.json +10 -1
  156. package/src/core/desk.ts +11 -2
  157. package/src/core/hosted.ts +351 -0
  158. package/src/core/index.ts +28 -1
  159. package/src/core/location.ts +23 -3
  160. package/src/core/preferences.ts +132 -0
  161. package/src/core/scheme.ts +16 -5
  162. package/src/core/theme.ts +91 -0
  163. package/src/core/themeChange.ts +59 -0
  164. package/src/core/types.ts +5 -0
  165. package/src/css/apps.css +52 -1
  166. package/src/css/shell.css +99 -0
  167. package/src/css/tokens.css +10 -0
  168. package/src/css/windows.css +28 -0
  169. package/src/fx/fx.ts +7 -25
  170. package/src/host/checkChrome.ts +257 -0
  171. package/src/host/checkTheme.ts +134 -0
  172. package/src/host/index.ts +10 -0
  173. package/src/host/router.ts +374 -0
  174. package/src/react/Desktop.tsx +16 -21
  175. package/src/react/Dock.tsx +34 -28
  176. package/src/react/MenuBar.tsx +22 -4
  177. package/src/react/app.tsx +116 -22
  178. package/src/react/appFrame.tsx +39 -14
  179. package/src/react/appPanels.tsx +102 -31
  180. package/src/react/appearance.tsx +36 -45
  181. package/src/react/context.tsx +99 -13
  182. package/src/react/dockStatus.ts +42 -0
  183. package/src/react/frameMenus.ts +100 -0
  184. package/src/react/hostApp.tsx +89 -0
  185. package/src/react/hostDock.tsx +118 -0
  186. package/src/react/hostMenu.ts +3 -38
  187. package/src/react/hosted.tsx +65 -0
  188. package/src/react/index.ts +12 -4
  189. package/src/react/mediaQuery.ts +18 -0
  190. package/src/react/shell.tsx +30 -3
  191. package/src/react/sidebar.tsx +10 -3
  192. package/src/react/windowDescription.ts +12 -1
  193. package/src/react/windowMenus.ts +107 -0
  194. package/src/shell/HostShell.tsx +220 -0
  195. package/src/shell/index.ts +11 -0
  196. package/src/shell/keys.ts +101 -0
  197. package/src/shell/motion.ts +163 -0
package/src/react/app.tsx CHANGED
@@ -4,7 +4,7 @@ import { isOpen } from '../core/desk.js'
4
4
  import type { Desk } from '../core/desk.js'
5
5
  import { bindShortcuts } from '../core/shortcuts.js'
6
6
  import type { Keymap } from '../core/shortcuts.js'
7
- import type { WindowId, WindowLimits } from '../core/types.js'
7
+ import type { Size, WindowId, WindowLimits } from '../core/types.js'
8
8
  import type { AppearanceRows } from './appearance.js'
9
9
  import type { DockEntry, DockItem } from './Dock.js'
10
10
  import type { Menu, MenuItem } from './MenuBar.js'
@@ -27,12 +27,16 @@ import type { Menu, MenuItem } from './MenuBar.js'
27
27
  export interface AppLink {
28
28
  readonly label: string
29
29
  readonly url: string
30
+ /** A heading the link is listed under on About, such as "Social". Links with none come first, unheaded. */
31
+ readonly group?: string
30
32
  }
31
33
 
32
34
  /** One line of the About panel's facts: what something is, and its value. */
33
35
  export interface AboutFact {
34
36
  readonly name: string
35
37
  readonly value: string
38
+ /** What Copy copies in place of `value`, which is what is shown: a short commit shown, the full one copied. */
39
+ readonly copyValue?: string
36
40
  /** What the person might want to know of it. Shown under the value, never copied. */
37
41
  readonly note?: ReactNode
38
42
  /** Where to read more, shown after the note as a link: the guide to a setup that could be faster. Never copied. */
@@ -48,6 +52,11 @@ export interface AboutFact {
48
52
  export interface AboutSection {
49
53
  readonly title?: string
50
54
  readonly facts: readonly AboutFact[]
55
+ /**
56
+ * Still being worked out: the section shows "Checking" under its title, while the others are shown,
57
+ * and Copy leaves it out until it is ready.
58
+ */
59
+ readonly pending?: boolean
51
60
  }
52
61
 
53
62
  /** One section of Settings: a heading and the controls under it. */
@@ -60,6 +69,11 @@ export interface SettingsSection {
60
69
  /** In the sidebar layout, beside its name. */
61
70
  readonly icon?: ReactNode
62
71
  readonly badge?: ReactNode
72
+ /**
73
+ * A line about the section as a whole: what it changes, or that a change waits for a restart. In the
74
+ * sidebar layout it is the Settings window's note while the section is open; on one page, under its heading.
75
+ */
76
+ readonly note?: ReactNode
63
77
  readonly content: ReactNode
64
78
  }
65
79
 
@@ -78,6 +92,11 @@ export interface AppSettings {
78
92
  * `sidebar`: a list of sections beside the one chosen, in a bigger window, for many.
79
93
  */
80
94
  readonly layout?: 'panel' | 'sidebar'
95
+ /**
96
+ * How big the sidebar layout may be. Left out, it is any size from 600 × 400, opens at 720 × 640, and can be
97
+ * resized and filled like any window. The one-page panel always fits its content.
98
+ */
99
+ readonly limits?: WindowLimits
81
100
  /** A count on the gear in the dock, as any dock item's badge: updates waiting, a plugin to finish setting up. */
82
101
  readonly badge?: ReactNode
83
102
  /**
@@ -94,6 +113,11 @@ export interface DeskApp {
94
113
  readonly name: string
95
114
  /** The app's mark, drawn large on the About panel. */
96
115
  readonly icon?: ReactNode
116
+ /**
117
+ * The app's name as a wide mark, for a brand that is a wordmark: drawn under the icon at its own width
118
+ * rather than squeezed into a square, in place of the name as text, which stays for screen readers.
119
+ */
120
+ readonly wordmark?: ReactNode
97
121
  readonly version?: string
98
122
  /** A line under the name: what the app is for. */
99
123
  readonly description?: ReactNode
@@ -135,7 +159,7 @@ export const SettingsCommand = 'desk.settings'
135
159
  * these shows the shortcut and leaves the binding to this, so one press is one command. A host's native menu
136
160
  * bar that gives the shortcut a key of its own takes it over while it is up, so the page does not do it too.
137
161
  */
138
- const DESK_SHORTCUTS: Keymap = { 'mod+comma': SettingsCommand }
162
+ export const DESK_SHORTCUTS: Keymap = { 'mod+comma': SettingsCommand }
139
163
  const hostOwns = new WeakMap<Desk, (shortcut: string) => boolean>()
140
164
 
141
165
  /** Whether a menu item's shortcut is one Desk binds on the command already, so the menu only shows it. */
@@ -155,8 +179,10 @@ export function hostOwnsShortcuts(desk: Desk, owns: (shortcut: string) => boolea
155
179
 
156
180
  /** Panels have one size: the desk centres them, filled or not. About is one, and Settings on one page. */
157
181
  export const PANEL_LIMITS: WindowLimits = { minWidth: 360, minHeight: 200, maxWidth: 560, maxHeight: 560, fitContent: true }
158
- /** The sidebar layout of Settings is bigger, for many sections and the list of them. */
159
- export const SIDEBAR_LIMITS: WindowLimits = { minWidth: 600, minHeight: 400, maxWidth: 880, maxHeight: 640 }
182
+ /** The sidebar layout of Settings is a window like any other, for many sections and the list of them: no bigger than the desk, no smaller than this. */
183
+ export const SIDEBAR_LIMITS: WindowLimits = { minWidth: 600, minHeight: 400 }
184
+ /** The size the sidebar layout opens at, before the person makes it another. */
185
+ export const SIDEBAR_SIZE: Size = { width: 720, height: 640 }
160
186
 
161
187
  const AppContext = createContext<DeskApp | null>(null)
162
188
  /** Gives the declaration, with Appearance in place, to everything inside `DeskProvider`. */
@@ -192,16 +218,27 @@ export function appWindowTitle(app: DeskApp | null, id: WindowId): string | null
192
218
 
193
219
  /** How big Desk's own window may be: a panel, or the bigger sidebar layout of Settings. */
194
220
  export const appWindowLimits = (app: DeskApp | null, which: 'about' | 'settings'): WindowLimits =>
195
- which === 'settings' && app?.settings?.layout === 'sidebar' ? SIDEBAR_LIMITS : PANEL_LIMITS
221
+ which === 'settings' && app?.settings?.layout === 'sidebar' ? (app.settings.limits ?? SIDEBAR_LIMITS) : PANEL_LIMITS
222
+
223
+ const clamp = (n: number, min = 0, max = Infinity) => Math.min(Math.max(n, min), max)
224
+
225
+ /** Where the sidebar layout opens: its usual size, within the app's limits. */
226
+ function sidebarSize(limits: WindowLimits): Size {
227
+ return {
228
+ width: clamp(SIDEBAR_SIZE.width, limits.minWidth, limits.maxWidth),
229
+ height: clamp(SIDEBAR_SIZE.height, limits.minHeight, limits.maxHeight),
230
+ }
231
+ }
196
232
 
197
233
  /**
198
234
  * Opens one of Desk's panels: filled, so it sits centred at its one size. A panel already open is brought
199
235
  * forward where it is, and moved to `route` if one is given.
200
236
  */
201
- export function openPanel(desk: Desk, id: WindowId, route?: string): void {
237
+ export function openPanel(desk: Desk, id: WindowId, route?: string, size?: Size): void {
202
238
  const at = route === undefined ? {} : { route }
203
239
  if (isOpen(desk.getState(), id)) desk.open(id, at)
204
- else desk.open(id, { mode: 'filled', ...at })
240
+ // Given a size, a window rather than a panel: free at that size, or as the person left it, able to fill the desk.
241
+ else desk.open(id, size ? { size, ...at } : { mode: 'filled', ...at })
205
242
  }
206
243
 
207
244
  /**
@@ -210,13 +247,32 @@ export function openPanel(desk: Desk, id: WindowId, route?: string): void {
210
247
  */
211
248
  export const openAbout = (desk: Desk): void => openPanel(desk, ABOUT_WINDOW)
212
249
 
213
- /** Opens Settings, in the app's own window if it has one, on `route` if given. */
214
- export function openSettings(desk: Desk, app: DeskApp | null, route?: string): void {
250
+ /** Opens Settings for this declaration, in the app's own window if it has one, on `route` if given. */
251
+ export function openAppSettings(desk: Desk, app: DeskApp | null, route?: string): void {
215
252
  if (!hasSettings(app)) return
216
- if (app?.settings?.open) app.settings.open(route)
217
- else openPanel(desk, SETTINGS_WINDOW, route)
253
+ const settings = app?.settings
254
+ if (settings?.open) settings.open(route)
255
+ else openPanel(desk, SETTINGS_WINDOW, route, settings?.layout === 'sidebar' ? sidebarSize(appWindowLimits(app, 'settings')) : undefined)
256
+ }
257
+
258
+ /* The declaration each desk's provider holds, as shown (Appearance in place, less what a host themes). */
259
+ const declarations = new WeakMap<Desk, () => DeskApp | null>()
260
+
261
+ /** The provider says what the app on this desk declared. Returns a function that forgets it. */
262
+ export function declareOn(desk: Desk, app: () => DeskApp | null): () => void {
263
+ declarations.set(desk, app)
264
+ return () => {
265
+ if (declarations.get(desk) === app) declarations.delete(desk)
266
+ }
218
267
  }
219
268
 
269
+ /**
270
+ * Opens Settings as the gear, the menu item and ⌘, do, on the section `route` names: Desk's panel, or the
271
+ * app's own window. For a caller outside React, such as a search result or a link handler; inside, use
272
+ * `useOpenSettings()`. Nothing when the app has no Settings to show, or no provider has declared it.
273
+ */
274
+ export const openSettings = (desk: Desk, route?: string): void => openAppSettings(desk, declarations.get(desk)?.() ?? null, route)
275
+
220
276
  const glyph = (path: string) => (
221
277
  <svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
222
278
  <path d={path} />
@@ -230,29 +286,67 @@ const INFO = glyph('M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM12 11v5M12 8h.01')
230
286
 
231
287
  /**
232
288
  * Where the gear goes, when the app wants it somewhere other than just before About: put this among its own
233
- * system items. It is dropped when the app has no settings.
289
+ * system items, or among the items of a stack, a System stack. It is dropped when the app has no settings.
290
+ */
291
+ export const dockSettings = (): AppDockMarker => ({ type: 'settings', id: SETTINGS_WINDOW, label: 'Settings', icon: GEAR })
292
+
293
+ /**
294
+ * Where About goes, when the app wants it somewhere other than last in the system group: among its own items,
295
+ * or in a stack. Placed either way, the app's own place is the only one: Desk adds no loose About.
296
+ */
297
+ export const dockAbout = (): AppDockMarker => ({ type: 'about', id: ABOUT_WINDOW, label: 'About', icon: INFO })
298
+
299
+ /**
300
+ * The marker `dockSettings()` and `dockAbout()` give: a dock entry, and a stack item too, so either can stand
301
+ * in a stack's items. Desk puts the real item in its place.
234
302
  */
235
- export const dockSettings = (): DockEntry => ({ type: 'settings', id: SETTINGS_WINDOW })
303
+ export type AppDockMarker = { readonly type: 'settings' | 'about'; readonly id: string } & DockItem
236
304
 
237
305
  /** The separator the system group starts after. An app that has none gets one before Settings and About. */
238
306
  export const SYSTEM_GROUP = 'system'
239
307
 
240
- type Placed = Exclude<DockEntry, { readonly type: 'settings' }>
308
+ type Placed = Exclude<DockEntry, { readonly type: 'settings' | 'about' }>
309
+ type Marker = AppDockMarker['type']
310
+
311
+ /** Which marker an entry or stack item is, `dockSettings()` or `dockAbout()`, or null for any other. */
312
+ export const markerOf = (entry: object): Marker | null => {
313
+ const type = (entry as { readonly type?: unknown }).type
314
+ return type === 'settings' || type === 'about' ? type : null
315
+ }
241
316
 
242
317
  /**
243
- * The app's dock entries with Settings and About in place: About last in the system group (the entries after
244
- * the separator with id `system`, up to the next separator), Settings where `dockSettings()` stands or else
245
- * just before About. The app's own items keep their order. Without a declaration, only the marker goes.
318
+ * The app's dock entries with Settings and About in place. Where the app put `dockSettings()` or `dockAbout()`,
319
+ * among its entries or in a stack, each goes there. What it did not place goes at the end of the system group
320
+ * (the entries after the separator with id `system`, up to the next separator): Settings, then About. The
321
+ * app's own items keep their order. Without a declaration, only the markers go, and a stack they leave empty.
246
322
  */
247
323
  export function placeAppDockItems(entries: readonly DockEntry[], app: DeskApp | null, open: { settings: () => void; about: () => void }): Placed[] {
248
324
  const settings: DockItem | null = hasSettings(app)
249
325
  ? { id: SETTINGS_WINDOW, label: 'Settings', icon: GEAR, onSelect: open.settings, ...(app?.settings?.badge != null ? { badge: app.settings.badge } : {}) }
250
326
  : null
251
- const marked = entries.some(e => e.type === 'settings')
252
- const placed: Placed[] = entries.flatMap(e => (e.type !== 'settings' ? [e] : settings && app ? [{ type: 'item' as const, ...settings }] : []))
253
- if (!app) return placed
254
- const about: Placed = { type: 'item', id: ABOUT_WINDOW, label: 'About', icon: INFO, onSelect: open.about }
255
- const ending = [...(settings && !marked ? [{ type: 'item' as const, ...settings }] : []), about]
327
+ const about: DockItem | null = app ? { id: ABOUT_WINDOW, label: 'About', icon: INFO, onSelect: open.about } : null
328
+ const marked = new Set<Marker>()
329
+ // A marker placed twice gives one item, where it first stands.
330
+ const replace = (marker: Marker): DockItem[] => {
331
+ const item = marked.has(marker) ? null : marker === 'settings' ? settings : about
332
+ marked.add(marker)
333
+ return item ? [item] : []
334
+ }
335
+ const placed: Placed[] = entries.flatMap((entry): Placed[] => {
336
+ const marker = markerOf(entry)
337
+ if (marker) return replace(marker).map(item => ({ type: 'item' as const, ...item }))
338
+ if (entry.type !== 'stack') return [entry as Placed]
339
+ if (!entry.items.some(markerOf)) return [entry]
340
+ const items = entry.items.flatMap(item => {
341
+ const inStack = markerOf(item)
342
+ return inStack ? replace(inStack) : [item]
343
+ })
344
+ return items.length ? [{ ...entry, items }] : []
345
+ })
346
+ const ending = [...(settings && !marked.has('settings') ? [settings] : []), ...(about && !marked.has('about') ? [about] : [])].map(
347
+ item => ({ type: 'item' as const, ...item }),
348
+ )
349
+ if (!ending.length) return placed
256
350
  const start = placed.findIndex(e => e.type === 'separator' && e.id === SYSTEM_GROUP)
257
351
  if (start < 0) return [...placed, ...(placed.length ? [{ type: 'separator' as const, id: SYSTEM_GROUP }] : []), ...ending]
258
352
  const next = placed.findIndex((e, i) => i > start && e.type === 'separator')
@@ -1,11 +1,15 @@
1
- import { useEffect, useRef } from 'react'
1
+ import { useEffect, useId, useRef, useState } from 'react'
2
2
  import type { CSSProperties } from 'react'
3
3
  import { topicMatches } from '../core/events.js'
4
+ import { DESK_PROTOCOL } from '../core/hosted.js'
5
+ import type { DeskChrome } from '../core/hosted.js'
6
+ import type { AppTheme } from '../core/theme.js'
4
7
  import type { DeskEvent } from '../core/events.js'
5
8
  import { useDragging, useDropTarget } from './dnd.js'
6
9
  import type { Accepts } from './dnd.js'
7
10
  import { useDesk, useWindowId } from './context.js'
8
11
  import { useBus } from './events.js'
12
+ import { frameMenus, useFrameMenus } from './frameMenus.js'
9
13
 
10
14
  /*
11
15
  * A generated app — a self-contained page — running inside a window, and taking
@@ -17,8 +21,8 @@ import { useBus } from './events.js'
17
21
  * which it may say, and what may be dropped on it. Nothing else crosses.
18
22
  */
19
23
 
20
- /** The protocol version. Every message carries it, so a mismatch is ignored rather than misread. */
21
- const PROTOCOL = 1
24
+ /** Every message carries the protocol version, shared with hosted mode, so a mismatch is ignored rather than misread. */
25
+ const PROTOCOL = DESK_PROTOCOL
22
26
 
23
27
  /*
24
28
  * THE HOST'S LOOK, OFFERED TO THE APP.
@@ -27,31 +31,30 @@ const PROTOCOL = 1
27
31
  * page inside a dark desk, a dark one inside a light desk. Switching the desk's theme should carry
28
32
  * the app too — the person switched the whole thing, not the chrome around it.
29
33
  *
30
- * So the host offers its palette, and the app takes it or ignores it. `mode` says which way round
31
- * the page is, for an app that decides its own colours but wants to know; `tokens` are custom
32
- * properties the bridge sets on the app's own root, so an app that reads them gets the desk's
33
- * colours with nothing to write.
34
+ * So the host offers its palette (an `AppTheme`), and the app takes it or ignores it. `mode` says
35
+ * which way round the page is, for an app that decides its own colours but wants to know; `tokens`
36
+ * are custom properties the bridge sets on the app's own root, so an app that reads them gets the
37
+ * desk's colours with nothing to write.
34
38
  *
35
39
  * The mode is stamped as `data-theme`, which is the attribute desk's own stylesheet reads and the
36
40
  * one the HIG tells app authors to honour — so a page already written that way follows the desk
37
41
  * with nothing added to it.
38
42
  */
39
- export interface AppTheme {
40
- readonly mode: 'light' | 'dark'
41
- /** Custom properties, named as they will be set: `{ '--sb-bg-dark': '#0b0f1a' }`. */
42
- readonly tokens: Readonly<Record<string, string>>
43
- }
44
43
 
45
44
  type HostMessage =
46
45
  | { readonly desk: 1; readonly kind: 'hello'; readonly window: string | null; readonly listens: readonly string[]; readonly says: readonly string[]; readonly theme: AppTheme | null }
47
46
  | { readonly desk: 1; readonly kind: 'theme'; readonly theme: AppTheme }
48
47
  | { readonly desk: 1; readonly kind: 'event'; readonly topic: string; readonly payload: unknown; readonly from: string | null }
49
48
  | { readonly desk: 1; readonly kind: 'drop'; readonly type: string; readonly payload: unknown; readonly from: string | null }
49
+ /** A menu item the app sent was chosen: hosted mode's command, with the app's own id. */
50
+ | { readonly desk: 1; readonly kind: 'command'; readonly target: 'menu'; readonly id: string }
50
51
 
51
52
  type AppMessage =
52
53
  | { readonly desk: 1; readonly kind: 'ready' }
53
54
  | { readonly desk: 1; readonly kind: 'publish'; readonly topic: string; readonly payload: unknown }
54
55
  | { readonly desk: 1; readonly kind: 'open'; readonly window: string }
56
+ /** The app's menus, as hosted mode's apps send theirs. Only `menus` is read. */
57
+ | { readonly desk: 1; readonly kind: 'chrome'; readonly chrome: Partial<DeskChrome> }
55
58
 
56
59
  const isAppMessage = (data: unknown): data is AppMessage =>
57
60
  typeof data === 'object' && data !== null && (data as { desk?: unknown }).desk === PROTOCOL && typeof (data as { kind?: unknown }).kind === 'string'
@@ -72,6 +75,12 @@ export interface AppFrameProps {
72
75
  readonly accepts?: Accepts
73
76
  /** Windows the app may ask to open. Default: none. */
74
77
  readonly opens?: readonly string[]
78
+ /**
79
+ * The app may add menus to the bar, which join it while this frame's window is in front. Its items
80
+ * go back to it alone when chosen, and never take a shortcut the page uses, nor one without a modifier
81
+ * (only `mod`, `ctrl`, `alt` or F1–F24 bind). Default: false.
82
+ */
83
+ readonly menus?: boolean
75
84
  /**
76
85
  * The frame's sandbox. The default lets the app run its own scripts and forms, and
77
86
  * nothing more: no same-origin access, no top-level navigation, no pop-ups.
@@ -89,6 +98,7 @@ export function AppFrame({
89
98
  theme,
90
99
  accepts,
91
100
  opens = [],
101
+ menus: addsMenus = false,
92
102
  sandbox = 'allow-scripts allow-forms',
93
103
  className,
94
104
  }: AppFrameProps) {
@@ -105,8 +115,13 @@ export function AppFrame({
105
115
  frame.current?.contentWindow?.postMessage(message, '*')
106
116
  }
107
117
 
108
- const latest = useRef({ listens, says, opens, windowId, theme })
109
- latest.current = { listens, says, opens, windowId, theme }
118
+ const latest = useRef({ listens, says, opens, windowId, theme, addsMenus })
119
+ latest.current = { listens, says, opens, windowId, theme, addsMenus }
120
+
121
+ // The app's menus, named for this frame so they never meet the page's or another frame's.
122
+ const prefix = `frame${useId()}`
123
+ const [menus, setMenus] = useState<ReturnType<typeof frameMenus>>(null)
124
+ useFrameMenus(desk, addsMenus ? windowId : null, menus, id => post({ desk: PROTOCOL, kind: 'command', target: 'menu', id }))
110
125
 
111
126
  // What the app says: only from this frame, only on topics it was granted.
112
127
  useEffect(() => {
@@ -115,11 +130,15 @@ export function AppFrame({
115
130
  const message = event.data
116
131
  const granted = latest.current
117
132
  if (message.kind === 'ready') {
133
+ // A page loading in the frame, perhaps a new one: the menus it had are gone with the old.
134
+ setMenus(null)
118
135
  post({ desk: PROTOCOL, kind: 'hello', window: granted.windowId, listens: granted.listens, says: granted.says, theme: granted.theme ?? null })
119
136
  } else if (message.kind === 'publish') {
120
137
  if (typeof message.topic === 'string' && granted.says.some(pattern => topicMatches(pattern, message.topic))) {
121
138
  bus.publish(message.topic, message.payload, { from: granted.windowId })
122
139
  }
140
+ } else if (message.kind === 'chrome') {
141
+ if (granted.addsMenus) setMenus(frameMenus(message.chrome?.menus, prefix))
123
142
  } else if (message.kind === 'open') {
124
143
  if (typeof message.window === 'string' && granted.opens.includes(message.window)) desk.open(message.window)
125
144
  }
@@ -182,11 +201,14 @@ export function AppFrame({
182
201
  * desk.onDrop(drop => …) take what is dropped on the window
183
202
  * desk.publish('ride.selected', ride) say something, if it was granted
184
203
  * desk.open('map') ask for a window, if it was granted
204
+ * desk.setMenus([{ id, label, items }]) add menus to the bar, if it was granted
205
+ * desk.onCommand(id => …) hear which of its menu items was chosen
185
206
  * desk.window which window this is, once connected
186
207
  */
187
208
  export const APP_BRIDGE_SCRIPT = `(() => {
188
209
  const handlers = new Map();
189
210
  const drops = [];
211
+ const commands = [];
190
212
  const send = message => parent.postMessage(Object.assign({ desk: ${PROTOCOL} }, message), '*');
191
213
  const applyTheme = theme => {
192
214
  if (!theme) return;
@@ -208,6 +230,8 @@ export const APP_BRIDGE_SCRIPT = `(() => {
208
230
  onDrop(handler) { drops.push(handler); },
209
231
  publish(topic, payload) { send({ kind: 'publish', topic, payload }); },
210
232
  open(window) { send({ kind: 'open', window }); },
233
+ setMenus(menus) { send({ kind: 'chrome', chrome: { menus } }); },
234
+ onCommand(handler) { commands.push(handler); },
211
235
  };
212
236
  const matches = (pattern, topic) =>
213
237
  pattern === '*' || pattern === topic || (pattern.endsWith('.*') && (topic === pattern.slice(0, -2) || topic.startsWith(pattern.slice(0, -1))));
@@ -218,6 +242,7 @@ export const APP_BRIDGE_SCRIPT = `(() => {
218
242
  if (message.kind === 'theme') applyTheme(message.theme);
219
243
  if (message.kind === 'event') for (const [pattern, list] of handlers) if (matches(pattern, message.topic)) list.forEach(h => h(message));
220
244
  if (message.kind === 'drop') drops.forEach(h => h(message));
245
+ if (message.kind === 'command' && message.target === 'menu') commands.forEach(h => h(message.id));
221
246
  });
222
247
  window.desk = desk;
223
248
  send({ kind: 'ready' });
@@ -1,8 +1,9 @@
1
1
  import { useCallback, useEffect, useRef } from 'react'
2
2
  import type { ReactNode } from 'react'
3
- import { openSettings, useDeskApp } from './app.js'
3
+ import { openAppSettings, useDeskApp } from './app.js'
4
4
  import type { AboutSection, DeskApp, SettingsSection } from './app.js'
5
5
  import { useOptionalDesk, useWindowRoute } from './context.js'
6
+ import { useMediaQuery } from './mediaQuery.js'
6
7
  import { Button } from './controls.js'
7
8
  import { useCopy } from './copy.js'
8
9
  import { Pane, Section } from './pane.js'
@@ -10,17 +11,22 @@ import { Loading } from './progress.js'
10
11
  import { Sidebar } from './sidebar.js'
11
12
  import type { SidebarSection } from './sidebar.js'
12
13
  import { Split } from './split.js'
14
+ import { useWindowBack, useWindowNote } from './windowDescription.js'
13
15
 
14
16
  /*
15
17
  * The windows behind About and Settings, drawn from what the app declared. Both read the declaration from
16
18
  * the desk, so a section added at runtime, or a fact that changes, shows without the window being rebuilt.
17
19
  */
18
20
 
19
- /** The app's name and version, then every fact that may be copied, by section: what About's Copy copies. */
21
+ /**
22
+ * The app's name and version, then every fact that may be copied, by section, each as its `copyValue` if it
23
+ * has one: what About's Copy copies. A section still pending is left out.
24
+ */
20
25
  export function aboutText(app: Pick<DeskApp, 'name' | 'version'>, sections: readonly AboutSection[]): string {
21
26
  const blocks = [app.version ? `${app.name} ${app.version}` : app.name]
22
27
  for (const section of sections) {
23
- const lines = section.facts.filter(fact => fact.copy !== false).map(({ name, value }) => `${name}: ${value}`)
28
+ if (section.pending) continue
29
+ const lines = section.facts.filter(fact => fact.copy !== false).map(({ name, value, copyValue }) => `${name}: ${copyValue ?? value}`)
24
30
  if (lines.length) blocks.push([...(section.title ? [section.title] : []), ...lines].join('\n'))
25
31
  }
26
32
  return blocks.join('\n\n')
@@ -35,7 +41,7 @@ export function useOpenSettings(): (route?: string) => void {
35
41
  const app = useDeskApp()
36
42
  const desk = useOptionalDesk()
37
43
  return useCallback((route?: string) => {
38
- if (desk) openSettings(desk, app, route)
44
+ if (desk) openAppSettings(desk, app, route)
39
45
  }, [desk, app])
40
46
  }
41
47
 
@@ -58,7 +64,7 @@ function AboutPanel({ app }: { readonly app: DeskApp }) {
58
64
  const copying = useCopy(text, textRef)
59
65
  const hasFacts = Boolean(app.facts)
60
66
  // Copy is for something to copy: not while facts are read, and not when there are none to report.
61
- const copyable = Boolean(sections?.some(section => section.facts.some(fact => fact.copy !== false)))
67
+ const copyable = Boolean(sections?.some(section => !section.pending && section.facts.some(fact => fact.copy !== false)))
62
68
  return (
63
69
  <Pane
64
70
  padded
@@ -77,17 +83,19 @@ function AboutPanel({ app }: { readonly app: DeskApp }) {
77
83
  <div className="desk-about-body">
78
84
  <div className="desk-about-brand">
79
85
  {app.icon != null && <div className="desk-about-icon" aria-hidden="true">{app.icon}</div>}
80
- <h2 className="desk-about-name">{app.name}</h2>
86
+ {app.wordmark != null && <div className="desk-about-wordmark" aria-hidden="true">{app.wordmark}</div>}
87
+ <h2 className={app.wordmark != null ? 'desk-about-name desk-about-name-hidden' : 'desk-about-name'}>{app.name}</h2>
81
88
  {app.version && <p className="desk-about-version desk-text-muted">Version {app.version}</p>}
82
89
  {app.description != null && <p className="desk-about-description">{app.description}</p>}
83
90
  </div>
84
- {app.links?.length ? (
85
- <nav className="desk-about-links" aria-label="Links">
86
- {app.links.map(link => (
91
+ {byGroup(app.links ?? [], link => link.group).map(({ group, items }) => (
92
+ <nav key={group} className="desk-about-links" aria-label={group || 'Links'}>
93
+ {group && <h3 className="desk-about-links-heading desk-text-small desk-text-muted">{group}</h3>}
94
+ {items.map(link => (
87
95
  <a key={link.url} href={link.url} target="_blank" rel="noopener noreferrer">{link.label}</a>
88
96
  ))}
89
97
  </nav>
90
- ) : null}
98
+ ))}
91
99
  {app.note != null && <p className="desk-about-note desk-text-small desk-text-muted">{app.note}</p>}
92
100
  {hasFacts && !sections && <Loading label="Reading what is running" />}
93
101
  {sections?.length ? (
@@ -104,8 +112,26 @@ function AboutPanel({ app }: { readonly app: DeskApp }) {
104
112
  )
105
113
  }
106
114
 
115
+ /** Items by their group, in the order each group first appears; those with none (or '') first, as group ''. */
116
+ function byGroup<T>(items: readonly T[], groupOf: (item: T) => string | undefined): { group: string; items: T[] }[] {
117
+ const groups: { group: string; items: T[] }[] = []
118
+ for (const item of items) {
119
+ const group = groupOf(item) ?? ''
120
+ let found = groups.find(g => g.group === group)
121
+ if (!found) {
122
+ found = { group, items: [] }
123
+ if (group) groups.push(found)
124
+ else groups.unshift(found)
125
+ }
126
+ found.items.push(item)
127
+ }
128
+ return groups
129
+ }
130
+
107
131
  function AboutFacts({ section }: { readonly section: AboutSection }) {
108
- const list = (
132
+ const list = section.pending ? (
133
+ <Loading label="Checking" size="small" />
134
+ ) : (
109
135
  <dl className="desk-about-facts">
110
136
  {section.facts.map(({ name, value, note, link }) => (
111
137
  <div key={name}>
@@ -129,20 +155,9 @@ function AboutFacts({ section }: { readonly section: AboutSection }) {
129
155
 
130
156
  /** The sidebar's groups, in the order each first appears; sections with no group come first, unheaded. */
131
157
  export function settingsGroups(sections: readonly SettingsSection[]): SidebarSection[] {
132
- const groups: { id: string; label?: string; items: SettingsSection[] }[] = []
133
- for (const section of sections) {
134
- const id = section.group ?? ''
135
- let group = groups.find(g => g.id === id)
136
- if (!group) {
137
- group = { id, ...(section.group ? { label: section.group } : {}), items: [] }
138
- if (id) groups.push(group)
139
- else groups.unshift(group)
140
- }
141
- group.items.push(section)
142
- }
143
- return groups.map(({ id, label, items }) => ({
144
- id: id || 'settings',
145
- ...(label ? { label } : {}),
158
+ return byGroup(sections, section => section.group).map(({ group, items }) => ({
159
+ id: group || 'settings',
160
+ ...(group ? { label: group } : {}),
146
161
  items: items.map(s => ({ id: s.id, label: s.title, ...(s.icon != null ? { icon: s.icon } : {}), ...(s.badge != null ? { badge: s.badge } : {}) })),
147
162
  }))
148
163
  }
@@ -159,6 +174,16 @@ export function SettingsContent() {
159
174
  const [route, setRoute] = useWindowRoute()
160
175
  const page = useRef<HTMLDivElement>(null)
161
176
  const sidebar = app?.settings?.layout === 'sidebar'
177
+ // On a narrow screen the list and the section take turns: with no route the list, then the section with Back.
178
+ const narrow = useMediaQuery(NARROW)
179
+ const listing = narrow && !route
180
+ const returnTo = useRef('')
181
+ const list = useRef<HTMLDivElement>(null)
182
+
183
+ // Back puts focus on the row it came from, so a keyboard or a screen reader carries on from there.
184
+ useEffect(() => {
185
+ if (listing && returnTo.current) list.current?.querySelector<HTMLElement>(`[data-item="${CSS.escape(returnTo.current)}"]`)?.focus()
186
+ }, [listing])
162
187
 
163
188
  // On one page, a link to a section scrolls it into view.
164
189
  useEffect(() => {
@@ -173,7 +198,7 @@ export function SettingsContent() {
173
198
  <div ref={page} className="desk-settings-page">
174
199
  {sections.map(section => (
175
200
  <div key={section.id} data-settings-section={section.id}>
176
- <Section title={section.title}>{section.content}</Section>
201
+ <SettingsSectionView section={section} />
177
202
  </div>
178
203
  ))}
179
204
  </div>
@@ -183,15 +208,61 @@ export function SettingsContent() {
183
208
  // With no route, or one to a section that has gone, the first section as listed, not as declared.
184
209
  const groups = settingsGroups(sections)
185
210
  const chosen = sections.find(s => s.id === route) ?? sections.find(s => s.id === groups[0]?.items[0]?.id) ?? sections[0]!
211
+ if (listing) {
212
+ return (
213
+ <div ref={list} className="desk-settings-list">
214
+ {/* The row come back from is the current one, and the list's tab stop, as it has focus. */}
215
+ <Sidebar label="Settings" sections={groups} value={sections.find(s => s.id === returnTo.current)?.id ?? chosen.id} onChange={setRoute} focusOnly />
216
+ </div>
217
+ )
218
+ }
219
+ const back = () => {
220
+ returnTo.current = chosen.id
221
+ setRoute('')
222
+ }
223
+ if (narrow) return <NarrowSection section={chosen} onBack={back} />
224
+ const pane = (
225
+ <Pane padded label={chosen.title} className="desk-settings">
226
+ <SettingsSectionView section={chosen} windowNote />
227
+ </Pane>
228
+ )
186
229
  return (
187
230
  <Split side={<Sidebar label="Settings" sections={groups} value={chosen.id} onChange={setRoute} />} size={220} min={180} label="Resize the list of settings">
188
- <Pane padded label={chosen.title} className="desk-settings">
189
- <SettingsSectionView section={chosen} />
190
- </Pane>
231
+ {pane}
191
232
  </Split>
192
233
  )
193
234
  }
194
235
 
195
- function SettingsSectionView({ section }: { readonly section: SettingsSection }): ReactNode {
196
- return <Section title={section.title}>{section.content}</Section>
236
+ /**
237
+ * One section on a narrow screen, as a phone shows a page one step in: "‹ Settings" leads the title row and
238
+ * the title is the section's. Outside a window, with no title row, the way back is a button of its own.
239
+ */
240
+ function NarrowSection({ section, onBack }: { readonly section: SettingsSection; readonly onBack: () => void }): ReactNode {
241
+ const inTitleBar = useWindowBack({ label: 'Settings', title: section.title, onBack })
242
+ return (
243
+ <Pane padded label={section.title} className="desk-settings">
244
+ {!inTitleBar && <Button className="desk-settings-back" onClick={onBack} aria-label="Back to Settings">‹ Settings</Button>}
245
+ {/* The title row names the section, so the page does not again; it has no room for the note, which stays here. */}
246
+ <SettingsSectionView section={section} heading={!inTitleBar} />
247
+ </Pane>
248
+ )
249
+ }
250
+
251
+ /** Narrow enough that a list beside a section leaves neither room: an upright phone. */
252
+ const NARROW = '(max-width: 600px)'
253
+
254
+ /**
255
+ * One section: its heading, its note and its controls. With `windowNote`, the note is the window's, in the
256
+ * title bar, while this section is the one shown; outside a window it stays under the heading.
257
+ */
258
+ function SettingsSectionView({ section, windowNote, heading = true }: { readonly section: SettingsSection; readonly windowNote?: boolean; readonly heading?: boolean }): ReactNode {
259
+ const inTitleBar = useWindowNote(windowNote ? section.note : undefined) && windowNote
260
+ const body = (
261
+ <>
262
+ {section.note != null && !inTitleBar && <p className="desk-settings-note">{section.note}</p>}
263
+ {section.content}
264
+ </>
265
+ )
266
+ // Without a heading of its own, where the title row already names it: still a section, named for it.
267
+ return heading ? <Section title={section.title}>{body}</Section> : <section aria-label={section.title} className="desk-section">{body}</section>
197
268
  }