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
|
@@ -294,7 +294,7 @@
|
|
|
294
294
|
CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
|
|
295
295
|
return attributeName;
|
|
296
296
|
}
|
|
297
|
-
/** version: 2.
|
|
297
|
+
/** version: 2.26.0 */
|
|
298
298
|
|
|
299
299
|
/**
|
|
300
300
|
* Copyright (C) 2018 salesforce.com, inc.
|
|
@@ -376,7 +376,7 @@
|
|
|
376
376
|
patch$1(propName);
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
|
-
/** version: 2.
|
|
379
|
+
/** version: 2.26.0 */
|
|
380
380
|
|
|
381
381
|
/**
|
|
382
382
|
* Copyright (C) 2018 salesforce.com, inc.
|
|
@@ -392,7 +392,6 @@
|
|
|
392
392
|
DUMMY_TEST_FLAG: null,
|
|
393
393
|
ENABLE_ELEMENT_PATCH: null,
|
|
394
394
|
ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST: null,
|
|
395
|
-
ENABLE_HMR: null,
|
|
396
395
|
ENABLE_HTML_COLLECTIONS_PATCH: null,
|
|
397
396
|
ENABLE_INNER_OUTER_TEXT_PATCH: null,
|
|
398
397
|
ENABLE_MIXED_SHADOW_MODE: null,
|
|
@@ -402,6 +401,8 @@
|
|
|
402
401
|
ENABLE_REACTIVE_SETTER: null,
|
|
403
402
|
ENABLE_WIRE_SYNC_EMIT: null,
|
|
404
403
|
ENABLE_LIGHT_GET_ROOT_NODE_PATCH: null,
|
|
404
|
+
DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
|
|
405
|
+
ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
|
|
405
406
|
};
|
|
406
407
|
if (!_globalThis.lwcRuntimeFlags) {
|
|
407
408
|
Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
|
|
@@ -1386,7 +1387,9 @@
|
|
|
1386
1387
|
const LightningElement = function () {
|
|
1387
1388
|
// This should be as performant as possible, while any initialization should be done lazily
|
|
1388
1389
|
if (isNull(vmBeingConstructed)) {
|
|
1389
|
-
|
|
1390
|
+
// Thrown when doing something like `new LightningElement()` or
|
|
1391
|
+
// `class Foo extends LightningElement {}; new Foo()`
|
|
1392
|
+
throw new TypeError('Illegal constructor');
|
|
1390
1393
|
}
|
|
1391
1394
|
const vm = vmBeingConstructed;
|
|
1392
1395
|
const { def, elm } = vm;
|
|
@@ -2166,34 +2169,19 @@
|
|
|
2166
2169
|
freeze(BaseBridgeElement);
|
|
2167
2170
|
seal(BaseBridgeElement.prototype);
|
|
2168
2171
|
function setActiveVM(vm) {
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2172
|
+
{
|
|
2173
|
+
// this method should never leak to prod
|
|
2174
|
+
throw new ReferenceError();
|
|
2175
|
+
}
|
|
2173
2176
|
}
|
|
2174
2177
|
function swapTemplate(oldTpl, newTpl) {
|
|
2175
|
-
|
|
2176
|
-
if (!lwcRuntimeFlags.ENABLE_HMR) {
|
|
2177
|
-
throw new Error('HMR is not enabled');
|
|
2178
|
-
}
|
|
2179
|
-
|
|
2180
|
-
return false;
|
|
2178
|
+
return false;
|
|
2181
2179
|
}
|
|
2182
2180
|
function swapComponent(oldComponent, newComponent) {
|
|
2183
|
-
|
|
2184
|
-
if (!lwcRuntimeFlags.ENABLE_HMR) {
|
|
2185
|
-
throw new Error('HMR is not enabled');
|
|
2186
|
-
}
|
|
2187
|
-
|
|
2188
|
-
return false;
|
|
2181
|
+
return false;
|
|
2189
2182
|
}
|
|
2190
2183
|
function swapStyle(oldStyle, newStyle) {
|
|
2191
|
-
|
|
2192
|
-
if (!lwcRuntimeFlags.ENABLE_HMR) {
|
|
2193
|
-
throw new Error('HMR is not enabled');
|
|
2194
|
-
}
|
|
2195
|
-
|
|
2196
|
-
return false;
|
|
2184
|
+
return false;
|
|
2197
2185
|
}
|
|
2198
2186
|
|
|
2199
2187
|
/*
|
|
@@ -2376,230 +2364,265 @@
|
|
|
2376
2364
|
* SPDX-License-Identifier: MIT
|
|
2377
2365
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2378
2366
|
*/
|
|
2367
|
+
|
|
2379
2368
|
function makeHostToken(token) {
|
|
2380
|
-
|
|
2369
|
+
return `${token}-host`;
|
|
2381
2370
|
}
|
|
2371
|
+
|
|
2382
2372
|
function createInlineStyleVNode(content) {
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2373
|
+
return api.h('style', {
|
|
2374
|
+
key: 'style',
|
|
2375
|
+
attrs: {
|
|
2376
|
+
type: 'text/css'
|
|
2377
|
+
}
|
|
2378
|
+
}, [api.t(content)]);
|
|
2389
2379
|
}
|
|
2380
|
+
|
|
2390
2381
|
function updateStylesheetToken(vm, template) {
|
|
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
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2382
|
+
const {
|
|
2383
|
+
elm,
|
|
2384
|
+
context,
|
|
2385
|
+
renderMode,
|
|
2386
|
+
shadowMode,
|
|
2387
|
+
renderer: {
|
|
2388
|
+
getClassList,
|
|
2389
|
+
removeAttribute,
|
|
2390
|
+
setAttribute
|
|
2391
|
+
}
|
|
2392
|
+
} = vm;
|
|
2393
|
+
const {
|
|
2394
|
+
stylesheets: newStylesheets,
|
|
2395
|
+
stylesheetToken: newStylesheetToken
|
|
2396
|
+
} = template;
|
|
2397
|
+
const isSyntheticShadow = renderMode === 1
|
|
2398
|
+
/* RenderMode.Shadow */
|
|
2399
|
+
&& shadowMode === 1
|
|
2400
|
+
/* ShadowMode.Synthetic */
|
|
2401
|
+
;
|
|
2402
|
+
const {
|
|
2403
|
+
hasScopedStyles
|
|
2404
|
+
} = context;
|
|
2405
|
+
let newToken;
|
|
2406
|
+
let newHasTokenInClass;
|
|
2407
|
+
let newHasTokenInAttribute; // Reset the styling token applied to the host element.
|
|
2408
|
+
|
|
2409
|
+
const {
|
|
2410
|
+
stylesheetToken: oldToken,
|
|
2411
|
+
hasTokenInClass: oldHasTokenInClass,
|
|
2412
|
+
hasTokenInAttribute: oldHasTokenInAttribute
|
|
2413
|
+
} = context;
|
|
2414
|
+
|
|
2415
|
+
if (!isUndefined$1(oldToken)) {
|
|
2416
|
+
if (oldHasTokenInClass) {
|
|
2417
|
+
getClassList(elm).remove(makeHostToken(oldToken));
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
if (oldHasTokenInAttribute) {
|
|
2421
|
+
removeAttribute(elm, makeHostToken(oldToken));
|
|
2422
|
+
}
|
|
2423
|
+
} // Apply the new template styling token to the host element, if the new template has any
|
|
2424
|
+
// associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
|
|
2425
|
+
|
|
2426
|
+
|
|
2427
|
+
if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
|
|
2428
|
+
newToken = newStylesheetToken;
|
|
2429
|
+
} // Set the new styling token on the host element
|
|
2430
|
+
|
|
2431
|
+
|
|
2432
|
+
if (!isUndefined$1(newToken)) {
|
|
2433
|
+
if (hasScopedStyles) {
|
|
2434
|
+
getClassList(elm).add(makeHostToken(newToken));
|
|
2435
|
+
newHasTokenInClass = true;
|
|
2436
|
+
}
|
|
2437
|
+
|
|
2438
|
+
if (isSyntheticShadow) {
|
|
2439
|
+
setAttribute(elm, makeHostToken(newToken), '');
|
|
2440
|
+
newHasTokenInAttribute = true;
|
|
2441
|
+
}
|
|
2442
|
+
} // Update the styling tokens present on the context object.
|
|
2443
|
+
|
|
2444
|
+
|
|
2445
|
+
context.stylesheetToken = newToken;
|
|
2446
|
+
context.hasTokenInClass = newHasTokenInClass;
|
|
2447
|
+
context.hasTokenInAttribute = newHasTokenInAttribute;
|
|
2428
2448
|
}
|
|
2449
|
+
|
|
2429
2450
|
function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2451
|
+
const content = [];
|
|
2452
|
+
let root;
|
|
2453
|
+
|
|
2454
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
2455
|
+
let stylesheet = stylesheets[i];
|
|
2456
|
+
|
|
2457
|
+
if (isArray$1(stylesheet)) {
|
|
2458
|
+
ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
|
|
2459
|
+
} else {
|
|
2460
|
+
|
|
2461
|
+
const isScopedCss = stylesheet[KEY__SCOPED_CSS];
|
|
2462
|
+
|
|
2463
|
+
if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS) {
|
|
2464
|
+
if (!isScopedCss && vm.renderMode === 0
|
|
2465
|
+
/* RenderMode.Light */
|
|
2466
|
+
) {
|
|
2467
|
+
logError('Unscoped CSS is not supported in Light DOM. Please use scoped CSS (*.scoped.css) instead of unscoped CSS (*.css).');
|
|
2468
|
+
continue;
|
|
2436
2469
|
}
|
|
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
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2470
|
+
} // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
|
|
2471
|
+
|
|
2472
|
+
|
|
2473
|
+
const scopeToken = isScopedCss || vm.shadowMode === 1
|
|
2474
|
+
/* ShadowMode.Synthetic */
|
|
2475
|
+
&& vm.renderMode === 1
|
|
2476
|
+
/* RenderMode.Shadow */
|
|
2477
|
+
? stylesheetToken : undefined; // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
|
|
2478
|
+
// native shadow DOM. Synthetic shadow DOM never uses `:host`.
|
|
2479
|
+
|
|
2480
|
+
const useActualHostSelector = vm.renderMode === 0
|
|
2481
|
+
/* RenderMode.Light */
|
|
2482
|
+
? !isScopedCss : vm.shadowMode === 0
|
|
2483
|
+
/* ShadowMode.Native */
|
|
2484
|
+
; // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
|
|
2485
|
+
// we use an attribute selector on the host to simulate :dir().
|
|
2486
|
+
|
|
2487
|
+
let useNativeDirPseudoclass;
|
|
2488
|
+
|
|
2489
|
+
if (vm.renderMode === 1
|
|
2490
|
+
/* RenderMode.Shadow */
|
|
2491
|
+
) {
|
|
2492
|
+
useNativeDirPseudoclass = vm.shadowMode === 0
|
|
2493
|
+
/* ShadowMode.Native */
|
|
2494
|
+
;
|
|
2495
|
+
} else {
|
|
2496
|
+
// Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
|
|
2497
|
+
// At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
|
|
2498
|
+
if (isUndefined$1(root)) {
|
|
2499
|
+
// Only calculate the root once as necessary
|
|
2500
|
+
root = getNearestShadowComponent(vm);
|
|
2465
2501
|
}
|
|
2502
|
+
|
|
2503
|
+
useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0
|
|
2504
|
+
/* ShadowMode.Native */
|
|
2505
|
+
;
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
|
|
2466
2509
|
}
|
|
2467
|
-
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
return content;
|
|
2468
2513
|
}
|
|
2514
|
+
|
|
2469
2515
|
function getStylesheetsContent(vm, template) {
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2516
|
+
const {
|
|
2517
|
+
stylesheets,
|
|
2518
|
+
stylesheetToken
|
|
2519
|
+
} = template;
|
|
2520
|
+
let content = [];
|
|
2521
|
+
|
|
2522
|
+
if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
|
|
2523
|
+
content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
|
|
2524
|
+
}
|
|
2525
|
+
|
|
2526
|
+
return content;
|
|
2527
|
+
} // It might be worth caching this to avoid doing the lookup repeatedly, but
|
|
2478
2528
|
// perf testing has not shown it to be a huge improvement yet:
|
|
2479
2529
|
// https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
|
|
2530
|
+
|
|
2480
2531
|
function getNearestShadowComponent(vm) {
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2532
|
+
let owner = vm;
|
|
2533
|
+
|
|
2534
|
+
while (!isNull(owner)) {
|
|
2535
|
+
if (owner.renderMode === 1
|
|
2536
|
+
/* RenderMode.Shadow */
|
|
2537
|
+
) {
|
|
2538
|
+
return owner;
|
|
2487
2539
|
}
|
|
2488
|
-
|
|
2540
|
+
|
|
2541
|
+
owner = owner.owner;
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
return owner;
|
|
2489
2545
|
}
|
|
2490
2546
|
/**
|
|
2491
2547
|
* If the component that is currently being rendered uses scoped styles,
|
|
2492
2548
|
* this returns the unique token for that scoped stylesheet. Otherwise
|
|
2493
2549
|
* it returns null.
|
|
2494
2550
|
*/
|
|
2551
|
+
|
|
2552
|
+
|
|
2495
2553
|
function getScopeTokenClass(owner) {
|
|
2496
|
-
|
|
2497
|
-
|
|
2554
|
+
const {
|
|
2555
|
+
cmpTemplate,
|
|
2556
|
+
context
|
|
2557
|
+
} = owner;
|
|
2558
|
+
return context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken) || null;
|
|
2498
2559
|
}
|
|
2499
2560
|
/**
|
|
2500
2561
|
* This function returns the host style token for a custom element if it
|
|
2501
2562
|
* exists. Otherwise it returns null.
|
|
2563
|
+
*
|
|
2564
|
+
* A host style token is applied to the component if scoped styles are used.
|
|
2502
2565
|
*/
|
|
2566
|
+
|
|
2503
2567
|
function getStylesheetTokenHost(vnode) {
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
// synthetic, we know we won't find a native component if we go any further.
|
|
2512
|
-
return null;
|
|
2513
|
-
}
|
|
2514
|
-
return owner;
|
|
2515
|
-
}
|
|
2516
|
-
function createStylesheet(vm, stylesheets) {
|
|
2517
|
-
const { renderMode, shadowMode, renderer: { insertStylesheet }, } = vm;
|
|
2518
|
-
if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
|
|
2519
|
-
for (let i = 0; i < stylesheets.length; i++) {
|
|
2520
|
-
insertStylesheet(stylesheets[i]);
|
|
2521
|
-
}
|
|
2522
|
-
}
|
|
2523
|
-
else if (vm.hydrated) {
|
|
2524
|
-
// Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
|
|
2525
|
-
// This works in the client, because the stylesheets are created, and cached in the VM
|
|
2526
|
-
// the first time the VM renders.
|
|
2527
|
-
// native shadow or light DOM, SSR
|
|
2528
|
-
return ArrayMap.call(stylesheets, createInlineStyleVNode);
|
|
2529
|
-
}
|
|
2530
|
-
else {
|
|
2531
|
-
// native shadow or light DOM, DOM renderer
|
|
2532
|
-
const root = getNearestNativeShadowComponent(vm);
|
|
2533
|
-
// null root means a global style
|
|
2534
|
-
const target = isNull(root) ? undefined : root.shadowRoot;
|
|
2535
|
-
for (let i = 0; i < stylesheets.length; i++) {
|
|
2536
|
-
insertStylesheet(stylesheets[i], target);
|
|
2537
|
-
}
|
|
2538
|
-
}
|
|
2539
|
-
return null;
|
|
2568
|
+
const {
|
|
2569
|
+
template
|
|
2570
|
+
} = getComponentInternalDef(vnode.ctor);
|
|
2571
|
+
const {
|
|
2572
|
+
stylesheetToken
|
|
2573
|
+
} = template;
|
|
2574
|
+
return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
|
|
2540
2575
|
}
|
|
2541
2576
|
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
* All rights reserved.
|
|
2545
|
-
* SPDX-License-Identifier: MIT
|
|
2546
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2547
|
-
*/
|
|
2577
|
+
function getNearestNativeShadowComponent(vm) {
|
|
2578
|
+
const owner = getNearestShadowComponent(vm);
|
|
2548
2579
|
|
|
2549
|
-
|
|
2550
|
-
|
|
2580
|
+
if (!isNull(owner) && owner.shadowMode === 1
|
|
2581
|
+
/* ShadowMode.Synthetic */
|
|
2582
|
+
) {
|
|
2583
|
+
// Synthetic-within-native is impossible. So if the nearest shadow component is
|
|
2584
|
+
// synthetic, we know we won't find a native component if we go any further.
|
|
2585
|
+
return null;
|
|
2586
|
+
}
|
|
2551
2587
|
|
|
2552
|
-
return
|
|
2588
|
+
return owner;
|
|
2553
2589
|
}
|
|
2554
2590
|
|
|
2555
|
-
function
|
|
2591
|
+
function createStylesheet(vm, stylesheets) {
|
|
2556
2592
|
const {
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
// produce only tags with lowercase letters
|
|
2562
|
-
// But, for backwards compatibility, we will lower case the tagName
|
|
2563
|
-
|
|
2564
|
-
tagName = tagName.toLowerCase();
|
|
2565
|
-
let CE = getCustomElement(tagName);
|
|
2566
|
-
|
|
2567
|
-
if (!isUndefined$1(CE)) {
|
|
2568
|
-
return CE;
|
|
2569
|
-
}
|
|
2570
|
-
/**
|
|
2571
|
-
* LWC Upgradable Element reference to an element that was created
|
|
2572
|
-
* via the scoped registry mechanism, and that is ready to be upgraded.
|
|
2573
|
-
*/
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
CE = class LWCUpgradableElement extends RendererHTMLElement {
|
|
2577
|
-
constructor(upgradeCallback) {
|
|
2578
|
-
super();
|
|
2579
|
-
|
|
2580
|
-
if (isFunction$1(upgradeCallback)) {
|
|
2581
|
-
upgradeCallback(this); // nothing to do with the result for now
|
|
2582
|
-
}
|
|
2593
|
+
renderMode,
|
|
2594
|
+
shadowMode,
|
|
2595
|
+
renderer: {
|
|
2596
|
+
insertStylesheet
|
|
2583
2597
|
}
|
|
2598
|
+
} = vm;
|
|
2584
2599
|
|
|
2585
|
-
|
|
2600
|
+
if (renderMode === 1
|
|
2601
|
+
/* RenderMode.Shadow */
|
|
2602
|
+
&& shadowMode === 1
|
|
2603
|
+
/* ShadowMode.Synthetic */
|
|
2604
|
+
) {
|
|
2605
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
2606
|
+
insertStylesheet(stylesheets[i]);
|
|
2607
|
+
}
|
|
2608
|
+
} else if (vm.hydrated) {
|
|
2609
|
+
// Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
|
|
2610
|
+
// This works in the client, because the stylesheets are created, and cached in the VM
|
|
2611
|
+
// the first time the VM renders.
|
|
2612
|
+
// native shadow or light DOM, SSR
|
|
2613
|
+
return ArrayMap.call(stylesheets, createInlineStyleVNode);
|
|
2614
|
+
} else {
|
|
2615
|
+
// native shadow or light DOM, DOM renderer
|
|
2616
|
+
const root = getNearestNativeShadowComponent(vm); // null root means a global style
|
|
2586
2617
|
|
|
2587
|
-
|
|
2588
|
-
CE.prototype.connectedCallback = function () {
|
|
2589
|
-
if (checkHasVM(this)) {
|
|
2590
|
-
connectRootElement(this);
|
|
2591
|
-
}
|
|
2592
|
-
};
|
|
2618
|
+
const target = isNull(root) ? undefined : root.shadowRoot;
|
|
2593
2619
|
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
}
|
|
2598
|
-
};
|
|
2620
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
2621
|
+
insertStylesheet(stylesheets[i], target);
|
|
2622
|
+
}
|
|
2599
2623
|
}
|
|
2600
2624
|
|
|
2601
|
-
|
|
2602
|
-
return CE;
|
|
2625
|
+
return null;
|
|
2603
2626
|
}
|
|
2604
2627
|
|
|
2605
2628
|
/*
|
|
@@ -3089,7 +3112,9 @@
|
|
|
3089
3112
|
sel,
|
|
3090
3113
|
owner
|
|
3091
3114
|
} = vnode;
|
|
3092
|
-
const
|
|
3115
|
+
const {
|
|
3116
|
+
createCustomElement
|
|
3117
|
+
} = renderer;
|
|
3093
3118
|
/**
|
|
3094
3119
|
* Note: if the upgradable constructor does not expect, or throw when we new it
|
|
3095
3120
|
* with a callback as the first argument, we could implement a more advanced
|
|
@@ -3098,10 +3123,25 @@
|
|
|
3098
3123
|
*/
|
|
3099
3124
|
|
|
3100
3125
|
let vm;
|
|
3101
|
-
|
|
3126
|
+
|
|
3127
|
+
const upgradeCallback = elm => {
|
|
3102
3128
|
// the custom element from the registry is expecting an upgrade callback
|
|
3103
3129
|
vm = createViewModelHook(elm, vnode, renderer);
|
|
3104
|
-
}
|
|
3130
|
+
};
|
|
3131
|
+
|
|
3132
|
+
const connectedCallback = elm => {
|
|
3133
|
+
if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
|
|
3134
|
+
connectRootElement(elm);
|
|
3135
|
+
}
|
|
3136
|
+
};
|
|
3137
|
+
|
|
3138
|
+
const disconnectedCallback = elm => {
|
|
3139
|
+
if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
|
|
3140
|
+
disconnectRootElement(elm);
|
|
3141
|
+
}
|
|
3142
|
+
};
|
|
3143
|
+
|
|
3144
|
+
const elm = createCustomElement(sel, upgradeCallback, connectedCallback, disconnectedCallback);
|
|
3105
3145
|
vnode.elm = elm;
|
|
3106
3146
|
vnode.vm = vm;
|
|
3107
3147
|
linkNodeToShadow(elm, owner, renderer);
|
|
@@ -3109,8 +3149,6 @@
|
|
|
3109
3149
|
|
|
3110
3150
|
if (vm) {
|
|
3111
3151
|
allocateChildren(vnode, vm);
|
|
3112
|
-
} else if (vnode.ctor !== UpgradableConstructor) {
|
|
3113
|
-
throw new TypeError(`Incorrect Component Constructor`);
|
|
3114
3152
|
}
|
|
3115
3153
|
|
|
3116
3154
|
patchElementPropsAndAttrs$1(null, vnode, renderer);
|
|
@@ -5466,19 +5504,23 @@
|
|
|
5466
5504
|
//
|
|
5467
5505
|
// Consequently, hydration mismatches will occur if scoped CSS token classnames
|
|
5468
5506
|
// are rendered during SSR. This needs to be accounted for when validating.
|
|
5469
|
-
if (scopedToken) {
|
|
5507
|
+
if (!isNull(scopedToken) || !isNull(stylesheetTokenHost)) {
|
|
5470
5508
|
if (!isUndefined$1(className)) {
|
|
5471
|
-
className
|
|
5472
|
-
|
|
5473
|
-
|
|
5509
|
+
// The order of the className should be scopedToken className stylesheetTokenHost
|
|
5510
|
+
const classTokens = [scopedToken, className, stylesheetTokenHost];
|
|
5511
|
+
const classNames = ArrayFilter.call(classTokens, (token) => !isNull(token));
|
|
5512
|
+
className = ArrayJoin.call(classNames, ' ');
|
|
5474
5513
|
}
|
|
5475
5514
|
else if (!isUndefined$1(classMap)) {
|
|
5476
|
-
classMap = Object.assign(Object.assign(Object.assign({}, classMap), { [scopedToken]: true }), (isNull(stylesheetTokenHost) ? {
|
|
5515
|
+
classMap = Object.assign(Object.assign(Object.assign({}, classMap), (!isNull(scopedToken) ? { [scopedToken]: true } : {})), (!isNull(stylesheetTokenHost) ? { [stylesheetTokenHost]: true } : {}));
|
|
5477
5516
|
}
|
|
5478
5517
|
else {
|
|
5479
|
-
className
|
|
5480
|
-
|
|
5481
|
-
|
|
5518
|
+
// The order of the className should be scopedToken stylesheetTokenHost
|
|
5519
|
+
const classTokens = [scopedToken, stylesheetTokenHost];
|
|
5520
|
+
const classNames = ArrayFilter.call(classTokens, (token) => !isNull(token));
|
|
5521
|
+
if (classNames.length) {
|
|
5522
|
+
className = ArrayJoin.call(classNames, ' ');
|
|
5523
|
+
}
|
|
5482
5524
|
}
|
|
5483
5525
|
}
|
|
5484
5526
|
let nodesAreCompatible = true;
|
|
@@ -5607,7 +5649,7 @@
|
|
|
5607
5649
|
}
|
|
5608
5650
|
return ctor;
|
|
5609
5651
|
}
|
|
5610
|
-
/* version: 2.
|
|
5652
|
+
/* version: 2.26.0 */
|
|
5611
5653
|
|
|
5612
5654
|
/*
|
|
5613
5655
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -5742,6 +5784,626 @@
|
|
|
5742
5784
|
}
|
|
5743
5785
|
}
|
|
5744
5786
|
|
|
5787
|
+
/*
|
|
5788
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
5789
|
+
* All rights reserved.
|
|
5790
|
+
* SPDX-License-Identifier: MIT
|
|
5791
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5792
|
+
*/
|
|
5793
|
+
function isCustomElementRegistryAvailable() {
|
|
5794
|
+
if (typeof customElements === 'undefined') {
|
|
5795
|
+
return false;
|
|
5796
|
+
}
|
|
5797
|
+
try {
|
|
5798
|
+
// dereference HTMLElement global because babel wraps globals in compat mode with a
|
|
5799
|
+
// _wrapNativeSuper()
|
|
5800
|
+
// This is a problem because LWCUpgradableElement extends renderer.HTMLElement which does not
|
|
5801
|
+
// get wrapped by babel.
|
|
5802
|
+
const HTMLElementAlias = HTMLElement;
|
|
5803
|
+
// In case we use compat mode with a modern browser, the compat mode transformation
|
|
5804
|
+
// invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
|
|
5805
|
+
// which are not equipped to be initialized that way.
|
|
5806
|
+
class clazz extends HTMLElementAlias {
|
|
5807
|
+
}
|
|
5808
|
+
customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
|
|
5809
|
+
new clazz();
|
|
5810
|
+
return true;
|
|
5811
|
+
}
|
|
5812
|
+
catch (_a) {
|
|
5813
|
+
return false;
|
|
5814
|
+
}
|
|
5815
|
+
}
|
|
5816
|
+
const hasCustomElements = isCustomElementRegistryAvailable();
|
|
5817
|
+
|
|
5818
|
+
/*
|
|
5819
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
5820
|
+
* All rights reserved.
|
|
5821
|
+
* SPDX-License-Identifier: MIT
|
|
5822
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5823
|
+
*/
|
|
5824
|
+
// Creates a custom element for compat (legacy) browser environments
|
|
5825
|
+
const createCustomElementCompat = (tagName, upgradeCallback) => {
|
|
5826
|
+
const elm = document.createElement(tagName);
|
|
5827
|
+
upgradeCallback(elm); // nothing to do with the result for now
|
|
5828
|
+
return elm;
|
|
5829
|
+
};
|
|
5830
|
+
|
|
5831
|
+
/*
|
|
5832
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
5833
|
+
* All rights reserved.
|
|
5834
|
+
* SPDX-License-Identifier: MIT
|
|
5835
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5836
|
+
*/
|
|
5837
|
+
const cachedConstructors = new Map();
|
|
5838
|
+
const elementsUpgradedOutsideLWC = new WeakSet();
|
|
5839
|
+
let elementBeingUpgradedByLWC = false;
|
|
5840
|
+
// Creates a constructor that is intended to be used as a vanilla custom element, except that the upgradeCallback is
|
|
5841
|
+
// passed in to the constructor so LWC can reuse the same custom element constructor for multiple components.
|
|
5842
|
+
// Another benefit is that only LWC can create components that actually do anything – if you do
|
|
5843
|
+
// `customElements.define('x-foo')`, then you don't have access to the upgradeCallback, so it's a dummy custom element.
|
|
5844
|
+
// This class should be created once per tag name.
|
|
5845
|
+
const createUpgradableConstructor = (connectedCallback, disconnectedCallback) => {
|
|
5846
|
+
// TODO [#2972]: this class should expose observedAttributes as necessary
|
|
5847
|
+
return class UpgradableConstructor extends HTMLElement {
|
|
5848
|
+
constructor(upgradeCallback) {
|
|
5849
|
+
super();
|
|
5850
|
+
// If the element is not created using lwc.createElement(), e.g. `document.createElement('x-foo')`,
|
|
5851
|
+
// then elementBeingUpgraded will be false
|
|
5852
|
+
if (elementBeingUpgradedByLWC) {
|
|
5853
|
+
upgradeCallback(this);
|
|
5854
|
+
}
|
|
5855
|
+
else {
|
|
5856
|
+
// keep track of elements that were not created by lwc.createElement,
|
|
5857
|
+
// so we can ignore their lifecycle hooks
|
|
5858
|
+
elementsUpgradedOutsideLWC.add(this);
|
|
5859
|
+
// TODO [#2970]: LWC elements cannot be upgraded via new Ctor()
|
|
5860
|
+
// Do we want to support this? Throw an error? Currently for backwards compat it's a no-op.
|
|
5861
|
+
}
|
|
5862
|
+
}
|
|
5863
|
+
connectedCallback() {
|
|
5864
|
+
if (!elementsUpgradedOutsideLWC.has(this)) {
|
|
5865
|
+
connectedCallback(this);
|
|
5866
|
+
}
|
|
5867
|
+
}
|
|
5868
|
+
disconnectedCallback() {
|
|
5869
|
+
if (!elementsUpgradedOutsideLWC.has(this)) {
|
|
5870
|
+
disconnectedCallback(this);
|
|
5871
|
+
}
|
|
5872
|
+
}
|
|
5873
|
+
};
|
|
5874
|
+
};
|
|
5875
|
+
const createCustomElementVanilla = (tagName, upgradeCallback, connectedCallback, disconnectedCallback) => {
|
|
5876
|
+
// use global custom elements registry
|
|
5877
|
+
let UpgradableConstructor = cachedConstructors.get(tagName);
|
|
5878
|
+
if (isUndefined$1(UpgradableConstructor)) {
|
|
5879
|
+
if (!isUndefined$1(customElements.get(tagName))) {
|
|
5880
|
+
throw new Error(`Unexpected tag name "${tagName}". This name is a registered custom element, preventing LWC to upgrade the element.`);
|
|
5881
|
+
}
|
|
5882
|
+
UpgradableConstructor = createUpgradableConstructor(connectedCallback, disconnectedCallback);
|
|
5883
|
+
customElements.define(tagName, UpgradableConstructor);
|
|
5884
|
+
cachedConstructors.set(tagName, UpgradableConstructor);
|
|
5885
|
+
}
|
|
5886
|
+
elementBeingUpgradedByLWC = true;
|
|
5887
|
+
try {
|
|
5888
|
+
return new UpgradableConstructor(upgradeCallback);
|
|
5889
|
+
}
|
|
5890
|
+
finally {
|
|
5891
|
+
elementBeingUpgradedByLWC = false;
|
|
5892
|
+
}
|
|
5893
|
+
};
|
|
5894
|
+
|
|
5895
|
+
/*
|
|
5896
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
5897
|
+
* All rights reserved.
|
|
5898
|
+
* SPDX-License-Identifier: MIT
|
|
5899
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5900
|
+
*/
|
|
5901
|
+
/**
|
|
5902
|
+
* Create a scoped registry, i.e. a function that can create custom elements whose tag names
|
|
5903
|
+
* do not conflict with vanilla custom elements having the same tag name.
|
|
5904
|
+
*/
|
|
5905
|
+
function createScopedRegistry() {
|
|
5906
|
+
if (!hasCustomElements) {
|
|
5907
|
+
// This code should never be reached, because we don't use the pivot registry if
|
|
5908
|
+
// custom elements are unavailable.
|
|
5909
|
+
throw new Error('Custom elements are not supported in this environment.');
|
|
5910
|
+
}
|
|
5911
|
+
const { HTMLElement: NativeHTMLElement } = window;
|
|
5912
|
+
const { hasAttribute: nativeHasAttribute, setAttribute: nativeSetAttribute, removeAttribute: nativeRemoveAttribute, getAttribute: nativeGetAttribute, } = NativeHTMLElement.prototype;
|
|
5913
|
+
const definitionForElement = new WeakMap();
|
|
5914
|
+
const pendingRegistryForElement = new WeakMap();
|
|
5915
|
+
const definitionForConstructor = new WeakMap();
|
|
5916
|
+
const registeredUserCtors = new WeakSet();
|
|
5917
|
+
const pivotCtorByTag = new Map();
|
|
5918
|
+
const globalDefinitionsByTag = new Map();
|
|
5919
|
+
const globalDefinitionsByClass = new Map();
|
|
5920
|
+
const awaitingUpgrade = new Map();
|
|
5921
|
+
const EMPTY_SET = new Set();
|
|
5922
|
+
function createDefinitionRecord(constructor) {
|
|
5923
|
+
var _a;
|
|
5924
|
+
const { connectedCallback, disconnectedCallback, adoptedCallback, attributeChangedCallback, } = constructor.prototype;
|
|
5925
|
+
const observedAttributes = new Set((_a = constructor.observedAttributes) !== null && _a !== void 0 ? _a : []);
|
|
5926
|
+
return {
|
|
5927
|
+
UserCtor: constructor,
|
|
5928
|
+
PivotCtor: undefined,
|
|
5929
|
+
connectedCallback,
|
|
5930
|
+
disconnectedCallback,
|
|
5931
|
+
adoptedCallback,
|
|
5932
|
+
attributeChangedCallback,
|
|
5933
|
+
observedAttributes,
|
|
5934
|
+
};
|
|
5935
|
+
}
|
|
5936
|
+
// Helper to create stand-in element for each tagName registered that delegates out to the registry for the given
|
|
5937
|
+
// element. Note that the `registeredDefinition` represents the constructor that was used to register during
|
|
5938
|
+
// `customElements.define()`. Whereas the `pivotDefinition` represents the constructor that is passed when the pivot
|
|
5939
|
+
// constructor is invoked with another constructor.
|
|
5940
|
+
function createPivotingClass(tagName, registeredDefinition) {
|
|
5941
|
+
class PivotCtor extends NativeHTMLElement {
|
|
5942
|
+
constructor(UserCtor) {
|
|
5943
|
+
// This constructor can only be invoked by:
|
|
5944
|
+
// a) the browser instantiating an element from parsing or via document.createElement.
|
|
5945
|
+
// b) LWC new PivotClass (This constructor is NOT observable/accessible in user-land).
|
|
5946
|
+
// b) new UserClass.
|
|
5947
|
+
// When LWC instantiates it, it will pass the upgrading definition as an argument
|
|
5948
|
+
// If the caller signals via UserCtor that this is in fact a controlled
|
|
5949
|
+
// definition, we use that one, otherwise fallback to the global
|
|
5950
|
+
// internal registry.
|
|
5951
|
+
super();
|
|
5952
|
+
const userCtorIsDefined = !isUndefined$1(UserCtor);
|
|
5953
|
+
if (userCtorIsDefined) {
|
|
5954
|
+
if (!isConstructor(UserCtor)) {
|
|
5955
|
+
throw new TypeError(`Failed to create custom element: the provided constructor is not a constructor.`);
|
|
5956
|
+
}
|
|
5957
|
+
if (!registeredUserCtors.has(UserCtor)) {
|
|
5958
|
+
throw new Error(`Failed to create custom element: the provided constructor is unregistered: ${UserCtor.name}.`);
|
|
5959
|
+
}
|
|
5960
|
+
}
|
|
5961
|
+
const definition = userCtorIsDefined
|
|
5962
|
+
? getOrCreateDefinitionForConstructor(UserCtor)
|
|
5963
|
+
: globalDefinitionsByTag.get(tagName);
|
|
5964
|
+
if (!isUndefined$1(definition)) {
|
|
5965
|
+
internalUpgrade(this, registeredDefinition, definition);
|
|
5966
|
+
}
|
|
5967
|
+
else {
|
|
5968
|
+
// This is the case in which there is no global definition, and
|
|
5969
|
+
// it is not handled by LWC (otherwise it will have a valid UserCtor)
|
|
5970
|
+
// so we need to add it to the pending queue just in case it eventually
|
|
5971
|
+
// gets defined in the global registry.
|
|
5972
|
+
pendingRegistryForElement.set(this, registeredDefinition);
|
|
5973
|
+
}
|
|
5974
|
+
}
|
|
5975
|
+
connectedCallback() {
|
|
5976
|
+
var _a;
|
|
5977
|
+
const definition = definitionForElement.get(this);
|
|
5978
|
+
if (!isUndefined$1(definition)) {
|
|
5979
|
+
// Delegate out to user callback
|
|
5980
|
+
(_a = definition.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
5981
|
+
}
|
|
5982
|
+
else {
|
|
5983
|
+
// Register for upgrade when defined (only when connected, so we don't leak)
|
|
5984
|
+
let awaiting = awaitingUpgrade.get(tagName);
|
|
5985
|
+
if (isUndefined$1(awaiting)) {
|
|
5986
|
+
awaitingUpgrade.set(tagName, (awaiting = new Set()));
|
|
5987
|
+
}
|
|
5988
|
+
awaiting.add(this);
|
|
5989
|
+
}
|
|
5990
|
+
}
|
|
5991
|
+
disconnectedCallback() {
|
|
5992
|
+
var _a;
|
|
5993
|
+
const definition = definitionForElement.get(this);
|
|
5994
|
+
if (!isUndefined$1(definition)) {
|
|
5995
|
+
// Delegate out to user callback
|
|
5996
|
+
(_a = definition.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
5997
|
+
}
|
|
5998
|
+
else {
|
|
5999
|
+
// Un-register for upgrade when defined (so we don't leak)
|
|
6000
|
+
const awaiting = awaitingUpgrade.get(tagName);
|
|
6001
|
+
// At this point, awaiting should never be undefined, because connectedCallback
|
|
6002
|
+
// must have been called before disconnectedCallback. But just to be safe, we check
|
|
6003
|
+
if (!isUndefined$1(awaiting)) {
|
|
6004
|
+
awaiting.delete(this);
|
|
6005
|
+
}
|
|
6006
|
+
}
|
|
6007
|
+
}
|
|
6008
|
+
adoptedCallback() {
|
|
6009
|
+
var _a;
|
|
6010
|
+
const definition = definitionForElement.get(this);
|
|
6011
|
+
(_a = definition === null || definition === void 0 ? void 0 : definition.adoptedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
6012
|
+
}
|
|
6013
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
6014
|
+
var _a;
|
|
6015
|
+
const definition = definitionForElement.get(this);
|
|
6016
|
+
// if both definitions are the same, then the observedAttributes is the same,
|
|
6017
|
+
// but if they are different, only if the runtime definition has the attribute
|
|
6018
|
+
// marked as observed, then it should invoke attributeChangedCallback.
|
|
6019
|
+
if (registeredDefinition === definition ||
|
|
6020
|
+
(definition === null || definition === void 0 ? void 0 : definition.observedAttributes.has(name))) {
|
|
6021
|
+
(_a = definition.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.apply(this, [name, oldValue, newValue]);
|
|
6022
|
+
}
|
|
6023
|
+
}
|
|
6024
|
+
}
|
|
6025
|
+
PivotCtor.observedAttributes = [...registeredDefinition.observedAttributes];
|
|
6026
|
+
return PivotCtor;
|
|
6027
|
+
}
|
|
6028
|
+
function getNewObservedAttributes(registeredDefinition, pivotDefinition) {
|
|
6029
|
+
const { observedAttributes, attributeChangedCallback } = pivotDefinition;
|
|
6030
|
+
if (observedAttributes.size === 0 || isUndefined$1(attributeChangedCallback)) {
|
|
6031
|
+
// This instance does not need to observe any attributes, no need to patch
|
|
6032
|
+
return EMPTY_SET;
|
|
6033
|
+
}
|
|
6034
|
+
// Natively, the attributes observed by the registered definition are going to be taken
|
|
6035
|
+
// care of by the browser, only the difference between the two sets has to be taken
|
|
6036
|
+
// care by the patched version.
|
|
6037
|
+
return new Set([...pivotDefinition.observedAttributes].filter((x) => !registeredDefinition.observedAttributes.has(x)));
|
|
6038
|
+
}
|
|
6039
|
+
function throwAsyncError(error) {
|
|
6040
|
+
// Per native custom element behavior, errors thrown in attributeChangedCallback
|
|
6041
|
+
// become unhandled async errors. We use setTimeout() instead of Promise.resolve()
|
|
6042
|
+
// to make it an unhandled error rather than an unhandled rejection.
|
|
6043
|
+
setTimeout(() => {
|
|
6044
|
+
throw error;
|
|
6045
|
+
});
|
|
6046
|
+
}
|
|
6047
|
+
// Helper to patch `setAttribute`/`getAttribute` to implement `attributeChangedCallback`.
|
|
6048
|
+
// Why is this necessary? Well basically, you can't change the `observedAttributes` after
|
|
6049
|
+
// a custom element is defined. So with pivots, if two classes share the same tag name,
|
|
6050
|
+
// and the second class observes attributes that aren't observed by the first one,
|
|
6051
|
+
// then those attributes can never be observed by the native `observedAttributes` system.
|
|
6052
|
+
// So we have to simulate it by patching `getAttribute`/`removeAttribute`. Note that
|
|
6053
|
+
// we only do this when absolutely necessary, though; i.e. because we've determined
|
|
6054
|
+
// that we aren't observing the attributes we need to.
|
|
6055
|
+
function patchAttributes(instance, registeredDefinition, pivotDefinition) {
|
|
6056
|
+
const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
|
|
6057
|
+
if (newObservedAttributes.size === 0) {
|
|
6058
|
+
return;
|
|
6059
|
+
}
|
|
6060
|
+
const { attributeChangedCallback } = pivotDefinition;
|
|
6061
|
+
// Patch the instance.
|
|
6062
|
+
// Note we use the native `getAttribute` rather than the super's `getAttribute` because
|
|
6063
|
+
// we don't actually want it to be observable that we're calling `getAttribute` from
|
|
6064
|
+
// `setAttribute` and `removeAttribute`.
|
|
6065
|
+
// TODO [#2994]: this should handle reflected properties such as `ariaLabel` and `role`.
|
|
6066
|
+
defineProperties(instance, {
|
|
6067
|
+
setAttribute: {
|
|
6068
|
+
value: function setAttribute(name, value) {
|
|
6069
|
+
if (newObservedAttributes.has(name)) {
|
|
6070
|
+
const old = nativeGetAttribute.call(this, name);
|
|
6071
|
+
nativeSetAttribute.call(this, name, value);
|
|
6072
|
+
try {
|
|
6073
|
+
attributeChangedCallback.call(this, name, old, value + '');
|
|
6074
|
+
}
|
|
6075
|
+
catch (error) {
|
|
6076
|
+
throwAsyncError(error);
|
|
6077
|
+
}
|
|
6078
|
+
}
|
|
6079
|
+
else {
|
|
6080
|
+
nativeSetAttribute.call(this, name, value);
|
|
6081
|
+
}
|
|
6082
|
+
},
|
|
6083
|
+
writable: true,
|
|
6084
|
+
enumerable: true,
|
|
6085
|
+
configurable: true,
|
|
6086
|
+
},
|
|
6087
|
+
removeAttribute: {
|
|
6088
|
+
value: function removeAttribute(name) {
|
|
6089
|
+
if (newObservedAttributes.has(name)) {
|
|
6090
|
+
const old = nativeGetAttribute.call(this, name);
|
|
6091
|
+
nativeRemoveAttribute.call(this, name);
|
|
6092
|
+
try {
|
|
6093
|
+
attributeChangedCallback.call(this, name, old, null);
|
|
6094
|
+
}
|
|
6095
|
+
catch (error) {
|
|
6096
|
+
throwAsyncError(error);
|
|
6097
|
+
}
|
|
6098
|
+
}
|
|
6099
|
+
else {
|
|
6100
|
+
nativeRemoveAttribute.call(this, name);
|
|
6101
|
+
}
|
|
6102
|
+
},
|
|
6103
|
+
writable: true,
|
|
6104
|
+
enumerable: true,
|
|
6105
|
+
configurable: true,
|
|
6106
|
+
},
|
|
6107
|
+
});
|
|
6108
|
+
}
|
|
6109
|
+
function patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition) {
|
|
6110
|
+
// The below case patches observed attributes for the case where the HTML element is upgraded
|
|
6111
|
+
// from a pre-existing one in the DOM.
|
|
6112
|
+
const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
|
|
6113
|
+
if (getNewObservedAttributes(registeredDefinition, pivotDefinition).size === 0) {
|
|
6114
|
+
return;
|
|
6115
|
+
}
|
|
6116
|
+
const { attributeChangedCallback } = pivotDefinition;
|
|
6117
|
+
// Approximate observedAttributes from the user class, but only for the new observed attributes
|
|
6118
|
+
newObservedAttributes.forEach((name) => {
|
|
6119
|
+
if (nativeHasAttribute.call(instance, name)) {
|
|
6120
|
+
const newValue = nativeGetAttribute.call(instance, name);
|
|
6121
|
+
attributeChangedCallback.call(instance, name, null, newValue);
|
|
6122
|
+
}
|
|
6123
|
+
});
|
|
6124
|
+
}
|
|
6125
|
+
// User extends this HTMLElement, which returns the CE being upgraded
|
|
6126
|
+
let upgradingInstance;
|
|
6127
|
+
// Helper to upgrade an instance with a CE definition using "constructor call trick"
|
|
6128
|
+
function internalUpgrade(instance, registeredDefinition, pivotDefinition) {
|
|
6129
|
+
setPrototypeOf(instance, pivotDefinition.UserCtor.prototype);
|
|
6130
|
+
definitionForElement.set(instance, pivotDefinition);
|
|
6131
|
+
// attributes patches when needed
|
|
6132
|
+
if (pivotDefinition !== registeredDefinition) {
|
|
6133
|
+
patchAttributes(instance, registeredDefinition, pivotDefinition);
|
|
6134
|
+
}
|
|
6135
|
+
// Tricking the construction path to believe that a new instance is being created,
|
|
6136
|
+
// that way it will execute the super initialization mechanism but the HTMLElement
|
|
6137
|
+
// constructor will reuse the instance by returning the upgradingInstance.
|
|
6138
|
+
// This is by far the most important piece of the puzzle
|
|
6139
|
+
upgradingInstance = instance;
|
|
6140
|
+
// By `new`ing the UserCtor, we now jump to the constructor for the overridden global HTMLElement
|
|
6141
|
+
// The reason this happens is that the UserCtor extends HTMLElement, so it calls the `super()`.
|
|
6142
|
+
// Note that `upgradingInstance` is explicitly handled in the HTMLElement constructor.
|
|
6143
|
+
new pivotDefinition.UserCtor();
|
|
6144
|
+
patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition);
|
|
6145
|
+
}
|
|
6146
|
+
function isConstructor(constructor) {
|
|
6147
|
+
return isFunction$1(constructor) && isObject(constructor.prototype);
|
|
6148
|
+
}
|
|
6149
|
+
function getOrCreateDefinitionForConstructor(constructor) {
|
|
6150
|
+
if (!isConstructor(constructor)) {
|
|
6151
|
+
throw new TypeError('The referenced constructor is not a constructor.');
|
|
6152
|
+
}
|
|
6153
|
+
const definition = definitionForConstructor.get(constructor);
|
|
6154
|
+
if (!isUndefined$1(definition)) {
|
|
6155
|
+
return definition;
|
|
6156
|
+
}
|
|
6157
|
+
return createDefinitionRecord(constructor);
|
|
6158
|
+
}
|
|
6159
|
+
const { customElements: nativeRegistry } = window;
|
|
6160
|
+
const { define: nativeDefine, whenDefined: nativeWhenDefined, get: nativeGet } = nativeRegistry;
|
|
6161
|
+
// patch for the global registry define mechanism
|
|
6162
|
+
CustomElementRegistry.prototype.define = function define(tagName, constructor, options) {
|
|
6163
|
+
if (options && options.extends) {
|
|
6164
|
+
// TODO [#2983]: should we support `extends`?
|
|
6165
|
+
throw new DOMException('NotSupportedError: "extends" key in customElements.define() options is not supported.');
|
|
6166
|
+
}
|
|
6167
|
+
if (globalDefinitionsByTag.has(tagName)) {
|
|
6168
|
+
throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': the name "${tagName}" has already been used with this registry`);
|
|
6169
|
+
}
|
|
6170
|
+
if (!isUndefined$1(globalDefinitionsByClass.get(constructor))) {
|
|
6171
|
+
throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': this constructor has already been used with this registry`);
|
|
6172
|
+
}
|
|
6173
|
+
const definition = getOrCreateDefinitionForConstructor(constructor);
|
|
6174
|
+
registeredUserCtors.add(constructor);
|
|
6175
|
+
let PivotCtor = pivotCtorByTag.get(tagName);
|
|
6176
|
+
if (isUndefined$1(PivotCtor)) {
|
|
6177
|
+
PivotCtor = createPivotingClass(tagName, definition);
|
|
6178
|
+
// Register a pivoting class which will handle global registry initializations
|
|
6179
|
+
nativeDefine.call(nativeRegistry, tagName, PivotCtor);
|
|
6180
|
+
}
|
|
6181
|
+
// Only cache after nativeDefine has been called, because if it throws an error
|
|
6182
|
+
// (e.g. for an invalid tag name), then we don't want to cache anything.
|
|
6183
|
+
definitionForConstructor.set(constructor, definition);
|
|
6184
|
+
pivotCtorByTag.set(tagName, PivotCtor);
|
|
6185
|
+
globalDefinitionsByTag.set(tagName, definition);
|
|
6186
|
+
globalDefinitionsByClass.set(constructor, definition);
|
|
6187
|
+
// For globally defined custom elements, the definition associated
|
|
6188
|
+
// to the UserCtor has a back-pointer to PivotCtor in case the user
|
|
6189
|
+
// new the UserCtor, so we know how to create the underlying element.
|
|
6190
|
+
definition.PivotCtor = PivotCtor;
|
|
6191
|
+
// Upgrade any elements created in this scope before customElements.define
|
|
6192
|
+
// was called, which should be exhibited by the following steps:
|
|
6193
|
+
// 1) LWC registers a tagName for an LWC component.
|
|
6194
|
+
// 2) Element with same tagName is created with document.createElement()
|
|
6195
|
+
// and inserted into DOM.
|
|
6196
|
+
// 3) customElements.define() is called with tagName and non-LWC constructor.
|
|
6197
|
+
// This requires immediate upgrade when the new global tagName is defined.
|
|
6198
|
+
const awaiting = awaitingUpgrade.get(tagName);
|
|
6199
|
+
if (!isUndefined$1(awaiting)) {
|
|
6200
|
+
awaitingUpgrade.delete(tagName);
|
|
6201
|
+
for (const element of awaiting) {
|
|
6202
|
+
const registeredDefinition = pendingRegistryForElement.get(element);
|
|
6203
|
+
// At this point, registeredDefinition should never be undefined because awaitingUpgrade
|
|
6204
|
+
// is only populated when we haven't run internalUpgrade yet, and we only populate
|
|
6205
|
+
// pendingRegistryForElement when internalUpgrade hasn't run yet.
|
|
6206
|
+
// But just to be safe, we check.
|
|
6207
|
+
if (!isUndefined$1(registeredDefinition)) {
|
|
6208
|
+
pendingRegistryForElement.delete(element);
|
|
6209
|
+
internalUpgrade(element, registeredDefinition, definition);
|
|
6210
|
+
}
|
|
6211
|
+
}
|
|
6212
|
+
}
|
|
6213
|
+
};
|
|
6214
|
+
CustomElementRegistry.prototype.get = function get(tagName) {
|
|
6215
|
+
const NativeCtor = nativeGet.call(nativeRegistry, tagName);
|
|
6216
|
+
if (!isUndefined$1(NativeCtor)) {
|
|
6217
|
+
const definition = globalDefinitionsByTag.get(tagName);
|
|
6218
|
+
if (!isUndefined$1(definition)) {
|
|
6219
|
+
return definition.UserCtor; // defined by the patched custom elements registry
|
|
6220
|
+
}
|
|
6221
|
+
// TODO [#3073]: return undefined rather than the pivot constructor (NativeCtor)
|
|
6222
|
+
return NativeCtor; // return the pivot constructor or constructor that existed before patching
|
|
6223
|
+
}
|
|
6224
|
+
};
|
|
6225
|
+
CustomElementRegistry.prototype.whenDefined = function whenDefined(tagName) {
|
|
6226
|
+
return nativeWhenDefined.call(nativeRegistry, tagName).then((NativeCtor) => {
|
|
6227
|
+
const definition = globalDefinitionsByTag.get(tagName);
|
|
6228
|
+
if (!isUndefined$1(definition)) {
|
|
6229
|
+
return definition.UserCtor;
|
|
6230
|
+
}
|
|
6231
|
+
// TODO [#3073]: return undefined rather than the pivot constructor (NativeCtor)
|
|
6232
|
+
// In this case, the custom element must have been defined before the registry patches
|
|
6233
|
+
// were applied. So return the non-pivot constructor
|
|
6234
|
+
if (isUndefined$1(NativeCtor)) {
|
|
6235
|
+
// Chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1335247
|
|
6236
|
+
// We can patch the correct behavior using customElements.get()
|
|
6237
|
+
return nativeGet.call(nativeRegistry, tagName);
|
|
6238
|
+
}
|
|
6239
|
+
return NativeCtor;
|
|
6240
|
+
});
|
|
6241
|
+
};
|
|
6242
|
+
// This constructor is invoked when we call `new pivotDefinition.UserCtor()`
|
|
6243
|
+
// @ts-ignore
|
|
6244
|
+
window.HTMLElement = function HTMLElement() {
|
|
6245
|
+
// Upgrading case: the pivoting class constructor was run by the browser's
|
|
6246
|
+
// native custom elements and we're in the process of running the
|
|
6247
|
+
// "constructor-call trick" on the natively constructed instance, so just
|
|
6248
|
+
// return that here.
|
|
6249
|
+
// This code path is also called when LWC `new`s a PivotCtor.
|
|
6250
|
+
const instance = upgradingInstance;
|
|
6251
|
+
if (!isUndefined$1(instance)) {
|
|
6252
|
+
upgradingInstance = undefined;
|
|
6253
|
+
return instance;
|
|
6254
|
+
}
|
|
6255
|
+
// Construction case: we need to construct the pivoting instance and return it.
|
|
6256
|
+
// This is possible when the user register it via global registry and instantiate
|
|
6257
|
+
// it via `new Ctor()`.
|
|
6258
|
+
const { constructor } = this;
|
|
6259
|
+
const definition = globalDefinitionsByClass.get(constructor);
|
|
6260
|
+
if (isUndefined$1(definition) || isUndefined$1(definition.PivotCtor)) {
|
|
6261
|
+
// This code path is hit if someone `new`s a class that extends `HTMLElement` without
|
|
6262
|
+
// doing `customElements.define()` first. This matches native browser behavior:
|
|
6263
|
+
// https://stackoverflow.com/a/61883392
|
|
6264
|
+
throw new TypeError('Illegal constructor');
|
|
6265
|
+
}
|
|
6266
|
+
// This constructor is ONLY invoked when it is the user instantiating
|
|
6267
|
+
// an element via new Ctor while Ctor is a registered global constructor.
|
|
6268
|
+
const { PivotCtor, UserCtor } = definition;
|
|
6269
|
+
return new PivotCtor(UserCtor);
|
|
6270
|
+
};
|
|
6271
|
+
HTMLElement.prototype = NativeHTMLElement.prototype;
|
|
6272
|
+
/**
|
|
6273
|
+
* Create a new PivotConstructor for the given tagName, which is capable of being constructed
|
|
6274
|
+
* with a UserConstructor defining the behavior. Passing in the UserConstructor here
|
|
6275
|
+
* is a hint that can be used when registering a custom element with the global custom elements
|
|
6276
|
+
* registry for the first time, which provides certain optimizations. It also marks the UserConstructor
|
|
6277
|
+
* as "safe" to be used when passed in to a PivotConstructor.
|
|
6278
|
+
*
|
|
6279
|
+
* @param tagName - element tag name
|
|
6280
|
+
* @param UserCtor - userland custom element constructor
|
|
6281
|
+
* @returns a new custom element constructor
|
|
6282
|
+
*/
|
|
6283
|
+
return function createPivotConstructor(tagName, UserCtor) {
|
|
6284
|
+
tagName = StringToLowerCase.call(tagName);
|
|
6285
|
+
let PivotCtor = pivotCtorByTag.get(tagName);
|
|
6286
|
+
if (isUndefined$1(PivotCtor)) {
|
|
6287
|
+
const definition = getOrCreateDefinitionForConstructor(UserCtor);
|
|
6288
|
+
PivotCtor = createPivotingClass(tagName, definition);
|
|
6289
|
+
// Register a pivoting class as a global custom element
|
|
6290
|
+
nativeDefine.call(nativeRegistry, tagName, PivotCtor);
|
|
6291
|
+
definition.PivotCtor = PivotCtor;
|
|
6292
|
+
// Only cache after nativeDefine has been called, because if it throws an error
|
|
6293
|
+
// (e.g. for an invalid tag name), then we don't want to cache anything.
|
|
6294
|
+
definitionForConstructor.set(UserCtor, definition);
|
|
6295
|
+
pivotCtorByTag.set(tagName, PivotCtor);
|
|
6296
|
+
}
|
|
6297
|
+
// Register a UserConstructor as "safe" to be used within a PivotConstructor
|
|
6298
|
+
registeredUserCtors.add(UserCtor);
|
|
6299
|
+
return PivotCtor;
|
|
6300
|
+
};
|
|
6301
|
+
}
|
|
6302
|
+
|
|
6303
|
+
/*
|
|
6304
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
6305
|
+
* All rights reserved.
|
|
6306
|
+
* SPDX-License-Identifier: MIT
|
|
6307
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6308
|
+
*/
|
|
6309
|
+
let createScopedConstructor;
|
|
6310
|
+
let CachedHTMLElement; // We only call `createScopedRegistry()` if the browser supports custom elements and
|
|
6311
|
+
// ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is enabled, because we don't want to patch eagerly if the flag is disabled
|
|
6312
|
+
// or we're in a legacy browser.
|
|
6313
|
+
|
|
6314
|
+
if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
|
|
6315
|
+
if (hasCustomElements) {
|
|
6316
|
+
// If ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is true, then we eagerly initialize the scoped registry.
|
|
6317
|
+
// It's assumed that ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is set *before* LWC loads, and never changes.
|
|
6318
|
+
//
|
|
6319
|
+
// Why not lazily patch in `createCustomElement`? Well, this could lead to subtle bugs, e.g.:
|
|
6320
|
+
//
|
|
6321
|
+
// 1. LWC loads
|
|
6322
|
+
// 2. `const Ctor = class extends HTMLElement {}`
|
|
6323
|
+
// 3. `lwc.createElement(...)` // here we lazily patch
|
|
6324
|
+
// 4. `customElements.define('x-foo', Ctor)` // throws error because class is bound to stale HTMLElement
|
|
6325
|
+
//
|
|
6326
|
+
// To reduce the risk of this, it's safer to patch the registry eagerly.
|
|
6327
|
+
createScopedConstructor = createScopedRegistry(); // It's important to cache window.HTMLElement here. Otherwise, someone else could overwrite window.HTMLElement (e.g.
|
|
6328
|
+
// another copy of the engine, or another scoping implementation) and we would get "Illegal constructor" errors
|
|
6329
|
+
// because the HTMLElement prototypes are mixed up.
|
|
6330
|
+
//
|
|
6331
|
+
// The reason this happens is that the scoping implementation overwrites window.HTMLElement and expects to work
|
|
6332
|
+
// with that version of HTMLElement. So if you load two copies of the scoping implementation in the same environment,
|
|
6333
|
+
// the second one may accidentally grab window.HTMLElement from the first (when doing `class extends HTMLElement`).
|
|
6334
|
+
// Caching avoids this problem.
|
|
6335
|
+
|
|
6336
|
+
CachedHTMLElement = window.HTMLElement;
|
|
6337
|
+
}
|
|
6338
|
+
} // Creates a constructor that is intended to be used as the UserConstructor in a scoped (pivots) registry.
|
|
6339
|
+
// In this case, the upgradeCallback only needs to be defined once because we create these on-demand,
|
|
6340
|
+
// multiple times per tag name.
|
|
6341
|
+
|
|
6342
|
+
|
|
6343
|
+
const createUserConstructor = (upgradeCallback, connectedCallback, disconnectedCallback, HTMLElementToExtend) => {
|
|
6344
|
+
// TODO [#2972]: this class should expose observedAttributes as necessary
|
|
6345
|
+
return class UserConstructor extends HTMLElementToExtend {
|
|
6346
|
+
constructor() {
|
|
6347
|
+
super();
|
|
6348
|
+
upgradeCallback(this);
|
|
6349
|
+
}
|
|
6350
|
+
|
|
6351
|
+
connectedCallback() {
|
|
6352
|
+
connectedCallback(this);
|
|
6353
|
+
}
|
|
6354
|
+
|
|
6355
|
+
disconnectedCallback() {
|
|
6356
|
+
disconnectedCallback(this);
|
|
6357
|
+
}
|
|
6358
|
+
|
|
6359
|
+
};
|
|
6360
|
+
};
|
|
6361
|
+
|
|
6362
|
+
function createCustomElementScoped(tagName, upgradeCallback, connectedCallback, disconnectedCallback) {
|
|
6363
|
+
if (isUndefined$1(createScopedConstructor) || isUndefined$1(CachedHTMLElement)) {
|
|
6364
|
+
// This error should be impossible to hit
|
|
6365
|
+
throw new Error('The flag ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY must be set to true to use this feature');
|
|
6366
|
+
}
|
|
6367
|
+
|
|
6368
|
+
const UserConstructor = createUserConstructor(upgradeCallback, connectedCallback, disconnectedCallback, CachedHTMLElement);
|
|
6369
|
+
const ScopedConstructor = createScopedConstructor(tagName, UserConstructor);
|
|
6370
|
+
return new ScopedConstructor(UserConstructor);
|
|
6371
|
+
}
|
|
6372
|
+
|
|
6373
|
+
/*
|
|
6374
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
6375
|
+
* All rights reserved.
|
|
6376
|
+
* SPDX-License-Identifier: MIT
|
|
6377
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6378
|
+
*/
|
|
6379
|
+
/**
|
|
6380
|
+
* We have three modes for creating custom elements:
|
|
6381
|
+
*
|
|
6382
|
+
* 1. Compat (legacy) browser support (e.g. IE11). Totally custom, doesn't rely on native browser APIs.
|
|
6383
|
+
* 2. "Vanilla" custom elements registry. This system actually still allows us to have two LWC components with the
|
|
6384
|
+
* same tag name, via a simple trick: every custom element constructor we define in the registry is basically
|
|
6385
|
+
* the same. It's essentially a dummy `class extends HTMLElement` that accepts an `upgradeCallback` in its
|
|
6386
|
+
* constructor, which allows us to have completely customized functionality for different components.
|
|
6387
|
+
* 3. "Scoped" (or "pivot") custom elements. This relies on a sophisticated system that emulates the "scoped custom
|
|
6388
|
+
* elements registry" proposal, with support for avoiding conflicts in tag names both between LWC components and
|
|
6389
|
+
* between LWC components and third-party elements. This uses a similar trick to #2, but is much more complex
|
|
6390
|
+
* because it must patch the global `customElements` and `HTMLElement` objects.
|
|
6391
|
+
*/
|
|
6392
|
+
|
|
6393
|
+
let createCustomElement;
|
|
6394
|
+
|
|
6395
|
+
if (hasCustomElements) {
|
|
6396
|
+
if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
|
|
6397
|
+
createCustomElement = createCustomElementScoped;
|
|
6398
|
+
} else {
|
|
6399
|
+
// use global custom elements registry (vanilla)
|
|
6400
|
+
createCustomElement = createCustomElementVanilla;
|
|
6401
|
+
}
|
|
6402
|
+
} else {
|
|
6403
|
+
// no registry available here
|
|
6404
|
+
createCustomElement = createCustomElementCompat;
|
|
6405
|
+
}
|
|
6406
|
+
|
|
5745
6407
|
/*
|
|
5746
6408
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
5747
6409
|
* All rights reserved.
|
|
@@ -5802,7 +6464,7 @@
|
|
|
5802
6464
|
function isNull(obj) {
|
|
5803
6465
|
return obj === null;
|
|
5804
6466
|
}
|
|
5805
|
-
/** version: 2.
|
|
6467
|
+
/** version: 2.26.0 */
|
|
5806
6468
|
|
|
5807
6469
|
/*
|
|
5808
6470
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -5810,65 +6472,6 @@
|
|
|
5810
6472
|
* SPDX-License-Identifier: MIT
|
|
5811
6473
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5812
6474
|
*/
|
|
5813
|
-
exports.getCustomElement = void 0;
|
|
5814
|
-
exports.defineCustomElement = void 0;
|
|
5815
|
-
let HTMLElementConstructor;
|
|
5816
|
-
function isCustomElementRegistryAvailable() {
|
|
5817
|
-
if (typeof customElements === 'undefined') {
|
|
5818
|
-
return false;
|
|
5819
|
-
}
|
|
5820
|
-
try {
|
|
5821
|
-
// dereference HTMLElement global because babel wraps globals in compat mode with a
|
|
5822
|
-
// _wrapNativeSuper()
|
|
5823
|
-
// This is a problem because LWCUpgradableElement extends renderer.HTMLElementExported which does not
|
|
5824
|
-
// get wrapped by babel.
|
|
5825
|
-
const HTMLElementAlias = HTMLElement;
|
|
5826
|
-
// In case we use compat mode with a modern browser, the compat mode transformation
|
|
5827
|
-
// invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
|
|
5828
|
-
// which are not equipped to be initialized that way.
|
|
5829
|
-
class clazz extends HTMLElementAlias {
|
|
5830
|
-
}
|
|
5831
|
-
customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
|
|
5832
|
-
new clazz();
|
|
5833
|
-
return true;
|
|
5834
|
-
}
|
|
5835
|
-
catch (_a) {
|
|
5836
|
-
return false;
|
|
5837
|
-
}
|
|
5838
|
-
}
|
|
5839
|
-
if (isCustomElementRegistryAvailable()) {
|
|
5840
|
-
exports.getCustomElement = customElements.get.bind(customElements);
|
|
5841
|
-
exports.defineCustomElement = customElements.define.bind(customElements);
|
|
5842
|
-
HTMLElementConstructor = HTMLElement;
|
|
5843
|
-
}
|
|
5844
|
-
else {
|
|
5845
|
-
const registry = Object.create(null);
|
|
5846
|
-
const reverseRegistry = new WeakMap();
|
|
5847
|
-
exports.defineCustomElement = function define(name, ctor) {
|
|
5848
|
-
if (name !== String.prototype.toLowerCase.call(name) || registry[name]) {
|
|
5849
|
-
throw new TypeError(`Invalid Registration`);
|
|
5850
|
-
}
|
|
5851
|
-
registry[name] = ctor;
|
|
5852
|
-
reverseRegistry.set(ctor, name);
|
|
5853
|
-
};
|
|
5854
|
-
exports.getCustomElement = function get(name) {
|
|
5855
|
-
return registry[name];
|
|
5856
|
-
};
|
|
5857
|
-
HTMLElementConstructor = function HTMLElement() {
|
|
5858
|
-
if (!(this instanceof HTMLElement)) {
|
|
5859
|
-
throw new TypeError(`Invalid Invocation`);
|
|
5860
|
-
}
|
|
5861
|
-
const { constructor } = this;
|
|
5862
|
-
const name = reverseRegistry.get(constructor);
|
|
5863
|
-
if (!name) {
|
|
5864
|
-
throw new TypeError(`Invalid Construction`);
|
|
5865
|
-
}
|
|
5866
|
-
const elm = document.createElement(name);
|
|
5867
|
-
Object.setPrototypeOf(elm, constructor.prototype);
|
|
5868
|
-
return elm;
|
|
5869
|
-
};
|
|
5870
|
-
HTMLElementConstructor.prototype = HTMLElement.prototype;
|
|
5871
|
-
}
|
|
5872
6475
|
function cloneNode(node, deep) {
|
|
5873
6476
|
return node.cloneNode(deep);
|
|
5874
6477
|
}
|
|
@@ -6042,9 +6645,7 @@
|
|
|
6042
6645
|
function assertInstanceOfHTMLElement(elm, msg) {
|
|
6043
6646
|
assert.invariant(elm instanceof HTMLElement, msg);
|
|
6044
6647
|
}
|
|
6045
|
-
const HTMLElementExported = HTMLElementConstructor;
|
|
6046
6648
|
|
|
6047
|
-
exports.HTMLElementExported = HTMLElementExported;
|
|
6048
6649
|
exports.addEventListener = addEventListener;
|
|
6049
6650
|
exports.assertInstanceOfHTMLElement = assertInstanceOfHTMLElement;
|
|
6050
6651
|
exports.attachShadow = attachShadow;
|
|
@@ -6104,6 +6705,8 @@
|
|
|
6104
6705
|
{
|
|
6105
6706
|
// insertStyleSheet implementation shares a global cache of stylesheet data
|
|
6106
6707
|
insertStylesheet,
|
|
6708
|
+
// relies on a shared global cache
|
|
6709
|
+
createCustomElement,
|
|
6107
6710
|
isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
|
|
6108
6711
|
isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
|
|
6109
6712
|
});
|
|
@@ -6199,36 +6802,44 @@
|
|
|
6199
6802
|
// This WeakSet usage is valid because this functionality is not meant to run in IE11.
|
|
6200
6803
|
const hydratedCustomElements = new WeakSet();
|
|
6201
6804
|
function buildCustomElementConstructor(Ctor) {
|
|
6805
|
+
var _a;
|
|
6202
6806
|
const HtmlPrototype = getComponentHtmlPrototype(Ctor);
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6807
|
+
const { observedAttributes } = HtmlPrototype;
|
|
6808
|
+
const { attributeChangedCallback } = HtmlPrototype.prototype;
|
|
6809
|
+
return _a = class extends HTMLElement {
|
|
6810
|
+
constructor() {
|
|
6811
|
+
super();
|
|
6812
|
+
if (this.isConnected) {
|
|
6813
|
+
// this if block is hit when there's already an un-upgraded element in the DOM with the same tag name.
|
|
6814
|
+
hydrateComponent(this, Ctor, {});
|
|
6815
|
+
hydratedCustomElements.add(this);
|
|
6816
|
+
}
|
|
6817
|
+
else {
|
|
6818
|
+
createVM(this, Ctor, renderer, {
|
|
6819
|
+
mode: 'open',
|
|
6820
|
+
owner: null,
|
|
6821
|
+
tagName: this.tagName,
|
|
6822
|
+
});
|
|
6823
|
+
}
|
|
6210
6824
|
}
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6825
|
+
connectedCallback() {
|
|
6826
|
+
if (hydratedCustomElements.has(this)) {
|
|
6827
|
+
// This is an un-upgraded element that was hydrated in the constructor.
|
|
6828
|
+
hydratedCustomElements.delete(this);
|
|
6829
|
+
}
|
|
6830
|
+
else {
|
|
6831
|
+
connectRootElement(this);
|
|
6832
|
+
}
|
|
6217
6833
|
}
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
if (hydratedCustomElements.has(this)) {
|
|
6221
|
-
// This is an un-upgraded element that was hydrated in the constructor.
|
|
6222
|
-
hydratedCustomElements.delete(this);
|
|
6834
|
+
disconnectedCallback() {
|
|
6835
|
+
disconnectRootElement(this);
|
|
6223
6836
|
}
|
|
6224
|
-
|
|
6225
|
-
|
|
6837
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
6838
|
+
attributeChangedCallback.call(this, name, oldValue, newValue);
|
|
6226
6839
|
}
|
|
6227
|
-
}
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
}
|
|
6231
|
-
};
|
|
6840
|
+
},
|
|
6841
|
+
_a.observedAttributes = observedAttributes,
|
|
6842
|
+
_a;
|
|
6232
6843
|
}
|
|
6233
6844
|
|
|
6234
6845
|
/*
|
|
@@ -6312,8 +6923,13 @@
|
|
|
6312
6923
|
throw new TypeError(`"createElement" function expects an "is" option with a valid component constructor.`);
|
|
6313
6924
|
}
|
|
6314
6925
|
|
|
6315
|
-
const
|
|
6316
|
-
|
|
6926
|
+
const {
|
|
6927
|
+
createCustomElement
|
|
6928
|
+
} = renderer; // tagName must be all lowercase, unfortunately, we have legacy code that is
|
|
6929
|
+
// passing `sel` as a camel-case, which makes them invalid custom elements name
|
|
6930
|
+
// the following line guarantees that this does not leaks beyond this point.
|
|
6931
|
+
|
|
6932
|
+
const tagName = StringToLowerCase.call(sel); // the custom element from the registry is expecting an upgrade callback
|
|
6317
6933
|
|
|
6318
6934
|
/**
|
|
6319
6935
|
* Note: if the upgradable constructor does not expect, or throw when we new it
|
|
@@ -6322,9 +6938,9 @@
|
|
|
6322
6938
|
* an upgradable custom element.
|
|
6323
6939
|
*/
|
|
6324
6940
|
|
|
6325
|
-
const
|
|
6941
|
+
const upgradeCallback = elm => {
|
|
6326
6942
|
createVM(elm, Ctor, renderer, {
|
|
6327
|
-
tagName
|
|
6943
|
+
tagName,
|
|
6328
6944
|
mode: options.mode !== 'closed' ? 'open' : 'closed',
|
|
6329
6945
|
owner: null
|
|
6330
6946
|
});
|
|
@@ -6333,15 +6949,21 @@
|
|
|
6333
6949
|
ConnectingSlot.set(elm, connectRootElement);
|
|
6334
6950
|
DisconnectingSlot.set(elm, disconnectRootElement);
|
|
6335
6951
|
}
|
|
6952
|
+
};
|
|
6336
6953
|
|
|
6337
|
-
|
|
6338
|
-
|
|
6954
|
+
const connectedCallback = elm => {
|
|
6955
|
+
if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
|
|
6956
|
+
connectRootElement(elm);
|
|
6957
|
+
}
|
|
6958
|
+
};
|
|
6339
6959
|
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6960
|
+
const disconnectedCallback = elm => {
|
|
6961
|
+
if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
|
|
6962
|
+
disconnectRootElement(elm);
|
|
6963
|
+
}
|
|
6964
|
+
};
|
|
6344
6965
|
|
|
6966
|
+
const element = createCustomElement(tagName, upgradeCallback, connectedCallback, disconnectedCallback);
|
|
6345
6967
|
return element;
|
|
6346
6968
|
}
|
|
6347
6969
|
|
|
@@ -6413,7 +7035,7 @@
|
|
|
6413
7035
|
});
|
|
6414
7036
|
freeze(LightningElement);
|
|
6415
7037
|
seal(LightningElement.prototype);
|
|
6416
|
-
/* version: 2.
|
|
7038
|
+
/* version: 2.26.0 */
|
|
6417
7039
|
|
|
6418
7040
|
exports.LightningElement = LightningElement;
|
|
6419
7041
|
exports.__unstable__ProfilerControl = profilerControl;
|