katoikia-app/web-ui/web-react/node_modules/primereact/menubar/menubar.esm.min.js

2 lines
11 KiB
JavaScript

import e,{Component as t}from"react";import{DomHandler as n,classNames as r,ObjectUtils as i,ZIndexUtils as o}from"primereact/utils";import{Ripple as l}from"primereact/ripple";import u from"primereact/api";function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function c(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function m(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function p(e,t){return p=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},p(e,t)}function f(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&&p(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 m(e)}function d(e){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},d(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 b(){return b=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},b.apply(this,arguments)}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 C=function(o){f(h,t);var u,a,p=(u=h,a=k(),function(){var e,t=d(u);if(a){var n=d(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return v(this,e)});function h(e){var t;return s(this,h),(t=p.call(this,e)).state={activeItem:null},t.onLeafClick=t.onLeafClick.bind(m(t)),t.onChildItemKeyDown=t.onChildItemKeyDown.bind(m(t)),t}return c(h,[{key:"getElementRef",value:function(e){return this.element=e,this.props.forwardRef?this.props.forwardRef(e):this.element}},{key:"onItemMouseEnter",value:function(e,t){t.disabled||this.props.mobileActive?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}),t.items?this.setState(this.state.activeItem&&t===this.state.activeItem?{activeItem:null}:{activeItem:t}):this.onLeafClick())}},{key:"onItemKeyDown",value:function(e,t){var n=e.currentTarget.parentElement;switch(e.which){case 40:this.props.root?t.items&&this.expandSubmenu(t,n):this.navigateToNextItem(n),e.preventDefault();break;case 38:this.props.root||this.navigateToPrevItem(n),e.preventDefault();break;case 39:if(this.props.root){var r=this.findNextItem(n);r&&r.children[0].focus()}else t.items&&this.expandSubmenu(t,n);e.preventDefault();break;case 37:this.props.root&&this.navigateToPrevItem(n),e.preventDefault()}this.props.onKeyDown&&this.props.onKeyDown(e,n)}},{key:"onChildItemKeyDown",value:function(e,t){this.props.root?38===e.which&&null==t.previousElementSibling&&this.collapseMenu(t):37===e.which&&this.collapseMenu(t)}},{key:"expandSubmenu",value:function(e,t){this.setState({activeItem:e}),setTimeout((function(){t.children[1].children[0].children[0].focus()}),50)}},{key:"collapseMenu",value:function(e){this.setState({activeItem:null}),e.parentElement.previousElementSibling.focus()}},{key:"navigateToNextItem",value:function(e){var t=this.findNextItem(e);t&&t.children[0].focus()}},{key:"navigateToPrevItem",value:function(e){var t=this.findPrevItem(e);t&&t.children[0].focus()}},{key:"findNextItem",value:function(e){var t=e.nextElementSibling;return t?n.hasClass(t,"p-disabled")||!n.hasClass(t,"p-menuitem")?this.findNextItem(t):t:null}},{key:"findPrevItem",value:function(e){var t=e.previousElementSibling;return t?n.hasClass(t,"p-disabled")||!n.hasClass(t,"p-menuitem")?this.findPrevItem(t):t:null}},{key:"onLeafClick",value:function(){this.setState({activeItem:null}),this.props.onLeafClick&&this.props.onLeafClick()}},{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:"componentDidUpdate",value:function(e){e.parentActive&&!this.props.parentActive&&this.setState({activeItem:null})}},{key:"componentWillUnmount",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{key:"renderSeparator",value:function(t){return e.createElement("li",{key:"separator_"+t,className:"p-menu-separator",role:"separator"})}},{key:"renderSubmenu",value:function(t){return t.items?e.createElement(I,{model:t.items,mobileActive:this.props.mobileActive,onLeafClick:this.onLeafClick,onKeyDown:this.onChildItemKeyDown,parentActive:t===this.state.activeItem}):null}},{key:"renderMenuitem",value:function(t,n){var o=this,u=r("p-menuitem",{"p-menuitem-active":this.state.activeItem===t},t.className),s=r("p-menuitem-link",{"p-disabled":t.disabled}),a=r("p-menuitem-icon",t.icon),c=r("p-submenu-icon pi",{"pi-angle-down":this.props.root,"pi-angle-right":!this.props.root}),m=t.icon&&e.createElement("span",{className:a}),p=t.label&&e.createElement("span",{className:"p-menuitem-text"},t.label),f=t.items&&e.createElement("span",{className:c}),h=this.renderSubmenu(t),v=e.createElement("a",{href:t.url||"#",role:"menuitem",className:s,target:t.target,"aria-haspopup":null!=t.items,onClick:function(e){return o.onItemClick(e,t)},onKeyDown:function(e){return o.onItemKeyDown(e,t)}},m,p,f,e.createElement(l,null));t.template&&(v=i.getJSXElement(t.template,t,{onClick:function(e){return o.onItemClick(e,t)},onKeyDown:function(e){return o.onItemKeyDown(e,t)},className:s,labelClassName:"p-menuitem-text",iconClassName:a,submenuIconClassName:c,element:v,props:this.props}));return e.createElement("li",{key:t.label+"_"+n,role:"none",className:u,style:t.style,onMouseEnter:function(e){return o.onItemMouseEnter(e,t)}},v,h)}},{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 t=this,n=r({"p-submenu-list":!this.props.root,"p-menubar-root-list":this.props.root}),i=this.renderMenu();return e.createElement("ul",{ref:function(e){return t.getElementRef(e)},className:n,role:this.props.root?"menubar":"menu"},i)}}]),h}();y(C,"defaultProps",{model:null,root:!1,className:null,popup:!1,onLeafClick:null,onKeyDown:null,parentActive:!1,mobileActive:!1,forwardRef:null});var I=e.forwardRef((function(t,n){return e.createElement(C,b({forwardRef:n},t))}));function g(){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 E=function(n){f(h,t);var l,a,p=(l=h,a=g(),function(){var e,t=d(l);if(a){var n=d(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return v(this,e)});function h(e){var t;return s(this,h),(t=p.call(this,e)).state={mobileActive:!1},t.toggle=t.toggle.bind(m(t)),t.onLeafClick=t.onLeafClick.bind(m(t)),t}return c(h,[{key:"toggle",value:function(e){var t=this;e.preventDefault(),this.setState((function(e){return{mobileActive:!e.mobileActive}}),(function(){t.state.mobileActive?(o.set("menu",t.rootmenu,u.autoZIndex,u.zIndex.menu),t.bindDocumentClickListener()):(t.unbindDocumentClickListener(),o.clear(t.rootmenu))}))}},{key:"bindDocumentClickListener",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){e.state.mobileActive&&e.isOutsideClicked(t)&&e.setState({mobileActive:!1},(function(){e.unbindDocumentClickListener(),o.clear(e.rootmenu)}))},document.addEventListener("click",this.documentClickListener))}},{key:"isOutsideClicked",value:function(e){return this.rootmenu!==e.target&&!this.rootmenu.contains(e.target)&&this.menubutton!==e.target&&!this.menubutton.contains(e.target)}},{key:"unbindDocumentClickListener",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{key:"onLeafClick",value:function(){var e=this;this.setState({mobileActive:!1},(function(){e.unbindDocumentClickListener(),o.clear(e.rootmenu)}))}},{key:"componentWillUnmount",value:function(){o.clear(this.rootmenu)}},{key:"renderCustomContent",value:function(){return this.props.children?e.createElement("div",{className:"p-menubar-custom"},this.props.children):null}},{key:"renderStartContent",value:function(){if(this.props.start){var t=i.getJSXElement(this.props.start,this.props);return e.createElement("div",{className:"p-menubar-start"},t)}return null}},{key:"renderEndContent",value:function(){if(this.props.end){var t=i.getJSXElement(this.props.end,this.props);return e.createElement("div",{className:"p-menubar-end"},t)}return null}},{key:"renderMenuButton",value:function(){var t=this;return e.createElement("a",{ref:function(e){return t.menubutton=e},href:"#",role:"button",tabIndex:0,className:"p-menubar-button",onClick:this.toggle},e.createElement("i",{className:"pi pi-bars"}))}},{key:"render",value:function(){var t=this,n=r("p-menubar p-component",{"p-menubar-mobile-active":this.state.mobileActive},this.props.className),i=this.renderStartContent(),o=this.renderEndContent(),l=this.renderMenuButton();return e.createElement("div",{id:this.props.id,className:n,style:this.props.style},i,l,e.createElement(I,{ref:function(e){return t.rootmenu=e},model:this.props.model,root:!0,mobileActive:this.state.mobileActive,onLeafClick:this.onLeafClick}),o)}}]),h}();y(E,"defaultProps",{id:null,model:null,style:null,className:null,start:null,end:null});export{E as Menubar};