wu-framework 1.1.6 → 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 +94 -74
- 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/react.js
CHANGED
|
@@ -1,513 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
* Simplifica la integración de React con Wu Framework.
|
|
5
|
-
* Convierte componentes React en microfrontends con UNA línea de código.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* // Microfrontend (main.tsx)
|
|
9
|
-
* import { wuReact } from 'wu-framework/adapters/react';
|
|
10
|
-
* import App from './App';
|
|
11
|
-
*
|
|
12
|
-
* wuReact.register('my-app', App);
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* // Shell (cargar microfrontend)
|
|
16
|
-
* import { WuSlot } from 'wu-framework/adapters/react';
|
|
17
|
-
*
|
|
18
|
-
* <WuSlot name="my-app" url="http://localhost:3001" />
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
// Estado global del adapter
|
|
22
|
-
const adapterState = {
|
|
23
|
-
roots: new Map(),
|
|
24
|
-
React: null,
|
|
25
|
-
ReactDOM: null,
|
|
26
|
-
createRoot: null,
|
|
27
|
-
initialized: false
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Detecta y obtiene React del contexto global o lo importa
|
|
32
|
-
*/
|
|
33
|
-
async function ensureReact() {
|
|
34
|
-
if (adapterState.initialized) return true;
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
// Intentar obtener de window (común en microfrontends)
|
|
38
|
-
if (typeof window !== 'undefined') {
|
|
39
|
-
if (window.React && window.ReactDOM) {
|
|
40
|
-
adapterState.React = window.React;
|
|
41
|
-
adapterState.ReactDOM = window.ReactDOM;
|
|
42
|
-
adapterState.createRoot = window.ReactDOM.createRoot;
|
|
43
|
-
adapterState.initialized = true;
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Intentar import dinámico
|
|
49
|
-
const [React, ReactDOM] = await Promise.all([
|
|
50
|
-
import('react'),
|
|
51
|
-
import('react-dom/client')
|
|
52
|
-
]);
|
|
53
|
-
|
|
54
|
-
adapterState.React = React.default || React;
|
|
55
|
-
adapterState.ReactDOM = ReactDOM;
|
|
56
|
-
adapterState.createRoot = ReactDOM.createRoot;
|
|
57
|
-
adapterState.initialized = true;
|
|
58
|
-
return true;
|
|
59
|
-
|
|
60
|
-
} catch (error) {
|
|
61
|
-
console.error('[WuReact] Failed to load React:', error);
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Obtiene la instancia de Wu Framework
|
|
68
|
-
*/
|
|
69
|
-
function getWuInstance() {
|
|
70
|
-
if (typeof window === 'undefined') return null;
|
|
71
|
-
|
|
72
|
-
return window.wu
|
|
73
|
-
|| window.parent?.wu
|
|
74
|
-
|| window.top?.wu
|
|
75
|
-
|| null;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Espera a que Wu Framework esté disponible (sin polling agresivo)
|
|
80
|
-
*/
|
|
81
|
-
function waitForWu(timeout = 5000) {
|
|
82
|
-
return new Promise((resolve, reject) => {
|
|
83
|
-
// Check inmediato
|
|
84
|
-
const wu = getWuInstance();
|
|
85
|
-
if (wu) {
|
|
86
|
-
resolve(wu);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Usar MutationObserver + evento en lugar de polling
|
|
91
|
-
const startTime = Date.now();
|
|
92
|
-
|
|
93
|
-
// Escuchar evento de Wu Framework
|
|
94
|
-
const handleWuReady = (event) => {
|
|
95
|
-
cleanup();
|
|
96
|
-
resolve(getWuInstance());
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
window.addEventListener('wu:ready', handleWuReady);
|
|
100
|
-
window.addEventListener('wu:app:ready', handleWuReady);
|
|
101
|
-
|
|
102
|
-
// Fallback con polling conservador (cada 200ms, no 100ms)
|
|
103
|
-
const checkInterval = setInterval(() => {
|
|
104
|
-
const wu = getWuInstance();
|
|
105
|
-
if (wu) {
|
|
106
|
-
cleanup();
|
|
107
|
-
resolve(wu);
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (Date.now() - startTime > timeout) {
|
|
112
|
-
cleanup();
|
|
113
|
-
reject(new Error(`Wu Framework not found after ${timeout}ms`));
|
|
114
|
-
}
|
|
115
|
-
}, 200);
|
|
116
|
-
|
|
117
|
-
function cleanup() {
|
|
118
|
-
clearInterval(checkInterval);
|
|
119
|
-
window.removeEventListener('wu:ready', handleWuReady);
|
|
120
|
-
window.removeEventListener('wu:app:ready', handleWuReady);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Registra un componente React como microfrontend
|
|
127
|
-
*
|
|
128
|
-
* @param {string} appName - Nombre único del microfrontend (debe coincidir con wu.json)
|
|
129
|
-
* @param {React.ComponentType} Component - Componente React principal
|
|
130
|
-
* @param {Object} options - Opciones adicionales
|
|
131
|
-
* @param {boolean} options.strictMode - Envolver en StrictMode (default: true)
|
|
132
|
-
* @param {Object} options.props - Props iniciales para el componente
|
|
133
|
-
* @param {Function} options.onMount - Callback después de montar
|
|
134
|
-
* @param {Function} options.onUnmount - Callback antes de desmontar
|
|
135
|
-
* @param {boolean} options.standalone - Permitir ejecución standalone (default: true)
|
|
136
|
-
* @param {string} options.standaloneContainer - Selector para modo standalone (default: '#root')
|
|
137
|
-
*/
|
|
138
|
-
async function register(appName, Component, options = {}) {
|
|
139
|
-
const {
|
|
140
|
-
strictMode = true,
|
|
141
|
-
props = {},
|
|
142
|
-
onMount = null,
|
|
143
|
-
onUnmount = null,
|
|
144
|
-
standalone = true,
|
|
145
|
-
standaloneContainer = '#root'
|
|
146
|
-
} = options;
|
|
147
|
-
|
|
148
|
-
// Asegurar que React está disponible
|
|
149
|
-
const hasReact = await ensureReact();
|
|
150
|
-
if (!hasReact) {
|
|
151
|
-
console.error(`[WuReact] Cannot register ${appName}: React not available`);
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const { React, createRoot } = adapterState;
|
|
156
|
-
|
|
157
|
-
// Función de mount interna
|
|
158
|
-
const mountApp = (container) => {
|
|
159
|
-
if (!container) {
|
|
160
|
-
console.error(`[WuReact] Mount failed for ${appName}: container is null`);
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Evitar doble mount
|
|
165
|
-
if (adapterState.roots.has(appName)) {
|
|
166
|
-
console.warn(`[WuReact] ${appName} already mounted, unmounting first`);
|
|
167
|
-
unmountApp();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
try {
|
|
171
|
-
const root = createRoot(container);
|
|
172
|
-
|
|
173
|
-
// Crear elemento con o sin StrictMode
|
|
174
|
-
let element = React.createElement(Component, props);
|
|
175
|
-
if (strictMode && React.StrictMode) {
|
|
176
|
-
element = React.createElement(React.StrictMode, null, element);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
root.render(element);
|
|
180
|
-
adapterState.roots.set(appName, { root, container });
|
|
181
|
-
|
|
182
|
-
console.log(`[WuReact] ✅ ${appName} mounted successfully`);
|
|
183
|
-
|
|
184
|
-
if (onMount) {
|
|
185
|
-
onMount(container);
|
|
186
|
-
}
|
|
187
|
-
} catch (error) {
|
|
188
|
-
console.error(`[WuReact] Mount error for ${appName}:`, error);
|
|
189
|
-
throw error;
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
// Función de unmount interna
|
|
194
|
-
const unmountApp = (container) => {
|
|
195
|
-
const instance = adapterState.roots.get(appName);
|
|
196
|
-
|
|
197
|
-
if (instance) {
|
|
198
|
-
try {
|
|
199
|
-
if (onUnmount) {
|
|
200
|
-
onUnmount(instance.container);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
instance.root.unmount();
|
|
204
|
-
adapterState.roots.delete(appName);
|
|
205
|
-
|
|
206
|
-
console.log(`[WuReact] ✅ ${appName} unmounted successfully`);
|
|
207
|
-
} catch (error) {
|
|
208
|
-
console.error(`[WuReact] Unmount error for ${appName}:`, error);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Limpiar container si se proporciona
|
|
213
|
-
if (container) {
|
|
214
|
-
container.innerHTML = '';
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
// Intentar registrar con Wu Framework
|
|
219
|
-
try {
|
|
220
|
-
const wu = await waitForWu(3000);
|
|
221
|
-
|
|
222
|
-
wu.define(appName, {
|
|
223
|
-
mount: mountApp,
|
|
224
|
-
unmount: unmountApp
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
console.log(`[WuReact] ✅ ${appName} registered with Wu Framework`);
|
|
228
|
-
return true;
|
|
229
|
-
|
|
230
|
-
} catch (error) {
|
|
231
|
-
// Wu no disponible
|
|
232
|
-
console.warn(`[WuReact] Wu Framework not available for ${appName}`);
|
|
233
|
-
|
|
234
|
-
// Modo standalone si está habilitado
|
|
235
|
-
if (standalone) {
|
|
236
|
-
const containerElement = document.querySelector(standaloneContainer);
|
|
237
|
-
|
|
238
|
-
if (containerElement) {
|
|
239
|
-
console.log(`[WuReact] Running ${appName} in standalone mode`);
|
|
240
|
-
mountApp(containerElement);
|
|
241
|
-
return true;
|
|
242
|
-
} else {
|
|
243
|
-
console.warn(`[WuReact] Standalone container ${standaloneContainer} not found`);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return false;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Crea un componente React para cargar microfrontends (para el Shell)
|
|
253
|
-
*
|
|
254
|
-
* @example
|
|
255
|
-
* import { createWuSlot } from 'wu-framework/adapters/react';
|
|
256
|
-
* const WuSlot = createWuSlot(React);
|
|
257
|
-
*
|
|
258
|
-
* <WuSlot name="my-app" url="http://localhost:3001" />
|
|
259
|
-
*/
|
|
260
|
-
function createWuSlot(React) {
|
|
261
|
-
const { useState, useEffect, useRef, useCallback } = React;
|
|
262
|
-
|
|
263
|
-
return function WuSlot({
|
|
264
|
-
name,
|
|
265
|
-
url,
|
|
266
|
-
appName = null,
|
|
267
|
-
fallback = null,
|
|
268
|
-
onLoad = null,
|
|
269
|
-
onError = null,
|
|
270
|
-
onMount = null,
|
|
271
|
-
onUnmount = null,
|
|
272
|
-
className = '',
|
|
273
|
-
style = {},
|
|
274
|
-
...props
|
|
275
|
-
}) {
|
|
276
|
-
const containerRef = useRef(null);
|
|
277
|
-
const appInstanceRef = useRef(null);
|
|
278
|
-
const [loading, setLoading] = useState(true);
|
|
279
|
-
const [error, setError] = useState(null);
|
|
280
|
-
|
|
281
|
-
const actualAppName = appName || name;
|
|
282
|
-
|
|
283
|
-
const mountMicrofrontend = useCallback(async () => {
|
|
284
|
-
if (!containerRef.current) return;
|
|
285
|
-
|
|
286
|
-
try {
|
|
287
|
-
setLoading(true);
|
|
288
|
-
setError(null);
|
|
289
|
-
|
|
290
|
-
const wu = getWuInstance();
|
|
291
|
-
if (!wu) {
|
|
292
|
-
throw new Error('Wu Framework not initialized');
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// Crear container interno
|
|
296
|
-
const containerId = `wu-slot-${actualAppName}-${Date.now()}`;
|
|
297
|
-
const innerContainer = document.createElement('div');
|
|
298
|
-
innerContainer.id = containerId;
|
|
299
|
-
innerContainer.style.width = '100%';
|
|
300
|
-
innerContainer.style.height = '100%';
|
|
301
|
-
containerRef.current.innerHTML = '';
|
|
302
|
-
containerRef.current.appendChild(innerContainer);
|
|
303
|
-
|
|
304
|
-
// Crear y montar la app
|
|
305
|
-
const app = wu.app(actualAppName, {
|
|
306
|
-
url,
|
|
307
|
-
container: `#${containerId}`,
|
|
308
|
-
autoInit: true
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
appInstanceRef.current = app;
|
|
312
|
-
await app.mount();
|
|
313
|
-
|
|
314
|
-
setLoading(false);
|
|
315
|
-
|
|
316
|
-
if (onLoad) onLoad({ name: actualAppName, url });
|
|
317
|
-
if (onMount) onMount({ name: actualAppName, container: innerContainer });
|
|
318
|
-
|
|
319
|
-
} catch (err) {
|
|
320
|
-
console.error(`[WuSlot] Error loading ${actualAppName}:`, err);
|
|
321
|
-
setError(err.message || 'Failed to load microfrontend');
|
|
322
|
-
setLoading(false);
|
|
323
|
-
|
|
324
|
-
if (onError) onError(err);
|
|
325
|
-
}
|
|
326
|
-
}, [actualAppName, url, onLoad, onError, onMount]);
|
|
327
|
-
|
|
328
|
-
useEffect(() => {
|
|
329
|
-
mountMicrofrontend();
|
|
330
|
-
|
|
331
|
-
return () => {
|
|
332
|
-
if (appInstanceRef.current) {
|
|
333
|
-
if (onUnmount) onUnmount({ name: actualAppName });
|
|
334
|
-
|
|
335
|
-
appInstanceRef.current.unmount().catch(err => {
|
|
336
|
-
console.warn(`[WuSlot] Error unmounting ${actualAppName}:`, err);
|
|
337
|
-
});
|
|
338
|
-
appInstanceRef.current = null;
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
}, [mountMicrofrontend, actualAppName, onUnmount]);
|
|
342
|
-
|
|
343
|
-
// Render de error
|
|
344
|
-
if (error) {
|
|
345
|
-
return React.createElement('div', {
|
|
346
|
-
className: `wu-slot wu-slot-error ${className}`,
|
|
347
|
-
style: {
|
|
348
|
-
padding: '1rem',
|
|
349
|
-
border: '1px solid #f5c6cb',
|
|
350
|
-
borderRadius: '4px',
|
|
351
|
-
backgroundColor: '#f8d7da',
|
|
352
|
-
color: '#721c24',
|
|
353
|
-
...style
|
|
354
|
-
},
|
|
355
|
-
...props
|
|
356
|
-
}, [
|
|
357
|
-
React.createElement('strong', { key: 'title' }, `Error loading ${name}`),
|
|
358
|
-
React.createElement('p', { key: 'message', style: { margin: '0.5rem 0 0 0' } }, error)
|
|
359
|
-
]);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// Render principal
|
|
363
|
-
return React.createElement('div', {
|
|
364
|
-
ref: containerRef,
|
|
365
|
-
className: `wu-slot ${loading ? 'wu-slot-loading' : 'wu-slot-loaded'} ${className}`,
|
|
366
|
-
style: {
|
|
367
|
-
minHeight: '100px',
|
|
368
|
-
position: 'relative',
|
|
369
|
-
...style
|
|
370
|
-
},
|
|
371
|
-
'data-wu-app': actualAppName,
|
|
372
|
-
'data-wu-url': url,
|
|
373
|
-
...props
|
|
374
|
-
}, loading && (fallback || React.createElement('div', {
|
|
375
|
-
style: {
|
|
376
|
-
display: 'flex',
|
|
377
|
-
alignItems: 'center',
|
|
378
|
-
justifyContent: 'center',
|
|
379
|
-
padding: '2rem',
|
|
380
|
-
color: '#666'
|
|
381
|
-
}
|
|
382
|
-
}, `Loading ${name}...`)));
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Hook para usar el EventBus de Wu Framework en React
|
|
388
|
-
*
|
|
389
|
-
* @example
|
|
390
|
-
* const { emit, on } = useWuEvents();
|
|
391
|
-
*
|
|
392
|
-
* useEffect(() => {
|
|
393
|
-
* const unsub = on('user:login', (data) => console.log(data));
|
|
394
|
-
* return unsub;
|
|
395
|
-
* }, [on]);
|
|
396
|
-
*/
|
|
397
|
-
function createUseWuEvents(React) {
|
|
398
|
-
const { useCallback, useEffect, useRef } = React;
|
|
399
|
-
|
|
400
|
-
return function useWuEvents() {
|
|
401
|
-
const subscriptionsRef = useRef([]);
|
|
402
|
-
|
|
403
|
-
const emit = useCallback((event, data, options) => {
|
|
404
|
-
const wu = getWuInstance();
|
|
405
|
-
if (wu?.eventBus) {
|
|
406
|
-
wu.eventBus.emit(event, data, options);
|
|
407
|
-
} else {
|
|
408
|
-
console.warn('[useWuEvents] Wu Framework not available');
|
|
409
|
-
}
|
|
410
|
-
}, []);
|
|
411
|
-
|
|
412
|
-
const on = useCallback((event, callback) => {
|
|
413
|
-
const wu = getWuInstance();
|
|
414
|
-
if (wu?.eventBus) {
|
|
415
|
-
const unsubscribe = wu.eventBus.on(event, callback);
|
|
416
|
-
subscriptionsRef.current.push(unsubscribe);
|
|
417
|
-
return unsubscribe;
|
|
418
|
-
}
|
|
419
|
-
console.warn('[useWuEvents] Wu Framework not available');
|
|
420
|
-
return () => {};
|
|
421
|
-
}, []);
|
|
422
|
-
|
|
423
|
-
const once = useCallback((event, callback) => {
|
|
424
|
-
const wu = getWuInstance();
|
|
425
|
-
if (wu?.eventBus) {
|
|
426
|
-
return wu.eventBus.once(event, callback);
|
|
427
|
-
}
|
|
428
|
-
console.warn('[useWuEvents] Wu Framework not available');
|
|
429
|
-
return () => {};
|
|
430
|
-
}, []);
|
|
431
|
-
|
|
432
|
-
// Cleanup on unmount
|
|
433
|
-
useEffect(() => {
|
|
434
|
-
return () => {
|
|
435
|
-
subscriptionsRef.current.forEach(unsub => unsub());
|
|
436
|
-
subscriptionsRef.current = [];
|
|
437
|
-
};
|
|
438
|
-
}, []);
|
|
439
|
-
|
|
440
|
-
return { emit, on, once };
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
* Hook para usar el Store de Wu Framework en React
|
|
446
|
-
*
|
|
447
|
-
* @example
|
|
448
|
-
* const { state, setState, subscribe } = useWuStore('user');
|
|
449
|
-
*/
|
|
450
|
-
function createUseWuStore(React) {
|
|
451
|
-
const { useState, useCallback, useEffect } = React;
|
|
452
|
-
|
|
453
|
-
return function useWuStore(namespace = '') {
|
|
454
|
-
const [state, setLocalState] = useState(() => {
|
|
455
|
-
const wu = getWuInstance();
|
|
456
|
-
return wu?.store?.get(namespace) || null;
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
const setState = useCallback((path, value) => {
|
|
460
|
-
const wu = getWuInstance();
|
|
461
|
-
if (wu?.store) {
|
|
462
|
-
const fullPath = namespace ? `${namespace}.${path}` : path;
|
|
463
|
-
wu.store.set(fullPath, value);
|
|
464
|
-
}
|
|
465
|
-
}, [namespace]);
|
|
466
|
-
|
|
467
|
-
const getState = useCallback((path = '') => {
|
|
468
|
-
const wu = getWuInstance();
|
|
469
|
-
if (wu?.store) {
|
|
470
|
-
const fullPath = namespace ? (path ? `${namespace}.${path}` : namespace) : path;
|
|
471
|
-
return wu.store.get(fullPath);
|
|
472
|
-
}
|
|
473
|
-
return null;
|
|
474
|
-
}, [namespace]);
|
|
475
|
-
|
|
476
|
-
// Subscribe to changes
|
|
477
|
-
useEffect(() => {
|
|
478
|
-
const wu = getWuInstance();
|
|
479
|
-
if (!wu?.store) return;
|
|
480
|
-
|
|
481
|
-
const pattern = namespace ? `${namespace}.*` : '*';
|
|
482
|
-
const unsubscribe = wu.store.on(pattern, () => {
|
|
483
|
-
setLocalState(wu.store.get(namespace));
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
return unsubscribe;
|
|
487
|
-
}, [namespace]);
|
|
488
|
-
|
|
489
|
-
return { state, setState, getState };
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
// API pública del adapter
|
|
494
|
-
export const wuReact = {
|
|
495
|
-
register,
|
|
496
|
-
createWuSlot,
|
|
497
|
-
createUseWuEvents,
|
|
498
|
-
createUseWuStore,
|
|
499
|
-
getWuInstance,
|
|
500
|
-
waitForWu
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
// Named exports para conveniencia
|
|
504
|
-
export {
|
|
505
|
-
register,
|
|
506
|
-
createWuSlot,
|
|
507
|
-
createUseWuEvents,
|
|
508
|
-
createUseWuStore,
|
|
509
|
-
getWuInstance,
|
|
510
|
-
waitForWu
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
export default wuReact;
|
|
1
|
+
// Re-export from folder structure — backward compatibility
|
|
2
|
+
export * from './react/index.js';
|
|
3
|
+
export { default } from './react/index.js';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WU-FRAMEWORK ADAPTERS — Shared Utilities
|
|
3
|
+
*
|
|
4
|
+
* Common functions used across all framework adapters.
|
|
5
|
+
* Extracted to avoid duplication.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get the Wu Framework instance from window or parent frames.
|
|
10
|
+
* @returns {object|null}
|
|
11
|
+
*/
|
|
12
|
+
export function getWuInstance() {
|
|
13
|
+
if (typeof window === 'undefined') return null;
|
|
14
|
+
|
|
15
|
+
return window.wu
|
|
16
|
+
|| window.parent?.wu
|
|
17
|
+
|| window.top?.wu
|
|
18
|
+
|| null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Wait for Wu Framework to become available.
|
|
23
|
+
* @param {number} timeout - Timeout in ms (default 5000)
|
|
24
|
+
* @returns {Promise<object>}
|
|
25
|
+
*/
|
|
26
|
+
export function waitForWu(timeout = 5000) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
const wu = getWuInstance();
|
|
29
|
+
if (wu) {
|
|
30
|
+
resolve(wu);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const startTime = Date.now();
|
|
35
|
+
|
|
36
|
+
const handleWuReady = () => {
|
|
37
|
+
cleanup();
|
|
38
|
+
resolve(getWuInstance());
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
window.addEventListener('wu:ready', handleWuReady);
|
|
42
|
+
window.addEventListener('wu:app:ready', handleWuReady);
|
|
43
|
+
|
|
44
|
+
const checkInterval = setInterval(() => {
|
|
45
|
+
const wu = getWuInstance();
|
|
46
|
+
if (wu) {
|
|
47
|
+
cleanup();
|
|
48
|
+
resolve(wu);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (Date.now() - startTime > timeout) {
|
|
53
|
+
cleanup();
|
|
54
|
+
reject(new Error(`Wu Framework not found after ${timeout}ms`));
|
|
55
|
+
}
|
|
56
|
+
}, 200);
|
|
57
|
+
|
|
58
|
+
function cleanup() {
|
|
59
|
+
clearInterval(checkInterval);
|
|
60
|
+
window.removeEventListener('wu:ready', handleWuReady);
|
|
61
|
+
window.removeEventListener('wu:app:ready', handleWuReady);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WU-FRAMEWORK SOLID AI INTEGRATION
|
|
3
|
+
*/
|
|
4
|
+
function getWuInstance() {
|
|
5
|
+
if (typeof window === 'undefined') return null;
|
|
6
|
+
return window.wu || window.parent?.wu || window.top?.wu || null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function createUseWuAI() {
|
|
10
|
+
return function useWuAI(options = {}) {
|
|
11
|
+
const { namespace = 'default' } = options;
|
|
12
|
+
const state = { messages: [], isStreaming: false, error: null };
|
|
13
|
+
return {
|
|
14
|
+
messages: () => state.messages,
|
|
15
|
+
isStreaming: () => state.isStreaming,
|
|
16
|
+
error: () => state.error,
|
|
17
|
+
async send(text) {
|
|
18
|
+
if (!text?.trim()) return;
|
|
19
|
+
const wu = getWuInstance();
|
|
20
|
+
if (!wu?.ai) { state.error = 'Wu AI not available'; return; }
|
|
21
|
+
state.messages = [...state.messages, { id: `user-${Date.now()}`, role: 'user', content: text, timestamp: Date.now() }];
|
|
22
|
+
state.isStreaming = true; state.error = null;
|
|
23
|
+
try {
|
|
24
|
+
const res = await wu.ai.send(text, { namespace });
|
|
25
|
+
state.messages = [...state.messages, { id: `assistant-${Date.now()}`, role: 'assistant', content: res.content, timestamp: Date.now() }];
|
|
26
|
+
} catch (err) { state.error = err.message; }
|
|
27
|
+
state.isStreaming = false;
|
|
28
|
+
},
|
|
29
|
+
clear() { state.messages = []; state.error = null; },
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🚀 WU-FRAMEWORK SOLID.JS ADAPTER - TypeScript Declarations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { WuCore } from '../core/wu-core';
|
|
6
|
+
|
|
7
|
+
// Solid types (generics to avoid hard dependency)
|
|
8
|
+
type Component<P = {}> = (props: P) => any;
|
|
9
|
+
type Accessor<T> = () => T;
|
|
10
|
+
type Setter<T> = (value: T | ((prev: T) => T)) => T;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Opciones de registro Solid
|
|
14
|
+
*/
|
|
15
|
+
export interface SolidRegisterOptions {
|
|
16
|
+
/** Props iniciales */
|
|
17
|
+
props?: Record<string, any>;
|
|
18
|
+
/** Callback después de montar */
|
|
19
|
+
onMount?: (container: HTMLElement) => void;
|
|
20
|
+
/** Callback antes de desmontar */
|
|
21
|
+
onUnmount?: (container: HTMLElement) => void;
|
|
22
|
+
/** Permitir ejecución standalone */
|
|
23
|
+
standalone?: boolean;
|
|
24
|
+
/** Selector para modo standalone */
|
|
25
|
+
standaloneContainer?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Props del componente WuSlot
|
|
30
|
+
*/
|
|
31
|
+
export interface WuSlotProps {
|
|
32
|
+
name: string;
|
|
33
|
+
url: string;
|
|
34
|
+
appName?: string;
|
|
35
|
+
fallback?: string;
|
|
36
|
+
onLoad?: (data: { name: string; url: string }) => void;
|
|
37
|
+
onError?: (error: Error) => void;
|
|
38
|
+
class?: string;
|
|
39
|
+
style?: Record<string, string | number>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Resultado de createWuStore
|
|
44
|
+
*/
|
|
45
|
+
export type WuStoreResult<T = any> = [
|
|
46
|
+
Accessor<T>,
|
|
47
|
+
(path: string, value: any) => void
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Helper de eventos Wu para Solid
|
|
52
|
+
*/
|
|
53
|
+
export interface UseWuEventsResult {
|
|
54
|
+
emit: (event: string, data?: any, options?: any) => void;
|
|
55
|
+
on: (event: string, callback: (data: any) => void) => () => void;
|
|
56
|
+
once: (event: string, callback: (data: any) => void) => () => void;
|
|
57
|
+
off: (event: string, callback: (data: any) => void) => void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Contexto de Wu
|
|
62
|
+
*/
|
|
63
|
+
export interface WuContextResult {
|
|
64
|
+
WuProvider: Component<{ children?: any }>;
|
|
65
|
+
useWu: () => WuCore | null;
|
|
66
|
+
WuContext: any;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function register(
|
|
70
|
+
appName: string,
|
|
71
|
+
Component: Component,
|
|
72
|
+
options?: SolidRegisterOptions
|
|
73
|
+
): Promise<boolean>;
|
|
74
|
+
|
|
75
|
+
export function createWuSlot(): Component<WuSlotProps>;
|
|
76
|
+
|
|
77
|
+
export function createWuStore<T = any>(namespace?: string): WuStoreResult<T>;
|
|
78
|
+
|
|
79
|
+
export function createWuEvent<T = any>(eventPattern: string): Accessor<T | null>;
|
|
80
|
+
|
|
81
|
+
export function useWuEvents(): UseWuEventsResult;
|
|
82
|
+
|
|
83
|
+
export function createWuContext(): WuContextResult;
|
|
84
|
+
|
|
85
|
+
export function getWuInstance(): WuCore | null;
|
|
86
|
+
|
|
87
|
+
export function waitForWu(timeout?: number): Promise<WuCore>;
|
|
88
|
+
|
|
89
|
+
export interface WuSolidAdapter {
|
|
90
|
+
register: typeof register;
|
|
91
|
+
createWuSlot: typeof createWuSlot;
|
|
92
|
+
createWuStore: typeof createWuStore;
|
|
93
|
+
createWuEvent: typeof createWuEvent;
|
|
94
|
+
useWuEvents: typeof useWuEvents;
|
|
95
|
+
createWuContext: typeof createWuContext;
|
|
96
|
+
getWuInstance: typeof getWuInstance;
|
|
97
|
+
waitForWu: typeof waitForWu;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export const wuSolid: WuSolidAdapter;
|
|
101
|
+
export default wuSolid;
|