@aegis-framework/pandora 0.4.2 → 0.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.
- package/README.md +1394 -727
- package/dist/pandora.browser.js +16 -15
- package/dist/pandora.browser.js.map +11 -9
- package/dist/pandora.js +16 -15
- package/dist/pandora.js.map +10 -8
- package/dist/types/Component.d.ts +792 -209
- package/dist/types/Component.d.ts.map +1 -1
- package/dist/types/Decorators.d.ts +378 -35
- package/dist/types/Decorators.d.ts.map +1 -1
- package/dist/types/Registry.d.ts +478 -105
- package/dist/types/Registry.d.ts.map +1 -1
- package/dist/types/ShadowComponent.d.ts +128 -23
- package/dist/types/ShadowComponent.d.ts.map +1 -1
- package/dist/types/Testing.d.ts +74 -0
- package/dist/types/Testing.d.ts.map +1 -0
- package/dist/types/TypedState.d.ts +51 -0
- package/dist/types/TypedState.d.ts.map +1 -0
- package/dist/types/Types.d.ts +92 -2
- package/dist/types/Types.d.ts.map +1 -1
- package/dist/types/Util.d.ts +134 -15
- package/dist/types/Util.d.ts.map +1 -1
- package/dist/types/browser.d.ts +14 -0
- package/dist/types/browser.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -2
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +11 -5
package/dist/types/Registry.d.ts
CHANGED
|
@@ -6,9 +6,9 @@ type ComponentClass = typeof Component & {
|
|
|
6
6
|
type StateSubscriber<T = unknown> = (newValue: T, oldValue: T | undefined) => void;
|
|
7
7
|
type LifecycleCallback = (component: Component, tag: string) => void;
|
|
8
8
|
type ErrorCallback = (error: Error, component: Component, tag: string, lifecycle: string) => void;
|
|
9
|
-
type MiddlewareType = '
|
|
9
|
+
type MiddlewareType = 'render';
|
|
10
10
|
type RenderType = 'string' | 'lit';
|
|
11
|
-
type Middleware = (component: Component, value:
|
|
11
|
+
type Middleware = (component: Component, value: unknown, renderType?: RenderType) => unknown;
|
|
12
12
|
type ComponentLoader = () => Promise<ComponentClass | {
|
|
13
13
|
default: ComponentClass;
|
|
14
14
|
}>;
|
|
@@ -19,9 +19,36 @@ interface ComponentStats {
|
|
|
19
19
|
isLazy: boolean;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Pandora's central registry for custom elements, global state, lifecycle
|
|
23
|
+
* observers, and the render middleware pipeline.
|
|
24
|
+
*
|
|
25
|
+
* Everything you register with `@Register` flows through here, and you can
|
|
26
|
+
* also talk to it directly: keep a catalog of tags, hot-swap implementations
|
|
27
|
+
* with `evolve()`, share values across the tree with `setState()` /
|
|
28
|
+
* `subscribe()`, watch every mount and unmount, or wrap render output with
|
|
29
|
+
* `use('render', ...)`.
|
|
30
|
+
*
|
|
31
|
+
* Most APIs are designed to be used from anywhere in your app — import the
|
|
32
|
+
* default export and call the static methods directly. There's no instance
|
|
33
|
+
* to construct.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* import Registry, { Component, Register } from '@aegis-framework/pandora';
|
|
37
|
+
*
|
|
38
|
+
* @Register('theme-toggle')
|
|
39
|
+
* class ThemeToggle extends Component {
|
|
40
|
+
* render() {
|
|
41
|
+
* return `<button>Toggle</button>`;
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* Registry.setState('theme', 'dark');
|
|
46
|
+
* const unsubscribe = Registry.subscribe('theme', (next) => {
|
|
47
|
+
* document.documentElement.dataset.theme = next as string;
|
|
48
|
+
* });
|
|
23
49
|
*/
|
|
24
50
|
declare class Registry {
|
|
51
|
+
/** Backing store for the `debug` accessor; defaults off so logging stays quiet in production. @internal */
|
|
25
52
|
private static _debug;
|
|
26
53
|
private static components;
|
|
27
54
|
private static implementations;
|
|
@@ -33,256 +60,602 @@ declare class Registry {
|
|
|
33
60
|
private static aliases;
|
|
34
61
|
private static lazyLoaders;
|
|
35
62
|
private static middleware;
|
|
63
|
+
/** Flipped true on the first `_init()` call so subsequent entry points skip re-wiring Component hooks. @internal */
|
|
36
64
|
private static _initialized;
|
|
37
65
|
/**
|
|
38
|
-
*
|
|
66
|
+
* One-time bootstrap that wires Component's hook slots to Registry methods.
|
|
67
|
+
* The `_initialized` guard keeps repeated entry points (register, lazy,
|
|
68
|
+
* onMount, etc.) from re-installing the hooks on every call.
|
|
69
|
+
*
|
|
70
|
+
* @internal
|
|
39
71
|
*/
|
|
40
72
|
private static _init;
|
|
41
73
|
/**
|
|
42
|
-
*
|
|
74
|
+
* Associates a tag name with a component class and defines it on
|
|
75
|
+
* `window.customElements`.
|
|
76
|
+
*
|
|
77
|
+
* You usually don't call this yourself — `@Register('my-tag')` does it for
|
|
78
|
+
* you — but it's useful when you construct component classes dynamically
|
|
79
|
+
* or register them from a bootstrapper. Throws if the tag is already
|
|
80
|
+
* taken; reach for `evolve()` to swap an implementation instead.
|
|
81
|
+
*
|
|
82
|
+
* @param tag - The custom element tag to register under.
|
|
83
|
+
* @param component - The component class to associate with the tag.
|
|
43
84
|
*
|
|
44
|
-
* @
|
|
45
|
-
*
|
|
85
|
+
* @example
|
|
86
|
+
* class MyGreeting extends Component {
|
|
87
|
+
* render() { return `<p>Hello</p>`; }
|
|
88
|
+
* }
|
|
89
|
+
*
|
|
90
|
+
* Registry.register('my-greeting', MyGreeting);
|
|
46
91
|
*/
|
|
47
92
|
static register(tag: string, component: ComponentClass): void;
|
|
48
93
|
/**
|
|
49
|
-
*
|
|
94
|
+
* Activates a deferred component by running the same work as `register()`.
|
|
50
95
|
*
|
|
51
|
-
*
|
|
96
|
+
* Use this with components decorated `@Register('my-tag', { defer: true })`
|
|
97
|
+
* when you're ready to define them on `customElements`. Behaviorally
|
|
98
|
+
* identical to `register()`; the different name just makes intent clearer
|
|
99
|
+
* at the call site.
|
|
100
|
+
*
|
|
101
|
+
* @param tag - The tag to activate.
|
|
102
|
+
* @param component - The component class to define.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* @Register('lazy-chart', { defer: true })
|
|
106
|
+
* class LazyChart extends Component { render() { return ''; } }
|
|
107
|
+
*
|
|
108
|
+
* // Later, when you're ready to light it up:
|
|
109
|
+
* Registry.define('lazy-chart', LazyChart);
|
|
110
|
+
*/
|
|
111
|
+
static define(tag: string, component: ComponentClass): void;
|
|
112
|
+
/**
|
|
113
|
+
* Returns the class currently backing a tag, including any version
|
|
114
|
+
* installed by `evolve()` or a resolved lazy loader.
|
|
115
|
+
*
|
|
116
|
+
* Unlike `get()`, which always returns the originally-registered class,
|
|
117
|
+
* this method follows `evolve()` swaps so tooling and debuggers can
|
|
118
|
+
* inspect the live behavior.
|
|
119
|
+
*
|
|
120
|
+
* @param tag - The tag to look up.
|
|
121
|
+
* @returns The active implementation, or `undefined` if the tag is unknown.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* const CurrentButton = Registry.getImplementation('my-button');
|
|
52
125
|
*/
|
|
53
126
|
static getImplementation(tag: string): ComponentClass | undefined;
|
|
54
127
|
/**
|
|
55
|
-
*
|
|
128
|
+
* Applies a source class's prototype, field defaults, metadata, and
|
|
129
|
+
* decorator effects to a live instance. Used for both the evolve() swap
|
|
130
|
+
* and lazy-load upgrade paths: we can't redefine the custom element, so
|
|
131
|
+
* we replay the new class's behavior onto each existing instance.
|
|
132
|
+
*
|
|
133
|
+
* @internal
|
|
134
|
+
*/
|
|
135
|
+
static _applyImplementation(instance: Component, source: ComponentClass, _merge?: boolean): void;
|
|
136
|
+
/**
|
|
137
|
+
* Hot-swaps the implementation behind a registered tag, so every future
|
|
138
|
+
* instance uses the new class.
|
|
139
|
+
*
|
|
140
|
+
* The browser only lets you call `customElements.define()` once per tag,
|
|
141
|
+
* so Pandora keeps the original class bound to the tag and replays the
|
|
142
|
+
* new class's prototype methods, field defaults, and decorator effects
|
|
143
|
+
* onto each live instance. Aliases created with `alias()` also pick up
|
|
144
|
+
* the swap.
|
|
145
|
+
*
|
|
146
|
+
* Pass `true` as the third argument to force an immediate re-render of
|
|
147
|
+
* every live instance (including aliased ones). Without it, already-mounted
|
|
148
|
+
* components keep running the old code until they naturally re-render.
|
|
149
|
+
*
|
|
150
|
+
* @param tag - The existing tag whose implementation you're replacing.
|
|
151
|
+
* @param component - The new component class to install.
|
|
152
|
+
* @param rerender - When `true`, re-renders every mounted instance right away.
|
|
56
153
|
*
|
|
57
|
-
* @
|
|
58
|
-
*
|
|
59
|
-
*
|
|
154
|
+
* @example
|
|
155
|
+
* class MyCounter extends Component {
|
|
156
|
+
* render() { return `<span>v1</span>`; }
|
|
157
|
+
* }
|
|
158
|
+
* Registry.register('my-counter', MyCounter);
|
|
159
|
+
*
|
|
160
|
+
* class MyCounterV2 extends Component {
|
|
161
|
+
* render() { return `<span>v2</span>`; }
|
|
162
|
+
* }
|
|
163
|
+
* Registry.evolve('my-counter', MyCounterV2, true);
|
|
60
164
|
*/
|
|
61
165
|
static evolve(tag: string, component: ComponentClass, rerender?: boolean): void;
|
|
62
166
|
/**
|
|
63
|
-
*
|
|
167
|
+
* Finds every live instance of a tag in the document.
|
|
168
|
+
*
|
|
169
|
+
* With one argument, returns the matching `NodeList` so you can iterate
|
|
170
|
+
* it yourself. Pass a callback as the second argument and Pandora will
|
|
171
|
+
* iterate for you and return nothing. Throws if the tag isn't registered.
|
|
172
|
+
*
|
|
173
|
+
* @param tag - The tag whose instances you want.
|
|
174
|
+
* @param callback - Optional iterator invoked once per instance.
|
|
175
|
+
* @returns A `NodeList` when no callback is provided; otherwise `void`.
|
|
64
176
|
*
|
|
65
|
-
* @
|
|
66
|
-
*
|
|
177
|
+
* @example
|
|
178
|
+
* // Collect every instance:
|
|
179
|
+
* const buttons = Registry.instances('my-button');
|
|
180
|
+
*
|
|
181
|
+
* // Or iterate them directly:
|
|
182
|
+
* Registry.instances('my-button', (el) => {
|
|
183
|
+
* (el as HTMLElement).classList.add('ready');
|
|
184
|
+
* });
|
|
67
185
|
*/
|
|
68
|
-
static instances(tag: string
|
|
186
|
+
static instances(tag: string): NodeListOf<Element>;
|
|
187
|
+
static instances(tag: string, callback: (instance: Element) => void): void;
|
|
69
188
|
/**
|
|
70
|
-
*
|
|
189
|
+
* Builds a detached element for a registered tag and seeds its initial
|
|
190
|
+
* props and attributes.
|
|
191
|
+
*
|
|
192
|
+
* The returned element is created with `document.createElement` but not
|
|
193
|
+
* attached anywhere — you choose where it lives by calling
|
|
194
|
+
* `parent.appendChild(...)` or similar. Values are assigned as properties;
|
|
195
|
+
* for plain fields without a reactive setter, string, number, and truthy
|
|
196
|
+
* boolean values also mirror to the matching attribute.
|
|
71
197
|
*
|
|
72
|
-
* @param tag - The tag
|
|
73
|
-
* @param props -
|
|
74
|
-
* @returns
|
|
198
|
+
* @param tag - The registered tag to create.
|
|
199
|
+
* @param props - Initial property values keyed by field name.
|
|
200
|
+
* @returns A detached component instance ready to attach.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* const avatar = Registry.instantiate('user-avatar', {
|
|
204
|
+
* userId: 'u_42',
|
|
205
|
+
* size: 48
|
|
206
|
+
* });
|
|
207
|
+
* document.body.appendChild(avatar);
|
|
75
208
|
*/
|
|
76
209
|
static instantiate(tag: string, props: Record<string, any>): Component;
|
|
77
210
|
/**
|
|
78
|
-
*
|
|
211
|
+
* Checks whether any component is registered under the given tag.
|
|
212
|
+
*
|
|
213
|
+
* Includes aliases and lazy components, since both are tracked in the
|
|
214
|
+
* same catalog.
|
|
79
215
|
*
|
|
80
|
-
* @param tag - The tag
|
|
81
|
-
* @returns
|
|
216
|
+
* @param tag - The tag to check.
|
|
217
|
+
* @returns `true` if the tag is known to Registry.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* if (!Registry.has('theme-toggle')) {
|
|
221
|
+
* Registry.register('theme-toggle', ThemeToggle);
|
|
222
|
+
* }
|
|
82
223
|
*/
|
|
83
224
|
static has(tag: string): boolean;
|
|
84
225
|
/**
|
|
85
|
-
*
|
|
226
|
+
* Returns the originally-registered class for a tag.
|
|
227
|
+
*
|
|
228
|
+
* If you want the current implementation (honoring `evolve()`), use
|
|
229
|
+
* `getImplementation()` instead.
|
|
230
|
+
*
|
|
231
|
+
* @param tag - The tag to look up.
|
|
232
|
+
* @returns The registered class, or `undefined` if the tag is unknown.
|
|
86
233
|
*
|
|
87
|
-
* @
|
|
88
|
-
*
|
|
234
|
+
* @example
|
|
235
|
+
* const ThemeToggle = Registry.get('theme-toggle');
|
|
89
236
|
*/
|
|
90
237
|
static get(tag: string): ComponentClass | undefined;
|
|
91
238
|
/**
|
|
92
|
-
*
|
|
239
|
+
* Stores a value under the given key and synchronously notifies every
|
|
240
|
+
* `subscribe()` callback registered on that key.
|
|
241
|
+
*
|
|
242
|
+
* Subscribers run in registration order and receive `(newValue, oldValue)`.
|
|
243
|
+
* If a callback throws, the error propagates — wrap risky work yourself.
|
|
93
244
|
*
|
|
94
|
-
* @param key - The state key
|
|
95
|
-
* @param value - The value
|
|
245
|
+
* @param key - The state key.
|
|
246
|
+
* @param value - The new value.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* Registry.setState('theme', 'dark');
|
|
250
|
+
* Registry.setState('user', { id: 'u_42', name: 'Ada' });
|
|
96
251
|
*/
|
|
97
252
|
static setState<T>(key: string, value: T): void;
|
|
98
253
|
/**
|
|
99
|
-
*
|
|
254
|
+
* Reads the current value stored under a key.
|
|
100
255
|
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
256
|
+
* Returns `undefined` if nothing has been set, which is indistinguishable
|
|
257
|
+
* from a value that was explicitly set to `undefined` — use `hasState()`
|
|
258
|
+
* if you need to tell them apart.
|
|
259
|
+
*
|
|
260
|
+
* @param key - The state key to read.
|
|
261
|
+
* @returns The current value, or `undefined` if the key is unset.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* const theme = Registry.getState<'light' | 'dark'>('theme');
|
|
103
265
|
*/
|
|
104
266
|
static getState<T>(key: string): T | undefined;
|
|
105
267
|
/**
|
|
106
|
-
*
|
|
268
|
+
* Checks whether a state key has been set.
|
|
269
|
+
*
|
|
270
|
+
* Useful when you need to distinguish "never set" from "set to `undefined`."
|
|
107
271
|
*
|
|
108
|
-
* @param key - The state key to check
|
|
109
|
-
* @returns
|
|
272
|
+
* @param key - The state key to check.
|
|
273
|
+
* @returns `true` if the key exists in the store.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* if (!Registry.hasState('theme')) {
|
|
277
|
+
* Registry.setState('theme', 'light');
|
|
278
|
+
* }
|
|
110
279
|
*/
|
|
111
280
|
static hasState(key: string): boolean;
|
|
112
281
|
/**
|
|
113
|
-
*
|
|
282
|
+
* Removes a state key and notifies subscribers with `(undefined, oldValue)`.
|
|
283
|
+
*
|
|
284
|
+
* Returns `false` if the key wasn't present, so subscribers aren't called
|
|
285
|
+
* for no-ops.
|
|
286
|
+
*
|
|
287
|
+
* @param key - The state key to delete.
|
|
288
|
+
* @returns `true` if the key existed and was removed.
|
|
114
289
|
*
|
|
115
|
-
* @
|
|
116
|
-
*
|
|
290
|
+
* @example
|
|
291
|
+
* Registry.deleteState('user');
|
|
117
292
|
*/
|
|
118
293
|
static deleteState(key: string): boolean;
|
|
119
294
|
/**
|
|
120
|
-
*
|
|
295
|
+
* Listens for changes to a state key.
|
|
296
|
+
*
|
|
297
|
+
* The callback fires only on future `setState()` and `deleteState()` calls —
|
|
298
|
+
* it does not run immediately with the current value, so call `getState()`
|
|
299
|
+
* yourself if you need to seed initial UI. Call the returned function to
|
|
300
|
+
* stop listening.
|
|
301
|
+
*
|
|
302
|
+
* @param key - The state key to watch.
|
|
303
|
+
* @param callback - Receives `(newValue, oldValue)` whenever the key changes.
|
|
304
|
+
* @returns A function that removes this subscription.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* const stop = Registry.subscribe<'light' | 'dark'>('theme', (next, prev) => {
|
|
308
|
+
* console.log(`theme changed from ${prev} to ${next}`);
|
|
309
|
+
* });
|
|
121
310
|
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* @returns An unsubscribe function
|
|
311
|
+
* // Later, when you no longer care:
|
|
312
|
+
* stop();
|
|
125
313
|
*/
|
|
126
314
|
static subscribe<T>(key: string, callback: StateSubscriber<T>): () => void;
|
|
127
315
|
/**
|
|
128
|
-
*
|
|
316
|
+
* Removes a specific callback from a state key's subscription list.
|
|
317
|
+
*
|
|
318
|
+
* Most of the time you'll use the function returned by `subscribe()`
|
|
319
|
+
* instead — this overload is available when you need to hold a reference
|
|
320
|
+
* to the callback separately.
|
|
321
|
+
*
|
|
322
|
+
* @param key - The state key you subscribed to.
|
|
323
|
+
* @param callback - The exact callback reference to remove.
|
|
129
324
|
*
|
|
130
|
-
* @
|
|
131
|
-
*
|
|
325
|
+
* @example
|
|
326
|
+
* const onThemeChange = (next: unknown) => console.log(next);
|
|
327
|
+
* Registry.subscribe('theme', onThemeChange);
|
|
328
|
+
* Registry.unsubscribe('theme', onThemeChange);
|
|
132
329
|
*/
|
|
133
330
|
static unsubscribe<T>(key: string, callback: StateSubscriber<T>): void;
|
|
134
331
|
/**
|
|
135
|
-
*
|
|
332
|
+
* Returns a shallow copy of every key/value pair currently in the store.
|
|
333
|
+
*
|
|
334
|
+
* Handy for debugging, snapshotting, or serializing state. The copy is
|
|
335
|
+
* shallow, so nested objects still share references with the live state.
|
|
136
336
|
*
|
|
137
|
-
* @returns A
|
|
337
|
+
* @returns A new object with all current state entries.
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* const snapshot = Registry.getAllState();
|
|
341
|
+
* console.log(snapshot);
|
|
138
342
|
*/
|
|
139
343
|
static getAllState(): Record<string, unknown>;
|
|
140
344
|
/**
|
|
141
|
-
*
|
|
345
|
+
* Removes every state key and notifies subscribers for each one.
|
|
346
|
+
*
|
|
347
|
+
* Each key is deleted via `deleteState()`, so subscribers receive
|
|
348
|
+
* `(undefined, oldValue)` per key in insertion order. This is most useful
|
|
349
|
+
* between tests; reach for `deleteState()` for targeted cleanup.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* afterEach(() => {
|
|
353
|
+
* Registry.clearState();
|
|
354
|
+
* });
|
|
142
355
|
*/
|
|
143
356
|
static clearState(): void;
|
|
144
357
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
358
|
+
* Drops every subscription registered via `subscribe()`.
|
|
359
|
+
*
|
|
360
|
+
* After this call, stored values remain untouched, but no callbacks will
|
|
361
|
+
* fire on future changes. Intended for test teardown — in app code,
|
|
362
|
+
* prefer the unsubscribe function each subscription returns.
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* afterEach(() => {
|
|
366
|
+
* Registry.clearSubscriptions();
|
|
367
|
+
* });
|
|
368
|
+
*/
|
|
369
|
+
static clearSubscriptions(): void;
|
|
370
|
+
/**
|
|
371
|
+
* Removes every middleware registered through `use()`.
|
|
372
|
+
*
|
|
373
|
+
* Mainly for test isolation, since middleware survives between specs
|
|
374
|
+
* otherwise.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* afterEach(() => {
|
|
378
|
+
* Registry.clearMiddleware();
|
|
379
|
+
* });
|
|
380
|
+
*/
|
|
381
|
+
static clearMiddleware(): void;
|
|
382
|
+
/**
|
|
383
|
+
* Toggles Pandora's debug logging.
|
|
384
|
+
*
|
|
385
|
+
* When `true`, Registry and Component write lifecycle events to the
|
|
386
|
+
* console (`Registered`, `Mounted`, `Evolved`, error traces, and so on).
|
|
387
|
+
* Defaults to `false`.
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* Registry.debug = true;
|
|
147
391
|
*/
|
|
148
392
|
static get debug(): boolean;
|
|
149
393
|
static set debug(value: boolean);
|
|
150
394
|
/**
|
|
151
|
-
*
|
|
395
|
+
* Writes a `[Pandora] …` message to the console when debug mode is on.
|
|
396
|
+
*
|
|
397
|
+
* Use this for your own logging if you want it to stay silent in
|
|
398
|
+
* production but pop up when you flip `Registry.debug = true`.
|
|
152
399
|
*
|
|
153
|
-
* @param message -
|
|
154
|
-
* @param data - Optional
|
|
400
|
+
* @param message - Text to log.
|
|
401
|
+
* @param data - Optional extra value logged alongside the message.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* Registry.debug = true;
|
|
405
|
+
* Registry.log('user signed in', { id: 'u_42' });
|
|
155
406
|
*/
|
|
156
407
|
static log(message: string, data?: unknown): void;
|
|
157
408
|
/**
|
|
158
|
-
*
|
|
409
|
+
* Returns every tag currently known to Registry.
|
|
410
|
+
*
|
|
411
|
+
* Includes aliases and lazy placeholders alongside normally-registered
|
|
412
|
+
* tags.
|
|
413
|
+
*
|
|
414
|
+
* @returns An array of tag names.
|
|
159
415
|
*
|
|
160
|
-
* @
|
|
416
|
+
* @example
|
|
417
|
+
* console.log(Registry.list()); // ['my-greeting', 'theme-toggle', ...]
|
|
161
418
|
*/
|
|
162
419
|
static list(): string[];
|
|
163
420
|
/**
|
|
164
|
-
*
|
|
421
|
+
* Reports current info about registered components: how many are mounted,
|
|
422
|
+
* whether they're active, and whether they're still lazy.
|
|
423
|
+
*
|
|
424
|
+
* Called with a tag, returns a single stats object (throws if the tag is
|
|
425
|
+
* unknown). Called with no argument, returns an array covering every
|
|
426
|
+
* registered tag.
|
|
427
|
+
*
|
|
428
|
+
* @param tag - Optional specific tag to inspect.
|
|
429
|
+
* @returns Stats for one tag or an array of stats for all tags.
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* Registry.stats('my-button');
|
|
433
|
+
* // { tag: 'my-button', instanceCount: 3, isRegistered: true, isLazy: false }
|
|
165
434
|
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
435
|
+
* Registry.stats();
|
|
436
|
+
* // [{ tag: 'my-button', ... }, { tag: 'theme-toggle', ... }]
|
|
168
437
|
*/
|
|
169
438
|
static stats(tag?: string): ComponentStats | ComponentStats[];
|
|
170
439
|
/**
|
|
171
|
-
*
|
|
440
|
+
* Observes every component mount across your app.
|
|
441
|
+
*
|
|
442
|
+
* Your callback runs once for each component after its `connectedCallback`
|
|
443
|
+
* resolves, receiving the instance and its tag. Useful for analytics,
|
|
444
|
+
* wiring up dev tooling, or running a setup step whenever any Pandora
|
|
445
|
+
* component appears.
|
|
172
446
|
*
|
|
173
|
-
* @param callback -
|
|
174
|
-
* @returns
|
|
447
|
+
* @param callback - Invoked with `(component, tag)` on every mount.
|
|
448
|
+
* @returns A function that removes this observer.
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* const stop = Registry.onMount((component, tag) => {
|
|
452
|
+
* console.log(`<${tag}> mounted`, component);
|
|
453
|
+
* });
|
|
175
454
|
*/
|
|
176
455
|
static onMount(callback: LifecycleCallback): () => void;
|
|
177
456
|
/**
|
|
178
|
-
*
|
|
457
|
+
* Observes every component unmount across your app.
|
|
458
|
+
*
|
|
459
|
+
* Fires after `disconnectedCallback` completes, receiving the instance
|
|
460
|
+
* and its tag. Pair it with `onMount()` to track lifecycles globally.
|
|
179
461
|
*
|
|
180
|
-
* @param callback -
|
|
181
|
-
* @returns
|
|
462
|
+
* @param callback - Invoked with `(component, tag)` on every unmount.
|
|
463
|
+
* @returns A function that removes this observer.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* Registry.onUnmount((component, tag) => {
|
|
467
|
+
* console.log(`<${tag}> unmounted`);
|
|
468
|
+
* });
|
|
182
469
|
*/
|
|
183
470
|
static onUnmount(callback: LifecycleCallback): () => void;
|
|
184
471
|
/**
|
|
185
|
-
*
|
|
472
|
+
* Fans a mount event out to every onMount observer. Each callback is
|
|
473
|
+
* wrapped in try/catch so one misbehaving handler can't take down the
|
|
474
|
+
* rest of the chain or the mounting component itself.
|
|
475
|
+
*
|
|
186
476
|
* @internal
|
|
187
477
|
*/
|
|
188
478
|
static _notifyMount(component: Component, tag: string): void;
|
|
189
479
|
/**
|
|
190
|
-
*
|
|
480
|
+
* Fans an unmount event out to every onUnmount observer. Same
|
|
481
|
+
* per-callback error isolation as _notifyMount so teardown keeps moving
|
|
482
|
+
* even when a single observer throws.
|
|
191
483
|
*
|
|
192
484
|
* @internal
|
|
193
485
|
*/
|
|
194
486
|
static _notifyUnmount(component: Component, tag: string): void;
|
|
195
487
|
/**
|
|
196
|
-
*
|
|
488
|
+
* Installs a global error handler for component lifecycle errors.
|
|
489
|
+
*
|
|
490
|
+
* When a component throws during mount, render, or another lifecycle
|
|
491
|
+
* step, each registered handler runs with `(error, component, tag,
|
|
492
|
+
* lifecycle)`. If no handlers are registered, the error is re-thrown so
|
|
493
|
+
* you still see failures in development.
|
|
494
|
+
*
|
|
495
|
+
* @param callback - Invoked with details about the failure.
|
|
496
|
+
* @returns A function that removes this handler.
|
|
197
497
|
*
|
|
198
|
-
* @
|
|
199
|
-
*
|
|
498
|
+
* @example
|
|
499
|
+
* Registry.onError((error, component, tag, lifecycle) => {
|
|
500
|
+
* console.error(`<${tag}> crashed in ${lifecycle}`, error);
|
|
501
|
+
* reportToSentry(error, { tag, lifecycle });
|
|
502
|
+
* });
|
|
200
503
|
*/
|
|
201
504
|
static onError(callback: ErrorCallback): () => void;
|
|
202
505
|
/**
|
|
203
|
-
*
|
|
506
|
+
* Dispatches a component lifecycle error. When no onError observers are
|
|
507
|
+
* registered we re-throw so failures stay visible during development;
|
|
508
|
+
* once any observer is installed, errors flow through the callback
|
|
509
|
+
* chain (each wrapped in try/catch to isolate misbehaving handlers).
|
|
204
510
|
*
|
|
205
511
|
* @internal
|
|
206
512
|
*/
|
|
207
513
|
static _notifyError(error: Error, component: Component, tag: string, lifecycle: string): void;
|
|
208
514
|
/**
|
|
209
|
-
*
|
|
515
|
+
* Creates a second tag that renders the same component as an existing one.
|
|
516
|
+
*
|
|
517
|
+
* Under the hood, Pandora defines a lightweight subclass of the original
|
|
518
|
+
* component and registers it under the new tag, so both tags render
|
|
519
|
+
* independently while sharing behavior. Later `evolve()` calls on the
|
|
520
|
+
* original flow through to the alias automatically.
|
|
521
|
+
*
|
|
522
|
+
* Set the alias up *before* any `<alias-tag>` element appears in the
|
|
523
|
+
* document — this is what actually defines the custom element. Throws if
|
|
524
|
+
* the alias name is already taken or the original isn't registered.
|
|
210
525
|
*
|
|
211
|
-
* @param aliasTag - The new tag name to
|
|
212
|
-
* @param originalTag - The
|
|
526
|
+
* @param aliasTag - The new tag name to register.
|
|
527
|
+
* @param originalTag - The existing tag to mirror.
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* Registry.register('my-button', MyButton);
|
|
531
|
+
* Registry.alias('primary-button', 'my-button');
|
|
532
|
+
*
|
|
533
|
+
* // <primary-button> now behaves just like <my-button>.
|
|
213
534
|
*/
|
|
214
535
|
static alias(aliasTag: string, originalTag: string): void;
|
|
215
536
|
/**
|
|
216
|
-
*
|
|
537
|
+
* Looks up the tag a given alias points to.
|
|
538
|
+
*
|
|
539
|
+
* @param aliasTag - A tag that was created with `alias()`.
|
|
540
|
+
* @returns The underlying tag, or `undefined` if `aliasTag` isn't an alias.
|
|
217
541
|
*
|
|
218
|
-
* @
|
|
219
|
-
*
|
|
542
|
+
* @example
|
|
543
|
+
* Registry.alias('primary-button', 'my-button');
|
|
544
|
+
* Registry.getOriginalTag('primary-button'); // 'my-button'
|
|
545
|
+
* Registry.getOriginalTag('my-button'); // undefined
|
|
220
546
|
*/
|
|
221
547
|
static getOriginalTag(aliasTag: string): string | undefined;
|
|
222
548
|
/**
|
|
223
|
-
*
|
|
549
|
+
* Reports whether a tag was created via `alias()`.
|
|
550
|
+
*
|
|
551
|
+
* @param tag - The tag to check.
|
|
552
|
+
* @returns `true` if this tag is an alias of another registered tag.
|
|
224
553
|
*
|
|
225
|
-
* @
|
|
226
|
-
*
|
|
554
|
+
* @example
|
|
555
|
+
* Registry.isAlias('primary-button'); // true
|
|
556
|
+
* Registry.isAlias('my-button'); // false
|
|
227
557
|
*/
|
|
228
558
|
static isAlias(tag: string): boolean;
|
|
229
559
|
/**
|
|
230
|
-
*
|
|
560
|
+
* Registers a tag whose implementation is fetched on demand.
|
|
561
|
+
*
|
|
562
|
+
* Pandora defines a placeholder custom element right away, so you can put
|
|
563
|
+
* `<lazy-chart>` in markup immediately. The first time one connects, the
|
|
564
|
+
* loader runs, its resolved class is applied to every pending instance,
|
|
565
|
+
* and the loader is discarded — subsequent instances reuse the already-
|
|
566
|
+
* loaded implementation without calling the loader again.
|
|
567
|
+
*
|
|
568
|
+
* The loader can return either the class directly or a module namespace
|
|
569
|
+
* with a `default` export, so dynamic `import()` calls work out of the box.
|
|
570
|
+
*
|
|
571
|
+
* @param tag - The tag to reserve for lazy loading.
|
|
572
|
+
* @param loader - Async function that resolves to the component class.
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* Registry.lazy('lazy-chart', () => import('./LazyChart'));
|
|
231
576
|
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
577
|
+
* // Somewhere in your markup:
|
|
578
|
+
* // <lazy-chart data-metric="signups"></lazy-chart>
|
|
234
579
|
*/
|
|
235
580
|
static lazy(tag: string, loader: ComponentLoader): void;
|
|
236
581
|
/**
|
|
237
|
-
*
|
|
582
|
+
* Runs a registered lazy loader once, resolves its module-or-class
|
|
583
|
+
* result, and installs the class as the live implementation for the
|
|
584
|
+
* tag. We delete the loader afterwards so later instances short-circuit
|
|
585
|
+
* and reuse the cached implementation instead of re-invoking import().
|
|
238
586
|
*
|
|
239
587
|
* @internal
|
|
240
588
|
*/
|
|
241
589
|
static _loadLazyComponent(tag: string): Promise<void>;
|
|
242
590
|
/**
|
|
243
|
-
*
|
|
591
|
+
* Reports whether a tag is still waiting to be lazily loaded.
|
|
244
592
|
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
593
|
+
* Returns `true` only while the loader has not yet run; once a lazy
|
|
594
|
+
* component has loaded (via mount or `preload()`), this returns `false`.
|
|
595
|
+
*
|
|
596
|
+
* @param tag - The tag to check.
|
|
597
|
+
* @returns `true` if the loader is registered and hasn't fired yet.
|
|
598
|
+
*
|
|
599
|
+
* @example
|
|
600
|
+
* if (Registry.isLazy('lazy-chart')) {
|
|
601
|
+
* await Registry.preload('lazy-chart');
|
|
602
|
+
* }
|
|
247
603
|
*/
|
|
248
604
|
static isLazy(tag: string): boolean;
|
|
249
605
|
/**
|
|
250
|
-
*
|
|
606
|
+
* Runs a lazy component's loader without having to mount it first.
|
|
607
|
+
*
|
|
608
|
+
* Handy for warming up components you'll need soon (route transitions,
|
|
609
|
+
* about-to-open dialogs). No-ops if the tag isn't lazy or has already
|
|
610
|
+
* been loaded.
|
|
251
611
|
*
|
|
252
|
-
* @param tag - The tag
|
|
612
|
+
* @param tag - The lazy tag to load ahead of time.
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* // Prime the chart before the user opens the dashboard:
|
|
616
|
+
* await Registry.preload('lazy-chart');
|
|
253
617
|
*/
|
|
254
618
|
static preload(tag: string): Promise<void>;
|
|
255
619
|
/**
|
|
256
|
-
*
|
|
620
|
+
* Installs a middleware function into one of Pandora's pipelines.
|
|
621
|
+
*
|
|
622
|
+
* Today the only supported type is `'render'`, which receives each
|
|
623
|
+
* component's render output before it's applied to the DOM. Multiple
|
|
624
|
+
* middleware run in registration order, and each one sees the value the
|
|
625
|
+
* previous one returned, so you can chain transforms. The `renderType`
|
|
626
|
+
* argument tells you whether the value is a plain string template or a
|
|
627
|
+
* lit-html `TemplateResult`, so you can handle them appropriately.
|
|
257
628
|
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
629
|
+
* If a middleware throws, the error is logged via `console.error` and
|
|
630
|
+
* the pipeline continues with the value it received, so one faulty
|
|
631
|
+
* middleware can't break the chain.
|
|
260
632
|
*
|
|
261
|
-
* @
|
|
633
|
+
* @param type - The middleware pipeline to hook into (currently `'render'`).
|
|
634
|
+
* @param middleware - Receives `(component, value, renderType?)` and returns the new value.
|
|
635
|
+
* @returns A function that removes this middleware.
|
|
262
636
|
*
|
|
263
637
|
* @example
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
* return value.toUpperCase();
|
|
638
|
+
* const stop = Registry.use('render', (component, value, renderType) => {
|
|
639
|
+
* if (renderType === 'string' && typeof value === 'string') {
|
|
640
|
+
* return value.replace(/TODO/g, '<mark>TODO</mark>');
|
|
268
641
|
* }
|
|
269
|
-
* // For lit-html, return as-is or wrap
|
|
270
642
|
* return value;
|
|
271
643
|
* });
|
|
272
644
|
*/
|
|
273
645
|
static use(type: MiddlewareType, middleware: Middleware): () => void;
|
|
274
646
|
/**
|
|
275
|
-
*
|
|
647
|
+
* Threads a value through every registered middleware in insertion
|
|
648
|
+
* order, each one seeing the previous one's return value. Throws are
|
|
649
|
+
* caught and logged — the faulty middleware contributes nothing and the
|
|
650
|
+
* previous result passes through unchanged so one bad hook can't break
|
|
651
|
+
* the render pipeline.
|
|
276
652
|
*
|
|
277
|
-
* @param type - The middleware type
|
|
278
|
-
* @param component - The component instance
|
|
279
|
-
* @param value - The value to process
|
|
280
|
-
* @param renderType - For 'render' middleware, indicates if template is 'string' or 'lit'
|
|
281
653
|
* @internal
|
|
282
654
|
*/
|
|
283
|
-
static _applyMiddleware(type: MiddlewareType, component: Component, value:
|
|
655
|
+
static _applyMiddleware(type: MiddlewareType, component: Component, value: unknown, renderType?: RenderType): unknown;
|
|
284
656
|
/**
|
|
285
|
-
*
|
|
657
|
+
* Quick probe used by Component on hot render paths to skip building a
|
|
658
|
+
* middleware context when nothing is registered for this type.
|
|
286
659
|
*
|
|
287
660
|
* @internal
|
|
288
661
|
*/
|