Skip to content

Commit

Permalink
v1.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Jul 31, 2017
1 parent 26d90bc commit 74489f1
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 115 deletions.
233 changes: 122 additions & 111 deletions dist/infinite-tree.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! infinite-tree v1.12.1 | (c) 2017 Cheton Wu <[email protected]> | MIT | https://github.com/cheton/infinite-tree */
/*! infinite-tree v1.12.2 | (c) 2017 Cheton Wu <[email protected]> | MIT | https://github.com/cheton/infinite-tree */
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
Expand Down Expand Up @@ -448,14 +448,25 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
/* eslint prefer-spread: 0 */


var error = function error() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
var error = function error(format) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}

var argIndex = 0;
var message = 'Error: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});

if (console && console.error) {
var prefix = '[InfiniteTree]';
console.error.apply(console, [prefix].concat(args));
console.error(message);
}
try {
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this error to fire.
throw new Error(message);
} catch (e) {
// Ignore
}
};

Expand Down Expand Up @@ -745,7 +756,7 @@ var InfiniteTree = function (_events$EventEmitter) {
_this.options = _extends({}, _this.options, options);

if (!_this.options.el) {
console.error('Failed to initialize infinite-tree: el is not specified.', options);
error('Failed to initialize infinite-tree: el is not specified.', options);
return _possibleConstructorReturn(_this);
}

Expand Down Expand Up @@ -1057,6 +1068,110 @@ var InfiniteTree = function (_events$EventEmitter) {

return true;
};
// Filters nodes. Use a string or a function to test each node of the tree. Otherwise, it will render nothing after filtering (e.g. tree.filter(), tree.filter(null), tree.flter(0), tree.filter({}), etc.).
// @param {string|function} predicate A keyword string, or a function to test each node of the tree. If the predicate is an empty string, all nodes will be filtered. If the predicate is a function, returns true to keep the node, false otherwise.
// @param {object} [options] The options object.
// @param {boolean} [options.caseSensitive] Case sensitive string comparison. Defaults to false. This option is only available for string comparison.
// @param {boolean} [options.exactMatch] Exact string matching. Defaults to false. This option is only available for string comparison.
// @param {string} [options.filterPath] Gets the value at path of Node object. Defaults to 'name'. This option is only available for string comparison.
// @param {boolean} [options.includeAncestors] Whether to include ancestor nodes. Defaults to true.
// @param {boolean} [options.includeDescendants] Whether to include descendant nodes. Defaults to true.
// @example
//
// const filterOptions = {
// caseSensitive: false,
// exactMatch: false,
// filterPath: 'props.some.other.key',
// includeAncestors: true,
// includeDescendants: true
// };
// tree.filter('keyword', filterOptions);
//
// @example
//
// const filterOptions = {
// includeAncestors: true,
// includeDescendants: true
// };
// tree.filter(function(node) {
// const keyword = 'keyword';
// const filterText = node.name || '';
// return filterText.toLowerCase().indexOf(keyword) >= 0;
// }, filterOptions);


InfiniteTree.prototype.filter = function filter(predicate, options) {
options = _extends({
caseSensitive: false,
exactMatch: false,
filterPath: 'name',
includeAncestors: true,
includeDescendants: true
}, options);

this.filtered = true;

var rootNode = this.state.rootNode;
var traverse = function traverse(node) {
var filterNode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

if (!node || !node.children) {
return false;
}

if (node === rootNode) {
node.state.filtered = false;
} else if (filterNode) {
node.state.filtered = true;
} else if (typeof predicate === 'string') {
// string
var filterText = (0, _utilities.get)(node, options.filterPath, '');
var keyword = predicate;
if (!options.caseSensitive) {
filterText = filterText.toLowerCase();
keyword = keyword.toLowerCase();
}
node.state.filtered = options.exactMatch ? filterText === keyword : filterText.indexOf(keyword) >= 0;
} else if (typeof predicate === 'function') {
// function
var callback = predicate;
node.state.filtered = !!callback(node);
} else {
node.state.filtered = false;
}

if (options.includeDescendants) {
filterNode = filterNode || node.state.filtered;
}

var filtered = false;
for (var i = 0; i < node.children.length; ++i) {
var childNode = node.children[i];
if (!childNode) {
continue;
}
if (traverse(childNode, filterNode)) {
filtered = true;
}
}
if (options.includeAncestors && filtered) {
node.state.filtered = true;
}

return node.state.filtered;
};

traverse(rootNode);

// Update rows
this.rows.length = this.nodes.length;
for (var i = 0; i < this.nodes.length; ++i) {
var node = this.nodes[i];
this.rows[i] = this.options.rowRenderer(node, this.options);
}

this.update();
};
// Flattens all child nodes of a parent node by performing full tree traversal using child-parent link.
// No recursion or stack is involved.
// @param {Node} parentNode The Node object that defines the parent node.
Expand Down Expand Up @@ -1873,110 +1988,6 @@ var InfiniteTree = function (_events$EventEmitter) {

return traverse(node);
};
// Filters nodes. Use a string or a function to test each node of the tree. Otherwise, it will render nothing after filtering (e.g. tree.filter(), tree.filter(null), tree.flter(0), tree.filter({}), etc.).
// @param {string|function} predicate A keyword string, or a function to test each node of the tree. If the predicate is an empty string, all nodes will be filtered. If the predicate is a function, returns true to keep the node, false otherwise.
// @param {object} [options] The options object.
// @param {boolean} [options.caseSensitive] Case sensitive string comparison. Defaults to false. This option is only available for string comparison.
// @param {boolean} [options.exactMatch] Exact string matching. Defaults to false. This option is only available for string comparison.
// @param {string} [options.filterPath] Gets the value at path of Node object. Defaults to 'name'. This option is only available for string comparison.
// @param {boolean} [options.includeAncestors] Whether to include ancestor nodes. Defaults to true.
// @param {boolean} [options.includeDescendants] Whether to include descendant nodes. Defaults to true.
// @example
//
// const filterOptions = {
// caseSensitive: false,
// exactMatch: false,
// filterPath: 'props.some.other.key',
// includeAncestors: true,
// includeDescendants: true
// };
// tree.filter('keyword', filterOptions);
//
// @example
//
// const filterOptions = {
// includeAncestors: true,
// includeDescendants: true
// };
// tree.filter(function(node) {
// const keyword = 'keyword';
// const filterText = node.name || '';
// return filterText.toLowerCase().indexOf(keyword) >= 0;
// }, filterOptions);


InfiniteTree.prototype.filter = function filter(predicate, options) {
options = _extends({
caseSensitive: false,
exactMatch: false,
filterPath: 'name',
includeAncestors: true,
includeDescendants: true
}, options);

this.filtered = true;

var rootNode = this.state.rootNode;
var traverse = function traverse(node) {
var filterNode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

if (!node || !node.children) {
return false;
}

if (node === rootNode) {
node.state.filtered = false;
} else if (filterNode) {
node.state.filtered = true;
} else if (typeof predicate === 'string') {
// string
var filterText = (0, _utilities.get)(node, options.filterPath, '');
var keyword = predicate;
if (!options.caseSensitive) {
filterText = filterText.toLowerCase();
keyword = keyword.toLowerCase();
}
node.state.filtered = options.exactMatch ? filterText === keyword : filterText.indexOf(keyword) >= 0;
} else if (typeof predicate === 'function') {
// function
var callback = predicate;
node.state.filtered = !!callback(node);
} else {
node.state.filtered = false;
}

if (options.includeDescendants) {
filterNode = filterNode || node.state.filtered;
}

var filtered = false;
for (var i = 0; i < node.children.length; ++i) {
var childNode = node.children[i];
if (!childNode) {
continue;
}
if (traverse(childNode, filterNode)) {
filtered = true;
}
}
if (options.includeAncestors && filtered) {
node.state.filtered = true;
}

return node.state.filtered;
};

traverse(rootNode);

// Update rows
this.rows.length = this.nodes.length;
for (var i = 0; i < this.nodes.length; ++i) {
var node = this.nodes[i];
this.rows[i] = this.options.rowRenderer(node, this.options);
}

this.update();
};
// Unfilters nodes.


Expand Down
4 changes: 2 additions & 2 deletions dist/infinite-tree.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/examples.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "infinite-tree",
"version": "1.12.1",
"version": "1.12.2",
"description": "A browser-ready tree library that can efficiently display a large amount of data using infinite scrolling.",
"homepage": "https://github.com/cheton/infinite-tree",
"main": "lib/index.js",
Expand Down

0 comments on commit 74489f1

Please sign in to comment.