@lwc/synthetic-shadow 2.6.1 → 2.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.6.1 */
197
+ /** version: 2.7.2 */
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.6.1 */
1527
+ /** version: 2.7.2 */
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
  }
@@ -2143,6 +2181,12 @@ const SyntheticShadowRootDescriptors = {
2143
2181
  return `[object ShadowRoot]`;
2144
2182
  }
2145
2183
 
2184
+ },
2185
+ synthetic: {
2186
+ writable: false,
2187
+ enumerable: false,
2188
+ configurable: false,
2189
+ value: true
2146
2190
  }
2147
2191
  };
2148
2192
  const ShadowRootDescriptors = {
@@ -3971,6 +4015,14 @@ retargetRelatedTarget(FocusEvent);
3971
4015
  */
3972
4016
  retargetRelatedTarget(MouseEvent);
3973
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
+
3974
4026
  /*
3975
4027
  * Copyright (c) 2018, salesforce.com, inc.
3976
4028
  * All rights reserved.
@@ -4024,10 +4076,22 @@ function getFilteredSlotFlattenNodes(slot) {
4024
4076
  }
4025
4077
 
4026
4078
  function assignedSlotGetterPatched() {
4027
- 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
+ }
4028
4092
  /**
4029
4093
  * The node is assigned to a slot if:
4030
- * - 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
4031
4095
  * - and if the slot owner key is different than the node owner key.
4032
4096
  *
4033
4097
  * When the slot and the slotted node are 2 different shadow trees, the owner keys will be
@@ -4036,6 +4100,7 @@ function assignedSlotGetterPatched() {
4036
4100
  * different than the node owner key (always `undefined`).
4037
4101
  */
4038
4102
 
4103
+
4039
4104
  if (!isNull(parentNode) && isSlotElement(parentNode) && getNodeOwnerKey(parentNode) !== getNodeOwnerKey(this)) {
4040
4105
  return parentNode;
4041
4106
  }
@@ -5650,4 +5715,4 @@ defineProperty(Element.prototype, '$domManual$', {
5650
5715
 
5651
5716
  configurable: true
5652
5717
  });
5653
- /** version: 2.6.1 */
5718
+ /** version: 2.7.2 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lwc/synthetic-shadow",
3
- "version": "2.6.1",
3
+ "version": "2.7.2",
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.6.1",
40
- "@lwc/shared": "2.6.1"
39
+ "@lwc/features": "2.7.2",
40
+ "@lwc/shared": "2.7.2"
41
41
  },
42
- "gitHead": "65ae5d96106495314904cade2522cceef2067229"
42
+ "gitHead": "f668a3ad36bbebbaa33a5863408a45bf4185d218"
43
43
  }