@wippy-fe/webcomponent-vue 0.0.68 → 0.0.70
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/README.md +18 -0
- package/dist/index.d.ts +103 -78
- package/dist/index.js +208 -47
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/starter/README.md +15 -0
- package/starter/package.json +22 -0
- package/starter/src/index.js +25 -0
- package/starter/src/page.js +5 -0
- package/starter/vite.config.mjs +25 -0
package/README.md
CHANGED
|
@@ -49,6 +49,24 @@ export async function webComponent() {
|
|
|
49
49
|
define(import.meta.url, MyElement)
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
## Lazy components
|
|
53
|
+
|
|
54
|
+
Copy the [starter](./starter) to create a page. Use `lazyVueConfig` with
|
|
55
|
+
`surface: 'page'` or `surface: 'compact'` and an importer that resolves a
|
|
56
|
+
mount configuration with the real root. Keep data loading and errors
|
|
57
|
+
inside the component. The helper handles import failure and emits
|
|
58
|
+
`error` with `{ message, error }`.
|
|
59
|
+
|
|
60
|
+
An opted-in element emits `wippy-mounted` directly after its real root
|
|
61
|
+
mounts. Attach a listener before insertion. `wippyMountState` is
|
|
62
|
+
`idle`, `mounting`, `mounted`, or `failed` and is updated before the
|
|
63
|
+
event. Existing configurations retain their lifecycle. An eager root may
|
|
64
|
+
opt in with `mountLifecycle: true` when its initial render is synchronous.
|
|
65
|
+
|
|
66
|
+
`preloadImplementation()` can start the import without constructing an
|
|
67
|
+
element. It returns a promise. Handle rejection when calling it. The
|
|
68
|
+
class shares a successful import with instances and can retry a failed one.
|
|
69
|
+
|
|
52
70
|
## API Reference
|
|
53
71
|
|
|
54
72
|
### `WippyVueElement` (abstract class)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,106 @@
|
|
|
1
|
-
import { LayoutBusBound, WippyElement } from '@wippy-fe/webcomponent-core';
|
|
2
|
-
export { BroadcastEnvelope, ContentListener, ContentSubscription, EventEmitterHandle, HostCssKey, HostVisibilityListener, HostVisibilitySubscription, 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
1
|
import { PiniaPlugin } from 'pinia';
|
|
2
|
+
import { Component, App, InjectionKey, Ref } from 'vue';
|
|
3
|
+
import { WippyElement, LayoutBusBound } from '@wippy-fe/webcomponent-core';
|
|
4
|
+
export { BroadcastEnvelope, ContentListener, ContentSubscription, EventEmitterHandle, HostCssKey, HostVisibilityListener, HostVisibilitySubscription, LayoutBusBound, ParseResult, PropsListener, PropsSubscription, ReactiveAdapter, SubscribeOptions, WippyElement, WippyElementConfig, WippyPropDefinition, WippyPropsSchema, define } from '@wippy-fe/webcomponent-core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The heavy half of a Vue element's config — the root component, its plugins,
|
|
8
|
+
* and providers. Either supplied eagerly on `WippyVueElementConfig` or returned
|
|
9
|
+
* by `lazyConfig()` from a dynamically-imported chunk (so the element shell can
|
|
10
|
+
* stay tiny and load the framework + component tree on first connect).
|
|
11
|
+
*/
|
|
12
|
+
interface WippyVueMountConfig {
|
|
13
|
+
/** The root Vue component to mount. */
|
|
14
|
+
rootComponent: Component;
|
|
15
|
+
/** Additional Vue plugins to install (beyond Pinia which is always installed). */
|
|
16
|
+
plugins?: Array<{
|
|
17
|
+
install: (app: App) => void;
|
|
18
|
+
}>;
|
|
19
|
+
/** Pinia plugins to install (e.g., createWippyPersist()). */
|
|
20
|
+
piniaPlugins?: PiniaPlugin[];
|
|
21
|
+
/** Extra providers to inject into the Vue app. */
|
|
22
|
+
providers?: (app: App, element: WippyVueElement<any, any>) => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Vue-specific configuration returned by `static get vueConfig()`.
|
|
26
|
+
*
|
|
27
|
+
* Provide EITHER an eager `rootComponent` (+ optional plugins/providers) for a
|
|
28
|
+
* normal element, OR `lazyConfig` for a thin shell that defers the heavy parts:
|
|
29
|
+
* when `lazyConfig` is set and `rootComponent` is omitted, `onMount` shows a
|
|
30
|
+
* `<wippy-loading>` placeholder, awaits `lazyConfig()` (typically `() =>
|
|
31
|
+
* import('./internals').then(m => ({ rootComponent: m.Root, providers: m.boot }))`),
|
|
32
|
+
* then mounts. The props/events bridge + lifecycle stay here, so the lazily
|
|
33
|
+
* imported chunk only carries the framework + component tree.
|
|
34
|
+
*/
|
|
35
|
+
interface WippyVueElementConfig extends Partial<WippyVueMountConfig> {
|
|
36
|
+
/** Lazily resolve the mount config (root + plugins + providers) on first connect. */
|
|
37
|
+
lazyConfig?: () => Promise<WippyVueMountConfig>;
|
|
38
|
+
/** Opt in when the eager root renders synchronously or lazyConfig resolves the real root. */
|
|
39
|
+
mountLifecycle?: true;
|
|
40
|
+
lazyUi?: WippyVueLazyOptions;
|
|
41
|
+
}
|
|
42
|
+
type WippyMountState = 'idle' | 'mounting' | 'mounted' | 'failed';
|
|
43
|
+
/**
|
|
44
|
+
* Vue 3 integration for Wippy web components.
|
|
45
|
+
*
|
|
46
|
+
* Generic over `Props` (parsed prop object type) and `Events` (event map).
|
|
47
|
+
* These flow through to typed hooks, reactive refs, and composable helpers.
|
|
48
|
+
*
|
|
49
|
+
* Usage:
|
|
50
|
+
* ```ts
|
|
51
|
+
* class MyElement extends WippyVueElement<MyProps, MyEvents> {
|
|
52
|
+
* static get wippyConfig(): WippyElementConfig<MyProps> {
|
|
53
|
+
* return { propsSchema: pkg.wippy.props, inlineCss: stylesText }
|
|
54
|
+
* }
|
|
55
|
+
* static get vueConfig() {
|
|
56
|
+
* return { rootComponent: MyApp }
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* In Vue components, use the typed composable helpers:
|
|
62
|
+
* ```ts
|
|
63
|
+
* const props = useProps<MyProps>()
|
|
64
|
+
* const emit = useEvents<MyEvents>()
|
|
65
|
+
* const errors = usePropsErrors()
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
declare abstract class WippyVueElement<Props = Record<string, unknown>, Events = Record<string, unknown>> extends WippyElement<Props, Events> {
|
|
69
|
+
private _vueApp;
|
|
70
|
+
private _mountingApp;
|
|
71
|
+
private _mountState;
|
|
72
|
+
private _feedback;
|
|
73
|
+
private _propsRef;
|
|
74
|
+
private _errorsRef;
|
|
75
|
+
private _contentRef;
|
|
76
|
+
private _hostVisibilityRef;
|
|
77
|
+
/** Cleanup handle for the core-adapter → Vue-ref bridge subscription. */
|
|
78
|
+
private _bridgeAbort;
|
|
79
|
+
/**
|
|
80
|
+
* Override to provide Vue-specific configuration.
|
|
81
|
+
*/
|
|
82
|
+
static get vueConfig(): WippyVueElementConfig;
|
|
83
|
+
/** Prepare the implementation without creating a Vue or Pinia instance. */
|
|
84
|
+
static preloadImplementation(): Promise<void>;
|
|
85
|
+
/** Undefined on configurations that use only the legacy load event. */
|
|
86
|
+
get wippyMountState(): WippyMountState | undefined;
|
|
87
|
+
protected onMount(_shadow: ShadowRoot, container: HTMLElement, initialProps: Props, initialErrors: string[], initialContent?: string | null, _isRemount?: boolean): void;
|
|
88
|
+
protected onUnmount(): void;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface WippyVueLazyOptions {
|
|
92
|
+
surface: 'page' | 'compact';
|
|
93
|
+
loading: string;
|
|
94
|
+
failed: string;
|
|
95
|
+
/** Milliseconds before showing a compact spinner. */
|
|
96
|
+
delay?: number;
|
|
97
|
+
/** Milliseconds each attachment waits for the implementation. */
|
|
98
|
+
timeout?: number;
|
|
99
|
+
/** Compact errors use an icon and an accessible label. */
|
|
100
|
+
iconOnly?: boolean;
|
|
101
|
+
}
|
|
102
|
+
/** The importer should only load code and configuration. Vue mounts on attachment. */
|
|
103
|
+
declare function lazyVueConfig(load: () => Promise<WippyVueMountConfig>, options: WippyVueLazyOptions): WippyVueElementConfig;
|
|
5
104
|
|
|
6
105
|
/** Injection key for the event emitter function. */
|
|
7
106
|
declare const EVENT_PROVIDER: InjectionKey<(event: string, detail?: unknown) => void>;
|
|
@@ -169,78 +268,4 @@ interface TypedProviders<Props, Events> {
|
|
|
169
268
|
*/
|
|
170
269
|
declare function createProviders<Props, Events = Record<string, unknown>>(): TypedProviders<Props, Events>;
|
|
171
270
|
|
|
172
|
-
|
|
173
|
-
* The heavy half of a Vue element's config — the root component, its plugins,
|
|
174
|
-
* and providers. Either supplied eagerly on `WippyVueElementConfig` or returned
|
|
175
|
-
* by `lazyConfig()` from a dynamically-imported chunk (so the element shell can
|
|
176
|
-
* stay tiny and load the framework + component tree on first connect).
|
|
177
|
-
*/
|
|
178
|
-
interface WippyVueMountConfig {
|
|
179
|
-
/** The root Vue component to mount. */
|
|
180
|
-
rootComponent: Component;
|
|
181
|
-
/** Additional Vue plugins to install (beyond Pinia which is always installed). */
|
|
182
|
-
plugins?: Array<{
|
|
183
|
-
install: (app: App) => void;
|
|
184
|
-
}>;
|
|
185
|
-
/** Pinia plugins to install (e.g., createWippyPersist()). */
|
|
186
|
-
piniaPlugins?: PiniaPlugin[];
|
|
187
|
-
/** Extra providers to inject into the Vue app. */
|
|
188
|
-
providers?: (app: App, element: WippyVueElement<any, any>) => void;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Vue-specific configuration returned by `static get vueConfig()`.
|
|
192
|
-
*
|
|
193
|
-
* Provide EITHER an eager `rootComponent` (+ optional plugins/providers) for a
|
|
194
|
-
* normal element, OR `lazyConfig` for a thin shell that defers the heavy parts:
|
|
195
|
-
* when `lazyConfig` is set and `rootComponent` is omitted, `onMount` shows a
|
|
196
|
-
* `<wippy-loading>` placeholder, awaits `lazyConfig()` (typically `() =>
|
|
197
|
-
* import('./internals').then(m => ({ rootComponent: m.Root, providers: m.boot }))`),
|
|
198
|
-
* then mounts. The props/events bridge + lifecycle stay here, so the lazily
|
|
199
|
-
* imported chunk only carries the framework + component tree.
|
|
200
|
-
*/
|
|
201
|
-
interface WippyVueElementConfig extends Partial<WippyVueMountConfig> {
|
|
202
|
-
/** Lazily resolve the mount config (root + plugins + providers) on first connect. */
|
|
203
|
-
lazyConfig?: () => Promise<WippyVueMountConfig>;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Vue 3 integration for Wippy web components.
|
|
207
|
-
*
|
|
208
|
-
* Generic over `Props` (parsed prop object type) and `Events` (event map).
|
|
209
|
-
* These flow through to typed hooks, reactive refs, and composable helpers.
|
|
210
|
-
*
|
|
211
|
-
* Usage:
|
|
212
|
-
* ```ts
|
|
213
|
-
* class MyElement extends WippyVueElement<MyProps, MyEvents> {
|
|
214
|
-
* static get wippyConfig(): WippyElementConfig<MyProps> {
|
|
215
|
-
* return { propsSchema: pkg.wippy.props, inlineCss: stylesText }
|
|
216
|
-
* }
|
|
217
|
-
* static get vueConfig() {
|
|
218
|
-
* return { rootComponent: MyApp }
|
|
219
|
-
* }
|
|
220
|
-
* }
|
|
221
|
-
* ```
|
|
222
|
-
*
|
|
223
|
-
* In Vue components, use the typed composable helpers:
|
|
224
|
-
* ```ts
|
|
225
|
-
* const props = useProps<MyProps>()
|
|
226
|
-
* const emit = useEvents<MyEvents>()
|
|
227
|
-
* const errors = usePropsErrors()
|
|
228
|
-
* ```
|
|
229
|
-
*/
|
|
230
|
-
declare abstract class WippyVueElement<Props = Record<string, unknown>, Events = Record<string, unknown>> extends WippyElement<Props, Events> {
|
|
231
|
-
private _vueApp;
|
|
232
|
-
private _propsRef;
|
|
233
|
-
private _errorsRef;
|
|
234
|
-
private _contentRef;
|
|
235
|
-
private _hostVisibilityRef;
|
|
236
|
-
/** Cleanup handle for the core-adapter → Vue-ref bridge subscription. */
|
|
237
|
-
private _bridgeAbort;
|
|
238
|
-
/**
|
|
239
|
-
* Override to provide Vue-specific configuration.
|
|
240
|
-
*/
|
|
241
|
-
static get vueConfig(): WippyVueElementConfig;
|
|
242
|
-
protected onMount(_shadow: ShadowRoot, container: HTMLElement, initialProps: Props, initialErrors: string[], initialContent?: string | null, _isRemount?: boolean): void;
|
|
243
|
-
protected onUnmount(): void;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export { CONTENT_PROVIDER, EVENT_PROVIDER, HOST_PROVIDER, HOST_VISIBILITY_PROVIDER, LAYOUT_BUS_PROVIDER, PANEL_ID_PROVIDER, PROPS_ERROR_PROVIDER, PROPS_PROVIDER, type TypedProviders, WippyVueElement, type WippyVueElementConfig, type WippyVueMountConfig, createProviders, useContent, useEvents, useHost, useHostVisibility, useHostVisibilityRefresh, useLayoutBus, usePanelId, useProps, usePropsErrors };
|
|
271
|
+
export { CONTENT_PROVIDER, EVENT_PROVIDER, HOST_PROVIDER, HOST_VISIBILITY_PROVIDER, LAYOUT_BUS_PROVIDER, PANEL_ID_PROVIDER, PROPS_ERROR_PROVIDER, PROPS_PROVIDER, type TypedProviders, type WippyMountState, WippyVueElement, type WippyVueElementConfig, type WippyVueLazyOptions, type WippyVueMountConfig, createProviders, lazyVueConfig, useContent, useEvents, useHost, useHostVisibility, useHostVisibilityRefresh, useLayoutBus, usePanelId, useProps, usePropsErrors };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,37 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
|
|
5
|
+
// src/lazy.ts
|
|
6
|
+
function lazyVueConfig(load, options) {
|
|
7
|
+
return { lazyConfig: load, mountLifecycle: true, lazyUi: options };
|
|
8
|
+
}
|
|
9
|
+
function lazyFeedback(document, options, failed) {
|
|
10
|
+
const el = document.createElement("div");
|
|
11
|
+
const label = failed ? options.failed : options.loading;
|
|
12
|
+
el.dataset.lazyState = failed ? "failed" : "loading";
|
|
13
|
+
el.setAttribute("role", failed ? "alert" : "status");
|
|
14
|
+
el.setAttribute("aria-label", label);
|
|
15
|
+
el.style.cssText = "display:grid;place-items:center;text-align:center;";
|
|
16
|
+
const page = options.surface === "page";
|
|
17
|
+
el.style.cssText += page ? "block-size:100%;min-block-size:0;" : "min-block-size:2rem;font-size:.875rem;";
|
|
18
|
+
if (failed) {
|
|
19
|
+
el.style.color = "var(--p-danger-500, currentColor)";
|
|
20
|
+
el.textContent = !page && options.iconOnly ? "\u26A0" : label;
|
|
21
|
+
if (!page && options.iconOnly)
|
|
22
|
+
el.title = label;
|
|
23
|
+
} else {
|
|
24
|
+
const style = document.createElement("style");
|
|
25
|
+
style.textContent = '@media (prefers-reduced-motion: no-preference) { [data-lazy-state="loading"] > [data-wippy-spinner] { animation: wippy-lazy-spin 1s linear infinite; } } @keyframes wippy-lazy-spin { to { transform: rotate(1turn); } }';
|
|
26
|
+
const spinner = document.createElement("span");
|
|
27
|
+
spinner.dataset.wippySpinner = "";
|
|
28
|
+
spinner.setAttribute("aria-hidden", "true");
|
|
29
|
+
spinner.style.cssText = "display:block;box-sizing:border-box;inline-size:1em;block-size:1em;border:2px solid var(--p-surface-300, currentColor);border-top-color:var(--p-primary-color, currentColor);border-radius:50%;";
|
|
30
|
+
spinner.style.fontSize = page ? "2rem" : "1em";
|
|
31
|
+
el.append(style, spinner);
|
|
32
|
+
}
|
|
33
|
+
return el;
|
|
34
|
+
}
|
|
35
|
+
|
|
5
36
|
// src/providers.ts
|
|
6
37
|
import { inject, onMounted, onUnmounted, watch } from "vue";
|
|
7
38
|
var EVENT_PROVIDER = /* @__PURE__ */ Symbol("wippy:emit");
|
|
@@ -105,10 +136,26 @@ function createProviders() {
|
|
|
105
136
|
import { getWippyHost, getWippyHostBus, getWippyPanelId, WippyElement } from "@wippy-fe/webcomponent-core";
|
|
106
137
|
import { createPinia, getActivePinia, setActivePinia } from "pinia";
|
|
107
138
|
import { createApp, ref } from "vue";
|
|
139
|
+
var implementations = /* @__PURE__ */ new WeakMap();
|
|
140
|
+
function loadImplementation(ctor, load) {
|
|
141
|
+
const pending = implementations.get(ctor);
|
|
142
|
+
if (pending)
|
|
143
|
+
return pending;
|
|
144
|
+
const attempt = Promise.resolve().then(load);
|
|
145
|
+
implementations.set(ctor, attempt);
|
|
146
|
+
void attempt.catch(() => {
|
|
147
|
+
if (implementations.get(ctor) === attempt)
|
|
148
|
+
implementations.delete(ctor);
|
|
149
|
+
});
|
|
150
|
+
return attempt;
|
|
151
|
+
}
|
|
108
152
|
var WippyVueElement = class extends WippyElement {
|
|
109
153
|
constructor() {
|
|
110
154
|
super(...arguments);
|
|
111
155
|
__publicField(this, "_vueApp", null);
|
|
156
|
+
__publicField(this, "_mountingApp", false);
|
|
157
|
+
__publicField(this, "_mountState", "idle");
|
|
158
|
+
__publicField(this, "_feedback", null);
|
|
112
159
|
__publicField(this, "_propsRef", ref({}));
|
|
113
160
|
__publicField(this, "_errorsRef", ref([]));
|
|
114
161
|
__publicField(this, "_contentRef", ref(null));
|
|
@@ -122,17 +169,32 @@ var WippyVueElement = class extends WippyElement {
|
|
|
122
169
|
static get vueConfig() {
|
|
123
170
|
throw new Error("WippyVueElement subclass must override static get vueConfig()");
|
|
124
171
|
}
|
|
172
|
+
/** Prepare the implementation without creating a Vue or Pinia instance. */
|
|
173
|
+
static async preloadImplementation() {
|
|
174
|
+
const config = this.vueConfig;
|
|
175
|
+
if (config.mountLifecycle && !config.rootComponent && config.lazyConfig)
|
|
176
|
+
await loadImplementation(this, config.lazyConfig);
|
|
177
|
+
}
|
|
178
|
+
/** Undefined on configurations that use only the legacy load event. */
|
|
179
|
+
get wippyMountState() {
|
|
180
|
+
return this.constructor.vueConfig.mountLifecycle ? this._mountState : void 0;
|
|
181
|
+
}
|
|
125
182
|
onMount(_shadow, container, initialProps, initialErrors, initialContent, _isRemount) {
|
|
126
|
-
const
|
|
183
|
+
const ctor = this.constructor;
|
|
184
|
+
const vueConfig = ctor.vueConfig;
|
|
185
|
+
const bridgeAbort = new AbortController();
|
|
186
|
+
this._bridgeAbort = bridgeAbort;
|
|
187
|
+
const isCurrent = () => !bridgeAbort.signal.aborted && this._bridgeAbort === bridgeAbort;
|
|
188
|
+
this._mountState = "mounting";
|
|
127
189
|
this._propsRef.value = initialProps;
|
|
128
190
|
this._errorsRef.value = initialErrors;
|
|
129
191
|
this._contentRef.value = initialContent ?? null;
|
|
130
192
|
this._hostVisibilityRef.value = this.hostVisible;
|
|
131
193
|
for (const error of initialErrors) {
|
|
132
194
|
this.emitEvent("invalid", { message: error });
|
|
195
|
+
if (!isCurrent())
|
|
196
|
+
return;
|
|
133
197
|
}
|
|
134
|
-
const bridgeAbort = new AbortController();
|
|
135
|
-
this._bridgeAbort = bridgeAbort;
|
|
136
198
|
this.reactive.props.subscribe((props, errors) => {
|
|
137
199
|
this._propsRef.value = props;
|
|
138
200
|
this._errorsRef.value = [...errors];
|
|
@@ -149,67 +211,165 @@ var WippyVueElement = class extends WippyElement {
|
|
|
149
211
|
this._hostVisibilityRef.value = visible;
|
|
150
212
|
}, { signal: bridgeAbort.signal });
|
|
151
213
|
const mountApp = (mountConfig) => {
|
|
152
|
-
if (
|
|
214
|
+
if (!isCurrent())
|
|
153
215
|
return;
|
|
154
216
|
const hostPinia = getActivePinia();
|
|
155
217
|
const app = createApp(mountConfig.rootComponent);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
218
|
+
let mounted = false;
|
|
219
|
+
let failed = false;
|
|
220
|
+
let initialError;
|
|
221
|
+
let errorHandler;
|
|
222
|
+
this._mountingApp = true;
|
|
223
|
+
try {
|
|
224
|
+
const pinia = createPinia();
|
|
225
|
+
if (mountConfig.piniaPlugins) {
|
|
226
|
+
for (const plugin of mountConfig.piniaPlugins)
|
|
227
|
+
pinia.use(plugin);
|
|
228
|
+
}
|
|
229
|
+
app.use(pinia);
|
|
230
|
+
for (const plugin of mountConfig.plugins ?? [])
|
|
165
231
|
app.use(plugin);
|
|
232
|
+
app.provide(PROPS_PROVIDER, this._propsRef);
|
|
233
|
+
app.provide(PROPS_ERROR_PROVIDER, this._errorsRef);
|
|
234
|
+
app.provide(EVENT_PROVIDER, this.emitEvent.bind(this));
|
|
235
|
+
app.provide(CONTENT_PROVIDER, this._contentRef);
|
|
236
|
+
app.provide(HOST_VISIBILITY_PROVIDER, this._hostVisibilityRef);
|
|
237
|
+
app.provide(PANEL_ID_PROVIDER, getWippyPanelId(this));
|
|
238
|
+
app.provide(LAYOUT_BUS_PROVIDER, getWippyHostBus(this));
|
|
239
|
+
app.provide(HOST_PROVIDER, getWippyHost(this));
|
|
240
|
+
mountConfig.providers?.(app, this);
|
|
241
|
+
if (!isCurrent())
|
|
242
|
+
return;
|
|
243
|
+
errorHandler = app.config.errorHandler;
|
|
244
|
+
if (vueConfig.mountLifecycle) {
|
|
245
|
+
app.config.errorHandler = (error, instance, info) => {
|
|
246
|
+
if (!failed)
|
|
247
|
+
initialError = error;
|
|
248
|
+
failed = true;
|
|
249
|
+
errorHandler?.(error, instance, info);
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
app.mount(container);
|
|
253
|
+
mounted = true;
|
|
254
|
+
if (failed)
|
|
255
|
+
throw initialError;
|
|
256
|
+
if (isCurrent())
|
|
257
|
+
this._vueApp = app;
|
|
258
|
+
} finally {
|
|
259
|
+
if (vueConfig.mountLifecycle && mounted)
|
|
260
|
+
app.config.errorHandler = errorHandler;
|
|
261
|
+
try {
|
|
262
|
+
if (mounted && (failed || !isCurrent()))
|
|
263
|
+
app.unmount();
|
|
264
|
+
} finally {
|
|
265
|
+
setActivePinia(hostPinia);
|
|
266
|
+
this._mountingApp = false;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (vueConfig.mountLifecycle) {
|
|
270
|
+
queueMicrotask(() => {
|
|
271
|
+
if (isCurrent() && this.isConnected) {
|
|
272
|
+
this._mountState = "mounted";
|
|
273
|
+
this.dispatchEvent(new Event("wippy-mounted"));
|
|
274
|
+
}
|
|
275
|
+
});
|
|
166
276
|
}
|
|
167
|
-
app.provide(PROPS_PROVIDER, this._propsRef);
|
|
168
|
-
app.provide(PROPS_ERROR_PROVIDER, this._errorsRef);
|
|
169
|
-
app.provide(EVENT_PROVIDER, this.emitEvent.bind(this));
|
|
170
|
-
app.provide(CONTENT_PROVIDER, this._contentRef);
|
|
171
|
-
app.provide(HOST_VISIBILITY_PROVIDER, this._hostVisibilityRef);
|
|
172
|
-
app.provide(PANEL_ID_PROVIDER, getWippyPanelId(this));
|
|
173
|
-
app.provide(LAYOUT_BUS_PROVIDER, getWippyHostBus(this));
|
|
174
|
-
app.provide(HOST_PROVIDER, getWippyHost(this));
|
|
175
|
-
if (mountConfig.providers)
|
|
176
|
-
mountConfig.providers(app, this);
|
|
177
|
-
app.mount(container);
|
|
178
|
-
if (hostPinia)
|
|
179
|
-
setActivePinia(hostPinia);
|
|
180
277
|
};
|
|
181
278
|
if (vueConfig.rootComponent) {
|
|
182
|
-
|
|
279
|
+
if (this._mountingApp && vueConfig.mountLifecycle) {
|
|
280
|
+
queueMicrotask(() => {
|
|
281
|
+
try {
|
|
282
|
+
mountApp(vueConfig);
|
|
283
|
+
} catch (error) {
|
|
284
|
+
if (isCurrent()) {
|
|
285
|
+
this._mountState = "failed";
|
|
286
|
+
this.emitEvent("error", { message: error instanceof Error ? error.message : String(error), error });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
try {
|
|
293
|
+
mountApp(vueConfig);
|
|
294
|
+
} catch (error) {
|
|
295
|
+
if (isCurrent()) {
|
|
296
|
+
this._mountState = "failed";
|
|
297
|
+
throw error;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
183
300
|
} else if (vueConfig.lazyConfig) {
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
301
|
+
const doc = container.ownerDocument;
|
|
302
|
+
const options = vueConfig.lazyUi;
|
|
303
|
+
if (options?.surface === "page") {
|
|
304
|
+
container.style.blockSize = "100%";
|
|
305
|
+
container.style.minBlockSize = "0";
|
|
306
|
+
}
|
|
307
|
+
let settled = false;
|
|
308
|
+
let delayTimer;
|
|
309
|
+
let deadline;
|
|
310
|
+
const clearPending = () => {
|
|
311
|
+
clearTimeout(delayTimer);
|
|
312
|
+
clearTimeout(deadline);
|
|
313
|
+
this._feedback?.remove();
|
|
314
|
+
this._feedback = null;
|
|
315
|
+
};
|
|
316
|
+
bridgeAbort.signal.addEventListener("abort", clearPending, { once: true });
|
|
317
|
+
const showLoader = () => {
|
|
318
|
+
if (!isCurrent() || settled)
|
|
189
319
|
return;
|
|
190
|
-
loader.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
320
|
+
const loader = options ? lazyFeedback(doc, options, false) : doc.createElement("wippy-loading");
|
|
321
|
+
loader.setAttribute("no-bg", "");
|
|
322
|
+
this._feedback = loader;
|
|
323
|
+
container.appendChild(loader);
|
|
324
|
+
};
|
|
325
|
+
const fail = (error) => {
|
|
326
|
+
if (!isCurrent())
|
|
194
327
|
return;
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
328
|
+
settled = true;
|
|
329
|
+
clearPending();
|
|
330
|
+
this._mountState = "failed";
|
|
331
|
+
const message = options?.failed ?? (error instanceof Error ? error.message : String(error));
|
|
332
|
+
const el = options ? lazyFeedback(doc, options, true) : doc.createElement("wippy-error");
|
|
333
|
+
if (!options) {
|
|
334
|
+
el.setAttribute("title", "Failed to load");
|
|
335
|
+
el.setAttribute("message", message);
|
|
336
|
+
}
|
|
337
|
+
this._feedback = el;
|
|
338
|
+
container.appendChild(el);
|
|
339
|
+
this.emitEvent("error", options ? { message, error } : { message });
|
|
340
|
+
};
|
|
341
|
+
const delay = options?.delay ?? (options?.surface === "compact" ? 200 : 0);
|
|
342
|
+
if (delay > 0)
|
|
343
|
+
delayTimer = setTimeout(showLoader, delay);
|
|
344
|
+
else
|
|
345
|
+
showLoader();
|
|
346
|
+
if (options)
|
|
347
|
+
deadline = setTimeout(() => fail(new Error("The component did not load in time.")), options.timeout ?? 3e4);
|
|
348
|
+
const promise = vueConfig.mountLifecycle ? loadImplementation(ctor, vueConfig.lazyConfig) : vueConfig.lazyConfig();
|
|
349
|
+
void promise.then((mountConfig) => {
|
|
350
|
+
if (!isCurrent() || settled)
|
|
351
|
+
return;
|
|
352
|
+
settled = true;
|
|
353
|
+
clearPending();
|
|
354
|
+
mountApp(mountConfig);
|
|
355
|
+
}, (error) => {
|
|
356
|
+
if (!settled)
|
|
357
|
+
fail(error);
|
|
358
|
+
}).catch(fail);
|
|
202
359
|
} else {
|
|
360
|
+
this._mountState = "failed";
|
|
203
361
|
throw new Error("WippyVueElement vueConfig must provide rootComponent or lazyConfig");
|
|
204
362
|
}
|
|
205
363
|
}
|
|
206
364
|
onUnmount() {
|
|
207
365
|
this._bridgeAbort?.abort();
|
|
208
366
|
this._bridgeAbort = null;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
367
|
+
this._mountState = "idle";
|
|
368
|
+
this._feedback?.remove();
|
|
369
|
+
this._feedback = null;
|
|
370
|
+
const app = this._vueApp;
|
|
371
|
+
this._vueApp = null;
|
|
372
|
+
app?.unmount();
|
|
213
373
|
}
|
|
214
374
|
};
|
|
215
375
|
|
|
@@ -228,6 +388,7 @@ export {
|
|
|
228
388
|
WippyVueElement,
|
|
229
389
|
createProviders,
|
|
230
390
|
define,
|
|
391
|
+
lazyVueConfig,
|
|
231
392
|
useContent,
|
|
232
393
|
useEvents,
|
|
233
394
|
useHost,
|
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 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 '@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,C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K,CAAC,gBAAgB;AACrB,YAAI,YAAY,OAAO;AACrB;AACF,eAAO,OAAO;AACd,iBAAS,WAAW;AAAA,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/lazy.ts","../src/providers.ts","../src/vue-element.ts","../src/index.ts"],"sourcesContent":["import type { WippyVueElementConfig, WippyVueMountConfig } from './vue-element.ts'\n\nexport interface WippyVueLazyOptions {\n surface: 'page' | 'compact'\n loading: string\n failed: string\n /** Milliseconds before showing a compact spinner. */\n delay?: number\n /** Milliseconds each attachment waits for the implementation. */\n timeout?: number\n /** Compact errors use an icon and an accessible label. */\n iconOnly?: boolean\n}\n\n/** The importer should only load code and configuration. Vue mounts on attachment. */\nexport function lazyVueConfig(\n load: () => Promise<WippyVueMountConfig>,\n options: WippyVueLazyOptions,\n): WippyVueElementConfig {\n return { lazyConfig: load, mountLifecycle: true, lazyUi: options }\n}\n\nexport function lazyFeedback(document: Document, options: WippyVueLazyOptions, failed: boolean): HTMLElement {\n const el = document.createElement('div')\n const label = failed ? options.failed : options.loading\n el.dataset.lazyState = failed ? 'failed' : 'loading'\n el.setAttribute('role', failed ? 'alert' : 'status')\n el.setAttribute('aria-label', label)\n el.style.cssText = 'display:grid;place-items:center;text-align:center;'\n const page = options.surface === 'page'\n el.style.cssText += page ? 'block-size:100%;min-block-size:0;' : 'min-block-size:2rem;font-size:.875rem;'\n if (failed) {\n el.style.color = 'var(--p-danger-500, currentColor)'\n el.textContent = !page && options.iconOnly ? '⚠' : label\n if (!page && options.iconOnly)\n el.title = label\n }\n else {\n const style = document.createElement('style')\n style.textContent = '@media (prefers-reduced-motion: no-preference) { [data-lazy-state=\"loading\"] > [data-wippy-spinner] { animation: wippy-lazy-spin 1s linear infinite; } } @keyframes wippy-lazy-spin { to { transform: rotate(1turn); } }'\n const spinner = document.createElement('span')\n spinner.dataset.wippySpinner = ''\n spinner.setAttribute('aria-hidden', 'true')\n spinner.style.cssText = 'display:block;box-sizing:border-box;inline-size:1em;block-size:1em;border:2px solid var(--p-surface-300, currentColor);border-top-color:var(--p-primary-color, currentColor);border-radius:50%;'\n spinner.style.fontSize = page ? '2rem' : '1em'\n el.append(style, spinner)\n }\n return el\n}\n","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 type { WippyVueLazyOptions } from './lazy.ts'\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 { lazyFeedback } from './lazy.ts'\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 /** Opt in when the eager root renders synchronously or lazyConfig resolves the real root. */\r\n mountLifecycle?: true\r\n lazyUi?: WippyVueLazyOptions\r\n}\r\n\r\nexport type WippyMountState = 'idle' | 'mounting' | 'mounted' | 'failed'\r\n\r\nconst implementations = new WeakMap<typeof WippyVueElement, Promise<WippyVueMountConfig>>()\r\n\r\nfunction loadImplementation(ctor: typeof WippyVueElement, load: () => Promise<WippyVueMountConfig>) {\r\n const pending = implementations.get(ctor)\r\n if (pending)\r\n return pending\r\n const attempt = Promise.resolve().then(load)\r\n implementations.set(ctor, attempt)\r\n void attempt.catch(() => {\r\n if (implementations.get(ctor) === attempt)\r\n implementations.delete(ctor)\r\n })\r\n return attempt\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 _mountingApp = false\r\n private _mountState: WippyMountState = 'idle'\r\n private _feedback: HTMLElement | 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 /** Prepare the implementation without creating a Vue or Pinia instance. */\r\n static async preloadImplementation(): Promise<void> {\r\n const config = this.vueConfig\r\n if (config.mountLifecycle && !config.rootComponent && config.lazyConfig)\r\n await loadImplementation(this, config.lazyConfig)\r\n }\r\n\r\n /** Undefined on configurations that use only the legacy load event. */\r\n get wippyMountState(): WippyMountState | undefined {\r\n return (this.constructor as typeof WippyVueElement).vueConfig.mountLifecycle ? this._mountState : undefined\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 ctor = this.constructor as typeof WippyVueElement\r\n const vueConfig = ctor.vueConfig\r\n const bridgeAbort = new AbortController()\r\n this._bridgeAbort = bridgeAbort\r\n const isCurrent = () => !bridgeAbort.signal.aborted && this._bridgeAbort === bridgeAbort\r\n this._mountState = 'mounting'\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 if (!isCurrent())\r\n return\r\n }\r\n\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 if (!isCurrent())\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 let mounted = false\r\n let failed = false\r\n let initialError: unknown\r\n let errorHandler: typeof app.config.errorHandler\r\n this._mountingApp = true\r\n try {\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 for (const plugin of mountConfig.plugins ?? [])\r\n app.use(plugin)\r\n\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)\r\n app.provide(HOST_VISIBILITY_PROVIDER, this._hostVisibilityRef)\r\n\r\n // Managed layout sets these wires before the element is connected.\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 mountConfig.providers?.(app, this)\r\n if (!isCurrent())\r\n return\r\n\r\n errorHandler = app.config.errorHandler\r\n if (vueConfig.mountLifecycle) {\r\n app.config.errorHandler = (error, instance, info) => {\r\n if (!failed)\r\n initialError = error\r\n failed = true\r\n errorHandler?.(error, instance, info)\r\n }\r\n }\r\n app.mount(container)\r\n mounted = true\r\n if (failed)\r\n throw initialError\r\n if (isCurrent())\r\n this._vueApp = app\r\n }\r\n finally {\r\n if (vueConfig.mountLifecycle && mounted)\r\n app.config.errorHandler = errorHandler\r\n try {\r\n if (mounted && (failed || !isCurrent()))\r\n app.unmount()\r\n }\r\n finally {\r\n setActivePinia(hostPinia)\r\n this._mountingApp = false\r\n }\r\n }\r\n\r\n if (vueConfig.mountLifecycle) {\r\n // The base class dispatches the eager element's legacy load synchronously.\r\n queueMicrotask(() => {\r\n if (isCurrent() && this.isConnected) {\r\n this._mountState = 'mounted'\r\n this.dispatchEvent(new Event('wippy-mounted'))\r\n }\r\n })\r\n }\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 if (this._mountingApp && vueConfig.mountLifecycle) {\r\n queueMicrotask(() => {\r\n try {\r\n mountApp(vueConfig as WippyVueMountConfig)\r\n }\r\n catch (error) {\r\n if (isCurrent()) {\r\n this._mountState = 'failed'\r\n this.emitEvent('error', { message: error instanceof Error ? error.message : String(error), error })\r\n }\r\n }\r\n })\r\n return\r\n }\r\n try {\r\n mountApp(vueConfig as WippyVueMountConfig)\r\n }\r\n catch (error) {\r\n if (isCurrent()) {\r\n this._mountState = 'failed'\r\n throw error\r\n }\r\n }\r\n }\r\n else if (vueConfig.lazyConfig) {\r\n const doc = container.ownerDocument\r\n const options = vueConfig.lazyUi\r\n if (options?.surface === 'page') {\r\n container.style.blockSize = '100%'\r\n container.style.minBlockSize = '0'\r\n }\r\n let settled = false\r\n let delayTimer: ReturnType<typeof setTimeout> | undefined\r\n let deadline: ReturnType<typeof setTimeout> | undefined\r\n const clearPending = () => {\r\n clearTimeout(delayTimer)\r\n clearTimeout(deadline)\r\n this._feedback?.remove()\r\n this._feedback = null\r\n }\r\n bridgeAbort.signal.addEventListener('abort', clearPending, { once: true })\r\n const showLoader = () => {\r\n if (!isCurrent() || settled)\r\n return\r\n const loader = options ? lazyFeedback(doc, options, false) : doc.createElement('wippy-loading')\r\n loader.setAttribute('no-bg', '')\r\n this._feedback = loader\r\n container.appendChild(loader)\r\n }\r\n const fail = (error: unknown) => {\r\n if (!isCurrent())\r\n return\r\n settled = true\r\n clearPending()\r\n this._mountState = 'failed'\r\n const message = options?.failed ?? (error instanceof Error ? error.message : String(error))\r\n const el = options ? lazyFeedback(doc, options, true) : doc.createElement('wippy-error')\r\n if (!options) {\r\n el.setAttribute('title', 'Failed to load')\r\n el.setAttribute('message', message)\r\n }\r\n this._feedback = el\r\n container.appendChild(el)\r\n this.emitEvent('error', options ? { message, error } : { message })\r\n }\r\n const delay = options?.delay ?? (options?.surface === 'compact' ? 200 : 0)\r\n if (delay > 0)\r\n delayTimer = setTimeout(showLoader, delay)\r\n else\r\n showLoader()\r\n if (options)\r\n deadline = setTimeout(() => fail(new Error('The component did not load in time.')), options.timeout ?? 30000)\r\n\r\n const promise = vueConfig.mountLifecycle\r\n ? loadImplementation(ctor, vueConfig.lazyConfig)\r\n : vueConfig.lazyConfig()\r\n void promise.then((mountConfig) => {\r\n if (!isCurrent() || settled)\r\n return\r\n settled = true\r\n clearPending()\r\n mountApp(mountConfig)\r\n }, (error) => {\r\n if (!settled)\r\n fail(error)\r\n }).catch(fail)\r\n }\r\n else {\r\n this._mountState = 'failed'\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 this._mountState = 'idle'\r\n this._feedback?.remove()\r\n this._feedback = null\r\n const app = this._vueApp\r\n this._vueApp = null\r\n app?.unmount()\r\n }\r\n}\r\n","export { lazyVueConfig } from './lazy.ts'\r\nexport type { WippyVueLazyOptions } from './lazy.ts'\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// Vue layer\r\nexport { WippyVueElement } from './vue-element.ts'\r\nexport type { WippyMountState, 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":";;;;;AAeO,SAAS,cACd,MACA,SACuB;AACvB,SAAO,EAAE,YAAY,MAAM,gBAAgB,MAAM,QAAQ,QAAQ;AACnE;AAEO,SA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AO;AACvB,SAAK,YAAY;AACjB,UAAM,MAAM,KAAK;AACjB,SAAK,UAAU;AACf,SAAK,QAAQ;AAAA,EACf;AACF;;;AClVA,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.70",
|
|
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",
|
|
@@ -18,17 +18,18 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"package.json",
|
|
20
20
|
"README.md",
|
|
21
|
-
"dist/"
|
|
21
|
+
"dist/",
|
|
22
|
+
"starter/"
|
|
22
23
|
],
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@wippy-fe/webcomponent-core": "^0.0.
|
|
25
|
+
"@wippy-fe/webcomponent-core": "^0.0.70"
|
|
25
26
|
},
|
|
26
27
|
"peerDependencies": {
|
|
28
|
+
"@wippy-fe/proxy": "^0.0.70",
|
|
29
|
+
"@wippy-fe/shared": "^0.0.70",
|
|
27
30
|
"@iconify/vue": "^5.0.0",
|
|
28
31
|
"pinia": "^2.1.0 || ^3.0.0 || ^4.0.0",
|
|
29
|
-
"vue": "^3.5.0"
|
|
30
|
-
"@wippy-fe/proxy": "^0.0.68",
|
|
31
|
-
"@wippy-fe/shared": "^0.0.68"
|
|
32
|
+
"vue": "^3.5.0"
|
|
32
33
|
},
|
|
33
34
|
"scripts": {
|
|
34
35
|
"build": "tsup",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Lazy Vue page starter
|
|
2
|
+
|
|
3
|
+
Copy this directory outside `node_modules`. Copy the matching Web Host
|
|
4
|
+
release's `import-map.json` into it. The build uses that file's exact
|
|
5
|
+
external names. Install the matching release of all `@wippy-fe` packages
|
|
6
|
+
and run `npm run build`.
|
|
7
|
+
|
|
8
|
+
Serve `dist/` as the static directory of a Wippy `view.component`. Use
|
|
9
|
+
`index.js` as its entrypoint and `example-lazy-page` as the tag. The Host
|
|
10
|
+
provides the import map and proxy. In KickSide, a navigation item that
|
|
11
|
+
names the tag mounts the page in a full-height slot.
|
|
12
|
+
|
|
13
|
+
Use `surface: 'compact'` for a control and let the component occupy its
|
|
14
|
+
natural height. A host that needs that height can observe the element
|
|
15
|
+
with `ResizeObserver`.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "example-lazy-page",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"specification": "wippy-component-1.0",
|
|
7
|
+
"browser": "index.js",
|
|
8
|
+
"scripts": { "build": "vite build" },
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@iconify/vue": "^5.0.0",
|
|
11
|
+
"@wippy-fe/proxy": "*",
|
|
12
|
+
"@wippy-fe/shared": "*",
|
|
13
|
+
"@wippy-fe/webcomponent-vue": "*",
|
|
14
|
+
"pinia": "^3.0.0",
|
|
15
|
+
"vue": "^3.5.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@wippy-fe/vite-plugin": "*",
|
|
19
|
+
"vite": "^7.3.0"
|
|
20
|
+
},
|
|
21
|
+
"wippy": { "type": "component", "tagName": "example-lazy-page" }
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { define, lazyVueConfig, WippyVueElement } from '@wippy-fe/webcomponent-vue'
|
|
2
|
+
|
|
3
|
+
class ExamplePage extends WippyVueElement {
|
|
4
|
+
static get wippyConfig() {
|
|
5
|
+
return {
|
|
6
|
+
propsSchema: { type: 'object', properties: {} },
|
|
7
|
+
hostCssKeys: ['themeConfigUrl'],
|
|
8
|
+
inlineCss: ':host{display:block;height:100%;min-height:0}main{height:100%;overflow:auto}',
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static get vueConfig() {
|
|
13
|
+
return lazyVueConfig(() => import('./page.js').then(({ default: rootComponent }) => ({ rootComponent })), {
|
|
14
|
+
surface: 'page',
|
|
15
|
+
loading: 'Loading the example page',
|
|
16
|
+
failed: 'Could not load the example page.',
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function webComponent() {
|
|
22
|
+
return ExamplePage
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
define(import.meta.url, ExamplePage)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import { wippyComponentPlugin } from '@wippy-fe/vite-plugin'
|
|
4
|
+
import { defineConfig } from 'vite'
|
|
5
|
+
|
|
6
|
+
const index = fileURLToPath(new URL('./src/index.js', import.meta.url))
|
|
7
|
+
const { imports } = JSON.parse(readFileSync(new URL('./import-map.json', import.meta.url), 'utf8'))
|
|
8
|
+
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
plugins: [wippyComponentPlugin({ required: true, lazyEntries: ['index'] })],
|
|
11
|
+
build: {
|
|
12
|
+
target: 'esnext',
|
|
13
|
+
lib: { entry: { index }, formats: ['es'] },
|
|
14
|
+
rollupOptions: {
|
|
15
|
+
external: Object.keys(imports),
|
|
16
|
+
preserveEntrySignatures: 'strict',
|
|
17
|
+
output: {
|
|
18
|
+
manualChunks(id) {
|
|
19
|
+
if (id.includes('/@wippy-fe/webcomponent-') || id.includes('/@wippy-fe--webcomponent-'))
|
|
20
|
+
return 'wc-runtime'
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
})
|