@lwc/synthetic-shadow 2.6.2 → 2.6.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.
@@ -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.2 */
197
+ /** version: 2.6.3 */
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.
@@ -899,6 +900,14 @@ function getNodeKey(node) {
899
900
  function isNodeShadowed(node) {
900
901
  return !isUndefined(getNodeOwnerKey(node));
901
902
  }
903
+ /**
904
+ * Returns true if this node is a shadow host, is in a shadow host, or contains a shadow host
905
+ * anywhere in its tree.
906
+ */
907
+
908
+ function isNodeOrDescendantsShadowed(node) {
909
+ return isNodeShadowed(node) || isSyntheticShadowHost(node) || containsHost(node);
910
+ }
902
911
 
903
912
  /*
904
913
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1523,7 +1532,7 @@ if (!_globalThis.lwcRuntimeFlags) {
1523
1532
  }
1524
1533
 
1525
1534
  const runtimeFlags = _globalThis.lwcRuntimeFlags;
1526
- /** version: 2.6.2 */
1535
+ /** version: 2.6.3 */
1527
1536
 
1528
1537
  /*
1529
1538
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1616,7 +1625,9 @@ function parentElementGetterPatched() {
1616
1625
  }
1617
1626
 
1618
1627
  function compareDocumentPositionPatched(otherNode) {
1619
- if (this.getRootNode() === otherNode) {
1628
+ if (this === otherNode) {
1629
+ return 0;
1630
+ } else if (this.getRootNode() === otherNode) {
1620
1631
  // "this" is in a shadow tree where the shadow root is the "otherNode".
1621
1632
  return 10; // Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING
1622
1633
  } else if (getNodeOwnerKey(this) !== getNodeOwnerKey(otherNode)) {
@@ -1662,7 +1673,7 @@ function cloneNodePatched(deep) {
1662
1673
  function childNodesGetterPatched() {
1663
1674
  if (isSyntheticShadowHost(this)) {
1664
1675
  const owner = getNodeOwner(this);
1665
- const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
1676
+ const childNodes = isNull(owner) ? getFilteredChildNodes(this) : getAllMatches(owner, getFilteredChildNodes(this));
1666
1677
 
1667
1678
  if (process.env.NODE_ENV !== 'production' && isFalse(hasNativeSymbolSupport) && isExternalChildNodeAccessorFlagOn()) {
1668
1679
  // inserting a comment node as the first childNode to trick the IE11
@@ -1773,7 +1784,8 @@ defineProperties(_Node.prototype, {
1773
1784
  textContent: {
1774
1785
  get() {
1775
1786
  if (!runtimeFlags.ENABLE_NODE_PATCH) {
1776
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1787
+ // See note on get innerHTML in faux-shadow/element.ts
1788
+ if (isNodeOrDescendantsShadowed(this)) {
1777
1789
  return textContentGetterPatched.call(this);
1778
1790
  }
1779
1791
 
@@ -2007,7 +2019,22 @@ function getAllRootNodes(node) {
2007
2019
  }
2008
2020
 
2009
2021
  return rootNodes;
2010
- }
2022
+ } // Keep searching up the host tree until we find an element that is within the immediate shadow root
2023
+
2024
+
2025
+ const findAncestorHostInImmediateShadowRoot = (rootNode, targetRootNode) => {
2026
+ let host;
2027
+
2028
+ while (!isUndefined(host = rootNode.host)) {
2029
+ const thisRootNode = host.getRootNode();
2030
+
2031
+ if (thisRootNode === targetRootNode) {
2032
+ return host;
2033
+ }
2034
+
2035
+ rootNode = thisRootNode;
2036
+ }
2037
+ };
2011
2038
 
2012
2039
  function fauxElementsFromPoint(context, doc, left, top) {
2013
2040
  const elements = elementsFromPoint.call(doc, left, top);
@@ -2021,8 +2048,28 @@ function fauxElementsFromPoint(context, doc, left, top) {
2021
2048
  for (let i = 0; i < elements.length; i++) {
2022
2049
  const element = elements[i];
2023
2050
 
2024
- if (rootNodes.indexOf(element.getRootNode()) !== -1 && !isSyntheticSlotElement(element)) {
2025
- result.push(element);
2051
+ if (isSyntheticSlotElement(element)) {
2052
+ continue;
2053
+ }
2054
+
2055
+ const elementRootNode = element.getRootNode();
2056
+
2057
+ if (ArrayIndexOf.call(rootNodes, elementRootNode) !== -1) {
2058
+ ArrayPush.call(result, element);
2059
+ continue;
2060
+ } // In cases where the host element is not visible but its shadow descendants are, then
2061
+ // we may get the shadow descendant instead of the host element here. (The
2062
+ // browser doesn't know the difference in synthetic shadow DOM.)
2063
+ // In native shadow DOM, however, elementsFromPoint would return the host but not
2064
+ // the child. So we need to detect if this shadow element's host is accessible from
2065
+ // the context's shadow root. Note we also need to be careful not to add the host
2066
+ // multiple times.
2067
+
2068
+
2069
+ const ancestorHost = findAncestorHostInImmediateShadowRoot(elementRootNode, rootNodes[0]);
2070
+
2071
+ if (!isUndefined(ancestorHost) && ArrayIndexOf.call(elements, ancestorHost) === -1 && ArrayIndexOf.call(result, ancestorHost) === -1) {
2072
+ ArrayPush.call(result, ancestorHost);
2026
2073
  }
2027
2074
  }
2028
2075
  }
@@ -2096,6 +2143,28 @@ function isSyntheticShadowHost(node) {
2096
2143
  function isSyntheticShadowRoot(node) {
2097
2144
  const shadowRootRecord = InternalSlot.get(node);
2098
2145
  return !isUndefined(shadowRootRecord) && node === shadowRootRecord.shadowRoot;
2146
+ } // Return true if any descendant is a host element
2147
+
2148
+ function containsHost(node) {
2149
+ // IE11 complains with "Unexpected call to method or property access." when calling walker.nextNode().
2150
+ // The fix for this is to only walk trees for nodes that are Node.ELEMENT_NODE.
2151
+ if (node.nodeType !== _Node.ELEMENT_NODE) {
2152
+ return false;
2153
+ } // IE requires all four arguments, even though the fourth is deprecated
2154
+ // https://developer.mozilla.org/en-US/docs/Web/API/Document/createTreeWalker#browser_compatibility
2155
+ // @ts-ignore
2156
+
2157
+
2158
+ const walker = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT, null, false);
2159
+ let descendant;
2160
+
2161
+ while (!isNull(descendant = walker.nextNode())) {
2162
+ if (isSyntheticShadowHost(descendant)) {
2163
+ return true;
2164
+ }
2165
+ }
2166
+
2167
+ return false;
2099
2168
  }
2100
2169
  let uid = 0;
2101
2170
  function attachShadow(elm, options) {
@@ -2143,6 +2212,12 @@ const SyntheticShadowRootDescriptors = {
2143
2212
  return `[object ShadowRoot]`;
2144
2213
  }
2145
2214
 
2215
+ },
2216
+ synthetic: {
2217
+ writable: false,
2218
+ enumerable: false,
2219
+ configurable: false,
2220
+ value: true
2146
2221
  }
2147
2222
  };
2148
2223
  const ShadowRootDescriptors = {
@@ -3971,6 +4046,14 @@ retargetRelatedTarget(FocusEvent);
3971
4046
  */
3972
4047
  retargetRelatedTarget(MouseEvent);
3973
4048
 
4049
+ /*
4050
+ * Copyright (c) 2021, salesforce.com, inc.
4051
+ * All rights reserved.
4052
+ * SPDX-License-Identifier: MIT
4053
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4054
+ */
4055
+ const assignedSlotGetter = hasOwnProperty.call(Text.prototype, 'assignedSlot') ? getOwnPropertyDescriptor(Text.prototype, 'assignedSlot').get : () => null;
4056
+
3974
4057
  /*
3975
4058
  * Copyright (c) 2018, salesforce.com, inc.
3976
4059
  * All rights reserved.
@@ -4024,10 +4107,22 @@ function getFilteredSlotFlattenNodes(slot) {
4024
4107
  }
4025
4108
 
4026
4109
  function assignedSlotGetterPatched() {
4027
- const parentNode = parentNodeGetter.call(this);
4110
+ const parentNode = parentNodeGetter.call(this); // use original assignedSlot if parent has a native shdow root
4111
+
4112
+ if (parentNode instanceof Element) {
4113
+ const sr = shadowRootGetter.call(parentNode);
4114
+
4115
+ if (isInstanceOfNativeShadowRoot(sr)) {
4116
+ if (this instanceof Text) {
4117
+ return assignedSlotGetter.call(this);
4118
+ }
4119
+
4120
+ return assignedSlotGetter$1.call(this);
4121
+ }
4122
+ }
4028
4123
  /**
4029
4124
  * The node is assigned to a slot if:
4030
- * - it has a parent and it parent its parent is a slot element
4125
+ * - it has a parent and its parent is a slot element
4031
4126
  * - and if the slot owner key is different than the node owner key.
4032
4127
  *
4033
4128
  * When the slot and the slotted node are 2 different shadow trees, the owner keys will be
@@ -4036,6 +4131,7 @@ function assignedSlotGetterPatched() {
4036
4131
  * different than the node owner key (always `undefined`).
4037
4132
  */
4038
4133
 
4134
+
4039
4135
  if (!isNull(parentNode) && isSlotElement(parentNode) && getNodeOwnerKey(parentNode) !== getNodeOwnerKey(this)) {
4040
4136
  return parentNode;
4041
4137
  }
@@ -4252,7 +4348,10 @@ defineProperties(Element.prototype, {
4252
4348
  innerHTML: {
4253
4349
  get() {
4254
4350
  if (!runtimeFlags.ENABLE_ELEMENT_PATCH) {
4255
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
4351
+ // If this element is in synthetic shadow, if it's a synthetic shadow host,
4352
+ // or if any of its descendants are synthetic shadow hosts, then we can't
4353
+ // use the native innerHTML because it would expose private node internals.
4354
+ if (isNodeOrDescendantsShadowed(this)) {
4256
4355
  return innerHTMLGetterPatched.call(this);
4257
4356
  }
4258
4357
 
@@ -4277,7 +4376,8 @@ defineProperties(Element.prototype, {
4277
4376
  outerHTML: {
4278
4377
  get() {
4279
4378
  if (!runtimeFlags.ENABLE_ELEMENT_PATCH) {
4280
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
4379
+ // See notes above on get innerHTML
4380
+ if (isNodeOrDescendantsShadowed(this)) {
4281
4381
  return outerHTMLGetterPatched.call(this);
4282
4382
  }
4283
4383
 
@@ -5650,4 +5750,4 @@ defineProperty(Element.prototype, '$domManual$', {
5650
5750
 
5651
5751
  configurable: true
5652
5752
  });
5653
- /** version: 2.6.2 */
5753
+ /** version: 2.6.3 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lwc/synthetic-shadow",
3
- "version": "2.6.2",
3
+ "version": "2.6.3",
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.2",
40
- "@lwc/shared": "2.6.2"
39
+ "@lwc/features": "2.6.3",
40
+ "@lwc/shared": "2.6.3"
41
41
  },
42
- "gitHead": "a49666f207d17e164aa914cf00b8f9d5a656228d"
42
+ "gitHead": "1fdd835243eed190b8ab9ca61ae7eae9f9a4073d"
43
43
  }