nukejs 0.0.12 → 0.0.13
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/builder.js +2 -0
- package/dist/hmr-bundle.js +10 -0
- package/dist/hmr.js +3 -0
- package/dist/html-store.d.ts +128 -0
- package/dist/index.d.ts +2 -1
- package/package.json +1 -1
package/dist/builder.js
CHANGED
package/dist/hmr-bundle.js
CHANGED
|
@@ -28,6 +28,16 @@ function hmr() {
|
|
|
28
28
|
}
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
+
if (msg.type === "layout-reload") {
|
|
32
|
+
const base = msg.base === "/" ? "" : msg.base;
|
|
33
|
+
const pathname = window.location.pathname;
|
|
34
|
+
const isUnder = pathname === (base || "/") || pathname.startsWith(base + "/");
|
|
35
|
+
if (isUnder) {
|
|
36
|
+
log.info("[HMR] Layout changed:", msg.base);
|
|
37
|
+
navigate(pathname + window.location.search);
|
|
38
|
+
}
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
31
41
|
if (msg.type === "replace") {
|
|
32
42
|
log.info("[HMR] Component changed:", msg.component);
|
|
33
43
|
navigate(window.location.pathname + window.location.search);
|
package/dist/hmr.js
CHANGED
|
@@ -29,6 +29,9 @@ function buildPayload(filename) {
|
|
|
29
29
|
return { type: "replace", component: stem };
|
|
30
30
|
}
|
|
31
31
|
const url = pageFileToUrl(normalized);
|
|
32
|
+
if (stem === "layout") {
|
|
33
|
+
return { type: "layout-reload", base: url };
|
|
34
|
+
}
|
|
32
35
|
return { type: "reload", url };
|
|
33
36
|
}
|
|
34
37
|
const ext = path.extname(filename).toLowerCase();
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* html-store.ts — Per-Request HTML Head Store
|
|
3
|
+
*
|
|
4
|
+
* Provides a request-scoped store that server components can write to via
|
|
5
|
+
* `useHtml()` during SSR. The accumulated values are flushed into the
|
|
6
|
+
* rendered HTML document after the component tree is fully rendered.
|
|
7
|
+
*
|
|
8
|
+
* Why globalThis?
|
|
9
|
+
* Node's module system may import this file multiple times if the page
|
|
10
|
+
* module and the nukejs package resolve to different copies (e.g. when
|
|
11
|
+
* running from source in dev with tsx). Using a well-known Symbol on
|
|
12
|
+
* globalThis guarantees all copies share the same store instance.
|
|
13
|
+
*
|
|
14
|
+
* Request isolation:
|
|
15
|
+
* runWithHtmlStore() creates a fresh store before rendering and clears it
|
|
16
|
+
* in the `finally` block, so concurrent requests cannot bleed into each other.
|
|
17
|
+
*
|
|
18
|
+
* Title resolution:
|
|
19
|
+
* Layouts and pages can both call useHtml({ title: … }). Layouts typically
|
|
20
|
+
* pass a template function:
|
|
21
|
+
*
|
|
22
|
+
* useHtml({ title: (prev) => `${prev} | Acme` })
|
|
23
|
+
*
|
|
24
|
+
* Operations are collected in render order (outermost layout first, page
|
|
25
|
+
* last) then resolved *in reverse* so the page's string value is the base
|
|
26
|
+
* and layout template functions wrap outward.
|
|
27
|
+
*/
|
|
28
|
+
/** A page sets a literal string; a layout wraps with a template function. */
|
|
29
|
+
export type TitleValue = string | ((prev: string) => string);
|
|
30
|
+
export interface HtmlAttrs {
|
|
31
|
+
lang?: string;
|
|
32
|
+
class?: string;
|
|
33
|
+
style?: string;
|
|
34
|
+
dir?: string;
|
|
35
|
+
[attr: string]: string | undefined;
|
|
36
|
+
}
|
|
37
|
+
export interface BodyAttrs {
|
|
38
|
+
class?: string;
|
|
39
|
+
style?: string;
|
|
40
|
+
[attr: string]: string | undefined;
|
|
41
|
+
}
|
|
42
|
+
export interface MetaTag {
|
|
43
|
+
name?: string;
|
|
44
|
+
property?: string;
|
|
45
|
+
httpEquiv?: string;
|
|
46
|
+
charset?: string;
|
|
47
|
+
content?: string;
|
|
48
|
+
[attr: string]: string | undefined;
|
|
49
|
+
}
|
|
50
|
+
export interface LinkTag {
|
|
51
|
+
rel?: string;
|
|
52
|
+
href?: string;
|
|
53
|
+
type?: string;
|
|
54
|
+
media?: string;
|
|
55
|
+
as?: string;
|
|
56
|
+
crossOrigin?: string;
|
|
57
|
+
integrity?: string;
|
|
58
|
+
hrefLang?: string;
|
|
59
|
+
sizes?: string;
|
|
60
|
+
[attr: string]: string | undefined;
|
|
61
|
+
}
|
|
62
|
+
export interface ScriptTag {
|
|
63
|
+
src?: string;
|
|
64
|
+
content?: string;
|
|
65
|
+
type?: string;
|
|
66
|
+
defer?: boolean;
|
|
67
|
+
async?: boolean;
|
|
68
|
+
crossOrigin?: string;
|
|
69
|
+
integrity?: string;
|
|
70
|
+
noModule?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Where to inject the script in the document.
|
|
73
|
+
* 'head' (default) — placed inside <head>, inside the <!--n-head--> block.
|
|
74
|
+
* 'body' — placed at the very end of <body>, inside the
|
|
75
|
+
* <!--n-body-scripts--> block, just before </body>.
|
|
76
|
+
*/
|
|
77
|
+
position?: 'head' | 'body';
|
|
78
|
+
}
|
|
79
|
+
export interface StyleTag {
|
|
80
|
+
content?: string;
|
|
81
|
+
media?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface HtmlStore {
|
|
84
|
+
/** Collected in render order; resolved in reverse so the page title wins. */
|
|
85
|
+
titleOps: TitleValue[];
|
|
86
|
+
/** Attributes merged onto <html>; last write wins per attribute. */
|
|
87
|
+
htmlAttrs: HtmlAttrs;
|
|
88
|
+
/** Attributes merged onto <body>; last write wins per attribute. */
|
|
89
|
+
bodyAttrs: BodyAttrs;
|
|
90
|
+
/** Accumulated in render order: layouts first, page last. */
|
|
91
|
+
meta: MetaTag[];
|
|
92
|
+
link: LinkTag[];
|
|
93
|
+
script: ScriptTag[];
|
|
94
|
+
style: StyleTag[];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Runs `fn` inside a fresh HTML store and returns the collected values.
|
|
98
|
+
*
|
|
99
|
+
* Usage in SSR:
|
|
100
|
+
* ```ts
|
|
101
|
+
* const store = await runWithHtmlStore(async () => {
|
|
102
|
+
* appHtml = await renderElementToHtml(element, ctx);
|
|
103
|
+
* });
|
|
104
|
+
* // store.titleOps, store.meta, etc. are now populated
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function runWithHtmlStore(fn: () => Promise<void>): Promise<HtmlStore>;
|
|
108
|
+
/**
|
|
109
|
+
* Returns the current request's store, or `undefined` if called outside of
|
|
110
|
+
* a `runWithHtmlStore` context (e.g. in the browser or in a test).
|
|
111
|
+
*/
|
|
112
|
+
export declare function getHtmlStore(): HtmlStore | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* Resolves the final page title from a list of title operations.
|
|
115
|
+
*
|
|
116
|
+
* Operations are walked in *reverse* so the page's value is the starting
|
|
117
|
+
* point and layout template functions wrap it outward:
|
|
118
|
+
*
|
|
119
|
+
* ```
|
|
120
|
+
* ops = [ (p) => `${p} | Acme`, 'About' ] ← layout pushed first, page last
|
|
121
|
+
* Walk in reverse:
|
|
122
|
+
* i=1: op = 'About' → title = 'About'
|
|
123
|
+
* i=0: op = (p) => … → title = 'About | Acme'
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @param fallback Used when ops is empty (e.g. a page that didn't call useHtml).
|
|
127
|
+
*/
|
|
128
|
+
export declare function resolveTitle(ops: TitleValue[], fallback?: string): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { useHtml } from './use-html';
|
|
2
|
-
export type { HtmlOptions
|
|
2
|
+
export type { HtmlOptions } from './use-html';
|
|
3
|
+
export type { TitleValue, HtmlAttrs, BodyAttrs, MetaTag, LinkTag, ScriptTag, StyleTag, } from './html-store';
|
|
3
4
|
export { default as useRouter } from './use-router';
|
|
4
5
|
export { useRequest } from './use-request';
|
|
5
6
|
export type { RequestContext } from './use-request';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nukejs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "A minimal, opinionated full-stack React framework on Node.js that server-renders everything and hydrates only interactive parts.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|