@typed/ui 0.3.2 → 0.3.4
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/Component/package.json +6 -0
- package/Props/package.json +6 -0
- package/dist/cjs/Anchor.js +3 -85
- package/dist/cjs/Anchor.js.map +1 -1
- package/dist/cjs/Component.js +6 -0
- package/dist/cjs/Component.js.map +1 -0
- package/dist/cjs/Link.js +2 -3
- package/dist/cjs/Link.js.map +1 -1
- package/dist/cjs/Props.js +26 -0
- package/dist/cjs/Props.js.map +1 -0
- package/dist/cjs/dom-properties.js.map +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/useClickAway.js.map +1 -1
- package/dist/dts/Anchor.d.ts +5 -56
- package/dist/dts/Anchor.d.ts.map +1 -1
- package/dist/dts/Component.d.ts +16 -0
- package/dist/dts/Component.d.ts.map +1 -0
- package/dist/dts/Link.d.ts +1 -1
- package/dist/dts/Link.d.ts.map +1 -1
- package/dist/dts/Props.d.ts +60 -0
- package/dist/dts/Props.d.ts.map +1 -0
- package/dist/dts/{internal/dom-properties.d.ts → dom-properties.d.ts} +258 -39
- package/dist/dts/dom-properties.d.ts.map +1 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/Anchor.js +1 -65
- package/dist/esm/Anchor.js.map +1 -1
- package/dist/esm/Component.js +5 -0
- package/dist/esm/Component.js.map +1 -0
- package/dist/esm/Link.js +4 -3
- package/dist/esm/Link.js.map +1 -1
- package/dist/esm/Props.js +19 -0
- package/dist/esm/Props.js.map +1 -0
- package/dist/esm/dom-properties.js +5 -0
- package/dist/esm/dom-properties.js.map +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/useClickAway.js.map +1 -1
- package/dom-properties/package.json +6 -0
- package/package.json +36 -12
- package/src/Anchor.ts +6 -190
- package/src/Component.ts +24 -0
- package/src/Link.ts +12 -39
- package/src/Props.ts +95 -0
- package/src/{internal/dom-properties.ts → dom-properties.ts} +260 -40
- package/src/index.ts +1 -0
- package/src/useClickAway.ts +1 -1
- package/dist/cjs/internal/dom-properties.js.map +0 -1
- package/dist/dts/internal/dom-properties.d.ts.map +0 -1
- package/dist/esm/internal/dom-properties.js +0 -2
- package/dist/esm/internal/dom-properties.js.map +0 -1
- /package/dist/cjs/{internal/dom-properties.js → dom-properties.js} +0 -0
package/dist/esm/Anchor.js
CHANGED
|
@@ -1,73 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import * as Fx from "@typed/fx/Fx";
|
|
5
|
-
import * as Directive from "@typed/template/Directive";
|
|
6
|
-
import * as EventHandler from "@typed/template/EventHandler";
|
|
7
4
|
import { html } from "@typed/template/RenderTemplate";
|
|
8
|
-
import * as Effect from "effect/Effect";
|
|
9
|
-
import { uncapitalize } from "effect/String";
|
|
10
5
|
/**
|
|
11
6
|
* @since 1.0.0
|
|
12
7
|
*/
|
|
13
|
-
export
|
|
14
|
-
const { data, hash, host, hostname, href, hreflang, pathname, port, protocol, ref, scrollLeft, scrollTop, search, ...rest } = props;
|
|
15
|
-
const refDirective = Directive.ref(({ value }) => Effect.gen(function* (_) {
|
|
16
|
-
yield* _(addEventListeners(props, value));
|
|
17
|
-
if (ref) {
|
|
18
|
-
yield* _(ref(value));
|
|
19
|
-
}
|
|
20
|
-
}));
|
|
21
|
-
return html `<a
|
|
22
|
-
ref="${refDirective}"
|
|
23
|
-
.props="${rest}"
|
|
24
|
-
.data="${data}"
|
|
25
|
-
.scrollLeft="${scrollLeft}"
|
|
26
|
-
.scrollTop="${scrollTop}"
|
|
27
|
-
.hash="${hash}"
|
|
28
|
-
.host="${host}"
|
|
29
|
-
.hostname="${hostname}"
|
|
30
|
-
.href="${href}"
|
|
31
|
-
.hreflang="${hreflang}"
|
|
32
|
-
.pathname="${pathname}"
|
|
33
|
-
.port="${port}"
|
|
34
|
-
.protocol="${protocol}"
|
|
35
|
-
.search="${search}"
|
|
36
|
-
>${children}</a>`;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @since 1.0.0
|
|
40
|
-
*/
|
|
41
|
-
export function addEventListeners(props, ref) {
|
|
42
|
-
return Fx.forkScoped(Fx.mergeAll(getEventHandlers(props).map(([type, handler]) => addEventListener(ref, type, handler))));
|
|
43
|
-
}
|
|
44
|
-
function addEventListener(ref, event, handler) {
|
|
45
|
-
return Fx.mapEffect(ref.events(event, handler.options), (ev) => handler.handler(ev));
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* @since 1.0.0
|
|
49
|
-
*/
|
|
50
|
-
export function getEventHandlers(props) {
|
|
51
|
-
const eventHandlers = Object.keys(props).filter((x) => x[0] === "o" && x[1] === "n").flatMap((key) => {
|
|
52
|
-
const handler = getEventHandler(props[key]);
|
|
53
|
-
if (!handler)
|
|
54
|
-
return [];
|
|
55
|
-
const eventType = uncapitalize(key.slice(2));
|
|
56
|
-
return [[eventType, handler]];
|
|
57
|
-
});
|
|
58
|
-
return eventHandlers;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @since 1.0.0
|
|
62
|
-
*/
|
|
63
|
-
export function getEventHandler(handler) {
|
|
64
|
-
if (!handler)
|
|
65
|
-
return null;
|
|
66
|
-
if (Effect.isEffect(handler)) {
|
|
67
|
-
return EventHandler.make(() => handler);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
return handler;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
8
|
+
export const Anchor = (props, ...children) => html `<a ...${props}>${children}</a>`;
|
|
73
9
|
//# sourceMappingURL=Anchor.js.map
|
package/dist/esm/Anchor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Anchor.js","sourceRoot":"","sources":["../../src/Anchor.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"Anchor.js","sourceRoot":"","sources":["../../src/Anchor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAA;AAUrD;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAA2B,CAAC,KAAK,EAAE,GAAG,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAA,SAAS,KAAK,IAAI,QAAQ,MAAM,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Component.js","sourceRoot":"","sources":["../../src/Component.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/dist/esm/Link.js
CHANGED
|
@@ -5,11 +5,12 @@ import { makeHref } from "@typed/router";
|
|
|
5
5
|
import * as EventHandler from "@typed/template/EventHandler";
|
|
6
6
|
import { Placeholder } from "@typed/template/Placeholder";
|
|
7
7
|
import * as Effect from "effect/Effect";
|
|
8
|
-
import { Anchor
|
|
8
|
+
import { Anchor } from "./Anchor.js";
|
|
9
|
+
import { getEventHandler } from "./Props.js";
|
|
9
10
|
/**
|
|
10
11
|
* @since 1.0.0
|
|
11
12
|
*/
|
|
12
|
-
export function Link({ onClick,
|
|
13
|
+
export function Link({ onClick, relative, replace, state, to, ...props }, ...children) {
|
|
13
14
|
return Fx.gen(function* (_) {
|
|
14
15
|
const onClickHandler = getEventHandler(onClick);
|
|
15
16
|
const toRef = yield* _(Placeholder.asRef(to));
|
|
@@ -35,7 +36,7 @@ export function Link({ onClick, ref, relative, replace, state, to, ...props }, .
|
|
|
35
36
|
}
|
|
36
37
|
yield* _(navigate);
|
|
37
38
|
}), onClickHandler?.options);
|
|
38
|
-
const allProps = { ...props,
|
|
39
|
+
const allProps = { ...props, href, state: stateRef, onClick: onClickEventHandler };
|
|
39
40
|
return Anchor(allProps, ...children);
|
|
40
41
|
});
|
|
41
42
|
}
|
package/dist/esm/Link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.js","sourceRoot":"","sources":["../../src/Link.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,c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B,CAAC,CAAC,CAAA;YAEH,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;gBAC3B,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;YACvD,CAAC;QACH,CAAC,CAAC,CAAA;QAEF,MAAM,mBAAmB,GAAG,YAAY,CAAC,cAAc,CACrD,CAAC,EAAyD,EAAE,EAAE,CAC5D,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAC,CAAC;YACpB,IAAI,cAAc,EAAE,CAAC;gBACnB,KAAK,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;YACtC,CAAC;YACD,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;QACpB,CAAC,CAAC,EACJ,cAAc,EAAE,OAAO,CACxB,CAAA;QAED,MAAM,QAAQ,GAAG,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,mBAAmB,EAAE,CAAA;QAElF,OAAO,MAAM,CAAC,QAAwB,EAAE,GAAG,QAAQ,CAAC,CAAA;IACtD,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as EventHandler from "@typed/template/EventHandler";
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
/**
|
|
7
|
+
* @since 1.0.0
|
|
8
|
+
*/
|
|
9
|
+
export function getEventHandler(handler) {
|
|
10
|
+
if (!handler)
|
|
11
|
+
return null;
|
|
12
|
+
if (Effect.isEffect(handler)) {
|
|
13
|
+
return EventHandler.make(() => handler);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return handler;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=Props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Props.js","sourceRoot":"","sources":["../../src/Props.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,YAAY,MAAM,8BAA8B,CAAA;AAG5D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAuE/B;;GAEG;AACH,MAAM,UAAU,eAAe,CAC7B,OAA8F;IAE9F,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAA;IAEzB,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,OAAO,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,CAAA;IACzC,CAAC;SAAM,CAAC;QACN,OAAO,OAAO,CAAA;IAChB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-properties.js","sourceRoot":"","sources":["../../src/dom-properties.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,QAAQ;AACR,4BAA4B;AAC5B,UAAU;AACV,YAAY;AACZ,SAAS;AACT,SAAS;AACT,cAAc;AACd,gBAAgB;AAChB,WAAW;AACX,UAAU;AACV,OAAO;AACP,QAAQ;AACR,SAAS;AACT,sBAAsB;AACtB,SAAS;AACT,kBAAkB;AAClB,eAAe;AACf,mBAAmB;AACnB,SAAS;AACT,iBAAiB;AACjB,0BAA0B;AAE1B;;GAEG;AACH,cAAc,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,QAAQ;AACR,4BAA4B;AAC5B,UAAU;AACV,YAAY;AACZ,SAAS;AACT,SAAS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AQ,GAAG,EAAE,CAAC,GAAG,CACrB,EAAE,CAAC,KAAK,CAAC,IAA0D,CAAC,EACpE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAClC,CAAA;QAED,OAAO,EAAE,CAAC,SAAS,CACjB,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,EACvD,CAAC,CACF,CAAA;IACH,CAAC,CAAC,CAAC,CAAA;AACL,CAAC;AAED,MAAM,YAAY,GAAG,CACnB,KAAgE,EAChE,IAA4B,EAC8C,EAAE;IAC5E,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;IAE3B,IACE,MAAM,KAAK,IAAI;QACf,IAAI,CAAC,IAAI,CACP,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,KAAK,MAAM;YACZ,CAAC,CAAC,QAAQ,CAAC,MAAc,CAAC,CAC7B,EACD,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,EAAE,CAAA;IACtB,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typed/ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -10,18 +10,18 @@
|
|
|
10
10
|
"sideEffects": [],
|
|
11
11
|
"author": "Typed contributors",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@effect/platform": "
|
|
14
|
-
"@effect/schema": "0.
|
|
13
|
+
"@effect/platform": "0.42.2",
|
|
14
|
+
"@effect/schema": "0.60.2",
|
|
15
15
|
"csstype": "^3.1.3",
|
|
16
|
-
"effect": "^2.0
|
|
17
|
-
"@typed/
|
|
18
|
-
"@typed/
|
|
19
|
-
"@typed/environment": "0.3.
|
|
20
|
-
"@typed/
|
|
21
|
-
"@typed/navigation": "0.8.
|
|
22
|
-
"@typed/
|
|
23
|
-
"@typed/
|
|
24
|
-
"@typed/
|
|
16
|
+
"effect": "^2.1.0",
|
|
17
|
+
"@typed/dom": "9.0.1",
|
|
18
|
+
"@typed/fx": "1.20.2",
|
|
19
|
+
"@typed/environment": "0.3.1",
|
|
20
|
+
"@typed/context": "0.21.1",
|
|
21
|
+
"@typed/navigation": "0.8.2",
|
|
22
|
+
"@typed/router": "0.21.2",
|
|
23
|
+
"@typed/template": "0.3.4",
|
|
24
|
+
"@typed/route": "2.0.2"
|
|
25
25
|
},
|
|
26
26
|
"main": "./dist/cjs/index.js",
|
|
27
27
|
"module": "./dist/esm/index.js",
|
|
@@ -38,11 +38,26 @@
|
|
|
38
38
|
"import": "./dist/esm/Anchor.js",
|
|
39
39
|
"default": "./dist/cjs/Anchor.js"
|
|
40
40
|
},
|
|
41
|
+
"./Component": {
|
|
42
|
+
"types": "./dist/dts/Component.d.ts",
|
|
43
|
+
"import": "./dist/esm/Component.js",
|
|
44
|
+
"default": "./dist/cjs/Component.js"
|
|
45
|
+
},
|
|
41
46
|
"./Link": {
|
|
42
47
|
"types": "./dist/dts/Link.d.ts",
|
|
43
48
|
"import": "./dist/esm/Link.js",
|
|
44
49
|
"default": "./dist/cjs/Link.js"
|
|
45
50
|
},
|
|
51
|
+
"./Props": {
|
|
52
|
+
"types": "./dist/dts/Props.d.ts",
|
|
53
|
+
"import": "./dist/esm/Props.js",
|
|
54
|
+
"default": "./dist/cjs/Props.js"
|
|
55
|
+
},
|
|
56
|
+
"./dom-properties": {
|
|
57
|
+
"types": "./dist/dts/dom-properties.d.ts",
|
|
58
|
+
"import": "./dist/esm/dom-properties.js",
|
|
59
|
+
"default": "./dist/cjs/dom-properties.js"
|
|
60
|
+
},
|
|
46
61
|
"./useClickAway": {
|
|
47
62
|
"types": "./dist/dts/useClickAway.d.ts",
|
|
48
63
|
"import": "./dist/esm/useClickAway.js",
|
|
@@ -59,9 +74,18 @@
|
|
|
59
74
|
"Anchor": [
|
|
60
75
|
"./dist/dts/Anchor.d.ts"
|
|
61
76
|
],
|
|
77
|
+
"Component": [
|
|
78
|
+
"./dist/dts/Component.d.ts"
|
|
79
|
+
],
|
|
62
80
|
"Link": [
|
|
63
81
|
"./dist/dts/Link.d.ts"
|
|
64
82
|
],
|
|
83
|
+
"Props": [
|
|
84
|
+
"./dist/dts/Props.d.ts"
|
|
85
|
+
],
|
|
86
|
+
"dom-properties": [
|
|
87
|
+
"./dist/dts/dom-properties.d.ts"
|
|
88
|
+
],
|
|
65
89
|
"useClickAway": [
|
|
66
90
|
"./dist/dts/useClickAway.d.ts"
|
|
67
91
|
],
|
package/src/Anchor.ts
CHANGED
|
@@ -2,201 +2,17 @@
|
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import type {
|
|
9
|
-
import * as EventHandler from "@typed/template/EventHandler"
|
|
10
|
-
import type { Placeholder } from "@typed/template/Placeholder"
|
|
11
|
-
import type { Renderable } from "@typed/template/Renderable"
|
|
12
|
-
import type { RenderEvent } from "@typed/template/RenderEvent"
|
|
13
|
-
import { html, type RenderTemplate } from "@typed/template/RenderTemplate"
|
|
14
|
-
import type { Rendered } from "@typed/wire"
|
|
15
|
-
import type { ReadonlyRecord, Scope } from "effect"
|
|
16
|
-
import * as Effect from "effect/Effect"
|
|
17
|
-
import { uncapitalize } from "effect/String"
|
|
18
|
-
import type { HTMLAnchorElementProperties } from "./internal/dom-properties.js"
|
|
5
|
+
import { html } from "@typed/template/RenderTemplate"
|
|
6
|
+
import type { Component } from "./Component.js"
|
|
7
|
+
import type { HTMLAnchorElementProperties } from "./dom-properties.js"
|
|
8
|
+
import type { TypedProps } from "./Props.js"
|
|
19
9
|
|
|
20
10
|
/**
|
|
21
11
|
* @since 1.0.0
|
|
22
12
|
*/
|
|
23
|
-
export type AnchorProps =
|
|
24
|
-
& {
|
|
25
|
-
readonly [K in keyof HTMLAnchorElementProperties]?:
|
|
26
|
-
| HTMLAnchorElementProperties[K]
|
|
27
|
-
| Placeholder.Any<HTMLAnchorElementProperties[K]>
|
|
28
|
-
| undefined
|
|
29
|
-
}
|
|
30
|
-
& {
|
|
31
|
-
readonly ref?: ((ref: ElementSource<HTMLAnchorElement>) => Effect.Effect<any, any, any>) | undefined
|
|
32
|
-
readonly data?: Placeholder.Any<ReadonlyRecord.ReadonlyRecord<any>> | undefined
|
|
33
|
-
}
|
|
34
|
-
& EventHandlerProps<HTMLAnchorElement>
|
|
13
|
+
export type AnchorProps = TypedProps<HTMLAnchorElementProperties, HTMLAnchorElement>
|
|
35
14
|
|
|
36
15
|
/**
|
|
37
16
|
* @since 1.0.0
|
|
38
17
|
*/
|
|
39
|
-
export
|
|
40
|
-
readonly [K in keyof EventMap as K extends string ? `on${Capitalize<K>}` : never]?:
|
|
41
|
-
| EventHandler.EventHandler<
|
|
42
|
-
any,
|
|
43
|
-
any,
|
|
44
|
-
EventWithCurrentTarget<El, Extract<EventMap[K], Event>>
|
|
45
|
-
>
|
|
46
|
-
| Effect.Effect<any, any, unknown>
|
|
47
|
-
| null
|
|
48
|
-
| undefined
|
|
49
|
-
}
|
|
50
|
-
type ReturnOf<T> = T extends (...args: any) => infer R ? R : never
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @since 1.0.0
|
|
54
|
-
*/
|
|
55
|
-
export function Anchor<
|
|
56
|
-
const Props extends AnchorProps,
|
|
57
|
-
Children extends ReadonlyArray<Renderable<any, any>> = readonly []
|
|
58
|
-
>(
|
|
59
|
-
props: Props,
|
|
60
|
-
...children: Children
|
|
61
|
-
): Fx.Fx<
|
|
62
|
-
RenderTemplate | Scope.Scope | Placeholder.Context<Props[keyof Props] | ReturnOf<Props["ref"]> | Children[number]>,
|
|
63
|
-
Placeholder.Error<Props[keyof Props] | ReturnOf<Props["ref"]> | Children[number]>,
|
|
64
|
-
RenderEvent
|
|
65
|
-
> {
|
|
66
|
-
const {
|
|
67
|
-
data,
|
|
68
|
-
hash,
|
|
69
|
-
host,
|
|
70
|
-
hostname,
|
|
71
|
-
href,
|
|
72
|
-
hreflang,
|
|
73
|
-
pathname,
|
|
74
|
-
port,
|
|
75
|
-
protocol,
|
|
76
|
-
ref,
|
|
77
|
-
scrollLeft,
|
|
78
|
-
scrollTop,
|
|
79
|
-
search,
|
|
80
|
-
...rest
|
|
81
|
-
} = props
|
|
82
|
-
|
|
83
|
-
const refDirective = Directive.ref(({ value }) =>
|
|
84
|
-
Effect.gen(function*(_) {
|
|
85
|
-
yield* _(addEventListeners(props, value))
|
|
86
|
-
|
|
87
|
-
if (ref) {
|
|
88
|
-
yield* _(ref(value as any))
|
|
89
|
-
}
|
|
90
|
-
})
|
|
91
|
-
)
|
|
92
|
-
return html`<a
|
|
93
|
-
ref="${refDirective}"
|
|
94
|
-
.props="${rest}"
|
|
95
|
-
.data="${data}"
|
|
96
|
-
.scrollLeft="${scrollLeft}"
|
|
97
|
-
.scrollTop="${scrollTop}"
|
|
98
|
-
.hash="${hash}"
|
|
99
|
-
.host="${host}"
|
|
100
|
-
.hostname="${hostname}"
|
|
101
|
-
.href="${href}"
|
|
102
|
-
.hreflang="${hreflang}"
|
|
103
|
-
.pathname="${pathname}"
|
|
104
|
-
.port="${port}"
|
|
105
|
-
.protocol="${protocol}"
|
|
106
|
-
.search="${search}"
|
|
107
|
-
>${children}</a>` as any
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* @since 1.0.0
|
|
112
|
-
*/
|
|
113
|
-
export function addEventListeners<Props extends EventHandlerProps<any>, T extends Rendered>(
|
|
114
|
-
props: Props,
|
|
115
|
-
ref: ElementSource<T>
|
|
116
|
-
): Effect.Effect<Scope.Scope | GetEventHandlersContext<Props>, never, void> {
|
|
117
|
-
return Fx.forkScoped(
|
|
118
|
-
Fx.mergeAll(
|
|
119
|
-
getEventHandlers(props).map(([type, handler]: any) => addEventListener(ref, type, handler))
|
|
120
|
-
)
|
|
121
|
-
) as any
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function addEventListener<T extends Rendered, R, E, Ev extends Event>(
|
|
125
|
-
ref: ElementSource<T>,
|
|
126
|
-
event: string,
|
|
127
|
-
handler: EventHandler.EventHandler<R, E, Ev>
|
|
128
|
-
) {
|
|
129
|
-
return Fx.mapEffect(ref.events(event as any, handler.options), (ev) => handler.handler(ev as any))
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
type ValuesOf<T> = [T[keyof T]] extends [infer R] ? R : never
|
|
133
|
-
|
|
134
|
-
type ToEventType<T> = T extends `on${infer S}` ? Uncapitalize<S> : never
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* @since 1.0.0
|
|
138
|
-
*/
|
|
139
|
-
export type GetEventHandlersContext<T extends EventHandlerProps<any>> = ValuesOf<
|
|
140
|
-
{
|
|
141
|
-
readonly [K in keyof T as K extends `on${string}` ? K : never]: EventHandler.Context<GetEventHandler<T[K]>>
|
|
142
|
-
}
|
|
143
|
-
>
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* @since 1.0.0
|
|
147
|
-
*/
|
|
148
|
-
export type GetEventHandlers<T extends EventHandlerProps<any>> = [
|
|
149
|
-
ReadonlyArray<
|
|
150
|
-
ValuesOf<
|
|
151
|
-
{
|
|
152
|
-
readonly [K in keyof T as K extends `on${string}` ? K : never]: readonly [ToEventType<K>, GetEventHandler<T[K]>]
|
|
153
|
-
}
|
|
154
|
-
>
|
|
155
|
-
>
|
|
156
|
-
] extends [ReadonlyArray<infer R>] ? ReadonlyArray<R> : never
|
|
157
|
-
|
|
158
|
-
type GetEventHandler<
|
|
159
|
-
T
|
|
160
|
-
> = T extends EventHandler.EventHandler<infer R, infer E, infer Ev> ? EventHandler.EventHandler<R, E, Ev>
|
|
161
|
-
: T extends Effect.Effect<infer R, infer E, infer _> ? EventHandler.EventHandler<R, E, Event>
|
|
162
|
-
: never
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* @since 1.0.0
|
|
166
|
-
*/
|
|
167
|
-
export function getEventHandlers<Props extends EventHandlerProps<any>>(props: Props) {
|
|
168
|
-
const eventHandlers: Array<readonly [string, EventHandler.EventHandler<any, any, any>]> = Object.keys(props).filter((
|
|
169
|
-
x
|
|
170
|
-
) => x[0] === "o" && x[1] === "n").flatMap((key) => {
|
|
171
|
-
const handler = getEventHandler(
|
|
172
|
-
props[key as keyof typeof props] as
|
|
173
|
-
| EventHandler.EventHandler<any, any, any>
|
|
174
|
-
| Effect.Effect<any, any, unknown>
|
|
175
|
-
| null
|
|
176
|
-
| undefined
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
if (!handler) return []
|
|
180
|
-
|
|
181
|
-
const eventType = uncapitalize(key.slice(2))
|
|
182
|
-
|
|
183
|
-
return [[eventType, handler] as const]
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
return eventHandlers as any as GetEventHandlers<Props>
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* @since 1.0.0
|
|
191
|
-
*/
|
|
192
|
-
export function getEventHandler<R, E, Ev extends Event = Event>(
|
|
193
|
-
handler: EventHandler.EventHandler<R, E, Ev> | Effect.Effect<R, E, unknown> | null | undefined
|
|
194
|
-
): EventHandler.EventHandler<R, E, Ev> | null {
|
|
195
|
-
if (!handler) return null
|
|
196
|
-
|
|
197
|
-
if (Effect.isEffect(handler)) {
|
|
198
|
-
return EventHandler.make(() => handler)
|
|
199
|
-
} else {
|
|
200
|
-
return handler
|
|
201
|
-
}
|
|
202
|
-
}
|
|
18
|
+
export const Anchor: Component<AnchorProps> = (props, ...children) => html`<a ...${props}>${children}</a>`
|
package/src/Component.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Fx } from "@typed/fx/Fx"
|
|
6
|
+
import type { Placeholder } from "@typed/template/Placeholder"
|
|
7
|
+
import type { Renderable } from "@typed/template/Renderable"
|
|
8
|
+
import type { RenderEvent } from "@typed/template/RenderEvent"
|
|
9
|
+
import type { RenderTemplate } from "@typed/template/RenderTemplate"
|
|
10
|
+
import type { Scope } from "effect"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
export interface Component<Props, R = never, E = never> {
|
|
16
|
+
<P extends Props, Children extends ReadonlyArray<Renderable<any, any>>>(
|
|
17
|
+
props: P,
|
|
18
|
+
...children: Children
|
|
19
|
+
): Fx<
|
|
20
|
+
R | Scope.Scope | RenderTemplate | Placeholder.Context<P[keyof P] | Children[number]>,
|
|
21
|
+
E | Placeholder.Error<P[keyof P] | Children[number]>,
|
|
22
|
+
RenderEvent
|
|
23
|
+
>
|
|
24
|
+
}
|
package/src/Link.ts
CHANGED
|
@@ -14,7 +14,8 @@ import type { RenderEvent } from "@typed/template/RenderEvent"
|
|
|
14
14
|
import type { RenderTemplate } from "@typed/template/RenderTemplate"
|
|
15
15
|
import * as Effect from "effect/Effect"
|
|
16
16
|
import type * as Scope from "effect/Scope"
|
|
17
|
-
import { Anchor, type AnchorProps
|
|
17
|
+
import { Anchor, type AnchorProps } from "./Anchor.js"
|
|
18
|
+
import { getEventHandler } from "./Props.js"
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* @since 1.0.0
|
|
@@ -31,53 +32,28 @@ export type LinkProps = Omit<AnchorProps, keyof URL> & {
|
|
|
31
32
|
* @since 1.0.0
|
|
32
33
|
*/
|
|
33
34
|
export function Link<Props extends LinkProps, Children extends ReadonlyArray<Renderable<any, any>> = readonly []>(
|
|
34
|
-
{ onClick,
|
|
35
|
+
{ onClick, relative, replace, state, to, ...props }: Props,
|
|
35
36
|
...children: Children
|
|
36
37
|
): Fx.Fx<
|
|
37
38
|
| Navigation.Navigation
|
|
38
39
|
| CurrentRoute
|
|
39
40
|
| RenderTemplate
|
|
40
41
|
| Scope.Scope
|
|
41
|
-
| Placeholder.Context<Props[keyof Props] | Children[number]
|
|
42
|
-
|
|
43
|
-
Placeholder.Error<Props[keyof Props] | Children[number]> | Fx.Error<Props[keyof Props] | Children[number]>,
|
|
42
|
+
| Placeholder.Context<Props[keyof Props] | Children[number]>,
|
|
43
|
+
Placeholder.Error<Props[keyof Props] | Children[number]>,
|
|
44
44
|
RenderEvent
|
|
45
45
|
> {
|
|
46
46
|
return Fx.gen(function*(_) {
|
|
47
47
|
const onClickHandler = getEventHandler(onClick)
|
|
48
|
-
const toRef = yield* _(
|
|
49
|
-
|
|
50
|
-
)
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
relative ?? true
|
|
54
|
-
)
|
|
55
|
-
)
|
|
56
|
-
const replaceRef = yield* _(
|
|
57
|
-
Placeholder.asRef<Placeholder.Context<Props["replace"]>, Placeholder.Error<Props["replace"]>, boolean>(
|
|
58
|
-
replace ?? false
|
|
59
|
-
)
|
|
60
|
-
)
|
|
61
|
-
const stateRef = yield* _(
|
|
62
|
-
Placeholder.asRef<Placeholder.Context<Props["state"]>, Placeholder.Error<Props["state"]>, unknown>(
|
|
63
|
-
state as Placeholder.Any<unknown>
|
|
64
|
-
)
|
|
65
|
-
)
|
|
66
|
-
const reloadDocument = yield* _(
|
|
67
|
-
Placeholder.asRef<
|
|
68
|
-
Placeholder.Context<Props["reloadDocument"]>,
|
|
69
|
-
Placeholder.Error<Props["reloadDocument"]>,
|
|
70
|
-
boolean
|
|
71
|
-
>(
|
|
72
|
-
props.reloadDocument ?? false
|
|
73
|
-
)
|
|
74
|
-
)
|
|
75
|
-
|
|
48
|
+
const toRef = yield* _(Placeholder.asRef(to))
|
|
49
|
+
const relativeRef = yield* _(Placeholder.asRef(relative ?? true))
|
|
50
|
+
const replaceRef = yield* _(Placeholder.asRef(replace ?? false))
|
|
51
|
+
const stateRef = yield* _(Placeholder.asRef(state as Placeholder.Any<unknown>))
|
|
52
|
+
const reloadDocument = yield* _(Placeholder.asRef(props.reloadDocument ?? false))
|
|
76
53
|
const href = RefSubject.mapEffect(
|
|
77
54
|
RefSubject.tuple([relativeRef, toRef]),
|
|
78
55
|
([rel, to]) => rel ? makeHref(to) : Effect.succeed(to)
|
|
79
56
|
)
|
|
80
|
-
|
|
81
57
|
const navigate = Effect.gen(function*(_) {
|
|
82
58
|
const current = yield* _(Effect.all({ replace: replaceRef, state: stateRef, reloadDocument }))
|
|
83
59
|
const url = yield* _(href)
|
|
@@ -103,11 +79,8 @@ export function Link<Props extends LinkProps, Children extends ReadonlyArray<Ren
|
|
|
103
79
|
onClickHandler?.options
|
|
104
80
|
)
|
|
105
81
|
|
|
106
|
-
const allProps = { ...props,
|
|
82
|
+
const allProps = { ...props, href, state: stateRef, onClick: onClickEventHandler }
|
|
107
83
|
|
|
108
|
-
return Anchor(
|
|
109
|
-
allProps as any as AnchorProps,
|
|
110
|
-
...children
|
|
111
|
-
)
|
|
84
|
+
return Anchor(allProps as any as Props, ...children)
|
|
112
85
|
})
|
|
113
86
|
}
|