wu-framework 1.1.17 → 1.1.19
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/LICENSE +39 -39
- package/README.md +460 -440
- package/integrations/astro/README.md +127 -127
- package/integrations/astro/WuApp.astro +63 -63
- package/integrations/astro/WuShell.astro +39 -39
- package/integrations/astro/index.js +68 -68
- package/integrations/astro/package.json +38 -38
- package/integrations/astro/types.d.ts +53 -53
- package/package.json +45 -2
- package/src/adapters/alpine/index.d.ts +60 -0
- package/src/adapters/alpine/index.js +231 -0
- package/src/adapters/alpine.d.ts +3 -0
- package/src/adapters/alpine.js +3 -0
- package/src/adapters/htmx/index.d.ts +60 -0
- package/src/adapters/htmx/index.js +242 -0
- package/src/adapters/htmx.d.ts +3 -0
- package/src/adapters/htmx.js +3 -0
- package/src/adapters/index.js +60 -3
- package/src/adapters/qwik/index.d.ts +52 -0
- package/src/adapters/qwik/index.js +50 -0
- package/src/adapters/qwik.d.ts +3 -0
- package/src/adapters/qwik.js +3 -0
- package/src/adapters/react/ai.js +135 -135
- package/src/adapters/react/index.d.ts +246 -246
- package/src/adapters/react/index.js +695 -695
- package/src/adapters/stencil/index.d.ts +54 -0
- package/src/adapters/stencil/index.js +228 -0
- package/src/adapters/stencil.d.ts +3 -0
- package/src/adapters/stencil.js +3 -0
- package/src/adapters/stimulus/index.d.ts +60 -0
- package/src/adapters/stimulus/index.js +255 -0
- package/src/adapters/stimulus.d.ts +3 -0
- package/src/adapters/stimulus.js +3 -0
- package/src/adapters/vue/index.js +8 -0
- package/dist/wu-framework.cjs.js +0 -3
- package/dist/wu-framework.cjs.js.map +0 -1
- package/dist/wu-framework.dev.js +0 -15667
- package/dist/wu-framework.dev.js.map +0 -1
- package/dist/wu-framework.esm.js +0 -3
- package/dist/wu-framework.esm.js.map +0 -1
- package/dist/wu-framework.umd.js +0 -3
- package/dist/wu-framework.umd.js.map +0 -1
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import type { AstroIntegration } from 'astro';
|
|
2
|
-
|
|
3
|
-
/** Configuration for a single wu micro-app. */
|
|
4
|
-
export interface WuAppConfig {
|
|
5
|
-
/** Unique name used to reference this micro-app. */
|
|
6
|
-
name: string;
|
|
7
|
-
/** URL or path from which the micro-app is loaded. */
|
|
8
|
-
url: string;
|
|
9
|
-
/** Loading strategy. Defaults to the framework default. */
|
|
10
|
-
strategy?: 'eager' | 'lazy' | 'manual';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Options accepted by the wu Astro integration. */
|
|
14
|
-
export interface WuIntegrationOptions {
|
|
15
|
-
/** Micro-apps to auto-register via wu.init(). */
|
|
16
|
-
apps?: WuAppConfig[];
|
|
17
|
-
/** Global sandbox isolation mode. */
|
|
18
|
-
sandbox?: 'module' | 'strict' | 'eval';
|
|
19
|
-
/** CDN URL for the wu-framework UMD bundle. When omitted the local package is used. */
|
|
20
|
-
cdn?: string;
|
|
21
|
-
/** Enable debug logging. */
|
|
22
|
-
debug?: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Astro integration factory for wu-framework.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* import wu from '@wu-framework/astro';
|
|
30
|
-
* export default defineConfig({ integrations: [wu({ apps: [...] })] });
|
|
31
|
-
*/
|
|
32
|
-
export default function wuIntegration(
|
|
33
|
-
options?: WuIntegrationOptions
|
|
34
|
-
): AstroIntegration;
|
|
35
|
-
|
|
36
|
-
/** Props for the WuShell.astro layout component. */
|
|
37
|
-
export interface WuShellProps {
|
|
38
|
-
apps: WuAppConfig[];
|
|
39
|
-
sandbox?: 'module' | 'strict' | 'eval';
|
|
40
|
-
debug?: boolean;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Props for the WuApp.astro mount component. */
|
|
44
|
-
export interface WuAppProps {
|
|
45
|
-
/** Name of the registered wu micro-app. */
|
|
46
|
-
name: string;
|
|
47
|
-
/** Defer mounting until the element is visible (IntersectionObserver). */
|
|
48
|
-
lazy?: boolean;
|
|
49
|
-
/** CSS class(es) for the container div. */
|
|
50
|
-
class?: string;
|
|
51
|
-
/** Inline styles for the container div. */
|
|
52
|
-
style?: string;
|
|
53
|
-
}
|
|
1
|
+
import type { AstroIntegration } from 'astro';
|
|
2
|
+
|
|
3
|
+
/** Configuration for a single wu micro-app. */
|
|
4
|
+
export interface WuAppConfig {
|
|
5
|
+
/** Unique name used to reference this micro-app. */
|
|
6
|
+
name: string;
|
|
7
|
+
/** URL or path from which the micro-app is loaded. */
|
|
8
|
+
url: string;
|
|
9
|
+
/** Loading strategy. Defaults to the framework default. */
|
|
10
|
+
strategy?: 'eager' | 'lazy' | 'manual';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Options accepted by the wu Astro integration. */
|
|
14
|
+
export interface WuIntegrationOptions {
|
|
15
|
+
/** Micro-apps to auto-register via wu.init(). */
|
|
16
|
+
apps?: WuAppConfig[];
|
|
17
|
+
/** Global sandbox isolation mode. */
|
|
18
|
+
sandbox?: 'module' | 'strict' | 'eval';
|
|
19
|
+
/** CDN URL for the wu-framework UMD bundle. When omitted the local package is used. */
|
|
20
|
+
cdn?: string;
|
|
21
|
+
/** Enable debug logging. */
|
|
22
|
+
debug?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Astro integration factory for wu-framework.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* import wu from '@wu-framework/astro';
|
|
30
|
+
* export default defineConfig({ integrations: [wu({ apps: [...] })] });
|
|
31
|
+
*/
|
|
32
|
+
export default function wuIntegration(
|
|
33
|
+
options?: WuIntegrationOptions
|
|
34
|
+
): AstroIntegration;
|
|
35
|
+
|
|
36
|
+
/** Props for the WuShell.astro layout component. */
|
|
37
|
+
export interface WuShellProps {
|
|
38
|
+
apps: WuAppConfig[];
|
|
39
|
+
sandbox?: 'module' | 'strict' | 'eval';
|
|
40
|
+
debug?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Props for the WuApp.astro mount component. */
|
|
44
|
+
export interface WuAppProps {
|
|
45
|
+
/** Name of the registered wu micro-app. */
|
|
46
|
+
name: string;
|
|
47
|
+
/** Defer mounting until the element is visible (IntersectionObserver). */
|
|
48
|
+
lazy?: boolean;
|
|
49
|
+
/** CSS class(es) for the container div. */
|
|
50
|
+
class?: string;
|
|
51
|
+
/** Inline styles for the container div. */
|
|
52
|
+
style?: string;
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wu-framework",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Universal Microfrontends Framework -
|
|
3
|
+
"version": "1.1.19",
|
|
4
|
+
"description": "Universal Microfrontends Framework - 13 frameworks, zero config, Shadow DOM isolation",
|
|
5
5
|
"main": "dist/wu-framework.cjs.js",
|
|
6
6
|
"module": "src/index.js",
|
|
7
7
|
"browser": "dist/wu-framework.umd.js",
|
|
@@ -22,6 +22,11 @@
|
|
|
22
22
|
"./adapters/solid": "./src/adapters/solid/index.js",
|
|
23
23
|
"./adapters/lit": "./src/adapters/lit/index.js",
|
|
24
24
|
"./adapters/vanilla": "./src/adapters/vanilla/index.js",
|
|
25
|
+
"./adapters/alpine": "./src/adapters/alpine/index.js",
|
|
26
|
+
"./adapters/qwik": "./src/adapters/qwik/index.js",
|
|
27
|
+
"./adapters/stencil": "./src/adapters/stencil/index.js",
|
|
28
|
+
"./adapters/htmx": "./src/adapters/htmx/index.js",
|
|
29
|
+
"./adapters/stimulus": "./src/adapters/stimulus/index.js",
|
|
25
30
|
"./integrations/astro": "./integrations/astro/index.js",
|
|
26
31
|
"./integrations/astro/WuApp.astro": "./integrations/astro/WuApp.astro",
|
|
27
32
|
"./integrations/astro/WuShell.astro": "./integrations/astro/WuShell.astro"
|
|
@@ -112,6 +117,21 @@
|
|
|
112
117
|
],
|
|
113
118
|
"adapters/vanilla": [
|
|
114
119
|
"src/adapters/vanilla/index.d.ts"
|
|
120
|
+
],
|
|
121
|
+
"adapters/alpine": [
|
|
122
|
+
"src/adapters/alpine/index.d.ts"
|
|
123
|
+
],
|
|
124
|
+
"adapters/qwik": [
|
|
125
|
+
"src/adapters/qwik/index.d.ts"
|
|
126
|
+
],
|
|
127
|
+
"adapters/stencil": [
|
|
128
|
+
"src/adapters/stencil/index.d.ts"
|
|
129
|
+
],
|
|
130
|
+
"adapters/htmx": [
|
|
131
|
+
"src/adapters/htmx/index.d.ts"
|
|
132
|
+
],
|
|
133
|
+
"adapters/stimulus": [
|
|
134
|
+
"src/adapters/stimulus/index.d.ts"
|
|
115
135
|
]
|
|
116
136
|
}
|
|
117
137
|
},
|
|
@@ -129,6 +149,11 @@
|
|
|
129
149
|
},
|
|
130
150
|
"peerDependencies": {
|
|
131
151
|
"@angular/core": ">=14.0.0",
|
|
152
|
+
"@builder.io/qwik": ">=1.0.0",
|
|
153
|
+
"@hotwired/stimulus": ">=3.0.0",
|
|
154
|
+
"@stencil/core": ">=4.0.0",
|
|
155
|
+
"alpinejs": ">=3.0.0",
|
|
156
|
+
"htmx.org": ">=2.0.0",
|
|
132
157
|
"lit": ">=2.0.0",
|
|
133
158
|
"preact": ">=10.0.0",
|
|
134
159
|
"react": ">=16.8.0",
|
|
@@ -137,6 +162,9 @@
|
|
|
137
162
|
"svelte": ">=3.0.0",
|
|
138
163
|
"vue": ">=3.0.0"
|
|
139
164
|
},
|
|
165
|
+
"overrides": {
|
|
166
|
+
"serialize-javascript": "^7.0.3"
|
|
167
|
+
},
|
|
140
168
|
"peerDependenciesMeta": {
|
|
141
169
|
"react": {
|
|
142
170
|
"optional": true
|
|
@@ -161,6 +189,21 @@
|
|
|
161
189
|
},
|
|
162
190
|
"lit": {
|
|
163
191
|
"optional": true
|
|
192
|
+
},
|
|
193
|
+
"alpinejs": {
|
|
194
|
+
"optional": true
|
|
195
|
+
},
|
|
196
|
+
"@builder.io/qwik": {
|
|
197
|
+
"optional": true
|
|
198
|
+
},
|
|
199
|
+
"@stencil/core": {
|
|
200
|
+
"optional": true
|
|
201
|
+
},
|
|
202
|
+
"htmx.org": {
|
|
203
|
+
"optional": true
|
|
204
|
+
},
|
|
205
|
+
"@hotwired/stimulus": {
|
|
206
|
+
"optional": true
|
|
164
207
|
}
|
|
165
208
|
}
|
|
166
209
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WU-FRAMEWORK ALPINE.JS ADAPTER - TypeScript Declarations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { WuCore } from '../../core/wu-core';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Alpine.js app configuration
|
|
9
|
+
*/
|
|
10
|
+
export interface AlpineAppConfig {
|
|
11
|
+
/** HTML template string containing Alpine directives (x-data, x-bind, etc.) */
|
|
12
|
+
template: string;
|
|
13
|
+
/** Function that returns the Alpine data object */
|
|
14
|
+
data?: () => Record<string, any>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Alpine.js adapter registration options
|
|
19
|
+
*/
|
|
20
|
+
export interface AlpineRegisterOptions {
|
|
21
|
+
/** Callback after mounting */
|
|
22
|
+
onMount?: (container: HTMLElement) => void;
|
|
23
|
+
/** Callback before unmounting */
|
|
24
|
+
onUnmount?: (container: HTMLElement) => void;
|
|
25
|
+
/** Allow standalone execution when Wu Framework is not available */
|
|
26
|
+
standalone?: boolean;
|
|
27
|
+
/** CSS selector for standalone mode container */
|
|
28
|
+
standaloneContainer?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Register an Alpine.js app as a Wu microfrontend
|
|
33
|
+
*/
|
|
34
|
+
export function register(
|
|
35
|
+
appName: string,
|
|
36
|
+
appConfig: AlpineAppConfig,
|
|
37
|
+
options?: AlpineRegisterOptions
|
|
38
|
+
): Promise<boolean>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get the current Wu Framework instance
|
|
42
|
+
*/
|
|
43
|
+
export function getWuInstance(): WuCore | null;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Wait for Wu Framework to become available
|
|
47
|
+
*/
|
|
48
|
+
export function waitForWu(timeout?: number): Promise<WuCore>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Alpine.js adapter interface
|
|
52
|
+
*/
|
|
53
|
+
export interface WuAlpineAdapter {
|
|
54
|
+
register: typeof register;
|
|
55
|
+
getWuInstance: typeof getWuInstance;
|
|
56
|
+
waitForWu: typeof waitForWu;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const wuAlpine: WuAlpineAdapter;
|
|
60
|
+
export default wuAlpine;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WU-FRAMEWORK ALPINE.JS ADAPTER
|
|
3
|
+
*
|
|
4
|
+
* Bridges Alpine.js reactive components into Wu Framework's
|
|
5
|
+
* microfrontend orchestration layer. Alpine's declarative
|
|
6
|
+
* x-data / x-bind paradigm maps naturally to a template + data
|
|
7
|
+
* registration model.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* import { wuAlpine } from 'wu-framework/adapters/alpine';
|
|
11
|
+
*
|
|
12
|
+
* wuAlpine.register('my-app', {
|
|
13
|
+
* template: '<div x-data="app"><span x-text="message"></span></div>',
|
|
14
|
+
* data: () => ({ message: 'Hello from Alpine' })
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // With lifecycle hooks
|
|
19
|
+
* wuAlpine.register('counter', {
|
|
20
|
+
* template: `
|
|
21
|
+
* <div x-data="app">
|
|
22
|
+
* <span x-text="count"></span>
|
|
23
|
+
* <button @click="count++">+</button>
|
|
24
|
+
* </div>
|
|
25
|
+
* `,
|
|
26
|
+
* data: () => ({ count: 0 })
|
|
27
|
+
* }, {
|
|
28
|
+
* onMount: (container) => console.log('Mounted'),
|
|
29
|
+
* onUnmount: (container) => console.log('Unmounted')
|
|
30
|
+
* });
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
// Adapter-scoped state
|
|
34
|
+
const adapterState = {
|
|
35
|
+
apps: new Map()
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Obtiene la instancia de Wu Framework
|
|
40
|
+
*/
|
|
41
|
+
function getWuInstance() {
|
|
42
|
+
if (typeof window === 'undefined') return null;
|
|
43
|
+
|
|
44
|
+
return window.wu
|
|
45
|
+
|| window.parent?.wu
|
|
46
|
+
|| window.top?.wu
|
|
47
|
+
|| null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Espera a que Wu Framework este disponible
|
|
52
|
+
*/
|
|
53
|
+
function waitForWu(timeout = 5000) {
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
const wu = getWuInstance();
|
|
56
|
+
if (wu) {
|
|
57
|
+
resolve(wu);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const startTime = Date.now();
|
|
62
|
+
|
|
63
|
+
const handleWuReady = () => {
|
|
64
|
+
cleanup();
|
|
65
|
+
resolve(getWuInstance());
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
window.addEventListener('wu:ready', handleWuReady);
|
|
69
|
+
window.addEventListener('wu:app:ready', handleWuReady);
|
|
70
|
+
|
|
71
|
+
const checkInterval = setInterval(() => {
|
|
72
|
+
const wu = getWuInstance();
|
|
73
|
+
if (wu) {
|
|
74
|
+
cleanup();
|
|
75
|
+
resolve(wu);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (Date.now() - startTime > timeout) {
|
|
80
|
+
cleanup();
|
|
81
|
+
reject(new Error(`Wu Framework not found after ${timeout}ms`));
|
|
82
|
+
}
|
|
83
|
+
}, 200);
|
|
84
|
+
|
|
85
|
+
function cleanup() {
|
|
86
|
+
clearInterval(checkInterval);
|
|
87
|
+
window.removeEventListener('wu:ready', handleWuReady);
|
|
88
|
+
window.removeEventListener('wu:app:ready', handleWuReady);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Registra una app Alpine.js como microfrontend
|
|
95
|
+
*
|
|
96
|
+
* @param {string} appName - Nombre unico del microfrontend
|
|
97
|
+
* @param {Object} appConfig - Configuracion de la app Alpine
|
|
98
|
+
* @param {string} appConfig.template - HTML string con directivas Alpine (x-data, x-bind, etc.)
|
|
99
|
+
* @param {Function} appConfig.data - Funcion que retorna el objeto de datos Alpine
|
|
100
|
+
* @param {Object} [options] - Opciones adicionales
|
|
101
|
+
* @param {Function} [options.onMount] - Callback despues de montar
|
|
102
|
+
* @param {Function} [options.onUnmount] - Callback antes de desmontar
|
|
103
|
+
* @param {boolean} [options.standalone=true] - Permitir ejecucion standalone
|
|
104
|
+
* @param {string} [options.standaloneContainer='#app'] - Selector para modo standalone
|
|
105
|
+
* @returns {Promise<boolean>} true si el registro fue exitoso
|
|
106
|
+
*/
|
|
107
|
+
async function register(appName, appConfig, options = {}) {
|
|
108
|
+
const { template, data } = appConfig;
|
|
109
|
+
|
|
110
|
+
const {
|
|
111
|
+
onMount = null,
|
|
112
|
+
onUnmount = null,
|
|
113
|
+
standalone = true,
|
|
114
|
+
standaloneContainer = '#app'
|
|
115
|
+
} = options;
|
|
116
|
+
|
|
117
|
+
if (!template || typeof template !== 'string') {
|
|
118
|
+
throw new Error(`[WuAlpine] template (HTML string) is required for ${appName}`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Mount function
|
|
122
|
+
const mountApp = (container) => {
|
|
123
|
+
if (!container) {
|
|
124
|
+
console.error(`[WuAlpine] Mount failed for ${appName}: container is null`);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Prevent double-mount
|
|
129
|
+
if (adapterState.apps.has(appName)) {
|
|
130
|
+
console.warn(`[WuAlpine] ${appName} already mounted, unmounting first`);
|
|
131
|
+
unmountApp();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
container.innerHTML = '';
|
|
136
|
+
|
|
137
|
+
// Inject template HTML
|
|
138
|
+
container.innerHTML = template;
|
|
139
|
+
|
|
140
|
+
// Initialize Alpine on this subtree
|
|
141
|
+
const Alpine = window.Alpine;
|
|
142
|
+
if (Alpine) {
|
|
143
|
+
if (data && typeof data === 'function') {
|
|
144
|
+
Alpine.data('app', data);
|
|
145
|
+
}
|
|
146
|
+
Alpine.initTree(container);
|
|
147
|
+
} else {
|
|
148
|
+
console.warn(`[WuAlpine] window.Alpine not found - template inserted but not initialized`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
adapterState.apps.set(appName, { container, config: appConfig });
|
|
152
|
+
|
|
153
|
+
console.log(`[WuAlpine] ${appName} mounted successfully`);
|
|
154
|
+
|
|
155
|
+
if (onMount) {
|
|
156
|
+
onMount(container);
|
|
157
|
+
}
|
|
158
|
+
} catch (error) {
|
|
159
|
+
console.error(`[WuAlpine] Mount error for ${appName}:`, error);
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// Unmount function
|
|
165
|
+
const unmountApp = (container) => {
|
|
166
|
+
const appData = adapterState.apps.get(appName);
|
|
167
|
+
|
|
168
|
+
if (appData) {
|
|
169
|
+
try {
|
|
170
|
+
if (onUnmount) {
|
|
171
|
+
onUnmount(appData.container);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Tear down Alpine reactivity on this subtree
|
|
175
|
+
const Alpine = window.Alpine;
|
|
176
|
+
if (Alpine && typeof Alpine.destroyTree === 'function') {
|
|
177
|
+
Alpine.destroyTree(appData.container);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
appData.container.innerHTML = '';
|
|
181
|
+
adapterState.apps.delete(appName);
|
|
182
|
+
|
|
183
|
+
console.log(`[WuAlpine] ${appName} unmounted successfully`);
|
|
184
|
+
} catch (error) {
|
|
185
|
+
console.error(`[WuAlpine] Unmount error for ${appName}:`, error);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (container) {
|
|
190
|
+
container.innerHTML = '';
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// Register with Wu Framework or fall back to standalone
|
|
195
|
+
try {
|
|
196
|
+
const wu = await waitForWu(3000);
|
|
197
|
+
|
|
198
|
+
wu.define(appName, {
|
|
199
|
+
mount: mountApp,
|
|
200
|
+
unmount: unmountApp
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
console.log(`[WuAlpine] ${appName} registered with Wu Framework`);
|
|
204
|
+
return true;
|
|
205
|
+
|
|
206
|
+
} catch (error) {
|
|
207
|
+
console.warn(`[WuAlpine] Wu Framework not available for ${appName}`);
|
|
208
|
+
|
|
209
|
+
if (standalone) {
|
|
210
|
+
const containerElement = document.querySelector(standaloneContainer);
|
|
211
|
+
|
|
212
|
+
if (containerElement) {
|
|
213
|
+
console.log(`[WuAlpine] Running ${appName} in standalone mode`);
|
|
214
|
+
mountApp(containerElement);
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Public API
|
|
224
|
+
export const wuAlpine = {
|
|
225
|
+
register,
|
|
226
|
+
getWuInstance,
|
|
227
|
+
waitForWu
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export { register, getWuInstance, waitForWu };
|
|
231
|
+
export default wuAlpine;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WU-FRAMEWORK HTMX ADAPTER - TypeScript Declarations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { WuCore } from '../../core/wu-core';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* HTMX app configuration
|
|
9
|
+
*/
|
|
10
|
+
export interface HtmxAppConfig {
|
|
11
|
+
/** HTML template string containing hx-* attributes */
|
|
12
|
+
template: string;
|
|
13
|
+
/** Base URL for HTMX endpoints (rewrites relative paths in hx-get, hx-post, etc.) */
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* HTMX adapter registration options
|
|
19
|
+
*/
|
|
20
|
+
export interface HtmxRegisterOptions {
|
|
21
|
+
/** Callback after mounting */
|
|
22
|
+
onMount?: (container: HTMLElement) => void;
|
|
23
|
+
/** Callback before unmounting */
|
|
24
|
+
onUnmount?: (container: HTMLElement) => void;
|
|
25
|
+
/** Allow standalone execution when Wu Framework is not available */
|
|
26
|
+
standalone?: boolean;
|
|
27
|
+
/** CSS selector for standalone mode container */
|
|
28
|
+
standaloneContainer?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Register an HTMX app as a Wu microfrontend
|
|
33
|
+
*/
|
|
34
|
+
export function register(
|
|
35
|
+
appName: string,
|
|
36
|
+
config: HtmxAppConfig,
|
|
37
|
+
options?: HtmxRegisterOptions
|
|
38
|
+
): Promise<boolean>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get the current Wu Framework instance
|
|
42
|
+
*/
|
|
43
|
+
export function getWuInstance(): WuCore | null;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Wait for Wu Framework to become available
|
|
47
|
+
*/
|
|
48
|
+
export function waitForWu(timeout?: number): Promise<WuCore>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* HTMX adapter interface
|
|
52
|
+
*/
|
|
53
|
+
export interface WuHtmxAdapter {
|
|
54
|
+
register: typeof register;
|
|
55
|
+
getWuInstance: typeof getWuInstance;
|
|
56
|
+
waitForWu: typeof waitForWu;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const wuHtmx: WuHtmxAdapter;
|
|
60
|
+
export default wuHtmx;
|