lwc 2.32.1 → 2.34.0

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 (41) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +842 -595
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +842 -595
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +758 -501
  5. package/dist/engine-dom/iife/es5/engine-dom.js +316 -177
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +329 -173
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +842 -595
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +758 -501
  11. package/dist/engine-dom/umd/es5/engine-dom.js +316 -177
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +329 -173
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +807 -507
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +807 -507
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +7 -5
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +7 -5
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +7 -5
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +7 -5
  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 +5 -3
  34. package/dist/wire-service/iife/es5/wire-service.min.js +1 -1
  35. package/dist/wire-service/iife/es5/wire-service_debug.js +5 -3
  36. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  37. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  38. package/dist/wire-service/umd/es5/wire-service.js +5 -3
  39. package/dist/wire-service/umd/es5/wire-service.min.js +1 -1
  40. package/dist/wire-service/umd/es5/wire-service_debug.js +5 -3
  41. package/package.json +7 -7
@@ -121,6 +121,9 @@
121
121
  * The above list of 46 aria attributes is consistent with the following resources:
122
122
  * https://github.com/w3c/aria/pull/708/files#diff-eacf331f0ffc35d4b482f1d15a887d3bR11060
123
123
  * https://wicg.github.io/aom/spec/aria-reflection.html
124
+ *
125
+ * NOTE: If you update this list, please update test files that implicitly reference this list!
126
+ * Searching the codebase for `aria-flowto` and `ariaFlowTo` should be good enough to find all usages.
124
127
  */
125
128
  const AriaPropertyNames = [
126
129
  'ariaActiveDescendant',
@@ -336,89 +339,7 @@
336
339
  CACHED_ATTRIBUTE_PROPERTY_MAPPING.set(attrName, propertyName);
337
340
  return propertyName;
338
341
  }
339
- /** version: 2.32.1 */
340
-
341
- /**
342
- * Copyright (C) 2018 salesforce.com, inc.
343
- */
344
-
345
- /*
346
- * Copyright (c) 2018, salesforce.com, inc.
347
- * All rights reserved.
348
- * SPDX-License-Identifier: MIT
349
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
350
- */
351
- function detect(propName) {
352
- return getOwnPropertyDescriptor$1(Element.prototype, propName) === undefined;
353
- }
354
-
355
- /*
356
- * Copyright (c) 2018, salesforce.com, inc.
357
- * All rights reserved.
358
- * SPDX-License-Identifier: MIT
359
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
360
- */
361
- const nodeToAriaPropertyValuesMap = new WeakMap();
362
- function getAriaPropertyMap(elm) {
363
- let map = nodeToAriaPropertyValuesMap.get(elm);
364
- if (map === undefined) {
365
- map = {};
366
- nodeToAriaPropertyValuesMap.set(elm, map);
367
- }
368
- return map;
369
- }
370
- function getNormalizedAriaPropertyValue(value) {
371
- return value == null ? null : String(value);
372
- }
373
- function createAriaPropertyPropertyDescriptor(propName, attrName) {
374
- return {
375
- get() {
376
- const map = getAriaPropertyMap(this);
377
- if (hasOwnProperty$1.call(map, propName)) {
378
- return map[propName];
379
- }
380
- // otherwise just reflect what's in the attribute
381
- return this.hasAttribute(attrName) ? this.getAttribute(attrName) : null;
382
- },
383
- set(newValue) {
384
- const normalizedValue = getNormalizedAriaPropertyValue(newValue);
385
- const map = getAriaPropertyMap(this);
386
- map[propName] = normalizedValue;
387
- // reflect into the corresponding attribute
388
- if (newValue === null) {
389
- this.removeAttribute(attrName);
390
- }
391
- else {
392
- this.setAttribute(attrName, newValue);
393
- }
394
- },
395
- configurable: true,
396
- enumerable: true,
397
- };
398
- }
399
- function patch$1(propName) {
400
- // Typescript is inferring the wrong function type for this particular
401
- // overloaded method: https://github.com/Microsoft/TypeScript/issues/27972
402
- // @ts-ignore type-mismatch
403
- const attrName = AriaPropNameToAttrNameMap[propName];
404
- const descriptor = createAriaPropertyPropertyDescriptor(propName, attrName);
405
- Object.defineProperty(Element.prototype, propName, descriptor);
406
- }
407
-
408
- /*
409
- * Copyright (c) 2018, salesforce.com, inc.
410
- * All rights reserved.
411
- * SPDX-License-Identifier: MIT
412
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
413
- */
414
- const ElementPrototypeAriaPropertyNames = keys(AriaPropNameToAttrNameMap);
415
- for (let i = 0, len = ElementPrototypeAriaPropertyNames.length; i < len; i += 1) {
416
- const propName = ElementPrototypeAriaPropertyNames[i];
417
- if (detect(propName)) {
418
- patch$1(propName);
419
- }
420
- }
421
- /** version: 2.32.1 */
342
+ /** version: 2.34.0 */
422
343
 
423
344
  /**
424
345
  * Copyright (C) 2018 salesforce.com, inc.
@@ -440,6 +361,8 @@
440
361
  DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
441
362
  ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
442
363
  ENABLE_FROZEN_TEMPLATE: null,
364
+ DISABLE_ARIA_REFLECTION_POLYFILL: null,
365
+ ENABLE_PROGRAMMATIC_STYLESHEETS: null,
443
366
  };
444
367
  if (!_globalThis.lwcRuntimeFlags) {
445
368
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -483,6 +406,83 @@
483
406
  */
484
407
  function setFeatureFlagForTest(name, value) {
485
408
  }
409
+ /** version: 2.34.0 */
410
+
411
+ /**
412
+ * Copyright (C) 2018 salesforce.com, inc.
413
+ */
414
+
415
+ /*
416
+ * Copyright (c) 2018, salesforce.com, inc.
417
+ * All rights reserved.
418
+ * SPDX-License-Identifier: MIT
419
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
420
+ */
421
+ function detect(propName, prototype) {
422
+ return isUndefined$1(getOwnPropertyDescriptor$1(prototype, propName));
423
+ }
424
+
425
+ /*
426
+ * Copyright (c) 2018, salesforce.com, inc.
427
+ * All rights reserved.
428
+ * SPDX-License-Identifier: MIT
429
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
430
+ */
431
+ function createAriaPropertyPropertyDescriptor(attrName) {
432
+ // Note that we need to call this.{get,set,has,remove}Attribute rather than dereferencing
433
+ // from Element.prototype, because these methods are overridden in LightningElement.
434
+ return {
435
+ get() {
436
+ // reflect what's in the attribute
437
+ return this.hasAttribute(attrName) ? this.getAttribute(attrName) : null;
438
+ },
439
+ set(newValue) {
440
+ // reflect into the corresponding attribute
441
+ if (isNull(newValue)) {
442
+ this.removeAttribute(attrName);
443
+ }
444
+ else {
445
+ this.setAttribute(attrName, newValue);
446
+ }
447
+ },
448
+ configurable: true,
449
+ enumerable: true,
450
+ };
451
+ }
452
+ function patch$1(propName, prototype) {
453
+ const attrName = AriaPropNameToAttrNameMap[propName];
454
+ const descriptor = createAriaPropertyPropertyDescriptor(attrName);
455
+ defineProperty(prototype, propName, descriptor);
456
+ }
457
+
458
+ /*
459
+ * Copyright (c) 2018, salesforce.com, inc.
460
+ * All rights reserved.
461
+ * SPDX-License-Identifier: MIT
462
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
463
+ */
464
+ function applyAriaReflection(prototype = Element.prototype) {
465
+ const ElementPrototypeAriaPropertyNames = keys(AriaPropNameToAttrNameMap);
466
+ for (let i = 0, len = ElementPrototypeAriaPropertyNames.length; i < len; i += 1) {
467
+ const propName = ElementPrototypeAriaPropertyNames[i];
468
+ if (detect(propName, prototype)) {
469
+ patch$1(propName, prototype);
470
+ }
471
+ }
472
+ }
473
+ /** version: 2.34.0 */
474
+
475
+ /*
476
+ * Copyright (c) 2018, salesforce.com, inc.
477
+ * All rights reserved.
478
+ * SPDX-License-Identifier: MIT
479
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
480
+ */
481
+ if (!lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
482
+ // If DISABLE_ARIA_REFLECTION_POLYFILL is false, then we need to apply the ARIA reflection polyfill globally,
483
+ // i.e. to the global Element.prototype
484
+ applyAriaReflection();
485
+ }
486
486
 
