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

2 lines
12 KiB
JavaScript

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/ripple"),i=require("primereact/csstransition"),r=require("primereact/overlayservice"),o=require("primereact/portal"),s=require("primereact/api");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=l(e),a=l(s);function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function p(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&&p(e.prototype,t),n&&p(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function d(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function f(e,t){return f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},f(e,t)}function h(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&&f(e,t)}function v(e){return v="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},v(e)}function y(e,t){if(t&&("object"===v(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return d(e)}function b(e){return b=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},b(e)}function k(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(){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 C=function(i){h(l,e.Component);var r,o,s=(r=l,o=E(),function(){var e,t=b(r);if(o){var n=b(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return y(this,e)});function l(e){var t;return c(this,l),(t=s.call(this,e)).state={activeItem:null},t.onLeafClick=t.onLeafClick.bind(d(t)),t.onChildItemKeyDown=t.onChildItemKeyDown.bind(d(t)),t}return m(l,[{key:"componentDidUpdate",value:function(e){e.parentActive&&!this.props.parentActive&&this.setState({activeItem:null}),this.props.parentActive&&!this.props.root&&this.position()}},{key:"componentDidMount",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){e.element&&!e.element.contains(t.target)&&e.setState({activeItem:null})},document.addEventListener("click",this.documentClickListener))}},{key:"componentWillUnmount",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{key:"position",value:function(){if(this.element){var e=this.element.parentElement,n=t.DomHandler.getOffset(e),i=t.DomHandler.getViewport(),r=this.element.offsetParent?this.element.offsetWidth:t.DomHandler.getHiddenElementOuterWidth(this.element),o=t.DomHandler.getOuterWidth(e.children[0]);parseInt(n.left,10)+o+r>i.width-t.DomHandler.calculateScrollbarWidth()&&t.DomHandler.addClass(this.element,"p-submenu-list-flipped")}}},{key:"onItemMouseEnter",value:function(e,t){t.disabled?e.preventDefault():this.props.root?(this.state.activeItem||this.props.popup)&&this.setState({activeItem:t}):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}),this.props.root&&t.items&&this.setState(this.state.activeItem&&t===this.state.activeItem?{activeItem:null}:{activeItem:t}),t.items||this.onLeafClick())}},{key:"onItemKeyDown",value:function(e,t){var n=e.currentTarget.parentElement;switch(e.which){case 40:var i=this.findNextItem(n);i&&i.children[0].focus(),e.preventDefault();break;case 38:var r=this.findPrevItem(n);r&&r.children[0].focus(),e.preventDefault();break;case 39:t.items&&(this.setState({activeItem:t}),setTimeout((function(){n.children[1].children[0].children[0].focus()}),50)),e.preventDefault()}this.props.onKeyDown&&this.props.onKeyDown(e,n)}},{key:"onChildItemKeyDown",value:function(e,t){37===e.which&&(this.setState({activeItem:null}),t.parentElement.previousElementSibling.focus())}},{key:"findNextItem",value:function(e){var n=e.nextElementSibling;return n?t.DomHandler.hasClass(n,"p-disabled")||!t.DomHandler.hasClass(n,"p-menuitem")?this.findNextItem(n):n:null}},{key:"findPrevItem",value:function(e){var n=e.previousElementSibling;return n?t.DomHandler.hasClass(n,"p-disabled")||!t.DomHandler.hasClass(n,"p-menuitem")?this.findPrevItem(n):n:null}},{key:"onLeafClick",value:function(){this.setState({activeItem:null}),this.props.onLeafClick&&this.props.onLeafClick()}},{key:"renderSeparator",value:function(e){return u.default.createElement("li",{key:"separator_"+e,className:"p-menu-separator",role:"separator"})}},{key:"renderSubmenu",value:function(e){return e.items?u.default.createElement(l,{model:e.items,onLeafClick:this.onLeafClick,popup:this.props.popup,onKeyDown:this.onChildItemKeyDown,parentActive:e===this.state.activeItem}):null}},{key:"renderMenuitem",value:function(e,i){var r=this,o=this.state.activeItem===e,s=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",p=e.icon&&u.default.createElement("span",{className:a}),m=e.label&&u.default.createElement("span",{className:"p-menuitem-text"},e.label),d=e.items&&u.default.createElement("span",{className:c}),f=this.renderSubmenu(e),h=u.default.createElement("a",{href:e.url||"#",className:l,target:e.target,role:"menuitem","aria-haspopup":null!=e.items,onClick:function(t){return r.onItemClick(t,e)},onKeyDown:function(t){return r.onItemKeyDown(t,e)},"aria-disabled":e.disabled},p,m,d,u.default.createElement(n.Ripple,null));e.template&&(h=t.ObjectUtils.getJSXElement(e.template,e,{onClick:function(t){return r.onItemClick(t,e)},onKeyDown:function(t){return r.onItemKeyDown(t,e)},className:l,labelClassName:"p-menuitem-text",iconClassName:a,submenuIconClassName:c,element:h,props:this.props,active:o}));return u.default.createElement("li",{key:e.label+"_"+i,className:s,style:e.style,onMouseEnter:function(t){return r.onItemMouseEnter(t,e)},role:"none"},h,f)}},{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=this,n=t.classNames({"p-submenu-list":!this.props.root}),i=this.renderMenu();return u.default.createElement("ul",{ref:function(t){return e.element=t},className:n,role:this.props.root?"menubar":"menu","aria-orientation":"horizontal"},i)}}]),l}();function L(){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}}k(C,"defaultProps",{model:null,root:!1,className:null,popup:!1,onLeafClick:null,onKeyDown:null,parentActive:!1});var D=function(n){h(f,e.Component);var s,l,p=(s=f,l=L(),function(){var e,t=b(s);if(l){var n=b(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return y(this,e)});function f(e){var t;return c(this,f),(t=p.call(this,e)).state={visible:!e.popup},t.onEnter=t.onEnter.bind(d(t)),t.onEntered=t.onEntered.bind(d(t)),t.onExit=t.onExit.bind(d(t)),t.onExited=t.onExited.bind(d(t)),t.onPanelClick=t.onPanelClick.bind(d(t)),t.menuRef=u.default.createRef(),t}return m(f,[{key:"onPanelClick",value:function(e){this.props.popup&&r.OverlayService.emit("overlay-click",{originalEvent:e,target:this.target})}},{key:"toggle",value:function(e){this.props.popup&&(this.state.visible?this.hide(e):this.show(e))}},{key:"show",value:function(e){var t=this;this.target=e.currentTarget;var n=e;this.setState({visible:!0},(function(){t.props.onShow&&t.props.onShow(n)}))}},{key:"hide",value:function(e){var t=this,n=e;this.setState({visible:!1},(function(){t.props.onHide&&t.props.onHide(n)}))}},{key:"onEnter",value:function(){this.props.autoZIndex&&t.ZIndexUtils.set("menu",this.menuRef.current,a.default.autoZIndex,this.props.baseZIndex||a.default.zIndex.menu),t.DomHandler.absolutePosition(this.menuRef.current,this.target)}},{key:"onEntered",value:function(){this.bindDocumentListeners(),this.bindScrollListener()}},{key:"onExit",value:function(){this.target=null,this.unbindDocumentListeners(),this.unbindScrollListener()}},{key:"onExited",value:function(){t.ZIndexUtils.clear(this.menuRef.current)}},{key:"bindDocumentListeners",value:function(){this.bindDocumentClickListener(),this.bindDocumentResizeListener()}},{key:"unbindDocumentListeners",value:function(){this.unbindDocumentClickListener(),this.unbindDocumentResizeListener()}},{key:"bindDocumentClickListener",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){e.props.popup&&e.state.visible&&e.menuRef.current&&!e.menuRef.current.contains(t.target)&&e.hide(t)},document.addEventListener("click",this.documentClickListener))}},{key:"unbindDocumentClickListener",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{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:"unbindDocumentResizeListener",value:function(){this.documentResizeListener&&(window.removeEventListener("resize",this.documentResizeListener),this.documentResizeListener=null)}},{key:"bindScrollListener",value:function(){var e=this;this.scrollHandler||(this.scrollHandler=new t.ConnectedOverlayScrollHandler(this.target,(function(t){e.state.visible&&e.hide(t)}))),this.scrollHandler.bindScrollListener()}},{key:"unbindScrollListener",value:function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()}},{key:"componentWillUnmount",value:function(){this.unbindDocumentListeners(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),t.ZIndexUtils.clear(this.menuRef.current)}},{key:"renderElement",value:function(){var e=t.classNames("p-tieredmenu p-component",{"p-tieredmenu-overlay":this.props.popup},this.props.className);return u.default.createElement(i.CSSTransition,{nodeRef:this.menuRef,classNames:"p-connected-overlay",in:this.state.visible,timeout:{enter:120,exit:100},options:this.props.transitionOptions,unmountOnExit:!0,onEnter:this.onEnter,onEntered:this.onEntered,onExit:this.onExit,onExited:this.onExited},u.default.createElement("div",{ref:this.menuRef,id:this.props.id,className:e,style:this.props.style,onClick:this.onPanelClick},u.default.createElement(C,{model:this.props.model,root:!0,popup:this.props.popup})))}},{key:"render",value:function(){var e=this.renderElement();return this.props.popup?u.default.createElement(o.Portal,{element:e,appendTo:this.props.appendTo}):e}}]),f}();k(D,"defaultProps",{id:null,model:null,popup:!1,style:null,className:null,autoZIndex:!0,baseZIndex:0,appendTo:null,transitionOptions:null,onShow:null,onHide:null}),exports.TieredMenu=D;