@liberation-data/desk 0.6.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 +99 -1
- 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 +2 -2
- 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 +14 -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 +10 -3
- package/dist/react/Desktop.d.ts.map +1 -1
- package/dist/react/Desktop.js +30 -13
- 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 +9 -2
- package/dist/react/appFrame.d.ts.map +1 -1
- package/dist/react/appFrame.js +26 -5
- 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 +38 -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 +3 -0
- package/src/core/location.ts +15 -7
- package/src/core/types.ts +15 -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 +48 -14
- package/src/react/Dock.tsx +10 -4
- package/src/react/MenuBar.tsx +12 -3
- package/src/react/appFrame.tsx +52 -5
- package/src/react/documentTitle.ts +52 -0
- package/src/react/index.ts +2 -0
package/dist/react/appFrame.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { Accepts } from './dnd.js';
|
|
2
|
+
export interface AppTheme {
|
|
3
|
+
readonly mode: 'light' | 'dark';
|
|
4
|
+
/** Custom properties, named as they will be set: `{ '--sb-bg-dark': '#0b0f1a' }`. */
|
|
5
|
+
readonly tokens: Readonly<Record<string, string>>;
|
|
6
|
+
}
|
|
2
7
|
export interface AppFrameProps {
|
|
3
8
|
/** The accessible name of the frame: what the app is. */
|
|
4
9
|
readonly title: string;
|
|
@@ -9,6 +14,8 @@ export interface AppFrameProps {
|
|
|
9
14
|
readonly listens?: readonly string[];
|
|
10
15
|
/** Topics the app may say. Anything else it publishes is dropped. Default: none. */
|
|
11
16
|
readonly says?: readonly string[];
|
|
17
|
+
/** The desk's own look, offered to the app: it is applied to the app's root and re-sent on change. */
|
|
18
|
+
readonly theme?: AppTheme;
|
|
12
19
|
/** What may be dropped on it. Default: nothing. */
|
|
13
20
|
readonly accepts?: Accepts;
|
|
14
21
|
/** Windows the app may ask to open. Default: none. */
|
|
@@ -20,7 +27,7 @@ export interface AppFrameProps {
|
|
|
20
27
|
readonly sandbox?: string;
|
|
21
28
|
readonly className?: string;
|
|
22
29
|
}
|
|
23
|
-
export declare function AppFrame({ title, src, srcDoc, listens, says, accepts, opens, sandbox, className, }: AppFrameProps): import("react").JSX.Element;
|
|
30
|
+
export declare function AppFrame({ title, src, srcDoc, listens, says, theme, accepts, opens, sandbox, className, }: AppFrameProps): import("react").JSX.Element;
|
|
24
31
|
/**
|
|
25
32
|
* The app's half of the bridge, as a script to put in its page. It gives the page a
|
|
26
33
|
* small `desk` object:
|
|
@@ -31,7 +38,7 @@ export declare function AppFrame({ title, src, srcDoc, listens, says, accepts, o
|
|
|
31
38
|
* desk.open('map') ask for a window, if it was granted
|
|
32
39
|
* desk.window which window this is, once connected
|
|
33
40
|
*/
|
|
34
|
-
export declare const APP_BRIDGE_SCRIPT = "(() => {\n const handlers = new Map();\n const drops = [];\n const send = message => parent.postMessage(Object.assign({ desk: 1 }, message), '*');\n const desk = {\n window: null,\n listens: [],\n says: [],\n on(topic, handler) { (handlers.get(topic) || handlers.set(topic, []).get(topic)).push(handler); },\n onDrop(handler) { drops.push(handler); },\n publish(topic, payload) { send({ kind: 'publish', topic, payload }); },\n open(window) { send({ kind: 'open', window }); },\n };\n const matches = (pattern, topic) =>\n pattern === '*' || pattern === topic || (pattern.endsWith('.*') && (topic === pattern.slice(0, -2) || topic.startsWith(pattern.slice(0, -1))));\n addEventListener('message', event => {\n if (event.source !== parent || !event.data || event.data.desk !== 1) return;\n const message = event.data;\n if (message.kind === 'hello') { desk.window = message.window; desk.listens = message.listens; desk.says = message.says; }\n if (message.kind === 'event') for (const [pattern, list] of handlers) if (matches(pattern, message.topic)) list.forEach(h => h(message));\n if (message.kind === 'drop') drops.forEach(h => h(message));\n });\n window.desk = desk;\n send({ kind: 'ready' });\n})();";
|
|
41
|
+
export declare const APP_BRIDGE_SCRIPT = "(() => {\n const handlers = new Map();\n const drops = [];\n const send = message => parent.postMessage(Object.assign({ desk: 1 }, message), '*');\n const applyTheme = theme => {\n if (!theme) return;\n desk.theme = theme;\n const root = document.documentElement;\n root.dataset.theme = theme.mode;\n root.style.colorScheme = theme.mode;\n for (const [name, value] of Object.entries(theme.tokens || {})) root.style.setProperty(name, value);\n themed.forEach(h => h(theme));\n };\n const themed = [];\n const desk = {\n window: null,\n listens: [],\n says: [],\n theme: null,\n onTheme(handler) { themed.push(handler); if (desk.theme) handler(desk.theme); },\n on(topic, handler) { (handlers.get(topic) || handlers.set(topic, []).get(topic)).push(handler); },\n onDrop(handler) { drops.push(handler); },\n publish(topic, payload) { send({ kind: 'publish', topic, payload }); },\n open(window) { send({ kind: 'open', window }); },\n };\n const matches = (pattern, topic) =>\n pattern === '*' || pattern === topic || (pattern.endsWith('.*') && (topic === pattern.slice(0, -2) || topic.startsWith(pattern.slice(0, -1))));\n addEventListener('message', event => {\n if (event.source !== parent || !event.data || event.data.desk !== 1) return;\n const message = event.data;\n if (message.kind === 'hello') { desk.window = message.window; desk.listens = message.listens; desk.says = message.says; applyTheme(message.theme); }\n if (message.kind === 'theme') applyTheme(message.theme);\n if (message.kind === 'event') for (const [pattern, list] of handlers) if (matches(pattern, message.topic)) list.forEach(h => h(message));\n if (message.kind === 'drop') drops.forEach(h => h(message));\n });\n window.desk = desk;\n send({ kind: 'ready' });\n})();";
|
|
35
42
|
/** Puts the bridge into a page of HTML, so a generated app needs nothing added by hand. */
|
|
36
43
|
export declare function withAppBridge(html: string): string;
|
|
37
44
|
//# sourceMappingURL=appFrame.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appFrame.d.ts","sourceRoot":"","sources":["../../src/react/appFrame.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"appFrame.d.ts","sourceRoot":"","sources":["../../src/react/appFrame.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAiCvC,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAA;IAC/B,qFAAqF;IACrF,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAClD;AAgBD,MAAM,WAAW,aAAa;IAC5B,yDAAyD;IACzD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,gEAAgE;IAChE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,wFAAwF;IACxF,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACpC,oFAAoF;IACpF,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACjC,sGAAsG;IACtG,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAA;IACzB,mDAAmD;IACnD,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IAC1B,sDAAsD;IACtD,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAClC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EACL,GAAG,EACH,MAAM,EACN,OAAY,EACZ,IAAS,EACT,KAAK,EACL,OAAO,EACP,KAAU,EACV,OAAqC,EACrC,SAAS,GACV,EAAE,aAAa,+BAiFf;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,qyDAqCxB,CAAA;AAEN,2FAA2F;AAC3F,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGlD"}
|
package/dist/react/appFrame.js
CHANGED
|
@@ -16,7 +16,7 @@ import { useBus } from './events.js';
|
|
|
16
16
|
/** The protocol version. Every message carries it, so a mismatch is ignored rather than misread. */
|
|
17
17
|
const PROTOCOL = 1;
|
|
18
18
|
const isAppMessage = (data) => typeof data === 'object' && data !== null && data.desk === PROTOCOL && typeof data.kind === 'string';
|
|
19
|
-
export function AppFrame({ title, src, srcDoc, listens = [], says = [], accepts, opens = [], sandbox = 'allow-scripts allow-forms', className, }) {
|
|
19
|
+
export function AppFrame({ title, src, srcDoc, listens = [], says = [], theme, accepts, opens = [], sandbox = 'allow-scripts allow-forms', className, }) {
|
|
20
20
|
const desk = useDesk();
|
|
21
21
|
const bus = useBus();
|
|
22
22
|
const windowId = useWindowId();
|
|
@@ -28,8 +28,8 @@ export function AppFrame({ title, src, srcDoc, listens = [], says = [], accepts,
|
|
|
28
28
|
// window and no other.
|
|
29
29
|
frame.current?.contentWindow?.postMessage(message, '*');
|
|
30
30
|
};
|
|
31
|
-
const latest = useRef({ listens, says, opens, windowId });
|
|
32
|
-
latest.current = { listens, says, opens, windowId };
|
|
31
|
+
const latest = useRef({ listens, says, opens, windowId, theme });
|
|
32
|
+
latest.current = { listens, says, opens, windowId, theme };
|
|
33
33
|
// What the app says: only from this frame, only on topics it was granted.
|
|
34
34
|
useEffect(() => {
|
|
35
35
|
const onMessage = (event) => {
|
|
@@ -38,7 +38,7 @@ export function AppFrame({ title, src, srcDoc, listens = [], says = [], accepts,
|
|
|
38
38
|
const message = event.data;
|
|
39
39
|
const granted = latest.current;
|
|
40
40
|
if (message.kind === 'ready') {
|
|
41
|
-
post({ desk: PROTOCOL, kind: 'hello', window: granted.windowId, listens: granted.listens, says: granted.says });
|
|
41
|
+
post({ desk: PROTOCOL, kind: 'hello', window: granted.windowId, listens: granted.listens, says: granted.says, theme: granted.theme ?? null });
|
|
42
42
|
}
|
|
43
43
|
else if (message.kind === 'publish') {
|
|
44
44
|
if (typeof message.topic === 'string' && granted.says.some(pattern => topicMatches(pattern, message.topic))) {
|
|
@@ -53,6 +53,14 @@ export function AppFrame({ title, src, srcDoc, listens = [], says = [], accepts,
|
|
|
53
53
|
window.addEventListener('message', onMessage);
|
|
54
54
|
return () => window.removeEventListener('message', onMessage);
|
|
55
55
|
}, [bus, desk]);
|
|
56
|
+
// The desk's look, again, whenever it changes: a person switching theme switches the app too.
|
|
57
|
+
const themeKey = theme ? `${theme.mode}|${Object.entries(theme.tokens).map(([k, v]) => `${k}:${v}`).join(';')}` : '';
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!latest.current.theme)
|
|
60
|
+
return;
|
|
61
|
+
post({ desk: PROTOCOL, kind: 'theme', theme: latest.current.theme });
|
|
62
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
63
|
+
}, [themeKey]);
|
|
56
64
|
// What the app hears: only the topics it was granted, and never its own words back.
|
|
57
65
|
const listenKey = listens.join('|');
|
|
58
66
|
useEffect(() => {
|
|
@@ -90,10 +98,22 @@ export const APP_BRIDGE_SCRIPT = `(() => {
|
|
|
90
98
|
const handlers = new Map();
|
|
91
99
|
const drops = [];
|
|
92
100
|
const send = message => parent.postMessage(Object.assign({ desk: ${PROTOCOL} }, message), '*');
|
|
101
|
+
const applyTheme = theme => {
|
|
102
|
+
if (!theme) return;
|
|
103
|
+
desk.theme = theme;
|
|
104
|
+
const root = document.documentElement;
|
|
105
|
+
root.dataset.theme = theme.mode;
|
|
106
|
+
root.style.colorScheme = theme.mode;
|
|
107
|
+
for (const [name, value] of Object.entries(theme.tokens || {})) root.style.setProperty(name, value);
|
|
108
|
+
themed.forEach(h => h(theme));
|
|
109
|
+
};
|
|
110
|
+
const themed = [];
|
|
93
111
|
const desk = {
|
|
94
112
|
window: null,
|
|
95
113
|
listens: [],
|
|
96
114
|
says: [],
|
|
115
|
+
theme: null,
|
|
116
|
+
onTheme(handler) { themed.push(handler); if (desk.theme) handler(desk.theme); },
|
|
97
117
|
on(topic, handler) { (handlers.get(topic) || handlers.set(topic, []).get(topic)).push(handler); },
|
|
98
118
|
onDrop(handler) { drops.push(handler); },
|
|
99
119
|
publish(topic, payload) { send({ kind: 'publish', topic, payload }); },
|
|
@@ -104,7 +124,8 @@ export const APP_BRIDGE_SCRIPT = `(() => {
|
|
|
104
124
|
addEventListener('message', event => {
|
|
105
125
|
if (event.source !== parent || !event.data || event.data.desk !== ${PROTOCOL}) return;
|
|
106
126
|
const message = event.data;
|
|
107
|
-
if (message.kind === 'hello') { desk.window = message.window; desk.listens = message.listens; desk.says = message.says; }
|
|
127
|
+
if (message.kind === 'hello') { desk.window = message.window; desk.listens = message.listens; desk.says = message.says; applyTheme(message.theme); }
|
|
128
|
+
if (message.kind === 'theme') applyTheme(message.theme);
|
|
108
129
|
if (message.kind === 'event') for (const [pattern, list] of handlers) if (matches(pattern, message.topic)) list.forEach(h => h(message));
|
|
109
130
|
if (message.kind === 'drop') drops.forEach(h => h(message));
|
|
110
131
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appFrame.js","sourceRoot":"","sources":["../../src/react/appFrame.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAErD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC;;;;;;;;GAQG;AAEH,oGAAoG;AACpG,MAAM,QAAQ,GAAG,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"appFrame.js","sourceRoot":"","sources":["../../src/react/appFrame.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAErD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC;;;;;;;;GAQG;AAEH,oGAAoG;AACpG,MAAM,QAAQ,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AE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC1E,KAAK,EAAE,UAAU,GACjB,GACE,CACP,CAAA;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;qEAGoC,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;wEAyBL,QAAQ;;;;;;;;;MAS1E,CAAA;AAEN,2FAA2F;AAC3F,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,MAAM,GAAG,WAAW,iBAAiB,WAAW,CAAA;IACtD,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,IAAI,EAAE,CAAA;AACpH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WindowId } from '../core/types.js';
|
|
2
|
+
export interface DocumentTitleOptions {
|
|
3
|
+
/** The app's name, kept after the window's: `Rides — Garage`. Defaults to the document's own title. */
|
|
4
|
+
readonly app?: string;
|
|
5
|
+
/** What goes between the two names. */
|
|
6
|
+
readonly separator?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Keeps `document.title` on the frontmost window: `Rides — Garage`, and `Garage` with nothing open. */
|
|
9
|
+
export declare function useDocumentTitle(title: (id: WindowId) => string, options?: DocumentTitleOptions): void;
|
|
10
|
+
//# sourceMappingURL=documentTitle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentTitle.d.ts","sourceRoot":"","sources":["../../src/react/documentTitle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAkBhD,MAAM,WAAW,oBAAoB;IACnC,uGAAuG;IACvG,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,uCAAuC;IACvC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAC5B;AAID,wGAAwG;AACxG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,QAAQ,KAAK,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,IAAI,CAqB1G"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { focusedId } from '../core/desk.js';
|
|
3
|
+
import { useDeskState } from './context.js';
|
|
4
|
+
const DEFAULT_SEPARATOR = ' — ';
|
|
5
|
+
/** Keeps `document.title` on the frontmost window: `Rides — Garage`, and `Garage` with nothing open. */
|
|
6
|
+
export function useDocumentTitle(title, options = {}) {
|
|
7
|
+
const { app, separator = DEFAULT_SEPARATOR } = options;
|
|
8
|
+
const state = useDeskState();
|
|
9
|
+
const id = focusedId(state);
|
|
10
|
+
// What the page was called before the desk took it over: the app's name by default, and what
|
|
11
|
+
// is put back on the way out. Read once, so a title this hook set is never mistaken for it.
|
|
12
|
+
const [original] = useState(() => (typeof document === 'undefined' ? '' : document.title));
|
|
13
|
+
const base = app ?? original;
|
|
14
|
+
const front = id === null ? '' : title(id);
|
|
15
|
+
const next = front && base ? `${front}${separator}${base}` : front || base;
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (next)
|
|
18
|
+
document.title = next;
|
|
19
|
+
}, [next]);
|
|
20
|
+
// Only on the way out: a restore that ran between renders would flicker the real title away.
|
|
21
|
+
useEffect(() => () => {
|
|
22
|
+
document.title = original;
|
|
23
|
+
}, [original]);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=documentTitle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentTitle.js","sourceRoot":"","sources":["../../src/react/documentTitle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,EAAE,S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ANGED
|
@@ -10,6 +10,8 @@ export { useCanPerform, useCommand, usePerform, useShortcuts } from './commands.
|
|
|
10
10
|
export type { UseCommandOptions } from './commands.js';
|
|
11
11
|
export { Desktop } from './Desktop.js';
|
|
12
12
|
export type { DeskLayout, DesktopProps } from './Desktop.js';
|
|
13
|
+
export { useDocumentTitle } from './documentTitle.js';
|
|
14
|
+
export type { DocumentTitleOptions } from './documentTitle.js';
|
|
13
15
|
export { lazyWindow } from './windowBoundary.js';
|
|
14
16
|
export type { WindowFailed, WindowLoading } from './windowBoundary.js';
|
|
15
17
|
export { Button, Checkbox, ChoiceGroup, RadioGroup, SegmentedControl, Slider, TextField, Toggle } from './controls.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC1E,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAChG,YAAY,EACV,OAAO,EACP,IAAI,EACJ,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/E,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACnF,YAAY,EAAE,iBAAiB,EAAE,MA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ACjH,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC3G,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AACrG,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC/E,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA"}
|
package/dist/react/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { DeskShell } from './shell.js';
|
|
|
4
4
|
export { DeskProvider, useDesk, useDeskState, useWindowId } from './context.js';
|
|
5
5
|
export { useCanPerform, useCommand, usePerform, useShortcuts } from './commands.js';
|
|
6
6
|
export { Desktop } from './Desktop.js';
|
|
7
|
+
export { useDocumentTitle } from './documentTitle.js';
|
|
7
8
|
export { lazyWindow } from './windowBoundary.js';
|
|
8
9
|
export { Button, Checkbox, ChoiceGroup, RadioGroup, SegmentedControl, Slider, TextField, Toggle } from './controls.js';
|
|
9
10
|
export { Pane, Toolbar } from './pane.js';
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAE1E,OAAO,EAAE,YA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O,EAAE,MAAM,WAAW,CAAA;AAEzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAGtE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEzE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAErG,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE9E,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC3G,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAGjD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA"}
|
package/llms.txt
CHANGED
|
@@ -62,7 +62,8 @@ interface Desk {
|
|
|
62
62
|
openInstance(type: string, options?): string // 'query', then 'query#2' — returns the id it opened
|
|
63
63
|
close(id: string): void
|
|
64
64
|
closeAll(): void
|
|
65
|
-
|
|
65
|
+
minimize(id: string): void // off the desk, still open and loaded; see Minimizing
|
|
66
|
+
focus(id: string): void // forward, and back onto the desk when minimized
|
|
66
67
|
float(id: string, frame?: Frame): void // no frame: last place it sat, else the next cascade step
|
|
67
68
|
fill(id: string): void // fill the desk; remembers the frame for float()
|
|
68
69
|
toggleMode(id: string): void // zoom: fill ⇄ free
|
|
@@ -77,7 +78,8 @@ interface Desk {
|
|
|
77
78
|
|
|
78
79
|
interface DeskState {
|
|
79
80
|
windows: readonly DeskWindow[] // the order they were opened = the order Arrange lays out
|
|
80
|
-
stack: readonly string[] // back to front; the last one is key
|
|
81
|
+
stack: readonly string[] // back to front; the last one NOT minimized is key
|
|
82
|
+
minimized?: readonly string[] // open and off the desk; absent while nothing is
|
|
81
83
|
}
|
|
82
84
|
type DeskWindow = { id: string; mode: 'filled' } | { id: string; mode: 'floating'; frame: Frame }
|
|
83
85
|
interface Frame { x: number; y: number; width: number; height: number }
|
|
@@ -98,11 +100,26 @@ lays windows out once as free windows (`placeAll`); moving or resizing one chang
|
|
|
98
100
|
filled window frees it where it sits. Edge drops take a half; double-click or the green control zooms. State is immutable; every mutator returns void and notifies
|
|
99
101
|
subscribers only when something actually changed.
|
|
100
102
|
|
|
103
|
+
### Minimizing
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
desk.minimize(id) // off the desk, still open and still mounted
|
|
107
|
+
desk.focus(id) / desk.open(id) // and back, to the mode and frame it had — there is no un-minimize
|
|
108
|
+
isMinimized(state, id) / onDesk(state)
|
|
109
|
+
state.minimized?: readonly WindowId[] // absent while nothing is minimized
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Deliberately NOT a `WindowMode`: the window keeps its mode and frame, which is how it comes back to them.
|
|
113
|
+
`focusedId` skips minimized windows, so a desk with everything minimized has no key window and shows
|
|
114
|
+
`<Desktop empty>`; Arrange, window cycling and `fitToStage` skip them too. The title bar's amber control and
|
|
115
|
+
`DeskCommands.minimizeWindow` (⌘M) do it. The dock keeps `data-running` and adds `data-minimized`;
|
|
116
|
+
`windowMenuItems` gives the item `detail: 'Minimized'`.
|
|
117
|
+
|
|
101
118
|
### URL and history
|
|
102
119
|
|
|
103
120
|
```ts
|
|
104
121
|
syncWithLocation(desk, stage: () => Size, options?: LocationOptions, env?: LocationEnv): () => void
|
|
105
|
-
serialize(state, options?): URLSearchParams // #w=rides,map
|
|
122
|
+
serialize(state, options?): URLSearchParams // #w=rides,map~_&f=rides (`~` = free, `_` = minimized)
|
|
106
123
|
parse(params, stage, options?): DeskState
|
|
107
124
|
interface LocationOptions { key?: 'w'; focusKey?: 'f'; isKnown?: (id: string) => boolean }
|
|
108
125
|
```
|
|
@@ -110,6 +127,17 @@ interface LocationOptions { key?: 'w'; focusKey?: 'f'; isKnown?: (id: string) =>
|
|
|
110
127
|
Opening or closing pushes history (Back closes); focus and mode changes replace it. Frames are never in the
|
|
111
128
|
URL. Other hash parameters are left alone. A URL naming no windows adopts whatever the app opened.
|
|
112
129
|
|
|
130
|
+
### The browser tab
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
useDocumentTitle(title: (id: WindowId) => string, options?: DocumentTitleOptions): void
|
|
134
|
+
interface DocumentTitleOptions { app?: string; separator?: string } // default separator ' — '
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
`document.title` follows the frontmost window — `Rides — Garage` — and is the app's name alone with nothing
|
|
138
|
+
open. `app` defaults to the document's own title (the page's `<title>`), and is restored on unmount. The
|
|
139
|
+
window's name is a string here, not the `ReactNode` `<Desktop title>` renders.
|
|
140
|
+
|
|
113
141
|
### Commands (the responder chain)
|
|
114
142
|
|
|
115
143
|
```ts
|
|
@@ -119,7 +147,7 @@ addCommandHandler(element: EventTarget, command, handler, { enabled? }): () => v
|
|
|
119
147
|
addDeskCommands(stage: EventTarget, desk): () => void
|
|
120
148
|
chainStart(desk, options?): EventTarget
|
|
121
149
|
windowElement(doc, id): Element | null
|
|
122
|
-
DeskCommands = { closeWindow, zoomWindow, arrange, nextWindow, previousWindow }
|
|
150
|
+
DeskCommands = { closeWindow, minimizeWindow, zoomWindow, arrange, nextWindow, previousWindow }
|
|
123
151
|
// arrange is answered by a mounted Desktop: 1 fills, 2 split, 3 one tall + two stacked, 4+ a grid of usable cells;
|
|
124
152
|
// the focused window takes the first place. Put it in the Window menu as "Arrange", shortcut 'mod+alt+a'.
|
|
125
153
|
WINDOW_ATTRIBUTE = 'data-desk-window'; STAGE_ATTRIBUTE = 'data-desk-stage'
|
|
@@ -190,6 +218,8 @@ useWindowId(): string | null // inside a window's content
|
|
|
190
218
|
title={(id) => ReactNode}
|
|
191
219
|
note?={(id) => ReactNode} // quiet text in the title bar: what this window is looking at
|
|
192
220
|
info?={(id) => ReactNode} // an (i) at the end of the title bar: what this window IS
|
|
221
|
+
limits?={(id) => ({ maxWidth?, maxHeight?, minWidth?, minHeight? } | null)} // a window with a natural
|
|
222
|
+
// size is never stretched past it; filled, it centres
|
|
193
223
|
actions?={(id) => ReactNode} // window-wide controls in the title bar
|
|
194
224
|
loading?={(id) => ReactNode} // inside a window while its code loads
|
|
195
225
|
failed?={(id, error, reload) => ReactNode} // inside a window that could not open
|
|
@@ -306,13 +336,16 @@ useDeskEvent<T>(topic, handler, { replay? }) // replay: deliver the las
|
|
|
306
336
|
|
|
307
337
|
```tsx
|
|
308
338
|
<AppFrame title src?|srcDoc? listens?={string[]} says?={string[]} accepts?={Accepts} opens?={string[]}
|
|
339
|
+
theme?={{ mode: 'light'|'dark', tokens: Record<string,string> }}
|
|
309
340
|
sandbox?="allow-scripts allow-forms" />
|
|
341
|
+
// theme: sent with hello and again on change; the bridge sets the tokens as custom properties on the
|
|
342
|
+
// app's root, with data-theme and color-scheme (the attribute desk's own CSS and the HIG use). The app may read desk.theme / desk.onTheme(fn).
|
|
310
343
|
withAppBridge(html): string // puts the app-side script in the page's <head>
|
|
311
344
|
APP_BRIDGE_SCRIPT // the same script, to include some other way
|
|
312
345
|
```
|
|
313
346
|
|
|
314
347
|
Inside the page: `desk.on(topic, message => …)`, `desk.onDrop(message => …)`, `desk.publish(topic, payload)`,
|
|
315
|
-
`desk.open(window)`, and `desk.window` once connected. Messages carry `desk: 1`. The host ignores anything not
|
|
348
|
+
`desk.open(window)`, `desk.theme`, `desk.onTheme(fn)`, and `desk.window` once connected. Messages carry `desk: 1`. The host ignores anything not
|
|
316
349
|
from its own frame, drops publishes outside `says` and opens outside `opens`, never echoes an app its own
|
|
317
350
|
events, and sets the frame's `pointer-events: none` while a drag is in the air so drops reach it.
|
|
318
351
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liberation-data/desk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A desktop for the web, for React: windows, a dock, menus and commands, controls, tours and setup assistants.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"desktop",
|
|
8
|
+
"window-manager",
|
|
9
|
+
"windows",
|
|
10
|
+
"dock",
|
|
11
|
+
"menu-bar",
|
|
12
|
+
"commands",
|
|
13
|
+
"ui",
|
|
14
|
+
"ui-components",
|
|
15
|
+
"typescript",
|
|
16
|
+
"web-desktop",
|
|
17
|
+
"tours",
|
|
18
|
+
"onboarding"
|
|
19
|
+
],
|
|
5
20
|
"license": "Apache-2.0",
|
|
6
21
|
"author": "Jasper Blues",
|
|
7
22
|
"repository": {
|
package/src/core/commands.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { focusedId } from './desk.js'
|
|
1
|
+
import { focusedId, onDesk } from './desk.js'
|
|
2
2
|
import type { Desk } from './desk.js'
|
|
3
3
|
|
|
4
4
|
/*
|
|
@@ -118,6 +118,8 @@ export const DeskCommands = {
|
|
|
118
118
|
closeWindow: 'desk.window.close',
|
|
119
119
|
/** Fills the key window, or frees it: the green control. */
|
|
120
120
|
zoomWindow: 'desk.window.zoom',
|
|
121
|
+
/** Takes the key window off the desk, still open and still loaded: the amber control. */
|
|
122
|
+
minimizeWindow: 'desk.window.minimize',
|
|
121
123
|
/** Answered by a mounted Desktop, which knows the space windows are laid out in. */
|
|
122
124
|
arrange: 'desk.window.arrange',
|
|
123
125
|
nextWindow: 'desk.window.next',
|
|
@@ -126,8 +128,10 @@ export const DeskCommands = {
|
|
|
126
128
|
|
|
127
129
|
export function addDeskCommands(stage: EventTarget, desk: Desk): () => void {
|
|
128
130
|
const key = () => focusedId(desk.getState())
|
|
131
|
+
// Only the windows on the desk: cycling through a minimized one would drag it back out by the way.
|
|
129
132
|
const cycle = (step: 1 | -1) => {
|
|
130
|
-
const
|
|
133
|
+
const windows = onDesk(desk.getState())
|
|
134
|
+
if (!windows.length) return
|
|
131
135
|
const current = windows.findIndex(w => w.id === key())
|
|
132
136
|
const next = windows[(current + step + windows.length) % windows.length]
|
|
133
137
|
if (next) desk.focus(next.id)
|
|
@@ -135,8 +139,9 @@ export function addDeskCommands(stage: EventTarget, desk: Desk): () => void {
|
|
|
135
139
|
const removers = [
|
|
136
140
|
addCommandHandler(stage, DeskCommands.closeWindow, () => { const id = key(); if (id) desk.close(id) }, { enabled: () => key() !== null }),
|
|
137
141
|
addCommandHandler(stage, DeskCommands.zoomWindow, () => { const id = key(); if (id) desk.toggleMode(id) }, { enabled: () => key() !== null }),
|
|
138
|
-
addCommandHandler(stage, DeskCommands.
|
|
139
|
-
addCommandHandler(stage, DeskCommands.
|
|
142
|
+
addCommandHandler(stage, DeskCommands.minimizeWindow, () => { const id = key(); if (id) desk.minimize(id) }, { enabled: () => key() !== null }),
|
|
143
|
+
addCommandHandler(stage, DeskCommands.nextWindow, () => cycle(1), { enabled: () => onDesk(desk.getState()).length > 1 }),
|
|
144
|
+
addCommandHandler(stage, DeskCommands.previousWindow, () => cycle(-1), { enabled: () => onDesk(desk.getState()).length > 1 }),
|
|
140
145
|
]
|
|
141
146
|
return () => removers.forEach(remove => remove())
|
|
142
147
|
}
|
package/src/core/desk.ts
CHANGED
|
@@ -19,6 +19,12 @@ export interface Desk {
|
|
|
19
19
|
openInstance(type: string, options?: OpenOptions): WindowId
|
|
20
20
|
close(id: WindowId): void
|
|
21
21
|
closeAll(): void
|
|
22
|
+
/**
|
|
23
|
+
* Off the desk without being closed: still open, still mounted, and keeping the mode and frame it
|
|
24
|
+
* had. Focusing or opening it again brings it back.
|
|
25
|
+
*/
|
|
26
|
+
minimize(id: WindowId): void
|
|
27
|
+
/** Brings a window forward, and back onto the desk when it was minimized. */
|
|
22
28
|
focus(id: WindowId): void
|
|
23
29
|
/** Frees a window: where it last was, or at the next step of the cascade. Given a frame, puts it there. */
|
|
24
30
|
float(id: WindowId, frame?: Frame): void
|
|
@@ -59,7 +65,24 @@ const DEFAULT_CASCADE: CascadeOptions = {
|
|
|
59
65
|
|
|
60
66
|
const DEFAULT_STAGE: Size = { width: 1024, height: 768 }
|
|
61
67
|
|
|
62
|
-
|
|
68
|
+
/** Open, and off the desk: still mounted, and not somewhere anyone can point at. */
|
|
69
|
+
export const isMinimized = (state: DeskState, id: WindowId): boolean => state.minimized?.includes(id) ?? false
|
|
70
|
+
|
|
71
|
+
/** The windows on the desk, in the order they were opened: what Arrange lays out. */
|
|
72
|
+
export const onDesk = (state: DeskState): readonly DeskWindow[] =>
|
|
73
|
+
state.minimized?.length ? state.windows.filter(w => !isMinimized(state, w.id)) : state.windows
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The key window: the frontmost one on the desk. A minimized window keeps its place in the stack,
|
|
77
|
+
* so it comes back where it was, but is never key — there is nothing on screen to type into.
|
|
78
|
+
*/
|
|
79
|
+
export const focusedId = (state: DeskState): WindowId | null => {
|
|
80
|
+
for (let i = state.stack.length - 1; i >= 0; i--) {
|
|
81
|
+
const id = state.stack[i] as WindowId
|
|
82
|
+
if (!isMinimized(state, id)) return id
|
|
83
|
+
}
|
|
84
|
+
return null
|
|
85
|
+
}
|
|
63
86
|
|
|
64
87
|
/**
|
|
65
88
|
* Two windows onto the same thing — a second query beside the first — are the
|
|
@@ -117,7 +140,18 @@ export function normalise(state: DeskState): DeskState {
|
|
|
117
140
|
const ids = new Set(windows.map(w => w.id))
|
|
118
141
|
const stacked = state.stack.filter((id, i, all) => ids.has(id) && all.indexOf(id) === i)
|
|
119
142
|
const unstacked = windows.map(w => w.id).filter(id => !stacked.includes(id))
|
|
120
|
-
|
|
143
|
+
const minimized = state.minimized?.filter((id, i, all) => ids.has(id) && all.indexOf(id) === i) ?? []
|
|
144
|
+
const stack = [...unstacked, ...stacked]
|
|
145
|
+
// Left out while nothing is minimized: the everyday state is the two lists it always was.
|
|
146
|
+
return minimized.length ? { windows, stack, minimized } : { windows, stack }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Keeps the field out of the state while nothing is minimized, so the everyday state is two lists. */
|
|
150
|
+
function withMinimized(state: DeskState, ids: readonly WindowId[]): DeskState {
|
|
151
|
+
if (ids.length) return { ...state, minimized: ids }
|
|
152
|
+
if (!state.minimized) return state
|
|
153
|
+
const { minimized: _none, ...rest } = state
|
|
154
|
+
return rest
|
|
121
155
|
}
|
|
122
156
|
|
|
123
157
|
export function createDesk(options: DeskOptions = {}): Desk {
|
|
@@ -133,8 +167,14 @@ export function createDesk(options: DeskOptions = {}): Desk {
|
|
|
133
167
|
listeners.forEach(listener => listener(state))
|
|
134
168
|
}
|
|
135
169
|
|
|
136
|
-
|
|
137
|
-
|
|
170
|
+
/*
|
|
171
|
+
* Forward, and back onto the desk: there is no focused-but-minimized window, so every way of
|
|
172
|
+
* choosing one comes back through here.
|
|
173
|
+
*/
|
|
174
|
+
const toFront = (s: DeskState, id: WindowId): DeskState => {
|
|
175
|
+
const shown = withMinimized(s, s.minimized?.filter(x => x !== id) ?? [])
|
|
176
|
+
return shown.stack.at(-1) === id ? shown : { ...shown, stack: [...shown.stack.filter(x => x !== id), id] }
|
|
177
|
+
}
|
|
138
178
|
|
|
139
179
|
const nextFrame = (s: DeskState) => nextCascadeFrame(s.windows, stage(), cascade)
|
|
140
180
|
|
|
@@ -165,11 +205,16 @@ export function createDesk(options: DeskOptions = {}): Desk {
|
|
|
165
205
|
return frame.x + 40 <= width && frame.y + 20 <= height && frame.x >= 0 && frame.y >= 0 ? frame : undefined
|
|
166
206
|
}
|
|
167
207
|
|
|
208
|
+
/* Already in the mode being asked for, so nothing to change — except that it may be off the desk. */
|
|
209
|
+
const restoreIfMinimized = (id: WindowId) => {
|
|
210
|
+
if (isMinimized(state, id)) commit(toFront(state, id))
|
|
211
|
+
}
|
|
212
|
+
|
|
168
213
|
// Plain functions rather than methods, so `const { open } = desk` works.
|
|
169
214
|
const float = (id: WindowId, frame?: Frame) => {
|
|
170
215
|
const window = find(id)
|
|
171
216
|
if (!window) return
|
|
172
|
-
if (window.mode === 'floating' && !frame) return
|
|
217
|
+
if (window.mode === 'floating' && !frame) return restoreIfMinimized(id)
|
|
173
218
|
const next = frame ?? fits(remembered.get(id)) ?? nextFrame(state)
|
|
174
219
|
if (frame) {
|
|
175
220
|
remembered.set(id, frame)
|
|
@@ -182,7 +227,8 @@ export function createDesk(options: DeskOptions = {}): Desk {
|
|
|
182
227
|
|
|
183
228
|
const fill = (id: WindowId) => {
|
|
184
229
|
const window = find(id)
|
|
185
|
-
if (!window
|
|
230
|
+
if (!window) return
|
|
231
|
+
if (window.mode === 'filled') return restoreIfMinimized(id)
|
|
186
232
|
remembered.set(id, window.frame)
|
|
187
233
|
layouts?.save(windowType(id), { mode: 'filled' })
|
|
188
234
|
commit(toFront(replace(state, { id, mode: 'filled' }), id))
|
|
@@ -228,7 +274,15 @@ export function createDesk(options: DeskOptions = {}): Desk {
|
|
|
228
274
|
},
|
|
229
275
|
|
|
230
276
|
close(id) {
|
|
231
|
-
if (find(id))
|
|
277
|
+
if (!find(id)) return
|
|
278
|
+
const closed: DeskState = { windows: state.windows.filter(w => w.id !== id), stack: state.stack.filter(x => x !== id) }
|
|
279
|
+
commit(withMinimized(closed, state.minimized?.filter(x => x !== id) ?? []))
|
|
280
|
+
},
|
|
281
|
+
|
|
282
|
+
minimize(id) {
|
|
283
|
+
if (!find(id) || isMinimized(state, id)) return
|
|
284
|
+
// The stack is left alone: a window comes back to where it was, not to the front of everything.
|
|
285
|
+
commit(withMinimized(state, [...(state.minimized ?? []), id]))
|
|
232
286
|
},
|
|
233
287
|
|
|
234
288
|
closeAll() {
|
package/src/core/index.ts
CHANGED
|
@@ -4,8 +4,10 @@ export {
|
|
|
4
4
|
cascadeSlot,
|
|
5
5
|
focusedId,
|
|
6
6
|
instancesOf,
|
|
7
|
+
isMinimized,
|
|
7
8
|
isOpen,
|
|
8
9
|
nextCascadeFrame,
|
|
10
|
+
onDesk,
|
|
9
11
|
normalise,
|
|
10
12
|
windowType,
|
|
11
13
|
EMPTY,
|
|
@@ -41,5 +43,6 @@ export type {
|
|
|
41
43
|
OpenOptions,
|
|
42
44
|
Size,
|
|
43
45
|
WindowId,
|
|
46
|
+
WindowLimits,
|
|
44
47
|
WindowMode,
|
|
45
48
|
} from './types.js'
|
package/src/core/location.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cascadeFrame, focusedId, normalise } from './desk.js'
|
|
1
|
+
import { cascadeFrame, focusedId, isMinimized, normalise } from './desk.js'
|
|
2
2
|
import type { Desk } from './desk.js'
|
|
3
3
|
import type { DeskState, DeskWindow, Size, WindowId } from './types.js'
|
|
4
4
|
|
|
@@ -7,12 +7,15 @@ import type { DeskState, DeskWindow, Size, WindowId } from './types.js'
|
|
|
7
7
|
* never frames. A shared link should open the same things, not reproduce
|
|
8
8
|
* someone else's window positions on a different screen.
|
|
9
9
|
*
|
|
10
|
-
* #w=notes,clock~,
|
|
10
|
+
* #w=notes,clock~,inspector_&f=clock
|
|
11
11
|
*
|
|
12
|
-
* `~` marks a free window; the others fill the desk. `
|
|
12
|
+
* `~` marks a free window; the others fill the desk. `_` marks one that is minimized — open and
|
|
13
|
+
* off the desk — which is not a position but which windows are open and how, so it travels.
|
|
14
|
+
* `f` names the focused window.
|
|
13
15
|
*/
|
|
14
16
|
|
|
15
17
|
const FLOAT = '~'
|
|
18
|
+
const MINIMIZED = '_'
|
|
16
19
|
|
|
17
20
|
const warned = new Set<string>()
|
|
18
21
|
/** Said once per message: a warning on every parse would be noise, not help. */
|
|
@@ -36,7 +39,9 @@ export function serialize(state: DeskState, options: LocationOptions = {}): URLS
|
|
|
36
39
|
if (!state.windows.length) return params
|
|
37
40
|
params.set(
|
|
38
41
|
options.key ?? 'w',
|
|
39
|
-
state.windows
|
|
42
|
+
state.windows
|
|
43
|
+
.map(w => `${encodeURIComponent(w.id)}${w.mode === 'floating' ? FLOAT : ''}${isMinimized(state, w.id) ? MINIMIZED : ''}`)
|
|
44
|
+
.join(','),
|
|
40
45
|
)
|
|
41
46
|
const focused = focusedId(state)
|
|
42
47
|
if (focused) params.set(options.focusKey ?? 'f', focused)
|
|
@@ -58,8 +63,10 @@ export function parse(params: URLSearchParams, stage: Size, options: LocationOpt
|
|
|
58
63
|
.split(',')
|
|
59
64
|
.filter(Boolean)
|
|
60
65
|
.map(token => {
|
|
61
|
-
const
|
|
62
|
-
|
|
66
|
+
const minimized = token.endsWith(MINIMIZED)
|
|
67
|
+
const rest = minimized ? token.slice(0, -1) : token
|
|
68
|
+
const floating = rest.endsWith(FLOAT)
|
|
69
|
+
return { id: decodeURIComponent(floating ? rest.slice(0, -1) : rest), floating, minimized }
|
|
63
70
|
})
|
|
64
71
|
.filter(e => e.id && known(e.id))
|
|
65
72
|
|
|
@@ -72,7 +79,8 @@ export function parse(params: URLSearchParams, stage: Size, options: LocationOpt
|
|
|
72
79
|
const focus = params.get(options.focusKey ?? 'f')
|
|
73
80
|
const ids = windows.map(w => w.id)
|
|
74
81
|
const stack = focus && ids.includes(focus) ? [...ids.filter(id => id !== focus), focus] : ids
|
|
75
|
-
|
|
82
|
+
const minimized = entries.filter(e => e.minimized).map(e => e.id)
|
|
83
|
+
return normalise(minimized.length ? { windows, stack, minimized } : { windows, stack })
|
|
76
84
|
}
|
|
77
85
|
|
|
78
86
|
export interface LocationEnv {
|