@praxisjs/jsx 0.3.10 → 0.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/CHANGELOG.md +26 -0
- package/dist/__tests__/jsx-runtime.types.test.d.ts +2 -0
- package/dist/__tests__/jsx-runtime.types.test.d.ts.map +1 -0
- package/dist/__tests__/jsx-runtime.types.test.js +110 -0
- package/dist/__tests__/jsx-runtime.types.test.js.map +1 -0
- package/dist/dom-types.d.ts +637 -0
- package/dist/dom-types.d.ts.map +1 -0
- package/dist/dom-types.js +2 -0
- package/dist/dom-types.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/jsx-runtime.d.ts +147 -193
- package/dist/jsx-runtime.d.ts.map +1 -1
- package/dist/jsx-runtime.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/jsx-runtime.types.test.ts +167 -0
- package/src/dom-types.ts +1015 -0
- package/src/index.ts +73 -0
- package/src/jsx-runtime.ts +295 -224
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { describe, it, expectTypeOf } from "vitest";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
Reactive,
|
|
5
|
+
ButtonHTMLAttributes,
|
|
6
|
+
InputHTMLAttributes,
|
|
7
|
+
AnchorHTMLAttributes,
|
|
8
|
+
ImgHTMLAttributes,
|
|
9
|
+
HTMLAttributes,
|
|
10
|
+
CSSProperties,
|
|
11
|
+
SVGAttributes,
|
|
12
|
+
ButtonType,
|
|
13
|
+
HTMLInputTypeAttribute,
|
|
14
|
+
LinkTarget,
|
|
15
|
+
} from "../dom-types";
|
|
16
|
+
|
|
17
|
+
describe("Reactive<T>", () => {
|
|
18
|
+
it("accepts a plain value", () => {
|
|
19
|
+
expectTypeOf<string>().toMatchTypeOf<Reactive<string>>();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("accepts a zero-arg function", () => {
|
|
23
|
+
expectTypeOf<() => string>().toMatchTypeOf<Reactive<string>>();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("rejects a plain number for Reactive<string>", () => {
|
|
27
|
+
expectTypeOf<number>().not.toMatchTypeOf<Reactive<string>>();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("LiteralUnion-based string attributes", () => {
|
|
32
|
+
it("ButtonType: literal values are assignable", () => {
|
|
33
|
+
expectTypeOf<"button">().toMatchTypeOf<ButtonType>();
|
|
34
|
+
expectTypeOf<"submit">().toMatchTypeOf<ButtonType>();
|
|
35
|
+
expectTypeOf<"reset">().toMatchTypeOf<ButtonType>();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("ButtonType: arbitrary string is assignable", () => {
|
|
39
|
+
expectTypeOf<string>().toMatchTypeOf<ButtonType>();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("HTMLInputTypeAttribute: known literals are assignable", () => {
|
|
43
|
+
expectTypeOf<"text">().toMatchTypeOf<HTMLInputTypeAttribute>();
|
|
44
|
+
expectTypeOf<"email">().toMatchTypeOf<HTMLInputTypeAttribute>();
|
|
45
|
+
expectTypeOf<"password">().toMatchTypeOf<HTMLInputTypeAttribute>();
|
|
46
|
+
expectTypeOf<"checkbox">().toMatchTypeOf<HTMLInputTypeAttribute>();
|
|
47
|
+
expectTypeOf<"radio">().toMatchTypeOf<HTMLInputTypeAttribute>();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("HTMLInputTypeAttribute: arbitrary string is assignable", () => {
|
|
51
|
+
expectTypeOf<string>().toMatchTypeOf<HTMLInputTypeAttribute>();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("LinkTarget: known literals are assignable", () => {
|
|
55
|
+
expectTypeOf<"_blank">().toMatchTypeOf<LinkTarget>();
|
|
56
|
+
expectTypeOf<"_self">().toMatchTypeOf<LinkTarget>();
|
|
57
|
+
expectTypeOf<"_parent">().toMatchTypeOf<LinkTarget>();
|
|
58
|
+
expectTypeOf<"_top">().toMatchTypeOf<LinkTarget>();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("LinkTarget: arbitrary string (e.g. frame name) is assignable", () => {
|
|
62
|
+
expectTypeOf<string>().toMatchTypeOf<LinkTarget>();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("ButtonHTMLAttributes", () => {
|
|
67
|
+
it("type prop accepts ButtonType", () => {
|
|
68
|
+
type TypeProp = ButtonHTMLAttributes["type"];
|
|
69
|
+
expectTypeOf<"button">().toMatchTypeOf<TypeProp>();
|
|
70
|
+
expectTypeOf<"submit">().toMatchTypeOf<TypeProp>();
|
|
71
|
+
expectTypeOf<"reset">().toMatchTypeOf<TypeProp>();
|
|
72
|
+
expectTypeOf<string>().toMatchTypeOf<TypeProp>();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("type prop is reactive", () => {
|
|
76
|
+
type TypeProp = NonNullable<ButtonHTMLAttributes["type"]>;
|
|
77
|
+
expectTypeOf<() => "button">().toMatchTypeOf<TypeProp>();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("disabled prop is reactive boolean", () => {
|
|
81
|
+
type DisabledProp = NonNullable<ButtonHTMLAttributes["disabled"]>;
|
|
82
|
+
expectTypeOf<true>().toMatchTypeOf<DisabledProp>();
|
|
83
|
+
expectTypeOf<() => boolean>().toMatchTypeOf<DisabledProp>();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("class prop accepts reactive string", () => {
|
|
87
|
+
type ClassProp = NonNullable<ButtonHTMLAttributes["class"]>;
|
|
88
|
+
expectTypeOf<string>().toMatchTypeOf<ClassProp>();
|
|
89
|
+
expectTypeOf<() => string>().toMatchTypeOf<ClassProp>();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("onClick receives MouseEvent with currentTarget HTMLButtonElement", () => {
|
|
93
|
+
type Handler = NonNullable<
|
|
94
|
+
ButtonHTMLAttributes<HTMLButtonElement>["onClick"]
|
|
95
|
+
>;
|
|
96
|
+
type Evt = Parameters<Handler>[0];
|
|
97
|
+
expectTypeOf<HTMLButtonElement>().toMatchTypeOf<Evt["currentTarget"]>();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("InputHTMLAttributes", () => {
|
|
102
|
+
it("type prop accepts HTMLInputTypeAttribute", () => {
|
|
103
|
+
type TypeProp = NonNullable<InputHTMLAttributes["type"]>;
|
|
104
|
+
expectTypeOf<"email">().toMatchTypeOf<TypeProp>();
|
|
105
|
+
expectTypeOf<string>().toMatchTypeOf<TypeProp>();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("ref prop receives HTMLInputElement", () => {
|
|
109
|
+
type RefProp = NonNullable<InputHTMLAttributes<HTMLInputElement>["ref"]>;
|
|
110
|
+
type Param = Parameters<RefProp>[0];
|
|
111
|
+
expectTypeOf<HTMLInputElement>().toMatchTypeOf<Param>();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("AnchorHTMLAttributes", () => {
|
|
116
|
+
it("target accepts LinkTarget (literals and arbitrary strings)", () => {
|
|
117
|
+
type TargetProp = NonNullable<AnchorHTMLAttributes["target"]>;
|
|
118
|
+
expectTypeOf<"_blank">().toMatchTypeOf<TargetProp>();
|
|
119
|
+
expectTypeOf<string>().toMatchTypeOf<TargetProp>();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe("ImgHTMLAttributes", () => {
|
|
124
|
+
it("ref prop receives HTMLImageElement", () => {
|
|
125
|
+
type RefProp = NonNullable<ImgHTMLAttributes<HTMLImageElement>["ref"]>;
|
|
126
|
+
type Param = Parameters<RefProp>[0];
|
|
127
|
+
expectTypeOf<HTMLImageElement>().toMatchTypeOf<Param>();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe("HTMLAttributes", () => {
|
|
132
|
+
it("style accepts a plain string", () => {
|
|
133
|
+
type StyleProp = NonNullable<HTMLAttributes["style"]>;
|
|
134
|
+
expectTypeOf<string>().toMatchTypeOf<StyleProp>();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("style accepts a CSSProperties object", () => {
|
|
138
|
+
type StyleProp = NonNullable<HTMLAttributes["style"]>;
|
|
139
|
+
expectTypeOf<CSSProperties>().toMatchTypeOf<StyleProp>();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("style accepts a reactive CSSProperties function", () => {
|
|
143
|
+
type StyleProp = NonNullable<HTMLAttributes["style"]>;
|
|
144
|
+
expectTypeOf<() => CSSProperties>().toMatchTypeOf<StyleProp>();
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("CSSProperties", () => {
|
|
149
|
+
it("accepts CSS custom properties", () => {
|
|
150
|
+
const props: CSSProperties = { "--brand-color": "#f00" };
|
|
151
|
+
expectTypeOf(props).toMatchTypeOf<CSSProperties>();
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("SVGAttributes", () => {
|
|
156
|
+
it("fill prop is reactive string", () => {
|
|
157
|
+
type FillProp = NonNullable<SVGAttributes["fill"]>;
|
|
158
|
+
expectTypeOf<string>().toMatchTypeOf<FillProp>();
|
|
159
|
+
expectTypeOf<() => string>().toMatchTypeOf<FillProp>();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("onClick receives MouseEvent with SVGElement currentTarget", () => {
|
|
163
|
+
type Handler = NonNullable<SVGAttributes<SVGCircleElement>["onClick"]>;
|
|
164
|
+
type Evt = Parameters<Handler>[0];
|
|
165
|
+
expectTypeOf<SVGCircleElement>().toMatchTypeOf<Evt["currentTarget"]>();
|
|
166
|
+
});
|
|
167
|
+
});
|