@flightdev/ui 2.0.0
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/.turbo/turbo-build.log +81 -0
- package/.turbo/turbo-lint.log +40 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/LICENSE +21 -0
- package/README.md +92 -0
- package/TESTING.md +124 -0
- package/dist/adapter-MMD-iHNx.d.ts +424 -0
- package/dist/adapters/tier-1/angular.d.ts +60 -0
- package/dist/adapters/tier-1/angular.js +2 -0
- package/dist/adapters/tier-1/index.d.ts +7 -0
- package/dist/adapters/tier-1/index.js +7 -0
- package/dist/adapters/tier-1/qwik.d.ts +55 -0
- package/dist/adapters/tier-1/qwik.js +2 -0
- package/dist/adapters/tier-1/react.d.ts +67 -0
- package/dist/adapters/tier-1/react.js +2 -0
- package/dist/adapters/tier-1/solid.d.ts +45 -0
- package/dist/adapters/tier-1/solid.js +2 -0
- package/dist/adapters/tier-1/svelte.d.ts +48 -0
- package/dist/adapters/tier-1/svelte.js +2 -0
- package/dist/adapters/tier-1/vue.d.ts +47 -0
- package/dist/adapters/tier-1/vue.js +2 -0
- package/dist/adapters/tier-2/index.d.ts +7 -0
- package/dist/adapters/tier-2/index.js +7 -0
- package/dist/adapters/tier-2/inferno.d.ts +31 -0
- package/dist/adapters/tier-2/inferno.js +2 -0
- package/dist/adapters/tier-2/lit.d.ts +34 -0
- package/dist/adapters/tier-2/lit.js +2 -0
- package/dist/adapters/tier-2/marko.d.ts +59 -0
- package/dist/adapters/tier-2/marko.js +2 -0
- package/dist/adapters/tier-2/mithril.d.ts +31 -0
- package/dist/adapters/tier-2/mithril.js +2 -0
- package/dist/adapters/tier-2/preact.d.ts +33 -0
- package/dist/adapters/tier-2/preact.js +2 -0
- package/dist/adapters/tier-2/stencil.d.ts +52 -0
- package/dist/adapters/tier-2/stencil.js +2 -0
- package/dist/adapters/tier-3/alpine.d.ts +73 -0
- package/dist/adapters/tier-3/alpine.js +2 -0
- package/dist/adapters/tier-3/hotwire.d.ts +71 -0
- package/dist/adapters/tier-3/hotwire.js +2 -0
- package/dist/adapters/tier-3/htmx.d.ts +88 -0
- package/dist/adapters/tier-3/htmx.js +2 -0
- package/dist/adapters/tier-3/index.d.ts +7 -0
- package/dist/adapters/tier-3/index.js +7 -0
- package/dist/adapters/tier-3/petite-vue.d.ts +56 -0
- package/dist/adapters/tier-3/petite-vue.js +2 -0
- package/dist/adapters/tier-3/stimulus.d.ts +63 -0
- package/dist/adapters/tier-3/stimulus.js +2 -0
- package/dist/adapters/tier-3/vanilla.d.ts +63 -0
- package/dist/adapters/tier-3/vanilla.js +2 -0
- package/dist/chunk-2SNQ6PTM.js +217 -0
- package/dist/chunk-3D4XMIZI.js +136 -0
- package/dist/chunk-3HU6GSQ4.js +125 -0
- package/dist/chunk-4PZDNFL7.js +148 -0
- package/dist/chunk-5IBLFTYL.js +114 -0
- package/dist/chunk-64JZJ7OK.js +142 -0
- package/dist/chunk-7ZJI3QU2.js +132 -0
- package/dist/chunk-CE4FJHQJ.js +133 -0
- package/dist/chunk-DTCAUBH5.js +87 -0
- package/dist/chunk-NTASPOHG.js +106 -0
- package/dist/chunk-OI2AMQLG.js +152 -0
- package/dist/chunk-Q7HUE44H.js +106 -0
- package/dist/chunk-QH3LOWXU.js +155 -0
- package/dist/chunk-QIVAK6BH.js +103 -0
- package/dist/chunk-V34XPVGK.js +103 -0
- package/dist/chunk-VK7ZPMO7.js +221 -0
- package/dist/chunk-X6CNUW6T.js +136 -0
- package/dist/chunk-XTDK7ME5.js +382 -0
- package/dist/chunk-YFGSHW5S.js +121 -0
- package/dist/chunk-ZAJVSE7J.js +90 -0
- package/dist/core/index.d.ts +161 -0
- package/dist/core/index.js +2 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +71 -0
- package/docs/ADAPTERS.md +946 -0
- package/docs/PATTERNS.md +836 -0
- package/package.json +229 -0
- package/src/adapters/tier-1/angular.ts +223 -0
- package/src/adapters/tier-1/index.ts +12 -0
- package/src/adapters/tier-1/qwik.ts +177 -0
- package/src/adapters/tier-1/react.ts +330 -0
- package/src/adapters/tier-1/solid.ts +222 -0
- package/src/adapters/tier-1/svelte.ts +211 -0
- package/src/adapters/tier-1/vue.ts +234 -0
- package/src/adapters/tier-2/index.ts +12 -0
- package/src/adapters/tier-2/inferno.ts +149 -0
- package/src/adapters/tier-2/lit.ts +191 -0
- package/src/adapters/tier-2/marko.ts +199 -0
- package/src/adapters/tier-2/mithril.ts +152 -0
- package/src/adapters/tier-2/preact.ts +133 -0
- package/src/adapters/tier-2/stencil.ts +214 -0
- package/src/adapters/tier-3/alpine.ts +218 -0
- package/src/adapters/tier-3/hotwire.ts +254 -0
- package/src/adapters/tier-3/htmx.ts +263 -0
- package/src/adapters/tier-3/index.ts +12 -0
- package/src/adapters/tier-3/petite-vue.ts +163 -0
- package/src/adapters/tier-3/stimulus.ts +233 -0
- package/src/adapters/tier-3/vanilla.ts +252 -0
- package/src/ambient.d.ts +310 -0
- package/src/core/adapter.ts +366 -0
- package/src/core/index.ts +56 -0
- package/src/core/registry.ts +518 -0
- package/src/core/types.ts +461 -0
- package/src/htmx.ts +134 -0
- package/src/index.ts +263 -0
- package/test/__mocks__/stencil-core.ts +19 -0
- package/test/__mocks__/stencil-hydrate.ts +15 -0
- package/test/adapters/tier-1.test.ts +206 -0
- package/test/adapters/tier-2.test.ts +175 -0
- package/test/adapters/tier-3.test.ts +284 -0
- package/test/contracts/adapter.contract.ts +293 -0
- package/test/core/core.test.ts +310 -0
- package/test/errors/error-handling.test.ts +454 -0
- package/test/integration/htmx.integration.test.ts +246 -0
- package/test/integration/react.integration.test.ts +271 -0
- package/test/integration/registry.integration.test.ts +308 -0
- package/tsconfig.json +22 -0
- package/tsup.config.ts +93 -0
- package/vitest.config.ts +101 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { BaseUIAdapter } from './chunk-2SNQ6PTM.js';
|
|
2
|
+
|
|
3
|
+
// src/adapters/tier-2/mithril.ts
|
|
4
|
+
var MithrilAdapter = class extends BaseUIAdapter {
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
super();
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
id = "mithril";
|
|
10
|
+
name = "Mithril";
|
|
11
|
+
framework = "mithril";
|
|
12
|
+
frameworkVersion = "2+";
|
|
13
|
+
tier = "tier-2";
|
|
14
|
+
capabilities = {
|
|
15
|
+
streaming: false,
|
|
16
|
+
partialHydration: false,
|
|
17
|
+
islands: false,
|
|
18
|
+
resumable: false,
|
|
19
|
+
ssg: true,
|
|
20
|
+
csr: true,
|
|
21
|
+
serverComponents: false
|
|
22
|
+
};
|
|
23
|
+
async renderToString(component, _context) {
|
|
24
|
+
const startTime = performance.now();
|
|
25
|
+
try {
|
|
26
|
+
const render = await import('mithril-node-render').then((m2) => m2.default || m2);
|
|
27
|
+
const m = await import('mithril').then((mod) => mod.default || mod);
|
|
28
|
+
const MithrilComponent = component.component;
|
|
29
|
+
const vnode = m(MithrilComponent, component.props ?? {});
|
|
30
|
+
const html = await render(vnode);
|
|
31
|
+
return {
|
|
32
|
+
html,
|
|
33
|
+
hydrationData: {
|
|
34
|
+
props: component.props,
|
|
35
|
+
componentId: component.id ?? this.generateId()
|
|
36
|
+
},
|
|
37
|
+
timing: this.createTiming(startTime)
|
|
38
|
+
};
|
|
39
|
+
} catch (error) {
|
|
40
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
41
|
+
if (message.includes("Cannot find module 'mithril-node-render'")) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
"[Flight/Mithril] Mithril SSR package not found.\nInstall required packages:\n npm install mithril mithril-node-render\n npm install -D @types/mithril"
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
getHydrationScript(result) {
|
|
50
|
+
const data = this.serializeProps(result.hydrationData);
|
|
51
|
+
return `
|
|
52
|
+
<script type="module">
|
|
53
|
+
window.__FLIGHT_DATA__ = ${data};
|
|
54
|
+
window.__FLIGHT_ADAPTER__ = 'mithril';
|
|
55
|
+
|
|
56
|
+
import m from 'mithril';
|
|
57
|
+
|
|
58
|
+
const App = window.__FLIGHT_APP__;
|
|
59
|
+
const container = document.getElementById('app');
|
|
60
|
+
|
|
61
|
+
if (App && container) {
|
|
62
|
+
// Mithril mounts and diffs against existing DOM
|
|
63
|
+
m.mount(container, {
|
|
64
|
+
view: () => m(App, window.__FLIGHT_DATA__.props)
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
</script>
|
|
68
|
+
`.trim();
|
|
69
|
+
}
|
|
70
|
+
getClientEntry() {
|
|
71
|
+
return `
|
|
72
|
+
import m from 'mithril';
|
|
73
|
+
|
|
74
|
+
export function hydrate() {
|
|
75
|
+
const container = document.getElementById('app');
|
|
76
|
+
const App = window.__FLIGHT_APP__;
|
|
77
|
+
const data = window.__FLIGHT_DATA__ ?? {};
|
|
78
|
+
|
|
79
|
+
if (!container || !App) {
|
|
80
|
+
console.warn('[Flight/Mithril] Missing container or App');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Mithril automatically diffs against existing DOM
|
|
85
|
+
m.mount(container, {
|
|
86
|
+
view: () => m(App, data.props)
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function render(App, container, props = {}) {
|
|
91
|
+
m.mount(container, {
|
|
92
|
+
view: () => m(App, props)
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
`.trim();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
function mithril(options) {
|
|
99
|
+
return new MithrilAdapter(options);
|
|
100
|
+
}
|
|
101
|
+
var mithril_default = mithril;
|
|
102
|
+
|
|
103
|
+
export { MithrilAdapter, mithril, mithril_default };
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { BaseUIAdapter } from './chunk-2SNQ6PTM.js';
|
|
2
|
+
|
|
3
|
+
// src/adapters/tier-1/react.ts
|
|
4
|
+
var ReactAdapter = class extends BaseUIAdapter {
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
super();
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
id = "react";
|
|
10
|
+
name = "React";
|
|
11
|
+
framework = "react";
|
|
12
|
+
frameworkVersion = "18+";
|
|
13
|
+
tier = "tier-1";
|
|
14
|
+
capabilities = {
|
|
15
|
+
streaming: true,
|
|
16
|
+
partialHydration: true,
|
|
17
|
+
islands: true,
|
|
18
|
+
resumable: false,
|
|
19
|
+
// React 19 has some resumability features
|
|
20
|
+
ssg: true,
|
|
21
|
+
csr: true,
|
|
22
|
+
serverComponents: true
|
|
23
|
+
};
|
|
24
|
+
async renderToString(component, _context) {
|
|
25
|
+
const startTime = performance.now();
|
|
26
|
+
const { renderToString } = await import('react-dom/server');
|
|
27
|
+
const { createElement } = await import('react');
|
|
28
|
+
const element = createElement(
|
|
29
|
+
component.component,
|
|
30
|
+
component.props ?? {},
|
|
31
|
+
component.children
|
|
32
|
+
);
|
|
33
|
+
const html = renderToString(element);
|
|
34
|
+
return {
|
|
35
|
+
html,
|
|
36
|
+
hydrationData: {
|
|
37
|
+
props: component.props,
|
|
38
|
+
componentId: component.id ?? this.generateId()
|
|
39
|
+
},
|
|
40
|
+
timing: this.createTiming(startTime)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Render to stream using React 18+ streaming SSR.
|
|
45
|
+
*
|
|
46
|
+
* Uses `renderToReadableStream` (Web Streams API) which works in:
|
|
47
|
+
* - Node.js 18+ (with Web Streams support)
|
|
48
|
+
* - Deno
|
|
49
|
+
* - Cloudflare Workers
|
|
50
|
+
* - Vercel Edge Runtime
|
|
51
|
+
* - Other edge runtimes
|
|
52
|
+
*
|
|
53
|
+
* Falls back to `renderToPipeableStream` for Node.js environments
|
|
54
|
+
* that require traditional streams.
|
|
55
|
+
*/
|
|
56
|
+
renderToStream(component, _context, options) {
|
|
57
|
+
let aborted = false;
|
|
58
|
+
let abortController = null;
|
|
59
|
+
let resolvePromise;
|
|
60
|
+
let rejectPromise;
|
|
61
|
+
const done = new Promise((resolve, reject) => {
|
|
62
|
+
resolvePromise = resolve;
|
|
63
|
+
rejectPromise = reject;
|
|
64
|
+
});
|
|
65
|
+
const stream = new ReadableStream({
|
|
66
|
+
start: async (controller) => {
|
|
67
|
+
try {
|
|
68
|
+
const { renderToReadableStream } = await import('react-dom/server');
|
|
69
|
+
const { createElement } = await import('react');
|
|
70
|
+
const element = createElement(
|
|
71
|
+
component.component,
|
|
72
|
+
component.props ?? {},
|
|
73
|
+
component.children
|
|
74
|
+
);
|
|
75
|
+
abortController = new AbortController();
|
|
76
|
+
const reactStream = await renderToReadableStream(element, {
|
|
77
|
+
signal: abortController.signal,
|
|
78
|
+
onError(error) {
|
|
79
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
80
|
+
options?.onError?.(err);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
options?.onShellReady?.();
|
|
84
|
+
const reader = reactStream.getReader();
|
|
85
|
+
const pump = async () => {
|
|
86
|
+
try {
|
|
87
|
+
while (true) {
|
|
88
|
+
if (aborted) {
|
|
89
|
+
await reader.cancel();
|
|
90
|
+
controller.close();
|
|
91
|
+
resolvePromise();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const { done: readerDone, value } = await reader.read();
|
|
95
|
+
if (readerDone) {
|
|
96
|
+
controller.close();
|
|
97
|
+
options?.onAllReady?.();
|
|
98
|
+
resolvePromise();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (value) {
|
|
102
|
+
controller.enqueue(value);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
} catch (error) {
|
|
106
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
107
|
+
options?.onError?.(err);
|
|
108
|
+
controller.error(err);
|
|
109
|
+
rejectPromise(err);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
await pump();
|
|
113
|
+
} catch (error) {
|
|
114
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
115
|
+
if (err.message.includes("renderToReadableStream")) {
|
|
116
|
+
await this.fallbackStreamRender(component, controller, options, resolvePromise, rejectPromise);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
options?.onShellError?.(err);
|
|
120
|
+
options?.onError?.(err);
|
|
121
|
+
controller.error(err);
|
|
122
|
+
rejectPromise(err);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return {
|
|
127
|
+
stream,
|
|
128
|
+
done,
|
|
129
|
+
abort: () => {
|
|
130
|
+
aborted = true;
|
|
131
|
+
abortController?.abort();
|
|
132
|
+
resolvePromise();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Fallback render for environments without Web Streams support.
|
|
138
|
+
* Uses renderToString and emits as a single chunk.
|
|
139
|
+
*/
|
|
140
|
+
async fallbackStreamRender(component, controller, options, resolvePromise, rejectPromise) {
|
|
141
|
+
try {
|
|
142
|
+
const { renderToString } = await import('react-dom/server');
|
|
143
|
+
const { createElement } = await import('react');
|
|
144
|
+
const element = createElement(
|
|
145
|
+
component.component,
|
|
146
|
+
component.props ?? {},
|
|
147
|
+
component.children
|
|
148
|
+
);
|
|
149
|
+
options?.onShellReady?.();
|
|
150
|
+
const html = renderToString(element);
|
|
151
|
+
const encoded = new TextEncoder().encode(html);
|
|
152
|
+
controller.enqueue(encoded);
|
|
153
|
+
controller.close();
|
|
154
|
+
options?.onAllReady?.();
|
|
155
|
+
resolvePromise();
|
|
156
|
+
} catch (error) {
|
|
157
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
158
|
+
options?.onError?.(err);
|
|
159
|
+
controller.error(err);
|
|
160
|
+
rejectPromise(err);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
getHydrationScript(result) {
|
|
164
|
+
const data = this.serializeProps(result.hydrationData);
|
|
165
|
+
return `
|
|
166
|
+
<script type="module">
|
|
167
|
+
window.__FLIGHT_DATA__ = ${data};
|
|
168
|
+
window.__FLIGHT_ADAPTER__ = 'react';
|
|
169
|
+
|
|
170
|
+
import { hydrateRoot } from 'react-dom/client';
|
|
171
|
+
|
|
172
|
+
const container = document.getElementById('app');
|
|
173
|
+
const App = window.__FLIGHT_APP__;
|
|
174
|
+
|
|
175
|
+
if (container && App) {
|
|
176
|
+
const { props } = window.__FLIGHT_DATA__;
|
|
177
|
+
import('react').then(({ createElement }) => {
|
|
178
|
+
hydrateRoot(container, createElement(App, props));
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
</script>
|
|
182
|
+
`.trim();
|
|
183
|
+
}
|
|
184
|
+
getClientEntry() {
|
|
185
|
+
return `
|
|
186
|
+
import { hydrateRoot, createRoot } from 'react-dom/client';
|
|
187
|
+
import { createElement } from 'react';
|
|
188
|
+
|
|
189
|
+
export function hydrate() {
|
|
190
|
+
const container = document.getElementById('app');
|
|
191
|
+
const App = window.__FLIGHT_APP__;
|
|
192
|
+
const data = window.__FLIGHT_DATA__ ?? {};
|
|
193
|
+
|
|
194
|
+
if (!container || !App) {
|
|
195
|
+
console.warn('[Flight/React] Missing container or App');
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Check if we have SSR content to hydrate
|
|
200
|
+
if (container.innerHTML.trim()) {
|
|
201
|
+
hydrateRoot(container, createElement(App, data.props));
|
|
202
|
+
} else {
|
|
203
|
+
// Fallback to client-side render
|
|
204
|
+
createRoot(container).render(createElement(App, data.props));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function render(App, container, props = {}) {
|
|
209
|
+
const root = createRoot(container);
|
|
210
|
+
root.render(createElement(App, props));
|
|
211
|
+
return root;
|
|
212
|
+
}
|
|
213
|
+
`.trim();
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
function react(options) {
|
|
217
|
+
return new ReactAdapter(options);
|
|
218
|
+
}
|
|
219
|
+
var react_default = react;
|
|
220
|
+
|
|
221
|
+
export { ReactAdapter, react, react_default };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { BaseUIAdapter } from './chunk-2SNQ6PTM.js';
|
|
2
|
+
|
|
3
|
+
// src/adapters/tier-1/svelte.ts
|
|
4
|
+
var SvelteAdapter = class extends BaseUIAdapter {
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
super();
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
id = "svelte";
|
|
10
|
+
name = "Svelte";
|
|
11
|
+
framework = "svelte";
|
|
12
|
+
frameworkVersion = "5+";
|
|
13
|
+
tier = "tier-1";
|
|
14
|
+
capabilities = {
|
|
15
|
+
streaming: false,
|
|
16
|
+
// Svelte 5 doesn't have streaming SSR yet
|
|
17
|
+
partialHydration: true,
|
|
18
|
+
islands: true,
|
|
19
|
+
resumable: false,
|
|
20
|
+
ssg: true,
|
|
21
|
+
csr: true,
|
|
22
|
+
serverComponents: false
|
|
23
|
+
};
|
|
24
|
+
async renderToString(component, _context) {
|
|
25
|
+
const startTime = performance.now();
|
|
26
|
+
try {
|
|
27
|
+
const { render } = await import('svelte/server');
|
|
28
|
+
const SvelteComponent = component.component;
|
|
29
|
+
const { body, head } = render(SvelteComponent, {
|
|
30
|
+
props: component.props ?? {}
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
html: body,
|
|
34
|
+
head,
|
|
35
|
+
hydrationData: {
|
|
36
|
+
props: component.props,
|
|
37
|
+
componentId: component.id ?? this.generateId()
|
|
38
|
+
},
|
|
39
|
+
css: this.options.extractCss ? void 0 : void 0,
|
|
40
|
+
// CSS handled by bundler
|
|
41
|
+
timing: this.createTiming(startTime)
|
|
42
|
+
};
|
|
43
|
+
} catch (error) {
|
|
44
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
45
|
+
if (message.includes("Cannot find module 'svelte/server'")) {
|
|
46
|
+
return this.renderSvelte4(component, startTime);
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Fallback render for Svelte 4
|
|
53
|
+
*/
|
|
54
|
+
async renderSvelte4(component, startTime) {
|
|
55
|
+
const SvelteComponent = component.component;
|
|
56
|
+
const result = SvelteComponent.render(component.props ?? {});
|
|
57
|
+
return {
|
|
58
|
+
html: result.html,
|
|
59
|
+
head: result.head,
|
|
60
|
+
css: result.css?.code,
|
|
61
|
+
hydrationData: {
|
|
62
|
+
props: component.props,
|
|
63
|
+
componentId: component.id ?? this.generateId()
|
|
64
|
+
},
|
|
65
|
+
timing: this.createTiming(startTime)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
getHydrationScript(result) {
|
|
69
|
+
const data = this.serializeProps(result.hydrationData);
|
|
70
|
+
return `
|
|
71
|
+
<script type="module">
|
|
72
|
+
window.__FLIGHT_DATA__ = ${data};
|
|
73
|
+
window.__FLIGHT_ADAPTER__ = 'svelte';
|
|
74
|
+
|
|
75
|
+
const App = window.__FLIGHT_APP__;
|
|
76
|
+
const container = document.getElementById('app');
|
|
77
|
+
|
|
78
|
+
if (App && container) {
|
|
79
|
+
const { props } = window.__FLIGHT_DATA__;
|
|
80
|
+
// Svelte 5 mount
|
|
81
|
+
import('svelte').then(({ mount, hydrate }) => {
|
|
82
|
+
if (container.innerHTML.trim()) {
|
|
83
|
+
hydrate(App, { target: container, props });
|
|
84
|
+
} else {
|
|
85
|
+
mount(App, { target: container, props });
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
</script>
|
|
90
|
+
`.trim();
|
|
91
|
+
}
|
|
92
|
+
getClientEntry() {
|
|
93
|
+
return `
|
|
94
|
+
// Svelte 5 client entry
|
|
95
|
+
import { mount, hydrate } from 'svelte';
|
|
96
|
+
|
|
97
|
+
export function hydrateApp() {
|
|
98
|
+
const container = document.getElementById('app');
|
|
99
|
+
const App = window.__FLIGHT_APP__;
|
|
100
|
+
const data = window.__FLIGHT_DATA__ ?? {};
|
|
101
|
+
|
|
102
|
+
if (!container || !App) {
|
|
103
|
+
console.warn('[Flight/Svelte] Missing container or App');
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Check if we have SSR content to hydrate
|
|
108
|
+
if (container.innerHTML.trim()) {
|
|
109
|
+
return hydrate(App, {
|
|
110
|
+
target: container,
|
|
111
|
+
props: data.props ?? {},
|
|
112
|
+
});
|
|
113
|
+
} else {
|
|
114
|
+
// Fallback to client-side render
|
|
115
|
+
return mount(App, {
|
|
116
|
+
target: container,
|
|
117
|
+
props: data.props ?? {},
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function render(App, container, props = {}) {
|
|
123
|
+
return mount(App, { target: container, props });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Export for Flight
|
|
127
|
+
export { hydrateApp as hydrate };
|
|
128
|
+
`.trim();
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
function svelte(options) {
|
|
132
|
+
return new SvelteAdapter(options);
|
|
133
|
+
}
|
|
134
|
+
var svelte_default = svelte;
|
|
135
|
+
|
|
136
|
+
export { SvelteAdapter, svelte, svelte_default };
|