@embedpdf/plugin-ui 1.4.1 → 2.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1313 -655
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +110 -74
- package/dist/lib/index.d.ts +8 -7
- package/dist/lib/reducer.d.ts +5 -5
- package/dist/lib/schema.d.ts +257 -0
- package/dist/lib/selectors.d.ts +16 -0
- package/dist/lib/types.d.ts +185 -202
- package/dist/lib/ui-plugin.d.ts +66 -18
- package/dist/lib/utils/consts.d.ts +25 -0
- package/dist/lib/utils/index.d.ts +5 -0
- package/dist/lib/utils/responsive-utils.d.ts +10 -0
- package/dist/lib/utils/schema-merger.d.ts +15 -0
- package/dist/lib/utils/stylesheet-generator.d.ts +40 -0
- package/dist/lib/utils/ui-props.d.ts +14 -0
- package/dist/preact/adapter.d.ts +4 -2
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +450 -49
- package/dist/preact/index.js.map +1 -1
- package/dist/preact/utils.d.ts +1 -0
- package/dist/react/adapter.d.ts +2 -2
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +449 -48
- package/dist/react/index.js.map +1 -1
- package/dist/react/utils.d.ts +1 -0
- package/dist/shared/auto-menu-renderer.d.ts +13 -0
- package/dist/shared/hooks/index.d.ts +4 -0
- package/dist/shared/hooks/use-item-renderer.d.ts +14 -0
- package/dist/shared/hooks/use-register-anchor.d.ts +17 -0
- package/dist/shared/hooks/use-schema-renderer.d.ts +61 -0
- package/dist/shared/hooks/use-selection-menu.d.ts +11 -0
- package/dist/shared/hooks/use-ui.d.ts +13 -5
- package/dist/shared/index.d.ts +4 -1
- package/dist/shared/provider.d.ts +68 -0
- package/dist/shared/registries/anchor-registry.d.ts +16 -0
- package/dist/shared/registries/component-registry.d.ts +20 -0
- package/dist/shared/registries/index.d.ts +3 -0
- package/dist/shared/registries/renderers-registry.d.ts +8 -0
- package/dist/shared/root.d.ts +12 -0
- package/dist/shared/types.d.ts +67 -0
- package/dist/shared-preact/auto-menu-renderer.d.ts +13 -0
- package/dist/shared-preact/hooks/index.d.ts +4 -0
- package/dist/shared-preact/hooks/use-item-renderer.d.ts +14 -0
- package/dist/shared-preact/hooks/use-register-anchor.d.ts +17 -0
- package/dist/shared-preact/hooks/use-schema-renderer.d.ts +61 -0
- package/dist/shared-preact/hooks/use-selection-menu.d.ts +11 -0
- package/dist/shared-preact/hooks/use-ui.d.ts +13 -5
- package/dist/shared-preact/index.d.ts +4 -1
- package/dist/shared-preact/provider.d.ts +68 -0
- package/dist/shared-preact/registries/anchor-registry.d.ts +16 -0
- package/dist/shared-preact/registries/component-registry.d.ts +20 -0
- package/dist/shared-preact/registries/index.d.ts +3 -0
- package/dist/shared-preact/registries/renderers-registry.d.ts +8 -0
- package/dist/shared-preact/root.d.ts +12 -0
- package/dist/shared-preact/types.d.ts +67 -0
- package/dist/shared-react/auto-menu-renderer.d.ts +13 -0
- package/dist/shared-react/hooks/index.d.ts +4 -0
- package/dist/shared-react/hooks/use-item-renderer.d.ts +14 -0
- package/dist/shared-react/hooks/use-register-anchor.d.ts +17 -0
- package/dist/shared-react/hooks/use-schema-renderer.d.ts +61 -0
- package/dist/shared-react/hooks/use-selection-menu.d.ts +11 -0
- package/dist/shared-react/hooks/use-ui.d.ts +13 -5
- package/dist/shared-react/index.d.ts +4 -1
- package/dist/shared-react/provider.d.ts +68 -0
- package/dist/shared-react/registries/anchor-registry.d.ts +16 -0
- package/dist/shared-react/registries/component-registry.d.ts +20 -0
- package/dist/shared-react/registries/index.d.ts +3 -0
- package/dist/shared-react/registries/renderers-registry.d.ts +8 -0
- package/dist/shared-react/root.d.ts +12 -0
- package/dist/shared-react/types.d.ts +67 -0
- package/dist/svelte/auto-menu-renderer.svelte.d.ts +15 -0
- package/dist/svelte/hooks/index.d.ts +5 -0
- package/dist/svelte/hooks/use-item-renderer.svelte.d.ts +24 -0
- package/dist/svelte/hooks/use-register-anchor.svelte.d.ts +18 -0
- package/dist/svelte/hooks/use-schema-renderer.svelte.d.ts +78 -0
- package/dist/svelte/hooks/use-selection-menu.svelte.d.ts +9 -0
- package/dist/svelte/hooks/use-ui.svelte.d.ts +34 -0
- package/dist/svelte/index.cjs +2 -0
- package/dist/svelte/index.cjs.map +1 -0
- package/dist/svelte/index.d.ts +6 -0
- package/dist/svelte/index.js +553 -0
- package/dist/svelte/index.js.map +1 -0
- package/dist/svelte/provider.svelte.d.ts +33 -0
- package/dist/svelte/registries/anchor-registry.svelte.d.ts +14 -0
- package/dist/svelte/registries/component-registry.svelte.d.ts +17 -0
- package/dist/svelte/registries/index.d.ts +3 -0
- package/dist/svelte/registries/renderers-registry.svelte.d.ts +3 -0
- package/dist/svelte/root.svelte.d.ts +8 -0
- package/dist/svelte/types.d.ts +67 -0
- package/dist/vue/auto-menu-renderer.vue.d.ts +15 -0
- package/dist/vue/hooks/index.d.ts +5 -0
- package/dist/vue/hooks/use-item-renderer.d.ts +16 -0
- package/dist/vue/hooks/use-register-anchor.d.ts +19 -0
- package/dist/vue/hooks/use-schema-renderer.d.ts +63 -0
- package/dist/vue/hooks/use-selection-menu.d.ts +28 -0
- package/dist/vue/hooks/use-ui.d.ts +940 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +6 -0
- package/dist/vue/index.js +544 -0
- package/dist/vue/index.js.map +1 -0
- package/dist/vue/provider.vue.d.ts +43 -0
- package/dist/vue/registries/anchor-registry.d.ts +14 -0
- package/dist/vue/registries/component-registry.d.ts +17 -0
- package/dist/vue/registries/index.d.ts +3 -0
- package/dist/vue/registries/renderers-registry.d.ts +3 -0
- package/dist/vue/root.vue.d.ts +13 -0
- package/dist/vue/types.d.ts +67 -0
- package/package.json +32 -9
- package/dist/lib/menu/menu-manager.d.ts +0 -98
- package/dist/lib/menu/types.d.ts +0 -91
- package/dist/lib/menu/utils.d.ts +0 -6
- package/dist/lib/ui-component.d.ts +0 -30
- package/dist/lib/utils.d.ts +0 -33
- package/dist/shared/components/component-wrapper.d.ts +0 -5
- package/dist/shared/components/index.d.ts +0 -1
- package/dist/shared/components/plugin-ui-provider.d.ts +0 -37
- package/dist/shared-preact/components/component-wrapper.d.ts +0 -5
- package/dist/shared-preact/components/index.d.ts +0 -1
- package/dist/shared-preact/components/plugin-ui-provider.d.ts +0 -37
- package/dist/shared-react/components/component-wrapper.d.ts +0 -5
- package/dist/shared-react/components/index.d.ts +0 -1
- package/dist/shared-react/components/plugin-ui-provider.d.ts +0 -37
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("@embedpdf/core/vue"),n=require("@embedpdf/plugin-ui"),o=()=>t.usePlugin(n.UIPlugin.id),r=()=>t.useCapability(n.UIPlugin.id),u=t=>{const{provides:n}=r(),o=e.ref(null);e.watch([n,()=>e.toValue(t)],([e,t],n,r)=>{if(!e)return void(o.value=null);const u=e.forDocument(t);o.value=u.getState();const l=u.onToolbarChanged(()=>{o.value=u.getState()}),a=u.onPanelChanged(()=>{o.value=u.getState()}),s=u.onModalChanged(()=>{o.value=u.getState()}),c=u.onMenuChanged(()=>{o.value=u.getState()});r(()=>{l(),a(),s(),c()})},{immediate:!0});return{provides:e.computed(()=>{var o;const r=e.toValue(t);return(null==(o=n.value)?void 0:o.forDocument(r))??null}),state:e.readonly(o)}},l=Symbol("AnchorRegistry");function a(){const t=e.ref(new Map);return{register(e,n,o){const r=`${e}:${n}`;t.value.set(r,o)},unregister(e,n){const o=`${e}:${n}`;t.value.delete(o)},getAnchor(e,n){const o=`${e}:${n}`;return t.value.get(o)||null}}}function s(){const t=a();return e.provide(l,t),t}function c(){const t=e.inject(l);if(!t)throw new Error("useAnchorRegistry must be used within UIProvider");return t}const i=Symbol("ComponentRegistry");function d(t={}){const n=e.ref(new Map(Object.entries(t)));return{register(e,t){n.value.set(e,t)},unregister(e){n.value.delete(e)},get:e=>n.value.get(e),has:e=>n.value.has(e),getRegisteredIds:()=>Array.from(n.value.keys())}}function v(t={}){const n=d(t);return e.provide(i,n),n}function p(){const t=e.inject(i);if(!t)throw new Error("useComponentRegistry must be used within UIProvider");return t}const m=Symbol("Renderers");function f(t){e.provide(m,t)}function g(){const t=e.inject(m);if(!t)throw new Error("useRenderers must be used within UIProvider");return t}const h=e.defineComponent({__name:"auto-menu-renderer",props:{documentId:{},container:{}},setup(t){const n=t,{state:o}=u(n.documentId),{provides:l}=r(),a=c(),s=g(),i=e.ref(null),d=e.computed(()=>{var e;return(null==(e=o.value)?void 0:e.openMenus)||{}}),v=e.computed(()=>{var e;return null==(e=l.value)?void 0:e.getSchema()});e.watch(d,e=>{const t=Object.keys(e);if(t.length>0){const o=t[0];if(!o)return void(i.value=null);const r=e[o];if(r&&r.triggeredByItemId){const e=a.getAnchor(n.documentId,r.triggeredByItemId);i.value={menuId:o,anchorEl:e}}else i.value=null}else i.value=null},{immediate:!0});const p=e.computed(()=>{if(!i.value||!v.value)return null;const e=v.value.menus[i.value.menuId];return e||(console.warn(`Menu "${i.value.menuId}" not found in schema`),null)}),m=()=>{var e;i.value&&(null==(e=l.value)||e.forDocument(n.documentId).closeMenu(i.value.menuId))},f=e.computed(()=>s.menu);return(n,o)=>i.value&&p.value&&f.value?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(f.value),{key:0,schema:p.value,documentId:t.documentId,anchorEl:i.value.anchorEl,onClose:m,container:t.container},null,40,["schema","documentId","anchorEl","container"])):e.createCommentVNode("",!0)}}),I=e.defineComponent({inheritAttrs:!1,__name:"root",setup(t){const u=e.useAttrs(),{plugin:l}=o(),{provides:a}=r(),s=e.ref([]),c=e.ref(null);let i=null,d=null;function v(){if(!c.value||!l.value)return;d=function(e){const t=e.getRootNode();return t instanceof ShadowRoot?t:document.head}(c.value);const e=d.querySelector(n.UI_SELECTORS.STYLES);if(e)return i=e,void(e.textContent=l.value.getStylesheet());const t=l.value.getStylesheet(),o=document.createElement("style");o.setAttribute(n.UI_ATTRIBUTES.STYLES,""),o.textContent=t,d instanceof ShadowRoot?d.insertBefore(o,d.firstChild):d.appendChild(o),i=o}const p=e.computed(()=>{const e={[n.UI_ATTRIBUTES.ROOT]:""};return s.value.length>0&&(e[n.UI_ATTRIBUTES.DISABLED_CATEGORIES]=s.value.join(" ")),e});let m=null,f=null;return e.onMounted(()=>{v(),l.value&&(m=l.value.onStylesheetInvalidated(()=>{i&&l.value&&(i.textContent=l.value.getStylesheet())})),a.value&&(s.value=a.value.getDisabledCategories(),f=a.value.onCategoryChanged(e=>{s.value=e.disabledCategories}))}),e.onUnmounted(()=>{(null==i?void 0:i.parentNode)&&i.remove(),i=null,d=null,null==m||m(),null==f||f()}),e.watch(l,()=>{c.value&&l.value&&v()}),(t,n)=>(e.openBlock(),e.createElementBlock("div",e.mergeProps({ref_key:"rootRef",ref:c},{...e.unref(u),...p.value},{style:{containerType:"inline-size"}}),[e.renderSlot(t.$slots,"default")],16))}}),y=e.defineComponent({inheritAttrs:!1,__name:"provider",props:{documentId:{},components:{default:()=>({})},renderers:{},menuContainer:{default:null}},setup(t){const n=e.useAttrs(),o=t;return s(),v(o.components),f(o.renderers),(o,r)=>(e.openBlock(),e.createBlock(I,e.normalizeProps(e.guardReactiveProps(e.unref(n))),{default:e.withCtx(()=>[e.renderSlot(o.$slots,"default"),e.createVNode(h,{documentId:t.documentId,container:t.menuContainer},null,8,["documentId","container"])]),_:3},16))}});exports.AutoMenuRenderer=h,exports.UIProvider=y,exports.createAnchorRegistry=a,exports.createComponentRegistry=d,exports.provideAnchorRegistry=s,exports.provideComponentRegistry=v,exports.provideRenderers=f,exports.useAnchorRegistry=c,exports.useComponentRegistry=p,exports.useItemRenderer=function(){const t=p();return{renderCustomComponent:(n,o,r)=>{const u=t.get(n);return u?e.h(u,{documentId:o,...r||{}}):(console.error(`Component "${n}" not found in registry`),null)}}},exports.useRegisterAnchor=function(t,n){const o=c(),r=e.ref(null);return e.onBeforeUnmount(()=>{r.value&&o.unregister(t,n)}),e=>{const u=(null==e?void 0:e.$el)||e;r.value&&r.value!==u&&o.unregister(t,n),r.value=u,u&&o.register(t,n,u)}},exports.useRenderers=g,exports.useSchemaRenderer=function(t){const n=g(),{provides:o}=r(),{state:l}=u(t);return{renderToolbar:(r,u)=>{var a;const s=null==(a=o.value)?void 0:a.getSchema();if(!s||!o.value||!l.value)return null;const c=`${r}-${u}`,i=l.value.activeToolbars[c];if(!i)return null;const d=s.toolbars[i.toolbarId];if(!d)return console.warn(`Toolbar "${i.toolbarId}" not found in schema`),null;const v=!d.permanent?()=>{var n;null==(n=o.value)||n.forDocument(e.toValue(t)).closeToolbarSlot(r,u)}:void 0,p=n.toolbar;return e.h(p,{key:i.toolbarId,schema:d,documentId:e.toValue(t),isOpen:i.isOpen,onClose:v})},renderPanel:(r,u)=>{var a;const s=null==(a=o.value)?void 0:a.getSchema();if(!s||!o.value||!l.value)return null;const c=`${r}-${u}`,i=l.value.activePanels[c];if(!i)return null;const d=s.panels[i.panelId];if(!d)return console.warn(`Panel "${i.panelId}" not found in schema`),null;const v=n.panel;return e.h(v,{key:i.panelId,schema:d,documentId:e.toValue(t),isOpen:i.isOpen,onClose:()=>{var n;null==(n=o.value)||n.forDocument(e.toValue(t)).closePanelSlot(r,u)}})},getActiveToolbars:()=>l.value?Object.entries(l.value.activeToolbars).map(([e,t])=>{const[n,o]=e.split("-");return{placement:n,slot:o,toolbarId:t.toolbarId,isOpen:t.isOpen}}):[],getActivePanels:()=>l.value?Object.entries(l.value.activePanels).map(([e,t])=>{const[n,o]=e.split("-");return{placement:n,slot:o,panelId:t.panelId,isOpen:t.isOpen}}):[]}},exports.useSelectionMenu=function(t,n){const{provides:o}=r(),u=g(),l=e.computed(()=>{var e;return null==(e=o.value)?void 0:e.getSchema()}),a=e.computed(()=>{var n,o;return null==(o=null==(n=l.value)?void 0:n.selectionMenus)?void 0:o[e.toValue(t)]});return e.computed(()=>{if(!a.value)return;const t=a.value,o=e.toValue(n),r=u.selectionMenu;return n=>n.selected?e.h(r,{schema:t,documentId:o,props:n}):null})},exports.useUICapability=r,exports.useUIPlugin=o,exports.useUISchema=()=>{const{provides:t}=r(),n=e.computed(()=>{var e;return(null==(e=t.value)?void 0:e.getSchema())??null});return e.readonly(n)},exports.useUIState=u,Object.keys(n).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>n[e]})});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-ui.ts","../../src/vue/registries/anchor-registry.ts","../../src/vue/registries/component-registry.ts","../../src/vue/registries/renderers-registry.ts","../../src/vue/auto-menu-renderer.vue","../../src/vue/root.vue","../../src/vue/provider.vue","../../src/vue/hooks/use-item-renderer.ts","../../src/vue/hooks/use-register-anchor.ts","../../src/vue/hooks/use-schema-renderer.ts","../../src/vue/hooks/use-selection-menu.ts"],"sourcesContent":["import { ref, watch, computed, readonly, toValue, type MaybeRefOrGetter } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { UIPlugin, UIDocumentState, UISchema } from '@embedpdf/plugin-ui';\n\nexport const useUIPlugin = () => usePlugin<UIPlugin>(UIPlugin.id);\nexport const useUICapability = () => useCapability<UIPlugin>(UIPlugin.id);\n\n/**\n * Hook for UI state for a specific document\n * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport const useUIState = (documentId: MaybeRefOrGetter<string>) => {\n const { provides } = useUICapability();\n const state = ref<UIDocumentState | null>(null);\n\n watch(\n [provides, () => toValue(documentId)],\n ([providesValue, docId], _, onCleanup) => {\n if (!providesValue) {\n state.value = null;\n return;\n }\n\n const scope = providesValue.forDocument(docId);\n\n // Set initial state\n state.value = scope.getState();\n\n // Subscribe to all changes\n const unsubToolbar = scope.onToolbarChanged(() => {\n state.value = scope.getState();\n });\n const unsubPanel = scope.onPanelChanged(() => {\n state.value = scope.getState();\n });\n const unsubModal = scope.onModalChanged(() => {\n state.value = scope.getState();\n });\n const unsubMenu = scope.onMenuChanged(() => {\n state.value = scope.getState();\n });\n\n onCleanup(() => {\n unsubToolbar();\n unsubPanel();\n unsubModal();\n unsubMenu();\n });\n },\n { immediate: true },\n );\n\n // Return a computed ref for the scoped capability\n const scopedProvides = computed(() => {\n const docId = toValue(documentId);\n return provides.value?.forDocument(docId) ?? null;\n });\n\n return {\n provides: scopedProvides,\n state: readonly(state),\n };\n};\n\n/**\n * Hook to get UI schema\n */\nexport const useUISchema = () => {\n const { provides } = useUICapability();\n const schema = computed<UISchema | null>(() => provides.value?.getSchema() ?? null);\n\n return readonly(schema);\n};\n","import { ref, inject, provide, type InjectionKey, type Ref } from 'vue';\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 AnchorRegistryKey: InjectionKey<AnchorRegistry> = Symbol('AnchorRegistry');\n\nexport function createAnchorRegistry(): AnchorRegistry {\n const anchors: Ref<Map<string, HTMLElement>> = ref(new Map());\n\n return {\n register(documentId: string, itemId: string, element: HTMLElement) {\n const key = `${documentId}:${itemId}`;\n anchors.value.set(key, element);\n },\n\n unregister(documentId: string, itemId: string) {\n const key = `${documentId}:${itemId}`;\n anchors.value.delete(key);\n },\n\n getAnchor(documentId: string, itemId: string) {\n const key = `${documentId}:${itemId}`;\n return anchors.value.get(key) || null;\n },\n };\n}\n\nexport function provideAnchorRegistry() {\n const registry = createAnchorRegistry();\n provide(AnchorRegistryKey, registry);\n return registry;\n}\n\nexport function useAnchorRegistry(): AnchorRegistry {\n const registry = inject(AnchorRegistryKey);\n if (!registry) {\n throw new Error('useAnchorRegistry must be used within UIProvider');\n }\n return registry;\n}\n","import { ref, inject, provide, type Component, type InjectionKey, type Ref } from 'vue';\nimport type { 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: Component<BaseComponentProps>): void;\n unregister(id: string): void;\n get(id: string): Component<BaseComponentProps> | undefined;\n has(id: string): boolean;\n getRegisteredIds(): string[];\n}\n\nconst ComponentRegistryKey: InjectionKey<ComponentRegistry> = Symbol('ComponentRegistry');\n\nexport function createComponentRegistry(\n initialComponents: Record<string, Component<BaseComponentProps>> = {},\n): ComponentRegistry {\n const components: Ref<Map<string, Component<BaseComponentProps>>> = ref(\n new Map(Object.entries(initialComponents)),\n );\n\n return {\n register(id: string, component: Component<BaseComponentProps>) {\n components.value.set(id, component);\n },\n\n unregister(id: string) {\n components.value.delete(id);\n },\n\n get(id: string) {\n return components.value.get(id);\n },\n\n has(id: string) {\n return components.value.has(id);\n },\n\n getRegisteredIds() {\n return Array.from(components.value.keys());\n },\n };\n}\n\nexport function provideComponentRegistry(\n initialComponents: Record<string, Component<BaseComponentProps>> = {},\n) {\n const registry = createComponentRegistry(initialComponents);\n provide(ComponentRegistryKey, registry);\n return registry;\n}\n\nexport function useComponentRegistry(): ComponentRegistry {\n const registry = inject(ComponentRegistryKey);\n if (!registry) {\n throw new Error('useComponentRegistry must be used within UIProvider');\n }\n return registry;\n}\n","import { inject, provide, type InjectionKey } from 'vue';\nimport type { UIRenderers } from '../types';\n\n/**\n * Renderers Registry\n *\n * Provides access to user-supplied renderers (toolbar, panel, menu).\n */\nconst RenderersKey: InjectionKey<UIRenderers> = Symbol('Renderers');\n\nexport function provideRenderers(renderers: UIRenderers) {\n provide(RenderersKey, renderers);\n}\n\nexport function useRenderers(): UIRenderers {\n const renderers = inject(RenderersKey);\n if (!renderers) {\n throw new Error('useRenderers must be used within UIProvider');\n }\n return renderers;\n}\n","<template>\n <component\n v-if=\"activeMenu && menuSchema && MenuRenderer\"\n :is=\"MenuRenderer\"\n :schema=\"menuSchema\"\n :documentId=\"documentId\"\n :anchorEl=\"activeMenu.anchorEl\"\n :onClose=\"handleClose\"\n :container=\"container\"\n />\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, computed, watch } from 'vue';\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 */\n\ninterface Props {\n documentId: string; // Which document's menus to render\n container?: HTMLElement | null;\n}\n\nconst props = defineProps<Props>();\n\nconst { state: uiState } = useUIState(props.documentId);\nconst { provides } = useUICapability();\nconst anchorRegistry = useAnchorRegistry();\nconst renderers = useRenderers();\n\nconst activeMenu = ref<{\n menuId: string;\n anchorEl: HTMLElement | null;\n} | null>(null);\n\nconst openMenus = computed(() => uiState.value?.openMenus || {});\nconst schema = computed(() => provides.value?.getSchema());\n\n// Update active menu when state changes\nwatch(\n openMenus,\n (menus) => {\n const openMenuIds = Object.keys(menus);\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 activeMenu.value = null;\n return;\n }\n\n const menuState = menus[menuId];\n if (menuState && menuState.triggeredByItemId) {\n // Look up anchor with documentId scope\n const anchor = anchorRegistry.getAnchor(props.documentId, menuState.triggeredByItemId);\n activeMenu.value = { menuId, anchorEl: anchor };\n } else {\n activeMenu.value = null;\n }\n } else {\n activeMenu.value = null;\n }\n },\n { immediate: true },\n);\n\nconst menuSchema = computed(() => {\n if (!activeMenu.value || !schema.value) return null;\n\n const menuSchemaValue = schema.value.menus[activeMenu.value.menuId];\n if (!menuSchemaValue) {\n console.warn(`Menu \"${activeMenu.value.menuId}\" not found in schema`);\n return null;\n }\n\n return menuSchemaValue;\n});\n\nconst handleClose = () => {\n if (activeMenu.value) {\n provides.value?.forDocument(props.documentId).closeMenu(activeMenu.value.menuId);\n }\n};\n\n// Use the user-provided menu renderer\nconst MenuRenderer = computed(() => renderers.menu);\n</script>\n","<template>\n <div\n ref=\"rootRef\"\n v-bind=\"{ ...attrs, ...(rootAttrs as any) }\"\n :style=\"{ containerType: 'inline-size' }\"\n >\n <slot />\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, computed, onMounted, onUnmounted, watch, useAttrs } from 'vue';\nimport { UI_ATTRIBUTES, UI_SELECTORS } from '@embedpdf/plugin-ui';\nimport { useUIPlugin, useUICapability } from './hooks/use-ui';\n\n// Disable automatic attribute inheritance since we handle it manually\ndefineOptions({\n inheritAttrs: false,\n});\n\nconst attrs = useAttrs();\n\nconst { plugin } = useUIPlugin();\nconst { provides } = useUICapability();\n\nconst disabledCategories = ref<string[]>([]);\nconst rootRef = ref<HTMLDivElement | null>(null);\n\nlet styleEl: HTMLStyleElement | null = null;\nlet styleTarget: HTMLElement | ShadowRoot | null = null;\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\n/**\n * Inject or update stylesheet\n */\nfunction injectStyles() {\n if (!rootRef.value || !plugin.value) {\n return;\n }\n\n styleTarget = getStyleTarget(rootRef.value);\n\n // Check if styles already exist in this target\n const existingStyle = styleTarget.querySelector(UI_SELECTORS.STYLES) as HTMLStyleElement | null;\n\n if (existingStyle) {\n styleEl = existingStyle;\n // Update content in case locale changed\n existingStyle.textContent = plugin.value.getStylesheet();\n return;\n }\n\n // Create and inject stylesheet\n const stylesheet = plugin.value.getStylesheet();\n const newStyleEl = document.createElement('style');\n newStyleEl.setAttribute(UI_ATTRIBUTES.STYLES, '');\n newStyleEl.textContent = stylesheet;\n\n if (styleTarget instanceof ShadowRoot) {\n styleTarget.insertBefore(newStyleEl, styleTarget.firstChild);\n } else {\n styleTarget.appendChild(newStyleEl);\n }\n\n styleEl = newStyleEl;\n}\n\n/**\n * Cleanup styles\n */\nfunction cleanupStyles() {\n if (styleEl?.parentNode) {\n styleEl.remove();\n }\n styleEl = null;\n styleTarget = null;\n}\n\n// Build root element attributes\nconst rootAttrs = computed(() => {\n const result: Record<string, string> = {\n [UI_ATTRIBUTES.ROOT]: '',\n };\n\n if (disabledCategories.value.length > 0) {\n result[UI_ATTRIBUTES.DISABLED_CATEGORIES] = disabledCategories.value.join(' ');\n }\n\n return result;\n});\n\n// Stylesheet invalidation cleanup\nlet stylesheetCleanup: (() => void) | null = null;\n\n// Category change cleanup\nlet categoryCleanup: (() => void) | null = null;\n\nonMounted(() => {\n // Inject styles on mount\n injectStyles();\n\n // Subscribe to stylesheet invalidation\n if (plugin.value) {\n stylesheetCleanup = plugin.value.onStylesheetInvalidated(() => {\n if (styleEl && plugin.value) {\n styleEl.textContent = plugin.value.getStylesheet();\n }\n });\n }\n\n // Subscribe to category changes\n if (provides.value) {\n disabledCategories.value = provides.value.getDisabledCategories();\n\n categoryCleanup = provides.value.onCategoryChanged((event) => {\n disabledCategories.value = event.disabledCategories;\n });\n }\n});\n\nonUnmounted(() => {\n cleanupStyles();\n stylesheetCleanup?.();\n categoryCleanup?.();\n});\n\n// Re-inject styles if plugin changes\nwatch(plugin, () => {\n if (rootRef.value && plugin.value) {\n injectStyles();\n }\n});\n</script>\n","<template>\n <UIRoot v-bind=\"attrs\">\n <slot />\n <!-- Automatically render menus for this document -->\n <AutoMenuRenderer :documentId=\"documentId\" :container=\"menuContainer\" />\n </UIRoot>\n</template>\n\n<script setup lang=\"ts\">\nimport type { Component } from 'vue';\nimport { useAttrs } from 'vue';\nimport { provideAnchorRegistry } from './registries/anchor-registry';\nimport { provideComponentRegistry } from './registries/component-registry';\nimport { provideRenderers } from './registries/renderers-registry';\nimport type { BaseComponentProps, UIRenderers } from './types';\nimport AutoMenuRenderer from './auto-menu-renderer.vue';\nimport UIRoot from './root.vue';\n\n// Disable automatic attribute inheritance since we pass them to UIRoot\ndefineOptions({\n inheritAttrs: false,\n});\n\nconst attrs = useAttrs();\n\n/**\n * UIProvider Props\n */\ninterface Props {\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, Component<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\nconst props = withDefaults(defineProps<Props>(), {\n components: () => ({}),\n menuContainer: 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 * ```vue\n * <EmbedPDF :engine=\"engine\" :plugins=\"plugins\">\n * <template v-slot=\"{ pluginsReady, activeDocumentId }\">\n * <UIProvider\n * v-if=\"pluginsReady && activeDocumentId\"\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 * class=\"relative flex h-full w-full\"\n * >\n * <ViewerLayout />\n * </UIProvider>\n * </template>\n * </EmbedPDF>\n * ```\n */\n\n// Provide all registries\nprovideAnchorRegistry();\nprovideComponentRegistry(props.components);\nprovideRenderers(props.renderers);\n</script>\n","import { h } from 'vue';\nimport { 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 h(Component, { documentId, ...(props || {}) });\n },\n };\n}\n","import { onBeforeUnmount, ref, watch } from 'vue';\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 to attach to the element (use with :ref=\"anchorRef\")\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * const anchorRef = useRegisterAnchor(props.documentId, 'zoom-button');\n * </script>\n *\n * <template>\n * <button :ref=\"anchorRef\">Zoom</button>\n * </template>\n * ```\n */\nexport function useRegisterAnchor(documentId: string, itemId: string) {\n const registry = useAnchorRegistry();\n const elementRef = ref<HTMLElement | null>(null);\n\n // Function to set ref\n const setRef = (el: any) => {\n // Handle Vue 3 ref binding\n const element = el?.$el || el;\n\n // Unregister previous element if exists\n if (elementRef.value && elementRef.value !== element) {\n registry.unregister(documentId, itemId);\n }\n\n elementRef.value = element;\n\n // Register new element\n if (element) {\n registry.register(documentId, itemId, element);\n }\n };\n\n // Cleanup on unmount\n onBeforeUnmount(() => {\n if (elementRef.value) {\n registry.unregister(documentId, itemId);\n }\n });\n\n return setRef;\n}\n","import { h, toValue, type VNode, type MaybeRefOrGetter } from 'vue';\nimport { useUICapability, useUIState } from './use-ui';\nimport { useRenderers } from '../registries/renderers-registry';\n\n/**\n * High-level composable 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 * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport function useSchemaRenderer(documentId: MaybeRefOrGetter<string>) {\n const renderers = useRenderers();\n const { provides } = useUICapability();\n const { state: uiState } = useUIState(documentId);\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 * ```vue\n * <component :is=\"renderToolbar('top', 'main')\" />\n * <component :is=\"renderToolbar('top', 'secondary')\" />\n * ```\n */\n renderToolbar: (placement: 'top' | 'bottom' | 'left' | 'right', slot: string): VNode | null => {\n const schema = provides.value?.getSchema();\n\n if (!schema || !provides.value || !uiState.value) return null;\n\n const slotKey = `${placement}-${slot}`;\n const toolbarSlot = uiState.value.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.value?.forDocument(toValue(documentId)).closeToolbarSlot(placement, slot);\n }\n : undefined;\n\n const ToolbarRenderer = renderers.toolbar;\n\n // ALWAYS render, pass isOpen state\n return h(ToolbarRenderer, {\n key: toolbarSlot.toolbarId,\n schema: toolbarSchema,\n documentId: toValue(documentId),\n isOpen: toolbarSlot.isOpen,\n onClose: handleClose,\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 * ```vue\n * <component :is=\"renderPanel('left', 'main')\" />\n * <component :is=\"renderPanel('right', 'main')\" />\n * ```\n */\n renderPanel: (placement: 'left' | 'right' | 'top' | 'bottom', slot: string): VNode | null => {\n const schema = provides.value?.getSchema();\n\n if (!schema || !provides.value || !uiState.value) return null;\n\n const slotKey = `${placement}-${slot}`;\n const panelSlot = uiState.value.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.value?.forDocument(toValue(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 h(PanelRenderer, {\n key: panelSlot.panelId,\n schema: panelSchema,\n documentId: toValue(documentId),\n isOpen: panelSlot.isOpen,\n onClose: handleClose,\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.value) return [];\n return Object.entries(uiState.value.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.value) return [];\n return Object.entries(uiState.value.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 { computed, h, toValue, type VNode, type MaybeRefOrGetter } from 'vue';\nimport type { SelectionMenuPropsBase, SelectionMenuRenderFn } from '@embedpdf/utils/vue';\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 (can be ref, computed, getter, or plain value)\n * @returns A computed ref containing the render function or undefined\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * const annotationMenu = useSelectionMenu('annotation', () => props.documentId);\n * </script>\n *\n * <template>\n * <AnnotationLayer\n * :documentId=\"documentId\"\n * :selectionMenu=\"annotationMenu\"\n * />\n * </template>\n * ```\n */\nexport function useSelectionMenu<TContext extends { type: string } = { type: string }>(\n menuId: MaybeRefOrGetter<string>,\n documentId: MaybeRefOrGetter<string>,\n) {\n const { provides } = useUICapability();\n const renderers = useRenderers();\n\n const schema = computed(() => provides.value?.getSchema());\n const menuSchema = computed(() => schema.value?.selectionMenus?.[toValue(menuId)]);\n\n // Return a computed that produces the render function (or undefined)\n const renderFn = computed<SelectionMenuRenderFn<TContext> | undefined>(() => {\n // If no schema for this menu, return undefined\n if (!menuSchema.value) {\n return undefined;\n }\n\n // Capture current values for the closure\n const currentMenuSchema = menuSchema.value;\n const currentDocumentId = toValue(documentId);\n const SelectionMenuRenderer = renderers.selectionMenu;\n\n // Return the render function\n return (props: SelectionMenuPropsBase<TContext>): VNode | null => {\n if (!props.selected) {\n return null;\n }\n\n return h(SelectionMenuRenderer, {\n schema: currentMenuSchema,\n documentId: currentDocumentId,\n props,\n });\n };\n });\n\n return renderFn;\n}\n"],"names":["useUIPlugin","usePlugin","UIPlugin","id","useUICapability","useCapability","useUIState","documentId","provides","state","ref","watch","toValue","providesValue","docId","_","onCleanup","value","scope","forDocument","getState","unsubToolbar","onToolbarChanged","unsubPanel","onPanelChanged","unsubModal","onModalChanged","unsubMenu","onMenuChanged","immediate","computed","_a","readonly","AnchorRegistryKey","Symbol","createAnchorRegistry","anchors","Map","register","itemId","element","key","set","unregister","delete","getAnchor","get","provideAnchorRegistry","registry","provide","useAnchorRegistry","inject","Error","ComponentRegistryKey","createComponentRegistry","initialComponents","components","Object","entries","component","has","getRegisteredIds","Array","from","keys","provideComponentRegistry","useComponentRegistry","RenderersKey","provideRenderers","renderers","useRenderers","props","__props","uiState","anchorRegistry","activeMenu","openMenus","schema","getSchema","menus","openMenuIds","length","menuId","menuState","triggeredByItemId","anchor","anchorEl","menuSchema","menuSchemaValue","console","warn","handleClose","closeMenu","MenuRenderer","menu","_openBlock","_createBlock","_resolveDynamicComponent","onClose","container","attrs","useAttrs","plugin","disabledCategories","rootRef","styleEl","styleTarget","injectStyles","root","getRootNode","ShadowRoot","document","head","getStyleTarget","existingStyle","querySelector","UI_SELECTORS","STYLES","textContent","getStylesheet","stylesheet","newStyleEl","createElement","setAttribute","UI_ATTRIBUTES","insertBefore","firstChild","appendChild","rootAttrs","result","ROOT","DISABLED_CATEGORIES","join","stylesheetCleanup","categoryCleanup","onMounted","onStylesheetInvalidated","getDisabledCategories","onCategoryChanged","event","onUnmounted","parentNode","remove","_createElementBlock","_mergeProps","_unref","style","containerType","_renderSlot","_ctx","$slots","UIRoot","_createVNode","AutoMenuRenderer","menuContainer","componentRegistry","renderCustomComponent","componentId","Component","h","error","elementRef","onBeforeUnmount","el","$el","renderToolbar","placement","slot","slotKey","toolbarSlot","activeToolbars","toolbarSchema","toolbars","toolbarId","permanent","closeToolbarSlot","ToolbarRenderer","toolbar","isOpen","renderPanel","panelSlot","activePanels","panelSchema","panels","panelId","PanelRenderer","panel","closePanelSlot","getActiveToolbars","map","split","getActivePanels","_b","selectionMenus","currentMenuSchema","currentDocumentId","SelectionMenuRenderer","selectionMenu","selected"],"mappings":"wKAIaA,EAAc,IAAMC,YAAoBC,EAAAA,SAASC,IACjDC,EAAkB,IAAMC,gBAAwBH,EAAAA,SAASC,IAMzDG,EAAcC,IACzB,MAAMC,SAAEA,GAAaJ,IACfK,EAAQC,EAAAA,IAA4B,MAE1CC,EAAAA,MACE,CAACH,EAAU,IAAMI,UAAQL,IACzB,EAAEM,EAAeC,GAAQC,EAAGC,KAC1B,IAAKH,EAEH,YADAJ,EAAMQ,MAAQ,MAIhB,MAAMC,EAAQL,EAAcM,YAAYL,GAGxCL,EAAMQ,MAAQC,EAAME,WAGpB,MAAMC,EAAeH,EAAMI,iB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AAO,CACLxB,YACAC,OACAM,UAAWJ,EAAYI,UACvBK,OAAQT,EAAYS,UAPG,GAgB7Ba,gBAAiB,IACVtH,EAAQxD,MACNwC,OAAOC,QAAQe,EAAQxD,MAAMoK,cAAcQ,IAAI,EAAErB,EAASY,MAC/D,MAAOd,EAAWC,GAAQC,EAAQsB,MAAM,KACxC,MAAO,CACLxB,YACAC,OACAiB,QAASJ,EAAUI,QACnBN,OAAQE,EAAUF,UAPK,GAYjC,2BChIO,SACLhG,EACA3E,GAEA,MAAMC,SAAEA,GAAaJ,IACfiE,EAAYC,IAEZO,EAAS/C,EAAAA,SAAS,WAAM,OAAA,OAAAC,EAAAvB,EAASS,YAAT,EAAAc,EAAgB+C,cACxCS,EAAazD,EAAAA,SAAS,aAAM,OAAA,OAAAkK,EAAA,OAAAjK,EAAA8C,EAAO5D,YAAP,EAAAc,EAAckK,qBAAd,EAAAD,EAA+BpL,EAAAA,QAAQsE,MA4BzE,OAzBiBpD,EAAAA,SAAsD,KAErE,IAAKyD,EAAWtE,MACd,OAIF,MAAMiL,EAAoB3G,EAAWtE,MAC/BkL,EAAoBvL,EAAAA,QAAQL,GAC5B6L,EAAwB/H,EAAUgI,cAGxC,OAAQ9H,GACDA,EAAM+H,SAIJvC,EAAAA,EAAEqC,EAAuB,CAC9BvH,OAAQqH,EACR3L,WAAY4L,EACZ5H,UANO,MAYf,sEVI2B,KACzB,MAAM/D,SAAEA,GAAaJ,IACfyE,EAAS/C,EAAAA,SAA0B,WAAM,OAAA,OAAAC,EAAAvB,EAASS,gBAAO6D,cAAe,OAE9E,OAAO9C,EAAAA,SAAS6C"}
|
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
import { ref, watch, toValue, computed, readonly, provide, inject, onBeforeUnmount, h, defineComponent, createBlock, createCommentVNode, openBlock, resolveDynamicComponent, useAttrs, onMounted, onUnmounted, createElementBlock, mergeProps, unref, renderSlot, normalizeProps, guardReactiveProps, withCtx, createVNode } from "vue";
|
|
2
|
+
import { usePlugin, useCapability } from "@embedpdf/core/vue";
|
|
3
|
+
import { UIPlugin, UI_ATTRIBUTES, UI_SELECTORS } from "@embedpdf/plugin-ui";
|
|
4
|
+
export * from "@embedpdf/plugin-ui";
|
|
5
|
+
const useUIPlugin = () => usePlugin(UIPlugin.id);
|
|
6
|
+
const useUICapability = () => useCapability(UIPlugin.id);
|
|
7
|
+
const useUIState = (documentId) => {
|
|
8
|
+
const { provides } = useUICapability();
|
|
9
|
+
const state = ref(null);
|
|
10
|
+
watch(
|
|
11
|
+
[provides, () => toValue(documentId)],
|
|
12
|
+
([providesValue, docId], _, onCleanup) => {
|
|
13
|
+
if (!providesValue) {
|
|
14
|
+
state.value = null;
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const scope = providesValue.forDocument(docId);
|
|
18
|
+
state.value = scope.getState();
|
|
19
|
+
const unsubToolbar = scope.onToolbarChanged(() => {
|
|
20
|
+
state.value = scope.getState();
|
|
21
|
+
});
|
|
22
|
+
const unsubPanel = scope.onPanelChanged(() => {
|
|
23
|
+
state.value = scope.getState();
|
|
24
|
+
});
|
|
25
|
+
const unsubModal = scope.onModalChanged(() => {
|
|
26
|
+
state.value = scope.getState();
|
|
27
|
+
});
|
|
28
|
+
const unsubMenu = scope.onMenuChanged(() => {
|
|
29
|
+
state.value = scope.getState();
|
|
30
|
+
});
|
|
31
|
+
onCleanup(() => {
|
|
32
|
+
unsubToolbar();
|
|
33
|
+
unsubPanel();
|
|
34
|
+
unsubModal();
|
|
35
|
+
unsubMenu();
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
{ immediate: true }
|
|
39
|
+
);
|
|
40
|
+
const scopedProvides = computed(() => {
|
|
41
|
+
var _a;
|
|
42
|
+
const docId = toValue(documentId);
|
|
43
|
+
return ((_a = provides.value) == null ? void 0 : _a.forDocument(docId)) ?? null;
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
provides: scopedProvides,
|
|
47
|
+
state: readonly(state)
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const useUISchema = () => {
|
|
51
|
+
const { provides } = useUICapability();
|
|
52
|
+
const schema = computed(() => {
|
|
53
|
+
var _a;
|
|
54
|
+
return ((_a = provides.value) == null ? void 0 : _a.getSchema()) ?? null;
|
|
55
|
+
});
|
|
56
|
+
return readonly(schema);
|
|
57
|
+
};
|
|
58
|
+
const AnchorRegistryKey = Symbol("AnchorRegistry");
|
|
59
|
+
function createAnchorRegistry() {
|
|
60
|
+
const anchors = ref(/* @__PURE__ */ new Map());
|
|
61
|
+
return {
|
|
62
|
+
register(documentId, itemId, element) {
|
|
63
|
+
const key = `${documentId}:${itemId}`;
|
|
64
|
+
anchors.value.set(key, element);
|
|
65
|
+
},
|
|
66
|
+
unregister(documentId, itemId) {
|
|
67
|
+
const key = `${documentId}:${itemId}`;
|
|
68
|
+
anchors.value.delete(key);
|
|
69
|
+
},
|
|
70
|
+
getAnchor(documentId, itemId) {
|
|
71
|
+
const key = `${documentId}:${itemId}`;
|
|
72
|
+
return anchors.value.get(key) || null;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function provideAnchorRegistry() {
|
|
77
|
+
const registry = createAnchorRegistry();
|
|
78
|
+
provide(AnchorRegistryKey, registry);
|
|
79
|
+
return registry;
|
|
80
|
+
}
|
|
81
|
+
function useAnchorRegistry() {
|
|
82
|
+
const registry = inject(AnchorRegistryKey);
|
|
83
|
+
if (!registry) {
|
|
84
|
+
throw new Error("useAnchorRegistry must be used within UIProvider");
|
|
85
|
+
}
|
|
86
|
+
return registry;
|
|
87
|
+
}
|
|
88
|
+
function useRegisterAnchor(documentId, itemId) {
|
|
89
|
+
const registry = useAnchorRegistry();
|
|
90
|
+
const elementRef = ref(null);
|
|
91
|
+
const setRef = (el) => {
|
|
92
|
+
const element = (el == null ? void 0 : el.$el) || el;
|
|
93
|
+
if (elementRef.value && elementRef.value !== element) {
|
|
94
|
+
registry.unregister(documentId, itemId);
|
|
95
|
+
}
|
|
96
|
+
elementRef.value = element;
|
|
97
|
+
if (element) {
|
|
98
|
+
registry.register(documentId, itemId, element);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
onBeforeUnmount(() => {
|
|
102
|
+
if (elementRef.value) {
|
|
103
|
+
registry.unregister(documentId, itemId);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return setRef;
|
|
107
|
+
}
|
|
108
|
+
const ComponentRegistryKey = Symbol("ComponentRegistry");
|
|
109
|
+
function createComponentRegistry(initialComponents = {}) {
|
|
110
|
+
const components = ref(
|
|
111
|
+
new Map(Object.entries(initialComponents))
|
|
112
|
+
);
|
|
113
|
+
return {
|
|
114
|
+
register(id, component) {
|
|
115
|
+
components.value.set(id, component);
|
|
116
|
+
},
|
|
117
|
+
unregister(id) {
|
|
118
|
+
components.value.delete(id);
|
|
119
|
+
},
|
|
120
|
+
get(id) {
|
|
121
|
+
return components.value.get(id);
|
|
122
|
+
},
|
|
123
|
+
has(id) {
|
|
124
|
+
return components.value.has(id);
|
|
125
|
+
},
|
|
126
|
+
getRegisteredIds() {
|
|
127
|
+
return Array.from(components.value.keys());
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function provideComponentRegistry(initialComponents = {}) {
|
|
132
|
+
const registry = createComponentRegistry(initialComponents);
|
|
133
|
+
provide(ComponentRegistryKey, registry);
|
|
134
|
+
return registry;
|
|
135
|
+
}
|
|
136
|
+
function useComponentRegistry() {
|
|
137
|
+
const registry = inject(ComponentRegistryKey);
|
|
138
|
+
if (!registry) {
|
|
139
|
+
throw new Error("useComponentRegistry must be used within UIProvider");
|
|
140
|
+
}
|
|
141
|
+
return registry;
|
|
142
|
+
}
|
|
143
|
+
function useItemRenderer() {
|
|
144
|
+
const componentRegistry = useComponentRegistry();
|
|
145
|
+
return {
|
|
146
|
+
/**
|
|
147
|
+
* Render a custom component by ID
|
|
148
|
+
*
|
|
149
|
+
* @param componentId - Component ID from schema
|
|
150
|
+
* @param documentId - Document ID
|
|
151
|
+
* @param props - Additional props to pass to component
|
|
152
|
+
* @returns Rendered component or null if not found
|
|
153
|
+
*/
|
|
154
|
+
renderCustomComponent: (componentId, documentId, props) => {
|
|
155
|
+
const Component = componentRegistry.get(componentId);
|
|
156
|
+
if (!Component) {
|
|
157
|
+
console.error(`Component "${componentId}" not found in registry`);
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
return h(Component, { documentId, ...props || {} });
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const RenderersKey = Symbol("Renderers");
|
|
165
|
+
function provideRenderers(renderers) {
|
|
166
|
+
provide(RenderersKey, renderers);
|
|
167
|
+
}
|
|
168
|
+
function useRenderers() {
|
|
169
|
+
const renderers = inject(RenderersKey);
|
|
170
|
+
if (!renderers) {
|
|
171
|
+
throw new Error("useRenderers must be used within UIProvider");
|
|
172
|
+
}
|
|
173
|
+
return renderers;
|
|
174
|
+
}
|
|
175
|
+
function useSchemaRenderer(documentId) {
|
|
176
|
+
const renderers = useRenderers();
|
|
177
|
+
const { provides } = useUICapability();
|
|
178
|
+
const { state: uiState } = useUIState(documentId);
|
|
179
|
+
return {
|
|
180
|
+
/**
|
|
181
|
+
* Render a toolbar by placement and slot
|
|
182
|
+
*
|
|
183
|
+
* Always renders with isOpen state when toolbar exists in slot.
|
|
184
|
+
*
|
|
185
|
+
* @param placement - 'top' | 'bottom' | 'left' | 'right'
|
|
186
|
+
* @param slot - Slot name (e.g. 'main', 'secondary')
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```vue
|
|
190
|
+
* <component :is="renderToolbar('top', 'main')" />
|
|
191
|
+
* <component :is="renderToolbar('top', 'secondary')" />
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
renderToolbar: (placement, slot) => {
|
|
195
|
+
var _a;
|
|
196
|
+
const schema = (_a = provides.value) == null ? void 0 : _a.getSchema();
|
|
197
|
+
if (!schema || !provides.value || !uiState.value) return null;
|
|
198
|
+
const slotKey = `${placement}-${slot}`;
|
|
199
|
+
const toolbarSlot = uiState.value.activeToolbars[slotKey];
|
|
200
|
+
if (!toolbarSlot) return null;
|
|
201
|
+
const toolbarSchema = schema.toolbars[toolbarSlot.toolbarId];
|
|
202
|
+
if (!toolbarSchema) {
|
|
203
|
+
console.warn(`Toolbar "${toolbarSlot.toolbarId}" not found in schema`);
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
const isClosable = !toolbarSchema.permanent;
|
|
207
|
+
const handleClose = isClosable ? () => {
|
|
208
|
+
var _a2;
|
|
209
|
+
(_a2 = provides.value) == null ? void 0 : _a2.forDocument(toValue(documentId)).closeToolbarSlot(placement, slot);
|
|
210
|
+
} : void 0;
|
|
211
|
+
const ToolbarRenderer = renderers.toolbar;
|
|
212
|
+
return h(ToolbarRenderer, {
|
|
213
|
+
key: toolbarSlot.toolbarId,
|
|
214
|
+
schema: toolbarSchema,
|
|
215
|
+
documentId: toValue(documentId),
|
|
216
|
+
isOpen: toolbarSlot.isOpen,
|
|
217
|
+
onClose: handleClose
|
|
218
|
+
});
|
|
219
|
+
},
|
|
220
|
+
/**
|
|
221
|
+
* Render a panel by placement and slot
|
|
222
|
+
*
|
|
223
|
+
* ALWAYS renders (when panel exists in slot) with isOpen state.
|
|
224
|
+
* Your renderer controls whether to display or animate.
|
|
225
|
+
*
|
|
226
|
+
* @param placement - 'left' | 'right' | 'top' | 'bottom'
|
|
227
|
+
* @param slot - Slot name (e.g. 'main', 'secondary', 'inspector')
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```vue
|
|
231
|
+
* <component :is="renderPanel('left', 'main')" />
|
|
232
|
+
* <component :is="renderPanel('right', 'main')" />
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
renderPanel: (placement, slot) => {
|
|
236
|
+
var _a;
|
|
237
|
+
const schema = (_a = provides.value) == null ? void 0 : _a.getSchema();
|
|
238
|
+
if (!schema || !provides.value || !uiState.value) return null;
|
|
239
|
+
const slotKey = `${placement}-${slot}`;
|
|
240
|
+
const panelSlot = uiState.value.activePanels[slotKey];
|
|
241
|
+
if (!panelSlot) return null;
|
|
242
|
+
const panelSchema = schema.panels[panelSlot.panelId];
|
|
243
|
+
if (!panelSchema) {
|
|
244
|
+
console.warn(`Panel "${panelSlot.panelId}" not found in schema`);
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
const handleClose = () => {
|
|
248
|
+
var _a2;
|
|
249
|
+
(_a2 = provides.value) == null ? void 0 : _a2.forDocument(toValue(documentId)).closePanelSlot(placement, slot);
|
|
250
|
+
};
|
|
251
|
+
const PanelRenderer = renderers.panel;
|
|
252
|
+
return h(PanelRenderer, {
|
|
253
|
+
key: panelSlot.panelId,
|
|
254
|
+
schema: panelSchema,
|
|
255
|
+
documentId: toValue(documentId),
|
|
256
|
+
isOpen: panelSlot.isOpen,
|
|
257
|
+
onClose: handleClose
|
|
258
|
+
});
|
|
259
|
+
},
|
|
260
|
+
/**
|
|
261
|
+
* Helper: Get all active toolbars for this document
|
|
262
|
+
* Useful for batch rendering or debugging
|
|
263
|
+
*/
|
|
264
|
+
getActiveToolbars: () => {
|
|
265
|
+
if (!uiState.value) return [];
|
|
266
|
+
return Object.entries(uiState.value.activeToolbars).map(([slotKey, toolbarSlot]) => {
|
|
267
|
+
const [placement, slot] = slotKey.split("-");
|
|
268
|
+
return {
|
|
269
|
+
placement,
|
|
270
|
+
slot,
|
|
271
|
+
toolbarId: toolbarSlot.toolbarId,
|
|
272
|
+
isOpen: toolbarSlot.isOpen
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
/**
|
|
277
|
+
* Helper: Get all active panels for this document
|
|
278
|
+
* Useful for batch rendering or debugging
|
|
279
|
+
*/
|
|
280
|
+
getActivePanels: () => {
|
|
281
|
+
if (!uiState.value) return [];
|
|
282
|
+
return Object.entries(uiState.value.activePanels).map(([slotKey, panelSlot]) => {
|
|
283
|
+
const [placement, slot] = slotKey.split("-");
|
|
284
|
+
return {
|
|
285
|
+
placement,
|
|
286
|
+
slot,
|
|
287
|
+
panelId: panelSlot.panelId,
|
|
288
|
+
isOpen: panelSlot.isOpen
|
|
289
|
+
};
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function useSelectionMenu(menuId, documentId) {
|
|
295
|
+
const { provides } = useUICapability();
|
|
296
|
+
const renderers = useRenderers();
|
|
297
|
+
const schema = computed(() => {
|
|
298
|
+
var _a;
|
|
299
|
+
return (_a = provides.value) == null ? void 0 : _a.getSchema();
|
|
300
|
+
});
|
|
301
|
+
const menuSchema = computed(() => {
|
|
302
|
+
var _a, _b;
|
|
303
|
+
return (_b = (_a = schema.value) == null ? void 0 : _a.selectionMenus) == null ? void 0 : _b[toValue(menuId)];
|
|
304
|
+
});
|
|
305
|
+
const renderFn = computed(() => {
|
|
306
|
+
if (!menuSchema.value) {
|
|
307
|
+
return void 0;
|
|
308
|
+
}
|
|
309
|
+
const currentMenuSchema = menuSchema.value;
|
|
310
|
+
const currentDocumentId = toValue(documentId);
|
|
311
|
+
const SelectionMenuRenderer = renderers.selectionMenu;
|
|
312
|
+
return (props) => {
|
|
313
|
+
if (!props.selected) {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
return h(SelectionMenuRenderer, {
|
|
317
|
+
schema: currentMenuSchema,
|
|
318
|
+
documentId: currentDocumentId,
|
|
319
|
+
props
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
});
|
|
323
|
+
return renderFn;
|
|
324
|
+
}
|
|
325
|
+
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
326
|
+
__name: "auto-menu-renderer",
|
|
327
|
+
props: {
|
|
328
|
+
documentId: {},
|
|
329
|
+
container: {}
|
|
330
|
+
},
|
|
331
|
+
setup(__props) {
|
|
332
|
+
const props = __props;
|
|
333
|
+
const { state: uiState } = useUIState(props.documentId);
|
|
334
|
+
const { provides } = useUICapability();
|
|
335
|
+
const anchorRegistry = useAnchorRegistry();
|
|
336
|
+
const renderers = useRenderers();
|
|
337
|
+
const activeMenu = ref(null);
|
|
338
|
+
const openMenus = computed(() => {
|
|
339
|
+
var _a;
|
|
340
|
+
return ((_a = uiState.value) == null ? void 0 : _a.openMenus) || {};
|
|
341
|
+
});
|
|
342
|
+
const schema = computed(() => {
|
|
343
|
+
var _a;
|
|
344
|
+
return (_a = provides.value) == null ? void 0 : _a.getSchema();
|
|
345
|
+
});
|
|
346
|
+
watch(
|
|
347
|
+
openMenus,
|
|
348
|
+
(menus) => {
|
|
349
|
+
const openMenuIds = Object.keys(menus);
|
|
350
|
+
if (openMenuIds.length > 0) {
|
|
351
|
+
const menuId = openMenuIds[0];
|
|
352
|
+
if (!menuId) {
|
|
353
|
+
activeMenu.value = null;
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const menuState = menus[menuId];
|
|
357
|
+
if (menuState && menuState.triggeredByItemId) {
|
|
358
|
+
const anchor = anchorRegistry.getAnchor(props.documentId, menuState.triggeredByItemId);
|
|
359
|
+
activeMenu.value = { menuId, anchorEl: anchor };
|
|
360
|
+
} else {
|
|
361
|
+
activeMenu.value = null;
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
activeMenu.value = null;
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
{ immediate: true }
|
|
368
|
+
);
|
|
369
|
+
const menuSchema = computed(() => {
|
|
370
|
+
if (!activeMenu.value || !schema.value) return null;
|
|
371
|
+
const menuSchemaValue = schema.value.menus[activeMenu.value.menuId];
|
|
372
|
+
if (!menuSchemaValue) {
|
|
373
|
+
console.warn(`Menu "${activeMenu.value.menuId}" not found in schema`);
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
return menuSchemaValue;
|
|
377
|
+
});
|
|
378
|
+
const handleClose = () => {
|
|
379
|
+
var _a;
|
|
380
|
+
if (activeMenu.value) {
|
|
381
|
+
(_a = provides.value) == null ? void 0 : _a.forDocument(props.documentId).closeMenu(activeMenu.value.menuId);
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
const MenuRenderer = computed(() => renderers.menu);
|
|
385
|
+
return (_ctx, _cache) => {
|
|
386
|
+
return activeMenu.value && menuSchema.value && MenuRenderer.value ? (openBlock(), createBlock(resolveDynamicComponent(MenuRenderer.value), {
|
|
387
|
+
key: 0,
|
|
388
|
+
schema: menuSchema.value,
|
|
389
|
+
documentId: __props.documentId,
|
|
390
|
+
anchorEl: activeMenu.value.anchorEl,
|
|
391
|
+
onClose: handleClose,
|
|
392
|
+
container: __props.container
|
|
393
|
+
}, null, 40, ["schema", "documentId", "anchorEl", "container"])) : createCommentVNode("", true);
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
398
|
+
...{
|
|
399
|
+
inheritAttrs: false
|
|
400
|
+
},
|
|
401
|
+
__name: "root",
|
|
402
|
+
setup(__props) {
|
|
403
|
+
const attrs = useAttrs();
|
|
404
|
+
const { plugin } = useUIPlugin();
|
|
405
|
+
const { provides } = useUICapability();
|
|
406
|
+
const disabledCategories = ref([]);
|
|
407
|
+
const rootRef = ref(null);
|
|
408
|
+
let styleEl = null;
|
|
409
|
+
let styleTarget = null;
|
|
410
|
+
function getStyleTarget(element) {
|
|
411
|
+
const root = element.getRootNode();
|
|
412
|
+
if (root instanceof ShadowRoot) {
|
|
413
|
+
return root;
|
|
414
|
+
}
|
|
415
|
+
return document.head;
|
|
416
|
+
}
|
|
417
|
+
function injectStyles() {
|
|
418
|
+
if (!rootRef.value || !plugin.value) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
styleTarget = getStyleTarget(rootRef.value);
|
|
422
|
+
const existingStyle = styleTarget.querySelector(UI_SELECTORS.STYLES);
|
|
423
|
+
if (existingStyle) {
|
|
424
|
+
styleEl = existingStyle;
|
|
425
|
+
existingStyle.textContent = plugin.value.getStylesheet();
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const stylesheet = plugin.value.getStylesheet();
|
|
429
|
+
const newStyleEl = document.createElement("style");
|
|
430
|
+
newStyleEl.setAttribute(UI_ATTRIBUTES.STYLES, "");
|
|
431
|
+
newStyleEl.textContent = stylesheet;
|
|
432
|
+
if (styleTarget instanceof ShadowRoot) {
|
|
433
|
+
styleTarget.insertBefore(newStyleEl, styleTarget.firstChild);
|
|
434
|
+
} else {
|
|
435
|
+
styleTarget.appendChild(newStyleEl);
|
|
436
|
+
}
|
|
437
|
+
styleEl = newStyleEl;
|
|
438
|
+
}
|
|
439
|
+
function cleanupStyles() {
|
|
440
|
+
if (styleEl == null ? void 0 : styleEl.parentNode) {
|
|
441
|
+
styleEl.remove();
|
|
442
|
+
}
|
|
443
|
+
styleEl = null;
|
|
444
|
+
styleTarget = null;
|
|
445
|
+
}
|
|
446
|
+
const rootAttrs = computed(() => {
|
|
447
|
+
const result = {
|
|
448
|
+
[UI_ATTRIBUTES.ROOT]: ""
|
|
449
|
+
};
|
|
450
|
+
if (disabledCategories.value.length > 0) {
|
|
451
|
+
result[UI_ATTRIBUTES.DISABLED_CATEGORIES] = disabledCategories.value.join(" ");
|
|
452
|
+
}
|
|
453
|
+
return result;
|
|
454
|
+
});
|
|
455
|
+
let stylesheetCleanup = null;
|
|
456
|
+
let categoryCleanup = null;
|
|
457
|
+
onMounted(() => {
|
|
458
|
+
injectStyles();
|
|
459
|
+
if (plugin.value) {
|
|
460
|
+
stylesheetCleanup = plugin.value.onStylesheetInvalidated(() => {
|
|
461
|
+
if (styleEl && plugin.value) {
|
|
462
|
+
styleEl.textContent = plugin.value.getStylesheet();
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
if (provides.value) {
|
|
467
|
+
disabledCategories.value = provides.value.getDisabledCategories();
|
|
468
|
+
categoryCleanup = provides.value.onCategoryChanged((event) => {
|
|
469
|
+
disabledCategories.value = event.disabledCategories;
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
onUnmounted(() => {
|
|
474
|
+
cleanupStyles();
|
|
475
|
+
stylesheetCleanup == null ? void 0 : stylesheetCleanup();
|
|
476
|
+
categoryCleanup == null ? void 0 : categoryCleanup();
|
|
477
|
+
});
|
|
478
|
+
watch(plugin, () => {
|
|
479
|
+
if (rootRef.value && plugin.value) {
|
|
480
|
+
injectStyles();
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
return (_ctx, _cache) => {
|
|
484
|
+
return openBlock(), createElementBlock("div", mergeProps({
|
|
485
|
+
ref_key: "rootRef",
|
|
486
|
+
ref: rootRef
|
|
487
|
+
}, { ...unref(attrs), ...rootAttrs.value }, { style: { containerType: "inline-size" } }), [
|
|
488
|
+
renderSlot(_ctx.$slots, "default")
|
|
489
|
+
], 16);
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
494
|
+
...{
|
|
495
|
+
inheritAttrs: false
|
|
496
|
+
},
|
|
497
|
+
__name: "provider",
|
|
498
|
+
props: {
|
|
499
|
+
documentId: {},
|
|
500
|
+
components: { default: () => ({}) },
|
|
501
|
+
renderers: {},
|
|
502
|
+
menuContainer: { default: null }
|
|
503
|
+
},
|
|
504
|
+
setup(__props) {
|
|
505
|
+
const attrs = useAttrs();
|
|
506
|
+
const props = __props;
|
|
507
|
+
provideAnchorRegistry();
|
|
508
|
+
provideComponentRegistry(props.components);
|
|
509
|
+
provideRenderers(props.renderers);
|
|
510
|
+
return (_ctx, _cache) => {
|
|
511
|
+
return openBlock(), createBlock(_sfc_main$1, normalizeProps(guardReactiveProps(unref(attrs))), {
|
|
512
|
+
default: withCtx(() => [
|
|
513
|
+
renderSlot(_ctx.$slots, "default"),
|
|
514
|
+
createVNode(_sfc_main$2, {
|
|
515
|
+
documentId: __props.documentId,
|
|
516
|
+
container: __props.menuContainer
|
|
517
|
+
}, null, 8, ["documentId", "container"])
|
|
518
|
+
]),
|
|
519
|
+
_: 3
|
|
520
|
+
}, 16);
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
export {
|
|
525
|
+
_sfc_main$2 as AutoMenuRenderer,
|
|
526
|
+
_sfc_main as UIProvider,
|
|
527
|
+
createAnchorRegistry,
|
|
528
|
+
createComponentRegistry,
|
|
529
|
+
provideAnchorRegistry,
|
|
530
|
+
provideComponentRegistry,
|
|
531
|
+
provideRenderers,
|
|
532
|
+
useAnchorRegistry,
|
|
533
|
+
useComponentRegistry,
|
|
534
|
+
useItemRenderer,
|
|
535
|
+
useRegisterAnchor,
|
|
536
|
+
useRenderers,
|
|
537
|
+
useSchemaRenderer,
|
|
538
|
+
useSelectionMenu,
|
|
539
|
+
useUICapability,
|
|
540
|
+
useUIPlugin,
|
|
541
|
+
useUISchema,
|
|
542
|
+
useUIState
|
|
543
|
+
};
|
|
544
|
+
//# sourceMappingURL=index.js.map
|