@wippy-fe/webcomponent-vue 0.0.32 → 0.0.35

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.
@@ -1,205 +1,208 @@
1
- import type { LayoutBusBound } from '@wippy-fe/webcomponent-core'
2
- import type { InjectionKey, Ref } from 'vue'
3
- import { inject } from 'vue'
4
-
5
- // ── Base injection keys (untyped) ────────────────────────────
6
-
7
- /** Injection key for the event emitter function. */
8
- export const EVENT_PROVIDER = Symbol('wippy:emit') as InjectionKey<
9
- (event: string, detail?: unknown) => void
10
- >
11
-
12
- /** Injection key for the reactive props ref. */
13
- export const PROPS_PROVIDER = Symbol('wippy:props') as InjectionKey<Ref<Record<string, unknown>>>
14
-
15
- /** Injection key for the reactive props error ref. */
16
- export const PROPS_ERROR_PROVIDER = Symbol('wippy:props_error') as InjectionKey<Ref<string[]>>
17
-
18
- /** Injection key for reactive content from child <template data-type="..."> elements. */
19
- export const CONTENT_PROVIDER = Symbol('wippy:content') as InjectionKey<Ref<string | null>>
20
-
21
- /**
22
- * Injection key for the panelId this web component lives in (when
23
- * mounted inside a managed-layout `kind: 'component'` panel). `null`
24
- * outside a managed-layout host.
25
- */
26
- export const PANEL_ID_PROVIDER = Symbol('wippy:panel-id') as InjectionKey<string | null>
27
-
28
- /**
29
- * Injection key for the panel-bound layout bus. Use to publish or
30
- * subscribe to in-tab broadcasts. `null` outside a managed-layout
31
- * host.
32
- */
33
- export const LAYOUT_BUS_PROVIDER = Symbol('wippy:layout-bus') as InjectionKey<LayoutBusBound | null>
34
-
35
- /**
36
- * Injection key for the panel-scoped `host` wrapper attached by the
37
- * managed-layout shell. Same shape as the iframe-side `host`; layout
38
- * broadcast / send / on are routed through the panel-bound bus so
39
- * sourcePanelId attribution is correct. `null` outside a managed-layout
40
- * host (callers fall back to importing `host` from `@wippy-fe/proxy`).
41
- */
42
- export const HOST_PROVIDER = Symbol('wippy:host') as InjectionKey<unknown>
43
-
44
- // ── Composables (typed) ──────────────────────────────────────
45
-
46
- /**
47
- * Inject the reactive props ref, typed to your component's props interface.
48
- *
49
- * Must be called inside a Vue component's `setup()` that lives within a `WippyVueElement`.
50
- *
51
- * ```ts
52
- * const props = useProps<ComponentProps>()
53
- * // props is Ref<ComponentProps>
54
- * console.log(props.value.maxFileSize)
55
- * ```
56
- */
57
- export function useProps<Props>(): Ref<Props> {
58
- const props = inject(PROPS_PROVIDER)
59
- if (!props)
60
- throw new Error('useProps() must be called inside a WippyVueElement')
61
- return props as unknown as Ref<Props>
62
- }
63
-
64
- /**
65
- * Inject the typed event emitter, constrained to your component's event map.
66
- *
67
- * Must be called inside a Vue component's `setup()` that lives within a `WippyVueElement`.
68
- *
69
- * ```ts
70
- * const emit = useEvents<Events>()
71
- * emit('upload-complete', { fileId: '123', status: 'done' }) // fully typed
72
- * ```
73
- */
74
- export function useEvents<Events>(): <K extends keyof Events>(event: K, detail: Events[K]) => void {
75
- const emit = inject(EVENT_PROVIDER)
76
- if (!emit)
77
- throw new Error('useEvents() must be called inside a WippyVueElement')
78
- return emit as unknown as <K extends keyof Events>(event: K, detail: Events[K]) => void
79
- }
80
-
81
- /**
82
- * Inject the reactive prop validation errors ref.
83
- *
84
- * Must be called inside a Vue component's `setup()` that lives within a `WippyVueElement`.
85
- *
86
- * ```ts
87
- * const errors = usePropsErrors()
88
- * // errors is Ref<string[]>
89
- * ```
90
- */
91
- export function usePropsErrors(): Ref<string[]> {
92
- const errors = inject(PROPS_ERROR_PROVIDER)
93
- if (!errors)
94
- throw new Error('usePropsErrors() must be called inside a WippyVueElement')
95
- return errors
96
- }
97
-
98
- /**
99
- * Inject the reactive content ref (from child `<template data-type="...">` elements).
100
- *
101
- * Must be called inside a Vue component's `setup()` within a `WippyVueElement`
102
- * that has `contentTemplate` configured.
103
- *
104
- * ```ts
105
- * const content = useContent()
106
- * // content is Ref<string | null>
107
- * ```
108
- */
109
- export function useContent(): Ref<string | null> {
110
- const content = inject(CONTENT_PROVIDER)
111
- if (!content)
112
- throw new Error('useContent() must be called inside a WippyVueElement with contentTemplate configured')
113
- return content
114
- }
115
-
116
- /**
117
- * Inject the current panelId (from `data-wippy-panel-id` set by the
118
- * managed-layout `ComponentResolver`). Returns `null` outside a
119
- * managed-layout host or when not inside a `kind: 'component'` panel.
120
- *
121
- * **Status: Draft 1 (preview).** Part of the managed-layout API; see
122
- * `managed-layout.md` in the gen-2-chat repo. Field names may change
123
- * between minor releases until a production consumer drives the
124
- * corner cases out.
125
- *
126
- * ```ts
127
- * const panelId = usePanelId()
128
- * if (panelId) console.log('I am the', panelId, 'panel')
129
- * ```
130
- */
131
- export function usePanelId(): string | null {
132
- return inject(PANEL_ID_PROVIDER, null)
133
- }
134
-
135
- /**
136
- * Inject the panel-bound layout bus. `null` outside a managed-layout
137
- * host. Use to publish on the in-tab bus or subscribe to broadcasts
138
- * targeted at this panel.
139
- *
140
- * **Status: Draft 1 (preview).** Part of the managed-layout API; see
141
- * `managed-layout.md` in the gen-2-chat repo.
142
- *
143
- * ```ts
144
- * const bus = useLayoutBus()
145
- * bus?.subscribe(({ channel, payload, sourcePanelId }) => { ... })
146
- * bus?.broadcast('open-chat', { token: '...' })
147
- * ```
148
- */
149
- export function useLayoutBus(): LayoutBusBound | null {
150
- return inject(LAYOUT_BUS_PROVIDER, null)
151
- }
152
-
153
- /**
154
- * Inject the panel-scoped `host` wrapper. `null` outside a
155
- * managed-layout host. Subclass code that needs a host in non-layout
156
- * contexts can fall back to `import { host } from '@wippy-fe/proxy'`.
157
- *
158
- * Pass the host shape as the type parameter to access fields like
159
- * `layout.broadcast`. The default `H = unknown` keeps callers honest
160
- * about narrowing before use.
161
- *
162
- * **Status: Draft 1 (preview).** Part of the managed-layout API; see
163
- * `managed-layout.md` in the gen-2-chat repo.
164
- *
165
- * ```ts
166
- * import type { ProxyApiInstance } from '@wippy-fe/proxy'
167
- *
168
- * const host = useHost<ProxyApiInstance['host']>()
169
- * host?.layout.broadcast('open-chat', { token })
170
- * host?.layout.updatePanel('right', { route: '/foo' })
171
- * ```
172
- */
173
- export function useHost<H = unknown>(): H | null {
174
- return inject(HOST_PROVIDER, null) as H | null
175
- }
176
-
177
- // ── createProviders (typed injection keys) ───────────────────
178
-
179
- /**
180
- * Typed provider keys for a specific component.
181
- */
182
- export interface TypedProviders<Props, Events> {
183
- EVENT_PROVIDER: InjectionKey<<K extends keyof Events>(event: K, detail: Events[K]) => void>
184
- PROPS_PROVIDER: InjectionKey<Ref<Props>>
185
- PROPS_ERROR_PROVIDER: InjectionKey<Ref<string[]>>
186
- }
187
-
188
- /**
189
- * Creates typed provider injection keys for a specific component.
190
- *
191
- * Use this if you prefer raw `inject(KEY)` over the composable helpers.
192
- * Returns the same Symbol instances with narrowed types.
193
- *
194
- * ```ts
195
- * export const { EVENT_PROVIDER, PROPS_PROVIDER, PROPS_ERROR_PROVIDER } =
196
- * createProviders<ComponentProps, Events>()
197
- * ```
198
- */
199
- export function createProviders<Props, Events = Record<string, unknown>>(): TypedProviders<Props, Events> {
200
- return {
201
- EVENT_PROVIDER: EVENT_PROVIDER as unknown as TypedProviders<Props, Events>['EVENT_PROVIDER'],
202
- PROPS_PROVIDER: PROPS_PROVIDER as unknown as TypedProviders<Props, Events>['PROPS_PROVIDER'],
203
- PROPS_ERROR_PROVIDER,
204
- }
205
- }
1
+ import { LayoutBusBound, WippyElement } from '@wippy-fe/webcomponent-core';
2
+ export { BroadcastEnvelope, ContentListener, ContentSubscription, EventEmitterHandle, HostCssKey, LayoutBusBound, ParseResult, PropsListener, PropsSubscription, ReactiveAdapter, SubscribeOptions, WippyElement, WippyElementConfig, WippyPropDefinition, WippyPropsSchema, define } from '@wippy-fe/webcomponent-core';
3
+ import { InjectionKey, Ref, Component, App } from 'vue';
4
+ import { PiniaPlugin } from 'pinia';
5
+
6
+ /** Injection key for the event emitter function. */
7
+ declare const EVENT_PROVIDER: InjectionKey<(event: string, detail?: unknown) => void>;
8
+ /** Injection key for the reactive props ref. */
9
+ declare const PROPS_PROVIDER: InjectionKey<Ref<Record<string, unknown>>>;
10
+ /** Injection key for the reactive props error ref. */
11
+ declare const PROPS_ERROR_PROVIDER: InjectionKey<Ref<string[]>>;
12
+ /** Injection key for reactive content from child <template data-type="..."> elements. */
13
+ declare const CONTENT_PROVIDER: InjectionKey<Ref<string | null>>;
14
+ /**
15
+ * Injection key for the panelId this web component lives in (when
16
+ * mounted inside a managed-layout `kind: 'component'` panel). `null`
17
+ * outside a managed-layout host.
18
+ */
19
+ declare const PANEL_ID_PROVIDER: InjectionKey<string | null>;
20
+ /**
21
+ * Injection key for the panel-bound layout bus. Use to publish or
22
+ * subscribe to in-tab broadcasts. `null` outside a managed-layout
23
+ * host.
24
+ */
25
+ declare const LAYOUT_BUS_PROVIDER: InjectionKey<LayoutBusBound | null>;
26
+ /**
27
+ * Injection key for the panel-scoped `host` wrapper attached by the
28
+ * managed-layout shell. Same shape as the iframe-side `host`; layout
29
+ * broadcast / send / on are routed through the panel-bound bus so
30
+ * sourcePanelId attribution is correct. `null` outside a managed-layout
31
+ * host (callers fall back to importing `host` from `@wippy-fe/proxy`).
32
+ */
33
+ declare const HOST_PROVIDER: InjectionKey<unknown>;
34
+ /**
35
+ * Inject the reactive props ref, typed to your component's props interface.
36
+ *
37
+ * Must be called inside a Vue component's `setup()` that lives within a `WippyVueElement`.
38
+ *
39
+ * ```ts
40
+ * const props = useProps<ComponentProps>()
41
+ * // props is Ref<ComponentProps>
42
+ * console.log(props.value.maxFileSize)
43
+ * ```
44
+ */
45
+ declare function useProps<Props>(): Ref<Props>;
46
+ /**
47
+ * Inject the typed event emitter, constrained to your component's event map.
48
+ *
49
+ * Must be called inside a Vue component's `setup()` that lives within a `WippyVueElement`.
50
+ *
51
+ * ```ts
52
+ * const emit = useEvents<Events>()
53
+ * emit('upload-complete', { fileId: '123', status: 'done' }) // fully typed
54
+ * ```
55
+ */
56
+ declare function useEvents<Events>(): <K extends keyof Events>(event: K, detail: Events[K]) => void;
57
+ /**
58
+ * Inject the reactive prop validation errors ref.
59
+ *
60
+ * Must be called inside a Vue component's `setup()` that lives within a `WippyVueElement`.
61
+ *
62
+ * ```ts
63
+ * const errors = usePropsErrors()
64
+ * // errors is Ref<string[]>
65
+ * ```
66
+ */
67
+ declare function usePropsErrors(): Ref<string[]>;
68
+ /**
69
+ * Inject the reactive content ref (from child `<template data-type="...">` elements).
70
+ *
71
+ * Must be called inside a Vue component's `setup()` within a `WippyVueElement`
72
+ * that has `contentTemplate` configured.
73
+ *
74
+ * ```ts
75
+ * const content = useContent()
76
+ * // content is Ref<string | null>
77
+ * ```
78
+ */
79
+ declare function useContent(): Ref<string | null>;
80
+ /**
81
+ * Inject the current panelId (from `data-wippy-panel-id` set by the
82
+ * managed-layout `ComponentResolver`). Returns `null` outside a
83
+ * managed-layout host or when not inside a `kind: 'component'` panel.
84
+ *
85
+ * **Status: Draft 1 (preview).** Part of the managed-layout API; see
86
+ * `managed-layout.md` in the gen-2-chat repo. Field names may change
87
+ * between minor releases until a production consumer drives the
88
+ * corner cases out.
89
+ *
90
+ * ```ts
91
+ * const panelId = usePanelId()
92
+ * if (panelId) console.log('I am the', panelId, 'panel')
93
+ * ```
94
+ */
95
+ declare function usePanelId(): string | null;
96
+ /**
97
+ * Inject the panel-bound layout bus. `null` outside a managed-layout
98
+ * host. Use to publish on the in-tab bus or subscribe to broadcasts
99
+ * targeted at this panel.
100
+ *
101
+ * **Status: Draft 1 (preview).** Part of the managed-layout API; see
102
+ * `managed-layout.md` in the gen-2-chat repo.
103
+ *
104
+ * ```ts
105
+ * const bus = useLayoutBus()
106
+ * bus?.subscribe(({ channel, payload, sourcePanelId }) => { ... })
107
+ * bus?.broadcast('open-chat', { token: '...' })
108
+ * ```
109
+ */
110
+ declare function useLayoutBus(): LayoutBusBound | null;
111
+ /**
112
+ * Inject the panel-scoped `host` wrapper. `null` outside a
113
+ * managed-layout host. Subclass code that needs a host in non-layout
114
+ * contexts can fall back to `import { host } from '@wippy-fe/proxy'`.
115
+ *
116
+ * Pass the host shape as the type parameter to access fields like
117
+ * `layout.broadcast`. The default `H = unknown` keeps callers honest
118
+ * about narrowing before use.
119
+ *
120
+ * **Status: Draft 1 (preview).** Part of the managed-layout API; see
121
+ * `managed-layout.md` in the gen-2-chat repo.
122
+ *
123
+ * ```ts
124
+ * import type { ProxyApiInstance } from '@wippy-fe/proxy'
125
+ *
126
+ * const host = useHost<ProxyApiInstance['host']>()
127
+ * host?.layout.broadcast('open-chat', { token })
128
+ * host?.layout.updatePanel('right', { route: '/foo' })
129
+ * ```
130
+ */
131
+ declare function useHost<H = unknown>(): H | null;
132
+ /**
133
+ * Typed provider keys for a specific component.
134
+ */
135
+ interface TypedProviders<Props, Events> {
136
+ EVENT_PROVIDER: InjectionKey<(<K extends keyof Events>(event: K, detail: Events[K]) => void)>;
137
+ PROPS_PROVIDER: InjectionKey<Ref<Props>>;
138
+ PROPS_ERROR_PROVIDER: InjectionKey<Ref<string[]>>;
139
+ }
140
+ /**
141
+ * Creates typed provider injection keys for a specific component.
142
+ *
143
+ * Use this if you prefer raw `inject(KEY)` over the composable helpers.
144
+ * Returns the same Symbol instances with narrowed types.
145
+ *
146
+ * ```ts
147
+ * export const { EVENT_PROVIDER, PROPS_PROVIDER, PROPS_ERROR_PROVIDER } =
148
+ * createProviders<ComponentProps, Events>()
149
+ * ```
150
+ */
151
+ declare function createProviders<Props, Events = Record<string, unknown>>(): TypedProviders<Props, Events>;
152
+
153
+ /**
154
+ * Vue-specific configuration returned by `static get vueConfig()`.
155
+ */
156
+ interface WippyVueElementConfig {
157
+ /** The root Vue component to mount. */
158
+ rootComponent: Component;
159
+ /** Additional Vue plugins to install (beyond Pinia which is always installed). */
160
+ plugins?: Array<{
161
+ install: (app: App) => void;
162
+ }>;
163
+ /** Pinia plugins to install (e.g., createWippyPersist()). */
164
+ piniaPlugins?: PiniaPlugin[];
165
+ /** Extra providers to inject into the Vue app. */
166
+ providers?: (app: App, element: WippyVueElement<any, any>) => void;
167
+ }
168
+ /**
169
+ * Vue 3 integration for Wippy web components.
170
+ *
171
+ * Generic over `Props` (parsed prop object type) and `Events` (event map).
172
+ * These flow through to typed hooks, reactive refs, and composable helpers.
173
+ *
174
+ * Usage:
175
+ * ```ts
176
+ * class MyElement extends WippyVueElement<MyProps, MyEvents> {
177
+ * static get wippyConfig(): WippyElementConfig<MyProps> {
178
+ * return { propsSchema: pkg.wippy.props, inlineCss: stylesText }
179
+ * }
180
+ * static get vueConfig() {
181
+ * return { rootComponent: MyApp }
182
+ * }
183
+ * }
184
+ * ```
185
+ *
186
+ * In Vue components, use the typed composable helpers:
187
+ * ```ts
188
+ * const props = useProps<MyProps>()
189
+ * const emit = useEvents<MyEvents>()
190
+ * const errors = usePropsErrors()
191
+ * ```
192
+ */
193
+ declare abstract class WippyVueElement<Props = Record<string, unknown>, Events = Record<string, unknown>> extends WippyElement<Props, Events> {
194
+ private _vueApp;
195
+ private _propsRef;
196
+ private _errorsRef;
197
+ private _contentRef;
198
+ /** Cleanup handle for the core-adapter → Vue-ref bridge subscription. */
199
+ private _bridgeAbort;
200
+ /**
201
+ * Override to provide Vue-specific configuration.
202
+ */
203
+ static get vueConfig(): WippyVueElementConfig;
204
+ protected onMount(_shadow: ShadowRoot, container: HTMLElement, initialProps: Props, initialErrors: string[], initialContent?: string | null, _isRemount?: boolean): void;
205
+ protected onUnmount(): void;
206
+ }
207
+
208
+ export { CONTENT_PROVIDER, EVENT_PROVIDER, HOST_PROVIDER, LAYOUT_BUS_PROVIDER, PANEL_ID_PROVIDER, PROPS_ERROR_PROVIDER, PROPS_PROVIDER, type TypedProviders, WippyVueElement, type WippyVueElementConfig, createProviders, useContent, useEvents, useHost, useLayoutBus, usePanelId, useProps, usePropsErrors };
package/dist/index.js ADDED
@@ -0,0 +1,155 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+
5
+ // src/providers.ts
6
+ import { inject } from "vue";
7
+ var EVENT_PROVIDER = /* @__PURE__ */ Symbol("wippy:emit");
8
+ var PROPS_PROVIDER = /* @__PURE__ */ Symbol("wippy:props");
9
+ var PROPS_ERROR_PROVIDER = /* @__PURE__ */ Symbol("wippy:props_error");
10
+ var CONTENT_PROVIDER = /* @__PURE__ */ Symbol("wippy:content");
11
+ var PANEL_ID_PROVIDER = /* @__PURE__ */ Symbol("wippy:panel-id");
12
+ var LAYOUT_BUS_PROVIDER = /* @__PURE__ */ Symbol("wippy:layout-bus");
13
+ var HOST_PROVIDER = /* @__PURE__ */ Symbol("wippy:host");
14
+ function useProps() {
15
+ const props = inject(PROPS_PROVIDER);
16
+ if (!props)
17
+ throw new Error("useProps() must be called inside a WippyVueElement");
18
+ return props;
19
+ }
20
+ function useEvents() {
21
+ const emit = inject(EVENT_PROVIDER);
22
+ if (!emit)
23
+ throw new Error("useEvents() must be called inside a WippyVueElement");
24
+ return emit;
25
+ }
26
+ function usePropsErrors() {
27
+ const errors = inject(PROPS_ERROR_PROVIDER);
28
+ if (!errors)
29
+ throw new Error("usePropsErrors() must be called inside a WippyVueElement");
30
+ return errors;
31
+ }
32
+ function useContent() {
33
+ const content = inject(CONTENT_PROVIDER);
34
+ if (!content)
35
+ throw new Error("useContent() must be called inside a WippyVueElement with contentTemplate configured");
36
+ return content;
37
+ }
38
+ function usePanelId() {
39
+ return inject(PANEL_ID_PROVIDER, null);
40
+ }
41
+ function useLayoutBus() {
42
+ return inject(LAYOUT_BUS_PROVIDER, null);
43
+ }
44
+ function useHost() {
45
+ return inject(HOST_PROVIDER, null);
46
+ }
47
+ function createProviders() {
48
+ return {
49
+ EVENT_PROVIDER,
50
+ PROPS_PROVIDER,
51
+ PROPS_ERROR_PROVIDER
52
+ };
53
+ }
54
+
55
+ // src/vue-element.ts
56
+ import { getWippyHost, getWippyHostBus, getWippyPanelId, WippyElement } from "@wippy-fe/webcomponent-core";
57
+ import { createPinia, getActivePinia, setActivePinia } from "pinia";
58
+ import { createApp, ref } from "vue";
59
+ var WippyVueElement = class extends WippyElement {
60
+ constructor() {
61
+ super(...arguments);
62
+ __publicField(this, "_vueApp", null);
63
+ __publicField(this, "_propsRef", ref({}));
64
+ __publicField(this, "_errorsRef", ref([]));
65
+ __publicField(this, "_contentRef", ref(null));
66
+ /** Cleanup handle for the core-adapter → Vue-ref bridge subscription. */
67
+ __publicField(this, "_bridgeAbort", null);
68
+ }
69
+ /**
70
+ * Override to provide Vue-specific configuration.
71
+ */
72
+ static get vueConfig() {
73
+ throw new Error("WippyVueElement subclass must override static get vueConfig()");
74
+ }
75
+ onMount(_shadow, container, initialProps, initialErrors, initialContent, _isRemount) {
76
+ const vueConfig = this.constructor.vueConfig;
77
+ this._propsRef.value = initialProps;
78
+ this._errorsRef.value = initialErrors;
79
+ this._contentRef.value = initialContent ?? null;
80
+ for (const error of initialErrors) {
81
+ this.emitEvent("invalid", { message: error });
82
+ }
83
+ this._bridgeAbort = new AbortController();
84
+ this.reactive.props.subscribe((props, errors) => {
85
+ this._propsRef.value = props;
86
+ this._errorsRef.value = [...errors];
87
+ for (const error of errors) {
88
+ this.emitEvent("invalid", { message: error });
89
+ }
90
+ }, { signal: this._bridgeAbort.signal });
91
+ if (this.reactive.content) {
92
+ this.reactive.content.subscribe((content) => {
93
+ this._contentRef.value = content;
94
+ }, { signal: this._bridgeAbort.signal });
95
+ }
96
+ const hostPinia = getActivePinia();
97
+ this._vueApp = createApp(vueConfig.rootComponent);
98
+ const pinia = createPinia();
99
+ if (vueConfig.piniaPlugins) {
100
+ for (const plugin of vueConfig.piniaPlugins)
101
+ pinia.use(plugin);
102
+ }
103
+ this._vueApp.use(pinia);
104
+ if (vueConfig.plugins) {
105
+ for (const plugin of vueConfig.plugins) {
106
+ this._vueApp.use(plugin);
107
+ }
108
+ }
109
+ this._vueApp.provide(PROPS_PROVIDER, this._propsRef);
110
+ this._vueApp.provide(PROPS_ERROR_PROVIDER, this._errorsRef);
111
+ this._vueApp.provide(EVENT_PROVIDER, this.emitEvent.bind(this));
112
+ this._vueApp.provide(CONTENT_PROVIDER, this._contentRef);
113
+ this._vueApp.provide(PANEL_ID_PROVIDER, getWippyPanelId(this));
114
+ this._vueApp.provide(LAYOUT_BUS_PROVIDER, getWippyHostBus(this));
115
+ this._vueApp.provide(HOST_PROVIDER, getWippyHost(this));
116
+ if (vueConfig.providers) {
117
+ vueConfig.providers(this._vueApp, this);
118
+ }
119
+ this._vueApp.mount(container);
120
+ if (hostPinia)
121
+ setActivePinia(hostPinia);
122
+ }
123
+ onUnmount() {
124
+ this._bridgeAbort?.abort();
125
+ this._bridgeAbort = null;
126
+ if (this._vueApp) {
127
+ this._vueApp.unmount();
128
+ this._vueApp = null;
129
+ }
130
+ }
131
+ };
132
+
133
+ // src/index.ts
134
+ import { define, WippyElement as WippyElement2 } from "@wippy-fe/webcomponent-core";
135
+ export {
136
+ CONTENT_PROVIDER,
137
+ EVENT_PROVIDER,
138
+ HOST_PROVIDER,
139
+ LAYOUT_BUS_PROVIDER,
140
+ PANEL_ID_PROVIDER,
141
+ PROPS_ERROR_PROVIDER,
142
+ PROPS_PROVIDER,
143
+ WippyElement2 as WippyElement,
144
+ WippyVueElement,
145
+ createProviders,
146
+ define,
147
+ useContent,
148
+ useEvents,
149
+ useHost,
150
+ useLayoutBus,
151
+ usePanelId,
152
+ useProps,
153
+ usePropsErrors
154
+ };
155
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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 } from 'vue'\r\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>\r\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 {\r\n return inject(HOST_PROVIDER, null) as H | null\r\n}\r\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, LAYOUT_BUS_PROVIDER, PANEL_ID_PROVIDER, PROPS_ERROR_PROVIDER, PROPS_PROVIDER } from './providers.ts'\r\n\r\n/**\r\n * Vue-specific configuration returned by `static get vueConfig()`.\r\n */\r\nexport interface WippyVueElementConfig {\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 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)\r\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\r\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 this._bridgeAbort = new AbortController()\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: this._bridgeAbort.signal })\r\n\r\n if (this.reactive.content) {\r\n this.reactive.content.subscribe((content) => {\r\n this._contentRef.value = content\r\n }, { signal: this._bridgeAbort.signal })\r\n }\r\n\r\n // 2. Create Vue app + Pinia\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 this._vueApp = createApp(vueConfig.rootComponent)\r\n const pinia = createPinia()\r\n if (vueConfig.piniaPlugins) {\r\n for (const plugin of vueConfig.piniaPlugins)\r\n pinia.use(plugin)\r\n }\r\n this._vueApp.use(pinia)\r\n\r\n // 3. Install extra plugins\r\n if (vueConfig.plugins) {\r\n for (const plugin of vueConfig.plugins) {\r\n this._vueApp.use(plugin)\r\n }\r\n }\r\n\r\n // 4. Provide standard injection keys\r\n this._vueApp.provide(PROPS_PROVIDER, this._propsRef as Ref<Record<string, unknown>>)\r\n this._vueApp.provide(PROPS_ERROR_PROVIDER, this._errorsRef)\r\n this._vueApp.provide(EVENT_PROVIDER, this.emitEvent.bind(this))\r\n this._vueApp.provide(CONTENT_PROVIDER, this._contentRef)\r\n\r\n // 4b. Managed-layout integration. The `ComponentResolver` (host\r\n // side) sets `dataset.wippyPanelId` and `__wippyHostBus` on this\r\n // element BEFORE insertion, so they're available now in\r\n // `connectedCallback`. Outside a managed-layout host both are\r\n // null — composables tolerate the null path.\r\n this._vueApp.provide(PANEL_ID_PROVIDER, getWippyPanelId(this))\r\n this._vueApp.provide(LAYOUT_BUS_PROVIDER, getWippyHostBus(this))\r\n this._vueApp.provide(HOST_PROVIDER, getWippyHost(this))\r\n\r\n // 5. Custom providers\r\n if (vueConfig.providers) {\r\n vueConfig.providers(this._vueApp, this)\r\n }\r\n\r\n // 6. Mount\r\n this._vueApp.mount(container)\r\n\r\n // 7. Restore the host's activePinia — prevents this web component's\r\n // Pinia from being used by unrelated code that calls useStore()\r\n // outside of a component setup context (e.g. axios interceptors).\r\n if (hostPinia)\r\n setActivePinia(hostPinia)\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,\r\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,\r\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 } 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,\r\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":"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","names":["WippyElement"]}
package/package.json CHANGED
@@ -1,23 +1,35 @@
1
1
  {
2
2
  "name": "@wippy-fe/webcomponent-vue",
3
- "version": "0.0.32",
4
- "description": "Vue 3 integration layer for Wippy web components — extends @wippy-fe/webcomponent-core with reactive props, Pinia, and provider injection.",
3
+ "version": "0.0.35",
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
- "main": "src/index.ts",
7
- "types": "src/index.ts",
6
+ "license": "UNLICENSED",
7
+ "sideEffects": false,
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ },
16
+ "./package.json": "./package.json"
17
+ },
8
18
  "files": [
9
- "src/",
10
- "package.json"
19
+ "package.json",
20
+ "dist/"
11
21
  ],
