UNPKG

kwikid-components-react

Version:

KwikID's Component Library in React

49 lines (45 loc) 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _kwikidToolkit = require("kwikid-toolkit"); var _react = _interopRequireWildcard(require("react")); var _DynamicViewContainer = require("./DynamicViewContainer.defaults"); var _DynamicViewContainer2 = require("./DynamicViewContainer.helper"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } const KwikIDDataViewerDynamicViewContainer = _ref => { var _config$layout2; let { data = _DynamicViewContainer.KWIKID_DATA_VIEWER_DYNAMIC_VIEW_CONTAINER.data, config = _DynamicViewContainer.KWIKID_DATA_VIEWER_DYNAMIC_VIEW_CONTAINER.config } = _ref; (0, _react.useEffect)(() => { if ((0, _kwikidToolkit.isNotEmptyValue)(config) && (0, _kwikidToolkit.checkObjectPathExists)(config, "layout.components") && (0, _kwikidToolkit.checkObjectPathExists)(config, "layout.id")) { const root = document.getElementById(config.layout.id); if (root) { // Clear previous content root.innerHTML = ""; // Apply styles root.setAttribute("style", config.layout.styles || ""); // Call the async function to get and render all components (0, _DynamicViewContainer2.getComponents)(root, config.layout.components, data, config).catch(e => { console.log(e); }); } } // Cleanup function to clear content when component unmounts or updates return () => { var _config$layout; const root = document.getElementById(((_config$layout = config.layout) === null || _config$layout === void 0 ? void 0 : _config$layout.id) || ""); if (root) { root.innerHTML = ""; } }; }, [config, data]); if (!(config !== null && config !== void 0 && (_config$layout2 = config.layout) !== null && _config$layout2 !== void 0 && _config$layout2.id)) return null; return /*#__PURE__*/_react.default.createElement("div", { id: config.layout.id }); }; var _default = exports.default = KwikIDDataViewerDynamicViewContainer;