2 lines
9.2 KiB
JavaScript
2 lines
9.2 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.panelmenu=function(e,t,n,r){"use strict";function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=a(t);function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function s(e){if(Array.isArray(e))return l(e)}function o(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function u(e,t){if(e){if("string"==typeof e)return l(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?l(e,t):void 0}}function c(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function m(e){return s(e)||o(e)||u(e)||c()}function p(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function f(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 d(e,t,n){return t&&f(e.prototype,t),n&&f(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function h(e,t){return h=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},h(e,t)}function v(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&&h(e,t)}function y(e){return y="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},y(e)}function b(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function N(e,t){if(t&&("object"===y(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return b(e)}function I(e){return I=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},I(e)}function g(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,r=I(e);if(t){var a=I(this).constructor;n=Reflect.construct(r,arguments,a)}else n=r.apply(this,arguments);return N(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 S=function(e){v(a,e);var t=E(a);function a(e){var n;return p(this,a),(n=t.call(this,e)).state={activeItem:n.findActiveItem()},n}return d(a,[{key:"onItemClick",value:function(e,t){if(t.disabled)e.preventDefault();else{t.url||e.preventDefault(),t.command&&t.command({originalEvent:e,item:t});var n=this.state.activeItem;this.isItemActive(t)?(t.expanded=!1,this.setState({activeItem:this.props.multiple?n.filter((function(e){return e!==t})):null})):(!this.props.multiple&&n&&(n.expanded=!1),t.expanded=!0,this.setState({activeItem:this.props.multiple?[].concat(m(n||[]),[t]):t}))}}},{key:"findActiveItem",value:function(){if(this.props.model){if(this.props.multiple)return this.props.model.filter((function(e){return e.expanded}));var e=null;return this.props.model.forEach((function(t){t.expanded&&(e?t.expanded=!1:e=t)})),e}return null}},{key:"isItemActive",value:function(e){return this.state.activeItem&&(this.props.multiple?this.state.activeItem.indexOf(e)>-1:this.state.activeItem===e)}},{key:"renderSeparator",value:function(e){return i.default.createElement("li",{key:"separator_"+e,className:"p-menu-separator"})}},{key:"renderSubmenu",value:function(e,t){var l=n.classNames("p-toggleable-content",{"p-toggleable-content-collapsed":!t}),s=i.default.createRef();return e.items?i.default.createElement(r.CSSTransition,{nodeRef:s,classNames:"p-toggleable-content",timeout:{enter:1e3,exit:450},in:t,unmountOnExit:!0},i.default.createElement("div",{ref:s,className:l},i.default.createElement(a,{model:e.items,multiple:this.props.multiple}))):null}},{key:"renderMenuitem",value:function(e,t){var r=this,a=this.isItemActive(e),l=n.classNames("p-menuitem",e.className),s=n.classNames("p-menuitem-link",{"p-disabled":e.disabled}),o=n.classNames("p-menuitem-icon",e.icon),u=n.classNames("p-panelmenu-icon pi pi-fw",{"pi-angle-right":!a,"pi-angle-down":a}),c=e.icon&&i.default.createElement("span",{className:o}),m=e.label&&i.default.createElement("span",{className:"p-menuitem-text"},e.label),p=e.items&&i.default.createElement("span",{className:u}),f=this.renderSubmenu(e,a),d=i.default.createElement("a",{href:e.url||"#",className:s,target:e.target,onClick:function(n){return r.onItemClick(n,e,t)},role:"menuitem","aria-disabled":e.disabled},p,c,m);e.template&&(d=n.ObjectUtils.getJSXElement(e.template,e,{onClick:function(n){return r.onItemClick(n,e,t)},className:s,labelClassName:"p-menuitem-text",iconClassName:o,submenuIconClassName:u,element:d,props:this.props,leaf:!e.items,active:a}));return i.default.createElement("li",{key:e.label+"_"+t,className:l,style:e.style,role:"none"},d,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=n.classNames("p-submenu-list",this.props.className),t=this.renderMenu();return i.default.createElement("ul",{className:e,role:"tree"},t)}}]),a}(t.Component);g(S,"defaultProps",{model:null,multiple:!1});var x=function(e){v(a,e);var t=E(a);function a(e){var n;return p(this,a),(n=t.call(this,e)).state={id:e.id,activeItem:n.findActiveItem()},n}return d(a,[{key:"onItemClick",value:function(e,t){if(t.disabled)e.preventDefault();else{t.url||e.preventDefault(),t.command&&t.command({originalEvent:e,item:t});var n=this.state.activeItem;this.isItemActive(t)?(t.expanded=!1,this.setState({activeItem:this.props.multiple?n.filter((function(e){return e!==t})):null})):(!this.props.multiple&&n&&(n.expanded=!1),t.expanded=!0,this.setState({activeItem:this.props.multiple?[].concat(m(n||[]),[t]):t}))}}},{key:"findActiveItem",value:function(){if(this.props.model){if(this.props.multiple)return this.props.model.filter((function(e){return e.expanded}));var e=null;return this.props.model.forEach((function(t){t.expanded&&(e?t.expanded=!1:e=t)})),e}return null}},{key:"isItemActive",value:function(e){return this.state.activeItem&&(this.props.multiple?this.state.activeItem.indexOf(e)>-1:this.state.activeItem===e)}},{key:"componentDidMount",value:function(){this.state.id||this.setState({id:n.UniqueComponentId()})}},{key:"renderPanel",value:function(e,t){var a=this,l=this.isItemActive(e),s=n.classNames("p-panelmenu-panel",e.className),o=n.classNames("p-component p-panelmenu-header",{"p-highlight":l,"p-disabled":e.disabled}),u=n.classNames("p-panelmenu-icon pi",{"pi-chevron-right":!l," pi-chevron-down":l}),c=n.classNames("p-menuitem-icon",e.icon),m=e.items&&i.default.createElement("span",{className:u}),p=e.icon&&i.default.createElement("span",{className:c}),f=e.label&&i.default.createElement("span",{className:"p-menuitem-text"},e.label),d=n.classNames("p-toggleable-content",{"p-toggleable-content-collapsed":!l}),h=i.default.createRef(),v=i.default.createElement("a",{href:e.url||"#",className:"p-panelmenu-header-link",onClick:function(t){return a.onItemClick(t,e)},"aria-expanded":l,id:this.state.id+"_header","aria-controls":this.state.id+"content","aria-disabled":e.disabled},m,p,f);e.template&&(v=n.ObjectUtils.getJSXElement(e.template,e,{onClick:function(t){return a.onItemClick(t,e)},className:"p-panelmenu-header-link",labelClassName:"p-menuitem-text",submenuIconClassName:u,iconClassName:c,element:v,props:this.props,leaf:!e.items,active:l}));return i.default.createElement("div",{key:e.label+"_"+t,className:s,style:e.style},i.default.createElement("div",{className:o,style:e.style},v),i.default.createElement(r.CSSTransition,{nodeRef:h,classNames:"p-toggleable-content",timeout:{enter:1e3,exit:450},in:l,unmountOnExit:!0,options:this.props.transitionOptions},i.default.createElement("div",{ref:h,className:d,role:"region",id:this.state.id+"_content","aria-labelledby":this.state.id+"_header"},i.default.createElement("div",{className:"p-panelmenu-content"},i.default.createElement(S,{model:e.items,className:"p-panelmenu-root-submenu",multiple:this.props.multiple})))))}},{key:"renderPanels",value:function(){var e=this;return this.props.model?this.props.model.map((function(t,n){return e.renderPanel(t,n)})):null}},{key:"render",value:function(){var e=n.classNames("p-panelmenu p-component",this.props.className),t=this.renderPanels();return i.default.createElement("div",{id:this.props.id,className:e,style:this.props.style},t)}}]),a}(t.Component);return g(x,"defaultProps",{id:null,model:null,style:null,className:null,multiple:!1,transitionOptions:null}),e.PanelMenu=x,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.utils,primereact.csstransition);
|