vasille
Version:
The first Developer eXperience Orientated front-end framework (core library).
208 lines (207 loc) • 7.12 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, T extends object = object> extends Reactive<T> {
/**
* 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(input: T, 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 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
* @param cb {function (TextNode)} Callback if previous is slot name
*/
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;
/**
* Defines an if node
* @param cond {IValue} condition
* @param cb {function(Fragment)} callback to run on true
* @return {this}
*/
if(cond: IValue<unknown>, cb: (node: Fragment<Node, Element, TagOptions>) => void): void;
else(cb: (node: Fragment<Node, Element, TagOptions>) => void): void;
elif(cond: IValue<unknown>, cb: (node: Fragment<Node, Element, TagOptions>) => void): void;
/**
* Create a case for switch
* @param cond {IValue<boolean>}
* @param cb {function(Fragment) : void}
* @return {{cond : IValue, cb : (function(Fragment) : void)}}
*/
case(cond: IValue<unknown>, cb: (node: Fragment<Node, Element, TagOptions>) => void): {
cond: IValue<unknown>;
cb: (node: Fragment<Node, Element, TagOptions>) => void;
};
/**
* @param cb {(function(Fragment) : void)}
* @return {{cond : IValue, cb : (function(Fragment) : void)}}
*/
default(cb: (node: Fragment<Node, Element, TagOptions>) => void): {
cond: IValue<boolean>;
cb: (node: Fragment<Node, Element, TagOptions>) => void;
};
destroy(): void;
}
export declare class Fragment<Node, Element, TagOptions extends object, T extends object = object> extends Root<Node, Element, TagOptions, T> {
readonly name?: string;
parent: Root<Node, Element, TagOptions>;
constructor(input: T, runner: Runner<Node, Element, TagOptions>, name?: string);
/**
* 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, TextProps> {
protected handler: ((v: unknown) => void) | null;
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, 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> {
constructor(input: TagOptions, runner: Runner<Node, Element, TagOptions>, tagName: string);
abstract compose(): void;
protected findFirstChild(): Node | Element | undefined;
appendNode(node: Node): 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 sync;
/**
* Constructs a switch node and define a sync function
*/
constructor(runner: Runner<Node, Element, TagOptions>);
addCase(case_: {
cond: IValue<unknown>;
cb: (node: Fragment<Node, Element, TagOptions>) => void;
}): void;
/**
* Creates a child node
* @param cb {function(Fragment)} Call-back
*/
createChild(cb: (node: Fragment<Node, Element, TagOptions>) => void): 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, DebugProps> {
protected handler: ((v: unknown) => void) | null;
constructor(input: DebugProps, runner: Runner<Node, Element, TagOptions>);
abstract compose(): void;
destroy(): void;
}