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.
Files changed (35) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +1103 -533
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +1103 -533
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +942 -320
  5. package/dist/engine-dom/iife/es5/engine-dom.js +966 -312
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +895 -225
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +1103 -533
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +942 -320
  11. package/dist/engine-dom/umd/es5/engine-dom.js +966 -312
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +895 -225
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +331 -339
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +331 -339
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  20. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
  22. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  23. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  24. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
  26. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  27. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  28. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  29. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  30. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  31. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  34. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  35. package/package.json +7 -7
@@ -299,9 +299,9 @@ function htmlPropertyToAttribute(propName) {
299
299
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
300
300
  */
301
301
  // Increment whenever the LWC template compiler changes
302
- const LWC_VERSION = "2.25.0";
302
+ const LWC_VERSION = "2.26.0";
303
303
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
304
- /** version: 2.25.0 */
304
+ /** version: 2.26.0 */
305
305
 
306
306
  /**
307
307
  * Copyright (C) 2018 salesforce.com, inc.
@@ -383,7 +383,7 @@ for (let i = 0, len = ElementPrototypeAriaPropertyNames.length; i < len; i += 1)
383
383
  patch$1(propName);
384
384
  }
385
385
  }
386
- /** version: 2.25.0 */
386
+ /** version: 2.26.0 */
387
387
 
388
388
  /**
389
389
  * Copyright (C) 2018 salesforce.com, inc.
@@ -399,7 +399,6 @@ const features = {
399
399
  DUMMY_TEST_FLAG: null,
400
400
  ENABLE_ELEMENT_PATCH: null,
401
401
  ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST: null,
402
- ENABLE_HMR: null,
403
402
  ENABLE_HTML_COLLECTIONS_PATCH: null,
404
403
  ENABLE_INNER_OUTER_TEXT_PATCH: null,
405
404
  ENABLE_MIXED_SHADOW_MODE: null,
@@ -409,6 +408,8 @@ const features = {
409
408
  ENABLE_REACTIVE_SETTER: null,
410
409
  ENABLE_WIRE_SYNC_EMIT: null,
411
410
  ENABLE_LIGHT_GET_ROOT_NODE_PATCH: null,
411
+ DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
412
+ ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
412
413
  };
413
414
  if (!_globalThis.lwcRuntimeFlags) {
414
415
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -462,7 +463,7 @@ function setFeatureFlagForTest(name, value) {
462
463
  setFeatureFlag(name, value);
463
464
  }
464
465
  }
465
- /** version: 2.25.0 */
466
+ /** version: 2.26.0 */
466
467
 
467
468
  /*
468
469
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1936,7 +1937,9 @@ const refsCache = new WeakMap();
1936
1937
  const LightningElement = function () {
1937
1938
  // This should be as performant as possible, while any initialization should be done lazily
1938
1939
  if (isNull(vmBeingConstructed)) {
1939
- throw new ReferenceError('Illegal constructor');
1940
+ // Thrown when doing something like `new LightningElement()` or
1941
+ // `class Foo extends LightningElement {}; new Foo()`
1942
+ throw new TypeError('Illegal constructor');
1940
1943
  }
1941
1944
  const vm = vmBeingConstructed;
1942
1945
  const { def, elm } = vm;
@@ -2985,274 +2988,213 @@ const swappedStyleMap = new WeakMap();
2985
2988
  const activeTemplates = new WeakMap();
2986
2989
  const activeComponents = new WeakMap();
2987
2990
  const activeStyles = new WeakMap();
2988
-
2989
2991
  function rehydrateHotTemplate(tpl) {
2990
- const list = activeTemplates.get(tpl);
2991
-
2992
- if (!isUndefined$1(list)) {
2993
- list.forEach(vm => {
2994
- if (isFalse(vm.isDirty)) {
2995
- // forcing the vm to rehydrate in the micro-task:
2996
- markComponentAsDirty(vm);
2997
- scheduleRehydration(vm);
2998
- }
2999
- }); // resetting the Set to release the memory of those vm references
3000
- // since they are not longer related to this template, instead
3001
- // they will get re-associated once these instances are rehydrated.
3002
-
3003
- list.clear();
3004
- }
3005
-
3006
- return true;
2992
+ const list = activeTemplates.get(tpl);
2993
+ if (!isUndefined$1(list)) {
2994
+ list.forEach((vm) => {
2995
+ if (isFalse(vm.isDirty)) {
2996
+ // forcing the vm to rehydrate in the micro-task:
2997
+ markComponentAsDirty(vm);
2998
+ scheduleRehydration(vm);
2999
+ }
3000
+ });
3001
+ // resetting the Set to release the memory of those vm references
3002
+ // since they are not longer related to this template, instead
3003
+ // they will get re-associated once these instances are rehydrated.
3004
+ list.clear();
3005
+ }
3006
+ return true;
3007
3007
  }
3008
-
3009
3008
  function rehydrateHotStyle(style) {
3010
- const list = activeStyles.get(style);
3011
-
3012
- if (!isUndefined$1(list)) {
3013
- list.forEach(vm => {
3014
- // if a style definition is swapped, we must reset
3015
- // vm's template content in the next micro-task:
3016
- forceRehydration(vm);
3017
- }); // resetting the Set to release the memory of those vm references
3018
- // since they are not longer related to this style, instead
3019
- // they will get re-associated once these instances are rehydrated.
3020
-
3021
- list.clear();
3022
- }
3023
-
3024
- return true;
3009
+ const list = activeStyles.get(style);
3010
+ if (!isUndefined$1(list)) {
3011
+ list.forEach((vm) => {
3012
+ // if a style definition is swapped, we must reset
3013
+ // vm's template content in the next micro-task:
3014
+ forceRehydration(vm);
3015
+ });
3016
+ // resetting the Set to release the memory of those vm references
3017
+ // since they are not longer related to this style, instead
3018
+ // they will get re-associated once these instances are rehydrated.
3019
+ list.clear();
3020
+ }
3021
+ return true;
3025
3022
  }
3026
-
3027
3023
  function rehydrateHotComponent(Ctor) {
3028
- const list = activeComponents.get(Ctor);
3029
- let canRefreshAllInstances = true;
3030
-
3031
- if (!isUndefined$1(list)) {
3032
- list.forEach(vm => {
3033
- const {
3034
- owner
3035
- } = vm;
3036
-
3037
- if (!isNull(owner)) {
3038
- // if a component class definition is swapped, we must reset
3039
- // owner's template content in the next micro-task:
3040
- forceRehydration(owner);
3041
- } else {
3042
- // the hot swapping for components only work for instances of components
3043
- // created from a template, root elements can't be swapped because we
3044
- // don't have a way to force the creation of the element with the same state
3045
- // of the current element.
3046
- // Instead, we can report the problem to the caller so it can take action,
3047
- // for example: reload the entire page.
3048
- canRefreshAllInstances = false;
3049
- }
3050
- }); // resetting the Set to release the memory of those vm references
3051
- // since they are not longer related to this constructor, instead
3052
- // they will get re-associated once these instances are rehydrated.
3053
-
3054
- list.clear();
3055
- }
3056
-
3057
- return canRefreshAllInstances;
3024
+ const list = activeComponents.get(Ctor);
3025
+ let canRefreshAllInstances = true;
3026
+ if (!isUndefined$1(list)) {
3027
+ list.forEach((vm) => {
3028
+ const { owner } = vm;
3029
+ if (!isNull(owner)) {
3030
+ // if a component class definition is swapped, we must reset
3031
+ // owner's template content in the next micro-task:
3032
+ forceRehydration(owner);
3033
+ }
3034
+ else {
3035
+ // the hot swapping for components only work for instances of components
3036
+ // created from a template, root elements can't be swapped because we
3037
+ // don't have a way to force the creation of the element with the same state
3038
+ // of the current element.
3039
+ // Instead, we can report the problem to the caller so it can take action,
3040
+ // for example: reload the entire page.
3041
+ canRefreshAllInstances = false;
3042
+ }
3043
+ });
3044
+ // resetting the Set to release the memory of those vm references
3045
+ // since they are not longer related to this constructor, instead
3046
+ // they will get re-associated once these instances are rehydrated.
3047
+ list.clear();
3048
+ }
3049
+ return canRefreshAllInstances;
3058
3050
  }
3059
-
3060
3051
  function getTemplateOrSwappedTemplate(tpl) {
3061
- if (process.env.NODE_ENV === 'production') {
3062
- // this method should never leak to prod
3063
- throw new ReferenceError();
3064
- }
3065
-
3066
- if (lwcRuntimeFlags.ENABLE_HMR) {
3052
+ if (process.env.NODE_ENV === 'production') {
3053
+ // this method should never leak to prod
3054
+ throw new ReferenceError();
3055
+ }
3067
3056
  const visited = new Set();
3068
-
3069
3057
  while (swappedTemplateMap.has(tpl) && !visited.has(tpl)) {
3070
- visited.add(tpl);
3071
- tpl = swappedTemplateMap.get(tpl);
3058
+ visited.add(tpl);
3059
+ tpl = swappedTemplateMap.get(tpl);
3072
3060
  }
3073
- }
3074
-
3075
- return tpl;
3061
+ return tpl;
3076
3062
  }
3077
3063
  function getComponentOrSwappedComponent(Ctor) {
3078
- if (process.env.NODE_ENV === 'production') {
3079
- // this method should never leak to prod
3080
- throw new ReferenceError();
3081
- }
3082
-
3083
- if (lwcRuntimeFlags.ENABLE_HMR) {
3064
+ if (process.env.NODE_ENV === 'production') {
3065
+ // this method should never leak to prod
3066
+ throw new ReferenceError();
3067
+ }
3084
3068
  const visited = new Set();
3085
-
3086
3069
  while (swappedComponentMap.has(Ctor) && !visited.has(Ctor)) {
3087
- visited.add(Ctor);
3088
- Ctor = swappedComponentMap.get(Ctor);
3070
+ visited.add(Ctor);
3071
+ Ctor = swappedComponentMap.get(Ctor);
3089
3072
  }
3090
- }
3091
-
3092
- return Ctor;
3073
+ return Ctor;
3093
3074
  }
3094
3075
  function getStyleOrSwappedStyle(style) {
3095
- if (process.env.NODE_ENV === 'production') {
3096
- // this method should never leak to prod
3097
- throw new ReferenceError();
3098
- }
3099
-
3100
- if (lwcRuntimeFlags.ENABLE_HMR) {
3076
+ if (process.env.NODE_ENV === 'production') {
3077
+ // this method should never leak to prod
3078
+ throw new ReferenceError();
3079
+ }
3101
3080
  const visited = new Set();
3102
-
3103
3081
  while (swappedStyleMap.has(style) && !visited.has(style)) {
3104
- visited.add(style);
3105
- style = swappedStyleMap.get(style);
3082
+ visited.add(style);
3083
+ style = swappedStyleMap.get(style);
3106
3084
  }
3107
- }
3108
-
3109
- return style;
3085
+ return style;
3110
3086
  }
3111
3087
  function setActiveVM(vm) {
3112
- if (process.env.NODE_ENV === 'production') {
3113
- // this method should never leak to prod
3114
- throw new ReferenceError();
3115
- }
3116
-
3117
- if (lwcRuntimeFlags.ENABLE_HMR) {
3088
+ if (process.env.NODE_ENV === 'production') {
3089
+ // this method should never leak to prod
3090
+ throw new ReferenceError();
3091
+ }
3118
3092
  // tracking active component
3119
3093
  const Ctor = vm.def.ctor;
3120
3094
  let componentVMs = activeComponents.get(Ctor);
3121
-
3122
3095
  if (isUndefined$1(componentVMs)) {
3123
- componentVMs = new Set();
3124
- activeComponents.set(Ctor, componentVMs);
3125
- } // this will allow us to keep track of the hot components
3126
-
3127
-
3128
- componentVMs.add(vm); // tracking active template
3129
-
3096
+ componentVMs = new Set();
3097
+ activeComponents.set(Ctor, componentVMs);
3098
+ }
3099
+ // this will allow us to keep track of the hot components
3100
+ componentVMs.add(vm);
3101
+ // tracking active template
3130
3102
  const tpl = vm.cmpTemplate;
3131
-
3132
3103
  if (tpl) {
3133
- let templateVMs = activeTemplates.get(tpl);
3134
-
3135
- if (isUndefined$1(templateVMs)) {
3136
- templateVMs = new Set();
3137
- activeTemplates.set(tpl, templateVMs);
3138
- } // this will allow us to keep track of the templates that are
3139
- // being used by a hot component
3140
-
3141
-
3142
- templateVMs.add(vm); // tracking active styles associated to template
3143
-
3144
- const stylesheets = tpl.stylesheets;
3145
-
3146
- if (!isUndefined$1(stylesheets)) {
3147
- flattenStylesheets(stylesheets).forEach(stylesheet => {
3148
- // this is necessary because we don't hold the list of styles
3149
- // in the vm, we only hold the selected (already swapped template)
3150
- // but the styles attached to the template might not be the actual
3151
- // active ones, but the swapped versions of those.
3152
- stylesheet = getStyleOrSwappedStyle(stylesheet);
3153
- let stylesheetVMs = activeStyles.get(stylesheet);
3154
-
3155
- if (isUndefined$1(stylesheetVMs)) {
3156
- stylesheetVMs = new Set();
3157
- activeStyles.set(stylesheet, stylesheetVMs);
3158
- } // this will allow us to keep track of the stylesheet that are
3159
- // being used by a hot component
3160
-
3161
-
3162
- stylesheetVMs.add(vm);
3163
- });
3164
- }
3104
+ let templateVMs = activeTemplates.get(tpl);
3105
+ if (isUndefined$1(templateVMs)) {
3106
+ templateVMs = new Set();
3107
+ activeTemplates.set(tpl, templateVMs);
3108
+ }
3109
+ // this will allow us to keep track of the templates that are
3110
+ // being used by a hot component
3111
+ templateVMs.add(vm);
3112
+ // tracking active styles associated to template
3113
+ const stylesheets = tpl.stylesheets;
3114
+ if (!isUndefined$1(stylesheets)) {
3115
+ flattenStylesheets(stylesheets).forEach((stylesheet) => {
3116
+ // this is necessary because we don't hold the list of styles
3117
+ // in the vm, we only hold the selected (already swapped template)
3118
+ // but the styles attached to the template might not be the actual
3119
+ // active ones, but the swapped versions of those.
3120
+ stylesheet = getStyleOrSwappedStyle(stylesheet);
3121
+ let stylesheetVMs = activeStyles.get(stylesheet);
3122
+ if (isUndefined$1(stylesheetVMs)) {
3123
+ stylesheetVMs = new Set();
3124
+ activeStyles.set(stylesheet, stylesheetVMs);
3125
+ }
3126
+ // this will allow us to keep track of the stylesheet that are
3127
+ // being used by a hot component
3128
+ stylesheetVMs.add(vm);
3129
+ });
3130
+ }
3165
3131
  }
3166
- }
3167
3132
  }
3168
3133
  function removeActiveVM(vm) {
3169
- if (process.env.NODE_ENV === 'production') {
3170
- // this method should never leak to prod
3171
- throw new ReferenceError();
3172
- }
3173
-
3174
- if (lwcRuntimeFlags.ENABLE_HMR) {
3134
+ if (process.env.NODE_ENV === 'production') {
3135
+ // this method should never leak to prod
3136
+ throw new ReferenceError();
3137
+ }
3175
3138
  // tracking inactive component
3176
3139
  const Ctor = vm.def.ctor;
3177
3140
  let list = activeComponents.get(Ctor);
3178
-
3179
3141
  if (!isUndefined$1(list)) {
3180
- // deleting the vm from the set to avoid leaking memory
3181
- list.delete(vm);
3182
- } // removing inactive template
3183
-
3184
-
3185
- const tpl = vm.cmpTemplate;
3186
-
3187
- if (tpl) {
3188
- list = activeTemplates.get(tpl);
3189
-
3190
- if (!isUndefined$1(list)) {
3191
3142
  // deleting the vm from the set to avoid leaking memory
3192
3143
  list.delete(vm);
3193
- } // removing active styles associated to template
3194
-
3195
-
3196
- const styles = tpl.stylesheets;
3197
-
3198
- if (!isUndefined$1(styles)) {
3199
- flattenStylesheets(styles).forEach(style => {
3200
- list = activeStyles.get(style);
3201
-
3202
- if (!isUndefined$1(list)) {
3144
+ }
3145
+ // removing inactive template
3146
+ const tpl = vm.cmpTemplate;
3147
+ if (tpl) {
3148
+ list = activeTemplates.get(tpl);
3149
+ if (!isUndefined$1(list)) {
3203
3150
  // deleting the vm from the set to avoid leaking memory
3204
3151
  list.delete(vm);
3205
- }
3206
- });
3207
- }
3152
+ }
3153
+ // removing active styles associated to template
3154
+ const styles = tpl.stylesheets;
3155
+ if (!isUndefined$1(styles)) {
3156
+ flattenStylesheets(styles).forEach((style) => {
3157
+ list = activeStyles.get(style);
3158
+ if (!isUndefined$1(list)) {
3159
+ // deleting the vm from the set to avoid leaking memory
3160
+ list.delete(vm);
3161
+ }
3162
+ });
3163
+ }
3208
3164
  }
3209
- }
3210
3165
  }
3211
3166
  function swapTemplate(oldTpl, newTpl) {
3212
- if (process.env.NODE_ENV !== 'production') {
3213
- if (isTemplateRegistered(oldTpl) && isTemplateRegistered(newTpl)) {
3214
- swappedTemplateMap.set(oldTpl, newTpl);
3215
- return rehydrateHotTemplate(oldTpl);
3216
- } else {
3217
- throw new TypeError(`Invalid Template`);
3167
+ if (process.env.NODE_ENV !== 'production') {
3168
+ if (isTemplateRegistered(oldTpl) && isTemplateRegistered(newTpl)) {
3169
+ swappedTemplateMap.set(oldTpl, newTpl);
3170
+ return rehydrateHotTemplate(oldTpl);
3171
+ }
3172
+ else {
3173
+ throw new TypeError(`Invalid Template`);
3174
+ }
3218
3175
  }
3219
- }
3220
-
3221
- if (!lwcRuntimeFlags.ENABLE_HMR) {
3222
- throw new Error('HMR is not enabled');
3223
- }
3224
-
3225
- return false;
3176
+ return false;
3226
3177
  }
3227
3178
  function swapComponent(oldComponent, newComponent) {
3228
- if (process.env.NODE_ENV !== 'production') {
3229
- if (isComponentConstructor(oldComponent) && isComponentConstructor(newComponent)) {
3230
- swappedComponentMap.set(oldComponent, newComponent);
3231
- return rehydrateHotComponent(oldComponent);
3232
- } else {
3233
- throw new TypeError(`Invalid Component`);
3179
+ if (process.env.NODE_ENV !== 'production') {
3180
+ if (isComponentConstructor(oldComponent) && isComponentConstructor(newComponent)) {
3181
+ swappedComponentMap.set(oldComponent, newComponent);
3182
+ return rehydrateHotComponent(oldComponent);
3183
+ }
3184
+ else {
3185
+ throw new TypeError(`Invalid Component`);
3186
+ }
3234
3187
  }
3235
- }
3236
-
3237
- if (!lwcRuntimeFlags.ENABLE_HMR) {
3238
- throw new Error('HMR is not enabled');
3239
- }
3240
-
3241
- return false;
3188
+ return false;
3242
3189
  }
3243
3190
  function swapStyle(oldStyle, newStyle) {
3244
- if (process.env.NODE_ENV !== 'production') {
3245
- // TODO [#1887]: once the support for registering styles is implemented
3246
- // we can add the validation of both styles around this block.
3247
- swappedStyleMap.set(oldStyle, newStyle);
3248
- return rehydrateHotStyle(oldStyle);
3249
- }
3250
-
3251
- if (!lwcRuntimeFlags.ENABLE_HMR) {
3252
- throw new Error('HMR is not enabled');
3253
- }
3254
-
3255
- return false;
3191
+ if (process.env.NODE_ENV !== 'production') {
3192
+ // TODO [#1887]: once the support for registering styles is implemented
3193
+ // we can add the validation of both styles around this block.
3194
+ swappedStyleMap.set(oldStyle, newStyle);
3195
+ return rehydrateHotStyle(oldStyle);
3196
+ }
3197
+ return false;
3256
3198
  }
3257
3199
 
3258
3200
  /*
@@ -3459,244 +3401,273 @@ function getComponentDef(Ctor) {
3459
3401
  * SPDX-License-Identifier: MIT
3460
3402
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3461
3403
  */
3404
+
3462
3405
  function makeHostToken(token) {
3463
- return `${token}-host`;
3406
+ return `${token}-host`;
3464
3407
  }
3408
+
3465
3409
  function createInlineStyleVNode(content) {
3466
- return api.h('style', {
3467
- key: 'style',
3468
- attrs: {
3469
- type: 'text/css',
3470
- },
3471
- }, [api.t(content)]);
3410
+ return api.h('style', {
3411
+ key: 'style',
3412
+ attrs: {
3413
+ type: 'text/css'
3414
+ }
3415
+ }, [api.t(content)]);
3472
3416
  }
3417
+
3473
3418
  function updateStylesheetToken(vm, template) {
3474
- const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
3475
- const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
3476
- const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3477
- const { hasScopedStyles } = context;
3478
- let newToken;
3479
- let newHasTokenInClass;
3480
- let newHasTokenInAttribute;
3481
- // Reset the styling token applied to the host element.
3482
- const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
3483
- if (!isUndefined$1(oldToken)) {
3484
- if (oldHasTokenInClass) {
3485
- getClassList(elm).remove(makeHostToken(oldToken));
3486
- }
3487
- if (oldHasTokenInAttribute) {
3488
- removeAttribute(elm, makeHostToken(oldToken));
3489
- }
3490
- }
3491
- // Apply the new template styling token to the host element, if the new template has any
3492
- // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3493
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
3494
- newToken = newStylesheetToken;
3495
- }
3496
- // Set the new styling token on the host element
3497
- if (!isUndefined$1(newToken)) {
3498
- if (hasScopedStyles) {
3499
- getClassList(elm).add(makeHostToken(newToken));
3500
- newHasTokenInClass = true;
3501
- }
3502
- if (isSyntheticShadow) {
3503
- setAttribute(elm, makeHostToken(newToken), '');
3504
- newHasTokenInAttribute = true;
3505
- }
3506
- }
3507
- // Update the styling tokens present on the context object.
3508
- context.stylesheetToken = newToken;
3509
- context.hasTokenInClass = newHasTokenInClass;
3510
- context.hasTokenInAttribute = newHasTokenInAttribute;
3419
+ const {
3420
+ elm,
3421
+ context,
3422
+ renderMode,
3423
+ shadowMode,
3424
+ renderer: {
3425
+ getClassList,
3426
+ removeAttribute,
3427
+ setAttribute
3428
+ }
3429
+ } = vm;
3430
+ const {
3431
+ stylesheets: newStylesheets,
3432
+ stylesheetToken: newStylesheetToken
3433
+ } = template;
3434
+ const isSyntheticShadow = renderMode === 1
3435
+ /* RenderMode.Shadow */
3436
+ && shadowMode === 1
3437
+ /* ShadowMode.Synthetic */
3438
+ ;
3439
+ const {
3440
+ hasScopedStyles
3441
+ } = context;
3442
+ let newToken;
3443
+ let newHasTokenInClass;
3444
+ let newHasTokenInAttribute; // Reset the styling token applied to the host element.
3445
+
3446
+ const {
3447
+ stylesheetToken: oldToken,
3448
+ hasTokenInClass: oldHasTokenInClass,
3449
+ hasTokenInAttribute: oldHasTokenInAttribute
3450
+ } = context;
3451
+
3452
+ if (!isUndefined$1(oldToken)) {
3453
+ if (oldHasTokenInClass) {
3454
+ getClassList(elm).remove(makeHostToken(oldToken));
3455
+ }
3456
+
3457
+ if (oldHasTokenInAttribute) {
3458
+ removeAttribute(elm, makeHostToken(oldToken));
3459
+ }
3460
+ } // Apply the new template styling token to the host element, if the new template has any
3461
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3462
+
3463
+
3464
+ if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
3465
+ newToken = newStylesheetToken;
3466
+ } // Set the new styling token on the host element
3467
+
3468
+
3469
+ if (!isUndefined$1(newToken)) {
3470
+ if (hasScopedStyles) {
3471
+ getClassList(elm).add(makeHostToken(newToken));
3472
+ newHasTokenInClass = true;
3473
+ }
3474
+
3475
+ if (isSyntheticShadow) {
3476
+ setAttribute(elm, makeHostToken(newToken), '');
3477
+ newHasTokenInAttribute = true;
3478
+ }
3479
+ } // Update the styling tokens present on the context object.
3480
+
3481
+
3482
+ context.stylesheetToken = newToken;
3483
+ context.hasTokenInClass = newHasTokenInClass;
3484
+ context.hasTokenInAttribute = newHasTokenInAttribute;
3511
3485
  }
