lwc 2.25.1 → 2.26.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 +885 -411
- package/dist/engine-dom/iife/es2017/engine-dom.js +885 -411
- package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
- package/dist/engine-dom/iife/es2017/engine-dom_debug.js +731 -205
- package/dist/engine-dom/iife/es5/engine-dom.js +954 -311
- package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
- package/dist/engine-dom/iife/es5/engine-dom_debug.js +883 -224
- package/dist/engine-dom/umd/es2017/engine-dom.js +885 -411
- package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
- package/dist/engine-dom/umd/es2017/engine-dom_debug.js +731 -205
- package/dist/engine-dom/umd/es5/engine-dom.js +954 -311
- package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
- package/dist/engine-dom/umd/es5/engine-dom_debug.js +883 -224
- package/dist/engine-server/commonjs/es2017/engine-server.js +133 -227
- package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
- package/dist/engine-server/esm/es2017/engine-server.js +133 -227
- 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_debug.js +3 -3
- package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
- package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
- package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
- package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
- package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
- package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
- 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 +2 -2
- package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
- 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 +2 -2
- package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
- package/package.json +7 -7
|
@@ -291,7 +291,7 @@ var LWC = (function (exports) {
|
|
|
291
291
|
CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
|
|
292
292
|
return attributeName;
|
|
293
293
|
}
|
|
294
|
-
/** version: 2.
|
|
294
|
+
/** version: 2.26.0 */
|
|
295
295
|
|
|
296
296
|
/**
|
|
297
297
|
* Copyright (C) 2018 salesforce.com, inc.
|
|
@@ -373,7 +373,7 @@ var LWC = (function (exports) {
|
|
|
373
373
|
patch$1(propName);
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
|
-
/** version: 2.
|
|
376
|
+
/** version: 2.26.0 */
|
|
377
377
|
|
|
378
378
|
/**
|
|
379
379
|
* Copyright (C) 2018 salesforce.com, inc.
|
|
@@ -389,7 +389,6 @@ var LWC = (function (exports) {
|
|
|
389
389
|
DUMMY_TEST_FLAG: null,
|
|
390
390
|
ENABLE_ELEMENT_PATCH: null,
|
|
391
391
|
ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST: null,
|
|
392
|
-
ENABLE_HMR: null,
|
|
393
392
|
ENABLE_HTML_COLLECTIONS_PATCH: null,
|
|
394
393
|
ENABLE_INNER_OUTER_TEXT_PATCH: null,
|
|
395
394
|
ENABLE_MIXED_SHADOW_MODE: null,
|
|
@@ -400,6 +399,7 @@ var LWC = (function (exports) {
|
|
|
400
399
|
ENABLE_WIRE_SYNC_EMIT: null,
|
|
401
400
|
ENABLE_LIGHT_GET_ROOT_NODE_PATCH: null,
|
|
402
401
|
DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
|
|
402
|
+
ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
|
|
403
403
|
};
|
|
404
404
|
if (!_globalThis.lwcRuntimeFlags) {
|
|
405
405
|
Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
|
|
@@ -1384,7 +1384,9 @@ var LWC = (function (exports) {
|
|
|
1384
1384
|
const LightningElement = function () {
|
|
1385
1385
|
// This should be as performant as possible, while any initialization should be done lazily
|
|
1386
1386
|
if (isNull(vmBeingConstructed)) {
|
|
1387
|
-
|
|
1387
|
+
// Thrown when doing something like `new LightningElement()` or
|
|
1388
|
+
// `class Foo extends LightningElement {}; new Foo()`
|
|
1389
|
+
throw new TypeError('Illegal constructor');
|
|
1388
1390
|
}
|
|
1389
1391
|
const vm = vmBeingConstructed;
|
|
1390
1392
|
const { def, elm } = vm;
|
|
@@ -2164,34 +2166,19 @@ var LWC = (function (exports) {
|
|
|
2164
2166
|
freeze(BaseBridgeElement);
|
|
2165
2167
|
seal(BaseBridgeElement.prototype);
|
|
2166
2168
|
function setActiveVM(vm) {
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2169
|
+
{
|
|
2170
|
+
// this method should never leak to prod
|
|
2171
|
+
throw new ReferenceError();
|
|
2172
|
+
}
|
|
2171
2173
|
}
|
|
2172
2174
|
function swapTemplate(oldTpl, newTpl) {
|
|
2173
|
-
|
|
2174
|
-
if (!lwcRuntimeFlags.ENABLE_HMR) {
|
|
2175
|
-
throw new Error('HMR is not enabled');
|
|
2176
|
-
}
|
|
2177
|
-
|
|
2178
|
-
return false;
|
|
2175
|
+
return false;
|
|
2179
2176
|
}
|
|
2180
2177
|
function swapComponent(oldComponent, newComponent) {
|
|
2181
|
-
|
|
2182
|
-
if (!lwcRuntimeFlags.ENABLE_HMR) {
|
|
2183
|
-
throw new Error('HMR is not enabled');
|
|
2184
|
-
}
|
|
2185
|
-
|
|
2186
|
-
return false;
|
|
2178
|
+
return false;
|
|
2187
2179
|
}
|
|
2188
2180
|
function swapStyle(oldStyle, newStyle) {
|
|
2189
|
-
|
|
2190
|
-
if (!lwcRuntimeFlags.ENABLE_HMR) {
|
|
2191
|
-
throw new Error('HMR is not enabled');
|
|
2192
|
-
}
|
|
2193
|
-
|
|
2194
|
-
return false;
|
|
2181
|
+
return false;
|
|
2195
2182
|
}
|
|
2196
2183
|
|
|
2197
2184
|
/*
|
|
@@ -2570,15 +2557,18 @@ var LWC = (function (exports) {
|
|
|
2570
2557
|
/**
|
|
2571
2558
|
* This function returns the host style token for a custom element if it
|
|
2572
2559
|
* exists. Otherwise it returns null.
|
|
2560
|
+
*
|
|
2561
|
+
* A host style token is applied to the component if scoped styles are used.
|
|
2573
2562
|
*/
|
|
2574
2563
|
|
|
2575
2564
|
function getStylesheetTokenHost(vnode) {
|
|
2576
2565
|
const {
|
|
2577
|
-
template
|
|
2578
|
-
stylesheetToken
|
|
2579
|
-
}
|
|
2566
|
+
template
|
|
2580
2567
|
} = getComponentInternalDef(vnode.ctor);
|
|
2581
|
-
|
|
2568
|
+
const {
|
|
2569
|
+
stylesheetToken
|
|
2570
|
+
} = template;
|
|
2571
|
+
return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
|
|
2582
2572
|
}
|
|
2583
2573
|
|
|
2584
2574
|
function getNearestNativeShadowComponent(vm) {
|
|
@@ -2632,69 +2622,6 @@ var LWC = (function (exports) {
|
|
|
2632
2622
|
return null;
|
|
2633
2623
|
}
|
|
2634
2624
|
|
|
2635
|
-
/*
|
|
2636
|
-
* Copyright (c) 2020, salesforce.com, inc.
|
|
2637
|
-
* All rights reserved.
|
|
2638
|
-
* SPDX-License-Identifier: MIT
|
|
2639
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2640
|
-
*/
|
|
2641
|
-
|
|
2642
|
-
function checkHasVM(elm) {
|
|
2643
|
-
const hasVM = !isUndefined$1(getAssociatedVMIfPresent(elm));
|
|
2644
|
-
|
|
2645
|
-
return hasVM;
|
|
2646
|
-
}
|
|
2647
|
-
|
|
2648
|
-
function getUpgradableConstructor(tagName, renderer) {
|
|
2649
|
-
const {
|
|
2650
|
-
getCustomElement,
|
|
2651
|
-
HTMLElementExported: RendererHTMLElement,
|
|
2652
|
-
defineCustomElement
|
|
2653
|
-
} = renderer; // Should never get a tag with upper case letter at this point, the compiler should
|
|
2654
|
-
// produce only tags with lowercase letters
|
|
2655
|
-
// But, for backwards compatibility, we will lower case the tagName
|
|
2656
|
-
|
|
2657
|
-
tagName = tagName.toLowerCase();
|
|
2658
|
-
let CE = getCustomElement(tagName);
|
|
2659
|
-
|
|
2660
|
-
if (!isUndefined$1(CE)) {
|
|
2661
|
-
return CE;
|
|
2662
|
-
}
|
|
2663
|
-
/**
|
|
2664
|
-
* LWC Upgradable Element reference to an element that was created
|
|
2665
|
-
* via the scoped registry mechanism, and that is ready to be upgraded.
|
|
2666
|
-
*/
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
CE = class LWCUpgradableElement extends RendererHTMLElement {
|
|
2670
|
-
constructor(upgradeCallback) {
|
|
2671
|
-
super();
|
|
2672
|
-
|
|
2673
|
-
if (isFunction$1(upgradeCallback)) {
|
|
2674
|
-
upgradeCallback(this); // nothing to do with the result for now
|
|
2675
|
-
}
|
|
2676
|
-
}
|
|
2677
|
-
|
|
2678
|
-
};
|
|
2679
|
-
|
|
2680
|
-
if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
|
|
2681
|
-
CE.prototype.connectedCallback = function () {
|
|
2682
|
-
if (checkHasVM(this)) {
|
|
2683
|
-
connectRootElement(this);
|
|
2684
|
-
}
|
|
2685
|
-
};
|
|
2686
|
-
|
|
2687
|
-
CE.prototype.disconnectedCallback = function () {
|
|
2688
|
-
if (checkHasVM(this)) {
|
|
2689
|
-
disconnectRootElement(this);
|
|
2690
|
-
}
|
|
2691
|
-
};
|
|
2692
|
-
}
|
|
2693
|
-
|
|
2694
|
-
defineCustomElement(tagName, CE);
|
|
2695
|
-
return CE;
|
|
2696
|
-
}
|
|
2697
|
-
|
|
2698
2625
|
/*
|
|
2699
2626
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
2700
2627
|
* All rights reserved.
|
|
@@ -3182,7 +3109,9 @@ var LWC = (function (exports) {
|
|
|
3182
3109
|
sel,
|
|
3183
3110
|
owner
|
|
3184
3111
|
} = vnode;
|
|
3185
|
-
const
|
|
3112
|
+
const {
|
|
3113
|
+
createCustomElement
|
|
3114
|
+
} = renderer;
|
|
3186
3115
|
/**
|
|
3187
3116
|
* Note: if the upgradable constructor does not expect, or throw when we new it
|
|
3188
3117
|
* with a callback as the first argument, we could implement a more advanced
|
|
@@ -3191,10 +3120,25 @@ var LWC = (function (exports) {
|
|
|
3191
3120
|
*/
|
|
3192
3121
|
|
|
3193
3122
|
let vm;
|
|
3194
|
-
|
|
3123
|
+
|
|
3124
|
+
const upgradeCallback = elm => {
|
|
3195
3125
|
// the custom element from the registry is expecting an upgrade callback
|
|
3196
3126
|
vm = createViewModelHook(elm, vnode, renderer);
|
|
3197
|
-
}
|
|
3127
|
+
};
|
|
3128
|
+
|
|
3129
|
+
const connectedCallback = elm => {
|
|
3130
|
+
if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
|
|
3131
|
+
connectRootElement(elm);
|
|
3132
|
+
}
|
|
3133
|
+
};
|
|
3134
|
+
|
|
3135
|
+
const disconnectedCallback = elm => {
|
|
3136
|
+
if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
|
|
3137
|
+
disconnectRootElement(elm);
|
|
3138
|
+
}
|
|
3139
|
+
};
|
|
3140
|
+
|
|
3141
|
+
const elm = createCustomElement(sel, upgradeCallback, connectedCallback, disconnectedCallback);
|
|
3198
3142
|
vnode.elm = elm;
|
|
3199
3143
|
vnode.vm = vm;
|
|
3200
3144
|
linkNodeToShadow(elm, owner, renderer);
|
|
@@ -3202,8 +3146,6 @@ var LWC = (function (exports) {
|
|
|
3202
3146
|
|
|
3203
3147
|
if (vm) {
|
|
3204
3148
|
allocateChildren(vnode, vm);
|
|
3205
|
-
} else if (vnode.ctor !== UpgradableConstructor) {
|
|
3206
|
-
throw new TypeError(`Incorrect Component Constructor`);
|
|
3207
3149
|
}
|
|
3208
3150
|
|
|
3209
3151
|
patchElementPropsAndAttrs$1(null, vnode, renderer);
|
|
@@ -5559,19 +5501,23 @@ var LWC = (function (exports) {
|
|
|
5559
5501
|
//
|
|
5560
5502
|
// Consequently, hydration mismatches will occur if scoped CSS token classnames
|
|
5561
5503
|
// are rendered during SSR. This needs to be accounted for when validating.
|
|
5562
|
-
if (scopedToken) {
|
|
5504
|
+
if (!isNull(scopedToken) || !isNull(stylesheetTokenHost)) {
|
|
5563
5505
|
if (!isUndefined$1(className)) {
|
|
5564
|
-
className
|
|
5565
|
-
|
|
5566
|
-
|
|
5506
|
+
// The order of the className should be scopedToken className stylesheetTokenHost
|
|
5507
|
+
const classTokens = [scopedToken, className, stylesheetTokenHost];
|
|
5508
|
+
const classNames = ArrayFilter.call(classTokens, (token) => !isNull(token));
|
|
5509
|
+
className = ArrayJoin.call(classNames, ' ');
|
|
5567
5510
|
}
|
|
5568
5511
|
else if (!isUndefined$1(classMap)) {
|
|
5569
|
-
classMap = Object.assign(Object.assign(Object.assign({}, classMap), { [scopedToken]: true }), (isNull(stylesheetTokenHost) ? {
|
|
5512
|
+
classMap = Object.assign(Object.assign(Object.assign({}, classMap), (!isNull(scopedToken) ? { [scopedToken]: true } : {})), (!isNull(stylesheetTokenHost) ? { [stylesheetTokenHost]: true } : {}));
|
|
5570
5513
|
}
|
|
5571
5514
|
else {
|
|
5572
|
-
className
|
|
5573
|
-
|
|
5574
|
-
|
|
5515
|
+
// The order of the className should be scopedToken stylesheetTokenHost
|
|
5516
|
+
const classTokens = [scopedToken, stylesheetTokenHost];
|
|
5517
|
+
const classNames = ArrayFilter.call(classTokens, (token) => !isNull(token));
|
|
5518
|
+
if (classNames.length) {
|
|
5519
|
+
className = ArrayJoin.call(classNames, ' ');
|
|
5520
|
+
}
|
|
5575
5521
|
}
|
|
5576
5522
|
}
|
|
5577
5523
|
let nodesAreCompatible = true;
|
|
@@ -5700,7 +5646,7 @@ var LWC = (function (exports) {
|
|
|
5700
5646
|
}
|
|
5701
5647
|
return ctor;
|
|
5702
5648
|
}
|
|
5703
|
-
/* version: 2.
|
|
5649
|
+
/* version: 2.26.0 */
|
|
5704
5650
|
|
|
5705
5651
|
/*
|
|
5706
5652
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -5835,6 +5781,626 @@ var LWC = (function (exports) {
|
|
|
5835
5781
|
}
|
|
5836
5782
|
}
|
|
5837
5783
|
|
|
5784
|
+
/*
|
|
5785
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
5786
|
+
* All rights reserved.
|
|
5787
|
+
* SPDX-License-Identifier: MIT
|
|
5788
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5789
|
+
*/
|
|
5790
|
+
function isCustomElementRegistryAvailable() {
|
|
5791
|
+
if (typeof customElements === 'undefined') {
|
|
5792
|
+
return false;
|
|
5793
|
+
}
|
|
5794
|
+
try {
|
|
5795
|
+
// dereference HTMLElement global because babel wraps globals in compat mode with a
|
|
5796
|
+
// _wrapNativeSuper()
|
|
5797
|
+
// This is a problem because LWCUpgradableElement extends renderer.HTMLElement which does not
|
|
5798
|
+
// get wrapped by babel.
|
|
5799
|
+
const HTMLElementAlias = HTMLElement;
|
|
5800
|
+
// In case we use compat mode with a modern browser, the compat mode transformation
|
|
5801
|
+
// invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
|
|
5802
|
+
// which are not equipped to be initialized that way.
|
|
5803
|
+
class clazz extends HTMLElementAlias {
|
|
5804
|
+
}
|
|
5805
|
+
customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
|
|
5806
|
+
new clazz();
|
|
5807
|
+
return true;
|
|
5808
|
+
}
|
|
5809
|
+
catch (_a) {
|
|
5810
|
+
return false;
|
|
5811
|
+
}
|
|
5812
|
+
}
|
|
5813
|
+
const hasCustomElements = isCustomElementRegistryAvailable();
|
|
5814
|
+
|
|
5815
|
+
/*
|
|
5816
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
5817
|
+
* All rights reserved.
|
|
5818
|
+
* SPDX-License-Identifier: MIT
|
|
5819
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5820
|
+
*/
|
|
5821
|
+
// Creates a custom element for compat (legacy) browser environments
|
|
5822
|
+
const createCustomElementCompat = (tagName, upgradeCallback) => {
|
|
5823
|
+
const elm = document.createElement(tagName);
|
|
5824
|
+
upgradeCallback(elm); // nothing to do with the result for now
|
|
5825
|
+
return elm;
|
|
5826
|
+
};
|
|
5827
|
+
|
|
5828
|
+
/*
|
|
5829
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
5830
|
+
* All rights reserved.
|
|
5831
|
+
* SPDX-License-Identifier: MIT
|
|
5832
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5833
|
+
*/
|
|
5834
|
+
const cachedConstructors = new Map();
|
|
5835
|
+
const elementsUpgradedOutsideLWC = new WeakSet();
|
|
5836
|
+
let elementBeingUpgradedByLWC = false;
|
|
5837
|
+
// Creates a constructor that is intended to be used as a vanilla custom element, except that the upgradeCallback is
|
|
5838
|
+
// passed in to the constructor so LWC can reuse the same custom element constructor for multiple components.
|
|
5839
|
+
// Another benefit is that only LWC can create components that actually do anything – if you do
|
|
5840
|
+
// `customElements.define('x-foo')`, then you don't have access to the upgradeCallback, so it's a dummy custom element.
|
|
5841
|
+
// This class should be created once per tag name.
|
|
5842
|
+
const createUpgradableConstructor = (connectedCallback, disconnectedCallback) => {
|
|
5843
|
+
// TODO [#2972]: this class should expose observedAttributes as necessary
|
|
5844
|
+
return class UpgradableConstructor extends HTMLElement {
|
|
5845
|
+
constructor(upgradeCallback) {
|
|
5846
|
+
super();
|
|
5847
|
+
// If the element is not created using lwc.createElement(), e.g. `document.createElement('x-foo')`,
|
|
5848
|
+
// then elementBeingUpgraded will be false
|
|
5849
|
+
if (elementBeingUpgradedByLWC) {
|
|
5850
|
+
upgradeCallback(this);
|
|
5851
|
+
}
|
|
5852
|
+
else {
|
|
5853
|
+
// keep track of elements that were not created by lwc.createElement,
|
|
5854
|
+
// so we can ignore their lifecycle hooks
|
|
5855
|
+
elementsUpgradedOutsideLWC.add(this);
|
|
5856
|
+
// TODO [#2970]: LWC elements cannot be upgraded via new Ctor()
|
|
5857
|
+
// Do we want to support this? Throw an error? Currently for backwards compat it's a no-op.
|
|
5858
|
+
}
|
|
5859
|
+
}
|
|
5860
|
+
connectedCallback() {
|
|
5861
|
+
if (!elementsUpgradedOutsideLWC.has(this)) {
|
|
5862
|
+
connectedCallback(this);
|
|
5863
|
+
}
|
|
5864
|
+
}
|
|
5865
|
+
disconnectedCallback() {
|
|
5866
|
+
if (!elementsUpgradedOutsideLWC.has(this)) {
|
|
5867
|
+
disconnectedCallback(this);
|
|
5868
|
+
}
|
|
5869
|
+
}
|
|
5870
|
+
};
|
|
5871
|
+
};
|
|
5872
|
+
const createCustomElementVanilla = (tagName, upgradeCallback, connectedCallback, disconnectedCallback) => {
|
|
5873
|
+
// use global custom elements registry
|
|
5874
|
+
let UpgradableConstructor = cachedConstructors.get(tagName);
|
|
5875
|
+
if (isUndefined$1(UpgradableConstructor)) {
|
|
5876
|
+
if (!isUndefined$1(customElements.get(tagName))) {
|
|
5877
|
+
throw new Error(`Unexpected tag name "${tagName}". This name is a registered custom element, preventing LWC to upgrade the element.`);
|
|
5878
|
+
}
|
|
5879
|
+
UpgradableConstructor = createUpgradableConstructor(connectedCallback, disconnectedCallback);
|
|
5880
|
+
customElements.define(tagName, UpgradableConstructor);
|
|
5881
|
+
cachedConstructors.set(tagName, UpgradableConstructor);
|
|
5882
|
+
}
|
|
5883
|
+
elementBeingUpgradedByLWC = true;
|
|
5884
|
+
try {
|
|
5885
|
+
return new UpgradableConstructor(upgradeCallback);
|
|
5886
|
+
}
|
|
5887
|
+
finally {
|
|
5888
|
+
elementBeingUpgradedByLWC = false;
|
|
5889
|
+
}
|
|
5890
|
+
};
|
|
5891
|
+
|
|
5892
|
+
/*
|
|
5893
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
5894
|
+
* All rights reserved.
|
|
5895
|
+
* SPDX-License-Identifier: MIT
|
|
5896
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5897
|
+
*/
|
|
5898
|
+
/**
|
|
5899
|
+
* Create a scoped registry, i.e. a function that can create custom elements whose tag names
|
|
5900
|
+
* do not conflict with vanilla custom elements having the same tag name.
|
|
5901
|
+
*/
|
|
5902
|
+
function createScopedRegistry() {
|
|
5903
|
+
if (!hasCustomElements) {
|
|
5904
|
+
// This code should never be reached, because we don't use the pivot registry if
|
|
5905
|
+
// custom elements are unavailable.
|
|
5906
|
+
throw new Error('Custom elements are not supported in this environment.');
|
|
5907
|
+
}
|
|
5908
|
+
const { HTMLElement: NativeHTMLElement } = window;
|
|
5909
|
+
const { hasAttribute: nativeHasAttribute, setAttribute: nativeSetAttribute, removeAttribute: nativeRemoveAttribute, getAttribute: nativeGetAttribute, } = NativeHTMLElement.prototype;
|
|
5910
|
+
const definitionForElement = new WeakMap();
|
|
5911
|
+
const pendingRegistryForElement = new WeakMap();
|
|
5912
|
+
const definitionForConstructor = new WeakMap();
|
|
5913
|
+
const registeredUserCtors = new WeakSet();
|
|
5914
|
+
const pivotCtorByTag = new Map();
|
|
5915
|
+
const globalDefinitionsByTag = new Map();
|
|
5916
|
+
const globalDefinitionsByClass = new Map();
|
|
5917
|
+
const awaitingUpgrade = new Map();
|
|
5918
|
+
const EMPTY_SET = new Set();
|
|
5919
|
+
function createDefinitionRecord(constructor) {
|
|
5920
|
+
var _a;
|
|
5921
|
+
const { connectedCallback, disconnectedCallback, adoptedCallback, attributeChangedCallback, } = constructor.prototype;
|
|
5922
|
+
const observedAttributes = new Set((_a = constructor.observedAttributes) !== null && _a !== void 0 ? _a : []);
|
|
5923
|
+
return {
|
|
5924
|
+
UserCtor: constructor,
|
|
5925
|
+
PivotCtor: undefined,
|
|
5926
|
+
connectedCallback,
|
|
5927
|
+
disconnectedCallback,
|
|
5928
|
+
adoptedCallback,
|
|
5929
|
+
attributeChangedCallback,
|
|
5930
|
+
observedAttributes,
|
|
5931
|
+
};
|
|
5932
|
+
}
|
|
5933
|
+
// Helper to create stand-in element for each tagName registered that delegates out to the registry for the given
|
|
5934
|
+
// element. Note that the `registeredDefinition` represents the constructor that was used to register during
|
|
5935
|
+
// `customElements.define()`. Whereas the `pivotDefinition` represents the constructor that is passed when the pivot
|
|
5936
|
+
// constructor is invoked with another constructor.
|
|
5937
|
+
function createPivotingClass(tagName, registeredDefinition) {
|
|
5938
|
+
class PivotCtor extends NativeHTMLElement {
|
|
5939
|
+
constructor(UserCtor) {
|
|
5940
|
+
// This constructor can only be invoked by:
|
|
5941
|
+
// a) the browser instantiating an element from parsing or via document.createElement.
|
|
5942
|
+
// b) LWC new PivotClass (This constructor is NOT observable/accessible in user-land).
|
|
5943
|
+
// b) new UserClass.
|
|
5944
|
+
// When LWC instantiates it, it will pass the upgrading definition as an argument
|
|
5945
|
+
// If the caller signals via UserCtor that this is in fact a controlled
|
|
5946
|
+
// definition, we use that one, otherwise fallback to the global
|
|
5947
|
+
// internal registry.
|
|
5948
|
+
super();
|
|
5949
|
+
const userCtorIsDefined = !isUndefined$1(UserCtor);
|
|
5950
|
+
if (userCtorIsDefined) {
|
|
5951
|
+
if (!isConstructor(UserCtor)) {
|
|
5952
|
+
throw new TypeError(`Failed to create custom element: the provided constructor is not a constructor.`);
|
|
5953
|
+
}
|
|
5954
|
+
if (!registeredUserCtors.has(UserCtor)) {
|
|
5955
|
+
throw new Error(`Failed to create custom element: the provided constructor is unregistered: ${UserCtor.name}.`);
|
|
5956
|
+
}
|
|
5957
|
+
}
|
|
5958
|
+
const definition = userCtorIsDefined
|
|
5959
|
+
? getOrCreateDefinitionForConstructor(UserCtor)
|
|
5960
|
+
: globalDefinitionsByTag.get(tagName);
|
|
5961
|
+
if (!isUndefined$1(definition)) {
|
|
5962
|
+
internalUpgrade(this, registeredDefinition, definition);
|
|
5963
|
+
}
|
|
5964
|
+
else {
|
|
5965
|
+
// This is the case in which there is no global definition, and
|
|
5966
|
+
// it is not handled by LWC (otherwise it will have a valid UserCtor)
|
|
5967
|
+
// so we need to add it to the pending queue just in case it eventually
|
|
5968
|
+
// gets defined in the global registry.
|
|
5969
|
+
pendingRegistryForElement.set(this, registeredDefinition);
|
|
5970
|
+
}
|
|
5971
|
+
}
|
|
5972
|
+
connectedCallback() {
|
|
5973
|
+
var _a;
|
|
5974
|
+
const definition = definitionForElement.get(this);
|
|
5975
|
+
if (!isUndefined$1(definition)) {
|
|
5976
|
+
// Delegate out to user callback
|
|
5977
|
+
(_a = definition.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
5978
|
+
}
|
|
5979
|
+
else {
|
|
5980
|
+
// Register for upgrade when defined (only when connected, so we don't leak)
|
|
5981
|
+
let awaiting = awaitingUpgrade.get(tagName);
|
|
5982
|
+
if (isUndefined$1(awaiting)) {
|
|
5983
|
+
awaitingUpgrade.set(tagName, (awaiting = new Set()));
|
|
5984
|
+
}
|
|
5985
|
+
awaiting.add(this);
|
|
5986
|
+
}
|
|
5987
|
+
}
|
|
5988
|
+
disconnectedCallback() {
|
|
5989
|
+
var _a;
|
|
5990
|
+
const definition = definitionForElement.get(this);
|
|
5991
|
+
if (!isUndefined$1(definition)) {
|
|
5992
|
+
// Delegate out to user callback
|
|
5993
|
+
(_a = definition.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
5994
|
+
}
|
|
5995
|
+
else {
|
|
5996
|
+
// Un-register for upgrade when defined (so we don't leak)
|
|
5997
|
+
const awaiting = awaitingUpgrade.get(tagName);
|
|
5998
|
+
// At this point, awaiting should never be undefined, because connectedCallback
|
|
5999
|
+
// must have been called before disconnectedCallback. But just to be safe, we check
|
|
6000
|
+
if (!isUndefined$1(awaiting)) {
|
|
6001
|
+
awaiting.delete(this);
|
|
6002
|
+
}
|
|
6003
|
+
}
|
|
6004
|
+
}
|
|
6005
|
+
adoptedCallback() {
|
|
6006
|
+
var _a;
|
|
6007
|
+
const definition = definitionForElement.get(this);
|
|
6008
|
+
(_a = definition === null || definition === void 0 ? void 0 : definition.adoptedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
6009
|
+
}
|
|
6010
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
6011
|
+
var _a;
|
|
6012
|
+
const definition = definitionForElement.get(this);
|
|
6013
|
+
// if both definitions are the same, then the observedAttributes is the same,
|
|
6014
|
+
// but if they are different, only if the runtime definition has the attribute
|
|
6015
|
+
// marked as observed, then it should invoke attributeChangedCallback.
|
|
6016
|
+
if (registeredDefinition === definition ||
|
|
6017
|
+
(definition === null || definition === void 0 ? void 0 : definition.observedAttributes.has(name))) {
|
|
6018
|
+
(_a = definition.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.apply(this, [name, oldValue, newValue]);
|
|
6019
|
+
}
|
|
6020
|
+
}
|
|
6021
|
+
}
|
|
6022
|
+
PivotCtor.observedAttributes = [...registeredDefinition.observedAttributes];
|
|
6023
|
+
return PivotCtor;
|
|
6024
|
+
}
|
|
6025
|
+
function getNewObservedAttributes(registeredDefinition, pivotDefinition) {
|
|
6026
|
+
const { observedAttributes, attributeChangedCallback } = pivotDefinition;
|
|
6027
|
+
if (observedAttributes.size === 0 || isUndefined$1(attributeChangedCallback)) {
|
|
6028
|
+
// This instance does not need to observe any attributes, no need to patch
|
|
6029
|
+
return EMPTY_SET;
|
|
6030
|
+
}
|
|
6031
|
+
// Natively, the attributes observed by the registered definition are going to be taken
|
|
6032
|
+
// care of by the browser, only the difference between the two sets has to be taken
|
|
6033
|
+
// care by the patched version.
|
|
6034
|
+
return new Set([...pivotDefinition.observedAttributes].filter((x) => !registeredDefinition.observedAttributes.has(x)));
|
|
6035
|
+
}
|
|
6036
|
+
function throwAsyncError(error) {
|
|
6037
|
+
// Per native custom element behavior, errors thrown in attributeChangedCallback
|
|
6038
|
+
// become unhandled async errors. We use setTimeout() instead of Promise.resolve()
|
|
6039
|
+
// to make it an unhandled error rather than an unhandled rejection.
|
|
6040
|
+
setTimeout(() => {
|
|
6041
|
+
throw error;
|
|
6042
|
+
});
|
|
6043
|
+
}
|
|
6044
|
+
// Helper to patch `setAttribute`/`getAttribute` to implement `attributeChangedCallback`.
|
|
6045
|
+
// Why is this necessary? Well basically, you can't change the `observedAttributes` after
|
|
6046
|
+
// a custom element is defined. So with pivots, if two classes share the same tag name,
|
|
6047
|
+
// and the second class observes attributes that aren't observed by the first one,
|
|
6048
|
+
// then those attributes can never be observed by the native `observedAttributes` system.
|
|
6049
|
+
// So we have to simulate it by patching `getAttribute`/`removeAttribute`. Note that
|
|
6050
|
+
// we only do this when absolutely necessary, though; i.e. because we've determined
|
|
6051
|
+
// that we aren't observing the attributes we need to.
|
|
6052
|
+
function patchAttributes(instance, registeredDefinition, pivotDefinition) {
|
|
6053
|
+
const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
|
|
6054
|
+
if (newObservedAttributes.size === 0) {
|
|
6055
|
+
return;
|
|
6056
|
+
}
|
|
6057
|
+
const { attributeChangedCallback } = pivotDefinition;
|
|
6058
|
+
// Patch the instance.
|
|
6059
|
+
// Note we use the native `getAttribute` rather than the super's `getAttribute` because
|
|
6060
|
+
// we don't actually want it to be observable that we're calling `getAttribute` from
|
|
6061
|
+
// `setAttribute` and `removeAttribute`.
|
|
6062
|
+
// TODO [#2994]: this should handle reflected properties such as `ariaLabel` and `role`.
|
|
6063
|
+
defineProperties(instance, {
|
|
6064
|
+
setAttribute: {
|
|
6065
|
+
value: function setAttribute(name, value) {
|
|
6066
|
+
if (newObservedAttributes.has(name)) {
|
|
6067
|
+
const old = nativeGetAttribute.call(this, name);
|
|
6068
|
+
nativeSetAttribute.call(this, name, value);
|
|
6069
|
+
try {
|
|
6070
|
+
attributeChangedCallback.call(this, name, old, value + '');
|
|
6071
|
+
}
|
|
6072
|
+
catch (error) {
|
|
6073
|
+
throwAsyncError(error);
|
|
6074
|
+
}
|
|
6075
|
+
}
|
|
6076
|
+
else {
|
|
6077
|
+
nativeSetAttribute.call(this, name, value);
|
|
6078
|
+
}
|
|
6079
|
+
},
|
|
6080
|
+
writable: true,
|
|
6081
|
+
enumerable: true,
|
|
6082
|
+
configurable: true,
|
|
6083
|
+
},
|
|
6084
|
+
removeAttribute: {
|
|
6085
|
+
value: function removeAttribute(name) {
|
|
6086
|
+
if (newObservedAttributes.has(name)) {
|
|
6087
|
+
const old = nativeGetAttribute.call(this, name);
|
|
6088
|
+
nativeRemoveAttribute.call(this, name);
|
|
6089
|
+
try {
|
|
6090
|
+
attributeChangedCallback.call(this, name, old, null);
|
|
6091
|
+
}
|
|
6092
|
+
catch (error) {
|
|
6093
|
+
throwAsyncError(error);
|
|
6094
|
+
}
|
|
6095
|
+
}
|
|
6096
|
+
else {
|
|
6097
|
+
nativeRemoveAttribute.call(this, name);
|
|
6098
|
+
}
|
|
6099
|
+
},
|
|
6100
|
+
writable: true,
|
|
6101
|
+
enumerable: true,
|
|
6102
|
+
configurable: true,
|
|
6103
|
+
},
|
|
6104
|
+
});
|
|
6105
|
+
}
|
|
6106
|
+
function patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition) {
|
|
6107
|
+
// The below case patches observed attributes for the case where the HTML element is upgraded
|
|
6108
|
+
// from a pre-existing one in the DOM.
|
|
6109
|
+
const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
|
|
6110
|
+
if (getNewObservedAttributes(registeredDefinition, pivotDefinition).size === 0) {
|
|
6111
|
+
return;
|
|
6112
|
+
}
|
|
6113
|
+
const { attributeChangedCallback } = pivotDefinition;
|
|
6114
|
+
// Approximate observedAttributes from the user class, but only for the new observed attributes
|
|
6115
|
+
newObservedAttributes.forEach((name) => {
|
|
6116
|
+
if (nativeHasAttribute.call(instance, name)) {
|
|
6117
|
+
const newValue = nativeGetAttribute.call(instance, name);
|
|
6118
|
+
attributeChangedCallback.call(instance, name, null, newValue);
|
|
6119
|
+
}
|
|
6120
|
+
});
|
|
6121
|
+
}
|
|
6122
|
+
// User extends this HTMLElement, which returns the CE being upgraded
|
|
6123
|
+
let upgradingInstance;
|
|
6124
|
+
// Helper to upgrade an instance with a CE definition using "constructor call trick"
|
|
6125
|
+
function internalUpgrade(instance, registeredDefinition, pivotDefinition) {
|
|
6126
|
+
setPrototypeOf(instance, pivotDefinition.UserCtor.prototype);
|
|
6127
|
+
definitionForElement.set(instance, pivotDefinition);
|
|
6128
|
+
// attributes patches when needed
|
|
6129
|
+
if (pivotDefinition !== registeredDefinition) {
|
|
6130
|
+
patchAttributes(instance, registeredDefinition, pivotDefinition);
|
|
6131
|
+
}
|
|
6132
|
+
// Tricking the construction path to believe that a new instance is being created,
|
|
6133
|
+
// that way it will execute the super initialization mechanism but the HTMLElement
|
|
6134
|
+
// constructor will reuse the instance by returning the upgradingInstance.
|
|
6135
|
+
// This is by far the most important piece of the puzzle
|
|
6136
|
+
upgradingInstance = instance;
|
|
6137
|
+
// By `new`ing the UserCtor, we now jump to the constructor for the overridden global HTMLElement
|
|
6138
|
+
// The reason this happens is that the UserCtor extends HTMLElement, so it calls the `super()`.
|
|
6139
|
+
// Note that `upgradingInstance` is explicitly handled in the HTMLElement constructor.
|
|
6140
|
+
new pivotDefinition.UserCtor();
|
|
6141
|
+
patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition);
|
|
6142
|
+
}
|
|
6143
|
+
function isConstructor(constructor) {
|
|
6144
|
+
return isFunction$1(constructor) && isObject(constructor.prototype);
|
|
6145
|
+
}
|
|
6146
|
+
function getOrCreateDefinitionForConstructor(constructor) {
|
|
6147
|
+
if (!isConstructor(constructor)) {
|
|
6148
|
+
throw new TypeError('The referenced constructor is not a constructor.');
|
|
6149
|
+
}
|
|
6150
|
+
const definition = definitionForConstructor.get(constructor);
|
|
6151
|
+
if (!isUndefined$1(definition)) {
|
|
6152
|
+
return definition;
|
|
6153
|
+
}
|
|
6154
|
+
return createDefinitionRecord(constructor);
|
|
6155
|
+
}
|
|
6156
|
+
const { customElements: nativeRegistry } = window;
|
|
6157
|
+
const { define: nativeDefine, whenDefined: nativeWhenDefined, get: nativeGet } = nativeRegistry;
|
|
6158
|
+
// patch for the global registry define mechanism
|
|
6159
|
+
CustomElementRegistry.prototype.define = function define(tagName, constructor, options) {
|
|
6160
|
+
if (options && options.extends) {
|
|
6161
|
+
// TODO [#2983]: should we support `extends`?
|
|
6162
|
+
throw new DOMException('NotSupportedError: "extends" key in customElements.define() options is not supported.');
|
|
6163
|
+
}
|
|
6164
|
+
if (globalDefinitionsByTag.has(tagName)) {
|
|
6165
|
+
throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': the name "${tagName}" has already been used with this registry`);
|
|
6166
|
+
}
|
|
6167
|
+
if (!isUndefined$1(globalDefinitionsByClass.get(constructor))) {
|
|
6168
|
+
throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': this constructor has already been used with this registry`);
|
|
6169
|
+
}
|
|
6170
|
+
const definition = getOrCreateDefinitionForConstructor(constructor);
|
|
6171
|
+
registeredUserCtors.add(constructor);
|
|
6172
|
+
let PivotCtor = pivotCtorByTag.get(tagName);
|
|
6173
|
+
if (isUndefined$1(PivotCtor)) {
|
|
6174
|
+
PivotCtor = createPivotingClass(tagName, definition);
|
|
6175
|
+
// Register a pivoting class which will handle global registry initializations
|
|
6176
|
+
nativeDefine.call(nativeRegistry, tagName, PivotCtor);
|
|
6177
|
+
}
|
|
6178
|
+
// Only cache after nativeDefine has been called, because if it throws an error
|
|
6179
|
+
// (e.g. for an invalid tag name), then we don't want to cache anything.
|
|
6180
|
+
definitionForConstructor.set(constructor, definition);
|
|
6181
|
+
pivotCtorByTag.set(tagName, PivotCtor);
|
|
6182
|
+
globalDefinitionsByTag.set(tagName, definition);
|
|
6183
|
+
globalDefinitionsByClass.set(constructor, definition);
|
|
6184
|
+
// For globally defined custom elements, the definition associated
|
|
6185
|
+
// to the UserCtor has a back-pointer to PivotCtor in case the user
|
|
6186
|
+
// new the UserCtor, so we know how to create the underlying element.
|
|
6187
|
+
definition.PivotCtor = PivotCtor;
|
|
6188
|
+
// Upgrade any elements created in this scope before customElements.define
|
|
6189
|
+
// was called, which should be exhibited by the following steps:
|
|
6190
|
+
// 1) LWC registers a tagName for an LWC component.
|
|
6191
|
+
// 2) Element with same tagName is created with document.createElement()
|
|
6192
|
+
// and inserted into DOM.
|
|
6193
|
+
// 3) customElements.define() is called with tagName and non-LWC constructor.
|
|
6194
|
+
// This requires immediate upgrade when the new global tagName is defined.
|
|
6195
|
+
const awaiting = awaitingUpgrade.get(tagName);
|
|
6196
|
+
if (!isUndefined$1(awaiting)) {
|
|
6197
|
+
awaitingUpgrade.delete(tagName);
|
|
6198
|
+
for (const element of awaiting) {
|
|
6199
|
+
const registeredDefinition = pendingRegistryForElement.get(element);
|
|
6200
|
+
// At this point, registeredDefinition should never be undefined because awaitingUpgrade
|
|
6201
|
+
// is only populated when we haven't run internalUpgrade yet, and we only populate
|
|
6202
|
+
// pendingRegistryForElement when internalUpgrade hasn't run yet.
|
|
6203
|
+
// But just to be safe, we check.
|
|
6204
|
+
if (!isUndefined$1(registeredDefinition)) {
|
|
6205
|
+
pendingRegistryForElement.delete(element);
|
|
6206
|
+
internalUpgrade(element, registeredDefinition, definition);
|
|
6207
|
+
}
|
|
6208
|
+
}
|
|
6209
|
+
}
|
|
6210
|
+
};
|
|
6211
|
+
CustomElementRegistry.prototype.get = function get(tagName) {
|
|
6212
|
+
const NativeCtor = nativeGet.call(nativeRegistry, tagName);
|
|
6213
|
+
if (!isUndefined$1(NativeCtor)) {
|
|
6214
|
+
const definition = globalDefinitionsByTag.get(tagName);
|
|
6215
|
+
if (!isUndefined$1(definition)) {
|
|
6216
|
+
return definition.UserCtor; // defined by the patched custom elements registry
|
|
6217
|
+
}
|
|
6218
|
+
// TODO [#3073]: return undefined rather than the pivot constructor (NativeCtor)
|
|
6219
|
+
return NativeCtor; // return the pivot constructor or constructor that existed before patching
|
|
6220
|
+
}
|
|
6221
|
+
};
|
|
6222
|
+
CustomElementRegistry.prototype.whenDefined = function whenDefined(tagName) {
|
|
6223
|
+
return nativeWhenDefined.call(nativeRegistry, tagName).then((NativeCtor) => {
|
|
6224
|
+
const definition = globalDefinitionsByTag.get(tagName);
|
|
6225
|
+
if (!isUndefined$1(definition)) {
|
|
6226
|
+
return definition.UserCtor;
|
|
6227
|
+
}
|
|
6228
|
+
// TODO [#3073]: return undefined rather than the pivot constructor (NativeCtor)
|
|
6229
|
+
// In this case, the custom element must have been defined before the registry patches
|
|
6230
|
+
// were applied. So return the non-pivot constructor
|
|
6231
|
+
if (isUndefined$1(NativeCtor)) {
|
|
6232
|
+
// Chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1335247
|
|
6233
|
+
// We can patch the correct behavior using customElements.get()
|
|
6234
|
+
return nativeGet.call(nativeRegistry, tagName);
|
|
6235
|
+
}
|
|
6236
|
+
return NativeCtor;
|
|
6237
|
+
});
|
|
6238
|
+
};
|
|
6239
|
+
// This constructor is invoked when we call `new pivotDefinition.UserCtor()`
|
|
6240
|
+
// @ts-ignore
|
|
6241
|
+
window.HTMLElement = function HTMLElement() {
|
|
6242
|
+
// Upgrading case: the pivoting class constructor was run by the browser's
|
|
6243
|
+
// native custom elements and we're in the process of running the
|
|
6244
|
+
// "constructor-call trick" on the natively constructed instance, so just
|
|
6245
|
+
// return that here.
|
|
6246
|
+
// This code path is also called when LWC `new`s a PivotCtor.
|
|
6247
|
+
const instance = upgradingInstance;
|
|
6248
|
+
if (!isUndefined$1(instance)) {
|
|
6249
|
+
upgradingInstance = undefined;
|
|
6250
|
+
return instance;
|
|
6251
|
+
}
|
|
6252
|
+
// Construction case: we need to construct the pivoting instance and return it.
|
|
6253
|
+
// This is possible when the user register it via global registry and instantiate
|
|
6254
|
+
// it via `new Ctor()`.
|
|
6255
|
+
const { constructor } = this;
|
|
6256
|
+
const definition = globalDefinitionsByClass.get(constructor);
|
|
6257
|
+
if (isUndefined$1(definition) || isUndefined$1(definition.PivotCtor)) {
|
|
6258
|
+
// This code path is hit if someone `new`s a class that extends `HTMLElement` without
|
|
6259
|
+
// doing `customElements.define()` first. This matches native browser behavior:
|
|
6260
|
+
// https://stackoverflow.com/a/61883392
|
|
6261
|
+
throw new TypeError('Illegal constructor');
|
|
6262
|
+
}
|
|
6263
|
+
// This constructor is ONLY invoked when it is the user instantiating
|
|
6264
|
+
// an element via new Ctor while Ctor is a registered global constructor.
|
|
6265
|
+
const { PivotCtor, UserCtor } = definition;
|
|
6266
|
+
return new PivotCtor(UserCtor);
|
|
6267
|
+
};
|
|
6268
|
+
HTMLElement.prototype = NativeHTMLElement.prototype;
|
|
6269
|
+
/**
|
|
6270
|
+
* Create a new PivotConstructor for the given tagName, which is capable of being constructed
|
|
6271
|
+
* with a UserConstructor defining the behavior. Passing in the UserConstructor here
|
|
6272
|
+
* is a hint that can be used when registering a custom element with the global custom elements
|
|
6273
|
+
* registry for the first time, which provides certain optimizations. It also marks the UserConstructor
|
|
6274
|
+
* as "safe" to be used when passed in to a PivotConstructor.
|
|
6275
|
+
*
|
|
6276
|
+
* @param tagName - element tag name
|
|
6277
|
+
* @param UserCtor - userland custom element constructor
|
|
6278
|
+
* @returns a new custom element constructor
|
|
6279
|
+
*/
|
|
6280
|
+
return function createPivotConstructor(tagName, UserCtor) {
|
|
6281
|
+
tagName = StringToLowerCase.call(tagName);
|
|
6282
|
+
let PivotCtor = pivotCtorByTag.get(tagName);
|
|
6283
|
+
if (isUndefined$1(PivotCtor)) {
|
|
6284
|
+
const definition = getOrCreateDefinitionForConstructor(UserCtor);
|
|
6285
|
+
PivotCtor = createPivotingClass(tagName, definition);
|
|
6286
|
+
// Register a pivoting class as a global custom element
|
|
6287
|
+
nativeDefine.call(nativeRegistry, tagName, PivotCtor);
|
|
6288
|
+
definition.PivotCtor = PivotCtor;
|
|
6289
|
+
// Only cache after nativeDefine has been called, because if it throws an error
|
|
6290
|
+
// (e.g. for an invalid tag name), then we don't want to cache anything.
|
|
6291
|
+
definitionForConstructor.set(UserCtor, definition);
|
|
6292
|
+
pivotCtorByTag.set(tagName, PivotCtor);
|
|
6293
|
+
}
|
|
6294
|
+
// Register a UserConstructor as "safe" to be used within a PivotConstructor
|
|
6295
|
+
registeredUserCtors.add(UserCtor);
|
|
6296
|
+
return PivotCtor;
|
|
6297
|
+
};
|
|
6298
|
+
}
|
|
6299
|
+
|
|
6300
|
+
/*
|
|
6301
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
6302
|
+
* All rights reserved.
|
|
6303
|
+
* SPDX-License-Identifier: MIT
|
|
6304
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6305
|
+
*/
|
|
6306
|
+
let createScopedConstructor;
|
|
6307
|
+
let CachedHTMLElement; // We only call `createScopedRegistry()` if the browser supports custom elements and
|
|
6308
|
+
// ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is enabled, because we don't want to patch eagerly if the flag is disabled
|
|
6309
|
+
// or we're in a legacy browser.
|
|
6310
|
+
|
|
6311
|
+
if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
|
|
6312
|
+
if (hasCustomElements) {
|
|
6313
|
+
// If ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is true, then we eagerly initialize the scoped registry.
|
|
6314
|
+
// It's assumed that ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is set *before* LWC loads, and never changes.
|
|
6315
|
+
//
|
|
6316
|
+
// Why not lazily patch in `createCustomElement`? Well, this could lead to subtle bugs, e.g.:
|
|
6317
|
+
//
|
|
6318
|
+
// 1. LWC loads
|
|
6319
|
+
// 2. `const Ctor = class extends HTMLElement {}`
|
|
6320
|
+
// 3. `lwc.createElement(...)` // here we lazily patch
|
|
6321
|
+
// 4. `customElements.define('x-foo', Ctor)` // throws error because class is bound to stale HTMLElement
|
|
6322
|
+
//
|
|
6323
|
+
// To reduce the risk of this, it's safer to patch the registry eagerly.
|
|
6324
|
+
createScopedConstructor = createScopedRegistry(); // It's important to cache window.HTMLElement here. Otherwise, someone else could overwrite window.HTMLElement (e.g.
|
|
6325
|
+
// another copy of the engine, or another scoping implementation) and we would get "Illegal constructor" errors
|
|
6326
|
+
// because the HTMLElement prototypes are mixed up.
|
|
6327
|
+
//
|
|
6328
|
+
// The reason this happens is that the scoping implementation overwrites window.HTMLElement and expects to work
|
|
6329
|
+
// with that version of HTMLElement. So if you load two copies of the scoping implementation in the same environment,
|
|
6330
|
+
// the second one may accidentally grab window.HTMLElement from the first (when doing `class extends HTMLElement`).
|
|
6331
|
+
// Caching avoids this problem.
|
|
6332
|
+
|
|
6333
|
+
CachedHTMLElement = window.HTMLElement;
|
|
6334
|
+
}
|
|
6335
|
+
} // Creates a constructor that is intended to be used as the UserConstructor in a scoped (pivots) registry.
|
|
6336
|
+
// In this case, the upgradeCallback only needs to be defined once because we create these on-demand,
|
|
6337
|
+
// multiple times per tag name.
|
|
6338
|
+
|
|
6339
|
+
|
|
6340
|
+
const createUserConstructor = (upgradeCallback, connectedCallback, disconnectedCallback, HTMLElementToExtend) => {
|
|
6341
|
+
// TODO [#2972]: this class should expose observedAttributes as necessary
|
|
6342
|
+
return class UserConstructor extends HTMLElementToExtend {
|
|
6343
|
+
constructor() {
|
|
6344
|
+
super();
|
|
6345
|
+
upgradeCallback(this);
|
|
6346
|
+
}
|
|
6347
|
+
|
|
6348
|
+
connectedCallback() {
|
|
6349
|
+
connectedCallback(this);
|
|
6350
|
+
}
|
|
6351
|
+
|
|
6352
|
+
disconnectedCallback() {
|
|
6353
|
+
disconnectedCallback(this);
|
|
6354
|
+
}
|
|
6355
|
+
|
|
6356
|
+
};
|
|
6357
|
+
};
|
|
6358
|
+
|
|
6359
|
+
function createCustomElementScoped(tagName, upgradeCallback, connectedCallback, disconnectedCallback) {
|
|
6360
|
+
if (isUndefined$1(createScopedConstructor) || isUndefined$1(CachedHTMLElement)) {
|
|
6361
|
+
// This error should be impossible to hit
|
|
6362
|
+
throw new Error('The flag ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY must be set to true to use this feature');
|
|
6363
|
+
}
|
|
6364
|
+
|
|
6365
|
+
const UserConstructor = createUserConstructor(upgradeCallback, connectedCallback, disconnectedCallback, CachedHTMLElement);
|
|
6366
|
+
const ScopedConstructor = createScopedConstructor(tagName, UserConstructor);
|
|
6367
|
+
return new ScopedConstructor(UserConstructor);
|
|
6368
|
+
}
|
|
6369
|
+
|
|
6370
|
+
/*
|
|
6371
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
6372
|
+
* All rights reserved.
|
|
6373
|
+
* SPDX-License-Identifier: MIT
|
|
6374
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6375
|
+
*/
|
|
6376
|
+
/**
|
|
6377
|
+
* We have three modes for creating custom elements:
|
|
6378
|
+
*
|
|
6379
|
+
* 1. Compat (legacy) browser support (e.g. IE11). Totally custom, doesn't rely on native browser APIs.
|
|
6380
|
+
* 2. "Vanilla" custom elements registry. This system actually still allows us to have two LWC components with the
|
|
6381
|
+
* same tag name, via a simple trick: every custom element constructor we define in the registry is basically
|
|
6382
|
+
* the same. It's essentially a dummy `class extends HTMLElement` that accepts an `upgradeCallback` in its
|
|
6383
|
+
* constructor, which allows us to have completely customized functionality for different components.
|
|
6384
|
+
* 3. "Scoped" (or "pivot") custom elements. This relies on a sophisticated system that emulates the "scoped custom
|
|
6385
|
+
* elements registry" proposal, with support for avoiding conflicts in tag names both between LWC components and
|
|
6386
|
+
* between LWC components and third-party elements. This uses a similar trick to #2, but is much more complex
|
|
6387
|
+
* because it must patch the global `customElements` and `HTMLElement` objects.
|
|
6388
|
+
*/
|
|
6389
|
+
|
|
6390
|
+
let createCustomElement;
|
|
6391
|
+
|
|
6392
|
+
if (hasCustomElements) {
|
|
6393
|
+
if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
|
|
6394
|
+
createCustomElement = createCustomElementScoped;
|
|
6395
|
+
} else {
|
|
6396
|
+
// use global custom elements registry (vanilla)
|
|
6397
|
+
createCustomElement = createCustomElementVanilla;
|
|
6398
|
+
}
|
|
6399
|
+
} else {
|
|
6400
|
+
// no registry available here
|
|
6401
|
+
createCustomElement = createCustomElementCompat;
|
|
6402
|
+
}
|
|
6403
|
+
|
|
5838
6404
|
/*
|
|
5839
6405
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
5840
6406
|
* All rights reserved.
|
|
@@ -5895,7 +6461,7 @@ var LWC = (function (exports) {
|
|
|
5895
6461
|
function isNull(obj) {
|
|
5896
6462
|
return obj === null;
|
|
5897
6463
|
}
|
|
5898
|
-
/** version: 2.
|
|
6464
|
+
/** version: 2.26.0 */
|
|
5899
6465
|
|
|
5900
6466
|
/*
|
|
5901
6467
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -5903,65 +6469,6 @@ var LWC = (function (exports) {
|
|
|
5903
6469
|
* SPDX-License-Identifier: MIT
|
|
5904
6470
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5905
6471
|
*/
|
|
5906
|
-
exports.getCustomElement = void 0;
|
|
5907
|
-
exports.defineCustomElement = void 0;
|
|
5908
|
-
let HTMLElementConstructor;
|
|
5909
|
-
function isCustomElementRegistryAvailable() {
|
|
5910
|
-
if (typeof customElements === 'undefined') {
|
|
5911
|
-
return false;
|
|
5912
|
-
}
|
|
5913
|
-
try {
|
|
5914
|
-
// dereference HTMLElement global because babel wraps globals in compat mode with a
|
|
5915
|
-
// _wrapNativeSuper()
|
|
5916
|
-
// This is a problem because LWCUpgradableElement extends renderer.HTMLElementExported which does not
|
|
5917
|
-
// get wrapped by babel.
|
|
5918
|
-
const HTMLElementAlias = HTMLElement;
|
|
5919
|
-
// In case we use compat mode with a modern browser, the compat mode transformation
|
|
5920
|
-
// invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
|
|
5921
|
-
// which are not equipped to be initialized that way.
|
|
5922
|
-
class clazz extends HTMLElementAlias {
|
|
5923
|
-
}
|
|
5924
|
-
customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
|
|
5925
|
-
new clazz();
|
|
5926
|
-
return true;
|
|
5927
|
-
}
|
|
5928
|
-
catch (_a) {
|
|
5929
|
-
return false;
|
|
5930
|
-
}
|
|
5931
|
-
}
|
|
5932
|
-
if (isCustomElementRegistryAvailable()) {
|
|
5933
|
-
exports.getCustomElement = customElements.get.bind(customElements);
|
|
5934
|
-
exports.defineCustomElement = customElements.define.bind(customElements);
|
|
5935
|
-
HTMLElementConstructor = HTMLElement;
|
|
5936
|
-
}
|
|
5937
|
-
else {
|
|
5938
|
-
const registry = Object.create(null);
|
|
5939
|
-
const reverseRegistry = new WeakMap();
|
|
5940
|
-
exports.defineCustomElement = function define(name, ctor) {
|
|
5941
|
-
if (name !== String.prototype.toLowerCase.call(name) || registry[name]) {
|
|
5942
|
-
throw new TypeError(`Invalid Registration`);
|
|
5943
|
-
}
|
|
5944
|
-
registry[name] = ctor;
|
|
5945
|
-
reverseRegistry.set(ctor, name);
|
|
5946
|
-
};
|
|
5947
|
-
exports.getCustomElement = function get(name) {
|
|
5948
|
-
return registry[name];
|
|
5949
|
-
};
|
|
5950
|
-
HTMLElementConstructor = function HTMLElement() {
|
|
5951
|
-
if (!(this instanceof HTMLElement)) {
|
|
5952
|
-
throw new TypeError(`Invalid Invocation`);
|
|
5953
|
-
}
|
|
5954
|
-
const { constructor } = this;
|
|
5955
|
-
const name = reverseRegistry.get(constructor);
|
|
5956
|
-
if (!name) {
|
|
5957
|
-
throw new TypeError(`Invalid Construction`);
|
|
5958
|
-
}
|
|
5959
|
-
const elm = document.createElement(name);
|
|
5960
|
-
Object.setPrototypeOf(elm, constructor.prototype);
|
|
5961
|
-
return elm;
|
|
5962
|
-
};
|
|
5963
|
-
HTMLElementConstructor.prototype = HTMLElement.prototype;
|
|
5964
|
-
}
|
|
5965
6472
|
function cloneNode(node, deep) {
|
|
5966
6473
|
return node.cloneNode(deep);
|
|
5967
6474
|
}
|
|
@@ -6135,9 +6642,7 @@ var LWC = (function (exports) {
|
|
|
6135
6642
|
function assertInstanceOfHTMLElement(elm, msg) {
|
|
6136
6643
|
assert.invariant(elm instanceof HTMLElement, msg);
|
|
6137
6644
|
}
|
|
6138
|
-
const HTMLElementExported = HTMLElementConstructor;
|
|
6139
6645
|
|
|
6140
|
-
exports.HTMLElementExported = HTMLElementExported;
|
|
6141
6646
|
exports.addEventListener = addEventListener;
|
|
6142
6647
|
exports.assertInstanceOfHTMLElement = assertInstanceOfHTMLElement;
|
|
6143
6648
|
exports.attachShadow = attachShadow;
|
|
@@ -6197,6 +6702,8 @@ var LWC = (function (exports) {
|
|
|
6197
6702
|
{
|
|
6198
6703
|
// insertStyleSheet implementation shares a global cache of stylesheet data
|
|
6199
6704
|
insertStylesheet,
|
|
6705
|
+
// relies on a shared global cache
|
|
6706
|
+
createCustomElement,
|
|
6200
6707
|
isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
|
|
6201
6708
|
isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
|
|
6202
6709
|
});
|
|
@@ -6292,36 +6799,44 @@ var LWC = (function (exports) {
|
|
|
6292
6799
|
// This WeakSet usage is valid because this functionality is not meant to run in IE11.
|
|
6293
6800
|
const hydratedCustomElements = new WeakSet();
|
|
6294
6801
|
function buildCustomElementConstructor(Ctor) {
|
|
6802
|
+
var _a;
|
|
6295
6803
|
const HtmlPrototype = getComponentHtmlPrototype(Ctor);
|
|
6296
|
-
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
|
-
|
|
6300
|
-
|
|
6301
|
-
|
|
6302
|
-
|
|
6804
|
+
const { observedAttributes } = HtmlPrototype;
|
|
6805
|
+
const { attributeChangedCallback } = HtmlPrototype.prototype;
|
|
6806
|
+
return _a = class extends HTMLElement {
|
|
6807
|
+
constructor() {
|
|
6808
|
+
super();
|
|
6809
|
+
if (this.isConnected) {
|
|
6810
|
+
// this if block is hit when there's already an un-upgraded element in the DOM with the same tag name.
|
|
6811
|
+
hydrateComponent(this, Ctor, {});
|
|
6812
|
+
hydratedCustomElements.add(this);
|
|
6813
|
+
}
|
|
6814
|
+
else {
|
|
6815
|
+
createVM(this, Ctor, renderer, {
|
|
6816
|
+
mode: 'open',
|
|
6817
|
+
owner: null,
|
|
6818
|
+
tagName: this.tagName,
|
|
6819
|
+
});
|
|
6820
|
+
}
|
|
6303
6821
|
}
|
|
6304
|
-
|
|
6305
|
-
|
|
6306
|
-
|
|
6307
|
-
|
|
6308
|
-
|
|
6309
|
-
|
|
6822
|
+
connectedCallback() {
|
|
6823
|
+
if (hydratedCustomElements.has(this)) {
|
|
6824
|
+
// This is an un-upgraded element that was hydrated in the constructor.
|
|
6825
|
+
hydratedCustomElements.delete(this);
|
|
6826
|
+
}
|
|
6827
|
+
else {
|
|
6828
|
+
connectRootElement(this);
|
|
6829
|
+
}
|
|
6310
6830
|
}
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
if (hydratedCustomElements.has(this)) {
|
|
6314
|
-
// This is an un-upgraded element that was hydrated in the constructor.
|
|
6315
|
-
hydratedCustomElements.delete(this);
|
|
6831
|
+
disconnectedCallback() {
|
|
6832
|
+
disconnectRootElement(this);
|
|
6316
6833
|
}
|
|
6317
|
-
|
|
6318
|
-
|
|
6834
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
6835
|
+
attributeChangedCallback.call(this, name, oldValue, newValue);
|
|
6319
6836
|
}
|
|
6320
|
-
}
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
}
|
|
6324
|
-
};
|
|
6837
|
+
},
|
|
6838
|
+
_a.observedAttributes = observedAttributes,
|
|
6839
|
+
_a;
|
|
6325
6840
|
}
|
|
6326
6841
|
|
|
6327
6842
|
/*
|
|
@@ -6405,8 +6920,13 @@ var LWC = (function (exports) {
|
|
|
6405
6920
|
throw new TypeError(`"createElement" function expects an "is" option with a valid component constructor.`);
|
|
6406
6921
|
}
|
|
6407
6922
|
|
|
6408
|
-
const
|
|
6409
|
-
|
|
6923
|
+
const {
|
|
6924
|
+
createCustomElement
|
|
6925
|
+
} = renderer; // tagName must be all lowercase, unfortunately, we have legacy code that is
|
|
6926
|
+
// passing `sel` as a camel-case, which makes them invalid custom elements name
|
|
6927
|
+
// the following line guarantees that this does not leaks beyond this point.
|
|
6928
|
+
|
|
6929
|
+
const tagName = StringToLowerCase.call(sel); // the custom element from the registry is expecting an upgrade callback
|
|
6410
6930
|
|
|
6411
6931
|
/**
|
|
6412
6932
|
* Note: if the upgradable constructor does not expect, or throw when we new it
|
|
@@ -6415,9 +6935,9 @@ var LWC = (function (exports) {
|
|
|
6415
6935
|
* an upgradable custom element.
|
|
6416
6936
|
*/
|
|
6417
6937
|
|
|
6418
|
-
const
|
|
6938
|
+
const upgradeCallback = elm => {
|
|
6419
6939
|
createVM(elm, Ctor, renderer, {
|
|
6420
|
-
tagName
|
|
6940
|
+
tagName,
|
|
6421
6941
|
mode: options.mode !== 'closed' ? 'open' : 'closed',
|
|
6422
6942
|
owner: null
|
|
6423
6943
|
});
|
|
@@ -6426,15 +6946,21 @@ var LWC = (function (exports) {
|
|
|
6426
6946
|
ConnectingSlot.set(elm, connectRootElement);
|
|
6427
6947
|
DisconnectingSlot.set(elm, disconnectRootElement);
|
|
6428
6948
|
}
|
|
6949
|
+
};
|
|
6429
6950
|
|
|
6430
|
-
|
|
6431
|
-
|
|
6951
|
+
const connectedCallback = elm => {
|
|
6952
|
+
if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
|
|
6953
|
+
connectRootElement(elm);
|
|
6954
|
+
}
|
|
6955
|
+
};
|
|
6432
6956
|
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6436
|
-
|
|
6957
|
+
const disconnectedCallback = elm => {
|
|
6958
|
+
if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
|
|
6959
|
+
disconnectRootElement(elm);
|
|
6960
|
+
}
|
|
6961
|
+
};
|
|
6437
6962
|
|
|
6963
|
+
const element = createCustomElement(tagName, upgradeCallback, connectedCallback, disconnectedCallback);
|
|
6438
6964
|
return element;
|
|
6439
6965
|
}
|
|
6440
6966
|
|
|
@@ -6506,7 +7032,7 @@ var LWC = (function (exports) {
|
|
|
6506
7032
|
});
|
|
6507
7033
|
freeze(LightningElement);
|
|
6508
7034
|
seal(LightningElement.prototype);
|
|
6509
|
-
/* version: 2.
|
|
7035
|
+
/* version: 2.26.0 */
|
|
6510
7036
|
|
|
6511
7037
|
exports.LightningElement = LightningElement;
|
|
6512
7038
|
exports.__unstable__ProfilerControl = profilerControl;
|