2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/ripple"),r=require("primereact/api");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=i(e),l=i(r);function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(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 s(e,t,n){return t&&u(e.prototype,t),n&&u(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function c(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function m(e,t){return m=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},m(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&&m(e,t)}function p(e){return p="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},p(e)}function d(e,t){if(t&&("object"===p(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return c(e)}function h(e){return h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},h(e)}function v(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 y(){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 k=function(r){f(m,e.Component);var i,l,u=(i=m,l=y(),function(){var e,t=h(i);if(l){var n=h(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return d(this,e)});function m(e){var t;return a(this,m),(t=u.call(this,e)).state={activeItem:null},t.onLeafClick=t.onLeafClick.bind(c(t)),t.onChildItemKeyDown=t.onChildItemKeyDown.bind(c(t)),t}return s(m,[{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 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:"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(e){return o.default.createElement("li",{key:"separator_"+e,className:"p-menu-separator",role:"separator"})}},{key:"renderSubmenu",value:function(e){return e.items?o.default.createElement(C,{model:e.items,mobileActive:this.props.mobileActive,onLeafClick:this.onLeafClick,onKeyDown:this.onChildItemKeyDown,parentActive:e===this.state.activeItem}):null}},{key:"renderMenuitem",value:function(e,r){var i=this,l=t.classNames("p-menuitem",{"p-menuitem-active":this.state.activeItem===e},e.className),a=t.classNames("p-menuitem-link",{"p-disabled":e.disabled}),u=t.classNames("p-menuitem-icon",e.icon),s=t.classNames("p-submenu-icon pi",{"pi-angle-down":this.props.root,"pi-angle-right":!this.props.root}),c=e.icon&&o.default.createElement("span",{className:u}),m=e.label&&o.default.createElement("span",{className:"p-menuitem-text"},e.label),f=e.items&&o.default.createElement("span",{className:s}),p=this.renderSubmenu(e),d=o.default.createElement("a",{href:e.url||"#",role:"menuitem",className:a,target:e.target,"aria-haspopup":null!=e.items,onClick:function(t){return i.onItemClick(t,e)},onKeyDown:function(t){return i.onItemKeyDown(t,e)}},c,m,f,o.default.createElement(n.Ripple,null));e.template&&(d=t.ObjectUtils.getJSXElement(e.template,e,{onClick:function(t){return i.onItemClick(t,e)},onKeyDown:function(t){return i.onItemKeyDown(t,e)},className:a,labelClassName:"p-menuitem-text",iconClassName:u,submenuIconClassName:s,element:d,props:this.props}));return o.default.createElement("li",{key:e.label+"_"+r,role:"none",className:l,style:e.style,onMouseEnter:function(t){return i.onItemMouseEnter(t,e)}},d,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=this,n=t.classNames({"p-submenu-list":!this.props.root,"p-menubar-root-list":this.props.root}),r=this.renderMenu();return o.default.createElement("ul",{ref:function(t){return e.getElementRef(t)},className:n,role:this.props.root?"menubar":"menu"},r)}}]),m}();v(k,"defaultProps",{model:null,root:!1,className:null,popup:!1,onLeafClick:null,onKeyDown:null,parentActive:!1,mobileActive:!1,forwardRef:null});var C=o.default.forwardRef((function(e,t){return o.default.createElement(k,b({forwardRef:t},e))}));function I(){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 g=function(n){f(m,e.Component);var r,i,u=(r=m,i=I(),function(){var e,t=h(r);if(i){var n=h(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return d(this,e)});function m(e){var t;return a(this,m),(t=u.call(this,e)).state={mobileActive:!1},t.toggle=t.toggle.bind(c(t)),t.onLeafClick=t.onLeafClick.bind(c(t)),t}return s(m,[{key:"toggle",value:function(e){var n=this;e.preventDefault(),this.setState((function(e){return{mobileActive:!e.mobileActive}}),(function(){n.state.mobileActive?(t.ZIndexUtils.set("menu",n.rootmenu,l.default.autoZIndex,l.default.zIndex.menu),n.bindDocumentClickListener()):(n.unbindDocumentClickListener(),t.ZIndexUtils.clear(n.rootmenu))}))}},{key:"bindDocumentClickListener",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(n){e.state.mobileActive&&e.isOutsideClicked(n)&&e.setState({mobileActive:!1},(function(){e.unbindDocumentClickListener(),t.ZIndexUtils.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(),t.ZIndexUtils.clear(e.rootmenu)}))}},{key:"componentWillUnmount",value:function(){t.ZIndexUtils.clear(this.rootmenu)}},{key:"renderCustomContent",value:function(){return this.props.children?o.default.createElement("div",{className:"p-menubar-custom"},this.props.children):null}},{key:"renderStartContent",value:function(){if(this.props.start){var e=t.ObjectUtils.getJSXElement(this.props.start,this.props);return o.default.createElement("div",{className:"p-menubar-start"},e)}return null}},{key:"renderEndContent",value:function(){if(this.props.end){var e=t.ObjectUtils.getJSXElement(this.props.end,this.props);return o.default.createElement("div",{className:"p-menubar-end"},e)}return null}},{key:"renderMenuButton",value:function(){var e=this;return o.default.createElement("a",{ref:function(t){return e.menubutton=t},href:"#",role:"button",tabIndex:0,className:"p-menubar-button",onClick:this.toggle},o.default.createElement("i",{className:"pi pi-bars"}))}},{key:"render",value:function(){var e=this,n=t.classNames("p-menubar p-component",{"p-menubar-mobile-active":this.state.mobileActive},this.props.className),r=this.renderStartContent(),i=this.renderEndContent(),l=this.renderMenuButton();return o.default.createElement("div",{id:this.props.id,className:n,style:this.props.style},r,l,o.default.createElement(C,{ref:function(t){return e.rootmenu=t},model:this.props.model,root:!0,mobileActive:this.state.mobileActive,onLeafClick:this.onLeafClick}),i)}}]),m}();v(g,"defaultProps",{id:null,model:null,style:null,className:null,start:null,end:null}),exports.Menubar=g;
|