2 lines
10 KiB
JavaScript
2 lines
10 KiB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/csstransition"),i=require("primereact/overlayservice"),r=require("primereact/portal"),s=require("primereact/api");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=o(e),l=o(s);function u(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}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 d(e,t,n){return t&&p(e.prototype,t),n&&p(e,n),Object.defineProperty(e,"prototype",{writable:!1}),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 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 u(e)}function b(e){return b=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},b(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 k(e){var t=E();return function(){var n,i=b(e);if(t){var r=b(this).constructor;n=Reflect.construct(i,arguments,r)}else n=i.apply(this,arguments);return v(this,n)}}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 w=function(n){f(r,e.Component);var i=k(r);function r(e){var t;return c(this,r),(t=i.call(this,e)).state={activeItem:null},t}return d(r,[{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({activeItem:t}),this.props.onForward()))}},{key:"renderSeparator",value:function(e){return a.default.createElement("li",{key:"separator_"+e,className:"p-menu-separator"})}},{key:"renderSubmenu",value:function(e){return e.items?a.default.createElement(r,{model:e.items,index:this.props.index+1,menuWidth:this.props.menuWidth,effectDuration:this.props.effectDuration,onForward:this.props.onForward,parentActive:e===this.state.activeItem}):null}},{key:"renderMenuitem",value:function(e,n){var i=this,r=this.state.activeItem===e,s=t.classNames("p-menuitem",{"p-menuitem-active":r,"p-disabled":e.disabled},e.className),o=t.classNames("p-menuitem-icon",e.icon),l="p-submenu-icon pi pi-fw pi-angle-right",u=e.icon&&a.default.createElement("span",{className:o}),c=e.label&&a.default.createElement("span",{className:"p-menuitem-text"},e.label),p=e.items&&a.default.createElement("span",{className:l}),d=this.renderSubmenu(e),m=a.default.createElement("a",{href:e.url||"#",className:"p-menuitem-link",target:e.target,onClick:function(t){return i.onItemClick(t,e,n)},"aria-disabled":e.disabled},u,c,p);e.template&&(m=t.ObjectUtils.getJSXElement(e.template,e,{onClick:function(t){return i.onItemClick(t,e,n)},className:"p-menuitem-link",labelClassName:"p-menuitem-text",iconClassName:o,submenuIconClassName:l,element:m,props:this.props,active:r}));return a.default.createElement("li",{key:e.label+"_"+n,className:s,style:e.style},m,d)}},{key:"renderItem",value:function(e,t){return e.separator?this.renderSeparator(t):this.renderMenuitem(e,t)}},{key:"renderItems",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=t.classNames({"p-slidemenu-rootlist":this.props.root,"p-submenu-list":!this.props.root,"p-active-submenu":this.props.parentActive}),n={width:this.props.menuWidth+"px",left:this.props.root?-1*this.props.level*this.props.menuWidth+"px":this.props.menuWidth+"px",transitionProperty:this.props.root?"left":"none",transitionDuration:this.props.effectDuration+"ms",transitionTimingFunction:this.props.easing},i=this.renderItems();return a.default.createElement("ul",{className:e,style:n},i)}}]),r}();y(w,"defaultProps",{model:null,level:0,easing:"ease-out",effectDuration:250,menuWidth:190,parentActive:!1,onForward:null});var g=function(s){f(p,e.Component);var o=k(p);function p(e){var t;return c(this,p),(t=o.call(this,e)).state={level:0,visible:!1},t.navigateBack=t.navigateBack.bind(u(t)),t.navigateForward=t.navigateForward.bind(u(t)),t.onEnter=t.onEnter.bind(u(t)),t.onEntered=t.onEntered.bind(u(t)),t.onExit=t.onExit.bind(u(t)),t.onExited=t.onExited.bind(u(t)),t.onPanelClick=t.onPanelClick.bind(u(t)),t.menuRef=a.default.createRef(),t}return d(p,[{key:"onPanelClick",value:function(e){this.props.popup&&i.OverlayService.emit("overlay-click",{originalEvent:e,target:this.target})}},{key:"navigateForward",value:function(){this.setState({level:this.state.level+1})}},{key:"navigateBack",value:function(){this.setState({level:this.state.level-1})}},{key:"renderBackward",value:function(){var e=this,n=t.classNames("p-slidemenu-backward",{"p-hidden":0===this.state.level});return a.default.createElement("div",{ref:function(t){return e.backward=t},className:n,onClick:this.navigateBack},a.default.createElement("span",{className:"p-slidemenu-backward-icon pi pi-fw pi-chevron-left"}),a.default.createElement("span",null,this.props.backLabel))}},{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,l.default.autoZIndex,this.props.baseZIndex||l.default.zIndex.menu),t.DomHandler.absolutePosition(this.menuRef.current,this.target)}},{key:"onEntered",value:function(){this.bindDocumentClickListener(),this.bindDocumentResizeListener(),this.bindScrollListener()}},{key:"onExit",value:function(){this.target=null,this.unbindDocumentClickListener(),this.unbindDocumentResizeListener(),this.unbindScrollListener()}},{key:"onExited",value:function(){t.ZIndexUtils.clear(this.menuRef.current),this.setState({level:0})}},{key:"bindDocumentClickListener",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){e.state.visible&&e.isOutsideClicked(t)&&e.hide(t)},document.addEventListener("click",this.documentClickListener))}},{key:"isOutsideClicked",value:function(e){return this.menuRef&&this.menuRef.current&&!(this.menuRef.current.isSameNode(e.target)||this.menuRef.current.contains(e.target))}},{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:"unbindDocumentClickListener",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{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:"componentDidUpdate",value:function(e,t){this.props.model!==e.model&&this.setState({level:0})}},{key:"componentWillUnmount",value:function(){this.unbindDocumentClickListener(),this.unbindDocumentResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),t.ZIndexUtils.clear(this.menuRef.current)}},{key:"renderElement",value:function(){var e=this,i=t.classNames("p-slidemenu p-component",{"p-slidemenu-overlay":this.props.popup},this.props.className),r=this.renderBackward();return a.default.createElement(n.CSSTransition,{nodeRef:this.menuRef,classNames:"p-connected-overlay",in:!this.props.popup||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},a.default.createElement("div",{ref:this.menuRef,id:this.props.id,className:i,style:this.props.style,onClick:this.onPanelClick},a.default.createElement("div",{className:"p-slidemenu-wrapper",style:{height:this.props.viewportHeight+"px"}},a.default.createElement("div",{className:"p-slidemenu-content",ref:function(t){return e.slideMenuContent=t}},a.default.createElement(w,{model:this.props.model,root:!0,index:0,menuWidth:this.props.menuWidth,effectDuration:this.props.effectDuration,level:this.state.level,parentActive:0===this.state.level,onForward:this.navigateForward})),r)))}},{key:"render",value:function(){var e=this.renderElement();return this.props.popup?a.default.createElement(r.Portal,{element:e,appendTo:this.props.appendTo}):e}}]),p}();y(g,"defaultProps",{id:null,model:null,popup:!1,style:null,className:null,easing:"ease-out",effectDuration:250,backLabel:"Back",menuWidth:190,viewportHeight:175,autoZIndex:!0,baseZIndex:0,appendTo:null,transitionOptions:null,onShow:null,onHide:null}),exports.SlideMenu=g,exports.SlideMenuSub=w;
|