@lwc/engine-core 3.4.0 → 3.6.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.
@@ -3,5 +3,5 @@ export interface HTMLElementConstructor {
3
3
  prototype: HTMLElement;
4
4
  new (): HTMLElement;
5
5
  }
6
- export declare function HTMLBridgeElementFactory(SuperClass: HTMLElementConstructor, publicProperties: string[], methods: string[], observedFields: string[], proto: LightningElement | null): HTMLElementConstructor;
6
+ export declare function HTMLBridgeElementFactory(SuperClass: HTMLElementConstructor, publicProperties: string[], methods: string[], observedFields: string[], proto: LightningElement | null, hasCustomSuperClass: boolean): HTMLElementConstructor;
7
7
  export declare const BaseBridgeElement: HTMLElementConstructor;
@@ -17,6 +17,7 @@ export interface LightningElementConstructor {
17
17
  readonly CustomElementConstructor: HTMLElementConstructor;
18
18
  delegatesFocus?: boolean;
19
19
  renderMode?: 'light' | 'shadow';
20
+ formAssociated?: boolean;
20
21
  shadowSupportMode?: ShadowSupportMode;
21
22
  stylesheets: TemplateStylesheetFactories;
22
23
  }
@@ -32,6 +33,10 @@ export interface LightningElement extends HTMLElementTheGoodParts, AccessibleEle
32
33
  disconnectedCallback?(): void;
33
34
  renderedCallback?(): void;
34
35
  errorCallback?(error: any, stack: string): void;
36
+ formAssociatedCallback?(): void;
37
+ formResetCallback?(): void;
38
+ formDisabledCallback?(): void;
39
+ formStateRestoreCallback?(): void;
35
40
  }
