lwc 2.25.1 → 2.27.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 (37) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +953 -431
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +953 -431
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +797 -223
  5. package/dist/engine-dom/iife/es5/engine-dom.js +1025 -330
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +952 -241
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +953 -431
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +797 -223
  11. package/dist/engine-dom/umd/es5/engine-dom.js +1025 -330
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +952 -241
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +201 -247
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +201 -247
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +4 -4
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +4 -4
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +4 -4
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
  23. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +4 -4
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +4 -4
  26. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
  28. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  29. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  30. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  31. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  33. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  34. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  35. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  36. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  37. package/package.json +7 -7
@@ -43,7 +43,7 @@ var assert = /*#__PURE__*/Object.freeze({
43
43
  */
44
44
  const { assign, create, defineProperties, defineProperty, freeze, getOwnPropertyDescriptor: getOwnPropertyDescriptor$1, getOwnPropertyNames: getOwnPropertyNames$1, getPrototypeOf: getPrototypeOf$1, hasOwnProperty: hasOwnProperty$1, isFrozen, keys, seal, setPrototypeOf, } = Object;
45
45
  const { isArray: isArray$1 } = Array;
46
- const { copyWithin: ArrayCopyWithin, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush$1, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, } = Array.prototype;
46
+ const { concat: ArrayConcat$1, copyWithin: ArrayCopyWithin, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush$1, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, } = Array.prototype;
47
47
  const { fromCharCode: StringFromCharCode } = String;
48
48
  const { charCodeAt: StringCharCodeAt, replace: StringReplace, slice: StringSlice, toLowerCase: StringToLowerCase, } = String.prototype;
49
49
  function isUndefined$1(obj) {
@@ -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.1";
302
+ const LWC_VERSION = "2.27.0";
303
303
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
304
- /** version: 2.25.1 */
304
+ /** version: 2.27.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.1 */
386
+ /** version: 2.27.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,
@@ -410,6 +409,7 @@ const features = {
410
409
  ENABLE_WIRE_SYNC_EMIT: null,
411
410
  ENABLE_LIGHT_GET_ROOT_NODE_PATCH: null,
412
411
  DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
412
+ ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
413
413
  };
414
414
  if (!_globalThis.lwcRuntimeFlags) {
415
415
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -463,7 +463,7 @@ function setFeatureFlagForTest(name, value) {
463
463
  setFeatureFlag(name, value);
464
464
  }
465
465
  }
466
- /** version: 2.25.1 */
466
+ /** version: 2.27.0 */
467
467
 
468
468
  /*
469
469
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1937,7 +1937,9 @@ const refsCache = new WeakMap();
1937
1937
  const LightningElement = function () {
1938
1938
  // This should be as performant as possible, while any initialization should be done lazily
1939
1939
  if (isNull(vmBeingConstructed)) {
1940
- 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');
1941
1943
  }
1942
1944
  const vm = vmBeingConstructed;
1943
1945
  const { def, elm } = vm;
@@ -2986,274 +2988,213 @@ const swappedStyleMap = new WeakMap();
2986
2988
  const activeTemplates = new WeakMap();
2987
2989
  const activeComponents = new WeakMap();
2988
2990
  const activeStyles = new WeakMap();
2989
-
2990
2991
  function rehydrateHotTemplate(tpl) {
2991
- const list = activeTemplates.get(tpl);
2992
-
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
- }); // resetting the Set to release the memory of those vm references
3001
- // since they are not longer related to this template, instead
3002
- // they will get re-associated once these instances are rehydrated.
3003
-
3004
- list.clear();
3005
- }
3006
-
3007
- 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;
3008
3007
  }
3009
-
3010
3008
  function rehydrateHotStyle(style) {
3011
- const list = activeStyles.get(style);
3012
-
3013
- if (!isUndefined$1(list)) {
3014
- list.forEach(vm => {
3015
- // if a style definition is swapped, we must reset
3016
- // vm's template content in the next micro-task:
3017
- forceRehydration(vm);
3018
- }); // resetting the Set to release the memory of those vm references
3019
- // since they are not longer related to this style, instead
3020
- // they will get re-associated once these instances are rehydrated.
3021
-
3022
- list.clear();
3023
- }
3024
-
3025
- 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;
3026
3022
  }
3027
-
3028
3023
  function rehydrateHotComponent(Ctor) {
3029
- const list = activeComponents.get(Ctor);
3030
- let canRefreshAllInstances = true;
3031
-
3032
- if (!isUndefined$1(list)) {
3033
- list.forEach(vm => {
3034
- const {
3035
- owner
3036
- } = vm;
3037
-
3038
- if (!isNull(owner)) {
3039
- // if a component class definition is swapped, we must reset
3040
- // owner's template content in the next micro-task:
3041
- forceRehydration(owner);
3042
- } else {
3043
- // the hot swapping for components only work for instances of components
3044
- // created from a template, root elements can't be swapped because we
3045
- // don't have a way to force the creation of the element with the same state
3046
- // of the current element.
3047
- // Instead, we can report the problem to the caller so it can take action,
3048
- // for example: reload the entire page.
3049
- canRefreshAllInstances = false;
3050
- }
3051
- }); // resetting the Set to release the memory of those vm references
3052
- // since they are not longer related to this constructor, instead
3053
- // they will get re-associated once these instances are rehydrated.
3054
-
3055
- list.clear();
3056
- }
3057
-
3058
- 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;
3059
3050
  }
3060
-
3061
3051
  function getTemplateOrSwappedTemplate(tpl) {
3062
- if (process.env.NODE_ENV === 'production') {
3063
- // this method should never leak to prod
3064
- throw new ReferenceError();
3065
- }
3066
-
3067
- if (lwcRuntimeFlags.ENABLE_HMR) {
3052
+ if (process.env.NODE_ENV === 'production') {
3053
+ // this method should never leak to prod
3054
+ throw new ReferenceError();
3055
+ }
3068
3056
  const visited = new Set();
3069
-
3070
3057
  while (swappedTemplateMap.has(tpl) && !visited.has(tpl)) {
3071
- visited.add(tpl);
3072
- tpl = swappedTemplateMap.get(tpl);
3058
+ visited.add(tpl);
3059
+ tpl = swappedTemplateMap.get(tpl);
3073
3060
  }
3074
- }
3075
-
3076
- return tpl;
3061
+ return tpl;
3077
3062
  }
3078
3063
  function getComponentOrSwappedComponent(Ctor) {
3079
- if (process.env.NODE_ENV === 'production') {
3080
- // this method should never leak to prod
3081
- throw new ReferenceError();
3082
- }
3083
-
3084
- if (lwcRuntimeFlags.ENABLE_HMR) {
3064
+ if (process.env.NODE_ENV === 'production') {
3065
+ // this method should never leak to prod
3066
+ throw new ReferenceError();
3067
+ }
3085
3068
  const visited = new Set();
3086
-
3087
3069
  while (swappedComponentMap.has(Ctor) && !visited.has(Ctor)) {
3088
- visited.add(Ctor);
3089
- Ctor = swappedComponentMap.get(Ctor);
3070
+ visited.add(Ctor);
3071
+ Ctor = swappedComponentMap.get(Ctor);
3090
3072
  }
3091
- }
3092
-
3093
- return Ctor;
3073
+ return Ctor;
3094
3074
  }
3095
3075
  function getStyleOrSwappedStyle(style) {
3096
- if (process.env.NODE_ENV === 'production') {
3097
- // this method should never leak to prod
3098
- throw new ReferenceError();
3099
- }
3100
-
3101
- if (lwcRuntimeFlags.ENABLE_HMR) {
3076
+ if (process.env.NODE_ENV === 'production') {
3077
+ // this method should never leak to prod
3078
+ throw new ReferenceError();
3079
+ }
3102
3080
  const visited = new Set();
3103
-
3104
3081
  while (swappedStyleMap.has(style) && !visited.has(style)) {
3105
- visited.add(style);
3106
- style = swappedStyleMap.get(style);
3082
+ visited.add(style);
3083
+ style = swappedStyleMap.get(style);
3107
3084
  }
3108
- }
3109
-
3110
- return style;
3085
+ return style;
3111
3086
  }
3112
3087
  function setActiveVM(vm) {
3113
- if (process.env.NODE_ENV === 'production') {
3114
- // this method should never leak to prod
3115
- throw new ReferenceError();
3116
- }
3117
-
3118
- if (lwcRuntimeFlags.ENABLE_HMR) {
3088
+ if (process.env.NODE_ENV === 'production') {
3089
+ // this method should never leak to prod
3090
+ throw new ReferenceError();
3091
+ }
3119
3092
  // tracking active component
3120
3093
  const Ctor = vm.def.ctor;
3121
3094
  let componentVMs = activeComponents.get(Ctor);
3122
-
3123
3095
  if (isUndefined$1(componentVMs)) {
3124
- componentVMs = new Set();
3125
- activeComponents.set(Ctor, componentVMs);
3126
- } // this will allow us to keep track of the hot components
3127
-
3128
-
3129
- componentVMs.add(vm); // tracking active template
3130
-
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
3131
3102
  const tpl = vm.cmpTemplate;
3132
-
3133
3103
  if (tpl) {
3134
- let templateVMs = activeTemplates.get(tpl);
3135
-
3136
- if (isUndefined$1(templateVMs)) {
3137
- templateVMs = new Set();
3138
- activeTemplates.set(tpl, templateVMs);
3139
- } // this will allow us to keep track of the templates that are
3140
- // being used by a hot component
3141
-
3142
-
3143
- templateVMs.add(vm); // tracking active styles associated to template
3144
-
3145
- const stylesheets = tpl.stylesheets;
3146
-
3147
- if (!isUndefined$1(stylesheets)) {
3148
- flattenStylesheets(stylesheets).forEach(stylesheet => {
3149
- // this is necessary because we don't hold the list of styles
3150
- // in the vm, we only hold the selected (already swapped template)
3151
- // but the styles attached to the template might not be the actual
3152
- // active ones, but the swapped versions of those.
3153
- stylesheet = getStyleOrSwappedStyle(stylesheet);
3154
- let stylesheetVMs = activeStyles.get(stylesheet);
3155
-
3156
- if (isUndefined$1(stylesheetVMs)) {
3157
- stylesheetVMs = new Set();
3158
- activeStyles.set(stylesheet, stylesheetVMs);
3159
- } // this will allow us to keep track of the stylesheet that are
3160
- // being used by a hot component
3161
-
3162
-
3163
- stylesheetVMs.add(vm);
3164
- });
3165
- }
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
+ }
3166
3131
  }
3167
- }
3168
3132
  }
3169
3133
  function removeActiveVM(vm) {
3170
- if (process.env.NODE_ENV === 'production') {
3171
- // this method should never leak to prod
3172
- throw new ReferenceError();
3173
- }
3174
-
3175
- if (lwcRuntimeFlags.ENABLE_HMR) {
3134
+ if (process.env.NODE_ENV === 'production') {
3135
+ // this method should never leak to prod
3136
+ throw new ReferenceError();
3137
+ }
3176
3138
  // tracking inactive component
3177
3139
  const Ctor = vm.def.ctor;
3178
3140
  let list = activeComponents.get(Ctor);
3179
-
3180
3141
  if (!isUndefined$1(list)) {
3181
- // deleting the vm from the set to avoid leaking memory
3182
- list.delete(vm);
3183
- } // removing inactive template
3184
-
3185
-
3186
- const tpl = vm.cmpTemplate;
3187
-
3188
- if (tpl) {
3189
- list = activeTemplates.get(tpl);
3190
-
3191
- if (!isUndefined$1(list)) {
3192
3142
  // deleting the vm from the set to avoid leaking memory
3193
3143
  list.delete(vm);
3194
- } // removing active styles associated to template
3195
-
3196
-
3197
- const styles = tpl.stylesheets;
3198
-
3199
- if (!isUndefined$1(styles)) {
3200
- flattenStylesheets(styles).forEach(style => {
3201
- list = activeStyles.get(style);
3202
-
3203
- 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)) {
3204
3150
  // deleting the vm from the set to avoid leaking memory
3205
3151
  list.delete(vm);
3206
- }
3207
- });
3208
- }
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
+ }
3209
3164
  }
3210
- }
3211
3165
  }
3212
3166
  function swapTemplate(oldTpl, newTpl) {
3213
- if (process.env.NODE_ENV !== 'production') {
3214
- if (isTemplateRegistered(oldTpl) && isTemplateRegistered(newTpl)) {
3215
- swappedTemplateMap.set(oldTpl, newTpl);
3216
- return rehydrateHotTemplate(oldTpl);
3217
- } else {
3218
- 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
+ }
3219
3175
  }
3220
- }
3221
-
3222
- if (!lwcRuntimeFlags.ENABLE_HMR) {
3223
- throw new Error('HMR is not enabled');
3224
- }
3225
-
3226
- return false;
3176
+ return false;
3227
3177
  }
3228
3178
  function swapComponent(oldComponent, newComponent) {
3229
- if (process.env.NODE_ENV !== 'production') {
3230
- if (isComponentConstructor(oldComponent) && isComponentConstructor(newComponent)) {
3231
- swappedComponentMap.set(oldComponent, newComponent);
3232
- return rehydrateHotComponent(oldComponent);
3233
- } else {
3234
- 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
+ }
3235
3187
  }
3236
- }
3237
-
3238
- if (!lwcRuntimeFlags.ENABLE_HMR) {
3239
- throw new Error('HMR is not enabled');
3240
- }
3241
-
3242
- return false;
3188
+ return false;
3243
3189
  }
3244
3190
  function swapStyle(oldStyle, newStyle) {
3245
- if (process.env.NODE_ENV !== 'production') {
3246
- // TODO [#1887]: once the support for registering styles is implemented
3247
- // we can add the validation of both styles around this block.
3248
- swappedStyleMap.set(oldStyle, newStyle);
3249
- return rehydrateHotStyle(oldStyle);
3250
- }
3251
-
3252
- if (!lwcRuntimeFlags.ENABLE_HMR) {
3253
- throw new Error('HMR is not enabled');
3254
- }
3255
-
3256
- 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;
3257
3198
  }
3258
3199
 
3259
3200
  /*
@@ -3664,15 +3605,18 @@ function getScopeTokenClass(owner) {
3664
3605
  /**
3665
3606
  * This function returns the host style token for a custom element if it
3666
3607
  * exists. Otherwise it returns null.
3608
+ *
3609
+ * A host style token is applied to the component if scoped styles are used.
3667
3610
  */
3668
3611
 
3669
3612
  function getStylesheetTokenHost(vnode) {
3670
3613
  const {
3671
- template: {
3672
- stylesheetToken
3673
- }
3614
+ template
3674
3615
  } = getComponentInternalDef(vnode.ctor);
3675
- return !isUndefined$1(stylesheetToken) ? makeHostToken(stylesheetToken) : null;
3616
+ const {
3617
+ stylesheetToken
3618
+ } = template;
3619
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
3676
3620
  }
3677
3621
 
3678
3622
  function getNearestNativeShadowComponent(vm) {
@@ -3726,75 +3670,6 @@ function createStylesheet(vm, stylesheets) {
3726
3670
  return null;
3727
3671
  }
3728
3672
 
3729
- /*
3730
- * Copyright (c) 2020, salesforce.com, inc.
3731
- * All rights reserved.
3732
- * SPDX-License-Identifier: MIT
3733
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3734
- */
3735
-
3736
- function checkHasVM(elm) {
3737
- const hasVM = !isUndefined$1(getAssociatedVMIfPresent(elm));
3738
-
3739
- if (process.env.NODE_ENV !== 'production' && !hasVM) {
3740
- // Occurs when an element is manually created with the same tag name as an existing LWC component. In that case,
3741
- // we skip calling the LWC connectedCallback/disconnectedCallback logic and log an error.
3742
- 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.`);
3743
- }
3744
-
3745
- return hasVM;
3746
- }
3747
-
3748
- function getUpgradableConstructor(tagName, renderer) {
3749
- const {
3750
- getCustomElement,
3751
- HTMLElementExported: RendererHTMLElement,
3752
- defineCustomElement
3753
- } = renderer; // Should never get a tag with upper case letter at this point, the compiler should
3754
- // produce only tags with lowercase letters
3755
- // But, for backwards compatibility, we will lower case the tagName
3756
-
3757
- tagName = tagName.toLowerCase();
3758
- let CE = getCustomElement(tagName);
3759
-
3760
- if (!isUndefined$1(CE)) {
3761
- return CE;
3762
- }
3763
- /**
3764
- * LWC Upgradable Element reference to an element that was created
3765
- * via the scoped registry mechanism, and that is ready to be upgraded.
3766
- */
3767
-
3768
-
3769
- CE = class LWCUpgradableElement extends RendererHTMLElement {
3770
- constructor(upgradeCallback) {
3771
- super();
3772
-
3773
- if (isFunction$1(upgradeCallback)) {
3774
- upgradeCallback(this); // nothing to do with the result for now
3775
- }
3776
- }
3777
-
3778
- };
3779
-
3780
- if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3781
- CE.prototype.connectedCallback = function () {
3782
- if (checkHasVM(this)) {
3783
- connectRootElement(this);
3784
- }
3785
- };
3786
-
3787
- CE.prototype.disconnectedCallback = function () {
3788
- if (checkHasVM(this)) {
3789
- disconnectRootElement(this);
3790
- }
3791
- };
3792
- }
3793
-
3794
- defineCustomElement(tagName, CE);
3795
- return CE;
3796
- }
3797
-
3798
3673
  /*
3799
3674
  * Copyright (c) 2018, salesforce.com, inc.
3800
3675
  * All rights reserved.
@@ -3811,6 +3686,9 @@ function isSameVnode(vnode1, vnode2) {
3811
3686
  function isVCustomElement(vnode) {
3812
3687
  return vnode.type === 3 /* VNodeType.CustomElement */;
3813
3688
  }
3689
+ function isVScopedSlotFragment(vnode) {
3690
+ return vnode.type === 6 /* VNodeType.ScopedSlotFragment */;
3691
+ }
3814
3692
 
3815
3693
  /*
3816
3694
  * Copyright (c) 2018, salesforce.com, inc.
@@ -4308,7 +4186,9 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
4308
4186
  sel,
4309
4187
  owner
4310
4188
  } = vnode;
4311
- const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
4189
+ const {
4190
+ createCustomElement
4191
+ } = renderer;
4312
4192
  /**
4313
4193
  * Note: if the upgradable constructor does not expect, or throw when we new it
4314
4194
  * with a callback as the first argument, we could implement a more advanced
@@ -4317,10 +4197,25 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
4317
4197
  */
4318
4198
 
4319
4199
  let vm;
4320
- const elm = new UpgradableConstructor(elm => {
4200
+
4201
+ const upgradeCallback = elm => {
4321
4202
  // the custom element from the registry is expecting an upgrade callback
4322
4203
  vm = createViewModelHook(elm, vnode, renderer);
4323
- });
4204
+ };
4205
+
4206
+ const connectedCallback = elm => {
4207
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
4208
+ connectRootElement(elm);
4209
+ }
4210
+ };
4211
+
4212
+ const disconnectedCallback = elm => {
4213
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
4214
+ disconnectRootElement(elm);
4215
+ }
4216
+ };
4217
+
4218
+ const elm = createCustomElement(sel, upgradeCallback, connectedCallback, disconnectedCallback);
4324
4219
  vnode.elm = elm;
4325
4220
  vnode.vm = vm;
4326
4221
  linkNodeToShadow(elm, owner, renderer);
@@ -4328,8 +4223,6 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
4328
4223
 
4329
4224
  if (vm) {
4330
4225
  allocateChildren(vnode, vm);
4331
- } else if (vnode.ctor !== UpgradableConstructor) {
4332
- throw new TypeError(`Incorrect Component Constructor`);
4333
4226
  }
4334
4227
 
4335
4228
  patchElementPropsAndAttrs$1(null, vnode, renderer);
@@ -4630,7 +4523,7 @@ function allocateChildren(vnode, vm) {
4630
4523
  /* RenderMode.Light */
4631
4524
  ) {
4632
4525
  // slow path
4633
- allocateInSlot(vm, children); // save the allocated children in case this vnode is reused.
4526
+ allocateInSlot(vm, children, vnode.owner); // save the allocated children in case this vnode is reused.
4634
4527
 
4635
4528
  vnode.aChildren = children; // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4636
4529
 
@@ -4666,13 +4559,19 @@ function createViewModelHook(elm, vnode, renderer) {
4666
4559
  return vm;
4667
4560
  }
4668
4561
 
4669
- function allocateInSlot(vm, children) {
4670
- var _a;
4562
+ function allocateInSlot(vm, children, owner) {
4563
+ var _a, _b;
4671
4564
 
4672
4565
  const {
4673
- cmpSlots: oldSlots
4566
+ cmpSlots: {
4567
+ slotAssignments: oldSlotsMapping
4568
+ }
4674
4569
  } = vm;
4675
- const cmpSlots = vm.cmpSlots = create(null);
4570
+ const cmpSlotsMapping = create(null);
4571
+ vm.cmpSlots = {
4572
+ owner,
4573
+ slotAssignments: cmpSlotsMapping
4574
+ };
4676
4575
 
4677
4576
  for (let i = 0, len = children.length; i < len; i += 1) {
4678
4577
  const vnode = children[i];
@@ -4684,19 +4583,21 @@ function allocateInSlot(vm, children) {
4684
4583
  let slotName = '';
4685
4584
 
4686
4585
  if (isVBaseElement(vnode)) {
4687
- slotName = ((_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) || '';
4586
+ slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
4587
+ } else if (isVScopedSlotFragment(vnode)) {
4588
+ slotName = vnode.slotName;
4688
4589
  }
4689
4590
 
4690
- const vnodes = cmpSlots[slotName] = cmpSlots[slotName] || [];
4591
+ const vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
4691
4592
  ArrayPush$1.call(vnodes, vnode);
4692
4593
  }
4693
4594
 
4694
4595
  if (isFalse(vm.isDirty)) {
4695
4596
  // We need to determine if the old allocation is really different from the new one
4696
4597
  // and mark the vm as dirty
4697
- const oldKeys = keys(oldSlots);
4598
+ const oldKeys = keys(oldSlotsMapping);
4698
4599
 
4699
- if (oldKeys.length !== keys(cmpSlots).length) {
4600
+ if (oldKeys.length !== keys(cmpSlotsMapping).length) {
4700
4601
  markComponentAsDirty(vm);
4701
4602
  return;
4702
4603
  }
@@ -4704,15 +4605,15 @@ function allocateInSlot(vm, children) {
4704
4605
  for (let i = 0, len = oldKeys.length; i < len; i += 1) {
4705
4606
  const key = oldKeys[i];
4706
4607
 
4707
- if (isUndefined$1(cmpSlots[key]) || oldSlots[key].length !== cmpSlots[key].length) {
4608
+ if (isUndefined$1(cmpSlotsMapping[key]) || oldSlotsMapping[key].length !== cmpSlotsMapping[key].length) {
4708
4609
  markComponentAsDirty(vm);
4709
4610
  return;
4710
4611
  }
4711
4612
 
4712
- const oldVNodes = oldSlots[key];
4713
- const vnodes = cmpSlots[key];
4613
+ const oldVNodes = oldSlotsMapping[key];
4614
+ const vnodes = cmpSlotsMapping[key];
4714
4615
 
4715
- for (let j = 0, a = cmpSlots[key].length; j < a; j += 1) {
4616
+ for (let j = 0, a = cmpSlotsMapping[key].length; j < a; j += 1) {
4716
4617
  if (oldVNodes[j] !== vnodes[j]) {
4717
4618
  markComponentAsDirty(vm);
4718
4619
  return;
@@ -4912,6 +4813,18 @@ const SymbolIterator = Symbol.iterator;
4912
4813
  function addVNodeToChildLWC(vnode) {
4913
4814
  ArrayPush$1.call(getVMBeingRendered().velements, vnode);
4914
4815
  }
4816
+ // [s]coped [s]lot [f]actory
4817
+ function ssf(slotName, factory) {
4818
+ return {
4819
+ type: 6 /* VNodeType.ScopedSlotFragment */,
4820
+ factory,
4821
+ owner: getVMBeingRendered(),
4822
+ elm: undefined,
4823
+ sel: undefined,
4824
+ key: undefined,
4825
+ slotName,
4826
+ };
4827
+ }
4915
4828
  // [st]atic node
4916
4829
  function st(fragment, key) {
4917
4830
  return {
@@ -4995,9 +4908,31 @@ function s(slotName, data, children, slotset) {
4995
4908
  assert.isTrue(isArray$1(children), `h() 3rd argument children must be an array.`);
4996
4909
  }
4997
4910
  if (!isUndefined$1(slotset) &&
4998
- !isUndefined$1(slotset[slotName]) &&
4999
- slotset[slotName].length !== 0) {
5000
- children = slotset[slotName];
4911
+ !isUndefined$1(slotset.slotAssignments) &&
4912
+ !isUndefined$1(slotset.slotAssignments[slotName]) &&
4913
+ slotset.slotAssignments[slotName].length !== 0) {
4914
+ children = slotset.slotAssignments[slotName].reduce((acc, vnode) => {
4915
+ // If the passed slot content is factory, evaluate it and use the produced vnodes
4916
+ if (vnode && isVScopedSlotFragment(vnode)) {
4917
+ const vmBeingRenderedInception = getVMBeingRendered();
4918
+ let children = [];
4919
+ // Evaluate in the scope of the slot content's owner
4920
+ // if a slotset is provided, there will always be an owner. The only case where owner is
4921
+ // undefined is for root components, but root components cannot accept slotted content
4922
+ setVMBeingRendered(slotset.owner);
4923
+ try {
4924
+ children = vnode.factory(data.slotData);
4925
+ }
4926
+ finally {
4927
+ setVMBeingRendered(vmBeingRenderedInception);
4928
+ }
4929
+ return ArrayConcat$1.call(acc, children);
4930
+ }
4931
+ else {
4932
+ // If the slot content is a static list of child nodes provided by the parent, nothing to do
4933
+ return ArrayConcat$1.call(acc, vnode);
4934
+ }
4935
+ }, []);
5001
4936
  }
5002
4937
  const vmBeingRendered = getVMBeingRendered();
5003
4938
  const { renderMode, shadowMode } = vmBeingRendered;
@@ -5317,6 +5252,7 @@ const api = freeze({
5317
5252
  gid,
5318
5253
  fid,
5319
5254
  shc,
5255
+ ssf,
5320
5256
  });
5321
5257
 
5322
5258
  /*
@@ -5453,9 +5389,9 @@ function validateSlots(vm, html) {
5453
5389
  }
5454
5390
  const { cmpSlots } = vm;
5455
5391
  const { slots = EmptyArray } = html;
5456
- for (const slotName in cmpSlots) {
5392
+ for (const slotName in cmpSlots.slotAssignments) {
5457
5393
  // eslint-disable-next-line @lwc/lwc-internal/no-production-assert
5458
- assert.isTrue(isArray$1(cmpSlots[slotName]), `Slots can only be set to an array, instead received ${toString$1(cmpSlots[slotName])} for slot "${slotName}" in ${vm}.`);
5394
+ assert.isTrue(isArray$1(cmpSlots.slotAssignments[slotName]), `Slots can only be set to an array, instead received ${toString$1(cmpSlots.slotAssignments[slotName])} for slot "${slotName}" in ${vm}.`);
5459
5395
  if (slotName !== '' && ArrayIndexOf.call(slots, slotName) === -1) {
5460
5396
  // TODO [#1297]: this should never really happen because the compiler should always validate
5461
5397
  // eslint-disable-next-line @lwc/lwc-internal/no-production-assert
@@ -5952,7 +5888,9 @@ function createVM(elm, ctor, renderer, options) {
5952
5888
  velements: EmptyArray,
5953
5889
  cmpProps: create(null),
5954
5890
  cmpFields: create(null),
5955
- cmpSlots: create(null),
5891
+ cmpSlots: {
5892
+ slotAssignments: create(null)
5893
+ },
5956
5894
  oar: create(null),
5957
5895
  cmpTemplate: null,
5958
5896
  hydrated: Boolean(hydrated),
@@ -7103,19 +7041,23 @@ function validateClassAttr(vnode, elm, renderer) {
7103
7041
  //
7104
7042
  // Consequently, hydration mismatches will occur if scoped CSS token classnames
7105
7043
  // are rendered during SSR. This needs to be accounted for when validating.
7106
- if (scopedToken) {
7044
+ if (!isNull(scopedToken) || !isNull(stylesheetTokenHost)) {
7107
7045
  if (!isUndefined$1(className)) {
7108
- className = isNull(stylesheetTokenHost)
7109
- ? `${scopedToken} ${className}`
7110
- : `${scopedToken} ${className} ${stylesheetTokenHost}`;
7046
+ // The order of the className should be scopedToken className stylesheetTokenHost
7047
+ const classTokens = [scopedToken, className, stylesheetTokenHost];
7048
+ const classNames = ArrayFilter.call(classTokens, (token) => !isNull(token));
7049
+ className = ArrayJoin.call(classNames, ' ');
7111
7050
  }
7112
7051
  else if (!isUndefined$1(classMap)) {
7113
- classMap = Object.assign(Object.assign(Object.assign({}, classMap), { [scopedToken]: true }), (isNull(stylesheetTokenHost) ? {} : { [stylesheetTokenHost]: true }));
7052
+ classMap = Object.assign(Object.assign(Object.assign({}, classMap), (!isNull(scopedToken) ? { [scopedToken]: true } : {})), (!isNull(stylesheetTokenHost) ? { [stylesheetTokenHost]: true } : {}));
7114
7053
  }
7115
7054
  else {
7116
- className = isNull(stylesheetTokenHost)
7117
- ? `${scopedToken}`
7118
- : `${scopedToken} ${stylesheetTokenHost}`;
7055
+ // The order of the className should be scopedToken stylesheetTokenHost
7056
+ const classTokens = [scopedToken, stylesheetTokenHost];
7057
+ const classNames = ArrayFilter.call(classTokens, (token) => !isNull(token));
7058
+ if (classNames.length) {
7059
+ className = ArrayJoin.call(classNames, ' ');
7060
+ }
7119
7061
  }
7120
7062
  }
7121
7063
  let nodesAreCompatible = true;
@@ -7357,7 +7299,7 @@ function getComponentConstructor(elm) {
7357
7299
  }
7358
7300
  return ctor;
7359
7301
  }
7360
- /* version: 2.25.1 */
7302
+ /* version: 2.27.0 */
7361
7303
 
7362
7304
  /*
7363
7305
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7501,6 +7443,626 @@ function insertStylesheet(content, target) {
7501
7443
  }
7502
7444
  }
7503
7445
 
7446
+ /*
7447
+ * Copyright (c) 2020, salesforce.com, inc.
7448
+ * All rights reserved.
7449
+ * SPDX-License-Identifier: MIT
7450
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7451
+ */
7452
+ function isCustomElementRegistryAvailable() {
7453
+ if (typeof customElements === 'undefined') {
7454
+ return false;
7455
+ }
7456
+ try {
7457
+ // dereference HTMLElement global because babel wraps globals in compat mode with a
7458
+ // _wrapNativeSuper()
7459
+ // This is a problem because LWCUpgradableElement extends renderer.HTMLElement which does not
7460
+ // get wrapped by babel.
7461
+ const HTMLElementAlias = HTMLElement;
7462
+ // In case we use compat mode with a modern browser, the compat mode transformation
7463
+ // invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
7464
+ // which are not equipped to be initialized that way.
7465
+ class clazz extends HTMLElementAlias {
7466
+ }
7467
+ customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
7468
+ new clazz();
7469
+ return true;
7470
+ }
7471
+ catch (_a) {
7472
+ return false;
7473
+ }
7474
+ }
7475
+ const hasCustomElements = isCustomElementRegistryAvailable();
7476
+
7477
+ /*
7478
+ * Copyright (c) 2018, salesforce.com, inc.
7479
+ * All rights reserved.
7480
+ * SPDX-License-Identifier: MIT
7481
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7482
+ */
7483
+ // Creates a custom element for compat (legacy) browser environments
7484
+ const createCustomElementCompat = (tagName, upgradeCallback) => {
7485
+ const elm = document.createElement(tagName);
7486
+ upgradeCallback(elm); // nothing to do with the result for now
7487
+ return elm;
7488
+ };
7489
+
7490
+ /*
7491
+ * Copyright (c) 2018, salesforce.com, inc.
7492
+ * All rights reserved.
7493
+ * SPDX-License-Identifier: MIT
7494
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7495
+ */
7496
+ const cachedConstructors = new Map();
7497
+ const elementsUpgradedOutsideLWC = new WeakSet();
7498
+ let elementBeingUpgradedByLWC = false;
7499
+ // Creates a constructor that is intended to be used as a vanilla custom element, except that the upgradeCallback is
7500
+ // passed in to the constructor so LWC can reuse the same custom element constructor for multiple components.
7501
+ // Another benefit is that only LWC can create components that actually do anything – if you do
7502
+ // `customElements.define('x-foo')`, then you don't have access to the upgradeCallback, so it's a dummy custom element.
7503
+ // This class should be created once per tag name.
7504
+ const createUpgradableConstructor = (connectedCallback, disconnectedCallback) => {
7505
+ // TODO [#2972]: this class should expose observedAttributes as necessary
7506
+ return class UpgradableConstructor extends HTMLElement {
7507
+ constructor(upgradeCallback) {
7508
+ super();
7509
+ // If the element is not created using lwc.createElement(), e.g. `document.createElement('x-foo')`,
7510
+ // then elementBeingUpgraded will be false
7511
+ if (elementBeingUpgradedByLWC) {
7512
+ upgradeCallback(this);
7513
+ }
7514
+ else {
7515
+ // keep track of elements that were not created by lwc.createElement,
7516
+ // so we can ignore their lifecycle hooks
7517
+ elementsUpgradedOutsideLWC.add(this);
7518
+ // TODO [#2970]: LWC elements cannot be upgraded via new Ctor()
7519
+ // Do we want to support this? Throw an error? Currently for backwards compat it's a no-op.
7520
+ }
7521
+ }
7522
+ connectedCallback() {
7523
+ if (!elementsUpgradedOutsideLWC.has(this)) {
7524
+ connectedCallback(this);
7525
+ }
7526
+ }
7527
+ disconnectedCallback() {
7528
+ if (!elementsUpgradedOutsideLWC.has(this)) {
7529
+ disconnectedCallback(this);
7530
+ }
7531
+ }
7532
+ };
7533
+ };
7534
+ const createCustomElementVanilla = (tagName, upgradeCallback, connectedCallback, disconnectedCallback) => {
7535
+ // use global custom elements registry
7536
+ let UpgradableConstructor = cachedConstructors.get(tagName);
7537
+ if (isUndefined$1(UpgradableConstructor)) {
7538
+ if (!isUndefined$1(customElements.get(tagName))) {
7539
+ throw new Error(`Unexpected tag name "${tagName}". This name is a registered custom element, preventing LWC to upgrade the element.`);
7540
+ }
7541
+ UpgradableConstructor = createUpgradableConstructor(connectedCallback, disconnectedCallback);
7542
+ customElements.define(tagName, UpgradableConstructor);
7543
+ cachedConstructors.set(tagName, UpgradableConstructor);
7544
+ }
7545
+ elementBeingUpgradedByLWC = true;
7546
+ try {
7547
+ return new UpgradableConstructor(upgradeCallback);
7548
+ }
7549
+ finally {
7550
+ elementBeingUpgradedByLWC = false;
7551
+ }
7552
+ };
7553
+
7554
+ /*
7555
+ * Copyright (c) 2020, salesforce.com, inc.
7556
+ * All rights reserved.
7557
+ * SPDX-License-Identifier: MIT
7558
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7559
+ */
7560
+ /**
7561
+ * Create a scoped registry, i.e. a function that can create custom elements whose tag names
7562
+ * do not conflict with vanilla custom elements having the same tag name.
7563
+ */
7564
+ function createScopedRegistry() {
7565
+ if (!hasCustomElements) {
7566
+ // This code should never be reached, because we don't use the pivot registry if
7567
+ // custom elements are unavailable.
7568
+ throw new Error('Custom elements are not supported in this environment.');
7569
+ }
7570
+ const { HTMLElement: NativeHTMLElement } = window;
7571
+ const { hasAttribute: nativeHasAttribute, setAttribute: nativeSetAttribute, removeAttribute: nativeRemoveAttribute, getAttribute: nativeGetAttribute, } = NativeHTMLElement.prototype;
7572
+ const definitionForElement = new WeakMap();
7573
+ const pendingRegistryForElement = new WeakMap();
7574
+ const definitionForConstructor = new WeakMap();
7575
+ const registeredUserCtors = new WeakSet();
7576
+ const pivotCtorByTag = new Map();
7577
+ const globalDefinitionsByTag = new Map();
7578
+ const globalDefinitionsByClass = new Map();
7579
+ const awaitingUpgrade = new Map();
7580
+ const EMPTY_SET = new Set();
7581
+ function createDefinitionRecord(constructor) {
7582
+ var _a;
7583
+ const { connectedCallback, disconnectedCallback, adoptedCallback, attributeChangedCallback, } = constructor.prototype;
7584
+ const observedAttributes = new Set((_a = constructor.observedAttributes) !== null && _a !== void 0 ? _a : []);
7585
+ return {
7586
+ UserCtor: constructor,
7587
+ PivotCtor: undefined,
7588
+ connectedCallback,
7589
+ disconnectedCallback,
7590
+ adoptedCallback,
7591
+ attributeChangedCallback,
7592
+ observedAttributes,
7593
+ };
7594
+ }
7595
+ // Helper to create stand-in element for each tagName registered that delegates out to the registry for the given
7596
+ // element. Note that the `registeredDefinition` represents the constructor that was used to register during
7597
+ // `customElements.define()`. Whereas the `pivotDefinition` represents the constructor that is passed when the pivot
7598
+ // constructor is invoked with another constructor.
7599
+ function createPivotingClass(tagName, registeredDefinition) {
7600
+ class PivotCtor extends NativeHTMLElement {
7601
+ constructor(UserCtor) {
7602
+ // This constructor can only be invoked by:
7603
+ // a) the browser instantiating an element from parsing or via document.createElement.
7604
+ // b) LWC new PivotClass (This constructor is NOT observable/accessible in user-land).
7605
+ // b) new UserClass.
7606
+ // When LWC instantiates it, it will pass the upgrading definition as an argument
7607
+ // If the caller signals via UserCtor that this is in fact a controlled
7608
+ // definition, we use that one, otherwise fallback to the global
7609
+ // internal registry.
7610
+ super();
7611
+ const userCtorIsDefined = !isUndefined$1(UserCtor);
7612
+ if (userCtorIsDefined) {
7613
+ if (!isConstructor(UserCtor)) {
7614
+ throw new TypeError(`Failed to create custom element: the provided constructor is not a constructor.`);
7615
+ }
7616
+ if (!registeredUserCtors.has(UserCtor)) {
7617
+ throw new Error(`Failed to create custom element: the provided constructor is unregistered: ${UserCtor.name}.`);
7618
+ }
7619
+ }
7620
+ const definition = userCtorIsDefined
7621
+ ? getOrCreateDefinitionForConstructor(UserCtor)
7622
+ : globalDefinitionsByTag.get(tagName);
7623
+ if (!isUndefined$1(definition)) {
7624
+ internalUpgrade(this, registeredDefinition, definition);
7625
+ }
7626
+ else {
7627
+ // This is the case in which there is no global definition, and
7628
+ // it is not handled by LWC (otherwise it will have a valid UserCtor)
7629
+ // so we need to add it to the pending queue just in case it eventually
7630
+ // gets defined in the global registry.
7631
+ pendingRegistryForElement.set(this, registeredDefinition);
7632
+ }
7633
+ }
7634
+ connectedCallback() {
7635
+ var _a;
7636
+ const definition = definitionForElement.get(this);
7637
+ if (!isUndefined$1(definition)) {
7638
+ // Delegate out to user callback
7639
+ (_a = definition.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
7640
+ }
7641
+ else {
7642
+ // Register for upgrade when defined (only when connected, so we don't leak)
7643
+ let awaiting = awaitingUpgrade.get(tagName);
7644
+ if (isUndefined$1(awaiting)) {
7645
+ awaitingUpgrade.set(tagName, (awaiting = new Set()));
7646
+ }
7647
+ awaiting.add(this);
7648
+ }
7649
+ }
7650
+ disconnectedCallback() {
7651
+ var _a;
7652
+ const definition = definitionForElement.get(this);
7653
+ if (!isUndefined$1(definition)) {
7654
+ // Delegate out to user callback
7655
+ (_a = definition.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
7656
+ }
7657
+ else {
7658
+ // Un-register for upgrade when defined (so we don't leak)
7659
+ const awaiting = awaitingUpgrade.get(tagName);
7660
+ // At this point, awaiting should never be undefined, because connectedCallback
7661
+ // must have been called before disconnectedCallback. But just to be safe, we check
7662
+ if (!isUndefined$1(awaiting)) {
7663
+ awaiting.delete(this);
7664
+ }
7665
+ }
7666
+ }
7667
+ adoptedCallback() {
7668
+ var _a;
7669
+ const definition = definitionForElement.get(this);
7670
+ (_a = definition === null || definition === void 0 ? void 0 : definition.adoptedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
7671
+ }
7672
+ attributeChangedCallback(name, oldValue, newValue) {
7673
+ var _a;
7674
+ const definition = definitionForElement.get(this);
7675
+ // if both definitions are the same, then the observedAttributes is the same,
7676
+ // but if they are different, only if the runtime definition has the attribute
7677
+ // marked as observed, then it should invoke attributeChangedCallback.
7678
+ if (registeredDefinition === definition ||
7679
+ (definition === null || definition === void 0 ? void 0 : definition.observedAttributes.has(name))) {
7680
+ (_a = definition.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.apply(this, [name, oldValue, newValue]);
7681
+ }
7682
+ }
7683
+ }
7684
+ PivotCtor.observedAttributes = [...registeredDefinition.observedAttributes];
7685
+ return PivotCtor;
7686
+ }
7687
+ function getNewObservedAttributes(registeredDefinition, pivotDefinition) {
7688
+ const { observedAttributes, attributeChangedCallback } = pivotDefinition;
7689
+ if (observedAttributes.size === 0 || isUndefined$1(attributeChangedCallback)) {
7690
+ // This instance does not need to observe any attributes, no need to patch
7691
+ return EMPTY_SET;
7692
+ }
7693
+ // Natively, the attributes observed by the registered definition are going to be taken
7694
+ // care of by the browser, only the difference between the two sets has to be taken
7695
+ // care by the patched version.
7696
+ return new Set([...pivotDefinition.observedAttributes].filter((x) => !registeredDefinition.observedAttributes.has(x)));
7697
+ }
7698
+ function throwAsyncError(error) {
7699
+ // Per native custom element behavior, errors thrown in attributeChangedCallback
7700
+ // become unhandled async errors. We use setTimeout() instead of Promise.resolve()
7701
+ // to make it an unhandled error rather than an unhandled rejection.
7702
+ setTimeout(() => {
7703
+ throw error;
7704
+ });
7705
+ }
7706
+ // Helper to patch `setAttribute`/`getAttribute` to implement `attributeChangedCallback`.
7707
+ // Why is this necessary? Well basically, you can't change the `observedAttributes` after
7708
+ // a custom element is defined. So with pivots, if two classes share the same tag name,
7709
+ // and the second class observes attributes that aren't observed by the first one,
7710
+ // then those attributes can never be observed by the native `observedAttributes` system.
7711
+ // So we have to simulate it by patching `getAttribute`/`removeAttribute`. Note that
7712
+ // we only do this when absolutely necessary, though; i.e. because we've determined
7713
+ // that we aren't observing the attributes we need to.
7714
+ function patchAttributes(instance, registeredDefinition, pivotDefinition) {
7715
+ const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
7716
+ if (newObservedAttributes.size === 0) {
7717
+ return;
7718
+ }
7719
+ const { attributeChangedCallback } = pivotDefinition;
7720
+ // Patch the instance.
7721
+ // Note we use the native `getAttribute` rather than the super's `getAttribute` because
7722
+ // we don't actually want it to be observable that we're calling `getAttribute` from
7723
+ // `setAttribute` and `removeAttribute`.
7724
+ // TODO [#2994]: this should handle reflected properties such as `ariaLabel` and `role`.
7725
+ defineProperties(instance, {
7726
+ setAttribute: {
7727
+ value: function setAttribute(name, value) {
7728
+ if (newObservedAttributes.has(name)) {
7729
+ const old = nativeGetAttribute.call(this, name);
7730
+ nativeSetAttribute.call(this, name, value);
7731
+ try {
7732
+ attributeChangedCallback.call(this, name, old, value + '');
7733
+ }
7734
+ catch (error) {
7735
+ throwAsyncError(error);
7736
+ }
7737
+ }
7738
+ else {
7739
+ nativeSetAttribute.call(this, name, value);
7740
+ }
7741
+ },
7742
+ writable: true,
7743
+ enumerable: true,
7744
+ configurable: true,
7745
+ },
7746
+ removeAttribute: {
7747
+ value: function removeAttribute(name) {
7748
+ if (newObservedAttributes.has(name)) {
7749
+ const old = nativeGetAttribute.call(this, name);
7750
+ nativeRemoveAttribute.call(this, name);
7751
+ try {
7752
+ attributeChangedCallback.call(this, name, old, null);
7753
+ }
7754
+ catch (error) {
7755
+ throwAsyncError(error);
7756
+ }
7757
+ }
7758
+ else {
7759
+ nativeRemoveAttribute.call(this, name);
7760
+ }
7761
+ },
7762
+ writable: true,
7763
+ enumerable: true,
7764
+ configurable: true,
7765
+ },
7766
+ });
7767
+ }
7768
+ function patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition) {
7769
+ // The below case patches observed attributes for the case where the HTML element is upgraded
7770
+ // from a pre-existing one in the DOM.
7771
+ const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
7772
+ if (getNewObservedAttributes(registeredDefinition, pivotDefinition).size === 0) {
7773
+ return;
7774
+ }
7775
+ const { attributeChangedCallback } = pivotDefinition;
7776
+ // Approximate observedAttributes from the user class, but only for the new observed attributes
7777
+ newObservedAttributes.forEach((name) => {
7778
+ if (nativeHasAttribute.call(instance, name)) {
7779
+ const newValue = nativeGetAttribute.call(instance, name);
7780
+ attributeChangedCallback.call(instance, name, null, newValue);
7781
+ }
7782
+ });
7783
+ }
7784
+ // User extends this HTMLElement, which returns the CE being upgraded
7785
+ let upgradingInstance;
7786
+ // Helper to upgrade an instance with a CE definition using "constructor call trick"
7787
+ function internalUpgrade(instance, registeredDefinition, pivotDefinition) {
7788
+ setPrototypeOf(instance, pivotDefinition.UserCtor.prototype);
7789
+ definitionForElement.set(instance, pivotDefinition);
7790
+ // attributes patches when needed
7791
+ if (pivotDefinition !== registeredDefinition) {
7792
+ patchAttributes(instance, registeredDefinition, pivotDefinition);
7793
+ }
7794
+ // Tricking the construction path to believe that a new instance is being created,
7795
+ // that way it will execute the super initialization mechanism but the HTMLElement
7796
+ // constructor will reuse the instance by returning the upgradingInstance.
7797
+ // This is by far the most important piece of the puzzle
7798
+ upgradingInstance = instance;
7799
+ // By `new`ing the UserCtor, we now jump to the constructor for the overridden global HTMLElement
7800
+ // The reason this happens is that the UserCtor extends HTMLElement, so it calls the `super()`.
7801
+ // Note that `upgradingInstance` is explicitly handled in the HTMLElement constructor.
7802
+ new pivotDefinition.UserCtor();
7803
+ patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition);
7804
+ }
7805
+ function isConstructor(constructor) {
7806
+ return isFunction$1(constructor) && isObject(constructor.prototype);
7807
+ }
7808
+ function getOrCreateDefinitionForConstructor(constructor) {
7809
+ if (!isConstructor(constructor)) {
7810
+ throw new TypeError('The referenced constructor is not a constructor.');
7811
+ }
7812
+ const definition = definitionForConstructor.get(constructor);
7813
+ if (!isUndefined$1(definition)) {
7814
+ return definition;
7815
+ }
7816
+ return createDefinitionRecord(constructor);
7817
+ }
7818
+ const { customElements: nativeRegistry } = window;
7819
+ const { define: nativeDefine, whenDefined: nativeWhenDefined, get: nativeGet } = nativeRegistry;
7820
+ // patch for the global registry define mechanism
7821
+ CustomElementRegistry.prototype.define = function define(tagName, constructor, options) {
7822
+ if (options && options.extends) {
7823
+ // TODO [#2983]: should we support `extends`?
7824
+ throw new DOMException('NotSupportedError: "extends" key in customElements.define() options is not supported.');
7825
+ }
7826
+ if (globalDefinitionsByTag.has(tagName)) {
7827
+ throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': the name "${tagName}" has already been used with this registry`);
7828
+ }
7829
+ if (!isUndefined$1(globalDefinitionsByClass.get(constructor))) {
7830
+ throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': this constructor has already been used with this registry`);
7831
+ }
7832
+ const definition = getOrCreateDefinitionForConstructor(constructor);
7833
+ registeredUserCtors.add(constructor);
7834
+ let PivotCtor = pivotCtorByTag.get(tagName);
7835
+ if (isUndefined$1(PivotCtor)) {
7836
+ PivotCtor = createPivotingClass(tagName, definition);
7837
+ // Register a pivoting class which will handle global registry initializations
7838
+ nativeDefine.call(nativeRegistry, tagName, PivotCtor);
7839
+ }
7840
+ // Only cache after nativeDefine has been called, because if it throws an error
7841
+ // (e.g. for an invalid tag name), then we don't want to cache anything.
7842
+ definitionForConstructor.set(constructor, definition);
7843
+ pivotCtorByTag.set(tagName, PivotCtor);
7844
+ globalDefinitionsByTag.set(tagName, definition);
7845
+ globalDefinitionsByClass.set(constructor, definition);
7846
+ // For globally defined custom elements, the definition associated
7847
+ // to the UserCtor has a back-pointer to PivotCtor in case the user
7848
+ // new the UserCtor, so we know how to create the underlying element.
7849
+ definition.PivotCtor = PivotCtor;
7850
+ // Upgrade any elements created in this scope before customElements.define
7851
+ // was called, which should be exhibited by the following steps:
7852
+ // 1) LWC registers a tagName for an LWC component.
7853
+ // 2) Element with same tagName is created with document.createElement()
7854
+ // and inserted into DOM.
7855
+ // 3) customElements.define() is called with tagName and non-LWC constructor.
7856
+ // This requires immediate upgrade when the new global tagName is defined.
7857
+ const awaiting = awaitingUpgrade.get(tagName);
7858
+ if (!isUndefined$1(awaiting)) {
7859
+ awaitingUpgrade.delete(tagName);
7860
+ for (const element of awaiting) {
7861
+ const registeredDefinition = pendingRegistryForElement.get(element);
7862
+ // At this point, registeredDefinition should never be undefined because awaitingUpgrade
7863
+ // is only populated when we haven't run internalUpgrade yet, and we only populate
7864
+ // pendingRegistryForElement when internalUpgrade hasn't run yet.
7865
+ // But just to be safe, we check.
7866
+ if (!isUndefined$1(registeredDefinition)) {
7867
+ pendingRegistryForElement.delete(element);
7868
+ internalUpgrade(element, registeredDefinition, definition);
7869
+ }
7870
+ }
7871
+ }
7872
+ };
7873
+ CustomElementRegistry.prototype.get = function get(tagName) {
7874
+ const NativeCtor = nativeGet.call(nativeRegistry, tagName);
7875
+ if (!isUndefined$1(NativeCtor)) {
7876
+ const definition = globalDefinitionsByTag.get(tagName);
7877
+ if (!isUndefined$1(definition)) {
7878
+ return definition.UserCtor; // defined by the patched custom elements registry
7879
+ }
7880
+ // TODO [#3073]: return undefined rather than the pivot constructor (NativeCtor)
7881
+ return NativeCtor; // return the pivot constructor or constructor that existed before patching
7882
+ }
7883
+ };
7884
+ CustomElementRegistry.prototype.whenDefined = function whenDefined(tagName) {
7885
+ return nativeWhenDefined.call(nativeRegistry, tagName).then((NativeCtor) => {
7886
+ const definition = globalDefinitionsByTag.get(tagName);
7887
+ if (!isUndefined$1(definition)) {
7888
+ return definition.UserCtor;
7889
+ }
7890
+ // TODO [#3073]: return undefined rather than the pivot constructor (NativeCtor)
7891
+ // In this case, the custom element must have been defined before the registry patches
7892
+ // were applied. So return the non-pivot constructor
7893
+ if (isUndefined$1(NativeCtor)) {
7894
+ // Chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1335247
7895
+ // We can patch the correct behavior using customElements.get()
7896
+ return nativeGet.call(nativeRegistry, tagName);
7897
+ }
7898
+ return NativeCtor;
7899
+ });
7900
+ };
7901
+ // This constructor is invoked when we call `new pivotDefinition.UserCtor()`
7902
+ // @ts-ignore
7903
+ window.HTMLElement = function HTMLElement() {
7904
+ // Upgrading case: the pivoting class constructor was run by the browser's
7905
+ // native custom elements and we're in the process of running the
7906
+ // "constructor-call trick" on the natively constructed instance, so just
7907
+ // return that here.
7908
+ // This code path is also called when LWC `new`s a PivotCtor.
7909
+ const instance = upgradingInstance;
7910
+ if (!isUndefined$1(instance)) {
7911
+ upgradingInstance = undefined;
7912
+ return instance;
7913
+ }
7914
+ // Construction case: we need to construct the pivoting instance and return it.
7915
+ // This is possible when the user register it via global registry and instantiate
7916
+ // it via `new Ctor()`.
7917
+ const { constructor } = this;
7918
+ const definition = globalDefinitionsByClass.get(constructor);
7919
+ if (isUndefined$1(definition) || isUndefined$1(definition.PivotCtor)) {
7920
+ // This code path is hit if someone `new`s a class that extends `HTMLElement` without
7921
+ // doing `customElements.define()` first. This matches native browser behavior:
7922
+ // https://stackoverflow.com/a/61883392
7923
+ throw new TypeError('Illegal constructor');
7924
+ }
7925
+ // This constructor is ONLY invoked when it is the user instantiating
7926
+ // an element via new Ctor while Ctor is a registered global constructor.
7927
+ const { PivotCtor, UserCtor } = definition;
7928
+ return new PivotCtor(UserCtor);
7929
+ };
7930
+ HTMLElement.prototype = NativeHTMLElement.prototype;
7931
+ /**
7932
+ * Create a new PivotConstructor for the given tagName, which is capable of being constructed
7933
+ * with a UserConstructor defining the behavior. Passing in the UserConstructor here
7934
+ * is a hint that can be used when registering a custom element with the global custom elements
7935
+ * registry for the first time, which provides certain optimizations. It also marks the UserConstructor
7936
+ * as "safe" to be used when passed in to a PivotConstructor.
7937
+ *
7938
+ * @param tagName - element tag name
7939
+ * @param UserCtor - userland custom element constructor
7940
+ * @returns a new custom element constructor
7941
+ */
7942
+ return function createPivotConstructor(tagName, UserCtor) {
7943
+ tagName = StringToLowerCase.call(tagName);
7944
+ let PivotCtor = pivotCtorByTag.get(tagName);
7945
+ if (isUndefined$1(PivotCtor)) {
7946
+ const definition = getOrCreateDefinitionForConstructor(UserCtor);
7947
+ PivotCtor = createPivotingClass(tagName, definition);
7948
+ // Register a pivoting class as a global custom element
7949
+ nativeDefine.call(nativeRegistry, tagName, PivotCtor);
7950
+ definition.PivotCtor = PivotCtor;
7951
+ // Only cache after nativeDefine has been called, because if it throws an error
7952
+ // (e.g. for an invalid tag name), then we don't want to cache anything.
7953
+ definitionForConstructor.set(UserCtor, definition);
7954
+ pivotCtorByTag.set(tagName, PivotCtor);
7955
+ }
7956
+ // Register a UserConstructor as "safe" to be used within a PivotConstructor
7957
+ registeredUserCtors.add(UserCtor);
7958
+ return PivotCtor;
7959
+ };
7960
+ }
7961
+
7962
+ /*
7963
+ * Copyright (c) 2018, salesforce.com, inc.
7964
+ * All rights reserved.
7965
+ * SPDX-License-Identifier: MIT
7966
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7967
+ */
7968
+ let createScopedConstructor;
7969
+ let CachedHTMLElement; // We only call `createScopedRegistry()` if the browser supports custom elements and
7970
+ // ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is enabled, because we don't want to patch eagerly if the flag is disabled
7971
+ // or we're in a legacy browser.
7972
+
7973
+ if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
7974
+ if (hasCustomElements) {
7975
+ // If ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is true, then we eagerly initialize the scoped registry.
7976
+ // It's assumed that ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is set *before* LWC loads, and never changes.
7977
+ //
7978
+ // Why not lazily patch in `createCustomElement`? Well, this could lead to subtle bugs, e.g.:
7979
+ //
7980
+ // 1. LWC loads
7981
+ // 2. `const Ctor = class extends HTMLElement {}`
7982
+ // 3. `lwc.createElement(...)` // here we lazily patch
7983
+ // 4. `customElements.define('x-foo', Ctor)` // throws error because class is bound to stale HTMLElement
7984
+ //
7985
+ // To reduce the risk of this, it's safer to patch the registry eagerly.
7986
+ createScopedConstructor = createScopedRegistry(); // It's important to cache window.HTMLElement here. Otherwise, someone else could overwrite window.HTMLElement (e.g.
7987
+ // another copy of the engine, or another scoping implementation) and we would get "Illegal constructor" errors
7988
+ // because the HTMLElement prototypes are mixed up.
7989
+ //
7990
+ // The reason this happens is that the scoping implementation overwrites window.HTMLElement and expects to work
7991
+ // with that version of HTMLElement. So if you load two copies of the scoping implementation in the same environment,
7992
+ // the second one may accidentally grab window.HTMLElement from the first (when doing `class extends HTMLElement`).
7993
+ // Caching avoids this problem.
7994
+
7995
+ CachedHTMLElement = window.HTMLElement;
7996
+ }
7997
+ } // Creates a constructor that is intended to be used as the UserConstructor in a scoped (pivots) registry.
7998
+ // In this case, the upgradeCallback only needs to be defined once because we create these on-demand,
7999
+ // multiple times per tag name.
8000
+
8001
+
8002
+ const createUserConstructor = (upgradeCallback, connectedCallback, disconnectedCallback, HTMLElementToExtend) => {
8003
+ // TODO [#2972]: this class should expose observedAttributes as necessary
8004
+ return class UserConstructor extends HTMLElementToExtend {
8005
+ constructor() {
8006
+ super();
8007
+ upgradeCallback(this);
8008
+ }
8009
+
8010
+ connectedCallback() {
8011
+ connectedCallback(this);
8012
+ }
8013
+
8014
+ disconnectedCallback() {
8015
+ disconnectedCallback(this);
8016
+ }
8017
+
8018
+ };
8019
+ };
8020
+
8021
+ function createCustomElementScoped(tagName, upgradeCallback, connectedCallback, disconnectedCallback) {
8022
+ if (isUndefined$1(createScopedConstructor) || isUndefined$1(CachedHTMLElement)) {
8023
+ // This error should be impossible to hit
8024
+ throw new Error('The flag ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY must be set to true to use this feature');
8025
+ }
8026
+
8027
+ const UserConstructor = createUserConstructor(upgradeCallback, connectedCallback, disconnectedCallback, CachedHTMLElement);
8028
+ const ScopedConstructor = createScopedConstructor(tagName, UserConstructor);
8029
+ return new ScopedConstructor(UserConstructor);
8030
+ }
8031
+
8032
+ /*
8033
+ * Copyright (c) 2018, salesforce.com, inc.
8034
+ * All rights reserved.
8035
+ * SPDX-License-Identifier: MIT
8036
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8037
+ */
8038
+ /**
8039
+ * We have three modes for creating custom elements:
8040
+ *
8041
+ * 1. Compat (legacy) browser support (e.g. IE11). Totally custom, doesn't rely on native browser APIs.
8042
+ * 2. "Vanilla" custom elements registry. This system actually still allows us to have two LWC components with the
8043
+ * same tag name, via a simple trick: every custom element constructor we define in the registry is basically
8044
+ * the same. It's essentially a dummy `class extends HTMLElement` that accepts an `upgradeCallback` in its
8045
+ * constructor, which allows us to have completely customized functionality for different components.
8046
+ * 3. "Scoped" (or "pivot") custom elements. This relies on a sophisticated system that emulates the "scoped custom
8047
+ * elements registry" proposal, with support for avoiding conflicts in tag names both between LWC components and
8048
+ * between LWC components and third-party elements. This uses a similar trick to #2, but is much more complex
8049
+ * because it must patch the global `customElements` and `HTMLElement` objects.
8050
+ */
8051
+
8052
+ let createCustomElement;
8053
+
8054
+ if (hasCustomElements) {
8055
+ if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
8056
+ createCustomElement = createCustomElementScoped;
8057
+ } else {
8058
+ // use global custom elements registry (vanilla)
8059
+ createCustomElement = createCustomElementVanilla;
8060
+ }
8061
+ } else {
8062
+ // no registry available here
8063
+ createCustomElement = createCustomElementCompat;
8064
+ }
8065
+
7504
8066
  /*
7505
8067
  * Copyright (c) 2018, salesforce.com, inc.
7506
8068
  * All rights reserved.
@@ -7561,7 +8123,7 @@ function rendererFactory(baseRenderer) {
7561
8123
  function isNull(obj) {
7562
8124
  return obj === null;
7563
8125
  }
7564
- /** version: 2.25.1 */
8126
+ /** version: 2.27.0 */
7565
8127
 
