@tearleads/windowing 0.2.6 → 0.2.8

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
@@ -2,11 +2,12 @@
2
2
 
3
3
  App-agnostic window management for React: window state (open, focus order,
4
4
  minimize/maximize, a per-window route and Back stack), window chrome (title
5
- bar, menu bar, toolbar, sidebar, status bar, resize handles), and the menu and
6
- sidebar primitives that chrome renders with.
5
+ bar, menu bar, toolbar, sidebar, status bar, resize handles), the menu and
6
+ sidebar primitives that chrome renders with, and a taskbar's start menu.
7
7
 
8
8
  The package knows nothing about the applications that run inside its windows.
9
- It depends only on React, react-dom, and Phosphor icons.
9
+ It depends only on React, react-dom, and Phosphor icons, which draw the
10
+ chrome's own icons unless a host passes its own (see [Icons](#icons)).
10
11
 
11
12
  ## Composing a desktop
12
13
 
@@ -79,6 +80,14 @@ content keeps its width even when a status message briefly takes height from
79
80
  the body. Last, the window moves as far as it must to stay on the surface.
80
81
  `undefined` withdraws the item.
81
82
 
83
+ To open a window already fitted, pass `fitToContent: true` to `create`. The
84
+ window fits once, as Fit to Content would, when its content has loaded and
85
+ reported its size. Content reports its load by calling
86
+ `useCurrentWindow()?.markContentLoaded?.()`, for example once a page has
87
+ rendered. A later call does nothing. A window that is maximized when its
88
+ content loads, as a host might open it on a narrow screen, stays maximized,
89
+ and a window on a hidden surface fits once the surface shows.
90
+
82
91
  ## Slots
83
92
 
84
93
  - **`ContentBoundary`** — `Window` renders a window's component inside this
@@ -115,6 +124,67 @@ row is reserved from the start. An app that never routes passes
115
124
  first registers toolbar actions. From then on the row stays, as in any window,
116
125
  so the body does not shift when actions come and go.
117
126
 
127
+ ## Icons
128
+
129
+ Icons are components, from any icon set. `MenuItem`, `StartMenu` items, and the
130
+ chrome take a `WindowingIcon`: a component that accepts `WindowingIconProps`
131
+ (`aria-hidden`, `className`, `focusable`, and `size`), as Phosphor and Lucide
132
+ icons do. A menu item renders its icon at 16 pixels:
133
+
134
+ ```tsx
135
+ import { NotePencilIcon } from "@phosphor-icons/react";
136
+
137
+ <MenuItem icon={NotePencilIcon} label="Notes" onClick={openNotes} />;
138
+ ```
139
+
140
+ Toolbar actions take a rendered `icon` element instead, as shown above.
141
+
142
+ The chrome draws three icons of its own, from Phosphor: the toolbar's Back
143
+ caret and the title bar menu's Move Forward and Move Backward arrows.
144
+ `WindowingIconsProvider` replaces them for the chrome inside it. An icon it
145
+ leaves out keeps the one from the nearest provider above, or the default:
146
+
147
+ ```tsx
148
+ import { ArrowDown, ArrowUp, ChevronLeft } from "lucide-react";
149
+
150
+ <WindowingIconsProvider
151
+ icons={{ back: ChevronLeft, moveBackward: ArrowDown, moveForward: ArrowUp }}
152
+ >
153
+ <Desktop />
154
+ </WindowingIconsProvider>;
155
+ ```
156
+
157
+ ## Start menu
158
+
159
+ `StartMenu` is a taskbar's start button: place it at the bar's leading edge,
160
+ give it an `icon` to show (a logo or an icon element), and the menu opens above
161
+ the button's top-left corner. Its `items` each take an `id`, `label`, optional
162
+ `icon` and `disabled`, and `onSelect`, which runs after the menu closes and
163
+ receives where the menu opened, for placing a new window near it:
164
+
165
+ ```tsx
166
+ <StartMenu
167
+ icon={<Logo />}
168
+ items={[
169
+ {
170
+ icon: NotePencilIcon,
171
+ id: "notes",
172
+ label: "Notes",
173
+ onSelect: ({ x }) => create("Notes", x, 80, NotesApp),
174
+ },
175
+ ]}
176
+ />
177
+ ```
178
+
179
+ The button is named "Menu" unless `label` says otherwise, and announces its
180
+ menu with `aria-haspopup` and `aria-expanded`. By default it is a square,
181
+ borderless control the height of the bar's controls, lit while hovered,
182
+ focused, or open (`StartMenu.css`). A `className` replaces that styling, so a
183
+ host's own button styles apply alone. A menu that needs more than a list passes
184
+ `renderMenu`, which renders the open menu itself and receives its `position`
185
+ and a `close` callback. Tearleads' footer does this in
186
+ `packages/app/src/shell/pane/footer/PaneFooter.tsx`.
187
+
118
188
  ## Styles
119
189
 
120
190
  Each component imports its own stylesheet, so a bundler that handles CSS imports
@@ -0,0 +1,21 @@
1
+ import { type PropsWithChildren } from "react";
2
+ import type { WindowingIcon } from "./windowingIcon.js";
3
+ /** The icons the window chrome draws on its own. */
4
+ export interface WindowingIcons {
5
+ /** The toolbar's Back button. */
6
+ back: WindowingIcon;
7
+ /** Move Backward, in a title bar's context menu. */
8
+ moveBackward: WindowingIcon;
9
+ /** Move Forward, in a title bar's context menu. */
10
+ moveForward: WindowingIcon;
11
+ }
12
+ /** The chrome's icons: Phosphor's, unless a provider replaces them. */
13
+ export declare function useWindowingIcons(): WindowingIcons;
14
+ /**
15
+ * Draws the chrome inside it with `icons` in place of its Phosphor defaults, so
16
+ * the chrome can match a host's icon set. An icon left out keeps the one from
17
+ * the nearest provider above, or the default.
18
+ */
19
+ export declare function WindowingIconsProvider({ children, icons, }: PropsWithChildren<{
20
+ icons: Partial<WindowingIcons>;
21
+ }>): import("react").JSX.Element;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ArrowDownIcon } from "@phosphor-icons/react/dist/csr/ArrowDown";
3
+ import { ArrowUpIcon } from "@phosphor-icons/react/dist/csr/ArrowUp";
4
+ import { CaretLeftIcon } from "@phosphor-icons/react/dist/csr/CaretLeft";
5
+ import { createContext, useContext, useMemo, } from "react";
6
+ const PHOSPHOR_ICONS = {
7
+ back: CaretLeftIcon,
8
+ moveBackward: ArrowDownIcon,
9
+ moveForward: ArrowUpIcon,
10
+ };
11
+ const WindowingIconsContext = createContext(PHOSPHOR_ICONS);
12
+ /** The chrome's icons: Phosphor's, unless a provider replaces them. */
13
+ export function useWindowingIcons() {
14
+ return useContext(WindowingIconsContext);
15
+ }
16
+ /**
17
+ * Draws the chrome inside it with `icons` in place of its Phosphor defaults, so
18
+ * the chrome can match a host's icon set. An icon left out keeps the one from
19
+ * the nearest provider above, or the default.
20
+ */
21
+ export function WindowingIconsProvider({ children, icons, }) {
22
+ const inherited = useWindowingIcons();
23
+ const { back, moveBackward, moveForward } = icons;
24
+ const value = useMemo(() => ({
25
+ back: back ?? inherited.back,
26
+ moveBackward: moveBackward ?? inherited.moveBackward,
27
+ moveForward: moveForward ?? inherited.moveForward,
28
+ }), [back, inherited, moveBackward, moveForward]);
29
+ return (_jsx(WindowingIconsContext.Provider, { value: value, children: children }));
30
+ }
31
+ //# sourceMappingURL=WindowingIcons.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WindowingIcons.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/icons/WindowingIcons.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AACzE,OAAO,EACL,aAAa,EAEb,UAAU,EACV,OAAO,GACR,MAAM,OAAO,CAAC;AAaf,MAAM,cAAc,GAAmB;IACrC,IAAI,EAAE,aAAa;IACnB,YAAY,EAAE,aAAa;IAC3B,WAAW,EAAE,WAAW;CACzB,CAAC;AAEF,MAAM,qBAAqB,GAAG,aAAa,CAAiB,cAAc,CAAC,CAAC;AAE5E,uEAAuE;AACvE,MAAM,UAAU,iBAAiB;IAC/B,OAAO,UAAU,CAAC,qBAAqB,CAAC,CAAC;AAC3C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,EACrC,QAAQ,EACR,KAAK,GACiD;IACtD,MAAM,SAAS,GAAG,iBAAiB,EAAE,CAAC;IACtC,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAClD,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC;QACL,IAAI,EAAE,IAAI,IAAI,SAAS,CAAC,IAAI;QAC5B,YAAY,EAAE,YAAY,IAAI,SAAS,CAAC,YAAY;QACpD,WAAW,EAAE,WAAW,IAAI,SAAS,CAAC,WAAW;KAClD,CAAC,EACF,CAAC,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,CAAC,CAC7C,CAAC;IACF,OAAO,CACL,KAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACzC,QAAQ,GACsB,CAClC,CAAC;AACJ,CAAC","sourcesContent":["import { ArrowDownIcon } from \"@phosphor-icons/react/dist/csr/ArrowDown\";\nimport { ArrowUpIcon } from \"@phosphor-icons/react/dist/csr/ArrowUp\";\nimport { CaretLeftIcon } from \"@phosphor-icons/react/dist/csr/CaretLeft\";\nimport {\n createContext,\n type PropsWithChildren,\n useContext,\n useMemo,\n} from \"react\";\nimport type { WindowingIcon } from \"./windowingIcon\";\n\n/** The icons the window chrome draws on its own. */\nexport interface WindowingIcons {\n /** The toolbar's Back button. */\n back: WindowingIcon;\n /** Move Backward, in a title bar's context menu. */\n moveBackward: WindowingIcon;\n /** Move Forward, in a title bar's context menu. */\n moveForward: WindowingIcon;\n}\n\nconst PHOSPHOR_ICONS: WindowingIcons = {\n back: CaretLeftIcon,\n moveBackward: ArrowDownIcon,\n moveForward: ArrowUpIcon,\n};\n\nconst WindowingIconsContext = createContext<WindowingIcons>(PHOSPHOR_ICONS);\n\n/** The chrome's icons: Phosphor's, unless a provider replaces them. */\nexport function useWindowingIcons(): WindowingIcons {\n return useContext(WindowingIconsContext);\n}\n\n/**\n * Draws the chrome inside it with `icons` in place of its Phosphor defaults, so\n * the chrome can match a host's icon set. An icon left out keeps the one from\n * the nearest provider above, or the default.\n */\nexport function WindowingIconsProvider({\n children,\n icons,\n}: PropsWithChildren<{ icons: Partial<WindowingIcons> }>) {\n const inherited = useWindowingIcons();\n const { back, moveBackward, moveForward } = icons;\n const value = useMemo(\n () => ({\n back: back ?? inherited.back,\n moveBackward: moveBackward ?? inherited.moveBackward,\n moveForward: moveForward ?? inherited.moveForward,\n }),\n [back, inherited, moveBackward, moveForward],\n );\n return (\n <WindowingIconsContext.Provider value={value}>\n {children}\n </WindowingIconsContext.Provider>\n );\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { ComponentType } from "react";
2
+ /**
3
+ * The props the window chrome renders an icon with. Phosphor and Lucide icons
4
+ * accept them, as does any component that draws an SVG from them.
5
+ */
6
+ export interface WindowingIconProps {
7
+ "aria-hidden"?: boolean | "true" | "false";
8
+ className?: string;
9
+ focusable?: boolean | "true" | "false";
10
+ size?: number | string;
11
+ }
12
+ /** An icon from any icon set, as a component the chrome renders. */
13
+ export type WindowingIcon = ComponentType<WindowingIconProps>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=windowingIcon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windowingIcon.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/icons/windowingIcon.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentType } from \"react\";\n\n/**\n * The props the window chrome renders an icon with. Phosphor and Lucide icons\n * accept them, as does any component that draws an SVG from them.\n */\nexport interface WindowingIconProps {\n \"aria-hidden\"?: boolean | \"true\" | \"false\";\n className?: string;\n focusable?: boolean | \"true\" | \"false\";\n size?: number | string;\n}\n\n/** An icon from any icon set, as a component the chrome renders. */\nexport type WindowingIcon = ComponentType<WindowingIconProps>;\n"]}
package/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export { createRequiredContext, type RequiredContext, } from "./createRequiredContext.js";
2
+ export { type WindowingIcons, WindowingIconsProvider, } from "./icons/WindowingIcons.js";
3
+ export type { WindowingIcon, WindowingIconProps } from "./icons/windowingIcon.js";
2
4
  export { Menu, type MenuPosition } from "./menu/Menu.js";
3
5
  export { MenuItem, type MenuItemProps } from "./menu/MenuItem.js";
6
+ export { StartMenu, type StartMenuItem, type StartMenuProps, } from "./menu/StartMenu.js";
4
7
  export { type ContextMenuState, useContextMenuPositionState, useContextMenuState, } from "./menu/useContextMenuState.js";
5
8
  export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.js";
6
9
  export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, useWindowBackground, useWindowContentSize, } from "./window/CurrentWindowContext.js";
package/index.js CHANGED
@@ -1,9 +1,12 @@
1
1
  import "./tokens.css";
2
2
  // The public windowing API: window state, window chrome and its registration
3
- // hooks, and the menu and sidebar primitives the chrome renders with.
3
+ // hooks, the menu and sidebar primitives the chrome renders with, a taskbar's
4
+ // start menu, and the icons the chrome draws.
4
5
  export { createRequiredContext, } from "./createRequiredContext.js";
6
+ export { WindowingIconsProvider, } from "./icons/WindowingIcons.js";
5
7
  export { Menu } from "./menu/Menu.js";
6
8
  export { MenuItem } from "./menu/MenuItem.js";
9
+ export { StartMenu, } from "./menu/StartMenu.js";
7
10
  export { useContextMenuPositionState, useContextMenuState, } from "./menu/useContextMenuState.js";
8
11
  export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.js";
