wu-framework 1.1.7 → 1.1.8
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 +511 -977
- package/dist/wu-framework.cjs.js +3 -1
- package/dist/wu-framework.cjs.js.map +1 -0
- package/dist/wu-framework.dev.js +7533 -2761
- package/dist/wu-framework.dev.js.map +1 -1
- package/dist/wu-framework.esm.js +3 -0
- package/dist/wu-framework.esm.js.map +1 -0
- package/dist/wu-framework.umd.js +3 -1
- package/dist/wu-framework.umd.js.map +1 -0
- package/integrations/astro/README.md +127 -0
- package/integrations/astro/WuApp.astro +63 -0
- package/integrations/astro/WuShell.astro +39 -0
- package/integrations/astro/index.js +68 -0
- package/integrations/astro/package.json +38 -0
- package/integrations/astro/types.d.ts +53 -0
- package/package.json +89 -71
- package/src/adapters/angular/ai.js +30 -0
- package/src/adapters/angular/index.d.ts +154 -0
- package/src/adapters/angular/index.js +932 -0
- package/src/adapters/angular.d.ts +3 -154
- package/src/adapters/angular.js +3 -813
- package/src/adapters/index.js +35 -24
- package/src/adapters/lit/ai.js +20 -0
- package/src/adapters/lit/index.d.ts +120 -0
- package/src/adapters/lit/index.js +721 -0
- package/src/adapters/lit.d.ts +3 -120
- package/src/adapters/lit.js +3 -726
- package/src/adapters/preact/ai.js +33 -0
- package/src/adapters/preact/index.d.ts +108 -0
- package/src/adapters/preact/index.js +661 -0
- package/src/adapters/preact.d.ts +3 -108
- package/src/adapters/preact.js +3 -665
- package/src/adapters/react/ai.js +135 -0
- package/src/adapters/react/index.d.ts +246 -0
- package/src/adapters/react/index.js +689 -0
- package/src/adapters/react.d.ts +3 -212
- package/src/adapters/react.js +3 -513
- package/src/adapters/shared.js +64 -0
- package/src/adapters/solid/ai.js +32 -0
- package/src/adapters/solid/index.d.ts +101 -0
- package/src/adapters/solid/index.js +586 -0
- package/src/adapters/solid.d.ts +3 -101
- package/src/adapters/solid.js +3 -591
- package/src/adapters/svelte/ai.js +31 -0
- package/src/adapters/svelte/index.d.ts +166 -0
- package/src/adapters/svelte/index.js +798 -0
- package/src/adapters/svelte.d.ts +3 -166
- package/src/adapters/svelte.js +3 -803
- package/src/adapters/vanilla/ai.js +30 -0
- package/src/adapters/vanilla/index.d.ts +179 -0
- package/src/adapters/vanilla/index.js +785 -0
- package/src/adapters/vanilla.d.ts +3 -179
- package/src/adapters/vanilla.js +3 -791
- package/src/adapters/vue/ai.js +52 -0
- package/src/adapters/vue/index.d.ts +299 -0
- package/src/adapters/vue/index.js +608 -0
- package/src/adapters/vue.d.ts +3 -299
- package/src/adapters/vue.js +3 -611
- package/src/ai/wu-ai-actions.js +261 -0
- package/src/ai/wu-ai-browser.js +663 -0
- package/src/ai/wu-ai-context.js +332 -0
- package/src/ai/wu-ai-conversation.js +554 -0
- package/src/ai/wu-ai-permissions.js +381 -0
- package/src/ai/wu-ai-provider.js +605 -0
- package/src/ai/wu-ai-schema.js +225 -0
- package/src/ai/wu-ai-triggers.js +396 -0
- package/src/ai/wu-ai.js +474 -0
- package/src/core/wu-app.js +50 -8
- package/src/core/wu-cache.js +1 -1
- package/src/core/wu-core.js +645 -677
- package/src/core/wu-html-parser.js +121 -211
- package/src/core/wu-iframe-sandbox.js +328 -0
- package/src/core/wu-mcp-bridge.js +647 -0
- package/src/core/wu-overrides.js +510 -0
- package/src/core/wu-prefetch.js +414 -0
- package/src/core/wu-proxy-sandbox.js +398 -75
- package/src/core/wu-sandbox.js +86 -268
- package/src/core/wu-script-executor.js +79 -182
- package/src/core/wu-snapshot-sandbox.js +149 -106
- package/src/core/wu-strategies.js +13 -0
- package/src/core/wu-style-bridge.js +0 -2
- package/src/index.js +139 -665
- package/dist/wu-framework.hex.js +0 -23
- package/dist/wu-framework.min.js +0 -1
- package/dist/wu-framework.obf.js +0 -1
- package/scripts/build-protected.js +0 -366
- package/scripts/build.js +0 -212
- package/scripts/rollup-plugin-hex.js +0 -143
- package/src/core/wu-registry.js +0 -60
- package/src/core/wu-sandbox-pool.js +0 -390
package/src/adapters/svelte.js
CHANGED
|
@@ -1,803 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
* Simplifica la integración de Svelte con Wu Framework.
|
|
5
|
-
* Convierte componentes Svelte en microfrontends con UNA línea de código.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* // Microfrontend (main.js)
|
|
9
|
-
* import { wuSvelte } from 'wu-framework/adapters/svelte';
|
|
10
|
-
* import App from './App.svelte';
|
|
11
|
-
*
|
|
12
|
-
* wuSvelte.register('my-app', App);
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* // Shell (cargar microfrontend)
|
|
16
|
-
* import WuSlot from 'wu-framework/adapters/svelte/WuSlot.svelte';
|
|
17
|
-
*
|
|
18
|
-
* <WuSlot name="my-app" url="http://localhost:3001" />
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
// Estado global del adapter
|
|
22
|
-
const adapterState = {
|
|
23
|
-
apps: new Map(),
|
|
24
|
-
initialized: false
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Obtiene la instancia de Wu Framework
|
|
29
|
-
*/
|
|
30
|
-
function getWuInstance() {
|
|
31
|
-
if (typeof window === 'undefined') return null;
|
|
32
|
-
|
|
33
|
-
return window.wu
|
|
34
|
-
|| window.parent?.wu
|
|
35
|
-
|| window.top?.wu
|
|
36
|
-
|| null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Espera a que Wu Framework esté disponible
|
|
41
|
-
*/
|
|
42
|
-
function waitForWu(timeout = 5000) {
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
const wu = getWuInstance();
|
|
45
|
-
if (wu) {
|
|
46
|
-
resolve(wu);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const startTime = Date.now();
|
|
51
|
-
|
|
52
|
-
const handleWuReady = () => {
|
|
53
|
-
cleanup();
|
|
54
|
-
resolve(getWuInstance());
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
window.addEventListener('wu:ready', handleWuReady);
|
|
58
|
-
window.addEventListener('wu:app:ready', handleWuReady);
|
|
59
|
-
|
|
60
|
-
const checkInterval = setInterval(() => {
|
|
61
|
-
const wu = getWuInstance();
|
|
62
|
-
if (wu) {
|
|
63
|
-
cleanup();
|
|
64
|
-
resolve(wu);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (Date.now() - startTime > timeout) {
|
|
69
|
-
cleanup();
|
|
70
|
-
reject(new Error(`Wu Framework not found after ${timeout}ms`));
|
|
71
|
-
}
|
|
72
|
-
}, 200);
|
|
73
|
-
|
|
74
|
-
function cleanup() {
|
|
75
|
-
clearInterval(checkInterval);
|
|
76
|
-
window.removeEventListener('wu:ready', handleWuReady);
|
|
77
|
-
window.removeEventListener('wu:app:ready', handleWuReady);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Registra un componente Svelte como microfrontend
|
|
84
|
-
*
|
|
85
|
-
* @param {string} appName - Nombre único del microfrontend (debe coincidir con wu.json)
|
|
86
|
-
* @param {typeof SvelteComponent} Component - Componente Svelte principal (App.svelte)
|
|
87
|
-
* @param {Object} options - Opciones adicionales
|
|
88
|
-
* @param {Object} options.props - Props iniciales para el componente
|
|
89
|
-
* @param {Object} options.context - Contexto a pasar al componente
|
|
90
|
-
* @param {boolean} options.intro - Ejecutar transiciones de intro (default: false)
|
|
91
|
-
* @param {Function} options.onMount - Callback después de montar
|
|
92
|
-
* @param {Function} options.onUnmount - Callback antes de desmontar
|
|
93
|
-
* @param {boolean} options.standalone - Permitir ejecución standalone (default: true)
|
|
94
|
-
* @param {string} options.standaloneContainer - Selector para modo standalone (default: '#app')
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* // Básico
|
|
98
|
-
* wuSvelte.register('my-app', App);
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* // Con props y context
|
|
102
|
-
* wuSvelte.register('my-app', App, {
|
|
103
|
-
* props: { apiUrl: 'https://api.example.com' },
|
|
104
|
-
* context: new Map([['theme', 'dark']]),
|
|
105
|
-
* onMount: (container) => console.log('Mounted!')
|
|
106
|
-
* });
|
|
107
|
-
*/
|
|
108
|
-
async function register(appName, Component, options = {}) {
|
|
109
|
-
const {
|
|
110
|
-
props = {},
|
|
111
|
-
context = new Map(),
|
|
112
|
-
intro = false,
|
|
113
|
-
onMount = null,
|
|
114
|
-
onUnmount = null,
|
|
115
|
-
standalone = true,
|
|
116
|
-
standaloneContainer = '#app'
|
|
117
|
-
} = options;
|
|
118
|
-
|
|
119
|
-
// Función de mount interna
|
|
120
|
-
const mountApp = (container) => {
|
|
121
|
-
if (!container) {
|
|
122
|
-
console.error(`[WuSvelte] Mount failed for ${appName}: container is null`);
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Evitar doble mount
|
|
127
|
-
if (adapterState.apps.has(appName)) {
|
|
128
|
-
console.warn(`[WuSvelte] ${appName} already mounted, unmounting first`);
|
|
129
|
-
unmountApp();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
try {
|
|
133
|
-
// Limpiar container
|
|
134
|
-
container.innerHTML = '';
|
|
135
|
-
|
|
136
|
-
// Crear instancia del componente Svelte
|
|
137
|
-
const instance = new Component({
|
|
138
|
-
target: container,
|
|
139
|
-
props: {
|
|
140
|
-
...props,
|
|
141
|
-
// Inyectar información de Wu
|
|
142
|
-
wuAppName: appName,
|
|
143
|
-
wuInstance: getWuInstance()
|
|
144
|
-
},
|
|
145
|
-
context,
|
|
146
|
-
intro
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// Guardar referencia
|
|
150
|
-
adapterState.apps.set(appName, {
|
|
151
|
-
instance,
|
|
152
|
-
container,
|
|
153
|
-
Component
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
console.log(`[WuSvelte] ✅ ${appName} mounted successfully`);
|
|
157
|
-
|
|
158
|
-
if (onMount) {
|
|
159
|
-
onMount(container, instance);
|
|
160
|
-
}
|
|
161
|
-
} catch (error) {
|
|
162
|
-
console.error(`[WuSvelte] Mount error for ${appName}:`, error);
|
|
163
|
-
throw error;
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
// Función de unmount interna
|
|
168
|
-
const unmountApp = (container) => {
|
|
169
|
-
const appData = adapterState.apps.get(appName);
|
|
170
|
-
|
|
171
|
-
if (appData) {
|
|
172
|
-
try {
|
|
173
|
-
if (onUnmount) {
|
|
174
|
-
onUnmount(appData.container, appData.instance);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Destruir instancia de Svelte
|
|
178
|
-
appData.instance.$destroy();
|
|
179
|
-
adapterState.apps.delete(appName);
|
|
180
|
-
|
|
181
|
-
console.log(`[WuSvelte] ✅ ${appName} unmounted successfully`);
|
|
182
|
-
} catch (error) {
|
|
183
|
-
console.error(`[WuSvelte] Unmount error for ${appName}:`, error);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Limpiar container si se proporciona
|
|
188
|
-
if (container) {
|
|
189
|
-
container.innerHTML = '';
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
// Intentar registrar con Wu Framework
|
|
194
|
-
try {
|
|
195
|
-
const wu = await waitForWu(3000);
|
|
196
|
-
|
|
197
|
-
wu.define(appName, {
|
|
198
|
-
mount: mountApp,
|
|
199
|
-
unmount: unmountApp
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
console.log(`[WuSvelte] ✅ ${appName} registered with Wu Framework`);
|
|
203
|
-
return true;
|
|
204
|
-
|
|
205
|
-
} catch (error) {
|
|
206
|
-
console.warn(`[WuSvelte] Wu Framework not available for ${appName}`);
|
|
207
|
-
|
|
208
|
-
// Modo standalone si está habilitado
|
|
209
|
-
if (standalone) {
|
|
210
|
-
const containerElement = document.querySelector(standaloneContainer);
|
|
211
|
-
|
|
212
|
-
if (containerElement) {
|
|
213
|
-
console.log(`[WuSvelte] Running ${appName} in standalone mode`);
|
|
214
|
-
mountApp(containerElement);
|
|
215
|
-
return true;
|
|
216
|
-
} else {
|
|
217
|
-
console.warn(`[WuSvelte] Standalone container ${standaloneContainer} not found`);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Registra un componente Svelte 5 con runes como microfrontend
|
|
227
|
-
*
|
|
228
|
-
* @param {string} appName - Nombre único del microfrontend
|
|
229
|
-
* @param {typeof SvelteComponent} Component - Componente Svelte 5
|
|
230
|
-
* @param {Object} options - Opciones adicionales
|
|
231
|
-
*
|
|
232
|
-
* @example
|
|
233
|
-
* // Svelte 5 con mount API
|
|
234
|
-
* import { wuSvelte } from 'wu-framework/adapters/svelte';
|
|
235
|
-
* import App from './App.svelte';
|
|
236
|
-
*
|
|
237
|
-
* wuSvelte.registerSvelte5('my-app', App);
|
|
238
|
-
*/
|
|
239
|
-
async function registerSvelte5(appName, Component, options = {}) {
|
|
240
|
-
const {
|
|
241
|
-
props = {},
|
|
242
|
-
onMount = null,
|
|
243
|
-
onUnmount = null,
|
|
244
|
-
standalone = true,
|
|
245
|
-
standaloneContainer = '#app'
|
|
246
|
-
} = options;
|
|
247
|
-
|
|
248
|
-
// Función de mount para Svelte 5
|
|
249
|
-
const mountApp = async (container) => {
|
|
250
|
-
if (!container) {
|
|
251
|
-
console.error(`[WuSvelte5] Mount failed for ${appName}: container is null`);
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Evitar doble mount
|
|
256
|
-
if (adapterState.apps.has(appName)) {
|
|
257
|
-
console.warn(`[WuSvelte5] ${appName} already mounted, unmounting first`);
|
|
258
|
-
await unmountApp();
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
try {
|
|
262
|
-
container.innerHTML = '';
|
|
263
|
-
|
|
264
|
-
// Svelte 5 usa mount() del módulo svelte
|
|
265
|
-
let mountFn;
|
|
266
|
-
try {
|
|
267
|
-
const svelte = await import('svelte');
|
|
268
|
-
mountFn = svelte.mount;
|
|
269
|
-
} catch (e) {
|
|
270
|
-
// Fallback a API legacy
|
|
271
|
-
console.warn('[WuSvelte5] Svelte 5 mount not available, using legacy API');
|
|
272
|
-
return register(appName, Component, options);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// Montar con Svelte 5 API
|
|
276
|
-
const instance = mountFn(Component, {
|
|
277
|
-
target: container,
|
|
278
|
-
props: {
|
|
279
|
-
...props,
|
|
280
|
-
wuAppName: appName,
|
|
281
|
-
wuInstance: getWuInstance()
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
adapterState.apps.set(appName, {
|
|
286
|
-
instance,
|
|
287
|
-
container,
|
|
288
|
-
Component,
|
|
289
|
-
isSvelte5: true
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
console.log(`[WuSvelte5] ✅ ${appName} mounted successfully`);
|
|
293
|
-
|
|
294
|
-
if (onMount) {
|
|
295
|
-
onMount(container, instance);
|
|
296
|
-
}
|
|
297
|
-
} catch (error) {
|
|
298
|
-
console.error(`[WuSvelte5] Mount error for ${appName}:`, error);
|
|
299
|
-
throw error;
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
// Función de unmount para Svelte 5
|
|
304
|
-
const unmountApp = async (container) => {
|
|
305
|
-
const appData = adapterState.apps.get(appName);
|
|
306
|
-
|
|
307
|
-
if (appData) {
|
|
308
|
-
try {
|
|
309
|
-
if (onUnmount) {
|
|
310
|
-
onUnmount(appData.container, appData.instance);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// Svelte 5 usa unmount()
|
|
314
|
-
if (appData.isSvelte5) {
|
|
315
|
-
try {
|
|
316
|
-
const svelte = await import('svelte');
|
|
317
|
-
if (svelte.unmount) {
|
|
318
|
-
svelte.unmount(appData.instance);
|
|
319
|
-
}
|
|
320
|
-
} catch (e) {
|
|
321
|
-
// Fallback
|
|
322
|
-
if (appData.instance.$destroy) {
|
|
323
|
-
appData.instance.$destroy();
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
} else {
|
|
327
|
-
appData.instance.$destroy();
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
adapterState.apps.delete(appName);
|
|
331
|
-
console.log(`[WuSvelte5] ✅ ${appName} unmounted successfully`);
|
|
332
|
-
} catch (error) {
|
|
333
|
-
console.error(`[WuSvelte5] Unmount error for ${appName}:`, error);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
if (container) {
|
|
338
|
-
container.innerHTML = '';
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
// Intentar registrar con Wu Framework
|
|
343
|
-
try {
|
|
344
|
-
const wu = await waitForWu(3000);
|
|
345
|
-
|
|
346
|
-
wu.define(appName, {
|
|
347
|
-
mount: mountApp,
|
|
348
|
-
unmount: unmountApp
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
console.log(`[WuSvelte5] ✅ ${appName} registered with Wu Framework`);
|
|
352
|
-
return true;
|
|
353
|
-
|
|
354
|
-
} catch (error) {
|
|
355
|
-
console.warn(`[WuSvelte5] Wu Framework not available for ${appName}`);
|
|
356
|
-
|
|
357
|
-
if (standalone) {
|
|
358
|
-
const containerElement = document.querySelector(standaloneContainer);
|
|
359
|
-
|
|
360
|
-
if (containerElement) {
|
|
361
|
-
console.log(`[WuSvelte5] Running ${appName} in standalone mode`);
|
|
362
|
-
await mountApp(containerElement);
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
return false;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Store reactivo para usar con Svelte
|
|
373
|
-
* Compatible con la sintaxis $store de Svelte
|
|
374
|
-
*
|
|
375
|
-
* @param {string} namespace - Namespace en el store de Wu
|
|
376
|
-
* @returns {Object} Store compatible con Svelte
|
|
377
|
-
*
|
|
378
|
-
* @example
|
|
379
|
-
* <script>
|
|
380
|
-
* import { createWuStore } from 'wu-framework/adapters/svelte';
|
|
381
|
-
*
|
|
382
|
-
* const userStore = createWuStore('user');
|
|
383
|
-
*
|
|
384
|
-
* // Usar con sintaxis reactiva
|
|
385
|
-
* $: userName = $userStore?.name;
|
|
386
|
-
*
|
|
387
|
-
* function updateName(name) {
|
|
388
|
-
* userStore.set('name', name);
|
|
389
|
-
* }
|
|
390
|
-
* </script>
|
|
391
|
-
*/
|
|
392
|
-
function createWuStore(namespace = '') {
|
|
393
|
-
const subscribers = new Set();
|
|
394
|
-
let currentValue = null;
|
|
395
|
-
let unsubscribeWu = null;
|
|
396
|
-
|
|
397
|
-
// Obtener valor inicial
|
|
398
|
-
const wu = getWuInstance();
|
|
399
|
-
if (wu?.store) {
|
|
400
|
-
currentValue = wu.store.get(namespace);
|
|
401
|
-
|
|
402
|
-
// Suscribirse a cambios en Wu Store
|
|
403
|
-
const pattern = namespace ? `${namespace}.*` : '*';
|
|
404
|
-
unsubscribeWu = wu.store.on(pattern, () => {
|
|
405
|
-
currentValue = wu.store.get(namespace);
|
|
406
|
-
subscribers.forEach(fn => fn(currentValue));
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
return {
|
|
411
|
-
// Svelte store contract
|
|
412
|
-
subscribe(fn) {
|
|
413
|
-
subscribers.add(fn);
|
|
414
|
-
fn(currentValue);
|
|
415
|
-
|
|
416
|
-
return () => {
|
|
417
|
-
subscribers.delete(fn);
|
|
418
|
-
// Limpiar suscripción a Wu si no hay más subscribers
|
|
419
|
-
if (subscribers.size === 0 && unsubscribeWu) {
|
|
420
|
-
unsubscribeWu();
|
|
421
|
-
unsubscribeWu = null;
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
},
|
|
425
|
-
|
|
426
|
-
// Métodos adicionales
|
|
427
|
-
set(path, value) {
|
|
428
|
-
const wu = getWuInstance();
|
|
429
|
-
if (wu?.store) {
|
|
430
|
-
const fullPath = namespace ? `${namespace}.${path}` : path;
|
|
431
|
-
wu.store.set(fullPath, value);
|
|
432
|
-
}
|
|
433
|
-
},
|
|
434
|
-
|
|
435
|
-
get(path = '') {
|
|
436
|
-
const wu = getWuInstance();
|
|
437
|
-
if (wu?.store) {
|
|
438
|
-
const fullPath = namespace ? (path ? `${namespace}.${path}` : namespace) : path;
|
|
439
|
-
return wu.store.get(fullPath);
|
|
440
|
-
}
|
|
441
|
-
return null;
|
|
442
|
-
},
|
|
443
|
-
|
|
444
|
-
update(fn) {
|
|
445
|
-
const newValue = fn(currentValue);
|
|
446
|
-
const wu = getWuInstance();
|
|
447
|
-
if (wu?.store && namespace) {
|
|
448
|
-
wu.store.set(namespace, newValue);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* Store para eventos de Wu Framework
|
|
456
|
-
* Permite usar eventos de forma reactiva en Svelte
|
|
457
|
-
*
|
|
458
|
-
* @example
|
|
459
|
-
* <script>
|
|
460
|
-
* import { createWuEventStore } from 'wu-framework/adapters/svelte';
|
|
461
|
-
*
|
|
462
|
-
* const userEvents = createWuEventStore('user:*');
|
|
463
|
-
*
|
|
464
|
-
* $: if ($userEvents) {
|
|
465
|
-
* console.log('User event:', $userEvents);
|
|
466
|
-
* }
|
|
467
|
-
* </script>
|
|
468
|
-
*/
|
|
469
|
-
function createWuEventStore(eventPattern) {
|
|
470
|
-
const subscribers = new Set();
|
|
471
|
-
let lastEvent = null;
|
|
472
|
-
let unsubscribeWu = null;
|
|
473
|
-
|
|
474
|
-
const wu = getWuInstance();
|
|
475
|
-
if (wu?.eventBus) {
|
|
476
|
-
unsubscribeWu = wu.eventBus.on(eventPattern, (event) => {
|
|
477
|
-
lastEvent = event;
|
|
478
|
-
subscribers.forEach(fn => fn(lastEvent));
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
return {
|
|
483
|
-
subscribe(fn) {
|
|
484
|
-
subscribers.add(fn);
|
|
485
|
-
fn(lastEvent);
|
|
486
|
-
|
|
487
|
-
return () => {
|
|
488
|
-
subscribers.delete(fn);
|
|
489
|
-
if (subscribers.size === 0 && unsubscribeWu) {
|
|
490
|
-
unsubscribeWu();
|
|
491
|
-
unsubscribeWu = null;
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
},
|
|
495
|
-
|
|
496
|
-
emit(data, options) {
|
|
497
|
-
const wu = getWuInstance();
|
|
498
|
-
if (wu?.eventBus) {
|
|
499
|
-
// Extraer nombre del evento del patrón (sin wildcard)
|
|
500
|
-
const eventName = eventPattern.replace('*', 'custom');
|
|
501
|
-
wu.eventBus.emit(eventName, data, options);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Helper para usar el EventBus de Wu en Svelte
|
|
509
|
-
*
|
|
510
|
-
* @example
|
|
511
|
-
* <script>
|
|
512
|
-
* import { useWuEvents } from 'wu-framework/adapters/svelte';
|
|
513
|
-
* import { onDestroy } from 'svelte';
|
|
514
|
-
*
|
|
515
|
-
* const { emit, on, cleanup } = useWuEvents();
|
|
516
|
-
*
|
|
517
|
-
* on('user:login', (data) => {
|
|
518
|
-
* console.log('User logged in:', data);
|
|
519
|
-
* });
|
|
520
|
-
*
|
|
521
|
-
* onDestroy(cleanup);
|
|
522
|
-
* </script>
|
|
523
|
-
*/
|
|
524
|
-
function useWuEvents() {
|
|
525
|
-
const subscriptions = [];
|
|
526
|
-
|
|
527
|
-
const emit = (event, data, options) => {
|
|
528
|
-
const wu = getWuInstance();
|
|
529
|
-
if (wu?.eventBus) {
|
|
530
|
-
wu.eventBus.emit(event, data, options);
|
|
531
|
-
} else {
|
|
532
|
-
console.warn('[useWuEvents] Wu Framework not available');
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
const on = (event, callback) => {
|
|
537
|
-
const wu = getWuInstance();
|
|
538
|
-
if (wu?.eventBus) {
|
|
539
|
-
const unsubscribe = wu.eventBus.on(event, callback);
|
|
540
|
-
subscriptions.push(unsubscribe);
|
|
541
|
-
return unsubscribe;
|
|
542
|
-
}
|
|
543
|
-
console.warn('[useWuEvents] Wu Framework not available');
|
|
544
|
-
return () => {};
|
|
545
|
-
};
|
|
546
|
-
|
|
547
|
-
const once = (event, callback) => {
|
|
548
|
-
const wu = getWuInstance();
|
|
549
|
-
if (wu?.eventBus) {
|
|
550
|
-
return wu.eventBus.once(event, callback);
|
|
551
|
-
}
|
|
552
|
-
return () => {};
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
const off = (event, callback) => {
|
|
556
|
-
const wu = getWuInstance();
|
|
557
|
-
if (wu?.eventBus) {
|
|
558
|
-
wu.eventBus.off(event, callback);
|
|
559
|
-
}
|
|
560
|
-
};
|
|
561
|
-
|
|
562
|
-
const cleanup = () => {
|
|
563
|
-
subscriptions.forEach(unsub => unsub());
|
|
564
|
-
subscriptions.length = 0;
|
|
565
|
-
};
|
|
566
|
-
|
|
567
|
-
return { emit, on, once, off, cleanup };
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* Crea la configuración para un componente WuSlot en Svelte
|
|
572
|
-
* Retorna el código del componente que se puede usar como referencia
|
|
573
|
-
*
|
|
574
|
-
* @example
|
|
575
|
-
* // WuSlot.svelte - Crear manualmente basado en esta configuración
|
|
576
|
-
* const config = createWuSlotConfig();
|
|
577
|
-
* // Usar config.template como base para el componente
|
|
578
|
-
*/
|
|
579
|
-
function createWuSlotConfig() {
|
|
580
|
-
return {
|
|
581
|
-
props: ['name', 'url', 'appName', 'fallbackText'],
|
|
582
|
-
|
|
583
|
-
template: `
|
|
584
|
-
<script>
|
|
585
|
-
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
|
|
586
|
-
import { getWuInstance } from 'wu-framework/adapters/svelte';
|
|
587
|
-
|
|
588
|
-
export let name;
|
|
589
|
-
export let url;
|
|
590
|
-
export let appName = null;
|
|
591
|
-
export let fallbackText = null;
|
|
592
|
-
|
|
593
|
-
const dispatch = createEventDispatcher();
|
|
594
|
-
|
|
595
|
-
let container;
|
|
596
|
-
let loading = true;
|
|
597
|
-
let error = null;
|
|
598
|
-
let appInstance = null;
|
|
599
|
-
|
|
600
|
-
$: actualAppName = appName || name;
|
|
601
|
-
|
|
602
|
-
onMount(async () => {
|
|
603
|
-
await mountMicrofrontend();
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
onDestroy(() => {
|
|
607
|
-
unmountMicrofrontend();
|
|
608
|
-
});
|
|
609
|
-
|
|
610
|
-
async function mountMicrofrontend() {
|
|
611
|
-
try {
|
|
612
|
-
loading = true;
|
|
613
|
-
error = null;
|
|
614
|
-
|
|
615
|
-
const wu = getWuInstance();
|
|
616
|
-
if (!wu) {
|
|
617
|
-
throw new Error('Wu Framework not initialized');
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
const containerId = \`wu-slot-\${actualAppName}-\${Date.now()}\`;
|
|
621
|
-
const innerContainer = document.createElement('div');
|
|
622
|
-
innerContainer.id = containerId;
|
|
623
|
-
innerContainer.style.width = '100%';
|
|
624
|
-
innerContainer.style.height = '100%';
|
|
625
|
-
|
|
626
|
-
container.innerHTML = '';
|
|
627
|
-
container.appendChild(innerContainer);
|
|
628
|
-
|
|
629
|
-
const app = wu.app(actualAppName, {
|
|
630
|
-
url,
|
|
631
|
-
container: \`#\${containerId}\`,
|
|
632
|
-
autoInit: true
|
|
633
|
-
});
|
|
634
|
-
|
|
635
|
-
appInstance = app;
|
|
636
|
-
await app.mount();
|
|
637
|
-
|
|
638
|
-
loading = false;
|
|
639
|
-
dispatch('load', { name: actualAppName, url });
|
|
640
|
-
dispatch('mount', { name: actualAppName, container: innerContainer });
|
|
641
|
-
|
|
642
|
-
} catch (err) {
|
|
643
|
-
console.error(\`[WuSlot] Error loading \${actualAppName}:\`, err);
|
|
644
|
-
error = err.message || 'Failed to load microfrontend';
|
|
645
|
-
loading = false;
|
|
646
|
-
dispatch('error', err);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
async function unmountMicrofrontend() {
|
|
651
|
-
if (appInstance) {
|
|
652
|
-
dispatch('unmount', { name: actualAppName });
|
|
653
|
-
|
|
654
|
-
try {
|
|
655
|
-
await appInstance.unmount();
|
|
656
|
-
} catch (err) {
|
|
657
|
-
console.warn(\`[WuSlot] Error unmounting \${actualAppName}:\`, err);
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
appInstance = null;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
</script>
|
|
664
|
-
|
|
665
|
-
<div
|
|
666
|
-
bind:this={container}
|
|
667
|
-
class="wu-slot"
|
|
668
|
-
class:wu-slot-loading={loading}
|
|
669
|
-
class:wu-slot-error={error}
|
|
670
|
-
data-wu-app={actualAppName}
|
|
671
|
-
data-wu-url={url}
|
|
672
|
-
style="min-height: 100px; position: relative;">
|
|
673
|
-
|
|
674
|
-
{#if error}
|
|
675
|
-
<div class="wu-slot-error-message"
|
|
676
|
-
style="padding: 1rem; border: 1px solid #f5c6cb; border-radius: 4px; background: #f8d7da; color: #721c24;">
|
|
677
|
-
<strong>Error loading {name}</strong>
|
|
678
|
-
<p style="margin: 0.5rem 0 0 0;">{error}</p>
|
|
679
|
-
</div>
|
|
680
|
-
{:else if loading}
|
|
681
|
-
<div class="wu-slot-loading-message"
|
|
682
|
-
style="display: flex; align-items: center; justify-content: center; padding: 2rem; color: #666;">
|
|
683
|
-
{fallbackText || \`Loading \${name}...\`}
|
|
684
|
-
</div>
|
|
685
|
-
{/if}
|
|
686
|
-
</div>
|
|
687
|
-
|
|
688
|
-
<style>
|
|
689
|
-
.wu-slot {
|
|
690
|
-
width: 100%;
|
|
691
|
-
min-height: 100px;
|
|
692
|
-
}
|
|
693
|
-
</style>
|
|
694
|
-
`.trim(),
|
|
695
|
-
|
|
696
|
-
// Implementación JavaScript pura para usar sin .svelte
|
|
697
|
-
createInstance: (target, props) => {
|
|
698
|
-
let container = document.createElement('div');
|
|
699
|
-
container.className = 'wu-slot';
|
|
700
|
-
container.style.minHeight = '100px';
|
|
701
|
-
container.style.position = 'relative';
|
|
702
|
-
target.appendChild(container);
|
|
703
|
-
|
|
704
|
-
let loading = true;
|
|
705
|
-
let error = null;
|
|
706
|
-
let appInstance = null;
|
|
707
|
-
|
|
708
|
-
const actualAppName = props.appName || props.name;
|
|
709
|
-
|
|
710
|
-
const updateUI = () => {
|
|
711
|
-
if (error) {
|
|
712
|
-
container.innerHTML = `
|
|
713
|
-
<div style="padding: 1rem; border: 1px solid #f5c6cb; border-radius: 4px; background: #f8d7da; color: #721c24;">
|
|
714
|
-
<strong>Error loading ${props.name}</strong>
|
|
715
|
-
<p style="margin: 0.5rem 0 0 0;">${error}</p>
|
|
716
|
-
</div>
|
|
717
|
-
`;
|
|
718
|
-
} else if (loading) {
|
|
719
|
-
container.innerHTML = `
|
|
720
|
-
<div style="display: flex; align-items: center; justify-content: center; padding: 2rem; color: #666;">
|
|
721
|
-
${props.fallbackText || `Loading ${props.name}...`}
|
|
722
|
-
</div>
|
|
723
|
-
`;
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
|
-
|
|
727
|
-
const mount = async () => {
|
|
728
|
-
try {
|
|
729
|
-
updateUI();
|
|
730
|
-
|
|
731
|
-
const wu = getWuInstance();
|
|
732
|
-
if (!wu) throw new Error('Wu Framework not initialized');
|
|
733
|
-
|
|
734
|
-
const containerId = `wu-slot-${actualAppName}-${Date.now()}`;
|
|
735
|
-
const innerContainer = document.createElement('div');
|
|
736
|
-
innerContainer.id = containerId;
|
|
737
|
-
innerContainer.style.cssText = 'width: 100%; height: 100%;';
|
|
738
|
-
|
|
739
|
-
container.innerHTML = '';
|
|
740
|
-
container.appendChild(innerContainer);
|
|
741
|
-
|
|
742
|
-
const app = wu.app(actualAppName, {
|
|
743
|
-
url: props.url,
|
|
744
|
-
container: `#${containerId}`,
|
|
745
|
-
autoInit: true
|
|
746
|
-
});
|
|
747
|
-
|
|
748
|
-
appInstance = app;
|
|
749
|
-
await app.mount();
|
|
750
|
-
|
|
751
|
-
loading = false;
|
|
752
|
-
if (props.onLoad) props.onLoad({ name: actualAppName, url: props.url });
|
|
753
|
-
|
|
754
|
-
} catch (err) {
|
|
755
|
-
error = err.message;
|
|
756
|
-
loading = false;
|
|
757
|
-
updateUI();
|
|
758
|
-
if (props.onError) props.onError(err);
|
|
759
|
-
}
|
|
760
|
-
};
|
|
761
|
-
|
|
762
|
-
const destroy = async () => {
|
|
763
|
-
if (appInstance) {
|
|
764
|
-
try {
|
|
765
|
-
await appInstance.unmount();
|
|
766
|
-
} catch (e) {}
|
|
767
|
-
appInstance = null;
|
|
768
|
-
}
|
|
769
|
-
container.remove();
|
|
770
|
-
};
|
|
771
|
-
|
|
772
|
-
mount();
|
|
773
|
-
|
|
774
|
-
return { destroy };
|
|
775
|
-
}
|
|
776
|
-
};
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
// API pública del adapter
|
|
780
|
-
export const wuSvelte = {
|
|
781
|
-
register,
|
|
782
|
-
registerSvelte5,
|
|
783
|
-
createWuStore,
|
|
784
|
-
createWuEventStore,
|
|
785
|
-
useWuEvents,
|
|
786
|
-
createWuSlotConfig,
|
|
787
|
-
getWuInstance,
|
|
788
|
-
waitForWu
|
|
789
|
-
};
|
|
790
|
-
|
|
791
|
-
// Named exports para conveniencia
|
|
792
|
-
export {
|
|
793
|
-
register,
|
|
794
|
-
registerSvelte5,
|
|
795
|
-
createWuStore,
|
|
796
|
-
createWuEventStore,
|
|
797
|
-
useWuEvents,
|
|
798
|
-
createWuSlotConfig,
|
|
799
|
-
getWuInstance,
|
|
800
|
-
waitForWu
|
|
801
|
-
};
|
|
802
|
-
|
|
803
|
-
export default wuSvelte;
|
|
1
|
+
// Re-export from folder structure — backward compatibility
|
|
2
|
+
export * from './svelte/index.js';
|
|
3
|
+
export { default } from './svelte/index.js';
|