lwc 2.32.0 → 2.32.1

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 (39) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +222 -249
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +222 -249
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +94 -145
  5. package/dist/engine-dom/iife/es5/engine-dom.js +211 -226
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +120 -183
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +222 -249
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +94 -145
  11. package/dist/engine-dom/umd/es5/engine-dom.js +211 -226
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +120 -183
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +218 -224
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +218 -224
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +676 -909
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +676 -909
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +644 -882
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +85 -345
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +85 -345
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +676 -909
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +644 -882
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +85 -345
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +85 -345
  30. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  31. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  34. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  35. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  36. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  37. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  38. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  39. package/package.json +7 -7
@@ -89,7 +89,7 @@
89
89
  const KEY__SHADOW_TOKEN = '$shadowToken$';
90
90
  const KEY__SHADOW_TOKEN_PRIVATE = '$$ShadowTokenKey$$';
91
91
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
92
- /** version: 2.32.0 */
92
+ /** version: 2.32.1 */
93
93
 
94
94
  /*
95
95
  * Copyright (c) 2018, salesforce.com, inc.
@@ -363,7 +363,8 @@
363
363
  return win;
364
364
  }
365
365
  let skipGlobalPatching;
366
- // TODO [#1222]: remove global bypass
366
+ // Note: we deviate from native shadow here, but are not fixing
367
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
367
368
  function isGlobalPatchingSkipped(node) {
368
369
  // we lazily compute this value instead of doing it during evaluation, this helps
369
370
  // for apps that are setting this after the engine code is evaluated.
@@ -403,7 +404,7 @@
403
404
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
404
405
  }
405
406
  const lwcRuntimeFlags = _globalThis.lwcRuntimeFlags;
406
- /** version: 2.32.0 */
407
+ /** version: 2.32.1 */
407
408
 
408
409
  /*
409
410
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1084,112 +1085,116 @@
1084
1085
  * because we don't want to patch the children getters for those elements.
1085
1086
  */
1086
1087
  function hasMountedChildren(node) {
1087
- return isSyntheticSlotElement(node) || isSyntheticShadowHost(node);
1088
+ return isSyntheticSlotElement(node) || isSyntheticShadowHost(node);
1088
1089
  }
