UNPKG

@react-awesome-query-builder-dev/ui

Version:
187 lines 8.05 kB
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/inherits"; import _extends from "@babel/runtime/helpers/extends"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; var _excluded = ["type"]; function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import React, { PureComponent } from "react"; import PropTypes from "prop-types"; import Rule from "./Rule"; import Group from "./Group"; import RuleGroup from "./RuleGroup"; import RuleGroupExt from "./RuleGroupExt"; import SwitchGroup from "./SwitchGroup"; import CaseGroup from "./CaseGroup"; var types = ["rule", "group", "rule_group", "switch_group", "case_group"]; var getProperties = function getProperties(props) { var _props$properties; var properties = ((_props$properties = props.properties) === null || _props$properties === void 0 ? void 0 : _props$properties.toObject()) || {}; var result = _objectSpread({}, properties); if (props.isParentLocked) { result.isLocked = true; } if (properties.isLocked) { result.isTrueLocked = true; } return result; }; var typeMap = { rule: function rule(props) { return /*#__PURE__*/React.createElement(Rule, _extends({}, getProperties(props), { id: props.id, groupId: props.groupId, path: props.path, actions: props.actions, reordableNodesCnt: props.reordableNodesCnt, totalRulesCnt: props.totalRulesCnt, config: props.config, onDragStart: props.onDragStart, isDraggingTempo: props.isDraggingTempo, parentField: props.parentField, parentFieldPathSize: props.parentFieldPathSize, parentReordableNodesCnt: props.parentReordableNodesCnt, parentFieldCanReorder: props.parentFieldCanReorder })); }, group: function group(props) { return /*#__PURE__*/React.createElement(Group, _extends({}, getProperties(props), { id: props.id, groupId: props.groupId, path: props.path, actions: props.actions, config: props.config, reordableNodesCnt: props.reordableNodesCnt, totalRulesCnt: props.totalRulesCnt, onDragStart: props.onDragStart, isDraggingTempo: props.isDraggingTempo, children1: props.children1, parentField: props.parentField, parentFieldPathSize: props.parentFieldPathSize, parentReordableNodesCnt: props.parentReordableNodesCnt, parentFieldCanReorder: props.parentFieldCanReorder })); }, rule_group: function rule_group(props) { return /*#__PURE__*/React.createElement(RuleGroup, _extends({}, getProperties(props), { id: props.id, groupId: props.groupId, path: props.path, actions: props.actions, config: props.config, reordableNodesCnt: props.reordableNodesCnt, totalRulesCnt: props.totalRulesCnt, onDragStart: props.onDragStart, isDraggingTempo: props.isDraggingTempo, children1: props.children1, parentField: props.parentField, parentFieldPathSize: props.parentFieldPathSize, parentReordableNodesCnt: props.parentReordableNodesCnt, parentFieldCanReorder: props.parentFieldCanReorder })); }, rule_group_ext: function rule_group_ext(props) { return /*#__PURE__*/React.createElement(RuleGroupExt, _extends({}, getProperties(props), { id: props.id, groupId: props.groupId, path: props.path, actions: props.actions, config: props.config, reordableNodesCnt: props.reordableNodesCnt, totalRulesCnt: props.totalRulesCnt, onDragStart: props.onDragStart, isDraggingTempo: props.isDraggingTempo, children1: props.children1, parentField: props.parentField, parentFieldPathSize: props.parentFieldPathSize, parentReordableNodesCnt: props.parentReordableNodesCnt, parentFieldCanReorder: props.parentFieldCanReorder })); }, switch_group: function switch_group(props) { return /*#__PURE__*/React.createElement(SwitchGroup, _extends({}, getProperties(props), { id: props.id, groupId: props.groupId, path: props.path, actions: props.actions, config: props.config, reordableNodesCnt: props.reordableNodesCnt, totalRulesCnt: props.totalRulesCnt, onDragStart: props.onDragStart, isDraggingTempo: props.isDraggingTempo, children1: props.children1, parentField: null, parentReordableNodesCnt: props.parentReordableNodesCnt })); }, case_group: function case_group(props) { return /*#__PURE__*/React.createElement(CaseGroup, _extends({}, getProperties(props), { id: props.id, groupId: props.groupId, path: props.path, actions: props.actions, config: props.config, reordableNodesCnt: props.reordableNodesCnt, totalRulesCnt: props.totalRulesCnt, onDragStart: props.onDragStart, isDraggingTempo: props.isDraggingTempo, children1: props.children1, parentField: null, parentReordableNodesCnt: props.parentReordableNodesCnt })); } }; var Item = /*#__PURE__*/function (_PureComponent) { function Item() { _classCallCheck(this, Item); return _callSuper(this, Item, arguments); } _inherits(Item, _PureComponent); return _createClass(Item, [{ key: "render", value: function render() { var _props$properties2; var _this$props = this.props, type = _this$props.type, props = _objectWithoutProperties(_this$props, _excluded); var mode = (_props$properties2 = props.properties) === null || _props$properties2 === void 0 ? void 0 : _props$properties2.get("mode"); var postfix = mode == "array" ? "_ext" : ""; var renderItem = props.config.settings.renderItem; var Cmp = typeMap[type + postfix]; if (renderItem) { return renderItem(_objectSpread(_objectSpread({}, props), {}, { type: type, itemComponent: Cmp }), props.config.ctx); } if (!Cmp) return null; return Cmp(props); } }]); }(PureComponent); Item.propTypes = { config: PropTypes.object.isRequired, id: PropTypes.string.isRequired, groupId: PropTypes.string, type: PropTypes.oneOf(types).isRequired, path: PropTypes.any.isRequired, //instanceOf(Immutable.List) properties: PropTypes.any, //instanceOf(Immutable.Map) children1: PropTypes.any, //instanceOf(Immutable.OrderedMap) actions: PropTypes.object.isRequired, reordableNodesCnt: PropTypes.number, onDragStart: PropTypes.func, parentField: PropTypes.string, //from RuleGroup isDraggingTempo: PropTypes.bool, isParentLocked: PropTypes.bool }; export { Item };