3486
+
3512
3487
  function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
3513
- const content = [];
3514
- let root;
3515
- for (let i = 0; i < stylesheets.length; i++) {
3516
- let stylesheet = stylesheets[i];
3517
- if (isArray$1(stylesheet)) {
3518
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
3488
+ const content = [];
3489
+ let root;
3490
+
3491
+ for (let i = 0; i < stylesheets.length; i++) {
3492
+ let stylesheet = stylesheets[i];
3493
+
3494
+ if (isArray$1(stylesheet)) {
3495
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
3496
+ } else {
3497
+ if (process.env.NODE_ENV !== 'production') {
3498
+ // Check for compiler version mismatch in dev mode only
3499
+ checkVersionMismatch(stylesheet, 'stylesheet'); // in dev-mode, we support hot swapping of stylesheet, which means that
3500
+ // the component instance might be attempting to use an old version of
3501
+ // the stylesheet, while internally, we have a replacement for it.
3502
+
3503
+ stylesheet = getStyleOrSwappedStyle(stylesheet);
3504
+ }
3505
+
3506
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
3507
+
3508
+ if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS) {
3509
+ if (!isScopedCss && vm.renderMode === 0
3510
+ /* RenderMode.Light */
3511
+ ) {
3512
+ logError('Unscoped CSS is not supported in Light DOM. Please use scoped CSS (*.scoped.css) instead of unscoped CSS (*.css).');
3513
+ continue;
3519
3514
  }
3520
- else {
3521
- if (process.env.NODE_ENV !== 'production') {
3522
- // Check for compiler version mismatch in dev mode only
3523
- checkVersionMismatch(stylesheet, 'stylesheet');
3524
- // in dev-mode, we support hot swapping of stylesheet, which means that
3525
- // the component instance might be attempting to use an old version of
3526
- // the stylesheet, while internally, we have a replacement for it.
3527
- stylesheet = getStyleOrSwappedStyle(stylesheet);
3528
- }
3529
- const isScopedCss = stylesheet[KEY__SCOPED_CSS];
3530
- // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
3531
- const scopeToken = isScopedCss ||
3532
- (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
3533
- ? stylesheetToken
3534
- : undefined;
3535
- // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
3536
- // native shadow DOM. Synthetic shadow DOM never uses `:host`.
3537
- const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
3538
- ? !isScopedCss
3539
- : vm.shadowMode === 0 /* ShadowMode.Native */;
3540
- // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
3541
- // we use an attribute selector on the host to simulate :dir().
3542
- let useNativeDirPseudoclass;
3543
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
3544
- useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
3545
- }
3546
- else {
3547
- // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
3548
- // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
3549
- if (isUndefined$1(root)) {
3550
- // Only calculate the root once as necessary
3551
- root = getNearestShadowComponent(vm);
3552
- }
3553
- useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
3554
- }
3555
- ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
3515
+ } // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
3516
+
3517
+
3518
+ const scopeToken = isScopedCss || vm.shadowMode === 1
3519
+ /* ShadowMode.Synthetic */
3520
+ && vm.renderMode === 1
3521
+ /* RenderMode.Shadow */
3522
+ ? stylesheetToken : undefined; // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
3523
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
3524
+
3525
+ const useActualHostSelector = vm.renderMode === 0
3526
+ /* RenderMode.Light */
3527
+ ? !isScopedCss : vm.shadowMode === 0
3528
+ /* ShadowMode.Native */
3529
+ ; // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
3530
+ // we use an attribute selector on the host to simulate :dir().
3531
+
3532
+ let useNativeDirPseudoclass;
3533
+
3534
+ if (vm.renderMode === 1
3535
+ /* RenderMode.Shadow */
3536
+ ) {
3537
+ useNativeDirPseudoclass = vm.shadowMode === 0
3538
+ /* ShadowMode.Native */
3539
+ ;
3540
+ } else {
3541
+ // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
3542
+ // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
3543
+ if (isUndefined$1(root)) {
3544
+ // Only calculate the root once as necessary
3545
+ root = getNearestShadowComponent(vm);
3556
3546
  }
3547
+
3548
+ useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0
3549
+ /* ShadowMode.Native */
3550
+ ;
3551
+ }
3552
+
3553
+ ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
3557
3554
  }
3558
- return content;
3555
+ }
3556
+
3557
+ return content;
3559
3558
  }
3559
+
3560
3560
  function getStylesheetsContent(vm, template) {
3561
- const { stylesheets, stylesheetToken } = template;
3562
- let content = [];
3563
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
3564
- content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3565
- }
3566
- return content;
3567
- }
3568
- // It might be worth caching this to avoid doing the lookup repeatedly, but
3561
+ const {
3562
+ stylesheets,
3563
+ stylesheetToken
3564
+ } = template;
3565
+ let content = [];
3566
+
3567
+ if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
3568
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3569
+ }
3570
+
3571
+ return content;
3572
+ } // It might be worth caching this to avoid doing the lookup repeatedly, but
3569
3573
  // perf testing has not shown it to be a huge improvement yet:
