2 lines
9.1 KiB
JavaScript
2 lines
9.1 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.speeddial=function(e,t,i,n,r){"use strict";function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=s(t);function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function c(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function p(e,t){return p=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},p(e,t)}function u(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&&p(e,t)}function f(e){return f="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},f(e)}function d(e,t){if(t&&("object"===f(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return c(e)}function h(e){return h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},h(e)}function m(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function y(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function b(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?y(Object(i),!0).forEach((function(t){m(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):y(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function v(){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 k=function(e){u(C,e);var t,s,p,f,y,k=(t=C,s=v(),function(){var e,i=h(t);if(s){var n=h(this).constructor;e=Reflect.construct(i,arguments,n)}else e=i.apply(this,arguments);return d(this,e)});function C(e){var t;return l(this,C),(t=k.call(this,e)).state={visible:!1},t.onClick=t.onClick.bind(c(t)),t.onItemClick=t.onItemClick.bind(c(t)),t}return p=C,f=[{key:"isVisible",value:function(){return this.props.onVisibleChange?this.props.visible:this.state.visible}},{key:"show",value:function(){this.props.onVisibleChange?this.props.onVisibleChange(!0):this.setState({visible:!0}),this.props.onShow&&this.props.onShow()}},{key:"hide",value:function(){this.props.onVisibleChange?this.props.onVisibleChange(!1):this.setState({visible:!1}),this.props.onHide&&this.props.onHide()}},{key:"onClick",value:function(e){this.isVisible()?this.hide():this.show(),this.props.onClick&&this.props.onClick(e),this.isItemClicked=!0}},{key:"onItemClick",value:function(e,t){t.command&&t.command({originalEvent:e,item:t}),this.hide(),this.isItemClicked=!0,e.preventDefault()}},{key:"bindDocumentClickListener",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){e.isVisible()&&e.isOutsideClicked(t)&&e.hide(),e.isItemClicked=!1},document.addEventListener("click",this.documentClickListener))}},{key:"unbindDocumentClickListener",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{key:"isOutsideClicked",value:function(e){return this.container&&!(this.container.isSameNode(e.target)||this.container.contains(e.target)||this.isItemClicked)}},{key:"calculateTransitionDelay",value:function(e){var t=this.props.model.length;return(this.isVisible()?e:t-e-1)*this.props.transitionDelay}},{key:"calculatePointStyle",value:function(e){var t=this.props.type;if("linear"!==t){var i=this.props.model.length,n=this.props.radius||20*i;if("circle"===t){var r=2*Math.PI/i;return{left:"calc(".concat(n*Math.cos(r*e),"px + var(--item-diff-x, 0px))"),top:"calc(".concat(n*Math.sin(r*e),"px + var(--item-diff-y, 0px))")}}if("semi-circle"===t){var s=this.props.direction,o=Math.PI/(i-1),l="calc(".concat(n*Math.cos(o*e),"px + var(--item-diff-x, 0px))"),a="calc(".concat(n*Math.sin(o*e),"px + var(--item-diff-y, 0px))");if("up"===s)return{left:l,bottom:a};if("down"===s)return{left:l,top:a};if("left"===s)return{right:a,top:l};if("right"===s)return{left:a,top:l}}else if("quarter-circle"===t){var c=this.props.direction,p=Math.PI/(2*(i-1)),u="calc(".concat(n*Math.cos(p*e),"px + var(--item-diff-x, 0px))"),f="calc(".concat(n*Math.sin(p*e),"px + var(--item-diff-y, 0px))");if("up-left"===c)return{right:u,bottom:f};if("up-right"===c)return{left:u,bottom:f};if("down-left"===c)return{right:f,top:u};if("down-right"===c)return{left:f,top:u}}}return{}}},{key:"getItemStyle",value:function(e){var t=this.calculateTransitionDelay(e),i=this.calculatePointStyle(e);return b({transitionDelay:"".concat(t,"ms")},i)}},{key:"componentDidMount",value:function(){if("linear"!==this.props.type){var e=r.DomHandler.findSingle(this.container,".p-speeddial-button"),t=r.DomHandler.findSingle(this.list,".p-speeddial-item");if(e&&t){var i=Math.abs(e.offsetWidth-t.offsetWidth),n=Math.abs(e.offsetHeight-t.offsetHeight);this.list.style.setProperty("--item-diff-x","".concat(i/2,"px")),this.list.style.setProperty("--item-diff-y","".concat(n/2,"px"))}}this.props.hideOnClickOutside&&this.bindDocumentClickListener()}},{key:"componentWillUnmount",value:function(){this.props.hideOnClickOutside&&this.unbindDocumentClickListener()}},{key:"renderItem",value:function(e,t){var i=this,s=this.getItemStyle(t),l=e.icon,a=e.label,c=e.template,p=e.url,u=e.target,f=r.classNames("p-speeddial-action",{"p-disabled":e.disabled}),d=r.classNames("p-speeddial-action-icon",l),h=o.default.createElement("a",{href:p||"#",role:"menuitem",className:f,target:u,"data-pr-tooltip":a,onClick:function(t){return i.onItemClick(t,e)}},l&&o.default.createElement("span",{className:d}),o.default.createElement(n.Ripple,null));if(c){var m={onClick:function(t){return i.onItemClick(t,e)},className:f,iconClassName:d,element:h,props:this.props,visible:this.isVisible()};h=r.ObjectUtils.getJSXElement(c,e,m)}return o.default.createElement("li",{key:t,className:"p-speeddial-item",style:s,role:"none"},h)}},{key:"renderItems",value:function(){var e=this;return this.props.model?this.props.model.map((function(t,i){return e.renderItem(t,i)})):null}},{key:"renderList",value:function(){var e=this,t=this.renderItems();return o.default.createElement("ul",{ref:function(t){return e.list=t},className:"p-speeddial-list",role:"menu"},t)}},{key:"renderButton",value:function(){var e,t=this,n=this.isVisible(),s=r.classNames("p-speeddial-button p-button-rounded",{"p-speeddial-rotate":this.props.rotateAnimation&&!this.props.hideIcon},this.props.buttonClassName),l=r.classNames((m(e={},"".concat(this.props.showIcon),!n&&!!this.props.showIcon||!this.props.hideIcon),m(e,"".concat(this.props.hideIcon),n&&!!this.props.hideIcon),e)),a=o.default.createElement(i.Button,{type:"button",style:this.props.buttonStyle,className:s,icon:l,onClick:this.onClick,disabled:this.props.disabled});return this.props.buttonTemplate?r.ObjectUtils.getJSXElement(this.props.buttonTemplate,{onClick:function(e){return t.onClick(e)},className:s,iconClassName:l,element:a,props:this.props,visible:n}):a}},{key:"renderMask",value:function(){if(this.props.mask){var e=this.isVisible(),t=r.classNames("p-speeddial-mask",{"p-speeddial-mask-visible":e},this.props.maskClassName);return o.default.createElement("div",{className:t,style:this.props.maskStyle})}return null}},{key:"render",value:function(){var e,t=this,i=r.classNames("p-speeddial p-component p-speeddial-".concat(this.props.type),(m(e={},"p-speeddial-direction-".concat(this.props.direction),"circle"!==this.props.type),m(e,"p-speeddial-opened",this.isVisible()),m(e,"p-disabled",this.props.disabled),e),this.props.className),n=this.renderButton(),s=this.renderList(),l=this.renderMask();return o.default.createElement(o.default.Fragment,null,o.default.createElement("div",{ref:function(e){return t.container=e},id:this.props.id,className:i,style:this.props.style},n,s),l)}}],f&&a(p.prototype,f),y&&a(p,y),Object.defineProperty(p,"prototype",{writable:!1}),C}(t.Component);return m(k,"defaultProps",{id:null,model:null,visible:!1,style:null,className:null,direction:"up",transitionDelay:30,type:"linear",radius:0,mask:!1,disabled:!1,hideOnClickOutside:!0,buttonStyle:null,buttonClassName:null,buttonTemplate:null,maskStyle:null,maskClassName:null,showIcon:"pi pi-plus",hideIcon:null,rotateAnimation:!0,onVisibleChange:null,onClick:null,onShow:null,onHide:null}),e.SpeedDial=k,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.button,primereact.ripple,primereact.utils);
|