2 lines
6.0 KiB
JavaScript
2 lines
6.0 KiB
JavaScript
import{Component as e}from"react";import{DomHandler as t,ObjectUtils as n}from"primereact/utils";function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}function i(e,t){return i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},i(e,t)}function a(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&&i(e,t)}function o(e){return o="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},o(e)}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e,t){if(t&&("object"===o(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return l(e)}function c(e){return c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},c(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 h,m,f,d=function(i){a(v,e);var o,l,h,m,f,d=(o=v,l=p(),function(){var e,t=c(o);if(l){var n=c(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return u(this,e)});function v(){return s(this,v),d.apply(this,arguments)}return h=v,(m=[{key:"enter",value:function(){var e=this;this.props.enterActiveClassName?this.animating||(this.animating=!0,"slidedown"===this.props.enterActiveClassName&&(this.target.style.height="0px",t.removeClass(this.target,"hidden"),this.target.style.maxHeight=this.target.scrollHeight+"px",t.addClass(this.target,"hidden"),this.target.style.height=""),t.addClass(this.target,this.props.enterActiveClassName),this.props.enterClassName&&t.removeClass(this.target,this.props.enterClassName),this.enterListener=function(){t.removeClass(e.target,e.props.enterActiveClassName),e.props.enterToClassName&&t.addClass(e.target,e.props.enterToClassName),e.target.removeEventListener("animationend",e.enterListener),"slidedown"===e.props.enterActiveClassName&&(e.target.style.maxHeight=""),e.animating=!1},this.target.addEventListener("animationend",this.enterListener)):(this.props.enterClassName&&t.removeClass(this.target,this.props.enterClassName),this.props.enterToClassName&&t.addClass(this.target,this.props.enterToClassName)),this.props.hideOnOutsideClick&&this.bindDocumentListener()}},{key:"leave",value:function(){var e=this;this.props.leaveActiveClassName?this.animating||(this.animating=!0,t.addClass(this.target,this.props.leaveActiveClassName),this.props.leaveClassName&&t.removeClass(this.target,this.props.leaveClassName),this.leaveListener=function(){t.removeClass(e.target,e.props.leaveActiveClassName),e.props.leaveToClassName&&t.addClass(e.target,e.props.leaveToClassName),e.target.removeEventListener("animationend",e.leaveListener),e.animating=!1},this.target.addEventListener("animationend",this.leaveListener)):(this.props.leaveClassName&&t.removeClass(this.target,this.props.leaveClassName),this.props.leaveToClassName&&t.addClass(this.target,this.props.leaveToClassName)),this.props.hideOnOutsideClick&&this.unbindDocumentListener()}},{key:"resolveTarget",value:function(){if(this.target)return this.target;switch(this.props.selector){case"@next":return this.el.nextElementSibling;case"@prev":return this.el.previousElementSibling;case"@parent":return this.el.parentElement;case"@grandparent":return this.el.parentElement.parentElement;default:return document.querySelector(this.props.selector)}}},{key:"bindDocumentListener",value:function(){var e=this;this.documentListener||(this.documentListener=function(t){"static"===getComputedStyle(e.target).getPropertyValue("position")?e.unbindDocumentListener():e.el.isSameNode(t.target)||e.el.contains(t.target)||e.target.contains(t.target)||e.leave()},this.el.ownerDocument.addEventListener("click",this.documentListener))}},{key:"unbindDocumentListener",value:function(){this.documentListener&&(this.el.ownerDocument.removeEventListener("click",this.documentListener),this.documentListener=null)}},{key:"bindEvents",value:function(){var e=this;this.clickListener=function(){e.target=e.resolveTarget(),e.props.toggleClassName?t.hasClass(e.target,e.props.toggleClassName)?t.removeClass(e.target,e.props.toggleClassName):t.addClass(e.target,e.props.toggleClassName):null===e.target.offsetParent?e.enter():e.leave()},this.el.addEventListener("click",this.clickListener)}},{key:"unbindEvents",value:function(){this.clickListener&&(this.el.removeEventListener("click",this.clickListener),this.clickListener=null)}},{key:"el",get:function(){return n.getRefElement(this.props.nodeRef)}},{key:"init",value:function(){this.el&&this.bindEvents()}},{key:"destroy",value:function(){this.unbindEvents(),this.unbindDocumentListener(),this.target=null}},{key:"componentDidMount",value:function(){this.init()}},{key:"componentDidUpdate",value:function(e,t){e.nodeRef!==this.props.nodeRef&&(this.destroy(),this.init())}},{key:"componentWillUnmount",value:function(){this.destroy()}},{key:"render",value:function(){return this.props.children}}])&&r(h.prototype,m),f&&r(h,f),Object.defineProperty(h,"prototype",{writable:!1}),v}();f={nodeRef:null,selector:null,enterClassName:null,enterActiveClassName:null,enterToClassName:null,leaveClassName:null,leaveActiveClassName:null,leaveToClassName:null,hideOnOutsideClick:!1,toggleClassName:null},(m="defaultProps")in(h=d)?Object.defineProperty(h,m,{value:f,enumerable:!0,configurable:!0,writable:!0}):h[m]=f;export{d as StyleClass};
|