evikit 2.3.2 → 2.4.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/README.md +19 -0
- package/index.d.ts +153 -134
- package/index.js +211 -243
- package/package.json +1 -1
- package/server.js +498 -487
- package/html.js +0 -49
package/index.js
CHANGED
|
@@ -1,243 +1,211 @@
|
|
|
1
|
-
import { toStatic } from "hoofd/preact";
|
|
2
|
-
import { h } from "preact";
|
|
3
|
-
import {
|
|
4
|
-
ErrorBoundary,
|
|
5
|
-
hydrate as iso,
|
|
6
|
-
Router as IsoRouter,
|
|
7
|
-
LocationProvider,
|
|
8
|
-
prerender,
|
|
9
|
-
} from "preact-iso";
|
|
10
|
-
import { locationStub } from "preact-iso/prerender";
|
|
11
|
-
import { useState } from "preact/hooks";
|
|
12
|
-
|
|
13
|
-
import { flatten, primary, references, relations } from "./db.js";
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
export
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
export
|
|
192
|
-
|
|
193
|
-
export
|
|
194
|
-
|
|
195
|
-
export
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
form,
|
|
213
|
-
h1,
|
|
214
|
-
h2,
|
|
215
|
-
h3,
|
|
216
|
-
h4,
|
|
217
|
-
h5,
|
|
218
|
-
h6,
|
|
219
|
-
header,
|
|
220
|
-
hr,
|
|
221
|
-
i,
|
|
222
|
-
img,
|
|
223
|
-
input,
|
|
224
|
-
label,
|
|
225
|
-
legend,
|
|
226
|
-
li,
|
|
227
|
-
main,
|
|
228
|
-
nav,
|
|
229
|
-
ol,
|
|
230
|
-
option,
|
|
231
|
-
p,
|
|
232
|
-
path,
|
|
233
|
-
pre,
|
|
234
|
-
section,
|
|
235
|
-
select,
|
|
236
|
-
small,
|
|
237
|
-
span,
|
|
238
|
-
strong,
|
|
239
|
-
summary,
|
|
240
|
-
svg,
|
|
241
|
-
title,
|
|
242
|
-
ul,
|
|
243
|
-
};
|
|
1
|
+
import { toStatic } from "hoofd/preact";
|
|
2
|
+
import { h } from "preact";
|
|
3
|
+
import {
|
|
4
|
+
ErrorBoundary,
|
|
5
|
+
hydrate as iso,
|
|
6
|
+
Router as IsoRouter,
|
|
7
|
+
LocationProvider,
|
|
8
|
+
prerender,
|
|
9
|
+
} from "preact-iso";
|
|
10
|
+
import { locationStub } from "preact-iso/prerender";
|
|
11
|
+
import { useState } from "preact/hooks";
|
|
12
|
+
|
|
13
|
+
import { flatten, primary, references, relations } from "./db.js";
|
|
14
|
+
import { HTMLElement } from "./html-element.js";
|
|
15
|
+
import { getI18n, Po, RawI18nProvider, useI18n } from "./i18n.js";
|
|
16
|
+
import {
|
|
17
|
+
dehydrate,
|
|
18
|
+
Hydrate,
|
|
19
|
+
QueryClient,
|
|
20
|
+
QueryClientProvider,
|
|
21
|
+
useQueryClient,
|
|
22
|
+
} from "./query.js";
|
|
23
|
+
import { queryApi, useApi } from "./use-api.js";
|
|
24
|
+
import { useEnhance } from "./use-enhance.js";
|
|
25
|
+
import { useStatus } from "./use-status.js";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {(props: { dehydratedState?: ReturnType<import("./query.js").dehydrate> | undefined, i18n: ReturnType<import("./i18n.js").useI18n> } ) => import("preact").VNode} App
|
|
29
|
+
* @param {string} renderTarget
|
|
30
|
+
*/
|
|
31
|
+
export async function hydrate(App, renderTarget) {
|
|
32
|
+
if (typeof window !== "undefined") {
|
|
33
|
+
const app = document.querySelector(renderTarget);
|
|
34
|
+
if (!app) {
|
|
35
|
+
throw new Error(`${renderTarget} not found`);
|
|
36
|
+
}
|
|
37
|
+
let data;
|
|
38
|
+
const prerender = document.querySelector("#preact-prerender-data");
|
|
39
|
+
if (prerender) {
|
|
40
|
+
data = JSON.parse(prerender.textContent);
|
|
41
|
+
prerender.remove();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// If api and hydrate run in the same process, keep value from api.
|
|
45
|
+
// Avoid infinite recursion.
|
|
46
|
+
if (!Po.value) {
|
|
47
|
+
Po.set(
|
|
48
|
+
async (lang) =>
|
|
49
|
+
await (
|
|
50
|
+
await fetch(`${location.origin}/po/${encodeURIComponent(lang)}`)
|
|
51
|
+
).json(),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
iso(
|
|
56
|
+
h(App, {
|
|
57
|
+
dehydratedState: data?.dehydratedState,
|
|
58
|
+
// `window` matters. We want JSDOM navigator in tests, not Node.js one.
|
|
59
|
+
i18n: await getI18n(...window.navigator.languages),
|
|
60
|
+
}),
|
|
61
|
+
app,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @param {{ children?: import("preact").ComponentChildren, dehydratedState?: ReturnType<import("./query.js").dehydrate> | undefined, i18n: ReturnType<import("./i18n.js").useI18n> }} props */
|
|
67
|
+
export function Router({ children, dehydratedState, i18n }) {
|
|
68
|
+
const [queryClient] = useState(
|
|
69
|
+
() =>
|
|
70
|
+
new QueryClient({
|
|
71
|
+
defaultOptions: { queries: { staleTime: 60 * 1000 } },
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return h(
|
|
76
|
+
RawI18nProvider,
|
|
77
|
+
{ value: /** @type {any} */ (i18n) },
|
|
78
|
+
h(
|
|
79
|
+
QueryClientProvider,
|
|
80
|
+
{ client: queryClient },
|
|
81
|
+
h(
|
|
82
|
+
Hydrate,
|
|
83
|
+
{ state: dehydratedState },
|
|
84
|
+
h(
|
|
85
|
+
LocationProvider,
|
|
86
|
+
null,
|
|
87
|
+
h(ErrorBoundary, null, h(IsoRouter, null, children)),
|
|
88
|
+
),
|
|
89
|
+
),
|
|
90
|
+
),
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @param {(props: { dehydratedState?: ReturnType<import("./query.js").dehydrate> | undefined, i18n: ReturnType<import("./i18n.js").useI18n> }) => import("preact").VNode} App
|
|
96
|
+
* @param {{ lang?: string, url: string }} data
|
|
97
|
+
*/
|
|
98
|
+
export async function ssr(App, data) {
|
|
99
|
+
const origin = process.env["ORIGIN"] || "http://localhost:5173";
|
|
100
|
+
const i18n = await getI18n(...(data.lang ? [data.lang] : []));
|
|
101
|
+
|
|
102
|
+
const queryClient = new QueryClient({
|
|
103
|
+
defaultOptions: { queries: { staleTime: 0 } },
|
|
104
|
+
});
|
|
105
|
+
await queryClient.prefetchQuery(
|
|
106
|
+
queryApi({ lang: i18n.getLocale(), origin, path: data.url }),
|
|
107
|
+
);
|
|
108
|
+
const dehydratedState = dehydrate(queryClient, {
|
|
109
|
+
shouldRedactErrors: (error) => {
|
|
110
|
+
const { name } = /** @type {any} */ (error);
|
|
111
|
+
return !(Number(name) && name == "404");
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
locationStub(data.url);
|
|
116
|
+
const { html, links } = await prerender(h(/** @type {any} */ (App), {}), {
|
|
117
|
+
props: { dehydratedState, i18n },
|
|
118
|
+
});
|
|
119
|
+
const { metas, title } = toStatic();
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
data: { ...data, dehydratedState },
|
|
123
|
+
head: {
|
|
124
|
+
elements: new Set(
|
|
125
|
+
metas.map((props) => ({
|
|
126
|
+
props: Object.fromEntries(
|
|
127
|
+
Object.entries(props).map(([name, content]) => [
|
|
128
|
+
name,
|
|
129
|
+
String(content),
|
|
130
|
+
]),
|
|
131
|
+
),
|
|
132
|
+
type: "meta",
|
|
133
|
+
})),
|
|
134
|
+
),
|
|
135
|
+
lang: i18n.getLocale(),
|
|
136
|
+
title,
|
|
137
|
+
},
|
|
138
|
+
html,
|
|
139
|
+
links,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export const a = HTMLElement("a");
|
|
144
|
+
export const address = HTMLElement("address");
|
|
145
|
+
export const article = HTMLElement("article");
|
|
146
|
+
export const aside = HTMLElement("aside");
|
|
147
|
+
export const audio = HTMLElement("audio");
|
|
148
|
+
export const b = HTMLElement("b");
|
|
149
|
+
export const blockquote = HTMLElement("blockquote");
|
|
150
|
+
export const br = HTMLElement("br");
|
|
151
|
+
export const button = HTMLElement("button");
|
|
152
|
+
export const canvas = HTMLElement("canvas");
|
|
153
|
+
export const circle = HTMLElement("circle");
|
|
154
|
+
export const code = HTMLElement("code");
|
|
155
|
+
export const del = HTMLElement("del");
|
|
156
|
+
export const details = HTMLElement("details");
|
|
157
|
+
export const dialog = HTMLElement("dialog");
|
|
158
|
+
export const div = HTMLElement("div");
|
|
159
|
+
export const em = HTMLElement("em");
|
|
160
|
+
export const fieldset = HTMLElement("fieldset");
|
|
161
|
+
export const figcaption = HTMLElement("figcaption");
|
|
162
|
+
export const figure = HTMLElement("figure");
|
|
163
|
+
export const footer = HTMLElement("footer");
|
|
164
|
+
export const form = HTMLElement("form");
|
|
165
|
+
export const h1 = HTMLElement("h1");
|
|
166
|
+
export const h2 = HTMLElement("h2");
|
|
167
|
+
export const h3 = HTMLElement("h3");
|
|
168
|
+
export const h4 = HTMLElement("h4");
|
|
169
|
+
export const h5 = HTMLElement("h5");
|
|
170
|
+
export const h6 = HTMLElement("h6");
|
|
171
|
+
export const header = HTMLElement("header");
|
|
172
|
+
export const hgroup = HTMLElement("hgroup");
|
|
173
|
+
export const hr = HTMLElement("hr");
|
|
174
|
+
export const i = HTMLElement("i");
|
|
175
|
+
export const iframe = HTMLElement("iframe");
|
|
176
|
+
export const img = HTMLElement("img");
|
|
177
|
+
export const input = HTMLElement("input");
|
|
178
|
+
export const ins = HTMLElement("ins");
|
|
179
|
+
export const label = HTMLElement("label");
|
|
180
|
+
export const legend = HTMLElement("legend");
|
|
181
|
+
export const li = HTMLElement("li");
|
|
182
|
+
export const main = HTMLElement("main");
|
|
183
|
+
export const nav = HTMLElement("nav");
|
|
184
|
+
export const ol = HTMLElement("ol");
|
|
185
|
+
export const option = HTMLElement("option");
|
|
186
|
+
export const p = HTMLElement("p");
|
|
187
|
+
export const path = HTMLElement("path");
|
|
188
|
+
export const picture = HTMLElement("picture");
|
|
189
|
+
export const pre = HTMLElement("pre");
|
|
190
|
+
export const section = HTMLElement("section");
|
|
191
|
+
export const select = HTMLElement("select");
|
|
192
|
+
export const small = HTMLElement("small");
|
|
193
|
+
export const source = HTMLElement("source");
|
|
194
|
+
export const span = HTMLElement("span");
|
|
195
|
+
export const strong = HTMLElement("strong");
|
|
196
|
+
export const sub = HTMLElement("sub");
|
|
197
|
+
export const summary = HTMLElement("summary");
|
|
198
|
+
export const sup = HTMLElement("sup");
|
|
199
|
+
export const svg = HTMLElement("svg");
|
|
200
|
+
export const table = HTMLElement("table");
|
|
201
|
+
export const tbody = HTMLElement("tbody");
|
|
202
|
+
export const td = HTMLElement("td");
|
|
203
|
+
export const textarea = HTMLElement("textarea");
|
|
204
|
+
export const thead = HTMLElement("thead");
|
|
205
|
+
export const title = HTMLElement("title");
|
|
206
|
+
export const tr = HTMLElement("tr");
|
|
207
|
+
export const ul = HTMLElement("ul");
|
|
208
|
+
export const video = HTMLElement("video");
|
|
209
|
+
|
|
210
|
+
export { flatten, primary, references, relations };
|
|
211
|
+
export { getI18n, useApi, useEnhance, useI18n, useQueryClient, useStatus };
|