@lwc/engine-core 4.0.0-alpha.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -96,11 +96,6 @@ This experimental API enables the identification of LWC constructors.
96
96
  This experimental API enables the creation of a reactive readonly membrane around any object
97
97
  value.
98
98
 
99
- ### register()
100
-
101
- This experimental API enables the registration of 'services' in LWC by exposing hooks into the
102
- component life-cycle.
103
-
104
99
  ### setHooks()
105
100
 
106
101
  This experimental API allows setting overridable hooks with an application specific implementation.
@@ -1,8 +1,9 @@
1
1
  import { SlotSet } from './vm';
2
2
  import { LightningElementConstructor } from './base-lightning-element';
3
- import { Key, VComment, VCustomElement, VElement, VElementData, VFragment, VNode, VNodes, VScopedSlotFragment, VStatic, VStaticElementData, VText } from './vnodes';
3
+ import { Key, VComment, VCustomElement, VElement, VElementData, VFragment, VNode, VNodes, VScopedSlotFragment, VStatic, VText, VStaticPart, VStaticPartData } from './vnodes';
4
+ declare function sp(partId: number, data: VStaticPartData): VStaticPart;
4
5
  declare function ssf(slotName: unknown, factory: (value: any, key: any) => VFragment): VScopedSlotFragment;
5
- declare function st(fragment: Element, key: Key, data?: VStaticElementData): VStatic;
6
+ declare function st(fragment: Element, key: Key, parts?: VStaticPart[]): VStatic;
6
7
  declare function fr(key: Key, children: VNodes, stable: 0 | 1): VFragment;
7
8
  declare function h(sel: string, data: VElementData, children?: VNodes): VElement;
8
9
  declare function ti(value: any): number;
@@ -56,6 +57,7 @@ declare const api: Readonly<{
56
57
  shc: typeof shc;
57
58
  ssf: typeof ssf;
58
59
  ddc: typeof ddc;
60
+ sp: typeof sp;
59
61
  }>;
60
62
  export default api;
61
63
  export type RenderAPI = typeof api;
@@ -1,6 +1,7 @@
1
+ import { LightningElement } from './base-lightning-element';
1
2
  export interface HTMLElementConstructor {
2
3
  prototype: HTMLElement;
3
4
  new (): HTMLElement;
4
5
  }
5
- export declare function HTMLBridgeElementFactory(SuperClass: HTMLElementConstructor, props: string[], methods: string[]): HTMLElementConstructor;
6
+ export declare function HTMLBridgeElementFactory(SuperClass: HTMLElementConstructor, publicProperties: string[], methods: string[], observedFields: string[], proto: LightningElement | null, hasCustomSuperClass: boolean): HTMLElementConstructor;
6
7
  export declare const BaseBridgeElement: HTMLElementConstructor;
@@ -17,10 +17,11 @@ 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
  }
23
- type HTMLElementTheGoodParts = Pick<Object, 'toString'> & Pick<HTMLElement, 'accessKey' | 'addEventListener' | 'children' | 'childNodes' | 'classList' | 'dir' | 'dispatchEvent' | 'draggable' | 'firstChild' | 'firstElementChild' | 'getAttribute' | 'getAttributeNS' | 'getBoundingClientRect' | 'getElementsByClassName' | 'getElementsByTagName' | 'hasAttribute' | 'hasAttributeNS' | 'hidden' | 'id' | 'isConnected' | 'lang' | 'lastChild' | 'lastElementChild' | 'ownerDocument' | 'querySelector' | 'querySelectorAll' | 'removeAttribute' | 'removeAttributeNS' | 'removeEventListener' | 'setAttribute' | 'setAttributeNS' | 'spellcheck' | 'tabIndex' | 'tagName' | 'title'>;
24
+ type HTMLElementTheGoodParts = Pick<Object, 'toString'> & Pick<HTMLElement, 'accessKey' | 'addEventListener' | 'attachInternals' | 'children' | 'childNodes' | 'classList' | 'dir' | 'dispatchEvent' | 'draggable' | 'firstChild' | 'firstElementChild' | 'getAttribute' | 'getAttributeNS' | 'getBoundingClientRect' | 'getElementsByClassName' | 'getElementsByTagName' | 'hasAttribute' | 'hasAttributeNS' | 'hidden' | 'id' | 'isConnected' | 'lang' | 'lastChild' | 'lastElementChild' | 'ownerDocument' | 'querySelector' | 'querySelectorAll' | 'removeAttribute' | 'removeAttributeNS' | 'removeEventListener' | 'setAttribute' | 'setAttributeNS' | 'spellcheck' | 'tabIndex' | 'tagName' | 'title'>;
24
25
  type RefNodes = {
25
26
  [name: string]: Element;
26
27
  };
