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