@void/svelte 0.27.0 → 1.0.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/dist/plugin.d.mts +2 -1
- package/dist/plugin.mjs +25 -54
- package/package.json +6 -6
- package/src/runtime/App.svelte +0 -6
- package/src/runtime/Link.svelte +8 -14
- package/src/runtime/use-navigation.ts +0 -2
- package/src/runtime/use-router.ts +0 -2
package/dist/plugin.d.mts
CHANGED
package/dist/plugin.mjs
CHANGED
|
@@ -2,8 +2,9 @@ import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
|
2
2
|
import { generateComponentManifest, resolveEffectiveLayoutChain, resolvePagesDir, resolveStaticPageDataBuildOptions, scanPages } from "void/pages";
|
|
3
3
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
4
4
|
import nodePath from "node:path";
|
|
5
|
+
import { preprocess } from "svelte/compiler";
|
|
5
6
|
import { normalizePath } from "vite";
|
|
6
|
-
import { ISLANDS_CLIENT_ENTRY_ID, ISLANDS_RENDERER_ID, computePagesNeedingClientJS, editIslandSource,
|
|
7
|
+
import { ISLANDS_CLIENT_ENTRY_ID, ISLANDS_RENDERER_ID, computePagesNeedingClientJS, editIslandSource, findIslandImports, findStaticCssImports, needsIslandClientBundle, resolveSpecifier, rewriteCssImportForVirtualModule, watchPagesForRescan } from "void/pages-islands-plugin";
|
|
7
8
|
//#region ../../node_modules/.pnpm/pathslash@0.1.0/node_modules/pathslash/dist/index.mjs
|
|
8
9
|
const BACKSLASH_RE = /\\/g;
|
|
9
10
|
const isWindows = process.platform === "win32";
|
|
@@ -61,9 +62,7 @@ function islandsPlugin(pagesDir, options) {
|
|
|
61
62
|
const islandManifest = /* @__PURE__ */ new Map();
|
|
62
63
|
const islandCssFiles = /* @__PURE__ */ new Set();
|
|
63
64
|
let isDev = false;
|
|
64
|
-
let viteRoot = "";
|
|
65
65
|
let resolvedConfig = null;
|
|
66
|
-
/** Resolve an island import and record it in the client manifest. */
|
|
67
66
|
function registerIsland(spec, importerDir, hydrate) {
|
|
68
67
|
const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS);
|
|
69
68
|
if (!absPath) return {
|
|
@@ -86,7 +85,6 @@ function islandsPlugin(pagesDir, options) {
|
|
|
86
85
|
enforce: "pre",
|
|
87
86
|
configResolved(config) {
|
|
88
87
|
resolvedConfig = config;
|
|
89
|
-
viteRoot = config.root;
|
|
90
88
|
isDev = config.command === "serve";
|
|
91
89
|
},
|
|
92
90
|
configureServer(server) {
|
|
@@ -127,22 +125,14 @@ function islandsPlugin(pagesDir, options) {
|
|
|
127
125
|
}
|
|
128
126
|
},
|
|
129
127
|
resolveId: {
|
|
130
|
-
filter: { id: /^(virtual:void-islands-(renderer|client)|\/@void-island-wrap\/)
|
|
128
|
+
filter: { id: /^(virtual:void-islands-(renderer|client)|\/@void-island-wrap\/)/ },
|
|
131
129
|
handler(source) {
|
|
132
130
|
if (source === ISLANDS_RENDERER_ID || source === ISLANDS_CLIENT_ENTRY_ID) return "\0" + source;
|
|
133
131
|
if (source.startsWith(WRAPPER_PREFIX)) return source;
|
|
134
|
-
if (source.endsWith(".css")) {
|
|
135
|
-
const srcPath = normalizePath(source.slice(0, -4));
|
|
136
|
-
if (islandCssFiles.has(srcPath)) return srcPath + ".css";
|
|
137
|
-
if (srcPath.startsWith("/")) {
|
|
138
|
-
const absPath = normalizePath(resolve(viteRoot, srcPath.slice(1)));
|
|
139
|
-
if (islandCssFiles.has(absPath)) return absPath + ".css";
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
132
|
}
|
|
143
133
|
},
|
|
144
134
|
load: {
|
|
145
|
-
filter: { id: /^(\0virtual:void-islands-(renderer|client)|\/@void-island-wrap\/)
|
|
135
|
+
filter: { id: /^(\0virtual:void-islands-(renderer|client)|\/@void-island-wrap\/)/ },
|
|
146
136
|
handler(id) {
|
|
147
137
|
if (id === "\0" + ISLANDS_RENDERER_ID) {
|
|
148
138
|
if (!pageScan) return "export function renderIslandPage() { throw new Error('No pages found'); }";
|
|
@@ -156,10 +146,6 @@ function islandsPlugin(pagesDir, options) {
|
|
|
156
146
|
return generateIslandClientEntry(islandManifest, islandCssFiles, isDev);
|
|
157
147
|
}
|
|
158
148
|
if (id.startsWith(WRAPPER_PREFIX)) return generateWrapperComponent(id);
|
|
159
|
-
if (id.endsWith(".css") && !id.startsWith("\0")) {
|
|
160
|
-
const srcPath = id.slice(0, -4);
|
|
161
|
-
if (islandCssFiles.has(srcPath)) return extractCssImports(srcPath);
|
|
162
|
-
}
|
|
163
149
|
}
|
|
164
150
|
},
|
|
165
151
|
transform: {
|
|
@@ -196,34 +182,35 @@ function islandsPlugin(pagesDir, options) {
|
|
|
196
182
|
name: "void-svelte:islands-style",
|
|
197
183
|
apply: "build",
|
|
198
184
|
resolveId: {
|
|
199
|
-
filter: { id:
|
|
185
|
+
filter: { id: /\.svelte\.css\?island-style$/ },
|
|
200
186
|
handler(source) {
|
|
201
187
|
return source;
|
|
202
188
|
}
|
|
203
189
|
},
|
|
204
190
|
load: {
|
|
205
|
-
filter: { id:
|
|
206
|
-
handler(id) {
|
|
207
|
-
const
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
let
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
191
|
+
filter: { id: /\.svelte\.css\?island-style$/ },
|
|
192
|
+
async handler(id) {
|
|
193
|
+
const file = id.slice(0, -17);
|
|
194
|
+
const api = resolvedConfig?.plugins.find((plugin) => plugin.name === "vite-plugin-svelte:config")?.api;
|
|
195
|
+
if (typeof api?.compileSvelte !== "function" || typeof api.idParser !== "function") this.error("Svelte island page styles need the @sveltejs/vite-plugin-svelte version that @void/svelte depends on.");
|
|
196
|
+
this.addWatchFile(file);
|
|
197
|
+
let code = readFileSync(file, "utf-8");
|
|
198
|
+
let map;
|
|
199
|
+
if (api.options.preprocess) {
|
|
200
|
+
const processed = await preprocess(code, api.options.preprocess, { filename: file });
|
|
201
|
+
code = processed.code;
|
|
202
|
+
map = processed.map;
|
|
203
|
+
for (const dependency of processed.dependencies ?? []) this.addWatchFile(dependency);
|
|
217
204
|
}
|
|
218
|
-
|
|
205
|
+
const { compiled } = await api.compileSvelte(api.idParser(file, false), code, api.options, this.environment, map);
|
|
206
|
+
return {
|
|
207
|
+
code: compiled.css?.code ?? "",
|
|
208
|
+
map: compiled.css?.map ?? null
|
|
209
|
+
};
|
|
219
210
|
}
|
|
220
211
|
}
|
|
221
212
|
}];
|
|
222
213
|
}
|
|
223
|
-
/**
|
|
224
|
-
* Generate a virtual Svelte wrapper component from a wrapper URL.
|
|
225
|
-
* The URL encodes: src (absolute component path), island (ID), hydrate (strategy).
|
|
226
|
-
*/
|
|
227
214
|
function generateWrapperComponent(id) {
|
|
228
215
|
const url = new URL(id, "file://");
|
|
229
216
|
const src = decodeURIComponent(url.searchParams.get("src") || "");
|
|
@@ -267,7 +254,6 @@ export async function renderIslandPage(pageObj, assetTags) {
|
|
|
267
254
|
layouts: layoutComponents,
|
|
268
255
|
pageProps: pageObj.props,
|
|
269
256
|
shared: pageObj.shared || {},
|
|
270
|
-
errors: pageObj.errors || {},
|
|
271
257
|
params: pageObj.params || {},
|
|
272
258
|
router: null,
|
|
273
259
|
stores: null,
|
|
@@ -298,16 +284,7 @@ function generateIslandClientEntry(manifest, cssFiles, isDev) {
|
|
|
298
284
|
lines.push("import { initIslands } from \"void/pages-client\";");
|
|
299
285
|
if (!isDev) for (const file of cssFiles) {
|
|
300
286
|
const content = readFileSync(file, "utf-8");
|
|
301
|
-
|
|
302
|
-
styleRe.lastIndex = 0;
|
|
303
|
-
let styleIndex = 0;
|
|
304
|
-
let styleMatch;
|
|
305
|
-
while ((styleMatch = styleRe.exec(content)) !== null) {
|
|
306
|
-
const langMatch = styleMatch[1].match(/\blang\s*=\s*["'](\w+)["']/);
|
|
307
|
-
const lang = langMatch ? langMatch[1] : "css";
|
|
308
|
-
lines.push(`import ${JSON.stringify(file + "?island-style&index=" + styleIndex + "&lang." + lang)};`);
|
|
309
|
-
styleIndex++;
|
|
310
|
-
}
|
|
287
|
+
if (/<style\b/.test(content)) lines.push(`import ${JSON.stringify(file + ".css?island-style")};`);
|
|
311
288
|
for (const item of findStaticCssImports(content, file)) lines.push(rewriteCssImportForVirtualModule(item.statement, item.specifier, file));
|
|
312
289
|
}
|
|
313
290
|
lines.push("const islands = {");
|
|
@@ -456,7 +433,6 @@ export async function renderPage(pageObj, assetTags) {
|
|
|
456
433
|
layouts: layoutComponents,
|
|
457
434
|
pageProps: pageObj.props,
|
|
458
435
|
shared: pageObj.shared || {},
|
|
459
|
-
errors: pageObj.errors || {},
|
|
460
436
|
params: pageObj.params || {},
|
|
461
437
|
router: createSsrRouter(pageObj.url || "/", pageObj.params || {}),
|
|
462
438
|
routeUrl: pageObj.url || "/",
|
|
@@ -497,7 +473,6 @@ const pageStore = writable(null);
|
|
|
497
473
|
const propsStore = writable({});
|
|
498
474
|
const layoutsStore = writable([]);
|
|
499
475
|
const sharedStore = writable({});
|
|
500
|
-
const errorsStore = writable({});
|
|
501
476
|
const paramsStore = writable({});
|
|
502
477
|
let routeUrl = window.location.pathname + window.location.search + window.location.hash;
|
|
503
478
|
let routeParams = {};
|
|
@@ -514,7 +489,6 @@ const { router, initialPageData, initialComponent, initialLayouts, start, commit
|
|
|
514
489
|
applyUpdate(pageData, comp, layouts) {
|
|
515
490
|
propsStore.set(pageData.props);
|
|
516
491
|
sharedStore.set(pageData.shared || {});
|
|
517
|
-
errorsStore.set(pageData.errors || {});
|
|
518
492
|
routeParams = pageData.params || {};
|
|
519
493
|
paramsStore.set(routeParams);
|
|
520
494
|
layoutsStore.set(layouts);
|
|
@@ -541,13 +515,12 @@ const { router, initialPageData, initialComponent, initialLayouts, start, commit
|
|
|
541
515
|
|
|
542
516
|
const reactiveRouter = createRouterFacade(router, () => routeUrl, () => routeParams);
|
|
543
517
|
|
|
544
|
-
setActionRouter(
|
|
518
|
+
setActionRouter(router);
|
|
545
519
|
|
|
546
520
|
pageStore.set(initialComponent);
|
|
547
521
|
propsStore.set(initialPageData.props);
|
|
548
522
|
layoutsStore.set(initialLayouts);
|
|
549
523
|
sharedStore.set(initialPageData.shared || {});
|
|
550
|
-
errorsStore.set(initialPageData.errors || {});
|
|
551
524
|
routeParams = initialPageData.params || {};
|
|
552
525
|
paramsStore.set(routeParams);
|
|
553
526
|
|
|
@@ -560,7 +533,6 @@ const appOptions = {
|
|
|
560
533
|
layouts: initialLayouts,
|
|
561
534
|
pageProps: initialPageData.props,
|
|
562
535
|
shared: initialPageData.shared || {},
|
|
563
|
-
errors: initialPageData.errors || {},
|
|
564
536
|
params: initialPageData.params || {},
|
|
565
537
|
router,
|
|
566
538
|
routeUrl,
|
|
@@ -570,7 +542,6 @@ const appOptions = {
|
|
|
570
542
|
props: propsStore,
|
|
571
543
|
layouts: layoutsStore,
|
|
572
544
|
shared: sharedStore,
|
|
573
|
-
errors: errorsStore,
|
|
574
545
|
params: paramsStore,
|
|
575
546
|
route: routeStore,
|
|
576
547
|
navigation: navigationStore,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@void/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Svelte pages, server rendering, forms, and navigation for Void.",
|
|
5
5
|
"homepage": "https://void.cloud",
|
|
6
6
|
"bugs": {
|
|
@@ -38,17 +38,17 @@
|
|
|
38
38
|
"@sveltejs/vite-plugin-svelte": "^7.3.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@types/node": "^26.6.
|
|
41
|
+
"@types/node": "^26.6.5",
|
|
42
42
|
"pathslash": "^0.1.0",
|
|
43
43
|
"svelte": "^5.57.2",
|
|
44
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@1.
|
|
45
|
-
"vite-plus": "1.
|
|
46
|
-
"void": "0.
|
|
44
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.2.0",
|
|
45
|
+
"vite-plus": "1.2.0",
|
|
46
|
+
"void": "1.0.3"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"svelte": "^5.0.0",
|
|
50
50
|
"vite": "^8.0.0",
|
|
51
|
-
"void": "0.
|
|
51
|
+
"void": "1.0.3"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"build": "vp pack",
|
package/src/runtime/App.svelte
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
layouts: props.layouts,
|
|
13
13
|
pageProps: props.pageProps,
|
|
14
14
|
shared: props.shared,
|
|
15
|
-
errors: props.errors,
|
|
16
15
|
params: props.params,
|
|
17
16
|
router: props.router,
|
|
18
17
|
routeUrl: props.routeUrl,
|
|
@@ -25,7 +24,6 @@
|
|
|
25
24
|
let currentLayouts = $state(init.layouts);
|
|
26
25
|
let currentPageProps = $state(init.pageProps);
|
|
27
26
|
let shared = $state(init.shared);
|
|
28
|
-
let errors = $state(init.errors);
|
|
29
27
|
let params = $state(init.params || {});
|
|
30
28
|
let routeUrl = $state(init.routeUrl || "/");
|
|
31
29
|
let navigation = $state(init.navigation || idleNavigationState());
|
|
@@ -46,9 +44,6 @@
|
|
|
46
44
|
setContext("__void_shared", {
|
|
47
45
|
get value() { return shared; },
|
|
48
46
|
});
|
|
49
|
-
setContext("__void_errors", {
|
|
50
|
-
get value() { return errors; },
|
|
51
|
-
});
|
|
52
47
|
setContext("__void_params", {
|
|
53
48
|
get value() { return params; },
|
|
54
49
|
});
|
|
@@ -66,7 +61,6 @@
|
|
|
66
61
|
init.stores.props.subscribe((v) => { currentPageProps = v; }),
|
|
67
62
|
init.stores.layouts.subscribe((v) => { currentLayouts = v; }),
|
|
68
63
|
init.stores.shared.subscribe(replaceShared),
|
|
69
|
-
init.stores.errors.subscribe((v) => { errors = v; }),
|
|
70
64
|
init.stores.params.subscribe((v) => { params = v; }),
|
|
71
65
|
init.stores.route.subscribe((v) => { routeUrl = v; }),
|
|
72
66
|
init.stores.navigation.subscribe((v) => { navigation = v; }),
|
package/src/runtime/Link.svelte
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { getContext, onDestroy, onMount, type Snippet } from "svelte";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
isModifiedEvent,
|
|
5
|
+
mergeDataIntoHref,
|
|
6
|
+
type PrefetchOptions,
|
|
7
|
+
type VoidRouter,
|
|
8
|
+
} from "void/pages-client";
|
|
4
9
|
|
|
5
10
|
type PrefetchStrategy = "hover" | "click" | "mount" | "visible";
|
|
6
11
|
type LinkMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
7
12
|
type NavigateEvent = { preventDefault(): void };
|
|
8
13
|
type EventHandler<T extends Event> = (event: T) => void;
|
|
9
|
-
type PrefetchOptions = {
|
|
10
|
-
cacheFor?: number | string | [string, string];
|
|
11
|
-
method?: LinkMethod;
|
|
12
|
-
};
|
|
13
14
|
|
|
14
15
|
let {
|
|
15
16
|
href,
|
|
@@ -57,12 +58,8 @@
|
|
|
57
58
|
|
|
58
59
|
const router = getContext<VoidRouter>("__void_router");
|
|
59
60
|
|
|
60
|
-
function hasPrefetch(prefetch: boolean | PrefetchStrategy | Array<PrefetchStrategy>): boolean {
|
|
61
|
-
return prefetch !== false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
61
|
function getStrategies(): Array<PrefetchStrategy> {
|
|
65
|
-
if (
|
|
62
|
+
if (prefetchProp !== false && !isGet) {
|
|
66
63
|
throw new Error(
|
|
67
64
|
'Link: prefetch only supports GET links. Remove `prefetch` or use method="GET".',
|
|
68
65
|
);
|
|
@@ -90,13 +87,10 @@
|
|
|
90
87
|
if (hrefWithData === current) {
|
|
91
88
|
return;
|
|
92
89
|
}
|
|
93
|
-
const options: PrefetchOptions = {};
|
|
90
|
+
const options: PrefetchOptions = { method: normalizedMethod };
|
|
94
91
|
if (cacheFor !== undefined) {
|
|
95
92
|
options.cacheFor = cacheFor;
|
|
96
93
|
}
|
|
97
|
-
if (normalizedMethod) {
|
|
98
|
-
options.method = normalizedMethod;
|
|
99
|
-
}
|
|
100
94
|
router.prefetch(hrefWithData, options);
|
|
101
95
|
}
|
|
102
96
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { getContext } from 'svelte';
|
|
2
2
|
import { idleNavigationState, type NavigationState } from 'void/pages-client';
|
|
3
3
|
|
|
4
|
-
export type { NavigationState } from 'void/pages-client';
|
|
5
|
-
|
|
6
4
|
export function useNavigation(): NavigationState {
|
|
7
5
|
const ctx = getContext<{ value: NavigationState }>('__void_navigation');
|
|
8
6
|
if (!ctx) {
|
|
@@ -2,8 +2,6 @@ import { getContext } from 'svelte';
|
|
|
2
2
|
import { ssrProxy } from 'void/pages-client';
|
|
3
3
|
import type { VoidRouter } from 'void/pages-client';
|
|
4
4
|
|
|
5
|
-
export type { VoidRouter } from 'void/pages-client';
|
|
6
|
-
|
|
7
5
|
export function useRouter(): VoidRouter {
|
|
8
6
|
return getContext<VoidRouter>('__void_router') ?? ssrProxy;
|
|
9
7
|
}
|