1 line
7.7 KiB
JSON
1 line
7.7 KiB
JSON
|
{"ast":null,"code":"import { getShadowRoot } from \"rc-util/es/Dom/shadow\";\nimport { warning } from \"rc-util/es/warning\";\nimport * as React from 'react';\nimport { getWin } from \"../util\";\nexport default function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen) {\n var openRef = React.useRef(open);\n openRef.current = open;\n\n // Click to hide is special action since click popup element should not hide\n React.useEffect(function () {\n if (clickToHide && popupEle && (!mask || maskClosable)) {\n var onTriggerClose = function onTriggerClose(e) {\n var _e$composedPath;\n if (openRef.current && !inPopupOrChild(((_e$composedPath = e.composedPath) === null || _e$composedPath === void 0 || (_e$composedPath = _e$composedPath.call(e)) === null || _e$composedPath === void 0 ? void 0 : _e$composedPath[0]) || e.target)) {\n triggerOpen(false);\n }\n };\n var win = getWin(popupEle);\n win.addEventListener('mousedown', onTriggerClose, true);\n win.addEventListener('contextmenu', onTriggerClose, true);\n\n // shadow root\n var targetShadowRoot = getShadowRoot(targetEle);\n if (targetShadowRoot) {\n targetShadowRoot.addEventListener('mousedown', onTriggerClose, true);\n targetShadowRoot.addEventListener('contextmenu', onTriggerClose, true);\n }\n\n // Warning if target and popup not in same root\n if (process.env.NODE_ENV !== 'production') {\n var _targetEle$getRootNod, _popupEle$getRootNode;\n var targetRoot = targetEle === null || targetEle === void 0 || (_targetEle$getRootNod = targetEle.getRootNode) === null || _targetEle$getRootNod === void 0 ? void 0 : _targetEle$getRootNod.call(targetEle);\n var popupRoot = (_popupEle$getRootNode = popupEle.getRootNode) === null || _popupEle$getRootNode === void 0 ? void 0 : _popupEle$getRootNode.call(popupEle);\n warning(targetRoot === popupRoot, \"trigger element and popup element should in same shadow root.\");\n }\n return function () {\n win.removeEventListener('mousedown', onTriggerClose, true);\n win.removeEventListener('contextmenu', onTriggerClose, true);\n if (targetShadowRoot) {\n targetShadowRoot.removeEventListener('mousedown', onTriggerClose, true);\n targetShadowRoot.removeEventListener('contextmenu', onTriggerClose, true);\n }\n };\n }\n }, [clickToHide, targetEle, popupEle, mask, maskClosable]);\n}","map":{"version":3,"names":["getShadowRoot","warning","React","getWin","useWinClick","open","clickToHide","targetEle","popupEle","mask","maskClosable","inPopupOrChild","triggerOpen","openRef","useRef","current","useEffect","onTriggerClose","e","_e$composedPath","composedPath","call","target","win","addEventListener","targetShadowRoot","process","env","NODE_ENV","_targetEle$getRootNod","_popupEle$getRootNode","targetRoot","getRootNode","popupRoot","removeEventListener"],"sources":["C:/Users/Аришина)/source/repos/PromoCursed/node_modules/@rc-component/trigger/es/hooks/useWinClick.js"],"sourcesContent":["import { getShadowRoot } from \"rc-util/es/Dom/shadow\";\nimport { warning } from \"rc-util/es/warning\";\nimport * as React from 'react';\nimport { getWin } from \"../util\";\nexport default function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen) {\n var openRef = React.useRef(open);\n openRef.current = open;\n\n // Click to hide is special action since click popup element should not hide\n React.useEffect(function () {\n if (clickToHide && popupEle && (!mask || maskClosable)) {\n var onTriggerClose = function onTriggerClose(e) {\n var _e$composedPath;\n if (openRef.current && !inPopupOrChild(((_e$composedPath = e.composedPath) === null || _e$composedPath === void 0 || (_e$composedPath = _e$composedPath.call(e)) === null || _e$composedPath === void 0 ? void 0 : _e$composedPath[0]) || e.target)) {\n triggerOpen(false);\n }\n
|