@3sln/dodo 0.0.2 → 0.0.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/vdom.js +51 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3sln/dodo",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "A minimal, configurable virtual DOM library.",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/vdom.js CHANGED
@@ -91,10 +91,10 @@ function getPathFromElement(element) {
91
91
  let current = element;
92
92
  while (current) {
93
93
  path.push(current);
94
- if (current.shadowRoot) {
95
- current = current.shadowRoot.host;
94
+ if (current.parentElement) {
95
+ current = current.parentElement;
96
96
  } else {
97
- current = current.parentNode;
97
+ current = current.getRootNode()?.host;
98
98
  }
99
99
  }
100
100
  return path;
@@ -577,41 +577,65 @@ export default (userSettings) => {
577
577
 
578
578
  const moveBefore = window.Element.prototype.moveBefore;
579
579
  const insertBefore = window.Element.prototype.insertBefore;
580
- if (target.isConnected && typeof moveBefore === 'function') {
581
- for (let i = 0; i < newDomChildren.length; i++) {
582
- const newChild = newDomChildren[i];
583
- const existingChildAtPosition = target.childNodes[i];
584
- if (newChild !== existingChildAtPosition) {
585
- (newChild.isConnected ? moveBefore : insertBefore).call(target, newChild, existingChildAtPosition);
580
+ if (target.isConnected) {
581
+ if (typeof moveBefore === 'function') {
582
+ for (let i = 0; i < newDomChildren.length; i++) {
583
+ const newChild = newDomChildren[i];
584
+ const existingChildAtPosition = target.childNodes[i];
585
+ if (newChild !== existingChildAtPosition) {
586
+ (newChild.isConnected ? moveBefore : insertBefore).call(target, newChild, existingChildAtPosition);
587
+ }
588
+ const state = newChild[NODE_STATE];
589
+ if (state?.newVdom) {
590
+ if (!state.vdom) {
591
+ try {
592
+ state.newVdom.hooks?.$attach?.(newChild);
593
+ if (state.newVdom.type === SPECIAL_NODE) {
594
+ state.newVdom.tag.attach?.(newChild);
595
+ }
596
+ } catch (err) {
597
+ console.error(err);
598
+ }
599
+ }
600
+ reconcileNode(newChild);
601
+ }
586
602
  }
587
- const state = newChild[NODE_STATE];
588
- if (state?.newVdom) {
589
- if (!state.vdom) {
590
- try {
591
- state.newVdom.hooks?.$attach?.(newChild);
592
- if (state.newVdom.type === SPECIAL_NODE) {
593
- state.newVdom.tag.attach?.(newChild);
603
+ } else {
604
+ const doc = target.ownerDocument;
605
+ let focusWithin = documentToFocusWithinSet.get(doc);
606
+ if (!focusWithin) {
607
+ focusWithin = installFocusTrackingForDocument(doc);
608
+ }
609
+ for (let i = 0; i < newDomChildren.length; i++) {
610
+ const newChild = newDomChildren[i];
611
+ const existingChildAtPosition = target.childNodes[i];
612
+ if (newChild !== existingChildAtPosition) {
613
+ if (!focusWithin.has(newChild)) {
614
+ insertBefore.call(target, newChild, existingChildAtPosition);
615
+ }
616
+ }
617
+ const state = newChild[NODE_STATE];
618
+ if (state?.newVdom) {
619
+ if (!state.vdom) {
620
+ try {
621
+ state.newVdom.hooks?.$attach?.(newChild);
622
+ if (state.newVdom.type === SPECIAL_NODE) {
623
+ state.newVdom.tag.attach?.(newChild);
624
+ }
625
+ } catch (err) {
626
+ console.error(err);
594
627
  }
595
- } catch (err) {
596
- console.error(err);
597
628
  }
629
+ reconcileNode(newChild);
598
630
  }
599
- reconcileNode(newChild);
600
631
  }
601
632
  }
602
633
  } else {
603
- const doc = target.ownerDocument;
604
- let focusWithin = documentToFocusWithinSet.get(doc);
605
- if (!focusWithin) {
606
- focusWithin = installFocusTrackingForDocument(doc);
607
- }
608
634
  for (let i = 0; i < newDomChildren.length; i++) {
609
635
  const newChild = newDomChildren[i];
610
636
  const existingChildAtPosition = target.childNodes[i];
611
637
  if (newChild !== existingChildAtPosition) {
612
- if (!focusWithin.has(newChild)) {
613
- insertBefore.call(target, newChild, existingChildAtPosition);
614
- }
638
+ insertBefore.call(target, newChild, existingChildAtPosition);
615
639
  }
616
640
  const state = newChild[NODE_STATE];
617
641
  if (state?.newVdom) {