UNPKG

@flatbiz/antd

Version:
59 lines (55 loc) 1.88 kB
/*! @flatjs/forge MIT @flatbiz/antd */ import { classNames } from '@dimjs/utils/class-names/class-names'; import { createRoot } from 'react-dom/client'; import { b as bodyAppendDivElement } from './dom-DJxTwF3J.js'; import { jsx } from 'react/jsx-runtime'; /** * 动态添加 element 元素 * ``` * 1. 默认添加到 body 下 * 2. 可通过 getContainer 参数设置添加位置 * ``` */ var dynamicNode = { append: function append() { var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var container = function () { var tempElement; if (typeof props.getContainer === 'string') { tempElement = document.querySelector(props.getContainer); } else if (typeof props.getContainer === 'function') { tempElement = props.getContainer(); } else { tempElement = bodyAppendDivElement().divElement; } return tempElement; }(); var className = classNames('v-dynamic-node', { 'v-dynamic-node-fixed': props.fixed }, props.className); var nodeElementId = "id_".concat(Date.now()); var root = createRoot(container); root.render(/*#__PURE__*/jsx("div", { className: className, id: nodeElementId, children: props.content })); window['_dynamic_node_element_id'] = nodeElementId; return { elementId: nodeElementId }; }, remove: function remove(elementId) { var dynamicElementId = elementId || window['_dynamic_node_element_id']; if (dynamicElementId) { try { var _document$querySelect; (_document$querySelect = document.querySelector("#".concat(dynamicElementId))) === null || _document$querySelect === void 0 || _document$querySelect.remove(); } catch (_error) { // } } } }; export { dynamicNode as d }; //# sourceMappingURL=dynamic-node-B_An5owN.js.map