2 lines
9.1 KiB
JavaScript
2 lines
9.1 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.megamenu=function(e,t,n,a){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=r(t);function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function u(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){return s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},s(e,t)}function c(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&&s(e,t)}function m(e){return m="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},m(e)}function p(e,t){if(t&&("object"===m(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return u(e)}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}function d(){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 v,h,y,b=function(e){c(y,e);var t,r,s,m,v,h=(t=y,r=d(),function(){var e,n=f(t);if(r){var a=f(this).constructor;e=Reflect.construct(n,arguments,a)}else e=n.apply(this,arguments);return p(this,e)});function y(e){var t;return l(this,y),(t=h.call(this,e)).state={activeItem:null},t.onLeafClick=t.onLeafClick.bind(u(t)),t}return s=y,(m=[{key:"onLeafClick",value:function(e,t){t.disabled?e.preventDefault():(t.url||e.preventDefault(),t.command&&t.command({originalEvent:e,item:t}),this.setState({activeItem:null}))}},{key:"onCategoryMouseEnter",value:function(e,t){t.disabled?e.preventDefault():this.state.activeItem&&this.setState({activeItem:t})}},{key:"onCategoryClick",value:function(e,t){t.disabled||(t.url||e.preventDefault(),t.command&&t.command({originalEvent:e,item:this.props.item}),t.items&&this.setState(this.state.activeItem&&this.state.activeItem===t?{activeItem:null}:{activeItem:t})),e.preventDefault()}},{key:"onCategoryKeyDown",value:function(e,t){var n=e.currentTarget.parentElement;switch(e.which){case 40:this.isHorizontal()?this.expandMenu(t):this.navigateToNextItem(n),e.preventDefault();break;case 38:this.isVertical()?this.navigateToPrevItem(n):t.items&&t===this.state.activeItem&&this.collapseMenu(),e.preventDefault();break;case 39:this.isHorizontal()?this.navigateToNextItem(n):this.expandMenu(t),e.preventDefault();break;case 37:this.isHorizontal()?this.navigateToPrevItem(n):t.items&&t===this.state.activeItem&&this.collapseMenu(),e.preventDefault()}}},{key:"expandMenu",value:function(e){e.items&&this.setState({activeItem:e})}},{key:"collapseMenu",value:function(e){this.setState({activeItem:null})}},{key:"findNextItem",value:function(e){var t=e.nextElementSibling;return t?n.DomHandler.hasClass(t,"p-disabled")||!n.DomHandler.hasClass(t,"p-menuitem")?this.findNextItem(t):t:null}},{key:"findPrevItem",value:function(e){var t=e.previousElementSibling;return t?n.DomHandler.hasClass(t,"p-disabled")||!n.DomHandler.hasClass(t,"p-menuitem")?this.findPrevItem(t):t:null}},{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:"isHorizontal",value:function(){return"horizontal"===this.props.orientation}},{key:"isVertical",value:function(){return"vertical"===this.props.orientation}},{key:"getColumnClassName",value:function(e){var t;switch(e.items?e.items.length:0){case 2:t="p-megamenu-col-6";break;case 3:t="p-megamenu-col-4";break;case 4:t="p-megamenu-col-3";break;case 6:t="p-megamenu-col-2";break;default:t="p-megamenu-col-12"}return t}},{key:"componentDidMount",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){e.container&&!e.container.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:"renderSeparator",value:function(e){return i.default.createElement("li",{key:"separator_"+e,className:"p-menu-separator",role:"separator"})}},{key:"renderSubmenuIcon",value:function(e){if(e.items){var t=n.classNames("p-submenu-icon pi",{"pi-angle-down":this.isHorizontal(),"pi-angle-right":this.isVertical()});return i.default.createElement("span",{className:t})}return null}},{key:"renderSubmenuItem",value:function(e,t){var r=this;if(e.separator)return this.renderSeparator(t);var l=n.classNames("p-menuitem",e.className),o=n.classNames("p-menuitem-link",{"p-disabled":e.disabled}),u=n.classNames(e.icon,"p-menuitem-icon"),s=i.default.createElement("a",{href:e.url||"#",className:o,target:e.target,onClick:function(t){return r.onLeafClick(t,e)},role:"menuitem","aria-disabled":e.disabled},e.icon&&i.default.createElement("span",{className:u}),e.label&&i.default.createElement("span",{className:"p-menuitem-text"},e.label),i.default.createElement(a.Ripple,null));return e.template&&(s=n.ObjectUtils.getJSXElement(e.template,e,{onClick:function(t){return r.onLeafClick(t,e)},className:o,labelClassName:"p-menuitem-text",iconClassName:u,element:s,props:this.props})),i.default.createElement("li",{key:e.label+"_"+t,className:l,style:e.style,role:"none"},s)}},{key:"renderSubmenu",value:function(e){var t=this,a=n.classNames("p-megamenu-submenu-header",{"p-disabled":e.disabled},e.className),r=e.items.map((function(e,n){return t.renderSubmenuItem(e,n)}));return i.default.createElement(i.default.Fragment,{key:e.label},i.default.createElement("li",{className:a,style:e.style,role:"presentation","aria-disabled":e.disabled},e.label),r)}},{key:"renderSubmenus",value:function(e){var t=this;return e.map((function(e,n){return t.renderSubmenu(e,n)}))}},{key:"renderColumn",value:function(e,t,n,a){var r=this.renderSubmenus(t);return i.default.createElement("div",{key:e.label+"_column_"+n,className:a},i.default.createElement("ul",{className:"p-megamenu-submenu",role:"menu"},r))}},{key:"renderColumns",value:function(e){var t=this;if(e.items){var n=this.getColumnClassName(e);return e.items.map((function(a,r){return t.renderColumn(e,a,r,n)}))}return null}},{key:"renderCategoryPanel",value:function(e){if(e.items){var t=this.renderColumns(e);return i.default.createElement("div",{className:"p-megamenu-panel"},i.default.createElement("div",{className:"p-megamenu-grid"},t))}return null}},{key:"renderCategory",value:function(e,t){var r=this,l=n.classNames("p-menuitem",{"p-menuitem-active":e===this.state.activeItem},e.className),o=n.classNames("p-menuitem-link",{"p-disabled":e.disabled}),u=n.classNames("p-menuitem-icon",e.icon),s=e.icon&&i.default.createElement("span",{className:u}),c=e.label&&i.default.createElement("span",{className:"p-menuitem-text"},e.label),m=e.template?n.ObjectUtils.getJSXElement(e.template,e):null,p=this.renderSubmenuIcon(e),f=this.renderCategoryPanel(e);return i.default.createElement("li",{key:e.label+"_"+t,className:l,style:e.style,onMouseEnter:function(t){return r.onCategoryMouseEnter(t,e)},role:"none"},i.default.createElement("a",{href:e.url||"#",className:o,target:e.target,onClick:function(t){return r.onCategoryClick(t,e)},onKeyDown:function(t){return r.onCategoryKeyDown(t,e)},role:"menuitem","aria-haspopup":null!=e.items},s,c,m,p,i.default.createElement(a.Ripple,null)),f)}},{key:"renderMenu",value:function(){var e=this;return this.props.model?this.props.model.map((function(t,n){return e.renderCategory(t,n,!0)})):null}},{key:"renderCustomContent",value:function(){return this.props.children?i.default.createElement("div",{className:"p-megamenu-custom"},this.props.children):null}},{key:"render",value:function(){var e=this,t=n.classNames("p-megamenu p-component",{"p-megamenu-horizontal":"horizontal"===this.props.orientation,"p-megamenu-vertical":"vertical"===this.props.orientation},this.props.className),a=this.renderMenu(),r=this.renderCustomContent();return i.default.createElement("div",{ref:function(t){return e.container=t},id:this.props.id,className:t,style:this.props.style},i.default.createElement("ul",{className:"p-megamenu-root-list",role:"menubar"},a),r)}}])&&o(s.prototype,m),v&&o(s,v),Object.defineProperty(s,"prototype",{writable:!1}),y}(t.Component);return y={id:null,model:null,style:null,className:null,orientation:"horizontal"},(h="defaultProps")in(v=b)?Object.defineProperty(v,h,{value:y,enumerable:!0,configurable:!0,writable:!0}):v[h]=y,e.MegaMenu=b,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.utils,primereact.ripple);
|