UNPKG

dash-renderer

Version:

render dash components in react

51 lines (50 loc) 3.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkDashChildrenUpdate = checkDashChildrenUpdate; exports.checkRenderTypeProp = checkRenderTypeProp; exports.createElement = createElement; exports.getComponentLayout = getComponentLayout; exports.isDryComponent = isDryComponent; exports.stringifyPath = stringifyPath; exports.validateComponent = validateComponent; var _react = _interopRequireDefault(require("react")); var _ramda = require("ramda"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function createElement(element, props, extraProps, children) { var allProps = (0, _ramda.mergeRight)(props, extraProps); if (Array.isArray(children)) { return /*#__PURE__*/_react.default.createElement.apply(_react.default, [element, allProps].concat(_toConsumableArray(children))); } return /*#__PURE__*/_react.default.createElement(element, allProps, children); } function isDryComponent(obj) { return (0, _ramda.type)(obj) === 'Object' && (0, _ramda.has)('type', obj) && (0, _ramda.has)('namespace', obj) && (0, _ramda.has)('props', obj); } function validateComponent(componentDefinition) { if ((0, _ramda.type)(componentDefinition) === 'Array') { throw new Error('The children property of a component is a list of lists, instead ' + 'of just a list. This can sometimes be due to a trailing comma. ' + 'Check the component that has the following contents ' + 'and remove one of the levels of nesting: \n' + JSON.stringify(componentDefinition, null, 2)); } if ((0, _ramda.type)(componentDefinition) === 'Object' && !((0, _ramda.has)('namespace', componentDefinition) && (0, _ramda.has)('type', componentDefinition) && (0, _ramda.has)('props', componentDefinition))) { throw new Error('An object was provided as `children` instead of a component, ' + 'string, or number (or list of those). ' + 'Check the children property that looks something like:\n' + JSON.stringify(componentDefinition, null, 2)); } } function stringifyPath(layoutPath) { return (0, _ramda.join)(',', layoutPath); } function getComponentLayout(componentPath, state) { return (0, _ramda.path)(componentPath, state.layout); } function checkRenderTypeProp(componentDefinition) { return 'dashRenderType' in (0, _ramda.pathOr)({}, [componentDefinition === null || componentDefinition === void 0 ? void 0 : componentDefinition.namespace, componentDefinition === null || componentDefinition === void 0 ? void 0 : componentDefinition.type], window); } function checkDashChildrenUpdate(componentDefinition) { return 'dashChildrenUpdate' in (0, _ramda.pathOr)({}, [componentDefinition === null || componentDefinition === void 0 ? void 0 : componentDefinition.namespace, componentDefinition === null || componentDefinition === void 0 ? void 0 : componentDefinition.type], window); }