jsx-framework-test-pb 0.2.6 → 0.2.7
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/runtime/createElement.js +31 -20
- package/package.json +1 -1
|
@@ -49,48 +49,59 @@ export function createElement(element) {
|
|
|
49
49
|
function createReactiveChild(fn) {
|
|
50
50
|
// Use an empty text node as a stable anchor point (invisible in DOM)
|
|
51
51
|
const anchor = document.createTextNode('');
|
|
52
|
-
|
|
52
|
+
// Track actual inserted nodes (not the DocumentFragment which empties on insert)
|
|
53
|
+
let currentNodes = [];
|
|
53
54
|
let isFirstRun = true;
|
|
54
55
|
const cleanup = effect(() => {
|
|
55
56
|
const value = fn();
|
|
56
|
-
// Clean up previous
|
|
57
|
-
if (!isFirstRun
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
// Clean up previous nodes (skip on first run)
|
|
58
|
+
if (!isFirstRun) {
|
|
59
|
+
currentNodes.forEach(node => {
|
|
60
|
+
cleanupTree(node);
|
|
61
|
+
node.parentNode?.removeChild(node);
|
|
62
|
+
});
|
|
63
|
+
currentNodes = [];
|
|
61
64
|
}
|
|
62
65
|
// Handle different return types
|
|
66
|
+
let newNode = null;
|
|
63
67
|
if (value == null || value === false) {
|
|
64
|
-
|
|
68
|
+
newNode = null;
|
|
65
69
|
}
|
|
66
70
|
else if (typeof value === 'string' || typeof value === 'number') {
|
|
67
|
-
|
|
71
|
+
newNode = document.createTextNode(String(value));
|
|
68
72
|
}
|
|
69
73
|
else if (isElement(value) || Array.isArray(value)) {
|
|
70
|
-
|
|
74
|
+
newNode = createElement(value);
|
|
71
75
|
}
|
|
72
76
|
else {
|
|
73
|
-
|
|
77
|
+
newNode = document.createTextNode(String(value));
|
|
78
|
+
}
|
|
79
|
+
// Track the actual nodes before a DocumentFragment empties on insertion
|
|
80
|
+
if (newNode) {
|
|
81
|
+
if (newNode instanceof DocumentFragment) {
|
|
82
|
+
currentNodes = Array.from(newNode.childNodes);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
currentNodes = [newNode];
|
|
86
|
+
}
|
|
74
87
|
}
|
|
75
88
|
// Insert new node after anchor (skip on first run - handled by fragment)
|
|
76
|
-
if (!isFirstRun &&
|
|
77
|
-
anchor.parentNode.insertBefore(
|
|
89
|
+
if (!isFirstRun && newNode && anchor.parentNode) {
|
|
90
|
+
anchor.parentNode.insertBefore(newNode, anchor.nextSibling);
|
|
78
91
|
}
|
|
79
92
|
isFirstRun = false;
|
|
80
93
|
});
|
|
81
94
|
trackCleanup(anchor, () => {
|
|
82
95
|
cleanup();
|
|
83
|
-
|
|
84
|
-
cleanupTree(
|
|
85
|
-
|
|
86
|
-
}
|
|
96
|
+
currentNodes.forEach(node => {
|
|
97
|
+
cleanupTree(node);
|
|
98
|
+
node.parentNode?.removeChild(node);
|
|
99
|
+
});
|
|
87
100
|
});
|
|
88
|
-
// Return fragment with anchor and initial
|
|
101
|
+
// Return fragment with anchor and initial nodes
|
|
89
102
|
const fragment = document.createDocumentFragment();
|
|
90
103
|
fragment.appendChild(anchor);
|
|
91
|
-
|
|
92
|
-
fragment.appendChild(currentNode);
|
|
93
|
-
}
|
|
104
|
+
currentNodes.forEach(node => fragment.appendChild(node));
|
|
94
105
|
return fragment;
|
|
95
106
|
}
|
|
96
107
|
function cleanupTree(node) {
|