@@ -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 { createVM, connectRootElement, disconnectRootElement, getAssociatedVMIfPresent, } 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';
@@ -18,7 +18,6 @@ export { getComponentConstructor } from './get-component-constructor';
18
18
  export type { RendererAPI, LifecycleCallback } from './renderer';
19
19
  export type { ConfigValue as WireConfigValue, ContextValue as WireContextValue, DataCallback, WireAdapter, WireAdapterConstructor, WireAdapterSchemaValue, WireContextSubscriptionPayload, WireContextSubscriptionCallback, } from './wiring';
20
20
  export { LightningElement } from './base-lightning-element';
21
- export { register } from './services';
22
21
  export { default as api } from './decorators/api';
23
22
  export { default as track } from './decorators/track';
24
23
  export { default as wire } from './decorators/wire';
@@ -1,3 +1,3 @@
1
1
  import { RendererAPI } from '../renderer';
2
- import { VBaseElement, VStatic } from '../vnodes';
3
- export declare function applyEventListeners(vnode: VBaseElement | VStatic, renderer: RendererAPI): void;
2
+ import { VBaseElement, VStaticPart } from '../vnodes';
3
+ export declare function applyEventListeners(vnode: VBaseElement | VStaticPart, renderer: RendererAPI): void;
@@ -0,0 +1,3 @@
1
+ import { VM } from '../vm';
2
+ import { VBaseElement, VStaticPart } from '../vnodes';
3
+ export declare function applyRefs(vnode: VBaseElement | VStaticPart, owner: VM): void;
@@ -0,0 +1,11 @@
1
+ import { VStatic } from '../vnodes';
2
+ import { RendererAPI } from '../renderer';
3
+ /**
4
+ * Given an array of static parts, do all the mounting required for these parts.
5
+ *
6
+ * @param root - the root element
7
+ * @param vnode - the parent VStatic
8
+ * @param renderer - the renderer to use
9
+ * @param mount - true this is a first (mount) render as opposed to a subsequent (patch) render
10
+ */
11
+ export declare function applyStaticParts(root: Element, vnode: VStatic, renderer: RendererAPI, mount: boolean): void;
@@ -14,6 +14,7 @@ export interface RendererAPI {
14
14
  createText: (content: string) => N;
15
15
  createComment: (content: string) => N;
16
16
  nextSibling: (node: N) => N | null;
17
+ previousSibling: (node: N) => N | null;
17
18
  attachShadow: (element: E, options: ShadowRootInit) => N;
18
19
  getProperty: (node: N, key: string) => any;
19
20
  setProperty: (node: N, key: string, value: any) => void;
@@ -41,8 +42,10 @@ export interface RendererAPI {
41
42
  isConnected: (node: N) => boolean;
42
43
  insertStylesheet: (content: string, target?: ShadowRoot) => void;
43
44
  assertInstanceOfHTMLElement: (elm: any, msg: string) => void;
44
- createCustomElement: (tagName: string, upgradeCallback: LifecycleCallback, connectedCallback: LifecycleCallback, disconnectedCallback: LifecycleCallback) => E;
45
+ createCustomElement: (tagName: string, upgradeCallback: LifecycleCallback, connectedCallback?: LifecycleCallback, disconnectedCallback?: LifecycleCallback, formAssociatedCallback?: LifecycleCallback, formDisabledCallback?: LifecycleCallback, formResetCallback?: LifecycleCallback, formStateRestoreCallback?: LifecycleCallback) => E;
46
+ defineCustomElement: (tagName: string, connectedCallback?: LifecycleCallback, disconnectedCallback?: LifecycleCallback) => void;
45
47
  ownerDocument(elm: E): Document;
46
48
  registerContextConsumer: (element: E, adapterContextToken: string, subscriptionPayload: WireContextSubscriptionPayload) => void;
49
+ attachInternals: (elm: E) => ElementInternals;
47
50
  }
48
51
  export {};
@@ -12,14 +12,14 @@ export type StylesheetFactory = (stylesheetToken: string | undefined, useActualH
12
12
  * @import CSS declaration).
13
13
  */
14
14
  export type TemplateStylesheetFactories = Array<StylesheetFactory | TemplateStylesheetFactories>;
15
- export declare function updateStylesheetToken(vm: VM, template: Template): void;
15
+ export declare function updateStylesheetToken(vm: VM, template: Template, legacy: boolean): void;
16
16
  export declare function getStylesheetsContent(vm: VM, template: Template): string[];
17
17
  /**
18
18
  * If the component that is currently being rendered uses scoped styles,
19
19
  * this returns the unique token for that scoped stylesheet. Otherwise
20
20
  * it returns null.
21
21
  */
22
- export declare function getScopeTokenClass(owner: VM): string | null;
22
+ export declare function getScopeTokenClass(owner: VM, legacy: boolean): string | null;
23
23
  /**
24
24
  * This function returns the host style token for a custom element if it
25
25
  * exists. Otherwise it returns null.
@@ -10,6 +10,8 @@ export interface Template {
10
10
  stylesheets?: TemplateStylesheetFactories;
11
11
  /** The string used for synthetic shadow style scoping and light DOM style scoping. */
12
12
  stylesheetToken?: string;
13
+ /** Same as the above, but for legacy use cases (pre-LWC v3.0.0) */
14
+ legacyStylesheetToken?: string;
13
15
  /** Render mode for the template. Could be light or undefined (which means it's shadow) */
14
16
  renderMode?: 'light';
15
17
  /** True if this template contains template refs, undefined or false otherwise */
@@ -1,6 +1,4 @@
1
1
  import { StylesheetFactory, TemplateStylesheetFactories } from './stylesheet';
2
- import { VM } from './vm';
3
- import { VBaseElement, VStatic } from './vnodes';
4
2
  type Callback = () => void;
5
3
  export declare const SPACE_CHAR = 32;
6
4
  export declare const EmptyObject: any;
@@ -16,6 +14,5 @@ export declare function cloneAndOmitKey(object: {
16
14
  [key: string]: any;
17
15
  };
18
16
  export declare function flattenStylesheets(stylesheets: TemplateStylesheetFactories): StylesheetFactory[];
19
- export declare function setRefVNode(vm: VM, ref: string, vnode: VBaseElement | VStatic): void;
20
17
  export declare function assertNotProd(): void;
21
18
  export {};
@@ -4,7 +4,7 @@ import { Template } from './template';
4
4
  import { ComponentDef } from './def';
5
5
  import { LightningElement, LightningElementConstructor } from './base-lightning-element';
6
6
  import { ReactiveObserver } from './mutation-tracker';
7
- import { VNodes, VCustomElement, VNode, VBaseElement, VStatic } from './vnodes';
7
+ import { VNodes, VCustomElement, VNode, VBaseElement, VStaticPart } from './vnodes';
8
8
  import { TemplateStylesheetFactories } from './stylesheet';
9
9
  type ShadowRootMode = 'open' | 'closed';
10
10
  export interface TemplateCache {
@@ -31,7 +31,8 @@ export declare const enum ShadowMode {
31
31
  }
32
32
  export declare const enum ShadowSupportMode {
33
33
  Any = "any",
34
- Default = "reset"
34
+ Default = "reset",
35
+ Native = "native"
35
36
  }
36
37
  export declare const enum LwcDomMode {
37
38
  Manual = "manual"
@@ -43,6 +44,12 @@ export interface Context {
43
44
  hasTokenInClass: boolean | undefined;
44
45
  /** True if a stylesheetToken was added to the host attributes */
45
46
  hasTokenInAttribute: boolean | undefined;
47
+ /** The legacy string used for synthetic shadow DOM and light DOM style scoping. */
48
+ legacyStylesheetToken: string | undefined;
49
+ /** True if a legacyStylesheetToken was added to the host class */
50
+ hasLegacyTokenInClass: boolean | undefined;
51
+ /** True if a legacyStylesheetToken was added to the host attributes */
52
+ hasLegacyTokenInAttribute: boolean | undefined;
46
53
  /** Whether or not light DOM scoped styles are present in the stylesheets. */
47
54
  hasScopedStyles: boolean | undefined;
48
55
  /** The VNodes injected in all the shadow trees to apply the associated component stylesheets. */
@@ -56,7 +63,7 @@ export interface Context {
56
63
  wiredDisconnecting: Array<() => void>;
57
64
  }
58
65
  export type RefVNodes = {
59
- [name: string]: VBaseElement | VStatic;
66
+ [name: string]: VBaseElement | VStaticPart;
60
67
  };
61
68
  export interface VM<N = HostNode, E = HostElement> {
62
69
  /** The host element */
@@ -152,6 +159,10 @@ export declare function createVM<HostNode, HostElement>(elm: HostElement, ctor:
152
159
  tagName: string;
153
160
  hydrated?: boolean;
154
161
  }): VM;
162
+ export declare function computeShadowAndRenderMode(Ctor: LightningElementConstructor, renderer: RendererAPI): {
163
+ renderMode: RenderMode;
164
+ shadowMode: ShadowMode;
165
+ };
155
166
  export declare function associateVM(obj: VMAssociable, vm: VM): void;
156
167
  export declare function getAssociatedVM(obj: VMAssociable): VM;
157
168
  export declare function getAssociatedVMIfPresent(obj: VMAssociable): VM | undefined;
@@ -161,4 +172,10 @@ export declare function resetComponentRoot(vm: VM): void;
161
172
  export declare function scheduleRehydration(vm: VM): void;
162
173
  export declare function runWithBoundaryProtection(vm: VM, owner: VM | null, pre: () => void, job: () => void, post: () => void): void;
163
174
  export declare function forceRehydration(vm: VM): void;
175
+ export declare function runFormAssociatedCustomElementCallback(vm: VM, faceCb: () => void): void;
176
+ export declare function runFormAssociatedCallback(elm: HTMLElement): void;
177
+ export declare function runFormDisabledCallback(elm: HTMLElement): void;
178
+ export declare function runFormResetCallback(elm: HTMLElement): void;
179
+ export declare function runFormStateRestoreCallback(elm: HTMLElement): void;
180
+ export declare function resetRefVNodes(vm: VM): void;
164
181
  export {};
@@ -27,13 +27,18 @@ export interface VScopedSlotFragment extends BaseVNode {
27
27
  type: VNodeType.ScopedSlotFragment;
28
28
  slotName: unknown;
29
29
  }
30
- export type VStaticElementData = Pick<VElementData, 'on' | 'ref'>;
30
+ export interface VStaticPart {
31
+ readonly partId: number;
32
+ readonly data: VStaticPartData;
33
+ elm: Element | undefined;
34
+ }
35
+ export type VStaticPartData = Pick<VElementData, 'on' | 'ref'>;
31
36
  export interface VStatic extends BaseVNode {
32
37
  readonly type: VNodeType.Static;
33
38
  readonly sel: undefined;
34
39
  readonly key: Key;
35
40
  readonly fragment: Element;
36
- readonly data: VStaticElementData | undefined;
41
+ readonly parts: VStaticPart[] | undefined;
37
42
  elm: Element | undefined;
38
43
  }
39
44
  export interface VFragment extends BaseVNode, BaseVParent {
@@ -82,7 +87,6 @@ export interface VNodeData {
82
87
  readonly on?: Readonly<Record<string, (event: Event) => any>>;
83
88
  readonly svg?: boolean;
84
89
  readonly renderer?: RendererAPI;
85
- readonly spread?: Readonly<Record<string, any>>;
86
90
  }
87
91
  export interface VElementData extends VNodeData {
88
92
  readonly key: Key;