@tearleads/windowing 0.2.4 → 0.2.5
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 +13 -2
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/window/CurrentWindowContext.d.ts +16 -1
- package/window/CurrentWindowContext.js +31 -3
- package/window/CurrentWindowContext.js.map +1 -1
- package/window/Window.js +12 -8
- package/window/Window.js.map +1 -1
- package/window/useWindowFit.d.ts +13 -0
- package/window/useWindowFit.js +88 -0
- package/window/useWindowFit.js.map +1 -0
- package/window/windowGeometry.d.ts +9 -0
- package/window/windowGeometry.js +27 -0
- package/window/windowGeometry.js.map +1 -1
package/README.md
CHANGED
|
@@ -68,6 +68,17 @@ restore one, pass them back as `create` options, which take precedence over
|
|
|
68
68
|
`create`'s viewport `x`/`y`. `setGeometry(id, { position, size })` moves or
|
|
69
69
|
resizes a window programmatically.
|
|
70
70
|
|
|
71
|
+
Content with a natural size, such as a document page, passes it in CSS pixels
|
|
72
|
+
to `useWindowContentSize({ width, height })` while it is mounted. Its window
|
|
73
|
+
then offers **Fit to Content** in the View menu, which restores the window if
|
|
74
|
+
maximized and sizes it so the scroll pane's content area shows that size. The
|
|
75
|
+
fit measures the chrome as rendered (bars, sidebar, the pane's padding and
|
|
76
|
+
scrollbars) and stays within the surface. Content the surface cannot hold
|
|
77
|
+
scrolls. The width always leaves room for a vertical scrollbar, so the
|
|
78
|
+
content keeps its width even when a status message briefly takes height from
|
|
79
|
+
the body. Last, the window moves as far as it must to stay on the surface.
|
|
80
|
+
`undefined` withdraws the item.
|
|
81
|
+
|
|
71
82
|
## Slots
|
|
72
83
|
|
|
73
84
|
- **`ContentBoundary`** — `Window` renders a window's component inside this
|
|
@@ -79,8 +90,8 @@ resizes a window programmatically.
|
|
|
79
90
|
window layer only stores and compares it; the host interprets it.
|
|
80
91
|
|
|
81
92
|
Windows register their own menu items, title-bar actions, a Back action, a
|
|
82
|
-
sidebar, and a
|
|
83
|
-
window's content.
|
|
93
|
+
sidebar, a background, and a natural size through the `useWindow*` hooks, from
|
|
94
|
+
inside the window's content.
|
|
84
95
|
|
|
85
96
|
## Toolbar
|
|
86
97
|
|
package/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { Menu, type MenuPosition } from "./menu/Menu.js";
|
|
|
3
3
|
export { MenuItem, type MenuItemProps } from "./menu/MenuItem.js";
|
|
4
4
|
export { type ContextMenuState, useContextMenuPositionState, useContextMenuState, } from "./menu/useContextMenuState.js";
|
|
5
5
|
export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.js";
|
|
6
|
-
export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, useWindowBackground, } from "./window/CurrentWindowContext.js";
|
|
6
|
+
export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, useWindowBackground, useWindowContentSize, } from "./window/CurrentWindowContext.js";
|
|
7
7
|
export { Window, type WindowContentBoundary } from "./window/Window.js";
|
|
8
8
|
export { WindowTitleBarActionButtons } from "./window/WindowChromeActions.js";
|
|
9
9
|
export { WindowCloseButton } from "./window/WindowCloseButton.js";
|
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export { Menu } from "./menu/Menu.js";
|
|
|
6
6
|
export { MenuItem } from "./menu/MenuItem.js";
|
|
7
7
|
export { useContextMenuPositionState, useContextMenuState, } from "./menu/useContextMenuState.js";
|
|
8
8
|
export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.js";
|
|
9
|
-
export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, useWindowBackground, } from "./window/CurrentWindowContext.js";
|
|
9
|
+
export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, useWindowBackground, useWindowContentSize, } from "./window/CurrentWindowContext.js";
|
|
10
10
|
export { Window } from "./window/Window.js";
|
|
11
11
|
export { WindowTitleBarActionButtons } from "./window/WindowChromeActions.js";
|
|
12
12
|
export { WindowCloseButton } from "./window/WindowCloseButton.js";
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../home/runner/work/tearleads/tearleads/packages/windowing/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,6EAA6E;AAC7E,sEAAsE;AACtE,OAAO,EACL,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,IAAI,EAAqB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAsB,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAEL,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../home/runner/work/tearleads/tearleads/packages/windowing/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,6EAA6E;AAC7E,sEAAsE;AACtE,OAAO,EACL,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,IAAI,EAAqB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAsB,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAEL,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,MAAM,EAA8B,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,6BAA6B,EAC7B,uBAAuB,EACvB,wBAAwB,EACxB,2BAA2B,EAC3B,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAQlB,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["import \"./tokens.css\";\n\n// The public windowing API: window state, window chrome and its registration\n// hooks, and the menu and sidebar primitives the chrome renders with.\nexport {\n createRequiredContext,\n type RequiredContext,\n} from \"./createRequiredContext\";\nexport { Menu, type MenuPosition } from \"./menu/Menu\";\nexport { MenuItem, type MenuItemProps } from \"./menu/MenuItem\";\nexport {\n type ContextMenuState,\n useContextMenuPositionState,\n useContextMenuState,\n} from \"./menu/useContextMenuState\";\nexport { SidebarResizeHandle, useSidebarResize } from \"./sidebar/SidebarResize\";\nexport {\n CurrentWindowProvider,\n useCurrentWindow,\n useSuppressWindowToolbar,\n useWindowBackground,\n useWindowContentSize,\n} from \"./window/CurrentWindowContext\";\nexport { Window, type WindowContentBoundary } from \"./window/Window\";\nexport { WindowTitleBarActionButtons } from \"./window/WindowChromeActions\";\nexport { WindowCloseButton } from \"./window/WindowCloseButton\";\nexport {\n useWindowBackAction,\n useWindowBackActionValue,\n useWindowFileMenuItem,\n useWindowRefreshMenuItem,\n useWindowRefreshMenuItemValue,\n useWindowTitleBarAction,\n useWindowTitleBarActions,\n useWindowToolbarReservation,\n useWindowViewMenuItem,\n WindowMenuProvider,\n} from \"./window/WindowMenuContext\";\nexport {\n hasWindowSidebar,\n useRegisteredWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./window/WindowSidebarContext\";\nexport {\n findTopWindow,\n useWindowActions,\n useWindowStateData,\n type WindowCreateOptions,\n type WindowEntry,\n type WindowGeometry,\n type WindowPosition,\n type WindowSize,\n type WindowStateActions,\n type WindowStateData,\n WindowStateProvider,\n} from \"./window/WindowStateProvider\";\nexport { WindowToolBar } from \"./window/WindowToolBar\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tearleads/windowing",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "App-agnostic window management for React: window state, window chrome, and the menu and sidebar primitives it renders with.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type PropsWithChildren } from "react";
|
|
2
|
+
import type { WindowSize } from "./WindowStateProvider/index.js";
|
|
2
3
|
interface CurrentWindowContextValue {
|
|
3
4
|
close: () => void;
|
|
4
5
|
id: string;
|
|
@@ -9,6 +10,12 @@ interface CurrentWindowContextValue {
|
|
|
9
10
|
* provider outside a `Window` may omit it.
|
|
10
11
|
*/
|
|
11
12
|
setBackground?: ((background: string | undefined) => void) | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Record the content's natural size, which the window's Fit to Content sizes
|
|
15
|
+
* it to; `undefined` withdraws it. Hosts that render this provider outside a
|
|
16
|
+
* `Window` may omit it.
|
|
17
|
+
*/
|
|
18
|
+
setContentSize?: ((size: WindowSize | undefined) => void) | undefined;
|
|
12
19
|
showStatusMessage: (message: string) => void;
|
|
13
20
|
/**
|
|
14
21
|
* Hide the window's toolbar row until the returned release is called. Refcounted,
|
|
@@ -16,7 +23,7 @@ interface CurrentWindowContextValue {
|
|
|
16
23
|
*/
|
|
17
24
|
suppressToolbar: () => () => void;
|
|
18
25
|
}
|
|
19
|
-
export declare function CurrentWindowProvider({ children, close, id, overlayHost, setBackground, showStatusMessage, suppressToolbar, }: PropsWithChildren<CurrentWindowContextValue>): import("react").JSX.Element;
|
|
26
|
+
export declare function CurrentWindowProvider({ children, close, id, overlayHost, setBackground, setContentSize, showStatusMessage, suppressToolbar, }: PropsWithChildren<CurrentWindowContextValue>): import("react").JSX.Element;
|
|
20
27
|
export declare function useCurrentWindow(): CurrentWindowContextValue | null;
|
|
21
28
|
/**
|
|
22
29
|
* Drop the host window's toolbar row while `active`.
|
|
@@ -40,4 +47,12 @@ export declare function useSuppressWindowToolbar(active: boolean): void;
|
|
|
40
47
|
* frame before the content's own background.
|
|
41
48
|
*/
|
|
42
49
|
export declare function useWindowBackground(background: string | undefined): void;
|
|
50
|
+
/**
|
|
51
|
+
* Offer Fit to Content in the host window's View menu while mounted. It sizes
|
|
52
|
+
* the window so its content area shows `size`, the content's natural size in
|
|
53
|
+
* CSS pixels, as far as the desktop surface allows; content that still scrolls
|
|
54
|
+
* gets room for its scrollbar. `undefined` withdraws the item. Outside a window
|
|
55
|
+
* this is inert.
|
|
56
|
+
*/
|
|
57
|
+
export declare function useWindowContentSize(size: WindowSize | undefined): void;
|
|
43
58
|
export {};
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useContext, useLayoutEffect, useMemo, } from "react";
|
|
2
|
+
import { createContext, useContext, useEffect, useLayoutEffect, useMemo, } from "react";
|
|
3
3
|
const CurrentWindowContext = createContext(null);
|
|
4
|
-
export function CurrentWindowProvider({ children, close, id, overlayHost, setBackground, showStatusMessage, suppressToolbar, }) {
|
|
4
|
+
export function CurrentWindowProvider({ children, close, id, overlayHost, setBackground, setContentSize, showStatusMessage, suppressToolbar, }) {
|
|
5
5
|
const value = useMemo(() => ({
|
|
6
6
|
close,
|
|
7
7
|
id,
|
|
8
8
|
overlayHost,
|
|
9
9
|
setBackground,
|
|
10
|
+
setContentSize,
|
|
10
11
|
showStatusMessage,
|
|
11
12
|
suppressToolbar,
|
|
12
|
-
}), [
|
|
13
|
+
}), [
|
|
14
|
+
close,
|
|
15
|
+
id,
|
|
16
|
+
overlayHost,
|
|
17
|
+
setBackground,
|
|
18
|
+
setContentSize,
|
|
19
|
+
showStatusMessage,
|
|
20
|
+
suppressToolbar,
|
|
21
|
+
]);
|
|
13
22
|
return (_jsx(CurrentWindowContext.Provider, { value: value, children: children }));
|
|
14
23
|
}
|
|
15
24
|
export function useCurrentWindow() {
|
|
@@ -54,4 +63,23 @@ export function useWindowBackground(background) {
|
|
|
54
63
|
return () => setBackground(undefined);
|
|
55
64
|
}, [background, setBackground]);
|
|
56
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Offer Fit to Content in the host window's View menu while mounted. It sizes
|
|
68
|
+
* the window so its content area shows `size`, the content's natural size in
|
|
69
|
+
* CSS pixels, as far as the desktop surface allows; content that still scrolls
|
|
70
|
+
* gets room for its scrollbar. `undefined` withdraws the item. Outside a window
|
|
71
|
+
* this is inert.
|
|
72
|
+
*/
|
|
73
|
+
export function useWindowContentSize(size) {
|
|
74
|
+
const setContentSize = useCurrentWindow()?.setContentSize;
|
|
75
|
+
const width = size?.width;
|
|
76
|
+
const height = size?.height;
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (width === undefined || height === undefined || !setContentSize) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
setContentSize({ height, width });
|
|
82
|
+
return () => setContentSize(undefined);
|
|
83
|
+
}, [height, setContentSize, width]);
|
|
84
|
+
}
|
|
57
85
|
//# sourceMappingURL=CurrentWindowContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrentWindowContext.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/CurrentWindowContext.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAEb,UAAU,EACV,eAAe,EACf,OAAO,GACR,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"CurrentWindowContext.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/CurrentWindowContext.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAEb,UAAU,EACV,SAAS,EACT,eAAe,EACf,OAAO,GACR,MAAM,OAAO,CAAC;AA2Bf,MAAM,oBAAoB,GAAG,aAAa,CACxC,IAAI,CACL,CAAC;AAEF,MAAM,UAAU,qBAAqB,CAAC,EACpC,QAAQ,EACR,KAAK,EACL,EAAE,EACF,WAAW,EACX,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,eAAe,GAC8B;IAC7C,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC;QACL,KAAK;QACL,EAAE;QACF,WAAW;QACX,aAAa;QACb,cAAc;QACd,iBAAiB;QACjB,eAAe;KAChB,CAAC,EACF;QACE,KAAK;QACL,EAAE;QACF,WAAW;QACX,aAAa;QACb,cAAc;QACd,iBAAiB;QACjB,eAAe;KAChB,CACF,CAAC;IAEF,OAAO,CACL,KAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACxC,QAAQ,GACqB,CACjC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAU,CAAC,oBAAoB,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAe;IACtD,MAAM,eAAe,GAAG,gBAAgB,EAAE,EAAE,eAAe,CAAC;IAE5D,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;YAChC,OAAO;QACT,CAAC;QACD,OAAO,eAAe,EAAE,CAAC;IAC3B,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAA8B;IAChE,MAAM,aAAa,GAAG,gBAAgB,EAAE,EAAE,aAAa,CAAC;IAExD,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,UAAU,KAAK,SAAS,IAAI,CAAC,aAAa,EAAE,CAAC;YAC/C,OAAO;QACT,CAAC;QACD,aAAa,CAAC,UAAU,CAAC,CAAC;QAC1B,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAA4B;IAC/D,MAAM,cAAc,GAAG,gBAAgB,EAAE,EAAE,cAAc,CAAC;IAC1D,MAAM,KAAK,GAAG,IAAI,EAAE,KAAK,CAAC;IAC1B,MAAM,MAAM,GAAG,IAAI,EAAE,MAAM,CAAC;IAE5B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,KAAK,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,cAAc,EAAE,CAAC;YACnE,OAAO;QACT,CAAC;QACD,cAAc,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QAClC,OAAO,GAAG,EAAE,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import {\n createContext,\n type PropsWithChildren,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n} from \"react\";\nimport type { WindowSize } from \"./WindowStateProvider\";\n\ninterface CurrentWindowContextValue {\n close: () => void;\n id: string;\n overlayHost: HTMLElement | null;\n /**\n * Paint the window's background with `background`, any CSS color, in place of\n * `--window-background`; `undefined` restores it. Hosts that render this\n * provider outside a `Window` may omit it.\n */\n setBackground?: ((background: string | undefined) => void) | undefined;\n /**\n * Record the content's natural size, which the window's Fit to Content sizes\n * it to; `undefined` withdraws it. Hosts that render this provider outside a\n * `Window` may omit it.\n */\n setContentSize?: ((size: WindowSize | undefined) => void) | undefined;\n showStatusMessage: (message: string) => void;\n /**\n * Hide the window's toolbar row until the returned release is called. Refcounted,\n * so overlapping suppressions restore the row only once the last one releases.\n */\n suppressToolbar: () => () => void;\n}\n\nconst CurrentWindowContext = createContext<CurrentWindowContextValue | null>(\n null,\n);\n\nexport function CurrentWindowProvider({\n children,\n close,\n id,\n overlayHost,\n setBackground,\n setContentSize,\n showStatusMessage,\n suppressToolbar,\n}: PropsWithChildren<CurrentWindowContextValue>) {\n const value = useMemo(\n () => ({\n close,\n id,\n overlayHost,\n setBackground,\n setContentSize,\n showStatusMessage,\n suppressToolbar,\n }),\n [\n close,\n id,\n overlayHost,\n setBackground,\n setContentSize,\n showStatusMessage,\n suppressToolbar,\n ],\n );\n\n return (\n <CurrentWindowContext.Provider value={value}>\n {children}\n </CurrentWindowContext.Provider>\n );\n}\n\nexport function useCurrentWindow() {\n return useContext(CurrentWindowContext);\n}\n\n/**\n * Drop the host window's toolbar row while `active`.\n *\n * A full-pane overlay (the image viewer) carries its own toolbar, and the\n * window's row would otherwise stack directly above it — two toolbars, one of\n * them driving chrome the overlay covers. Outside a window this is inert, since\n * the routed shell's overlays cover the whole viewport already.\n *\n * Suppressing in a layout effect keeps the row from being painted alongside the\n * overlay's own toolbar for a frame and then resizing the pane out from under it.\n */\nexport function useSuppressWindowToolbar(active: boolean) {\n const suppressToolbar = useCurrentWindow()?.suppressToolbar;\n\n useLayoutEffect(() => {\n if (!active || !suppressToolbar) {\n return;\n }\n return suppressToolbar();\n }, [active, suppressToolbar]);\n}\n\n/**\n * Paint the host window's background, behind its body and sidebar, with\n * `background` (any CSS color) while mounted; `undefined` keeps the default,\n * `--window-background`. A document viewer uses it to set its page apart from\n * the window around it. Outside a window this is inert.\n *\n * Applying it in a layout effect keeps the default from being painted for a\n * frame before the content's own background.\n */\nexport function useWindowBackground(background: string | undefined) {\n const setBackground = useCurrentWindow()?.setBackground;\n\n useLayoutEffect(() => {\n if (background === undefined || !setBackground) {\n return;\n }\n setBackground(background);\n return () => setBackground(undefined);\n }, [background, setBackground]);\n}\n\n/**\n * Offer Fit to Content in the host window's View menu while mounted. It sizes\n * the window so its content area shows `size`, the content's natural size in\n * CSS pixels, as far as the desktop surface allows; content that still scrolls\n * gets room for its scrollbar. `undefined` withdraws the item. Outside a window\n * this is inert.\n */\nexport function useWindowContentSize(size: WindowSize | undefined) {\n const setContentSize = useCurrentWindow()?.setContentSize;\n const width = size?.width;\n const height = size?.height;\n\n useEffect(() => {\n if (width === undefined || height === undefined || !setContentSize) {\n return;\n }\n setContentSize({ height, width });\n return () => setContentSize(undefined);\n }, [height, setContentSize, width]);\n}\n"]}
|
package/window/Window.js
CHANGED
|
@@ -2,8 +2,9 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { useCallback, useEffect, useId, useMemo, useRef, useState, } from "react";
|
|
3
3
|
import "./Window.css";
|
|
4
4
|
import { CurrentWindowProvider } from "./CurrentWindowContext.js";
|
|
5
|
+
import { useWindowGeometryMenu } from "./useWindowFit.js";
|
|
5
6
|
import { useWindowGeometry } from "./useWindowGeometry.js";
|
|
6
|
-
import { useFocusWindowOnShow
|
|
7
|
+
import { useFocusWindowOnShow } from "./useWindowKeyboardGeometry.js";
|
|
7
8
|
import { WindowBody } from "./WindowBody.js";
|
|
8
9
|
import { WindowMenuBar } from "./WindowMenuBar.js";
|
|
9
10
|
import { useWindowFileMenuItems, useWindowViewMenuItems, WindowMenuProvider, } from "./WindowMenuContext.js";
|
|
@@ -85,7 +86,7 @@ function useWindowActions(entry, fileMenuItems, viewMenuItems, geometryMenuItems
|
|
|
85
86
|
showStatusBar,
|
|
86
87
|
};
|
|
87
88
|
}
|
|
88
|
-
function
|
|
89
|
+
function getWindowFrameStyle(maximized, position, size, zIndex) {
|
|
89
90
|
if (maximized) {
|
|
90
91
|
return { top: 0, left: 0, width: "100%", height: "100%", zIndex };
|
|
91
92
|
}
|
|
@@ -105,6 +106,12 @@ function getWindowStyle(maximized, position, size, zIndex) {
|
|
|
105
106
|
...(size ? { width: size.width, height: size.height } : {}),
|
|
106
107
|
};
|
|
107
108
|
}
|
|
109
|
+
function getWindowStyle(maximized, position, size, zIndex, background) {
|
|
110
|
+
return {
|
|
111
|
+
...getWindowFrameStyle(maximized, position, size, zIndex),
|
|
112
|
+
"--window-background": background,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
108
115
|
function useWindowStatusMessage() {
|
|
109
116
|
const [statusText, setStatusText] = useState("");
|
|
110
117
|
const statusTimeoutRef = useRef(null);
|
|
@@ -178,7 +185,7 @@ function WindowInnerContent({ ContentBoundary, entry, historyBack, isTop, }) {
|
|
|
178
185
|
const hasSidebar = hasWindowSidebar(sidebar);
|
|
179
186
|
const { handlePointerDown, handleResizePointerDown, position, size, ...stepped } = useWindowGeometry(entry, maximized, windowRef);
|
|
180
187
|
const { showStatusMessage, statusText } = useWindowStatusMessage();
|
|
181
|
-
const geometryMenuItems =
|
|
188
|
+
const { geometryMenuItems, setContentSize } = useWindowGeometryMenu(entry, stepped, { overlayHost, windowRef }, showStatusMessage);
|
|
182
189
|
const actions = useWindowActions(entry, fileMenuItems, viewMenuItems, geometryMenuItems, hasSidebar);
|
|
183
190
|
// A maximized window fills its surface without a laid-out position.
|
|
184
191
|
useFocusWindowOnShow(windowRef, {
|
|
@@ -187,17 +194,14 @@ function WindowInnerContent({ ContentBoundary, entry, historyBack, isTop, }) {
|
|
|
187
194
|
});
|
|
188
195
|
const { suppressToolbar, toolbarSuppressed } = useWindowToolbarSuppression();
|
|
189
196
|
const { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps } = useWindowRootHandlers(entry.id);
|
|
190
|
-
const style =
|
|
191
|
-
...getWindowStyle(maximized, position, size, zIndex),
|
|
192
|
-
"--window-background": background,
|
|
193
|
-
};
|
|
197
|
+
const style = getWindowStyle(maximized, position, size, zIndex, background);
|
|
194
198
|
if (minimized) {
|
|
195
199
|
return null;
|
|
196
200
|
}
|
|
197
201
|
// A section labelled by its title is a region landmark. Windows are
|
|
198
202
|
// non-modal and freely arranged, so they are not dialogs; hosts keep that
|
|
199
203
|
// role for the modals they open inside a window.
|
|
200
|
-
return (_jsxs("section", { ref: windowRef, "aria-labelledby": titleId, className: maximized ? "window window--maximized" : "window", tabIndex: -1, ...windowContextMenuTrapProps, onPointerDownCapture: handleWindowPointerDown, style: style, children: [_jsx(WindowChrome, { actions: actions, entry: entry, historyBack: historyBack, onGoBack: handleGoBack, onPointerDown: handlePointerDown, titleId: titleId, toolbarSuppressed: toolbarSuppressed }), _jsx(CurrentWindowProvider, { close: actions.handleClose, id: entry.id, overlayHost: overlayHost, setBackground: setBackground, showStatusMessage: showStatusMessage, suppressToolbar: suppressToolbar, children: _jsx(WindowBodyWithSidebar, { overlayHostRef: setOverlayHost, showSidebar: actions.showSidebar, children: ContentBoundary ? (_jsx(ContentBoundary, { entry: entry, children: Component && _jsx(Component, {}) })) : (Component && _jsx(Component, {})) }) }), _jsx(WindowStatusBar, { text: statusText, visible: actions.showStatusBar }), !maximized && (_jsx(WindowResizeHandles, { handleResizePointerDown: handleResizePointerDown }))] }));
|
|
204
|
+
return (_jsxs("section", { ref: windowRef, "aria-labelledby": titleId, className: maximized ? "window window--maximized" : "window", tabIndex: -1, ...windowContextMenuTrapProps, onPointerDownCapture: handleWindowPointerDown, style: style, children: [_jsx(WindowChrome, { actions: actions, entry: entry, historyBack: historyBack, onGoBack: handleGoBack, onPointerDown: handlePointerDown, titleId: titleId, toolbarSuppressed: toolbarSuppressed }), _jsx(CurrentWindowProvider, { close: actions.handleClose, id: entry.id, overlayHost: overlayHost, setBackground: setBackground, setContentSize: setContentSize, showStatusMessage: showStatusMessage, suppressToolbar: suppressToolbar, children: _jsx(WindowBodyWithSidebar, { overlayHostRef: setOverlayHost, showSidebar: actions.showSidebar, children: ContentBoundary ? (_jsx(ContentBoundary, { entry: entry, children: Component && _jsx(Component, {}) })) : (Component && _jsx(Component, {})) }) }), _jsx(WindowStatusBar, { text: statusText, visible: actions.showStatusBar }), !maximized && (_jsx(WindowResizeHandles, { handleResizePointerDown: handleResizePointerDown }))] }));
|
|
201
205
|
}
|
|
202
206
|
function WindowBodyWithSidebar({ showSidebar, overlayHostRef, children, }) {
|
|
203
207
|
const { sidebar } = useWindowSidebar();
|
package/window/Window.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Window.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/Window.tsx"],"names":[],"mappings":";AAAA,OAAO,EAOL,WAAW,EACX,SAAS,EACT,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AACrE,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,aAAa,EACb,gBAAgB,IAAI,qBAAqB,EACzC,kBAAkB,GAInB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,M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OAAO,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACvC,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE7C,OAAO,CACL,KAAC,UAAU,IACT,UAAU,EAAE,cAAc,EAC1B,WAAW,EAAE,WAAW,IAAI,UAAU,EACtC,OAAO,EAAE,OAAO,YAEf,QAAQ,GACE,CACd,CAAC;AACJ,CAAC","sourcesContent":["import {\n type ComponentType,\n type CSSProperties,\n type HTMLAttributes,\n type PropsWithChildren,\n type MouseEvent as ReactMouseEvent,\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport \"./Window.css\";\nimport { CurrentWindowProvider } from \"./CurrentWindowContext\";\nimport { useWindowGeometry } from \"./useWindowGeometry\";\nimport {\n useFocusWindowOnShow,\n useWindowGeometryMenuItems,\n} from \"./useWindowKeyboardGeometry\";\nimport { WindowBody } from \"./WindowBody\";\nimport { WindowMenuBar, type WindowMenuItem } from \"./WindowMenuBar\";\nimport {\n useWindowFileMenuItems,\n useWindowViewMenuItems,\n WindowMenuProvider,\n} from \"./WindowMenuContext\";\nimport { WindowResizeHandles } from \"./WindowResizeHandle\";\nimport {\n hasWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./WindowSidebarContext\";\nimport {\n findTopWindow,\n useWindowActions as useWindowStateActions,\n useWindowStateData,\n type WindowEntry,\n type WindowPosition,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport { WindowStatusBar } from \"./WindowStatusBar\";\nimport { WindowTitleBar } from \"./WindowTitleBar\";\nimport { WindowToolBar } from \"./WindowToolBar\";\n\n// Wraps a window's content so the host can give it app-specific context (a\n// route, an error boundary) without the window layer knowing about apps.\nexport type WindowContentBoundary = ComponentType<\n PropsWithChildren<{ entry: WindowEntry }>\n>;\n\ninterface WindowProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n /**\n * Whether the toolbar offers Back through the window's own route history,\n * reserving its row from the start (see `WindowToolBar`). Defaults to whether\n * the window has an `appId`. Pass false for an app that never routes, so its\n * window has no toolbar row until the app first registers toolbar actions.\n */\n historyBack?: boolean | undefined;\n windowId: string;\n}\n\nconst WINDOW_STATUS_MESSAGE_DURATION_MS = 2500;\n\nexport function Window({\n ContentBoundary,\n historyBack,\n windowId,\n}: WindowProps) {\n const { windowMap, windows } = useWindowStateData();\n const entry = windowMap.get(windowId);\n const isTop =\n findTopWindow(windows, (candidate) => !candidate.minimized)?.id ===\n windowId;\n\n if (!entry) return null;\n\n return (\n <WindowInner\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack ?? entry.appId !== undefined}\n isTop={isTop}\n />\n );\n}\n\nfunction useWindowActions(\n entry: WindowEntry,\n fileMenuItems: WindowMenuItem[],\n viewMenuItems: WindowMenuItem[],\n geometryMenuItems: WindowMenuItem[],\n hasSidebar: boolean,\n) {\n const { close, minimize, moveBackward, moveForward, toggleMaximize } =\n useWindowStateActions();\n const [showStatusBar, setShowStatusBar] = useState(true);\n const [showSidebar, setShowSidebar] = useState(\n entry.initialShowSidebar ?? true,\n );\n const handleClose = useCallback(() => close(entry.id), [close, entry.id]);\n const handleMinimize = useCallback(\n () => minimize(entry.id),\n [entry.id, minimize],\n );\n const handleMoveForward = useCallback(\n () => moveForward(entry.id),\n [entry.id, moveForward],\n );\n const handleMoveBackward = useCallback(\n () => moveBackward(entry.id),\n [entry.id, moveBackward],\n );\n const handleMaximize = useCallback(\n () => toggleMaximize(entry.id),\n [entry.id, toggleMaximize],\n );\n const toggleStatusBar = useCallback(\n () => setShowStatusBar((previous) => !previous),\n [],\n );\n const toggleSidebar = useCallback(\n () => setShowSidebar((previous) => !previous),\n [],\n );\n const menus = useMemo(\n () => [\n {\n label: \"File\",\n items: [\n ...fileMenuItems,\n { id: \"close\", label: \"Close\", onClick: handleClose },\n ],\n },\n {\n label: \"View\",\n items: [\n ...viewMenuItems,\n ...geometryMenuItems,\n {\n id: \"toggle-status-bar\",\n label: `${showStatusBar ? \"Hide\" : \"Show\"} Status Bar`,\n onClick: toggleStatusBar,\n },\n ...(hasSidebar\n ? [\n {\n id: \"toggle-sidebar\",\n label: `${showSidebar ? \"Hide\" : \"Show\"} Sidebar`,\n onClick: toggleSidebar,\n },\n ]\n : []),\n ],\n },\n ],\n [\n geometryMenuItems,\n hasSidebar,\n handleClose,\n fileMenuItems,\n showSidebar,\n showStatusBar,\n toggleSidebar,\n toggleStatusBar,\n viewMenuItems,\n ],\n );\n\n return {\n handleClose,\n handleMaximize,\n handleMinimize,\n handleMoveBackward,\n handleMoveForward,\n menus,\n showSidebar,\n showStatusBar,\n };\n}\n\n// The window paints with `--window-background`, which a background its content\n// sets (see `useWindowBackground`) overrides inline.\ninterface WindowStyle extends CSSProperties {\n \"--window-background\"?: string | undefined;\n}\n\nfunction getWindowStyle(\n maximized: boolean,\n position: WindowPosition | null,\n size: WindowSize | null,\n zIndex: number,\n): CSSProperties | undefined {\n if (maximized) {\n return { top: 0, left: 0, width: \"100%\", height: \"100%\", zIndex };\n }\n if (!position) {\n // Hidden until laid out; a requested size applies already so the first\n // clamp measures the window at the size it will show.\n return {\n visibility: \"hidden\",\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n }\n\n return {\n left: position.x,\n top: position.y,\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n}\n\nfunction useWindowStatusMessage() {\n const [statusText, setStatusText] = useState(\"\");\n const statusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const showStatusMessage = useCallback((message: string) => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n setStatusText(message);\n statusTimeoutRef.current = setTimeout(() => {\n setStatusText(\"\");\n statusTimeoutRef.current = null;\n }, WINDOW_STATUS_MESSAGE_DURATION_MS);\n }, []);\n\n useEffect(() => {\n return () => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n };\n }, []);\n\n return { showStatusMessage, statusText };\n}\n\n// Refcounted so overlapping overlays (one closing as another opens) never leave\n// the row hidden, and never flash it back for a frame between the two.\nfunction useWindowToolbarSuppression() {\n const [suppressionCount, setSuppressionCount] = useState(0);\n const suppressToolbar = useCallback(() => {\n setSuppressionCount((count) => count + 1);\n return () => setSuppressionCount((count) => Math.max(0, count - 1));\n }, []);\n\n return { suppressToolbar, toolbarSuppressed: suppressionCount > 0 };\n}\n\ninterface WindowInnerProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n entry: WindowEntry;\n historyBack: boolean;\n // Whether this is the foremost visible window, the one that takes focus.\n isTop: boolean;\n}\n\nfunction WindowInner({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n return (\n <WindowMenuProvider>\n <WindowSidebarProvider>\n <WindowInnerContent\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack}\n isTop={isTop}\n />\n </WindowSidebarProvider>\n </WindowMenuProvider>\n );\n}\n\n// The bars above the body: title, menus, and the toolbar row a full-pane overlay\n// can stand down (see `useWindowToolbarSuppression`).\nfunction WindowChrome({\n actions,\n entry,\n historyBack,\n onGoBack,\n onPointerDown,\n titleId,\n toolbarSuppressed,\n}: {\n actions: ReturnType<typeof useWindowActions>;\n entry: WindowEntry;\n historyBack: boolean;\n onGoBack: () => void;\n onPointerDown: (event: ReactPointerEvent) => void;\n titleId: string;\n toolbarSuppressed: boolean;\n}) {\n return (\n <>\n <WindowTitleBar\n title={entry.title}\n titleId={titleId}\n onPointerDown={onPointerDown}\n onMinimize={actions.handleMinimize}\n onMaximize={actions.handleMaximize}\n onClose={actions.handleClose}\n onMoveForward={actions.handleMoveForward}\n onMoveBackward={actions.handleMoveBackward}\n />\n <WindowMenuBar menus={actions.menus} />\n {!toolbarSuppressed && (\n <WindowToolBar\n canGoBack={(entry.routeHistory?.length ?? 0) > 0}\n showHistoryBack={historyBack}\n onGoBack={onGoBack}\n />\n )}\n </>\n );\n}\n\n// Handlers on the window root: its Back caret, raising it on any press inside,\n// and keeping background context menus from opening under window-local ones.\nfunction useWindowRootHandlers(windowId: string) {\n // The toolbar renders above the route boundary, so the window's own Back stack\n // is threaded in from here rather than read from context.\n const { bringToFront, goBackRoute } = useWindowStateActions();\n const handleGoBack = useCallback(() => {\n goBackRoute(windowId);\n }, [windowId, goBackRoute]);\n const handleWindowPointerDown = useCallback(() => {\n bringToFront(windowId);\n }, [bringToFront, windowId]);\n const handleWindowContextMenu = useCallback((event: ReactMouseEvent) => {\n // Keep background pane context menus from opening underneath window-local menus.\n event.stopPropagation();\n }, []);\n const windowContextMenuTrapProps: Pick<\n HTMLAttributes<HTMLElement>,\n \"onContextMenu\"\n > = {\n onContextMenu: handleWindowContextMenu,\n };\n\n return { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps };\n}\n\nfunction WindowInnerContent({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n const { maximized, minimized, zIndex, component: Component } = entry;\n const windowRef = useRef<HTMLElement>(null);\n const titleId = useId();\n const [overlayHost, setOverlayHost] = useState<HTMLElement | null>(null);\n const [background, setBackground] = useState<string | undefined>();\n const fileMenuItems = useWindowFileMenuItems();\n const viewMenuItems = useWindowViewMenuItems();\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n const {\n handlePointerDown,\n handleResizePointerDown,\n position,\n size,\n ...stepped\n } = useWindowGeometry(entry, maximized, windowRef);\n const { showStatusMessage, statusText } = useWindowStatusMessage();\n const geometryMenuItems = useWindowGeometryMenuItems(\n stepped,\n { maximized, minimized, windowRef },\n showStatusMessage,\n );\n const actions = useWindowActions(\n entry,\n fileMenuItems,\n viewMenuItems,\n geometryMenuItems,\n hasSidebar,\n );\n // A maximized window fills its surface without a laid-out position.\n useFocusWindowOnShow(windowRef, {\n isTop,\n shown: !minimized && (maximized || position !== null),\n });\n const { suppressToolbar, toolbarSuppressed } = useWindowToolbarSuppression();\n const { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps } =\n useWindowRootHandlers(entry.id);\n const style: WindowStyle = {\n ...getWindowStyle(maximized, position, size, zIndex),\n \"--window-background\": background,\n };\n\n if (minimized) {\n return null;\n }\n\n // A section labelled by its title is a region landmark. Windows are\n // non-modal and freely arranged, so they are not dialogs; hosts keep that\n // role for the modals they open inside a window.\n return (\n <section\n ref={windowRef}\n aria-labelledby={titleId}\n className={maximized ? \"window window--maximized\" : \"window\"}\n tabIndex={-1}\n {...windowContextMenuTrapProps}\n onPointerDownCapture={handleWindowPointerDown}\n style={style}\n >\n <WindowChrome\n actions={actions}\n entry={entry}\n historyBack={historyBack}\n onGoBack={handleGoBack}\n onPointerDown={handlePointerDown}\n titleId={titleId}\n toolbarSuppressed={toolbarSuppressed}\n />\n <CurrentWindowProvider\n close={actions.handleClose}\n id={entry.id}\n overlayHost={overlayHost}\n setBackground={setBackground}\n showStatusMessage={showStatusMessage}\n suppressToolbar={suppressToolbar}\n >\n <WindowBodyWithSidebar\n overlayHostRef={setOverlayHost}\n showSidebar={actions.showSidebar}\n >\n {ContentBoundary ? (\n <ContentBoundary entry={entry}>\n {Component && <Component />}\n </ContentBoundary>\n ) : (\n Component && <Component />\n )}\n </WindowBodyWithSidebar>\n </CurrentWindowProvider>\n <WindowStatusBar text={statusText} visible={actions.showStatusBar} />\n {!maximized && (\n <WindowResizeHandles\n handleResizePointerDown={handleResizePointerDown}\n />\n )}\n </section>\n );\n}\n\nfunction WindowBodyWithSidebar({\n showSidebar,\n overlayHostRef,\n children,\n}: PropsWithChildren<{\n overlayHostRef: (element: HTMLDivElement | null) => void;\n showSidebar: boolean;\n}>) {\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n\n return (\n <WindowBody\n contentRef={overlayHostRef}\n showSidebar={showSidebar && hasSidebar}\n sidebar={sidebar}\n >\n {children}\n </WindowBody>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Window.js","sourceRoot":"","sources":["../../../home/runner/work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,KAAC,UAAU,IACT,UAAU,EAAE,cAAc,EAC1B,WAAW,EAAE,WAAW,IAAI,UAAU,EACtC,OAAO,EAAE,OAAO,YAEf,QAAQ,GACE,CACd,CAAC;AACJ,CAAC","sourcesContent":["import {\n type ComponentType,\n type CSSProperties,\n type HTMLAttributes,\n type PropsWithChildren,\n type MouseEvent as ReactMouseEvent,\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport \"./Window.css\";\nimport { CurrentWindowProvider } from \"./CurrentWindowContext\";\nimport { useWindowGeometryMenu } from \"./useWindowFit\";\nimport { useWindowGeometry } from \"./useWindowGeometry\";\nimport { useFocusWindowOnShow } from \"./useWindowKeyboardGeometry\";\nimport { WindowBody } from \"./WindowBody\";\nimport { WindowMenuBar, type WindowMenuItem } from \"./WindowMenuBar\";\nimport {\n useWindowFileMenuItems,\n useWindowViewMenuItems,\n WindowMenuProvider,\n} from \"./WindowMenuContext\";\nimport { WindowResizeHandles } from \"./WindowResizeHandle\";\nimport {\n hasWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./WindowSidebarContext\";\nimport {\n findTopWindow,\n useWindowActions as useWindowStateActions,\n useWindowStateData,\n type WindowEntry,\n type WindowPosition,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport { WindowStatusBar } from \"./WindowStatusBar\";\nimport { WindowTitleBar } from \"./WindowTitleBar\";\nimport { WindowToolBar } from \"./WindowToolBar\";\n\n// Wraps a window's content so the host can give it app-specific context (a\n// route, an error boundary) without the window layer knowing about apps.\nexport type WindowContentBoundary = ComponentType<\n PropsWithChildren<{ entry: WindowEntry }>\n>;\n\ninterface WindowProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n /**\n * Whether the toolbar offers Back through the window's own route history,\n * reserving its row from the start (see `WindowToolBar`). Defaults to whether\n * the window has an `appId`. Pass false for an app that never routes, so its\n * window has no toolbar row until the app first registers toolbar actions.\n */\n historyBack?: boolean | undefined;\n windowId: string;\n}\n\nconst WINDOW_STATUS_MESSAGE_DURATION_MS = 2500;\n\nexport function Window({\n ContentBoundary,\n historyBack,\n windowId,\n}: WindowProps) {\n const { windowMap, windows } = useWindowStateData();\n const entry = windowMap.get(windowId);\n const isTop =\n findTopWindow(windows, (candidate) => !candidate.minimized)?.id ===\n windowId;\n\n if (!entry) return null;\n\n return (\n <WindowInner\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack ?? entry.appId !== undefined}\n isTop={isTop}\n />\n );\n}\n\nfunction useWindowActions(\n entry: WindowEntry,\n fileMenuItems: WindowMenuItem[],\n viewMenuItems: WindowMenuItem[],\n geometryMenuItems: WindowMenuItem[],\n hasSidebar: boolean,\n) {\n const { close, minimize, moveBackward, moveForward, toggleMaximize } =\n useWindowStateActions();\n const [showStatusBar, setShowStatusBar] = useState(true);\n const [showSidebar, setShowSidebar] = useState(\n entry.initialShowSidebar ?? true,\n );\n const handleClose = useCallback(() => close(entry.id), [close, entry.id]);\n const handleMinimize = useCallback(\n () => minimize(entry.id),\n [entry.id, minimize],\n );\n const handleMoveForward = useCallback(\n () => moveForward(entry.id),\n [entry.id, moveForward],\n );\n const handleMoveBackward = useCallback(\n () => moveBackward(entry.id),\n [entry.id, moveBackward],\n );\n const handleMaximize = useCallback(\n () => toggleMaximize(entry.id),\n [entry.id, toggleMaximize],\n );\n const toggleStatusBar = useCallback(\n () => setShowStatusBar((previous) => !previous),\n [],\n );\n const toggleSidebar = useCallback(\n () => setShowSidebar((previous) => !previous),\n [],\n );\n const menus = useMemo(\n () => [\n {\n label: \"File\",\n items: [\n ...fileMenuItems,\n { id: \"close\", label: \"Close\", onClick: handleClose },\n ],\n },\n {\n label: \"View\",\n items: [\n ...viewMenuItems,\n ...geometryMenuItems,\n {\n id: \"toggle-status-bar\",\n label: `${showStatusBar ? \"Hide\" : \"Show\"} Status Bar`,\n onClick: toggleStatusBar,\n },\n ...(hasSidebar\n ? [\n {\n id: \"toggle-sidebar\",\n label: `${showSidebar ? \"Hide\" : \"Show\"} Sidebar`,\n onClick: toggleSidebar,\n },\n ]\n : []),\n ],\n },\n ],\n [\n geometryMenuItems,\n hasSidebar,\n handleClose,\n fileMenuItems,\n showSidebar,\n showStatusBar,\n toggleSidebar,\n toggleStatusBar,\n viewMenuItems,\n ],\n );\n\n return {\n handleClose,\n handleMaximize,\n handleMinimize,\n handleMoveBackward,\n handleMoveForward,\n menus,\n showSidebar,\n showStatusBar,\n };\n}\n\n// The window paints with `--window-background`, which a background its content\n// sets (see `useWindowBackground`) overrides inline.\ninterface WindowStyle extends CSSProperties {\n \"--window-background\"?: string | undefined;\n}\n\nfunction getWindowFrameStyle(\n maximized: boolean,\n position: WindowPosition | null,\n size: WindowSize | null,\n zIndex: number,\n): CSSProperties {\n if (maximized) {\n return { top: 0, left: 0, width: \"100%\", height: \"100%\", zIndex };\n }\n if (!position) {\n // Hidden until laid out; a requested size applies already so the first\n // clamp measures the window at the size it will show.\n return {\n visibility: \"hidden\",\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n }\n\n return {\n left: position.x,\n top: position.y,\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n}\n\nfunction getWindowStyle(\n maximized: boolean,\n position: WindowPosition | null,\n size: WindowSize | null,\n zIndex: number,\n background: string | undefined,\n): WindowStyle {\n return {\n ...getWindowFrameStyle(maximized, position, size, zIndex),\n \"--window-background\": background,\n };\n}\n\nfunction useWindowStatusMessage() {\n const [statusText, setStatusText] = useState(\"\");\n const statusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const showStatusMessage = useCallback((message: string) => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n setStatusText(message);\n statusTimeoutRef.current = setTimeout(() => {\n setStatusText(\"\");\n statusTimeoutRef.current = null;\n }, WINDOW_STATUS_MESSAGE_DURATION_MS);\n }, []);\n\n useEffect(() => {\n return () => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n };\n }, []);\n\n return { showStatusMessage, statusText };\n}\n\n// Refcounted so overlapping overlays (one closing as another opens) never leave\n// the row hidden, and never flash it back for a frame between the two.\nfunction useWindowToolbarSuppression() {\n const [suppressionCount, setSuppressionCount] = useState(0);\n const suppressToolbar = useCallback(() => {\n setSuppressionCount((count) => count + 1);\n return () => setSuppressionCount((count) => Math.max(0, count - 1));\n }, []);\n\n return { suppressToolbar, toolbarSuppressed: suppressionCount > 0 };\n}\n\ninterface WindowInnerProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n entry: WindowEntry;\n historyBack: boolean;\n // Whether this is the foremost visible window, the one that takes focus.\n isTop: boolean;\n}\n\nfunction WindowInner({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n return (\n <WindowMenuProvider>\n <WindowSidebarProvider>\n <WindowInnerContent\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack}\n isTop={isTop}\n />\n </WindowSidebarProvider>\n </WindowMenuProvider>\n );\n}\n\n// The bars above the body: title, menus, and the toolbar row a full-pane overlay\n// can stand down (see `useWindowToolbarSuppression`).\nfunction WindowChrome({\n actions,\n entry,\n historyBack,\n onGoBack,\n onPointerDown,\n titleId,\n toolbarSuppressed,\n}: {\n actions: ReturnType<typeof useWindowActions>;\n entry: WindowEntry;\n historyBack: boolean;\n onGoBack: () => void;\n onPointerDown: (event: ReactPointerEvent) => void;\n titleId: string;\n toolbarSuppressed: boolean;\n}) {\n return (\n <>\n <WindowTitleBar\n title={entry.title}\n titleId={titleId}\n onPointerDown={onPointerDown}\n onMinimize={actions.handleMinimize}\n onMaximize={actions.handleMaximize}\n onClose={actions.handleClose}\n onMoveForward={actions.handleMoveForward}\n onMoveBackward={actions.handleMoveBackward}\n />\n <WindowMenuBar menus={actions.menus} />\n {!toolbarSuppressed && (\n <WindowToolBar\n canGoBack={(entry.routeHistory?.length ?? 0) > 0}\n showHistoryBack={historyBack}\n onGoBack={onGoBack}\n />\n )}\n </>\n );\n}\n\n// Handlers on the window root: its Back caret, raising it on any press inside,\n// and keeping background context menus from opening under window-local ones.\nfunction useWindowRootHandlers(windowId: string) {\n // The toolbar renders above the route boundary, so the window's own Back stack\n // is threaded in from here rather than read from context.\n const { bringToFront, goBackRoute } = useWindowStateActions();\n const handleGoBack = useCallback(() => {\n goBackRoute(windowId);\n }, [windowId, goBackRoute]);\n const handleWindowPointerDown = useCallback(() => {\n bringToFront(windowId);\n }, [bringToFront, windowId]);\n const handleWindowContextMenu = useCallback((event: ReactMouseEvent) => {\n // Keep background pane context menus from opening underneath window-local menus.\n event.stopPropagation();\n }, []);\n const windowContextMenuTrapProps: Pick<\n HTMLAttributes<HTMLElement>,\n \"onContextMenu\"\n > = {\n onContextMenu: handleWindowContextMenu,\n };\n\n return { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps };\n}\n\nfunction WindowInnerContent({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n const { maximized, minimized, zIndex, component: Component } = entry;\n const windowRef = useRef<HTMLElement>(null);\n const titleId = useId();\n const [overlayHost, setOverlayHost] = useState<HTMLElement | null>(null);\n const [background, setBackground] = useState<string | undefined>();\n const fileMenuItems = useWindowFileMenuItems();\n const viewMenuItems = useWindowViewMenuItems();\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n const {\n handlePointerDown,\n handleResizePointerDown,\n position,\n size,\n ...stepped\n } = useWindowGeometry(entry, maximized, windowRef);\n const { showStatusMessage, statusText } = useWindowStatusMessage();\n const { geometryMenuItems, setContentSize } = useWindowGeometryMenu(\n entry,\n stepped,\n { overlayHost, windowRef },\n showStatusMessage,\n );\n const actions = useWindowActions(\n entry,\n fileMenuItems,\n viewMenuItems,\n geometryMenuItems,\n hasSidebar,\n );\n // A maximized window fills its surface without a laid-out position.\n useFocusWindowOnShow(windowRef, {\n isTop,\n shown: !minimized && (maximized || position !== null),\n });\n const { suppressToolbar, toolbarSuppressed } = useWindowToolbarSuppression();\n const { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps } =\n useWindowRootHandlers(entry.id);\n const style = getWindowStyle(maximized, position, size, zIndex, background);\n\n if (minimized) {\n return null;\n }\n\n // A section labelled by its title is a region landmark. Windows are\n // non-modal and freely arranged, so they are not dialogs; hosts keep that\n // role for the modals they open inside a window.\n return (\n <section\n ref={windowRef}\n aria-labelledby={titleId}\n className={maximized ? \"window window--maximized\" : \"window\"}\n tabIndex={-1}\n {...windowContextMenuTrapProps}\n onPointerDownCapture={handleWindowPointerDown}\n style={style}\n >\n <WindowChrome\n actions={actions}\n entry={entry}\n historyBack={historyBack}\n onGoBack={handleGoBack}\n onPointerDown={handlePointerDown}\n titleId={titleId}\n toolbarSuppressed={toolbarSuppressed}\n />\n <CurrentWindowProvider\n close={actions.handleClose}\n id={entry.id}\n overlayHost={overlayHost}\n setBackground={setBackground}\n setContentSize={setContentSize}\n showStatusMessage={showStatusMessage}\n suppressToolbar={suppressToolbar}\n >\n <WindowBodyWithSidebar\n overlayHostRef={setOverlayHost}\n showSidebar={actions.showSidebar}\n >\n {ContentBoundary ? (\n <ContentBoundary entry={entry}>\n {Component && <Component />}\n </ContentBoundary>\n ) : (\n Component && <Component />\n )}\n </WindowBodyWithSidebar>\n </CurrentWindowProvider>\n <WindowStatusBar text={statusText} visible={actions.showStatusBar} />\n {!maximized && (\n <WindowResizeHandles\n handleResizePointerDown={handleResizePointerDown}\n />\n )}\n </section>\n );\n}\n\nfunction WindowBodyWithSidebar({\n showSidebar,\n overlayHostRef,\n children,\n}: PropsWithChildren<{\n overlayHostRef: (element: HTMLDivElement | null) => void;\n showSidebar: boolean;\n}>) {\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n\n return (\n <WindowBody\n contentRef={overlayHostRef}\n showSidebar={showSidebar && hasSidebar}\n sidebar={sidebar}\n >\n {children}\n </WindowBody>\n );\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import { useWindowGeometryMenuItems } from "./useWindowKeyboardGeometry.js";
|
|
3
|
+
import type { WindowMenuItem } from "./WindowMenuBar.js";
|
|
4
|
+
import { type WindowEntry, type WindowSize } from "./WindowStateProvider/index.js";
|
|
5
|
+
interface WindowFitHost {
|
|
6
|
+
overlayHost: HTMLElement | null;
|
|
7
|
+
windowRef: RefObject<HTMLElement | null>;
|
|
8
|
+
}
|
|
9
|
+
export declare function useWindowGeometryMenu(entry: WindowEntry, stepped: Parameters<typeof useWindowGeometryMenuItems>[0], host: WindowFitHost, announce: (message: string) => void): {
|
|
10
|
+
geometryMenuItems: WindowMenuItem[];
|
|
11
|
+
setContentSize: import("react").Dispatch<import("react").SetStateAction<WindowSize | undefined>>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from "react";
|
|
2
|
+
import { useWindowGeometryMenuItems } from "./useWindowKeyboardGeometry.js";
|
|
3
|
+
import { useWindowActions, } from "./WindowStateProvider/index.js";
|
|
4
|
+
import { fitWindowGeometry } from "./windowGeometry.js";
|
|
5
|
+
const SCROLL_PANE_SELECTOR = ":scope > .window-body-content-scroll, :scope > .window-sidebar-content-scroll";
|
|
6
|
+
// The pane's scrollbars, forced on before its own overflow is put back. Layout
|
|
7
|
+
// is read between the writes, so nothing is painted meanwhile.
|
|
8
|
+
function measureScrollbars(pane) {
|
|
9
|
+
const { overflow } = pane.style;
|
|
10
|
+
pane.style.overflow = "scroll";
|
|
11
|
+
const scrollbar = {
|
|
12
|
+
height: pane.offsetHeight - pane.clientHeight,
|
|
13
|
+
width: pane.offsetWidth - pane.clientWidth,
|
|
14
|
+
};
|
|
15
|
+
pane.style.overflow = overflow;
|
|
16
|
+
return scrollbar;
|
|
17
|
+
}
|
|
18
|
+
function measureWindowFit(windowElement, pane) {
|
|
19
|
+
const frame = windowElement.getBoundingClientRect();
|
|
20
|
+
const paneRect = pane.getBoundingClientRect();
|
|
21
|
+
const style = getComputedStyle(pane);
|
|
22
|
+
const px = (value) => Number.parseFloat(value) || 0;
|
|
23
|
+
return {
|
|
24
|
+
chrome: {
|
|
25
|
+
height: frame.height - paneRect.height,
|
|
26
|
+
width: frame.width - paneRect.width,
|
|
27
|
+
},
|
|
28
|
+
padding: {
|
|
29
|
+
height: px(style.paddingTop) + px(style.paddingBottom),
|
|
30
|
+
width: px(style.paddingLeft) + px(style.paddingRight),
|
|
31
|
+
},
|
|
32
|
+
scrollbar: measureScrollbars(pane),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// Fit to Content, offered in the View menu while the window's content has a
|
|
36
|
+
// natural size (see `useWindowContentSize`). It measures the window's chrome
|
|
37
|
+
// as rendered, so it allows for whichever bars and sidebar show, and restores
|
|
38
|
+
// a maximized window first.
|
|
39
|
+
function useWindowFit(entry, { overlayHost, windowRef }) {
|
|
40
|
+
const { setGeometry, toggleMaximize } = useWindowActions();
|
|
41
|
+
const [contentSize, setContentSize] = useState();
|
|
42
|
+
const { id, maximized, position } = entry;
|
|
43
|
+
const fitToContent = useCallback(() => {
|
|
44
|
+
const element = windowRef.current;
|
|
45
|
+
const surface = element?.parentElement;
|
|
46
|
+
const pane = overlayHost?.querySelector(SCROLL_PANE_SELECTOR);
|
|
47
|
+
if (!contentSize || !element || !surface || !pane) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const geometry = fitWindowGeometry(contentSize, measureWindowFit(element, pane), { height: surface.clientHeight, width: surface.clientWidth }, position ?? { x: 0, y: 0 });
|
|
51
|
+
if (maximized) {
|
|
52
|
+
toggleMaximize(id);
|
|
53
|
+
}
|
|
54
|
+
setGeometry(id, geometry);
|
|
55
|
+
}, [
|
|
56
|
+
contentSize,
|
|
57
|
+
id,
|
|
58
|
+
maximized,
|
|
59
|
+
overlayHost,
|
|
60
|
+
position,
|
|
61
|
+
setGeometry,
|
|
62
|
+
toggleMaximize,
|
|
63
|
+
windowRef,
|
|
64
|
+
]);
|
|
65
|
+
const fitMenuItems = useMemo(() => contentSize
|
|
66
|
+
? [
|
|
67
|
+
{
|
|
68
|
+
id: "fit-to-content",
|
|
69
|
+
label: "Fit to Content",
|
|
70
|
+
onClick: fitToContent,
|
|
71
|
+
},
|
|
72
|
+
]
|
|
73
|
+
: [], [contentSize, fitToContent]);
|
|
74
|
+
return { fitMenuItems, setContentSize };
|
|
75
|
+
}
|
|
76
|
+
// The View menu's geometry entries: keyboard move and resize, then Fit to
|
|
77
|
+
// Content while the content has a natural size.
|
|
78
|
+
export function useWindowGeometryMenu(entry, stepped, host, announce) {
|
|
79
|
+
const keyboardItems = useWindowGeometryMenuItems(stepped, {
|
|
80
|
+
maximized: entry.maximized,
|
|
81
|
+
minimized: entry.minimized,
|
|
82
|
+
windowRef: host.windowRef,
|
|
83
|
+
}, announce);
|
|
84
|
+
const { fitMenuItems, setContentSize } = useWindowFit(entry, host);
|
|
85
|
+
const geometryMenuItems = useMemo(() => [...keyboardItems, ...fitMenuItems], [fitMenuItems, keyboardItems]);
|
|
86
|
+
return { geometryMenuItems, setContentSize };
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=useWindowFit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWindowFit.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/useWindowFit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAEzE,OAAO,EACL,gBAAgB,GAGjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAyB,MAAM,kBAAkB,CAAC;AAE5E,MAAM,oBAAoB,GACxB,+EAA+E,CAAC;AAElF,+EAA+E;AAC/E,+DAA+D;AAC/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B,KAAK,EAAE,gBAAgB;gBACvB,OAAO,EAAE,YAAY;aACtB;SACF;QACH,CAAC,CAAC,EAAE,EACR,CAAC,WAAW,EAAE,YAAY,CAAC,CAC5B,CAAC;IAEF,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC;AAC1C,CAAC;AAED,0EAA0E;AAC1E,gDAAgD;AAChD,MAAM,UAAU,qBAAqB,CACnC,KAAkB,EAClB,OAAyD,EACzD,IAAmB,EACnB,QAAmC;IAEnC,MAAM,aAAa,GAAG,0BAA0B,CAC9C,OAAO,EACP;QACE,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,EACD,QAAQ,CACT,CAAC;IACF,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,GAAG,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnE,MAAM,iBAAiB,GAAG,OAAO,CAC/B,GAAG,EAAE,CAAC,CAAC,GAAG,aAAa,EAAE,GAAG,YAAY,CAAC,EACzC,CAAC,YAAY,EAAE,aAAa,CAAC,CAC9B,CAAC;IAEF,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,CAAC;AAC/C,CAAC","sourcesContent":["import { type RefObject, useCallback, useMemo, useState } from \"react\";\nimport { useWindowGeometryMenuItems } from \"./useWindowKeyboardGeometry\";\nimport type { WindowMenuItem } from \"./WindowMenuBar\";\nimport {\n useWindowActions,\n type WindowEntry,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport { fitWindowGeometry, type WindowFitMetrics } from \"./windowGeometry\";\n\nconst SCROLL_PANE_SELECTOR =\n \":scope > .window-body-content-scroll, :scope > .window-sidebar-content-scroll\";\n\n// The pane's scrollbars, forced on before its own overflow is put back. Layout\n// is read between the writes, so nothing is painted meanwhile.\nfunction measureScrollbars(pane: HTMLElement): WindowSize {\n const { overflow } = pane.style;\n pane.style.overflow = \"scroll\";\n const scrollbar = {\n height: pane.offsetHeight - pane.clientHeight,\n width: pane.offsetWidth - pane.clientWidth,\n };\n pane.style.overflow = overflow;\n return scrollbar;\n}\n\nfunction measureWindowFit(\n windowElement: HTMLElement,\n pane: HTMLElement,\n): WindowFitMetrics {\n const frame = windowElement.getBoundingClientRect();\n const paneRect = pane.getBoundingClientRect();\n const style = getComputedStyle(pane);\n const px = (value: string) => Number.parseFloat(value) || 0;\n\n return {\n chrome: {\n height: frame.height - paneRect.height,\n width: frame.width - paneRect.width,\n },\n padding: {\n height: px(style.paddingTop) + px(style.paddingBottom),\n width: px(style.paddingLeft) + px(style.paddingRight),\n },\n scrollbar: measureScrollbars(pane),\n };\n}\n\ninterface WindowFitHost {\n overlayHost: HTMLElement | null;\n windowRef: RefObject<HTMLElement | null>;\n}\n\n// Fit to Content, offered in the View menu while the window's content has a\n// natural size (see `useWindowContentSize`). It measures the window's chrome\n// as rendered, so it allows for whichever bars and sidebar show, and restores\n// a maximized window first.\nfunction useWindowFit(\n entry: WindowEntry,\n { overlayHost, windowRef }: WindowFitHost,\n) {\n const { setGeometry, toggleMaximize } = useWindowActions();\n const [contentSize, setContentSize] = useState<WindowSize | undefined>();\n const { id, maximized, position } = entry;\n\n const fitToContent = useCallback(() => {\n const element = windowRef.current;\n const surface = element?.parentElement;\n const pane = overlayHost?.querySelector<HTMLElement>(SCROLL_PANE_SELECTOR);\n if (!contentSize || !element || !surface || !pane) {\n return;\n }\n const geometry = fitWindowGeometry(\n contentSize,\n measureWindowFit(element, pane),\n { height: surface.clientHeight, width: surface.clientWidth },\n position ?? { x: 0, y: 0 },\n );\n if (maximized) {\n toggleMaximize(id);\n }\n setGeometry(id, geometry);\n }, [\n contentSize,\n id,\n maximized,\n overlayHost,\n position,\n setGeometry,\n toggleMaximize,\n windowRef,\n ]);\n\n const fitMenuItems = useMemo<WindowMenuItem[]>(\n () =>\n contentSize\n ? [\n {\n id: \"fit-to-content\",\n label: \"Fit to Content\",\n onClick: fitToContent,\n },\n ]\n : [],\n [contentSize, fitToContent],\n );\n\n return { fitMenuItems, setContentSize };\n}\n\n// The View menu's geometry entries: keyboard move and resize, then Fit to\n// Content while the content has a natural size.\nexport function useWindowGeometryMenu(\n entry: WindowEntry,\n stepped: Parameters<typeof useWindowGeometryMenuItems>[0],\n host: WindowFitHost,\n announce: (message: string) => void,\n) {\n const keyboardItems = useWindowGeometryMenuItems(\n stepped,\n {\n maximized: entry.maximized,\n minimized: entry.minimized,\n windowRef: host.windowRef,\n },\n announce,\n );\n const { fitMenuItems, setContentSize } = useWindowFit(entry, host);\n const geometryMenuItems = useMemo(\n () => [...keyboardItems, ...fitMenuItems],\n [fitMenuItems, keyboardItems],\n );\n\n return { geometryMenuItems, setContentSize };\n}\n"]}
|
|
@@ -34,3 +34,12 @@ export declare function resizeWindowWithinContainer(resizeState: WindowResizeSta
|
|
|
34
34
|
height: number;
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
|
+
export interface WindowFitMetrics {
|
|
38
|
+
chrome: WindowSize;
|
|
39
|
+
padding: WindowSize;
|
|
40
|
+
scrollbar: WindowSize;
|
|
41
|
+
}
|
|
42
|
+
export declare function fitWindowGeometry(content: WindowSize, { chrome, padding, scrollbar }: WindowFitMetrics, surface: WindowSize, position: WindowPosition): {
|
|
43
|
+
position: WindowPosition;
|
|
44
|
+
size: WindowSize;
|
|
45
|
+
};
|
package/window/windowGeometry.js
CHANGED
|
@@ -55,4 +55,31 @@ export function resizeWindowWithinContainer(resizeState, clientX, clientY, conta
|
|
|
55
55
|
size: { width, height },
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
+
// The geometry that shows `content` whole where the surface has room, then
|
|
59
|
+
// moves the window as far as it must to stay on the surface. The width always
|
|
60
|
+
// allows for a vertical scrollbar, even for content that fits: a status message
|
|
61
|
+
// takes height from the body while it shows, and content that then scrolled
|
|
62
|
+
// would lose width to the scrollbar, reflowing a layout that depends on it.
|
|
63
|
+
// Content wider than the surface also scrolls sideways, so that scrollbar takes
|
|
64
|
+
// height.
|
|
65
|
+
export function fitWindowGeometry(content, { chrome, padding, scrollbar }, surface, position) {
|
|
66
|
+
const width = chrome.width + padding.width + content.width + scrollbar.width;
|
|
67
|
+
const scrollsAcross = width > surface.width;
|
|
68
|
+
const height = chrome.height +
|
|
69
|
+
padding.height +
|
|
70
|
+
content.height +
|
|
71
|
+
(scrollsAcross ? scrollbar.height : 0);
|
|
72
|
+
const fit = (natural, available, minimum) => Math.max(minimum, Math.min(available, Math.ceil(natural)));
|
|
73
|
+
const size = {
|
|
74
|
+
width: fit(width, surface.width, MIN_WIDTH),
|
|
75
|
+
height: fit(height, surface.height, MIN_HEIGHT),
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
position: {
|
|
79
|
+
x: Math.max(0, Math.min(position.x, surface.width - size.width)),
|
|
80
|
+
y: Math.max(0, Math.min(position.y, surface.height - size.height)),
|
|
81
|
+
},
|
|
82
|
+
size,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
58
85
|
//# sourceMappingURL=windowGeometry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"windowGeometry.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/windowGeometry.ts"],"names":[],"mappings":"AAGA,8EAA8E;AAC9E,2DAA2D;AAE3D,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAC;AAC7B,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC;AA0B9B,6EAA6E;AAC7E,0EAA0E;AAC1E,MAAM,UAAU,mBAAmB,CACjC,OAA2B,EAC3B,CAAS,EACT,CAAS,EACT,IAAuB;IAEvB,MAAM,SAAS,GAAG,OAAO,EAAE,aAAa,CAAC;IACzC,IAAI,CAAC,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;QAC3B,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAClB,CAAC;IACD,sEAAsE;IACtE,MAAM,KAAK,GAAG,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AC,CAAC;QACnC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE;QAClB,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;KACxB,CAAC;AACJ,CAAC","sourcesContent":["import type { ResizeEdge } from \"./WindowResizeHandle\";\nimport type { WindowPosition, WindowSize } from \"./WindowStateProvider\";\n\n// Window geometry math shared by the pointer, keyboard, and layout hooks. All\n// positions and sizes are relative to the desktop surface.\n\nexport const MIN_WIDTH = 200;\nexport const MIN_HEIGHT = 100;\n\nexport interface WindowDragState {\n offsetX: number;\n offsetY: number;\n pointerId: number;\n}\n\nexport interface WindowResizeState {\n edge: ResizeEdge;\n pointerId: number;\n startHeight: number;\n startLeft: number;\n startTop: number;\n startWidth: number;\n startX: number;\n startY: number;\n borderX: number;\n borderY: number;\n}\n\nexport interface LiveGeometry {\n position: WindowPosition | null;\n size: WindowSize | null;\n}\n\n// Clamps against the size the window is about to render at when it is known,\n// so a position committed with a new size is not measured at the old one.\nexport function clampWindowPosition(\n element: HTMLElement | null,\n x: number,\n y: number,\n size: WindowSize | null,\n): WindowPosition {\n const container = element?.parentElement;\n if (!element || !container) {\n return { x, y };\n }\n // A requested size renders no smaller than the stylesheet's minimums.\n const width = size ? Math.max(MIN_WIDTH, size.width) : element.offsetWidth;\n const height = size\n ? Math.max(MIN_HEIGHT, size.height)\n : element.offsetHeight;\n\n return {\n x: Math.max(0, Math.min(x, container.clientWidth - width)),\n y: Math.max(0, Math.min(y, container.clientHeight - height)),\n };\n}\n\nexport function resizeWindowWithinContainer(\n resizeState: WindowResizeState,\n clientX: number,\n clientY: number,\n container: HTMLElement | null,\n) {\n const deltaX = clientX - resizeState.startX;\n const deltaY = clientY - resizeState.startY;\n const { edge } = resizeState;\n const movesLeft = edge.includes(\"w\");\n const movesUp = edge.includes(\"n\");\n // A side handle drags one edge, so the other axis keeps its start size.\n const resizesX = movesLeft || edge.includes(\"e\");\n const resizesY = movesUp || edge.includes(\"s\");\n let width = Math.max(\n MIN_WIDTH,\n resizeState.startWidth + (resizesX ? deltaX * (movesLeft ? -1 : 1) : 0),\n );\n let height = Math.max(\n MIN_HEIGHT,\n resizeState.startHeight + (resizesY ? deltaY * (movesUp ? -1 : 1) : 0),\n );\n let x = movesLeft\n ? resizeState.startLeft + resizeState.startWidth - width\n : resizeState.startLeft;\n let y = movesUp\n ? resizeState.startTop + resizeState.startHeight - height\n : resizeState.startTop;\n\n if (container) {\n if (x < 0) {\n width += x;\n x = 0;\n }\n if (y < 0) {\n height += y;\n y = 0;\n }\n width = Math.min(width, container.clientWidth - x - resizeState.borderX);\n height = Math.min(height, container.clientHeight - y - resizeState.borderY);\n width = Math.max(MIN_WIDTH, width);\n height = Math.max(MIN_HEIGHT, height);\n }\n\n return {\n position: { x, y },\n size: { width, height },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"windowGeometry.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/windowGeometry.ts"],"names":[],"mappings":"AAGA,8EAA8E;AAC9E,2DAA2D;AAE3D,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAC;AAC7B,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC;AA0B9B,6EAA6E;AAC7E,0EAA0E;AAC1E,MAAM,UAAU,mBAAmB,CACjC,OAA2B,EAC3B,CAAS,EACT,CAAS,EACT,IAAuB;IAEvB,MAAM,SAAS,GAAG,OAAO,EAAE,aAAa,CAAC;IACzC,IAAI,CAAC,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;QAC3B,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAClB,CAAC;IACD,sEAAsE;IACtE,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,C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AQ,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YAChE,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;SACnE;QACD,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["import type { ResizeEdge } from \"./WindowResizeHandle\";\nimport type { WindowPosition, WindowSize } from \"./WindowStateProvider\";\n\n// Window geometry math shared by the pointer, keyboard, and layout hooks. All\n// positions and sizes are relative to the desktop surface.\n\nexport const MIN_WIDTH = 200;\nexport const MIN_HEIGHT = 100;\n\nexport interface WindowDragState {\n offsetX: number;\n offsetY: number;\n pointerId: number;\n}\n\nexport interface WindowResizeState {\n edge: ResizeEdge;\n pointerId: number;\n startHeight: number;\n startLeft: number;\n startTop: number;\n startWidth: number;\n startX: number;\n startY: number;\n borderX: number;\n borderY: number;\n}\n\nexport interface LiveGeometry {\n position: WindowPosition | null;\n size: WindowSize | null;\n}\n\n// Clamps against the size the window is about to render at when it is known,\n// so a position committed with a new size is not measured at the old one.\nexport function clampWindowPosition(\n element: HTMLElement | null,\n x: number,\n y: number,\n size: WindowSize | null,\n): WindowPosition {\n const container = element?.parentElement;\n if (!element || !container) {\n return { x, y };\n }\n // A requested size renders no smaller than the stylesheet's minimums.\n const width = size ? Math.max(MIN_WIDTH, size.width) : element.offsetWidth;\n const height = size\n ? Math.max(MIN_HEIGHT, size.height)\n : element.offsetHeight;\n\n return {\n x: Math.max(0, Math.min(x, container.clientWidth - width)),\n y: Math.max(0, Math.min(y, container.clientHeight - height)),\n };\n}\n\nexport function resizeWindowWithinContainer(\n resizeState: WindowResizeState,\n clientX: number,\n clientY: number,\n container: HTMLElement | null,\n) {\n const deltaX = clientX - resizeState.startX;\n const deltaY = clientY - resizeState.startY;\n const { edge } = resizeState;\n const movesLeft = edge.includes(\"w\");\n const movesUp = edge.includes(\"n\");\n // A side handle drags one edge, so the other axis keeps its start size.\n const resizesX = movesLeft || edge.includes(\"e\");\n const resizesY = movesUp || edge.includes(\"s\");\n let width = Math.max(\n MIN_WIDTH,\n resizeState.startWidth + (resizesX ? deltaX * (movesLeft ? -1 : 1) : 0),\n );\n let height = Math.max(\n MIN_HEIGHT,\n resizeState.startHeight + (resizesY ? deltaY * (movesUp ? -1 : 1) : 0),\n );\n let x = movesLeft\n ? resizeState.startLeft + resizeState.startWidth - width\n : resizeState.startLeft;\n let y = movesUp\n ? resizeState.startTop + resizeState.startHeight - height\n : resizeState.startTop;\n\n if (container) {\n if (x < 0) {\n width += x;\n x = 0;\n }\n if (y < 0) {\n height += y;\n y = 0;\n }\n width = Math.min(width, container.clientWidth - x - resizeState.borderX);\n height = Math.min(height, container.clientHeight - y - resizeState.borderY);\n width = Math.max(MIN_WIDTH, width);\n height = Math.max(MIN_HEIGHT, height);\n }\n\n return {\n position: { x, y },\n size: { width, height },\n };\n}\n\n// What a window adds around its content's natural size, measured from the\n// rendered window (see `useWindowFit`): `scrollbar` is what the scroll pane's\n// scrollbars take on each axis, the vertical one's width and the horizontal\n// one's height.\nexport interface WindowFitMetrics {\n // The window's size less its scroll pane's, so borders, bars, and a sidebar.\n chrome: WindowSize;\n padding: WindowSize;\n scrollbar: WindowSize;\n}\n\n// The geometry that shows `content` whole where the surface has room, then\n// moves the window as far as it must to stay on the surface. The width always\n// allows for a vertical scrollbar, even for content that fits: a status message\n// takes height from the body while it shows, and content that then scrolled\n// would lose width to the scrollbar, reflowing a layout that depends on it.\n// Content wider than the surface also scrolls sideways, so that scrollbar takes\n// height.\nexport function fitWindowGeometry(\n content: WindowSize,\n { chrome, padding, scrollbar }: WindowFitMetrics,\n surface: WindowSize,\n position: WindowPosition,\n): { position: WindowPosition; size: WindowSize } {\n const width = chrome.width + padding.width + content.width + scrollbar.width;\n const scrollsAcross = width > surface.width;\n const height =\n chrome.height +\n padding.height +\n content.height +\n (scrollsAcross ? scrollbar.height : 0);\n const fit = (natural: number, available: number, minimum: number) =>\n Math.max(minimum, Math.min(available, Math.ceil(natural)));\n const size = {\n width: fit(width, surface.width, MIN_WIDTH),\n height: fit(height, surface.height, MIN_HEIGHT),\n };\n\n return {\n position: {\n x: Math.max(0, Math.min(position.x, surface.width - size.width)),\n y: Math.max(0, Math.min(position.y, surface.height - size.height)),\n },\n size,\n };\n}\n"]}
|