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.
Files changed (6) hide show
  1. package/README.md +19 -0
  2. package/index.d.ts +153 -134
  3. package/index.js +211 -243
  4. package/package.json +1 -1
  5. package/server.js +498 -487
  6. package/html.js +0 -49
package/README.md CHANGED
@@ -14,9 +14,26 @@ Vite is a good foundation for building a server-rendered monolith SPA with an JS
14
14
  - Have SEO meta descriptions
15
15
  - Generate API documentation with a Swagger overview
16
16
  - Send multipart not urlencoded when there's a file
17
+ - Distribute requests between listeners for each CPU core
17
18
 
18
19
  _TODO_ Add more simple language docs near code, don't overwhelm readers.
19
20
 
21
+ ## Quick start
22
+
23
+ > 😉 If you are new to Preact and the concept of Virtual DOM, it is a good idea to complete the [Preact tutorial](https://preactjs.com/tutorial/) first.
24
+
25
+ Run the [create-evikit](https://codeberg.org/nykula/create-evikit) initializer to start with a todo app example that you can see on the [EviKit website](https://evikit.js.org/):
26
+
27
+ ```sh
28
+ npm init evikit my-app
29
+ cd my-app
30
+ npm run dev
31
+ ```
32
+
33
+ Then open http://localhost:5173/, try editing the example routes and see changes live.
34
+
35
+ The initializer automates some of the steps from this tutorial, such as installing dependencies, adding scripts to your `package.json`, and creating typical files such as `index.html` and `vite.config.js`.
36
+
20
37
  ## Documentation
21
38
 
22
39
  Let's see how to build a basic poll application using this framework. The application will be a site that lets people view polls, suggest their options and vote.
@@ -847,6 +864,8 @@ form(
847
864
 
848
865
  For the Ukrainian language, which has the `uk` [two-letter language code](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes), create an empty file `po/uk.po`. It will use the [gettext](https://www.gnu.org/software/gettext/) format, which is well-known to professional translators.
849
866
 
867
+ Install the `gettext` package from your distribution repositories or from [here for Windows](https://mlocati.github.io/articles/gettext-iconv-windows.html).
868
+
850
869
  Extract translatable strings from code:
851
870
 
852
871
  ```sh
package/index.d.ts CHANGED
@@ -1,134 +1,153 @@
1
- import type { ClassAttributes, ComponentChildren, JSX, VNode } from "preact";
2
-
3
- import i18n from "gettext.js";
4
-
5
- import { flatten, primary, references, relations } from "./db.js";
6
- import { useApi } from "./use-api.js";
7
- import { useEnhance } from "./use-enhance.js";
8
-
9
- export interface DehydratedState {
10
- queries: { queryHash: string; state: QueryState }[];
11
- }
12
-
13
- export interface QueryState {
14
- data: any; // eslint-disable-line @typescript-eslint/no-explicit-any
15
- dataUpdatedAt: number;
16
- error: null | unknown;
17
- isInvalidated: boolean;
18
- status: "error" | "loading" | "success";
19
- }
20
-
21
- type H<T extends keyof JSX.IntrinsicElements> = (
22
- props: (ClassAttributes<HTMLElement> & JSX.IntrinsicElements[T]) | null,
23
- ...children: ComponentChildren[]
24
- ) => VNode<ClassAttributes<HTMLElement> & JSX.IntrinsicElements[T]>;
25
-
26
- export function dehydrate(
27
- queryClient: ReturnType<typeof useQueryClient>,
28
- options: {
29
- shouldRedactErrors: (error: unknown) => boolean;
30
- },
31
- ): DehydratedState;
32
-
33
- export function getI18n(...langs: string[]): Promise<i18n.Gettext>;
34
-
35
- export function hydrate(
36
- App: (props: {
37
- dehydratedState?: DehydratedState | undefined;
38
- i18n: i18n.Gettext;
39
- }) => VNode<any>, // eslint-disable-line @typescript-eslint/no-explicit-any
40
- renderTarget: string,
41
- ): Promise<void>;
42
-
43
- export function Router({
44
- children,
45
- dehydratedState,
46
- i18n,
47
- }: {
48
- children?: ComponentChildren;
49
- dehydratedState?: DehydratedState | undefined;
50
- i18n: i18n.Gettext;
51
- }): VNode<any>; // eslint-disable-line @typescript-eslint/no-explicit-any
52
-
53
- export function ssr(
54
- App: (props: {
55
- dehydratedState?: DehydratedState | undefined;
56
- i18n: i18n.Gettext;
57
- }) => VNode<any>, // eslint-disable-line @typescript-eslint/no-explicit-any
58
- data: { lang?: string; url: string },
59
- ): Promise<{
60
- data: {
61
- dehydratedState: DehydratedState;
62
- lang?: string;
63
- url: string;
64
- };
65
- head: {
66
- elements: Set<{
67
- props: Record<string, string>;
68
- type: string;
69
- }>;
70
- lang: string;
71
- title: string;
72
- };
73
- html: string;
74
- links: Set<string> | undefined;
75
- }>;
76
-
77
- export function useI18n(): i18n.Gettext;
78
-
79
- export function useQueryClient(): {
80
- invalidateQueries(): void;
81
- };
82
-
83
- export function useStatus(error: unknown): string;
84
-
85
- export const a: H<"a">;
86
- export const article: H<"article">;
87
- export const b: H<"b">;
88
- export const blockquote: H<"blockquote">;
89
- export const br: H<"br">;
90
- export const button: H<"button">;
91
- export const circle: H<"circle">;
92
- export const code: H<"code">;
93
- export const details: H<"details">;
94
- export const dialog: H<"dialog">;
95
- export const div: H<"div">;
96
- export const em: H<"em">;
97
- export const fieldset: H<"fieldset">;
98
- export const figcaption: H<"figcaption">;
99
- export const figure: H<"figure">;
100
- export const footer: H<"footer">;
101
- export const form: H<"form">;
102
- export const h1: H<"h1">;
103
- export const h2: H<"h2">;
104
- export const h3: H<"h3">;
105
- export const h4: H<"h4">;
106
- export const h5: H<"h5">;
107
- export const h6: H<"h6">;
108
- export const header: H<"header">;
109
- export const hr: H<"hr">;
110
- export const i: H<"i">;
111
- export const img: H<"img">;
112
- export const input: H<"input">;
113
- export const label: H<"label">;
114
- export const legend: H<"legend">;
115
- export const li: H<"li">;
116
- export const main: H<"main">;
117
- export const nav: H<"nav">;
118
- export const ol: H<"ol">;
119
- export const option: H<"option">;
120
- export const p: H<"p">;
121
- export const path: H<"path">;
122
- export const pre: H<"pre">;
123
- export const section: H<"section">;
124
- export const select: H<"select">;
125
- export const small: H<"small">;
126
- export const span: H<"span">;
127
- export const strong: H<"strong">;
128
- export const summary: H<"summary">;
129
- export const svg: H<"svg">;
130
- export const title: H<"title">;
131
- export const ul: H<"ul">;
132
-
133
- export { flatten, primary, references, relations };
134
- export { useApi, useEnhance };
1
+ import type { ClassAttributes, ComponentChildren, JSX, VNode } from "preact";
2
+
3
+ import i18n from "gettext.js";
4
+
5
+ import { flatten, primary, references, relations } from "./db.js";
6
+ import { useApi } from "./use-api.js";
7
+ import { useEnhance } from "./use-enhance.js";
8
+
9
+ export interface DehydratedState {
10
+ queries: { queryHash: string; state: QueryState }[];
11
+ }
12
+
13
+ export interface QueryState {
14
+ data: any; // eslint-disable-line @typescript-eslint/no-explicit-any
15
+ dataUpdatedAt: number;
16
+ error: null | unknown;
17
+ isInvalidated: boolean;
18
+ status: "error" | "loading" | "success";
19
+ }
20
+
21
+ type H<T extends keyof JSX.IntrinsicElements> = (
22
+ props: (ClassAttributes<HTMLElement> & JSX.IntrinsicElements[T]) | null,
23
+ ...children: ComponentChildren[]
24
+ ) => VNode<ClassAttributes<HTMLElement> & JSX.IntrinsicElements[T]>;
25
+
26
+ export function dehydrate(
27
+ queryClient: ReturnType<typeof useQueryClient>,
28
+ options: {
29
+ shouldRedactErrors: (error: unknown) => boolean;
30
+ },
31
+ ): DehydratedState;
32
+
33
+ export function getI18n(...langs: string[]): Promise<i18n.Gettext>;
34
+
35
+ export function hydrate(
36
+ App: (props: {
37
+ dehydratedState?: DehydratedState | undefined;
38
+ i18n: i18n.Gettext;
39
+ }) => VNode<any>, // eslint-disable-line @typescript-eslint/no-explicit-any
40
+ renderTarget: string,
41
+ ): Promise<void>;
42
+
43
+ export function Router({
44
+ children,
45
+ dehydratedState,
46
+ i18n,
47
+ }: {
48
+ children?: ComponentChildren;
49
+ dehydratedState?: DehydratedState | undefined;
50
+ i18n: i18n.Gettext;
51
+ }): VNode<any>; // eslint-disable-line @typescript-eslint/no-explicit-any
52
+
53
+ export function ssr(
54
+ App: (props: {
55
+ dehydratedState?: DehydratedState | undefined;
56
+ i18n: i18n.Gettext;
57
+ }) => VNode<any>, // eslint-disable-line @typescript-eslint/no-explicit-any
58
+ data: { lang?: string; url: string },
59
+ ): Promise<{
60
+ data: {
61
+ dehydratedState: DehydratedState;
62
+ lang?: string;
63
+ url: string;
64
+ };
65
+ head: {
66
+ elements: Set<{
67
+ props: Record<string, string>;
68
+ type: string;
69
+ }>;
70
+ lang: string;
71
+ title: string;
72
+ };
73
+ html: string;
74
+ links: Set<string> | undefined;
75
+ }>;
76
+
77
+ export function useI18n(): i18n.Gettext;
78
+
79
+ export function useQueryClient(): {
80
+ invalidateQueries(): void;
81
+ };
82
+
83
+ export function useStatus(error: unknown): string;
84
+
85
+ export const a: H<"a">;
86
+ export const address: H<"address">;
87
+ export const article: H<"article">;
88
+ export const aside: H<"aside">;
89
+ export const audio: H<"audio">;
90
+ export const b: H<"b">;
91
+ export const blockquote: H<"blockquote">;
92
+ export const br: H<"br">;
93
+ export const button: H<"button">;
94
+ export const canvas: H<"canvas">;
95
+ export const circle: H<"circle">;
96
+ export const code: H<"code">;
97
+ export const del: H<"del">;
98
+ export const details: H<"details">;
99
+ export const dialog: H<"dialog">;
100
+ export const div: H<"div">;
101
+ export const em: H<"em">;
102
+ export const fieldset: H<"fieldset">;
103
+ export const figcaption: H<"figcaption">;
104
+ export const figure: H<"figure">;
105
+ export const footer: H<"footer">;
106
+ export const form: H<"form">;
107
+ export const h1: H<"h1">;
108
+ export const h2: H<"h2">;
109
+ export const h3: H<"h3">;
110
+ export const h4: H<"h4">;
111
+ export const h5: H<"h5">;
112
+ export const h6: H<"h6">;
113
+ export const header: H<"header">;
114
+ export const hgroup: H<"hgroup">;
115
+ export const hr: H<"hr">;
116
+ export const i: H<"i">;
117
+ export const iframe: H<"iframe">;
118
+ export const img: H<"img">;
119
+ export const input: H<"input">;
120
+ export const ins: H<"ins">;
121
+ export const label: H<"label">;
122
+ export const legend: H<"legend">;
123
+ export const li: H<"li">;
124
+ export const main: H<"main">;
125
+ export const nav: H<"nav">;
126
+ export const ol: H<"ol">;
127
+ export const option: H<"option">;
128
+ export const p: H<"p">;
129
+ export const path: H<"path">;
130
+ export const picture: H<"picture">;
131
+ export const pre: H<"pre">;
132
+ export const section: H<"section">;
133
+ export const select: H<"select">;
134
+ export const small: H<"small">;
135
+ export const source: H<"source">;
136
+ export const span: H<"span">;
137
+ export const strong: H<"strong">;
138
+ export const sub: H<"sub">;
139
+ export const summary: H<"summary">;
140
+ export const sup: H<"sup">;
141
+ export const svg: H<"svg">;
142
+ export const table: H<"table">;
143
+ export const tbody: H<"tbody">;
144
+ export const td: H<"td">;
145
+ export const textarea: H<"textarea">;
146
+ export const thead: H<"thead">;
147
+ export const title: H<"title">;
148
+ export const tr: H<"tr">;
149
+ export const ul: H<"ul">;
150
+ export const video: H<"video">;
151
+
152
+ export { flatten, primary, references, relations };
153
+ export { useApi, useEnhance };