487
487
  /*
488
488
  * Copyright (c) 2018, salesforce.com, inc.
@@ -542,6 +542,18 @@
542
542
  }
543
543
  return result;
544
544
  }
545
+ function flattenStylesheets(stylesheets) {
546
+ const list = [];
547
+ for (const stylesheet of stylesheets) {
548
+ if (!Array.isArray(stylesheet)) {
549
+ list.push(stylesheet);
550
+ }
551
+ else {
552
+ list.push(...flattenStylesheets(stylesheet));
553
+ }
554
+ }
555
+ return list;
556
+ }
545
557
  // Set a ref (lwc:ref) on a VM, from a template API
546
558
  function setRefVNode(vm, ref, vnode) {
547
559
  // If this method is called, then vm.refVNodes is set as the template has refs.
@@ -787,6 +799,9 @@
787
799
  // Global HTML Attributes & Properties
788
800
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
789
801
  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
802
+ //
803
+ // If you update this list, check for test files that recapitulate the same list. Searching the codebase
804
+ // for e.g. "dropzone" should suffice.
790
805
  assign(create(null), {
791
806
  accessKey: {
792
807
  attribute: 'accesskey',
@@ -1389,30 +1404,35 @@
1389
1404
  * for the Base Lightning Element, it also include the reactivity bit, so the standard property is reactive.
1390
1405
  */
1391
1406
  function createBridgeToElementDescriptor(propName, descriptor) {
1392
- const { get, set, enumerable, configurable } = descriptor;
1393
- if (!isFunction$1(get)) {
1394
- throw new TypeError();
1395
- }
1396
- if (!isFunction$1(set)) {
1397
- throw new TypeError();
1407
+ const {
1408
+ get,
1409
+ set,
1410
+ enumerable,
1411
+ configurable
1412
+ } = descriptor;
1413
+ if (!isFunction$1(get)) {
1414
+ throw new TypeError();
1415
+ }
1416
+ if (!isFunction$1(set)) {
1417
+ throw new TypeError();
1418
+ }
1419
+ return {
1420
+ enumerable,
1421
+ configurable,
1422
+ get() {
1423
+ const vm = getAssociatedVM(this);
1424
+ if (isBeingConstructed(vm)) {
1425
+ return;
1426
+ }
1427
+ componentValueObserved(vm, propName);
1428
+ return get.call(vm.elm);
1429
+ },
1430
+ set(newValue) {
1431
+ const vm = getAssociatedVM(this);
1432
+ updateComponentValue(vm, propName, newValue);
1433
+ return set.call(vm.elm, newValue);
1398
1434
  }
1399
- return {
1400
- enumerable,
1401
- configurable,
1402
- get() {
1403
- const vm = getAssociatedVM(this);
1404
- if (isBeingConstructed(vm)) {
1405
- return;
1406
- }
1407
- componentValueObserved(vm, propName);
1408
- return get.call(vm.elm);
1409
- },
1410
- set(newValue) {
1411
- const vm = getAssociatedVM(this);
1412
- updateComponentValue(vm, propName, newValue);
1413
- return set.call(vm.elm, newValue);
1414
- },
1415
- };
1435
+ };
1416
1436
  }
1417
1437
  const EMPTY_REFS = freeze(create(null));
1418
1438
  const refsCache = new WeakMap();
@@ -1422,262 +1442,361 @@
1422
1442
  **/
1423
1443
  // @ts-ignore
1424
1444
  const LightningElement = function () {
1425
- // This should be as performant as possible, while any initialization should be done lazily
1426
- if (isNull(vmBeingConstructed)) {
1427
- // Thrown when doing something like `new LightningElement()` or
1428
- // `class Foo extends LightningElement {}; new Foo()`
1429
- throw new TypeError('Illegal constructor');
1430
- }
1431
- const vm = vmBeingConstructed;
1432
- const { def, elm } = vm;
1433
- const { bridge } = def;
1434
- const component = this;
1435
- setPrototypeOf(elm, bridge.prototype);
1436
- vm.component = this;
1437
- // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
1438
- // component creation and passes hooks to instrument all the component interactions with the
1439
- // engine. We are intentionally hiding this argument from the formal API of LightningElement
1440
- // because we don't want folks to know about it just yet.
1441
- if (arguments.length === 1) {
1442
- const { callHook, setHook, getHook } = arguments[0];
1443
- vm.callHook = callHook;
1444
- vm.setHook = setHook;
1445
- vm.getHook = getHook;
1446
- }
1447
- markLockerLiveObject(this);
1448
- // Linking elm, shadow root and component with the VM.
1449
- associateVM(component, vm);
1450
- associateVM(elm, vm);
1451
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
1452
- vm.renderRoot = doAttachShadow(vm);
1453
- }
1454
- else {
1455
- vm.renderRoot = elm;
1456
- }
1457
- return this;
1445
+ // This should be as performant as possible, while any initialization should be done lazily
1446
+ if (isNull(vmBeingConstructed)) {
1447
+ // Thrown when doing something like `new LightningElement()` or
1448
+ // `class Foo extends LightningElement {}; new Foo()`
1449
+ throw new TypeError('Illegal constructor');
1450
+ }
1451
+ const vm = vmBeingConstructed;
1452
+ const {
1453
+ def,
1454
+ elm
1455
+ } = vm;
1456
+ const {
1457
+ bridge
1458
+ } = def;
1459
+ const component = this;
1460
+ setPrototypeOf(elm, bridge.prototype);
1461
+ vm.component = this;
1462
+ // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
1463
+ // component creation and passes hooks to instrument all the component interactions with the
1464
+ // engine. We are intentionally hiding this argument from the formal API of LightningElement
1465
+ // because we don't want folks to know about it just yet.
1466
+ if (arguments.length === 1) {
1467
+ const {
1468
+ callHook,
1469
+ setHook,
1470
+ getHook
1471
+ } = arguments[0];
1472
+ vm.callHook = callHook;
1473
+ vm.setHook = setHook;
1474
+ vm.getHook = getHook;
1475
+ }
1476
+ markLockerLiveObject(this);
1477
+ // Linking elm, shadow root and component with the VM.
1478
+ associateVM(component, vm);
1479
+ associateVM(elm, vm);
1480
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
1481
+ vm.renderRoot = doAttachShadow(vm);
1482
+ } else {
1483
+ vm.renderRoot = elm;
1484
+ }
1485
+ return this;
1458
1486
  };