3570
3574
  // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
3575
+
3571
3576
  function getNearestShadowComponent(vm) {
3572
- let owner = vm;
3573
- while (!isNull(owner)) {
3574
- if (owner.renderMode === 1 /* RenderMode.Shadow */) {
3575
- return owner;
3576
- }
3577
- owner = owner.owner;
3577
+ let owner = vm;
3578
+
3579
+ while (!isNull(owner)) {
3580
+ if (owner.renderMode === 1
3581
+ /* RenderMode.Shadow */
3582
+ ) {
3583
+ return owner;
3578
3584
  }
3579
- return owner;
3585
+
3586
+ owner = owner.owner;
3587
+ }
3588
+
3589
+ return owner;
3580
3590
  }
3581
3591
  /**
3582
3592
  * If the component that is currently being rendered uses scoped styles,
3583
3593
  * this returns the unique token for that scoped stylesheet. Otherwise
3584
3594
  * it returns null.
3585
3595
  */
3596
+
3597
+
3586
3598
  function getScopeTokenClass(owner) {
3587
- const { cmpTemplate, context } = owner;
3588
- return (context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) || null;
3599
+ const {
3600
+ cmpTemplate,
3601
+ context
3602
+ } = owner;
3603
+ return context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken) || null;
3589
3604
  }
