@tearleads/windowing 0.2.3 → 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 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, and a
82
- sidebar through the `useWindow*` hooks, from inside the window's content.
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
 
@@ -124,6 +125,17 @@ and `--emphasis-text`), and `--color-hairline`. A dark theme that sets only the
124
125
  `--color-*` primitives gets near-white edges and chips, so set these too, as
125
126
  Tearleads' dark theme does.
126
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
+
127
139
  The window rounds its corners but does not clip its content, since its resize
128
140
  handles and menus reach past its edges. While no visible status bar sits below
129
141
  it, the window body rounds its own bottom corners to the window's inner radius
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/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,GACzB,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} 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"]}
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tearleads/windowing",
3
- "version": "0.2.3",
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
6
  "repository": {
@@ -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(() => ({ close, id, overlayHost, showStatusMessage, suppressToolbar }), [close, id, overlayHost, showStatusMessage, suppressToolbar]);
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/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;AAcf,MAAM,oBAAoB,GAAG,aAAa,CACxC,IAAI,CACL,CAAC;AAEF,MAAM,UAAU,qBAAqB,CAAC,EACpC,QAAQ,EACR,KAAK,EACL,EAAE,EACF,WAAW,EACX,iBAAiB,EACjB,eAAe,GAC8B;IAC7C,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,iBAAiB,EAAE,eAAe,EAAE,CAAC,EACtE,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,iBAAiB,EAAE,eAAe,CAAC,CAC7D,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","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 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 showStatusMessage,\n suppressToolbar,\n}: PropsWithChildren<CurrentWindowContextValue>) {\n const value = useMemo(\n () => ({ close, id, overlayHost, showStatusMessage, suppressToolbar }),\n [close, id, overlayHost, 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"]}
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 = getWindowStyle(maximized, position, size, zIndex);
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();
@@ -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,i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,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\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/tearleads/tearleads/packages/windowing/src/window/Window.tsx"],"names":[],"mappings":";AAAA,OAAO,EAOL,WAAW,EACX,SAAS,EACT,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AACrE,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,aAAa,EACb,gBAAgB,IAAI,qBAAqB,EACzC,kBAAkB,GAInB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAoBhD,MAAM,iCAAiC,GAAG,IAAI,CAAC;AAE/C,MAA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AU,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"]}