@wsxjs/wsx-core 0.0.26 → 0.0.27
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/chunk-DYG2LIOG.mjs +1315 -0
- package/dist/chunk-VCL7OXC6.mjs +1282 -0
- package/dist/chunk-WDQYPG2N.mjs +1315 -0
- package/dist/index.js +60 -2
- package/dist/index.mjs +1 -1
- package/dist/jsx-runtime.js +60 -2
- package/dist/jsx-runtime.mjs +1 -1
- package/dist/jsx.js +60 -2
- package/dist/jsx.mjs +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/utils/element-creation.ts +32 -1
- package/src/utils/element-update.ts +52 -1
|
@@ -19,7 +19,9 @@ function applySingleProp(
|
|
|
19
19
|
tag: string,
|
|
20
20
|
isSVG: boolean
|
|
21
21
|
): void {
|
|
22
|
-
|
|
22
|
+
// 关键修复:不要在这里提前返回 false,因为布尔属性 false 需要特殊处理(移除属性)
|
|
23
|
+
// 只对 null 和 undefined 提前返回
|
|
24
|
+
if (value === null || value === undefined) {
|
|
23
25
|
return;
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -61,6 +63,35 @@ function applySingleProp(
|
|
|
61
63
|
if (typeof value === "boolean") {
|
|
62
64
|
if (value) {
|
|
63
65
|
element.setAttribute(key, "");
|
|
66
|
+
// 对于 input 元素,同时设置 JavaScript 属性
|
|
67
|
+
if (element instanceof HTMLInputElement) {
|
|
68
|
+
if (key === "checked") {
|
|
69
|
+
element.checked = true;
|
|
70
|
+
} else if (key === "disabled") {
|
|
71
|
+
element.disabled = true;
|
|
72
|
+
} else if (key === "readonly") {
|
|
73
|
+
element.readOnly = true; // 注意:JavaScript 属性是 readOnly(驼峰)
|
|
74
|
+
}
|
|
75
|
+
} else if (element instanceof HTMLOptionElement && key === "selected") {
|
|
76
|
+
element.selected = true;
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
// 关键修复:当布尔属性为 false 时,应该移除属性
|
|
80
|
+
// 这样可以确保元素状态正确更新(例如:radio button 取消选择时移除 checked 属性)
|
|
81
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
82
|
+
element.removeAttribute(attributeName);
|
|
83
|
+
// 对于 input 元素,同时设置 JavaScript 属性为 false
|
|
84
|
+
if (element instanceof HTMLInputElement) {
|
|
85
|
+
if (key === "checked") {
|
|
86
|
+
element.checked = false;
|
|
87
|
+
} else if (key === "disabled") {
|
|
88
|
+
element.disabled = false;
|
|
89
|
+
} else if (key === "readonly") {
|
|
90
|
+
element.readOnly = false; // 注意:JavaScript 属性是 readOnly(驼峰)
|
|
91
|
+
}
|
|
92
|
+
} else if (element instanceof HTMLOptionElement && key === "selected") {
|
|
93
|
+
element.selected = false;
|
|
94
|
+
}
|
|
64
95
|
}
|
|
65
96
|
return;
|
|
66
97
|
}
|
|
@@ -124,7 +124,9 @@ function applySingleProp(
|
|
|
124
124
|
tag: string,
|
|
125
125
|
isSVG: boolean
|
|
126
126
|
): void {
|
|
127
|
-
|
|
127
|
+
// 关键修复:不要在这里提前返回 false,因为布尔属性 false 需要特殊处理(移除属性)
|
|
128
|
+
// 只对 null 和 undefined 提前返回
|
|
129
|
+
if (value === null || value === undefined) {
|
|
128
130
|
return;
|
|
129
131
|
}
|
|
130
132
|
|
|
@@ -175,6 +177,35 @@ function applySingleProp(
|
|
|
175
177
|
if (typeof value === "boolean") {
|
|
176
178
|
if (value) {
|
|
177
179
|
element.setAttribute(key, "");
|
|
180
|
+
// 对于 input 元素,同时设置 JavaScript 属性
|
|
181
|
+
if (element instanceof HTMLInputElement) {
|
|
182
|
+
if (key === "checked") {
|
|
183
|
+
element.checked = true;
|
|
184
|
+
} else if (key === "disabled") {
|
|
185
|
+
element.disabled = true;
|
|
186
|
+
} else if (key === "readonly") {
|
|
187
|
+
element.readOnly = true; // 注意:JavaScript 属性是 readOnly(驼峰)
|
|
188
|
+
}
|
|
189
|
+
} else if (element instanceof HTMLOptionElement && key === "selected") {
|
|
190
|
+
element.selected = true;
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
// 关键修复:当布尔属性为 false 时,应该移除属性
|
|
194
|
+
// 这样可以确保元素状态正确更新(例如:radio button 取消选择时移除 checked 属性)
|
|
195
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
196
|
+
element.removeAttribute(attributeName);
|
|
197
|
+
// 对于 input 元素,同时设置 JavaScript 属性为 false
|
|
198
|
+
if (element instanceof HTMLInputElement) {
|
|
199
|
+
if (key === "checked") {
|
|
200
|
+
element.checked = false;
|
|
201
|
+
} else if (key === "disabled") {
|
|
202
|
+
element.disabled = false;
|
|
203
|
+
} else if (key === "readonly") {
|
|
204
|
+
element.readOnly = false; // 注意:JavaScript 属性是 readOnly(驼峰)
|
|
205
|
+
}
|
|
206
|
+
} else if (element instanceof HTMLOptionElement && key === "selected") {
|
|
207
|
+
element.selected = false;
|
|
208
|
+
}
|
|
178
209
|
}
|
|
179
210
|
return;
|
|
180
211
|
}
|
|
@@ -367,6 +398,26 @@ export function updateChildren(
|
|
|
367
398
|
// 即使不需要更新,也要标记为已处理(文本节点已存在且内容正确)
|
|
368
399
|
if (oldNode && oldNode.parentNode === element) {
|
|
369
400
|
processedNodes.add(oldNode);
|
|
401
|
+
} else if (!oldNode && oldText === newText) {
|
|
402
|
+
// 关键修复:如果 oldNode 为 null 但 oldText === newText,
|
|
403
|
+
// 说明 DOM 中可能已经存在一个匹配的文本节点,只是没有被 findTextNode 找到
|
|
404
|
+
// 我们需要查找并标记它,避免在清理阶段被误删
|
|
405
|
+
// 这种情况可能发生在文本节点和元素节点混合排列时,domIndex 位置不准确
|
|
406
|
+
// 从 domIndex.value 开始搜索,因为这是 findTextNode 停止的位置
|
|
407
|
+
// 这样可以更准确地找到对应的文本节点
|
|
408
|
+
for (let j = domIndex.value; j < element.childNodes.length; j++) {
|
|
409
|
+
const node = element.childNodes[j];
|
|
410
|
+
if (
|
|
411
|
+
node.nodeType === Node.TEXT_NODE &&
|
|
412
|
+
node.parentNode === element &&
|
|
413
|
+
node.textContent === newText &&
|
|
414
|
+
!processedNodes.has(node)
|
|
415
|
+
) {
|
|
416
|
+
// 找到匹配的文本节点,标记为已处理
|
|
417
|
+
processedNodes.add(node);
|
|
418
|
+
break; // 只标记第一个匹配的节点
|
|
419
|
+
}
|
|
420
|
+
}
|
|
370
421
|
}
|
|
371
422
|
}
|
|
372
423
|
} else {
|