2 lines
6.9 KiB
JavaScript
2 lines
6.9 KiB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/ripple"),r=require("react-transition-group"),o=require("primereact/csstransition");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=s(e);function a(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 l(e){if(Array.isArray(e))return a(e)}function u(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function c(e,t){if(e){if("string"==typeof e)return a(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)?a(e,t):void 0}}function f(){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 p(e){return l(e)||u(e)||c(e)||f()}function m(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function y(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 h(e,t,n){return t&&y(e.prototype,t),n&&y(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function d(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function v(e,t){return v=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},v(e,t)}function b(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&&v(e,t)}function g(e){return g="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},g(e)}function C(e,t){if(t&&("object"===g(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return d(e)}function k(e){return k=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},k(e)}function w(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function O(){return O=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},O.apply(this,arguments)}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 R=function(r){b(l,e.Component);var o,s,a=(o=l,s=E(),function(){var e,t=k(o);if(s){var n=k(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return C(this,e)});function l(e){var t;return m(this,l),(t=a.call(this,e)).onClick=t.onClick.bind(d(t)),t.onClose=t.onClose.bind(d(t)),t}return h(l,[{key:"componentDidMount",value:function(){var e=this;this.props.message.sticky||(this.timeout=setTimeout((function(){e.onClose(null)}),this.props.message.life||3e3))}},{key:"componentWillUnmount",value:function(){this.timeout&&clearTimeout(this.timeout)}},{key:"onClose",value:function(e){this.timeout&&clearTimeout(this.timeout),this.props.onClose&&this.props.onClose(this.props.message),e&&(e.preventDefault(),e.stopPropagation())}},{key:"onClick",value:function(){this.props.onClick&&this.props.onClick(this.props.message)}},{key:"renderCloseIcon",value:function(){return!1!==this.props.message.closable?i.default.createElement("button",{type:"button",className:"p-message-close p-link",onClick:this.onClose},i.default.createElement("i",{className:"p-message-close-icon pi pi-times"}),i.default.createElement(n.Ripple,null)):null}},{key:"renderMessage",value:function(){if(this.props.message){var e=this.props.message,n=e.severity,r=e.content,o=e.summary,s=e.detail,a=t.classNames("p-message-icon pi ",{"pi-info-circle":"info"===n,"pi-check":"success"===n,"pi-exclamation-triangle":"warn"===n,"pi-times-circle":"error"===n});return r||i.default.createElement(i.default.Fragment,null,i.default.createElement("span",{className:a}),i.default.createElement("span",{className:"p-message-summary"},o),i.default.createElement("span",{className:"p-message-detail"},s))}return null}},{key:"render",value:function(){var e="p-message p-component p-message-"+this.props.message.severity,t=this.renderCloseIcon(),n=this.renderMessage();return i.default.createElement("div",{ref:this.props.forwardRef,className:e,onClick:this.onClick},i.default.createElement("div",{className:"p-message-wrapper"},n,t))}}]),l}();w(R,"defaultProps",{message:null,onClose:null,onClick:null});var j=i.default.forwardRef((function(e,t){return i.default.createElement(R,O({forwardRef:t},e))}));function S(){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 P=0,N=function(t){b(l,e.Component);var n,s,a=(n=l,s=S(),function(){var e,t=k(n);if(s){var r=k(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return C(this,e)});function l(e){var t;return m(this,l),(t=a.call(this,e)).state={messages:[]},t.onClose=t.onClose.bind(d(t)),t}return h(l,[{key:"show",value:function(e){if(e){var t=[];if(Array.isArray(e))for(var n=0;n<e.length;n++)e[n].id=P++,t=[].concat(p(this.state.messages),p(e));else e.id=P++,t=this.state.messages?[].concat(p(this.state.messages),[e]):[e];this.setState({messages:t})}}},{key:"clear",value:function(){this.setState({messages:[]})}},{key:"replace",value:function(e){var t=this;this.setState({messages:[]},(function(){return t.show(e)}))}},{key:"onClose",value:function(e){var t=this.state.messages.filter((function(t){return t.id!==e.id}));this.setState({messages:t}),this.props.onRemove&&this.props.onRemove(e)}},{key:"render",value:function(){var e=this;return i.default.createElement("div",{id:this.props.id,className:this.props.className,style:this.props.style},i.default.createElement(r.TransitionGroup,null,this.state.messages.map((function(t){var n=i.default.createRef();return i.default.createElement(o.CSSTransition,{nodeRef:n,key:t.id,classNames:"p-message",unmountOnExit:!0,timeout:{enter:300,exit:300},options:e.props.transitionOptions},i.default.createElement(j,{ref:n,message:t,onClick:e.props.onClick,onClose:e.onClose}))}))))}}]),l}();w(N,"defaultProps",{id:null,className:null,style:null,transitionOptions:null,onRemove:null,onClick:null}),exports.Messages=N;
|