36
41
  /**
37
42
  * This class is the base class for any LWC element.
@@ -20,12 +20,17 @@ export interface ComponentDef {
20
20
  template: Template;
21
21
  renderMode: RenderMode;
22
22
  shadowSupportMode: ShadowSupportMode;
23
+ formAssociated: boolean | undefined;
23
24
  ctor: LightningElementConstructor;
24
25
  bridge: HTMLElementConstructor;
25
26
  connectedCallback?: LightningElement['connectedCallback'];
26
27
  disconnectedCallback?: LightningElement['disconnectedCallback'];
27
28
  renderedCallback?: LightningElement['renderedCallback'];
28
29
  errorCallback?: LightningElement['errorCallback'];
30
+ formAssociatedCallback?: LightningElement['formAssociatedCallback'];
31
+ formResetCallback?: LightningElement['formResetCallback'];
32
+ formDisabledCallback?: LightningElement['formDisabledCallback'];
33
+ formStateRestoreCallback?: LightningElement['formStateRestoreCallback'];
29
34
  render: LightningElement['render'];
30
35
  }
31
36
  /**
@@ -1,5 +1,5 @@
1
1
  export { getComponentHtmlPrototype } from './def';
2
- export { RenderMode, ShadowMode, connectRootElement, createVM, disconnectRootElement, getAssociatedVMIfPresent, computeShadowAndRenderMode, } from './vm';
2
+ export { RenderMode, ShadowMode, connectRootElement, createVM, disconnectRootElement, getAssociatedVMIfPresent, computeShadowAndRenderMode, runFormAssociatedCallback, runFormDisabledCallback, runFormResetCallback, runFormStateRestoreCallback, } from './vm';
3
3
  export { createContextProviderWithRegister } from './wiring';
4
4
  export { parseFragment, parseSVGFragment } from './template';
5
5
  export { hydrateRoot } from './hydration';
@@ -41,7 +41,7 @@ export interface RendererAPI {
41
41
  isConnected: (node: N) => boolean;
42
42
  insertStylesheet: (content: string, target?: ShadowRoot) => void;
43
43
  assertInstanceOfHTMLElement: (elm: any, msg: string) => void;
44
- createCustomElement: (tagName: string, upgradeCallback: LifecycleCallback, connectedCallback?: LifecycleCallback, disconnectedCallback?: LifecycleCallback) => E;
44
+ createCustomElement: (tagName: string, upgradeCallback: LifecycleCallback, connectedCallback?: LifecycleCallback, disconnectedCallback?: LifecycleCallback, formAssociatedCallback?: LifecycleCallback, formDisabledCallback?: LifecycleCallback, formResetCallback?: LifecycleCallback, formStateRestoreCallback?: LifecycleCallback) => E;
45
45
  ownerDocument(elm: E): Document;
46
46
  registerContextConsumer: (element: E, adapterContextToken: string, subscriptionPayload: WireContextSubscriptionPayload) => void;
47
47
  attachInternals: (elm: E) => ElementInternals;
@@ -30,7 +30,8 @@ export declare const enum ShadowMode {
30
30
  }
31
31
  export declare const enum ShadowSupportMode {
32
32
  Any = "any",
33
- Default = "reset"
33
+ Default = "reset",
34
+ Native = "native"
34
35
  }
35
36
  export declare const enum LwcDomMode {
36
37
  Manual = "manual"
@@ -166,4 +167,9 @@ export declare function resetComponentRoot(vm: VM): void;
166
167
  export declare function scheduleRehydration(vm: VM): void;
167
168
  export declare function runWithBoundaryProtection(vm: VM, owner: VM | null, pre: () => void, job: () => void, post: () => void): void;
168
169
  export declare function forceRehydration(vm: VM): void;
170
+ export declare function runFormAssociatedCustomElementCallback(vm: VM, faceCb: () => void): void;
171
+ export declare function runFormAssociatedCallback(elm: HTMLElement): void;
172
+ export declare function runFormDisabledCallback(elm: HTMLElement): void;
173
+ export declare function runFormResetCallback(elm: HTMLElement): void;
174
+ export declare function runFormStateRestoreCallback(elm: HTMLElement): void;
169
175
  export {};
package/dist/index.cjs.js CHANGED
@@ -523,8 +523,8 @@ function lockDomMutation() {
523
523
  assertNotProd(); // this method should never leak to prod
524
524
  isDomMutationAllowed = false;
525
525
  }
526
- function logMissingPortalError(name, type) {
527
- return logError(`The \`${name}\` ${type} is available only on elements that use the \`lwc:dom="manual"\` directive.`);
526
+ function logMissingPortalWarn(name, type) {
527
+ return logWarn(`The \`${name}\` ${type} is available only on elements that use the \`lwc:dom="manual"\` directive.`);
528
528
  }
529
529
  function patchElementWithRestrictions(elm, options) {
530
530
  assertNotProd(); // this method should never leak to prod
@@ -549,14 +549,14 @@ function patchElementWithRestrictions(elm, options) {
549
549
  shared.assign(descriptors, {
550
550
  appendChild: generateDataDescriptor({
551
551
  value(aChild) {
552
- logMissingPortalError('appendChild', 'method');
552
+ logMissingPortalWarn('appendChild', 'method');
553
553
  return appendChild.call(this, aChild);
554
554
  },
555
555
  }),
556
556
  insertBefore: generateDataDescriptor({
557
557
  value(newNode, referenceNode) {
558
558
  if (!isDomMutationAllowed) {
559
- logMissingPortalError('insertBefore', 'method');
559
+ logMissingPortalWarn('insertBefore', 'method');
560
560
  }
561
561
  return insertBefore.call(this, newNode, referenceNode);
562
562
  },
@@ -564,14 +564,14 @@ function patchElementWithRestrictions(elm, options) {
564
564
  removeChild: generateDataDescriptor({
565
565
  value(aChild) {
566
566
  if (!isDomMutationAllowed) {
567
- logMissingPortalError('removeChild', 'method');
567
+ logMissingPortalWarn('removeChild', 'method');
568
568
  }
569
569
  return removeChild.call(this, aChild);
570
570
  },
571
571
  }),
572
572
  replaceChild: generateDataDescriptor({
573
573
  value(newChild, oldChild) {
574
- logMissingPortalError('replaceChild', 'method');
574
+ logMissingPortalWarn('replaceChild', 'method');
575
575
  return replaceChild.call(this, newChild, oldChild);
576
576
  },
577
577
  }),
@@ -581,7 +581,7 @@ function patchElementWithRestrictions(elm, options) {
581
581
  },
582
582
  set(value) {
583
583
  if (!isDomMutationAllowed) {
584
- logMissingPortalError('nodeValue', 'property');
584
+ logMissingPortalWarn('nodeValue', 'property');
585
585
  }
586
586
  originalNodeValueDescriptor.set.call(this, value);
587
587
  },
@@ -591,7 +591,7 @@ function patchElementWithRestrictions(elm, options) {
591
591
  return originalTextContentDescriptor.get.call(this);
592
592
  },
593
593
  set(value) {
594
- logMissingPortalError('textContent', 'property');
594
+ logMissingPortalWarn('textContent', 'property');
595
595
  originalTextContentDescriptor.set.call(this, value);
596
596
  },
597
597
  }),
@@ -600,7 +600,7 @@ function patchElementWithRestrictions(elm, options) {
600
600
  return originalInnerHTMLDescriptor.get.call(this);
601
601
  },
602
602
  set(value) {
603
- logMissingPortalError('innerHTML', 'property');
603
+ logMissingPortalWarn('innerHTML', 'property');
604
604
  return originalInnerHTMLDescriptor.set.call(this, value);
605
605
  },
606
606
  }),
@@ -1458,7 +1458,51 @@ function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
1458
1458
  logError(`this.${methodOrPropName} should not be called during the construction of the custom element for ${getComponentTag(vm)} because the element is not yet in the DOM or has no children yet.`);
1459
1459
  }
1460
1460
  }
1461
- const supportsElementInternals = typeof ElementInternals !== 'undefined';
1461
+ // List of properties on ElementInternals that are formAssociated can be found in the spec:
1462
+ // https://html.spec.whatwg.org/multipage/custom-elements.html#form-associated-custom-elements
1463
+ const formAssociatedProps = new Set([
1464
+ 'setFormValue',
1465
+ 'form',
1466
+ 'setValidity',
1467
+ 'willValidate',
1468
+ 'validity',
1469
+ 'validationMessage',
1470
+ 'checkValidity',
1471
+ 'reportValidity',
1472
+ 'labels',
1473
+ ]);
1474
+ // Verify that access to a form-associated property of the ElementInternals proxy has formAssociated set in the LWC.
1475
+ function assertFormAssociatedPropertySet(propertyKey, isFormAssociated) {
1476
+ if (formAssociatedProps.has(propertyKey) && !isFormAssociated) {
1477
+ //Note this error message mirrors Chrome and Firefox error messages, in Safari the error is slightly different.
1478
+ throw new DOMException(`Failed to execute '${propertyKey}' on 'ElementInternals': The target element is not a form-associated custom element.`);
1479
+ }
1480
+ }
1481
+ // Wrap all ElementInternal objects in a proxy to prevent form association when `formAssociated` is not set on an LWC.
1482
+ // This is needed because the 1UpgradeableConstructor1 always sets `formAssociated=true`, which means all
1483
+ // ElementInternal objects will have form-associated properties set when an LWC is placed in a form.
1484
+ // We are doing this to guard against customers taking a dependency on form elements being associated to ElementInternals
1485
+ // when 'formAssociated' has not been set on the LWC.
1486
+ function createElementInternalsProxy(elementInternals, isFormAssociated) {
1487
+ const elementInternalsProxy = new Proxy(elementInternals, {
1488
+ set(target, propertyKey, newValue) {
1489
+ // ElementInternals implementation uses strings as property keys exclusively in chrome, firefox, and safari
1490
+ assertFormAssociatedPropertySet(propertyKey, isFormAssociated);
1491
+ return Reflect.set(target, propertyKey, newValue);
1492
+ },
1493
+ get(target, propertyKey) {
1494
+ // ElementInternals implementation uses strings as property keys exclusively in chrome, firefox, and safari
1495
+ assertFormAssociatedPropertySet(propertyKey, isFormAssociated);
1496
+ const internalsPropertyValue = Reflect.get(target, propertyKey);
1497
+ // Bind the property value to the target so that function invocations are called with the
1498
+ // correct context ('this' value).
1499
+ return typeof internalsPropertyValue === 'function'
1500
+ ? internalsPropertyValue.bind(target)
1501
+ : internalsPropertyValue;
1502
+ },
1503
+ });
1504
+ return elementInternalsProxy;
1505
+ }
1462
1506
  // @ts-ignore
1463
1507
  LightningElement.prototype = {
1464
1508
  constructor: LightningElement,
@@ -1552,15 +1596,13 @@ LightningElement.prototype = {
1552
1596
  },
1553
1597
  attachInternals() {
1554
1598
  const vm = getAssociatedVM(this);
1555
- const { elm, renderer: { attachInternals }, } = vm;
1556
- if (shared.isFalse(supportsElementInternals)) {
1557
- // Browsers that don't support attachInternals will need to be polyfilled before LWC is loaded.
1558
- throw new Error('attachInternals API is not supported in this browser environment.');
1559
- }
1560
- if (vm.renderMode === 0 /* RenderMode.Light */ || vm.shadowMode === 1 /* ShadowMode.Synthetic */) {
1599
+ const { elm, def: { formAssociated }, renderer: { attachInternals }, } = vm;
1600
+ if (vm.shadowMode === 1 /* ShadowMode.Synthetic */) {
1561
1601
  throw new Error('attachInternals API is not supported in light DOM or synthetic shadow.');
1562
1602
  }
1563
- return attachInternals(elm);
1603
+ const internals = attachInternals(elm);
1604
+ // #TODO[2970]: remove proxy once `UpgradeableConstructor` has been removed
1605
+ return createElementInternalsProxy(internals, Boolean(formAssociated));
1564
1606
  },