1459
1487
  function doAttachShadow(vm) {
1460
- const { elm, mode, shadowMode, def: { ctor }, renderer: { attachShadow }, } = vm;
1461
- const shadowRoot = attachShadow(elm, {
1462
- [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
1463
- delegatesFocus: Boolean(ctor.delegatesFocus),
1464
- mode,
1465
- });
1466
- vm.shadowRoot = shadowRoot;
1467
- associateVM(shadowRoot, vm);
1468
- return shadowRoot;
1488
+ const {
1489
+ elm,
1490
+ mode,
1491
+ shadowMode,
1492
+ def: {
1493
+ ctor
1494
+ },
1495
+ renderer: {
1496
+ attachShadow
1497
+ }
1498
+ } = vm;
1499
+ const shadowRoot = attachShadow(elm, {
1500
+ [KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
1501
+ delegatesFocus: Boolean(ctor.delegatesFocus),
1502
+ mode
1503
+ });
1504
+ vm.shadowRoot = shadowRoot;
1505
+ associateVM(shadowRoot, vm);
1506
+ return shadowRoot;
1469
1507
  }
1470
1508
  // @ts-ignore
1471
1509
  LightningElement.prototype = {
1472
- constructor: LightningElement,
1473
- dispatchEvent(event) {
1474
- const vm = getAssociatedVM(this);
1475
- const { elm, renderer: { dispatchEvent }, } = vm;
1476
- return dispatchEvent(elm, event);
1477
- },
1478
- addEventListener(type, listener, options) {
1479
- const vm = getAssociatedVM(this);
1480
- const { elm, renderer: { addEventListener }, } = vm;
1481
- const wrappedListener = getWrappedComponentsListener(vm, listener);
1482
- addEventListener(elm, type, wrappedListener, options);
1483
- },
1484
- removeEventListener(type, listener, options) {
1485
- const vm = getAssociatedVM(this);
1486
- const { elm, renderer: { removeEventListener }, } = vm;
1487
- const wrappedListener = getWrappedComponentsListener(vm, listener);
1488
- removeEventListener(elm, type, wrappedListener, options);
1489
- },
1490
- hasAttribute(name) {
1491
- const vm = getAssociatedVM(this);
1492
- const { elm, renderer: { getAttribute }, } = vm;
1493
- return !isNull(getAttribute(elm, name));
1494
- },
1495
- hasAttributeNS(namespace, name) {
1496
- const vm = getAssociatedVM(this);
1497
- const { elm, renderer: { getAttribute }, } = vm;
1498
- return !isNull(getAttribute(elm, name, namespace));
1499
- },
1500
- removeAttribute(name) {
1501
- const vm = getAssociatedVM(this);
1502
- const { elm, renderer: { removeAttribute }, } = vm;
1503
- unlockAttribute(elm, name);
1504
- removeAttribute(elm, name);
1505
- lockAttribute();
1506
- },
1507
- removeAttributeNS(namespace, name) {
1508
- const { elm, renderer: { removeAttribute }, } = getAssociatedVM(this);
1509
- unlockAttribute(elm, name);
1510
- removeAttribute(elm, name, namespace);
1511
- lockAttribute();
1512
- },
1513
- getAttribute(name) {
1514
- const vm = getAssociatedVM(this);
1515
- const { elm } = vm;
1516
- const { getAttribute } = vm.renderer;
1517
- return getAttribute(elm, name);
1518
- },
1519
- getAttributeNS(namespace, name) {
1520
- const vm = getAssociatedVM(this);
1521
- const { elm } = vm;
1522
- const { getAttribute } = vm.renderer;
1523
- return getAttribute(elm, name, namespace);
1524
- },
1525
- setAttribute(name, value) {
1526
- const vm = getAssociatedVM(this);
1527
- const { elm, renderer: { setAttribute }, } = vm;
1528
- unlockAttribute(elm, name);
1529
- setAttribute(elm, name, value);
1530
- lockAttribute();
1531
- },
1532
- setAttributeNS(namespace, name, value) {
1533
- const vm = getAssociatedVM(this);
1534
- const { elm, renderer: { setAttribute }, } = vm;
1535
- unlockAttribute(elm, name);
1536
- setAttribute(elm, name, value, namespace);
1537
- lockAttribute();
1538
- },
1539
- getBoundingClientRect() {
1540
- const vm = getAssociatedVM(this);
1541
- const { elm, renderer: { getBoundingClientRect }, } = vm;
1542
- return getBoundingClientRect(elm);
1543
- },
1544
- get isConnected() {
1545
- const vm = getAssociatedVM(this);
1546
- const { elm, renderer: { isConnected }, } = vm;
1547
- return isConnected(elm);
1548
- },
1549
- get classList() {
1550
- const vm = getAssociatedVM(this);
1551
- const { elm, renderer: { getClassList }, } = vm;
1552
- return getClassList(elm);
1553
- },
1554
- get template() {
1555
- const vm = getAssociatedVM(this);
1556
- return vm.shadowRoot;
1557
- },
1558
- get refs() {
1559
- const vm = getAssociatedVM(this);
1560
- if (isUpdatingTemplate) {
1561
- // If the template is in the process of being updated, then we don't want to go through the normal
1562
- // process of returning the refs and caching them, because the state of the refs is unstable.
1563
- // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
1564
- // based on `this.refs.bar`.
1565
- return;
1566
- }
1567
- const { refVNodes, hasRefVNodes, cmpTemplate } = vm;
1568
- // For backwards compatibility with component written before template refs
1569
- // were introduced, we return undefined if the template has no refs defined
1570
- // anywhere. This fixes components that may want to add an expando called `refs`
1571
- // and are checking if it exists with `if (this.refs)` before adding it.
1572
- // Note it is not sufficient to just check if `refVNodes` is null or empty,
1573
- // because a template may have `lwc:ref` defined within a falsy `if:true` block.
1574
- if (!hasRefVNodes) {
1575
- return;
1576
- }
1577
- // For templates that are using `lwc:ref`, if there are no refs currently available
1578
- // (e.g. refs inside of a falsy `if:true` block), we return an empty object.
1579
- if (isNull(refVNodes)) {
1580
- return EMPTY_REFS;
1581
- }
1582
- // The refNodes can be cached based on the refVNodes, since the refVNodes
1583
- // are recreated from scratch every time the template is rendered.
1584
- // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
1585
- let refs = refsCache.get(refVNodes);
1586
- if (isUndefined$1(refs)) {
1587
- refs = create(null);
1588
- for (const key of keys(refVNodes)) {
1589
- refs[key] = refVNodes[key].elm;
1590
- }
1591
- freeze(refs);
1592
- refsCache.set(refVNodes, refs);
1593
- }
1594
- return refs;
1595
- },
1596
- // For backwards compat, we allow component authors to set `refs` as an expando
1597
- set refs(value) {
1598
- defineProperty(this, 'refs', {
1599
- configurable: true,
1600
- enumerable: true,
1601
- writable: true,
1602
- value,
1603
- });
1604
- },
1605
- get shadowRoot() {
1606
- // From within the component instance, the shadowRoot is always reported as "closed".
1607
- // Authors should rely on this.template instead.
1608
- return null;
1609
- },
1610
- get children() {
1611
- const vm = getAssociatedVM(this);
1612
- const renderer = vm.renderer;
1613
- return renderer.getChildren(vm.elm);
1614
- },
1615
- get childNodes() {
1616
- const vm = getAssociatedVM(this);
1617
- const renderer = vm.renderer;
1618
- return renderer.getChildNodes(vm.elm);
1619
- },
1620
- get firstChild() {
1621
- const vm = getAssociatedVM(this);
1622
- const renderer = vm.renderer;
1623
- return renderer.getFirstChild(vm.elm);
1624
- },
1625
- get firstElementChild() {
1626
- const vm = getAssociatedVM(this);
1627
- const renderer = vm.renderer;
1628
- return renderer.getFirstElementChild(vm.elm);
1629
- },
1630
- get lastChild() {
1631
- const vm = getAssociatedVM(this);
1632
- const renderer = vm.renderer;
1633
- return renderer.getLastChild(vm.elm);
1634
- },
1635
- get lastElementChild() {
1636
- const vm = getAssociatedVM(this);
1637
- const renderer = vm.renderer;
1638
- return renderer.getLastElementChild(vm.elm);
1639
- },
1640
- render() {
1641
- const vm = getAssociatedVM(this);
1642
- return vm.def.template;
1643
- },
1644
- toString() {
1645
- const vm = getAssociatedVM(this);
1646
- return `[object ${vm.def.name}]`;
1647
- },
1510
+ constructor: LightningElement,
1511
+ dispatchEvent(event) {
1512
+ const vm = getAssociatedVM(this);
1513
+ const {
1514
+ elm,
1515
+ renderer: {
1516
+ dispatchEvent
1517
+ }
1518
+ } = vm;
1519
+ return dispatchEvent(elm, event);
1520
+ },
1521
+ addEventListener(type, listener, options) {
1522
+ const vm = getAssociatedVM(this);
1523
+ const {
1524
+ elm,
1525
+ renderer: {
1526
+ addEventListener
1527
+ }
1528
+ } = vm;
1529
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
1530
+ addEventListener(elm, type, wrappedListener, options);
1531
+ },
1532
+ removeEventListener(type, listener, options) {
1533
+ const vm = getAssociatedVM(this);
1534
+ const {
1535
+ elm,
1536
+ renderer: {
1537
+ removeEventListener
1538
+ }
1539
+ } = vm;
1540
+ const wrappedListener = getWrappedComponentsListener(vm, listener);
1541
+ removeEventListener(elm, type, wrappedListener, options);
1542
+ },
1543
+ hasAttribute(name) {
1544
+ const vm = getAssociatedVM(this);
1545
+ const {
1546
+ elm,
1547
+ renderer: {
1548
+ getAttribute
1549
+ }
1550
+ } = vm;
1551
+ return !isNull(getAttribute(elm, name));
1552
+ },
1553
+ hasAttributeNS(namespace, name) {
1554
+ const vm = getAssociatedVM(this);
1555
+ const {
1556
+ elm,
1557
+ renderer: {
1558
+ getAttribute
1559
+ }
1560
+ } = vm;
1561
+ return !isNull(getAttribute(elm, name, namespace));
1562
+ },
1563
+ removeAttribute(name) {
1564
+ const vm = getAssociatedVM(this);
1565
+ const {
1566
+ elm,
1567
+ renderer: {
1568
+ removeAttribute
1569
+ }
1570
+ } = vm;
1571
+ unlockAttribute(elm, name);
1572
+ removeAttribute(elm, name);
1573
+ lockAttribute();
1574
+ },
1575
+ removeAttributeNS(namespace, name) {
1576
+ const {
1577
+ elm,
1578
+ renderer: {
1579
+ removeAttribute
1580
+ }
1581
+ } = getAssociatedVM(this);
1582
+ unlockAttribute(elm, name);
1583
+ removeAttribute(elm, name, namespace);
1584
+ lockAttribute();
1585
+ },
1586
+ getAttribute(name) {
1587
+ const vm = getAssociatedVM(this);
1588
+ const {
1589
+ elm
1590
+ } = vm;
1591
+ const {
1592
+ getAttribute
1593
+ } = vm.renderer;
1594
+ return getAttribute(elm, name);
1595
+ },
1596
+ getAttributeNS(namespace, name) {
1597
+ const vm = getAssociatedVM(this);
1598
+ const {
1599
+ elm
1600
+ } = vm;
1601
+ const {
1602
+ getAttribute
1603
+ } = vm.renderer;
1604
+ return getAttribute(elm, name, namespace);
1605
+ },
1606
+ setAttribute(name, value) {
1607
+ const vm = getAssociatedVM(this);
1608
+ const {
1609
+ elm,
1610
+ renderer: {
1611
+ setAttribute
1612
+ }
1613
+ } = vm;
1614
+ unlockAttribute(elm, name);
1615
+ setAttribute(elm, name, value);
1616
+ lockAttribute();
1617
+ },
1618
+ setAttributeNS(namespace, name, value) {
1619
+ const vm = getAssociatedVM(this);
1620
+ const {
1621
+ elm,
1622
+ renderer: {
1623
+ setAttribute
1624
+ }
1625
+ } = vm;
1626
+ unlockAttribute(elm, name);
1627
+ setAttribute(elm, name, value, namespace);
1628
+ lockAttribute();
1629
+ },
1630
+ getBoundingClientRect() {
1631
+ const vm = getAssociatedVM(this);
1632
+ const {
1633
+ elm,
1634
+ renderer: {
1635
+ getBoundingClientRect
1636
+ }
1637
+ } = vm;
1638
+ return getBoundingClientRect(elm);
1639
+ },
1640
+ get isConnected() {
1641
+ const vm = getAssociatedVM(this);
1642
+ const {
1643
+ elm,
1644
+ renderer: {
1645
+ isConnected
1646
+ }
1647
+ } = vm;
1648
+ return isConnected(elm);
1649
+ },
1650
+ get classList() {
1651
+ const vm = getAssociatedVM(this);
1652
+ const {
1653
+ elm,
1654
+ renderer: {
1655
+ getClassList
1656
+ }
1657
+ } = vm;
1658
+ return getClassList(elm);
1659
+ },
1660
+ get template() {
1661
+ const vm = getAssociatedVM(this);
1662
+ return vm.shadowRoot;
1663
+ },
1664
+ get refs() {
1665
+ const vm = getAssociatedVM(this);
1666
+ if (isUpdatingTemplate) {
1667
+ // If the template is in the process of being updated, then we don't want to go through the normal
1668
+ // process of returning the refs and caching them, because the state of the refs is unstable.
1669
+ // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
1670
+ // based on `this.refs.bar`.
1671
+ return;
1672
+ }
1673
+ const {
1674
+ refVNodes,
1675
+ hasRefVNodes,
1676
+ cmpTemplate
1677
+ } = vm;
1678
+ // For backwards compatibility with component written before template refs
1679
+ // were introduced, we return undefined if the template has no refs defined
1680
+ // anywhere. This fixes components that may want to add an expando called `refs`
1681
+ // and are checking if it exists with `if (this.refs)` before adding it.
1682
+ // Note it is not sufficient to just check if `refVNodes` is null or empty,
1683
+ // because a template may have `lwc:ref` defined within a falsy `if:true` block.
1684
+ if (!hasRefVNodes) {
1685
+ return;
1686
+ }
1687
+ // For templates that are using `lwc:ref`, if there are no refs currently available
1688
+ // (e.g. refs inside of a falsy `if:true` block), we return an empty object.
1689
+ if (isNull(refVNodes)) {
1690
+ return EMPTY_REFS;
1691
+ }
1692
+ // The refNodes can be cached based on the refVNodes, since the refVNodes
1693
+ // are recreated from scratch every time the template is rendered.
1694
+ // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
1695
+ let refs = refsCache.get(refVNodes);
1696
+ if (isUndefined$1(refs)) {
1697
+ refs = create(null);
1698
+ for (const key of keys(refVNodes)) {
1699
+ refs[key] = refVNodes[key].elm;
1700
+ }
1701
+ freeze(refs);
1702
+ refsCache.set(refVNodes, refs);
1703
+ }
1704
+ return refs;
1705
+ },
1706
+ // For backwards compat, we allow component authors to set `refs` as an expando
1707
+ set refs(value) {
1708
+ defineProperty(this, 'refs', {
1709
+ configurable: true,
1710
+ enumerable: true,
1711
+ writable: true,
1712
+ value
1713
+ });
1714
+ },
1715
+ get shadowRoot() {
1716
+ // From within the component instance, the shadowRoot is always reported as "closed".
1717
+ // Authors should rely on this.template instead.
1718
+ return null;
1719
+ },
1720
+ get children() {
1721
+ const vm = getAssociatedVM(this);
1722
+ const renderer = vm.renderer;
1723
+ return renderer.getChildren(vm.elm);
1724
+ },
1725
+ get childNodes() {
1726
+ const vm = getAssociatedVM(this);
1727
+ const renderer = vm.renderer;
1728
+ return renderer.getChildNodes(vm.elm);
1729
+ },
1730
+ get firstChild() {
1731
+ const vm = getAssociatedVM(this);
1732
+ const renderer = vm.renderer;
1733
+ return renderer.getFirstChild(vm.elm);
1734
+ },
1735
+ get firstElementChild() {
1736
+ const vm = getAssociatedVM(this);
1737
+ const renderer = vm.renderer;
1738
+ return renderer.getFirstElementChild(vm.elm);
1739
+ },
1740
+ get lastChild() {
1741
+ const vm = getAssociatedVM(this);
1742
+ const renderer = vm.renderer;
1743
+ return renderer.getLastChild(vm.elm);
1744
+ },
1745
+ get lastElementChild() {
1746
+ const vm = getAssociatedVM(this);
1747
+ const renderer = vm.renderer;
1748
+ return renderer.getLastElementChild(vm.elm);
1749
+ },
1750
+ render() {
1751
+ const vm = getAssociatedVM(this);
1752
+ return vm.def.template;
1753
+ },
1754
+ toString() {
1755
+ const vm = getAssociatedVM(this);
1756
+ return `[object ${vm.def.name}]`;
1757
+ }
1648
1758
  };
1649
1759
  const queryAndChildGetterDescriptors = create(null);
1650
- const queryMethods = [
1651
- 'getElementsByClassName',
1652
- 'getElementsByTagName',
1653
- 'querySelector',
1654
- 'querySelectorAll',
1655
- ];
1760
+ const queryMethods = ['getElementsByClassName', 'getElementsByTagName', 'querySelector', 'querySelectorAll'];
1656
1761
  // Generic passthrough for query APIs on HTMLElement to the relevant Renderer APIs
1657
1762
  for (const queryMethod of queryMethods) {
1658
- queryAndChildGetterDescriptors[queryMethod] = {
1659
- value(arg) {
1660
- const vm = getAssociatedVM(this);
1661
- const { elm, renderer } = vm;
1662
- return renderer[queryMethod](elm, arg);
1663
- },
1664
- configurable: true,
1665
- enumerable: true,
1666
- writable: true,
1667
- };
1763
+ queryAndChildGetterDescriptors[queryMethod] = {
1764
+ value(arg) {
1765
+ const vm = getAssociatedVM(this);
1766
+ const {
1767
+ elm,
1768
+ renderer
1769
+ } = vm;
1770
+ return renderer[queryMethod](elm, arg);
1771
+ },
1772
+ configurable: true,
1773
+ enumerable: true,
1774
+ writable: true
1775
+ };
1668
1776
  }
1669
1777
  defineProperties(LightningElement.prototype, queryAndChildGetterDescriptors);
1670
1778
  const lightningBasedDescriptors = create(null);
1671
1779
  for (const propName in HTMLElementOriginalDescriptors) {
1672
- lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
1780
+ lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
1673
1781
  }
1674
1782
  defineProperties(LightningElement.prototype, lightningBasedDescriptors);
1783
+ function applyAriaReflectionToLightningElement() {
1784
+ // If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
1785
+ // apply it to LightningElement.prototype.
1786
+ // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
1787
+ applyAriaReflection(LightningElement.prototype);
1788
+ }
1789
+ // The reason for this odd if/else branching is limitations in @lwc/features:
1790
+ // https://github.com/salesforce/lwc/blob/master/packages/%40lwc/features/README.md#only-works-with-if-statements
1791
+ if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
1792
+ applyAriaReflectionToLightningElement();
1793
+ }
1675
1794
  defineProperty(LightningElement, 'CustomElementConstructor', {
1676
- get() {
1677
- // If required, a runtime-specific implementation must be defined.
1678
- throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
1679
- },
1680
- configurable: true,
1795
+ get() {
1796
+ // If required, a runtime-specific implementation must be defined.
1797
+ throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
1798
+ },
1799
+ configurable: true
1681
1800
  });
1682
1801
 
1683
1802
  function createObservedFieldPropertyDescriptor(key) {
@@ -1964,138 +2083,161 @@
1964
2083
  const cachedGetterByKey = create(null);
1965
2084
  const cachedSetterByKey = create(null);
1966
2085
  function createGetter(key) {
1967
- let fn = cachedGetterByKey[key];
1968
- if (isUndefined$1(fn)) {
1969
- fn = cachedGetterByKey[key] = function () {
1970
- const vm = getAssociatedVM(this);
1971
- const { getHook } = vm;
1972
- return getHook(vm.component, key);
1973
- };
1974
- }
1975
- return fn;
2086
+ let fn = cachedGetterByKey[key];
2087
+ if (isUndefined$1(fn)) {
2088
+ fn = cachedGetterByKey[key] = function () {
2089
+ const vm = getAssociatedVM(this);
2090
+ const {
2091
+ getHook
2092
+ } = vm;
2093
+ return getHook(vm.component, key);
2094
+ };
2095
+ }
2096
+ return fn;
1976
2097
  }
1977
2098
  function createSetter(key) {
1978
- let fn = cachedSetterByKey[key];
1979
- if (isUndefined$1(fn)) {
1980
- fn = cachedSetterByKey[key] = function (newValue) {
1981
- const vm = getAssociatedVM(this);
1982
- const { setHook } = vm;
1983
- newValue = getReadOnlyProxy(newValue);
1984
- setHook(vm.component, key, newValue);
1985
- };
1986
- }
1987
- return fn;
2099
+ let fn = cachedSetterByKey[key];
2100
+ if (isUndefined$1(fn)) {
2101
+ fn = cachedSetterByKey[key] = function (newValue) {
2102
+ const vm = getAssociatedVM(this);
2103
+ const {
2104
+ setHook
2105
+ } = vm;
2106
+ newValue = getReadOnlyProxy(newValue);
2107
+ setHook(vm.component, key, newValue);
2108
+ };
2109
+ }
2110
+ return fn;
1988
2111
  }
1989
2112
  function createMethodCaller(methodName) {
1990
- return function () {
1991
- const vm = getAssociatedVM(this);
1992
- const { callHook, component } = vm;
1993
- const fn = component[methodName];
1994
- return callHook(vm.component, fn, ArraySlice.call(arguments));
1995
- };
2113
+ return function () {
2114
+ const vm = getAssociatedVM(this);
2115
+ const {
2116
+ callHook,
2117
+ component
2118
+ } = vm;
2119
+ const fn = component[methodName];
2120
+ return callHook(vm.component, fn, ArraySlice.call(arguments));
2121
+ };
1996
2122
  }
1997
2123
  function createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback) {
1998
- return function attributeChangedCallback(attrName, oldValue, newValue) {
1999
- if (oldValue === newValue) {
2000
- // Ignore same values.
2001
- return;
2002
- }
2003
- const propName = attributeToPropMap[attrName];
2004
- if (isUndefined$1(propName)) {
2005
- if (!isUndefined$1(superAttributeChangedCallback)) {
2006
- // delegate unknown attributes to the super.
2007
- // Typescript does not like it when you treat the `arguments` object as an array
2008
- // @ts-ignore type-mismatch
2009
- superAttributeChangedCallback.apply(this, arguments);
2010
- }
2011
- return;
2012
- }
2013
- if (!isAttributeLocked(this, attrName)) {
2014
- // Ignore changes triggered by the engine itself during:
2015
- // * diffing when public props are attempting to reflect to the DOM
2016
- // * component via `this.setAttribute()`, should never update the prop
2017
- // Both cases, the setAttribute call is always wrapped by the unlocking of the
2018
- // attribute to be changed
2019
- return;
2020
- }
2021
- // Reflect attribute change to the corresponding property when changed from outside.
2022
- this[propName] = newValue;
2023
- };
2024
- }
2025
- function HTMLBridgeElementFactory(SuperClass, props, methods) {
2026
- let HTMLBridgeElement;
2027
- /**
2028
- * Modern browsers will have all Native Constructors as regular Classes
2029
- * and must be instantiated with the new keyword. In older browsers,
2030
- * specifically IE11, those are objects with a prototype property defined,
2031
- * since they are not supposed to be extended or instantiated with the
2032
- * new keyword. This forking logic supports both cases, specifically because
2033
- * wc.ts relies on the construction path of the bridges to create new
2034
- * fully qualifying web components.
2035
- */
2036
- if (isFunction$1(SuperClass)) {
2037
- HTMLBridgeElement = class extends SuperClass {
2038
- };
2039
- }
2040
- else {
2041
- HTMLBridgeElement = function () {
2042
- // Bridge classes are not supposed to be instantiated directly in
2043
- // browsers that do not support web components.
2044
- throw new TypeError('Illegal constructor');
2045
- };
2046
- // prototype inheritance dance
2047
- setPrototypeOf(HTMLBridgeElement, SuperClass);
2048
- setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2049
- defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2050
- writable: true,
2051
- configurable: true,
2052
- value: HTMLBridgeElement,
2053
- });
2124
+ return function attributeChangedCallback(attrName, oldValue, newValue) {
2125
+ if (oldValue === newValue) {
2126
+ // Ignore same values.
2127
+ return;
2054
2128
  }
2055
- // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2056
- // and false positives in case of inheritance.
2057
- const attributeToPropMap = create(null);
2058
- const { attributeChangedCallback: superAttributeChangedCallback } = SuperClass.prototype;
2059
- const { observedAttributes: superObservedAttributes = [] } = SuperClass;
2060
- const descriptors = create(null);
2061
- // expose getters and setters for each public props on the new Element Bridge
2062
- for (let i = 0, len = props.length; i < len; i += 1) {
2063
- const propName = props[i];
2064
- attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
2065
- descriptors[propName] = {
2066
- get: createGetter(propName),
2067
- set: createSetter(propName),
2068
- enumerable: true,
2069
- configurable: true,
2070
- };
2129
+ const propName = attributeToPropMap[attrName];
2130
+ if (isUndefined$1(propName)) {
2131
+ if (!isUndefined$1(superAttributeChangedCallback)) {
2132
+ // delegate unknown attributes to the super.
2133
+ // Typescript does not like it when you treat the `arguments` object as an array
2134
+ // @ts-ignore type-mismatch
2135
+ superAttributeChangedCallback.apply(this, arguments);
2136
+ }
2137
+ return;
2071
2138
  }
2072
- // expose public methods as props on the new Element Bridge
2073
- for (let i = 0, len = methods.length; i < len; i += 1) {
2074
- const methodName = methods[i];
2075
- descriptors[methodName] = {
2076
- value: createMethodCaller(methodName),
2077
- writable: true,
2078
- configurable: true,
2079
- };
2139
+ if (!isAttributeLocked(this, attrName)) {
2140
+ // Ignore changes triggered by the engine itself during:
2141
+ // * diffing when public props are attempting to reflect to the DOM
2142
+ // * component via `this.setAttribute()`, should never update the prop
2143
+ // Both cases, the setAttribute call is always wrapped by the unlocking of the
2144
+ // attribute to be changed
2145
+ return;
2080
2146
  }
2081
- // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
2082
- // map of attributes to props. We do this after all other props and methods to avoid the possibility
2083
- // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
2084
- // to preserve this definition.
2085
- descriptors.attributeChangedCallback = {
2086
- value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback),
2147
+ // Reflect attribute change to the corresponding property when changed from outside.
2148
+ this[propName] = newValue;
2149
+ };
2150
+ }
2151
+ function HTMLBridgeElementFactory(SuperClass, props, methods) {
2152
+ let HTMLBridgeElement;
2153
+ /**
2154
+ * Modern browsers will have all Native Constructors as regular Classes
2155
+ * and must be instantiated with the new keyword. In older browsers,
2156
+ * specifically IE11, those are objects with a prototype property defined,
2157
+ * since they are not supposed to be extended or instantiated with the
2158
+ * new keyword. This forking logic supports both cases, specifically because
2159
+ * wc.ts relies on the construction path of the bridges to create new
2160
+ * fully qualifying web components.
2161
+ */
2162
+ if (isFunction$1(SuperClass)) {
2163
+ HTMLBridgeElement = class extends SuperClass {};
2164
+ } else {
2165
+ HTMLBridgeElement = function () {
2166
+ // Bridge classes are not supposed to be instantiated directly in
2167
+ // browsers that do not support web components.
2168
+ throw new TypeError('Illegal constructor');
2087
2169
  };
2088
- // Specify attributes for which we want to reflect changes back to their corresponding
2089
- // properties via attributeChangedCallback.
2090
- defineProperty(HTMLBridgeElement, 'observedAttributes', {
2091
- get() {
2092
- return [...superObservedAttributes, ...keys(attributeToPropMap)];
2093
- },
2170
+ // prototype inheritance dance
2171
+ setPrototypeOf(HTMLBridgeElement, SuperClass);
2172
+ setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
2173
+ defineProperty(HTMLBridgeElement.prototype, 'constructor', {
2174
+ writable: true,
2175
+ configurable: true,
2176
+ value: HTMLBridgeElement
2094
2177
  });
2095
- defineProperties(HTMLBridgeElement.prototype, descriptors);
2096
- return HTMLBridgeElement;
2178
+ }
2179
+ // generating the hash table for attributes to avoid duplicate fields and facilitate validation
2180
+ // and false positives in case of inheritance.
2181
+ const attributeToPropMap = create(null);
2182
+ const {
2183
+ attributeChangedCallback: superAttributeChangedCallback
2184
+ } = SuperClass.prototype;
2185
+ const {
2186
+ observedAttributes: superObservedAttributes = []
2187
+ } = SuperClass;
2188
+ const descriptors = create(null);
2189
+ // expose getters and setters for each public props on the new Element Bridge
2190
+ for (let i = 0, len = props.length; i < len; i += 1) {
2191
+ const propName = props[i];
2192
+ attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
2193
+ descriptors[propName] = {
2194
+ get: createGetter(propName),
2195
+ set: createSetter(propName),
2196
+ enumerable: true,
2197
+ configurable: true
2198
+ };
2199
+ }
2200
+ // expose public methods as props on the new Element Bridge
2201
+ for (let i = 0, len = methods.length; i < len; i += 1) {
2202
+ const methodName = methods[i];
2203
+ descriptors[methodName] = {
2204
+ value: createMethodCaller(methodName),
2205
+ writable: true,
2206
+ configurable: true
2207
+ };
2208
+ }
2209
+ // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
2210
+ // map of attributes to props. We do this after all other props and methods to avoid the possibility
2211
+ // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
2212
+ // to preserve this definition.
2213
+ descriptors.attributeChangedCallback = {
2214
+ value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback)
2215
+ };
2216
+ // Specify attributes for which we want to reflect changes back to their corresponding
2217
+ // properties via attributeChangedCallback.
2218
+ defineProperty(HTMLBridgeElement, 'observedAttributes', {
2219
+ get() {
2220
+ return [...superObservedAttributes, ...keys(attributeToPropMap)];
2221
+ }
2222
+ });
2223
+ defineProperties(HTMLBridgeElement.prototype, descriptors);
2224
+ return HTMLBridgeElement;
2097
2225
  }
2098
2226
  const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
2227
+ {
2228
+ // This ARIA reflection only really makes sense in the browser. On the server, there is no `renderedCallback()`,
2229
+ // so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't need to expose
2230
+ // ARIA props outside the LightningElement
2231
+ if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
2232
+ // If ARIA reflection is not applied globally to Element.prototype, apply it to HTMLBridgeElement.prototype.
2233
+ // This allows `elm.aria*` property accessors to work from outside a component, and to reflect `aria-*` attrs.
2234
+ // This is especially important because the template compiler compiles aria-* attrs on components to aria* props
2235
+ //
2236
+ // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
2237
+ // accessors inside the HTMLBridgeElementFactory.
2238
+ applyAriaReflection(BaseBridgeElement.prototype);
2239
+ }
2240
+ }
2099
2241
  freeze(BaseBridgeElement);
2100
2242
  seal(BaseBridgeElement.prototype);
2101
2243
  function setActiveVM(vm) {
@@ -2321,6 +2463,9 @@
2321
2463
  stylesheets: newStylesheets,
2322
2464
  stylesheetToken: newStylesheetToken
2323
2465
  } = template;
2466
+ const {
2467
+ stylesheets: newVmStylesheets
2468
+ } = vm;
2324
2469
  const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
2325
2470
  const {
2326
2471
  hasScopedStyles
@@ -2344,7 +2489,9 @@
2344
2489
  }
2345
2490
  // Apply the new template styling token to the host element, if the new template has any
2346
2491
  // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
2347
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
2492
+ const hasNewStylesheets = hasStyles(newStylesheets);
2493
+ const hasNewVmStylesheets = hasStyles(newVmStylesheets);
2494
+ if (hasNewStylesheets || hasNewVmStylesheets) {
2348
2495
  newToken = newStylesheetToken;
2349
2496
  }
2350
2497
  // Set the new styling token on the host element
@@ -2408,10 +2555,17 @@
2408
2555
  stylesheets,
2409
2556
  stylesheetToken
2410
2557
  } = template;
2558
+ const {
2559
+ stylesheets: vmStylesheets
2560
+ } = vm;
2411
2561
  let content = [];
2412
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
2562
+ if (hasStyles(stylesheets)) {
2413
2563
  content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
2414
2564
  }
2565
+ // VM (component) stylesheets apply after template stylesheets
2566
+ if (hasStyles(vmStylesheets)) {
2567
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
2568
+ }
2415
2569
  return content;
2416
2570
  }