1089
1090
  function getShadowParent(node, value) {
1090
- const owner = getNodeOwner(node);
1091
- if (value === owner) {
1092
- // walking up via parent chain might end up in the shadow root element
1093
- return getShadowRoot(owner);
1094
- } else if (value instanceof Element) {
1095
- if (getNodeNearestOwnerKey(node) === getNodeNearestOwnerKey(value)) {
1096
- // the element and its parent node belong to the same shadow root
1097
- return value;
1098
- } else if (!isNull(owner) && isSlotElement(value)) {
1099
- // slotted elements must be top level childNodes of the slot element
1100
- // where they slotted into, but its shadowed parent is always the
1101
- // owner of the slot.
1102
- const slotOwner = getNodeOwner(value);
1103
- if (!isNull(slotOwner) && isNodeOwnedBy(owner, slotOwner)) {
1104
- // it is a slotted element, and therefore its parent is always going to be the host of the slot
1105
- return slotOwner;
1106
- }
1091
+ const owner = getNodeOwner(node);
1092
+ if (value === owner) {
1093
+ // walking up via parent chain might end up in the shadow root element
1094
+ return getShadowRoot(owner);
1095
+ }
1096
+ else if (value instanceof Element) {
1097
+ if (getNodeNearestOwnerKey(node) === getNodeNearestOwnerKey(value)) {
1098
+ // the element and its parent node belong to the same shadow root
1099
+ return value;
1100
+ }
1101
+ else if (!isNull(owner) && isSlotElement(value)) {
1102
+ // slotted elements must be top level childNodes of the slot element
1103
+ // where they slotted into, but its shadowed parent is always the
1104
+ // owner of the slot.
1105
+ const slotOwner = getNodeOwner(value);
1106
+ if (!isNull(slotOwner) && isNodeOwnedBy(owner, slotOwner)) {
1107
+ // it is a slotted element, and therefore its parent is always going to be the host of the slot
1108
+ return slotOwner;
1109
+ }
1110
+ }
1107
1111
  }
1108
- }
1109
- return null;
1112
+ return null;
1110
1113
  }
1111
1114
  function hasChildNodesPatched() {
1112
- return getInternalChildNodes(this).length > 0;
1115
+ return getInternalChildNodes(this).length > 0;
1113
1116
  }
1114
1117
  function firstChildGetterPatched() {
1115
- const childNodes = getInternalChildNodes(this);
1116
- return childNodes[0] || null;
1118
+ const childNodes = getInternalChildNodes(this);
1119
+ return childNodes[0] || null;
1117
1120
  }
1118
1121
  function lastChildGetterPatched() {
1119
- const childNodes = getInternalChildNodes(this);
1120
- return childNodes[childNodes.length - 1] || null;
1122
+ const childNodes = getInternalChildNodes(this);
1123
+ return childNodes[childNodes.length - 1] || null;
1121
1124
  }
1122
1125
  function textContentGetterPatched() {
1123
- return getTextContent(this);
1126
+ return getTextContent(this);
1124
1127
  }
1125
1128
  function textContentSetterPatched(value) {
1126
- textContextSetter.call(this, value);
1129
+ textContextSetter.call(this, value);
1127
1130
  }
1128
1131
  function parentNodeGetterPatched() {
1129
- const value = parentNodeGetter.call(this);
1130
- if (isNull(value)) {
1131
- return value;
1132
- }
1133
- // TODO [#1635]: this needs optimization, maybe implementing it based on this.assignedSlot
1134
- return getShadowParent(this, value);
1132
+ const value = parentNodeGetter.call(this);
1133
+ if (isNull(value)) {
1134
+ return value;
1135
+ }
1136
+ // TODO [#1635]: this needs optimization, maybe implementing it based on this.assignedSlot
1137
+ return getShadowParent(this, value);
1135
1138
  }
1136
1139
  function parentElementGetterPatched() {
1137
- const value = parentNodeGetter.call(this);
1138
- if (isNull(value)) {
1139
- return null;
1140
- }
1141
- const parentNode = getShadowParent(this, value);
1142
- // it could be that the parentNode is the shadowRoot, in which case
1143
- // we need to return null.
1144
- // TODO [#1635]: this needs optimization, maybe implementing it based on this.assignedSlot
1145
- return parentNode instanceof Element ? parentNode : null;
1140
+ const value = parentNodeGetter.call(this);
1141
+ if (isNull(value)) {
1142
+ return null;
1143
+ }
1144
+ const parentNode = getShadowParent(this, value);
1145
+ // it could be that the parentNode is the shadowRoot, in which case
1146
+ // we need to return null.
1147
+ // TODO [#1635]: this needs optimization, maybe implementing it based on this.assignedSlot
1148
+ return parentNode instanceof Element ? parentNode : null;
1146
1149
  }
1147
1150
  function compareDocumentPositionPatched(otherNode) {
1148
- if (this === otherNode) {
1149
- return 0;
1150
- } else if (this.getRootNode() === otherNode) {
1151
- // "this" is in a shadow tree where the shadow root is the "otherNode".
1152
- return 10; // Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING
1153
- } else if (getNodeOwnerKey(this) !== getNodeOwnerKey(otherNode)) {
1154
- // "this" and "otherNode" belongs to 2 different shadow tree.
1155
- return 35; // Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | Node.DOCUMENT_POSITION_PRECEDING
1156
- }
1157
- // Since "this" and "otherNode" are part of the same shadow tree we can safely rely to the native
1158
- // Node.compareDocumentPosition implementation.
1159
- return compareDocumentPosition.call(this, otherNode);
1151
+ if (this === otherNode) {
1152
+ return 0;
1153
+ }
1154
+ else if (this.getRootNode() === otherNode) {
1155
+ // "this" is in a shadow tree where the shadow root is the "otherNode".
1156
+ return 10; // Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING
1157
+ }
1158
+ else if (getNodeOwnerKey(this) !== getNodeOwnerKey(otherNode)) {
1159
+ // "this" and "otherNode" belongs to 2 different shadow tree.
1160
+ return 35; // Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | Node.DOCUMENT_POSITION_PRECEDING
1161
+ }
1162
+ // Since "this" and "otherNode" are part of the same shadow tree we can safely rely to the native
1163
+ // Node.compareDocumentPosition implementation.
1164
+ return compareDocumentPosition.call(this, otherNode);
1160
1165
  }
1161
1166
  function containsPatched(otherNode) {
1162
- if (otherNode == null || getNodeOwnerKey(this) !== getNodeOwnerKey(otherNode)) {
1163
- // it is from another shadow
1164
- return false;
1165
- }
1166
- return (compareDocumentPosition.call(this, otherNode) & DOCUMENT_POSITION_CONTAINED_BY) !== 0;
1167
+ if (otherNode == null || getNodeOwnerKey(this) !== getNodeOwnerKey(otherNode)) {
1168
+ // it is from another shadow
1169
+ return false;
1170
+ }
1171
+ return (compareDocumentPosition.call(this, otherNode) & DOCUMENT_POSITION_CONTAINED_BY) !== 0;
1167
1172
  }
1168
1173
  function cloneNodePatched(deep) {
1169
- const clone = cloneNode.call(this, false);
1170
- // Per spec, browsers only care about truthy values
1171
- // Not strict true or false
1172
- if (!deep) {
1174
+ const clone = cloneNode.call(this, false);
1175
+ // Per spec, browsers only care about truthy values
1176
+ // Not strict true or false
1177
+ if (!deep) {
1178
+ return clone;
1179
+ }
1180
+ const childNodes = getInternalChildNodes(this);
1181
+ for (let i = 0, len = childNodes.length; i < len; i += 1) {
1182
+ clone.appendChild(childNodes[i].cloneNode(true));
1183
+ }
1173
1184
  return clone;
1174
- }
1175
- const childNodes = getInternalChildNodes(this);
1176
- for (let i = 0, len = childNodes.length; i < len; i += 1) {
1177
- clone.appendChild(childNodes[i].cloneNode(true));
1178
- }
1179
- return clone;
1180
1185
  }
1181
1186
  /**
1182
1187
  * This method only applies to elements with a shadow or slots
1183
1188
  */
1184
1189
  function childNodesGetterPatched() {
1185
- if (isSyntheticShadowHost(this)) {
1186
- const owner = getNodeOwner(this);
1187
- const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
1188
- return createStaticNodeList(childNodes);
1189
- }
1190
- // nothing to do here since this does not have a synthetic shadow attached to it
1191
- // TODO [#1636]: what about slot elements?
1192
- return childNodesGetter.call(this);
1190
+ if (isSyntheticShadowHost(this)) {
1191
+ const owner = getNodeOwner(this);
1192
+ const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
1193
+ return createStaticNodeList(childNodes);
1194
+ }
1195
+ // nothing to do here since this does not have a synthetic shadow attached to it
1196
+ // TODO [#1636]: what about slot elements?
1197
+ return childNodesGetter.call(this);
1193
1198
  }
1194
1199
  const nativeGetRootNode = _Node.prototype.getRootNode;
1195
1200
  /**
@@ -1197,14 +1202,16 @@
1197
1202
  * If Node.prototype.getRootNode is supported, use it
1198
1203
  * else, assume we are working in non-native shadow mode and climb using parentNode
1199
1204
  */
1200
- const getDocumentOrRootNode = !isUndefined(nativeGetRootNode) ? nativeGetRootNode : function () {
1201
- let node = this;
1202
- let nodeParent;
1203
- while (!isNull(nodeParent = parentNodeGetter.call(node))) {
1204
- node = nodeParent;
1205
- }
1206
- return node;
1207
- };
1205
+ const getDocumentOrRootNode = !isUndefined(nativeGetRootNode)
1206
+ ? nativeGetRootNode
1207
+ : function () {
1208
+ let node = this;
1209
+ let nodeParent;
1210
+ while (!isNull((nodeParent = parentNodeGetter.call(node)))) {
1211
+ node = nodeParent;
1212
+ }
1213
+ return node;
1214
+ };
1208
1215
  /**
1209
1216
  * Get the shadow root
1210
1217
  * getNodeOwner() returns the host element that owns the given node
@@ -1215,12 +1222,12 @@
1215
1222
  * @param {Node} node
1216
1223
  */
1217
1224
  function getNearestRoot(node) {
1218
- const ownerNode = getNodeOwner(node);
1219
- if (isNull(ownerNode)) {
1220
- // we hit a wall, either we are in native shadow mode or the node is not in lwc boundary.
1221
- return getDocumentOrRootNode.call(node);
1222
- }
1223
- return getShadowRoot(ownerNode);
1225
+ const ownerNode = getNodeOwner(node);
1226
+ if (isNull(ownerNode)) {
1227
+ // we hit a wall, either we are in native shadow mode or the node is not in lwc boundary.
1228
+ return getDocumentOrRootNode.call(node);
1229
+ }
1230
+ return getShadowRoot(ownerNode);
1224
1231
  }
1225
1232
  /**
1226
1233
  * If looking for a root node beyond shadow root by calling `node.getRootNode({composed: true})`, use the original `Node.prototype.getRootNode` method
@@ -1242,187 +1249,170 @@
1242
1249
  *
1243
1250
  **/
1244
1251
  function getRootNodePatched(options) {
1245
- const composed = isUndefined(options) ? false : !!options.composed;
1246
- return isTrue(composed) ? getDocumentOrRootNode.call(this, options) : getNearestRoot(this);
1252
+ const composed = isUndefined(options) ? false : !!options.composed;
1253
+ return isTrue(composed) ? getDocumentOrRootNode.call(this, options) : getNearestRoot(this);
1247
1254
  }
1248
1255
  // Non-deep-traversing patches: this descriptor map includes all descriptors that
1249
1256
  // do not give access to nodes beyond the immediate children.
1250
1257
  defineProperties(_Node.prototype, {
1251
- firstChild: {
1252
- get() {
1253
- if (hasMountedChildren(this)) {
1254
- return firstChildGetterPatched.call(this);
1255
- }
1256
- return firstChildGetter.call(this);
1258
+ firstChild: {
1259
+ get() {
1260
+ if (hasMountedChildren(this)) {
1261
+ return firstChildGetterPatched.call(this);
1262
+ }
1263
+ return firstChildGetter.call(this);
1264
+ },
1265
+ enumerable: true,
1266
+ configurable: true,
1257
1267
  },
1258
- enumerable: true,
1259
- configurable: true
1260
- },
1261
- lastChild: {
1262
- get() {
1263
- if (hasMountedChildren(this)) {
1264
- return lastChildGetterPatched.call(this);
1265
- }
1266
- return lastChildGetter.call(this);
1268
+ lastChild: {
1269
+ get() {
1270
+ if (hasMountedChildren(this)) {
1271
+ return lastChildGetterPatched.call(this);
1272
+ }
1273
+ return lastChildGetter.call(this);
1274
+ },
1275
+ enumerable: true,
1276
+ configurable: true,
1267
1277
  },
1268
- enumerable: true,
1269
- configurable: true
1270
- },
1271
- textContent: {
1272
- get() {
1273
- if (!lwcRuntimeFlags.ENABLE_NODE_PATCH) {
1274
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1275
- return textContentGetterPatched.call(this);
1276
- }
1277
- return textContentGetter.call(this);
1278
- }
1279
- // TODO [#1222]: remove global bypass
1280
- if (isGlobalPatchingSkipped(this)) {
1281
- return textContentGetter.call(this);
1282
- }
1283
- return textContentGetterPatched.call(this);
1278
+ textContent: {
1279
+ get() {
1280
+ // Note: we deviate from native shadow here, but are not fixing
1281
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
1282
+ if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1283
+ return textContentGetterPatched.call(this);
1284
+ }
1285
+ return textContentGetter.call(this);
1286
+ },
1287
+ set: textContentSetterPatched,
1288
+ enumerable: true,
1289
+ configurable: true,
1284
1290
  },
1285
- set: textContentSetterPatched,
1286
- enumerable: true,
1287
- configurable: true
1288
- },
1289
- parentNode: {
1290
- get() {
1291
- if (isNodeShadowed(this)) {
1292
- return parentNodeGetterPatched.call(this);
1293
- }
1294
- const parentNode = parentNodeGetter.call(this);
1295
- // Handle the case where a top level light DOM element is slotted into a synthetic
1296
- // shadow slot.
1297
- if (!isNull(parentNode) && isSyntheticSlotElement(parentNode)) {
1298
- return getNodeOwner(parentNode);
1299
- }
1300
- return parentNode;
1291
+ parentNode: {
1292
+ get() {
1293
+ if (isNodeShadowed(this)) {
1294
+ return parentNodeGetterPatched.call(this);
1295
+ }
1296
+ const parentNode = parentNodeGetter.call(this);
1297
+ // Handle the case where a top level light DOM element is slotted into a synthetic
1298
+ // shadow slot.
1299
+ if (!isNull(parentNode) && isSyntheticSlotElement(parentNode)) {
1300
+ return getNodeOwner(parentNode);
1301
+ }
1302
+ return parentNode;
1303
+ },
1304
+ enumerable: true,
1305
+ configurable: true,
1301
1306
  },
1302
- enumerable: true,
1303
- configurable: true
1304
- },
1305
- parentElement: {
1306
- get() {
1307
- if (isNodeShadowed(this)) {
1308
- return parentElementGetterPatched.call(this);
1309
- }
1310
- const parentElement = parentElementGetter.call(this);
1311
- // Handle the case where a top level light DOM element is slotted into a synthetic
1312
- // shadow slot.
1313
- if (!isNull(parentElement) && isSyntheticSlotElement(parentElement)) {
1314
- return getNodeOwner(parentElement);
1315
- }
1316
- return parentElement;
1307
+ parentElement: {
1308
+ get() {
1309
+ if (isNodeShadowed(this)) {
1310
+ return parentElementGetterPatched.call(this);
1311
+ }
1312
+ const parentElement = parentElementGetter.call(this);
1313
+ // Handle the case where a top level light DOM element is slotted into a synthetic
1314
+ // shadow slot.
1315
+ if (!isNull(parentElement) && isSyntheticSlotElement(parentElement)) {
1316
+ return getNodeOwner(parentElement);
1317
+ }
1318
+ return parentElement;
1319
+ },
1320
+ enumerable: true,
1321
+ configurable: true,
1317
1322
  },
1318
- enumerable: true,
1319
- configurable: true
1320
- },
1321
- childNodes: {
1322
- get() {
1323
- if (hasMountedChildren(this)) {
1324
- return childNodesGetterPatched.call(this);
1325
- }
1326
- return childNodesGetter.call(this);
1323
+ childNodes: {
1324
+ get() {
1325
+ if (hasMountedChildren(this)) {
1326
+ return childNodesGetterPatched.call(this);
1327
+ }
1328
+ return childNodesGetter.call(this);
1329
+ },
1330
+ enumerable: true,
1331
+ configurable: true,
1327
1332
  },
1328
- enumerable: true,
1329
- configurable: true
1330
- },
1331
- hasChildNodes: {
1332
- value() {
1333
- if (hasMountedChildren(this)) {
1334
- return hasChildNodesPatched.call(this);
1335
- }
1336
- return hasChildNodes.call(this);
1333
+ hasChildNodes: {
1334
+ value() {
1335
+ if (hasMountedChildren(this)) {
1336
+ return hasChildNodesPatched.call(this);
1337
+ }
1338
+ return hasChildNodes.call(this);
1339
+ },
1340
+ enumerable: true,
1341
+ writable: true,
1342
+ configurable: true,
1337
1343
  },
1338
- enumerable: true,
1339
- writable: true,
1340
- configurable: true
1341
- },
1342
- compareDocumentPosition: {
1343
- value(otherNode) {
1344
- // TODO [#1222]: remove global bypass
1345
- if (isGlobalPatchingSkipped(this)) {
1346
- return compareDocumentPosition.call(this, otherNode);
1347
- }
1348
- return compareDocumentPositionPatched.call(this, otherNode);
1344
+ compareDocumentPosition: {
1345
+ value(otherNode) {
1346
+ // Note: we deviate from native shadow here, but are not fixing
1347
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
1348
+ if (isGlobalPatchingSkipped(this)) {
1349
+ return compareDocumentPosition.call(this, otherNode);
1350
+ }
1351
+ return compareDocumentPositionPatched.call(this, otherNode);
1352
+ },
1353
+ enumerable: true,
1354
+ writable: true,
1355
+ configurable: true,
1349
1356
  },
1350
- enumerable: true,
1351
- writable: true,
1352
- configurable: true
1353
- },
1354
- contains: {
1355
- value(otherNode) {
1356
- // 1. Node.prototype.contains() returns true if otherNode is an inclusive descendant
1357
- // spec: https://dom.spec.whatwg.org/#dom-node-contains
1358
- // 2. This normalizes the behavior of this api across all browsers.
1359
- // In IE11, a disconnected dom element without children invoking contains() on self, returns false
1360
- if (this === otherNode) {
1361
- return true;
1362
- }
1363
- if (!lwcRuntimeFlags.ENABLE_NODE_PATCH) {
1364
- if (otherNode == null) {
1365
- return false;
1366
- }
1367
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1368
- return containsPatched.call(this, otherNode);
1369
- }
1370
- return contains.call(this, otherNode);
1371
- }
1372
- // TODO [#1222]: remove global bypass
1373
- if (isGlobalPatchingSkipped(this)) {
1374
- return contains.call(this, otherNode);
1375
- }
1376
- return containsPatched.call(this, otherNode);
1357
+ contains: {
1358
+ value(otherNode) {
1359
+ // 1. Node.prototype.contains() returns true if otherNode is an inclusive descendant
1360
+ // spec: https://dom.spec.whatwg.org/#dom-node-contains
1361
+ // 2. This normalizes the behavior of this api across all browsers.
1362
+ // In IE11, a disconnected dom element without children invoking contains() on self, returns false
1363
+ if (this === otherNode) {
1364
+ return true;
1365
+ }
1366
+ // Note: we deviate from native shadow here, but are not fixing
1367
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
1368
+ if (otherNode == null) {
1369
+ return false;
1370
+ }
1371
+ if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1372
+ return containsPatched.call(this, otherNode);
1373
+ }
1374
+ return contains.call(this, otherNode);
1375
+ },
1376
+ enumerable: true,
1377
+ writable: true,
1378
+ configurable: true,
1377
1379
  },
1378
- enumerable: true,
1379
- writable: true,
1380
- configurable: true
1381
- },
1382
- cloneNode: {
1383
- value(deep) {
1384
- if (!lwcRuntimeFlags.ENABLE_NODE_PATCH) {
1385
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1386
- return cloneNodePatched.call(this, deep);
1387
- }
1388
- return cloneNode.call(this, deep);
1389
- }
1390
- if (isTrue(deep)) {
1391
- // TODO [#1222]: remove global bypass
1392
- if (isGlobalPatchingSkipped(this)) {
1393
- return cloneNode.call(this, deep);
1394
- }
1395
- return cloneNodePatched.call(this, deep);
1396
- }
1397
- return cloneNode.call(this, deep);
1380
+ cloneNode: {
1381
+ value(deep) {
1382
+ // Note: we deviate from native shadow here, but are not fixing
1383
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
1384
+ if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1385
+ return cloneNodePatched.call(this, deep);
1386
+ }
1387
+ return cloneNode.call(this, deep);
1388
+ },
1389
+ enumerable: true,
1390
+ writable: true,
1391
+ configurable: true,
1392
+ },
1393
+ getRootNode: {
1394
+ value: getRootNodePatched,
1395
+ enumerable: true,
1396
+ configurable: true,
1397
+ writable: true,
1398
+ },
1399
+ isConnected: {
1400
+ enumerable: true,
1401
+ configurable: true,
1402
+ get() {
1403
+ return isConnected.call(this);
1404
+ },
1398
1405
  },
1399
- enumerable: true,
1400
- writable: true,
1401
- configurable: true
1402
- },
1403
- getRootNode: {
1404
- value: getRootNodePatched,
1405
- enumerable: true,
1406
- configurable: true,
1407
- writable: true
1408
- },
1409
- isConnected: {
1410
- enumerable: true,
1411
- configurable: true,
1412
- get() {
1413
- return isConnected.call(this);
1414
- }
1415
- }
1416
1406
  });
1417
1407
  const getInternalChildNodes = function (node) {
1418
- return node.childNodes;
1419
- };
1408
+ return node.childNodes;
1409
+ };
1420
1410
  // IE11 extra patches for wrong prototypes
1421
1411
  if (hasOwnProperty.call(HTMLElement.prototype, 'contains')) {
1422
- defineProperty(HTMLElement.prototype, 'contains', getOwnPropertyDescriptor(_Node.prototype, 'contains'));
1412
+ defineProperty(HTMLElement.prototype, 'contains', getOwnPropertyDescriptor(_Node.prototype, 'contains'));
1423
1413
  }
1424
1414
  if (hasOwnProperty.call(HTMLElement.prototype, 'parentElement')) {
1425
- defineProperty(HTMLElement.prototype, 'parentElement', getOwnPropertyDescriptor(_Node.prototype, 'parentElement'));
1415
+ defineProperty(HTMLElement.prototype, 'parentElement', getOwnPropertyDescriptor(_Node.prototype, 'parentElement'));
1426
1416
  }
1427
1417
 
1428
1418
  /*
@@ -2340,7 +2330,8 @@
2340
2330
  if (isNull(elm)) {
2341
2331
  return null;
2342
2332
  }
2343
- // TODO [#1222]: remove global bypass
2333
+ // Note: we deviate from native shadow here, but are not fixing
2334
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2344
2335
  return isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm) ? elm : null;
2345
2336
  },
2346
2337
  writable: true,
@@ -2351,7 +2342,8 @@
2351
2342
  value() {
2352
2343
  const elements = arrayFromCollection(querySelectorAll.apply(this, ArraySlice.call(arguments)));
2353
2344
  const filtered = ArrayFind.call(elements,
2354
- // TODO [#1222]: remove global bypass
2345
+ // Note: we deviate from native shadow here, but are not fixing
2346
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2355
2347
  (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2356
2348
  return !isUndefined(filtered) ? filtered : null;
2357
2349
  },
@@ -2363,7 +2355,8 @@
2363
2355
  value() {
2364
2356
  const elements = arrayFromCollection(querySelectorAll.apply(this, ArraySlice.call(arguments)));
2365
2357
  const filtered = ArrayFilter.call(elements,
2366
- // TODO [#1222]: remove global bypass
2358
+ // Note: we deviate from native shadow here, but are not fixing
2359
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2367
2360
  (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2368
2361
  return createStaticNodeList(filtered);
2369
2362
  },
@@ -2375,7 +2368,8 @@
2375
2368
  value() {
2376
2369
  const elements = arrayFromCollection(getElementsByClassName.apply(this, ArraySlice.call(arguments)));
2377
2370
  const filtered = ArrayFilter.call(elements,
2378
- // TODO [#1222]: remove global bypass
2371
+ // Note: we deviate from native shadow here, but are not fixing
2372
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2379
2373
  (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2380
2374
  return createStaticHTMLCollection(filtered);
2381
2375
  },
@@ -2387,7 +2381,8 @@
2387
2381
  value() {
2388
2382
  const elements = arrayFromCollection(getElementsByTagName.apply(this, ArraySlice.call(arguments)));
2389
2383
  const filtered = ArrayFilter.call(elements,
2390
- // TODO [#1222]: remove global bypass
2384
+ // Note: we deviate from native shadow here, but are not fixing
2385
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2391
2386
  (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2392
2387
  return createStaticHTMLCollection(filtered);
2393
2388
  },
@@ -2399,7 +2394,8 @@
2399
2394
  value() {
2400
2395
  const elements = arrayFromCollection(getElementsByTagNameNS.apply(this, ArraySlice.call(arguments)));
2401
2396
  const filtered = ArrayFilter.call(elements,
2402
- // TODO [#1222]: remove global bypass
2397
+ // Note: we deviate from native shadow here, but are not fixing
2398
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2403
2399
  (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2404
2400
  return createStaticHTMLCollection(filtered);
2405
2401
  },
@@ -2415,7 +2411,8 @@
2415
2411
  value() {
2416
2412
  const elements = arrayFromCollection(getElementsByName.apply(this, ArraySlice.call(arguments)));
2417
2413
  const filtered = ArrayFilter.call(elements,
2418
- // TODO [#1222]: remove global bypass
2414
+ // Note: we deviate from native shadow here, but are not fixing
2415
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2419
2416
  (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2420
2417
  return createStaticNodeList(filtered);
2421
2418
  },
@@ -3514,7 +3511,8 @@
3514
3511
  else if (context instanceof HTMLBodyElement) {
3515
3512
  // `context` is document.body which is already patched.
3516
3513
  filtered = ArrayFilter.call(unfilteredNodes,
3517
- // TODO [#1222]: remove global bypass
3514
+ // Note: we deviate from native shadow here, but are not fixing
3515
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3518
3516
  (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(context));
3519
3517
  }
3520
3518
  else {
@@ -3531,247 +3529,233 @@
3531
3529
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3532
3530
  */
3533
3531
  function innerHTMLGetterPatched() {
3534
- const childNodes = getInternalChildNodes(this);
3535
- let innerHTML = '';
3536
- for (let i = 0, len = childNodes.length; i < len; i += 1) {
3537
- innerHTML += getOuterHTML(childNodes[i]);
3538
- }
3539
- return innerHTML;
3532
+ const childNodes = getInternalChildNodes(this);
3533
+ let innerHTML = '';
3534
+ for (let i = 0, len = childNodes.length; i < len; i += 1) {
3535
+ innerHTML += getOuterHTML(childNodes[i]);
3536
+ }
3537
+ return innerHTML;
3540
3538
  }
3541
3539
  function outerHTMLGetterPatched() {
3542
- return getOuterHTML(this);
3540
+ return getOuterHTML(this);
3543
3541
  }
3544
3542
  function attachShadowPatched(options) {
3545
- // To retain native behavior of the API, provide synthetic shadowRoot only when specified
3546
- if (options[KEY__SYNTHETIC_MODE]) {
3547
- return attachShadow(this, options);
3548
- }
3549
- return attachShadow$1.call(this, options);
3543
+ // To retain native behavior of the API, provide synthetic shadowRoot only when specified
3544
+ if (options[KEY__SYNTHETIC_MODE]) {
3545
+ return attachShadow(this, options);
3546
+ }
3547
+ return attachShadow$1.call(this, options);
3550
3548
  }
3551
3549
  function shadowRootGetterPatched() {
3552
- if (isSyntheticShadowHost(this)) {
3553
- const shadow = getShadowRoot(this);
3554
- if (shadow.mode === 'open') {
3555
- return shadow;
3550
+ if (isSyntheticShadowHost(this)) {
3551
+ const shadow = getShadowRoot(this);
3552
+ if (shadow.mode === 'open') {
3553
+ return shadow;
3554
+ }
3556
3555
  }
3557
- }
3558
- return shadowRootGetter.call(this);
3556
+ return shadowRootGetter.call(this);
3559
3557
  }
3560
3558
  function childrenGetterPatched() {
3561
- const owner = getNodeOwner(this);
3562
- const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
3563
- return createStaticHTMLCollection(ArrayFilter.call(childNodes, node => node instanceof Element));
3559
+ const owner = getNodeOwner(this);
3560
+ const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
3561
+ return createStaticHTMLCollection(ArrayFilter.call(childNodes, (node) => node instanceof Element));
3564
3562
  }
3565
3563
  function childElementCountGetterPatched() {
3566
- return this.children.length;
3564
+ return this.children.length;
3567
3565
  }
3568
3566
  function firstElementChildGetterPatched() {
3569
- return this.children[0] || null;
3567
+ return this.children[0] || null;
3570
3568
  }
3571
3569
  function lastElementChildGetterPatched() {
3572
- const {
3573
- children
3574
- } = this;
3575
- return children.item(children.length - 1) || null;
3570
+ const { children } = this;
3571
+ return children.item(children.length - 1) || null;
3576
3572
  }
3577
3573
  // Non-deep-traversing patches: this descriptor map includes all descriptors that
3578
3574
  // do not five access to nodes beyond the immediate children.
3579
3575
  defineProperties(Element.prototype, {
3580
- innerHTML: {
3581
- get() {
3582
- if (!lwcRuntimeFlags.ENABLE_ELEMENT_PATCH) {
3583
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
3584
- return innerHTMLGetterPatched.call(this);
3585
- }
3586
- return innerHTMLGetter.call(this);
3587
- }
3588
- // TODO [#1222]: remove global bypass
3589
- if (isGlobalPatchingSkipped(this)) {
3590
- return innerHTMLGetter.call(this);
3591
- }
3592
- return innerHTMLGetterPatched.call(this);
3576
+ innerHTML: {
3577
+ get() {
3578
+ // Note: we deviate from native shadow here, but are not fixing
3579
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3580
+ if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
3581
+ return innerHTMLGetterPatched.call(this);
3582
+ }
3583
+ return innerHTMLGetter.call(this);
3584
+ },
3585
+ set(v) {
3586
+ innerHTMLSetter.call(this, v);
3587
+ },
3588
+ enumerable: true,
3589
+ configurable: true,
3593
3590
  },
3594
- set(v) {
3595
- innerHTMLSetter.call(this, v);
3591
+ outerHTML: {
3592
+ get() {
3593
+ // Note: we deviate from native shadow here, but are not fixing
3594
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3595
+ if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
3596
+ return outerHTMLGetterPatched.call(this);
3597
+ }
3598
+ return outerHTMLGetter.call(this);
3599
+ },
3600
+ set(v) {
3601
+ outerHTMLSetter.call(this, v);
3602
+ },
3603
+ enumerable: true,
3604
+ configurable: true,
3596
3605
  },
3597
- enumerable: true,
3598
- configurable: true
3599
- },
3600
- outerHTML: {
3601
- get() {
3602
- if (!lwcRuntimeFlags.ENABLE_ELEMENT_PATCH) {
3603
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
3604
- return outerHTMLGetterPatched.call(this);
3605
- }
3606
- return outerHTMLGetter.call(this);
3607
- }
3608
- // TODO [#1222]: remove global bypass
3609
- if (isGlobalPatchingSkipped(this)) {
3610
- return outerHTMLGetter.call(this);
3611
- }
3612
- return outerHTMLGetterPatched.call(this);
3606
+ attachShadow: {
3607
+ value: attachShadowPatched,
3608
+ enumerable: true,
3609
+ writable: true,
3610
+ configurable: true,
3613
3611
  },
3614
- set(v) {
3615
- outerHTMLSetter.call(this, v);
3612
+ shadowRoot: {
3613
+ get: shadowRootGetterPatched,
3614
+ enumerable: true,
3615
+ configurable: true,
3616
3616
  },
3617
- enumerable: true,
3618
- configurable: true
3619
- },
3620
- attachShadow: {
3621
- value: attachShadowPatched,
3622
- enumerable: true,
3623
- writable: true,
3624
- configurable: true
3625
- },
3626
- shadowRoot: {
3627
- get: shadowRootGetterPatched,
3628
- enumerable: true,
3629
- configurable: true
3630
- },
3631
- // patched in HTMLElement if exists (IE11 is the one off here)
3632
- children: {
3633
- get() {
3634
- if (hasMountedChildren(this)) {
3635
- return childrenGetterPatched.call(this);
3636
- }
3637
- return childrenGetter.call(this);
3617
+ // patched in HTMLElement if exists (IE11 is the one off here)
3618
+ children: {
3619
+ get() {
3620
+ if (hasMountedChildren(this)) {
3621
+ return childrenGetterPatched.call(this);
3622
+ }
3623
+ return childrenGetter.call(this);
3624
+ },
3625
+ enumerable: true,
3626
+ configurable: true,
3638
3627
  },
3639
- enumerable: true,
3640
- configurable: true
3641
- },
3642
- childElementCount: {
3643
- get() {
3644
- if (hasMountedChildren(this)) {
3645
- return childElementCountGetterPatched.call(this);
3646
- }
3647
- return childElementCountGetter.call(this);
3628
+ childElementCount: {
3629
+ get() {
3630
+ if (hasMountedChildren(this)) {
3631
+ return childElementCountGetterPatched.call(this);
3632
+ }
3633
+ return childElementCountGetter.call(this);
3634
+ },
3635
+ enumerable: true,
3636
+ configurable: true,
3648
3637
  },
3649
- enumerable: true,
3650
- configurable: true
3651
- },
3652
- firstElementChild: {
3653
- get() {
3654
- if (hasMountedChildren(this)) {
3655
- return firstElementChildGetterPatched.call(this);
3656
- }
3657
- return firstElementChildGetter.call(this);
3638
+ firstElementChild: {
3639
+ get() {
3640
+ if (hasMountedChildren(this)) {
3641
+ return firstElementChildGetterPatched.call(this);
3642
+ }
3643
+ return firstElementChildGetter.call(this);
3644
+ },
3645
+ enumerable: true,
3646
+ configurable: true,
3658
3647
  },
3659
- enumerable: true,
3660
- configurable: true
3661
- },
3662
- lastElementChild: {
3663
- get() {
3664
- if (hasMountedChildren(this)) {
3665
- return lastElementChildGetterPatched.call(this);
3666
- }
3667
- return lastElementChildGetter.call(this);
3648
+ lastElementChild: {
3649
+ get() {
3650
+ if (hasMountedChildren(this)) {
3651
+ return lastElementChildGetterPatched.call(this);
3652
+ }
3653
+ return lastElementChildGetter.call(this);
3654
+ },
3655
+ enumerable: true,
3656
+ configurable: true,
3657
+ },
3658
+ assignedSlot: {
3659
+ get: assignedSlotGetterPatched,
3660
+ enumerable: true,
3661
+ configurable: true,
3668
3662
  },
3669
- enumerable: true,
3670
- configurable: true
3671
- },
3672
- assignedSlot: {
3673
- get: assignedSlotGetterPatched,
3674
- enumerable: true,
3675
- configurable: true
3676
- }
3677
3663
  });
3678
3664
  // IE11 extra patches for wrong prototypes
3679
3665
  if (hasOwnProperty.call(HTMLElement.prototype, 'innerHTML')) {
3680
- defineProperty(HTMLElement.prototype, 'innerHTML', getOwnPropertyDescriptor(Element.prototype, 'innerHTML'));
3666
+ defineProperty(HTMLElement.prototype, 'innerHTML', getOwnPropertyDescriptor(Element.prototype, 'innerHTML'));
3681
3667
  }
3682
3668
  if (hasOwnProperty.call(HTMLElement.prototype, 'outerHTML')) {
3683
- defineProperty(HTMLElement.prototype, 'outerHTML', getOwnPropertyDescriptor(Element.prototype, 'outerHTML'));
3669
+ defineProperty(HTMLElement.prototype, 'outerHTML', getOwnPropertyDescriptor(Element.prototype, 'outerHTML'));
3684
3670
  }
3685
3671
  if (hasOwnProperty.call(HTMLElement.prototype, 'children')) {
3686
- defineProperty(HTMLElement.prototype, 'children', getOwnPropertyDescriptor(Element.prototype, 'children'));
3672
+ defineProperty(HTMLElement.prototype, 'children', getOwnPropertyDescriptor(Element.prototype, 'children'));
3687
3673
  }
3688
3674
  // Deep-traversing patches from this point on:
3689
3675
  function querySelectorPatched() {
3690
- const nodeList = arrayFromCollection(querySelectorAll$1.apply(this, ArraySlice.call(arguments)));
3691
- if (isSyntheticShadowHost(this)) {
3692
- // element with shadowRoot attached
3693
- const owner = getNodeOwner(this);
3694
- if (!isUndefined(getNodeKey(this))) {
3695
- // it is a custom element, and we should then filter by slotted elements
3696
- return getFirstSlottedMatch(this, nodeList);
3697
- } else if (isNull(owner)) {
3698
- return null;
3699
- } else {
3700
- // regular element, we should then filter by ownership
3701
- return getFirstMatch(owner, nodeList);
3676
+ const nodeList = arrayFromCollection(querySelectorAll$1.apply(this, ArraySlice.call(arguments)));
3677
+ if (isSyntheticShadowHost(this)) {
3678
+ // element with shadowRoot attached
3679
+ const owner = getNodeOwner(this);
3680
+ if (!isUndefined(getNodeKey(this))) {
3681
+ // it is a custom element, and we should then filter by slotted elements
3682
+ return getFirstSlottedMatch(this, nodeList);
3683
+ }
3684
+ else if (isNull(owner)) {
3685
+ return null;
3686
+ }
3687
+ else {
3688
+ // regular element, we should then filter by ownership
3689
+ return getFirstMatch(owner, nodeList);
3690
+ }
3702
3691
  }
3703
- } else if (isNodeShadowed(this)) {
3704
- // element inside a shadowRoot
3705
- const ownerKey = getNodeOwnerKey(this);
3706
- if (!isUndefined(ownerKey)) {
3707
- // `this` is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
3708
- const elm = ArrayFind.call(nodeList, elm => getNodeNearestOwnerKey(elm) === ownerKey);
3709
- return isUndefined(elm) ? null : elm;
3710
- } else {
3711
- if (!lwcRuntimeFlags.ENABLE_NODE_LIST_PATCH) {
3712
- // `this` is a manually inserted element inside a shadowRoot, return the first element.
3713
- return nodeList.length === 0 ? null : nodeList[0];
3714
- }
3715
- // Element is inside a shadow but we dont know which one. Use the
3716
- // "nearest" owner key to filter by ownership.
3717
- const contextNearestOwnerKey = getNodeNearestOwnerKey(this);
3718
- const elm = ArrayFind.call(nodeList, elm => getNodeNearestOwnerKey(elm) === contextNearestOwnerKey);
3719
- return isUndefined(elm) ? null : elm;
3692
+ else if (isNodeShadowed(this)) {
3693
+ // element inside a shadowRoot
3694
+ const ownerKey = getNodeOwnerKey(this);
3695
+ if (!isUndefined(ownerKey)) {
3696
+ // `this` is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
3697
+ const elm = ArrayFind.call(nodeList, (elm) => getNodeNearestOwnerKey(elm) === ownerKey);
3698
+ return isUndefined(elm) ? null : elm;
3699
+ }
3700
+ else {
3701
+ // Note: we deviate from native shadow here, but are not fixing
3702
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3703
+ // `this` is a manually inserted element inside a shadowRoot, return the first element.
3704
+ return nodeList.length === 0 ? null : nodeList[0];
3705
+ }
3720
3706
  }
3721
- } else {
3722
- if (!lwcRuntimeFlags.ENABLE_NODE_LIST_PATCH) {
3723
- if (!(this instanceof HTMLBodyElement)) {
3724
- const elm = nodeList[0];
3707
+ else {
3708
+ if (!(this instanceof HTMLBodyElement)) {
3709
+ const elm = nodeList[0];
3710
+ return isUndefined(elm) ? null : elm;
3711
+ }
3712
+ // element belonging to the document
3713
+ const elm = ArrayFind.call(nodeList, (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(this));
3725
3714
  return isUndefined(elm) ? null : elm;
3726
- }
3727
3715
  }
3728
- // element belonging to the document
3729
- const elm = ArrayFind.call(nodeList,
3730
- // TODO [#1222]: remove global bypass
3731
- elm => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(this));
3732
- return isUndefined(elm) ? null : elm;
3733
- }
3734
3716
  }
3735
- function getFilteredArrayOfNodes(context, unfilteredNodes, shadowDomSemantic) {
3736
- let filtered;
3737
- if (isSyntheticShadowHost(context)) {
3738
- // element with shadowRoot attached
3739
- const owner = getNodeOwner(context);
3740
- if (!isUndefined(getNodeKey(context))) {
3741
- // it is a custom element, and we should then filter by slotted elements
3742
- filtered = getAllSlottedMatches(context, unfilteredNodes);
3743
- } else if (isNull(owner)) {
3744
- filtered = [];
3745
- } else {
3746
- // regular element, we should then filter by ownership
3747
- filtered = getAllMatches(owner, unfilteredNodes);
3717
+ function getFilteredArrayOfNodes(context, unfilteredNodes) {
3718
+ let filtered;
3719
+ if (isSyntheticShadowHost(context)) {
3720
+ // element with shadowRoot attached
3721
+ const owner = getNodeOwner(context);
3722
+ if (!isUndefined(getNodeKey(context))) {
3723
+ // it is a custom element, and we should then filter by slotted elements
3724
+ filtered = getAllSlottedMatches(context, unfilteredNodes);
3725
+ }
3726
+ else if (isNull(owner)) {
3727
+ filtered = [];
3728
+ }
3729
+ else {
3730
+ // regular element, we should then filter by ownership
3731
+ filtered = getAllMatches(owner, unfilteredNodes);
3732
+ }
3748
3733
  }
3749
- } else if (isNodeShadowed(context)) {
3750
- // element inside a shadowRoot
3751
- const ownerKey = getNodeOwnerKey(context);
3752
- if (!isUndefined(ownerKey)) {
3753
- // context is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
3754
- filtered = ArrayFilter.call(unfilteredNodes, elm => getNodeNearestOwnerKey(elm) === ownerKey);
3755
- } else if (shadowDomSemantic === 1 /* ShadowDomSemantic.Enabled */) {
3756
- // context is inside a shadow, we dont know which one.
3757
- const contextNearestOwnerKey = getNodeNearestOwnerKey(context);
3758
- filtered = ArrayFilter.call(unfilteredNodes, elm => getNodeNearestOwnerKey(elm) === contextNearestOwnerKey);
3759
- } else {
3760
- // context is manually inserted without lwc:dom-manual and ShadowDomSemantics is off, return everything
3761
- filtered = ArraySlice.call(unfilteredNodes);
3734
+ else if (isNodeShadowed(context)) {
3735
+ // element inside a shadowRoot
3736
+ const ownerKey = getNodeOwnerKey(context);
3737
+ if (!isUndefined(ownerKey)) {
3738
+ // context is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
3739
+ filtered = ArrayFilter.call(unfilteredNodes, (elm) => getNodeNearestOwnerKey(elm) === ownerKey);
3740
+ }
3741
+ else {
3742
+ // Note: we deviate from native shadow here, but are not fixing
3743
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3744
+ // context is manually inserted without lwc:dom-manual, return everything
3745
+ filtered = ArraySlice.call(unfilteredNodes);
3746
+ }
3762
3747
  }
3763
- } else {
3764
- if (context instanceof HTMLBodyElement || shadowDomSemantic === 1 /* ShadowDomSemantic.Enabled */) {
3765
- // `context` is document.body or element belonging to the document with the patch enabled
3766
- filtered = ArrayFilter.call(unfilteredNodes,
3767
- // TODO [#1222]: remove global bypass
3768
- elm => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(context));
3769
- } else {
3770
- // `context` is outside the lwc boundary and patch is not enabled.
3771
- filtered = ArraySlice.call(unfilteredNodes);
3748
+ else {
3749
+ if (context instanceof HTMLBodyElement) {
3750
+ // `context` is document.body or element belonging to the document with the patch enabled
3751
+ filtered = ArrayFilter.call(unfilteredNodes, (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(context));
3752
+ }
3753
+ else {
3754
+ // `context` is outside the lwc boundary and patch is not enabled.
3755
+ filtered = ArraySlice.call(unfilteredNodes);
3756
+ }
3772
3757
  }
3773
- }
3774
- return filtered;
3758
+ return filtered;
3775
3759
  }
3776
3760
  // The following patched methods hide shadowed elements from global
3777
3761
  // traversing mechanisms. They are simplified for performance reasons to
@@ -3783,263 +3767,66 @@
3783
3767
  // is not a big problem considering the amount of code that is relying on
3784
3768
  // the liveliness of these results are rare.
3785
3769
  defineProperties(Element.prototype, {
3786
- querySelector: {
3787
- value: querySelectorPatched,
3788
- writable: true,
3789
- enumerable: true,
3790
- configurable: true
3791
- },
3792
- querySelectorAll: {
3793
- value() {
3794
- const nodeList = arrayFromCollection(querySelectorAll$1.apply(this, ArraySlice.call(arguments)));
3795
- if (!lwcRuntimeFlags.ENABLE_NODE_LIST_PATCH) {
3796
- const filteredResults = getFilteredArrayOfNodes(this, nodeList, 0 /* ShadowDomSemantic.Disabled */);
3797
- return createStaticNodeList(filteredResults);
3798
- }
3799
- return createStaticNodeList(getFilteredArrayOfNodes(this, nodeList, 1 /* ShadowDomSemantic.Enabled */));
3770
+ querySelector: {
3771
+ value: querySelectorPatched,
3772
+ writable: true,
3773
+ enumerable: true,
3774
+ configurable: true,
3775
+ },
3776
+ querySelectorAll: {
3777
+ value() {
3778
+ const nodeList = arrayFromCollection(querySelectorAll$1.apply(this, ArraySlice.call(arguments)));
3779
+ // Note: we deviate from native shadow here, but are not fixing
3780
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3781
+ const filteredResults = getFilteredArrayOfNodes(this, nodeList);
3782
+ return createStaticNodeList(filteredResults);
3783
+ },
3784
+ writable: true,
3785
+ enumerable: true,
3786
+ configurable: true,
3800
3787
  },
3801
-
3802
- writable: true,
3803
- enumerable: true,
3804
- configurable: true
3805
- }
3806
3788
  });
3807
3789
  // The following APIs are used directly by Jest internally so we avoid patching them during testing.
3808
3790
  {
3809
- defineProperties(Element.prototype, {
3810
- getElementsByClassName: {
3811
- value() {
3812
- const elements = arrayFromCollection(getElementsByClassName$1.apply(this, ArraySlice.call(arguments)));
3813
- if (!lwcRuntimeFlags.ENABLE_HTML_COLLECTIONS_PATCH) {
3814
- return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
3815
- }
3816
- const filteredResults = getFilteredArrayOfNodes(this, elements, 1 /* ShadowDomSemantic.Enabled */);
3817
- return createStaticHTMLCollection(filteredResults);
3818
- },
3819
- writable: true,
3820
- enumerable: true,
3821
- configurable: true
3822
- },
3823
- getElementsByTagName: {
3824
- value() {
3825
- const elements = arrayFromCollection(getElementsByTagName$1.apply(this, ArraySlice.call(arguments)));
3826
- if (!lwcRuntimeFlags.ENABLE_HTML_COLLECTIONS_PATCH) {
3827
- return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
3828
- }
3829
- const filteredResults = getFilteredArrayOfNodes(this, elements, 1 /* ShadowDomSemantic.Enabled */);
3830
- return createStaticHTMLCollection(filteredResults);
3831
- },
3832
- writable: true,
3833
- enumerable: true,
3834
- configurable: true
3835
- },
3836
- getElementsByTagNameNS: {
3837
- value() {
3838
- const elements = arrayFromCollection(getElementsByTagNameNS$1.apply(this, ArraySlice.call(arguments)));
3839
- if (!lwcRuntimeFlags.ENABLE_HTML_COLLECTIONS_PATCH) {
3840
- return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
3841
- }
3842
- const filteredResults = getFilteredArrayOfNodes(this, elements, 1 /* ShadowDomSemantic.Enabled */);
3843
- return createStaticHTMLCollection(filteredResults);
3844
- },
3845
- writable: true,
3846
- enumerable: true,
3847
- configurable: true
3848
- }
3849
- });
3791
+ defineProperties(Element.prototype, {
3792
+ getElementsByClassName: {
3793
+ value() {
3794
+ const elements = arrayFromCollection(getElementsByClassName$1.apply(this, ArraySlice.call(arguments)));
3795
+ // Note: we deviate from native shadow here, but are not fixing
3796
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3797
+ return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
3798
+ },
3799
+ writable: true,
3800
+ enumerable: true,
3801
+ configurable: true,
3802
+ },
3803
+ getElementsByTagName: {
3804
+ value() {
3805
+ const elements = arrayFromCollection(getElementsByTagName$1.apply(this, ArraySlice.call(arguments)));
3806
+ // Note: we deviate from native shadow here, but are not fixing
3807
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3808
+ return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
3809
+ },
3810
+ writable: true,
3811
+ enumerable: true,
3812
+ configurable: true,
3813
+ },
3814
+ getElementsByTagNameNS: {
3815
+ value() {
3816
+ const elements = arrayFromCollection(getElementsByTagNameNS$1.apply(this, ArraySlice.call(arguments)));
3817
+ // Note: we deviate from native shadow here, but are not fixing
3818
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3819
+ return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
3820
+ },
3821
+ writable: true,
3822
+ enumerable: true,
3823
+ configurable: true,
3824
+ },
3825
+ });
3850
3826
  }
3851
3827
  // IE11 extra patches for wrong prototypes
3852
3828
  if (hasOwnProperty.call(HTMLElement.prototype, 'getElementsByClassName')) {
3853
- defineProperty(HTMLElement.prototype, 'getElementsByClassName', getOwnPropertyDescriptor(Element.prototype, 'getElementsByClassName'));
3854
- }
3855
-
3856
- /*
3857
- * Copyright (c) 2018, salesforce.com, inc.
3858
- * All rights reserved.
3859
- * SPDX-License-Identifier: MIT
3860
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3861
- */
3862
- function getElementComputedStyle(element) {
3863
- const win = getOwnerWindow(element);
3864
- return windowGetComputedStyle.call(win, element);
3865
- }
3866
- function getWindowSelection(node) {
3867
- const win = getOwnerWindow(node);
3868
- return windowGetSelection.call(win);
3869
- }
3870
- function nodeIsBeingRendered(nodeComputedStyle) {
3871
- return nodeComputedStyle.visibility === 'visible' && nodeComputedStyle.display !== 'none';
3872
- }
3873
- function getSelectionState(element) {
3874
- const win = getOwnerWindow(element);
3875
- const selection = getWindowSelection(element);
3876
- if (selection === null) {
3877
- return null;
3878
- }
3879
- const ranges = [];
3880
- for (let i = 0; i < selection.rangeCount; i++) {
3881
- ranges.push(selection.getRangeAt(i));
3882
- }
3883
- const state = {
3884
- element,
3885
- onselect: win.onselect,
3886
- onselectstart: win.onselectstart,
3887
- onselectionchange: win.onselectionchange,
3888
- ranges,
3889
- };
3890
- win.onselect = null;
3891
- win.onselectstart = null;
3892
- win.onselectionchange = null;
3893
- return state;
3894
- }
3895
- function restoreSelectionState(state) {
3896
- if (state === null) {
3897
- return;
3898
- }
3899
- const { element, onselect, onselectstart, onselectionchange, ranges } = state;
3900
- const win = getOwnerWindow(element);
3901
- const selection = getWindowSelection(element);
3902
- selection.removeAllRanges();
3903
- for (let i = 0; i < ranges.length; i++) {
3904
- selection.addRange(ranges[i]);
3905
- }
3906
- win.onselect = onselect;
3907
- win.onselectstart = onselectstart;
3908
- win.onselectionchange = onselectionchange;
3909
- }
3910
- /**
3911
- * Gets the "innerText" of a text node using the Selection API
3912
- *
3913
- * NOTE: For performance reasons, since this function will be called multiple times while calculating the innerText of
3914
- * an element, it does not restore the current selection.
3915
- */
3916
- function getTextNodeInnerText(textNode) {
3917
- const selection = getWindowSelection(textNode);
3918
- if (selection === null) {
3919
- return textNode.textContent || '';
3920
- }
3921
- const range = document.createRange();
3922
- range.selectNodeContents(textNode);
3923
- const domRect = range.getBoundingClientRect();
3924
- if (domRect.height <= 0 || domRect.width <= 0) {
3925
- // the text node is not rendered
3926
- return '';
3927
- }
3928
- // Needed to remove non rendered characters from the text node.
3929
- selection.removeAllRanges();
3930
- selection.addRange(range);
3931
- const selectionText = selection.toString();
3932
- // The textNode is visible, but it may not be selectable. When the text is not selectable,
3933
- // textContent is the nearest approximation to innerText.
3934
- return selectionText ? selectionText : textNode.textContent || '';
3935
- }
3936
- const nodeIsElement = (node) => node.nodeType === ELEMENT_NODE;
3937
- const nodeIsText = (node) => node.nodeType === TEXT_NODE;
3938
- /**
3939
- * Spec: https://html.spec.whatwg.org/multipage/dom.html#inner-text-collection-steps
3940
- * One spec implementation: https://github.com/servo/servo/blob/721271dcd3c20db5ca8cf146e2b5907647afb4d6/components/layout/query.rs#L1132
3941
- */
3942
- function innerTextCollectionSteps(node) {
3943
- const items = [];
3944
- if (nodeIsElement(node)) {
3945
- const { tagName } = node;
3946
- const computedStyle = getElementComputedStyle(node);
3947
- if (tagName === 'OPTION') {
3948
- // For options, is hard to get the "rendered" text, let's use the original getter.
3949
- return [1, innerTextGetter.call(node), 1];
3950
- }
3951
- else if (tagName === 'TEXTAREA') {
3952
- return [];
3953
- }
3954
- else {
3955
- const childNodes = node.childNodes;
3956
- for (let i = 0, n = childNodes.length; i < n; i++) {
3957
- ArrayPush.apply(items, innerTextCollectionSteps(childNodes[i]));
3958
- }
3959
- }
3960
- if (!nodeIsBeingRendered(computedStyle)) {
3961
- if (tagName === 'SELECT' || tagName === 'DATALIST') {
3962
- // the select is either: .visibility != 'visible' or .display === hidden, therefore this select should
3963
- // not display any value.
3964
- return [];
3965
- }
3966
- return items;
3967
- }
3968
- if (tagName === 'BR') {
3969
- items.push('\u{000A}' /* line feed */);
3970
- }
3971
- const { display } = computedStyle;
3972
- if (display === 'table-cell') {
3973
- // omitting case: and node's CSS box is not the last 'table-cell' box of its enclosing 'table-row' box
3974
- items.push('\u{0009}' /* tab */);
3975
- }
3976
- if (display === 'table-row') {
3977
- // omitting case: and node's CSS box is not the last 'table-row' box of the nearest ancestor 'table' box
3978
- items.push('\u{000A}' /* line feed */);
3979
- }
3980
- if (tagName === 'P') {
3981
- items.unshift(2);
3982
- items.push(2);
3983
- }
3984
- if (display === 'block' ||
3985
- display === 'table-caption' ||
3986
- display === 'flex' ||
3987
- display === 'table') {
3988
- items.unshift(1);
3989
- items.push(1);
3990
- }
3991
- }
3992
- else if (nodeIsText(node)) {
3993
- items.push(getTextNodeInnerText(node));
3994
- }
3995
- return items;
3996
- }
3997
- /**
3998
- * InnerText getter spec: https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute
3999
- *
4000
- * One spec implementation: https://github.com/servo/servo/blob/721271dcd3c20db5ca8cf146e2b5907647afb4d6/components/layout/query.rs#L1087
4001
- */
4002
- function getInnerText(element) {
4003
- const thisComputedStyle = getElementComputedStyle(element);
4004
- if (!nodeIsBeingRendered(thisComputedStyle)) {
4005
- return getTextContent(element) || '';
4006
- }
4007
- const selectionState = getSelectionState(element);
4008
- const results = [];
4009
- const childNodes = element.childNodes;
4010
- for (let i = 0, n = childNodes.length; i < n; i++) {
4011
- ArrayPush.apply(results, innerTextCollectionSteps(childNodes[i]));
4012
- }
4013
- restoreSelectionState(selectionState);
4014
- let elementInnerText = '';
4015
- let maxReqLineBreakCount = 0;
4016
- for (let i = 0, n = results.length; i < n; i++) {
4017
- const item = results[i];
4018
- if (typeof item === 'string') {
4019
- if (maxReqLineBreakCount > 0) {
4020
- for (let j = 0; j < maxReqLineBreakCount; j++) {
4021
- elementInnerText += '\u{000A}';
4022
- }
4023
- maxReqLineBreakCount = 0;
4024
- }
4025
- if (item.length > 0) {
4026
- elementInnerText += item;
4027
- }
4028
- }
4029
- else {
4030
- if (elementInnerText.length == 0) {
4031
- // Remove required line break count at the start.
4032
- continue;
4033
- }
4034
- // Store the count if it's the max of this run,
4035
- // but it may be ignored if no text item is found afterwards,
4036
- // which means that these are consecutive line breaks at the end.
4037
- if (item > maxReqLineBreakCount) {
4038
- maxReqLineBreakCount = item;
4039
- }
4040
- }
4041
- }
4042
- return elementInnerText;
3829
+ defineProperty(HTMLElement.prototype, 'getElementsByClassName', getOwnPropertyDescriptor(Element.prototype, 'getElementsByClassName'));
4043
3830
  }
4044
3831
 
4045
3832
  /*
@@ -4380,209 +4167,184 @@
4380
4167
  * SPDX-License-Identifier: MIT
4381
4168
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4382
4169
  */
4383
- const {
4384
- blur,
4385
- focus
4386
- } = HTMLElement.prototype;
4170
+ const { blur, focus } = HTMLElement.prototype;
4387
4171
  /**
4388
4172
  * This method only applies to elements with a shadow attached to them
4389
4173
  */
4390
4174
  function tabIndexGetterPatched() {
4391
- if (isDelegatingFocus(this) && isFalse(hasAttribute.call(this, 'tabindex'))) {
4392
- // this covers the case where the default tabindex should be 0 because the
4393
- // custom element is delegating its focus
4394
- return 0;
4395
- }
4396
- return tabIndexGetter.call(this);
4175
+ if (isDelegatingFocus(this) && isFalse(hasAttribute.call(this, 'tabindex'))) {
4176
+ // this covers the case where the default tabindex should be 0 because the
4177
+ // custom element is delegating its focus
4178
+ return 0;
4179
+ }
4180
+ return tabIndexGetter.call(this);
4397
4181
  }
4398
4182
  /**
4399
4183
  * This method only applies to elements with a shadow attached to them
4400
4184
  */
4401
4185
  function tabIndexSetterPatched(value) {
4402
- // This tabIndex setter might be confusing unless it is understood that HTML
4403
- // elements have default tabIndex property values. Natively focusable elements have
4404
- // a default tabIndex value of 0 and all other elements have a default tabIndex
4405
- // value of -1. For example, the tabIndex property value is -1 for both <x-foo> and
4406
- // <x-foo tabindex="-1">, but our delegatesFocus polyfill should only kick in for
4407
- // the latter case when the value of the tabindex attribute is -1.
4408
- const delegatesFocus = isDelegatingFocus(this);
4409
- // Record the state of things before invoking component setter.
4410
- const prevValue = tabIndexGetter.call(this);
4411
- const prevHasAttr = hasAttribute.call(this, 'tabindex');
4412
- tabIndexSetter.call(this, value);
4413
- // Record the state of things after invoking component setter.
4414
- const currValue = tabIndexGetter.call(this);
4415
- const currHasAttr = hasAttribute.call(this, 'tabindex');
4416
- const didValueChange = prevValue !== currValue;
4417
- // If the tabindex attribute is initially rendered, we can assume that this setter has
4418
- // previously executed and a listener has been added. We must remove that listener if
4419
- // the tabIndex property value has changed or if the component no longer renders a
4420
- // tabindex attribute.
4421
- if (prevHasAttr && (didValueChange || isFalse(currHasAttr))) {
4422
- if (prevValue === -1) {
4423
- ignoreFocusIn(this);
4424
- }
4425
- if (prevValue === 0 && delegatesFocus) {
4426
- ignoreFocus(this);
4186
+ // This tabIndex setter might be confusing unless it is understood that HTML
4187
+ // elements have default tabIndex property values. Natively focusable elements have
4188
+ // a default tabIndex value of 0 and all other elements have a default tabIndex
4189
+ // value of -1. For example, the tabIndex property value is -1 for both <x-foo> and
4190
+ // <x-foo tabindex="-1">, but our delegatesFocus polyfill should only kick in for
4191
+ // the latter case when the value of the tabindex attribute is -1.
4192
+ const delegatesFocus = isDelegatingFocus(this);
4193
+ // Record the state of things before invoking component setter.
4194
+ const prevValue = tabIndexGetter.call(this);
4195
+ const prevHasAttr = hasAttribute.call(this, 'tabindex');
4196
+ tabIndexSetter.call(this, value);
4197
+ // Record the state of things after invoking component setter.
4198
+ const currValue = tabIndexGetter.call(this);
4199
+ const currHasAttr = hasAttribute.call(this, 'tabindex');
4200
+ const didValueChange = prevValue !== currValue;
4201
+ // If the tabindex attribute is initially rendered, we can assume that this setter has
4202
+ // previously executed and a listener has been added. We must remove that listener if
4203
+ // the tabIndex property value has changed or if the component no longer renders a
4204
+ // tabindex attribute.
4205
+ if (prevHasAttr && (didValueChange || isFalse(currHasAttr))) {
4206
+ if (prevValue === -1) {
4207
+ ignoreFocusIn(this);
4208
+ }
4209
+ if (prevValue === 0 && delegatesFocus) {
4210
+ ignoreFocus(this);
4211
+ }
4212
+ }
4213
+ // If a tabindex attribute was not rendered after invoking its setter, it means the
4214
+ // component is taking control. Do nothing.
4215
+ if (isFalse(currHasAttr)) {
4216
+ return;
4217
+ }
4218
+ // If the tabindex attribute is initially rendered, we can assume that this setter has
4219
+ // previously executed and a listener has been added. If the tabindex attribute is still
4220
+ // rendered after invoking the setter AND the tabIndex property value has not changed,
4221
+ // we don't need to do any work.
4222
+ if (prevHasAttr && currHasAttr && isFalse(didValueChange)) {
4223
+ return;
4224
+ }
4225
+ // At this point we know that a tabindex attribute was rendered after invoking the
4226
+ // setter and that either:
4227
+ // 1) This is the first time this setter is being invoked.
4228
+ // 2) This is not the first time this setter is being invoked and the value is changing.
4229
+ // We need to add the appropriate listeners in either case.
4230
+ if (currValue === -1) {
4231
+ // Add the magic to skip the shadow tree
4232
+ handleFocusIn(this);
4233
+ }
4234
+ if (currValue === 0 && delegatesFocus) {
4235
+ // Add the magic to skip the host element
4236
+ handleFocus(this);
4427
4237
  }
4428
- }
4429
- // If a tabindex attribute was not rendered after invoking its setter, it means the
4430
- // component is taking control. Do nothing.
4431
- if (isFalse(currHasAttr)) {
4432
- return;
4433
- }
4434
- // If the tabindex attribute is initially rendered, we can assume that this setter has
4435
- // previously executed and a listener has been added. If the tabindex attribute is still
4436
- // rendered after invoking the setter AND the tabIndex property value has not changed,
4437
- // we don't need to do any work.
4438
- if (prevHasAttr && currHasAttr && isFalse(didValueChange)) {
4439
- return;
4440
- }
4441
- // At this point we know that a tabindex attribute was rendered after invoking the
4442
- // setter and that either:
4443
- // 1) This is the first time this setter is being invoked.
4444
- // 2) This is not the first time this setter is being invoked and the value is changing.
4445
- // We need to add the appropriate listeners in either case.
4446
- if (currValue === -1) {
4447
- // Add the magic to skip the shadow tree
4448
- handleFocusIn(this);
4449
- }
4450
- if (currValue === 0 && delegatesFocus) {
4451
- // Add the magic to skip the host element
4452
- handleFocus(this);
4453
- }
4454
4238
  }
4455
4239
  /**
4456
4240
  * This method only applies to elements with a shadow attached to them
4457
4241
  */
4458
4242
  function blurPatched() {
4459
- if (isDelegatingFocus(this)) {
4460
- const currentActiveElement = getActiveElement(this);
4461
- if (!isNull(currentActiveElement)) {
4462
- // if there is an active element, blur it (intentionally using the dot notation in case the user defines the blur routine)
4463
- currentActiveElement.blur();
4464
- return;
4243
+ if (isDelegatingFocus(this)) {
4244
+ const currentActiveElement = getActiveElement(this);
4245
+ if (!isNull(currentActiveElement)) {
4246
+ // if there is an active element, blur it (intentionally using the dot notation in case the user defines the blur routine)
4247
+ currentActiveElement.blur();
4248
+ return;
4249
+ }
4465
4250
  }
4466
- }
4467
- return blur.call(this);
4251
+ return blur.call(this);
4468
4252
  }
4469
4253
  function focusPatched() {
4470
- // Save enabled state
4471
- const originallyEnabled = isKeyboardFocusNavigationRoutineEnabled();
4472
- // Change state by disabling if originally enabled
4473
- if (originallyEnabled) {
4474
- disableKeyboardFocusNavigationRoutines();
4475
- }
4476
- if (isSyntheticShadowHost(this) && isDelegatingFocus(this)) {
4477
- hostElementFocus.call(this);
4478
- return;
4479
- }
4480
- // Typescript does not like it when you treat the `arguments` object as an array
4481
- // @ts-ignore type-mismatch
4482
- focus.apply(this, arguments);
4483
- // Restore state by enabling if originally enabled
4484
- if (originallyEnabled) {
4485
- enableKeyboardFocusNavigationRoutines();
4486
- }
4254
+ // Save enabled state
4255
+ const originallyEnabled = isKeyboardFocusNavigationRoutineEnabled();
4256
+ // Change state by disabling if originally enabled
4257
+ if (originallyEnabled) {
4258
+ disableKeyboardFocusNavigationRoutines();
4259
+ }
4260
+ if (isSyntheticShadowHost(this) && isDelegatingFocus(this)) {
4261
+ hostElementFocus.call(this);
4262
+ return;
4263
+ }
4264
+ // Typescript does not like it when you treat the `arguments` object as an array
4265
+ // @ts-ignore type-mismatch
4266
+ focus.apply(this, arguments);
4267
+ // Restore state by enabling if originally enabled
4268
+ if (originallyEnabled) {
4269
+ enableKeyboardFocusNavigationRoutines();
4270
+ }
4487
4271
  }
4488
4272
  // Non-deep-traversing patches: this descriptor map includes all descriptors that
4489
4273
  // do not five access to nodes beyond the immediate children.
4490
4274
  defineProperties(HTMLElement.prototype, {
4491
- tabIndex: {
4492
- get() {
4493
- if (isSyntheticShadowHost(this)) {
4494
- return tabIndexGetterPatched.call(this);
4495
- }
4496
- return tabIndexGetter.call(this);
4497
- },
4498
- set(v) {
4499
- if (isSyntheticShadowHost(this)) {
4500
- return tabIndexSetterPatched.call(this, v);
4501
- }
4502
- return tabIndexSetter.call(this, v);
4275
+ tabIndex: {
4276
+ get() {
4277
+ if (isSyntheticShadowHost(this)) {
4278
+ return tabIndexGetterPatched.call(this);
4279
+ }
4280
+ return tabIndexGetter.call(this);
4281
+ },
4282
+ set(v) {
4283
+ if (isSyntheticShadowHost(this)) {
4284
+ return tabIndexSetterPatched.call(this, v);
4285
+ }
4286
+ return tabIndexSetter.call(this, v);
4287
+ },
4288
+ enumerable: true,
4289
+ configurable: true,
4503
4290
  },
4504
- enumerable: true,
4505
- configurable: true
4506
- },
4507
- blur: {
4508
- value() {
4509
- if (isSyntheticShadowHost(this)) {
4510
- return blurPatched.call(this);
4511
- }
4512
- blur.call(this);
4291
+ blur: {
4292
+ value() {
4293
+ if (isSyntheticShadowHost(this)) {
4294
+ return blurPatched.call(this);
4295
+ }
4296
+ blur.call(this);
4297
+ },
4298
+ enumerable: true,
4299
+ writable: true,
4300
+ configurable: true,
4513
4301
  },
4514
- enumerable: true,
4515
- writable: true,
4516
- configurable: true
4517
- },
4518
- focus: {
4519
- value() {
4520
- // Typescript does not like it when you treat the `arguments` object as an array
4521
- // @ts-ignore type-mismatch
4522
- focusPatched.apply(this, arguments);
4302
+ focus: {
4303
+ value() {
4304
+ // Typescript does not like it when you treat the `arguments` object as an array
4305
+ // @ts-ignore type-mismatch
4306
+ focusPatched.apply(this, arguments);
4307
+ },
4308
+ enumerable: true,
4309
+ writable: true,
4310
+ configurable: true,
4523
4311
  },
4524
- enumerable: true,
4525
- writable: true,
4526
- configurable: true
4527
- }
4528
4312
  });
4529
4313
  // Note: In JSDOM innerText is not implemented: https://github.com/jsdom/jsdom/issues/1245
4530
4314
  if (innerTextGetter !== null && innerTextSetter !== null) {
4531
- defineProperty(HTMLElement.prototype, 'innerText', {
4532
- get() {
4533
- if (!lwcRuntimeFlags.ENABLE_INNER_OUTER_TEXT_PATCH) {
4534
- return innerTextGetter.call(this);
4535
- }
4536
- if (!lwcRuntimeFlags.ENABLE_ELEMENT_PATCH) {
4537
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
4538
- return getInnerText(this);
4539
- }
4540
- return innerTextGetter.call(this);
4541
- }
4542
- // TODO [#1222]: remove global bypass
4543
- if (isGlobalPatchingSkipped(this)) {
4544
- return innerTextGetter.call(this);
4545
- }
4546
- return getInnerText(this);
4547
- },
4548
- set(v) {
4549
- innerTextSetter.call(this, v);
4550
- },
4551
- enumerable: true,
4552
- configurable: true
4553
- });
4315
+ defineProperty(HTMLElement.prototype, 'innerText', {
4316
+ get() {
4317
+ // Note: we deviate from native shadow here, but are not fixing
4318
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
4319
+ return innerTextGetter.call(this);
4320
+ },
4321
+ set(v) {
4322
+ innerTextSetter.call(this, v);
4323
+ },
4324
+ enumerable: true,
4325
+ configurable: true,
4326
+ });
4554
4327
  }
4555
4328
  // Note: Firefox does not have outerText, https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/outerText
4556
4329
  if (outerTextGetter !== null && outerTextSetter !== null) {
4557
- // From https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/outerText :
4558
- // HTMLElement.outerText is a non-standard property. As a getter, it returns the same value as Node.innerText.
4559
- // As a setter, it removes the current node and replaces it with the given text.
4560
- defineProperty(HTMLElement.prototype, 'outerText', {
4561
- get() {
4562
- if (!lwcRuntimeFlags.ENABLE_INNER_OUTER_TEXT_PATCH) {
4563
- return outerTextGetter.call(this);
4564
- }
4565
- if (!lwcRuntimeFlags.ENABLE_ELEMENT_PATCH) {
4566
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
4567
- return getInnerText(this);
4568
- }
4569
- return outerTextGetter.call(this);
4570
- }
4571
- // TODO [#1222]: remove global bypass
4572
- if (isGlobalPatchingSkipped(this)) {
4573
- return outerTextGetter.call(this);
4574
- }
4575
- return getInnerText(this);
4576
- },
4577
- set(v) {
4578
- // Invoking the `outerText` setter on a host element should trigger its disconnection, but until we merge node reactions, it will not work.
4579
- // We could reimplement the outerText setter in JavaScript ([blink implementation](https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/html/html_element.cc;l=841-879;drc=6e8b402a6231405b753919029c9027404325ea00;bpv=0;bpt=1))
4580
- // but the benefits don't worth the efforts.
4581
- outerTextSetter.call(this, v);
4582
- },
4583
- enumerable: true,
4584
- configurable: true
4585
- });
4330
+ // From https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/outerText :
4331
+ // HTMLElement.outerText is a non-standard property. As a getter, it returns the same value as Node.innerText.
4332
+ // As a setter, it removes the current node and replaces it with the given text.
4333
+ defineProperty(HTMLElement.prototype, 'outerText', {
4334
+ get() {
4335
+ // Note: we deviate from native shadow here, but are not fixing
4336
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
4337
+ return outerTextGetter.call(this);
4338
+ },
4339
+ set(v) {
4340
+ // Invoking the `outerText` setter on a host element should trigger its disconnection, but until we merge node reactions, it will not work.
4341
+ // We could reimplement the outerText setter in JavaScript ([blink implementation](https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/html/html_element.cc;l=841-879;drc=6e8b402a6231405b753919029c9027404325ea00;bpv=0;bpt=1))
4342
+ // but the benefits don't worth the efforts.
4343
+ outerTextSetter.call(this, v);
4344
+ },
4345
+ enumerable: true,
4346
+ configurable: true,
4347
+ });
4586
4348
  }
4587
4349
 
4588
4350
  /*
@@ -4758,6 +4520,6 @@
4758
4520
  },
4759
4521
  configurable: true,
4760
4522
  });
4761
- /** version: 2.32.0 */
4523
+ /** version: 2.32.1 */
4762
4524
 
4763
4525
  }));