wu-framework 1.0.6 → 1.1.1

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.
@@ -0,0 +1,299 @@
1
+ /**
2
+ * Wu Framework Vue Adapter - TypeScript Definitions
3
+ */
4
+
5
+ import { App, Component, Ref, DefineComponent } from 'vue';
6
+
7
+ // ============================================================================
8
+ // Core Types (shared with React adapter)
9
+ // ============================================================================
10
+
11
+ export interface WuInstance {
12
+ init: (config: WuConfig) => Promise<void>;
13
+ mount: (appName: string, container: string) => Promise<void>;
14
+ unmount: (appName: string) => Promise<void>;
15
+ define: (appName: string, lifecycle: WuLifecycle) => void;
16
+ app: (name: string, config: WuAppConfig) => WuApp;
17
+ eventBus: WuEventBus;
18
+ store: WuStore;
19
+ }
20
+
21
+ export interface WuConfig {
22
+ apps: Array<{
23
+ name: string;
24
+ url: string;
25
+ strategy?: 'lazy' | 'eager' | 'preload' | 'idle';
26
+ }>;
27
+ }
28
+
29
+ export interface WuLifecycle {
30
+ mount: (container: HTMLElement) => void | Promise<void>;
31
+ unmount: (container?: HTMLElement) => void | Promise<void>;
32
+ }
33
+
34
+ export interface WuAppConfig {
35
+ url: string;
36
+ container: string;
37
+ autoInit?: boolean;
38
+ }
39
+
40
+ export interface WuApp {
41
+ mount: (container?: string) => Promise<void>;
42
+ unmount: () => Promise<void>;
43
+ remount: () => Promise<void>;
44
+ reload: () => Promise<void>;
45
+ destroy: () => Promise<void>;
46
+ isMounted: boolean;
47
+ info: WuAppInfo;
48
+ }
49
+
50
+ export interface WuAppInfo {
51
+ name: string;
52
+ url: string;
53
+ mounted: boolean;
54
+ status: 'stable' | 'refreshed' | 'unstable';
55
+ }
56
+
57
+ export interface WuEventBus {
58
+ emit: (event: string, data?: any, options?: EmitOptions) => void;
59
+ on: (event: string, callback: EventCallback) => () => void;
60
+ once: (event: string, callback: EventCallback) => () => void;
61
+ off: (event: string, callback?: EventCallback) => void;
62
+ }
63
+
64
+ export interface WuStore {
65
+ get: (path?: string) => any;
66
+ set: (path: string, value: any) => number;
67
+ on: (pattern: string, callback: StoreCallback) => () => void;
68
+ batch: (updates: Record<string, any>) => number[];
69
+ clear: () => void;
70
+ }
71
+
72
+ export type EventCallback = (event: WuEvent) => void;
73
+ export type StoreCallback = (change: { path: string; value: any }) => void;
74
+
75
+ export interface WuEvent {
76
+ name: string;
77
+ data: any;
78
+ timestamp: number;
79
+ source?: string;
80
+ }
81
+
82
+ export interface EmitOptions {
83
+ appName?: string;
84
+ timestamp?: number;
85
+ meta?: Record<string, any>;
86
+ }
87
+
88
+ // ============================================================================
89
+ // Vue Adapter Types
90
+ // ============================================================================
91
+
92
+ export interface VueRegisterOptions {
93
+ /**
94
+ * Function to configure the Vue app (install plugins, add global components, etc.)
95
+ * @param app - Vue app instance
96
+ */
97
+ setup?: (app: App) => void;
98
+ /** Initial props for the component */
99
+ props?: Record<string, any>;
100
+ /** Callback after mounting */
101
+ onMount?: (container: HTMLElement, app: App) => void;
102
+ /** Callback before unmounting */
103
+ onUnmount?: (container: HTMLElement, app: App) => void;
104
+ /** Allow standalone execution (default: true) */
105
+ standalone?: boolean;
106
+ /** Selector for standalone mode (default: '#app') */
107
+ standaloneContainer?: string;
108
+ }
109
+
110
+ /**
111
+ * Register a Vue component as a microfrontend
112
+ *
113
+ * @example
114
+ * // Basic
115
+ * wuVue.register('my-app', App);
116
+ *
117
+ * @example
118
+ * // With plugins
119
+ * wuVue.register('my-app', App, {
120
+ * setup: (app) => {
121
+ * app.use(createPinia());
122
+ * app.use(router);
123
+ * }
124
+ * });
125
+ */
126
+ export function register(
127
+ appName: string,
128
+ RootComponent: Component,
129
+ options?: VueRegisterOptions
130
+ ): Promise<boolean>;
131
+
132
+ // ============================================================================
133
+ // WuSlot Component Types
134
+ // ============================================================================
135
+
136
+ export interface WuSlotProps {
137
+ /** Display name for the microfrontend */
138
+ name: string;
139
+ /** URL where the microfrontend is hosted */
140
+ url: string;
141
+ /** App name from wu.json (defaults to name if not provided) */
142
+ appName?: string;
143
+ /** Custom fallback text while loading */
144
+ fallbackText?: string;
145
+ }
146
+
147
+ export interface WuSlotEmits {
148
+ /** Emitted when microfrontend loads successfully */
149
+ (e: 'load', info: { name: string; url: string }): void;
150
+ /** Emitted when loading fails */
151
+ (e: 'error', error: Error): void;
152
+ /** Emitted when microfrontend mounts */
153
+ (e: 'mount', info: { name: string; container: HTMLElement }): void;
154
+ /** Emitted when microfrontend unmounts */
155
+ (e: 'unmount', info: { name: string }): void;
156
+ }
157
+
158
+ /**
159
+ * Vue component for loading microfrontends
160
+ *
161
+ * @example
162
+ * <WuSlot name="my-app" url="http://localhost:3001" @load="onLoad" />
163
+ */
164
+ export const WuSlot: DefineComponent<WuSlotProps, {}, {}, {}, {}, {}, {}, WuSlotEmits>;
165
+
166
+ // ============================================================================
167
+ // Composables Types
168
+ // ============================================================================
169
+
170
+ export interface UseWuEventsReturn {
171
+ /** Emit an event to the event bus */
172
+ emit: (event: string, data?: any, options?: EmitOptions) => void;
173
+ /** Subscribe to an event */
174
+ on: (event: string, callback: EventCallback) => () => void;
175
+ /** Subscribe to an event once */
176
+ once: (event: string, callback: EventCallback) => () => void;
177
+ /** Unsubscribe from an event */
178
+ off: (event: string, callback?: EventCallback) => void;
179
+ /** Clean up all subscriptions (call in onUnmounted) */
180
+ cleanup: () => void;
181
+ }
182
+
183
+ /**
184
+ * Composable for using Wu Framework EventBus
185
+ *
186
+ * @example
187
+ * const { emit, on, cleanup } = useWuEvents();
188
+ *
189
+ * onMounted(() => {
190
+ * on('user:login', handleLogin);
191
+ * });
192
+ *
193
+ * onUnmounted(() => {
194
+ * cleanup();
195
+ * });
196
+ */
197
+ export function useWuEvents(): UseWuEventsReturn;
198
+
199
+ export interface UseWuStoreReturn<T = any> {
200
+ /** Reactive state value */
201
+ state: Ref<T | null>;
202
+ /** Set a value in the store */
203
+ setState: (path: string, value: any) => void;
204
+ /** Get a value from the store */
205
+ getState: (path?: string) => any;
206
+ /** Clean up subscription (call in onUnmounted) */
207
+ cleanup: () => void;
208
+ }
209
+
210
+ /**
211
+ * Composable for using Wu Framework Store
212
+ *
213
+ * @example
214
+ * const { state, setState, getState, cleanup } = useWuStore('user');
215
+ *
216
+ * // state.value is reactive
217
+ * watchEffect(() => {
218
+ * console.log('User changed:', state.value);
219
+ * });
220
+ *
221
+ * onUnmounted(() => {
222
+ * cleanup();
223
+ * });
224
+ */
225
+ export function useWuStore<T = any>(namespace?: string): UseWuStoreReturn<T>;
226
+
227
+ // ============================================================================
228
+ // Plugin Types
229
+ // ============================================================================
230
+
231
+ export interface WuVuePluginOptions {
232
+ // Reserved for future options
233
+ }
234
+
235
+ /**
236
+ * Vue plugin to install Wu Framework globally
237
+ *
238
+ * @example
239
+ * import { createApp } from 'vue';
240
+ * import { wuVuePlugin } from 'wu-framework/adapters/vue';
241
+ *
242
+ * const app = createApp(App);
243
+ * app.use(wuVuePlugin);
244
+ *
245
+ * // Now you can use:
246
+ * // - <WuSlot /> component globally
247
+ * // - this.$wu in Options API
248
+ * // - inject('wu') in Composition API
249
+ */
250
+ export const wuVuePlugin: {
251
+ install: (app: App, options?: WuVuePluginOptions) => void;
252
+ };
253
+
254
+ // ============================================================================
255
+ // Utility Functions
256
+ // ============================================================================
257
+
258
+ /**
259
+ * Get the Wu Framework instance
260
+ */
261
+ export function getWuInstance(): WuInstance | null;
262
+
263
+ /**
264
+ * Wait for Wu Framework to be available
265
+ * @param timeout - Maximum time to wait in ms (default: 5000)
266
+ */
267
+ export function waitForWu(timeout?: number): Promise<WuInstance>;
268
+
269
+ // ============================================================================
270
+ // Main Export
271
+ // ============================================================================
272
+
273
+ export interface WuVueAdapter {
274
+ register: typeof register;
275
+ WuSlot: typeof WuSlot;
276
+ useWuEvents: typeof useWuEvents;
277
+ useWuStore: typeof useWuStore;
278
+ wuVuePlugin: typeof wuVuePlugin;
279
+ getWuInstance: typeof getWuInstance;
280
+ waitForWu: typeof waitForWu;
281
+ }
282
+
283
+ export const wuVue: WuVueAdapter;
284
+ export default wuVue;
285
+
286
+ // ============================================================================
287
+ // Global Augmentations
288
+ // ============================================================================
289
+
290
+ declare module '@vue/runtime-core' {
291
+ interface ComponentCustomProperties {
292
+ /** Wu Framework instance */
293
+ $wu: WuInstance | null;
294
+ /** Wu Framework EventBus helpers */
295
+ $wuEvents: UseWuEventsReturn;
296
+ /** Wu Framework Store factory */
297
+ $wuStore: <T = any>(namespace?: string) => UseWuStoreReturn<T>;
298
+ }
299
+ }