2417
2571
  // It might be worth caching this to avoid doing the lookup repeatedly, but
@@ -2449,10 +2603,13 @@
2449
2603
  const {
2450
2604
  template
2451
2605
  } = getComponentInternalDef(vnode.ctor);
2606
+ const {
2607
+ vm
2608
+ } = vnode;
2452
2609
  const {
2453
2610
  stylesheetToken
2454
2611
  } = template;
2455
- return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
2612
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template, vm) ? makeHostToken(stylesheetToken) : null;
2456
2613
  }
2457
2614
  function getNearestNativeShadowComponent(vm) {
2458
2615
  const owner = getNearestShadowComponent(vm);
@@ -3035,6 +3192,28 @@
3035
3192
  // in fallback mode, the allocation will always set children to
3036
3193
  // empty and delegate the real allocation to the slot elements
3037
3194
  allocateChildren(n2, vm);
3195
+ // Solves an edge case with slotted VFragments in native shadow mode.
3196
+ //
3197
+ // During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
3198
+ // to avoid interfering with native slot behavior. When this happens, if any of the fragments
3199
+ // were not stable, the children must go through the dynamic diffing algo.
3200
+ //
3201
+ // If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
3202
+ // the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
3203
+ // nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
3204
+ // mark the new children dynamic.
3205
+ //
3206
+ // Example:
3207
+ // n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
3208
+ // n2.children: [div, null, div] => [div, null, div] // marked ???
3209
+ const {
3210
+ shadowMode,
3211
+ renderMode
3212
+ } = vm;
3213
+ if (shadowMode == 0 /* ShadowMode.Native */ && renderMode !== 0 /* RenderMode.Light */ && hasDynamicChildren(n1.children)) {
3214
+ // No-op if children has already been marked dynamic by 'allocateChildren()'.
3215
+ markAsDynamicChildren(n2.children);
3216
+ }
3038
3217
  }
