lwc 2.32.1 → 2.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/engine-dom/esm/es2017/engine-dom.js +842 -595
- package/dist/engine-dom/iife/es2017/engine-dom.js +842 -595
- package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
- package/dist/engine-dom/iife/es2017/engine-dom_debug.js +758 -501
- package/dist/engine-dom/iife/es5/engine-dom.js +316 -177
- package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
- package/dist/engine-dom/iife/es5/engine-dom_debug.js +329 -173
- package/dist/engine-dom/umd/es2017/engine-dom.js +842 -595
- package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
- package/dist/engine-dom/umd/es2017/engine-dom_debug.js +758 -501
- package/dist/engine-dom/umd/es5/engine-dom.js +316 -177
- package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
- package/dist/engine-dom/umd/es5/engine-dom_debug.js +329 -173
- package/dist/engine-server/commonjs/es2017/engine-server.js +807 -507
- package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
- package/dist/engine-server/esm/es2017/engine-server.js +807 -507
- package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
- package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
- package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
- package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
- package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +7 -5
- package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
- package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +7 -5
- package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
- package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
- package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
- package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +7 -5
- package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
- package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +7 -5
- package/dist/wire-service/esm/es2017/wire-service.js +2 -2
- package/dist/wire-service/iife/es2017/wire-service.js +2 -2
- package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
- package/dist/wire-service/iife/es5/wire-service.js +5 -3
- package/dist/wire-service/iife/es5/wire-service.min.js +1 -1
- package/dist/wire-service/iife/es5/wire-service_debug.js +5 -3
- package/dist/wire-service/umd/es2017/wire-service.js +2 -2
- package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
- package/dist/wire-service/umd/es5/wire-service.js +5 -3
- package/dist/wire-service/umd/es5/wire-service.min.js +1 -1
- package/dist/wire-service/umd/es5/wire-service_debug.js +5 -3
- package/package.json +7 -7
|
@@ -120,6 +120,9 @@ function getPropertyDescriptor(o, p) {
|
|
|
120
120
|
* The above list of 46 aria attributes is consistent with the following resources:
|
|
121
121
|
* https://github.com/w3c/aria/pull/708/files#diff-eacf331f0ffc35d4b482f1d15a887d3bR11060
|
|
122
122
|
* https://wicg.github.io/aom/spec/aria-reflection.html
|
|
123
|
+
*
|
|
124
|
+
* NOTE: If you update this list, please update test files that implicitly reference this list!
|
|
125
|
+
* Searching the codebase for `aria-flowto` and `ariaFlowTo` should be good enough to find all usages.
|
|
123
126
|
*/
|
|
124
127
|
const AriaPropertyNames = [
|
|
125
128
|
'ariaActiveDescendant',
|
|
@@ -469,9 +472,9 @@ function htmlEscape(str, attrMode = false) {
|
|
|
469
472
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
470
473
|
*/
|
|
471
474
|
// Increment whenever the LWC template compiler changes
|
|
472
|
-
const LWC_VERSION = "2.
|
|
475
|
+
const LWC_VERSION = "2.34.0";
|
|
473
476
|
const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
|
|
474
|
-
/** version: 2.
|
|
477
|
+
/** version: 2.34.0 */
|
|
475
478
|
|
|
476
479
|
/*
|
|
477
480
|
* Copyright (c) 2020, salesforce.com, inc.
|
|
@@ -525,6 +528,8 @@ const features = {
|
|
|
525
528
|
DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
|
|
526
529
|
ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
|
|
527
530
|
ENABLE_FROZEN_TEMPLATE: null,
|
|
531
|
+
DISABLE_ARIA_REFLECTION_POLYFILL: null,
|
|
532
|
+
ENABLE_PROGRAMMATIC_STYLESHEETS: null,
|
|
528
533
|
};
|
|
529
534
|
if (!_globalThis.lwcRuntimeFlags) {
|
|
530
535
|
Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
|
|
@@ -578,7 +583,71 @@ function setFeatureFlagForTest(name, value) {
|
|
|
578
583
|
setFeatureFlag(name, value);
|
|
579
584
|
}
|
|
580
585
|
}
|
|
581
|
-
/** version: 2.
|
|
586
|
+
/** version: 2.34.0 */
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Copyright (C) 2018 salesforce.com, inc.
|
|
590
|
+
*/
|
|
591
|
+
|
|
592
|
+
/*
|
|
593
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
594
|
+
* All rights reserved.
|
|
595
|
+
* SPDX-License-Identifier: MIT
|
|
596
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
597
|
+
*/
|
|
598
|
+
function detect(propName, prototype) {
|
|
599
|
+
return isUndefined$1(getOwnPropertyDescriptor$1(prototype, propName));
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/*
|
|
603
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
604
|
+
* All rights reserved.
|
|
605
|
+
* SPDX-License-Identifier: MIT
|
|
606
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
607
|
+
*/
|
|
608
|
+
function createAriaPropertyPropertyDescriptor(attrName) {
|
|
609
|
+
// Note that we need to call this.{get,set,has,remove}Attribute rather than dereferencing
|
|
610
|
+
// from Element.prototype, because these methods are overridden in LightningElement.
|
|
611
|
+
return {
|
|
612
|
+
get() {
|
|
613
|
+
// reflect what's in the attribute
|
|
614
|
+
return this.hasAttribute(attrName) ? this.getAttribute(attrName) : null;
|
|
615
|
+
},
|
|
616
|
+
set(newValue) {
|
|
617
|
+
// reflect into the corresponding attribute
|
|
618
|
+
if (isNull(newValue)) {
|
|
619
|
+
this.removeAttribute(attrName);
|
|
620
|
+
}
|
|
621
|
+
else {
|
|
622
|
+
this.setAttribute(attrName, newValue);
|
|
623
|
+
}
|
|
624
|
+
},
|
|
625
|
+
configurable: true,
|
|
626
|
+
enumerable: true,
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
function patch$1(propName, prototype) {
|
|
630
|
+
const attrName = AriaPropNameToAttrNameMap[propName];
|
|
631
|
+
const descriptor = createAriaPropertyPropertyDescriptor(attrName);
|
|
632
|
+
defineProperty(prototype, propName, descriptor);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/*
|
|
636
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
637
|
+
* All rights reserved.
|
|
638
|
+
* SPDX-License-Identifier: MIT
|
|
639
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
640
|
+
*/
|
|
641
|
+
function applyAriaReflection(prototype = Element.prototype) {
|
|
642
|
+
const ElementPrototypeAriaPropertyNames = keys(AriaPropNameToAttrNameMap);
|
|
643
|
+
for (let i = 0, len = ElementPrototypeAriaPropertyNames.length; i < len; i += 1) {
|
|
644
|
+
const propName = ElementPrototypeAriaPropertyNames[i];
|
|
645
|
+
if (detect(propName, prototype)) {
|
|
646
|
+
patch$1(propName, prototype);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
/** version: 2.34.0 */
|
|
582
651
|
|
|
583
652
|
/* proxy-compat-disable */
|
|
584
653
|
|
|
@@ -744,6 +813,7 @@ function log(method, message, vm) {
|
|
|
744
813
|
if (!isUndefined$1(vm)) {
|
|
745
814
|
msg = `${msg}\n${getComponentStack(vm)}`;
|
|
746
815
|
}
|
|
816
|
+
// In Jest tests, reduce the warning and error verbosity by not printing the callstack
|
|
747
817
|
if (process.env.NODE_ENV === 'test') {
|
|
748
818
|
/* eslint-disable-next-line no-console */
|
|
749
819
|
console[method](msg);
|
|
@@ -810,6 +880,9 @@ function offsetPropertyErrorMessage(name) {
|
|
|
810
880
|
// Global HTML Attributes & Properties
|
|
811
881
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
|
|
812
882
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
|
|
883
|
+
//
|
|
884
|
+
// If you update this list, check for test files that recapitulate the same list. Searching the codebase
|
|
885
|
+
// for e.g. "dropzone" should suffice.
|
|
813
886
|
const globalHTMLProperties = assign(create(null), {
|
|
814
887
|
accessKey: {
|
|
815
888
|
attribute: 'accesskey',
|
|
@@ -1835,45 +1908,50 @@ function getReactiveProxy(value) {
|
|
|
1835
1908
|
* for the Base Lightning Element, it also include the reactivity bit, so the standard property is reactive.
|
|
1836
1909
|
*/
|
|
1837
1910
|
function createBridgeToElementDescriptor(propName, descriptor) {
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1911
|
+
const {
|
|
1912
|
+
get,
|
|
1913
|
+
set,
|
|
1914
|
+
enumerable,
|
|
1915
|
+
configurable
|
|
1916
|
+
} = descriptor;
|
|
1917
|
+
if (!isFunction$1(get)) {
|
|
1918
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1919
|
+
assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
|
|
1920
|
+
}
|
|
1921
|
+
throw new TypeError();
|
|
1922
|
+
}
|
|
1923
|
+
if (!isFunction$1(set)) {
|
|
1924
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1925
|
+
assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
|
|
1844
1926
|
}
|
|
1845
|
-
|
|
1927
|
+
throw new TypeError();
|
|
1928
|
+
}
|
|
1929
|
+
return {
|
|
1930
|
+
enumerable,
|
|
1931
|
+
configurable,
|
|
1932
|
+
get() {
|
|
1933
|
+
const vm = getAssociatedVM(this);
|
|
1934
|
+
if (isBeingConstructed(vm)) {
|
|
1846
1935
|
if (process.env.NODE_ENV !== 'production') {
|
|
1847
|
-
|
|
1936
|
+
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);
|
|
1848
1937
|
}
|
|
1849
|
-
|
|
1938
|
+
return;
|
|
1939
|
+
}
|
|
1940
|
+
return get.call(vm.elm);
|
|
1941
|
+
},
|
|
1942
|
+
set(newValue) {
|
|
1943
|
+
const vm = getAssociatedVM(this);
|
|
1944
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1945
|
+
const vmBeingRendered = getVMBeingRendered();
|
|
1946
|
+
assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
|
|
1947
|
+
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}`);
|
|
1948
|
+
assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
|
|
1949
|
+
assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
|
|
1950
|
+
}
|
|
1951
|
+
updateComponentValue(vm, propName, newValue);
|
|
1952
|
+
return set.call(vm.elm, newValue);
|
|
1850
1953
|
}
|
|
1851
|
-
|
|
1852
|
-
enumerable,
|
|
1853
|
-
configurable,
|
|
1854
|
-
get() {
|
|
1855
|
-
const vm = getAssociatedVM(this);
|
|
1856
|
-
if (isBeingConstructed(vm)) {
|
|
1857
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1858
|
-
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);
|
|
1859
|
-
}
|
|
1860
|
-
return;
|
|
1861
|
-
}
|
|
1862
|
-
return get.call(vm.elm);
|
|
1863
|
-
},
|
|
1864
|
-
set(newValue) {
|
|
1865
|
-
const vm = getAssociatedVM(this);
|
|
1866
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1867
|
-
const vmBeingRendered = getVMBeingRendered();
|
|
1868
|
-
assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
|
|
1869
|
-
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}`);
|
|
1870
|
-
assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
|
|
1871
|
-
assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
|
|
1872
|
-
}
|
|
1873
|
-
updateComponentValue(vm, propName, newValue);
|
|
1874
|
-
return set.call(vm.elm, newValue);
|
|
1875
|
-
},
|
|
1876
|
-
};
|
|
1954
|
+
};
|
|
1877
1955
|
}
|
|
1878
1956
|
const EMPTY_REFS = freeze(create(null));
|
|
1879
1957
|
const refsCache = new WeakMap();
|
|
@@ -1883,344 +1961,443 @@ const refsCache = new WeakMap();
|
|
|
1883
1961
|
**/
|
|
1884
1962
|
// @ts-ignore
|
|
1885
1963
|
const LightningElement = function () {
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1964
|
+
// This should be as performant as possible, while any initialization should be done lazily
|
|
1965
|
+
if (isNull(vmBeingConstructed)) {
|
|
1966
|
+
// Thrown when doing something like `new LightningElement()` or
|
|
1967
|
+
// `class Foo extends LightningElement {}; new Foo()`
|
|
1968
|
+
throw new TypeError('Illegal constructor');
|
|
1969
|
+
}
|
|
1970
|
+
const vm = vmBeingConstructed;
|
|
1971
|
+
const {
|
|
1972
|
+
def,
|
|
1973
|
+
elm
|
|
1974
|
+
} = vm;
|
|
1975
|
+
const {
|
|
1976
|
+
bridge
|
|
1977
|
+
} = def;
|
|
1978
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1979
|
+
const {
|
|
1980
|
+
assertInstanceOfHTMLElement
|
|
1981
|
+
} = vm.renderer;
|
|
1982
|
+
assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
|
|
1983
|
+
}
|
|
1984
|
+
const component = this;
|
|
1985
|
+
setPrototypeOf(elm, bridge.prototype);
|
|
1986
|
+
vm.component = this;
|
|
1987
|
+
// Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
|
|
1988
|
+
// component creation and passes hooks to instrument all the component interactions with the
|
|
1989
|
+
// engine. We are intentionally hiding this argument from the formal API of LightningElement
|
|
1990
|
+
// because we don't want folks to know about it just yet.
|
|
1991
|
+
if (arguments.length === 1) {
|
|
1992
|
+
const {
|
|
1993
|
+
callHook,
|
|
1994
|
+
setHook,
|
|
1995
|
+
getHook
|
|
1996
|
+
} = arguments[0];
|
|
1997
|
+
vm.callHook = callHook;
|
|
1998
|
+
vm.setHook = setHook;
|
|
1999
|
+
vm.getHook = getHook;
|
|
2000
|
+
}
|
|
2001
|
+
// Linking elm, shadow root and component with the VM.
|
|
2002
|
+
associateVM(component, vm);
|
|
2003
|
+
associateVM(elm, vm);
|
|
2004
|
+
if (vm.renderMode === 1 /* RenderMode.Shadow */) {
|
|
2005
|
+
vm.renderRoot = doAttachShadow(vm);
|
|
2006
|
+
} else {
|
|
2007
|
+
vm.renderRoot = elm;
|
|
2008
|
+
}
|
|
2009
|
+
// Adding extra guard rails in DEV mode.
|
|
2010
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2011
|
+
patchCustomElementWithRestrictions(elm);
|
|
2012
|
+
patchComponentWithRestrictions(component);
|
|
2013
|
+
}
|
|
2014
|
+
return this;
|
|
2015
|
+
};
|
|
2016
|
+
function doAttachShadow(vm) {
|
|
2017
|
+
const {
|
|
2018
|
+
elm,
|
|
2019
|
+
mode,
|
|
2020
|
+
shadowMode,
|
|
2021
|
+
def: {
|
|
2022
|
+
ctor
|
|
2023
|
+
},
|
|
2024
|
+
renderer: {
|
|
2025
|
+
attachShadow
|
|
2026
|
+
}
|
|
2027
|
+
} = vm;
|
|
2028
|
+
const shadowRoot = attachShadow(elm, {
|
|
2029
|
+
[KEY__SYNTHETIC_MODE]: shadowMode === 1 /* ShadowMode.Synthetic */,
|
|
2030
|
+
delegatesFocus: Boolean(ctor.delegatesFocus),
|
|
2031
|
+
mode
|
|
2032
|
+
});
|
|
2033
|
+
vm.shadowRoot = shadowRoot;
|
|
2034
|
+
associateVM(shadowRoot, vm);
|
|
2035
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2036
|
+
patchShadowRootWithRestrictions(shadowRoot);
|
|
2037
|
+
}
|
|
2038
|
+
return shadowRoot;
|
|
2039
|
+
}
|
|
2040
|
+
function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
|
|
2041
|
+
if (isBeingConstructed(vm)) {
|
|
2042
|
+
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.`);
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
// @ts-ignore
|
|
2046
|
+
LightningElement.prototype = {
|
|
2047
|
+
constructor: LightningElement,
|
|
2048
|
+
dispatchEvent(event) {
|
|
2049
|
+
const vm = getAssociatedVM(this);
|
|
2050
|
+
const {
|
|
2051
|
+
elm,
|
|
2052
|
+
renderer: {
|
|
2053
|
+
dispatchEvent
|
|
2054
|
+
}
|
|
2055
|
+
} = vm;
|
|
2056
|
+
return dispatchEvent(elm, event);
|
|
2057
|
+
},
|
|
2058
|
+
addEventListener(type, listener, options) {
|
|
2059
|
+
const vm = getAssociatedVM(this);
|
|
2060
|
+
const {
|
|
2061
|
+
elm,
|
|
2062
|
+
renderer: {
|
|
2063
|
+
addEventListener
|
|
2064
|
+
}
|
|
2065
|
+
} = vm;
|
|
1895
2066
|
if (process.env.NODE_ENV !== 'production') {
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
2067
|
+
const vmBeingRendered = getVMBeingRendered();
|
|
2068
|
+
assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
|
|
2069
|
+
assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
|
|
2070
|
+
assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
|
|
2071
|
+
}
|
|
2072
|
+
const wrappedListener = getWrappedComponentsListener(vm, listener);
|
|
2073
|
+
addEventListener(elm, type, wrappedListener, options);
|
|
2074
|
+
},
|
|
2075
|
+
removeEventListener(type, listener, options) {
|
|
2076
|
+
const vm = getAssociatedVM(this);
|
|
2077
|
+
const {
|
|
2078
|
+
elm,
|
|
2079
|
+
renderer: {
|
|
2080
|
+
removeEventListener
|
|
2081
|
+
}
|
|
2082
|
+
} = vm;
|
|
2083
|
+
const wrappedListener = getWrappedComponentsListener(vm, listener);
|
|
2084
|
+
removeEventListener(elm, type, wrappedListener, options);
|
|
2085
|
+
},
|
|
2086
|
+
hasAttribute(name) {
|
|
2087
|
+
const vm = getAssociatedVM(this);
|
|
2088
|
+
const {
|
|
2089
|
+
elm,
|
|
2090
|
+
renderer: {
|
|
2091
|
+
getAttribute
|
|
2092
|
+
}
|
|
2093
|
+
} = vm;
|
|
2094
|
+
return !isNull(getAttribute(elm, name));
|
|
2095
|
+
},
|
|
2096
|
+
hasAttributeNS(namespace, name) {
|
|
2097
|
+
const vm = getAssociatedVM(this);
|
|
2098
|
+
const {
|
|
2099
|
+
elm,
|
|
2100
|
+
renderer: {
|
|
2101
|
+
getAttribute
|
|
2102
|
+
}
|
|
2103
|
+
} = vm;
|
|
2104
|
+
return !isNull(getAttribute(elm, name, namespace));
|
|
2105
|
+
},
|
|
2106
|
+
removeAttribute(name) {
|
|
2107
|
+
const vm = getAssociatedVM(this);
|
|
2108
|
+
const {
|
|
2109
|
+
elm,
|
|
2110
|
+
renderer: {
|
|
2111
|
+
removeAttribute
|
|
2112
|
+
}
|
|
2113
|
+
} = vm;
|
|
2114
|
+
unlockAttribute(elm, name);
|
|
2115
|
+
removeAttribute(elm, name);
|
|
2116
|
+
lockAttribute();
|
|
2117
|
+
},
|
|
2118
|
+
removeAttributeNS(namespace, name) {
|
|
2119
|
+
const {
|
|
2120
|
+
elm,
|
|
2121
|
+
renderer: {
|
|
2122
|
+
removeAttribute
|
|
2123
|
+
}
|
|
2124
|
+
} = getAssociatedVM(this);
|
|
2125
|
+
unlockAttribute(elm, name);
|
|
2126
|
+
removeAttribute(elm, name, namespace);
|
|
2127
|
+
lockAttribute();
|
|
2128
|
+
},
|
|
2129
|
+
getAttribute(name) {
|
|
2130
|
+
const vm = getAssociatedVM(this);
|
|
2131
|
+
const {
|
|
2132
|
+
elm
|
|
2133
|
+
} = vm;
|
|
2134
|
+
const {
|
|
2135
|
+
getAttribute
|
|
2136
|
+
} = vm.renderer;
|
|
2137
|
+
return getAttribute(elm, name);
|
|
2138
|
+
},
|
|
2139
|
+
getAttributeNS(namespace, name) {
|
|
2140
|
+
const vm = getAssociatedVM(this);
|
|
2141
|
+
const {
|
|
2142
|
+
elm
|
|
2143
|
+
} = vm;
|
|
2144
|
+
const {
|
|
2145
|
+
getAttribute
|
|
2146
|
+
} = vm.renderer;
|
|
2147
|
+
return getAttribute(elm, name, namespace);
|
|
2148
|
+
},
|
|
2149
|
+
setAttribute(name, value) {
|
|
2150
|
+
const vm = getAssociatedVM(this);
|
|
2151
|
+
const {
|
|
2152
|
+
elm,
|
|
2153
|
+
renderer: {
|
|
2154
|
+
setAttribute
|
|
2155
|
+
}
|
|
2156
|
+
} = vm;
|
|
2157
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2158
|
+
assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
|
|
2159
|
+
}
|
|
2160
|
+
unlockAttribute(elm, name);
|
|
2161
|
+
setAttribute(elm, name, value);
|
|
2162
|
+
lockAttribute();
|
|
2163
|
+
},
|
|
2164
|
+
setAttributeNS(namespace, name, value) {
|
|
2165
|
+
const vm = getAssociatedVM(this);
|
|
2166
|
+
const {
|
|
2167
|
+
elm,
|
|
2168
|
+
renderer: {
|
|
2169
|
+
setAttribute
|
|
2170
|
+
}
|
|
2171
|
+
} = vm;
|
|
2172
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2173
|
+
assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
|
|
2174
|
+
}
|
|
2175
|
+
unlockAttribute(elm, name);
|
|
2176
|
+
setAttribute(elm, name, value, namespace);
|
|
2177
|
+
lockAttribute();
|
|
2178
|
+
},
|
|
2179
|
+
getBoundingClientRect() {
|
|
2180
|
+
const vm = getAssociatedVM(this);
|
|
2181
|
+
const {
|
|
2182
|
+
elm,
|
|
2183
|
+
renderer: {
|
|
2184
|
+
getBoundingClientRect
|
|
2185
|
+
}
|
|
2186
|
+
} = vm;
|
|
2187
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2188
|
+
warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
|
|
1911
2189
|
}
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
2190
|
+
return getBoundingClientRect(elm);
|
|
2191
|
+
},
|
|
2192
|
+
get isConnected() {
|
|
2193
|
+
const vm = getAssociatedVM(this);
|
|
2194
|
+
const {
|
|
2195
|
+
elm,
|
|
2196
|
+
renderer: {
|
|
2197
|
+
isConnected
|
|
2198
|
+
}
|
|
2199
|
+
} = vm;
|
|
2200
|
+
return isConnected(elm);
|
|
2201
|
+
},
|
|
2202
|
+
get classList() {
|
|
2203
|
+
const vm = getAssociatedVM(this);
|
|
2204
|
+
const {
|
|
2205
|
+
elm,
|
|
2206
|
+
renderer: {
|
|
2207
|
+
getClassList
|
|
2208
|
+
}
|
|
2209
|
+
} = vm;
|
|
2210
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2211
|
+
// TODO [#1290]: this still fails in dev but works in production, eventually, we should
|
|
2212
|
+
// just throw in all modes
|
|
2213
|
+
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.`);
|
|
2214
|
+
}
|
|
2215
|
+
return getClassList(elm);
|
|
2216
|
+
},
|
|
2217
|
+
get template() {
|
|
2218
|
+
const vm = getAssociatedVM(this);
|
|
2219
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2220
|
+
if (vm.renderMode === 0 /* RenderMode.Light */) {
|
|
2221
|
+
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`.');
|
|
2222
|
+
}
|
|
1917
2223
|
}
|
|
1918
|
-
|
|
1919
|
-
|
|
2224
|
+
return vm.shadowRoot;
|
|
2225
|
+
},
|
|
2226
|
+
get refs() {
|
|
2227
|
+
const vm = getAssociatedVM(this);
|
|
2228
|
+
if (isUpdatingTemplate) {
|
|
2229
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2230
|
+
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().`);
|
|
2231
|
+
}
|
|
2232
|
+
// If the template is in the process of being updated, then we don't want to go through the normal
|
|
2233
|
+
// process of returning the refs and caching them, because the state of the refs is unstable.
|
|
2234
|
+
// This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
|
|
2235
|
+
// based on `this.refs.bar`.
|
|
2236
|
+
return;
|
|
1920
2237
|
}
|
|
1921
|
-
// Adding extra guard rails in DEV mode.
|
|
1922
2238
|
if (process.env.NODE_ENV !== 'production') {
|
|
1923
|
-
|
|
1924
|
-
patchComponentWithRestrictions(component);
|
|
2239
|
+
warnIfInvokedDuringConstruction(vm, 'refs');
|
|
1925
2240
|
}
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
2241
|
+
const {
|
|
2242
|
+
refVNodes,
|
|
2243
|
+
hasRefVNodes,
|
|
2244
|
+
cmpTemplate
|
|
2245
|
+
} = vm;
|
|
2246
|
+
// If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
|
|
2247
|
+
// if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
|
|
2248
|
+
// so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
|
|
2249
|
+
// `warnIfInvokedDuringConstruction` above).
|
|
2250
|
+
if (process.env.NODE_ENV !== 'production' && isNull(cmpTemplate) && !isBeingConstructed(vm)) {
|
|
2251
|
+
logError(`this.refs is undefined for ${getComponentTag(vm)}. This is either because the attached template has no "lwc:ref" directive, or this.refs was ` + `invoked before renderedCallback(). Use this.refs only when the referenced HTML elements have ` + `been rendered to the DOM, such as within renderedCallback() or disconnectedCallback().`);
|
|
2252
|
+
}
|
|
2253
|
+
// For backwards compatibility with component written before template refs
|
|
2254
|
+
// were introduced, we return undefined if the template has no refs defined
|
|
2255
|
+
// anywhere. This fixes components that may want to add an expando called `refs`
|
|
2256
|
+
// and are checking if it exists with `if (this.refs)` before adding it.
|
|
2257
|
+
// Note it is not sufficient to just check if `refVNodes` is null or empty,
|
|
2258
|
+
// because a template may have `lwc:ref` defined within a falsy `if:true` block.
|
|
2259
|
+
if (!hasRefVNodes) {
|
|
2260
|
+
return;
|
|
2261
|
+
}
|
|
2262
|
+
// For templates that are using `lwc:ref`, if there are no refs currently available
|
|
2263
|
+
// (e.g. refs inside of a falsy `if:true` block), we return an empty object.
|
|
2264
|
+
if (isNull(refVNodes)) {
|
|
2265
|
+
return EMPTY_REFS;
|
|
2266
|
+
}
|
|
2267
|
+
// The refNodes can be cached based on the refVNodes, since the refVNodes
|
|
2268
|
+
// are recreated from scratch every time the template is rendered.
|
|
2269
|
+
// This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
|
|
2270
|
+
let refs = refsCache.get(refVNodes);
|
|
2271
|
+
if (isUndefined$1(refs)) {
|
|
2272
|
+
refs = create(null);
|
|
2273
|
+
for (const key of keys(refVNodes)) {
|
|
2274
|
+
refs[key] = refVNodes[key].elm;
|
|
2275
|
+
}
|
|
2276
|
+
freeze(refs);
|
|
2277
|
+
refsCache.set(refVNodes, refs);
|
|
2278
|
+
}
|
|
2279
|
+
return refs;
|
|
2280
|
+
},
|
|
2281
|
+
// For backwards compat, we allow component authors to set `refs` as an expando
|
|
2282
|
+
set refs(value) {
|
|
2283
|
+
defineProperty(this, 'refs', {
|
|
2284
|
+
configurable: true,
|
|
2285
|
+
enumerable: true,
|
|
2286
|
+
writable: true,
|
|
2287
|
+
value
|
|
1934
2288
|
});
|
|
1935
|
-
|
|
1936
|
-
|
|
2289
|
+
},
|
|
2290
|
+
get shadowRoot() {
|
|
2291
|
+
// From within the component instance, the shadowRoot is always reported as "closed".
|
|
2292
|
+
// Authors should rely on this.template instead.
|
|
2293
|
+
return null;
|
|
2294
|
+
},
|
|
2295
|
+
get children() {
|
|
2296
|
+
const vm = getAssociatedVM(this);
|
|
2297
|
+
const renderer = vm.renderer;
|
|
1937
2298
|
if (process.env.NODE_ENV !== 'production') {
|
|
1938
|
-
|
|
2299
|
+
warnIfInvokedDuringConstruction(vm, 'children');
|
|
1939
2300
|
}
|
|
1940
|
-
return
|
|
1941
|
-
}
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
2301
|
+
return renderer.getChildren(vm.elm);
|
|
2302
|
+
},
|
|
2303
|
+
get childNodes() {
|
|
2304
|
+
const vm = getAssociatedVM(this);
|
|
2305
|
+
const renderer = vm.renderer;
|
|
2306
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2307
|
+
warnIfInvokedDuringConstruction(vm, 'childNodes');
|
|
1945
2308
|
}
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
}
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
lockAttribute();
|
|
1989
|
-
},
|
|
1990
|
-
removeAttributeNS(namespace, name) {
|
|
1991
|
-
const { elm, renderer: { removeAttribute }, } = getAssociatedVM(this);
|
|
1992
|
-
unlockAttribute(elm, name);
|
|
1993
|
-
removeAttribute(elm, name, namespace);
|
|
1994
|
-
lockAttribute();
|
|
1995
|
-
},
|
|
1996
|
-
getAttribute(name) {
|
|
1997
|
-
const vm = getAssociatedVM(this);
|
|
1998
|
-
const { elm } = vm;
|
|
1999
|
-
const { getAttribute } = vm.renderer;
|
|
2000
|
-
return getAttribute(elm, name);
|
|
2001
|
-
},
|
|
2002
|
-
getAttributeNS(namespace, name) {
|
|
2003
|
-
const vm = getAssociatedVM(this);
|
|
2004
|
-
const { elm } = vm;
|
|
2005
|
-
const { getAttribute } = vm.renderer;
|
|
2006
|
-
return getAttribute(elm, name, namespace);
|
|
2007
|
-
},
|
|
2008
|
-
setAttribute(name, value) {
|
|
2009
|
-
const vm = getAssociatedVM(this);
|
|
2010
|
-
const { elm, renderer: { setAttribute }, } = vm;
|
|
2011
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2012
|
-
assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
|
|
2013
|
-
}
|
|
2014
|
-
unlockAttribute(elm, name);
|
|
2015
|
-
setAttribute(elm, name, value);
|
|
2016
|
-
lockAttribute();
|
|
2017
|
-
},
|
|
2018
|
-
setAttributeNS(namespace, name, value) {
|
|
2019
|
-
const vm = getAssociatedVM(this);
|
|
2020
|
-
const { elm, renderer: { setAttribute }, } = vm;
|
|
2021
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2022
|
-
assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
|
|
2023
|
-
}
|
|
2024
|
-
unlockAttribute(elm, name);
|
|
2025
|
-
setAttribute(elm, name, value, namespace);
|
|
2026
|
-
lockAttribute();
|
|
2027
|
-
},
|
|
2028
|
-
getBoundingClientRect() {
|
|
2029
|
-
const vm = getAssociatedVM(this);
|
|
2030
|
-
const { elm, renderer: { getBoundingClientRect }, } = vm;
|
|
2031
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2032
|
-
warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
|
|
2033
|
-
}
|
|
2034
|
-
return getBoundingClientRect(elm);
|
|
2035
|
-
},
|
|
2036
|
-
get isConnected() {
|
|
2037
|
-
const vm = getAssociatedVM(this);
|
|
2038
|
-
const { elm, renderer: { isConnected }, } = vm;
|
|
2039
|
-
return isConnected(elm);
|
|
2040
|
-
},
|
|
2041
|
-
get classList() {
|
|
2042
|
-
const vm = getAssociatedVM(this);
|
|
2043
|
-
const { elm, renderer: { getClassList }, } = vm;
|
|
2044
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2045
|
-
// TODO [#1290]: this still fails in dev but works in production, eventually, we should
|
|
2046
|
-
// just throw in all modes
|
|
2047
|
-
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.`);
|
|
2048
|
-
}
|
|
2049
|
-
return getClassList(elm);
|
|
2050
|
-
},
|
|
2051
|
-
get template() {
|
|
2052
|
-
const vm = getAssociatedVM(this);
|
|
2053
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2054
|
-
if (vm.renderMode === 0 /* RenderMode.Light */) {
|
|
2055
|
-
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`.');
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
return vm.shadowRoot;
|
|
2059
|
-
},
|
|
2060
|
-
get refs() {
|
|
2061
|
-
const vm = getAssociatedVM(this);
|
|
2062
|
-
if (isUpdatingTemplate) {
|
|
2063
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2064
|
-
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().`);
|
|
2065
|
-
}
|
|
2066
|
-
// If the template is in the process of being updated, then we don't want to go through the normal
|
|
2067
|
-
// process of returning the refs and caching them, because the state of the refs is unstable.
|
|
2068
|
-
// This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
|
|
2069
|
-
// based on `this.refs.bar`.
|
|
2070
|
-
return;
|
|
2071
|
-
}
|
|
2072
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2073
|
-
warnIfInvokedDuringConstruction(vm, 'refs');
|
|
2074
|
-
}
|
|
2075
|
-
const { refVNodes, hasRefVNodes, cmpTemplate } = vm;
|
|
2076
|
-
// If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
|
|
2077
|
-
// if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
|
|
2078
|
-
// so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
|
|
2079
|
-
// `warnIfInvokedDuringConstruction` above).
|
|
2080
|
-
if (process.env.NODE_ENV !== 'production' &&
|
|
2081
|
-
isNull(cmpTemplate) &&
|
|
2082
|
-
!isBeingConstructed(vm)) {
|
|
2083
|
-
logError(`this.refs is undefined for ${getComponentTag(vm)}. This is either because the attached template has no "lwc:ref" directive, or this.refs was ` +
|
|
2084
|
-
`invoked before renderedCallback(). Use this.refs only when the referenced HTML elements have ` +
|
|
2085
|
-
`been rendered to the DOM, such as within renderedCallback() or disconnectedCallback().`);
|
|
2086
|
-
}
|
|
2087
|
-
// For backwards compatibility with component written before template refs
|
|
2088
|
-
// were introduced, we return undefined if the template has no refs defined
|
|
2089
|
-
// anywhere. This fixes components that may want to add an expando called `refs`
|
|
2090
|
-
// and are checking if it exists with `if (this.refs)` before adding it.
|
|
2091
|
-
// Note it is not sufficient to just check if `refVNodes` is null or empty,
|
|
2092
|
-
// because a template may have `lwc:ref` defined within a falsy `if:true` block.
|
|
2093
|
-
if (!hasRefVNodes) {
|
|
2094
|
-
return;
|
|
2095
|
-
}
|
|
2096
|
-
// For templates that are using `lwc:ref`, if there are no refs currently available
|
|
2097
|
-
// (e.g. refs inside of a falsy `if:true` block), we return an empty object.
|
|
2098
|
-
if (isNull(refVNodes)) {
|
|
2099
|
-
return EMPTY_REFS;
|
|
2100
|
-
}
|
|
2101
|
-
// The refNodes can be cached based on the refVNodes, since the refVNodes
|
|
2102
|
-
// are recreated from scratch every time the template is rendered.
|
|
2103
|
-
// This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
|
|
2104
|
-
let refs = refsCache.get(refVNodes);
|
|
2105
|
-
if (isUndefined$1(refs)) {
|
|
2106
|
-
refs = create(null);
|
|
2107
|
-
for (const key of keys(refVNodes)) {
|
|
2108
|
-
refs[key] = refVNodes[key].elm;
|
|
2109
|
-
}
|
|
2110
|
-
freeze(refs);
|
|
2111
|
-
refsCache.set(refVNodes, refs);
|
|
2112
|
-
}
|
|
2113
|
-
return refs;
|
|
2114
|
-
},
|
|
2115
|
-
// For backwards compat, we allow component authors to set `refs` as an expando
|
|
2116
|
-
set refs(value) {
|
|
2117
|
-
defineProperty(this, 'refs', {
|
|
2118
|
-
configurable: true,
|
|
2119
|
-
enumerable: true,
|
|
2120
|
-
writable: true,
|
|
2121
|
-
value,
|
|
2122
|
-
});
|
|
2123
|
-
},
|
|
2124
|
-
get shadowRoot() {
|
|
2125
|
-
// From within the component instance, the shadowRoot is always reported as "closed".
|
|
2126
|
-
// Authors should rely on this.template instead.
|
|
2127
|
-
return null;
|
|
2128
|
-
},
|
|
2129
|
-
get children() {
|
|
2130
|
-
const vm = getAssociatedVM(this);
|
|
2131
|
-
const renderer = vm.renderer;
|
|
2132
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2133
|
-
warnIfInvokedDuringConstruction(vm, 'children');
|
|
2134
|
-
}
|
|
2135
|
-
return renderer.getChildren(vm.elm);
|
|
2136
|
-
},
|
|
2137
|
-
get childNodes() {
|
|
2138
|
-
const vm = getAssociatedVM(this);
|
|
2139
|
-
const renderer = vm.renderer;
|
|
2140
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2141
|
-
warnIfInvokedDuringConstruction(vm, 'childNodes');
|
|
2142
|
-
}
|
|
2143
|
-
return renderer.getChildNodes(vm.elm);
|
|
2144
|
-
},
|
|
2145
|
-
get firstChild() {
|
|
2146
|
-
const vm = getAssociatedVM(this);
|
|
2147
|
-
const renderer = vm.renderer;
|
|
2148
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2149
|
-
warnIfInvokedDuringConstruction(vm, 'firstChild');
|
|
2150
|
-
}
|
|
2151
|
-
return renderer.getFirstChild(vm.elm);
|
|
2152
|
-
},
|
|
2153
|
-
get firstElementChild() {
|
|
2154
|
-
const vm = getAssociatedVM(this);
|
|
2155
|
-
const renderer = vm.renderer;
|
|
2156
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2157
|
-
warnIfInvokedDuringConstruction(vm, 'firstElementChild');
|
|
2158
|
-
}
|
|
2159
|
-
return renderer.getFirstElementChild(vm.elm);
|
|
2160
|
-
},
|
|
2161
|
-
get lastChild() {
|
|
2162
|
-
const vm = getAssociatedVM(this);
|
|
2163
|
-
const renderer = vm.renderer;
|
|
2164
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2165
|
-
warnIfInvokedDuringConstruction(vm, 'lastChild');
|
|
2166
|
-
}
|
|
2167
|
-
return renderer.getLastChild(vm.elm);
|
|
2168
|
-
},
|
|
2169
|
-
get lastElementChild() {
|
|
2170
|
-
const vm = getAssociatedVM(this);
|
|
2171
|
-
const renderer = vm.renderer;
|
|
2172
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2173
|
-
warnIfInvokedDuringConstruction(vm, 'lastElementChild');
|
|
2174
|
-
}
|
|
2175
|
-
return renderer.getLastElementChild(vm.elm);
|
|
2176
|
-
},
|
|
2177
|
-
render() {
|
|
2178
|
-
const vm = getAssociatedVM(this);
|
|
2179
|
-
return vm.def.template;
|
|
2180
|
-
},
|
|
2181
|
-
toString() {
|
|
2182
|
-
const vm = getAssociatedVM(this);
|
|
2183
|
-
return `[object ${vm.def.name}]`;
|
|
2184
|
-
},
|
|
2309
|
+
return renderer.getChildNodes(vm.elm);
|
|
2310
|
+
},
|
|
2311
|
+
get firstChild() {
|
|
2312
|
+
const vm = getAssociatedVM(this);
|
|
2313
|
+
const renderer = vm.renderer;
|
|
2314
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2315
|
+
warnIfInvokedDuringConstruction(vm, 'firstChild');
|
|
2316
|
+
}
|
|
2317
|
+
return renderer.getFirstChild(vm.elm);
|
|
2318
|
+
},
|
|
2319
|
+
get firstElementChild() {
|
|
2320
|
+
const vm = getAssociatedVM(this);
|
|
2321
|
+
const renderer = vm.renderer;
|
|
2322
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2323
|
+
warnIfInvokedDuringConstruction(vm, 'firstElementChild');
|
|
2324
|
+
}
|
|
2325
|
+
return renderer.getFirstElementChild(vm.elm);
|
|
2326
|
+
},
|
|
2327
|
+
get lastChild() {
|
|
2328
|
+
const vm = getAssociatedVM(this);
|
|
2329
|
+
const renderer = vm.renderer;
|
|
2330
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2331
|
+
warnIfInvokedDuringConstruction(vm, 'lastChild');
|
|
2332
|
+
}
|
|
2333
|
+
return renderer.getLastChild(vm.elm);
|
|
2334
|
+
},
|
|
2335
|
+
get lastElementChild() {
|
|
2336
|
+
const vm = getAssociatedVM(this);
|
|
2337
|
+
const renderer = vm.renderer;
|
|
2338
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2339
|
+
warnIfInvokedDuringConstruction(vm, 'lastElementChild');
|
|
2340
|
+
}
|
|
2341
|
+
return renderer.getLastElementChild(vm.elm);
|
|
2342
|
+
},
|
|
2343
|
+
render() {
|
|
2344
|
+
const vm = getAssociatedVM(this);
|
|
2345
|
+
return vm.def.template;
|
|
2346
|
+
},
|
|
2347
|
+
toString() {
|
|
2348
|
+
const vm = getAssociatedVM(this);
|
|
2349
|
+
return `[object ${vm.def.name}]`;
|
|
2350
|
+
}
|
|
2185
2351
|
};
|
|
2186
2352
|
const queryAndChildGetterDescriptors = create(null);
|
|
2187
|
-
const queryMethods = [
|
|
2188
|
-
'getElementsByClassName',
|
|
2189
|
-
'getElementsByTagName',
|
|
2190
|
-
'querySelector',
|
|
2191
|
-
'querySelectorAll',
|
|
2192
|
-
];
|
|
2353
|
+
const queryMethods = ['getElementsByClassName', 'getElementsByTagName', 'querySelector', 'querySelectorAll'];
|
|
2193
2354
|
// Generic passthrough for query APIs on HTMLElement to the relevant Renderer APIs
|
|
2194
2355
|
for (const queryMethod of queryMethods) {
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
}
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2356
|
+
queryAndChildGetterDescriptors[queryMethod] = {
|
|
2357
|
+
value(arg) {
|
|
2358
|
+
const vm = getAssociatedVM(this);
|
|
2359
|
+
const {
|
|
2360
|
+
elm,
|
|
2361
|
+
renderer
|
|
2362
|
+
} = vm;
|
|
2363
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2364
|
+
warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
|
|
2365
|
+
}
|
|
2366
|
+
return renderer[queryMethod](elm, arg);
|
|
2367
|
+
},
|
|
2368
|
+
configurable: true,
|
|
2369
|
+
enumerable: true,
|
|
2370
|
+
writable: true
|
|
2371
|
+
};
|
|
2208
2372
|
}
|
|
2209
2373
|
defineProperties(LightningElement.prototype, queryAndChildGetterDescriptors);
|
|
2210
2374
|
const lightningBasedDescriptors = create(null);
|
|
2211
2375
|
for (const propName in HTMLElementOriginalDescriptors) {
|
|
2212
|
-
|
|
2376
|
+
lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
|
|
2213
2377
|
}
|
|
2214
2378
|
defineProperties(LightningElement.prototype, lightningBasedDescriptors);
|
|
2379
|
+
function applyAriaReflectionToLightningElement() {
|
|
2380
|
+
// If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
|
|
2381
|
+
// apply it to LightningElement.prototype.
|
|
2382
|
+
// This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
|
|
2383
|
+
applyAriaReflection(LightningElement.prototype);
|
|
2384
|
+
}
|
|
2385
|
+
// The reason for this odd if/else branching is limitations in @lwc/features:
|
|
2386
|
+
// https://github.com/salesforce/lwc/blob/master/packages/%40lwc/features/README.md#only-works-with-if-statements
|
|
2387
|
+
if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
|
|
2388
|
+
applyAriaReflectionToLightningElement();
|
|
2389
|
+
} else {
|
|
2390
|
+
applyAriaReflectionToLightningElement();
|
|
2391
|
+
}
|
|
2215
2392
|
defineProperty(LightningElement, 'CustomElementConstructor', {
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2393
|
+
get() {
|
|
2394
|
+
// If required, a runtime-specific implementation must be defined.
|
|
2395
|
+
throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
|
|
2396
|
+
},
|
|
2397
|
+
configurable: true
|
|
2221
2398
|
});
|
|
2222
2399
|
if (process.env.NODE_ENV !== 'production') {
|
|
2223
|
-
|
|
2400
|
+
patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
|
|
2224
2401
|
}
|
|
2225
2402
|
|
|
2226
2403
|
function createObservedFieldPropertyDescriptor(key) {
|
|
@@ -2675,136 +2852,145 @@ function sanitizeAttribute(tagName, namespaceUri, attrName, attrValue) {
|
|
|
2675
2852
|
const cachedGetterByKey = create(null);
|
|
2676
2853
|
const cachedSetterByKey = create(null);
|
|
2677
2854
|
function createGetter(key) {
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2855
|
+
let fn = cachedGetterByKey[key];
|
|
2856
|
+
if (isUndefined$1(fn)) {
|
|
2857
|
+
fn = cachedGetterByKey[key] = function () {
|
|
2858
|
+
const vm = getAssociatedVM(this);
|
|
2859
|
+
const {
|
|
2860
|
+
getHook
|
|
2861
|
+
} = vm;
|
|
2862
|
+
return getHook(vm.component, key);
|
|
2863
|
+
};
|
|
2864
|
+
}
|
|
2865
|
+
return fn;
|
|
2687
2866
|
}
|
|
2688
2867
|
function createSetter(key) {
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2868
|
+
let fn = cachedSetterByKey[key];
|
|
2869
|
+
if (isUndefined$1(fn)) {
|
|
2870
|
+
fn = cachedSetterByKey[key] = function (newValue) {
|
|
2871
|
+
const vm = getAssociatedVM(this);
|
|
2872
|
+
const {
|
|
2873
|
+
setHook
|
|
2874
|
+
} = vm;
|
|
2875
|
+
newValue = getReadOnlyProxy(newValue);
|
|
2876
|
+
setHook(vm.component, key, newValue);
|
|
2877
|
+
};
|
|
2878
|
+
}
|
|
2879
|
+
return fn;
|
|
2699
2880
|
}
|
|
2700
2881
|
function createMethodCaller(methodName) {
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
};
|
|
2882
|
+
return function () {
|
|
2883
|
+
const vm = getAssociatedVM(this);
|
|
2884
|
+
const {
|
|
2885
|
+
callHook,
|
|
2886
|
+
component
|
|
2887
|
+
} = vm;
|
|
2888
|
+
const fn = component[methodName];
|
|
2889
|
+
return callHook(vm.component, fn, ArraySlice.call(arguments));
|
|
2890
|
+
};
|
|
2707
2891
|
}
|
|
2708
2892
|
function createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback) {
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
}
|
|
2714
|
-
const propName = attributeToPropMap[attrName];
|
|
2715
|
-
if (isUndefined$1(propName)) {
|
|
2716
|
-
if (!isUndefined$1(superAttributeChangedCallback)) {
|
|
2717
|
-
// delegate unknown attributes to the super.
|
|
2718
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
2719
|
-
// @ts-ignore type-mismatch
|
|
2720
|
-
superAttributeChangedCallback.apply(this, arguments);
|
|
2721
|
-
}
|
|
2722
|
-
return;
|
|
2723
|
-
}
|
|
2724
|
-
if (!isAttributeLocked(this, attrName)) {
|
|
2725
|
-
// Ignore changes triggered by the engine itself during:
|
|
2726
|
-
// * diffing when public props are attempting to reflect to the DOM
|
|
2727
|
-
// * component via `this.setAttribute()`, should never update the prop
|
|
2728
|
-
// Both cases, the setAttribute call is always wrapped by the unlocking of the
|
|
2729
|
-
// attribute to be changed
|
|
2730
|
-
return;
|
|
2731
|
-
}
|
|
2732
|
-
// Reflect attribute change to the corresponding property when changed from outside.
|
|
2733
|
-
this[propName] = newValue;
|
|
2734
|
-
};
|
|
2735
|
-
}
|
|
2736
|
-
function HTMLBridgeElementFactory(SuperClass, props, methods) {
|
|
2737
|
-
let HTMLBridgeElement;
|
|
2738
|
-
/**
|
|
2739
|
-
* Modern browsers will have all Native Constructors as regular Classes
|
|
2740
|
-
* and must be instantiated with the new keyword. In older browsers,
|
|
2741
|
-
* specifically IE11, those are objects with a prototype property defined,
|
|
2742
|
-
* since they are not supposed to be extended or instantiated with the
|
|
2743
|
-
* new keyword. This forking logic supports both cases, specifically because
|
|
2744
|
-
* wc.ts relies on the construction path of the bridges to create new
|
|
2745
|
-
* fully qualifying web components.
|
|
2746
|
-
*/
|
|
2747
|
-
if (isFunction$1(SuperClass)) {
|
|
2748
|
-
HTMLBridgeElement = class extends SuperClass {
|
|
2749
|
-
};
|
|
2750
|
-
}
|
|
2751
|
-
else {
|
|
2752
|
-
HTMLBridgeElement = function () {
|
|
2753
|
-
// Bridge classes are not supposed to be instantiated directly in
|
|
2754
|
-
// browsers that do not support web components.
|
|
2755
|
-
throw new TypeError('Illegal constructor');
|
|
2756
|
-
};
|
|
2757
|
-
// prototype inheritance dance
|
|
2758
|
-
setPrototypeOf(HTMLBridgeElement, SuperClass);
|
|
2759
|
-
setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
|
|
2760
|
-
defineProperty(HTMLBridgeElement.prototype, 'constructor', {
|
|
2761
|
-
writable: true,
|
|
2762
|
-
configurable: true,
|
|
2763
|
-
value: HTMLBridgeElement,
|
|
2764
|
-
});
|
|
2893
|
+
return function attributeChangedCallback(attrName, oldValue, newValue) {
|
|
2894
|
+
if (oldValue === newValue) {
|
|
2895
|
+
// Ignore same values.
|
|
2896
|
+
return;
|
|
2765
2897
|
}
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
|
|
2776
|
-
descriptors[propName] = {
|
|
2777
|
-
get: createGetter(propName),
|
|
2778
|
-
set: createSetter(propName),
|
|
2779
|
-
enumerable: true,
|
|
2780
|
-
configurable: true,
|
|
2781
|
-
};
|
|
2898
|
+
const propName = attributeToPropMap[attrName];
|
|
2899
|
+
if (isUndefined$1(propName)) {
|
|
2900
|
+
if (!isUndefined$1(superAttributeChangedCallback)) {
|
|
2901
|
+
// delegate unknown attributes to the super.
|
|
2902
|
+
// Typescript does not like it when you treat the `arguments` object as an array
|
|
2903
|
+
// @ts-ignore type-mismatch
|
|
2904
|
+
superAttributeChangedCallback.apply(this, arguments);
|
|
2905
|
+
}
|
|
2906
|
+
return;
|
|
2782
2907
|
}
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
};
|
|
2908
|
+
if (!isAttributeLocked(this, attrName)) {
|
|
2909
|
+
// Ignore changes triggered by the engine itself during:
|
|
2910
|
+
// * diffing when public props are attempting to reflect to the DOM
|
|
2911
|
+
// * component via `this.setAttribute()`, should never update the prop
|
|
2912
|
+
// Both cases, the setAttribute call is always wrapped by the unlocking of the
|
|
2913
|
+
// attribute to be changed
|
|
2914
|
+
return;
|
|
2791
2915
|
}
|
|
2792
|
-
//
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2916
|
+
// Reflect attribute change to the corresponding property when changed from outside.
|
|
2917
|
+
this[propName] = newValue;
|
|
2918
|
+
};
|
|
2919
|
+
}
|
|
2920
|
+
function HTMLBridgeElementFactory(SuperClass, props, methods) {
|
|
2921
|
+
let HTMLBridgeElement;
|
|
2922
|
+
/**
|
|
2923
|
+
* Modern browsers will have all Native Constructors as regular Classes
|
|
2924
|
+
* and must be instantiated with the new keyword. In older browsers,
|
|
2925
|
+
* specifically IE11, those are objects with a prototype property defined,
|
|
2926
|
+
* since they are not supposed to be extended or instantiated with the
|
|
2927
|
+
* new keyword. This forking logic supports both cases, specifically because
|
|
2928
|
+
* wc.ts relies on the construction path of the bridges to create new
|
|
2929
|
+
* fully qualifying web components.
|
|
2930
|
+
*/
|
|
2931
|
+
if (isFunction$1(SuperClass)) {
|
|
2932
|
+
HTMLBridgeElement = class extends SuperClass {};
|
|
2933
|
+
} else {
|
|
2934
|
+
HTMLBridgeElement = function () {
|
|
2935
|
+
// Bridge classes are not supposed to be instantiated directly in
|
|
2936
|
+
// browsers that do not support web components.
|
|
2937
|
+
throw new TypeError('Illegal constructor');
|
|
2798
2938
|
};
|
|
2799
|
-
//
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2939
|
+
// prototype inheritance dance
|
|
2940
|
+
setPrototypeOf(HTMLBridgeElement, SuperClass);
|
|
2941
|
+
setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
|
|
2942
|
+
defineProperty(HTMLBridgeElement.prototype, 'constructor', {
|
|
2943
|
+
writable: true,
|
|
2944
|
+
configurable: true,
|
|
2945
|
+
value: HTMLBridgeElement
|
|
2805
2946
|
});
|
|
2806
|
-
|
|
2807
|
-
|
|
2947
|
+
}
|
|
2948
|
+
// generating the hash table for attributes to avoid duplicate fields and facilitate validation
|
|
2949
|
+
// and false positives in case of inheritance.
|
|
2950
|
+
const attributeToPropMap = create(null);
|
|
2951
|
+
const {
|
|
2952
|
+
attributeChangedCallback: superAttributeChangedCallback
|
|
2953
|
+
} = SuperClass.prototype;
|
|
2954
|
+
const {
|
|
2955
|
+
observedAttributes: superObservedAttributes = []
|
|
2956
|
+
} = SuperClass;
|
|
2957
|
+
const descriptors = create(null);
|
|
2958
|
+
// expose getters and setters for each public props on the new Element Bridge
|
|
2959
|
+
for (let i = 0, len = props.length; i < len; i += 1) {
|
|
2960
|
+
const propName = props[i];
|
|
2961
|
+
attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
|
|
2962
|
+
descriptors[propName] = {
|
|
2963
|
+
get: createGetter(propName),
|
|
2964
|
+
set: createSetter(propName),
|
|
2965
|
+
enumerable: true,
|
|
2966
|
+
configurable: true
|
|
2967
|
+
};
|
|
2968
|
+
}
|
|
2969
|
+
// expose public methods as props on the new Element Bridge
|
|
2970
|
+
for (let i = 0, len = methods.length; i < len; i += 1) {
|
|
2971
|
+
const methodName = methods[i];
|
|
2972
|
+
descriptors[methodName] = {
|
|
2973
|
+
value: createMethodCaller(methodName),
|
|
2974
|
+
writable: true,
|
|
2975
|
+
configurable: true
|
|
2976
|
+
};
|
|
2977
|
+
}
|
|
2978
|
+
// creating a new attributeChangedCallback per bridge because they are bound to the corresponding
|
|
2979
|
+
// map of attributes to props. We do this after all other props and methods to avoid the possibility
|
|
2980
|
+
// of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
|
|
2981
|
+
// to preserve this definition.
|
|
2982
|
+
descriptors.attributeChangedCallback = {
|
|
2983
|
+
value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback)
|
|
2984
|
+
};
|
|
2985
|
+
// Specify attributes for which we want to reflect changes back to their corresponding
|
|
2986
|
+
// properties via attributeChangedCallback.
|
|
2987
|
+
defineProperty(HTMLBridgeElement, 'observedAttributes', {
|
|
2988
|
+
get() {
|
|
2989
|
+
return [...superObservedAttributes, ...keys(attributeToPropMap)];
|
|
2990
|
+
}
|
|
2991
|
+
});
|
|
2992
|
+
defineProperties(HTMLBridgeElement.prototype, descriptors);
|
|
2993
|
+
return HTMLBridgeElement;
|
|
2808
2994
|
}
|
|
2809
2995
|
const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
|
|
2810
2996
|
freeze(BaseBridgeElement);
|
|
@@ -3165,6 +3351,9 @@ function updateStylesheetToken(vm, template) {
|
|
|
3165
3351
|
stylesheets: newStylesheets,
|
|
3166
3352
|
stylesheetToken: newStylesheetToken
|
|
3167
3353
|
} = template;
|
|
3354
|
+
const {
|
|
3355
|
+
stylesheets: newVmStylesheets
|
|
3356
|
+
} = vm;
|
|
3168
3357
|
const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
|
|
3169
3358
|
const {
|
|
3170
3359
|
hasScopedStyles
|
|
@@ -3188,7 +3377,9 @@ function updateStylesheetToken(vm, template) {
|
|
|
3188
3377
|
}
|
|
3189
3378
|
// Apply the new template styling token to the host element, if the new template has any
|
|
3190
3379
|
// associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
|
|
3191
|
-
|
|
3380
|
+
const hasNewStylesheets = hasStyles(newStylesheets);
|
|
3381
|
+
const hasNewVmStylesheets = hasStyles(newVmStylesheets);
|
|
3382
|
+
if (hasNewStylesheets || hasNewVmStylesheets) {
|
|
3192
3383
|
newToken = newStylesheetToken;
|
|
3193
3384
|
}
|
|
3194
3385
|
// Set the new styling token on the host element
|
|
@@ -3260,10 +3451,17 @@ function getStylesheetsContent(vm, template) {
|
|
|
3260
3451
|
stylesheets,
|
|
3261
3452
|
stylesheetToken
|
|
3262
3453
|
} = template;
|
|
3454
|
+
const {
|
|
3455
|
+
stylesheets: vmStylesheets
|
|
3456
|
+
} = vm;
|
|
3263
3457
|
let content = [];
|
|
3264
|
-
if (
|
|
3458
|
+
if (hasStyles(stylesheets)) {
|
|
3265
3459
|
content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
|
|
3266
3460
|
}
|
|
3461
|
+
// VM (component) stylesheets apply after template stylesheets
|
|
3462
|
+
if (hasStyles(vmStylesheets)) {
|
|
3463
|
+
ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
|
|
3464
|
+
}
|
|
3267
3465
|
return content;
|
|
3268
3466
|
}
|
|
3269
3467
|
// It might be worth caching this to avoid doing the lookup repeatedly, but
|
|
@@ -3869,6 +4067,28 @@ function patchCustomElement(n1, n2, parent, renderer) {
|
|
|
3869
4067
|
// in fallback mode, the allocation will always set children to
|
|
3870
4068
|
// empty and delegate the real allocation to the slot elements
|
|
3871
4069
|
allocateChildren(n2, vm);
|
|
4070
|
+
// Solves an edge case with slotted VFragments in native shadow mode.
|
|
4071
|
+
//
|
|
4072
|
+
// During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
|
|
4073
|
+
// to avoid interfering with native slot behavior. When this happens, if any of the fragments
|
|
4074
|
+
// were not stable, the children must go through the dynamic diffing algo.
|
|
4075
|
+
//
|
|
4076
|
+
// If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
|
|
4077
|
+
// the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
|
|
4078
|
+
// nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
|
|
4079
|
+
// mark the new children dynamic.
|
|
4080
|
+
//
|
|
4081
|
+
// Example:
|
|
4082
|
+
// n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
|
|
4083
|
+
// n2.children: [div, null, div] => [div, null, div] // marked ???
|
|
4084
|
+
const {
|
|
4085
|
+
shadowMode,
|
|
4086
|
+
renderMode
|
|
4087
|
+
} = vm;
|
|
4088
|
+
if (shadowMode == 0 /* ShadowMode.Native */ && renderMode !== 0 /* RenderMode.Light */ && hasDynamicChildren(n1.children)) {
|
|
4089
|
+
// No-op if children has already been marked dynamic by 'allocateChildren()'.
|
|
4090
|
+
markAsDynamicChildren(n2.children);
|
|
4091
|
+
}
|
|
3872
4092
|
}
|
|
3873
4093
|
// in fallback mode, the children will be always empty, so, nothing
|
|
3874
4094
|
// will happen, but in native, it does allocate the light dom
|
|
@@ -4061,7 +4281,6 @@ function allocateChildren(vnode, vm) {
|
|
|
4061
4281
|
//
|
|
4062
4282
|
// In case #2, we will always get a fresh VCustomElement.
|
|
4063
4283
|
const children = vnode.aChildren || vnode.children;
|
|
4064
|
-
vm.aChildren = children;
|
|
4065
4284
|
const {
|
|
4066
4285
|
renderMode,
|
|
4067
4286
|
shadowMode
|
|
@@ -4074,15 +4293,61 @@ function allocateChildren(vnode, vm) {
|
|
|
4074
4293
|
logError(`Invalid usage of 'lwc:slot-data' on ${getComponentTag(vm)} tag. Scoped slot content can only be passed to a light dom child.`);
|
|
4075
4294
|
}
|
|
4076
4295
|
}
|
|
4296
|
+
// If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
|
|
4297
|
+
// children VFragments to avoid them interfering with default slot behavior.
|
|
4298
|
+
const allocatedChildren = flattenFragmentsInChildren(children);
|
|
4299
|
+
vnode.children = allocatedChildren;
|
|
4300
|
+
vm.aChildren = allocatedChildren;
|
|
4077
4301
|
if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
|
|
4078
4302
|
// slow path
|
|
4079
|
-
allocateInSlot(vm,
|
|
4303
|
+
allocateInSlot(vm, allocatedChildren, vnode.owner);
|
|
4080
4304
|
// save the allocated children in case this vnode is reused.
|
|
4081
|
-
vnode.aChildren =
|
|
4305
|
+
vnode.aChildren = allocatedChildren;
|
|
4082
4306
|
// every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
|
|
4083
4307
|
vnode.children = EmptyArray;
|
|
4084
4308
|
}
|
|
4085
4309
|
}
|
|
4310
|
+
/**
|
|
4311
|
+
* Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
|
|
4312
|
+
* marks the resulting children array as dynamic. Uses a stack (array) to iteratively traverse the nested VFragments
|
|
4313
|
+
* and avoid the perf overhead of creating/destroying throwaway arrays/objects in a recursive approach.
|
|
4314
|
+
*
|
|
4315
|
+
* With the delimiters removed, the contents are marked dynamic so they are diffed correctly.
|
|
4316
|
+
*
|
|
4317
|
+
* This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
|
|
4318
|
+
*/
|
|
4319
|
+
function flattenFragmentsInChildren(children) {
|
|
4320
|
+
const flattenedChildren = [];
|
|
4321
|
+
// Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
|
|
4322
|
+
// If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
|
|
4323
|
+
const nodeStack = [];
|
|
4324
|
+
let fragmentFound = false;
|
|
4325
|
+
for (let i = children.length - 1; i > -1; i -= 1) {
|
|
4326
|
+
const child = children[i];
|
|
4327
|
+
ArrayPush$1.call(nodeStack, child);
|
|
4328
|
+
fragmentFound = fragmentFound || !!(child && isVFragment(child));
|
|
4329
|
+
}
|
|
4330
|
+
if (!fragmentFound) {
|
|
4331
|
+
return children;
|
|
4332
|
+
}
|
|
4333
|
+
let currentNode;
|
|
4334
|
+
while (!isUndefined$1(currentNode = ArrayPop.call(nodeStack))) {
|
|
4335
|
+
if (!isNull(currentNode) && isVFragment(currentNode)) {
|
|
4336
|
+
const fChildren = currentNode.children;
|
|
4337
|
+
// Ignore the start and end text node delimiters
|
|
4338
|
+
for (let i = fChildren.length - 2; i > 0; i -= 1) {
|
|
4339
|
+
ArrayPush$1.call(nodeStack, fChildren[i]);
|
|
4340
|
+
}
|
|
4341
|
+
} else {
|
|
4342
|
+
ArrayPush$1.call(flattenedChildren, currentNode);
|
|
4343
|
+
}
|
|
4344
|
+
}
|
|
4345
|
+
// We always mark the children as dynamic because nothing generates stable VFragments yet.
|
|
4346
|
+
// If/when stable VFragments are generated by the compiler, this code should be updated to
|
|
4347
|
+
// not mark dynamic if all flattened VFragments were stable.
|
|
4348
|
+
markAsDynamicChildren(flattenedChildren);
|
|
4349
|
+
return flattenedChildren;
|
|
4350
|
+
}
|
|
4086
4351
|
function createViewModelHook(elm, vnode, renderer) {
|
|
4087
4352
|
let vm = getAssociatedVMIfPresent(elm);
|
|
4088
4353
|
// There is a possibility that a custom element is registered under tagName, in which case, the
|
|
@@ -4107,22 +4372,20 @@ function createViewModelHook(elm, vnode, renderer) {
|
|
|
4107
4372
|
}
|
|
4108
4373
|
return vm;
|
|
4109
4374
|
}
|
|
4110
|
-
|
|
4111
|
-
* Collects all slots into a SlotSet, traversing through VFragment Nodes
|
|
4112
|
-
*/
|
|
4113
|
-
function collectSlots(vm, children, cmpSlotsMapping) {
|
|
4375
|
+
function allocateInSlot(vm, children, owner) {
|
|
4114
4376
|
var _a, _b;
|
|
4377
|
+
const {
|
|
4378
|
+
cmpSlots: {
|
|
4379
|
+
slotAssignments: oldSlotsMapping
|
|
4380
|
+
}
|
|
4381
|
+
} = vm;
|
|
4382
|
+
const cmpSlotsMapping = create(null);
|
|
4383
|
+
// Collect all slots into cmpSlotsMapping
|
|
4115
4384
|
for (let i = 0, len = children.length; i < len; i += 1) {
|
|
4116
4385
|
const vnode = children[i];
|
|
4117
4386
|
if (isNull(vnode)) {
|
|
4118
4387
|
continue;
|
|
4119
4388
|
}
|
|
4120
|
-
// Dive further iff the content is wrapped in a VFragment
|
|
4121
|
-
if (isVFragment(vnode)) {
|
|
4122
|
-
// Remove the text delimiter nodes to avoid overriding default slot content
|
|
4123
|
-
collectSlots(vm, vnode.children.slice(1, -1), cmpSlotsMapping);
|
|
4124
|
-
continue;
|
|
4125
|
-
}
|
|
4126
4389
|
let slotName = '';
|
|
4127
4390
|
if (isVBaseElement(vnode)) {
|
|
4128
4391
|
slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
|
|
@@ -4132,15 +4395,6 @@ function collectSlots(vm, children, cmpSlotsMapping) {
|
|
|
4132
4395
|
const vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
|
|
4133
4396
|
ArrayPush$1.call(vnodes, vnode);
|
|
4134
4397
|
}
|
|
4135
|
-
}
|
|
4136
|
-
function allocateInSlot(vm, children, owner) {
|
|
4137
|
-
const {
|
|
4138
|
-
cmpSlots: {
|
|
4139
|
-
slotAssignments: oldSlotsMapping
|
|
4140
|
-
}
|
|
4141
|
-
} = vm;
|
|
4142
|
-
const cmpSlotsMapping = create(null);
|
|
4143
|
-
collectSlots(vm, children, cmpSlotsMapping);
|
|
4144
4398
|
vm.cmpSlots = {
|
|
4145
4399
|
owner,
|
|
4146
4400
|
slotAssignments: cmpSlotsMapping
|
|
@@ -4171,14 +4425,14 @@ function allocateInSlot(vm, children, owner) {
|
|
|
4171
4425
|
}
|
|
4172
4426
|
}
|
|
4173
4427
|
// Using a WeakMap instead of a WeakSet because this one works in IE11 :(
|
|
4174
|
-
const
|
|
4175
|
-
// dynamic children means it was generated by an iteration
|
|
4176
|
-
//
|
|
4428
|
+
const DynamicChildren = new WeakMap();
|
|
4429
|
+
// dynamic children means it was either generated by an iteration in a template
|
|
4430
|
+
// or part of an unstable fragment, and will require a more complex diffing algo.
|
|
4177
4431
|
function markAsDynamicChildren(children) {
|
|
4178
|
-
|
|
4432
|
+
DynamicChildren.set(children, 1);
|
|
4179
4433
|
}
|
|
4180
4434
|
function hasDynamicChildren(children) {
|
|
4181
|
-
return
|
|
4435
|
+
return DynamicChildren.has(children);
|
|
4182
4436
|
}
|
|
4183
4437
|
function createKeyToOldIdx(children, beginIdx, endIdx) {
|
|
4184
4438
|
const map = {};
|
|
@@ -5005,7 +5259,7 @@ function evaluateTemplate(vm, html) {
|
|
|
5005
5259
|
// Create a brand new template cache for the swapped templated.
|
|
5006
5260
|
context.tplCache = create(null);
|
|
5007
5261
|
// Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
|
|
5008
|
-
context.hasScopedStyles = computeHasScopedStyles(html);
|
|
5262
|
+
context.hasScopedStyles = computeHasScopedStyles(html, vm);
|
|
5009
5263
|
// Update the scoping token on the host element.
|
|
5010
5264
|
updateStylesheetToken(vm, html);
|
|
5011
5265
|
// Evaluate, create stylesheet and cache the produced VNode for future
|
|
@@ -5048,9 +5302,8 @@ function evaluateTemplate(vm, html) {
|
|
|
5048
5302
|
}
|
|
5049
5303
|
return vnodes;
|
|
5050
5304
|
}
|
|
5051
|
-
function
|
|
5052
|
-
|
|
5053
|
-
if (!isUndefined$1(stylesheets)) {
|
|
5305
|
+
function computeHasScopedStylesInStylesheets(stylesheets) {
|
|
5306
|
+
if (hasStyles(stylesheets)) {
|
|
5054
5307
|
for (let i = 0; i < stylesheets.length; i++) {
|
|
5055
5308
|
if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
|
|
5056
5309
|
return true;
|
|
@@ -5059,6 +5312,15 @@ function computeHasScopedStyles(template) {
|
|
|
5059
5312
|
}
|
|
5060
5313
|
return false;
|
|
5061
5314
|
}
|
|
5315
|
+
function computeHasScopedStyles(template, vm) {
|
|
5316
|
+
const { stylesheets } = template;
|
|
5317
|
+
const vmStylesheets = !isUndefined$1(vm) ? vm.stylesheets : null;
|
|
5318
|
+
return (computeHasScopedStylesInStylesheets(stylesheets) ||
|
|
5319
|
+
computeHasScopedStylesInStylesheets(vmStylesheets));
|
|
5320
|
+
}
|
|
5321
|
+
function hasStyles(stylesheets) {
|
|
5322
|
+
return !isUndefined$1(stylesheets) && !isNull(stylesheets) && stylesheets.length > 0;
|
|
5323
|
+
}
|
|
5062
5324
|
|
|
5063
5325
|
/*
|
|
5064
5326
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -5368,6 +5630,7 @@ function createVM(elm, ctor, renderer, options) {
|
|
|
5368
5630
|
// Properties set right after VM creation.
|
|
5369
5631
|
tro: null,
|
|
5370
5632
|
shadowMode: null,
|
|
5633
|
+
stylesheets: null,
|
|
5371
5634
|
// Properties set by the LightningElement constructor.
|
|
5372
5635
|
component: null,
|
|
5373
5636
|
shadowRoot: null,
|
|
@@ -5380,6 +5643,7 @@ function createVM(elm, ctor, renderer, options) {
|
|
|
5380
5643
|
if (process.env.NODE_ENV !== 'production') {
|
|
5381
5644
|
vm.debugInfo = create(null);
|
|
5382
5645
|
}
|
|
5646
|
+
vm.stylesheets = computeStylesheets(vm, def.ctor);
|
|
5383
5647
|
vm.shadowMode = computeShadowMode(vm, renderer);
|
|
5384
5648
|
vm.tro = getTemplateReactiveObserver();
|
|
5385
5649
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -5398,6 +5662,42 @@ function createVM(elm, ctor, renderer, options) {
|
|
|
5398
5662
|
}
|
|
5399
5663
|
return vm;
|
|
5400
5664
|
}
|
|
5665
|
+
function validateComponentStylesheets(vm, stylesheets) {
|
|
5666
|
+
let valid = true;
|
|
5667
|
+
const validate = arrayOrStylesheet => {
|
|
5668
|
+
if (isArray$1(arrayOrStylesheet)) {
|
|
5669
|
+
for (let i = 0; i < arrayOrStylesheet.length; i++) {
|
|
5670
|
+
validate(arrayOrStylesheet[i]);
|
|
5671
|
+
}
|
|
5672
|
+
} else if (!isFunction$1(arrayOrStylesheet)) {
|
|
5673
|
+
// function assumed to be a stylesheet factory
|
|
5674
|
+
valid = false;
|
|
5675
|
+
}
|
|
5676
|
+
};
|
|
5677
|
+
if (!isArray$1(stylesheets)) {
|
|
5678
|
+
valid = false;
|
|
5679
|
+
} else {
|
|
5680
|
+
validate(stylesheets);
|
|
5681
|
+
}
|
|
5682
|
+
return valid;
|
|
5683
|
+
}
|
|
5684
|
+
// Validate and flatten any stylesheets defined as `static stylesheets`
|
|
5685
|
+
function computeStylesheets(vm, ctor) {
|
|
5686
|
+
if (lwcRuntimeFlags.ENABLE_PROGRAMMATIC_STYLESHEETS) {
|
|
5687
|
+
const {
|
|
5688
|
+
stylesheets
|
|
5689
|
+
} = ctor;
|
|
5690
|
+
if (!isUndefined$1(stylesheets)) {
|
|
5691
|
+
const valid = validateComponentStylesheets(vm, stylesheets);
|
|
5692
|
+
if (valid) {
|
|
5693
|
+
return flattenStylesheets(stylesheets);
|
|
5694
|
+
} else if (process.env.NODE_ENV !== 'production') {
|
|
5695
|
+
logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
|
|
5696
|
+
}
|
|
5697
|
+
}
|
|
5698
|
+
}
|
|
5699
|
+
return null;
|
|
5700
|
+
}
|
|
5401
5701
|
function computeShadowMode(vm, renderer) {
|
|
5402
5702
|
const {
|
|
5403
5703
|
def
|
|
@@ -6198,7 +6498,7 @@ function freezeTemplate(tmpl) {
|
|
|
6198
6498
|
}
|
|
6199
6499
|
}
|
|
6200
6500
|
}
|
|
6201
|
-
/* version: 2.
|
|
6501
|
+
/* version: 2.34.0 */
|
|
6202
6502
|
|
|
6203
6503
|
/*
|
|
6204
6504
|
* Copyright (c) 2020, salesforce.com, inc.
|
|
@@ -6669,7 +6969,7 @@ function renderComponent(tagName, Ctor, props = {}) {
|
|
|
6669
6969
|
*/
|
|
6670
6970
|
freeze(LightningElement);
|
|
6671
6971
|
seal(LightningElement.prototype);
|
|
6672
|
-
/* version: 2.
|
|
6972
|
+
/* version: 2.34.0 */
|
|
6673
6973
|
|
|
6674
6974
|
exports.LightningElement = LightningElement;
|
|
6675
6975
|
exports.api = api$1;
|