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