@lvce-editor/virtual-dom 1.5.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
@@ -436,6 +436,13 @@ var setProp = ($Element, key, value, eventMap, newEventMap) => {
436
436
  }
437
437
  attachEvent($Element, eventMap, eventName, value, newEventMap);
438
438
  break;
439
+ case "id":
440
+ if (value) {
441
+ $Element[key] = value;
442
+ } else {
443
+ $Element.removeAttribute(key);
444
+ }
445
+ break;
439
446
  default:
440
447
  if (key.startsWith("data-")) {
441
448
  $Element.dataset[key.slice("data-".length)] = value;
@@ -513,7 +520,10 @@ var rememberFocus = ($Viewlet, dom, eventMap, uid = 0) => {
513
520
  const oldTop = $Viewlet.style.top;
514
521
  const oldWidth = $Viewlet.style.width;
515
522
  const oldHeight = $Viewlet.style.height;
516
- const focused = document.activeElement.getAttribute("name");
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");
517
527
  const $$Inputs = queryInputs($Viewlet);
518
528
  const inputMap = /* @__PURE__ */ Object.create(null);
519
529
  for (const $Input of $$Inputs) {
@@ -532,7 +542,14 @@ var rememberFocus = ($Viewlet, dom, eventMap, uid = 0) => {
532
542
  for (const $Input of $$NewInputs) {
533
543
  $Input.value = inputMap[$Input.name] || $Input.value || "";
534
544
  }
535
- if (focused) {
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) {
536
553
  const $Focused = $Viewlet.querySelector(`[name="${focused}"]`);
537
554
  if ($Focused) {
538
555
  $Focused.focus();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/virtual-dom",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -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
- // @ts-expect-error
22
- const focused = document.activeElement.getAttribute('name')
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
- if (focused) {
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
@@ -76,6 +76,13 @@ export const setProp = (
76
76
  }
77
77
  AttachEvent.attachEvent($Element, eventMap, eventName, value, newEventMap)
78
78
  break
79
+ case 'id':
80
+ if (value) {
81
+ $Element[key] = value
82
+ } else {
83
+ $Element.removeAttribute(key)
84
+ }
85
+ break
79
86
  default:
80
87
  if (key.startsWith('data-')) {
81
88
  $Element.dataset[key.slice('data-'.length)] = value