3039
3218
  // in fallback mode, the children will be always empty, so, nothing
3040
3219
  // will happen, but in native, it does allocate the light dom
@@ -3196,20 +3375,65 @@
3196
3375
  //
3197
3376
  // In case #2, we will always get a fresh VCustomElement.
3198
3377
  const children = vnode.aChildren || vnode.children;
3199
- vm.aChildren = children;
3200
3378
  const {
3201
3379
  renderMode,
3202
3380
  shadowMode
3203
3381
  } = vm;
3382
+ // If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
3383
+ // children VFragments to avoid them interfering with default slot behavior.
3384
+ const allocatedChildren = flattenFragmentsInChildren(children);
3385
+ vnode.children = allocatedChildren;
3386
+ vm.aChildren = allocatedChildren;
3204
3387
  if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
3205
3388
  // slow path
3206
- allocateInSlot(vm, children, vnode.owner);
3389
+ allocateInSlot(vm, allocatedChildren, vnode.owner);
3207
3390
  // save the allocated children in case this vnode is reused.
3208
- vnode.aChildren = children;
3391
+ vnode.aChildren = allocatedChildren;
3209
3392
  // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
3210
3393
  vnode.children = EmptyArray;
3211
3394
  }
3212
3395
  }
3396
+ /**
3397
+ * Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
3398
+ * marks the resulting children array as dynamic. Uses a stack (array) to iteratively traverse the nested VFragments
3399
+ * and avoid the perf overhead of creating/destroying throwaway arrays/objects in a recursive approach.
3400
+ *
3401
+ * With the delimiters removed, the contents are marked dynamic so they are diffed correctly.
3402
+ *
3403
+ * This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
3404
+ */
3405
+ function flattenFragmentsInChildren(children) {
3406
+ const flattenedChildren = [];
3407
+ // Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
3408
+ // If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
3409
+ const nodeStack = [];
3410
+ let fragmentFound = false;
3411
+ for (let i = children.length - 1; i > -1; i -= 1) {
3412
+ const child = children[i];
3413
+ ArrayPush$1.call(nodeStack, child);
3414
+ fragmentFound = fragmentFound || !!(child && isVFragment(child));
3415
+ }
3416
+ if (!fragmentFound) {
3417
+ return children;
3418
+ }
3419
+ let currentNode;
3420
+ while (!isUndefined$1(currentNode = ArrayPop.call(nodeStack))) {
3421
+ if (!isNull(currentNode) && isVFragment(currentNode)) {
3422
+ const fChildren = currentNode.children;
3423
+ // Ignore the start and end text node delimiters
3424
+ for (let i = fChildren.length - 2; i > 0; i -= 1) {
3425
+ ArrayPush$1.call(nodeStack, fChildren[i]);
3426
+ }
3427
+ } else {
3428
+ ArrayPush$1.call(flattenedChildren, currentNode);
3429
+ }
3430
+ }
3431
+ // We always mark the children as dynamic because nothing generates stable VFragments yet.
3432
+ // If/when stable VFragments are generated by the compiler, this code should be updated to
3433
+ // not mark dynamic if all flattened VFragments were stable.
3434
+ markAsDynamicChildren(flattenedChildren);
3435
+ return flattenedChildren;
3436
+ }
3213
3437
  function createViewModelHook(elm, vnode, renderer) {
3214
3438
  let vm = getAssociatedVMIfPresent(elm);
3215
3439
  // There is a possibility that a custom element is registered under tagName, in which case, the
@@ -3231,22 +3455,20 @@
3231
3455
  });
