UNPKG

8.32 kBTypeScriptView Raw
1/*
2 * Copyright (c) 2018, salesforce.com, inc.
3 * All rights reserved.
4 * SPDX-License-Identifier: MIT
5 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6 */
7
8/**
9 * Lightning Web Components core module
10 */
11
12declare module 'lwc' {
13 // backwards compatible type used for the old days when TS didn't support `event.composed`
14 interface ComposableEvent extends Event {
15 composed: boolean;
16 }
17
18 class HTMLElementTheGoodPart {
19 dispatchEvent(evt: Event): boolean;
20 addEventListener(
21 type: string,
22 listener: EventListenerOrEventListenerObject,
23 options?: boolean | AddEventListenerOptions
24 ): void;
25 removeEventListener(
26 type: string,
27 listener: EventListenerOrEventListenerObject,
28 options?: boolean | EventListenerOptions
29 ): void;
30 setAttributeNS(ns: string, attrName: string, value: any): void;
31 removeAttributeNS(ns: string, attrName: string): void;
32 removeAttribute(attrName: string): void;
33 setAttribute(attrName: string, value: any): void;
34 getAttribute(attrName: string): string | null;
35 getAttributeNS(ns: string, attrName: string): string | null;
36 getBoundingClientRect(): ClientRect;
37 querySelector<E extends Element = Element>(selectors: string): E | null;
38 querySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
39 getElementsByTagName(tagNameOrWildCard: string): HTMLCollectionOf<Element>;
40 getElementsByClassName(names: string): HTMLCollectionOf<Element>;
41 readonly tagName: string;
42 readonly classList: DOMTokenList;
43
44 // Default HTML Properties
45 dir: string;
46 id: string;
47 accessKey: string;
48 title: string;
49 lang: string;
50 hidden: boolean;
51 draggable: boolean;
52 tabIndex: number;
53
54 // Aria Properties
55 ariaAutoComplete: string | null;
56 ariaChecked: string | null;
57 ariaCurrent: string | null;
58 ariaDisabled: string | null;
59 ariaExpanded: string | null;
60 ariaHasPopup: string | null;
61 ariaHidden: string | null;
62 ariaInvalid: string | null;
63 ariaLabel: string | null;
64 ariaLevel: string | null;
65 ariaMultiLine: string | null;
66 ariaMultiSelectable: string | null;
67 ariaOrientation: string | null;
68 ariaPressed: string | null;
69 ariaReadOnly: string | null;
70 ariaRequired: string | null;
71 ariaSelected: string | null;
72 ariaSort: string | null;
73 ariaValueMax: string | null;
74 ariaValueMin: string | null;
75 ariaValueNow: string | null;
76 ariaValueText: string | null;
77 ariaLive: string | null;
78 ariaRelevant: string | null;
79 ariaAtomic: string | null;
80 ariaBusy: string | null;
81 ariaActiveDescendant: string | null;
82 ariaControls: string | null;
83 ariaDescribedBy: string | null;
84 ariaFlowTo: string | null;
85 ariaLabelledBy: string | null;
86 ariaOwns: string | null;
87 ariaPosInSet: string | null;
88 ariaSetSize: string | null;
89 ariaColCount: string | null;
90 ariaColIndex: string | null;
91 ariaDetails: string | null;
92 ariaErrorMessage: string | null;
93 ariaKeyShortcuts: string | null;
94 ariaModal: string | null;
95 ariaPlaceholder: string | null;
96 ariaRoleDescription: string | null;
97 ariaRowCount: string | null;
98 ariaRowIndex: string | null;
99 ariaRowSpan: string | null;
100 ariaColSpan: string | null;
101 role: string | null;
102 }
103
104 // @ts-ignore type-mismatch
105 interface ShadowRootTheGoodPart extends NodeSelector {
106 mode: string;
107 readonly activeElement: Element | null;
108 readonly host: HTMLElement;
109 readonly firstChild: Node | null;
110 readonly lastChild: Node | null;
111 readonly innerHTML: string;
112 readonly textContent: string;
113 readonly childNodes: Node[];
114 readonly delegatesFocus: boolean;
115 addEventListener(
116 type: string,
117 listener: EventListenerOrEventListenerObject,
118 options?: boolean | AddEventListenerOptions
119 ): void;
120 removeEventListener(
121 type: string,
122 listener: EventListenerOrEventListenerObject,
123 options?: boolean | EventListenerOptions
124 ): void;
125 hasChildNodes(): boolean;
126 compareDocumentPosition(otherNode: Node): number;
127 contains(otherNode: Node): boolean;
128 elementFromPoint(x: number, y: number): Element | null;
129 querySelector<K extends keyof HTMLElementTagNameMap>(
130 selectors: K
131 ): HTMLElementTagNameMap[K] | null;
132 querySelector<K extends keyof SVGElementTagNameMap>(
133 selectors: K
134 ): SVGElementTagNameMap[K] | null;
135 querySelector<E extends Element = Element>(selectors: string): E | null;
136 querySelectorAll<K extends keyof HTMLElementTagNameMap>(
137 selectors: K
138 ): NodeListOf<HTMLElementTagNameMap[K]>;
139 querySelectorAll<K extends keyof SVGElementTagNameMap>(
140 selectors: K
141 ): NodeListOf<SVGElementTagNameMap[K]>;
142 querySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
143 }
144
145 /**
146 * Base class for the Lightning Web Component JavaScript class
147 */
148 export class LightningElement extends HTMLElementTheGoodPart {
149 /**
150 * This static getter builds a Web Component class from a LWC constructor so it can be registered
151 * as a new element via customElements.define() at any given time. For example:
152 *
153 * ```
154 * import XComponent from 'namespace/element';
155 * customElements.define('x-component', XComponent.CustomElementConstructor);
156 * const elm = document.createElement('x-component');
157 * ```
158 */
159 static get CustomElementConstructor(): typeof HTMLElement;
160 /**
161 * Called when the element is inserted in a document
162 */
163 connectedCallback(): void;
164 /**
165 * Called when the element is removed from a document
166 */
167 disconnectedCallback(): void;
168 /**
169 * Called after every render of the component
170 */
171 renderedCallback(): void;
172 /**
173 * Called when a descendant component throws an error in one of its lifecycle hooks
174 */
175 errorCallback(error: Error, stack: string): void;
176
177 readonly template: ShadowRootTheGoodPart;
178 readonly shadowRoot: null;
179 }
180
181 /**
182 * Decorator to mark public reactive properties
183 */
184 export const api: PropertyDecorator;
185
186 /**
187 * Decorator to mark private reactive properties
188 */
189 export const track: PropertyDecorator;
190
191 /**
192 * Decorator factory to wire a property or method to a wire adapter data source
193 * @param getType imperative accessor for the data source
194 * @param config configuration object for the accessor
195 */
196 export function wire(getType: (config?: any) => any, config?: any): PropertyDecorator;
197
198 type WireConfigValue = Record<string, any>;
199 type ContextValue = Record<string, any>;
200
201 interface WireAdapter {
202 update(config: WireConfigValue, context?: ContextValue): void;
203 connect(): void;
204 disconnect(): void;
205 }
206
207 type WireDataCallback = (value: any) => void;
208 type WireAdapterSchemaValue = 'optional' | 'required';
209
210 interface ContextConsumer {
211 provide(newContext: ContextValue): void;
212 }
213
214 interface ContextProviderOptions {
215 consumerConnectedCallback: (consumer: ContextConsumer) => void;
216 consumerDisconnectedCallback?: (consumer: ContextConsumer) => void;
217 }
218
219 interface WireAdapterConstructor {
220 new (callback: WireDataCallback): WireAdapter;
221 configSchema?: Record<string, WireAdapterSchemaValue>;
222 contextSchema?: Record<string, WireAdapterSchemaValue>;
223 }
224
225 type Contextualizer = (elm: EventTarget, options: ContextProviderOptions) => void;
226 export function createContextProvider(config: WireAdapterConstructor): Contextualizer;
227}