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
@@ -153,7 +153,7 @@
153
153
  // We use this to detect symbol support in order to avoid the expensive symbol polyfill. Note that
154
154
  // we can't use typeof since it will fail when transpiling.
155
155
  const hasNativeSymbolSupport = /*@__PURE__*/ (() => Symbol('x').toString() === 'Symbol(x)')();
156
- /** version: 2.32.0 */
156
+ /** version: 2.32.1 */
157
157
 
158
158
  /*
159
159
  * Copyright (c) 2018, salesforce.com, inc.
@@ -427,7 +427,8 @@
427
427
  return win;
428
428
  }
429
429
  let skipGlobalPatching;
430
- // TODO [#1222]: remove global bypass
430
+ // Note: we deviate from native shadow here, but are not fixing
431
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
431
432
  function isGlobalPatchingSkipped(node) {
432
433
  // we lazily compute this value instead of doing it during evaluation, this helps
433
434
  // for apps that are setting this after the engine code is evaluated.
@@ -467,7 +468,7 @@
467
468
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
468
469
  }
469
470
  const lwcRuntimeFlags = _globalThis.lwcRuntimeFlags;
470
- /** version: 2.32.0 */
471
+ /** version: 2.32.1 */
471
472
 
472
473
  /*
473
474
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1161,119 +1162,125 @@
1161
1162
  * because we don't want to patch the children getters for those elements.
1162
1163
  */
1163
1164
  function hasMountedChildren(node) {
1164
- return isSyntheticSlotElement(node) || isSyntheticShadowHost(node);
1165
+ return isSyntheticSlotElement(node) || isSyntheticShadowHost(node);
1165
1166
  }
