ivi
Version:
Lightweight Embeddable Web UI Library.
87 lines • 2.92 kB
TypeScript
import { type SNode, type Component } from "./core.js";
/**
* Dispatch Event options.
*/
export interface DispatchEventOptions {
/**
* Option indicating whether the event bubbles. The default is `true`.
*/
bubbles?: boolean;
/**
* Option indicating whether the event can be cancelled. The default is
* `false`.
*/
cancelable?: boolean;
/**
* Option indicating whether the event will trigger listeners outside of a
* shadow root. The default is `false`.
*/
composed?: boolean;
}
export type EventDispatcher = {
(component: Component): boolean;
<T>(component: Component, value: T): boolean;
};
/**
* Creates an event dispatcher that finds the closest child DOM node and emits
* a CustomEvent with `EventTarget.dispatchEvent()` method.
*
* Event dispatcher invokes event handlers synchronously. All event handlers are
* invoked before event dispatcher returns.
*
* @typeparam T Data type.
* @param eventType Event type.
* @param options {@link DispatchEventOptions}.
* @returns `false` if event is cancelable, and at least one of the event
* handlers which received event called `Event.preventDefault()`. Otherwise
* `true`.
* @__NO_SIDE_EFFECTS__
*/
export declare const eventDispatcher: <T>(eventType: string, options?: DispatchEventOptions) => EventDispatcher;
/**
* Finds the closest DOM node from a Stateful Tree {@link SNode}.
*
* @typeparam T DOM node type.
* @param sNode Stateful Tree {@link SNode}.
* @returns DOM node.
*/
export declare const findDOMNode: <T extends Node | Text>(sNode: SNode | null) => T | null;
/**
* VisitNodesDirective controls the {@link visitNodes} traversal algorithm.
*/
export declare const enum VisitNodesDirective {
/** Continue traversing the tree. */
Continue = 0,
/** Stops immediately. */
StopImmediate = 1,
/**
* Stops traversing through children nodes and continues trversing through
* adjacent nodes.
*/
Stop = 2
}
/**
* Traverses stateful tree and invokes `visitor` function on each {@link SNode}.
*
* @param sNode {@link SNode}.
* @param visitor Visitor function.
* @returns {@link VisitNodesDirective}
*/
export declare const visitNodes: (sNode: SNode, visitor: (opState: SNode) => VisitNodesDirective) => VisitNodesDirective;
/**
* Checks if a Stateful Tree {@link SNode} contains a DOM element.
*
* @param node Stateful Tree {@link SNode}.
* @param element DOM element.
* @returns True when parent contains an element.
*/
export declare const containsDOMElement: (node: SNode, element: Element) => boolean;
/**
* Checks if a Stateful Tree {@link SNode} has a child DOM element.
*
* @param node Stateful Tree {@link SNode}.
* @param child DOM element.
* @returns True when parent has a DOM element child.
*/
export declare const hasDOMElement: (node: SNode, child: Element) => boolean;
//# sourceMappingURL=utils.d.ts.map