@liberation-data/desk 0.44.0 → 0.46.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 +72 -9
- package/dist/core/desk.d.ts +2 -0
- package/dist/core/desk.d.ts.map +1 -1
- package/dist/core/desk.js +11 -2
- package/dist/core/desk.js.map +1 -1
- package/dist/core/hosted.d.ts +15 -0
- package/dist/core/hosted.d.ts.map +1 -1
- package/dist/core/hosted.js +28 -0
- package/dist/core/hosted.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/theme.d.ts +15 -0
- package/dist/core/theme.d.ts.map +1 -1
- package/dist/core/theme.js +73 -1
- package/dist/core/theme.js.map +1 -1
- package/dist/core/types.d.ts +5 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/css/apps.css +17 -0
- package/dist/css/shell.css +89 -0
- package/dist/css/windows.css +28 -0
- package/dist/desk.css +45 -0
- package/dist/host/checkTheme.d.ts +2 -7
- package/dist/host/checkTheme.d.ts.map +1 -1
- package/dist/host/checkTheme.js +3 -27
- package/dist/host/checkTheme.js.map +1 -1
- package/dist/host/router.d.ts +1 -0
- package/dist/host/router.d.ts.map +1 -1
- package/dist/host/router.js +11 -0
- package/dist/host/router.js.map +1 -1
- package/dist/react/Desktop.d.ts.map +1 -1
- package/dist/react/Desktop.js +11 -14
- package/dist/react/Desktop.js.map +1 -1
- package/dist/react/app.d.ts +15 -3
- package/dist/react/app.d.ts.map +1 -1
- package/dist/react/app.js +20 -8
- package/dist/react/app.js.map +1 -1
- package/dist/react/appPanels.d.ts.map +1 -1
- package/dist/react/appPanels.js +44 -5
- package/dist/react/appPanels.js.map +1 -1
- package/dist/react/context.d.ts +16 -1
- package/dist/react/context.d.ts.map +1 -1
- package/dist/react/context.js +5 -3
- package/dist/react/context.js.map +1 -1
- package/dist/react/hostApp.d.ts +3 -1
- package/dist/react/hostApp.d.ts.map +1 -1
- package/dist/react/hostApp.js +3 -2
- package/dist/react/hostApp.js.map +1 -1
- package/dist/react/hosted.d.ts +10 -3
- package/dist/react/hosted.d.ts.map +1 -1
- package/dist/react/hosted.js +68 -8
- package/dist/react/hosted.js.map +1 -1
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -2
- package/dist/react/index.js.map +1 -1
- package/dist/react/mediaQuery.d.ts +3 -0
- package/dist/react/mediaQuery.d.ts.map +1 -0
- package/dist/react/mediaQuery.js +11 -0
- package/dist/react/mediaQuery.js.map +1 -0
- package/dist/react/shell.d.ts +3 -1
- package/dist/react/shell.d.ts.map +1 -1
- package/dist/react/shell.js +2 -2
- package/dist/react/shell.js.map +1 -1
- package/dist/react/sidebar.d.ts +6 -1
- package/dist/react/sidebar.d.ts.map +1 -1
- package/dist/react/sidebar.js +6 -3
- package/dist/react/sidebar.js.map +1 -1
- package/dist/react/windowDescription.d.ts +7 -0
- package/dist/react/windowDescription.d.ts.map +1 -1
- package/dist/react/windowDescription.js +9 -0
- package/dist/react/windowDescription.js.map +1 -1
- package/dist/shell/HostOverview.d.ts +41 -0
- package/dist/shell/HostOverview.d.ts.map +1 -0
- package/dist/shell/HostOverview.js +219 -0
- package/dist/shell/HostOverview.js.map +1 -0
- package/dist/shell/HostShell.d.ts +3 -1
- package/dist/shell/HostShell.d.ts.map +1 -1
- package/dist/shell/HostShell.js +6 -4
- package/dist/shell/HostShell.js.map +1 -1
- package/dist/shell/index.d.ts +4 -0
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +2 -0
- package/dist/shell/index.js.map +1 -1
- package/dist/shell/zoom.d.ts +62 -0
- package/dist/shell/zoom.d.ts.map +1 -0
- package/dist/shell/zoom.js +116 -0
- package/dist/shell/zoom.js.map +1 -0
- package/llms.txt +18 -10
- package/package.json +12 -7
- package/src/core/desk.ts +11 -2
- package/src/core/hosted.ts +33 -0
- package/src/core/index.ts +1 -1
- package/src/core/theme.ts +69 -1
- package/src/core/types.ts +5 -0
- package/src/css/apps.css +17 -0
- package/src/css/shell.css +89 -0
- package/src/css/windows.css +28 -0
- package/src/host/checkTheme.ts +3 -25
- package/src/host/router.ts +12 -0
- package/src/react/Desktop.tsx +16 -21
- package/src/react/app.tsx +32 -8
- package/src/react/appPanels.tsx +64 -6
- package/src/react/context.tsx +20 -2
- package/src/react/hostApp.tsx +3 -2
- package/src/react/hosted.tsx +68 -8
- package/src/react/index.ts +3 -2
- package/src/react/mediaQuery.ts +18 -0
- package/src/react/shell.tsx +4 -2
- package/src/react/sidebar.tsx +10 -3
- package/src/react/windowDescription.ts +12 -1
- package/src/shell/HostOverview.tsx +317 -0
- package/src/shell/HostShell.tsx +8 -5
- package/src/shell/index.ts +18 -0
- package/src/shell/zoom.ts +151 -0
package/src/react/Desktop.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState
|
|
1
|
+
import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
|
2
2
|
import type { CSSProperties, PointerEvent as ReactPointerEvent, ReactNode } from 'react'
|
|
3
3
|
import { addCommandHandler, addDeskCommands, DeskCommands, STAGE_ATTRIBUTE, WINDOW_ATTRIBUTE, windowElement } from '../core/commands.js'
|
|
4
4
|
import { focusedId, isMinimized, onDesk } from '../core/desk.js'
|
|
@@ -10,6 +10,8 @@ import type { Widget, WidgetCorner } from './widgets.js'
|
|
|
10
10
|
import { arrangement, areaAround } from './arrange.js'
|
|
11
11
|
import { InfoTip } from './infoTip.js'
|
|
12
12
|
import { useDesk, useDeskState, useLook, WindowContext } from './context.js'
|
|
13
|
+
import type { WindowBack } from './context.js'
|
|
14
|
+
import { useMediaQuery } from './mediaQuery.js'
|
|
13
15
|
import type { DeskApp } from './app.js'
|
|
14
16
|
import { ABOUT_WINDOW, appWindowLimits, appWindowTitle, desksWindow, SETTINGS_WINDOW, useDeskApp } from './app.js'
|
|
15
17
|
import { AboutContent, SettingsContent } from './appPanels.js'
|
|
@@ -71,22 +73,6 @@ const NO_WIDGETS: readonly Widget[] = []
|
|
|
71
73
|
/** Touch-first: a coarse pointer that cannot hover. A tablet with a trackpad reports otherwise. */
|
|
72
74
|
const TOUCH = '(pointer: coarse) and (hover: none)'
|
|
73
75
|
|
|
74
|
-
function useMediaQuery(query: string): boolean {
|
|
75
|
-
const subscribe = useCallback(
|
|
76
|
-
(onChange: () => void) => {
|
|
77
|
-
const list = globalThis.matchMedia?.(query)
|
|
78
|
-
list?.addEventListener('change', onChange)
|
|
79
|
-
return () => list?.removeEventListener('change', onChange)
|
|
80
|
-
},
|
|
81
|
-
[query],
|
|
82
|
-
)
|
|
83
|
-
return useSyncExternalStore(
|
|
84
|
-
subscribe,
|
|
85
|
-
() => globalThis.matchMedia?.(query).matches ?? false,
|
|
86
|
-
() => false,
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
76
|
const MIN_WIDTH = 240
|
|
91
77
|
const MIN_HEIGHT = 160
|
|
92
78
|
/** How close to the edge a dragged window has to get before it takes that half. */
|
|
@@ -411,7 +397,8 @@ function WindowView({ window, layout, hidden, minimized, depth, focused, title,
|
|
|
411
397
|
// What the content reports in place of the note and the (i) it was given: nothing, until it does.
|
|
412
398
|
const [reportedNote, setNote] = useState<ReactNode>(undefined)
|
|
413
399
|
const [reportedInfo, setInfo] = useState<ReactNode>(undefined)
|
|
414
|
-
const
|
|
400
|
+
const [back, setBack] = useState<WindowBack | undefined>(undefined)
|
|
401
|
+
const context = useMemo(() => ({ id: window.id, element, setProgress, setNote, setInfo, setBack }), [window.id])
|
|
415
402
|
const note = reportedNote ?? givenNote
|
|
416
403
|
const info = reportedInfo ?? givenInfo
|
|
417
404
|
const titleId = `desk-title-${window.id}`
|
|
@@ -496,8 +483,9 @@ function WindowView({ window, layout, hidden, minimized, depth, focused, title,
|
|
|
496
483
|
const capped: CSSProperties = {
|
|
497
484
|
...(limits?.maxWidth ? { maxWidth: limits.maxWidth } : {}),
|
|
498
485
|
...(limits?.maxHeight ? { maxHeight: limits.maxHeight } : {}),
|
|
499
|
-
|
|
500
|
-
...(limits?.
|
|
486
|
+
// Never wider or taller than the room: a phone is narrower than many windows' least.
|
|
487
|
+
...(limits?.minWidth ? { minWidth: `min(${limits.minWidth}px, 100%)` } : {}),
|
|
488
|
+
...(limits?.minHeight ? { minHeight: `min(${limits.minHeight}px, 100%)` } : {}),
|
|
501
489
|
...(centred ? { margin: 'auto' } : {}),
|
|
502
490
|
}
|
|
503
491
|
const style: CSSProperties | undefined =
|
|
@@ -519,9 +507,15 @@ function WindowView({ window, layout, hidden, minimized, depth, focused, title,
|
|
|
519
507
|
)
|
|
520
508
|
const heading = (
|
|
521
509
|
<h2 id={titleId} className="desk-title">
|
|
522
|
-
{title}
|
|
510
|
+
{back ? back.title : title}
|
|
523
511
|
</h2>
|
|
524
512
|
)
|
|
513
|
+
// A view one step in: the way back leads the title, as on a phone's navigation bar.
|
|
514
|
+
const backButton = back && (
|
|
515
|
+
<button type="button" className="desk-window-back" aria-label={`Back to ${back.label}`} onClick={back.onBack}>
|
|
516
|
+
<span aria-hidden="true">‹</span> {back.label}
|
|
517
|
+
</button>
|
|
518
|
+
)
|
|
525
519
|
const windowNote = note != null && note !== false && <p className="desk-window-note">{note}</p>
|
|
526
520
|
|
|
527
521
|
/*
|
|
@@ -570,6 +564,7 @@ function WindowView({ window, layout, hidden, minimized, depth, focused, title,
|
|
|
570
564
|
data-progress={progress ? true : undefined}
|
|
571
565
|
>
|
|
572
566
|
{look === 'mac' ? controls : windowInfo}
|
|
567
|
+
{backButton}
|
|
573
568
|
{look === 'gnome' ? (
|
|
574
569
|
// Title and note stacked in the middle of the bar, as a GNOME header bar carries them.
|
|
575
570
|
<>
|
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'
|
|
@@ -69,6 +69,11 @@ export interface SettingsSection {
|
|
|
69
69
|
/** In the sidebar layout, beside its name. */
|
|
70
70
|
readonly icon?: ReactNode
|
|
71
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
|
|
72
77
|
readonly content: ReactNode
|
|
73
78
|
}
|
|
74
79
|
|
|
@@ -87,6 +92,11 @@ export interface AppSettings {
|
|
|
87
92
|
* `sidebar`: a list of sections beside the one chosen, in a bigger window, for many.
|
|
88
93
|
*/
|
|
89
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
|
|
90
100
|
/** A count on the gear in the dock, as any dock item's badge: updates waiting, a plugin to finish setting up. */
|
|
91
101
|
readonly badge?: ReactNode
|
|
92
102
|
/**
|
|
@@ -169,8 +179,10 @@ export function hostOwnsShortcuts(desk: Desk, owns: (shortcut: string) => boolea
|
|
|
169
179
|
|
|
170
180
|
/** Panels have one size: the desk centres them, filled or not. About is one, and Settings on one page. */
|
|
171
181
|
export const PANEL_LIMITS: WindowLimits = { minWidth: 360, minHeight: 200, maxWidth: 560, maxHeight: 560, fitContent: true }
|
|
172
|
-
/** The sidebar layout of Settings is
|
|
173
|
-
export const SIDEBAR_LIMITS: WindowLimits = { minWidth: 600, minHeight: 400
|
|
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 }
|
|
174
186
|
|
|
175
187
|
const AppContext = createContext<DeskApp | null>(null)
|
|
176
188
|
/** Gives the declaration, with Appearance in place, to everything inside `DeskProvider`. */
|
|
@@ -206,16 +218,27 @@ export function appWindowTitle(app: DeskApp | null, id: WindowId): string | null
|
|
|
206
218
|
|
|
207
219
|
/** How big Desk's own window may be: a panel, or the bigger sidebar layout of Settings. */
|
|
208
220
|
export const appWindowLimits = (app: DeskApp | null, which: 'about' | 'settings'): WindowLimits =>
|
|
209
|
-
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
|
+
}
|
|
210
232
|
|
|
211
233
|
/**
|
|
212
234
|
* Opens one of Desk's panels: filled, so it sits centred at its one size. A panel already open is brought
|
|
213
235
|
* forward where it is, and moved to `route` if one is given.
|
|
214
236
|
*/
|
|
215
|
-
export function openPanel(desk: Desk, id: WindowId, route?: string): void {
|
|
237
|
+
export function openPanel(desk: Desk, id: WindowId, route?: string, size?: Size): void {
|
|
216
238
|
const at = route === undefined ? {} : { route }
|
|
217
239
|
if (isOpen(desk.getState(), id)) desk.open(id, at)
|
|
218
|
-
|
|
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 })
|
|
219
242
|
}
|
|
220
243
|
|
|
221
244
|
/**
|
|
@@ -227,8 +250,9 @@ export const openAbout = (desk: Desk): void => openPanel(desk, ABOUT_WINDOW)
|
|
|
227
250
|
/** Opens Settings for this declaration, in the app's own window if it has one, on `route` if given. */
|
|
228
251
|
export function openAppSettings(desk: Desk, app: DeskApp | null, route?: string): void {
|
|
229
252
|
if (!hasSettings(app)) return
|
|
230
|
-
|
|
231
|
-
|
|
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)
|
|
232
256
|
}
|
|
233
257
|
|
|
234
258
|
/* The declaration each desk's provider holds, as shown (Appearance in place, less what a host themes). */
|
package/src/react/appPanels.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import type { ReactNode } from 'react'
|
|
|
3
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,6 +11,7 @@ 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
|
|
@@ -172,6 +174,16 @@ export function SettingsContent() {
|
|
|
172
174
|
const [route, setRoute] = useWindowRoute()
|
|
173
175
|
const page = useRef<HTMLDivElement>(null)
|
|
174
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])
|
|
175
187
|
|
|
176
188
|
// On one page, a link to a section scrolls it into view.
|
|
177
189
|
useEffect(() => {
|
|
@@ -186,7 +198,7 @@ export function SettingsContent() {
|
|
|
186
198
|
<div ref={page} className="desk-settings-page">
|
|
187
199
|
{sections.map(section => (
|
|
188
200
|
<div key={section.id} data-settings-section={section.id}>
|
|
189
|
-
<
|
|
201
|
+
<SettingsSectionView section={section} />
|
|
190
202
|
</div>
|
|
191
203
|
))}
|
|
192
204
|
</div>
|
|
@@ -196,15 +208,61 @@ export function SettingsContent() {
|
|
|
196
208
|
// With no route, or one to a section that has gone, the first section as listed, not as declared.
|
|
197
209
|
const groups = settingsGroups(sections)
|
|
198
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
|
+
)
|
|
199
229
|
return (
|
|
200
230
|
<Split side={<Sidebar label="Settings" sections={groups} value={chosen.id} onChange={setRoute} />} size={220} min={180} label="Resize the list of settings">
|
|
201
|
-
|
|
202
|
-
<SettingsSectionView section={chosen} />
|
|
203
|
-
</Pane>
|
|
231
|
+
{pane}
|
|
204
232
|
</Split>
|
|
205
233
|
)
|
|
206
234
|
}
|
|
207
235
|
|
|
208
|
-
|
|
209
|
-
|
|
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>
|
|
210
268
|
}
|
package/src/react/context.tsx
CHANGED
|
@@ -67,6 +67,11 @@ export interface DeskProviderProps {
|
|
|
67
67
|
* dark and the platform chrome apply whatever this does; the default, `applyTheme`, takes all of it.
|
|
68
68
|
*/
|
|
69
69
|
readonly onTheme?: (theme: DeskTheme) => void
|
|
70
|
+
/**
|
|
71
|
+
* Hosted, the primary publishes the theme it wears (`appliedTheme`) for the other apps, at once and
|
|
72
|
+
* on every change. False publishes nothing; `usePublishTheme` publishes another theme instead.
|
|
73
|
+
*/
|
|
74
|
+
readonly publishTheme?: boolean
|
|
70
75
|
readonly children: ReactNode
|
|
71
76
|
}
|
|
72
77
|
|
|
@@ -83,6 +88,8 @@ function useHostConnection(bridge: DeskHostBridge | null, wears: boolean, onThem
|
|
|
83
88
|
if (!bridge) return
|
|
84
89
|
const connected = connectHost(bridge)
|
|
85
90
|
const stop = !wears ? () => {} : connected.subscribe<DeskTheme>('primary', THEME_TOPIC, ({ payload }) => {
|
|
91
|
+
// The primary hears its own theme back: it is already wearing it.
|
|
92
|
+
if (connected.primary()) return
|
|
86
93
|
;(wear.current ?? applyTheme)(payload)
|
|
87
94
|
// After the app's own handler, so light or dark and the look hold whatever it did.
|
|
88
95
|
applyThemeBasics(payload)
|
|
@@ -99,7 +106,7 @@ function useHostConnection(bridge: DeskHostBridge | null, wears: boolean, onThem
|
|
|
99
106
|
return { client, theme }
|
|
100
107
|
}
|
|
101
108
|
|
|
102
|
-
export function DeskProvider({ desk, options, look: appLook = 'auto', services, app: declared, host, onTheme, children }: DeskProviderProps) {
|
|
109
|
+
export function DeskProvider({ desk, options, look: appLook = 'auto', services, app: declared, host, onTheme, publishTheme = true, children }: DeskProviderProps) {
|
|
103
110
|
const [value] = useState(() => desk ?? createDesk(options))
|
|
104
111
|
const [bus] = useState(createBus)
|
|
105
112
|
const [held] = useState(() => services ?? [])
|
|
@@ -172,7 +179,7 @@ export function DeskProvider({ desk, options, look: appLook = 'auto', services,
|
|
|
172
179
|
<LookContext.Provider value={resolved}>
|
|
173
180
|
<AppProvider value={app ?? null}>
|
|
174
181
|
<HostContext.Provider value={hosting}>
|
|
175
|
-
{bridge && <HostedApp />}
|
|
182
|
+
{bridge && <HostedApp publishTheme={publishTheme} />}
|
|
176
183
|
<DragProvider>{children}</DragProvider>
|
|
177
184
|
</HostContext.Provider>
|
|
178
185
|
</AppProvider>
|
|
@@ -215,6 +222,17 @@ export interface WindowContextValue {
|
|
|
215
222
|
readonly setNote: (note: ReactNode) => void
|
|
216
223
|
/** Where `useWindowInfo` reports to, the same way. */
|
|
217
224
|
readonly setInfo: (info: ReactNode) => void
|
|
225
|
+
/** Where `useWindowBack` reports to: `undefined` puts the window's own title back. */
|
|
226
|
+
readonly setBack: (back: WindowBack | undefined) => void
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** A view one step into the window: the way back, named for where it leads, and the title while it shows. */
|
|
230
|
+
export interface WindowBack {
|
|
231
|
+
/** The parent, as the button names it: "‹ Settings", read as "Back to Settings". */
|
|
232
|
+
readonly label: string
|
|
233
|
+
/** What the title says while this view shows, such as the section open in Settings. */
|
|
234
|
+
readonly title: ReactNode
|
|
235
|
+
readonly onBack: () => void
|
|
218
236
|
}
|
|
219
237
|
|
|
220
238
|
/** Present inside a window's content: which window this is, and its element. */
|
package/src/react/hostApp.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import { hasSettings, useDeskApp } from './app.js'
|
|
|
5
5
|
import type { AboutSection, AppLink, DeskApp } from './app.js'
|
|
6
6
|
import { useOpenSettings } from './appPanels.js'
|
|
7
7
|
import { badgeText } from './hostDock.js'
|
|
8
|
-
import { useHost } from './hosted.js'
|
|
8
|
+
import { useHost, usePublishAppliedTheme } from './hosted.js'
|
|
9
9
|
|
|
10
10
|
/*
|
|
11
11
|
* SETTINGS AND ABOUT, WHEN A HOST HAS THEM.
|
|
@@ -65,8 +65,9 @@ export function hostSettings(app: DeskApp | null): HostSettingsSection[] {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/** Sends the host the app's Settings sections and About, and opens Settings where the host says. Draws nothing. */
|
|
68
|
-
export function HostedApp() {
|
|
68
|
+
export function HostedApp({ publishTheme = true }: { readonly publishTheme?: boolean }) {
|
|
69
69
|
const host = useHost()
|
|
70
|
+
usePublishAppliedTheme(publishTheme)
|
|
70
71
|
const app = useDeskApp()
|
|
71
72
|
const openSettings = useOpenSettings()
|
|
72
73
|
// The facts are a hook, read here as the About panel reads them, so they can change.
|
package/src/react/hosted.tsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { createContext, useContext, useEffect, useMemo, useRef } from 'react'
|
|
1
|
+
import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react'
|
|
2
2
|
import { THEME_TOPIC } from '../core/hosted.js'
|
|
3
3
|
import type { Broadcast, HostClient, Publisher } from '../core/hosted.js'
|
|
4
|
+
import { appliedTheme } from '../core/theme.js'
|
|
4
5
|
import type { DeskTheme } from '../core/theme.js'
|
|
6
|
+
import { THEME_CHANGE } from '../core/themeChange.js'
|
|
5
7
|
import type { MenuHost } from './hostMenu.js'
|
|
6
8
|
|
|
7
9
|
/*
|
|
@@ -49,13 +51,16 @@ export function useHostBroadcast<T = unknown>(publisher: Publisher, topic: strin
|
|
|
49
51
|
useEffect(() => host?.subscribe<T>(publisher, topic, broadcast => latest.current(broadcast)), [host, publisher, topic])
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
/** Per connection, how many `usePublishTheme`s are mounted, and who to tell when that changes. */
|
|
55
|
+
const themeOwners = new WeakMap<HostClient, { count: number; readonly changed: Set<() => void> }>()
|
|
56
|
+
const ownersOf = (host: HostClient) => {
|
|
57
|
+
let owners = themeOwners.get(host)
|
|
58
|
+
if (!owners) themeOwners.set(host, (owners = { count: 0, changed: new Set() }))
|
|
59
|
+
return owners
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Sends `theme` when it is set and differs from what this hook last sent. The one path a theme takes. */
|
|
63
|
+
function useThemeSender(host: HostClient | null, theme: DeskTheme | null): void {
|
|
59
64
|
const key = theme ? JSON.stringify(theme) : ''
|
|
60
65
|
const latest = useRef(theme)
|
|
61
66
|
latest.current = theme
|
|
@@ -63,3 +68,58 @@ export function usePublishTheme(theme: DeskTheme | null): void {
|
|
|
63
68
|
if (host && latest.current) host.publish(THEME_TOPIC, latest.current)
|
|
64
69
|
}, [host, key])
|
|
65
70
|
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Publishes this app's theme to the host, again whenever it changes: for a primary whose theme for the
|
|
74
|
+
* others is not the one it wears. While mounted, it is published instead of `appliedTheme`. The host
|
|
75
|
+
* passes it on only from the primary. Does nothing when not hosted; while `theme` is null it publishes
|
|
76
|
+
* nothing, and holds back `appliedTheme` too.
|
|
77
|
+
*/
|
|
78
|
+
export function usePublishTheme(theme: DeskTheme | null): void {
|
|
79
|
+
const host = useHost()
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (!host) return
|
|
82
|
+
const owners = ownersOf(host)
|
|
83
|
+
owners.count++
|
|
84
|
+
owners.changed.forEach(tell => tell())
|
|
85
|
+
return () => {
|
|
86
|
+
owners.count--
|
|
87
|
+
owners.changed.forEach(tell => tell())
|
|
88
|
+
}
|
|
89
|
+
}, [host])
|
|
90
|
+
useThemeSender(host, theme)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The primary's default: the theme it wears, at once and on every change of scheme, look or tokens,
|
|
95
|
+
* unless `enabled` is false or a `usePublishTheme` publishes another. An app that isn't the primary
|
|
96
|
+
* (the host says, through `role`) publishes nothing, so the host has nothing to refuse.
|
|
97
|
+
*/
|
|
98
|
+
export function usePublishAppliedTheme(enabled: boolean): void {
|
|
99
|
+
const host = useHost()
|
|
100
|
+
const [theme, setTheme] = useState<DeskTheme | null>(null)
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if (!host || !enabled || typeof document === 'undefined') return
|
|
103
|
+
const owners = ownersOf(host)
|
|
104
|
+
let primary = false
|
|
105
|
+
const read = () => setTheme(primary && owners.count === 0 ? appliedTheme() : null)
|
|
106
|
+
const stopRole = host.onRole(is => {
|
|
107
|
+
primary = is
|
|
108
|
+
read()
|
|
109
|
+
})
|
|
110
|
+
owners.changed.add(read)
|
|
111
|
+
// Every way the worn theme changes ends on the root: the scheme and look as attributes, tokens in
|
|
112
|
+
// its style or a class, and a host's or the app's applyTheme says so with desk-themechange.
|
|
113
|
+
const observer = new MutationObserver(read)
|
|
114
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme', 'data-look', 'style', 'class'] })
|
|
115
|
+
document.addEventListener(THEME_CHANGE, read)
|
|
116
|
+
return () => {
|
|
117
|
+
stopRole()
|
|
118
|
+
owners.changed.delete(read)
|
|
119
|
+
observer.disconnect()
|
|
120
|
+
document.removeEventListener(THEME_CHANGE, read)
|
|
121
|
+
setTheme(null)
|
|
122
|
+
}
|
|
123
|
+
}, [host, enabled])
|
|
124
|
+
useThemeSender(host, theme)
|
|
125
|
+
}
|
package/src/react/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ export {
|
|
|
23
23
|
SETTINGS_WINDOW,
|
|
24
24
|
SettingsCommand,
|
|
25
25
|
SIDEBAR_LIMITS,
|
|
26
|
+
SIDEBAR_SIZE,
|
|
26
27
|
SYSTEM_GROUP,
|
|
27
28
|
useDeskApp,
|
|
28
29
|
} from './app.js'
|
|
@@ -43,7 +44,7 @@ export { COLOR_SCHEME_KEY, COLOR_SCHEME_SCRIPT, colorSchemeScript, LOOK_KEY } fr
|
|
|
43
44
|
export type { ColorScheme } from '../core/scheme.js'
|
|
44
45
|
export type { DeskShellProps } from './shell.js'
|
|
45
46
|
export { DeskProvider, useDesk, useDeskState, useLook, useWindowId, useWindowRoute } from './context.js'
|
|
46
|
-
export type { DeskProviderProps } from './context.js'
|
|
47
|
+
export type { DeskProviderProps, WindowBack } from './context.js'
|
|
47
48
|
export { useCanPerform, useCommand, usePerform, useShortcuts } from './commands.js'
|
|
48
49
|
export type { UseCommandOptions } from './commands.js'
|
|
49
50
|
export { isWidgetInFront, setWidgetInFront, useWidgetsInFront } from './widgets.js'
|
|
@@ -75,7 +76,7 @@ export type { SoundsToggleProps } from './soundsToggle.js'
|
|
|
75
76
|
export { Loading, Spinner } from './progress.js'
|
|
76
77
|
export { useWindowProgress } from './windowProgress.js'
|
|
77
78
|
export type { WindowProgress } from './windowProgress.js'
|
|
78
|
-
export { useWindowInfo, useWindowNote } from './windowDescription.js'
|
|
79
|
+
export { useWindowBack, useWindowInfo, useWindowNote } from './windowDescription.js'
|
|
79
80
|
export type { WindowDescription } from './windowDescription.js'
|
|
80
81
|
export type { LoadingProps, SpinnerProps, SpinnerSize } from './progress.js'
|
|
81
82
|
export { Led } from './led.js'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useCallback, useSyncExternalStore } from 'react'
|
|
2
|
+
|
|
3
|
+
/** Whether a CSS media query matches now, re-read when it changes. False where there is no `matchMedia`. */
|
|
4
|
+
export function useMediaQuery(query: string): boolean {
|
|
5
|
+
const subscribe = useCallback(
|
|
6
|
+
(onChange: () => void) => {
|
|
7
|
+
const list = globalThis.matchMedia?.(query)
|
|
8
|
+
list?.addEventListener('change', onChange)
|
|
9
|
+
return () => list?.removeEventListener('change', onChange)
|
|
10
|
+
},
|
|
11
|
+
[query],
|
|
12
|
+
)
|
|
13
|
+
return useSyncExternalStore(
|
|
14
|
+
subscribe,
|
|
15
|
+
() => globalThis.matchMedia?.(query).matches ?? false,
|
|
16
|
+
() => false,
|
|
17
|
+
)
|
|
18
|
+
}
|
package/src/react/shell.tsx
CHANGED
|
@@ -33,6 +33,8 @@ export interface DeskShellProps {
|
|
|
33
33
|
readonly host?: DeskHostBridge | null
|
|
34
34
|
/** How a hosted app wears the theme it is sent. See `DeskProviderProps.onTheme`. */
|
|
35
35
|
readonly onTheme?: (theme: DeskTheme) => void
|
|
36
|
+
/** Hosted, whether the primary publishes the theme it wears. See `DeskProviderProps.publishTheme`. */
|
|
37
|
+
readonly publishTheme?: boolean
|
|
36
38
|
/**
|
|
37
39
|
* Where every choice Desk remembers is kept: scheme, look, sounds. This browser's localStorage when left
|
|
38
40
|
* out. Desk copies the store's values to localStorage too, for the head script's first paint.
|
|
@@ -45,7 +47,7 @@ export interface DeskShellProps {
|
|
|
45
47
|
const givenStores: PreferenceStore[] = []
|
|
46
48
|
|
|
47
49
|
/** Everything an app needs around it, in one component: the desk, its bus, and toasts. */
|
|
48
|
-
export function DeskShell({ desk, options, bus, toasts = true, look = 'auto', services = [], app, host, onTheme, preferences, children }: DeskShellProps) {
|
|
50
|
+
export function DeskShell({ desk, options, bus, toasts = true, look = 'auto', services = [], app, host, onTheme, publishTheme, preferences, children }: DeskShellProps) {
|
|
49
51
|
const [made] = useState(() => desk ?? createDesk(options))
|
|
50
52
|
useLayoutEffect(() => {
|
|
51
53
|
if (!preferences) return
|
|
@@ -58,6 +60,6 @@ export function DeskShell({ desk, options, bus, toasts = true, look = 'auto', se
|
|
|
58
60
|
}
|
|
59
61
|
}, [preferences])
|
|
60
62
|
const inner = toasts ? <ToastProvider>{children}</ToastProvider> : children
|
|
61
|
-
const given = { ...(app ? { app } : {}), ...(host === undefined ? {} : { host }), ...(onTheme === undefined ? {} : { onTheme }) }
|
|
63
|
+
const given = { ...(app ? { app } : {}), ...(host === undefined ? {} : { host }), ...(onTheme === undefined ? {} : { onTheme }), ...(publishTheme === undefined ? {} : { publishTheme }) }
|
|
62
64
|
return <DeskProvider desk={made} look={look} services={services} {...given}>{bus ? <BusProvider bus={bus}>{inner}</BusProvider> : inner}</DeskProvider>
|
|
63
65
|
}
|
package/src/react/sidebar.tsx
CHANGED
|
@@ -27,9 +27,14 @@ export interface SidebarProps {
|
|
|
27
27
|
readonly label: string
|
|
28
28
|
readonly footer?: ReactNode
|
|
29
29
|
readonly className?: string
|
|
30
|
+
/**
|
|
31
|
+
* `true` when the list is shown on its own and choosing a place takes you away from it, as on a phone: the
|
|
32
|
+
* arrow keys then only move between the items, and Enter or a click chooses one. Otherwise moving chooses.
|
|
33
|
+
*/
|
|
34
|
+
readonly focusOnly?: boolean
|
|
30
35
|
}
|
|
31
36
|
|
|
32
|
-
export function Sidebar({ sections, value, onChange, label, footer, className }: SidebarProps) {
|
|
37
|
+
export function Sidebar({ sections, value, onChange, label, footer, className, focusOnly }: SidebarProps) {
|
|
33
38
|
const nav = useRef<HTMLElement>(null)
|
|
34
39
|
const items = sections.flatMap(section => section.items).filter(item => !item.disabled)
|
|
35
40
|
|
|
@@ -38,13 +43,15 @@ export function Sidebar({ sections, value, onChange, label, footer, className }:
|
|
|
38
43
|
const delta = keys[event.key as keyof typeof keys]
|
|
39
44
|
if (!delta && event.key !== 'Home' && event.key !== 'End') return
|
|
40
45
|
event.preventDefault()
|
|
41
|
-
|
|
46
|
+
// Moving without choosing, it moves from the item that has focus, not the one chosen.
|
|
47
|
+
const focused = (document.activeElement as HTMLElement | null)?.dataset?.item
|
|
48
|
+
const at = items.findIndex(item => item.id === (focusOnly && focused !== undefined ? focused : value))
|
|
42
49
|
const next =
|
|
43
50
|
event.key === 'Home' ? items[0]
|
|
44
51
|
: event.key === 'End' ? items.at(-1)
|
|
45
52
|
: items[(at + (delta ?? 1) + items.length) % items.length]
|
|
46
53
|
if (!next) return
|
|
47
|
-
onChange(next.id)
|
|
54
|
+
if (!focusOnly) onChange(next.id)
|
|
48
55
|
nav.current?.querySelector<HTMLButtonElement>(`[data-item="${CSS.escape(next.id)}"]`)?.focus()
|
|
49
56
|
}
|
|
50
57
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useContext, useEffect } from 'react'
|
|
2
2
|
import type { ReactNode } from 'react'
|
|
3
3
|
import { WindowContext } from './context.js'
|
|
4
|
+
import type { WindowBack } from './context.js'
|
|
4
5
|
|
|
5
6
|
/*
|
|
6
7
|
* WHAT THIS VIEW IS LOOKING AT, IN THE TITLE BAR.
|
|
@@ -40,7 +41,17 @@ export function useWindowInfo(info: WindowDescription): boolean {
|
|
|
40
41
|
return useReport(setInfo, info)
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
/**
|
|
45
|
+
* A view one step in, as Settings' section on a phone: the title row gets a back button named for the
|
|
46
|
+
* parent ("‹ Settings") and the title becomes the view's, until the component unmounts or reports nothing.
|
|
47
|
+
* Returns whether a title row took it; outside a window the caller draws its own way back.
|
|
48
|
+
*/
|
|
49
|
+
export function useWindowBack(back: WindowBack | null | undefined): boolean {
|
|
50
|
+
const setBack = useContext(WindowContext)?.setBack
|
|
51
|
+
return useReport(setBack, back ?? undefined)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function useReport<T>(set: ((value: T | undefined) => void) | undefined, value: T | undefined): boolean {
|
|
44
55
|
useEffect(() => {
|
|
45
56
|
set?.(value)
|
|
46
57
|
}, [set, value])
|