7566
8128
  /*
7567
8129
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7569,65 +8131,6 @@ function rendererFactory(baseRenderer) {
7569
8131
  * SPDX-License-Identifier: MIT
7570
8132
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7571
8133
  */
7572
- exports.getCustomElement = void 0;
7573
- exports.defineCustomElement = void 0;
7574
- let HTMLElementConstructor;
7575
- function isCustomElementRegistryAvailable() {
7576
- if (typeof customElements === 'undefined') {
7577
- return false;
7578
- }
7579
- try {
7580
- // dereference HTMLElement global because babel wraps globals in compat mode with a
7581
- // _wrapNativeSuper()
7582
- // This is a problem because LWCUpgradableElement extends renderer.HTMLElementExported which does not
7583
- // get wrapped by babel.
7584
- const HTMLElementAlias = HTMLElement;
7585
- // In case we use compat mode with a modern browser, the compat mode transformation
7586
- // invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
7587
- // which are not equipped to be initialized that way.
7588
- class clazz extends HTMLElementAlias {
7589
- }
7590
- customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
7591
- new clazz();
7592
- return true;
7593
- }
7594
- catch (_a) {
7595
- return false;
7596
- }
7597
- }
7598
- if (isCustomElementRegistryAvailable()) {
7599
- exports.getCustomElement = customElements.get.bind(customElements);
7600
- exports.defineCustomElement = customElements.define.bind(customElements);
7601
- HTMLElementConstructor = HTMLElement;
7602
- }
7603
- else {
7604
- const registry = Object.create(null);
7605
- const reverseRegistry = new WeakMap();
7606
- exports.defineCustomElement = function define(name, ctor) {
7607
- if (name !== String.prototype.toLowerCase.call(name) || registry[name]) {
7608
- throw new TypeError(`Invalid Registration`);
7609
- }
7610
- registry[name] = ctor;
7611
- reverseRegistry.set(ctor, name);
7612
- };
7613
- exports.getCustomElement = function get(name) {
7614
- return registry[name];
7615
- };
7616
- HTMLElementConstructor = function HTMLElement() {
7617
- if (!(this instanceof HTMLElement)) {
7618
- throw new TypeError(`Invalid Invocation`);
7619
- }
7620
- const { constructor } = this;
7621
- const name = reverseRegistry.get(constructor);
7622
- if (!name) {
7623
- throw new TypeError(`Invalid Construction`);
7624
- }
7625
- const elm = document.createElement(name);
7626
- Object.setPrototypeOf(elm, constructor.prototype);
7627
- return elm;
7628
- };
7629
- HTMLElementConstructor.prototype = HTMLElement.prototype;
7630
- }
7631
8134
  function cloneNode(node, deep) {
7632
8135
  return node.cloneNode(deep);
7633
8136
  }
