Skip to content

Feature/drag threshold #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ node_modules

example/bundle*
.publish

dist
7 changes: 0 additions & 7 deletions Makefile

This file was deleted.

138 changes: 138 additions & 0 deletions dist/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var UITreeNode = function (_Component) {
_inherits(UITreeNode, _Component);

function UITreeNode(props) {
_classCallCheck(this, UITreeNode);

var _this = _possibleConstructorReturn(this, (UITreeNode.__proto__ || Object.getPrototypeOf(UITreeNode)).call(this, props));

_this.renderCollapse = function () {
var index = _this.props.index;


if (index.children && index.children.length) {
var collapsed = index.node.collapsed;


return _react2.default.createElement('span', {
className: (0, _classnames2.default)('collapse', collapsed ? 'caret-right' : 'caret-down'),
onMouseDown: function onMouseDown(e) {
return e.stopPropagation();
},
onClick: _this.handleCollapse
});
}

return null;
};

_this.renderChildren = function () {
var _this$props = _this.props,
index = _this$props.index,
tree = _this$props.tree,
dragging = _this$props.dragging;


if (index.children && index.children.length) {
var childrenStyles = {
paddingLeft: _this.props.paddingLeft
};

return _react2.default.createElement(
'div',
{ className: 'children', style: childrenStyles },
index.children.map(function (child) {
var childIndex = tree.getIndex(child);

return _react2.default.createElement(UITreeNode, {
tree: tree,
index: childIndex,
key: childIndex.id,
dragging: dragging,
paddingLeft: _this.props.paddingLeft,
onCollapse: _this.props.onCollapse,
onDragStart: _this.props.onDragStart
});
})
);
}

return null;
};

_this.handleCollapse = function (e) {
e.stopPropagation();
var nodeId = _this.props.index.id;

if (_this.props.onCollapse) {
_this.props.onCollapse(nodeId);
}
};

_this.handleMouseDown = function (e) {
var nodeId = _this.props.index.id;
var dom = _this.innerRef.current;

if (_this.props.onDragStart) {
_this.props.onDragStart(nodeId, dom, e);
}
};

_this.innerRef = _react2.default.createRef();
return _this;
}

_createClass(UITreeNode, [{
key: 'render',
value: function render() {
var _props = this.props,
tree = _props.tree,
index = _props.index,
dragging = _props.dragging;
var node = index.node;

var styles = {};

return _react2.default.createElement(
'div',
{
className: (0, _classnames2.default)('m-node', {
placeholder: index.id === dragging
}),
style: styles
},
_react2.default.createElement(
'div',
{ className: 'inner', ref: this.innerRef, onMouseDown: this.handleMouseDown },
this.renderCollapse(),
tree.renderNode(node)
),
node.collapsed ? null : this.renderChildren()
);
}
}]);

return UITreeNode;
}(_react.Component);

module.exports = UITreeNode;
49 changes: 49 additions & 0 deletions dist/react-ui-tree.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.f-no-select {
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.m-tree {
position: relative;
overflow-x: hidden;
overflow-y: auto;
height: 100%;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.m-draggable {
position: absolute;
opacity: 0.8;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.m-node.placeholder > * {
visibility: hidden;
}
.m-node.placeholder {
outline: 1px dashed #ccc;
}
.m-node .inner {
position: relative;
cursor: pointer;
padding-left: 10px;
}
.m-node .collapse {
position: absolute;
left: 0;
cursor: pointer;
}
.m-node .caret-right:before {
content: '\25B8';
}
.m-node .caret-down:before {
content: '\25BE';
}
Loading