UNPKG

wix-style-react

Version:
116 lines (98 loc) 4.7 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import React, { Component } from 'react'; import classNames from 'classnames'; import Item from './Item'; import { getDepth } from './utils'; var Container = /*#__PURE__*/function (_Component) { _inherits(Container, _Component); var _super = _createSuper(Container); function Container() { _classCallCheck(this, Container); return _super.apply(this, arguments); } _createClass(Container, [{ key: "render", value: function render() { var _this$props = this.props, items = _this$props.items, parentPosition = _this$props.parentPosition, childrenProperty = _this$props.childrenProperty, childrenStyle = _this$props.childrenStyle, renderAction = _this$props.renderAction, treeDepth = _this$props.treeDepth, _this$props$isParentL = _this$props.isParentLastItem, isParentLastItem = _this$props$isParentL === void 0 ? true : _this$props$isParentL, isRenderDraggingChildren = _this$props.isRenderDraggingChildren, topLevel = _this$props.topLevel, theme = _this$props.theme; var containerClass; if (theme) { containerClass = topLevel && theme.topContainer || theme.container; } var classes = classNames('nestable-container', { 'nestable-top-container': topLevel }, containerClass); return /*#__PURE__*/React.createElement("div", { className: classes, style: topLevel ? {} : childrenStyle }, items.map(function (item, i) { var position = parentPosition.concat([i]); var children = item[childrenProperty]; var hasChildren = children && children.length; var isLastItem = items.length - 1 === i; var actionButton = renderAction({ siblings: items, item: item, veryLastItem: isLastItem && isParentLastItem, depth: treeDepth }); var veryLastItem = isLastItem && isParentLastItem && (!hasChildren || item.isCollapsed) && !actionButton; return /*#__PURE__*/React.createElement(Item, { id: item.id, key: item.id, item: item, index: i, isVeryLastItem: veryLastItem, siblings: items, isRenderDraggingChildren: isRenderDraggingChildren, position: position, depth: getDepth(item, childrenProperty), theme: theme }, !item.isCollapsed && /*#__PURE__*/React.createElement("div", null, hasChildren ? /*#__PURE__*/React.createElement(WrappedContainer, { isParentLastItem: isLastItem && isParentLastItem && !actionButton, items: children, renderAction: renderAction, isRenderDraggingChildren: isRenderDraggingChildren, parentPosition: position, childrenProperty: childrenProperty, childrenStyle: childrenStyle, theme: theme, treeDepth: treeDepth + 1 }) : null, actionButton)); })); } }]); return Container; }(Component); var WrappedContainer = /*#__PURE__*/function (_React$PureComponent) { _inherits(WrappedContainer, _React$PureComponent); var _super2 = _createSuper(WrappedContainer); function WrappedContainer() { _classCallCheck(this, WrappedContainer); return _super2.apply(this, arguments); } _createClass(WrappedContainer, [{ key: "render", value: function render() { return /*#__PURE__*/React.createElement(Container, this.props); } }]); return WrappedContainer; }(React.PureComponent); export default WrappedContainer;