"use strict";var stringUtil=require("./stringUtil-1ce2e674.js"),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),loopTreeData=function(e,c,u){var t=null!=c?c:{titleKey:"name",idKey:["id"]},o=t.titleKey,l=t.idKey;return stringUtil.map_1(e,function(e){for(var t=e[o],n=l.length,r="",a=0;a<n;a++){var i=l[a];if(e[i]){r=e[i];break}}t=stringUtil.__assign(stringUtil.__assign({},e),{title:t,key:r}),t=u?u(t):t;return e.children?stringUtil.__assign(stringUtil.__assign({},t),{children:loopTreeData(e.children,c,u)}):t})};function useContextMenu(e){var t=e.triggerElement,c=e.menuRender,n=e.disabled,r=void 0!==n&&n,n=e.triggerByChild,u=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],g=e.width,m=e.height,p=React.useRef(null),e=React.useState(!1),a=e[0],s=e[1],e=React.useState(0),v=e[0],_=e[1],e=React.useState(0),R=e[0],h=e[1],e=React.useMemo(function(){return{position:"fixed",left:t&&a?v:"-"+(window.outerWidth+1e3)+"px",top:t&&a?R:"-"+(window.outerHeight+1e3)+"px",zIndex:9999}},[a,t,v,R]),x=React.useCallback(function(e){d(e),p.current=e},[d]),i=(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&&(!u||n.contains(t))&&(u||n===t)){if(l)for(var r=l.length,a=t;a;){for(var i=0;i<r;i++)if(a.classList.contains(l[i])||a.tagName===l[i])return;a=a.parentElement}if(e.preventDefault(),s(!0),o)return t=(n=o(e))[0],n=n[1],_(t),void h(n);var t=e.clientX,n=void 0===t?0:t,t=e.clientY,e=void 0===t?0:t,t=document.documentElement,c=t.clientWidth,t=t.clientHeight,c=n+g-c,t=e+m-t;_(0<c?n-c:n),h(0<t?e-t:e)}},[l,o,m,u,g])),y=React.useCallback(function(){s(!1)},[]);return React.useEffect(function(){return r?null!=t&&t.removeEventListener("contextmenu",i):null!=t&&t.addEventListener("contextmenu",i),function(){null!=t&&t.removeEventListener("contextmenu",i)}},[y,i,t,r]),r?null:ReactDOM.createPortal(React__default.default.createElement("div",{className:n,ref:x,style:e,onClick:y},c()),(null==f?void 0:f())||document.body)}function compact(e){for(var t=-1,n=null==e?0:e.length,r=0,a=[];++t<n;){var i=e[t];i&&(a[r++]=i)}return a}var compact_1=compact;exports.compact_1=compact_1,exports.loopTreeData=loopTreeData,exports.useContextMenu=useContextMenu;
