@lwc/engine-core 2.37.0 → 2.37.2
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.
- package/dist/engine-core.cjs.js +2149 -2413
- package/dist/engine-core.js +2149 -2414
- package/package.json +4 -4
- package/types/framework/reporting.d.ts +7 -5
- package/types/index.d.ts +0 -1
- package/types/testFeatureFlag.d.ts +0 -1
package/dist/engine-core.cjs.js
CHANGED
|
@@ -1,31 +1,9 @@
|
|
|
1
1
|
/* proxy-compat-disable */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var features = require('@lwc/features');
|
|
5
4
|
var shared = require('@lwc/shared');
|
|
6
5
|
var ariaReflection = require('@lwc/aria-reflection');
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
10
|
-
* All rights reserved.
|
|
11
|
-
* SPDX-License-Identifier: MIT
|
|
12
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
13
|
-
*/
|
|
14
|
-
// Only used in LWC's Karma tests
|
|
15
|
-
if (process.env.NODE_ENV === 'test-karma-lwc') {
|
|
16
|
-
window.addEventListener('test-dummy-flag', () => {
|
|
17
|
-
let hasFlag = false;
|
|
18
|
-
if (features.lwcRuntimeFlags.DUMMY_TEST_FLAG) {
|
|
19
|
-
hasFlag = true;
|
|
20
|
-
}
|
|
21
|
-
window.dispatchEvent(new CustomEvent('has-dummy-flag', {
|
|
22
|
-
detail: {
|
|
23
|
-
package: '@lwc/engine-core',
|
|
24
|
-
hasFlag
|
|
25
|
-
}
|
|
26
|
-
}));
|
|
27
|
-
});
|
|
28
|
-
}
|
|
6
|
+
var features = require('@lwc/features');
|
|
29
7
|
|
|
30
8
|
/*
|
|
31
9
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -1489,51 +1467,46 @@ function markLockerLiveObject(obj) {
|
|
|
1489
1467
|
* for the Base Lightning Element, it also include the reactivity bit, so the standard property is reactive.
|
|
1490
1468
|
*/
|
|
1491
1469
|
function createBridgeToElementDescriptor(propName, descriptor) {
|
|
1492
|
-
|
|
1493
|
-
get
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
if (!shared.isFunction(get)) {
|
|
1499
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1500
|
-
shared.assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
|
|
1501
|
-
}
|
|
1502
|
-
throw new TypeError();
|
|
1503
|
-
}
|
|
1504
|
-
if (!shared.isFunction(set)) {
|
|
1505
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1506
|
-
shared.assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
|
|
1470
|
+
const { get, set, enumerable, configurable } = descriptor;
|
|
1471
|
+
if (!shared.isFunction(get)) {
|
|
1472
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1473
|
+
shared.assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
|
|
1474
|
+
}
|
|
1475
|
+
throw new TypeError();
|
|
1507
1476
|
}
|
|
1508
|
-
|
|
1509
|
-
}
|
|
1510
|
-
return {
|
|
1511
|
-
enumerable,
|
|
1512
|
-
configurable,
|
|
1513
|
-
get() {
|
|
1514
|
-
const vm = getAssociatedVM(this);
|
|
1515
|
-
if (isBeingConstructed(vm)) {
|
|
1477
|
+
if (!shared.isFunction(set)) {
|
|
1516
1478
|
if (process.env.NODE_ENV !== 'production') {
|
|
1517
|
-
|
|
1479
|
+
shared.assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
|
|
1518
1480
|
}
|
|
1519
|
-
|
|
1520
|
-
}
|
|
1521
|
-
componentValueObserved(vm, propName);
|
|
1522
|
-
return get.call(vm.elm);
|
|
1523
|
-
},
|
|
1524
|
-
set(newValue) {
|
|
1525
|
-
const vm = getAssociatedVM(this);
|
|
1526
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1527
|
-
const vmBeingRendered = getVMBeingRendered();
|
|
1528
|
-
shared.assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
|
|
1529
|
-
shared.assert.invariant(!isUpdatingTemplate, `When updating the template of ${vmBeingRendered}, one of the accessors used by the template has side effects on the state of ${vm}.${propName}`);
|
|
1530
|
-
shared.assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
|
|
1531
|
-
shared.assert.invariant(!shared.isObject(newValue) || shared.isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
|
|
1532
|
-
}
|
|
1533
|
-
updateComponentValue(vm, propName, newValue);
|
|
1534
|
-
return set.call(vm.elm, newValue);
|
|
1481
|
+
throw new TypeError();
|
|
1535
1482
|
}
|
|
1536
|
-
|
|
1483
|
+
return {
|
|
1484
|
+
enumerable,
|
|
1485
|
+
configurable,
|
|
1486
|
+
get() {
|
|
1487
|
+
const vm = getAssociatedVM(this);
|
|
1488
|
+
if (isBeingConstructed(vm)) {
|
|
1489
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1490
|
+
logError(`The value of property \`${propName}\` can't be read from the constructor because the owner component hasn't set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
|
|
1491
|
+
}
|
|
1492
|
+
return;
|
|
1493
|
+
}
|
|
1494
|
+
componentValueObserved(vm, propName);
|
|
1495
|
+
return get.call(vm.elm);
|
|
1496
|
+
},
|
|
1497
|
+
set(newValue) {
|
|
1498
|
+
const vm = getAssociatedVM(this);
|
|
1499
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1500
|
+
const vmBeingRendered = getVMBeingRendered();
|
|
1501
|
+
shared.assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
|
|
1502
|
+
shared.assert.invariant(!isUpdatingTemplate, `When updating the template of ${vmBeingRendered}, one of the accessors used by the template has side effects on the state of ${vm}.${propName}`);
|
|
1503
|
+
shared.assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
|
|
1504
|
+
shared.assert.invariant(!shared.isObject(newValue) || shared.isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
|
|
1505
|
+
}
|
|
1506
|
+
updateComponentValue(vm, propName, newValue);
|
|
1507
|
+
return set.call(vm.elm, newValue);
|
|
1508
|
+
},
|
|
1509
|
+
};
|
|
1537
1510
|
}
|
|
1538
1511
|
const refsCache = new WeakMap();
|
|
1539
1512
|
/**
|
|
@@ -1542,437 +1515,348 @@ const refsCache = new WeakMap();
|
|
|
1542
1515
|
**/
|
|
1543
1516
|
// @ts-ignore
|
|
1544
1517
|
const LightningElement = function () {
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
def
|
|
1554
|
-
elm
|
|
1555
|
-
} = vm;
|
|
1556
|
-
const {
|
|
1557
|
-
bridge
|
|
1558
|
-
} = def;
|
|
1559
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1560
|
-
const {
|
|
1561
|
-
assertInstanceOfHTMLElement
|
|
1562
|
-
} = vm.renderer;
|
|
1563
|
-
assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
|
|
1564
|
-
}
|
|
1565
|
-
const component = this;
|
|
1566
|
-
shared.setPrototypeOf(elm, bridge.prototype);
|
|
1567
|
-
vm.component = this;
|
|
1568
|
-
// Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
|
|
1569
|
-
// component creation and passes hooks to instrument all the component interactions with the
|
|
1570
|
-
// engine. We are intentionally hiding this argument from the formal API of LightningElement
|
|
1571
|
-
// because we don't want folks to know about it just yet.
|
|
1572
|
-
if (arguments.length === 1) {
|
|
1573
|
-
const {
|
|
1574
|
-
callHook,
|
|
1575
|
-
setHook,
|
|
1576
|
-
getHook
|
|
1577
|
-
} = arguments[0];
|
|
1578
|
-
vm.callHook = callHook;
|
|
1579
|
-
vm.setHook = setHook;
|
|
1580
|
-
vm.getHook = getHook;
|
|
1581
|
-
}
|
|
1582
|
-
markLockerLiveObject(this);
|
|
1583
|
-
// Linking elm, shadow root and component with the VM.
|
|
1584
|
-
associateVM(component, vm);
|
|
1585
|
-
associateVM(elm, vm);
|
|
1586
|
-
if (vm.renderMode === 1 /* RenderMode.Shadow */) {
|
|
1587
|
-
vm.renderRoot = doAttachShadow(vm);
|
|
1588
|
-
} else {
|
|
1589
|
-
vm.renderRoot = elm;
|
|
1590
|
-
}
|
|
1591
|
-
// Adding extra guard rails in DEV mode.
|
|
1592
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1593
|
-
patchCustomElementWithRestrictions(elm);
|
|
1594
|
-
patchComponentWithRestrictions(component);
|
|
1595
|
-
}
|
|
1596
|
-
return this;
|
|
1597
|
-
};
|
|
1598
|
-
function doAttachShadow(vm) {
|
|
1599
|
-
const {
|
|
1600
|
-
elm,
|
|
1601
|
-
mode,
|
|
1602
|
-
shadowMode,
|
|
1603
|
-
def: {
|
|
1604
|
-
ctor
|
|
1605
|
-
},
|
|
1606
|
-
renderer: {
|
|
1607
|
-
attachShadow
|
|
1608
|
-
}
|
|
1609
|
-
} = vm;
|
|
1610
|
-
const shadowRoot = attachShadow(elm, {
|
|
1611
|
-
[shared.KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
|
|
1612
|
-
delegatesFocus: Boolean(ctor.delegatesFocus),
|
|
1613
|
-
mode
|
|
1614
|
-
});
|
|
1615
|
-
vm.shadowRoot = shadowRoot;
|
|
1616
|
-
associateVM(shadowRoot, vm);
|
|
1617
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1618
|
-
patchShadowRootWithRestrictions(shadowRoot);
|
|
1619
|
-
}
|
|
1620
|
-
return shadowRoot;
|
|
1621
|
-
}
|
|
1622
|
-
function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
|
|
1623
|
-
if (isBeingConstructed(vm)) {
|
|
1624
|
-
logError(`this.${methodOrPropName} should not be called during the construction of the custom element for ${getComponentTag(vm)} because the element is not yet in the DOM or has no children yet.`);
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
// @ts-ignore
|
|
1628
|
-
LightningElement.prototype = {
|
|
1629
|
-
constructor: LightningElement,
|
|
1630
|
-
dispatchEvent(event) {
|
|
1631
|
-
const vm = getAssociatedVM(this);
|
|
1632
|
-
const {
|
|
1633
|
-
elm,
|
|
1634
|
-
renderer: {
|
|
1635
|
-
dispatchEvent
|
|
1636
|
-
}
|
|
1637
|
-
} = vm;
|
|
1638
|
-
return dispatchEvent(elm, event);
|
|
1639
|
-
},
|
|
1640
|
-
addEventListener(type, listener, options) {
|
|
1641
|
-
const vm = getAssociatedVM(this);
|
|
1642
|
-
const {
|
|
1643
|
-
elm,
|
|
1644
|
-
renderer: {
|
|
1645
|
-
addEventListener
|
|
1646
|
-
}
|
|
1647
|
-
} = vm;
|
|
1648
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1649
|
-
const vmBeingRendered = getVMBeingRendered();
|
|
1650
|
-
shared.assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
|
|
1651
|
-
shared.assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
|
|
1652
|
-
shared.assert.invariant(shared.isFunction(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
|
|
1653
|
-
}
|
|
1654
|
-
const wrappedListener = getWrappedComponentsListener(vm, listener);
|
|
1655
|
-
addEventListener(elm, type, wrappedListener, options);
|
|
1656
|
-
},
|
|
1657
|
-
removeEventListener(type, listener, options) {
|
|
1658
|
-
const vm = getAssociatedVM(this);
|
|
1659
|
-
const {
|
|
1660
|
-
elm,
|
|
1661
|
-
renderer: {
|
|
1662
|
-
removeEventListener
|
|
1663
|
-
}
|
|
1664
|
-
} = vm;
|
|
1665
|
-
const wrappedListener = getWrappedComponentsListener(vm, listener);
|
|
1666
|
-
removeEventListener(elm, type, wrappedListener, options);
|
|
1667
|
-
},
|
|
1668
|
-
hasAttribute(name) {
|
|
1669
|
-
const vm = getAssociatedVM(this);
|
|
1670
|
-
const {
|
|
1671
|
-
elm,
|
|
1672
|
-
renderer: {
|
|
1673
|
-
getAttribute
|
|
1674
|
-
}
|
|
1675
|
-
} = vm;
|
|
1676
|
-
return !shared.isNull(getAttribute(elm, name));
|
|
1677
|
-
},
|
|
1678
|
-
hasAttributeNS(namespace, name) {
|
|
1679
|
-
const vm = getAssociatedVM(this);
|
|
1680
|
-
const {
|
|
1681
|
-
elm,
|
|
1682
|
-
renderer: {
|
|
1683
|
-
getAttribute
|
|
1684
|
-
}
|
|
1685
|
-
} = vm;
|
|
1686
|
-
return !shared.isNull(getAttribute(elm, name, namespace));
|
|
1687
|
-
},
|
|
1688
|
-
removeAttribute(name) {
|
|
1689
|
-
const vm = getAssociatedVM(this);
|
|
1690
|
-
const {
|
|
1691
|
-
elm,
|
|
1692
|
-
renderer: {
|
|
1693
|
-
removeAttribute
|
|
1694
|
-
}
|
|
1695
|
-
} = vm;
|
|
1696
|
-
unlockAttribute(elm, name);
|
|
1697
|
-
removeAttribute(elm, name);
|
|
1698
|
-
lockAttribute();
|
|
1699
|
-
},
|
|
1700
|
-
removeAttributeNS(namespace, name) {
|
|
1701
|
-
const {
|
|
1702
|
-
elm,
|
|
1703
|
-
renderer: {
|
|
1704
|
-
removeAttribute
|
|
1705
|
-
}
|
|
1706
|
-
} = getAssociatedVM(this);
|
|
1707
|
-
unlockAttribute(elm, name);
|
|
1708
|
-
removeAttribute(elm, name, namespace);
|
|
1709
|
-
lockAttribute();
|
|
1710
|
-
},
|
|
1711
|
-
getAttribute(name) {
|
|
1712
|
-
const vm = getAssociatedVM(this);
|
|
1713
|
-
const {
|
|
1714
|
-
elm
|
|
1715
|
-
} = vm;
|
|
1716
|
-
const {
|
|
1717
|
-
getAttribute
|
|
1718
|
-
} = vm.renderer;
|
|
1719
|
-
return getAttribute(elm, name);
|
|
1720
|
-
},
|
|
1721
|
-
getAttributeNS(namespace, name) {
|
|
1722
|
-
const vm = getAssociatedVM(this);
|
|
1723
|
-
const {
|
|
1724
|
-
elm
|
|
1725
|
-
} = vm;
|
|
1726
|
-
const {
|
|
1727
|
-
getAttribute
|
|
1728
|
-
} = vm.renderer;
|
|
1729
|
-
return getAttribute(elm, name, namespace);
|
|
1730
|
-
},
|
|
1731
|
-
setAttribute(name, value) {
|
|
1732
|
-
const vm = getAssociatedVM(this);
|
|
1733
|
-
const {
|
|
1734
|
-
elm,
|
|
1735
|
-
renderer: {
|
|
1736
|
-
setAttribute
|
|
1737
|
-
}
|
|
1738
|
-
} = vm;
|
|
1739
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1740
|
-
shared.assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
|
|
1741
|
-
}
|
|
1742
|
-
unlockAttribute(elm, name);
|
|
1743
|
-
setAttribute(elm, name, value);
|
|
1744
|
-
lockAttribute();
|
|
1745
|
-
},
|
|
1746
|
-
setAttributeNS(namespace, name, value) {
|
|
1747
|
-
const vm = getAssociatedVM(this);
|
|
1748
|
-
const {
|
|
1749
|
-
elm,
|
|
1750
|
-
renderer: {
|
|
1751
|
-
setAttribute
|
|
1752
|
-
}
|
|
1753
|
-
} = vm;
|
|
1754
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1755
|
-
shared.assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
|
|
1756
|
-
}
|
|
1757
|
-
unlockAttribute(elm, name);
|
|
1758
|
-
setAttribute(elm, name, value, namespace);
|
|
1759
|
-
lockAttribute();
|
|
1760
|
-
},
|
|
1761
|
-
getBoundingClientRect() {
|
|
1762
|
-
const vm = getAssociatedVM(this);
|
|
1763
|
-
const {
|
|
1764
|
-
elm,
|
|
1765
|
-
renderer: {
|
|
1766
|
-
getBoundingClientRect
|
|
1767
|
-
}
|
|
1768
|
-
} = vm;
|
|
1769
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1770
|
-
warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
|
|
1771
|
-
}
|
|
1772
|
-
return getBoundingClientRect(elm);
|
|
1773
|
-
},
|
|
1774
|
-
get isConnected() {
|
|
1775
|
-
const vm = getAssociatedVM(this);
|
|
1776
|
-
const {
|
|
1777
|
-
elm,
|
|
1778
|
-
renderer: {
|
|
1779
|
-
isConnected
|
|
1780
|
-
}
|
|
1781
|
-
} = vm;
|
|
1782
|
-
return isConnected(elm);
|
|
1783
|
-
},
|
|
1784
|
-
get classList() {
|
|
1785
|
-
const vm = getAssociatedVM(this);
|
|
1786
|
-
const {
|
|
1787
|
-
elm,
|
|
1788
|
-
renderer: {
|
|
1789
|
-
getClassList
|
|
1790
|
-
}
|
|
1791
|
-
} = vm;
|
|
1792
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1793
|
-
// TODO [#1290]: this still fails in dev but works in production, eventually, we should
|
|
1794
|
-
// just throw in all modes
|
|
1795
|
-
shared.assert.isFalse(isBeingConstructed(vm), `Failed to construct ${vm}: The result must not have attributes. Adding or tampering with classname in constructor is not allowed in a web component, use connectedCallback() instead.`);
|
|
1796
|
-
}
|
|
1797
|
-
return getClassList(elm);
|
|
1798
|
-
},
|
|
1799
|
-
get template() {
|
|
1800
|
-
const vm = getAssociatedVM(this);
|
|
1801
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1802
|
-
if (vm.renderMode === 0 /* RenderMode.Light */) {
|
|
1803
|
-
logError('`this.template` returns null for light DOM components. Since there is no shadow, the rendered content can be accessed via `this` itself. e.g. instead of `this.template.querySelector`, use `this.querySelector`.');
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1806
|
-
return vm.shadowRoot;
|
|
1807
|
-
},
|
|
1808
|
-
get refs() {
|
|
1809
|
-
const vm = getAssociatedVM(this);
|
|
1810
|
-
if (isUpdatingTemplate) {
|
|
1811
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1812
|
-
logError(`this.refs should not be called while ${getComponentTag(vm)} is rendering. Use this.refs only when the DOM is stable, e.g. in renderedCallback().`);
|
|
1813
|
-
}
|
|
1814
|
-
// If the template is in the process of being updated, then we don't want to go through the normal
|
|
1815
|
-
// process of returning the refs and caching them, because the state of the refs is unstable.
|
|
1816
|
-
// This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
|
|
1817
|
-
// based on `this.refs.bar`.
|
|
1818
|
-
return;
|
|
1819
|
-
}
|
|
1518
|
+
// This should be as performant as possible, while any initialization should be done lazily
|
|
1519
|
+
if (shared.isNull(vmBeingConstructed)) {
|
|
1520
|
+
// Thrown when doing something like `new LightningElement()` or
|
|
1521
|
+
// `class Foo extends LightningElement {}; new Foo()`
|
|
1522
|
+
throw new TypeError('Illegal constructor');
|
|
1523
|
+
}
|
|
1524
|
+
const vm = vmBeingConstructed;
|
|
1525
|
+
const { def, elm } = vm;
|
|
1526
|
+
const { bridge } = def;
|
|
1820
1527
|
if (process.env.NODE_ENV !== 'production') {
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
//
|
|
1828
|
-
//
|
|
1829
|
-
//
|
|
1830
|
-
//
|
|
1831
|
-
if (
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
//
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
// are recreated from scratch every time the template is rendered.
|
|
1844
|
-
// This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
|
|
1845
|
-
let refs = refsCache.get(refVNodes);
|
|
1846
|
-
if (shared.isUndefined(refs)) {
|
|
1847
|
-
refs = shared.create(null);
|
|
1848
|
-
for (const key of shared.keys(refVNodes)) {
|
|
1849
|
-
refs[key] = refVNodes[key].elm;
|
|
1850
|
-
}
|
|
1851
|
-
shared.freeze(refs);
|
|
1852
|
-
refsCache.set(refVNodes, refs);
|
|
1853
|
-
}
|
|
1854
|
-
return refs;
|
|
1855
|
-
},
|
|
1856
|
-
// For backwards compat, we allow component authors to set `refs` as an expando
|
|
1857
|
-
set refs(value) {
|
|
1858
|
-
shared.defineProperty(this, 'refs', {
|
|
1859
|
-
configurable: true,
|
|
1860
|
-
enumerable: true,
|
|
1861
|
-
writable: true,
|
|
1862
|
-
value
|
|
1863
|
-
});
|
|
1864
|
-
},
|
|
1865
|
-
get shadowRoot() {
|
|
1866
|
-
// From within the component instance, the shadowRoot is always reported as "closed".
|
|
1867
|
-
// Authors should rely on this.template instead.
|
|
1868
|
-
return null;
|
|
1869
|
-
},
|
|
1870
|
-
get children() {
|
|
1871
|
-
const vm = getAssociatedVM(this);
|
|
1872
|
-
const renderer = vm.renderer;
|
|
1873
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1874
|
-
warnIfInvokedDuringConstruction(vm, 'children');
|
|
1528
|
+
const { assertInstanceOfHTMLElement } = vm.renderer;
|
|
1529
|
+
assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
|
|
1530
|
+
}
|
|
1531
|
+
const component = this;
|
|
1532
|
+
shared.setPrototypeOf(elm, bridge.prototype);
|
|
1533
|
+
vm.component = this;
|
|
1534
|
+
// Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
|
|
1535
|
+
// component creation and passes hooks to instrument all the component interactions with the
|
|
1536
|
+
// engine. We are intentionally hiding this argument from the formal API of LightningElement
|
|
1537
|
+
// because we don't want folks to know about it just yet.
|
|
1538
|
+
if (arguments.length === 1) {
|
|
1539
|
+
const { callHook, setHook, getHook } = arguments[0];
|
|
1540
|
+
vm.callHook = callHook;
|
|
1541
|
+
vm.setHook = setHook;
|
|
1542
|
+
vm.getHook = getHook;
|
|
1543
|
+
}
|
|
1544
|
+
markLockerLiveObject(this);
|
|
1545
|
+
// Linking elm, shadow root and component with the VM.
|
|
1546
|
+
associateVM(component, vm);
|
|
1547
|
+
associateVM(elm, vm);
|
|
1548
|
+
if (vm.renderMode === 1 /* RenderMode.Shadow */) {
|
|
1549
|
+
vm.renderRoot = doAttachShadow(vm);
|
|
1875
1550
|
}
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
get childNodes() {
|
|
1879
|
-
const vm = getAssociatedVM(this);
|
|
1880
|
-
const renderer = vm.renderer;
|
|
1881
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1882
|
-
warnIfInvokedDuringConstruction(vm, 'childNodes');
|
|
1551
|
+
else {
|
|
1552
|
+
vm.renderRoot = elm;
|
|
1883
1553
|
}
|
|
1884
|
-
|
|
1885
|
-
},
|
|
1886
|
-
get firstChild() {
|
|
1887
|
-
const vm = getAssociatedVM(this);
|
|
1888
|
-
const renderer = vm.renderer;
|
|
1554
|
+
// Adding extra guard rails in DEV mode.
|
|
1889
1555
|
if (process.env.NODE_ENV !== 'production') {
|
|
1890
|
-
|
|
1556
|
+
patchCustomElementWithRestrictions(elm);
|
|
1557
|
+
patchComponentWithRestrictions(component);
|
|
1891
1558
|
}
|
|
1892
|
-
return
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
const
|
|
1896
|
-
const
|
|
1559
|
+
return this;
|
|
1560
|
+
};
|
|
1561
|
+
function doAttachShadow(vm) {
|
|
1562
|
+
const { elm, mode, shadowMode, def: { ctor }, renderer: { attachShadow }, } = vm;
|
|
1563
|
+
const shadowRoot = attachShadow(elm, {
|
|
1564
|
+
[shared.KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
|
|
1565
|
+
delegatesFocus: Boolean(ctor.delegatesFocus),
|
|
1566
|
+
mode,
|
|
1567
|
+
});
|
|
1568
|
+
vm.shadowRoot = shadowRoot;
|
|
1569
|
+
associateVM(shadowRoot, vm);
|
|
1897
1570
|
if (process.env.NODE_ENV !== 'production') {
|
|
1898
|
-
|
|
1571
|
+
patchShadowRootWithRestrictions(shadowRoot);
|
|
1899
1572
|
}
|
|
1900
|
-
return
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1906
|
-
warnIfInvokedDuringConstruction(vm, 'lastChild');
|
|
1573
|
+
return shadowRoot;
|
|
1574
|
+
}
|
|
1575
|
+
function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
|
|
1576
|
+
if (isBeingConstructed(vm)) {
|
|
1577
|
+
logError(`this.${methodOrPropName} should not be called during the construction of the custom element for ${getComponentTag(vm)} because the element is not yet in the DOM or has no children yet.`);
|
|
1907
1578
|
}
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1579
|
+
}
|
|
1580
|
+
// @ts-ignore
|
|
1581
|
+
LightningElement.prototype = {
|
|
1582
|
+
constructor: LightningElement,
|
|
1583
|
+
dispatchEvent(event) {
|
|
1584
|
+
const vm = getAssociatedVM(this);
|
|
1585
|
+
const { elm, renderer: { dispatchEvent }, } = vm;
|
|
1586
|
+
return dispatchEvent(elm, event);
|
|
1587
|
+
},
|
|
1588
|
+
addEventListener(type, listener, options) {
|
|
1589
|
+
const vm = getAssociatedVM(this);
|
|
1590
|
+
const { elm, renderer: { addEventListener }, } = vm;
|
|
1591
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1592
|
+
const vmBeingRendered = getVMBeingRendered();
|
|
1593
|
+
shared.assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
|
|
1594
|
+
shared.assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
|
|
1595
|
+
shared.assert.invariant(shared.isFunction(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
|
|
1596
|
+
}
|
|
1597
|
+
const wrappedListener = getWrappedComponentsListener(vm, listener);
|
|
1598
|
+
addEventListener(elm, type, wrappedListener, options);
|
|
1599
|
+
},
|
|
1600
|
+
removeEventListener(type, listener, options) {
|
|
1601
|
+
const vm = getAssociatedVM(this);
|
|
1602
|
+
const { elm, renderer: { removeEventListener }, } = vm;
|
|
1603
|
+
const wrappedListener = getWrappedComponentsListener(vm, listener);
|
|
1604
|
+
removeEventListener(elm, type, wrappedListener, options);
|
|
1605
|
+
},
|
|
1606
|
+
hasAttribute(name) {
|
|
1607
|
+
const vm = getAssociatedVM(this);
|
|
1608
|
+
const { elm, renderer: { getAttribute }, } = vm;
|
|
1609
|
+
return !shared.isNull(getAttribute(elm, name));
|
|
1610
|
+
},
|
|
1611
|
+
hasAttributeNS(namespace, name) {
|
|
1612
|
+
const vm = getAssociatedVM(this);
|
|
1613
|
+
const { elm, renderer: { getAttribute }, } = vm;
|
|
1614
|
+
return !shared.isNull(getAttribute(elm, name, namespace));
|
|
1615
|
+
},
|
|
1616
|
+
removeAttribute(name) {
|
|
1617
|
+
const vm = getAssociatedVM(this);
|
|
1618
|
+
const { elm, renderer: { removeAttribute }, } = vm;
|
|
1619
|
+
unlockAttribute(elm, name);
|
|
1620
|
+
removeAttribute(elm, name);
|
|
1621
|
+
lockAttribute();
|
|
1622
|
+
},
|
|
1623
|
+
removeAttributeNS(namespace, name) {
|
|
1624
|
+
const { elm, renderer: { removeAttribute }, } = getAssociatedVM(this);
|
|
1625
|
+
unlockAttribute(elm, name);
|
|
1626
|
+
removeAttribute(elm, name, namespace);
|
|
1627
|
+
lockAttribute();
|
|
1628
|
+
},
|
|
1629
|
+
getAttribute(name) {
|
|
1630
|
+
const vm = getAssociatedVM(this);
|
|
1631
|
+
const { elm } = vm;
|
|
1632
|
+
const { getAttribute } = vm.renderer;
|
|
1633
|
+
return getAttribute(elm, name);
|
|
1634
|
+
},
|
|
1635
|
+
getAttributeNS(namespace, name) {
|
|
1636
|
+
const vm = getAssociatedVM(this);
|
|
1637
|
+
const { elm } = vm;
|
|
1638
|
+
const { getAttribute } = vm.renderer;
|
|
1639
|
+
return getAttribute(elm, name, namespace);
|
|
1640
|
+
},
|
|
1641
|
+
setAttribute(name, value) {
|
|
1642
|
+
const vm = getAssociatedVM(this);
|
|
1643
|
+
const { elm, renderer: { setAttribute }, } = vm;
|
|
1644
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1645
|
+
shared.assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
|
|
1646
|
+
}
|
|
1647
|
+
unlockAttribute(elm, name);
|
|
1648
|
+
setAttribute(elm, name, value);
|
|
1649
|
+
lockAttribute();
|
|
1650
|
+
},
|
|
1651
|
+
setAttributeNS(namespace, name, value) {
|
|
1652
|
+
const vm = getAssociatedVM(this);
|
|
1653
|
+
const { elm, renderer: { setAttribute }, } = vm;
|
|
1654
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1655
|
+
shared.assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
|
|
1656
|
+
}
|
|
1657
|
+
unlockAttribute(elm, name);
|
|
1658
|
+
setAttribute(elm, name, value, namespace);
|
|
1659
|
+
lockAttribute();
|
|
1660
|
+
},
|
|
1661
|
+
getBoundingClientRect() {
|
|
1662
|
+
const vm = getAssociatedVM(this);
|
|
1663
|
+
const { elm, renderer: { getBoundingClientRect }, } = vm;
|
|
1664
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1665
|
+
warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
|
|
1666
|
+
}
|
|
1667
|
+
return getBoundingClientRect(elm);
|
|
1668
|
+
},
|
|
1669
|
+
get isConnected() {
|
|
1670
|
+
const vm = getAssociatedVM(this);
|
|
1671
|
+
const { elm, renderer: { isConnected }, } = vm;
|
|
1672
|
+
return isConnected(elm);
|
|
1673
|
+
},
|
|
1674
|
+
get classList() {
|
|
1675
|
+
const vm = getAssociatedVM(this);
|
|
1676
|
+
const { elm, renderer: { getClassList }, } = vm;
|
|
1677
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1678
|
+
// TODO [#1290]: this still fails in dev but works in production, eventually, we should
|
|
1679
|
+
// just throw in all modes
|
|
1680
|
+
shared.assert.isFalse(isBeingConstructed(vm), `Failed to construct ${vm}: The result must not have attributes. Adding or tampering with classname in constructor is not allowed in a web component, use connectedCallback() instead.`);
|
|
1681
|
+
}
|
|
1682
|
+
return getClassList(elm);
|
|
1683
|
+
},
|
|
1684
|
+
get template() {
|
|
1685
|
+
const vm = getAssociatedVM(this);
|
|
1686
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1687
|
+
if (vm.renderMode === 0 /* RenderMode.Light */) {
|
|
1688
|
+
logError('`this.template` returns null for light DOM components. Since there is no shadow, the rendered content can be accessed via `this` itself. e.g. instead of `this.template.querySelector`, use `this.querySelector`.');
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
return vm.shadowRoot;
|
|
1692
|
+
},
|
|
1693
|
+
get refs() {
|
|
1694
|
+
const vm = getAssociatedVM(this);
|
|
1695
|
+
if (isUpdatingTemplate) {
|
|
1696
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1697
|
+
logError(`this.refs should not be called while ${getComponentTag(vm)} is rendering. Use this.refs only when the DOM is stable, e.g. in renderedCallback().`);
|
|
1698
|
+
}
|
|
1699
|
+
// If the template is in the process of being updated, then we don't want to go through the normal
|
|
1700
|
+
// process of returning the refs and caching them, because the state of the refs is unstable.
|
|
1701
|
+
// This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
|
|
1702
|
+
// based on `this.refs.bar`.
|
|
1703
|
+
return;
|
|
1704
|
+
}
|
|
1705
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1706
|
+
warnIfInvokedDuringConstruction(vm, 'refs');
|
|
1707
|
+
}
|
|
1708
|
+
const { refVNodes, cmpTemplate } = vm;
|
|
1709
|
+
// If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
|
|
1710
|
+
// if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
|
|
1711
|
+
// so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
|
|
1712
|
+
// `warnIfInvokedDuringConstruction` above).
|
|
1713
|
+
if (process.env.NODE_ENV !== 'production' &&
|
|
1714
|
+
shared.isNull(cmpTemplate) &&
|
|
1715
|
+
!isBeingConstructed(vm)) {
|
|
1716
|
+
logError(`this.refs is undefined for ${getComponentTag(vm)}. This is either because the attached template has no "lwc:ref" directive, or this.refs was ` +
|
|
1717
|
+
`invoked before renderedCallback(). Use this.refs only when the referenced HTML elements have ` +
|
|
1718
|
+
`been rendered to the DOM, such as within renderedCallback() or disconnectedCallback().`);
|
|
1719
|
+
}
|
|
1720
|
+
// For backwards compatibility with component written before template refs
|
|
1721
|
+
// were introduced, we return undefined if the template has no refs defined
|
|
1722
|
+
// anywhere. This fixes components that may want to add an expando called `refs`
|
|
1723
|
+
// and are checking if it exists with `if (this.refs)` before adding it.
|
|
1724
|
+
// Note we use a null refVNodes to indicate that the template has no refs defined.
|
|
1725
|
+
if (shared.isNull(refVNodes)) {
|
|
1726
|
+
return;
|
|
1727
|
+
}
|
|
1728
|
+
// The refNodes can be cached based on the refVNodes, since the refVNodes
|
|
1729
|
+
// are recreated from scratch every time the template is rendered.
|
|
1730
|
+
// This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
|
|
1731
|
+
let refs = refsCache.get(refVNodes);
|
|
1732
|
+
if (shared.isUndefined(refs)) {
|
|
1733
|
+
refs = shared.create(null);
|
|
1734
|
+
for (const key of shared.keys(refVNodes)) {
|
|
1735
|
+
refs[key] = refVNodes[key].elm;
|
|
1736
|
+
}
|
|
1737
|
+
shared.freeze(refs);
|
|
1738
|
+
refsCache.set(refVNodes, refs);
|
|
1739
|
+
}
|
|
1740
|
+
return refs;
|
|
1741
|
+
},
|
|
1742
|
+
// For backwards compat, we allow component authors to set `refs` as an expando
|
|
1743
|
+
set refs(value) {
|
|
1744
|
+
shared.defineProperty(this, 'refs', {
|
|
1745
|
+
configurable: true,
|
|
1746
|
+
enumerable: true,
|
|
1747
|
+
writable: true,
|
|
1748
|
+
value,
|
|
1749
|
+
});
|
|
1750
|
+
},
|
|
1751
|
+
get shadowRoot() {
|
|
1752
|
+
// From within the component instance, the shadowRoot is always reported as "closed".
|
|
1753
|
+
// Authors should rely on this.template instead.
|
|
1754
|
+
return null;
|
|
1755
|
+
},
|
|
1756
|
+
get children() {
|
|
1757
|
+
const vm = getAssociatedVM(this);
|
|
1758
|
+
const renderer = vm.renderer;
|
|
1759
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1760
|
+
warnIfInvokedDuringConstruction(vm, 'children');
|
|
1761
|
+
}
|
|
1762
|
+
return renderer.getChildren(vm.elm);
|
|
1763
|
+
},
|
|
1764
|
+
get childNodes() {
|
|
1765
|
+
const vm = getAssociatedVM(this);
|
|
1766
|
+
const renderer = vm.renderer;
|
|
1767
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1768
|
+
warnIfInvokedDuringConstruction(vm, 'childNodes');
|
|
1769
|
+
}
|
|
1770
|
+
return renderer.getChildNodes(vm.elm);
|
|
1771
|
+
},
|
|
1772
|
+
get firstChild() {
|
|
1773
|
+
const vm = getAssociatedVM(this);
|
|
1774
|
+
const renderer = vm.renderer;
|
|
1775
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1776
|
+
warnIfInvokedDuringConstruction(vm, 'firstChild');
|
|
1777
|
+
}
|
|
1778
|
+
return renderer.getFirstChild(vm.elm);
|
|
1779
|
+
},
|
|
1780
|
+
get firstElementChild() {
|
|
1781
|
+
const vm = getAssociatedVM(this);
|
|
1782
|
+
const renderer = vm.renderer;
|
|
1783
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1784
|
+
warnIfInvokedDuringConstruction(vm, 'firstElementChild');
|
|
1785
|
+
}
|
|
1786
|
+
return renderer.getFirstElementChild(vm.elm);
|
|
1787
|
+
},
|
|
1788
|
+
get lastChild() {
|
|
1789
|
+
const vm = getAssociatedVM(this);
|
|
1790
|
+
const renderer = vm.renderer;
|
|
1791
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1792
|
+
warnIfInvokedDuringConstruction(vm, 'lastChild');
|
|
1793
|
+
}
|
|
1794
|
+
return renderer.getLastChild(vm.elm);
|
|
1795
|
+
},
|
|
1796
|
+
get lastElementChild() {
|
|
1797
|
+
const vm = getAssociatedVM(this);
|
|
1798
|
+
const renderer = vm.renderer;
|
|
1799
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1800
|
+
warnIfInvokedDuringConstruction(vm, 'lastElementChild');
|
|
1801
|
+
}
|
|
1802
|
+
return renderer.getLastElementChild(vm.elm);
|
|
1803
|
+
},
|
|
1804
|
+
render() {
|
|
1805
|
+
const vm = getAssociatedVM(this);
|
|
1806
|
+
return vm.def.template;
|
|
1807
|
+
},
|
|
1808
|
+
toString() {
|
|
1809
|
+
const vm = getAssociatedVM(this);
|
|
1810
|
+
return `[object ${vm.def.name}]`;
|
|
1811
|
+
},
|
|
1926
1812
|
};
|
|
1927
1813
|
const queryAndChildGetterDescriptors = shared.create(null);
|
|
1928
|
-
const queryMethods = [
|
|
1814
|
+
const queryMethods = [
|
|
1815
|
+
'getElementsByClassName',
|
|
1816
|
+
'getElementsByTagName',
|
|
1817
|
+
'querySelector',
|
|
1818
|
+
'querySelectorAll',
|
|
1819
|
+
];
|
|
1929
1820
|
// Generic passthrough for query APIs on HTMLElement to the relevant Renderer APIs
|
|
1930
1821
|
for (const queryMethod of queryMethods) {
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
enumerable: true,
|
|
1945
|
-
writable: true
|
|
1946
|
-
};
|
|
1822
|
+
queryAndChildGetterDescriptors[queryMethod] = {
|
|
1823
|
+
value(arg) {
|
|
1824
|
+
const vm = getAssociatedVM(this);
|
|
1825
|
+
const { elm, renderer } = vm;
|
|
1826
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1827
|
+
warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
|
|
1828
|
+
}
|
|
1829
|
+
return renderer[queryMethod](elm, arg);
|
|
1830
|
+
},
|
|
1831
|
+
configurable: true,
|
|
1832
|
+
enumerable: true,
|
|
1833
|
+
writable: true,
|
|
1834
|
+
};
|
|
1947
1835
|
}
|
|
1948
1836
|
shared.defineProperties(LightningElement.prototype, queryAndChildGetterDescriptors);
|
|
1949
1837
|
const lightningBasedDescriptors = shared.create(null);
|
|
1950
1838
|
for (const propName in HTMLElementOriginalDescriptors) {
|
|
1951
|
-
|
|
1839
|
+
lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
|
|
1952
1840
|
}
|
|
1953
1841
|
shared.defineProperties(LightningElement.prototype, lightningBasedDescriptors);
|
|
1954
1842
|
function applyAriaReflectionToLightningElement() {
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
}
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
if (features.lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
|
|
1963
|
-
applyAriaReflectionToLightningElement();
|
|
1964
|
-
} else if (!process.env.IS_BROWSER) {
|
|
1965
|
-
applyAriaReflectionToLightningElement();
|
|
1843
|
+
// If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
|
|
1844
|
+
// apply it to LightningElement.prototype.
|
|
1845
|
+
// This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
|
|
1846
|
+
ariaReflection.applyAriaReflection(LightningElement.prototype);
|
|
1847
|
+
}
|
|
1848
|
+
if (!process.env.IS_BROWSER || lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
|
|
1849
|
+
applyAriaReflectionToLightningElement();
|
|
1966
1850
|
}
|
|
1967
1851
|
shared.defineProperty(LightningElement, 'CustomElementConstructor', {
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1852
|
+
get() {
|
|
1853
|
+
// If required, a runtime-specific implementation must be defined.
|
|
1854
|
+
throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
|
|
1855
|
+
},
|
|
1856
|
+
configurable: true,
|
|
1973
1857
|
});
|
|
1974
1858
|
if (process.env.NODE_ENV !== 'production') {
|
|
1975
|
-
|
|
1859
|
+
patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
|
|
1976
1860
|
}
|
|
1977
1861
|
|
|
1978
1862
|
function createObservedFieldPropertyDescriptor(key) {
|
|
@@ -2002,281 +1886,247 @@ const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
|
|
|
2002
1886
|
const WIRE_DEBUG_ENTRY = '@wire';
|
|
2003
1887
|
const WireMetaMap = new Map();
|
|
2004
1888
|
class WireContextRegistrationEvent extends CustomEvent {
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
}
|
|
2020
|
-
});
|
|
2021
|
-
}
|
|
1889
|
+
constructor(adapterToken, { setNewContext, setDisconnectedCallback }) {
|
|
1890
|
+
super(adapterToken, {
|
|
1891
|
+
bubbles: true,
|
|
1892
|
+
composed: true,
|
|
1893
|
+
});
|
|
1894
|
+
shared.defineProperties(this, {
|
|
1895
|
+
setNewContext: {
|
|
1896
|
+
value: setNewContext,
|
|
1897
|
+
},
|
|
1898
|
+
setDisconnectedCallback: {
|
|
1899
|
+
value: setDisconnectedCallback,
|
|
1900
|
+
},
|
|
1901
|
+
});
|
|
1902
|
+
}
|
|
2022
1903
|
}
|
|
2023
1904
|
function createFieldDataCallback(vm, name) {
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
1905
|
+
return (value) => {
|
|
1906
|
+
updateComponentValue(vm, name, value);
|
|
1907
|
+
};
|
|
2027
1908
|
}
|
|
2028
1909
|
function createMethodDataCallback(vm, method) {
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
1910
|
+
return (value) => {
|
|
1911
|
+
// dispatching new value into the wired method
|
|
1912
|
+
runWithBoundaryProtection(vm, vm.owner, shared.noop, () => {
|
|
1913
|
+
// job
|
|
1914
|
+
method.call(vm.component, value);
|
|
1915
|
+
}, shared.noop);
|
|
1916
|
+
};
|
|
2036
1917
|
}
|
|
2037
1918
|
function createConfigWatcher(component, configCallback, callbackWhenConfigIsReady) {
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
1919
|
+
let hasPendingConfig = false;
|
|
1920
|
+
// creating the reactive observer for reactive params when needed
|
|
1921
|
+
const ro = createReactiveObserver(() => {
|
|
1922
|
+
if (hasPendingConfig === false) {
|
|
1923
|
+
hasPendingConfig = true;
|
|
1924
|
+
// collect new config in the micro-task
|
|
1925
|
+
Promise.resolve().then(() => {
|
|
1926
|
+
hasPendingConfig = false;
|
|
1927
|
+
// resetting current reactive params
|
|
1928
|
+
ro.reset();
|
|
1929
|
+
// dispatching a new config due to a change in the configuration
|
|
1930
|
+
computeConfigAndUpdate();
|
|
1931
|
+
});
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
const computeConfigAndUpdate = () => {
|
|
1935
|
+
let config;
|
|
1936
|
+
ro.observe(() => (config = configCallback(component)));
|
|
1937
|
+
// eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
|
|
1938
|
+
// TODO: dev-mode validation of config based on the adapter.configSchema
|
|
1939
|
+
// @ts-ignore it is assigned in the observe() callback
|
|
1940
|
+
callbackWhenConfigIsReady(config);
|
|
1941
|
+
};
|
|
1942
|
+
return {
|
|
1943
|
+
computeConfigAndUpdate,
|
|
1944
|
+
ro,
|
|
1945
|
+
};
|
|
2065
1946
|
}
|
|
2066
1947
|
function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
|
|
2067
|
-
|
|
2068
|
-
adapter
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
setNewContext(newContext) {
|
|
2094
|
-
// eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
|
|
2095
|
-
// TODO: dev-mode validation of config based on the adapter.contextSchema
|
|
2096
|
-
callbackWhenContextIsReady(newContext);
|
|
2097
|
-
},
|
|
2098
|
-
setDisconnectedCallback(disconnectCallback) {
|
|
2099
|
-
// adds this callback into the disconnect bucket so it gets disconnected from parent
|
|
2100
|
-
// the the element hosting the wire is disconnected
|
|
2101
|
-
shared.ArrayPush.call(wiredDisconnecting, disconnectCallback);
|
|
2102
|
-
}
|
|
1948
|
+
const { adapter } = wireDef;
|
|
1949
|
+
const adapterContextToken = getAdapterToken(adapter);
|
|
1950
|
+
if (shared.isUndefined(adapterContextToken)) {
|
|
1951
|
+
return; // no provider found, nothing to be done
|
|
1952
|
+
}
|
|
1953
|
+
const { elm, context: { wiredConnecting, wiredDisconnecting }, renderer: { dispatchEvent }, } = vm;
|
|
1954
|
+
// waiting for the component to be connected to formally request the context via the token
|
|
1955
|
+
shared.ArrayPush.call(wiredConnecting, () => {
|
|
1956
|
+
// This event is responsible for connecting the host element with another
|
|
1957
|
+
// element in the composed path that is providing contextual data. The provider
|
|
1958
|
+
// must be listening for a special dom event with the name corresponding to the value of
|
|
1959
|
+
// `adapterContextToken`, which will remain secret and internal to this file only to
|
|
1960
|
+
// guarantee that the linkage can be forged.
|
|
1961
|
+
const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
|
|
1962
|
+
setNewContext(newContext) {
|
|
1963
|
+
// eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
|
|
1964
|
+
// TODO: dev-mode validation of config based on the adapter.contextSchema
|
|
1965
|
+
callbackWhenContextIsReady(newContext);
|
|
1966
|
+
},
|
|
1967
|
+
setDisconnectedCallback(disconnectCallback) {
|
|
1968
|
+
// adds this callback into the disconnect bucket so it gets disconnected from parent
|
|
1969
|
+
// the the element hosting the wire is disconnected
|
|
1970
|
+
shared.ArrayPush.call(wiredDisconnecting, disconnectCallback);
|
|
1971
|
+
},
|
|
1972
|
+
});
|
|
1973
|
+
dispatchEvent(elm, contextRegistrationEvent);
|
|
2103
1974
|
});
|
|
2104
|
-
dispatchEvent(elm, contextRegistrationEvent);
|
|
2105
|
-
});
|
|
2106
1975
|
}
|
|
2107
1976
|
function createConnector(vm, name, wireDef) {
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
adapter,
|
|
2111
|
-
configCallback,
|
|
2112
|
-
dynamic
|
|
2113
|
-
} = wireDef;
|
|
2114
|
-
let debugInfo;
|
|
2115
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2116
|
-
const wiredPropOrMethod = shared.isUndefined(method) ? name : method.name;
|
|
2117
|
-
debugInfo = shared.create(null);
|
|
2118
|
-
debugInfo.wasDataProvisionedForConfig = false;
|
|
2119
|
-
vm.debugInfo[WIRE_DEBUG_ENTRY][wiredPropOrMethod] = debugInfo;
|
|
2120
|
-
}
|
|
2121
|
-
const fieldOrMethodCallback = shared.isUndefined(method) ? createFieldDataCallback(vm, name) : createMethodDataCallback(vm, method);
|
|
2122
|
-
const dataCallback = value => {
|
|
1977
|
+
const { method, adapter, configCallback, dynamic } = wireDef;
|
|
1978
|
+
let debugInfo;
|
|
2123
1979
|
if (process.env.NODE_ENV !== 'production') {
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
// some conditions in which it does not, ex:
|
|
2127
|
-
// race conditions in a poor network while the adapter does not cancel a previous request.
|
|
2128
|
-
debugInfo.wasDataProvisionedForConfig = true;
|
|
2129
|
-
}
|
|
2130
|
-
fieldOrMethodCallback(value);
|
|
2131
|
-
};
|
|
2132
|
-
let context;
|
|
2133
|
-
let connector;
|
|
2134
|
-
// Workaround to pass the component element associated to this wire adapter instance.
|
|
2135
|
-
shared.defineProperty(dataCallback, DeprecatedWiredElementHost, {
|
|
2136
|
-
value: vm.elm
|
|
2137
|
-
});
|
|
2138
|
-
shared.defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
|
|
2139
|
-
value: dynamic
|
|
2140
|
-
});
|
|
2141
|
-
runWithBoundaryProtection(vm, vm, shared.noop, () => {
|
|
2142
|
-
// job
|
|
2143
|
-
connector = new adapter(dataCallback);
|
|
2144
|
-
}, shared.noop);
|
|
2145
|
-
const updateConnectorConfig = config => {
|
|
2146
|
-
// every time the config is recomputed due to tracking,
|
|
2147
|
-
// this callback will be invoked with the new computed config
|
|
2148
|
-
runWithBoundaryProtection(vm, vm, shared.noop, () => {
|
|
2149
|
-
// job
|
|
2150
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2151
|
-
debugInfo.config = config;
|
|
2152
|
-
debugInfo.context = context;
|
|
1980
|
+
const wiredPropOrMethod = shared.isUndefined(method) ? name : method.name;
|
|
1981
|
+
debugInfo = shared.create(null);
|
|
2153
1982
|
debugInfo.wasDataProvisionedForConfig = false;
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
}
|
|
1983
|
+
vm.debugInfo[WIRE_DEBUG_ENTRY][wiredPropOrMethod] = debugInfo;
|
|
1984
|
+
}
|
|
1985
|
+
const fieldOrMethodCallback = shared.isUndefined(method)
|
|
1986
|
+
? createFieldDataCallback(vm, name)
|
|
1987
|
+
: createMethodDataCallback(vm, method);
|
|
1988
|
+
const dataCallback = (value) => {
|
|
1989
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1990
|
+
debugInfo.data = value;
|
|
1991
|
+
// Note: most of the time, the data provided is for the current config, but there may be
|
|
1992
|
+
// some conditions in which it does not, ex:
|
|
1993
|
+
// race conditions in a poor network while the adapter does not cancel a previous request.
|
|
1994
|
+
debugInfo.wasDataProvisionedForConfig = true;
|
|
1995
|
+
}
|
|
1996
|
+
fieldOrMethodCallback(value);
|
|
1997
|
+
};
|
|
1998
|
+
let context;
|
|
1999
|
+
let connector;
|
|
2000
|
+
// Workaround to pass the component element associated to this wire adapter instance.
|
|
2001
|
+
shared.defineProperty(dataCallback, DeprecatedWiredElementHost, {
|
|
2002
|
+
value: vm.elm,
|
|
2003
|
+
});
|
|
2004
|
+
shared.defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
|
|
2005
|
+
value: dynamic,
|
|
2178
2006
|
});
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2007
|
+
runWithBoundaryProtection(vm, vm, shared.noop, () => {
|
|
2008
|
+
// job
|
|
2009
|
+
connector = new adapter(dataCallback);
|
|
2010
|
+
}, shared.noop);
|
|
2011
|
+
const updateConnectorConfig = (config) => {
|
|
2012
|
+
// every time the config is recomputed due to tracking,
|
|
2013
|
+
// this callback will be invoked with the new computed config
|
|
2014
|
+
runWithBoundaryProtection(vm, vm, shared.noop, () => {
|
|
2015
|
+
// job
|
|
2016
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2017
|
+
debugInfo.config = config;
|
|
2018
|
+
debugInfo.context = context;
|
|
2019
|
+
debugInfo.wasDataProvisionedForConfig = false;
|
|
2020
|
+
}
|
|
2021
|
+
connector.update(config, context);
|
|
2022
|
+
}, shared.noop);
|
|
2023
|
+
};
|
|
2024
|
+
// Computes the current wire config and calls the update method on the wire adapter.
|
|
2025
|
+
// If it has params, we will need to observe changes in the next tick.
|
|
2026
|
+
const { computeConfigAndUpdate, ro } = createConfigWatcher(vm.component, configCallback, updateConnectorConfig);
|
|
2027
|
+
// if the adapter needs contextualization, we need to watch for new context and push it alongside the config
|
|
2028
|
+
if (!shared.isUndefined(adapter.contextSchema)) {
|
|
2029
|
+
createContextWatcher(vm, wireDef, (newContext) => {
|
|
2030
|
+
// every time the context is pushed into this component,
|
|
2031
|
+
// this callback will be invoked with the new computed context
|
|
2032
|
+
if (context !== newContext) {
|
|
2033
|
+
context = newContext;
|
|
2034
|
+
// Note: when new context arrives, the config will be recomputed and pushed along side the new
|
|
2035
|
+
// context, this is to preserve the identity characteristics, config should not have identity
|
|
2036
|
+
// (ever), while context can have identity
|
|
2037
|
+
if (vm.state === 1 /* VMState.connected */) {
|
|
2038
|
+
computeConfigAndUpdate();
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
});
|
|
2042
|
+
}
|
|
2043
|
+
return {
|
|
2044
|
+
// @ts-ignore the boundary protection executes sync, connector is always defined
|
|
2045
|
+
connector,
|
|
2046
|
+
computeConfigAndUpdate,
|
|
2047
|
+
resetConfigWatcher: () => ro.reset(),
|
|
2048
|
+
};
|
|
2186
2049
|
}
|
|
2187
2050
|
const AdapterToTokenMap = new Map();
|
|
2188
2051
|
function getAdapterToken(adapter) {
|
|
2189
|
-
|
|
2052
|
+
return AdapterToTokenMap.get(adapter);
|
|
2190
2053
|
}
|
|
2191
2054
|
function setAdapterToken(adapter, token) {
|
|
2192
|
-
|
|
2055
|
+
AdapterToTokenMap.set(adapter, token);
|
|
2193
2056
|
}
|
|
2194
2057
|
function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2058
|
+
// support for callable adapters
|
|
2059
|
+
if (adapter.adapter) {
|
|
2060
|
+
adapter = adapter.adapter;
|
|
2061
|
+
}
|
|
2062
|
+
const method = descriptor.value;
|
|
2063
|
+
const def = {
|
|
2064
|
+
adapter,
|
|
2065
|
+
method,
|
|
2066
|
+
configCallback,
|
|
2067
|
+
dynamic,
|
|
2068
|
+
};
|
|
2069
|
+
WireMetaMap.set(descriptor, def);
|
|
2207
2070
|
}
|
|
2208
2071
|
function storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic) {
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2072
|
+
// support for callable adapters
|
|
2073
|
+
if (adapter.adapter) {
|
|
2074
|
+
adapter = adapter.adapter;
|
|
2075
|
+
}
|
|
2076
|
+
const def = {
|
|
2077
|
+
adapter,
|
|
2078
|
+
configCallback,
|
|
2079
|
+
dynamic,
|
|
2080
|
+
};
|
|
2081
|
+
WireMetaMap.set(descriptor, def);
|
|
2219
2082
|
}
|
|
2220
2083
|
function installWireAdapters(vm) {
|
|
2221
|
-
|
|
2222
|
-
context,
|
|
2223
|
-
def: {
|
|
2224
|
-
wire
|
|
2225
|
-
}
|
|
2226
|
-
} = vm;
|
|
2227
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2228
|
-
vm.debugInfo[WIRE_DEBUG_ENTRY] = shared.create(null);
|
|
2229
|
-
}
|
|
2230
|
-
const wiredConnecting = context.wiredConnecting = [];
|
|
2231
|
-
const wiredDisconnecting = context.wiredDisconnecting = [];
|
|
2232
|
-
for (const fieldNameOrMethod in wire) {
|
|
2233
|
-
const descriptor = wire[fieldNameOrMethod];
|
|
2234
|
-
const wireDef = WireMetaMap.get(descriptor);
|
|
2084
|
+
const { context, def: { wire }, } = vm;
|
|
2235
2085
|
if (process.env.NODE_ENV !== 'production') {
|
|
2236
|
-
|
|
2086
|
+
vm.debugInfo[WIRE_DEBUG_ENTRY] = shared.create(null);
|
|
2237
2087
|
}
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2088
|
+
const wiredConnecting = (context.wiredConnecting = []);
|
|
2089
|
+
const wiredDisconnecting = (context.wiredDisconnecting = []);
|
|
2090
|
+
for (const fieldNameOrMethod in wire) {
|
|
2091
|
+
const descriptor = wire[fieldNameOrMethod];
|
|
2092
|
+
const wireDef = WireMetaMap.get(descriptor);
|
|
2093
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2094
|
+
shared.assert.invariant(wireDef, `Internal Error: invalid wire definition found.`);
|
|
2095
|
+
}
|
|
2096
|
+
if (!shared.isUndefined(wireDef)) {
|
|
2097
|
+
const { connector, computeConfigAndUpdate, resetConfigWatcher } = createConnector(vm, fieldNameOrMethod, wireDef);
|
|
2098
|
+
const hasDynamicParams = wireDef.dynamic.length > 0;
|
|
2099
|
+
shared.ArrayPush.call(wiredConnecting, () => {
|
|
2100
|
+
connector.connect();
|
|
2101
|
+
if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
|
|
2102
|
+
if (hasDynamicParams) {
|
|
2103
|
+
Promise.resolve().then(computeConfigAndUpdate);
|
|
2104
|
+
return;
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
computeConfigAndUpdate();
|
|
2108
|
+
});
|
|
2109
|
+
shared.ArrayPush.call(wiredDisconnecting, () => {
|
|
2110
|
+
connector.disconnect();
|
|
2111
|
+
resetConfigWatcher();
|
|
2112
|
+
});
|
|
2252
2113
|
}
|
|
2253
|
-
computeConfigAndUpdate();
|
|
2254
|
-
});
|
|
2255
|
-
shared.ArrayPush.call(wiredDisconnecting, () => {
|
|
2256
|
-
connector.disconnect();
|
|
2257
|
-
resetConfigWatcher();
|
|
2258
|
-
});
|
|
2259
2114
|
}
|
|
2260
|
-
}
|
|
2261
2115
|
}
|
|
2262
2116
|
function connectWireAdapters(vm) {
|
|
2263
|
-
|
|
2264
|
-
wiredConnecting
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
wiredConnecting[i]();
|
|
2268
|
-
}
|
|
2117
|
+
const { wiredConnecting } = vm.context;
|
|
2118
|
+
for (let i = 0, len = wiredConnecting.length; i < len; i += 1) {
|
|
2119
|
+
wiredConnecting[i]();
|
|
2120
|
+
}
|
|
2269
2121
|
}
|
|
2270
2122
|
function disconnectWireAdapters(vm) {
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
}
|
|
2279
|
-
}, shared.noop);
|
|
2123
|
+
const { wiredDisconnecting } = vm.context;
|
|
2124
|
+
runWithBoundaryProtection(vm, vm, shared.noop, () => {
|
|
2125
|
+
// job
|
|
2126
|
+
for (let i = 0, len = wiredDisconnecting.length; i < len; i += 1) {
|
|
2127
|
+
wiredDisconnecting[i]();
|
|
2128
|
+
}
|
|
2129
|
+
}, shared.noop);
|
|
2280
2130
|
}
|
|
2281
2131
|
|
|
2282
2132
|
/*
|
|
@@ -2672,7 +2522,7 @@ function checkVersionMismatch(func, type) {
|
|
|
2672
2522
|
// stylesheets and templates do not have user-meaningful names, but components do
|
|
2673
2523
|
const friendlyName = type === 'component' ? `${type} ${func.name}` : type;
|
|
2674
2524
|
logError(`LWC WARNING: current engine is v${shared.LWC_VERSION}, but ${friendlyName} was compiled with v${version}.\nPlease update your compiled code or LWC engine so that the versions match.\nNo further warnings will appear.`);
|
|
2675
|
-
report(
|
|
2525
|
+
report("CompilerRuntimeVersionMismatch" /* ReportingEventId.CompilerRuntimeVersionMismatch */, {
|
|
2676
2526
|
compilerVersion: version,
|
|
2677
2527
|
runtimeVersion: shared.LWC_VERSION,
|
|
2678
2528
|
});
|
|
@@ -2724,160 +2574,151 @@ function sanitizeAttribute(tagName, namespaceUri, attrName, attrValue) {
|
|
|
2724
2574
|
const cachedGetterByKey = shared.create(null);
|
|
2725
2575
|
const cachedSetterByKey = shared.create(null);
|
|
2726
2576
|
function createGetter(key) {
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
}
|
|
2737
|
-
return fn;
|
|
2577
|
+
let fn = cachedGetterByKey[key];
|
|
2578
|
+
if (shared.isUndefined(fn)) {
|
|
2579
|
+
fn = cachedGetterByKey[key] = function () {
|
|
2580
|
+
const vm = getAssociatedVM(this);
|
|
2581
|
+
const { getHook } = vm;
|
|
2582
|
+
return getHook(vm.component, key);
|
|
2583
|
+
};
|
|
2584
|
+
}
|
|
2585
|
+
return fn;
|
|
2738
2586
|
}
|
|
2739
2587
|
function createSetter(key) {
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
}
|
|
2751
|
-
return fn;
|
|
2588
|
+
let fn = cachedSetterByKey[key];
|
|
2589
|
+
if (shared.isUndefined(fn)) {
|
|
2590
|
+
fn = cachedSetterByKey[key] = function (newValue) {
|
|
2591
|
+
const vm = getAssociatedVM(this);
|
|
2592
|
+
const { setHook } = vm;
|
|
2593
|
+
newValue = getReadOnlyProxy(newValue);
|
|
2594
|
+
setHook(vm.component, key, newValue);
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
return fn;
|
|
2752
2598
|
}
|
|
2753
2599
|
function createMethodCaller(methodName) {
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
}
|
|
2760
|
-
const fn = component[methodName];
|
|
2761
|
-
return callHook(vm.component, fn, shared.ArraySlice.call(arguments));
|
|
2762
|
-
};
|
|
2600
|
+
return function () {
|
|
2601
|
+
const vm = getAssociatedVM(this);
|
|
2602
|
+
const { callHook, component } = vm;
|
|
2603
|
+
const fn = component[methodName];
|
|
2604
|
+
return callHook(vm.component, fn, shared.ArraySlice.call(arguments));
|
|
2605
|
+
};
|
|
2763
2606
|
}
|
|
2764
2607
|
function createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback) {
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2608
|
+
return function attributeChangedCallback(attrName, oldValue, newValue) {
|
|
2609
|
+
if (oldValue === newValue) {
|
|
2610
|
+
// Ignore same values.
|
|
2611
|
+
return;
|
|
2612
|
+
}
|
|
2613
|
+
const propName = attributeToPropMap[attrName];
|
|
2614
|
+
if (shared.isUndefined(propName)) {
|
|
2615
|
+
if (!shared.isUndefined(superAttributeChangedCallback)) {
|
|
2616
|
+
// delegate unknown attributes to the super.
|
|
2617
|
+
// Typescript does not like it when you treat the `arguments` object as an array
|
|
2618
|
+
// @ts-ignore type-mismatch
|
|
2619
|
+
superAttributeChangedCallback.apply(this, arguments);
|
|
2620
|
+
}
|
|
2621
|
+
return;
|
|
2622
|
+
}
|
|
2623
|
+
if (!isAttributeLocked(this, attrName)) {
|
|
2624
|
+
// Ignore changes triggered by the engine itself during:
|
|
2625
|
+
// * diffing when public props are attempting to reflect to the DOM
|
|
2626
|
+
// * component via `this.setAttribute()`, should never update the prop
|
|
2627
|
+
// Both cases, the setAttribute call is always wrapped by the unlocking of the
|
|
2628
|
+
// attribute to be changed
|
|
2629
|
+
return;
|
|
2630
|
+
}
|
|
2631
|
+
// Reflect attribute change to the corresponding property when changed from outside.
|
|
2632
|
+
this[propName] = newValue;
|
|
2633
|
+
};
|
|
2791
2634
|
}
|
|
2792
2635
|
function HTMLBridgeElementFactory(SuperClass, props, methods) {
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2636
|
+
let HTMLBridgeElement;
|
|
2637
|
+
/**
|
|
2638
|
+
* Modern browsers will have all Native Constructors as regular Classes
|
|
2639
|
+
* and must be instantiated with the new keyword. In older browsers,
|
|
2640
|
+
* specifically IE11, those are objects with a prototype property defined,
|
|
2641
|
+
* since they are not supposed to be extended or instantiated with the
|
|
2642
|
+
* new keyword. This forking logic supports both cases, specifically because
|
|
2643
|
+
* wc.ts relies on the construction path of the bridges to create new
|
|
2644
|
+
* fully qualifying web components.
|
|
2645
|
+
*/
|
|
2646
|
+
if (shared.isFunction(SuperClass)) {
|
|
2647
|
+
HTMLBridgeElement = class extends SuperClass {
|
|
2648
|
+
};
|
|
2649
|
+
}
|
|
2650
|
+
else {
|
|
2651
|
+
HTMLBridgeElement = function () {
|
|
2652
|
+
// Bridge classes are not supposed to be instantiated directly in
|
|
2653
|
+
// browsers that do not support web components.
|
|
2654
|
+
throw new TypeError('Illegal constructor');
|
|
2655
|
+
};
|
|
2656
|
+
// prototype inheritance dance
|
|
2657
|
+
shared.setPrototypeOf(HTMLBridgeElement, SuperClass);
|
|
2658
|
+
shared.setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
|
|
2659
|
+
shared.defineProperty(HTMLBridgeElement.prototype, 'constructor', {
|
|
2660
|
+
writable: true,
|
|
2661
|
+
configurable: true,
|
|
2662
|
+
value: HTMLBridgeElement,
|
|
2663
|
+
});
|
|
2664
|
+
}
|
|
2665
|
+
// generating the hash table for attributes to avoid duplicate fields and facilitate validation
|
|
2666
|
+
// and false positives in case of inheritance.
|
|
2667
|
+
const attributeToPropMap = shared.create(null);
|
|
2668
|
+
const { attributeChangedCallback: superAttributeChangedCallback } = SuperClass.prototype;
|
|
2669
|
+
const { observedAttributes: superObservedAttributes = [] } = SuperClass;
|
|
2670
|
+
const descriptors = shared.create(null);
|
|
2671
|
+
// expose getters and setters for each public props on the new Element Bridge
|
|
2672
|
+
for (let i = 0, len = props.length; i < len; i += 1) {
|
|
2673
|
+
const propName = props[i];
|
|
2674
|
+
attributeToPropMap[shared.htmlPropertyToAttribute(propName)] = propName;
|
|
2675
|
+
descriptors[propName] = {
|
|
2676
|
+
get: createGetter(propName),
|
|
2677
|
+
set: createSetter(propName),
|
|
2678
|
+
enumerable: true,
|
|
2679
|
+
configurable: true,
|
|
2680
|
+
};
|
|
2681
|
+
}
|
|
2682
|
+
// expose public methods as props on the new Element Bridge
|
|
2683
|
+
for (let i = 0, len = methods.length; i < len; i += 1) {
|
|
2684
|
+
const methodName = methods[i];
|
|
2685
|
+
descriptors[methodName] = {
|
|
2686
|
+
value: createMethodCaller(methodName),
|
|
2687
|
+
writable: true,
|
|
2688
|
+
configurable: true,
|
|
2689
|
+
};
|
|
2690
|
+
}
|
|
2691
|
+
// creating a new attributeChangedCallback per bridge because they are bound to the corresponding
|
|
2692
|
+
// map of attributes to props. We do this after all other props and methods to avoid the possibility
|
|
2693
|
+
// of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
|
|
2694
|
+
// to preserve this definition.
|
|
2695
|
+
descriptors.attributeChangedCallback = {
|
|
2696
|
+
value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback),
|
|
2810
2697
|
};
|
|
2811
|
-
//
|
|
2812
|
-
|
|
2813
|
-
shared.
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
value: HTMLBridgeElement
|
|
2698
|
+
// Specify attributes for which we want to reflect changes back to their corresponding
|
|
2699
|
+
// properties via attributeChangedCallback.
|
|
2700
|
+
shared.defineProperty(HTMLBridgeElement, 'observedAttributes', {
|
|
2701
|
+
get() {
|
|
2702
|
+
return [...superObservedAttributes, ...shared.keys(attributeToPropMap)];
|
|
2703
|
+
},
|
|
2818
2704
|
});
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
// and false positives in case of inheritance.
|
|
2822
|
-
const attributeToPropMap = shared.create(null);
|
|
2823
|
-
const {
|
|
2824
|
-
attributeChangedCallback: superAttributeChangedCallback
|
|
2825
|
-
} = SuperClass.prototype;
|
|
2826
|
-
const {
|
|
2827
|
-
observedAttributes: superObservedAttributes = []
|
|
2828
|
-
} = SuperClass;
|
|
2829
|
-
const descriptors = shared.create(null);
|
|
2830
|
-
// expose getters and setters for each public props on the new Element Bridge
|
|
2831
|
-
for (let i = 0, len = props.length; i < len; i += 1) {
|
|
2832
|
-
const propName = props[i];
|
|
2833
|
-
attributeToPropMap[shared.htmlPropertyToAttribute(propName)] = propName;
|
|
2834
|
-
descriptors[propName] = {
|
|
2835
|
-
get: createGetter(propName),
|
|
2836
|
-
set: createSetter(propName),
|
|
2837
|
-
enumerable: true,
|
|
2838
|
-
configurable: true
|
|
2839
|
-
};
|
|
2840
|
-
}
|
|
2841
|
-
// expose public methods as props on the new Element Bridge
|
|
2842
|
-
for (let i = 0, len = methods.length; i < len; i += 1) {
|
|
2843
|
-
const methodName = methods[i];
|
|
2844
|
-
descriptors[methodName] = {
|
|
2845
|
-
value: createMethodCaller(methodName),
|
|
2846
|
-
writable: true,
|
|
2847
|
-
configurable: true
|
|
2848
|
-
};
|
|
2849
|
-
}
|
|
2850
|
-
// creating a new attributeChangedCallback per bridge because they are bound to the corresponding
|
|
2851
|
-
// map of attributes to props. We do this after all other props and methods to avoid the possibility
|
|
2852
|
-
// of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
|
|
2853
|
-
// to preserve this definition.
|
|
2854
|
-
descriptors.attributeChangedCallback = {
|
|
2855
|
-
value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback)
|
|
2856
|
-
};
|
|
2857
|
-
// Specify attributes for which we want to reflect changes back to their corresponding
|
|
2858
|
-
// properties via attributeChangedCallback.
|
|
2859
|
-
shared.defineProperty(HTMLBridgeElement, 'observedAttributes', {
|
|
2860
|
-
get() {
|
|
2861
|
-
return [...superObservedAttributes, ...shared.keys(attributeToPropMap)];
|
|
2862
|
-
}
|
|
2863
|
-
});
|
|
2864
|
-
shared.defineProperties(HTMLBridgeElement.prototype, descriptors);
|
|
2865
|
-
return HTMLBridgeElement;
|
|
2705
|
+
shared.defineProperties(HTMLBridgeElement.prototype, descriptors);
|
|
2706
|
+
return HTMLBridgeElement;
|
|
2866
2707
|
}
|
|
2867
2708
|
const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, shared.getOwnPropertyNames(HTMLElementOriginalDescriptors), []);
|
|
2868
2709
|
if (process.env.IS_BROWSER) {
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2710
|
+
// This ARIA reflection only really makes sense in the browser. On the server, there is no `renderedCallback()`,
|
|
2711
|
+
// so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't need to expose
|
|
2712
|
+
// ARIA props outside the LightningElement
|
|
2713
|
+
if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
|
|
2714
|
+
// If ARIA reflection is not applied globally to Element.prototype, apply it to HTMLBridgeElement.prototype.
|
|
2715
|
+
// This allows `elm.aria*` property accessors to work from outside a component, and to reflect `aria-*` attrs.
|
|
2716
|
+
// This is especially important because the template compiler compiles aria-* attrs on components to aria* props
|
|
2717
|
+
//
|
|
2718
|
+
// Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
|
|
2719
|
+
// accessors inside the HTMLBridgeElementFactory.
|
|
2720
|
+
ariaReflection.applyAriaReflection(BaseBridgeElement.prototype);
|
|
2721
|
+
}
|
|
2881
2722
|
}
|
|
2882
2723
|
shared.freeze(BaseBridgeElement);
|
|
2883
2724
|
shared.seal(BaseBridgeElement.prototype);
|
|
@@ -3293,157 +3134,137 @@ function getComponentDef(Ctor) {
|
|
|
3293
3134
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3294
3135
|
*/
|
|
3295
3136
|
function makeHostToken(token) {
|
|
3296
|
-
|
|
3137
|
+
return `${token}-host`;
|
|
3297
3138
|
}
|
|
3298
3139
|
function createInlineStyleVNode(content) {
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3140
|
+
return api.h('style', {
|
|
3141
|
+
key: 'style',
|
|
3142
|
+
attrs: {
|
|
3143
|
+
type: 'text/css',
|
|
3144
|
+
},
|
|
3145
|
+
}, [api.t(content)]);
|
|
3305
3146
|
}
|
|
3306
3147
|
function updateStylesheetToken(vm, template) {
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
renderMode
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
}
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
// associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
|
|
3348
|
-
const hasNewStylesheets = hasStyles(newStylesheets);
|
|
3349
|
-
const hasNewVmStylesheets = hasStyles(newVmStylesheets);
|
|
3350
|
-
if (hasNewStylesheets || hasNewVmStylesheets) {
|
|
3351
|
-
newToken = newStylesheetToken;
|
|
3352
|
-
}
|
|
3353
|
-
// Set the new styling token on the host element
|
|
3354
|
-
if (!shared.isUndefined(newToken)) {
|
|
3355
|
-
if (hasScopedStyles) {
|
|
3356
|
-
getClassList(elm).add(makeHostToken(newToken));
|
|
3357
|
-
newHasTokenInClass = true;
|
|
3358
|
-
}
|
|
3359
|
-
if (isSyntheticShadow) {
|
|
3360
|
-
setAttribute(elm, makeHostToken(newToken), '');
|
|
3361
|
-
newHasTokenInAttribute = true;
|
|
3362
|
-
}
|
|
3363
|
-
}
|
|
3364
|
-
// Update the styling tokens present on the context object.
|
|
3365
|
-
context.stylesheetToken = newToken;
|
|
3366
|
-
context.hasTokenInClass = newHasTokenInClass;
|
|
3367
|
-
context.hasTokenInAttribute = newHasTokenInAttribute;
|
|
3148
|
+
const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
|
|
3149
|
+
const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
|
|
3150
|
+
const { stylesheets: newVmStylesheets } = vm;
|
|
3151
|
+
const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
|
|
3152
|
+
const { hasScopedStyles } = context;
|
|
3153
|
+
let newToken;
|
|
3154
|
+
let newHasTokenInClass;
|
|
3155
|
+
let newHasTokenInAttribute;
|
|
3156
|
+
// Reset the styling token applied to the host element.
|
|
3157
|
+
const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
|
|
3158
|
+
if (!shared.isUndefined(oldToken)) {
|
|
3159
|
+
if (oldHasTokenInClass) {
|
|
3160
|
+
getClassList(elm).remove(makeHostToken(oldToken));
|
|
3161
|
+
}
|
|
3162
|
+
if (oldHasTokenInAttribute) {
|
|
3163
|
+
removeAttribute(elm, makeHostToken(oldToken));
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3166
|
+
// Apply the new template styling token to the host element, if the new template has any
|
|
3167
|
+
// associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
|
|
3168
|
+
const hasNewStylesheets = hasStyles(newStylesheets);
|
|
3169
|
+
const hasNewVmStylesheets = hasStyles(newVmStylesheets);
|
|
3170
|
+
if (hasNewStylesheets || hasNewVmStylesheets) {
|
|
3171
|
+
newToken = newStylesheetToken;
|
|
3172
|
+
}
|
|
3173
|
+
// Set the new styling token on the host element
|
|
3174
|
+
if (!shared.isUndefined(newToken)) {
|
|
3175
|
+
if (hasScopedStyles) {
|
|
3176
|
+
getClassList(elm).add(makeHostToken(newToken));
|
|
3177
|
+
newHasTokenInClass = true;
|
|
3178
|
+
}
|
|
3179
|
+
if (isSyntheticShadow) {
|
|
3180
|
+
setAttribute(elm, makeHostToken(newToken), '');
|
|
3181
|
+
newHasTokenInAttribute = true;
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
// Update the styling tokens present on the context object.
|
|
3185
|
+
context.stylesheetToken = newToken;
|
|
3186
|
+
context.hasTokenInClass = newHasTokenInClass;
|
|
3187
|
+
context.hasTokenInAttribute = newHasTokenInAttribute;
|
|
3368
3188
|
}
|
|
3369
3189
|
function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3190
|
+
const content = [];
|
|
3191
|
+
let root;
|
|
3192
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
3193
|
+
let stylesheet = stylesheets[i];
|
|
3194
|
+
if (shared.isArray(stylesheet)) {
|
|
3195
|
+
shared.ArrayPush.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
|
|
3196
|
+
}
|
|
3197
|
+
else {
|
|
3198
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3199
|
+
// Check for compiler version mismatch in dev mode only
|
|
3200
|
+
checkVersionMismatch(stylesheet, 'stylesheet');
|
|
3201
|
+
// in dev-mode, we support hot swapping of stylesheet, which means that
|
|
3202
|
+
// the component instance might be attempting to use an old version of
|
|
3203
|
+
// the stylesheet, while internally, we have a replacement for it.
|
|
3204
|
+
stylesheet = getStyleOrSwappedStyle(stylesheet);
|
|
3205
|
+
}
|
|
3206
|
+
const isScopedCss = stylesheet[shared.KEY__SCOPED_CSS];
|
|
3207
|
+
if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS &&
|
|
3208
|
+
!isScopedCss &&
|
|
3209
|
+
vm.renderMode === 0 /* RenderMode.Light */) {
|
|
3210
|
+
logError('Unscoped CSS is not supported in Light DOM. Please use scoped CSS (*.scoped.css) instead of unscoped CSS (*.css).');
|
|
3211
|
+
continue;
|
|
3212
|
+
}
|
|
3213
|
+
// Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
|
|
3214
|
+
const scopeToken = isScopedCss ||
|
|
3215
|
+
(vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
|
|
3216
|
+
? stylesheetToken
|
|
3217
|
+
: undefined;
|
|
3218
|
+
// Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
|
|
3219
|
+
// native shadow DOM. Synthetic shadow DOM never uses `:host`.
|
|
3220
|
+
const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
|
|
3221
|
+
? !isScopedCss
|
|
3222
|
+
: vm.shadowMode === 0 /* ShadowMode.Native */;
|
|
3223
|
+
// Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
|
|
3224
|
+
// we use an attribute selector on the host to simulate :dir().
|
|
3225
|
+
let useNativeDirPseudoclass;
|
|
3226
|
+
if (vm.renderMode === 1 /* RenderMode.Shadow */) {
|
|
3227
|
+
useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
|
|
3228
|
+
}
|
|
3229
|
+
else {
|
|
3230
|
+
// Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
|
|
3231
|
+
// At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
|
|
3232
|
+
if (shared.isUndefined(root)) {
|
|
3233
|
+
// Only calculate the root once as necessary
|
|
3234
|
+
root = getNearestShadowComponent(vm);
|
|
3235
|
+
}
|
|
3236
|
+
useNativeDirPseudoclass = shared.isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
|
|
3237
|
+
}
|
|
3238
|
+
shared.ArrayPush.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
|
|
3239
|
+
}
|
|
3413
3240
|
}
|
|
3414
|
-
|
|
3415
|
-
return content;
|
|
3241
|
+
return content;
|
|
3416
3242
|
}
|
|
3417
3243
|
function getStylesheetsContent(vm, template) {
|
|
3418
|
-
|
|
3419
|
-
stylesheets
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
// VM (component) stylesheets apply after template stylesheets
|
|
3430
|
-
if (hasStyles(vmStylesheets)) {
|
|
3431
|
-
shared.ArrayPush.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
|
|
3432
|
-
}
|
|
3433
|
-
return content;
|
|
3244
|
+
const { stylesheets, stylesheetToken } = template;
|
|
3245
|
+
const { stylesheets: vmStylesheets } = vm;
|
|
3246
|
+
let content = [];
|
|
3247
|
+
if (hasStyles(stylesheets)) {
|
|
3248
|
+
content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
|
|
3249
|
+
}
|
|
3250
|
+
// VM (component) stylesheets apply after template stylesheets
|
|
3251
|
+
if (hasStyles(vmStylesheets)) {
|
|
3252
|
+
shared.ArrayPush.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
|
|
3253
|
+
}
|
|
3254
|
+
return content;
|
|
3434
3255
|
}
|
|
3435
3256
|
// It might be worth caching this to avoid doing the lookup repeatedly, but
|
|
3436
3257
|
// perf testing has not shown it to be a huge improvement yet:
|
|
3437
3258
|
// https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
|
|
3438
3259
|
function getNearestShadowComponent(vm) {
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3260
|
+
let owner = vm;
|
|
3261
|
+
while (!shared.isNull(owner)) {
|
|
3262
|
+
if (owner.renderMode === 1 /* RenderMode.Shadow */) {
|
|
3263
|
+
return owner;
|
|
3264
|
+
}
|
|
3265
|
+
owner = owner.owner;
|
|
3443
3266
|
}
|
|
3444
|
-
|
|
3445
|
-
}
|
|
3446
|
-
return owner;
|
|
3267
|
+
return owner;
|
|
3447
3268
|
}
|
|
3448
3269
|
/**
|
|
3449
3270
|
* If the component that is currently being rendered uses scoped styles,
|
|
@@ -3451,11 +3272,8 @@ function getNearestShadowComponent(vm) {
|
|
|
3451
3272
|
* it returns null.
|
|
3452
3273
|
*/
|
|
3453
3274
|
function getScopeTokenClass(owner) {
|
|
3454
|
-
|
|
3455
|
-
cmpTemplate
|
|
3456
|
-
context
|
|
3457
|
-
} = owner;
|
|
3458
|
-
return context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken) || null;
|
|
3275
|
+
const { cmpTemplate, context } = owner;
|
|
3276
|
+
return (context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) || null;
|
|
3459
3277
|
}
|
|
3460
3278
|
/**
|
|
3461
3279
|
* This function returns the host style token for a custom element if it
|
|
@@ -3464,54 +3282,46 @@ function getScopeTokenClass(owner) {
|
|
|
3464
3282
|
* A host style token is applied to the component if scoped styles are used.
|
|
3465
3283
|
*/
|
|
3466
3284
|
function getStylesheetTokenHost(vnode) {
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
const {
|
|
3474
|
-
stylesheetToken
|
|
3475
|
-
} = template;
|
|
3476
|
-
return !shared.isUndefined(stylesheetToken) && computeHasScopedStyles(template, vm) ? makeHostToken(stylesheetToken) : null;
|
|
3285
|
+
const { template } = getComponentInternalDef(vnode.ctor);
|
|
3286
|
+
const { vm } = vnode;
|
|
3287
|
+
const { stylesheetToken } = template;
|
|
3288
|
+
return !shared.isUndefined(stylesheetToken) && computeHasScopedStyles(template, vm)
|
|
3289
|
+
? makeHostToken(stylesheetToken)
|
|
3290
|
+
: null;
|
|
3477
3291
|
}
|
|
3478
3292
|
function getNearestNativeShadowComponent(vm) {
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3293
|
+
const owner = getNearestShadowComponent(vm);
|
|
3294
|
+
if (!shared.isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
|
|
3295
|
+
// Synthetic-within-native is impossible. So if the nearest shadow component is
|
|
3296
|
+
// synthetic, we know we won't find a native component if we go any further.
|
|
3297
|
+
return null;
|
|
3298
|
+
}
|
|
3299
|
+
return owner;
|
|
3486
3300
|
}
|
|
3487
3301
|
function createStylesheet(vm, stylesheets) {
|
|
3488
|
-
|
|
3489
|
-
renderMode
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
}
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
const target = shared.isNull(root) ? undefined : root.shadowRoot;
|
|
3510
|
-
for (let i = 0; i < stylesheets.length; i++) {
|
|
3511
|
-
insertStylesheet(stylesheets[i], target);
|
|
3302
|
+
const { renderMode, shadowMode, renderer: { insertStylesheet }, } = vm;
|
|
3303
|
+
if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
|
|
3304
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
3305
|
+
insertStylesheet(stylesheets[i]);
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
else if (!process.env.IS_BROWSER || vm.hydrated) {
|
|
3309
|
+
// Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
|
|
3310
|
+
// This works in the client, because the stylesheets are created, and cached in the VM
|
|
3311
|
+
// the first time the VM renders.
|
|
3312
|
+
// native shadow or light DOM, SSR
|
|
3313
|
+
return shared.ArrayMap.call(stylesheets, createInlineStyleVNode);
|
|
3314
|
+
}
|
|
3315
|
+
else {
|
|
3316
|
+
// native shadow or light DOM, DOM renderer
|
|
3317
|
+
const root = getNearestNativeShadowComponent(vm);
|
|
3318
|
+
// null root means a global style
|
|
3319
|
+
const target = shared.isNull(root) ? undefined : root.shadowRoot;
|
|
3320
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
3321
|
+
insertStylesheet(stylesheets[i], target);
|
|
3322
|
+
}
|
|
3512
3323
|
}
|
|
3513
|
-
|
|
3514
|
-
return null;
|
|
3324
|
+
return null;
|
|
3515
3325
|
}
|
|
3516
3326
|
|
|
3517
3327
|
/*
|
|
@@ -3830,505 +3640,443 @@ function applyStaticStyleAttribute(vnode, renderer) {
|
|
|
3830
3640
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3831
3641
|
*/
|
|
3832
3642
|
function patchChildren(c1, c2, parent, renderer) {
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3643
|
+
if (hasDynamicChildren(c2)) {
|
|
3644
|
+
updateDynamicChildren(c1, c2, parent, renderer);
|
|
3645
|
+
}
|
|
3646
|
+
else {
|
|
3647
|
+
updateStaticChildren(c1, c2, parent, renderer);
|
|
3648
|
+
}
|
|
3838
3649
|
}
|
|
3839
3650
|
function patch(n1, n2, parent, renderer) {
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
patchCustomElement(n1, n2, parent, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
|
|
3875
|
-
break;
|
|
3876
|
-
}
|
|
3651
|
+
var _a, _b;
|
|
3652
|
+
if (n1 === n2) {
|
|
3653
|
+
return;
|
|
3654
|
+
}
|
|
3655
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3656
|
+
if (!isSameVnode(n1, n2)) {
|
|
3657
|
+
throw new Error('Expected these VNodes to be the same: ' +
|
|
3658
|
+
JSON.stringify({ sel: n1.sel, key: n1.key }) +
|
|
3659
|
+
', ' +
|
|
3660
|
+
JSON.stringify({ sel: n2.sel, key: n2.key }));
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
switch (n2.type) {
|
|
3664
|
+
case 0 /* VNodeType.Text */:
|
|
3665
|
+
// VText has no special capability, fallback to the owner's renderer
|
|
3666
|
+
patchText(n1, n2, renderer);
|
|
3667
|
+
break;
|
|
3668
|
+
case 1 /* VNodeType.Comment */:
|
|
3669
|
+
// VComment has no special capability, fallback to the owner's renderer
|
|
3670
|
+
patchComment(n1, n2, renderer);
|
|
3671
|
+
break;
|
|
3672
|
+
case 4 /* VNodeType.Static */:
|
|
3673
|
+
n2.elm = n1.elm;
|
|
3674
|
+
break;
|
|
3675
|
+
case 5 /* VNodeType.Fragment */:
|
|
3676
|
+
patchFragment(n1, n2, parent, renderer);
|
|
3677
|
+
break;
|
|
3678
|
+
case 2 /* VNodeType.Element */:
|
|
3679
|
+
patchElement(n1, n2, (_a = n2.data.renderer) !== null && _a !== void 0 ? _a : renderer);
|
|
3680
|
+
break;
|
|
3681
|
+
case 3 /* VNodeType.CustomElement */:
|
|
3682
|
+
patchCustomElement(n1, n2, parent, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
|
|
3683
|
+
break;
|
|
3684
|
+
}
|
|
3877
3685
|
}
|
|
3878
3686
|
function mount(node, parent, renderer, anchor) {
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3687
|
+
var _a, _b;
|
|
3688
|
+
switch (node.type) {
|
|
3689
|
+
case 0 /* VNodeType.Text */:
|
|
3690
|
+
// VText has no special capability, fallback to the owner's renderer
|
|
3691
|
+
mountText(node, parent, anchor, renderer);
|
|
3692
|
+
break;
|
|
3693
|
+
case 1 /* VNodeType.Comment */:
|
|
3694
|
+
// VComment has no special capability, fallback to the owner's renderer
|
|
3695
|
+
mountComment(node, parent, anchor, renderer);
|
|
3696
|
+
break;
|
|
3697
|
+
case 4 /* VNodeType.Static */:
|
|
3698
|
+
// VStatic cannot have a custom renderer associated to them, using owner's renderer
|
|
3699
|
+
mountStatic(node, parent, anchor, renderer);
|
|
3700
|
+
break;
|
|
3701
|
+
case 5 /* VNodeType.Fragment */:
|
|
3702
|
+
mountFragment(node, parent, anchor, renderer);
|
|
3703
|
+
break;
|
|
3704
|
+
case 2 /* VNodeType.Element */:
|
|
3705
|
+
// If the vnode data has a renderer override use it, else fallback to owner's renderer
|
|
3706
|
+
mountElement(node, parent, anchor, (_a = node.data.renderer) !== null && _a !== void 0 ? _a : renderer);
|
|
3707
|
+
break;
|
|
3708
|
+
case 3 /* VNodeType.CustomElement */:
|
|
3709
|
+
// If the vnode data has a renderer override use it, else fallback to owner's renderer
|
|
3710
|
+
mountCustomElement(node, parent, anchor, (_b = node.data.renderer) !== null && _b !== void 0 ? _b : renderer);
|
|
3711
|
+
break;
|
|
3712
|
+
}
|
|
3905
3713
|
}
|
|
3906
3714
|
function patchText(n1, n2, renderer) {
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3715
|
+
n2.elm = n1.elm;
|
|
3716
|
+
if (n2.text !== n1.text) {
|
|
3717
|
+
updateTextContent(n2, renderer);
|
|
3718
|
+
}
|
|
3911
3719
|
}
|
|
3912
3720
|
function mountText(vnode, parent, anchor, renderer) {
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
} = renderer;
|
|
3919
|
-
const textNode = vnode.elm = createText(vnode.text);
|
|
3920
|
-
linkNodeToShadow(textNode, owner, renderer);
|
|
3921
|
-
insertNode(textNode, parent, anchor, renderer);
|
|
3721
|
+
const { owner } = vnode;
|
|
3722
|
+
const { createText } = renderer;
|
|
3723
|
+
const textNode = (vnode.elm = createText(vnode.text));
|
|
3724
|
+
linkNodeToShadow(textNode, owner, renderer);
|
|
3725
|
+
insertNode(textNode, parent, anchor, renderer);
|
|
3922
3726
|
}
|
|
3923
3727
|
function patchComment(n1, n2, renderer) {
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3728
|
+
n2.elm = n1.elm;
|
|
3729
|
+
// FIXME: Comment nodes should be static, we shouldn't need to diff them together. However
|
|
3730
|
+
// it is the case today.
|
|
3731
|
+
if (n2.text !== n1.text) {
|
|
3732
|
+
updateTextContent(n2, renderer);
|
|
3733
|
+
}
|
|
3930
3734
|
}
|
|
3931
3735
|
function mountComment(vnode, parent, anchor, renderer) {
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
} = renderer;
|
|
3938
|
-
const commentNode = vnode.elm = createComment(vnode.text);
|
|
3939
|
-
linkNodeToShadow(commentNode, owner, renderer);
|
|
3940
|
-
insertNode(commentNode, parent, anchor, renderer);
|
|
3736
|
+
const { owner } = vnode;
|
|
3737
|
+
const { createComment } = renderer;
|
|
3738
|
+
const commentNode = (vnode.elm = createComment(vnode.text));
|
|
3739
|
+
linkNodeToShadow(commentNode, owner, renderer);
|
|
3740
|
+
insertNode(commentNode, parent, anchor, renderer);
|
|
3941
3741
|
}
|
|
3942
3742
|
function mountFragment(vnode, parent, anchor, renderer) {
|
|
3943
|
-
|
|
3944
|
-
children
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
// children of a fragment will always have at least the two delimiters.
|
|
3948
|
-
vnode.elm = children[children.length - 1].elm;
|
|
3743
|
+
const { children } = vnode;
|
|
3744
|
+
mountVNodes(children, parent, renderer, anchor);
|
|
3745
|
+
// children of a fragment will always have at least the two delimiters.
|
|
3746
|
+
vnode.elm = children[children.length - 1].elm;
|
|
3949
3747
|
}
|
|
3950
3748
|
function patchFragment(n1, n2, parent, renderer) {
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
// Note: not reusing n1.elm, because during patching, it may be patched with another text node.
|
|
3961
|
-
n2.elm = children[children.length - 1].elm;
|
|
3749
|
+
const { children, stable } = n2;
|
|
3750
|
+
if (stable) {
|
|
3751
|
+
updateStaticChildren(n1.children, children, parent, renderer);
|
|
3752
|
+
}
|
|
3753
|
+
else {
|
|
3754
|
+
updateDynamicChildren(n1.children, children, parent, renderer);
|
|
3755
|
+
}
|
|
3756
|
+
// Note: not reusing n1.elm, because during patching, it may be patched with another text node.
|
|
3757
|
+
n2.elm = children[children.length - 1].elm;
|
|
3962
3758
|
}
|
|
3963
3759
|
function mountElement(vnode, parent, anchor, renderer) {
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
const elm = vnode.elm = createElement(sel, namespace);
|
|
3976
|
-
linkNodeToShadow(elm, owner, renderer);
|
|
3977
|
-
applyStyleScoping(elm, owner, renderer);
|
|
3978
|
-
applyDomManual(elm, vnode);
|
|
3979
|
-
applyElementRestrictions(elm, vnode);
|
|
3980
|
-
patchElementPropsAndAttrs$1(null, vnode, renderer);
|
|
3981
|
-
insertNode(elm, parent, anchor, renderer);
|
|
3982
|
-
mountVNodes(vnode.children, elm, renderer, null);
|
|
3760
|
+
const { sel, owner, data: { svg }, } = vnode;
|
|
3761
|
+
const { createElement } = renderer;
|
|
3762
|
+
const namespace = shared.isTrue(svg) ? shared.SVG_NAMESPACE : undefined;
|
|
3763
|
+
const elm = (vnode.elm = createElement(sel, namespace));
|
|
3764
|
+
linkNodeToShadow(elm, owner, renderer);
|
|
3765
|
+
applyStyleScoping(elm, owner, renderer);
|
|
3766
|
+
applyDomManual(elm, vnode);
|
|
3767
|
+
applyElementRestrictions(elm, vnode);
|
|
3768
|
+
patchElementPropsAndAttrs$1(null, vnode, renderer);
|
|
3769
|
+
insertNode(elm, parent, anchor, renderer);
|
|
3770
|
+
mountVNodes(vnode.children, elm, renderer, null);
|
|
3983
3771
|
}
|
|
3984
3772
|
function patchElement(n1, n2, renderer) {
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3773
|
+
const elm = (n2.elm = n1.elm);
|
|
3774
|
+
patchElementPropsAndAttrs$1(n1, n2, renderer);
|
|
3775
|
+
patchChildren(n1.children, n2.children, elm, renderer);
|
|
3988
3776
|
}
|
|
3989
3777
|
function mountStatic(vnode, parent, anchor, renderer) {
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
const {
|
|
4002
|
-
renderMode,
|
|
4003
|
-
shadowMode
|
|
4004
|
-
} = owner;
|
|
4005
|
-
if (isSyntheticShadowDefined) {
|
|
4006
|
-
if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
|
|
4007
|
-
elm[shared.KEY__SHADOW_STATIC] = true;
|
|
3778
|
+
const { owner } = vnode;
|
|
3779
|
+
const { cloneNode, isSyntheticShadowDefined } = renderer;
|
|
3780
|
+
const elm = (vnode.elm = cloneNode(vnode.fragment, true));
|
|
3781
|
+
linkNodeToShadow(elm, owner, renderer);
|
|
3782
|
+
applyElementRestrictions(elm, vnode);
|
|
3783
|
+
// Marks this node as Static to propagate the shadow resolver. must happen after elm is assigned to the proper shadow
|
|
3784
|
+
const { renderMode, shadowMode } = owner;
|
|
3785
|
+
if (isSyntheticShadowDefined) {
|
|
3786
|
+
if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
|
|
3787
|
+
elm[shared.KEY__SHADOW_STATIC] = true;
|
|
3788
|
+
}
|
|
4008
3789
|
}
|
|
4009
|
-
|
|
4010
|
-
insertNode(elm, parent, anchor, renderer);
|
|
3790
|
+
insertNode(elm, parent, anchor, renderer);
|
|
4011
3791
|
}
|
|
4012
3792
|
function mountCustomElement(vnode, parent, anchor, renderer) {
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
*/
|
|
4026
|
-
let vm;
|
|
4027
|
-
const upgradeCallback = elm => {
|
|
4028
|
-
// the custom element from the registry is expecting an upgrade callback
|
|
4029
|
-
vm = createViewModelHook(elm, vnode, renderer);
|
|
4030
|
-
};
|
|
4031
|
-
let connectedCallback;
|
|
4032
|
-
let disconnectedCallback;
|
|
4033
|
-
if (features.lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
|
|
4034
|
-
connectedCallback = elm => {
|
|
4035
|
-
connectRootElement(elm);
|
|
4036
|
-
};
|
|
4037
|
-
disconnectedCallback = elm => {
|
|
4038
|
-
disconnectRootElement(elm);
|
|
3793
|
+
const { sel, owner } = vnode;
|
|
3794
|
+
const { createCustomElement } = renderer;
|
|
3795
|
+
/**
|
|
3796
|
+
* Note: if the upgradable constructor does not expect, or throw when we new it
|
|
3797
|
+
* with a callback as the first argument, we could implement a more advanced
|
|
3798
|
+
* mechanism that only passes that argument if the constructor is known to be
|
|
3799
|
+
* an upgradable custom element.
|
|
3800
|
+
*/
|
|
3801
|
+
let vm;
|
|
3802
|
+
const upgradeCallback = (elm) => {
|
|
3803
|
+
// the custom element from the registry is expecting an upgrade callback
|
|
3804
|
+
vm = createViewModelHook(elm, vnode, renderer);
|
|
4039
3805
|
};
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
3806
|
+
let connectedCallback;
|
|
3807
|
+
let disconnectedCallback;
|
|
3808
|
+
if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
|
|
3809
|
+
connectedCallback = (elm) => {
|
|
3810
|
+
connectRootElement(elm);
|
|
3811
|
+
};
|
|
3812
|
+
disconnectedCallback = (elm) => {
|
|
3813
|
+
disconnectRootElement(elm);
|
|
3814
|
+
};
|
|
3815
|
+
}
|
|
3816
|
+
// Should never get a tag with upper case letter at this point; the compiler
|
|
3817
|
+
// should produce only tags with lowercase letters. However, the Java
|
|
3818
|
+
// compiler may generate tagnames with uppercase letters so - for backwards
|
|
3819
|
+
// compatibility, we lower case the tagname here.
|
|
3820
|
+
const normalizedTagname = sel.toLowerCase();
|
|
3821
|
+
const elm = createCustomElement(normalizedTagname, upgradeCallback, connectedCallback, disconnectedCallback);
|
|
3822
|
+
vnode.elm = elm;
|
|
3823
|
+
vnode.vm = vm;
|
|
3824
|
+
linkNodeToShadow(elm, owner, renderer);
|
|
3825
|
+
applyStyleScoping(elm, owner, renderer);
|
|
3826
|
+
if (vm) {
|
|
3827
|
+
allocateChildren(vnode, vm);
|
|
3828
|
+
}
|
|
3829
|
+
patchElementPropsAndAttrs$1(null, vnode, renderer);
|
|
3830
|
+
insertNode(elm, parent, anchor, renderer);
|
|
3831
|
+
if (vm) {
|
|
3832
|
+
if (process.env.IS_BROWSER) {
|
|
3833
|
+
if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
|
|
3834
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3835
|
+
// With synthetic lifecycle callbacks, it's possible for elements to be removed without the engine
|
|
3836
|
+
// noticing it (e.g. `appendChild` the same host element twice). This test ensures we don't regress.
|
|
3837
|
+
shared.assert.isTrue(vm.state === 0 /* VMState.created */, `${vm} cannot be recycled.`);
|
|
3838
|
+
}
|
|
3839
|
+
runConnectedCallback(vm);
|
|
3840
|
+
}
|
|
3841
|
+
}
|
|
3842
|
+
else {
|
|
3843
|
+
// On the server, we don't have native custom element lifecycle callbacks, so we must
|
|
3844
|
+
// manually invoke the connectedCallback for a child component.
|
|
3845
|
+
runConnectedCallback(vm);
|
|
3846
|
+
}
|
|
3847
|
+
}
|
|
3848
|
+
mountVNodes(vnode.children, elm, renderer, null);
|
|
3849
|
+
if (vm) {
|
|
3850
|
+
appendVM(vm);
|
|
3851
|
+
}
|
|
4076
3852
|
}
|
|
4077
3853
|
function patchCustomElement(n1, n2, parent, renderer) {
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
3854
|
+
if (n1.ctor !== n2.ctor) {
|
|
3855
|
+
// If the constructor, unmount the current component and mount a new one using the new
|
|
3856
|
+
// constructor.
|
|
3857
|
+
const anchor = renderer.nextSibling(n1.elm);
|
|
3858
|
+
unmount(n1, parent, renderer, true);
|
|
3859
|
+
mountCustomElement(n2, parent, anchor, renderer);
|
|
3860
|
+
}
|
|
3861
|
+
else {
|
|
3862
|
+
// Otherwise patch the existing component with new props/attrs/etc.
|
|
3863
|
+
const elm = (n2.elm = n1.elm);
|
|
3864
|
+
const vm = (n2.vm = n1.vm);
|
|
3865
|
+
patchElementPropsAndAttrs$1(n1, n2, renderer);
|
|
3866
|
+
if (!shared.isUndefined(vm)) {
|
|
3867
|
+
// in fallback mode, the allocation will always set children to
|
|
3868
|
+
// empty and delegate the real allocation to the slot elements
|
|
3869
|
+
allocateChildren(n2, vm);
|
|
3870
|
+
// Solves an edge case with slotted VFragments in native shadow mode.
|
|
3871
|
+
//
|
|
3872
|
+
// During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
|
|
3873
|
+
// to avoid interfering with native slot behavior. When this happens, if any of the fragments
|
|
3874
|
+
// were not stable, the children must go through the dynamic diffing algo.
|
|
3875
|
+
//
|
|
3876
|
+
// If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
|
|
3877
|
+
// the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
|
|
3878
|
+
// nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
|
|
3879
|
+
// mark the new children dynamic.
|
|
3880
|
+
//
|
|
3881
|
+
// Example:
|
|
3882
|
+
// n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
|
|
3883
|
+
// n2.children: [div, null, div] => [div, null, div] // marked ???
|
|
3884
|
+
const { shadowMode, renderMode } = vm;
|
|
3885
|
+
if (shadowMode == 0 /* ShadowMode.Native */ &&
|
|
3886
|
+
renderMode !== 0 /* RenderMode.Light */ &&
|
|
3887
|
+
hasDynamicChildren(n1.children)) {
|
|
3888
|
+
// No-op if children has already been marked dynamic by 'allocateChildren()'.
|
|
3889
|
+
markAsDynamicChildren(n2.children);
|
|
3890
|
+
}
|
|
3891
|
+
}
|
|
3892
|
+
// in fallback mode, the children will be always empty, so, nothing
|
|
3893
|
+
// will happen, but in native, it does allocate the light dom
|
|
3894
|
+
patchChildren(n1.children, n2.children, elm, renderer);
|
|
3895
|
+
if (!shared.isUndefined(vm)) {
|
|
3896
|
+
// this will probably update the shadowRoot, but only if the vm is in a dirty state
|
|
3897
|
+
// this is important to preserve the top to bottom synchronous rendering phase.
|
|
3898
|
+
rerenderVM(vm);
|
|
3899
|
+
}
|
|
4123
3900
|
}
|
|
4124
|
-
}
|
|
4125
3901
|
}
|
|
4126
3902
|
function mountVNodes(vnodes, parent, renderer, anchor, start = 0, end = vnodes.length) {
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
3903
|
+
for (; start < end; ++start) {
|
|
3904
|
+
const vnode = vnodes[start];
|
|
3905
|
+
if (isVNode(vnode)) {
|
|
3906
|
+
mount(vnode, parent, renderer, anchor);
|
|
3907
|
+
}
|
|
4131
3908
|
}
|
|
4132
|
-
}
|
|
4133
3909
|
}
|
|
4134
3910
|
function unmount(vnode, parent, renderer, doRemove = false) {
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
// The vnode might or might not have a data.renderer associated to it
|
|
4147
|
-
// but the removal used here is from the owner instead.
|
|
4148
|
-
removeNode(elm, parent, renderer);
|
|
4149
|
-
}
|
|
4150
|
-
}
|
|
4151
|
-
switch (type) {
|
|
4152
|
-
case 2 /* VNodeType.Element */:
|
|
4153
|
-
{
|
|
4154
|
-
// Slot content is removed to trigger slotchange event when removing slot.
|
|
4155
|
-
// Only required for synthetic shadow.
|
|
4156
|
-
const shouldRemoveChildren = sel === 'slot' && vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
|
|
4157
|
-
unmountVNodes(vnode.children, elm, renderer, shouldRemoveChildren);
|
|
4158
|
-
break;
|
|
4159
|
-
}
|
|
4160
|
-
case 3 /* VNodeType.CustomElement */:
|
|
4161
|
-
{
|
|
4162
|
-
const {
|
|
4163
|
-
vm
|
|
4164
|
-
} = vnode;
|
|
4165
|
-
// No need to unmount the children here, `removeVM` will take care of removing the
|
|
4166
|
-
// children.
|
|
4167
|
-
if (!shared.isUndefined(vm)) {
|
|
4168
|
-
removeVM(vm);
|
|
3911
|
+
const { type, elm, sel } = vnode;
|
|
3912
|
+
// When unmounting a VNode subtree not all the elements have to removed from the DOM. The
|
|
3913
|
+
// subtree root, is the only element worth unmounting from the subtree.
|
|
3914
|
+
if (doRemove) {
|
|
3915
|
+
if (type === 5 /* VNodeType.Fragment */) {
|
|
3916
|
+
unmountVNodes(vnode.children, parent, renderer, doRemove);
|
|
3917
|
+
}
|
|
3918
|
+
else {
|
|
3919
|
+
// The vnode might or might not have a data.renderer associated to it
|
|
3920
|
+
// but the removal used here is from the owner instead.
|
|
3921
|
+
removeNode(elm, parent, renderer);
|
|
4169
3922
|
}
|
|
4170
|
-
|
|
4171
|
-
|
|
3923
|
+
}
|
|
3924
|
+
switch (type) {
|
|
3925
|
+
case 2 /* VNodeType.Element */: {
|
|
3926
|
+
// Slot content is removed to trigger slotchange event when removing slot.
|
|
3927
|
+
// Only required for synthetic shadow.
|
|
3928
|
+
const shouldRemoveChildren = sel === 'slot' && vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
|
|
3929
|
+
unmountVNodes(vnode.children, elm, renderer, shouldRemoveChildren);
|
|
3930
|
+
break;
|
|
3931
|
+
}
|
|
3932
|
+
case 3 /* VNodeType.CustomElement */: {
|
|
3933
|
+
const { vm } = vnode;
|
|
3934
|
+
// No need to unmount the children here, `removeVM` will take care of removing the
|
|
3935
|
+
// children.
|
|
3936
|
+
if (!shared.isUndefined(vm)) {
|
|
3937
|
+
removeVM(vm);
|
|
3938
|
+
}
|
|
3939
|
+
}
|
|
3940
|
+
}
|
|
4172
3941
|
}
|
|
4173
3942
|
function unmountVNodes(vnodes, parent, renderer, doRemove = false, start = 0, end = vnodes.length) {
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
3943
|
+
for (; start < end; ++start) {
|
|
3944
|
+
const ch = vnodes[start];
|
|
3945
|
+
if (isVNode(ch)) {
|
|
3946
|
+
unmount(ch, parent, renderer, doRemove);
|
|
3947
|
+
}
|
|
4178
3948
|
}
|
|
4179
|
-
}
|
|
4180
3949
|
}
|
|
4181
3950
|
function isVNode(vnode) {
|
|
4182
|
-
|
|
3951
|
+
return vnode != null;
|
|
4183
3952
|
}
|
|
4184
3953
|
function linkNodeToShadow(elm, owner, renderer) {
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
} = renderer;
|
|
4193
|
-
// TODO [#1164]: this should eventually be done by the polyfill directly
|
|
4194
|
-
if (isSyntheticShadowDefined) {
|
|
4195
|
-
if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
|
|
4196
|
-
elm[shared.KEY__SHADOW_RESOLVER] = renderRoot[shared.KEY__SHADOW_RESOLVER];
|
|
3954
|
+
const { renderRoot, renderMode, shadowMode } = owner;
|
|
3955
|
+
const { isSyntheticShadowDefined } = renderer;
|
|
3956
|
+
// TODO [#1164]: this should eventually be done by the polyfill directly
|
|
3957
|
+
if (isSyntheticShadowDefined) {
|
|
3958
|
+
if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
|
|
3959
|
+
elm[shared.KEY__SHADOW_RESOLVER] = renderRoot[shared.KEY__SHADOW_RESOLVER];
|
|
3960
|
+
}
|
|
4197
3961
|
}
|
|
4198
|
-
}
|
|
4199
3962
|
}
|
|
4200
3963
|
function updateTextContent(vnode, renderer) {
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
setText
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
}
|
|
4211
|
-
setText(elm, text);
|
|
4212
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
4213
|
-
lockDomMutation();
|
|
4214
|
-
}
|
|
3964
|
+
const { elm, text } = vnode;
|
|
3965
|
+
const { setText } = renderer;
|
|
3966
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3967
|
+
unlockDomMutation();
|
|
3968
|
+
}
|
|
3969
|
+
setText(elm, text);
|
|
3970
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3971
|
+
lockDomMutation();
|
|
3972
|
+
}
|
|
4215
3973
|
}
|
|
4216
3974
|
function insertNode(node, parent, anchor, renderer) {
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
3975
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3976
|
+
unlockDomMutation();
|
|
3977
|
+
}
|
|
3978
|
+
renderer.insert(node, parent, anchor);
|
|
3979
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3980
|
+
lockDomMutation();
|
|
3981
|
+
}
|
|
4224
3982
|
}
|
|
4225
3983
|
function removeNode(node, parent, renderer) {
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
3984
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3985
|
+
unlockDomMutation();
|
|
3986
|
+
}
|
|
3987
|
+
renderer.remove(node, parent);
|
|
3988
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3989
|
+
lockDomMutation();
|
|
3990
|
+
}
|
|
4233
3991
|
}
|
|
4234
3992
|
function patchElementPropsAndAttrs$1(oldVnode, vnode, renderer) {
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
3993
|
+
if (shared.isNull(oldVnode)) {
|
|
3994
|
+
applyEventListeners(vnode, renderer);
|
|
3995
|
+
applyStaticClassAttribute(vnode, renderer);
|
|
3996
|
+
applyStaticStyleAttribute(vnode, renderer);
|
|
3997
|
+
}
|
|
3998
|
+
// Attrs need to be applied to element before props IE11 will wipe out value on radio inputs if
|
|
3999
|
+
// value is set before type=radio.
|
|
4000
|
+
patchClassAttribute(oldVnode, vnode, renderer);
|
|
4001
|
+
patchStyleAttribute(oldVnode, vnode, renderer);
|
|
4002
|
+
if (vnode.data.external) {
|
|
4003
|
+
patchAttrUnlessProp(oldVnode, vnode, renderer);
|
|
4004
|
+
}
|
|
4005
|
+
else {
|
|
4006
|
+
patchAttributes(oldVnode, vnode, renderer);
|
|
4007
|
+
}
|
|
4008
|
+
patchProps(oldVnode, vnode, renderer);
|
|
4250
4009
|
}
|
|
4251
4010
|
function applyStyleScoping(elm, owner, renderer) {
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
} = owner.context;
|
|
4266
|
-
if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && !shared.isUndefined(syntheticToken)) {
|
|
4267
|
-
elm.$shadowToken$ = syntheticToken;
|
|
4268
|
-
}
|
|
4011
|
+
// Set the class name for `*.scoped.css` style scoping.
|
|
4012
|
+
const scopeToken = getScopeTokenClass(owner);
|
|
4013
|
+
if (!shared.isNull(scopeToken)) {
|
|
4014
|
+
const { getClassList } = renderer;
|
|
4015
|
+
// TODO [#2762]: this dot notation with add is probably problematic
|
|
4016
|
+
// probably we should have a renderer api for just the add operation
|
|
4017
|
+
getClassList(elm).add(scopeToken);
|
|
4018
|
+
}
|
|
4019
|
+
// Set property element for synthetic shadow DOM style scoping.
|
|
4020
|
+
const { stylesheetToken: syntheticToken } = owner.context;
|
|
4021
|
+
if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && !shared.isUndefined(syntheticToken)) {
|
|
4022
|
+
elm.$shadowToken$ = syntheticToken;
|
|
4023
|
+
}
|
|
4269
4024
|
}
|
|
4270
4025
|
function applyDomManual(elm, vnode) {
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
owner
|
|
4274
|
-
|
|
4275
|
-
context
|
|
4026
|
+
var _a;
|
|
4027
|
+
const { owner, data: { context }, } = vnode;
|
|
4028
|
+
if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && ((_a = context === null || context === void 0 ? void 0 : context.lwc) === null || _a === void 0 ? void 0 : _a.dom) === "manual" /* LwcDomMode.Manual */) {
|
|
4029
|
+
elm.$domManual$ = true;
|
|
4276
4030
|
}
|
|
4277
|
-
} = vnode;
|
|
4278
|
-
if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && ((_a = context === null || context === void 0 ? void 0 : context.lwc) === null || _a === void 0 ? void 0 : _a.dom) === "manual" /* LwcDomMode.Manual */) {
|
|
4279
|
-
elm.$domManual$ = true;
|
|
4280
|
-
}
|
|
4281
4031
|
}
|
|
4282
4032
|
function applyElementRestrictions(elm, vnode) {
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4033
|
+
var _a, _b;
|
|
4034
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
4035
|
+
const isSynthetic = vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
|
|
4036
|
+
const isPortal = vnode.type === 2 /* VNodeType.Element */ && ((_b = (_a = vnode.data.context) === null || _a === void 0 ? void 0 : _a.lwc) === null || _b === void 0 ? void 0 : _b.dom) === "manual" /* LwcDomMode.Manual */;
|
|
4037
|
+
const isLight = vnode.owner.renderMode === 0 /* RenderMode.Light */;
|
|
4038
|
+
patchElementWithRestrictions(elm, {
|
|
4039
|
+
isPortal,
|
|
4040
|
+
isLight,
|
|
4041
|
+
isSynthetic,
|
|
4042
|
+
});
|
|
4043
|
+
}
|
|
4294
4044
|
}
|
|
4295
4045
|
function allocateChildren(vnode, vm) {
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
vnode.children = EmptyArray;
|
|
4331
|
-
}
|
|
4046
|
+
// A component with slots will re-render because:
|
|
4047
|
+
// 1- There is a change of the internal state.
|
|
4048
|
+
// 2- There is a change on the external api (ex: slots)
|
|
4049
|
+
//
|
|
4050
|
+
// In case #1, the vnodes in the cmpSlots will be reused since they didn't changed. This routine emptied the
|
|
4051
|
+
// slotted children when those VCustomElement were rendered and therefore in subsequent calls to allocate children
|
|
4052
|
+
// in a reused VCustomElement, there won't be any slotted children.
|
|
4053
|
+
// For those cases, we will use the reference for allocated children stored when rendering the fresh VCustomElement.
|
|
4054
|
+
//
|
|
4055
|
+
// In case #2, we will always get a fresh VCustomElement.
|
|
4056
|
+
const children = vnode.aChildren || vnode.children;
|
|
4057
|
+
const { renderMode, shadowMode } = vm;
|
|
4058
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
4059
|
+
// If any of the children being allocated is a scoped slot fragment, make sure the receiving
|
|
4060
|
+
// component is a light DOM component. This is mainly to validate light dom parent running
|
|
4061
|
+
// in native shadow mode.
|
|
4062
|
+
if (renderMode !== 0 /* RenderMode.Light */ &&
|
|
4063
|
+
shared.ArraySome.call(children, (child) => !shared.isNull(child) && isVScopedSlotFragment(child))) {
|
|
4064
|
+
logError(`Invalid usage of 'lwc:slot-data' on ${getComponentTag(vm)} tag. Scoped slot content can only be passed to a light dom child.`);
|
|
4065
|
+
}
|
|
4066
|
+
}
|
|
4067
|
+
// If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
|
|
4068
|
+
// children VFragments to avoid them interfering with default slot behavior.
|
|
4069
|
+
const allocatedChildren = flattenFragmentsInChildren(children);
|
|
4070
|
+
vnode.children = allocatedChildren;
|
|
4071
|
+
vm.aChildren = allocatedChildren;
|
|
4072
|
+
if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
|
|
4073
|
+
// slow path
|
|
4074
|
+
allocateInSlot(vm, allocatedChildren, vnode.owner);
|
|
4075
|
+
// save the allocated children in case this vnode is reused.
|
|
4076
|
+
vnode.aChildren = allocatedChildren;
|
|
4077
|
+
// every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
|
|
4078
|
+
vnode.children = EmptyArray;
|
|
4079
|
+
}
|
|
4332
4080
|
}
|
|
4333
4081
|
/**
|
|
4334
4082
|
* Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
|
|
@@ -4340,275 +4088,278 @@ function allocateChildren(vnode, vm) {
|
|
|
4340
4088
|
* This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
|
|
4341
4089
|
*/
|
|
4342
4090
|
function flattenFragmentsInChildren(children) {
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4091
|
+
const flattenedChildren = [];
|
|
4092
|
+
// Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
|
|
4093
|
+
// If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
|
|
4094
|
+
const nodeStack = [];
|
|
4095
|
+
let fragmentFound = false;
|
|
4096
|
+
for (let i = children.length - 1; i > -1; i -= 1) {
|
|
4097
|
+
const child = children[i];
|
|
4098
|
+
shared.ArrayPush.call(nodeStack, child);
|
|
4099
|
+
fragmentFound = fragmentFound || !!(child && isVFragment(child));
|
|
4100
|
+
}
|
|
4101
|
+
if (!fragmentFound) {
|
|
4102
|
+
return children;
|
|
4103
|
+
}
|
|
4104
|
+
let currentNode;
|
|
4105
|
+
while (!shared.isUndefined((currentNode = shared.ArrayPop.call(nodeStack)))) {
|
|
4106
|
+
if (!shared.isNull(currentNode) && isVFragment(currentNode)) {
|
|
4107
|
+
const fChildren = currentNode.children;
|
|
4108
|
+
// Ignore the start and end text node delimiters
|
|
4109
|
+
for (let i = fChildren.length - 2; i > 0; i -= 1) {
|
|
4110
|
+
shared.ArrayPush.call(nodeStack, fChildren[i]);
|
|
4111
|
+
}
|
|
4112
|
+
}
|
|
4113
|
+
else {
|
|
4114
|
+
shared.ArrayPush.call(flattenedChildren, currentNode);
|
|
4115
|
+
}
|
|
4116
|
+
}
|
|
4117
|
+
// We always mark the children as dynamic because nothing generates stable VFragments yet.
|
|
4118
|
+
// If/when stable VFragments are generated by the compiler, this code should be updated to
|
|
4119
|
+
// not mark dynamic if all flattened VFragments were stable.
|
|
4120
|
+
markAsDynamicChildren(flattenedChildren);
|
|
4121
|
+
return flattenedChildren;
|
|
4373
4122
|
}
|
|
4374
4123
|
function createViewModelHook(elm, vnode, renderer) {
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4124
|
+
let vm = getAssociatedVMIfPresent(elm);
|
|
4125
|
+
// There is a possibility that a custom element is registered under tagName, in which case, the
|
|
4126
|
+
// initialization is already carry on, and there is nothing else to do here since this hook is
|
|
4127
|
+
// called right after invoking `document.createElement`.
|
|
4128
|
+
if (!shared.isUndefined(vm)) {
|
|
4129
|
+
return vm;
|
|
4130
|
+
}
|
|
4131
|
+
const { sel, mode, ctor, owner } = vnode;
|
|
4132
|
+
vm = createVM(elm, ctor, renderer, {
|
|
4133
|
+
mode,
|
|
4134
|
+
owner,
|
|
4135
|
+
tagName: sel,
|
|
4136
|
+
});
|
|
4137
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
4138
|
+
shared.assert.isTrue(shared.isArray(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
|
|
4139
|
+
}
|
|
4380
4140
|
return vm;
|
|
4381
|
-
}
|
|
4382
|
-
const {
|
|
4383
|
-
sel,
|
|
4384
|
-
mode,
|
|
4385
|
-
ctor,
|
|
4386
|
-
owner
|
|
4387
|
-
} = vnode;
|
|
4388
|
-
vm = createVM(elm, ctor, renderer, {
|
|
4389
|
-
mode,
|
|
4390
|
-
owner,
|
|
4391
|
-
tagName: sel
|
|
4392
|
-
});
|
|
4393
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
4394
|
-
shared.assert.isTrue(shared.isArray(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
|
|
4395
|
-
}
|
|
4396
|
-
return vm;
|
|
4397
4141
|
}
|
|
4398
4142
|
function allocateInSlot(vm, children, owner) {
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
markComponentAsDirty(vm);
|
|
4449
|
-
return;
|
|
4143
|
+
var _a, _b;
|
|
4144
|
+
const { cmpSlots: { slotAssignments: oldSlotsMapping }, } = vm;
|
|
4145
|
+
const cmpSlotsMapping = shared.create(null);
|
|
4146
|
+
// Collect all slots into cmpSlotsMapping
|
|
4147
|
+
for (let i = 0, len = children.length; i < len; i += 1) {
|
|
4148
|
+
const vnode = children[i];
|
|
4149
|
+
if (shared.isNull(vnode)) {
|
|
4150
|
+
continue;
|
|
4151
|
+
}
|
|
4152
|
+
let slotName = '';
|
|
4153
|
+
if (isVBaseElement(vnode)) {
|
|
4154
|
+
slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
|
|
4155
|
+
}
|
|
4156
|
+
else if (isVScopedSlotFragment(vnode)) {
|
|
4157
|
+
slotName = vnode.slotName;
|
|
4158
|
+
}
|
|
4159
|
+
// Can't use toString here because Symbol(1).toString() is 'Symbol(1)'
|
|
4160
|
+
// but elm.setAttribute('slot', Symbol(1)) is an error.
|
|
4161
|
+
// the following line also throws same error for symbols
|
|
4162
|
+
// Similar for Object.create(null)
|
|
4163
|
+
const normalizedSlotName = '' + slotName;
|
|
4164
|
+
const vnodes = (cmpSlotsMapping[normalizedSlotName] =
|
|
4165
|
+
cmpSlotsMapping[normalizedSlotName] || []);
|
|
4166
|
+
shared.ArrayPush.call(vnodes, vnode);
|
|
4167
|
+
}
|
|
4168
|
+
vm.cmpSlots = { owner, slotAssignments: cmpSlotsMapping };
|
|
4169
|
+
if (shared.isFalse(vm.isDirty)) {
|
|
4170
|
+
// We need to determine if the old allocation is really different from the new one
|
|
4171
|
+
// and mark the vm as dirty
|
|
4172
|
+
const oldKeys = shared.keys(oldSlotsMapping);
|
|
4173
|
+
if (oldKeys.length !== shared.keys(cmpSlotsMapping).length) {
|
|
4174
|
+
markComponentAsDirty(vm);
|
|
4175
|
+
return;
|
|
4176
|
+
}
|
|
4177
|
+
for (let i = 0, len = oldKeys.length; i < len; i += 1) {
|
|
4178
|
+
const key = oldKeys[i];
|
|
4179
|
+
if (shared.isUndefined(cmpSlotsMapping[key]) ||
|
|
4180
|
+
oldSlotsMapping[key].length !== cmpSlotsMapping[key].length) {
|
|
4181
|
+
markComponentAsDirty(vm);
|
|
4182
|
+
return;
|
|
4183
|
+
}
|
|
4184
|
+
const oldVNodes = oldSlotsMapping[key];
|
|
4185
|
+
const vnodes = cmpSlotsMapping[key];
|
|
4186
|
+
for (let j = 0, a = cmpSlotsMapping[key].length; j < a; j += 1) {
|
|
4187
|
+
if (oldVNodes[j] !== vnodes[j]) {
|
|
4188
|
+
markComponentAsDirty(vm);
|
|
4189
|
+
return;
|
|
4190
|
+
}
|
|
4191
|
+
}
|
|
4450
4192
|
}
|
|
4451
|
-
}
|
|
4452
4193
|
}
|
|
4453
|
-
}
|
|
4454
4194
|
}
|
|
4455
4195
|
// Using a WeakMap instead of a WeakSet because this one works in IE11 :(
|
|
4456
4196
|
const DynamicChildren = new WeakMap();
|
|
4457
4197
|
// dynamic children means it was either generated by an iteration in a template
|
|
4458
4198
|
// or part of an unstable fragment, and will require a more complex diffing algo.
|
|
4459
4199
|
function markAsDynamicChildren(children) {
|
|
4460
|
-
|
|
4200
|
+
DynamicChildren.set(children, 1);
|
|
4461
4201
|
}
|
|
4462
4202
|
function hasDynamicChildren(children) {
|
|
4463
|
-
|
|
4203
|
+
return DynamicChildren.has(children);
|
|
4464
4204
|
}
|
|
4465
4205
|
function createKeyToOldIdx(children, beginIdx, endIdx) {
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
}
|
|
4479
|
-
return map;
|
|
4206
|
+
const map = {};
|
|
4207
|
+
// TODO [#1637]: simplify this by assuming that all vnodes has keys
|
|
4208
|
+
for (let j = beginIdx; j <= endIdx; ++j) {
|
|
4209
|
+
const ch = children[j];
|
|
4210
|
+
if (isVNode(ch)) {
|
|
4211
|
+
const { key } = ch;
|
|
4212
|
+
if (key !== undefined) {
|
|
4213
|
+
map[key] = j;
|
|
4214
|
+
}
|
|
4215
|
+
}
|
|
4216
|
+
}
|
|
4217
|
+
return map;
|
|
4480
4218
|
}
|
|
4481
4219
|
function updateDynamicChildren(oldCh, newCh, parent, renderer) {
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
if (isVNode(elmToMove)) {
|
|
4537
|
-
if (elmToMove.sel !== newStartVnode.sel) {
|
|
4538
|
-
// New element
|
|
4539
|
-
mount(newStartVnode, parent, renderer, oldStartVnode.elm);
|
|
4540
|
-
} else {
|
|
4541
|
-
patch(elmToMove, newStartVnode, parent, renderer);
|
|
4542
|
-
// Delete the old child, but copy the array since it is read-only.
|
|
4543
|
-
// The `oldCh` will be GC'ed after `updateDynamicChildren` is complete,
|
|
4544
|
-
// so we only care about the `oldCh` object inside this function.
|
|
4545
|
-
// To avoid cloning over and over again, we check `clonedOldCh`
|
|
4546
|
-
// and only clone once.
|
|
4547
|
-
if (!clonedOldCh) {
|
|
4548
|
-
clonedOldCh = true;
|
|
4549
|
-
oldCh = [...oldCh];
|
|
4220
|
+
let oldStartIdx = 0;
|
|
4221
|
+
let newStartIdx = 0;
|
|
4222
|
+
let oldEndIdx = oldCh.length - 1;
|
|
4223
|
+
let oldStartVnode = oldCh[0];
|
|
4224
|
+
let oldEndVnode = oldCh[oldEndIdx];
|
|
4225
|
+
const newChEnd = newCh.length - 1;
|
|
4226
|
+
let newEndIdx = newChEnd;
|
|
4227
|
+
let newStartVnode = newCh[0];
|
|
4228
|
+
let newEndVnode = newCh[newEndIdx];
|
|
4229
|
+
let oldKeyToIdx;
|
|
4230
|
+
let idxInOld;
|
|
4231
|
+
let elmToMove;
|
|
4232
|
+
let before;
|
|
4233
|
+
let clonedOldCh = false;
|
|
4234
|
+
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
|
4235
|
+
if (!isVNode(oldStartVnode)) {
|
|
4236
|
+
oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
|
|
4237
|
+
}
|
|
4238
|
+
else if (!isVNode(oldEndVnode)) {
|
|
4239
|
+
oldEndVnode = oldCh[--oldEndIdx];
|
|
4240
|
+
}
|
|
4241
|
+
else if (!isVNode(newStartVnode)) {
|
|
4242
|
+
newStartVnode = newCh[++newStartIdx];
|
|
4243
|
+
}
|
|
4244
|
+
else if (!isVNode(newEndVnode)) {
|
|
4245
|
+
newEndVnode = newCh[--newEndIdx];
|
|
4246
|
+
}
|
|
4247
|
+
else if (isSameVnode(oldStartVnode, newStartVnode)) {
|
|
4248
|
+
patch(oldStartVnode, newStartVnode, parent, renderer);
|
|
4249
|
+
oldStartVnode = oldCh[++oldStartIdx];
|
|
4250
|
+
newStartVnode = newCh[++newStartIdx];
|
|
4251
|
+
}
|
|
4252
|
+
else if (isSameVnode(oldEndVnode, newEndVnode)) {
|
|
4253
|
+
patch(oldEndVnode, newEndVnode, parent, renderer);
|
|
4254
|
+
oldEndVnode = oldCh[--oldEndIdx];
|
|
4255
|
+
newEndVnode = newCh[--newEndIdx];
|
|
4256
|
+
}
|
|
4257
|
+
else if (isSameVnode(oldStartVnode, newEndVnode)) {
|
|
4258
|
+
// Vnode moved right
|
|
4259
|
+
patch(oldStartVnode, newEndVnode, parent, renderer);
|
|
4260
|
+
insertNode(oldStartVnode.elm, parent, renderer.nextSibling(oldEndVnode.elm), renderer);
|
|
4261
|
+
oldStartVnode = oldCh[++oldStartIdx];
|
|
4262
|
+
newEndVnode = newCh[--newEndIdx];
|
|
4263
|
+
}
|
|
4264
|
+
else if (isSameVnode(oldEndVnode, newStartVnode)) {
|
|
4265
|
+
// Vnode moved left
|
|
4266
|
+
patch(oldEndVnode, newStartVnode, parent, renderer);
|
|
4267
|
+
insertNode(newStartVnode.elm, parent, oldStartVnode.elm, renderer);
|
|
4268
|
+
oldEndVnode = oldCh[--oldEndIdx];
|
|
4269
|
+
newStartVnode = newCh[++newStartIdx];
|
|
4270
|
+
}
|
|
4271
|
+
else {
|
|
4272
|
+
if (oldKeyToIdx === undefined) {
|
|
4273
|
+
oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
|
|
4550
4274
|
}
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4275
|
+
idxInOld = oldKeyToIdx[newStartVnode.key];
|
|
4276
|
+
if (shared.isUndefined(idxInOld)) {
|
|
4277
|
+
// New element
|
|
4278
|
+
mount(newStartVnode, parent, renderer, oldStartVnode.elm);
|
|
4279
|
+
newStartVnode = newCh[++newStartIdx];
|
|
4280
|
+
}
|
|
4281
|
+
else {
|
|
4282
|
+
elmToMove = oldCh[idxInOld];
|
|
4283
|
+
if (isVNode(elmToMove)) {
|
|
4284
|
+
if (elmToMove.sel !== newStartVnode.sel) {
|
|
4285
|
+
// New element
|
|
4286
|
+
mount(newStartVnode, parent, renderer, oldStartVnode.elm);
|
|
4287
|
+
}
|
|
4288
|
+
else {
|
|
4289
|
+
patch(elmToMove, newStartVnode, parent, renderer);
|
|
4290
|
+
// Delete the old child, but copy the array since it is read-only.
|
|
4291
|
+
// The `oldCh` will be GC'ed after `updateDynamicChildren` is complete,
|
|
4292
|
+
// so we only care about the `oldCh` object inside this function.
|
|
4293
|
+
// To avoid cloning over and over again, we check `clonedOldCh`
|
|
4294
|
+
// and only clone once.
|
|
4295
|
+
if (!clonedOldCh) {
|
|
4296
|
+
clonedOldCh = true;
|
|
4297
|
+
oldCh = [...oldCh];
|
|
4298
|
+
}
|
|
4299
|
+
// We've already cloned at least once, so it's no longer read-only
|
|
4300
|
+
oldCh[idxInOld] = undefined;
|
|
4301
|
+
insertNode(elmToMove.elm, parent, oldStartVnode.elm, renderer);
|
|
4302
|
+
}
|
|
4303
|
+
}
|
|
4304
|
+
newStartVnode = newCh[++newStartIdx];
|
|
4305
|
+
}
|
|
4306
|
+
}
|
|
4307
|
+
}
|
|
4308
|
+
if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
|
|
4309
|
+
if (oldStartIdx > oldEndIdx) {
|
|
4310
|
+
// There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
|
|
4311
|
+
// already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
|
|
4312
|
+
let i = newEndIdx;
|
|
4313
|
+
let n;
|
|
4314
|
+
do {
|
|
4315
|
+
n = newCh[++i];
|
|
4316
|
+
} while (!isVNode(n) && i < newChEnd);
|
|
4317
|
+
before = isVNode(n) ? n.elm : null;
|
|
4318
|
+
mountVNodes(newCh, parent, renderer, before, newStartIdx, newEndIdx + 1);
|
|
4319
|
+
}
|
|
4320
|
+
else {
|
|
4321
|
+
unmountVNodes(oldCh, parent, renderer, true, oldStartIdx, oldEndIdx + 1);
|
|
4322
|
+
}
|
|
4323
|
+
}
|
|
4575
4324
|
}
|
|
4576
4325
|
function updateStaticChildren(c1, c2, parent, renderer) {
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4326
|
+
const c1Length = c1.length;
|
|
4327
|
+
const c2Length = c2.length;
|
|
4328
|
+
if (c1Length === 0) {
|
|
4329
|
+
// the old list is empty, we can directly insert anything new
|
|
4330
|
+
mountVNodes(c2, parent, renderer, null);
|
|
4331
|
+
return;
|
|
4332
|
+
}
|
|
4333
|
+
if (c2Length === 0) {
|
|
4334
|
+
// the old list is nonempty and the new list is empty so we can directly remove all old nodes
|
|
4335
|
+
// this is the case in which the dynamic children of an if-directive should be removed
|
|
4336
|
+
unmountVNodes(c1, parent, renderer, true);
|
|
4337
|
+
return;
|
|
4338
|
+
}
|
|
4339
|
+
// if the old list is not empty, the new list MUST have the same
|
|
4340
|
+
// amount of nodes, that's why we call this static children
|
|
4341
|
+
let anchor = null;
|
|
4342
|
+
for (let i = c2Length - 1; i >= 0; i -= 1) {
|
|
4343
|
+
const n1 = c1[i];
|
|
4344
|
+
const n2 = c2[i];
|
|
4345
|
+
if (n2 !== n1) {
|
|
4346
|
+
if (isVNode(n1)) {
|
|
4347
|
+
if (isVNode(n2)) {
|
|
4348
|
+
// both vnodes are equivalent, and we just need to patch them
|
|
4349
|
+
patch(n1, n2, parent, renderer);
|
|
4350
|
+
anchor = n2.elm;
|
|
4351
|
+
}
|
|
4352
|
+
else {
|
|
4353
|
+
// removing the old vnode since the new one is null
|
|
4354
|
+
unmount(n1, parent, renderer, true);
|
|
4355
|
+
}
|
|
4356
|
+
}
|
|
4357
|
+
else if (isVNode(n2)) {
|
|
4358
|
+
mount(n2, parent, renderer, anchor);
|
|
4359
|
+
anchor = n2.elm;
|
|
4360
|
+
}
|
|
4361
|
+
}
|
|
4362
|
+
}
|
|
4612
4363
|
}
|
|
4613
4364
|
|
|
4614
4365
|
/*
|
|
@@ -5590,455 +5341,417 @@ let idx = 0;
|
|
|
5590
5341
|
/** The internal slot used to associate different objects the engine manipulates with the VM */
|
|
5591
5342
|
const ViewModelReflection = new WeakMap();
|
|
5592
5343
|
function callHook(cmp, fn, args = []) {
|
|
5593
|
-
|
|
5344
|
+
return fn.apply(cmp, args);
|
|
5594
5345
|
}
|
|
5595
5346
|
function setHook(cmp, prop, newValue) {
|
|
5596
|
-
|
|
5347
|
+
cmp[prop] = newValue;
|
|
5597
5348
|
}
|
|
5598
5349
|
function getHook(cmp, prop) {
|
|
5599
|
-
|
|
5350
|
+
return cmp[prop];
|
|
5600
5351
|
}
|
|
5601
5352
|
function rerenderVM(vm) {
|
|
5602
|
-
|
|
5353
|
+
rehydrate(vm);
|
|
5603
5354
|
}
|
|
5604
5355
|
function connectRootElement(elm) {
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5356
|
+
const vm = getAssociatedVM(elm);
|
|
5357
|
+
logGlobalOperationStart(7 /* OperationId.GlobalHydrate */, vm);
|
|
5358
|
+
// Usually means moving the element from one place to another, which is observable via
|
|
5359
|
+
// life-cycle hooks.
|
|
5360
|
+
if (vm.state === 1 /* VMState.connected */) {
|
|
5361
|
+
disconnectRootElement(elm);
|
|
5362
|
+
}
|
|
5363
|
+
runConnectedCallback(vm);
|
|
5364
|
+
rehydrate(vm);
|
|
5365
|
+
logGlobalOperationEnd(7 /* OperationId.GlobalHydrate */, vm);
|
|
5615
5366
|
}
|
|
5616
5367
|
function disconnectRootElement(elm) {
|
|
5617
|
-
|
|
5618
|
-
|
|
5368
|
+
const vm = getAssociatedVM(elm);
|
|
5369
|
+
resetComponentStateWhenRemoved(vm);
|
|
5619
5370
|
}
|
|
5620
5371
|
function appendVM(vm) {
|
|
5621
|
-
|
|
5372
|
+
rehydrate(vm);
|
|
5622
5373
|
}
|
|
5623
5374
|
// just in case the component comes back, with this we guarantee re-rendering it
|
|
5624
5375
|
// while preventing any attempt to rehydration until after reinsertion.
|
|
5625
5376
|
function resetComponentStateWhenRemoved(vm) {
|
|
5626
|
-
|
|
5627
|
-
state
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
|
|
5639
|
-
}
|
|
5640
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
5641
|
-
removeActiveVM(vm);
|
|
5642
|
-
}
|
|
5377
|
+
const { state } = vm;
|
|
5378
|
+
if (state !== 2 /* VMState.disconnected */) {
|
|
5379
|
+
const { tro } = vm;
|
|
5380
|
+
// Making sure that any observing record will not trigger the rehydrated on this vm
|
|
5381
|
+
tro.reset();
|
|
5382
|
+
runDisconnectedCallback(vm);
|
|
5383
|
+
// Spec: https://dom.spec.whatwg.org/#concept-node-remove (step 14-15)
|
|
5384
|
+
runChildNodesDisconnectedCallback(vm);
|
|
5385
|
+
runLightChildNodesDisconnectedCallback(vm);
|
|
5386
|
+
}
|
|
5387
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5388
|
+
removeActiveVM(vm);
|
|
5389
|
+
}
|
|
5643
5390
|
}
|
|
5644
5391
|
// this method is triggered by the diffing algo only when a vnode from the
|
|
5645
5392
|
// old vnode.children is removed from the DOM.
|
|
5646
5393
|
function removeVM(vm) {
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5394
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5395
|
+
shared.assert.isTrue(vm.state === 1 /* VMState.connected */ || vm.state === 2 /* VMState.disconnected */, `${vm} must have been connected.`);
|
|
5396
|
+
}
|
|
5397
|
+
resetComponentStateWhenRemoved(vm);
|
|
5651
5398
|
}
|
|
5652
5399
|
function getNearestShadowAncestor(vm) {
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5400
|
+
let ancestor = vm.owner;
|
|
5401
|
+
while (!shared.isNull(ancestor) && ancestor.renderMode === 0 /* RenderMode.Light */) {
|
|
5402
|
+
ancestor = ancestor.owner;
|
|
5403
|
+
}
|
|
5404
|
+
return ancestor;
|
|
5658
5405
|
}
|
|
5659
5406
|
function createVM(elm, ctor, renderer, options) {
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
|
|
5697
|
-
|
|
5698
|
-
|
|
5699
|
-
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
component: null,
|
|
5705
|
-
shadowRoot: null,
|
|
5706
|
-
renderRoot: null,
|
|
5707
|
-
callHook,
|
|
5708
|
-
setHook,
|
|
5709
|
-
getHook,
|
|
5710
|
-
renderer
|
|
5711
|
-
};
|
|
5712
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
5713
|
-
vm.debugInfo = shared.create(null);
|
|
5714
|
-
}
|
|
5715
|
-
vm.stylesheets = computeStylesheets(vm, def.ctor);
|
|
5716
|
-
vm.shadowMode = computeShadowMode(vm, renderer);
|
|
5717
|
-
vm.tro = getTemplateReactiveObserver(vm);
|
|
5718
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
5719
|
-
vm.toString = () => {
|
|
5720
|
-
return `[object:vm ${def.name} (${vm.idx})]`;
|
|
5407
|
+
const { mode, owner, tagName, hydrated } = options;
|
|
5408
|
+
const def = getComponentInternalDef(ctor);
|
|
5409
|
+
const vm = {
|
|
5410
|
+
elm,
|
|
5411
|
+
def,
|
|
5412
|
+
idx: idx++,
|
|
5413
|
+
state: 0 /* VMState.created */,
|
|
5414
|
+
isScheduled: false,
|
|
5415
|
+
isDirty: true,
|
|
5416
|
+
tagName,
|
|
5417
|
+
mode,
|
|
5418
|
+
owner,
|
|
5419
|
+
refVNodes: null,
|
|
5420
|
+
children: EmptyArray,
|
|
5421
|
+
aChildren: EmptyArray,
|
|
5422
|
+
velements: EmptyArray,
|
|
5423
|
+
cmpProps: shared.create(null),
|
|
5424
|
+
cmpFields: shared.create(null),
|
|
5425
|
+
cmpSlots: { slotAssignments: shared.create(null) },
|
|
5426
|
+
cmpTemplate: null,
|
|
5427
|
+
hydrated: Boolean(hydrated),
|
|
5428
|
+
renderMode: def.renderMode,
|
|
5429
|
+
context: {
|
|
5430
|
+
stylesheetToken: undefined,
|
|
5431
|
+
hasTokenInClass: undefined,
|
|
5432
|
+
hasTokenInAttribute: undefined,
|
|
5433
|
+
hasScopedStyles: undefined,
|
|
5434
|
+
styleVNodes: null,
|
|
5435
|
+
tplCache: EmptyObject,
|
|
5436
|
+
wiredConnecting: EmptyArray,
|
|
5437
|
+
wiredDisconnecting: EmptyArray,
|
|
5438
|
+
},
|
|
5439
|
+
// Properties set right after VM creation.
|
|
5440
|
+
tro: null,
|
|
5441
|
+
shadowMode: null,
|
|
5442
|
+
stylesheets: null,
|
|
5443
|
+
// Properties set by the LightningElement constructor.
|
|
5444
|
+
component: null,
|
|
5445
|
+
shadowRoot: null,
|
|
5446
|
+
renderRoot: null,
|
|
5447
|
+
callHook,
|
|
5448
|
+
setHook,
|
|
5449
|
+
getHook,
|
|
5450
|
+
renderer,
|
|
5721
5451
|
};
|
|
5722
|
-
if (
|
|
5723
|
-
|
|
5724
|
-
}
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5452
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5453
|
+
vm.debugInfo = shared.create(null);
|
|
5454
|
+
}
|
|
5455
|
+
vm.stylesheets = computeStylesheets(vm, def.ctor);
|
|
5456
|
+
vm.shadowMode = computeShadowMode(vm, renderer);
|
|
5457
|
+
vm.tro = getTemplateReactiveObserver(vm);
|
|
5458
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5459
|
+
vm.toString = () => {
|
|
5460
|
+
return `[object:vm ${def.name} (${vm.idx})]`;
|
|
5461
|
+
};
|
|
5462
|
+
if (lwcRuntimeFlags.ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST) {
|
|
5463
|
+
vm.shadowMode = 0 /* ShadowMode.Native */;
|
|
5464
|
+
}
|
|
5465
|
+
}
|
|
5466
|
+
// Create component instance associated to the vm and the element.
|
|
5467
|
+
invokeComponentConstructor(vm, def.ctor);
|
|
5468
|
+
// Initializing the wire decorator per instance only when really needed
|
|
5469
|
+
if (hasWireAdapters(vm)) {
|
|
5470
|
+
installWireAdapters(vm);
|
|
5471
|
+
}
|
|
5472
|
+
return vm;
|
|
5733
5473
|
}
|
|
5734
5474
|
function validateComponentStylesheets(vm, stylesheets) {
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5475
|
+
let valid = true;
|
|
5476
|
+
const validate = (arrayOrStylesheet) => {
|
|
5477
|
+
if (shared.isArray(arrayOrStylesheet)) {
|
|
5478
|
+
for (let i = 0; i < arrayOrStylesheet.length; i++) {
|
|
5479
|
+
validate(arrayOrStylesheet[i]);
|
|
5480
|
+
}
|
|
5481
|
+
}
|
|
5482
|
+
else if (!shared.isFunction(arrayOrStylesheet)) {
|
|
5483
|
+
// function assumed to be a stylesheet factory
|
|
5484
|
+
valid = false;
|
|
5485
|
+
}
|
|
5486
|
+
};
|
|
5487
|
+
if (!shared.isArray(stylesheets)) {
|
|
5488
|
+
valid = false;
|
|
5489
|
+
}
|
|
5490
|
+
else {
|
|
5491
|
+
validate(stylesheets);
|
|
5492
|
+
}
|
|
5493
|
+
return valid;
|
|
5752
5494
|
}
|
|
5753
5495
|
// Validate and flatten any stylesheets defined as `static stylesheets`
|
|
5754
5496
|
function computeStylesheets(vm, ctor) {
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
stylesheets
|
|
5758
|
-
|
|
5759
|
-
|
|
5760
|
-
|
|
5761
|
-
|
|
5762
|
-
|
|
5763
|
-
|
|
5764
|
-
|
|
5765
|
-
}
|
|
5766
|
-
|
|
5767
|
-
return null;
|
|
5497
|
+
warnOnStylesheetsMutation(ctor);
|
|
5498
|
+
const { stylesheets } = ctor;
|
|
5499
|
+
if (!shared.isUndefined(stylesheets)) {
|
|
5500
|
+
const valid = validateComponentStylesheets(vm, stylesheets);
|
|
5501
|
+
if (valid) {
|
|
5502
|
+
return flattenStylesheets(stylesheets);
|
|
5503
|
+
}
|
|
5504
|
+
else if (process.env.NODE_ENV !== 'production') {
|
|
5505
|
+
logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
|
|
5506
|
+
}
|
|
5507
|
+
}
|
|
5508
|
+
return null;
|
|
5768
5509
|
}
|
|
5769
5510
|
function warnOnStylesheetsMutation(ctor) {
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
}
|
|
5785
|
-
}
|
|
5511
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5512
|
+
let { stylesheets } = ctor;
|
|
5513
|
+
shared.defineProperty(ctor, 'stylesheets', {
|
|
5514
|
+
enumerable: true,
|
|
5515
|
+
configurable: true,
|
|
5516
|
+
get() {
|
|
5517
|
+
return stylesheets;
|
|
5518
|
+
},
|
|
5519
|
+
set(newValue) {
|
|
5520
|
+
logWarnOnce(`Dynamically setting the "stylesheets" static property on ${ctor.name} ` +
|
|
5521
|
+
'will not affect the stylesheets injected.');
|
|
5522
|
+
stylesheets = newValue;
|
|
5523
|
+
},
|
|
5524
|
+
});
|
|
5525
|
+
}
|
|
5786
5526
|
}
|
|
5787
5527
|
function computeShadowMode(vm, renderer) {
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
let shadowMode;
|
|
5796
|
-
if (isSyntheticShadowDefined) {
|
|
5797
|
-
if (def.renderMode === 0 /* RenderMode.Light */) {
|
|
5798
|
-
// ShadowMode.Native implies "not synthetic shadow" which is consistent with how
|
|
5799
|
-
// everything defaults to native when the synthetic shadow polyfill is unavailable.
|
|
5800
|
-
shadowMode = 0 /* ShadowMode.Native */;
|
|
5801
|
-
} else if (isNativeShadowDefined) {
|
|
5802
|
-
// Not combined with above condition because @lwc/features only supports identifiers in
|
|
5803
|
-
// the if-condition.
|
|
5804
|
-
if (features.lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE) {
|
|
5805
|
-
if (def.shadowSupportMode === "any" /* ShadowSupportMode.Any */) {
|
|
5806
|
-
shadowMode = 0 /* ShadowMode.Native */;
|
|
5807
|
-
} else {
|
|
5808
|
-
const shadowAncestor = getNearestShadowAncestor(vm);
|
|
5809
|
-
if (!shared.isNull(shadowAncestor) && shadowAncestor.shadowMode === 0 /* ShadowMode.Native */) {
|
|
5810
|
-
// Transitive support for native Shadow DOM. A component in native mode
|
|
5811
|
-
// transitively opts all of its descendants into native.
|
|
5528
|
+
const { def } = vm;
|
|
5529
|
+
const { isSyntheticShadowDefined, isNativeShadowDefined } = renderer;
|
|
5530
|
+
let shadowMode;
|
|
5531
|
+
if (isSyntheticShadowDefined) {
|
|
5532
|
+
if (def.renderMode === 0 /* RenderMode.Light */) {
|
|
5533
|
+
// ShadowMode.Native implies "not synthetic shadow" which is consistent with how
|
|
5534
|
+
// everything defaults to native when the synthetic shadow polyfill is unavailable.
|
|
5812
5535
|
shadowMode = 0 /* ShadowMode.Native */;
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
//
|
|
5536
|
+
}
|
|
5537
|
+
else if (isNativeShadowDefined) {
|
|
5538
|
+
// Not combined with above condition because @lwc/features only supports identifiers in
|
|
5539
|
+
// the if-condition.
|
|
5540
|
+
if (lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE) {
|
|
5541
|
+
if (def.shadowSupportMode === "any" /* ShadowSupportMode.Any */) {
|
|
5542
|
+
shadowMode = 0 /* ShadowMode.Native */;
|
|
5543
|
+
}
|
|
5544
|
+
else {
|
|
5545
|
+
const shadowAncestor = getNearestShadowAncestor(vm);
|
|
5546
|
+
if (!shared.isNull(shadowAncestor) &&
|
|
5547
|
+
shadowAncestor.shadowMode === 0 /* ShadowMode.Native */) {
|
|
5548
|
+
// Transitive support for native Shadow DOM. A component in native mode
|
|
5549
|
+
// transitively opts all of its descendants into native.
|
|
5550
|
+
shadowMode = 0 /* ShadowMode.Native */;
|
|
5551
|
+
}
|
|
5552
|
+
else {
|
|
5553
|
+
// Synthetic if neither this component nor any of its ancestors are configured
|
|
5554
|
+
// to be native.
|
|
5555
|
+
shadowMode = 1 /* ShadowMode.Synthetic */;
|
|
5556
|
+
}
|
|
5557
|
+
}
|
|
5558
|
+
}
|
|
5559
|
+
else {
|
|
5560
|
+
shadowMode = 1 /* ShadowMode.Synthetic */;
|
|
5561
|
+
}
|
|
5562
|
+
}
|
|
5563
|
+
else {
|
|
5564
|
+
// Synthetic if there is no native Shadow DOM support.
|
|
5816
5565
|
shadowMode = 1 /* ShadowMode.Synthetic */;
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
}
|
|
5823
|
-
|
|
5824
|
-
shadowMode = 1 /* ShadowMode.Synthetic */;
|
|
5825
|
-
}
|
|
5826
|
-
} else {
|
|
5827
|
-
// Native if the synthetic shadow polyfill is unavailable.
|
|
5828
|
-
shadowMode = 0 /* ShadowMode.Native */;
|
|
5829
|
-
}
|
|
5830
|
-
|
|
5831
|
-
return shadowMode;
|
|
5566
|
+
}
|
|
5567
|
+
}
|
|
5568
|
+
else {
|
|
5569
|
+
// Native if the synthetic shadow polyfill is unavailable.
|
|
5570
|
+
shadowMode = 0 /* ShadowMode.Native */;
|
|
5571
|
+
}
|
|
5572
|
+
return shadowMode;
|
|
5832
5573
|
}
|
|
5833
5574
|
function assertIsVM(obj) {
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5575
|
+
if (shared.isNull(obj) || !shared.isObject(obj) || !('renderRoot' in obj)) {
|
|
5576
|
+
throw new TypeError(`${obj} is not a VM.`);
|
|
5577
|
+
}
|
|
5837
5578
|
}
|
|
5838
5579
|
function associateVM(obj, vm) {
|
|
5839
|
-
|
|
5580
|
+
ViewModelReflection.set(obj, vm);
|
|
5840
5581
|
}
|
|
5841
5582
|
function getAssociatedVM(obj) {
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5583
|
+
const vm = ViewModelReflection.get(obj);
|
|
5584
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5585
|
+
assertIsVM(vm);
|
|
5586
|
+
}
|
|
5587
|
+
return vm;
|
|
5847
5588
|
}
|
|
5848
5589
|
function getAssociatedVMIfPresent(obj) {
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
5590
|
+
const maybeVm = ViewModelReflection.get(obj);
|
|
5591
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5592
|
+
if (!shared.isUndefined(maybeVm)) {
|
|
5593
|
+
assertIsVM(maybeVm);
|
|
5594
|
+
}
|
|
5853
5595
|
}
|
|
5854
|
-
|
|
5855
|
-
return maybeVm;
|
|
5596
|
+
return maybeVm;
|
|
5856
5597
|
}
|
|
5857
5598
|
function rehydrate(vm) {
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5599
|
+
if (shared.isTrue(vm.isDirty)) {
|
|
5600
|
+
const children = renderComponent(vm);
|
|
5601
|
+
patchShadowRoot(vm, children);
|
|
5602
|
+
}
|
|
5862
5603
|
}
|
|
5863
5604
|
function patchShadowRoot(vm, newCh) {
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
children
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
// the connectedCallback will take care of calling it in the right order at the end of
|
|
5891
|
-
// the current rehydration process.
|
|
5892
|
-
runRenderedCallback(vm);
|
|
5893
|
-
}
|
|
5605
|
+
const { renderRoot, children: oldCh, renderer } = vm;
|
|
5606
|
+
// caching the new children collection
|
|
5607
|
+
vm.children = newCh;
|
|
5608
|
+
if (newCh.length > 0 || oldCh.length > 0) {
|
|
5609
|
+
// patch function mutates vnodes by adding the element reference,
|
|
5610
|
+
// however, if patching fails it contains partial changes.
|
|
5611
|
+
if (oldCh !== newCh) {
|
|
5612
|
+
runWithBoundaryProtection(vm, vm, () => {
|
|
5613
|
+
// pre
|
|
5614
|
+
logOperationStart(2 /* OperationId.Patch */, vm);
|
|
5615
|
+
}, () => {
|
|
5616
|
+
// job
|
|
5617
|
+
patchChildren(oldCh, newCh, renderRoot, renderer);
|
|
5618
|
+
}, () => {
|
|
5619
|
+
// post
|
|
5620
|
+
logOperationEnd(2 /* OperationId.Patch */, vm);
|
|
5621
|
+
});
|
|
5622
|
+
}
|
|
5623
|
+
}
|
|
5624
|
+
if (vm.state === 1 /* VMState.connected */) {
|
|
5625
|
+
// If the element is connected, that means connectedCallback was already issued, and
|
|
5626
|
+
// any successive rendering should finish with the call to renderedCallback, otherwise
|
|
5627
|
+
// the connectedCallback will take care of calling it in the right order at the end of
|
|
5628
|
+
// the current rehydration process.
|
|
5629
|
+
runRenderedCallback(vm);
|
|
5630
|
+
}
|
|
5894
5631
|
}
|
|
5895
5632
|
function runRenderedCallback(vm) {
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
}
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
}
|
|
5910
|
-
if (!shared.isUndefined(renderedCallback)) {
|
|
5911
|
-
logOperationStart(4 /* OperationId.RenderedCallback */, vm);
|
|
5912
|
-
invokeComponentCallback(vm, renderedCallback);
|
|
5913
|
-
logOperationEnd(4 /* OperationId.RenderedCallback */, vm);
|
|
5914
|
-
}
|
|
5633
|
+
const { def: { renderedCallback }, } = vm;
|
|
5634
|
+
if (!process.env.IS_BROWSER) {
|
|
5635
|
+
return;
|
|
5636
|
+
}
|
|
5637
|
+
const { rendered } = Services;
|
|
5638
|
+
if (rendered) {
|
|
5639
|
+
invokeServiceHook(vm, rendered);
|
|
5640
|
+
}
|
|
5641
|
+
if (!shared.isUndefined(renderedCallback)) {
|
|
5642
|
+
logOperationStart(4 /* OperationId.RenderedCallback */, vm);
|
|
5643
|
+
invokeComponentCallback(vm, renderedCallback);
|
|
5644
|
+
logOperationEnd(4 /* OperationId.RenderedCallback */, vm);
|
|
5645
|
+
}
|
|
5915
5646
|
}
|
|
5916
5647
|
let rehydrateQueue = [];
|
|
5917
5648
|
function flushRehydrationQueue() {
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5649
|
+
logGlobalOperationStart(8 /* OperationId.GlobalRehydrate */);
|
|
5650
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5651
|
+
shared.assert.invariant(rehydrateQueue.length, `If rehydrateQueue was scheduled, it is because there must be at least one VM on this pending queue instead of ${rehydrateQueue}.`);
|
|
5652
|
+
}
|
|
5653
|
+
const vms = rehydrateQueue.sort((a, b) => a.idx - b.idx);
|
|
5654
|
+
rehydrateQueue = []; // reset to a new queue
|
|
5655
|
+
for (let i = 0, len = vms.length; i < len; i += 1) {
|
|
5656
|
+
const vm = vms[i];
|
|
5657
|
+
try {
|
|
5658
|
+
rehydrate(vm);
|
|
5659
|
+
}
|
|
5660
|
+
catch (error) {
|
|
5661
|
+
if (i + 1 < len) {
|
|
5662
|
+
// pieces of the queue are still pending to be rehydrated, those should have priority
|
|
5663
|
+
if (rehydrateQueue.length === 0) {
|
|
5664
|
+
addCallbackToNextTick(flushRehydrationQueue);
|
|
5665
|
+
}
|
|
5666
|
+
shared.ArrayUnshift.apply(rehydrateQueue, shared.ArraySlice.call(vms, i + 1));
|
|
5667
|
+
}
|
|
5668
|
+
// we need to end the measure before throwing.
|
|
5669
|
+
logGlobalOperationEnd(8 /* OperationId.GlobalRehydrate */);
|
|
5670
|
+
// re-throwing the original error will break the current tick, but since the next tick is
|
|
5671
|
+
// already scheduled, it should continue patching the rest.
|
|
5672
|
+
throw error; // eslint-disable-line no-unsafe-finally
|
|
5673
|
+
}
|
|
5674
|
+
}
|
|
5675
|
+
logGlobalOperationEnd(8 /* OperationId.GlobalRehydrate */);
|
|
5945
5676
|
}
|
|
5946
|
-
|
|
5947
5677
|
function runConnectedCallback(vm) {
|
|
5948
|
-
|
|
5949
|
-
state
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
connectedCallback
|
|
5968
|
-
} = vm.def;
|
|
5969
|
-
if (!shared.isUndefined(connectedCallback)) {
|
|
5970
|
-
logOperationStart(3 /* OperationId.ConnectedCallback */, vm);
|
|
5971
|
-
invokeComponentCallback(vm, connectedCallback);
|
|
5972
|
-
logOperationEnd(3 /* OperationId.ConnectedCallback */, vm);
|
|
5973
|
-
}
|
|
5678
|
+
const { state } = vm;
|
|
5679
|
+
if (state === 1 /* VMState.connected */) {
|
|
5680
|
+
return; // nothing to do since it was already connected
|
|
5681
|
+
}
|
|
5682
|
+
vm.state = 1 /* VMState.connected */;
|
|
5683
|
+
// reporting connection
|
|
5684
|
+
const { connected } = Services;
|
|
5685
|
+
if (connected) {
|
|
5686
|
+
invokeServiceHook(vm, connected);
|
|
5687
|
+
}
|
|
5688
|
+
if (hasWireAdapters(vm)) {
|
|
5689
|
+
connectWireAdapters(vm);
|
|
5690
|
+
}
|
|
5691
|
+
const { connectedCallback } = vm.def;
|
|
5692
|
+
if (!shared.isUndefined(connectedCallback)) {
|
|
5693
|
+
logOperationStart(3 /* OperationId.ConnectedCallback */, vm);
|
|
5694
|
+
invokeComponentCallback(vm, connectedCallback);
|
|
5695
|
+
logOperationEnd(3 /* OperationId.ConnectedCallback */, vm);
|
|
5696
|
+
}
|
|
5974
5697
|
}
|
|
5975
5698
|
function hasWireAdapters(vm) {
|
|
5976
|
-
|
|
5699
|
+
return shared.getOwnPropertyNames(vm.def.wire).length > 0;
|
|
5977
5700
|
}
|
|
5978
5701
|
function runDisconnectedCallback(vm) {
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
disconnected
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
|
|
6004
|
-
logOperationStart(5 /* OperationId.DisconnectedCallback */, vm);
|
|
6005
|
-
invokeComponentCallback(vm, disconnectedCallback);
|
|
6006
|
-
logOperationEnd(5 /* OperationId.DisconnectedCallback */, vm);
|
|
6007
|
-
}
|
|
5702
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5703
|
+
shared.assert.isTrue(vm.state !== 2 /* VMState.disconnected */, `${vm} must be inserted.`);
|
|
5704
|
+
}
|
|
5705
|
+
if (shared.isFalse(vm.isDirty)) {
|
|
5706
|
+
// this guarantees that if the component is reused/reinserted,
|
|
5707
|
+
// it will be re-rendered because we are disconnecting the reactivity
|
|
5708
|
+
// linking, so mutations are not automatically reflected on the state
|
|
5709
|
+
// of disconnected components.
|
|
5710
|
+
vm.isDirty = true;
|
|
5711
|
+
}
|
|
5712
|
+
vm.state = 2 /* VMState.disconnected */;
|
|
5713
|
+
// reporting disconnection
|
|
5714
|
+
const { disconnected } = Services;
|
|
5715
|
+
if (disconnected) {
|
|
5716
|
+
invokeServiceHook(vm, disconnected);
|
|
5717
|
+
}
|
|
5718
|
+
if (hasWireAdapters(vm)) {
|
|
5719
|
+
disconnectWireAdapters(vm);
|
|
5720
|
+
}
|
|
5721
|
+
const { disconnectedCallback } = vm.def;
|
|
5722
|
+
if (!shared.isUndefined(disconnectedCallback)) {
|
|
5723
|
+
logOperationStart(5 /* OperationId.DisconnectedCallback */, vm);
|
|
5724
|
+
invokeComponentCallback(vm, disconnectedCallback);
|
|
5725
|
+
logOperationEnd(5 /* OperationId.DisconnectedCallback */, vm);
|
|
5726
|
+
}
|
|
6008
5727
|
}
|
|
6009
5728
|
function runChildNodesDisconnectedCallback(vm) {
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
if (!shared.isUndefined(childVM)) {
|
|
6032
|
-
resetComponentStateWhenRemoved(childVM);
|
|
6033
|
-
}
|
|
5729
|
+
const { velements: vCustomElementCollection } = vm;
|
|
5730
|
+
// Reporting disconnection for every child in inverse order since they are
|
|
5731
|
+
// inserted in reserved order.
|
|
5732
|
+
for (let i = vCustomElementCollection.length - 1; i >= 0; i -= 1) {
|
|
5733
|
+
const { elm } = vCustomElementCollection[i];
|
|
5734
|
+
// There are two cases where the element could be undefined:
|
|
5735
|
+
// * when there is an error during the construction phase, and an error
|
|
5736
|
+
// boundary picks it, there is a possibility that the VCustomElement
|
|
5737
|
+
// is not properly initialized, and therefore is should be ignored.
|
|
5738
|
+
// * when slotted custom element is not used by the element where it is
|
|
5739
|
+
// slotted into it, as a result, the custom element was never
|
|
5740
|
+
// initialized.
|
|
5741
|
+
if (!shared.isUndefined(elm)) {
|
|
5742
|
+
const childVM = getAssociatedVMIfPresent(elm);
|
|
5743
|
+
// The VM associated with the element might be associated undefined
|
|
5744
|
+
// in the case where the VM failed in the middle of its creation,
|
|
5745
|
+
// eg: constructor throwing before invoking super().
|
|
5746
|
+
if (!shared.isUndefined(childVM)) {
|
|
5747
|
+
resetComponentStateWhenRemoved(childVM);
|
|
5748
|
+
}
|
|
5749
|
+
}
|
|
6034
5750
|
}
|
|
6035
|
-
}
|
|
6036
5751
|
}
|
|
6037
5752
|
function runLightChildNodesDisconnectedCallback(vm) {
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
} = vm;
|
|
6041
|
-
recursivelyDisconnectChildren(adoptedChildren);
|
|
5753
|
+
const { aChildren: adoptedChildren } = vm;
|
|
5754
|
+
recursivelyDisconnectChildren(adoptedChildren);
|
|
6042
5755
|
}
|
|
6043
5756
|
/**
|
|
6044
5757
|
* The recursion doesn't need to be a complete traversal of the vnode graph,
|
|
@@ -6048,104 +5761,98 @@ function runLightChildNodesDisconnectedCallback(vm) {
|
|
|
6048
5761
|
* defined on its shadow.
|
|
6049
5762
|
*/
|
|
6050
5763
|
function recursivelyDisconnectChildren(vnodes) {
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
5764
|
+
for (let i = 0, len = vnodes.length; i < len; i += 1) {
|
|
5765
|
+
const vnode = vnodes[i];
|
|
5766
|
+
if (!shared.isNull(vnode) && !shared.isUndefined(vnode.elm)) {
|
|
5767
|
+
switch (vnode.type) {
|
|
5768
|
+
case 2 /* VNodeType.Element */:
|
|
5769
|
+
recursivelyDisconnectChildren(vnode.children);
|
|
5770
|
+
break;
|
|
5771
|
+
case 3 /* VNodeType.CustomElement */: {
|
|
5772
|
+
const vm = getAssociatedVM(vnode.elm);
|
|
5773
|
+
resetComponentStateWhenRemoved(vm);
|
|
5774
|
+
break;
|
|
5775
|
+
}
|
|
5776
|
+
}
|
|
5777
|
+
}
|
|
6065
5778
|
}
|
|
6066
|
-
}
|
|
6067
5779
|
}
|
|
6068
5780
|
// This is a super optimized mechanism to remove the content of the root node (shadow root
|
|
6069
5781
|
// for shadow DOM components and the root element itself for light DOM) without having to go
|
|
6070
5782
|
// into snabbdom. Especially useful when the reset is a consequence of an error, in which case the
|
|
6071
5783
|
// children VNodes might not be representing the current state of the DOM.
|
|
6072
5784
|
function resetComponentRoot(vm) {
|
|
6073
|
-
|
|
6074
|
-
children
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
remove(child.elm, renderRoot);
|
|
6084
|
-
}
|
|
6085
|
-
}
|
|
6086
|
-
vm.children = EmptyArray;
|
|
6087
|
-
runChildNodesDisconnectedCallback(vm);
|
|
6088
|
-
vm.velements = EmptyArray;
|
|
5785
|
+
const { children, renderRoot, renderer: { remove }, } = vm;
|
|
5786
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
5787
|
+
const child = children[i];
|
|
5788
|
+
if (!shared.isNull(child) && !shared.isUndefined(child.elm)) {
|
|
5789
|
+
remove(child.elm, renderRoot);
|
|
5790
|
+
}
|
|
5791
|
+
}
|
|
5792
|
+
vm.children = EmptyArray;
|
|
5793
|
+
runChildNodesDisconnectedCallback(vm);
|
|
5794
|
+
vm.velements = EmptyArray;
|
|
6089
5795
|
}
|
|
6090
5796
|
function scheduleRehydration(vm) {
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
5797
|
+
if (!process.env.IS_BROWSER || shared.isTrue(vm.isScheduled)) {
|
|
5798
|
+
return;
|
|
5799
|
+
}
|
|
5800
|
+
vm.isScheduled = true;
|
|
5801
|
+
if (rehydrateQueue.length === 0) {
|
|
5802
|
+
addCallbackToNextTick(flushRehydrationQueue);
|
|
5803
|
+
}
|
|
5804
|
+
shared.ArrayPush.call(rehydrateQueue, vm);
|
|
6099
5805
|
}
|
|
6100
5806
|
function getErrorBoundaryVM(vm) {
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
5807
|
+
let currentVm = vm;
|
|
5808
|
+
while (!shared.isNull(currentVm)) {
|
|
5809
|
+
if (!shared.isUndefined(currentVm.def.errorCallback)) {
|
|
5810
|
+
return currentVm;
|
|
5811
|
+
}
|
|
5812
|
+
currentVm = currentVm.owner;
|
|
6105
5813
|
}
|
|
6106
|
-
currentVm = currentVm.owner;
|
|
6107
|
-
}
|
|
6108
5814
|
}
|
|
6109
5815
|
function runWithBoundaryProtection(vm, owner, pre, job, post) {
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
|
|
6126
|
-
|
|
6127
|
-
|
|
6128
|
-
|
|
6129
|
-
|
|
6130
|
-
|
|
5816
|
+
let error;
|
|
5817
|
+
pre();
|
|
5818
|
+
try {
|
|
5819
|
+
job();
|
|
5820
|
+
}
|
|
5821
|
+
catch (e) {
|
|
5822
|
+
error = Object(e);
|
|
5823
|
+
}
|
|
5824
|
+
finally {
|
|
5825
|
+
post();
|
|
5826
|
+
if (!shared.isUndefined(error)) {
|
|
5827
|
+
addErrorComponentStack(vm, error);
|
|
5828
|
+
const errorBoundaryVm = shared.isNull(owner) ? undefined : getErrorBoundaryVM(owner);
|
|
5829
|
+
if (shared.isUndefined(errorBoundaryVm)) {
|
|
5830
|
+
throw error; // eslint-disable-line no-unsafe-finally
|
|
5831
|
+
}
|
|
5832
|
+
resetComponentRoot(vm); // remove offenders
|
|
5833
|
+
logOperationStart(6 /* OperationId.ErrorCallback */, vm);
|
|
5834
|
+
// error boundaries must have an ErrorCallback
|
|
5835
|
+
const errorCallback = errorBoundaryVm.def.errorCallback;
|
|
5836
|
+
invokeComponentCallback(errorBoundaryVm, errorCallback, [error, error.wcStack]);
|
|
5837
|
+
logOperationEnd(6 /* OperationId.ErrorCallback */, vm);
|
|
5838
|
+
}
|
|
6131
5839
|
}
|
|
6132
|
-
}
|
|
6133
5840
|
}
|
|
6134
5841
|
function forceRehydration(vm) {
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
5842
|
+
// if we must reset the shadowRoot content and render the template
|
|
5843
|
+
// from scratch on an active instance, the way to force the reset
|
|
5844
|
+
// is by replacing the value of old template, which is used during
|
|
5845
|
+
// to determine if the template has changed or not during the rendering
|
|
5846
|
+
// process. If the template returned by render() is different from the
|
|
5847
|
+
// previous stored template, the styles will be reset, along with the
|
|
5848
|
+
// content of the shadowRoot, this way we can guarantee that all children
|
|
5849
|
+
// elements will be throw away, and new instances will be created.
|
|
5850
|
+
vm.cmpTemplate = () => [];
|
|
5851
|
+
if (shared.isFalse(vm.isDirty)) {
|
|
5852
|
+
// forcing the vm to rehydrate in the next tick
|
|
5853
|
+
markComponentAsDirty(vm);
|
|
5854
|
+
scheduleRehydration(vm);
|
|
5855
|
+
}
|
|
6149
5856
|
}
|
|
6150
5857
|
|
|
6151
5858
|
/*
|
|
@@ -6177,7 +5884,7 @@ function reportViolation$1(source, target, attrName) {
|
|
|
6177
5884
|
// vm should never be undefined here, but just to be safe, bail out and don't report
|
|
6178
5885
|
return;
|
|
6179
5886
|
}
|
|
6180
|
-
report(
|
|
5887
|
+
report("CrossRootAriaInSyntheticShadow" /* ReportingEventId.CrossRootAriaInSyntheticShadow */, {
|
|
6181
5888
|
tagName: vm.tagName,
|
|
6182
5889
|
attributeName: attrName,
|
|
6183
5890
|
});
|
|
@@ -6307,91 +6014,107 @@ if (process.env.IS_BROWSER && supportsCssEscape() && isSyntheticShadowLoaded())
|
|
|
6307
6014
|
// legacy non-standard Element.prototype extensions added by the @lwc/aria-reflection package.
|
|
6308
6015
|
//
|
|
6309
6016
|
// See the README for @lwc/aria-reflection
|
|
6310
|
-
const NON_STANDARD_ARIA_PROPS = [
|
|
6017
|
+
const NON_STANDARD_ARIA_PROPS = [
|
|
6018
|
+
'ariaActiveDescendant',
|
|
6019
|
+
'ariaControls',
|
|
6020
|
+
'ariaDescribedBy',
|
|
6021
|
+
'ariaDetails',
|
|
6022
|
+
'ariaErrorMessage',
|
|
6023
|
+
'ariaFlowTo',
|
|
6024
|
+
'ariaLabelledBy',
|
|
6025
|
+
'ariaOwns',
|
|
6026
|
+
];
|
|
6311
6027
|
function isLightningElement(elm) {
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
6028
|
+
// The former case is for `this.prop` (inside component) and the latter is for `element.prop` (outside component).
|
|
6029
|
+
// In both cases, we apply the non-standard prop even when the global polyfill is disabled, so this is kosher.
|
|
6030
|
+
return elm instanceof LightningElement || elm instanceof BaseBridgeElement;
|
|
6315
6031
|
}
|
|
6316
6032
|
function findVM(elm) {
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
host
|
|
6320
|
-
|
|
6321
|
-
const vm = shared.isUndefined(host) ? undefined : getAssociatedVMIfPresent(host);
|
|
6322
|
-
if (!shared.isUndefined(vm)) {
|
|
6323
|
-
return vm;
|
|
6324
|
-
}
|
|
6325
|
-
// Else it might be a light DOM component. Walk up the tree trying to find the owner
|
|
6326
|
-
let parentElement = elm;
|
|
6327
|
-
while (!shared.isNull(parentElement = parentElement.parentElement)) {
|
|
6328
|
-
if (isLightningElement(parentElement)) {
|
|
6329
|
-
const vm = getAssociatedVMIfPresent(parentElement);
|
|
6330
|
-
if (!shared.isUndefined(vm)) {
|
|
6033
|
+
// If it's a shadow DOM component, then it has a host
|
|
6034
|
+
const { host } = elm.getRootNode();
|
|
6035
|
+
const vm = shared.isUndefined(host) ? undefined : getAssociatedVMIfPresent(host);
|
|
6036
|
+
if (!shared.isUndefined(vm)) {
|
|
6331
6037
|
return vm;
|
|
6332
|
-
}
|
|
6333
6038
|
}
|
|
6334
|
-
|
|
6335
|
-
|
|
6039
|
+
// Else it might be a light DOM component. Walk up the tree trying to find the owner
|
|
6040
|
+
let parentElement = elm;
|
|
6041
|
+
while (!shared.isNull((parentElement = parentElement.parentElement))) {
|
|
6042
|
+
if (isLightningElement(parentElement)) {
|
|
6043
|
+
const vm = getAssociatedVMIfPresent(parentElement);
|
|
6044
|
+
if (!shared.isUndefined(vm)) {
|
|
6045
|
+
return vm;
|
|
6046
|
+
}
|
|
6047
|
+
}
|
|
6048
|
+
}
|
|
6049
|
+
// If we return undefined, it's because the element was rendered wholly outside a LightningElement
|
|
6336
6050
|
}
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6051
|
+
function checkAndReportViolation(elm, prop, isSetter, setValue) {
|
|
6052
|
+
if (!isLightningElement(elm)) {
|
|
6053
|
+
const vm = findVM(elm);
|
|
6054
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
6055
|
+
logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` +
|
|
6056
|
+
(shared.isUndefined(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) +
|
|
6057
|
+
`uses non-standard property "${prop}". This will be removed in a future version of LWC. ` +
|
|
6058
|
+
`See https://sfdc.co/deprecated-aria`);
|
|
6059
|
+
}
|
|
6060
|
+
let setValueType;
|
|
6061
|
+
if (isSetter) {
|
|
6062
|
+
// `typeof null` is "object" which is not very useful for detecting null.
|
|
6063
|
+
// We mostly want to know null vs undefined vs other types here, due to
|
|
6064
|
+
// https://github.com/salesforce/lwc/issues/3284
|
|
6065
|
+
setValueType = shared.isNull(setValue) ? 'null' : typeof setValue;
|
|
6066
|
+
}
|
|
6067
|
+
report("NonStandardAriaReflection" /* ReportingEventId.NonStandardAriaReflection */, {
|
|
6068
|
+
tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
|
|
6069
|
+
propertyName: prop,
|
|
6070
|
+
isSetter,
|
|
6071
|
+
setValueType,
|
|
6072
|
+
});
|
|
6343
6073
|
}
|
|
6344
|
-
report(2 /* ReportingEventId.NonStandardAriaReflection */, {
|
|
6345
|
-
tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
|
|
6346
|
-
propertyName: prop
|
|
6347
|
-
});
|
|
6348
|
-
}
|
|
6349
6074
|
}
|
|
6350
6075
|
function enableDetection() {
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6076
|
+
const { prototype } = Element;
|
|
6077
|
+
for (const prop of NON_STANDARD_ARIA_PROPS) {
|
|
6078
|
+
const descriptor = shared.getOwnPropertyDescriptor(prototype, prop);
|
|
6079
|
+
// The descriptor should exist because the @lwc/aria-reflection polyfill has run by now.
|
|
6080
|
+
// This happens automatically because of the ordering of imports.
|
|
6081
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
6082
|
+
/* istanbul ignore if */
|
|
6083
|
+
if (shared.isUndefined(descriptor) ||
|
|
6084
|
+
shared.isUndefined(descriptor.get) ||
|
|
6085
|
+
shared.isUndefined(descriptor.set)) {
|
|
6086
|
+
// should never happen
|
|
6087
|
+
throw new Error('detect-non-standard-aria.ts loaded before @lwc/aria-reflection');
|
|
6088
|
+
}
|
|
6089
|
+
}
|
|
6090
|
+
// @ts-ignore
|
|
6091
|
+
const { get, set } = descriptor;
|
|
6092
|
+
shared.defineProperty(prototype, prop, {
|
|
6093
|
+
get() {
|
|
6094
|
+
checkAndReportViolation(this, prop, false, undefined);
|
|
6095
|
+
return get.call(this);
|
|
6096
|
+
},
|
|
6097
|
+
set(val) {
|
|
6098
|
+
checkAndReportViolation(this, prop, true, val);
|
|
6099
|
+
return set.call(this, val);
|
|
6100
|
+
},
|
|
6101
|
+
configurable: true,
|
|
6102
|
+
enumerable: true,
|
|
6103
|
+
});
|
|
6364
6104
|
}
|
|
6365
|
-
// @ts-ignore
|
|
6366
|
-
const {
|
|
6367
|
-
get,
|
|
6368
|
-
set
|
|
6369
|
-
} = descriptor;
|
|
6370
|
-
shared.defineProperty(prototype, prop, {
|
|
6371
|
-
get() {
|
|
6372
|
-
checkAndReportViolation(this, prop);
|
|
6373
|
-
return get.call(this);
|
|
6374
|
-
},
|
|
6375
|
-
set(val) {
|
|
6376
|
-
checkAndReportViolation(this, prop);
|
|
6377
|
-
return set.call(this, val);
|
|
6378
|
-
},
|
|
6379
|
-
configurable: true,
|
|
6380
|
-
enumerable: true
|
|
6381
|
-
});
|
|
6382
|
-
}
|
|
6383
6105
|
}
|
|
6384
6106
|
// No point in running this code if we're not in a browser, or if the global polyfill is not loaded
|
|
6385
6107
|
if (process.env.IS_BROWSER) {
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6108
|
+
if (!lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
|
|
6109
|
+
// Always run detection in dev mode, so we can at least print to the console
|
|
6110
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
6111
|
+
enableDetection();
|
|
6112
|
+
}
|
|
6113
|
+
else {
|
|
6114
|
+
// In prod mode, only enable detection if reporting is enabled
|
|
6115
|
+
onReportingEnabled(enableDetection);
|
|
6116
|
+
}
|
|
6393
6117
|
}
|
|
6394
|
-
}
|
|
6395
6118
|
}
|
|
6396
6119
|
|
|
6397
6120
|
/*
|
|
@@ -6880,191 +6603,204 @@ function setHooks(hooks) {
|
|
|
6880
6603
|
const TEMPLATE_PROPS = ['slots', 'stylesheetToken', 'stylesheets', 'renderMode'];
|
|
6881
6604
|
// Expandos that may be placed on a stylesheet factory function, and which are meaningful to LWC at runtime
|
|
6882
6605
|
const STYLESHEET_PROPS = [
|
|
6883
|
-
// SEE `KEY__SCOPED_CSS` in @lwc/style-compiler
|
|
6884
|
-
'$scoped$'
|
|
6606
|
+
// SEE `KEY__SCOPED_CSS` in @lwc/style-compiler
|
|
6607
|
+
'$scoped$',
|
|
6608
|
+
];
|
|
6885
6609
|
// Via https://www.npmjs.com/package/object-observer
|
|
6886
|
-
const ARRAY_MUTATION_METHODS = [
|
|
6610
|
+
const ARRAY_MUTATION_METHODS = [
|
|
6611
|
+
'pop',
|
|
6612
|
+
'push',
|
|
6613
|
+
'shift',
|
|
6614
|
+
'unshift',
|
|
6615
|
+
'reverse',
|
|
6616
|
+
'sort',
|
|
6617
|
+
'fill',
|
|
6618
|
+
'splice',
|
|
6619
|
+
'copyWithin',
|
|
6620
|
+
];
|
|
6887
6621
|
let mutationTrackingDisabled = false;
|
|
6888
6622
|
function getOriginalArrayMethod(prop) {
|
|
6889
|
-
|
|
6890
|
-
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
|
|
6894
|
-
|
|
6895
|
-
|
|
6896
|
-
|
|
6897
|
-
|
|
6898
|
-
|
|
6899
|
-
|
|
6900
|
-
|
|
6901
|
-
|
|
6902
|
-
|
|
6903
|
-
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
|
|
6623
|
+
switch (prop) {
|
|
6624
|
+
case 'pop':
|
|
6625
|
+
return shared.ArrayPop;
|
|
6626
|
+
case 'push':
|
|
6627
|
+
return shared.ArrayPush;
|
|
6628
|
+
case 'shift':
|
|
6629
|
+
return shared.ArrayShift;
|
|
6630
|
+
case 'unshift':
|
|
6631
|
+
return shared.ArrayUnshift;
|
|
6632
|
+
case 'reverse':
|
|
6633
|
+
return shared.ArrayReverse;
|
|
6634
|
+
case 'sort':
|
|
6635
|
+
return shared.ArraySort;
|
|
6636
|
+
case 'fill':
|
|
6637
|
+
return shared.ArrayFill;
|
|
6638
|
+
case 'splice':
|
|
6639
|
+
return shared.ArraySplice;
|
|
6640
|
+
case 'copyWithin':
|
|
6641
|
+
return shared.ArrayCopyWithin;
|
|
6642
|
+
}
|
|
6909
6643
|
}
|
|
6910
6644
|
function reportViolation(type, eventId, prop) {
|
|
6911
|
-
|
|
6912
|
-
|
|
6913
|
-
|
|
6914
|
-
|
|
6915
|
-
|
|
6916
|
-
|
|
6645
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
6646
|
+
logWarnOnce(`Mutating the "${prop}" property on a ${type} ` +
|
|
6647
|
+
`is deprecated and will be removed in a future version of LWC. ` +
|
|
6648
|
+
`See: https://sfdc.co/template-mutation`);
|
|
6649
|
+
}
|
|
6650
|
+
report(eventId, { propertyName: prop });
|
|
6917
6651
|
}
|
|
6918
6652
|
function reportTemplateViolation(prop) {
|
|
6919
|
-
|
|
6653
|
+
reportViolation('template', "TemplateMutation" /* ReportingEventId.TemplateMutation */, prop);
|
|
6920
6654
|
}
|
|
6921
6655
|
function reportStylesheetViolation(prop) {
|
|
6922
|
-
|
|
6656
|
+
reportViolation('stylesheet', "StylesheetMutation" /* ReportingEventId.StylesheetMutation */, prop);
|
|
6923
6657
|
}
|
|
6924
6658
|
// Warn if the user tries to mutate a stylesheets array, e.g.:
|
|
6925
6659
|
// `tmpl.stylesheets.push(someStylesheetFunction)`
|
|
6926
6660
|
function warnOnArrayMutation(stylesheets) {
|
|
6927
|
-
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
|
|
6935
|
-
|
|
6936
|
-
|
|
6661
|
+
// We can't handle users calling Array.prototype.slice.call(tmpl.stylesheets), but
|
|
6662
|
+
// we can at least warn when they use the most common mutation methods.
|
|
6663
|
+
for (const prop of ARRAY_MUTATION_METHODS) {
|
|
6664
|
+
const originalArrayMethod = getOriginalArrayMethod(prop);
|
|
6665
|
+
stylesheets[prop] = function arrayMutationWarningWrapper() {
|
|
6666
|
+
reportTemplateViolation('stylesheets');
|
|
6667
|
+
// @ts-ignore
|
|
6668
|
+
return originalArrayMethod.apply(this, arguments);
|
|
6669
|
+
};
|
|
6670
|
+
}
|
|
6937
6671
|
}
|
|
6938
6672
|
// Warn if the user tries to mutate a stylesheet factory function, e.g.:
|
|
6939
6673
|
// `stylesheet.$scoped$ = true`
|
|
6940
6674
|
function warnOnStylesheetFunctionMutation(stylesheet) {
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
|
|
6954
|
-
|
|
6675
|
+
for (const prop of STYLESHEET_PROPS) {
|
|
6676
|
+
let value = stylesheet[prop];
|
|
6677
|
+
shared.defineProperty(stylesheet, prop, {
|
|
6678
|
+
enumerable: true,
|
|
6679
|
+
configurable: true,
|
|
6680
|
+
get() {
|
|
6681
|
+
return value;
|
|
6682
|
+
},
|
|
6683
|
+
set(newValue) {
|
|
6684
|
+
reportStylesheetViolation(prop);
|
|
6685
|
+
value = newValue;
|
|
6686
|
+
},
|
|
6687
|
+
});
|
|
6688
|
+
}
|
|
6955
6689
|
}
|
|
6956
6690
|
// Warn on either array or stylesheet (function) mutation, in a deeply-nested array
|
|
6957
6691
|
function trackStylesheetsMutation(stylesheets) {
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6692
|
+
traverseStylesheets(stylesheets, (subStylesheets) => {
|
|
6693
|
+
if (shared.isArray(subStylesheets)) {
|
|
6694
|
+
warnOnArrayMutation(subStylesheets);
|
|
6695
|
+
}
|
|
6696
|
+
else {
|
|
6697
|
+
warnOnStylesheetFunctionMutation(subStylesheets);
|
|
6698
|
+
}
|
|
6699
|
+
});
|
|
6965
6700
|
}
|
|
6966
6701
|
// Deeply freeze the entire array (of arrays) of stylesheet factory functions
|
|
6967
6702
|
function deepFreeze(stylesheets) {
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6703
|
+
traverseStylesheets(stylesheets, (subStylesheets) => {
|
|
6704
|
+
shared.freeze(subStylesheets);
|
|
6705
|
+
});
|
|
6971
6706
|
}
|
|
6972
6707
|
// Deep-traverse an array (of arrays) of stylesheet factory functions, and call the callback for every array/function
|
|
6973
6708
|
function traverseStylesheets(stylesheets, callback) {
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
|
|
6977
|
-
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
6709
|
+
callback(stylesheets);
|
|
6710
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
6711
|
+
const stylesheet = stylesheets[i];
|
|
6712
|
+
if (shared.isArray(stylesheet)) {
|
|
6713
|
+
traverseStylesheets(stylesheet, callback);
|
|
6714
|
+
}
|
|
6715
|
+
else {
|
|
6716
|
+
callback(stylesheet);
|
|
6717
|
+
}
|
|
6981
6718
|
}
|
|
6982
|
-
}
|
|
6983
6719
|
}
|
|
6984
6720
|
function trackMutations(tmpl) {
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
-
|
|
6989
|
-
|
|
6990
|
-
|
|
6991
|
-
|
|
6992
|
-
|
|
6993
|
-
|
|
6994
|
-
|
|
6995
|
-
|
|
6996
|
-
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
|
|
7002
|
-
|
|
7003
|
-
}
|
|
7004
|
-
const originalDescriptor = shared.getOwnPropertyDescriptor(tmpl, 'stylesheetTokens');
|
|
7005
|
-
shared.defineProperty(tmpl, 'stylesheetTokens', {
|
|
7006
|
-
enumerable: true,
|
|
7007
|
-
configurable: true,
|
|
7008
|
-
get: originalDescriptor.get,
|
|
7009
|
-
set(value) {
|
|
7010
|
-
reportTemplateViolation('stylesheetTokens');
|
|
7011
|
-
// Avoid logging/reporting twice (for both stylesheetToken and stylesheetTokens)
|
|
7012
|
-
mutationTrackingDisabled = true;
|
|
7013
|
-
originalDescriptor.set.call(this, value);
|
|
7014
|
-
mutationTrackingDisabled = false;
|
|
6721
|
+
if (!shared.isUndefined(tmpl.stylesheets)) {
|
|
6722
|
+
trackStylesheetsMutation(tmpl.stylesheets);
|
|
6723
|
+
}
|
|
6724
|
+
for (const prop of TEMPLATE_PROPS) {
|
|
6725
|
+
let value = tmpl[prop];
|
|
6726
|
+
shared.defineProperty(tmpl, prop, {
|
|
6727
|
+
enumerable: true,
|
|
6728
|
+
configurable: true,
|
|
6729
|
+
get() {
|
|
6730
|
+
return value;
|
|
6731
|
+
},
|
|
6732
|
+
set(newValue) {
|
|
6733
|
+
if (!mutationTrackingDisabled) {
|
|
6734
|
+
reportTemplateViolation(prop);
|
|
6735
|
+
}
|
|
6736
|
+
value = newValue;
|
|
6737
|
+
},
|
|
6738
|
+
});
|
|
7015
6739
|
}
|
|
7016
|
-
|
|
6740
|
+
const originalDescriptor = shared.getOwnPropertyDescriptor(tmpl, 'stylesheetTokens');
|
|
6741
|
+
shared.defineProperty(tmpl, 'stylesheetTokens', {
|
|
6742
|
+
enumerable: true,
|
|
6743
|
+
configurable: true,
|
|
6744
|
+
get: originalDescriptor.get,
|
|
6745
|
+
set(value) {
|
|
6746
|
+
reportTemplateViolation('stylesheetTokens');
|
|
6747
|
+
// Avoid logging/reporting twice (for both stylesheetToken and stylesheetTokens)
|
|
6748
|
+
mutationTrackingDisabled = true;
|
|
6749
|
+
originalDescriptor.set.call(this, value);
|
|
6750
|
+
mutationTrackingDisabled = false;
|
|
6751
|
+
},
|
|
6752
|
+
});
|
|
7017
6753
|
}
|
|
7018
6754
|
function addLegacyStylesheetTokensShim(tmpl) {
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
|
|
7024
|
-
|
|
7025
|
-
|
|
7026
|
-
|
|
7027
|
-
|
|
7028
|
-
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
|
|
7034
|
-
|
|
7035
|
-
|
|
7036
|
-
|
|
7037
|
-
|
|
7038
|
-
|
|
7039
|
-
|
|
7040
|
-
|
|
7041
|
-
|
|
7042
|
-
|
|
7043
|
-
}
|
|
7044
|
-
});
|
|
6755
|
+
// When ENABLE_FROZEN_TEMPLATE is false, then we shim stylesheetTokens on top of stylesheetToken for anyone who
|
|
6756
|
+
// is accessing the old internal API (backwards compat). Details: https://salesforce.quip.com/v1rmAFu2cKAr
|
|
6757
|
+
shared.defineProperty(tmpl, 'stylesheetTokens', {
|
|
6758
|
+
enumerable: true,
|
|
6759
|
+
configurable: true,
|
|
6760
|
+
get() {
|
|
6761
|
+
const { stylesheetToken } = this;
|
|
6762
|
+
if (shared.isUndefined(stylesheetToken)) {
|
|
6763
|
+
return stylesheetToken;
|
|
6764
|
+
}
|
|
6765
|
+
// Shim for the old `stylesheetTokens` property
|
|
6766
|
+
// See https://github.com/salesforce/lwc/pull/2332/files#diff-7901555acef29969adaa6583185b3e9bce475cdc6f23e799a54e0018cb18abaa
|
|
6767
|
+
return {
|
|
6768
|
+
hostAttribute: `${stylesheetToken}-host`,
|
|
6769
|
+
shadowAttribute: stylesheetToken,
|
|
6770
|
+
};
|
|
6771
|
+
},
|
|
6772
|
+
set(value) {
|
|
6773
|
+
// If the value is null or some other exotic object, you would be broken anyway in the past
|
|
6774
|
+
// because the engine would try to access hostAttribute/shadowAttribute, which would throw an error.
|
|
6775
|
+
// However it may be undefined in newer versions of LWC, so we need to guard against that case.
|
|
6776
|
+
this.stylesheetToken = shared.isUndefined(value) ? undefined : value.shadowAttribute;
|
|
6777
|
+
},
|
|
6778
|
+
});
|
|
7045
6779
|
}
|
|
7046
6780
|
function freezeTemplate(tmpl) {
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
|
|
6781
|
+
// TODO [#2782]: remove this flag and delete the legacy behavior
|
|
6782
|
+
if (lwcRuntimeFlags.ENABLE_FROZEN_TEMPLATE) {
|
|
6783
|
+
// Deep freeze the template
|
|
6784
|
+
shared.freeze(tmpl);
|
|
6785
|
+
if (!shared.isUndefined(tmpl.stylesheets)) {
|
|
6786
|
+
deepFreeze(tmpl.stylesheets);
|
|
6787
|
+
}
|
|
7053
6788
|
}
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7061
|
-
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
6789
|
+
else {
|
|
6790
|
+
// template is not frozen - shim, report, and warn
|
|
6791
|
+
// this shim should be applied in both dev and prod
|
|
6792
|
+
addLegacyStylesheetTokensShim(tmpl);
|
|
6793
|
+
// When ENABLE_FROZEN_TEMPLATE is false, we want to warn in dev mode whenever someone is mutating the template
|
|
6794
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
6795
|
+
trackMutations(tmpl);
|
|
6796
|
+
}
|
|
6797
|
+
else {
|
|
6798
|
+
// In prod mode, we only track mutations if reporting is enabled
|
|
6799
|
+
onReportingEnabled(() => {
|
|
6800
|
+
trackMutations(tmpl);
|
|
6801
|
+
});
|
|
6802
|
+
}
|
|
7066
6803
|
}
|
|
7067
|
-
}
|
|
7068
6804
|
}
|
|
7069
6805
|
|
|
7070
6806
|
/*
|
|
@@ -7128,4 +6864,4 @@ exports.swapTemplate = swapTemplate;
|
|
|
7128
6864
|
exports.track = track;
|
|
7129
6865
|
exports.unwrap = unwrap;
|
|
7130
6866
|
exports.wire = wire;
|
|
7131
|
-
/* version: 2.37.
|
|
6867
|
+
/* version: 2.37.2 */
|