@lvce-editor/virtual-dom 1.6.0 → 1.7.0
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
CHANGED
|
@@ -520,7 +520,10 @@ var rememberFocus = ($Viewlet, dom, eventMap, uid = 0) => {
|
|
|
520
520
|
const oldTop = $Viewlet.style.top;
|
|
521
521
|
const oldWidth = $Viewlet.style.width;
|
|
522
522
|
const oldHeight = $Viewlet.style.height;
|
|
523
|
-
const
|
|
523
|
+
const activeElement = document.activeElement;
|
|
524
|
+
const isTreeFocused = activeElement?.getAttribute("role") === "tree";
|
|
525
|
+
const isRootTree = $Viewlet.getAttribute("role") === "tree" && activeElement === $Viewlet;
|
|
526
|
+
const focused = activeElement?.getAttribute("name");
|
|
524
527
|
const $$Inputs = queryInputs($Viewlet);
|
|
525
528
|
const inputMap = /* @__PURE__ */ Object.create(null);
|
|
526
529
|
for (const $Input of $$Inputs) {
|
|
@@ -539,7 +542,14 @@ var rememberFocus = ($Viewlet, dom, eventMap, uid = 0) => {
|
|
|
539
542
|
for (const $Input of $$NewInputs) {
|
|
540
543
|
$Input.value = inputMap[$Input.name] || $Input.value || "";
|
|
541
544
|
}
|
|
542
|
-
if (
|
|
545
|
+
if (isRootTree) {
|
|
546
|
+
$Viewlet.focus();
|
|
547
|
+
} else if (isTreeFocused) {
|
|
548
|
+
const $Tree = $Viewlet.querySelector('[role="tree"]');
|
|
549
|
+
if ($Tree) {
|
|
550
|
+
$Tree.focus();
|
|
551
|
+
}
|
|
552
|
+
} else if (focused) {
|
|
543
553
|
const $Focused = $Viewlet.querySelector(`[name="${focused}"]`);
|
|
544
554
|
if ($Focused) {
|
|
545
555
|
$Focused.focus();
|
package/package.json
CHANGED
|
@@ -12,20 +12,25 @@ export const rememberFocus = (
|
|
|
12
12
|
eventMap: any,
|
|
13
13
|
uid = 0,
|
|
14
14
|
) => {
|
|
15
|
-
// TODO replace this workaround with
|
|
16
|
-
// virtual dom diffing
|
|
17
15
|
const oldLeft = $Viewlet.style.left
|
|
18
16
|
const oldTop = $Viewlet.style.top
|
|
19
17
|
const oldWidth = $Viewlet.style.width
|
|
20
18
|
const oldHeight = $Viewlet.style.height
|
|
21
|
-
|
|
22
|
-
const
|
|
19
|
+
|
|
20
|
+
const activeElement = document.activeElement
|
|
21
|
+
const isTreeFocused = activeElement?.getAttribute('role') === 'tree'
|
|
22
|
+
const isRootTree =
|
|
23
|
+
$Viewlet.getAttribute('role') === 'tree' && activeElement === $Viewlet
|
|
24
|
+
|
|
25
|
+
const focused = activeElement?.getAttribute('name')
|
|
26
|
+
|
|
23
27
|
const $$Inputs = queryInputs($Viewlet)
|
|
24
28
|
const inputMap = Object.create(null)
|
|
25
29
|
for (const $Input of $$Inputs) {
|
|
26
30
|
// @ts-ignore
|
|
27
31
|
inputMap[$Input.name] = $Input.value
|
|
28
32
|
}
|
|
33
|
+
|
|
29
34
|
if (uid) {
|
|
30
35
|
const newEventMap = RegisterEventListeners.getEventListenerMap(uid)
|
|
31
36
|
const $New = VirtualDom.render(dom, eventMap, newEventMap).firstChild
|
|
@@ -37,12 +42,22 @@ export const rememberFocus = (
|
|
|
37
42
|
} else {
|
|
38
43
|
VirtualDom.renderInto($Viewlet, dom, eventMap)
|
|
39
44
|
}
|
|
45
|
+
|
|
40
46
|
const $$NewInputs = queryInputs($Viewlet)
|
|
41
47
|
for (const $Input of $$NewInputs) {
|
|
42
48
|
// @ts-ignore
|
|
43
49
|
$Input.value = inputMap[$Input.name] || $Input.value || ''
|
|
44
50
|
}
|
|
45
|
-
|
|
51
|
+
|
|
52
|
+
if (isRootTree) {
|
|
53
|
+
$Viewlet.focus()
|
|
54
|
+
} else if (isTreeFocused) {
|
|
55
|
+
const $Tree = $Viewlet.querySelector('[role="tree"]')
|
|
56
|
+
if ($Tree) {
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
$Tree.focus()
|
|
59
|
+
}
|
|
60
|
+
} else if (focused) {
|
|
46
61
|
const $Focused = $Viewlet.querySelector(`[name="${focused}"]`)
|
|
47
62
|
if ($Focused) {
|
|
48
63
|
// @ts-ignore
|