clarusjs 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime/fragments.d.ts +5 -0
- package/dist/runtime/fragments.js +59 -0
- package/dist/runtime/loader.js +12 -1
- package/dist/runtime/router.js +1 -1
- package/dist/server/handler.d.ts +9 -0
- package/dist/server/handler.js +65 -7
- package/dist/vite/build.js +3 -0
- package/dist/vite/manifest.js +2 -2
- package/dist/vite/netlify.d.ts +2 -2
- package/dist/vite/netlify.js +8 -4
- package/dist/vite/plugin.d.ts +2 -0
- package/dist/vite/plugin.js +9 -1
- package/package.json +1 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import './loader.ts';
|
|
2
|
+
/** '/guide/lists/' → '/guide/lists/index.frag.html', keeping the query. */
|
|
3
|
+
export declare function fragmentUrl(url: URL): string;
|
|
4
|
+
/** Fetch the page's fragment and swap it in. Throws when there is none (the caller then loads the page normally). */
|
|
5
|
+
export declare function swap(url: URL, get?: (url: string) => Promise<Response>, isCurrent?: () => boolean): Promise<void>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Fragment navigation: moving between static and server pages swaps their region (data-cl-swap, or the body)
|
|
2
|
+
// instead of reloading. Browser only. Each page's fragment is <path>/index.frag.html; elements marked
|
|
3
|
+
// data-cl-persist="key" are kept across swaps, and the island loader attaches whatever islands arrive.
|
|
4
|
+
import './loader.js';
|
|
5
|
+
/** '/guide/lists/' → '/guide/lists/index.frag.html', keeping the query. */
|
|
6
|
+
export function fragmentUrl(url) {
|
|
7
|
+
return `${url.pathname.replace(/\/+$/, '')}/index.frag.html${url.search}`;
|
|
8
|
+
}
|
|
9
|
+
const region = (doc) => doc.querySelector('[data-cl-swap]') ?? doc.body;
|
|
10
|
+
/** Fetch the page's fragment and swap it in. Throws when there is none (the caller then loads the page normally). */
|
|
11
|
+
export async function swap(url, get = fetch,
|
|
12
|
+
// False once a newer navigation has started: then this one must not touch the document.
|
|
13
|
+
isCurrent = () => true) {
|
|
14
|
+
const src = fragmentUrl(url);
|
|
15
|
+
const res = await get(src);
|
|
16
|
+
if (!res.ok)
|
|
17
|
+
throw new Error(`${res.status}: ${src}`);
|
|
18
|
+
const doc = new DOMParser().parseFromString(await res.text(), 'text/html');
|
|
19
|
+
if (!isCurrent())
|
|
20
|
+
return;
|
|
21
|
+
const next = region(doc);
|
|
22
|
+
const old = region(document);
|
|
23
|
+
// A body can only replace a body, and a marked region a marked region: otherwise load the page normally.
|
|
24
|
+
if ((next === doc.body) !== (old === document.body))
|
|
25
|
+
throw new Error('different swap regions');
|
|
26
|
+
for (const title of next.querySelectorAll('title'))
|
|
27
|
+
title.remove(); // some parsers leave the leading <title> in the body
|
|
28
|
+
// Persisted elements move into the new page as they are, with their state and attached islands.
|
|
29
|
+
for (const old of document.querySelectorAll('[data-cl-persist]')) {
|
|
30
|
+
next.querySelector(`[data-cl-persist="${CSS.escape(old.getAttribute('data-cl-persist'))}"]`)?.replaceWith(old);
|
|
31
|
+
}
|
|
32
|
+
document.title = doc.title;
|
|
33
|
+
old.replaceWith(next);
|
|
34
|
+
globalThis.__clAttach?.(next);
|
|
35
|
+
}
|
|
36
|
+
const navigation = typeof document !== 'undefined' ? globalThis.navigation : undefined;
|
|
37
|
+
// Only the latest navigation may change the document; a URL that failed loads normally, never intercepted again
|
|
38
|
+
// (the reload of a failed URL is itself a navigation to it, which the fallback check lets through).
|
|
39
|
+
let latest = 0;
|
|
40
|
+
let fallback = '';
|
|
41
|
+
navigation?.addEventListener('navigate', (event) => {
|
|
42
|
+
const e = event;
|
|
43
|
+
if (!e.canIntercept || e.hashChange || e.downloadRequest !== null || e.formData)
|
|
44
|
+
return;
|
|
45
|
+
const url = new URL(e.destination.url);
|
|
46
|
+
if (url.href === fallback)
|
|
47
|
+
return;
|
|
48
|
+
const id = ++latest;
|
|
49
|
+
const isCurrent = () => latest === id && !e.signal.aborted;
|
|
50
|
+
e.intercept({
|
|
51
|
+
handler: () => swap(url, fetch, isCurrent).catch(() => {
|
|
52
|
+
if (!isCurrent())
|
|
53
|
+
return;
|
|
54
|
+
fallback = url.href;
|
|
55
|
+
// The URL is already committed: reload it (assign() would only move within the page when it has a #hash).
|
|
56
|
+
location.reload();
|
|
57
|
+
}),
|
|
58
|
+
});
|
|
59
|
+
});
|
package/dist/runtime/loader.js
CHANGED
|
@@ -9,8 +9,11 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
9
9
|
return path;
|
|
10
10
|
};
|
|
11
11
|
import { parse } from './serialize.js';
|
|
12
|
+
import { scope } from './signals.js';
|
|
12
13
|
// Islands scheduled or loading. `data-cl-ready` is set only after attach() succeeds.
|
|
13
14
|
const loading = new WeakSet();
|
|
15
|
+
// Each attached island's disposer: everything its attach() wired (effects, listeners) is released by it.
|
|
16
|
+
const attached = new Map();
|
|
14
17
|
let lastLoad = (src) => import(__rewriteRelativeImportExtension(/* @vite-ignore */ src));
|
|
15
18
|
// Events recorded until an island attaches, then replayed. Clicks and submits are held back (no navigation, no
|
|
16
19
|
// form post) so the island can handle them once it is ready.
|
|
@@ -100,7 +103,7 @@ async function attachOne(el, load, recorded) {
|
|
|
100
103
|
return;
|
|
101
104
|
}
|
|
102
105
|
try {
|
|
103
|
-
mod.attach(el, props, state);
|
|
106
|
+
attached.set(el, scope(() => mod.attach(el, props, state)));
|
|
104
107
|
el.setAttribute('data-cl-ready', '');
|
|
105
108
|
}
|
|
106
109
|
catch (err) {
|
|
@@ -120,6 +123,14 @@ async function attachOne(el, load, recorded) {
|
|
|
120
123
|
*/
|
|
121
124
|
export async function attachAll(root = document, load = lastLoad) {
|
|
122
125
|
lastLoad = load;
|
|
126
|
+
// Islands a navigation swap (or a re-render) took out of the document stop running: their effects and listeners
|
|
127
|
+
// are released. Islands kept across a swap stay connected, so they keep running.
|
|
128
|
+
for (const [el, dispose] of attached) {
|
|
129
|
+
if (!el.isConnected) {
|
|
130
|
+
dispose();
|
|
131
|
+
attached.delete(el);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
123
134
|
const islands = [...root.querySelectorAll('cl-island:not([data-cl-ready]):not([data-cl-error])')].filter((el) => !loading.has(el));
|
|
124
135
|
const now = [];
|
|
125
136
|
for (const el of islands) {
|
package/dist/runtime/router.js
CHANGED
package/dist/server/handler.d.ts
CHANGED
|
@@ -25,6 +25,10 @@ export declare function createHandler(pages: Record<string, () => Promise<PageMo
|
|
|
25
25
|
routerUrl?: string;
|
|
26
26
|
/** Vite's base ('/' or '/docs/'): client routes are listed at their browser paths, under it. */
|
|
27
27
|
base?: string;
|
|
28
|
+
/** Fragment navigation: every static and server page also answers at <path>/index.frag.html. */
|
|
29
|
+
fragments?: boolean;
|
|
30
|
+
/** URL of the fragment navigation script (with fragments on, every static and server page loads it). */
|
|
31
|
+
navUrl?: string;
|
|
28
32
|
}): {
|
|
29
33
|
fetch(request: Request): Promise<Response>;
|
|
30
34
|
routes: string[];
|
|
@@ -33,4 +37,9 @@ export declare function createHandler(pages: Record<string, () => Promise<PageMo
|
|
|
33
37
|
hasLoader(route: string): Promise<boolean>;
|
|
34
38
|
isServerPath(pathname: string): boolean;
|
|
35
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* A page's fragment: its <title>, then the element marked data-cl-swap (the region fragment navigation replaces), or
|
|
42
|
+
* its <body> when nothing is marked. Comments are ignored when looking; nested tags of the same name are balanced.
|
|
43
|
+
*/
|
|
44
|
+
export declare function toFragment(html: string): string;
|
|
36
45
|
export {};
|
package/dist/server/handler.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { modeFor } from './modes.js';
|
|
2
2
|
import { stringify } from '../runtime/serialize.js';
|
|
3
3
|
const DATA = '__data.json';
|
|
4
|
+
const FRAG = 'index.frag.html';
|
|
4
5
|
/** JSON that is safe inside a <script> element and in any HTML context: '<' never appears raw. */
|
|
5
6
|
const safeJson = (json) => json.replace(/</g, '\\u003c');
|
|
6
7
|
/** A whole path segment that is a parameter: [id], [$id]. Anything else, like v[2], is literal text. */
|
|
@@ -69,7 +70,10 @@ export function createHandler(pages, options = {}) {
|
|
|
69
70
|
serverRoutes: routes.filter((r) => modeFor(r.path, modes) === 'server').map((r) => r.path).sort(),
|
|
70
71
|
/** Whether a URL path belongs to a server route (what a host must send to this handler instead of a file). */
|
|
71
72
|
isServerPath(pathname) {
|
|
72
|
-
const
|
|
73
|
+
const trim = (path) => (path.length > 1 ? path.replace(/\/+$/, '') : path);
|
|
74
|
+
// <page>/index.frag.html belongs to that page when it exists; otherwise it is an ordinary path.
|
|
75
|
+
const owner = options.fragments && pathname.endsWith(`/${FRAG}`) ? match(trim(pathname.slice(0, -FRAG.length - 1) || '/')) : null;
|
|
76
|
+
const found = owner ?? match(trim(pathname));
|
|
73
77
|
return Boolean(found && modeFor(found.route.path, modes) === 'server');
|
|
74
78
|
},
|
|
75
79
|
/** Whether a route (as its file names it) has a load(). */
|
|
@@ -90,6 +94,9 @@ export function createHandler(pages, options = {}) {
|
|
|
90
94
|
// A client page's data, fetched by the router: written next to its shell.
|
|
91
95
|
if (mode === 'client')
|
|
92
96
|
out.push(path === '/' ? `/${DATA}` : `${path}/${DATA}`);
|
|
97
|
+
// A static page's fragment, for fragment navigation.
|
|
98
|
+
else if (options.fragments)
|
|
99
|
+
out.push(path === '/' ? `/${FRAG}` : `${path}/${FRAG}`);
|
|
93
100
|
};
|
|
94
101
|
if (!route.keys.length) {
|
|
95
102
|
add(route.path);
|
|
@@ -107,9 +114,9 @@ export function createHandler(pages, options = {}) {
|
|
|
107
114
|
const value = params[key];
|
|
108
115
|
// Each value fills one path segment and names a folder in the build: never empty, '.' or '..'.
|
|
109
116
|
// Path separators on any OS ('/', '\\') and NUL could step out of that folder once the segment is decoded.
|
|
110
|
-
// __data.json
|
|
111
|
-
if (typeof value !== 'string' || value === '' || value === '.' || value === '..' || value === DATA || /[/\\\0]/.test(value)) {
|
|
112
|
-
throw new Error(`${dataFile}: entries() gave ${JSON.stringify(value)} for "${key}"; each value must be a non-empty string without "/" or "\\", and not ".", ".." or "${
|
|
117
|
+
// __data.json and index.frag.html are a page's data and fragment files, so they can't also name a page.
|
|
118
|
+
if (typeof value !== 'string' || value === '' || value === '.' || value === '..' || value === DATA || value === FRAG || /[/\\\0]/.test(value)) {
|
|
119
|
+
throw new Error(`${dataFile}: entries() gave ${JSON.stringify(value)} for "${key}"; each value must be a non-empty string without "/" or "\\", and not ".", "..", "${DATA}" or "${FRAG}"`);
|
|
113
120
|
}
|
|
114
121
|
return encodeURIComponent(value);
|
|
115
122
|
}).join('/'));
|
|
@@ -134,6 +141,15 @@ export function createHandler(pages, options = {}) {
|
|
|
134
141
|
wantsData = true;
|
|
135
142
|
}
|
|
136
143
|
}
|
|
144
|
+
// <static or server route>/index.frag.html: that page's fragment, for fragment navigation.
|
|
145
|
+
let wantsFrag = false;
|
|
146
|
+
if (options.fragments && !wantsData && pathname.endsWith(`/${FRAG}`)) {
|
|
147
|
+
const owner = match(trim(pathname.slice(0, -FRAG.length - 1) || '/'));
|
|
148
|
+
if (owner && modeFor(owner.route.path, modes) !== 'client') {
|
|
149
|
+
found = owner;
|
|
150
|
+
wantsFrag = true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
137
153
|
const head = request.method === 'HEAD';
|
|
138
154
|
const notFound = () => new Response(head ? null : 'Not Found', { status: 404, headers: { 'content-type': 'text/plain; charset=utf-8' } });
|
|
139
155
|
const mode = found && modeFor(found.route.path, modes);
|
|
@@ -175,11 +191,17 @@ export function createHandler(pages, options = {}) {
|
|
|
175
191
|
return new Response(head ? null : safeJson(stringify(props)), { headers: { 'content-type': 'application/json; charset=utf-8' } });
|
|
176
192
|
}
|
|
177
193
|
const html = (await found.route.load()).render(props);
|
|
194
|
+
if (wantsFrag)
|
|
195
|
+
return new Response(head ? null : toFragment(html), { headers: { 'content-type': 'text/html; charset=utf-8' } });
|
|
178
196
|
const visible = maskComments(html);
|
|
179
197
|
const hasIslands = visible.includes('<cl-island ');
|
|
180
|
-
// Only pages with islands get a script, and only the loader; it fetches each island's own chunk.
|
|
181
|
-
|
|
182
|
-
const
|
|
198
|
+
// Only pages with islands get a script, and only the loader; it fetches each island's own chunk. With fragment
|
|
199
|
+
// navigation every page gets the navigation script instead, which brings the loader for islands that arrive.
|
|
200
|
+
const nav = options.fragments === true;
|
|
201
|
+
const style = hasIslands || nav ? '<style>cl-island{display:contents}</style>' : ''; // islands never affect layout
|
|
202
|
+
const script = nav
|
|
203
|
+
? `<script type="module" src="${options.navUrl ?? '/cl-nav.js'}"></script>`
|
|
204
|
+
: hasIslands ? `<script type="module" src="${loaderUrl}"></script>` : '';
|
|
183
205
|
const body = /<html[\s>]/i.test(visible)
|
|
184
206
|
? fullDocument(html, style, script)
|
|
185
207
|
: `<!doctype html><html><head><meta charset="utf-8"><title>clarusjs</title>${style}</head><body>${html}${script}</body></html>`;
|
|
@@ -192,6 +214,42 @@ function failure(message) {
|
|
|
192
214
|
console.error(`[clarusjs] ${message}`);
|
|
193
215
|
return new Response('Internal Server Error', { status: 500, headers: { 'content-type': 'text/plain; charset=utf-8' } });
|
|
194
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* A page's fragment: its <title>, then the element marked data-cl-swap (the region fragment navigation replaces), or
|
|
219
|
+
* its <body> when nothing is marked. Comments are ignored when looking; nested tags of the same name are balanced.
|
|
220
|
+
*/
|
|
221
|
+
export function toFragment(html) {
|
|
222
|
+
// Comments and raw-text contents (scripts, styles, textareas, the title) can hold tag-shaped text: blank them out.
|
|
223
|
+
const masked = maskComments(html).replace(/(<(script|style|textarea|title)\b[^>]*>)([\s\S]*?)(<\/\2\s*>)/gi, (_, open, _tag, body, close) => open + ' '.repeat(body.length) + close);
|
|
224
|
+
const title = /<title\b[^>]*>[\s\S]*?<\/title\s*>/i.exec(masked);
|
|
225
|
+
const titleHtml = title ? html.slice(title.index, title.index + title[0].length) : '<title>clarusjs</title>';
|
|
226
|
+
// The first start tag that carries a data-cl-swap attribute (boolean or with a value), attributes parsed properly.
|
|
227
|
+
const tags = /<([a-zA-Z][\w-]*)((?:\s+[^\s"'>/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]+))?)*)\s*\/?>/g;
|
|
228
|
+
let marked = null;
|
|
229
|
+
for (let m = tags.exec(masked); m; m = tags.exec(masked)) {
|
|
230
|
+
const names = [...m[2].matchAll(/\s+([^\s"'>/=]+)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]+))?/g)].map((a) => a[1].toLowerCase());
|
|
231
|
+
if (names.includes('data-cl-swap')) {
|
|
232
|
+
marked = m;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (marked) {
|
|
237
|
+
const tag = marked[1].toLowerCase();
|
|
238
|
+
const same = new RegExp(`<(/?)${tag}(?=[\\s>/])`, 'gi');
|
|
239
|
+
same.lastIndex = marked.index;
|
|
240
|
+
let depth = 0;
|
|
241
|
+
for (let m = same.exec(masked); m; m = same.exec(masked)) {
|
|
242
|
+
depth += m[1] ? -1 : 1;
|
|
243
|
+
if (depth === 0)
|
|
244
|
+
return titleHtml + html.slice(marked.index, masked.indexOf('>', m.index) + 1);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const open = /<body\b[^>]*>/i.exec(masked);
|
|
248
|
+
const close = masked.lastIndexOf('</body>');
|
|
249
|
+
if (!open || close === -1)
|
|
250
|
+
return `${titleHtml}<body>${html}</body>`;
|
|
251
|
+
return titleHtml + html.slice(open.index, close) + '</body>';
|
|
252
|
+
}
|
|
195
253
|
/** Same length as `html`, with every HTML comment blanked out, so positions found in it are valid in `html`. */
|
|
196
254
|
function maskComments(html) {
|
|
197
255
|
return html.replace(/<!--[\s\S]*?-->/g, (c) => ' '.repeat(c.length));
|
package/dist/vite/build.js
CHANGED
|
@@ -30,6 +30,9 @@ export function routeToFile(route) {
|
|
|
30
30
|
// A client page's data file is written as itself, next to the page's shell.
|
|
31
31
|
if (path === '__data.json' || path.endsWith('/__data.json'))
|
|
32
32
|
return path;
|
|
33
|
+
// A page's fragment, likewise.
|
|
34
|
+
if (path === 'index.frag.html' || path.endsWith('/index.frag.html'))
|
|
35
|
+
return path;
|
|
33
36
|
return path ? `${path}/index.html` : 'index.html';
|
|
34
37
|
}
|
|
35
38
|
/**
|
package/dist/vite/manifest.js
CHANGED
|
@@ -70,8 +70,8 @@ export function writeManifest(distDir, routes, base, loaded = [], server = []) {
|
|
|
70
70
|
const manifest = { version: 1, routes: {} };
|
|
71
71
|
const dataFile = (route) => (route === '/' ? '/__data.json' : `${route}/__data.json`);
|
|
72
72
|
for (const route of routes) {
|
|
73
|
-
if (route.endsWith('/__data.json'))
|
|
74
|
-
continue; //
|
|
73
|
+
if (route.endsWith('/__data.json') || route.endsWith('/index.frag.html'))
|
|
74
|
+
continue; // data and fragments, not pages
|
|
75
75
|
const isClient = routes.includes(dataFile(route));
|
|
76
76
|
// A client route's loader runs when its data file is written.
|
|
77
77
|
const ran = loaded.includes(route) || (isClient && loaded.includes(dataFile(route)));
|
package/dist/vite/netlify.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** '/account/[id]' → ['/account/:id', '/account/:id/'] (Netlify paths use URLPattern syntax). */
|
|
2
|
-
export declare function netlifyPaths(route: string): string[];
|
|
2
|
+
export declare function netlifyPaths(route: string, fragments?: boolean): string[];
|
|
3
3
|
/** Write (or, without server routes, remove) the function in `<root>/.netlify/v1/functions`. */
|
|
4
|
-
export declare function writeNetlifyFunction(root: string, serverEntry: string, serverRoutes: string[]): void;
|
|
4
|
+
export declare function writeNetlifyFunction(root: string, serverEntry: string, serverRoutes: string[], fragments?: boolean): void;
|
package/dist/vite/netlify.js
CHANGED
|
@@ -4,7 +4,7 @@ import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
|
4
4
|
import { dirname, relative, resolve, sep } from 'node:path';
|
|
5
5
|
const FUNCTION = '.netlify/v1/functions/clarusjs-server.mjs';
|
|
6
6
|
/** '/account/[id]' → ['/account/:id', '/account/:id/'] (Netlify paths use URLPattern syntax). */
|
|
7
|
-
export function netlifyPaths(route) {
|
|
7
|
+
export function netlifyPaths(route, fragments = false) {
|
|
8
8
|
const segments = route.split('/');
|
|
9
9
|
const keyOf = (seg) => /^\[([A-Za-z_$][\w$]*)\]$/.exec(seg)?.[1];
|
|
10
10
|
const valid = (key) => /^[A-Za-z_]\w*$/.test(key);
|
|
@@ -23,10 +23,14 @@ export function netlifyPaths(route) {
|
|
|
23
23
|
return `:${valid(key) ? key : fresh()}`;
|
|
24
24
|
return seg.replace(/[:*?+(){}\\]/g, '\\$&'); // literal text, not pattern syntax
|
|
25
25
|
}).join('/');
|
|
26
|
-
|
|
26
|
+
const paths = path === '/' || path === '' ? ['/'] : [path, `${path}/`];
|
|
27
|
+
// The page's fragment, for fragment navigation, comes from the same function.
|
|
28
|
+
if (fragments)
|
|
29
|
+
paths.push(path === '/' || path === '' ? '/index.frag.html' : `${path}/index.frag.html`);
|
|
30
|
+
return paths;
|
|
27
31
|
}
|
|
28
32
|
/** Write (or, without server routes, remove) the function in `<root>/.netlify/v1/functions`. */
|
|
29
|
-
export function writeNetlifyFunction(root, serverEntry, serverRoutes) {
|
|
33
|
+
export function writeNetlifyFunction(root, serverEntry, serverRoutes, fragments = false) {
|
|
30
34
|
const file = resolve(root, FUNCTION);
|
|
31
35
|
if (!serverRoutes.length) {
|
|
32
36
|
rmSync(file, { force: true });
|
|
@@ -40,7 +44,7 @@ export function writeNetlifyFunction(root, serverEntry, serverRoutes) {
|
|
|
40
44
|
'',
|
|
41
45
|
'export default (request) => handler.fetch(request)',
|
|
42
46
|
'',
|
|
43
|
-
`export const config = ${JSON.stringify({ path: serverRoutes.flatMap(netlifyPaths), preferStatic: true })}`,
|
|
47
|
+
`export const config = ${JSON.stringify({ path: serverRoutes.flatMap((r) => netlifyPaths(r, fragments)), preferStatic: true })}`,
|
|
44
48
|
'',
|
|
45
49
|
].join('\n'));
|
|
46
50
|
}
|
package/dist/vite/plugin.d.ts
CHANGED
|
@@ -7,5 +7,7 @@ export type ClarusOptions = {
|
|
|
7
7
|
routes?: ModeTable;
|
|
8
8
|
/** Where server routes deploy. 'netlify': a Netlify Function (Frameworks API) next to the static files. */
|
|
9
9
|
adapter?: 'netlify';
|
|
10
|
+
/** Fragment navigation: each static and server page also answers at <path>/index.frag.html. */
|
|
11
|
+
fragments?: boolean;
|
|
10
12
|
};
|
|
11
13
|
export default function clarusjs(options?: ClarusOptions): Plugin;
|
package/dist/vite/plugin.js
CHANGED
|
@@ -30,6 +30,7 @@ export function clientUrlFor(root, file) {
|
|
|
30
30
|
}
|
|
31
31
|
const LOADER_ENTRY = 'cl-loader';
|
|
32
32
|
const ROUTER_ENTRY = 'cl-router';
|
|
33
|
+
const NAV_ENTRY = 'cl-nav';
|
|
33
34
|
// Client entry name of a client-mode page's browser render module.
|
|
34
35
|
const renderEntry = (name) => `render/${name}`;
|
|
35
36
|
const CLIENT_OUT = 'dist/client';
|
|
@@ -112,6 +113,8 @@ export default function clarusjs(options = {}) {
|
|
|
112
113
|
const client = clientPages(appRoot, modes);
|
|
113
114
|
if (client.size)
|
|
114
115
|
input[ROUTER_ENTRY] = here('../runtime/router');
|
|
116
|
+
if (options.fragments)
|
|
117
|
+
input[NAV_ENTRY] = here('../runtime/fragments');
|
|
115
118
|
for (const file of client.values())
|
|
116
119
|
input[renderEntry(entryName(appRoot, file))] = `${file}?render`;
|
|
117
120
|
config.builder = {};
|
|
@@ -175,13 +178,15 @@ export default function clarusjs(options = {}) {
|
|
|
175
178
|
writeManifest(dist, routes, builder.config.base, loaded, server);
|
|
176
179
|
}
|
|
177
180
|
if (options.adapter === 'netlify')
|
|
178
|
-
writeNetlifyFunction(builder.config.root, entry, server.map((s) => s.route));
|
|
181
|
+
writeNetlifyFunction(builder.config.root, entry, server.map((s) => s.route), options.fragments === true);
|
|
179
182
|
},
|
|
180
183
|
resolveId(id) {
|
|
181
184
|
if (id === '/cl-loader.js')
|
|
182
185
|
return here('../runtime/loader');
|
|
183
186
|
if (id === '/cl-router.js')
|
|
184
187
|
return here('../runtime/router');
|
|
188
|
+
if (id === '/cl-nav.js')
|
|
189
|
+
return here('../runtime/fragments');
|
|
185
190
|
if (id === ENTRY)
|
|
186
191
|
return '\0' + ENTRY;
|
|
187
192
|
},
|
|
@@ -191,6 +196,7 @@ export default function clarusjs(options = {}) {
|
|
|
191
196
|
const urls = builtUrls();
|
|
192
197
|
const loaderUrl = urls?.get(LOADER_ENTRY) ?? '/cl-loader.js';
|
|
193
198
|
const routerUrl = urls?.get(ROUTER_ENTRY) ?? '/cl-router.js';
|
|
199
|
+
const navUrl = urls?.get(NAV_ENTRY) ?? '/cl-nav.js';
|
|
194
200
|
// Built: hashed chunk URLs. Dev: the source, served as JS by Vite.
|
|
195
201
|
const client = {};
|
|
196
202
|
for (const [route, file] of clientPages(root, modes)) {
|
|
@@ -212,6 +218,8 @@ export default function clarusjs(options = {}) {
|
|
|
212
218
|
` routerUrl: ${JSON.stringify(routerUrl)},\n` +
|
|
213
219
|
` client: ${JSON.stringify(client)},\n` +
|
|
214
220
|
` base: ${JSON.stringify(base)},\n` +
|
|
221
|
+
` fragments: ${options.fragments === true},\n` +
|
|
222
|
+
` navUrl: ${JSON.stringify(navUrl)},\n` +
|
|
215
223
|
`})\n`;
|
|
216
224
|
},
|
|
217
225
|
transform: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clarusjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Clear, compiled views: templates compiled to server HTML, with JavaScript only for interactive islands. SSR, SSG and CSR from one component model, built on Vite.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|