@lvce-editor/virtual-dom 1.22.0 → 1.23.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
@@ -654,28 +654,40 @@ const rememberFocus = ($Viewlet, dom, eventMap, uid = 0) => {
654
654
  const isTreeFocused = activeElement?.getAttribute('role') === 'tree';
655
655
  const isRootTree = $Viewlet.getAttribute('role') === 'tree' && activeElement === $Viewlet;
656
656
  const focused = activeElement?.getAttribute('name');
657
+ const $Hidden = document.createElement('div');
658
+ $Hidden.style.display = 'none';
659
+ if (focused) {
660
+ if (document.body) {
661
+ document.body.append($Hidden);
662
+ }
663
+ // @ts-ignore
664
+ $Hidden.append(activeElement);
665
+ }
657
666
  const $$Inputs = queryInputs($Viewlet);
658
667
  const inputMap = Object.create(null);
659
668
  for (const $Input of $$Inputs) {
660
- // @ts-ignore
661
669
  inputMap[$Input.name] = $Input.value;
662
670
  }
663
671
  if (uid) {
664
672
  const newEventMap = getEventListenerMap(uid);
665
673
  const $New = render(dom, eventMap, newEventMap).firstChild;
666
674
  setComponentUid($New, uid);
667
- // @ts-ignore
675
+ const $$NewInputs = queryInputs($New);
676
+ for (const $Input of $$NewInputs) {
677
+ $Input.value = inputMap[$Input.name] || $Input.value || '';
678
+ }
668
679
  $Viewlet.replaceWith($New);
669
- // @ts-ignore
680
+ if (focused) {
681
+ const $NewFocused = $Viewlet.querySelector(`[name="${focused}"]`);
682
+ if ($NewFocused) {
683
+ $NewFocused.replaceWith($Hidden.firstChild);
684
+ }
685
+ }
686
+ $Hidden.remove();
670
687
  $Viewlet = $New;
671
688
  } else {
672
689
  renderInto($Viewlet, dom, eventMap);
673
690
  }
674
- const $$NewInputs = queryInputs($Viewlet);
675
- for (const $Input of $$NewInputs) {
676
- // @ts-ignore
677
- $Input.value = inputMap[$Input.name] || $Input.value || '';
678
- }
679
691
  if (isRootTree) {
680
692
  $Viewlet.focus();
681
693
  } else if (isTreeFocused) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/virtual-dom",
3
- "version": "1.22.0",
3
+ "version": "1.23.0",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -13,39 +13,47 @@ export const rememberFocus = (
13
13
  const oldTop = $Viewlet.style.top
14
14
  const oldWidth = $Viewlet.style.width
15
15
  const oldHeight = $Viewlet.style.height
16
-
17
16
  const { activeElement } = document
18
17
  const isTreeFocused = activeElement?.getAttribute('role') === 'tree'
19
18
  const isRootTree =
20
19
  $Viewlet.getAttribute('role') === 'tree' && activeElement === $Viewlet
21
-
22
20
  const focused = activeElement?.getAttribute('name')
23
-
21
+ const $Hidden = document.createElement('div')
22
+ $Hidden.style.display = 'none'
23
+ if (focused) {
24
+ if (document.body) {
25
+ document.body.append($Hidden)
26
+ }
27
+ // @ts-ignore
28
+ $Hidden.append(activeElement)
29
+ }
24
30
  const $$Inputs = QueryInputs.queryInputs($Viewlet)
25
31
  const inputMap = Object.create(null)
26
32
  for (const $Input of $$Inputs) {
27
- // @ts-ignore
28
33
  inputMap[$Input.name] = $Input.value
29
34
  }
30
-
31
35
  if (uid) {
32
36
  const newEventMap = RegisterEventListeners.getEventListenerMap(uid)
33
- const $New = VirtualDom.render(dom, eventMap, newEventMap).firstChild
37
+ const $New = VirtualDom.render(dom, eventMap, newEventMap)
38
+ .firstChild as HTMLElement
34
39
  ComponentUid.setComponentUid($New, uid)
35
- // @ts-ignore
40
+ const $$NewInputs = QueryInputs.queryInputs($New)
41
+ for (const $Input of $$NewInputs) {
42
+ $Input.value = inputMap[$Input.name] || $Input.value || ''
43
+ }
36
44
  $Viewlet.replaceWith($New)
37
- // @ts-ignore
45
+ if (focused) {
46
+ const $NewFocused = $Viewlet.querySelector(`[name="${focused}"]`)
47
+ if ($NewFocused) {
48
+ $NewFocused.replaceWith($Hidden.firstChild as HTMLElement)
49
+ }
50
+ }
51
+ $Hidden.remove()
38
52
  $Viewlet = $New
39
53
  } else {
40
54
  VirtualDom.renderInto($Viewlet, dom, eventMap)
41
55
  }
42
56
 
43
- const $$NewInputs = QueryInputs.queryInputs($Viewlet)
44
- for (const $Input of $$NewInputs) {
45
- // @ts-ignore
46
- $Input.value = inputMap[$Input.name] || $Input.value || ''
47
- }
48
-
49
57
  if (isRootTree) {
50
58
  $Viewlet.focus()
51
59
  } else if (isTreeFocused) {
@@ -56,6 +64,7 @@ export const rememberFocus = (
56
64
  }
57
65
  } else if (focused) {
58
66
  const $Focused = $Viewlet.querySelector(`[name="${focused}"]`)
67
+
59
68
  if ($Focused) {
60
69
  // @ts-ignore
61
70
  $Focused.focus()