@embedpdf/plugin-ui 2.0.0-next.1 → 2.0.0-next.2

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 (56) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +235 -146
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/actions.d.ts +31 -15
  6. package/dist/lib/schema.d.ts +51 -10
  7. package/dist/lib/selectors.d.ts +5 -5
  8. package/dist/lib/types.d.ts +39 -23
  9. package/dist/lib/ui-plugin.d.ts +11 -8
  10. package/dist/lib/utils/consts.d.ts +3 -0
  11. package/dist/lib/utils/schema-merger.d.ts +1 -1
  12. package/dist/lib/utils/stylesheet-generator.d.ts +17 -0
  13. package/dist/preact/adapter.d.ts +1 -1
  14. package/dist/preact/index.cjs +1 -1
  15. package/dist/preact/index.cjs.map +1 -1
  16. package/dist/preact/index.js +143 -38
  17. package/dist/preact/index.js.map +1 -1
  18. package/dist/react/adapter.d.ts +1 -1
  19. package/dist/react/index.cjs +1 -1
  20. package/dist/react/index.cjs.map +1 -1
  21. package/dist/react/index.js +143 -38
  22. package/dist/react/index.js.map +1 -1
  23. package/dist/shared/hooks/index.d.ts +1 -0
  24. package/dist/shared/hooks/use-schema-renderer.d.ts +41 -9
  25. package/dist/shared/hooks/use-ui-container.d.ts +39 -0
  26. package/dist/shared/root.d.ts +1 -1
  27. package/dist/shared/types.d.ts +31 -6
  28. package/dist/shared-preact/hooks/index.d.ts +1 -0
  29. package/dist/shared-preact/hooks/use-schema-renderer.d.ts +41 -9
  30. package/dist/shared-preact/hooks/use-ui-container.d.ts +39 -0
  31. package/dist/shared-preact/root.d.ts +1 -1
  32. package/dist/shared-preact/types.d.ts +31 -6
  33. package/dist/shared-react/hooks/index.d.ts +1 -0
  34. package/dist/shared-react/hooks/use-schema-renderer.d.ts +41 -9
  35. package/dist/shared-react/hooks/use-ui-container.d.ts +39 -0
  36. package/dist/shared-react/root.d.ts +1 -1
  37. package/dist/shared-react/types.d.ts +31 -6
  38. package/dist/svelte/hooks/index.d.ts +1 -0
  39. package/dist/svelte/hooks/use-schema-renderer.svelte.d.ts +55 -12
  40. package/dist/svelte/hooks/use-ui-container.svelte.d.ts +41 -0
  41. package/dist/svelte/hooks/use-ui.svelte.d.ts +2 -2
  42. package/dist/svelte/index.cjs +1 -1
  43. package/dist/svelte/index.cjs.map +1 -1
  44. package/dist/svelte/index.js +112 -20
  45. package/dist/svelte/index.js.map +1 -1
  46. package/dist/svelte/types.d.ts +31 -6
  47. package/dist/vue/hooks/index.d.ts +1 -0
  48. package/dist/vue/hooks/use-schema-renderer.d.ts +41 -9
  49. package/dist/vue/hooks/use-ui-container.d.ts +39 -0
  50. package/dist/vue/hooks/use-ui.d.ts +148 -20
  51. package/dist/vue/index.cjs +1 -1
  52. package/dist/vue/index.cjs.map +1 -1
  53. package/dist/vue/index.js +126 -25
  54. package/dist/vue/index.js.map +1 -1
  55. package/dist/vue/types.d.ts +31 -6
  56. package/package.json +12 -12
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-ui.ts","../../src/shared/registries/anchor-registry.tsx","../../src/shared/registries/component-registry.tsx","../../src/shared/registries/renderers-registry.tsx","../../src/shared/auto-menu-renderer.tsx","../../src/shared/root.tsx","../../src/shared/provider.tsx","../../src/shared/hooks/use-item-renderer.tsx","../../src/shared/hooks/use-register-anchor.ts","../../src/shared/hooks/use-schema-renderer.tsx","../../src/shared/hooks/use-selection-menu.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { UIPlugin } from '@embedpdf/plugin-ui';\nimport { useState, useEffect } from '@framework';\nimport { UIDocumentState, UISchema } from '@embedpdf/plugin-ui';\n\nexport const useUICapability = () => useCapability<UIPlugin>(UIPlugin.id);\nexport const useUIPlugin = () => usePlugin<UIPlugin>(UIPlugin.id);\n\n/**\n * Get UI state for a document\n */\nexport const useUIState = (documentId: string) => {\n const { provides } = useUICapability();\n const [state, setState] = useState<UIDocumentState | null>(null);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n setState(scope.getState());\n\n // Subscribe to changes\n const unsubToolbar = scope.onToolbarChanged(() => setState(scope.getState()));\n const unsubPanel = scope.onPanelChanged(() => setState(scope.getState()));\n const unsubModal = scope.onModalChanged(() => setState(scope.getState()));\n const unsubMenu = scope.onMenuChanged(() => setState(scope.getState()));\n\n return () => {\n unsubToolbar();\n unsubPanel();\n unsubModal();\n unsubMenu();\n };\n }, [provides, documentId]);\n\n return state;\n};\n\n/**\n * Get UI schema\n */\nexport const useUISchema = (): UISchema | null => {\n const { provides } = useUICapability();\n return provides?.getSchema() ?? null;\n};\n","import { createContext, useContext, useRef, useCallback } from '@framework';\nimport type { ReactNode } from '@framework';\n\n/**\n * Anchor Registry\n *\n * Tracks DOM elements for menu positioning.\n * Each anchor is scoped by documentId and itemId.\n */\nexport interface AnchorRegistry {\n register(documentId: string, itemId: string, element: HTMLElement): void;\n unregister(documentId: string, itemId: string): void;\n getAnchor(documentId: string, itemId: string): HTMLElement | null;\n}\n\nconst AnchorRegistryContext = createContext<AnchorRegistry | null>(null);\n\nexport function AnchorRegistryProvider({ children }: { children: ReactNode }) {\n const anchorsRef = useRef<Map<string, HTMLElement>>(new Map());\n\n const registry: AnchorRegistry = {\n register: useCallback((documentId: string, itemId: string, element: HTMLElement) => {\n const key = `${documentId}:${itemId}`;\n anchorsRef.current.set(key, element);\n }, []),\n\n unregister: useCallback((documentId: string, itemId: string) => {\n const key = `${documentId}:${itemId}`;\n anchorsRef.current.delete(key);\n }, []),\n\n getAnchor: useCallback((documentId: string, itemId: string) => {\n const key = `${documentId}:${itemId}`;\n return anchorsRef.current.get(key) || null;\n }, []),\n };\n\n return (\n <AnchorRegistryContext.Provider value={registry}>{children}</AnchorRegistryContext.Provider>\n );\n}\n\nexport function useAnchorRegistry(): AnchorRegistry {\n const context = useContext(AnchorRegistryContext);\n if (!context) {\n throw new Error('useAnchorRegistry must be used within UIProvider');\n }\n return context;\n}\n","import { createContext, useContext, useRef, useCallback } from '@framework';\nimport type { ComponentType, ReactNode } from '@framework';\nimport { BaseComponentProps } from '../types';\n\n/**\n * Component Registry\n *\n * Stores custom components that can be referenced in the UI schema.\n */\nexport interface ComponentRegistry {\n register(id: string, component: ComponentType<BaseComponentProps>): void;\n unregister(id: string): void;\n get(id: string): ComponentType<BaseComponentProps> | undefined;\n has(id: string): boolean;\n getRegisteredIds(): string[];\n}\n\nconst ComponentRegistryContext = createContext<ComponentRegistry | null>(null);\n\nexport interface ComponentRegistryProviderProps {\n children: ReactNode;\n initialComponents?: Record<string, ComponentType<BaseComponentProps>>;\n}\n\nexport function ComponentRegistryProvider({\n children,\n initialComponents = {},\n}: ComponentRegistryProviderProps) {\n const componentsRef = useRef<Map<string, ComponentType<BaseComponentProps>>>(\n new Map(Object.entries(initialComponents)),\n );\n\n const registry: ComponentRegistry = {\n register: useCallback((id: string, component: ComponentType<BaseComponentProps>) => {\n componentsRef.current.set(id, component);\n }, []),\n\n unregister: useCallback((id: string) => {\n componentsRef.current.delete(id);\n }, []),\n\n get: useCallback((id: string) => {\n return componentsRef.current.get(id);\n }, []),\n\n has: useCallback((id: string) => {\n return componentsRef.current.has(id);\n }, []),\n\n getRegisteredIds: useCallback(() => {\n return Array.from(componentsRef.current.keys());\n }, []),\n };\n\n return (\n <ComponentRegistryContext.Provider value={registry}>\n {children}\n </ComponentRegistryContext.Provider>\n );\n}\n\nexport function useComponentRegistry(): ComponentRegistry {\n const context = useContext(ComponentRegistryContext);\n if (!context) {\n throw new Error('useComponentRegistry must be used within UIProvider');\n }\n return context;\n}\n","import { createContext, useContext } from '@framework';\nimport type { ReactNode } from '@framework';\nimport { UIRenderers } from '../types';\n\n/**\n * Renderers Registry\n *\n * Provides access to user-supplied renderers (toolbar, panel, menu).\n */\nconst RenderersContext = createContext<UIRenderers | null>(null);\n\nexport interface RenderersProviderProps {\n children: ReactNode;\n renderers: UIRenderers;\n}\n\nexport function RenderersProvider({ children, renderers }: RenderersProviderProps) {\n return <RenderersContext.Provider value={renderers}>{children}</RenderersContext.Provider>;\n}\n\nexport function useRenderers(): UIRenderers {\n const context = useContext(RenderersContext);\n if (!context) {\n throw new Error('useRenderers must be used within UIProvider');\n }\n return context;\n}\n","import { useState, useEffect } from '@framework';\nimport { useUIState, useUICapability } from './hooks/use-ui';\nimport { useAnchorRegistry } from './registries/anchor-registry';\nimport { useRenderers } from './registries/renderers-registry';\n\n/**\n * Automatically renders menus when opened\n *\n * This component:\n * 1. Listens to UI plugin state for open menus\n * 2. Looks up anchor elements from the anchor registry\n * 3. Renders menus using the user-provided menu renderer\n */\nexport interface AutoMenuRendererProps {\n container?: HTMLElement | null;\n documentId: string; // Which document's menus to render\n}\n\nexport function AutoMenuRenderer({ container, documentId }: AutoMenuRendererProps) {\n const uiState = useUIState(documentId);\n const { provides } = useUICapability();\n const anchorRegistry = useAnchorRegistry();\n const renderers = useRenderers();\n\n const [activeMenu, setActiveMenu] = useState<{\n menuId: string;\n anchorEl: HTMLElement | null;\n } | null>(null);\n\n const openMenus = uiState?.openMenus || {};\n const schema = provides?.getSchema();\n\n // Update active menu when state changes\n useEffect(() => {\n const openMenuIds = Object.keys(openMenus);\n\n if (openMenuIds.length > 0) {\n // Show the first open menu (in practice, should only be one)\n const menuId = openMenuIds[0];\n if (!menuId) {\n setActiveMenu(null);\n return;\n }\n\n const menuState = openMenus[menuId];\n if (menuState && menuState.triggeredByItemId) {\n // Look up anchor with documentId scope\n const anchor = anchorRegistry.getAnchor(documentId, menuState.triggeredByItemId);\n setActiveMenu({ menuId, anchorEl: anchor });\n } else {\n setActiveMenu(null);\n }\n } else {\n setActiveMenu(null);\n }\n }, [openMenus, anchorRegistry, documentId]);\n\n const handleClose = () => {\n if (activeMenu) {\n provides?.forDocument(documentId).closeMenu(activeMenu.menuId);\n }\n };\n\n if (!activeMenu || !schema) {\n return null;\n }\n\n const menuSchema = schema.menus[activeMenu.menuId];\n if (!menuSchema) {\n console.warn(`Menu \"${activeMenu.menuId}\" not found in schema`);\n return null;\n }\n\n // Use the user-provided menu renderer\n const MenuRenderer = renderers.menu;\n\n return (\n <MenuRenderer\n schema={menuSchema}\n documentId={documentId}\n anchorEl={activeMenu.anchorEl}\n onClose={handleClose}\n container={container}\n />\n );\n}\n","import { UI_ATTRIBUTES, UI_SELECTORS } from '@embedpdf/plugin-ui';\nimport { useUICapability, useUIPlugin } from './hooks/use-ui';\nimport {\n useState,\n useEffect,\n useRef,\n useMemo,\n useCallback,\n ReactNode,\n HTMLAttributes,\n} from '@framework';\n\n/**\n * Find the style injection target for an element.\n * Returns the shadow root if inside one, otherwise document.head.\n */\nfunction getStyleTarget(element: HTMLElement): HTMLElement | ShadowRoot {\n const root = element.getRootNode();\n if (root instanceof ShadowRoot) {\n return root;\n }\n return document.head;\n}\n\ninterface UIRootProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n}\n\n/**\n * Internal component that handles:\n * 1. Injecting the generated stylesheet (into shadow root or document.head)\n * 2. Managing the data-disabled-categories attribute\n * 3. Updating styles on locale changes\n */\nexport function UIRoot({ children, ...restProps }: UIRootProps) {\n const { plugin } = useUIPlugin();\n const { provides } = useUICapability();\n const [disabledCategories, setDisabledCategories] = useState<string[]>([]);\n const styleElRef = useRef<HTMLStyleElement | null>(null);\n const styleTargetRef = useRef<HTMLElement | ShadowRoot | null>(null);\n const previousElementRef = useRef<HTMLDivElement | null>(null);\n\n // Callback ref that handles style injection when element mounts\n // Handles React Strict Mode by tracking previous element\n const rootRefCallback = useCallback(\n (element: HTMLDivElement | null) => {\n const previousElement = previousElementRef.current;\n\n // Update ref\n previousElementRef.current = element;\n\n // If element is null (unmount), don't do anything yet\n // React Strict Mode will remount, so we'll handle cleanup in useEffect\n if (!element) {\n return;\n }\n\n // If element changed (or is new) and plugin is available, inject styles\n if (element !== previousElement && plugin) {\n const styleTarget = getStyleTarget(element);\n styleTargetRef.current = styleTarget;\n\n // Check if styles already exist in this target\n const existingStyle = styleTarget.querySelector(\n UI_SELECTORS.STYLES,\n ) as HTMLStyleElement | null;\n\n if (existingStyle) {\n styleElRef.current = existingStyle;\n // Update content in case locale changed\n existingStyle.textContent = plugin.getStylesheet();\n return;\n }\n\n // Create and inject stylesheet\n const stylesheet = plugin.getStylesheet();\n const styleEl = document.createElement('style');\n styleEl.setAttribute(UI_ATTRIBUTES.STYLES, '');\n styleEl.textContent = stylesheet;\n\n if (styleTarget instanceof ShadowRoot) {\n // For shadow root, prepend before other content\n styleTarget.insertBefore(styleEl, styleTarget.firstChild);\n } else {\n styleTarget.appendChild(styleEl);\n }\n\n styleElRef.current = styleEl;\n }\n },\n [plugin],\n );\n\n // Cleanup on actual unmount (not Strict Mode remount)\n useEffect(() => {\n return () => {\n // Only cleanup if we're actually unmounting (not just Strict Mode)\n // The style element will be reused if component remounts\n if (styleElRef.current?.parentNode && !previousElementRef.current) {\n styleElRef.current.remove();\n }\n styleElRef.current = null;\n styleTargetRef.current = null;\n };\n }, []);\n\n // Subscribe to stylesheet invalidation (locale changes, schema merges)\n useEffect(() => {\n if (!plugin) return;\n\n return plugin.onStylesheetInvalidated(() => {\n // Update the style element content\n if (styleElRef.current) {\n styleElRef.current.textContent = plugin.getStylesheet();\n }\n });\n }, [plugin]);\n\n // Subscribe to category changes\n useEffect(() => {\n if (!provides) return;\n\n setDisabledCategories(provides.getDisabledCategories());\n\n return provides.onCategoryChanged(({ disabledCategories }) => {\n setDisabledCategories(disabledCategories);\n });\n }, [provides]);\n\n // Build the disabled categories attribute value\n const disabledCategoriesAttr = useMemo(\n () => (disabledCategories.length > 0 ? disabledCategories.join(' ') : undefined),\n [disabledCategories],\n );\n\n const rootProps = {\n [UI_ATTRIBUTES.ROOT]: '',\n [UI_ATTRIBUTES.DISABLED_CATEGORIES]: disabledCategoriesAttr,\n };\n\n return (\n <div\n ref={rootRefCallback}\n {...rootProps}\n {...restProps}\n style={{ containerType: 'inline-size', ...restProps.style }}\n >\n {children}\n </div>\n );\n}\n","import type { ReactNode, ComponentType, HTMLAttributes } from '@framework';\nimport { AnchorRegistryProvider } from './registries/anchor-registry';\nimport { ComponentRegistryProvider } from './registries/component-registry';\nimport { RenderersProvider } from './registries/renderers-registry';\nimport { BaseComponentProps, UIRenderers } from './types';\nimport { AutoMenuRenderer } from './auto-menu-renderer';\nimport { UIRoot } from './root';\n\n/**\n * UIProvider Props\n */\nexport interface UIProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n\n /**\n * Document ID for this UI context\n * Required for menu rendering\n */\n documentId: string;\n\n /**\n * Custom component registry\n * Maps component IDs to components\n */\n components?: Record<string, ComponentType<BaseComponentProps>>;\n\n /**\n * REQUIRED: User-provided renderers\n * These define how toolbars, panels, and menus are displayed\n */\n renderers: UIRenderers;\n\n /**\n * Optional: Container for menu portal\n * Defaults to document.body\n */\n menuContainer?: HTMLElement | null;\n}\n\n/**\n * UIProvider - Single provider for all UI plugin functionality\n *\n * Manages:\n * - Anchor registry for menu positioning\n * - Component registry for custom components\n * - Renderers for toolbars, panels, and menus\n * - Automatic menu rendering\n *\n * @example\n * ```tsx\n * <EmbedPDF engine={engine} plugins={plugins}>\n * {({ pluginsReady }) => (\n * pluginsReady && (\n * <DocumentContext>\n * {({ activeDocumentId }) => (\n * activeDocumentId && (\n * <UIProvider\n * documentId={activeDocumentId}\n * components={{\n * 'thumbnail-panel': ThumbnailPanel,\n * 'bookmark-panel': BookmarkPanel,\n * }}\n * renderers={{\n * toolbar: ToolbarRenderer,\n * panel: PanelRenderer,\n * menu: MenuRenderer,\n * }}\n * >\n * <ViewerLayout />\n * </UIProvider>\n * )\n * )}\n * </DocumentContext>\n * )\n * )}\n * </EmbedPDF>\n * ```\n */\nexport function UIProvider({\n children,\n documentId,\n components = {},\n renderers,\n menuContainer,\n ...restProps\n}: UIProviderProps) {\n return (\n <AnchorRegistryProvider>\n <ComponentRegistryProvider initialComponents={components}>\n <RenderersProvider renderers={renderers}>\n <UIRoot {...restProps}>\n {children}\n {/* Automatically render menus for this document */}\n <AutoMenuRenderer documentId={documentId} container={menuContainer} />\n </UIRoot>\n </RenderersProvider>\n </ComponentRegistryProvider>\n </AnchorRegistryProvider>\n );\n}\n","import { useComponentRegistry } from '../registries/component-registry';\n\n/**\n * Helper utilities for building renderers\n */\nexport function useItemRenderer() {\n const componentRegistry = useComponentRegistry();\n\n return {\n /**\n * Render a custom component by ID\n *\n * @param componentId - Component ID from schema\n * @param documentId - Document ID\n * @param props - Additional props to pass to component\n * @returns Rendered component or null if not found\n */\n renderCustomComponent: (componentId: string, documentId: string, props?: any) => {\n const Component = componentRegistry.get(componentId);\n\n if (!Component) {\n console.error(`Component \"${componentId}\" not found in registry`);\n return null;\n }\n\n return <Component documentId={documentId} {...(props || {})} />;\n },\n };\n}\n","import { useCallback, useRef } from '@framework';\nimport { useAnchorRegistry } from '../registries/anchor-registry';\n\n/**\n * Register a DOM element as an anchor for menus\n *\n * @param documentId - Document ID\n * @param itemId - Item ID (typically matches the toolbar/menu item ID)\n * @returns Ref callback to attach to the element\n *\n * @example\n * ```tsx\n * function ZoomButton({ documentId }: Props) {\n * const anchorRef = useRegisterAnchor(documentId, 'zoom-button');\n *\n * return <button ref={anchorRef}>Zoom</button>;\n * }\n * ```\n */\nexport function useRegisterAnchor(\n documentId: string,\n itemId: string,\n): (element: HTMLElement | null) => void {\n const registry = useAnchorRegistry();\n const elementRef = useRef<HTMLElement | null>(null);\n const documentIdRef = useRef(documentId);\n const itemIdRef = useRef(itemId);\n\n // Keep refs in sync\n documentIdRef.current = documentId;\n itemIdRef.current = itemId;\n\n // Return stable callback that uses refs\n return useCallback(\n (element: HTMLElement | null) => {\n // Store previous element\n const previousElement = elementRef.current;\n\n // Update ref\n elementRef.current = element;\n\n // Handle registration/unregistration\n if (element) {\n // Register new element\n if (element !== previousElement) {\n registry.register(documentIdRef.current, itemIdRef.current, element);\n }\n } else if (previousElement) {\n // Element is now null, but we had one before - unregister\n registry.unregister(documentIdRef.current, itemIdRef.current);\n }\n },\n [registry], // Only depend on registry!\n );\n}\n","import { useUICapability, useUIState } from './use-ui';\nimport { useRenderers } from '../registries/renderers-registry';\n\n/**\n * High-level hook for rendering UI from schema\n *\n * Provides simple functions to render toolbars and panels by placement+slot.\n * Always passes isOpen state to renderers so they can control animations.\n *\n * Automatically subscribes to UI state changes for the given document.\n */\nexport function useSchemaRenderer(documentId: string) {\n const renderers = useRenderers();\n const { provides } = useUICapability();\n const schema = provides?.getSchema();\n const uiState = useUIState(documentId); // Subscribe to state changes\n\n return {\n /**\n * Render a toolbar by placement and slot\n *\n * Always renders with isOpen state when toolbar exists in slot.\n *\n * @param placement - 'top' | 'bottom' | 'left' | 'right'\n * @param slot - Slot name (e.g. 'main', 'secondary')\n *\n * @example\n * ```tsx\n * {renderToolbar('top', 'main')}\n * {renderToolbar('top', 'secondary')}\n * ```\n */\n renderToolbar: (placement: 'top' | 'bottom' | 'left' | 'right', slot: string) => {\n if (!schema || !provides || !uiState) return null;\n\n const slotKey = `${placement}-${slot}`;\n const toolbarSlot = uiState.activeToolbars[slotKey];\n\n // If no toolbar in this slot, nothing to render\n if (!toolbarSlot) return null;\n\n const toolbarSchema = schema.toolbars[toolbarSlot.toolbarId];\n if (!toolbarSchema) {\n console.warn(`Toolbar \"${toolbarSlot.toolbarId}\" not found in schema`);\n return null;\n }\n\n // Check if toolbar is closable\n const isClosable = !toolbarSchema.permanent;\n\n const handleClose = isClosable\n ? () => {\n provides.forDocument(documentId).closeToolbarSlot(placement, slot);\n }\n : undefined;\n\n const ToolbarRenderer = renderers.toolbar;\n\n // ALWAYS render, pass isOpen state\n return (\n <ToolbarRenderer\n key={toolbarSlot.toolbarId}\n schema={toolbarSchema}\n documentId={documentId}\n isOpen={toolbarSlot.isOpen}\n onClose={handleClose}\n />\n );\n },\n\n /**\n * Render a panel by placement and slot\n *\n * ALWAYS renders (when panel exists in slot) with isOpen state.\n * Your renderer controls whether to display or animate.\n *\n * @param placement - 'left' | 'right' | 'top' | 'bottom'\n * @param slot - Slot name (e.g. 'main', 'secondary', 'inspector')\n *\n * @example\n * ```tsx\n * {renderPanel('left', 'main')}\n * {renderPanel('right', 'main')}\n * ```\n */\n renderPanel: (placement: 'left' | 'right' | 'top' | 'bottom', slot: string) => {\n if (!schema || !provides || !uiState) return null;\n const slotKey = `${placement}-${slot}`;\n const panelSlot = uiState.activePanels[slotKey];\n\n // If no panel in this slot, nothing to render\n if (!panelSlot) return null;\n\n const panelSchema = schema.panels[panelSlot.panelId];\n if (!panelSchema) {\n console.warn(`Panel \"${panelSlot.panelId}\" not found in schema`);\n return null;\n }\n\n const handleClose = () => {\n provides.forDocument(documentId).closePanelSlot(placement, slot);\n };\n\n const PanelRenderer = renderers.panel;\n\n // ALWAYS render, pass isOpen state\n // Your renderer decides whether to return null or animate\n return (\n <PanelRenderer\n key={panelSlot.panelId}\n schema={panelSchema}\n documentId={documentId}\n isOpen={panelSlot.isOpen}\n onClose={handleClose}\n />\n );\n },\n\n /**\n * Helper: Get all active toolbars for this document\n * Useful for batch rendering or debugging\n */\n getActiveToolbars: () => {\n if (!uiState) return [];\n return Object.entries(uiState.activeToolbars).map(([slotKey, toolbarSlot]) => {\n const [placement, slot] = slotKey.split('-');\n return {\n placement,\n slot,\n toolbarId: toolbarSlot.toolbarId,\n isOpen: toolbarSlot.isOpen,\n };\n });\n },\n\n /**\n * Helper: Get all active panels for this document\n * Useful for batch rendering or debugging\n */\n getActivePanels: () => {\n if (!uiState) return [];\n return Object.entries(uiState.activePanels).map(([slotKey, panelSlot]) => {\n const [placement, slot] = slotKey.split('-');\n return {\n placement,\n slot,\n panelId: panelSlot.panelId,\n isOpen: panelSlot.isOpen,\n };\n });\n },\n };\n}\n","import { useCallback } from '@framework';\nimport { SelectionMenuPropsBase, SelectionMenuRenderFn } from '@embedpdf/utils/@framework';\nimport { useUICapability } from './use-ui';\nimport { useRenderers } from '../registries/renderers-registry';\n\n/**\n * Creates a render function for a selection menu from the schema\n *\n * @param menuId - The selection menu ID from schema\n * @param documentId - Document ID\n * @returns A render function compatible with layer selectionMenu props\n */\nexport function useSelectionMenu<TContext extends { type: string }>(\n menuId: string,\n documentId: string,\n): SelectionMenuRenderFn<TContext> | undefined {\n const { provides } = useUICapability();\n const renderers = useRenderers();\n\n const renderFn = useCallback(\n (props: SelectionMenuPropsBase<TContext>) => {\n const schema = provides?.getSchema();\n const menuSchema = schema?.selectionMenus?.[menuId];\n\n if (!menuSchema) {\n return null;\n }\n\n if (!props.selected) {\n return null;\n }\n\n const SelectionMenuRenderer = renderers.selectionMenu;\n\n return <SelectionMenuRenderer schema={menuSchema} documentId={documentId} props={props} />;\n },\n [provides, renderers, menuId, documentId],\n );\n\n // Return undefined if schema doesn't have this menu\n const schema = provides?.getSchema();\n if (!schema?.selectionMenus?.[menuId]) {\n return undefined;\n }\n\n return renderFn;\n}\n"],"names":["useUICapability","useCapability","UIPlugin","id","useUIPlugin","usePlugin","useUIState","documentId","provides","state","setState","useState","useEffect","scope","forDocument","getState","unsubToolbar","onToolbarChanged","unsubPanel","onPanelChanged","unsubModal","onModalChanged","unsubMenu","onMenuChanged","AnchorRegistryContext","createContext","AnchorRegistryProvider","children","anchorsRef","useRef","Map","registry","register","useCallback","itemId","element","key","current","set","unregister","delete","getAnchor","get","Provider","value","useAnchorRegistry","context","useContext","Error","ComponentRegistryContext","ComponentRegistryProvider","initialComponents","componentsRef","Object","entries","component","has","getRegisteredIds","Array","from","keys","useComponentRegistry","RenderersContext","RenderersProvider","renderers","useRenderers","AutoMenuRenderer","container","uiState","anchorRegistry","activeMenu","setActiveMenu","openMenus","schema","getSchema","openMenuIds","length","menuId","menuState","triggeredByItemId","anchor","anchorEl","menuSchema","menus","console","warn","MenuRenderer","menu","jsx","onClose","closeMenu","UIRoot","restProps","plugin","disabledCategories","setDisabledCategories","styleElRef","styleTargetRef","previousElementRef","rootRefCallback","previousElement","styleTarget","root","getRootNode","ShadowRoot","document","head","getStyleTarget","existingStyle","querySelector","UI_SELECTORS","STYLES","textContent","getStylesheet","stylesheet","styleEl","createElement","setAttribute","UI_ATTRIBUTES","insertBefore","firstChild","appendChild","_a","parentNode","remove","onStylesheetInvalidated","getDisabledCategories","onCategoryChanged","disabledCategoriesAttr","useMemo","join","rootProps","ROOT","DISABLED_CATEGORIES","ref","style","containerType","components","menuContainer","jsxs","componentRegistry","renderCustomComponent","componentId","props","Component","error","elementRef","documentIdRef","itemIdRef","renderToolbar","placement","slot","slotKey","toolbarSlot","activeToolbars","toolbarSchema","toolbars","toolbarId","handleClose","permanent","closeToolbarSlot","ToolbarRenderer","toolbar","isOpen","renderPanel","panelSlot","activePanels","panelSchema","panels","panelId","PanelRenderer","panel","closePanelSlot","getActiveToolbars","map","split","getActivePanels","renderFn","selectionMenus","selected","SelectionMenuRenderer","selectionMenu"],"mappings":"wOAKaA,EAAkB,IAAMC,gBAAwBC,EAAAA,SAASC,IACzDC,EAAc,IAAMC,YAAoBH,EAAAA,SAASC,IAKjDG,EAAcC,IACzB,MAAMC,SAAEA,GAAaR,KACdS,EAAOC,GAAYC,EAAAA,SAAiC,MAsB3D,OApBAC,EAAAA,UAAU,KACR,IAAKJ,EAAU,OAEf,MAAMK,EAAQL,EAASM,YAAYP,GACnCG,EAASG,EAAME,YAGf,MAAMC,EAAeH,EAAMI,iBAAiB,IAAMP,EAASG,EAAME,aAC3DG,EAAaL,EAAMM,eAAe,IAAMT,EAASG,EAAME,aACvDK,EAAaP,EAAMQ,eAAe,IAAMX,EAASG,EAAME,aACvDO,EAAYT,EAAMU,cAAc,IAAMb,EAASG,EAAME,aAE3D,MAAO,KACLC,IACAE,IACAE,IACAE,MAED,CAACd,EAAUD,IAEPE,GCpBHe,EAAwBC,EAAAA,cAAqC,MAE5D,SAASC,GAAuBC,SAAEA,IACvC,MAAMC,EAAaC,EAAAA,OAAiC,IAAIC,KAElDC,EAA2B,CAC/BC,SAAUC,EAAAA,YAAY,CAAC1B,EAAoB2B,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AAYqK,eAAetB,EAAWC,KASpDc,EAAUI,UAarBI,kBAAmB,IACZzG,EACEf,OAAOC,QAAQc,EAAQsF,gBAAgBoB,IAAI,EAAEtB,EAASC,MAC3D,MAAOH,EAAWC,GAAQC,EAAQuB,MAAM,KACxC,MAAO,CACLzB,YACAC,OACAM,UAAWJ,EAAYI,UACvBM,OAAQV,EAAYU,UAPH,GAgBvBa,gBAAiB,IACV5G,EACEf,OAAOC,QAAQc,EAAQkG,cAAcQ,IAAI,EAAEtB,EAASa,MACzD,MAAOf,EAAWC,GAAQC,EAAQuB,MAAM,KACxC,MAAO,CACLzB,YACAC,OACAkB,QAASJ,EAAUI,QACnBN,OAAQE,EAAUF,UAPD,GAY3B,2BC5IO,SACLtF,EACAtE,SAEA,MAAMC,SAAEA,GAAaR,IACfgE,EAAYC,IAEZgH,EAAWhJ,EAAAA,YACd8G,UACC,MAAMtE,EAAS,MAAAjE,OAAA,EAAAA,EAAUkE,YACnBQ,EAAaT,OAAAA,EAAAA,MAAAA,OAAAA,EAAAA,EAAQyG,uBAARzG,EAAyBI,GAE5C,IAAKK,EACH,OAAO,KAGT,IAAK6D,EAAMoC,SACT,OAAO,KAGT,MAAMC,EAAwBpH,EAAUqH,cAExC,OAAO7F,EAAAA,IAAC4F,EAAA,CAAsB3G,OAAQS,EAAY3E,aAAwBwI,WAE5E,CAACvI,EAAUwD,EAAWa,EAAQtE,IAI1BkE,EAAS,MAAAjE,OAAA,EAAAA,EAAUkE,YACzB,GAAK,OAAAgD,EAAA,MAAAjD,OAAA,EAAAA,EAAQyG,qBAAR,EAAAxD,EAAyB7C,GAI9B,OAAOoG,CACT,sEVL2B,KACzB,MAAMzK,SAAEA,GAAaR,IACrB,aAAOQ,WAAUkE,cAAe"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-ui.ts","../../src/shared/hooks/use-ui-container.ts","../../src/shared/registries/anchor-registry.tsx","../../src/shared/registries/component-registry.tsx","../../src/shared/registries/renderers-registry.tsx","../../src/shared/auto-menu-renderer.tsx","../../src/shared/root.tsx","../../src/shared/provider.tsx","../../src/shared/hooks/use-item-renderer.tsx","../../src/shared/hooks/use-register-anchor.ts","../../src/shared/hooks/use-schema-renderer.tsx","../../src/shared/hooks/use-selection-menu.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { UIPlugin } from '@embedpdf/plugin-ui';\nimport { useState, useEffect } from '@framework';\nimport { UIDocumentState, UISchema } from '@embedpdf/plugin-ui';\n\nexport const useUICapability = () => useCapability<UIPlugin>(UIPlugin.id);\nexport const useUIPlugin = () => usePlugin<UIPlugin>(UIPlugin.id);\n\n/**\n * Get UI state for a document\n */\nexport const useUIState = (documentId: string) => {\n const { provides } = useUICapability();\n const [state, setState] = useState<UIDocumentState | null>(null);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n setState(scope.getState());\n\n // Subscribe to changes\n const unsubToolbar = scope.onToolbarChanged(() => setState(scope.getState()));\n const unsubSidebar = scope.onSidebarChanged(() => setState(scope.getState()));\n const unsubModal = scope.onModalChanged(() => setState(scope.getState()));\n const unsubMenu = scope.onMenuChanged(() => setState(scope.getState()));\n\n return () => {\n unsubToolbar();\n unsubSidebar();\n unsubModal();\n unsubMenu();\n };\n }, [provides, documentId]);\n\n return state;\n};\n\n/**\n * Get UI schema\n */\nexport const useUISchema = (): UISchema | null => {\n const { provides } = useUICapability();\n return provides?.getSchema() ?? null;\n};\n","import { createContext, useContext, RefObject } from '@framework';\n\nexport interface UIContainerContextValue {\n /** Reference to the UIRoot container element */\n containerRef: RefObject<HTMLDivElement>;\n /** Get the container element (may be null if not mounted) */\n getContainer: () => HTMLDivElement | null;\n}\n\nexport const UIContainerContext = createContext<UIContainerContextValue | null>(null);\n\n/**\n * Hook to access the UI container element.\n *\n * This provides access to the UIRoot container for:\n * - Container query based responsiveness\n * - Portaling elements to the root\n * - Measuring container dimensions\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { containerRef, getContainer } = useUIContainer();\n *\n * // Use containerRef for ResizeObserver\n * useEffect(() => {\n * const container = getContainer();\n * if (!container) return;\n *\n * const observer = new ResizeObserver(() => {\n * console.log('Container width:', container.clientWidth);\n * });\n * observer.observe(container);\n * return () => observer.disconnect();\n * }, [getContainer]);\n *\n * // Or portal to the container\n * return createPortal(<Modal />, getContainer()!);\n * }\n * ```\n */\nexport function useUIContainer(): UIContainerContextValue {\n const context = useContext(UIContainerContext);\n if (!context) {\n throw new Error('useUIContainer must be used within a UIProvider');\n }\n return context;\n}\n","import { createContext, useContext, useRef, useCallback } from '@framework';\nimport type { ReactNode } from '@framework';\n\n/**\n * Anchor Registry\n *\n * Tracks DOM elements for menu positioning.\n * Each anchor is scoped by documentId and itemId.\n */\nexport interface AnchorRegistry {\n register(documentId: string, itemId: string, element: HTMLElement): void;\n unregister(documentId: string, itemId: string): void;\n getAnchor(documentId: string, itemId: string): HTMLElement | null;\n}\n\nconst AnchorRegistryContext = createContext<AnchorRegistry | null>(null);\n\nexport function AnchorRegistryProvider({ children }: { children: ReactNode }) {\n const anchorsRef = useRef<Map<string, HTMLElement>>(new Map());\n\n const registry: AnchorRegistry = {\n register: useCallback((documentId: string, itemId: string, element: HTMLElement) => {\n const key = `${documentId}:${itemId}`;\n anchorsRef.current.set(key, element);\n }, []),\n\n unregister: useCallback((documentId: string, itemId: string) => {\n const key = `${documentId}:${itemId}`;\n anchorsRef.current.delete(key);\n }, []),\n\n getAnchor: useCallback((documentId: string, itemId: string) => {\n const key = `${documentId}:${itemId}`;\n return anchorsRef.current.get(key) || null;\n }, []),\n };\n\n return (\n <AnchorRegistryContext.Provider value={registry}>{children}</AnchorRegistryContext.Provider>\n );\n}\n\nexport function useAnchorRegistry(): AnchorRegistry {\n const context = useContext(AnchorRegistryContext);\n if (!context) {\n throw new Error('useAnchorRegistry must be used within UIProvider');\n }\n return context;\n}\n","import { createContext, useContext, useRef, useCallback } from '@framework';\nimport type { ComponentType, ReactNode } from '@framework';\nimport { BaseComponentProps } from '../types';\n\n/**\n * Component Registry\n *\n * Stores custom components that can be referenced in the UI schema.\n */\nexport interface ComponentRegistry {\n register(id: string, component: ComponentType<BaseComponentProps>): void;\n unregister(id: string): void;\n get(id: string): ComponentType<BaseComponentProps> | undefined;\n has(id: string): boolean;\n getRegisteredIds(): string[];\n}\n\nconst ComponentRegistryContext = createContext<ComponentRegistry | null>(null);\n\nexport interface ComponentRegistryProviderProps {\n children: ReactNode;\n initialComponents?: Record<string, ComponentType<BaseComponentProps>>;\n}\n\nexport function ComponentRegistryProvider({\n children,\n initialComponents = {},\n}: ComponentRegistryProviderProps) {\n const componentsRef = useRef<Map<string, ComponentType<BaseComponentProps>>>(\n new Map(Object.entries(initialComponents)),\n );\n\n const registry: ComponentRegistry = {\n register: useCallback((id: string, component: ComponentType<BaseComponentProps>) => {\n componentsRef.current.set(id, component);\n }, []),\n\n unregister: useCallback((id: string) => {\n componentsRef.current.delete(id);\n }, []),\n\n get: useCallback((id: string) => {\n return componentsRef.current.get(id);\n }, []),\n\n has: useCallback((id: string) => {\n return componentsRef.current.has(id);\n }, []),\n\n getRegisteredIds: useCallback(() => {\n return Array.from(componentsRef.current.keys());\n }, []),\n };\n\n return (\n <ComponentRegistryContext.Provider value={registry}>\n {children}\n </ComponentRegistryContext.Provider>\n );\n}\n\nexport function useComponentRegistry(): ComponentRegistry {\n const context = useContext(ComponentRegistryContext);\n if (!context) {\n throw new Error('useComponentRegistry must be used within UIProvider');\n }\n return context;\n}\n","import { createContext, useContext } from '@framework';\nimport type { ReactNode } from '@framework';\nimport { UIRenderers } from '../types';\n\n/**\n * Renderers Registry\n *\n * Provides access to user-supplied renderers (toolbar, panel, menu).\n */\nconst RenderersContext = createContext<UIRenderers | null>(null);\n\nexport interface RenderersProviderProps {\n children: ReactNode;\n renderers: UIRenderers;\n}\n\nexport function RenderersProvider({ children, renderers }: RenderersProviderProps) {\n return <RenderersContext.Provider value={renderers}>{children}</RenderersContext.Provider>;\n}\n\nexport function useRenderers(): UIRenderers {\n const context = useContext(RenderersContext);\n if (!context) {\n throw new Error('useRenderers must be used within UIProvider');\n }\n return context;\n}\n","import { useState, useEffect } from '@framework';\nimport { useUIState, useUICapability } from './hooks/use-ui';\nimport { useAnchorRegistry } from './registries/anchor-registry';\nimport { useRenderers } from './registries/renderers-registry';\n\n/**\n * Automatically renders menus when opened\n *\n * This component:\n * 1. Listens to UI plugin state for open menus\n * 2. Looks up anchor elements from the anchor registry\n * 3. Renders menus using the user-provided menu renderer\n */\nexport interface AutoMenuRendererProps {\n container?: HTMLElement | null;\n documentId: string; // Which document's menus to render\n}\n\nexport function AutoMenuRenderer({ container, documentId }: AutoMenuRendererProps) {\n const uiState = useUIState(documentId);\n const { provides } = useUICapability();\n const anchorRegistry = useAnchorRegistry();\n const renderers = useRenderers();\n\n const [activeMenu, setActiveMenu] = useState<{\n menuId: string;\n anchorEl: HTMLElement | null;\n } | null>(null);\n\n const openMenus = uiState?.openMenus || {};\n const schema = provides?.getSchema();\n\n // Update active menu when state changes\n useEffect(() => {\n const openMenuIds = Object.keys(openMenus);\n\n if (openMenuIds.length > 0) {\n // Show the first open menu (in practice, should only be one)\n const menuId = openMenuIds[0];\n if (!menuId) {\n setActiveMenu(null);\n return;\n }\n\n const menuState = openMenus[menuId];\n if (menuState && menuState.triggeredByItemId) {\n // Look up anchor with documentId scope\n const anchor = anchorRegistry.getAnchor(documentId, menuState.triggeredByItemId);\n setActiveMenu({ menuId, anchorEl: anchor });\n } else {\n setActiveMenu(null);\n }\n } else {\n setActiveMenu(null);\n }\n }, [openMenus, anchorRegistry, documentId]);\n\n const handleClose = () => {\n if (activeMenu) {\n provides?.forDocument(documentId).closeMenu(activeMenu.menuId);\n }\n };\n\n if (!activeMenu || !schema) {\n return null;\n }\n\n const menuSchema = schema.menus[activeMenu.menuId];\n if (!menuSchema) {\n console.warn(`Menu \"${activeMenu.menuId}\" not found in schema`);\n return null;\n }\n\n // Use the user-provided menu renderer\n const MenuRenderer = renderers.menu;\n\n return (\n <MenuRenderer\n schema={menuSchema}\n documentId={documentId}\n anchorEl={activeMenu.anchorEl}\n onClose={handleClose}\n container={container}\n />\n );\n}\n","import { UI_ATTRIBUTES, UI_SELECTORS } from '@embedpdf/plugin-ui';\nimport { useUICapability, useUIPlugin } from './hooks/use-ui';\nimport { UIContainerContext, UIContainerContextValue } from './hooks/use-ui-container';\nimport {\n useState,\n useEffect,\n useRef,\n useMemo,\n useCallback,\n ReactNode,\n HTMLAttributes,\n} from '@framework';\n\n/**\n * Find the style injection target for an element.\n * Returns the shadow root if inside one, otherwise document.head.\n */\nfunction getStyleTarget(element: HTMLElement): HTMLElement | ShadowRoot {\n const root = element.getRootNode();\n if (root instanceof ShadowRoot) {\n return root;\n }\n return document.head;\n}\n\ninterface UIRootProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n}\n\n/**\n * Internal component that handles:\n * 1. Injecting the generated stylesheet (into shadow root or document.head)\n * 2. Managing the data-disabled-categories attribute\n * 3. Updating styles on locale changes\n */\nexport function UIRoot({ children, style, ...restProps }: UIRootProps) {\n const { plugin } = useUIPlugin();\n const { provides } = useUICapability();\n const [disabledCategories, setDisabledCategories] = useState<string[]>([]);\n const [hiddenItems, setHiddenItems] = useState<string[]>([]);\n const styleElRef = useRef<HTMLStyleElement | null>(null);\n const styleTargetRef = useRef<HTMLElement | ShadowRoot | null>(null);\n const previousElementRef = useRef<HTMLDivElement | null>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n\n // Create container context value (memoized to prevent unnecessary re-renders)\n const containerContextValue = useMemo<UIContainerContextValue>(\n () => ({\n containerRef,\n getContainer: () => containerRef.current,\n }),\n [],\n );\n\n // Callback ref that handles style injection when element mounts\n // Handles React Strict Mode by tracking previous element\n const rootRefCallback = useCallback(\n (element: HTMLDivElement | null) => {\n const previousElement = previousElementRef.current;\n\n // Update refs\n previousElementRef.current = element;\n (containerRef as any).current = element;\n\n // If element is null (unmount), don't do anything yet\n // React Strict Mode will remount, so we'll handle cleanup in useEffect\n if (!element) {\n return;\n }\n\n // If element changed (or is new) and plugin is available, inject styles\n if (element !== previousElement && plugin) {\n const styleTarget = getStyleTarget(element);\n styleTargetRef.current = styleTarget;\n\n // Check if styles already exist in this target\n const existingStyle = styleTarget.querySelector(\n UI_SELECTORS.STYLES,\n ) as HTMLStyleElement | null;\n\n if (existingStyle) {\n styleElRef.current = existingStyle;\n // Update content in case locale changed\n existingStyle.textContent = plugin.getStylesheet();\n return;\n }\n\n // Create and inject stylesheet\n const stylesheet = plugin.getStylesheet();\n const styleEl = document.createElement('style');\n styleEl.setAttribute(UI_ATTRIBUTES.STYLES, '');\n styleEl.textContent = stylesheet;\n\n if (styleTarget instanceof ShadowRoot) {\n // For shadow root, prepend before other content\n styleTarget.insertBefore(styleEl, styleTarget.firstChild);\n } else {\n styleTarget.appendChild(styleEl);\n }\n\n styleElRef.current = styleEl;\n }\n },\n [plugin],\n );\n\n // Cleanup on actual unmount (not Strict Mode remount)\n useEffect(() => {\n return () => {\n // Only cleanup if we're actually unmounting (not just Strict Mode)\n // The style element will be reused if component remounts\n if (styleElRef.current?.parentNode && !previousElementRef.current) {\n styleElRef.current.remove();\n }\n styleElRef.current = null;\n styleTargetRef.current = null;\n };\n }, []);\n\n // Subscribe to stylesheet invalidation (locale changes, schema merges)\n useEffect(() => {\n if (!plugin) return;\n\n return plugin.onStylesheetInvalidated(() => {\n // Update the style element content\n if (styleElRef.current) {\n styleElRef.current.textContent = plugin.getStylesheet();\n }\n });\n }, [plugin]);\n\n // Subscribe to category and hidden items changes\n useEffect(() => {\n if (!provides) return;\n\n setDisabledCategories(provides.getDisabledCategories());\n setHiddenItems(provides.getHiddenItems());\n\n return provides.onCategoryChanged(({ disabledCategories, hiddenItems }) => {\n setDisabledCategories(disabledCategories);\n setHiddenItems(hiddenItems);\n });\n }, [provides]);\n\n // Build the disabled categories attribute value\n const disabledCategoriesAttr = useMemo(\n () => (disabledCategories.length > 0 ? disabledCategories.join(' ') : undefined),\n [disabledCategories],\n );\n\n // Build the hidden items attribute value\n const hiddenItemsAttr = useMemo(\n () => (hiddenItems.length > 0 ? hiddenItems.join(' ') : undefined),\n [hiddenItems],\n );\n\n const combinedStyle = useMemo(() => {\n const base = { containerType: 'inline-size' as const };\n if (style && typeof style === 'object') {\n return { ...base, ...style };\n }\n return base;\n }, [style]);\n\n const rootProps = {\n [UI_ATTRIBUTES.ROOT]: '',\n [UI_ATTRIBUTES.DISABLED_CATEGORIES]: disabledCategoriesAttr,\n [UI_ATTRIBUTES.HIDDEN_ITEMS]: hiddenItemsAttr,\n };\n\n return (\n <UIContainerContext.Provider value={containerContextValue}>\n <div ref={rootRefCallback} {...rootProps} {...restProps} style={combinedStyle}>\n {children}\n </div>\n </UIContainerContext.Provider>\n );\n}\n","import type { ReactNode, ComponentType, HTMLAttributes } from '@framework';\nimport { AnchorRegistryProvider } from './registries/anchor-registry';\nimport { ComponentRegistryProvider } from './registries/component-registry';\nimport { RenderersProvider } from './registries/renderers-registry';\nimport { BaseComponentProps, UIRenderers } from './types';\nimport { AutoMenuRenderer } from './auto-menu-renderer';\nimport { UIRoot } from './root';\n\n/**\n * UIProvider Props\n */\nexport interface UIProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n\n /**\n * Document ID for this UI context\n * Required for menu rendering\n */\n documentId: string;\n\n /**\n * Custom component registry\n * Maps component IDs to components\n */\n components?: Record<string, ComponentType<BaseComponentProps>>;\n\n /**\n * REQUIRED: User-provided renderers\n * These define how toolbars, panels, and menus are displayed\n */\n renderers: UIRenderers;\n\n /**\n * Optional: Container for menu portal\n * Defaults to document.body\n */\n menuContainer?: HTMLElement | null;\n}\n\n/**\n * UIProvider - Single provider for all UI plugin functionality\n *\n * Manages:\n * - Anchor registry for menu positioning\n * - Component registry for custom components\n * - Renderers for toolbars, panels, and menus\n * - Automatic menu rendering\n *\n * @example\n * ```tsx\n * <EmbedPDF engine={engine} plugins={plugins}>\n * {({ pluginsReady }) => (\n * pluginsReady && (\n * <DocumentContext>\n * {({ activeDocumentId }) => (\n * activeDocumentId && (\n * <UIProvider\n * documentId={activeDocumentId}\n * components={{\n * 'thumbnail-panel': ThumbnailPanel,\n * 'bookmark-panel': BookmarkPanel,\n * }}\n * renderers={{\n * toolbar: ToolbarRenderer,\n * panel: PanelRenderer,\n * menu: MenuRenderer,\n * }}\n * >\n * <ViewerLayout />\n * </UIProvider>\n * )\n * )}\n * </DocumentContext>\n * )\n * )}\n * </EmbedPDF>\n * ```\n */\nexport function UIProvider({\n children,\n documentId,\n components = {},\n renderers,\n menuContainer,\n ...restProps\n}: UIProviderProps) {\n return (\n <AnchorRegistryProvider>\n <ComponentRegistryProvider initialComponents={components}>\n <RenderersProvider renderers={renderers}>\n <UIRoot {...restProps}>\n {children}\n {/* Automatically render menus for this document */}\n <AutoMenuRenderer documentId={documentId} container={menuContainer} />\n </UIRoot>\n </RenderersProvider>\n </ComponentRegistryProvider>\n </AnchorRegistryProvider>\n );\n}\n","import { useComponentRegistry } from '../registries/component-registry';\n\n/**\n * Helper utilities for building renderers\n */\nexport function useItemRenderer() {\n const componentRegistry = useComponentRegistry();\n\n return {\n /**\n * Render a custom component by ID\n *\n * @param componentId - Component ID from schema\n * @param documentId - Document ID\n * @param props - Additional props to pass to component\n * @returns Rendered component or null if not found\n */\n renderCustomComponent: (componentId: string, documentId: string, props?: any) => {\n const Component = componentRegistry.get(componentId);\n\n if (!Component) {\n console.error(`Component \"${componentId}\" not found in registry`);\n return null;\n }\n\n return <Component documentId={documentId} {...(props || {})} />;\n },\n };\n}\n","import { useCallback, useRef } from '@framework';\nimport { useAnchorRegistry } from '../registries/anchor-registry';\n\n/**\n * Register a DOM element as an anchor for menus\n *\n * @param documentId - Document ID\n * @param itemId - Item ID (typically matches the toolbar/menu item ID)\n * @returns Ref callback to attach to the element\n *\n * @example\n * ```tsx\n * function ZoomButton({ documentId }: Props) {\n * const anchorRef = useRegisterAnchor(documentId, 'zoom-button');\n *\n * return <button ref={anchorRef}>Zoom</button>;\n * }\n * ```\n */\nexport function useRegisterAnchor(\n documentId: string,\n itemId: string,\n): (element: HTMLElement | null) => void {\n const registry = useAnchorRegistry();\n const elementRef = useRef<HTMLElement | null>(null);\n const documentIdRef = useRef(documentId);\n const itemIdRef = useRef(itemId);\n\n // Keep refs in sync\n documentIdRef.current = documentId;\n itemIdRef.current = itemId;\n\n // Return stable callback that uses refs\n return useCallback(\n (element: HTMLElement | null) => {\n // Store previous element\n const previousElement = elementRef.current;\n\n // Update ref\n elementRef.current = element;\n\n // Handle registration/unregistration\n if (element) {\n // Register new element\n if (element !== previousElement) {\n registry.register(documentIdRef.current, itemIdRef.current, element);\n }\n } else if (previousElement) {\n // Element is now null, but we had one before - unregister\n registry.unregister(documentIdRef.current, itemIdRef.current);\n }\n },\n [registry], // Only depend on registry!\n );\n}\n","import { useUICapability, useUIState } from './use-ui';\nimport { useRenderers } from '../registries/renderers-registry';\n\n/**\n * High-level hook for rendering UI from schema\n *\n * Provides simple functions to render toolbars, sidebars, and modals.\n * Always passes isOpen state to renderers so they can control animations.\n *\n * Automatically subscribes to UI state changes for the given document.\n */\nexport function useSchemaRenderer(documentId: string) {\n const renderers = useRenderers();\n const { provides } = useUICapability();\n const schema = provides?.getSchema();\n const uiState = useUIState(documentId); // Subscribe to state changes\n\n return {\n /**\n * Render a toolbar by placement and slot\n *\n * Always renders with isOpen state when toolbar exists in slot.\n *\n * @param placement - 'top' | 'bottom' | 'left' | 'right'\n * @param slot - Slot name (e.g. 'main', 'secondary')\n *\n * @example\n * ```tsx\n * {renderToolbar('top', 'main')}\n * {renderToolbar('top', 'secondary')}\n * ```\n */\n renderToolbar: (placement: 'top' | 'bottom' | 'left' | 'right', slot: string) => {\n if (!schema || !provides || !uiState) return null;\n\n const slotKey = `${placement}-${slot}`;\n const toolbarSlot = uiState.activeToolbars[slotKey];\n\n // If no toolbar in this slot, nothing to render\n if (!toolbarSlot) return null;\n\n const toolbarSchema = schema.toolbars[toolbarSlot.toolbarId];\n if (!toolbarSchema) {\n console.warn(`Toolbar \"${toolbarSlot.toolbarId}\" not found in schema`);\n return null;\n }\n\n // Check if toolbar is closable\n const isClosable = !toolbarSchema.permanent;\n\n const handleClose = isClosable\n ? () => {\n provides.forDocument(documentId).closeToolbarSlot(placement, slot);\n }\n : undefined;\n\n const ToolbarRenderer = renderers.toolbar;\n\n // ALWAYS render, pass isOpen state\n return (\n <ToolbarRenderer\n key={toolbarSlot.toolbarId}\n schema={toolbarSchema}\n documentId={documentId}\n isOpen={toolbarSlot.isOpen}\n onClose={handleClose}\n />\n );\n },\n\n /**\n * Render a sidebar by placement and slot\n *\n * ALWAYS renders (when sidebar exists in slot) with isOpen state.\n * Your renderer controls whether to display or animate.\n *\n * @param placement - 'left' | 'right' | 'top' | 'bottom'\n * @param slot - Slot name (e.g. 'main', 'secondary', 'inspector')\n *\n * @example\n * ```tsx\n * {renderSidebar('left', 'main')}\n * {renderSidebar('right', 'main')}\n * ```\n */\n renderSidebar: (placement: 'left' | 'right' | 'top' | 'bottom', slot: string) => {\n if (!schema || !provides || !uiState) return null;\n const slotKey = `${placement}-${slot}`;\n const sidebarSlot = uiState.activeSidebars[slotKey];\n\n // If no sidebar in this slot, nothing to render\n if (!sidebarSlot) return null;\n\n const sidebarSchema = schema.sidebars?.[sidebarSlot.sidebarId];\n if (!sidebarSchema) {\n console.warn(`Sidebar \"${sidebarSlot.sidebarId}\" not found in schema`);\n return null;\n }\n\n const handleClose = () => {\n provides.forDocument(documentId).closeSidebarSlot(placement, slot);\n };\n\n const SidebarRenderer = renderers.sidebar;\n\n // ALWAYS render, pass isOpen state\n // Your renderer decides whether to return null or animate\n return (\n <SidebarRenderer\n key={sidebarSlot.sidebarId}\n schema={sidebarSchema}\n documentId={documentId}\n isOpen={sidebarSlot.isOpen}\n onClose={handleClose}\n />\n );\n },\n\n /**\n * Render the active modal (if any)\n *\n * Only one modal can be active at a time.\n * Modals are defined in schema.modals.\n *\n * Supports animation lifecycle:\n * - isOpen: true = visible\n * - isOpen: false = animate out (modal still rendered)\n * - onExited called after animation → modal removed\n *\n * @example\n * ```tsx\n * {renderModal()}\n * ```\n */\n renderModal: () => {\n if (!schema || !provides || !uiState?.activeModal) return null;\n\n const { modalId, isOpen } = uiState.activeModal;\n\n const modalSchema = schema.modals?.[modalId];\n if (!modalSchema) {\n console.warn(`Modal \"${modalId}\" not found in schema`);\n return null;\n }\n\n const handleClose = () => {\n provides.forDocument(documentId).closeModal();\n };\n\n const handleExited = () => {\n provides.forDocument(documentId).clearModal();\n };\n\n const ModalRenderer = renderers.modal;\n if (!ModalRenderer) {\n console.warn('No modal renderer registered');\n return null;\n }\n\n return (\n <ModalRenderer\n key={modalId}\n schema={modalSchema}\n documentId={documentId}\n isOpen={isOpen}\n onClose={handleClose}\n onExited={handleExited}\n />\n );\n },\n\n /**\n * Helper: Get all active toolbars for this document\n * Useful for batch rendering or debugging\n */\n getActiveToolbars: () => {\n if (!uiState) return [];\n return Object.entries(uiState.activeToolbars).map(([slotKey, toolbarSlot]) => {\n const [placement, slot] = slotKey.split('-');\n return {\n placement,\n slot,\n toolbarId: toolbarSlot.toolbarId,\n isOpen: toolbarSlot.isOpen,\n };\n });\n },\n\n /**\n * Helper: Get all active sidebars for this document\n * Useful for batch rendering or debugging\n */\n getActiveSidebars: () => {\n if (!uiState) return [];\n return Object.entries(uiState.activeSidebars).map(([slotKey, sidebarSlot]) => {\n const [placement, slot] = slotKey.split('-');\n return {\n placement,\n slot,\n sidebarId: sidebarSlot.sidebarId,\n isOpen: sidebarSlot.isOpen,\n };\n });\n },\n\n /**\n * Render all enabled overlays\n *\n * Overlays are floating components positioned over the document content.\n * Unlike modals, multiple overlays can be visible and they don't block interaction.\n *\n * @example\n * ```tsx\n * <div className=\"relative\">\n * {children}\n * {renderOverlays()}\n * </div>\n * ```\n */\n renderOverlays: () => {\n if (!schema?.overlays || !provides) return null;\n\n const OverlayRenderer = renderers.overlay;\n if (!OverlayRenderer) {\n return null;\n }\n\n const overlays = Object.values(schema.overlays);\n if (overlays.length === 0) return null;\n\n return (\n <>\n {overlays.map((overlaySchema) => (\n <OverlayRenderer\n key={overlaySchema.id}\n schema={overlaySchema}\n documentId={documentId}\n />\n ))}\n </>\n );\n },\n };\n}\n","import { useCallback } from '@framework';\nimport { SelectionMenuPropsBase, SelectionMenuRenderFn } from '@embedpdf/utils/@framework';\nimport { useUICapability } from './use-ui';\nimport { useRenderers } from '../registries/renderers-registry';\n\n/**\n * Creates a render function for a selection menu from the schema\n *\n * @param menuId - The selection menu ID from schema\n * @param documentId - Document ID\n * @returns A render function compatible with layer selectionMenu props\n */\nexport function useSelectionMenu<TContext extends { type: string }>(\n menuId: string,\n documentId: string,\n): SelectionMenuRenderFn<TContext> | undefined {\n const { provides } = useUICapability();\n const renderers = useRenderers();\n\n const renderFn = useCallback(\n (props: SelectionMenuPropsBase<TContext>) => {\n const schema = provides?.getSchema();\n const menuSchema = schema?.selectionMenus?.[menuId];\n\n if (!menuSchema) {\n return null;\n }\n\n if (!props.selected) {\n return null;\n }\n\n const SelectionMenuRenderer = renderers.selectionMenu;\n\n return <SelectionMenuRenderer schema={menuSchema} documentId={documentId} props={props} />;\n },\n [provides, renderers, menuId, documentId],\n );\n\n // Return undefined if schema doesn't have this menu\n const schema = provides?.getSchema();\n if (!schema?.selectionMenus?.[menuId]) {\n return undefined;\n }\n\n return renderFn;\n}\n"],"names":["useUICapability","useCapability","UIPlugin","id","useUIPlugin","usePlugin","useUIState","documentId","provides","state","setState","useState","useEffect","scope","forDocument","getState","unsubToolbar","onToolbarChanged","unsubSidebar","onSidebarChanged","unsubModal","onModalChanged","unsubMenu","onMenuChanged","UIContainerContext","createContext","AnchorRegistryContext","AnchorRegistryProvider","children","anchorsRef","useRef","Map","registry","register","useCallback","itemId","element","key","current","set","unregister","delete","getAnchor","get","Provider","value","useAnchorRegistry","context","useContext","Error","ComponentRegistryContext","ComponentRegistryProvider","initialComponents","componentsRef","Object","entries","component","has","getRegisteredIds","Array","from","keys","useComponentRegistry","RenderersContext","RenderersProvider","renderers","useRenderers","AutoMenuRenderer","container","uiState","anchorRegistry","activeMenu","setActiveMenu","openMenus","schema","getSchema","openMenuIds","length","menuId","menuState","triggeredByItemId","anchor","anchorEl","menuSchema","menus","console","warn","MenuRenderer","menu","jsx","onClose","closeMenu","UIRoot","style","restProps","plugin","disabledCategories","setDisabledCategories","hiddenItems","setHiddenItems","styleElRef","styleTargetRef","previousElementRef","containerRef","containerContextValue","useMemo","getContainer","rootRefCallback","previousElement","styleTarget","root","getRootNode","ShadowRoot","document","head","getStyleTarget","existingStyle","querySelector","UI_SELECTORS","STYLES","textContent","getStylesheet","stylesheet","styleEl","createElement","setAttribute","UI_ATTRIBUTES","insertBefore","firstChild","appendChild","_a","parentNode","remove","onStylesheetInvalidated","getDisabledCategories","getHiddenItems","onCategoryChanged","disabledCategoriesAttr","join","hiddenItemsAttr","combinedStyle","base","containerType","rootProps","ROOT","DISABLED_CATEGORIES","HIDDEN_ITEMS","ref","components","menuContainer","jsxs","componentRegistry","renderCustomComponent","componentId","props","Component","error","elementRef","documentIdRef","itemIdRef","renderToolbar","placement","slot","slotKey","toolbarSlot","activeToolbars","toolbarSchema","toolbars","toolbarId","handleClose","permanent","closeToolbarSlot","ToolbarRenderer","toolbar","isOpen","renderSidebar","sidebarSlot","activeSidebars","sidebarSchema","sidebars","sidebarId","SidebarRenderer","sidebar","closeSidebarSlot","renderModal","activeModal","modalId","modalSchema","modals","ModalRenderer","modal","closeModal","onExited","clearModal","getActiveToolbars","map","split","getActiveSidebars","renderOverlays","overlays","OverlayRenderer","overlay","values","Fragment","overlaySchema","renderFn","selectionMenus","selected","SelectionMenuRenderer","selectionMenu"],"mappings":"wOAKaA,EAAkB,IAAMC,gBAAwBC,EAAAA,SAASC,IACzDC,EAAc,IAAMC,YAAoBH,EAAAA,SAASC,IAKjDG,EAAcC,IACzB,MAAMC,SAAEA,GAAaR,KACdS,EAAOC,GAAYC,EAAAA,SAAiC,MAs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OO,SACL2E,EACAvE,SAEA,MAAMC,SAAEA,GAAaR,IACfiE,EAAYC,IAEZ2I,EAAW3K,EAAAA,YACdwH,UACC,MAAMhF,EAAS,MAAAlE,OAAA,EAAAA,EAAUmE,YACnBQ,EAAaT,OAAAA,EAAAA,MAAAA,OAAAA,EAAAA,EAAQoI,uBAARpI,EAAyBI,GAE5C,IAAKK,EACH,OAAO,KAGT,IAAKuE,EAAMqD,SACT,OAAO,KAGT,MAAMC,EAAwB/I,EAAUgJ,cAExC,OAAOxH,EAAAA,IAACuH,EAAA,CAAsBtI,OAAQS,EAAY5E,aAAwBmJ,WAE5E,CAAClJ,EAAUyD,EAAWa,EAAQvE,IAI1BmE,EAAS,MAAAlE,OAAA,EAAAA,EAAUmE,YACzB,GAAK,OAAAuD,EAAA,MAAAxD,OAAA,EAAAA,EAAQoI,qBAAR,EAAA5E,EAAyBpD,GAI9B,OAAO+H,CACT,mDVLO,WACL,MAAM9J,EAAUC,EAAAA,WAAWxB,GAC3B,IAAKuB,EACH,MAAM,IAAIE,MAAM,mDAElB,OAAOF,CACT,4CDN2B,KACzB,MAAMvC,SAAEA,GAAaR,IACrB,aAAOQ,WAAUmE,cAAe"}
@@ -2,8 +2,8 @@ import { useCapability, usePlugin } from "@embedpdf/core/preact";
2
2
  import { UIPlugin, UI_SELECTORS, UI_ATTRIBUTES } from "@embedpdf/plugin-ui";
3
3
  export * from "@embedpdf/plugin-ui";
4
4
  import { createContext } from "preact";
5
- import { useState, useEffect, useRef, useCallback, useContext, useMemo } from "preact/hooks";
6
- import { jsx, jsxs } from "preact/jsx-runtime";
5
+ import { useState, useEffect, useContext, useRef, useCallback, useMemo } from "preact/hooks";
6
+ import { jsx, Fragment, jsxs } from "preact/jsx-runtime";
7
7
  const useUICapability = () => useCapability(UIPlugin.id);
8
8
  const useUIPlugin = () => usePlugin(UIPlugin.id);
9
9
  const useUIState = (documentId) => {
@@ -14,12 +14,12 @@ const useUIState = (documentId) => {
14
14
  const scope = provides.forDocument(documentId);
15
15
  setState(scope.getState());
16
16
  const unsubToolbar = scope.onToolbarChanged(() => setState(scope.getState()));
17
- const unsubPanel = scope.onPanelChanged(() => setState(scope.getState()));
17
+ const unsubSidebar = scope.onSidebarChanged(() => setState(scope.getState()));
18
18
  const unsubModal = scope.onModalChanged(() => setState(scope.getState()));
19
19
  const unsubMenu = scope.onMenuChanged(() => setState(scope.getState()));
20
20
  return () => {
21
21
  unsubToolbar();
22
- unsubPanel();
22
+ unsubSidebar();
23
23
  unsubModal();
24
24
  unsubMenu();
25
25
  };
@@ -30,6 +30,14 @@ const useUISchema = () => {
30
30
  const { provides } = useUICapability();
31
31
  return (provides == null ? void 0 : provides.getSchema()) ?? null;
32
32
  };
33
+ const UIContainerContext = createContext(null);
34
+ function useUIContainer() {
35
+ const context = useContext(UIContainerContext);
36
+ if (!context) {
37
+ throw new Error("useUIContainer must be used within a UIProvider");
38
+ }
39
+ return context;
40
+ }
33
41
  const AnchorRegistryContext = createContext(null);
34
42
  function AnchorRegistryProvider({ children }) {
35
43
  const anchorsRef = useRef(/* @__PURE__ */ new Map());
@@ -192,9 +200,9 @@ function useSchemaRenderer(documentId) {
192
200
  );
193
201
  },
194
202
  /**
195
- * Render a panel by placement and slot
203
+ * Render a sidebar by placement and slot
196
204
  *
197
- * ALWAYS renders (when panel exists in slot) with isOpen state.
205
+ * ALWAYS renders (when sidebar exists in slot) with isOpen state.
198
206
  * Your renderer controls whether to display or animate.
199
207
  *
200
208
  * @param placement - 'left' | 'right' | 'top' | 'bottom'
@@ -202,33 +210,82 @@ function useSchemaRenderer(documentId) {
202
210
  *
203
211
  * @example
204
212
  * ```tsx
205
- * {renderPanel('left', 'main')}
206
- * {renderPanel('right', 'main')}
213
+ * {renderSidebar('left', 'main')}
214
+ * {renderSidebar('right', 'main')}
207
215
  * ```
208
216
  */
209
- renderPanel: (placement, slot) => {
217
+ renderSidebar: (placement, slot) => {
218
+ var _a;
210
219
  if (!schema || !provides || !uiState) return null;
211
220
  const slotKey = `${placement}-${slot}`;
212
- const panelSlot = uiState.activePanels[slotKey];
213
- if (!panelSlot) return null;
214
- const panelSchema = schema.panels[panelSlot.panelId];
215
- if (!panelSchema) {
216
- console.warn(`Panel "${panelSlot.panelId}" not found in schema`);
221
+ const sidebarSlot = uiState.activeSidebars[slotKey];
222
+ if (!sidebarSlot) return null;
223
+ const sidebarSchema = (_a = schema.sidebars) == null ? void 0 : _a[sidebarSlot.sidebarId];
224
+ if (!sidebarSchema) {
225
+ console.warn(`Sidebar "${sidebarSlot.sidebarId}" not found in schema`);
217
226
  return null;
218
227
  }
219
228
  const handleClose = () => {
220
- provides.forDocument(documentId).closePanelSlot(placement, slot);
229
+ provides.forDocument(documentId).closeSidebarSlot(placement, slot);
221
230
  };
222
- const PanelRenderer = renderers.panel;
231
+ const SidebarRenderer = renderers.sidebar;
223
232
  return /* @__PURE__ */ jsx(
224
- PanelRenderer,
233
+ SidebarRenderer,
225
234
  {
226
- schema: panelSchema,
235
+ schema: sidebarSchema,
227
236
  documentId,
228
- isOpen: panelSlot.isOpen,
237
+ isOpen: sidebarSlot.isOpen,
229
238
  onClose: handleClose
230
239
  },
231
- panelSlot.panelId
240
+ sidebarSlot.sidebarId
241
+ );
242
+ },
243
+ /**
244
+ * Render the active modal (if any)
245
+ *
246
+ * Only one modal can be active at a time.
247
+ * Modals are defined in schema.modals.
248
+ *
249
+ * Supports animation lifecycle:
250
+ * - isOpen: true = visible
251
+ * - isOpen: false = animate out (modal still rendered)
252
+ * - onExited called after animation → modal removed
253
+ *
254
+ * @example
255
+ * ```tsx
256
+ * {renderModal()}
257
+ * ```
258
+ */
259
+ renderModal: () => {
260
+ var _a;
261
+ if (!schema || !provides || !(uiState == null ? void 0 : uiState.activeModal)) return null;
262
+ const { modalId, isOpen } = uiState.activeModal;
263
+ const modalSchema = (_a = schema.modals) == null ? void 0 : _a[modalId];
264
+ if (!modalSchema) {
265
+ console.warn(`Modal "${modalId}" not found in schema`);
266
+ return null;
267
+ }
268
+ const handleClose = () => {
269
+ provides.forDocument(documentId).closeModal();
270
+ };
271
+ const handleExited = () => {
272
+ provides.forDocument(documentId).clearModal();
273
+ };
274
+ const ModalRenderer = renderers.modal;
275
+ if (!ModalRenderer) {
276
+ console.warn("No modal renderer registered");
277
+ return null;
278
+ }
279
+ return /* @__PURE__ */ jsx(
280
+ ModalRenderer,
281
+ {
282
+ schema: modalSchema,
283
+ documentId,
284
+ isOpen,
285
+ onClose: handleClose,
286
+ onExited: handleExited
287
+ },
288
+ modalId
232
289
  );
233
290
  },
234
291
  /**
@@ -248,20 +305,51 @@ function useSchemaRenderer(documentId) {
248
305
  });
249
306
  },
250
307
  /**
251
- * Helper: Get all active panels for this document
308
+ * Helper: Get all active sidebars for this document
252
309
  * Useful for batch rendering or debugging
253
310
  */
254
- getActivePanels: () => {
311
+ getActiveSidebars: () => {
255
312
  if (!uiState) return [];
256
- return Object.entries(uiState.activePanels).map(([slotKey, panelSlot]) => {
313
+ return Object.entries(uiState.activeSidebars).map(([slotKey, sidebarSlot]) => {
257
314
  const [placement, slot] = slotKey.split("-");
258
315
  return {
259
316
  placement,
260
317
  slot,
261
- panelId: panelSlot.panelId,
262
- isOpen: panelSlot.isOpen
318
+ sidebarId: sidebarSlot.sidebarId,
319
+ isOpen: sidebarSlot.isOpen
263
320
  };
264
321
  });
322
+ },
323
+ /**
324
+ * Render all enabled overlays
325
+ *
326
+ * Overlays are floating components positioned over the document content.
327
+ * Unlike modals, multiple overlays can be visible and they don't block interaction.
328
+ *
329
+ * @example
330
+ * ```tsx
331
+ * <div className="relative">
332
+ * {children}
333
+ * {renderOverlays()}
334
+ * </div>
335
+ * ```
336
+ */
337
+ renderOverlays: () => {
338
+ if (!(schema == null ? void 0 : schema.overlays) || !provides) return null;
339
+ const OverlayRenderer = renderers.overlay;
340
+ if (!OverlayRenderer) {
341
+ return null;
342
+ }
343
+ const overlays = Object.values(schema.overlays);
344
+ if (overlays.length === 0) return null;
345
+ return /* @__PURE__ */ jsx(Fragment, { children: overlays.map((overlaySchema) => /* @__PURE__ */ jsx(
346
+ OverlayRenderer,
347
+ {
348
+ schema: overlaySchema,
349
+ documentId
350
+ },
351
+ overlaySchema.id
352
+ )) });
265
353
  }
266
354
  };
267
355
  }
@@ -350,17 +438,27 @@ function getStyleTarget(element) {
350
438
  }
351
439
  return document.head;
352
440
  }
353
- function UIRoot({ children, ...restProps }) {
441
+ function UIRoot({ children, style, ...restProps }) {
354
442
  const { plugin } = useUIPlugin();
355
443
  const { provides } = useUICapability();
356
444
  const [disabledCategories, setDisabledCategories] = useState([]);
445
+ const [hiddenItems, setHiddenItems] = useState([]);
357
446
  const styleElRef = useRef(null);
358
447
  const styleTargetRef = useRef(null);
359
448
  const previousElementRef = useRef(null);
449
+ const containerRef = useRef(null);
450
+ const containerContextValue = useMemo(
451
+ () => ({
452
+ containerRef,
453
+ getContainer: () => containerRef.current
454
+ }),
455
+ []
456
+ );
360
457
  const rootRefCallback = useCallback(
361
458
  (element) => {
362
459
  const previousElement = previousElementRef.current;
363
460
  previousElementRef.current = element;
461
+ containerRef.current = element;
364
462
  if (!element) {
365
463
  return;
366
464
  }
@@ -410,28 +508,33 @@ function UIRoot({ children, ...restProps }) {
410
508
  useEffect(() => {
411
509
  if (!provides) return;
412
510
  setDisabledCategories(provides.getDisabledCategories());
413
- return provides.onCategoryChanged(({ disabledCategories: disabledCategories2 }) => {
511
+ setHiddenItems(provides.getHiddenItems());
512
+ return provides.onCategoryChanged(({ disabledCategories: disabledCategories2, hiddenItems: hiddenItems2 }) => {
414
513
  setDisabledCategories(disabledCategories2);
514
+ setHiddenItems(hiddenItems2);
415
515
  });
416
516
  }, [provides]);
417
517
  const disabledCategoriesAttr = useMemo(
418
518
  () => disabledCategories.length > 0 ? disabledCategories.join(" ") : void 0,
419
519
  [disabledCategories]
420
520
  );
521
+ const hiddenItemsAttr = useMemo(
522
+ () => hiddenItems.length > 0 ? hiddenItems.join(" ") : void 0,
523
+ [hiddenItems]
524
+ );
525
+ const combinedStyle = useMemo(() => {
526
+ const base = { containerType: "inline-size" };
527
+ if (style && typeof style === "object") {
528
+ return { ...base, ...style };
529
+ }
530
+ return base;
531
+ }, [style]);
421
532
  const rootProps = {
422
533
  [UI_ATTRIBUTES.ROOT]: "",
423
- [UI_ATTRIBUTES.DISABLED_CATEGORIES]: disabledCategoriesAttr
534
+ [UI_ATTRIBUTES.DISABLED_CATEGORIES]: disabledCategoriesAttr,
535
+ [UI_ATTRIBUTES.HIDDEN_ITEMS]: hiddenItemsAttr
424
536
  };
425
- return /* @__PURE__ */ jsx(
426
- "div",
427
- {
428
- ref: rootRefCallback,
429
- ...rootProps,
430
- ...restProps,
431
- style: { containerType: "inline-size", ...restProps.style },
432
- children
433
- }
434
- );
537
+ return /* @__PURE__ */ jsx(UIContainerContext.Provider, { value: containerContextValue, children: /* @__PURE__ */ jsx("div", { ref: rootRefCallback, ...rootProps, ...restProps, style: combinedStyle, children }) });
435
538
  }
436
539
  function UIProvider({
437
540
  children,
@@ -450,6 +553,7 @@ export {
450
553
  AnchorRegistryProvider,
451
554
  ComponentRegistryProvider,
452
555
  RenderersProvider,
556
+ UIContainerContext,
453
557
  UIProvider,
454
558
  useAnchorRegistry,
455
559
  useComponentRegistry,
@@ -459,6 +563,7 @@ export {
459
563
  useSchemaRenderer,
460
564
  useSelectionMenu,
461
565
  useUICapability,
566
+ useUIContainer,
462
567
  useUIPlugin,
463
568
  useUISchema,
464
569
  useUIState