/** * Component runtime — implicit "current component" context plus every lifecycle * hook a `setup()` function can call. * * Design note: hooks are plain module-level functions (not a bag/context object * passed into `setup`). They resolve the active component through a single * module-level pointer (`currentContext`), set for the duration of `setup()` and * of each queued `onMounted` callback. This is the same mechanism React/Vue/Solid * use for their composable hooks — it lets any helper function (not just the * top-level `setup()` body) call `onMounted`/`onCleanup`/`bind`/... directly, * with no context object to thread through every layer of a composable. */ import { type Cleanup, type Readable } from '@vielzeug/ripple'; export type OnMountedCallback = () => Cleanup | undefined; export type OnFormResetCallback = () => void; export type RuntimeContext = { element: HTMLElement; formResetCallbacks: OnFormResetCallback[]; mountCallbacks: OnMountedCallback[]; }; /** * Returns the current component's host element. * Only valid synchronously during component `setup()` (or inside a composable * called from it) — throws otherwise. */ export declare const getHost: () => HTMLElement; export declare const tryRegisterCleanup: (fn: Cleanup) => boolean; /** Registers cleanup work for component disconnect. */ export declare const onCleanup: (fn: Cleanup) => void; /** * Register work to run after the component template mounts to the DOM. * Multiple callbacks run in registration order. */ export declare const onMounted: (fn: OnMountedCallback) => void; /** * Register work to run when the ancestor `
` is reset (native `formResetCallback`, * only fires for `formAssociated: true` components). Multiple callbacks run in * registration order, every time the form resets — unlike `onMounted`, this isn't a * one-shot hook. */ export declare const onFormReset: (fn: OnFormResetCallback) => void; /** * Create a reactive effect scoped to the component lifecycle. * Automatically cleaned up on component disconnect. * Returns a stop function that disposes the effect immediately. * * Named `watchEffect` (not `watch`) to avoid shadowing `@vielzeug/ripple`'s * `watch(source, callback)`, which has different semantics (explicit source, * old/new value pair) — the two are commonly imported in the same file. */ export declare const watchEffect: (fn: () => Cleanup | undefined) => (() => void); /** * Attach a scoped event listener that is automatically removed on component disconnect. * Silently no-ops when `target` is `null` or `undefined` (safe for reactive targets). */ export declare function onEvent(target: EventTarget | null | undefined, event: K, listener: (e: HTMLElementEventMap[K]) => void, options?: AddEventListenerOptions): void; /** * Watch a ref signal and run a callback when it resolves to a non-null element. * The callback's return value is used as a cleanup function. */ export declare const onElement: (ref: Readable, callback: (el: T) => Cleanup | undefined | undefined) => (() => void); //# sourceMappingURL=runtime.d.ts.map