@ai-matrx/summon 0.1.4 → 0.1.5
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/CHANGELOG.md +3 -1
- package/README.md +2 -2
- package/dist/index.cjs +4 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/persistence-data.cjs +9 -0
- package/dist/persistence-data.cjs.map +1 -1
- package/dist/persistence-data.d.cts +2 -1
- package/dist/persistence-data.d.ts +2 -1
- package/dist/persistence-data.js +9 -0
- package/dist/persistence-data.js.map +1 -1
- package/dist/persistence.cjs +6 -4
- package/dist/persistence.cjs.map +1 -1
- package/dist/persistence.js +6 -4
- package/dist/persistence.js.map +1 -1
- package/dist/react.cjs +19 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +8 -1
- package/dist/react.d.ts +8 -1
- package/dist/react.js +19 -0
- package/dist/react.js.map +1 -1
- package/dist/url.cjs +32 -50
- package/dist/url.cjs.map +1 -1
- package/dist/url.d.cts +2 -8
- package/dist/url.d.ts +2 -8
- package/dist/url.js +8 -24
- package/dist/url.js.map +1 -1
- package/dist/window-host.cjs +43 -1
- package/dist/window-host.cjs.map +1 -1
- package/dist/window-host.d.cts +45 -1
- package/dist/window-host.d.ts +45 -1
- package/dist/window-host.js +44 -2
- package/dist/window-host.js.map +1 -1
- package/dist/window.cjs +127 -149
- package/dist/window.cjs.map +1 -1
- package/dist/window.d.cts +2 -46
- package/dist/window.d.ts +2 -46
- package/dist/window.js +14 -34
- package/dist/window.js.map +1 -1
- package/package.json +4 -4
package/dist/window-host.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/window-host.ts","../src/window/config.tsx","../src/window/WindowTraySync.tsx","../src/window/tray/trayPreviewRegistry.ts"],"sourcesContent":["// @ai-matrx/summon/window-host — the light half of the window section, safe to mount at the app\n// root: window configuration (WindowsProvider), the viewport/tray sync, and tray-preview\n// registration. Importing it never loads WindowPanel; the window section reads this section's\n// context through the package name, so both share one context.\nexport {\n WindowsProvider,\n useWindowConfig,\n WindowSelectionSurface,\n DEFAULT_WINDOW_CONFIG,\n DEFAULT_ESCAPE_YIELD_SELECTOR,\n DEFAULT_MOBILE_TOP_OFFSET,\n type WindowConfig,\n type WindowsProviderProps,\n type WindowSelectionSurfaceProps,\n} from \"./window/config\";\nexport { WindowTraySync } from \"./window/WindowTraySync\";\nexport {\n registerTrayPreview,\n getTrayPreviewEntry,\n resetTrayPreviews,\n type TrayPreviewContext,\n type TrayPreviewEntry,\n type TraySnapshotCapture,\n} from \"./window/tray/trayPreviewRegistry\";\n","\"use client\";\n\n/**\n * WindowsProvider — the window section's host options, read by every WindowPanel through context.\n * Everything has a working default, so no provider is needed at all; a host passes only what it\n * has (AI Matrx: its right-click selection menu and its header offset).\n */\nimport { createContext, useContext, useMemo, type ComponentType, type ReactNode } from \"react\";\n\nexport interface WindowSelectionSurfaceProps {\n readonly children: ReactNode;\n}\n\nexport interface WindowConfig {\n /**\n * Visible elements matching this selector own the Escape key: a window with `closeOnEscape`\n * yields to them (menus, popovers, listboxes and open dialogs always do). Default\n * `[data-overlay-escape-yield]` — mark any host surface that must take Escape first.\n */\n readonly escapeYieldSelector: string;\n /** Top offset of a phone fullscreen window (below the host's header). Default `var(--header-height, 0px)`. */\n readonly mobileTopOffset: string;\n /**\n * Wraps every window body (desktop, popped out, and all three phone presentations). Default:\n * passthrough. AI Matrx injects its selection toolbar + right-click menu here.\n */\n readonly selectionSurface: ComponentType<WindowSelectionSurfaceProps>;\n}\n\nfunction PassthroughSurface({ children }: WindowSelectionSurfaceProps) {\n return <>{children}</>;\n}\n\nexport const DEFAULT_ESCAPE_YIELD_SELECTOR = \"[data-overlay-escape-yield]\";\nexport const DEFAULT_MOBILE_TOP_OFFSET = \"var(--header-height, 0px)\";\n\nexport const DEFAULT_WINDOW_CONFIG: WindowConfig = {\n escapeYieldSelector: DEFAULT_ESCAPE_YIELD_SELECTOR,\n mobileTopOffset: DEFAULT_MOBILE_TOP_OFFSET,\n selectionSurface: PassthroughSurface,\n};\n\nconst WindowConfigContext = createContext<WindowConfig>(DEFAULT_WINDOW_CONFIG);\nWindowConfigContext.displayName = \"WindowConfigContext\";\n\nexport interface WindowsProviderProps extends Partial<WindowConfig> {\n readonly children?: ReactNode;\n}\n\nexport function WindowsProvider({ escapeYieldSelector, mobileTopOffset, selectionSurface, children }: WindowsProviderProps) {\n const value = useMemo<WindowConfig>(\n () => ({\n escapeYieldSelector: escapeYieldSelector ?? DEFAULT_WINDOW_CONFIG.escapeYieldSelector,\n mobileTopOffset: mobileTopOffset ?? DEFAULT_WINDOW_CONFIG.mobileTopOffset,\n selectionSurface: selectionSurface ?? DEFAULT_WINDOW_CONFIG.selectionSurface,\n }),\n [escapeYieldSelector, mobileTopOffset, selectionSurface],\n );\n return <WindowConfigContext.Provider value={value}>{children}</WindowConfigContext.Provider>;\n}\n\nexport function useWindowConfig(): WindowConfig {\n return useContext(WindowConfigContext);\n}\n\n/** The configured selection surface, as a component. */\nexport function WindowSelectionSurface({ children }: WindowSelectionSurfaceProps) {\n const Surface = useWindowConfig().selectionSurface;\n return <Surface>{children}</Surface>;\n}\n","\"use client\";\n\n/**\n * WindowTraySync\n *\n * Mounts ONCE in the root layout. Attaches a single debounced resize listener\n * that:\n * 1. Recomputes the positions of all minimized windows (tray slots can change\n * when chips-per-row shifts on viewport resize).\n * 2. Clamps every docked windowed window into the new viewport so windows\n * positioned for a larger screen stay reachable after a downsize.\n *\n * Zero re-renders — fires and forgets.\n *\n * Debounce: 500ms — a continuous window-drag generates exactly one dispatch\n * when the user stops moving. Short bursts (e.g. snapping) are ignored.\n *\n * Usage (in both authenticated and SSR root layouts):\n * <WindowTraySync />\n */\n\nimport { useEffect } from \"react\";\nimport { useSummonDispatch } from \"@ai-matrx/summon/react\";\nimport {\n recomputeTrayPositions,\n clampAllWindowRects,\n} from \"@ai-matrx/summon\";\nimport { safeViewportDims } from \"@ai-matrx/summon\";\n\nconst DEBOUNCE_MS = 500;\n\nexport function WindowTraySync() {\n const dispatch = useSummonDispatch();\n\n useEffect(() => {\n let timer: ReturnType<typeof setTimeout> | null = null;\n\n const syncWindowGeometry = () => {\n // A resize that measures 0×0 is a hidden/undisplayed tab or a\n // display:none ancestor, never a real screen. Bail WITHOUT dispatching:\n // reacting to it would rewrite every window rect and every tray slot\n // against invented dimensions, and the next real measurement would\n // then have to undo it. No measurement, no write.\n const { vw, vh, degenerate } = safeViewportDims();\n if (degenerate) return;\n dispatch(\n recomputeTrayPositions({ viewportWidth: vw, viewportHeight: vh }),\n );\n dispatch(clampAllWindowRects({ viewportWidth: vw, viewportHeight: vh }));\n };\n\n // This island may load after the viewport already changed. Synchronising\n // once on mount closes that event-listener gap for persisted windows.\n syncWindowGeometry();\n\n const handleResize = () => {\n if (timer !== null) clearTimeout(timer);\n timer = setTimeout(() => {\n timer = null;\n syncWindowGeometry();\n }, DEBOUNCE_MS);\n };\n\n window.addEventListener(\"resize\", handleResize, { passive: true });\n\n return () => {\n window.removeEventListener(\"resize\", handleResize);\n if (timer !== null) clearTimeout(timer);\n };\n }, [dispatch]);\n\n return null;\n}\n\nexport default WindowTraySync;\n","/**\n * Tray previews — overlay id → a semantic minimized preview and/or a custom snapshot capture.\n *\n * The host registers its previews once (AI Matrx keeps its own preview components in the app):\n *\n * registerTrayPreview(\"notesWindow\", NotesTrayPreview);\n * registerTrayPreview(\"canvasWindow\", { captureTraySnapshot: captureCanvas });\n *\n * A window with a preview component skips snapshot capture entirely (cheaper, higher fidelity).\n * A window with neither gets the default capture (`defaultTraySnapshotCapture`, html-to-image when\n * the host installed it). State lives in a global slot (kit globalSlot, D9).\n */\nimport type { ComponentType } from \"react\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\n\nexport interface TrayPreviewContext {\n /** The window's allowlisted semantic data (open data merged with what `onCollectData` returned). */\n readonly data: Readonly<Record<string, unknown>>;\n /** Stable overlay id (the registry key). */\n readonly overlayId: string;\n /** Instance id — `\"default\"` for singleton windows. */\n readonly instanceId: string;\n /** The display title. */\n readonly title: string;\n}\n\nexport type TraySnapshotCapture = (bodyEl: HTMLElement) => Promise<Blob | null>;\n\nexport interface TrayPreviewEntry {\n readonly Preview?: ComponentType<TrayPreviewContext>;\n readonly captureTraySnapshot?: TraySnapshotCapture;\n}\n\nconst EMPTY: TrayPreviewEntry = {};\n\nconst registry = (): Map<string, TrayPreviewEntry> =>\n globalSlot<Map<string, TrayPreviewEntry>>(\"ai-matrx.summon.window.trayPreviews\", () => new Map());\n\n/**\n * Register the minimized preview for an overlay (or any window id). Pass a component, or an entry\n * with `Preview` and/or `captureTraySnapshot`. Re-registering replaces. Returns an unregister.\n */\nexport function registerTrayPreview(\n overlayId: string,\n preview: ComponentType<TrayPreviewContext> | TrayPreviewEntry,\n): () => void {\n const entry: TrayPreviewEntry = typeof preview === \"function\" ? { Preview: preview } : preview;\n registry().set(overlayId, entry);\n return () => {\n if (registry().get(overlayId) === entry) registry().delete(overlayId);\n };\n}\n\nexport function getTrayPreviewEntry(overlayId: string): TrayPreviewEntry {\n return registry().get(overlayId) ?? EMPTY;\n}\n\n/** Test-only. */\nexport function resetTrayPreviews(): void {\n registry().clear();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOA,mBAAuF;AAuB9E;AADT,SAAS,mBAAmB,EAAE,SAAS,GAAgC;AACrE,SAAO,2EAAG,UAAS;AACrB;AAEO,IAAM,gCAAgC;AACtC,IAAM,4BAA4B;AAElC,IAAM,wBAAsC;AAAA,EACjD,qBAAqB;AAAA,EACrB,iBAAiB;AAAA,EACjB,kBAAkB;AACpB;AAEA,IAAM,0BAAsB,4BAA4B,qBAAqB;AAC7E,oBAAoB,cAAc;AA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KAAM,cAAa,KAAK;AAAA,IACxC;AAAA,EACF,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AACT;;;AC3DA,yBAA2B;AAoB3B,IAAM,QAA0B,CAAC;AAEjC,IAAM,WAAW,UACf,+BAA0C,uCAAuC,MAAM,oBAAI,IAAI,CAAC;AAM3F,SAAS,oBACd,WACA,SACY;AACZ,QAAM,QAA0B,OAAO,YAAY,aAAa,EAAE,SAAS,QAAQ,IAAI;AACvF,WAAS,EAAE,IAAI,WAAW,KAAK;AAC/B,SAAO,MAAM;AACX,QAAI,SAAS,EAAE,IAAI,SAAS,MAAM,MAAO,UAAS,EAAE,OAAO,SAAS;AAAA,EACtE;AACF;AAEO,SAAS,oBAAoB,WAAqC;AACvE,SAAO,SAAS,EAAE,IAAI,SAAS,KAAK;AACtC;AAGO,SAAS,oBAA0B;AACxC,WAAS,EAAE,MAAM;AACnB;","names":["import_react","import_summon"]}
|
|
1
|
+
{"version":3,"sources":["../src/window-host.ts","../src/window/config.tsx","../src/window/WindowTraySync.tsx","../src/window/popout/PopoutContext.tsx","../src/window/popout/usePopoutContainer.ts","../src/window/useOverlaySurfaceRenderAck.ts","../src/window/tray/trayPreviewRegistry.ts"],"sourcesContent":["// @ai-matrx/summon/window-host — the light half of the window section, safe to mount at the app\n// root: window configuration (WindowsProvider), the viewport/tray sync, and tray-preview\n// registration. Importing it never loads WindowPanel; the window section reads this section's\n// context through the package name, so both share one context.\nexport {\n WindowsProvider,\n useWindowConfig,\n WindowSelectionSurface,\n DEFAULT_WINDOW_CONFIG,\n DEFAULT_ESCAPE_YIELD_SELECTOR,\n DEFAULT_MOBILE_TOP_OFFSET,\n type WindowConfig,\n type WindowsProviderProps,\n type WindowSelectionSurfaceProps,\n} from \"./window/config\";\nexport { WindowTraySync } from \"./window/WindowTraySync\";\n// Hooks a render module calls inside a window, light enough for the boot graph. The popout context\n// lives HERE (one identity): the window section imports it through the package name.\nexport { usePopout, PopoutContext, type PopoutContextValue, type PopoutMode } from \"./window/popout/PopoutContext\";\nexport { usePopoutContainer } from \"./window/popout/usePopoutContainer\";\nexport { useOverlaySurfaceRenderAck } from \"./window/useOverlaySurfaceRenderAck\";\nexport {\n registerTrayPreview,\n getTrayPreviewEntry,\n resetTrayPreviews,\n type TrayPreviewContext,\n type TrayPreviewEntry,\n type TraySnapshotCapture,\n} from \"./window/tray/trayPreviewRegistry\";\n","\"use client\";\n\n/**\n * WindowsProvider — the window section's host options, read by every WindowPanel through context.\n * Everything has a working default, so no provider is needed at all; a host passes only what it\n * has (AI Matrx: its right-click selection menu and its header offset).\n */\nimport { createContext, useContext, useMemo, type ComponentType, type ReactNode } from \"react\";\n\nexport interface WindowSelectionSurfaceProps {\n readonly children: ReactNode;\n}\n\nexport interface WindowConfig {\n /**\n * Visible elements matching this selector own the Escape key: a window with `closeOnEscape`\n * yields to them (menus, popovers, listboxes and open dialogs always do). Default\n * `[data-overlay-escape-yield]` — mark any host surface that must take Escape first.\n */\n readonly escapeYieldSelector: string;\n /** Top offset of a phone fullscreen window (below the host's header). Default `var(--header-height, 0px)`. */\n readonly mobileTopOffset: string;\n /**\n * Wraps every window body (desktop, popped out, and all three phone presentations). Default:\n * passthrough. AI Matrx injects its selection toolbar + right-click menu here.\n */\n readonly selectionSurface: ComponentType<WindowSelectionSurfaceProps>;\n}\n\nfunction PassthroughSurface({ children }: WindowSelectionSurfaceProps) {\n return <>{children}</>;\n}\n\nexport const DEFAULT_ESCAPE_YIELD_SELECTOR = \"[data-overlay-escape-yield]\";\nexport const DEFAULT_MOBILE_TOP_OFFSET = \"var(--header-height, 0px)\";\n\nexport const DEFAULT_WINDOW_CONFIG: WindowConfig = {\n escapeYieldSelector: DEFAULT_ESCAPE_YIELD_SELECTOR,\n mobileTopOffset: DEFAULT_MOBILE_TOP_OFFSET,\n selectionSurface: PassthroughSurface,\n};\n\nconst WindowConfigContext = createContext<WindowConfig>(DEFAULT_WINDOW_CONFIG);\nWindowConfigContext.displayName = \"WindowConfigContext\";\n\nexport interface WindowsProviderProps extends Partial<WindowConfig> {\n readonly children?: ReactNode;\n}\n\nexport function WindowsProvider({ escapeYieldSelector, mobileTopOffset, selectionSurface, children }: WindowsProviderProps) {\n const value = useMemo<WindowConfig>(\n () => ({\n escapeYieldSelector: escapeYieldSelector ?? DEFAULT_WINDOW_CONFIG.escapeYieldSelector,\n mobileTopOffset: mobileTopOffset ?? DEFAULT_WINDOW_CONFIG.mobileTopOffset,\n selectionSurface: selectionSurface ?? DEFAULT_WINDOW_CONFIG.selectionSurface,\n }),\n [escapeYieldSelector, mobileTopOffset, selectionSurface],\n );\n return <WindowConfigContext.Provider value={value}>{children}</WindowConfigContext.Provider>;\n}\n\nexport function useWindowConfig(): WindowConfig {\n return useContext(WindowConfigContext);\n}\n\n/** The configured selection surface, as a component. */\nexport function WindowSelectionSurface({ children }: WindowSelectionSurfaceProps) {\n const Surface = useWindowConfig().selectionSurface;\n return <Surface>{children}</Surface>;\n}\n","\"use client\";\n\n/**\n * WindowTraySync\n *\n * Mounts ONCE in the root layout. Does nothing — no listener, no dispatch — until a window\n * exists (one boolean selector), then attaches a single debounced resize listener that:\n * 1. Recomputes the positions of all minimized windows (tray slots can change\n * when chips-per-row shifts on viewport resize).\n * 2. Clamps every docked windowed window into the new viewport so windows\n * positioned for a larger screen stay reachable after a downsize.\n *\n * Zero re-renders — fires and forgets.\n *\n * Debounce: 500ms — a continuous window-drag generates exactly one dispatch\n * when the user stops moving. Short bursts (e.g. snapping) are ignored.\n *\n * Usage (in both authenticated and SSR root layouts):\n * <WindowTraySync />\n */\n\nimport { useEffect } from \"react\";\nimport { useSummonDispatch, useSummonSelector } from \"@ai-matrx/summon/react\";\nimport {\n recomputeTrayPositions,\n clampAllWindowRects,\n} from \"@ai-matrx/summon\";\nimport { safeViewportDims, type WindowManagerState } from \"@ai-matrx/summon\";\n\nconst DEBOUNCE_MS = 500;\n\n/** Any window registered or waiting to restore: until then there is no geometry to keep in view. */\nexport function selectAnyWindowGeometry(state: { windowManager?: WindowManagerState }): boolean {\n const wm = state.windowManager;\n if (!wm) return false;\n for (const _ in wm.windows) return true;\n for (const _ in wm.pendingRestores) return true;\n return false;\n}\n\nexport function WindowTraySync() {\n const dispatch = useSummonDispatch();\n const active = useSummonSelector(selectAnyWindowGeometry);\n\n useEffect(() => {\n if (!active) return;\n let timer: ReturnType<typeof setTimeout> | null = null;\n\n const syncWindowGeometry = () => {\n // A resize that measures 0×0 is a hidden/undisplayed tab or a\n // display:none ancestor, never a real screen. Bail WITHOUT dispatching:\n // reacting to it would rewrite every window rect and every tray slot\n // against invented dimensions, and the next real measurement would\n // then have to undo it. No measurement, no write.\n const { vw, vh, degenerate } = safeViewportDims();\n if (degenerate) return;\n dispatch(\n recomputeTrayPositions({ viewportWidth: vw, viewportHeight: vh }),\n );\n dispatch(clampAllWindowRects({ viewportWidth: vw, viewportHeight: vh }));\n };\n\n // This island may load after the viewport already changed. Synchronising\n // once on mount closes that event-listener gap for persisted windows.\n syncWindowGeometry();\n\n const handleResize = () => {\n if (timer !== null) clearTimeout(timer);\n timer = setTimeout(() => {\n timer = null;\n syncWindowGeometry();\n }, DEBOUNCE_MS);\n };\n\n window.addEventListener(\"resize\", handleResize, { passive: true });\n\n return () => {\n window.removeEventListener(\"resize\", handleResize);\n if (timer !== null) clearTimeout(timer);\n };\n }, [dispatch, active]);\n\n return null;\n}\n\nexport default WindowTraySync;\n","\"use client\";\n\n/**\n * PopoutContext — exposes the popout `Document` / `Window` / portal target\n * to descendants of a popped-out subtree.\n *\n * The default value (`popoutDocument: null`, etc.) means \"I'm rendered in\n * the parent document.\" Descendants that need to behave differently inside\n * a popout (e.g. Radix portals retargeting their content) call\n * `usePopout()` and branch on the values.\n *\n * **Architectural note:** because `createPortal` preserves the parent\n * React tree, every ancestor `Provider` cascades into the popout — Redux,\n * Theme, Tooltip, Router, all work without re-wrapping. This context is\n * for the *opposite* direction: telling popped-out content \"you're inside\n * a popout window, here's the document/window/container you should use\n * instead of the global `document`/`window`.\"\n */\nimport { createContext, useContext } from \"react\";\n\nexport type PopoutMode = \"pip\" | \"popup\";\n\nexport interface PopoutContextValue {\n /**\n * The popout `Document`. `null` when this subtree is rendered in the\n * parent (the default).\n */\n popoutDocument: Document | null;\n /**\n * The popout `Window`. `null` when this subtree is rendered in the parent.\n * Use for `addEventListener`, `matchMedia`, `innerWidth`, etc., when the\n * popout-scoped answer is what you need.\n */\n popoutWindow: Window | null;\n /**\n * Element to use as the Radix `Portal.container` prop so floating UI\n * (tooltips, popovers, dropdowns) renders inside the popout instead of\n * the parent `document.body`. Returns `null` outside a popout —\n * `usePopoutContainer` coerces this to `undefined` so Radix falls back\n * to its default container automatically.\n */\n popoutContainer: HTMLElement | null;\n /**\n * Which popout mechanism is in use. `null` outside a popout.\n * Currently only used for diagnostics; downstream components may branch\n * on it later (e.g. show different chrome for `popup` vs `pip`).\n */\n mode: PopoutMode | null;\n}\n\nconst DEFAULT_VALUE: PopoutContextValue = {\n popoutDocument: null,\n popoutWindow: null,\n popoutContainer: null,\n mode: null,\n};\n\nexport const PopoutContext =\n createContext<PopoutContextValue>(DEFAULT_VALUE);\n\n/** Read the current popout context. Always defined — never throws. */\nexport function usePopout(): PopoutContextValue {\n return useContext(PopoutContext);\n}\n","\"use client\";\n\n/**\n * usePopoutContainer — return the element Radix portals (Tooltip, Popover,\n * Dropdown, Dialog, Select, AlertDialog, HoverCard) should mount into.\n *\n * **The problem this solves:** by default every Radix `Portal` mounts to\n * `document.body`. When a tooltip-trigger lives inside a popped-out window\n * but the popover content portals to the *parent* document, the tooltip\n * appears in the wrong window — typically invisible to the user.\n *\n * **The fix:** wrappers around Radix primitives call this hook and pass\n * the result as `<Primitive.Portal container={...} />`. Inside a popout,\n * the result is the popout's `<body>`. Outside a popout, the result is\n * `undefined`, which Radix interprets as \"use the default\" — meaning no\n * behavior change for any of the thousands of existing usages.\n *\n * **Why `undefined` instead of `null`?** Radix's `container` prop accepts\n * `HTMLElement | null | undefined`. Passing `null` actively tries to\n * portal into a `null` target and crashes. Passing `undefined` falls\n * through to the default (`document.body`). The `?? undefined` coerces\n * the `null` we get from `PopoutContext` outside a popout into the\n * Radix-friendly default-fallthrough value.\n */\nimport { usePopout } from \"./PopoutContext\";\n\nexport function usePopoutContainer(): HTMLElement | undefined {\n return usePopout().popoutContainer ?? undefined;\n}\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { ackOverlaySurfaceRender, clearOverlaySurfaceRender } from \"@ai-matrx/summon\";\n\n/**\n * Acknowledge a visible presentation that intentionally replaces WindowPanel.\n *\n * Registered singleton window overlays normally prove they are on screen by mounting a\n * WindowPanel and registering geometry. Mobile drawers, sheets, and full-screen\n * viewers have no window-manager geometry, so their composition root must use\n * this hook while that alternate surface is active.\n */\nexport function useOverlaySurfaceRenderAck(\n overlayId: string,\n active: boolean,\n): void {\n useEffect(() => {\n if (!active) return undefined;\n ackOverlaySurfaceRender(overlayId);\n return () => clearOverlaySurfaceRender(overlayId);\n }, [active, overlayId]);\n}\n","/**\n * Tray previews — overlay id → a semantic minimized preview and/or a custom snapshot capture.\n *\n * The host registers its previews once (AI Matrx keeps its own preview components in the app):\n *\n * registerTrayPreview(\"notesWindow\", NotesTrayPreview);\n * registerTrayPreview(\"canvasWindow\", { captureTraySnapshot: captureCanvas });\n *\n * A window with a preview component skips snapshot capture entirely (cheaper, higher fidelity).\n * A window with neither gets the default capture (`defaultTraySnapshotCapture`, html-to-image when\n * the host installed it). State lives in a global slot (kit globalSlot, D9).\n */\nimport type { ComponentType } from \"react\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\n\nexport interface TrayPreviewContext {\n /** The window's allowlisted semantic data (open data merged with what `onCollectData` returned). */\n readonly data: Readonly<Record<string, unknown>>;\n /** Stable overlay id (the registry key). */\n readonly overlayId: string;\n /** Instance id — `\"default\"` for singleton windows. */\n readonly instanceId: string;\n /** The display title. */\n readonly title: string;\n}\n\nexport type TraySnapshotCapture = (bodyEl: HTMLElement) => Promise<Blob | null>;\n\nexport interface TrayPreviewEntry {\n readonly Preview?: ComponentType<TrayPreviewContext>;\n readonly captureTraySnapshot?: TraySnapshotCapture;\n}\n\nconst EMPTY: TrayPreviewEntry = {};\n\nconst registry = (): Map<string, TrayPreviewEntry> =>\n globalSlot<Map<string, TrayPreviewEntry>>(\"ai-matrx.summon.window.trayPreviews\", () => new Map());\n\n/**\n * Register the minimized preview for an overlay (or any window id). Pass a component, or an entry\n * with `Preview` and/or `captureTraySnapshot`. Re-registering replaces. Returns an unregister.\n */\nexport function registerTrayPreview(\n overlayId: string,\n preview: ComponentType<TrayPreviewContext> | TrayPreviewEntry,\n): () => void {\n const entry: TrayPreviewEntry = typeof preview === \"function\" ? { Preview: preview } : preview;\n registry().set(overlayId, entry);\n return () => {\n if (registry().get(overlayId) === entry) registry().delete(overlayId);\n };\n}\n\nexport function getTrayPreviewEntry(overlayId: string): TrayPreviewEntry {\n return registry().get(overlayId) ?? EMPTY;\n}\n\n/** Test-only. */\nexport function resetTrayPreviews(): void {\n registry().clear();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOA,mBAAuF;AAuB9E;AADT,SAAS,mBAAmB,EAAE,SAAS,GAAgC;AACrE,SAAO,2EAAG,UAAS;AACrB;AAEO,IAAM,gCAAgC;AACtC,IAAM,4BAA4B;AAElC,IAAM,wBAAsC;AAAA,EACjD,qBAAqB;AAAA,EACrB,iBAAiB;AAAA,EACjB,kBAAkB;AACpB;AAEA,IAAM,0BAAsB,4BAA4B,qBAAqB;AAC7E,oBAAoB,cAAc;AAM3B,SAAS,gBAAgB,EAAE,qBAAqB,iBAAiB,kBAAkB,SAAS,GAAyB;AAC1H,QAAM,YAAQ;AAAA,IACZ,OAAO;AAAA,MACL,qBAAqB,uBAAuB,sBAAsB;AAAA,MAClE,iBAAiB,mBAAmB,sBAA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WAAO,MAAM;AACX,aAAO,oBAAoB,UAAU,YAAY;AACjD,UAAI,UAAU,KAAM,cAAa,KAAK;AAAA,IACxC;AAAA,EACF,GAAG,CAAC,UAAU,MAAM,CAAC;AAErB,SAAO;AACT;;;ACjEA,IAAAC,gBAA0C;AAgC1C,IAAM,gBAAoC;AAAA,EACxC,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,iBAAiB;AAAA,EACjB,MAAM;AACR;AAEO,IAAM,oBACX,6BAAkC,aAAa;AAG1C,SAAS,YAAgC;AAC9C,aAAO,0BAAW,aAAa;AACjC;;;ACrCO,SAAS,qBAA8C;AAC5D,SAAO,UAAU,EAAE,mBAAmB;AACxC;;;AC1BA,IAAAC,gBAA0B;AAC1B,IAAAC,iBAAmE;AAU5D,SAAS,2BACd,WACA,QACM;AACN,+BAAU,MAAM;AACd,QAAI,CAAC,OAAQ,QAAO;AACpB,gDAAwB,SAAS;AACjC,WAAO,UAAM,0CAA0B,SAAS;AAAA,EAClD,GAAG,CAAC,QAAQ,SAAS,CAAC;AACxB;;;ACTA,yBAA2B;AAoB3B,IAAM,QAA0B,CAAC;AAEjC,IAAM,WAAW,UACf,+BAA0C,uCAAuC,MAAM,oBAAI,IAAI,CAAC;AAM3F,SAAS,oBACd,WACA,SACY;AACZ,QAAM,QAA0B,OAAO,YAAY,aAAa,EAAE,SAAS,QAAQ,IAAI;AACvF,WAAS,EAAE,IAAI,WAAW,KAAK;AAC/B,SAAO,MAAM;AACX,QAAI,SAAS,EAAE,IAAI,SAAS,MAAM,MAAO,UAAS,EAAE,OAAO,SAAS;AAAA,EACtE;AACF;AAEO,SAAS,oBAAoB,WAAqC;AACvE,SAAO,SAAS,EAAE,IAAI,SAAS,KAAK;AACtC;AAGO,SAAS,oBAA0B;AACxC,WAAS,EAAE,MAAM;AACnB;","names":["import_react","import_summon","import_react","import_react","import_summon"]}
|
package/dist/window-host.d.cts
CHANGED
|
@@ -32,6 +32,50 @@ declare function WindowSelectionSurface({ children }: WindowSelectionSurfaceProp
|
|
|
32
32
|
|
|
33
33
|
declare function WindowTraySync(): null;
|
|
34
34
|
|
|
35
|
+
type PopoutMode = "pip" | "popup";
|
|
36
|
+
interface PopoutContextValue {
|
|
37
|
+
/**
|
|
38
|
+
* The popout `Document`. `null` when this subtree is rendered in the
|
|
39
|
+
* parent (the default).
|
|
40
|
+
*/
|
|
41
|
+
popoutDocument: Document | null;
|
|
42
|
+
/**
|
|
43
|
+
* The popout `Window`. `null` when this subtree is rendered in the parent.
|
|
44
|
+
* Use for `addEventListener`, `matchMedia`, `innerWidth`, etc., when the
|
|
45
|
+
* popout-scoped answer is what you need.
|
|
46
|
+
*/
|
|
47
|
+
popoutWindow: Window | null;
|
|
48
|
+
/**
|
|
49
|
+
* Element to use as the Radix `Portal.container` prop so floating UI
|
|
50
|
+
* (tooltips, popovers, dropdowns) renders inside the popout instead of
|
|
51
|
+
* the parent `document.body`. Returns `null` outside a popout —
|
|
52
|
+
* `usePopoutContainer` coerces this to `undefined` so Radix falls back
|
|
53
|
+
* to its default container automatically.
|
|
54
|
+
*/
|
|
55
|
+
popoutContainer: HTMLElement | null;
|
|
56
|
+
/**
|
|
57
|
+
* Which popout mechanism is in use. `null` outside a popout.
|
|
58
|
+
* Currently only used for diagnostics; downstream components may branch
|
|
59
|
+
* on it later (e.g. show different chrome for `popup` vs `pip`).
|
|
60
|
+
*/
|
|
61
|
+
mode: PopoutMode | null;
|
|
62
|
+
}
|
|
63
|
+
declare const PopoutContext: react.Context<PopoutContextValue>;
|
|
64
|
+
/** Read the current popout context. Always defined — never throws. */
|
|
65
|
+
declare function usePopout(): PopoutContextValue;
|
|
66
|
+
|
|
67
|
+
declare function usePopoutContainer(): HTMLElement | undefined;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Acknowledge a visible presentation that intentionally replaces WindowPanel.
|
|
71
|
+
*
|
|
72
|
+
* Registered singleton window overlays normally prove they are on screen by mounting a
|
|
73
|
+
* WindowPanel and registering geometry. Mobile drawers, sheets, and full-screen
|
|
74
|
+
* viewers have no window-manager geometry, so their composition root must use
|
|
75
|
+
* this hook while that alternate surface is active.
|
|
76
|
+
*/
|
|
77
|
+
declare function useOverlaySurfaceRenderAck(overlayId: string, active: boolean): void;
|
|
78
|
+
|
|
35
79
|
/**
|
|
36
80
|
* Tray previews — overlay id → a semantic minimized preview and/or a custom snapshot capture.
|
|
37
81
|
*
|
|
@@ -69,4 +113,4 @@ declare function getTrayPreviewEntry(overlayId: string): TrayPreviewEntry;
|
|
|
69
113
|
/** Test-only. */
|
|
70
114
|
declare function resetTrayPreviews(): void;
|
|
71
115
|
|
|
72
|
-
export { DEFAULT_ESCAPE_YIELD_SELECTOR, DEFAULT_MOBILE_TOP_OFFSET, DEFAULT_WINDOW_CONFIG, type TrayPreviewContext, type TrayPreviewEntry, type TraySnapshotCapture, type WindowConfig, WindowSelectionSurface, type WindowSelectionSurfaceProps, WindowTraySync, WindowsProvider, type WindowsProviderProps, getTrayPreviewEntry, registerTrayPreview, resetTrayPreviews, useWindowConfig };
|
|
116
|
+
export { DEFAULT_ESCAPE_YIELD_SELECTOR, DEFAULT_MOBILE_TOP_OFFSET, DEFAULT_WINDOW_CONFIG, PopoutContext, type PopoutContextValue, type PopoutMode, type TrayPreviewContext, type TrayPreviewEntry, type TraySnapshotCapture, type WindowConfig, WindowSelectionSurface, type WindowSelectionSurfaceProps, WindowTraySync, WindowsProvider, type WindowsProviderProps, getTrayPreviewEntry, registerTrayPreview, resetTrayPreviews, useOverlaySurfaceRenderAck, usePopout, usePopoutContainer, useWindowConfig };
|
package/dist/window-host.d.ts
CHANGED
|
@@ -32,6 +32,50 @@ declare function WindowSelectionSurface({ children }: WindowSelectionSurfaceProp
|
|
|
32
32
|
|
|
33
33
|
declare function WindowTraySync(): null;
|
|
34
34
|
|
|
35
|
+
type PopoutMode = "pip" | "popup";
|
|
36
|
+
interface PopoutContextValue {
|
|
37
|
+
/**
|
|
38
|
+
* The popout `Document`. `null` when this subtree is rendered in the
|
|
39
|
+
* parent (the default).
|
|
40
|
+
*/
|
|
41
|
+
popoutDocument: Document | null;
|
|
42
|
+
/**
|
|
43
|
+
* The popout `Window`. `null` when this subtree is rendered in the parent.
|
|
44
|
+
* Use for `addEventListener`, `matchMedia`, `innerWidth`, etc., when the
|
|
45
|
+
* popout-scoped answer is what you need.
|
|
46
|
+
*/
|
|
47
|
+
popoutWindow: Window | null;
|
|
48
|
+
/**
|
|
49
|
+
* Element to use as the Radix `Portal.container` prop so floating UI
|
|
50
|
+
* (tooltips, popovers, dropdowns) renders inside the popout instead of
|
|
51
|
+
* the parent `document.body`. Returns `null` outside a popout —
|
|
52
|
+
* `usePopoutContainer` coerces this to `undefined` so Radix falls back
|
|
53
|
+
* to its default container automatically.
|
|
54
|
+
*/
|
|
55
|
+
popoutContainer: HTMLElement | null;
|
|
56
|
+
/**
|
|
57
|
+
* Which popout mechanism is in use. `null` outside a popout.
|
|
58
|
+
* Currently only used for diagnostics; downstream components may branch
|
|
59
|
+
* on it later (e.g. show different chrome for `popup` vs `pip`).
|
|
60
|
+
*/
|
|
61
|
+
mode: PopoutMode | null;
|
|
62
|
+
}
|
|
63
|
+
declare const PopoutContext: react.Context<PopoutContextValue>;
|
|
64
|
+
/** Read the current popout context. Always defined — never throws. */
|
|
65
|
+
declare function usePopout(): PopoutContextValue;
|
|
66
|
+
|
|
67
|
+
declare function usePopoutContainer(): HTMLElement | undefined;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Acknowledge a visible presentation that intentionally replaces WindowPanel.
|
|
71
|
+
*
|
|
72
|
+
* Registered singleton window overlays normally prove they are on screen by mounting a
|
|
73
|
+
* WindowPanel and registering geometry. Mobile drawers, sheets, and full-screen
|
|
74
|
+
* viewers have no window-manager geometry, so their composition root must use
|
|
75
|
+
* this hook while that alternate surface is active.
|
|
76
|
+
*/
|
|
77
|
+
declare function useOverlaySurfaceRenderAck(overlayId: string, active: boolean): void;
|
|
78
|
+
|
|
35
79
|
/**
|
|
36
80
|
* Tray previews — overlay id → a semantic minimized preview and/or a custom snapshot capture.
|
|
37
81
|
*
|
|
@@ -69,4 +113,4 @@ declare function getTrayPreviewEntry(overlayId: string): TrayPreviewEntry;
|
|
|
69
113
|
/** Test-only. */
|
|
70
114
|
declare function resetTrayPreviews(): void;
|
|
71
115
|
|
|
72
|
-
export { DEFAULT_ESCAPE_YIELD_SELECTOR, DEFAULT_MOBILE_TOP_OFFSET, DEFAULT_WINDOW_CONFIG, type TrayPreviewContext, type TrayPreviewEntry, type TraySnapshotCapture, type WindowConfig, WindowSelectionSurface, type WindowSelectionSurfaceProps, WindowTraySync, WindowsProvider, type WindowsProviderProps, getTrayPreviewEntry, registerTrayPreview, resetTrayPreviews, useWindowConfig };
|
|
116
|
+
export { DEFAULT_ESCAPE_YIELD_SELECTOR, DEFAULT_MOBILE_TOP_OFFSET, DEFAULT_WINDOW_CONFIG, PopoutContext, type PopoutContextValue, type PopoutMode, type TrayPreviewContext, type TrayPreviewEntry, type TraySnapshotCapture, type WindowConfig, WindowSelectionSurface, type WindowSelectionSurfaceProps, WindowTraySync, WindowsProvider, type WindowsProviderProps, getTrayPreviewEntry, registerTrayPreview, resetTrayPreviews, useOverlaySurfaceRenderAck, usePopout, usePopoutContainer, useWindowConfig };
|
package/dist/window-host.js
CHANGED
|
@@ -36,16 +36,25 @@ function WindowSelectionSurface({ children }) {
|
|
|
36
36
|
|
|
37
37
|
// src/window/WindowTraySync.tsx
|
|
38
38
|
import { useEffect } from "react";
|
|
39
|
-
import { useSummonDispatch } from "@ai-matrx/summon/react";
|
|
39
|
+
import { useSummonDispatch, useSummonSelector } from "@ai-matrx/summon/react";
|
|
40
40
|
import {
|
|
41
41
|
recomputeTrayPositions,
|
|
42
42
|
clampAllWindowRects
|
|
43
43
|
} from "@ai-matrx/summon";
|
|
44
44
|
import { safeViewportDims } from "@ai-matrx/summon";
|
|
45
45
|
var DEBOUNCE_MS = 500;
|
|
46
|
+
function selectAnyWindowGeometry(state) {
|
|
47
|
+
const wm = state.windowManager;
|
|
48
|
+
if (!wm) return false;
|
|
49
|
+
for (const _ in wm.windows) return true;
|
|
50
|
+
for (const _ in wm.pendingRestores) return true;
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
46
53
|
function WindowTraySync() {
|
|
47
54
|
const dispatch = useSummonDispatch();
|
|
55
|
+
const active = useSummonSelector(selectAnyWindowGeometry);
|
|
48
56
|
useEffect(() => {
|
|
57
|
+
if (!active) return;
|
|
49
58
|
let timer = null;
|
|
50
59
|
const syncWindowGeometry = () => {
|
|
51
60
|
const { vw, vh, degenerate } = safeViewportDims();
|
|
@@ -68,10 +77,39 @@ function WindowTraySync() {
|
|
|
68
77
|
window.removeEventListener("resize", handleResize);
|
|
69
78
|
if (timer !== null) clearTimeout(timer);
|
|
70
79
|
};
|
|
71
|
-
}, [dispatch]);
|
|
80
|
+
}, [dispatch, active]);
|
|
72
81
|
return null;
|
|
73
82
|
}
|
|
74
83
|
|
|
84
|
+
// src/window/popout/PopoutContext.tsx
|
|
85
|
+
import { createContext as createContext2, useContext as useContext2 } from "react";
|
|
86
|
+
var DEFAULT_VALUE = {
|
|
87
|
+
popoutDocument: null,
|
|
88
|
+
popoutWindow: null,
|
|
89
|
+
popoutContainer: null,
|
|
90
|
+
mode: null
|
|
91
|
+
};
|
|
92
|
+
var PopoutContext = createContext2(DEFAULT_VALUE);
|
|
93
|
+
function usePopout() {
|
|
94
|
+
return useContext2(PopoutContext);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/window/popout/usePopoutContainer.ts
|
|
98
|
+
function usePopoutContainer() {
|
|
99
|
+
return usePopout().popoutContainer ?? void 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/window/useOverlaySurfaceRenderAck.ts
|
|
103
|
+
import { useEffect as useEffect2 } from "react";
|
|
104
|
+
import { ackOverlaySurfaceRender, clearOverlaySurfaceRender } from "@ai-matrx/summon";
|
|
105
|
+
function useOverlaySurfaceRenderAck(overlayId, active) {
|
|
106
|
+
useEffect2(() => {
|
|
107
|
+
if (!active) return void 0;
|
|
108
|
+
ackOverlaySurfaceRender(overlayId);
|
|
109
|
+
return () => clearOverlaySurfaceRender(overlayId);
|
|
110
|
+
}, [active, overlayId]);
|
|
111
|
+
}
|
|
112
|
+
|
|
75
113
|
// src/window/tray/trayPreviewRegistry.ts
|
|
76
114
|
import { globalSlot } from "@ai-matrx/kit/global-slot";
|
|
77
115
|
var EMPTY = {};
|
|
@@ -93,12 +131,16 @@ export {
|
|
|
93
131
|
DEFAULT_ESCAPE_YIELD_SELECTOR,
|
|
94
132
|
DEFAULT_MOBILE_TOP_OFFSET,
|
|
95
133
|
DEFAULT_WINDOW_CONFIG,
|
|
134
|
+
PopoutContext,
|
|
96
135
|
WindowSelectionSurface,
|
|
97
136
|
WindowTraySync,
|
|
98
137
|
WindowsProvider,
|
|
99
138
|
getTrayPreviewEntry,
|
|
100
139
|
registerTrayPreview,
|
|
101
140
|
resetTrayPreviews,
|
|
141
|
+
useOverlaySurfaceRenderAck,
|
|
142
|
+
usePopout,
|
|
143
|
+
usePopoutContainer,
|
|
102
144
|
useWindowConfig
|
|
103
145
|
};
|
|
104
146
|
//# sourceMappingURL=window-host.js.map
|
package/dist/window-host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/window/config.tsx","../src/window/WindowTraySync.tsx","../src/window/tray/trayPreviewRegistry.ts"],"sourcesContent":["\"use client\";\n\n/**\n * WindowsProvider — the window section's host options, read by every WindowPanel through context.\n * Everything has a working default, so no provider is needed at all; a host passes only what it\n * has (AI Matrx: its right-click selection menu and its header offset).\n */\nimport { createContext, useContext, useMemo, type ComponentType, type ReactNode } from \"react\";\n\nexport interface WindowSelectionSurfaceProps {\n readonly children: ReactNode;\n}\n\nexport interface WindowConfig {\n /**\n * Visible elements matching this selector own the Escape key: a window with `closeOnEscape`\n * yields to them (menus, popovers, listboxes and open dialogs always do). Default\n * `[data-overlay-escape-yield]` — mark any host surface that must take Escape first.\n */\n readonly escapeYieldSelector: string;\n /** Top offset of a phone fullscreen window (below the host's header). Default `var(--header-height, 0px)`. */\n readonly mobileTopOffset: string;\n /**\n * Wraps every window body (desktop, popped out, and all three phone presentations). Default:\n * passthrough. AI Matrx injects its selection toolbar + right-click menu here.\n */\n readonly selectionSurface: ComponentType<WindowSelectionSurfaceProps>;\n}\n\nfunction PassthroughSurface({ children }: WindowSelectionSurfaceProps) {\n return <>{children}</>;\n}\n\nexport const DEFAULT_ESCAPE_YIELD_SELECTOR = \"[data-overlay-escape-yield]\";\nexport const DEFAULT_MOBILE_TOP_OFFSET = \"var(--header-height, 0px)\";\n\nexport const DEFAULT_WINDOW_CONFIG: WindowConfig = {\n escapeYieldSelector: DEFAULT_ESCAPE_YIELD_SELECTOR,\n mobileTopOffset: DEFAULT_MOBILE_TOP_OFFSET,\n selectionSurface: PassthroughSurface,\n};\n\nconst WindowConfigContext = createContext<WindowConfig>(DEFAULT_WINDOW_CONFIG);\nWindowConfigContext.displayName = \"WindowConfigContext\";\n\nexport interface WindowsProviderProps extends Partial<WindowConfig> {\n readonly children?: ReactNode;\n}\n\nexport function WindowsProvider({ escapeYieldSelector, mobileTopOffset, selectionSurface, children }: WindowsProviderProps) {\n const value = useMemo<WindowConfig>(\n () => ({\n escapeYieldSelector: escapeYieldSelector ?? DEFAULT_WINDOW_CONFIG.escapeYieldSelector,\n mobileTopOffset: mobileTopOffset ?? DEFAULT_WINDOW_CONFIG.mobileTopOffset,\n selectionSurface: selectionSurface ?? DEFAULT_WINDOW_CONFIG.selectionSurface,\n }),\n [escapeYieldSelector, mobileTopOffset, selectionSurface],\n );\n return <WindowConfigContext.Provider value={value}>{children}</WindowConfigContext.Provider>;\n}\n\nexport function useWindowConfig(): WindowConfig {\n return useContext(WindowConfigContext);\n}\n\n/** The configured selection surface, as a component. */\nexport function WindowSelectionSurface({ children }: WindowSelectionSurfaceProps) {\n const Surface = useWindowConfig().selectionSurface;\n return <Surface>{children}</Surface>;\n}\n","\"use client\";\n\n/**\n * WindowTraySync\n *\n * Mounts ONCE in the root layout. Attaches a single debounced resize listener\n * that:\n * 1. Recomputes the positions of all minimized windows (tray slots can change\n * when chips-per-row shifts on viewport resize).\n * 2. Clamps every docked windowed window into the new viewport so windows\n * positioned for a larger screen stay reachable after a downsize.\n *\n * Zero re-renders — fires and forgets.\n *\n * Debounce: 500ms — a continuous window-drag generates exactly one dispatch\n * when the user stops moving. Short bursts (e.g. snapping) are ignored.\n *\n * Usage (in both authenticated and SSR root layouts):\n * <WindowTraySync />\n */\n\nimport { useEffect } from \"react\";\nimport { useSummonDispatch } from \"@ai-matrx/summon/react\";\nimport {\n recomputeTrayPositions,\n clampAllWindowRects,\n} from \"@ai-matrx/summon\";\nimport { safeViewportDims } from \"@ai-matrx/summon\";\n\nconst DEBOUNCE_MS = 500;\n\nexport function WindowTraySync() {\n const dispatch = useSummonDispatch();\n\n useEffect(() => {\n let timer: ReturnType<typeof setTimeout> | null = null;\n\n const syncWindowGeometry = () => {\n // A resize that measures 0×0 is a hidden/undisplayed tab or a\n // display:none ancestor, never a real screen. Bail WITHOUT dispatching:\n // reacting to it would rewrite every window rect and every tray slot\n // against invented dimensions, and the next real measurement would\n // then have to undo it. No measurement, no write.\n const { vw, vh, degenerate } = safeViewportDims();\n if (degenerate) return;\n dispatch(\n recomputeTrayPositions({ viewportWidth: vw, viewportHeight: vh }),\n );\n dispatch(clampAllWindowRects({ viewportWidth: vw, viewportHeight: vh }));\n };\n\n // This island may load after the viewport already changed. Synchronising\n // once on mount closes that event-listener gap for persisted windows.\n syncWindowGeometry();\n\n const handleResize = () => {\n if (timer !== null) clearTimeout(timer);\n timer = setTimeout(() => {\n timer = null;\n syncWindowGeometry();\n }, DEBOUNCE_MS);\n };\n\n window.addEventListener(\"resize\", handleResize, { passive: true });\n\n return () => {\n window.removeEventListener(\"resize\", handleResize);\n if (timer !== null) clearTimeout(timer);\n };\n }, [dispatch]);\n\n return null;\n}\n\nexport default WindowTraySync;\n","/**\n * Tray previews — overlay id → a semantic minimized preview and/or a custom snapshot capture.\n *\n * The host registers its previews once (AI Matrx keeps its own preview components in the app):\n *\n * registerTrayPreview(\"notesWindow\", NotesTrayPreview);\n * registerTrayPreview(\"canvasWindow\", { captureTraySnapshot: captureCanvas });\n *\n * A window with a preview component skips snapshot capture entirely (cheaper, higher fidelity).\n * A window with neither gets the default capture (`defaultTraySnapshotCapture`, html-to-image when\n * the host installed it). State lives in a global slot (kit globalSlot, D9).\n */\nimport type { ComponentType } from \"react\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\n\nexport interface TrayPreviewContext {\n /** The window's allowlisted semantic data (open data merged with what `onCollectData` returned). */\n readonly data: Readonly<Record<string, unknown>>;\n /** Stable overlay id (the registry key). */\n readonly overlayId: string;\n /** Instance id — `\"default\"` for singleton windows. */\n readonly instanceId: string;\n /** The display title. */\n readonly title: string;\n}\n\nexport type TraySnapshotCapture = (bodyEl: HTMLElement) => Promise<Blob | null>;\n\nexport interface TrayPreviewEntry {\n readonly Preview?: ComponentType<TrayPreviewContext>;\n readonly captureTraySnapshot?: TraySnapshotCapture;\n}\n\nconst EMPTY: TrayPreviewEntry = {};\n\nconst registry = (): Map<string, TrayPreviewEntry> =>\n globalSlot<Map<string, TrayPreviewEntry>>(\"ai-matrx.summon.window.trayPreviews\", () => new Map());\n\n/**\n * Register the minimized preview for an overlay (or any window id). Pass a component, or an entry\n * with `Preview` and/or `captureTraySnapshot`. Re-registering replaces. Returns an unregister.\n */\nexport function registerTrayPreview(\n overlayId: string,\n preview: ComponentType<TrayPreviewContext> | TrayPreviewEntry,\n): () => void {\n const entry: TrayPreviewEntry = typeof preview === \"function\" ? { Preview: preview } : preview;\n registry().set(overlayId, entry);\n return () => {\n if (registry().get(overlayId) === entry) registry().delete(overlayId);\n };\n}\n\nexport function getTrayPreviewEntry(overlayId: string): TrayPreviewEntry {\n return registry().get(overlayId) ?? EMPTY;\n}\n\n/** Test-only.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;AACA,eAAS,oBAAoB,EAAE,eAAe,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAAA,IACzE;AAIA,uBAAmB;AAEnB,UAAM,eAAe,MAAM;AACzB,UAAI,UAAU,KAAM,cAAa,KAAK;AACtC,cAAQ,WAAW,MAAM;AACvB,gBAAQ;AACR,2BAAmB;AAAA,MACrB,GAAG,WAAW;AAAA,IAChB;AAEA,WAAO,iBAAiB,UAAU,cAAc,EAAE,SAAS,KAAK,CAAC;AAEjE,WAAO,MAAM;AACX,aAAO,oBAAoB,UAAU,YAAY;AACjD,UAAI,UAAU,KAAM,cAAa,KAAK;AAAA,IACxC;AAAA,EACF,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AACT;;;AC3DA,SAAS,kBAAkB;AAoB3B,IAAM,QAA0B,CAAC;AAEjC,IAAM,WAAW,MACf,WAA0C,uCAAuC,MAAM,oBAAI,IAAI,CAAC;AAM3F,SAAS,oBACd,WACA,SACY;AACZ,QAAM,QAA0B,OAAO,YAAY,aAAa,EAAE,SAAS,QAAQ,IAAI;AACvF,WAAS,EAAE,IAAI,WAAW,KAAK;AAC/B,SAAO,MAAM;AACX,QAAI,SAAS,EAAE,IAAI,SAAS,MAAM,MAAO,UAAS,EAAE,OAAO,SAAS;AAAA,EACtE;AACF;AAEO,SAAS,oBAAoB,WAAqC;AACvE,SAAO,SAAS,EAAE,IAAI,SAAS,KAAK;AACtC;AAGO,SAAS,oBAA0B;AACxC,WAAS,EAAE,MAAM;AACnB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/window/config.tsx","../src/window/WindowTraySync.tsx","../src/window/popout/PopoutContext.tsx","../src/window/popout/usePopoutContainer.ts","../src/window/useOverlaySurfaceRenderAck.ts","../src/window/tray/trayPreviewRegistry.ts"],"sourcesContent":["\"use client\";\n\n/**\n * WindowsProvider — the window section's host options, read by every WindowPanel through context.\n * Everything has a working default, so no provider is needed at all; a host passes only what it\n * has (AI Matrx: its right-click selection menu and its header offset).\n */\nimport { createContext, useContext, useMemo, type ComponentType, type ReactNode } from \"react\";\n\nexport interface WindowSelectionSurfaceProps {\n readonly children: ReactNode;\n}\n\nexport interface WindowConfig {\n /**\n * Visible elements matching this selector own the Escape key: a window with `closeOnEscape`\n * yields to them (menus, popovers, listboxes and open dialogs always do). Default\n * `[data-overlay-escape-yield]` — mark any host surface that must take Escape first.\n */\n readonly escapeYieldSelector: string;\n /** Top offset of a phone fullscreen window (below the host's header). Default `var(--header-height, 0px)`. */\n readonly mobileTopOffset: string;\n /**\n * Wraps every window body (desktop, popped out, and all three phone presentations). Default:\n * passthrough. AI Matrx injects its selection toolbar + right-click menu here.\n */\n readonly selectionSurface: ComponentType<WindowSelectionSurfaceProps>;\n}\n\nfunction PassthroughSurface({ children }: WindowSelectionSurfaceProps) {\n return <>{children}</>;\n}\n\nexport const DEFAULT_ESCAPE_YIELD_SELECTOR = \"[data-overlay-escape-yield]\";\nexport const DEFAULT_MOBILE_TOP_OFFSET = \"var(--header-height, 0px)\";\n\nexport const DEFAULT_WINDOW_CONFIG: WindowConfig = {\n escapeYieldSelector: DEFAULT_ESCAPE_YIELD_SELECTOR,\n mobileTopOffset: DEFAULT_MOBILE_TOP_OFFSET,\n selectionSurface: PassthroughSurface,\n};\n\nconst WindowConfigContext = createContext<WindowConfig>(DEFAULT_WINDOW_CONFIG);\nWindowConfigContext.displayName = \"WindowConfigContext\";\n\nexport interface WindowsProviderProps extends Partial<WindowConfig> {\n readonly children?: ReactNode;\n}\n\nexport function WindowsProvider({ escapeYieldSelector, mobileTopOffset, selectionSurface, children }: WindowsProviderProps) {\n const value = useMemo<WindowConfig>(\n () => ({\n escapeYieldSelector: escapeYieldSelector ?? DEFAULT_WINDOW_CONFIG.escapeYieldSelector,\n mobileTopOffset: mobileTopOffset ?? DEFAULT_WINDOW_CONFIG.mobileTopOffset,\n selectionSurface: selectionSurface ?? DEFAULT_WINDOW_CONFIG.selectionSurface,\n }),\n [escapeYieldSelector, mobileTopOffset, selectionSurface],\n );\n return <WindowConfigContext.Provider value={value}>{children}</WindowConfigContext.Provider>;\n}\n\nexport function useWindowConfig(): WindowConfig {\n return useContext(WindowConfigContext);\n}\n\n/** The configured selection surface, as a component. */\nexport function WindowSelectionSurface({ children }: WindowSelectionSurfaceProps) {\n const Surface = useWindowConfig().selectionSurface;\n return <Surface>{children}</Surface>;\n}\n","\"use client\";\n\n/**\n * WindowTraySync\n *\n * Mounts ONCE in the root layout. Does nothing — no listener, no dispatch — until a window\n * exists (one boolean selector), then attaches a single debounced resize listener that:\n * 1. Recomputes the positions of all minimized windows (tray slots can change\n * when chips-per-row shifts on viewport resize).\n * 2. Clamps every docked windowed window into the new viewport so windows\n * positioned for a larger screen stay reachable after a downsize.\n *\n * Zero re-renders — fires and forgets.\n *\n * Debounce: 500ms — a continuous window-drag generates exactly one dispatch\n * when the user stops moving. Short bursts (e.g. snapping) are ignored.\n *\n * Usage (in both authenticated and SSR root layouts):\n * <WindowTraySync />\n */\n\nimport { useEffect } from \"react\";\nimport { useSummonDispatch, useSummonSelector } from \"@ai-matrx/summon/react\";\nimport {\n recomputeTrayPositions,\n clampAllWindowRects,\n} from \"@ai-matrx/summon\";\nimport { safeViewportDims, type WindowManagerState } from \"@ai-matrx/summon\";\n\nconst DEBOUNCE_MS = 500;\n\n/** Any window registered or waiting to restore: until then there is no geometry to keep in view. */\nexport function selectAnyWindowGeometry(state: { windowManager?: WindowManagerState }): boolean {\n const wm = state.windowManager;\n if (!wm) return false;\n for (const _ in wm.windows) return true;\n for (const _ in wm.pendingRestores) return true;\n return false;\n}\n\nexport function WindowTraySync() {\n const dispatch = useSummonDispatch();\n const active = useSummonSelector(selectAnyWindowGeometry);\n\n useEffect(() => {\n if (!active) return;\n let timer: ReturnType<typeof setTimeout> | null = null;\n\n const syncWindowGeometry = () => {\n // A resize that measures 0×0 is a hidden/undisplayed tab or a\n // display:none ancestor, never a real screen. Bail WITHOUT dispatching:\n // reacting to it would rewrite every window rect and every tray slot\n // against invented dimensions, and the next real measurement would\n // then have to undo it. No measurement, no write.\n const { vw, vh, degenerate } = safeViewportDims();\n if (degenerate) return;\n dispatch(\n recomputeTrayPositions({ viewportWidth: vw, viewportHeight: vh }),\n );\n dispatch(clampAllWindowRects({ viewportWidth: vw, viewportHeight: vh }));\n };\n\n // This island may load after the viewport already changed. Synchronising\n // once on mount closes that event-listener gap for persisted windows.\n syncWindowGeometry();\n\n const handleResize = () => {\n if (timer !== null) clearTimeout(timer);\n timer = setTimeout(() => {\n timer = null;\n syncWindowGeometry();\n }, DEBOUNCE_MS);\n };\n\n window.addEventListener(\"resize\", handleResize, { passive: true });\n\n return () => {\n window.removeEventListener(\"resize\", handleResize);\n if (timer !== null) clearTimeout(timer);\n };\n }, [dispatch, active]);\n\n return null;\n}\n\nexport default WindowTraySync;\n","\"use client\";\n\n/**\n * PopoutContext — exposes the popout `Document` / `Window` / portal target\n * to descendants of a popped-out subtree.\n *\n * The default value (`popoutDocument: null`, etc.) means \"I'm rendered in\n * the parent document.\" Descendants that need to behave differently inside\n * a popout (e.g. Radix portals retargeting their content) call\n * `usePopout()` and branch on the values.\n *\n * **Architectural note:** because `createPortal` preserves the parent\n * React tree, every ancestor `Provider` cascades into the popout — Redux,\n * Theme, Tooltip, Router, all work without re-wrapping. This context is\n * for the *opposite* direction: telling popped-out content \"you're inside\n * a popout window, here's the document/window/container you should use\n * instead of the global `document`/`window`.\"\n */\nimport { createContext, useContext } from \"react\";\n\nexport type PopoutMode = \"pip\" | \"popup\";\n\nexport interface PopoutContextValue {\n /**\n * The popout `Document`. `null` when this subtree is rendered in the\n * parent (the default).\n */\n popoutDocument: Document | null;\n /**\n * The popout `Window`. `null` when this subtree is rendered in the parent.\n * Use for `addEventListener`, `matchMedia`, `innerWidth`, etc., when the\n * popout-scoped answer is what you need.\n */\n popoutWindow: Window | null;\n /**\n * Element to use as the Radix `Portal.container` prop so floating UI\n * (tooltips, popovers, dropdowns) renders inside the popout instead of\n * the parent `document.body`. Returns `null` outside a popout —\n * `usePopoutContainer` coerces this to `undefined` so Radix falls back\n * to its default container automatically.\n */\n popoutContainer: HTMLElement | null;\n /**\n * Which popout mechanism is in use. `null` outside a popout.\n * Currently only used for diagnostics; downstream components may branch\n * on it later (e.g. show different chrome for `popup` vs `pip`).\n */\n mode: PopoutMode | null;\n}\n\nconst DEFAULT_VALUE: PopoutContextValue = {\n popoutDocument: null,\n popoutWindow: null,\n popoutContainer: null,\n mode: null,\n};\n\nexport const PopoutContext =\n createContext<PopoutContextValue>(DEFAULT_VALUE);\n\n/** Read the current popout context. Always defined — never throws. */\nexport function usePopout(): PopoutContextValue {\n return useContext(PopoutContext);\n}\n","\"use client\";\n\n/**\n * usePopoutContainer — return the element Radix portals (Tooltip, Popover,\n * Dropdown, Dialog, Select, AlertDialog, HoverCard) should mount into.\n *\n * **The problem this solves:** by default every Radix `Portal` mounts to\n * `document.body`. When a tooltip-trigger lives inside a popped-out window\n * but the popover content portals to the *parent* document, the tooltip\n * appears in the wrong window — typically invisible to the user.\n *\n * **The fix:** wrappers around Radix primitives call this hook and pass\n * the result as `<Primitive.Portal container={...} />`. Inside a popout,\n * the result is the popout's `<body>`. Outside a popout, the result is\n * `undefined`, which Radix interprets as \"use the default\" — meaning no\n * behavior change for any of the thousands of existing usages.\n *\n * **Why `undefined` instead of `null`?** Radix's `container` prop accepts\n * `HTMLElement | null | undefined`. Passing `null` actively tries to\n * portal into a `null` target and crashes. Passing `undefined` falls\n * through to the default (`document.body`). The `?? undefined` coerces\n * the `null` we get from `PopoutContext` outside a popout into the\n * Radix-friendly default-fallthrough value.\n */\nimport { usePopout } from \"./PopoutContext\";\n\nexport function usePopoutContainer(): HTMLElement | undefined {\n return usePopout().popoutContainer ?? undefined;\n}\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { ackOverlaySurfaceRender, clearOverlaySurfaceRender } from \"@ai-matrx/summon\";\n\n/**\n * Acknowledge a visible presentation that intentionally replaces WindowPanel.\n *\n * Registered singleton window overlays normally prove they are on screen by mounting a\n * WindowPanel and registering geometry. Mobile drawers, sheets, and full-screen\n * viewers have no window-manager geometry, so their composition root must use\n * this hook while that alternate surface is active.\n */\nexport function useOverlaySurfaceRenderAck(\n overlayId: string,\n active: boolean,\n): void {\n useEffect(() => {\n if (!active) return undefined;\n ackOverlaySurfaceRender(overlayId);\n return () => clearOverlaySurfaceRender(overlayId);\n }, [active, overlayId]);\n}\n","/**\n * Tray previews — overlay id → a semantic minimized preview and/or a custom snapshot capture.\n *\n * The host registers its previews once (AI Matrx keeps its own preview components in the app):\n *\n * registerTrayPreview(\"notesWindow\", NotesTrayPreview);\n * registerTrayPreview(\"canvasWindow\", { captureTraySnapshot: captureCanvas });\n *\n * A window with a preview component skips snapshot capture entirely (cheaper, higher fidelity).\n * A window with neither gets the default capture (`defaultTraySnapshotCapture`, html-to-image when\n * the host installed it). State lives in a global slot (kit globalSlot, D9).\n */\nimport type { ComponentType } from \"react\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\n\nexport interface TrayPreviewContext {\n /** The window's allowlisted semantic data (open data merged with what `onCollectData` returned). */\n readonly data: Readonly<Record<string, unknown>>;\n /** Stable overlay id (the registry key). */\n readonly overlayId: string;\n /** Instance id — `\"default\"` for singleton windows. */\n readonly instanceId: string;\n /** The display title. */\n readonly title: string;\n}\n\nexport type TraySnapshotCapture = (bodyEl: HTMLElement) => Promise<Blob | null>;\n\nexport interface TrayPreviewEntry {\n readonly Preview?: ComponentType<TrayPreviewContext>;\n readonly captureTraySnapshot?: TraySnapshotCapture;\n}\n\nconst EMPTY: TrayPreviewEntry = {};\n\nconst registry = (): Map<string, TrayPreviewEntry> =>\n globalSlot<Map<string, TrayPreviewEntry>>(\"ai-matrx.summon.window.trayPreviews\", () => new Map());\n\n/**\n * Register the minimized preview for an overlay (or any window id). Pass a component, or an entry\n * with `Preview` and/or `captureTraySnapshot`. Re-registering replaces. Returns an unregister.\n */\nexport function registerTrayPreview(\n overlayId: string,\n preview: ComponentType<TrayPreviewContext> | TrayPreviewEntry,\n): () => void {\n const entry: TrayPreviewEntry = typeof preview === \"function\" ? { Preview: preview } : preview;\n registry().set(overlayId, entry);\n return () => {\n if (registry().get(overlayId) === entry) registry().delete(overlayId);\n };\n}\n\nexport function getTrayPreviewEntry(overlayId: string): TrayPreviewEntry {\n return registry().get(overlayId) ?? EMPTY;\n}\n\n/** Test-only. */\nexport function resetTrayPreviews(): void {\n registry().clear();\n}\n"],"mappings":";;;AAOA,SAAS,eAAe,YAAY,eAAmD;AAuB9E;AADT,SAAS,mBAAmB,EAAE,SAAS,GAAgC;AACrE,SAAO,gCAAG,UAAS;AACrB;AAEO,IAAM,gCAAgC;AACtC,IAAM,4BAA4B;AAElC,IAAM,wBAAsC;AAAA,EACjD,qBAAqB;AAAA,EACrB,iBAAiB;AAAA,EACjB,kBAAkB;AACpB;AAEA,IAAM,sBAAsB,cAA4B,qBAAqB;AAC7E,oBAAoB,cAAc;AAM3B,SAAS,gBAAgB,EAAE,qBAAqB,iBAAiB,kBAAkB,SAAS,GAAyB;AAC1H,QAAM,QAAQ;AAAA,IACZ,OAAO;AAAA,MACL,qBAAqB,uBAAuB,sBAAsB;AAAA,MAClE,iBAAiB,mBAAmB,sBAAsB;AAAA,MAC1D,kBAAkB,oBAAoB,sBAAsB;AAAA,IAC9D;AAAA,IACA,CAAC,qBAAqB,iBAAiB,gBAAgB;AAAA,EACzD;AACA,SAAO,oBAAC,oBAAoB,UAApB,EAA6B,OAAe,UAAS;AAC/D;AAEO,SAAS,kBAAgC;AAC9C,SAAO,WAAW,mBAAmB;AACvC;AAGO,SAAS,uBAAuB,EAAE,SAAS,GAAgC;AAChF,QAAM,UAAU,gBAAgB,EAAE;AAClC,SAAO,oBAAC,WAAS,UAAS;AAC5B;;;AChDA,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB,yBAAyB;AACrD;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAiD;AAE1D,IAAM,cAAc;AAGb,SAAS,wBAAwB,O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