码桶

发现社区成员的开源项目

geekssl /

wstats

公开
main
wstats/public/assets/index-BW_2QB9V.js
index-BW_2QB9V.js11.9 KB
import{Z as R,Y as A,_ as N,ac as k,R as r,a5 as T,aA as M,bb as W,aV as L,av as z,a8 as p,a9 as F,aa as _,r as x,c4 as S,c5 as m,bs as B,bt as D,bk as X}from"./index-GWuvg2UH.js";import{I as H,b as q,c as G,a as U}from"./IconTickCircle-BYgwCdAe.js";class P extends R{constructor(a){super(Object.assign(Object.assign({},P.defaultAdapter),a)),this.handleMouseInSideChange=e=>{this._adapter.handleMouseInSideChange(e)},this.getInputWrapperRect=()=>this._adapter.getInputWrapperRect()}hasToast(a){return this._adapter.getState("list").map(t=>{let{id:s}=t;return s}).includes(a)}addToast(a){const e=this._adapter.getState("list");e.push(a),this._adapter.updateToast(e,[],[])}updateToast(a,e){let t=this._adapter.getState("list");t=t.map(n=>n.id===a?Object.assign(Object.assign({},n),e):n);const s=t.filter(n=>n.id===a);this._adapter.updateToast(t,[],s)}removeToast(a){let e=this._adapter.getState("list");const t=[];e=e.filter(s=>s.id===a?(t.push(s),!1):!0),this._adapter.updateToast(e,t,[])}destroyAll(){const a=this._adapter.getState("list");a.length>0&&this._adapter.updateToast([],a,[])}}const w=`${A}-toast`,C={PREFIX:w,WRAPPER:`${w}-wrapper`},E={types:["warning","success","info","error","default"],themes:["normal","light"],directions:["ltr","rtl"]},V={duration:3};class $ extends R{constructor(a){super(Object.assign(Object.assign({},$.defaultAdapter),a)),this._timer=null,this._id=null}init(){this.startCloseTimer_(),this._id=this._adapter.getProp("id")}destroy(){this.clearCloseTimer_()}startCloseTimer_(){const a=this._adapter.getProp("duration");a&&N(a)&&(this._timer=setTimeout(()=>{this.close()},a*1e3))}close(a){a&&a.stopPropagation(),this._adapter.notifyWrapperToRemove(this._id),this._adapter.notifyClose()}clearCloseTimer_(){this._timer&&(clearTimeout(this._timer),this._timer=null)}restartCloseTimer(){this.clearCloseTimer_(),this.startCloseTimer_()}}const g=C.PREFIX;let y=class extends k{constructor(a){super(a),this.toastEle=r.createRef(),this.clearCloseTimer=()=>{this.foundation.clearCloseTimer_()},this.startCloseTimer=()=>{this.foundation.startCloseTimer_()},this.restartCloseTimer=()=>{this.foundation.restartCloseTimer()},this.state={},this.foundation=new $(this.adapter)}get adapter(){return Object.assign(Object.assign({},super.adapter),{notifyWrapperToRemove:a=>{this.props.close(a)},notifyClose:()=>{this.props.onClose()}})}componentDidMount(){this.foundation.init()}componentWillUnmount(){this.foundation.destroy()}close(a){this.foundation.close(a)}renderIcon(){const{type:a,icon:e}=this.props,s={warning:r.createElement(U,null),success:r.createElement(G,null),info:r.createElement(q,null),error:r.createElement(H,null)}[a],n="large",c=T(`${g}-icon`,`${g}-icon-${a}`);return e?M(e)?r.cloneElement(e,{size:n,className:`${g}-icon`}):e:a&&s?r.cloneElement(s,{size:n,className:c}):null}render(){const{content:a,type:e,theme:t,showClose:s,textMaxWidth:n,className:c,style:o}=this.props,i=this.props.direction||this.context.direction,f=T(g,c,{[`${g}-${e}`]:!0,[`${g}-${t}`]:t==="light",[`${g}-rtl`]:i==="rtl"}),l={};l.maxWidth=n;const h="borderless",b="small",v=this.props.positionInList?this.props.positionInList.length-this.props.positionInList.index-1:0,O=r.createElement("div",{ref:this.toastEle,role:"alert","aria-label":`${e||"default"} type`,className:f,style:Object.assign(Object.assign({},o),{transform:`translate3d(0,0,${v*-10}px)`}),onMouseEnter:this.clearCloseTimer,onMouseLeave:this.startCloseTimer,onAnimationStart:this.props.onAnimationStart,onAnimationEnd:this.props.onAnimationEnd},r.createElement("div",{className:`${g}-content`},this.renderIcon(),r.createElement("span",{className:`${g}-content-text`,style:l,"x-semi-prop":"content"},a),s&&r.createElement("div",{className:`${g}-close-button`},r.createElement(W,{onClick:j=>this.close(j),type:"tertiary",icon:r.createElement(L,{"x-semi-prop":"icon"}),theme:h,size:b}))));if(this.props.stack){const j=this.props.stackExpanded&&this.toastEle.current&&getComputedStyle(this.toastEle.current).height||0;return r.createElement("div",{className:`${g}-zero-height-wrapper`,style:{height:j}},O)}else return O}};y.contextType=z;y.propTypes={onClose:p.func,content:p.node,close:p.func,duration:p.number,theme:p.oneOf(E.themes),type:p.oneOf(E.types),textMaxWidth:p.oneOfType([p.string,p.number]),style:p.object,className:p.string,showClose:p.bool,stack:p.bool,stackExpanded:p.bool,icon:p.node,direction:p.oneOf(E.directions)};y.__SemiComponentName__="Toast";y.defaultProps=F(y.__SemiComponentName__,{onClose:_,content:"",close:_,duration:V.duration,textMaxWidth:450,showClose:!0,stack:!1,stackExpanded:!1,theme:"normal"});var Y=function(d,a){var e={};for(var t in d)Object.prototype.hasOwnProperty.call(d,t)&&a.indexOf(t)<0&&(e[t]=d[t]);if(d!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,t=Object.getOwnPropertySymbols(d);s<t.length;s++)a.indexOf(t[s])<0&&Object.prototype.propertyIsEnumerable.call(d,t[s])&&(e[t[s]]=d[t[s]]);return e};const Z=(d,a)=>{var{afterClose:e}=d,t=Y(d,["afterClose"]);const[s,n]=x.useState(!0),c=()=>{n(!1)};return r.useImperativeHandle(a,()=>({close:()=>{n(!1)}})),x.useEffect(()=>{s||e(t.id)},[s]),s?r.createElement(y,Object.assign({},t,{close:c})):null},J=r.forwardRef(Z),I={motion:!0,zIndex:1010,duration:3};function K(){const[d,a]=r.useState([]);function e(t,s){return a(n=>[{element:t,config:s},...n]),n=>{a(c=>c.filter(o=>{let{config:i}=o;return i.id!==n}))}}return[d,e]}function Q(){const[d,a]=K(),e=x.useRef(new Map),t=n=>{const c=S("semi_toast_"),o=Object.assign(Object.assign({},n),{id:c});let i;const f=r.createElement(J,Object.assign({},o,{key:c,afterClose:l=>i(l),ref:l=>{var h;e.current.set(c,{close:(h=l==null?void 0:l.close)!==null&&h!==void 0?h:_})}}));return i=a(f,Object.assign({},o)),c},s=n=>{var c;const{close:o}=(c=e.current.get(n))!==null&&c!==void 0?c:{};o==null||o()};return[{success:n=>t(Object.assign(Object.assign(Object.assign({},I),n),{type:"success"})),info:n=>t(Object.assign(Object.assign(Object.assign({},I),n),{type:"info"})),error:n=>t(Object.assign(Object.assign(Object.assign({},I),n),{type:"error"})),warning:n=>t(Object.assign(Object.assign(Object.assign({},I),n),{type:"warning"})),open:n=>t(Object.assign(Object.assign(Object.assign({},I),n),{type:"default"})),close:n=>s(n)},r.createElement(r.Fragment,null,Array.isArray(d)&&d.length?r.createElement(r.Fragment,null,d.map(n=>n.element)):null)]}const ee=()=>{var d;return d=class u extends k{constructor(e){super(e),this.stack=!1,this.innerWrapperRef=r.createRef(),this.handleMouseEnter=t=>{this.stack&&this.foundation.handleMouseInSideChange(!0)},this.handleMouseLeave=t=>{var s;this.stack&&(!((s=this.foundation.getInputWrapperRect())===null||s===void 0)&&s.height)&&this.foundation.handleMouseInSideChange(!1)},this.state={list:[],removedItems:[],updatedItems:[],mouseInSide:!1},this.foundation=new P(this.adapter)}get adapter(){return Object.assign(Object.assign({},super.adapter),{updateToast:(e,t,s)=>{this.setState({list:e,removedItems:t,updatedItems:s})},handleMouseInSideChange:e=>{this.setState({mouseInSide:e})},getInputWrapperRect:()=>{var e;return(e=this.innerWrapperRef.current)===null||e===void 0?void 0:e.getBoundingClientRect()}})}static create(e){var t,s,n;const c=(t=e.id)!==null&&t!==void 0?t:S("toast"),o=((n=(s=m===null||m===void 0?void 0:m.config)===null||s===void 0?void 0:s.overrideDefaultProps)===null||n===void 0?void 0:n.Toast)||{},i=Object.assign(Object.assign(Object.assign({},u.defaultOpts),o),e);if(u.ref){const f=document.querySelector(`#${this.wrapperId}`);["top","left","bottom","right"].map(l=>{l in i&&(f.style[l]=typeof i[l]=="number"?`${i[l]}px`:i[l])}),!!i.stack!==u.ref.stack&&(u.ref.stack=!!i.stack),u.ref.has(c)?u.ref.update(c,Object.assign(Object.assign({},i),{id:c})):u.ref.add(Object.assign(Object.assign({},i),{id:c}))}else{const f=document.createElement("div");this.wrapperId||(this.wrapperId=S("toast-wrapper").slice(0,26)),f.className=C.WRAPPER,f.id=this.wrapperId,f.style.zIndex=String(typeof e.zIndex=="number"?e.zIndex:i.zIndex),["top","left","bottom","right"].map(l=>{if(l in i){const h=i[l];f.style[l]=typeof h=="number"?`${h}px`:h}}),i.getPopupContainer?i.getPopupContainer().appendChild(f):document.body.appendChild(f),B(r.createElement(u,{ref:l=>{l&&(u.ref=l,l.add(Object.assign(Object.assign({},i),{id:c})),l.stack=!!i.stack)}}),f)}return c}static close(e){u.ref&&u.ref.remove(e)}static destroyAll(){var e;if(u.ref){u.ref.destroyAll();const t=document.querySelector(`#${this.wrapperId}`);t&&(D(t),(e=t.parentNode)===null||e===void 0||e.removeChild(t)),u.ref=null,this.wrapperId=null}}static getWrapperId(){return this.wrapperId}static info(e){var t,s;typeof e=="string"&&(e={content:e});const n=((s=(t=m===null||m===void 0?void 0:m.config)===null||t===void 0?void 0:t.overrideDefaultProps)===null||s===void 0?void 0:s.Toast)||{};return this.create(Object.assign(Object.assign(Object.assign(Object.assign({},u.defaultOpts),n),e),{type:"info"}))}static warning(e){var t,s;typeof e=="string"&&(e={content:e});const n=((s=(t=m===null||m===void 0?void 0:m.config)===null||t===void 0?void 0:t.overrideDefaultProps)===null||s===void 0?void 0:s.Toast)||{};return this.create(Object.assign(Object.assign(Object.assign(Object.assign({},u.defaultOpts),n),e),{type:"warning"}))}static error(e){var t,s;typeof e=="string"&&(e={content:e});const n=((s=(t=m===null||m===void 0?void 0:m.config)===null||t===void 0?void 0:t.overrideDefaultProps)===null||s===void 0?void 0:s.Toast)||{};return this.create(Object.assign(Object.assign(Object.assign(Object.assign({},u.defaultOpts),n),e),{type:"error"}))}static success(e){var t,s;typeof e=="string"&&(e={content:e});const n=((s=(t=m===null||m===void 0?void 0:m.config)===null||t===void 0?void 0:t.overrideDefaultProps)===null||s===void 0?void 0:s.Toast)||{};return this.create(Object.assign(Object.assign(Object.assign(Object.assign({},u.defaultOpts),n),e),{type:"success"}))}static config(e){["top","left","bottom","right"].forEach(t=>{t in e&&(u.defaultOpts[t]=e[t])}),typeof e.theme=="string"&&E.themes.includes(e.theme)&&(u.defaultOpts.theme=e.theme),typeof e.zIndex=="number"&&(u.defaultOpts.zIndex=e.zIndex),typeof e.duration=="number"&&(u.defaultOpts.duration=e.duration),typeof e.getPopupContainer=="function"&&(u.defaultOpts.getPopupContainer=e.getPopupContainer)}has(e){return this.foundation.hasToast(e)}add(e){return this.foundation.addToast(e)}update(e,t){return this.foundation.updateToast(e,t)}remove(e){return this.foundation.removeToast(e)}destroyAll(){return this.foundation.destroyAll()}render(){let{list:e}=this.state;const{removedItems:t,updatedItems:s}=this.state;e=Array.from(new Set([...e,...t]));const n=s.map(o=>{let{id:i}=o;return i}),c=o=>{var i;!((i=o==null?void 0:o.foundation)===null||i===void 0)&&i._id&&n.includes(o.foundation._id)&&o.foundation.restartCloseTimer()};return r.createElement(r.Fragment,null,r.createElement("div",{className:T({[`${C.PREFIX}-innerWrapper`]:!0,[`${C.PREFIX}-innerWrapper-hover`]:this.state.mouseInSide}),ref:this.innerWrapperRef,onMouseEnter:this.handleMouseEnter,onMouseLeave:this.handleMouseLeave},e.map((o,i)=>{const f=t.find(h=>h.id===o.id)!==void 0,l=f?"leave":"enter";return r.createElement(X,{key:o.id,motion:o.motion,animationState:l,startClassName:f?`${C.PREFIX}-animation-hide`:`${C.PREFIX}-animation-show`,onAnimationEnd:h=>{l==="leave"&&this.setState(b=>{var v;return!((v=b.removedItems)===null||v===void 0)&&v.some(O=>O.id===o.id)?Object.assign(Object.assign({},b),{removedItems:b.removedItems.filter(O=>O.id!==o.id)}):null})}},h=>{let{animationClassName:b,animationEventsNeedBind:v,isAnimating:O}=h;return r.createElement(y,Object.assign({},o,{stack:this.stack,stackExpanded:this.state.mouseInSide,positionInList:{length:e.length,index:i},className:T({[o.className]:!!o.className,[b]:!0})},v,{style:Object.assign({},o.style),close:j=>this.remove(j),ref:c}))})})))}},d.defaultOpts={motion:!0,zIndex:1010,content:""},d.propTypes={content:p.node,duration:p.number,onClose:p.func,icon:p.node,direction:p.oneOf(E.directions),stack:p.bool},d.defaultProps={},d};class te{static create(a){const e=ee();return e.useToast=Q,a&&e.config(a),e}}const oe=te.create();export{oe as T};