lwc 2.25.0 → 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 +1103 -533
- package/dist/engine-dom/iife/es2017/engine-dom.js +1103 -533
- package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
- package/dist/engine-dom/iife/es2017/engine-dom_debug.js +942 -320
- package/dist/engine-dom/iife/es5/engine-dom.js +966 -312
- package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
- package/dist/engine-dom/iife/es5/engine-dom_debug.js +895 -225
- package/dist/engine-dom/umd/es2017/engine-dom.js +1103 -533
- package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
- package/dist/engine-dom/umd/es2017/engine-dom_debug.js +942 -320
- package/dist/engine-dom/umd/es5/engine-dom.js +966 -312
- package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
- package/dist/engine-dom/umd/es5/engine-dom_debug.js +895 -225
- package/dist/engine-server/commonjs/es2017/engine-server.js +331 -339
- package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
- package/dist/engine-server/esm/es2017/engine-server.js +331 -339
- 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,
|
|
@@ -399,6 +398,8 @@ var LWC = (function (exports) {
|
|
|
399
398
|
ENABLE_REACTIVE_SETTER: null,
|
|
400
399
|
ENABLE_WIRE_SYNC_EMIT: null,
|
|
401
400
|
ENABLE_LIGHT_GET_ROOT_NODE_PATCH: null,
|
|
401
|
+
DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
|
|
402
|
+
ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
|
|
402
403
|
};
|
|
403
404
|
if (!_globalThis.lwcRuntimeFlags) {
|
|
404
405
|
Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
|
|
@@ -1383,7 +1384,9 @@ var LWC = (function (exports) {
|
|
|
1383
1384
|
const LightningElement = function () {
|
|
1384
1385
|
// This should be as performant as possible, while any initialization should be done lazily
|
|
1385
1386
|
if (isNull(vmBeingConstructed)) {
|
|
1386
|
-
|
|
1387
|
+
// Thrown when doing something like `new LightningElement()` or
|
|
1388
|
+
// `class Foo extends LightningElement {}; new Foo()`
|
|
1389
|
+
throw new TypeError('Illegal constructor');
|
|
1387
1390
|
}
|
|
1388
1391
|
const vm = vmBeingConstructed;
|
|
1389
1392
|
const { def, elm } = vm;
|
|
@@ -2163,34 +2166,19 @@ var LWC = (function (exports) {
|
|
|
2163
2166
|
freeze(BaseBridgeElement);
|
|
2164
2167
|
seal(BaseBridgeElement.prototype);
|
|
2165
2168
|
function setActiveVM(vm) {
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2169
|
+
{
|
|
2170
|
+
// this method should never leak to prod
|
|
2171
|
+
throw new ReferenceError();
|
|
2172
|
+
}
|
|
2170
2173
|
}
|
|
2171
2174
|
function swapTemplate(oldTpl, newTpl) {
|
|
2172
|
-
|
|
2173
|
-
if (!lwcRuntimeFlags.ENABLE_HMR) {
|
|
2174
|
-
throw new Error('HMR is not enabled');
|
|
2175
|
-
}
|
|
2176
|
-
|
|
2177
|
-
return false;
|
|
2175
|
+
return false;
|
|
2178
2176
|
}
|
|
2179
2177
|
function swapComponent(oldComponent, newComponent) {
|
|
2180
|
-
|
|
2181
|
-
if (!lwcRuntimeFlags.ENABLE_HMR) {
|
|
2182
|
-
throw new Error('HMR is not enabled');
|
|
2183
|
-
}
|
|
2184
|
-
|
|
2185
|
-
return false;
|
|
2178
|
+
return false;
|
|
2186
2179
|
}
|
|
2187
2180
|
function swapStyle(oldStyle, newStyle) {
|
|
2188
|
-
|
|
2189
|
-
if (!lwcRuntimeFlags.ENABLE_HMR) {
|
|
2190
|
-
throw new Error('HMR is not enabled');
|
|
2191
|
-
}
|
|
2192
|
-
|
|
2193
|
-
return false;
|
|
2181
|
+
return false;
|
|
2194
2182
|
}
|
|
2195
2183
|
|
|
2196
2184
|
/*
|
|
@@ -2373,230 +2361,265 @@ var LWC = (function (exports) {
|
|
|
2373
2361
|
* SPDX-License-Identifier: MIT
|
|
2374
2362
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2375
2363
|
*/
|
|
2364
|
+
|
|
2376
2365
|
function makeHostToken(token) {
|
|
2377
|
-
|
|
2366
|
+
return `${token}-host`;
|
|
2378
2367
|
}
|
|
2368
|
+
|
|
2379
2369
|
function createInlineStyleVNode(content) {
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2370
|
+
return api.h('style', {
|
|
2371
|
+
key: 'style',
|
|
2372
|
+
attrs: {
|
|
2373
|
+
type: 'text/css'
|
|
2374
|
+
}
|
|
2375
|
+
}, [api.t(content)]);
|
|
2386
2376
|
}
|
|
2377
|
+
|
|
2387
2378
|
function updateStylesheetToken(vm, template) {
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2379
|
+
const {
|
|
2380
|
+
elm,
|
|
2381
|
+
context,
|
|
2382
|
+
renderMode,
|
|
2383
|
+
shadowMode,
|
|
2384
|
+
renderer: {
|
|
2385
|
+
getClassList,
|
|
2386
|
+
removeAttribute,
|
|
2387
|
+
setAttribute
|
|
2388
|
+
}
|
|
2389
|
+
} = vm;
|
|
2390
|
+
const {
|
|
2391
|
+
stylesheets: newStylesheets,
|
|
2392
|
+
stylesheetToken: newStylesheetToken
|
|
2393
|
+
} = template;
|
|
2394
|
+
const isSyntheticShadow = renderMode === 1
|
|
2395
|
+
/* RenderMode.Shadow */
|
|
2396
|
+
&& shadowMode === 1
|
|
2397
|
+
/* ShadowMode.Synthetic */
|
|
2398
|
+
;
|
|
2399
|
+
const {
|
|
2400
|
+
hasScopedStyles
|
|
2401
|
+
} = context;
|
|
2402
|
+
let newToken;
|
|
2403
|
+
let newHasTokenInClass;
|
|
2404
|
+
let newHasTokenInAttribute; // Reset the styling token applied to the host element.
|
|
2405
|
+
|
|
2406
|
+
const {
|
|
2407
|
+
stylesheetToken: oldToken,
|
|
2408
|
+
hasTokenInClass: oldHasTokenInClass,
|
|
2409
|
+
hasTokenInAttribute: oldHasTokenInAttribute
|
|
2410
|
+
} = context;
|
|
2411
|
+
|
|
2412
|
+
if (!isUndefined$1(oldToken)) {
|
|
2413
|
+
if (oldHasTokenInClass) {
|
|
2414
|
+
getClassList(elm).remove(makeHostToken(oldToken));
|
|
2415
|
+
}
|
|
2416
|
+
|
|
2417
|
+
if (oldHasTokenInAttribute) {
|
|
2418
|
+
removeAttribute(elm, makeHostToken(oldToken));
|
|
2419
|
+
}
|
|
2420
|
+
} // Apply the new template styling token to the host element, if the new template has any
|
|
2421
|
+
// associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
|
|
2422
|
+
|
|
2423
|
+
|
|
2424
|
+
if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
|
|
2425
|
+
newToken = newStylesheetToken;
|
|
2426
|
+
} // Set the new styling token on the host element
|
|
2427
|
+
|
|
2428
|
+
|
|
2429
|
+
if (!isUndefined$1(newToken)) {
|
|
2430
|
+
if (hasScopedStyles) {
|
|
2431
|
+
getClassList(elm).add(makeHostToken(newToken));
|
|
2432
|
+
newHasTokenInClass = true;
|
|
2433
|
+
}
|
|
2434
|
+
|
|
2435
|
+
if (isSyntheticShadow) {
|
|
2436
|
+
setAttribute(elm, makeHostToken(newToken), '');
|
|
2437
|
+
newHasTokenInAttribute = true;
|
|
2438
|
+
}
|
|
2439
|
+
} // Update the styling tokens present on the context object.
|
|
2440
|
+
|
|
2441
|
+
|
|
2442
|
+
context.stylesheetToken = newToken;
|
|
2443
|
+
context.hasTokenInClass = newHasTokenInClass;
|
|
2444
|
+
context.hasTokenInAttribute = newHasTokenInAttribute;
|
|
2425
2445
|
}
|
|
2446
|
+
|
|
2426
2447
|
function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2448
|
+
const content = [];
|
|
2449
|
+
let root;
|
|
2450
|
+
|
|
2451
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
2452
|
+
let stylesheet = stylesheets[i];
|
|
2453
|
+
|
|
2454
|
+
if (isArray$1(stylesheet)) {
|
|
2455
|
+
ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
|
|
2456
|
+
} else {
|
|
2457
|
+
|
|
2458
|
+
const isScopedCss = stylesheet[KEY__SCOPED_CSS];
|
|
2459
|
+
|
|
2460
|
+
if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS) {
|
|
2461
|
+
if (!isScopedCss && vm.renderMode === 0
|
|
2462
|
+
/* RenderMode.Light */
|
|
2463
|
+
) {
|
|
2464
|
+
logError('Unscoped CSS is not supported in Light DOM. Please use scoped CSS (*.scoped.css) instead of unscoped CSS (*.css).');
|
|
2465
|
+
continue;
|
|
2433
2466
|
}
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2467
|
+
} // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
|
|
2468
|
+
|
|
2469
|
+
|
|
2470
|
+
const scopeToken = isScopedCss || vm.shadowMode === 1
|
|
2471
|
+
/* ShadowMode.Synthetic */
|
|
2472
|
+
&& vm.renderMode === 1
|
|
2473
|
+
/* RenderMode.Shadow */
|
|
2474
|
+
? stylesheetToken : undefined; // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
|
|
2475
|
+
// native shadow DOM. Synthetic shadow DOM never uses `:host`.
|
|
2476
|
+
|
|
2477
|
+
const useActualHostSelector = vm.renderMode === 0
|
|
2478
|
+
/* RenderMode.Light */
|
|
2479
|
+
? !isScopedCss : vm.shadowMode === 0
|
|
2480
|
+
/* ShadowMode.Native */
|
|
2481
|
+
; // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
|
|
2482
|
+
// we use an attribute selector on the host to simulate :dir().
|
|
2483
|
+
|
|
2484
|
+
let useNativeDirPseudoclass;
|
|
2485
|
+
|
|
2486
|
+
if (vm.renderMode === 1
|
|
2487
|
+
/* RenderMode.Shadow */
|
|
2488
|
+
) {
|
|
2489
|
+
useNativeDirPseudoclass = vm.shadowMode === 0
|
|
2490
|
+
/* ShadowMode.Native */
|
|
2491
|
+
;
|
|
2492
|
+
} else {
|
|
2493
|
+
// Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
|
|
2494
|
+
// At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
|
|
2495
|
+
if (isUndefined$1(root)) {
|
|
2496
|
+
// Only calculate the root once as necessary
|
|
2497
|
+
root = getNearestShadowComponent(vm);
|
|
2462
2498
|
}
|
|
2499
|
+
|
|
2500
|
+
useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0
|
|
2501
|
+
/* ShadowMode.Native */
|
|
2502
|
+
;
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
|
|
2463
2506
|
}
|
|
2464
|
-
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
return content;
|
|
2465
2510
|
}
|
|
2511
|
+
|
|
2466
2512
|
function getStylesheetsContent(vm, template) {
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2513
|
+
const {
|
|
2514
|
+
stylesheets,
|
|
2515
|
+
stylesheetToken
|
|
2516
|
+
} = template;
|
|
2517
|
+
let content = [];
|
|
2518
|
+
|
|
2519
|
+
if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
|
|
2520
|
+
content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
return content;
|
|
2524
|
+
} // It might be worth caching this to avoid doing the lookup repeatedly, but
|
|
2475
2525
|
// perf testing has not shown it to be a huge improvement yet:
|
|
2476
2526
|
// https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
|
|
2527
|
+
|
|
2477
2528
|
function getNearestShadowComponent(vm) {
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2529
|
+
let owner = vm;
|
|
2530
|
+
|
|
2531
|
+
while (!isNull(owner)) {
|
|
2532
|
+
if (owner.renderMode === 1
|
|
2533
|
+
/* RenderMode.Shadow */
|
|
2534
|
+
) {
|
|
2535
|
+
return owner;
|
|
2484
2536
|
}
|
|
2485
|
-
|
|
2537
|
+
|
|
2538
|
+
owner = owner.owner;
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2541
|
+
return owner;
|
|
2486
2542
|
}
|
|
2487
2543
|
/**
|
|
2488
2544
|
* If the component that is currently being rendered uses scoped styles,
|
|
2489
2545
|
* this returns the unique token for that scoped stylesheet. Otherwise
|
|
2490
2546
|
* it returns null.
|
|
2491
2547
|
*/
|
|
2548
|
+
|
|
2549
|
+
|
|
2492
2550
|
function getScopeTokenClass(owner) {
|
|
2493
|
-
|
|
2494
|
-
|
|
2551
|
+
const {
|
|
2552
|
+
cmpTemplate,
|
|
2553
|
+
context
|
|
2554
|
+
} = owner;
|
|
2555
|
+
return context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken) || null;
|
|
2495
2556
|
}
|
|
2496
2557
|
/**
|
|
2497
2558
|
* This function returns the host style token for a custom element if it
|
|
2498
2559
|
* exists. Otherwise it returns null.
|
|
2560
|
+
*
|
|
2561
|
+
* A host style token is applied to the component if scoped styles are used.
|
|
2499
2562
|
*/
|
|
2563
|
+
|
|
2500
2564
|
function getStylesheetTokenHost(vnode) {
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
// synthetic, we know we won't find a native component if we go any further.
|
|
2509
|
-
return null;
|
|
2510
|
-
}
|
|
2511
|
-
return owner;
|
|
2512
|
-
}
|
|
2513
|
-
function createStylesheet(vm, stylesheets) {
|
|
2514
|
-
const { renderMode, shadowMode, renderer: { insertStylesheet }, } = vm;
|
|
2515
|
-
if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
|
|
2516
|
-
for (let i = 0; i < stylesheets.length; i++) {
|
|
2517
|
-
insertStylesheet(stylesheets[i]);
|
|
2518
|
-
}
|
|
2519
|
-
}
|
|
2520
|
-
else if (vm.hydrated) {
|
|
2521
|
-
// Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
|
|
2522
|
-
// This works in the client, because the stylesheets are created, and cached in the VM
|
|
2523
|
-
// the first time the VM renders.
|
|
2524
|
-
// native shadow or light DOM, SSR
|
|
2525
|
-
return ArrayMap.call(stylesheets, createInlineStyleVNode);
|
|
2526
|
-
}
|
|
2527
|
-
else {
|
|
2528
|
-
// native shadow or light DOM, DOM renderer
|
|
2529
|
-
const root = getNearestNativeShadowComponent(vm);
|
|
2530
|
-
// null root means a global style
|
|
2531
|
-
const target = isNull(root) ? undefined : root.shadowRoot;
|
|
2532
|
-
for (let i = 0; i < stylesheets.length; i++) {
|
|
2533
|
-
insertStylesheet(stylesheets[i], target);
|
|
2534
|
-
}
|
|
2535
|
-
}
|
|
2536
|
-
return null;
|
|
2565
|
+
const {
|
|
2566
|
+
template
|
|
2567
|
+
} = getComponentInternalDef(vnode.ctor);
|
|
2568
|
+
const {
|
|
2569
|
+
stylesheetToken
|
|
2570
|
+
} = template;
|
|
2571
|
+
return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
|
|
2537
2572
|
}
|
|
2538
2573
|
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
* All rights reserved.
|
|
2542
|
-
* SPDX-License-Identifier: MIT
|
|
2543
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2544
|
-
*/
|
|
2574
|
+
function getNearestNativeShadowComponent(vm) {
|
|
2575
|
+
const owner = getNearestShadowComponent(vm);
|
|
2545
2576
|
|
|
2546
|
-
|
|
2547
|
-
|
|
2577
|
+
if (!isNull(owner) && owner.shadowMode === 1
|
|
2578
|
+
/* ShadowMode.Synthetic */
|
|
2579
|
+
) {
|
|
2580
|
+
// Synthetic-within-native is impossible. So if the nearest shadow component is
|
|
2581
|
+
// synthetic, we know we won't find a native component if we go any further.
|
|
2582
|
+
return null;
|
|
2583
|
+
}
|
|
2548
2584
|
|
|
2549
|
-
return
|
|
2585
|
+
return owner;
|
|
2550
2586
|
}
|
|
2551
2587
|
|
|
2552
|
-
function
|
|
2588
|
+
function createStylesheet(vm, stylesheets) {
|
|
2553
2589
|
const {
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
// produce only tags with lowercase letters
|
|
2559
|
-
// But, for backwards compatibility, we will lower case the tagName
|
|
2560
|
-
|
|
2561
|
-
tagName = tagName.toLowerCase();
|
|
2562
|
-
let CE = getCustomElement(tagName);
|
|
2563
|
-
|
|
2564
|
-
if (!isUndefined$1(CE)) {
|
|
2565
|
-
return CE;
|
|
2566
|
-
}
|
|
2567
|
-
/**
|
|
2568
|
-
* LWC Upgradable Element reference to an element that was created
|
|
2569
|
-
* via the scoped registry mechanism, and that is ready to be upgraded.
|
|
2570
|
-
*/
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
CE = class LWCUpgradableElement extends RendererHTMLElement {
|
|
2574
|
-
constructor(upgradeCallback) {
|
|
2575
|
-
super();
|
|
2576
|
-
|
|
2577
|
-
if (isFunction$1(upgradeCallback)) {
|
|
2578
|
-
upgradeCallback(this); // nothing to do with the result for now
|
|
2579
|
-
}
|
|
2590
|
+
renderMode,
|
|
2591
|
+
shadowMode,
|
|
2592
|
+
renderer: {
|
|
2593
|
+
insertStylesheet
|
|
2580
2594
|
}
|
|
2595
|
+
} = vm;
|
|
2581
2596
|
|
|
2582
|
-
|
|
2597
|
+
if (renderMode === 1
|
|
2598
|
+
/* RenderMode.Shadow */
|
|
2599
|
+
&& shadowMode === 1
|
|
2600
|
+
/* ShadowMode.Synthetic */
|
|
2601
|
+
) {
|
|
2602
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
2603
|
+
insertStylesheet(stylesheets[i]);
|
|
2604
|
+
}
|
|
2605
|
+
} else if (vm.hydrated) {
|
|
2606
|
+
// Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
|
|
2607
|
+
// This works in the client, because the stylesheets are created, and cached in the VM
|
|
2608
|
+
// the first time the VM renders.
|
|
2609
|
+
// native shadow or light DOM, SSR
|
|
2610
|
+
return ArrayMap.call(stylesheets, createInlineStyleVNode);
|
|
2611
|
+
} else {
|
|
2612
|
+
// native shadow or light DOM, DOM renderer
|
|
2613
|
+
const root = getNearestNativeShadowComponent(vm); // null root means a global style
|
|
2583
2614
|
|
|
2584
|
-
|
|
2585
|
-
CE.prototype.connectedCallback = function () {
|
|
2586
|
-
if (checkHasVM(this)) {
|
|
2587
|
-
connectRootElement(this);
|
|
2588
|
-
}
|
|
2589
|
-
};
|
|
2615
|
+
const target = isNull(root) ? undefined : root.shadowRoot;
|
|
2590
2616
|
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
}
|
|
2595
|
-
};
|
|
2617
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
2618
|
+
insertStylesheet(stylesheets[i], target);
|
|
2619
|
+
}
|
|
2596
2620
|
}
|
|
2597
2621
|
|
|
2598
|
-
|
|
2599
|
-
return CE;
|
|
2622
|
+
return null;
|
|
2600
2623
|
}
|
|
2601
2624
|
|
|
2602
2625
|
/*
|
|
@@ -3086,7 +3109,9 @@ var LWC = (function (exports) {
|
|
|
3086
3109
|
sel,
|
|
3087
3110
|
owner
|
|
3088
3111
|
} = vnode;
|
|
3089
|
-
const
|
|
3112
|
+
const {
|
|
3113
|
+
createCustomElement
|
|
3114
|
+
} = renderer;
|
|
3090
3115
|
/**
|
|
3091
3116
|
* Note: if the upgradable constructor does not expect, or throw when we new it
|
|
3092
3117
|
* with a callback as the first argument, we could implement a more advanced
|
|
@@ -3095,10 +3120,25 @@ var LWC = (function (exports) {
|
|
|
3095
3120
|
*/
|
|
3096
3121
|
|
|
3097
3122
|
let vm;
|
|
3098
|
-
|
|
3123
|
+
|
|
3124
|
+
const upgradeCallback = elm => {
|
|
3099
3125
|
// the custom element from the registry is expecting an upgrade callback
|
|
3100
3126
|
vm = createViewModelHook(elm, vnode, renderer);
|
|
3101
|
-
}
|
|
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);
|
|
3102
3142
|
vnode.elm = elm;
|
|
3103
3143
|
vnode.vm = vm;
|
|
3104
3144
|
linkNodeToShadow(elm, owner, renderer);
|
|
@@ -3106,8 +3146,6 @@ var LWC = (function (exports) {
|
|
|
3106
3146
|
|
|
3107
3147
|
if (vm) {
|
|
3108
3148
|
allocateChildren(vnode, vm);
|
|
3109
|
-
} else if (vnode.ctor !== UpgradableConstructor) {
|
|
3110
|
-
throw new TypeError(`Incorrect Component Constructor`);
|
|
3111
3149
|
}
|
|
3112
3150
|
|
|
3113
3151
|
patchElementPropsAndAttrs$1(null, vnode, renderer);
|
|
@@ -5463,19 +5501,23 @@ var LWC = (function (exports) {
|
|
|
5463
5501
|
//
|
|
5464
5502
|
// Consequently, hydration mismatches will occur if scoped CSS token classnames
|
|
5465
5503
|
// are rendered during SSR. This needs to be accounted for when validating.
|
|
5466
|
-
if (scopedToken) {
|
|
5504
|
+
if (!isNull(scopedToken) || !isNull(stylesheetTokenHost)) {
|
|
5467
5505
|
if (!isUndefined$1(className)) {
|
|
5468
|
-
className
|
|
5469
|
-
|
|
5470
|
-
|
|
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, ' ');
|
|
5471
5510
|
}
|
|
5472
5511
|
else if (!isUndefined$1(classMap)) {
|
|
5473
|
-
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 } : {}));
|
|
5474
5513
|
}
|
|
5475
5514
|
else {
|
|
5476
|
-
className
|
|
5477
|
-
|
|
5478
|
-
|
|
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
|
+
}
|
|
5479
5521
|
}
|
|
5480
5522
|
}
|
|
5481
5523
|
let nodesAreCompatible = true;
|
|
@@ -5604,7 +5646,7 @@ var LWC = (function (exports) {
|
|
|
5604
5646
|
}
|
|
5605
5647
|
return ctor;
|
|
5606
5648
|
}
|
|
5607
|
-
/* version: 2.
|
|
5649
|
+
/* version: 2.26.0 */
|
|
5608
5650
|
|
|
5609
5651
|
/*
|
|
5610
5652
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -5739,6 +5781,626 @@ var LWC = (function (exports) {
|
|
|
5739
5781
|
}
|
|
5740
5782
|
}
|
|
5741
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
|
+
|
|
5742
6404
|
/*
|
|
5743
6405
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
5744
6406
|
* All rights reserved.
|
|
@@ -5799,7 +6461,7 @@ var LWC = (function (exports) {
|
|
|
5799
6461
|
function isNull(obj) {
|
|
5800
6462
|
return obj === null;
|
|
5801
6463
|
}
|
|
5802
|
-
/** version: 2.
|
|
6464
|
+
/** version: 2.26.0 */
|
|
5803
6465
|
|
|
5804
6466
|
/*
|
|
5805
6467
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -5807,65 +6469,6 @@ var LWC = (function (exports) {
|
|
|
5807
6469
|
* SPDX-License-Identifier: MIT
|
|
5808
6470
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5809
6471
|
*/
|
|
5810
|
-
exports.getCustomElement = void 0;
|
|
5811
|
-
exports.defineCustomElement = void 0;
|
|
5812
|
-
let HTMLElementConstructor;
|
|
5813
|
-
function isCustomElementRegistryAvailable() {
|
|
5814
|
-
if (typeof customElements === 'undefined') {
|
|
5815
|
-
return false;
|
|
5816
|
-
}
|
|
5817
|
-
try {
|
|
5818
|
-
// dereference HTMLElement global because babel wraps globals in compat mode with a
|
|
5819
|
-
// _wrapNativeSuper()
|
|
5820
|
-
// This is a problem because LWCUpgradableElement extends renderer.HTMLElementExported which does not
|
|
5821
|
-
// get wrapped by babel.
|
|
5822
|
-
const HTMLElementAlias = HTMLElement;
|
|
5823
|
-
// In case we use compat mode with a modern browser, the compat mode transformation
|
|
5824
|
-
// invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
|
|
5825
|
-
// which are not equipped to be initialized that way.
|
|
5826
|
-
class clazz extends HTMLElementAlias {
|
|
5827
|
-
}
|
|
5828
|
-
customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
|
|
5829
|
-
new clazz();
|
|
5830
|
-
return true;
|
|
5831
|
-
}
|
|
5832
|
-
catch (_a) {
|
|
5833
|
-
return false;
|
|
5834
|
-
}
|
|
5835
|
-
}
|
|
5836
|
-
if (isCustomElementRegistryAvailable()) {
|
|
5837
|
-
exports.getCustomElement = customElements.get.bind(customElements);
|
|
5838
|
-
exports.defineCustomElement = customElements.define.bind(customElements);
|
|
5839
|
-
HTMLElementConstructor = HTMLElement;
|
|
5840
|
-
}
|
|
5841
|
-
else {
|
|
5842
|
-
const registry = Object.create(null);
|
|
5843
|
-
const reverseRegistry = new WeakMap();
|
|
5844
|
-
exports.defineCustomElement = function define(name, ctor) {
|
|
5845
|
-
if (name !== String.prototype.toLowerCase.call(name) || registry[name]) {
|
|
5846
|
-
throw new TypeError(`Invalid Registration`);
|
|
5847
|
-
}
|
|
5848
|
-
registry[name] = ctor;
|
|
5849
|
-
reverseRegistry.set(ctor, name);
|
|
5850
|
-
};
|
|
5851
|
-
exports.getCustomElement = function get(name) {
|
|
5852
|
-
return registry[name];
|
|
5853
|
-
};
|
|
5854
|
-
HTMLElementConstructor = function HTMLElement() {
|
|
5855
|
-
if (!(this instanceof HTMLElement)) {
|
|
5856
|
-
throw new TypeError(`Invalid Invocation`);
|
|
5857
|
-
}
|
|
5858
|
-
const { constructor } = this;
|
|
5859
|
-
const name = reverseRegistry.get(constructor);
|
|
5860
|
-
if (!name) {
|
|
5861
|
-
throw new TypeError(`Invalid Construction`);
|
|
5862
|
-
}
|
|
5863
|
-
const elm = document.createElement(name);
|
|
5864
|
-
Object.setPrototypeOf(elm, constructor.prototype);
|
|
5865
|
-
return elm;
|
|
5866
|
-
};
|
|
5867
|
-
HTMLElementConstructor.prototype = HTMLElement.prototype;
|
|
5868
|
-
}
|
|
5869
6472
|
function cloneNode(node, deep) {
|
|
5870
6473
|
return node.cloneNode(deep);
|
|
5871
6474
|
}
|
|
@@ -6039,9 +6642,7 @@ var LWC = (function (exports) {
|
|
|
6039
6642
|
function assertInstanceOfHTMLElement(elm, msg) {
|
|
6040
6643
|
assert.invariant(elm instanceof HTMLElement, msg);
|
|
6041
6644
|
}
|
|
6042
|
-
const HTMLElementExported = HTMLElementConstructor;
|
|
6043
6645
|
|
|
6044
|
-
exports.HTMLElementExported = HTMLElementExported;
|
|
6045
6646
|
exports.addEventListener = addEventListener;
|
|
6046
6647
|
exports.assertInstanceOfHTMLElement = assertInstanceOfHTMLElement;
|
|
6047
6648
|
exports.attachShadow = attachShadow;
|
|
@@ -6101,6 +6702,8 @@ var LWC = (function (exports) {
|
|
|
6101
6702
|
{
|
|
6102
6703
|
// insertStyleSheet implementation shares a global cache of stylesheet data
|
|
6103
6704
|
insertStylesheet,
|
|
6705
|
+
// relies on a shared global cache
|
|
6706
|
+
createCustomElement,
|
|
6104
6707
|
isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
|
|
6105
6708
|
isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
|
|
6106
6709
|
});
|
|
@@ -6196,36 +6799,44 @@ var LWC = (function (exports) {
|
|
|
6196
6799
|
// This WeakSet usage is valid because this functionality is not meant to run in IE11.
|
|
6197
6800
|
const hydratedCustomElements = new WeakSet();
|
|
6198
6801
|
function buildCustomElementConstructor(Ctor) {
|
|
6802
|
+
var _a;
|
|
6199
6803
|
const HtmlPrototype = getComponentHtmlPrototype(Ctor);
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
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
|
+
}
|
|
6207
6821
|
}
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
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
|
+
}
|
|
6214
6830
|
}
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
if (hydratedCustomElements.has(this)) {
|
|
6218
|
-
// This is an un-upgraded element that was hydrated in the constructor.
|
|
6219
|
-
hydratedCustomElements.delete(this);
|
|
6831
|
+
disconnectedCallback() {
|
|
6832
|
+
disconnectRootElement(this);
|
|
6220
6833
|
}
|
|
6221
|
-
|
|
6222
|
-
|
|
6834
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
6835
|
+
attributeChangedCallback.call(this, name, oldValue, newValue);
|
|
6223
6836
|
}
|
|
6224
|
-
}
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
}
|
|
6228
|
-
};
|
|
6837
|
+
},
|
|
6838
|
+
_a.observedAttributes = observedAttributes,
|
|
6839
|
+
_a;
|
|
6229
6840
|
}
|
|
6230
6841
|
|
|
6231
6842
|
/*
|
|
@@ -6309,8 +6920,13 @@ var LWC = (function (exports) {
|
|
|
6309
6920
|
throw new TypeError(`"createElement" function expects an "is" option with a valid component constructor.`);
|
|
6310
6921
|
}
|
|
6311
6922
|
|
|
6312
|
-
const
|
|
6313
|
-
|
|
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
|
|
6314
6930
|
|
|
6315
6931
|
/**
|
|
6316
6932
|
* Note: if the upgradable constructor does not expect, or throw when we new it
|
|
@@ -6319,9 +6935,9 @@ var LWC = (function (exports) {
|
|
|
6319
6935
|
* an upgradable custom element.
|
|
6320
6936
|
*/
|
|
6321
6937
|
|
|
6322
|
-
const
|
|
6938
|
+
const upgradeCallback = elm => {
|
|
6323
6939
|
createVM(elm, Ctor, renderer, {
|
|
6324
|
-
tagName
|
|
6940
|
+
tagName,
|
|
6325
6941
|
mode: options.mode !== 'closed' ? 'open' : 'closed',
|
|
6326
6942
|
owner: null
|
|
6327
6943
|
});
|
|
@@ -6330,15 +6946,21 @@ var LWC = (function (exports) {
|
|
|
6330
6946
|
ConnectingSlot.set(elm, connectRootElement);
|
|
6331
6947
|
DisconnectingSlot.set(elm, disconnectRootElement);
|
|
6332
6948
|
}
|
|
6949
|
+
};
|
|
6333
6950
|
|
|
6334
|
-
|
|
6335
|
-
|
|
6951
|
+
const connectedCallback = elm => {
|
|
6952
|
+
if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
|
|
6953
|
+
connectRootElement(elm);
|
|
6954
|
+
}
|
|
6955
|
+
};
|
|
6336
6956
|
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6957
|
+
const disconnectedCallback = elm => {
|
|
6958
|
+
if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
|
|
6959
|
+
disconnectRootElement(elm);
|
|
6960
|
+
}
|
|
6961
|
+
};
|
|
6341
6962
|
|
|
6963
|
+
const element = createCustomElement(tagName, upgradeCallback, connectedCallback, disconnectedCallback);
|
|
6342
6964
|
return element;
|
|
6343
6965
|
}
|
|
6344
6966
|
|
|
@@ -6410,7 +7032,7 @@ var LWC = (function (exports) {
|
|
|
6410
7032
|
});
|
|
6411
7033
|
freeze(LightningElement);
|
|
6412
7034
|
seal(LightningElement.prototype);
|
|
6413
|
-
/* version: 2.
|
|
7035
|
+
/* version: 2.26.0 */
|
|
6414
7036
|
|
|
6415
7037
|
exports.LightningElement = LightningElement;
|
|
6416
7038
|
exports.__unstable__ProfilerControl = profilerControl;
|