@wsxjs/wsx-core 0.0.9 → 0.0.10
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/index.js +15 -9
- package/dist/index.mjs +15 -9
- package/package.json +1 -1
- package/src/base-component.ts +33 -16
package/dist/index.js
CHANGED
|
@@ -654,20 +654,26 @@ var BaseComponent = class extends HTMLElement {
|
|
|
654
654
|
return;
|
|
655
655
|
}
|
|
656
656
|
const root = this.getActiveRoot();
|
|
657
|
-
let
|
|
657
|
+
let activeElement = null;
|
|
658
658
|
if (root instanceof ShadowRoot) {
|
|
659
|
-
|
|
659
|
+
activeElement = root.activeElement;
|
|
660
660
|
} else {
|
|
661
661
|
const docActiveElement = document.activeElement;
|
|
662
|
-
|
|
662
|
+
if (docActiveElement && root.contains(docActiveElement)) {
|
|
663
|
+
activeElement = docActiveElement;
|
|
664
|
+
}
|
|
663
665
|
}
|
|
664
|
-
if (
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
this.
|
|
666
|
+
if (activeElement) {
|
|
667
|
+
const isInputElement = activeElement instanceof HTMLInputElement || activeElement instanceof HTMLTextAreaElement || activeElement instanceof HTMLSelectElement || activeElement.hasAttribute("contenteditable");
|
|
668
|
+
const forceRender = activeElement.hasAttribute("data-wsx-force-render");
|
|
669
|
+
if (isInputElement && !forceRender) {
|
|
670
|
+
this._pendingRerender = true;
|
|
671
|
+
if (this._rerenderDebounceTimer !== null) {
|
|
672
|
+
clearTimeout(this._rerenderDebounceTimer);
|
|
673
|
+
this._rerenderDebounceTimer = null;
|
|
674
|
+
}
|
|
675
|
+
return;
|
|
669
676
|
}
|
|
670
|
-
return;
|
|
671
677
|
}
|
|
672
678
|
if (this._pendingRerender) {
|
|
673
679
|
this._pendingRerender = false;
|
package/dist/index.mjs
CHANGED
|
@@ -421,20 +421,26 @@ var BaseComponent = class extends HTMLElement {
|
|
|
421
421
|
return;
|
|
422
422
|
}
|
|
423
423
|
const root = this.getActiveRoot();
|
|
424
|
-
let
|
|
424
|
+
let activeElement = null;
|
|
425
425
|
if (root instanceof ShadowRoot) {
|
|
426
|
-
|
|
426
|
+
activeElement = root.activeElement;
|
|
427
427
|
} else {
|
|
428
428
|
const docActiveElement = document.activeElement;
|
|
429
|
-
|
|
429
|
+
if (docActiveElement && root.contains(docActiveElement)) {
|
|
430
|
+
activeElement = docActiveElement;
|
|
431
|
+
}
|
|
430
432
|
}
|
|
431
|
-
if (
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
this.
|
|
433
|
+
if (activeElement) {
|
|
434
|
+
const isInputElement = activeElement instanceof HTMLInputElement || activeElement instanceof HTMLTextAreaElement || activeElement instanceof HTMLSelectElement || activeElement.hasAttribute("contenteditable");
|
|
435
|
+
const forceRender = activeElement.hasAttribute("data-wsx-force-render");
|
|
436
|
+
if (isInputElement && !forceRender) {
|
|
437
|
+
this._pendingRerender = true;
|
|
438
|
+
if (this._rerenderDebounceTimer !== null) {
|
|
439
|
+
clearTimeout(this._rerenderDebounceTimer);
|
|
440
|
+
this._rerenderDebounceTimer = null;
|
|
441
|
+
}
|
|
442
|
+
return;
|
|
436
443
|
}
|
|
437
|
-
return;
|
|
438
444
|
}
|
|
439
445
|
if (this._pendingRerender) {
|
|
440
446
|
this._pendingRerender = false;
|
package/package.json
CHANGED
package/src/base-component.ts
CHANGED
|
@@ -229,31 +229,48 @@ export abstract class BaseComponent extends HTMLElement {
|
|
|
229
229
|
return;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
//
|
|
232
|
+
// 检查是否有需要持续输入的元素获得焦点(input、textarea、select、contenteditable)
|
|
233
|
+
// 按钮等其他元素应该立即重渲染,以反映状态变化
|
|
233
234
|
const root = this.getActiveRoot();
|
|
234
|
-
let
|
|
235
|
+
let activeElement: HTMLElement | null = null;
|
|
235
236
|
|
|
236
237
|
if (root instanceof ShadowRoot) {
|
|
237
|
-
|
|
238
|
+
activeElement = root.activeElement as HTMLElement | null;
|
|
238
239
|
} else {
|
|
239
240
|
const docActiveElement = document.activeElement;
|
|
240
|
-
|
|
241
|
+
if (docActiveElement && root.contains(docActiveElement)) {
|
|
242
|
+
activeElement = docActiveElement as HTMLElement;
|
|
243
|
+
}
|
|
241
244
|
}
|
|
242
245
|
|
|
243
|
-
//
|
|
244
|
-
//
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
246
|
+
// 只对需要持续输入的元素跳过重渲染(input、textarea、select、contenteditable)
|
|
247
|
+
// 按钮等其他元素应该立即重渲染
|
|
248
|
+
// 如果元素有 data-wsx-force-render 属性,即使是要持续输入的元素也强制重渲染
|
|
249
|
+
if (activeElement) {
|
|
250
|
+
const isInputElement =
|
|
251
|
+
activeElement instanceof HTMLInputElement ||
|
|
252
|
+
activeElement instanceof HTMLTextAreaElement ||
|
|
253
|
+
activeElement instanceof HTMLSelectElement ||
|
|
254
|
+
activeElement.hasAttribute("contenteditable");
|
|
255
|
+
|
|
256
|
+
// 检查是否有强制渲染属性
|
|
257
|
+
const forceRender = activeElement.hasAttribute("data-wsx-force-render");
|
|
258
|
+
|
|
259
|
+
// 如果是输入元素且没有强制渲染属性,跳过重渲染,等待 blur 事件
|
|
260
|
+
if (isInputElement && !forceRender) {
|
|
261
|
+
// 标记需要重渲染,但延迟到 blur 事件
|
|
262
|
+
this._pendingRerender = true;
|
|
263
|
+
|
|
264
|
+
// 清除之前的定时器(不再使用定时器,只等待 blur)
|
|
265
|
+
if (this._rerenderDebounceTimer !== null) {
|
|
266
|
+
clearTimeout(this._rerenderDebounceTimer);
|
|
267
|
+
this._rerenderDebounceTimer = null;
|
|
268
|
+
}
|
|
248
269
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
clearTimeout(this._rerenderDebounceTimer);
|
|
252
|
-
this._rerenderDebounceTimer = null;
|
|
270
|
+
// 不执行重渲染,等待 blur 事件
|
|
271
|
+
return;
|
|
253
272
|
}
|
|
254
|
-
|
|
255
|
-
// 不执行重渲染,等待 blur 事件
|
|
256
|
-
return;
|
|
273
|
+
// 对于按钮等其他元素,或者有 data-wsx-force-render 属性的输入元素,继续执行重渲染(不跳过)
|
|
257
274
|
}
|
|
258
275
|
|
|
259
276
|
// 没有焦点元素,立即重渲染(使用 queueMicrotask 批量处理)
|