@lwc/synthetic-shadow 2.7.0 → 2.7.4

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.
@@ -194,7 +194,7 @@ const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
194
194
 
195
195
 
196
196
  const hasNativeSymbolSupport = /*@__PURE__*/(() => Symbol('x').toString() === 'Symbol(x)')();
197
- /** version: 2.7.0 */
197
+ /** version: 2.7.4 */
198
198
 
199
199
  /*
200
200
  * Copyright (c) 2018, salesforce.com, inc.
@@ -301,6 +301,7 @@ const {
301
301
  getElementsByClassName: getElementsByClassName$1
302
302
  } = HTMLElement.prototype;
303
303
  const shadowRootGetter = hasOwnProperty.call(Element.prototype, 'shadowRoot') ? getOwnPropertyDescriptor(Element.prototype, 'shadowRoot').get : () => null;
304
+ const assignedSlotGetter$1 = hasOwnProperty.call(Element.prototype, 'assignedSlot') ? getOwnPropertyDescriptor(Element.prototype, 'assignedSlot').get : () => null;
304
305
 
305
306
  /*
306
307
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1523,7 +1524,7 @@ if (!_globalThis.lwcRuntimeFlags) {
1523
1524
  }
1524
1525
 
1525
1526
  const runtimeFlags = _globalThis.lwcRuntimeFlags;
1526
- /** version: 2.7.0 */
1527
+ /** version: 2.7.4 */
1527
1528
 
1528
1529
  /*
1529
1530
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1616,7 +1617,9 @@ function parentElementGetterPatched() {
1616
1617
  }
1617
1618
 
1618
1619
  function compareDocumentPositionPatched(otherNode) {
1619
- if (this.getRootNode() === otherNode) {
1620
+ if (this === otherNode) {
1621
+ return 0;
1622
+ } else if (this.getRootNode() === otherNode) {
1620
1623
  // "this" is in a shadow tree where the shadow root is the "otherNode".
1621
1624
  return 10; // Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING
1622
1625
  } else if (getNodeOwnerKey(this) !== getNodeOwnerKey(otherNode)) {
@@ -2007,7 +2010,22 @@ function getAllRootNodes(node) {
2007
2010
  }
2008
2011
 
2009
2012
  return rootNodes;
2010
- }
2013
+ } // Keep searching up the host tree until we find an element that is within the immediate shadow root
2014
+
2015
+
2016
+ const findAncestorHostInImmediateShadowRoot = (rootNode, targetRootNode) => {
2017
+ let host;
2018
+
2019
+ while (!isUndefined(host = rootNode.host)) {
2020
+ const thisRootNode = host.getRootNode();
2021
+
2022
+ if (thisRootNode === targetRootNode) {
2023
+ return host;
2024
+ }
2025
+
2026
+ rootNode = thisRootNode;
2027
+ }
2028
+ };
2011
2029
 
2012
2030
  function fauxElementsFromPoint(context, doc, left, top) {
2013
2031
  const elements = elementsFromPoint.call(doc, left, top);
@@ -2021,8 +2039,28 @@ function fauxElementsFromPoint(context, doc, left, top) {
2021
2039
  for (let i = 0; i < elements.length; i++) {
2022
2040
  const element = elements[i];
2023
2041
 
2024
- if (rootNodes.indexOf(element.getRootNode()) !== -1 && !isSyntheticSlotElement(element)) {
2025
- result.push(element);
2042
+ if (isSyntheticSlotElement(element)) {
2043
+ continue;
2044
+ }
2045
+
2046
+ const elementRootNode = element.getRootNode();
2047
+
2048
+ if (ArrayIndexOf.call(rootNodes, elementRootNode) !== -1) {
2049
+ ArrayPush.call(result, element);
2050
+ continue;
2051
+ } // In cases where the host element is not visible but its shadow descendants are, then
2052
+ // we may get the shadow descendant instead of the host element here. (The
2053
+ // browser doesn't know the difference in synthetic shadow DOM.)
2054
+ // In native shadow DOM, however, elementsFromPoint would return the host but not
2055
+ // the child. So we need to detect if this shadow element's host is accessible from
2056
+ // the context's shadow root. Note we also need to be careful not to add the host
2057
+ // multiple times.
2058
+
2059
+
2060
+ const ancestorHost = findAncestorHostInImmediateShadowRoot(elementRootNode, rootNodes[0]);
2061
+
2062
+ if (!isUndefined(ancestorHost) && ArrayIndexOf.call(elements, ancestorHost) === -1 && ArrayIndexOf.call(result, ancestorHost) === -1) {
2063
+ ArrayPush.call(result, ancestorHost);
2026
2064
  }
2027
2065
  }
2028
2066
  }
@@ -3977,6 +4015,14 @@ retargetRelatedTarget(FocusEvent);
3977
4015
  */
