From a47d4d70357d426987f218c8bbcef6c946559d20 Mon Sep 17 00:00:00 2001 From: John Scaglione Date: Wed, 15 Feb 2017 13:07:59 -0800 Subject: [PATCH] Remove compiled lib from git --- .gitignore | 1 + lib/TreeMenu.js | 147 ------------------------- lib/TreeMenuUtils.js | 47 -------- lib/TreeNode.js | 253 ------------------------------------------- lib/TreeNodeMixin.js | 37 ------- lib/index.js | 7 -- 6 files changed, 1 insertion(+), 491 deletions(-) delete mode 100644 lib/TreeMenu.js delete mode 100644 lib/TreeMenuUtils.js delete mode 100644 lib/TreeNode.js delete mode 100644 lib/TreeNodeMixin.js delete mode 100644 lib/index.js diff --git a/.gitignore b/.gitignore index 87ed8e4..16b131a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules/ node_modules npm-debug.log +lib/ diff --git a/lib/TreeMenu.js b/lib/TreeMenu.js deleted file mode 100644 index e6d5f6f..0000000 --- a/lib/TreeMenu.js +++ /dev/null @@ -1,147 +0,0 @@ -var React = require('react'), - TreeNode = require('./TreeNode'), - TreeNodeFactory = React.createFactory(TreeNode), - TreeNodeMixin = require('./TreeNodeMixin'), - clone = require('lodash/clone'), - omit = require('lodash/omit'), - sortBy = require('lodash/sortBy'), - invariant = require('invariant'), - assign = require('object-assign'), - map = require('lodash/map'); - -/** - * The root component for a tree view. Can have one or many children - * - * @type {TreeMenu} - */ -var TreeMenu = React.createClass({ - displayName: 'TreeMenu', - - - mixins: [TreeNodeMixin], - - propTypes: { - - stateful: React.PropTypes.bool, - classNamePrefix: React.PropTypes.string, - identifier: React.PropTypes.string, - onTreeNodeClick: React.PropTypes.func, - onTreeNodeCheckChange: React.PropTypes.func, - onTreeNodeSelectChange: React.PropTypes.func, - collapsible: React.PropTypes.bool, - expandIconClass: React.PropTypes.string, - collapseIconClass: React.PropTypes.string, - data: React.PropTypes.oneOfType([React.PropTypes.array, React.PropTypes.object]), - labelFilter: React.PropTypes.func, - labelFactory: React.PropTypes.func, - checkboxFactory: React.PropTypes.func, - sort: React.PropTypes.oneOfType([React.PropTypes.bool, React.PropTypes.function]) - }, - - getDefaultProps: function () { - return { - classNamePrefix: "tree-view", - stateful: false - }; - }, - - render: function () { - - var props = this.props; - - return React.createElement( - 'div', - { className: props.classNamePrefix }, - this._getTreeNodes() - ); - }, - - /** - * Gets data from declarative TreeMenu nodes - * - * @param children - * @returns {*} - * @private - */ - _getDataFromChildren: function (children) { - - var iterableChildren = Array.isArray(children) ? children : [children]; - - var self = this; - return iterableChildren.map(function (child) { - - var data = clone(omit(child.props, "children")); - - if (child.props.children) { - data.children = self._getDataFromChildren(child.props.children); - } - - return data; - }); - }, - - /** - * Get TreeNode instances for render() - * - * @returns {*} - * @private - */ - _getTreeNodes: function () { - - var treeMenuProps = this.props, - treeData; - - invariant(!treeMenuProps.children || !treeMenuProps.data, "Either children or data props are expected in TreeMenu, but not both"); - - if (treeMenuProps.children) { - treeData = this._getDataFromChildren(treeMenuProps.children); - } else { - treeData = treeMenuProps.data; - } - - var thisComponent = this; - - function dataToNodes(data, ancestor) { - - var isRootNode = false; - if (!ancestor) { - isRootNode = true; - ancestor = []; - } - - var nodes = map(data, function (dataForNode, i) { - - var nodeProps = omit(dataForNode, ["children", "onClick", "onCheckChange"]), - children = []; - - nodeProps.label = nodeProps.label || i; - - if (dataForNode.children) { - children = dataToNodes(dataForNode.children, ancestor.concat(thisComponent.getNodeId(treeMenuProps, nodeProps, i))); - } - - nodeProps = assign(nodeProps, thisComponent.getTreeNodeProps(treeMenuProps, nodeProps, ancestor, isRootNode, i)); - - return TreeNodeFactory(nodeProps, children); - }); - - var sort = thisComponent.props.sort; - - if (sort) { - var sorter = typeof sort === "boolean" ? function (node) { - return node.props.label; - } : sort; - nodes = sortBy(nodes, sorter); - } - - return nodes; - } - - if (treeData) { - return dataToNodes(treeData); - } - } - -}); - -module.exports = TreeMenu; \ No newline at end of file diff --git a/lib/TreeMenuUtils.js b/lib/TreeMenuUtils.js deleted file mode 100644 index 44992d0..0000000 --- a/lib/TreeMenuUtils.js +++ /dev/null @@ -1,47 +0,0 @@ - -var TreeMenuUtils = { - - /** - * //TODO: use immutable API here..this function mutates! - * - * @param lineage - * @param prevState - * @param mutatedProperty - * @param identifier optional - * @returns {*} - */ - getNewTreeState: function (lineage, prevState, mutatedProperty, identifier) { - - function setPropState(node, value) { - node[mutatedProperty] = value; - var children = node.children; - if (children) { - node.children.forEach(function (childNode, ci) { - setPropState(childNode, value); - }); - } - } - - function getUpdatedTreeState(state) { - state = state || prevState; - var id = lineage.shift(); - state.forEach(function (node, i) { - var nodeId = identifier ? state[i][identifier] : i; - if (nodeId === id) { - if (!lineage.length) { - setPropState(state[i], !state[i][mutatedProperty]); - } else { - state[i].children = getUpdatedTreeState(state[i].children); - } - } - }); - - return state; - } - - return getUpdatedTreeState(); - } - -}; - -module.exports = TreeMenuUtils; \ No newline at end of file diff --git a/lib/TreeNode.js b/lib/TreeNode.js deleted file mode 100644 index 3db0698..0000000 --- a/lib/TreeNode.js +++ /dev/null @@ -1,253 +0,0 @@ -var React = require('react'), - TreeNodeMixin = require('./TreeNodeMixin'), - noop = require('lodash/noop'); - -/** - * Individual nodes in tree hierarchy, nested under a single node - * - * - * @type {TreeNode} - */ -var TreeNode = React.createClass({ - displayName: 'TreeNode', - - - mixins: [TreeNodeMixin], - - propTypes: { - - stateful: React.PropTypes.bool, - checkbox: React.PropTypes.bool, - collapsible: React.PropTypes.bool, - collapsed: React.PropTypes.bool, - expandIconClass: React.PropTypes.string, - collapseIconClass: React.PropTypes.string, - checked: React.PropTypes.bool, - label: React.PropTypes.string.isRequired, - classNamePrefix: React.PropTypes.string, - onClick: React.PropTypes.func, - onCheckChange: React.PropTypes.func, - onSelectChange: React.PropTypes.func, - onCollapseChange: React.PropTypes.func, - labelFilter: React.PropTypes.func, - labelFactory: React.PropTypes.func, - checkboxFactory: React.PropTypes.func - - }, - - getInitialState: function () { - return {}; - }, - - getDefaultProps: function () { - return { - stateful: false, - collapsible: true, - collapsed: false, - checkbox: false, - onClick: function (lineage) { - console.log("Tree Node clicked: " + lineage.join(" > ")); - }, - onCheckChange: function (lineage) { - console.log("Tree Node indicating a checkbox check state should change: " + lineage.join(" > ")); - }, - onCollapseChange: function (lineage) { - console.log("Tree Node indicating collapse state should change: " + lineage.join(" > ")); - }, - checked: false, - expandIconClass: "", - collapseIconClass: "", - labelFactory: function (labelClassName, displayLabel) { - return React.createElement( - 'label', - { className: labelClassName }, - displayLabel - ); - }, - checkboxFactory: function (className, isChecked) { - return React.createElement('input', { - className: className, - type: 'checkbox', - checked: isChecked, - onChange: noop }); - } - }; - }, - - _getCollapseNode: function () { - var props = this.props, - collapseNode = null; - - if (props.collapsible) { - var collapseClassName = this._getRootCssClass() + "-collapse-toggle "; - var collapseToggleHandler = this._handleCollapseChange; - if (!props.children || props.children.length === 0) { - collapseToggleHandler = noop; - collapseClassName += "collapse-spacer"; - } else { - collapseClassName += this._isCollapsed() ? props.expandIconClass : props.collapseIconClass; - } - collapseNode = React.createElement('span', { onClick: collapseToggleHandler, className: collapseClassName }); - } - return collapseNode; - }, - - render: function () { - return React.createElement( - 'div', - { className: this._getRootCssClass() }, - this._getCollapseNode(), - React.createElement( - 'span', - { onClick: this._handleClick }, - this._getCheckboxNode(), - this._getLabelNode() - ), - this._getChildrenNode() - ); - }, - - componentWillReceiveProps: function (nextProps) { - - if (!this._isStateful()) return; - - var mutations = {}; - - if (this.props.checked !== nextProps.checked) { - mutations.checked = nextProps.checked; - } - - this.setState(mutations); - }, - - _getRootCssClass: function () { - return this.props.classNamePrefix + "-node"; - }, - - _getChildrenNode: function () { - - var props = this.props; - - if (this._isCollapsed()) return null; - - var children = props.children; - - if (this._isStateful()) { - var state = this.state; - children = React.Children.map(props.children, function (child) { - return React.cloneElement(child, { - key: child.key, - ref: child.ref, - checked: state.checked - }); - }); - } - - return React.createElement( - 'div', - { className: this._getRootCssClass() + "-children" }, - children - ); - }, - - _getLabelNode: function () { - - var props = this.props, - labelClassName = props.classNamePrefix + "-node-label"; - - if (this._isSelected()) { - labelClassName += " selected"; - } - - var displayLabel = props.label; - - if (props.labelFilter) displayLabel = props.labelFilter(displayLabel); - - return this.props.labelFactory(labelClassName, displayLabel, this._getLineage()); - }, - - _getCheckboxNode: function () { - var props = this.props; - if (!props.checkbox) return null; - - return this.props.checkboxFactory(props.classNamePrefix + "-node-checkbox", this._isChecked(), this._getLineage()); - }, - - _isStateful: function () { - - return this.props.stateful ? true : false; - }, - - _isChecked: function () { - - if (this._isStateful() && typeof this.state.checked !== "undefined") return this.state.checked; - return this.props.checked; - }, - - _isSelected: function () { - - if (this._isStateful() && typeof this.state.selected !== "undefined") return this.state.selected; - return this.props.selected; - }, - - _isCollapsed: function () { - - if (this._isStateful() && typeof this.state.collapsed !== "undefined") return this.state.collapsed; - - if (!this.props.collapsible) return false; - - return this.props.collapsed; - }, - - _handleClick: function () { - if (this.props.checkbox) { - return this._handleCheckChange(); - } else if (this.props.onSelectChange) { - return this._handleSelectChange(); - } - - this.props.onClick(this._getLineage()); - }, - - _toggleNodeStateIfStateful: function (field) { - if (this._isStateful()) { - var newValue = !this.props[field]; - if (typeof this.state[field] !== "undefined") { - newValue = !this.state[field]; - } - var mutation = {}; - mutation[field] = newValue; - console.log(mutation); - this.setState(mutation); - } - }, - - _handleCheckChange: function () { - - this._toggleNodeStateIfStateful("checked"); - - this.props.onCheckChange(this._getLineage()); - }, - - _handleSelectChange: function () { - - this._toggleNodeStateIfStateful("selected"); - - this.props.onSelectChange(this._getLineage()); - }, - - _handleCollapseChange: function () { - - this._toggleNodeStateIfStateful("collapsed"); - - this.props.onCollapseChange(this._getLineage()); - }, - - _getLineage: function () { - - return this.props.ancestor.concat(this.props.id); - } - -}); - -module.exports = TreeNode; \ No newline at end of file diff --git a/lib/TreeNodeMixin.js b/lib/TreeNodeMixin.js deleted file mode 100644 index 4000a00..0000000 --- a/lib/TreeNodeMixin.js +++ /dev/null @@ -1,37 +0,0 @@ -var pick = require('lodash/pick'), - extend = require('lodash/assign'); - -var TreeNodeMixin = { - - /** - * Build the properties necessary for the TreeNode instance - * - * @param rootProps - * @param props - * @param ancestor - * @param isRootNode - * @param childIndex - * @returns {{classNamePrefix: (*|TreeMenu.propTypes.classNamePrefix|TreeMenu.getDefaultProps.classNamePrefix|TreeNodeMixin._getTreeNodeProps.classNamePrefix), collapseIconClass: (*|TreeMenu.propTypes.collapseIconClass|App._getStaticTreeExample.collapseIconClass|App._getDynamicTreeExample.collapseIconClass|TreeNodeMixin._getTreeNodeProps.collapseIconClass), expandIconClass: (*|TreeMenu.propTypes.expandIconClass|App._getStaticTreeExample.expandIconClass|App._getDynamicTreeExample.expandIconClass|TreeNodeMixin._getTreeNodeProps.expandIconClass), collapsible: (*|TreeMenu.propTypes.collapsible|TreeMenu.getDefaultProps.collapsible|App._getStaticTreeExample.collapsible|TreeNodeMixin._getTreeNodeProps.collapsible), ancestor: *, onClick: (TreeMenu.propTypes.onTreeNodeClick|*|App._getStaticTreeExample.onTreeNodeClick|App._getDynamicTreeExample.onTreeNodeClick), onCheckChange: (TreeMenu.propTypes.onTreeNodeCheckChange|*|App._getStaticTreeExample.onTreeNodeCheckChange|App._getDynamicTreeExample.onTreeNodeCheckChange), onCollapseChange: (App._getDynamicTreeExample.onTreeNodeCollapseChange|*), id: *, key: string}} - * @private - */ - getTreeNodeProps: function (rootProps, props, ancestor, isRootNode, childIndex) { - - //TODO: use omit/pick to clean this up - - return extend({ - ancestor: ancestor, - onClick: rootProps.onTreeNodeClick, - onCheckChange: rootProps.onTreeNodeCheckChange, - onSelectChange: rootProps.onTreeNodeSelectChange, - onCollapseChange: rootProps.onTreeNodeCollapseChange, - id: this.getNodeId(rootProps, props, childIndex), - key: "tree-node-" + ancestor.join(".") + childIndex - }, pick(rootProps, "classNamePrefix", "collapseIconClass", "expandIconClass", "collapsible", "stateful", "labelFilter", "checkboxFactory", "labelFactory")); - }, - - getNodeId: function (rootProps, props, childIndex) { - return rootProps.identifier && props[rootProps.identifier] ? props[rootProps.identifier] : childIndex; - } -}; - -module.exports = TreeNodeMixin; \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index e6c1b90..0000000 --- a/lib/index.js +++ /dev/null @@ -1,7 +0,0 @@ -var api = require('./TreeMenu'); - -api.TreeMenu = require('./TreeMenu'); -api.TreeNode = require('./TreeNode'); -api.Utils = require('./TreeMenuUtils'); - -module.exports = api; \ No newline at end of file