Skip to content

Commit e3e53ad

Browse files
committed
Prepare for v1
1 parent ca019ed commit e3e53ad

File tree

3 files changed

+152
-37
lines changed

3 files changed

+152
-37
lines changed

dist/react-infinite-tree.js

Lines changed: 139 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -552,14 +552,6 @@ var _class = function (_Component) {
552552
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = _class.__proto__ || Object.getPrototypeOf(_class)).call.apply(_ref, [this].concat(args))), _this), _this.tree = null, _this.state = {
553553
nodes: []
554554
}, _this.eventHandlers = {
555-
/*
556-
onClick: null,
557-
onDoubleClick: null,
558-
onKeyDown: null,
559-
onKeyUp: null,
560-
*/
561-
onClusterWillChange: null,
562-
onClusterDidChange: null,
563555
onContentWillUpdate: null,
564556
onContentDidUpdate: null,
565557
onOpenNode: null,
@@ -592,6 +584,41 @@ var _class = function (_Component) {
592584

593585
this.tree = new _infiniteTree2.default(options);
594586

587+
// Sets the current scroll position to this node.
588+
// @param {Node} node The Node object.
589+
// @return {boolean} Returns true on success, false otherwise.
590+
this.tree.scrollToNode = function (node) {
591+
if (!_this2.tree || !_this2.virtualList) {
592+
return false;
593+
}
594+
595+
var nodeIndex = _this2.tree.nodes.indexOf(node);
596+
if (nodeIndex < 0) {
597+
return false;
598+
}
599+
600+
var offset = _this2.virtualList.getOffsetForIndex(nodeIndex);
601+
_this2.virtualList.scrollTo(offset);
602+
603+
return true;
604+
};
605+
606+
// Gets (or sets) the current vertical position of the scroll bar.
607+
// @param {number} [value] If the value is specified, indicates the new position to set the scroll bar to.
608+
// @return {number} Returns the vertical scroll position.
609+
this.tree.scrollTop = function (value) {
610+
if (!_this2.tree || !_this2.virtualList) {
611+
return;
612+
}
613+
614+
if (value !== undefined) {
615+
_this2.virtualList.scrollTo(Number(value));
616+
}
617+
618+
return _this2.virtualList.getNodeOffset();
619+
};
620+
621+
// Updates the tree.
595622
this.tree.update = function () {
596623
_this2.tree.emit('contentWillUpdate');
597624
_this2.setState(function (state) {
@@ -637,30 +664,55 @@ var _class = function (_Component) {
637664
var _this4 = this;
638665

639666
var _props2 = this.props,
667+
autoOpen = _props2.autoOpen,
668+
selectable = _props2.selectable,
669+
tabIndex = _props2.tabIndex,
670+
data = _props2.data,
640671
width = _props2.width,
641672
height = _props2.height,
642673
rowHeight = _props2.rowHeight,
643-
onKeyUp = _props2.onKeyUp,
644-
onKeyDown = _props2.onKeyDown,
645-
tabIndex = _props2.tabIndex,
646-
className = _props2.className,
647-
style = _props2.style;
674+
rowRenderer = _props2.rowRenderer,
675+
loadNodes = _props2.loadNodes,
676+
shouldSelectNode = _props2.shouldSelectNode,
677+
scrollOffset = _props2.scrollOffset,
678+
scrollToIndex = _props2.scrollToIndex,
679+
onScroll = _props2.onScroll,
680+
onContentWillUpdate = _props2.onContentWillUpdate,
681+
onContentDidUpdate = _props2.onContentDidUpdate,
682+
onOpenNode = _props2.onOpenNode,
683+
onCloseNode = _props2.onCloseNode,
684+
onSelectNode = _props2.onSelectNode,
685+
onWillOpenNode = _props2.onWillOpenNode,
686+
onWillCloseNode = _props2.onWillCloseNode,
687+
onWillSelectNode = _props2.onWillSelectNode,
688+
style = _props2.style,
689+
props = _objectWithoutProperties(_props2, ['autoOpen', 'selectable', 'tabIndex', 'data', 'width', 'height', 'rowHeight', 'rowRenderer', 'loadNodes', 'shouldSelectNode', 'scrollOffset', 'scrollToIndex', 'onScroll', 'onContentWillUpdate', 'onContentDidUpdate', 'onOpenNode', 'onCloseNode', 'onSelectNode', 'onWillOpenNode', 'onWillCloseNode', 'onWillSelectNode', 'style']);
690+
691+
var render = typeof children === 'function' ? children : rowRenderer;
648692

649-
var render = typeof this.props.children === 'function' ? this.props.children : this.props.rowRenderer;
650693
var count = this.tree ? this.tree.nodes.length : 0;
651694

695+
// VirtualList
696+
var virtualListProps = {};
697+
if (scrollOffset !== undefined && count > 0) {
698+
virtualListProps.scrollOffset = scrollOffset;
699+
}
700+
if (scrollToIndex !== undefined && scrollToIndex >= 0 && scrollToIndex < count) {
701+
virtualListProps.scrollToIndex = scrollToIndex;
702+
}
703+
if (typeof onScroll !== 'function') {
704+
virtualListProps.onScroll = onScroll;
705+
}
706+
652707
return _react2.default.createElement(
653708
'div',
654-
{
655-
className: className,
709+
_extends({}, props, {
656710
style: _extends({
657711
outline: 'none'
658712
}, style),
659-
onKeyDown: onKeyDown,
660-
onKeyUp: onKeyUp,
661713
tabIndex: tabIndex
662-
},
663-
_react2.default.createElement(_reactTinyVirtualList2.default, {
714+
}),
715+
_react2.default.createElement(_reactTinyVirtualList2.default, _extends({
664716
ref: function ref(node) {
665717
_this4.virtualList = node;
666718
},
@@ -686,22 +738,85 @@ var _class = function (_Component) {
686738
row
687739
);
688740
}
689-
})
741+
}, virtualListProps))
690742
);
691743
}
692744
}]);
693745

694746
return _class;
695747
}(_react.Component);
696748