9
12
  export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, useWindowBackground, useWindowContentSize, } from "./window/CurrentWindowContext.js";
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../home/runner/work/tearleads/tearleads/packages/windowing/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,6EAA6E;AAC7E,sEAAsE;AACtE,OAAO,EACL,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,IAAI,EAAqB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAsB,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAEL,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,MAAM,EAA8B,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,6BAA6B,EAC7B,uBAAuB,EACvB,wBAAwB,EACxB,2BAA2B,EAC3B,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAQlB,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["import \"./tokens.css\";\n\n// The public windowing API: window state, window chrome and its registration\n// hooks, and the menu and sidebar primitives the chrome renders with.\nexport {\n createRequiredContext,\n type RequiredContext,\n} from \"./createRequiredContext\";\nexport { Menu, type MenuPosition } from \"./menu/Menu\";\nexport { MenuItem, type MenuItemProps } from \"./menu/MenuItem\";\nexport {\n type ContextMenuState,\n useContextMenuPositionState,\n useContextMenuState,\n} from \"./menu/useContextMenuState\";\nexport { SidebarResizeHandle, useSidebarResize } from \"./sidebar/SidebarResize\";\nexport {\n CurrentWindowProvider,\n useCurrentWindow,\n useSuppressWindowToolbar,\n useWindowBackground,\n useWindowContentSize,\n} from \"./window/CurrentWindowContext\";\nexport { Window, type WindowContentBoundary } from \"./window/Window\";\nexport { WindowTitleBarActionButtons } from \"./window/WindowChromeActions\";\nexport { WindowCloseButton } from \"./window/WindowCloseButton\";\nexport {\n useWindowBackAction,\n useWindowBackActionValue,\n useWindowFileMenuItem,\n useWindowRefreshMenuItem,\n useWindowRefreshMenuItemValue,\n useWindowTitleBarAction,\n useWindowTitleBarActions,\n useWindowToolbarReservation,\n useWindowViewMenuItem,\n WindowMenuProvider,\n} from \"./window/WindowMenuContext\";\nexport {\n hasWindowSidebar,\n useRegisteredWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./window/WindowSidebarContext\";\nexport {\n findTopWindow,\n useWindowActions,\n useWindowStateData,\n type WindowCreateOptions,\n type WindowEntry,\n type WindowGeometry,\n type WindowPosition,\n type WindowSize,\n type WindowStateActions,\n type WindowStateData,\n WindowStateProvider,\n} from \"./window/WindowStateProvider\";\nexport { WindowToolBar } from \"./window/WindowToolBar\";\n"]}
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,8EAA8E;AAC9E,8CAA8C;AAC9C,OAAO,EACL,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,IAAI,EAAqB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAsB,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EACL,SAAS,GAGV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,MAAM,EAA8B,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,6BAA6B,EAC7B,uBAAuB,EACvB,wBAAwB,EACxB,2BAA2B,EAC3B,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAQlB,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["import \"./tokens.css\";\n\n// The public windowing API: window state, window chrome and its registration\n// hooks, the menu and sidebar primitives the chrome renders with, a taskbar's\n// start menu, and the icons the chrome draws.\nexport {\n createRequiredContext,\n type RequiredContext,\n} from \"./createRequiredContext\";\nexport {\n type WindowingIcons,\n WindowingIconsProvider,\n} from \"./icons/WindowingIcons\";\nexport type { WindowingIcon, WindowingIconProps } from \"./icons/windowingIcon\";\nexport { Menu, type MenuPosition } from \"./menu/Menu\";\nexport { MenuItem, type MenuItemProps } from \"./menu/MenuItem\";\nexport {\n StartMenu,\n type StartMenuItem,\n type StartMenuProps,\n} from \"./menu/StartMenu\";\nexport {\n type ContextMenuState,\n useContextMenuPositionState,\n useContextMenuState,\n} from \"./menu/useContextMenuState\";\nexport { SidebarResizeHandle, useSidebarResize } from \"./sidebar/SidebarResize\";\nexport {\n CurrentWindowProvider,\n useCurrentWindow,\n useSuppressWindowToolbar,\n useWindowBackground,\n useWindowContentSize,\n} from \"./window/CurrentWindowContext\";\nexport { Window, type WindowContentBoundary } from \"./window/Window\";\nexport { WindowTitleBarActionButtons } from \"./window/WindowChromeActions\";\nexport { WindowCloseButton } from \"./window/WindowCloseButton\";\nexport {\n useWindowBackAction,\n useWindowBackActionValue,\n useWindowFileMenuItem,\n useWindowRefreshMenuItem,\n useWindowRefreshMenuItemValue,\n useWindowTitleBarAction,\n useWindowTitleBarActions,\n useWindowToolbarReservation,\n useWindowViewMenuItem,\n WindowMenuProvider,\n} from \"./window/WindowMenuContext\";\nexport {\n hasWindowSidebar,\n useRegisteredWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./window/WindowSidebarContext\";\nexport {\n findTopWindow,\n useWindowActions,\n useWindowStateData,\n type WindowCreateOptions,\n type WindowEntry,\n type WindowGeometry,\n type WindowPosition,\n type WindowSize,\n type WindowStateActions,\n type WindowStateData,\n WindowStateProvider,\n} from \"./window/WindowStateProvider\";\nexport { WindowToolBar } from \"./window/WindowToolBar\";\n"]}
@@ -1,9 +1,10 @@
1
- import type { Icon } from "@phosphor-icons/react";
2
1
  import type { MouseEventHandler } from "react";
2
+ import type { WindowingIcon } from "../icons/windowingIcon.js";
3
3
  export interface MenuItemProps {
4
- icon?: Icon;
4
+ /** Any icon component, such as a Phosphor or Lucide icon. */
5
+ icon?: WindowingIcon | undefined;
5
6
  label: string;
6
- disabled?: boolean;
7
+ disabled?: boolean | undefined;
7
8
  onClick: MouseEventHandler<HTMLButtonElement>;
8
9
  }
9
10
  export declare function MenuItem({ icon: IconComponent, label, disabled, onClick, }: MenuItemProps): import("react").JSX.Element;
package/menu/MenuItem.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  export function MenuItem({ icon: IconComponent, label, disabled, onClick, }) {
3
- return (_jsxs("button", { type: "button", disabled: disabled, onClick: onClick, children: [IconComponent && (_jsx(IconComponent, { "aria-hidden": "true", className: "menu-item-icon", focusable: "false", size: 16, weight: "regular" })), _jsx("span", { className: "menu-item-label", children: label })] }));
3
+ return (_jsxs("button", { type: "button", disabled: disabled, onClick: onClick, children: [IconComponent && (_jsx(IconComponent, { "aria-hidden": "true", className: "menu-item-icon", focusable: "false", size: 16 })), _jsx("span", { className: "menu-item-label", children: label })] }));
4
4
  }
5
5
  //# sourceMappingURL=MenuItem.js.map
@@ -1 +1 @@
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
+ {"version":3,"file":"MenuItem.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/MenuItem.tsx"],"names":[],"mappings":";AAWA,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,GACR,CACH,EACD,eAAM,SAAS,EAAC,iBAAiB,YAAE,KAAK,GAAQ,IACzC,CACV,CAAC;AACJ,CAAC","sourcesContent":["import type { MouseEventHandler } from \"react\";\nimport type { WindowingIcon } from \"../icons/windowingIcon\";\n\nexport interface MenuItemProps {\n /** Any icon component, such as a Phosphor or Lucide icon. */\n icon?: WindowingIcon | undefined;\n label: string;\n disabled?: boolean | undefined;\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 />\n )}\n <span className=\"menu-item-label\">{label}</span>\n </button>\n );\n}\n"]}
@@ -0,0 +1,26 @@
1
+ /*
2
+ * The start menu button's default look: a square, borderless control the
3
+ * height of the bar's other controls, lit while hovered, focused, or open. A
4
+ * host that passes its own classes replaces this class, and with it these rules.
5
+ */
6
+ .start-menu-button {
7
+ display: inline-flex;
8
+ flex: 0 0 auto;
9
+ align-items: center;
10
+ justify-content: center;
11
+ width: var(--control-height);
12
+ height: var(--control-height);
13
+ padding: 0;
14
+ border: 0;
15
+ border-radius: var(--app-radius-control);
16
+ background: transparent;
17
+ color: inherit;
18
+ cursor: pointer;
19
+ }
20
+
21
+ .start-menu-button:hover,
22
+ .start-menu-button:focus-visible,
23
+ .start-menu-button[aria-expanded="true"] {
24
+ background: var(--emphasis-surface);
25
+ color: var(--emphasis-text);
26
+ }
@@ -0,0 +1,42 @@
1
+ import type { ReactNode } from "react";
2
+ import type { WindowingIcon } from "../icons/windowingIcon.js";
3
+ import { type MenuPosition } from "./Menu.js";
4
+ /** One entry in a {@link StartMenu}. */
5
+ export interface StartMenuItem {
6
+ disabled?: boolean | undefined;
7
+ icon?: WindowingIcon | undefined;
8
+ id: string;
9
+ label: string;
10
+ /**
11
+ * Runs when the item is chosen, after the menu closes. `position` is where
12
+ * the menu opened, for placing what the item opens near it.
13
+ */
14
+ onSelect: (position: MenuPosition) => void;
15
+ }
16
+ export interface StartMenuProps {
17
+ /**
18
+ * Classes for the button. They replace the default `start-menu-button`
19
+ * styling, so a host's own button styles apply alone.
20
+ */
21
+ className?: string | undefined;
22
+ /** What the button shows, such as a logo or an icon. */
23
+ icon: ReactNode;
24
+ /** The menu's entries, in order. Ignored when `renderMenu` is given. */
25
+ items?: readonly StartMenuItem[] | undefined;
26
+ /** The button's accessible name. */
27
+ label?: string | undefined;
28
+ /**
29
+ * Renders the open menu itself, such as a `Menu` whose content needs more
30
+ * than a list of items, in place of `items`. Call `close` to close it.
31
+ */
32
+ renderMenu?: ((menu: {
33
+ close: () => void;
34
+ position: MenuPosition;
35
+ }) => ReactNode) | undefined;
36
+ }
37
+ /**
38
+ * A taskbar's start menu: a button, usually at the bar's leading edge, that
39
+ * opens a menu above its top-left corner. Give it `items` for a list of
40
+ * entries, or `renderMenu` to render the menu yourself.
41
+ */
42
+ export declare function StartMenu({ className, icon, items, label, renderMenu, }: StartMenuProps): import("react").JSX.Element;
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Menu } from "./Menu.js";
3
+ import { MenuItem } from "./MenuItem.js";
4
+ import "./StartMenu.css";
5
+ import { useContextMenuPositionState } from "./useContextMenuState.js";
6
+ /**
7
+ * A taskbar's start menu: a button, usually at the bar's leading edge, that
8
+ * opens a menu above its top-left corner. Give it `items` for a list of
9
+ * entries, or `renderMenu` to render the menu yourself.
10
+ */
11
+ export function StartMenu({ className, icon, items = [], label = "Menu", renderMenu, }) {
12
+ const { closeContextMenu: close, contextMenu: position, openContextMenuAt, } = useContextMenuPositionState();
13
+ return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: className ?? "start-menu-button", "aria-label": label, "aria-haspopup": "menu", "aria-expanded": position !== null, onClick: (event) => {
14
+ const bounds = event.currentTarget.getBoundingClientRect();
15
+ openContextMenuAt({ x: bounds.left, y: bounds.top });
16
+ }, children: icon }), position &&
17
+ (renderMenu ? (renderMenu({ close, position })) : (_jsx(Menu, { position: position, onClose: close, children: items.map((item) => (_jsx(MenuItem, { disabled: item.disabled, icon: item.icon, label: item.label, onClick: () => {
18
+ close();
19
+ item.onSelect(position);
20
+ } }, item.id))) })))] }));
21
+ }
22
+ //# sourceMappingURL=StartMenu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StartMenu.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/StartMenu.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,IAAI,EAAqB,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,iBAAiB,CAAC;AACzB,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAoCpE;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,EACxB,SAAS,EACT,IAAI,EACJ,KAAK,GAAG,EAAE,EACV,KAAK,GAAG,MAAM,EACd,UAAU,GACK;IACf,MAAM,EACJ,gBAAgB,EAAE,KAAK,EACvB,WAAW,EAAE,QAAQ,EACrB,iBAAiB,GAClB,GAAG,2BAA2B,EAAE,CAAC;IAElC,OAAO,CACL,8BACE,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAE,SAAS,IAAI,mBAAmB,gBAC/B,KAAK,mBACH,MAAM,mBACL,QAAQ,KAAK,IAAI,EAChC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;oBACjB,MAAM,MAAM,GAAG,KAAK,CAAC,aAAa,CAAC,qBAAqB,EAAE,CAAC;oBAC3D,iBAAiB,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;gBACvD,CAAC,YAEA,IAAI,GACE,EACR,QAAQ;gBACP,CAAC,UAAU,CAAC,CAAC,CAAC,CACZ,UAAU,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAChC,CAAC,CAAC,CAAC,CACF,KAAC,IAAI,IAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,YACrC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACnB,KAAC,QAAQ,IAEP,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,OAAO,EAAE,GAAG,EAAE;4BACZ,KAAK,EAAE,CAAC;4BACR,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;wBAC1B,CAAC,IAPI,IAAI,CAAC,EAAE,CAQZ,CACH,CAAC,GACG,CACR,CAAC,IACH,CACJ,CAAC;AACJ,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport type { WindowingIcon } from \"../icons/windowingIcon\";\nimport { Menu, type MenuPosition } from \"./Menu\";\nimport { MenuItem } from \"./MenuItem\";\nimport \"./StartMenu.css\";\nimport { useContextMenuPositionState } from \"./useContextMenuState\";\n\n/** One entry in a {@link StartMenu}. */\nexport interface StartMenuItem {\n disabled?: boolean | undefined;\n icon?: WindowingIcon | undefined;\n id: string;\n label: string;\n /**\n * Runs when the item is chosen, after the menu closes. `position` is where\n * the menu opened, for placing what the item opens near it.\n */\n onSelect: (position: MenuPosition) => void;\n}\n\nexport interface StartMenuProps {\n /**\n * Classes for the button. They replace the default `start-menu-button`\n * styling, so a host's own button styles apply alone.\n */\n className?: string | undefined;\n /** What the button shows, such as a logo or an icon. */\n icon: ReactNode;\n /** The menu's entries, in order. Ignored when `renderMenu` is given. */\n items?: readonly StartMenuItem[] | undefined;\n /** The button's accessible name. */\n label?: string | undefined;\n /**\n * Renders the open menu itself, such as a `Menu` whose content needs more\n * than a list of items, in place of `items`. Call `close` to close it.\n */\n renderMenu?:\n | ((menu: { close: () => void; position: MenuPosition }) => ReactNode)\n | undefined;\n}\n\n/**\n * A taskbar's start menu: a button, usually at the bar's leading edge, that\n * opens a menu above its top-left corner. Give it `items` for a list of\n * entries, or `renderMenu` to render the menu yourself.\n */\nexport function StartMenu({\n className,\n icon,\n items = [],\n label = \"Menu\",\n renderMenu,\n}: StartMenuProps) {\n const {\n closeContextMenu: close,\n contextMenu: position,\n openContextMenuAt,\n } = useContextMenuPositionState();\n\n return (\n <>\n <button\n type=\"button\"\n className={className ?? \"start-menu-button\"}\n aria-label={label}\n aria-haspopup=\"menu\"\n aria-expanded={position !== null}\n onClick={(event) => {\n const bounds = event.currentTarget.getBoundingClientRect();\n openContextMenuAt({ x: bounds.left, y: bounds.top });\n }}\n >\n {icon}\n </button>\n {position &&\n (renderMenu ? (\n renderMenu({ close, position })\n ) : (\n <Menu position={position} onClose={close}>\n {items.map((item) => (\n <MenuItem\n key={item.id}\n disabled={item.disabled}\n icon={item.icon}\n label={item.label}\n onClick={() => {\n close();\n item.onSelect(position);\n }}\n />\n ))}\n </Menu>\n ))}\n </>\n );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tearleads/windowing",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "App-agnostic window management for React: window state, window chrome, and the menu and sidebar primitives it renders with.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -3,6 +3,13 @@ import type { WindowSize } from "./WindowStateProvider/index.js";
3
3
  interface CurrentWindowContextValue {
4
4
  close: () => void;
5
5
  id: string;
6
+ /**
7
+ * Tell the window its content has loaded. A window opened with
8
+ * `fitToContent` fits then, once the content has reported its size; later
9
+ * calls do nothing. Hosts that render this provider outside a `Window` may
10
+ * omit it.
11
+ */
12
+ markContentLoaded?: (() => void) | undefined;
6
13
  overlayHost: HTMLElement | null;
7
14
  /**
8
15
  * Paint the window's background with `background`, any CSS color, in place of
@@ -23,7 +30,7 @@ interface CurrentWindowContextValue {
23
30
  */
24
31
  suppressToolbar: () => () => void;
25
32
  }
26
- export declare function CurrentWindowProvider({ children, close, id, overlayHost, setBackground, setContentSize, showStatusMessage, suppressToolbar, }: PropsWithChildren<CurrentWindowContextValue>): import("react").JSX.Element;
33
+ export declare function CurrentWindowProvider({ children, close, id, markContentLoaded, overlayHost, setBackground, setContentSize, showStatusMessage, suppressToolbar, }: PropsWithChildren<CurrentWindowContextValue>): import("react").JSX.Element;
27
34
  export declare function useCurrentWindow(): CurrentWindowContextValue | null;
