@stackend/api
Version:
JS bindings to api.stackend.com
123 lines • 3.72 kB
TypeScript
import Reference from './Reference';
import XcapObject from './XcapObject';
export declare const TREE_CLASS = "se.josh.xcap.tree.impl.TreeImpl";
export interface Node {
permalink: string;
name: string;
description: string;
ref: Reference | null /** Referenced object */;
referenceId: number /** Id of referenced object */;
data: any /** user data */;
children: Array<Node>;
}
export interface Tree extends XcapObject, Node {
totalChildNodes: number;
}
/**
* Create, but does not store a new tree
*/
export declare function newTree(name: string): Tree;
/**
* Create, but does not store a new node
*/
export declare function newTreeNode(name: string): Node;
/**
* Clone a node
* @param node
* @returns {Node|*}
*/
export declare function cloneNode(node: Node): Node;
/**
* Clone a tree
* @param tree
* @returns {Node}
*/
export declare function cloneTree(tree: Tree): Tree;
/**
* Get the permalink to a three path
* @param treePath
* @param node
*/
export declare function getPermalink(treePath: Array<Node>, node?: Node | null): string;
/**
* Get an array with all parent nodes up to a specific node
* @param tree
* @param node
*/
export declare function getTreePath(tree: Tree | null, node: Node | null): Array<Node> | null;
export declare function getTreePathMatch(tree: Tree, apply: (node: Node, parent: Node, parents: Array<Node>, i: number) => boolean): Array<Node> | null;
/**
* Get a tree node by its permalink
* @param tree
* @param permalink
*/
export declare function getTreeNodeByPermalink(tree: Tree, permalink: string | null): Node | null;
export declare function _findNodeByPermalink(tree: Tree, permalink: string, accumulatedPermalink?: string): Node | null;
/**
* Remove a tree node
* @param tree
* @param node
* @returns {boolean}
*/
export declare function removeTreeNode(tree: Tree, node: Node): Node | null;
export declare function removeTreeNodeByPermalink(tree: Tree, permalink: string): Node | null;
export declare enum InsertionPoint {
BEFORE = "BEFORE",
AFTER = "AFTER",
CHILD = "CHILD"
}
/**
* Move a tree node
* @param tree
* @param node
* @param insertionPoint
* @param relativeTo
*/
export declare function moveTreeNode(tree: Tree, node: Node, insertionPoint: InsertionPoint, relativeTo: Node): boolean;
/**
* Add a node to the tree
* @param tree
* @param node
*/
export declare function addNode(tree: Tree, node: Node): Tree | null;
/**
* Find a node that matches the test
* @param tree
* @param test
* @returns {Node|null|?Node}
*/
export declare function findNode(tree: Tree, test: (node: Node) => boolean): Node | null;
/**
* Get the tree path to a node
* @param tree
* @param permalink
* @returns {?Array<Node>}
*/
export declare function getNodePath(tree: Tree, permalink: string): Array<Node> | null;
/**
* Get a node by it's permalink
* @param tree
* @param permalink
*/
export declare function getNode(tree: Tree, permalink: string): Node | null;
/**
* Apply a function to each node
* @param tree
* @param apply A function to apply. Returning true will abort the processing
* @return Path to the node where the iteration was aborted
*/
export declare function forEachNode(tree: Tree, apply: (node: Node, parent: Node, parents: Array<Node>, i: number) => boolean): Array<Node> | null;
/**
* Check if the path is a sub path of ofPath
* @param path
* @param ofPath
* @returns {boolean}
*/
export declare function isSubPath(path: Array<Node>, ofPath: Array<Node>): boolean;
/**
* Get the tree part of the permalink
* @param permalink
* @returns {string|null}
*/
export declare function getTreePermalink(permalink: string | null): string | null;
//# sourceMappingURL=tree.d.ts.map