749+
_class.displayName = 'InfiniteTree';
697750
_class.propTypes = {
751+
// Whether to open all nodes when tree is loaded.
752+
autoOpen: _propTypes2.default.bool,
753+
754+
// Whether or not a node is selectable in the tree.
755+
selectable: _propTypes2.default.bool,
756+
757+
// Specifies the tab order to make tree focusable.
758+
tabIndex: _propTypes2.default.number,
759+
760+
// Tree data structure, or a collection of tree data structures.
761+
data: _propTypes2.default.oneOfType([_propTypes2.default.array, _propTypes2.default.object]),
762+
763+
// Width of the tree.
698764
width: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]).isRequired,
765+
766+
// Height of the tree.
699767
height: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]).isRequired,
700-
rowHeight: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.func]).isRequired,
701-
rowRenderer: _propTypes2.default.func.isRequired
768+
769+
// Either a fixed height, an array containing the heights of all the rows, or a function that returns the height of a row given its index: `(index: number): number`
770+
rowHeight: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.array, _propTypes2.default.func]).isRequired,
771+
772+
// A row renderer for rendering a tree node.
773+
rowRenderer: _propTypes2.default.func,
774+
775+
// Loads nodes on demand.
776+
loadNodes: _propTypes2.default.func,
777+
778+
// Provides a function to determine if a node can be selected or deselected. The function must return `true` or `false`. This function will not take effect if `selectable` is not `true`.
779+
shouldSelectNode: _propTypes2.default.func,
780+
781+
// Controls the scroll offset.
782+
scrollOffset: _propTypes2.default.number,
783+
784+
// Node index to scroll to.
785+
scrollToIndex: _propTypes2.default.number,
786+
787+
// Callback invoked whenever the scroll offset changes.
788+
onScroll: _propTypes2.default.func,
789+
790+
// Callback invoked before updating the tree.
791+
onContentWillUpdate: _propTypes2.default.func,
792+
793+
// Callback invoked when the tree is updated.
794+
onContentDidUpdate: _propTypes2.default.func,
795+
796+
// Callback invoked when a node is opened.
797+
onOpenNode: _propTypes2.default.func,
798+
799+
// Callback invoked when a node is closed.
800+
onCloseNode: _propTypes2.default.func,
801+
802+
// Callback invoked when a node is selected or deselected.
803+
onSelectNode: _propTypes2.default.func,
804+
805+
// Callback invoked before opening a node.
806+
onWillOpenNode: _propTypes2.default.func,
807+
808+
// Callback invoked before closing a node.
809+
onWillCloseNode: _propTypes2.default.func,
810+
811+
// Callback invoked before selecting or deselecting a node.
812+
onWillSelectNode: _propTypes2.default.func
702813
};
703814
_class.defaultProps = {
704-
tabIndex: 0
815+
autoOpen: false,
816+
selectable: true,
817+
tabIndex: 0,
818+
data: [],
819+
width: '100%'
705820
};
706821
exports.default = _class;
707822
;

0 commit comments

Comments
 (0)