/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import { PATH_TOKENS_TYPE, TOKEN_TYPES_TYPE } from "@fluid-experimental/property-properties"; import { DataBinding } from "./dataBinding.js"; export type NodeType = DataBindingTree | ArrayNode | null | undefined; interface Value { pathCallbacks?: Record>; representations?: Map; ordered?: DataBinding[]; groupedByDataBindingType?: Map; } export type NodeValue = Value | null; /** * Helper function: reconstruct a tokenized path up to (but not including) a position. * * @param in_tokenizedPath - tokenized path * @param in_pathDelimiters - token types for the path * @param in_position - position in the path (must be >= 0 <= the length of the tokenized path) * @returns reconstructed path * @constructor * @package * @hidden */ export declare function concatTokenizedPath(in_tokenizedPath: (string | number)[], in_pathDelimiters: TOKEN_TYPES_TYPE[], in_position: number): string; /** * An DataBindingTree is a tree structure that is intended to reflect the structure of a property set hierarchy * but doesn't inherently have values at all nodes. * * @ignore * @alias DataBindingTree * @package * @hidden */ export declare class DataBindingTree { _value: NodeValue; _childNodes: any; /** * Constructor * @constructor */ constructor(); /** * Returns the value stored at this node. * * @returns The value stored at this node. * @package */ getValue(): NodeValue; /** * @param value The value to store at this node */ setValue(value: NodeValue): void; /** * @param in_tokens - tokenized path * * @returns the path */ generatePathFromTokens(in_tokens: (string | number)[]): string | undefined; /** * Compute the number of nodes that are needed and wasted in the subtree. The count covers all nodes in the * subtree, including this node. A node is needed if it is holding a value, or if it is needed to represent * the tree structure to hold a needed node deeper in the hierarchy. Otherwise it is wasted. * * @returns the number of nodes * that are needed in the subtree, and the number that are wasted. 'gen' is for a general node, and 'arrays' is * for nodes that are specifically known to be array nodes. */ _computeUsage(): { genNeeded: number; genWasted: number; arraysNeeded: number; arraysWasted: number; }; /** * * @param in_from - index from which to generate the path * @param in_tokens - the tokens to generate a path for * * @returns The formatted string, or undefined if tokens are an invalid path */ _generatePathFromTokensInternal(in_from: number, in_tokens: (string | number)[]): string | undefined; /** * Returns the node in the tree that is the farthest along the given path. * * @param in_tokenizedPath - tokenized path to be removed * @param in_pathDelimiters - token types for the path * @param in_position - where we are along the path * @param in_parent - parent node (only used by ArrayNode/MapNode) * * @returns The node farthest along the path and the corresponding * (partial) path * @private */ _getClosestNode(in_tokenizedPath: (string | number)[], in_pathDelimiters: PATH_TOKENS_TYPE[], in_position: number, _in_parent?: DataBindingTree | ArrayNode): any; /** * Returns the node in the tree that is the farthest along the given path. * * @param path - The path * @returns The deepest node in the tree * @package */ getClosestNode(path: string): any; /** * Returns the node in the tree that is at the given path (if one exists). * * @param in_tokenizedPath - tokenized path to the node * @param in_position - where we are along the path * @param in_pathDelimiters - token types for the path * @param io_collectedNodes - (optional) collect nodes along the path in this array * @returns The node at the path if one exists, null otherwise. * @private */ _getNode(in_tokenizedPath: (string | number)[], in_position: number, in_pathDelimiters?: PATH_TOKENS_TYPE[], io_collectedNodes?: DataBindingTree[]): NodeType; /** * Returns the node in the tree that is at the given path (if one exists). * * @param path - The path to search for. * @returns The node at the path if one exists, null otherwise. * @package */ getNode(path: string): NodeType; /** * Returns the node in the tree that is at the given tokenized path (if one exists). * * @param tokenizedPath - The tokenized path * @returns The node at the path if one exists, null otherwise. * @package */ getNodeForTokenizedPath(tokenizedPath: Array): NodeType; /** * Internal function: insert the value into the tree using the tokenized path and calling itself recursively. * * @param in_tokenizedPath - tokenized path to the value * @param in_pathDelimiters - token types for the path * @param in_position - where we are along the path * @param in_value - The value to insert into the tree * @returns The node that was created for the value */ _insert(in_tokenizedPath: (string | number)[], in_pathDelimiters: PATH_TOKENS_TYPE[], in_position: number, in_value: any): NodeType; /** * @param in_tokenizedPathOrToken - Tokenized path * @param in_propertyContext - Property context * @returns node */ insertChild(in_tokenizedPathOrToken: Array | string | number, in_propertyContext: string): NodeType; /** * Insert a node at the given (absolute) path into the tree with the given value. * * The path may contain any number of non-existing elements or array indices larger than an existing array's length, * these will be inserted into the tree as necessary. * * This function assumes that a) the path we insert here does not exist yet. Parts of it may exist, but not the * entire path. If a path ends with an element in a collection, the collection may * exist already. * b) the new node will contain a path callback. * * @param in_absolutePath - the path to be inserted * @param in_value - The value of the newly inserted node * @returns The node that was created for the value * @package */ insertNodeForPathCallback(in_absolutePath: string, in_value?: any): NodeType; /** * Make sure that if a node with path callbacks is in an array container, this is correctly flagged in the array. * * @param in_absolutePath - the path to the node * @package */ setNodeForPathCallback(in_absolutePath: string): void; /** * Internal function: convert a MapNode or ArrayNode child to a vanilla DataBindingTree node. * * @param io_parentNode - parent node whose child we convert * @param in_key - key (index) of the child we want to replace */ protected _convertFromSpecializedNode(io_parentNode: DataBindingTree | ArrayNode | MapNode, in_key: string | number): void; /** * Internal function: convert a DataBindingTree child to an ArrayNode. * * It is assumed that the key of all children are numeric. The new node's _highestPathCallbackIndexA flag will be set * to signal that this must have path callbacks. If the keys are not continuous, array elements that don't * have corresponding keys will be left as "undefined". * * @param io_parentNode - parent node whose child we convert * @param in_key - key (index) of the child we want to replace */ protected _convertToArrayNode(io_parentNode: DataBindingTree | ArrayNode, in_key: string | number): void; /** * Internal function: convert a DataBindingTree child to a MapNode. * * @param io_parentNode - parent node whose child we convert * @param in_key - key (index) of the child we want to replace */ private _convertToMapNode; /** * @param in_context - Context * @returns Node/Tree */ static _createDataBindingTreeNodeForContext(in_context: string): MapNode | NodeType; /** * Inserts the value into the tree at the provided path. * * @param in_path - The path to the value * @param in_value - The value to insert into the tree * @returns The node that was created for the path * @package */ insert(in_path: string, in_value: any): NodeType; /** * Internal function: removes a sub tree using the tokenized path and calling itself recursively. * * @param in_tokenizedPath - tokenized path to be removed * @param in_pathDelimiters - token types for the path * @param in_position - where we are along the path * @returns The root of the subtree that was removed, or null * @private */ _remove(in_tokenizedPath: (string | number)[], in_pathDelimiters: TOKEN_TYPES_TYPE[], in_position: number): NodeType; /** * Removes a sub tree * * @param in_path - The path to remove. If empty, just returns itself (nothing is removed). * @returns The subtree that was removed. Null if nothing was removed * @package */ remove(in_path: string): NodeType; /** * Calls a function with each value stored in the tree. * * @param callback - The function to call. Called with the value of each node. * @param postCallback - Function which is called after all child nodes have been processed * @param - The path up to this node * @package */ forEachChild(callback: Function, postCallback?: Function, in_path?: (string | number)[]): void; /** * Returns a boolean indicating whether the node has children (i.e. is a leaf) * * @returns true if we have children * @package */ hasChildren(): boolean; /** * Returns an array of nodes that make up the given path in the tree * // @TODO currently unused. * @param in_path - the path * * @returns the array of nodes * @package */ getNodesInPath(in_path: string): Array; /** * Returns a map of paths to the children * * @returns The map of children * @package */ getChildren(): { [s: string]: DataBindingTree; }; /** * Collect all subtree paths from a node into a set * * @param in_currentPath - the path we've come so far * @param in_paths - the set into which we're collecting * @private */ _getSubtreePaths(in_currentPath: string, in_paths: Set): void; /** * Returns a set of paths (relative to this node) to all nodes in the subtree from this node * * @returns The subtree paths as a set of strings * @package */ getSubtreePaths(): Set; /** * Returns the immediate child with the given name of this node * * @param in_child - the name of the child or an array of names * if an array is passed, the .getChild() function will be performed on each child in sequence * for example .get(['position','x']) is equivalent to .get('position').get('x') * @returns The specified child node (or undefined) * @package */ getChild(in_child: string | Array): NodeType; /** * Removes the subtree of a direct child * * @param in_child - the name of the child to remove * @returns The subtree that was removed. Null if nothing was removed * @package */ removeChild(in_child: number | string): NodeType; /** * Return a data binding of the provided type * @param in_bindingType - The requested bindingType * @returns A data binding of the provided type or undefined if no data binding is * present. * @package */ getDataBindingByType(in_bindingType: string): DataBinding | undefined; /** * Returns an array of Data Bindings that are present at this node. * * @returns An array of Data Binders in registration order, * which may be empty if no suitable data bindings are present at the node. * @package */ getDataBindings(): Array; } /** * A MapNode is a node in the DataBinding tree that contains a map of sub trees. * * @constructor * @ignore * @package */ export declare class MapNode extends DataBindingTree { /** * * @param in_from - index from which to generate the path * @param in_tokens - the tokens to generate a path for * * @returns the formatted string, or undefined if tokens are an invalid path */ _generatePathFromTokensInternal(in_from: number, in_tokens: string[]): string | undefined; } /** * An ArrayNode is a node in the DataBinding tree that contains an array of sub trees. * * @constructor * @ignore * @package */ export declare class ArrayNode extends DataBindingTree { _highestPathCallbackIndex: number; _actualLength: number; /** * Constructor */ constructor(); /** * * @param in_from - index from which to generate the path * @param in_tokens - the tokens to generate a path for * * @returns the formatted string, or undefined if tokens are an invalid path */ _generatePathFromTokensInternal(in_from: number, in_tokens: string[]): string | undefined; /** * Internal function: insert the value into the tree using the tokenized path and calling itself recursively. * * Note: currently we assume that reference paths will *only* be inserted into the tree using this function and * not e.g. insertChild() ! * * @param in_tokenizedPath - tokenized path to the value * @param in_pathDelimiters - token types for the path * @param in_position - where we are along the path * @param in_value - The value to insert into the tree * @returns The node that was created for the value */ _insert(in_tokenizedPath: (string | number)[], in_pathDelimiters: TOKEN_TYPES_TYPE[], in_position: number, in_value: any): NodeType; /** * @param in_index - index * @param in_propertyContext - property context * @returns node * @package */ insertChild(in_index: number, in_propertyContext: string): NodeType; /** * Returns the tree node farthest along the given path. * * @param in_tokenizedPath - tokenized path to be removed * @param in_pathDelimiters - token types for the path * @param in_position - where we are along the path * @param in_parent - parent node (returned when we can't traverse further) * * @returns The node farthest along the path and the corresponding * (partial) path */ _getClosestNode(in_tokenizedPath: (string | number)[], in_pathDelimiters: PATH_TOKENS_TYPE[], in_position: number, in_parent: DataBindingTree | ArrayNode): any; /** * Returns the node in the tree that is at the given path (if one exists). * * @param in_tokenizedPath - tokenized path to the node * @param in_position - where we are along the path * @param in_pathDelimiters - token types for the path * @param io_collectedNodes - (optional) collect nodes along the path in this array * @returns The node at the path if one exists, null otherwise. */ _getNode(in_tokenizedPath: (string | number)[], in_position: number, in_pathDelimiters: TOKEN_TYPES_TYPE[], io_collectedNodes?: DataBindingTree[]): NodeType; /** * Returns the tree node at the given path. * * @param path - The path to traverse. Must start with an index (E.g. [1].a.b.etc...) * @returns The node at the path if one exists. Otherwise, undefined. * @package */ getNode(path: string): NodeType; /** * Internal function: removes a sub tree using the tokenized path and calling itself recursively. * * @param in_tokenizedPath - tokenized path to be removed * @param in_pathDelimiters - token types for the path * @param in_position - where we are along the path * @returns The root of the subtree that was removed, or null */ _remove(in_tokenizedPath: string[], in_pathDelimiters: TOKEN_TYPES_TYPE[], in_position: number): NodeType; /** * Removes the subtree of a direct child * * @param in_index - the index of the child to remove * @returns The subtree that was removed. null if nothing was removed * @package */ removeChild(in_index: number): NodeType; /** * Calls a function with each value stored in the tree. * * @param callback - The function to call. Called with the value of each node. * @param postCallback - Function which is called after all child nodes have been processed * @param in_path - The path up to this node * @package */ forEachChild(callback: Function, postCallback?: Function, in_path?: (string | number)[]): void; /** * Returns a boolean indicating whether the node has children (i.e. is it a leaf node) * * @returns true if we have children * @package */ hasChildren(): boolean; /** * Returns an array of objects describing the children * * @returns The array of children * @package */ getChildren(): any; /** * Collect all subtree paths from a node into a set * * @param in_currentPath - the path we've come so far * @param in_paths - the set into which we're collecting */ _getSubtreePaths(in_currentPath: string, in_paths: Set): void; /** * Returns the immediate child with the given name of this node * * @param in_child - the name of the child or an array of names * if an array is passed, the .getChild() function will be performed on each child in sequence * for example .get(['position','x']) is equivalent to .get('position').get('x') * @returns The specified child node (or null) * @package */ getChild(in_child: string | string[]): NodeType; } export {}; //# sourceMappingURL=dataBindingTree.d.ts.map