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.
@@ -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 { root: rootProp, children, ...attrs } = props;
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 if (isString(attrValue)) {
395
- el.setAttribute(attrName, attrValue);
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) => el.setAttribute(attrName, String(value)));
410
+ attrValue.reactive((value) => setAttribute(el, attrName, value));
403
411
  } else {
404
- el.setAttribute(attrName, String(attrValue));
412
+ setAttribute(el, attrName, attrValue);
405
413
  }
406
414
  break;
407
415
  }
408
416
  }
409
- (rootProp instanceof HTMLElement ? rootProp : root).appendChild(el);
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
@@ -166,7 +166,7 @@ var $vnode = Symbol.for("jsx.vnode");
166
166
  var $setup = Symbol.for("mono.setup");
167
167
 
168
168
  // version.ts
169
- var VERSION = "0.8.0-beta.1";
169
+ var VERSION = "0.8.0-beta.3";
170
170
 
171
171
  // render.ts
172
172
  var cdn = "https://raw.esm.sh";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mono-jsx",
3
- "version": "0.8.0-beta.2",
3
+ "version": "0.8.0-beta.4",
4
4
  "description": "`<html>` as a `Response`.",
5
5
  "type": "module",
6
6
  "module": "./index.mjs",
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", "es2022"];
35
- compilerOptions.module ??= "es2022";
34
+ compilerOptions.lib ??= ["dom", "esnext"];
35
+ compilerOptions.module ??= "esnext";
36
36
  compilerOptions.moduleResolution ??= "bundler";
37
37
  compilerOptions.allowImportingTsExtensions ??= true;
38
38
  compilerOptions.noEmit ??= true;
@@ -14,4 +14,7 @@ declare global {
14
14
  // extends built-in JSX elements
15
15
  interface BuiltinElements extends Mono.Elements {}
16
16
  }
17
+ interface HTMLElement {
18
+ mount(node: VNode, aboutSignal?: AbortSignal): void;
19
+ }
17
20
  }
@@ -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 `root` attribute is used to mount the component to the DOM.
22
+ * The `portal` attribute is used to mount the component to a specified DOM element.
23
+ * @mono-jsx
23
24
  */
24
- root?: HTMLElement;
25
+ portal?: HTMLElement;
25
26
  }
26
27
 
27
28
  export interface AsyncComponentAttributes {