"use strict";var React=require("react"),ReactDOM=require("react-dom"),reactUse=require("react-use");function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var React__default=_interopDefaultLegacy(React);function useContextMenu(e){var t=e.triggerElement,u=e.menuRender,n=e.disabled,a=void 0!==n&&n,n=e.triggerByChild,i=void 0===n||n,n=e.wrapperClassName,f=e.getPopupContainer,o=e.getMenuPosition,l=e.blackList,e=reactUse.useMeasure(),d=e[0],e=e[1],m=e.width,v=e.height,p=React.useRef(null),e=React.useState(!1),c=e[0],s=e[1],e=React.useState(0),R=e[0],g=e[1],e=React.useState(0),x=e[0],C=e[1],e=React.useMemo(function(){return{position:"fixed",left:t&&c?R:"-"+(window.outerWidth+1e3)+"px",top:t&&c?x:"-"+(window.outerHeight+1e3)+"px",zIndex:9999}},[c,t,R,x]),h=React.useCallback(function(e){d(e),p.current=e},[d]),r=(reactUse.useClickAway(p,function(){s(!1)}),React.useCallback(function(e){var t=e.target,n=e.currentTarget;if(t&&n&&t instanceof Element&&n instanceof Element&&(!i||n.contains(t))&&(i||n===t)){if(l)for(var a=l.length,c=t;c;){for(var r=0;r<a;r++)if(c.classList.contains(l[r])||c.tagName===l[r])return;c=c.parentElement}if(e.preventDefault(),s(!0),o)return t=(n=o(e))[0],n=n[1],g(t),void C(n);var t=e.clientX,n=void 0===t?0:t,t=e.clientY,e=void 0===t?0:t,t=document.documentElement,u=t.clientWidth,t=t.clientHeight,u=n+m-u,t=e+v-t;g(0<u?n-u:n),C(0<t?e-t:e)}},[l,o,v,i,m])),E=React.useCallback(function(){s(!1)},[]);return React.useEffect(function(){return a?null!=t&&t.removeEventListener("contextmenu",r):null!=t&&t.addEventListener("contextmenu",r),function(){null!=t&&t.removeEventListener("contextmenu",r)}},[E,r,t,a]),a?null:ReactDOM.createPortal(React__default.default.createElement("div",{className:n,ref:h,style:e,onClick:E},u()),(null==f?void 0:f())||document.body)}function compact(e){for(var t=-1,n=null==e?0:e.length,a=0,c=[];++t<n;){var r=e[t];r&&(c[a++]=r)}return c}var compact_1=compact;exports.compact_1=compact_1,exports.useContextMenu=useContextMenu;
