@liberation-data/desk 0.7.0 → 0.8.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 (61) hide show
  1. package/README.md +69 -2
  2. package/dist/core/commands.d.ts +2 -0
  3. package/dist/core/commands.d.ts.map +1 -1
  4. package/dist/core/commands.js +11 -4
  5. package/dist/core/commands.js.map +1 -1
  6. package/dist/core/desk.d.ts +14 -0
  7. package/dist/core/desk.d.ts.map +1 -1
  8. package/dist/core/desk.js +56 -7
  9. package/dist/core/desk.js.map +1 -1
  10. package/dist/core/index.d.ts +1 -1
  11. package/dist/core/index.d.ts.map +1 -1
  12. package/dist/core/index.js +1 -1
  13. package/dist/core/index.js.map +1 -1
  14. package/dist/core/location.d.ts.map +1 -1
  15. package/dist/core/location.js +15 -7
  16. package/dist/core/location.js.map +1 -1
  17. package/dist/core/types.d.ts +7 -1
  18. package/dist/core/types.d.ts.map +1 -1
  19. package/dist/css/dock.css +6 -0
  20. package/dist/css/tokens.css +1 -0
  21. package/dist/css/windows.css +5 -0
  22. package/dist/desk.css +12 -0
  23. package/dist/react/Desktop.d.ts +1 -1
  24. package/dist/react/Desktop.d.ts.map +1 -1
  25. package/dist/react/Desktop.js +13 -9
  26. package/dist/react/Desktop.js.map +1 -1
  27. package/dist/react/Dock.d.ts.map +1 -1
  28. package/dist/react/Dock.js +10 -7
  29. package/dist/react/Dock.js.map +1 -1
  30. package/dist/react/MenuBar.d.ts +5 -1
  31. package/dist/react/MenuBar.d.ts.map +1 -1
  32. package/dist/react/MenuBar.js +10 -3
  33. package/dist/react/MenuBar.js.map +1 -1
  34. package/dist/react/appFrame.d.ts +1 -1
  35. package/dist/react/appFrame.d.ts.map +1 -1
  36. package/dist/react/appFrame.js +1 -1
  37. package/dist/react/appFrame.js.map +1 -1
  38. package/dist/react/documentTitle.d.ts +10 -0
  39. package/dist/react/documentTitle.d.ts.map +1 -0
  40. package/dist/react/documentTitle.js +25 -0
  41. package/dist/react/documentTitle.js.map +1 -0
  42. package/dist/react/index.d.ts +2 -0
  43. package/dist/react/index.d.ts.map +1 -1
  44. package/dist/react/index.js +1 -0
  45. package/dist/react/index.js.map +1 -1
  46. package/llms.txt +33 -5
  47. package/package.json +16 -1
  48. package/src/core/commands.ts +9 -4
  49. package/src/core/desk.ts +61 -7
  50. package/src/core/index.ts +2 -0
  51. package/src/core/location.ts +15 -7
  52. package/src/core/types.ts +7 -1
  53. package/src/css/dock.css +6 -0
  54. package/src/css/tokens.css +1 -0
  55. package/src/css/windows.css +5 -0
  56. package/src/react/Desktop.tsx +21 -9
  57. package/src/react/Dock.tsx +10 -4
  58. package/src/react/MenuBar.tsx +12 -3
  59. package/src/react/appFrame.tsx +5 -1
  60. package/src/react/documentTitle.ts +52 -0
  61. package/src/react/index.ts +2 -0
@@ -0,0 +1,52 @@
1
+ import { useEffect, useState } from 'react'
2
+ import { focusedId } from '../core/desk.js'
3
+ import type { WindowId } from '../core/types.js'
4
+ import { useDeskState } from './context.js'
5
+
6
+ /*
7
+ * The browser's title bar, and every tab strip and window switcher that reads it, says what
8
+ * is in front — as an application's title bar does. The frontmost window's name comes first,
9
+ * because that is the part a narrow tab still shows.
10
+ *
11
+ * The app's own name is not asked for twice: left out, it is whatever the document was
12
+ * already called, which is the <title> in the page's HTML. That stays the one place the app
13
+ * is named, and the title is put back as it was when the desk goes away — a desk mounted in
14
+ * a larger page must not leave the last window's name behind it.
15
+ *
16
+ * A window's name is wanted as a string here, not as the ReactNode <Desktop> renders: an
17
+ * icon beside a label is a title bar's business, and `document.title` is text. It is the same
18
+ * signature `windowMenuItems` asks for, so an app with a Window menu already has one.
19
+ */
20
+
21
+ export interface DocumentTitleOptions {
22
+ /** The app's name, kept after the window's: `Rides — Garage`. Defaults to the document's own title. */
23
+ readonly app?: string
24
+ /** What goes between the two names. */
25
+ readonly separator?: string
26
+ }
27
+
28
+ const DEFAULT_SEPARATOR = ' — '
29
+
30
+ /** Keeps `document.title` on the frontmost window: `Rides — Garage`, and `Garage` with nothing open. */
31
+ export function useDocumentTitle(title: (id: WindowId) => string, options: DocumentTitleOptions = {}): void {
32
+ const { app, separator = DEFAULT_SEPARATOR } = options
33
+ const state = useDeskState()
34
+ const id = focusedId(state)
35
+
36
+ // What the page was called before the desk took it over: the app's name by default, and what
37
+ // is put back on the way out. Read once, so a title this hook set is never mistaken for it.
38
+ const [original] = useState(() => (typeof document === 'undefined' ? '' : document.title))
39
+ const base = app ?? original
40
+
41
+ const front = id === null ? '' : title(id)
42
+ const next = front && base ? `${front}${separator}${base}` : front || base
43
+
44
+ useEffect(() => {
45
+ if (next) document.title = next
46
+ }, [next])
47
+
48
+ // Only on the way out: a restore that ran between renders would flicker the real title away.
49
+ useEffect(() => () => {
50
+ document.title = original
51
+ }, [original])
52
+ }
@@ -19,6 +19,8 @@ export { useCanPerform, useCommand, usePerform, useShortcuts } from './commands.
19
19
  export type { UseCommandOptions } from './commands.js'
20
20
  export { Desktop } from './Desktop.js'
21
21
  export type { DeskLayout, DesktopProps } from './Desktop.js'
22
+ export { useDocumentTitle } from './documentTitle.js'
23
+ export type { DocumentTitleOptions } from './documentTitle.js'
22
24
  export { lazyWindow } from './windowBoundary.js'
23
25
  export type { WindowFailed, WindowLoading } from './windowBoundary.js'
24
26
  export { Button, Checkbox, ChoiceGroup, RadioGroup, SegmentedControl, Slider, TextField, Toggle } from './controls.js'