@ai-matrx/summon 0.1.7 → 0.1.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +15 -2
  2. package/dist/gate-DUvE-Cc1.d.cts +399 -0
  3. package/dist/gate-DUvE-Cc1.d.ts +399 -0
  4. package/dist/handles.cjs +1 -0
  5. package/dist/handles.cjs.map +1 -1
  6. package/dist/handles.d.cts +3 -61
  7. package/dist/handles.d.ts +3 -61
  8. package/dist/handles.js +1 -0
  9. package/dist/handles.js.map +1 -1
  10. package/dist/helpers-2NY1ha0V.d.cts +63 -0
  11. package/dist/helpers-2NY1ha0V.d.ts +63 -0
  12. package/dist/index.cjs +194 -159
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +9 -355
  15. package/dist/index.d.ts +9 -355
  16. package/dist/index.js +200 -165
  17. package/dist/index.js.map +1 -1
  18. package/dist/instanceBody-CgZAFnic.d.cts +23 -0
  19. package/dist/instanceBody-CgZAFnic.d.ts +23 -0
  20. package/dist/open.cjs +408 -0
  21. package/dist/open.cjs.map +1 -0
  22. package/dist/open.d.cts +22 -0
  23. package/dist/open.d.ts +22 -0
  24. package/dist/open.js +375 -0
  25. package/dist/open.js.map +1 -0
  26. package/dist/react.cjs +249 -352
  27. package/dist/react.cjs.map +1 -1
  28. package/dist/react.d.cts +11 -151
  29. package/dist/react.d.ts +11 -151
  30. package/dist/react.js +210 -306
  31. package/dist/react.js.map +1 -1
  32. package/dist/root.cjs +277 -0
  33. package/dist/root.cjs.map +1 -0
  34. package/dist/root.d.cts +175 -0
  35. package/dist/root.d.ts +175 -0
  36. package/dist/root.js +254 -0
  37. package/dist/root.js.map +1 -0
  38. package/dist/window-host.cjs +11 -2
  39. package/dist/window-host.cjs.map +1 -1
  40. package/dist/window-host.d.cts +1 -0
  41. package/dist/window-host.d.ts +1 -0
  42. package/dist/window-host.js +11 -2
  43. package/dist/window-host.js.map +1 -1
  44. package/dist/window.cjs +2 -1
  45. package/dist/window.cjs.map +1 -1
  46. package/dist/window.d.cts +3 -2
  47. package/dist/window.d.ts +3 -2
  48. package/dist/window.js +2 -1
  49. package/dist/window.js.map +1 -1
  50. package/package.json +28 -5
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/root.ts","../src/root/SummonRoot.tsx","../src/root/context.ts","../src/root/host.ts","../src/root/storeHooks.ts","../src/root/defineOverlay.tsx","../src/root/dispatchers.ts","../src/root/emit.ts","../src/root/instance.ts"],"sourcesContent":["// @ai-matrx/summon/root — the light React half: `<SummonRoot>` (store + host settings, nothing\n// heavy), the store hooks, `defineOverlay` (openers, Controller, open/close hooks, emitter) and the\n// instance context. Importing it never loads a slice, the host, a window or the handles registry.\nexport { SummonRoot, type SummonRootProps } from \"./root/SummonRoot\";\nexport { SummonStoreContext, SummonPortsContext } from \"./root/context\";\nexport {\n configureSummonHost,\n getSummonHostConfig,\n getSummonHostPorts,\n getSummonHostVersion,\n type SummonHostConfig,\n type SummonHostWindows,\n type OverlayRenderContext,\n type OverlayErrorExtrasContext,\n} from \"./root/host\";\nexport {\n useSummonSelector,\n useSummonDispatch,\n useSummonStore,\n useSummonPorts,\n useOptionalSummonPorts,\n useOptionalSummonStore,\n type SummonReactDispatch,\n type SummonReactStore,\n} from \"./root/storeHooks\";\nexport {\n defineOverlay,\n CALLBACK_GROUP_KEY,\n type OverlayDefinition,\n type OverlaySpec,\n type HostableOverlay,\n type OverlayHandle,\n type OverlayOpener,\n type OverlayOpenOptions,\n type OverlayControllerProps,\n type OverlayEmitter,\n type OverlayEventMap,\n type OverlayHandlers,\n} from \"./root/defineOverlay\";\nexport { newInstanceId, dispatchOpen, dispatchClose } from \"./root/dispatchers\";\nexport { OverlayInstanceContext, useOverlayInstance, useOptionalOverlayInstance, type OverlayInstanceContextValue } from \"./root/instance\";\nexport { registerOverlayEmitter, emitOverlayEventLight } from \"./root/emit\";\n","// `<SummonRoot>` — the only summon component a host mounts at its root, and it does next to\n// nothing: it hands the host's store to the summon context (so every opener works at once) and\n// records the host's settings. Nothing heavy loads here. The host's runtime component (tray sync,\n// router bridge — whatever only matters once windows exist) is fetched and mounted the moment the\n// summon core installs: on the first open, a page's own WindowPanel, a link, or saved windows.\n\nimport { lazy, Suspense, useEffect, useState, useSyncExternalStore, type ComponentType, type ReactNode } from \"react\";\nimport { Provider } from \"react-redux\";\nimport type { Store } from \"@reduxjs/toolkit\";\nimport { isSummonInstalled, subscribeSummonInstalled } from \"@ai-matrx/summon/open\";\nimport { SummonStoreContext } from \"./context\";\nimport { configureSummonHost, type SummonHostConfig } from \"./host\";\n\nexport interface SummonRootProps extends SummonHostConfig {\n /** The host store, with the gate (`createSummonGate`) in its middleware chain. */\n readonly store: Store<unknown>;\n /** Mounted once the summon core is installed; one import() of the host's whole runtime set. */\n readonly runtime?: () => Promise<{ default: ComponentType }>;\n readonly children?: ReactNode;\n}\n\nconst serverSnapshot = () => false;\n\nexport function SummonRoot({ store, runtime, children, ports, renderWrapper, errorReportExtras, windows }: SummonRootProps) {\n // Settings are recorded before the first child renders (a page's WindowPanel may read them).\n const [config] = useState<SummonHostConfig>(() => {\n const initial = { ports, renderWrapper, errorReportExtras, windows };\n configureSummonHost(initial);\n return initial;\n });\n useEffect(() => {\n if (config.ports === ports && config.renderWrapper === renderWrapper && config.errorReportExtras === errorReportExtras && config.windows === windows) return;\n configureSummonHost({ ports, renderWrapper, errorReportExtras, windows });\n }, [config, ports, renderWrapper, errorReportExtras, windows]);\n\n const installed = useSyncExternalStore(subscribeSummonInstalled, isSummonInstalled, serverSnapshot);\n const [Runtime] = useState(() => (runtime ? lazy(runtime) : null));\n\n return (\n <Provider store={store} context={SummonStoreContext}>\n {children}\n {installed && Runtime ? (\n <Suspense fallback={null}>\n <Runtime />\n </Suspense>\n ) : null}\n </Provider>\n );\n}\n","// The contexts every summon section reads, light enough for the root: the overlays store rides\n// its OWN react-redux context (chat-package pattern), so a private overlays store never collides\n// with a host's store and a host that hands its one store to `<SummonRoot>` simply passes it in.\nimport { createContext } from \"react\";\nimport type { ReactReduxContextValue } from \"react-redux\";\nimport type { SummonPorts } from \"@ai-matrx/summon/open\";\n\nexport const SummonStoreContext = createContext<ReactReduxContextValue | null>(null);\nSummonStoreContext.displayName = \"SummonStoreContext\";\n\nexport const SummonPortsContext = createContext<SummonPorts | null>(null);\nSummonPortsContext.displayName = \"SummonPortsContext\";\n","// The host's settings, configured ONCE at the root (`<SummonRoot>`) and read wherever a provider\n// is absent: a WindowPanel rendered by a page, the lazily loaded host, links and persistence. A\n// heavy `<SummonProvider>` still overrides them for its subtree (a package's own bare host).\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\nimport { resolvePorts, type SummonPorts } from \"@ai-matrx/summon/open\";\nimport type { ComponentType, ReactNode } from \"react\";\n\n/** One rendered overlay instance, as the host wrapper and error extras see it. */\nexport interface OverlayRenderContext {\n readonly overlayId: string;\n readonly instanceId: string;\n readonly instanceKey: string;\n readonly label: string;\n}\n\nexport interface OverlayErrorExtrasContext extends OverlayRenderContext {\n readonly error: unknown;\n readonly componentStack: string | null;\n}\n\nexport interface SummonHostWindows {\n readonly escapeYieldSelector?: string | undefined;\n readonly mobileTopOffset?: string | undefined;\n readonly selectionSurface?: ComponentType<{ readonly children: ReactNode }> | undefined;\n}\n\nexport interface SummonHostConfig {\n readonly ports?: Partial<SummonPorts> | undefined;\n /** Wrap every rendered overlay (AI Matrx: its surface layer boundary). */\n readonly renderWrapper?: ((node: ReactNode, context: OverlayRenderContext) => ReactNode) | undefined;\n /** Extra controls in the default error card's footer (AI Matrx: \"Copy for AI\"). */\n readonly errorReportExtras?: ((context: OverlayErrorExtrasContext) => ReactNode) | undefined;\n /** Window host options (the window section reads them when no WindowsProvider is above). */\n readonly windows?: SummonHostWindows | undefined;\n}\n\ninterface HostSlot {\n config: SummonHostConfig;\n ports: SummonPorts | null;\n version: number;\n}\n\nconst slot = (): HostSlot => globalSlot<HostSlot>(\"ai-matrx.summon.host\", () => ({ config: {}, ports: null, version: 0 }));\n\nexport function configureSummonHost(config: SummonHostConfig): void {\n const s = slot();\n if (s.config === config) return;\n s.config = config;\n s.ports = null;\n s.version += 1;\n}\n\nexport function getSummonHostConfig(): SummonHostConfig {\n return slot().config;\n}\n\n/** The configured ports, resolved over the working defaults (stable until reconfigured). */\nexport function getSummonHostPorts(): SummonPorts {\n const s = slot();\n return (s.ports ??= resolvePorts(s.config.ports));\n}\n\n/** Bumps on every reconfigure; memo keys for values derived from the host config. */\nexport function getSummonHostVersion(): number {\n return slot().version;\n}\n","// Typed hooks over the package's own store context. Every package component reads the overlays\n// store through these, never react-redux's default context, so a host's own <Provider> and the\n// overlays store never collide.\n\nimport { useContext } from \"react\";\nimport {\n createDispatchHook,\n createSelectorHook,\n createStoreHook,\n type UseDispatch,\n type UseSelector,\n type UseStore,\n} from \"react-redux\";\nimport type { Dispatch, Store, UnknownAction } from \"@reduxjs/toolkit\";\nimport type { SummonRootState } from \"@ai-matrx/summon\";\nimport type { SummonPorts } from \"@ai-matrx/summon/open\";\nimport { SummonPortsContext, SummonStoreContext } from \"./context\";\nimport { getSummonHostPorts } from \"./host\";\n\n/** Dispatch as the React section uses it: plain actions (thunks are the host's business). */\nexport type SummonReactDispatch = Dispatch<UnknownAction>;\n\n/** The store as the React section sees it: the overlays slices at their root keys (a host store has more). */\nexport type SummonReactStore = Store<SummonRootState>;\n\n/** Select from the overlays store. */\nexport const useSummonSelector: UseSelector<SummonRootState> = createSelectorHook(SummonStoreContext).withTypes<SummonRootState>();\n\n/** The overlays store's dispatch. */\nexport const useSummonDispatch: UseDispatch<SummonReactDispatch> = createDispatchHook(SummonStoreContext).withTypes<SummonReactDispatch>();\n\n/** The overlays store itself (for `getState()` inside callbacks). */\nexport const useSummonStore: UseStore<SummonReactStore> = createStoreHook(SummonStoreContext).withTypes<SummonReactStore>();\n\n/** The nearest provider's ports, else the ports configured at the root, else the working defaults. */\nexport function useSummonPorts(): SummonPorts {\n return useContext(SummonPortsContext) ?? getSummonHostPorts();\n}\n\n/** Same as `useSummonPorts` (kept for components written to work page-local). */\nexport function useOptionalSummonPorts(): SummonPorts {\n return useContext(SummonPortsContext) ?? getSummonHostPorts();\n}\n\n/**\n * The nearest provider's store, or `null` when nothing above provides one — for packages that\n * mount their own provider only when the host has none (chat's windows on a bare host).\n */\nexport function useOptionalSummonStore(): SummonReactStore | null {\n const context = useContext(SummonStoreContext);\n return context ? (context.store as unknown as SummonReactStore) : null;\n}\n","// `defineOverlay` — the declare-once API (C38 R2). One light definition per overlay carries its\n// metadata and (optionally) a lazy `render` import; the definition generates the opener hook, the declarative\n// Controller, the open/close hooks and a typed event emitter. The host renders definitions; the\n// render module is the old controller block, moved verbatim, and is fetched only when opened.\n//\n// Light by construction (the root section): no slice, no host, no handles registry. Opening goes\n// through the light creators (a gated host store loads the core on the first one); a callback-aware\n// open reserves its event channel and the handles section arrives with that first open.\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n DEFAULT_INSTANCE_ID,\n instanceKey as toInstanceKey,\n openPendingEventChannel,\n selectIsOverlayOpen,\n type InstanceKey,\n type OverlayDefinitionMeta,\n type OverlayRawData,\n type AnyOverlayMeta,\n} from \"@ai-matrx/summon/open\";\nimport type { OverlayRenderProps } from \"../react/instanceBody\";\nimport type { RenderModule } from \"../react/loaderCache\";\nimport { dispatchClose, dispatchOpen, newInstanceId } from \"./dispatchers\";\nimport { emitOverlayEventLight } from \"./emit\";\nimport { useOptionalOverlayInstance } from \"./instance\";\nimport { useSummonDispatch, useSummonSelector, type SummonReactDispatch } from \"./storeHooks\";\n\n/** Event name → payload, declared once per overlay: `defineOverlay<Data, { uploaded: Result }>()`. */\nexport type OverlayEventMap = Record<string, unknown>;\n\nexport type OverlayHandlers<Events extends OverlayEventMap> = {\n readonly [K in keyof Events]?: (payload: Events[K]) => void;\n};\n\nfunction openOverlayEventChannel<Events extends OverlayEventMap>(\n owner: InstanceKey,\n getHandlers: () => OverlayHandlers<Events> | undefined,\n): string {\n return openPendingEventChannel(owner, getHandlers as () => Readonly<Record<string, ((payload: unknown) => void) | undefined>> | undefined);\n}\n\n/** The open-data key that carries an overlay's event channel id (the old callback-group key). */\nexport const CALLBACK_GROUP_KEY = \"callbackGroupId\";\n\nexport interface OverlayHandle {\n readonly overlayId: string;\n readonly instanceId: string;\n close(): void;\n}\n\nexport interface OverlayOpenOptions<Data, Events extends OverlayEventMap> {\n readonly data?: Data;\n /** Single-instance overlays ignore it unless given; multi-instance generate one when omitted. */\n readonly instanceId?: string;\n /** Plain functions; they reach the caller through an event channel owned by the instance. */\n readonly handlers?: OverlayHandlers<Events>;\n}\n\nexport type OverlayOpener<Data, Events extends OverlayEventMap> = (options?: OverlayOpenOptions<Data, Events>) => OverlayHandle;\n\nexport type OverlayControllerProps<Data, Events extends OverlayEventMap> = Data & {\n readonly instanceId?: string;\n readonly handlers?: OverlayHandlers<Events>;\n};\n\nexport type OverlayEmitter<Events extends OverlayEventMap> = <K extends keyof Events & string>(event: K, payload: Events[K]) => void;\n\n/** What a definition file passes to `defineOverlay<Data>()(…)`. */\nexport interface OverlaySpec<Id extends string, Data, Parsed> extends OverlayDefinitionMeta<Id, Data> {\n /**\n * The lazily loaded render module. Its default export receives `OverlayRenderProps<Parsed>`.\n * Optional: a large app leaves it out and hands `<SummonHost renders={…}>` one id → import map,\n * so files that import a definition for its opener never gain an import() edge to the window\n * (the host-build law). When present it wins over the host map.\n */\n readonly render?: () => Promise<RenderModule<OverlayRenderProps<NoInfer<Parsed>>>>;\n /** Narrow raw open data once. `null` = refuse: the instance is closed with a warning. */\n readonly parse?: (raw: OverlayRawData) => Parsed | null;\n}\n\n/** The type-erased half the host renders; no data types cross this line. */\nexport interface HostableOverlay {\n readonly id: string;\n readonly label: string;\n readonly instance: \"single\" | \"multi\";\n readonly keepAlive: \"none\" | \"hidden\" | \"restore\";\n /** The metadata the core registry stores (links, window options, defaults…). */\n readonly meta: AnyOverlayMeta;\n /** The definition's own render loader (the host's `renders` map is used when absent). */\n readonly render?: (() => Promise<unknown>) | undefined;\n /** Narrows raw open data; the host builds each instance body from it on first render. */\n readonly parse?: ((raw: OverlayRawData) => unknown) | undefined;\n}\n\nexport interface OverlayDefinition<Id extends string, Data, Parsed, Events extends OverlayEventMap>\n extends Omit<OverlayDefinitionMeta<Id, Data>, \"id\" | \"instance\" | \"keepAlive\">,\n HostableOverlay {\n readonly id: Id;\n readonly render?: () => Promise<RenderModule<OverlayRenderProps<Parsed>>>;\n /** Imperative opener: `const open = def.useSummon(); open({ data })` → handle. */\n useSummon(): OverlayOpener<Data, Events>;\n /** Declarative form: opens on mount, closes on unmount, re-opens when its data changes. */\n readonly Controller: (props: OverlayControllerProps<Data, Events>) => null;\n useIsOpen(instanceId?: string): boolean;\n /** `const close = def.useClose(); close(instanceId?)`. */\n useClose(): (instanceId?: string) => void;\n /** Inside the render tree: emit a declared event to the opener's handlers. */\n useEmit(): OverlayEmitter<Events>;\n}\n\nfunction openWith<Data, Events extends OverlayEventMap>(\n dispatch: SummonReactDispatch,\n id: string,\n multi: boolean,\n options: OverlayOpenOptions<Data, Events> | undefined,\n): OverlayHandle {\n const instanceId = options?.instanceId ?? (multi ? newInstanceId(id) : DEFAULT_INSTANCE_ID);\n const key = toInstanceKey(id, instanceId);\n const data: Record<string, unknown> = {};\n const given: unknown = options?.data;\n if (typeof given === \"object\" && given !== null) Object.assign(data, given);\n const handlers = options?.handlers;\n if (handlers) data[CALLBACK_GROUP_KEY] = openOverlayEventChannel<Events>(key, () => handlers);\n dispatchOpen(dispatch, id, instanceId, data);\n return { overlayId: id, instanceId, close: () => dispatchClose(dispatch, id, instanceId) };\n}\n\n/** Stable identity for the serialisable part of Controller props (functions never reopen). */\nfunction dataSignature(data: Readonly<Record<string, unknown>>): string {\n try {\n return JSON.stringify(data, (_key, value: unknown) => (typeof value === \"function\" ? undefined : value));\n } catch {\n return String(Date.now());\n }\n}\n\n/**\n * Declare an overlay once. Curried so `Data` (and `Events`) are named while the id and the\n * parsed-data type are inferred:\n *\n * export const notesWindow = defineOverlay<NotesWindowData>()({\n * id: \"notesWindow\", label: \"Notes\", render: () => import(\"./notesWindow.render\"),\n * });\n */\nexport function defineOverlay<Data extends object = Record<string, never>, Events extends OverlayEventMap = Record<never, never>>() {\n return function define<const Id extends string, Parsed = OverlayRawData>(\n spec: OverlaySpec<Id, Data, Parsed>,\n ): OverlayDefinition<Id, Data, Parsed, Events> {\n const id = spec.id;\n const multi = spec.instance === \"multi\";\n // The registry stores every definition's metadata under one erased type (AnyOverlayMeta).\n const meta: AnyOverlayMeta = spec;\n\n function useSummon(): OverlayOpener<Data, Events> {\n const dispatch = useSummonDispatch();\n return useCallback((options) => openWith(dispatch, id, multi, options), [dispatch]);\n }\n\n function useIsOpen(instanceId: string = DEFAULT_INSTANCE_ID): boolean {\n return useSummonSelector((state) => selectIsOverlayOpen(state, id, instanceId));\n }\n\n function useClose(): (instanceId?: string) => void {\n const dispatch = useSummonDispatch();\n return useCallback((instanceId?: string) => dispatchClose(dispatch, id, instanceId ?? DEFAULT_INSTANCE_ID), [dispatch]);\n }\n\n function useEmit(): OverlayEmitter<Events> {\n const instance = useOptionalOverlayInstance();\n const channelId = instance?.overlayId === id ? instance.rawData?.[CALLBACK_GROUP_KEY] : undefined;\n return useCallback<OverlayEmitter<Events>>(\n (event, payload) => {\n if (typeof channelId === \"string\") emitOverlayEventLight(channelId, event, payload);\n },\n [channelId],\n );\n }\n\n function Controller(props: OverlayControllerProps<Data, Events>): null {\n const dispatch = useSummonDispatch();\n const [ownInstanceId] = useState(() => (multi ? newInstanceId(id) : DEFAULT_INSTANCE_ID));\n const instanceId = props.instanceId ?? ownInstanceId;\n // Latest handlers, read at emit time: a new function identity never reopens the overlay.\n const handlersRef = useRef(props.handlers);\n handlersRef.current = props.handlers;\n const hasHandlers = props.handlers !== undefined;\n\n const data = useMemo(() => {\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(props)) {\n if (key !== \"instanceId\" && key !== \"handlers\") out[key] = value;\n }\n return out;\n }, [props]);\n const signature = dataSignature(data);\n const dataRef = useRef(data);\n dataRef.current = data;\n\n useEffect(() => {\n const key: InstanceKey = toInstanceKey(id, instanceId);\n const open: Record<string, unknown> = { ...dataRef.current };\n if (hasHandlers) open[CALLBACK_GROUP_KEY] = openOverlayEventChannel<Events>(key, () => handlersRef.current);\n dispatchOpen(dispatch, id, instanceId, open);\n return () => dispatchClose(dispatch, id, instanceId);\n }, [dispatch, instanceId, signature, hasHandlers]);\n\n return null;\n }\n Controller.displayName = `${id}Controller`;\n\n return {\n ...spec,\n id,\n label: spec.label,\n instance: multi ? \"multi\" : \"single\",\n keepAlive: spec.keepAlive ?? \"none\",\n meta,\n useSummon,\n Controller,\n useIsOpen,\n useClose,\n useEmit,\n };\n };\n}\n","// The one place a definition turns an untyped (string) overlay id into the typed action creators.\n// Inside the package `OverlayId` is `string`; a host that augments the registry narrows it to its\n// ids, and these keep compiling there because definitions carry their own id.\n\nimport { closeOverlay, openOverlay, DEFAULT_INSTANCE_ID, type OverlayDataOf, type OverlayId } from \"@ai-matrx/summon/open\";\nimport type { SummonReactDispatch } from \"./storeHooks\";\n\nexport function newInstanceId(overlayId: string): string {\n return `${overlayId}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n}\n\nexport function dispatchOpen(dispatch: SummonReactDispatch, overlayId: string, instanceId: string, data: unknown): void {\n dispatch(\n openOverlay({\n overlayId: overlayId as OverlayId,\n instanceId,\n data: (data ?? null) as OverlayDataOf<OverlayId> | null,\n }),\n );\n}\n\nexport function dispatchClose(dispatch: SummonReactDispatch, overlayId: string, instanceId: string = DEFAULT_INSTANCE_ID): void {\n dispatch(closeOverlay({ overlayId: overlayId as OverlayId, instanceId }));\n}\n","// Emitting an overlay event from inside its render tree. The render tree has the handles registry\n// loaded (the react section registers its synchronous emitter on evaluation); before that, the\n// emit waits for the one handles import.\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\nimport { materializePendingChannels } from \"@ai-matrx/summon/open\";\n\ntype Emitter = (channelId: string, type: string, payload: unknown) => void;\n\nconst slot = (): { emit: Emitter | null } => globalSlot(\"ai-matrx.summon.emitter\", () => ({ emit: null as Emitter | null }));\n\n/** The react section installs the synchronous emitter (it holds handles statically). */\nexport function registerOverlayEmitter(emit: Emitter): void {\n slot().emit = emit;\n}\n\nexport function emitOverlayEventLight(channelId: string, type: string, payload: unknown): void {\n const emit = slot().emit;\n if (emit) {\n emit(channelId, type, payload);\n return;\n }\n void import(\"@ai-matrx/summon/handles\").then(({ createEventChannel, getEventChannel }) => {\n materializePendingChannels(createEventChannel);\n getEventChannel<{ type: string; payload: unknown }>(channelId)?.emit({ type, payload });\n });\n}\n","// The context every rendered overlay instance provides to its subtree, and the hooks that read who\n// it is. Light: a definition's `useEmit` reads it; the saved-state hook stays in `./react`.\nimport { createContext, useContext } from \"react\";\nimport type { InstanceKey, OverlayRawData } from \"@ai-matrx/summon/open\";\n\nexport interface OverlayInstanceContextValue {\n readonly overlayId: string;\n readonly instanceId: string;\n readonly instanceKey: InstanceKey;\n readonly close: () => void;\n readonly hidden: boolean;\n /** The open data as it arrived (pre-parse); event emitters read their channel id from it. */\n readonly rawData: OverlayRawData;\n}\n\nexport const OverlayInstanceContext = createContext<OverlayInstanceContextValue | null>(null);\nOverlayInstanceContext.displayName = \"OverlayInstanceContext\";\n\n/** The open instance this component renders inside. Throws outside an overlay. */\nexport function useOverlayInstance(): OverlayInstanceContextValue {\n const value = useContext(OverlayInstanceContext);\n if (!value) throw new Error(\"[summon] useOverlayInstance() was called outside a rendered overlay.\");\n return value;\n}\n\n/** Same as `useOverlayInstance`, but `null` outside an overlay. */\nexport function useOptionalOverlayInstance(): OverlayInstanceContextValue | null {\n return useContext(OverlayInstanceContext);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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AM,QAAQ;AACzC,kBAAY,UAAU,MAAM;AAC5B,YAAM,cAAc,MAAM,aAAa;AAEvC,YAAM,WAAO,uBAAQ,MAAM;AACzB,cAAM,MAA+B,CAAC;AACtC,mBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,cAAI,QAAQ,gBAAgB,QAAQ,WAAY,KAAI,GAAG,IAAI;AAAA,QAC7D;AACA,eAAO;AAAA,MACT,GAAG,CAAC,KAAK,CAAC;AACV,YAAM,YAAY,cAAc,IAAI;AACpC,YAAM,cAAU,sBAAO,IAAI;AAC3B,cAAQ,UAAU;AAElB,mCAAU,MAAM;AACd,cAAM,UAAmB,aAAAA,aAAc,IAAI,UAAU;AACrD,cAAM,OAAgC,EAAE,GAAG,QAAQ,QAAQ;AAC3D,YAAI,YAAa,MAAK,kBAAkB,IAAI,wBAAgC,KAAK,MAAM,YAAY,OAAO;AAC1G,qBAAa,UAAU,IAAI,YAAY,IAAI;AAC3C,eAAO,MAAM,cAAc,UAAU,IAAI,UAAU;AAAA,MACrD,GAAG,CAAC,UAAU,YAAY,WAAW,WAAW,CAAC;AAEjD,aAAO;AAAA,IACT;AACA,eAAW,cAAc,GAAG,EAAE;AAE9B,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,MACA,OAAO,KAAK;AAAA,MACZ,UAAU,QAAQ,UAAU;AAAA,MAC5B,WAAW,KAAK,aAAa;AAAA,MAC7B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":["import_react","import_open","import_react","import_react_redux","import_react","import_open","import_open","import_global_slot","import_open","slot","import_react","toInstanceKey"]}
@@ -0,0 +1,175 @@
1
+ import * as react from 'react';
2
+ import { ReactNode, ComponentType } from 'react';
3
+ import * as _reduxjs_toolkit from '@reduxjs/toolkit';
4
+ import { Store, Dispatch, UnknownAction } from '@reduxjs/toolkit';
5
+ import { SummonPorts, AnyOverlayMeta, OverlayRawData, OverlayDefinitionMeta, InstanceKey } from '@ai-matrx/summon/open';
6
+ import { ReactReduxContextValue, UseDispatch, UseSelector, UseStore } from 'react-redux';
7
+ import { SummonRootState } from '@ai-matrx/summon';
8
+ import { a as RenderModule, O as OverlayRenderProps } from './instanceBody-CgZAFnic.cjs';
9
+
10
+ /** One rendered overlay instance, as the host wrapper and error extras see it. */
11
+ interface OverlayRenderContext {
12
+ readonly overlayId: string;
13
+ readonly instanceId: string;
14
+ readonly instanceKey: string;
15
+ readonly label: string;
16
+ }
17
+ interface OverlayErrorExtrasContext extends OverlayRenderContext {
18
+ readonly error: unknown;
19
+ readonly componentStack: string | null;
20
+ }
21
+ interface SummonHostWindows {
22
+ readonly escapeYieldSelector?: string | undefined;
23
+ readonly mobileTopOffset?: string | undefined;
24
+ readonly selectionSurface?: ComponentType<{
25
+ readonly children: ReactNode;
26
+ }> | undefined;
27
+ }
28
+ interface SummonHostConfig {
29
+ readonly ports?: Partial<SummonPorts> | undefined;
30
+ /** Wrap every rendered overlay (AI Matrx: its surface layer boundary). */
31
+ readonly renderWrapper?: ((node: ReactNode, context: OverlayRenderContext) => ReactNode) | undefined;
32
+ /** Extra controls in the default error card's footer (AI Matrx: "Copy for AI"). */
33
+ readonly errorReportExtras?: ((context: OverlayErrorExtrasContext) => ReactNode) | undefined;
34
+ /** Window host options (the window section reads them when no WindowsProvider is above). */
35
+ readonly windows?: SummonHostWindows | undefined;
36
+ }
37
+ declare function configureSummonHost(config: SummonHostConfig): void;
38
+ declare function getSummonHostConfig(): SummonHostConfig;
39
+ /** The configured ports, resolved over the working defaults (stable until reconfigured). */
40
+ declare function getSummonHostPorts(): SummonPorts;
41
+ /** Bumps on every reconfigure; memo keys for values derived from the host config. */
42
+ declare function getSummonHostVersion(): number;
43
+
44
+ interface SummonRootProps extends SummonHostConfig {
45
+ /** The host store, with the gate (`createSummonGate`) in its middleware chain. */
46
+ readonly store: Store<unknown>;
47
+ /** Mounted once the summon core is installed; one import() of the host's whole runtime set. */
48
+ readonly runtime?: () => Promise<{
49
+ default: ComponentType;
50
+ }>;
51
+ readonly children?: ReactNode;
52
+ }
53
+ declare function SummonRoot({ store, runtime, children, ports, renderWrapper, errorReportExtras, windows }: SummonRootProps): react.JSX.Element;
54
+
55
+ declare const SummonStoreContext: react.Context<ReactReduxContextValue<any, _reduxjs_toolkit.UnknownAction> | null>;
56
+ declare const SummonPortsContext: react.Context<SummonPorts | null>;
57
+
58
+ /** Dispatch as the React section uses it: plain actions (thunks are the host's business). */
59
+ type SummonReactDispatch = Dispatch<UnknownAction>;
60
+ /** The store as the React section sees it: the overlays slices at their root keys (a host store has more). */
61
+ type SummonReactStore = Store<SummonRootState>;
62
+ /** Select from the overlays store. */
63
+ declare const useSummonSelector: UseSelector<SummonRootState>;
64
+ /** The overlays store's dispatch. */
65
+ declare const useSummonDispatch: UseDispatch<SummonReactDispatch>;
66
+ /** The overlays store itself (for `getState()` inside callbacks). */
67
+ declare const useSummonStore: UseStore<SummonReactStore>;
68
+ /** The nearest provider's ports, else the ports configured at the root, else the working defaults. */
69
+ declare function useSummonPorts(): SummonPorts;
70
+ /** Same as `useSummonPorts` (kept for components written to work page-local). */
71
+ declare function useOptionalSummonPorts(): SummonPorts;
72
+ /**
73
+ * The nearest provider's store, or `null` when nothing above provides one — for packages that
74
+ * mount their own provider only when the host has none (chat's windows on a bare host).
75
+ */
76
+ declare function useOptionalSummonStore(): SummonReactStore | null;
77
+
78
+ /** Event name → payload, declared once per overlay: `defineOverlay<Data, { uploaded: Result }>()`. */
79
+ type OverlayEventMap = Record<string, unknown>;
80
+ type OverlayHandlers<Events extends OverlayEventMap> = {
81
+ readonly [K in keyof Events]?: (payload: Events[K]) => void;
82
+ };
83
+ /** The open-data key that carries an overlay's event channel id (the old callback-group key). */
84
+ declare const CALLBACK_GROUP_KEY = "callbackGroupId";
85
+ interface OverlayHandle {
86
+ readonly overlayId: string;
87
+ readonly instanceId: string;
88
+ close(): void;
89
+ }
90
+ interface OverlayOpenOptions<Data, Events extends OverlayEventMap> {
91
+ readonly data?: Data;
92
+ /** Single-instance overlays ignore it unless given; multi-instance generate one when omitted. */
93
+ readonly instanceId?: string;
94
+ /** Plain functions; they reach the caller through an event channel owned by the instance. */
95
+ readonly handlers?: OverlayHandlers<Events>;
96
+ }
97
+ type OverlayOpener<Data, Events extends OverlayEventMap> = (options?: OverlayOpenOptions<Data, Events>) => OverlayHandle;
98
+ type OverlayControllerProps<Data, Events extends OverlayEventMap> = Data & {
99
+ readonly instanceId?: string;
100
+ readonly handlers?: OverlayHandlers<Events>;
101
+ };
102
+ type OverlayEmitter<Events extends OverlayEventMap> = <K extends keyof Events & string>(event: K, payload: Events[K]) => void;
103
+ /** What a definition file passes to `defineOverlay<Data>()(…)`. */
104
+ interface OverlaySpec<Id extends string, Data, Parsed> extends OverlayDefinitionMeta<Id, Data> {
105
+ /**
106
+ * The lazily loaded render module. Its default export receives `OverlayRenderProps<Parsed>`.
107
+ * Optional: a large app leaves it out and hands `<SummonHost renders={…}>` one id → import map,
108
+ * so files that import a definition for its opener never gain an import() edge to the window
109
+ * (the host-build law). When present it wins over the host map.
110
+ */
111
+ readonly render?: () => Promise<RenderModule<OverlayRenderProps<NoInfer<Parsed>>>>;
112
+ /** Narrow raw open data once. `null` = refuse: the instance is closed with a warning. */
113
+ readonly parse?: (raw: OverlayRawData) => Parsed | null;
114
+ }
115
+ /** The type-erased half the host renders; no data types cross this line. */
116
+ interface HostableOverlay {
117
+ readonly id: string;
118
+ readonly label: string;
119
+ readonly instance: "single" | "multi";
120
+ readonly keepAlive: "none" | "hidden" | "restore";
121
+ /** The metadata the core registry stores (links, window options, defaults…). */
122
+ readonly meta: AnyOverlayMeta;
123
+ /** The definition's own render loader (the host's `renders` map is used when absent). */
124
+ readonly render?: (() => Promise<unknown>) | undefined;
125
+ /** Narrows raw open data; the host builds each instance body from it on first render. */
126
+ readonly parse?: ((raw: OverlayRawData) => unknown) | undefined;
127
+ }
128
+ interface OverlayDefinition<Id extends string, Data, Parsed, Events extends OverlayEventMap> extends Omit<OverlayDefinitionMeta<Id, Data>, "id" | "instance" | "keepAlive">, HostableOverlay {
129
+ readonly id: Id;
130
+ readonly render?: () => Promise<RenderModule<OverlayRenderProps<Parsed>>>;
131
+ /** Imperative opener: `const open = def.useSummon(); open({ data })` → handle. */
132
+ useSummon(): OverlayOpener<Data, Events>;
133
+ /** Declarative form: opens on mount, closes on unmount, re-opens when its data changes. */
134
+ readonly Controller: (props: OverlayControllerProps<Data, Events>) => null;
135
+ useIsOpen(instanceId?: string): boolean;
136
+ /** `const close = def.useClose(); close(instanceId?)`. */
137
+ useClose(): (instanceId?: string) => void;
138
+ /** Inside the render tree: emit a declared event to the opener's handlers. */
139
+ useEmit(): OverlayEmitter<Events>;
140
+ }
141
+ /**
142
+ * Declare an overlay once. Curried so `Data` (and `Events`) are named while the id and the
143
+ * parsed-data type are inferred:
144
+ *
145
+ * export const notesWindow = defineOverlay<NotesWindowData>()({
146
+ * id: "notesWindow", label: "Notes", render: () => import("./notesWindow.render"),
147
+ * });
148
+ */
149
+ declare function defineOverlay<Data extends object = Record<string, never>, Events extends OverlayEventMap = Record<never, never>>(): <const Id extends string, Parsed = OverlayRawData>(spec: OverlaySpec<Id, Data, Parsed>) => OverlayDefinition<Id, Data, Parsed, Events>;
150
+
151
+ declare function newInstanceId(overlayId: string): string;
152
+ declare function dispatchOpen(dispatch: SummonReactDispatch, overlayId: string, instanceId: string, data: unknown): void;
153
+ declare function dispatchClose(dispatch: SummonReactDispatch, overlayId: string, instanceId?: string): void;
154
+
155
+ interface OverlayInstanceContextValue {
156
+ readonly overlayId: string;
157
+ readonly instanceId: string;
158
+ readonly instanceKey: InstanceKey;
159
+ readonly close: () => void;
160
+ readonly hidden: boolean;
161
+ /** The open data as it arrived (pre-parse); event emitters read their channel id from it. */
162
+ readonly rawData: OverlayRawData;
163
+ }
164
+ declare const OverlayInstanceContext: react.Context<OverlayInstanceContextValue | null>;
165
+ /** The open instance this component renders inside. Throws outside an overlay. */
166
+ declare function useOverlayInstance(): OverlayInstanceContextValue;
167
+ /** Same as `useOverlayInstance`, but `null` outside an overlay. */
168
+ declare function useOptionalOverlayInstance(): OverlayInstanceContextValue | null;
169
+
170
+ type Emitter = (channelId: string, type: string, payload: unknown) => void;
171
+ /** The react section installs the synchronous emitter (it holds handles statically). */
172
+ declare function registerOverlayEmitter(emit: Emitter): void;
173
+ declare function emitOverlayEventLight(channelId: string, type: string, payload: unknown): void;
174
+
175
+ export { CALLBACK_GROUP_KEY, type HostableOverlay, type OverlayControllerProps, type OverlayDefinition, type OverlayEmitter, type OverlayErrorExtrasContext, type OverlayEventMap, type OverlayHandle, type OverlayHandlers, OverlayInstanceContext, type OverlayInstanceContextValue, type OverlayOpenOptions, type OverlayOpener, type OverlayRenderContext, type OverlaySpec, type SummonHostConfig, type SummonHostWindows, SummonPortsContext, type SummonReactDispatch, type SummonReactStore, SummonRoot, type SummonRootProps, SummonStoreContext, configureSummonHost, defineOverlay, dispatchClose, dispatchOpen, emitOverlayEventLight, getSummonHostConfig, getSummonHostPorts, getSummonHostVersion, newInstanceId, registerOverlayEmitter, useOptionalOverlayInstance, useOptionalSummonPorts, useOptionalSummonStore, useOverlayInstance, useSummonDispatch, useSummonPorts, useSummonSelector, useSummonStore };
package/dist/root.d.ts ADDED
@@ -0,0 +1,175 @@
1
+ import * as react from 'react';
2
+ import { ReactNode, ComponentType } from 'react';
3
+ import * as _reduxjs_toolkit from '@reduxjs/toolkit';
4
+ import { Store, Dispatch, UnknownAction } from '@reduxjs/toolkit';
5
+ import { SummonPorts, AnyOverlayMeta, OverlayRawData, OverlayDefinitionMeta, InstanceKey } from '@ai-matrx/summon/open';
6
+ import { ReactReduxContextValue, UseDispatch, UseSelector, UseStore } from 'react-redux';
7
+ import { SummonRootState } from '@ai-matrx/summon';
8
+ import { a as RenderModule, O as OverlayRenderProps } from './instanceBody-CgZAFnic.js';
9
+
10
+ /** One rendered overlay instance, as the host wrapper and error extras see it. */
11
+ interface OverlayRenderContext {
12
+ readonly overlayId: string;
13
+ readonly instanceId: string;
14
+ readonly instanceKey: string;
15
+ readonly label: string;
16
+ }
17
+ interface OverlayErrorExtrasContext extends OverlayRenderContext {
18
+ readonly error: unknown;
19
+ readonly componentStack: string | null;
20
+ }
21
+ interface SummonHostWindows {
22
+ readonly escapeYieldSelector?: string | undefined;
23
+ readonly mobileTopOffset?: string | undefined;
24
+ readonly selectionSurface?: ComponentType<{
25
+ readonly children: ReactNode;
26
+ }> | undefined;
27
+ }
28
+ interface SummonHostConfig {
29
+ readonly ports?: Partial<SummonPorts> | undefined;
30
+ /** Wrap every rendered overlay (AI Matrx: its surface layer boundary). */
31
+ readonly renderWrapper?: ((node: ReactNode, context: OverlayRenderContext) => ReactNode) | undefined;
32
+ /** Extra controls in the default error card's footer (AI Matrx: "Copy for AI"). */
33
+ readonly errorReportExtras?: ((context: OverlayErrorExtrasContext) => ReactNode) | undefined;
34
+ /** Window host options (the window section reads them when no WindowsProvider is above). */
35
+ readonly windows?: SummonHostWindows | undefined;
36
+ }
37
+ declare function configureSummonHost(config: SummonHostConfig): void;
38
+ declare function getSummonHostConfig(): SummonHostConfig;
39
+ /** The configured ports, resolved over the working defaults (stable until reconfigured). */
40
+ declare function getSummonHostPorts(): SummonPorts;
41
+ /** Bumps on every reconfigure; memo keys for values derived from the host config. */
42
+ declare function getSummonHostVersion(): number;
43
+
44
+ interface SummonRootProps extends SummonHostConfig {
45
+ /** The host store, with the gate (`createSummonGate`) in its middleware chain. */
46
+ readonly store: Store<unknown>;
47
+ /** Mounted once the summon core is installed; one import() of the host's whole runtime set. */
48
+ readonly runtime?: () => Promise<{
49
+ default: ComponentType;
50
+ }>;
51
+ readonly children?: ReactNode;
52
+ }
53
+ declare function SummonRoot({ store, runtime, children, ports, renderWrapper, errorReportExtras, windows }: SummonRootProps): react.JSX.Element;
54
+
55
+ declare const SummonStoreContext: react.Context<ReactReduxContextValue<any, _reduxjs_toolkit.UnknownAction> | null>;
56
+ declare const SummonPortsContext: react.Context<SummonPorts | null>;
57
+
58
+ /** Dispatch as the React section uses it: plain actions (thunks are the host's business). */
59
+ type SummonReactDispatch = Dispatch<UnknownAction>;
60
+ /** The store as the React section sees it: the overlays slices at their root keys (a host store has more). */
61
+ type SummonReactStore = Store<SummonRootState>;
62
+ /** Select from the overlays store. */
63
+ declare const useSummonSelector: UseSelector<SummonRootState>;
64
+ /** The overlays store's dispatch. */
65
+ declare const useSummonDispatch: UseDispatch<SummonReactDispatch>;
66
+ /** The overlays store itself (for `getState()` inside callbacks). */
67
+ declare const useSummonStore: UseStore<SummonReactStore>;
68
+ /** The nearest provider's ports, else the ports configured at the root, else the working defaults. */
69
+ declare function useSummonPorts(): SummonPorts;
70
+ /** Same as `useSummonPorts` (kept for components written to work page-local). */
71
+ declare function useOptionalSummonPorts(): SummonPorts;
72
+ /**
73
+ * The nearest provider's store, or `null` when nothing above provides one — for packages that
74
+ * mount their own provider only when the host has none (chat's windows on a bare host).
75
+ */
76
+ declare function useOptionalSummonStore(): SummonReactStore | null;
77
+
78
+ /** Event name → payload, declared once per overlay: `defineOverlay<Data, { uploaded: Result }>()`. */
79
+ type OverlayEventMap = Record<string, unknown>;
80
+ type OverlayHandlers<Events extends OverlayEventMap> = {
81
+ readonly [K in keyof Events]?: (payload: Events[K]) => void;
82
+ };
83
+ /** The open-data key that carries an overlay's event channel id (the old callback-group key). */
84
+ declare const CALLBACK_GROUP_KEY = "callbackGroupId";
85
+ interface OverlayHandle {
86
+ readonly overlayId: string;
87
+ readonly instanceId: string;
88
+ close(): void;
89
+ }
90
+ interface OverlayOpenOptions<Data, Events extends OverlayEventMap> {
91
+ readonly data?: Data;
92
+ /** Single-instance overlays ignore it unless given; multi-instance generate one when omitted. */
93
+ readonly instanceId?: string;
94
+ /** Plain functions; they reach the caller through an event channel owned by the instance. */
95
+ readonly handlers?: OverlayHandlers<Events>;
96
+ }
97
+ type OverlayOpener<Data, Events extends OverlayEventMap> = (options?: OverlayOpenOptions<Data, Events>) => OverlayHandle;
98
+ type OverlayControllerProps<Data, Events extends OverlayEventMap> = Data & {
99
+ readonly instanceId?: string;
100
+ readonly handlers?: OverlayHandlers<Events>;
101
+ };
102
+ type OverlayEmitter<Events extends OverlayEventMap> = <K extends keyof Events & string>(event: K, payload: Events[K]) => void;
103
+ /** What a definition file passes to `defineOverlay<Data>()(…)`. */
104
+ interface OverlaySpec<Id extends string, Data, Parsed> extends OverlayDefinitionMeta<Id, Data> {
105
+ /**
106
+ * The lazily loaded render module. Its default export receives `OverlayRenderProps<Parsed>`.
107
+ * Optional: a large app leaves it out and hands `<SummonHost renders={…}>` one id → import map,
108
+ * so files that import a definition for its opener never gain an import() edge to the window
109
+ * (the host-build law). When present it wins over the host map.
110
+ */
111
+ readonly render?: () => Promise<RenderModule<OverlayRenderProps<NoInfer<Parsed>>>>;
112
+ /** Narrow raw open data once. `null` = refuse: the instance is closed with a warning. */
113
+ readonly parse?: (raw: OverlayRawData) => Parsed | null;
114
+ }
115
+ /** The type-erased half the host renders; no data types cross this line. */
116
+ interface HostableOverlay {
117
+ readonly id: string;
118
+ readonly label: string;
119
+ readonly instance: "single" | "multi";
120
+ readonly keepAlive: "none" | "hidden" | "restore";
121
+ /** The metadata the core registry stores (links, window options, defaults…). */
122
+ readonly meta: AnyOverlayMeta;
123
+ /** The definition's own render loader (the host's `renders` map is used when absent). */
124
+ readonly render?: (() => Promise<unknown>) | undefined;
125
+ /** Narrows raw open data; the host builds each instance body from it on first render. */
126
+ readonly parse?: ((raw: OverlayRawData) => unknown) | undefined;
127
+ }
128
+ interface OverlayDefinition<Id extends string, Data, Parsed, Events extends OverlayEventMap> extends Omit<OverlayDefinitionMeta<Id, Data>, "id" | "instance" | "keepAlive">, HostableOverlay {
129
+ readonly id: Id;
130
+ readonly render?: () => Promise<RenderModule<OverlayRenderProps<Parsed>>>;
131
+ /** Imperative opener: `const open = def.useSummon(); open({ data })` → handle. */
132
+ useSummon(): OverlayOpener<Data, Events>;
133
+ /** Declarative form: opens on mount, closes on unmount, re-opens when its data changes. */
134
+ readonly Controller: (props: OverlayControllerProps<Data, Events>) => null;
135
+ useIsOpen(instanceId?: string): boolean;
136
+ /** `const close = def.useClose(); close(instanceId?)`. */
137
+ useClose(): (instanceId?: string) => void;
138
+ /** Inside the render tree: emit a declared event to the opener's handlers. */
139
+ useEmit(): OverlayEmitter<Events>;
140
+ }
141
+ /**
142
+ * Declare an overlay once. Curried so `Data` (and `Events`) are named while the id and the
143
+ * parsed-data type are inferred:
144
+ *
145
+ * export const notesWindow = defineOverlay<NotesWindowData>()({
146
+ * id: "notesWindow", label: "Notes", render: () => import("./notesWindow.render"),
147
+ * });
148
+ */
149
+ declare function defineOverlay<Data extends object = Record<string, never>, Events extends OverlayEventMap = Record<never, never>>(): <const Id extends string, Parsed = OverlayRawData>(spec: OverlaySpec<Id, Data, Parsed>) => OverlayDefinition<Id, Data, Parsed, Events>;
150
+
151
+ declare function newInstanceId(overlayId: string): string;
152
+ declare function dispatchOpen(dispatch: SummonReactDispatch, overlayId: string, instanceId: string, data: unknown): void;
153
+ declare function dispatchClose(dispatch: SummonReactDispatch, overlayId: string, instanceId?: string): void;
154
+
155
+ interface OverlayInstanceContextValue {
156
+ readonly overlayId: string;
157
+ readonly instanceId: string;
158
+ readonly instanceKey: InstanceKey;
159
+ readonly close: () => void;
160
+ readonly hidden: boolean;
161
+ /** The open data as it arrived (pre-parse); event emitters read their channel id from it. */
162
+ readonly rawData: OverlayRawData;
163
+ }
164
+ declare const OverlayInstanceContext: react.Context<OverlayInstanceContextValue | null>;
165
+ /** The open instance this component renders inside. Throws outside an overlay. */
166
+ declare function useOverlayInstance(): OverlayInstanceContextValue;
167
+ /** Same as `useOverlayInstance`, but `null` outside an overlay. */
168
+ declare function useOptionalOverlayInstance(): OverlayInstanceContextValue | null;
169
+
170
+ type Emitter = (channelId: string, type: string, payload: unknown) => void;
171
+ /** The react section installs the synchronous emitter (it holds handles statically). */
172
+ declare function registerOverlayEmitter(emit: Emitter): void;
173
+ declare function emitOverlayEventLight(channelId: string, type: string, payload: unknown): void;
174
+
175
+ export { CALLBACK_GROUP_KEY, type HostableOverlay, type OverlayControllerProps, type OverlayDefinition, type OverlayEmitter, type OverlayErrorExtrasContext, type OverlayEventMap, type OverlayHandle, type OverlayHandlers, OverlayInstanceContext, type OverlayInstanceContextValue, type OverlayOpenOptions, type OverlayOpener, type OverlayRenderContext, type OverlaySpec, type SummonHostConfig, type SummonHostWindows, SummonPortsContext, type SummonReactDispatch, type SummonReactStore, SummonRoot, type SummonRootProps, SummonStoreContext, configureSummonHost, defineOverlay, dispatchClose, dispatchOpen, emitOverlayEventLight, getSummonHostConfig, getSummonHostPorts, getSummonHostVersion, newInstanceId, registerOverlayEmitter, useOptionalOverlayInstance, useOptionalSummonPorts, useOptionalSummonStore, useOverlayInstance, useSummonDispatch, useSummonPorts, useSummonSelector, useSummonStore };