3590
3605
  /**
3591
3606
  * This function returns the host style token for a custom element if it
3592
3607
  * exists. Otherwise it returns null.
3608
+ *
3609
+ * A host style token is applied to the component if scoped styles are used.
3593
3610
  */
3611
+
3594
3612
  function getStylesheetTokenHost(vnode) {
3595
- const { template: { stylesheetToken }, } = getComponentInternalDef(vnode.ctor);
3596
- return !isUndefined$1(stylesheetToken) ? makeHostToken(stylesheetToken) : null;
3597
- }
3598
- function getNearestNativeShadowComponent(vm) {
3599
- const owner = getNearestShadowComponent(vm);
3600
- if (!isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
3601
- // Synthetic-within-native is impossible. So if the nearest shadow component is
3602
- // synthetic, we know we won't find a native component if we go any further.
3603
- return null;
3604
- }
3605
- return owner;
3606
- }
3607
- function createStylesheet(vm, stylesheets) {
3608
- const { renderMode, shadowMode, renderer: { insertStylesheet }, } = vm;
3609
- if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
3610
- for (let i = 0; i < stylesheets.length; i++) {
3611
- insertStylesheet(stylesheets[i]);
3612
- }
3613
- }
3614
- else if (vm.hydrated) {
3615
- // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3616
- // This works in the client, because the stylesheets are created, and cached in the VM
3617
- // the first time the VM renders.
3618
- // native shadow or light DOM, SSR
3619
- return ArrayMap.call(stylesheets, createInlineStyleVNode);
3620
- }
3621
- else {
3622
- // native shadow or light DOM, DOM renderer
3623
- const root = getNearestNativeShadowComponent(vm);
3624
- // null root means a global style
3625
- const target = isNull(root) ? undefined : root.shadowRoot;
3626
- for (let i = 0; i < stylesheets.length; i++) {
3627
- insertStylesheet(stylesheets[i], target);
3628
- }
3629
- }
3630
- return null;
3613
+ const {
3614
+ template
3615
+ } = getComponentInternalDef(vnode.ctor);
3616
+ const {
3617
+ stylesheetToken
3618
+ } = template;
3619
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
3631
3620
  }
3632
3621
 