3978
4016
  retargetRelatedTarget(MouseEvent);
3979
4017
 
4018
+ /*
4019
+ * Copyright (c) 2021, salesforce.com, inc.
4020
+ * All rights reserved.
4021
+ * SPDX-License-Identifier: MIT
4022
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4023
+ */
4024
+ const assignedSlotGetter = hasOwnProperty.call(Text.prototype, 'assignedSlot') ? getOwnPropertyDescriptor(Text.prototype, 'assignedSlot').get : () => null;
4025
+
3980
4026
  /*
3981
4027
  * Copyright (c) 2018, salesforce.com, inc.
3982
4028
  * All rights reserved.
@@ -4030,10 +4076,22 @@ function getFilteredSlotFlattenNodes(slot) {
4030
4076
  }
4031
4077
 
4032
4078
  function assignedSlotGetterPatched() {
4033
- const parentNode = parentNodeGetter.call(this);
4079
+ const parentNode = parentNodeGetter.call(this); // use original assignedSlot if parent has a native shdow root
4080
+
4081
+ if (parentNode instanceof Element) {
4082
+ const sr = shadowRootGetter.call(parentNode);
4083
+
4084
+ if (isInstanceOfNativeShadowRoot(sr)) {
4085
+ if (this instanceof Text) {
4086
+ return assignedSlotGetter.call(this);
4087
+ }
4088
+
4089
+ return assignedSlotGetter$1.call(this);
4090
+ }
4091
+ }
4034
4092
  /**
4035
4093
  * The node is assigned to a slot if:
4036
- * - it has a parent and it parent its parent is a slot element
4094
+ * - it has a parent and its parent is a slot element
4037
4095
  * - and if the slot owner key is different than the node owner key.
4038
4096
  *
4039
4097
  * When the slot and the slotted node are 2 different shadow trees, the owner keys will be
@@ -4042,6 +4100,7 @@ function assignedSlotGetterPatched() {
4042
4100
  * different than the node owner key (always `undefined`).
4043
4101
  */
4044
4102
 
4103
+
4045
4104
  if (!isNull(parentNode) && isSlotElement(parentNode) && getNodeOwnerKey(parentNode) !== getNodeOwnerKey(this)) {
4046
4105
  return parentNode;
4047
4106
  }
@@ -5656,4 +5715,4 @@ defineProperty(Element.prototype, '$domManual$', {
5656
5715
 
5657
5716
  configurable: true
5658
5717
  });
5659
- /** version: 2.7.0 */
5718
+ /** version: 2.7.4 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lwc/synthetic-shadow",
3
- "version": "2.7.0",
3
+ "version": "2.7.4",
4
4
  "description": "Synthetic Shadow Root for LWC",
5
5
  "homepage": "https://lwc.dev/",
6
6
  "repository": {
@@ -36,8 +36,8 @@
36
36
  "access": "public"
37
37
  },
38
38
  "devDependencies": {
39
- "@lwc/features": "2.7.0",
40
- "@lwc/shared": "2.7.0"
39
+ "@lwc/features": "2.7.4",
40
+ "@lwc/shared": "2.7.4"
41
41
  },
42
- "gitHead": "656663a9f95f90bd648c6fc2200201afc0156393"
42
+ "gitHead": "df4eda8be794fa5f7a01148c137eea4e546a0844"
43
43
  }