vasille
Version:
The same framework which is designed to build bulletproof frontends (core library).
180 lines (179 loc) • 5.94 kB
TypeScript
import { Reactive } from "../core/core.js";
import { IValue } from "../core/ivalue.js";
import { Runner } from "./runner.js";
/**
* This class is symbolic
* @extends Reactive
*/
export declare abstract class Root<Node, Element, TagOptions extends object> extends Reactive {
/**
* The children list
* @type Array
*/
readonly children: Set<Fragment<Node, Element, TagOptions>>;
readonly runner: Runner<Node, Element, TagOptions>;
lastChild: Fragment<Node, Element, TagOptions> | undefined;
protected constructor(runner: Runner<Node, Element, TagOptions>);
/**
* Pushes a node to children immediately
* @param node {Fragment} A node to push
* @protected
*/
protected pushNode(node: Fragment<Node, Element, TagOptions>): void;
/**
* Find the first node in the element if so exists
* @return {?Element}
* @protected
*/
protected findFirstChild(): Node | Element | undefined;
/**
* Append a node to the end of element
* @param node {Node} node to insert
*/
abstract appendNode(node: Node): void;
/**
* Defines a text fragment
* @param text {String | IValue} A text fragment string
*/
text(text: unknown): void;
debug(text: IValue<unknown>): void;
/**
* Defines a tag element
* @param tagName {String} the tag name
* @param input
* @param cb {function(Tag, *)} callback
*/
tag(tagName: string, input: TagOptions, cb?: (ctx: Tag<Node, Element, TagOptions>) => void): void;
/**
* Defines a custom element
* @param node {Fragment} vasille element to insert
* @param callback {function($ : *)}
*/
create<T extends Fragment<Node, Element, TagOptions>>(node: T, callback?: (ctx: T) => void): void;
destroy(): void;
}
export declare class Fragment<Node, Element, TagOptions extends object> extends Root<Node, Element, TagOptions> {
parent: Root<Node, Element, TagOptions>;
constructor(runner: Runner<Node, Element, TagOptions>);
/**
* Next node
* @type {?Fragment}
*/
protected next?: Fragment<Node, Element, TagOptions>;
/**
* Previous node
* @type {?Fragment}
*/
protected prev?: Fragment<Node, Element, TagOptions>;
/**
* Pushes a node to children immediately
* @param node {Fragment} A node to push
* @protected
*/
protected pushNode(node: Fragment<Node, Element, TagOptions>): void;
/**
* Append a node to the end of element
* @param node {Node} node to insert
*/
appendNode(node: Node): void;
/**
* Insert a node as a sibling of this
* @param node {Node} node to insert
*/
insertAdjacent(node: Node): void;
compose(): void;
insertBefore(node: Fragment<Node, Element, TagOptions>): void;
insertAfter(node: Fragment<Node, Element, TagOptions>): void;
remove(): void;
destroy(): void;
}
export interface TextProps {
text: unknown;
}
/**
* Represents a text node
* @class TextNode
* @extends Fragment
*/
export declare abstract class TextNode<Node, Element, TagOptions extends object> extends Fragment<Node, Element, TagOptions> {
protected handler: ((v: unknown) => void) | null;
protected readonly data: unknown;
constructor(input: TextProps, runner: Runner<Node, Element, TagOptions>);
abstract compose(): void;
protected abstract findFirstChild(): Node;
destroy(): void;
}
/**
* Vasille node which can manipulate an element node
* @class INode
* @extends Fragment
*/
export declare abstract class INode<Node, Element, TagOptions extends object> extends Fragment<Node, Element, TagOptions> {
/**
* The element of vasille node
* @type Element
*/
protected node: Element;
get element(): Element;
insertAdjacent(node: Node): void;
protected abstract applyOptions(options: TagOptions): void;
}
/**
* Represents an Vasille.js HTML element node
* @class Tag
* @extends INode
*/
export declare abstract class Tag<Node, Element, TagOptions extends object> extends INode<Node, Element, TagOptions> {
readonly name: string;
readonly options: TagOptions;
constructor(options: TagOptions, runner: Runner<Node, Element, TagOptions>, tagName: string);
abstract compose(): void;
protected findFirstChild(): Node | Element | undefined;
appendNode(node: Node): void;
}
interface SwitchedNodeCase<Node, Element, TagOptions extends object> {
$case: IValue<unknown>;
slot: (node: Fragment<Node, Element, TagOptions>) => void;
}
/**
* Defines a node which can switch its children conditionally
*/
export declare class SwitchedNode<Node, Element, TagOptions extends object> extends Fragment<Node, Element, TagOptions> {
/**
* Index of current true condition
* @type number
*/
private index;
/**
* Array of possible cases
* @type {Array<{cond : IValue<unknown>, cb : function(Fragment)}>}
*/
private cases;
/**
* A function that syncs index and content will be bounded to each condition
* @type {Function}
*/
private readonly sync;
/**
* Constructs a switch node and define a sync function
*/
constructor(runner: Runner<Node, Element, TagOptions>, cases: SwitchedNodeCase<Node, Element, TagOptions>[], _default?: (node: Fragment<Node, Element, TagOptions>) => void);
compose(): void;
destroy(): void;
}
export interface DebugProps {
text: IValue<unknown>;
}
/**
* Represents a debug node
* @class DebugNode
* @extends Fragment
*/
export declare abstract class DebugNode<Node, Element, TagOptions extends object> extends Fragment<Node, Element, TagOptions> {
protected handler: ((v: unknown) => void) | null;
protected readonly data: IValue<unknown>;
constructor(input: DebugProps, runner: Runner<Node, Element, TagOptions>);
abstract compose(): void;
destroy(): void;
}
export {};