3633
- /*
3634
- * Copyright (c) 2020, salesforce.com, inc.
3635
- * All rights reserved.
3636
- * SPDX-License-Identifier: MIT
3637
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3638
- */
3639
-
3640
- function checkHasVM(elm) {
3641
- const hasVM = !isUndefined$1(getAssociatedVMIfPresent(elm));
3622
+ function getNearestNativeShadowComponent(vm) {
3623
+ const owner = getNearestShadowComponent(vm);
3642
3624
 
3643
- if (process.env.NODE_ENV !== 'production' && !hasVM) {
3644
- // Occurs when an element is manually created with the same tag name as an existing LWC component. In that case,
3645
- // we skip calling the LWC connectedCallback/disconnectedCallback logic and log an error.
3646
- logError(`VM for tag name "${elm.tagName.toLowerCase()}" is undefined. ` + `This indicates that an element was created with this tag name, ` + `which is already reserved by an LWC component. Use lwc.createElement ` + `instead to create elements.`);
3625
+ if (!isNull(owner) && owner.shadowMode === 1
3626
+ /* ShadowMode.Synthetic */
3627
+ ) {
3628
+ // Synthetic-within-native is impossible. So if the nearest shadow component is
3629
+ // synthetic, we know we won't find a native component if we go any further.
3630
+ return null;
3647
3631
  }
3648
3632
 
3649
- return hasVM;
3633
+ return owner;
3650
3634
  }
3651
3635
 
3652
- function getUpgradableConstructor(tagName, renderer) {
3636
+ function createStylesheet(vm, stylesheets) {
3653
3637
  const {
3654
- getCustomElement,
3655
- HTMLElementExported: RendererHTMLElement,
3656
- defineCustomElement
3657
- } = renderer; // Should never get a tag with upper case letter at this point, the compiler should
3658
- // produce only tags with lowercase letters
3659
- // But, for backwards compatibility, we will lower case the tagName
3660
-
3661
- tagName = tagName.toLowerCase();
3662
- let CE = getCustomElement(tagName);
3663
-
3664
- if (!isUndefined$1(CE)) {
3665
- return CE;
3666
- }
3667
- /**
3668
- * LWC Upgradable Element reference to an element that was created
3669
- * via the scoped registry mechanism, and that is ready to be upgraded.
3670
- */
3671
-
3672
-
3673
- CE = class LWCUpgradableElement extends RendererHTMLElement {
3674
- constructor(upgradeCallback) {
3675
- super();
3676
-
3677
- if (isFunction$1(upgradeCallback)) {
3678
- upgradeCallback(this); // nothing to do with the result for now
3679
- }
3638
+ renderMode,
3639
+ shadowMode,
3640
+ renderer: {
3641
+ insertStylesheet
3680
3642
  }
3643
+ } = vm;
3681
3644
 
3682
- };
3645
+ if (renderMode === 1
3646
+ /* RenderMode.Shadow */
3647
+ && shadowMode === 1
3648
+ /* ShadowMode.Synthetic */
3649
+ ) {
3650
+ for (let i = 0; i < stylesheets.length; i++) {
3651
+ insertStylesheet(stylesheets[i]);
3652
+ }
3653
+ } else if (vm.hydrated) {
3654
+ // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3655
+ // This works in the client, because the stylesheets are created, and cached in the VM
3656
+ // the first time the VM renders.
3657
+ // native shadow or light DOM, SSR
3658
+ return ArrayMap.call(stylesheets, createInlineStyleVNode);
3659
+ } else {
3660
+ // native shadow or light DOM, DOM renderer
3661
+ const root = getNearestNativeShadowComponent(vm); // null root means a global style
3683
3662
 
3684
- if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3685
- CE.prototype.connectedCallback = function () {
3686
- if (checkHasVM(this)) {
3687
- connectRootElement(this);
3688
- }
3689
- };
3663
+ const target = isNull(root) ? undefined : root.shadowRoot;
3690
3664
 
3691
- CE.prototype.disconnectedCallback = function () {
3692
- if (checkHasVM(this)) {
3693
- disconnectRootElement(this);
3694
- }
3695
- };
3665
+ for (let i = 0; i < stylesheets.length; i++) {
3666
+ insertStylesheet(stylesheets[i], target);
3667
+ }
3696
3668
  }
3697
3669
 
3698
- defineCustomElement(tagName, CE);
3699
- return CE;
3670
+ return null;
3700
3671
  }
3701
3672
 
3702
3673
  /*
@@ -4212,7 +4183,9 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
4212
4183
  sel,
4213
4184
  owner
4214
4185
  } = vnode;
4215
- const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
4186
+ const {
4187
+ createCustomElement
4188
+ } = renderer;
4216
4189
  /**
4217
4190
  * Note: if the upgradable constructor does not expect, or throw when we new it
4218
4191
  * with a callback as the first argument, we could implement a more advanced
@@ -4221,10 +4194,25 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
4221
4194
  */
4222
4195
 
4223
4196
  let vm;
4224
- const elm = new UpgradableConstructor(elm => {
4197
+
4198
+ const upgradeCallback = elm => {
4225
4199
  // the custom element from the registry is expecting an upgrade callback
4226
4200
  vm = createViewModelHook(elm, vnode, renderer);
4227
- });
4201
+ };
4202
+
4203
+ const connectedCallback = elm => {
4204
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
4205
+ connectRootElement(elm);
4206
+ }
4207
+ };
4208
+
4209
+ const disconnectedCallback = elm => {
4210
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
4211
+ disconnectRootElement(elm);
4212
+ }
4213
+ };
4214
+
4215
+ const elm = createCustomElement(sel, upgradeCallback, connectedCallback, disconnectedCallback);
4228
4216
  vnode.elm = elm;
4229
4217
  vnode.vm = vm;
4230
4218
  linkNodeToShadow(elm, owner, renderer);
@@ -4232,8 +4220,6 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
4232
4220
 
4233
4221
  if (vm) {
4234
4222
  allocateChildren(vnode, vm);
4235
- } else if (vnode.ctor !== UpgradableConstructor) {
4236
- throw new TypeError(`Incorrect Component Constructor`);
4237
4223
  }
4238
4224
 
4239
4225
  patchElementPropsAndAttrs$1(null, vnode, renderer);
@@ -7007,19 +6993,23 @@ function validateClassAttr(vnode, elm, renderer) {
7007
6993
  //
7008
6994
  // Consequently, hydration mismatches will occur if scoped CSS token classnames
7009
6995
  // are rendered during SSR. This needs to be accounted for when validating.
7010
- if (scopedToken) {
6996
+ if (!isNull(scopedToken) || !isNull(stylesheetTokenHost)) {
7011
6997
  if (!isUndefined$1(className)) {
7012
- className = isNull(stylesheetTokenHost)
7013
- ? `${scopedToken} ${className}`
7014
- : `${scopedToken} ${className} ${stylesheetTokenHost}`;
6998
+ // The order of the className should be scopedToken className stylesheetTokenHost
6999
+ const classTokens = [scopedToken, className, stylesheetTokenHost];
7000
+ const classNames = ArrayFilter.call(classTokens, (token) => !isNull(token));
7001
+ className = ArrayJoin.call(classNames, ' ');
7015
7002
  }
7016
7003
  else if (!isUndefined$1(classMap)) {
7017
- classMap = Object.assign(Object.assign(Object.assign({}, classMap), { [scopedToken]: true }), (isNull(stylesheetTokenHost) ? {} : { [stylesheetTokenHost]: true }));
7004
+ classMap = Object.assign(Object.assign(Object.assign({}, classMap), (!isNull(scopedToken) ? { [scopedToken]: true } : {})), (!isNull(stylesheetTokenHost) ? { [stylesheetTokenHost]: true } : {}));
7018
7005
  }
7019
7006
  else {
7020
- className = isNull(stylesheetTokenHost)
7021
- ? `${scopedToken}`
7022
- : `${scopedToken} ${stylesheetTokenHost}`;
7007
+ // The order of the className should be scopedToken stylesheetTokenHost
7008
+ const classTokens = [scopedToken, stylesheetTokenHost];
7009
+ const classNames = ArrayFilter.call(classTokens, (token) => !isNull(token));
7010
+ if (classNames.length) {
7011
+ className = ArrayJoin.call(classNames, ' ');
7012
+ }
7023
7013
  }
7024
7014
  }
7025
7015
  let nodesAreCompatible = true;
@@ -7261,7 +7251,7 @@ function getComponentConstructor(elm) {
7261
7251
  }
7262
7252
  return ctor;
7263
7253
  }
7264
- /* version: 2.25.0 */
7254
+ /* version: 2.26.0 */
7265
7255
 
7266
7256
  /*
7267
7257
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7405,6 +7395,626 @@ function insertStylesheet(content, target) {
7405
7395
  }
7406
7396
  }
7407
7397
 
7398
+ /*
7399
+ * Copyright (c) 2020, salesforce.com, inc.
7400
+ * All rights reserved.
7401
+ * SPDX-License-Identifier: MIT
7402
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7403
+ */
7404
+ function isCustomElementRegistryAvailable() {
7405
+ if (typeof customElements === 'undefined') {
7406
+ return false;
7407
+ }
7408
+ try {
7409
+ // dereference HTMLElement global because babel wraps globals in compat mode with a
7410
+ // _wrapNativeSuper()
7411
+ // This is a problem because LWCUpgradableElement extends renderer.HTMLElement which does not
7412
+ // get wrapped by babel.
7413
+ const HTMLElementAlias = HTMLElement;
7414
+ // In case we use compat mode with a modern browser, the compat mode transformation
7415
+ // invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
7416
+ // which are not equipped to be initialized that way.
7417
+ class clazz extends HTMLElementAlias {
7418
+ }
7419
+ customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
7420
+ new clazz();
7421
+ return true;
7422
+ }
7423
+ catch (_a) {
7424
+ return false;
7425
+ }
7426
+ }
7427
+ const hasCustomElements = isCustomElementRegistryAvailable();
7428
+
7429
+ /*
7430
+ * Copyright (c) 2018, salesforce.com, inc.
7431
+ * All rights reserved.
7432
+ * SPDX-License-Identifier: MIT
7433
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7434
+ */
7435
+ // Creates a custom element for compat (legacy) browser environments
7436
+ const createCustomElementCompat = (tagName, upgradeCallback) => {
7437
+ const elm = document.createElement(tagName);
7438
+ upgradeCallback(elm); // nothing to do with the result for now
7439
+ return elm;
7440
+ };
7441
+
7442
+ /*
7443
+ * Copyright (c) 2018, salesforce.com, inc.
7444
+ * All rights reserved.
7445
+ * SPDX-License-Identifier: MIT
7446
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7447
+ */
7448
+ const cachedConstructors = new Map();
7449
+ const elementsUpgradedOutsideLWC = new WeakSet();
7450
+ let elementBeingUpgradedByLWC = false;
7451
+ // Creates a constructor that is intended to be used as a vanilla custom element, except that the upgradeCallback is
7452
+ // passed in to the constructor so LWC can reuse the same custom element constructor for multiple components.
7453
+ // Another benefit is that only LWC can create components that actually do anything – if you do
7454
+ // `customElements.define('x-foo')`, then you don't have access to the upgradeCallback, so it's a dummy custom element.
7455
+ // This class should be created once per tag name.
7456
+ const createUpgradableConstructor = (connectedCallback, disconnectedCallback) => {
7457
+ // TODO [#2972]: this class should expose observedAttributes as necessary
7458
+ return class UpgradableConstructor extends HTMLElement {
7459
+ constructor(upgradeCallback) {
7460
+ super();
7461
+ // If the element is not created using lwc.createElement(), e.g. `document.createElement('x-foo')`,
7462
+ // then elementBeingUpgraded will be false
7463
+ if (elementBeingUpgradedByLWC) {
7464
+ upgradeCallback(this);
7465
+ }
7466
+ else {
7467
+ // keep track of elements that were not created by lwc.createElement,
7468
+ // so we can ignore their lifecycle hooks
7469
+ elementsUpgradedOutsideLWC.add(this);
7470
+ // TODO [#2970]: LWC elements cannot be upgraded via new Ctor()
7471
+ // Do we want to support this? Throw an error? Currently for backwards compat it's a no-op.
7472
+ }
7473
+ }
7474
+ connectedCallback() {
7475
+ if (!elementsUpgradedOutsideLWC.has(this)) {
7476
+ connectedCallback(this);
7477
+ }
7478
+ }
7479
+ disconnectedCallback() {
7480
+ if (!elementsUpgradedOutsideLWC.has(this)) {
7481
+ disconnectedCallback(this);
7482
+ }
7483
+ }
7484
+ };
7485
+ };
7486
+ const createCustomElementVanilla = (tagName, upgradeCallback, connectedCallback, disconnectedCallback) => {
7487
+ // use global custom elements registry
7488
+ let UpgradableConstructor = cachedConstructors.get(tagName);
7489
+ if (isUndefined$1(UpgradableConstructor)) {
7490
+ if (!isUndefined$1(customElements.get(tagName))) {
7491
+ throw new Error(`Unexpected tag name "${tagName}". This name is a registered custom element, preventing LWC to upgrade the element.`);
7492
+ }
7493
+ UpgradableConstructor = createUpgradableConstructor(connectedCallback, disconnectedCallback);
7494
+ customElements.define(tagName, UpgradableConstructor);
7495
+ cachedConstructors.set(tagName, UpgradableConstructor);
7496
+ }
7497
+ elementBeingUpgradedByLWC = true;
7498
+ try {
7499
+ return new UpgradableConstructor(upgradeCallback);
7500
+ }
7501
+ finally {
7502
+ elementBeingUpgradedByLWC = false;
7503
+ }
7504
+ };
7505
+
7506
+ /*
7507
+ * Copyright (c) 2020, salesforce.com, inc.
7508
+ * All rights reserved.
7509
+ * SPDX-License-Identifier: MIT
7510
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7511
+ */
7512
+ /**
7513
+ * Create a scoped registry, i.e. a function that can create custom elements whose tag names
7514
+ * do not conflict with vanilla custom elements having the same tag name.
7515
+ */
7516
+ function createScopedRegistry() {
7517
+ if (!hasCustomElements) {
7518
+ // This code should never be reached, because we don't use the pivot registry if
7519
+ // custom elements are unavailable.
7520
+ throw new Error('Custom elements are not supported in this environment.');
7521
+ }
7522
+ const { HTMLElement: NativeHTMLElement } = window;
7523
+ const { hasAttribute: nativeHasAttribute, setAttribute: nativeSetAttribute, removeAttribute: nativeRemoveAttribute, getAttribute: nativeGetAttribute, } = NativeHTMLElement.prototype;
7524
+ const definitionForElement = new WeakMap();
7525
+ const pendingRegistryForElement = new WeakMap();
7526
+ const definitionForConstructor = new WeakMap();
7527
+ const registeredUserCtors = new WeakSet();
7528
+ const pivotCtorByTag = new Map();
7529
+ const globalDefinitionsByTag = new Map();
7530
+ const globalDefinitionsByClass = new Map();
7531
+ const awaitingUpgrade = new Map();
7532
+ const EMPTY_SET = new Set();
7533
+ function createDefinitionRecord(constructor) {
7534
+ var _a;
7535
+ const { connectedCallback, disconnectedCallback, adoptedCallback, attributeChangedCallback, } = constructor.prototype;
7536
+ const observedAttributes = new Set((_a = constructor.observedAttributes) !== null && _a !== void 0 ? _a : []);
7537
+ return {
7538
+ UserCtor: constructor,
7539
+ PivotCtor: undefined,
7540
+ connectedCallback,
7541
+ disconnectedCallback,
7542
+ adoptedCallback,
7543
+ attributeChangedCallback,
7544
+ observedAttributes,
7545
+ };
7546
+ }
7547
+ // Helper to create stand-in element for each tagName registered that delegates out to the registry for the given
7548
+ // element. Note that the `registeredDefinition` represents the constructor that was used to register during
7549
+ // `customElements.define()`. Whereas the `pivotDefinition` represents the constructor that is passed when the pivot
7550
+ // constructor is invoked with another constructor.
7551
+ function createPivotingClass(tagName, registeredDefinition) {
7552
+ class PivotCtor extends NativeHTMLElement {
7553
+ constructor(UserCtor) {
7554
+ // This constructor can only be invoked by:
7555
+ // a) the browser instantiating an element from parsing or via document.createElement.
7556
+ // b) LWC new PivotClass (This constructor is NOT observable/accessible in user-land).
7557
+ // b) new UserClass.
7558
+ // When LWC instantiates it, it will pass the upgrading definition as an argument
7559
+ // If the caller signals via UserCtor that this is in fact a controlled
7560
+ // definition, we use that one, otherwise fallback to the global
7561
+ // internal registry.
7562
+ super();
7563
+ const userCtorIsDefined = !isUndefined$1(UserCtor);
7564
+ if (userCtorIsDefined) {
7565
+ if (!isConstructor(UserCtor)) {
7566
+ throw new TypeError(`Failed to create custom element: the provided constructor is not a constructor.`);
7567
+ }
7568
+ if (!registeredUserCtors.has(UserCtor)) {
7569
+ throw new Error(`Failed to create custom element: the provided constructor is unregistered: ${UserCtor.name}.`);
7570
+ }
7571
+ }
7572
+ const definition = userCtorIsDefined
7573
+ ? getOrCreateDefinitionForConstructor(UserCtor)
7574
+ : globalDefinitionsByTag.get(tagName);
7575
+ if (!isUndefined$1(definition)) {
7576
+ internalUpgrade(this, registeredDefinition, definition);
7577
+ }
7578
+ else {
7579
+ // This is the case in which there is no global definition, and
7580
+ // it is not handled by LWC (otherwise it will have a valid UserCtor)
7581
+ // so we need to add it to the pending queue just in case it eventually
7582
+ // gets defined in the global registry.
7583
+ pendingRegistryForElement.set(this, registeredDefinition);
7584
+ }
7585
+ }
7586
+ connectedCallback() {
7587
+ var _a;
7588
+ const definition = definitionForElement.get(this);
7589
+ if (!isUndefined$1(definition)) {
7590
+ // Delegate out to user callback
7591
+ (_a = definition.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
7592
+ }
7593
+ else {
7594
+ // Register for upgrade when defined (only when connected, so we don't leak)
7595
+ let awaiting = awaitingUpgrade.get(tagName);
7596
+ if (isUndefined$1(awaiting)) {
7597
+ awaitingUpgrade.set(tagName, (awaiting = new Set()));
7598
+ }
7599
+ awaiting.add(this);
7600
+ }
7601
+ }
7602
+ disconnectedCallback() {
7603
+ var _a;
7604
+ const definition = definitionForElement.get(this);
7605
+ if (!isUndefined$1(definition)) {
7606
+ // Delegate out to user callback
7607
+ (_a = definition.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
7608
+ }
7609
+ else {
7610
+ // Un-register for upgrade when defined (so we don't leak)
7611
+ const awaiting = awaitingUpgrade.get(tagName);
7612
+ // At this point, awaiting should never be undefined, because connectedCallback
7613
+ // must have been called before disconnectedCallback. But just to be safe, we check
7614
+ if (!isUndefined$1(awaiting)) {
7615
+ awaiting.delete(this);
7616
+ }
7617
+ }
7618
+ }
7619
+ adoptedCallback() {
7620
+ var _a;
7621
+ const definition = definitionForElement.get(this);
7622
+ (_a = definition === null || definition === void 0 ? void 0 : definition.adoptedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
7623
+ }
7624
+ attributeChangedCallback(name, oldValue, newValue) {
7625
+ var _a;
7626
+ const definition = definitionForElement.get(this);
7627
+ // if both definitions are the same, then the observedAttributes is the same,
7628
+ // but if they are different, only if the runtime definition has the attribute
7629
+ // marked as observed, then it should invoke attributeChangedCallback.
7630
+ if (registeredDefinition === definition ||
7631
+ (definition === null || definition === void 0 ? void 0 : definition.observedAttributes.has(name))) {
7632
+ (_a = definition.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.apply(this, [name, oldValue, newValue]);
7633
+ }
7634
+ }
7635
+ }
7636
+ PivotCtor.observedAttributes = [...registeredDefinition.observedAttributes];
7637
+ return PivotCtor;
7638
+ }
7639
+ function getNewObservedAttributes(registeredDefinition, pivotDefinition) {
7640
+ const { observedAttributes, attributeChangedCallback } = pivotDefinition;
7641
+ if (observedAttributes.size === 0 || isUndefined$1(attributeChangedCallback)) {
7642
+ // This instance does not need to observe any attributes, no need to patch
7643
+ return EMPTY_SET;
7644
+ }
7645
+ // Natively, the attributes observed by the registered definition are going to be taken
7646
+ // care of by the browser, only the difference between the two sets has to be taken
7647
+ // care by the patched version.
7648
+ return new Set([...pivotDefinition.observedAttributes].filter((x) => !registeredDefinition.observedAttributes.has(x)));
7649
+ }
7650
+ function throwAsyncError(error) {
7651
+ // Per native custom element behavior, errors thrown in attributeChangedCallback
7652
+ // become unhandled async errors. We use setTimeout() instead of Promise.resolve()
7653
+ // to make it an unhandled error rather than an unhandled rejection.
7654
+ setTimeout(() => {
7655
+ throw error;
7656
+ });
7657
+ }
7658
+ // Helper to patch `setAttribute`/`getAttribute` to implement `attributeChangedCallback`.
7659
+ // Why is this necessary? Well basically, you can't change the `observedAttributes` after
7660
+ // a custom element is defined. So with pivots, if two classes share the same tag name,
7661
+ // and the second class observes attributes that aren't observed by the first one,
7662
+ // then those attributes can never be observed by the native `observedAttributes` system.
7663
+ // So we have to simulate it by patching `getAttribute`/`removeAttribute`. Note that
7664
+ // we only do this when absolutely necessary, though; i.e. because we've determined
7665
+ // that we aren't observing the attributes we need to.
7666
+ function patchAttributes(instance, registeredDefinition, pivotDefinition) {
7667
+ const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
7668
+ if (newObservedAttributes.size === 0) {
7669
+ return;
7670
+ }
7671
+ const { attributeChangedCallback } = pivotDefinition;
7672
+ // Patch the instance.
7673
+ // Note we use the native `getAttribute` rather than the super's `getAttribute` because
7674
+ // we don't actually want it to be observable that we're calling `getAttribute` from
7675
+ // `setAttribute` and `removeAttribute`.
7676
+ // TODO [#2994]: this should handle reflected properties such as `ariaLabel` and `role`.
7677
+ defineProperties(instance, {
7678
+ setAttribute: {
7679
+ value: function setAttribute(name, value) {
7680
+ if (newObservedAttributes.has(name)) {
7681
+ const old = nativeGetAttribute.call(this, name);
7682
+ nativeSetAttribute.call(this, name, value);
7683
+ try {
7684
+ attributeChangedCallback.call(this, name, old, value + '');
7685
+ }
7686
+ catch (error) {
7687
+ throwAsyncError(error);
7688
+ }
7689
+ }
7690
+ else {
7691
+ nativeSetAttribute.call(this, name, value);
7692
+ }
7693
+ },
7694
+ writable: true,
7695
+ enumerable: true,
7696
+ configurable: true,
7697
+ },
7698
+ removeAttribute: {
7699
+ value: function removeAttribute(name) {
7700
+ if (newObservedAttributes.has(name)) {
7701
+ const old = nativeGetAttribute.call(this, name);
7702
+ nativeRemoveAttribute.call(this, name);
7703
+ try {
7704
+ attributeChangedCallback.call(this, name, old, null);
7705
+ }
7706
+ catch (error) {
7707
+ throwAsyncError(error);
7708
+ }
7709
+ }
7710
+ else {
7711
+ nativeRemoveAttribute.call(this, name);
7712
+ }
7713
+ },
7714
+ writable: true,
7715
+ enumerable: true,
7716
+ configurable: true,
7717
+ },
7718
+ });
7719
+ }
7720
+ function patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition) {
7721
+ // The below case patches observed attributes for the case where the HTML element is upgraded
7722
+ // from a pre-existing one in the DOM.
7723
+ const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
7724
+ if (getNewObservedAttributes(registeredDefinition, pivotDefinition).size === 0) {
7725
+ return;
7726
+ }
7727
+ const { attributeChangedCallback } = pivotDefinition;
7728
+ // Approximate observedAttributes from the user class, but only for the new observed attributes
7729
+ newObservedAttributes.forEach((name) => {
7730
+ if (nativeHasAttribute.call(instance, name)) {
7731
+ const newValue = nativeGetAttribute.call(instance, name);
7732
+ attributeChangedCallback.call(instance, name, null, newValue);
7733
+ }
7734
+ });
7735
+ }
7736
+ // User extends this HTMLElement, which returns the CE being upgraded
7737
+ let upgradingInstance;
7738
+ // Helper to upgrade an instance with a CE definition using "constructor call trick"
7739
+ function internalUpgrade(instance, registeredDefinition, pivotDefinition) {
7740
+ setPrototypeOf(instance, pivotDefinition.UserCtor.prototype);
7741
+ definitionForElement.set(instance, pivotDefinition);
7742
+ // attributes patches when needed
7743
+ if (pivotDefinition !== registeredDefinition) {
7744
+ patchAttributes(instance, registeredDefinition, pivotDefinition);
7745
+ }
7746
+ // Tricking the construction path to believe that a new instance is being created,
7747
+ // that way it will execute the super initialization mechanism but the HTMLElement
7748
+ // constructor will reuse the instance by returning the upgradingInstance.
7749
+ // This is by far the most important piece of the puzzle
7750
+ upgradingInstance = instance;
7751
+ // By `new`ing the UserCtor, we now jump to the constructor for the overridden global HTMLElement
7752
+ // The reason this happens is that the UserCtor extends HTMLElement, so it calls the `super()`.
7753
+ // Note that `upgradingInstance` is explicitly handled in the HTMLElement constructor.
7754
+ new pivotDefinition.UserCtor();
7755
+ patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition);
7756
+ }
7757
+ function isConstructor(constructor) {
7758
+ return isFunction$1(constructor) && isObject(constructor.prototype);
7759
+ }
7760
+ function getOrCreateDefinitionForConstructor(constructor) {
7761
+ if (!isConstructor(constructor)) {
7762
+ throw new TypeError('The referenced constructor is not a constructor.');
7763
+ }
7764
+ const definition = definitionForConstructor.get(constructor);
7765
+ if (!isUndefined$1(definition)) {
7766
+ return definition;
7767
+ }
7768
+ return createDefinitionRecord(constructor);
7769
+ }
7770
+ const { customElements: nativeRegistry } = window;
7771
+ const { define: nativeDefine, whenDefined: nativeWhenDefined, get: nativeGet } = nativeRegistry;
7772
+ // patch for the global registry define mechanism
7773
+ CustomElementRegistry.prototype.define = function define(tagName, constructor, options) {
7774
+ if (options && options.extends) {
7775
+ // TODO [#2983]: should we support `extends`?
7776
+ throw new DOMException('NotSupportedError: "extends" key in customElements.define() options is not supported.');
7777
+ }
7778
+ if (globalDefinitionsByTag.has(tagName)) {
7779
+ throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': the name "${tagName}" has already been used with this registry`);
7780
+ }
7781
+ if (!isUndefined$1(globalDefinitionsByClass.get(constructor))) {
7782
+ throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': this constructor has already been used with this registry`);
7783
+ }
7784
+ const definition = getOrCreateDefinitionForConstructor(constructor);
7785
+ registeredUserCtors.add(constructor);
7786
+ let PivotCtor = pivotCtorByTag.get(tagName);
7787
+ if (isUndefined$1(PivotCtor)) {
7788
+ PivotCtor = createPivotingClass(tagName, definition);
7789
+ // Register a pivoting class which will handle global registry initializations
7790
+ nativeDefine.call(nativeRegistry, tagName, PivotCtor);
7791
+ }
7792
+ // Only cache after nativeDefine has been called, because if it throws an error
7793
+ // (e.g. for an invalid tag name), then we don't want to cache anything.
7794
+ definitionForConstructor.set(constructor, definition);
7795
+ pivotCtorByTag.set(tagName, PivotCtor);
7796
+ globalDefinitionsByTag.set(tagName, definition);
7797
+ globalDefinitionsByClass.set(constructor, definition);
7798
+ // For globally defined custom elements, the definition associated
7799
+ // to the UserCtor has a back-pointer to PivotCtor in case the user
7800
+ // new the UserCtor, so we know how to create the underlying element.
7801
+ definition.PivotCtor = PivotCtor;
7802
+ // Upgrade any elements created in this scope before customElements.define
7803
+ // was called, which should be exhibited by the following steps:
7804
+ // 1) LWC registers a tagName for an LWC component.
7805
+ // 2) Element with same tagName is created with document.createElement()
7806
+ // and inserted into DOM.
7807
+ // 3) customElements.define() is called with tagName and non-LWC constructor.
7808
+ // This requires immediate upgrade when the new global tagName is defined.
7809
+ const awaiting = awaitingUpgrade.get(tagName);
7810
+ if (!isUndefined$1(awaiting)) {
7811
+ awaitingUpgrade.delete(tagName);
7812
+ for (const element of awaiting) {
7813
+ const registeredDefinition = pendingRegistryForElement.get(element);
7814
+ // At this point, registeredDefinition should never be undefined because awaitingUpgrade
7815
+ // is only populated when we haven't run internalUpgrade yet, and we only populate
7816
+ // pendingRegistryForElement when internalUpgrade hasn't run yet.
7817
+ // But just to be safe, we check.
7818
+ if (!isUndefined$1(registeredDefinition)) {
7819
+ pendingRegistryForElement.delete(element);
7820
+ internalUpgrade(element, registeredDefinition, definition);
7821
+ }
7822
+ }
7823
+ }
7824
+ };
7825
+ CustomElementRegistry.prototype.get = function get(tagName) {
7826
+ const NativeCtor = nativeGet.call(nativeRegistry, tagName);
7827
+ if (!isUndefined$1(NativeCtor)) {
7828
+ const definition = globalDefinitionsByTag.get(tagName);
7829
+ if (!isUndefined$1(definition)) {
7830
+ return definition.UserCtor; // defined by the patched custom elements registry
7831
+ }
7832
+ // TODO [#3073]: return undefined rather than the pivot constructor (NativeCtor)
7833
+ return NativeCtor; // return the pivot constructor or constructor that existed before patching
7834
+ }
7835
+ };
7836
+ CustomElementRegistry.prototype.whenDefined = function whenDefined(tagName) {
7837
+ return nativeWhenDefined.call(nativeRegistry, tagName).then((NativeCtor) => {
7838
+ const definition = globalDefinitionsByTag.get(tagName);
7839
+ if (!isUndefined$1(definition)) {
7840
+ return definition.UserCtor;
7841
+ }
7842
+ // TODO [#3073]: return undefined rather than the pivot constructor (NativeCtor)
7843
+ // In this case, the custom element must have been defined before the registry patches
7844
+ // were applied. So return the non-pivot constructor
7845
+ if (isUndefined$1(NativeCtor)) {
7846
+ // Chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1335247
7847
+ // We can patch the correct behavior using customElements.get()
7848
+ return nativeGet.call(nativeRegistry, tagName);
7849
+ }
7850
+ return NativeCtor;
7851
+ });
7852
+ };
7853
+ // This constructor is invoked when we call `new pivotDefinition.UserCtor()`
7854
+ // @ts-ignore
7855
+ window.HTMLElement = function HTMLElement() {
7856
+ // Upgrading case: the pivoting class constructor was run by the browser's
7857
+ // native custom elements and we're in the process of running the
7858
+ // "constructor-call trick" on the natively constructed instance, so just
7859
+ // return that here.
7860
+ // This code path is also called when LWC `new`s a PivotCtor.
7861
+ const instance = upgradingInstance;
7862
+ if (!isUndefined$1(instance)) {
7863
+ upgradingInstance = undefined;
7864
+ return instance;
7865
+ }
7866
+ // Construction case: we need to construct the pivoting instance and return it.
7867
+ // This is possible when the user register it via global registry and instantiate
7868
+ // it via `new Ctor()`.
7869
+ const { constructor } = this;
7870
+ const definition = globalDefinitionsByClass.get(constructor);
7871
+ if (isUndefined$1(definition) || isUndefined$1(definition.PivotCtor)) {
7872
+ // This code path is hit if someone `new`s a class that extends `HTMLElement` without
7873
+ // doing `customElements.define()` first. This matches native browser behavior:
7874
+ // https://stackoverflow.com/a/61883392
7875
+ throw new TypeError('Illegal constructor');
7876
+ }
7877
+ // This constructor is ONLY invoked when it is the user instantiating
7878
+ // an element via new Ctor while Ctor is a registered global constructor.
7879
+ const { PivotCtor, UserCtor } = definition;
7880
+ return new PivotCtor(UserCtor);
7881
+ };
7882
+ HTMLElement.prototype = NativeHTMLElement.prototype;
7883
+ /**
7884
+ * Create a new PivotConstructor for the given tagName, which is capable of being constructed
7885
+ * with a UserConstructor defining the behavior. Passing in the UserConstructor here
7886
+ * is a hint that can be used when registering a custom element with the global custom elements
7887
+ * registry for the first time, which provides certain optimizations. It also marks the UserConstructor
7888
+ * as "safe" to be used when passed in to a PivotConstructor.
7889
+ *
7890
+ * @param tagName - element tag name
7891
+ * @param UserCtor - userland custom element constructor
7892
+ * @returns a new custom element constructor
7893
+ */
7894
+ return function createPivotConstructor(tagName, UserCtor) {
7895
+ tagName = StringToLowerCase.call(tagName);
7896
+ let PivotCtor = pivotCtorByTag.get(tagName);
7897
+ if (isUndefined$1(PivotCtor)) {
7898
+ const definition = getOrCreateDefinitionForConstructor(UserCtor);
7899
+ PivotCtor = createPivotingClass(tagName, definition);
7900
+ // Register a pivoting class as a global custom element
7901
+ nativeDefine.call(nativeRegistry, tagName, PivotCtor);
7902
+ definition.PivotCtor = PivotCtor;
7903
+ // Only cache after nativeDefine has been called, because if it throws an error
7904
+ // (e.g. for an invalid tag name), then we don't want to cache anything.
7905
+ definitionForConstructor.set(UserCtor, definition);
7906
+ pivotCtorByTag.set(tagName, PivotCtor);
7907
+ }
7908
+ // Register a UserConstructor as "safe" to be used within a PivotConstructor
7909
+ registeredUserCtors.add(UserCtor);
7910
+ return PivotCtor;
7911
+ };
7912
+ }
7913
+
7914
+ /*
7915
+ * Copyright (c) 2018, salesforce.com, inc.
7916
+ * All rights reserved.
7917
+ * SPDX-License-Identifier: MIT
7918
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7919
+ */
7920
+ let createScopedConstructor;
7921
+ let CachedHTMLElement; // We only call `createScopedRegistry()` if the browser supports custom elements and
7922
+ // ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is enabled, because we don't want to patch eagerly if the flag is disabled
7923
+ // or we're in a legacy browser.
7924
+
7925
+ if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
7926
+ if (hasCustomElements) {
7927
+ // If ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is true, then we eagerly initialize the scoped registry.
7928
+ // It's assumed that ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is set *before* LWC loads, and never changes.
7929
+ //
7930
+ // Why not lazily patch in `createCustomElement`? Well, this could lead to subtle bugs, e.g.:
7931
+ //
7932
+ // 1. LWC loads
7933
+ // 2. `const Ctor = class extends HTMLElement {}`
7934
+ // 3. `lwc.createElement(...)` // here we lazily patch
7935
+ // 4. `customElements.define('x-foo', Ctor)` // throws error because class is bound to stale HTMLElement
7936
+ //
7937
+ // To reduce the risk of this, it's safer to patch the registry eagerly.
7938
+ createScopedConstructor = createScopedRegistry(); // It's important to cache window.HTMLElement here. Otherwise, someone else could overwrite window.HTMLElement (e.g.
7939
+ // another copy of the engine, or another scoping implementation) and we would get "Illegal constructor" errors
7940
+ // because the HTMLElement prototypes are mixed up.
7941
+ //
7942
+ // The reason this happens is that the scoping implementation overwrites window.HTMLElement and expects to work
7943
+ // with that version of HTMLElement. So if you load two copies of the scoping implementation in the same environment,
7944
+ // the second one may accidentally grab window.HTMLElement from the first (when doing `class extends HTMLElement`).
7945
+ // Caching avoids this problem.
7946
+
7947
+ CachedHTMLElement = window.HTMLElement;
7948
+ }
7949
+ } // Creates a constructor that is intended to be used as the UserConstructor in a scoped (pivots) registry.
7950
+ // In this case, the upgradeCallback only needs to be defined once because we create these on-demand,
7951
+ // multiple times per tag name.
7952
+
7953
+
7954
+ const createUserConstructor = (upgradeCallback, connectedCallback, disconnectedCallback, HTMLElementToExtend) => {
7955
+ // TODO [#2972]: this class should expose observedAttributes as necessary
7956
+ return class UserConstructor extends HTMLElementToExtend {
7957
+ constructor() {
7958
+ super();
7959
+ upgradeCallback(this);
7960
+ }
7961
+
7962
+ connectedCallback() {
7963
+ connectedCallback(this);
7964
+ }
7965
+
7966
+ disconnectedCallback() {
7967
+ disconnectedCallback(this);
7968
+ }
7969
+
7970
+ };
7971
+ };
7972
+
7973
+ function createCustomElementScoped(tagName, upgradeCallback, connectedCallback, disconnectedCallback) {
7974
+ if (isUndefined$1(createScopedConstructor) || isUndefined$1(CachedHTMLElement)) {
7975
+ // This error should be impossible to hit
7976
+ throw new Error('The flag ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY must be set to true to use this feature');
7977
+ }
7978
+
7979
+ const UserConstructor = createUserConstructor(upgradeCallback, connectedCallback, disconnectedCallback, CachedHTMLElement);
7980
+ const ScopedConstructor = createScopedConstructor(tagName, UserConstructor);
7981
+ return new ScopedConstructor(UserConstructor);
7982
+ }
7983
+
7984
+ /*
7985
+ * Copyright (c) 2018, salesforce.com, inc.
7986
+ * All rights reserved.
7987
+ * SPDX-License-Identifier: MIT
7988
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7989
+ */
7990
+ /**
7991
+ * We have three modes for creating custom elements:
7992
+ *
7993
+ * 1. Compat (legacy) browser support (e.g. IE11). Totally custom, doesn't rely on native browser APIs.
7994
+ * 2. "Vanilla" custom elements registry. This system actually still allows us to have two LWC components with the
7995
+ * same tag name, via a simple trick: every custom element constructor we define in the registry is basically
7996
+ * the same. It's essentially a dummy `class extends HTMLElement` that accepts an `upgradeCallback` in its
7997
+ * constructor, which allows us to have completely customized functionality for different components.
7998
+ * 3. "Scoped" (or "pivot") custom elements. This relies on a sophisticated system that emulates the "scoped custom
7999
+ * elements registry" proposal, with support for avoiding conflicts in tag names both between LWC components and
8000
+ * between LWC components and third-party elements. This uses a similar trick to #2, but is much more complex
8001
+ * because it must patch the global `customElements` and `HTMLElement` objects.
8002
+ */
8003
+
8004
+ let createCustomElement;
8005
+
8006
+ if (hasCustomElements) {
8007
+ if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
8008
+ createCustomElement = createCustomElementScoped;
8009
+ } else {
8010
+ // use global custom elements registry (vanilla)
8011
+ createCustomElement = createCustomElementVanilla;
8012
+ }
8013
+ } else {
8014
+ // no registry available here
8015
+ createCustomElement = createCustomElementCompat;
8016
+ }
8017
+
7408
8018
  /*
7409
8019
  * Copyright (c) 2018, salesforce.com, inc.
7410
8020
  * All rights reserved.
@@ -7465,7 +8075,7 @@ function rendererFactory(baseRenderer) {
7465
8075
  function isNull(obj) {
7466
8076
  return obj === null;
7467
8077
  }
7468
- /** version: 2.25.0 */
8078
+ /** version: 2.26.0 */
7469
8079
 
7470
8080
  /*
7471
8081
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7473,65 +8083,6 @@ function rendererFactory(baseRenderer) {
7473
8083
  * SPDX-License-Identifier: MIT
7474
8084
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7475
8085
  */
7476
- exports.getCustomElement = void 0;
7477
- exports.defineCustomElement = void 0;
7478
- let HTMLElementConstructor;
7479
- function isCustomElementRegistryAvailable() {
7480
- if (typeof customElements === 'undefined') {
7481
- return false;
7482
- }
7483
- try {
7484
- // dereference HTMLElement global because babel wraps globals in compat mode with a
7485
- // _wrapNativeSuper()
7486
- // This is a problem because LWCUpgradableElement extends renderer.HTMLElementExported which does not
7487
- // get wrapped by babel.
7488
- const HTMLElementAlias = HTMLElement;
7489
- // In case we use compat mode with a modern browser, the compat mode transformation
7490
- // invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
7491
- // which are not equipped to be initialized that way.
7492
- class clazz extends HTMLElementAlias {
7493
- }
7494
- customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
7495
- new clazz();
7496
- return true;
7497
- }
7498
- catch (_a) {
7499
- return false;
7500
- }
7501
- }
7502
- if (isCustomElementRegistryAvailable()) {
7503
- exports.getCustomElement = customElements.get.bind(customElements);
7504
- exports.defineCustomElement = customElements.define.bind(customElements);
7505
- HTMLElementConstructor = HTMLElement;
7506
- }
7507
- else {
7508
- const registry = Object.create(null);
7509
- const reverseRegistry = new WeakMap();
7510
- exports.defineCustomElement = function define(name, ctor) {
7511
- if (name !== String.prototype.toLowerCase.call(name) || registry[name]) {
7512
- throw new TypeError(`Invalid Registration`);
7513
- }
7514
- registry[name] = ctor;
7515
- reverseRegistry.set(ctor, name);
7516
- };
7517
- exports.getCustomElement = function get(name) {
7518
- return registry[name];
7519
- };
7520
- HTMLElementConstructor = function HTMLElement() {
7521
- if (!(this instanceof HTMLElement)) {
7522
- throw new TypeError(`Invalid Invocation`);
7523
- }
7524
- const { constructor } = this;
7525
- const name = reverseRegistry.get(constructor);
7526
- if (!name) {
7527
- throw new TypeError(`Invalid Construction`);
7528
- }
7529
- const elm = document.createElement(name);
7530
- Object.setPrototypeOf(elm, constructor.prototype);
7531
- return elm;
7532
- };
7533
- HTMLElementConstructor.prototype = HTMLElement.prototype;
7534
- }
7535
8086
  function cloneNode(node, deep) {
7536
8087
  return node.cloneNode(deep);
7537
8088
  }
@@ -7705,9 +8256,7 @@ function rendererFactory(baseRenderer) {
7705
8256
  function assertInstanceOfHTMLElement(elm, msg) {
7706
8257
  assert.invariant(elm instanceof HTMLElement, msg);
7707
8258
  }
7708
- const HTMLElementExported = HTMLElementConstructor;
7709
8259
 
7710
- exports.HTMLElementExported = HTMLElementExported;
7711
8260
  exports.addEventListener = addEventListener;
7712
8261
  exports.assertInstanceOfHTMLElement = assertInstanceOfHTMLElement;
7713
8262
  exports.attachShadow = attachShadow;
@@ -7767,6 +8316,8 @@ rendererFactory(null),
7767
8316
  {
7768
8317
  // insertStyleSheet implementation shares a global cache of stylesheet data
7769
8318
  insertStylesheet,
8319
+ // relies on a shared global cache
8320
+ createCustomElement,
7770
8321
  isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
7771
8322
  isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
7772
8323
  });
@@ -7867,36 +8418,44 @@ function deprecatedBuildCustomElementConstructor(Ctor) {
7867
8418
  // This WeakSet usage is valid because this functionality is not meant to run in IE11.
7868
8419
  const hydratedCustomElements = new WeakSet();
7869
8420
  function buildCustomElementConstructor(Ctor) {
8421
+ var _a;
7870
8422
  const HtmlPrototype = getComponentHtmlPrototype(Ctor);
7871
- return class extends HtmlPrototype {
7872
- constructor() {
7873
- super();
7874
- if (this.isConnected) {
7875
- // this if block is hit when there's already an un-upgraded element in the DOM with the same tag name.
7876
- hydrateComponent(this, Ctor, {});
7877
- hydratedCustomElements.add(this);
8423
+ const { observedAttributes } = HtmlPrototype;
8424
+ const { attributeChangedCallback } = HtmlPrototype.prototype;
8425
+ return _a = class extends HTMLElement {
8426
+ constructor() {
8427
+ super();
8428
+ if (this.isConnected) {
8429
+ // this if block is hit when there's already an un-upgraded element in the DOM with the same tag name.
8430
+ hydrateComponent(this, Ctor, {});
8431
+ hydratedCustomElements.add(this);
8432
+ }
8433
+ else {
8434
+ createVM(this, Ctor, renderer, {
8435
+ mode: 'open',
8436
+ owner: null,
8437
+ tagName: this.tagName,
8438
+ });
8439
+ }
7878
8440
  }
7879
- else {
7880
- createVM(this, Ctor, renderer, {
7881
- mode: 'open',
7882
- owner: null,
7883
- tagName: this.tagName,
7884
- });
8441
+ connectedCallback() {
8442
+ if (hydratedCustomElements.has(this)) {
8443
+ // This is an un-upgraded element that was hydrated in the constructor.
8444
+ hydratedCustomElements.delete(this);
8445
+ }
8446
+ else {
8447
+ connectRootElement(this);
8448
+ }
7885
8449
  }
7886
- }
7887
- connectedCallback() {
7888
- if (hydratedCustomElements.has(this)) {
7889
- // This is an un-upgraded element that was hydrated in the constructor.
7890
- hydratedCustomElements.delete(this);
8450
+ disconnectedCallback() {
8451
+ disconnectRootElement(this);
7891
8452
  }
7892
- else {
7893
- connectRootElement(this);
8453
+ attributeChangedCallback(name, oldValue, newValue) {
8454
+ attributeChangedCallback.call(this, name, oldValue, newValue);
7894
8455
  }
7895
- }
7896
- disconnectedCallback() {
7897
- disconnectRootElement(this);
7898
- }
7899
- };
8456
+ },
8457
+ _a.observedAttributes = observedAttributes,
8458
+ _a;
7900
8459
  }
7901
8460
 
7902
8461
  /*
@@ -7983,8 +8542,13 @@ function createElement(sel, options) {
7983
8542
  throw new TypeError(`"createElement" function expects an "is" option with a valid component constructor.`);
7984
8543
  }
7985
8544
 
7986
- const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
7987
- let wasComponentUpgraded = false; // the custom element from the registry is expecting an upgrade callback
8545
+ const {
8546
+ createCustomElement
8547
+ } = renderer; // tagName must be all lowercase, unfortunately, we have legacy code that is
8548
+ // passing `sel` as a camel-case, which makes them invalid custom elements name
8549
+ // the following line guarantees that this does not leaks beyond this point.
8550
+
8551
+ const tagName = StringToLowerCase.call(sel); // the custom element from the registry is expecting an upgrade callback
7988
8552
 
7989
8553
  /**
7990
8554
  * Note: if the upgradable constructor does not expect, or throw when we new it
@@ -7993,9 +8557,9 @@ function createElement(sel, options) {
7993
8557
  * an upgradable custom element.
7994
8558
  */
7995
8559
 
7996
- const element = new UpgradableConstructor(elm => {
8560
+ const upgradeCallback = elm => {
7997
8561
  createVM(elm, Ctor, renderer, {
7998
- tagName: sel,
8562
+ tagName,
7999
8563
  mode: options.mode !== 'closed' ? 'open' : 'closed',
8000
8564
  owner: null
8001
8565
  });
@@ -8004,15 +8568,21 @@ function createElement(sel, options) {
8004
8568
  ConnectingSlot.set(elm, connectRootElement);
8005
8569
  DisconnectingSlot.set(elm, disconnectRootElement);
8006
8570
  }
8571
+ };
8007
8572
 
8008
- wasComponentUpgraded = true;
8009
- });
8573
+ const connectedCallback = elm => {
8574
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
8575
+ connectRootElement(elm);
8576
+ }
8577
+ };
8010
8578
 
8011
- if (!wasComponentUpgraded) {
8012
- /* eslint-disable-next-line no-console */
8013
- console.error(`Unexpected tag name "${sel}". This name is a registered custom element, preventing LWC to upgrade the element.`);
8014
- }
8579
+ const disconnectedCallback = elm => {
8580
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
8581
+ disconnectRootElement(elm);
8582
+ }
8583
+ };
8015
8584
 
8585
+ const element = createCustomElement(tagName, upgradeCallback, connectedCallback, disconnectedCallback);
8016
8586
  return element;
8017
8587
  }
8018
8588
 
@@ -8084,6 +8654,6 @@ defineProperty(LightningElement, 'CustomElementConstructor', {
8084
8654
  });
8085
8655
  freeze(LightningElement);
8086
8656
  seal(LightningElement.prototype);
8087
- /* version: 2.25.0 */
8657
+ /* version: 2.26.0 */
8088
8658
 
8089
8659
  export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, deprecatedBuildCustomElementConstructor as buildCustomElementConstructor, createContextProvider, createElement, freezeTemplate, getComponentConstructor, getComponentDef, hydrateComponent, isComponentConstructor, isNodeShadowed as isNodeFromTemplate, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, renderer, rendererFactory, sanitizeAttribute, setFeatureFlag, setFeatureFlagForTest, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };