From baaa731f79de2501f17c48abbef1f83915c64a91 Mon Sep 17 00:00:00 2001 From: AdaskoTheBeAsT Date: Sun, 7 Sep 2014 18:39:55 +0200 Subject: [PATCH] Synchronization with 3.0.3 version of jstree Synchronization with 3.0.3 version of jstree --- jstree/jstree-tests.ts | 33 ++- jstree/jstree.d.ts | 464 +++++++++++++++++++++++++++++++++-------- 2 files changed, 412 insertions(+), 85 deletions(-) diff --git a/jstree/jstree-tests.ts b/jstree/jstree-tests.ts index ddd1c60ddd..ce82807218 100644 --- a/jstree/jstree-tests.ts +++ b/jstree/jstree-tests.ts @@ -6,6 +6,8 @@ var version: string = $.jstree.version; // create new instance var instance1: JSTree = $('div').jstree(); +$('div').jstree('open_node', '#branch'); + // get existing reference var existingReference: JSTree = $.jstree.reference('sds'); @@ -63,5 +65,34 @@ var advancedTree = $("#briefcasetree").jstree({ } } } - }); +}); + +var a = $('a').jstree(); + + +//tree with new unique plugin parameters +var treeWithUnique = $('#treeWithUnique').jstree({ + unique: { + case_sensitive: true, + duplicate: (name: string, counter: number): string => { + return name + ' ( ' + counter.toString() + ' )'; + } + } +}); + +// tree with new core properties +var treeWithNewCoreProperties = $('#treeWithNewCoreProperties').jstree({ + core: { + worker: true, + force_text: true, + } +}); + +// tree with new checkbox properties +var treeWithNewCheckboxProperties = $('#treeWithNewCheckboxProperties').jstree({ + checkbox: { + cascade: true, + tie_selection: true + } +}); diff --git a/jstree/jstree.d.ts b/jstree/jstree.d.ts index 4039795bab..10eff8d759 100644 --- a/jstree/jstree.d.ts +++ b/jstree/jstree.d.ts @@ -1,4 +1,4 @@ -// Type definitions for jsTree v3.0.0 +// Type definitions for jsTree v3.0.3 // Project: http://www.jstree.com/ // Definitions by: Adam Pluciński // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -17,19 +17,50 @@ interface JQueryStatic { } +interface JQuery { + /** + * Create an instance, get an instance or invoke a command on a instance. + * + * If there is no instance associated with the current node a new one is created + * and `arg` is used to extend `$.jstree.defaults` for this new instance. There would be no return value (chaining is not broken). + * + * If there is an existing instance and `arg` is a string the command specified by `arg` is executed on the instance, + * with any additional arguments passed to the function. If the function returns a value it will be returned (chaining could break depending on function). + * + * If there is an existing instance and `arg` is not a string the instance itself is returned (similar to `$.jstree.reference`). + * + * In any other case - nothing is returned and chaining is not broken. + * + * __Examples__ + * + * $('#tree1').jstree(); // creates an instance + * $('#tree2').jstree({ plugins : [] }); // create an instance with some options + * $('#tree1').jstree('open_node', '#branch_1'); // call a method on an existing instance, passing additional arguments + * $('#tree2').jstree(); // get an existing instance (or create an instance) + * $('#tree2').jstree(true); // get an existing instance (will not create new instance) + * $('#branch_1').jstree().select_node('#branch_1'); // get an instance (using a nested element and call a method) + * + * @name $().jstree([arg]) + * @param {String|Object} arg + * @return {Mixed} + */ + jstree(): JSTree; + jstree(options: JSTreeStaticDefaults): JSTree; + jstree(arg: boolean): JSTree; + jstree(...args: any[]): any; +} + interface JSTreeStatic { /** - * specifies the jstree version in use - * @property version - * @type {string} - */ + * specifies the jstree version in use + * @name $.jstree.version + */ version: string; /** - * holds all the default options used when creating new instances - * @property defaults - * @type {JSTreeStaticDefaults} - */ + * holds all the default options used when creating new instances + * @name $.jstree.defaults + */ defaults: JSTreeStaticDefaults; /** @@ -37,19 +68,29 @@ interface JSTreeStatic { */ plugins: any[]; path: string; - idregex:any; + idregex: any; + /** - * creates a jstree instance - * @param el the element to create the instance on, can be jQuery extended or a selector - * @param options {JSTreeOptions} options for this instance (extends `$.jstree.defaults`) - * @returns {JSTree} the new instance - */ + * creates a jstree instance + * @name $.jstree.create(el [, options]) + * @param {DOMElement|jQuery|String} el the element to create the instance on, can be jQuery extended or a selector + * @param {Object} options options for this instance (extends `$.jstree.defaults`) + * @return {jsTree} the new instance + */ create(el: any, options?: JSTreeStaticDefaults): JSTree; /** - * the jstree class constructor, used only internally - * @param id {number} this instance's index - */ + * remove all traces of jstree from the DOM and destroy all instances + * @name $.jstree.destroy() + */ + destroy(): void; + + /** + * the jstree class constructor, used only internally + * @private + * @name $.jstree.core(id) + * @param {Number} id this instance's index + */ core(id: number): void; /** @@ -96,31 +137,39 @@ interface JSTreeStatic { interface JSTreeStaticDefaults { /** - * configure which plugins will be active on an instance. - * Should be an array of strings, where each element is a plugin name. - * The default is [] - */ + * configure which plugins will be active on an instance. + * Should be an array of strings, where each element is a plugin name. + * The default is `[]` + * @name $.jstree.defaults.plugins + */ plugins: string[]; + /** - * stores all defaults for the core - */ + * stores all defaults for the core + * @name $.jstree.defaults.core + */ core: JSTreeStaticDefaultsCore; + /** * stores all defaults for the checkbox plugin */ checkbox?: JSTreeStaticDefaultsCheckbox; + /** * stores all defaults for the contextmenu plugin */ contextmenu?: JSTreeStaticDefaultsContextMenu; + /** * stores all defaults for the drag'n'drop plugin */ dnd?: JSTreeStaticDefaultsDragNDrop; + /** * stores all defaults for the search plugin */ search?: JSTreeStaticDefaultsSearch; + /** * the settings function used to sort the nodes. * It is executed in the tree's context, accepts two nodes as arguments and should return `1` or `-1`. @@ -128,10 +177,12 @@ interface JSTreeStaticDefaults { * @plugin sort */ sort?: (x: any, y: any) => number; + /** * stores all defaults for the state plugin */ state?: JSTreeStaticDefaultsState; + /** * An object storing all types as key value pairs, * where the key is the type name and the value is an object @@ -151,10 +202,11 @@ interface JSTreeStaticDefaults { * default represents the default node - any settings here will be applied to all nodes that do not have a type specified. */ types?: any; - /** - * stores all defaults for the unique plugin - * @name $.jstree.defaults.unique - * @plugin unique + + /** + * stores all defaults for the unique plugin + * @name $.jstree.defaults.unique + * @plugin unique */ unique?: JSTreeStaticDefaultsUnique; } @@ -210,6 +262,7 @@ interface JSTreeStaticDefaultsCore { * @name $.jstree.defaults.core.data */ data?: any; + /** * configure the various strings used throughout the tree * @@ -222,7 +275,7 @@ interface JSTreeStaticDefaultsCore { * $('#tree').jstree({ * 'core' : { * 'strings' : { - * 'Loading...' : 'Please wait ...' + * 'Loading ...' : 'Please wait ...' * } * } * }); @@ -230,7 +283,7 @@ interface JSTreeStaticDefaultsCore { * @name $.jstree.defaults.core.strings */ strings?: any; - + /** * determines what happens when a user tries to modify the structure of the tree * If left as `false` all operations like create, rename, delete, move or copy are prevented. @@ -263,61 +316,87 @@ interface JSTreeStaticDefaultsCore { * @name $.jstree.defaults.core.animation */ animation?: any; + /** * a boolean indicating if multiple nodes can be selected * @name $.jstree.defaults.core.multiple */ multiple?: boolean; + /** * theme configuration object * @name $.jstree.defaults.core.themes */ themes?: JSTreeStaticDefaultsCoreThemes; + /** * if left as `true` all parents of all selected nodes will be opened once the tree loads (so that all selected nodes are visible to the user) * @name $.jstree.defaults.core.expand_selected_onload */ expand_selected_onload?: boolean; + + /** + * if left as `true` web workers will be used to parse incoming JSON data where possible, so that the UI will not be blocked by large requests. + * Workers are however about 30% slower. Defaults to `true` + * @name $.jstree.defaults.core.worker + */ + worker?: boolean; + + /** + * Force node text to plain text (and escape HTML). Defaults to `false` + * @name $.jstree.defaults.core.force_text + */ + force_text?: boolean; } interface JSTreeStaticDefaultsCoreThemes { /** - * the name of the theme to use (if left as false the default theme is used) + * the name of the theme to use (if left as `false` the default theme is used) + * @name $.jstree.defaults.core.themes.name */ name?: string; + /** - * the URL of the theme's CSS file, leave this as false if you have manually - * included the theme CSS (recommended). - * You can set this to true too which will try to autoload the theme. + * the URL of the theme's CSS file, leave this as `false` if you have manually included the theme CSS (recommended). You can set this to `true` too which will try to autoload the theme. + * @name $.jstree.defaults.core.themes.url */ url?: string; + /** - * the location of all jstree themes - only used if url is set to true + * the location of all jstree themes - only used if `url` is set to `true` + * @name $.jstree.defaults.core.themes.dir */ dir?: string; + /** * a boolean indicating if connecting dots are shown + * @name $.jstree.defaults.core.themes.dots */ dots?: boolean; + /** * a boolean indicating if node icons are shown + * @name $.jstree.defaults.core.themes.icons */ icons?: boolean; + /** * a boolean indicating if the tree background is striped + * @name $.jstree.defaults.core.themes.stripes */ stripes?: boolean; + /** - * a string (or boolean false) specifying the theme - * variant to use (if the theme supports variants) + * a string (or boolean `false`) specifying the theme variant to use (if the theme supports variants) + * @name $.jstree.defaults.core.themes.variant */ variant?: any; + /** - * a boolean specifying if a reponsive version of the theme should kick - * in on smaller screens (if the theme supports it). Defaults to true. + * a boolean specifying if a reponsive version of the theme should kick in on smaller screens (if the theme supports it). Defaults to `false`. + * @name $.jstree.defaults.core.themes.responsive */ responsive?: boolean; - } interface JSTreeStaticDefaultsCheckbox { @@ -327,32 +406,45 @@ interface JSTreeStaticDefaultsCheckbox { * @plugin checkbox */ visible: boolean; + /** * a boolean indicating if checkboxes should cascade down and have an undetermined state. Defaults to `true`. * @name $.jstree.defaults.checkbox.three_state * @plugin checkbox */ three_state: boolean; + /** * a boolean indicating if clicking anywhere on the node should act as clicking on the checkbox. Defaults to `true`. * @name $.jstree.defaults.checkbox.whole_node * @plugin checkbox */ whole_node: boolean; + /** * a boolean indicating if the selected style of a node should be kept, or removed. Defaults to `true`. * @name $.jstree.defaults.checkbox.keep_selected_style * @plugin checkbox */ keep_selected_style: boolean; - /** - * This setting controls how cascading and undetermined nodes are applied. - * If 'up' is in the string - cascading up is enabled, if 'down' is in the string - cascading down is enabled, if 'undetermined' is in the string - undetermined nodes will be used. - * If `three_state` is set to `true` this setting is automatically set to 'up+down+undetermined'. Defaults to ''. - * @name $.jstree.defaults.checkbox.cascade - * @plugin checkbox - */ - cascade:boolean; + + /** + * This setting controls how cascading and undetermined nodes are applied. + * If 'up' is in the string - cascading up is enabled, if 'down' is in the string - cascading down is enabled, if 'undetermined' is in the string - undetermined nodes will be used. + * If `three_state` is set to `true` this setting is automatically set to 'up+down+undetermined'. Defaults to ''. + * @name $.jstree.defaults.checkbox.cascade + * @plugin checkbox + */ + cascade: boolean; + + /** + * This setting controls if checkbox are bound to the general tree selection + * or to an internal array maintained by the checkbox plugin. + * Defaults to `true`, only set to `false` if you know exactly what you are doing. + * @name $.jstree.defaults.checkbox.tie_selection + * @plugin checkbox + */ + tie_selection: boolean; } interface JSTreeStaticDefaultsContextMenu { @@ -362,12 +454,14 @@ interface JSTreeStaticDefaultsContextMenu { * @plugin contextmenu */ select_node: boolean; + /** * a boolean indicating if the menu should be shown aligned with the node. Defaults to `true`, otherwise the mouse coordinates are used. * @name $.jstree.defaults.contextmenu.show_at_node * @plugin contextmenu */ show_at_node: boolean; + /** * an object of actions, or a function that accepts a node and a callback function and calls the callback function with an object of actions available for that node (you can also return the items too). * @@ -395,6 +489,7 @@ interface JSTreeStaticDefaultsDragNDrop { * @plugin dnd */ copy: boolean; + /** * a number indicating how long a node should remain hovered while dragging to be opened. Defaults to `500`. * @name $.jstree.defaults.dnd.open_timeout @@ -444,18 +539,21 @@ interface JSTreeStaticDefaultsSearch { * @plugin search */ ajax: any; + /** * Indicates if the search should be fuzzy or not (should `chnd3` match `child node 3`). Default is `true`. * @name $.jstree.defaults.search.fuzzy * @plugin search */ fuzzy: boolean; + /** * Indicates if the search should be case sensitive. Default is `false`. * @name $.jstree.defaults.search.case_sensitive * @plugin search */ case_sensitive: boolean; + /** * Indicates if the tree should be filtered to show only matching nodes * (keep in mind this can be a heavy on large trees in old browsers). Default is `false`. @@ -463,6 +561,7 @@ interface JSTreeStaticDefaultsSearch { * @plugin search */ show_only_matches: boolean; + /** * Indicates if all nodes opened to reveal the search result, * should be closed when the search is cleared or a new search is performed. Default is `true`. @@ -477,6 +576,16 @@ interface JSTreeStaticDefaultsSearch { * @plugin search */ search_leaves_only: boolean; + + /** + * If set to a function it wil be called in the instance's scope with two arguments - + * search string and node (where node will be every node in the structure, so use with caution). + * If the function returns a truthy value the node will be considered a match + * (it might not be displayed if search_only_leaves is set to true and the node is not a leaf). Default is `false`. + * @name $.jstree.defaults.search.search_callback + * @plugin search + */ + search_callback: any; } interface JSTreeStaticDefaultsState { @@ -486,6 +595,7 @@ interface JSTreeStaticDefaultsState { * @plugin state */ key: string; + /** * A space separated list of events that trigger a state save. Defaults to `changed.jstree open_node.jstree close_node.jstree`. * @name $.jstree.defaults.state.events @@ -506,23 +616,23 @@ interface JSTreeStaticDefaultsState { * @plugin state */ filter: any; - } interface JSTreeStaticDefaultsUnique { - /** - * Indicates if the comparison should be case sensitive. Default is `false`. - * @name $.jstree.defaults.unique.case_sensitive - * @plugin unique - */ - case_sensitive:boolean; -} - -interface JQuery { - jstree(): JSTree; - jstree(options: JSTreeStaticDefaults): JSTree; - jstree(arg: boolean): JSTree; - jstree(...args: any[]): JSTree; + /** + * Indicates if the comparison should be case sensitive. Default is `false`. + * @name $.jstree.defaults.unique.case_sensitive + * @plugin unique + */ + case_sensitive: boolean; + /** + * A callback executed in the instance's scope when a new node is created + * and the name is already taken, the two arguments are the conflicting name and the counter. + * The default will produce results like `New node (2)`. + * @name $.jstree.defaults.unique.duplicate + * @plugin unique + */ + duplicate: (name: string, counter: number) => string; } interface JSTree extends JQuery { @@ -532,12 +642,14 @@ interface JSTree extends JQuery { * @param {Boolean} keep_html if not set to `true` the container will be emptied, otherwise the current DOM elements will be kept intact */ destroy: (keep_html?: boolean) => void; + /** * returns the jQuery extended instance container * @name get_container() * @return {jQuery} */ get_container: () => JQuery; + /** * get the JSON representation of a node (or the actual jQuery extended DOM node) by using any input (child DOM element, ID string, selector, etc) * @name get_node(obj [, as_dom]) @@ -545,7 +657,8 @@ interface JSTree extends JQuery { * @param {Boolean} as_dom * @return {Object|jQuery} */ - get_node: (obj: any, as_dom?: boolean) => JQuery; + get_node: (obj: any, as_dom?: boolean) => any; + /** * get the path to a node, either consisting of node texts, or of node IDs, optionally glued together (otherwise an array) * @name get_path(obj [, glue, ids]) @@ -554,7 +667,8 @@ interface JSTree extends JQuery { * @param {Boolean} ids if set to true build the path using ID, otherwise node text is used * @return {mixed} */ - get_path: (obj:any, glue:string, ids:boolean) => JQuery; + get_path: (obj: any, glue: string, ids: boolean) => any; + /** * get the next visible node that is below the `obj` node. If `strict` is set to `true` only sibling nodes are returned. * @name get_next_dom(obj [, strict]) @@ -562,7 +676,8 @@ interface JSTree extends JQuery { * @param {Boolean} strict * @return {jQuery} */ - get_next_dom: (obj:any, strict?:boolean) => JQuery; + get_next_dom: (obj: any, strict?: boolean) => JQuery; + /** * get the previous visible node that is above the `obj` node. If `strict` is set to `true` only sibling nodes are returned. * @name get_prev_dom(obj [, strict]) @@ -571,6 +686,7 @@ interface JSTree extends JQuery { * @return {jQuery} */ get_prev_dom: (obj: any, strict?: boolean) => JQuery; + /** * get the parent ID of a node * @name get_parent(obj) @@ -578,6 +694,7 @@ interface JSTree extends JQuery { * @return {String} */ get_parent: (obj: any) => string; + /** * get a jQuery collection of all the children of a node (node must be rendered) * @name get_children_dom(obj) @@ -585,6 +702,7 @@ interface JSTree extends JQuery { * @return {jQuery} */ get_children_dom: (obj: any) => JQuery; + /** * checks if a node has children * @name is_parent(obj) @@ -592,6 +710,7 @@ interface JSTree extends JQuery { * @return {Boolean} */ is_parent: (obj: any) => boolean; + /** * checks if a node is loaded (its children are available) * @name is_loaded(obj) @@ -599,6 +718,7 @@ interface JSTree extends JQuery { * @return {Boolean} */ is_loaded: (obj: any) => boolean; + /** * check if a node is currently loading (fetching children) * @name is_loading(obj) @@ -606,6 +726,7 @@ interface JSTree extends JQuery { * @return {Boolean} */ is_loading: (obj: any) => boolean; + /** * check if a node is opened * @name is_open(obj) @@ -613,6 +734,7 @@ interface JSTree extends JQuery { * @return {Boolean} */ is_open: (obj: any) => boolean; + /** * check if a node is in a closed state * @name is_closed(obj) @@ -620,6 +742,7 @@ interface JSTree extends JQuery { * @return {Boolean} */ is_closed: (obj: any) => boolean; + /** * check if a node has no children * @name is_leaf(obj) @@ -627,6 +750,7 @@ interface JSTree extends JQuery { * @return {Boolean} */ is_leaf: (obj: any) => boolean; + /** * loads a node (fetches its children using the `core.data` setting). Multiple nodes can be passed to by using an array. * @name load_node(obj [, callback]) @@ -636,13 +760,15 @@ interface JSTree extends JQuery { * @return {Boolean} * @trigger load_node.jstree */ - load_node: (obj: any, callback: any) => boolean; + load_node: (obj: any, callback: (node: any, status: boolean) => void) => boolean; + /** * redraws all nodes that need to be redrawn or optionally - the whole tree * @name redraw([full]) * @param {Boolean} full if set to `true` all nodes are redrawn. */ redraw: (full?: boolean) => void; + /** * opens a node, revaling its children. If the node is not loaded it will be loaded and opened once ready. * @name open_node(obj [, callback, animation]) @@ -653,6 +779,7 @@ interface JSTree extends JQuery { * @trigger open_node.jstree, after_open.jstree, before_open.jstree */ open_node: (obj: any, callback?: any, animation?: any) => void; + /** * closes a node, hiding its children * @name close_node(obj [, animation]) @@ -662,12 +789,14 @@ interface JSTree extends JQuery { * @trigger close_node.jstree, after_close.jstree */ close_node: (obj: any, animation?: any) => void; + /** * toggles a node - closing it if it is open, opening it if it is closed * @name toggle_node(obj) * @param {mixed} obj the node to toggle */ toggle_node: (obj: any) => void; + /** * opens all nodes within a node (or the tree), revaling their children. If the node is not loaded it will be loaded and opened once ready. * @name open_all([obj, animation, original_obj]) @@ -677,6 +806,7 @@ interface JSTree extends JQuery { * @trigger open_all.jstree */ open_all: (obj?: any, animation?: number, original_obj?: any) => void; + /** * closes all nodes within a node (or the tree), revaling their children * @name close_all([obj, animation]) @@ -685,6 +815,7 @@ interface JSTree extends JQuery { * @trigger close_all.jstree */ close_all: (obj?: any, animation?: number) => void; + /** * checks if a node is disabled (not selectable) * @name is_disabled(obj) @@ -692,6 +823,7 @@ interface JSTree extends JQuery { * @return {Boolean} */ is_disabled: (obj: any) => boolean; + /** * enables a node - so that it can be selected * @name enable_node(obj) @@ -699,6 +831,7 @@ interface JSTree extends JQuery { * @trigger enable_node.jstree */ enable_node: (obj: any) => boolean; + /** * disables a node - so that it can not be selected * @name disable_node(obj) @@ -706,6 +839,7 @@ interface JSTree extends JQuery { * @trigger disable_node.jstree */ disable_node: (obj: any) => boolean; + /** * select a node * @name select_node(obj [, supress_event, prevent_open]) @@ -714,7 +848,8 @@ interface JSTree extends JQuery { * @param {Boolean} prevent_open if set to `true` parents of the selected node won't be opened * @trigger select_node.jstree, changed.jstree */ - select_node: (obj: any, supress_event?: boolean, prevent_open?: boolean, e?:any) => void; + select_node: (obj: any, supress_event?: boolean, prevent_open?: boolean, e?: any) => any; + /** * deselect a node * @name deselect_node(obj [, supress_event]) @@ -722,7 +857,8 @@ interface JSTree extends JQuery { * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered * @trigger deselect_node.jstree, changed.jstree */ - deselect_node: (obj: any, supress_event?: boolean, e?:any) => void; + deselect_node: (obj: any, supress_event?: boolean, e?: any) => void; + /** * select all nodes in the tree * @name select_all([supress_event]) @@ -730,6 +866,7 @@ interface JSTree extends JQuery { * @trigger select_all.jstree, changed.jstree */ select_all: (supress_event?: boolean) => void; + /** * deselect all selected nodes * @name deselect_all([supress_event]) @@ -737,6 +874,7 @@ interface JSTree extends JQuery { * @trigger deselect_all.jstree, changed.jstree */ deselect_all: (supress_event?: boolean) => void; + /** * checks if a node is selected * @name is_selected(obj) @@ -744,41 +882,49 @@ interface JSTree extends JQuery { * @return {Boolean} */ is_selected: (obj: any) => boolean; + /** * get an array of all selected nodes * @name get_selected([full]) * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned * @return {Array} */ - get_selected: (full?: any) => string[]; + get_selected: (full?: any) => any[]; + /** * get an array of all top level selected nodes (ignoring children of selected nodes) * @name get_top_selected([full]) * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned * @return {Array} */ - get_top_selected: (full?: any) => string[]; + get_top_selected: (full?: any) => any[]; + /** * get an array of all bottom level selected nodes (ignoring selected parents) * @name get_top_selected([full]) * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned * @return {Array} */ - get_bottom_selected: (full?: any) => string[]; + get_bottom_selected: (full?: any) => any[]; + /** * refreshes the tree - all nodes are reloaded with calls to `load_node`. * @name refresh() * @param {Boolean} skip_loading an option to skip showing the loading indicator + * @param {Mixed} forget_state if set to `true` state will not be reapplied, + * if set to a function (receiving the current state as argument) the result of that function will be used as state * @trigger refresh.jstree */ - refresh: (skip_loading:boolean) => void; + refresh: (skip_loading: boolean, forget_state: any) => void; + /** * refreshes a node in the tree (reload its children) all opened nodes inside that node are reloaded with calls to `load_node`. * @name refresh_node(obj) - * @param {Boolean} skip_loading an option to skip showing the loading indicator - * @trigger refresh.jstree + * @param {mixed} obj the node + * @trigger refresh_node.jstree */ - refresh_node: (obj:any) => void; + refresh_node: (obj: any) => void; + /** * set (change) the ID of a node * @name set_id(obj, id) @@ -786,7 +932,8 @@ interface JSTree extends JQuery { * @param {String} id the new ID * @return {Boolean} */ - set_id: (obj: any, id: string) => void; + set_id: (obj: any, id: string) => boolean; + /** * get the text value of a node * @name get_text(obj) @@ -794,6 +941,7 @@ interface JSTree extends JQuery { * @return {String} */ get_text: (obj: any) => string; + /** * gets a JSON representation of a node (or the whole tree) * @name get_json([obj, options]) @@ -806,7 +954,8 @@ interface JSTree extends JQuery { * @param {Boolean} options.flat return flat JSON instead of nested * @return {Object} */ - get_json: (obj?: any, options?: JSTreeGetJsonOptions) => any; + get_json: (obj?: any, options?: JSTreeGetJsonOptions, flat?: boolean) => any; + /** * create a new node (do not confuse with load_node) * @name create_node([obj, node, pos, callback, is_loaded]) @@ -818,7 +967,8 @@ interface JSTree extends JQuery { * @return {String} the ID of the newly create node * @trigger model.jstree, create_node.jstree */ - create_node: (obj?: any, node?: any, pos?: any, callback?: any, is_loaded?: boolean) => string; + create_node: (par?: any, node?: any, pos?: any, callback?: any, is_loaded?: boolean) => string; + /** * set the text value of a node * @name rename_node(obj, val) @@ -828,6 +978,7 @@ interface JSTree extends JQuery { * @trigger rename_node.jstree */ rename_node: (obj: any, val: string) => boolean; + /** * remove a node * @name delete_node(obj) @@ -836,12 +987,14 @@ interface JSTree extends JQuery { * @trigger delete_node.jstree, changed.jstree */ delete_node: (obj: any) => boolean; + /** * get the last error * @name last_error() * @return {Object} */ last_error: () => any; + /** * move a node to a new parent * @name move_node(obj, par [, pos, callback, is_loaded]) @@ -853,6 +1006,7 @@ interface JSTree extends JQuery { * @trigger move_node.jstree */ move_node: (obj: any, par: any, pos?: any, callback?: any, internal?: boolean) => void; + /** * copy a node to a new parent * @name copy_node(obj, par [, pos, callback, is_loaded]) @@ -864,6 +1018,7 @@ interface JSTree extends JQuery { * @trigger model.jstree copy_node.jstree */ copy_node: (obj: any, par: any, pos?: any, callback?: any, internal?: boolean) => void; + /** * cut a node (a later call to `paste(obj)` would move the node) * @name cut(obj) @@ -871,6 +1026,7 @@ interface JSTree extends JQuery { * @trigger cut.jstree */ cut: (obj: any) => void; + /** * copy a node (a later call to `paste(obj)` would copy the node) * @name copy(obj) @@ -878,18 +1034,21 @@ interface JSTree extends JQuery { * @trigger copy.jstre */ copy: (obj: any) => void; + /** * get the current buffer (any nodes that are waiting for a paste operation) * @name get_buffer() * @return {Object} an object consisting of `mode` ("copy_node" or "move_node"), `node` (an array of objects) and `inst` (the instance) */ - get_buffer: () => any; + get_buffer: () => Buffer; + /** * check if there is something in the buffer to paste * @name can_paste() * @return {Boolean} */ can_paste: () => boolean; + /** * copy or move the previously cut or copied nodes to a new parent * @name paste(obj [, pos]) @@ -897,7 +1056,8 @@ interface JSTree extends JQuery { * @param {mixed} pos the position to insert at (besides integer, "first" and "last" are supported), defaults to integer `0` * @trigger paste.jstree */ - paste: (obj: any) => void; + paste: (obj: any, pos: any) => void; + /** * put a node in edit mode (input field to rename the node) * @name edit(obj [, default_text]) @@ -905,6 +1065,7 @@ interface JSTree extends JQuery { * @param {String} default_text the text to populate the input with (if omitted the node text value is used) */ edit: (obj: any, default_text?: string) => void; + /** * changes the theme * @name set_theme(theme_name [, theme_url]) @@ -914,69 +1075,82 @@ interface JSTree extends JQuery { * @trigger set_theme.jstree */ set_theme: (theme_name: string, theme_url?: any) => void; + /** * gets the name of the currently applied theme name * @name get_theme() * @return {String} */ get_theme: () => string; + /** * changes the theme variant (if the theme has variants) * @name set_theme_variant(variant_name) * @param {String|Boolean} variant_name the variant to apply (if `false` is used the current variant is removed) */ set_theme_variant: (variant_name: any) => void; + /** * gets the name of the currently applied theme variant * @name get_theme() * @return {String} */ get_theme_variant: () => string; + /** * shows a striped background on the container (if the theme supports it) * @name show_stripes() */ show_stripes: () => void; + /** * hides the striped background on the container * @name hide_stripes() */ hide_stripes: () => void; + /** * toggles the striped background on the container * @name toggle_stripes() */ toggle_stripes: () => void; + /** * shows the connecting dots (if the theme supports it) * @name show_dots() */ show_dots: () => void; + /** * hides the connecting dots * @name hide_dots() */ hide_dots: () => void; + /** * toggles the connecting dots * @name toggle_dots() */ toggle_dots: () => void; + /** * show the node icons * @name show_icons() */ show_icons: () => void; + /** * hide the node icons * @name hide_icons() */ hide_icons: () => void; + /** * toggle the node icons * @name toggle_icons() */ toggle_icons: () => void; + /** * set the node icon for a node * @name set_icon(obj, icon) @@ -985,6 +1159,7 @@ interface JSTree extends JQuery { * if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class */ set_icon: (obj: any, icon: string) => void; + /** * get the node icon for a node * @name get_icon(obj) @@ -992,22 +1167,24 @@ interface JSTree extends JQuery { * @return {String} */ get_icon: (obj: any) => string; + /** * hide the icon on an individual node * @name hide_icon(obj) * @param {mixed} obj */ hide_icon: (obj: any) => void; + /** * show the icon on an individual node * @name show_icon(obj) * @param {mixed} obj */ show_icon: (obj: any) => void; + /** */ - redraw_node: (obj: any, deep:boolean, is_callback:boolean) => any; - activate_node: (obj: any, e: any) => any; + redraw_node: (obj: any, deep: boolean, is_callback: boolean) => any; /** * show the node checkbox icons @@ -1015,22 +1192,105 @@ interface JSTree extends JQuery { * @plugin checkbox */ show_checkboxes: () => void; + /** * hide the node checkbox icons * @name hide_checkboxes() * @plugin checkbox */ hide_checkboxes: () => void; + /** * toggle the node icons * @name toggle_checkboxes() * @plugin checkbox */ toggle_checkboxes: () => void; + + /** + * checks if a node is in an undetermined state + * @name is_undetermined(obj) + * @param {mixed} obj + * @return {Boolean} + */ + is_undetermined: (obj: any) => boolean; + + activate_node: (obj: any, e: any) => any; + /** + * check a node (only if tie_selection in checkbox settings is false, otherwise select_node will be called internally) + * @name check_node(obj) + * @param {mixed} obj an array can be used to check multiple nodes + * @trigger check_node.jstree + * @plugin checkbox + */ + check_node: (obj: any, e: any) => any; + + /** + * uncheck a node (only if tie_selection in checkbox settings is false, otherwise deselect_node will be called internally) + * @name deselect_node(obj) + * @param {mixed} obj an array can be used to deselect multiple nodes + * @trigger uncheck_node.jstree + * @plugin checkbox + */ + uncheck_node: (obj: any, e: any) => any; + + /** + * checks all nodes in the tree (only if tie_selection in checkbox settings is false, otherwise select_all will be called internally) + * @name check_all() + * @trigger check_all.jstree, changed.jstree + * @plugin checkbox + */ + check_all: () => any; + + /** + * uncheck all checked nodes (only if tie_selection in checkbox settings is false, otherwise deselect_all will be called internally) + * @name uncheck_all() + * @trigger uncheck_all.jstree + * @plugin checkbox + */ + uncheck_all: () => any; + + /** + * checks if a node is checked (if tie_selection is on in the settings this function will return the same as is_selected) + * @name is_checked(obj) + * @param {mixed} obj + * @return {Boolean} + * @plugin checkbox + */ + is_checked: (obj: any) => boolean; + + /** + * get an array of all checked nodes (if tie_selection is on in the settings this function will return the same as get_selected) + * @name get_checked([full]) + * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned + * @return {Array} + * @plugin checkbox + */ + get_checked: (full: any) => any[]; + + /** + * get an array of all top level checked nodes (ignoring children of checked nodes) (if tie_selection is on in the settings this function will return the same as get_top_selected) + * @name get_top_checked([full]) + * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned + * @return {Array} + * @plugin checkbox + */ + get_top_checked: (full: any) => any[]; + + /** + * get an array of all bottom level checked nodes (ignoring selected parents) (if tie_selection is on in the settings this function will return the same as get_bottom_selected) + * @name get_bottom_checked([full]) + * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned + * @return {Array} + * @plugin checkbox + */ + get_bottom_checked: (full: any) => any[]; + /** * context menu plugin */ teardown: () => void; + /** * prepare and show the context menu for a node * @name show_contextmenu(obj [, x, y]) @@ -1041,7 +1301,8 @@ interface JSTree extends JQuery { * @plugin contextmenu * @trigger show_contextmenu.jstree */ - show_contextmenu: (obj: any, x?: number, y?: number, e?:any) => void; + show_contextmenu: (obj: any, x?: number, y?: number, e?: any) => void; + /** * used to search the tree nodes for a given string * @name search(str [, skip_async]) @@ -1051,6 +1312,7 @@ interface JSTree extends JQuery { * @trigger search.jstree */ search: (str: string, skip_async?: boolean) => void; + /** * used to clear the last search (removes classes and shows all nodes if filtering is on) * @name clear_search() @@ -1058,24 +1320,39 @@ interface JSTree extends JQuery { * @trigger clear_search.jstree */ clear_search: () => void; + + /** + * used to sort a node's children + * @private + * @name sort(obj [, deep]) + * @param {mixed} obj the node + * @param {Boolean} deep if set to `true` nodes are sorted recursively. + * @plugin sort + * @trigger search.jstree + */ + sort: (obj: any, deep?: boolean) => void; + /** * save the state * @name save_state() * @plugin state */ save_state: () => void; + /** * restore the state from the user's computer * @name restore_state() * @plugin state */ restore_state: () => void; + /** * clear the state on the user's computer * @name clear_state() * @plugin state */ clear_state: () => void; + /** * used to retrieve the type settings object for a node * @name get_rules(obj) @@ -1084,6 +1361,7 @@ interface JSTree extends JQuery { * @plugin types */ get_rules: (obj: any) => any; + /** * used to retrieve the type string or settings object for a node * @name get_type(obj [, rules]) @@ -1093,6 +1371,7 @@ interface JSTree extends JQuery { * @plugin types */ get_type: (obj: any, rules?: any) => any; + /** * used to change a node's type * @name set_type(obj, type) @@ -1101,7 +1380,6 @@ interface JSTree extends JQuery { * @plugin types */ set_type: (obj: any, type: string) => any; - //bind(eventType: string, handler?: (event: any, data: JSTreeBindOptions) => any): JSTree; } interface JSTreeGetJsonOptions { @@ -1109,14 +1387,26 @@ interface JSTreeGetJsonOptions { * do not return state information */ no_state: boolean; + /** * do not return ID */ no_id: boolean; + /** * do not include children */ no_children: boolean; + + /** + * do not include node data + */ + no_data: boolean; + + /** + * return flat JSON instead of nested + */ + flat: boolean; } interface JSTreeBindOptions { @@ -1125,3 +1415,9 @@ interface JSTreeBindOptions { rslt?: any; rlbk?: any; } + +interface Buffer { + mode: string; + node: any[]; + inst: any; +}