@tearleads/windowing 0.2.6 → 0.2.7
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 +8 -0
- package/package.json +1 -1
- package/window/CurrentWindowContext.d.ts +8 -1
- package/window/CurrentWindowContext.js +3 -1
- package/window/CurrentWindowContext.js.map +1 -1
- package/window/Window.js +2 -2
- package/window/Window.js.map +1 -1
- package/window/WindowStateProvider/types.d.ts +2 -0
- package/window/WindowStateProvider/types.js.map +1 -1
- package/window/WindowStateProvider/util/createWindowEntry.js +1 -0
- package/window/WindowStateProvider/util/createWindowEntry.js.map +1 -1
- package/window/useWindowFit.d.ts +4 -1
- package/window/useWindowFit.js +62 -7
- package/window/useWindowFit.js.map +1 -1
package/README.md
CHANGED
|
@@ -79,6 +79,14 @@ content keeps its width even when a status message briefly takes height from
|
|
|
79
79
|
the body. Last, the window moves as far as it must to stay on the surface.
|
|
80
80
|
`undefined` withdraws the item.
|
|
81
81
|
|
|
82
|
+
To open a window already fitted, pass `fitToContent: true` to `create`. The
|
|
83
|
+
window fits once, as Fit to Content would, when its content has loaded and
|
|
84
|
+
reported its size. Content reports its load by calling
|
|
85
|
+
`useCurrentWindow()?.markContentLoaded?.()`, for example once a page has
|
|
86
|
+
rendered. A later call does nothing. A window that is maximized when its
|
|
87
|
+
content loads, as a host might open it on a narrow screen, stays maximized,
|
|
88
|
+
and a window on a hidden surface fits once the surface shows.
|
|
89
|
+
|
|
82
90
|
## Slots
|
|
83
91
|
|
|
84
92
|
- **`ContentBoundary`** — `Window` renders a window's component inside this
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tearleads/windowing",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
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": {
|
|
@@ -3,6 +3,13 @@ import type { WindowSize } from "./WindowStateProvider/index.js";
|
|
|
3
3
|
interface CurrentWindowContextValue {
|
|
4
4
|
close: () => void;
|
|
5
5
|
id: string;
|
|
6
|
+
/**
|
|
7
|
+
* Tell the window its content has loaded. A window opened with
|
|
8
|
+
* `fitToContent` fits then, once the content has reported its size; later
|
|
9
|
+
* calls do nothing. Hosts that render this provider outside a `Window` may
|
|
10
|
+
* omit it.
|
|
11
|
+
*/
|
|
12
|
+
markContentLoaded?: (() => void) | undefined;
|
|
6
13
|
overlayHost: HTMLElement | null;
|
|
7
14
|
/**
|
|
8
15
|
* Paint the window's background with `background`, any CSS color, in place of
|
|
@@ -23,7 +30,7 @@ interface CurrentWindowContextValue {
|
|
|
23
30
|
*/
|
|
24
31
|
suppressToolbar: () => () => void;
|
|
25
32
|
}
|
|
26
|
-
export declare function CurrentWindowProvider({ children, close, id, overlayHost, setBackground, setContentSize, showStatusMessage, suppressToolbar, }: PropsWithChildren<CurrentWindowContextValue>): import("react").JSX.Element;
|
|
33
|
+
export declare function CurrentWindowProvider({ children, close, id, markContentLoaded, overlayHost, setBackground, setContentSize, showStatusMessage, suppressToolbar, }: PropsWithChildren<CurrentWindowContextValue>): import("react").JSX.Element;
|
|
27
34
|
export declare function useCurrentWindow(): CurrentWindowContextValue | null;
|
|
28
35
|
/**
|
|
29
36
|
* Drop the host window's toolbar row while `active`.
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useContext, useEffect, useLayoutEffect, useMemo, } from "react";
|
|
3
3
|
const CurrentWindowContext = createContext(null);
|
|
4
|
-
export function CurrentWindowProvider({ children, close, id, overlayHost, setBackground, setContentSize, showStatusMessage, suppressToolbar, }) {
|
|
4
|
+
export function CurrentWindowProvider({ children, close, id, markContentLoaded, overlayHost, setBackground, setContentSize, showStatusMessage, suppressToolbar, }) {
|
|
5
5
|
const value = useMemo(() => ({
|
|
6
6
|
close,
|
|
7
7
|
id,
|
|
8
|
+
markContentLoaded,
|
|
8
9
|
overlayHost,
|
|
9
10
|
setBackground,
|
|
10
11
|
setContentSize,
|
|
@@ -13,6 +14,7 @@ export function CurrentWindowProvider({ children, close, id, overlayHost, setBac
|
|
|
13
14
|
}), [
|
|
14
15
|
close,
|
|
15
16
|
id,
|
|
17
|
+
markContentLoaded,
|
|
16
18
|
overlayHost,
|
|
17
19
|
setBackground,
|
|
18
20
|
setContentSize,
|
|
@@ -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,SAAS,EACT,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;AAkCf,MAAM,oBAAoB,GAAG,aAAa,CACxC,IAAI,CACL,CAAC;AAEF,MAAM,UAAU,qBAAqB,CAAC,EACpC,QAAQ,EACR,KAAK,EACL,EAAE,EACF,iBAAiB,EACjB,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,iBAAiB;QACjB,WAAW;QACX,aAAa;QACb,cAAc;QACd,iBAAiB;QACjB,eAAe;KAChB,CAAC,EACF;QACE,KAAK;QACL,EAAE;QACF,iBAAiB;QACjB,WAAW;QACX,aAAa;QACb,cAAc;QACd,iBAAiB;QACjB,eAAe;KAChB,CACF,CAA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Ac,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 /**\n * Tell the window its content has loaded. A window opened with\n * `fitToContent` fits then, once the content has reported its size; later\n * calls do nothing. Hosts that render this provider outside a `Window` may\n * omit it.\n */\n markContentLoaded?: (() => void) | undefined;\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 markContentLoaded,\n overlayHost,\n setBackground,\n setContentSize,\n showStatusMessage,\n suppressToolbar,\n}: PropsWithChildren<CurrentWindowContextValue>) {\n const value = useMemo(\n () => ({\n close,\n id,\n markContentLoaded,\n overlayHost,\n setBackground,\n setContentSize,\n showStatusMessage,\n suppressToolbar,\n }),\n [\n close,\n id,\n markContentLoaded,\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
|
@@ -185,7 +185,7 @@ function WindowInnerContent({ ContentBoundary, entry, historyBack, isTop, }) {
|
|
|
185
185
|
const hasSidebar = hasWindowSidebar(sidebar);
|
|
186
186
|
const { handlePointerDown, handleResizePointerDown, position, size, ...stepped } = useWindowGeometry(entry, maximized, windowRef);
|
|
187
187
|
const { showStatusMessage, statusText } = useWindowStatusMessage();
|
|
188
|
-
const {
|
|
188
|
+
const { contentFit, geometryMenuItems } = useWindowGeometryMenu(entry, stepped, { overlayHost, windowRef }, showStatusMessage);
|
|
189
189
|
const actions = useWindowActions(entry, fileMenuItems, viewMenuItems, geometryMenuItems, hasSidebar);
|
|
190
190
|
// A maximized window fills its surface without a laid-out position.
|
|
191
191
|
useFocusWindowOnShow(windowRef, {
|
|
@@ -201,7 +201,7 @@ function WindowInnerContent({ ContentBoundary, entry, historyBack, isTop, }) {
|
|
|
201
201
|
// A section labelled by its title is a region landmark. Windows are
|
|
202
202
|
// non-modal and freely arranged, so they are not dialogs; hosts keep that
|
|
203
203
|
// role for the modals they open inside a window.
|
|
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,
|
|
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, ...contentFit, 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 }))] }));
|
|
205
205
|
}
|
|
206
206
|
function WindowBodyWithSidebar({ showSidebar, overlayHostRef, children, }) {
|
|
207
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,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,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,wBAA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e,IAAC,KAAK,EAAE,KAAK,YAC1B,SAAS,IAAI,KAAC,SAAS,KAAG,GACX,CACnB,CAAC,CAAC,CAAC,CACF,SAAS,IAAI,KAAC,SAAS,KAAG,CAC3B,GACqB,GACF,EACxB,KAAC,eAAe,IAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,aAAa,GAAI,EACpE,CAAC,SAAS,IAAI,CACb,KAAC,mBAAmB,IAClB,uBAAuB,EAAE,uBAAuB,GAChD,CACH,IACO,CACX,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,EAC7B,WAAW,EACX,cAAc,EACd,QAAQ,GAIR;IACA,MAAM,EAAE,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 { 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"]}
|
|
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,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,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,gBAA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,CAAC,CAAC,CAAC,CACjB,KAAC,eAAe,IAAC,KAAK,EAAE,KAAK,YAC1B,SAAS,IAAI,KAAC,SAAS,KAAG,GACX,CACnB,CAAC,CAAC,CAAC,CACF,SAAS,IAAI,KAAC,SAAS,KAAG,CAC3B,GACqB,GACF,EACxB,KAAC,eAAe,IAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,aAAa,GAAI,EACpE,CAAC,SAAS,IAAI,CACb,KAAC,mBAAmB,IAClB,uBAAuB,EAAE,uBAAuB,GAChD,CACH,IACO,CACX,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,EAC7B,WAAW,EACX,cAAc,EACd,QAAQ,GAIR;IACA,MAAM,EAAE,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 { 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 { contentFit, geometryMenuItems } = 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 {...contentFit}\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"]}
|
|
@@ -23,6 +23,7 @@ export interface WindowEntry {
|
|
|
23
23
|
initialY: number;
|
|
24
24
|
position?: WindowPosition | undefined;
|
|
25
25
|
size?: WindowSize | undefined;
|
|
26
|
+
fitToContent?: boolean | undefined;
|
|
26
27
|
maximized: boolean;
|
|
27
28
|
minimized: boolean;
|
|
28
29
|
zIndex: number;
|
|
@@ -30,6 +31,7 @@ export interface WindowEntry {
|
|
|
30
31
|
}
|
|
31
32
|
export interface WindowCreateOptions {
|
|
32
33
|
appId?: string;
|
|
34
|
+
fitToContent?: boolean | undefined;
|
|
33
35
|
initialShowSidebar?: boolean | undefined;
|
|
34
36
|
pathSegments?: ReadonlyArray<string> | undefined;
|
|
35
37
|
position?: WindowPosition | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowStateProvider/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentType } from \"react\";\n\nexport type WindowMoveDirection = \"forward\" | \"backward\";\n\n// Window geometry is relative to the desktop surface a window is rendered in\n// (the window's offset parent), not to the viewport.\nexport interface WindowPosition {\n x: number;\n y: number;\n}\n\nexport interface WindowSize {\n width: number;\n height: number;\n}\n\nexport interface WindowGeometry {\n position: WindowPosition;\n size?: WindowSize | undefined;\n}\n\nexport interface WindowEntry {\n // An opaque key naming the app that owns this window. The window layer only\n // stores and compares it; the host interprets it (see Window's\n // ContentBoundary).\n appId?: string;\n id: string;\n initialShowSidebar?: boolean | undefined;\n pathSegments?: ReadonlyArray<string> | undefined;\n // The window's own Back stack: routes previously visited in this window, the\n // most recent last. A window is not backed by browser history (only the\n // routed shell is), so this is what gives the windowed toolbar a working Back\n // caret. Forward is deliberately not modelled — the toolbar offers Back only.\n routeHistory?: ReadonlyArray<ReadonlyArray<string>> | undefined;\n title: string;\n // Where the window first appears, in viewport coordinates (for example the\n // point a launcher was clicked). Ignored once position is known.\n initialX: number;\n initialY: number;\n // The window's committed geometry. Set when the window is first laid out and\n // whenever a drag or resize ends, so a host can save and restore a layout.\n // Without size the window takes its stylesheet's default size.\n position?: WindowPosition | undefined;\n size?: WindowSize | undefined;\n // maximized and minimized live here rather than inside Window so the taskbar\n // can drive both without reaching into a window's local state.\n maximized: boolean;\n minimized: boolean;\n zIndex: number;\n component?: ComponentType;\n}\n\nexport interface WindowCreateOptions {\n appId?: string;\n initialShowSidebar?: boolean | undefined;\n pathSegments?: ReadonlyArray<string> | undefined;\n // Surface-relative geometry to open with, such as a restored layout. A\n // position takes precedence over create's viewport x/y.\n position?: WindowPosition | undefined;\n size?: WindowSize | undefined;\n}\n\nexport interface WindowStateData {\n // windows is the raw useState array — stable and cheap to iterate for\n // rendering lists. windowMap is derived via useMemo for O(1) lookups by ID.\n // Both are already memoized so neither adds redundant computation.\n windows: WindowEntry[];\n windowMap: Map<string, WindowEntry>;\n}\n\nexport interface WindowStateActions {\n create: (\n title: string,\n x: number,\n y: number,\n component?: ComponentType,\n options?: WindowCreateOptions,\n ) => string;\n close: (id: string) => void;\n maximize: (id: string) => void;\n minimize: (id: string) => void;\n restore: (id: string) => void;\n toggleMaximize: (id: string) => void;\n updateRoute: (\n id: string,\n pathSegments: ReadonlyArray<string>,\n options?: { replace?: boolean | undefined },\n ) => void;\n goBackRoute: (id: string) => void;\n updateTitle: (id: string, title: string) => void;\n moveForward: (id: string) => void;\n moveBackward: (id: string) => void;\n bringToFront: (id: string) => void;\n setGeometry: (id: string, geometry: WindowGeometry) => void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowStateProvider/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentType } from \"react\";\n\nexport type WindowMoveDirection = \"forward\" | \"backward\";\n\n// Window geometry is relative to the desktop surface a window is rendered in\n// (the window's offset parent), not to the viewport.\nexport interface WindowPosition {\n x: number;\n y: number;\n}\n\nexport interface WindowSize {\n width: number;\n height: number;\n}\n\nexport interface WindowGeometry {\n position: WindowPosition;\n size?: WindowSize | undefined;\n}\n\nexport interface WindowEntry {\n // An opaque key naming the app that owns this window. The window layer only\n // stores and compares it; the host interprets it (see Window's\n // ContentBoundary).\n appId?: string;\n id: string;\n initialShowSidebar?: boolean | undefined;\n pathSegments?: ReadonlyArray<string> | undefined;\n // The window's own Back stack: routes previously visited in this window, the\n // most recent last. A window is not backed by browser history (only the\n // routed shell is), so this is what gives the windowed toolbar a working Back\n // caret. Forward is deliberately not modelled — the toolbar offers Back only.\n routeHistory?: ReadonlyArray<ReadonlyArray<string>> | undefined;\n title: string;\n // Where the window first appears, in viewport coordinates (for example the\n // point a launcher was clicked). Ignored once position is known.\n initialX: number;\n initialY: number;\n // The window's committed geometry. Set when the window is first laid out and\n // whenever a drag or resize ends, so a host can save and restore a layout.\n // Without size the window takes its stylesheet's default size.\n position?: WindowPosition | undefined;\n size?: WindowSize | undefined;\n // Whether the window fits itself to its content once the content has loaded\n // (see WindowCreateOptions).\n fitToContent?: boolean | undefined;\n // maximized and minimized live here rather than inside Window so the taskbar\n // can drive both without reaching into a window's local state.\n maximized: boolean;\n minimized: boolean;\n zIndex: number;\n component?: ComponentType;\n}\n\nexport interface WindowCreateOptions {\n appId?: string;\n // Opens the window fitted to its content, as View > Fit to Content would fit\n // it: once the content has marked itself loaded and reported its natural\n // size. A window maximized by then stays maximized.\n fitToContent?: boolean | undefined;\n initialShowSidebar?: boolean | undefined;\n pathSegments?: ReadonlyArray<string> | undefined;\n // Surface-relative geometry to open with, such as a restored layout. A\n // position takes precedence over create's viewport x/y.\n position?: WindowPosition | undefined;\n size?: WindowSize | undefined;\n}\n\nexport interface WindowStateData {\n // windows is the raw useState array — stable and cheap to iterate for\n // rendering lists. windowMap is derived via useMemo for O(1) lookups by ID.\n // Both are already memoized so neither adds redundant computation.\n windows: WindowEntry[];\n windowMap: Map<string, WindowEntry>;\n}\n\nexport interface WindowStateActions {\n create: (\n title: string,\n x: number,\n y: number,\n component?: ComponentType,\n options?: WindowCreateOptions,\n ) => string;\n close: (id: string) => void;\n maximize: (id: string) => void;\n minimize: (id: string) => void;\n restore: (id: string) => void;\n toggleMaximize: (id: string) => void;\n updateRoute: (\n id: string,\n pathSegments: ReadonlyArray<string>,\n options?: { replace?: boolean | undefined },\n ) => void;\n goBackRoute: (id: string) => void;\n updateTitle: (id: string, title: string) => void;\n moveForward: (id: string) => void;\n moveBackward: (id: string) => void;\n bringToFront: (id: string) => void;\n setGeometry: (id: string, geometry: WindowGeometry) => void;\n}\n"]}
|
|
@@ -11,6 +11,7 @@ export function createWindowEntry(id, title, x, y, zIndex, component, options =
|
|
|
11
11
|
initialY: y,
|
|
12
12
|
...(options.position ? { position: { ...options.position } } : {}),
|
|
13
13
|
...(options.size ? { size: { ...options.size } } : {}),
|
|
14
|
+
...(options.fitToContent ? { fitToContent: true } : {}),
|
|
14
15
|
maximized: false,
|
|
15
16
|
minimized: false,
|
|
16
17
|
zIndex,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createWindowEntry.js","sourceRoot":"","sources":["../../../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowStateProvider/util/createWindowEntry.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,iBAAiB,CAC/B,EAAU,EACV,KAAa,EACb,CAAS,EACT,CAAS,EACT,MAAc,EACd,SAAyB,EACzB,UAA+B,EAAE;IAEjC,OAAO;QACL,EAAE;QACF,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClD,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;QAC9C,GAAG,CAAC,OAAO,CAAC,YAAY;YACtB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,EAAE;YAC7C,CAAC,CAAC,EAAE,CAAC;QACP,KAAK;QACL,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;QACX,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,SAAS,EAAE,KAAK;QAChB,SAAS,EAAE,KAAK;QAChB,MAAM;QACN,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import type { ComponentType } from \"react\";\nimport type { WindowCreateOptions, WindowEntry } from \"../types\";\n\nexport function createWindowEntry(\n id: string,\n title: string,\n x: number,\n y: number,\n zIndex: number,\n component?: ComponentType,\n options: WindowCreateOptions = {},\n): WindowEntry {\n return {\n id,\n ...(options.appId ? { appId: options.appId } : {}),\n initialShowSidebar: options.initialShowSidebar,\n ...(options.pathSegments\n ? { pathSegments: [...options.pathSegments] }\n : {}),\n title,\n initialX: x,\n initialY: y,\n ...(options.position ? { position: { ...options.position } } : {}),\n ...(options.size ? { size: { ...options.size } } : {}),\n maximized: false,\n minimized: false,\n zIndex,\n ...(component ? { component } : {}),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"createWindowEntry.js","sourceRoot":"","sources":["../../../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowStateProvider/util/createWindowEntry.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,iBAAiB,CAC/B,EAAU,EACV,KAAa,EACb,CAAS,EACT,CAAS,EACT,MAAc,EACd,SAAyB,EACzB,UAA+B,EAAE;IAEjC,OAAO;QACL,EAAE;QACF,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClD,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;QAC9C,GAAG,CAAC,OAAO,CAAC,YAAY;YACtB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,EAAE;YAC7C,CAAC,CAAC,EAAE,CAAC;QACP,KAAK;QACL,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;QACX,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,SAAS,EAAE,KAAK;QAChB,SAAS,EAAE,KAAK;QAChB,MAAM;QACN,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import type { ComponentType } from \"react\";\nimport type { WindowCreateOptions, WindowEntry } from \"../types\";\n\nexport function createWindowEntry(\n id: string,\n title: string,\n x: number,\n y: number,\n zIndex: number,\n component?: ComponentType,\n options: WindowCreateOptions = {},\n): WindowEntry {\n return {\n id,\n ...(options.appId ? { appId: options.appId } : {}),\n initialShowSidebar: options.initialShowSidebar,\n ...(options.pathSegments\n ? { pathSegments: [...options.pathSegments] }\n : {}),\n title,\n initialX: x,\n initialY: y,\n ...(options.position ? { position: { ...options.position } } : {}),\n ...(options.size ? { size: { ...options.size } } : {}),\n ...(options.fitToContent ? { fitToContent: true } : {}),\n maximized: false,\n minimized: false,\n zIndex,\n ...(component ? { component } : {}),\n };\n}\n"]}
|
package/window/useWindowFit.d.ts
CHANGED
|
@@ -7,7 +7,10 @@ interface WindowFitHost {
|
|
|
7
7
|
windowRef: RefObject<HTMLElement | null>;
|
|
8
8
|
}
|
|
9
9
|
export declare function useWindowGeometryMenu(entry: WindowEntry, stepped: Parameters<typeof useWindowGeometryMenuItems>[0], host: WindowFitHost, announce: (message: string) => void): {
|
|
10
|
+
contentFit: {
|
|
11
|
+
markContentLoaded: () => void;
|
|
12
|
+
setContentSize: import("react").Dispatch<import("react").SetStateAction<WindowSize | undefined>>;
|
|
13
|
+
};
|
|
10
14
|
geometryMenuItems: WindowMenuItem[];
|
|
11
|
-
setContentSize: import("react").Dispatch<import("react").SetStateAction<WindowSize | undefined>>;
|
|
12
15
|
};
|
|
13
16
|
export {};
|
package/window/useWindowFit.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useMemo, useState } from "react";
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
|
|
2
2
|
import { useWindowGeometryMenuItems } from "./useWindowKeyboardGeometry.js";
|
|
3
3
|
import { useWindowActions, } from "./WindowStateProvider/index.js";
|
|
4
4
|
import { fitWindowGeometry } from "./windowGeometry.js";
|
|
@@ -32,6 +32,51 @@ function measureWindowFit(windowElement, pane) {
|
|
|
32
32
|
scrollbar: measureScrollbars(pane),
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
+
// A window opened with `fitToContent` fits once, the first time its content
|
|
36
|
+
// has both marked itself loaded and reported a size while the window shows. A
|
|
37
|
+
// window maximized by then (as a host opens windows on narrow screens, before
|
|
38
|
+
// they are ever laid out) stays maximized and does not fit later. A hidden
|
|
39
|
+
// surface (an inactive workspace) has no size to fit against, so the fit waits
|
|
40
|
+
// until it has one.
|
|
41
|
+
function useFitOnLoad(entry, contentSize, fit, windowRef) {
|
|
42
|
+
const [loaded, setLoaded] = useState(false);
|
|
43
|
+
const pending = useRef(entry.fitToContent === true);
|
|
44
|
+
const markContentLoaded = useCallback(() => setLoaded(true), []);
|
|
45
|
+
const { maximized, minimized, position } = entry;
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!pending.current || !loaded || minimized) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (maximized) {
|
|
51
|
+
pending.current = false;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!contentSize) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const attempt = () => {
|
|
58
|
+
if (fit()) {
|
|
59
|
+
pending.current = false;
|
|
60
|
+
}
|
|
61
|
+
return !pending.current;
|
|
62
|
+
};
|
|
63
|
+
if (!position || attempt()) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const surface = windowRef.current?.parentElement;
|
|
67
|
+
if (!surface || typeof ResizeObserver === "undefined") {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const observer = new ResizeObserver(() => {
|
|
71
|
+
if (attempt()) {
|
|
72
|
+
observer.disconnect();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
observer.observe(surface);
|
|
76
|
+
return () => observer.disconnect();
|
|
77
|
+
}, [contentSize, fit, loaded, maximized, minimized, position, windowRef]);
|
|
78
|
+
return markContentLoaded;
|
|
79
|
+
}
|
|
35
80
|
// Fit to Content, offered in the View menu while the window's content has a
|
|
36
81
|
// natural size (see `useWindowContentSize`). It measures the window's chrome
|
|
37
82
|
// as rendered, so it allows for whichever bars and sidebar show, and restores
|
|
@@ -40,18 +85,25 @@ function useWindowFit(entry, { overlayHost, windowRef }) {
|
|
|
40
85
|
const { setGeometry, toggleMaximize } = useWindowActions();
|
|
41
86
|
const [contentSize, setContentSize] = useState();
|
|
42
87
|
const { id, maximized, position } = entry;
|
|
88
|
+
// Whether the window fitted: one that is not rendered, or whose surface is
|
|
89
|
+
// hidden, has nothing to measure.
|
|
43
90
|
const fitToContent = useCallback(() => {
|
|
44
91
|
const element = windowRef.current;
|
|
45
92
|
const surface = element?.parentElement;
|
|
46
93
|
const pane = overlayHost?.querySelector(SCROLL_PANE_SELECTOR);
|
|
47
|
-
if (!contentSize ||
|
|
48
|
-
|
|
94
|
+
if (!contentSize ||
|
|
95
|
+
!element ||
|
|
96
|
+
!surface ||
|
|
97
|
+
!pane ||
|
|
98
|
+
(surface.clientWidth === 0 && surface.clientHeight === 0)) {
|
|
99
|
+
return false;
|
|
49
100
|
}
|
|
50
101
|
const geometry = fitWindowGeometry(contentSize, measureWindowFit(element, pane), { height: surface.clientHeight, width: surface.clientWidth }, position ?? { x: 0, y: 0 });
|
|
51
102
|
if (maximized) {
|
|
52
103
|
toggleMaximize(id);
|
|
53
104
|
}
|
|
54
105
|
setGeometry(id, geometry);
|
|
106
|
+
return true;
|
|
55
107
|
}, [
|
|
56
108
|
contentSize,
|
|
57
109
|
id,
|
|
@@ -71,18 +123,21 @@ function useWindowFit(entry, { overlayHost, windowRef }) {
|
|
|
71
123
|
},
|
|
72
124
|
]
|
|
73
125
|
: [], [contentSize, fitToContent]);
|
|
74
|
-
|
|
126
|
+
const markContentLoaded = useFitOnLoad(entry, contentSize, fitToContent, windowRef);
|
|
127
|
+
return { fitMenuItems, markContentLoaded, setContentSize };
|
|
75
128
|
}
|
|
76
129
|
// The View menu's geometry entries: keyboard move and resize, then Fit to
|
|
77
|
-
// Content while the content has a natural size.
|
|
130
|
+
// Content while the content has a natural size. `contentFit` is the content's
|
|
131
|
+
// side of fitting, `setContentSize` and `markContentLoaded`, which the window
|
|
132
|
+
// passes to its content.
|
|
78
133
|
export function useWindowGeometryMenu(entry, stepped, host, announce) {
|
|
79
134
|
const keyboardItems = useWindowGeometryMenuItems(stepped, {
|
|
80
135
|
maximized: entry.maximized,
|
|
81
136
|
minimized: entry.minimized,
|
|
82
137
|
windowRef: host.windowRef,
|
|
83
138
|
}, announce);
|
|
84
|
-
const { fitMenuItems,
|
|
139
|
+
const { fitMenuItems, ...contentFit } = useWindowFit(entry, host);
|
|
85
140
|
const geometryMenuItems = useMemo(() => [...keyboardItems, ...fitMenuItems], [fitMenuItems, keyboardItems]);
|
|
86
|
-
return {
|
|
141
|
+
return { contentFit, geometryMenuItems };
|
|
87
142
|
}
|
|
88
143
|
//# sourceMappingURL=useWindowFit.js.map
|
|
@@ -1 +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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,CAC1B,GAAG,EAAE,CACH,WAAW;QACT,CAAC,CAAC;YACE;gBACE,EAAE,EAAE,gBAAgB;gBACpB,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"]}
|
|
1
|
+
{"version":3,"file":"useWindowFit.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/useWindowFit.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,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/D,SAAS,iBAAiB,CAAC,IAAiB;IAC1C,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;IAChC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC/B,MAAM,SAAS,GAAG;QAChB,MAAM,EAAE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY;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C,CAAC","sourcesContent":["import {\n type RefObject,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} 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// A window opened with `fitToContent` fits once, the first time its content\n// has both marked itself loaded and reported a size while the window shows. A\n// window maximized by then (as a host opens windows on narrow screens, before\n// they are ever laid out) stays maximized and does not fit later. A hidden\n// surface (an inactive workspace) has no size to fit against, so the fit waits\n// until it has one.\nfunction useFitOnLoad(\n entry: WindowEntry,\n contentSize: WindowSize | undefined,\n fit: () => boolean,\n windowRef: RefObject<HTMLElement | null>,\n) {\n const [loaded, setLoaded] = useState(false);\n const pending = useRef(entry.fitToContent === true);\n const markContentLoaded = useCallback(() => setLoaded(true), []);\n const { maximized, minimized, position } = entry;\n\n useEffect(() => {\n if (!pending.current || !loaded || minimized) {\n return;\n }\n if (maximized) {\n pending.current = false;\n return;\n }\n if (!contentSize) {\n return;\n }\n const attempt = () => {\n if (fit()) {\n pending.current = false;\n }\n return !pending.current;\n };\n if (!position || attempt()) {\n return;\n }\n const surface = windowRef.current?.parentElement;\n if (!surface || typeof ResizeObserver === \"undefined\") {\n return;\n }\n const observer = new ResizeObserver(() => {\n if (attempt()) {\n observer.disconnect();\n }\n });\n observer.observe(surface);\n return () => observer.disconnect();\n }, [contentSize, fit, loaded, maximized, minimized, position, windowRef]);\n\n return markContentLoaded;\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 // Whether the window fitted: one that is not rendered, or whose surface is\n // hidden, has nothing to measure.\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 (\n !contentSize ||\n !element ||\n !surface ||\n !pane ||\n (surface.clientWidth === 0 && surface.clientHeight === 0)\n ) {\n return false;\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 return true;\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 const markContentLoaded = useFitOnLoad(\n entry,\n contentSize,\n fitToContent,\n windowRef,\n );\n\n return { fitMenuItems, markContentLoaded, 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. `contentFit` is the content's\n// side of fitting, `setContentSize` and `markContentLoaded`, which the window\n// passes to its content.\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, ...contentFit } = useWindowFit(entry, host);\n const geometryMenuItems = useMemo(\n () => [...keyboardItems, ...fitMenuItems],\n [fitMenuItems, keyboardItems],\n );\n\n return { contentFit, geometryMenuItems };\n}\n"]}
|