28
35
  /**
29
36
  * Drop the host window's toolbar row while `active`.
@@ -1,10 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createContext, useContext, useEffect, useLayoutEffect, useMemo, } from "react";
3
3
  const CurrentWindowContext = createContext(null);
4
- export function CurrentWindowProvider({ children, close, id, overlayHost, setBackground, setContentSize, showStatusMessage, suppressToolbar, }) {
4
+ export function CurrentWindowProvider({ children, close, id, markContentLoaded, overlayHost, setBackground, setContentSize, showStatusMessage, suppressToolbar, }) {
5
5
  const value = useMemo(() => ({
6
6
  close,
7
7
  id,
8
+ markContentLoaded,
8
9
  overlayHost,
9
10
  setBackground,
10
11
  setContentSize,
@@ -13,6 +14,7 @@ export function CurrentWindowProvider({ children, close, id, overlayHost, setBac
13
14
  }), [
14
15
  close,
15
16
  id,
17
+ markContentLoaded,
16
18
  overlayHost,
17
19
  setBackground,
18
20
  setContentSize,
@@ -1 +1 @@
1
- {"version":3,"file":"CurrentWindowContext.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/CurrentWindowContext.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAE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C;YAC/C,OAAO;QACT,CAAC;QACD,aAAa,CAAC,UAAU,CAAC,CAAC;QAC1B,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAA4B;IAC/D,MAAM,cAAc,GAAG,gBAAgB,EAAE,EAAE,cAAc,CAAC;IAC1D,MAAM,KAAK,GAAG,IAAI,EAAE,KAAK,CAAC;IAC1B,MAAM,MAAM,GAAG,IAAI,EAAE,MAAM,CAAC;IAE5B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,KAAK,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,cAAc,EAAE,CAAC;YACnE,OAAO;QACT,CAAC;QACD,cAAc,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QAClC,OAAO,GAAG,EAAE,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import {\n createContext,\n type PropsWithChildren,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n} from \"react\";\nimport type { WindowSize } from \"./WindowStateProvider\";\n\ninterface CurrentWindowContextValue {\n close: () => void;\n id: string;\n overlayHost: HTMLElement | null;\n /**\n * Paint the window's background with `background`, any CSS color, in place of\n * `--window-background`; `undefined` restores it. Hosts that render this\n * provider outside a `Window` may omit it.\n */\n setBackground?: ((background: string | undefined) => void) | undefined;\n /**\n * Record the content's natural size, which the window's Fit to Content sizes\n * it to; `undefined` withdraws it. Hosts that render this provider outside a\n * `Window` may omit it.\n */\n setContentSize?: ((size: WindowSize | undefined) => void) | undefined;\n showStatusMessage: (message: string) => void;\n /**\n * Hide the window's toolbar row until the returned release is called. Refcounted,\n * so overlapping suppressions restore the row only once the last one releases.\n */\n suppressToolbar: () => () => void;\n}\n\nconst CurrentWindowContext = createContext<CurrentWindowContextValue | null>(\n null,\n);\n\nexport function CurrentWindowProvider({\n children,\n close,\n id,\n overlayHost,\n setBackground,\n setContentSize,\n showStatusMessage,\n suppressToolbar,\n}: PropsWithChildren<CurrentWindowContextValue>) {\n const value = useMemo(\n () => ({\n close,\n id,\n overlayHost,\n setBackground,\n setContentSize,\n showStatusMessage,\n suppressToolbar,\n }),\n [\n close,\n id,\n overlayHost,\n setBackground,\n setContentSize,\n showStatusMessage,\n suppressToolbar,\n ],\n );\n\n return (\n <CurrentWindowContext.Provider value={value}>\n {children}\n </CurrentWindowContext.Provider>\n );\n}\n\nexport function useCurrentWindow() {\n return useContext(CurrentWindowContext);\n}\n\n/**\n * Drop the host window's toolbar row while `active`.\n *\n * A full-pane overlay (the image viewer) carries its own toolbar, and the\n * window's row would otherwise stack directly above it — two toolbars, one of\n * them driving chrome the overlay covers. Outside a window this is inert, since\n * the routed shell's overlays cover the whole viewport already.\n *\n * Suppressing in a layout effect keeps the row from being painted alongside the\n * overlay's own toolbar for a frame and then resizing the pane out from under it.\n */\nexport function useSuppressWindowToolbar(active: boolean) {\n const suppressToolbar = useCurrentWindow()?.suppressToolbar;\n\n useLayoutEffect(() => {\n if (!active || !suppressToolbar) {\n return;\n }\n return suppressToolbar();\n }, [active, suppressToolbar]);\n}\n\n/**\n * Paint the host window's background, behind its body and sidebar, with\n * `background` (any CSS color) while mounted; `undefined` keeps the default,\n * `--window-background`. A document viewer uses it to set its page apart from\n * the window around it. Outside a window this is inert.\n *\n * Applying it in a layout effect keeps the default from being painted for a\n * frame before the content's own background.\n */\nexport function useWindowBackground(background: string | undefined) {\n const setBackground = useCurrentWindow()?.setBackground;\n\n useLayoutEffect(() => {\n if (background === undefined || !setBackground) {\n return;\n }\n setBackground(background);\n return () => setBackground(undefined);\n }, [background, setBackground]);\n}\n\n/**\n * Offer Fit to Content in the host window's View menu while mounted. It sizes\n * the window so its content area shows `size`, the content's natural size in\n * CSS pixels, as far as the desktop surface allows; content that still scrolls\n * gets room for its scrollbar. `undefined` withdraws the item. Outside a window\n * this is inert.\n */\nexport function useWindowContentSize(size: WindowSize | undefined) {\n const setContentSize = useCurrentWindow()?.setContentSize;\n const width = size?.width;\n const height = size?.height;\n\n useEffect(() => {\n if (width === undefined || height === undefined || !setContentSize) {\n return;\n }\n setContentSize({ height, width });\n return () => setContentSize(undefined);\n }, [height, setContentSize, width]);\n}\n"]}
1
+ {"version":3,"file":"CurrentWindowContext.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/CurrentWindowContext.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAEb,UAAU,EACV,SAAS,EACT,eAAe,EACf,OAAO,GACR,MAAM,OAAO,CAAC;AAkCf,MAAM,oBAAoB,GAAG,aAAa,CACxC,IAAI,CACL,CAAC;AAEF,MAAM,UAAU,qBAAqB,CAAC,EACpC,QAAQ,EACR,KAAK,EACL,EAAE,EACF,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,eAAe,GAC8B;IAC7C,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC;QACL,KAAK;QACL,EAAE;QACF,iBAAiB;QACjB,WAAW;QACX,aAAa;QACb,cAAc;QACd,iBAAiB;QACjB,eAAe;KAChB,CAAC,EACF;QACE,KAAK;QACL,EAAE;QACF,iBAAiB;QACjB,WAAW;QACX,aAAa;QACb,cAAc;QACd,iBAAiB;QACjB,eAAe;KAChB,CACF,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;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AC,CAAC;AACtC,CAAC","sourcesContent":["import {\n createContext,\n type PropsWithChildren,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n} from \"react\";\nimport type { WindowSize } from \"./WindowStateProvider\";\n\ninterface CurrentWindowContextValue {\n close: () => void;\n id: string;\n /**\n * Tell the window its content has loaded. A window opened with\n * `fitToContent` fits then, once the content has reported its size; later\n * calls do nothing. Hosts that render this provider outside a `Window` may\n * omit it.\n */\n markContentLoaded?: (() => void) | undefined;\n overlayHost: HTMLElement | null;\n /**\n * Paint the window's background with `background`, any CSS color, in place of\n * `--window-background`; `undefined` restores it. Hosts that render this\n * provider outside a `Window` may omit it.\n */\n setBackground?: ((background: string | undefined) => void) | undefined;\n /**\n * Record the content's natural size, which the window's Fit to Content sizes\n * it to; `undefined` withdraws it. Hosts that render this provider outside a\n * `Window` may omit it.\n */\n setContentSize?: ((size: WindowSize | undefined) => void) | undefined;\n showStatusMessage: (message: string) => void;\n /**\n * Hide the window's toolbar row until the returned release is called. Refcounted,\n * so overlapping suppressions restore the row only once the last one releases.\n */\n suppressToolbar: () => () => void;\n}\n\nconst CurrentWindowContext = createContext<CurrentWindowContextValue | null>(\n null,\n);\n\nexport function CurrentWindowProvider({\n children,\n close,\n id,\n markContentLoaded,\n overlayHost,\n setBackground,\n setContentSize,\n showStatusMessage,\n suppressToolbar,\n}: PropsWithChildren<CurrentWindowContextValue>) {\n const value = useMemo(\n () => ({\n close,\n id,\n markContentLoaded,\n overlayHost,\n setBackground,\n setContentSize,\n showStatusMessage,\n suppressToolbar,\n }),\n [\n close,\n id,\n markContentLoaded,\n overlayHost,\n setBackground,\n setContentSize,\n showStatusMessage,\n suppressToolbar,\n ],\n );\n\n return (\n <CurrentWindowContext.Provider value={value}>\n {children}\n </CurrentWindowContext.Provider>\n );\n}\n\nexport function useCurrentWindow() {\n return useContext(CurrentWindowContext);\n}\n\n/**\n * Drop the host window's toolbar row while `active`.\n *\n * A full-pane overlay (the image viewer) carries its own toolbar, and the\n * window's row would otherwise stack directly above it — two toolbars, one of\n * them driving chrome the overlay covers. Outside a window this is inert, since\n * the routed shell's overlays cover the whole viewport already.\n *\n * Suppressing in a layout effect keeps the row from being painted alongside the\n * overlay's own toolbar for a frame and then resizing the pane out from under it.\n */\nexport function useSuppressWindowToolbar(active: boolean) {\n const suppressToolbar = useCurrentWindow()?.suppressToolbar;\n\n useLayoutEffect(() => {\n if (!active || !suppressToolbar) {\n return;\n }\n return suppressToolbar();\n }, [active, suppressToolbar]);\n}\n\n/**\n * Paint the host window's background, behind its body and sidebar, with\n * `background` (any CSS color) while mounted; `undefined` keeps the default,\n * `--window-background`. A document viewer uses it to set its page apart from\n * the window around it. Outside a window this is inert.\n *\n * Applying it in a layout effect keeps the default from being painted for a\n * frame before the content's own background.\n */\nexport function useWindowBackground(background: string | undefined) {\n const setBackground = useCurrentWindow()?.setBackground;\n\n useLayoutEffect(() => {\n if (background === undefined || !setBackground) {\n return;\n }\n setBackground(background);\n return () => setBackground(undefined);\n }, [background, setBackground]);\n}\n\n/**\n * Offer Fit to Content in the host window's View menu while mounted. It sizes\n * the window so its content area shows `size`, the content's natural size in\n * CSS pixels, as far as the desktop surface allows; content that still scrolls\n * gets room for its scrollbar. `undefined` withdraws the item. Outside a window\n * this is inert.\n */\nexport function useWindowContentSize(size: WindowSize | undefined) {\n const setContentSize = useCurrentWindow()?.setContentSize;\n const width = size?.width;\n const height = size?.height;\n\n useEffect(() => {\n if (width === undefined || height === undefined || !setContentSize) {\n return;\n }\n setContentSize({ height, width });\n return () => setContentSize(undefined);\n }, [height, setContentSize, width]);\n}\n"]}
package/window/Window.js CHANGED
@@ -185,7 +185,7 @@ function WindowInnerContent({ ContentBoundary, entry, historyBack, isTop, }) {
185
185
  const hasSidebar = hasWindowSidebar(sidebar);
186
186
  const { handlePointerDown, handleResizePointerDown, position, size, ...stepped } = useWindowGeometry(entry, maximized, windowRef);
187
187
  const { showStatusMessage, statusText } = useWindowStatusMessage();
188
- const { geometryMenuItems, setContentSize } = useWindowGeometryMenu(entry, stepped, { overlayHost, windowRef }, showStatusMessage);
188
+ const { contentFit, geometryMenuItems } = useWindowGeometryMenu(entry, stepped, { overlayHost, windowRef }, showStatusMessage);
189
189
  const actions = useWindowActions(entry, fileMenuItems, viewMenuItems, geometryMenuItems, hasSidebar);
190
190
  // A maximized window fills its surface without a laid-out position.
191
191
  useFocusWindowOnShow(windowRef, {
@@ -201,7 +201,7 @@ function WindowInnerContent({ ContentBoundary, entry, historyBack, isTop, }) {
201
201
  // A section labelled by its title is a region landmark. Windows are
202
202
  // non-modal and freely arranged, so they are not dialogs; hosts keep that
203
203
  // role for the modals they open inside a window.
204
- return (_jsxs("section", { ref: windowRef, "aria-labelledby": titleId, className: maximized ? "window window--maximized" : "window", tabIndex: -1, ...windowContextMenuTrapProps, onPointerDownCapture: handleWindowPointerDown, style: style, children: [_jsx(WindowChrome, { actions: actions, entry: entry, historyBack: historyBack, onGoBack: handleGoBack, onPointerDown: handlePointerDown, titleId: titleId, toolbarSuppressed: toolbarSuppressed }), _jsx(CurrentWindowProvider, { close: actions.handleClose, id: entry.id, overlayHost: overlayHost, setBackground: setBackground, setContentSize: setContentSize, showStatusMessage: showStatusMessage, suppressToolbar: suppressToolbar, children: _jsx(WindowBodyWithSidebar, { overlayHostRef: setOverlayHost, showSidebar: actions.showSidebar, children: ContentBoundary ? (_jsx(ContentBoundary, { entry: entry, children: Component && _jsx(Component, {}) })) : (Component && _jsx(Component, {})) }) }), _jsx(WindowStatusBar, { text: statusText, visible: actions.showStatusBar }), !maximized && (_jsx(WindowResizeHandles, { handleResizePointerDown: handleResizePointerDown }))] }));
204
+ return (_jsxs("section", { ref: windowRef, "aria-labelledby": titleId, className: maximized ? "window window--maximized" : "window", tabIndex: -1, ...windowContextMenuTrapProps, onPointerDownCapture: handleWindowPointerDown, style: style, children: [_jsx(WindowChrome, { actions: actions, entry: entry, historyBack: historyBack, onGoBack: handleGoBack, onPointerDown: handlePointerDown, titleId: titleId, toolbarSuppressed: toolbarSuppressed }), _jsx(CurrentWindowProvider, { close: actions.handleClose, id: entry.id, overlayHost: overlayHost, setBackground: setBackground, ...contentFit, showStatusMessage: showStatusMessage, suppressToolbar: suppressToolbar, children: _jsx(WindowBodyWithSidebar, { overlayHostRef: setOverlayHost, showSidebar: actions.showSidebar, children: ContentBoundary ? (_jsx(ContentBoundary, { entry: entry, children: Component && _jsx(Component, {}) })) : (Component && _jsx(Component, {})) }) }), _jsx(WindowStatusBar, { text: statusText, visible: actions.showStatusBar }), !maximized && (_jsx(WindowResizeHandles, { handleResizePointerDown: handleResizePointerDown }))] }));
205
205
  }
206
206
  function WindowBodyWithSidebar({ showSidebar, overlayHostRef, children, }) {
207
207
  const { sidebar } = useWindowSidebar();
@@ -1 +1 @@
1
- {"version":3,"file":"Window.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/Window.tsx"],"names":[],"mappings":";AAAA,OAAO,EAOL,WAAW,EACX,SAAS,EACT,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AACrE,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;A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AK,EAAE,KAAK,YAC1B,SAAS,IAAI,KAAC,SAAS,KAAG,GACX,CACnB,CAAC,CAAC,CAAC,CACF,SAAS,IAAI,KAAC,SAAS,KAAG,CAC3B,GACqB,GACF,EACxB,KAAC,eAAe,IAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,aAAa,GAAI,EACpE,CAAC,SAAS,IAAI,CACb,KAAC,mBAAmB,IAClB,uBAAuB,EAAE,uBAAuB,GAChD,CACH,IACO,CACX,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,EAC7B,WAAW,EACX,cAAc,EACd,QAAQ,GAIR;IACA,MAAM,EAAE,OAAO,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACvC,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE7C,OAAO,CACL,KAAC,UAAU,IACT,UAAU,EAAE,cAAc,EAC1B,WAAW,EAAE,WAAW,IAAI,UAAU,EACtC,OAAO,EAAE,OAAO,YAEf,QAAQ,GACE,CACd,CAAC;AACJ,CAAC","sourcesContent":["import {\n type ComponentType,\n type CSSProperties,\n type HTMLAttributes,\n type PropsWithChildren,\n type MouseEvent as ReactMouseEvent,\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport \"./Window.css\";\nimport { CurrentWindowProvider } from \"./CurrentWindowContext\";\nimport { useWindowGeometryMenu } from \"./useWindowFit\";\nimport { useWindowGeometry } from \"./useWindowGeometry\";\nimport { useFocusWindowOnShow } from \"./useWindowKeyboardGeometry\";\nimport { WindowBody } from \"./WindowBody\";\nimport { WindowMenuBar, type WindowMenuItem } from \"./WindowMenuBar\";\nimport {\n useWindowFileMenuItems,\n useWindowViewMenuItems,\n WindowMenuProvider,\n} from \"./WindowMenuContext\";\nimport { WindowResizeHandles } from \"./WindowResizeHandle\";\nimport {\n hasWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./WindowSidebarContext\";\nimport {\n findTopWindow,\n useWindowActions as useWindowStateActions,\n useWindowStateData,\n type WindowEntry,\n type WindowPosition,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport { WindowStatusBar } from \"./WindowStatusBar\";\nimport { WindowTitleBar } from \"./WindowTitleBar\";\nimport { WindowToolBar } from \"./WindowToolBar\";\n\n// Wraps a window's content so the host can give it app-specific context (a\n// route, an error boundary) without the window layer knowing about apps.\nexport type WindowContentBoundary = ComponentType<\n PropsWithChildren<{ entry: WindowEntry }>\n>;\n\ninterface WindowProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n /**\n * Whether the toolbar offers Back through the window's own route history,\n * reserving its row from the start (see `WindowToolBar`). Defaults to whether\n * the window has an `appId`. Pass false for an app that never routes, so its\n * window has no toolbar row until the app first registers toolbar actions.\n */\n historyBack?: boolean | undefined;\n windowId: string;\n}\n\nconst WINDOW_STATUS_MESSAGE_DURATION_MS = 2500;\n\nexport function Window({\n ContentBoundary,\n historyBack,\n windowId,\n}: WindowProps) {\n const { windowMap, windows } = useWindowStateData();\n const entry = windowMap.get(windowId);\n const isTop =\n findTopWindow(windows, (candidate) => !candidate.minimized)?.id ===\n windowId;\n\n if (!entry) return null;\n\n return (\n <WindowInner\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack ?? entry.appId !== undefined}\n isTop={isTop}\n />\n );\n}\n\nfunction useWindowActions(\n entry: WindowEntry,\n fileMenuItems: WindowMenuItem[],\n viewMenuItems: WindowMenuItem[],\n geometryMenuItems: WindowMenuItem[],\n hasSidebar: boolean,\n) {\n const { close, minimize, moveBackward, moveForward, toggleMaximize } =\n useWindowStateActions();\n const [showStatusBar, setShowStatusBar] = useState(true);\n const [showSidebar, setShowSidebar] = useState(\n entry.initialShowSidebar ?? true,\n );\n const handleClose = useCallback(() => close(entry.id), [close, entry.id]);\n const handleMinimize = useCallback(\n () => minimize(entry.id),\n [entry.id, minimize],\n );\n const handleMoveForward = useCallback(\n () => moveForward(entry.id),\n [entry.id, moveForward],\n );\n const handleMoveBackward = useCallback(\n () => moveBackward(entry.id),\n [entry.id, moveBackward],\n );\n const handleMaximize = useCallback(\n () => toggleMaximize(entry.id),\n [entry.id, toggleMaximize],\n );\n const toggleStatusBar = useCallback(\n () => setShowStatusBar((previous) => !previous),\n [],\n );\n const toggleSidebar = useCallback(\n () => setShowSidebar((previous) => !previous),\n [],\n );\n const menus = useMemo(\n () => [\n {\n label: \"File\",\n items: [\n ...fileMenuItems,\n { id: \"close\", label: \"Close\", onClick: handleClose },\n ],\n },\n {\n label: \"View\",\n items: [\n ...viewMenuItems,\n ...geometryMenuItems,\n {\n id: \"toggle-status-bar\",\n label: `${showStatusBar ? \"Hide\" : \"Show\"} Status Bar`,\n onClick: toggleStatusBar,\n },\n ...(hasSidebar\n ? [\n {\n id: \"toggle-sidebar\",\n label: `${showSidebar ? \"Hide\" : \"Show\"} Sidebar`,\n onClick: toggleSidebar,\n },\n ]\n : []),\n ],\n },\n ],\n [\n geometryMenuItems,\n hasSidebar,\n handleClose,\n fileMenuItems,\n showSidebar,\n showStatusBar,\n toggleSidebar,\n toggleStatusBar,\n viewMenuItems,\n ],\n );\n\n return {\n handleClose,\n handleMaximize,\n handleMinimize,\n handleMoveBackward,\n handleMoveForward,\n menus,\n showSidebar,\n showStatusBar,\n };\n}\n\n// The window paints with `--window-background`, which a background its content\n// sets (see `useWindowBackground`) overrides inline.\ninterface WindowStyle extends CSSProperties {\n \"--window-background\"?: string | undefined;\n}\n\nfunction getWindowFrameStyle(\n maximized: boolean,\n position: WindowPosition | null,\n size: WindowSize | null,\n zIndex: number,\n): CSSProperties {\n if (maximized) {\n return { top: 0, left: 0, width: \"100%\", height: \"100%\", zIndex };\n }\n if (!position) {\n // Hidden until laid out; a requested size applies already so the first\n // clamp measures the window at the size it will show.\n return {\n visibility: \"hidden\",\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n }\n\n return {\n left: position.x,\n top: position.y,\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n}\n\nfunction getWindowStyle(\n maximized: boolean,\n position: WindowPosition | null,\n size: WindowSize | null,\n zIndex: number,\n background: string | undefined,\n): WindowStyle {\n return {\n ...getWindowFrameStyle(maximized, position, size, zIndex),\n \"--window-background\": background,\n };\n}\n\nfunction useWindowStatusMessage() {\n const [statusText, setStatusText] = useState(\"\");\n const statusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const showStatusMessage = useCallback((message: string) => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n setStatusText(message);\n statusTimeoutRef.current = setTimeout(() => {\n setStatusText(\"\");\n statusTimeoutRef.current = null;\n }, WINDOW_STATUS_MESSAGE_DURATION_MS);\n }, []);\n\n useEffect(() => {\n return () => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n };\n }, []);\n\n return { showStatusMessage, statusText };\n}\n\n// Refcounted so overlapping overlays (one closing as another opens) never leave\n// the row hidden, and never flash it back for a frame between the two.\nfunction useWindowToolbarSuppression() {\n const [suppressionCount, setSuppressionCount] = useState(0);\n const suppressToolbar = useCallback(() => {\n setSuppressionCount((count) => count + 1);\n return () => setSuppressionCount((count) => Math.max(0, count - 1));\n }, []);\n\n return { suppressToolbar, toolbarSuppressed: suppressionCount > 0 };\n}\n\ninterface WindowInnerProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n entry: WindowEntry;\n historyBack: boolean;\n // Whether this is the foremost visible window, the one that takes focus.\n isTop: boolean;\n}\n\nfunction WindowInner({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n return (\n <WindowMenuProvider>\n <WindowSidebarProvider>\n <WindowInnerContent\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack}\n isTop={isTop}\n />\n </WindowSidebarProvider>\n </WindowMenuProvider>\n );\n}\n\n// The bars above the body: title, menus, and the toolbar row a full-pane overlay\n// can stand down (see `useWindowToolbarSuppression`).\nfunction WindowChrome({\n actions,\n entry,\n historyBack,\n onGoBack,\n onPointerDown,\n titleId,\n toolbarSuppressed,\n}: {\n actions: ReturnType<typeof useWindowActions>;\n entry: WindowEntry;\n historyBack: boolean;\n onGoBack: () => void;\n onPointerDown: (event: ReactPointerEvent) => void;\n titleId: string;\n toolbarSuppressed: boolean;\n}) {\n return (\n <>\n <WindowTitleBar\n title={entry.title}\n titleId={titleId}\n onPointerDown={onPointerDown}\n onMinimize={actions.handleMinimize}\n onMaximize={actions.handleMaximize}\n onClose={actions.handleClose}\n onMoveForward={actions.handleMoveForward}\n onMoveBackward={actions.handleMoveBackward}\n />\n <WindowMenuBar menus={actions.menus} />\n {!toolbarSuppressed && (\n <WindowToolBar\n canGoBack={(entry.routeHistory?.length ?? 0) > 0}\n showHistoryBack={historyBack}\n onGoBack={onGoBack}\n />\n )}\n </>\n );\n}\n\n// Handlers on the window root: its Back caret, raising it on any press inside,\n// and keeping background context menus from opening under window-local ones.\nfunction useWindowRootHandlers(windowId: string) {\n // The toolbar renders above the route boundary, so the window's own Back stack\n // is threaded in from here rather than read from context.\n const { bringToFront, goBackRoute } = useWindowStateActions();\n const handleGoBack = useCallback(() => {\n goBackRoute(windowId);\n }, [windowId, goBackRoute]);\n const handleWindowPointerDown = useCallback(() => {\n bringToFront(windowId);\n }, [bringToFront, windowId]);\n const handleWindowContextMenu = useCallback((event: ReactMouseEvent) => {\n // Keep background pane context menus from opening underneath window-local menus.\n event.stopPropagation();\n }, []);\n const windowContextMenuTrapProps: Pick<\n HTMLAttributes<HTMLElement>,\n \"onContextMenu\"\n > = {\n onContextMenu: handleWindowContextMenu,\n };\n\n return { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps };\n}\n\nfunction WindowInnerContent({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n const { maximized, minimized, zIndex, component: Component } = entry;\n const windowRef = useRef<HTMLElement>(null);\n const titleId = useId();\n const [overlayHost, setOverlayHost] = useState<HTMLElement | null>(null);\n const [background, setBackground] = useState<string | undefined>();\n const fileMenuItems = useWindowFileMenuItems();\n const viewMenuItems = useWindowViewMenuItems();\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n const {\n handlePointerDown,\n handleResizePointerDown,\n position,\n size,\n ...stepped\n } = useWindowGeometry(entry, maximized, windowRef);\n const { showStatusMessage, statusText } = useWindowStatusMessage();\n const { geometryMenuItems, setContentSize } = useWindowGeometryMenu(\n entry,\n stepped,\n { overlayHost, windowRef },\n showStatusMessage,\n );\n const actions = useWindowActions(\n entry,\n fileMenuItems,\n viewMenuItems,\n geometryMenuItems,\n hasSidebar,\n );\n // A maximized window fills its surface without a laid-out position.\n useFocusWindowOnShow(windowRef, {\n isTop,\n shown: !minimized && (maximized || position !== null),\n });\n const { suppressToolbar, toolbarSuppressed } = useWindowToolbarSuppression();\n const { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps } =\n useWindowRootHandlers(entry.id);\n const style = getWindowStyle(maximized, position, size, zIndex, background);\n\n if (minimized) {\n return null;\n }\n\n // A section labelled by its title is a region landmark. Windows are\n // non-modal and freely arranged, so they are not dialogs; hosts keep that\n // role for the modals they open inside a window.\n return (\n <section\n ref={windowRef}\n aria-labelledby={titleId}\n className={maximized ? \"window window--maximized\" : \"window\"}\n tabIndex={-1}\n {...windowContextMenuTrapProps}\n onPointerDownCapture={handleWindowPointerDown}\n style={style}\n >\n <WindowChrome\n actions={actions}\n entry={entry}\n historyBack={historyBack}\n onGoBack={handleGoBack}\n onPointerDown={handlePointerDown}\n titleId={titleId}\n toolbarSuppressed={toolbarSuppressed}\n />\n <CurrentWindowProvider\n close={actions.handleClose}\n id={entry.id}\n overlayHost={overlayHost}\n setBackground={setBackground}\n setContentSize={setContentSize}\n showStatusMessage={showStatusMessage}\n suppressToolbar={suppressToolbar}\n >\n <WindowBodyWithSidebar\n overlayHostRef={setOverlayHost}\n showSidebar={actions.showSidebar}\n >\n {ContentBoundary ? (\n <ContentBoundary entry={entry}>\n {Component && <Component />}\n </ContentBoundary>\n ) : (\n Component && <Component />\n )}\n </WindowBodyWithSidebar>\n </CurrentWindowProvider>\n <WindowStatusBar text={statusText} visible={actions.showStatusBar} />\n {!maximized && (\n <WindowResizeHandles\n handleResizePointerDown={handleResizePointerDown}\n />\n )}\n </section>\n );\n}\n\nfunction WindowBodyWithSidebar({\n showSidebar,\n overlayHostRef,\n children,\n}: PropsWithChildren<{\n overlayHostRef: (element: HTMLDivElement | null) => void;\n showSidebar: boolean;\n}>) {\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n\n return (\n <WindowBody\n contentRef={overlayHostRef}\n showSidebar={showSidebar && hasSidebar}\n sidebar={sidebar}\n >\n {children}\n </WindowBody>\n );\n}\n"]}
1
+ {"version":3,"file":"Window.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/Window.tsx"],"names":[],"mappings":";AAAA,OAAO,EAOL,WAAW,EACX,SAAS,EACT,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AACrE,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EACL,gBAAgB,EAChB,gBAAgB,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,CACjB,KAAC,eAAe,IAAC,KAAK,EAAE,KAAK,YAC1B,SAAS,IAAI,KAAC,SAAS,KAAG,GACX,CACnB,CAAC,CAAC,CAAC,CACF,SAAS,IAAI,KAAC,SAAS,KAAG,CAC3B,GACqB,GACF,EACxB,KAAC,eAAe,IAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,aAAa,GAAI,EACpE,CAAC,SAAS,IAAI,CACb,KAAC,mBAAmB,IAClB,uBAAuB,EAAE,uBAAuB,GAChD,CACH,IACO,CACX,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,EAC7B,WAAW,EACX,cAAc,EACd,QAAQ,GAIR;IACA,MAAM,EAAE,OAAO,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACvC,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE7C,OAAO,CACL,KAAC,UAAU,IACT,UAAU,EAAE,cAAc,EAC1B,WAAW,EAAE,WAAW,IAAI,UAAU,EACtC,OAAO,EAAE,OAAO,YAEf,QAAQ,GACE,CACd,CAAC;AACJ,CAAC","sourcesContent":["import {\n type ComponentType,\n type CSSProperties,\n type HTMLAttributes,\n type PropsWithChildren,\n type MouseEvent as ReactMouseEvent,\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport \"./Window.css\";\nimport { CurrentWindowProvider } from \"./CurrentWindowContext\";\nimport { useWindowGeometryMenu } from \"./useWindowFit\";\nimport { useWindowGeometry } from \"./useWindowGeometry\";\nimport { useFocusWindowOnShow } from \"./useWindowKeyboardGeometry\";\nimport { WindowBody } from \"./WindowBody\";\nimport { WindowMenuBar, type WindowMenuItem } from \"./WindowMenuBar\";\nimport {\n useWindowFileMenuItems,\n useWindowViewMenuItems,\n WindowMenuProvider,\n} from \"./WindowMenuContext\";\nimport { WindowResizeHandles } from \"./WindowResizeHandle\";\nimport {\n hasWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./WindowSidebarContext\";\nimport {\n findTopWindow,\n useWindowActions as useWindowStateActions,\n useWindowStateData,\n type WindowEntry,\n type WindowPosition,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport { WindowStatusBar } from \"./WindowStatusBar\";\nimport { WindowTitleBar } from \"./WindowTitleBar\";\nimport { WindowToolBar } from \"./WindowToolBar\";\n\n// Wraps a window's content so the host can give it app-specific context (a\n// route, an error boundary) without the window layer knowing about apps.\nexport type WindowContentBoundary = ComponentType<\n PropsWithChildren<{ entry: WindowEntry }>\n>;\n\ninterface WindowProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n /**\n * Whether the toolbar offers Back through the window's own route history,\n * reserving its row from the start (see `WindowToolBar`). Defaults to whether\n * the window has an `appId`. Pass false for an app that never routes, so its\n * window has no toolbar row until the app first registers toolbar actions.\n */\n historyBack?: boolean | undefined;\n windowId: string;\n}\n\nconst WINDOW_STATUS_MESSAGE_DURATION_MS = 2500;\n\nexport function Window({\n ContentBoundary,\n historyBack,\n windowId,\n}: WindowProps) {\n const { windowMap, windows } = useWindowStateData();\n const entry = windowMap.get(windowId);\n const isTop =\n findTopWindow(windows, (candidate) => !candidate.minimized)?.id ===\n windowId;\n\n if (!entry) return null;\n\n return (\n <WindowInner\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack ?? entry.appId !== undefined}\n isTop={isTop}\n />\n );\n}\n\nfunction useWindowActions(\n entry: WindowEntry,\n fileMenuItems: WindowMenuItem[],\n viewMenuItems: WindowMenuItem[],\n geometryMenuItems: WindowMenuItem[],\n hasSidebar: boolean,\n) {\n const { close, minimize, moveBackward, moveForward, toggleMaximize } =\n useWindowStateActions();\n const [showStatusBar, setShowStatusBar] = useState(true);\n const [showSidebar, setShowSidebar] = useState(\n entry.initialShowSidebar ?? true,\n );\n const handleClose = useCallback(() => close(entry.id), [close, entry.id]);\n const handleMinimize = useCallback(\n () => minimize(entry.id),\n [entry.id, minimize],\n );\n const handleMoveForward = useCallback(\n () => moveForward(entry.id),\n [entry.id, moveForward],\n );\n const handleMoveBackward = useCallback(\n () => moveBackward(entry.id),\n [entry.id, moveBackward],\n );\n const handleMaximize = useCallback(\n () => toggleMaximize(entry.id),\n [entry.id, toggleMaximize],\n );\n const toggleStatusBar = useCallback(\n () => setShowStatusBar((previous) => !previous),\n [],\n );\n const toggleSidebar = useCallback(\n () => setShowSidebar((previous) => !previous),\n [],\n );\n const menus = useMemo(\n () => [\n {\n label: \"File\",\n items: [\n ...fileMenuItems,\n { id: \"close\", label: \"Close\", onClick: handleClose },\n ],\n },\n {\n label: \"View\",\n items: [\n ...viewMenuItems,\n ...geometryMenuItems,\n {\n id: \"toggle-status-bar\",\n label: `${showStatusBar ? \"Hide\" : \"Show\"} Status Bar`,\n onClick: toggleStatusBar,\n },\n ...(hasSidebar\n ? [\n {\n id: \"toggle-sidebar\",\n label: `${showSidebar ? \"Hide\" : \"Show\"} Sidebar`,\n onClick: toggleSidebar,\n },\n ]\n : []),\n ],\n },\n ],\n [\n geometryMenuItems,\n hasSidebar,\n handleClose,\n fileMenuItems,\n showSidebar,\n showStatusBar,\n toggleSidebar,\n toggleStatusBar,\n viewMenuItems,\n ],\n );\n\n return {\n handleClose,\n handleMaximize,\n handleMinimize,\n handleMoveBackward,\n handleMoveForward,\n menus,\n showSidebar,\n showStatusBar,\n };\n}\n\n// The window paints with `--window-background`, which a background its content\n// sets (see `useWindowBackground`) overrides inline.\ninterface WindowStyle extends CSSProperties {\n \"--window-background\"?: string | undefined;\n}\n\nfunction getWindowFrameStyle(\n maximized: boolean,\n position: WindowPosition | null,\n size: WindowSize | null,\n zIndex: number,\n): CSSProperties {\n if (maximized) {\n return { top: 0, left: 0, width: \"100%\", height: \"100%\", zIndex };\n }\n if (!position) {\n // Hidden until laid out; a requested size applies already so the first\n // clamp measures the window at the size it will show.\n return {\n visibility: \"hidden\",\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n }\n\n return {\n left: position.x,\n top: position.y,\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n}\n\nfunction getWindowStyle(\n maximized: boolean,\n position: WindowPosition | null,\n size: WindowSize | null,\n zIndex: number,\n background: string | undefined,\n): WindowStyle {\n return {\n ...getWindowFrameStyle(maximized, position, size, zIndex),\n \"--window-background\": background,\n };\n}\n\nfunction useWindowStatusMessage() {\n const [statusText, setStatusText] = useState(\"\");\n const statusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const showStatusMessage = useCallback((message: string) => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n setStatusText(message);\n statusTimeoutRef.current = setTimeout(() => {\n setStatusText(\"\");\n statusTimeoutRef.current = null;\n }, WINDOW_STATUS_MESSAGE_DURATION_MS);\n }, []);\n\n useEffect(() => {\n return () => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n };\n }, []);\n\n return { showStatusMessage, statusText };\n}\n\n// Refcounted so overlapping overlays (one closing as another opens) never leave\n// the row hidden, and never flash it back for a frame between the two.\nfunction useWindowToolbarSuppression() {\n const [suppressionCount, setSuppressionCount] = useState(0);\n const suppressToolbar = useCallback(() => {\n setSuppressionCount((count) => count + 1);\n return () => setSuppressionCount((count) => Math.max(0, count - 1));\n }, []);\n\n return { suppressToolbar, toolbarSuppressed: suppressionCount > 0 };\n}\n\ninterface WindowInnerProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n entry: WindowEntry;\n historyBack: boolean;\n // Whether this is the foremost visible window, the one that takes focus.\n isTop: boolean;\n}\n\nfunction WindowInner({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n return (\n <WindowMenuProvider>\n <WindowSidebarProvider>\n <WindowInnerContent\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack}\n isTop={isTop}\n />\n </WindowSidebarProvider>\n </WindowMenuProvider>\n );\n}\n\n// The bars above the body: title, menus, and the toolbar row a full-pane overlay\n// can stand down (see `useWindowToolbarSuppression`).\nfunction WindowChrome({\n actions,\n entry,\n historyBack,\n onGoBack,\n onPointerDown,\n titleId,\n toolbarSuppressed,\n}: {\n actions: ReturnType<typeof useWindowActions>;\n entry: WindowEntry;\n historyBack: boolean;\n onGoBack: () => void;\n onPointerDown: (event: ReactPointerEvent) => void;\n titleId: string;\n toolbarSuppressed: boolean;\n}) {\n return (\n <>\n <WindowTitleBar\n title={entry.title}\n titleId={titleId}\n onPointerDown={onPointerDown}\n onMinimize={actions.handleMinimize}\n onMaximize={actions.handleMaximize}\n onClose={actions.handleClose}\n onMoveForward={actions.handleMoveForward}\n onMoveBackward={actions.handleMoveBackward}\n />\n <WindowMenuBar menus={actions.menus} />\n {!toolbarSuppressed && (\n <WindowToolBar\n canGoBack={(entry.routeHistory?.length ?? 0) > 0}\n showHistoryBack={historyBack}\n onGoBack={onGoBack}\n />\n )}\n </>\n );\n}\n\n// Handlers on the window root: its Back caret, raising it on any press inside,\n// and keeping background context menus from opening under window-local ones.\nfunction useWindowRootHandlers(windowId: string) {\n // The toolbar renders above the route boundary, so the window's own Back stack\n // is threaded in from here rather than read from context.\n const { bringToFront, goBackRoute } = useWindowStateActions();\n const handleGoBack = useCallback(() => {\n goBackRoute(windowId);\n }, [windowId, goBackRoute]);\n const handleWindowPointerDown = useCallback(() => {\n bringToFront(windowId);\n }, [bringToFront, windowId]);\n const handleWindowContextMenu = useCallback((event: ReactMouseEvent) => {\n // Keep background pane context menus from opening underneath window-local menus.\n event.stopPropagation();\n }, []);\n const windowContextMenuTrapProps: Pick<\n HTMLAttributes<HTMLElement>,\n \"onContextMenu\"\n > = {\n onContextMenu: handleWindowContextMenu,\n };\n\n return { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps };\n}\n\nfunction WindowInnerContent({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n const { maximized, minimized, zIndex, component: Component } = entry;\n const windowRef = useRef<HTMLElement>(null);\n const titleId = useId();\n const [overlayHost, setOverlayHost] = useState<HTMLElement | null>(null);\n const [background, setBackground] = useState<string | undefined>();\n const fileMenuItems = useWindowFileMenuItems();\n const viewMenuItems = useWindowViewMenuItems();\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n const {\n handlePointerDown,\n handleResizePointerDown,\n position,\n size,\n ...stepped\n } = useWindowGeometry(entry, maximized, windowRef);\n const { showStatusMessage, statusText } = useWindowStatusMessage();\n const { contentFit, geometryMenuItems } = useWindowGeometryMenu(\n entry,\n stepped,\n { overlayHost, windowRef },\n showStatusMessage,\n );\n const actions = useWindowActions(\n entry,\n fileMenuItems,\n viewMenuItems,\n geometryMenuItems,\n hasSidebar,\n );\n // A maximized window fills its surface without a laid-out position.\n useFocusWindowOnShow(windowRef, {\n isTop,\n shown: !minimized && (maximized || position !== null),\n });\n const { suppressToolbar, toolbarSuppressed } = useWindowToolbarSuppression();\n const { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps } =\n useWindowRootHandlers(entry.id);\n const style = getWindowStyle(maximized, position, size, zIndex, background);\n\n if (minimized) {\n return null;\n }\n\n // A section labelled by its title is a region landmark. Windows are\n // non-modal and freely arranged, so they are not dialogs; hosts keep that\n // role for the modals they open inside a window.\n return (\n <section\n ref={windowRef}\n aria-labelledby={titleId}\n className={maximized ? \"window window--maximized\" : \"window\"}\n tabIndex={-1}\n {...windowContextMenuTrapProps}\n onPointerDownCapture={handleWindowPointerDown}\n style={style}\n >\n <WindowChrome\n actions={actions}\n entry={entry}\n historyBack={historyBack}\n onGoBack={handleGoBack}\n onPointerDown={handlePointerDown}\n titleId={titleId}\n toolbarSuppressed={toolbarSuppressed}\n />\n <CurrentWindowProvider\n close={actions.handleClose}\n id={entry.id}\n overlayHost={overlayHost}\n setBackground={setBackground}\n {...contentFit}\n showStatusMessage={showStatusMessage}\n suppressToolbar={suppressToolbar}\n >\n <WindowBodyWithSidebar\n overlayHostRef={setOverlayHost}\n showSidebar={actions.showSidebar}\n >\n {ContentBoundary ? (\n <ContentBoundary entry={entry}>\n {Component && <Component />}\n </ContentBoundary>\n ) : (\n Component && <Component />\n )}\n </WindowBodyWithSidebar>\n </CurrentWindowProvider>\n <WindowStatusBar text={statusText} visible={actions.showStatusBar} />\n {!maximized && (\n <WindowResizeHandles\n handleResizePointerDown={handleResizePointerDown}\n />\n )}\n </section>\n );\n}\n\nfunction WindowBodyWithSidebar({\n showSidebar,\n overlayHostRef,\n children,\n}: PropsWithChildren<{\n overlayHostRef: (element: HTMLDivElement | null) => void;\n showSidebar: boolean;\n}>) {\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n\n return (\n <WindowBody\n contentRef={overlayHostRef}\n showSidebar={showSidebar && hasSidebar}\n sidebar={sidebar}\n >\n {children}\n </WindowBody>\n );\n}\n"]}
@@ -23,6 +23,7 @@ export interface WindowEntry {
23
23
  initialY: number;
24
24
  position?: WindowPosition | undefined;
25
25
  size?: WindowSize | undefined;
26
+ fitToContent?: boolean | undefined;
26
27
  maximized: boolean;
27
28
  minimized: boolean;
28
29
  zIndex: number;
@@ -30,6 +31,7 @@ export interface WindowEntry {
30
31
  }
31
32
  export interface WindowCreateOptions {
32
33
  appId?: string;
34
+ fitToContent?: boolean | undefined;
33
35
  initialShowSidebar?: boolean | undefined;
34
36
  pathSegments?: ReadonlyArray<string> | undefined;
35
37
  position?: WindowPosition | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowStateProvider/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentType } from \"react\";\n\nexport type WindowMoveDirection = \"forward\" | \"backward\";\n\n// Window geometry is relative to the desktop surface a window is rendered in\n// (the window's offset parent), not to the viewport.\nexport interface WindowPosition {\n x: number;\n y: number;\n}\n\nexport interface WindowSize {\n width: number;\n height: number;\n}\n\nexport interface WindowGeometry {\n position: WindowPosition;\n size?: WindowSize | undefined;\n}\n\nexport interface WindowEntry {\n // An opaque key naming the app that owns this window. The window layer only\n // stores and compares it; the host interprets it (see Window's\n // ContentBoundary).\n appId?: string;\n id: string;\n initialShowSidebar?: boolean | undefined;\n pathSegments?: ReadonlyArray<string> | undefined;\n // The window's own Back stack: routes previously visited in this window, the\n // most recent last. A window is not backed by browser history (only the\n // routed shell is), so this is what gives the windowed toolbar a working Back\n // caret. Forward is deliberately not modelled — the toolbar offers Back only.\n routeHistory?: ReadonlyArray<ReadonlyArray<string>> | undefined;\n title: string;\n // Where the window first appears, in viewport coordinates (for example the\n // point a launcher was clicked). Ignored once position is known.\n initialX: number;\n initialY: number;\n // The window's committed geometry. Set when the window is first laid out and\n // whenever a drag or resize ends, so a host can save and restore a layout.\n // Without size the window takes its stylesheet's default size.\n position?: WindowPosition | undefined;\n size?: WindowSize | undefined;\n // maximized and minimized live here rather than inside Window so the taskbar\n // can drive both without reaching into a window's local state.\n maximized: boolean;\n minimized: boolean;\n zIndex: number;\n component?: ComponentType;\n}\n\nexport interface WindowCreateOptions {\n appId?: string;\n initialShowSidebar?: boolean | undefined;\n pathSegments?: ReadonlyArray<string> | undefined;\n // Surface-relative geometry to open with, such as a restored layout. A\n // position takes precedence over create's viewport x/y.\n position?: WindowPosition | undefined;\n size?: WindowSize | undefined;\n}\n\nexport interface WindowStateData {\n // windows is the raw useState array — stable and cheap to iterate for\n // rendering lists. windowMap is derived via useMemo for O(1) lookups by ID.\n // Both are already memoized so neither adds redundant computation.\n windows: WindowEntry[];\n windowMap: Map<string, WindowEntry>;\n}\n\nexport interface WindowStateActions {\n create: (\n title: string,\n x: number,\n y: number,\n component?: ComponentType,\n options?: WindowCreateOptions,\n ) => string;\n close: (id: string) => void;\n maximize: (id: string) => void;\n minimize: (id: string) => void;\n restore: (id: string) => void;\n toggleMaximize: (id: string) => void;\n updateRoute: (\n id: string,\n pathSegments: ReadonlyArray<string>,\n options?: { replace?: boolean | undefined },\n ) => void;\n goBackRoute: (id: string) => void;\n updateTitle: (id: string, title: string) => void;\n moveForward: (id: string) => void;\n moveBackward: (id: string) => void;\n bringToFront: (id: string) => void;\n setGeometry: (id: string, geometry: WindowGeometry) => void;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowStateProvider/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentType } from \"react\";\n\nexport type WindowMoveDirection = \"forward\" | \"backward\";\n\n// Window geometry is relative to the desktop surface a window is rendered in\n// (the window's offset parent), not to the viewport.\nexport interface WindowPosition {\n x: number;\n y: number;\n}\n\nexport interface WindowSize {\n width: number;\n height: number;\n}\n\nexport interface WindowGeometry {\n position: WindowPosition;\n size?: WindowSize | undefined;\n}\n\nexport interface WindowEntry {\n // An opaque key naming the app that owns this window. The window layer only\n // stores and compares it; the host interprets it (see Window's\n // ContentBoundary).\n appId?: string;\n id: string;\n initialShowSidebar?: boolean | undefined;\n pathSegments?: ReadonlyArray<string> | undefined;\n // The window's own Back stack: routes previously visited in this window, the\n // most recent last. A window is not backed by browser history (only the\n // routed shell is), so this is what gives the windowed toolbar a working Back\n // caret. Forward is deliberately not modelled — the toolbar offers Back only.\n routeHistory?: ReadonlyArray<ReadonlyArray<string>> | undefined;\n title: string;\n // Where the window first appears, in viewport coordinates (for example the\n // point a launcher was clicked). Ignored once position is known.\n initialX: number;\n initialY: number;\n // The window's committed geometry. Set when the window is first laid out and\n // whenever a drag or resize ends, so a host can save and restore a layout.\n // Without size the window takes its stylesheet's default size.\n position?: WindowPosition | undefined;\n size?: WindowSize | undefined;\n // Whether the window fits itself to its content once the content has loaded\n // (see WindowCreateOptions).\n fitToContent?: boolean | undefined;\n // maximized and minimized live here rather than inside Window so the taskbar\n // can drive both without reaching into a window's local state.\n maximized: boolean;\n minimized: boolean;\n zIndex: number;\n component?: ComponentType;\n}\n\nexport interface WindowCreateOptions {\n appId?: string;\n // Opens the window fitted to its content, as View > Fit to Content would fit\n // it: once the content has marked itself loaded and reported its natural\n // size. A window maximized by then stays maximized.\n fitToContent?: boolean | undefined;\n initialShowSidebar?: boolean | undefined;\n pathSegments?: ReadonlyArray<string> | undefined;\n // Surface-relative geometry to open with, such as a restored layout. A\n // position takes precedence over create's viewport x/y.\n position?: WindowPosition | undefined;\n size?: WindowSize | undefined;\n}\n\nexport interface WindowStateData {\n // windows is the raw useState array — stable and cheap to iterate for\n // rendering lists. windowMap is derived via useMemo for O(1) lookups by ID.\n // Both are already memoized so neither adds redundant computation.\n windows: WindowEntry[];\n windowMap: Map<string, WindowEntry>;\n}\n\nexport interface WindowStateActions {\n create: (\n title: string,\n x: number,\n y: number,\n component?: ComponentType,\n options?: WindowCreateOptions,\n ) => string;\n close: (id: string) => void;\n maximize: (id: string) => void;\n minimize: (id: string) => void;\n restore: (id: string) => void;\n toggleMaximize: (id: string) => void;\n updateRoute: (\n id: string,\n pathSegments: ReadonlyArray<string>,\n options?: { replace?: boolean | undefined },\n ) => void;\n goBackRoute: (id: string) => void;\n updateTitle: (id: string, title: string) => void;\n moveForward: (id: string) => void;\n moveBackward: (id: string) => void;\n bringToFront: (id: string) => void;\n setGeometry: (id: string, geometry: WindowGeometry) => void;\n}\n"]}
@@ -11,6 +11,7 @@ export function createWindowEntry(id, title, x, y, zIndex, component, options =
11
11
  initialY: y,
12
12
  ...(options.position ? { position: { ...options.position } } : {}),
13
13
  ...(options.size ? { size: { ...options.size } } : {}),
14
+ ...(options.fitToContent ? { fitToContent: true } : {}),
14
15
  maximized: false,
15
16
  minimized: false,
16
17
  zIndex,
@@ -1 +1 @@
1
- {"version":3,"file":"createWindowEntry.js","sourceRoot":"","sources":["../../../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowStateProvider/util/createWindowEntry.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,iBAAiB,CAC/B,EAAU,EACV,KAAa,EACb,CAAS,EACT,CAAS,EACT,MAAc,EACd,SAAyB,EACzB,UAA+B,EAAE;IAEjC,OAAO;QACL,EAAE;QACF,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClD,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;QAC9C,GAAG,CAAC,OAAO,CAAC,YAAY;YACtB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,EAAE;YAC7C,CAAC,CAAC,EAAE,CAAC;QACP,KAAK;QACL,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;QACX,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,SAAS,EAAE,KAAK;QAChB,SAAS,EAAE,KAAK;QAChB,MAAM;QACN,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import type { ComponentType } from \"react\";\nimport type { WindowCreateOptions, WindowEntry } from \"../types\";\n\nexport function createWindowEntry(\n id: string,\n title: string,\n x: number,\n y: number,\n zIndex: number,\n component?: ComponentType,\n options: WindowCreateOptions = {},\n): WindowEntry {\n return {\n id,\n ...(options.appId ? { appId: options.appId } : {}),\n initialShowSidebar: options.initialShowSidebar,\n ...(options.pathSegments\n ? { pathSegments: [...options.pathSegments] }\n : {}),\n title,\n initialX: x,\n initialY: y,\n ...(options.position ? { position: { ...options.position } } : {}),\n ...(options.size ? { size: { ...options.size } } : {}),\n maximized: false,\n minimized: false,\n zIndex,\n ...(component ? { component } : {}),\n };\n}\n"]}
1
+ {"version":3,"file":"createWindowEntry.js","sourceRoot":"","sources":["../../../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowStateProvider/util/createWindowEntry.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,iBAAiB,CAC/B,EAAU,EACV,KAAa,EACb,CAAS,EACT,CAAS,EACT,MAAc,EACd,SAAyB,EACzB,UAA+B,EAAE;IAEjC,OAAO;QACL,EAAE;QACF,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClD,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;QAC9C,GAAG,CAAC,OAAO,CAAC,YAAY;YACtB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,EAAE;YAC7C,CAAC,CAAC,EAAE,CAAC;QACP,KAAK;QACL,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;QACX,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,SAAS,EAAE,KAAK;QAChB,SAAS,EAAE,KAAK;QAChB,MAAM;QACN,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import type { ComponentType } from \"react\";\nimport type { WindowCreateOptions, WindowEntry } from \"../types\";\n\nexport function createWindowEntry(\n id: string,\n title: string,\n x: number,\n y: number,\n zIndex: number,\n component?: ComponentType,\n options: WindowCreateOptions = {},\n): WindowEntry {\n return {\n id,\n ...(options.appId ? { appId: options.appId } : {}),\n initialShowSidebar: options.initialShowSidebar,\n ...(options.pathSegments\n ? { pathSegments: [...options.pathSegments] }\n : {}),\n title,\n initialX: x,\n initialY: y,\n ...(options.position ? { position: { ...options.position } } : {}),\n ...(options.size ? { size: { ...options.size } } : {}),\n ...(options.fitToContent ? { fitToContent: true } : {}),\n maximized: false,\n minimized: false,\n zIndex,\n ...(component ? { component } : {}),\n };\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { ArrowDownIcon } from "@phosphor-icons/react/dist/csr/ArrowDown";
3
- import { ArrowUpIcon } from "@phosphor-icons/react/dist/csr/ArrowUp";
4
2
  import { useCallback } from "react";
3
+ import { useWindowingIcons } from "../icons/WindowingIcons.js";
5
4
  import { Menu } from "../menu/Menu.js";
6
5
  import { MenuItem } from "../menu/MenuItem.js";
7
6
  import { useContextMenuPositionState } from "../menu/useContextMenuState.js";
@@ -11,6 +10,7 @@ import { WindowMaximizeButton } from "./WindowMaximizeButton.js";
11
10
  import { WindowMinimizeButton } from "./WindowMinimizeButton.js";
12
11
  export function WindowTitleBar({ title, titleId, onPointerDown, onMinimize, onMaximize, onClose, onMoveForward, onMoveBackward, }) {
13
12
  const { closeContextMenu, contextMenu, openContextMenuAt } = useContextMenuPositionState();
13
+ const icons = useWindowingIcons();
14
14
  const handlePointerDown = useCallback((e) => {
15
15
  const target = e.target;
16
16
  if (e.button !== 0)
@@ -25,10 +25,10 @@ export function WindowTitleBar({ title, titleId, onPointerDown, onMinimize, onMa
25
25
  event.preventDefault();
26
26
  event.stopPropagation();
27
27
  openContextMenuAt({ x: event.clientX, y: event.clientY });
28
- }, children: [_jsx("span", { className: "window-titlebar-title", id: titleId, title: title, children: title }), _jsxs("div", { className: "window-titlebar-buttons", children: [_jsx(WindowMinimizeButton, { onClick: onMinimize }), _jsx(WindowMaximizeButton, { onClick: onMaximize }), _jsx(WindowCloseButton, { label: "Close window", onClick: onClose })] }), contextMenu && (_jsxs(Menu, { position: contextMenu, onClose: closeContextMenu, direction: "down", children: [_jsx(MenuItem, { icon: ArrowUpIcon, label: "Move Forward", onClick: () => {
28
+ }, children: [_jsx("span", { className: "window-titlebar-title", id: titleId, title: title, children: title }), _jsxs("div", { className: "window-titlebar-buttons", children: [_jsx(WindowMinimizeButton, { onClick: onMinimize }), _jsx(WindowMaximizeButton, { onClick: onMaximize }), _jsx(WindowCloseButton, { label: "Close window", onClick: onClose })] }), contextMenu && (_jsxs(Menu, { position: contextMenu, onClose: closeContextMenu, direction: "down", children: [_jsx(MenuItem, { icon: icons.moveForward, label: "Move Forward", onClick: () => {
29
29
  onMoveForward();
30
30
  closeContextMenu();
31
- } }), _jsx(MenuItem, { icon: ArrowDownIcon, label: "Move Backward", onClick: () => {
31
+ } }), _jsx(MenuItem, { icon: icons.moveBackward, label: "Move Backward", onClick: () => {
32
32
  onMoveBackward();
33
33
  closeContextMenu();
34
34
  } })] }))] }));
@@ -1 +1 @@
1
- {"version":3,"file":"WindowTitleBar.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowTitleBar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAO,EAAkB,WAAW,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,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,YAC9D,KAAK,GACD,EACP,eAAK,SAAS,EAAC,yBAAyB,aACtC,KAAC,oBAAoB,IAAC,OAAO,EAAE,UAAU,GAAI,EAC7C,KAAC,oBAAoB,IAAC,OAAO,EAAE,UAAU,GAAI,EAC7C,KAAC,iBAAiB,IAAC,KAAK,EAAC,cAAc,EAAC,OAAO,EAAE,OAAO,GAAI,IACxD,EACL,WAAW,IAAI,CACd,MAAC,IAAI,IACH,QAAQ,EAAE,WAAW,EACrB,OAAO,EAAE,gBAAgB,EACzB,SAAS,EAAC,MAAM,aAEhB,KAAC,QAAQ,IACP,IAAI,EAAE,WAAW,EACjB,KAAK,EAAC,cAAc,EACpB,OAAO,EAAE,GAAG,EAAE;4BACZ,aAAa,EAAE,CAAC;4BAChB,gBAAgB,EAAE,CAAC;wBACrB,CAAC,GACD,EACF,KAAC,QAAQ,IACP,IAAI,EAAE,aAAa,EACnB,KAAK,EAAC,eAAe,EACrB,OAAO,EAAE,GAAG,EAAE;4BACZ,cAAc,EAAE,CAAC;4BACjB,gBAAgB,EAAE,CAAC;wBACrB,CAAC,GACD,IACG,CACR,IACG,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { ArrowDownIcon } from \"@phosphor-icons/react/dist/csr/ArrowDown\";\nimport { ArrowUpIcon } from \"@phosphor-icons/react/dist/csr/ArrowUp\";\nimport { type ReactNode, useCallback } from \"react\";\nimport { Menu } from \"../menu/Menu\";\nimport { MenuItem } from \"../menu/MenuItem\";\nimport { useContextMenuPositionState } from \"../menu/useContextMenuState\";\nimport \"./WindowTitleBar.css\";\nimport { WindowCloseButton } from \"./WindowCloseButton\";\nimport { WindowMaximizeButton } from \"./WindowMaximizeButton\";\nimport { WindowMinimizeButton } from \"./WindowMinimizeButton\";\n\nexport interface WindowTitleBarAction {\n disabled?: boolean;\n icon: ReactNode;\n id: string;\n label: string;\n onClick: () => void;\n pressed?: boolean;\n}\n\nexport function WindowTitleBar({\n title,\n titleId,\n onPointerDown,\n onMinimize,\n onMaximize,\n onClose,\n onMoveForward,\n onMoveBackward,\n}: {\n title: string;\n titleId?: string | undefined;\n onPointerDown: (e: React.PointerEvent) => void;\n onMinimize: () => void;\n onMaximize: () => void;\n onClose: () => void;\n onMoveForward: () => void;\n onMoveBackward: () => void;\n}) {\n const { closeContextMenu, contextMenu, openContextMenuAt } =\n useContextMenuPositionState();\n\n const handlePointerDown = useCallback(\n (e: React.PointerEvent<HTMLDivElement>) => {\n const target = e.target;\n if (e.button !== 0) return;\n // Element, not HTMLElement: an icon inside a button (including the\n // portaled context menu, whose events bubble through React) is SVG.\n if (target instanceof Element && target.closest(\"button\")) return;\n onPointerDown(e);\n },\n [onPointerDown],\n );\n\n return (\n <div\n role=\"toolbar\"\n aria-label=\"Window controls\"\n className=\"window-titlebar\"\n onPointerDown={handlePointerDown}\n onContextMenu={(event) => {\n event.preventDefault();\n event.stopPropagation();\n openContextMenuAt({ x: event.clientX, y: event.clientY });\n }}\n >\n <span className=\"window-titlebar-title\" id={titleId} title={title}>\n {title}\n </span>\n <div className=\"window-titlebar-buttons\">\n <WindowMinimizeButton onClick={onMinimize} />\n <WindowMaximizeButton onClick={onMaximize} />\n <WindowCloseButton label=\"Close window\" onClick={onClose} />\n </div>\n {contextMenu && (\n <Menu\n position={contextMenu}\n onClose={closeContextMenu}\n direction=\"down\"\n >\n <MenuItem\n icon={ArrowUpIcon}\n label=\"Move Forward\"\n onClick={() => {\n onMoveForward();\n closeContextMenu();\n }}\n />\n <MenuItem\n icon={ArrowDownIcon}\n label=\"Move Backward\"\n onClick={() => {\n onMoveBackward();\n closeContextMenu();\n }}\n />\n </Menu>\n )}\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"WindowTitleBar.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowTitleBar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB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,KAAK,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5D,CAAC,aAED,eAAM,SAAS,EAAC,uBAAuB,EAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,YAC9D,KAAK,GACD,EACP,eAAK,SAAS,EAAC,yBAAyB,aACtC,KAAC,oBAAoB,IAAC,OAAO,EAAE,UAAU,GAAI,EAC7C,KAAC,oBAAoB,IAAC,OAAO,EAAE,UAAU,GAAI,EAC7C,KAAC,iBAAiB,IAAC,KAAK,EAAC,cAAc,EAAC,OAAO,EAAE,OAAO,GAAI,IACxD,EACL,WAAW,IAAI,CACd,MAAC,IAAI,IACH,QAAQ,EAAE,WAAW,EACrB,OAAO,EAAE,gBAAgB,EACzB,SAAS,EAAC,MAAM,aAEhB,KAAC,QAAQ,IACP,IAAI,EAAE,KAAK,CAAC,WAAW,EACvB,KAAK,EAAC,cAAc,EACpB,OAAO,EAAE,GAAG,EAAE;4BACZ,aAAa,EAAE,CAAC;4BAChB,gBAAgB,EAAE,CAAC;wBACrB,CAAC,GACD,EACF,KAAC,QAAQ,IACP,IAAI,EAAE,KAAK,CAAC,YAAY,EACxB,KAAK,EAAC,eAAe,EACrB,OAAO,EAAE,GAAG,EAAE;4BACZ,cAAc,EAAE,CAAC;4BACjB,gBAAgB,EAAE,CAAC;wBACrB,CAAC,GACD,IACG,CACR,IACG,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { type ReactNode, useCallback } from \"react\";\nimport { useWindowingIcons } from \"../icons/WindowingIcons\";\nimport { Menu } from \"../menu/Menu\";\nimport { MenuItem } from \"../menu/MenuItem\";\nimport { useContextMenuPositionState } from \"../menu/useContextMenuState\";\nimport \"./WindowTitleBar.css\";\nimport { WindowCloseButton } from \"./WindowCloseButton\";\nimport { WindowMaximizeButton } from \"./WindowMaximizeButton\";\nimport { WindowMinimizeButton } from \"./WindowMinimizeButton\";\n\nexport interface WindowTitleBarAction {\n disabled?: boolean;\n icon: ReactNode;\n id: string;\n label: string;\n onClick: () => void;\n pressed?: boolean;\n}\n\nexport function WindowTitleBar({\n title,\n titleId,\n onPointerDown,\n onMinimize,\n onMaximize,\n onClose,\n onMoveForward,\n onMoveBackward,\n}: {\n title: string;\n titleId?: string | undefined;\n onPointerDown: (e: React.PointerEvent) => void;\n onMinimize: () => void;\n onMaximize: () => void;\n onClose: () => void;\n onMoveForward: () => void;\n onMoveBackward: () => void;\n}) {\n const { closeContextMenu, contextMenu, openContextMenuAt } =\n useContextMenuPositionState();\n const icons = useWindowingIcons();\n\n const handlePointerDown = useCallback(\n (e: React.PointerEvent<HTMLDivElement>) => {\n const target = e.target;\n if (e.button !== 0) return;\n // Element, not HTMLElement: an icon inside a button (including the\n // portaled context menu, whose events bubble through React) is SVG.\n if (target instanceof Element && target.closest(\"button\")) return;\n onPointerDown(e);\n },\n [onPointerDown],\n );\n\n return (\n <div\n role=\"toolbar\"\n aria-label=\"Window controls\"\n className=\"window-titlebar\"\n onPointerDown={handlePointerDown}\n onContextMenu={(event) => {\n event.preventDefault();\n event.stopPropagation();\n openContextMenuAt({ x: event.clientX, y: event.clientY });\n }}\n >\n <span className=\"window-titlebar-title\" id={titleId} title={title}>\n {title}\n </span>\n <div className=\"window-titlebar-buttons\">\n <WindowMinimizeButton onClick={onMinimize} />\n <WindowMaximizeButton onClick={onMaximize} />\n <WindowCloseButton label=\"Close window\" onClick={onClose} />\n </div>\n {contextMenu && (\n <Menu\n position={contextMenu}\n onClose={closeContextMenu}\n direction=\"down\"\n >\n <MenuItem\n icon={icons.moveForward}\n label=\"Move Forward\"\n onClick={() => {\n onMoveForward();\n closeContextMenu();\n }}\n />\n <MenuItem\n icon={icons.moveBackward}\n label=\"Move Backward\"\n onClick={() => {\n onMoveBackward();\n closeContextMenu();\n }}\n />\n </Menu>\n )}\n </div>\n );\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CaretLeftIcon } from "@phosphor-icons/react/dist/csr/CaretLeft";
3
2
  import { useState } from "react";
3
+ import { useWindowingIcons } from "../icons/WindowingIcons.js";
4
4
  import "./WindowToolBar.css";
5
5
  import { WindowTitleBarActionButtons } from "./WindowChromeActions.js";
6
6
  import { useWindowBackActionValue, useWindowTitleBarActions, useWindowToolbarReservationReleased, useWindowToolbarReserved, } from "./WindowMenuContext.js";
@@ -38,6 +38,7 @@ import { useWindowBackActionValue, useWindowTitleBarActions, useWindowToolbarRes
38
38
  * chrome does).
39
39
  */
40
40
  export function WindowToolBar({ canGoBack = false, onGoBack, showHistoryBack = false, } = {}) {
41
+ const { back: BackIcon } = useWindowingIcons();
41
42
  const backAction = useWindowBackActionValue();
42
43
  const actions = useWindowTitleBarActions();
43
44
  const reserved = useWindowToolbarReserved();
@@ -63,6 +64,6 @@ export function WindowToolBar({ canGoBack = false, onGoBack, showHistoryBack = f
63
64
  return null;
64
65
  }
65
66
  const backLabel = backAction?.label ?? "Back";
66
- return (_jsxs("div", { "aria-label": "Toolbar", className: "window-toolbar", role: "toolbar", children: [_jsx("div", { className: "window-toolbar-primary", children: showBack && (_jsxs("button", { "aria-label": backLabel, className: "window-toolbar-button", disabled: backAction?.disabled ?? false, title: backLabel, type: "button", onClick: backAction?.onClick ?? onGoBack, children: [_jsx(CaretLeftIcon, { "aria-hidden": true, size: 18 }), _jsx("span", { className: "window-toolbar-back-label", children: backLabel })] })) }), _jsx("div", { className: "window-toolbar-spacer" }), actions.length > 0 && (_jsx("div", { className: "window-toolbar-actions", children: _jsx(WindowTitleBarActionButtons, { actions: actions, className: "window-toolbar-button" }) }))] }));
67
+ return (_jsxs("div", { "aria-label": "Toolbar", className: "window-toolbar", role: "toolbar", children: [_jsx("div", { className: "window-toolbar-primary", children: showBack && (_jsxs("button", { "aria-label": backLabel, className: "window-toolbar-button", disabled: backAction?.disabled ?? false, title: backLabel, type: "button", onClick: backAction?.onClick ?? onGoBack, children: [_jsx(BackIcon, { "aria-hidden": true, size: 18 }), _jsx("span", { className: "window-toolbar-back-label", children: backLabel })] })) }), _jsx("div", { className: "window-toolbar-spacer" }), actions.length > 0 && (_jsx("div", { className: "window-toolbar-actions", children: _jsx(WindowTitleBarActionButtons, { actions: actions, className: "window-toolbar-button" }) }))] }));
67
68
  }
68
69
  //# sourceMappingURL=WindowToolBar.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"WindowToolBar.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowToolBar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,mCAAmC,EACnC,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B,SAAS,GAAG,KAAK,EACjB,QAAQ,EACR,eAAe,GAAG,KAAK,MAKrB,EAAE;IACJ,MAAM,UAAU,GAAG,wBAAwB,EAAE,CAAC;IAC9C,MAAM,OAAO,GAAG,wBAAwB,EAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG,wBAAwB,EAAE,CAAC;IAC5C,MAAM,mBAAmB,GAAG,mCAAmC,EAAE,CAAC;IAClE,MAAM,QAAQ,GAAG,UAAU,KAAK,IAAI,IAAI,CAAC,eAAe,IAAI,SAAS,CAAC,CAAC;IACvE,MAAM,SAAS,GACb,UAAU,KAAK,IAAI,IAAI,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/D,+EAA+E;IAC/E,4EAA4E;IAC5E,8EAA8E;IAC9E,6EAA6E;IAC7E,8EAA8E;IAC9E,MAA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aretLeftIcon } from \"@phosphor-icons/react/dist/csr/CaretLeft\";\nimport { useState } from \"react\";\nimport \"./WindowToolBar.css\";\nimport { WindowTitleBarActionButtons } from \"./WindowChromeActions\";\nimport {\n useWindowBackActionValue,\n useWindowTitleBarActions,\n useWindowToolbarReservationReleased,\n useWindowToolbarReserved,\n} from \"./WindowMenuContext\";\n\n/**\n * The window's toolbar row, sitting below the File/View menu bar and above the\n * body. It renders the same actions the routed app bar shows — the registered\n * {@link useWindowBackAction} on the left and {@link useWindowTitleBarAction}\n * icon buttons on the right — so a mini-app hosted in a window gets the same\n * toolbar chrome it gets in the routed shell.\n *\n * The left slot resolves exactly as `RoutedPaneAppBar` does: a registered back\n * action wins, and otherwise the button steps back through the host's own\n * history. `showHistoryBack` turns that fallback on for a window hosting a\n * routed mini-app, whose history is the window's Back stack (windows are not\n * backed by browser history); the fallback is omitted when that stack is empty.\n * Unlike the routed shell's paired Back/Forward controls, the window has no\n * adjacent history control whose stable placement would justify a disabled\n * Back button.\n *\n * Both surfaces read one shared registry (WindowMenuContext), so a mini-app\n * registers its actions once and they appear wherever it is hosted.\n *\n * A window whose app never registers toolbar chrome keeps a flush menu bar/body\n * (the row renders nothing). But once an app HAS shown chrome, the row stays\n * mounted and reserves its {@link WindowToolBar.css} min-height even when the\n * action set momentarily clears — on an action-less sub-route or a loading tick\n * where the app's `show` conditions are briefly false. Unmounting the row in\n * those windows would drop a full bar-height out of the flex column and shift\n * the body up, then back down when the actions re-register (visible flicker).\n *\n * An app that wants the row on every route — a blank bar where a route carries\n * no actions, rather than one that only appears after some route first shows\n * chrome — reserves it via {@link useWindowToolbarReservation} (the reserved row\n * still mounts a commit late, once that hook's effect registers, as all window\n * chrome does).\n */\nexport function WindowToolBar({\n canGoBack = false,\n onGoBack,\n showHistoryBack = false,\n}: {\n canGoBack?: boolean;\n onGoBack?: (() => void) | undefined;\n showHistoryBack?: boolean;\n} = {}) {\n const backAction = useWindowBackActionValue();\n const actions = useWindowTitleBarActions();\n const reserved = useWindowToolbarReserved();\n const reservationReleased = useWindowToolbarReservationReleased();\n const showBack = backAction !== null || (showHistoryBack && canGoBack);\n const hasChrome =\n backAction !== null || showHistoryBack || actions.length > 0;\n // Latch: this window's app has shown toolbar chrome at least once, so keep the\n // row reserved from here on rather than collapsing it on a transient empty.\n // Seed from the mount-time value so a window that already has chrome does not\n // latch during render at all; the render-phase set below catches chrome that\n // first appears after mount, without an effect's extra committed render pass.\n const [hasShownChrome, setHasShownChrome] = useState(hasChrome);\n let latchedChrome = hasShownChrome;\n if (hasChrome && !latchedChrome) {\n setHasShownChrome(true);\n latchedChrome = true;\n } else if (!hasChrome && reservationReleased && latchedChrome) {\n setHasShownChrome(false);\n latchedChrome = false;\n }\n\n if (!hasChrome && !latchedChrome && !reserved) {\n return null;\n }\n\n const backLabel = backAction?.label ?? \"Back\";\n\n return (\n <div aria-label=\"Toolbar\" className=\"window-toolbar\" role=\"toolbar\">\n <div className=\"window-toolbar-primary\">\n {showBack && (\n <button\n aria-label={backLabel}\n className=\"window-toolbar-button\"\n disabled={backAction?.disabled ?? false}\n title={backLabel}\n type=\"button\"\n onClick={backAction?.onClick ?? onGoBack}\n >\n <CaretLeftIcon aria-hidden size={18} />\n <span className=\"window-toolbar-back-label\">{backLabel}</span>\n </button>\n )}\n </div>\n <div className=\"window-toolbar-spacer\" />\n {actions.length > 0 && (\n <div className=\"window-toolbar-actions\">\n <WindowTitleBarActionButtons\n actions={actions}\n className=\"window-toolbar-button\"\n />\n </div>\n )}\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"WindowToolBar.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowToolBar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EAAE,2BAA2B,EAAE,MAAM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,EAAE,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,SAAS,GAAG,UAAU,EAAE,KAAK,IAAI,MAAM,CAAC;IAE9C,OAAO,CACL,6BAAgB,SAAS,EAAC,SAAS,EAAC,gBAAgB,EAAC,IAAI,EAAC,SAAS,aACjE,cAAK,SAAS,EAAC,wBAAwB,YACpC,QAAQ,IAAI,CACX,gCACc,SAAS,EACrB,SAAS,EAAC,uBAAuB,EACjC,QAAQ,EAAE,UAAU,EAAE,QAAQ,IAAI,KAAK,EACvC,KAAK,EAAE,SAAS,EAChB,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,UAAU,EAAE,OAAO,IAAI,QAAQ,aAExC,KAAC,QAAQ,yBAAa,IAAI,EAAE,EAAE,GAAI,EAClC,eAAM,SAAS,EAAC,2BAA2B,YAAE,SAAS,GAAQ,IACvD,CACV,GACG,EACN,cAAK,SAAS,EAAC,uBAAuB,GAAG,EACxC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CACrB,cAAK,SAAS,EAAC,wBAAwB,YACrC,KAAC,2BAA2B,IAC1B,OAAO,EAAE,OAAO,EAChB,SAAS,EAAC,uBAAuB,GACjC,GACE,CACP,IACG,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { useState } from \"react\";\nimport { useWindowingIcons } from \"../icons/WindowingIcons\";\nimport \"./WindowToolBar.css\";\nimport { WindowTitleBarActionButtons } from \"./WindowChromeActions\";\nimport {\n useWindowBackActionValue,\n useWindowTitleBarActions,\n useWindowToolbarReservationReleased,\n useWindowToolbarReserved,\n} from \"./WindowMenuContext\";\n\n/**\n * The window's toolbar row, sitting below the File/View menu bar and above the\n * body. It renders the same actions the routed app bar shows — the registered\n * {@link useWindowBackAction} on the left and {@link useWindowTitleBarAction}\n * icon buttons on the right — so a mini-app hosted in a window gets the same\n * toolbar chrome it gets in the routed shell.\n *\n * The left slot resolves exactly as `RoutedPaneAppBar` does: a registered back\n * action wins, and otherwise the button steps back through the host's own\n * history. `showHistoryBack` turns that fallback on for a window hosting a\n * routed mini-app, whose history is the window's Back stack (windows are not\n * backed by browser history); the fallback is omitted when that stack is empty.\n * Unlike the routed shell's paired Back/Forward controls, the window has no\n * adjacent history control whose stable placement would justify a disabled\n * Back button.\n *\n * Both surfaces read one shared registry (WindowMenuContext), so a mini-app\n * registers its actions once and they appear wherever it is hosted.\n *\n * A window whose app never registers toolbar chrome keeps a flush menu bar/body\n * (the row renders nothing). But once an app HAS shown chrome, the row stays\n * mounted and reserves its {@link WindowToolBar.css} min-height even when the\n * action set momentarily clears — on an action-less sub-route or a loading tick\n * where the app's `show` conditions are briefly false. Unmounting the row in\n * those windows would drop a full bar-height out of the flex column and shift\n * the body up, then back down when the actions re-register (visible flicker).\n *\n * An app that wants the row on every route — a blank bar where a route carries\n * no actions, rather than one that only appears after some route first shows\n * chrome — reserves it via {@link useWindowToolbarReservation} (the reserved row\n * still mounts a commit late, once that hook's effect registers, as all window\n * chrome does).\n */\nexport function WindowToolBar({\n canGoBack = false,\n onGoBack,\n showHistoryBack = false,\n}: {\n canGoBack?: boolean;\n onGoBack?: (() => void) | undefined;\n showHistoryBack?: boolean;\n} = {}) {\n const { back: BackIcon } = useWindowingIcons();\n const backAction = useWindowBackActionValue();\n const actions = useWindowTitleBarActions();\n const reserved = useWindowToolbarReserved();\n const reservationReleased = useWindowToolbarReservationReleased();\n const showBack = backAction !== null || (showHistoryBack && canGoBack);\n const hasChrome =\n backAction !== null || showHistoryBack || actions.length > 0;\n // Latch: this window's app has shown toolbar chrome at least once, so keep the\n // row reserved from here on rather than collapsing it on a transient empty.\n // Seed from the mount-time value so a window that already has chrome does not\n // latch during render at all; the render-phase set below catches chrome that\n // first appears after mount, without an effect's extra committed render pass.\n const [hasShownChrome, setHasShownChrome] = useState(hasChrome);\n let latchedChrome = hasShownChrome;\n if (hasChrome && !latchedChrome) {\n setHasShownChrome(true);\n latchedChrome = true;\n } else if (!hasChrome && reservationReleased && latchedChrome) {\n setHasShownChrome(false);\n latchedChrome = false;\n }\n\n if (!hasChrome && !latchedChrome && !reserved) {\n return null;\n }\n\n const backLabel = backAction?.label ?? \"Back\";\n\n return (\n <div aria-label=\"Toolbar\" className=\"window-toolbar\" role=\"toolbar\">\n <div className=\"window-toolbar-primary\">\n {showBack && (\n <button\n aria-label={backLabel}\n className=\"window-toolbar-button\"\n disabled={backAction?.disabled ?? false}\n title={backLabel}\n type=\"button\"\n onClick={backAction?.onClick ?? onGoBack}\n >\n <BackIcon aria-hidden size={18} />\n <span className=\"window-toolbar-back-label\">{backLabel}</span>\n </button>\n )}\n </div>\n <div className=\"window-toolbar-spacer\" />\n {actions.length > 0 && (\n <div className=\"window-toolbar-actions\">\n <WindowTitleBarActionButtons\n actions={actions}\n className=\"window-toolbar-button\"\n />\n </div>\n )}\n </div>\n );\n}\n"]}
@@ -7,7 +7,10 @@ interface WindowFitHost {
7
7
  windowRef: RefObject<HTMLElement | null>;
8
8
  }
9
9
  export declare function useWindowGeometryMenu(entry: WindowEntry, stepped: Parameters<typeof useWindowGeometryMenuItems>[0], host: WindowFitHost, announce: (message: string) => void): {
10
+ contentFit: {
11
+ markContentLoaded: () => void;
12
+ setContentSize: import("react").Dispatch<import("react").SetStateAction<WindowSize | undefined>>;
13
+ };
10
14
  geometryMenuItems: WindowMenuItem[];
11
- setContentSize: import("react").Dispatch<import("react").SetStateAction<WindowSize | undefined>>;
12
15
  };
13
16
  export {};
@@ -1,4 +1,4 @@
1
- import { useCallback, useMemo, useState } from "react";
1
+ import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
2
2
  import { useWindowGeometryMenuItems } from "./useWindowKeyboardGeometry.js";
3
3
  import { useWindowActions, } from "./WindowStateProvider/index.js";
4
4
  import { fitWindowGeometry } from "./windowGeometry.js";
@@ -32,6 +32,51 @@ function measureWindowFit(windowElement, pane) {
32
32
  scrollbar: measureScrollbars(pane),
33
33
  };
34
34
  }
35
+ // A window opened with `fitToContent` fits once, the first time its content
36
+ // has both marked itself loaded and reported a size while the window shows. A
37
+ // window maximized by then (as a host opens windows on narrow screens, before
38
+ // they are ever laid out) stays maximized and does not fit later. A hidden
39
+ // surface (an inactive workspace) has no size to fit against, so the fit waits
40
+ // until it has one.
41
+ function useFitOnLoad(entry, contentSize, fit, windowRef) {
42
+ const [loaded, setLoaded] = useState(false);
43
+ const pending = useRef(entry.fitToContent === true);
44
+ const markContentLoaded = useCallback(() => setLoaded(true), []);
45
+ const { maximized, minimized, position } = entry;
46
+ useEffect(() => {
47
+ if (!pending.current || !loaded || minimized) {
48
+ return;
49
+ }
50
+ if (maximized) {
51
+ pending.current = false;
52
+ return;
53
+ }
54
+ if (!contentSize) {
55
+ return;
56
+ }
57
+ const attempt = () => {
58
+ if (fit()) {
59
+ pending.current = false;
60
+ }
61
+ return !pending.current;
62
+ };
63
+ if (!position || attempt()) {
64
+ return;
65
+ }
66
+ const surface = windowRef.current?.parentElement;
67
+ if (!surface || typeof ResizeObserver === "undefined") {
68
+ return;
69
+ }
70
+ const observer = new ResizeObserver(() => {
71
+ if (attempt()) {
72
+ observer.disconnect();
73
+ }
74
+ });
75
+ observer.observe(surface);
76
+ return () => observer.disconnect();
77
+ }, [contentSize, fit, loaded, maximized, minimized, position, windowRef]);
78
+ return markContentLoaded;
79
+ }
35
80
  // Fit to Content, offered in the View menu while the window's content has a
36
81
  // natural size (see `useWindowContentSize`). It measures the window's chrome
37
82
  // as rendered, so it allows for whichever bars and sidebar show, and restores
@@ -40,18 +85,25 @@ function useWindowFit(entry, { overlayHost, windowRef }) {
40
85
  const { setGeometry, toggleMaximize } = useWindowActions();
41
86
  const [contentSize, setContentSize] = useState();
42
87
  const { id, maximized, position } = entry;
88
+ // Whether the window fitted: one that is not rendered, or whose surface is
89
+ // hidden, has nothing to measure.
43
90
  const fitToContent = useCallback(() => {
44
91
  const element = windowRef.current;
45
92
  const surface = element?.parentElement;
46
93
  const pane = overlayHost?.querySelector(SCROLL_PANE_SELECTOR);
47
- if (!contentSize || !element || !surface || !pane) {
48
- return;
94
+ if (!contentSize ||
95
+ !element ||
96
+ !surface ||
97
+ !pane ||
98
+ (surface.clientWidth === 0 && surface.clientHeight === 0)) {
99
+ return false;
49
100
  }
50
101
  const geometry = fitWindowGeometry(contentSize, measureWindowFit(element, pane), { height: surface.clientHeight, width: surface.clientWidth }, position ?? { x: 0, y: 0 });
51
102
  if (maximized) {
52
103
  toggleMaximize(id);
53
104
  }
54
105
  setGeometry(id, geometry);
106
+ return true;
55
107
  }, [
56
108
  contentSize,
57
109
  id,
@@ -71,18 +123,21 @@ function useWindowFit(entry, { overlayHost, windowRef }) {
71
123
  },
72
124
  ]
73
125
  : [], [contentSize, fitToContent]);
74
- return { fitMenuItems, setContentSize };
126
+ const markContentLoaded = useFitOnLoad(entry, contentSize, fitToContent, windowRef);
127
+ return { fitMenuItems, markContentLoaded, setContentSize };
75
128
  }
76
129
  // The View menu's geometry entries: keyboard move and resize, then Fit to
77
- // Content while the content has a natural size.
130
+ // Content while the content has a natural size. `contentFit` is the content's
131
+ // side of fitting, `setContentSize` and `markContentLoaded`, which the window
132
+ // passes to its content.
78
133
  export function useWindowGeometryMenu(entry, stepped, host, announce) {
79
134
  const keyboardItems = useWindowGeometryMenuItems(stepped, {
80
135
  maximized: entry.maximized,
81
136
  minimized: entry.minimized,
82
137
  windowRef: host.windowRef,
83
138
  }, announce);
84
- const { fitMenuItems, setContentSize } = useWindowFit(entry, host);
139
+ const { fitMenuItems, ...contentFit } = useWindowFit(entry, host);
85
140
  const geometryMenuItems = useMemo(() => [...keyboardItems, ...fitMenuItems], [fitMenuItems, keyboardItems]);
86
- return { geometryMenuItems, setContentSize };
141
+ return { contentFit, geometryMenuItems };
87
142
  }
88
143
  //# sourceMappingURL=useWindowFit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useWindowFit.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/useWindowFit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAA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QACD,WAAW,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC5B,CAAC,EAAE;QACD,WAAW;QACX,EAAE;QACF,SAAS;QACT,WAAW;QACX,QAAQ;QACR,WAAW;QACX,cAAc;QACd,SAAS;KACV,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,OAAO,CAC1B,GAAG,EAAE,CACH,WAAW;QACT,CAAC,CAAC;YACE;gBACE,EAAE,EAAE,gBAAgB;gBACpB,KAAK,EAAE,gBAAgB;gBACvB,OAAO,EAAE,YAAY;aACtB;SACF;QACH,CAAC,CAAC,EAAE,EACR,CAAC,WAAW,EAAE,YAAY,CAAC,CAC5B,CAAC;IAEF,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC;AAC1C,CAAC;AAED,0EAA0E;AAC1E,gDAAgD;AAChD,MAAM,UAAU,qBAAqB,CACnC,KAAkB,EAClB,OAAyD,EACzD,IAAmB,EACnB,QAAmC;IAEnC,MAAM,aAAa,GAAG,0BAA0B,CAC9C,OAAO,EACP;QACE,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,EACD,QAAQ,CACT,CAAC;IACF,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,GAAG,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnE,MAAM,iBAAiB,GAAG,OAAO,CAC/B,GAAG,EAAE,CAAC,CAAC,GAAG,aAAa,EAAE,GAAG,YAAY,CAAC,EACzC,CAAC,YAAY,EAAE,aAAa,CAAC,CAC9B,CAAC;IAEF,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,CAAC;AAC/C,CAAC","sourcesContent":["import { type RefObject, useCallback, useMemo, useState } from \"react\";\nimport { useWindowGeometryMenuItems } from \"./useWindowKeyboardGeometry\";\nimport type { WindowMenuItem } from \"./WindowMenuBar\";\nimport {\n useWindowActions,\n type WindowEntry,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport { fitWindowGeometry, type WindowFitMetrics } from \"./windowGeometry\";\n\nconst SCROLL_PANE_SELECTOR =\n \":scope > .window-body-content-scroll, :scope > .window-sidebar-content-scroll\";\n\n// The pane's scrollbars, forced on before its own overflow is put back. Layout\n// is read between the writes, so nothing is painted meanwhile.\nfunction measureScrollbars(pane: HTMLElement): WindowSize {\n const { overflow } = pane.style;\n pane.style.overflow = \"scroll\";\n const scrollbar = {\n height: pane.offsetHeight - pane.clientHeight,\n width: pane.offsetWidth - pane.clientWidth,\n };\n pane.style.overflow = overflow;\n return scrollbar;\n}\n\nfunction measureWindowFit(\n windowElement: HTMLElement,\n pane: HTMLElement,\n): WindowFitMetrics {\n const frame = windowElement.getBoundingClientRect();\n const paneRect = pane.getBoundingClientRect();\n const style = getComputedStyle(pane);\n const px = (value: string) => Number.parseFloat(value) || 0;\n\n return {\n chrome: {\n height: frame.height - paneRect.height,\n width: frame.width - paneRect.width,\n },\n padding: {\n height: px(style.paddingTop) + px(style.paddingBottom),\n width: px(style.paddingLeft) + px(style.paddingRight),\n },\n scrollbar: measureScrollbars(pane),\n };\n}\n\ninterface WindowFitHost {\n overlayHost: HTMLElement | null;\n windowRef: RefObject<HTMLElement | null>;\n}\n\n// Fit to Content, offered in the View menu while the window's content has a\n// natural size (see `useWindowContentSize`). It measures the window's chrome\n// as rendered, so it allows for whichever bars and sidebar show, and restores\n// a maximized window first.\nfunction useWindowFit(\n entry: WindowEntry,\n { overlayHost, windowRef }: WindowFitHost,\n) {\n const { setGeometry, toggleMaximize } = useWindowActions();\n const [contentSize, setContentSize] = useState<WindowSize | undefined>();\n const { id, maximized, position } = entry;\n\n const fitToContent = useCallback(() => {\n const element = windowRef.current;\n const surface = element?.parentElement;\n const pane = overlayHost?.querySelector<HTMLElement>(SCROLL_PANE_SELECTOR);\n if (!contentSize || !element || !surface || !pane) {\n return;\n }\n const geometry = fitWindowGeometry(\n contentSize,\n measureWindowFit(element, pane),\n { height: surface.clientHeight, width: surface.clientWidth },\n position ?? { x: 0, y: 0 },\n );\n if (maximized) {\n toggleMaximize(id);\n }\n setGeometry(id, geometry);\n }, [\n contentSize,\n id,\n maximized,\n overlayHost,\n position,\n setGeometry,\n toggleMaximize,\n windowRef,\n ]);\n\n const fitMenuItems = useMemo<WindowMenuItem[]>(\n () =>\n contentSize\n ? [\n {\n id: \"fit-to-content\",\n label: \"Fit to Content\",\n onClick: fitToContent,\n },\n ]\n : [],\n [contentSize, fitToContent],\n );\n\n return { fitMenuItems, setContentSize };\n}\n\n// The View menu's geometry entries: keyboard move and resize, then Fit to\n// Content while the content has a natural size.\nexport function useWindowGeometryMenu(\n entry: WindowEntry,\n stepped: Parameters<typeof useWindowGeometryMenuItems>[0],\n host: WindowFitHost,\n announce: (message: string) => void,\n) {\n const keyboardItems = useWindowGeometryMenuItems(\n stepped,\n {\n maximized: entry.maximized,\n minimized: entry.minimized,\n windowRef: host.windowRef,\n },\n announce,\n );\n const { fitMenuItems, setContentSize } = useWindowFit(entry, host);\n const geometryMenuItems = useMemo(\n () => [...keyboardItems, ...fitMenuItems],\n [fitMenuItems, keyboardItems],\n );\n\n return { geometryMenuItems, setContentSize };\n}\n"]}
1
+ {"version":3,"file":"useWindowFit.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/useWindowFit.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAEzE,OAAO,EACL,gBAAgB,GAGjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAyB,MAAM,kBAAkB,CAAC;AAE5E,MAAM,oBAAoB,GACxB,+EAA+E,CAAC;AAElF,+EAA+E;AAC/E,+DAA+D;AAC/D,SAAS,iBAAiB,CAAC,IAAiB;IAC1C,MAA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,iBAAiB,GAAG,OAAO,CAC/B,GAAG,EAAE,CAAC,CAAC,GAAG,aAAa,EAAE,GAAG,YAAY,CAAC,EACzC,CAAC,YAAY,EAAE,aAAa,CAAC,CAC9B,CAAC;IAEF,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC;AAC3C,CAAC","sourcesContent":["import {\n type RefObject,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useWindowGeometryMenuItems } from \"./useWindowKeyboardGeometry\";\nimport type { WindowMenuItem } from \"./WindowMenuBar\";\nimport {\n useWindowActions,\n type WindowEntry,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport { fitWindowGeometry, type WindowFitMetrics } from \"./windowGeometry\";\n\nconst SCROLL_PANE_SELECTOR =\n \":scope > .window-body-content-scroll, :scope > .window-sidebar-content-scroll\";\n\n// The pane's scrollbars, forced on before its own overflow is put back. Layout\n// is read between the writes, so nothing is painted meanwhile.\nfunction measureScrollbars(pane: HTMLElement): WindowSize {\n const { overflow } = pane.style;\n pane.style.overflow = \"scroll\";\n const scrollbar = {\n height: pane.offsetHeight - pane.clientHeight,\n width: pane.offsetWidth - pane.clientWidth,\n };\n pane.style.overflow = overflow;\n return scrollbar;\n}\n\nfunction measureWindowFit(\n windowElement: HTMLElement,\n pane: HTMLElement,\n): WindowFitMetrics {\n const frame = windowElement.getBoundingClientRect();\n const paneRect = pane.getBoundingClientRect();\n const style = getComputedStyle(pane);\n const px = (value: string) => Number.parseFloat(value) || 0;\n\n return {\n chrome: {\n height: frame.height - paneRect.height,\n width: frame.width - paneRect.width,\n },\n padding: {\n height: px(style.paddingTop) + px(style.paddingBottom),\n width: px(style.paddingLeft) + px(style.paddingRight),\n },\n scrollbar: measureScrollbars(pane),\n };\n}\n\ninterface WindowFitHost {\n overlayHost: HTMLElement | null;\n windowRef: RefObject<HTMLElement | null>;\n}\n\n// A window opened with `fitToContent` fits once, the first time its content\n// has both marked itself loaded and reported a size while the window shows. A\n// window maximized by then (as a host opens windows on narrow screens, before\n// they are ever laid out) stays maximized and does not fit later. A hidden\n// surface (an inactive workspace) has no size to fit against, so the fit waits\n// until it has one.\nfunction useFitOnLoad(\n entry: WindowEntry,\n contentSize: WindowSize | undefined,\n fit: () => boolean,\n windowRef: RefObject<HTMLElement | null>,\n) {\n const [loaded, setLoaded] = useState(false);\n const pending = useRef(entry.fitToContent === true);\n const markContentLoaded = useCallback(() => setLoaded(true), []);\n const { maximized, minimized, position } = entry;\n\n useEffect(() => {\n if (!pending.current || !loaded || minimized) {\n return;\n }\n if (maximized) {\n pending.current = false;\n return;\n }\n if (!contentSize) {\n return;\n }\n const attempt = () => {\n if (fit()) {\n pending.current = false;\n }\n return !pending.current;\n };\n if (!position || attempt()) {\n return;\n }\n const surface = windowRef.current?.parentElement;\n if (!surface || typeof ResizeObserver === \"undefined\") {\n return;\n }\n const observer = new ResizeObserver(() => {\n if (attempt()) {\n observer.disconnect();\n }\n });\n observer.observe(surface);\n return () => observer.disconnect();\n }, [contentSize, fit, loaded, maximized, minimized, position, windowRef]);\n\n return markContentLoaded;\n}\n\n// Fit to Content, offered in the View menu while the window's content has a\n// natural size (see `useWindowContentSize`). It measures the window's chrome\n// as rendered, so it allows for whichever bars and sidebar show, and restores\n// a maximized window first.\nfunction useWindowFit(\n entry: WindowEntry,\n { overlayHost, windowRef }: WindowFitHost,\n) {\n const { setGeometry, toggleMaximize } = useWindowActions();\n const [contentSize, setContentSize] = useState<WindowSize | undefined>();\n const { id, maximized, position } = entry;\n\n // Whether the window fitted: one that is not rendered, or whose surface is\n // hidden, has nothing to measure.\n const fitToContent = useCallback(() => {\n const element = windowRef.current;\n const surface = element?.parentElement;\n const pane = overlayHost?.querySelector<HTMLElement>(SCROLL_PANE_SELECTOR);\n if (\n !contentSize ||\n !element ||\n !surface ||\n !pane ||\n (surface.clientWidth === 0 && surface.clientHeight === 0)\n ) {\n return false;\n }\n const geometry = fitWindowGeometry(\n contentSize,\n measureWindowFit(element, pane),\n { height: surface.clientHeight, width: surface.clientWidth },\n position ?? { x: 0, y: 0 },\n );\n if (maximized) {\n toggleMaximize(id);\n }\n setGeometry(id, geometry);\n return true;\n }, [\n contentSize,\n id,\n maximized,\n overlayHost,\n position,\n setGeometry,\n toggleMaximize,\n windowRef,\n ]);\n\n const fitMenuItems = useMemo<WindowMenuItem[]>(\n () =>\n contentSize\n ? [\n {\n id: \"fit-to-content\",\n label: \"Fit to Content\",\n onClick: fitToContent,\n },\n ]\n : [],\n [contentSize, fitToContent],\n );\n\n const markContentLoaded = useFitOnLoad(\n entry,\n contentSize,\n fitToContent,\n windowRef,\n );\n\n return { fitMenuItems, markContentLoaded, setContentSize };\n}\n\n// The View menu's geometry entries: keyboard move and resize, then Fit to\n// Content while the content has a natural size. `contentFit` is the content's\n// side of fitting, `setContentSize` and `markContentLoaded`, which the window\n// passes to its content.\nexport function useWindowGeometryMenu(\n entry: WindowEntry,\n stepped: Parameters<typeof useWindowGeometryMenuItems>[0],\n host: WindowFitHost,\n announce: (message: string) => void,\n) {\n const keyboardItems = useWindowGeometryMenuItems(\n stepped,\n {\n maximized: entry.maximized,\n minimized: entry.minimized,\n windowRef: host.windowRef,\n },\n announce,\n );\n const { fitMenuItems, ...contentFit } = useWindowFit(entry, host);\n const geometryMenuItems = useMemo(\n () => [...keyboardItems, ...fitMenuItems],\n [fitMenuItems, keyboardItems],\n );\n\n return { contentFit, geometryMenuItems };\n}\n"]}