@@ -7801,9 +8304,7 @@ function rendererFactory(baseRenderer) {
7801
8304
  function assertInstanceOfHTMLElement(elm, msg) {
7802
8305
  assert.invariant(elm instanceof HTMLElement, msg);
7803
8306
  }
7804
- const HTMLElementExported = HTMLElementConstructor;
7805
8307
 
7806
- exports.HTMLElementExported = HTMLElementExported;
7807
8308
  exports.addEventListener = addEventListener;
7808
8309
  exports.assertInstanceOfHTMLElement = assertInstanceOfHTMLElement;
7809
8310
  exports.attachShadow = attachShadow;
@@ -7863,6 +8364,8 @@ rendererFactory(null),
7863
8364
  {
7864
8365
  // insertStyleSheet implementation shares a global cache of stylesheet data
7865
8366
  insertStylesheet,
8367
+ // relies on a shared global cache
8368
+ createCustomElement,
7866
8369
  isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
7867
8370
  isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
7868
8371
  });
@@ -7963,36 +8466,44 @@ function deprecatedBuildCustomElementConstructor(Ctor) {
7963
8466
  // This WeakSet usage is valid because this functionality is not meant to run in IE11.
7964
8467
  const hydratedCustomElements = new WeakSet();
7965
8468
  function buildCustomElementConstructor(Ctor) {
8469
+ var _a;
7966
8470
  const HtmlPrototype = getComponentHtmlPrototype(Ctor);
7967
- return class extends HtmlPrototype {
7968
- constructor() {
7969
- super();
7970
- if (this.isConnected) {
7971
- // this if block is hit when there's already an un-upgraded element in the DOM with the same tag name.
7972
- hydrateComponent(this, Ctor, {});
7973
- hydratedCustomElements.add(this);
8471
+ const { observedAttributes } = HtmlPrototype;
8472
+ const { attributeChangedCallback } = HtmlPrototype.prototype;
8473
+ return _a = class extends HTMLElement {
8474
+ constructor() {
8475
+ super();
8476
+ if (this.isConnected) {
8477
+ // this if block is hit when there's already an un-upgraded element in the DOM with the same tag name.
8478
+ hydrateComponent(this, Ctor, {});
8479
+ hydratedCustomElements.add(this);
8480
+ }
8481
+ else {
8482
+ createVM(this, Ctor, renderer, {
8483
+ mode: 'open',
8484
+ owner: null,
8485
+ tagName: this.tagName,
8486
+ });
8487
+ }
7974
8488
  }
7975
- else {
7976
- createVM(this, Ctor, renderer, {
7977
- mode: 'open',
7978
- owner: null,
7979
- tagName: this.tagName,
7980
- });
8489
+ connectedCallback() {
8490
+ if (hydratedCustomElements.has(this)) {
8491
+ // This is an un-upgraded element that was hydrated in the constructor.
8492
+ hydratedCustomElements.delete(this);
8493
+ }
8494
+ else {
8495
+ connectRootElement(this);
8496
+ }
7981
8497
  }
7982
- }
7983
- connectedCallback() {
7984
- if (hydratedCustomElements.has(this)) {
7985
- // This is an un-upgraded element that was hydrated in the constructor.
7986
- hydratedCustomElements.delete(this);
8498
+ disconnectedCallback() {
8499
+ disconnectRootElement(this);
7987
8500
  }
7988
- else {
7989
- connectRootElement(this);
8501
+ attributeChangedCallback(name, oldValue, newValue) {
8502
+ attributeChangedCallback.call(this, name, oldValue, newValue);
7990
8503
  }
7991
- }
7992
- disconnectedCallback() {
7993
- disconnectRootElement(this);
7994
- }
7995
- };
8504
+ },
8505
+ _a.observedAttributes = observedAttributes,
8506
+ _a;
7996
8507
  }
7997
8508
 
7998
8509
  /*
@@ -8079,8 +8590,13 @@ function createElement(sel, options) {
8079
8590
  throw new TypeError(`"createElement" function expects an "is" option with a valid component constructor.`);
8080
8591
  }
8081
8592
 
8082
- const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
8083
- let wasComponentUpgraded = false; // the custom element from the registry is expecting an upgrade callback
8593
+ const {
8594
+ createCustomElement
8595
+ } = renderer; // tagName must be all lowercase, unfortunately, we have legacy code that is
8596
+ // passing `sel` as a camel-case, which makes them invalid custom elements name
8597
+ // the following line guarantees that this does not leaks beyond this point.
8598
+
8599
+ const tagName = StringToLowerCase.call(sel); // the custom element from the registry is expecting an upgrade callback
8084
8600
 
8085
8601
  /**
8086
8602
  * Note: if the upgradable constructor does not expect, or throw when we new it
@@ -8089,9 +8605,9 @@ function createElement(sel, options) {
8089
8605
  * an upgradable custom element.
8090
8606
  */
8091
8607
 
8092
- const element = new UpgradableConstructor(elm => {
8608
+ const upgradeCallback = elm => {
8093
8609
  createVM(elm, Ctor, renderer, {
8094
- tagName: sel,
8610
+ tagName,
8095
8611
  mode: options.mode !== 'closed' ? 'open' : 'closed',
8096
8612
  owner: null
8097
8613
  });
@@ -8100,15 +8616,21 @@ function createElement(sel, options) {
8100
8616
  ConnectingSlot.set(elm, connectRootElement);
8101
8617
  DisconnectingSlot.set(elm, disconnectRootElement);
8102
8618
  }
8619
+ };
8103
8620
 
8104
- wasComponentUpgraded = true;
8105
- });
8621
+ const connectedCallback = elm => {
8622
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
8623
+ connectRootElement(elm);
8624
+ }
8625
+ };
8106
8626
 
8107
- if (!wasComponentUpgraded) {
8108
- /* eslint-disable-next-line no-console */
8109
- console.error(`Unexpected tag name "${sel}". This name is a registered custom element, preventing LWC to upgrade the element.`);
8110
- }
8627
+ const disconnectedCallback = elm => {
8628
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
8629
+ disconnectRootElement(elm);
8630
+ }
8631
+ };
8111
8632
 
8633
+ const element = createCustomElement(tagName, upgradeCallback, connectedCallback, disconnectedCallback);
8112
8634
  return element;
8113
8635
  }
8114
8636
 
@@ -8180,6 +8702,6 @@ defineProperty(LightningElement, 'CustomElementConstructor', {
8180
8702
  });
8181
8703
  freeze(LightningElement);
8182
8704
  seal(LightningElement.prototype);
8183
- /* version: 2.25.1 */
8705
+ /* version: 2.27.0 */
8184
8706
 
8185
8707
  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 };