kwikid-components-react
Version:
KwikID's Component Library in React
50 lines (46 loc) • 2.77 kB
JavaScript
;
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 _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
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;