1 line
7.6 KiB
JSON
1 line
7.6 KiB
JSON
|
{"ast":null,"code":"import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport useLayoutEffect from \"rc-util/es/hooks/useLayoutEffect\";\nimport canUseDom from \"rc-util/es/Dom/canUseDom\";\nimport OrderContext from \"./Context\";\nvar EMPTY_LIST = [];\n\n/**\n * Will add `div` to document. Nest call will keep order\n * @param render Render DOM in document\n */\nexport default function useDom(render, debug) {\n var _React$useState = React.useState(function () {\n if (!canUseDom()) {\n return null;\n }\n var defaultEle = document.createElement('div');\n if (process.env.NODE_ENV !== 'production' && debug) {\n defaultEle.setAttribute('data-debug', debug);\n }\n return defaultEle;\n }),\n _React$useState2 = _slicedToArray(_React$useState, 1),\n ele = _React$useState2[0];\n\n // ========================== Order ==========================\n var appendedRef = React.useRef(false);\n var queueCreate = React.useContext(OrderContext);\n var _React$useState3 = React.useState(EMPTY_LIST),\n _React$useState4 = _slicedToArray(_React$useState3, 2),\n queue = _React$useState4[0],\n setQueue = _React$useState4[1];\n var mergedQueueCreate = queueCreate || (appendedRef.current ? undefined : function (appendFn) {\n setQueue(function (origin) {\n var newQueue = [appendFn].concat(_toConsumableArray(origin));\n return newQueue;\n });\n });\n\n // =========================== DOM ===========================\n function append() {\n if (!ele.parentElement) {\n document.body.appendChild(ele);\n }\n appendedRef.current = true;\n }\n function cleanup() {\n var _ele$parentElement;\n (_ele$parentElement = ele.parentElement) === null || _ele$parentElement === void 0 ? void 0 : _ele$parentElement.removeChild(ele);\n appendedRef.current = false;\n }\n useLayoutEffect(function () {\n if (render) {\n if (queueCreate) {\n queueCreate(append);\n } else {\n append();\n }\n } else {\n cleanup();\n }\n return cleanup;\n }, [render]);\n useLayoutEffect(function () {\n if (queue.length) {\n queue.forEach(function (appendFn) {\n return appendFn();\n });\n setQueue(EMPTY_LIST);\n }\n }, [queue]);\n return [ele, mergedQueueCreate];\n}","map":{"version":3,"names":["_toConsumableArray","_slicedToArray","React","useLayoutEffect","canUseDom","OrderContext","EMPTY_LIST","useDom","render","debug","_React$useState","useState","defaultEle","document","createElement","process","env","NODE_ENV","setAttribute","_React$useState2","ele","appendedRef","useRef","queueCreate","useContext","_React$useState3","_React$useState4","queue","setQueue","mergedQueueCreate","current","undefined","appendFn","origin","newQueue","concat","append","parentElement","body","appendChild","cleanup","_ele$parentElement","removeChild","length","forEach"],"sources":["C:/Users/Аришина)/source/repos/PromoCursed/node_modules/@rc-component/portal/es/useDom.js"],"sourcesContent":["import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport useLayoutEffect from \"rc-util/es/hooks/useLayoutEffect\";\nimport canUseDom from \"rc-util/es/Dom/canUseDom\";\nimport OrderContext from \"./Context\";\nvar EMPTY_LIST = [];\n\n/**\n * Will add `div` to document. Nest call will keep order\n * @param render Render DOM in document\n */\nexport default function useDom(render, debug) {\n var _React$useState = React.useState(function () {\n if (!canUseDom()) {\n return null;\n }\n var defaultEle = document.createElement('div');\n if (process.env.NODE_ENV !== 'production' && debug) {\n defaultEle.setAttribute('data-debug', debug);\n }\n return defaultEle;\n }),\n _React$useState2 = _slicedToArray(_React$useState, 1
|