UNPKG

dash-renderer

Version:

render dash components in react

45 lines (44 loc) 2.81 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 createElement(element, props, extraProps, children) { var allProps = (0, _ramda.mergeRight)(props, extraProps); if (Array.isArray(children)) { return /*#__PURE__*/_react.default.createElement(element, allProps, ...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); }