mini-jsx-test-pb 0.1.4 → 0.1.6

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.
@@ -2,23 +2,39 @@ import {
2
2
  effect
3
3
  } from "./chunk-DIUGWQ3J.js";
4
4
 
5
+ // src/jsx/anchor.ts
6
+ function createAnchor(parent) {
7
+ const anchor = document.createComment("jsx");
8
+ parent.appendChild(anchor);
9
+ return anchor;
10
+ }
11
+
5
12
  // src/jsx/mount.ts
6
- function mountChild(parent, child) {
7
- if (child == null || child === true || child === false) return;
8
- if (Array.isArray(child)) {
9
- for (const c of child) mountChild(parent, c);
10
- return;
13
+ function normalize(value) {
14
+ if (value == null || value === true || value === false) return [];
15
+ if (Array.isArray(value)) {
16
+ return value.flatMap(normalize);
11
17
  }
12
- if (child instanceof Node) {
13
- parent.appendChild(child);
14
- return;
18
+ if (value instanceof Node) return [value];
19
+ return [document.createTextNode(String(value))];
20
+ }
21
+ function removeNodes(nodes) {
22
+ for (const n of nodes) {
23
+ n.parentNode?.removeChild(n);
15
24
  }
25
+ }
26
+ function mountChild(parent, child) {
16
27
  if (typeof child === "function") {
17
- const text = document.createTextNode("");
18
- parent.appendChild(text);
28
+ const anchor = createAnchor(parent);
29
+ let mounted = [];
19
30
  effect(() => {
20
- const v = child();
21
- text.nodeValue = v == null ? "" : String(v);
31
+ const value = child();
32
+ const next = normalize(value);
33
+ removeNodes(mounted);
34
+ for (const n of next) {
35
+ parent.insertBefore(n, anchor);
36
+ }
37
+ mounted = next;
22
38
  });
23
39
  return;
24
40
  }
@@ -26,7 +42,9 @@ function mountChild(parent, child) {
26
42
  mountChild(parent, () => child.val);
27
43
  return;
28
44
  }
29
- parent.appendChild(document.createTextNode(String(child)));
45
+ for (const node of normalize(child)) {
46
+ parent.appendChild(node);
47
+ }
30
48
  }
31
49
 
32
50
  // src/jsx/jsx.ts
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  h
3
- } from "../chunk-VFKTCWRG.js";
4
- import "../chunk-DIUGWQ3J.js";
3
+ } from "./chunk-46TBOZKD.js";
4
+ import "./chunk-DIUGWQ3J.js";
5
5
 
6
6
  // src/jsx/jsx-dev-runtime.ts
7
7
  function jsxDEV(type, props) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  h
3
- } from "../chunk-VFKTCWRG.js";
4
- import "../chunk-DIUGWQ3J.js";
3
+ } from "./chunk-46TBOZKD.js";
4
+ import "./chunk-DIUGWQ3J.js";
5
5
 
6
6
  // src/jsx/jsx-runtime.ts
7
7
  function jsx(type, props) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mini-jsx-test-pb",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "dist"
24
24
  ],
25
25
  "scripts": {
26
- "build": "tsup src/index.ts src/jsx/jsx-runtime.ts src/jsx/jsx-dev-runtime.ts --format esm --dts",
26
+ "build": "tsup src/index.ts src/jsx-runtime.ts src/jsx-dev-runtime.ts --format esm --dts",
27
27
  "dev": "tsup src/index.ts --format esm --dts --watch"
28
28
  },
29
29
  "devDependencies": {
File without changes