2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/button"),n=require("primereact/utils"),r=require("primereact/csstransition"),i=require("primereact/portal"),o=require("primereact/tooltip"),l=require("primereact/overlayservice"),s=require("primereact/api");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=a(e),c=a(s);function p(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function d(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 f(e,t,n){return t&&d(e.prototype,t),n&&d(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function h(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 y(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 v(e){return v="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},v(e)}function b(e,t){if(t&&("object"===v(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return h(e)}function k(e){return k=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},k(e)}function O(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function C(){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(t){y(l,e.Component);var r,i,o=(r=l,i=C(),function(){var e,t=k(r);if(i){var n=k(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return b(this,e)});function l(e){var t;return p(this,l),(t=o.call(this,e)).onClick=t.onClick.bind(h(t)),t}return f(l,[{key:"onClick",value:function(e){this.props.menuitem.command&&this.props.menuitem.command({originalEvent:e,item:this.props.menuitem}),this.props.onItemClick&&this.props.onItemClick(e),e.preventDefault()}},{key:"renderSeparator",value:function(){return u.default.createElement("li",{className:"p-menu-separator",role:"separator"})}},{key:"renderMenuitem",value:function(){var e=this,t=this.props.menuitem,r=t.icon,i=t.label,o=t.template,l=t.url,s=t.target,a=n.classNames("p-menuitem-link",{"p-disabled":t.disabled}),c=n.classNames("p-menuitem-icon",r),p=u.default.createElement("a",{href:l||"#",role:"menuitem",className:a,target:s,onClick:this.onClick},r=r&&u.default.createElement("span",{className:c}),i=i&&u.default.createElement("span",{className:"p-menuitem-text"},i));o&&(p=n.ObjectUtils.getJSXElement(o,this.props.menuitem,{onClick:function(t){return e.onClick(t)},className:a,labelClassName:"p-menuitem-text",iconClassName:c,element:p,props:this.props}));return u.default.createElement("li",{className:"p-menuitem",role:"none"},p)}},{key:"renderItem",value:function(){return this.props.menuitem.separator?this.renderSeparator():this.renderMenuitem()}},{key:"render",value:function(){return this.renderItem()}}]),l}();function w(){return w=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},w.apply(this,arguments)}function R(){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}}O(E,"defaultProps",{menuitem:null,onItemClick:null});var S=function(t){y(a,e.Component);var o,l,s=(o=a,l=R(),function(){var e,t=k(o);if(l){var n=k(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return b(this,e)});function a(){return p(this,a),s.apply(this,arguments)}return f(a,[{key:"renderElement",value:function(){var e=n.classNames("p-menu p-menu-overlay p-component",this.props.menuClassName);return u.default.createElement(r.CSSTransition,{nodeRef:this.props.forwardRef,classNames:"p-connected-overlay",in:this.props.in,timeout:{enter:120,exit:100},options:this.props.transitionOptions,unmountOnExit:!0,onEnter:this.props.onEnter,onEntered:this.props.onEntered,onExit:this.props.onExit,onExited:this.props.onExited},u.default.createElement("div",{ref:this.props.forwardRef,className:e,style:this.props.menuStyle,id:this.props.id,onClick:this.onClick},u.default.createElement("ul",{className:"p-menu-list p-reset",role:"menu"},this.props.children)))}},{key:"render",value:function(){var e=this.renderElement();return u.default.createElement(i.Portal,{element:e,appendTo:this.props.appendTo})}}]),a}();O(S,"defaultProps",{appendTo:null,menuStyle:null,menuClassName:null,id:null,onClick:null});var x=u.default.forwardRef((function(e,t){return u.default.createElement(S,w({forwardRef:t},e))}));function L(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function N(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?L(Object(n),!0).forEach((function(t){O(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):L(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function P(){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 j=function(r){y(d,e.Component);var i,s,a=(i=d,s=P(),function(){var e,t=k(i);if(s){var n=k(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return b(this,e)});function d(e){var t;return p(this,d),(t=a.call(this,e)).state={id:e.id,overlayVisible:!1},t.onDropdownButtonClick=t.onDropdownButtonClick.bind(h(t)),t.onItemClick=t.onItemClick.bind(h(t)),t.onOverlayEnter=t.onOverlayEnter.bind(h(t)),t.onOverlayEntered=t.onOverlayEntered.bind(h(t)),t.onOverlayExit=t.onOverlayExit.bind(h(t)),t.onOverlayExited=t.onOverlayExited.bind(h(t)),t.onPanelClick=t.onPanelClick.bind(h(t)),t.overlayRef=u.default.createRef(),t}return f(d,[{key:"onPanelClick",value:function(e){l.OverlayService.emit("overlay-click",{originalEvent:e,target:this.container})}},{key:"onDropdownButtonClick",value:function(){this.state.overlayVisible?this.hide():this.show()}},{key:"onItemClick",value:function(){this.hide()}},{key:"show",value:function(){this.setState({overlayVisible:!0})}},{key:"hide",value:function(){this.setState({overlayVisible:!1})}},{key:"onOverlayEnter",value:function(){n.ZIndexUtils.set("overlay",this.overlayRef.current,c.default.autoZIndex,c.default.zIndex.overlay),this.alignOverlay()}},{key:"onOverlayEntered",value:function(){this.bindDocumentClickListener(),this.bindScrollListener(),this.bindResizeListener(),this.props.onShow&&this.props.onShow()}},{key:"onOverlayExit",value:function(){this.unbindDocumentClickListener(),this.unbindScrollListener(),this.unbindResizeListener()}},{key:"onOverlayExited",value:function(){n.ZIndexUtils.clear(this.overlayRef.current),this.props.onHide&&this.props.onHide()}},{key:"alignOverlay",value:function(){n.DomHandler.alignOverlay(this.overlayRef.current,this.defaultButton.parentElement,this.props.appendTo||c.default.appendTo)}},{key:"bindDocumentClickListener",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){e.state.overlayVisible&&e.isOutsideClicked(t)&&e.hide()},document.addEventListener("click",this.documentClickListener))}},{key:"bindScrollListener",value:function(){var e=this;this.scrollHandler||(this.scrollHandler=new n.ConnectedOverlayScrollHandler(this.container,(function(){e.state.overlayVisible&&e.hide()}))),this.scrollHandler.bindScrollListener()}},{key:"unbindScrollListener",value:function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()}},{key:"bindResizeListener",value:function(){var e=this;this.resizeListener||(this.resizeListener=function(){e.state.overlayVisible&&!n.DomHandler.isTouchDevice()&&e.hide()},window.addEventListener("resize",this.resizeListener))}},{key:"unbindResizeListener",value:function(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)}},{key:"isOutsideClicked",value:function(e){return this.container&&this.overlayRef&&this.overlayRef.current&&!this.overlayRef.current.contains(e.target)}},{key:"unbindDocumentClickListener",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{key:"componentDidMount",value:function(){this.state.id||this.setState({id:n.UniqueComponentId()}),this.props.tooltip&&this.renderTooltip()}},{key:"componentDidUpdate",value:function(e){e.tooltip===this.props.tooltip&&e.tooltipOptions===this.props.tooltipOptions||(this.tooltip?this.tooltip.update(N({content:this.props.tooltip},this.props.tooltipOptions||{})):this.renderTooltip())}},{key:"componentWillUnmount",value:function(){this.unbindDocumentClickListener(),this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.tooltip&&(this.tooltip.destroy(),this.tooltip=null),n.ZIndexUtils.clear(this.overlayRef.current)}},{key:"renderTooltip",value:function(){this.tooltip=o.tip({target:this.container,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"renderItems",value:function(){var e=this;return this.props.model?this.props.model.map((function(t,n){return u.default.createElement(E,{menuitem:t,key:n,onItemClick:e.onItemClick})})):null}},{key:"render",value:function(){var e=this,r=n.classNames("p-splitbutton p-component",this.props.className,{"p-disabled":this.props.disabled}),i=n.classNames("p-splitbutton-defaultbutton",this.props.buttonClassName),o=n.classNames("p-splitbutton-menubutton",this.props.menuButtonClassName),l=this.renderItems(),s=this.props.buttonTemplate?n.ObjectUtils.getJSXElement(this.props.buttonTemplate,this.props):null;return u.default.createElement("div",{id:this.state.id,className:r,style:this.props.style,ref:function(t){return e.container=t}},u.default.createElement(t.Button,{ref:function(t){return e.defaultButton=t},type:"button",className:i,icon:this.props.icon,label:this.props.label,onClick:this.props.onClick,disabled:this.props.disabled,tabIndex:this.props.tabIndex},s),u.default.createElement(t.Button,{type:"button",className:o,icon:this.props.dropdownIcon,onClick:this.onDropdownButtonClick,disabled:this.props.disabled,"aria-expanded":this.state.overlayVisible,"aria-haspopup":!0,"aria-owns":this.state.id+"_overlay"}),u.default.createElement(x,{ref:this.overlayRef,appendTo:this.props.appendTo,id:this.state.id+"_overlay",menuStyle:this.props.menuStyle,menuClassName:this.props.menuClassName,onClick:this.onPanelClick,in:this.state.overlayVisible,onEnter:this.onOverlayEnter,onEntered:this.onOverlayEntered,onExit:this.onOverlayExit,onExited:this.onOverlayExited,transitionOptions:this.props.transitionOptions},l))}}]),d}();O(j,"defaultProps",{id:null,label:null,icon:null,model:null,disabled:null,style:null,className:null,buttonClassName:null,menuStyle:null,menuClassName:null,menuButtonClassName:null,tabIndex:null,appendTo:null,tooltip:null,tooltipOptions:null,buttonTemplate:null,transitionOptions:null,dropdownIcon:"pi pi-chevron-down",onClick:null,onShow:null,onHide:null}),exports.SplitButton=j;
|