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