@void/solid 0.7.4 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/plugin.mjs +56 -54
- package/package.json +3 -3
- package/src/runtime/context.ts +4 -0
- package/src/runtime/index.ts +8 -1
- package/src/runtime/use-params.ts +10 -0
package/README.md
CHANGED
package/dist/plugin.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import solid from "vite-plugin-solid";
|
|
|
2
2
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
3
3
|
import { normalizePath } from "vite";
|
|
4
4
|
import { generateComponentManifest, resolveEffectiveLayoutChain, resolveStaticPageDataBuildOptions, scanPages } from "void/pages";
|
|
5
|
-
import { ISLANDS_CLIENT_ENTRY_ID, ISLANDS_RENDERER_ID, computePagesNeedingClientJS,
|
|
5
|
+
import { ISLANDS_CLIENT_ENTRY_ID, ISLANDS_RENDERER_ID, computePagesNeedingClientJS, extractCssImports, needsIslandClientBundle, resolveSpecifier, rewriteCssImportForVirtualModule, watchPagesForRescan } from "void/pages-islands-plugin";
|
|
6
6
|
//#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
7
7
|
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
8
8
|
function normalizeWindowsPath(input = "") {
|
|
@@ -157,13 +157,7 @@ function islandsPlugin(pagesDir) {
|
|
|
157
157
|
const wrapperMeta = /* @__PURE__ */ new Map();
|
|
158
158
|
let wrapperId = 0;
|
|
159
159
|
let viteRoot = "";
|
|
160
|
-
const islandCssMap = /* @__PURE__ */ new Map();
|
|
161
160
|
let resolvedConfig = null;
|
|
162
|
-
/** Rebuild islandCssMap from current file contents (re-runs fileHasCssImports). */
|
|
163
|
-
function rebuildIslandCssMap$1() {
|
|
164
|
-
if (!pageScan) return;
|
|
165
|
-
rebuildIslandCssMap(pageScan, pagesDir, islandCssMap, fileHasCssImports);
|
|
166
|
-
}
|
|
167
161
|
function computePagesNeedingClientJS$1() {
|
|
168
162
|
if (!pageScan) return /* @__PURE__ */ new Set();
|
|
169
163
|
return computePagesNeedingClientJS(pageScan, pagesDir, resolvedConfig);
|
|
@@ -177,10 +171,8 @@ function islandsPlugin(pagesDir) {
|
|
|
177
171
|
isDev = config.command === "serve";
|
|
178
172
|
},
|
|
179
173
|
configureServer(server) {
|
|
180
|
-
configureIslandCssServer(server, islandCssFiles, viteRoot, rebuildIslandCssMap$1);
|
|
181
174
|
watchPagesForRescan(server, pagesDir, root, (scan) => {
|
|
182
175
|
pageScan = scan;
|
|
183
|
-
rebuildIslandCssMap$1();
|
|
184
176
|
});
|
|
185
177
|
},
|
|
186
178
|
async buildStart() {
|
|
@@ -228,7 +220,6 @@ function islandsPlugin(pagesDir) {
|
|
|
228
220
|
const layoutChain = resolveEffectiveLayoutChain(page, pageScan.layouts, pageScan.namedLayouts);
|
|
229
221
|
for (const layout of layoutChain) islandCssFiles.add(normalizePath(resolve(pagesDir, layout.filePath)));
|
|
230
222
|
}
|
|
231
|
-
rebuildIslandCssMap$1();
|
|
232
223
|
}
|
|
233
224
|
},
|
|
234
225
|
resolveId: {
|
|
@@ -254,7 +245,7 @@ function islandsPlugin(pagesDir) {
|
|
|
254
245
|
const mdPlugin = resolvedConfig?.plugins?.find((p) => p.name === "void-md");
|
|
255
246
|
const mdScriptIds = new Set(mdPlugin?.api?.getClientScripts?.()?.keys() ?? []);
|
|
256
247
|
const needsJS = computePagesNeedingClientJS$1();
|
|
257
|
-
return generateIslandRenderer(pageScan, pagesDir,
|
|
248
|
+
return generateIslandRenderer(pageScan, pagesDir, mdScriptIds, needsJS);
|
|
258
249
|
}
|
|
259
250
|
if (id === "\0" + ISLANDS_CLIENT_ENTRY_ID) {
|
|
260
251
|
if (!pageScan) return "";
|
|
@@ -329,23 +320,16 @@ export default function _IslandWrap(props) {
|
|
|
329
320
|
}
|
|
330
321
|
`;
|
|
331
322
|
}
|
|
332
|
-
function generateIslandRenderer(scan, pagesDir,
|
|
333
|
-
let cssMapCode = "";
|
|
334
|
-
if (isDev && islandCssMap.size > 0) {
|
|
335
|
-
const cssMapObj = {};
|
|
336
|
-
for (const [compId, paths] of islandCssMap) cssMapObj[compId] = paths.map((p) => "/" + normalizePath(relative(viteRoot, p)) + ".css");
|
|
337
|
-
cssMapCode = `const __cssPaths = ${JSON.stringify(cssMapObj)};`;
|
|
338
|
-
}
|
|
323
|
+
function generateIslandRenderer(scan, pagesDir, mdScriptIds, pagesNeedingClientJS) {
|
|
339
324
|
const mdScriptIdsCode = `const __mdClientScriptIds = new Set(${JSON.stringify([...mdScriptIds])});`;
|
|
340
325
|
const needsJSCode = `const __pagesNeedingClientJS = new Set(${JSON.stringify([...pagesNeedingClientJS])});`;
|
|
341
326
|
return `
|
|
342
327
|
import { renderToStringAsync, generateHydrationScript } from "solid-js/web";
|
|
343
328
|
import { createComponent } from "solid-js";
|
|
344
|
-
import { SharedContext, ErrorsContext } from "@void/solid";
|
|
329
|
+
import { SharedContext, ErrorsContext, ParamsContext } from "@void/solid";
|
|
345
330
|
import { renderHeadToString, renderHtmlAttrs, renderBodyAttrs } from "void/pages-head";
|
|
346
331
|
|
|
347
332
|
${generateComponentManifest(scan, pagesDir)}
|
|
348
|
-
${cssMapCode}
|
|
349
333
|
${mdScriptIdsCode}
|
|
350
334
|
${needsJSCode}
|
|
351
335
|
|
|
@@ -367,15 +351,20 @@ export async function renderIslandPage(pageObj, assetTags) {
|
|
|
367
351
|
return createComponent(ErrorsContext.Provider, {
|
|
368
352
|
value: pageObj.errors || {},
|
|
369
353
|
get children() {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
354
|
+
return createComponent(ParamsContext.Provider, {
|
|
355
|
+
value: pageObj.params || {},
|
|
356
|
+
get children() {
|
|
357
|
+
// Build layout chain inside providers so contexts are available.
|
|
358
|
+
// No RouterContext — islands have no Void Router.
|
|
359
|
+
let element = createComponent(PageComponent, pageObj.props);
|
|
360
|
+
for (let i = layoutComponents.length - 1; i >= 0; i--) {
|
|
361
|
+
const Layout = layoutComponents[i];
|
|
362
|
+
const child = element;
|
|
363
|
+
element = createComponent(Layout, { get children() { return child; } });
|
|
364
|
+
}
|
|
365
|
+
return element;
|
|
366
|
+
}
|
|
367
|
+
});
|
|
379
368
|
}
|
|
380
369
|
});
|
|
381
370
|
}
|
|
@@ -391,7 +380,7 @@ export async function renderIslandPage(pageObj, assetTags) {
|
|
|
391
380
|
|
|
392
381
|
return \`<!doctype html>
|
|
393
382
|
<html\${htmlAttrs}>
|
|
394
|
-
<head>\${headHtml}\${
|
|
383
|
+
<head>\${headHtml}\${assetTags.css}\${__pagesNeedingClientJS.has(pageObj.component) ? assetTags.preloads : ""}\${__pagesNeedingClientJS.has(pageObj.component) ? generateHydrationScript() : ""}</head>
|
|
395
384
|
<body\${bodyAttrs}>
|
|
396
385
|
<div id="app"\${__mdScriptAttr}>\${html}</div>
|
|
397
386
|
\${__pagesNeedingClientJS.has(pageObj.component) ? assetTags.body : ""}
|
|
@@ -504,7 +493,7 @@ function generateRendererModule(scan, pagesDir) {
|
|
|
504
493
|
return `
|
|
505
494
|
import { renderToStringAsync, generateHydrationScript } from "solid-js/web";
|
|
506
495
|
import { createComponent } from "solid-js";
|
|
507
|
-
import { SharedContext, ErrorsContext, RouterContext, NavigationContext } from "@void/solid";
|
|
496
|
+
import { SharedContext, ErrorsContext, ParamsContext, RouterContext, NavigationContext } from "@void/solid";
|
|
508
497
|
import { createSsrRouter, idleNavigationState } from "void/pages-client";
|
|
509
498
|
import { renderHeadToString, renderHtmlAttrs, renderBodyAttrs } from "void/pages-head";
|
|
510
499
|
import { serializePageData } from "void/pages-server";
|
|
@@ -526,19 +515,24 @@ export async function renderPage(pageObj, assetTags) {
|
|
|
526
515
|
value: pageObj.errors || {},
|
|
527
516
|
get children() {
|
|
528
517
|
return createComponent(RouterContext.Provider, {
|
|
529
|
-
value: createSsrRouter(pageObj.url || "/"),
|
|
518
|
+
value: createSsrRouter(pageObj.url || "/", pageObj.params || {}),
|
|
530
519
|
get children() {
|
|
531
520
|
return createComponent(NavigationContext.Provider, {
|
|
532
521
|
value: () => idleNavigationState(),
|
|
533
522
|
get children() {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
523
|
+
return createComponent(ParamsContext.Provider, {
|
|
524
|
+
value: pageObj.params || {},
|
|
525
|
+
get children() {
|
|
526
|
+
// Build layout chain inside providers so contexts are available
|
|
527
|
+
let element = createComponent(PageComponent, pageObj.props);
|
|
528
|
+
for (let i = layoutComponents.length - 1; i >= 0; i--) {
|
|
529
|
+
const Layout = layoutComponents[i];
|
|
530
|
+
const child = element;
|
|
531
|
+
element = createComponent(Layout, { get children() { return child; } });
|
|
532
|
+
}
|
|
533
|
+
return element;
|
|
534
|
+
}
|
|
535
|
+
});
|
|
542
536
|
}
|
|
543
537
|
});
|
|
544
538
|
}
|
|
@@ -573,7 +567,7 @@ function generateClientEntry(scan, pagesDir, viewTransitions, prefetch, staticPa
|
|
|
573
567
|
return `
|
|
574
568
|
import { createSignal, createComponent, batch } from "solid-js";
|
|
575
569
|
import { hydrate } from "solid-js/web";
|
|
576
|
-
import { SharedContext, ErrorsContext, RouterContext, NavigationContext, setActionRouter } from "@void/solid";
|
|
570
|
+
import { SharedContext, ErrorsContext, ParamsContext, RouterContext, NavigationContext, setActionRouter } from "@void/solid";
|
|
577
571
|
import { createRouterFacade, createVoidRouter, idleNavigationState } from "void/pages-client";
|
|
578
572
|
import { parseCacheFor } from "void/pages-prefetch";
|
|
579
573
|
|
|
@@ -585,6 +579,7 @@ const [layouts, setLayouts] = createSignal([]);
|
|
|
585
579
|
const [shared, setShared] = createSignal({});
|
|
586
580
|
const [errors, setErrors] = createSignal({});
|
|
587
581
|
const [routeUrl, setRouteUrl] = createSignal(window.location.pathname + window.location.search + window.location.hash);
|
|
582
|
+
const [routeParams, setRouteParams] = createSignal({});
|
|
588
583
|
const [navigation, setNavigation] = createSignal(idleNavigationState());
|
|
589
584
|
|
|
590
585
|
const { router, initialPageData, initialComponent, initialLayouts, start } =
|
|
@@ -601,6 +596,7 @@ const { router, initialPageData, initialComponent, initialLayouts, start } =
|
|
|
601
596
|
setLayouts(layoutComps);
|
|
602
597
|
setShared((prev) => ({ ...prev, ...(pageData.shared || {}) }));
|
|
603
598
|
setErrors(pageData.errors || {});
|
|
599
|
+
setRouteParams(pageData.params || {});
|
|
604
600
|
});
|
|
605
601
|
},
|
|
606
602
|
onDeferredUpdate(props) {
|
|
@@ -621,7 +617,7 @@ const { router, initialPageData, initialComponent, initialLayouts, start } =
|
|
|
621
617
|
},
|
|
622
618
|
});
|
|
623
619
|
|
|
624
|
-
const reactiveRouter = createRouterFacade(router, () => routeUrl());
|
|
620
|
+
const reactiveRouter = createRouterFacade(router, () => routeUrl(), () => routeParams());
|
|
625
621
|
|
|
626
622
|
setActionRouter(reactiveRouter);
|
|
627
623
|
|
|
@@ -631,6 +627,7 @@ batch(() => {
|
|
|
631
627
|
setLayouts(initialLayouts);
|
|
632
628
|
setShared(initialPageData.shared || {});
|
|
633
629
|
setErrors(initialPageData.errors || {});
|
|
630
|
+
setRouteParams(initialPageData.params || {});
|
|
634
631
|
});
|
|
635
632
|
|
|
636
633
|
function App() {
|
|
@@ -643,19 +640,24 @@ function App() {
|
|
|
643
640
|
return createComponent(RouterContext.Provider, {
|
|
644
641
|
value: reactiveRouter,
|
|
645
642
|
get children() {
|
|
646
|
-
return createComponent(
|
|
647
|
-
value
|
|
643
|
+
return createComponent(ParamsContext.Provider, {
|
|
644
|
+
get value() { return routeParams(); },
|
|
648
645
|
get children() {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
646
|
+
return createComponent(NavigationContext.Provider, {
|
|
647
|
+
value: navigation,
|
|
648
|
+
get children() {
|
|
649
|
+
const Comp = component();
|
|
650
|
+
if (!Comp) return null;
|
|
651
|
+
let element = createComponent(Comp, pageProps());
|
|
652
|
+
const layoutList = layouts();
|
|
653
|
+
for (let i = layoutList.length - 1; i >= 0; i--) {
|
|
654
|
+
const Layout = layoutList[i];
|
|
655
|
+
const child = element;
|
|
656
|
+
element = createComponent(Layout, { get children() { return child; } });
|
|
657
|
+
}
|
|
658
|
+
return element;
|
|
659
|
+
}
|
|
660
|
+
});
|
|
659
661
|
}
|
|
660
662
|
});
|
|
661
663
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@void/solid",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/voidzero-dev/void.git",
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
"solid-js": "^1.9.12",
|
|
44
44
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.1.20",
|
|
45
45
|
"vite-plus": "^0.1.20",
|
|
46
|
-
"void": "0.7.
|
|
46
|
+
"void": "0.7.6"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"solid-js": "^1.9.0",
|
|
50
50
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.1.20",
|
|
51
|
-
"void": "0.7.
|
|
51
|
+
"void": "0.7.6"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"build": "vp pack",
|
package/src/runtime/context.ts
CHANGED
|
@@ -8,6 +8,10 @@ export const SharedContext: Context<Record<string, unknown> | null> = createCont
|
|
|
8
8
|
export const ErrorsContext: Context<
|
|
9
9
|
Record<string, string> | (() => Record<string, string>) | null
|
|
10
10
|
> = createContext<Record<string, string> | (() => Record<string, string>) | null>(null);
|
|
11
|
+
export const ParamsContext: Context<Record<string, string> | null> = createContext<Record<
|
|
12
|
+
string,
|
|
13
|
+
string
|
|
14
|
+
> | null>(null);
|
|
11
15
|
export const RouterContext: Context<VoidRouter | null> = createContext<VoidRouter | null>(null);
|
|
12
16
|
export const NavigationContext: Context<(() => NavigationState) | null> = createContext<
|
|
13
17
|
(() => NavigationState) | null
|
package/src/runtime/index.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
export { Link, type LinkProps } from './link.tsx';
|
|
2
2
|
export { useRouter } from './use-router.ts';
|
|
3
|
+
export { useParams } from './use-params.ts';
|
|
3
4
|
export { useShared } from './use-shared.ts';
|
|
4
5
|
export { useForm } from './use-form.ts';
|
|
5
6
|
export { useNavigation } from './use-navigation.ts';
|
|
6
7
|
export { useIslandForm } from './use-island-form.ts';
|
|
7
8
|
export { action, setActionRouter } from './action.ts';
|
|
8
|
-
export {
|
|
9
|
+
export {
|
|
10
|
+
SharedContext,
|
|
11
|
+
ErrorsContext,
|
|
12
|
+
ParamsContext,
|
|
13
|
+
RouterContext,
|
|
14
|
+
NavigationContext,
|
|
15
|
+
} from './context.ts';
|
|
9
16
|
export type { DeferredState as Deferred, InferProps } from 'void';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useContext } from 'solid-js';
|
|
2
|
+
import { ParamsContext } from './context.ts';
|
|
3
|
+
|
|
4
|
+
export function useParams<T extends Record<string, string> = Record<string, string>>(): T {
|
|
5
|
+
const params = useContext(ParamsContext);
|
|
6
|
+
if (params === null) {
|
|
7
|
+
throw new Error('useParams(): must be used inside a Void page.');
|
|
8
|
+
}
|
|
9
|
+
return params as T;
|
|
10
|
+
}
|