jsx-framework-test-pb 0.2.6 → 0.2.8
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/jsx-dev-runtime.d.ts +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/runtime/createElement.js +31 -20
- package/dist/types.d.ts +3 -2
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ export declare function jsxDEV(type: string | Function | symbol, props: ElementP
|
|
|
6
6
|
columnNumber: number;
|
|
7
7
|
}, self?: any): DevElement;
|
|
8
8
|
export declare namespace JSX {
|
|
9
|
-
type Element = import('./types').
|
|
9
|
+
type Element = import('./types').ValidElement;
|
|
10
10
|
interface IntrinsicElements extends JsxIntrinsicElements {
|
|
11
11
|
}
|
|
12
12
|
interface ElementChildrenAttribute {
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare const Fragment: symbol;
|
|
|
3
3
|
export declare function jsx(type: string | Function | symbol, props: ElementProps, key?: string): Element;
|
|
4
4
|
export declare const jsxs: typeof jsx;
|
|
5
5
|
export declare namespace JSX {
|
|
6
|
-
type Element = import('./types').
|
|
6
|
+
type Element = import('./types').ValidElement;
|
|
7
7
|
interface IntrinsicElements extends JsxIntrinsicElements {
|
|
8
8
|
}
|
|
9
9
|
interface ElementChildrenAttribute {
|
|
@@ -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) {
|
package/dist/types.d.ts
CHANGED
|
@@ -17,7 +17,8 @@ export interface ElementProps {
|
|
|
17
17
|
[key: string]: any;
|
|
18
18
|
}
|
|
19
19
|
export type ElementChild = Element | string | number | boolean | null | undefined | (() => any);
|
|
20
|
-
export type
|
|
20
|
+
export type ValidElement = Element | (() => any) | null;
|
|
21
|
+
export type FC<P = {}> = (props: P) => ValidElement;
|
|
21
22
|
export interface CSSProperties {
|
|
22
23
|
[key: string]: string | number;
|
|
23
24
|
}
|
|
@@ -346,7 +347,7 @@ export interface JsxIntrinsicElements {
|
|
|
346
347
|
}
|
|
347
348
|
declare global {
|
|
348
349
|
namespace JSX {
|
|
349
|
-
type Element = import('./types').
|
|
350
|
+
type Element = import('./types').ValidElement;
|
|
350
351
|
interface IntrinsicElements extends JsxIntrinsicElements {
|
|
351
352
|
}
|
|
352
353
|
interface ElementChildrenAttribute {
|