3232
3456
  return vm;
3233
3457
  }
3234
- /**
3235
- * Collects all slots into a SlotSet, traversing through VFragment Nodes
3236
- */
3237
- function collectSlots(vm, children, cmpSlotsMapping) {
3458
+ function allocateInSlot(vm, children, owner) {
3238
3459
  var _a, _b;
3460
+ const {
3461
+ cmpSlots: {
3462
+ slotAssignments: oldSlotsMapping
3463
+ }
3464
+ } = vm;
3465
+ const cmpSlotsMapping = create(null);
3466
+ // Collect all slots into cmpSlotsMapping
3239
3467
  for (let i = 0, len = children.length; i < len; i += 1) {
3240
3468
  const vnode = children[i];
3241
3469
  if (isNull(vnode)) {
3242
3470
  continue;
3243
3471
  }
3244
- // Dive further iff the content is wrapped in a VFragment
3245
- if (isVFragment(vnode)) {
3246
- // Remove the text delimiter nodes to avoid overriding default slot content
3247
- collectSlots(vm, vnode.children.slice(1, -1), cmpSlotsMapping);
3248
- continue;
3249
- }
3250
3472
  let slotName = '';
3251
3473
  if (isVBaseElement(vnode)) {
3252
3474
  slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
@@ -3256,15 +3478,6 @@
3256
3478
  const vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
3257
3479
  ArrayPush$1.call(vnodes, vnode);
3258
3480
  }
3259
- }
3260
- function allocateInSlot(vm, children, owner) {
3261
- const {
3262
- cmpSlots: {
3263
- slotAssignments: oldSlotsMapping
3264
- }
3265
- } = vm;
3266
- const cmpSlotsMapping = create(null);
3267
- collectSlots(vm, children, cmpSlotsMapping);
3268
3481
  vm.cmpSlots = {
3269
3482
  owner,
3270
3483
  slotAssignments: cmpSlotsMapping
@@ -3295,14 +3508,14 @@
3295
3508
  }
3296
3509
  }
3297
3510
  // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
3298
- const FromIteration = new WeakMap();
3299
- // dynamic children means it was generated by an iteration
3300
- // in a template, and will require a more complex diffing algo.
3511
+ const DynamicChildren = new WeakMap();
3512
+ // dynamic children means it was either generated by an iteration in a template
3513
+ // or part of an unstable fragment, and will require a more complex diffing algo.
3301
3514
  function markAsDynamicChildren(children) {
3302
- FromIteration.set(children, 1);
3515
+ DynamicChildren.set(children, 1);
3303
3516
  }
3304
3517
  function hasDynamicChildren(children) {
3305
- return FromIteration.has(children);
3518
+ return DynamicChildren.has(children);
3306
3519
  }
3307
3520
  function createKeyToOldIdx(children, beginIdx, endIdx) {
3308
3521
  const map = {};
@@ -3961,7 +4174,7 @@
3961
4174
  // Create a brand new template cache for the swapped templated.
3962
4175
  context.tplCache = create(null);
3963
4176
  // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
3964
- context.hasScopedStyles = computeHasScopedStyles(html);
4177
+ context.hasScopedStyles = computeHasScopedStyles(html, vm);
3965
4178
  // Update the scoping token on the host element.
3966
4179
  updateStylesheetToken(vm, html);
3967
4180
  // Evaluate, create stylesheet and cache the produced VNode for future
@@ -3996,9 +4209,8 @@
3996
4209
  });
3997
4210
  return vnodes;
3998
4211
  }
