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