@tearleads/windowing 0.2.24 → 0.2.25
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/display/DisplayProperties.css +8 -0
- package/package.json +1 -1
- package/window/Window.js +2 -2
- package/window/Window.js.map +1 -1
- package/window/useWindowFit.d.ts +2 -1
- package/window/useWindowFit.js +4 -4
- package/window/useWindowFit.js.map +1 -1
- package/window/useWindowGeometry.d.ts +2 -1
- package/window/useWindowGeometry.js +10 -2
- package/window/useWindowGeometry.js.map +1 -1
|
@@ -99,6 +99,14 @@
|
|
|
99
99
|
box-shadow: inset 0 0 0 1px var(--color-hairline);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/* Fit a complete tile vertically, repeating across the preview instead of
|
|
103
|
+
* cropping large artwork at desktop scale. Outrank Wallpaper.css regardless
|
|
104
|
+
* of the host's import order; the desktop keeps its natural pixel tile size. */
|
|
105
|
+
.display-properties-swatch.wallpaper-pattern[data-pattern]::before {
|
|
106
|
+
-webkit-mask-size: auto 100%;
|
|
107
|
+
mask-size: auto 100%;
|
|
108
|
+
}
|
|
109
|
+
|
|
102
110
|
.display-properties-label {
|
|
103
111
|
overflow: hidden;
|
|
104
112
|
text-overflow: ellipsis;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tearleads/windowing",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.25",
|
|
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": {
|
package/window/Window.js
CHANGED
|
@@ -183,9 +183,9 @@ function WindowInnerContent({ ContentBoundary, entry, historyBack, isTop, }) {
|
|
|
183
183
|
const viewMenuItems = useWindowViewMenuItems();
|
|
184
184
|
const { sidebar } = useWindowSidebar();
|
|
185
185
|
const hasSidebar = hasWindowSidebar(sidebar);
|
|
186
|
-
const { handlePointerDown, handleResizePointerDown, position, size, ...stepped } = useWindowGeometry(entry, maximized, windowRef);
|
|
186
|
+
const { applyGeometry, handlePointerDown, handleResizePointerDown, position, size, ...stepped } = useWindowGeometry(entry, maximized, windowRef);
|
|
187
187
|
const { showStatusMessage, statusText } = useWindowStatusMessage();
|
|
188
|
-
const { contentFit, geometryMenuItems } = useWindowGeometryMenu(entry, stepped, { overlayHost, windowRef }, showStatusMessage);
|
|
188
|
+
const { contentFit, geometryMenuItems } = useWindowGeometryMenu(entry, stepped, { applyGeometry, 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, {
|
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;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AAC,WAAW,YAE/B,eAAe,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"]}
|
|
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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ACpB,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,OAAO,CAAC,WAAW,YAE/B,eAAe,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 applyGeometry,\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 { applyGeometry, 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"]}
|
package/window/useWindowFit.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type RefObject } from "react";
|
|
2
2
|
import { useWindowGeometryMenuItems } from "./useWindowKeyboardGeometry.js";
|
|
3
3
|
import type { WindowMenuItem } from "./WindowMenuBar.js";
|
|
4
|
-
import { type WindowEntry, type WindowSize } from "./WindowStateProvider/index.js";
|
|
4
|
+
import { type WindowEntry, type WindowGeometry, type WindowSize } from "./WindowStateProvider/index.js";
|
|
5
5
|
interface WindowFitHost {
|
|
6
|
+
applyGeometry: (geometry: WindowGeometry) => void;
|
|
6
7
|
overlayHost: HTMLElement | null;
|
|
7
8
|
windowRef: RefObject<HTMLElement | null>;
|
|
8
9
|
}
|
package/window/useWindowFit.js
CHANGED
|
@@ -81,8 +81,8 @@ function useFitOnLoad(entry, contentSize, fit, windowRef) {
|
|
|
81
81
|
// natural size (see `useWindowContentSize`). It measures the window's chrome
|
|
82
82
|
// as rendered, so it allows for whichever bars and sidebar show, and restores
|
|
83
83
|
// a maximized window first.
|
|
84
|
-
function useWindowFit(entry, { overlayHost, windowRef }) {
|
|
85
|
-
const {
|
|
84
|
+
function useWindowFit(entry, { applyGeometry, overlayHost, windowRef }) {
|
|
85
|
+
const { toggleMaximize } = useWindowActions();
|
|
86
86
|
const [contentSize, setContentSize] = useState();
|
|
87
87
|
const { id, maximized, position } = entry;
|
|
88
88
|
// Whether the window fitted: one that is not rendered, or whose surface is
|
|
@@ -102,15 +102,15 @@ function useWindowFit(entry, { overlayHost, windowRef }) {
|
|
|
102
102
|
if (maximized) {
|
|
103
103
|
toggleMaximize(id);
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
applyGeometry(geometry);
|
|
106
106
|
return true;
|
|
107
107
|
}, [
|
|
108
|
+
applyGeometry,
|
|
108
109
|
contentSize,
|
|
109
110
|
id,
|
|
110
111
|
maximized,
|
|
111
112
|
overlayHost,
|
|
112
113
|
position,
|
|
113
|
-
setGeometry,
|
|
114
114
|
toggleMaximize,
|
|
115
115
|
windowRef,
|
|
116
116
|
]);
|
|
@@ -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,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,CA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AAE,CAAC,CAAC,GAAG,aAAa,EAAE,GAAG,YAAY,CAAC,EACzC,CAAC,YAAY,EAAE,aAAa,CAAC,CAC9B,CAAC;IAEF,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC;AAC3C,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"]}
|
|
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,GAIjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAyB,MAAM,kBAAkB,CAAC;AAE5E,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,EAAE,YAAY,EAAE,GAAG,UAAU,EAAE,GAAG,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAClE,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,UAAU,EAAE,iBAAiB,EAAE,CAAC;AAC3C,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 WindowGeometry,\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 applyGeometry: (geometry: WindowGeometry) => void;\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 { applyGeometry, overlayHost, windowRef }: WindowFitHost,\n) {\n const { 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 applyGeometry(geometry);\n return true;\n }, [\n applyGeometry,\n contentSize,\n id,\n maximized,\n overlayHost,\n position,\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"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type PointerEvent as ReactPointerEvent, type RefObject } from "react";
|
|
2
2
|
import type { ResizeEdge } from "./WindowResizeHandle.js";
|
|
3
|
-
import { type WindowEntry, type WindowPosition, type WindowSize } from "./WindowStateProvider/index.js";
|
|
3
|
+
import { type WindowEntry, type WindowGeometry, type WindowPosition, type WindowSize } from "./WindowStateProvider/index.js";
|
|
4
4
|
import { type LiveGeometry } from "./windowGeometry.js";
|
|
5
5
|
export declare function useWindowGeometry(entry: WindowEntry, maximized: boolean, windowRef: RefObject<HTMLElement | null>): {
|
|
6
|
+
applyGeometry: (geometry: WindowGeometry) => void;
|
|
6
7
|
commit: () => void;
|
|
7
8
|
hold: (holding: boolean) => void;
|
|
8
9
|
handlePointerDown: (event: ReactPointerEvent) => void;
|
|
@@ -73,12 +73,19 @@ function useLiveGeometry(entry) {
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
}, [entry.id, setGeometry]);
|
|
76
|
+
// Fit and other window-owned changes must update the live frame before
|
|
77
|
+
// publication: a surface observer can commit again before the passive mirror.
|
|
78
|
+
const applyGeometry = useCallback((geometry) => {
|
|
79
|
+
setPosition(geometry.position);
|
|
80
|
+
setSize(geometry.size ?? null);
|
|
81
|
+
commit();
|
|
82
|
+
}, [commit, setPosition, setSize]);
|
|
76
83
|
// The committed size is the source of truth between gestures: a restored
|
|
77
84
|
// layout or host call applies it, and clearing it restores the default size.
|
|
78
85
|
useEffect(() => {
|
|
79
86
|
setSize(entry.size ?? null);
|
|
80
87
|
}, [entry.size, setSize]);
|
|
81
|
-
return { commit, live, position, setPosition, setSize, size };
|
|
88
|
+
return { applyGeometry, commit, live, position, setPosition, setSize, size };
|
|
82
89
|
}
|
|
83
90
|
// Stepwise geometry for keyboard move and resize. Steps stay local until the
|
|
84
91
|
// caller commits, like a pointer gesture; restore puts a snapshot back.
|
|
@@ -182,7 +189,7 @@ function useGestureStarts(windowRef, maximized, position, dragging, resizing) {
|
|
|
182
189
|
return { handlePointerDown, handleResizePointerDown };
|
|
183
190
|
}
|
|
184
191
|
export function useWindowGeometry(entry, maximized, windowRef) {
|
|
185
|
-
const { commit, live, position, setPosition, setSize, size } = useLiveGeometry(entry);
|
|
192
|
+
const { applyGeometry, commit, live, position, setPosition, setSize, size } = useLiveGeometry(entry);
|
|
186
193
|
const dragging = useRef(null);
|
|
187
194
|
const resizing = useRef(null);
|
|
188
195
|
// Maximizing or minimizing mid-gesture (a second touch on the title bar's
|
|
@@ -232,6 +239,7 @@ export function useWindowGeometry(entry, maximized, windowRef) {
|
|
|
232
239
|
const stepped = useSteppedGeometry(windowRef, maximized, live, clamp, setPosition, setSize);
|
|
233
240
|
return {
|
|
234
241
|
...stepped,
|
|
242
|
+
applyGeometry,
|
|
235
243
|
commit,
|
|
236
244
|
hold,
|
|
237
245
|
handlePointerDown,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowGeometry.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/useWindowGeometry.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EACL,gBAAgB,GAIjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,mBAAmB,EAEnB,UAAU,EACV,SAAS,EACT,2BAA2B,GAG5B,MAAM,kBAAkB,CAAC;AAE1B,+EAA+E;AAC/E,2EAA2E;AAC3E,uEAAuE;AACvE,SAAS,wBAAwB,CAC/B,SAAwC,EACxC,QAAkD,EAClD,QAAoD,EACpD,KAA+C,EAC/C,WAA4C,EAC5C,OAA2C,EAC3C,MAAkB;IAElB,SAAS,CAAC,GAAG,EAAE;QACb,wEAAwE;QACxE,0CAA0C;QAC1C,SAAS,gBAAgB,CAAC,KAAmB;YAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC;YACrD,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS,CAAC;QACnE,CAAC;QAED,SAAS,iBAAiB,CAAC,KAAmB;YAC5C,IAA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S,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EACjE,CAAC,IAAI,EAAE,SAAS,CAAC,CAClB,CAAC;IAEF,MAAM,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC;QAC/B,KAAK;QACL,MAAM;QACN,QAAQ;QACR,KAAK;QACL,IAAI;QACJ,QAAQ;QACR,WAAW;QACX,IAAI;QACJ,SAAS;KACV,CAAC,CAAC;IAEH,wEAAwE;IACxE,6EAA6E;IAC7E,MAAM,aAAa,GAAG,WAAW,CAAC,GAAG,EAAE;QACrC,MAAM,EAAE,CAAC;QACT,IAAI,CAAC,KAAK,CAAC,CAAC;IACd,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAEnB,wBAAwB,CACtB,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,WAAW,EACX,OAAO,EACP,aAAa,CACd,CAAC;IAEF,MAAM,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,GAAG,gBAAgB,CACrE,SAAS,EACT,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,QAAQ,CACT,CAAC;IAEF,MAAM,OAAO,GAAG,kBAAkB,CAChC,SAAS,EACT,SAAS,EACT,IAAI,EACJ,KAAK,EACL,WAAW,EACX,OAAO,CACR,CAAC;IAEF,OAAO;QACL,GAAG,OAAO;QACV,MAAM;QACN,IAAI;QACJ,iBAAiB;QACjB,uBAAuB;QACvB,QAAQ;QACR,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["import {\n type MutableRefObject,\n type PointerEvent as ReactPointerEvent,\n type RefObject,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { useWindowLayout } from \"./useWindowLayout\";\nimport type { ResizeEdge } from \"./WindowResizeHandle\";\nimport {\n useWindowActions,\n type WindowEntry,\n type WindowPosition,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport {\n clampWindowPosition,\n type LiveGeometry,\n MIN_HEIGHT,\n MIN_WIDTH,\n resizeWindowWithinContainer,\n type WindowDragState,\n type WindowResizeState,\n} from \"./windowGeometry\";\n\n// Pointer events cover mouse, touch, and pen alike. The live geometry stays in\n// component state while a gesture runs, so only this window re-renders per\n// frame; the gesture's end commits it to the shared window state once.\nfunction useWindowPointerTracking(\n windowRef: RefObject<HTMLElement | null>,\n dragging: MutableRefObject<WindowDragState | null>,\n resizing: MutableRefObject<WindowResizeState | null>,\n clamp: (x: number, y: number) => WindowPosition,\n setPosition: (value: WindowPosition) => void,\n setSize: (value: WindowSize | null) => void,\n finish: () => void,\n) {\n useEffect(() => {\n // Only the pointer that started a gesture drives it, so a second finger\n // cannot move the window or end the drag.\n function isGesturePointer(event: PointerEvent) {\n const gesture = resizing.current ?? dragging.current;\n return gesture !== null && gesture.pointerId === event.pointerId;\n }\n\n function handlePointerMove(event: PointerEvent) {\n if (!isGesturePointer(event)) {\n return;\n }\n if (resizing.current) {\n const nextFrame = resizeWindowWithinContainer(\n resizing.current,\n event.clientX,\n event.clientY,\n windowRef.current?.parentElement ?? null,\n );\n setPosition(nextFrame.position);\n setSize(nextFrame.size);\n return;\n }\n\n if (dragging.current) {\n setPosition(\n clamp(\n event.clientX - dragging.current.offsetX,\n event.clientY - dragging.current.offsetY,\n ),\n );\n }\n }\n\n function handlePointerEnd(event: PointerEvent) {\n if (!isGesturePointer(event)) {\n return;\n }\n dragging.current = null;\n resizing.current = null;\n finish();\n }\n\n document.addEventListener(\"pointermove\", handlePointerMove);\n document.addEventListener(\"pointerup\", handlePointerEnd);\n document.addEventListener(\"pointercancel\", handlePointerEnd);\n document.addEventListener(\"lostpointercapture\", handlePointerEnd);\n return () => {\n document.removeEventListener(\"pointermove\", handlePointerMove);\n document.removeEventListener(\"pointerup\", handlePointerEnd);\n document.removeEventListener(\"pointercancel\", handlePointerEnd);\n document.removeEventListener(\"lostpointercapture\", handlePointerEnd);\n };\n }, [clamp, dragging, finish, resizing, setPosition, setSize, windowRef]);\n}\n\nfunction useLiveGeometry(entry: WindowEntry) {\n const { setGeometry } = useWindowActions();\n const [position, setPositionState] = useState<WindowPosition | null>(null);\n const [size, setSizeState] = useState<WindowSize | null>(entry.size ?? null);\n // Mirrors the live state so a gesture's end commits the latest frame.\n const live = useRef<LiveGeometry>({\n position: null,\n size: entry.size ?? null,\n });\n\n const setPosition = useCallback((value: WindowPosition) => {\n live.current.position = value;\n setPositionState(value);\n }, []);\n const setSize = useCallback((value: WindowSize | null) => {\n live.current.size = value;\n setSizeState(value);\n }, []);\n const commit = useCallback(() => {\n const committedPosition = live.current.position;\n if (committedPosition) {\n setGeometry(entry.id, {\n position: committedPosition,\n size: live.current.size ?? undefined,\n });\n }\n }, [entry.id, setGeometry]);\n\n // The committed size is the source of truth between gestures: a restored\n // layout or host call applies it, and clearing it restores the default size.\n useEffect(() => {\n setSize(entry.size ?? null);\n }, [entry.size, setSize]);\n\n return { commit, live, position, setPosition, setSize, size };\n}\n\n// Stepwise geometry for keyboard move and resize. Steps stay local until the\n// caller commits, like a pointer gesture; restore puts a snapshot back.\nfunction useSteppedGeometry(\n windowRef: RefObject<HTMLElement | null>,\n maximized: boolean,\n live: MutableRefObject<LiveGeometry>,\n clamp: (x: number, y: number) => WindowPosition,\n setPosition: (value: WindowPosition) => void,\n setSize: (value: WindowSize | null) => void,\n) {\n const nudge = useCallback(\n (deltaX: number, deltaY: number) => {\n const current = live.current.position;\n if (!current || maximized) {\n return;\n }\n setPosition(clamp(current.x + deltaX, current.y + deltaY));\n },\n [clamp, live, maximized, setPosition],\n );\n\n const grow = useCallback(\n (deltaWidth: number, deltaHeight: number) => {\n const element = windowRef.current;\n const current = live.current.position;\n if (!element || !current || maximized) {\n return;\n }\n // Step from the size on screen: a requested size below the stylesheet\n // minimums renders at the minimum, so growing from it would show nothing.\n const requested = live.current.size;\n const base = requested\n ? {\n height: Math.max(MIN_HEIGHT, requested.height),\n width: Math.max(MIN_WIDTH, requested.width),\n }\n : { height: element.offsetHeight, width: element.offsetWidth };\n const container = element.parentElement;\n const maxWidth = container\n ? container.clientWidth - current.x\n : Number.POSITIVE_INFINITY;\n const maxHeight = container\n ? container.clientHeight - current.y\n : Number.POSITIVE_INFINITY;\n setSize({\n height: Math.max(\n MIN_HEIGHT,\n Math.min(base.height + deltaHeight, maxHeight),\n ),\n width: Math.max(MIN_WIDTH, Math.min(base.width + deltaWidth, maxWidth)),\n });\n },\n [live, maximized, setSize, windowRef],\n );\n\n const snapshot = useCallback(\n (): LiveGeometry => ({ ...live.current }),\n [live],\n );\n const restore = useCallback(\n (saved: LiveGeometry) => {\n if (saved.position) {\n setPosition(saved.position);\n }\n setSize(saved.size);\n },\n [setPosition, setSize],\n );\n\n return { grow, nudge, restore, snapshot };\n}\n\n// Keeps a gesture's pointer events coming to the window even when the pointer\n// passes over an iframe, whose document would otherwise swallow the release.\n// Synthetic events carry no active pointer, so a failed capture is fine.\nfunction capturePointer(event: ReactPointerEvent) {\n try {\n event.currentTarget.setPointerCapture(event.pointerId);\n } catch {\n // Not an active pointer; the document listeners still track the gesture.\n }\n}\n\n// Starts a drag from the title bar or a resize from an edge or corner. The\n// gesture itself is tracked on the document by useWindowPointerTracking.\nfunction useGestureStarts(\n windowRef: RefObject<HTMLElement | null>,\n maximized: boolean,\n position: WindowPosition | null,\n dragging: MutableRefObject<WindowDragState | null>,\n resizing: MutableRefObject<WindowResizeState | null>,\n) {\n const handlePointerDown = useCallback(\n (event: ReactPointerEvent) => {\n // One gesture at a time: a second pointer pressing the title bar or a\n // resize handle mid-gesture must not take it over.\n if (!position || maximized || dragging.current || resizing.current) {\n return;\n }\n dragging.current = {\n offsetX: event.clientX - position.x,\n offsetY: event.clientY - position.y,\n pointerId: event.pointerId,\n };\n capturePointer(event);\n },\n [dragging, maximized, position, resizing],\n );\n\n const handleResizePointerDown = useCallback(\n (event: ReactPointerEvent, edge: ResizeEdge) => {\n if (\n maximized ||\n !position ||\n !windowRef.current ||\n dragging.current ||\n resizing.current\n ) {\n return;\n }\n event.stopPropagation();\n capturePointer(event);\n const el = windowRef.current;\n const computed = getComputedStyle(el);\n const borderBox = computed.boxSizing === \"border-box\";\n resizing.current = {\n edge,\n pointerId: event.pointerId,\n startX: event.clientX,\n startY: event.clientY,\n startLeft: position.x,\n startTop: position.y,\n startWidth: parseFloat(computed.width),\n startHeight: parseFloat(computed.height),\n borderX: borderBox ? 0 : el.offsetWidth - el.clientWidth,\n borderY: borderBox ? 0 : el.offsetHeight - el.clientHeight,\n };\n },\n [maximized, position, resizing, windowRef],\n );\n\n return { handlePointerDown, handleResizePointerDown };\n}\n\nexport function useWindowGeometry(\n entry: WindowEntry,\n maximized: boolean,\n windowRef: RefObject<HTMLElement | null>,\n) {\n const { commit, live, position, setPosition, setSize, size } =\n useLiveGeometry(entry);\n const dragging = useRef<WindowDragState | null>(null);\n const resizing = useRef<WindowResizeState | null>(null);\n // Maximizing or minimizing mid-gesture (a second touch on the title bar's\n // controls) abandons the gesture: its frames were measured at the normal\n // size, so the live geometry goes back to the committed geometry.\n useEffect(() => {\n if (!(maximized || entry.minimized)) {\n return;\n }\n if (!dragging.current && !resizing.current) {\n return;\n }\n dragging.current = null;\n resizing.current = null;\n setSize(entry.size ?? null);\n if (entry.position) {\n setPosition(entry.position);\n }\n }, [\n entry.minimized,\n entry.position,\n entry.size,\n maximized,\n setPosition,\n setSize,\n ]);\n const clamp = useCallback(\n (x: number, y: number) =>\n clampWindowPosition(windowRef.current, x, y, live.current.size),\n [live, windowRef],\n );\n\n const { hold } = useWindowLayout({\n clamp,\n commit,\n dragging,\n entry,\n live,\n resizing,\n setPosition,\n size,\n windowRef,\n });\n\n // A finished gesture commits its geometry, then runs any layout it held\n // off (a surface resize mid-gesture), even when the geometry did not change.\n const finishGesture = useCallback(() => {\n commit();\n hold(false);\n }, [commit, hold]);\n\n useWindowPointerTracking(\n windowRef,\n dragging,\n resizing,\n clamp,\n setPosition,\n setSize,\n finishGesture,\n );\n\n const { handlePointerDown, handleResizePointerDown } = useGestureStarts(\n windowRef,\n maximized,\n position,\n dragging,\n resizing,\n );\n\n const stepped = useSteppedGeometry(\n windowRef,\n maximized,\n live,\n clamp,\n setPosition,\n setSize,\n );\n\n return {\n ...stepped,\n commit,\n hold,\n handlePointerDown,\n handleResizePointerDown,\n position,\n size,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useWindowGeometry.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/useWindowGeometry.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EACL,gBAAgB,GAKjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,mBAAmB,EAEnB,UAAU,EACV,SAAS,EACT,2BAA2B,GAG5B,MAAM,kBAAkB,CAAC;AAE1B,+EAA+E;AAC/E,2EAA2E;AAC3E,uEAAuE;AACvE,SAAS,wBAAwB,CAC/B,SAAwC,EACxC,QAAkD,EAClD,QAAoD,EACpD,KAA+C,EAC/C,WAA4C,EAC5C,OAA2C,EAC3C,MAAkB;IAElB,SAAS,CAAC,GAAG,EAAE;QACb,wEAAwE;QACxE,0CAA0C;QAC1C,SAAS,gBAAgB,CAAC,KAAmB;YAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC;YACrD,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS,CAAC;QACnE,CAAC;QAED,SAAS,iBAAiB,CAAC,KAAmB;YAC5C,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC7B,OAAO;YACT,CAAC;YACD,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;gBACrB,MAAM,SAAS,GAAG,2BAA2B,CAC3C,QAAQ,CAA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AAK,CAAC,IAAI;QACV,SAAS;QACT,WAAW;QACX,OAAO;KACR,CAAC,CAAC;IACH,MAAM,KAAK,GAAG,WAAW,CACvB,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CACvB,mBAAmB,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EACjE,CAAC,IAAI,EAAE,SAAS,CAAC,CAClB,CAAC;IAEF,MAAM,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC;QAC/B,KAAK;QACL,MAAM;QACN,QAAQ;QACR,KAAK;QACL,IAAI;QACJ,QAAQ;QACR,WAAW;QACX,IAAI;QACJ,SAAS;KACV,CAAC,CAAC;IAEH,wEAAwE;IACxE,6EAA6E;IAC7E,MAAM,aAAa,GAAG,WAAW,CAAC,GAAG,EAAE;QACrC,MAAM,EAAE,CAAC;QACT,IAAI,CAAC,KAAK,CAAC,CAAC;IACd,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAEnB,wBAAwB,CACtB,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,WAAW,EACX,OAAO,EACP,aAAa,CACd,CAAC;IAEF,MAAM,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,GAAG,gBAAgB,CACrE,SAAS,EACT,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,QAAQ,CACT,CAAC;IAEF,MAAM,OAAO,GAAG,kBAAkB,CAChC,SAAS,EACT,SAAS,EACT,IAAI,EACJ,KAAK,EACL,WAAW,EACX,OAAO,CACR,CAAC;IAEF,OAAO;QACL,GAAG,OAAO;QACV,aAAa;QACb,MAAM;QACN,IAAI;QACJ,iBAAiB;QACjB,uBAAuB;QACvB,QAAQ;QACR,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["import {\n type MutableRefObject,\n type PointerEvent as ReactPointerEvent,\n type RefObject,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { useWindowLayout } from \"./useWindowLayout\";\nimport type { ResizeEdge } from \"./WindowResizeHandle\";\nimport {\n useWindowActions,\n type WindowEntry,\n type WindowGeometry,\n type WindowPosition,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport {\n clampWindowPosition,\n type LiveGeometry,\n MIN_HEIGHT,\n MIN_WIDTH,\n resizeWindowWithinContainer,\n type WindowDragState,\n type WindowResizeState,\n} from \"./windowGeometry\";\n\n// Pointer events cover mouse, touch, and pen alike. The live geometry stays in\n// component state while a gesture runs, so only this window re-renders per\n// frame; the gesture's end commits it to the shared window state once.\nfunction useWindowPointerTracking(\n windowRef: RefObject<HTMLElement | null>,\n dragging: MutableRefObject<WindowDragState | null>,\n resizing: MutableRefObject<WindowResizeState | null>,\n clamp: (x: number, y: number) => WindowPosition,\n setPosition: (value: WindowPosition) => void,\n setSize: (value: WindowSize | null) => void,\n finish: () => void,\n) {\n useEffect(() => {\n // Only the pointer that started a gesture drives it, so a second finger\n // cannot move the window or end the drag.\n function isGesturePointer(event: PointerEvent) {\n const gesture = resizing.current ?? dragging.current;\n return gesture !== null && gesture.pointerId === event.pointerId;\n }\n\n function handlePointerMove(event: PointerEvent) {\n if (!isGesturePointer(event)) {\n return;\n }\n if (resizing.current) {\n const nextFrame = resizeWindowWithinContainer(\n resizing.current,\n event.clientX,\n event.clientY,\n windowRef.current?.parentElement ?? null,\n );\n setPosition(nextFrame.position);\n setSize(nextFrame.size);\n return;\n }\n\n if (dragging.current) {\n setPosition(\n clamp(\n event.clientX - dragging.current.offsetX,\n event.clientY - dragging.current.offsetY,\n ),\n );\n }\n }\n\n function handlePointerEnd(event: PointerEvent) {\n if (!isGesturePointer(event)) {\n return;\n }\n dragging.current = null;\n resizing.current = null;\n finish();\n }\n\n document.addEventListener(\"pointermove\", handlePointerMove);\n document.addEventListener(\"pointerup\", handlePointerEnd);\n document.addEventListener(\"pointercancel\", handlePointerEnd);\n document.addEventListener(\"lostpointercapture\", handlePointerEnd);\n return () => {\n document.removeEventListener(\"pointermove\", handlePointerMove);\n document.removeEventListener(\"pointerup\", handlePointerEnd);\n document.removeEventListener(\"pointercancel\", handlePointerEnd);\n document.removeEventListener(\"lostpointercapture\", handlePointerEnd);\n };\n }, [clamp, dragging, finish, resizing, setPosition, setSize, windowRef]);\n}\n\nfunction useLiveGeometry(entry: WindowEntry) {\n const { setGeometry } = useWindowActions();\n const [position, setPositionState] = useState<WindowPosition | null>(null);\n const [size, setSizeState] = useState<WindowSize | null>(entry.size ?? null);\n // Mirrors the live state so a gesture's end commits the latest frame.\n const live = useRef<LiveGeometry>({\n position: null,\n size: entry.size ?? null,\n });\n\n const setPosition = useCallback((value: WindowPosition) => {\n live.current.position = value;\n setPositionState(value);\n }, []);\n const setSize = useCallback((value: WindowSize | null) => {\n live.current.size = value;\n setSizeState(value);\n }, []);\n const commit = useCallback(() => {\n const committedPosition = live.current.position;\n if (committedPosition) {\n setGeometry(entry.id, {\n position: committedPosition,\n size: live.current.size ?? undefined,\n });\n }\n }, [entry.id, setGeometry]);\n\n // Fit and other window-owned changes must update the live frame before\n // publication: a surface observer can commit again before the passive mirror.\n const applyGeometry = useCallback(\n (geometry: WindowGeometry) => {\n setPosition(geometry.position);\n setSize(geometry.size ?? null);\n commit();\n },\n [commit, setPosition, setSize],\n );\n\n // The committed size is the source of truth between gestures: a restored\n // layout or host call applies it, and clearing it restores the default size.\n useEffect(() => {\n setSize(entry.size ?? null);\n }, [entry.size, setSize]);\n\n return { applyGeometry, commit, live, position, setPosition, setSize, size };\n}\n\n// Stepwise geometry for keyboard move and resize. Steps stay local until the\n// caller commits, like a pointer gesture; restore puts a snapshot back.\nfunction useSteppedGeometry(\n windowRef: RefObject<HTMLElement | null>,\n maximized: boolean,\n live: MutableRefObject<LiveGeometry>,\n clamp: (x: number, y: number) => WindowPosition,\n setPosition: (value: WindowPosition) => void,\n setSize: (value: WindowSize | null) => void,\n) {\n const nudge = useCallback(\n (deltaX: number, deltaY: number) => {\n const current = live.current.position;\n if (!current || maximized) {\n return;\n }\n setPosition(clamp(current.x + deltaX, current.y + deltaY));\n },\n [clamp, live, maximized, setPosition],\n );\n\n const grow = useCallback(\n (deltaWidth: number, deltaHeight: number) => {\n const element = windowRef.current;\n const current = live.current.position;\n if (!element || !current || maximized) {\n return;\n }\n // Step from the size on screen: a requested size below the stylesheet\n // minimums renders at the minimum, so growing from it would show nothing.\n const requested = live.current.size;\n const base = requested\n ? {\n height: Math.max(MIN_HEIGHT, requested.height),\n width: Math.max(MIN_WIDTH, requested.width),\n }\n : { height: element.offsetHeight, width: element.offsetWidth };\n const container = element.parentElement;\n const maxWidth = container\n ? container.clientWidth - current.x\n : Number.POSITIVE_INFINITY;\n const maxHeight = container\n ? container.clientHeight - current.y\n : Number.POSITIVE_INFINITY;\n setSize({\n height: Math.max(\n MIN_HEIGHT,\n Math.min(base.height + deltaHeight, maxHeight),\n ),\n width: Math.max(MIN_WIDTH, Math.min(base.width + deltaWidth, maxWidth)),\n });\n },\n [live, maximized, setSize, windowRef],\n );\n\n const snapshot = useCallback(\n (): LiveGeometry => ({ ...live.current }),\n [live],\n );\n const restore = useCallback(\n (saved: LiveGeometry) => {\n if (saved.position) {\n setPosition(saved.position);\n }\n setSize(saved.size);\n },\n [setPosition, setSize],\n );\n\n return { grow, nudge, restore, snapshot };\n}\n\n// Keeps a gesture's pointer events coming to the window even when the pointer\n// passes over an iframe, whose document would otherwise swallow the release.\n// Synthetic events carry no active pointer, so a failed capture is fine.\nfunction capturePointer(event: ReactPointerEvent) {\n try {\n event.currentTarget.setPointerCapture(event.pointerId);\n } catch {\n // Not an active pointer; the document listeners still track the gesture.\n }\n}\n\n// Starts a drag from the title bar or a resize from an edge or corner. The\n// gesture itself is tracked on the document by useWindowPointerTracking.\nfunction useGestureStarts(\n windowRef: RefObject<HTMLElement | null>,\n maximized: boolean,\n position: WindowPosition | null,\n dragging: MutableRefObject<WindowDragState | null>,\n resizing: MutableRefObject<WindowResizeState | null>,\n) {\n const handlePointerDown = useCallback(\n (event: ReactPointerEvent) => {\n // One gesture at a time: a second pointer pressing the title bar or a\n // resize handle mid-gesture must not take it over.\n if (!position || maximized || dragging.current || resizing.current) {\n return;\n }\n dragging.current = {\n offsetX: event.clientX - position.x,\n offsetY: event.clientY - position.y,\n pointerId: event.pointerId,\n };\n capturePointer(event);\n },\n [dragging, maximized, position, resizing],\n );\n\n const handleResizePointerDown = useCallback(\n (event: ReactPointerEvent, edge: ResizeEdge) => {\n if (\n maximized ||\n !position ||\n !windowRef.current ||\n dragging.current ||\n resizing.current\n ) {\n return;\n }\n event.stopPropagation();\n capturePointer(event);\n const el = windowRef.current;\n const computed = getComputedStyle(el);\n const borderBox = computed.boxSizing === \"border-box\";\n resizing.current = {\n edge,\n pointerId: event.pointerId,\n startX: event.clientX,\n startY: event.clientY,\n startLeft: position.x,\n startTop: position.y,\n startWidth: parseFloat(computed.width),\n startHeight: parseFloat(computed.height),\n borderX: borderBox ? 0 : el.offsetWidth - el.clientWidth,\n borderY: borderBox ? 0 : el.offsetHeight - el.clientHeight,\n };\n },\n [maximized, position, resizing, windowRef],\n );\n\n return { handlePointerDown, handleResizePointerDown };\n}\n\nexport function useWindowGeometry(\n entry: WindowEntry,\n maximized: boolean,\n windowRef: RefObject<HTMLElement | null>,\n) {\n const { applyGeometry, commit, live, position, setPosition, setSize, size } =\n useLiveGeometry(entry);\n const dragging = useRef<WindowDragState | null>(null);\n const resizing = useRef<WindowResizeState | null>(null);\n // Maximizing or minimizing mid-gesture (a second touch on the title bar's\n // controls) abandons the gesture: its frames were measured at the normal\n // size, so the live geometry goes back to the committed geometry.\n useEffect(() => {\n if (!(maximized || entry.minimized)) {\n return;\n }\n if (!dragging.current && !resizing.current) {\n return;\n }\n dragging.current = null;\n resizing.current = null;\n setSize(entry.size ?? null);\n if (entry.position) {\n setPosition(entry.position);\n }\n }, [\n entry.minimized,\n entry.position,\n entry.size,\n maximized,\n setPosition,\n setSize,\n ]);\n const clamp = useCallback(\n (x: number, y: number) =>\n clampWindowPosition(windowRef.current, x, y, live.current.size),\n [live, windowRef],\n );\n\n const { hold } = useWindowLayout({\n clamp,\n commit,\n dragging,\n entry,\n live,\n resizing,\n setPosition,\n size,\n windowRef,\n });\n\n // A finished gesture commits its geometry, then runs any layout it held\n // off (a surface resize mid-gesture), even when the geometry did not change.\n const finishGesture = useCallback(() => {\n commit();\n hold(false);\n }, [commit, hold]);\n\n useWindowPointerTracking(\n windowRef,\n dragging,\n resizing,\n clamp,\n setPosition,\n setSize,\n finishGesture,\n );\n\n const { handlePointerDown, handleResizePointerDown } = useGestureStarts(\n windowRef,\n maximized,\n position,\n dragging,\n resizing,\n );\n\n const stepped = useSteppedGeometry(\n windowRef,\n maximized,\n live,\n clamp,\n setPosition,\n setSize,\n );\n\n return {\n ...stepped,\n applyGeometry,\n commit,\n hold,\n handlePointerDown,\n handleResizePointerDown,\n position,\n size,\n };\n}\n"]}
|