ovr 4.0.0 → 4.1.1
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/app/context.d.ts.map +1 -1
- package/dist/app/context.js +2 -1
- package/dist/app/get.d.ts +6 -8
- package/dist/app/get.d.ts.map +1 -1
- package/dist/app/get.js +19 -0
- package/dist/app/post.d.ts +5 -9
- package/dist/app/post.d.ts.map +1 -1
- package/dist/app/post.js +11 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/jsx/chunk/index.js +5 -3
- package/dist/jsx/index.d.ts.map +1 -1
- package/dist/jsx/index.js +36 -28
- package/dist/jsx/merge-async-generators.d.ts +4 -2
- package/dist/jsx/merge-async-generators.d.ts.map +1 -1
- package/dist/jsx/merge-async-generators.js +4 -3
- package/dist/types/index.d.ts +17 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/app/context.ts +3 -1
- package/src/app/get.ts +33 -5
- package/src/app/post.ts +17 -7
- package/src/index.ts +0 -1
- package/src/jsx/chunk/index.ts +5 -5
- package/src/jsx/index.ts +36 -32
- package/src/jsx/merge-async-generators.ts +5 -3
- package/src/types/index.ts +12 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/app/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,GAAG,EAAe,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,MAAM,YAAY,CAAC;AAGpB,KAAK,MAAM,GAAG,CAAC,KAAK,EAAE;IAAE,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAA;CAAE,KAAK,GAAG,CAAC,OAAO,CAAC;AAShE,qBAAa,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,CAAC,EAAE,MAAM;IAkEvC;;;;;;;;OAQG;IACH,IAAI,CAAC,CAAC,EAAE,MAAM;IAed;;OAEG;IACH,KAAK;IA+BL;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,MAAM,CAAC,GAAG;CAUV"}
|
package/dist/app/context.js
CHANGED
|
@@ -170,6 +170,7 @@ export class Context {
|
|
|
170
170
|
// HTML partial - just use the layouts + page
|
|
171
171
|
gen = toGenerator(Page);
|
|
172
172
|
}
|
|
173
|
+
let result;
|
|
173
174
|
this.html(new ReadableStream({
|
|
174
175
|
pull: async (c) => {
|
|
175
176
|
if (this.req.signal.aborted) {
|
|
@@ -177,7 +178,7 @@ export class Context {
|
|
|
177
178
|
gen.return();
|
|
178
179
|
return;
|
|
179
180
|
}
|
|
180
|
-
|
|
181
|
+
result = await gen.next();
|
|
181
182
|
if (result.done)
|
|
182
183
|
c.close();
|
|
183
184
|
else
|
package/dist/app/get.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { type JSX } from "../jsx/index.js";
|
|
2
|
-
import type { ExtractParams } from "../types/index.js";
|
|
3
|
-
import type { Middleware
|
|
4
|
-
type AnchorProps<P extends Params> = JSX.IntrinsicElements["a"] & (keyof P extends never ? {
|
|
5
|
-
params?: never;
|
|
6
|
-
} : {
|
|
7
|
-
params: P;
|
|
8
|
-
});
|
|
2
|
+
import type { AnchorProps, ButtonProps, ExtractParams, FormProps } from "../types/index.js";
|
|
3
|
+
import type { Middleware } from "./index.js";
|
|
9
4
|
export declare class Get<Pattern extends string = string> {
|
|
10
5
|
#private;
|
|
11
6
|
/** Route pattern */
|
|
@@ -14,6 +9,10 @@ export declare class Get<Pattern extends string = string> {
|
|
|
14
9
|
middleware: Middleware<any>[];
|
|
15
10
|
/** `<a>` component with preset `href` attribute. */
|
|
16
11
|
Anchor: (props: AnchorProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
12
|
+
/** `<button>` component with preset `formaction` and `formmethod` attributes. */
|
|
13
|
+
Button: (props: ButtonProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
14
|
+
/** `<form>` component with preset `method` and `action` attributes. */
|
|
15
|
+
Form: (props: FormProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
17
16
|
/**
|
|
18
17
|
* @param pattern Route pattern
|
|
19
18
|
* @param middleware GET middleware
|
|
@@ -36,5 +35,4 @@ export declare class Get<Pattern extends string = string> {
|
|
|
36
35
|
*/
|
|
37
36
|
constructor(pattern: Pattern, ...middleware: Middleware<ExtractParams<Pattern>>[]);
|
|
38
37
|
}
|
|
39
|
-
export {};
|
|
40
38
|
//# sourceMappingURL=get.d.ts.map
|
package/dist/app/get.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../src/app/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAO,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../src/app/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAO,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,EACX,WAAW,EACX,WAAW,EACX,aAAa,EACb,SAAS,EACT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,qBAAa,GAAG,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;;IAC/C,oBAAoB;IACpB,OAAO,EAAE,OAAO,CAAC;IAEjB,qBAAqB;IACrB,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;IAE9B,oDAAoD;IACpD,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC;IAEpE,iFAAiF;IACjF,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC;IAEpE,uEAAuE;IACvE,IAAI,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC;IAIhE;;;;;;;;;;;;;;;;;;;OAmBG;gBAEF,OAAO,EAAE,OAAO,EAChB,GAAG,UAAU,EAAE,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE;CA+BpD"}
|
package/dist/app/get.js
CHANGED
|
@@ -7,6 +7,10 @@ export class Get {
|
|
|
7
7
|
middleware;
|
|
8
8
|
/** `<a>` component with preset `href` attribute. */
|
|
9
9
|
Anchor;
|
|
10
|
+
/** `<button>` component with preset `formaction` and `formmethod` attributes. */
|
|
11
|
+
Button;
|
|
12
|
+
/** `<form>` component with preset `method` and `action` attributes. */
|
|
13
|
+
Form;
|
|
10
14
|
#parts;
|
|
11
15
|
/**
|
|
12
16
|
* @param pattern Route pattern
|
|
@@ -36,5 +40,20 @@ export class Get {
|
|
|
36
40
|
const { params = {}, ...rest } = props;
|
|
37
41
|
return jsx("a", { href: insertParams(this.#parts, params), ...rest });
|
|
38
42
|
};
|
|
43
|
+
this.Button = (props) => {
|
|
44
|
+
const { params = {}, ...rest } = props;
|
|
45
|
+
return jsx("button", {
|
|
46
|
+
formaction: insertParams(this.#parts, params),
|
|
47
|
+
formmethod: "get",
|
|
48
|
+
...rest,
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
this.Form = (props) => {
|
|
52
|
+
const { params = {}, ...rest } = props;
|
|
53
|
+
return jsx("form", {
|
|
54
|
+
action: insertParams(this.#parts, params),
|
|
55
|
+
...rest,
|
|
56
|
+
});
|
|
57
|
+
};
|
|
39
58
|
}
|
|
40
59
|
}
|
package/dist/app/post.d.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { type JSX } from "../jsx/index.js";
|
|
2
|
-
import type { ExtractParams } from "../types/index.js";
|
|
3
|
-
import type { Middleware
|
|
4
|
-
type FormProps<P extends Params> = JSX.IntrinsicElements["form"] & (keyof P extends never ? {
|
|
5
|
-
params?: never;
|
|
6
|
-
} : {
|
|
7
|
-
params: P;
|
|
8
|
-
});
|
|
2
|
+
import type { ButtonProps, ExtractParams, FormProps } from "../types/index.js";
|
|
3
|
+
import type { Middleware } from "./index.js";
|
|
9
4
|
export declare class Post<Pattern extends string = string> {
|
|
10
5
|
#private;
|
|
11
6
|
/** Route pattern */
|
|
12
7
|
pattern: Pattern;
|
|
13
8
|
/** POST middleware */
|
|
14
9
|
middleware: Middleware<any>[];
|
|
10
|
+
/** `<button>` component with preset `formaction` and `formmethod` attributes. */
|
|
11
|
+
Button: (props: ButtonProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
15
12
|
/** `<form>` component with preset `method` and `action` attributes. */
|
|
16
13
|
Form: (props: FormProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
17
14
|
/**
|
|
@@ -29,7 +26,7 @@ export declare class Post<Pattern extends string = string> {
|
|
|
29
26
|
*
|
|
30
27
|
* const page = new Get("/", () => (
|
|
31
28
|
* <post.Form>
|
|
32
|
-
* <input />
|
|
29
|
+
* <input type="text" name="name" />
|
|
33
30
|
* <button>Submit</button>
|
|
34
31
|
* </post.Form>
|
|
35
32
|
* ));
|
|
@@ -44,5 +41,4 @@ export declare class Post<Pattern extends string = string> {
|
|
|
44
41
|
*/
|
|
45
42
|
constructor(pattern: Pattern, ...middleware: Middleware<ExtractParams<Pattern>>[]);
|
|
46
43
|
}
|
|
47
|
-
export {};
|
|
48
44
|
//# sourceMappingURL=post.d.ts.map
|
package/dist/app/post.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post.d.ts","sourceRoot":"","sources":["../../src/app/post.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAO,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"post.d.ts","sourceRoot":"","sources":["../../src/app/post.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAO,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,qBAAa,IAAI,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;;IAChD,oBAAoB;IACpB,OAAO,EAAE,OAAO,CAAC;IAEjB,sBAAsB;IACtB,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;IAE9B,iFAAiF;IACjF,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC;IAEpE,uEAAuE;IACvE,IAAI,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC;IAIhE;;;;;;;;;;;;;;;;;;;;;;OAsBG;gBACS,GAAG,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC,EAAE;IAC3C;;;OAGG;gBAEF,OAAO,EAAE,OAAO,EAChB,GAAG,UAAU,EAAE,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE;CAqCpD"}
|
package/dist/app/post.js
CHANGED
|
@@ -6,6 +6,8 @@ export class Post {
|
|
|
6
6
|
pattern;
|
|
7
7
|
/** POST middleware */
|
|
8
8
|
middleware;
|
|
9
|
+
/** `<button>` component with preset `formaction` and `formmethod` attributes. */
|
|
10
|
+
Button;
|
|
9
11
|
/** `<form>` component with preset `method` and `action` attributes. */
|
|
10
12
|
Form;
|
|
11
13
|
#parts = [];
|
|
@@ -16,9 +18,17 @@ export class Post {
|
|
|
16
18
|
}
|
|
17
19
|
else {
|
|
18
20
|
this.middleware.unshift(patternOrMiddleware);
|
|
19
|
-
this.pattern = `/
|
|
21
|
+
this.pattern = `/_p/${hash(this.middleware.join())}`;
|
|
20
22
|
}
|
|
21
23
|
this.#parts = this.pattern.split("/");
|
|
24
|
+
this.Button = (props) => {
|
|
25
|
+
const { params = {}, ...rest } = props;
|
|
26
|
+
return jsx("button", {
|
|
27
|
+
formaction: insertParams(this.#parts, params),
|
|
28
|
+
formmethod: "post",
|
|
29
|
+
...rest,
|
|
30
|
+
});
|
|
31
|
+
};
|
|
22
32
|
this.Form = (props) => {
|
|
23
33
|
const { params = {}, ...rest } = props;
|
|
24
34
|
return jsx("form", {
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,KAAK,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,KAAK,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/jsx/chunk/index.js
CHANGED
|
@@ -40,12 +40,14 @@ export class Chunk {
|
|
|
40
40
|
// tracks the position of the last successful match in the input string
|
|
41
41
|
let start = 0;
|
|
42
42
|
let result = "";
|
|
43
|
+
// index of the match
|
|
44
|
+
let i;
|
|
45
|
+
let match;
|
|
43
46
|
// since `g` flag is used, regex maintains state with each loop,
|
|
44
47
|
// checking from the lastIndex onward each time
|
|
45
48
|
while (regex.test(s)) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const match = s[i];
|
|
49
|
+
i = regex.lastIndex - 1;
|
|
50
|
+
match = s[i];
|
|
49
51
|
result +=
|
|
50
52
|
// everything that didn't match during this test
|
|
51
53
|
s.slice(start, i) +
|
package/dist/jsx/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jsx/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,KAAK,EAAE,iBAAiB,IAAI,EAAE,EAAE,MAAM,yBAAyB,CAAC;AAIvE,wBAAwB;AACxB,yBAA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,OAAO,GAAG,aAAa,CAClC,YAAY,CACT,MAAM,GACN,MAAM,GACN,MAAM,GACN,OAAO,GACP,MAAM,GACN,IAAI,GACJ,SAAS,GACT,MAAM,GACN,QAAQ,CAAC,OAAO,CAAC,GACjB,aAAa,CAAC,OAAO,CAAC,CACxB,CACD,CAAC;CACF;AAED,+BAA+B;AAC/B,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AAuBhD;;;;;;;GAOG;AACH,wBAAuB,GAAG,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,EACjD,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC,GAAG,MAAM,EACzC,KAAK,EAAE,CAAC,wCAwCR;AAED;;;;;GAKG;AACH,wBAAuB,QAAQ,CAAC,KAAK,GAAE;IAAE,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;CAAO,wCAErE;AAED;;;GAGG;AACH,wBAAuB,WAAW,CACjC,OAAO,EAAE,GAAG,CAAC,OAAO,GAClB,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CA8GtC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,QAAQ,GAAU,SAAS,GAAG,CAAC,OAAO,oBAOlD,CAAC"}
|
package/dist/jsx/index.js
CHANGED
|
@@ -37,25 +37,28 @@ export async function* jsx(tag, props) {
|
|
|
37
37
|
}
|
|
38
38
|
// intrinsic element
|
|
39
39
|
const { children, ...rest } = props;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
let attributes = "";
|
|
41
|
+
let key;
|
|
42
|
+
let value;
|
|
43
|
+
for (key in rest) {
|
|
44
|
+
value = rest[key]; // needs to come before reassigning keys
|
|
43
45
|
if (key === "className")
|
|
44
46
|
key = "class";
|
|
45
47
|
else if (key === "htmlFor")
|
|
46
48
|
key = "for";
|
|
47
49
|
if (value === true) {
|
|
48
50
|
// just put the key without the value
|
|
49
|
-
attributes
|
|
51
|
+
attributes += ` ${key}`;
|
|
50
52
|
}
|
|
51
|
-
else if (typeof value === "string"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
else if (typeof value === "string") {
|
|
54
|
+
attributes += ` ${key}="${Chunk.escape(value, true)}"`;
|
|
55
|
+
}
|
|
56
|
+
else if (typeof value === "number" || typeof value === "bigint") {
|
|
57
|
+
attributes += ` ${key}="${value}"`;
|
|
55
58
|
}
|
|
56
59
|
// otherwise, don't include the attribute
|
|
57
60
|
}
|
|
58
|
-
yield new Chunk(`<${tag}${attributes
|
|
61
|
+
yield new Chunk(`<${tag}${attributes}>`, true);
|
|
59
62
|
if (voidElements.has(tag))
|
|
60
63
|
return;
|
|
61
64
|
yield* toGenerator(children);
|
|
@@ -94,7 +97,8 @@ export async function* toGenerator(element) {
|
|
|
94
97
|
if (typeof element === "object") {
|
|
95
98
|
if (Symbol.asyncIterator in element) {
|
|
96
99
|
// async iterable - lazily resolve
|
|
97
|
-
|
|
100
|
+
let children;
|
|
101
|
+
for await (children of element)
|
|
98
102
|
yield* toGenerator(children);
|
|
99
103
|
return;
|
|
100
104
|
}
|
|
@@ -106,10 +110,11 @@ export async function* toGenerator(element) {
|
|
|
106
110
|
typeof iterator.return === "function") {
|
|
107
111
|
// sync generator
|
|
108
112
|
// process lazily - avoids loading all in memory
|
|
109
|
-
const yieldIterations =
|
|
113
|
+
const yieldIterations = 150;
|
|
110
114
|
let yieldCounter = yieldIterations;
|
|
115
|
+
let result;
|
|
111
116
|
while (true) {
|
|
112
|
-
|
|
117
|
+
result = iterator.next();
|
|
113
118
|
if (result.done)
|
|
114
119
|
break;
|
|
115
120
|
yield* toGenerator(result.value);
|
|
@@ -125,19 +130,21 @@ export async function* toGenerator(element) {
|
|
|
125
130
|
// other iterable - array, set, etc.
|
|
126
131
|
// process children in parallel
|
|
127
132
|
const generators = [];
|
|
133
|
+
let result;
|
|
128
134
|
while (true) {
|
|
129
|
-
|
|
135
|
+
result = iterator.next();
|
|
130
136
|
if (result.done)
|
|
131
137
|
break;
|
|
132
138
|
generators.push(toGenerator(result.value));
|
|
133
139
|
}
|
|
134
|
-
const queue = new Array(generators.length)
|
|
135
|
-
let current = 0;
|
|
140
|
+
const queue = new Array(generators.length);
|
|
136
141
|
const complete = new Set();
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
142
|
+
let current = 0;
|
|
143
|
+
let m;
|
|
144
|
+
for await (m of merge(generators)) {
|
|
145
|
+
if (m.result.done) {
|
|
146
|
+
complete.add(m.index);
|
|
147
|
+
if (m.index === current) {
|
|
141
148
|
while (++current < generators.length) {
|
|
142
149
|
if (queue[current]) {
|
|
143
150
|
// yield whatever is in the next queue even if it hasn't completed yet
|
|
@@ -150,15 +157,15 @@ export async function* toGenerator(element) {
|
|
|
150
157
|
}
|
|
151
158
|
}
|
|
152
159
|
}
|
|
153
|
-
else if (index === current) {
|
|
154
|
-
yield
|
|
160
|
+
else if (m.index === current) {
|
|
161
|
+
yield m.result.value; // stream the current value directly
|
|
155
162
|
}
|
|
156
163
|
else {
|
|
157
164
|
// queue the value for later
|
|
158
|
-
if (queue[index])
|
|
159
|
-
queue[index].concat(
|
|
165
|
+
if (queue[m.index])
|
|
166
|
+
queue[m.index].concat(m.result.value);
|
|
160
167
|
else
|
|
161
|
-
queue[index] =
|
|
168
|
+
queue[m.index] = m.result.value;
|
|
162
169
|
}
|
|
163
170
|
}
|
|
164
171
|
// clear the queue
|
|
@@ -181,8 +188,9 @@ export async function* toGenerator(element) {
|
|
|
181
188
|
* @returns Concatenated HTML
|
|
182
189
|
*/
|
|
183
190
|
export const toString = async (element) => {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
191
|
+
let buffer = "";
|
|
192
|
+
let chunk;
|
|
193
|
+
for await (chunk of toGenerator(element))
|
|
194
|
+
buffer += chunk.value;
|
|
195
|
+
return buffer;
|
|
188
196
|
};
|
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
* Adapted from [stack overflow answers](https://stackoverflow.com/questions/50585456).
|
|
6
6
|
*
|
|
7
7
|
* @param generators Resolved in parallel.
|
|
8
|
-
* @param returnValue Passed into each `iterator.return()`
|
|
9
8
|
* @yields `IteratorResult` and `index` of the resolved generator.
|
|
10
9
|
*/
|
|
11
|
-
export declare function merge<T>(generators: AsyncGenerator<T, void>[]): AsyncGenerator<
|
|
10
|
+
export declare function merge<T>(generators: AsyncGenerator<T, void>[]): AsyncGenerator<{
|
|
11
|
+
index: number;
|
|
12
|
+
result: IteratorResult<T, void>;
|
|
13
|
+
}, void, unknown>;
|
|
12
14
|
//# sourceMappingURL=merge-async-generators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-async-generators.d.ts","sourceRoot":"","sources":["../../src/jsx/merge-async-generators.ts"],"names":[],"mappings":"AAKA
|
|
1
|
+
{"version":3,"file":"merge-async-generators.d.ts","sourceRoot":"","sources":["../../src/jsx/merge-async-generators.ts"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,wBAAuB,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE;;;kBA6BpE"}
|
|
@@ -9,7 +9,6 @@ const next = async (iterator, index) => ({
|
|
|
9
9
|
* Adapted from [stack overflow answers](https://stackoverflow.com/questions/50585456).
|
|
10
10
|
*
|
|
11
11
|
* @param generators Resolved in parallel.
|
|
12
|
-
* @param returnValue Passed into each `iterator.return()`
|
|
13
12
|
* @yields `IteratorResult` and `index` of the resolved generator.
|
|
14
13
|
*/
|
|
15
14
|
export async function* merge(generators) {
|
|
@@ -29,7 +28,9 @@ export async function* merge(generators) {
|
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
finally {
|
|
32
|
-
for (const
|
|
33
|
-
|
|
31
|
+
for (const iterator of iterators) {
|
|
32
|
+
// catch - could have already returned
|
|
33
|
+
iterator.return().catch(() => { });
|
|
34
|
+
}
|
|
34
35
|
}
|
|
35
36
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Params } from "../app/index.js";
|
|
2
|
+
import type { JSX } from "../jsx/index.js";
|
|
1
3
|
export type MaybePromise<T> = T | Promise<T>;
|
|
2
4
|
export type MaybeFunction<T> = T | (() => T);
|
|
3
5
|
export type DeepArray<T> = T | DeepArray<T>[];
|
|
@@ -12,4 +14,19 @@ export type ExtractMultiParams<Patterns extends string[]> = Patterns extends [
|
|
|
12
14
|
infer First extends string,
|
|
13
15
|
...infer Rest extends string[]
|
|
14
16
|
] ? Rest["length"] extends 0 ? ExtractParams<First> : ExtractParams<First> | ExtractMultiParams<Rest> : never;
|
|
17
|
+
export type AnchorProps<P extends Params> = JSX.IntrinsicElements["a"] & (keyof P extends never ? {
|
|
18
|
+
params?: never;
|
|
19
|
+
} : {
|
|
20
|
+
params: P;
|
|
21
|
+
});
|
|
22
|
+
export type FormProps<P extends Params> = JSX.IntrinsicElements["form"] & (keyof P extends never ? {
|
|
23
|
+
params?: never;
|
|
24
|
+
} : {
|
|
25
|
+
params: P;
|
|
26
|
+
});
|
|
27
|
+
export type ButtonProps<P extends Params> = JSX.IntrinsicElements["button"] & (keyof P extends never ? {
|
|
28
|
+
params?: never;
|
|
29
|
+
} : {
|
|
30
|
+
params: P;
|
|
31
|
+
});
|
|
15
32
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAE7C,MAAM,MAAM,SAAS,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AAC,CAAC;AAE9D,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,GAAG,CAAC,iBAAiB,CAAC,QAAQ,CAAC,GAC1E,CAAC,MAAM,CAAC,SAAS,KAAK,GAAG;IAAE,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/app/context.ts
CHANGED
|
@@ -233,6 +233,8 @@ export class Context<P extends Params = Params> {
|
|
|
233
233
|
gen = toGenerator(Page);
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
let result: IteratorResult<Chunk>;
|
|
237
|
+
|
|
236
238
|
this.html(
|
|
237
239
|
new ReadableStream<string>({
|
|
238
240
|
pull: async (c) => {
|
|
@@ -242,7 +244,7 @@ export class Context<P extends Params = Params> {
|
|
|
242
244
|
return;
|
|
243
245
|
}
|
|
244
246
|
|
|
245
|
-
|
|
247
|
+
result = await gen.next();
|
|
246
248
|
if (result.done) c.close();
|
|
247
249
|
else c.enqueue(result.value.value);
|
|
248
250
|
},
|
package/src/app/get.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type JSX, jsx } from "../jsx/index.js";
|
|
2
2
|
import { insertParams } from "../trie/insert-params.js";
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import type {
|
|
4
|
+
AnchorProps,
|
|
5
|
+
ButtonProps,
|
|
6
|
+
ExtractParams,
|
|
7
|
+
FormProps,
|
|
8
|
+
} from "../types/index.js";
|
|
9
|
+
import type { Middleware } from "./index.js";
|
|
8
10
|
|
|
9
11
|
export class Get<Pattern extends string = string> {
|
|
10
12
|
/** Route pattern */
|
|
@@ -16,6 +18,12 @@ export class Get<Pattern extends string = string> {
|
|
|
16
18
|
/** `<a>` component with preset `href` attribute. */
|
|
17
19
|
Anchor: (props: AnchorProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
18
20
|
|
|
21
|
+
/** `<button>` component with preset `formaction` and `formmethod` attributes. */
|
|
22
|
+
Button: (props: ButtonProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
23
|
+
|
|
24
|
+
/** `<form>` component with preset `method` and `action` attributes. */
|
|
25
|
+
Form: (props: FormProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
26
|
+
|
|
19
27
|
#parts: string[];
|
|
20
28
|
|
|
21
29
|
/**
|
|
@@ -45,10 +53,30 @@ export class Get<Pattern extends string = string> {
|
|
|
45
53
|
this.pattern = pattern;
|
|
46
54
|
this.middleware = middleware;
|
|
47
55
|
this.#parts = pattern.split("/");
|
|
56
|
+
|
|
48
57
|
this.Anchor = (props) => {
|
|
49
58
|
const { params = {}, ...rest } = props;
|
|
50
59
|
|
|
51
60
|
return jsx("a", { href: insertParams(this.#parts, params), ...rest });
|
|
52
61
|
};
|
|
62
|
+
|
|
63
|
+
this.Button = (props) => {
|
|
64
|
+
const { params = {}, ...rest } = props;
|
|
65
|
+
|
|
66
|
+
return jsx("button", {
|
|
67
|
+
formaction: insertParams(this.#parts, params),
|
|
68
|
+
formmethod: "get",
|
|
69
|
+
...rest,
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
this.Form = (props) => {
|
|
74
|
+
const { params = {}, ...rest } = props;
|
|
75
|
+
|
|
76
|
+
return jsx("form", {
|
|
77
|
+
action: insertParams(this.#parts, params),
|
|
78
|
+
...rest,
|
|
79
|
+
});
|
|
80
|
+
};
|
|
53
81
|
}
|
|
54
82
|
}
|
package/src/app/post.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { type JSX, jsx } from "../jsx/index.js";
|
|
2
2
|
import { insertParams } from "../trie/insert-params.js";
|
|
3
|
-
import type { ExtractParams } from "../types/index.js";
|
|
3
|
+
import type { ButtonProps, ExtractParams, FormProps } from "../types/index.js";
|
|
4
4
|
import { hash } from "../util/hash.js";
|
|
5
|
-
import type { Middleware
|
|
6
|
-
|
|
7
|
-
type FormProps<P extends Params> = JSX.IntrinsicElements["form"] &
|
|
8
|
-
(keyof P extends never ? { params?: never } : { params: P });
|
|
5
|
+
import type { Middleware } from "./index.js";
|
|
9
6
|
|
|
10
7
|
export class Post<Pattern extends string = string> {
|
|
11
8
|
/** Route pattern */
|
|
@@ -14,6 +11,9 @@ export class Post<Pattern extends string = string> {
|
|
|
14
11
|
/** POST middleware */
|
|
15
12
|
middleware: Middleware<any>[];
|
|
16
13
|
|
|
14
|
+
/** `<button>` component with preset `formaction` and `formmethod` attributes. */
|
|
15
|
+
Button: (props: ButtonProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
16
|
+
|
|
17
17
|
/** `<form>` component with preset `method` and `action` attributes. */
|
|
18
18
|
Form: (props: FormProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
19
19
|
|
|
@@ -34,7 +34,7 @@ export class Post<Pattern extends string = string> {
|
|
|
34
34
|
*
|
|
35
35
|
* const page = new Get("/", () => (
|
|
36
36
|
* <post.Form>
|
|
37
|
-
* <input />
|
|
37
|
+
* <input type="text" name="name" />
|
|
38
38
|
* <button>Submit</button>
|
|
39
39
|
* </post.Form>
|
|
40
40
|
* ));
|
|
@@ -61,11 +61,21 @@ export class Post<Pattern extends string = string> {
|
|
|
61
61
|
this.pattern = patternOrMiddleware;
|
|
62
62
|
} else {
|
|
63
63
|
this.middleware.unshift(patternOrMiddleware);
|
|
64
|
-
this.pattern = `/
|
|
64
|
+
this.pattern = `/_p/${hash(this.middleware.join())}` as Pattern;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
this.#parts = this.pattern.split("/");
|
|
68
68
|
|
|
69
|
+
this.Button = (props) => {
|
|
70
|
+
const { params = {}, ...rest } = props;
|
|
71
|
+
|
|
72
|
+
return jsx("button", {
|
|
73
|
+
formaction: insertParams(this.#parts, params),
|
|
74
|
+
formmethod: "post",
|
|
75
|
+
...rest,
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
69
79
|
this.Form = (props) => {
|
|
70
80
|
const { params = {}, ...rest } = props;
|
|
71
81
|
|
package/src/index.ts
CHANGED
package/src/jsx/chunk/index.ts
CHANGED
|
@@ -46,20 +46,20 @@ export class Chunk {
|
|
|
46
46
|
// tracks the position of the last successful match in the input string
|
|
47
47
|
let start = 0;
|
|
48
48
|
let result = "";
|
|
49
|
+
// index of the match
|
|
50
|
+
let i: number;
|
|
51
|
+
let match: string | undefined;
|
|
49
52
|
|
|
50
53
|
// since `g` flag is used, regex maintains state with each loop,
|
|
51
54
|
// checking from the lastIndex onward each time
|
|
52
55
|
while (regex.test(s)) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const match = s[i];
|
|
56
|
-
|
|
56
|
+
i = regex.lastIndex - 1;
|
|
57
|
+
match = s[i];
|
|
57
58
|
result +=
|
|
58
59
|
// everything that didn't match during this test
|
|
59
60
|
s.slice(start, i) +
|
|
60
61
|
// replacement
|
|
61
62
|
(match === "&" ? "&" : match === '"' ? """ : "<");
|
|
62
|
-
|
|
63
63
|
start = regex.lastIndex;
|
|
64
64
|
}
|
|
65
65
|
|
package/src/jsx/index.ts
CHANGED
|
@@ -72,28 +72,28 @@ export async function* jsx<P extends Props = Props>(
|
|
|
72
72
|
// intrinsic element
|
|
73
73
|
const { children, ...rest } = props;
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
let attributes = "";
|
|
76
|
+
let key: string;
|
|
77
|
+
let value: JSX.Element;
|
|
76
78
|
|
|
77
|
-
for (
|
|
78
|
-
|
|
79
|
+
for (key in rest) {
|
|
80
|
+
value = rest[key]; // needs to come before reassigning keys
|
|
79
81
|
|
|
80
82
|
if (key === "className") key = "class";
|
|
81
83
|
else if (key === "htmlFor") key = "for";
|
|
82
84
|
|
|
83
85
|
if (value === true) {
|
|
84
86
|
// just put the key without the value
|
|
85
|
-
attributes
|
|
86
|
-
} else if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
) {
|
|
91
|
-
attributes.push(` ${key}="${Chunk.escape(String(value), true)}"`);
|
|
87
|
+
attributes += ` ${key}`;
|
|
88
|
+
} else if (typeof value === "string") {
|
|
89
|
+
attributes += ` ${key}="${Chunk.escape(value, true)}"`;
|
|
90
|
+
} else if (typeof value === "number" || typeof value === "bigint") {
|
|
91
|
+
attributes += ` ${key}="${value}"`;
|
|
92
92
|
}
|
|
93
93
|
// otherwise, don't include the attribute
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
yield new Chunk(`<${tag}${attributes
|
|
96
|
+
yield new Chunk(`<${tag}${attributes}>`, true);
|
|
97
97
|
|
|
98
98
|
if (voidElements.has(tag)) return;
|
|
99
99
|
|
|
@@ -139,7 +139,9 @@ export async function* toGenerator(
|
|
|
139
139
|
if (typeof element === "object") {
|
|
140
140
|
if (Symbol.asyncIterator in element) {
|
|
141
141
|
// async iterable - lazily resolve
|
|
142
|
-
|
|
142
|
+
let children: JSX.Element;
|
|
143
|
+
|
|
144
|
+
for await (children of element) yield* toGenerator(children);
|
|
143
145
|
|
|
144
146
|
return;
|
|
145
147
|
}
|
|
@@ -155,11 +157,12 @@ export async function* toGenerator(
|
|
|
155
157
|
) {
|
|
156
158
|
// sync generator
|
|
157
159
|
// process lazily - avoids loading all in memory
|
|
158
|
-
const yieldIterations =
|
|
160
|
+
const yieldIterations = 150;
|
|
159
161
|
let yieldCounter = yieldIterations;
|
|
162
|
+
let result: IteratorResult<JSX.Element>;
|
|
160
163
|
|
|
161
164
|
while (true) {
|
|
162
|
-
|
|
165
|
+
result = iterator.next();
|
|
163
166
|
|
|
164
167
|
if (result.done) break;
|
|
165
168
|
yield* toGenerator(result.value);
|
|
@@ -178,26 +181,24 @@ export async function* toGenerator(
|
|
|
178
181
|
// other iterable - array, set, etc.
|
|
179
182
|
// process children in parallel
|
|
180
183
|
const generators: AsyncGenerator<Chunk, void, unknown>[] = [];
|
|
184
|
+
let result: IteratorResult<JSX.Element>;
|
|
181
185
|
|
|
182
186
|
while (true) {
|
|
183
|
-
|
|
187
|
+
result = iterator.next();
|
|
184
188
|
if (result.done) break;
|
|
185
189
|
generators.push(toGenerator(result.value));
|
|
186
190
|
}
|
|
187
191
|
|
|
188
|
-
const queue: (Chunk | null)[] = new Array(generators.length)
|
|
189
|
-
|
|
190
|
-
let current = 0;
|
|
192
|
+
const queue: (Chunk | null)[] = new Array(generators.length);
|
|
191
193
|
const complete = new Set<number>();
|
|
194
|
+
let current = 0;
|
|
195
|
+
let m: { index: number; result: IteratorResult<Chunk, void> };
|
|
192
196
|
|
|
193
|
-
for await (
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
} of merge(generators)) {
|
|
197
|
-
if (done) {
|
|
198
|
-
complete.add(index);
|
|
197
|
+
for await (m of merge(generators)) {
|
|
198
|
+
if (m.result.done) {
|
|
199
|
+
complete.add(m.index);
|
|
199
200
|
|
|
200
|
-
if (index === current) {
|
|
201
|
+
if (m.index === current) {
|
|
201
202
|
while (++current < generators.length) {
|
|
202
203
|
if (queue[current]) {
|
|
203
204
|
// yield whatever is in the next queue even if it hasn't completed yet
|
|
@@ -209,12 +210,12 @@ export async function* toGenerator(
|
|
|
209
210
|
if (!complete.has(current)) break;
|
|
210
211
|
}
|
|
211
212
|
}
|
|
212
|
-
} else if (index === current) {
|
|
213
|
-
yield
|
|
213
|
+
} else if (m.index === current) {
|
|
214
|
+
yield m.result.value; // stream the current value directly
|
|
214
215
|
} else {
|
|
215
216
|
// queue the value for later
|
|
216
|
-
if (queue[index]) queue[index]
|
|
217
|
-
else queue[index] =
|
|
217
|
+
if (queue[m.index]) queue[m.index]!.concat(m.result.value);
|
|
218
|
+
else queue[m.index] = m.result.value;
|
|
218
219
|
}
|
|
219
220
|
}
|
|
220
221
|
|
|
@@ -241,7 +242,10 @@ export async function* toGenerator(
|
|
|
241
242
|
* @returns Concatenated HTML
|
|
242
243
|
*/
|
|
243
244
|
export const toString = async (element: JSX.Element) => {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
245
|
+
let buffer = "";
|
|
246
|
+
let chunk: Chunk;
|
|
247
|
+
|
|
248
|
+
for await (chunk of toGenerator(element)) buffer += chunk.value;
|
|
249
|
+
|
|
250
|
+
return buffer;
|
|
247
251
|
};
|
|
@@ -10,12 +10,11 @@ const next = async <T, R>(iterator: AsyncIterator<T, R>, index: number) => ({
|
|
|
10
10
|
* Adapted from [stack overflow answers](https://stackoverflow.com/questions/50585456).
|
|
11
11
|
*
|
|
12
12
|
* @param generators Resolved in parallel.
|
|
13
|
-
* @param returnValue Passed into each `iterator.return()`
|
|
14
13
|
* @yields `IteratorResult` and `index` of the resolved generator.
|
|
15
14
|
*/
|
|
16
15
|
export async function* merge<T>(generators: AsyncGenerator<T, void>[]) {
|
|
17
16
|
const iterators = generators.map((gen) => gen[Symbol.asyncIterator]());
|
|
18
|
-
const promises = new Map<number,
|
|
17
|
+
const promises = new Map<number, ReturnType<typeof next<T, void>>>();
|
|
19
18
|
|
|
20
19
|
iterators.forEach((iterator, index) =>
|
|
21
20
|
promises.set(index, next(iterator, index)),
|
|
@@ -37,6 +36,9 @@ export async function* merge<T>(generators: AsyncGenerator<T, void>[]) {
|
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
} finally {
|
|
40
|
-
for (const
|
|
39
|
+
for (const iterator of iterators) {
|
|
40
|
+
// catch - could have already returned
|
|
41
|
+
iterator.return().catch(() => {});
|
|
42
|
+
}
|
|
41
43
|
}
|
|
42
44
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { Params } from "../app/index.js";
|
|
2
|
+
import type { JSX } from "../jsx/index.js";
|
|
3
|
+
|
|
1
4
|
export type MaybePromise<T> = T | Promise<T>;
|
|
2
5
|
|
|
3
6
|
export type MaybeFunction<T> = T | (() => T);
|
|
@@ -21,3 +24,12 @@ export type ExtractMultiParams<Patterns extends string[]> = Patterns extends [
|
|
|
21
24
|
? ExtractParams<First>
|
|
22
25
|
: ExtractParams<First> | ExtractMultiParams<Rest>
|
|
23
26
|
: never;
|
|
27
|
+
|
|
28
|
+
export type AnchorProps<P extends Params> = JSX.IntrinsicElements["a"] &
|
|
29
|
+
(keyof P extends never ? { params?: never } : { params: P });
|
|
30
|
+
|
|
31
|
+
export type FormProps<P extends Params> = JSX.IntrinsicElements["form"] &
|
|
32
|
+
(keyof P extends never ? { params?: never } : { params: P });
|
|
33
|
+
|
|
34
|
+
export type ButtonProps<P extends Params> = JSX.IntrinsicElements["button"] &
|
|
35
|
+
(keyof P extends never ? { params?: never } : { params: P });
|