@liberation-data/desk 0.44.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.
- package/README.md +14 -3
- 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/types.d.ts +5 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/css/apps.css +17 -0
- package/dist/css/windows.css +28 -0
- package/dist/desk.css +45 -0
- 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 +10 -0
- package/dist/react/context.d.ts.map +1 -1
- package/dist/react/context.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/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/llms.txt +9 -6
- package/package.json +1 -1
- package/src/core/desk.ts +11 -2
- package/src/core/types.ts +5 -0
- package/src/css/apps.css +17 -0
- package/src/css/windows.css +28 -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 +11 -0
- package/src/react/index.ts +3 -2
- package/src/react/mediaQuery.ts +18 -0
- package/src/react/sidebar.tsx +10 -3
- package/src/react/windowDescription.ts +12 -1
package/llms.txt
CHANGED
|
@@ -64,7 +64,8 @@ fitFrame(frame, stage, min?): Frame | null; stepFrom(frame, open: Frame[], stage
|
|
|
64
64
|
interface Desk {
|
|
65
65
|
getState(): DeskState
|
|
66
66
|
subscribe(listener: (state: DeskState) => void): () => void
|
|
67
|
-
open(id: string, options?: { mode?: 'filled' | 'floating'; frame?: Frame; route?: string }): void // default fills; a frame floats;
|
|
67
|
+
open(id: string, options?: { mode?: 'filled' | 'floating'; frame?: Frame; size?: Size; route?: string }): void // default fills; a frame floats;
|
|
68
|
+
// size: free, centred at that size, unless left filled or placed last time;
|
|
68
69
|
// a route moves it there, open already or not
|
|
69
70
|
openInstance(type: string, options?): string // 'query', then 'query#2' — returns the id it opened
|
|
70
71
|
close(id: string): void
|
|
@@ -264,6 +265,7 @@ useWindowRoute(): [route, setRoute] // where this window is insi
|
|
|
264
265
|
useWindowProgress({ value, max, label } | null): boolean // a real count in this window's title bar; false outside one
|
|
265
266
|
useWindowNote(note: ReactNode): boolean // this view's note in place of the window's; null defers, false hides
|
|
266
267
|
useWindowInfo(info: ReactNode): boolean // this view's (i) in place of the window's; null defers
|
|
268
|
+
useWindowBack({ label, title, onBack } | null): boolean // a view one step in: "‹ label" (named "Back to label") before the title, which becomes `title`
|
|
267
269
|
|
|
268
270
|
<Desktop
|
|
269
271
|
renderWindow={(id) => ReactNode} // memoised: chrome re-renders, content does not
|
|
@@ -425,9 +427,9 @@ interface DeskApp { name; icon?; wordmark?: ReactNode; version?; description?; l
|
|
|
425
427
|
facts?: () => AboutSection[] | null; // a HOOK, called inside the About panel; null = still reading, [] = nothing, no Copy
|
|
426
428
|
settings?: AppSettings } // leave out: no gear, no "Settings…", no ⌘,
|
|
427
429
|
interface AboutSection { title?; pending?: boolean; facts: { name; value: string; copyValue?: string; note?: ReactNode; link?: { label, url }; copy?: false }[] } // copy:false = shown, not copied; note and link never copied; copyValue copied in place of value; pending = "Checking", left out of Copy
|
|
428
|
-
interface AppSettings { sections?: SettingsSection[]; layout?: 'panel' | 'sidebar'; badge?: ReactNode;
|
|
430
|
+
interface AppSettings { sections?: SettingsSection[]; layout?: 'panel' | 'sidebar'; badge?: ReactNode; limits?: WindowLimits; // limits: the sidebar layout's
|
|
429
431
|
open?: (route?: string) => void } // open: the app's own Settings window; Desk draws none
|
|
430
|
-
interface SettingsSection { id; title; group?; icon?; badge?; content: ReactNode } // id = the route of `settings
|
|
432
|
+
interface SettingsSection { id; title; group?; icon?; badge?; note?: ReactNode; content: ReactNode } // id = the route of `settings`; note: the window's note while open (one page: under the heading)
|
|
431
433
|
// AppSettings.appearance?: true | { scheme?; defaultScheme?: 'system'|'light'|'dark'; look?; sounds?: Fx; soundsDescription?; theme?: ReactNode } // Desk's first section
|
|
432
434
|
// defaultScheme: what applies while nothing is chosen (default 'system'); give colorSchemeScript the same
|
|
433
435
|
// DeskApp.themeFromHost?: boolean // receives its theme from a host: no scheme/look/theme rows (sounds stay); default: found from the bridge
|
|
@@ -443,7 +445,7 @@ setPreferenceStore(store?); getPreference(key); setPreference(key, value); subsc
|
|
|
443
445
|
dockSettings(); dockAbout() // markers: where the gear / About go, among dock entries OR in a stack's items
|
|
444
446
|
// (a System stack); placed, Desk adds no loose one. Default: end of the system group
|
|
445
447
|
SETTINGS_WINDOW = 'settings'; ABOUT_WINDOW = 'about'; SettingsCommand = 'desk.settings'; SYSTEM_GROUP = 'system'
|
|
446
|
-
PANEL_LIMITS; SIDEBAR_LIMITS
|
|
448
|
+
PANEL_LIMITS; SIDEBAR_LIMITS; SIDEBAR_SIZE // the panel fits its content; the sidebar layout opens free at SIDEBAR_SIZE (720 × 640), resizable and fillable; Desktop `limits` for those ids overrides
|
|
447
449
|
openAbout(desk) // About as the dock opens it: a centred panel, or forward where it is
|
|
448
450
|
useOpenSettings(): (route?) => void // Settings as the gear opens it (the app's own `open` too); nothing without settings
|
|
449
451
|
openSettings(desk, route?) // the same, outside React (search results, link handlers); reads the provider's declaration
|
|
@@ -456,7 +458,8 @@ Declared, Desk adds: in the Dock, the gear (when there are settings) and About a
|
|
|
456
458
|
group (entries after `dockSeparator('system')`; a separator and group of their own when there is none); in the
|
|
457
459
|
MenuBar's app menu (first with `emphasis`, else one is made, named `name`) "About <name>", separator,
|
|
458
460
|
"Settings…" (mod+comma), separator, then the app's items; Desktop draws the `about` and (with `settings` and no `open`) `settings` windows as
|
|
459
|
-
centred panels (sidebar layout: a
|
|
461
|
+
centred panels (sidebar layout: a window like any other, with a Sidebar grouped by `group`; on a narrow screen,
|
|
462
|
+
(max-width: 600px), the list alone, then the section, its title in the title row after "‹ Settings"; arrows move, Enter opens). Gear, menu and ⌘, focus an
|
|
460
463
|
open panel where it is. ⌘, is bound by the provider on the command, so it works with no MenuBar; the menu item only
|
|
461
464
|
shows it. A `host` menu bar gets the same items through the same publish; the host owns ⌘, while it is up.
|
|
462
465
|
With facts, About has Copy: name + version, then each section's copyable facts. Never put credentials in facts.
|
|
@@ -616,7 +619,7 @@ interface Column<Row> { key; header; render?; align?; numeric?; sortable?; width
|
|
|
616
619
|
interface Sort { key: string; direction: 'ascending' | 'descending' }
|
|
617
620
|
|
|
618
621
|
<Sidebar sections={{ id, label?, items: { id, label, icon?, badge?, disabled? }[] }[]}
|
|
619
|
-
value onChange label footer? />
|
|
622
|
+
value onChange label footer? focusOnly? /> // focusOnly: arrows move focus only, Enter/click chooses (a list shown alone)
|
|
620
623
|
|
|
621
624
|
<Outline rows={{ id, label, depth, disabled? }[]} value={string | null} onChange showing? label />
|
|
622
625
|
```
|
package/package.json
CHANGED
package/src/core/desk.ts
CHANGED
|
@@ -139,6 +139,15 @@ export function nextCascadeFrame(windows: readonly DeskWindow[], stage: Size, op
|
|
|
139
139
|
return cascadeFrame(taken.size % options.wrap, stage, options)
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
/** A frame of this size in the middle of the stage, made smaller where the stage is, keeping a margin. */
|
|
143
|
+
export function centredFrame(size: Size, stage: Size, margin: number): Frame {
|
|
144
|
+
// A stage not measured yet has no size to fit to: the size as asked, at the margin.
|
|
145
|
+
if (stage.width <= 0 || stage.height <= 0) return { x: margin, y: margin, ...size }
|
|
146
|
+
const width = Math.max(0, Math.min(size.width, stage.width - margin * 2))
|
|
147
|
+
const height = Math.max(0, Math.min(size.height, stage.height - margin * 2))
|
|
148
|
+
return { x: Math.round((stage.width - width) / 2), y: Math.round((stage.height - height) / 2), width, height }
|
|
149
|
+
}
|
|
150
|
+
|
|
142
151
|
/** Is this frame wholly on a desk of this size? */
|
|
143
152
|
const withinStage = (frame: Frame, stage: Size) =>
|
|
144
153
|
frame.x >= 0 && frame.y >= 0 && frame.x + frame.width <= stage.width && frame.y + frame.height <= stage.height
|
|
@@ -279,10 +288,10 @@ export function createDesk(options: DeskOptions = {}): Desk {
|
|
|
279
288
|
}
|
|
280
289
|
const saved = opts.mode || opts.frame ? undefined : layouts?.load(windowType(id))
|
|
281
290
|
const kept = saved?.mode === 'floating' ? fitFrame(saved.frame, stage()) : null
|
|
282
|
-
const mode = opts.mode ?? (opts.frame || kept ? 'floating' : 'filled')
|
|
291
|
+
const mode = opts.mode ?? (opts.frame || kept || (opts.size && !saved) ? 'floating' : 'filled')
|
|
283
292
|
const frame = () => {
|
|
284
293
|
if (opts.frame) return opts.frame
|
|
285
|
-
if (!kept) return nextFrame(state)
|
|
294
|
+
if (!kept) return opts.size ? centredFrame(opts.size, stage(), cascade.margin) : nextFrame(state)
|
|
286
295
|
const siblings = state.stack.flatMap(other => {
|
|
287
296
|
const w = find(other)
|
|
288
297
|
return w?.mode === 'floating' && windowType(w.id) === windowType(id) ? [w.frame] : []
|
package/src/core/types.ts
CHANGED
|
@@ -62,6 +62,11 @@ export interface OpenOptions {
|
|
|
62
62
|
/** Open as a free window rather than filling the desk. Given a frame, it floats there. */
|
|
63
63
|
readonly mode?: WindowMode
|
|
64
64
|
readonly frame?: Frame
|
|
65
|
+
/**
|
|
66
|
+
* A window that is best free at a size of its own, such as a big Settings: unless the person left it filled
|
|
67
|
+
* or at a frame last time, it opens free at this size, centred and fitted to the desk.
|
|
68
|
+
*/
|
|
69
|
+
readonly size?: Size
|
|
65
70
|
/** Where inside the window: given to a window already open, it moves there as it comes forward. */
|
|
66
71
|
readonly route?: string
|
|
67
72
|
}
|
package/src/css/apps.css
CHANGED
|
@@ -237,3 +237,20 @@
|
|
|
237
237
|
flex-direction: column;
|
|
238
238
|
gap: var(--desk-space-5);
|
|
239
239
|
}
|
|
240
|
+
|
|
241
|
+
/* A section's note, where there is no title bar to carry it: under its heading. */
|
|
242
|
+
.desk-settings-note {
|
|
243
|
+
margin: 0 0 var(--desk-space-3);
|
|
244
|
+
font-size: var(--desk-text-small);
|
|
245
|
+
color: var(--desk-muted);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* On a narrow screen, the list alone fills Settings, and Back leads a section. */
|
|
249
|
+
.desk-settings-list {
|
|
250
|
+
height: 100%;
|
|
251
|
+
overflow: auto;
|
|
252
|
+
}
|
|
253
|
+
.desk-settings-back {
|
|
254
|
+
align-self: flex-start;
|
|
255
|
+
margin-bottom: var(--desk-space-3);
|
|
256
|
+
}
|
package/src/css/windows.css
CHANGED
|
@@ -172,6 +172,34 @@
|
|
|
172
172
|
color: var(--desk-muted);
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
/* The way back from a view one step in, before the title: "‹ Settings", as a phone's navigation bar has it. */
|
|
176
|
+
.desk-window-back {
|
|
177
|
+
flex: none;
|
|
178
|
+
display: inline-flex;
|
|
179
|
+
align-items: center;
|
|
180
|
+
gap: 2px;
|
|
181
|
+
margin: 0 var(--desk-space-2) 0 0;
|
|
182
|
+
padding: 2px var(--desk-space-1);
|
|
183
|
+
border: 0;
|
|
184
|
+
border-radius: 6px;
|
|
185
|
+
background: none;
|
|
186
|
+
color: var(--desk-accent);
|
|
187
|
+
font: inherit;
|
|
188
|
+
font-size: var(--desk-text-body);
|
|
189
|
+
cursor: pointer;
|
|
190
|
+
}
|
|
191
|
+
.desk-window-back > span {
|
|
192
|
+
font-size: var(--desk-text-title);
|
|
193
|
+
line-height: 1;
|
|
194
|
+
}
|
|
195
|
+
.desk-window-back:hover {
|
|
196
|
+
background: color-mix(in oklab, var(--desk-accent) 12%, transparent);
|
|
197
|
+
}
|
|
198
|
+
.desk-window-back:focus-visible {
|
|
199
|
+
outline: 2px solid var(--desk-accent);
|
|
200
|
+
outline-offset: 1px;
|
|
201
|
+
}
|
|
202
|
+
|
|
175
203
|
.desk-window-note {
|
|
176
204
|
margin: 0 0 0 auto;
|
|
177
205
|
min-width: 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
|
@@ -215,6 +215,17 @@ export interface WindowContextValue {
|
|
|
215
215
|
readonly setNote: (note: ReactNode) => void
|
|
216
216
|
/** Where `useWindowInfo` reports to, the same way. */
|
|
217
217
|
readonly setInfo: (info: ReactNode) => void
|
|
218
|
+
/** Where `useWindowBack` reports to: `undefined` puts the window's own title back. */
|
|
219
|
+
readonly setBack: (back: WindowBack | undefined) => void
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** A view one step into the window: the way back, named for where it leads, and the title while it shows. */
|
|
223
|
+
export interface WindowBack {
|
|
224
|
+
/** The parent, as the button names it: "‹ Settings", read as "Back to Settings". */
|
|
225
|
+
readonly label: string
|
|
226
|
+
/** What the title says while this view shows, such as the section open in Settings. */
|
|
227
|
+
readonly title: ReactNode
|
|
228
|
+
readonly onBack: () => void
|
|
218
229
|
}
|
|
219
230
|
|
|
220
231
|
/** Present inside a window's content: which window this is, and its element. */
|
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/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])
|