@wippy-fe/webcomponent-vue 0.0.63 → 0.0.65
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.d.ts +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -88,7 +88,7 @@ declare function useContent(): Ref<string | null>;
|
|
|
88
88
|
* managed-layout host or when not inside a `kind: 'component'` panel.
|
|
89
89
|
*
|
|
90
90
|
* **Status: Draft 1 (preview).** Part of the managed-layout API; see
|
|
91
|
-
* `managed-layout.md` in the
|
|
91
|
+
* `managed-layout.md` in the Wippy Web Host repository. Field names may change
|
|
92
92
|
* between minor releases until a production consumer drives the
|
|
93
93
|
* corner cases out.
|
|
94
94
|
*
|
|
@@ -104,7 +104,7 @@ declare function usePanelId(): string | null;
|
|
|
104
104
|
* targeted at this panel.
|
|
105
105
|
*
|
|
106
106
|
* **Status: Draft 1 (preview).** Part of the managed-layout API; see
|
|
107
|
-
* `managed-layout.md` in the
|
|
107
|
+
* `managed-layout.md` in the Wippy Web Host repository.
|
|
108
108
|
*
|
|
109
109
|
* ```ts
|
|
110
110
|
* const bus = useLayoutBus()
|
|
@@ -123,7 +123,7 @@ declare function useLayoutBus(): LayoutBusBound | null;
|
|
|
123
123
|
* about narrowing before use.
|
|
124
124
|
*
|
|
125
125
|
* **Status: Draft 1 (preview).** Part of the managed-layout API; see
|
|
126
|
-
* `managed-layout.md` in the
|
|
126
|
+
* `managed-layout.md` in the Wippy Web Host repository.
|
|
127
127
|
*
|
|
128
128
|
* ```ts
|
|
129
129
|
* import type { ProxyApiInstance } from '@wippy-fe/proxy'
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/providers.ts","../src/vue-element.ts","../src/index.ts"],"sourcesContent":["import type { LayoutBusBound } from '@wippy-fe/webcomponent-core'\r\nimport type { InjectionKey, Ref } from 'vue'\r\nimport { inject, onMounted, onUnmounted, watch } from 'vue'\n\r\n// ── Base injection keys (untyped) ────────────────────────────\r\n\r\n/** Injection key for the event emitter function. */\r\nexport const EVENT_PROVIDER = Symbol('wippy:emit') as InjectionKey<\r\n (event: string, detail?: unknown) => void\r\n>\r\n\r\n/** Injection key for the reactive props ref. */\r\nexport const PROPS_PROVIDER = Symbol('wippy:props') as InjectionKey<Ref<Record<string, unknown>>>\r\n\r\n/** Injection key for the reactive props error ref. */\r\nexport const PROPS_ERROR_PROVIDER = Symbol('wippy:props_error') as InjectionKey<Ref<string[]>>\r\n\r\n/** Injection key for reactive content from child <template data-type=\"...\"> elements. */\r\nexport const CONTENT_PROVIDER = Symbol('wippy:content') as InjectionKey<Ref<string | null>>\r\n\r\n/**\r\n * Injection key for the panelId this web component lives in (when\r\n * mounted inside a managed-layout `kind: 'component'` panel). `null`\r\n * outside a managed-layout host.\r\n */\r\nexport const PANEL_ID_PROVIDER = Symbol('wippy:panel-id') as InjectionKey<string | null>\r\n\r\n/**\r\n * Injection key for the panel-bound layout bus. Use to publish or\r\n * subscribe to in-tab broadcasts. `null` outside a managed-layout\r\n * host.\r\n */\r\nexport const LAYOUT_BUS_PROVIDER = Symbol('wippy:layout-bus') as InjectionKey<LayoutBusBound | null>\r\n\r\n/**\r\n * Injection key for the panel-scoped `host` wrapper attached by the\r\n * managed-layout shell. Same shape as the iframe-side `host`; layout\r\n * broadcast / send / on are routed through the panel-bound bus so\r\n * sourcePanelId attribution is correct. `null` outside a managed-layout\r\n * host (callers fall back to importing `host` from `@wippy-fe/proxy`).\r\n */\r\nexport const HOST_PROVIDER = Symbol('wippy:host') as InjectionKey<unknown>\n\n/**\n * Reactive logical activity owned by the embedding host. `null` means this\n * component is unmanaged (for example, mounted directly by an application).\n */\nexport const HOST_VISIBILITY_PROVIDER = Symbol('wippy:host-visibility') as InjectionKey<Ref<boolean | null>>\n\r\n// ── Composables (typed) ──────────────────────────────────────\r\n\r\n/**\r\n * Inject the reactive props ref, typed to your component's props interface.\r\n *\r\n * Must be called inside a Vue component's `setup()` that lives within a `WippyVueElement`.\r\n *\r\n * ```ts\r\n * const props = useProps<ComponentProps>()\r\n * // props is Ref<ComponentProps>\r\n * console.log(props.value.maxFileSize)\r\n * ```\r\n */\r\nexport function useProps<Props>(): Ref<Props> {\r\n const props = inject(PROPS_PROVIDER)\r\n if (!props)\r\n throw new Error('useProps() must be called inside a WippyVueElement')\r\n return props as unknown as Ref<Props>\r\n}\r\n\r\n/**\r\n * Inject the typed event emitter, constrained to your component's event map.\r\n *\r\n * Must be called inside a Vue component's `setup()` that lives within a `WippyVueElement`.\r\n *\r\n * ```ts\r\n * const emit = useEvents<Events>()\r\n * emit('upload-complete', { fileId: '123', status: 'done' }) // fully typed\r\n * ```\r\n */\r\nexport function useEvents<Events>(): <K extends keyof Events>(event: K, detail: Events[K]) => void {\r\n const emit = inject(EVENT_PROVIDER)\r\n if (!emit)\r\n throw new Error('useEvents() must be called inside a WippyVueElement')\r\n return emit as unknown as <K extends keyof Events>(event: K, detail: Events[K]) => void\r\n}\r\n\r\n/**\r\n * Inject the reactive prop validation errors ref.\r\n *\r\n * Must be called inside a Vue component's `setup()` that lives within a `WippyVueElement`.\r\n *\r\n * ```ts\r\n * const errors = usePropsErrors()\r\n * // errors is Ref<string[]>\r\n * ```\r\n */\r\nexport function usePropsErrors(): Ref<string[]> {\r\n const errors = inject(PROPS_ERROR_PROVIDER)\r\n if (!errors)\r\n throw new Error('usePropsErrors() must be called inside a WippyVueElement')\r\n return errors\r\n}\r\n\r\n/**\r\n * Inject the reactive content ref (from child `<template data-type=\"...\">` elements).\r\n *\r\n * Must be called inside a Vue component's `setup()` within a `WippyVueElement`\r\n * that has `contentTemplate` configured.\r\n *\r\n * ```ts\r\n * const content = useContent()\r\n * // content is Ref<string | null>\r\n * ```\r\n */\r\nexport function useContent(): Ref<string | null> {\r\n const content = inject(CONTENT_PROVIDER)\r\n if (!content)\r\n throw new Error('useContent() must be called inside a WippyVueElement with contentTemplate configured')\r\n return content\r\n}\r\n\r\n/**\r\n * Inject the current panelId (from `data-wippy-panel-id` set by the\r\n * managed-layout `ComponentResolver`). Returns `null` outside a\r\n * managed-layout host or when not inside a `kind: 'component'` panel.\r\n *\r\n * **Status: Draft 1 (preview).** Part of the managed-layout API; see\r\n * `managed-layout.md` in the gen-2-chat repo. Field names may change\r\n * between minor releases until a production consumer drives the\r\n * corner cases out.\r\n *\r\n * ```ts\r\n * const panelId = usePanelId()\r\n * if (panelId) console.log('I am the', panelId, 'panel')\r\n * ```\r\n */\r\nexport function usePanelId(): string | null {\r\n return inject(PANEL_ID_PROVIDER, null)\r\n}\r\n\r\n/**\r\n * Inject the panel-bound layout bus. `null` outside a managed-layout\r\n * host. Use to publish on the in-tab bus or subscribe to broadcasts\r\n * targeted at this panel.\r\n *\r\n * **Status: Draft 1 (preview).** Part of the managed-layout API; see\r\n * `managed-layout.md` in the gen-2-chat repo.\r\n *\r\n * ```ts\r\n * const bus = useLayoutBus()\r\n * bus?.subscribe(({ channel, payload, sourcePanelId }) => { ... })\r\n * bus?.broadcast('open-chat', { token: '...' })\r\n * ```\r\n */\r\nexport function useLayoutBus(): LayoutBusBound | null {\r\n return inject(LAYOUT_BUS_PROVIDER, null)\r\n}\r\n\r\n/**\r\n * Inject the panel-scoped `host` wrapper. `null` outside a\r\n * managed-layout host. Subclass code that needs a host in non-layout\r\n * contexts can fall back to `import { host } from '@wippy-fe/proxy'`.\r\n *\r\n * Pass the host shape as the type parameter to access fields like\r\n * `layout.broadcast`. The default `H = unknown` keeps callers honest\r\n * about narrowing before use.\r\n *\r\n * **Status: Draft 1 (preview).** Part of the managed-layout API; see\r\n * `managed-layout.md` in the gen-2-chat repo.\r\n *\r\n * ```ts\r\n * import type { ProxyApiInstance } from '@wippy-fe/proxy'\r\n *\r\n * const host = useHost<ProxyApiInstance['host']>()\r\n * host?.layout.broadcast('open-chat', { token })\r\n * host?.layout.updatePanel('right', { route: '/foo' })\r\n * ```\r\n */\r\nexport function useHost<H = unknown>(): H | null {\n return inject(HOST_PROVIDER, null) as H | null\n}\n\n/**\n * Read host-owned logical activity without coupling it to CSS or viewport\n * visibility. Hosts update this ref without remounting the web component.\n */\nexport function useHostVisibility(): Ref<boolean | null> {\n const visible = inject(HOST_VISIBILITY_PROVIDER)\n if (!visible)\n throw new Error('useHostVisibility() must be called inside a WippyVueElement')\n return visible\n}\n\n/**\n * Preserve a component's ordinary initial load, then refresh retained data\n * only when the host reveals a previously inactive element. The callback is\n * serialized so a reveal cannot race an in-flight load. Multiple reveals\n * during one load coalesce into one trailing refresh. The resulting promise\n * is returned to Vue lifecycle/watch handlers so failures continue through\n * Vue's normal error handling.\n */\nexport function useHostVisibilityRefresh(task: () => void | Promise<void>): Ref<boolean | null> {\n const visible = useHostVisibility()\n let mounted = false\n let running: Promise<void> | null = null\n let refreshQueued = false\n\n function runTask(): Promise<void> {\n if (running) {\n refreshQueued = true\n return running\n }\n\n let current: Promise<void>\n try {\n current = Promise.resolve(task())\n }\n catch (error) {\n current = Promise.reject(error)\n }\n\n const scheduled = current.finally(() => {\n if (running !== scheduled)\n return\n running = null\n\n if (mounted && refreshQueued) {\n refreshQueued = false\n return runTask()\n }\n })\n running = scheduled\n return scheduled\n }\n\n onMounted(() => {\n mounted = true\n return runTask()\n })\n\n onUnmounted(() => {\n mounted = false\n refreshQueued = false\n })\n\n watch(visible, (next, previous) => {\n if (mounted && previous === false && next === true)\n return runTask()\n })\n\n return visible\n}\n\r\n// ── createProviders (typed injection keys) ───────────────────\r\n\r\n/**\r\n * Typed provider keys for a specific component.\r\n */\r\nexport interface TypedProviders<Props, Events> {\r\n EVENT_PROVIDER: InjectionKey<<K extends keyof Events>(event: K, detail: Events[K]) => void>\r\n PROPS_PROVIDER: InjectionKey<Ref<Props>>\r\n PROPS_ERROR_PROVIDER: InjectionKey<Ref<string[]>>\r\n}\r\n\r\n/**\r\n * Creates typed provider injection keys for a specific component.\r\n *\r\n * Use this if you prefer raw `inject(KEY)` over the composable helpers.\r\n * Returns the same Symbol instances with narrowed types.\r\n *\r\n * ```ts\r\n * export const { EVENT_PROVIDER, PROPS_PROVIDER, PROPS_ERROR_PROVIDER } =\r\n * createProviders<ComponentProps, Events>()\r\n * ```\r\n */\r\nexport function createProviders<Props, Events = Record<string, unknown>>(): TypedProviders<Props, Events> {\r\n return {\r\n EVENT_PROVIDER: EVENT_PROVIDER as unknown as TypedProviders<Props, Events>['EVENT_PROVIDER'],\r\n PROPS_PROVIDER: PROPS_PROVIDER as unknown as TypedProviders<Props, Events>['PROPS_PROVIDER'],\r\n PROPS_ERROR_PROVIDER,\r\n }\r\n}\r\n","import type { PiniaPlugin } from 'pinia'\r\nimport type { App, Component, Ref } from 'vue'\r\nimport { getWippyHost, getWippyHostBus, getWippyPanelId, WippyElement } from '@wippy-fe/webcomponent-core'\r\nimport { createPinia, getActivePinia, setActivePinia } from 'pinia'\r\nimport { createApp, ref } from 'vue'\r\nimport { CONTENT_PROVIDER, EVENT_PROVIDER, HOST_PROVIDER, HOST_VISIBILITY_PROVIDER, LAYOUT_BUS_PROVIDER, PANEL_ID_PROVIDER, PROPS_ERROR_PROVIDER, PROPS_PROVIDER } from './providers.ts'\n\r\n/**\r\n * The heavy half of a Vue element's config — the root component, its plugins,\r\n * and providers. Either supplied eagerly on `WippyVueElementConfig` or returned\r\n * by `lazyConfig()` from a dynamically-imported chunk (so the element shell can\r\n * stay tiny and load the framework + component tree on first connect).\r\n */\r\nexport interface WippyVueMountConfig {\r\n /** The root Vue component to mount. */\r\n rootComponent: Component\r\n /** Additional Vue plugins to install (beyond Pinia which is always installed). */\r\n plugins?: Array<{ install: (app: App) => void }>\r\n /** Pinia plugins to install (e.g., createWippyPersist()). */\r\n piniaPlugins?: PiniaPlugin[]\r\n /** Extra providers to inject into the Vue app. */\r\n providers?: (app: App, element: WippyVueElement<any, any>) => void\r\n}\r\n\r\n/**\r\n * Vue-specific configuration returned by `static get vueConfig()`.\r\n *\r\n * Provide EITHER an eager `rootComponent` (+ optional plugins/providers) for a\r\n * normal element, OR `lazyConfig` for a thin shell that defers the heavy parts:\r\n * when `lazyConfig` is set and `rootComponent` is omitted, `onMount` shows a\r\n * `<wippy-loading>` placeholder, awaits `lazyConfig()` (typically `() =>\r\n * import('./internals').then(m => ({ rootComponent: m.Root, providers: m.boot }))`),\r\n * then mounts. The props/events bridge + lifecycle stay here, so the lazily\r\n * imported chunk only carries the framework + component tree.\r\n */\r\nexport interface WippyVueElementConfig extends Partial<WippyVueMountConfig> {\r\n /** Lazily resolve the mount config (root + plugins + providers) on first connect. */\r\n lazyConfig?: () => Promise<WippyVueMountConfig>\r\n}\r\n\r\n/**\r\n * Vue 3 integration for Wippy web components.\r\n *\r\n * Generic over `Props` (parsed prop object type) and `Events` (event map).\r\n * These flow through to typed hooks, reactive refs, and composable helpers.\r\n *\r\n * Usage:\r\n * ```ts\r\n * class MyElement extends WippyVueElement<MyProps, MyEvents> {\r\n * static get wippyConfig(): WippyElementConfig<MyProps> {\r\n * return { propsSchema: pkg.wippy.props, inlineCss: stylesText }\r\n * }\r\n * static get vueConfig() {\r\n * return { rootComponent: MyApp }\r\n * }\r\n * }\r\n * ```\r\n *\r\n * In Vue components, use the typed composable helpers:\r\n * ```ts\r\n * const props = useProps<MyProps>()\r\n * const emit = useEvents<MyEvents>()\r\n * const errors = usePropsErrors()\r\n * ```\r\n */\r\nexport abstract class WippyVueElement<\r\n Props = Record<string, unknown>,\r\n Events = Record<string, unknown>,\r\n> extends WippyElement<Props, Events> {\r\n private _vueApp: App<Element> | null = null\r\n private _propsRef: Ref<Props> = ref({}) as Ref<Props>\r\n private _errorsRef: Ref<string[]> = ref([])\r\n private _contentRef: Ref<string | null> = ref(null)\n private _hostVisibilityRef: Ref<boolean | null> = ref(null)\n /** Cleanup handle for the core-adapter → Vue-ref bridge subscription. */\r\n private _bridgeAbort: AbortController | null = null\r\n\r\n /**\r\n * Override to provide Vue-specific configuration.\r\n */\r\n static get vueConfig(): WippyVueElementConfig {\r\n throw new Error('WippyVueElement subclass must override static get vueConfig()')\r\n }\r\n\r\n protected onMount(\r\n _shadow: ShadowRoot,\r\n container: HTMLElement,\r\n initialProps: Props,\r\n initialErrors: string[],\r\n initialContent?: string | null,\r\n _isRemount?: boolean,\r\n ): void {\r\n // On reconnect (`_isRemount === true`) the previous Vue app was\r\n // already torn down by `onUnmount`, which calls `_vueApp.unmount()`\r\n // and detaches Vue's rendered DOM from the reused container. So we\r\n // can construct a fresh Vue app here — no special-case branch needed.\r\n // If the container ever holds residual children, Vue's mount will\r\n // replace them.\r\n const vueConfig = (this.constructor as typeof WippyVueElement).vueConfig\r\n\r\n // 1. Seed reactive refs from initial state, then bridge to the core\r\n // reactive adapter so subsequent attribute / content changes\r\n // propagate without manual ref writes in `onPropsChanged` /\r\n // `onContentChanged`. The core adapter is the single source of\r\n // truth; the Vue refs are a read-only mirror that consumers reach\r\n // via `useProps()` / `useContent()` / `usePropsErrors()`.\r\n this._propsRef.value = initialProps\r\n this._errorsRef.value = initialErrors\r\n this._contentRef.value = initialContent ?? null\n this._hostVisibilityRef.value = this.hostVisible\n\r\n // Emit initial errors as invalid events\r\n for (const error of initialErrors) {\r\n this.emitEvent('invalid', { message: error })\r\n }\r\n\r\n const bridgeAbort = new AbortController()\r\n this._bridgeAbort = bridgeAbort\r\n this.reactive.props.subscribe((props, errors) => {\r\n this._propsRef.value = props\r\n this._errorsRef.value = [...errors]\r\n for (const error of errors) {\r\n this.emitEvent('invalid', { message: error })\r\n }\r\n }, { signal: bridgeAbort.signal })\r\n\r\n if (this.reactive.content) {\n this.reactive.content.subscribe((content) => {\r\n this._contentRef.value = content\r\n }, { signal: bridgeAbort.signal })\r\n }\n this.reactive.hostVisibility.subscribe((visible) => {\n this._hostVisibilityRef.value = visible\n }, { signal: bridgeAbort.signal })\n\r\n // 2. Create + mount the Vue app from the resolved mount config. Factored\r\n // out so it runs either synchronously (eager `rootComponent`) or after\r\n // `lazyConfig()` resolves (thin-shell path).\r\n const mountApp = (mountConfig: WippyVueMountConfig): void => {\r\n // Bail if the element was disconnected while `lazyConfig()` was in flight.\r\n if (bridgeAbort.signal.aborted)\r\n return\r\n\r\n // Save and restore the host's activePinia so this web component's\r\n // isolated Pinia instance doesn't contaminate the global scope.\r\n // See: https://pinia.vuejs.org/core-concepts/outside-component-usage\r\n const hostPinia = getActivePinia()\r\n\r\n const app = createApp(mountConfig.rootComponent)\r\n this._vueApp = app\r\n const pinia = createPinia()\r\n if (mountConfig.piniaPlugins) {\r\n for (const plugin of mountConfig.piniaPlugins)\r\n pinia.use(plugin)\r\n }\r\n app.use(pinia)\r\n\r\n // Install extra plugins\r\n if (mountConfig.plugins) {\r\n for (const plugin of mountConfig.plugins)\r\n app.use(plugin)\r\n }\r\n\r\n // Provide standard injection keys\r\n app.provide(PROPS_PROVIDER, this._propsRef as Ref<Record<string, unknown>>)\r\n app.provide(PROPS_ERROR_PROVIDER, this._errorsRef)\r\n app.provide(EVENT_PROVIDER, this.emitEvent.bind(this))\r\n app.provide(CONTENT_PROVIDER, this._contentRef)\n app.provide(HOST_VISIBILITY_PROVIDER, this._hostVisibilityRef)\n\r\n // Managed-layout integration. The `ComponentResolver` (host side) sets\r\n // `dataset.wippyPanelId` and `__wippyHostBus` on this element BEFORE\r\n // insertion, so they're available now. Outside a managed-layout host\r\n // both are null — composables tolerate the null path.\r\n app.provide(PANEL_ID_PROVIDER, getWippyPanelId(this))\r\n app.provide(LAYOUT_BUS_PROVIDER, getWippyHostBus(this))\r\n app.provide(HOST_PROVIDER, getWippyHost(this))\r\n\r\n // Custom providers\r\n if (mountConfig.providers)\r\n mountConfig.providers(app, this)\r\n\r\n app.mount(container)\r\n\r\n // Restore the host's activePinia — prevents this web component's Pinia\r\n // from being used by unrelated code that calls useStore() outside of a\r\n // component setup context (e.g. axios interceptors).\r\n if (hostPinia)\r\n setActivePinia(hostPinia)\r\n }\r\n\r\n // 3. Eager `rootComponent` → mount now. Otherwise `lazyConfig` → show a\r\n // `<wippy-loading>` placeholder and mount once the heavy chunk resolves.\r\n if (vueConfig.rootComponent) {\r\n mountApp(vueConfig as WippyVueMountConfig)\r\n }\r\n else if (vueConfig.lazyConfig) {\r\n const loader = document.createElement('wippy-loading')\r\n loader.setAttribute('no-bg', '')\r\n container.appendChild(loader)\r\n vueConfig.lazyConfig()\r\n .then((mountConfig) => {\r\n if (bridgeAbort.signal.aborted)\r\n return\r\n loader.remove()\r\n mountApp(mountConfig)\r\n })\r\n .catch((err) => {\r\n if (bridgeAbort.signal.aborted)\r\n return\r\n // The lazy chunk failed to load (offline / 404 / bad bundle). Swap the\r\n // spinner for a visible <wippy-error> so the element doesn't sit on a\r\n // perpetual loading placeholder; also emit `error` for programmatic\r\n // consumers. (Both wippy-loading/wippy-error are registered together\r\n // by loading.js, which is injected alongside this shell.)\r\n const message = err instanceof Error ? err.message : String(err)\r\n const errorEl = document.createElement('wippy-error')\r\n errorEl.setAttribute('title', 'Failed to load')\r\n errorEl.setAttribute('message', message)\r\n loader.replaceWith(errorEl)\r\n this.emitEvent('error', { message })\r\n })\r\n }\r\n else {\r\n throw new Error('WippyVueElement vueConfig must provide rootComponent or lazyConfig')\r\n }\r\n }\r\n\r\n protected onUnmount(): void {\r\n // Tear down the core-adapter bridge BEFORE unmounting Vue, so the\r\n // Vue refs can't be mutated mid-teardown by a stray late notify.\r\n this._bridgeAbort?.abort()\r\n this._bridgeAbort = null\r\n if (this._vueApp) {\r\n this._vueApp.unmount()\r\n this._vueApp = null\r\n }\r\n }\r\n}\r\n","// Providers: base symbols, composables, and createProviders utility\r\nexport {\r\n CONTENT_PROVIDER,\r\n createProviders,\r\n EVENT_PROVIDER,\r\n HOST_PROVIDER,\n HOST_VISIBILITY_PROVIDER,\n LAYOUT_BUS_PROVIDER,\r\n PANEL_ID_PROVIDER,\r\n PROPS_ERROR_PROVIDER,\r\n PROPS_PROVIDER,\r\n useContent,\r\n useEvents,\r\n useHost,\n useHostVisibility,\n useHostVisibilityRefresh,\n useLayoutBus,\r\n usePanelId,\r\n useProps,\r\n usePropsErrors,\r\n} from './providers.ts'\r\nexport type { TypedProviders } from './providers.ts'\r\n\r\n// Vue layer\r\nexport { WippyVueElement } from './vue-element.ts'\r\nexport type { WippyVueElementConfig, WippyVueMountConfig } from './vue-element.ts'\r\n\r\n// Re-export core for convenience\r\nexport { define, WippyElement } from '@wippy-fe/webcomponent-core'\r\nexport type {\r\n BroadcastEnvelope,\r\n ContentListener,\r\n ContentSubscription,\r\n EventEmitterHandle,\r\n HostCssKey,\n HostVisibilityListener,\n HostVisibilitySubscription,\n LayoutBusBound,\r\n ParseResult,\r\n PropsListener,\r\n PropsSubscription,\r\n ReactiveAdapter,\r\n SubscribeOptions,\r\n WippyElementConfig,\r\n WippyPropDefinition,\r\n WippyPropsSchema,\r\n} from '@wippy-fe/webcomponent-core'\r\n"],"mappings":";;;;;AAEA,SAAS,QAAQ,WAAW,aAAa,aAAa;AAK/C,IAAM,iBAAiB,uBAAO,YAAY;AAK1C,IAAM,iBAAiB,uBAAO,aAAa;AAG3C,IAAM,uBAAuB,uBAAO,mBAAmB;AAGvD,IAAM,mBAAmB,uBAAO,eAAe;AAO/C,IAAM,oBAAoB,uBAAO,gBAAgB;AAOjD,IAAM,sBAAsB,uBAAO,kBAAkB;AASrD,IAAM,gBAAgB,uBAAO,YAAY;AAMzC,IAAM,2BAA2B,uBAAO,uBAAuB;AAe/D,SAAS,WAA8B;AAC5C,QAAM,QAAQ,OAAO,cAAc;AACnC,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,oDAAoD;AACtE,SAAO;AACT;AAYO,SAAS,YAAmF;AACjG,QAAM,OAAO,OAAO,cAAc;AAClC,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,qDAAqD;AACvE,SAAO;AACT;AAYO,SAAS,iBAAgC;AAC9C,QAAM,SAAS,OAAO,oBAAoB;AAC1C,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,0DAA0D;AAC5E,SAAO;AACT;AAaO,SAAS,aAAiC;AAC/C,QAAM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A,MACtB,CAAC,EACA,MAAM,CAAC,QAAQ;AACd,YAAI,YAAY,OAAO;AACrB;AAMF,cAAM,UAAU,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC/D,cAAM,UAAU,SAAS,cAAc,aAAa;AACpD,gBAAQ,aAAa,SAAS,gBAAgB;AAC9C,gBAAQ,aAAa,WAAW,OAAO;AACvC,eAAO,YAAY,OAAO;AAC1B,aAAK,UAAU,SAAS,EAAE,QAAQ,CAAC;AAAA,MACrC,CAAC;AAAA,IACL,OACK;AACH,YAAM,IAAI,MAAM,oEAAoE;AAAA,IACtF;AAAA,EACF;AAAA,EAEU,YAAkB;AAG1B,SAAK,cAAc,MAAM;AACzB,SAAK,eAAe;AACpB,QAAI,KAAK,SAAS;AAChB,WAAK,QAAQ,QAAQ;AACrB,WAAK,UAAU;AAAA,IACjB;AAAA,EACF;AACF;;;AClNA,SAAS,QAAQ,gBAAAA,qBAAoB;","names":["WippyElement"]}
|
|
1
|
+
{"version":3,"sources":["../src/providers.ts","../src/vue-element.ts","../src/index.ts"],"sourcesContent":["import type { LayoutBusBound } from '@wippy-fe/webcomponent-core'\r\nimport type { InjectionKey, Ref } from 'vue'\r\nimport { inject, onMounted, onUnmounted, watch } from 'vue'\n\r\n// ── Base injection keys (untyped) ────────────────────────────\r\n\r\n/** Injection key for the event emitter function. */\r\nexport const EVENT_PROVIDER = Symbol('wippy:emit') as InjectionKey<\r\n (event: string, detail?: unknown) => void\r\n>\r\n\r\n/** Injection key for the reactive props ref. */\r\nexport const PROPS_PROVIDER = Symbol('wippy:props') as InjectionKey<Ref<Record<string, unknown>>>\r\n\r\n/** Injection key for the reactive props error ref. */\r\nexport const PROPS_ERROR_PROVIDER = Symbol('wippy:props_error') as InjectionKey<Ref<string[]>>\r\n\r\n/** Injection key for reactive content from child <template data-type=\"...\"> elements. */\r\nexport const CONTENT_PROVIDER = Symbol('wippy:content') as InjectionKey<Ref<string | null>>\r\n\r\n/**\r\n * Injection key for the panelId this web component lives in (when\r\n * mounted inside a managed-layout `kind: 'component'` panel). `null`\r\n * outside a managed-layout host.\r\n */\r\nexport const PANEL_ID_PROVIDER = Symbol('wippy:panel-id') as InjectionKey<string | null>\r\n\r\n/**\r\n * Injection key for the panel-bound layout bus. Use to publish or\r\n * subscribe to in-tab broadcasts. `null` outside a managed-layout\r\n * host.\r\n */\r\nexport const LAYOUT_BUS_PROVIDER = Symbol('wippy:layout-bus') as InjectionKey<LayoutBusBound | null>\r\n\r\n/**\r\n * Injection key for the panel-scoped `host` wrapper attached by the\r\n * managed-layout shell. Same shape as the iframe-side `host`; layout\r\n * broadcast / send / on are routed through the panel-bound bus so\r\n * sourcePanelId attribution is correct. `null` outside a managed-layout\r\n * host (callers fall back to importing `host` from `@wippy-fe/proxy`).\r\n */\r\nexport const HOST_PROVIDER = Symbol('wippy:host') as InjectionKey<unknown>\n\n/**\n * Reactive logical activity owned by the embedding host. `null` means this\n * component is unmanaged (for example, mounted directly by an application).\n */\nexport const HOST_VISIBILITY_PROVIDER = Symbol('wippy:host-visibility') as InjectionKey<Ref<boolean | null>>\n\r\n// ── Composables (typed) ──────────────────────────────────────\r\n\r\n/**\r\n * Inject the reactive props ref, typed to your component's props interface.\r\n *\r\n * Must be called inside a Vue component's `setup()` that lives within a `WippyVueElement`.\r\n *\r\n * ```ts\r\n * const props = useProps<ComponentProps>()\r\n * // props is Ref<ComponentProps>\r\n * console.log(props.value.maxFileSize)\r\n * ```\r\n */\r\nexport function useProps<Props>(): Ref<Props> {\r\n const props = inject(PROPS_PROVIDER)\r\n if (!props)\r\n throw new Error('useProps() must be called inside a WippyVueElement')\r\n return props as unknown as Ref<Props>\r\n}\r\n\r\n/**\r\n * Inject the typed event emitter, constrained to your component's event map.\r\n *\r\n * Must be called inside a Vue component's `setup()` that lives within a `WippyVueElement`.\r\n *\r\n * ```ts\r\n * const emit = useEvents<Events>()\r\n * emit('upload-complete', { fileId: '123', status: 'done' }) // fully typed\r\n * ```\r\n */\r\nexport function useEvents<Events>(): <K extends keyof Events>(event: K, detail: Events[K]) => void {\r\n const emit = inject(EVENT_PROVIDER)\r\n if (!emit)\r\n throw new Error('useEvents() must be called inside a WippyVueElement')\r\n return emit as unknown as <K extends keyof Events>(event: K, detail: Events[K]) => void\r\n}\r\n\r\n/**\r\n * Inject the reactive prop validation errors ref.\r\n *\r\n * Must be called inside a Vue component's `setup()` that lives within a `WippyVueElement`.\r\n *\r\n * ```ts\r\n * const errors = usePropsErrors()\r\n * // errors is Ref<string[]>\r\n * ```\r\n */\r\nexport function usePropsErrors(): Ref<string[]> {\r\n const errors = inject(PROPS_ERROR_PROVIDER)\r\n if (!errors)\r\n throw new Error('usePropsErrors() must be called inside a WippyVueElement')\r\n return errors\r\n}\r\n\r\n/**\r\n * Inject the reactive content ref (from child `<template data-type=\"...\">` elements).\r\n *\r\n * Must be called inside a Vue component's `setup()` within a `WippyVueElement`\r\n * that has `contentTemplate` configured.\r\n *\r\n * ```ts\r\n * const content = useContent()\r\n * // content is Ref<string | null>\r\n * ```\r\n */\r\nexport function useContent(): Ref<string | null> {\r\n const content = inject(CONTENT_PROVIDER)\r\n if (!content)\r\n throw new Error('useContent() must be called inside a WippyVueElement with contentTemplate configured')\r\n return content\r\n}\r\n\r\n/**\r\n * Inject the current panelId (from `data-wippy-panel-id` set by the\r\n * managed-layout `ComponentResolver`). Returns `null` outside a\r\n * managed-layout host or when not inside a `kind: 'component'` panel.\r\n *\r\n * **Status: Draft 1 (preview).** Part of the managed-layout API; see\r\n * `managed-layout.md` in the Wippy Web Host repository. Field names may change\r\n * between minor releases until a production consumer drives the\r\n * corner cases out.\r\n *\r\n * ```ts\r\n * const panelId = usePanelId()\r\n * if (panelId) console.log('I am the', panelId, 'panel')\r\n * ```\r\n */\r\nexport function usePanelId(): string | null {\r\n return inject(PANEL_ID_PROVIDER, null)\r\n}\r\n\r\n/**\r\n * Inject the panel-bound layout bus. `null` outside a managed-layout\r\n * host. Use to publish on the in-tab bus or subscribe to broadcasts\r\n * targeted at this panel.\r\n *\r\n * **Status: Draft 1 (preview).** Part of the managed-layout API; see\r\n * `managed-layout.md` in the Wippy Web Host repository.\r\n *\r\n * ```ts\r\n * const bus = useLayoutBus()\r\n * bus?.subscribe(({ channel, payload, sourcePanelId }) => { ... })\r\n * bus?.broadcast('open-chat', { token: '...' })\r\n * ```\r\n */\r\nexport function useLayoutBus(): LayoutBusBound | null {\r\n return inject(LAYOUT_BUS_PROVIDER, null)\r\n}\r\n\r\n/**\r\n * Inject the panel-scoped `host` wrapper. `null` outside a\r\n * managed-layout host. Subclass code that needs a host in non-layout\r\n * contexts can fall back to `import { host } from '@wippy-fe/proxy'`.\r\n *\r\n * Pass the host shape as the type parameter to access fields like\r\n * `layout.broadcast`. The default `H = unknown` keeps callers honest\r\n * about narrowing before use.\r\n *\r\n * **Status: Draft 1 (preview).** Part of the managed-layout API; see\r\n * `managed-layout.md` in the Wippy Web Host repository.\r\n *\r\n * ```ts\r\n * import type { ProxyApiInstance } from '@wippy-fe/proxy'\r\n *\r\n * const host = useHost<ProxyApiInstance['host']>()\r\n * host?.layout.broadcast('open-chat', { token })\r\n * host?.layout.updatePanel('right', { route: '/foo' })\r\n * ```\r\n */\r\nexport function useHost<H = unknown>(): H | null {\n return inject(HOST_PROVIDER, null) as H | null\n}\n\n/**\n * Read host-owned logical activity without coupling it to CSS or viewport\n * visibility. Hosts update this ref without remounting the web component.\n */\nexport function useHostVisibility(): Ref<boolean | null> {\n const visible = inject(HOST_VISIBILITY_PROVIDER)\n if (!visible)\n throw new Error('useHostVisibility() must be called inside a WippyVueElement')\n return visible\n}\n\n/**\n * Preserve a component's ordinary initial load, then refresh retained data\n * only when the host reveals a previously inactive element. The callback is\n * serialized so a reveal cannot race an in-flight load. Multiple reveals\n * during one load coalesce into one trailing refresh. The resulting promise\n * is returned to Vue lifecycle/watch handlers so failures continue through\n * Vue's normal error handling.\n */\nexport function useHostVisibilityRefresh(task: () => void | Promise<void>): Ref<boolean | null> {\n const visible = useHostVisibility()\n let mounted = false\n let running: Promise<void> | null = null\n let refreshQueued = false\n\n function runTask(): Promise<void> {\n if (running) {\n refreshQueued = true\n return running\n }\n\n let current: Promise<void>\n try {\n current = Promise.resolve(task())\n }\n catch (error) {\n current = Promise.reject(error)\n }\n\n const scheduled = current.finally(() => {\n if (running !== scheduled)\n return\n running = null\n\n if (mounted && refreshQueued) {\n refreshQueued = false\n return runTask()\n }\n })\n running = scheduled\n return scheduled\n }\n\n onMounted(() => {\n mounted = true\n return runTask()\n })\n\n onUnmounted(() => {\n mounted = false\n refreshQueued = false\n })\n\n watch(visible, (next, previous) => {\n if (mounted && previous === false && next === true)\n return runTask()\n })\n\n return visible\n}\n\r\n// ── createProviders (typed injection keys) ───────────────────\r\n\r\n/**\r\n * Typed provider keys for a specific component.\r\n */\r\nexport interface TypedProviders<Props, Events> {\r\n EVENT_PROVIDER: InjectionKey<<K extends keyof Events>(event: K, detail: Events[K]) => void>\r\n PROPS_PROVIDER: InjectionKey<Ref<Props>>\r\n PROPS_ERROR_PROVIDER: InjectionKey<Ref<string[]>>\r\n}\r\n\r\n/**\r\n * Creates typed provider injection keys for a specific component.\r\n *\r\n * Use this if you prefer raw `inject(KEY)` over the composable helpers.\r\n * Returns the same Symbol instances with narrowed types.\r\n *\r\n * ```ts\r\n * export const { EVENT_PROVIDER, PROPS_PROVIDER, PROPS_ERROR_PROVIDER } =\r\n * createProviders<ComponentProps, Events>()\r\n * ```\r\n */\r\nexport function createProviders<Props, Events = Record<string, unknown>>(): TypedProviders<Props, Events> {\r\n return {\r\n EVENT_PROVIDER: EVENT_PROVIDER as unknown as TypedProviders<Props, Events>['EVENT_PROVIDER'],\r\n PROPS_PROVIDER: PROPS_PROVIDER as unknown as TypedProviders<Props, Events>['PROPS_PROVIDER'],\r\n PROPS_ERROR_PROVIDER,\r\n }\r\n}\r\n","import type { PiniaPlugin } from 'pinia'\r\nimport type { App, Component, Ref } from 'vue'\r\nimport { getWippyHost, getWippyHostBus, getWippyPanelId, WippyElement } from '@wippy-fe/webcomponent-core'\r\nimport { createPinia, getActivePinia, setActivePinia } from 'pinia'\r\nimport { createApp, ref } from 'vue'\r\nimport { CONTENT_PROVIDER, EVENT_PROVIDER, HOST_PROVIDER, HOST_VISIBILITY_PROVIDER, LAYOUT_BUS_PROVIDER, PANEL_ID_PROVIDER, PROPS_ERROR_PROVIDER, PROPS_PROVIDER } from './providers.ts'\n\r\n/**\r\n * The heavy half of a Vue element's config — the root component, its plugins,\r\n * and providers. Either supplied eagerly on `WippyVueElementConfig` or returned\r\n * by `lazyConfig()` from a dynamically-imported chunk (so the element shell can\r\n * stay tiny and load the framework + component tree on first connect).\r\n */\r\nexport interface WippyVueMountConfig {\r\n /** The root Vue component to mount. */\r\n rootComponent: Component\r\n /** Additional Vue plugins to install (beyond Pinia which is always installed). */\r\n plugins?: Array<{ install: (app: App) => void }>\r\n /** Pinia plugins to install (e.g., createWippyPersist()). */\r\n piniaPlugins?: PiniaPlugin[]\r\n /** Extra providers to inject into the Vue app. */\r\n providers?: (app: App, element: WippyVueElement<any, any>) => void\r\n}\r\n\r\n/**\r\n * Vue-specific configuration returned by `static get vueConfig()`.\r\n *\r\n * Provide EITHER an eager `rootComponent` (+ optional plugins/providers) for a\r\n * normal element, OR `lazyConfig` for a thin shell that defers the heavy parts:\r\n * when `lazyConfig` is set and `rootComponent` is omitted, `onMount` shows a\r\n * `<wippy-loading>` placeholder, awaits `lazyConfig()` (typically `() =>\r\n * import('./internals').then(m => ({ rootComponent: m.Root, providers: m.boot }))`),\r\n * then mounts. The props/events bridge + lifecycle stay here, so the lazily\r\n * imported chunk only carries the framework + component tree.\r\n */\r\nexport interface WippyVueElementConfig extends Partial<WippyVueMountConfig> {\r\n /** Lazily resolve the mount config (root + plugins + providers) on first connect. */\r\n lazyConfig?: () => Promise<WippyVueMountConfig>\r\n}\r\n\r\n/**\r\n * Vue 3 integration for Wippy web components.\r\n *\r\n * Generic over `Props` (parsed prop object type) and `Events` (event map).\r\n * These flow through to typed hooks, reactive refs, and composable helpers.\r\n *\r\n * Usage:\r\n * ```ts\r\n * class MyElement extends WippyVueElement<MyProps, MyEvents> {\r\n * static get wippyConfig(): WippyElementConfig<MyProps> {\r\n * return { propsSchema: pkg.wippy.props, inlineCss: stylesText }\r\n * }\r\n * static get vueConfig() {\r\n * return { rootComponent: MyApp }\r\n * }\r\n * }\r\n * ```\r\n *\r\n * In Vue components, use the typed composable helpers:\r\n * ```ts\r\n * const props = useProps<MyProps>()\r\n * const emit = useEvents<MyEvents>()\r\n * const errors = usePropsErrors()\r\n * ```\r\n */\r\nexport abstract class WippyVueElement<\r\n Props = Record<string, unknown>,\r\n Events = Record<string, unknown>,\r\n> extends WippyElement<Props, Events> {\r\n private _vueApp: App<Element> | null = null\r\n private _propsRef: Ref<Props> = ref({}) as Ref<Props>\r\n private _errorsRef: Ref<string[]> = ref([])\r\n private _contentRef: Ref<string | null> = ref(null)\n private _hostVisibilityRef: Ref<boolean | null> = ref(null)\n /** Cleanup handle for the core-adapter → Vue-ref bridge subscription. */\r\n private _bridgeAbort: AbortController | null = null\r\n\r\n /**\r\n * Override to provide Vue-specific configuration.\r\n */\r\n static get vueConfig(): WippyVueElementConfig {\r\n throw new Error('WippyVueElement subclass must override static get vueConfig()')\r\n }\r\n\r\n protected onMount(\r\n _shadow: ShadowRoot,\r\n container: HTMLElement,\r\n initialProps: Props,\r\n initialErrors: string[],\r\n initialContent?: string | null,\r\n _isRemount?: boolean,\r\n ): void {\r\n // On reconnect (`_isRemount === true`) the previous Vue app was\r\n // already torn down by `onUnmount`, which calls `_vueApp.unmount()`\r\n // and detaches Vue's rendered DOM from the reused container. So we\r\n // can construct a fresh Vue app here — no special-case branch needed.\r\n // If the container ever holds residual children, Vue's mount will\r\n // replace them.\r\n const vueConfig = (this.constructor as typeof WippyVueElement).vueConfig\r\n\r\n // 1. Seed reactive refs from initial state, then bridge to the core\r\n // reactive adapter so subsequent attribute / content changes\r\n // propagate without manual ref writes in `onPropsChanged` /\r\n // `onContentChanged`. The core adapter is the single source of\r\n // truth; the Vue refs are a read-only mirror that consumers reach\r\n // via `useProps()` / `useContent()` / `usePropsErrors()`.\r\n this._propsRef.value = initialProps\r\n this._errorsRef.value = initialErrors\r\n this._contentRef.value = initialContent ?? null\n this._hostVisibilityRef.value = this.hostVisible\n\r\n // Emit initial errors as invalid events\r\n for (const error of initialErrors) {\r\n this.emitEvent('invalid', { message: error })\r\n }\r\n\r\n const bridgeAbort = new AbortController()\r\n this._bridgeAbort = bridgeAbort\r\n this.reactive.props.subscribe((props, errors) => {\r\n this._propsRef.value = props\r\n this._errorsRef.value = [...errors]\r\n for (const error of errors) {\r\n this.emitEvent('invalid', { message: error })\r\n }\r\n }, { signal: bridgeAbort.signal })\r\n\r\n if (this.reactive.content) {\n this.reactive.content.subscribe((content) => {\r\n this._contentRef.value = content\r\n }, { signal: bridgeAbort.signal })\r\n }\n this.reactive.hostVisibility.subscribe((visible) => {\n this._hostVisibilityRef.value = visible\n }, { signal: bridgeAbort.signal })\n\r\n // 2. Create + mount the Vue app from the resolved mount config. Factored\r\n // out so it runs either synchronously (eager `rootComponent`) or after\r\n // `lazyConfig()` resolves (thin-shell path).\r\n const mountApp = (mountConfig: WippyVueMountConfig): void => {\r\n // Bail if the element was disconnected while `lazyConfig()` was in flight.\r\n if (bridgeAbort.signal.aborted)\r\n return\r\n\r\n // Save and restore the host's activePinia so this web component's\r\n // isolated Pinia instance doesn't contaminate the global scope.\r\n // See: https://pinia.vuejs.org/core-concepts/outside-component-usage\r\n const hostPinia = getActivePinia()\r\n\r\n const app = createApp(mountConfig.rootComponent)\r\n this._vueApp = app\r\n const pinia = createPinia()\r\n if (mountConfig.piniaPlugins) {\r\n for (const plugin of mountConfig.piniaPlugins)\r\n pinia.use(plugin)\r\n }\r\n app.use(pinia)\r\n\r\n // Install extra plugins\r\n if (mountConfig.plugins) {\r\n for (const plugin of mountConfig.plugins)\r\n app.use(plugin)\r\n }\r\n\r\n // Provide standard injection keys\r\n app.provide(PROPS_PROVIDER, this._propsRef as Ref<Record<string, unknown>>)\r\n app.provide(PROPS_ERROR_PROVIDER, this._errorsRef)\r\n app.provide(EVENT_PROVIDER, this.emitEvent.bind(this))\r\n app.provide(CONTENT_PROVIDER, this._contentRef)\n app.provide(HOST_VISIBILITY_PROVIDER, this._hostVisibilityRef)\n\r\n // Managed-layout integration. The `ComponentResolver` (host side) sets\r\n // `dataset.wippyPanelId` and `__wippyHostBus` on this element BEFORE\r\n // insertion, so they're available now. Outside a managed-layout host\r\n // both are null — composables tolerate the null path.\r\n app.provide(PANEL_ID_PROVIDER, getWippyPanelId(this))\r\n app.provide(LAYOUT_BUS_PROVIDER, getWippyHostBus(this))\r\n app.provide(HOST_PROVIDER, getWippyHost(this))\r\n\r\n // Custom providers\r\n if (mountConfig.providers)\r\n mountConfig.providers(app, this)\r\n\r\n app.mount(container)\r\n\r\n // Restore the host's activePinia — prevents this web component's Pinia\r\n // from being used by unrelated code that calls useStore() outside of a\r\n // component setup context (e.g. axios interceptors).\r\n if (hostPinia)\r\n setActivePinia(hostPinia)\r\n }\r\n\r\n // 3. Eager `rootComponent` → mount now. Otherwise `lazyConfig` → show a\r\n // `<wippy-loading>` placeholder and mount once the heavy chunk resolves.\r\n if (vueConfig.rootComponent) {\r\n mountApp(vueConfig as WippyVueMountConfig)\r\n }\r\n else if (vueConfig.lazyConfig) {\r\n const loader = document.createElement('wippy-loading')\r\n loader.setAttribute('no-bg', '')\r\n container.appendChild(loader)\r\n vueConfig.lazyConfig()\r\n .then((mountConfig) => {\r\n if (bridgeAbort.signal.aborted)\r\n return\r\n loader.remove()\r\n mountApp(mountConfig)\r\n })\r\n .catch((err) => {\r\n if (bridgeAbort.signal.aborted)\r\n return\r\n // The lazy chunk failed to load (offline / 404 / bad bundle). Swap the\r\n // spinner for a visible <wippy-error> so the element doesn't sit on a\r\n // perpetual loading placeholder; also emit `error` for programmatic\r\n // consumers. (Both wippy-loading/wippy-error are registered together\r\n // by loading.js, which is injected alongside this shell.)\r\n const message = err instanceof Error ? err.message : String(err)\r\n const errorEl = document.createElement('wippy-error')\r\n errorEl.setAttribute('title', 'Failed to load')\r\n errorEl.setAttribute('message', message)\r\n loader.replaceWith(errorEl)\r\n this.emitEvent('error', { message })\r\n })\r\n }\r\n else {\r\n throw new Error('WippyVueElement vueConfig must provide rootComponent or lazyConfig')\r\n }\r\n }\r\n\r\n protected onUnmount(): void {\r\n // Tear down the core-adapter bridge BEFORE unmounting Vue, so the\r\n // Vue refs can't be mutated mid-teardown by a stray late notify.\r\n this._bridgeAbort?.abort()\r\n this._bridgeAbort = null\r\n if (this._vueApp) {\r\n this._vueApp.unmount()\r\n this._vueApp = null\r\n }\r\n }\r\n}\r\n","// Providers: base symbols, composables, and createProviders utility\r\nexport {\r\n CONTENT_PROVIDER,\r\n createProviders,\r\n EVENT_PROVIDER,\r\n HOST_PROVIDER,\n HOST_VISIBILITY_PROVIDER,\n LAYOUT_BUS_PROVIDER,\r\n PANEL_ID_PROVIDER,\r\n PROPS_ERROR_PROVIDER,\r\n PROPS_PROVIDER,\r\n useContent,\r\n useEvents,\r\n useHost,\n useHostVisibility,\n useHostVisibilityRefresh,\n useLayoutBus,\r\n usePanelId,\r\n useProps,\r\n usePropsErrors,\r\n} from './providers.ts'\r\nexport type { TypedProviders } from './providers.ts'\r\n\r\n// Vue layer\r\nexport { WippyVueElement } from './vue-element.ts'\r\nexport type { WippyVueElementConfig, WippyVueMountConfig } from './vue-element.ts'\r\n\r\n// Re-export core for convenience\r\nexport { define, WippyElement } from '@wippy-fe/webcomponent-core'\r\nexport type {\r\n BroadcastEnvelope,\r\n ContentListener,\r\n ContentSubscription,\r\n EventEmitterHandle,\r\n HostCssKey,\n HostVisibilityListener,\n HostVisibilitySubscription,\n LayoutBusBound,\r\n ParseResult,\r\n PropsListener,\r\n PropsSubscription,\r\n ReactiveAdapter,\r\n SubscribeOptions,\r\n WippyElementConfig,\r\n WippyPropDefinition,\r\n WippyPropsSchema,\r\n} from '@w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,QAAQ,QAAQ;AACrB,WAAK,UAAU;AAAA,IACjB;AAAA,EACF;AACF;;;AClNA,SAAS,QAAQ,gBAAAA,qBAAoB;","names":["WippyElement"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wippy-fe/webcomponent-vue",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.65",
|
|
4
4
|
"description": "Vue 3 integration layer for Wippy web components - extends @wippy-fe/webcomponent-core with reactive props, Pinia, and provider injection.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"dist/"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@wippy-fe/webcomponent-core": "^0.0.
|
|
24
|
+
"@wippy-fe/webcomponent-core": "^0.0.65"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@iconify/vue": "^5.0.0",
|
|
28
28
|
"pinia": "^2.1.0 || ^3.0.0 || ^4.0.0",
|
|
29
29
|
"vue": "^3.5.0",
|
|
30
|
-
"@wippy-fe/proxy": "^0.0.
|
|
31
|
-
"@wippy-fe/shared": "^0.0.
|
|
30
|
+
"@wippy-fe/proxy": "^0.0.65",
|
|
31
|
+
"@wippy-fe/shared": "^0.0.65"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "tsup",
|