@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.
- package/README.md +69 -2
- package/dist/core/commands.d.ts +2 -0
- package/dist/core/commands.d.ts.map +1 -1
- package/dist/core/commands.js +11 -4
- package/dist/core/commands.js.map +1 -1
- package/dist/core/desk.d.ts +14 -0
- package/dist/core/desk.d.ts.map +1 -1
- package/dist/core/desk.js +56 -7
- package/dist/core/desk.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/location.d.ts.map +1 -1
- package/dist/core/location.js +15 -7
- package/dist/core/location.js.map +1 -1
- package/dist/core/types.d.ts +7 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/css/dock.css +6 -0
- package/dist/css/tokens.css +1 -0
- package/dist/css/windows.css +5 -0
- package/dist/desk.css +12 -0
- package/dist/react/Desktop.d.ts +1 -1
- package/dist/react/Desktop.d.ts.map +1 -1
- package/dist/react/Desktop.js +13 -9
- package/dist/react/Desktop.js.map +1 -1
- package/dist/react/Dock.d.ts.map +1 -1
- package/dist/react/Dock.js +10 -7
- package/dist/react/Dock.js.map +1 -1
- package/dist/react/MenuBar.d.ts +5 -1
- package/dist/react/MenuBar.d.ts.map +1 -1
- package/dist/react/MenuBar.js +10 -3
- package/dist/react/MenuBar.js.map +1 -1
- package/dist/react/appFrame.d.ts +1 -1
- package/dist/react/appFrame.d.ts.map +1 -1
- package/dist/react/appFrame.js +1 -1
- package/dist/react/appFrame.js.map +1 -1
- package/dist/react/documentTitle.d.ts +10 -0
- package/dist/react/documentTitle.d.ts.map +1 -0
- package/dist/react/documentTitle.js +25 -0
- package/dist/react/documentTitle.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/llms.txt +33 -5
- package/package.json +16 -1
- package/src/core/commands.ts +9 -4
- package/src/core/desk.ts +61 -7
- package/src/core/index.ts +2 -0
- package/src/core/location.ts +15 -7
- package/src/core/types.ts +7 -1
- package/src/css/dock.css +6 -0
- package/src/css/tokens.css +1 -0
- package/src/css/windows.css +5 -0
- package/src/react/Desktop.tsx +21 -9
- package/src/react/Dock.tsx +10 -4
- package/src/react/MenuBar.tsx +12 -3
- package/src/react/appFrame.tsx +5 -1
- package/src/react/documentTitle.ts +52 -0
- 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
|
+
}
|
package/src/react/index.ts
CHANGED
|
@@ -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'
|