@rusticarcade/palette 0.4.0 → 0.7.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 +1 -1
- package/dist/dev/index.js +588 -722
- package/dist/prod/index.d.ts +154 -360
- package/dist/prod/index.js +1 -1
- package/dist/test/index.d.ts +128 -317
- package/dist/test/index.js +14 -210
- package/package.json +1 -1
package/dist/test/index.d.ts
CHANGED
|
@@ -13,29 +13,15 @@ type StateListener<Shape> = (state: Shape) => void;
|
|
|
13
13
|
*
|
|
14
14
|
* The State class wraps stateful data and provides an API for mutating the data
|
|
15
15
|
* while listeners subscribe to meaningful updates.
|
|
16
|
-
*
|
|
17
|
-
* Modify state with setters, mutators, transactions, or proxied updates with
|
|
18
|
-
* deep reactivity and array mutation support built in.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
*
|
|
22
|
-
* ```typescript
|
|
23
|
-
* const state = new State({count: 1});
|
|
24
|
-
* state.addListener(data => console.log(data))
|
|
25
|
-
*
|
|
26
|
-
* state.set("count", 2); // Prints "2"
|
|
27
|
-
* state.set("count", 2); // Nothing happens, no change
|
|
28
|
-
* state.live.count = 3; // Prints "3"
|
|
29
|
-
* ```
|
|
30
16
|
*/
|
|
31
17
|
declare class State<Shape extends object> {
|
|
18
|
+
static isState<T extends object>(value: unknown): value is State<T>;
|
|
32
19
|
private _data;
|
|
33
20
|
private _listeners;
|
|
34
21
|
private _proxy?;
|
|
35
22
|
private _proxyCache;
|
|
36
23
|
private _reverseProxyCache;
|
|
37
|
-
|
|
38
|
-
constructor(initialData: Shape, onChange?: StateListener<Shape>);
|
|
24
|
+
constructor(initialData: Shape, listener?: StateListener<Shape>);
|
|
39
25
|
/**
|
|
40
26
|
* Lazily create and cache proxies into the state for reactive updates on
|
|
41
27
|
* nested values.
|
|
@@ -65,7 +51,7 @@ declare class State<Shape extends object> {
|
|
|
65
51
|
* This is a direct reference to the internal state. It is marked as Readonly
|
|
66
52
|
* to help prevent accidental changes. Never edit this value directly.
|
|
67
53
|
*/
|
|
68
|
-
get
|
|
54
|
+
get raw(): Readonly<Shape>;
|
|
69
55
|
/**
|
|
70
56
|
* Live reactive accessor for state data. Deeply nested changes trigger
|
|
71
57
|
* automatic updates, including array, Map, and Set mutations.
|
|
@@ -76,10 +62,6 @@ declare class State<Shape extends object> {
|
|
|
76
62
|
*/
|
|
77
63
|
get live(): Shape;
|
|
78
64
|
/**
|
|
79
|
-
* Indicates if this state is currently locked (true) or not (false)
|
|
80
|
-
*/
|
|
81
|
-
get isLocked(): boolean;
|
|
82
|
-
/**
|
|
83
65
|
* Add a handler function for when this state changes.
|
|
84
66
|
*
|
|
85
67
|
* Listeners are invoked in the order they are registered and are passed a
|
|
@@ -98,14 +80,6 @@ declare class State<Shape extends object> {
|
|
|
98
80
|
*
|
|
99
81
|
* The value is returned as Readonly to prevent accidental state mutations.
|
|
100
82
|
* To mutate stateful properties, use {@link set} or {@link patch} instead.
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
*
|
|
104
|
-
* ```typescript
|
|
105
|
-
* const state = new State({ count: 1 });
|
|
106
|
-
* console.log(state.get("count")); // 1
|
|
107
|
-
* ```
|
|
108
|
-
*
|
|
109
83
|
*/
|
|
110
84
|
get: <K extends keyof Shape>(key: K) => Readonly<Shape[K]>;
|
|
111
85
|
/**
|
|
@@ -114,13 +88,6 @@ declare class State<Shape extends object> {
|
|
|
114
88
|
*
|
|
115
89
|
* The object returned from this function can be edited without modifying the
|
|
116
90
|
* actual internal state.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
*
|
|
120
|
-
* ```typescript
|
|
121
|
-
* const snap = state.snapshot();
|
|
122
|
-
* snap.count += 1;
|
|
123
|
-
* state.patch(snap);
|
|
124
91
|
* ```
|
|
125
92
|
*/
|
|
126
93
|
snapshot: () => Shape;
|
|
@@ -137,44 +104,17 @@ declare class State<Shape extends object> {
|
|
|
137
104
|
* state.set("count", 2); // State is now { count: 2, color: "red" }
|
|
138
105
|
* ```
|
|
139
106
|
*/
|
|
140
|
-
set: <K extends keyof Shape>(key: K, value: Shape[K]) =>
|
|
107
|
+
set: <K extends keyof Shape>(key: K, value: Shape[K]) => State<Shape>;
|
|
141
108
|
/**
|
|
142
109
|
* Set multiple stateful properties at once, leaving omitted properties
|
|
143
110
|
* unchanged.
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
*
|
|
147
|
-
* Patch a partial state, updating all listed properties at once
|
|
148
|
-
*
|
|
149
|
-
* ```typescript
|
|
150
|
-
* const state = new State({
|
|
151
|
-
* weather: "sunny",
|
|
152
|
-
* temperature: 30,
|
|
153
|
-
* humidity: 70,
|
|
154
|
-
* });
|
|
155
|
-
*
|
|
156
|
-
* // Leaves `temperature` unchanged
|
|
157
|
-
* state.patch({
|
|
158
|
-
* weather: "cloudy",
|
|
159
|
-
* humidity: 50,
|
|
160
|
-
* });
|
|
161
|
-
* ```
|
|
162
111
|
*/
|
|
163
112
|
patch: (patch: Partial<Shape>) => State<Shape>;
|
|
164
113
|
/**
|
|
165
|
-
* Fully replace the current state data and force
|
|
166
|
-
* updated data immediately.
|
|
114
|
+
* Fully replace the current state data and force an update
|
|
167
115
|
*/
|
|
168
116
|
replace: (state: Shape) => State<Shape>;
|
|
169
117
|
/**
|
|
170
|
-
* Lock this State instance, preventing further external changes
|
|
171
|
-
*/
|
|
172
|
-
lock: () => State<Shape>;
|
|
173
|
-
/**
|
|
174
|
-
* Unlock this State instance, allowing further external changes
|
|
175
|
-
*/
|
|
176
|
-
unlock: () => State<Shape>;
|
|
177
|
-
/**
|
|
178
118
|
* Apply complex updates to the state using a mutator function.
|
|
179
119
|
*
|
|
180
120
|
* The mutator function takes one parameter which is a structuredClone copy of
|
|
@@ -182,87 +122,6 @@ declare class State<Shape extends object> {
|
|
|
182
122
|
* patched in to the state.
|
|
183
123
|
*/
|
|
184
124
|
mutate: (mutator: (current: Shape) => Shape) => State<Shape>;
|
|
185
|
-
/**
|
|
186
|
-
* Perform an async mutation of the state, optionally locking the state during
|
|
187
|
-
* the process.
|
|
188
|
-
* @param mutator A function to mutate and return the new state
|
|
189
|
-
* @param lock If `true`, lock the state until the mutator completes
|
|
190
|
-
*/
|
|
191
|
-
mutateAsync: (mutator: (current: Shape) => Promise<Shape>, lock?: boolean) => Promise<State<Shape>>;
|
|
192
|
-
/**
|
|
193
|
-
* Perform a transaction-style set of actions defined within a function.
|
|
194
|
-
*
|
|
195
|
-
* The provided function can do anything, beyond just setting state. Any
|
|
196
|
-
* uncaught errors thrown from within the function will cause the transaction
|
|
197
|
-
* to fail and the state to automatically roll back to the last valid state.
|
|
198
|
-
*
|
|
199
|
-
* During a transaction, this state instance will be locked, preventing other
|
|
200
|
-
* changes.
|
|
201
|
-
*
|
|
202
|
-
* Transactions will always result in a state update when successful.
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
*
|
|
206
|
-
* Transactions with locking and rollback support
|
|
207
|
-
*
|
|
208
|
-
* ```typescript
|
|
209
|
-
* const state = new State({count: 1});
|
|
210
|
-
*
|
|
211
|
-
* state.transaction(async (s) => {
|
|
212
|
-
* // `s` is a full State object you can safely manipulate
|
|
213
|
-
* s.set("count", 10);
|
|
214
|
-
* });
|
|
215
|
-
* state.get("count"); // => 10;
|
|
216
|
-
*
|
|
217
|
-
* // Errors inside the transaction roll back the state
|
|
218
|
-
* state.transaction(async (s) => {
|
|
219
|
-
* s.set("count", 100);
|
|
220
|
-
* throw new Error();
|
|
221
|
-
* });
|
|
222
|
-
* state.get("count"); // => 10;
|
|
223
|
-
*/
|
|
224
|
-
transaction: (fn: (state: State<Shape>) => void) => boolean;
|
|
225
|
-
/**
|
|
226
|
-
* Perform a transaction-style set of actions defined within an async function
|
|
227
|
-
*
|
|
228
|
-
* The provided function can do anything, beyond just setting state. Any
|
|
229
|
-
* uncaught errors thrown from within the function will cause the transaction
|
|
230
|
-
* to fail and the state to automatically roll back to the last valid state.
|
|
231
|
-
*
|
|
232
|
-
* During a transaction, this state instance will be locked, preventing other
|
|
233
|
-
* changes.
|
|
234
|
-
*
|
|
235
|
-
* Transactions will always result in a state update when successful.
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
*
|
|
239
|
-
* Transactions with locking and rollback support
|
|
240
|
-
*
|
|
241
|
-
* ```typescript
|
|
242
|
-
* const state = new State({count: 1});
|
|
243
|
-
*
|
|
244
|
-
* // Awaiting the result of a transaction
|
|
245
|
-
* await state.transactionAsync(async (s) => {
|
|
246
|
-
* // `s` is a full State object you can safely manipulate
|
|
247
|
-
* s.set("count", 10);
|
|
248
|
-
* });
|
|
249
|
-
* state.get("count"); // => 10;
|
|
250
|
-
*
|
|
251
|
-
* // Errors inside the transaction roll back the state
|
|
252
|
-
* await state.transactionAsync(async (s) => {
|
|
253
|
-
* s.set("count", 100);
|
|
254
|
-
* throw new Error();
|
|
255
|
-
* });
|
|
256
|
-
* state.get("count"); // => 10;
|
|
257
|
-
*
|
|
258
|
-
* // If you forget to await the transaction, its still locked
|
|
259
|
-
* state.transactionAsync(async (s) => {
|
|
260
|
-
* await waitSeconds(1);
|
|
261
|
-
* });
|
|
262
|
-
* state.set("count", 1); // Error: State is locked!
|
|
263
|
-
* ```
|
|
264
|
-
*/
|
|
265
|
-
transactionAsync: (fn: (state: State<Shape>) => Promise<void>) => Promise<boolean>;
|
|
266
125
|
}
|
|
267
126
|
type ParsedNotation = {
|
|
268
127
|
/** The raw string representation of the parsed notation */
|
|
@@ -283,6 +142,13 @@ declare const enum Directive {
|
|
|
283
142
|
ElseIf = "::else-if",
|
|
284
143
|
Else = "::else"
|
|
285
144
|
}
|
|
145
|
+
declare const enum UpdateType {
|
|
146
|
+
Conditional = "cond",
|
|
147
|
+
Tag = "tag",
|
|
148
|
+
Attribute = "attr",
|
|
149
|
+
List = "list",
|
|
150
|
+
Swap = "swap"
|
|
151
|
+
}
|
|
286
152
|
type ConditionalRenderSchemeBranch = {
|
|
287
153
|
type: Directive.If | Directive.ElseIf;
|
|
288
154
|
notation: ParsedNotation;
|
|
@@ -294,27 +160,27 @@ type ConditionalRenderSchemeBranch = {
|
|
|
294
160
|
branchTemplateHTML: string;
|
|
295
161
|
};
|
|
296
162
|
interface ConditionalRenderScheme {
|
|
297
|
-
type:
|
|
163
|
+
type: UpdateType.Conditional;
|
|
298
164
|
branches: ConditionalRenderSchemeBranch[];
|
|
299
165
|
}
|
|
300
166
|
interface AttributeUpdateScheme {
|
|
301
|
-
type:
|
|
167
|
+
type: UpdateType.Attribute;
|
|
302
168
|
notation: ParsedNotation;
|
|
303
169
|
attribute: string;
|
|
304
170
|
nodeRef: string;
|
|
305
171
|
}
|
|
306
172
|
interface TagChangeScheme {
|
|
307
|
-
type:
|
|
173
|
+
type: UpdateType.Tag;
|
|
308
174
|
notation: ParsedNotation;
|
|
309
175
|
nodeRef: string;
|
|
310
176
|
}
|
|
311
177
|
interface ContentSwapScheme {
|
|
312
|
-
type:
|
|
178
|
+
type: UpdateType.Swap;
|
|
313
179
|
notation: ParsedNotation;
|
|
314
180
|
nodeRef: string;
|
|
315
181
|
}
|
|
316
182
|
interface ListRenderScheme {
|
|
317
|
-
type:
|
|
183
|
+
type: UpdateType.List;
|
|
318
184
|
notation: ParsedNotation;
|
|
319
185
|
keyNotation: ParsedNotation;
|
|
320
186
|
nodeRef: string;
|
|
@@ -344,20 +210,33 @@ type TemplateContext = {
|
|
|
344
210
|
* Leverages a simple syntax to provide accessors to template data from one of
|
|
345
211
|
* four categories, based on use case:
|
|
346
212
|
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
213
|
+
* | Prefix | Namespace |
|
|
214
|
+
* | ------ | ------------------------------------------------ |
|
|
215
|
+
* | `@` | The `attr` namespace (host element attributes) |
|
|
216
|
+
* | `$` | The `state` namespace (component reactive state) |
|
|
217
|
+
* | `*` | The `data` namespace (component computed props) |
|
|
218
|
+
* | `#` | The `item` namespace (list item context) |
|
|
353
219
|
*
|
|
354
220
|
* Bind attributes to a value using the `:attribute` syntax:
|
|
355
221
|
*
|
|
356
222
|
* ```html
|
|
357
223
|
* <div :id="$id" :class="@classname"></div>
|
|
358
224
|
* ```
|
|
225
|
+
*
|
|
226
|
+
* Or use directives with notations for advanced templating:
|
|
227
|
+
*
|
|
228
|
+
* ```html
|
|
229
|
+
* <div ::if="*showList">
|
|
230
|
+
* <ul>
|
|
231
|
+
* <li ::each="$items" ::key="#id">
|
|
232
|
+
* <span ::swap="#content"></span>
|
|
233
|
+
* </li>
|
|
234
|
+
* </ul>
|
|
235
|
+
* </div>
|
|
236
|
+
* ```
|
|
359
237
|
*/
|
|
360
238
|
declare class Template {
|
|
239
|
+
static isTemplate(value: unknown): value is Template;
|
|
361
240
|
/**
|
|
362
241
|
* Properties related to the global Template build cache.
|
|
363
242
|
*
|
|
@@ -426,16 +305,6 @@ declare class Template {
|
|
|
426
305
|
}
|
|
427
306
|
type EventName = keyof GlobalEventHandlersEventMap;
|
|
428
307
|
type EventHandler<K extends EventName = EventName> = (event: GlobalEventHandlersEventMap[K]) => void;
|
|
429
|
-
interface LiveAttributes<State extends object = {}> {
|
|
430
|
-
[name: string]: {
|
|
431
|
-
onChange?: (this: Component<State>, current: string | null, previous: string | null) => void;
|
|
432
|
-
reflect?: (this: Component<State>) => unknown;
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
type ComputedProperties<StateShape extends object = {}> = Record<string, unknown> | ((this: Component<StateShape>) => Record<string, unknown>);
|
|
436
|
-
type ComponentStyles = CSSStyleSheet | CSSStyleSheet[] | string;
|
|
437
|
-
type AttributeMap = Map<string, string | null>;
|
|
438
|
-
type StateInitializer<Shape extends object = {}> = Shape | State<Shape> | ((this: Component<Shape>) => Shape | State<Shape>);
|
|
439
308
|
declare enum RootMode {
|
|
440
309
|
Closed = "closed",
|
|
441
310
|
Open = "open"
|
|
@@ -446,133 +315,57 @@ declare enum RootMode {
|
|
|
446
315
|
* managed attributes, and dynamic templating.
|
|
447
316
|
*/
|
|
448
317
|
declare abstract class Component<StateShape extends object = {}> extends HTMLElement {
|
|
449
|
-
/** The HTML tag name to use for this Component */
|
|
450
|
-
static tagName: string;
|
|
451
|
-
/** An HTML Template element for this element to use. */
|
|
452
|
-
static template: HTMLTemplateElement | Template;
|
|
453
318
|
/**
|
|
454
|
-
*
|
|
319
|
+
* Check if a value is a Component instance
|
|
455
320
|
*/
|
|
456
|
-
static
|
|
321
|
+
static isComponent(value: unknown): value is Component;
|
|
457
322
|
/**
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
* @remarks
|
|
461
|
-
* If you use the {@link define} factory helper, this value will be
|
|
462
|
-
* automatically merged with a list of any defined {@link liveAttributes}.
|
|
323
|
+
* Check if a value is a Component class
|
|
463
324
|
*/
|
|
325
|
+
static isComponentClass(value: unknown): value is typeof Component;
|
|
326
|
+
static readComponentTagName(componentClass: typeof Component): string;
|
|
327
|
+
/** The HTML tag name to use for this Component */
|
|
328
|
+
static tagName: string;
|
|
329
|
+
/** An HTML Template element for this element to use. */
|
|
330
|
+
static template: HTMLTemplateElement | Template;
|
|
331
|
+
/** Styles to encapsulate to this component's root. */
|
|
332
|
+
static style: CSSStyleSheet | CSSStyleSheet[] | string;
|
|
333
|
+
/** Attributes to watch for changes for updates. */
|
|
464
334
|
static observedAttributes: string[];
|
|
465
335
|
/**
|
|
466
|
-
* The mode for this Component's ShadowRoot.
|
|
336
|
+
* The mode for this Component's ShadowRoot.
|
|
337
|
+
*
|
|
338
|
+
* MDN: https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/mode
|
|
467
339
|
*/
|
|
468
340
|
static rootMode: RootMode;
|
|
469
|
-
/**
|
|
470
|
-
* Initialization lifecycle method. Main scripting and event listeners.
|
|
471
|
-
* @returns a function to handle cleanup tasks when the component unmounts
|
|
472
|
-
*/
|
|
473
|
-
protected script?(): VoidFunction | void;
|
|
474
341
|
/** Called immediately before each template update */
|
|
475
|
-
|
|
342
|
+
beforeUpdate?(changedAttributes: Record<string, string | null>): void;
|
|
476
343
|
/** Called immediately after each template update */
|
|
477
|
-
|
|
344
|
+
afterUpdate?(previousAttributes: Record<string, string | null>): void;
|
|
478
345
|
/** Final lifecycle method called at the end of the unmounting process. */
|
|
479
|
-
|
|
346
|
+
finalize?(): void;
|
|
480
347
|
/**
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
* @example
|
|
485
|
-
*
|
|
486
|
-
* Recovering from errors or displaying a fallback
|
|
487
|
-
*
|
|
488
|
-
* ```typescript
|
|
489
|
-
* onError(error) {
|
|
490
|
-
* if (error.canRecover) {
|
|
491
|
-
* this.recover();
|
|
492
|
-
* return;
|
|
493
|
-
* }
|
|
494
|
-
*
|
|
495
|
-
* this.replaceWith("Oh dear, an error happened real bad");
|
|
496
|
-
* }
|
|
497
|
-
* ```
|
|
348
|
+
* Handle errors thrown during lifecycle methods of this component or any
|
|
349
|
+
* unhandled errors from child components.
|
|
498
350
|
*/
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
|
|
502
|
-
*
|
|
503
|
-
* @remarks
|
|
504
|
-
* If `initialState` is defined as a function, the function is evaluated at
|
|
505
|
-
* mounting time and the return value is used as the initial state.
|
|
506
|
-
*/
|
|
507
|
-
protected initialState?: StateInitializer<StateShape>;
|
|
351
|
+
onError?(error: unknown): void;
|
|
352
|
+
/** The initial state for this Component */
|
|
353
|
+
initialState?(): State<StateShape> | StateShape;
|
|
508
354
|
/**
|
|
509
355
|
* An object or function returning an object which populates the `data` values
|
|
510
356
|
* in the templating engine. Such values are accessed using the `*` notation.
|
|
511
|
-
*
|
|
512
|
-
* @example
|
|
513
|
-
*
|
|
514
|
-
* ```typescript
|
|
515
|
-
* host = {
|
|
516
|
-
* avatarUrl: "http://...",
|
|
517
|
-
* renderTime: () => new Date().toISOString(),
|
|
518
|
-
* }
|
|
519
|
-
* ```
|
|
520
|
-
*
|
|
521
|
-
* ```html
|
|
522
|
-
* <img :src="*avatarUrl" />
|
|
523
|
-
* <span>Rendered at ${"*renderTime"}</span>
|
|
524
|
-
* ```
|
|
525
357
|
*/
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
*
|
|
531
|
-
* @example
|
|
532
|
-
*
|
|
533
|
-
* ```typescript
|
|
534
|
-
* liveAttributes = {
|
|
535
|
-
* done: {
|
|
536
|
-
* onChange(newValue) {
|
|
537
|
-
* this.state.set("done", !!newValue);
|
|
538
|
-
* },
|
|
539
|
-
* reflect() { return this.state.current.done }
|
|
540
|
-
* }
|
|
541
|
-
* };
|
|
542
|
-
* ```
|
|
543
|
-
*
|
|
544
|
-
* @remarks
|
|
545
|
-
* The optional functions are:
|
|
546
|
-
*
|
|
547
|
-
* `onChange(newValue, oldValue): void`, a handler function for when the value
|
|
548
|
-
* of this attribute has changed. Runs once per update cycle, *before* the
|
|
549
|
-
* update occurs.
|
|
550
|
-
*
|
|
551
|
-
* `reflect(): unknown`, a function which returns a value to serialize and set
|
|
552
|
-
* as this attribute *after* an update completes.
|
|
553
|
-
*
|
|
554
|
-
* If using the {@link define} helper, the keys of this property are
|
|
555
|
-
* automatically merged with any defined {@link observedAttributes}.
|
|
556
|
-
*/
|
|
557
|
-
protected liveAttributes?: LiveAttributes<StateShape>;
|
|
558
|
-
private _template;
|
|
559
|
-
private _root;
|
|
560
|
-
private _state?;
|
|
561
|
-
private _delegator?;
|
|
562
|
-
private _ownListeners?;
|
|
563
|
-
private _cleanupFn?;
|
|
564
|
-
private _renderInternals;
|
|
358
|
+
computedProperties?(this: Component<StateShape>, attributes: Record<string, string | null>, state: StateShape): Record<string, unknown>;
|
|
359
|
+
readonly root: ShadowRoot;
|
|
360
|
+
readonly template: Template;
|
|
361
|
+
private _cmp;
|
|
565
362
|
constructor();
|
|
566
363
|
/** Produce the data object to pass to the template's render function */
|
|
567
364
|
private _getRenderContext;
|
|
568
365
|
private _escalateError;
|
|
569
366
|
private _reportError;
|
|
570
|
-
private _executeAttributeChangeHandlers;
|
|
571
|
-
private _reflectLiveAttributes;
|
|
572
367
|
/** The actual update behavior */
|
|
573
|
-
private
|
|
574
|
-
/** Safely request for an update to run on the next frame */
|
|
575
|
-
private _scheduleUpdate;
|
|
368
|
+
private _render;
|
|
576
369
|
private _adoptState;
|
|
577
370
|
/**
|
|
578
371
|
* @deprecated Use {@link script} instead
|
|
@@ -583,14 +376,18 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
|
|
|
583
376
|
*/
|
|
584
377
|
protected disconnectedCallback(): void;
|
|
585
378
|
/**
|
|
586
|
-
* @deprecated Use {@link
|
|
379
|
+
* @deprecated Use {@link beforeUpdate} and {@link afterUpdate} instead
|
|
587
380
|
*/
|
|
588
381
|
protected attributeChangedCallback(name: string, _: string | null, newValue: string | null): void;
|
|
382
|
+
get isMounted(): boolean;
|
|
589
383
|
/**
|
|
590
|
-
*
|
|
384
|
+
* Access the full {@link State} instance for this Component.
|
|
385
|
+
*
|
|
386
|
+
* @remarks
|
|
387
|
+
* Calling this method on a component which is not using reactive state
|
|
388
|
+
* will result in an error being thrown.
|
|
591
389
|
*/
|
|
592
|
-
|
|
593
|
-
get isMounted(): boolean;
|
|
390
|
+
getState(): State<StateShape>;
|
|
594
391
|
/**
|
|
595
392
|
* Accessor for live reactive state.
|
|
596
393
|
*
|
|
@@ -603,71 +400,85 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
|
|
|
603
400
|
*/
|
|
604
401
|
set state(newState: StateShape | State<StateShape>);
|
|
605
402
|
/**
|
|
606
|
-
* Access the full {@link State} instance for this Component.
|
|
607
|
-
*
|
|
608
|
-
* @remarks
|
|
609
|
-
* Calling this method on a component which is not using reactive state
|
|
610
|
-
* will result in an error being thrown.
|
|
611
|
-
*/
|
|
612
|
-
getState(): State<StateShape>;
|
|
613
|
-
/**
|
|
614
403
|
* Manually schedule a render to occur, optionally providing a callback to
|
|
615
404
|
* invoke after the render completes.
|
|
616
405
|
*
|
|
617
406
|
* @remarks
|
|
618
|
-
* Calling {@link
|
|
407
|
+
* Calling {@link render} multiple times in the same event loop won't
|
|
619
408
|
* schedule multiple renders. Renders are scheduled to occur on the next
|
|
620
409
|
* animation frame.
|
|
621
410
|
*/
|
|
622
|
-
|
|
411
|
+
render: () => void;
|
|
623
412
|
/**
|
|
624
|
-
* Listen for events
|
|
413
|
+
* Listen for events on a child element based on the provided query
|
|
625
414
|
*
|
|
626
|
-
*
|
|
627
|
-
* to create listeners on the host element itself.
|
|
415
|
+
* @returns A function which removes the listener when called
|
|
628
416
|
*
|
|
417
|
+
* @remarks
|
|
629
418
|
* Event listeners created with this method are automatically cleaned up when
|
|
630
|
-
* the component unmounts.
|
|
419
|
+
* the component unmounts. You can manually remove the listener during the
|
|
420
|
+
* component's lifecycle by calling the returned function if need be.
|
|
631
421
|
*/
|
|
632
|
-
listen<E extends EventName>(
|
|
633
|
-
stopListening<E extends EventName>(targetDescriptor: string | typeof Component<any> | HTMLElement, eventName: E, eventHandler: EventHandler<E>): void;
|
|
634
|
-
dispatchEvent(event: Event): boolean;
|
|
422
|
+
listen<E extends EventName>(target: string, eventName: E, eventHandler: EventHandler<E>): VoidFunction;
|
|
635
423
|
/**
|
|
636
|
-
*
|
|
424
|
+
* Listen for events on a child element based on the provided component's tag
|
|
425
|
+
*
|
|
426
|
+
* @returns A function which removes the listener when called
|
|
427
|
+
*
|
|
428
|
+
* @remarks
|
|
429
|
+
* Event listeners created with this method are automatically cleaned up when
|
|
430
|
+
* the component unmounts. You can manually remove the listener during the
|
|
431
|
+
* component's lifecycle by calling the returned function if need be.
|
|
637
432
|
*/
|
|
638
|
-
|
|
639
|
-
bubbles: boolean;
|
|
640
|
-
cancelable: boolean;
|
|
641
|
-
composed: boolean;
|
|
642
|
-
}): boolean;
|
|
643
|
-
querySelector<E extends HTMLElement>(query: string): E | null;
|
|
644
|
-
querySelectorAll<E extends HTMLElement>(query: string): NodeListOf<E>;
|
|
645
|
-
getElementById<E extends HTMLElement>(id: string): E | null;
|
|
646
|
-
requireElementById<E extends HTMLElement>(id: string): E;
|
|
647
|
-
setAttribute(name: string, value: string): void;
|
|
433
|
+
listen<E extends EventName>(target: typeof Component<any>, eventName: E, eventHandler: EventHandler<E>): VoidFunction;
|
|
648
434
|
/**
|
|
649
|
-
*
|
|
435
|
+
* Listen for events on the host element
|
|
436
|
+
*
|
|
437
|
+
* @returns A function which removes the listener when called
|
|
650
438
|
*
|
|
651
|
-
*
|
|
439
|
+
* @remarks
|
|
440
|
+
* Event listeners created with this method are automatically cleaned up when
|
|
441
|
+
* the component unmounts. You can manually remove the listener during the
|
|
442
|
+
* component's lifecycle by calling the returned function if need be.
|
|
652
443
|
*/
|
|
653
|
-
|
|
654
|
-
getAttribute(name: string): string | null;
|
|
444
|
+
listen<E extends EventName>(target: typeof this, eventName: E, eventHandler: EventHandler<E>): VoidFunction;
|
|
655
445
|
/**
|
|
656
|
-
*
|
|
446
|
+
* Listen for events on the host element
|
|
657
447
|
*
|
|
658
|
-
*
|
|
659
|
-
*
|
|
448
|
+
* @returns A function which removes the listener when called
|
|
449
|
+
*
|
|
450
|
+
* @remarks
|
|
451
|
+
* Event listeners created with this method are automatically cleaned up when
|
|
452
|
+
* the component unmounts. You can manually remove the listener during the
|
|
453
|
+
* component's lifecycle by calling the returned function if need be.
|
|
660
454
|
*/
|
|
661
|
-
|
|
455
|
+
listen<E extends EventName>(target: ":host", eventName: E, eventHandler: EventHandler<E>): VoidFunction;
|
|
662
456
|
/**
|
|
663
|
-
*
|
|
457
|
+
* Publish a {@link CustomEvent} with the provided name and options.
|
|
458
|
+
*
|
|
459
|
+
* Default options are:
|
|
460
|
+
*
|
|
461
|
+
* ```typescript
|
|
462
|
+
* {
|
|
463
|
+
* bubbles: true,
|
|
464
|
+
* cancelable: true,
|
|
465
|
+
* composed: true,
|
|
466
|
+
* detail: undefined,
|
|
467
|
+
* }
|
|
468
|
+
* ```
|
|
469
|
+
*
|
|
470
|
+
* @param name The name of the custom event to publish
|
|
471
|
+
* @param options Options to configure the custom event
|
|
664
472
|
*/
|
|
665
|
-
|
|
473
|
+
dispatchEvent<T>(name: string, options: CustomEventInit<T>): boolean;
|
|
474
|
+
dispatchEvent(event: Event): boolean;
|
|
666
475
|
/**
|
|
667
|
-
*
|
|
668
|
-
*
|
|
476
|
+
* Returns a reference to the HTML Element with the provided ID within the
|
|
477
|
+
* shadow root of this component.
|
|
478
|
+
*
|
|
479
|
+
* Throws an error if no element with the provided ID is found
|
|
669
480
|
*/
|
|
670
|
-
|
|
481
|
+
ref<E extends HTMLElement>(id: string): E;
|
|
671
482
|
/**
|
|
672
483
|
* Serialize this element to a string
|
|
673
484
|
*/
|
|
@@ -699,7 +510,7 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
|
|
|
699
510
|
* @param attributes A record of attributes to apply
|
|
700
511
|
* @returns A reference to the rendered Component
|
|
701
512
|
*/
|
|
702
|
-
declare function renderTestComponent<E extends typeof Component<any>>(component: E, attributes?: Record<string,
|
|
513
|
+
declare function renderTestComponent<E extends typeof Component<any>>(component: E, attributes?: Record<string, string | null>): Promise<InstanceType<E>>;
|
|
703
514
|
/**
|
|
704
515
|
* Force a render on the target element
|
|
705
516
|
*
|