1565
1607
  get isConnected() {
1566
1608
  const vm = getAssociatedVM(this);
@@ -2582,7 +2624,7 @@ function createAccessorThatWarns(propName) {
2582
2624
  configurable: true,
2583
2625
  };
2584
2626
  }
2585
- function HTMLBridgeElementFactory(SuperClass, publicProperties, methods, observedFields, proto) {
2627
+ function HTMLBridgeElementFactory(SuperClass, publicProperties, methods, observedFields, proto, hasCustomSuperClass) {
2586
2628
  const HTMLBridgeElement = class extends SuperClass {
2587
2629
  };
2588
2630
  // generating the hash table for attributes to avoid duplicate fields and facilitate validation
@@ -2593,7 +2635,8 @@ function HTMLBridgeElementFactory(SuperClass, publicProperties, methods, observe
2593
2635
  const descriptors = shared.create(null);
2594
2636
  // present a hint message so that developers are aware that they have not decorated property with @api
2595
2637
  if (process.env.NODE_ENV !== 'production') {
2596
- if (!shared.isUndefined(proto) && !shared.isNull(proto)) {
2638
+ // TODO [#3761]: enable for components that don't extend from LightningElement
2639
+ if (!shared.isUndefined(proto) && !shared.isNull(proto) && !hasCustomSuperClass) {
2597
2640
  const nonPublicPropertiesToWarnOn = new Set([
2598
2641
  // getters, setters, and methods
2599
2642
  ...shared.keys(shared.getOwnPropertyDescriptors(proto)),
@@ -2641,9 +2684,26 @@ function HTMLBridgeElementFactory(SuperClass, publicProperties, methods, observe
2641
2684
  };
2642
2685
  // To avoid leaking private component details, accessing internals from outside a component is not allowed.
2643
2686
  descriptors.attachInternals = {
2687
+ set() {
2688
+ if (process.env.NODE_ENV !== 'production') {
2689
+ logWarn('attachInternals cannot be accessed outside of a component. Use this.attachInternals instead.');
2690
+ }
2691
+ },
2644
2692
  get() {
2645
2693
  if (process.env.NODE_ENV !== 'production') {
2646
- logError('attachInternals cannot be accessed outside of a component. Use this.attachInternals instead.');
2694
+ logWarn('attachInternals cannot be accessed outside of a component. Use this.attachInternals instead.');
2695
+ }
2696
+ },
2697
+ };
2698
+ descriptors.formAssociated = {
2699
+ set() {
2700
+ if (process.env.NODE_ENV !== 'production') {
2701
+ logWarn('formAssociated cannot be accessed outside of a component. Set the value within the component class.');
2702
+ }
2703
+ },
2704
+ get() {
2705
+ if (process.env.NODE_ENV !== 'production') {
2706
+ logWarn('formAssociated cannot be accessed outside of a component. Set the value within the component class.');
2647
2707
  }
2648
2708
  },
2649
2709
  };
@@ -2657,7 +2717,7 @@ function HTMLBridgeElementFactory(SuperClass, publicProperties, methods, observe
2657
2717
  shared.defineProperties(HTMLBridgeElement.prototype, descriptors);
2658
2718
  return HTMLBridgeElement;
2659
2719
  }
2660
- const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, shared.getOwnPropertyNames(HTMLElementOriginalDescriptors), [], [], null);
2720
+ const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, shared.getOwnPropertyNames(HTMLElementOriginalDescriptors), [], [], null, false);
2661
2721
  if (process.env.IS_BROWSER) {
2662
2722
  // This ARIA reflection only really makes sense in the browser. On the server, there is no `renderedCallback()`,
2663
2723
  // so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't need to expose
@@ -2955,7 +3015,7 @@ function getCtorProto(Ctor) {
2955
3015
  return proto;
2956
3016
  }
2957
3017
  function createComponentDef(Ctor) {
2958
- const { shadowSupportMode: ctorShadowSupportMode, renderMode: ctorRenderMode } = Ctor;
3018
+ const { shadowSupportMode: ctorShadowSupportMode, renderMode: ctorRenderMode, formAssociated: ctorFormAssociated, } = Ctor;
2959
3019
  if (process.env.NODE_ENV !== 'production') {
2960
3020
  const ctorName = Ctor.name;
2961
3021
  // Removing the following assert until https://bugs.webkit.org/show_bug.cgi?id=190140 is fixed.
@@ -2967,7 +3027,8 @@ function createComponentDef(Ctor) {
2967
3027
  }
2968
3028
  if (!shared.isUndefined(ctorShadowSupportMode) &&
2969
3029
  ctorShadowSupportMode !== "any" /* ShadowSupportMode.Any */ &&
2970
- ctorShadowSupportMode !== "reset" /* ShadowSupportMode.Default */) {
3030
+ ctorShadowSupportMode !== "reset" /* ShadowSupportMode.Default */ &&
3031
+ ctorShadowSupportMode !== "native" /* ShadowSupportMode.Native */) {
2971
3032
  logError(`Invalid value for static property shadowSupportMode: '${ctorShadowSupportMode}'`);
2972
3033
  }
2973
3034
  if (!shared.isUndefined(ctorRenderMode) &&
@@ -2979,10 +3040,11 @@ function createComponentDef(Ctor) {
2979
3040
  const decoratorsMeta = getDecoratorsMeta(Ctor);
2980
3041
  const { apiFields, apiFieldsConfig, apiMethods, wiredFields, wiredMethods, observedFields } = decoratorsMeta;
2981
3042
  const proto = Ctor.prototype;
2982
- let { connectedCallback, disconnectedCallback, renderedCallback, errorCallback, render } = proto;
3043
+ let { connectedCallback, disconnectedCallback, renderedCallback, errorCallback, formAssociatedCallback, formResetCallback, formDisabledCallback, formStateRestoreCallback, render, } = proto;
2983
3044
  const superProto = getCtorProto(Ctor);
2984
- const superDef = superProto !== LightningElement ? getComponentInternalDef(superProto) : lightingElementDef;
2985
- const bridge = HTMLBridgeElementFactory(superDef.bridge, shared.keys(apiFields), shared.keys(apiMethods), shared.keys(observedFields), proto);
3045
+ const hasCustomSuperClass = superProto !== LightningElement;
3046
+ const superDef = hasCustomSuperClass ? getComponentInternalDef(superProto) : lightingElementDef;
3047
+ const bridge = HTMLBridgeElementFactory(superDef.bridge, shared.keys(apiFields), shared.keys(apiMethods), shared.keys(observedFields), proto, hasCustomSuperClass);
2986
3048
  const props = shared.assign(shared.create(null), superDef.props, apiFields);
2987
3049
  const propsConfig = shared.assign(shared.create(null), superDef.propsConfig, apiFieldsConfig);
2988
3050
  const methods = shared.assign(shared.create(null), superDef.methods, apiMethods);
@@ -2991,6 +3053,10 @@ function createComponentDef(Ctor) {
2991
3053
  disconnectedCallback = disconnectedCallback || superDef.disconnectedCallback;
2992
3054
  renderedCallback = renderedCallback || superDef.renderedCallback;
2993
3055
  errorCallback = errorCallback || superDef.errorCallback;
3056
+ formAssociatedCallback = formAssociatedCallback || superDef.formAssociatedCallback;
3057
+ formResetCallback = formResetCallback || superDef.formResetCallback;
3058
+ formDisabledCallback = formDisabledCallback || superDef.formDisabledCallback;
3059
+ formStateRestoreCallback = formStateRestoreCallback || superDef.formStateRestoreCallback;
2994
3060
  render = render || superDef.render;
2995
3061
  let shadowSupportMode = superDef.shadowSupportMode;
2996
3062
  if (!shared.isUndefined(ctorShadowSupportMode)) {
@@ -3000,6 +3066,10 @@ function createComponentDef(Ctor) {
3000
3066
  if (!shared.isUndefined(ctorRenderMode)) {
3001
3067
  renderMode = ctorRenderMode === 'light' ? 0 /* RenderMode.Light */ : 1 /* RenderMode.Shadow */;
3002
3068
  }
3069
+ let formAssociated = superDef.formAssociated;
3070
+ if (!shared.isUndefined(ctorFormAssociated)) {
3071
+ formAssociated = ctorFormAssociated;
3072
+ }
3003
3073
  const template = getComponentRegisteredTemplate(Ctor) || superDef.template;
3004
3074
  const name = Ctor.name || superDef.name;
3005
3075
  // installing observed fields into the prototype.
@@ -3015,10 +3085,15 @@ function createComponentDef(Ctor) {
3015
3085
  template,
3016
3086
  renderMode,
3017
3087
  shadowSupportMode,
3088
+ formAssociated,
3018
3089
  connectedCallback,
3019
3090
  disconnectedCallback,
3020
- renderedCallback,
3021
3091
  errorCallback,
3092
+ formAssociatedCallback,
3093
+ formDisabledCallback,
3094
+ formResetCallback,
3095
+ formStateRestoreCallback,
3096
+ renderedCallback,
3022
3097
  render,
3023
3098
  };
3024
3099
  // This is a no-op unless Lightning DevTools are enabled.
@@ -3095,6 +3170,7 @@ const lightingElementDef = {
3095
3170
  methods: EmptyObject,
3096
3171
  renderMode: 1 /* RenderMode.Shadow */,
3097
3172
  shadowSupportMode: "reset" /* ShadowSupportMode.Default */,
3173
+ formAssociated: undefined,
3098
3174
  wire: EmptyObject,
3099
3175
  bridge: BaseBridgeElement,
3100
3176
  template: defaultEmptyTemplate,
@@ -3804,6 +3880,10 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
3804
3880
  };
3805
3881
  let connectedCallback;
3806
3882
  let disconnectedCallback;
3883
+ let formAssociatedCallback;
3884
+ let formDisabledCallback;
3885
+ let formResetCallback;
3886
+ let formStateRestoreCallback;
3807
3887
  if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3808
3888
  connectedCallback = (elm) => {
3809
3889
  connectRootElement(elm);
@@ -3811,13 +3891,25 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
3811
3891
  disconnectedCallback = (elm) => {
3812
3892
  disconnectRootElement(elm);
3813
3893
  };
3894
+ formAssociatedCallback = (elm) => {
3895
+ runFormAssociatedCallback(elm);
3896
+ };
3897
+ formDisabledCallback = (elm) => {
3898
+ runFormDisabledCallback(elm);
3899
+ };
3900
+ formResetCallback = (elm) => {
3901
+ runFormResetCallback(elm);
3902
+ };
3903
+ formStateRestoreCallback = (elm) => {
3904
+ runFormStateRestoreCallback(elm);
3905
+ };
3814
3906
  }
3815
3907
  // Should never get a tag with upper case letter at this point; the compiler
3816
3908
  // should produce only tags with lowercase letters. However, the Java
3817
3909
  // compiler may generate tagnames with uppercase letters so - for backwards
3818
3910
  // compatibility, we lower case the tagname here.
3819
3911
  const normalizedTagname = sel.toLowerCase();
3820
- const elm = createCustomElement(normalizedTagname, upgradeCallback, connectedCallback, disconnectedCallback);
3912
+ const elm = createCustomElement(normalizedTagname, upgradeCallback, connectedCallback, disconnectedCallback, formAssociatedCallback, formDisabledCallback, formResetCallback, formStateRestoreCallback);
3821
3913
  vnode.elm = elm;
3822
3914
  vnode.vm = vm;
3823
3915
  linkNodeToShadow(elm, owner, renderer);
@@ -5635,8 +5727,10 @@ function computeShadowMode(def, owner, renderer) {
5635
5727
  // everything defaults to native when the synthetic shadow polyfill is unavailable.
5636
5728
  shadowMode = 0 /* ShadowMode.Native */;
5637
5729
  }
5638
- else if (lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE) {
5639
- if (def.shadowSupportMode === "any" /* ShadowSupportMode.Any */) {
5730
+ else if (lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE ||
5731
+ def.shadowSupportMode === "native" /* ShadowSupportMode.Native */) {
5732
+ if (def.shadowSupportMode === "any" /* ShadowSupportMode.Any */ ||
5733
+ def.shadowSupportMode === "native" /* ShadowSupportMode.Native */) {
5640
5734
  shadowMode = 0 /* ShadowMode.Native */;
5641
5735
  }
5642
5736
  else {
@@ -5945,6 +6039,48 @@ function forceRehydration(vm) {
5945
6039
  scheduleRehydration(vm);
5946
6040
  }
5947
6041
  }
6042
+ function runFormAssociatedCustomElementCallback(vm, faceCb) {
6043
+ const { renderMode, shadowMode, def: { formAssociated }, } = vm;
6044
+ // Technically the UpgradableConstructor always sets `static formAssociated = true` but silently fail here to match browser behavior.
6045
+ if (shared.isUndefined(formAssociated) || shared.isFalse(formAssociated)) {
6046
+ if (process.env.NODE_ENV !== 'production') {
6047
+ logWarn(`Form associated lifecycle methods must have the 'static formAssociated' value set in the component's prototype chain.`);
6048
+ }
6049
+ return;
6050
+ }
6051
+ if (shadowMode === 1 /* ShadowMode.Synthetic */ && renderMode !== 0 /* RenderMode.Light */) {
6052
+ throw new Error('Form associated lifecycle methods are not available in synthetic shadow. Please use native shadow or light DOM.');
6053
+ }
6054
+ invokeComponentCallback(vm, faceCb);
6055
+ }
6056
+ function runFormAssociatedCallback(elm) {
6057
+ const vm = getAssociatedVM(elm);
6058
+ const { formAssociatedCallback } = vm.def;
6059
+ if (!shared.isUndefined(formAssociatedCallback)) {
6060
+ runFormAssociatedCustomElementCallback(vm, formAssociatedCallback);
6061
+ }
6062
+ }
6063
+ function runFormDisabledCallback(elm) {
6064
+ const vm = getAssociatedVM(elm);
6065
+ const { formDisabledCallback } = vm.def;
6066
+ if (!shared.isUndefined(formDisabledCallback)) {
6067
+ runFormAssociatedCustomElementCallback(vm, formDisabledCallback);
6068
+ }
6069
+ }
6070
+ function runFormResetCallback(elm) {
6071
+ const vm = getAssociatedVM(elm);
6072
+ const { formResetCallback } = vm.def;
6073
+ if (!shared.isUndefined(formResetCallback)) {
6074
+ runFormAssociatedCustomElementCallback(vm, formResetCallback);
6075
+ }
6076
+ }
6077
+ function runFormStateRestoreCallback(elm) {
6078
+ const vm = getAssociatedVM(elm);
6079
+ const { formStateRestoreCallback } = vm.def;
6080
+ if (!shared.isUndefined(formStateRestoreCallback)) {
6081
+ runFormAssociatedCustomElementCallback(vm, formStateRestoreCallback);
6082
+ }
6083
+ }
5948
6084
 
5949
6085
  /*
5950
6086
  * Copyright (c) 2018, salesforce.com, inc.
@@ -6857,7 +6993,7 @@ function trackMutations(tmpl) {
6857
6993
  }
6858
6994
  function addLegacyStylesheetTokensShim(tmpl) {
6859
6995
  // When ENABLE_FROZEN_TEMPLATE is false, then we shim stylesheetTokens on top of stylesheetToken for anyone who
6860
- // is accessing the old internal API (backwards compat). Details: https://salesforce.quip.com/v1rmAFu2cKAr
6996
+ // is accessing the old internal API (backwards compat). Details: W-14210169
6861
6997
  shared.defineProperty(tmpl, 'stylesheetTokens', {
6862
6998
  enumerable: true,
6863
6999
  configurable: true,
@@ -6982,6 +7118,10 @@ exports.readonly = readonly;
6982
7118
  exports.registerComponent = registerComponent;
6983
7119
  exports.registerDecorators = registerDecorators;
6984
7120
  exports.registerTemplate = registerTemplate;
7121
+ exports.runFormAssociatedCallback = runFormAssociatedCallback;
7122
+ exports.runFormDisabledCallback = runFormDisabledCallback;
7123
+ exports.runFormResetCallback = runFormResetCallback;
7124
+ exports.runFormStateRestoreCallback = runFormStateRestoreCallback;
6985
7125
  exports.sanitizeAttribute = sanitizeAttribute;
6986
7126
  exports.setHooks = setHooks;
6987
7127
  exports.swapComponent = swapComponent;
@@ -6990,5 +7130,5 @@ exports.swapTemplate = swapTemplate;
6990
7130
  exports.track = track;
6991
7131
  exports.unwrap = unwrap;
6992
7132
  exports.wire = wire;
6993
- /** version: 3.4.0 */
7133
+ /** version: 3.6.0 */
6994
7134
  //# sourceMappingURL=index.cjs.js.map