12
22
  "dependencies": {
13
- "@wippy-fe/webcomponent-core": "0.0.32"
23
+ "@wippy-fe/webcomponent-core": "^0.0.35"
14
24
  },
15
25
  "peerDependencies": {
16
26
  "@iconify/vue": "^5.0.0",
17
27
  "pinia": "^2.1.0",
18
28
  "vue": "^3.5.0",
19
- "@wippy-fe/proxy": "0.0.32",
20
- "@wippy-fe/shared": "0.0.32"
29
+ "@wippy-fe/shared": "^0.0.35",
30
+ "@wippy-fe/proxy": "^0.0.35"
21
31
  },
22
- "license": "UNLICENSED"
32
+ "scripts": {
33
+ "build": "tsup"
34
+ }
23
35
  }
package/src/index.ts DELETED
@@ -1,42 +0,0 @@
1
- // Providers: base symbols, composables, and createProviders utility
2
- export {
3
- CONTENT_PROVIDER,
4
- createProviders,
5
- EVENT_PROVIDER,
6
- HOST_PROVIDER,
7
- LAYOUT_BUS_PROVIDER,
8
- PANEL_ID_PROVIDER,
9
- PROPS_ERROR_PROVIDER,
10
- PROPS_PROVIDER,
11
- useContent,
12
- useEvents,
13
- useHost,
14
- useLayoutBus,
15
- usePanelId,
16
- useProps,
17
- usePropsErrors,
18
- } from './providers.ts'
19
- export type { TypedProviders } from './providers.ts'
20
-
21
- // Vue layer
22
- export { WippyVueElement } from './vue-element.ts'
23
- export type { WippyVueElementConfig } from './vue-element.ts'
24
-
25
- // Re-export core for convenience
26
- export { define, WippyElement } from '@wippy-fe/webcomponent-core'
27
- export type {
28
- BroadcastEnvelope,
29
- ContentListener,
30
- ContentSubscription,
31
- EventEmitterHandle,
32
- HostCssKey,
33
- LayoutBusBound,
34
- ParseResult,
35
- PropsListener,
36
- PropsSubscription,
37
- ReactiveAdapter,
38
- SubscribeOptions,
39
- WippyElementConfig,
40
- WippyPropDefinition,
41
- WippyPropsSchema,
42
- } from '@wippy-fe/webcomponent-core'
@@ -1,85 +0,0 @@
1
- /**
2
- * @vitest-environment jsdom
3
- *
4
- * Covers `useHost()` Vue composable — injects HOST_PROVIDER, returns
5
- * `null` outside a managed-layout host so callers can fall back to
6
- * the global `host` import explicitly.
7
- */
8
- import { describe, expect, it } from 'vitest'
9
- import { createApp, defineComponent, h } from 'vue'
10
- import { HOST_PROVIDER, useHost } from './providers.ts'
11
-
12
- function mount(rootComponent: ReturnType<typeof defineComponent>) {
13
- const container = document.createElement('div')
14
- document.body.appendChild(container)
15
- const app = createApp(rootComponent)
16
- app.mount(container)
17
- return { app, container, unmount: () => {
18
- app.unmount()
19
- container.remove()
20
- } }
21
- }
22
-
23
- describe('useHost', () => {
24
- it('returns null outside a managed-layout host (no provider)', () => {
25
- let observed: unknown = 'sentinel'
26
- const Probe = defineComponent({
27
- setup() {
28
- observed = useHost()
29
- return () => h('div')
30
- },
31
- })
32
- const { unmount } = mount(Probe)
33
- expect(observed).toBeNull()
34
- unmount()
35
- })
36
-
37
- it('returns the panel-scoped wrapper when HOST_PROVIDER is provided', () => {
38
- let observed: unknown = 'sentinel'
39
- const fakeWrapper = { layout: { broadcast: () => {}, send: () => {}, on: () => () => {} } }
40
- const Probe = defineComponent({
41
- setup() {
42
- observed = useHost()
43
- return () => h('div')
44
- },
45
- })
46
- const Parent = defineComponent({
47
- setup() {
48
- return () => h(Probe)
49
- },
50
- })
51
- const container = document.createElement('div')
52
- document.body.appendChild(container)
53
- const app = createApp(Parent)
54
- // Identity check: prove `useHost()` reads from the EXACT
55
- // HOST_PROVIDER key. A composable that injected from a wrong key
56
- // would still return undefined → null, falsely passing the
57
- // "returns null" test, so this is the only place the key
58
- // contract is actually verified.
59
- app.provide(HOST_PROVIDER, fakeWrapper)
60
- app.mount(container)
61
- expect(observed).toBe(fakeWrapper)
62
- app.unmount()
63
- container.remove()
64
- })
65
-
66
- it('does NOT read from a different injection key', () => {
67
- let observed: unknown = 'sentinel'
68
- const fakeWrapper = { layout: {} }
69
- const wrongKey = Symbol('wrong-key')
70
- const Probe = defineComponent({
71
- setup() {
72
- observed = useHost()
73
- return () => h('div')
74
- },
75
- })
76
- const container = document.createElement('div')
77
- document.body.appendChild(container)
78
- const app = createApp(Probe)
79
- app.provide(wrongKey, fakeWrapper) // NOT HOST_PROVIDER
80
- app.mount(container)
81
- expect(observed).toBeNull()
82
- app.unmount()
83
- container.remove()
84
- })
85
- })
@@ -1,172 +0,0 @@
1
- import type { PiniaPlugin } from 'pinia'
2
- import type { App, Component, Ref } from 'vue'
3
- import { getWippyHost, getWippyHostBus, getWippyPanelId, WippyElement } from '@wippy-fe/webcomponent-core'
4
- import { createPinia, getActivePinia, setActivePinia } from 'pinia'
5
- import { createApp, ref } from 'vue'
6
- import { CONTENT_PROVIDER, EVENT_PROVIDER, HOST_PROVIDER, LAYOUT_BUS_PROVIDER, PANEL_ID_PROVIDER, PROPS_ERROR_PROVIDER, PROPS_PROVIDER } from './providers.ts'
7
-
8
- /**
9
- * Vue-specific configuration returned by `static get vueConfig()`.
10
- */
11
- export interface WippyVueElementConfig {
12
- /** The root Vue component to mount. */
13
- rootComponent: Component
14
- /** Additional Vue plugins to install (beyond Pinia which is always installed). */
15
- plugins?: Array<{ install: (app: App) => void }>
16
- /** Pinia plugins to install (e.g., createWippyPersist()). */
17
- piniaPlugins?: PiniaPlugin[]
18
- /** Extra providers to inject into the Vue app. */
19
- providers?: (app: App, element: WippyVueElement<any, any>) => void
20
- }
21
-
22
- /**
23
- * Vue 3 integration for Wippy web components.
24
- *
25
- * Generic over `Props` (parsed prop object type) and `Events` (event map).
26
- * These flow through to typed hooks, reactive refs, and composable helpers.
27
- *
28
- * Usage:
29
- * ```ts
30
- * class MyElement extends WippyVueElement<MyProps, MyEvents> {
31
- * static get wippyConfig(): WippyElementConfig<MyProps> {
32
- * return { propsSchema: pkg.wippy.props, inlineCss: stylesText }
33
- * }
34
- * static get vueConfig() {
35
- * return { rootComponent: MyApp }
36
- * }
37
- * }
38
- * ```
39
- *
40
- * In Vue components, use the typed composable helpers:
41
- * ```ts
42
- * const props = useProps<MyProps>()
43
- * const emit = useEvents<MyEvents>()
44
- * const errors = usePropsErrors()
45
- * ```
46
- */
47
- export abstract class WippyVueElement<
48
- Props = Record<string, unknown>,
49
- Events = Record<string, unknown>,
50
- > extends WippyElement<Props, Events> {
51
- private _vueApp: App<Element> | null = null
52
- private _propsRef: Ref<Props> = ref({}) as Ref<Props>
53
- private _errorsRef: Ref<string[]> = ref([])
54
- private _contentRef: Ref<string | null> = ref(null)
55
- /** Cleanup handle for the core-adapter → Vue-ref bridge subscription. */
56
- private _bridgeAbort: AbortController | null = null
57
-
58
- /**
59
- * Override to provide Vue-specific configuration.
60
- */
61
- static get vueConfig(): WippyVueElementConfig {
62
- throw new Error('WippyVueElement subclass must override static get vueConfig()')
63
- }
64
-
65
- protected onMount(
66
- _shadow: ShadowRoot,
67
- container: HTMLElement,
68
- initialProps: Props,
69
- initialErrors: string[],
70
- initialContent?: string | null,
71
- _isRemount?: boolean,
72
- ): void {
73
- // On reconnect (`_isRemount === true`) the previous Vue app was
74
- // already torn down by `onUnmount`, which calls `_vueApp.unmount()`
75
- // and detaches Vue's rendered DOM from the reused container. So we
76
- // can construct a fresh Vue app here — no special-case branch needed.
77
- // If the container ever holds residual children, Vue's mount will
78
- // replace them.
79
- const vueConfig = (this.constructor as typeof WippyVueElement).vueConfig
80
-
81
- // 1. Seed reactive refs from initial state, then bridge to the core
82
- // reactive adapter so subsequent attribute / content changes
83
- // propagate without manual ref writes in `onPropsChanged` /
84
- // `onContentChanged`. The core adapter is the single source of
85
- // truth; the Vue refs are a read-only mirror that consumers reach
86
- // via `useProps()` / `useContent()` / `usePropsErrors()`.
87
- this._propsRef.value = initialProps
88
- this._errorsRef.value = initialErrors
89
- this._contentRef.value = initialContent ?? null
90
-
91
- // Emit initial errors as invalid events
92
- for (const error of initialErrors) {
93
- this.emitEvent('invalid', { message: error })
94
- }
95
-
96
- this._bridgeAbort = new AbortController()
97
- this.reactive.props.subscribe((props, errors) => {
98
- this._propsRef.value = props
99
- this._errorsRef.value = [...errors]
100
- for (const error of errors) {
101
- this.emitEvent('invalid', { message: error })
102
- }
103
- }, { signal: this._bridgeAbort.signal })
104
-
105
- if (this.reactive.content) {
106
- this.reactive.content.subscribe((content) => {
107
- this._contentRef.value = content
108
- }, { signal: this._bridgeAbort.signal })
109
- }
110
-
111
- // 2. Create Vue app + Pinia
112
- // Save and restore the host's activePinia so this web component's
113
- // isolated Pinia instance doesn't contaminate the global scope.
114
- // See: https://pinia.vuejs.org/core-concepts/outside-component-usage
115
- const hostPinia = getActivePinia()
116
-
117
- this._vueApp = createApp(vueConfig.rootComponent)
118
- const pinia = createPinia()
119
- if (vueConfig.piniaPlugins) {
120
- for (const plugin of vueConfig.piniaPlugins)
121
- pinia.use(plugin)
122
- }
123
- this._vueApp.use(pinia)
124
-
125
- // 3. Install extra plugins
126
- if (vueConfig.plugins) {
127
- for (const plugin of vueConfig.plugins) {
128
- this._vueApp.use(plugin)
129
- }
130
- }
131
-
132
- // 4. Provide standard injection keys
133
- this._vueApp.provide(PROPS_PROVIDER, this._propsRef as Ref<Record<string, unknown>>)
134
- this._vueApp.provide(PROPS_ERROR_PROVIDER, this._errorsRef)
135
- this._vueApp.provide(EVENT_PROVIDER, this.emitEvent.bind(this))
136
- this._vueApp.provide(CONTENT_PROVIDER, this._contentRef)
137
-
138
- // 4b. Managed-layout integration. The `ComponentResolver` (host
139
- // side) sets `dataset.wippyPanelId` and `__wippyHostBus` on this
140
- // element BEFORE insertion, so they're available now in
141
- // `connectedCallback`. Outside a managed-layout host both are
142
- // null — composables tolerate the null path.
143
- this._vueApp.provide(PANEL_ID_PROVIDER, getWippyPanelId(this))
144
- this._vueApp.provide(LAYOUT_BUS_PROVIDER, getWippyHostBus(this))
145
- this._vueApp.provide(HOST_PROVIDER, getWippyHost(this))
146
-
147
- // 5. Custom providers
148
- if (vueConfig.providers) {
149
- vueConfig.providers(this._vueApp, this)
150
- }
151
-
152
- // 6. Mount
153
- this._vueApp.mount(container)
154
-
155
- // 7. Restore the host's activePinia — prevents this web component's
156
- // Pinia from being used by unrelated code that calls useStore()
157
- // outside of a component setup context (e.g. axios interceptors).
158
- if (hostPinia)
159
- setActivePinia(hostPinia)
160
- }
161
-
162
- protected onUnmount(): void {
163
- // Tear down the core-adapter bridge BEFORE unmounting Vue, so the
164
- // Vue refs can't be mutated mid-teardown by a stray late notify.
165
- this._bridgeAbort?.abort()
166
- this._bridgeAbort = null
167
- if (this._vueApp) {
168
- this._vueApp.unmount()
169
- this._vueApp = null
170
- }
171
- }
172
- }