void-plugin-hono-jsx 0.1.0-alpha.3 → 0.1.0-alpha.4
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/CHANGELOG.md +52 -0
- package/README.md +41 -12
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/dist/browser/client.d.ts +2 -1
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/client.js +76 -22
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/document-head.d.ts +1 -1
- package/dist/browser/document-head.d.ts.map +1 -1
- package/dist/browser/document-head.js +22 -1
- package/dist/browser/document-head.js.map +1 -1
- package/dist/browser/form-view.d.ts +10 -0
- package/dist/browser/form-view.d.ts.map +1 -0
- package/dist/browser/form-view.js +16 -0
- package/dist/browser/form-view.js.map +1 -0
- package/dist/browser/form.d.ts +28 -12
- package/dist/browser/form.d.ts.map +1 -1
- package/dist/browser/form.js +84 -23
- package/dist/browser/form.js.map +1 -1
- package/dist/browser/markdown.d.ts +15 -0
- package/dist/browser/markdown.d.ts.map +1 -0
- package/dist/browser/markdown.js +6 -0
- package/dist/browser/markdown.js.map +1 -0
- package/dist/browser/navigation.d.ts +13 -0
- package/dist/browser/navigation.d.ts.map +1 -0
- package/dist/browser/navigation.js +83 -0
- package/dist/browser/navigation.js.map +1 -0
- package/dist/browser/pages.d.ts +33 -3
- package/dist/browser/pages.d.ts.map +1 -1
- package/dist/browser/pages.js +76 -13
- package/dist/browser/pages.js.map +1 -1
- package/dist/plugins/hono-islands.d.ts +1 -1
- package/dist/plugins/hono-islands.d.ts.map +1 -1
- package/dist/plugins/hono-islands.js +156 -24
- package/dist/plugins/hono-islands.js.map +1 -1
- package/dist/plugins/hono-markdown.d.ts +4 -0
- package/dist/plugins/hono-markdown.d.ts.map +1 -0
- package/dist/plugins/hono-markdown.js +91 -0
- package/dist/plugins/hono-markdown.js.map +1 -0
- package/dist/plugins/hono-pages.d.ts +9 -1
- package/dist/plugins/hono-pages.d.ts.map +1 -1
- package/dist/plugins/hono-pages.js +51 -15
- package/dist/plugins/hono-pages.js.map +1 -1
- package/dist/plugins/markdown-api.d.ts +10 -0
- package/dist/plugins/markdown-api.d.ts.map +1 -0
- package/dist/plugins/markdown-api.js +13 -0
- package/dist/plugins/markdown-api.js.map +1 -0
- package/dist/plugins/markdown-compiler.d.ts +43 -0
- package/dist/plugins/markdown-compiler.d.ts.map +1 -0
- package/dist/plugins/markdown-compiler.js +91 -0
- package/dist/plugins/markdown-compiler.js.map +1 -0
- package/dist/plugins/resolve-component.d.ts +3 -0
- package/dist/plugins/resolve-component.d.ts.map +1 -0
- package/dist/plugins/resolve-component.js +15 -0
- package/dist/plugins/resolve-component.js.map +1 -0
- package/dist/plugins/runtime-paths.d.ts +1 -0
- package/dist/plugins/runtime-paths.d.ts.map +1 -1
- package/dist/plugins/runtime-paths.js +2 -0
- package/dist/plugins/runtime-paths.js.map +1 -1
- package/dist/server/form-view.d.ts +10 -0
- package/dist/server/form-view.d.ts.map +1 -0
- package/dist/server/form-view.js +16 -0
- package/dist/server/form-view.js.map +1 -0
- package/dist/server/form.d.ts +28 -12
- package/dist/server/form.d.ts.map +1 -1
- package/dist/server/form.js +84 -23
- package/dist/server/form.js.map +1 -1
- package/dist/server/markdown.d.ts +15 -0
- package/dist/server/markdown.d.ts.map +1 -0
- package/dist/server/markdown.js +6 -0
- package/dist/server/markdown.js.map +1 -0
- package/dist/server/pages.d.ts +33 -3
- package/dist/server/pages.d.ts.map +1 -1
- package/dist/server/pages.js +76 -13
- package/dist/server/pages.js.map +1 -1
- package/package.json +21 -3
- package/src/plugins/hono-islands.ts +121 -23
- package/src/plugins/hono-markdown.ts +78 -0
- package/src/plugins/hono-pages.ts +50 -14
- package/src/plugins/markdown-api.ts +17 -0
- package/src/plugins/markdown-compiler.ts +77 -0
- package/src/plugins/resolve-component.ts +12 -0
- package/src/plugins/runtime-paths.ts +2 -0
- package/src/runtime/client.tsx +66 -24
- package/src/runtime/document-head.ts +20 -1
- package/src/runtime/form-view.tsx +23 -0
- package/src/runtime/form.ts +82 -41
- package/src/runtime/markdown.ts +7 -0
- package/src/runtime/navigation.ts +72 -0
- package/src/runtime/pages.tsx +77 -15
|
@@ -1,29 +1,54 @@
|
|
|
1
1
|
import { realpathSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { normalizePath } from 'vite';
|
|
4
|
-
import { pagesRuntimePath, clientRuntimePath, publicRuntimeModules } from './runtime-paths.js';
|
|
4
|
+
import { pagesRuntimePath, clientRuntimePath, markdownRuntimePath, publicRuntimeModules } from './runtime-paths.js';
|
|
5
5
|
import { generateComponentManifest, resolvePagesDir, resolveStaticPageDataBuildOptions, scanPages } from 'void/pages';
|
|
6
|
+
import { parseCacheFor } from 'void/pages-prefetch';
|
|
6
7
|
import { honoJsx } from './hono-jsx.js';
|
|
7
8
|
import { honoIslands } from './hono-islands.js';
|
|
9
|
+
import { markdownApi, markdownDiagnostic } from './markdown-api.js';
|
|
8
10
|
import { assertSupportedFrameworks } from './compatibility.js';
|
|
9
11
|
const rendererId = 'virtual:void-pages-renderer';
|
|
10
12
|
const clientId = 'virtual:void-pages-client';
|
|
13
|
+
function assertComponentFile(file, kind, markdown = false) {
|
|
14
|
+
if (/\.md$/.test(file)) {
|
|
15
|
+
if (markdown && kind === 'page')
|
|
16
|
+
return;
|
|
17
|
+
if (markdown)
|
|
18
|
+
throw new Error('Hono Markdown: layouts must remain TSX/JSX: ' + file);
|
|
19
|
+
throw new Error(`${markdownDiagnostic} ${kind}: ${file}`);
|
|
20
|
+
}
|
|
21
|
+
if (!/\.[jt]sx$/.test(file))
|
|
22
|
+
throw new Error(`Hono Pages: only standard TSX/JSX ${kind}s are supported: ${file}.`);
|
|
23
|
+
}
|
|
24
|
+
function clientOptions(options) {
|
|
25
|
+
const viewTransitions = options.viewTransitions ?? false;
|
|
26
|
+
const prefetchHoverDelay = options.prefetch?.hoverDelay ?? 75;
|
|
27
|
+
if (typeof viewTransitions !== 'boolean')
|
|
28
|
+
throw new Error('Hono Pages: viewTransitions must be a boolean.');
|
|
29
|
+
if (!Number.isFinite(prefetchHoverDelay) || prefetchHoverDelay < 0)
|
|
30
|
+
throw new Error('Hono Pages: prefetch.hoverDelay must be a finite non-negative number.');
|
|
31
|
+
const prefetchDefaultCacheFor = parseCacheFor(options.prefetch?.cacheFor ?? '30s');
|
|
32
|
+
if (![prefetchDefaultCacheFor.stale, prefetchDefaultCacheFor.expires].every(value => Number.isFinite(value) && value >= 0) || prefetchDefaultCacheFor.stale > prefetchDefaultCacheFor.expires) {
|
|
33
|
+
throw new Error('Hono Pages: prefetch.cacheFor must have finite non-negative durations, with stale <= expires.');
|
|
34
|
+
}
|
|
35
|
+
return { viewTransitions, prefetchHoverDelay, prefetchDefaultCacheFor };
|
|
36
|
+
}
|
|
11
37
|
/** Experimental Pages contract verified against Void 0.26.1 and 0.27.0. */
|
|
12
|
-
export function
|
|
38
|
+
export function voidHonoJsx(options = {}) {
|
|
39
|
+
const navigationOptions = clientOptions(options);
|
|
13
40
|
const root = process.cwd();
|
|
14
41
|
const pagesDir = resolvePagesDir(root);
|
|
15
42
|
const staticData = resolveStaticPageDataBuildOptions(root);
|
|
16
43
|
let scan;
|
|
44
|
+
let markdown;
|
|
17
45
|
async function rescan() {
|
|
18
46
|
scan = await scanPages(root, { pagesDir });
|
|
19
47
|
for (const layout of [...scan.layouts, ...scan.namedLayouts]) {
|
|
20
|
-
|
|
21
|
-
throw new Error('Hono Pages: only standard TSX/JSX layouts are supported.');
|
|
48
|
+
assertComponentFile(layout.filePath, 'layout');
|
|
22
49
|
}
|
|
23
50
|
for (const page of scan.pages) {
|
|
24
|
-
|
|
25
|
-
throw new Error(`Hono Pages: only standard TSX/JSX pages are supported: ${page.componentPath}.`);
|
|
26
|
-
}
|
|
51
|
+
assertComponentFile(page.componentPath, 'page', Boolean(markdown));
|
|
27
52
|
if (staticData.enabled && page.methods.some((method) => method === 'action' || method === 'actions')) {
|
|
28
53
|
throw new Error(`Hono Pages: actions require a server and cannot be used with static output: ${page.componentPath}.`);
|
|
29
54
|
}
|
|
@@ -40,6 +65,12 @@ export function voidHonoPages() {
|
|
|
40
65
|
build: { manifest: true, rollupOptions: { input: { 'pages-client': clientId } } },
|
|
41
66
|
};
|
|
42
67
|
},
|
|
68
|
+
configResolved: {
|
|
69
|
+
order: 'pre',
|
|
70
|
+
handler(config) {
|
|
71
|
+
markdown = markdownApi(config.plugins);
|
|
72
|
+
},
|
|
73
|
+
},
|
|
43
74
|
configEnvironment() {
|
|
44
75
|
const modules = Object.keys(publicRuntimeModules);
|
|
45
76
|
const packages = [...new Set(modules.map((id) => id.slice(0, id.lastIndexOf('/'))))];
|
|
@@ -77,7 +108,7 @@ export function voidHonoPages() {
|
|
|
77
108
|
resolveId(id) {
|
|
78
109
|
if (id === rendererId || id === clientId)
|
|
79
110
|
return `\0${id}`;
|
|
80
|
-
if (id === pagesRuntimePath || id === clientRuntimePath)
|
|
111
|
+
if (id === pagesRuntimePath || id === clientRuntimePath || id === markdownRuntimePath)
|
|
81
112
|
return { id: realpathSync(id), external: false };
|
|
82
113
|
const runtime = publicRuntimeModules[id];
|
|
83
114
|
if (runtime)
|
|
@@ -89,7 +120,7 @@ export function voidHonoPages() {
|
|
|
89
120
|
const currentScan = scan ?? await rescan();
|
|
90
121
|
const serverSnapshot = id === `\0${rendererId}` && this.environment.mode === 'dev';
|
|
91
122
|
const manifestScan = id === `\0${clientId}`
|
|
92
|
-
? { ...currentScan, pages: currentScan.pages.filter((page) => !page.island) }
|
|
123
|
+
? { ...currentScan, pages: currentScan.pages.filter((page) => !page.island), layouts: currentScan.layouts.filter((layout) => !layout.island), namedLayouts: currentScan.namedLayouts.filter((layout) => !layout.island) }
|
|
93
124
|
: serverSnapshot ? { ...currentScan, pages: currentScan.pages.filter((page) => page.renderMode !== 'client') } : currentScan;
|
|
94
125
|
let manifest = generateComponentManifest(manifestScan, pagesDir);
|
|
95
126
|
if (serverSnapshot) {
|
|
@@ -108,10 +139,13 @@ export function voidHonoPages() {
|
|
|
108
139
|
if (id === `\0${clientId}` && !currentScan.pages.some((page) => !page.island))
|
|
109
140
|
return 'export {};';
|
|
110
141
|
if (id === `\0${rendererId}`) {
|
|
142
|
+
const markdownScriptIds = [...(markdown?.getClientScripts().keys() ?? [])];
|
|
111
143
|
return `
|
|
112
144
|
import { jsx } from 'hono/jsx';
|
|
113
|
-
import {
|
|
114
|
-
|
|
145
|
+
${markdown ? `import { MarkdownContext } from ${JSON.stringify(markdownRuntimePath)};` : ''}
|
|
146
|
+
const markdownScriptIds = new Set(${JSON.stringify(markdownScriptIds)});
|
|
147
|
+
import { createSsrRouter, idleNavigationState } from 'void/pages-client';
|
|
148
|
+
import { PageContext, RouterContext, NavigationContext } from ${JSON.stringify(pagesRuntimePath)};
|
|
115
149
|
import { serializePageData } from 'void/pages-server';
|
|
116
150
|
import { renderHeadToString, renderHtmlAttrs, renderBodyAttrs } from 'void/pages-head';
|
|
117
151
|
${manifest}
|
|
@@ -119,7 +153,7 @@ export async function renderPage(pageObj, assetTags) {
|
|
|
119
153
|
if (${JSON.stringify(staticData.enabled)} && pageObj.deferredKeys) throw new Error('Hono Pages: deferred props cannot be statically prerendered; remove defer().');
|
|
120
154
|
const load = components[pageObj.component];
|
|
121
155
|
if (!load) throw new Error('Hono Pages: unknown page component ' + pageObj.component);
|
|
122
|
-
const { default: Page } = await load();
|
|
156
|
+
const { default: Page, frontmatter = {}, headings = [] } = await load();
|
|
123
157
|
if (typeof Page !== 'function') throw new Error('Hono Pages: a page must export a component function.');
|
|
124
158
|
let content = jsx(Page, pageObj.props);
|
|
125
159
|
const ids = layoutTree[pageObj.component] ?? [];
|
|
@@ -128,21 +162,23 @@ export async function renderPage(pageObj, assetTags) {
|
|
|
128
162
|
if (typeof Layout !== 'function') throw new Error('Hono Pages: a layout must export a component function.');
|
|
129
163
|
content = jsx(Layout, { children: content });
|
|
130
164
|
}
|
|
131
|
-
|
|
165
|
+
${markdown ? 'content = jsx(MarkdownContext.Provider, { value: { frontmatter, headings, props: pageObj.props }, children: content });' : ''}
|
|
166
|
+
const markup = await jsx(RouterContext.Provider, { value: createSsrRouter(pageObj.url, pageObj.params), children: jsx(PageContext.Provider, { value: pageObj, children: jsx(NavigationContext.Provider, { value: idleNavigationState(), children: content }) }) }).toString();
|
|
167
|
+
const appHtml = await jsx('div', { id: 'app', 'data-md-script': markdownScriptIds.has(pageObj.component) ? pageObj.component : undefined, ${markdown ? "'data-hono-markdown': JSON.stringify({ frontmatter, headings })," : ''} dangerouslySetInnerHTML: { __html: markup } }).toString();
|
|
132
168
|
const head = pageObj.head;
|
|
133
169
|
const body = pageObj.deferredKeys ? assetTags.body.replaceAll('<script type="module"', '<script async type="module"') : assetTags.body;
|
|
134
170
|
return '<!doctype html><html' + (head ? renderHtmlAttrs(head) : '') + '><head>'
|
|
135
171
|
+ (head ? renderHeadToString(head) : '') + assetTags.css + assetTags.preloads
|
|
136
172
|
+ '</head><body' + (head ? renderBodyAttrs(head) : '') + '>'
|
|
137
173
|
+ '<script id="__VOID_PAGE_DATA__" type="application/json">' + serializePageData(pageObj) + '</script>'
|
|
138
|
-
+
|
|
174
|
+
+ appHtml + body + '</body></html>';
|
|
139
175
|
}
|
|
140
176
|
`;
|
|
141
177
|
}
|
|
142
178
|
return `
|
|
143
179
|
import { startHonoPages } from ${JSON.stringify(clientRuntimePath)};
|
|
144
180
|
${manifest}
|
|
145
|
-
await startHonoPages({ components, layoutTree, routeMeta, matchRoute, staticPageData: ${JSON.stringify(staticData.enabled)}, staticPageDataFastPath: ${JSON.stringify(staticData.fastPath)} });
|
|
181
|
+
await startHonoPages({ components, layoutTree, routeMeta, matchRoute, staticPageData: ${JSON.stringify(staticData.enabled)}, staticPageDataFastPath: ${JSON.stringify(staticData.fastPath)} }, ${JSON.stringify(navigationOptions)});
|
|
146
182
|
`;
|
|
147
183
|
},
|
|
148
184
|
}];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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ACzB,CAAC,CAAC,CAAC;oBACH,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,QAAQ,CAAC;gBAClD,CAAC;gBACD,IAAI,EAAE,KAAK,KAAK,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;oBAAE,OAAO,YAAY,CAAC;gBACnG,IAAI,EAAE,KAAK,KAAK,UAAU,EAAE,EAAE,CAAC;oBAC7B,OAAO;;;6CAG8B,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC;;;EAG3E,QAAQ;;QAEF,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;CAqBzC,CAAC;gBACI,CAAC;gBACD,OAAO;iCACoB,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC;EAChE,QAAQ;wFAC8E,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,6BAA6B,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC;CACzL,CAAC;YACE,CAAC;SACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { realpathSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { normalizePath } from 'vite';\nimport { pagesRuntimePath, clientRuntimePath, publicRuntimeModules } from './runtime-paths.ts';\nimport { generateComponentManifest, resolvePagesDir, resolveStaticPageDataBuildOptions, scanPages, type PageScanResult } from 'void/pages';\nimport type { Plugin } from 'vite';\nimport { honoJsx } from './hono-jsx.ts';\nimport { honoIslands } from './hono-islands.ts';\nimport { assertSupportedFrameworks } from './compatibility.ts';\n\nconst rendererId = 'virtual:void-pages-renderer';\nconst clientId = 'virtual:void-pages-client';\n\n/** Experimental Pages contract verified against Void 0.26.1 and 0.27.0. */\nexport function voidHonoPages(): Plugin[] {\n const root = process.cwd();\n const pagesDir = resolvePagesDir(root);\n const staticData = resolveStaticPageDataBuildOptions(root);\n let scan: PageScanResult | undefined;\n\n async function rescan() {\n scan = await scanPages(root, { pagesDir });\n for (const layout of [...scan.layouts, ...scan.namedLayouts]) {\n if (layout.island || !/\\.[jt]sx$/.test(layout.filePath)) throw new Error('Hono Pages: only standard TSX/JSX layouts are supported.');\n }\n for (const page of scan.pages) {\n if (!/\\.[jt]sx$/.test(page.componentPath)) {\n throw new Error(`Hono Pages: only standard TSX/JSX pages are supported: ${page.componentPath}.`);\n }\n if (staticData.enabled && page.methods.some((method) => method === 'action' || method === 'actions')) {\n throw new Error(`Hono Pages: actions require a server and cannot be used with static output: ${page.componentPath}.`);\n }\n }\n return scan;\n }\n\n return [honoIslands(), honoJsx(), {\n name: 'void-hono:pages',\n enforce: 'pre',\n config(config) {\n assertSupportedFrameworks({ root: resolve(config.root ?? root), viteVersion: this?.meta?.viteVersion });\n return {\n resolve: { dedupe: ['hono'] },\n build: { manifest: true, rollupOptions: { input: { 'pages-client': clientId } } },\n };\n },\n configEnvironment() {\n const modules = Object.keys(publicRuntimeModules);\n const packages = [...new Set(modules.map((id) => id.slice(0, id.lastIndexOf('/'))))];\n return { optimizeDeps: { exclude: ['hono', ...modules] }, resolve: { noExternal: ['hono', ...packages] } };\n },\n async buildStart() {\n await rescan();\n },\n configureServer(server) {\n const clear = (file: string) => {\n if (normalizePath(file).startsWith(normalizePath(pagesDir) + '/')) scan = undefined;\n };\n server.watcher.on('add', clear);\n server.watcher.on('unlink', clear);\n server.httpServer?.once('close', () => { server.watcher.off('add', clear); server.watcher.off('unlink', clear); });\n },\n async hotUpdate({ file, type, modules, timestamp }) {\n if (!normalizePath(file).startsWith(normalizePath(pagesDir) + '/')) return;\n await rescan();\n if (type !== 'update') return [];\n const invalidated = new Set<(typeof modules)[number]>();\n for (const module of modules) this.environment.moduleGraph.invalidateModule(module, invalidated, timestamp, true);\n for (const id of [rendererId, clientId]) {\n const module = this.environment.moduleGraph.getModuleById(`\\0${id}`);\n if (module) this.environment.moduleGraph.invalidateModule(module, invalidated, timestamp, true);\n }\n this.environment.hot.send({ type: 'full-reload' });\n return [];\n },\n resolveId(id) {\n if (id === rendererId || id === clientId) return `\\0${id}`;\n if (id === pagesRuntimePath || id === clientRuntimePath) return { id: realpathSync(id), external: false };\n const runtime = publicRuntimeModules[id];\n if (runtime) return { id: realpathSync(this.environment.config.consumer === 'client' ? runtime.client : runtime.server), external: false };\n },\n async load(id) {\n if (id !== `\\0${rendererId}` && id !== `\\0${clientId}`) return;\n const currentScan = scan ?? await rescan();\n const serverSnapshot = id === `\\0${rendererId}` && this.environment.mode === 'dev';\n const manifestScan = id === `\\0${clientId}`\n ? { ...currentScan, pages: currentScan.pages.filter((page) => !page.island) }\n : serverSnapshot ? { ...currentScan, pages: currentScan.pages.filter((page) => page.renderMode !== 'client') } : currentScan;\n let manifest = generateComponentManifest(manifestScan, pagesDir);\n if (serverSnapshot) {\n // A request can retain the old renderer while the worker module runner\n // reloads. Capture components with its providers instead of importing\n // a new generation into an in-flight render. Browser-only pages remain\n // absent from this server graph; production keeps lazy imports.\n const imports: string[] = [];\n manifest = manifest.replace(/\\(\\) => import\\((\"(?:[^\"\\\\]|\\\\.)*\")\\)/g, (_, path: string) => {\n const name = `__honoPageSnapshot${imports.length}`;\n imports.push(`import * as ${name} from ${path};`);\n return `() => ${name}`;\n });\n manifest = imports.join('\\n') + '\\n' + manifest;\n }\n if (id === `\\0${clientId}` && !currentScan.pages.some((page) => !page.island)) return 'export {};';\n if (id === `\\0${rendererId}`) {\n return `\nimport { jsx } from 'hono/jsx';\nimport { createSsrRouter } from 'void/pages-client';\nimport { PageContext, RouterContext } from ${JSON.stringify(pagesRuntimePath)};\nimport { serializePageData } from 'void/pages-server';\nimport { renderHeadToString, renderHtmlAttrs, renderBodyAttrs } from 'void/pages-head';\n${manifest}\nexport async function renderPage(pageObj, assetTags) {\n if (${JSON.stringify(staticData.enabled)} && pageObj.deferredKeys) throw new Error('Hono Pages: deferred props cannot be statically prerendered; remove defer().');\n const load = components[pageObj.component];\n if (!load) throw new Error('Hono Pages: unknown page component ' + pageObj.component);\n const { default: Page } = await load();\n if (typeof Page !== 'function') throw new Error('Hono Pages: a page must export a component function.');\n let content = jsx(Page, pageObj.props);\n const ids = layoutTree[pageObj.component] ?? [];\n const layouts = await Promise.all(ids.map(async (id) => (await components[id]()).default));\n for (const Layout of layouts.reverse()) {\n if (typeof Layout !== 'function') throw new Error('Hono Pages: a layout must export a component function.');\n content = jsx(Layout, { children: content });\n }\n const markup = await jsx(RouterContext.Provider, { value: createSsrRouter(pageObj.url, pageObj.params), children: jsx(PageContext.Provider, { value: pageObj, children: content }) }).toString();\n const head = pageObj.head;\n const body = pageObj.deferredKeys ? assetTags.body.replaceAll('<script type=\"module\"', '<script async type=\"module\"') : assetTags.body;\n return '<!doctype html><html' + (head ? renderHtmlAttrs(head) : '') + '><head>'\n + (head ? renderHeadToString(head) : '') + assetTags.css + assetTags.preloads\n + '</head><body' + (head ? renderBodyAttrs(head) : '') + '>'\n + '<script id=\"__VOID_PAGE_DATA__\" type=\"application/json\">' + serializePageData(pageObj) + '</script>'\n + '<div id=\"app\">' + markup + '</div>' + body + '</body></html>';\n}\n`;\n }\n return `\nimport { startHonoPages } from ${JSON.stringify(clientRuntimePath)};\n${manifest}\nawait startHonoPages({ components, layoutTree, routeMeta, matchRoute, staticPageData: ${JSON.stringify(staticData.enabled)}, staticPageDataFastPath: ${JSON.stringify(staticData.fastPath)} });\n`;\n },\n }];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hono-pages.js","sourceRoot":"","sources":["../../src/plugins/hono-pages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,mBAAmB,EA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,CAAC,CAAC,CAAC,kEAAkE,CAAC,CAAC,CAAC,EAAE;;;;;;;;;CAS/N,CAAC;gBACI,CAAC;gBACD,OAAO;iCACoB,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC;EAChE,QAAQ;wFAC8E,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,6BAA6B,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC;CACjO,CAAC;YACE,CAAC;SACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { realpathSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { normalizePath } from 'vite';\nimport { pagesRuntimePath, clientRuntimePath, markdownRuntimePath, publicRuntimeModules } from './runtime-paths.ts';\nimport { generateComponentManifest, resolvePagesDir, resolveStaticPageDataBuildOptions, scanPages, type PageScanResult } from 'void/pages';\nimport type { Plugin } from 'vite';\nimport { parseCacheFor, type CacheForInput } from 'void/pages-prefetch';\nimport { honoJsx } from './hono-jsx.ts';\nimport { honoIslands } from './hono-islands.ts';\nimport { markdownApi, markdownDiagnostic, type HonoMarkdownApi } from './markdown-api.ts';\nimport { assertSupportedFrameworks } from './compatibility.ts';\n\nconst rendererId = 'virtual:void-pages-renderer';\nconst clientId = 'virtual:void-pages-client';\n\nfunction assertComponentFile(file: string, kind: 'page' | 'layout', markdown = false) {\n if (/\\.md$/.test(file)) { if (markdown && kind === 'page') return; if (markdown) throw new Error('Hono Markdown: layouts must remain TSX/JSX: ' + file); throw new Error(`${markdownDiagnostic} ${kind}: ${file}`); }\n if (!/\\.[jt]sx$/.test(file)) throw new Error(`Hono Pages: only standard TSX/JSX ${kind}s are supported: ${file}.`);\n}\n\n\nexport type HonoJsxOptions = {\n viewTransitions?: boolean;\n prefetch?: { hoverDelay?: number; cacheFor?: CacheForInput };\n};\n\nfunction clientOptions(options: HonoJsxOptions) {\n const viewTransitions = options.viewTransitions ?? false;\n const prefetchHoverDelay = options.prefetch?.hoverDelay ?? 75;\n if (typeof viewTransitions !== 'boolean') throw new Error('Hono Pages: viewTransitions must be a boolean.');\n if (!Number.isFinite(prefetchHoverDelay) || prefetchHoverDelay < 0) throw new Error('Hono Pages: prefetch.hoverDelay must be a finite non-negative number.');\n const prefetchDefaultCacheFor = parseCacheFor(options.prefetch?.cacheFor ?? '30s');\n if (![prefetchDefaultCacheFor.stale, prefetchDefaultCacheFor.expires].every(value => Number.isFinite(value) && value >= 0) || prefetchDefaultCacheFor.stale > prefetchDefaultCacheFor.expires) {\n throw new Error('Hono Pages: prefetch.cacheFor must have finite non-negative durations, with stale <= expires.');\n }\n return { viewTransitions, prefetchHoverDelay, prefetchDefaultCacheFor };\n}\n\n/** Experimental Pages contract verified against Void 0.26.1 and 0.27.0. */\nexport function voidHonoJsx(options: HonoJsxOptions = {}): Plugin[] {\n const navigationOptions = clientOptions(options);\n const root = process.cwd();\n const pagesDir = resolvePagesDir(root);\n const staticData = resolveStaticPageDataBuildOptions(root);\n let scan: PageScanResult | undefined;\n let markdown: HonoMarkdownApi | undefined;\n\n async function rescan() {\n scan = await scanPages(root, { pagesDir });\n for (const layout of [...scan.layouts, ...scan.namedLayouts]) {\n assertComponentFile(layout.filePath, 'layout');\n }\n for (const page of scan.pages) {\n assertComponentFile(page.componentPath, 'page', Boolean(markdown));\n if (staticData.enabled && page.methods.some((method) => method === 'action' || method === 'actions')) {\n throw new Error(`Hono Pages: actions require a server and cannot be used with static output: ${page.componentPath}.`);\n }\n }\n return scan;\n }\n\n return [honoIslands(), honoJsx(), {\n name: 'void-hono:pages',\n enforce: 'pre',\n config(config) {\n assertSupportedFrameworks({ root: resolve(config.root ?? root), viteVersion: this?.meta?.viteVersion });\n return {\n resolve: { dedupe: ['hono'] },\n build: { manifest: true, rollupOptions: { input: { 'pages-client': clientId } } },\n };\n },\n configResolved: {\n order: 'pre',\n handler(config) {\n markdown = markdownApi(config.plugins);\n },\n },\n configEnvironment() {\n const modules = Object.keys(publicRuntimeModules);\n const packages = [...new Set(modules.map((id) => id.slice(0, id.lastIndexOf('/'))))];\n return { optimizeDeps: { exclude: ['hono', ...modules] }, resolve: { noExternal: ['hono', ...packages] } };\n },\n async buildStart() {\n await rescan();\n },\n configureServer(server) {\n const clear = (file: string) => {\n if (normalizePath(file).startsWith(normalizePath(pagesDir) + '/')) scan = undefined;\n };\n server.watcher.on('add', clear);\n server.watcher.on('unlink', clear);\n server.httpServer?.once('close', () => { server.watcher.off('add', clear); server.watcher.off('unlink', clear); });\n },\n async hotUpdate({ file, type, modules, timestamp }) {\n if (!normalizePath(file).startsWith(normalizePath(pagesDir) + '/')) return;\n await rescan();\n if (type !== 'update') return [];\n const invalidated = new Set<(typeof modules)[number]>();\n for (const module of modules) this.environment.moduleGraph.invalidateModule(module, invalidated, timestamp, true);\n for (const id of [rendererId, clientId]) {\n const module = this.environment.moduleGraph.getModuleById(`\\0${id}`);\n if (module) this.environment.moduleGraph.invalidateModule(module, invalidated, timestamp, true);\n }\n this.environment.hot.send({ type: 'full-reload' });\n return [];\n },\n resolveId(id) {\n if (id === rendererId || id === clientId) return `\\0${id}`;\n if (id === pagesRuntimePath || id === clientRuntimePath || id === markdownRuntimePath) return { id: realpathSync(id), external: false };\n const runtime = publicRuntimeModules[id];\n if (runtime) return { id: realpathSync(this.environment.config.consumer === 'client' ? runtime.client : runtime.server), external: false };\n },\n async load(id) {\n if (id !== `\\0${rendererId}` && id !== `\\0${clientId}`) return;\n const currentScan = scan ?? await rescan();\n const serverSnapshot = id === `\\0${rendererId}` && this.environment.mode === 'dev';\n const manifestScan = id === `\\0${clientId}`\n ? { ...currentScan, pages: currentScan.pages.filter((page) => !page.island), layouts: currentScan.layouts.filter((layout) => !layout.island), namedLayouts: currentScan.namedLayouts.filter((layout) => !layout.island) }\n : serverSnapshot ? { ...currentScan, pages: currentScan.pages.filter((page) => page.renderMode !== 'client') } : currentScan;\n let manifest = generateComponentManifest(manifestScan, pagesDir);\n if (serverSnapshot) {\n // A request can retain the old renderer while the worker module runner\n // reloads. Capture components with its providers instead of importing\n // a new generation into an in-flight render. Browser-only pages remain\n // absent from this server graph; production keeps lazy imports.\n const imports: string[] = [];\n manifest = manifest.replace(/\\(\\) => import\\((\"(?:[^\"\\\\]|\\\\.)*\")\\)/g, (_, path: string) => {\n const name = `__honoPageSnapshot${imports.length}`;\n imports.push(`import * as ${name} from ${path};`);\n return `() => ${name}`;\n });\n manifest = imports.join('\\n') + '\\n' + manifest;\n }\n if (id === `\\0${clientId}` && !currentScan.pages.some((page) => !page.island)) return 'export {};';\n if (id === `\\0${rendererId}`) {\n const markdownScriptIds = [...(markdown?.getClientScripts().keys() ?? [])];\n return `\nimport { jsx } from 'hono/jsx';\n${markdown ? `import { MarkdownContext } from ${JSON.stringify(markdownRuntimePath)};` : ''}\nconst markdownScriptIds = new Set(${JSON.stringify(markdownScriptIds)});\nimport { createSsrRouter, idleNavigationState } from 'void/pages-client';\nimport { PageContext, RouterContext, NavigationContext } from ${JSON.stringify(pagesRuntimePath)};\nimport { serializePageData } from 'void/pages-server';\nimport { renderHeadToString, renderHtmlAttrs, renderBodyAttrs } from 'void/pages-head';\n${manifest}\nexport async function renderPage(pageObj, assetTags) {\n if (${JSON.stringify(staticData.enabled)} && pageObj.deferredKeys) throw new Error('Hono Pages: deferred props cannot be statically prerendered; remove defer().');\n const load = components[pageObj.component];\n if (!load) throw new Error('Hono Pages: unknown page component ' + pageObj.component);\n const { default: Page, frontmatter = {}, headings = [] } = await load();\n if (typeof Page !== 'function') throw new Error('Hono Pages: a page must export a component function.');\n let content = jsx(Page, pageObj.props);\n const ids = layoutTree[pageObj.component] ?? [];\n const layouts = await Promise.all(ids.map(async (id) => (await components[id]()).default));\n for (const Layout of layouts.reverse()) {\n if (typeof Layout !== 'function') throw new Error('Hono Pages: a layout must export a component function.');\n content = jsx(Layout, { children: content });\n }\n ${markdown ? 'content = jsx(MarkdownContext.Provider, { value: { frontmatter, headings, props: pageObj.props }, children: content });' : ''}\n const markup = await jsx(RouterContext.Provider, { value: createSsrRouter(pageObj.url, pageObj.params), children: jsx(PageContext.Provider, { value: pageObj, children: jsx(NavigationContext.Provider, { value: idleNavigationState(), children: content }) }) }).toString();\n const appHtml = await jsx('div', { id: 'app', 'data-md-script': markdownScriptIds.has(pageObj.component) ? pageObj.component : undefined, ${markdown ? \"'data-hono-markdown': JSON.stringify({ frontmatter, headings }),\" : ''} dangerouslySetInnerHTML: { __html: markup } }).toString();\n const head = pageObj.head;\n const body = pageObj.deferredKeys ? assetTags.body.replaceAll('<script type=\"module\"', '<script async type=\"module\"') : assetTags.body;\n return '<!doctype html><html' + (head ? renderHtmlAttrs(head) : '') + '><head>'\n + (head ? renderHeadToString(head) : '') + assetTags.css + assetTags.preloads\n + '</head><body' + (head ? renderBodyAttrs(head) : '') + '>'\n + '<script id=\"__VOID_PAGE_DATA__\" type=\"application/json\">' + serializePageData(pageObj) + '</script>'\n + appHtml + body + '</body></html>';\n}\n`;\n }\n return `\nimport { startHonoPages } from ${JSON.stringify(clientRuntimePath)};\n${manifest}\nawait startHonoPages({ components, layoutTree, routeMeta, matchRoute, staticPageData: ${JSON.stringify(staticData.enabled)}, staticPageDataFastPath: ${JSON.stringify(staticData.fastPath)} }, ${JSON.stringify(navigationOptions)});\n`;\n },\n }];\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
export declare const markdownDiagnostic = "Hono Pages: Markdown requires voidHonoMarkdown() from void-plugin-hono-jsx/markdown/plugin and its optional parser dependencies. See docs/markdown.md.";
|
|
3
|
+
export type HonoMarkdownApi = {
|
|
4
|
+
adapter: 'hono';
|
|
5
|
+
clientEntryId: string;
|
|
6
|
+
getClientScripts(): Map<string, string>;
|
|
7
|
+
getGraphSource(file: string): string;
|
|
8
|
+
};
|
|
9
|
+
export declare function markdownApi(plugins: readonly Plugin[]): HonoMarkdownApi | undefined;
|
|
10
|
+
//# sourceMappingURL=markdown-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-api.d.ts","sourceRoot":"","sources":["../../src/plugins/markdown-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,eAAO,MAAM,kBAAkB,2JAA2J,CAAC;AAC3L,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACtC,CAAC;AACF,wBAAgB,WAAW,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,eAAe,GAAG,SAAS,CAOnF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const markdownDiagnostic = 'Hono Pages: Markdown requires voidHonoMarkdown() from void-plugin-hono-jsx/markdown/plugin and its optional parser dependencies. See docs/markdown.md.';
|
|
2
|
+
export function markdownApi(plugins) {
|
|
3
|
+
const markdown = plugins.filter(plugin => plugin.name === 'void-md');
|
|
4
|
+
if (markdown.length > 1)
|
|
5
|
+
throw new Error('Hono Pages: configure only one Markdown compiler.');
|
|
6
|
+
const plugin = markdown[0];
|
|
7
|
+
if (!plugin)
|
|
8
|
+
return;
|
|
9
|
+
if (plugin.api?.adapter !== 'hono')
|
|
10
|
+
throw new Error('Hono Pages: use voidHonoMarkdown(), not @void/md/plugin; the official compiler does not emit Hono components.');
|
|
11
|
+
return plugin.api;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=markdown-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-api.js","sourceRoot":"","sources":["../../src/plugins/markdown-api.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kBAAkB,GAAG,wJAAwJ,CAAC;AAO3L,MAAM,UAAU,WAAW,CAAC,OAA0B;IACpD,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IACrE,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IAC9F,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC3B,IAAI,CAAC,MAAM;QAAE,OAAO;IACpB,IAAI,MAAM,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,+GAA+G,CAAC,CAAC;IACrK,OAAO,MAAM,CAAC,GAAsB,CAAC;AACvC,CAAC","sourcesContent":["import type { Plugin } from 'vite';\n\nexport const markdownDiagnostic = 'Hono Pages: Markdown requires voidHonoMarkdown() from void-plugin-hono-jsx/markdown/plugin and its optional parser dependencies. See docs/markdown.md.';\nexport type HonoMarkdownApi = {\n adapter: 'hono';\n clientEntryId: string;\n getClientScripts(): Map<string, string>;\n getGraphSource(file: string): string;\n};\nexport function markdownApi(plugins: readonly Plugin[]): HonoMarkdownApi | undefined {\n const markdown = plugins.filter(plugin => plugin.name === 'void-md');\n if (markdown.length > 1) throw new Error('Hono Pages: configure only one Markdown compiler.');\n const plugin = markdown[0];\n if (!plugin) return;\n if (plugin.api?.adapter !== 'hono') throw new Error('Hono Pages: use voidHonoMarkdown(), not @void/md/plugin; the official compiler does not emit Hono components.');\n return plugin.api as HonoMarkdownApi;\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type Heading = {
|
|
2
|
+
depth: number;
|
|
3
|
+
slug: string;
|
|
4
|
+
text: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function extractMarkdown(source: string): {
|
|
7
|
+
body: string;
|
|
8
|
+
script: string;
|
|
9
|
+
imports: {
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
importName: string;
|
|
13
|
+
specifierRaw: string;
|
|
14
|
+
specifier: string;
|
|
15
|
+
hydrate: string;
|
|
16
|
+
}[];
|
|
17
|
+
graphSource: string;
|
|
18
|
+
clientCode: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function compileMarkdown(source: string): {
|
|
21
|
+
body: string;
|
|
22
|
+
script: string;
|
|
23
|
+
imports: {
|
|
24
|
+
start: number;
|
|
25
|
+
end: number;
|
|
26
|
+
importName: string;
|
|
27
|
+
specifierRaw: string;
|
|
28
|
+
specifier: string;
|
|
29
|
+
hydrate: string;
|
|
30
|
+
}[];
|
|
31
|
+
graphSource: string;
|
|
32
|
+
clientCode: string;
|
|
33
|
+
frontmatter: Record<string, unknown>;
|
|
34
|
+
headings: Heading[];
|
|
35
|
+
html: string;
|
|
36
|
+
};
|
|
37
|
+
export declare function renderChunks(html: string, names: Set<string>): ({
|
|
38
|
+
html: string;
|
|
39
|
+
} | {
|
|
40
|
+
name: string;
|
|
41
|
+
props: Record<string, string | boolean>;
|
|
42
|
+
})[];
|
|
43
|
+
//# sourceMappingURL=markdown-compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-compiler.d.ts","sourceRoot":"","sources":["../../src/plugins/markdown-compiler.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,OAAO,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AACpE,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM;;;;;;;;;;;;;EAU7C;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM;;;;;;;;;;;;;;;;EAgC7C;AAID,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC;UAE/B,MAAM;;UAAa,MAAM;WAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;KAkB/F"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import MarkdownExit from 'markdown-exit';
|
|
2
|
+
import { parseSync } from 'vite';
|
|
3
|
+
import { parseDocument } from 'yaml';
|
|
4
|
+
import { findIslandImports, editIslandSource } from 'void/pages-islands-plugin';
|
|
5
|
+
const unescapeAttribute = new MarkdownExit().utils.unescapeAll;
|
|
6
|
+
export function extractMarkdown(source) {
|
|
7
|
+
const match = source.match(/^<script\b[^>]*>([\s\S]*?)<\/script>\s*\n?/);
|
|
8
|
+
const script = match?.[1] ?? '';
|
|
9
|
+
const body = match ? source.slice(match[0].length) : source;
|
|
10
|
+
const imports = findIslandImports(script, 'markdown-script.ts');
|
|
11
|
+
const attributed = parseSync('markdown-script.ts', script).program.body.filter(node => node.type === 'ImportDeclaration' && node.attributes?.some(({ key }) => ('name' in key && key.name === 'island') || ('value' in key && key.value === 'island')));
|
|
12
|
+
if (attributed.length !== imports.length)
|
|
13
|
+
throw new Error('Hono Markdown: use one default component import with exactly one island attribute.');
|
|
14
|
+
const graphSource = imports.map(entry => script.slice(entry.start, entry.end)).join('\n');
|
|
15
|
+
const clientCode = editIslandSource(script, imports.map(entry => ({ start: entry.start, end: entry.end, text: '' }))).code.trim();
|
|
16
|
+
return { body, script, imports, graphSource, clientCode };
|
|
17
|
+
}
|
|
18
|
+
export function compileMarkdown(source) {
|
|
19
|
+
const extracted = extractMarkdown(source);
|
|
20
|
+
const match = extracted.body.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
|
|
21
|
+
let frontmatter = {};
|
|
22
|
+
if (match) {
|
|
23
|
+
const yaml = parseDocument(match[1], { uniqueKeys: true });
|
|
24
|
+
if (yaml.errors.length)
|
|
25
|
+
throw new Error('Hono Markdown: invalid frontmatter: ' + yaml.errors.map(error => error.message).join('; '));
|
|
26
|
+
const value = yaml.toJS({ maxAliasCount: 50 });
|
|
27
|
+
if (value !== null && (typeof value !== 'object' || Array.isArray(value)))
|
|
28
|
+
throw new Error('Hono Markdown: frontmatter must be a mapping.');
|
|
29
|
+
frontmatter = (value ?? {});
|
|
30
|
+
try {
|
|
31
|
+
JSON.stringify(frontmatter);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
throw new Error('Hono Markdown: frontmatter must be JSON serializable.');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const content = match ? extracted.body.slice(match[0].length) : extracted.body;
|
|
38
|
+
const compiler = new MarkdownExit({ html: true, linkify: true });
|
|
39
|
+
const tokens = compiler.parse(content, {});
|
|
40
|
+
const headings = [];
|
|
41
|
+
const slugs = new Map();
|
|
42
|
+
const authoredHtml = tokens.flatMap(token => token.type === 'html_block' || token.type === 'html_inline' ? [token.content] : (token.children ?? []).filter(child => child.type === 'html_inline').map(child => child.content)).join('\n');
|
|
43
|
+
const usedIds = new Set([...authoredHtml.matchAll(/\bid\s*=\s*(?:"([^"]*)"|'([^']*)')/g)].map(match => match[1] ?? match[2]));
|
|
44
|
+
for (let index = 0; index < tokens.length; index++) {
|
|
45
|
+
if (tokens[index].type !== 'heading_open')
|
|
46
|
+
continue;
|
|
47
|
+
const inline = tokens[index + 1];
|
|
48
|
+
const text = inline.children?.map(token => token.type === 'text' || token.type === 'code_inline' ? token.content : token.type === 'image' ? token.content : '').join('') ?? inline.content;
|
|
49
|
+
const base = text.toLowerCase().replace(/[^\p{L}\p{N} _-]/gu, '').trim().replace(/\s+/g, '-') || 'heading';
|
|
50
|
+
let count = slugs.get(base) ?? 0;
|
|
51
|
+
let slug = count ? `${base}-${count}` : base;
|
|
52
|
+
while (usedIds.has(slug)) {
|
|
53
|
+
count++;
|
|
54
|
+
slug = `${base}-${count}`;
|
|
55
|
+
}
|
|
56
|
+
slugs.set(base, count + 1);
|
|
57
|
+
usedIds.add(slug);
|
|
58
|
+
tokens[index].attrSet('id', slug);
|
|
59
|
+
headings.push({ depth: Number(tokens[index].tag.slice(1)), slug, text });
|
|
60
|
+
}
|
|
61
|
+
return { ...extracted, frontmatter, headings, html: compiler.renderer.render(tokens, compiler.options, {}) };
|
|
62
|
+
}
|
|
63
|
+
// Component tag splitting follows @void/md 0.27.0's emit-shared convention.
|
|
64
|
+
// Hono raw fragments preserve enclosing HTML across the component boundaries.
|
|
65
|
+
export function renderChunks(html, names) {
|
|
66
|
+
const tags = /<([A-Z]\w*)\s*((?:[^>/"']|"[^"]*"|'[^']*')*)\/\s*>|<([A-Z]\w*)\s*((?:[^>/"']|"[^"]*"|'[^']*')*)>([\s\S]*?)<\/\3\s*>/g;
|
|
67
|
+
const chunks = [];
|
|
68
|
+
let cursor = 0;
|
|
69
|
+
for (const match of html.matchAll(tags)) {
|
|
70
|
+
const name = match[1] ?? match[3];
|
|
71
|
+
if (!names.has(name))
|
|
72
|
+
continue;
|
|
73
|
+
if (match[5]?.trim())
|
|
74
|
+
throw new Error('Hono Markdown: island tag children are unsupported; pass literal attributes to a self-closing tag.');
|
|
75
|
+
if (match.index > cursor)
|
|
76
|
+
chunks.push({ html: html.slice(cursor, match.index) });
|
|
77
|
+
const props = Object.create(null);
|
|
78
|
+
const attrs = match[2] ?? match[4] ?? '';
|
|
79
|
+
const attrRe = /(\w[\w-]*)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s]+)))?/g;
|
|
80
|
+
for (const attr of attrs.matchAll(attrRe)) {
|
|
81
|
+
const value = attr[2] ?? attr[3] ?? attr[4];
|
|
82
|
+
props[attr[1]] = value === undefined ? true : unescapeAttribute(value);
|
|
83
|
+
}
|
|
84
|
+
chunks.push({ name, props });
|
|
85
|
+
cursor = match.index + match[0].length;
|
|
86
|
+
}
|
|
87
|
+
if (cursor < html.length)
|
|
88
|
+
chunks.push({ html: html.slice(cursor) });
|
|
89
|
+
return chunks;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=markdown-compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-compiler.js","sourceRoot":"","s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GAAG,MAAM;YAAE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACjF,MAAM,KAAK,GAAqC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpE,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACzC,MAAM,MAAM,GAAG,yDAAyD,CAAC;QACzE,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;YAC5C,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QACzE,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAAC,MAAM,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACvE,CAAC;IACD,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM;QAAE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACpE,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import MarkdownExit from 'markdown-exit';\nimport { parseSync } from 'vite';\nimport { parseDocument } from 'yaml';\nimport { findIslandImports, editIslandSource } from 'void/pages-islands-plugin';\n\nconst unescapeAttribute = new MarkdownExit().utils.unescapeAll;\n\nexport type Heading = { depth: number; slug: string; text: string };\nexport function extractMarkdown(source: string) {\n const match = source.match(/^<script\\b[^>]*>([\\s\\S]*?)<\\/script>\\s*\\n?/);\n const script = match?.[1] ?? '';\n const body = match ? source.slice(match[0].length) : source;\n const imports = findIslandImports(script, 'markdown-script.ts');\n const attributed = parseSync('markdown-script.ts', script).program.body.filter(node => node.type === 'ImportDeclaration' && node.attributes?.some(({ key }) => ('name' in key && key.name === 'island') || ('value' in key && key.value === 'island')));\n if (attributed.length !== imports.length) throw new Error('Hono Markdown: use one default component import with exactly one island attribute.');\n const graphSource = imports.map(entry => script.slice(entry.start, entry.end)).join('\\n');\n const clientCode = editIslandSource(script, imports.map(entry => ({ start: entry.start, end: entry.end, text: '' }))).code.trim();\n return { body, script, imports, graphSource, clientCode };\n}\n\nexport function compileMarkdown(source: string) {\n const extracted = extractMarkdown(source);\n const match = extracted.body.match(/^---\\r?\\n([\\s\\S]*?)\\r?\\n---(?:\\r?\\n|$)/);\n let frontmatter: Record<string, unknown> = {};\n if (match) {\n const yaml = parseDocument(match[1], { uniqueKeys: true });\n if (yaml.errors.length) throw new Error('Hono Markdown: invalid frontmatter: ' + yaml.errors.map(error => error.message).join('; '));\n const value: unknown = yaml.toJS({ maxAliasCount: 50 });\n if (value !== null && (typeof value !== 'object' || Array.isArray(value))) throw new Error('Hono Markdown: frontmatter must be a mapping.');\n frontmatter = (value ?? {}) as Record<string, unknown>;\n try { JSON.stringify(frontmatter); } catch { throw new Error('Hono Markdown: frontmatter must be JSON serializable.'); }\n }\n const content = match ? extracted.body.slice(match[0].length) : extracted.body;\n const compiler = new MarkdownExit({ html: true, linkify: true });\n const tokens = compiler.parse(content, {});\n const headings: Heading[] = [];\n const slugs = new Map<string, number>();\n const authoredHtml = tokens.flatMap(token => token.type === 'html_block' || token.type === 'html_inline' ? [token.content] : (token.children ?? []).filter(child => child.type === 'html_inline').map(child => child.content)).join('\\n');\n const usedIds = new Set([...authoredHtml.matchAll(/\\bid\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)')/g)].map(match => match[1] ?? match[2]));\n for (let index = 0; index < tokens.length; index++) {\n if (tokens[index].type !== 'heading_open') continue;\n const inline = tokens[index + 1];\n const text = inline.children?.map(token => token.type === 'text' || token.type === 'code_inline' ? token.content : token.type === 'image' ? token.content : '').join('') ?? inline.content;\n const base = text.toLowerCase().replace(/[^\\p{L}\\p{N} _-]/gu, '').trim().replace(/\\s+/g, '-') || 'heading';\n let count = slugs.get(base) ?? 0;\n let slug = count ? `${base}-${count}` : base;\n while (usedIds.has(slug)) { count++; slug = `${base}-${count}`; }\n slugs.set(base, count + 1); usedIds.add(slug);\n tokens[index].attrSet('id', slug);\n headings.push({ depth: Number(tokens[index].tag.slice(1)), slug, text });\n }\n return { ...extracted, frontmatter, headings, html: compiler.renderer.render(tokens, compiler.options, {}) };\n}\n\n// Component tag splitting follows @void/md 0.27.0's emit-shared convention.\n// Hono raw fragments preserve enclosing HTML across the component boundaries.\nexport function renderChunks(html: string, names: Set<string>) {\n const tags = /<([A-Z]\\w*)\\s*((?:[^>/\"']|\"[^\"]*\"|'[^']*')*)\\/\\s*>|<([A-Z]\\w*)\\s*((?:[^>/\"']|\"[^\"]*\"|'[^']*')*)>([\\s\\S]*?)<\\/\\3\\s*>/g;\n const chunks: Array<{ html: string } | { name: string; props: Record<string, string | boolean> }> = [];\n let cursor = 0;\n for (const match of html.matchAll(tags)) {\n const name = match[1] ?? match[3];\n if (!names.has(name)) continue;\n if (match[5]?.trim()) throw new Error('Hono Markdown: island tag children are unsupported; pass literal attributes to a self-closing tag.');\n if (match.index > cursor) chunks.push({ html: html.slice(cursor, match.index) });\n const props: Record<string, string | boolean> = Object.create(null);\n const attrs = match[2] ?? match[4] ?? '';\n const attrRe = /(\\w[\\w-]*)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s]+)))?/g;\n for (const attr of attrs.matchAll(attrRe)) {\n const value = attr[2] ?? attr[3] ?? attr[4];\n props[attr[1]] = value === undefined ? true : unescapeAttribute(value);\n }\n chunks.push({ name, props }); cursor = match.index + match[0].length;\n }\n if (cursor < html.length) chunks.push({ html: html.slice(cursor) });\n return chunks;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-component.d.ts","sourceRoot":"","sources":["../../src/plugins/resolve-component.ts"],"names":[],"mappings":"AAGA,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,iBAO5F"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { statSync } from 'node:fs';
|
|
2
|
+
import { resolveSpecifier } from 'void/pages-islands-plugin';
|
|
3
|
+
/** Relative component imports also use Vite's directory/index convention. */
|
|
4
|
+
export function resolveComponent(specifier, importerDir, extensions) {
|
|
5
|
+
const target = resolveSpecifier(specifier, importerDir, extensions);
|
|
6
|
+
if (!target)
|
|
7
|
+
return null;
|
|
8
|
+
if (statSync(target).isFile())
|
|
9
|
+
return target;
|
|
10
|
+
if (!statSync(target).isDirectory())
|
|
11
|
+
return null;
|
|
12
|
+
const index = resolveSpecifier('./index', target, extensions);
|
|
13
|
+
return index && statSync(index).isFile() ? index : null;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=resolve-component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-component.js","sourceRoot":"","sources":["../../src/plugins/resolve-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,6EAA6E;AAC7E,MAAM,UAAU,gBAAgB,CAAC,SAAiB,EAAE,WAAmB,EAAE,UAAoB;IAC3F,MAAM,MAAM,GAAG,gBAAgB,CAAC,SAAS,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;IACpE,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE;QAAE,OAAO,MAAM,CAAC;IAC7C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE;QAAE,OAAO,IAAI,CAAC;IACjD,MAAM,KAAK,GAAG,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC9D,OAAO,KAAK,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1D,CAAC","sourcesContent":["import { statSync } from 'node:fs';\nimport { resolveSpecifier } from 'void/pages-islands-plugin';\n\n/** Relative component imports also use Vite's directory/index convention. */\nexport function resolveComponent(specifier: string, importerDir: string, extensions: string[]) {\n const target = resolveSpecifier(specifier, importerDir, extensions);\n if (!target) return null;\n if (statSync(target).isFile()) return target;\n if (!statSync(target).isDirectory()) return null;\n const index = resolveSpecifier('./index', target, extensions);\n return index && statSync(index).isFile() ? index : null;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-paths.d.ts","sourceRoot":"","sources":["../../src/plugins/runtime-paths.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,gBAAgB,QAAoG,CAAC;AAClI,eAAO,MAAM,iBAAiB,QAAuG,CAAC;AACtI,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"runtime-paths.d.ts","sourceRoot":"","sources":["../../src/plugins/runtime-paths.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,gBAAgB,QAAoG,CAAC;AAClI,eAAO,MAAM,iBAAiB,QAAuG,CAAC;AACtI,eAAO,MAAM,mBAAmB,QAAyG,CAAC;AAC1I,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAO9E,CAAC"}
|
|
@@ -4,7 +4,9 @@ import { fileURLToPath } from 'node:url';
|
|
|
4
4
|
const compiled = new URL(import.meta.url).pathname.endsWith('.js');
|
|
5
5
|
export const pagesRuntimePath = fileURLToPath(new URL(compiled ? '../server/pages.js' : '../runtime/pages.tsx', import.meta.url));
|
|
6
6
|
export const clientRuntimePath = fileURLToPath(new URL(compiled ? '../browser/client.js' : '../runtime/client.tsx', import.meta.url));
|
|
7
|
+
export const markdownRuntimePath = fileURLToPath(new URL(compiled ? '../server/markdown.js' : '../runtime/markdown.ts', import.meta.url));
|
|
7
8
|
export const publicRuntimeModules = compiled ? {
|
|
9
|
+
'void-plugin-hono-jsx/markdown': { server: markdownRuntimePath, client: fileURLToPath(new URL('../browser/markdown.js', import.meta.url)) },
|
|
8
10
|
'void-plugin-hono-jsx/pages': { server: pagesRuntimePath, client: fileURLToPath(new URL('../browser/pages.js', import.meta.url)) },
|
|
9
11
|
'void-plugin-hono-jsx/form': {
|
|
10
12
|
server: fileURLToPath(new URL('../server/form.js', import.meta.url)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-paths.js","sourceRoot":"","sources":["../../src/plugins/runtime-paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,kFAAkF;AAClF,oFAAoF;AACpF,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACnE,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,sBAAsB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAClI,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,uBAAuB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACtI,MAAM,CAAC,MAAM,oBAAoB,GAAuD,QAAQ,CAAC,CAAC,CAAC;IACjG,4BAA4B,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,aAAa,CAAC,IAAI,GAAG,CAAC,qBAAqB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE;IAClI,2BAA2B,EAAE;QAC3B,MAAM,EAAE,aAAa,CAAC,IAAI,GAAG,CAAC,mBAAmB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACpE,MAAM,EAAE,aAAa,CAAC,IAAI,GAAG,CAAC,oBAAoB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;KACtE;CACF,CAAC,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { fileURLToPath } from 'node:url';\n\n// Source fixtures use TSX; npm consumers use the precompiled environment entries.\n// Keep this adaptation in TypeScript so both emitted maps describe the actual code.\nconst compiled = new URL(import.meta.url).pathname.endsWith('.js');\nexport const pagesRuntimePath = fileURLToPath(new URL(compiled ? '../server/pages.js' : '../runtime/pages.tsx', import.meta.url));\nexport const clientRuntimePath = fileURLToPath(new URL(compiled ? '../browser/client.js' : '../runtime/client.tsx', import.meta.url));\nexport const publicRuntimeModules: Record<string, { server: string; client: string }> = compiled ? {\n 'void-plugin-hono-jsx/pages': { server: pagesRuntimePath, client: fileURLToPath(new URL('../browser/pages.js', import.meta.url)) },\n 'void-plugin-hono-jsx/form': {\n server: fileURLToPath(new URL('../server/form.js', import.meta.url)),\n client: fileURLToPath(new URL('../browser/form.js', import.meta.url)),\n },\n} : {};\n"]}
|
|
1
|
+
{"version":3,"file":"runtime-paths.js","sourceRoot":"","s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,IAAI,CAAC,GAAG,CAAC,CAAC;QACpE,MAAM,EAAE,aAAa,CAAC,IAAI,GAAG,CAAC,oBAAoB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;KACtE;CACF,CAAC,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { fileURLToPath } from 'node:url';\n\n// Source fixtures use TSX; npm consumers use the precompiled environment entries.\n// Keep this adaptation in TypeScript so both emitted maps describe the actual code.\nconst compiled = new URL(import.meta.url).pathname.endsWith('.js');\nexport const pagesRuntimePath = fileURLToPath(new URL(compiled ? '../server/pages.js' : '../runtime/pages.tsx', import.meta.url));\nexport const clientRuntimePath = fileURLToPath(new URL(compiled ? '../browser/client.js' : '../runtime/client.tsx', import.meta.url));\nexport const markdownRuntimePath = fileURLToPath(new URL(compiled ? '../server/markdown.js' : '../runtime/markdown.ts', import.meta.url));\nexport const publicRuntimeModules: Record<string, { server: string; client: string }> = compiled ? {\n 'void-plugin-hono-jsx/markdown': { server: markdownRuntimePath, client: fileURLToPath(new URL('../browser/markdown.js', import.meta.url)) },\n 'void-plugin-hono-jsx/pages': { server: pagesRuntimePath, client: fileURLToPath(new URL('../browser/pages.js', import.meta.url)) },\n 'void-plugin-hono-jsx/form': {\n server: fileURLToPath(new URL('../server/form.js', import.meta.url)),\n client: fileURLToPath(new URL('../browser/form.js', import.meta.url)),\n },\n} : {};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type JSX, type Child } from 'hono/jsx';
|
|
2
|
+
import { type FormMethod, type FormModel, type VoidActionError } from 'void/pages-client';
|
|
3
|
+
export type FormProps = Omit<JSX.IntrinsicElements['form'], 'action' | 'method' | 'onSubmit' | 'onError'> & {
|
|
4
|
+
form: FormModel<[string | FormData | undefined]>;
|
|
5
|
+
method?: FormMethod;
|
|
6
|
+
url?: string;
|
|
7
|
+
renderError?: (error: VoidActionError) => Child;
|
|
8
|
+
};
|
|
9
|
+
export declare function Form({ form, method, url, renderError, children, ...props }: FormProps): import("hono/jsx/jsx-dev-runtime").JSX.Element;
|
|
10
|
+
//# sourceMappingURL=form-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-view.d.ts","sourceRoot":"","sources":["../../src/runtime/form-view.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,GAAG,EAAE,KAAK,KAAK,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAAgF,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAExK,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC,GAAG;IAC1G,IAAI,EAAE,SAAS,CAAC,CAAC,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC;IACjD,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,KAAK,CAAC;CACjD,CAAC;AACF,wBAAgB,IAAI,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,SAAS,kDAa9F"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "hono/jsx/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'hono/jsx';
|
|
3
|
+
import { formErrorMessage, formRetryMessage, formSubmissionBlocked, scheduleFormRetry } from 'void/pages-client';
|
|
4
|
+
export function Form({ form, method = 'post', url, renderError, children, ...props }) {
|
|
5
|
+
const [now, setNow] = useState(Date.now());
|
|
6
|
+
useEffect(() => scheduleFormRetry(form.error, () => setNow(Date.now())), [form.error]);
|
|
7
|
+
const message = formErrorMessage(form);
|
|
8
|
+
const retry = formRetryMessage(form.error);
|
|
9
|
+
const blocked = formSubmissionBlocked(form, now);
|
|
10
|
+
return _jsxs("form", { ...props, "aria-busy": form.pending, onSubmit: (event) => {
|
|
11
|
+
event.preventDefault();
|
|
12
|
+
if (!blocked)
|
|
13
|
+
void form[method](url ?? new FormData(event.currentTarget));
|
|
14
|
+
}, children: [message && _jsxs("div", { role: "alert", "data-void-form-error": true, children: [form.error && renderError ? renderError(form.error) : message, retry && _jsx("p", { children: retry })] }), children] });
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=form-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-view.js","sourceRoot":"","sources":["../../src/runtime/form-view.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAwB,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,iBAAiB,EAAyD,MAAM,mBAAmB,CAAC;AAQxK,MAAM,UAAU,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAa;IAC7F,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC3C,SAAS,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACvF,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAG,qBAAqB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACjD,OAAO,mBAAU,KAAK,eAAa,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAY,EAAE,EAAE;YAC1E,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,IAAI,CAAC,OAAO;gBAAE,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,aAAgC,CAAC,CAAC,CAAC;QAC/F,CAAC,aACE,OAAO,IAAI,eAAK,IAAI,EAAC,OAAO,2CAAuB,IAAI,CAAC,KAAK,IAAI,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,IAAI,sBAAI,KAAK,GAAK,IAAO,EAChJ,QAAQ,IACJ,CAAC;AACV,CAAC","sourcesContent":["import { useEffect, useState, type JSX, type Child } from 'hono/jsx';\nimport { formErrorMessage, formRetryMessage, formSubmissionBlocked, scheduleFormRetry, type FormMethod, type FormModel, type VoidActionError } from 'void/pages-client';\n\nexport type FormProps = Omit<JSX.IntrinsicElements['form'], 'action' | 'method' | 'onSubmit' | 'onError'> & {\n form: FormModel<[string | FormData | undefined]>;\n method?: FormMethod;\n url?: string;\n renderError?: (error: VoidActionError) => Child;\n};\nexport function Form({ form, method = 'post', url, renderError, children, ...props }: FormProps) {\n const [now, setNow] = useState(Date.now());\n useEffect(() => scheduleFormRetry(form.error, () => setNow(Date.now())), [form.error]);\n const message = formErrorMessage(form);\n const retry = formRetryMessage(form.error);\n const blocked = formSubmissionBlocked(form, now);\n return <form {...props} aria-busy={form.pending} onSubmit={(event: Event) => {\n event.preventDefault();\n if (!blocked) void form[method](url ?? new FormData(event.currentTarget as HTMLFormElement));\n }}>\n {message && <div role=\"alert\" data-void-form-error>{form.error && renderError ? renderError(form.error) : message}{retry && <p>{retry}</p>}</div>}\n {children}\n </form>;\n}\n"]}
|
package/dist/server/form.d.ts
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
|
-
import { type FormMethod } from 'void/pages-client';
|
|
2
|
-
|
|
1
|
+
import { VoidActionError, type FormMethod } from 'void/pages-client';
|
|
2
|
+
import type { ActionFormOptions, ActionUrl, ResolveActionBody } from 'void/routes';
|
|
3
|
+
import { action } from './pages.tsx';
|
|
4
|
+
export { Form, type FormProps } from './form-view.tsx';
|
|
5
|
+
export { action };
|
|
6
|
+
type Fields = Record<string, unknown>;
|
|
7
|
+
type Body<U extends string> = ResolveActionBody<U> extends Fields ? ResolveActionBody<U> : Fields;
|
|
8
|
+
type SetData<T> = {
|
|
9
|
+
(next: T | ((current: T) => T)): void;
|
|
10
|
+
<K extends keyof T & string>(field: K, value: T[K]): void;
|
|
11
|
+
};
|
|
12
|
+
export type HonoForm<T extends Fields> = {
|
|
3
13
|
data: T;
|
|
4
|
-
setData:
|
|
14
|
+
setData: SetData<T>;
|
|
5
15
|
errors: Record<string, string>;
|
|
6
16
|
pending: boolean;
|
|
17
|
+
error: VoidActionError | null;
|
|
18
|
+
hasChanges: boolean;
|
|
7
19
|
wasSuccessful: boolean;
|
|
8
|
-
|
|
9
|
-
submit
|
|
10
|
-
cancel
|
|
11
|
-
reset
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
recentlySuccessful: boolean;
|
|
21
|
+
submit(method: FormMethod, target?: string | FormData): Promise<void>;
|
|
22
|
+
cancel(): void;
|
|
23
|
+
reset: {
|
|
24
|
+
(): void;
|
|
25
|
+
(...fields: Array<keyof T & string>): void;
|
|
26
|
+
};
|
|
27
|
+
clearErrors(...fields: Array<keyof T & string>): void;
|
|
28
|
+
clearError(): void;
|
|
29
|
+
} & Record<FormMethod, (target?: string | FormData) => Promise<void>>;
|
|
30
|
+
export declare function useForm<T extends Fields>(initialData: T): HonoForm<T>;
|
|
31
|
+
export declare function useForm<U extends ActionUrl & string>(url: U, defaults: Body<U>, options?: ActionFormOptions<U>): HonoForm<Body<U>>;
|
|
32
|
+
export declare function useIslandForm<T extends Fields>(defaults: T): HonoForm<T>;
|
|
17
33
|
//# sourceMappingURL=form.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/runtime/form.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/runtime/form.ts"],"names":[],"mappings":"AACA,OAAO,EAAwE,eAAe,EAAqB,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC9J,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAuC,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACtC,KAAK,IAAI,CAAC,CAAC,SAAS,MAAM,IAAI,iBAAiB,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AAClG,KAAK,OAAO,CAAC,CAAC,IAAI;IAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC;IAAC,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;CAAE,CAAC;AACvH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI;IACvC,IAAI,EAAE,CAAC,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAAC,MAAM,EAAE,M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