mono-jsx 0.8.0-beta.2 → 0.8.0-beta.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/dom/jsx-runtime.mjs +17 -15
- package/jsx-runtime.mjs +1 -1
- package/package.json +1 -1
- package/setup.mjs +2 -2
- package/types/dom/jsx-runtime.d.ts +3 -0
- package/types/dom/mono.d.ts +0 -11
- package/types/jsx.d.ts +3 -2
package/dom/jsx-runtime.mjs
CHANGED
|
@@ -186,6 +186,14 @@ var isVNode = (v) => Array.isArray(v) && v.length === 3 && v[2] === $vnode;
|
|
|
186
186
|
var isReactive = (v) => v instanceof Signal || v instanceof Compute;
|
|
187
187
|
var createTextNode = (text = "") => document.createTextNode(text);
|
|
188
188
|
var onAbort = (signal, callback) => signal?.addEventListener("abort", callback);
|
|
189
|
+
var setAttribute = (el, name, value) => {
|
|
190
|
+
const type = typeof value;
|
|
191
|
+
if (type === "boolean") {
|
|
192
|
+
el.toggleAttribute(name, value);
|
|
193
|
+
} else if (type === "number" || type === "string") {
|
|
194
|
+
el.setAttribute(name, String(value));
|
|
195
|
+
}
|
|
196
|
+
};
|
|
189
197
|
var render = (scope, child, root, abortSignal) => {
|
|
190
198
|
switch (typeof child) {
|
|
191
199
|
case "boolean":
|
|
@@ -327,7 +335,7 @@ var render = (scope, child, root, abortSignal) => {
|
|
|
327
335
|
renderFC(customElements.get(tag), props, root, abortSignal);
|
|
328
336
|
break;
|
|
329
337
|
}
|
|
330
|
-
const {
|
|
338
|
+
const { portal, children, ...attrs } = props;
|
|
331
339
|
const el = document.createElement(tag);
|
|
332
340
|
for (const [attrName, attrValue] of Object.entries(attrs)) {
|
|
333
341
|
switch (attrName) {
|
|
@@ -391,22 +399,22 @@ var render = (scope, child, root, abortSignal) => {
|
|
|
391
399
|
evt.preventDefault();
|
|
392
400
|
attrValue(new FormData(evt.target), evt);
|
|
393
401
|
});
|
|
394
|
-
} else
|
|
395
|
-
|
|
402
|
+
} else {
|
|
403
|
+
setAttribute(el, attrName, attrValue);
|
|
396
404
|
}
|
|
397
405
|
break;
|
|
398
406
|
default:
|
|
399
407
|
if (attrName.startsWith("on") && isFunction(attrValue)) {
|
|
400
408
|
el.addEventListener(attrName.slice(2).toLowerCase(), attrValue);
|
|
401
409
|
} else if (isReactive(attrValue)) {
|
|
402
|
-
attrValue.reactive((value) =>
|
|
410
|
+
attrValue.reactive((value) => setAttribute(el, attrName, value));
|
|
403
411
|
} else {
|
|
404
|
-
|
|
412
|
+
setAttribute(el, attrName, attrValue);
|
|
405
413
|
}
|
|
406
414
|
break;
|
|
407
415
|
}
|
|
408
416
|
}
|
|
409
|
-
(
|
|
417
|
+
(portal instanceof HTMLElement ? portal : root).appendChild(el);
|
|
410
418
|
onAbort(abortSignal, () => el.remove());
|
|
411
419
|
if (children !== void 0) {
|
|
412
420
|
renderChildren(scope, children, el, abortSignal);
|
|
@@ -569,18 +577,9 @@ var createScope = (slots, abortSignal) => {
|
|
|
569
577
|
var Fragment = $fragment;
|
|
570
578
|
var jsx = (tag, props = new NullProtoObject(), key) => {
|
|
571
579
|
const vnode = [tag, props, $vnode];
|
|
572
|
-
const { root, abortSignal } = props;
|
|
573
580
|
if (key !== void 0) {
|
|
574
581
|
props.key = key;
|
|
575
582
|
}
|
|
576
|
-
if (tag === "mount" && root instanceof HTMLElement) {
|
|
577
|
-
render(
|
|
578
|
-
new NullProtoObject(),
|
|
579
|
-
vnode,
|
|
580
|
-
root,
|
|
581
|
-
abortSignal instanceof AbortSignal ? abortSignal : void 0
|
|
582
|
-
);
|
|
583
|
-
}
|
|
584
583
|
return vnode;
|
|
585
584
|
};
|
|
586
585
|
var jsxEscape = (value) => {
|
|
@@ -601,6 +600,9 @@ var html = (template, ...values) => [
|
|
|
601
600
|
},
|
|
602
601
|
$vnode
|
|
603
602
|
];
|
|
603
|
+
HTMLElement.prototype.mount = function(node, aboutSignal) {
|
|
604
|
+
render(new NullProtoObject(), node, this, aboutSignal);
|
|
605
|
+
};
|
|
604
606
|
Object.assign(globalThis, {
|
|
605
607
|
JSX,
|
|
606
608
|
html,
|
package/jsx-runtime.mjs
CHANGED
package/package.json
CHANGED
package/setup.mjs
CHANGED
|
@@ -31,8 +31,8 @@ async function setup() {
|
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
if (!globalThis.Deno) {
|
|
34
|
-
compilerOptions.lib ??= ["dom", "
|
|
35
|
-
compilerOptions.module ??= "
|
|
34
|
+
compilerOptions.lib ??= ["dom", "esnext"];
|
|
35
|
+
compilerOptions.module ??= "esnext";
|
|
36
36
|
compilerOptions.moduleResolution ??= "bundler";
|
|
37
37
|
compilerOptions.allowImportingTsExtensions ??= true;
|
|
38
38
|
compilerOptions.noEmit ??= true;
|
package/types/dom/mono.d.ts
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import type { BaseAttributes } from "../jsx.d.ts";
|
|
2
2
|
|
|
3
3
|
export interface Elements {
|
|
4
|
-
/**
|
|
5
|
-
* A built-in element of mono-jsx that mounts the children to the DOM.
|
|
6
|
-
* @mono-jsx
|
|
7
|
-
*/
|
|
8
|
-
mount: BaseAttributes & {
|
|
9
|
-
/**
|
|
10
|
-
* The root element to mount the children to.
|
|
11
|
-
*/
|
|
12
|
-
root: HTMLElement;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
4
|
/**
|
|
16
5
|
* A built-in element of mono-jsx that toggles the visibility of its children.
|
|
17
6
|
* @mono-jsx
|
package/types/jsx.d.ts
CHANGED
|
@@ -19,9 +19,10 @@ export interface BaseAttributes {
|
|
|
19
19
|
*/
|
|
20
20
|
slot?: string;
|
|
21
21
|
/**
|
|
22
|
-
* The `
|
|
22
|
+
* The `portal` attribute is used to mount the component to a specified DOM element.
|
|
23
|
+
* @mono-jsx
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
+
portal?: HTMLElement;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export interface AsyncComponentAttributes {
|