1166
1167
  function getShadowParent(node, value) {
1167
- const owner = getNodeOwner(node);
1168
- if (value === owner) {
1169
- // walking up via parent chain might end up in the shadow root element
1170
- return getShadowRoot(owner);
1171
- } else if (value instanceof Element) {
1172
- if (getNodeNearestOwnerKey(node) === getNodeNearestOwnerKey(value)) {
1173
- // the element and its parent node belong to the same shadow root
1174
- return value;
1175
- } else if (!isNull(owner) && isSlotElement(value)) {
1176
- // slotted elements must be top level childNodes of the slot element
1177
- // where they slotted into, but its shadowed parent is always the
1178
- // owner of the slot.
1179
- const slotOwner = getNodeOwner(value);
1180
- if (!isNull(slotOwner) && isNodeOwnedBy(owner, slotOwner)) {
1181
- // it is a slotted element, and therefore its parent is always going to be the host of the slot
1182
- return slotOwner;
1183
- }
1168
+ const owner = getNodeOwner(node);
1169
+ if (value === owner) {
1170
+ // walking up via parent chain might end up in the shadow root element
1171
+ return getShadowRoot(owner);
1172
+ }
1173
+ else if (value instanceof Element) {
1174
+ if (getNodeNearestOwnerKey(node) === getNodeNearestOwnerKey(value)) {
1175
+ // the element and its parent node belong to the same shadow root
1176
+ return value;
1177
+ }
1178
+ else if (!isNull(owner) && isSlotElement(value)) {
1179
+ // slotted elements must be top level childNodes of the slot element
1180
+ // where they slotted into, but its shadowed parent is always the
1181
+ // owner of the slot.
1182
+ const slotOwner = getNodeOwner(value);
1183
+ if (!isNull(slotOwner) && isNodeOwnedBy(owner, slotOwner)) {
1184
+ // it is a slotted element, and therefore its parent is always going to be the host of the slot
1185
+ return slotOwner;
1186
+ }
1187
+ }
1184
1188
  }
1185
- }
1186
- return null;
1189
+ return null;
1187
1190
  }
1188
1191
  function hasChildNodesPatched() {
1189
- return getInternalChildNodes(this).length > 0;
1192
+ return getInternalChildNodes(this).length > 0;
1190
1193
  }
1191
1194
  function firstChildGetterPatched() {
1192
- const childNodes = getInternalChildNodes(this);
1193
- return childNodes[0] || null;
1195
+ const childNodes = getInternalChildNodes(this);
1196
+ return childNodes[0] || null;
1194
1197
  }
1195
1198
  function lastChildGetterPatched() {
1196
- const childNodes = getInternalChildNodes(this);
1197
- return childNodes[childNodes.length - 1] || null;
1199
+ const childNodes = getInternalChildNodes(this);
1200
+ return childNodes[childNodes.length - 1] || null;
1198
1201
  }
1199
1202
  function textContentGetterPatched() {
1200
- return getTextContent(this);
1203
+ return getTextContent(this);
1201
1204
  }
1202
1205
  function textContentSetterPatched(value) {
1203
- textContextSetter.call(this, value);
1206
+ textContextSetter.call(this, value);
1204
1207
  }
1205
1208
  function parentNodeGetterPatched() {
1206
- const value = parentNodeGetter.call(this);
1207
- if (isNull(value)) {
1208
- return value;
1209
- }
1210
- // TODO [#1635]: this needs optimization, maybe implementing it based on this.assignedSlot
1211
- return getShadowParent(this, value);
1209
+ const value = parentNodeGetter.call(this);
1210
+ if (isNull(value)) {
1211
+ return value;
1212
+ }
1213
+ // TODO [#1635]: this needs optimization, maybe implementing it based on this.assignedSlot
1214
+ return getShadowParent(this, value);
1212
1215
  }
1213
1216
  function parentElementGetterPatched() {
1214
- const value = parentNodeGetter.call(this);
1215
- if (isNull(value)) {
1216
- return null;
1217
- }
1218
- const parentNode = getShadowParent(this, value);
1219
- // it could be that the parentNode is the shadowRoot, in which case
1220
- // we need to return null.
1221
- // TODO [#1635]: this needs optimization, maybe implementing it based on this.assignedSlot
1222
- return parentNode instanceof Element ? parentNode : null;
1217
+ const value = parentNodeGetter.call(this);
1218
+ if (isNull(value)) {
1219
+ return null;
1220
+ }
1221
+ const parentNode = getShadowParent(this, value);
1222
+ // it could be that the parentNode is the shadowRoot, in which case
1223
+ // we need to return null.
1224
+ // TODO [#1635]: this needs optimization, maybe implementing it based on this.assignedSlot
1225
+ return parentNode instanceof Element ? parentNode : null;
1223
1226
  }
1224
1227
  function compareDocumentPositionPatched(otherNode) {
1225
- if (this === otherNode) {
1226
- return 0;
1227
- } else if (this.getRootNode() === otherNode) {
1228
- // "this" is in a shadow tree where the shadow root is the "otherNode".
1229
- return 10; // Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING
1230
- } else if (getNodeOwnerKey(this) !== getNodeOwnerKey(otherNode)) {
1231
- // "this" and "otherNode" belongs to 2 different shadow tree.
1232
- return 35; // Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | Node.DOCUMENT_POSITION_PRECEDING
1233
- }
1234
- // Since "this" and "otherNode" are part of the same shadow tree we can safely rely to the native
1235
- // Node.compareDocumentPosition implementation.
1236
- return compareDocumentPosition.call(this, otherNode);
1228
+ if (this === otherNode) {
1229
+ return 0;
1230
+ }
1231
+ else if (this.getRootNode() === otherNode) {
1232
+ // "this" is in a shadow tree where the shadow root is the "otherNode".
1233
+ return 10; // Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING
1234
+ }
1235
+ else if (getNodeOwnerKey(this) !== getNodeOwnerKey(otherNode)) {
1236
+ // "this" and "otherNode" belongs to 2 different shadow tree.
1237
+ return 35; // Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | Node.DOCUMENT_POSITION_PRECEDING
1238
+ }
1239
+ // Since "this" and "otherNode" are part of the same shadow tree we can safely rely to the native
1240
+ // Node.compareDocumentPosition implementation.
1241
+ return compareDocumentPosition.call(this, otherNode);
1237
1242
  }
1238
1243
  function containsPatched(otherNode) {
1239
- if (otherNode == null || getNodeOwnerKey(this) !== getNodeOwnerKey(otherNode)) {
1240
- // it is from another shadow
1241
- return false;
1242
- }
1243
- return (compareDocumentPosition.call(this, otherNode) & DOCUMENT_POSITION_CONTAINED_BY) !== 0;
1244
+ if (otherNode == null || getNodeOwnerKey(this) !== getNodeOwnerKey(otherNode)) {
1245
+ // it is from another shadow
1246
+ return false;
1247
+ }
1248
+ return (compareDocumentPosition.call(this, otherNode) & DOCUMENT_POSITION_CONTAINED_BY) !== 0;
1244
1249
  }
1245
1250
  function cloneNodePatched(deep) {
1246
- const clone = cloneNode.call(this, false);
1247
- // Per spec, browsers only care about truthy values
1248
- // Not strict true or false
1249
- if (!deep) {
1251
+ const clone = cloneNode.call(this, false);
1252
+ // Per spec, browsers only care about truthy values
1253
+ // Not strict true or false
1254
+ if (!deep) {
1255
+ return clone;
1256
+ }
1257
+ const childNodes = getInternalChildNodes(this);
1258
+ for (let i = 0, len = childNodes.length; i < len; i += 1) {
1259
+ clone.appendChild(childNodes[i].cloneNode(true));
1260
+ }
1250
1261
  return clone;
1251
- }
1252
- const childNodes = getInternalChildNodes(this);
1253
- for (let i = 0, len = childNodes.length; i < len; i += 1) {
1254
- clone.appendChild(childNodes[i].cloneNode(true));
1255
- }
1256
- return clone;
1257
1262
  }
1258
1263
  /**
1259
1264
  * This method only applies to elements with a shadow or slots
1260
1265
  */
1261
1266
  function childNodesGetterPatched() {
1262
- if (isSyntheticShadowHost(this)) {
1263
- const owner = getNodeOwner(this);
1264
- const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
1265
- if (process.env.NODE_ENV !== 'production' && isFalse(hasNativeSymbolSupport) && isExternalChildNodeAccessorFlagOn()) {
1266
- // inserting a comment node as the first childNode to trick the IE11
1267
- // DevTool to show the content of the shadowRoot, this should only happen
1268
- // in dev-mode and in IE11 (which we detect by looking at the symbol).
1269
- // Plus it should only be in place if we know it is an external invoker.
1270
- ArrayUnshift.call(childNodes, getIE11FakeShadowRootPlaceholder(this));
1271
- }
1272
- return createStaticNodeList(childNodes);
1273
- }
1274
- // nothing to do here since this does not have a synthetic shadow attached to it
1275
- // TODO [#1636]: what about slot elements?
1276
- return childNodesGetter.call(this);
1267
+ if (isSyntheticShadowHost(this)) {
1268
+ const owner = getNodeOwner(this);
1269
+ const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
1270
+ if (process.env.NODE_ENV !== 'production' &&
1271
+ isFalse(hasNativeSymbolSupport) &&
1272
+ isExternalChildNodeAccessorFlagOn()) {
1273
+ // inserting a comment node as the first childNode to trick the IE11
1274
+ // DevTool to show the content of the shadowRoot, this should only happen
1275
+ // in dev-mode and in IE11 (which we detect by looking at the symbol).
1276
+ // Plus it should only be in place if we know it is an external invoker.
1277
+ ArrayUnshift.call(childNodes, getIE11FakeShadowRootPlaceholder(this));
1278
+ }
1279
+ return createStaticNodeList(childNodes);
1280
+ }
1281
+ // nothing to do here since this does not have a synthetic shadow attached to it
1282
+ // TODO [#1636]: what about slot elements?
1283
+ return childNodesGetter.call(this);
1277
1284
  }
1278
1285
  const nativeGetRootNode = _Node.prototype.getRootNode;
1279
1286
  /**
@@ -1281,14 +1288,16 @@
1281
1288
  * If Node.prototype.getRootNode is supported, use it
1282
1289
  * else, assume we are working in non-native shadow mode and climb using parentNode
1283
1290
  */
1284
- const getDocumentOrRootNode = !isUndefined(nativeGetRootNode) ? nativeGetRootNode : function () {
1285
- let node = this;
1286
- let nodeParent;
1287
- while (!isNull(nodeParent = parentNodeGetter.call(node))) {
1288
- node = nodeParent;
1289
- }
1290
- return node;
1291
- };
1291
+ const getDocumentOrRootNode = !isUndefined(nativeGetRootNode)
1292
+ ? nativeGetRootNode
1293
+ : function () {
1294
+ let node = this;
1295
+ let nodeParent;
1296
+ while (!isNull((nodeParent = parentNodeGetter.call(node)))) {
1297
+ node = nodeParent;
1298
+ }
1299
+ return node;
1300
+ };
1292
1301
  /**
1293
1302
  * Get the shadow root
1294
1303
  * getNodeOwner() returns the host element that owns the given node
@@ -1299,12 +1308,12 @@
1299
1308
  * @param {Node} node
1300
1309
  */
1301
1310
  function getNearestRoot(node) {
1302
- const ownerNode = getNodeOwner(node);
1303
- if (isNull(ownerNode)) {
1304
- // we hit a wall, either we are in native shadow mode or the node is not in lwc boundary.
1305
- return getDocumentOrRootNode.call(node);
1306
- }
1307
- return getShadowRoot(ownerNode);
1311
+ const ownerNode = getNodeOwner(node);
1312
+ if (isNull(ownerNode)) {
1313
+ // we hit a wall, either we are in native shadow mode or the node is not in lwc boundary.
1314
+ return getDocumentOrRootNode.call(node);
1315
+ }
1316
+ return getShadowRoot(ownerNode);
1308
1317
  }
1309
1318
  /**
1310
1319
  * If looking for a root node beyond shadow root by calling `node.getRootNode({composed: true})`, use the original `Node.prototype.getRootNode` method
@@ -1326,177 +1335,160 @@
1326
1335
  *
1327
1336
  **/
1328
1337
  function getRootNodePatched(options) {
1329
- const composed = isUndefined(options) ? false : !!options.composed;
1330
- return isTrue(composed) ? getDocumentOrRootNode.call(this, options) : getNearestRoot(this);
1338
+ const composed = isUndefined(options) ? false : !!options.composed;
1339
+ return isTrue(composed) ? getDocumentOrRootNode.call(this, options) : getNearestRoot(this);
1331
1340
  }
1332
1341
  // Non-deep-traversing patches: this descriptor map includes all descriptors that
1333
1342
  // do not give access to nodes beyond the immediate children.
1334
1343
  defineProperties(_Node.prototype, {
1335
- firstChild: {
1336
- get() {
1337
- if (hasMountedChildren(this)) {
1338
- return firstChildGetterPatched.call(this);
1339
- }
1340
- return firstChildGetter.call(this);
1344
+ firstChild: {
1345
+ get() {
1346
+ if (hasMountedChildren(this)) {
1347
+ return firstChildGetterPatched.call(this);
1348
+ }
1349
+ return firstChildGetter.call(this);
1350
+ },
1351
+ enumerable: true,
1352
+ configurable: true,
1341
1353
  },
1342
- enumerable: true,
1343
- configurable: true
1344
- },
1345
- lastChild: {
1346
- get() {
1347
- if (hasMountedChildren(this)) {
1348
- return lastChildGetterPatched.call(this);
1349
- }
1350
- return lastChildGetter.call(this);
1354
+ lastChild: {
1355
+ get() {
1356
+ if (hasMountedChildren(this)) {
1357
+ return lastChildGetterPatched.call(this);
1358
+ }
1359
+ return lastChildGetter.call(this);
1360
+ },
1361
+ enumerable: true,
1362
+ configurable: true,
1351
1363
  },
1352
- enumerable: true,
1353
- configurable: true
1354
- },
1355
- textContent: {
1356
- get() {
1357
- if (!lwcRuntimeFlags.ENABLE_NODE_PATCH) {
1358
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1359
- return textContentGetterPatched.call(this);
1360
- }
1361
- return textContentGetter.call(this);
1362
- }
1363
- // TODO [#1222]: remove global bypass
1364
- if (isGlobalPatchingSkipped(this)) {
1365
- return textContentGetter.call(this);
1366
- }
1367
- return textContentGetterPatched.call(this);
1364
+ textContent: {
1365
+ get() {
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 (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1369
+ return textContentGetterPatched.call(this);
1370
+ }
1371
+ return textContentGetter.call(this);
1372
+ },
1373
+ set: textContentSetterPatched,
1374
+ enumerable: true,
1375
+ configurable: true,
1368
1376
  },
1369
- set: textContentSetterPatched,
1370
- enumerable: true,
1371
- configurable: true
1372
- },
1373
- parentNode: {
1374
- get() {
1375
- if (isNodeShadowed(this)) {
1376
- return parentNodeGetterPatched.call(this);
1377
- }
1378
- const parentNode = parentNodeGetter.call(this);
1379
- // Handle the case where a top level light DOM element is slotted into a synthetic
1380
- // shadow slot.
1381
- if (!isNull(parentNode) && isSyntheticSlotElement(parentNode)) {
1382
- return getNodeOwner(parentNode);
1383
- }
1384
- return parentNode;
1377
+ parentNode: {
1378
+ get() {
1379
+ if (isNodeShadowed(this)) {
1380
+ return parentNodeGetterPatched.call(this);
1381
+ }
1382
+ const parentNode = parentNodeGetter.call(this);
1383
+ // Handle the case where a top level light DOM element is slotted into a synthetic
1384
+ // shadow slot.
1385
+ if (!isNull(parentNode) && isSyntheticSlotElement(parentNode)) {
1386
+ return getNodeOwner(parentNode);
1387
+ }
1388
+ return parentNode;
1389
+ },
1390
+ enumerable: true,
1391
+ configurable: true,
1385
1392
  },
1386
- enumerable: true,
1387
- configurable: true
1388
- },
1389
- parentElement: {
1390
- get() {
1391
- if (isNodeShadowed(this)) {
1392
- return parentElementGetterPatched.call(this);
1393
- }
1394
- const parentElement = parentElementGetter.call(this);
1395
- // Handle the case where a top level light DOM element is slotted into a synthetic
1396
- // shadow slot.
1397
- if (!isNull(parentElement) && isSyntheticSlotElement(parentElement)) {
1398
- return getNodeOwner(parentElement);
1399
- }
1400
- return parentElement;
1393
+ parentElement: {
1394
+ get() {
1395
+ if (isNodeShadowed(this)) {
1396
+ return parentElementGetterPatched.call(this);
1397
+ }
1398
+ const parentElement = parentElementGetter.call(this);
1399
+ // Handle the case where a top level light DOM element is slotted into a synthetic
1400
+ // shadow slot.
1401
+ if (!isNull(parentElement) && isSyntheticSlotElement(parentElement)) {
1402
+ return getNodeOwner(parentElement);
1403
+ }
1404
+ return parentElement;
1405
+ },
1406
+ enumerable: true,
1407
+ configurable: true,
1401
1408
  },
1402
- enumerable: true,
1403
- configurable: true
1404
- },
1405
- childNodes: {
1406
- get() {
1407
- if (hasMountedChildren(this)) {
1408
- return childNodesGetterPatched.call(this);
1409
- }
1410
- return childNodesGetter.call(this);
1409
+ childNodes: {
1410
+ get() {
1411
+ if (hasMountedChildren(this)) {
1412
+ return childNodesGetterPatched.call(this);
1413
+ }
1414
+ return childNodesGetter.call(this);
1415
+ },
1416
+ enumerable: true,
1417
+ configurable: true,
1411
1418
  },
1412
- enumerable: true,
1413
- configurable: true
1414
- },
1415
- hasChildNodes: {
1416
- value() {
1417
- if (hasMountedChildren(this)) {
1418
- return hasChildNodesPatched.call(this);
1419
- }
1420
- return hasChildNodes.call(this);
1419
+ hasChildNodes: {
1420
+ value() {
1421
+ if (hasMountedChildren(this)) {
1422
+ return hasChildNodesPatched.call(this);
1423
+ }
1424
+ return hasChildNodes.call(this);
1425
+ },
1426
+ enumerable: true,
1427
+ writable: true,
1428
+ configurable: true,
1421
1429
  },
1422
- enumerable: true,
1423
- writable: true,
1424
- configurable: true
1425
- },
1426
- compareDocumentPosition: {
1427
- value(otherNode) {
1428
- // TODO [#1222]: remove global bypass
1429
- if (isGlobalPatchingSkipped(this)) {
1430
- return compareDocumentPosition.call(this, otherNode);
1431
- }
1432
- return compareDocumentPositionPatched.call(this, otherNode);
1430
+ compareDocumentPosition: {
1431
+ value(otherNode) {
1432
+ // Note: we deviate from native shadow here, but are not fixing
1433
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
1434
+ if (isGlobalPatchingSkipped(this)) {
1435
+ return compareDocumentPosition.call(this, otherNode);
1436
+ }
1437
+ return compareDocumentPositionPatched.call(this, otherNode);
1438
+ },
1439
+ enumerable: true,
1440
+ writable: true,
1441
+ configurable: true,
1433
1442
  },
1434
- enumerable: true,
1435
- writable: true,
1436
- configurable: true
1437
- },
1438
- contains: {
1439
- value(otherNode) {
1440
- // 1. Node.prototype.contains() returns true if otherNode is an inclusive descendant
1441
- // spec: https://dom.spec.whatwg.org/#dom-node-contains
1442
- // 2. This normalizes the behavior of this api across all browsers.
1443
- // In IE11, a disconnected dom element without children invoking contains() on self, returns false
1444
- if (this === otherNode) {
1445
- return true;
1446
- }
1447
- if (!lwcRuntimeFlags.ENABLE_NODE_PATCH) {
1448
- if (otherNode == null) {
1449
- return false;
1450
- }
1451
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1452
- return containsPatched.call(this, otherNode);
1453
- }
1454
- return contains.call(this, otherNode);
1455
- }
1456
- // TODO [#1222]: remove global bypass
1457
- if (isGlobalPatchingSkipped(this)) {
1458
- return contains.call(this, otherNode);
1459
- }
1460
- return containsPatched.call(this, otherNode);
1443
+ contains: {
1444
+ value(otherNode) {
1445
+ // 1. Node.prototype.contains() returns true if otherNode is an inclusive descendant
1446
+ // spec: https://dom.spec.whatwg.org/#dom-node-contains
1447
+ // 2. This normalizes the behavior of this api across all browsers.
1448
+ // In IE11, a disconnected dom element without children invoking contains() on self, returns false
1449
+ if (this === otherNode) {
1450
+ return true;
1451
+ }
1452
+ // Note: we deviate from native shadow here, but are not fixing
1453
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
1454
+ if (otherNode == null) {
1455
+ return false;
1456
+ }
1457
+ if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1458
+ return containsPatched.call(this, otherNode);
1459
+ }
1460
+ return contains.call(this, otherNode);
1461
+ },
1462
+ enumerable: true,
1463
+ writable: true,
1464
+ configurable: true,
1461
1465
  },
1462
- enumerable: true,
1463
- writable: true,
1464
- configurable: true
1465
- },
1466
- cloneNode: {
1467
- value(deep) {
1468
- if (!lwcRuntimeFlags.ENABLE_NODE_PATCH) {
1469
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1470
- return cloneNodePatched.call(this, deep);
1471
- }
1472
- return cloneNode.call(this, deep);
1473
- }
1474
- if (isTrue(deep)) {
1475
- // TODO [#1222]: remove global bypass
1476
- if (isGlobalPatchingSkipped(this)) {
1477
- return cloneNode.call(this, deep);
1478
- }
1479
- return cloneNodePatched.call(this, deep);
1480
- }
1481
- return cloneNode.call(this, deep);
1466
+ cloneNode: {
1467
+ value(deep) {
1468
+ // Note: we deviate from native shadow here, but are not fixing
1469
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
1470
+ if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1471
+ return cloneNodePatched.call(this, deep);
1472
+ }
1473
+ return cloneNode.call(this, deep);
1474
+ },
1475
+ enumerable: true,
1476
+ writable: true,
1477
+ configurable: true,
1478
+ },
1479
+ getRootNode: {
1480
+ value: getRootNodePatched,
1481
+ enumerable: true,
1482
+ configurable: true,
1483
+ writable: true,
1484
+ },
1485
+ isConnected: {
1486
+ enumerable: true,
1487
+ configurable: true,
1488
+ get() {
1489
+ return isConnected.call(this);
1490
+ },
1482
1491
  },
1483
- enumerable: true,
1484
- writable: true,
1485
- configurable: true
1486
- },
1487
- getRootNode: {
1488
- value: getRootNodePatched,
1489
- enumerable: true,
1490
- configurable: true,
1491
- writable: true
1492
- },
1493
- isConnected: {
1494
- enumerable: true,
1495
- configurable: true,
1496
- get() {
1497
- return isConnected.call(this);
1498
- }
1499
- }
1500
1492
  });
1501
1493
  let internalChildNodeAccessorFlag = false;
1502
1494
  /**
@@ -1506,35 +1498,38 @@
1506
1498
  * case, the IE11 debugging comment for shadowRoot representation on the devtool.
1507
1499
  */
1508
1500
  function isExternalChildNodeAccessorFlagOn() {
1509
- return !internalChildNodeAccessorFlag;
1510
- }
1511
- const getInternalChildNodes = process.env.NODE_ENV !== 'production' && isFalse(hasNativeSymbolSupport) ? function (node) {
1512
- internalChildNodeAccessorFlag = true;
1513
- let childNodes;
1514
- let error = null;
1515
- try {
1516
- childNodes = node.childNodes;
1517
- } catch (e) {
1518
- // childNodes accessor should never throw, but just in case!
1519
- error = e;
1520
- } finally {
1521
- internalChildNodeAccessorFlag = false;
1522
- if (!isNull(error)) {
1523
- // re-throwing after restoring the state machinery for setInternalChildNodeAccessorFlag
1524
- throw error; // eslint-disable-line no-unsafe-finally
1501
+ return !internalChildNodeAccessorFlag;
1502
+ }
1503
+ const getInternalChildNodes = process.env.NODE_ENV !== 'production' && isFalse(hasNativeSymbolSupport)
1504
+ ? function (node) {
1505
+ internalChildNodeAccessorFlag = true;
1506
+ let childNodes;
1507
+ let error = null;
1508
+ try {
1509
+ childNodes = node.childNodes;
1510
+ }
1511
+ catch (e) {
1512
+ // childNodes accessor should never throw, but just in case!
1513
+ error = e;
1514
+ }
1515
+ finally {
1516
+ internalChildNodeAccessorFlag = false;
1517
+ if (!isNull(error)) {
1518
+ // re-throwing after restoring the state machinery for setInternalChildNodeAccessorFlag
1519
+ throw error; // eslint-disable-line no-unsafe-finally
1520
+ }
1521
+ }
1522
+ return childNodes;
1525
1523
  }
1526
- }
1527
-
1528
- return childNodes;
1529
- } : function (node) {
1530
- return node.childNodes;
1531
- };
1524
+ : function (node) {
1525
+ return node.childNodes;
1526
+ };
1532
1527
  // IE11 extra patches for wrong prototypes
1533
1528
  if (hasOwnProperty.call(HTMLElement.prototype, 'contains')) {
1534
- defineProperty(HTMLElement.prototype, 'contains', getOwnPropertyDescriptor(_Node.prototype, 'contains'));
1529
+ defineProperty(HTMLElement.prototype, 'contains', getOwnPropertyDescriptor(_Node.prototype, 'contains'));
1535
1530
  }
1536
1531
  if (hasOwnProperty.call(HTMLElement.prototype, 'parentElement')) {
1537
- defineProperty(HTMLElement.prototype, 'parentElement', getOwnPropertyDescriptor(_Node.prototype, 'parentElement'));
1532
+ defineProperty(HTMLElement.prototype, 'parentElement', getOwnPropertyDescriptor(_Node.prototype, 'parentElement'));
1538
1533
  }
1539
1534
 
1540
1535
  /*
@@ -2501,7 +2496,8 @@
2501
2496
  if (isNull(elm)) {
2502
2497
  return null;
2503
2498
  }
2504
- // TODO [#1222]: remove global bypass
2499
+ // Note: we deviate from native shadow here, but are not fixing
2500
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2505
2501
  return isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm) ? elm : null;
2506
2502
  },
2507
2503
  writable: true,
@@ -2512,7 +2508,8 @@
2512
2508
  value() {
2513
2509
  const elements = arrayFromCollection(querySelectorAll.apply(this, ArraySlice.call(arguments)));
2514
2510
  const filtered = ArrayFind.call(elements,
2515
- // TODO [#1222]: remove global bypass
2511
+ // Note: we deviate from native shadow here, but are not fixing
2512
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2516
2513
  (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2517
2514
  return !isUndefined(filtered) ? filtered : null;
2518
2515
  },
@@ -2524,7 +2521,8 @@
2524
2521
  value() {
2525
2522
  const elements = arrayFromCollection(querySelectorAll.apply(this, ArraySlice.call(arguments)));
2526
2523
  const filtered = ArrayFilter.call(elements,
2527
- // TODO [#1222]: remove global bypass
2524
+ // Note: we deviate from native shadow here, but are not fixing
2525
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2528
2526
  (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2529
2527
  return createStaticNodeList(filtered);
2530
2528
  },
@@ -2536,7 +2534,8 @@
2536
2534
  value() {
2537
2535
  const elements = arrayFromCollection(getElementsByClassName.apply(this, ArraySlice.call(arguments)));
2538
2536
  const filtered = ArrayFilter.call(elements,
2539
- // TODO [#1222]: remove global bypass
2537
+ // Note: we deviate from native shadow here, but are not fixing
2538
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2540
2539
  (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2541
2540
  return createStaticHTMLCollection(filtered);
2542
2541
  },
@@ -2548,7 +2547,8 @@
2548
2547
  value() {
2549
2548
  const elements = arrayFromCollection(getElementsByTagName.apply(this, ArraySlice.call(arguments)));
2550
2549
  const filtered = ArrayFilter.call(elements,
2551
- // TODO [#1222]: remove global bypass
2550
+ // Note: we deviate from native shadow here, but are not fixing
2551
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2552
2552
  (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2553
2553
  return createStaticHTMLCollection(filtered);
2554
2554
  },
@@ -2560,7 +2560,8 @@
2560
2560
  value() {
2561
2561
  const elements = arrayFromCollection(getElementsByTagNameNS.apply(this, ArraySlice.call(arguments)));
2562
2562
  const filtered = ArrayFilter.call(elements,
2563
- // TODO [#1222]: remove global bypass
2563
+ // Note: we deviate from native shadow here, but are not fixing
2564
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2564
2565
  (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2565
2566
  return createStaticHTMLCollection(filtered);
2566
2567
  },
@@ -2576,7 +2577,8 @@
2576
2577
  value() {
2577
2578
  const elements = arrayFromCollection(getElementsByName.apply(this, ArraySlice.call(arguments)));
2578
2579
  const filtered = ArrayFilter.call(elements,
2579
- // TODO [#1222]: remove global bypass
2580
+ // Note: we deviate from native shadow here, but are not fixing
2581
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2580
2582
  (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2581
2583
  return createStaticNodeList(filtered);
2582
2584
  },
@@ -3678,7 +3680,8 @@
3678
3680
  else if (context instanceof HTMLBodyElement) {
3679
3681
  // `context` is document.body which is already patched.
3680
3682
  filtered = ArrayFilter.call(unfilteredNodes,
3681
- // TODO [#1222]: remove global bypass
3683
+ // Note: we deviate from native shadow here, but are not fixing
3684
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3682
3685
  (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(context));
3683
3686
  }
3684
3687
  else {
@@ -3695,247 +3698,233 @@
3695
3698
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3696
3699
  */
3697
3700
  function innerHTMLGetterPatched() {
3698
- const childNodes = getInternalChildNodes(this);
3699
- let innerHTML = '';
3700
- for (let i = 0, len = childNodes.length; i < len; i += 1) {
3701
- innerHTML += getOuterHTML(childNodes[i]);
3702
- }
3703
- return innerHTML;
3701
+ const childNodes = getInternalChildNodes(this);
3702
+ let innerHTML = '';
3703
+ for (let i = 0, len = childNodes.length; i < len; i += 1) {
3704
+ innerHTML += getOuterHTML(childNodes[i]);
3705
+ }
3706
+ return innerHTML;
3704
3707
  }
3705
3708
  function outerHTMLGetterPatched() {
3706
- return getOuterHTML(this);
3709
+ return getOuterHTML(this);
3707
3710
  }
3708
3711
  function attachShadowPatched(options) {
3709
- // To retain native behavior of the API, provide synthetic shadowRoot only when specified
3710
- if (options[KEY__SYNTHETIC_MODE]) {
3711
- return attachShadow(this, options);
3712
- }
3713
- return attachShadow$1.call(this, options);
3712
+ // To retain native behavior of the API, provide synthetic shadowRoot only when specified
3713
+ if (options[KEY__SYNTHETIC_MODE]) {
3714
+ return attachShadow(this, options);
3715
+ }
3716
+ return attachShadow$1.call(this, options);
3714
3717
  }
3715
3718
  function shadowRootGetterPatched() {
3716
- if (isSyntheticShadowHost(this)) {
3717
- const shadow = getShadowRoot(this);
3718
- if (shadow.mode === 'open') {
3719
- return shadow;
3719
+ if (isSyntheticShadowHost(this)) {
3720
+ const shadow = getShadowRoot(this);
3721
+ if (shadow.mode === 'open') {
3722
+ return shadow;
3723
+ }
3720
3724
  }
3721
- }
3722
- return shadowRootGetter.call(this);
3725
+ return shadowRootGetter.call(this);
3723
3726
  }
3724
3727
  function childrenGetterPatched() {
3725
- const owner = getNodeOwner(this);
3726
- const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
3727
- return createStaticHTMLCollection(ArrayFilter.call(childNodes, node => node instanceof Element));
3728
+ const owner = getNodeOwner(this);
3729
+ const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
3730
+ return createStaticHTMLCollection(ArrayFilter.call(childNodes, (node) => node instanceof Element));
3728
3731
  }
3729
3732
  function childElementCountGetterPatched() {
3730
- return this.children.length;
3733
+ return this.children.length;
3731
3734
  }
3732
3735
  function firstElementChildGetterPatched() {
3733
- return this.children[0] || null;
3736
+ return this.children[0] || null;
3734
3737
  }
3735
3738
  function lastElementChildGetterPatched() {
3736
- const {
3737
- children
3738
- } = this;
3739
- return children.item(children.length - 1) || null;
3739
+ const { children } = this;
3740
+ return children.item(children.length - 1) || null;
3740
3741
  }
3741
3742
  // Non-deep-traversing patches: this descriptor map includes all descriptors that
3742
3743
  // do not five access to nodes beyond the immediate children.
3743
3744
  defineProperties(Element.prototype, {
3744
- innerHTML: {
3745
- get() {
3746
- if (!lwcRuntimeFlags.ENABLE_ELEMENT_PATCH) {
3747
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
3748
- return innerHTMLGetterPatched.call(this);
3749
- }
3750
- return innerHTMLGetter.call(this);
3751
- }
3752
- // TODO [#1222]: remove global bypass
3753
- if (isGlobalPatchingSkipped(this)) {
3754
- return innerHTMLGetter.call(this);
3755
- }
3756
- return innerHTMLGetterPatched.call(this);
3745
+ innerHTML: {
3746
+ get() {
3747
+ // Note: we deviate from native shadow here, but are not fixing
3748
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3749
+ if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
3750
+ return innerHTMLGetterPatched.call(this);
3751
+ }
3752
+ return innerHTMLGetter.call(this);
3753
+ },
3754
+ set(v) {
3755
+ innerHTMLSetter.call(this, v);
3756
+ },
3757
+ enumerable: true,
3758
+ configurable: true,
3757
3759
  },
3758
- set(v) {
3759
- innerHTMLSetter.call(this, v);
3760
+ outerHTML: {
3761
+ get() {
3762
+ // Note: we deviate from native shadow here, but are not fixing
3763
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3764
+ if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
3765
+ return outerHTMLGetterPatched.call(this);
3766
+ }
3767
+ return outerHTMLGetter.call(this);
3768
+ },
3769
+ set(v) {
3770
+ outerHTMLSetter.call(this, v);
3771
+ },
3772
+ enumerable: true,
3773
+ configurable: true,
3760
3774
  },
3761
- enumerable: true,
3762
- configurable: true
3763
- },
3764
- outerHTML: {
3765
- get() {
3766
- if (!lwcRuntimeFlags.ENABLE_ELEMENT_PATCH) {
3767
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
3768
- return outerHTMLGetterPatched.call(this);
3769
- }
3770
- return outerHTMLGetter.call(this);
3771
- }
3772
- // TODO [#1222]: remove global bypass
3773
- if (isGlobalPatchingSkipped(this)) {
3774
- return outerHTMLGetter.call(this);
3775
- }
3776
- return outerHTMLGetterPatched.call(this);
3775
+ attachShadow: {
3776
+ value: attachShadowPatched,
3777
+ enumerable: true,
3778
+ writable: true,
3779
+ configurable: true,
3777
3780
  },
3778
- set(v) {
3779
- outerHTMLSetter.call(this, v);
3781
+ shadowRoot: {
3782
+ get: shadowRootGetterPatched,
3783
+ enumerable: true,
3784
+ configurable: true,
3780
3785
  },
3781
- enumerable: true,
3782
- configurable: true
3783
- },
3784
- attachShadow: {
3785
- value: attachShadowPatched,
3786
- enumerable: true,
3787
- writable: true,
3788
- configurable: true
3789
- },
3790
- shadowRoot: {
3791
- get: shadowRootGetterPatched,
3792
- enumerable: true,
3793
- configurable: true
3794
- },
3795
- // patched in HTMLElement if exists (IE11 is the one off here)
3796
- children: {
3797
- get() {
3798
- if (hasMountedChildren(this)) {
3799
- return childrenGetterPatched.call(this);
3800
- }
3801
- return childrenGetter.call(this);
3786
+ // patched in HTMLElement if exists (IE11 is the one off here)
3787
+ children: {
3788
+ get() {
3789
+ if (hasMountedChildren(this)) {
3790
+ return childrenGetterPatched.call(this);
3791
+ }
3792
+ return childrenGetter.call(this);
3793
+ },
3794
+ enumerable: true,
3795
+ configurable: true,
3802
3796
  },
3803
- enumerable: true,
3804
- configurable: true
3805
- },
3806
- childElementCount: {
3807
- get() {
3808
- if (hasMountedChildren(this)) {
3809
- return childElementCountGetterPatched.call(this);
3810
- }
3811
- return childElementCountGetter.call(this);
3797
+ childElementCount: {
3798
+ get() {
3799
+ if (hasMountedChildren(this)) {
3800
+ return childElementCountGetterPatched.call(this);
3801
+ }
3802
+ return childElementCountGetter.call(this);
3803
+ },
3804
+ enumerable: true,
3805
+ configurable: true,
3812
3806
  },
3813
- enumerable: true,
3814
- configurable: true
3815
- },
3816
- firstElementChild: {
3817
- get() {
3818
- if (hasMountedChildren(this)) {
3819
- return firstElementChildGetterPatched.call(this);
3820
- }
3821
- return firstElementChildGetter.call(this);
3807
+ firstElementChild: {
3808
+ get() {
3809
+ if (hasMountedChildren(this)) {
3810
+ return firstElementChildGetterPatched.call(this);
3811
+ }
3812
+ return firstElementChildGetter.call(this);
3813
+ },
3814
+ enumerable: true,
3815
+ configurable: true,
3822
3816
  },
3823
- enumerable: true,
3824
- configurable: true
3825
- },
3826
- lastElementChild: {
3827
- get() {
3828
- if (hasMountedChildren(this)) {
3829
- return lastElementChildGetterPatched.call(this);
3830
- }
3831
- return lastElementChildGetter.call(this);
3817
+ lastElementChild: {
3818
+ get() {
3819
+ if (hasMountedChildren(this)) {
3820
+ return lastElementChildGetterPatched.call(this);
3821
+ }
3822
+ return lastElementChildGetter.call(this);
3823
+ },
3824
+ enumerable: true,
3825
+ configurable: true,
3826
+ },
3827
+ assignedSlot: {
3828
+ get: assignedSlotGetterPatched,
3829
+ enumerable: true,
3830
+ configurable: true,
3832
3831
  },
3833
- enumerable: true,
3834
- configurable: true
3835
- },
3836
- assignedSlot: {
3837
- get: assignedSlotGetterPatched,
3838
- enumerable: true,
3839
- configurable: true
3840
- }
3841
3832
  });
3842
3833
  // IE11 extra patches for wrong prototypes
3843
3834
  if (hasOwnProperty.call(HTMLElement.prototype, 'innerHTML')) {
3844
- defineProperty(HTMLElement.prototype, 'innerHTML', getOwnPropertyDescriptor(Element.prototype, 'innerHTML'));
3835
+ defineProperty(HTMLElement.prototype, 'innerHTML', getOwnPropertyDescriptor(Element.prototype, 'innerHTML'));
3845
3836
  }
3846
3837
  if (hasOwnProperty.call(HTMLElement.prototype, 'outerHTML')) {
3847
- defineProperty(HTMLElement.prototype, 'outerHTML', getOwnPropertyDescriptor(Element.prototype, 'outerHTML'));
3838
+ defineProperty(HTMLElement.prototype, 'outerHTML', getOwnPropertyDescriptor(Element.prototype, 'outerHTML'));
3848
3839
  }
3849
3840
  if (hasOwnProperty.call(HTMLElement.prototype, 'children')) {
3850
- defineProperty(HTMLElement.prototype, 'children', getOwnPropertyDescriptor(Element.prototype, 'children'));
3841
+ defineProperty(HTMLElement.prototype, 'children', getOwnPropertyDescriptor(Element.prototype, 'children'));
3851
3842
  }
3852
3843
  // Deep-traversing patches from this point on:
3853
3844
  function querySelectorPatched() {
3854
- const nodeList = arrayFromCollection(querySelectorAll$1.apply(this, ArraySlice.call(arguments)));
3855
- if (isSyntheticShadowHost(this)) {
3856
- // element with shadowRoot attached
3857
- const owner = getNodeOwner(this);
3858
- if (!isUndefined(getNodeKey(this))) {
3859
- // it is a custom element, and we should then filter by slotted elements
3860
- return getFirstSlottedMatch(this, nodeList);
3861
- } else if (isNull(owner)) {
3862
- return null;
3863
- } else {
3864
- // regular element, we should then filter by ownership
3865
- return getFirstMatch(owner, nodeList);
3845
+ const nodeList = arrayFromCollection(querySelectorAll$1.apply(this, ArraySlice.call(arguments)));
3846
+ if (isSyntheticShadowHost(this)) {
3847
+ // element with shadowRoot attached
3848
+ const owner = getNodeOwner(this);
3849
+ if (!isUndefined(getNodeKey(this))) {
3850
+ // it is a custom element, and we should then filter by slotted elements
3851
+ return getFirstSlottedMatch(this, nodeList);
3852
+ }
3853
+ else if (isNull(owner)) {
3854
+ return null;
3855
+ }
3856
+ else {
3857
+ // regular element, we should then filter by ownership
3858
+ return getFirstMatch(owner, nodeList);
3859
+ }
3866
3860
  }
3867
- } else if (isNodeShadowed(this)) {
3868
- // element inside a shadowRoot
3869
- const ownerKey = getNodeOwnerKey(this);
3870
- if (!isUndefined(ownerKey)) {
3871
- // `this` is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
3872
- const elm = ArrayFind.call(nodeList, elm => getNodeNearestOwnerKey(elm) === ownerKey);
3873
- return isUndefined(elm) ? null : elm;
3874
- } else {
3875
- if (!lwcRuntimeFlags.ENABLE_NODE_LIST_PATCH) {
3876
- // `this` is a manually inserted element inside a shadowRoot, return the first element.
3877
- return nodeList.length === 0 ? null : nodeList[0];
3878
- }
3879
- // Element is inside a shadow but we dont know which one. Use the
3880
- // "nearest" owner key to filter by ownership.
3881
- const contextNearestOwnerKey = getNodeNearestOwnerKey(this);
3882
- const elm = ArrayFind.call(nodeList, elm => getNodeNearestOwnerKey(elm) === contextNearestOwnerKey);
3883
- return isUndefined(elm) ? null : elm;
3861
+ else if (isNodeShadowed(this)) {
3862
+ // element inside a shadowRoot
3863
+ const ownerKey = getNodeOwnerKey(this);
3864
+ if (!isUndefined(ownerKey)) {
3865
+ // `this` is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
3866
+ const elm = ArrayFind.call(nodeList, (elm) => getNodeNearestOwnerKey(elm) === ownerKey);
3867
+ return isUndefined(elm) ? null : elm;
3868
+ }
3869
+ else {
3870
+ // Note: we deviate from native shadow here, but are not fixing
3871
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3872
+ // `this` is a manually inserted element inside a shadowRoot, return the first element.
3873
+ return nodeList.length === 0 ? null : nodeList[0];
3874
+ }
3884
3875
  }
3885
- } else {
3886
- if (!lwcRuntimeFlags.ENABLE_NODE_LIST_PATCH) {
3887
- if (!(this instanceof HTMLBodyElement)) {
3888
- const elm = nodeList[0];
3876
+ else {
3877
+ if (!(this instanceof HTMLBodyElement)) {
3878
+ const elm = nodeList[0];
3879
+ return isUndefined(elm) ? null : elm;
3880
+ }
3881
+ // element belonging to the document
3882
+ const elm = ArrayFind.call(nodeList, (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(this));
3889
3883
  return isUndefined(elm) ? null : elm;
3890
- }
3891
3884
  }
3892
- // element belonging to the document
3893
- const elm = ArrayFind.call(nodeList,
3894
- // TODO [#1222]: remove global bypass
3895
- elm => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(this));
3896
- return isUndefined(elm) ? null : elm;
3897
- }
3898
3885
  }
3899
- function getFilteredArrayOfNodes(context, unfilteredNodes, shadowDomSemantic) {
3900
- let filtered;
3901
- if (isSyntheticShadowHost(context)) {
3902
- // element with shadowRoot attached
3903
- const owner = getNodeOwner(context);
3904
- if (!isUndefined(getNodeKey(context))) {
3905
- // it is a custom element, and we should then filter by slotted elements
3906
- filtered = getAllSlottedMatches(context, unfilteredNodes);
3907
- } else if (isNull(owner)) {
3908
- filtered = [];
3909
- } else {
3910
- // regular element, we should then filter by ownership
3911
- filtered = getAllMatches(owner, unfilteredNodes);
3886
+ function getFilteredArrayOfNodes(context, unfilteredNodes) {
3887
+ let filtered;
3888
+ if (isSyntheticShadowHost(context)) {
3889
+ // element with shadowRoot attached
3890
+ const owner = getNodeOwner(context);
3891
+ if (!isUndefined(getNodeKey(context))) {
3892
+ // it is a custom element, and we should then filter by slotted elements
3893
+ filtered = getAllSlottedMatches(context, unfilteredNodes);
3894
+ }
3895
+ else if (isNull(owner)) {
3896
+ filtered = [];
3897
+ }
3898
+ else {
3899
+ // regular element, we should then filter by ownership
3900
+ filtered = getAllMatches(owner, unfilteredNodes);
3901
+ }
3912
3902
  }
3913
- } else if (isNodeShadowed(context)) {
3914
- // element inside a shadowRoot
3915
- const ownerKey = getNodeOwnerKey(context);
3916
- if (!isUndefined(ownerKey)) {
3917
- // context is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
3918
- filtered = ArrayFilter.call(unfilteredNodes, elm => getNodeNearestOwnerKey(elm) === ownerKey);
3919
- } else if (shadowDomSemantic === 1 /* ShadowDomSemantic.Enabled */) {
3920
- // context is inside a shadow, we dont know which one.
3921
- const contextNearestOwnerKey = getNodeNearestOwnerKey(context);
3922
- filtered = ArrayFilter.call(unfilteredNodes, elm => getNodeNearestOwnerKey(elm) === contextNearestOwnerKey);
3923
- } else {
3924
- // context is manually inserted without lwc:dom-manual and ShadowDomSemantics is off, return everything
3925
- filtered = ArraySlice.call(unfilteredNodes);
3903
+ else if (isNodeShadowed(context)) {
3904
+ // element inside a shadowRoot
3905
+ const ownerKey = getNodeOwnerKey(context);
3906
+ if (!isUndefined(ownerKey)) {
3907
+ // context is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
3908
+ filtered = ArrayFilter.call(unfilteredNodes, (elm) => getNodeNearestOwnerKey(elm) === ownerKey);
3909
+ }
3910
+ else {
3911
+ // Note: we deviate from native shadow here, but are not fixing
3912
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3913
+ // context is manually inserted without lwc:dom-manual, return everything
3914
+ filtered = ArraySlice.call(unfilteredNodes);
3915
+ }
3926
3916
  }
3927
- } else {
3928
- if (context instanceof HTMLBodyElement || shadowDomSemantic === 1 /* ShadowDomSemantic.Enabled */) {
3929
- // `context` is document.body or element belonging to the document with the patch enabled
3930
- filtered = ArrayFilter.call(unfilteredNodes,
3931
- // TODO [#1222]: remove global bypass
3932
- elm => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(context));
3933
- } else {
3934
- // `context` is outside the lwc boundary and patch is not enabled.
3935
- filtered = ArraySlice.call(unfilteredNodes);
3917
+ else {
3918
+ if (context instanceof HTMLBodyElement) {
3919
+ // `context` is document.body or element belonging to the document with the patch enabled
3920
+ filtered = ArrayFilter.call(unfilteredNodes, (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(context));
3921
+ }
3922
+ else {
3923
+ // `context` is outside the lwc boundary and patch is not enabled.
3924
+ filtered = ArraySlice.call(unfilteredNodes);
3925
+ }
3936
3926
  }
3937
- }
3938
- return filtered;
3927
+ return filtered;
3939
3928
  }
3940
3929
  // The following patched methods hide shadowed elements from global
3941
3930
  // traversing mechanisms. They are simplified for performance reasons to
@@ -3947,263 +3936,66 @@
3947
3936
  // is not a big problem considering the amount of code that is relying on
3948
3937
  // the liveliness of these results are rare.
3949
3938
  defineProperties(Element.prototype, {
3950
- querySelector: {
3951
- value: querySelectorPatched,
3952
- writable: true,
3953
- enumerable: true,
3954
- configurable: true
3955
- },
3956
- querySelectorAll: {
3957
- value() {
3958
- const nodeList = arrayFromCollection(querySelectorAll$1.apply(this, ArraySlice.call(arguments)));
3959
- if (!lwcRuntimeFlags.ENABLE_NODE_LIST_PATCH) {
3960
- const filteredResults = getFilteredArrayOfNodes(this, nodeList, 0 /* ShadowDomSemantic.Disabled */);
3961
- return createStaticNodeList(filteredResults);
3962
- }
3963
- return createStaticNodeList(getFilteredArrayOfNodes(this, nodeList, 1 /* ShadowDomSemantic.Enabled */));
3939
+ querySelector: {
3940
+ value: querySelectorPatched,
3941
+ writable: true,
3942
+ enumerable: true,
3943
+ configurable: true,
3944
+ },
3945
+ querySelectorAll: {
3946
+ value() {
3947
+ const nodeList = arrayFromCollection(querySelectorAll$1.apply(this, ArraySlice.call(arguments)));
3948
+ // Note: we deviate from native shadow here, but are not fixing
3949
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3950
+ const filteredResults = getFilteredArrayOfNodes(this, nodeList);
3951
+ return createStaticNodeList(filteredResults);
3952
+ },
3953
+ writable: true,
3954
+ enumerable: true,
3955
+ configurable: true,
3964
3956
  },
3965
-
3966
- writable: true,
3967
- enumerable: true,
3968
- configurable: true
3969
- }
3970
3957
  });
3971
3958
  // The following APIs are used directly by Jest internally so we avoid patching them during testing.
3972
3959
  if (process.env.NODE_ENV !== 'test') {
3973
- defineProperties(Element.prototype, {
3974
- getElementsByClassName: {
3975
- value() {
3976
- const elements = arrayFromCollection(getElementsByClassName$1.apply(this, ArraySlice.call(arguments)));
3977
- if (!lwcRuntimeFlags.ENABLE_HTML_COLLECTIONS_PATCH) {
3978
- return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
3979
- }
3980
- const filteredResults = getFilteredArrayOfNodes(this, elements, 1 /* ShadowDomSemantic.Enabled */);
3981
- return createStaticHTMLCollection(filteredResults);
3982
- },
3983
- writable: true,
3984
- enumerable: true,
3985
- configurable: true
3986
- },
3987
- getElementsByTagName: {
3988
- value() {
3989
- const elements = arrayFromCollection(getElementsByTagName$1.apply(this, ArraySlice.call(arguments)));
3990
- if (!lwcRuntimeFlags.ENABLE_HTML_COLLECTIONS_PATCH) {
3991
- return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
3992
- }
3993
- const filteredResults = getFilteredArrayOfNodes(this, elements, 1 /* ShadowDomSemantic.Enabled */);
3994
- return createStaticHTMLCollection(filteredResults);
3995
- },
3996
- writable: true,
3997
- enumerable: true,
3998
- configurable: true
3999
- },
4000
- getElementsByTagNameNS: {
4001
- value() {
4002
- const elements = arrayFromCollection(getElementsByTagNameNS$1.apply(this, ArraySlice.call(arguments)));
4003
- if (!lwcRuntimeFlags.ENABLE_HTML_COLLECTIONS_PATCH) {
4004
- return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
4005
- }
4006
- const filteredResults = getFilteredArrayOfNodes(this, elements, 1 /* ShadowDomSemantic.Enabled */);
4007
- return createStaticHTMLCollection(filteredResults);
4008
- },
4009
- writable: true,
4010
- enumerable: true,
4011
- configurable: true
4012
- }
4013
- });
3960
+ defineProperties(Element.prototype, {
3961
+ getElementsByClassName: {
3962
+ value() {
3963
+ const elements = arrayFromCollection(getElementsByClassName$1.apply(this, ArraySlice.call(arguments)));
3964
+ // Note: we deviate from native shadow here, but are not fixing
3965
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3966
+ return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
3967
+ },
3968
+ writable: true,
3969
+ enumerable: true,
3970
+ configurable: true,
3971
+ },
3972
+ getElementsByTagName: {
3973
+ value() {
3974
+ const elements = arrayFromCollection(getElementsByTagName$1.apply(this, ArraySlice.call(arguments)));
3975
+ // Note: we deviate from native shadow here, but are not fixing
3976
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3977
+ return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
3978
+ },
3979
+ writable: true,
3980
+ enumerable: true,
3981
+ configurable: true,
3982
+ },
3983
+ getElementsByTagNameNS: {
3984
+ value() {
3985
+ const elements = arrayFromCollection(getElementsByTagNameNS$1.apply(this, ArraySlice.call(arguments)));
3986
+ // Note: we deviate from native shadow here, but are not fixing
3987
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3988
+ return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
3989
+ },
3990
+ writable: true,
3991
+ enumerable: true,
3992
+ configurable: true,
3993
+ },
3994
+ });
4014
3995
  }
4015
3996
  // IE11 extra patches for wrong prototypes
4016
3997
  if (hasOwnProperty.call(HTMLElement.prototype, 'getElementsByClassName')) {
4017
- defineProperty(HTMLElement.prototype, 'getElementsByClassName', getOwnPropertyDescriptor(Element.prototype, 'getElementsByClassName'));
4018
- }
4019
-
4020
- /*
4021
- * Copyright (c) 2018, salesforce.com, inc.
4022
- * All rights reserved.
4023
- * SPDX-License-Identifier: MIT
4024
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4025
- */
4026
- function getElementComputedStyle(element) {
4027
- const win = getOwnerWindow(element);
4028
- return windowGetComputedStyle.call(win, element);
4029
- }
4030
- function getWindowSelection(node) {
4031
- const win = getOwnerWindow(node);
4032
- return windowGetSelection.call(win);
4033
- }
4034
- function nodeIsBeingRendered(nodeComputedStyle) {
4035
- return nodeComputedStyle.visibility === 'visible' && nodeComputedStyle.display !== 'none';
4036
- }
4037
- function getSelectionState(element) {
4038
- const win = getOwnerWindow(element);
4039
- const selection = getWindowSelection(element);
4040
- if (selection === null) {
4041
- return null;
4042
- }
4043
- const ranges = [];
4044
- for (let i = 0; i < selection.rangeCount; i++) {
4045
- ranges.push(selection.getRangeAt(i));
4046
- }
4047
- const state = {
4048
- element,
4049
- onselect: win.onselect,
4050
- onselectstart: win.onselectstart,
4051
- onselectionchange: win.onselectionchange,
4052
- ranges,
4053
- };
4054
- win.onselect = null;
4055
- win.onselectstart = null;
4056
- win.onselectionchange = null;
4057
- return state;
4058
- }
4059
- function restoreSelectionState(state) {
4060
- if (state === null) {
4061
- return;
4062
- }
4063
- const { element, onselect, onselectstart, onselectionchange, ranges } = state;
4064
- const win = getOwnerWindow(element);
4065
- const selection = getWindowSelection(element);
4066
- selection.removeAllRanges();
4067
- for (let i = 0; i < ranges.length; i++) {
4068
- selection.addRange(ranges[i]);
4069
- }
4070
- win.onselect = onselect;
4071
- win.onselectstart = onselectstart;
4072
- win.onselectionchange = onselectionchange;
4073
- }
4074
- /**
4075
- * Gets the "innerText" of a text node using the Selection API
4076
- *
4077
- * NOTE: For performance reasons, since this function will be called multiple times while calculating the innerText of
4078
- * an element, it does not restore the current selection.
4079
- */
4080
- function getTextNodeInnerText(textNode) {
4081
- const selection = getWindowSelection(textNode);
4082
- if (selection === null) {
4083
- return textNode.textContent || '';
4084
- }
4085
- const range = document.createRange();
4086
- range.selectNodeContents(textNode);
4087
- const domRect = range.getBoundingClientRect();
4088
- if (domRect.height <= 0 || domRect.width <= 0) {
4089
- // the text node is not rendered
4090
- return '';
4091
- }
4092
- // Needed to remove non rendered characters from the text node.
4093
- selection.removeAllRanges();
4094
- selection.addRange(range);
4095
- const selectionText = selection.toString();
4096
- // The textNode is visible, but it may not be selectable. When the text is not selectable,
4097
- // textContent is the nearest approximation to innerText.
4098
- return selectionText ? selectionText : textNode.textContent || '';
4099
- }
4100
- const nodeIsElement = (node) => node.nodeType === ELEMENT_NODE;
4101
- const nodeIsText = (node) => node.nodeType === TEXT_NODE;
4102
- /**
4103
- * Spec: https://html.spec.whatwg.org/multipage/dom.html#inner-text-collection-steps
4104
- * One spec implementation: https://github.com/servo/servo/blob/721271dcd3c20db5ca8cf146e2b5907647afb4d6/components/layout/query.rs#L1132
4105
- */
4106
- function innerTextCollectionSteps(node) {
4107
- const items = [];
4108
- if (nodeIsElement(node)) {
4109
- const { tagName } = node;
4110
- const computedStyle = getElementComputedStyle(node);
4111
- if (tagName === 'OPTION') {
4112
- // For options, is hard to get the "rendered" text, let's use the original getter.
4113
- return [1, innerTextGetter.call(node), 1];
4114
- }
4115
- else if (tagName === 'TEXTAREA') {
4116
- return [];
4117
- }
4118
- else {
4119
- const childNodes = node.childNodes;
4120
- for (let i = 0, n = childNodes.length; i < n; i++) {
4121
- ArrayPush.apply(items, innerTextCollectionSteps(childNodes[i]));
4122
- }
4123
- }
4124
- if (!nodeIsBeingRendered(computedStyle)) {
4125
- if (tagName === 'SELECT' || tagName === 'DATALIST') {
4126
- // the select is either: .visibility != 'visible' or .display === hidden, therefore this select should
4127
- // not display any value.
4128
- return [];
4129
- }
4130
- return items;
4131
- }
4132
- if (tagName === 'BR') {
4133
- items.push('\u{000A}' /* line feed */);
4134
- }
4135
- const { display } = computedStyle;
4136
- if (display === 'table-cell') {
4137
- // omitting case: and node's CSS box is not the last 'table-cell' box of its enclosing 'table-row' box
4138
- items.push('\u{0009}' /* tab */);
4139
- }
4140
- if (display === 'table-row') {
4141
- // omitting case: and node's CSS box is not the last 'table-row' box of the nearest ancestor 'table' box
4142
- items.push('\u{000A}' /* line feed */);
4143
- }
4144
- if (tagName === 'P') {
4145
- items.unshift(2);
4146
- items.push(2);
4147
- }
4148
- if (display === 'block' ||
4149
- display === 'table-caption' ||
4150
- display === 'flex' ||
4151
- display === 'table') {
4152
- items.unshift(1);
4153
- items.push(1);
4154
- }
4155
- }
4156
- else if (nodeIsText(node)) {
4157
- items.push(getTextNodeInnerText(node));
4158
- }
4159
- return items;
4160
- }
4161
- /**
4162
- * InnerText getter spec: https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute
4163
- *
4164
- * One spec implementation: https://github.com/servo/servo/blob/721271dcd3c20db5ca8cf146e2b5907647afb4d6/components/layout/query.rs#L1087
4165
- */
4166
- function getInnerText(element) {
4167
- const thisComputedStyle = getElementComputedStyle(element);
4168
- if (!nodeIsBeingRendered(thisComputedStyle)) {
4169
- return getTextContent(element) || '';
4170
- }
4171
- const selectionState = getSelectionState(element);
4172
- const results = [];
4173
- const childNodes = element.childNodes;
4174
- for (let i = 0, n = childNodes.length; i < n; i++) {
4175
- ArrayPush.apply(results, innerTextCollectionSteps(childNodes[i]));
4176
- }
4177
- restoreSelectionState(selectionState);
4178
- let elementInnerText = '';
4179
- let maxReqLineBreakCount = 0;
4180
- for (let i = 0, n = results.length; i < n; i++) {
4181
- const item = results[i];
4182
- if (typeof item === 'string') {
4183
- if (maxReqLineBreakCount > 0) {
4184
- for (let j = 0; j < maxReqLineBreakCount; j++) {
4185
- elementInnerText += '\u{000A}';
4186
- }
4187
- maxReqLineBreakCount = 0;
4188
- }
4189
- if (item.length > 0) {
4190
- elementInnerText += item;
4191
- }
4192
- }
4193
- else {
4194
- if (elementInnerText.length == 0) {
4195
- // Remove required line break count at the start.
4196
- continue;
4197
- }
4198
- // Store the count if it's the max of this run,
4199
- // but it may be ignored if no text item is found afterwards,
4200
- // which means that these are consecutive line breaks at the end.
4201
- if (item > maxReqLineBreakCount) {
4202
- maxReqLineBreakCount = item;
4203
- }
4204
- }
4205
- }
4206
- return elementInnerText;
3998
+ defineProperty(HTMLElement.prototype, 'getElementsByClassName', getOwnPropertyDescriptor(Element.prototype, 'getElementsByClassName'));
4207
3999
  }
4208
4000
 
4209
4001
  /*
@@ -4553,209 +4345,184 @@
4553
4345
  * SPDX-License-Identifier: MIT
4554
4346
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4555
4347
  */
4556
- const {
4557
- blur,
4558
- focus
4559
- } = HTMLElement.prototype;
4348
+ const { blur, focus } = HTMLElement.prototype;
4560
4349
  /**
4561
4350
  * This method only applies to elements with a shadow attached to them
4562
4351
  */
4563
4352
  function tabIndexGetterPatched() {
4564
- if (isDelegatingFocus(this) && isFalse(hasAttribute.call(this, 'tabindex'))) {
4565
- // this covers the case where the default tabindex should be 0 because the
4566
- // custom element is delegating its focus
4567
- return 0;
4568
- }
4569
- return tabIndexGetter.call(this);
4353
+ if (isDelegatingFocus(this) && isFalse(hasAttribute.call(this, 'tabindex'))) {
4354
+ // this covers the case where the default tabindex should be 0 because the
4355
+ // custom element is delegating its focus
4356
+ return 0;
4357
+ }
4358
+ return tabIndexGetter.call(this);
4570
4359
  }
4571
4360
  /**
4572
4361
  * This method only applies to elements with a shadow attached to them
4573
4362
  */
4574
4363
  function tabIndexSetterPatched(value) {
4575
- // This tabIndex setter might be confusing unless it is understood that HTML
4576
- // elements have default tabIndex property values. Natively focusable elements have
4577
- // a default tabIndex value of 0 and all other elements have a default tabIndex
4578
- // value of -1. For example, the tabIndex property value is -1 for both <x-foo> and
4579
- // <x-foo tabindex="-1">, but our delegatesFocus polyfill should only kick in for
4580
- // the latter case when the value of the tabindex attribute is -1.
4581
- const delegatesFocus = isDelegatingFocus(this);
4582
- // Record the state of things before invoking component setter.
4583
- const prevValue = tabIndexGetter.call(this);
4584
- const prevHasAttr = hasAttribute.call(this, 'tabindex');
4585
- tabIndexSetter.call(this, value);
4586
- // Record the state of things after invoking component setter.
4587
- const currValue = tabIndexGetter.call(this);
4588
- const currHasAttr = hasAttribute.call(this, 'tabindex');
4589
- const didValueChange = prevValue !== currValue;
4590
- // If the tabindex attribute is initially rendered, we can assume that this setter has
4591
- // previously executed and a listener has been added. We must remove that listener if
4592
- // the tabIndex property value has changed or if the component no longer renders a
4593
- // tabindex attribute.
4594
- if (prevHasAttr && (didValueChange || isFalse(currHasAttr))) {
4595
- if (prevValue === -1) {
4596
- ignoreFocusIn(this);
4597
- }
4598
- if (prevValue === 0 && delegatesFocus) {
4599
- ignoreFocus(this);
4364
+ // This tabIndex setter might be confusing unless it is understood that HTML
4365
+ // elements have default tabIndex property values. Natively focusable elements have
4366
+ // a default tabIndex value of 0 and all other elements have a default tabIndex
4367
+ // value of -1. For example, the tabIndex property value is -1 for both <x-foo> and
4368
+ // <x-foo tabindex="-1">, but our delegatesFocus polyfill should only kick in for
4369
+ // the latter case when the value of the tabindex attribute is -1.
4370
+ const delegatesFocus = isDelegatingFocus(this);
4371
+ // Record the state of things before invoking component setter.
4372
+ const prevValue = tabIndexGetter.call(this);
4373
+ const prevHasAttr = hasAttribute.call(this, 'tabindex');
4374
+ tabIndexSetter.call(this, value);
4375
+ // Record the state of things after invoking component setter.
4376
+ const currValue = tabIndexGetter.call(this);
4377
+ const currHasAttr = hasAttribute.call(this, 'tabindex');
4378
+ const didValueChange = prevValue !== currValue;
4379
+ // If the tabindex attribute is initially rendered, we can assume that this setter has
4380
+ // previously executed and a listener has been added. We must remove that listener if
4381
+ // the tabIndex property value has changed or if the component no longer renders a
4382
+ // tabindex attribute.
4383
+ if (prevHasAttr && (didValueChange || isFalse(currHasAttr))) {
4384
+ if (prevValue === -1) {
4385
+ ignoreFocusIn(this);
4386
+ }
4387
+ if (prevValue === 0 && delegatesFocus) {
4388
+ ignoreFocus(this);
4389
+ }
4390
+ }
4391
+ // If a tabindex attribute was not rendered after invoking its setter, it means the
4392
+ // component is taking control. Do nothing.
4393
+ if (isFalse(currHasAttr)) {
4394
+ return;
4395
+ }
4396
+ // If the tabindex attribute is initially rendered, we can assume that this setter has
4397
+ // previously executed and a listener has been added. If the tabindex attribute is still
4398
+ // rendered after invoking the setter AND the tabIndex property value has not changed,
4399
+ // we don't need to do any work.
4400
+ if (prevHasAttr && currHasAttr && isFalse(didValueChange)) {
4401
+ return;
4402
+ }
4403
+ // At this point we know that a tabindex attribute was rendered after invoking the
4404
+ // setter and that either:
4405
+ // 1) This is the first time this setter is being invoked.
4406
+ // 2) This is not the first time this setter is being invoked and the value is changing.
4407
+ // We need to add the appropriate listeners in either case.
4408
+ if (currValue === -1) {
4409
+ // Add the magic to skip the shadow tree
4410
+ handleFocusIn(this);
4411
+ }
4412
+ if (currValue === 0 && delegatesFocus) {
4413
+ // Add the magic to skip the host element
4414
+ handleFocus(this);
4600
4415
  }
4601
- }
4602
- // If a tabindex attribute was not rendered after invoking its setter, it means the
4603
- // component is taking control. Do nothing.
4604
- if (isFalse(currHasAttr)) {
4605
- return;
4606
- }
4607
- // If the tabindex attribute is initially rendered, we can assume that this setter has
4608
- // previously executed and a listener has been added. If the tabindex attribute is still
4609
- // rendered after invoking the setter AND the tabIndex property value has not changed,
4610
- // we don't need to do any work.
4611
- if (prevHasAttr && currHasAttr && isFalse(didValueChange)) {
4612
- return;
4613
- }
4614
- // At this point we know that a tabindex attribute was rendered after invoking the
4615
- // setter and that either:
4616
- // 1) This is the first time this setter is being invoked.
4617
- // 2) This is not the first time this setter is being invoked and the value is changing.
4618
- // We need to add the appropriate listeners in either case.
4619
- if (currValue === -1) {
4620
- // Add the magic to skip the shadow tree
4621
- handleFocusIn(this);
4622
- }
4623
- if (currValue === 0 && delegatesFocus) {
4624
- // Add the magic to skip the host element
4625
- handleFocus(this);
4626
- }
4627
4416
  }
4628
4417
  /**
4629
4418
  * This method only applies to elements with a shadow attached to them
4630
4419
  */
4631
4420
  function blurPatched() {
4632
- if (isDelegatingFocus(this)) {
4633
- const currentActiveElement = getActiveElement(this);
4634
- if (!isNull(currentActiveElement)) {
4635
- // if there is an active element, blur it (intentionally using the dot notation in case the user defines the blur routine)
4636
- currentActiveElement.blur();
4637
- return;
4421
+ if (isDelegatingFocus(this)) {
4422
+ const currentActiveElement = getActiveElement(this);
4423
+ if (!isNull(currentActiveElement)) {
4424
+ // if there is an active element, blur it (intentionally using the dot notation in case the user defines the blur routine)
4425
+ currentActiveElement.blur();
4426
+ return;
4427
+ }
4638
4428
  }
4639
- }
4640
- return blur.call(this);
4429
+ return blur.call(this);
4641
4430
  }
4642
4431
  function focusPatched() {
4643
- // Save enabled state
4644
- const originallyEnabled = isKeyboardFocusNavigationRoutineEnabled();
4645
- // Change state by disabling if originally enabled
4646
- if (originallyEnabled) {
4647
- disableKeyboardFocusNavigationRoutines();
4648
- }
4649
- if (isSyntheticShadowHost(this) && isDelegatingFocus(this)) {
4650
- hostElementFocus.call(this);
4651
- return;
4652
- }
4653
- // Typescript does not like it when you treat the `arguments` object as an array
4654
- // @ts-ignore type-mismatch
4655
- focus.apply(this, arguments);
4656
- // Restore state by enabling if originally enabled
4657
- if (originallyEnabled) {
4658
- enableKeyboardFocusNavigationRoutines();
4659
- }
4432
+ // Save enabled state
4433
+ const originallyEnabled = isKeyboardFocusNavigationRoutineEnabled();
4434
+ // Change state by disabling if originally enabled
4435
+ if (originallyEnabled) {
4436
+ disableKeyboardFocusNavigationRoutines();
4437
+ }
4438
+ if (isSyntheticShadowHost(this) && isDelegatingFocus(this)) {
4439
+ hostElementFocus.call(this);
4440
+ return;
4441
+ }
4442
+ // Typescript does not like it when you treat the `arguments` object as an array
4443
+ // @ts-ignore type-mismatch
4444
+ focus.apply(this, arguments);
4445
+ // Restore state by enabling if originally enabled
4446
+ if (originallyEnabled) {
4447
+ enableKeyboardFocusNavigationRoutines();
4448
+ }
4660
4449
  }
4661
4450
  // Non-deep-traversing patches: this descriptor map includes all descriptors that
4662
4451
  // do not five access to nodes beyond the immediate children.
4663
4452
  defineProperties(HTMLElement.prototype, {
4664
- tabIndex: {
4665
- get() {
4666
- if (isSyntheticShadowHost(this)) {
4667
- return tabIndexGetterPatched.call(this);
4668
- }
4669
- return tabIndexGetter.call(this);
4670
- },
4671
- set(v) {
4672
- if (isSyntheticShadowHost(this)) {
4673
- return tabIndexSetterPatched.call(this, v);
4674
- }
4675
- return tabIndexSetter.call(this, v);
4453
+ tabIndex: {
4454
+ get() {
4455
+ if (isSyntheticShadowHost(this)) {
4456
+ return tabIndexGetterPatched.call(this);
4457
+ }
4458
+ return tabIndexGetter.call(this);
4459
+ },
4460
+ set(v) {
4461
+ if (isSyntheticShadowHost(this)) {
4462
+ return tabIndexSetterPatched.call(this, v);
4463
+ }
4464
+ return tabIndexSetter.call(this, v);
4465
+ },
4466
+ enumerable: true,
4467
+ configurable: true,
4676
4468
  },
4677
- enumerable: true,
4678
- configurable: true
4679
- },
4680
- blur: {
4681
- value() {
4682
- if (isSyntheticShadowHost(this)) {
4683
- return blurPatched.call(this);
4684
- }
4685
- blur.call(this);
4469
+ blur: {
4470
+ value() {
4471
+ if (isSyntheticShadowHost(this)) {
4472
+ return blurPatched.call(this);
4473
+ }
4474
+ blur.call(this);
4475
+ },
4476
+ enumerable: true,
4477
+ writable: true,
4478
+ configurable: true,
4686
4479
  },
4687
- enumerable: true,
4688
- writable: true,
4689
- configurable: true
4690
- },
4691
- focus: {
4692
- value() {
4693
- // Typescript does not like it when you treat the `arguments` object as an array
4694
- // @ts-ignore type-mismatch
4695
- focusPatched.apply(this, arguments);
4480
+ focus: {
4481
+ value() {
4482
+ // Typescript does not like it when you treat the `arguments` object as an array
4483
+ // @ts-ignore type-mismatch
4484
+ focusPatched.apply(this, arguments);
4485
+ },
4486
+ enumerable: true,
4487
+ writable: true,
4488
+ configurable: true,
4696
4489
  },
4697
- enumerable: true,
4698
- writable: true,
4699
- configurable: true
4700
- }
4701
4490
  });
4702
4491
  // Note: In JSDOM innerText is not implemented: https://github.com/jsdom/jsdom/issues/1245
4703
4492
  if (innerTextGetter !== null && innerTextSetter !== null) {
4704
- defineProperty(HTMLElement.prototype, 'innerText', {
4705
- get() {
4706
- if (!lwcRuntimeFlags.ENABLE_INNER_OUTER_TEXT_PATCH) {
4707
- return innerTextGetter.call(this);
4708
- }
4709
- if (!lwcRuntimeFlags.ENABLE_ELEMENT_PATCH) {
4710
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
4711
- return getInnerText(this);
4712
- }
4713
- return innerTextGetter.call(this);
4714
- }
4715
- // TODO [#1222]: remove global bypass
4716
- if (isGlobalPatchingSkipped(this)) {
4717
- return innerTextGetter.call(this);
4718
- }
4719
- return getInnerText(this);
4720
- },
4721
- set(v) {
4722
- innerTextSetter.call(this, v);
4723
- },
4724
- enumerable: true,
4725
- configurable: true
4726
- });
4493
+ defineProperty(HTMLElement.prototype, 'innerText', {
4494
+ get() {
4495
+ // Note: we deviate from native shadow here, but are not fixing
4496
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
4497
+ return innerTextGetter.call(this);
4498
+ },
4499
+ set(v) {
4500
+ innerTextSetter.call(this, v);
4501
+ },
4502
+ enumerable: true,
4503
+ configurable: true,
4504
+ });
4727
4505
  }
4728
4506
  // Note: Firefox does not have outerText, https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/outerText
4729
4507
  if (outerTextGetter !== null && outerTextSetter !== null) {
4730
- // From https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/outerText :
4731
- // HTMLElement.outerText is a non-standard property. As a getter, it returns the same value as Node.innerText.
4732
- // As a setter, it removes the current node and replaces it with the given text.
4733
- defineProperty(HTMLElement.prototype, 'outerText', {
4734
- get() {
4735
- if (!lwcRuntimeFlags.ENABLE_INNER_OUTER_TEXT_PATCH) {
4736
- return outerTextGetter.call(this);
4737
- }
4738
- if (!lwcRuntimeFlags.ENABLE_ELEMENT_PATCH) {
4739
- if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
4740
- return getInnerText(this);
4741
- }
4742
- return outerTextGetter.call(this);
4743
- }
4744
- // TODO [#1222]: remove global bypass
4745
- if (isGlobalPatchingSkipped(this)) {
4746
- return outerTextGetter.call(this);
4747
- }
4748
- return getInnerText(this);
4749
- },
4750
- set(v) {
4751
- // Invoking the `outerText` setter on a host element should trigger its disconnection, but until we merge node reactions, it will not work.
4752
- // 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))
4753
- // but the benefits don't worth the efforts.
4754
- outerTextSetter.call(this, v);
4755
- },
4756
- enumerable: true,
4757
- configurable: true
4758
- });
4508
+ // From https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/outerText :
4509
+ // HTMLElement.outerText is a non-standard property. As a getter, it returns the same value as Node.innerText.
4510
+ // As a setter, it removes the current node and replaces it with the given text.
4511
+ defineProperty(HTMLElement.prototype, 'outerText', {
4512
+ get() {
4513
+ // Note: we deviate from native shadow here, but are not fixing
4514
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
4515
+ return outerTextGetter.call(this);
4516
+ },
4517
+ set(v) {
4518
+ // Invoking the `outerText` setter on a host element should trigger its disconnection, but until we merge node reactions, it will not work.
4519
+ // 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))
4520
+ // but the benefits don't worth the efforts.
4521
+ outerTextSetter.call(this, v);
4522
+ },
4523
+ enumerable: true,
4524
+ configurable: true,
4525
+ });
4759
4526
  }
4760
4527
 
4761
4528
  /*
@@ -4954,6 +4721,6 @@
4954
4721
  }));
4955
4722
  });
4956
4723
  }
4957
- /** version: 2.32.0 */
4724
+ /** version: 2.32.1 */
4958
4725
 
4959
4726
  }));