@blinkk/root 3.0.1 → 3.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/{chunk-FQBA5QSG.js → chunk-3Z5TNZEP.js} +3 -3
- package/dist/chunk-3Z5TNZEP.js.map +7 -0
- package/dist/{chunk-JCRXBB26.js → chunk-6NBKAR5Y.js} +2 -2
- package/dist/chunk-6NBKAR5Y.js.map +7 -0
- package/dist/chunk-6P3B7ZXL.js +1 -1
- package/dist/chunk-6P3B7ZXL.js.map +7 -1
- package/dist/{chunk-PVBPP5LN.js → chunk-7PSEEE6C.js} +10 -10
- package/dist/chunk-7PSEEE6C.js.map +7 -0
- package/dist/{chunk-M6WGW5VY.js → chunk-DU7JUEDY.js} +48 -6
- package/dist/chunk-DU7JUEDY.js.map +7 -0
- package/dist/{chunk-GSR74KEI.js → chunk-JTZWI4MH.js} +279 -73
- package/dist/chunk-JTZWI4MH.js.map +7 -0
- package/dist/{chunk-WAZTR3DX.js → chunk-KW7KTYGC.js} +2 -2
- package/dist/chunk-KW7KTYGC.js.map +7 -0
- package/dist/chunk-XSNCF7WU.js +1 -1
- package/dist/chunk-XSNCF7WU.js.map +7 -1
- package/dist/cli/build.d.ts +7 -0
- package/dist/cli/cli.d.ts +12 -0
- package/dist/cli/codegen.d.ts +5 -0
- package/dist/cli/create-package.d.ts +14 -0
- package/dist/cli/dev.d.ts +10 -0
- package/dist/cli/gae-deploy.d.ts +18 -0
- package/dist/cli/preview.d.ts +8 -0
- package/dist/cli/start.d.ts +8 -0
- package/dist/cli/startup/check-version.d.ts +17 -0
- package/dist/cli/startup/startup-tasks.d.ts +39 -0
- package/dist/cli.js +4 -4
- package/dist/cli.js.map +7 -1
- package/dist/core/components/Body.d.ts +23 -0
- package/dist/core/components/Head.d.ts +18 -0
- package/dist/core/components/Html.d.ts +24 -0
- package/dist/core/components/Script.d.ts +16 -0
- package/dist/core/config.d.ts +285 -0
- package/dist/core/core.d.ts +14 -0
- package/dist/core/hooks/useI18nContext.d.ts +11 -0
- package/dist/core/hooks/useRequestContext.d.ts +36 -0
- package/dist/core/hooks/useStringParams.d.ts +34 -0
- package/dist/core/hooks/useTranslations.d.ts +20 -0
- package/dist/core/hooks/useTranslationsMiddleware.d.ts +25 -0
- package/dist/core/pages/DevErrorPage.d.ts +9 -0
- package/dist/core/pages/DevNotFoundPage.d.ts +10 -0
- package/dist/core/pages/ErrorPage.d.ts +9 -0
- package/dist/core/plugin.d.ts +80 -0
- package/dist/core/pod.d.ts +54 -0
- package/dist/core/types.d.ts +228 -0
- package/dist/core.js +3 -3
- package/dist/core.js.map +7 -1
- package/dist/functions/functions.d.ts +1 -0
- package/dist/functions/server.d.ts +10 -0
- package/dist/functions.js +5 -5
- package/dist/functions.js.map +7 -1
- package/dist/jsx/jsx-dev-runtime.d.ts +10 -1
- package/dist/jsx/jsx-dev-runtime.js +2 -2
- package/dist/jsx/jsx-dev-runtime.js.map +7 -1
- package/dist/{jsx-C8BaDh-4.d.ts → jsx/jsx-render.d.ts} +3 -6
- package/dist/jsx/jsx-runtime.d.ts +120 -1
- package/dist/jsx/jsx-runtime.js +2 -2
- package/dist/jsx/jsx-runtime.js.map +7 -1
- package/dist/jsx/jsx.d.ts +37 -0
- package/dist/{jsx-dev-runtime-DUJrvx5P.d.ts → jsx/types.d.ts} +9 -125
- package/dist/jsx.js +3 -3
- package/dist/jsx.js.map +7 -1
- package/dist/middleware/common.d.ts +22 -0
- package/dist/middleware/hooks.d.ts +8 -0
- package/dist/middleware/middleware.d.ts +3 -0
- package/dist/middleware/multipart.d.ts +11 -0
- package/dist/middleware/redirects.d.ts +10 -0
- package/dist/middleware/session.d.ts +24 -0
- package/dist/middleware.js +2 -2
- package/dist/middleware.js.map +7 -1
- package/dist/node/element-graph.d.ts +51 -0
- package/dist/node/load-config.d.ts +17 -0
- package/dist/node/monorepo.d.ts +14 -0
- package/dist/node/node.d.ts +4 -0
- package/dist/node/pod-collector.d.ts +33 -0
- package/dist/node/pods-vite-plugin.d.ts +6 -0
- package/dist/node/vite-plugin-preact-alias.d.ts +10 -0
- package/dist/node/vite-plugin-prune-empty-chunks.d.ts +27 -0
- package/dist/node/vite-plugin-root-jsx-virtual.d.ts +16 -0
- package/dist/node/vite.d.ts +18 -0
- package/dist/node.js +2 -2
- package/dist/node.js.map +7 -1
- package/dist/render/accept-language.d.ts +8 -0
- package/dist/render/asset-map/asset-map.d.ts +25 -0
- package/dist/render/asset-map/build-asset-map.d.ts +47 -0
- package/dist/render/asset-map/dev-asset-map.d.ts +26 -0
- package/dist/render/countrie-language.d.ts +13 -0
- package/dist/render/html-minify.d.ts +3 -0
- package/dist/render/html-pretty.d.ts +3 -0
- package/dist/render/i18n-fallbacks.d.ts +11 -0
- package/dist/render/render.d.ts +91 -0
- package/dist/render/route-trie.d.ts +44 -0
- package/dist/render/router.d.ts +18 -0
- package/dist/render.js +9 -9
- package/dist/render.js.map +7 -1
- package/dist/utils/batch.d.ts +1 -0
- package/dist/utils/elements.d.ts +12 -0
- package/dist/utils/fsutils.d.ts +24 -0
- package/dist/utils/i18n.d.ts +8 -0
- package/dist/utils/ports.d.ts +8 -0
- package/dist/utils/rand.d.ts +10 -0
- package/dist/utils/url-path-params.d.ts +2 -0
- package/package.json +14 -15
- package/dist/chunk-FQBA5QSG.js.map +0 -1
- package/dist/chunk-GSR74KEI.js.map +0 -1
- package/dist/chunk-JCRXBB26.js.map +0 -1
- package/dist/chunk-M6WGW5VY.js.map +0 -1
- package/dist/chunk-PVBPP5LN.js.map +0 -1
- package/dist/chunk-WAZTR3DX.js.map +0 -1
- package/dist/cli.d.ts +0 -60
- package/dist/core.d.ts +0 -214
- package/dist/functions.d.ts +0 -14
- package/dist/jsx.d.ts +0 -2
- package/dist/middleware.d.ts +0 -43
- package/dist/node.d.ts +0 -91
- package/dist/render.d.ts +0 -8
- package/dist/types-Cksf99CK.d.ts +0 -827
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface StartupTaskContext {
|
|
2
|
+
/** Absolute path to the root project directory. */
|
|
3
|
+
rootDir: string;
|
|
4
|
+
/** Currently installed version of the `@blinkk/root` package. */
|
|
5
|
+
version?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface StartupTask {
|
|
8
|
+
/**
|
|
9
|
+
* Unique id for the task. Used as the persistence key for the last run time,
|
|
10
|
+
* so it must remain stable across releases.
|
|
11
|
+
*/
|
|
12
|
+
name: string;
|
|
13
|
+
/**
|
|
14
|
+
* Minimum time (in milliseconds) that must elapse between runs. When set, the
|
|
15
|
+
* task is skipped if it last ran more recently than this interval. Omit to
|
|
16
|
+
* run on every startup.
|
|
17
|
+
*/
|
|
18
|
+
throttle?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Optional predicate evaluated before the throttle check. When it returns
|
|
21
|
+
* false the task is skipped entirely (and its throttle is left untouched).
|
|
22
|
+
* Useful for opt-out flags, e.g. an env var that disables the task.
|
|
23
|
+
*/
|
|
24
|
+
enabled?: (ctx: StartupTaskContext) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Task logic. Thrown errors are swallowed by the runner so that a failing
|
|
27
|
+
* startup task never prevents `root` commands from starting.
|
|
28
|
+
*/
|
|
29
|
+
run: (ctx: StartupTaskContext) => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Runs all registered startup tasks, honoring each task's throttle interval.
|
|
33
|
+
*
|
|
34
|
+
* Tasks are best-effort: failures are swallowed and never block startup. The
|
|
35
|
+
* last run time of each task is persisted to the user's home directory so that
|
|
36
|
+
* throttled tasks (e.g. the version check) run at most once per interval across
|
|
37
|
+
* separate `root` invocations.
|
|
38
|
+
*/
|
|
39
|
+
export declare function runStartupTasks(ctx: StartupTaskContext): Promise<void>;
|
package/dist/cli.js
CHANGED
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
dev,
|
|
9
9
|
preview,
|
|
10
10
|
start
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-JTZWI4MH.js";
|
|
12
12
|
import "./chunk-6P3B7ZXL.js";
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
13
|
+
import "./chunk-6NBKAR5Y.js";
|
|
14
|
+
import "./chunk-7PSEEE6C.js";
|
|
15
15
|
import "./chunk-XSNCF7WU.js";
|
|
16
16
|
export {
|
|
17
17
|
CliRunner,
|
|
@@ -24,4 +24,4 @@ export {
|
|
|
24
24
|
preview,
|
|
25
25
|
start
|
|
26
26
|
};
|
|
27
|
-
//# sourceMappingURL=cli.js.map
|
|
27
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ComponentChildren, FunctionalComponent } from 'preact';
|
|
2
|
+
export type BodyProps = preact.JSX.HTMLAttributes<HTMLBodyElement> & {
|
|
3
|
+
children?: ComponentChildren;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* The `<Body>` component can be used to update attrs in the `<body>` tag.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
*
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <Body className="body">
|
|
12
|
+
* <h1>Hello world</h1>
|
|
13
|
+
* </Body>
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Output:
|
|
17
|
+
*
|
|
18
|
+
* ```html
|
|
19
|
+
* <body class="body">
|
|
20
|
+
* <h1>Hello world</h1>
|
|
21
|
+
* </body>
|
|
22
|
+
*/
|
|
23
|
+
export declare const Body: FunctionalComponent<BodyProps>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ComponentChildren, FunctionalComponent } from 'preact';
|
|
2
|
+
export type HeadProps = preact.JSX.HTMLAttributes<HTMLHeadElement> & {
|
|
3
|
+
children?: ComponentChildren;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* The <Head> component can be used for injecting elements into the HTML head
|
|
7
|
+
* tag from any part of a page. The <Head> can be added via any component or
|
|
8
|
+
* sub-component and will automatically be hoisted to the `<head>` element.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <Head>
|
|
14
|
+
* <link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
15
|
+
* </Head>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const Head: FunctionalComponent<HeadProps>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ComponentChildren, FunctionalComponent } from 'preact';
|
|
2
|
+
export interface HtmlContext {
|
|
3
|
+
htmlAttrs: preact.JSX.HTMLAttributes<HTMLHtmlElement>;
|
|
4
|
+
headAttrs: preact.JSX.HTMLAttributes<HTMLHeadElement>;
|
|
5
|
+
headComponents: ComponentChildren[];
|
|
6
|
+
bodyAttrs: preact.JSX.HTMLAttributes<HTMLBodyElement>;
|
|
7
|
+
scriptDeps: Array<preact.JSX.ScriptHTMLAttributes<HTMLScriptElement>>;
|
|
8
|
+
}
|
|
9
|
+
export declare const HTML_CONTEXT: import("preact").Context<HtmlContext | null>;
|
|
10
|
+
export type HtmlProps = preact.JSX.HTMLAttributes<HTMLHtmlElement> & {
|
|
11
|
+
children?: ComponentChildren;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The `<Html>` component can be used to update attrs in the `<html>` tag.
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
*
|
|
18
|
+
* ```tsx
|
|
19
|
+
* <Html lang="en-US">
|
|
20
|
+
* <h1>Hello world</h1>
|
|
21
|
+
* </Html>
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const Html: FunctionalComponent<HtmlProps>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FunctionalComponent } from 'preact';
|
|
2
|
+
export type ScriptProps = preact.JSX.HTMLAttributes<HTMLScriptElement> & {
|
|
3
|
+
src?: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* The <Script> component is used for rendering any custom script modules. At
|
|
7
|
+
* the moment, the system only pre-renders and bundles files that are in the
|
|
8
|
+
* `/bundles` folder at the root of the project.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <Script src="/bundles/main.ts" />
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const Script: FunctionalComponent<ScriptProps>;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { UserConfig as ViteUserConfig } from 'vite';
|
|
2
|
+
import { JsxRenderOptions } from '../jsx/jsx-render.js';
|
|
3
|
+
import { HtmlMinifyOptions } from '../render/html-minify.js';
|
|
4
|
+
import { HtmlPrettyOptions } from '../render/html-pretty.js';
|
|
5
|
+
import { Plugin } from './plugin.js';
|
|
6
|
+
import { PodConfig } from './pod.js';
|
|
7
|
+
import { RequestMiddleware } from './types.js';
|
|
8
|
+
export interface RootUserConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Canonical domain the website will serve on. Useful for things like the
|
|
11
|
+
* sitemap, SEO tags, etc.
|
|
12
|
+
*/
|
|
13
|
+
domain?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The base URL path that the site will serve on. Defaults to `/`;
|
|
16
|
+
*/
|
|
17
|
+
base?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Config for auto-injecting custom element dependencies.
|
|
20
|
+
*/
|
|
21
|
+
elements?: {
|
|
22
|
+
/**
|
|
23
|
+
* A list of directories to use to look for custom elements. The dir path
|
|
24
|
+
* should be relative to the project dir, e.g. "path/to/elements".
|
|
25
|
+
*/
|
|
26
|
+
include?: string[];
|
|
27
|
+
/**
|
|
28
|
+
* A list of RegEx patterns to exclude. The string passed to the RegEx is
|
|
29
|
+
* the file URL relative to the project root, e.g. "/elements/foo/foo.ts".
|
|
30
|
+
*/
|
|
31
|
+
exclude?: RegExp[];
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Config for manually injecting stylesheet entries as
|
|
35
|
+
* `<link rel="stylesheet">` tags.
|
|
36
|
+
*/
|
|
37
|
+
styles?: {
|
|
38
|
+
/**
|
|
39
|
+
* Project-root-relative stylesheet files to include on every rendered
|
|
40
|
+
* page, e.g. `styles/index.css`.
|
|
41
|
+
*
|
|
42
|
+
* Entries are normalized as URL paths, so both `styles/index.css` and
|
|
43
|
+
* `/styles/index.css` resolve to `/styles/index.css`.
|
|
44
|
+
*
|
|
45
|
+
* Manual entries are injected first, then auto-collected CSS
|
|
46
|
+
* dependencies are merged after. Duplicate URLs are de-duped so each
|
|
47
|
+
* stylesheet is only injected once.
|
|
48
|
+
*/
|
|
49
|
+
entries?: string[];
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Config options for localization and internationalization.
|
|
53
|
+
*/
|
|
54
|
+
i18n?: RootI18nConfig;
|
|
55
|
+
/**
|
|
56
|
+
* Config options for the Root.js express server.
|
|
57
|
+
*/
|
|
58
|
+
server?: RootServerConfig;
|
|
59
|
+
/**
|
|
60
|
+
* Build options for the `root build` command.
|
|
61
|
+
*/
|
|
62
|
+
build?: RootBuildConfig;
|
|
63
|
+
/**
|
|
64
|
+
* Vite config.
|
|
65
|
+
* @see {@link https://vitejs.dev/config/} for more information.
|
|
66
|
+
*/
|
|
67
|
+
vite?: ViteUserConfig;
|
|
68
|
+
/**
|
|
69
|
+
* Config for the built-in JSX-to-HTML renderer.
|
|
70
|
+
*
|
|
71
|
+
* - `mode: 'pretty'` (default) — block-level elements render on their own
|
|
72
|
+
* line with no indentation.
|
|
73
|
+
* - `mode: 'minimal'` — compact output with no extra whitespace.
|
|
74
|
+
*
|
|
75
|
+
* Use `blockElements` to specify additional custom element tag names that
|
|
76
|
+
* should be treated as block-level in pretty mode.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* export default defineConfig({
|
|
81
|
+
* jsxRenderer: {
|
|
82
|
+
* mode: 'pretty',
|
|
83
|
+
* blockElements: ['my-card', 'my-section'],
|
|
84
|
+
* },
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
jsxRenderer?: JsxRenderOptions;
|
|
89
|
+
/**
|
|
90
|
+
* Whether to automatically minify HTML output. This is enabled by default,
|
|
91
|
+
* in order to disable, pass `minifyHtml: false` to root.config.ts.
|
|
92
|
+
*/
|
|
93
|
+
minifyHtml?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Options to pass to html-minifier-terser.
|
|
96
|
+
*/
|
|
97
|
+
minifyHtmlOptions?: HtmlMinifyOptions;
|
|
98
|
+
/**
|
|
99
|
+
* Whether to pretty print HTML output.
|
|
100
|
+
*/
|
|
101
|
+
prettyHtml?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Options to pass to js-beautify.
|
|
104
|
+
*/
|
|
105
|
+
prettyHtmlOptions?: HtmlPrettyOptions;
|
|
106
|
+
/**
|
|
107
|
+
* Whether to include a sitemap.xml file to the build output.
|
|
108
|
+
*/
|
|
109
|
+
sitemap?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Plugins.
|
|
112
|
+
*/
|
|
113
|
+
plugins?: Plugin[];
|
|
114
|
+
/**
|
|
115
|
+
* Per-pod user-level overrides. The key is the pod name as declared in
|
|
116
|
+
* Pod.name.
|
|
117
|
+
*/
|
|
118
|
+
pods?: Record<string, PodConfig>;
|
|
119
|
+
/**
|
|
120
|
+
* Experimental config options. Note: these are subject to change at any time.
|
|
121
|
+
*/
|
|
122
|
+
experiments?: {
|
|
123
|
+
/** Whether to render `<script>` tags with `async`. */
|
|
124
|
+
enableScriptAsync?: boolean;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export type RootConfig = RootUserConfig & {
|
|
128
|
+
rootDir: string;
|
|
129
|
+
};
|
|
130
|
+
export interface LocaleGroup {
|
|
131
|
+
label?: string;
|
|
132
|
+
locales: string[];
|
|
133
|
+
}
|
|
134
|
+
export interface RootI18nConfig {
|
|
135
|
+
/**
|
|
136
|
+
* Locales enabled for the site.
|
|
137
|
+
*/
|
|
138
|
+
locales?: string[];
|
|
139
|
+
/**
|
|
140
|
+
* The default locale to use. Defaults is `en`.
|
|
141
|
+
*/
|
|
142
|
+
defaultLocale?: string;
|
|
143
|
+
/**
|
|
144
|
+
* URL format for localized content. Default is `/[locale]/[base]/[path]`.
|
|
145
|
+
*/
|
|
146
|
+
urlFormat?: string;
|
|
147
|
+
/**
|
|
148
|
+
* Localization groups, to help UIs (like Root.js CMS) logically group
|
|
149
|
+
* locales.
|
|
150
|
+
*/
|
|
151
|
+
groups?: Record<string, LocaleGroup>;
|
|
152
|
+
}
|
|
153
|
+
export interface RootBuildConfig {
|
|
154
|
+
/**
|
|
155
|
+
* Excludes the `/intl/{defaultLocale}/...` path from the SSG build.
|
|
156
|
+
*/
|
|
157
|
+
excludeDefaultLocaleFromIntlPaths?: boolean;
|
|
158
|
+
}
|
|
159
|
+
export interface RootRedirectConfig {
|
|
160
|
+
/**
|
|
161
|
+
* The source path to redirect. Accepts placeholders in the format
|
|
162
|
+
* `[key]` or `[...key]`. Use `[key]` for single segments and
|
|
163
|
+
* `[...key]` for multi-segment wildcards.
|
|
164
|
+
* @example "/old-path/[id]" or "/old-path/[...wildcard]"
|
|
165
|
+
*/
|
|
166
|
+
source: string;
|
|
167
|
+
/**
|
|
168
|
+
* The destination to redirect to. Placeholders from the source can
|
|
169
|
+
* optionally be inserted into the destination using the same
|
|
170
|
+
* placeholder format.
|
|
171
|
+
* @example "/new-path/[id]" or "/new-path/[...wildcard]"
|
|
172
|
+
*/
|
|
173
|
+
destination: string;
|
|
174
|
+
/**
|
|
175
|
+
* The redirect type (`301` = permanent, `302` = temporary). If unspecified,
|
|
176
|
+
* defaults to `302` (temporary).
|
|
177
|
+
*/
|
|
178
|
+
type?: 301 | 302;
|
|
179
|
+
}
|
|
180
|
+
export interface RootHeaderConfig {
|
|
181
|
+
/** A glob pattern match (regex not supported yet). */
|
|
182
|
+
source: string;
|
|
183
|
+
headers: Array<{
|
|
184
|
+
key: string;
|
|
185
|
+
value: string;
|
|
186
|
+
}>;
|
|
187
|
+
}
|
|
188
|
+
export interface ContentSecurityPolicyConfig {
|
|
189
|
+
directives?: Record<string, string[]>;
|
|
190
|
+
reportOnly?: boolean;
|
|
191
|
+
}
|
|
192
|
+
export interface XFrameOptionsConfig {
|
|
193
|
+
action: 'DENY' | 'SAMEORIGIN';
|
|
194
|
+
}
|
|
195
|
+
export interface RootSecurityConfig {
|
|
196
|
+
/**
|
|
197
|
+
* Content-Security-Policy config. If enabled, a nonce is auto-generated
|
|
198
|
+
* for every request and appended to script and stylesheet tags. You can
|
|
199
|
+
* validate your CSP headers using a tool like {@link https://csp-evaluator.withgoogle.com/}.
|
|
200
|
+
*
|
|
201
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP}
|
|
202
|
+
*/
|
|
203
|
+
contentSecurityPolicy?: ContentSecurityPolicyConfig | boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Strict-Transport-Security config. When enabled, the header value is set
|
|
206
|
+
* to `Strict-Transport-Security: max-age=63072000; includeSubDomains; preload`.
|
|
207
|
+
*/
|
|
208
|
+
strictTransportSecurity?: boolean;
|
|
209
|
+
/**
|
|
210
|
+
* X-Content-Type-Options config. When enabled, the header value is set to
|
|
211
|
+
* `X-Content-Type-Options: nosniff`.
|
|
212
|
+
*/
|
|
213
|
+
xContentTypeOptions?: boolean;
|
|
214
|
+
/**
|
|
215
|
+
* X-Frame-Options config. Setting this value to `true` will default the
|
|
216
|
+
* header value to `X-Frame-Options: SAMEORIGIN`.
|
|
217
|
+
*
|
|
218
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options}
|
|
219
|
+
*/
|
|
220
|
+
xFrameOptions?: 'DENY' | 'SAMEORIGIN' | boolean;
|
|
221
|
+
/**
|
|
222
|
+
* X-XSS-Protection config. When enabled, the header value is set to
|
|
223
|
+
* `X-XSS-Protection: 1; mode=block`.
|
|
224
|
+
*/
|
|
225
|
+
xXssProtection?: boolean;
|
|
226
|
+
}
|
|
227
|
+
export interface RootServerConfig {
|
|
228
|
+
/**
|
|
229
|
+
* An array of middleware to add to the express server. These middleware are
|
|
230
|
+
* added to the beginning of the express app.
|
|
231
|
+
*/
|
|
232
|
+
middlewares?: RequestMiddleware[];
|
|
233
|
+
/**
|
|
234
|
+
* The `trailingSlash` config allows you to control how the server handles
|
|
235
|
+
* trailing slashes. This config only affects URLs that do not have a file
|
|
236
|
+
* extension (i.e. HTML paths).
|
|
237
|
+
*
|
|
238
|
+
* - When `true`, the server redirects URLs to add a trailing slash
|
|
239
|
+
* - When `false`, the server redirects URLs to remove a trailing slash
|
|
240
|
+
* - When unspecified, the server allows URLs with and without trailing slash
|
|
241
|
+
*/
|
|
242
|
+
trailingSlash?: boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Cookie secret for the session middleware.
|
|
245
|
+
*
|
|
246
|
+
* Generate a secure secret with:
|
|
247
|
+
* ```
|
|
248
|
+
* node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
sessionCookieSecret?: string | string[];
|
|
252
|
+
/**
|
|
253
|
+
* List of redirects. Supports optional wildcards.
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* redirects: [
|
|
258
|
+
* {
|
|
259
|
+
* source: '/old-path/[id]',
|
|
260
|
+
* destination: '/new-path/[id]',
|
|
261
|
+
* type: 301,
|
|
262
|
+
* },
|
|
263
|
+
* {
|
|
264
|
+
* source: '/old-path/[...wildcard]',
|
|
265
|
+
* destination: '/new-path/[...wildcard]',
|
|
266
|
+
* },
|
|
267
|
+
* ]
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
redirects?: RootRedirectConfig[];
|
|
271
|
+
/**
|
|
272
|
+
* HTTP headers to add to a response.
|
|
273
|
+
*/
|
|
274
|
+
headers?: RootHeaderConfig[];
|
|
275
|
+
/**
|
|
276
|
+
* HTTP security settings. By default, all security settings are enabled with
|
|
277
|
+
* commonly used default values.
|
|
278
|
+
*/
|
|
279
|
+
security?: RootSecurityConfig;
|
|
280
|
+
/**
|
|
281
|
+
* Home page URL path, which is printed when the dev server starts.
|
|
282
|
+
*/
|
|
283
|
+
homePagePath?: string;
|
|
284
|
+
}
|
|
285
|
+
export declare function defineConfig(config: RootUserConfig): RootUserConfig;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './config.js';
|
|
2
|
+
export { Body } from './components/Body.js';
|
|
3
|
+
export { Head } from './components/Head.js';
|
|
4
|
+
export { Html, HTML_CONTEXT } from './components/Html.js';
|
|
5
|
+
export { Script } from './components/Script.js';
|
|
6
|
+
export { StringParamsContext, StringParamsProvider, useStringParams, } from './hooks/useStringParams.js';
|
|
7
|
+
export { TranslationMiddlewareProvider, useTranslationMiddleware, } from './hooks/useTranslationsMiddleware.js';
|
|
8
|
+
export { I18nContext, useI18nContext, getTranslations, } from './hooks/useI18nContext.js';
|
|
9
|
+
export { RequestContext, useRequestContext } from './hooks/useRequestContext.js';
|
|
10
|
+
export { useTranslations } from './hooks/useTranslations.js';
|
|
11
|
+
export * from './pod.js';
|
|
12
|
+
export * from './plugin.js';
|
|
13
|
+
export * from './types.js';
|
|
14
|
+
export * from '../utils/url-path-params.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const I18N_CONTEXT: import("preact").Context<I18nContext | null>;
|
|
2
|
+
export interface I18nContext {
|
|
3
|
+
locale: string;
|
|
4
|
+
translations: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A hook that returns information about the current i18n context, including the
|
|
8
|
+
* locale for the given route and a map of translations for that locale.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useI18nContext(): I18nContext;
|
|
11
|
+
export declare function getTranslations(locale: string): Record<string, string>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Route } from '../types.js';
|
|
2
|
+
export interface RequestContext {
|
|
3
|
+
/**
|
|
4
|
+
* The current request path, e.g. `/foo/bar` (default route path) or
|
|
5
|
+
* `/{locale}/foo/bar` (localized route path).
|
|
6
|
+
*/
|
|
7
|
+
currentPath: string;
|
|
8
|
+
/** The route file. */
|
|
9
|
+
route: Route;
|
|
10
|
+
/**
|
|
11
|
+
* Route param values. E.g. for a route like `routes/blog/[slug].tsx`,
|
|
12
|
+
* visiting `/blog/foo` will pass {slug: 'foo'} here.
|
|
13
|
+
*/
|
|
14
|
+
routeParams: Record<string, string>;
|
|
15
|
+
/** Props passed to the route's server component. */
|
|
16
|
+
props: any;
|
|
17
|
+
/** The current locale. */
|
|
18
|
+
locale: string;
|
|
19
|
+
/** Translations map for the current locale. */
|
|
20
|
+
translations: Record<string, string>;
|
|
21
|
+
/** CSP nonce value. */
|
|
22
|
+
nonce?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare const REQUEST_CONTEXT: import("preact").Context<RequestContext | null>;
|
|
25
|
+
/**
|
|
26
|
+
* A hook that returns information about the current route.
|
|
27
|
+
*
|
|
28
|
+
* Usage:
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* const ctx = useRequestContext();
|
|
32
|
+
* ctx.route.src;
|
|
33
|
+
* // => 'routes/index.tsx'
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function useRequestContext(): RequestContext;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ComponentChildren, FunctionalComponent } from 'preact';
|
|
2
|
+
export type StringParamsContext = Record<string, string>;
|
|
3
|
+
export declare const STRING_PARAMS_CONTEXT: import("preact").Context<StringParamsContext | null>;
|
|
4
|
+
export interface StringParamsProviderProps {
|
|
5
|
+
value?: StringParamsContext;
|
|
6
|
+
children?: ComponentChildren;
|
|
7
|
+
}
|
|
8
|
+
export declare const StringParamsProvider: FunctionalComponent<StringParamsProviderProps>;
|
|
9
|
+
/**
|
|
10
|
+
* A hook that returns a map of string params, configured via the
|
|
11
|
+
* `StringParamsProvider` context provider. These params are automatically
|
|
12
|
+
* applied to the `useTranslations()` hook.
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* export default function Page() {
|
|
19
|
+
* return (
|
|
20
|
+
* <StringParamsProvider value={{name: 'Alice'}}>
|
|
21
|
+
* <SayHello />
|
|
22
|
+
* </StringParamsProvider>
|
|
23
|
+
* );
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* function SayHello() {
|
|
27
|
+
* const t = useTranslations();
|
|
28
|
+
* return <h1>{t('Hello, {name}!')}</h1>;
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* This should render `<h1>Hello, Alice!</h1>`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function useStringParams(): StringParamsContext;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A hook that returns a function that can be used to translate a string, and
|
|
3
|
+
* optionally replace any parameterized values that are surrounded in curly
|
|
4
|
+
* braces.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const t = useTranslations();
|
|
10
|
+
* t('Hello {name}', {name: 'Bob'});
|
|
11
|
+
* // => 'Bounjour Bob'
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function useTranslations(): (str: string, params?: Record<string, string | number>) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Cleans a string that's used for translations. Performs the following:
|
|
17
|
+
* - Removes any leading/trailing whitespace
|
|
18
|
+
* - Removes spaces at the end of any line
|
|
19
|
+
*/
|
|
20
|
+
export declare function normalizeString(str: string): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ComponentChildren, FunctionalComponent } from 'preact';
|
|
2
|
+
type TransformFn = (str: string) => string;
|
|
3
|
+
export interface TranslationMiddleware {
|
|
4
|
+
/** Transform the string before translation lookup. */
|
|
5
|
+
beforeTranslate?: TransformFn;
|
|
6
|
+
/** Transform the string after translation lookup. */
|
|
7
|
+
afterTranslate?: TransformFn;
|
|
8
|
+
/** Transform the string before `{param}` values are replaced. */
|
|
9
|
+
beforeReplaceParams?: TransformFn;
|
|
10
|
+
/** Transform the string after `{param}` values are replaced. */
|
|
11
|
+
afterReplaceParams?: TransformFn;
|
|
12
|
+
}
|
|
13
|
+
export interface TranslationMiddlewareContext {
|
|
14
|
+
beforeTranslateFns: TransformFn[];
|
|
15
|
+
afterTranslateFns: TransformFn[];
|
|
16
|
+
beforeReplaceParamsFns: TransformFn[];
|
|
17
|
+
afterReplaceParamsFns: TransformFn[];
|
|
18
|
+
}
|
|
19
|
+
export interface TranslationMiddlewareProviderProps {
|
|
20
|
+
value?: TranslationMiddleware;
|
|
21
|
+
children?: ComponentChildren;
|
|
22
|
+
}
|
|
23
|
+
export declare const TranslationMiddlewareProvider: FunctionalComponent<TranslationMiddlewareProviderProps>;
|
|
24
|
+
export declare function useTranslationMiddleware(): TranslationMiddlewareContext;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Request, Route, RouteParams } from '../types.js';
|
|
2
|
+
interface DevErrorPageProps {
|
|
3
|
+
req: Request;
|
|
4
|
+
route?: Route;
|
|
5
|
+
routeParams?: RouteParams;
|
|
6
|
+
error: any;
|
|
7
|
+
}
|
|
8
|
+
export declare function DevErrorPage(props: DevErrorPageProps): import("preact").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Request, Route } from '../types.js';
|
|
2
|
+
interface DevNotFoundPageProps {
|
|
3
|
+
req: Request;
|
|
4
|
+
sitemap: Record<string, {
|
|
5
|
+
route: Route;
|
|
6
|
+
params: Record<string, string>;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
9
|
+
export declare function DevNotFoundPage(props: DevNotFoundPageProps): import("preact").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ComponentChildren } from 'preact';
|
|
2
|
+
export interface ErrorPageProps {
|
|
3
|
+
code: number;
|
|
4
|
+
title?: string;
|
|
5
|
+
message?: string;
|
|
6
|
+
children?: ComponentChildren;
|
|
7
|
+
align?: 'center';
|
|
8
|
+
}
|
|
9
|
+
export declare function ErrorPage(props: ErrorPageProps): import("preact").JSX.Element;
|