3999
- function computeHasScopedStyles(template) {
4000
- const { stylesheets } = template;
4001
- if (!isUndefined$1(stylesheets)) {
4212
+ function computeHasScopedStylesInStylesheets(stylesheets) {
4213
+ if (hasStyles(stylesheets)) {
4002
4214
  for (let i = 0; i < stylesheets.length; i++) {
4003
4215
  if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
4004
4216
  return true;
@@ -4007,6 +4219,15 @@
4007
4219
  }
4008
4220
  return false;
4009
4221
  }
4222
+ function computeHasScopedStyles(template, vm) {
4223
+ const { stylesheets } = template;
4224
+ const vmStylesheets = !isUndefined$1(vm) ? vm.stylesheets : null;
4225
+ return (computeHasScopedStylesInStylesheets(stylesheets) ||
4226
+ computeHasScopedStylesInStylesheets(vmStylesheets));
4227
+ }
4228
+ function hasStyles(stylesheets) {
4229
+ return !isUndefined$1(stylesheets) && !isNull(stylesheets) && stylesheets.length > 0;
4230
+ }
4010
4231
  let vmBeingConstructed = null;
4011
4232
  function isBeingConstructed(vm) {
4012
4233
  return vmBeingConstructed === vm;
@@ -4283,6 +4504,7 @@
4283
4504
  // Properties set right after VM creation.
4284
4505
  tro: null,
4285
4506
  shadowMode: null,
4507
+ stylesheets: null,
4286
4508
  // Properties set by the LightningElement constructor.
4287
4509
  component: null,
4288
4510
  shadowRoot: null,
@@ -4292,6 +4514,7 @@
4292
4514
  getHook,
4293
4515
  renderer
4294
4516
  };
4517
+ vm.stylesheets = computeStylesheets(vm, def.ctor);
4295
4518
  vm.shadowMode = computeShadowMode(vm, renderer);
4296
4519
  vm.tro = getTemplateReactiveObserver(vm);
4297
4520
  // Create component instance associated to the vm and the element.
@@ -4302,6 +4525,40 @@
4302
4525
  }
4303
4526
  return vm;
4304
4527
  }
4528
+ function validateComponentStylesheets(vm, stylesheets) {
4529
+ let valid = true;
4530
+ const validate = arrayOrStylesheet => {
4531
+ if (isArray$1(arrayOrStylesheet)) {
4532
+ for (let i = 0; i < arrayOrStylesheet.length; i++) {
4533
+ validate(arrayOrStylesheet[i]);
4534
+ }
4535
+ } else if (!isFunction$1(arrayOrStylesheet)) {
4536
+ // function assumed to be a stylesheet factory
4537
+ valid = false;
4538
+ }
4539
+ };
4540
+ if (!isArray$1(stylesheets)) {
4541
+ valid = false;
4542
+ } else {
4543
+ validate(stylesheets);
4544
+ }
4545
+ return valid;
4546
+ }
4547
+ // Validate and flatten any stylesheets defined as `static stylesheets`
4548
+ function computeStylesheets(vm, ctor) {
4549
+ if (lwcRuntimeFlags.ENABLE_PROGRAMMATIC_STYLESHEETS) {
4550
+ const {
4551
+ stylesheets
4552
+ } = ctor;
4553
+ if (!isUndefined$1(stylesheets)) {
4554
+ const valid = validateComponentStylesheets(vm, stylesheets);
4555
+ if (valid) {
4556
+ return flattenStylesheets(stylesheets);
4557
+ }
4558
+ }
4559
+ }
4560
+ return null;
4561
+ }
4305
4562
  function computeShadowMode(vm, renderer) {
4306
4563
  const {
4307
4564
  def
@@ -6257,7 +6514,7 @@
6257
6514
  function isNull(obj) {
6258
6515
  return obj === null;
6259
6516
  }
6260
- /** version: 2.32.1 */
6517
+ /** version: 2.34.0 */
6261
6518
 
6262
6519
  /*
6263
6520
  * Copyright (c) 2018, salesforce.com, inc.
@@ -6810,7 +7067,7 @@
6810
7067
  });
6811
7068
  freeze(LightningElement);
6812
7069
  seal(LightningElement.prototype);
6813
- /* version: 2.32.1 */
7070
+ /* version: 2.34.0 */
6814
7071
 
6815
7072
  exports.LightningElement = LightningElement;
6816
7073
  exports.__unstable__ProfilerControl = profilerControl;