@sigil-dev/grimoire 0.9.1 → 0.9.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/index.ts +35 -35
- package/package.json +9 -8
- package/preload.js +3 -3
- package/server.ts +19 -19
- package/src/client/deps.ts +13 -7
- package/src/client/enhance.ts +98 -98
- package/src/client/head.ts +30 -30
- package/src/client/index.ts +2 -2
- package/src/client/router.ts +445 -371
- package/src/client/scope.ts +22 -22
- package/src/dev/compile-module.ts +163 -163
- package/src/dev/effect-registry.ts +23 -23
- package/src/dev/graph.ts +114 -114
- package/src/dev/hmr-client.ts +185 -185
- package/src/dev/loader.ts +47 -47
- package/src/dev/paths.ts +14 -14
- package/src/dev/runtime-bundle.ts +52 -52
- package/src/dev/watcher.ts +47 -46
- package/src/env/dynamic-private.ts +19 -19
- package/src/env/dynamic-public.ts +22 -22
- package/src/env/index.ts +25 -25
- package/src/env/plugin.ts +19 -19
- package/src/env/private.ts +5 -5
- package/src/env/public.ts +7 -7
- package/src/env/typegen.ts +61 -61
- package/src/headers.ts +114 -114
- package/src/integrations/vite.ts +73 -73
- package/src/logger/index.ts +4 -4
- package/src/logger/instance.ts +6 -6
- package/src/logger/logger.ts +113 -113
- package/src/logger/request-middleware.ts +24 -24
- package/src/logger/transports.ts +117 -117
- package/src/logger/types.ts +39 -39
- package/src/rendering/head.ts +47 -47
- package/src/rendering/hydrate.ts +98 -79
- package/src/rendering/index.ts +455 -372
- package/src/rendering/ssrPlugin.ts +69 -69
- package/src/routing/manifest-gen.ts +12 -11
- package/src/routing/router.ts +109 -109
- package/src/routing/scanner.ts +141 -141
- package/src/routing/transform-routes.ts +102 -102
- package/src/sentinels/error.ts +52 -52
- package/src/sentinels/fail.ts +41 -41
- package/src/sentinels/redirect.ts +35 -35
- package/src/server/build.ts +243 -219
- package/src/server/context.ts +10 -10
- package/src/server/cookie-utils.ts +66 -66
- package/src/server/coordinator.ts +364 -356
- package/src/server/hooks.ts +114 -114
- package/src/server/index.ts +655 -658
- package/src/server/interactive.ts +56 -56
- package/src/server/plugins.ts +121 -120
- package/src/server/worker.ts +58 -58
- package/src/typegen/index.ts +356 -356
- package/src/types.ts +4 -4
- package/test/client-router.test.ts +37 -31
- package/test/context.test.ts +52 -52
- package/test/env.test.ts +70 -70
- package/test/exports.test.ts +37 -37
- package/test/fail.test.ts +46 -46
- package/test/headers.test.ts +100 -100
- package/test/hydration.test.ts +119 -119
- package/test/middleware.test.ts +223 -223
- package/test/preload.ts +5 -5
- package/test/redirect-error.test.ts +112 -112
- package/test/rendering.test.ts +615 -579
- package/test/routing.test.ts +81 -81
- package/test/scanning.test.ts +200 -200
- package/test/scope.test.ts +195 -195
- package/test/server.test.ts +249 -249
- package/test/streaming.test.ts +125 -125
- package/test/transform-routes.test.ts +84 -84
- package/test/typegen.test.ts +682 -682
- package/tsconfig.json +10 -10
- package/.grimoire/_routes.dom.js +0 -8
- package/.grimoire/_routes.hydrate.js +0 -8
- package/.grimoire/tsconfig.generated.json +0 -11
- package/.grimoire/types/ambient.d.ts +0 -59
- package/.grimoire/types/api/hello/$types.d.ts +0 -50
- package/.grimoire/types/api/items/$types.d.ts +0 -50
- package/.grimoire/types/echo/$types.d.ts +0 -50
- package/.grimoire/types/env-private.d.ts +0 -5
- package/.grimoire/types/env-public.d.ts +0 -5
- package/.grimoire/types/mixed/$types.d.ts +0 -50
- package/.grimoire/types/params/[docId]/$types.d.ts +0 -52
- package/.grimoire/types/reject/$types.d.ts +0 -50
- package/public/__grimoire__/hydrate.js +0 -585
- package/public/__grimoire__/index.js +0 -490
package/index.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
export { Head } from "./src/rendering/head";
|
|
2
|
-
|
|
3
|
-
export type { RouteFile, RouteTree } from "./src/routing/scanner";
|
|
4
|
-
export type { ErrorResult } from "./src/sentinels/error.ts";
|
|
5
|
-
export { error, isErrorResult } from "./src/sentinels/error.ts";
|
|
6
|
-
export type { FailResult } from "./src/sentinels/fail.ts";
|
|
7
|
-
export { fail, isFailResult } from "./src/sentinels/fail.ts";
|
|
8
|
-
export type { RedirectResult } from "./src/sentinels/redirect.ts";
|
|
9
|
-
export { isRedirectResult, redirect } from "./src/sentinels/redirect.ts";
|
|
10
|
-
export type {
|
|
11
|
-
CookieOptions,
|
|
12
|
-
Cookies,
|
|
13
|
-
Handle,
|
|
14
|
-
RequestEvent,
|
|
15
|
-
ResolveFunction,
|
|
16
|
-
} from "./src/server/hooks";
|
|
17
|
-
export { createHooks, sequence } from "./src/server/hooks";
|
|
18
|
-
export type {
|
|
19
|
-
BuiltinWorkerMode,
|
|
20
|
-
CoordinatorContext,
|
|
21
|
-
GrimoireConfig,
|
|
22
|
-
GrimoirePlugin,
|
|
23
|
-
LayoutServerLoad,
|
|
24
|
-
LoadContext,
|
|
25
|
-
PageServerLoad,
|
|
26
|
-
RenderContext,
|
|
27
|
-
RequestHandler,
|
|
28
|
-
RouteInfo,
|
|
29
|
-
TypedLoadContext,
|
|
30
|
-
WorkerDescriptor,
|
|
31
|
-
WorkerEnv,
|
|
32
|
-
WorkerMode,
|
|
33
|
-
WsRouteHandler,
|
|
34
|
-
} from "./src/types";
|
|
35
|
-
export { defineConfig } from "./src/types";
|
|
1
|
+
export { Head } from "./src/rendering/head";
|
|
2
|
+
// registerSSRPlugin is server-only — import from "@sigil-dev/grimoire/bun"
|
|
3
|
+
export type { RouteFile, RouteTree } from "./src/routing/scanner";
|
|
4
|
+
export type { ErrorResult } from "./src/sentinels/error.ts";
|
|
5
|
+
export { error, isErrorResult } from "./src/sentinels/error.ts";
|
|
6
|
+
export type { FailResult } from "./src/sentinels/fail.ts";
|
|
7
|
+
export { fail, isFailResult } from "./src/sentinels/fail.ts";
|
|
8
|
+
export type { RedirectResult } from "./src/sentinels/redirect.ts";
|
|
9
|
+
export { isRedirectResult, redirect } from "./src/sentinels/redirect.ts";
|
|
10
|
+
export type {
|
|
11
|
+
CookieOptions,
|
|
12
|
+
Cookies,
|
|
13
|
+
Handle,
|
|
14
|
+
RequestEvent,
|
|
15
|
+
ResolveFunction,
|
|
16
|
+
} from "./src/server/hooks";
|
|
17
|
+
export { createHooks, sequence } from "./src/server/hooks";
|
|
18
|
+
export type {
|
|
19
|
+
BuiltinWorkerMode,
|
|
20
|
+
CoordinatorContext,
|
|
21
|
+
GrimoireConfig,
|
|
22
|
+
GrimoirePlugin,
|
|
23
|
+
LayoutServerLoad,
|
|
24
|
+
LoadContext,
|
|
25
|
+
PageServerLoad,
|
|
26
|
+
RenderContext,
|
|
27
|
+
RequestHandler,
|
|
28
|
+
RouteInfo,
|
|
29
|
+
TypedLoadContext,
|
|
30
|
+
WorkerDescriptor,
|
|
31
|
+
WorkerEnv,
|
|
32
|
+
WorkerMode,
|
|
33
|
+
WsRouteHandler,
|
|
34
|
+
} from "./src/types";
|
|
35
|
+
export { defineConfig } from "./src/types";
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sigil-dev/grimoire",
|
|
3
|
+
"description": "Full stack web framework using Sigil",
|
|
3
4
|
"module": "index.ts",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"private": false,
|
|
6
|
-
"version": "0.9.
|
|
7
|
+
"version": "0.9.3",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": "./index.ts",
|
|
9
10
|
"./server": "./server.ts",
|
|
@@ -25,19 +26,19 @@
|
|
|
25
26
|
"test": "bun test"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"@babel/plugin-syntax-typescript": "^8.0.0-rc.6",
|
|
31
|
-
"@babel/preset-typescript": "^8.0.0-rc.6",
|
|
32
|
-
"@babel/types": "^8.0.0-rc.6",
|
|
33
|
-
"@sigil-dev/compiler": "0.9.1",
|
|
34
|
-
"@sigil-dev/runtime": "0.9.1",
|
|
29
|
+
"@sigil-dev/compiler": "0.9.3",
|
|
30
|
+
"@sigil-dev/runtime": "0.9.3",
|
|
35
31
|
"vite": "^8.0.16"
|
|
36
32
|
},
|
|
37
33
|
"peerDependencies": {
|
|
38
34
|
"typescript": "^5"
|
|
39
35
|
},
|
|
40
36
|
"devDependencies": {
|
|
37
|
+
"@babel/core": "^8.0.0-rc.6",
|
|
38
|
+
"@babel/plugin-syntax-jsx": "^8.0.0-rc.6",
|
|
39
|
+
"@babel/plugin-syntax-typescript": "^8.0.0-rc.6",
|
|
40
|
+
"@babel/preset-typescript": "^8.0.0-rc.6",
|
|
41
|
+
"@babel/types": "^8.0.0-rc.6",
|
|
41
42
|
"@types/bun": "latest"
|
|
42
43
|
}
|
|
43
44
|
}
|
package/preload.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { registerSSRPlugin } from "./src/rendering/ssrPlugin.ts";
|
|
2
|
-
|
|
3
|
-
registerSSRPlugin();
|
|
1
|
+
import { registerSSRPlugin } from "./src/rendering/ssrPlugin.ts";
|
|
2
|
+
|
|
3
|
+
registerSSRPlugin();
|
package/server.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export { log } from "./src/logger/instance.ts";
|
|
2
|
-
export { scanRoutes } from "./src/routing/scanner";
|
|
3
|
-
export { createServer } from "./src/server";
|
|
4
|
-
export { buildProject } from "./src/server/build";
|
|
5
|
-
export { parseCookies } from "./src/server/cookie-utils";
|
|
6
|
-
export { startCoordinator } from "./src/server/coordinator.ts";
|
|
7
|
-
export {
|
|
8
|
-
createWaiter,
|
|
9
|
-
listenForKeys,
|
|
10
|
-
stopListening,
|
|
11
|
-
} from "./src/server/interactive.ts";
|
|
12
|
-
export {
|
|
13
|
-
runDeserializeLocals,
|
|
14
|
-
runRouteRequest,
|
|
15
|
-
runSerializeLocals,
|
|
16
|
-
runWorkerSpawn,
|
|
17
|
-
} from "./src/server/plugins";
|
|
18
|
-
export type { TypegenConfig } from "./src/typegen";
|
|
19
|
-
export { generateTypes } from "./src/typegen";
|
|
1
|
+
export { log } from "./src/logger/instance.ts";
|
|
2
|
+
export { scanRoutes } from "./src/routing/scanner";
|
|
3
|
+
export { createServer } from "./src/server";
|
|
4
|
+
export { buildProject } from "./src/server/build";
|
|
5
|
+
export { parseCookies } from "./src/server/cookie-utils";
|
|
6
|
+
export { startCoordinator } from "./src/server/coordinator.ts";
|
|
7
|
+
export {
|
|
8
|
+
createWaiter,
|
|
9
|
+
listenForKeys,
|
|
10
|
+
stopListening,
|
|
11
|
+
} from "./src/server/interactive.ts";
|
|
12
|
+
export {
|
|
13
|
+
runDeserializeLocals,
|
|
14
|
+
runRouteRequest,
|
|
15
|
+
runSerializeLocals,
|
|
16
|
+
runWorkerSpawn,
|
|
17
|
+
} from "./src/server/plugins";
|
|
18
|
+
export type { TypegenConfig } from "./src/typegen";
|
|
19
|
+
export { generateTypes } from "./src/typegen";
|
package/src/client/deps.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
const routeDeps
|
|
1
|
+
const routeDeps = new Map<string, Set<string>>();
|
|
2
2
|
let _collecting: Set<string> | null = null;
|
|
3
3
|
|
|
4
|
-
export function startCollecting(): void {
|
|
4
|
+
export function startCollecting(): void {
|
|
5
|
+
_collecting = new Set();
|
|
6
|
+
}
|
|
5
7
|
export function stopCollecting(pattern: string): void {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
if (_collecting) routeDeps.set(pattern, _collecting);
|
|
9
|
+
_collecting = null;
|
|
10
|
+
}
|
|
11
|
+
export function depends(key: string): void {
|
|
12
|
+
_collecting?.add(key);
|
|
8
13
|
}
|
|
9
|
-
export function depends(key: string): void { _collecting?.add(key); }
|
|
10
14
|
export function hasDep(pattern: string, key: string): boolean {
|
|
11
|
-
|
|
15
|
+
return routeDeps.get(pattern)?.has(key) ?? false;
|
|
16
|
+
}
|
|
17
|
+
export function clearDeps(pattern: string): void {
|
|
18
|
+
routeDeps.delete(pattern);
|
|
12
19
|
}
|
|
13
|
-
export function clearDeps(pattern: string): void { routeDeps.delete(pattern); }
|
package/src/client/enhance.ts
CHANGED
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client-side form action handler.
|
|
3
|
-
* Wraps form submission with fetch, handles fail() responses, and updates state.
|
|
4
|
-
*
|
|
5
|
-
* Usage in +page.tsx:
|
|
6
|
-
*
|
|
7
|
-
* import { enhance } from "@sigil-dev/grimoire/client";
|
|
8
|
-
* import { createSignal } from "@sigil-dev/runtime";
|
|
9
|
-
*
|
|
10
|
-
* const [errors, setErrors] = createSignal({});
|
|
11
|
-
*
|
|
12
|
-
* <form use={[enhance, { action: "/api/login", onSuccess: () => { ... }, onFail: (data) => setErrors(data) }]}>
|
|
13
|
-
* ...
|
|
14
|
-
* </form>
|
|
15
|
-
*/
|
|
16
|
-
export interface EnhanceOptions {
|
|
17
|
-
/** URL to submit to (defaults to form's action) */
|
|
18
|
-
action?: string;
|
|
19
|
-
/** Called on successful submission (303 redirect) */
|
|
20
|
-
onSuccess?: (result: { redirect: string }) => void;
|
|
21
|
-
/** Called when server returns fail() with validation data */
|
|
22
|
-
onFail?: (data: Record<string, unknown>) => void;
|
|
23
|
-
/** Called on network or unexpected errors */
|
|
24
|
-
onError?: (error: Error) => void;
|
|
25
|
-
/** Whether to reset the form on success (default: true) */
|
|
26
|
-
reset?: boolean;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* use:enhance directive for progressive form enhancement.
|
|
31
|
-
* Attaches to a <form> element and intercepts submit events.
|
|
32
|
-
*
|
|
33
|
-
* Returns a cleanup function.
|
|
34
|
-
*/
|
|
35
|
-
export function enhance(
|
|
36
|
-
form: HTMLFormElement,
|
|
37
|
-
options: EnhanceOptions = {},
|
|
38
|
-
): () => void {
|
|
39
|
-
const { action, onSuccess, onFail, onError, reset = true } = options;
|
|
40
|
-
|
|
41
|
-
async function handleSubmit(e: Event) {
|
|
42
|
-
e.preventDefault();
|
|
43
|
-
|
|
44
|
-
const formData = new FormData(form);
|
|
45
|
-
const url =
|
|
46
|
-
action ?? form.getAttribute("action") ?? window.location.pathname;
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
const res = await fetch(url, {
|
|
50
|
-
method: "POST",
|
|
51
|
-
headers: {
|
|
52
|
-
"X-Grimoire-Form": "1",
|
|
53
|
-
},
|
|
54
|
-
body: formData,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const contentType = res.headers.get("content-type") ?? "";
|
|
58
|
-
|
|
59
|
-
if (contentType.includes("application/json")) {
|
|
60
|
-
const json = await res.json();
|
|
61
|
-
|
|
62
|
-
if (json.fail) {
|
|
63
|
-
// fail() response — validation errors
|
|
64
|
-
onFail?.(json.data);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Regular JSON response (API route)
|
|
69
|
-
onSuccess?.(json);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Non-JSON response (303 redirect or other)
|
|
74
|
-
if (res.status === 303) {
|
|
75
|
-
const location = res.headers.get("location") ?? "/";
|
|
76
|
-
if (reset) form.reset();
|
|
77
|
-
onSuccess?.({ redirect: location });
|
|
78
|
-
// Navigate to the redirect target
|
|
79
|
-
window.history.pushState({}, "", location);
|
|
80
|
-
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Other response
|
|
85
|
-
if (res.ok) {
|
|
86
|
-
if (reset) form.reset();
|
|
87
|
-
onSuccess?.({ redirect: window.location.pathname });
|
|
88
|
-
} else {
|
|
89
|
-
onError?.(new Error(`Form submission failed: ${res.status}`));
|
|
90
|
-
}
|
|
91
|
-
} catch (err) {
|
|
92
|
-
onError?.(err instanceof Error ? err : new Error(String(err)));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
form.addEventListener("submit", handleSubmit);
|
|
97
|
-
return () => form.removeEventListener("submit", handleSubmit);
|
|
98
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Client-side form action handler.
|
|
3
|
+
* Wraps form submission with fetch, handles fail() responses, and updates state.
|
|
4
|
+
*
|
|
5
|
+
* Usage in +page.tsx:
|
|
6
|
+
*
|
|
7
|
+
* import { enhance } from "@sigil-dev/grimoire/client";
|
|
8
|
+
* import { createSignal } from "@sigil-dev/runtime";
|
|
9
|
+
*
|
|
10
|
+
* const [errors, setErrors] = createSignal({});
|
|
11
|
+
*
|
|
12
|
+
* <form use={[enhance, { action: "/api/login", onSuccess: () => { ... }, onFail: (data) => setErrors(data) }]}>
|
|
13
|
+
* ...
|
|
14
|
+
* </form>
|
|
15
|
+
*/
|
|
16
|
+
export interface EnhanceOptions {
|
|
17
|
+
/** URL to submit to (defaults to form's action) */
|
|
18
|
+
action?: string;
|
|
19
|
+
/** Called on successful submission (303 redirect) */
|
|
20
|
+
onSuccess?: (result: { redirect: string }) => void;
|
|
21
|
+
/** Called when server returns fail() with validation data */
|
|
22
|
+
onFail?: (data: Record<string, unknown>) => void;
|
|
23
|
+
/** Called on network or unexpected errors */
|
|
24
|
+
onError?: (error: Error) => void;
|
|
25
|
+
/** Whether to reset the form on success (default: true) */
|
|
26
|
+
reset?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* use:enhance directive for progressive form enhancement.
|
|
31
|
+
* Attaches to a <form> element and intercepts submit events.
|
|
32
|
+
*
|
|
33
|
+
* Returns a cleanup function.
|
|
34
|
+
*/
|
|
35
|
+
export function enhance(
|
|
36
|
+
form: HTMLFormElement,
|
|
37
|
+
options: EnhanceOptions = {},
|
|
38
|
+
): () => void {
|
|
39
|
+
const { action, onSuccess, onFail, onError, reset = true } = options;
|
|
40
|
+
|
|
41
|
+
async function handleSubmit(e: Event) {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
|
|
44
|
+
const formData = new FormData(form);
|
|
45
|
+
const url =
|
|
46
|
+
action ?? form.getAttribute("action") ?? window.location.pathname;
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const res = await fetch(url, {
|
|
50
|
+
method: "POST",
|
|
51
|
+
headers: {
|
|
52
|
+
"X-Grimoire-Form": "1",
|
|
53
|
+
},
|
|
54
|
+
body: formData,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
58
|
+
|
|
59
|
+
if (contentType.includes("application/json")) {
|
|
60
|
+
const json = await res.json();
|
|
61
|
+
|
|
62
|
+
if (json.fail) {
|
|
63
|
+
// fail() response — validation errors
|
|
64
|
+
onFail?.(json.data);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Regular JSON response (API route)
|
|
69
|
+
onSuccess?.(json);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Non-JSON response (303 redirect or other)
|
|
74
|
+
if (res.status === 303) {
|
|
75
|
+
const location = res.headers.get("location") ?? "/";
|
|
76
|
+
if (reset) form.reset();
|
|
77
|
+
onSuccess?.({ redirect: location });
|
|
78
|
+
// Navigate to the redirect target
|
|
79
|
+
window.history.pushState({}, "", location);
|
|
80
|
+
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Other response
|
|
85
|
+
if (res.ok) {
|
|
86
|
+
if (reset) form.reset();
|
|
87
|
+
onSuccess?.({ redirect: window.location.pathname });
|
|
88
|
+
} else {
|
|
89
|
+
onError?.(new Error(`Form submission failed: ${res.status}`));
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
onError?.(err instanceof Error ? err : new Error(String(err)));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
form.addEventListener("submit", handleSubmit);
|
|
97
|
+
return () => form.removeEventListener("submit", handleSubmit);
|
|
98
|
+
}
|
package/src/client/head.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
let headElements: (string | Node)[] = [];
|
|
2
|
-
|
|
3
|
-
export function resetHead(): void {
|
|
4
|
-
headElements = [];
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function collectHead(): (string | Node)[] {
|
|
8
|
-
return headElements;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function applyHead(): void {
|
|
12
|
-
|
|
13
|
-
document.querySelectorAll("[data-sigil-head]").forEach((el) => el.remove());
|
|
14
|
-
for (const el of headElements) {
|
|
15
|
-
if (el instanceof Node) {
|
|
16
|
-
const clone = el.cloneNode(true) as HTMLElement;
|
|
17
|
-
clone.dataset.sigilHead = "1";
|
|
18
|
-
document.head.appendChild(clone);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function Head({ children }: { children: string | Node }): Comment {
|
|
24
|
-
if (typeof document === "undefined") {
|
|
25
|
-
headElements.push(children);
|
|
26
|
-
} else if (children instanceof Node) {
|
|
27
|
-
(headElements as Node[]).push(children);
|
|
28
|
-
}
|
|
29
|
-
return document.createComment("head");
|
|
30
|
-
}
|
|
1
|
+
let headElements: (string | Node)[] = [];
|
|
2
|
+
|
|
3
|
+
export function resetHead(): void {
|
|
4
|
+
headElements = [];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function collectHead(): (string | Node)[] {
|
|
8
|
+
return headElements;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function applyHead(): void {
|
|
12
|
+
//biome-ignore lint: ChildNode.remove() returns void??? sure typescript
|
|
13
|
+
document.querySelectorAll("[data-sigil-head]").forEach((el) => el.remove());
|
|
14
|
+
for (const el of headElements) {
|
|
15
|
+
if (el instanceof Node) {
|
|
16
|
+
const clone = el.cloneNode(true) as HTMLElement;
|
|
17
|
+
clone.dataset.sigilHead = "1";
|
|
18
|
+
document.head.appendChild(clone);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function Head({ children }: { children: string | Node }): Comment {
|
|
24
|
+
if (typeof document === "undefined") {
|
|
25
|
+
headElements.push(children);
|
|
26
|
+
} else if (children instanceof Node) {
|
|
27
|
+
(headElements as Node[]).push(children);
|
|
28
|
+
}
|
|
29
|
+
return document.createComment("head");
|
|
30
|
+
}
|
package/src/client/index.ts
CHANGED