@tearleads/windowing 0.2.0 → 0.2.4
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 +46 -7
- package/createRequiredContext.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/menu/Menu.js.map +1 -1
- package/menu/MenuItem.js.map +1 -1
- package/menu/useContextMenuState.js.map +1 -1
- package/menu/useMenuKeyboard.js.map +1 -1
- package/package.json +6 -1
- package/sidebar/SidebarResize.js.map +1 -1
- package/window/CurrentWindowContext.d.ts +17 -1
- package/window/CurrentWindowContext.js +28 -2
- package/window/CurrentWindowContext.js.map +1 -1
- package/window/Window.css +1 -1
- package/window/Window.js +6 -2
- package/window/Window.js.map +1 -1
- package/window/WindowBody.css +17 -0
- package/window/WindowBody.js.map +1 -1
- package/window/WindowChromeActions.js.map +1 -1
- package/window/WindowCloseButton.js.map +1 -1
- package/window/WindowMaximizeButton.js.map +1 -1
- package/window/WindowMenuBar.js.map +1 -1
- package/window/WindowMenuContext.js.map +1 -1
- package/window/WindowMinimizeButton.js.map +1 -1
- package/window/WindowResizeHandle.js.map +1 -1
- package/window/WindowSidebar.js.map +1 -1
- package/window/WindowSidebarContext.js.map +1 -1
- package/window/WindowStateProvider/WindowStateProvider.js.map +1 -1
- package/window/WindowStateProvider/context.js.map +1 -1
- package/window/WindowStateProvider/index.js.map +1 -1
- package/window/WindowStateProvider/types.js.map +1 -1
- package/window/WindowStateProvider/useWindowActions.js.map +1 -1
- package/window/WindowStateProvider/useWindowStateActions.js.map +1 -1
- package/window/WindowStateProvider/useWindowStateData.js.map +1 -1
- package/window/WindowStateProvider/util/bringWindowToFront.js.map +1 -1
- package/window/WindowStateProvider/util/createWindowEntry.js.map +1 -1
- package/window/WindowStateProvider/util/findAdjacentWindow.js.map +1 -1
- package/window/WindowStateProvider/util/findTopWindow.js.map +1 -1
- package/window/WindowStateProvider/util/getMaxWindowZIndex.js.map +1 -1
- package/window/WindowStateProvider/util/index.js.map +1 -1
- package/window/WindowStateProvider/util/swapWindowZIndexes.js.map +1 -1
- package/window/WindowStateProvider/util/updateWindowFlag.js.map +1 -1
- package/window/WindowStatusBar.js.map +1 -1
- package/window/WindowTitleBar.js.map +1 -1
- package/window/WindowToolBar.js.map +1 -1
- package/window/useWindowGeometry.js.map +1 -1
- package/window/useWindowItemRegistration.js.map +1 -1
- package/window/useWindowItemRegistry.js.map +1 -1
- package/window/useWindowKeyboardGeometry.js +14 -1
- package/window/useWindowKeyboardGeometry.js.map +1 -1
- package/window/useWindowLayout.js.map +1 -1
- package/window/useWindowToolbarReservationRegistry.js.map +1 -1
- package/window/windowGeometry.js.map +1 -1
- package/window/windowMenuRegistrations.js.map +1 -1
package/README.md
CHANGED
|
@@ -78,8 +78,9 @@ resizes a window programmatically.
|
|
|
78
78
|
- **`appId`** — an opaque string a host attaches when creating a window. The
|
|
79
79
|
window layer only stores and compares it; the host interprets it.
|
|
80
80
|
|
|
81
|
-
Windows register their own menu items, title-bar actions, a Back action,
|
|
82
|
-
sidebar through the `useWindow*` hooks, from inside the
|
|
81
|
+
Windows register their own menu items, title-bar actions, a Back action, a
|
|
82
|
+
sidebar, and a background through the `useWindow*` hooks, from inside the
|
|
83
|
+
window's content.
|
|
83
84
|
|
|
84
85
|
## Toolbar
|
|
85
86
|
|
|
@@ -118,6 +119,29 @@ window. That rule has zero specificity: any `:root` rule, theme, or scoped block
|
|
|
118
119
|
the host writes overrides it. Tearleads overrides them with its own themes in
|
|
119
120
|
`packages/ui/src/styles.css` and `packages/app/src/shell/layout/AppChrome.css`.
|
|
120
121
|
|
|
122
|
+
Several defaults derive from `--color-dark`, the foreground: the window edge
|
|
123
|
+
(`--border-strong-color`), the hover and selection chip (`--emphasis-surface`
|
|
124
|
+
and `--emphasis-text`), and `--color-hairline`. A dark theme that sets only the
|
|
125
|
+
`--color-*` primitives gets near-white edges and chips, so set these too, as
|
|
126
|
+
Tearleads' dark theme does.
|
|
127
|
+
|
|
128
|
+
The window paints its background, behind its body and sidebar, with
|
|
129
|
+
`--window-background`. `tokens.css` leaves it unset, so it falls back to
|
|
130
|
+
`--color-light` wherever that is set, including a scoped theme. Content sets
|
|
131
|
+
its own window's background with `useWindowBackground`, while it is mounted;
|
|
132
|
+
`undefined` keeps the default. A document viewer can use it to set its page
|
|
133
|
+
apart from the window around it:
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
useWindowBackground(`color-mix(in srgb, ${foreground} 10%, ${page})`);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The window rounds its corners but does not clip its content, since its resize
|
|
140
|
+
handles and menus reach past its edges. While no visible status bar sits below
|
|
141
|
+
it, the window body rounds its own bottom corners to the window's inner radius
|
|
142
|
+
and clips its content there, so content painted edge to edge stays inside the
|
|
143
|
+
border.
|
|
144
|
+
|
|
121
145
|
Windows and menus lay out `border-box`, the box model their sizes assume. Since
|
|
122
146
|
`box-sizing` does not inherit, a zero-specificity rule sets it on the window or
|
|
123
147
|
menu and everything inside, including window content; any host rule overrides
|
|
@@ -145,8 +169,21 @@ in them, which a consumer's typecheck could not resolve. The smoke script
|
|
|
145
169
|
installs the lowest React the peer range admits, typechecks against the
|
|
146
170
|
declarations with TypeScript's defaults, and bundles a named import with webpack.
|
|
147
171
|
|
|
148
|
-
|
|
149
|
-
|
|
172
|
+
Merging to `main` publishes. When `packages/windowing` changes there,
|
|
173
|
+
`.github/workflows/windowing-publish.yml` publishes the version in
|
|
174
|
+
`package.json` if it is newer than npm's `latest`; a merge that leaves the
|
|
175
|
+
version alone, a re-run, or a run that finishes after a newer release succeeds
|
|
176
|
+
without publishing (`scripts/publishDecision.ts` makes that call). The workflow
|
|
177
|
+
authenticates with
|
|
178
|
+
[npm trusted publishing](https://docs.npmjs.com/trusted-publishers): npm accepts
|
|
179
|
+
the job's GitHub OIDC token instead of an npm token, and attaches provenance to
|
|
180
|
+
each version. On npmjs.com the package's trusted publisher names the `a2f0`
|
|
181
|
+
owner, the `tearleads` repository, the `windowing-publish.yml` workflow, and
|
|
182
|
+
the `npm` environment, which the repository restricts to `main`. Renaming the
|
|
183
|
+
workflow or the environment breaks publishing until that setting matches.
|
|
184
|
+
|
|
185
|
+
To publish by hand instead, run from the repository root with an account that
|
|
186
|
+
owns the `@tearleads` npm scope:
|
|
150
187
|
|
|
151
188
|
```sh
|
|
152
189
|
npm login --registry https://registry.npmjs.org
|
|
@@ -158,7 +195,8 @@ bun run publish:npm
|
|
|
158
195
|
standalone windowing extraction. That set is only `@tearleads/windowing`: it has
|
|
159
196
|
no workspace dependencies, and its React peers and Phosphor dependency already
|
|
160
197
|
exist on npm. `scripts/publishWindowing.sh` is the package-specific command,
|
|
161
|
-
also available as `bun run --cwd packages/windowing publish:npm
|
|
198
|
+
also available as `bun run --cwd packages/windowing publish:npm`; the workflow
|
|
199
|
+
runs it too.
|
|
162
200
|
|
|
163
201
|
Both commands rebuild into a fresh temporary directory, publish its generated
|
|
164
202
|
consumer manifest with public access to `https://registry.npmjs.org`, and remove
|
|
@@ -177,5 +215,6 @@ an external consumer. It needs the network to install the consumer dependencies.
|
|
|
177
215
|
|
|
178
216
|
`ship-pr` bumps changed workspace packages before review and merge; the generated
|
|
179
217
|
manifest copies `version` from `package.json`. For a release outside that flow,
|
|
180
|
-
bump the version yourself before publishing. The
|
|
181
|
-
|
|
218
|
+
bump the version yourself before publishing. The manifest names this repository,
|
|
219
|
+
which npm requires of a version with provenance, and declares
|
|
220
|
+
`"license": "UNLICENSED"` until a license is chosen.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRequiredContext.js","sourceRoot":"","sources":["../../home/
|
|
1
|
+
{"version":3,"file":"createRequiredContext.js","sourceRoot":"","sources":["../../home/runner/work/tearleads/tearleads/packages/windowing/src/createRequiredContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAWhE;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACnC,YAAoB;IAEpB,MAAM,OAAO,GAAG,aAAa,CAAW,IAAI,CAAC,CAAC;IAE9C,SAAS,WAAW;QAClB,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAED,SAAS,WAAW;QAClB,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AAC/C,CAAC","sourcesContent":["import { type Context, createContext, useContext } from \"react\";\n\nexport interface RequiredContext<T> {\n /** The raw context, for rendering `context.Provider` in the owning provider. */\n context: Context<T | null>;\n /** Non-throwing twin for surfaces that may render outside the provider. */\n useOptional: () => T | null;\n /** Reads the context value, throwing `errorMessage` without a provider. */\n useRequired: () => T;\n}\n\n/**\n * A context whose value is mandatory for consumers. Callers export\n * `useRequired`/`useOptional` under their own hook names, so every\n * provider-guard hook shares this one accessor pair instead of restating the\n * `useContext`-then-throw boilerplate.\n */\nexport function createRequiredContext<T>(\n errorMessage: string,\n): RequiredContext<T> {\n const context = createContext<T | null>(null);\n\n function useOptional(): T | null {\n return useContext(context);\n }\n\n function useRequired(): T {\n const value = useContext(context);\n if (value === null) {\n throw new Error(errorMessage);\n }\n return value;\n }\n\n return { context, useOptional, useRequired };\n}\n"]}
|
package/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { Menu, type MenuPosition } from "./menu/Menu.js";
|
|
|
3
3
|
export { MenuItem, type MenuItemProps } from "./menu/MenuItem.js";
|
|
4
4
|
export { type ContextMenuState, useContextMenuPositionState, useContextMenuState, } from "./menu/useContextMenuState.js";
|
|
5
5
|
export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.js";
|
|
6
|
-
export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, } from "./window/CurrentWindowContext.js";
|
|
6
|
+
export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, useWindowBackground, } from "./window/CurrentWindowContext.js";
|
|
7
7
|
export { Window, type WindowContentBoundary } from "./window/Window.js";
|
|
8
8
|
export { WindowTitleBarActionButtons } from "./window/WindowChromeActions.js";
|
|
9
9
|
export { WindowCloseButton } from "./window/WindowCloseButton.js";
|
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export { Menu } from "./menu/Menu.js";
|
|
|
6
6
|
export { MenuItem } from "./menu/MenuItem.js";
|
|
7
7
|
export { useContextMenuPositionState, useContextMenuState, } from "./menu/useContextMenuState.js";
|
|
8
8
|
export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.js";
|
|
9
|
-
export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, } from "./window/CurrentWindowContext.js";
|
|
9
|
+
export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, useWindowBackground, } from "./window/CurrentWindowContext.js";
|
|
10
10
|
export { Window } from "./window/Window.js";
|
|
11
11
|
export { WindowTitleBarActionButtons } from "./window/WindowChromeActions.js";
|
|
12
12
|
export { WindowCloseButton } from "./window/WindowCloseButton.js";
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../home/
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../home/runner/work/tearleads/tearleads/packages/windowing/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,6EAA6E;AAC7E,sEAAsE;AACtE,OAAO,EACL,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,IAAI,EAAqB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAsB,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAEL,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,MAAM,EAA8B,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,6BAA6B,EAC7B,uBAAuB,EACvB,wBAAwB,EACxB,2BAA2B,EAC3B,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAQlB,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["import \"./tokens.css\";\n\n// The public windowing API: window state, window chrome and its registration\n// hooks, and the menu and sidebar primitives the chrome renders with.\nexport {\n createRequiredContext,\n type RequiredContext,\n} from \"./createRequiredContext\";\nexport { Menu, type MenuPosition } from \"./menu/Menu\";\nexport { MenuItem, type MenuItemProps } from \"./menu/MenuItem\";\nexport {\n type ContextMenuState,\n useContextMenuPositionState,\n useContextMenuState,\n} from \"./menu/useContextMenuState\";\nexport { SidebarResizeHandle, useSidebarResize } from \"./sidebar/SidebarResize\";\nexport {\n CurrentWindowProvider,\n useCurrentWindow,\n useSuppressWindowToolbar,\n useWindowBackground,\n} from \"./window/CurrentWindowContext\";\nexport { Window, type WindowContentBoundary } from \"./window/Window\";\nexport { WindowTitleBarActionButtons } from \"./window/WindowChromeActions\";\nexport { WindowCloseButton } from \"./window/WindowCloseButton\";\nexport {\n useWindowBackAction,\n useWindowBackActionValue,\n useWindowFileMenuItem,\n useWindowRefreshMenuItem,\n useWindowRefreshMenuItemValue,\n useWindowTitleBarAction,\n useWindowTitleBarActions,\n useWindowToolbarReservation,\n useWindowViewMenuItem,\n WindowMenuProvider,\n} from \"./window/WindowMenuContext\";\nexport {\n hasWindowSidebar,\n useRegisteredWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./window/WindowSidebarContext\";\nexport {\n findTopWindow,\n useWindowActions,\n useWindowStateData,\n type WindowCreateOptions,\n type WindowEntry,\n type WindowGeometry,\n type WindowPosition,\n type WindowSize,\n type WindowStateActions,\n type WindowStateData,\n WindowStateProvider,\n} from \"./window/WindowStateProvider\";\nexport { WindowToolBar } from \"./window/WindowToolBar\";\n"]}
|
package/menu/Menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Menu.js","sourceRoot":"","sources":["../../../home/a2f0/github/tearleads/packages/windowing/src/menu/Menu.tsx"],"names":[],"mappings":";AAAA,OAAO,EAIL,SAAS,EACT,cAAc,EACd,eAAe,EACf,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAClC,MAAM,sBAAsB,GAAkB;IAC5C,IAAI,EAAE,uBAAuB;IAC7B,aAAa,EAAE,MAAM;IACrB,GAAG,EAAE,uBAAuB;IAC5B,UAAU,EAAE,QAAQ;CACrB,CAAC;AAEF,2EAA2E;AAC3E,2EAA2E;AAC3E,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAEvC,SAAS,SAAS,CAAC,OAAoB;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AAE,SAAS,EAChB,QAAQ,EAAE,CAAC,CAAC,YAEX,QAAQ,GACL,EACN,QAAQ,CAAC,IAAI,CACd,CAAC;AACJ,CAAC","sourcesContent":["import {\n type CSSProperties,\n type PropsWithChildren,\n type RefObject,\n useEffect,\n useEffectEvent,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport \"./Menu.css\";\nimport { useMenuKeyboard } from \"./useMenuKeyboard\";\n\nconst MENU_VIEWPORT_MARGIN_PX = 8;\nconst MEASUREMENT_MENU_STYLE: CSSProperties = {\n left: MENU_VIEWPORT_MARGIN_PX,\n pointerEvents: \"none\",\n top: MENU_VIEWPORT_MARGIN_PX,\n visibility: \"hidden\",\n};\n\n// Fractional layout or zoom can report a spurious pixel of overflow; treat\n// that as fitting, since a false positive hands touch panning to the page.\nconst SCROLL_OVERFLOW_TOLERANCE_PX = 1;\n\nfunction overflows(element: HTMLElement): boolean {\n return (\n element.scrollHeight > element.clientHeight + SCROLL_OVERFLOW_TOLERANCE_PX\n );\n}\n\n/**\n * Whether touch should be allowed to pan inside the menu: its own box scrolls,\n * or a descendant scroll container (a select menu's option list) does. The\n * menu box is a scroll container by its stylesheet; descendants qualify by\n * their computed overflow so a plain overflowing block does not count.\n */\nfunction hasTouchScrollableContent(menu: HTMLElement): boolean {\n if (overflows(menu)) {\n return true;\n }\n\n for (const element of Array.from(menu.querySelectorAll<HTMLElement>(\"*\"))) {\n if (!overflows(element)) {\n continue;\n }\n const overflowY = getComputedStyle(element).overflowY;\n if (overflowY === \"auto\" || overflowY === \"scroll\") {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Dismiss the menu on a pointer press or a scroll outside it. The closer is\n * read through an effect event: consumers commonly pass an inline one, and\n * the document listeners should subscribe once, not on every render.\n */\nfunction useMenuOutsideDismissal(\n menuRef: RefObject<HTMLDivElement | null>,\n onClose: () => void,\n): void {\n const close = useEffectEvent(onClose);\n\n useEffect(() => {\n function handleClick(e: MouseEvent) {\n const target = e.target;\n if (!(target instanceof Node)) {\n close();\n return;\n }\n\n if (menuRef.current && !menuRef.current.contains(target)) {\n close();\n }\n }\n document.addEventListener(\"mousedown\", handleClick);\n return () => document.removeEventListener(\"mousedown\", handleClick);\n }, [menuRef]);\n\n // The menu is anchored once, from its trigger's position, so a scroll\n // anywhere else would leave it floating where the trigger used to be. Close\n // it instead. Scrolls inside the menu — its own overflow, or a list it\n // hosts — are the menu working as intended. Capture phase, because scroll\n // events do not bubble. The check covers this menu's own subtree only: a\n // nested Menu is portaled to the body too, so scrolling one would close its\n // parent. Nothing nests menus today; revisit here if that changes.\n useEffect(() => {\n function handleScroll(e: Event) {\n const target = e.target;\n if (target instanceof Node && menuRef.current?.contains(target)) {\n return;\n }\n close();\n }\n document.addEventListener(\"scroll\", handleScroll, true);\n return () => document.removeEventListener(\"scroll\", handleScroll, true);\n }, [menuRef]);\n}\n\nexport interface MenuPosition {\n x: number;\n y: number;\n}\n\ninterface MenuPlacement {\n anchorDirection: \"up\" | \"down\";\n anchorX: number;\n anchorY: number;\n left: number;\n maxHeight: number | undefined;\n maxWidth: number | undefined;\n measured: boolean;\n top: number;\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\nfunction createInitialMenuPlacement(\n position: MenuPosition,\n direction: \"up\" | \"down\",\n): MenuPlacement {\n return {\n anchorDirection: direction,\n anchorX: position.x,\n anchorY: position.y,\n left: position.x,\n maxHeight: undefined,\n maxWidth: undefined,\n measured: false,\n top: position.y,\n };\n}\n\nfunction placeMenuInViewport(input: {\n direction: \"up\" | \"down\";\n height: number;\n position: MenuPosition;\n viewportHeight: number;\n viewportWidth: number;\n width: number;\n}): MenuPlacement {\n const availableWidth = Math.max(\n 0,\n input.viewportWidth - MENU_VIEWPORT_MARGIN_PX * 2,\n );\n const availableHeight = Math.max(\n 0,\n input.viewportHeight - MENU_VIEWPORT_MARGIN_PX * 2,\n );\n const boundedWidth = Math.min(input.width, availableWidth);\n const boundedHeight = Math.min(input.height, availableHeight);\n const maxLeft = Math.max(\n MENU_VIEWPORT_MARGIN_PX,\n input.viewportWidth - MENU_VIEWPORT_MARGIN_PX - boundedWidth,\n );\n const maxTop = Math.max(\n MENU_VIEWPORT_MARGIN_PX,\n input.viewportHeight - MENU_VIEWPORT_MARGIN_PX - boundedHeight,\n );\n const preferredTop =\n input.direction === \"up\"\n ? input.position.y - boundedHeight\n : input.position.y;\n\n return {\n anchorDirection: input.direction,\n anchorX: input.position.x,\n anchorY: input.position.y,\n left: clamp(input.position.x, MENU_VIEWPORT_MARGIN_PX, maxLeft),\n maxHeight: availableHeight > 0 ? availableHeight : undefined,\n maxWidth: availableWidth > 0 ? availableWidth : undefined,\n measured: true,\n top: clamp(preferredTop, MENU_VIEWPORT_MARGIN_PX, maxTop),\n };\n}\n\nexport function Menu({\n position,\n onClose,\n direction = \"up\",\n keyboardNavigation = true,\n children,\n}: PropsWithChildren<{\n position: MenuPosition;\n onClose: () => void;\n direction?: \"up\" | \"down\";\n keyboardNavigation?: boolean;\n}>) {\n const menuRef = useRef<HTMLDivElement>(null);\n useMenuOutsideDismissal(menuRef, onClose);\n const { x, y } = position;\n const [placement, setPlacement] = useState(() =>\n createInitialMenuPlacement(position, direction),\n );\n // Whether anything in the menu scrolls, so the stylesheet can let touch pan\n // it while consuming swipes on a menu that fits (see Menu.css).\n const [scrollable, setScrollable] = useState(false);\n\n // Re-measure after every commit as well as on resize below: children can be\n // swapped or filtered while the menu is open without its box changing size,\n // which moves scrollHeight but not the ResizeObserver. setState bails out\n // when the answer is unchanged.\n useLayoutEffect(() => {\n const menu = menuRef.current;\n if (menu) {\n setScrollable(hasTouchScrollableContent(menu));\n }\n });\n\n useLayoutEffect(() => {\n const menu = menuRef.current;\n if (!menu) {\n return;\n }\n\n const updatePlacement = () => {\n const rect = menu.getBoundingClientRect();\n setPlacement(\n placeMenuInViewport({\n direction,\n height: rect.height,\n position,\n viewportHeight: window.innerHeight,\n viewportWidth: window.innerWidth,\n width: rect.width,\n }),\n );\n setScrollable(hasTouchScrollableContent(menu));\n };\n updatePlacement();\n const observer = new ResizeObserver(updatePlacement);\n observer.observe(menu);\n window.addEventListener(\"resize\", updatePlacement);\n return () => {\n observer.disconnect();\n window.removeEventListener(\"resize\", updatePlacement);\n };\n }, [x, y, direction]);\n\n const placementMatchesAnchor =\n placement.measured &&\n placement.anchorX === position.x &&\n placement.anchorY === position.y &&\n placement.anchorDirection === direction;\n useMenuKeyboard(\n menuRef,\n placementMatchesAnchor && keyboardNavigation,\n onClose,\n );\n const menuStyle: CSSProperties = placementMatchesAnchor\n ? {\n left: placement.left,\n maxHeight: placement.maxHeight,\n maxWidth: placement.maxWidth,\n top: placement.top,\n }\n : MEASUREMENT_MENU_STYLE;\n\n return createPortal(\n <div\n ref={menuRef}\n className=\"menu\"\n data-scrollable={scrollable || undefined}\n style={menuStyle}\n tabIndex={-1}\n >\n {children}\n </div>,\n document.body,\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Menu.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/Menu.tsx"],"names":[],"mappings":";AAAA,OAAO,EAIL,SAAS,EACT,cAAc,EACd,eAAe,EACf,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAClC,MAAM,sBAAsB,GAAkB;IAC5C,IAAI,EAAE,uBAAuB;IAC7B,aAAa,EAAE,MAAM;IACrB,GAAG,EAAE,uBAAuB;IAC5B,UAAU,EAAE,QAAQ;CACrB,CAAC;AAEF,2EAA2E;AAC3E,2EAA2E;AAC3E,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAEvC,SAAS,SAAS,CAAC,OAAoB;IACrC,OAAO,CAC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B,QAAQ,EAAE,CAAC,CAAC,YAEX,QAAQ,GACL,EACN,QAAQ,CAAC,IAAI,CACd,CAAC;AACJ,CAAC","sourcesContent":["import {\n type CSSProperties,\n type PropsWithChildren,\n type RefObject,\n useEffect,\n useEffectEvent,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport \"./Menu.css\";\nimport { useMenuKeyboard } from \"./useMenuKeyboard\";\n\nconst MENU_VIEWPORT_MARGIN_PX = 8;\nconst MEASUREMENT_MENU_STYLE: CSSProperties = {\n left: MENU_VIEWPORT_MARGIN_PX,\n pointerEvents: \"none\",\n top: MENU_VIEWPORT_MARGIN_PX,\n visibility: \"hidden\",\n};\n\n// Fractional layout or zoom can report a spurious pixel of overflow; treat\n// that as fitting, since a false positive hands touch panning to the page.\nconst SCROLL_OVERFLOW_TOLERANCE_PX = 1;\n\nfunction overflows(element: HTMLElement): boolean {\n return (\n element.scrollHeight > element.clientHeight + SCROLL_OVERFLOW_TOLERANCE_PX\n );\n}\n\n/**\n * Whether touch should be allowed to pan inside the menu: its own box scrolls,\n * or a descendant scroll container (a select menu's option list) does. The\n * menu box is a scroll container by its stylesheet; descendants qualify by\n * their computed overflow so a plain overflowing block does not count.\n */\nfunction hasTouchScrollableContent(menu: HTMLElement): boolean {\n if (overflows(menu)) {\n return true;\n }\n\n for (const element of Array.from(menu.querySelectorAll<HTMLElement>(\"*\"))) {\n if (!overflows(element)) {\n continue;\n }\n const overflowY = getComputedStyle(element).overflowY;\n if (overflowY === \"auto\" || overflowY === \"scroll\") {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Dismiss the menu on a pointer press or a scroll outside it. The closer is\n * read through an effect event: consumers commonly pass an inline one, and\n * the document listeners should subscribe once, not on every render.\n */\nfunction useMenuOutsideDismissal(\n menuRef: RefObject<HTMLDivElement | null>,\n onClose: () => void,\n): void {\n const close = useEffectEvent(onClose);\n\n useEffect(() => {\n function handleClick(e: MouseEvent) {\n const target = e.target;\n if (!(target instanceof Node)) {\n close();\n return;\n }\n\n if (menuRef.current && !menuRef.current.contains(target)) {\n close();\n }\n }\n document.addEventListener(\"mousedown\", handleClick);\n return () => document.removeEventListener(\"mousedown\", handleClick);\n }, [menuRef]);\n\n // The menu is anchored once, from its trigger's position, so a scroll\n // anywhere else would leave it floating where the trigger used to be. Close\n // it instead. Scrolls inside the menu — its own overflow, or a list it\n // hosts — are the menu working as intended. Capture phase, because scroll\n // events do not bubble. The check covers this menu's own subtree only: a\n // nested Menu is portaled to the body too, so scrolling one would close its\n // parent. Nothing nests menus today; revisit here if that changes.\n useEffect(() => {\n function handleScroll(e: Event) {\n const target = e.target;\n if (target instanceof Node && menuRef.current?.contains(target)) {\n return;\n }\n close();\n }\n document.addEventListener(\"scroll\", handleScroll, true);\n return () => document.removeEventListener(\"scroll\", handleScroll, true);\n }, [menuRef]);\n}\n\nexport interface MenuPosition {\n x: number;\n y: number;\n}\n\ninterface MenuPlacement {\n anchorDirection: \"up\" | \"down\";\n anchorX: number;\n anchorY: number;\n left: number;\n maxHeight: number | undefined;\n maxWidth: number | undefined;\n measured: boolean;\n top: number;\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\nfunction createInitialMenuPlacement(\n position: MenuPosition,\n direction: \"up\" | \"down\",\n): MenuPlacement {\n return {\n anchorDirection: direction,\n anchorX: position.x,\n anchorY: position.y,\n left: position.x,\n maxHeight: undefined,\n maxWidth: undefined,\n measured: false,\n top: position.y,\n };\n}\n\nfunction placeMenuInViewport(input: {\n direction: \"up\" | \"down\";\n height: number;\n position: MenuPosition;\n viewportHeight: number;\n viewportWidth: number;\n width: number;\n}): MenuPlacement {\n const availableWidth = Math.max(\n 0,\n input.viewportWidth - MENU_VIEWPORT_MARGIN_PX * 2,\n );\n const availableHeight = Math.max(\n 0,\n input.viewportHeight - MENU_VIEWPORT_MARGIN_PX * 2,\n );\n const boundedWidth = Math.min(input.width, availableWidth);\n const boundedHeight = Math.min(input.height, availableHeight);\n const maxLeft = Math.max(\n MENU_VIEWPORT_MARGIN_PX,\n input.viewportWidth - MENU_VIEWPORT_MARGIN_PX - boundedWidth,\n );\n const maxTop = Math.max(\n MENU_VIEWPORT_MARGIN_PX,\n input.viewportHeight - MENU_VIEWPORT_MARGIN_PX - boundedHeight,\n );\n const preferredTop =\n input.direction === \"up\"\n ? input.position.y - boundedHeight\n : input.position.y;\n\n return {\n anchorDirection: input.direction,\n anchorX: input.position.x,\n anchorY: input.position.y,\n left: clamp(input.position.x, MENU_VIEWPORT_MARGIN_PX, maxLeft),\n maxHeight: availableHeight > 0 ? availableHeight : undefined,\n maxWidth: availableWidth > 0 ? availableWidth : undefined,\n measured: true,\n top: clamp(preferredTop, MENU_VIEWPORT_MARGIN_PX, maxTop),\n };\n}\n\nexport function Menu({\n position,\n onClose,\n direction = \"up\",\n keyboardNavigation = true,\n children,\n}: PropsWithChildren<{\n position: MenuPosition;\n onClose: () => void;\n direction?: \"up\" | \"down\";\n keyboardNavigation?: boolean;\n}>) {\n const menuRef = useRef<HTMLDivElement>(null);\n useMenuOutsideDismissal(menuRef, onClose);\n const { x, y } = position;\n const [placement, setPlacement] = useState(() =>\n createInitialMenuPlacement(position, direction),\n );\n // Whether anything in the menu scrolls, so the stylesheet can let touch pan\n // it while consuming swipes on a menu that fits (see Menu.css).\n const [scrollable, setScrollable] = useState(false);\n\n // Re-measure after every commit as well as on resize below: children can be\n // swapped or filtered while the menu is open without its box changing size,\n // which moves scrollHeight but not the ResizeObserver. setState bails out\n // when the answer is unchanged.\n useLayoutEffect(() => {\n const menu = menuRef.current;\n if (menu) {\n setScrollable(hasTouchScrollableContent(menu));\n }\n });\n\n useLayoutEffect(() => {\n const menu = menuRef.current;\n if (!menu) {\n return;\n }\n\n const updatePlacement = () => {\n const rect = menu.getBoundingClientRect();\n setPlacement(\n placeMenuInViewport({\n direction,\n height: rect.height,\n position,\n viewportHeight: window.innerHeight,\n viewportWidth: window.innerWidth,\n width: rect.width,\n }),\n );\n setScrollable(hasTouchScrollableContent(menu));\n };\n updatePlacement();\n const observer = new ResizeObserver(updatePlacement);\n observer.observe(menu);\n window.addEventListener(\"resize\", updatePlacement);\n return () => {\n observer.disconnect();\n window.removeEventListener(\"resize\", updatePlacement);\n };\n }, [x, y, direction]);\n\n const placementMatchesAnchor =\n placement.measured &&\n placement.anchorX === position.x &&\n placement.anchorY === position.y &&\n placement.anchorDirection === direction;\n useMenuKeyboard(\n menuRef,\n placementMatchesAnchor && keyboardNavigation,\n onClose,\n );\n const menuStyle: CSSProperties = placementMatchesAnchor\n ? {\n left: placement.left,\n maxHeight: placement.maxHeight,\n maxWidth: placement.maxWidth,\n top: placement.top,\n }\n : MEASUREMENT_MENU_STYLE;\n\n return createPortal(\n <div\n ref={menuRef}\n className=\"menu\"\n data-scrollable={scrollable || undefined}\n style={menuStyle}\n tabIndex={-1}\n >\n {children}\n </div>,\n document.body,\n );\n}\n"]}
|
package/menu/MenuItem.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuItem.js","sourceRoot":"","sources":["../../../home/
|
|
1
|
+
{"version":3,"file":"MenuItem.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/MenuItem.tsx"],"names":[],"mappings":";AAUA,MAAM,UAAU,QAAQ,CAAC,EACvB,IAAI,EAAE,aAAa,EACnB,KAAK,EACL,QAAQ,EACR,OAAO,GACO;IACd,OAAO,CACL,kBAAQ,IAAI,EAAC,QAAQ,EAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,aACvD,aAAa,IAAI,CAChB,KAAC,aAAa,mBACA,MAAM,EAClB,SAAS,EAAC,gBAAgB,EAC1B,SAAS,EAAC,OAAO,EACjB,IAAI,EAAE,EAAE,EACR,MAAM,EAAC,SAAS,GAChB,CACH,EACD,eAAM,SAAS,EAAC,iBAAiB,YAAE,KAAK,GAAQ,IACzC,CACV,CAAC;AACJ,CAAC","sourcesContent":["import type { Icon } from \"@phosphor-icons/react\";\nimport type { MouseEventHandler } from \"react\";\n\nexport interface MenuItemProps {\n icon?: Icon;\n label: string;\n disabled?: boolean;\n onClick: MouseEventHandler<HTMLButtonElement>;\n}\n\nexport function MenuItem({\n icon: IconComponent,\n label,\n disabled,\n onClick,\n}: MenuItemProps) {\n return (\n <button type=\"button\" disabled={disabled} onClick={onClick}>\n {IconComponent && (\n <IconComponent\n aria-hidden=\"true\"\n className=\"menu-item-icon\"\n focusable=\"false\"\n size={16}\n weight=\"regular\"\n />\n )}\n <span className=\"menu-item-label\">{label}</span>\n </button>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useContextMenuState.js","sourceRoot":"","sources":["../../../home/
|
|
1
|
+
{"version":3,"file":"useContextMenuState.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/useContextMenuState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAc/D;;;;;;;;;;GAUG;AACH,SAAS,sBAAsB,CAAC,KAA8B;IAC5D,IAAI,KAAK,CAAC,OAAO,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,KAAK,CAAC,EAAE,CAAC;QAC/C,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAChD,CAAC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,aAAa,CAAC,qBAAqB,EAAE,CAAC;IACzD,OAAO,EAAE,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAe,MAEjD;IACC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAC5C,IAAI,CACL,CAAC;IACF,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC;IAE9B,MAAM,eAAe,GAAG,WAAW,CACjC,CAAC,KAA8B,EAAE,EAAO,EAAE,EAAE;QAC1C,KAAK,CAAC,cAAc,EAAE,CAAC;QACvB,KAAK,CAAC,eAAe,EAAE,CAAC;QACxB,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;QACb,cAAc,CAAC;YACb,EAAE;YACF,QAAQ,EAAE,sBAAsB,CAAC,KAAK,CAAC;SACxC,CAAC,CAAC;IACL,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,MAAM,gBAAgB,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAErE,OAAO;QACL,gBAAgB;QAChB,WAAW;QACX,eAAe;KAChB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAsB,IAAI,CAAC,CAAC;IAC1E,MAAM,gBAAgB,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IACrE,MAAM,iBAAiB,GAAG,WAAW,CACnC,CAAC,QAAsB,EAAE,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,EACpD,EAAE,CACH,CAAC;IAEF,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC;AAC9D,CAAC","sourcesContent":["import { type MouseEvent, useCallback, useState } from \"react\";\nimport type { MenuPosition } from \"./Menu\";\n\nexport interface ContextMenuState<TId = string> {\n id: TId;\n position: MenuPosition;\n}\n\ninterface ContextMenuStateModel<TId = string> {\n closeContextMenu: () => void;\n contextMenu: ContextMenuState<TId> | null;\n openContextMenu: (event: MouseEvent<HTMLElement>, id: TId) => void;\n}\n\n/**\n * Where to open the menu: the pointer, or — when the event carries no pointer\n * position — the trigger's own box.\n *\n * Keyboard activation (Enter/Space on a kebab, the context-menu key on a row)\n * dispatches with 0,0 client coordinates, which would pin the menu to the\n * viewport's top-left corner, far from the control that opened it. Anchoring\n * under the trigger instead matches what the standalone kebab menus already do\n * (see MiniAppRowActionsButton's callers). A real click at exactly 0,0 lands in\n * the very corner of the window, where none of these triggers can sit.\n */\nfunction getContextMenuPosition(event: MouseEvent<HTMLElement>): MenuPosition {\n if (event.clientX !== 0 || event.clientY !== 0) {\n return { x: event.clientX, y: event.clientY };\n }\n\n const rect = event.currentTarget.getBoundingClientRect();\n return { x: rect.left, y: rect.bottom };\n}\n\nexport function useContextMenuState<TId = string>(params?: {\n onOpen?: (id: TId) => void;\n}): ContextMenuStateModel<TId> {\n const [contextMenu, setContextMenu] = useState<ContextMenuState<TId> | null>(\n null,\n );\n const onOpen = params?.onOpen;\n\n const openContextMenu = useCallback(\n (event: MouseEvent<HTMLElement>, id: TId) => {\n event.preventDefault();\n event.stopPropagation();\n onOpen?.(id);\n setContextMenu({\n id,\n position: getContextMenuPosition(event),\n });\n },\n [onOpen],\n );\n\n const closeContextMenu = useCallback(() => setContextMenu(null), []);\n\n return {\n closeContextMenu,\n contextMenu,\n openContextMenu,\n };\n}\n\nexport function useContextMenuPositionState() {\n const [contextMenu, setContextMenu] = useState<MenuPosition | null>(null);\n const closeContextMenu = useCallback(() => setContextMenu(null), []);\n const openContextMenuAt = useCallback(\n (position: MenuPosition) => setContextMenu(position),\n [],\n );\n\n return { closeContextMenu, contextMenu, openContextMenuAt };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMenuKeyboard.js","sourceRoot":"","sources":["../../../home/
|
|
1
|
+
{"version":3,"file":"useMenuKeyboard.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/useMenuKeyboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAElE,SAAS,WAAW,C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,CAAC,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import { type RefObject, useEffect, useEffectEvent } from \"react\";\n\nfunction nextControl(\n controls: HTMLElement[],\n focused: Element | null,\n key: string,\n) {\n if (controls.length === 0) return undefined;\n const index = focused instanceof HTMLElement ? controls.indexOf(focused) : -1;\n switch (key) {\n case \"ArrowDown\":\n return controls[(index + 1) % controls.length];\n case \"ArrowUp\":\n return controls[\n index < 0\n ? controls.length - 1\n : (index - 1 + controls.length) % controls.length\n ];\n case \"Home\":\n return controls[0];\n case \"End\":\n return controls.at(-1);\n default:\n return undefined;\n }\n}\n\nexport function useMenuKeyboard(\n menuRef: RefObject<HTMLDivElement | null>,\n ready: boolean,\n onClose: () => void,\n) {\n const close = useEffectEvent(onClose);\n\n useEffect(() => {\n const menu = menuRef.current;\n if (!ready || !menu) return;\n\n const trigger = document.activeElement;\n let dismissedByPointer = false;\n const items = () =>\n Array.from(\n menu.querySelectorAll<HTMLElement>(\n \":is(button, input[type=checkbox]):not(:disabled):not([hidden])\",\n ),\n );\n const focusFirst = () =>\n (items()[0] ?? menu).focus({ preventScroll: true });\n focusFirst();\n // Startup and sync can replace an action while its menu is open. Recover\n // focus only when that replacement dropped it onto the document body.\n const observer = new MutationObserver(() => {\n if (!dismissedByPointer && document.activeElement === document.body) {\n focusFirst();\n }\n });\n observer.observe(menu, { childList: true, subtree: true });\n\n function restoreFocus() {\n if (trigger instanceof HTMLElement && trigger.isConnected) {\n trigger.focus({ preventScroll: true });\n return document.activeElement === trigger && trigger !== document.body;\n }\n return false;\n }\n\n function handleKeyDown(event: KeyboardEvent) {\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n if (!menu?.contains(document.activeElement)) return;\n if (event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n restoreFocus();\n close();\n return;\n }\n if (event.key === \"Tab\") {\n if (!restoreFocus()) event.preventDefault();\n close();\n return;\n }\n const next = nextControl(items(), document.activeElement, event.key);\n if (next) {\n event.preventDefault();\n event.stopPropagation();\n next.focus();\n }\n }\n\n function handleMouseDown(event: MouseEvent) {\n dismissedByPointer =\n event.target instanceof Node && !menu?.contains(event.target);\n }\n\n document.addEventListener(\"mousedown\", handleMouseDown, true);\n document.addEventListener(\"keydown\", handleKeyDown, true);\n return () => {\n observer.disconnect();\n document.removeEventListener(\"mousedown\", handleMouseDown, true);\n document.removeEventListener(\"keydown\", handleKeyDown, true);\n if (\n !dismissedByPointer &&\n (menu.contains(document.activeElement) ||\n document.activeElement === document.body)\n ) {\n restoreFocus();\n }\n };\n }, [menuRef, ready]);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tearleads/windowing",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
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
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/a2f0/tearleads.git",
|
|
9
|
+
"directory": "packages/windowing"
|
|
10
|
+
},
|
|
6
11
|
"type": "module",
|
|
7
12
|
"main": "./index.js",
|
|
8
13
|
"types": "./index.d.ts",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SidebarResize.js","sourceRoot":"","sources":["../../../home/
|
|
1
|
+
{"version":3,"file":"SidebarResize.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/sidebar/SidebarResize.tsx"],"names":[],"mappings":";AAAA,OAAO,EAML,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,qBAAqB,CAAC;AAE7B,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAQhC,SAAS,iBAAiB,CAAC,KAAa;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cAAc,EAAE,CAAC;QACvB,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrD,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,QAAQ,CAAC,CAAC,YAAY,EAAE,EAAE,CACxB,iBAAiB,CACf,CAAC,YAAY,IAAI,gBAAgB,EAAE,CAAC;YAClC,SAAS,GAAG,oBAAoB,GAAG,UAAU,CAChD,CACF,CAAC;IACJ,CAAC,EACD,CAAC,gBAAgB,CAAC,CACnB,CAAC;IAEF,OAAO;QACL,aAAa;QACb,iBAAiB;QACjB,aAAa,EAAE,gBAAgB,EAAE;QACjC,UAAU;QACV,KAAK;KACN,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,EAClC,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,aAAa,GAOd;IACC,OAAO,CACL,8BACiB,QAAQ,gBACZ,gBAAgB,sBACV,UAAU,mBACZ,SAAS,mBACT,SAAS,mBACT,YAAY,EAC3B,SAAS,EAAE,yBAAyB,SAAS,EAAE,EAC/C,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,CAAC,GACX,CACH,CAAC;AACJ,CAAC","sourcesContent":["import {\n type Dispatch,\n type KeyboardEvent as ReactKeyboardEvent,\n type PointerEvent as ReactPointerEvent,\n type RefObject,\n type SetStateAction,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport \"./SidebarResize.css\";\n\nconst MIN_WIDTH = 80;\nconst MAX_WIDTH = 400;\nconst KEYBOARD_RESIZE_STEP = 10;\n\ninterface DragState {\n pointerId: number;\n startWidth: number;\n startX: number;\n}\n\nfunction clampSidebarWidth(width: number) {\n return Math.min(MAX_WIDTH, Math.max(MIN_WIDTH, width));\n}\n\nfunction useSidebarDragEffect({\n active,\n draggingRef,\n endDrag,\n setWidth,\n}: {\n active: boolean;\n draggingRef: RefObject<DragState | null>;\n endDrag: () => void;\n setWidth: Dispatch<SetStateAction<number | null>>;\n}) {\n useEffect(() => {\n if (!active) {\n return;\n }\n\n function handlePointerMove(event: PointerEvent) {\n const dragState = draggingRef.current;\n if (!dragState || event.pointerId !== dragState.pointerId) {\n return;\n }\n\n const dx = event.clientX - dragState.startX;\n setWidth(clampSidebarWidth(dragState.startWidth + dx));\n }\n\n function handlePointerEnd(event: PointerEvent) {\n if (event.pointerId === draggingRef.current?.pointerId) {\n endDrag();\n }\n }\n\n document.addEventListener(\"pointermove\", handlePointerMove);\n document.addEventListener(\"pointerup\", handlePointerEnd);\n document.addEventListener(\"pointercancel\", handlePointerEnd);\n return () => {\n document.removeEventListener(\"pointermove\", handlePointerMove);\n document.removeEventListener(\"pointerup\", handlePointerEnd);\n document.removeEventListener(\"pointercancel\", handlePointerEnd);\n endDrag();\n };\n }, [active, draggingRef, endDrag, setWidth]);\n}\n\nexport function useSidebarResize({\n defaultWidth,\n initialWidth = defaultWidth,\n}: {\n defaultWidth: number;\n initialWidth?: number | null;\n}) {\n const [width, setWidth] = useState<number | null>(initialWidth);\n const [isDragging, setIsDragging] = useState(false);\n const sidebarRef = useRef<HTMLDivElement>(null);\n const draggingRef = useRef<DragState | null>(null);\n\n const readCurrentWidth = useCallback(() => {\n if (width !== null) {\n return width;\n }\n\n const measuredWidth = sidebarRef.current?.getBoundingClientRect().width;\n return measuredWidth && measuredWidth > 0\n ? clampSidebarWidth(measuredWidth)\n : defaultWidth;\n }, [defaultWidth, width]);\n\n const endDrag = useCallback(() => {\n if (!draggingRef.current) {\n return;\n }\n\n draggingRef.current = null;\n setIsDragging(false);\n document.body.style.cursor = \"\";\n document.body.style.userSelect = \"\";\n }, []);\n\n useSidebarDragEffect({\n active: isDragging,\n draggingRef,\n endDrag,\n setWidth,\n });\n\n const handlePointerDown = useCallback(\n (event: ReactPointerEvent<HTMLHRElement>) => {\n if (event.button !== 0 || !event.isPrimary) {\n return;\n }\n\n event.preventDefault();\n const startWidth = readCurrentWidth();\n draggingRef.current = {\n pointerId: event.pointerId,\n startWidth,\n startX: event.clientX,\n };\n setWidth(startWidth);\n setIsDragging(true);\n document.body.style.cursor = \"col-resize\";\n document.body.style.userSelect = \"none\";\n },\n [readCurrentWidth],\n );\n\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent<HTMLHRElement>) => {\n if (event.key === \"Home\") {\n event.preventDefault();\n setWidth(MIN_WIDTH);\n return;\n }\n\n if (event.key === \"End\") {\n event.preventDefault();\n setWidth(MAX_WIDTH);\n return;\n }\n\n if (event.key !== \"ArrowLeft\" && event.key !== \"ArrowRight\") {\n return;\n }\n\n event.preventDefault();\n const direction = event.key === \"ArrowLeft\" ? -1 : 1;\n const multiplier = event.shiftKey ? 5 : 1;\n setWidth((currentWidth) =>\n clampSidebarWidth(\n (currentWidth ?? readCurrentWidth()) +\n direction * KEYBOARD_RESIZE_STEP * multiplier,\n ),\n );\n },\n [readCurrentWidth],\n );\n\n return {\n handleKeyDown,\n handlePointerDown,\n resolvedWidth: readCurrentWidth(),\n sidebarRef,\n width,\n };\n}\n\nexport function SidebarResizeHandle({\n className,\n controls,\n currentWidth,\n onKeyDown,\n onPointerDown,\n}: {\n className: string;\n controls?: string | undefined;\n currentWidth: number;\n onKeyDown: (event: ReactKeyboardEvent<HTMLHRElement>) => void;\n onPointerDown: (event: ReactPointerEvent<HTMLHRElement>) => void;\n}) {\n return (\n <hr\n aria-controls={controls}\n aria-label=\"Resize sidebar\"\n aria-orientation=\"vertical\"\n aria-valuemax={MAX_WIDTH}\n aria-valuemin={MIN_WIDTH}\n aria-valuenow={currentWidth}\n className={`sidebar-resize-handle ${className}`}\n onKeyDown={onKeyDown}\n onPointerDown={onPointerDown}\n tabIndex={0}\n />\n );\n}\n"]}
|
|
@@ -3,6 +3,12 @@ interface CurrentWindowContextValue {
|
|
|
3
3
|
close: () => void;
|
|
4
4
|
id: string;
|
|
5
5
|
overlayHost: HTMLElement | null;
|
|
6
|
+
/**
|
|
7
|
+
* Paint the window's background with `background`, any CSS color, in place of
|
|
8
|
+
* `--window-background`; `undefined` restores it. Hosts that render this
|
|
9
|
+
* provider outside a `Window` may omit it.
|
|
10
|
+
*/
|
|
11
|
+
setBackground?: ((background: string | undefined) => void) | undefined;
|
|
6
12
|
showStatusMessage: (message: string) => void;
|
|
7
13
|
/**
|
|
8
14
|
* Hide the window's toolbar row until the returned release is called. Refcounted,
|
|
@@ -10,7 +16,7 @@ interface CurrentWindowContextValue {
|
|
|
10
16
|
*/
|
|
11
17
|
suppressToolbar: () => () => void;
|
|
12
18
|
}
|
|
13
|
-
export declare function CurrentWindowProvider({ children, close, id, overlayHost, showStatusMessage, suppressToolbar, }: PropsWithChildren<CurrentWindowContextValue>): import("react").JSX.Element;
|
|
19
|
+
export declare function CurrentWindowProvider({ children, close, id, overlayHost, setBackground, showStatusMessage, suppressToolbar, }: PropsWithChildren<CurrentWindowContextValue>): import("react").JSX.Element;
|
|
14
20
|
export declare function useCurrentWindow(): CurrentWindowContextValue | null;
|
|
15
21
|
/**
|
|
16
22
|
* Drop the host window's toolbar row while `active`.
|
|
@@ -24,4 +30,14 @@ export declare function useCurrentWindow(): CurrentWindowContextValue | null;
|
|
|
24
30
|
* overlay's own toolbar for a frame and then resizing the pane out from under it.
|
|
25
31
|
*/
|
|
26
32
|
export declare function useSuppressWindowToolbar(active: boolean): void;
|
|
33
|
+
/**
|
|
34
|
+
* Paint the host window's background, behind its body and sidebar, with
|
|
35
|
+
* `background` (any CSS color) while mounted; `undefined` keeps the default,
|
|
36
|
+
* `--window-background`. A document viewer uses it to set its page apart from
|
|
37
|
+
* the window around it. Outside a window this is inert.
|
|
38
|
+
*
|
|
39
|
+
* Applying it in a layout effect keeps the default from being painted for a
|
|
40
|
+
* frame before the content's own background.
|
|
41
|
+
*/
|
|
42
|
+
export declare function useWindowBackground(background: string | undefined): void;
|
|
27
43
|
export {};
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useContext, useLayoutEffect, useMemo, } from "react";
|
|
3
3
|
const CurrentWindowContext = createContext(null);
|
|
4
|
-
export function CurrentWindowProvider({ children, close, id, overlayHost, showStatusMessage, suppressToolbar, }) {
|
|
5
|
-
const value = useMemo(() => ({
|
|
4
|
+
export function CurrentWindowProvider({ children, close, id, overlayHost, setBackground, showStatusMessage, suppressToolbar, }) {
|
|
5
|
+
const value = useMemo(() => ({
|
|
6
|
+
close,
|
|
7
|
+
id,
|
|
8
|
+
overlayHost,
|
|
9
|
+
setBackground,
|
|
10
|
+
showStatusMessage,
|
|
11
|
+
suppressToolbar,
|
|
12
|
+
}), [close, id, overlayHost, setBackground, showStatusMessage, suppressToolbar]);
|
|
6
13
|
return (_jsx(CurrentWindowContext.Provider, { value: value, children: children }));
|
|
7
14
|
}
|
|
8
15
|
export function useCurrentWindow() {
|
|
@@ -28,4 +35,23 @@ export function useSuppressWindowToolbar(active) {
|
|
|
28
35
|
return suppressToolbar();
|
|
29
36
|
}, [active, suppressToolbar]);
|
|
30
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Paint the host window's background, behind its body and sidebar, with
|
|
40
|
+
* `background` (any CSS color) while mounted; `undefined` keeps the default,
|
|
41
|
+
* `--window-background`. A document viewer uses it to set its page apart from
|
|
42
|
+
* the window around it. Outside a window this is inert.
|
|
43
|
+
*
|
|
44
|
+
* Applying it in a layout effect keeps the default from being painted for a
|
|
45
|
+
* frame before the content's own background.
|
|
46
|
+
*/
|
|
47
|
+
export function useWindowBackground(background) {
|
|
48
|
+
const setBackground = useCurrentWindow()?.setBackground;
|
|
49
|
+
useLayoutEffect(() => {
|
|
50
|
+
if (background === undefined || !setBackground) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
setBackground(background);
|
|
54
|
+
return () => setBackground(undefined);
|
|
55
|
+
}, [background, setBackground]);
|
|
56
|
+
}
|
|
31
57
|
//# sourceMappingURL=CurrentWindowContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrentWindowContext.js","sourceRoot":"","sources":["../../../home/
|
|
1
|
+
{"version":3,"file":"CurrentWindowContext.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/CurrentWindowContext.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAEb,UAAU,EACV,eAAe,EACf,OAAO,GACR,MAAM,OAAO,CAAC;AAoBf,MAAM,oBAAoB,GAAG,aAAa,CACxC,IAAI,CACL,CAAC;AAEF,MAAM,UAAU,qBAAqB,CAAC,EACpC,QAAQ,EACR,KAAK,EACL,EAAE,EACF,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,eAAe,GAC8B;IAC7C,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC;QACL,KAAK;QACL,EAAE;QACF,WAAW;QACX,aAAa;QACb,iBAAiB;QACjB,eAAe;KAChB,CAAC,EACF,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,CAAC,CAC5E,CAAC;IAEF,OAAO,CACL,KAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACxC,QAAQ,GACqB,CACjC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAU,CAAC,oBAAoB,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAe;IACtD,MAAM,eAAe,GAAG,gBAAgB,EAAE,EAAE,eAAe,CAAC;IAE5D,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;YAChC,OAAO;QACT,CAAC;QACD,OAAO,eAAe,EAAE,CAAC;IAC3B,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAA8B;IAChE,MAAM,aAAa,GAAG,gBAAgB,EAAE,EAAE,aAAa,CAAC;IAExD,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,UAAU,KAAK,SAAS,IAAI,CAAC,aAAa,EAAE,CAAC;YAC/C,OAAO;QACT,CAAC;QACD,aAAa,CAAC,UAAU,CAAC,CAAC;QAC1B,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC;AAClC,CAAC","sourcesContent":["import {\n createContext,\n type PropsWithChildren,\n useContext,\n useLayoutEffect,\n useMemo,\n} from \"react\";\n\ninterface CurrentWindowContextValue {\n close: () => void;\n id: string;\n overlayHost: HTMLElement | null;\n /**\n * Paint the window's background with `background`, any CSS color, in place of\n * `--window-background`; `undefined` restores it. Hosts that render this\n * provider outside a `Window` may omit it.\n */\n setBackground?: ((background: string | undefined) => void) | undefined;\n showStatusMessage: (message: string) => void;\n /**\n * Hide the window's toolbar row until the returned release is called. Refcounted,\n * so overlapping suppressions restore the row only once the last one releases.\n */\n suppressToolbar: () => () => void;\n}\n\nconst CurrentWindowContext = createContext<CurrentWindowContextValue | null>(\n null,\n);\n\nexport function CurrentWindowProvider({\n children,\n close,\n id,\n overlayHost,\n setBackground,\n showStatusMessage,\n suppressToolbar,\n}: PropsWithChildren<CurrentWindowContextValue>) {\n const value = useMemo(\n () => ({\n close,\n id,\n overlayHost,\n setBackground,\n showStatusMessage,\n suppressToolbar,\n }),\n [close, id, overlayHost, setBackground, showStatusMessage, suppressToolbar],\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"]}
|
package/window/Window.css
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
max-height: 100%;
|
|
19
19
|
min-width: 200px;
|
|
20
20
|
min-height: 100px;
|
|
21
|
-
background: var(--color-light);
|
|
21
|
+
background: var(--window-background, var(--color-light));
|
|
22
22
|
border: var(--border-strong);
|
|
23
23
|
border-radius: var(--app-radius-surface);
|
|
24
24
|
box-shadow: var(--app-shadow-window);
|
package/window/Window.js
CHANGED
|
@@ -171,6 +171,7 @@ function WindowInnerContent({ ContentBoundary, entry, historyBack, isTop, }) {
|
|
|
171
171
|
const windowRef = useRef(null);
|
|
172
172
|
const titleId = useId();
|
|
173
173
|
const [overlayHost, setOverlayHost] = useState(null);
|
|
174
|
+
const [background, setBackground] = useState();
|
|
174
175
|
const fileMenuItems = useWindowFileMenuItems();
|
|
175
176
|
const viewMenuItems = useWindowViewMenuItems();
|
|
176
177
|
const { sidebar } = useWindowSidebar();
|
|
@@ -186,14 +187,17 @@ function WindowInnerContent({ ContentBoundary, entry, historyBack, isTop, }) {
|
|
|
186
187
|
});
|
|
187
188
|
const { suppressToolbar, toolbarSuppressed } = useWindowToolbarSuppression();
|
|
188
189
|
const { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps } = useWindowRootHandlers(entry.id);
|
|
189
|
-
const style =
|
|
190
|
+
const style = {
|
|
191
|
+
...getWindowStyle(maximized, position, size, zIndex),
|
|
192
|
+
"--window-background": background,
|
|
193
|
+
};
|
|
190
194
|
if (minimized) {
|
|
191
195
|
return null;
|
|
192
196
|
}
|
|
193
197
|
// A section labelled by its title is a region landmark. Windows are
|
|
194
198
|
// non-modal and freely arranged, so they are not dialogs; hosts keep that
|
|
195
199
|
// role for the modals they open inside a window.
|
|
196
|
-
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, 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 }))] }));
|
|
200
|
+
return (_jsxs("section", { ref: windowRef, "aria-labelledby": titleId, className: maximized ? "window window--maximized" : "window", tabIndex: -1, ...windowContextMenuTrapProps, onPointerDownCapture: handleWindowPointerDown, style: style, children: [_jsx(WindowChrome, { actions: actions, entry: entry, historyBack: historyBack, onGoBack: handleGoBack, onPointerDown: handlePointerDown, titleId: titleId, toolbarSuppressed: toolbarSuppressed }), _jsx(CurrentWindowProvider, { close: actions.handleClose, id: entry.id, overlayHost: overlayHost, setBackground: setBackground, showStatusMessage: showStatusMessage, suppressToolbar: suppressToolbar, children: _jsx(WindowBodyWithSidebar, { overlayHostRef: setOverlayHost, showSidebar: actions.showSidebar, children: ContentBoundary ? (_jsx(ContentBoundary, { entry: entry, children: Component && _jsx(Component, {}) })) : (Component && _jsx(Component, {})) }) }), _jsx(WindowStatusBar, { text: statusText, visible: actions.showStatusBar }), !maximized && (_jsx(WindowResizeHandles, { handleResizePointerDown: handleResizePointerDown }))] }));
|
|
197
201
|
}
|
|
198
202
|
function WindowBodyWithSidebar({ showSidebar, overlayHostRef, children, }) {
|
|
199
203
|
const { sidebar } = useWindowSidebar();
|
package/window/Window.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Window.js","sourceRoot":"","sources":["../../../home/a2f0/github/tearleads/packages/windowing/src/window/Window.tsx"],"names":[],"mappings":";AAAA,OAAO,EAOL,WAAW,EACX,SAAS,EACT,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AACrE,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC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,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 { useWindowGeometry } from \"./useWindowGeometry\";\nimport {\n useFocusWindowOnShow,\n useWindowGeometryMenuItems,\n} from \"./useWindowKeyboardGeometry\";\nimport { WindowBody } from \"./WindowBody\";\nimport { WindowMenuBar, type WindowMenuItem } from \"./WindowMenuBar\";\nimport {\n useWindowFileMenuItems,\n useWindowViewMenuItems,\n WindowMenuProvider,\n} from \"./WindowMenuContext\";\nimport { WindowResizeHandles } from \"./WindowResizeHandle\";\nimport {\n hasWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./WindowSidebarContext\";\nimport {\n findTopWindow,\n useWindowActions as useWindowStateActions,\n useWindowStateData,\n type WindowEntry,\n type WindowPosition,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport { WindowStatusBar } from \"./WindowStatusBar\";\nimport { WindowTitleBar } from \"./WindowTitleBar\";\nimport { WindowToolBar } from \"./WindowToolBar\";\n\n// Wraps a window's content so the host can give it app-specific context (a\n// route, an error boundary) without the window layer knowing about apps.\nexport type WindowContentBoundary = ComponentType<\n PropsWithChildren<{ entry: WindowEntry }>\n>;\n\ninterface WindowProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n /**\n * Whether the toolbar offers Back through the window's own route history,\n * reserving its row from the start (see `WindowToolBar`). Defaults to whether\n * the window has an `appId`. Pass false for an app that never routes, so its\n * window has no toolbar row until the app first registers toolbar actions.\n */\n historyBack?: boolean | undefined;\n windowId: string;\n}\n\nconst WINDOW_STATUS_MESSAGE_DURATION_MS = 2500;\n\nexport function Window({\n ContentBoundary,\n historyBack,\n windowId,\n}: WindowProps) {\n const { windowMap, windows } = useWindowStateData();\n const entry = windowMap.get(windowId);\n const isTop =\n findTopWindow(windows, (candidate) => !candidate.minimized)?.id ===\n windowId;\n\n if (!entry) return null;\n\n return (\n <WindowInner\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack ?? entry.appId !== undefined}\n isTop={isTop}\n />\n );\n}\n\nfunction useWindowActions(\n entry: WindowEntry,\n fileMenuItems: WindowMenuItem[],\n viewMenuItems: WindowMenuItem[],\n geometryMenuItems: WindowMenuItem[],\n hasSidebar: boolean,\n) {\n const { close, minimize, moveBackward, moveForward, toggleMaximize } =\n useWindowStateActions();\n const [showStatusBar, setShowStatusBar] = useState(true);\n const [showSidebar, setShowSidebar] = useState(\n entry.initialShowSidebar ?? true,\n );\n const handleClose = useCallback(() => close(entry.id), [close, entry.id]);\n const handleMinimize = useCallback(\n () => minimize(entry.id),\n [entry.id, minimize],\n );\n const handleMoveForward = useCallback(\n () => moveForward(entry.id),\n [entry.id, moveForward],\n );\n const handleMoveBackward = useCallback(\n () => moveBackward(entry.id),\n [entry.id, moveBackward],\n );\n const handleMaximize = useCallback(\n () => toggleMaximize(entry.id),\n [entry.id, toggleMaximize],\n );\n const toggleStatusBar = useCallback(\n () => setShowStatusBar((previous) => !previous),\n [],\n );\n const toggleSidebar = useCallback(\n () => setShowSidebar((previous) => !previous),\n [],\n );\n const menus = useMemo(\n () => [\n {\n label: \"File\",\n items: [\n ...fileMenuItems,\n { id: \"close\", label: \"Close\", onClick: handleClose },\n ],\n },\n {\n label: \"View\",\n items: [\n ...viewMenuItems,\n ...geometryMenuItems,\n {\n id: \"toggle-status-bar\",\n label: `${showStatusBar ? \"Hide\" : \"Show\"} Status Bar`,\n onClick: toggleStatusBar,\n },\n ...(hasSidebar\n ? [\n {\n id: \"toggle-sidebar\",\n label: `${showSidebar ? \"Hide\" : \"Show\"} Sidebar`,\n onClick: toggleSidebar,\n },\n ]\n : []),\n ],\n },\n ],\n [\n geometryMenuItems,\n hasSidebar,\n handleClose,\n fileMenuItems,\n showSidebar,\n showStatusBar,\n toggleSidebar,\n toggleStatusBar,\n viewMenuItems,\n ],\n );\n\n return {\n handleClose,\n handleMaximize,\n handleMinimize,\n handleMoveBackward,\n handleMoveForward,\n menus,\n showSidebar,\n showStatusBar,\n };\n}\n\nfunction getWindowStyle(\n maximized: boolean,\n position: WindowPosition | null,\n size: WindowSize | null,\n zIndex: number,\n): CSSProperties | undefined {\n if (maximized) {\n return { top: 0, left: 0, width: \"100%\", height: \"100%\", zIndex };\n }\n if (!position) {\n // Hidden until laid out; a requested size applies already so the first\n // clamp measures the window at the size it will show.\n return {\n visibility: \"hidden\",\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n }\n\n return {\n left: position.x,\n top: position.y,\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n}\n\nfunction useWindowStatusMessage() {\n const [statusText, setStatusText] = useState(\"\");\n const statusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const showStatusMessage = useCallback((message: string) => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n setStatusText(message);\n statusTimeoutRef.current = setTimeout(() => {\n setStatusText(\"\");\n statusTimeoutRef.current = null;\n }, WINDOW_STATUS_MESSAGE_DURATION_MS);\n }, []);\n\n useEffect(() => {\n return () => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n };\n }, []);\n\n return { showStatusMessage, statusText };\n}\n\n// Refcounted so overlapping overlays (one closing as another opens) never leave\n// the row hidden, and never flash it back for a frame between the two.\nfunction useWindowToolbarSuppression() {\n const [suppressionCount, setSuppressionCount] = useState(0);\n const suppressToolbar = useCallback(() => {\n setSuppressionCount((count) => count + 1);\n return () => setSuppressionCount((count) => Math.max(0, count - 1));\n }, []);\n\n return { suppressToolbar, toolbarSuppressed: suppressionCount > 0 };\n}\n\ninterface WindowInnerProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n entry: WindowEntry;\n historyBack: boolean;\n // Whether this is the foremost visible window, the one that takes focus.\n isTop: boolean;\n}\n\nfunction WindowInner({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n return (\n <WindowMenuProvider>\n <WindowSidebarProvider>\n <WindowInnerContent\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack}\n isTop={isTop}\n />\n </WindowSidebarProvider>\n </WindowMenuProvider>\n );\n}\n\n// The bars above the body: title, menus, and the toolbar row a full-pane overlay\n// can stand down (see `useWindowToolbarSuppression`).\nfunction WindowChrome({\n actions,\n entry,\n historyBack,\n onGoBack,\n onPointerDown,\n titleId,\n toolbarSuppressed,\n}: {\n actions: ReturnType<typeof useWindowActions>;\n entry: WindowEntry;\n historyBack: boolean;\n onGoBack: () => void;\n onPointerDown: (event: ReactPointerEvent) => void;\n titleId: string;\n toolbarSuppressed: boolean;\n}) {\n return (\n <>\n <WindowTitleBar\n title={entry.title}\n titleId={titleId}\n onPointerDown={onPointerDown}\n onMinimize={actions.handleMinimize}\n onMaximize={actions.handleMaximize}\n onClose={actions.handleClose}\n onMoveForward={actions.handleMoveForward}\n onMoveBackward={actions.handleMoveBackward}\n />\n <WindowMenuBar menus={actions.menus} />\n {!toolbarSuppressed && (\n <WindowToolBar\n canGoBack={(entry.routeHistory?.length ?? 0) > 0}\n showHistoryBack={historyBack}\n onGoBack={onGoBack}\n />\n )}\n </>\n );\n}\n\n// Handlers on the window root: its Back caret, raising it on any press inside,\n// and keeping background context menus from opening under window-local ones.\nfunction useWindowRootHandlers(windowId: string) {\n // The toolbar renders above the route boundary, so the window's own Back stack\n // is threaded in from here rather than read from context.\n const { bringToFront, goBackRoute } = useWindowStateActions();\n const handleGoBack = useCallback(() => {\n goBackRoute(windowId);\n }, [windowId, goBackRoute]);\n const handleWindowPointerDown = useCallback(() => {\n bringToFront(windowId);\n }, [bringToFront, windowId]);\n const handleWindowContextMenu = useCallback((event: ReactMouseEvent) => {\n // Keep background pane context menus from opening underneath window-local menus.\n event.stopPropagation();\n }, []);\n const windowContextMenuTrapProps: Pick<\n HTMLAttributes<HTMLElement>,\n \"onContextMenu\"\n > = {\n onContextMenu: handleWindowContextMenu,\n };\n\n return { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps };\n}\n\nfunction WindowInnerContent({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n const { maximized, minimized, zIndex, component: Component } = entry;\n const windowRef = useRef<HTMLElement>(null);\n const titleId = useId();\n const [overlayHost, setOverlayHost] = useState<HTMLElement | null>(null);\n const fileMenuItems = useWindowFileMenuItems();\n const viewMenuItems = useWindowViewMenuItems();\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n const {\n handlePointerDown,\n handleResizePointerDown,\n position,\n size,\n ...stepped\n } = useWindowGeometry(entry, maximized, windowRef);\n const { showStatusMessage, statusText } = useWindowStatusMessage();\n const geometryMenuItems = useWindowGeometryMenuItems(\n stepped,\n { maximized, minimized, windowRef },\n showStatusMessage,\n );\n const actions = useWindowActions(\n entry,\n fileMenuItems,\n viewMenuItems,\n geometryMenuItems,\n hasSidebar,\n );\n // A maximized window fills its surface without a laid-out position.\n useFocusWindowOnShow(windowRef, {\n isTop,\n shown: !minimized && (maximized || position !== null),\n });\n const { suppressToolbar, toolbarSuppressed } = useWindowToolbarSuppression();\n const { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps } =\n useWindowRootHandlers(entry.id);\n const style = getWindowStyle(maximized, position, size, zIndex);\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 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/tearle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,EACtB,aAAa,EAAE,iBAAiB,EAChC,OAAO,EAAE,OAAO,EAChB,iBAAiB,EAAE,iBAAiB,GACpC,EACF,KAAC,qBAAqB,IACpB,KAAK,EAAE,OAAO,CAAC,WAAW,EAC1B,EAAE,EAAE,KAAK,CAAC,EAAE,EACZ,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,iBAAiB,EAAE,iBAAiB,EACpC,eAAe,EAAE,eAAe,YAEhC,KAAC,qBAAqB,IACpB,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 { useWindowGeometry } from \"./useWindowGeometry\";\nimport {\n useFocusWindowOnShow,\n useWindowGeometryMenuItems,\n} from \"./useWindowKeyboardGeometry\";\nimport { WindowBody } from \"./WindowBody\";\nimport { WindowMenuBar, type WindowMenuItem } from \"./WindowMenuBar\";\nimport {\n useWindowFileMenuItems,\n useWindowViewMenuItems,\n WindowMenuProvider,\n} from \"./WindowMenuContext\";\nimport { WindowResizeHandles } from \"./WindowResizeHandle\";\nimport {\n hasWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./WindowSidebarContext\";\nimport {\n findTopWindow,\n useWindowActions as useWindowStateActions,\n useWindowStateData,\n type WindowEntry,\n type WindowPosition,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport { WindowStatusBar } from \"./WindowStatusBar\";\nimport { WindowTitleBar } from \"./WindowTitleBar\";\nimport { WindowToolBar } from \"./WindowToolBar\";\n\n// Wraps a window's content so the host can give it app-specific context (a\n// route, an error boundary) without the window layer knowing about apps.\nexport type WindowContentBoundary = ComponentType<\n PropsWithChildren<{ entry: WindowEntry }>\n>;\n\ninterface WindowProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n /**\n * Whether the toolbar offers Back through the window's own route history,\n * reserving its row from the start (see `WindowToolBar`). Defaults to whether\n * the window has an `appId`. Pass false for an app that never routes, so its\n * window has no toolbar row until the app first registers toolbar actions.\n */\n historyBack?: boolean | undefined;\n windowId: string;\n}\n\nconst WINDOW_STATUS_MESSAGE_DURATION_MS = 2500;\n\nexport function Window({\n ContentBoundary,\n historyBack,\n windowId,\n}: WindowProps) {\n const { windowMap, windows } = useWindowStateData();\n const entry = windowMap.get(windowId);\n const isTop =\n findTopWindow(windows, (candidate) => !candidate.minimized)?.id ===\n windowId;\n\n if (!entry) return null;\n\n return (\n <WindowInner\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack ?? entry.appId !== undefined}\n isTop={isTop}\n />\n );\n}\n\nfunction useWindowActions(\n entry: WindowEntry,\n fileMenuItems: WindowMenuItem[],\n viewMenuItems: WindowMenuItem[],\n geometryMenuItems: WindowMenuItem[],\n hasSidebar: boolean,\n) {\n const { close, minimize, moveBackward, moveForward, toggleMaximize } =\n useWindowStateActions();\n const [showStatusBar, setShowStatusBar] = useState(true);\n const [showSidebar, setShowSidebar] = useState(\n entry.initialShowSidebar ?? true,\n );\n const handleClose = useCallback(() => close(entry.id), [close, entry.id]);\n const handleMinimize = useCallback(\n () => minimize(entry.id),\n [entry.id, minimize],\n );\n const handleMoveForward = useCallback(\n () => moveForward(entry.id),\n [entry.id, moveForward],\n );\n const handleMoveBackward = useCallback(\n () => moveBackward(entry.id),\n [entry.id, moveBackward],\n );\n const handleMaximize = useCallback(\n () => toggleMaximize(entry.id),\n [entry.id, toggleMaximize],\n );\n const toggleStatusBar = useCallback(\n () => setShowStatusBar((previous) => !previous),\n [],\n );\n const toggleSidebar = useCallback(\n () => setShowSidebar((previous) => !previous),\n [],\n );\n const menus = useMemo(\n () => [\n {\n label: \"File\",\n items: [\n ...fileMenuItems,\n { id: \"close\", label: \"Close\", onClick: handleClose },\n ],\n },\n {\n label: \"View\",\n items: [\n ...viewMenuItems,\n ...geometryMenuItems,\n {\n id: \"toggle-status-bar\",\n label: `${showStatusBar ? \"Hide\" : \"Show\"} Status Bar`,\n onClick: toggleStatusBar,\n },\n ...(hasSidebar\n ? [\n {\n id: \"toggle-sidebar\",\n label: `${showSidebar ? \"Hide\" : \"Show\"} Sidebar`,\n onClick: toggleSidebar,\n },\n ]\n : []),\n ],\n },\n ],\n [\n geometryMenuItems,\n hasSidebar,\n handleClose,\n fileMenuItems,\n showSidebar,\n showStatusBar,\n toggleSidebar,\n toggleStatusBar,\n viewMenuItems,\n ],\n );\n\n return {\n handleClose,\n handleMaximize,\n handleMinimize,\n handleMoveBackward,\n handleMoveForward,\n menus,\n showSidebar,\n showStatusBar,\n };\n}\n\n// The window paints with `--window-background`, which a background its content\n// sets (see `useWindowBackground`) overrides inline.\ninterface WindowStyle extends CSSProperties {\n \"--window-background\"?: string | undefined;\n}\n\nfunction getWindowStyle(\n maximized: boolean,\n position: WindowPosition | null,\n size: WindowSize | null,\n zIndex: number,\n): CSSProperties | undefined {\n if (maximized) {\n return { top: 0, left: 0, width: \"100%\", height: \"100%\", zIndex };\n }\n if (!position) {\n // Hidden until laid out; a requested size applies already so the first\n // clamp measures the window at the size it will show.\n return {\n visibility: \"hidden\",\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n }\n\n return {\n left: position.x,\n top: position.y,\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n}\n\nfunction useWindowStatusMessage() {\n const [statusText, setStatusText] = useState(\"\");\n const statusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const showStatusMessage = useCallback((message: string) => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n setStatusText(message);\n statusTimeoutRef.current = setTimeout(() => {\n setStatusText(\"\");\n statusTimeoutRef.current = null;\n }, WINDOW_STATUS_MESSAGE_DURATION_MS);\n }, []);\n\n useEffect(() => {\n return () => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n };\n }, []);\n\n return { showStatusMessage, statusText };\n}\n\n// Refcounted so overlapping overlays (one closing as another opens) never leave\n// the row hidden, and never flash it back for a frame between the two.\nfunction useWindowToolbarSuppression() {\n const [suppressionCount, setSuppressionCount] = useState(0);\n const suppressToolbar = useCallback(() => {\n setSuppressionCount((count) => count + 1);\n return () => setSuppressionCount((count) => Math.max(0, count - 1));\n }, []);\n\n return { suppressToolbar, toolbarSuppressed: suppressionCount > 0 };\n}\n\ninterface WindowInnerProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n entry: WindowEntry;\n historyBack: boolean;\n // Whether this is the foremost visible window, the one that takes focus.\n isTop: boolean;\n}\n\nfunction WindowInner({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n return (\n <WindowMenuProvider>\n <WindowSidebarProvider>\n <WindowInnerContent\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack}\n isTop={isTop}\n />\n </WindowSidebarProvider>\n </WindowMenuProvider>\n );\n}\n\n// The bars above the body: title, menus, and the toolbar row a full-pane overlay\n// can stand down (see `useWindowToolbarSuppression`).\nfunction WindowChrome({\n actions,\n entry,\n historyBack,\n onGoBack,\n onPointerDown,\n titleId,\n toolbarSuppressed,\n}: {\n actions: ReturnType<typeof useWindowActions>;\n entry: WindowEntry;\n historyBack: boolean;\n onGoBack: () => void;\n onPointerDown: (event: ReactPointerEvent) => void;\n titleId: string;\n toolbarSuppressed: boolean;\n}) {\n return (\n <>\n <WindowTitleBar\n title={entry.title}\n titleId={titleId}\n onPointerDown={onPointerDown}\n onMinimize={actions.handleMinimize}\n onMaximize={actions.handleMaximize}\n onClose={actions.handleClose}\n onMoveForward={actions.handleMoveForward}\n onMoveBackward={actions.handleMoveBackward}\n />\n <WindowMenuBar menus={actions.menus} />\n {!toolbarSuppressed && (\n <WindowToolBar\n canGoBack={(entry.routeHistory?.length ?? 0) > 0}\n showHistoryBack={historyBack}\n onGoBack={onGoBack}\n />\n )}\n </>\n );\n}\n\n// Handlers on the window root: its Back caret, raising it on any press inside,\n// and keeping background context menus from opening under window-local ones.\nfunction useWindowRootHandlers(windowId: string) {\n // The toolbar renders above the route boundary, so the window's own Back stack\n // is threaded in from here rather than read from context.\n const { bringToFront, goBackRoute } = useWindowStateActions();\n const handleGoBack = useCallback(() => {\n goBackRoute(windowId);\n }, [windowId, goBackRoute]);\n const handleWindowPointerDown = useCallback(() => {\n bringToFront(windowId);\n }, [bringToFront, windowId]);\n const handleWindowContextMenu = useCallback((event: ReactMouseEvent) => {\n // Keep background pane context menus from opening underneath window-local menus.\n event.stopPropagation();\n }, []);\n const windowContextMenuTrapProps: Pick<\n HTMLAttributes<HTMLElement>,\n \"onContextMenu\"\n > = {\n onContextMenu: handleWindowContextMenu,\n };\n\n return { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps };\n}\n\nfunction WindowInnerContent({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n const { maximized, minimized, zIndex, component: Component } = entry;\n const windowRef = useRef<HTMLElement>(null);\n const titleId = useId();\n const [overlayHost, setOverlayHost] = useState<HTMLElement | null>(null);\n const [background, setBackground] = useState<string | undefined>();\n const fileMenuItems = useWindowFileMenuItems();\n const viewMenuItems = useWindowViewMenuItems();\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n const {\n handlePointerDown,\n handleResizePointerDown,\n position,\n size,\n ...stepped\n } = useWindowGeometry(entry, maximized, windowRef);\n const { showStatusMessage, statusText } = useWindowStatusMessage();\n const geometryMenuItems = useWindowGeometryMenuItems(\n stepped,\n { maximized, minimized, windowRef },\n showStatusMessage,\n );\n const actions = useWindowActions(\n entry,\n fileMenuItems,\n viewMenuItems,\n geometryMenuItems,\n hasSidebar,\n );\n // A maximized window fills its surface without a laid-out position.\n useFocusWindowOnShow(windowRef, {\n isTop,\n shown: !minimized && (maximized || position !== null),\n });\n const { suppressToolbar, toolbarSuppressed } = useWindowToolbarSuppression();\n const { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps } =\n useWindowRootHandlers(entry.id);\n const style: WindowStyle = {\n ...getWindowStyle(maximized, position, size, zIndex),\n \"--window-background\": background,\n };\n\n if (minimized) {\n return null;\n }\n\n // A section labelled by its title is a region landmark. Windows are\n // non-modal and freely arranged, so they are not dialogs; hosts keep that\n // role for the modals they open inside a window.\n return (\n <section\n ref={windowRef}\n aria-labelledby={titleId}\n className={maximized ? \"window window--maximized\" : \"window\"}\n tabIndex={-1}\n {...windowContextMenuTrapProps}\n onPointerDownCapture={handleWindowPointerDown}\n style={style}\n >\n <WindowChrome\n actions={actions}\n entry={entry}\n historyBack={historyBack}\n onGoBack={handleGoBack}\n onPointerDown={handlePointerDown}\n titleId={titleId}\n toolbarSuppressed={toolbarSuppressed}\n />\n <CurrentWindowProvider\n close={actions.handleClose}\n id={entry.id}\n overlayHost={overlayHost}\n setBackground={setBackground}\n showStatusMessage={showStatusMessage}\n suppressToolbar={suppressToolbar}\n >\n <WindowBodyWithSidebar\n overlayHostRef={setOverlayHost}\n showSidebar={actions.showSidebar}\n >\n {ContentBoundary ? (\n <ContentBoundary entry={entry}>\n {Component && <Component />}\n </ContentBoundary>\n ) : (\n Component && <Component />\n )}\n </WindowBodyWithSidebar>\n </CurrentWindowProvider>\n <WindowStatusBar text={statusText} visible={actions.showStatusBar} />\n {!maximized && (\n <WindowResizeHandles\n handleResizePointerDown={handleResizePointerDown}\n />\n )}\n </section>\n );\n}\n\nfunction WindowBodyWithSidebar({\n showSidebar,\n overlayHostRef,\n children,\n}: PropsWithChildren<{\n overlayHostRef: (element: HTMLDivElement | null) => void;\n showSidebar: boolean;\n}>) {\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n\n return (\n <WindowBody\n contentRef={overlayHostRef}\n showSidebar={showSidebar && hasSidebar}\n sidebar={sidebar}\n >\n {children}\n </WindowBody>\n );\n}\n"]}
|