@tempots/dom 5.0.0 → 5.0.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/clean.d.ts +2 -0
- package/dist/clean.js +1 -0
- package/dist/components/Attribute.d.ts +15 -0
- package/dist/components/Attribute.js +16 -0
- package/dist/components/BooleanAttribute.d.ts +15 -0
- package/dist/components/BooleanAttribute.js +16 -0
- package/dist/components/ClassName.d.ts +13 -0
- package/dist/components/ClassName.js +14 -0
- package/dist/components/El.d.ts +15 -0
- package/dist/components/El.js +21 -0
- package/dist/components/FadeIn.d.ts +18 -0
- package/dist/components/FadeIn.js +52 -0
- package/dist/components/FadeOut.d.ts +16 -0
- package/dist/components/FadeOut.js +39 -0
- package/dist/components/For.d.ts +7 -0
- package/dist/components/For.js +15 -0
- package/dist/components/Fragment.d.ts +12 -0
- package/dist/components/Fragment.js +16 -0
- package/dist/components/HiddenWhenEmpty.d.ts +7 -0
- package/dist/components/HiddenWhenEmpty.js +12 -0
- package/dist/components/If.d.ts +14 -0
- package/dist/components/If.js +19 -0
- package/dist/components/InnerHTML.d.ts +13 -0
- package/dist/components/InnerHTML.js +23 -0
- package/dist/components/Lifecycle.d.ts +14 -0
- package/dist/components/Lifecycle.js +18 -0
- package/dist/components/Match.d.ts +33 -0
- package/dist/components/Match.js +44 -0
- package/dist/components/NotEmpty.d.ts +10 -0
- package/dist/components/NotEmpty.js +11 -0
- package/dist/components/On.d.ts +15 -0
- package/dist/components/On.js +14 -0
- package/dist/components/OnRemove.d.ts +11 -0
- package/dist/components/OnRemove.js +14 -0
- package/dist/components/OneOf.d.ts +20 -0
- package/dist/components/OneOf.js +45 -0
- package/dist/components/Portal.d.ts +15 -0
- package/dist/components/Portal.js +20 -0
- package/dist/components/Property.d.ts +15 -0
- package/dist/components/Property.js +16 -0
- package/dist/components/Provider.d.ts +28 -0
- package/dist/components/Provider.js +44 -0
- package/dist/components/Repeat.d.ts +15 -0
- package/dist/components/Repeat.js +33 -0
- package/dist/components/Shadow.d.ts +0 -0
- package/dist/components/Shadow.js +1 -0
- package/dist/components/Show.d.ts +20 -0
- package/dist/components/Show.js +22 -0
- package/dist/components/Text.d.ts +15 -0
- package/dist/components/Text.js +33 -0
- package/dist/components/TextContent.d.ts +13 -0
- package/dist/components/TextContent.js +23 -0
- package/dist/components/Tween.d.ts +75 -0
- package/dist/components/Tween.js +242 -0
- package/dist/components/animatable.d.ts +53 -0
- package/dist/components/animatable.js +156 -0
- package/dist/dom-context.d.ts +38 -0
- package/dist/dom-context.js +260 -0
- package/dist/helpers/handle-anchor-click.d.ts +4 -0
- package/dist/helpers/handle-anchor-click.js +43 -0
- package/dist/helpers/handle-text-input.d.ts +1 -0
- package/dist/helpers/handle-text-input.js +4 -0
- package/dist/helpers/is-empty-element.d.ts +2 -0
- package/dist/helpers/is-empty-element.js +8 -0
- package/dist/index.d.ts +36 -0
- package/dist/jsx-dev-runtime.d.ts +1 -0
- package/dist/jsx-dev-runtime.js +1 -0
- package/dist/jsx-runtime.d.ts +9 -0
- package/dist/jsx-runtime.js +157 -0
- package/dist/jsx.d.ts +806 -0
- package/dist/jsx.js +1 -0
- package/dist/prop.d.ts +43 -0
- package/dist/prop.js +174 -0
- package/dist/render.d.ts +3 -0
- package/dist/render.js +7 -0
- package/dist/renderable.d.ts +5 -0
- package/dist/renderable.js +1 -0
- package/dist/types/clean.d.ts +2 -0
- package/dist/types/clean.js +1 -0
- package/dist/types/idom-context.d.ts +27 -0
- package/dist/types/idom-context.js +3 -0
- package/dist/types/renderable.d.ts +5 -0
- package/dist/types/renderable.js +1 -0
- package/package.json +5 -1
- package/.eslintignore +0 -10
- package/.eslintrc.cjs +0 -28
- package/coverage/clover.xml +0 -39
- package/coverage/coverage-final.json +0 -2
- package/coverage/lcov-report/OneOf.ts.html +0 -256
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/dom-context.ts.html +0 -928
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -116
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/prop.ts.html +0 -691
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/components/Attribute.ts.html +0 -154
- package/coverage/lcov-report/src/components/BooleanAttribute.ts.html +0 -154
- package/coverage/lcov-report/src/components/ClassName.ts.html +0 -151
- package/coverage/lcov-report/src/components/El.ts.html +0 -166
- package/coverage/lcov-report/src/components/FadeIn.ts.html +0 -262
- package/coverage/lcov-report/src/components/FadeOut.ts.html +0 -226
- package/coverage/lcov-report/src/components/For.ts.html +0 -151
- package/coverage/lcov-report/src/components/Fragment.ts.html +0 -142
- package/coverage/lcov-report/src/components/HiddenWhenEmpty.ts.html +0 -133
- package/coverage/lcov-report/src/components/If.ts.html +0 -217
- package/coverage/lcov-report/src/components/InnerHTML.ts.html +0 -178
- package/coverage/lcov-report/src/components/Lifecycle.ts.html +0 -157
- package/coverage/lcov-report/src/components/Match.ts.html +0 -286
- package/coverage/lcov-report/src/components/NotEmpty.tsx.html +0 -184
- package/coverage/lcov-report/src/components/On.ts.html +0 -151
- package/coverage/lcov-report/src/components/OnRemove.ts.html +0 -145
- package/coverage/lcov-report/src/components/OneOf.ts.html +0 -256
- package/coverage/lcov-report/src/components/Portal.ts.html +0 -175
- package/coverage/lcov-report/src/components/Property.ts.html +0 -154
- package/coverage/lcov-report/src/components/Provider.ts.html +0 -244
- package/coverage/lcov-report/src/components/Repeat.ts.html +0 -223
- package/coverage/lcov-report/src/components/Show.tsx.html +0 -190
- package/coverage/lcov-report/src/components/Text.ts.html +0 -229
- package/coverage/lcov-report/src/components/TextContent.ts.html +0 -178
- package/coverage/lcov-report/src/components/Tween.tsx.html +0 -943
- package/coverage/lcov-report/src/components/animatable.ts.html +0 -619
- package/coverage/lcov-report/src/components/index.html +0 -476
- package/coverage/lcov-report/src/dom-context.ts.html +0 -928
- package/coverage/lcov-report/src/helpers/handle-anchor-click.ts.html +0 -277
- package/coverage/lcov-report/src/helpers/handle-text-input.ts.html +0 -100
- package/coverage/lcov-report/src/helpers/index.html +0 -146
- package/coverage/lcov-report/src/helpers/is-empty-element.ts.html +0 -112
- package/coverage/lcov-report/src/index.html +0 -176
- package/coverage/lcov-report/src/index.ts.html +0 -412
- package/coverage/lcov-report/src/jsx-runtime.ts.html +0 -601
- package/coverage/lcov-report/src/prop.ts.html +0 -691
- package/coverage/lcov-report/src/render.ts.html +0 -112
- package/coverage/lcov-report/src/types/idom-context.ts.html +0 -184
- package/coverage/lcov-report/src/types/index.html +0 -116
- package/coverage/lcov-report/test/common.ts.html +0 -112
- package/coverage/lcov-report/test/index.html +0 -116
- package/coverage/lcov.info +0 -57
- package/jest.config.js +0 -5
- package/src/clean.ts +0 -2
- package/src/components/Attribute.ts +0 -23
- package/src/components/BooleanAttribute.ts +0 -23
- package/src/components/ClassName.ts +0 -22
- package/src/components/El.ts +0 -27
- package/src/components/FadeIn.ts +0 -59
- package/src/components/FadeOut.ts +0 -47
- package/src/components/For.ts +0 -22
- package/src/components/Fragment.ts +0 -19
- package/src/components/HiddenWhenEmpty.ts +0 -16
- package/src/components/If.ts +0 -44
- package/src/components/InnerHTML.ts +0 -31
- package/src/components/Lifecycle.ts +0 -24
- package/src/components/Match.ts +0 -67
- package/src/components/NotEmpty.tsx +0 -33
- package/src/components/On.ts +0 -22
- package/src/components/OnRemove.ts +0 -20
- package/src/components/OneOf.ts +0 -57
- package/src/components/Portal.ts +0 -30
- package/src/components/Property.ts +0 -23
- package/src/components/Provider.ts +0 -53
- package/src/components/Repeat.ts +0 -46
- package/src/components/Show.tsx +0 -35
- package/src/components/Text.ts +0 -48
- package/src/components/TextContent.ts +0 -31
- package/src/components/animatable.ts +0 -178
- package/src/dom-context.ts +0 -281
- package/src/helpers/handle-anchor-click.ts +0 -64
- package/src/helpers/handle-text-input.ts +0 -5
- package/src/helpers/is-empty-element.ts +0 -9
- package/src/index.ts +0 -109
- package/src/jsx-dev-runtime.ts +0 -8
- package/src/jsx-runtime.ts +0 -172
- package/src/jsx.ts +0 -1046
- package/src/prop.ts +0 -202
- package/src/render.ts +0 -9
- package/src/renderable.ts +0 -6
- package/test/common.ts +0 -9
- package/test/component.spec.tsx +0 -27
- package/test/domcontext.spec.ts +0 -36
- package/test/fadein.spec.tsx +0 -36
- package/test/fadeout.spec.tsx +0 -41
- package/test/if.spec.tsx +0 -30
- package/test/innerhtml.spec.tsx +0 -45
- package/test/prop.spec.ts +0 -10
- package/test/render.spec.tsx +0 -19
- package/test/textcontent.spec.tsx +0 -45
- package/test/when.spec.tsx +0 -30
- package/tsconfig.json +0 -21
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
function extractClassNames(cls) {
|
|
2
|
+
return (cls ?? '').split(/\s+/g).filter((className) => className.length > 0);
|
|
3
|
+
}
|
|
4
|
+
function createIntegerSet(x) {
|
|
5
|
+
const integerSet = new Set();
|
|
6
|
+
for (let i = 0; i < x; i++) {
|
|
7
|
+
integerSet.add(i);
|
|
8
|
+
}
|
|
9
|
+
return integerSet;
|
|
10
|
+
}
|
|
11
|
+
export function makeProviderMark() {
|
|
12
|
+
return Symbol('providerMark');
|
|
13
|
+
}
|
|
14
|
+
export class DOMContext {
|
|
15
|
+
document;
|
|
16
|
+
element;
|
|
17
|
+
reference;
|
|
18
|
+
ns;
|
|
19
|
+
providers;
|
|
20
|
+
static of(element) {
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
22
|
+
return new DOMContext(element.ownerDocument, element, undefined, undefined, {});
|
|
23
|
+
}
|
|
24
|
+
constructor(document, element, reference, ns, providers) {
|
|
25
|
+
this.document = document;
|
|
26
|
+
this.element = element;
|
|
27
|
+
this.reference = reference;
|
|
28
|
+
this.ns = ns;
|
|
29
|
+
this.providers = providers;
|
|
30
|
+
}
|
|
31
|
+
append(node) {
|
|
32
|
+
if (this.reference !== undefined) {
|
|
33
|
+
try {
|
|
34
|
+
// There are components (TextContent, InnerHTML) that can mess up with the internal state of an element
|
|
35
|
+
this.element.insertBefore(node, this.reference);
|
|
36
|
+
}
|
|
37
|
+
catch (_) {
|
|
38
|
+
this.element.appendChild(node);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.element.appendChild(node);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
getElement() {
|
|
46
|
+
return this.element;
|
|
47
|
+
}
|
|
48
|
+
getDocument() {
|
|
49
|
+
return this.document;
|
|
50
|
+
}
|
|
51
|
+
makeReference() {
|
|
52
|
+
const textNode = this.document.createTextNode('');
|
|
53
|
+
this.append(textNode);
|
|
54
|
+
return new DOMContext(this.document, this.element, textNode, this.ns, this.providers);
|
|
55
|
+
}
|
|
56
|
+
makeElement(tagName) {
|
|
57
|
+
if (this.ns !== undefined || tagName === 'svg') {
|
|
58
|
+
const ns = this.ns ?? 'http://www.w3.org/2000/svg';
|
|
59
|
+
const element = this.document.createElementNS(ns, tagName);
|
|
60
|
+
this.append(element);
|
|
61
|
+
return new DOMContext(this.document, element, undefined, ns, this.providers);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const element = this.document.createElement(tagName);
|
|
65
|
+
this.append(element);
|
|
66
|
+
return new DOMContext(this.document, element, undefined, this.ns, this.providers);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
getBooleanAttribute(name) {
|
|
70
|
+
return this.element.hasAttribute(name);
|
|
71
|
+
}
|
|
72
|
+
setBooleanAttribute(name, value) {
|
|
73
|
+
if (value) {
|
|
74
|
+
this.element.setAttribute(name, '');
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this.element.removeAttribute(name);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
createBooleanAttribute(name, value) {
|
|
81
|
+
const current = this.element.hasAttribute(name);
|
|
82
|
+
this.setBooleanAttribute(name, value);
|
|
83
|
+
return [
|
|
84
|
+
(newValue) => {
|
|
85
|
+
this.setBooleanAttribute(name, newValue);
|
|
86
|
+
},
|
|
87
|
+
(removeTree) => {
|
|
88
|
+
if (removeTree) {
|
|
89
|
+
this.setBooleanAttribute(name, current);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
getAttribute(name) {
|
|
95
|
+
return this.element.getAttribute(name);
|
|
96
|
+
}
|
|
97
|
+
setAttribute(name, value) {
|
|
98
|
+
if (value == null) {
|
|
99
|
+
this.element.removeAttribute(name);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.element.setAttribute(name, value);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
createAttribute(name, value) {
|
|
106
|
+
const current = this.element.getAttribute(name);
|
|
107
|
+
this.setAttribute(name, value);
|
|
108
|
+
return [
|
|
109
|
+
(newValue) => {
|
|
110
|
+
this.setAttribute(name, newValue);
|
|
111
|
+
},
|
|
112
|
+
(removeTree) => {
|
|
113
|
+
if (removeTree) {
|
|
114
|
+
this.setAttribute(name, current);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
getProperty(name) {
|
|
120
|
+
return Reflect.get(this.element, name);
|
|
121
|
+
}
|
|
122
|
+
setProperty(name, value) {
|
|
123
|
+
if (value == null) {
|
|
124
|
+
Reflect.deleteProperty(this.element, name);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
Reflect.set(this.element, name, value);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
createProperty(name, value) {
|
|
131
|
+
const current = this.getProperty(name);
|
|
132
|
+
this.setProperty(name, value);
|
|
133
|
+
return [
|
|
134
|
+
(newValue) => {
|
|
135
|
+
this.setProperty(name, newValue);
|
|
136
|
+
},
|
|
137
|
+
(removeTree) => {
|
|
138
|
+
if (removeTree) {
|
|
139
|
+
this.setProperty(name, current);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
createText(text) {
|
|
145
|
+
const textNode = this.document.createTextNode(text);
|
|
146
|
+
this.append(textNode);
|
|
147
|
+
return [
|
|
148
|
+
(newText) => {
|
|
149
|
+
textNode.nodeValue = newText;
|
|
150
|
+
},
|
|
151
|
+
(removeTree) => {
|
|
152
|
+
if (removeTree) {
|
|
153
|
+
textNode.remove();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
createClass(cls) {
|
|
159
|
+
let current = extractClassNames(cls);
|
|
160
|
+
current.forEach((className) => {
|
|
161
|
+
this.element.classList.add(className);
|
|
162
|
+
});
|
|
163
|
+
return [
|
|
164
|
+
(newClass) => {
|
|
165
|
+
current.forEach((className) => {
|
|
166
|
+
this.element.classList.remove(className);
|
|
167
|
+
});
|
|
168
|
+
current = extractClassNames(newClass);
|
|
169
|
+
current.forEach((className) => {
|
|
170
|
+
this.element.classList.add(className);
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
(removeTree) => {
|
|
174
|
+
if (removeTree) {
|
|
175
|
+
current.forEach((className) => {
|
|
176
|
+
this.element.classList.remove(className);
|
|
177
|
+
if (this.element.classList.length === 0) {
|
|
178
|
+
this.element.removeAttribute('class');
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
createHandler(name, handler) {
|
|
186
|
+
this.element.addEventListener(name, handler);
|
|
187
|
+
return (removeTree) => {
|
|
188
|
+
if (removeTree) {
|
|
189
|
+
this.element.removeEventListener(name, handler);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
suspendedClears = [];
|
|
194
|
+
delayClear(f) {
|
|
195
|
+
this.suspendedClears.push(f);
|
|
196
|
+
return (removeTree) => {
|
|
197
|
+
// TODO nothing happens?
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
requestClear(removeTree, willClear) {
|
|
201
|
+
if (this.suspendedClears.length === 0) {
|
|
202
|
+
willClear();
|
|
203
|
+
this.clear(removeTree);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const set = createIntegerSet(this.suspendedClears.length);
|
|
207
|
+
const clearSuspended = (index) => {
|
|
208
|
+
set.delete(index);
|
|
209
|
+
if (set.size === 0) {
|
|
210
|
+
willClear();
|
|
211
|
+
this.clear(removeTree);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
this.suspendedClears.forEach((f, i) => { f(removeTree, () => { clearSuspended(i); }); });
|
|
215
|
+
this.suspendedClears.length = 0;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
clear(removeTree) {
|
|
219
|
+
if (removeTree) {
|
|
220
|
+
if (this.reference !== undefined) {
|
|
221
|
+
this.reference.parentElement?.removeChild(this.reference);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
this.element.onblur = null;
|
|
225
|
+
this.element.parentElement?.removeChild(this.element);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
withProvider(mark, provider) {
|
|
230
|
+
return new DOMContext(this.document, this.element, this.reference, this.ns, {
|
|
231
|
+
...this.providers,
|
|
232
|
+
[mark]: provider
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
getProvider(mark) {
|
|
236
|
+
return this.providers[mark];
|
|
237
|
+
}
|
|
238
|
+
setStyle(name, value) {
|
|
239
|
+
if (value == null) {
|
|
240
|
+
this.element.style.removeProperty(name);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
this.element.style.setProperty(name, value);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
createStyle(name, value) {
|
|
247
|
+
const current = this.element.style.getPropertyValue(name);
|
|
248
|
+
this.setStyle(name, value);
|
|
249
|
+
return [
|
|
250
|
+
(newValue) => {
|
|
251
|
+
this.setStyle(name, newValue);
|
|
252
|
+
},
|
|
253
|
+
(removeTree) => {
|
|
254
|
+
if (removeTree) {
|
|
255
|
+
this.setStyle(name, current);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
function shouldNotApplyCallback(e, checkExtension, checkExternalUrl) {
|
|
2
|
+
let target = e.target;
|
|
3
|
+
while ((target != null) && !(target instanceof HTMLAnchorElement)) {
|
|
4
|
+
target = target.parentElement;
|
|
5
|
+
}
|
|
6
|
+
if (target == null)
|
|
7
|
+
return true;
|
|
8
|
+
const anchor = target;
|
|
9
|
+
// Check for modifier keys and non-left-button, which indicate the user wants to control
|
|
10
|
+
// navigation
|
|
11
|
+
if (e.button !== 0 || e.ctrlKey || e.metaKey) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
// If there is a target and it is not `_self` then we take this
|
|
15
|
+
// as a signal that it doesn't want to be intercepted.
|
|
16
|
+
if (anchor.target !== '_self') {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (anchor.getAttribute('download') != null) {
|
|
20
|
+
return true; // let the download happen
|
|
21
|
+
}
|
|
22
|
+
if (checkExternalUrl) {
|
|
23
|
+
const { pathname, search, hash } = anchor;
|
|
24
|
+
const relativeUrl = pathname + search + hash;
|
|
25
|
+
// don't navigate if external link or has extension
|
|
26
|
+
if (anchor.getAttribute('href') !== relativeUrl ||
|
|
27
|
+
(checkExtension && !/\/[^/.]*$/.test(pathname))) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
export const handleAnchorClick = (callback, options = {
|
|
34
|
+
checkExtension: true,
|
|
35
|
+
checkExternalUrl: true
|
|
36
|
+
}) => (e) => {
|
|
37
|
+
const { checkExtension, checkExternalUrl } = options;
|
|
38
|
+
if (shouldNotApplyCallback(e, checkExtension === true, checkExternalUrl === true)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (callback())
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const handleTextInput: (f: (input: string) => void) => (e: Event) => void;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Clear, type Clean } from './clean';
|
|
2
|
+
import { makeProviderMark, DOMContext, type ProviderMark } from './dom-context';
|
|
3
|
+
import { Prop, Signal } from './prop';
|
|
4
|
+
import { render } from './render';
|
|
5
|
+
import { type Renderable } from './renderable';
|
|
6
|
+
import { isEmptyElement } from './helpers/is-empty-element';
|
|
7
|
+
import { handleTextInput } from './helpers/handle-text-input';
|
|
8
|
+
import { handleAnchorClick } from './helpers/handle-anchor-click';
|
|
9
|
+
import { Animatable, applyInterpolatedAnimatableProp, applyInterpolatedAnimatable, applyAnimatableProp, applyAnimatable, getComputedAnimatableProp, getComputedAnimatable } from './components/animatable';
|
|
10
|
+
import { AttributeImpl, Attribute, type AttributeProps } from './components/Attribute';
|
|
11
|
+
import { BooleanAttributeImpl, BooleanAttribute, type BooleanAttributeProps } from './components/BooleanAttribute';
|
|
12
|
+
import { ClassNameImpl, ClassName, type ClassNameProps } from './components/ClassName';
|
|
13
|
+
import { ConsumerImpl, Consumer, type ConsumerProps, ProviderImpl, Provider, type ProviderProps } from './components/Provider';
|
|
14
|
+
import { ElImpl, El, type ElProps } from './components/El';
|
|
15
|
+
import { FadeIn, FadeInImpl, FadeInProps } from './components/FadeIn';
|
|
16
|
+
import { FadeOut, FadeOutImpl, FadeOutProps } from './components/FadeOut';
|
|
17
|
+
import { For, type ForProps } from './components/For';
|
|
18
|
+
import { FragmentImpl, Fragment } from './components/Fragment';
|
|
19
|
+
import { HiddenWhenEmptyImpl, HiddenWhenEmpty } from './components/HiddenWhenEmpty';
|
|
20
|
+
import { If, type IfProps, Unless, When, type WhenProps } from './components/If';
|
|
21
|
+
import { InnerHTMLImpl, InnerHTML, type InnerHTMLProps } from './components/InnerHTML';
|
|
22
|
+
import { Lifecycle, LifecycleImpl, type LifecycleProps } from './components/Lifecycle';
|
|
23
|
+
import { MatchImpl, Match, type MatchProps } from './components/Match';
|
|
24
|
+
import { NotEmpty, type NotEmptyProps } from './components/NotEmpty';
|
|
25
|
+
import { OnImpl, On, type OnProps } from './components/On';
|
|
26
|
+
import { OnRemoveImpl, OnRemove, type OnRemoveProps } from './components/OnRemove';
|
|
27
|
+
import { OneOfImpl, OneOf, type OneOfProps } from './components/OneOf';
|
|
28
|
+
import { PortalImpl, Portal, type PortalProps } from './components/Portal';
|
|
29
|
+
import { PropertyImpl, Property, type PropertyProps } from './components/Property';
|
|
30
|
+
import { RepeatImpl, Repeat, type RepeatProps } from './components/Repeat';
|
|
31
|
+
import { ShowImpl, Show, type ShowProps } from './components/Show';
|
|
32
|
+
import { TextImpl, Text, type TextProps } from './components/Text';
|
|
33
|
+
import { TextContentImpl, TextContent, type TextContentProps } from './components/TextContent';
|
|
34
|
+
import type { JSX } from './jsx-runtime';
|
|
35
|
+
export { applyInterpolatedAnimatableProp, applyInterpolatedAnimatable, applyAnimatableProp, applyAnimatable, getComputedAnimatableProp, getComputedAnimatable, AttributeImpl, Attribute, BooleanAttributeImpl, BooleanAttribute, ClassNameImpl, ClassName, ConsumerImpl, Consumer, DOMContext, ElImpl, El, FadeIn, FadeInImpl, FadeOut, FadeOutImpl, For, FragmentImpl, Fragment, handleTextInput, handleAnchorClick, HiddenWhenEmptyImpl, HiddenWhenEmpty, If, InnerHTMLImpl, InnerHTML, isEmptyElement, Lifecycle, LifecycleImpl, makeProviderMark, MatchImpl, Match, NotEmpty, OnImpl, On, OnRemoveImpl, OnRemove, OneOfImpl, OneOf, PortalImpl, Portal, Prop, PropertyImpl, Property, ProviderImpl, Provider, render, RepeatImpl, Repeat, ShowImpl, Show, Signal, TextImpl, Text, TextContentImpl, TextContent, Unless, When };
|
|
36
|
+
export type { AttributeProps, BooleanAttributeProps, ClassNameProps, Clean, Clear, ConsumerProps, ElProps, FadeInProps, FadeOutProps, ForProps, InnerHTMLProps, IfProps, JSX, LifecycleProps, MatchProps, NotEmptyProps, OnProps, OnRemoveProps, OneOfProps, PortalProps, PropertyProps, ProviderMark, ProviderProps, Renderable, RepeatProps, ShowProps, TextProps, TextContentProps, Animatable, WhenProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Fragment, jsx, jsxs, jsxDEV, makeRenderable, makeRenderables } from './jsx-runtime';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Fragment, jsx, jsxs, jsxDEV, makeRenderable, makeRenderables } from './jsx-runtime';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type JSX } from './jsx';
|
|
2
|
+
import { type Renderable } from './renderable';
|
|
3
|
+
export declare function makeRenderables(value: any): Renderable[];
|
|
4
|
+
export declare function makeRenderable(value: any): Renderable;
|
|
5
|
+
declare function makeFragment({ children }: {
|
|
6
|
+
children: any[];
|
|
7
|
+
}): Renderable;
|
|
8
|
+
declare function makeElement(Name: any, ...args: any[]): Renderable;
|
|
9
|
+
export { makeElement as jsx, makeElement as jsxs, makeElement as jsxDEV, makeFragment as Fragment, type JSX };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { ElImpl } from './components/El';
|
|
2
|
+
import { AttributeImpl } from './components/Attribute';
|
|
3
|
+
import { BooleanAttributeImpl } from './components/BooleanAttribute';
|
|
4
|
+
import { PropertyImpl } from './components/Property';
|
|
5
|
+
import { ClassNameImpl } from './components/ClassName';
|
|
6
|
+
import { Prop, Signal } from './prop';
|
|
7
|
+
import { TextImpl } from './components/Text';
|
|
8
|
+
import { OnImpl } from './components/On';
|
|
9
|
+
import { FragmentImpl } from './components/Fragment';
|
|
10
|
+
const domBooleanAttributes = new Set([
|
|
11
|
+
'allowfullscreen',
|
|
12
|
+
'allowpaymentrequest',
|
|
13
|
+
'async',
|
|
14
|
+
'autofocus',
|
|
15
|
+
'autoplay',
|
|
16
|
+
'capture',
|
|
17
|
+
'controls',
|
|
18
|
+
'default',
|
|
19
|
+
'defer',
|
|
20
|
+
'disabled',
|
|
21
|
+
'disablepictureinpicture',
|
|
22
|
+
'disableremoteplayback',
|
|
23
|
+
'download',
|
|
24
|
+
'draggable',
|
|
25
|
+
'formnovalidate',
|
|
26
|
+
'hidden',
|
|
27
|
+
'ismap',
|
|
28
|
+
'itemscope',
|
|
29
|
+
'loop',
|
|
30
|
+
'nomodule',
|
|
31
|
+
'novalidate',
|
|
32
|
+
'open',
|
|
33
|
+
'playsinline',
|
|
34
|
+
'readonly',
|
|
35
|
+
'required',
|
|
36
|
+
'reversed',
|
|
37
|
+
'scoped',
|
|
38
|
+
'seamless',
|
|
39
|
+
'spellcheck',
|
|
40
|
+
'truespeed'
|
|
41
|
+
]);
|
|
42
|
+
const domProperties = new Set([
|
|
43
|
+
'checked',
|
|
44
|
+
'checked',
|
|
45
|
+
'classList',
|
|
46
|
+
'className',
|
|
47
|
+
'contentEditable',
|
|
48
|
+
'dataset',
|
|
49
|
+
'innerHTML',
|
|
50
|
+
'multiple',
|
|
51
|
+
'muted',
|
|
52
|
+
'scrollLeft',
|
|
53
|
+
'scrollTop',
|
|
54
|
+
'selected',
|
|
55
|
+
'style',
|
|
56
|
+
'tabIndex',
|
|
57
|
+
'textContent',
|
|
58
|
+
'value'
|
|
59
|
+
]);
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
+
function isPrimitive(value) {
|
|
62
|
+
return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint' || value instanceof Date;
|
|
63
|
+
}
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
+
export function makeRenderables(value) {
|
|
66
|
+
if (value == null) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
if (Array.isArray(value)) {
|
|
70
|
+
return value.flatMap(makeRenderables);
|
|
71
|
+
}
|
|
72
|
+
if (typeof value === 'string') {
|
|
73
|
+
return [new TextImpl(new Prop(value))];
|
|
74
|
+
}
|
|
75
|
+
if (Signal.isSignal(value)) {
|
|
76
|
+
return [new TextImpl(value)];
|
|
77
|
+
}
|
|
78
|
+
if (typeof value === 'object' && 'appendTo' in value) {
|
|
79
|
+
return [value];
|
|
80
|
+
}
|
|
81
|
+
if (isPrimitive(value)) {
|
|
82
|
+
return [new TextImpl(new Prop(value).map(String))];
|
|
83
|
+
}
|
|
84
|
+
throw new Error(`Unkwown renderable: ${String(value)}`);
|
|
85
|
+
}
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
|
+
export function makeRenderable(value) {
|
|
88
|
+
const renderables = makeRenderables(value);
|
|
89
|
+
if (renderables.length === 0) {
|
|
90
|
+
return new FragmentImpl([]);
|
|
91
|
+
}
|
|
92
|
+
if (renderables.length === 1) {
|
|
93
|
+
return renderables[0];
|
|
94
|
+
}
|
|
95
|
+
return new FragmentImpl(renderables);
|
|
96
|
+
}
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
+
function isNamedConstructor(obj) {
|
|
99
|
+
return obj.prototype?.constructor?.name != null;
|
|
100
|
+
}
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
|
+
function makeFragment({ children }) {
|
|
103
|
+
if (Array.isArray(children)) {
|
|
104
|
+
return new FragmentImpl(children.flatMap(makeRenderables));
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
return makeRenderable(children);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
111
|
+
function makeElement(Name, ...args) {
|
|
112
|
+
if (typeof Name === 'function') {
|
|
113
|
+
if (isNamedConstructor(Name)) {
|
|
114
|
+
const el = new Name(...args);
|
|
115
|
+
return el;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
const el = Name(...args);
|
|
119
|
+
return el;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const { children: untypedChildren, ...rest } = args[0] ?? {};
|
|
123
|
+
const children = [];
|
|
124
|
+
if (Array.isArray(untypedChildren)) {
|
|
125
|
+
children.push(...(untypedChildren.flatMap(makeRenderables)));
|
|
126
|
+
}
|
|
127
|
+
else if (untypedChildren !== undefined) {
|
|
128
|
+
children.push(...makeRenderables(untypedChildren));
|
|
129
|
+
}
|
|
130
|
+
for (const [key, value] of Object.entries(rest)) {
|
|
131
|
+
if (key.startsWith('on')) {
|
|
132
|
+
const eventName = key.slice(2).toLowerCase();
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
134
|
+
children.push(new OnImpl(eventName, value));
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (value == null) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const prop = isPrimitive(value) ? new Prop(value) : value;
|
|
141
|
+
if (key === 'class' || key === 'className') {
|
|
142
|
+
children.push(new ClassNameImpl(prop));
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (domProperties.has(key)) {
|
|
146
|
+
children.push(new PropertyImpl(key, prop));
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (domBooleanAttributes.has(key)) {
|
|
150
|
+
children.push(new BooleanAttributeImpl(key, prop));
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
children.push(new AttributeImpl(key, prop));
|
|
154
|
+
}
|
|
155
|
+
return new ElImpl(Name, children);
|
|
156
|
+
}
|
|
157
|
+
export { makeElement as jsx, makeElement as jsxs, makeElement as jsxDEV, makeFragment as Fragment };
|