@jasonshimmy/custom-elements-runtime 2.5.1 → 2.5.5
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 +115 -40
- package/dist/css/colors.d.ts +14 -0
- package/dist/custom-elements-runtime.cjs.js +6 -18
- package/dist/custom-elements-runtime.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.colors.cjs.js +2 -0
- package/dist/custom-elements-runtime.colors.cjs.js.map +1 -0
- package/dist/custom-elements-runtime.colors.es.js +279 -0
- package/dist/custom-elements-runtime.colors.es.js.map +1 -0
- package/dist/custom-elements-runtime.directive-enhancements.es.js +1 -1
- package/dist/custom-elements-runtime.es.js +246 -3648
- package/dist/custom-elements-runtime.es.js.map +1 -1
- package/dist/custom-elements-runtime.event-bus.cjs.js +1 -1
- package/dist/custom-elements-runtime.event-bus.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.event-bus.es.js +28 -25
- package/dist/custom-elements-runtime.event-bus.es.js.map +1 -1
- package/dist/custom-elements-runtime.router.cjs.js +20 -20
- package/dist/custom-elements-runtime.router.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.router.es.js +790 -464
- package/dist/custom-elements-runtime.router.es.js.map +1 -1
- package/dist/custom-elements-runtime.ssr.cjs.js +1 -1
- package/dist/custom-elements-runtime.ssr.es.js +12 -8
- package/dist/custom-elements-runtime.ssr.es.js.map +1 -1
- package/dist/custom-elements-runtime.store.cjs.js +1 -1
- package/dist/custom-elements-runtime.store.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.store.es.js +5 -5
- package/dist/custom-elements-runtime.store.es.js.map +1 -1
- package/dist/custom-elements-runtime.transitions.cjs.js +1 -1
- package/dist/custom-elements-runtime.transitions.es.js +1 -1
- package/dist/event-bus.d.ts +17 -4
- package/dist/index.d.ts +13 -3
- package/dist/keep-alive.d.ts +50 -0
- package/dist/{logger-BuUYv7C_.js → logger-BvkEbVM4.js} +15 -11
- package/dist/logger-BvkEbVM4.js.map +1 -0
- package/dist/logger-CSALKaYm.cjs +2 -0
- package/dist/logger-CSALKaYm.cjs.map +1 -0
- package/dist/namespace-helpers-4qeKVqQw.cjs +5 -0
- package/dist/namespace-helpers-4qeKVqQw.cjs.map +1 -0
- package/dist/namespace-helpers-DcD_6_K1.js +989 -0
- package/dist/namespace-helpers-DcD_6_K1.js.map +1 -0
- package/dist/router/active-proxy.d.ts +5 -0
- package/dist/router/component-loader.d.ts +11 -0
- package/dist/router/instance.d.ts +11 -0
- package/dist/router/matcher.d.ts +14 -0
- package/dist/router/path-utils.d.ts +48 -0
- package/dist/router/types.d.ts +134 -0
- package/dist/router.d.ts +6 -147
- package/dist/runtime/builtin-components.d.ts +78 -0
- package/dist/runtime/component/element-class.d.ts +4 -0
- package/dist/runtime/component/factory.d.ts +39 -0
- package/dist/runtime/component/registry.d.ts +16 -0
- package/dist/runtime/component.d.ts +3 -50
- package/dist/runtime/discovery-state.d.ts +30 -0
- package/dist/runtime/hooks.d.ts +115 -0
- package/dist/runtime/logger.d.ts +19 -1
- package/dist/runtime/monitoring/health-monitor.d.ts +56 -0
- package/dist/runtime/reactive.d.ts +39 -7
- package/dist/runtime/render.d.ts +20 -4
- package/dist/runtime/scheduler.d.ts +115 -2
- package/dist/runtime/template-compiler/impl.d.ts +14 -0
- package/dist/runtime/template-compiler/lru-cache.d.ts +20 -0
- package/dist/runtime/template-compiler/props-parser.d.ts +15 -0
- package/dist/runtime/template-compiler/vnode-utils.d.ts +5 -0
- package/dist/runtime/template-compiler.d.ts +5 -28
- package/dist/runtime/types.d.ts +10 -0
- package/dist/runtime/vdom-directives.d.ts +71 -0
- package/dist/runtime/vdom-helpers.d.ts +126 -0
- package/dist/runtime/vdom-patch.d.ts +67 -0
- package/dist/runtime/vdom.d.ts +16 -140
- package/dist/ssr.d.ts +2 -1
- package/dist/teleport.d.ts +68 -0
- package/dist/template-compiler-CA4YRaBu.cjs +23 -0
- package/dist/template-compiler-CA4YRaBu.cjs.map +1 -0
- package/dist/template-compiler-CJFwjLCP.js +3981 -0
- package/dist/template-compiler-CJFwjLCP.js.map +1 -0
- package/dist/transitions-DPZiuXb9.cjs +330 -0
- package/dist/transitions-DPZiuXb9.cjs.map +1 -0
- package/dist/{transitions-CZ21fzhh.js → transitions-Di5wW9yc.js} +1059 -618
- package/dist/transitions-Di5wW9yc.js.map +1 -0
- package/dist/transitions.d.ts +1 -1
- package/package.json +20 -12
- package/dist/logger-BuUYv7C_.js.map +0 -1
- package/dist/logger-DiXdWaF-.cjs +0 -2
- package/dist/logger-DiXdWaF-.cjs.map +0 -1
- package/dist/namespace-helpers-BsKQl3aH.cjs +0 -5
- package/dist/namespace-helpers-BsKQl3aH.cjs.map +0 -1
- package/dist/namespace-helpers-Dw1mgQab.js +0 -692
- package/dist/namespace-helpers-Dw1mgQab.js.map +0 -1
- package/dist/transitions-CZ21fzhh.js.map +0 -1
- package/dist/transitions-RXe2brRm.cjs +0 -302
- package/dist/transitions-RXe2brRm.cjs.map +0 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in utility components provided by the custom-elements runtime.
|
|
3
|
+
*
|
|
4
|
+
* These components are registered automatically when this module is imported.
|
|
5
|
+
* They are designed to be minimal, tree-shakeable, and zero-dependency.
|
|
6
|
+
*
|
|
7
|
+
* Included components:
|
|
8
|
+
* - `<cer-suspense>` — Shows a fallback while async work is pending
|
|
9
|
+
* - `<cer-error-boundary>` — Catches render errors and shows a fallback UI
|
|
10
|
+
* - `<cer-keep-alive>` — Preserves component state across DOM removal/re-insertion
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* A built-in component that conditionally renders either the default slot
|
|
14
|
+
* content or the `fallback` slot content, controlled by the `pending` prop.
|
|
15
|
+
*
|
|
16
|
+
* Use the `pending` attribute/property to signal that async work is in
|
|
17
|
+
* progress; the component will swap to the `fallback` slot until `pending`
|
|
18
|
+
* becomes falsy.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```html
|
|
22
|
+
* <cer-suspense pending>
|
|
23
|
+
* <!-- shown when pending=false -->
|
|
24
|
+
* <my-async-content></my-async-content>
|
|
25
|
+
*
|
|
26
|
+
* <!-- shown while pending=true -->
|
|
27
|
+
* <div slot="fallback">Loading…</div>
|
|
28
|
+
* </cer-suspense>
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example Programmatic usage
|
|
32
|
+
* ```ts
|
|
33
|
+
* component('my-data-loader', () => {
|
|
34
|
+
* const pending = ref(true);
|
|
35
|
+
* useOnConnected(async () => {
|
|
36
|
+
* await fetchData();
|
|
37
|
+
* pending.value = false;
|
|
38
|
+
* });
|
|
39
|
+
* return html`
|
|
40
|
+
* <cer-suspense pending="${pending.value}">
|
|
41
|
+
* <my-data-view></my-data-view>
|
|
42
|
+
* <div slot="fallback">Loading data…</div>
|
|
43
|
+
* </cer-suspense>
|
|
44
|
+
* `;
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function registerSuspense(): void;
|
|
49
|
+
/**
|
|
50
|
+
* A built-in component that catches errors thrown during child component
|
|
51
|
+
* rendering and displays a fallback UI instead of crashing the page.
|
|
52
|
+
*
|
|
53
|
+
* Errors are caught via the `useOnError` lifecycle hook. Once an error is
|
|
54
|
+
* caught the component switches to showing the `fallback` named slot (or a
|
|
55
|
+
* default "Something went wrong" message if no fallback slot is provided).
|
|
56
|
+
*
|
|
57
|
+
* Call the custom `reset()` method on the element to clear the error and
|
|
58
|
+
* attempt re-rendering the default slot.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```html
|
|
62
|
+
* <cer-error-boundary>
|
|
63
|
+
* <my-risky-component></my-risky-component>
|
|
64
|
+
*
|
|
65
|
+
* <div slot="fallback">
|
|
66
|
+
* <p>Something went wrong. <button onclick="this.closest('cer-error-boundary').reset()">Retry</button></p>
|
|
67
|
+
* </div>
|
|
68
|
+
* </cer-error-boundary>
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function registerErrorBoundary(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Register all built-in components (`cer-suspense`, `cer-error-boundary`,
|
|
74
|
+
* `cer-keep-alive`).
|
|
75
|
+
* Safe to call multiple times — each registration is guarded by a
|
|
76
|
+
* `customElements.get()` check.
|
|
77
|
+
*/
|
|
78
|
+
export declare function registerBuiltinComponents(): void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ComponentConfig } from '../types';
|
|
2
|
+
export declare function createElementClass<S extends object, C extends object, P extends object, T extends object = object>(tag: string, config: ComponentConfig<S, C, P, T>): CustomElementConstructor | {
|
|
3
|
+
new (): object;
|
|
4
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { VNode } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Streamlined functional component API with automatic reactive props and lifecycle hooks.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* // Simple component with no parameters
|
|
8
|
+
* component('simple-header', () => {
|
|
9
|
+
* return html`<h1>Hello World</h1>`;
|
|
10
|
+
* });
|
|
11
|
+
*
|
|
12
|
+
* // With props using useProps() hook
|
|
13
|
+
* component('with-props', () => {
|
|
14
|
+
* const { message } = useProps({ message: 'Hello' });
|
|
15
|
+
* return html`<div>${message}</div>`;
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // With props and lifecycle hooks
|
|
19
|
+
* component('my-switch', () => {
|
|
20
|
+
* const { modelValue, label } = useProps({ modelValue: false, label: '' });
|
|
21
|
+
* const emit = useEmit();
|
|
22
|
+
*
|
|
23
|
+
* useOnConnected(() => console.log('Switch connected!'));
|
|
24
|
+
* useOnDisconnected(() => console.log('Switch disconnected!'));
|
|
25
|
+
*
|
|
26
|
+
* return html`
|
|
27
|
+
* <label>
|
|
28
|
+
* ${label}
|
|
29
|
+
* <input
|
|
30
|
+
* type="checkbox"
|
|
31
|
+
* :checked="${modelValue}"
|
|
32
|
+
* @change="${(e) => emit('update:modelValue', e.target.checked)}"
|
|
33
|
+
* />
|
|
34
|
+
* </label>
|
|
35
|
+
* `;
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function component(tag: string, renderFn: () => VNode | VNode[] | Promise<VNode | VNode[]>): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ComponentConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* Runtime registry of component configs.
|
|
5
|
+
* NOTE: This is an internal implementation detail. Do not import from the
|
|
6
|
+
* published package in consumer code — it is intended for runtime/HMR and
|
|
7
|
+
* internal tests only. Consumers should use the public `component` API.
|
|
8
|
+
*/
|
|
9
|
+
export declare const registry: Map<string, ComponentConfig<object, object, object>>;
|
|
10
|
+
/**
|
|
11
|
+
* Lazily initialize the global registry slot with SSR safety.
|
|
12
|
+
* This avoids performing a write to globalThis at module-import time
|
|
13
|
+
* (which is a side-effect that prevents bundlers from tree-shaking).
|
|
14
|
+
* Enhanced with SSR detection and multi-tenant safety.
|
|
15
|
+
*/
|
|
16
|
+
export declare function initGlobalRegistryIfNeeded(): void;
|
|
@@ -1,50 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Runtime registry of component configs.
|
|
5
|
-
* NOTE: This is an internal implementation detail. Do not import from the
|
|
6
|
-
* published package in consumer code — it is intended for runtime/HMR and
|
|
7
|
-
* internal tests only. Consumers should use the public `component` API.
|
|
8
|
-
*/
|
|
9
|
-
export declare const registry: Map<string, ComponentConfig<object, object, object>>;
|
|
10
|
-
export declare function createElementClass<S extends object, C extends object, P extends object, T extends object = object>(tag: string, config: ComponentConfig<S, C, P, T>): CustomElementConstructor | {
|
|
11
|
-
new (): object;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Streamlined functional component API with automatic reactive props and lifecycle hooks.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* // Simple component with no parameters
|
|
19
|
-
* component('simple-header', () => {
|
|
20
|
-
* return html`<h1>Hello World</h1>`;
|
|
21
|
-
* });
|
|
22
|
-
*
|
|
23
|
-
* // With props using useProps() hook
|
|
24
|
-
* component('with-props', () => {
|
|
25
|
-
* const { message } = useProps({ message: 'Hello' });
|
|
26
|
-
* return html`<div>${message}</div>`;
|
|
27
|
-
* });
|
|
28
|
-
*
|
|
29
|
-
* // With props and lifecycle hooks
|
|
30
|
-
* component('my-switch', () => {
|
|
31
|
-
* const { modelValue, label } = useProps({ modelValue: false, label: '' });
|
|
32
|
-
* const emit = useEmit();
|
|
33
|
-
*
|
|
34
|
-
* useOnConnected(() => console.log('Switch connected!'));
|
|
35
|
-
* useOnDisconnected(() => console.log('Switch disconnected!'));
|
|
36
|
-
*
|
|
37
|
-
* return html`
|
|
38
|
-
* <label>
|
|
39
|
-
* ${label}
|
|
40
|
-
* <input
|
|
41
|
-
* type="checkbox"
|
|
42
|
-
* :checked="${modelValue}"
|
|
43
|
-
* @change="${(e) => emit('update:modelValue', e.target.checked)}"
|
|
44
|
-
* />
|
|
45
|
-
* </label>
|
|
46
|
-
* `;
|
|
47
|
-
* });
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export declare function component(tag: string, renderFn: () => VNode | VNode[] | Promise<VNode | VNode[]>): void;
|
|
1
|
+
export { registry } from './component/registry';
|
|
2
|
+
export { createElementClass } from './component/element-class';
|
|
3
|
+
export { component } from './component/factory';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* discovery-state.ts
|
|
3
|
+
*
|
|
4
|
+
* Isolated discovery-render flag. Extracted from hooks.ts to break the
|
|
5
|
+
* circular dependency between hooks.ts and reactive.ts — both modules need
|
|
6
|
+
* to check `isDiscoveryRender()`, but hooks.ts also imports from reactive.ts.
|
|
7
|
+
*
|
|
8
|
+
* All side-effectful hooks (watchEffect, watch, useOnConnected, useStyle,
|
|
9
|
+
* provide, inject, useEmit, …) must guard their setup with
|
|
10
|
+
* `isDiscoveryRender()` and return early / return no-ops when it is true.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Returns `true` while a discovery render is in progress.
|
|
14
|
+
* Used by `html` tagged templates and hooks to short-circuit side effects.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare function isDiscoveryRender(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Mark the start of a discovery render pass.
|
|
20
|
+
* Call this immediately before invoking the render function for the first time
|
|
21
|
+
* (before `useProps` prop-name collection).
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function beginDiscoveryRender(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Mark the end of a discovery render pass.
|
|
27
|
+
* Call this in a `finally` block after the discovery render function returns.
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export declare function endDiscoveryRender(): void;
|
package/dist/runtime/hooks.d.ts
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
* Context-based hooks for functional components
|
|
3
3
|
* Provides React-like hooks with perfect TypeScript inference
|
|
4
4
|
*/
|
|
5
|
+
export { beginDiscoveryRender, endDiscoveryRender } from './discovery-state';
|
|
6
|
+
/**
|
|
7
|
+
* Returns true while a discovery render is in progress.
|
|
8
|
+
* Used by `html` and other primitives to short-circuit side effects.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function isDiscoveryRender(): boolean;
|
|
5
12
|
/**
|
|
6
13
|
* Set the current component context (called internally during render)
|
|
7
14
|
* @internal
|
|
@@ -12,6 +19,12 @@ export declare function setCurrentComponentContext(context: Record<string, unkno
|
|
|
12
19
|
* @internal
|
|
13
20
|
*/
|
|
14
21
|
export declare function clearCurrentComponentContext(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Get the current component context. Useful for advanced composable patterns
|
|
24
|
+
* that need to access or pass the context explicitly.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export declare function getCurrentComponentContext(): Record<string, unknown> | null;
|
|
15
28
|
/**
|
|
16
29
|
* Get the emit function for the current component
|
|
17
30
|
* Must be called during component render
|
|
@@ -137,3 +150,105 @@ export declare function useProps<T extends Record<string, unknown>>(defaults: T)
|
|
|
137
150
|
* ```
|
|
138
151
|
*/
|
|
139
152
|
export declare function useStyle(callback: () => string): void;
|
|
153
|
+
/**
|
|
154
|
+
* Store a value under a key so that descendant components can retrieve it
|
|
155
|
+
* with `inject()`. Must be called during component render.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* component('theme-provider', () => {
|
|
160
|
+
* provide('theme', 'dark');
|
|
161
|
+
* return html`<slot></slot>`;
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export declare function provide<T>(key: string | symbol, value: T): void;
|
|
166
|
+
/**
|
|
167
|
+
* Retrieve a value provided by an ancestor component. Traverses the shadow
|
|
168
|
+
* DOM tree upward through ShadowRoot host elements looking for the nearest
|
|
169
|
+
* `provide()` call with the matching key. Returns `defaultValue` (or
|
|
170
|
+
* `undefined`) when no provider is found. Must be called during render.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* component('themed-button', () => {
|
|
175
|
+
* const theme = inject<string>('theme', 'light');
|
|
176
|
+
* return html`<button class="btn-${theme}">Click</button>`;
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export declare function inject<T>(key: string | symbol, defaultValue?: T): T | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* Execute a function that calls hooks (useOnConnected, useOnDisconnected, etc.)
|
|
183
|
+
* using an explicit component context rather than requiring the call to happen
|
|
184
|
+
* directly inside a render function. This enables composable utility functions
|
|
185
|
+
* that register lifecycle callbacks from outside the render body.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* function useLogger(label: string) {
|
|
190
|
+
* return createComposable(() => {
|
|
191
|
+
* useOnConnected(() => console.log(`${label} connected`));
|
|
192
|
+
* useOnDisconnected(() => console.log(`${label} disconnected`));
|
|
193
|
+
* });
|
|
194
|
+
* }
|
|
195
|
+
*
|
|
196
|
+
* component('my-comp', () => {
|
|
197
|
+
* const stopLogger = useLogger('my-comp');
|
|
198
|
+
* stopLogger(context); // pass the component context explicitly
|
|
199
|
+
* return html`<div>Hello</div>`;
|
|
200
|
+
* });
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* More commonly, use it as a direct wrapper inside render:
|
|
204
|
+
* ```ts
|
|
205
|
+
* component('my-comp', () => {
|
|
206
|
+
* // Accepts context automatically from getCurrentComponentContext()
|
|
207
|
+
* createComposable(() => {
|
|
208
|
+
* useOnConnected(() => console.log('connected from composable'));
|
|
209
|
+
* })();
|
|
210
|
+
* return html`<div>Hello</div>`;
|
|
211
|
+
* });
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
export declare function createComposable<T>(fn: () => T): (ctx?: Record<string, unknown>) => T;
|
|
215
|
+
/**
|
|
216
|
+
* Expose a public interface from the current component so that parent
|
|
217
|
+
* components holding a template ref to this element can call its methods
|
|
218
|
+
* or read its properties. Must be called during component render.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* component('my-counter', () => {
|
|
223
|
+
* const count = ref(0);
|
|
224
|
+
* useExpose({ increment: () => count.value++, get count() { return count.value; } });
|
|
225
|
+
* return html`<div>${count.value}</div>`;
|
|
226
|
+
* });
|
|
227
|
+
*
|
|
228
|
+
* // Parent: counterRef.value.increment()
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
export declare function useExpose<T extends Record<string, unknown>>(exposed: T): void;
|
|
232
|
+
/**
|
|
233
|
+
* Access named slots provided to the current component. Returns helpers to
|
|
234
|
+
* check slot presence and retrieve slotted elements. Must be called during
|
|
235
|
+
* component render.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* component('my-card', () => {
|
|
240
|
+
* const slots = useSlots();
|
|
241
|
+
* return html`
|
|
242
|
+
* <div class="card">
|
|
243
|
+
* <slot></slot>
|
|
244
|
+
* ${slots.has('footer') ? html`<footer><slot name="footer"></slot></footer>` : ''}
|
|
245
|
+
* </div>
|
|
246
|
+
* `;
|
|
247
|
+
* });
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
export declare function useSlots(): {
|
|
251
|
+
has(name?: string): boolean;
|
|
252
|
+
getNodes(name?: string): Element[];
|
|
253
|
+
names(): string[];
|
|
254
|
+
};
|
package/dist/runtime/logger.d.ts
CHANGED
|
@@ -6,6 +6,14 @@
|
|
|
6
6
|
* Programmatically toggle dev-mode logging at runtime.
|
|
7
7
|
* Prefer setting `globalThis.__CE_RUNTIME_DEV__ = true` before importing
|
|
8
8
|
* the runtime so logs are enabled as early as possible.
|
|
9
|
+
*
|
|
10
|
+
* @param v - `true` to enable dev logging, `false` to disable it.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { setDevMode } from '@jasonshimmy/custom-elements-runtime';
|
|
15
|
+
* setDevMode(true); // enable verbose dev logs
|
|
16
|
+
* ```
|
|
9
17
|
*/
|
|
10
18
|
export declare function setDevMode(v: boolean): void;
|
|
11
19
|
/**
|
|
@@ -17,6 +25,16 @@ export declare function devError(message: string, ...args: unknown[]): void;
|
|
|
17
25
|
*/
|
|
18
26
|
export declare function devWarn(message: string, ...args: unknown[]): void;
|
|
19
27
|
/**
|
|
20
|
-
* Log
|
|
28
|
+
* Log an informational message only in development mode.
|
|
29
|
+
* No-ops in production builds or when dev mode is disabled.
|
|
30
|
+
*
|
|
31
|
+
* @param message - Message to log.
|
|
32
|
+
* @param args - Additional values to pass to `console.log`.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { devLog } from '@jasonshimmy/custom-elements-runtime';
|
|
37
|
+
* devLog('[my-component] mounted', { props });
|
|
38
|
+
* ```
|
|
21
39
|
*/
|
|
22
40
|
export declare function devLog(message: string, ...args: unknown[]): void;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Health Monitoring System
|
|
3
|
+
* Tracks framework health metrics and provides early warning for potential issues
|
|
4
|
+
*/
|
|
5
|
+
interface HealthMetric {
|
|
6
|
+
name: string;
|
|
7
|
+
value: number;
|
|
8
|
+
threshold: number;
|
|
9
|
+
status: 'healthy' | 'warning' | 'critical';
|
|
10
|
+
lastUpdated: number;
|
|
11
|
+
history: number[];
|
|
12
|
+
}
|
|
13
|
+
interface HealthReport {
|
|
14
|
+
overall: 'healthy' | 'warning' | 'critical';
|
|
15
|
+
metrics: Record<string, HealthMetric>;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
recommendations: string[];
|
|
18
|
+
}
|
|
19
|
+
export type { HealthReport };
|
|
20
|
+
/**
|
|
21
|
+
* Public interface for a health monitor instance.
|
|
22
|
+
* All state is managed internally via closures — no class syntax.
|
|
23
|
+
*/
|
|
24
|
+
export interface HealthMonitorInstance {
|
|
25
|
+
/** Update a specific health metric value */
|
|
26
|
+
updateMetric(name: string, value: number): void;
|
|
27
|
+
/** Get the current health report */
|
|
28
|
+
getHealthReport(): HealthReport;
|
|
29
|
+
/** Add a listener to be notified when a health check runs */
|
|
30
|
+
addListener(listener: (report: HealthReport) => void): void;
|
|
31
|
+
/** Remove a previously registered listener */
|
|
32
|
+
removeListener(listener: (report: HealthReport) => void): void;
|
|
33
|
+
/** Stop the periodic health monitoring timer */
|
|
34
|
+
stop(): void;
|
|
35
|
+
/** Get historical values for a specific metric */
|
|
36
|
+
getMetricHistory(name: string): number[];
|
|
37
|
+
/** Clear all metric history */
|
|
38
|
+
clearHistory(): void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a new health monitor instance.
|
|
42
|
+
* All mutable state lives in closures — no `class` or `this`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createHealthMonitor(): HealthMonitorInstance;
|
|
45
|
+
/**
|
|
46
|
+
* Get the global health monitor singleton instance.
|
|
47
|
+
*/
|
|
48
|
+
export declare function getHealthMonitor(): HealthMonitorInstance;
|
|
49
|
+
/**
|
|
50
|
+
* Update a health metric from anywhere in the framework.
|
|
51
|
+
*/
|
|
52
|
+
export declare function updateHealthMetric(name: string, value: number): void;
|
|
53
|
+
/**
|
|
54
|
+
* Get the current health status report.
|
|
55
|
+
*/
|
|
56
|
+
export declare function getHealthStatus(): HealthReport;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WatchOptions } from './types';
|
|
1
2
|
/**
|
|
2
3
|
* Global reactive system for tracking dependencies and triggering updates
|
|
3
4
|
*/
|
|
@@ -71,6 +72,22 @@ export declare class ReactiveState<T> {
|
|
|
71
72
|
constructor(initialValue: T);
|
|
72
73
|
get value(): T;
|
|
73
74
|
set value(newValue: T);
|
|
75
|
+
/**
|
|
76
|
+
* Read the current value without registering a reactive dependency.
|
|
77
|
+
* Useful for internal infrastructure (e.g. stable hook slots) that must
|
|
78
|
+
* inspect the stored value without re-triggering the containing component.
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
peek(): T;
|
|
82
|
+
/**
|
|
83
|
+
* Set the initial value without triggering any reactive updates or warnings.
|
|
84
|
+
* Only intended for internal/infrastructure use (e.g. storing a stable hook
|
|
85
|
+
* handle in a reactive slot without causing a spurious re-render).
|
|
86
|
+
* The value is stored as-is without reactive proxy wrapping so that opaque
|
|
87
|
+
* objects (e.g. TeleportHandle) are not accidentally instrumented.
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
initSilent(value: T): void;
|
|
74
91
|
addDependent(componentId: string): void;
|
|
75
92
|
removeDependent(componentId: string): void;
|
|
76
93
|
getDependents(): Set<string>;
|
|
@@ -101,18 +118,37 @@ export declare function ref<T>(initialValue: T): ReactiveState<T>;
|
|
|
101
118
|
*/
|
|
102
119
|
export declare function isReactiveState(v: unknown): v is ReactiveState<unknown>;
|
|
103
120
|
/**
|
|
104
|
-
* Create computed state that derives from other reactive state
|
|
121
|
+
* Create computed state that derives from other reactive state.
|
|
122
|
+
* The result is cached and only recomputed when tracked reactive dependencies change.
|
|
105
123
|
*
|
|
106
124
|
* @example
|
|
107
125
|
* ```ts
|
|
108
126
|
* const firstName = ref('John');
|
|
109
127
|
* const lastName = ref('Doe');
|
|
110
128
|
* const fullName = computed(() => `${firstName.value} ${lastName.value}`);
|
|
129
|
+
* console.log(fullName.value); // 'John Doe' — cached until firstName or lastName changes
|
|
111
130
|
* ```
|
|
112
131
|
*/
|
|
113
132
|
export declare function computed<T>(fn: () => T): {
|
|
114
133
|
readonly value: T;
|
|
115
134
|
};
|
|
135
|
+
/**
|
|
136
|
+
* Run a side-effect function immediately and automatically re-run it whenever
|
|
137
|
+
* any reactive state accessed inside `fn` changes. Similar to Vue's `watchEffect`.
|
|
138
|
+
*
|
|
139
|
+
* @returns A cleanup function that stops the effect.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* const count = ref(0);
|
|
144
|
+
* const stop = watchEffect(() => {
|
|
145
|
+
* document.title = `Count: ${count.value}`;
|
|
146
|
+
* });
|
|
147
|
+
* count.value++; // automatically re-runs the effect
|
|
148
|
+
* stop(); // cancel the effect
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function watchEffect(fn: () => void): () => void;
|
|
116
152
|
/**
|
|
117
153
|
* Create a watcher that runs when dependencies change
|
|
118
154
|
*
|
|
@@ -124,9 +160,5 @@ export declare function computed<T>(fn: () => T): {
|
|
|
124
160
|
* });
|
|
125
161
|
* ```
|
|
126
162
|
*/
|
|
127
|
-
export declare function watch<T>(source: ReactiveState<T>, callback: (newValue: T, oldValue?: T) => void, options?:
|
|
128
|
-
|
|
129
|
-
}): () => void;
|
|
130
|
-
export declare function watch<T>(source: () => T, callback: (newValue: T, oldValue?: T) => void, options?: {
|
|
131
|
-
immediate?: boolean;
|
|
132
|
-
}): () => void;
|
|
163
|
+
export declare function watch<T>(source: ReactiveState<T>, callback: (newValue: T, oldValue?: T) => void, options?: WatchOptions): () => void;
|
|
164
|
+
export declare function watch<T>(source: () => T, callback: (newValue: T, oldValue?: T) => void, options?: WatchOptions): () => void;
|
package/dist/runtime/render.d.ts
CHANGED
|
@@ -11,18 +11,34 @@ export declare function registerChildComponent(shadowRoot: ShadowRoot, childEl:
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function unregisterChildComponent(shadowRoot: ShadowRoot, childEl: HTMLElement): void;
|
|
13
13
|
/**
|
|
14
|
-
* Renders the component output.
|
|
14
|
+
* Renders the component output with optimized error handling and loading states.
|
|
15
15
|
*/
|
|
16
16
|
export declare function renderComponent<S extends object, C extends object, P extends object, T extends object>(shadowRoot: ShadowRoot | null, cfg: ComponentConfig<S, C, P, T>, context: ComponentContext<S, C, P, T>, refs: Refs['refs'], setHtmlString: (html: string) => void, setLoading: (val: boolean) => void, setError: (err: Error | null) => void, applyStyle: (html: string) => void): void;
|
|
17
17
|
/**
|
|
18
|
-
* Renders VNode(s) to the shadowRoot.
|
|
18
|
+
* Renders VNode(s) to the shadowRoot with performance optimizations.
|
|
19
19
|
*/
|
|
20
20
|
export declare function renderOutput<S extends object, C extends object, P extends object, T extends object>(shadowRoot: ShadowRoot | null, output: VNode | VNode[], context: ComponentContext<S, C, P, T>, refs: Refs['refs'], setHtmlString: (html: string) => void): void;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Advanced render request with intelligent throttling and loop detection.
|
|
23
23
|
*/
|
|
24
24
|
export declare function requestRender(renderFn: () => void, lastRenderTime: number, renderCount: number, setLastRenderTime: (t: number) => void, setRenderCount: (c: number) => void, renderTimeoutId: ReturnType<typeof setTimeout> | null, setRenderTimeoutId: (id: ReturnType<typeof setTimeout> | null) => void): void;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Optimized style application with intelligent caching and generation tracking.
|
|
27
27
|
*/
|
|
28
28
|
export declare function applyStyle<S extends object, C extends object, P extends object, T extends object>(shadowRoot: ShadowRoot | null, context: ComponentContext<S, C, P, T>, htmlString: string, styleSheet: CSSStyleSheet | null, setStyleSheet: (sheet: CSSStyleSheet | null) => void): void;
|
|
29
|
+
/**
|
|
30
|
+
* Clean up render-related caches for a shadow root
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export declare function cleanupRenderCaches(shadowRoot: ShadowRoot): void;
|
|
34
|
+
/**
|
|
35
|
+
* Get render performance metrics for debugging
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export declare function getRenderStats(shadowRoot: ShadowRoot): {
|
|
39
|
+
renderCount: number;
|
|
40
|
+
lastRenderTime: number;
|
|
41
|
+
isThrottled: boolean;
|
|
42
|
+
childComponentCount: number;
|
|
43
|
+
hasCachedHtml: boolean;
|
|
44
|
+
};
|