katoikia-app/web-ui/web-react/node_modules/primereact/contextmenu/contextmenu.cjs.min.js

2 lines
11 KiB
JavaScript

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/csstransition"),i=require("primereact/ripple"),r=require("primereact/portal"),o=require("primereact/api");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=u(e),l=u(o);function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function m(e,t,n){return t&&c(e.prototype,t),n&&c(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function f(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function d(e,t){return d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},d(e,t)}function p(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&d(e,t)}function h(e){return h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},h(e)}function v(e,t){if(t&&("object"===h(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return f(e)}function b(e){return b=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},b(e)}function y(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function E(e){var t=k();return function(){var n,i=b(e);if(t){var r=b(this).constructor;n=Reflect.construct(i,arguments,r)}else n=i.apply(this,arguments);return v(this,n)}}function k(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var L=function(r){p(u,e.Component);var o=E(u);function u(e){var t;return a(this,u),(t=o.call(this,e)).state={activeItem:null},t.onEnter=t.onEnter.bind(f(t)),t.submenuRef=s.default.createRef(),t}return m(u,[{key:"onItemMouseEnter",value:function(e,t){t.disabled?e.preventDefault():this.setState({activeItem:t})}},{key:"onItemClick",value:function(e,t){t.disabled?e.preventDefault():(t.url||e.preventDefault(),t.command&&t.command({originalEvent:e,item:t}),t.items||this.props.onLeafClick(e))}},{key:"position",value:function(){var e=this.submenuRef.current.parentElement,n=t.DomHandler.getOffset(this.submenuRef.current.parentElement),i=t.DomHandler.getViewport(),r=this.submenuRef.current.offsetParent?this.submenuRef.current.offsetWidth:t.DomHandler.getHiddenElementOuterWidth(this.submenuRef.current),o=t.DomHandler.getOuterWidth(e.children[0]);this.submenuRef.current.style.top="0px",this.submenuRef.current.style.left=parseInt(n.left,10)+o+r>i.width-t.DomHandler.calculateScrollbarWidth()?-1*r+"px":o+"px"}},{key:"onEnter",value:function(){this.position()}},{key:"isActive",value:function(){return this.props.root||!this.props.resetMenu}},{key:"componentDidUpdate",value:function(){this.isActive()&&this.position()}},{key:"renderSeparator",value:function(e){return s.default.createElement("li",{key:"separator_"+e,className:"p-menu-separator",role:"separator"})}},{key:"renderSubmenu",value:function(e){return e.items?s.default.createElement(u,{model:e.items,resetMenu:e!==this.state.activeItem,onLeafClick:this.props.onLeafClick}):null}},{key:"renderMenuitem",value:function(e,n){var r=this,o=this.state.activeItem===e,u=t.classNames("p-menuitem",{"p-menuitem-active":o},e.className),l=t.classNames("p-menuitem-link",{"p-disabled":e.disabled}),a=t.classNames("p-menuitem-icon",e.icon),c="p-submenu-icon pi pi-angle-right",m=e.icon&&s.default.createElement("span",{className:a}),f=e.label&&s.default.createElement("span",{className:"p-menuitem-text"},e.label),d=e.items&&s.default.createElement("span",{className:c}),p=this.renderSubmenu(e),h=s.default.createElement("a",{href:e.url||"#",className:l,target:e.target,onClick:function(t){return r.onItemClick(t,e,n)},role:"menuitem","aria-haspopup":null!=e.items,"aria-disabled":e.disabled},m,f,d,s.default.createElement(i.Ripple,null));e.template&&(h=t.ObjectUtils.getJSXElement(e.template,e,{onClick:function(t){return r.onItemClick(t,e,n)},className:l,labelClassName:"p-menuitem-text",iconClassName:a,submenuIconClassName:c,element:h,props:this.props,active:o}));return s.default.createElement("li",{key:e.label+"_"+n,role:"none",className:u,style:e.style,onMouseEnter:function(t){return r.onItemMouseEnter(t,e)}},h,p)}},{key:"renderItem",value:function(e,t){return e.separator?this.renderSeparator(t):this.renderMenuitem(e,t)}},{key:"renderMenu",value:function(){var e=this;return this.props.model?this.props.model.map((function(t,n){return e.renderItem(t,n)})):null}},{key:"render",value:function(){var e=t.classNames({"p-submenu-list":!this.props.root}),i=this.renderMenu(),r=this.isActive();return s.default.createElement(n.CSSTransition,{nodeRef:this.submenuRef,classNames:"p-contextmenusub",in:r,timeout:{enter:0,exit:0},unmountOnExit:!0,onEnter:this.onEnter},s.default.createElement("ul",{ref:this.submenuRef,className:e},i))}}],[{key:"getDerivedStateFromProps",value:function(e,t){return!0===e.resetMenu?{activeItem:null}:null}}]),u}();y(L,"defaultProps",{model:null,root:!1,className:null,resetMenu:!1,onLeafClick:null});var x=function(i){p(u,e.Component);var o=E(u);function u(e){var t;return a(this,u),(t=o.call(this,e)).state={visible:!1,reshow:!1,resetMenu:!1},t.onMenuClick=t.onMenuClick.bind(f(t)),t.onLeafClick=t.onLeafClick.bind(f(t)),t.onMenuMouseEnter=t.onMenuMouseEnter.bind(f(t)),t.onEnter=t.onEnter.bind(f(t)),t.onEntered=t.onEntered.bind(f(t)),t.onExit=t.onExit.bind(f(t)),t.onExited=t.onExited.bind(f(t)),t.menuRef=s.default.createRef(),t}return m(u,[{key:"onMenuClick",value:function(){this.setState({resetMenu:!1})}},{key:"onMenuMouseEnter",value:function(){this.setState({resetMenu:!1})}},{key:"show",value:function(e){var t=this;e instanceof Event||e.persist(),e.stopPropagation(),e.preventDefault(),this.currentEvent=e,this.state.visible?this.setState({reshow:!0}):this.setState({visible:!0},(function(){t.props.onShow&&t.props.onShow(t.currentEvent)}))}},{key:"hide",value:function(e){var t=this;e instanceof Event||e.persist(),this.currentEvent=e,this.setState({visible:!1,reshow:!1},(function(){t.props.onHide&&t.props.onHide(t.currentEvent)}))}},{key:"onEnter",value:function(){this.props.autoZIndex&&t.ZIndexUtils.set("menu",this.menuRef.current,l.default.autoZIndex,this.props.baseZIndex||l.default.zIndex.menu),this.position(this.currentEvent)}},{key:"onEntered",value:function(){this.bindDocumentListeners()}},{key:"onExit",value:function(){this.currentEvent=null,this.unbindDocumentListeners()}},{key:"onExited",value:function(){t.ZIndexUtils.clear(this.menuRef.current)}},{key:"position",value:function(e){if(e){var n=e.pageX+1,i=e.pageY+1,r=this.menuRef.current.offsetParent?this.menuRef.current.offsetWidth:t.DomHandler.getHiddenElementOuterWidth(this.menuRef.current),o=this.menuRef.current.offsetParent?this.menuRef.current.offsetHeight:t.DomHandler.getHiddenElementOuterHeight(this.menuRef.current),u=t.DomHandler.getViewport();n+r-document.body.scrollLeft>u.width&&(n-=r),i+o-document.body.scrollTop>u.height&&(i-=o),n<document.body.scrollLeft&&(n=document.body.scrollLeft),i<document.body.scrollTop&&(i=document.body.scrollTop),this.menuRef.current.style.left=n+"px",this.menuRef.current.style.top=i+"px"}}},{key:"onLeafClick",value:function(e){this.setState({resetMenu:!0}),this.hide(e),e.stopPropagation()}},{key:"isOutsideClicked",value:function(e){return this.menuRef&&this.menuRef.current&&!(this.menuRef.current.isSameNode(e.target)||this.menuRef.current.contains(e.target))}},{key:"bindDocumentListeners",value:function(){this.bindDocumentResizeListener(),this.bindDocumentClickListener()}},{key:"unbindDocumentListeners",value:function(){this.unbindDocumentResizeListener(),this.unbindDocumentClickListener()}},{key:"bindDocumentClickListener",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){e.isOutsideClicked(t)&&2!==t.button&&(e.hide(t),e.setState({resetMenu:!0}))},document.addEventListener("click",this.documentClickListener))}},{key:"bindDocumentContextMenuListener",value:function(){var e=this;this.documentContextMenuListener||(this.documentContextMenuListener=function(t){e.show(t)},document.addEventListener("contextmenu",this.documentContextMenuListener))}},{key:"bindDocumentResizeListener",value:function(){var e=this;this.documentResizeListener||(this.documentResizeListener=function(n){e.state.visible&&!t.DomHandler.isTouchDevice()&&e.hide(n)},window.addEventListener("resize",this.documentResizeListener))}},{key:"unbindDocumentClickListener",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{key:"unbindDocumentContextMenuListener",value:function(){this.documentContextMenuListener&&(document.removeEventListener("contextmenu",this.documentContextMenuListener),this.documentContextMenuListener=null)}},{key:"unbindDocumentResizeListener",value:function(){this.documentResizeListener&&(window.removeEventListener("resize",this.documentResizeListener),this.documentResizeListener=null)}},{key:"componentDidMount",value:function(){this.props.global&&this.bindDocumentContextMenuListener()}},{key:"componentDidUpdate",value:function(e,t){var n=this;if(this.state.visible&&(t.reshow!==this.state.reshow||e.model!==this.props.model)){var i=this.currentEvent;this.setState({visible:!1,reshow:!1,rePosition:!1,resetMenu:!0},(function(){return n.show(i)}))}}},{key:"componentWillUnmount",value:function(){this.unbindDocumentListeners(),this.unbindDocumentContextMenuListener(),t.ZIndexUtils.clear(this.menuRef.current)}},{key:"renderContextMenu",value:function(){var e=t.classNames("p-contextmenu p-component",this.props.className);return s.default.createElement(n.CSSTransition,{nodeRef:this.menuRef,classNames:"p-contextmenu",in:this.state.visible,timeout:{enter:250,exit:0},options:this.props.transitionOptions,unmountOnExit:!0,onEnter:this.onEnter,onEntered:this.onEntered,onExit:this.onExit,onExited:this.onExited},s.default.createElement("div",{ref:this.menuRef,id:this.props.id,className:e,style:this.props.style,onClick:this.onMenuClick,onMouseEnter:this.onMenuMouseEnter},s.default.createElement(L,{model:this.props.model,root:!0,resetMenu:this.state.resetMenu,onLeafClick:this.onLeafClick})))}},{key:"render",value:function(){var e=this.renderContextMenu();return s.default.createElement(r.Portal,{element:e,appendTo:this.props.appendTo})}}]),u}();y(x,"defaultProps",{id:null,model:null,style:null,className:null,global:!1,autoZIndex:!0,baseZIndex:0,appendTo:null,transitionOptions:null,onShow:null,onHide:null}),exports.ContextMenu=x;