bertui 0.2.2 → 0.2.3
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/package.json +1 -1
- package/src/client/compiler.js +33 -27
package/package.json
CHANGED
package/src/client/compiler.js
CHANGED
|
@@ -111,8 +111,7 @@ async function generateRouter(routes, outDir, root) {
|
|
|
111
111
|
return ` { path: '${route.route}', component: ${componentName}, type: '${route.type}' }`;
|
|
112
112
|
}).join(',\n');
|
|
113
113
|
|
|
114
|
-
const routerComponentCode = `
|
|
115
|
-
import { useState, useEffect, createContext, useContext } from 'react';
|
|
114
|
+
const routerComponentCode = `import { useState, useEffect, createContext, useContext, createElement } from 'react';
|
|
116
115
|
|
|
117
116
|
const RouterContext = createContext(null);
|
|
118
117
|
|
|
@@ -186,10 +185,10 @@ export function Router({ routes }) {
|
|
|
186
185
|
|
|
187
186
|
const Component = currentRoute?.component;
|
|
188
187
|
|
|
189
|
-
return (
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
188
|
+
return createElement(
|
|
189
|
+
RouterContext.Provider,
|
|
190
|
+
{ value: routerValue },
|
|
191
|
+
Component ? createElement(Component, { params }) : createElement(NotFound, null)
|
|
193
192
|
);
|
|
194
193
|
}
|
|
195
194
|
|
|
@@ -201,29 +200,28 @@ export function Link({ to, children, ...props }) {
|
|
|
201
200
|
navigate(to);
|
|
202
201
|
}
|
|
203
202
|
|
|
204
|
-
return (
|
|
205
|
-
<a href={to} onClick={handleClick} {...props}>
|
|
206
|
-
{children}
|
|
207
|
-
</a>
|
|
208
|
-
);
|
|
203
|
+
return createElement('a', { href: to, onClick: handleClick, ...props }, children);
|
|
209
204
|
}
|
|
210
205
|
|
|
211
206
|
function NotFound() {
|
|
212
|
-
return (
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
207
|
+
return createElement(
|
|
208
|
+
'div',
|
|
209
|
+
{
|
|
210
|
+
style: {
|
|
211
|
+
display: 'flex',
|
|
212
|
+
flexDirection: 'column',
|
|
213
|
+
alignItems: 'center',
|
|
214
|
+
justifyContent: 'center',
|
|
215
|
+
minHeight: '100vh',
|
|
216
|
+
fontFamily: 'system-ui'
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
createElement('h1', { style: { fontSize: '6rem', margin: 0 } }, '404'),
|
|
220
|
+
createElement('p', { style: { fontSize: '1.5rem', color: '#666' } }, 'Page not found'),
|
|
221
|
+
createElement('a', {
|
|
222
|
+
href: '/',
|
|
223
|
+
style: { color: '#10b981', textDecoration: 'none', fontSize: '1.2rem' }
|
|
224
|
+
}, 'Go home')
|
|
227
225
|
);
|
|
228
226
|
}
|
|
229
227
|
|
|
@@ -288,7 +286,15 @@ async function compileFile(srcPath, outDir, filename, relativePath) {
|
|
|
288
286
|
|
|
289
287
|
code = fixImports(code);
|
|
290
288
|
|
|
291
|
-
const transpiler = new Bun.Transpiler({
|
|
289
|
+
const transpiler = new Bun.Transpiler({
|
|
290
|
+
loader,
|
|
291
|
+
tsconfig: {
|
|
292
|
+
compilerOptions: {
|
|
293
|
+
jsx: 'react-jsx',
|
|
294
|
+
jsxImportSource: 'react'
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
});
|
|
292
298
|
let compiled = await transpiler.transform(code);
|
|
293
299
|
|
|
294
300
|
compiled = fixRelativeImports(compiled);
|