@liberation-data/desk 0.42.0 → 0.44.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 +312 -5
- package/dist/core/hosted.d.ts +222 -0
- package/dist/core/hosted.d.ts.map +1 -0
- package/dist/core/hosted.js +166 -0
- package/dist/core/hosted.js.map +1 -0
- package/dist/core/index.d.ts +10 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +5 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/location.d.ts +8 -1
- package/dist/core/location.d.ts.map +1 -1
- package/dist/core/location.js +18 -2
- package/dist/core/location.js.map +1 -1
- package/dist/core/preferences.d.ts +27 -0
- package/dist/core/preferences.d.ts.map +1 -0
- package/dist/core/preferences.js +121 -0
- package/dist/core/preferences.js.map +1 -0
- package/dist/core/scheme.d.ts +18 -0
- package/dist/core/scheme.d.ts.map +1 -0
- package/dist/core/scheme.js +24 -0
- package/dist/core/scheme.js.map +1 -0
- package/dist/core/theme.d.ts +41 -0
- package/dist/core/theme.d.ts.map +1 -0
- package/dist/core/theme.js +56 -0
- package/dist/core/theme.js.map +1 -0
- package/dist/core/themeChange.d.ts +25 -0
- package/dist/core/themeChange.d.ts.map +1 -0
- package/dist/core/themeChange.js +49 -0
- package/dist/core/themeChange.js.map +1 -0
- package/dist/core/types.d.ts +6 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/css/apps.css +183 -0
- package/dist/css/overlays.css +6 -0
- package/dist/css/shell.css +100 -0
- package/dist/css/tokens.css +10 -0
- package/dist/css/windows.css +21 -0
- package/dist/desk.css +220 -0
- package/dist/fx/fx.d.ts.map +1 -1
- package/dist/fx/fx.js +7 -31
- package/dist/fx/fx.js.map +1 -1
- package/dist/host/checkChrome.d.ts +20 -0
- package/dist/host/checkChrome.d.ts.map +1 -0
- package/dist/host/checkChrome.js +219 -0
- package/dist/host/checkChrome.js.map +1 -0
- package/dist/host/checkTheme.d.ts +35 -0
- package/dist/host/checkTheme.d.ts.map +1 -0
- package/dist/host/checkTheme.js +128 -0
- package/dist/host/checkTheme.js.map +1 -0
- package/dist/host/index.d.ts +7 -0
- package/dist/host/index.d.ts.map +1 -0
- package/dist/host/index.js +8 -0
- package/dist/host/index.js.map +1 -0
- package/dist/host/router.d.ts +99 -0
- package/dist/host/router.d.ts.map +1 -0
- package/dist/host/router.js +279 -0
- package/dist/host/router.js.map +1 -0
- package/dist/react/Desktop.d.ts.map +1 -1
- package/dist/react/Desktop.js +13 -2
- package/dist/react/Desktop.js.map +1 -1
- package/dist/react/Dock.d.ts +26 -2
- package/dist/react/Dock.d.ts.map +1 -1
- package/dist/react/Dock.js +23 -27
- package/dist/react/Dock.js.map +1 -1
- package/dist/react/MenuBar.d.ts +1 -1
- package/dist/react/MenuBar.d.ts.map +1 -1
- package/dist/react/MenuBar.js +36 -6
- package/dist/react/MenuBar.js.map +1 -1
- package/dist/react/app.d.ts +215 -0
- package/dist/react/app.d.ts.map +1 -0
- package/dist/react/app.js +192 -0
- package/dist/react/app.js.map +1 -0
- package/dist/react/appFrame.d.ts +11 -7
- package/dist/react/appFrame.d.ts.map +1 -1
- package/dist/react/appFrame.js +24 -6
- package/dist/react/appFrame.js.map +1 -1
- package/dist/react/appPanels.d.ts +25 -0
- package/dist/react/appPanels.d.ts.map +1 -0
- package/dist/react/appPanels.js +123 -0
- package/dist/react/appPanels.js.map +1 -0
- package/dist/react/appearance.d.ts +61 -0
- package/dist/react/appearance.d.ts.map +1 -0
- package/dist/react/appearance.js +119 -0
- package/dist/react/appearance.js.map +1 -0
- package/dist/react/codeBlock.d.ts.map +1 -1
- package/dist/react/codeBlock.js +6 -60
- package/dist/react/codeBlock.js.map +1 -1
- package/dist/react/context.d.ts +23 -1
- package/dist/react/context.d.ts.map +1 -1
- package/dist/react/context.js +108 -5
- package/dist/react/context.js.map +1 -1
- package/dist/react/copy.d.ts +22 -0
- package/dist/react/copy.d.ts.map +1 -0
- package/dist/react/copy.js +68 -0
- package/dist/react/copy.js.map +1 -0
- package/dist/react/dockStatus.d.ts +19 -0
- package/dist/react/dockStatus.d.ts.map +1 -0
- package/dist/react/dockStatus.js +25 -0
- package/dist/react/dockStatus.js.map +1 -0
- package/dist/react/documentTitle.d.ts.map +1 -1
- package/dist/react/documentTitle.js +4 -1
- package/dist/react/documentTitle.js.map +1 -1
- package/dist/react/frameMenus.d.ts +28 -0
- package/dist/react/frameMenus.d.ts.map +1 -0
- package/dist/react/frameMenus.js +85 -0
- package/dist/react/frameMenus.js.map +1 -0
- package/dist/react/hostApp.d.ts +15 -0
- package/dist/react/hostApp.d.ts.map +1 -0
- package/dist/react/hostApp.js +77 -0
- package/dist/react/hostApp.js.map +1 -0
- package/dist/react/hostDock.d.ts +25 -0
- package/dist/react/hostDock.d.ts.map +1 -0
- package/dist/react/hostDock.js +98 -0
- package/dist/react/hostDock.js.map +1 -0
- package/dist/react/hostMenu.d.ts +2 -36
- package/dist/react/hostMenu.d.ts.map +1 -1
- package/dist/react/hostMenu.js.map +1 -1
- package/dist/react/hosted.d.ts +28 -0
- package/dist/react/hosted.d.ts.map +1 -0
- package/dist/react/hosted.js +53 -0
- package/dist/react/hosted.js.map +1 -0
- package/dist/react/index.d.ts +12 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +8 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/layers.d.ts.map +1 -1
- package/dist/react/layers.js +7 -2
- package/dist/react/layers.js.map +1 -1
- package/dist/react/overlays.d.ts.map +1 -1
- package/dist/react/overlays.js +29 -12
- package/dist/react/overlays.js.map +1 -1
- package/dist/react/shell.d.ts +16 -1
- package/dist/react/shell.d.ts.map +1 -1
- package/dist/react/shell.js +19 -3
- package/dist/react/shell.js.map +1 -1
- package/dist/react/windowMenus.d.ts +19 -0
- package/dist/react/windowMenus.d.ts.map +1 -0
- package/dist/react/windowMenus.js +88 -0
- package/dist/react/windowMenus.js.map +1 -0
- package/dist/shell/HostShell.d.ts +53 -0
- package/dist/shell/HostShell.d.ts.map +1 -0
- package/dist/shell/HostShell.js +116 -0
- package/dist/shell/HostShell.js.map +1 -0
- package/dist/shell/index.d.ts +7 -0
- package/dist/shell/index.d.ts.map +1 -0
- package/dist/shell/index.js +9 -0
- package/dist/shell/index.js.map +1 -0
- package/dist/shell/keys.d.ts +47 -0
- package/dist/shell/keys.d.ts.map +1 -0
- package/dist/shell/keys.js +68 -0
- package/dist/shell/keys.js.map +1 -0
- package/dist/shell/motion.d.ts +72 -0
- package/dist/shell/motion.d.ts.map +1 -0
- package/dist/shell/motion.js +118 -0
- package/dist/shell/motion.js.map +1 -0
- package/llms.txt +84 -9
- package/package.json +10 -1
- package/src/core/hosted.ts +351 -0
- package/src/core/index.ts +29 -0
- package/src/core/location.ts +23 -3
- package/src/core/preferences.ts +132 -0
- package/src/core/scheme.ts +32 -0
- package/src/core/theme.ts +91 -0
- package/src/core/themeChange.ts +59 -0
- package/src/core/types.ts +6 -0
- package/src/css/apps.css +183 -0
- package/src/css/overlays.css +6 -0
- package/src/css/shell.css +99 -0
- package/src/css/tokens.css +10 -0
- package/src/css/windows.css +21 -0
- package/src/fx/fx.ts +7 -25
- package/src/host/checkChrome.ts +257 -0
- package/src/host/checkTheme.ts +134 -0
- package/src/host/index.ts +10 -0
- package/src/host/router.ts +374 -0
- package/src/react/Desktop.tsx +21 -3
- package/src/react/Dock.tsx +40 -24
- package/src/react/MenuBar.tsx +39 -6
- package/src/react/app.tsx +354 -0
- package/src/react/appFrame.tsx +39 -14
- package/src/react/appPanels.tsx +210 -0
- package/src/react/appearance.tsx +195 -0
- package/src/react/codeBlock.tsx +7 -65
- package/src/react/context.tsx +131 -4
- package/src/react/copy.ts +81 -0
- package/src/react/dockStatus.ts +42 -0
- package/src/react/documentTitle.ts +4 -1
- package/src/react/frameMenus.ts +100 -0
- package/src/react/hostApp.tsx +89 -0
- package/src/react/hostDock.tsx +118 -0
- package/src/react/hostMenu.ts +3 -38
- package/src/react/hosted.tsx +65 -0
- package/src/react/index.ts +34 -0
- package/src/react/layers.ts +7 -2
- package/src/react/overlays.tsx +30 -12
- package/src/react/shell.tsx +33 -3
- package/src/react/windowMenus.ts +107 -0
- package/src/shell/HostShell.tsx +220 -0
- package/src/shell/index.ts +11 -0
- package/src/shell/keys.ts +101 -0
- package/src/shell/motion.ts +163 -0
package/dist/react/context.js
CHANGED
|
@@ -1,29 +1,132 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useState, useSyncExternalStore } from 'react';
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
3
|
+
import { addCommandHandler } from '../core/commands.js';
|
|
3
4
|
import { createBus } from '../core/events.js';
|
|
4
5
|
import { createDesk, routeOf } from '../core/desk.js';
|
|
6
|
+
import { connectHost, findDeskHost, THEME_TOPIC } from '../core/hosted.js';
|
|
7
|
+
import { applyTheme, applyThemeBasics } from '../core/theme.js';
|
|
5
8
|
import { deviceLook, resolveLook } from '../core/look.js';
|
|
9
|
+
import { watchThemeChanges } from '../core/themeChange.js';
|
|
10
|
+
import { deskDrawsWindows } from '../core/location.js';
|
|
6
11
|
import { holdAll } from '../core/services.js';
|
|
12
|
+
import { AppProvider, bindDeskShortcuts, declareOn, desksWindow, hasSettings, openAppSettings, SettingsCommand } from './app.js';
|
|
13
|
+
import { AppearanceSettings, hasRows, hostThemed, rowsOf, showColorScheme, shownRows, useChosenColorScheme, useDefaultColorScheme, useLookChoice, useThemeFromHost } from './appearance.js';
|
|
7
14
|
import { DragProvider } from './dragContext.js';
|
|
15
|
+
import { HostedApp } from './hostApp.js';
|
|
16
|
+
import { HostContext } from './hosted.js';
|
|
8
17
|
import { missingProvider } from './missingProvider.js';
|
|
9
18
|
const DeskContext = createContext(null);
|
|
10
19
|
const LookContext = createContext(null);
|
|
11
20
|
/** Every desk comes with a bus; <BusProvider> only matters when one has to be shared or supplied. */
|
|
12
21
|
export const BusContext = createContext(null);
|
|
13
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Connects to the host while mounted, and wears the theme it passes on unless `wears` is false: the
|
|
24
|
+
* primary, whose theme it is, keeps its own. Null client until connected.
|
|
25
|
+
*/
|
|
26
|
+
function useHostConnection(bridge, wears, onTheme) {
|
|
27
|
+
const [client, setClient] = useState(null);
|
|
28
|
+
const [theme, setTheme] = useState(null);
|
|
29
|
+
const wear = useRef(onTheme);
|
|
30
|
+
wear.current = onTheme;
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (!bridge)
|
|
33
|
+
return;
|
|
34
|
+
const connected = connectHost(bridge);
|
|
35
|
+
const stop = !wears ? () => { } : connected.subscribe('primary', THEME_TOPIC, ({ payload }) => {
|
|
36
|
+
;
|
|
37
|
+
(wear.current ?? applyTheme)(payload);
|
|
38
|
+
// After the app's own handler, so light or dark and the look hold whatever it did.
|
|
39
|
+
applyThemeBasics(payload);
|
|
40
|
+
setTheme(payload);
|
|
41
|
+
});
|
|
42
|
+
setClient(connected);
|
|
43
|
+
return () => {
|
|
44
|
+
stop();
|
|
45
|
+
connected.close();
|
|
46
|
+
setClient(null);
|
|
47
|
+
setTheme(null);
|
|
48
|
+
};
|
|
49
|
+
}, [bridge, wears]);
|
|
50
|
+
return { client, theme };
|
|
51
|
+
}
|
|
52
|
+
export function DeskProvider({ desk, options, look: appLook = 'auto', services, app: declared, host, onTheme, children }) {
|
|
14
53
|
const [value] = useState(() => desk ?? createDesk(options));
|
|
15
54
|
const [bus] = useState(createBus);
|
|
16
55
|
const [held] = useState(() => services ?? []);
|
|
17
56
|
useEffect(() => holdAll(held), [held]);
|
|
18
|
-
const
|
|
57
|
+
const [bridge] = useState(() => (host === undefined ? findDeskHost() : host));
|
|
58
|
+
// The primary declares `themeFromHost: false`: the theme is its own, so it keeps its Appearance.
|
|
59
|
+
const hosted = useHostConnection(bridge, declared?.themeFromHost !== false, onTheme);
|
|
60
|
+
const hosting = useMemo(() => (bridge ? { client: hosted.client } : null), [bridge, hosted.client]);
|
|
61
|
+
// Appearance: the rows the app asked for, less the theme's when a host chooses it. A hosted app's
|
|
62
|
+
// host always does, so it offers no scheme, look or theme of its own.
|
|
63
|
+
const fromHost = useThemeFromHost(declared?.themeFromHost ?? (bridge ? true : undefined));
|
|
64
|
+
const rows = shownRows(rowsOf(declared?.settings?.appearance), fromHost);
|
|
65
|
+
const app = useMemo(() => withAppearance(declared, rows, appLook), [declared, rows.scheme, rows.defaultScheme, rows.look, rows.sounds, rows.theme, rows.soundsDescription, appLook]);
|
|
66
|
+
const chosenLook = useLookChoice();
|
|
67
|
+
const defaultScheme = useDefaultColorScheme(Boolean(rows.scheme), rows.defaultScheme);
|
|
68
|
+
const scheme = useChosenColorScheme() ?? defaultScheme;
|
|
69
|
+
const look = (rows.look && chosenLook) || appLook;
|
|
70
|
+
// A hosted app wears the look of the theme it was sent, once there is one.
|
|
71
|
+
const resolved = hosted.theme?.look ?? resolveLook(look);
|
|
72
|
+
useLayoutEffect(() => {
|
|
73
|
+
if (!rows.scheme)
|
|
74
|
+
return;
|
|
75
|
+
showColorScheme(scheme);
|
|
76
|
+
// Hiding because a host's theme arrived: the attribute is the host's now, so it stays.
|
|
77
|
+
return () => {
|
|
78
|
+
if (!hostThemed())
|
|
79
|
+
showColorScheme('system');
|
|
80
|
+
};
|
|
81
|
+
}, [rows.scheme, scheme]);
|
|
19
82
|
// On the root, not the desk: menus and popovers are portalled out of it, and are chrome too.
|
|
20
83
|
useLayoutEffect(() => {
|
|
84
|
+
watchThemeChanges();
|
|
21
85
|
document.documentElement.dataset.look = resolved;
|
|
22
86
|
return () => {
|
|
23
87
|
delete document.documentElement.dataset.look;
|
|
24
88
|
};
|
|
25
89
|
}, [resolved]);
|
|
26
|
-
|
|
90
|
+
// "Settings…" and ⌘, perform this; it answers at the top of the chain, so a window can still take it.
|
|
91
|
+
const latestApp = useRef(app ?? null);
|
|
92
|
+
latestApp.current = app ?? null;
|
|
93
|
+
// Outside React, openSettings(desk) and syncWithLocation read the declaration from the desk. Said as the
|
|
94
|
+
// provider renders, so a link read in the app's first effect already knows Settings and About, and again
|
|
95
|
+
// in an effect, which a remount in development runs after the cleanup that forgot it.
|
|
96
|
+
const [declaration] = useState(() => ({ app: () => latestApp.current, draws: (id) => desksWindow(latestApp.current, id) !== null }));
|
|
97
|
+
declareOn(value, declaration.app);
|
|
98
|
+
deskDrawsWindows(value, declaration.draws);
|
|
99
|
+
useLayoutEffect(() => {
|
|
100
|
+
const forgetApp = declareOn(value, declaration.app);
|
|
101
|
+
const forgetWindows = deskDrawsWindows(value, declaration.draws);
|
|
102
|
+
return () => {
|
|
103
|
+
forgetApp();
|
|
104
|
+
forgetWindows();
|
|
105
|
+
};
|
|
106
|
+
}, [value, declaration]);
|
|
107
|
+
const hasApp = app !== undefined;
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (!hasApp)
|
|
110
|
+
return;
|
|
111
|
+
const remove = addCommandHandler(document, SettingsCommand, (route) => openAppSettings(value, latestApp.current, typeof route === 'string' ? route : undefined), {
|
|
112
|
+
enabled: () => hasSettings(latestApp.current),
|
|
113
|
+
});
|
|
114
|
+
// ⌘, here, not only in the menu bar's keymap, so it works in an app that has none. Not when hosted:
|
|
115
|
+
// the host's frame owns it, menu bar or not, connected yet or not.
|
|
116
|
+
const unbind = bridge ? () => { } : bindDeskShortcuts(value);
|
|
117
|
+
return () => {
|
|
118
|
+
remove();
|
|
119
|
+
unbind();
|
|
120
|
+
};
|
|
121
|
+
}, [value, hasApp, bridge]);
|
|
122
|
+
return (_jsx(DeskContext.Provider, { value: value, children: _jsx(BusContext.Provider, { value: bus, children: _jsx(LookContext.Provider, { value: resolved, children: _jsx(AppProvider, { value: app ?? null, children: _jsxs(HostContext.Provider, { value: hosting, children: [bridge && _jsx(HostedApp, {}), _jsx(DragProvider, { children: children })] }) }) }) }) }));
|
|
123
|
+
}
|
|
124
|
+
/** The app's declaration with Desk's Appearance as its first section, when it has rows to show. */
|
|
125
|
+
function withAppearance(app, rows, look) {
|
|
126
|
+
if (!app?.settings || !hasRows(rows))
|
|
127
|
+
return app;
|
|
128
|
+
const appearance = { id: 'appearance', title: 'Appearance', content: _jsx(AppearanceSettings, { rows: rows, look: look }) };
|
|
129
|
+
return { ...app, settings: { ...app.settings, sections: [appearance, ...(app.settings.sections ?? [])] } };
|
|
27
130
|
}
|
|
28
131
|
/** The look the desk is wearing, for an app that draws chrome of its own. Outside a desk, the device's. */
|
|
29
132
|
export const useLook = () => useContext(LookContext) ?? deviceLook();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/react/context.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/react/context.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAE3I,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE7C,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE1E,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAE/D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACz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EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAA;IAC1G,MAAM,KAAK,GAAG,oBAAoB,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IACzD,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAA;IACzH,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAU,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
/** Where a copy has got to: nothing yet, done, or the text selected for the person to copy. */
|
|
3
|
+
export type Copying = 'idle' | 'copied' | 'select';
|
|
4
|
+
/** What `useCopy` gives a view: where the copy has got to, the action, and what to say about it. */
|
|
5
|
+
export interface CopyState {
|
|
6
|
+
readonly copying: Copying;
|
|
7
|
+
readonly copy: () => Promise<void>;
|
|
8
|
+
/** What the button says: Copy, Copied, or which keys copy the selection. */
|
|
9
|
+
readonly button: string;
|
|
10
|
+
/** What a polite status region says, so the result is heard as well as seen. */
|
|
11
|
+
readonly status: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Copying a block of text with a button, as `CodeBlock` and the About panel do.
|
|
15
|
+
*
|
|
16
|
+
* THE CLIPBOARD IS NOT ALWAYS THERE: a page over plain http has none, and a browser may refuse it.
|
|
17
|
+
* Then `select`'s element is selected and the older copy command tried; where that fails too, the
|
|
18
|
+
* selection stays and the button says which keys copy it, so the person is one keystroke away.
|
|
19
|
+
* New text has been neither copied nor selected, so the state goes back to idle when `text` changes.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useCopy(text: string, select: RefObject<HTMLElement | null>): CopyState;
|
|
22
|
+
//# sourceMappingURL=copy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy.d.ts","sourceRoot":"","sources":["../../src/react/copy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAMtC,+FAA+F;AAC/F,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAElD,oGAAoG;AACpG,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAClC,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,gFAAgF;IAChF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,SAAS,CAoDtF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { formatShortcut } from '../core/shortcuts.js';
|
|
3
|
+
/** How long "Copied" stays before the button says Copy again. */
|
|
4
|
+
const COPIED_MS = 2000;
|
|
5
|
+
/**
|
|
6
|
+
* Copying a block of text with a button, as `CodeBlock` and the About panel do.
|
|
7
|
+
*
|
|
8
|
+
* THE CLIPBOARD IS NOT ALWAYS THERE: a page over plain http has none, and a browser may refuse it.
|
|
9
|
+
* Then `select`'s element is selected and the older copy command tried; where that fails too, the
|
|
10
|
+
* selection stays and the button says which keys copy it, so the person is one keystroke away.
|
|
11
|
+
* New text has been neither copied nor selected, so the state goes back to idle when `text` changes.
|
|
12
|
+
*/
|
|
13
|
+
export function useCopy(text, select) {
|
|
14
|
+
const [copying, setCopying] = useState('idle');
|
|
15
|
+
const timer = useRef(undefined);
|
|
16
|
+
const alive = useRef(true);
|
|
17
|
+
const copied = useRef(text);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
alive.current = true;
|
|
20
|
+
return () => {
|
|
21
|
+
alive.current = false;
|
|
22
|
+
clearTimeout(timer.current);
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
25
|
+
// Put back while rendering, so not one frame says Copied over text nobody copied.
|
|
26
|
+
if (copied.current !== text) {
|
|
27
|
+
copied.current = text;
|
|
28
|
+
clearTimeout(timer.current);
|
|
29
|
+
if (copying !== 'idle')
|
|
30
|
+
setCopying('idle');
|
|
31
|
+
}
|
|
32
|
+
const settle = (next) => {
|
|
33
|
+
// A copy that finishes after the view has gone has nothing left to say it in.
|
|
34
|
+
if (!alive.current)
|
|
35
|
+
return;
|
|
36
|
+
clearTimeout(timer.current);
|
|
37
|
+
setCopying(next);
|
|
38
|
+
if (next === 'copied')
|
|
39
|
+
timer.current = setTimeout(() => setCopying('idle'), COPIED_MS);
|
|
40
|
+
};
|
|
41
|
+
const copy = async () => {
|
|
42
|
+
try {
|
|
43
|
+
await navigator.clipboard.writeText(text);
|
|
44
|
+
settle('copied');
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
const selection = window.getSelection();
|
|
48
|
+
if (select.current && selection)
|
|
49
|
+
selection.selectAllChildren(select.current);
|
|
50
|
+
let done = false;
|
|
51
|
+
try {
|
|
52
|
+
done = document.execCommand('copy');
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// Unsupported: the selection is the way.
|
|
56
|
+
}
|
|
57
|
+
settle(done ? 'copied' : 'select');
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const keys = formatShortcut('mod+c');
|
|
61
|
+
return {
|
|
62
|
+
copying,
|
|
63
|
+
copy,
|
|
64
|
+
button: copying === 'copied' ? 'Copied' : copying === 'select' ? `Press ${keys}` : 'Copy',
|
|
65
|
+
status: copying === 'copied' ? 'Copied' : copying === 'select' ? `Selected. Press ${keys} to copy.` : '',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=copy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy.js","sourceRoot":"","sources":["../../src/react/copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD,iEAAiE;AACjE,MAAM,SAAS,GAAG,IAAI,CAAA;AAetB;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAC,IAAY,EAAE,MAAqC;IACzE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAU,MAAM,CAAC,CAAA;IACvD,MAAM,KAAK,GAAG,MAAM,CAAgC,SAAS,CAAC,CAAA;IAC9D,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IAC1B,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IAE3B,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,CAAC,OAAO,GAAG,IAAI,CAAA;QACpB,OAAO,GAAG,EAAE;YACV,KAAK,CAAC,OAAO,GAAG,KAAK,CAAA;YACrB,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QAC7B,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IACN,kFAAkF;IAClF,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QAC5B,MAAM,CAAC,OAAO,GAAG,IAAI,CAAA;QACrB,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QA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C,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM;QACzF,MAAM,EAAE,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,mBAAmB,IAAI,WAAW,CAAC,CAAC,CAAC,EAAE;KACzG,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DeskState, WindowId } from '../core/types.js';
|
|
2
|
+
/** What a dock item needs to say whether its windows are open: the item's window kind, and its id. */
|
|
3
|
+
export interface DockTarget {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly window?: WindowId;
|
|
6
|
+
/** Whether its windows are open, said by someone else: an app a host runs reports its own. */
|
|
7
|
+
readonly status?: DockStatus;
|
|
8
|
+
}
|
|
9
|
+
/** Whether a dock item's windows are open, have focus, or are all minimized. */
|
|
10
|
+
export interface DockStatus {
|
|
11
|
+
readonly running: boolean;
|
|
12
|
+
readonly focused: boolean;
|
|
13
|
+
readonly minimized: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** The window a dock item opens and reports as running: its `window`, or its id. */
|
|
16
|
+
export declare const windowOf: (item: DockTarget) => WindowId;
|
|
17
|
+
/** Whether any of these items' windows are open, have focus, or are all minimized. */
|
|
18
|
+
export declare const statusOf: (state: DeskState, items: readonly DockTarget[]) => DockStatus;
|
|
19
|
+
//# sourceMappingURL=dockStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dockStatus.d.ts","sourceRoot":"","sources":["../../src/react/dockStatus.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3D,sGAAsG;AACtG,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAA;IAC1B,8FAA8F;IAC9F,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,CAAA;CAC7B;AAED,gFAAgF;AAChF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAC5B;AAED,oFAAoF;AACpF,eAAO,MAAM,QAAQ,SAAU,UAAU,KAAG,QAAkC,CAAA;AAE9E,sFAAsF;AACtF,eAAO,MAAM,QAAQ,UAAW,SAAS,SAAS,SAAS,UAAU,EAAE,KAAG,UAmBzE,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { focusedId, instancesOf, isMinimized, windowType } from '../core/desk.js';
|
|
2
|
+
/** The window a dock item opens and reports as running: its `window`, or its id. */
|
|
3
|
+
export const windowOf = (item) => item.window ?? item.id;
|
|
4
|
+
/** Whether any of these items' windows are open, have focus, or are all minimized. */
|
|
5
|
+
export const statusOf = (state, items) => {
|
|
6
|
+
const told = items.flatMap(i => (i.status ? [i.status] : []));
|
|
7
|
+
// Items whose status is reported (a hosted app's, drawn by its host) say it themselves.
|
|
8
|
+
if (told.length) {
|
|
9
|
+
return {
|
|
10
|
+
running: told.some(s => s.running),
|
|
11
|
+
focused: told.some(s => s.focused),
|
|
12
|
+
minimized: told.some(s => s.running) && told.every(s => !s.running || s.minimized),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const key = focusedId(state);
|
|
16
|
+
const windows = items.flatMap(i => instancesOf(state, windowOf(i)));
|
|
17
|
+
return {
|
|
18
|
+
// Any window of this kind counts: a second query window is still Query, running.
|
|
19
|
+
running: windows.length > 0,
|
|
20
|
+
focused: items.some(i => key !== null && windowType(key) === windowOf(i)),
|
|
21
|
+
// Open, and none of it on the desk. One window of a kind still showing means the item is not.
|
|
22
|
+
minimized: windows.length > 0 && windows.every(w => isMinimized(state, w.id)),
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=dockStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dockStatus.js","sourceRoot":"","sources":["../../src/react/dockStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAkBjF,oFAAoF;AACpF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAgB,EAAY,EAAE,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,EAAE,CAAA;AAE9E,sFAAsF;AACtF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAgB,EAAE,KAA4B,EAAc,EAAE;IACrF,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC7D,wFAAwF;IACxF,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;YAClC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;YAClC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,SAAS,CAAC;SACnF,CAAA;IACH,CAAC;IACD,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;IAC5B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACnE,OAAO;QACL,iFAAiF;QACjF,OAAO,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC;QAC3B,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC;QACzE,8FAA8F;QAC9F,SAAS,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;KAC9E,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"documentTitle.d.ts","sourceRoot":"","sources":["../../src/react/documentTitle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAmBhD,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,CAuB1G"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { focusedId } from '../core/desk.js';
|
|
3
|
+
import { appWindowTitle, useDeskApp } from './app.js';
|
|
3
4
|
import { useDeskState } from './context.js';
|
|
4
5
|
const DEFAULT_SEPARATOR = ' — ';
|
|
5
6
|
/** Keeps `document.title` on the frontmost window: `Rides — Garage`, and `Garage` with nothing open. */
|
|
@@ -7,11 +8,13 @@ export function useDocumentTitle(title, options = {}) {
|
|
|
7
8
|
const { app, separator = DEFAULT_SEPARATOR } = options;
|
|
8
9
|
const state = useDeskState();
|
|
9
10
|
const id = focusedId(state);
|
|
11
|
+
// Desk names its own About and Settings, so the app's title function need not.
|
|
12
|
+
const declared = useDeskApp();
|
|
10
13
|
// What the page was called before the desk took it over: the app's name by default, and what
|
|
11
14
|
// is put back on the way out. Read once, so a title this hook set is never mistaken for it.
|
|
12
15
|
const [original] = useState(() => (typeof document === 'undefined' ? '' : document.title));
|
|
13
16
|
const base = app ?? original;
|
|
14
|
-
const front = id === null ? '' : title(id);
|
|
17
|
+
const front = id === null ? '' : (appWindowTitle(declared, id) ?? title(id));
|
|
15
18
|
const next = front && base ? `${front}${separator}${base}` : front || base;
|
|
16
19
|
useEffect(() => {
|
|
17
20
|
if (next)
|
|
@@ -1 +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,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAwB3C,MAAM,iBAAiB,GAAG,KAAK,CAAA;AAE/B,wGAAwG;AACxG,MAAM,UAAU,gBAAgB,CAAC,KAA+B,EAAE,OAAO,GAAyB,EAAE;IAClG,MAAM,EAAE,GAAG,EAAE,SAAS,GAAG,iBAAiB,EAAE,GAAG,OAAO,CAAA;IACtD,MAAM,KAAK,GAAG,YAAY,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,GAAG,SAAS,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAA;IAE1E,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,IAAI;YAAE,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAA;IACjC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;IAEV,6FAA6F;IAC7F,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE;QACnB,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAA;IAC3B,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CommandId } from '../core/commands.js';
|
|
2
|
+
import type { Desk } from '../core/desk.js';
|
|
3
|
+
import type { WindowId } from '../core/types.js';
|
|
4
|
+
import type { Menu } from './MenuBar.js';
|
|
5
|
+
/** One item the frame turned into a command, and the app's own id for it. */
|
|
6
|
+
export interface FrameItem {
|
|
7
|
+
readonly command: CommandId;
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly enabled: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* An app's menus as the page's own, after `checkChrome`, its commands named `prefix`:menu index:row index, and what
|
|
13
|
+
* each stands for. Items without an id or label are left out, and menus past the first few. Null when
|
|
14
|
+
* there is nothing.
|
|
15
|
+
*/
|
|
16
|
+
export declare function frameMenus(raw: unknown, prefix: string): {
|
|
17
|
+
readonly menus: Menu[];
|
|
18
|
+
readonly items: FrameItem[];
|
|
19
|
+
} | null;
|
|
20
|
+
/**
|
|
21
|
+
* While the frame has menus and its window is in front, they join the bar, and choosing an item, or
|
|
22
|
+
* pressing its shortcut, calls `choose` with the app's own id for it.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useFrameMenus(desk: Desk, window: WindowId | null, menus: {
|
|
25
|
+
readonly menus: Menu[];
|
|
26
|
+
readonly items: FrameItem[];
|
|
27
|
+
} | null, choose: (id: string) => void): void;
|
|
28
|
+
//# sourceMappingURL=frameMenus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frameMenus.d.ts","sourceRoot":"","sources":["../../src/react/frameMenus.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAIpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAG3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,KAAK,EAAE,IAAI,EAAY,MAAM,cAAc,CAAA;AAiBlD,6EAA6E;AAC7E,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAA;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAC1B;AAwBD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,CAAA;CAAE,GAAG,IAAI,CAiBvH;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,QAAQ,GAAG,IAAI,EACvB,KAAK,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,CAAA;CAAE,GAAG,IAAI,EACrE,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,GAC3B,IAAI,CAUN"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { addCommandHandler } from '../core/commands.js';
|
|
3
|
+
import { focusedId } from '../core/desk.js';
|
|
4
|
+
import { warnOnce } from '../core/location.js';
|
|
5
|
+
import { parseShortcut } from '../core/shortcuts.js';
|
|
6
|
+
import { checkChrome } from '../host/checkChrome.js';
|
|
7
|
+
import { addWindowMenus } from './windowMenus.js';
|
|
8
|
+
/*
|
|
9
|
+
* MENUS FROM AN EMBEDDED APP.
|
|
10
|
+
*
|
|
11
|
+
* An app in an `AppFrame` sends its menus as hosted mode's apps do, as data in a `chrome` message, and
|
|
12
|
+
* hears what was chosen as a `command`. It is somebody else's page, so its menus get the check a host
|
|
13
|
+
* gives any app's chrome (`checkChrome`): a bad menu or item is dropped and the rest kept. The frame then
|
|
14
|
+
* turns them into the page's own menus, for the window it is in, so they join the bar while that window is
|
|
15
|
+
* in front. Each item becomes a command of its own, named for this frame, so a shortcut works through the
|
|
16
|
+
* bar like any other and a choice goes back only to the frame that sent it.
|
|
17
|
+
*/
|
|
18
|
+
/** The most menus one frame adds to the bar: room for a menu or two, not a bar of its own. */
|
|
19
|
+
const MAX_MENUS = 4;
|
|
20
|
+
/**
|
|
21
|
+
* Whether an embedded app may bind this shortcut: only with ⌘/Ctrl or ⌥ held, or a function key. A bare
|
|
22
|
+
* letter, Enter, Escape or an arrow belongs to whatever has focus, and a page in a frame must not take it
|
|
23
|
+
* from the rest of the desk. Read as `matchesShortcut` reads it, so a modifier it ignores (`meta+k`) does not count.
|
|
24
|
+
*/
|
|
25
|
+
const framesMayBind = (shortcut) => {
|
|
26
|
+
const s = parseShortcut(shortcut);
|
|
27
|
+
return s.mod || s.ctrl || s.alt || /^f([1-9]|1\d|2[0-4])$/.test(s.key);
|
|
28
|
+
};
|
|
29
|
+
const converted = (row, command, menu) => {
|
|
30
|
+
if (row.type === 'separator')
|
|
31
|
+
return [{ type: 'separator' }];
|
|
32
|
+
if (row.label === undefined)
|
|
33
|
+
return [];
|
|
34
|
+
if (row.type === 'header')
|
|
35
|
+
return [{ type: 'header', label: row.label }];
|
|
36
|
+
let { shortcut } = row;
|
|
37
|
+
if (shortcut !== undefined && !framesMayBind(shortcut)) {
|
|
38
|
+
warnOnce(`desk: "${row.label}" in the ${menu} menu asks for ${shortcut}, which has no modifier. An embedded app's shortcut needs one, so it keeps its label without the key.`);
|
|
39
|
+
shortcut = undefined;
|
|
40
|
+
}
|
|
41
|
+
return [{ type: 'command', label: row.label, command, ...(row.detail === undefined ? {} : { detail: row.detail }), ...(shortcut === undefined ? {} : { shortcut }), ...(row.checked === undefined ? {} : { checked: row.checked }) }];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* An app's menus as the page's own, after `checkChrome`, its commands named `prefix`:menu index:row index, and what
|
|
45
|
+
* each stands for. Items without an id or label are left out, and menus past the first few. Null when
|
|
46
|
+
* there is nothing.
|
|
47
|
+
*/
|
|
48
|
+
export function frameMenus(raw, prefix) {
|
|
49
|
+
const checked = checkChrome({ menus: raw, dock: [], settings: [], about: null }, location.origin);
|
|
50
|
+
if (!checked.ok)
|
|
51
|
+
return null;
|
|
52
|
+
const items = [];
|
|
53
|
+
// Named by place, not by the app's ids, which may repeat or run into each other ("a:b" + "c", "a" + "b:c").
|
|
54
|
+
const menus = checked.chrome.menus.slice(0, MAX_MENUS).map((menu, m) => ({
|
|
55
|
+
id: `${prefix}/${m}`,
|
|
56
|
+
label: menu.label,
|
|
57
|
+
items: menu.items.flatMap((row, r) => {
|
|
58
|
+
if (row.type === 'item' && row.id === undefined)
|
|
59
|
+
return [];
|
|
60
|
+
const command = `${prefix}:${m}:${r}`;
|
|
61
|
+
const made = converted(row, command, menu.label);
|
|
62
|
+
if (row.type === 'item' && made.length)
|
|
63
|
+
items.push({ command, id: row.id, enabled: row.enabled !== false });
|
|
64
|
+
return made;
|
|
65
|
+
}),
|
|
66
|
+
}));
|
|
67
|
+
return menus.length ? { menus, items } : null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* While the frame has menus and its window is in front, they join the bar, and choosing an item, or
|
|
71
|
+
* pressing its shortcut, calls `choose` with the app's own id for it.
|
|
72
|
+
*/
|
|
73
|
+
export function useFrameMenus(desk, window, menus, choose) {
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (!menus || window === null)
|
|
76
|
+
return undefined;
|
|
77
|
+
const front = () => focusedId(desk.getState()) === window;
|
|
78
|
+
const stops = menus.items.map(item => addCommandHandler(document, item.command, () => choose(item.id), { enabled: () => item.enabled && front() }));
|
|
79
|
+
stops.push(addWindowMenus(desk, window, menus.menus));
|
|
80
|
+
return () => stops.forEach(stop => stop());
|
|
81
|
+
// choose is read fresh by the caller through a ref; the menus are what change.
|
|
82
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
83
|
+
}, [desk, window, menus]);
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=frameMenus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frameMenus.js","sourceRoot":"","sources":["../../src/react/frameMenus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEvD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAGpD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAGpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD;;;;;;;;;GASG;AAEH,8FAA8F;AAC9F,MAAM,SAAS,GAAG,CAAC,CAAA;AASnB;;;;GAIG;AACH,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAE,EAAE;IACzC,MAAM,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;IACjC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC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AC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AAC/C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAU,EACV,MAAuB,EACvB,KAAqE,EACrE,MAA4B;IAE5B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,KAAK,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,SAAS,CAAA;QAC/C,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,MAAM,CAAA;QACzD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,iBAAiB,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,IAAI,KAAK,EAAE,EAAE,CAAC,CAAC,CAAA;QACnJ,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;QACrD,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA;QAC1C,+EAA+E;QAC/E,uDAAuD;IACzD,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA;AAC3B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HostAbout, HostSettingsSection } from '../core/hosted.js';
|
|
2
|
+
import type { AboutSection, DeskApp } from './app.js';
|
|
3
|
+
/**
|
|
4
|
+
* An app's About as data: its note and each fact's link, `copy: false` kept, and facts `[]` for nothing
|
|
5
|
+
* to report as against null while they are read. A fact's own note is React, and stays behind.
|
|
6
|
+
*/
|
|
7
|
+
export declare function hostAbout(app: DeskApp, facts: readonly AboutSection[] | null): HostAbout;
|
|
8
|
+
/**
|
|
9
|
+
* An app's Settings sections as data, in order; none for an app without settings. An app whose Settings
|
|
10
|
+
* is a window of its own, with no sections declared, is listed as one entry with the id `''`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function hostSettings(app: DeskApp | null): HostSettingsSection[];
|
|
13
|
+
/** Sends the host the app's Settings sections and About, and opens Settings where the host says. Draws nothing. */
|
|
14
|
+
export declare function HostedApp(): null;
|
|
15
|
+
//# sourceMappingURL=hostApp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostApp.d.ts","sourceRoot":"","sources":["../../src/react/hostApp.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAoB,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAEzF,OAAO,KAAK,EAAE,YAAY,EAAW,OAAO,EAAE,MAAM,UAAU,CAAA;AAsB9D;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,YAAY,EAAE,GAAG,IAAI,GAAG,SAAS,CAoBxF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,GAAG,mBAAmB,EAAE,CAQvE;AAED,mHAAmH;AACnH,wBAAgB,SAAS,SAqBxB"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { hasSettings, useDeskApp } from './app.js';
|
|
3
|
+
import { useOpenSettings } from './appPanels.js';
|
|
4
|
+
import { badgeText } from './hostDock.js';
|
|
5
|
+
import { useHost } from './hosted.js';
|
|
6
|
+
/*
|
|
7
|
+
* SETTINGS AND ABOUT, WHEN A HOST HAS THEM.
|
|
8
|
+
*
|
|
9
|
+
* A host that runs several apps has one Settings and one About in its own frame, so a hosted app draws
|
|
10
|
+
* no gear and no About item. It sends what it declared instead: its Settings sections by name (their
|
|
11
|
+
* controls are React and stay in the app), and its name, version, links and facts as plain data. When
|
|
12
|
+
* the person picks a section in the host's Settings, the app opens its own Settings there.
|
|
13
|
+
*/
|
|
14
|
+
/** An app without facts has nothing to report. */
|
|
15
|
+
const NO_FACTS = () => [];
|
|
16
|
+
const linkOf = ({ label, url }) => ({ label, url });
|
|
17
|
+
/** A note as text, when it is text; a note drawn with React cannot cross, and is left out. */
|
|
18
|
+
const noteText = (note) => (typeof note === 'string' || typeof note === 'number' ? String(note) : undefined);
|
|
19
|
+
/**
|
|
20
|
+
* An app's About as data: its note and each fact's link, `copy: false` kept, and facts `[]` for nothing
|
|
21
|
+
* to report as against null while they are read. A fact's own note is React, and stays behind.
|
|
22
|
+
*/
|
|
23
|
+
export function hostAbout(app, facts) {
|
|
24
|
+
const sections = facts?.map((section) => ({
|
|
25
|
+
...(section.title === undefined ? {} : { title: section.title }),
|
|
26
|
+
facts: section.facts.map(({ name, value, link, copy }) => ({
|
|
27
|
+
name,
|
|
28
|
+
value,
|
|
29
|
+
...(link === undefined ? {} : { link: linkOf(link) }),
|
|
30
|
+
...(copy === false ? { copy } : {}),
|
|
31
|
+
})),
|
|
32
|
+
}));
|
|
33
|
+
const note = noteText(app.note);
|
|
34
|
+
return {
|
|
35
|
+
name: app.name,
|
|
36
|
+
...(app.version === undefined ? {} : { version: app.version }),
|
|
37
|
+
links: (app.links ?? []).map(linkOf),
|
|
38
|
+
...(note === undefined ? {} : { note }),
|
|
39
|
+
facts: sections ?? null,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* An app's Settings sections as data, in order; none for an app without settings. An app whose Settings
|
|
44
|
+
* is a window of its own, with no sections declared, is listed as one entry with the id `''`.
|
|
45
|
+
*/
|
|
46
|
+
export function hostSettings(app) {
|
|
47
|
+
if (!app || !hasSettings(app))
|
|
48
|
+
return [];
|
|
49
|
+
const sections = app.settings?.sections ?? [];
|
|
50
|
+
if (sections.length === 0)
|
|
51
|
+
return [{ id: '', title: 'Settings' }];
|
|
52
|
+
return sections.map(({ id, title, group, badge }) => {
|
|
53
|
+
const text = badgeText(badge);
|
|
54
|
+
return { id, title, ...(group === undefined ? {} : { group }), ...(text === undefined ? {} : { badge: text }) };
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** Sends the host the app's Settings sections and About, and opens Settings where the host says. Draws nothing. */
|
|
58
|
+
export function HostedApp() {
|
|
59
|
+
const host = useHost();
|
|
60
|
+
const app = useDeskApp();
|
|
61
|
+
const openSettings = useOpenSettings();
|
|
62
|
+
// The facts are a hook, read here as the About panel reads them, so they can change.
|
|
63
|
+
const facts = (app?.facts ?? NO_FACTS)();
|
|
64
|
+
const settings = hostSettings(app);
|
|
65
|
+
const about = app ? hostAbout(app, facts) : null;
|
|
66
|
+
const key = JSON.stringify([settings, about]);
|
|
67
|
+
const open = useRef(openSettings);
|
|
68
|
+
open.current = openSettings;
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
host?.setChrome({ settings, about });
|
|
71
|
+
// key stands for both, which are rebuilt on every render.
|
|
72
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
73
|
+
}, [host, key]);
|
|
74
|
+
useEffect(() => host?.onCommand('settings', id => open.current(id === '' ? undefined : id)), [host]);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=hostApp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostApp.js","sourceRoot":"","sources":["../../src/react/hostApp.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAGzC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAA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{ DeskState } from '../core/types.js';
|
|
4
|
+
import type { Desk } from '../core/desk.js';
|
|
5
|
+
import type { DockEntry, DockItem } from './Dock.js';
|
|
6
|
+
/** The dock as plain data, and the item each id opens. */
|
|
7
|
+
export interface HostDockModel {
|
|
8
|
+
readonly model: readonly HostDockEntry[];
|
|
9
|
+
readonly run: ReadonlyMap<string, DockItem>;
|
|
10
|
+
}
|
|
11
|
+
/** A badge as text: numbers and strings as they are, anything else drawn as a dot. */
|
|
12
|
+
export declare const badgeText: (badge: ReactNode) => string | undefined;
|
|
13
|
+
/** Turns dock entries into what a host can draw, as the desk stands now. */
|
|
14
|
+
export declare function hostDockModel(entries: readonly DockEntry[], state: DeskState): HostDockModel;
|
|
15
|
+
/** Opens a dock item's window, or runs its own `onSelect`, as clicking it on a drawn dock does. */
|
|
16
|
+
export declare function selectDockItem(desk: Desk, item: DockItem): void;
|
|
17
|
+
/**
|
|
18
|
+
* The dock in hosted mode. Draws nothing. Sends the host the entries whenever they or the desk
|
|
19
|
+
* change, and runs the item the host says was chosen. A right-click menu, pinning and dragging
|
|
20
|
+
* stay with the drawn dock: a host offers its own.
|
|
21
|
+
*/
|
|
22
|
+
export declare function HostedDock({ entries }: {
|
|
23
|
+
readonly entries: readonly DockEntry[];
|
|
24
|
+
}): null;
|
|
25
|
+
//# sourceMappingURL=hostDock.d.ts.map
|