@ioca/react 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/lib/css/index.css +1 -1
- package/lib/css/index.css.map +1 -1
- package/lib/index.js +3536 -1
- package/lib/index.js.map +1 -1
- package/package.json +8 -5
- /package/lib/{index.d.ts → types/index.d.ts} +0 -0
package/lib/index.js
CHANGED
|
@@ -1,2 +1,3537 @@
|
|
|
1
|
-
import{jsxs as e,jsx as t,Fragment as n}from"react/jsx-runtime";import i from"classnames";import{debounce as a,uid as r,throttle as s,pick as l,title as o}from"radash";import{forwardRef as c,createElement as d,useEffect as u,useCallback as p,isValidElement as m,cloneElement as h,useState as g,useMemo as f,Children as v,useRef as b,useLayoutEffect as y,Fragment as N,createContext as k,useContext as C,useImperativeHandle as w}from"react";import{SkipPreviousRound as x,CloseRound as $,MinusRound as T,PlusRound as I,InboxTwotone as P,VisibilityRound as z,VisibilityOffRound as O,SyncAltRound as M,KeyboardArrowLeftRound as D,KeyboardArrowRightRound as S,CalendarMonthTwotone as j,PauseRound as E,PlayArrowRound as B,StopRound as Y,FullscreenExitRound as A,FullscreenRound as L,VolumeOffRound as V,VolumeDownRound as W,FeedOutlined as q,AspectRatioRound as F,OpenInNewRound as H,FileDownloadOutlined as R,RotateRightRound as X,RotateLeftRound as U,HideImageTwotone as G,MoreHorizRound as K,InfoOutlined as Z,SearchRound as _,CheckRound as J,UnfoldMoreRound as Q,KeyboardArrowDownRound as ee,ListAltRound as te,CloudUploadTwotone as ne,PlusSharp as ie}from"@ricons/material";import{useReactive as ae,useMemoizedFn as re,useClickAway as se,useCreation as le,useSize as oe}from"ahooks";import{createRoot as ce}from"react-dom/client";import de from"react-custom-scrollbars-2";import ue from"dayjs";import pe from"dayjs/plugin/customParseFormat";import{createPortal as me}from"react-dom";import he from"rc-virtual-list";import ge from"pubsub-js";const fe=500;function ve(e){const t=e.target,n=t.closest("[data-ripple]");t&&n&&function(e,t){const[n,i]=function(){const e=document.createElement("SPAN"),t=document.createElement("SPAN");return e.className="i-ripple-container",t.className="i-ripple",e.append(t),[e,t]}(),a=e.getBoundingClientRect(),r=2*Math.max(a.width,a.height);i.style.cssText=`\n left: ${t.pageX-a.left}px;\n top: ${t.pageY-a.top}px;\n width: ${r}px;\n height: ${r}px;\n transition: all 0.5s;\n `,e.insertAdjacentElement("afterbegin",n),e.offsetHeight,i.classList.add("i-ripple-active"),setTimeout((()=>{n.remove()}),fe)}(n,e)}const be=n=>{const{icon:a,text:r,size:s,style:l,className:o,...c}=n;return e("div",{className:i("i-loading-container",o),style:{fontSize:s,...l},...c,children:[a??t("svg",{width:"24",height:"24",stroke:"#000",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",className:"i-loading-icon",children:t("circle",{cx:"12",cy:"12",r:"9.5",fill:"none",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:40,strokeDashoffset:0})}),r]})},ye=({outline:e,flat:t,loading:n,disabled:a,size:r="normal",block:s,round:l,square:o,secondary:c,className:d})=>i("i-btn",d,{"i-btn-outline":e,"i-btn-flat":t,"i-btn-block":s,"i-btn-loading":n,"i-btn-square":o,"i-btn-secondary":c,[`i-btn-${r}`]:"normal"!==r,round:l,disabled:a}),Ne=c(((e,i)=>{const{as:a="a",children:r,className:s,loading:l,flat:o,outline:c,square:p,secondary:m,size:h,round:g,href:f,ripple:v=!0,onClick:b,...y}=e;if(!r)return t(n,{});const N=[l&&t(be,{},"loading"),d("span",{key:"content",className:"i-btn-content"},r)],k={className:ye(e),"data-ripple":v,onClick:e=>{l||y.disabled?e.stopPropagation():b?.(e)}};return u((()=>{v&&(document.documentElement.dataset.useripple||(document.documentElement.dataset.useripple="enable",document.addEventListener("mousedown",ve)))}),[v]),d(a,"string"==typeof a?{ref:i,href:f,...k,...y}:{to:f||"",...k,...y},N)}));Ne.Toggle=function(e){const{active:n,activeClass:a,after:r,disabled:s,children:l,className:o,onClick:c,onToggle:d,...m}=e,h=ae({active:n,done:!0}),g=p((()=>{const e=void 0!==r,t=!h.active;Object.assign(h,{active:t,done:!e}),d?.(t),e&&setTimeout((()=>{h.done=!0}),16)}),[r]);return u((()=>{h.active!==n&&g()}),[n]),t(Ne,{className:i(o,{[a||""]:h.active},"i-btn-toggle"),...m,onClick:e=>{c?.(e),!s&&g()},children:t("div",{className:i("i-btn-toggle-content",{"i-btn-toggle-active":h.done}),children:h.active?r??l:l})})},Ne.Group=function(e){const{children:n,vertical:a,className:r,style:s}=e;return t("div",{className:i(r,a?"i-btn-group-vertical":"i-btn-group-horizonal"),style:s,children:n})};const ke=c(((e,t)=>{const{icon:n,size:a="1.425em",rotate:r,style:s,className:l,...o}=e;if(!m(n))return n;const c={ref:t,style:{transform:r?`rotate(${r}deg)`:void 0,...s,width:a,height:a},className:i("i-icon",l),...o};return h(n,c)}));function Ce(e){const{style:n,className:a,onClick:r}=e;return t(Ne,{square:!0,className:i("i-affix-totop",a),style:{...n},onClick:r,children:t(ke,{icon:t(x,{}),rotate:90})})}const we=e=>{const{position:n="fixed",left:r,top:s,right:l,bottom:o,offset:c,style:d,className:p,children:m,getContainer:b=()=>document.body}=e,[y,N]=g(!1),k=f((()=>v.map(m,(e=>{if(e.type===Ce){const{onClick:t}=e.props;return h(e,{key:e.key,...e.props,onClick:e=>{const n=b();t?.(e),n?.scrollTo({top:0,left:0,behavior:"smooth"})}})}return e}))),[m,b]);return u((()=>{const e=b();if(!c||!e)return;const t=a({delay:160},(()=>{const t=e.scrollTop;N(t<c)}));return e.addEventListener("scroll",t),()=>{e.removeEventListener("scroll",t)}}),[c,b]),t("div",{className:i("i-affix",p,{"i-affix-hidden":y}),style:{...d,position:n,left:r,top:s,right:l,bottom:o},children:k})};we.ToTop=Ce;const xe=n=>{const{content:a,contentClass:r,dot:s,dotSize:l,round:o,disabled:c,style:d,className:u,children:p}=n;return e("div",{style:d,className:i("i-badge",{rounded:o},u),children:[p,t("div",{className:i("i-badge-content",r,{"i-badge-dot":s,"i-badge-hidden":c}),style:{fontSize:l},children:a})]})},$e=e=>n=>t("div",{style:n.style,className:i("i-card-"+e,n.className),children:n.children}),Te=$e("header"),Ie=$e("footer"),Pe=$e("banner"),ze=$e("tail"),Oe=n=>{const{shadow:a=!0,border:r,style:s,className:l,children:o}=n,c=f((()=>{const e={};return v.map(o,(t=>{switch(t.type){case Te:e.header=t;break;case Ie:e.footer=t;break;case Pe:e.banner=t;break;case ze:e.tailer=t;break;default:e.content=[...e.content||[],t]}})),e}),[o]),{header:d,banner:u,content:p,footer:m,tailer:h}=c;return e("div",{style:s,className:i("i-card",l,{shadow:a,"i-card-bordered":r}),children:[u,d,p&&t("div",{className:"i-card-content",children:p}),m,h]})};var Me;function De(e,t,n={}){const{refWindow:i,gap:a=0,offset:r=0,position:s="top",align:l}=n;if(!e||!t)return[0,0,{arrowX:0,arrowY:0,arrowPos:"bottom"}];const o=e.getBoundingClientRect(),c=t.getBoundingClientRect();let d=window.innerWidth,u=window.innerHeight,{left:p,top:m,right:h,bottom:g,width:f,height:v}=o;const{height:b,width:y}=c;if(!i){const t=e.offsetParent?.getBoundingClientRect();d=t?.width||d,u=t?.height||u,p=e.offsetLeft,m=e.offsetTop,h=p+o.width,g=m+o.height}let N=0,k=0,C=0,w=0,x="bottom";switch(s){case"left":case"right":N=v!==b?je({containerSize:u,targetSize:v,targetOffset:m,contentSize:b,gap:a,align:l}):m,w=N<m?m-N+v/2:v/2;const e=p-r-y,t=h+r+y;"left"===s?(k=e<0?h+r:e,C=e<0?0:y,x=e<0?"left":"right"):(k=d>t?h+r:e,C=d>t?0:y,x=d>t?"left":"right");break;case"top":case"bottom":k=f!==y?je({containerSize:d,targetOffset:p,targetSize:f,contentSize:y,gap:a,align:l}):p,C=k>p?y/2:p-k+f/2;const n=m-r-b,i=g+r+b;"top"===s?(N=n<0?g+r:n,w=n<0?0:b,x=n<0?"top":"bottom"):(N=u>i?g+r:n,w=u>i?0:b,x=u>i?"top":"bottom")}return[k,N,{arrowX:C,arrowY:w,arrowPos:x}]}function Se(e,t){const{pageX:n,pageY:i}=e,{width:a,height:r}=t.getBoundingClientRect(),{innerHeight:s,innerWidth:l}=window;return[n+a>=l&&n-a>0?n-a:n,i+r>=s&&i-r>0?i-r:i]}function je({containerSize:e,targetSize:t,targetOffset:n,contentSize:i,gap:a,align:r="center"}){const s=n+t/2;switch(r){case"start":return n+i>e?n+t:n;case"center":return t>=i?s-i/2:s+i/2+a>e?n+t-i:s-i/2-a<0?a:s-i/2;case"end":const r=n+t-i;return r>0?r:a;default:return s-i/2}}function Ee(e){return e.map((e=>["string","number"].includes(typeof e)?{label:e,value:e}:e))}function Be(e,t={}){const{precision:n,thousand:i}=t,a=e.toFixed(n);if(!i)return a;const r=a.split("."),s=r[0].replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g,`$&${i}`);return 1===r.length?s:`${s}.${r[1]}`}function Ye(e,t=document.body){const n=document.createElement("div");t.append(n);const i=ce(n),a=setTimeout((()=>{i?.render(e)}),0);return()=>{n?.remove(),i?.unmount(),a&&clearTimeout(a)}}function Ae(e){return e.match(/\.([^\./\?]+)($|\?)/)?.[1]}function Le(e,t){switch(!0){case["jpg","jpeg","png","webp","svg"].includes(e)||t?.startsWith("image/"):return Me.IMAGE;case["mp4","avi"].includes(e)||t?.startsWith("video/"):return Me.VIDEO;default:return Me.UNKNOWN}}function Ve(e,t=2){if(!+e)return"0 Bytes";const n=t<0?0:t,i=Math.floor(Math.log(e)/Math.log(1024));return`${parseFloat((e/Math.pow(1024,i)).toFixed(n))} ${["B","KB","MB","GB","TB","PB","EB","ZB","YB"][i]}`}function We(e,t,n){return e<t?t:e>n?n:e}function qe(n){const{type:a="default",label:r,name:s,value:l=!1,className:o,status:c="normal",message:d,disabled:p,partof:m,children:h,onChange:g,...f}=n,v=ae({value:l,status:c,message:d}),b=re((e=>{const t=e.target.checked;Object.assign(v,{value:t,status:c,message:d}),g?.(t,e)}));return u((()=>{v.value=l}),[l]),e("label",{className:i("i-checkbox-item",{[`i-checkbox-${v.status}`]:"normal"!==v.status,disabled:p},o),...f,children:[t("input",{type:"checkbox",name:s,className:i("i-checkbox-input",{[`i-checkbox-${a}`]:!m,"i-checkbox-partof":m}),checked:v.value,disabled:p,onChange:b}),t("span",{className:"i-checkbox-text",children:h||r}),v.message&&e("span",{className:"i-checkbox-message",children:["*",v.message]})]})}function Fe(n){const{label:a,name:r,options:s=[],value:l="",type:o="default",optionInline:c=!0,labelInline:d,disabled:p,status:m="normal",message:h,required:g,className:v,onChange:b,...y}=n,N=ae({value:l}),k=f((()=>Ee(s)),[s]),C=re(((e,t,n)=>{const i=[...N.value],a=i.findIndex((e=>e===t.value));e&&a<0?i.push(t.value):!e&&a>-1&&i.splice(a,1),N.value=i,b?.(i,t,n)}));return u((()=>{N.value=l}),[l]),e("div",{className:i("i-checkbox i-input-label",{[`i-checkbox-${m}`]:"normal"!==m,"i-input-inline":d},v),...y,children:[a&&e("span",{className:"i-input-label-text",children:[g&&t("span",{className:"error",children:"*"}),a,h&&t("p",{className:"i-checkbox-message",children:h})]}),t("div",{className:i("i-checkbox-options",{"i-options-block":!c,"i-checkbox-options-button":"button"===o}),children:k.map((e=>t(qe,{name:r,value:N.value.includes(e.value),type:o,disabled:p||e.disabled,onChange:(t,n)=>C(t,e,n),children:e.label},e.value)))})]})}Oe.Header=Te,Oe.Footer=Ie,Oe.Banner=Pe,Oe.Tailer=ze,function(e){e.IMAGE="IMAGE",e.VIDEO="VIDEO",e.AUDIO="AUDIO",e.PDF="PDF",e.EXCEL="EXCEL",e.TXT="TXT",e.UNKNOWN="UNKNOWN"}(Me||(Me={})),Fe.Item=qe;const He=e=>{const{as:a="a",active:s,className:l,icon:o=t($,{}),...c}=e;return s?d(a,{className:i("i-helpericon",l),...c},[d(ke,{key:r(3),icon:o})]):t(n,{})};const Re=n=>{const{active:a,items:r,multiple:s,border:l,headerClickable:o,className:c,children:d,renderToggle:u=e=>t(e?T:I,{}),onCollapse:p,...m}=n,h=ae({active:a}),g=f((()=>r||(d&&v.map(d,((e,t)=>{const{key:n,props:i}=e,{title:a,children:r,content:s,disabled:l,...o}=i;return{...o,key:n||t,title:a,content:r||s,disabled:l}}))||[])),[d]),b=e=>{const{key:t,disabled:n}=e;if(n)return;if(!s)return h.active=h.active===t?void 0:t,void p?.(t,void 0!==h.active);Array.isArray(h.active)||(h.active=[]);const i=h.active.findIndex((e=>e===t));i>-1?h.active.splice(i,1):void 0!==t&&h.active.push(t),p?.(t,i<0)};return t("div",{className:i("i-collapse",{"i-collapse-bordered":l},c),...m,children:g.map((n=>{const{key:a,title:r,content:l,disabled:c,className:d,...p}=n,m=s?(h.active||[]).includes(a):h.active===a;return e("div",{className:i("i-collapse-item",d,{"i-collapse-active":m,"i-collapse-disabled":c}),...p,children:[e("div",{className:"i-collapse-header",onClick:()=>(e=>{o&&b(e)})(n),children:[r,t(He,{active:!0,className:"i-collapse-toggle",icon:u(m),onClick:()=>b(n)})]}),t("div",{className:"i-collapse-content",children:l})]},a)}))})};function Xe(e){const{className:n,...a}=e;return t(P,{className:i("i-empty",n),...a})}function Ue({justify:e,col:t,row:n,colSpan:i=1,rowSpan:a=1}){return{"--datagrid-justify":e,gridArea:`${n+1} / ${t+1} / ${n+1+a} / ${t+1+i}`,insetInline:`var(--datagrid-cell-inset-${t})`}}function Ge(e){const{column:n,row:a,col:r,data:s,onCellClick:l,onCellDoubleClick:o}=e,{id:c,fixed:d,justify:u,rowSpan:p,render:m}=n,h=Ue({justify:u,fixed:d,col:r,row:a,rowSpan:p});return t("div",{className:i("i-datagrid-cell",{[`i-datagrid-cell-fixed-${d}`]:d}),"data-col":c,style:h,onClick:e=>l?.(s,n,a,r,e),onDoubleClick:e=>o?.(s,n,a,r,e),children:m?.(s[c],s,r)??t("div",{className:"i-datagrid-cell-content",children:s[c]})})}Re.Item=function(e){return t(n,{})};const Ke=new Set,Ze=new Set;function _e(e){u((()=>(Ke.add(e),()=>{Ke.delete(e)})),[e])}function Je(e){u((()=>(Ze.add(e),()=>{Ze.delete(e)})),[e])}function Qe(e){const t=new WeakMap,n=new IntersectionObserver((e=>{e.map((e=>{const n=t.get(e.target);n?.(e.target,e.isIntersecting)}))}),e);return{observe:function(e,i){t.get(e)||(t.set(e,i),e&&n.observe(e))},unobserve:function(e){e&&n.unobserve(e),t.delete(e)},disconnect:function(){n.disconnect()}}}function et(e){const{index:n,onWidthChange:i}=e,a=ae({resizing:!1,x:0,width:0}),r=re((e=>{const t=e.target.offsetParent.offsetWidth;Object.assign(a,{x:e.pageX,resizing:!0,width:t})}));return _e(re((e=>{if(!a.resizing)return;e.preventDefault();const t=a.width+e.pageX-a.x;t<=24||i(n,t)}))),Je((()=>{a.resizing&&(a.resizing=!1)})),t("i",{className:"i-datagrid-resizor",onMouseDown:r,onClick:e=>e.stopPropagation()})}document.addEventListener("mousemove",(e=>{for(const t of Ke.values())t(e)})),document.addEventListener("mouseup",(e=>{for(const t of Ze.values())t(e)}));const tt=e=>t("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...e,children:t("g",{fill:"none",children:t("path",{d:"M9 17.898c0 1.074 1.265 1.648 2.073.941l6.31-5.522a1.75 1.75 0 0 0 0-2.634l-6.31-5.522C10.265 4.454 9 5.028 9 6.102v11.796z",fill:"currentColor"})})});function nt(n){const{type:a}=n;return e("a",{className:i("i-datagrid-sorter",{[`i-datagrid-sorter-${a}`]:a}),children:[t(tt,{className:"i-datagrid-sorter-caret"}),t(tt,{className:"i-datagrid-sorter-caret"})]})}function it(e){const{row:n,data:i,columns:a,onRowClick:r,onCellClick:s,onCellDoubleClick:l}=e;return t("div",{className:"i-datagrid-row",onClick:()=>r?.(i,n),children:a.map(((e,a)=>t(Ge,{column:e,col:a,row:n,data:i,onCellClick:s,onCellDoubleClick:l},a)))})}function at(n){const{columns:a,resizable:r,sortBy:s,sortType:l,onWidthChange:o,onHeaderClick:c}=n;return t("div",{className:"i-datagrid-header i-datagrid-row",children:a.map(((n,a)=>{const{id:d,title:u,fixed:p,colSpan:m,sorter:h,justify:g,renderHeader:f}=n,v=Ue({justify:g,row:0,col:a,colSpan:m}),b=s===d?l:"";return e("div",{"data-col":d,className:i("i-datagrid-cell",{"i-datagrid-has-sorter":h,"i-datagrid-cell-fixed":p}),style:{...v,insetBlockStart:0},onClick:e=>c?.(n,e),children:[f?.(n,a)??t("div",{className:"i-datagrid-cell-content",children:u||d}),h&&t(nt,{type:b}),r&&t(et,{index:a,onWidthChange:o})]},a)}))})}const rt=n=>{const{data:a=[],columns:r=[],border:s,striped:l,header:o=!0,resizable:c,cellPadding:d=".5em",empty:m=t(Xe,{}),loading:h,height:g="unset",style:v,className:y,renderLoading:N=()=>t(be,{size:"1.5em",className:"color-3"}),onCellClick:k,onRowClick:C,onHeaderClick:w,onSort:x,onScroll:$,onResize:T}=n,I=b(null),P=b(null),z=ae({rows:a,widths:r.map((e=>e.width??"auto")),sortBy:"",sortType:""}),O=f((()=>{const{widths:e}=z,t={...v,"--grid-template-columns":e.map((e=>"number"==typeof e?`${e}px`:e)).join(" ")};if(!c)return t;const n=r.map(((t,n)=>{const{fixed:i}=t;return i?e[n]:0}));return r.map(((e,i)=>{const{fixed:a}=e;if(a)if(0===i)t["--datagrid-cell-inset-0"]=0;else if(i===n.length-1)t["--datagrid-cell-inset-"+(n.length-1)]="auto 0";else{const e="left"===a,r=(e?n.slice(0,i):n.slice(i+1)).reduce(((e,t)=>e+t))+"px",s=e?`${r} auto`:`auto ${r}`;t[`--datagrid-cell-inset-${i}`]=s}})),t}),[z.widths,c]),M=p(((e,t)=>{if(!c)return;const[...n]=z.widths;n[e]=t,z.widths=n,T?.(r[e],t)}),[c]),D=p(((e,t)=>{if(e?.sorter){const[t,n]=function(e,t,n){const i=["desc","asc"];if(e===n){const e=i.findIndex((e=>e===t))+1,a=i[e]||"";return[""===a?"":n,a]}return[n,"desc"]}(z.sortBy,z.sortType,e.id);Object.assign(z,{sortBy:t,sortType:n}),x?.(t,n)}w?.(e,t)}),[]),S=f((()=>{const{sortBy:e,sortType:t}=z;if(e&&!x){const n=r.find((t=>t.id===e))?.sorter,i="function"==typeof n?n:(t,n)=>n[e]-t[e],s=[...a].sort(i);return"desc"===t?s:s.reverse()}return a}),[a,r,z.sortBy,z.sortType]);u((()=>{if(!I.current)return;const{current:e}=I,t=e.querySelector(".i-datagrid-row")?.children;t?.length&&(z.widths=Array.from(t).map((e=>e.offsetWidth)))}),[r,c]),u((()=>{h&&P.current?.scrollTop(0)}),[h]);const j={"--padding":d,...O};return e(de,{ref:P,autoHide:!0,autoHeight:!0,autoHeightMax:g,style:j,className:i("i-datagrid-container",y,{"i-datagrid-bordered":s,"i-datagrid-striped":l}),renderView:e=>t("div",{...e,className:i({"i-datagrid-loading":h})}),onScroll:$,children:[e("div",{ref:I,className:"i-datagrid",children:[o&&t(at,{columns:r,resizable:c,sortType:z.sortType,sortBy:z.sortBy,onWidthChange:M,onHeaderClick:D}),S.map(((e,n)=>t(it,{row:n+(o?1:0),data:e,columns:r,onCellClick:k,onRowClick:C},n))),S.length<1&&m]}),h&&N()]})};function st(n){const{label:a,className:r,labelInline:s,style:l,children:o,status:c,tip:d,required:u}=n;return e("label",{className:i("i-input-label",r,{"i-input-inline":s}),style:l,children:[a&&e("span",{className:"i-input-label-text",children:[u&&t("span",{className:"error",children:"*"}),a]}),o,d&&t("span",{className:i("i-input-message",{[`i-input-${c}`]:"normal"!==c}),children:d})]})}const lt=c(((n,a)=>{const{type:r="text",label:s,name:l,value:o=n.initValue??"",initValue:c="",prepend:d,append:m,labelInline:h,className:g,status:v="normal",message:b,tip:y,clear:N,hideVisible:k,border:C,required:w,onChange:x,onEnter:$,style:T,...I}=n,P=ae({value:o,type:r,visible:!1}),M=p((e=>{const t=e.target.value;P.value=t,x?.(t,e)}),[]),D=re((e=>{"Enter"===e.code&&$?.()})),S=f((()=>{if("password"===r)return P.visible?t(z,{}):t(O,{})}),[P.visible]);u((()=>{P.value=o}),[o]);const j={ref:a,type:P.type,name:l,value:P.value,className:i("i-input",`i-input-${r}`),onChange:M,onKeyDown:D,...I},E=N&&P.value,B="password"===r&&!!P.value;return t(st,{label:s,labelInline:h,className:g,style:T,tip:b??y,status:v,required:w,children:e("div",{className:i("i-input-item",{[`i-input-${v}`]:"normal"!==v,"i-input-borderless":!C}),children:[d&&t("div",{className:"i-input-prepend",children:d}),t("input",{...j}),t(He,{active:!!E||B,icon:S,onClick:()=>{if("password"===r&&!k)return void Object.assign(P,{visible:!P.visible,type:P.visible?"password":"text"});x?.("")}}),m&&t("div",{className:"i-input-append",children:m})]})})})),ot=c(((n,a)=>{const{label:r,name:s,value:l=n.initValue??"",initValue:o,labelInline:c,step:d=1,min:m=-1/0,max:h=1/0,thousand:g,precision:f,type:v,className:b,status:y="normal",append:N,border:k,prepend:C,message:w,tip:x,hideControl:$,style:P,onChange:z,onEnter:O,onInput:M,onBlur:D,...S}=n,j=ae({value:l}),E=p((e=>We(e,m,h)),[m,h]),B=p((e=>Be(e,{precision:f,thousand:g})),[f,g]),Y=p((e=>e?"number"!=typeof e&&g?e.replaceAll(g,""):e:""),[g]),A=re((e=>{const{value:t}=e.target,n=Y(t.replace(/[^\d\.-]/g,""));j.value=n,z?.(+n,e)})),L=re((e=>{const t=Y(j.value)??0,n=E(+t+e);j.value=B(n),z?.(n)}));u((()=>{j.value=l}),[l]);const V={ref:a,name:s,value:j.value,className:"i-input i-input-number",onChange:A,...S};return t(st,{label:r,labelInline:c,className:b,style:P,tip:w??x,status:y,children:e("div",{className:i("i-input-item",{[`i-input-${y}`]:"normal"!==y,"i-input-borderless":!k}),children:[C&&t("div",{className:"i-input-prepend",children:C}),!$&&t(He,{active:!0,icon:t(T,{}),onClick:()=>L(-d)}),t("input",{...V}),!$&&t(He,{active:!0,icon:t(I,{}),onClick:()=>L(d)}),N&&t("div",{className:"i-input-append",children:N})]})})})),ct=c(((e,n)=>{const{label:a,name:r,value:s=e.initValue??"",initValue:l,labelInline:o,className:c,status:d="normal",message:m,tip:h,autoSize:g,border:f,style:v,onChange:y,onEnter:N,...k}=e,C=ae({value:s}),w=b(null),x=p((e=>{const t=e.target.value;C.value=t;const n=w.current?.firstChild;g&&n&&(n.style.height=`${n.scrollHeight}px`),y?.(t,e)}),[]),$=re((e=>{"Enter"===e.code&&N?.()}));u((()=>{C.value=s}),[s]);const T={ref:n,name:r,value:C.value,className:"i-input i-textarea",onChange:x,onKeyDown:$,...k};return t(st,{label:a,labelInline:o,className:c,style:v,tip:m??h,status:d,children:t("div",{ref:w,className:i("i-input-item",{[`i-input-${d}`]:"normal"!==d,"i-input-borderless":!f}),children:t("textarea",{...T})})})}));lt.Textarea=ct,lt.Number=ot,lt.Range=n=>{const{label:a,name:r,value:s=n.initValue??"",initValue:l,labelInline:o,min:c=-1/0,max:d=1/0,type:m,className:h,status:g="normal",message:f,tip:v,append:b,prepend:y,step:N=1,thousand:k,precision:C,hideControl:w,placeholder:x,border:$,onChange:P,onBlur:z,style:O,...D}=n,S=ae({value:s}),j=p((e=>We(e,c,d)),[c,d]),E=p((e=>Be(e,{precision:C,thousand:k})),[C,k]),B=p((e=>e?"number"!=typeof e&&k?e.replaceAll(k,""):e:""),[k]),Y=re(((e,t)=>{const{value:n}=e.target,i=B(n.replace(/[^\d\.-]/g,"")),a=Array.isArray(S.value)?S.value:[];a[t]=+i,S.value=a,P?.(a,e)})),A=re(((e,t,n)=>{e.preventDefault(),e.stopPropagation();const i=Array.isArray(S.value)?S.value:[],a=B(i[n])??0,r=j(+a+t);i[n]=E(r),S.value=i,P?.(i,e)})),L=re((e=>{e.preventDefault(),e.stopPropagation();const t=S.value??[],n=t[0];t[0]=t[1],t[1]=n,S.value=t,P?.(t)}));u((()=>{S.value=s}),[s]);const V={name:r,className:"i-input i-input-number",...D};return t(st,{label:a,labelInline:o,className:h,style:O,tip:f??v,status:g,children:e("div",{className:i("i-input-item",{[`i-input-${g}`]:"normal"!==g,"i-input-borderless":!$}),children:[y&&t("div",{className:"i-input-prepend",children:y}),!w&&t(He,{active:!0,icon:t(T,{}),onClick:e=>A(e,-N,0)}),t("input",{value:S.value?.[0]||"",placeholder:x?.[0],...V,onChange:e=>Y(e,0)}),!w&&t(He,{active:!0,icon:t(I,{}),onClick:e=>A(e,N,0)}),t(He,{active:!0,icon:t(M,{}),style:{margin:0},onClick:L}),!w&&t(He,{active:!0,icon:t(T,{}),onClick:e=>A(e,-N,1)}),t("input",{value:S.value?.[1]||"",placeholder:x?.[1],...V,onChange:e=>Y(e,1)}),!w&&t(He,{active:!0,icon:t(I,{}),onClick:e=>A(e,N,1)}),b&&t("div",{className:"i-input-append",children:b})]})})};const dt=c(((n,a)=>{const{getContainer:r=e=>e?.offsetParent??document.body,trigger:s,arrow:l,arrowProps:o={},className:c,children:d,...u}=n,p=f((()=>{let{left:e,top:t,pos:n}=o,i="";switch(n){case"left":e+=2,i="translate(-100%, -50%) rotate(180deg)";break;case"right":e-=2,i="translate(0, -50%)";break;case"top":t-=2,i="translate(-50%, -50%) rotate(-90deg)";break;case"bottom":t+=2,i="translate(-50%, -50%) rotate(90deg)"}return{left:e,top:t,transform:i}}),[o]),m=e("div",{ref:a,className:i("i-popup",c),...u,children:[l&&t("svg",{xmlns:"http://www.w3.org/2000/svg",className:"i-popup-arrow",style:p,children:t("path",{d:"M0.5 0L1.5 0C1.5 4, 3 5.5, 5 7.5S8,10 8,12S7 14.5, 5 16.5S1.5,20 1.5,24L0.5 24L0.5 0z"})}),d]});return me(m,r(s))}));function ut(i){const{visible:a=!1,content:r,trigger:s="hover",gap:l=12,offset:o=8,fixed:c,position:d="top",showDelay:p=16,hideDelay:g=12,touchable:N,arrow:k=!0,align:C,fitSize:w,watchResize:x,clickOutside:$=!0,disabled:T,referToWindow:I,style:P,className:z,getContainer:O,children:M,onVisibleChange:D}=i,S=b(null),j=b(null),E=ae({show:!1,toggling:!1,style:{position:c?"fixed":"absolute"},arrowProps:{}});se((e=>{if(!$)return;const t=e.target,n=S.current?.contains(t);E.show&&(!n||"contextmenu"===s)&&A(!1)}),j);const B=()=>{T||E.show&&("hover"!==s||"hover"===s&&!N)||(E.show=!0,E.toggling&&clearTimeout(E.toggling),E.toggling=setTimeout((()=>{const[e,t,{arrowX:n,arrowY:i,arrowPos:a}]=De(S.current,j.current,{position:d,gap:l,offset:o,align:C,refWindow:I});E.style={...E.style,opacity:1,transform:"none",left:e,top:t},E.arrowProps={left:n,top:i,pos:a},E.toggling&&clearTimeout(E.toggling),D?.(!0)}),p))},Y=()=>{E.show&&(E.toggling=setTimeout((()=>{E.style={...E.style,opacity:0,transform:"translate(0, 2px)"},setTimeout((()=>{E.show=!1,E.toggling&&clearTimeout(E.toggling),D?.(!1)}),160)}),g))},A=e=>{void 0===e?E.show?Y():B():e?B():Y()},L=le((()=>({click:{onClick:()=>A(!0)},hover:{onMouseEnter:()=>A(!0),onMouseLeave:()=>A(!1)},focus:{onFocus:()=>A(!0),onBlur:()=>A(!1)},contextmenu:{onContextMenu:e=>{if(e.preventDefault(),e.stopPropagation(),E.show){const[t,n]=Se(e,j.current);E.style={...E.style,left:t,top:n}}else E.show=!0,E.toggling=setTimeout((()=>{const[t,n]=Se(e,j.current);E.style={...E.style,opacity:1,transform:"none",left:t,top:n},E.toggling&&clearTimeout(E.toggling),D?.(!0)}),p)}},none:{}})),[]),V=f((()=>{if(!N)return{};const e={};return"hover"===s&&(e.onMouseEnter=()=>A(!0),e.onMouseLeave=()=>A(!1)),e}),[N,s]),W=()=>{if(!E.show)return;const[e,t,{arrowX:n,arrowY:i,arrowPos:a}]=De(S.current,j.current,{position:d,gap:l,offset:o,align:C,refWindow:I});Object.assign(E,{style:{...E.style,left:e,top:t},arrowProps:{left:n,top:i,pos:a}})};return u((()=>{if("contextmenu"===s)return;const{observe:e,unobserve:t,disconnect:n}=function(){const e=new WeakMap,t=new ResizeObserver((t=>{t.map((t=>{const n=e.get(t.target);n?.(t.target)}))}));return{observe:function(n,i){e.get(n)||(n&&t.observe(n),e.set(n,i))},unobserve:function(n){n&&t.unobserve(n),e.delete(n)},disconnect:function(){t.disconnect()}}}();return S.current&&e(S.current,W),x&&j.current?(e(j.current,W),()=>{x&&j.current&&(t(j.current),S.current&&t(S.current),n())}):void 0}),[x,j.current,S.current]),y((()=>{if(!w||!E.show)return;const e=["top","bottom"].includes(d),t=S.current?.[e?"offsetWidth":"offsetHeight"];E.style={...E.style,[e?"width":"height"]:t}}),[E.show,w]),y((()=>{A(a)}),[a]),e(n,{children:[v.map(M,(e=>{if(!m(e))return;const{type:t,props:n}=e;if("function"==typeof t)return e;const{className:i,...a}=n;return h(e,{ref:S,className:i,...L[s],...a})})),E.show&&t(dt,{ref:j,arrow:k&&"contextmenu"!==s,style:{...P,...E.style},arrowProps:E.arrowProps,className:z,...V,trigger:S.current,getContainer:O,children:r})]})}const pt=a=>{const{value:r,month:s,weeks:l=["一","二","三","四","五","六","日"],renderDate:o=e=>e.date(),disabledDate:c,onDateClick:d}=a,u=ue(),p=f((()=>{const e=[],t=s.add(-1,"month").endOf("month");let{$W:n,$D:i}=t;if(0!==n){const i=Array.from({length:n}).map(((e,i)=>t.add(i+1-n,"day")));e.push(...i)}const a=s.endOf("month");return i=a.$D,n=a.$W,e.push(...Array.from({length:i}).map(((e,t)=>a.add(t+1-i,"day")))),0!==n&&e.push(...Array.from({length:7-n}).map(((e,t)=>a.add(t+1,"day")))),e}),[s]),m=re((e=>{c?.(e)||d?.(e)}));return e(n,{children:[t("div",{className:"i-datepicker-weeks",children:l.map(((e,n)=>t("span",{className:"i-datepicker-week",children:e},n)))}),t("div",{className:"i-datepicker-dates",children:p.map(((e,n)=>{const a=e.isSame(r,"day"),l=e.isSame(s,"month"),d=e.isSame(u,"day"),p=c?.(e);return t("div",{className:i("i-datepicker-item",{"i-datepicker-active":a,"i-datepicker-same-month":l,"i-datepicker-today":d,"i-datepicker-disabled":p}),onClick:()=>m(e),children:o(e)},n)}))})]})},mt=[1,2,3,4,5,6,7,8,9,10,11,12],ht=n=>{const{value:i,unitMonth:a="月",unitYear:r="年",renderYear:s,renderMonth:l,onClick:o}=n;return e("a",{className:"i-datepicker-action","data-ripple":!0,onClick:o,children:[t("span",{children:s?.(i.year())}),r,t("span",{children:l?.(i.month()+1)}),a]})},gt=n=>{const{value:a,unitYear:r,unitMonth:l,renderDate:o,renderMonth:c=e=>e,renderYear:d=e=>e,disabledDate:m,onDateClick:h}=n,g=ae({today:a,month:a||ue(),selectedYear:ue(),years:[],selectable:!1}),f=b(null),v=p((e=>{g.month=g.month[e?"add":"subtract"](1,"month")}),[]),y=s({interval:100},(e=>{const t=e.deltaY<0;g.years=g.years.map((e=>e+(t?-1:1)))}));return u((()=>{if(!g.selectable)return;g.selectedYear=g.month;const e=g.selectedYear.year(),t=Array.from({length:7}).map(((t,n)=>e-3+n));g.years=[...t]}),[g.selectable]),u((()=>{g.today=a,g.month=a||ue()}),[a]),e("div",{className:"i-datepicker",children:[e("div",{className:"i-datepicker-units",children:[t(ht,{value:g.month,unitYear:r,unitMonth:l,renderMonth:c,renderYear:d,onClick:()=>g.selectable=!0}),t("a",{className:"ml-auto i-datepicker-action","data-ripple":!0,onClick:()=>v(!1),children:t(ke,{icon:t(D,{})})}),t("a",{className:"i-datepicker-action","data-ripple":!0,onClick:()=>v(!0),children:t(ke,{icon:t(S,{})})})]}),e("div",{className:i("i-datepicker-ym",{"i-datepicker-active":g.selectable}),children:[t(He,{active:!0,className:"i-datepicker-close",onClick:()=>g.selectable=!1}),t("div",{ref:f,className:"i-datepicker-years",onWheel:y,children:g.years.map((e=>t("a",{className:i("i-datepicker-year",{"i-datepicker-active":e===g.selectedYear.year()}),onClick:()=>g.selectedYear=g.selectedYear.year(e),children:d(e)},e)))}),t("div",{className:"i-datepicker-months",children:mt.map((e=>t("a",{className:i("i-datepicker-month",{"i-datepicker-active":e===g.month.month()+1}),onClick:()=>{return t=e,g.month=g.month.year(g.selectedYear.year()).month(t-1),void(g.selectable=!1);var t},children:c(e)},e)))})]}),t(pt,{value:g.today,month:g.month,disabledDate:m,onDateClick:e=>{e.isSame(g.today,"day")||(e.isSame(g.month,"month")||(g.month=e),g.today=e,h?.(e))},renderDate:o})]})};ue.extend(pe);const ft=["YYYY-MM-DD","YYYY-M-D","YYYY/MM/DD","YYYY/M/D"],vt=e=>{const{name:n,value:i,weeks:a,format:r="YYYY-MM-DD",renderDate:s,renderMonth:l,renderYear:o,popupProps:c,disabledDate:d,onDateClick:p,onChange:m,onBlur:h,...v}=e,b=ae({value:i}),[y,N]=g(!1),k=f((()=>{if(!b.value)return null;const e=ue(b.value,r,!0);return e.isValid()?e:null}),[b.value]),C=e=>{b.value=e,m?.(e)},w=()=>{if(!b.value)return;const e=ue(b.value,ft,!0);e.isValid()?C(e.format(r)):C("")};return u((()=>{b.value=i}),[i]),t(ut,{visible:y,trigger:"click",position:"bottom",arrow:!1,align:"start",content:t(gt,{value:k,weeks:a,renderDate:s,renderMonth:l,renderYear:o,disabledDate:d,onDateClick:e=>{C(e.format(r))}}),...c,watchResize:!0,onVisibleChange:N,children:t(lt,{value:b.value,prepend:t(ke,{icon:t(j,{}),className:"i-datepicker-icon",size:"1em"}),onChange:C,onBlur:e=>{h?.(e),w()},onEnter:w,...v})})},bt=n=>{const{data:a,colon:r,columns:s=1,gap:l=".5em",align:o,labelWidth:c,labelAlign:d,vertical:u,equally:p,style:m,className:h}=n;return t("div",{className:i("i-description",h),style:{"--description-label-width":c,gridTemplateColumns:`repeat(${s}, ${p?"1fr":"auto"})`,gap:l,textAlign:o,...m},children:a.map(((n,a)=>{const{label:s,value:l,style:o,hidden:c,rowSpan:p=1,colSpan:m=1}=n;return c?t(N,{},a):e("div",{className:i("i-description-item",{"i-description-item-vertical":u}),style:{gridColumn:`span ${m}`,gridRow:`span ${p}`,...o},children:[s&&e("div",{className:"i-description-label",style:{textAlign:d},children:[s,r]}),t("div",{className:"i-description-value",children:l})]},a)}))})};function yt(n){const{visible:a,position:r="left",header:s,footer:l,backdropClosable:o=!0,hideCloseButton:c,className:d,children:m,onVisibleChange:h,onClose:f,...v}=n,[y,N]=g(a),[k,C]=g(a),w=b(!0);u((()=>{a?x():$()}),[a]);const x=p((()=>{w.current&&(N(!0),h?.(!0),w.current=!1,setTimeout((()=>{C(!0),w.current=!0}),24))}),[]),$=p((()=>{w.current&&(w.current=!1,C(!1),setTimeout((()=>{N(!1),h?.(!1),w.current=!0,f?.()}),240))}),[]),T=p((function(){o&&$()}),[]);return me(y&&t("div",{className:i("i-backdrop-drawer",d,{"i-active":k}),onClick:T,...v,children:e("div",{className:i("i-drawer",`i-drawer-${r}`),onClick:e=>e.stopPropagation(),children:[e("header",{className:"i-drawer-header",children:[s,t(He,{active:!c,className:"i-drawer-close",onClick:$})]}),t("div",{className:"i-drawer-content",children:m}),t("div",{className:"i-drawer-footer",children:l})]})}),document.body)}const Nt=c(((n,a)=>{const{active:r,type:s,align:l,disabled:o,label:c,style:d,className:u,children:p,...m}=n;return e("li",{ref:a,className:i("i-list-item",u,{"i-list-item-active":r,"i-list-option":"option"===s,disabled:o}),style:{alignItems:l,...d},...m,children:[void 0!==c&&t("span",{className:"i-list-item-label",children:c}),p]})})),kt=e=>{const{label:n,type:a,className:r,children:s,...l}=e;return t("ul",{className:i("i-list",r),...l,children:v.map(s,((e,t)=>{const i="function"==typeof n?n(t):n;return h(e,{label:i,...e.props,type:a})}))})};kt.Virtual=e=>{const{data:n,itemKey:i,renderItem:a,...r}=e;return t(he,{data:n,itemKey:i,...r,children:(e,t)=>a?.(e,t)})},kt.Item=Nt;const{Item:Ct}=kt,wt=e=>{const{width:n,content:i,children:a,...r}=e;return t(ut,{trigger:"click",position:"bottom",touchable:!0,content:t(kt,{className:"i-dropdown-content",style:{minWidth:n},children:i}),...r,children:a})};wt.Item=e=>{const{more:n,moreProps:i,...a}=e,r=t(Ct,{...a});return n?t(ut,{position:"right",touchable:!0,arrow:!1,align:"start",offset:10,...i,content:t(kt,{className:"i-dropdown-content",onClick:e=>e.stopPropagation(),children:n}),children:r}):r};const xt=e=>{const{as:n="div",align:a,justify:r,direction:s,wrap:l,gap:o,columns:c,className:d,style:u,...p}=e,m=f((()=>{if(c)return"number"==typeof c?`repeat(${c}, 1fr)`:c}),[c]);return t(n,{...p,style:{alignItems:a,justifyContent:r,gap:o,flexDirection:s,flexWrap:!0===l?"wrap":l,gridTemplateColumns:m,...u},className:i(d,{[c?"grid":"flex"]:!0})})},$t=k({});class Tt{id;data={};rules={};constructor(){this.id=r(8),this.data={}}get(e){return e?this.data[e]:this.data}set(e,t){const n=this.id;if(this.data)return"string"==typeof e?(this.data[e]=t,void ge.publish(`${n}:set:${e}`,t)):void Object.keys(e).map((t=>{this.data[t]=e[t],ge.publish(`${n}:set:${t}`,e[t])}))}clear(){this.data&&Object.keys(this.data).map((e=>{ge.publish(`${this.id}:set:${e}`,void 0),this.data[e]=void 0}))}async validate(e){const{id:t,rules:n,data:i}=this;if(!n)return i;if(e){const a=n[e],r={validator:e=>Array.isArray(e)?e.length>0:![void 0,null,""].includes(e),message:void 0};"function"==typeof a?r.validator=a:!0===a?r.message="required":Object.assign(r,a);const s=r.validator?.(i[e],this);return s?(ge.publish(`${t}:invalid:${name}`,{message:null,status:"normal"}),!0):(ge.publish(`${t}:invalid:${e}`,{message:r.message,status:"error"}),!1)}let a=!0;return Object.keys(i).map((e=>{const r=n[e];if(void 0===r)return;const s={validator:e=>Array.isArray(e)?e.length>0:!!e,message:void 0};"function"==typeof r?s.validator=r:!0===r?s.message="required":Object.assign(s,r);const l=s.validator?.(i[e],this);l?ge.publish(`${t}:invalid:${e}`,{message:null,status:"normal"}):(ge.publish(`${t}:invalid:${e}`,{message:s.message,status:"error"}),a=!1)})),!!a&&i}}const It=e=>{const{form:n={},rules:a={},initialValues:r={},style:s,className:l,width:o,children:c,...d}=e;return u((()=>{Object.assign(n,{data:{...r},rules:{...a}})}),[n,a]),t($t.Provider,{value:n,children:t("form",{style:{...s,width:o},className:i("i-form",l),...d,children:c})})};function Pt(i){const{title:a,footer:r,hideCloseButton:s,footerLeft:l,okButtonProps:o={children:"确定",onClick:i.onOk},cancelButtonProps:c={secondary:!0,children:"关闭",onClick:i.onClose},children:d,onClose:u}=i,p=a||!s,m=f((()=>{if(r||null===r)return r;const i=Object.assign({},o),a=Object.assign({},c);return e(n,{children:[l,t(Ne,{...i}),t(Ne,{...a})]})}),[r,o,c]);return e(n,{children:[p&&e("header",{className:"i-modal-header",children:[a&&t("b",{children:a}),t(He,{active:!s,className:"i-modal-close",onClick:u})]}),t("div",{className:"i-modal-content",children:d}),t("footer",{className:"i-modal-footer",children:m})]})}function zt(n){const{visible:a,title:r,footer:s,okButtonProps:l,cancelButtonProps:o,closable:c=!0,hideBackdrop:d,backdropClosable:m=!0,hideCloseButton:h,width:f,height:v,customized:y,fixed:N,shadow:k=!0,children:C,style:w,className:x,footerLeft:$,onVisibleChange:T,onClose:I,onOk:P,...z}=n,[O,M]=g(a),[D,S]=g(!1),[j,E]=g(!1),B=b(!0),Y=p((()=>{B.current&&(M(!0),B.current=!1,setTimeout((()=>{S(!0),T?.(!0),B.current=!0}),24))}),[]),A=p((()=>{if(B.current){if(B.current=!1,!c)return E(!0),void setTimeout((()=>{E(!1),B.current=!0}),400);S(!1),setTimeout((()=>{M(!1),B.current=!0,T?.(!1),I?.()}),240)}}),[c]),L=p((function(){m&&A()}),[c,m]);return u((()=>{a?Y():A()}),[a]),O?me(t("div",{className:i("i-modal-container",{"i-modal-backdrop":!d,"i-modal-customized":y,"i-modal-active":D,fixed:N},x),style:w,onClick:L,children:e("div",{className:i("i-modal",{bounced:j,shadow:k}),style:{width:f,height:v},onClick:e=>e.stopPropagation(),...z,children:[y&&C,!y&&t(Pt,{title:r,hideCloseButton:h,footer:s,okButtonProps:l,cancelButtonProps:o,children:C,footerLeft:$,onOk:P,onClose:A})]})}),document.body):null}It.useForm=function(e){const t=b();return t.current||(t.current=e??new Tt),t.current},It.Field=function(e){const{name:t,required:n,children:i}=e,a=ae({value:void 0,status:"normal",message:void 0,update:0}),r=C($t),{id:s}=r,l=p((e=>{t&&r.set(t,e)}),[t]),o=f((()=>v.map(i,(e=>{if(!m(e))return null;const{onChange:t}=e.props,{value:i,status:r,message:s}=a;return h(e,{value:i,status:r,message:s,required:n,onChange:(...e)=>{l(e[0]),t?.(...e),Object.assign(a,{status:"normal",message:void 0})}})}))),[i,a.update]);return u((()=>{if(t)return ge.subscribe(`${s}:set:${t}`,((e,t)=>{a.value=t,a.update+=1})),ge.subscribe(`${s}:invalid:${t}`,((e,t)=>{Object.assign(a,t),a.update+=1})),setTimeout((()=>{r.data[t]=r.data[t]??void 0}),0),()=>{ge.unsubscribe(`${s}:set:${t}`),ge.unsubscribe(`${s}:invalid:${t}`)}}),[t]),t?o:i};const Ot=c(((e,n)=>{const i=ae({});return w(n,(()=>({update:(e={})=>{Object.assign(i,e)}}))),t(zt,{...e,...i})})),Mt=e=>{const{as:n="span",size:a,weight:r,decoration:s,gradient:l,style:o,className:c,children:d}=e,u=f((()=>l&&Array.isArray(l)?{background:`-webkit-linear-gradient(${l.join(",")})`,backgroundClip:"text"}:{}),[l]);return t(n,{style:{fontSize:a,fontWeight:r,textDecoration:s,...u,...o},className:i(c,{"i-text-gradient":l}),children:d})};function Dt(n){const{value:i,height:a=40,size:r=8}=n;return e("div",{className:"i-progress-circle",children:[e("svg",{width:a,height:a,children:[t("circle",{cx:a/2,cy:a/2,r:a/2-r/2,fill:"none",stroke:"var(--background-opacity-2)",strokeWidth:r}),t("circle",{cx:a/2,cy:a/2,r:a/2-r/2,fill:"none",stroke:"var(--color-main)",strokeWidth:r,strokeDasharray:100,pathLength:100,className:"i-progress-circle-path",strokeLinecap:"round",style:{strokeDashoffset:`calc(100 - ${i})`}})]}),e("span",{className:"i-progress-circle-value",children:[t("span",{children:i}),t(Mt,{size:".81em",className:"color-7",children:"%"})]})]})}Mt.Number=function(e){const{count:n,to:i,decimal:a,thousand:r=",",duration:s=2400,easing:l,...o}=e,[c,d]=g(n),p=f((()=>{if(void 0===c)return;const e=c.toFixed(a);return r?Be(c,{precision:a,thousand:r}):e}),[c,r]);return u((()=>{void 0!==n&&void 0!==i&&function(e,t,n=1e3,i,a=e=>1-Math.pow(1-e,4)){const r=performance.now(),s=t-e;let l=requestAnimationFrame((function e(){l=requestAnimationFrame(e);let t=(performance.now()-r)/n;t>=1&&(t=1,cancelAnimationFrame(l));const o=s*a(t);i?.(o)}))}(n,i,s,(e=>d(n+e)),l)}),[i]),u((()=>d(n)),[n]),t(Mt,{...o,children:p})},Mt.Time=function(e){const{seconds:n,zero:i,units:a,...r}=e,s=f((()=>void 0===n?"":function(e,t){const n=[],{zero:i=!0,units:a=["",":",":"]}=t||{},r=a.length;let s=0;for(;s<r&&!(e<=0&&s>1);){const t=Math.round(e%60);e=Math.floor(e/60),n.unshift((i&&t<10?`0${t}`:t)+a[s++])}return n.join("")}(n,{zero:i,units:a})),[n]);return t(Mt,{...r,children:s})};const St=c(((e,n)=>{const{value:a,size:r,barClass:s,dragging:l,renderCursor:o,onMouseDown:c}=e;return t("div",{ref:n,className:"i-progress",style:{height:r},onMouseDown:c,children:t("div",{className:i("i-progress-bar",s,{"no-transition":l}),style:{width:`${a}%`},children:o&&t("a",{className:"i-progress-cursor",children:o(a??0)})})})})),jt=n=>{const{value:a=0,size:r=8,height:s=40,precision:l=0,style:o,draggable:c=!0,type:d="line",barClass:p,label:m,labelInline:h,className:g,renderCursor:v,onChange:y}=n,N=b(null),k=ae({value:a,dragging:!1,width:0,start:0}),C=f((()=>{let e=+k.value.toFixed(l);return e=Math.min(100,e),e=Math.max(0,e),e}),[k.value,l]),w=re((e=>{if(!N.current||!c)return;const t=N.current.getBoundingClientRect(),n=100*(e.pageX-t.left)/t.width;Object.assign(k,{value:n,width:t.width,start:t.left,dragging:!0})})),x=re((e=>{if(!k.dragging||!c)return;e.preventDefault();const{start:t,width:n}=k,i=e.pageX-t;i<0||i>n||(k.value=100*(e.pageX-t)/n)})),$=re((()=>{k.dragging&&c&&(y?.(C),k.dragging=!1)}));return _e(x),Je($),u((()=>{k.value=a>100?100:a<0?0:a}),[a]),e("div",{className:i("i-input-label",g,{"i-input-inline":h}),style:o,children:[m&&t("span",{className:"i-input-label-text",children:m}),"line"===d&&t(St,{ref:N,size:r,barClass:p,dragging:k.dragging,value:k.value,renderCursor:v,onMouseDown:w}),"circle"===d&&t(Dt,{value:k.value,height:s,size:r})]})},Et=c(((n,a)=>{const{style:r,hideControls:s,autoplay:l,muted:o,volume:c=50,height:d,width:p,useOriginControls:m,timeProgressProps:h={barClass:"bg-2"},volumeProgressProps:g={barClass:"bg-1"},className:f,onFullScreenChange:v,...y}=n,N=ae({playing:l,volume:o?0:c,volumeCache:0,muted:o,current:0,duration:0,isFullscreen:!1}),k=b(null),C=e=>{const t=e.target;t.paused||Object.assign(N,{current:t.currentTime})},x=e=>{N.playing=!e.target.paused},$=()=>{const e=k.current?.parentElement;e&&(N.isFullscreen=document.fullscreenElement===e)},T=e=>{const t=e.target;Object.assign(N,{volume:100*t.volume,muted:0===t.volume})},I=()=>{const e=k.current;e&&(e.paused?e.play():e.pause())},P=()=>{const e=k.current;e&&(e.currentTime=0,e.pause())},z=()=>{const e=k.current?.parentElement;var t;e&&(N.isFullscreen?document.exitFullscreen?.():(t=e,t.requestFullscreen?.()),v?.(!N.isFullscreen))};return w(a,(()=>({play:()=>{const e=k.current;e&&e.play()},pause:()=>{const e=k.current;e&&e.pause()},stop:P,fullscreen:z,getVideo:()=>k.current}))),u((()=>{const e=k.current;if(e)return e.addEventListener("timeupdate",C),e.addEventListener("play",x),e.addEventListener("pause",x),e.addEventListener("volumechange",T),document.addEventListener("fullscreenchange",$),()=>{e.removeEventListener("timeupdate",C),e.removeEventListener("play",x),e.removeEventListener("pause",x),e.removeEventListener("volumechange",T),document.removeEventListener("fullscreenchange",$)}}),[]),e("div",{className:i("i-video",f),style:{height:d,width:p,...r},onClick:I,onDoubleClick:()=>z(),children:[t("video",{ref:k,onCanPlay:e=>{const t=e.target;Object.assign(N,{duration:t.duration,current:t.currentTime}),t.volume=N.volume/100},...y,controls:m}),!s&&!m&&e("div",{className:"i-video-controls",onClick:e=>e.stopPropagation(),children:[e("div",{className:"i-video-control flex-1",children:[t(Ne.Toggle,{className:"i-video-btn",flat:!0,square:!0,after:t(ke,{icon:t(E,{})}),active:N.playing,onClick:I,children:t(ke,{icon:t(B,{})})}),t(Ne,{className:"i-video-btn",flat:!0,square:!0,onClick:P,children:t(ke,{icon:t(Y,{})})}),e("span",{className:"i-video-times",children:[t(Mt.Time,{seconds:N.current})," /",t(Mt.Time,{seconds:N.duration})]}),t(jt,{className:"mr-8",...h,value:N.current/N.duration*100,onChange:e=>{const t=k.current;t&&(t.currentTime=N.duration*e/100)}})]}),t("div",{className:"i-video-control",children:t(Ne.Toggle,{className:"i-video-btn",flat:!0,square:!0,after:t(ke,{icon:t(A,{})}),active:N.isFullscreen,onClick:()=>z(),children:t(ke,{icon:t(L,{})})})}),e("div",{className:"i-video-control",children:[t(Ne.Toggle,{className:"i-video-btn",flat:!0,square:!0,active:N.volume<=0,after:t(ke,{icon:t(V,{}),size:"1.2em"}),onClick:()=>{const e=k.current;if(e)return e.volume>0?(N.volumeCache=e.volume,void(e.volume=0)):void(e.volume=0===N.volumeCache?.5:N.volumeCache)},children:t(ke,{icon:t(W,{})})}),t(jt,{style:{width:100},className:"mr-8",...g,value:N.volume,onChange:e=>{const t=k.current;t&&(t.volume=e/100)}})]})]})]})}));function Bt(n){const{name:i,suffix:a,type:r}=n;switch(r){case Me.IMAGE:return t("img",{src:n.src});case Me.VIDEO:return t(Et,{...n});default:return e("div",{className:"i-preview-unknown",children:[t(ke,{icon:t(q,{}),size:"3em"}),t("h5",{className:"mt-4",children:i||a||"?"})]})}}function Yt(i){const{items:a=[],initial:r=0,renderFile:l=Bt,onRotate:o,onChange:c,onClose:d,onZoom:u}=i,p=ae({current:r,rotate:0,scale:1,translate:"0, 0"}),m=b(null),h=f((()=>a.map((e=>{const t={src:""};return"string"==typeof e?t.src=e:Object.assign(t,e),t.suffix=Ae(t.src)||"",t.type=Le(t.suffix,e.type),t}))),[a]),{file:g,content:v}=f((()=>{const e=h[p.current];return{file:e,content:l(e)}}),[p.current,a]),y=g.type===Me.IMAGE,N=e=>{const t=h.length,{current:n}=p;p.current=e>=t?0:e<0?t-1:e,c?.(p.current,n),p.rotate=h[p.current].rotate||0,1!==p.scale&&(p.scale=1,u?.(1)),o?.(p.rotate)},k=e=>{p.rotate+=e,o?.(p.rotate)},C=s({interval:60},(e=>{if(!y)return;let t=p.scale+(e.deltaY<0?.05:-.05);t>2&&(t=2),t<.25&&(t=.25),u?.(t),p.scale=t}));return e(n,{children:[t("div",{ref:m,className:"i-preview-content",style:{transform:`rotate(${p.rotate}deg) scale(${p.scale})`},onWheel:C,onClick:e=>e.stopPropagation(),children:v}),e("div",{className:"i-preview-controls",children:[t(Ne,{square:!0,flat:!0,onClick:d,children:t(ke,{icon:t($,{})})}),h.length>1&&e("span",{className:"px-8",children:[p.current+1," / ",h.length]}),1!==p.scale&&e(Ne,{flat:!0,onClick:()=>p.scale=1,children:[t(ke,{icon:t(F,{})}),e("span",{className:"mt-4",children:[(100*p.scale).toFixed(0),"%"]})]}),t(Ne,{square:!0,flat:!0,href:g.src,target:"_blank",children:t(ke,{icon:t(H,{})})}),t(Ne,{square:!0,flat:!0,href:g.src,download:!0,target:"_blank",children:t(ke,{icon:t(R,{})})}),t(Ne,{square:!0,flat:!0,onClick:()=>k(90),children:t(ke,{icon:t(X,{})})}),t(Ne,{square:!0,flat:!0,onClick:()=>k(-90),children:t(ke,{icon:t(U,{})})}),h.length>1&&e(n,{children:[t(Ne,{square:!0,flat:!0,onClick:()=>N(p.current-1),children:t(ke,{icon:t(D,{})})}),t(Ne,{square:!0,flat:!0,onClick:()=>N(p.current+1),children:t(ke,{icon:t(S,{})})})]})]})]})}function At(){const e=b(null);return n=>{const{items:i,modalProps:a,onClose:r,...s}=n,l=Ye(t(Ot,{ref:e,visible:!0,className:"i-preview",customized:!0,shadow:!1,...a,children:t(Yt,{...s,items:i,onClose:()=>{e.current?.update({visible:!1})}}),fixed:!0,onClose:()=>{r?.(),l?.()}}))}}const Lt=a=>{const{src:r,round:s,size:l,initSize:o,lazyload:c,fallback:d=t(ke,{icon:t(G,{}),size:"2em",className:"color-5"}),fit:p,style:m,className:h,children:g,usePreview:f,onLoad:v,onError:y,onClick:N,...k}=a,C=ae({status:"loading"}),w=b(null),x=p?"100%":void 0,{observe:$,unobserve:T}=Qe(),I=At();u((()=>{if(r&&(C.status="loading",c&&w.current))return $(w.current,((e,t)=>{t&&(e.setAttribute("src",e.dataset.src||""),T(e))})),()=>{w.current&&T(w.current)}}),[r]),k[c?"data-src":"src"]=r;const P="loading"===C.status?o:void 0;return t("div",{style:{width:l??P,height:l??P,...m},className:i("i-image",h,{rounded:s,[`i-image-${C.status}`]:C.status}),children:"error"===C.status?d:e(n,{children:[r&&t("img",{ref:w,style:{objectFit:p,width:x,height:x},...k,onLoad:e=>{v?.(e),C.status=void 0},onError:e=>{y?.(e),C.status="error"},onClick:e=>{N?.(e),f&&r&&I({items:[{src:r,type:Me.IMAGE}]})}}),r&&"loading"===C.status&&t(be,{}),g&&t("div",{className:"i-image-text",children:g})]})})};Lt.List=function(e){const{items:n=[],gap:i=8,columns:a,wrap:r,direction:s,usePreview:l,onClick:o,...c}=e,d=At(),u=f((()=>n.map((e=>{const t={src:""};return"string"==typeof e?t.src=e:Object.assign(t,e),t.suffix=Ae(t.src)||"",t.type=Le(t.suffix,e.type),t}))),[n]);return u.length?t(xt,{className:"i-image-list",gap:i,columns:a,wrap:r,direction:s,children:u.map(((e,n)=>t(Lt,{src:e.src,size:60,usePreview:!1,onClick:e=>((e,t)=>{o?.(e),l&&d({items:u,initial:t})})(e,n),...c},n)))}):""};const Vt={left:"flex-start",center:"center",right:"flex-end"},Wt=12,qt={duration:3e3,closable:!0,active:!1},Ft=function(){const e=document.createElement("div");return e.dataset.id="messages",document.body.append(e),e}(),Ht={callout(e){},close(){}},Rt={left:[],center:[],right:[]},Xt={left:[],center:[],right:[]};ce(Ft).render(t((function(){const i=b(null),a=ae({items:{left:[],center:[],right:[]},tops:{left:[],center:[],right:[]}}),r={left:0,center:0,right:0};u((()=>{Object.assign(Ht,{callout:function(e){const{align:t="center",unshift:n,onShow:r}=e,s=Rt[t][n?"unshift":"push"](e);a.items[t]=[...Rt[t]],setTimeout((()=>{const e=i.current?.offsetHeight||0;Rt[t][n?0:s-1].active=!0,a.items[t]=[...Rt[t]],Xt[t][n?"unshift":"push"](e),a.tops[t]=[...Xt[t]],r?.()}),0),0!==e.duration&&setTimeout(this.close.bind(e),e.duration)},close:function(){const e=this,{align:t="center",onHide:n}=e,i=Rt[t].findIndex((t=>t.id===e.id));i<0||(Rt[t][i].active=!1,a.items[t]=[...Rt[t]],e.timer=setTimeout((()=>{const i=Rt[t].findIndex((t=>t.id===e.id));Rt[t].splice(i,1),Xt[t].splice(i,1),a.tops[t]=[...Xt[t]],a.items[t]=[...Rt[t]],e.timer&&clearTimeout(e.timer),n?.()}),240))}})}),[]);const s=(e,s)=>{if(!e)return t(n,{});const{id:l,active:o,content:c,align:d="center",className:u}=e;r[d]+=a.tops[d][s-1]||0;const p=Wt*s+r[d];return t(Ut,{ref:i,active:o,content:c,top:p,className:u,style:{alignSelf:Vt[d]},onClick:Ht.close.bind(e)},l)};return e("div",{className:"i-messages",children:[a.items.left.map(s),a.items.center.map(s),a.items.right.map(s)]})}),{}));const Ut=c((function({active:e,content:n,top:a,className:r,style:s,onClick:l},o){return t("div",{ref:o,className:i("i-message",r,{"i-message-active":e}),style:{...s,top:a},onClick:l,children:n})}));function Gt(e){return(["string","number"].includes(typeof e)||m(e))&&(e={content:e}),e=Object.assign({id:r(7)},qt,e),Ht.callout(e),Ht.close.bind(e)}zt.useModal=function(){const e=b(null);return{open:n=>{const i=Ye(t(Ot,{ref:e,visible:!0,...n,onClose:()=>{n.onClose?.(),i?.()}}))},update:t=>{if(!e.current)return;const{update:n}=e.current;n(t)}}};const Kt=n=>{const{page:a,active:r,children:s,onChange:l}=n,[o,c]=g(!1);return e("a",{className:i("i-page",{"i-page-active":r,"i-page-loading":o,"i-page-disabled":!1}),"data-page":a,onClick:async()=>{r||o||(c(!0),await(l?.(a)),c(!1))},children:[o&&t(be,{}),s]})},Zt=a=>{const{page:r=1,size:s=10,total:l=0,sibling:o=2,prev:c=t(ke,{icon:t(D,{})}),next:d=t(ke,{icon:t(S,{})}),simple:p,jumper:m,className:h,renderEllipsis:v=()=>t(ke,{icon:t(K,{}),className:"color-7"}),renderPage:b=e=>e,onChange:y,...N}=a,[k,C]=g(r),[w,x]=g(!1),$=f((()=>Math.ceil(l/s)),[s,l]),[T,I,P]=f((()=>{const e=Math.max(1,k-o),t=Math.min($,k+o);return[e,t,Array.from({length:t-e+1}).map(((t,n)=>e+n))]}),[k,$,o]);if($<=k&&1===k)return t(n,{});const z=async e=>{if(y&&!w)return x(!0),new Promise((async t=>{void 0!==e&&(await y(e),C(e),x(!1),t())}))};return u((()=>C(r)),[r]),e("div",{className:i("i-pagination",h),...N,children:[c&&t(Kt,{page:k-1||1,onChange:z,children:c}),T>1&&t(Kt,{page:1,onChange:z,children:b(1)}),T>2&&v(),P.map((e=>t(Kt,{page:e,active:e===k,onChange:z,children:b(e)},e))),I<$-1&&v(),I<$&&t(Kt,{page:$,onChange:z,children:b($)}),d&&t(Kt,{page:k+1,onChange:z,children:d})]})},_t={children:"确定"},Jt={children:"取消",secondary:!0},Qt=n=>{const{trigger:i="click",visible:a,icon:r=t(ke,{icon:t(Z,{}),className:"error"}),content:s,okButtonProps:l,cancelButtonProps:o,children:c,align:d="end",position:u="top",offset:p=12,extra:m,onOk:h,onClose:g,...f}=n,v=ae({loading:!1,visible:a}),b=l?Object.assign({},_t,l):_t,y=o?Object.assign({},Jt,o):Jt,N=e("div",{className:"i-popconfirm",children:[e(xt,{gap:12,children:[r,t("div",{className:"i-popconfirm-content",children:s})]}),e(xt,{gap:12,justify:"flex-end",className:"mt-8 i-popconfirm-footer",children:[null!==o&&t(Ne,{...y,onClick:async e=>{y.onClick?.(e),await(g?.()),v.visible=!1}}),m,null!==l&&t(Ne,{loading:v.loading,...b,onClick:async e=>{v.loading=!0,b.onClick?.(e),await(h?.()),v.loading=!1,v.visible=!1}})]})]});return t(ut,{content:N,...f,trigger:i,visible:v.visible,align:d,offset:p,position:u,onVisibleChange:e=>{v.visible=e,f.onVisibleChange?.(e)},children:c})};function en(n){const{type:a="default",name:r,value:s,checked:l,disabled:o,children:c,onChange:d}=n;return e("label",{className:i("i-radio-item",{disabled:o}),children:[t("input",{type:"radio",name:r,checked:l,className:i("i-radio-input",`i-radio-${a}`),disabled:o,onChange:e=>{d?.(s,e)}}),t("span",{className:"i-radio-text",children:c})]})}function tn(n){const{label:a,name:r,options:s,value:l,type:o="default",status:c="normal",message:d,optionInline:p=!0,labelInline:m,disabled:h,required:g,className:v,onChange:b}=n,y=ae({value:l}),N=f((()=>Ee(s)),[s]),k=re(((e,t)=>{y.value=e,b?.(e,t)}));return u((()=>{y.value=l}),[l]),e("div",{className:i("i-radio i-input-label",{[`i-radio-${c}`]:"normal"!==c,"i-input-inline":m},v),children:[a&&e("span",{className:"i-input-label-text",children:[g&&t("span",{className:"error",children:"*"}),a,d&&t("p",{className:"i-radio-message",children:d})]}),t("div",{className:i("i-radio-options",{"i-options-block":!p,"i-radio-options-button":"button"===o}),children:N.map((e=>t(en,{name:r,value:e.value,checked:y.value===e.value,type:o,disabled:h||e.disabled,onChange:k,children:e.label},e.value)))})]})}tn.Item=en;const nn=n=>{const{dot:a,dotClass:r,outline:s,round:l,size:o="normal",className:c,children:d,onClose:u,onClick:p,...m}=n;return e("span",{className:i("i-tag",{"i-tag-outline":s,"i-tag-clickable":p,[`i-tag-${o}`]:"normal"!==o,round:l},c),onClick:p,...m,children:[a&&t("span",{className:i("i-tag-dot",r)}),d,u&&t(He,{active:!0,className:"i-tag-close",onClick:u})]})},an=n=>{const{value:a,options:r,filter:s,filterPlaceholder:l,multiple:o,empty:c=t(Xe,{}),onSelect:d,onFilter:u}=n;return e("div",{className:i("i-select-options",{"i-select-options-multiple":o}),children:[s&&o&&e("div",{className:"i-select-filter",children:[t(ke,{icon:t(_,{}),className:"color-8 ml-8 my-auto",size:"1.2em"}),t("input",{type:"text",className:"i-input",placeholder:l,onChange:u})]}),0===r.length&&c,r.map(((n,i)=>{const{label:r,value:s,disabled:l}=n,c=o?a?.includes(s):a===s;return e(kt.Item,{active:c,type:"option",onClick:()=>d?.(s,n),disabled:l,children:[o&&t(ke,{icon:t(J,{}),className:"i-select-option-check",size:"1em"}),r]},s||i)}))]})},rn=n=>{const{options:i,value:a,maxDisplay:r,multiple:s,onSelect:l}=n;return s?((e=[],t=[],n=3)=>{const i=e.flatMap((e=>t.includes(e.value)?[e]:[]));if(n>=i.length)return i;const a=i.length-n,r=i.slice(0,n);return r.push(a),r})(i,a,r).map(((n,i)=>{if("number"==typeof n)return e(nn,{children:["+",n]},i);const{label:a,value:r}=n;return t(nn,{onClose:e=>{e?.stopPropagation(),l?.(r,n)},children:a},r)})):i.find((e=>e.value===a))?.label},sn=c(((n,r)=>{const{type:s="text",name:l,label:o,value:c="",placeholder:d,options:m=[],multiple:h,prepend:v,append:b,labelInline:y,style:N,className:k,message:C,status:w="normal",hideClear:x,maxDisplay:$,border:T,filter:I,tip:P,filterPlaceholder:z="...",popupProps:O,onSelect:M,onChange:D,...S}=n,j=ae({inputValue:"",filterValue:"",value:c,loading:!1}),[E,B]=g(!1),Y=f((()=>Ee(m)),[m]),A=f((()=>{const{filterValue:e}=j;if(!e||!I)return Y;const t="function"==typeof I?I:t=>t.value.includes(e)||t.label.includes(e);return Y.filter(t)}),[Y,I,j.filterValue]),L=e=>{j.value=e,D?.(e)},V=p(((e,t)=>{if(M?.(e,t),h){const t=[...j.value],n=t.findIndex((t=>t===e));return n>-1?t.splice(n,1):t.push(e),void L(t)}B(!1),L(e)}),[]),W=re(a({delay:400},(e=>{const t=e.target.value;j.filterValue=t})));u((()=>{j.value=c}),[c]);const q=h?j.value.length>0:!!j.value,F=!x&&E&&q,H=C??P;return e("label",{className:i("i-input-label",k,{"i-input-inline":y}),style:N,children:[o&&t("span",{className:"i-input-label-text",children:o}),t(ut,{position:"bottom",arrow:!1,fitSize:!0,...O,visible:E,trigger:"none",onVisibleChange:e=>{B(e),I&&(j.filterValue="")},content:t(an,{options:A,value:j.value,multiple:h,filter:!!I,filterPlaceholder:z,onSelect:V,onFilter:W}),children:e("div",{className:i("i-input-item",{[`i-input-${w}`]:"normal"!==w,"i-input-borderless":!T,"i-input-focus":E}),onClick:()=>B(!0),children:[v,t("input",{ref:r,type:"hidden",value:j.value,...S}),h?q?t("div",{className:i("i-input i-select",{"i-select-multiple":h}),children:rn({options:Y,value:j.value,multiple:h,maxDisplay:$,onSelect:V})}):t("input",{className:"i-input i-select",placeholder:d,readOnly:!0}):null,!h&&t("input",{value:E?j.filterValue:j.value,className:"i-input i-select",placeholder:j.value||d,onChange:e=>{j.filterValue=e.target.value},readOnly:!I}),t(He,{active:!0,icon:F?void 0:t(Q,{}),onClick:e=>{E&&L(h?[]:"")}}),b]})}),H&&t("span",{className:"i-input-message",children:H})]})}));function ln(){return t("i",{className:"i-step-divider"})}const on=["finished","active","pending"];function cn(e,n){return t("span",{className:"i-step-item-index",children:"finished"===n?t(J,{style:{width:"1em",height:"1.5em"}}):e+1})}function dn(a){const{index:r=0,active:s=0,renderIcon:l=cn,title:o,vertical:c,line:d=t(ln,{}),style:u,className:p,children:m,onClick:h}=a,g=on[r===s?1:r<s?0:2];return t("div",{style:u,className:i("i-step-item",`i-step-item-${g}`,p),onClick:()=>{h?.(r)},children:e(n,c?{children:[e("div",{className:"i-step-item-left",children:[l?.(r,g),d]}),e("div",{className:"i-step-item-right",children:[t("div",{className:"i-step-item-title",children:o}),m&&t("div",{className:"i-step-item-content",children:m})]})]}:{children:[e("div",{className:"i-step-item-title",children:[l?.(r,g),t("span",{children:o}),d]}),m&&t("div",{className:"i-step-item-content",children:m})]})})}const un=e=>{const{active:n=0,vertical:a,renderIcon:r,line:s,style:l,className:o,children:c,onClick:d}=e,u=f((()=>{const e=[];let t=0;return v.map(c,(i=>{if(!i||i.type!==dn)return;const{props:l}=i;e.push({...i,props:{renderIcon:r,line:s,onClick:d,...l,vertical:a,active:n,index:t++}})})),e}),[n,c]);return t("div",{className:i("i-step",{"i-step-vertical":a},o),style:l,children:u})};function pn(e){const{index:n=0,active:a,type:r,transition:s,gap:l=0,itemHeight:o,vertical:c,style:d,className:u,children:p}=e,m=f((()=>"normal"===r?{[c?"paddingBlock":"paddingInline"]:l/2,height:o}:{transform:`translate(-${100*n}%, 0)`,transition:s}),[n,l,o,c,r]);return t("div",{style:{...d,...m},className:i("i-swiper-item",u,{"i-swiper-active":a}),"data-index":n,children:p})}un.Item=dn;const mn=c(((a,r)=>{const{type:s="normal",initial:l=0,display:o=1,scroll:c=1,loop:d=!0,vertical:m,prev:h=t(ke,{icon:t(D,{}),size:"2em"}),next:g=t(ke,{icon:t(S,{}),size:"2em"}),duration:y=600,interval:N=3e3,autoplay:k,pauseOnHover:C,arrow:x=!0,reverse:$,draggable:T,dragOffset:I=40,gap:P=0,itemHeight:z,indicator:O,style:M,className:j,children:E,renderIndicator:B,onBeforeSwipe:Y,onAfterSwipe:A}=a,L=b(null),V=b(null),W=`all ${y/1e3}s`,q=ae({current:l,swipable:!0,transition:"fade"===s?"none":W,dragStart:0,dragging:!1,initialized:!1}),F=f((()=>v.map(E,(e=>{if(e.type===pn)return e}))),[E]),[H,R,X,U,G]=f((()=>{const e="normal"===s&&d&&F.length>o?o+1:0;let t=[];if(e<=0)t=[...F];else{const n=F.slice(0,e);t=[...F.slice(-e),...F,...n]}const n=t.length/o*100+"%";return[t,e,F.length,t.length,n]}),[o,d,s,F]),K=f((()=>-100*(q.current+R)/U),[q.current,U]),Z=f((()=>{if(X<=o||"fade"===s)return;return`translate3d(${m?`0, ${K}%`:`${K}%, 0`}, 0)`}),[K,m,o,X,s]),_=f((()=>{if(m&&z)return{height:z*o}}),[m,z,o]),J=f((()=>Array.from({length:Math.ceil((X-o)/c)+1})),[d,O]),Q=()=>{clearTimeout(V.current),V.current=null},ee=p((e=>{if(!q.swipable||e===q.current)return;q.swipable=!1,Y?.(q.current);let t=!1,n=e;const i=X-o;return d?e>i?(t=!0,e=X,n=0):e<0&&(t=!0,e=-o,n=i):(n=We(n,0,i),e=n),setTimeout((()=>{q.swipable=!0}),y+32),"fade"===s?(q.current=n,void A?.(n)):(q.current=e,t?void setTimeout((()=>{q.transition="none",q.current=n,A?.(n),k&&(V.current=setTimeout(te,N)),setTimeout((()=>{q.transition=W}),60)}),y+20):(k&&(V.current=setTimeout(te,N)),void setTimeout((()=>{A?.(n)}),y+12)))}),[y,k]),te=()=>{ee($?q.current-c:q.current+c)},ne=()=>{ee($?q.current+c:q.current-c)},ie=p((e=>{T&&q.swipable&&"fade"!==s&&(e.stopPropagation(),Object.assign(q,{dragStart:m?e.clientY:e.clientX,dragging:!0,transition:"none"}))}),[T,m]),re=p((e=>{if(!q.dragging||!L.current)return;e.preventDefault();const t=61.8*((m?e.clientY:e.clientX)-q.dragStart)/L.current[m?"offsetHeight":"offsetWidth"]+K;L.current.style.transform=`translate3d(${m?`0, ${t}%`:`${t}%, 0`}, 0)`}),[m,L.current,K]),se=p((e=>{if(!q.dragging||!L.current)return;const t=m?e.clientY:e.clientX,n=L.current[m?"offsetHeight":"offsetWidth"]/U,i=.618*(t-q.dragStart),a=Math.abs(i);if(a>I){const e=Math.floor(a/n)+(a%n-I>0?1:0);let t=q.current+(i>0?-e:e);ee(t)}L.current.style.transform=Z||"",Object.assign(q,{dragging:!1,transition:W})}),[m,L.current,K]);return _e(re),Je(se),w(r,(()=>({swipeTo:ee,swipeNext:te,swipePrev:ne}))),u((()=>{if(k)return V.current=setTimeout(te,N),()=>{clearTimeout(V.current),V.current=null}}),[k,N]),e("div",{style:M,className:i("i-swiper",{"i-swiper-vertical":m,"i-swiper-initialized":q.initialized},j),children:[e("div",{className:"i-swiper-track",style:_,onMouseOver:()=>{C&&Q()},onMouseLeave:()=>{C&&(Q(),V.current=setTimeout(te,N))},children:[t("div",{ref:L,className:i("i-swiper-list",{"i-swiper-fade":"fade"===s}),style:{[m?"height":"width"]:G,transform:Z,transition:q.transition},onMouseDown:ie,children:H.map(((e,n)=>{const{props:i}=e;return t(pn,{index:n,active:n-R===q.current,type:s,gap:P,transition:W,itemHeight:z,vertical:m,...i},n)}))}),x&&e(n,{children:[t("a",{className:"i-swiper-arrow i-swiper-prev",onClick:ne,children:h}),t("a",{className:"i-swiper-arrow i-swiper-next",onClick:te,children:g})]})]}),O&&t("div",{className:"i-swiper-indicators",children:J.map(((e,n)=>t("a",{className:i("i-swiper-indicator",{"i-indicator-active":n===Math[d?"floor":"ceil"]((q.current+X)%X/c)}),onClick:()=>ee(n*c),children:B?.(n)},n)))})]})}));mn.Item=pn;const hn=c(((n,a)=>{const{active:r,tabs:s,type:o="default",prepend:c,append:d,children:p,className:m,vertical:h,toggable:g,bar:f=!0,hideMore:y,barClass:N,renderMore:k=()=>t(Ne,{flat:!0,square:!0,size:"small",children:t(ke,{icon:t(K,{})})}),onTabChange:C,...x}=n,$=b([]),T=b(null),I=b(null),P=ae({active:r,prevActive:void 0,barStyle:{},cachedTabs:[],overflow:!1,more:[],tabs:[]}),{observe:z,unobserve:O}=Qe(),M=oe(I);u((()=>{if(!s)return p?void(P.tabs=v.map(p,((e,t)=>{const{key:n,props:i}=e,{title:a,children:r,content:s,keepDOM:o}=i,c=r?l(r,["props","type","$$typeof","ref"]):s;return{key:n||String(t),title:a,content:c,keepDOM:o}}))):void(P.tabs=[]);P.tabs=s.map(((e,t)=>["string","number"].includes(typeof e)?{key:e,title:e}:(void 0===e.key&&(e.key=t),e)))}),[p,s]);const D=e=>{const{key:t}=e,n=P.tabs.findIndex((e=>e.key===t));if(n>-1)return void j(P.tabs[n].key??n);const i=P.tabs.length,a=e.key??i;P.tabs.push({...e,key:a}),j(a)},S=e=>{const t=P.tabs.findIndex((t=>t.key===e));if(t<0)return;if(P.tabs.splice(t,1),P.active!==e)return;const n=P.tabs[t]||P.tabs[t-1];j(P.prevActive??n?.key??"")},j=e=>{if(e===P.active){if(!g)return;return C?.(void 0,e),P.active=void 0,void(P.barStyle={height:0,width:0})}P.prevActive=P.active,C?.(e,P.active),P.active=e},E=e=>{e.stopPropagation(),e.preventDefault(),h||I.current?.scrollBy({left:e.deltaY+e.deltaX})};return u((()=>{if(!M||y)return;const{scrollHeight:e,scrollWidth:t}=I.current,{width:n,height:i}=M;P.overflow=e>i||t>n,P.overflow&&$.current.map(((e,t)=>{e&&z(e,((e,n)=>{P.tabs[t]&&(P.tabs[t].intersecting=n,P.more=P.tabs.filter((e=>!e.intersecting)))}))}))}),[M,y,P.tabs.length]),u((()=>{if(!f||"pane"===o||void 0===P.active)return;const e=P.tabs.findIndex((e=>e.key===P.active));setTimeout((()=>{const t=$.current[e];if(!t)return;if(P.tabs[e].keepDOM&&P.active){P.cachedTabs.findIndex((e=>e===P.active))<0&&P.cachedTabs.unshift(P.active)}const{offsetHeight:n,offsetLeft:i,offsetTop:a,offsetWidth:r}=t,s="line"===o;P.barStyle={height:!h&&s?".25em":n,width:h&&s?".25em":r,transform:`translate(${i}px, ${a}px)`}}),16)}),[P.active,f]),u((()=>{void 0!==r&&P.active!==r&&j(r)}),[r]),u((()=>{if(!y)return()=>{$.current?.map(O)}}),[P.tabs.length]),u((()=>{if(I.current&&!h)return I.current.addEventListener("wheel",E,{passive:!1}),()=>{I.current&&I.current.removeEventListener("wheel",E)}}),[I.current]),w(a,(()=>({open:j,close:S,add:D,navs:I}))),e("div",{className:i("i-tabs",{flex:h,[`i-tabs-${o}`]:"default"!==o},m),...x,children:[e("div",{className:i("i-tab-navs-container",{"i-tab-navs-vertical":h}),children:[c,e("div",{ref:I,className:"i-tab-navs",children:[P.tabs.map(((n,a)=>{const{title:r,key:s=a,closable:l}=n;return e("a",{ref:e=>$.current[a]=e,className:i("i-tab-nav",{"i-tab-active":P.active===s}),onClick:()=>j(s),children:[r,l&&t(He,{as:"i",active:!0,className:"i-tab-nav-close",onClick:e=>{e.stopPropagation(),S(s)}})]},s)})),f&&t("span",{ref:T,className:i("i-tab-navs-bar",N),style:P.barStyle})]}),!y&&P.overflow&&P.more.length>0&&t(ut,{arrow:!1,position:h?"right":"bottom",align:"end",touchable:!0,hideDelay:500,content:t("div",{className:"i-tabs-morelist pd-4",children:P.more.map(((e,n)=>{const{key:a=n,title:r}=e,s=P.active===a;return t("a",{className:i("i-tab-nav",{"i-tab-active":s}),onClick:()=>j(a),children:r},a)}))}),children:k(P.more)}),d]}),t("div",{className:"i-tab-contents",children:P.tabs.map(((e,n)=>{const{key:a=n,content:r}=e,s=P.active===a;return(s||void 0!==a&&P.cachedTabs.includes(a))&&t("div",{className:i("i-tab-content",{"i-tab-active":s}),children:r},a)}))})]})}));function gn(e){const{data:a=[],depth:r=0,round:s,style:l,className:o,parent:c,nodeProps:d,...u}=e,p=a.map(((e,n)=>{const{type:i}=e,a=e[d.title],s=e[d.key]||(void 0!==c?.key?`${c.key}-${n}`:`${n}`);return e.key=s,e.parent=c,"title"===i?t("div",{className:"i-tree-group-title",children:a},n):i&&"item"!==i?t("div",{className:`i-tree-type-${i}`,children:a},n):t(vn,{index:n,item:e,depth:r,nodeProps:d,...u},s)}));return r>0?t(n,{children:p}):t("div",{className:i("i-tree",o,{"i-tree-round":s}),style:l,children:p})}hn.Item=e=>t(n,{});const fn=e=>{const{as:n="a",href:a,selected:r,children:s,...l}=e,o=i("i-tree-item-header",{"i-tree-item-selected":r});return t(n,"string"==typeof n?{href:a,className:o,...l,children:s}:{to:a||"",className:o,...l,children:s})},vn=n=>{const{item:a,depth:r=0,index:s,selected:l,checked:o=[],partofs:c={},checkable:d,nodeProps:u,renderExtra:p,onItemClick:m,onItemSelect:h,onItemCheck:f,...v}=n,{as:b,key:y="",href:N,icon:k,title:C,expanded:w,disabled:x}=a,$=a[u.children],[T,I]=g(w),P=re(((e,t)=>{t&&(e.preventDefault(),e.stopPropagation()),!x&&$?.length&&I((e=>!e))})),z=re((e=>{if(x)return e.preventDefault(),void e.stopPropagation();P(e),m?.(a,e),h?.(y,a)})),O=o.includes(y);return e("div",{className:i("i-tree-item",{"i-tree-expand":T}),children:[e(fn,{as:b,href:N,style:{paddingLeft:1.5*r+.5+"em"},selected:l===y,onClick:z,children:[d&&t(Fe.Item,{value:O,partof:!O&&c[y],className:"i-tree-checkbox",onChange:e=>f?.(a,e,[]),onClick:e=>e.stopPropagation()}),k&&t("span",{className:"i-tree-item-icon",children:k}),t("span",{className:"i-tree-item-title",children:C}),p?.(a),$&&t(ke,{icon:t(ee,{}),className:"i-tree-toggle",onClick:e=>P(e,!0)})]}),$?.length&&t("div",{className:"i-tree-item-content",children:t(gn,{data:$,depth:r+1,selected:l,checkable:d,parent:a,partofs:c,checked:o,nodeProps:u,renderExtra:p,onItemClick:m,onItemSelect:h,onItemCheck:f,...v})})]})},bn={key:"key",title:"title",children:"children"},yn=c(((e,n)=>{const{data:i=[],selected:a,checked:r=[],disabledRelated:s,nodeProps:l,onItemSelect:o,onItemCheck:c,...d}=e,p=ae({selected:a,checked:r,partofs:{},nodeMaps:new Map}),m=Object.assign({},bn,l),h=e=>p.checked.includes(e||""),g=re(((e,t,n)=>{const{key:i="",parent:a,children:r}=e,l={[i]:t},o={[i]:!1};if(s)return[l];if(t){if(a&&"leaf"!==n){const e=a.children?.some((e=>e.key!==i&&!h(e.key))),[t,n]=g(a,!0,"root");e||Object.assign(l,t),Object.assign(o,e?n:{},{[a.key]:!0})}return r?.length&&"root"!==n&&r.map((e=>{if(h(e.key))return;const[t]=g(e,!0,"leaf");Object.assign(l,t),o[e.key]=!1})),[l,o]}if(a&&"leaf"!==n){const[e,t]=g(a,!1,"root");Object.assign(l,e);const n=a.children?.some((e=>h(e.key)&&e.key!==i));Object.assign(o,n?{}:t,{[a.key]:n,[i]:!1})}return r?.length&&"root"!==n&&r.map((e=>{const[t]=g(e,!1,"leaf");h(e.key)&&(Object.assign(l,t),o[e.key]=!1)})),[l,o]}));return u((()=>{void 0!==a&&(p.selected=a)}),[a]),u((()=>{p.nodeMaps.clear();const{key:e,children:t}=m,n=i=>{i.map((i=>{p.nodeMaps.set(i[e],i),i[t]?.length>0&&n(i[t])}))};n(i)}),[i]),w(n,(()=>({getChecked:()=>{const e=[];return p.checked.map((t=>{const n=p.nodeMaps.get(t);e.push(n)})),[p.checked,e]},getSelected:()=>{const e=p.nodeMaps.get(p.selected);return[p.selected,e]},getPartofs:()=>{const e=[];return[Object.keys(p.partofs).filter((t=>{const n=p.partofs[t];if(n){const n=p.nodeMaps.get(t);e.push(n)}return n})),e]}}))),t(gn,{data:i,selected:p.selected,checked:p.checked,partofs:p.partofs,nodeProps:m,onItemCheck:(e,t)=>{const[n,i]=g(e,t),a=Object.keys(n);p.checked=t?Array.from(new Set([...p.checked,...a])):p.checked.filter((e=>!a.includes(e))),Object.assign(p.partofs,i),c?.(e,t,p.checked)},onItemSelect:(t,n)=>{e.selectable&&(p.selected=t,o?.(t,n))},...d})}));function Nn(i){const{mode:a,index:r,file:s,onRemove:l,onPreview:c}=i;if(!s)return"";const{name:d,size:u,url:p,src:m}=s,h=Le(d,s.type),g=t(He,{active:!0,className:"i-upload-delete",onClick:e=>{e.stopPropagation(),e.preventDefault(),l(r)}});if("card"===a){let i=t(n,{});switch(h){case Me.IMAGE:i=t(Lt,{lazyload:!0,src:p||m,fit:"cover",usePreview:!1});break;case Me.VIDEO:i=t("video",{src:p||m,preload:"none"});break;default:i=e(n,{children:[t(ke,{icon:t(te,{})}),t("span",{className:"i-upload-file-name",children:o(d)})]})}return e("div",{title:d,className:"i-upload-item-card",onClick:()=>c?.(r),children:[i,g]})}return e("div",{className:"i-upload-item",onClick:()=>c?.(r),children:[t("span",{children:d}),t("i",{className:"i-upload-size",children:Ve(u??0)}),g]})}const kn=c(((n,a)=>{const{label:s,labelInline:l,value:o,files:c=[],placeholder:d,status:p="normal",message:m,className:h,style:g,children:v,mode:y="default",cardSize:k="4em",disabled:C,limit:x=(n.multiple?1/0:1),multiple:$,renderItem:T=Nn,shouldUpload:I=()=>!0,uploader:P,onChange:z,onFilesChange:O,onUpload:M,...D}=n,S=ae({files:c,value:o,status:p,message:m,update:0}),j=b(null),E=At(),B=f((()=>v||("card"===y?t(Ne,{className:"i-upload-card-btn color-5",square:!0,flat:!0,outline:!0,disabled:C,children:t(ke,{icon:t(ie,{})})}):e(Ne,{className:"i-upload-btn",disabled:C,children:[t(ke,{icon:t(ne,{})})," Upload"]}))),[y,v]),Y=e=>{const[...t]=S.files,n=t.splice(e,1);URL.revokeObjectURL(n[0]?.src||""),S.files=t,O?.(t,n),z?.(t),j.current&&(j.current.value="")},A=async e=>{P&&e.forEach((async e=>{if(!I(e))return;const t=await P(e),n=S.files.findIndex((e=>e.uid===t.uid));n>-1&&(S.files[n]=t),"completed"===t?.status&&M?.(t)}))},L=e=>{E({items:S.files,initial:e})};u((()=>{Object.assign(S,{status:p,message:m})}),[p,m]),u((()=>{S.value=o}),[o]),w(a,(()=>({getFileList:()=>S.files})),[]);const{message:V,files:W}=S;return e(st,{label:s,labelInline:l,className:i("i-input-label-file",h),style:g,children:[t("input",{...D,disabled:C,ref:j,type:"file",className:"i-input-file-hidden",multiple:$,onChange:e=>{const t=Array.from(e.target.files||[]),{files:n}=S,i=[];t.map((e=>{const{name:t,size:a,type:s}=e,l=n.find((e=>{const{name:n,size:i,type:r}=e;return n===t&&i===a&&r===s})),o=URL.createObjectURL(e);e.src=o,S.update+=1,Object.assign(e,{uid:r(7),src:e.src||e.name}),!l&&i.push(e)}));const a=[...n,...i];Object.assign(S,{files:$?a.slice(0,x):[a.at(-1)],status:p,message:m}),O?.(S.files,i,e),z?.(S.files,e),A(i),j.current&&(j.current.value="")}}),e("div",{className:i("i-upload-inner",{[`i-upload-${y}`]:"default"!==y}),style:{"--upload-card-size":k},children:[t("div",{className:"i-upload-list",onClick:e=>{e.stopPropagation(),e.preventDefault()},children:W?.map(((e,n)=>t(N,{children:Nn({index:n,file:e,mode:y,onRemove:Y,onPreview:L})},n)))}),V&&t("span",{className:"i-upload-message",children:V}),W.length<x&&B]})]})}));export{we as Affix,xe as Badge,Ne as Button,Oe as Card,Fe as Checkbox,Re as Collapse,rt as Datagrid,vt as Datepicker,bt as Description,yt as Drawer,wt as Dropdown,xt as Flex,It as Form,ke as Icon,Lt as Image,lt as Input,kt as List,be as Loading,Gt as Message,zt as Modal,Zt as Pagination,Qt as Popconfirm,ut as Popup,jt as Progress,tn as Radio,sn as Select,un as Step,mn as Swiper,hn as Tabs,nn as Tag,Mt as Text,yn as Tree,kn as Upload,Et as Video,At as usePreview};
|
|
1
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { debounce, uid, throttle, pick, title } from 'radash';
|
|
4
|
+
import { forwardRef, createElement, useEffect, useCallback, isValidElement, cloneElement, useState, useMemo, Children, useRef, useLayoutEffect, Fragment as Fragment$1, createContext, useContext, useImperativeHandle } from 'react';
|
|
5
|
+
import { SkipPreviousRound, CloseRound, MinusRound, PlusRound, InboxTwotone, VisibilityRound, VisibilityOffRound, SyncAltRound, KeyboardArrowLeftRound, KeyboardArrowRightRound, CalendarMonthTwotone, PauseRound, PlayArrowRound, StopRound, FullscreenExitRound, FullscreenRound, VolumeOffRound, VolumeDownRound, FeedOutlined, AspectRatioRound, OpenInNewRound, FileDownloadOutlined, RotateRightRound, RotateLeftRound, HideImageTwotone, MoreHorizRound, InfoOutlined, SearchRound, CheckRound, UnfoldMoreRound, KeyboardArrowDownRound, ListAltRound, CloudUploadTwotone, PlusSharp } from '@ricons/material';
|
|
6
|
+
import { useReactive, useMemoizedFn, useClickAway, useCreation, useSize } from 'ahooks';
|
|
7
|
+
import { createRoot } from 'react-dom/client';
|
|
8
|
+
import ScrollContainer from 'react-custom-scrollbars-2';
|
|
9
|
+
import dayjs from 'dayjs';
|
|
10
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
11
|
+
import { createPortal } from 'react-dom';
|
|
12
|
+
import VList from 'rc-virtual-list';
|
|
13
|
+
import PubSub from 'pubsub-js';
|
|
14
|
+
|
|
15
|
+
const TIMEOUT = 500;
|
|
16
|
+
const useRipple = () => {
|
|
17
|
+
if (document.documentElement.dataset["useripple"])
|
|
18
|
+
return;
|
|
19
|
+
document.documentElement.dataset["useripple"] = "enable";
|
|
20
|
+
document.addEventListener("mousedown", listener);
|
|
21
|
+
};
|
|
22
|
+
function listener(e) {
|
|
23
|
+
const target = e.target;
|
|
24
|
+
const parent = target.closest("[data-ripple]");
|
|
25
|
+
if (!target || !parent)
|
|
26
|
+
return;
|
|
27
|
+
triggerRipple(parent, e);
|
|
28
|
+
}
|
|
29
|
+
function triggerRipple(target, e) {
|
|
30
|
+
const [$box, $ripple] = createRipple();
|
|
31
|
+
const rect = target.getBoundingClientRect();
|
|
32
|
+
const size = Math.max(rect.width, rect.height) * 2;
|
|
33
|
+
$ripple.style.cssText = `
|
|
34
|
+
left: ${e.pageX - rect.left}px;
|
|
35
|
+
top: ${e.pageY - rect.top}px;
|
|
36
|
+
width: ${size}px;
|
|
37
|
+
height: ${size}px;
|
|
38
|
+
transition: all ${TIMEOUT / 1000}s;
|
|
39
|
+
`;
|
|
40
|
+
target.insertAdjacentElement("afterbegin", $box);
|
|
41
|
+
target.offsetHeight;
|
|
42
|
+
$ripple.classList.add("i-ripple-active");
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
$box.remove();
|
|
45
|
+
}, TIMEOUT);
|
|
46
|
+
}
|
|
47
|
+
function createRipple() {
|
|
48
|
+
const $box = document.createElement("SPAN");
|
|
49
|
+
const $ripple = document.createElement("SPAN");
|
|
50
|
+
$box.className = "i-ripple-container";
|
|
51
|
+
$ripple.className = "i-ripple";
|
|
52
|
+
$box.append($ripple);
|
|
53
|
+
return [$box, $ripple];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const Loading = (props) => {
|
|
57
|
+
const { icon, text, size, style, className, ...restProps } = props;
|
|
58
|
+
return (jsxs("div", { className: classNames("i-loading-container", className), style: { fontSize: size, ...style }, ...restProps, children: [icon ?? (jsx("svg", { width: '24', height: '24', stroke: '#000', viewBox: '0 0 24 24', xmlns: 'http://www.w3.org/2000/svg', className: 'i-loading-icon', children: jsx("circle", { cx: '12', cy: '12', r: '9.5', fill: 'none', strokeWidth: '3', strokeLinecap: 'round', strokeDasharray: 40, strokeDashoffset: 0 }) })), text] }));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const formatClass = ({ outline, flat, loading, disabled, size = "normal", block, round, square, secondary, className, }) => classNames("i-btn", className, {
|
|
62
|
+
"i-btn-outline": outline,
|
|
63
|
+
"i-btn-flat": flat,
|
|
64
|
+
"i-btn-block": block,
|
|
65
|
+
"i-btn-loading": loading,
|
|
66
|
+
"i-btn-square": square,
|
|
67
|
+
"i-btn-secondary": secondary,
|
|
68
|
+
[`i-btn-${size}`]: size !== "normal",
|
|
69
|
+
round,
|
|
70
|
+
disabled,
|
|
71
|
+
});
|
|
72
|
+
const Button = forwardRef((props, ref) => {
|
|
73
|
+
const { as: As = "a", children, className, loading, flat, outline, square, secondary, size, round, href, ripple = true, onClick, ...restProps } = props;
|
|
74
|
+
const handleClick = (e) => {
|
|
75
|
+
if (loading || restProps.disabled) {
|
|
76
|
+
e.stopPropagation();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
onClick?.(e);
|
|
80
|
+
};
|
|
81
|
+
if (!children)
|
|
82
|
+
return jsx(Fragment, {});
|
|
83
|
+
const childNodes = [
|
|
84
|
+
loading && jsx(Loading, {}, 'loading'),
|
|
85
|
+
createElement("span", { key: "content", className: "i-btn-content" }, children),
|
|
86
|
+
];
|
|
87
|
+
const attrs = {
|
|
88
|
+
className: formatClass(props),
|
|
89
|
+
["data-ripple"]: ripple,
|
|
90
|
+
onClick: handleClick,
|
|
91
|
+
};
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
ripple && useRipple();
|
|
94
|
+
}, [ripple]);
|
|
95
|
+
if (typeof As === "string") {
|
|
96
|
+
return createElement(As, {
|
|
97
|
+
ref,
|
|
98
|
+
href,
|
|
99
|
+
...attrs,
|
|
100
|
+
...restProps,
|
|
101
|
+
}, childNodes);
|
|
102
|
+
}
|
|
103
|
+
return createElement(As, {
|
|
104
|
+
to: href || "",
|
|
105
|
+
...attrs,
|
|
106
|
+
...restProps,
|
|
107
|
+
}, childNodes);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
function Group(props) {
|
|
111
|
+
const { children, vertical, className, style } = props;
|
|
112
|
+
return (jsx("div", { className: classNames(className, vertical ? "i-btn-group-vertical" : "i-btn-group-horizonal"), style: style, children: children }));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function Toggle(props) {
|
|
116
|
+
const { active, activeClass, after, disabled, children, className, onClick, onToggle, ...restProps } = props;
|
|
117
|
+
const state = useReactive({
|
|
118
|
+
active,
|
|
119
|
+
done: true,
|
|
120
|
+
});
|
|
121
|
+
const toggle = useCallback(() => {
|
|
122
|
+
const hasAfter = after !== undefined;
|
|
123
|
+
const nextActive = !state.active;
|
|
124
|
+
Object.assign(state, {
|
|
125
|
+
active: nextActive,
|
|
126
|
+
done: !hasAfter,
|
|
127
|
+
});
|
|
128
|
+
onToggle?.(nextActive);
|
|
129
|
+
hasAfter &&
|
|
130
|
+
setTimeout(() => {
|
|
131
|
+
state.done = true;
|
|
132
|
+
}, 16);
|
|
133
|
+
}, [after]);
|
|
134
|
+
const handleClick = (e) => {
|
|
135
|
+
onClick?.(e);
|
|
136
|
+
!disabled && toggle();
|
|
137
|
+
};
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
state.active !== active && toggle();
|
|
140
|
+
}, [active]);
|
|
141
|
+
return (jsx(Button, { className: classNames(className, { [activeClass || ""]: state.active }, "i-btn-toggle"), ...restProps, onClick: handleClick, children: jsx("div", { className: classNames("i-btn-toggle-content", {
|
|
142
|
+
"i-btn-toggle-active": state.done,
|
|
143
|
+
}), children: state.active ? after ?? children : children }) }));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
Button.Toggle = Toggle;
|
|
147
|
+
Button.Group = Group;
|
|
148
|
+
|
|
149
|
+
const Icon = forwardRef((props, ref) => {
|
|
150
|
+
const { icon, size = "1.425em", rotate, style, className, ...restProps } = props;
|
|
151
|
+
if (!isValidElement(icon))
|
|
152
|
+
return icon;
|
|
153
|
+
const elProps = {
|
|
154
|
+
ref,
|
|
155
|
+
style: {
|
|
156
|
+
transform: rotate ? `rotate(${rotate}deg)` : undefined,
|
|
157
|
+
...style,
|
|
158
|
+
width: size,
|
|
159
|
+
height: size,
|
|
160
|
+
},
|
|
161
|
+
className: classNames("i-icon", className),
|
|
162
|
+
...restProps,
|
|
163
|
+
};
|
|
164
|
+
return cloneElement(icon, elProps);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
function ToTop(props) {
|
|
168
|
+
const { style, className, onClick } = props;
|
|
169
|
+
return (jsx(Button, { square: true, className: classNames("i-affix-totop", className), style: { ...style }, onClick: onClick, children: jsx(Icon, { icon: jsx(SkipPreviousRound, {}), rotate: 90 }) }));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const Affix = (props) => {
|
|
173
|
+
const { position = "fixed", left, top, right, bottom, offset, style, className, children, getContainer = () => document.body, } = props;
|
|
174
|
+
const [hidden, setHidden] = useState(false);
|
|
175
|
+
const hijackChildren = useMemo(() => Children.map(children, (node) => {
|
|
176
|
+
if (node.type === ToTop) {
|
|
177
|
+
const { onClick } = node.props;
|
|
178
|
+
return cloneElement(node, {
|
|
179
|
+
key: node.key,
|
|
180
|
+
...node.props,
|
|
181
|
+
onClick: (e) => {
|
|
182
|
+
const container = getContainer();
|
|
183
|
+
onClick?.(e);
|
|
184
|
+
container?.scrollTo({
|
|
185
|
+
top: 0,
|
|
186
|
+
left: 0,
|
|
187
|
+
behavior: "smooth",
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return node;
|
|
193
|
+
}), [children, getContainer]);
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
const container = getContainer();
|
|
196
|
+
if (!offset || !container)
|
|
197
|
+
return;
|
|
198
|
+
const listener = debounce({ delay: 160 }, () => {
|
|
199
|
+
const top = container.scrollTop;
|
|
200
|
+
setHidden(top < offset);
|
|
201
|
+
});
|
|
202
|
+
container.addEventListener("scroll", listener);
|
|
203
|
+
return () => {
|
|
204
|
+
container.removeEventListener("scroll", listener);
|
|
205
|
+
};
|
|
206
|
+
}, [offset, getContainer]);
|
|
207
|
+
return (jsx("div", { className: classNames("i-affix", className, {
|
|
208
|
+
"i-affix-hidden": hidden,
|
|
209
|
+
}), style: {
|
|
210
|
+
...style,
|
|
211
|
+
position,
|
|
212
|
+
left,
|
|
213
|
+
top,
|
|
214
|
+
right,
|
|
215
|
+
bottom,
|
|
216
|
+
}, children: hijackChildren }));
|
|
217
|
+
};
|
|
218
|
+
Affix.ToTop = ToTop;
|
|
219
|
+
|
|
220
|
+
const Badge = (props) => {
|
|
221
|
+
const { content, contentClass, dot, dotSize, round, disabled, style, className, children, } = props;
|
|
222
|
+
return (jsxs("div", { style: style, className: classNames("i-badge", { rounded: round }, className), children: [children, jsx("div", { className: classNames("i-badge-content", contentClass, {
|
|
223
|
+
"i-badge-dot": dot,
|
|
224
|
+
"i-badge-hidden": disabled,
|
|
225
|
+
}), style: { fontSize: dotSize }, children: content })] }));
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const Area = (name) => (props) => (jsx("div", { style: props.style, className: classNames("i-card-" + name, props.className), children: props.children }));
|
|
229
|
+
const Header$2 = Area("header");
|
|
230
|
+
const Footer = Area("footer");
|
|
231
|
+
const Banner = Area("banner");
|
|
232
|
+
const Tailer = Area("tail");
|
|
233
|
+
|
|
234
|
+
const Card = (props) => {
|
|
235
|
+
const { shadow = true, border, style, className, children } = props;
|
|
236
|
+
const slots = useMemo(() => {
|
|
237
|
+
const nodes = {};
|
|
238
|
+
Children.map(children, (child) => {
|
|
239
|
+
const type = child.type;
|
|
240
|
+
switch (type) {
|
|
241
|
+
case Header$2:
|
|
242
|
+
nodes["header"] = child;
|
|
243
|
+
break;
|
|
244
|
+
case Footer:
|
|
245
|
+
nodes["footer"] = child;
|
|
246
|
+
break;
|
|
247
|
+
case Banner:
|
|
248
|
+
nodes["banner"] = child;
|
|
249
|
+
break;
|
|
250
|
+
case Tailer:
|
|
251
|
+
nodes["tailer"] = child;
|
|
252
|
+
break;
|
|
253
|
+
default:
|
|
254
|
+
nodes["content"] = [...(nodes["content"] || []), child];
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
return nodes;
|
|
259
|
+
}, [children]);
|
|
260
|
+
const { header, banner, content, footer, tailer } = slots;
|
|
261
|
+
return (jsxs("div", { style: style, className: classNames("i-card", className, {
|
|
262
|
+
shadow,
|
|
263
|
+
"i-card-bordered": border,
|
|
264
|
+
}), children: [banner, header, content && jsx("div", { className: 'i-card-content', children: content }), footer, tailer] }));
|
|
265
|
+
};
|
|
266
|
+
Card.Header = Header$2;
|
|
267
|
+
Card.Footer = Footer;
|
|
268
|
+
Card.Banner = Banner;
|
|
269
|
+
Card.Tailer = Tailer;
|
|
270
|
+
|
|
271
|
+
var TFileType;
|
|
272
|
+
(function (TFileType) {
|
|
273
|
+
TFileType["IMAGE"] = "IMAGE";
|
|
274
|
+
TFileType["VIDEO"] = "VIDEO";
|
|
275
|
+
TFileType["AUDIO"] = "AUDIO";
|
|
276
|
+
TFileType["PDF"] = "PDF";
|
|
277
|
+
TFileType["EXCEL"] = "EXCEL";
|
|
278
|
+
TFileType["TXT"] = "TXT";
|
|
279
|
+
TFileType["UNKNOWN"] = "UNKNOWN";
|
|
280
|
+
})(TFileType || (TFileType = {}));
|
|
281
|
+
|
|
282
|
+
function getPosition($source, $popup, options = {}) {
|
|
283
|
+
const { refWindow, gap = 0, offset = 0, position = "top", align } = options;
|
|
284
|
+
if (!$source || !$popup)
|
|
285
|
+
return [
|
|
286
|
+
0,
|
|
287
|
+
0,
|
|
288
|
+
{
|
|
289
|
+
arrowX: 0,
|
|
290
|
+
arrowY: 0,
|
|
291
|
+
arrowPos: "bottom",
|
|
292
|
+
},
|
|
293
|
+
];
|
|
294
|
+
const rectT = $source.getBoundingClientRect();
|
|
295
|
+
const rectC = $popup.getBoundingClientRect();
|
|
296
|
+
let w = window.innerWidth;
|
|
297
|
+
let h = window.innerHeight;
|
|
298
|
+
let { left: tl, top: tt, right: tr, bottom: tb, width: tw, height: th, } = rectT;
|
|
299
|
+
const { height: ch, width: cw } = rectC;
|
|
300
|
+
if (!refWindow) {
|
|
301
|
+
const rectPa = $source.offsetParent?.getBoundingClientRect();
|
|
302
|
+
w = rectPa?.width || w;
|
|
303
|
+
h = rectPa?.height || h;
|
|
304
|
+
tl = $source.offsetLeft;
|
|
305
|
+
tt = $source.offsetTop;
|
|
306
|
+
tr = tl + rectT.width;
|
|
307
|
+
tb = tt + rectT.height;
|
|
308
|
+
}
|
|
309
|
+
let y = 0;
|
|
310
|
+
let x = 0;
|
|
311
|
+
let arrowX = 0;
|
|
312
|
+
let arrowY = 0;
|
|
313
|
+
let arrowPos = "bottom";
|
|
314
|
+
switch (position) {
|
|
315
|
+
case "left":
|
|
316
|
+
case "right":
|
|
317
|
+
y =
|
|
318
|
+
th !== ch
|
|
319
|
+
? computePosition({
|
|
320
|
+
containerSize: h,
|
|
321
|
+
targetSize: th,
|
|
322
|
+
targetOffset: tt,
|
|
323
|
+
contentSize: ch,
|
|
324
|
+
gap,
|
|
325
|
+
align,
|
|
326
|
+
})
|
|
327
|
+
: tt;
|
|
328
|
+
arrowY = y < tt ? tt - y + th / 2 : th / 2;
|
|
329
|
+
const xl = tl - offset - cw;
|
|
330
|
+
const xr = tr + offset + cw;
|
|
331
|
+
if (position === "left") {
|
|
332
|
+
x = xl < 0 ? tr + offset : xl;
|
|
333
|
+
arrowX = xl < 0 ? 0 : cw;
|
|
334
|
+
arrowPos = xl < 0 ? "left" : "right";
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
x = w > xr ? tr + offset : xl;
|
|
338
|
+
arrowX = w > xr ? 0 : cw;
|
|
339
|
+
arrowPos = w > xr ? "left" : "right";
|
|
340
|
+
}
|
|
341
|
+
break;
|
|
342
|
+
case "top":
|
|
343
|
+
case "bottom":
|
|
344
|
+
x =
|
|
345
|
+
tw !== cw
|
|
346
|
+
? computePosition({
|
|
347
|
+
containerSize: w,
|
|
348
|
+
targetOffset: tl,
|
|
349
|
+
targetSize: tw,
|
|
350
|
+
contentSize: cw,
|
|
351
|
+
gap,
|
|
352
|
+
align,
|
|
353
|
+
})
|
|
354
|
+
: tl;
|
|
355
|
+
arrowX = x > tl ? cw / 2 : tl - x + tw / 2;
|
|
356
|
+
const yt = tt - offset - ch;
|
|
357
|
+
const yb = tb + offset + ch;
|
|
358
|
+
if (position === "top") {
|
|
359
|
+
y = yt < 0 ? tb + offset : yt;
|
|
360
|
+
arrowY = yt < 0 ? 0 : ch;
|
|
361
|
+
arrowPos = yt < 0 ? "top" : "bottom";
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
y = h > yb ? tb + offset : yt;
|
|
365
|
+
arrowY = h > yb ? 0 : ch;
|
|
366
|
+
arrowPos = h > yb ? "top" : "bottom";
|
|
367
|
+
}
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
return [
|
|
371
|
+
x,
|
|
372
|
+
y,
|
|
373
|
+
{
|
|
374
|
+
arrowX,
|
|
375
|
+
arrowY,
|
|
376
|
+
arrowPos,
|
|
377
|
+
},
|
|
378
|
+
];
|
|
379
|
+
}
|
|
380
|
+
function getPointPosition(e, content) {
|
|
381
|
+
const { pageX: x, pageY: y } = e;
|
|
382
|
+
const { width: w, height: h } = content.getBoundingClientRect();
|
|
383
|
+
const { innerHeight: wh, innerWidth: ww } = window;
|
|
384
|
+
const left = x + w >= ww ? (x - w > 0 ? x - w : x) : x;
|
|
385
|
+
const top = y + h >= wh ? (y - h > 0 ? y - h : y) : y;
|
|
386
|
+
return [left, top];
|
|
387
|
+
}
|
|
388
|
+
function computePosition({ containerSize, targetSize, targetOffset, contentSize, gap, align = "center", }) {
|
|
389
|
+
const centerPoint = targetOffset + targetSize / 2;
|
|
390
|
+
switch (align) {
|
|
391
|
+
case "start":
|
|
392
|
+
return targetOffset + contentSize > containerSize
|
|
393
|
+
? targetOffset + targetSize
|
|
394
|
+
: targetOffset;
|
|
395
|
+
case "center":
|
|
396
|
+
if (targetSize >= contentSize) {
|
|
397
|
+
return centerPoint - contentSize / 2;
|
|
398
|
+
}
|
|
399
|
+
if (centerPoint + contentSize / 2 + gap > containerSize) {
|
|
400
|
+
return targetOffset + targetSize - contentSize;
|
|
401
|
+
}
|
|
402
|
+
if (centerPoint - contentSize / 2 - gap < 0) {
|
|
403
|
+
return gap;
|
|
404
|
+
}
|
|
405
|
+
return centerPoint - contentSize / 2;
|
|
406
|
+
case "end":
|
|
407
|
+
const result = targetOffset + targetSize - contentSize;
|
|
408
|
+
return result > 0 ? result : gap;
|
|
409
|
+
default:
|
|
410
|
+
return centerPoint - contentSize / 2;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function formatOption(options) {
|
|
414
|
+
return options.map((option) => ["string", "number"].includes(typeof option)
|
|
415
|
+
? { label: option, value: option }
|
|
416
|
+
: option);
|
|
417
|
+
}
|
|
418
|
+
function animate(from, to, duration = 1000, callback, easing = (t) => 1 - Math.pow(1 - t, 4)) {
|
|
419
|
+
const start = performance.now();
|
|
420
|
+
const diff = to - from;
|
|
421
|
+
let raf = requestAnimationFrame(loop);
|
|
422
|
+
function loop() {
|
|
423
|
+
raf = requestAnimationFrame(loop);
|
|
424
|
+
const past = performance.now() - start;
|
|
425
|
+
let percent = past / duration;
|
|
426
|
+
if (percent >= 1) {
|
|
427
|
+
percent = 1;
|
|
428
|
+
cancelAnimationFrame(raf);
|
|
429
|
+
}
|
|
430
|
+
const pass = diff * easing(percent);
|
|
431
|
+
callback?.(pass);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function formatNumber(value, options = {}) {
|
|
435
|
+
const { precision, thousand } = options;
|
|
436
|
+
const result = value.toFixed(precision);
|
|
437
|
+
if (!thousand)
|
|
438
|
+
return result;
|
|
439
|
+
const points = result.split(".");
|
|
440
|
+
const integer = points[0].replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, `$&${thousand}`);
|
|
441
|
+
if (points.length === 1)
|
|
442
|
+
return integer;
|
|
443
|
+
return `${integer}.${points[1]}`;
|
|
444
|
+
}
|
|
445
|
+
function renderNode(node, container = document.body) {
|
|
446
|
+
const div = document.createElement("div");
|
|
447
|
+
container.append(div);
|
|
448
|
+
const root = createRoot(div);
|
|
449
|
+
const sto = setTimeout(() => {
|
|
450
|
+
root?.render(node);
|
|
451
|
+
}, 0);
|
|
452
|
+
return () => {
|
|
453
|
+
div?.remove();
|
|
454
|
+
root?.unmount();
|
|
455
|
+
sto && clearTimeout(sto);
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
function getSuffixByUrl(url) {
|
|
459
|
+
return url.match(/\.([^\./\?]+)($|\?)/)?.[1];
|
|
460
|
+
}
|
|
461
|
+
function getFileType(suffix, type) {
|
|
462
|
+
switch (true) {
|
|
463
|
+
case ["jpg", "jpeg", "png", "webp", "svg"].includes(suffix) ||
|
|
464
|
+
type?.startsWith("image/"):
|
|
465
|
+
return TFileType["IMAGE"];
|
|
466
|
+
case ["mp4", "avi"].includes(suffix) || type?.startsWith("video/"):
|
|
467
|
+
return TFileType["VIDEO"];
|
|
468
|
+
default:
|
|
469
|
+
return TFileType["UNKNOWN"];
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
function fullScreen(el) {
|
|
473
|
+
el.requestFullscreen?.();
|
|
474
|
+
}
|
|
475
|
+
function exitFullScreen() {
|
|
476
|
+
document.exitFullscreen?.();
|
|
477
|
+
}
|
|
478
|
+
function formatTime(time, options) {
|
|
479
|
+
const result = [];
|
|
480
|
+
const { zero = true, units = ["", ":", ":"] } = options || {};
|
|
481
|
+
const l = units.length;
|
|
482
|
+
let i = 0;
|
|
483
|
+
while (i < l) {
|
|
484
|
+
if (time <= 0 && i > 1)
|
|
485
|
+
break;
|
|
486
|
+
const n = Math.round(time % 60);
|
|
487
|
+
time = Math.floor(time / 60);
|
|
488
|
+
result.unshift((zero && n < 10 ? `0${n}` : n) + units[i++]);
|
|
489
|
+
}
|
|
490
|
+
return result.join("");
|
|
491
|
+
}
|
|
492
|
+
function getNextSorter(prevSortBy, prevSortType, sortBy) {
|
|
493
|
+
const types = ["desc", "asc"];
|
|
494
|
+
if (prevSortBy === sortBy) {
|
|
495
|
+
const i = types.findIndex((t) => t === prevSortType) + 1;
|
|
496
|
+
const type = types[i] || "";
|
|
497
|
+
const by = type === "" ? "" : sortBy;
|
|
498
|
+
return [by, type];
|
|
499
|
+
}
|
|
500
|
+
return [sortBy, "desc"];
|
|
501
|
+
}
|
|
502
|
+
function formatBytes(bytes, decimals = 2) {
|
|
503
|
+
if (!+bytes)
|
|
504
|
+
return "0 Bytes";
|
|
505
|
+
const k = 1024;
|
|
506
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
507
|
+
const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
508
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
509
|
+
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
510
|
+
}
|
|
511
|
+
function clamp(value, min, max) {
|
|
512
|
+
return value < min ? min : value > max ? max : value;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function CheckboxItem(props) {
|
|
516
|
+
const { type = "default", label, name, value = false, className, status = "normal", message, disabled, partof, children, onChange, ...restProps } = props;
|
|
517
|
+
const state = useReactive({
|
|
518
|
+
value,
|
|
519
|
+
status,
|
|
520
|
+
message,
|
|
521
|
+
});
|
|
522
|
+
const handleChange = useMemoizedFn((e) => {
|
|
523
|
+
const checked = e.target.checked;
|
|
524
|
+
Object.assign(state, {
|
|
525
|
+
value: checked,
|
|
526
|
+
status,
|
|
527
|
+
message,
|
|
528
|
+
});
|
|
529
|
+
onChange?.(checked, e);
|
|
530
|
+
});
|
|
531
|
+
useEffect(() => {
|
|
532
|
+
state.value = value;
|
|
533
|
+
}, [value]);
|
|
534
|
+
return (jsxs("label", { className: classNames("i-checkbox-item", {
|
|
535
|
+
[`i-checkbox-${state.status}`]: state.status !== "normal",
|
|
536
|
+
disabled,
|
|
537
|
+
}, className), ...restProps, children: [jsx("input", { type: 'checkbox', name: name, className: classNames("i-checkbox-input", {
|
|
538
|
+
[`i-checkbox-${type}`]: !partof,
|
|
539
|
+
"i-checkbox-partof": partof,
|
|
540
|
+
}), checked: state.value, disabled: disabled, onChange: handleChange }), jsx("span", { className: 'i-checkbox-text', children: children || label }), state.message && (jsxs("span", { className: 'i-checkbox-message', children: ["*", state.message] }))] }));
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function Checkbox(props) {
|
|
544
|
+
const { label, name, options = [], value = "", type = "default", optionInline = true, labelInline, disabled, status = "normal", message, required, className, onChange, ...restProps } = props;
|
|
545
|
+
const state = useReactive({
|
|
546
|
+
value,
|
|
547
|
+
});
|
|
548
|
+
const formattedOptions = useMemo(() => formatOption(options), [options]);
|
|
549
|
+
const handleChange = useMemoizedFn((checked, opt, e) => {
|
|
550
|
+
const group = [...state.value];
|
|
551
|
+
const i = group.findIndex((item) => item === opt.value);
|
|
552
|
+
if (checked && i < 0) {
|
|
553
|
+
group.push(opt.value);
|
|
554
|
+
}
|
|
555
|
+
else if (!checked && i > -1) {
|
|
556
|
+
group.splice(i, 1);
|
|
557
|
+
}
|
|
558
|
+
state.value = group;
|
|
559
|
+
onChange?.(group, opt, e);
|
|
560
|
+
});
|
|
561
|
+
useEffect(() => {
|
|
562
|
+
state.value = value;
|
|
563
|
+
}, [value]);
|
|
564
|
+
return (jsxs("div", { className: classNames("i-checkbox i-input-label", {
|
|
565
|
+
[`i-checkbox-${status}`]: status !== "normal",
|
|
566
|
+
"i-input-inline": labelInline,
|
|
567
|
+
}, className), ...restProps, children: [label && (jsxs("span", { className: 'i-input-label-text', children: [required && jsx("span", { className: 'error', children: "*" }), label, message && jsx("p", { className: 'i-checkbox-message', children: message })] })), jsx("div", { className: classNames("i-checkbox-options", {
|
|
568
|
+
"i-options-block": !optionInline,
|
|
569
|
+
"i-checkbox-options-button": type === "button",
|
|
570
|
+
}), children: formattedOptions.map((option) => {
|
|
571
|
+
return (jsx(CheckboxItem, { name: name, value: state.value.includes(option.value), type: type, disabled: disabled || option.disabled, onChange: (checked, e) => handleChange(checked, option, e), children: option.label }, option.value));
|
|
572
|
+
}) })] }));
|
|
573
|
+
}
|
|
574
|
+
Checkbox.Item = CheckboxItem;
|
|
575
|
+
|
|
576
|
+
const Helpericon = (props) => {
|
|
577
|
+
const { as = "a", active, className, icon = jsx(CloseRound, {}), ...restProps } = props;
|
|
578
|
+
if (!active)
|
|
579
|
+
return jsx(Fragment, {});
|
|
580
|
+
return createElement(as, {
|
|
581
|
+
className: classNames("i-helpericon", className),
|
|
582
|
+
...restProps,
|
|
583
|
+
}, [
|
|
584
|
+
createElement(Icon, {
|
|
585
|
+
key: uid(3),
|
|
586
|
+
icon,
|
|
587
|
+
}),
|
|
588
|
+
]);
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
function Item$5(props) {
|
|
592
|
+
return jsx(Fragment, {});
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
const Collapse = (props) => {
|
|
596
|
+
const { active, items, multiple, border, headerClickable, className, children, renderToggle = (active) => active ? jsx(MinusRound, {}) : jsx(PlusRound, {}), onCollapse, ...restProps } = props;
|
|
597
|
+
const state = useReactive({
|
|
598
|
+
active,
|
|
599
|
+
});
|
|
600
|
+
const collapses = useMemo(() => {
|
|
601
|
+
if (!items) {
|
|
602
|
+
if (!children)
|
|
603
|
+
return [];
|
|
604
|
+
return (Children.map(children, (node, i) => {
|
|
605
|
+
const { key, props: nodeProps } = node;
|
|
606
|
+
const { title, children, content, disabled, ...restProps } = nodeProps;
|
|
607
|
+
return {
|
|
608
|
+
...restProps,
|
|
609
|
+
key: key || i,
|
|
610
|
+
title,
|
|
611
|
+
content: children || content,
|
|
612
|
+
disabled,
|
|
613
|
+
};
|
|
614
|
+
}) || []);
|
|
615
|
+
}
|
|
616
|
+
return items;
|
|
617
|
+
}, [children]);
|
|
618
|
+
const handleHeaderClick = (item) => {
|
|
619
|
+
if (!headerClickable)
|
|
620
|
+
return;
|
|
621
|
+
handleToggle(item);
|
|
622
|
+
};
|
|
623
|
+
const handleToggle = (item) => {
|
|
624
|
+
const { key, disabled } = item;
|
|
625
|
+
if (disabled)
|
|
626
|
+
return;
|
|
627
|
+
if (!multiple) {
|
|
628
|
+
state.active = state.active === key ? undefined : key;
|
|
629
|
+
onCollapse?.(key, state.active !== undefined);
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
if (!Array.isArray(state.active))
|
|
633
|
+
state.active = [];
|
|
634
|
+
const i = state.active.findIndex((k) => k === key);
|
|
635
|
+
if (i > -1) {
|
|
636
|
+
state.active.splice(i, 1);
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
key !== undefined && state.active.push(key);
|
|
640
|
+
}
|
|
641
|
+
onCollapse?.(key, i < 0);
|
|
642
|
+
};
|
|
643
|
+
return (jsx("div", { className: classNames("i-collapse", {
|
|
644
|
+
"i-collapse-bordered": border,
|
|
645
|
+
}, className), ...restProps, children: collapses.map((item) => {
|
|
646
|
+
const { key, title, content, disabled, className, ...restProps } = item;
|
|
647
|
+
const isActive = multiple
|
|
648
|
+
? (state.active || []).includes(key)
|
|
649
|
+
: state.active === key;
|
|
650
|
+
return (jsxs("div", { className: classNames("i-collapse-item", className, {
|
|
651
|
+
"i-collapse-active": isActive,
|
|
652
|
+
"i-collapse-disabled": disabled,
|
|
653
|
+
}), ...restProps, children: [jsxs("div", { className: 'i-collapse-header', onClick: () => handleHeaderClick(item), children: [title, jsx(Helpericon, { active: true, className: 'i-collapse-toggle', icon: renderToggle(isActive), onClick: () => handleToggle(item) })] }), jsx("div", { className: 'i-collapse-content', children: content })] }, key));
|
|
654
|
+
}) }));
|
|
655
|
+
};
|
|
656
|
+
Collapse.Item = Item$5;
|
|
657
|
+
|
|
658
|
+
function Empty(props) {
|
|
659
|
+
const { className, ...restProps } = props;
|
|
660
|
+
return (jsx(InboxTwotone, { className: classNames("i-empty", className), ...restProps }));
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
function getCellStyle({ justify, col, row, colSpan = 1, rowSpan = 1, }) {
|
|
664
|
+
const style = {
|
|
665
|
+
"--datagrid-justify": justify,
|
|
666
|
+
gridArea: `${row + 1} / ${col + 1} / ${row + 1 + rowSpan} / ${col + 1 + colSpan}`,
|
|
667
|
+
insetInline: `var(--datagrid-cell-inset-${col})`,
|
|
668
|
+
};
|
|
669
|
+
return style;
|
|
670
|
+
}
|
|
671
|
+
function Cell(props) {
|
|
672
|
+
const { column, row, col, data, onCellClick, onCellDoubleClick } = props;
|
|
673
|
+
const { id, fixed, justify, rowSpan, render } = column;
|
|
674
|
+
const style = getCellStyle({ justify, fixed, col, row, rowSpan });
|
|
675
|
+
return (jsx("div", { className: classNames("i-datagrid-cell", {
|
|
676
|
+
[`i-datagrid-cell-fixed-${fixed}`]: fixed,
|
|
677
|
+
}), "data-col": id, style: style, onClick: (e) => onCellClick?.(data, column, row, col, e), onDoubleClick: (e) => onCellDoubleClick?.(data, column, row, col, e), children: render?.(data[id], data, col) ?? (jsx("div", { className: 'i-datagrid-cell-content', children: data[id] })) }));
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
const MouseMoveEvents = new Set();
|
|
681
|
+
const MouseUpEvents = new Set();
|
|
682
|
+
document.addEventListener("mousemove", (e) => {
|
|
683
|
+
for (const listener of MouseMoveEvents.values()) {
|
|
684
|
+
listener(e);
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
document.addEventListener("mouseup", (e) => {
|
|
688
|
+
for (const listener of MouseUpEvents.values()) {
|
|
689
|
+
listener(e);
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
function useMouseMove(listener) {
|
|
693
|
+
useEffect(() => {
|
|
694
|
+
MouseMoveEvents.add(listener);
|
|
695
|
+
return () => {
|
|
696
|
+
MouseMoveEvents.delete(listener);
|
|
697
|
+
};
|
|
698
|
+
}, [listener]);
|
|
699
|
+
}
|
|
700
|
+
function useMouseUp(listener) {
|
|
701
|
+
useEffect(() => {
|
|
702
|
+
MouseUpEvents.add(listener);
|
|
703
|
+
return () => {
|
|
704
|
+
MouseUpEvents.delete(listener);
|
|
705
|
+
};
|
|
706
|
+
}, [listener]);
|
|
707
|
+
}
|
|
708
|
+
function useIntersectionObserver(configs) {
|
|
709
|
+
const WM = new WeakMap();
|
|
710
|
+
const IO = new IntersectionObserver((entries) => {
|
|
711
|
+
entries.map((entry) => {
|
|
712
|
+
const callback = WM.get(entry.target);
|
|
713
|
+
callback?.(entry.target, entry.isIntersecting);
|
|
714
|
+
});
|
|
715
|
+
}, configs);
|
|
716
|
+
function observe(target, callback) {
|
|
717
|
+
if (WM.get(target))
|
|
718
|
+
return;
|
|
719
|
+
WM.set(target, callback);
|
|
720
|
+
target && IO.observe(target);
|
|
721
|
+
}
|
|
722
|
+
function unobserve(target) {
|
|
723
|
+
target && IO.unobserve(target);
|
|
724
|
+
WM.delete(target);
|
|
725
|
+
}
|
|
726
|
+
function disconnect() {
|
|
727
|
+
IO.disconnect();
|
|
728
|
+
}
|
|
729
|
+
return {
|
|
730
|
+
observe,
|
|
731
|
+
unobserve,
|
|
732
|
+
disconnect,
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
function useResizeObserver() {
|
|
736
|
+
const WM = new WeakMap();
|
|
737
|
+
const IO = new ResizeObserver((entries) => {
|
|
738
|
+
entries.map((entry) => {
|
|
739
|
+
const callback = WM.get(entry.target);
|
|
740
|
+
callback?.(entry.target);
|
|
741
|
+
});
|
|
742
|
+
});
|
|
743
|
+
function observe(target, callback) {
|
|
744
|
+
if (WM.get(target))
|
|
745
|
+
return;
|
|
746
|
+
target && IO.observe(target);
|
|
747
|
+
WM.set(target, callback);
|
|
748
|
+
}
|
|
749
|
+
function unobserve(target) {
|
|
750
|
+
target && IO.unobserve(target);
|
|
751
|
+
WM.delete(target);
|
|
752
|
+
}
|
|
753
|
+
function disconnect() {
|
|
754
|
+
IO.disconnect();
|
|
755
|
+
}
|
|
756
|
+
return {
|
|
757
|
+
observe,
|
|
758
|
+
unobserve,
|
|
759
|
+
disconnect,
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
function Resize(props) {
|
|
764
|
+
const { index, onWidthChange } = props;
|
|
765
|
+
const state = useReactive({
|
|
766
|
+
resizing: false,
|
|
767
|
+
x: 0,
|
|
768
|
+
width: 0,
|
|
769
|
+
});
|
|
770
|
+
const handleMouseDown = useMemoizedFn((e) => {
|
|
771
|
+
const tar = e.target;
|
|
772
|
+
const width = tar.offsetParent.offsetWidth;
|
|
773
|
+
Object.assign(state, {
|
|
774
|
+
x: e.pageX,
|
|
775
|
+
resizing: true,
|
|
776
|
+
width,
|
|
777
|
+
});
|
|
778
|
+
});
|
|
779
|
+
const handleMouseMove = useMemoizedFn((e) => {
|
|
780
|
+
if (!state.resizing)
|
|
781
|
+
return;
|
|
782
|
+
e.preventDefault();
|
|
783
|
+
const after = state.width + e.pageX - state.x;
|
|
784
|
+
if (after <= 24)
|
|
785
|
+
return;
|
|
786
|
+
onWidthChange(index, after);
|
|
787
|
+
});
|
|
788
|
+
const handleMouseUp = () => {
|
|
789
|
+
if (!state.resizing)
|
|
790
|
+
return;
|
|
791
|
+
state.resizing = false;
|
|
792
|
+
};
|
|
793
|
+
useMouseMove(handleMouseMove);
|
|
794
|
+
useMouseUp(handleMouseUp);
|
|
795
|
+
return (jsx("i", { className: 'i-datagrid-resizor', onMouseDown: handleMouseDown, onClick: (e) => e.stopPropagation() }));
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
const Arrow = (props) => (jsx("svg", { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', ...props, children: jsx("g", { fill: 'none', children: jsx("path", { d: 'M9 17.898c0 1.074 1.265 1.648 2.073.941l6.31-5.522a1.75 1.75 0 0 0 0-2.634l-6.31-5.522C10.265 4.454 9 5.028 9 6.102v11.796z', fill: 'currentColor' }) }) }));
|
|
799
|
+
function Sorter(props) {
|
|
800
|
+
const { type } = props;
|
|
801
|
+
return (jsxs("a", { className: classNames("i-datagrid-sorter", {
|
|
802
|
+
[`i-datagrid-sorter-${type}`]: type,
|
|
803
|
+
}), children: [jsx(Arrow, { className: 'i-datagrid-sorter-caret' }), jsx(Arrow, { className: 'i-datagrid-sorter-caret' })] }));
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
function Row(props) {
|
|
807
|
+
const { row, data, columns, onRowClick, onCellClick, onCellDoubleClick } = props;
|
|
808
|
+
return (jsx("div", { className: 'i-datagrid-row', onClick: () => onRowClick?.(data, row), children: columns.map((col, i) => (jsx(Cell, { column: col, col: i, row: row, data: data, onCellClick: onCellClick, onCellDoubleClick: onCellDoubleClick }, i))) }));
|
|
809
|
+
}
|
|
810
|
+
function Header$1(props) {
|
|
811
|
+
const { columns, resizable, sortBy, sortType, onWidthChange, onHeaderClick, } = props;
|
|
812
|
+
return (jsx("div", { className: 'i-datagrid-header i-datagrid-row', children: columns.map((column, col) => {
|
|
813
|
+
const { id, title, fixed, colSpan, sorter, justify, renderHeader, } = column;
|
|
814
|
+
const style = getCellStyle({
|
|
815
|
+
justify,
|
|
816
|
+
row: 0,
|
|
817
|
+
col,
|
|
818
|
+
colSpan,
|
|
819
|
+
});
|
|
820
|
+
const order = sortBy === id ? sortType : "";
|
|
821
|
+
return (jsxs("div", { "data-col": id, className: classNames("i-datagrid-cell", {
|
|
822
|
+
"i-datagrid-has-sorter": sorter,
|
|
823
|
+
"i-datagrid-cell-fixed": fixed,
|
|
824
|
+
}), style: { ...style, insetBlockStart: 0 }, onClick: (e) => onHeaderClick?.(column, e), children: [renderHeader?.(column, col) ?? (jsx("div", { className: 'i-datagrid-cell-content', children: title || id })), sorter && jsx(Sorter, { type: order }), resizable && (jsx(Resize, { index: col, onWidthChange: onWidthChange }))] }, col));
|
|
825
|
+
}) }));
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
const Datagrid = (props) => {
|
|
829
|
+
const { data = [], columns = [], border, striped, header = true, resizable, cellPadding = ".5em", empty = jsx(Empty, {}), loading, height = "unset", style, className, renderLoading = () => jsx(Loading, { size: '1.5em', className: 'color-3' }), onCellClick, onRowClick, onHeaderClick, onSort, onScroll, onResize, } = props;
|
|
830
|
+
const container = useRef(null);
|
|
831
|
+
const scrollbar = useRef(null);
|
|
832
|
+
const state = useReactive({
|
|
833
|
+
rows: data,
|
|
834
|
+
widths: columns.map((col) => col.width ?? "auto"),
|
|
835
|
+
sortBy: "",
|
|
836
|
+
sortType: "",
|
|
837
|
+
});
|
|
838
|
+
const styles = useMemo(() => {
|
|
839
|
+
const { widths } = state;
|
|
840
|
+
const o = {
|
|
841
|
+
...style,
|
|
842
|
+
"--grid-template-columns": widths
|
|
843
|
+
.map((w) => {
|
|
844
|
+
return typeof w === "number" ? `${w}px` : w;
|
|
845
|
+
})
|
|
846
|
+
.join(" "),
|
|
847
|
+
};
|
|
848
|
+
if (!resizable)
|
|
849
|
+
return o;
|
|
850
|
+
const fws = columns.map((col, i) => {
|
|
851
|
+
const { fixed } = col;
|
|
852
|
+
if (!fixed)
|
|
853
|
+
return 0;
|
|
854
|
+
return widths[i];
|
|
855
|
+
});
|
|
856
|
+
columns.map((col, i) => {
|
|
857
|
+
const { fixed } = col;
|
|
858
|
+
if (!fixed)
|
|
859
|
+
return;
|
|
860
|
+
if (i === 0) {
|
|
861
|
+
o[`--datagrid-cell-inset-0`] = 0;
|
|
862
|
+
}
|
|
863
|
+
else if (i === fws.length - 1) {
|
|
864
|
+
o[`--datagrid-cell-inset-${fws.length - 1}`] = "auto 0";
|
|
865
|
+
}
|
|
866
|
+
else {
|
|
867
|
+
const isLeft = fixed === "left";
|
|
868
|
+
const before = isLeft ? fws.slice(0, i) : fws.slice(i + 1);
|
|
869
|
+
const sum = before.reduce((pre, cur) => pre + cur) + "px";
|
|
870
|
+
const result = isLeft ? `${sum} auto` : `auto ${sum}`;
|
|
871
|
+
o[`--datagrid-cell-inset-${i}`] = result;
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
return o;
|
|
875
|
+
}, [state.widths, resizable]);
|
|
876
|
+
const handleWidthChange = useCallback((i, w) => {
|
|
877
|
+
if (!resizable)
|
|
878
|
+
return;
|
|
879
|
+
const [...ws] = state.widths;
|
|
880
|
+
ws[i] = w;
|
|
881
|
+
state.widths = ws;
|
|
882
|
+
onResize?.(columns[i], w);
|
|
883
|
+
}, [resizable]);
|
|
884
|
+
const handleHeaderClick = useCallback((column, e) => {
|
|
885
|
+
if (column?.sorter) {
|
|
886
|
+
const [sortBy, sortType] = getNextSorter(state.sortBy, state.sortType, column.id);
|
|
887
|
+
Object.assign(state, {
|
|
888
|
+
sortBy,
|
|
889
|
+
sortType,
|
|
890
|
+
});
|
|
891
|
+
onSort?.(sortBy, sortType);
|
|
892
|
+
}
|
|
893
|
+
onHeaderClick?.(column, e);
|
|
894
|
+
}, []);
|
|
895
|
+
const rows = useMemo(() => {
|
|
896
|
+
const { sortBy, sortType } = state;
|
|
897
|
+
if (sortBy && !onSort) {
|
|
898
|
+
const sorter = columns.find((col) => col.id === sortBy)?.sorter;
|
|
899
|
+
const sortFn = typeof sorter === "function"
|
|
900
|
+
? sorter
|
|
901
|
+
: (a, b) => b[sortBy] - a[sortBy];
|
|
902
|
+
const sorted = [...data].sort(sortFn);
|
|
903
|
+
return sortType === "desc" ? sorted : sorted.reverse();
|
|
904
|
+
}
|
|
905
|
+
return data;
|
|
906
|
+
}, [data, columns, state.sortBy, state.sortType]);
|
|
907
|
+
useEffect(() => {
|
|
908
|
+
if (!container.current)
|
|
909
|
+
return;
|
|
910
|
+
const { current: div } = container;
|
|
911
|
+
const tds = div.querySelector(".i-datagrid-row")?.children;
|
|
912
|
+
if (!tds?.length)
|
|
913
|
+
return;
|
|
914
|
+
state.widths = Array.from(tds).map((node) => node.offsetWidth);
|
|
915
|
+
}, [columns, resizable]);
|
|
916
|
+
useEffect(() => {
|
|
917
|
+
loading && scrollbar.current?.scrollTop(0);
|
|
918
|
+
}, [loading]);
|
|
919
|
+
const scrollBarStyle = {
|
|
920
|
+
"--padding": cellPadding,
|
|
921
|
+
...styles,
|
|
922
|
+
};
|
|
923
|
+
return (jsxs(ScrollContainer, { ref: scrollbar, autoHide: true, autoHeight: true, autoHeightMax: height, style: scrollBarStyle, className: classNames("i-datagrid-container", className, {
|
|
924
|
+
"i-datagrid-bordered": border,
|
|
925
|
+
"i-datagrid-striped": striped,
|
|
926
|
+
}), renderView: (props) => (jsx("div", { ...props, className: classNames({ "i-datagrid-loading": loading }) })), onScroll: onScroll, children: [jsxs("div", { ref: container, className: 'i-datagrid', children: [header && (jsx(Header$1, { columns: columns, resizable: resizable, sortType: state.sortType, sortBy: state.sortBy, onWidthChange: handleWidthChange, onHeaderClick: handleHeaderClick })), rows.map((row, i) => (jsx(Row, { row: i + (header ? 1 : 0), data: row, columns: columns, onCellClick: onCellClick, onRowClick: onRowClick }, i))), rows.length < 1 && empty] }), loading && renderLoading()] }));
|
|
927
|
+
};
|
|
928
|
+
|
|
929
|
+
function InputContainer(props) {
|
|
930
|
+
const { label, className, labelInline, style, children, status, tip, required, } = props;
|
|
931
|
+
return (jsxs("label", { className: classNames("i-input-label", className, {
|
|
932
|
+
"i-input-inline": labelInline,
|
|
933
|
+
}), style: style, children: [label && (jsxs("span", { className: 'i-input-label-text', children: [required && jsx("span", { className: 'error', children: "*" }), label] })), children, tip && (jsx("span", { className: classNames("i-input-message", {
|
|
934
|
+
[`i-input-${status}`]: status !== "normal",
|
|
935
|
+
}), children: tip }))] }));
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
const Input = forwardRef((props, ref) => {
|
|
939
|
+
const { type = "text", label, name, value = props.initValue ?? "", initValue = "", prepend, append, labelInline, className, status = "normal", message, tip, clear, hideVisible, border, required, onChange, onEnter, style, ...restProps } = props;
|
|
940
|
+
const state = useReactive({
|
|
941
|
+
value,
|
|
942
|
+
type,
|
|
943
|
+
visible: false,
|
|
944
|
+
});
|
|
945
|
+
const handleChange = useCallback((e) => {
|
|
946
|
+
const v = e.target.value;
|
|
947
|
+
state.value = v;
|
|
948
|
+
onChange?.(v, e);
|
|
949
|
+
}, []);
|
|
950
|
+
const handleKeydown = useMemoizedFn((e) => {
|
|
951
|
+
e.code === "Enter" && onEnter?.();
|
|
952
|
+
});
|
|
953
|
+
const handleHelperClick = () => {
|
|
954
|
+
if (type === "password" && !hideVisible) {
|
|
955
|
+
Object.assign(state, {
|
|
956
|
+
visible: !state.visible,
|
|
957
|
+
type: !state.visible ? "text" : "password",
|
|
958
|
+
});
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
const v = "";
|
|
962
|
+
onChange?.(v);
|
|
963
|
+
};
|
|
964
|
+
const HelperIcon = useMemo(() => {
|
|
965
|
+
if (type === "password") {
|
|
966
|
+
return state.visible ? jsx(VisibilityRound, {}) : jsx(VisibilityOffRound, {});
|
|
967
|
+
}
|
|
968
|
+
return undefined;
|
|
969
|
+
}, [state.visible]);
|
|
970
|
+
useEffect(() => {
|
|
971
|
+
state.value = value;
|
|
972
|
+
}, [value]);
|
|
973
|
+
const inputProps = {
|
|
974
|
+
ref,
|
|
975
|
+
type: state.type,
|
|
976
|
+
name,
|
|
977
|
+
value: state.value,
|
|
978
|
+
className: classNames("i-input", `i-input-${type}`),
|
|
979
|
+
onChange: handleChange,
|
|
980
|
+
onKeyDown: handleKeydown,
|
|
981
|
+
...restProps,
|
|
982
|
+
};
|
|
983
|
+
const clearable = clear && state.value;
|
|
984
|
+
const showHelper = type === "password" && !!state.value;
|
|
985
|
+
return (jsx(InputContainer, { label: label, labelInline: labelInline, className: className, style: style, tip: message ?? tip, status: status, required: required, children: jsxs("div", { className: classNames("i-input-item", {
|
|
986
|
+
[`i-input-${status}`]: status !== "normal",
|
|
987
|
+
"i-input-borderless": !border,
|
|
988
|
+
}), children: [prepend && jsx("div", { className: 'i-input-prepend', children: prepend }), jsx("input", { ...inputProps }), jsx(Helpericon, { active: !!clearable || showHelper, icon: HelperIcon, onClick: handleHelperClick }), append && jsx("div", { className: 'i-input-append', children: append })] }) }));
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
const Number$2 = forwardRef((props, ref) => {
|
|
992
|
+
const { label, name, value = props.initValue ?? "", initValue, labelInline, step = 1, min = -Infinity, max = Infinity, thousand, precision, type, className, status = "normal", append, border, prepend, message, tip, hideControl, style, onChange, onEnter, onInput, onBlur, ...rest } = props;
|
|
993
|
+
const state = useReactive({
|
|
994
|
+
value,
|
|
995
|
+
});
|
|
996
|
+
const getRangeNumber = useCallback((v) => clamp(v, min, max), [min, max]);
|
|
997
|
+
const getFormatNumber = useCallback((v) => formatNumber(v, { precision, thousand }), [precision, thousand]);
|
|
998
|
+
const formatInputValue = useCallback((v) => {
|
|
999
|
+
if (!v)
|
|
1000
|
+
return "";
|
|
1001
|
+
if (typeof v === "number" || !thousand)
|
|
1002
|
+
return v;
|
|
1003
|
+
return v.replaceAll(thousand, "");
|
|
1004
|
+
}, [thousand]);
|
|
1005
|
+
const handleChange = useMemoizedFn((e) => {
|
|
1006
|
+
const { value } = e.target;
|
|
1007
|
+
const v = formatInputValue(value.replace(/[^\d\.-]/g, ""));
|
|
1008
|
+
state.value = v;
|
|
1009
|
+
onChange?.(+v, e);
|
|
1010
|
+
});
|
|
1011
|
+
const handleOperate = useMemoizedFn((param) => {
|
|
1012
|
+
const value = formatInputValue(state.value) ?? 0;
|
|
1013
|
+
const result = getRangeNumber(+value + param);
|
|
1014
|
+
state.value = getFormatNumber(result);
|
|
1015
|
+
onChange?.(result);
|
|
1016
|
+
});
|
|
1017
|
+
useEffect(() => {
|
|
1018
|
+
state.value = value;
|
|
1019
|
+
}, [value]);
|
|
1020
|
+
const inputProps = {
|
|
1021
|
+
ref,
|
|
1022
|
+
name,
|
|
1023
|
+
value: state.value,
|
|
1024
|
+
className: "i-input i-input-number",
|
|
1025
|
+
onChange: handleChange,
|
|
1026
|
+
...rest,
|
|
1027
|
+
};
|
|
1028
|
+
return (jsx(InputContainer, { label: label, labelInline: labelInline, className: className, style: style, tip: message ?? tip, status: status, children: jsxs("div", { className: classNames("i-input-item", {
|
|
1029
|
+
[`i-input-${status}`]: status !== "normal",
|
|
1030
|
+
"i-input-borderless": !border,
|
|
1031
|
+
}), children: [prepend && jsx("div", { className: 'i-input-prepend', children: prepend }), !hideControl && (jsx(Helpericon, { active: true, icon: jsx(MinusRound, {}), onClick: () => handleOperate(-step) })), jsx("input", { ...inputProps }), !hideControl && (jsx(Helpericon, { active: true, icon: jsx(PlusRound, {}), onClick: () => handleOperate(step) })), append && jsx("div", { className: 'i-input-append', children: append })] }) }));
|
|
1032
|
+
});
|
|
1033
|
+
|
|
1034
|
+
const Range = (props) => {
|
|
1035
|
+
const { label, name, value = props.initValue ?? "", initValue, labelInline, min = -Infinity, max = Infinity, type, className, status = "normal", message, tip, append, prepend, step = 1, thousand, precision, hideControl, placeholder, border, onChange, onBlur, style, ...restProps } = props;
|
|
1036
|
+
const state = useReactive({
|
|
1037
|
+
value,
|
|
1038
|
+
});
|
|
1039
|
+
const getRangeNumber = useCallback((v) => clamp(v, min, max), [min, max]);
|
|
1040
|
+
const getFormatNumber = useCallback((v) => formatNumber(v, { precision, thousand }), [precision, thousand]);
|
|
1041
|
+
const formatInputValue = useCallback((v) => {
|
|
1042
|
+
if (!v)
|
|
1043
|
+
return "";
|
|
1044
|
+
if (typeof v === "number" || !thousand)
|
|
1045
|
+
return v;
|
|
1046
|
+
return v.replaceAll(thousand, "");
|
|
1047
|
+
}, [thousand]);
|
|
1048
|
+
const handleChange = useMemoizedFn((e, i) => {
|
|
1049
|
+
const { value } = e.target;
|
|
1050
|
+
const v = formatInputValue(value.replace(/[^\d\.-]/g, ""));
|
|
1051
|
+
const range = Array.isArray(state.value) ? state.value : [];
|
|
1052
|
+
range[i] = +v;
|
|
1053
|
+
state.value = range;
|
|
1054
|
+
onChange?.(range, e);
|
|
1055
|
+
});
|
|
1056
|
+
const handleOperate = useMemoizedFn((e, param, i) => {
|
|
1057
|
+
e.preventDefault();
|
|
1058
|
+
e.stopPropagation();
|
|
1059
|
+
const range = Array.isArray(state.value) ? state.value : [];
|
|
1060
|
+
const value = formatInputValue(range[i]) ?? 0;
|
|
1061
|
+
const result = getRangeNumber(+value + param);
|
|
1062
|
+
range[i] = getFormatNumber(result);
|
|
1063
|
+
state.value = range;
|
|
1064
|
+
onChange?.(range, e);
|
|
1065
|
+
});
|
|
1066
|
+
const handleSwitch = useMemoizedFn((e) => {
|
|
1067
|
+
e.preventDefault();
|
|
1068
|
+
e.stopPropagation();
|
|
1069
|
+
const range = state.value ?? [];
|
|
1070
|
+
const v = range[0];
|
|
1071
|
+
range[0] = range[1];
|
|
1072
|
+
range[1] = v;
|
|
1073
|
+
state.value = range;
|
|
1074
|
+
onChange?.(range);
|
|
1075
|
+
});
|
|
1076
|
+
useEffect(() => {
|
|
1077
|
+
state.value = value;
|
|
1078
|
+
}, [value]);
|
|
1079
|
+
const inputProps = {
|
|
1080
|
+
name,
|
|
1081
|
+
className: "i-input i-input-number",
|
|
1082
|
+
...restProps,
|
|
1083
|
+
};
|
|
1084
|
+
return (jsx(InputContainer, { label: label, labelInline: labelInline, className: className, style: style, tip: message ?? tip, status: status, children: jsxs("div", { className: classNames("i-input-item", {
|
|
1085
|
+
[`i-input-${status}`]: status !== "normal",
|
|
1086
|
+
"i-input-borderless": !border,
|
|
1087
|
+
}), children: [prepend && jsx("div", { className: 'i-input-prepend', children: prepend }), !hideControl && (jsx(Helpericon, { active: true, icon: jsx(MinusRound, {}), onClick: (e) => handleOperate(e, -step, 0) })), jsx("input", { value: state.value?.[0] || "", placeholder: placeholder?.[0], ...inputProps, onChange: (e) => handleChange(e, 0) }), !hideControl && (jsx(Helpericon, { active: true, icon: jsx(PlusRound, {}), onClick: (e) => handleOperate(e, step, 0) })), jsx(Helpericon, { active: true, icon: jsx(SyncAltRound, {}), style: { margin: 0 }, onClick: handleSwitch }), !hideControl && (jsx(Helpericon, { active: true, icon: jsx(MinusRound, {}), onClick: (e) => handleOperate(e, -step, 1) })), jsx("input", { value: state.value?.[1] || "", placeholder: placeholder?.[1], ...inputProps, onChange: (e) => handleChange(e, 1) }), !hideControl && (jsx(Helpericon, { active: true, icon: jsx(PlusRound, {}), onClick: (e) => handleOperate(e, step, 1) })), append && jsx("div", { className: 'i-input-append', children: append })] }) }));
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
const Textarea = forwardRef((props, ref) => {
|
|
1091
|
+
const { label, name, value = props.initValue ?? "", initValue, labelInline, className, status = "normal", message, tip, autoSize, border, style, onChange, onEnter, ...restProps } = props;
|
|
1092
|
+
const state = useReactive({
|
|
1093
|
+
value,
|
|
1094
|
+
});
|
|
1095
|
+
const refTextarea = useRef(null);
|
|
1096
|
+
const handleChange = useCallback((e) => {
|
|
1097
|
+
const v = e.target.value;
|
|
1098
|
+
state.value = v;
|
|
1099
|
+
const ta = refTextarea.current?.firstChild;
|
|
1100
|
+
if (autoSize && ta) {
|
|
1101
|
+
// ta.style.height = "inherit";
|
|
1102
|
+
ta.style.height = `${ta.scrollHeight}px`;
|
|
1103
|
+
}
|
|
1104
|
+
onChange?.(v, e);
|
|
1105
|
+
}, []);
|
|
1106
|
+
const handleKeydown = useMemoizedFn((e) => {
|
|
1107
|
+
e.code === "Enter" && onEnter?.();
|
|
1108
|
+
});
|
|
1109
|
+
useEffect(() => {
|
|
1110
|
+
state.value = value;
|
|
1111
|
+
}, [value]);
|
|
1112
|
+
const inputProps = {
|
|
1113
|
+
ref,
|
|
1114
|
+
name,
|
|
1115
|
+
value: state.value,
|
|
1116
|
+
className: "i-input i-textarea",
|
|
1117
|
+
onChange: handleChange,
|
|
1118
|
+
onKeyDown: handleKeydown,
|
|
1119
|
+
...restProps,
|
|
1120
|
+
};
|
|
1121
|
+
return (jsx(InputContainer, { label: label, labelInline: labelInline, className: className, style: style, tip: message ?? tip, status: status, children: jsx("div", { ref: refTextarea, className: classNames("i-input-item", {
|
|
1122
|
+
[`i-input-${status}`]: status !== "normal",
|
|
1123
|
+
"i-input-borderless": !border,
|
|
1124
|
+
}), children: jsx("textarea", { ...inputProps }) }) }));
|
|
1125
|
+
});
|
|
1126
|
+
|
|
1127
|
+
Input.Textarea = Textarea;
|
|
1128
|
+
Input.Number = Number$2;
|
|
1129
|
+
Input.Range = Range;
|
|
1130
|
+
|
|
1131
|
+
const Content$1 = forwardRef((props, ref) => {
|
|
1132
|
+
const { getContainer = (trigger) => trigger?.offsetParent ?? document.body, trigger, arrow, arrowProps = {}, className, children, ...restProps } = props;
|
|
1133
|
+
const arrowCSS = useMemo(() => {
|
|
1134
|
+
let { left, top, pos } = arrowProps;
|
|
1135
|
+
let transform = "";
|
|
1136
|
+
switch (pos) {
|
|
1137
|
+
case "left":
|
|
1138
|
+
left += 2;
|
|
1139
|
+
transform = `translate(-100%, -50%) rotate(180deg)`;
|
|
1140
|
+
break;
|
|
1141
|
+
case "right":
|
|
1142
|
+
left -= 2;
|
|
1143
|
+
transform = `translate(0, -50%)`;
|
|
1144
|
+
break;
|
|
1145
|
+
case "top":
|
|
1146
|
+
top -= 2;
|
|
1147
|
+
transform = `translate(-50%, -50%) rotate(-90deg)`;
|
|
1148
|
+
break;
|
|
1149
|
+
case "bottom":
|
|
1150
|
+
top += 2;
|
|
1151
|
+
transform = `translate(-50%, -50%) rotate(90deg)`;
|
|
1152
|
+
break;
|
|
1153
|
+
}
|
|
1154
|
+
return {
|
|
1155
|
+
left,
|
|
1156
|
+
top,
|
|
1157
|
+
transform,
|
|
1158
|
+
};
|
|
1159
|
+
}, [arrowProps]);
|
|
1160
|
+
const content = (jsxs("div", { ref: ref, className: classNames("i-popup", className), ...restProps, children: [arrow && (jsx("svg", { xmlns: 'http://www.w3.org/2000/svg', className: 'i-popup-arrow', style: arrowCSS, children: jsx("path", { d: 'M0.5 0L1.5 0C1.5 4, 3 5.5, 5 7.5S8,10 8,12S7 14.5, 5 16.5S1.5,20 1.5,24L0.5 24L0.5 0z' }) })), children] }));
|
|
1161
|
+
return createPortal(content, getContainer(trigger));
|
|
1162
|
+
});
|
|
1163
|
+
|
|
1164
|
+
function Popup(props) {
|
|
1165
|
+
const { visible = false, content, trigger = "hover", gap = 12, offset = 8, fixed, position = "top", showDelay = 16, hideDelay = 12, touchable, arrow = true, align, fitSize, watchResize, clickOutside = true, disabled, referToWindow, style, className, getContainer, children, onVisibleChange, } = props;
|
|
1166
|
+
const triggerRef = useRef(null);
|
|
1167
|
+
const contentRef = useRef(null);
|
|
1168
|
+
const state = useReactive({
|
|
1169
|
+
show: false,
|
|
1170
|
+
toggling: false,
|
|
1171
|
+
style: { position: fixed ? "fixed" : "absolute" },
|
|
1172
|
+
arrowProps: {},
|
|
1173
|
+
});
|
|
1174
|
+
useClickAway((e) => {
|
|
1175
|
+
if (!clickOutside)
|
|
1176
|
+
return;
|
|
1177
|
+
const tar = e.target;
|
|
1178
|
+
const isContain = triggerRef.current?.contains(tar);
|
|
1179
|
+
if (!state.show)
|
|
1180
|
+
return;
|
|
1181
|
+
(!isContain || trigger === "contextmenu") && handleToggle(false);
|
|
1182
|
+
}, contentRef);
|
|
1183
|
+
const handleShow = () => {
|
|
1184
|
+
if (disabled)
|
|
1185
|
+
return;
|
|
1186
|
+
if (state.show &&
|
|
1187
|
+
(trigger !== "hover" || (trigger === "hover" && !touchable))) {
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
state.show = true;
|
|
1191
|
+
state.toggling && clearTimeout(state.toggling);
|
|
1192
|
+
state.toggling = setTimeout(() => {
|
|
1193
|
+
const [left, top, { arrowX, arrowY, arrowPos }] = getPosition(triggerRef.current, contentRef.current, {
|
|
1194
|
+
position,
|
|
1195
|
+
gap,
|
|
1196
|
+
offset,
|
|
1197
|
+
align,
|
|
1198
|
+
refWindow: referToWindow,
|
|
1199
|
+
});
|
|
1200
|
+
state.style = {
|
|
1201
|
+
...state.style,
|
|
1202
|
+
opacity: 1,
|
|
1203
|
+
transform: "none",
|
|
1204
|
+
left,
|
|
1205
|
+
top,
|
|
1206
|
+
};
|
|
1207
|
+
state.arrowProps = {
|
|
1208
|
+
left: arrowX,
|
|
1209
|
+
top: arrowY,
|
|
1210
|
+
pos: arrowPos,
|
|
1211
|
+
};
|
|
1212
|
+
state.toggling && clearTimeout(state.toggling);
|
|
1213
|
+
onVisibleChange?.(true);
|
|
1214
|
+
}, showDelay);
|
|
1215
|
+
};
|
|
1216
|
+
const handleHide = () => {
|
|
1217
|
+
if (!state.show)
|
|
1218
|
+
return;
|
|
1219
|
+
state.toggling = setTimeout(() => {
|
|
1220
|
+
state.style = {
|
|
1221
|
+
...state.style,
|
|
1222
|
+
opacity: 0,
|
|
1223
|
+
transform: "translate(0, 2px)",
|
|
1224
|
+
};
|
|
1225
|
+
setTimeout(() => {
|
|
1226
|
+
state.show = false;
|
|
1227
|
+
state.toggling && clearTimeout(state.toggling);
|
|
1228
|
+
onVisibleChange?.(false);
|
|
1229
|
+
}, 160);
|
|
1230
|
+
}, hideDelay);
|
|
1231
|
+
};
|
|
1232
|
+
const handleToggle = (action) => {
|
|
1233
|
+
if (action !== undefined) {
|
|
1234
|
+
action ? handleShow() : handleHide();
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
state.show ? handleHide() : handleShow();
|
|
1238
|
+
};
|
|
1239
|
+
const eventMaps = useCreation(() => ({
|
|
1240
|
+
click: {
|
|
1241
|
+
onClick: () => handleToggle(true),
|
|
1242
|
+
},
|
|
1243
|
+
hover: {
|
|
1244
|
+
onMouseEnter: () => handleToggle(true),
|
|
1245
|
+
onMouseLeave: () => handleToggle(false),
|
|
1246
|
+
},
|
|
1247
|
+
focus: {
|
|
1248
|
+
onFocus: () => handleToggle(true),
|
|
1249
|
+
onBlur: () => handleToggle(false),
|
|
1250
|
+
},
|
|
1251
|
+
contextmenu: {
|
|
1252
|
+
onContextMenu: (e) => {
|
|
1253
|
+
e.preventDefault();
|
|
1254
|
+
e.stopPropagation();
|
|
1255
|
+
if (state.show) {
|
|
1256
|
+
const [left, top] = getPointPosition(e, contentRef.current);
|
|
1257
|
+
state.style = {
|
|
1258
|
+
...state.style,
|
|
1259
|
+
left,
|
|
1260
|
+
top,
|
|
1261
|
+
};
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
state.show = true;
|
|
1265
|
+
state.toggling = setTimeout(() => {
|
|
1266
|
+
const [left, top] = getPointPosition(e, contentRef.current);
|
|
1267
|
+
state.style = {
|
|
1268
|
+
...state.style,
|
|
1269
|
+
opacity: 1,
|
|
1270
|
+
transform: "none",
|
|
1271
|
+
left,
|
|
1272
|
+
top,
|
|
1273
|
+
};
|
|
1274
|
+
state.toggling && clearTimeout(state.toggling);
|
|
1275
|
+
onVisibleChange?.(true);
|
|
1276
|
+
}, showDelay);
|
|
1277
|
+
},
|
|
1278
|
+
},
|
|
1279
|
+
none: {},
|
|
1280
|
+
}), []);
|
|
1281
|
+
const contentTouch = useMemo(() => {
|
|
1282
|
+
if (!touchable)
|
|
1283
|
+
return {};
|
|
1284
|
+
const events = {};
|
|
1285
|
+
if (trigger === "hover") {
|
|
1286
|
+
events["onMouseEnter"] = () => handleToggle(true);
|
|
1287
|
+
events["onMouseLeave"] = () => handleToggle(false);
|
|
1288
|
+
}
|
|
1289
|
+
return events;
|
|
1290
|
+
}, [touchable, trigger]);
|
|
1291
|
+
const computePosition = () => {
|
|
1292
|
+
if (!state.show)
|
|
1293
|
+
return;
|
|
1294
|
+
const [left, top, { arrowX, arrowY, arrowPos }] = getPosition(triggerRef.current, contentRef.current, {
|
|
1295
|
+
position,
|
|
1296
|
+
gap,
|
|
1297
|
+
offset,
|
|
1298
|
+
align,
|
|
1299
|
+
refWindow: referToWindow,
|
|
1300
|
+
});
|
|
1301
|
+
Object.assign(state, {
|
|
1302
|
+
style: { ...state.style, left, top },
|
|
1303
|
+
arrowProps: { left: arrowX, top: arrowY, pos: arrowPos },
|
|
1304
|
+
});
|
|
1305
|
+
};
|
|
1306
|
+
useEffect(() => {
|
|
1307
|
+
if (trigger === "contextmenu")
|
|
1308
|
+
return;
|
|
1309
|
+
const { observe, unobserve, disconnect } = useResizeObserver();
|
|
1310
|
+
triggerRef.current && observe(triggerRef.current, computePosition);
|
|
1311
|
+
if (!watchResize || !contentRef.current)
|
|
1312
|
+
return;
|
|
1313
|
+
observe(contentRef.current, computePosition);
|
|
1314
|
+
return () => {
|
|
1315
|
+
if (!watchResize || !contentRef.current)
|
|
1316
|
+
return;
|
|
1317
|
+
unobserve(contentRef.current);
|
|
1318
|
+
triggerRef.current && unobserve(triggerRef.current);
|
|
1319
|
+
disconnect();
|
|
1320
|
+
};
|
|
1321
|
+
}, [watchResize, contentRef.current, triggerRef.current]);
|
|
1322
|
+
useLayoutEffect(() => {
|
|
1323
|
+
if (!fitSize || !state.show)
|
|
1324
|
+
return;
|
|
1325
|
+
const vertical = ["top", "bottom"].includes(position);
|
|
1326
|
+
const size = triggerRef.current?.[vertical ? "offsetWidth" : "offsetHeight"];
|
|
1327
|
+
state.style = { ...state.style, [vertical ? "width" : "height"]: size };
|
|
1328
|
+
}, [state.show, fitSize]);
|
|
1329
|
+
useLayoutEffect(() => {
|
|
1330
|
+
handleToggle(visible);
|
|
1331
|
+
}, [visible]);
|
|
1332
|
+
return (jsxs(Fragment, { children: [Children.map(children, (child) => {
|
|
1333
|
+
if (!isValidElement(child))
|
|
1334
|
+
return;
|
|
1335
|
+
const { type, props } = child;
|
|
1336
|
+
if (typeof type === "function")
|
|
1337
|
+
return child;
|
|
1338
|
+
const { className, ...rest } = props;
|
|
1339
|
+
return cloneElement(child, {
|
|
1340
|
+
ref: triggerRef,
|
|
1341
|
+
className,
|
|
1342
|
+
...eventMaps[trigger],
|
|
1343
|
+
...rest,
|
|
1344
|
+
});
|
|
1345
|
+
}), state.show && (jsx(Content$1, { ref: contentRef, arrow: arrow && trigger !== "contextmenu", style: { ...style, ...state.style }, arrowProps: state.arrowProps, className: className, ...contentTouch, trigger: triggerRef.current, getContainer: getContainer, children: content }))] }));
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
const Dates = (props) => {
|
|
1349
|
+
const { value, month, weeks = ["一", "二", "三", "四", "五", "六", "日"], renderDate = (date) => date.date(), disabledDate, onDateClick, } = props;
|
|
1350
|
+
const today = dayjs();
|
|
1351
|
+
const dates = useMemo(() => {
|
|
1352
|
+
const dates = [];
|
|
1353
|
+
const lastDateOfLastMonth = month.add(-1, "month").endOf("month");
|
|
1354
|
+
let { $W, $D } = lastDateOfLastMonth;
|
|
1355
|
+
if ($W !== 0) {
|
|
1356
|
+
const lastMonthDates = Array.from({ length: $W }).map((whatever, i) => lastDateOfLastMonth.add(i + 1 - $W, "day"));
|
|
1357
|
+
dates.push(...lastMonthDates);
|
|
1358
|
+
}
|
|
1359
|
+
const lastDate = month.endOf("month");
|
|
1360
|
+
$D = lastDate.$D;
|
|
1361
|
+
$W = lastDate.$W;
|
|
1362
|
+
dates.push(...Array.from({ length: $D }).map((whatever, i) => lastDate.add(i + 1 - $D, "day")));
|
|
1363
|
+
if ($W !== 0) {
|
|
1364
|
+
dates.push(...Array.from({ length: 7 - $W }).map((whatever, i) => lastDate.add(i + 1, "day")));
|
|
1365
|
+
}
|
|
1366
|
+
return dates;
|
|
1367
|
+
}, [month]);
|
|
1368
|
+
const handleDateClick = useMemoizedFn((date) => {
|
|
1369
|
+
if (disabledDate?.(date))
|
|
1370
|
+
return;
|
|
1371
|
+
onDateClick?.(date);
|
|
1372
|
+
});
|
|
1373
|
+
return (jsxs(Fragment, { children: [jsx("div", { className: 'i-datepicker-weeks', children: weeks.map((week, i) => (jsx("span", { className: 'i-datepicker-week', children: week }, i))) }), jsx("div", { className: 'i-datepicker-dates', children: dates.map((date, i) => {
|
|
1374
|
+
const active = date.isSame(value, "day");
|
|
1375
|
+
const isSameMonth = date.isSame(month, "month");
|
|
1376
|
+
const isToday = date.isSame(today, "day");
|
|
1377
|
+
const disabled = disabledDate?.(date);
|
|
1378
|
+
return (jsx("div", { className: classNames("i-datepicker-item", {
|
|
1379
|
+
"i-datepicker-active": active,
|
|
1380
|
+
"i-datepicker-same-month": isSameMonth,
|
|
1381
|
+
"i-datepicker-today": isToday,
|
|
1382
|
+
"i-datepicker-disabled": disabled,
|
|
1383
|
+
}), onClick: () => handleDateClick(date), children: renderDate(date) }, i));
|
|
1384
|
+
}) })] }));
|
|
1385
|
+
};
|
|
1386
|
+
|
|
1387
|
+
const MONTHS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
|
1388
|
+
const YearMonth = (props) => {
|
|
1389
|
+
const { value, unitMonth = "月", unitYear = "年", renderYear, renderMonth, onClick, } = props;
|
|
1390
|
+
return (jsxs("a", { className: 'i-datepicker-action', "data-ripple": true, onClick: onClick, children: [jsx("span", { children: renderYear?.(value.year()) }), unitYear, jsx("span", { children: renderMonth?.(value.month() + 1) }), unitMonth] }));
|
|
1391
|
+
};
|
|
1392
|
+
const Panel = (props) => {
|
|
1393
|
+
const { value, unitYear, unitMonth, renderDate, renderMonth = (m) => m, renderYear = (y) => y, disabledDate, onDateClick, } = props;
|
|
1394
|
+
const state = useReactive({
|
|
1395
|
+
today: value,
|
|
1396
|
+
month: value || dayjs(),
|
|
1397
|
+
selectedYear: dayjs(),
|
|
1398
|
+
years: [],
|
|
1399
|
+
selectable: false,
|
|
1400
|
+
});
|
|
1401
|
+
const $years = useRef(null);
|
|
1402
|
+
const handleOperateMonth = useCallback((next) => {
|
|
1403
|
+
state.month = state.month[next ? "add" : "subtract"](1, "month");
|
|
1404
|
+
}, []);
|
|
1405
|
+
const handleChangeDate = (date) => {
|
|
1406
|
+
if (date.isSame(state.today, "day"))
|
|
1407
|
+
return;
|
|
1408
|
+
if (!date.isSame(state.month, "month")) {
|
|
1409
|
+
state.month = date;
|
|
1410
|
+
}
|
|
1411
|
+
state.today = date;
|
|
1412
|
+
onDateClick?.(date);
|
|
1413
|
+
};
|
|
1414
|
+
const handleChangeMonth = (month) => {
|
|
1415
|
+
state.month = state.month
|
|
1416
|
+
.year(state.selectedYear.year())
|
|
1417
|
+
.month(month - 1);
|
|
1418
|
+
state.selectable = false;
|
|
1419
|
+
};
|
|
1420
|
+
const getMoreYears = throttle({ interval: 100 }, (e) => {
|
|
1421
|
+
const isUp = e.deltaY < 0;
|
|
1422
|
+
state.years = state.years.map((y) => (y += isUp ? -1 : 1));
|
|
1423
|
+
});
|
|
1424
|
+
useEffect(() => {
|
|
1425
|
+
if (!state.selectable)
|
|
1426
|
+
return;
|
|
1427
|
+
state.selectedYear = state.month;
|
|
1428
|
+
const y = state.selectedYear.year();
|
|
1429
|
+
const years = Array.from({ length: 7 }).map((_, i) => y - 3 + i);
|
|
1430
|
+
state.years = [...years];
|
|
1431
|
+
}, [state.selectable]);
|
|
1432
|
+
useEffect(() => {
|
|
1433
|
+
state.today = value;
|
|
1434
|
+
state.month = value || dayjs();
|
|
1435
|
+
}, [value]);
|
|
1436
|
+
return (jsxs("div", { className: 'i-datepicker', children: [jsxs("div", { className: 'i-datepicker-units', children: [jsx(YearMonth, { value: state.month, unitYear: unitYear, unitMonth: unitMonth, renderMonth: renderMonth, renderYear: renderYear, onClick: () => (state.selectable = true) }), jsx("a", { className: 'ml-auto i-datepicker-action', "data-ripple": true, onClick: () => handleOperateMonth(false), children: jsx(Icon, { icon: jsx(KeyboardArrowLeftRound, {}) }) }), jsx("a", { className: 'i-datepicker-action', "data-ripple": true, onClick: () => handleOperateMonth(true), children: jsx(Icon, { icon: jsx(KeyboardArrowRightRound, {}) }) })] }), jsxs("div", { className: classNames("i-datepicker-ym", {
|
|
1437
|
+
"i-datepicker-active": state.selectable,
|
|
1438
|
+
}), children: [jsx(Helpericon, { active: true, className: 'i-datepicker-close', onClick: () => (state.selectable = false) }), jsx("div", { ref: $years, className: 'i-datepicker-years', onWheel: getMoreYears, children: state.years.map((y) => (jsx("a", { className: classNames("i-datepicker-year", {
|
|
1439
|
+
"i-datepicker-active": y === state.selectedYear.year(),
|
|
1440
|
+
}), onClick: () => (state.selectedYear =
|
|
1441
|
+
state.selectedYear.year(y)), children: renderYear(y) }, y))) }), jsx("div", { className: 'i-datepicker-months', children: MONTHS.map((m) => {
|
|
1442
|
+
return (jsx("a", { className: classNames("i-datepicker-month", {
|
|
1443
|
+
"i-datepicker-active": m === state.month.month() + 1,
|
|
1444
|
+
}), onClick: () => handleChangeMonth(m), children: renderMonth(m) }, m));
|
|
1445
|
+
}) })] }), jsx(Dates, { value: state.today, month: state.month, disabledDate: disabledDate, onDateClick: handleChangeDate, renderDate: renderDate })] }));
|
|
1446
|
+
};
|
|
1447
|
+
|
|
1448
|
+
dayjs.extend(customParseFormat);
|
|
1449
|
+
const FORMATTYPES = ["YYYY-MM-DD", "YYYY-M-D", "YYYY/MM/DD", "YYYY/M/D"];
|
|
1450
|
+
const Datepicker = (props) => {
|
|
1451
|
+
const { name, value, weeks, format = "YYYY-MM-DD", renderDate, renderMonth, renderYear, popupProps, disabledDate, onDateClick, onChange, onBlur, ...restProps } = props;
|
|
1452
|
+
const state = useReactive({
|
|
1453
|
+
value,
|
|
1454
|
+
});
|
|
1455
|
+
const [active, setActive] = useState(false);
|
|
1456
|
+
const dayJsValue = useMemo(() => {
|
|
1457
|
+
if (!state.value)
|
|
1458
|
+
return null;
|
|
1459
|
+
const date = dayjs(state.value, format, true);
|
|
1460
|
+
if (date.isValid())
|
|
1461
|
+
return date;
|
|
1462
|
+
return null;
|
|
1463
|
+
}, [state.value]);
|
|
1464
|
+
const handleDateClick = (date) => {
|
|
1465
|
+
handleChange(date.format(format));
|
|
1466
|
+
};
|
|
1467
|
+
const handleChange = (v) => {
|
|
1468
|
+
state.value = v;
|
|
1469
|
+
onChange?.(v);
|
|
1470
|
+
};
|
|
1471
|
+
const handleSetDate = () => {
|
|
1472
|
+
if (!state.value)
|
|
1473
|
+
return;
|
|
1474
|
+
const date = dayjs(state.value, FORMATTYPES, true);
|
|
1475
|
+
if (date.isValid()) {
|
|
1476
|
+
handleChange(date.format(format));
|
|
1477
|
+
return;
|
|
1478
|
+
}
|
|
1479
|
+
handleChange("");
|
|
1480
|
+
};
|
|
1481
|
+
const handleBlur = (e) => {
|
|
1482
|
+
onBlur?.(e);
|
|
1483
|
+
handleSetDate();
|
|
1484
|
+
};
|
|
1485
|
+
useEffect(() => {
|
|
1486
|
+
state.value = value;
|
|
1487
|
+
}, [value]);
|
|
1488
|
+
return (jsx(Popup, { visible: active, trigger: 'click', position: 'bottom', arrow: false, align: 'start', content: jsx(Panel, { value: dayJsValue, weeks: weeks, renderDate: renderDate, renderMonth: renderMonth, renderYear: renderYear, disabledDate: disabledDate, onDateClick: handleDateClick }), ...popupProps, watchResize: true, onVisibleChange: setActive, children: jsx(Input, { value: state.value, prepend: jsx(Icon, { icon: jsx(CalendarMonthTwotone, {}), className: 'i-datepicker-icon', size: '1em' }), onChange: handleChange, onBlur: handleBlur, onEnter: handleSetDate, ...restProps }) }));
|
|
1489
|
+
};
|
|
1490
|
+
|
|
1491
|
+
const Description = (props) => {
|
|
1492
|
+
const { data, colon, columns = 1, gap = ".5em", align, labelWidth, labelAlign, vertical, equally, style, className, } = props;
|
|
1493
|
+
return (jsx("div", { className: classNames("i-description", className), style: {
|
|
1494
|
+
["--description-label-width"]: labelWidth,
|
|
1495
|
+
gridTemplateColumns: `repeat(${columns}, ${equally ? "1fr" : "auto"})`,
|
|
1496
|
+
gap,
|
|
1497
|
+
textAlign: align,
|
|
1498
|
+
...style,
|
|
1499
|
+
}, children: data.map((item, i) => {
|
|
1500
|
+
const { label, value, style, hidden, rowSpan = 1, colSpan = 1, } = item;
|
|
1501
|
+
if (hidden)
|
|
1502
|
+
return jsx(Fragment$1, {}, i);
|
|
1503
|
+
return (jsxs("div", { className: classNames("i-description-item", {
|
|
1504
|
+
"i-description-item-vertical": vertical,
|
|
1505
|
+
}), style: {
|
|
1506
|
+
gridColumn: `span ${colSpan}`,
|
|
1507
|
+
gridRow: `span ${rowSpan}`,
|
|
1508
|
+
...style,
|
|
1509
|
+
}, children: [label && (jsxs("div", { className: 'i-description-label', style: { textAlign: labelAlign }, children: [label, colon] })), jsx("div", { className: 'i-description-value', children: value })] }, i));
|
|
1510
|
+
}) }));
|
|
1511
|
+
};
|
|
1512
|
+
|
|
1513
|
+
function Drawer(props) {
|
|
1514
|
+
const { visible, position = "left", header, footer, backdropClosable = true, hideCloseButton, className, children, onVisibleChange, onClose, ...restProps } = props;
|
|
1515
|
+
const [show, setShow] = useState(visible);
|
|
1516
|
+
const [active, setActive] = useState(visible);
|
|
1517
|
+
const toggable = useRef(true);
|
|
1518
|
+
useEffect(() => {
|
|
1519
|
+
visible ? handleShow() : handleHide();
|
|
1520
|
+
}, [visible]);
|
|
1521
|
+
const handleShow = useCallback(() => {
|
|
1522
|
+
if (!toggable.current)
|
|
1523
|
+
return;
|
|
1524
|
+
setShow(true);
|
|
1525
|
+
onVisibleChange?.(true);
|
|
1526
|
+
toggable.current = false;
|
|
1527
|
+
setTimeout(() => {
|
|
1528
|
+
setActive(true);
|
|
1529
|
+
toggable.current = true;
|
|
1530
|
+
}, 24);
|
|
1531
|
+
}, []);
|
|
1532
|
+
const handleHide = useCallback(() => {
|
|
1533
|
+
if (!toggable.current)
|
|
1534
|
+
return;
|
|
1535
|
+
toggable.current = false;
|
|
1536
|
+
setActive(false);
|
|
1537
|
+
setTimeout(() => {
|
|
1538
|
+
setShow(false);
|
|
1539
|
+
onVisibleChange?.(false);
|
|
1540
|
+
toggable.current = true;
|
|
1541
|
+
onClose?.();
|
|
1542
|
+
}, 240);
|
|
1543
|
+
}, []);
|
|
1544
|
+
const handleBackdropClick = useCallback(function () {
|
|
1545
|
+
backdropClosable && handleHide();
|
|
1546
|
+
}, []);
|
|
1547
|
+
return createPortal(show && (jsx("div", { className: classNames("i-backdrop-drawer", className, {
|
|
1548
|
+
"i-active": active,
|
|
1549
|
+
}), onClick: handleBackdropClick, ...restProps, children: jsxs("div", { className: classNames("i-drawer", `i-drawer-${position}`), onClick: (e) => e.stopPropagation(), children: [jsxs("header", { className: 'i-drawer-header', children: [header, jsx(Helpericon, { active: !hideCloseButton, className: 'i-drawer-close', onClick: handleHide })] }), jsx("div", { className: 'i-drawer-content', children: children }), jsx("div", { className: 'i-drawer-footer', children: footer })] }) })), document.body);
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
const Item$4 = forwardRef((props, ref) => {
|
|
1553
|
+
const { active, type, align, disabled, label, style, className, children, ...restProps } = props;
|
|
1554
|
+
return (jsxs("li", { ref: ref, className: classNames("i-list-item", className, {
|
|
1555
|
+
"i-list-item-active": active,
|
|
1556
|
+
"i-list-option": type === "option",
|
|
1557
|
+
disabled,
|
|
1558
|
+
}), style: { alignItems: align, ...style }, ...restProps, children: [label !== undefined && (jsx("span", { className: 'i-list-item-label', children: label })), children] }));
|
|
1559
|
+
});
|
|
1560
|
+
|
|
1561
|
+
const Virtual = (props) => {
|
|
1562
|
+
const { data, itemKey, renderItem, ...restProps } = props;
|
|
1563
|
+
return (jsx(VList, { data: data, itemKey: itemKey, ...restProps, children: (item, i) => {
|
|
1564
|
+
return renderItem?.(item, i);
|
|
1565
|
+
} }));
|
|
1566
|
+
};
|
|
1567
|
+
|
|
1568
|
+
const List$1 = (props) => {
|
|
1569
|
+
const { label, type, className, children, ...restProps } = props;
|
|
1570
|
+
return (jsx("ul", { className: classNames("i-list", className), ...restProps, children: Children.map(children, (node, i) => {
|
|
1571
|
+
const renderLabel = typeof label === "function" ? label(i) : label;
|
|
1572
|
+
return cloneElement(node, {
|
|
1573
|
+
label: renderLabel,
|
|
1574
|
+
...node.props,
|
|
1575
|
+
type,
|
|
1576
|
+
});
|
|
1577
|
+
}) }));
|
|
1578
|
+
};
|
|
1579
|
+
List$1.Virtual = Virtual;
|
|
1580
|
+
List$1.Item = Item$4;
|
|
1581
|
+
|
|
1582
|
+
const { Item: ListItem } = List$1;
|
|
1583
|
+
const Item$3 = (props) => {
|
|
1584
|
+
const { more, moreProps, ...restProps } = props;
|
|
1585
|
+
const Li = jsx(ListItem, { ...restProps });
|
|
1586
|
+
if (!more)
|
|
1587
|
+
return Li;
|
|
1588
|
+
return (jsx(Popup, { position: 'right', touchable: true, arrow: false, align: 'start', offset: 10, ...moreProps, content: jsx(List$1, { className: 'i-dropdown-content', onClick: (e) => e.stopPropagation(), children: more }), children: Li }));
|
|
1589
|
+
};
|
|
1590
|
+
|
|
1591
|
+
const Dropdown = (props) => {
|
|
1592
|
+
const { width, content, children, ...restProps } = props;
|
|
1593
|
+
return (jsx(Popup, { trigger: 'click', position: 'bottom', touchable: true, content: jsx(List$1, { className: 'i-dropdown-content', style: { minWidth: width }, children: content }), ...restProps, children: children }));
|
|
1594
|
+
};
|
|
1595
|
+
Dropdown.Item = Item$3;
|
|
1596
|
+
|
|
1597
|
+
const Flex = (props) => {
|
|
1598
|
+
const { as: Component = "div", align, justify, direction, wrap, gap, columns, className, style, ...restProps } = props;
|
|
1599
|
+
const gridColumns = useMemo(() => {
|
|
1600
|
+
if (!columns)
|
|
1601
|
+
return;
|
|
1602
|
+
if (typeof columns === "number")
|
|
1603
|
+
return `repeat(${columns}, 1fr)`;
|
|
1604
|
+
return columns;
|
|
1605
|
+
}, [columns]);
|
|
1606
|
+
return (jsx(Component, { ...restProps, style: {
|
|
1607
|
+
alignItems: align,
|
|
1608
|
+
justifyContent: justify,
|
|
1609
|
+
gap,
|
|
1610
|
+
flexDirection: direction,
|
|
1611
|
+
flexWrap: wrap === true ? "wrap" : wrap,
|
|
1612
|
+
gridTemplateColumns: gridColumns,
|
|
1613
|
+
...style,
|
|
1614
|
+
}, className: classNames(className, {
|
|
1615
|
+
[columns ? "grid" : "flex"]: true,
|
|
1616
|
+
}) }));
|
|
1617
|
+
};
|
|
1618
|
+
|
|
1619
|
+
const Context = createContext({});
|
|
1620
|
+
|
|
1621
|
+
function Field(props) {
|
|
1622
|
+
const { name, required, children } = props;
|
|
1623
|
+
const state = useReactive({
|
|
1624
|
+
value: undefined,
|
|
1625
|
+
status: "normal",
|
|
1626
|
+
message: undefined,
|
|
1627
|
+
update: 0,
|
|
1628
|
+
});
|
|
1629
|
+
const form = useContext(Context);
|
|
1630
|
+
const { id } = form;
|
|
1631
|
+
const handleChange = useCallback((v) => {
|
|
1632
|
+
if (!name)
|
|
1633
|
+
return;
|
|
1634
|
+
form.set(name, v);
|
|
1635
|
+
}, [name]);
|
|
1636
|
+
const hijackChildren = useMemo(() => {
|
|
1637
|
+
return Children.map(children, (node) => {
|
|
1638
|
+
if (!isValidElement(node))
|
|
1639
|
+
return null;
|
|
1640
|
+
const { onChange } = node.props;
|
|
1641
|
+
const { value, status, message } = state;
|
|
1642
|
+
return cloneElement(node, {
|
|
1643
|
+
value,
|
|
1644
|
+
status,
|
|
1645
|
+
message,
|
|
1646
|
+
required,
|
|
1647
|
+
onChange: (...args) => {
|
|
1648
|
+
handleChange(args[0]);
|
|
1649
|
+
onChange?.(...args);
|
|
1650
|
+
Object.assign(state, {
|
|
1651
|
+
status: "normal",
|
|
1652
|
+
message: undefined,
|
|
1653
|
+
});
|
|
1654
|
+
},
|
|
1655
|
+
});
|
|
1656
|
+
});
|
|
1657
|
+
}, [children, state.update]);
|
|
1658
|
+
useEffect(() => {
|
|
1659
|
+
if (!name)
|
|
1660
|
+
return;
|
|
1661
|
+
PubSub.subscribe(`${id}:set:${name}`, (evt, v) => {
|
|
1662
|
+
state.value = v;
|
|
1663
|
+
state.update += 1;
|
|
1664
|
+
});
|
|
1665
|
+
PubSub.subscribe(`${id}:invalid:${name}`, (evt, v) => {
|
|
1666
|
+
Object.assign(state, v);
|
|
1667
|
+
state.update += 1;
|
|
1668
|
+
});
|
|
1669
|
+
setTimeout(() => {
|
|
1670
|
+
form.data[name] = form.data[name] ?? undefined;
|
|
1671
|
+
}, 0);
|
|
1672
|
+
return () => {
|
|
1673
|
+
PubSub.unsubscribe(`${id}:set:${name}`);
|
|
1674
|
+
PubSub.unsubscribe(`${id}:invalid:${name}`);
|
|
1675
|
+
};
|
|
1676
|
+
}, [name]);
|
|
1677
|
+
if (!name)
|
|
1678
|
+
return children;
|
|
1679
|
+
return hijackChildren;
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
class IFormInstance {
|
|
1683
|
+
id;
|
|
1684
|
+
data = {};
|
|
1685
|
+
rules = {};
|
|
1686
|
+
constructor() {
|
|
1687
|
+
this.id = uid(8);
|
|
1688
|
+
this.data = {};
|
|
1689
|
+
}
|
|
1690
|
+
get(field) {
|
|
1691
|
+
return field ? this.data[field] : this.data;
|
|
1692
|
+
}
|
|
1693
|
+
set(field, value) {
|
|
1694
|
+
const id = this.id;
|
|
1695
|
+
if (!this.data)
|
|
1696
|
+
return;
|
|
1697
|
+
if (typeof field === "string") {
|
|
1698
|
+
this.data[field] = value;
|
|
1699
|
+
PubSub.publish(`${id}:set:${field}`, value);
|
|
1700
|
+
return;
|
|
1701
|
+
}
|
|
1702
|
+
Object.keys(field).map((name) => {
|
|
1703
|
+
this.data[name] = field[name];
|
|
1704
|
+
PubSub.publish(`${id}:set:${name}`, field[name]);
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
clear() {
|
|
1708
|
+
if (!this.data)
|
|
1709
|
+
return;
|
|
1710
|
+
Object.keys(this.data).map((name) => {
|
|
1711
|
+
PubSub.publish(`${this.id}:set:${name}`, undefined);
|
|
1712
|
+
this.data[name] = undefined;
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
async validate(field) {
|
|
1716
|
+
const { id, rules, data } = this;
|
|
1717
|
+
if (!rules)
|
|
1718
|
+
return data;
|
|
1719
|
+
if (field) {
|
|
1720
|
+
const o = rules[field];
|
|
1721
|
+
const rule = {
|
|
1722
|
+
validator: (v) => Array.isArray(v)
|
|
1723
|
+
? v.length > 0
|
|
1724
|
+
: ![undefined, null, ""].includes(v),
|
|
1725
|
+
message: undefined,
|
|
1726
|
+
};
|
|
1727
|
+
if (typeof o === "function") {
|
|
1728
|
+
rule.validator = o;
|
|
1729
|
+
}
|
|
1730
|
+
else if (o === true) {
|
|
1731
|
+
rule.message = "required";
|
|
1732
|
+
}
|
|
1733
|
+
else {
|
|
1734
|
+
Object.assign(rule, o);
|
|
1735
|
+
}
|
|
1736
|
+
const isValid = rule.validator?.(data[field], this);
|
|
1737
|
+
if (!isValid) {
|
|
1738
|
+
PubSub.publish(`${id}:invalid:${field}`, {
|
|
1739
|
+
message: rule.message,
|
|
1740
|
+
status: "error",
|
|
1741
|
+
});
|
|
1742
|
+
return false;
|
|
1743
|
+
}
|
|
1744
|
+
PubSub.publish(`${id}:invalid:${name}`, {
|
|
1745
|
+
message: null,
|
|
1746
|
+
status: "normal",
|
|
1747
|
+
});
|
|
1748
|
+
return true;
|
|
1749
|
+
}
|
|
1750
|
+
let isAllValid = true;
|
|
1751
|
+
Object.keys(data).map((name) => {
|
|
1752
|
+
const o = rules[name];
|
|
1753
|
+
if (o === undefined)
|
|
1754
|
+
return;
|
|
1755
|
+
const rule = {
|
|
1756
|
+
validator: (v) => (Array.isArray(v) ? v.length > 0 : !!v),
|
|
1757
|
+
message: undefined,
|
|
1758
|
+
};
|
|
1759
|
+
if (typeof o === "function") {
|
|
1760
|
+
rule.validator = o;
|
|
1761
|
+
}
|
|
1762
|
+
else if (o === true) {
|
|
1763
|
+
rule.message = "required";
|
|
1764
|
+
}
|
|
1765
|
+
else {
|
|
1766
|
+
Object.assign(rule, o);
|
|
1767
|
+
}
|
|
1768
|
+
const isValid = rule.validator?.(data[name], this);
|
|
1769
|
+
if (!isValid) {
|
|
1770
|
+
PubSub.publish(`${id}:invalid:${name}`, {
|
|
1771
|
+
message: rule.message,
|
|
1772
|
+
status: "error",
|
|
1773
|
+
});
|
|
1774
|
+
isAllValid = false;
|
|
1775
|
+
}
|
|
1776
|
+
else {
|
|
1777
|
+
PubSub.publish(`${id}:invalid:${name}`, {
|
|
1778
|
+
message: null,
|
|
1779
|
+
status: "normal",
|
|
1780
|
+
});
|
|
1781
|
+
}
|
|
1782
|
+
});
|
|
1783
|
+
return isAllValid ? data : false;
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
function useForm(form) {
|
|
1787
|
+
const formRef = useRef();
|
|
1788
|
+
if (!formRef.current) {
|
|
1789
|
+
formRef.current = form ?? new IFormInstance();
|
|
1790
|
+
}
|
|
1791
|
+
return formRef.current;
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
const Form = (props) => {
|
|
1795
|
+
const { form = {}, rules = {}, initialValues = {}, style, className, width, children, ...rest } = props;
|
|
1796
|
+
useEffect(() => {
|
|
1797
|
+
Object.assign(form, {
|
|
1798
|
+
data: { ...initialValues },
|
|
1799
|
+
rules: { ...rules },
|
|
1800
|
+
});
|
|
1801
|
+
}, [form, rules]);
|
|
1802
|
+
return (jsx(Context.Provider, { value: form, children: jsx("form", { style: { ...style, width }, className: classNames("i-form", className), ...rest, children: children }) }));
|
|
1803
|
+
};
|
|
1804
|
+
Form.useForm = useForm;
|
|
1805
|
+
Form.Field = Field;
|
|
1806
|
+
|
|
1807
|
+
function DefaultContent(props) {
|
|
1808
|
+
const { title, footer, hideCloseButton, footerLeft, okButtonProps = {
|
|
1809
|
+
children: "确定",
|
|
1810
|
+
onClick: props.onOk,
|
|
1811
|
+
}, cancelButtonProps = {
|
|
1812
|
+
secondary: true,
|
|
1813
|
+
children: "关闭",
|
|
1814
|
+
onClick: props.onClose,
|
|
1815
|
+
}, children, onClose, } = props;
|
|
1816
|
+
const showHeader = title || !hideCloseButton;
|
|
1817
|
+
const renderFooter = useMemo(() => {
|
|
1818
|
+
if (footer || footer === null)
|
|
1819
|
+
return footer;
|
|
1820
|
+
const propsOk = Object.assign({}, okButtonProps);
|
|
1821
|
+
const propsCancel = Object.assign({}, cancelButtonProps);
|
|
1822
|
+
return (jsxs(Fragment, { children: [footerLeft, jsx(Button, { ...propsOk }), jsx(Button, { ...propsCancel })] }));
|
|
1823
|
+
}, [footer, okButtonProps, cancelButtonProps]);
|
|
1824
|
+
return (jsxs(Fragment, { children: [showHeader && (jsxs("header", { className: 'i-modal-header', children: [title && jsx("b", { children: title }), jsx(Helpericon, { active: !hideCloseButton, className: 'i-modal-close', onClick: onClose })] })), jsx("div", { className: 'i-modal-content', children: children }), jsx("footer", { className: 'i-modal-footer', children: renderFooter })] }));
|
|
1825
|
+
}
|
|
1826
|
+
function Modal(props) {
|
|
1827
|
+
const { visible, title, footer, okButtonProps, cancelButtonProps, closable = true, hideBackdrop, backdropClosable = true, hideCloseButton, width, height, customized, fixed, shadow = true, children, style, className, footerLeft, onVisibleChange, onClose, onOk, ...restProps } = props;
|
|
1828
|
+
const [show, setShow] = useState(visible);
|
|
1829
|
+
const [active, setActive] = useState(false);
|
|
1830
|
+
const [bounced, setBounced] = useState(false);
|
|
1831
|
+
const toggable = useRef(true);
|
|
1832
|
+
const handleShow = useCallback(() => {
|
|
1833
|
+
if (!toggable.current)
|
|
1834
|
+
return;
|
|
1835
|
+
setShow(true);
|
|
1836
|
+
toggable.current = false;
|
|
1837
|
+
setTimeout(() => {
|
|
1838
|
+
setActive(true);
|
|
1839
|
+
onVisibleChange?.(true);
|
|
1840
|
+
toggable.current = true;
|
|
1841
|
+
}, 24);
|
|
1842
|
+
}, []);
|
|
1843
|
+
const handleHide = useCallback(() => {
|
|
1844
|
+
if (!toggable.current)
|
|
1845
|
+
return;
|
|
1846
|
+
toggable.current = false;
|
|
1847
|
+
if (!closable) {
|
|
1848
|
+
setBounced(true);
|
|
1849
|
+
setTimeout(() => {
|
|
1850
|
+
setBounced(false);
|
|
1851
|
+
toggable.current = true;
|
|
1852
|
+
}, 400);
|
|
1853
|
+
return;
|
|
1854
|
+
}
|
|
1855
|
+
setActive(false);
|
|
1856
|
+
setTimeout(() => {
|
|
1857
|
+
setShow(false);
|
|
1858
|
+
toggable.current = true;
|
|
1859
|
+
onVisibleChange?.(false);
|
|
1860
|
+
onClose?.();
|
|
1861
|
+
}, 240);
|
|
1862
|
+
}, [closable]);
|
|
1863
|
+
const handleBackdropClick = useCallback(function () {
|
|
1864
|
+
backdropClosable && handleHide();
|
|
1865
|
+
}, [closable, backdropClosable]);
|
|
1866
|
+
useEffect(() => {
|
|
1867
|
+
visible ? handleShow() : handleHide();
|
|
1868
|
+
}, [visible]);
|
|
1869
|
+
if (!show)
|
|
1870
|
+
return null;
|
|
1871
|
+
return createPortal(jsx("div", { className: classNames("i-modal-container", {
|
|
1872
|
+
"i-modal-backdrop": !hideBackdrop,
|
|
1873
|
+
"i-modal-customized": customized,
|
|
1874
|
+
"i-modal-active": active,
|
|
1875
|
+
fixed,
|
|
1876
|
+
}, className), style: style, onClick: handleBackdropClick, children: jsxs("div", { className: classNames("i-modal", {
|
|
1877
|
+
bounced,
|
|
1878
|
+
shadow,
|
|
1879
|
+
}), style: {
|
|
1880
|
+
width,
|
|
1881
|
+
height,
|
|
1882
|
+
}, onClick: (e) => e.stopPropagation(), ...restProps, children: [customized && children, !customized && (jsx(DefaultContent, { title: title, hideCloseButton: hideCloseButton, footer: footer, okButtonProps: okButtonProps, cancelButtonProps: cancelButtonProps, children: children, footerLeft: footerLeft, onOk: onOk, onClose: handleHide }))] }) }), document.body);
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
const HookModal = forwardRef((props, ref) => {
|
|
1886
|
+
const state = useReactive({});
|
|
1887
|
+
useImperativeHandle(ref, () => ({
|
|
1888
|
+
update: (config = {}) => {
|
|
1889
|
+
Object.assign(state, config);
|
|
1890
|
+
},
|
|
1891
|
+
}));
|
|
1892
|
+
return jsx(Modal, { ...props, ...state });
|
|
1893
|
+
});
|
|
1894
|
+
|
|
1895
|
+
const Text = (props) => {
|
|
1896
|
+
const { as: Tag = "span", size, weight, decoration, gradient, style, className, children, } = props;
|
|
1897
|
+
const gradients = useMemo(() => {
|
|
1898
|
+
if (!gradient || !Array.isArray(gradient))
|
|
1899
|
+
return {};
|
|
1900
|
+
return {
|
|
1901
|
+
background: `-webkit-linear-gradient(${gradient.join(",")})`,
|
|
1902
|
+
backgroundClip: "text",
|
|
1903
|
+
};
|
|
1904
|
+
}, [gradient]);
|
|
1905
|
+
return (jsx(Tag, { style: {
|
|
1906
|
+
fontSize: size,
|
|
1907
|
+
fontWeight: weight,
|
|
1908
|
+
textDecoration: decoration,
|
|
1909
|
+
...gradients,
|
|
1910
|
+
...style,
|
|
1911
|
+
}, className: classNames(className, {
|
|
1912
|
+
"i-text-gradient": gradient,
|
|
1913
|
+
}), children: children }));
|
|
1914
|
+
};
|
|
1915
|
+
|
|
1916
|
+
function Number$1(props) {
|
|
1917
|
+
const { count, to, decimal, thousand = ",", duration = 2400, easing, ...restProps } = props;
|
|
1918
|
+
const [n, setN] = useState(count);
|
|
1919
|
+
const number = useMemo(() => {
|
|
1920
|
+
if (n === undefined)
|
|
1921
|
+
return;
|
|
1922
|
+
const z = n.toFixed(decimal);
|
|
1923
|
+
if (!thousand)
|
|
1924
|
+
return z;
|
|
1925
|
+
return formatNumber(n, { precision: decimal, thousand });
|
|
1926
|
+
}, [n, thousand]);
|
|
1927
|
+
useEffect(() => {
|
|
1928
|
+
if (count === undefined || to === undefined)
|
|
1929
|
+
return;
|
|
1930
|
+
animate(count, to, duration, (v) => setN(count + v), easing);
|
|
1931
|
+
}, [to]);
|
|
1932
|
+
useEffect(() => setN(count), [count]);
|
|
1933
|
+
return jsx(Text, { ...restProps, children: number });
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
function Number(props) {
|
|
1937
|
+
const { seconds, zero, units, ...restProps } = props;
|
|
1938
|
+
const text = useMemo(() => {
|
|
1939
|
+
if (seconds === undefined)
|
|
1940
|
+
return "";
|
|
1941
|
+
return formatTime(seconds, {
|
|
1942
|
+
zero,
|
|
1943
|
+
units,
|
|
1944
|
+
});
|
|
1945
|
+
}, [seconds]);
|
|
1946
|
+
return jsx(Text, { ...restProps, children: text });
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
Text.Number = Number$1;
|
|
1950
|
+
Text.Time = Number;
|
|
1951
|
+
|
|
1952
|
+
function Circle(props) {
|
|
1953
|
+
const { value, height = 40, size = 8 } = props;
|
|
1954
|
+
return (jsxs("div", { className: 'i-progress-circle', children: [jsxs("svg", { width: height, height: height, children: [jsx("circle", { cx: height / 2, cy: height / 2, r: height / 2 - size / 2, fill: 'none', stroke: 'var(--background-opacity-2)', strokeWidth: size }), jsx("circle", { cx: height / 2, cy: height / 2, r: height / 2 - size / 2, fill: 'none', stroke: 'var(--color-main)', strokeWidth: size, strokeDasharray: 100, pathLength: 100, className: 'i-progress-circle-path', strokeLinecap: 'round', style: {
|
|
1955
|
+
strokeDashoffset: `calc(100 - ${value})`,
|
|
1956
|
+
} })] }), jsxs("span", { className: 'i-progress-circle-value', children: [jsx("span", { children: value }), jsx(Text, { size: '.81em', className: 'color-7', children: "%" })] })] }));
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
const Line = forwardRef((props, ref) => {
|
|
1960
|
+
const { value, size, barClass, dragging, renderCursor, onMouseDown } = props;
|
|
1961
|
+
return (jsx("div", { ref: ref, className: 'i-progress', style: { height: size }, onMouseDown: onMouseDown, children: jsx("div", { className: classNames("i-progress-bar", barClass, {
|
|
1962
|
+
"no-transition": dragging,
|
|
1963
|
+
}), style: { width: `${value}%` }, children: renderCursor && (jsx("a", { className: 'i-progress-cursor', children: renderCursor(value ?? 0) })) }) }));
|
|
1964
|
+
});
|
|
1965
|
+
|
|
1966
|
+
const Progress = (props) => {
|
|
1967
|
+
const { value = 0, size = 8, height = 40, precision = 0, style, draggable = true, type = "line", barClass, label, labelInline, className, renderCursor, onChange, } = props;
|
|
1968
|
+
const ref = useRef(null);
|
|
1969
|
+
const state = useReactive({
|
|
1970
|
+
value,
|
|
1971
|
+
dragging: false,
|
|
1972
|
+
width: 0,
|
|
1973
|
+
start: 0,
|
|
1974
|
+
});
|
|
1975
|
+
const toFixedValue = useMemo(() => {
|
|
1976
|
+
let value = +state.value.toFixed(precision);
|
|
1977
|
+
value = Math.min(100, value);
|
|
1978
|
+
value = Math.max(0, value);
|
|
1979
|
+
return value;
|
|
1980
|
+
}, [state.value, precision]);
|
|
1981
|
+
const handleMouseDown = useMemoizedFn((e) => {
|
|
1982
|
+
if (!ref.current || !draggable)
|
|
1983
|
+
return;
|
|
1984
|
+
const rect = ref.current.getBoundingClientRect();
|
|
1985
|
+
const value = ((e.pageX - rect.left) * 100) / rect.width;
|
|
1986
|
+
Object.assign(state, {
|
|
1987
|
+
value,
|
|
1988
|
+
width: rect.width,
|
|
1989
|
+
start: rect.left,
|
|
1990
|
+
dragging: true,
|
|
1991
|
+
});
|
|
1992
|
+
});
|
|
1993
|
+
const handleMouseMove = useMemoizedFn((e) => {
|
|
1994
|
+
if (!state.dragging || !draggable)
|
|
1995
|
+
return;
|
|
1996
|
+
e.preventDefault();
|
|
1997
|
+
const { start, width } = state;
|
|
1998
|
+
const offset = e.pageX - start;
|
|
1999
|
+
if (offset < 0 || offset > width)
|
|
2000
|
+
return;
|
|
2001
|
+
state.value = ((e.pageX - start) * 100) / width;
|
|
2002
|
+
});
|
|
2003
|
+
const handleMouseUp = useMemoizedFn(() => {
|
|
2004
|
+
if (!state.dragging || !draggable)
|
|
2005
|
+
return;
|
|
2006
|
+
onChange?.(toFixedValue);
|
|
2007
|
+
state.dragging = false;
|
|
2008
|
+
});
|
|
2009
|
+
useMouseMove(handleMouseMove);
|
|
2010
|
+
useMouseUp(handleMouseUp);
|
|
2011
|
+
useEffect(() => {
|
|
2012
|
+
if (value > 100) {
|
|
2013
|
+
state.value = 100;
|
|
2014
|
+
return;
|
|
2015
|
+
}
|
|
2016
|
+
if (value < 0) {
|
|
2017
|
+
state.value = 0;
|
|
2018
|
+
return;
|
|
2019
|
+
}
|
|
2020
|
+
state.value = value;
|
|
2021
|
+
}, [value]);
|
|
2022
|
+
return (jsxs("div", { className: classNames("i-input-label", className, {
|
|
2023
|
+
"i-input-inline": labelInline,
|
|
2024
|
+
}), style: style, children: [label && jsx("span", { className: 'i-input-label-text', children: label }), type === "line" && (jsx(Line, { ref: ref, size: size, barClass: barClass, dragging: state.dragging, value: state.value, renderCursor: renderCursor, onMouseDown: handleMouseDown })), type === "circle" && (jsx(Circle, { value: state.value, height: height, size: size }))] }));
|
|
2025
|
+
};
|
|
2026
|
+
|
|
2027
|
+
const Video = forwardRef((props, ref) => {
|
|
2028
|
+
const { style, hideControls, autoplay, muted, volume = 50, height, width, useOriginControls, timeProgressProps = {
|
|
2029
|
+
barClass: "bg-2",
|
|
2030
|
+
}, volumeProgressProps = {
|
|
2031
|
+
barClass: "bg-1",
|
|
2032
|
+
}, className, onFullScreenChange, ...restProps } = props;
|
|
2033
|
+
const state = useReactive({
|
|
2034
|
+
playing: autoplay,
|
|
2035
|
+
volume: muted ? 0 : volume,
|
|
2036
|
+
volumeCache: 0,
|
|
2037
|
+
muted,
|
|
2038
|
+
current: 0,
|
|
2039
|
+
duration: 0,
|
|
2040
|
+
isFullscreen: false,
|
|
2041
|
+
});
|
|
2042
|
+
const $v = useRef(null);
|
|
2043
|
+
const timeUpdateListener = (e) => {
|
|
2044
|
+
const tar = e.target;
|
|
2045
|
+
if (tar.paused)
|
|
2046
|
+
return;
|
|
2047
|
+
Object.assign(state, {
|
|
2048
|
+
current: tar.currentTime,
|
|
2049
|
+
});
|
|
2050
|
+
};
|
|
2051
|
+
const playChangeListener = (e) => {
|
|
2052
|
+
state.playing = !e.target.paused;
|
|
2053
|
+
};
|
|
2054
|
+
const fsChangeListener = () => {
|
|
2055
|
+
const tar = $v.current?.parentElement;
|
|
2056
|
+
if (!tar)
|
|
2057
|
+
return;
|
|
2058
|
+
state.isFullscreen = document.fullscreenElement === tar;
|
|
2059
|
+
};
|
|
2060
|
+
const volumeChangeListener = (e) => {
|
|
2061
|
+
const tar = e.target;
|
|
2062
|
+
Object.assign(state, {
|
|
2063
|
+
volume: tar.volume * 100,
|
|
2064
|
+
muted: tar.volume === 0,
|
|
2065
|
+
});
|
|
2066
|
+
};
|
|
2067
|
+
const handlePlay = () => {
|
|
2068
|
+
const v = $v.current;
|
|
2069
|
+
if (!v)
|
|
2070
|
+
return;
|
|
2071
|
+
v.paused ? v.play() : v.pause();
|
|
2072
|
+
};
|
|
2073
|
+
const handleReady = (e) => {
|
|
2074
|
+
const tar = e.target;
|
|
2075
|
+
Object.assign(state, {
|
|
2076
|
+
duration: tar.duration,
|
|
2077
|
+
current: tar.currentTime,
|
|
2078
|
+
});
|
|
2079
|
+
tar.volume = state.volume / 100;
|
|
2080
|
+
};
|
|
2081
|
+
const handleMuted = () => {
|
|
2082
|
+
const v = $v.current;
|
|
2083
|
+
if (!v)
|
|
2084
|
+
return;
|
|
2085
|
+
if (v.volume > 0) {
|
|
2086
|
+
state.volumeCache = v.volume;
|
|
2087
|
+
v.volume = 0;
|
|
2088
|
+
return;
|
|
2089
|
+
}
|
|
2090
|
+
v.volume = state.volumeCache === 0 ? 0.5 : state.volumeCache;
|
|
2091
|
+
};
|
|
2092
|
+
const handleStop = () => {
|
|
2093
|
+
const v = $v.current;
|
|
2094
|
+
if (!v)
|
|
2095
|
+
return;
|
|
2096
|
+
v.currentTime = 0;
|
|
2097
|
+
v.pause();
|
|
2098
|
+
};
|
|
2099
|
+
const handleFullscreen = () => {
|
|
2100
|
+
const tar = $v.current?.parentElement;
|
|
2101
|
+
if (!tar)
|
|
2102
|
+
return;
|
|
2103
|
+
state.isFullscreen ? exitFullScreen() : fullScreen(tar);
|
|
2104
|
+
onFullScreenChange?.(!state.isFullscreen);
|
|
2105
|
+
};
|
|
2106
|
+
const handleUpdateTime = (t) => {
|
|
2107
|
+
const v = $v.current;
|
|
2108
|
+
if (!v)
|
|
2109
|
+
return;
|
|
2110
|
+
v.currentTime = (state.duration * t) / 100;
|
|
2111
|
+
};
|
|
2112
|
+
const handleUpdateVolume = (t) => {
|
|
2113
|
+
const v = $v.current;
|
|
2114
|
+
if (!v)
|
|
2115
|
+
return;
|
|
2116
|
+
v.volume = t / 100;
|
|
2117
|
+
};
|
|
2118
|
+
useImperativeHandle(ref, () => ({
|
|
2119
|
+
play: () => {
|
|
2120
|
+
const v = $v.current;
|
|
2121
|
+
if (!v)
|
|
2122
|
+
return;
|
|
2123
|
+
v.play();
|
|
2124
|
+
},
|
|
2125
|
+
pause: () => {
|
|
2126
|
+
const v = $v.current;
|
|
2127
|
+
if (!v)
|
|
2128
|
+
return;
|
|
2129
|
+
v.pause();
|
|
2130
|
+
},
|
|
2131
|
+
stop: handleStop,
|
|
2132
|
+
fullscreen: handleFullscreen,
|
|
2133
|
+
getVideo: () => $v.current,
|
|
2134
|
+
}));
|
|
2135
|
+
useEffect(() => {
|
|
2136
|
+
const v = $v.current;
|
|
2137
|
+
if (!v)
|
|
2138
|
+
return;
|
|
2139
|
+
v.addEventListener("timeupdate", timeUpdateListener);
|
|
2140
|
+
v.addEventListener("play", playChangeListener);
|
|
2141
|
+
v.addEventListener("pause", playChangeListener);
|
|
2142
|
+
v.addEventListener("volumechange", volumeChangeListener);
|
|
2143
|
+
document.addEventListener("fullscreenchange", fsChangeListener);
|
|
2144
|
+
return () => {
|
|
2145
|
+
v.removeEventListener("timeupdate", timeUpdateListener);
|
|
2146
|
+
v.removeEventListener("play", playChangeListener);
|
|
2147
|
+
v.removeEventListener("pause", playChangeListener);
|
|
2148
|
+
v.removeEventListener("volumechange", volumeChangeListener);
|
|
2149
|
+
document.removeEventListener("fullscreenchange", fsChangeListener);
|
|
2150
|
+
};
|
|
2151
|
+
}, []);
|
|
2152
|
+
return (jsxs("div", { className: classNames("i-video", className), style: { height, width, ...style }, onClick: handlePlay, onDoubleClick: () => handleFullscreen(), children: [jsx("video", { ref: $v, onCanPlay: handleReady, ...restProps, controls: useOriginControls }), !hideControls && !useOriginControls && (jsxs("div", { className: 'i-video-controls', onClick: (e) => e.stopPropagation(), children: [jsxs("div", { className: 'i-video-control flex-1', children: [jsx(Button.Toggle, { className: 'i-video-btn', flat: true, square: true, after: jsx(Icon, { icon: jsx(PauseRound, {}) }), active: state.playing, onClick: handlePlay, children: jsx(Icon, { icon: jsx(PlayArrowRound, {}) }) }), jsx(Button, { className: 'i-video-btn', flat: true, square: true, onClick: handleStop, children: jsx(Icon, { icon: jsx(StopRound, {}) }) }), jsxs("span", { className: 'i-video-times', children: [jsx(Text.Time, { seconds: state.current }), " /", jsx(Text.Time, { seconds: state.duration })] }), jsx(Progress, { className: 'mr-8', ...timeProgressProps, value: (state.current / state.duration) * 100, onChange: handleUpdateTime })] }), jsx("div", { className: 'i-video-control', children: jsx(Button.Toggle, { className: 'i-video-btn', flat: true, square: true, after: jsx(Icon, { icon: jsx(FullscreenExitRound, {}) }), active: state.isFullscreen, onClick: () => handleFullscreen(), children: jsx(Icon, { icon: jsx(FullscreenRound, {}) }) }) }), jsxs("div", { className: 'i-video-control', children: [jsx(Button.Toggle, { className: 'i-video-btn', flat: true, square: true, active: state.volume <= 0, after: jsx(Icon, { icon: jsx(VolumeOffRound, {}), size: '1.2em' }), onClick: handleMuted, children: jsx(Icon, { icon: jsx(VolumeDownRound, {}) }) }), jsx(Progress, { style: { width: 100 }, className: 'mr-8', ...volumeProgressProps, value: state.volume, onChange: handleUpdateVolume })] })] }))] }));
|
|
2153
|
+
});
|
|
2154
|
+
|
|
2155
|
+
function renderFile(props) {
|
|
2156
|
+
const { name, suffix, type } = props;
|
|
2157
|
+
switch (type) {
|
|
2158
|
+
case TFileType.IMAGE:
|
|
2159
|
+
return jsx("img", { src: props.src });
|
|
2160
|
+
case TFileType.VIDEO:
|
|
2161
|
+
return jsx(Video, { ...props });
|
|
2162
|
+
default:
|
|
2163
|
+
return (jsxs("div", { className: 'i-preview-unknown', children: [jsx(Icon, { icon: jsx(FeedOutlined, {}), size: '3em' }), jsx("h5", { className: 'mt-4', children: name || suffix || "?" })] }));
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
function Content(props) {
|
|
2168
|
+
const { items = [], initial = 0, renderFile: renderFile$1 = renderFile, onRotate, onChange, onClose, onZoom, } = props;
|
|
2169
|
+
const state = useReactive({
|
|
2170
|
+
current: initial,
|
|
2171
|
+
rotate: 0,
|
|
2172
|
+
scale: 1,
|
|
2173
|
+
translate: `0, 0`,
|
|
2174
|
+
});
|
|
2175
|
+
const box = useRef(null);
|
|
2176
|
+
const files = useMemo(() => {
|
|
2177
|
+
return items.map((item) => {
|
|
2178
|
+
const o = {
|
|
2179
|
+
src: "",
|
|
2180
|
+
};
|
|
2181
|
+
if (typeof item === "string") {
|
|
2182
|
+
o.src = item;
|
|
2183
|
+
}
|
|
2184
|
+
else {
|
|
2185
|
+
Object.assign(o, item);
|
|
2186
|
+
}
|
|
2187
|
+
o.suffix = getSuffixByUrl(o.src) || "";
|
|
2188
|
+
o.type = getFileType(o.suffix, item["type"]);
|
|
2189
|
+
return o;
|
|
2190
|
+
});
|
|
2191
|
+
}, [items]);
|
|
2192
|
+
const { file, content } = useMemo(() => {
|
|
2193
|
+
const file = files[state.current];
|
|
2194
|
+
const content = renderFile$1(file);
|
|
2195
|
+
return {
|
|
2196
|
+
file,
|
|
2197
|
+
content,
|
|
2198
|
+
};
|
|
2199
|
+
}, [state.current, items]);
|
|
2200
|
+
const isImage = file.type === TFileType.IMAGE;
|
|
2201
|
+
const handleSwitch = (next) => {
|
|
2202
|
+
const l = files.length;
|
|
2203
|
+
const { current: before } = state;
|
|
2204
|
+
if (next >= l) {
|
|
2205
|
+
state.current = 0;
|
|
2206
|
+
}
|
|
2207
|
+
else if (next < 0) {
|
|
2208
|
+
state.current = l - 1;
|
|
2209
|
+
}
|
|
2210
|
+
else {
|
|
2211
|
+
state.current = next;
|
|
2212
|
+
}
|
|
2213
|
+
onChange?.(state.current, before);
|
|
2214
|
+
state.rotate = files[state.current].rotate || 0;
|
|
2215
|
+
if (state.scale !== 1) {
|
|
2216
|
+
state.scale = 1;
|
|
2217
|
+
onZoom?.(1);
|
|
2218
|
+
}
|
|
2219
|
+
onRotate?.(state.rotate);
|
|
2220
|
+
};
|
|
2221
|
+
const handleRotate = (deg) => {
|
|
2222
|
+
state.rotate += deg;
|
|
2223
|
+
onRotate?.(state.rotate);
|
|
2224
|
+
};
|
|
2225
|
+
const handleMouseWheel = throttle({ interval: 60 }, (e) => {
|
|
2226
|
+
if (!isImage)
|
|
2227
|
+
return;
|
|
2228
|
+
let after = state.scale + (e.deltaY < 0 ? 0.05 : -0.05);
|
|
2229
|
+
if (after > 2)
|
|
2230
|
+
after = 2;
|
|
2231
|
+
if (after < 0.25)
|
|
2232
|
+
after = 0.25;
|
|
2233
|
+
onZoom?.(after);
|
|
2234
|
+
state.scale = after;
|
|
2235
|
+
});
|
|
2236
|
+
return (jsxs(Fragment, { children: [jsx("div", { ref: box, className: 'i-preview-content', style: {
|
|
2237
|
+
transform: `rotate(${state.rotate}deg) scale(${state.scale})`,
|
|
2238
|
+
}, onWheel: handleMouseWheel, onClick: (e) => e.stopPropagation(), children: content }), jsxs("div", { className: 'i-preview-controls', children: [jsx(Button, { square: true, flat: true, onClick: onClose, children: jsx(Icon, { icon: jsx(CloseRound, {}) }) }), files.length > 1 && (jsxs("span", { className: 'px-8', children: [state.current + 1, " / ", files.length] })), state.scale !== 1 && (jsxs(Button, { flat: true, onClick: () => (state.scale = 1), children: [jsx(Icon, { icon: jsx(AspectRatioRound, {}) }), jsxs("span", { className: 'mt-4', children: [(state.scale * 100).toFixed(0), "%"] })] })), jsx(Button, { square: true, flat: true, href: file.src, target: '_blank', children: jsx(Icon, { icon: jsx(OpenInNewRound, {}) }) }), jsx(Button, { square: true, flat: true, href: file.src, download: true, target: '_blank', children: jsx(Icon, { icon: jsx(FileDownloadOutlined, {}) }) }), jsx(Button, { square: true, flat: true, onClick: () => handleRotate(90), children: jsx(Icon, { icon: jsx(RotateRightRound, {}) }) }), jsx(Button, { square: true, flat: true, onClick: () => handleRotate(-90), children: jsx(Icon, { icon: jsx(RotateLeftRound, {}) }) }), files.length > 1 && (jsxs(Fragment, { children: [jsx(Button, { square: true, flat: true, onClick: () => handleSwitch(state.current - 1), children: jsx(Icon, { icon: jsx(KeyboardArrowLeftRound, {}) }) }), jsx(Button, { square: true, flat: true, onClick: () => handleSwitch(state.current + 1), children: jsx(Icon, { icon: jsx(KeyboardArrowRightRound, {}) }) })] }))] })] }));
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
function usePreview() {
|
|
2242
|
+
const ref = useRef(null);
|
|
2243
|
+
const preview = (config) => {
|
|
2244
|
+
const { items, modalProps, onClose, ...restProps } = config;
|
|
2245
|
+
const handleClose = () => {
|
|
2246
|
+
onClose?.();
|
|
2247
|
+
unMount?.();
|
|
2248
|
+
};
|
|
2249
|
+
const unMount = renderNode(jsx(HookModal, { ref: ref, visible: true, className: 'i-preview', customized: true, shadow: false, ...modalProps, children: jsx(Content, { ...restProps, items: items, onClose: () => {
|
|
2250
|
+
ref.current?.update({ visible: false });
|
|
2251
|
+
} }), fixed: true, onClose: handleClose }));
|
|
2252
|
+
};
|
|
2253
|
+
return preview;
|
|
2254
|
+
}
|
|
2255
|
+
|
|
2256
|
+
const Image = (props) => {
|
|
2257
|
+
const { src, round, size, initSize, lazyload, fallback = (jsx(Icon, { icon: jsx(HideImageTwotone, {}), size: '2em', className: 'color-5' })), fit, style, className, children, usePreview: previewable, onLoad, onError, onClick, ...restProps } = props;
|
|
2258
|
+
const state = useReactive({
|
|
2259
|
+
status: "loading",
|
|
2260
|
+
});
|
|
2261
|
+
const ref = useRef(null);
|
|
2262
|
+
const wh = fit ? "100%" : undefined;
|
|
2263
|
+
const { observe, unobserve } = useIntersectionObserver();
|
|
2264
|
+
const preview = usePreview();
|
|
2265
|
+
const handleError = (err) => {
|
|
2266
|
+
onError?.(err);
|
|
2267
|
+
state.status = "error";
|
|
2268
|
+
};
|
|
2269
|
+
const handleLoad = (e) => {
|
|
2270
|
+
onLoad?.(e);
|
|
2271
|
+
state.status = undefined;
|
|
2272
|
+
};
|
|
2273
|
+
const handleClick = (e) => {
|
|
2274
|
+
onClick?.(e);
|
|
2275
|
+
previewable &&
|
|
2276
|
+
src &&
|
|
2277
|
+
preview({
|
|
2278
|
+
items: [
|
|
2279
|
+
{
|
|
2280
|
+
src,
|
|
2281
|
+
type: TFileType.IMAGE,
|
|
2282
|
+
},
|
|
2283
|
+
],
|
|
2284
|
+
});
|
|
2285
|
+
};
|
|
2286
|
+
useEffect(() => {
|
|
2287
|
+
if (!src)
|
|
2288
|
+
return;
|
|
2289
|
+
state.status = "loading";
|
|
2290
|
+
if (!lazyload || !ref.current)
|
|
2291
|
+
return;
|
|
2292
|
+
observe(ref.current, (tar, visible) => {
|
|
2293
|
+
if (!visible)
|
|
2294
|
+
return;
|
|
2295
|
+
tar.setAttribute("src", tar.dataset.src || "");
|
|
2296
|
+
unobserve(tar);
|
|
2297
|
+
});
|
|
2298
|
+
return () => {
|
|
2299
|
+
ref.current && unobserve(ref.current);
|
|
2300
|
+
};
|
|
2301
|
+
}, [src]);
|
|
2302
|
+
restProps[lazyload ? "data-src" : "src"] = src;
|
|
2303
|
+
const iSize = state.status === "loading" ? initSize : undefined;
|
|
2304
|
+
return (jsx("div", { style: {
|
|
2305
|
+
width: size ?? iSize,
|
|
2306
|
+
height: size ?? iSize,
|
|
2307
|
+
...style,
|
|
2308
|
+
}, className: classNames("i-image", className, {
|
|
2309
|
+
rounded: round,
|
|
2310
|
+
[`i-image-${state.status}`]: state.status,
|
|
2311
|
+
}), children: state.status === "error" ? (fallback) : (jsxs(Fragment, { children: [src && (jsx("img", { ref: ref, style: { objectFit: fit, width: wh, height: wh }, ...restProps, onLoad: handleLoad, onError: handleError, onClick: handleClick })), src && state.status === "loading" && jsx(Loading, {}), children && jsx("div", { className: 'i-image-text', children: children })] })) }));
|
|
2312
|
+
};
|
|
2313
|
+
|
|
2314
|
+
function List(props) {
|
|
2315
|
+
const { items = [], gap = 8, columns, wrap, direction, usePreview: previewable, onClick, ...restProps } = props;
|
|
2316
|
+
const preview = usePreview();
|
|
2317
|
+
const files = useMemo(() => {
|
|
2318
|
+
return items.map((item) => {
|
|
2319
|
+
const o = {
|
|
2320
|
+
src: "",
|
|
2321
|
+
};
|
|
2322
|
+
if (typeof item === "string") {
|
|
2323
|
+
o.src = item;
|
|
2324
|
+
}
|
|
2325
|
+
else {
|
|
2326
|
+
Object.assign(o, item);
|
|
2327
|
+
}
|
|
2328
|
+
o.suffix = getSuffixByUrl(o.src) || "";
|
|
2329
|
+
o.type = getFileType(o.suffix, item["type"]);
|
|
2330
|
+
return o;
|
|
2331
|
+
});
|
|
2332
|
+
}, [items]);
|
|
2333
|
+
const handleClick = (e, i) => {
|
|
2334
|
+
onClick?.(e);
|
|
2335
|
+
previewable &&
|
|
2336
|
+
preview({
|
|
2337
|
+
items: files,
|
|
2338
|
+
initial: i,
|
|
2339
|
+
});
|
|
2340
|
+
};
|
|
2341
|
+
if (!files.length)
|
|
2342
|
+
return "";
|
|
2343
|
+
return (jsx(Flex, { className: 'i-image-list', gap: gap, columns: columns, wrap: wrap, direction: direction, children: files.map((img, i) => {
|
|
2344
|
+
return (jsx(Image, { src: img.src, size: 60, usePreview: false, onClick: (e) => handleClick(e, i), ...restProps }, i));
|
|
2345
|
+
}) }));
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2348
|
+
Image.List = List;
|
|
2349
|
+
|
|
2350
|
+
const AlignMap = {
|
|
2351
|
+
left: "flex-start",
|
|
2352
|
+
center: "center",
|
|
2353
|
+
right: "flex-end",
|
|
2354
|
+
};
|
|
2355
|
+
const GlobalConfig = {
|
|
2356
|
+
align: "center",
|
|
2357
|
+
offset: "12px",
|
|
2358
|
+
gap: 12,
|
|
2359
|
+
max: 0,
|
|
2360
|
+
};
|
|
2361
|
+
const ItemDefaultConfig = {
|
|
2362
|
+
duration: 3000,
|
|
2363
|
+
closable: true,
|
|
2364
|
+
active: false,
|
|
2365
|
+
};
|
|
2366
|
+
const container = createContainer();
|
|
2367
|
+
const handler = {
|
|
2368
|
+
callout(item) { },
|
|
2369
|
+
close() { },
|
|
2370
|
+
};
|
|
2371
|
+
const queue = {
|
|
2372
|
+
left: [],
|
|
2373
|
+
center: [],
|
|
2374
|
+
right: [],
|
|
2375
|
+
};
|
|
2376
|
+
const heights = {
|
|
2377
|
+
left: [],
|
|
2378
|
+
center: [],
|
|
2379
|
+
right: [],
|
|
2380
|
+
};
|
|
2381
|
+
createRoot(container).render(jsx(Messages, {}));
|
|
2382
|
+
const MessageItem = forwardRef(function ({ active, content, top, className, style, onClick }, ref) {
|
|
2383
|
+
return (jsx("div", { ref: ref, className: classNames("i-message", className, {
|
|
2384
|
+
"i-message-active": active,
|
|
2385
|
+
}), style: {
|
|
2386
|
+
...style,
|
|
2387
|
+
top,
|
|
2388
|
+
}, onClick: onClick, children: content }));
|
|
2389
|
+
});
|
|
2390
|
+
function Messages() {
|
|
2391
|
+
const ref = useRef(null);
|
|
2392
|
+
const state = useReactive({
|
|
2393
|
+
items: {
|
|
2394
|
+
left: [],
|
|
2395
|
+
center: [],
|
|
2396
|
+
right: [],
|
|
2397
|
+
},
|
|
2398
|
+
tops: {
|
|
2399
|
+
left: [],
|
|
2400
|
+
center: [],
|
|
2401
|
+
right: [],
|
|
2402
|
+
},
|
|
2403
|
+
});
|
|
2404
|
+
const offsetTop = {
|
|
2405
|
+
left: 0,
|
|
2406
|
+
center: 0,
|
|
2407
|
+
right: 0,
|
|
2408
|
+
};
|
|
2409
|
+
useEffect(() => {
|
|
2410
|
+
Object.assign(handler, {
|
|
2411
|
+
callout: function (item) {
|
|
2412
|
+
const { align = "center", unshift, onShow } = item;
|
|
2413
|
+
const size = queue[align][unshift ? "unshift" : "push"](item);
|
|
2414
|
+
state.items[align] = [...queue[align]];
|
|
2415
|
+
setTimeout(() => {
|
|
2416
|
+
const h = ref.current?.offsetHeight || 0;
|
|
2417
|
+
queue[align][unshift ? 0 : size - 1].active = true;
|
|
2418
|
+
state.items[align] = [...queue[align]];
|
|
2419
|
+
heights[align][unshift ? "unshift" : "push"](h);
|
|
2420
|
+
state.tops[align] = [...heights[align]];
|
|
2421
|
+
onShow?.();
|
|
2422
|
+
}, 0);
|
|
2423
|
+
item.duration !== 0 &&
|
|
2424
|
+
setTimeout(this.close.bind(item), item.duration);
|
|
2425
|
+
},
|
|
2426
|
+
close: function () {
|
|
2427
|
+
const item = this;
|
|
2428
|
+
const { align = "center", onHide } = item;
|
|
2429
|
+
const index = queue[align].findIndex((i) => i.id === item.id);
|
|
2430
|
+
if (index < 0)
|
|
2431
|
+
return;
|
|
2432
|
+
queue[align][index].active = false;
|
|
2433
|
+
state.items[align] = [...queue[align]];
|
|
2434
|
+
item.timer = setTimeout(() => {
|
|
2435
|
+
const index = queue[align].findIndex((i) => i.id === item.id);
|
|
2436
|
+
queue[align].splice(index, 1);
|
|
2437
|
+
heights[align].splice(index, 1);
|
|
2438
|
+
state.tops[align] = [...heights[align]];
|
|
2439
|
+
state.items[align] = [...queue[align]];
|
|
2440
|
+
item.timer && clearTimeout(item.timer);
|
|
2441
|
+
onHide?.();
|
|
2442
|
+
}, 240);
|
|
2443
|
+
},
|
|
2444
|
+
});
|
|
2445
|
+
}, []);
|
|
2446
|
+
const renderItems = (item, i) => {
|
|
2447
|
+
if (!item)
|
|
2448
|
+
return jsx(Fragment, {});
|
|
2449
|
+
const { id, active, content, align = "center", className } = item;
|
|
2450
|
+
offsetTop[align] += state.tops[align][i - 1] || 0;
|
|
2451
|
+
const top = GlobalConfig.gap * i + offsetTop[align];
|
|
2452
|
+
return (jsx(MessageItem, { ref: ref, active: active, content: content, top: top, className: className, style: { alignSelf: AlignMap[align] }, onClick: handler.close.bind(item) }, id));
|
|
2453
|
+
};
|
|
2454
|
+
return (jsxs("div", { className: 'i-messages', children: [state.items.left.map(renderItems), state.items.center.map(renderItems), state.items.right.map(renderItems)] }));
|
|
2455
|
+
}
|
|
2456
|
+
function message(config) {
|
|
2457
|
+
if (["string", "number"].includes(typeof config) ||
|
|
2458
|
+
isValidElement(config)) {
|
|
2459
|
+
config = { content: config };
|
|
2460
|
+
}
|
|
2461
|
+
config = Object.assign({ id: uid(7) }, ItemDefaultConfig, config);
|
|
2462
|
+
handler.callout(config);
|
|
2463
|
+
return handler.close.bind(config);
|
|
2464
|
+
}
|
|
2465
|
+
function createContainer(direction) {
|
|
2466
|
+
const container = document.createElement("div");
|
|
2467
|
+
container.dataset.id = "messages";
|
|
2468
|
+
document.body.append(container);
|
|
2469
|
+
return container;
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2472
|
+
function useModal() {
|
|
2473
|
+
const ref = useRef(null);
|
|
2474
|
+
const handleOpen = (props) => {
|
|
2475
|
+
const unMount = renderNode(jsx(HookModal, { ref: ref, visible: true, ...props, onClose: () => {
|
|
2476
|
+
props.onClose?.();
|
|
2477
|
+
unMount?.();
|
|
2478
|
+
} }));
|
|
2479
|
+
};
|
|
2480
|
+
const handleUpdate = (props) => {
|
|
2481
|
+
if (!ref.current)
|
|
2482
|
+
return;
|
|
2483
|
+
const { update } = ref.current;
|
|
2484
|
+
update(props);
|
|
2485
|
+
};
|
|
2486
|
+
return {
|
|
2487
|
+
open: handleOpen,
|
|
2488
|
+
update: handleUpdate,
|
|
2489
|
+
};
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
Modal.useModal = useModal;
|
|
2493
|
+
|
|
2494
|
+
const Page = (props) => {
|
|
2495
|
+
const { page, active, children, onChange } = props;
|
|
2496
|
+
const [loading, setLoading] = useState(false);
|
|
2497
|
+
const handleClick = async () => {
|
|
2498
|
+
if (active || loading)
|
|
2499
|
+
return;
|
|
2500
|
+
setLoading(true);
|
|
2501
|
+
await onChange?.(page);
|
|
2502
|
+
setLoading(false);
|
|
2503
|
+
};
|
|
2504
|
+
return (jsxs("a", { className: classNames("i-page", {
|
|
2505
|
+
"i-page-active": active,
|
|
2506
|
+
"i-page-loading": loading,
|
|
2507
|
+
"i-page-disabled": false,
|
|
2508
|
+
}), "data-page": page, onClick: handleClick, children: [loading && jsx(Loading, {}), children] }));
|
|
2509
|
+
};
|
|
2510
|
+
|
|
2511
|
+
const Pagination = (props) => {
|
|
2512
|
+
const { page: defaultPage = 1, size = 10, total = 0, sibling = 2, prev = jsx(Icon, { icon: jsx(KeyboardArrowLeftRound, {}) }), next = jsx(Icon, { icon: jsx(KeyboardArrowRightRound, {}) }), simple, jumper, className, renderEllipsis = () => (jsx(Icon, { icon: jsx(MoreHorizRound, {}), className: 'color-7' })), renderPage = (i) => i, onChange, ...restProps } = props;
|
|
2513
|
+
const [page, setPage] = useState(defaultPage);
|
|
2514
|
+
const [loading, setLoading] = useState(false);
|
|
2515
|
+
const totalPage = useMemo(() => Math.ceil(total / size), [size, total]);
|
|
2516
|
+
const [start, end, loop] = useMemo(() => {
|
|
2517
|
+
const start = Math.max(1, page - sibling);
|
|
2518
|
+
const end = Math.min(totalPage, page + sibling);
|
|
2519
|
+
return [
|
|
2520
|
+
start,
|
|
2521
|
+
end,
|
|
2522
|
+
Array.from({ length: end - start + 1 }).map((n, i) => start + i),
|
|
2523
|
+
];
|
|
2524
|
+
}, [page, totalPage, sibling]);
|
|
2525
|
+
if (totalPage <= page && page === 1)
|
|
2526
|
+
return jsx(Fragment, {});
|
|
2527
|
+
const handlePageChange = async (p) => {
|
|
2528
|
+
if (!onChange || loading)
|
|
2529
|
+
return;
|
|
2530
|
+
setLoading(true);
|
|
2531
|
+
return new Promise(async (resolve) => {
|
|
2532
|
+
if (p === undefined)
|
|
2533
|
+
return;
|
|
2534
|
+
await onChange(p);
|
|
2535
|
+
setPage(p);
|
|
2536
|
+
setLoading(false);
|
|
2537
|
+
resolve();
|
|
2538
|
+
});
|
|
2539
|
+
};
|
|
2540
|
+
useEffect(() => setPage(defaultPage), [defaultPage]);
|
|
2541
|
+
return (jsxs("div", { className: classNames("i-pagination", className), ...restProps, children: [prev && (jsx(Page, { page: page - 1 || 1, onChange: handlePageChange, children: prev })), start > 1 && (jsx(Page, { page: 1, onChange: handlePageChange, children: renderPage(1) })), start > 2 && renderEllipsis(), loop.map((p) => {
|
|
2542
|
+
return (jsx(Page, { page: p, active: p === page, onChange: handlePageChange, children: renderPage(p) }, p));
|
|
2543
|
+
}), end < totalPage - 1 && renderEllipsis(), end < totalPage && (jsx(Page, { page: totalPage, onChange: handlePageChange, children: renderPage(totalPage) })), next && (jsx(Page, { page: page + 1, onChange: handlePageChange, children: next }))] }));
|
|
2544
|
+
};
|
|
2545
|
+
|
|
2546
|
+
const defaultOk = {
|
|
2547
|
+
children: "确定",
|
|
2548
|
+
};
|
|
2549
|
+
const defaultCancel = {
|
|
2550
|
+
children: "取消",
|
|
2551
|
+
secondary: true,
|
|
2552
|
+
};
|
|
2553
|
+
const Popconfirm = (props) => {
|
|
2554
|
+
const { trigger = "click", visible, icon = jsx(Icon, { icon: jsx(InfoOutlined, {}), className: 'error' }), content, okButtonProps, cancelButtonProps, children, align = "end", position = "top", offset = 12, extra, onOk, onClose, ...restProps } = props;
|
|
2555
|
+
const state = useReactive({
|
|
2556
|
+
loading: false,
|
|
2557
|
+
visible,
|
|
2558
|
+
});
|
|
2559
|
+
const ok = okButtonProps
|
|
2560
|
+
? Object.assign({}, defaultOk, okButtonProps)
|
|
2561
|
+
: defaultOk;
|
|
2562
|
+
const cancel = cancelButtonProps
|
|
2563
|
+
? Object.assign({}, defaultCancel, cancelButtonProps)
|
|
2564
|
+
: defaultCancel;
|
|
2565
|
+
const handleVisibleChange = (v) => {
|
|
2566
|
+
state.visible = v;
|
|
2567
|
+
restProps.onVisibleChange?.(v);
|
|
2568
|
+
};
|
|
2569
|
+
const handleOk = async (e) => {
|
|
2570
|
+
state.loading = true;
|
|
2571
|
+
ok.onClick?.(e);
|
|
2572
|
+
await onOk?.();
|
|
2573
|
+
state.loading = false;
|
|
2574
|
+
state.visible = false;
|
|
2575
|
+
};
|
|
2576
|
+
const handleCancel = async (e) => {
|
|
2577
|
+
cancel.onClick?.(e);
|
|
2578
|
+
await onClose?.();
|
|
2579
|
+
state.visible = false;
|
|
2580
|
+
};
|
|
2581
|
+
const popconfirmContent = (jsxs("div", { className: 'i-popconfirm', children: [jsxs(Flex, { gap: 12, children: [icon, jsx("div", { className: 'i-popconfirm-content', children: content })] }), jsxs(Flex, { gap: 12, justify: 'flex-end', className: 'mt-8 i-popconfirm-footer', children: [cancelButtonProps !== null && (jsx(Button, { ...cancel, onClick: handleCancel })), extra, okButtonProps !== null && (jsx(Button, { loading: state.loading, ...ok, onClick: handleOk }))] })] }));
|
|
2582
|
+
return (jsx(Popup, { content: popconfirmContent, ...restProps, trigger: trigger, visible: state.visible, align: align, offset: offset, position: position, onVisibleChange: handleVisibleChange, children: children }));
|
|
2583
|
+
};
|
|
2584
|
+
|
|
2585
|
+
function RadioItem(props) {
|
|
2586
|
+
const { type = "default", name, value, checked, disabled, children, onChange, } = props;
|
|
2587
|
+
const handleChange = (e) => {
|
|
2588
|
+
onChange?.(value, e);
|
|
2589
|
+
};
|
|
2590
|
+
return (jsxs("label", { className: classNames("i-radio-item", { disabled }), children: [jsx("input", { type: 'radio', name: name, checked: checked, className: classNames("i-radio-input", `i-radio-${type}`), disabled: disabled, onChange: handleChange }), jsx("span", { className: 'i-radio-text', children: children })] }));
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2593
|
+
function Radio(props) {
|
|
2594
|
+
const { label, name, options, value, type = "default", status = "normal", message, optionInline = true, labelInline, disabled, required, className, onChange, } = props;
|
|
2595
|
+
const state = useReactive({
|
|
2596
|
+
value,
|
|
2597
|
+
});
|
|
2598
|
+
const formattedOptions = useMemo(() => formatOption(options), [options]);
|
|
2599
|
+
const handleChange = useMemoizedFn((value, e) => {
|
|
2600
|
+
state.value = value;
|
|
2601
|
+
onChange?.(value, e);
|
|
2602
|
+
});
|
|
2603
|
+
useEffect(() => {
|
|
2604
|
+
state.value = value;
|
|
2605
|
+
}, [value]);
|
|
2606
|
+
return (jsxs("div", { className: classNames("i-radio i-input-label", {
|
|
2607
|
+
[`i-radio-${status}`]: status !== "normal",
|
|
2608
|
+
"i-input-inline": labelInline,
|
|
2609
|
+
}, className), children: [label && (jsxs("span", { className: 'i-input-label-text', children: [required && jsx("span", { className: 'error', children: "*" }), label, message && jsx("p", { className: 'i-radio-message', children: message })] })), jsx("div", { className: classNames("i-radio-options", {
|
|
2610
|
+
"i-options-block": !optionInline,
|
|
2611
|
+
"i-radio-options-button": type === "button",
|
|
2612
|
+
}), children: formattedOptions.map((option) => (jsx(RadioItem, { name: name, value: option.value, checked: state.value === option.value, type: type, disabled: disabled || option.disabled, onChange: handleChange, children: option.label }, option.value))) })] }));
|
|
2613
|
+
}
|
|
2614
|
+
Radio.Item = RadioItem;
|
|
2615
|
+
|
|
2616
|
+
const Tag = (props) => {
|
|
2617
|
+
const { dot, dotClass, outline, round, size = "normal", className, children, onClose, onClick, ...restProps } = props;
|
|
2618
|
+
return (jsxs("span", { className: classNames("i-tag", {
|
|
2619
|
+
"i-tag-outline": outline,
|
|
2620
|
+
"i-tag-clickable": onClick,
|
|
2621
|
+
[`i-tag-${size}`]: size !== "normal",
|
|
2622
|
+
round,
|
|
2623
|
+
}, className), onClick: onClick, ...restProps, children: [dot && jsx("span", { className: classNames("i-tag-dot", dotClass) }), children, onClose && (jsx(Helpericon, { active: true, className: 'i-tag-close', onClick: onClose }))] }));
|
|
2624
|
+
};
|
|
2625
|
+
|
|
2626
|
+
const Options = (props) => {
|
|
2627
|
+
const { value: val, options, filter, filterPlaceholder, multiple, empty = jsx(Empty, {}), onSelect, onFilter, } = props;
|
|
2628
|
+
return (jsxs("div", { className: classNames("i-select-options", {
|
|
2629
|
+
"i-select-options-multiple": multiple,
|
|
2630
|
+
}), children: [filter && multiple && (jsxs("div", { className: 'i-select-filter', children: [jsx(Icon, { icon: jsx(SearchRound, {}), className: 'color-8 ml-8 my-auto', size: '1.2em' }), jsx("input", { type: 'text', className: 'i-input', placeholder: filterPlaceholder, onChange: onFilter })] })), options.length === 0 && empty, options.map((option, i) => {
|
|
2631
|
+
const { label, value, disabled } = option;
|
|
2632
|
+
const isActive = multiple
|
|
2633
|
+
? val?.includes(value)
|
|
2634
|
+
: val === value;
|
|
2635
|
+
return (jsxs(List$1.Item, { active: isActive, type: 'option', onClick: () => onSelect?.(value, option), disabled: disabled, children: [multiple && (jsx(Icon, { icon: jsx(CheckRound, {}), className: 'i-select-option-check', size: '1em' })), label] }, value || i));
|
|
2636
|
+
})] }));
|
|
2637
|
+
};
|
|
2638
|
+
const activeOptions = (options = [], value = [], max = 3) => {
|
|
2639
|
+
const total = options.flatMap((opt) => value.includes(opt.value) ? [opt] : []);
|
|
2640
|
+
if (max >= total.length)
|
|
2641
|
+
return total;
|
|
2642
|
+
const rest = total.length - max;
|
|
2643
|
+
const after = total.slice(0, max);
|
|
2644
|
+
after.push(rest);
|
|
2645
|
+
return after;
|
|
2646
|
+
};
|
|
2647
|
+
const displayValue = (config) => {
|
|
2648
|
+
const { options, value, maxDisplay, multiple, onSelect } = config;
|
|
2649
|
+
if (multiple) {
|
|
2650
|
+
return activeOptions(options, value, maxDisplay).map((opt, i) => {
|
|
2651
|
+
if (typeof opt === "number")
|
|
2652
|
+
return jsxs(Tag, { children: ["+", opt] }, i);
|
|
2653
|
+
const { label, value } = opt;
|
|
2654
|
+
return (jsx(Tag, { onClose: (e) => {
|
|
2655
|
+
e?.stopPropagation();
|
|
2656
|
+
onSelect?.(value, opt);
|
|
2657
|
+
}, children: label }, value));
|
|
2658
|
+
});
|
|
2659
|
+
}
|
|
2660
|
+
return options.find((opt) => opt.value === value)?.label;
|
|
2661
|
+
};
|
|
2662
|
+
|
|
2663
|
+
const Select = forwardRef((props, ref) => {
|
|
2664
|
+
const { type = "text", name, label, value = "", placeholder, options = [], multiple, prepend, append, labelInline, style, className, message, status = "normal", hideClear, maxDisplay, border, filter, tip, filterPlaceholder = "...", popupProps, onSelect, onChange, ...restProps } = props;
|
|
2665
|
+
const state = useReactive({
|
|
2666
|
+
inputValue: "",
|
|
2667
|
+
filterValue: "",
|
|
2668
|
+
value,
|
|
2669
|
+
loading: false,
|
|
2670
|
+
});
|
|
2671
|
+
const [active, setActive] = useState(false);
|
|
2672
|
+
const formattedOptions = useMemo(() => formatOption(options), [options]);
|
|
2673
|
+
const filterOptions = useMemo(() => {
|
|
2674
|
+
const { filterValue: fv } = state;
|
|
2675
|
+
if (!fv || !filter)
|
|
2676
|
+
return formattedOptions;
|
|
2677
|
+
const filterFn = typeof filter === "function"
|
|
2678
|
+
? filter
|
|
2679
|
+
: (opt) => opt.value.includes(fv) || opt.label.includes(fv);
|
|
2680
|
+
return formattedOptions.filter(filterFn);
|
|
2681
|
+
}, [formattedOptions, filter, state.filterValue]);
|
|
2682
|
+
const changeValue = (v) => {
|
|
2683
|
+
state.value = v;
|
|
2684
|
+
onChange?.(v);
|
|
2685
|
+
};
|
|
2686
|
+
const handleSelect = useCallback((value, option) => {
|
|
2687
|
+
onSelect?.(value, option);
|
|
2688
|
+
if (multiple) {
|
|
2689
|
+
const values = [...state.value];
|
|
2690
|
+
const i = values.findIndex((v) => v === value);
|
|
2691
|
+
i > -1 ? values.splice(i, 1) : values.push(value);
|
|
2692
|
+
changeValue(values);
|
|
2693
|
+
return;
|
|
2694
|
+
}
|
|
2695
|
+
setActive(false);
|
|
2696
|
+
changeValue(value);
|
|
2697
|
+
}, []);
|
|
2698
|
+
const handleVisibleChange = (visible) => {
|
|
2699
|
+
setActive(visible);
|
|
2700
|
+
if (!filter)
|
|
2701
|
+
return;
|
|
2702
|
+
state.filterValue = "";
|
|
2703
|
+
};
|
|
2704
|
+
const handleHelperClick = (e) => {
|
|
2705
|
+
if (!active)
|
|
2706
|
+
return;
|
|
2707
|
+
changeValue(multiple ? [] : "");
|
|
2708
|
+
};
|
|
2709
|
+
const handleFilterChange = useMemoizedFn(debounce({ delay: 400 }, (e) => {
|
|
2710
|
+
const v = e.target.value;
|
|
2711
|
+
state.filterValue = v;
|
|
2712
|
+
}));
|
|
2713
|
+
const handleInputChange = (e) => {
|
|
2714
|
+
state.filterValue = e.target.value;
|
|
2715
|
+
};
|
|
2716
|
+
useEffect(() => {
|
|
2717
|
+
state.value = value;
|
|
2718
|
+
}, [value]);
|
|
2719
|
+
const hasValue = multiple
|
|
2720
|
+
? state.value.length > 0
|
|
2721
|
+
: !!state.value;
|
|
2722
|
+
const clearable = !hideClear && active && hasValue;
|
|
2723
|
+
const text = message ?? tip;
|
|
2724
|
+
return (jsxs("label", { className: classNames("i-input-label", className, {
|
|
2725
|
+
"i-input-inline": labelInline,
|
|
2726
|
+
}), style: style, children: [label && jsx("span", { className: 'i-input-label-text', children: label }), jsx(Popup, { position: 'bottom', arrow: false, fitSize: true, ...popupProps, visible: active, trigger: 'none', onVisibleChange: handleVisibleChange, content: jsx(Options, { options: filterOptions, value: state.value, multiple: multiple, filter: !!filter, filterPlaceholder: filterPlaceholder, onSelect: handleSelect, onFilter: handleFilterChange }), children: jsxs("div", { className: classNames("i-input-item", {
|
|
2727
|
+
[`i-input-${status}`]: status !== "normal",
|
|
2728
|
+
"i-input-borderless": !border,
|
|
2729
|
+
"i-input-focus": active,
|
|
2730
|
+
}), onClick: () => setActive(true), children: [prepend, jsx("input", { ref: ref, type: 'hidden', value: state.value, ...restProps }), multiple ? (hasValue ? (jsx("div", { className: classNames("i-input i-select", {
|
|
2731
|
+
"i-select-multiple": multiple,
|
|
2732
|
+
}), children: displayValue({
|
|
2733
|
+
options: formattedOptions,
|
|
2734
|
+
value: state.value,
|
|
2735
|
+
multiple,
|
|
2736
|
+
maxDisplay,
|
|
2737
|
+
onSelect: handleSelect,
|
|
2738
|
+
}) })) : (jsx("input", { className: 'i-input i-select', placeholder: placeholder, readOnly: true }))) : null, !multiple && (jsx("input", { value: active ? state.filterValue : state.value, className: 'i-input i-select', placeholder: state.value || placeholder, onChange: handleInputChange, readOnly: !filter })), jsx(Helpericon, { active: true, icon: clearable ? undefined : jsx(UnfoldMoreRound, {}), onClick: handleHelperClick }), append] }) }), text && jsx("span", { className: 'i-input-message', children: text })] }));
|
|
2739
|
+
});
|
|
2740
|
+
|
|
2741
|
+
function Divider() {
|
|
2742
|
+
return jsx("i", { className: 'i-step-divider' });
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
const STATUS = ["finished", "active", "pending"];
|
|
2746
|
+
function defaultRenderIcon(i, status) {
|
|
2747
|
+
return (jsx("span", { className: 'i-step-item-index', children: status === "finished" ? (jsx(CheckRound, { style: { width: "1em", height: "1.5em" } })) : (i + 1) }));
|
|
2748
|
+
}
|
|
2749
|
+
function Item$2(props) {
|
|
2750
|
+
const { index = 0, active = 0, renderIcon = defaultRenderIcon, title, vertical, line = jsx(Divider, {}), style, className, children, onClick, } = props;
|
|
2751
|
+
const status = STATUS[index === active ? 1 : index < active ? 0 : 2];
|
|
2752
|
+
const handleClick = () => {
|
|
2753
|
+
onClick?.(index);
|
|
2754
|
+
};
|
|
2755
|
+
return (jsx("div", { style: style, className: classNames("i-step-item", `i-step-item-${status}`, className), onClick: handleClick, children: vertical ? (jsxs(Fragment, { children: [jsxs("div", { className: 'i-step-item-left', children: [renderIcon?.(index, status), line] }), jsxs("div", { className: 'i-step-item-right', children: [jsx("div", { className: 'i-step-item-title', children: title }), children && (jsx("div", { className: 'i-step-item-content', children: children }))] })] })) : (jsxs(Fragment, { children: [jsxs("div", { className: 'i-step-item-title', children: [renderIcon?.(index, status), jsx("span", { children: title }), line] }), children && (jsx("div", { className: 'i-step-item-content', children: children }))] })) }));
|
|
2756
|
+
}
|
|
2757
|
+
|
|
2758
|
+
const Step = (props) => {
|
|
2759
|
+
const { active = 0, vertical, renderIcon, line, style, className, children, onClick, } = props;
|
|
2760
|
+
const steps = useMemo(() => {
|
|
2761
|
+
const nodes = [];
|
|
2762
|
+
let index = 0;
|
|
2763
|
+
Children.map(children, (el) => {
|
|
2764
|
+
if (!el || el.type !== Item$2)
|
|
2765
|
+
return;
|
|
2766
|
+
const { props: elProps } = el;
|
|
2767
|
+
nodes.push({
|
|
2768
|
+
...el,
|
|
2769
|
+
props: {
|
|
2770
|
+
renderIcon,
|
|
2771
|
+
line,
|
|
2772
|
+
onClick,
|
|
2773
|
+
...elProps,
|
|
2774
|
+
vertical,
|
|
2775
|
+
active,
|
|
2776
|
+
index: index++,
|
|
2777
|
+
},
|
|
2778
|
+
});
|
|
2779
|
+
});
|
|
2780
|
+
return nodes;
|
|
2781
|
+
}, [active, children]);
|
|
2782
|
+
return (jsx("div", { className: classNames("i-step", { "i-step-vertical": vertical }, className), style: style, children: steps }));
|
|
2783
|
+
};
|
|
2784
|
+
Step.Item = Item$2;
|
|
2785
|
+
|
|
2786
|
+
function Item$1(props) {
|
|
2787
|
+
const { index = 0, active, type, transition, gap = 0, itemHeight, vertical, style, className, children, } = props;
|
|
2788
|
+
const selfStyle = useMemo(() => {
|
|
2789
|
+
if (type === "normal") {
|
|
2790
|
+
return {
|
|
2791
|
+
[vertical ? "paddingBlock" : "paddingInline"]: gap / 2,
|
|
2792
|
+
height: itemHeight,
|
|
2793
|
+
};
|
|
2794
|
+
}
|
|
2795
|
+
return {
|
|
2796
|
+
transform: `translate(-${index * 100}%, 0)`,
|
|
2797
|
+
transition,
|
|
2798
|
+
};
|
|
2799
|
+
}, [index, gap, itemHeight, vertical, type]);
|
|
2800
|
+
return (jsx("div", { style: { ...style, ...selfStyle }, className: classNames("i-swiper-item", className, {
|
|
2801
|
+
"i-swiper-active": active,
|
|
2802
|
+
}), "data-index": index, children: children }));
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2805
|
+
const Swiper = forwardRef((props, ref) => {
|
|
2806
|
+
const { type = "normal", initial = 0, display = 1, scroll = 1, loop = true, vertical, prev = jsx(Icon, { icon: jsx(KeyboardArrowLeftRound, {}), size: '2em' }), next = jsx(Icon, { icon: jsx(KeyboardArrowRightRound, {}), size: '2em' }), duration = 600, interval = 3000, autoplay, pauseOnHover, arrow = true, reverse, draggable, dragOffset = 40, gap = 0, itemHeight, indicator, style, className, children, renderIndicator, onBeforeSwipe, onAfterSwipe, } = props;
|
|
2807
|
+
const listRef = useRef(null);
|
|
2808
|
+
const timerRef = useRef(null);
|
|
2809
|
+
const transition = `all ${duration / 1000}s`;
|
|
2810
|
+
const state = useReactive({
|
|
2811
|
+
current: initial,
|
|
2812
|
+
swipable: true,
|
|
2813
|
+
transition: type === "fade" ? "none" : transition,
|
|
2814
|
+
dragStart: 0,
|
|
2815
|
+
dragging: false,
|
|
2816
|
+
initialized: false,
|
|
2817
|
+
});
|
|
2818
|
+
const items = useMemo(() => {
|
|
2819
|
+
return Children.map(children, (node) => {
|
|
2820
|
+
if (node.type !== Item$1)
|
|
2821
|
+
return;
|
|
2822
|
+
return node;
|
|
2823
|
+
});
|
|
2824
|
+
}, [children]);
|
|
2825
|
+
const [displayItems, extra, size, total, listSize] = useMemo(() => {
|
|
2826
|
+
const extra = type === "normal" && loop && items.length > display
|
|
2827
|
+
? display + 1
|
|
2828
|
+
: 0;
|
|
2829
|
+
let list = [];
|
|
2830
|
+
if (extra <= 0) {
|
|
2831
|
+
list = [...items];
|
|
2832
|
+
}
|
|
2833
|
+
else {
|
|
2834
|
+
const head = items.slice(0, extra);
|
|
2835
|
+
const tail = items.slice(-extra);
|
|
2836
|
+
list = [...tail, ...items, ...head];
|
|
2837
|
+
}
|
|
2838
|
+
const listSize = `${(list.length / display) * 100}%`;
|
|
2839
|
+
return [list, extra, items.length, list.length, listSize];
|
|
2840
|
+
}, [display, loop, type, items]);
|
|
2841
|
+
const offsetPercent = useMemo(() => (-100 * (state.current + extra)) / total, [state.current, total]);
|
|
2842
|
+
const position = useMemo(() => {
|
|
2843
|
+
if (size <= display || type === "fade")
|
|
2844
|
+
return;
|
|
2845
|
+
const offset = vertical
|
|
2846
|
+
? `0, ${offsetPercent}%`
|
|
2847
|
+
: `${offsetPercent}%, 0`;
|
|
2848
|
+
return `translate3d(${offset}, 0)`;
|
|
2849
|
+
}, [offsetPercent, vertical, display, size, type]);
|
|
2850
|
+
const trackStyle = useMemo(() => {
|
|
2851
|
+
if (!vertical || !itemHeight)
|
|
2852
|
+
return;
|
|
2853
|
+
return {
|
|
2854
|
+
height: itemHeight * display,
|
|
2855
|
+
};
|
|
2856
|
+
}, [vertical, itemHeight, display]);
|
|
2857
|
+
const indicatorsLoop = useMemo(() => {
|
|
2858
|
+
return Array.from({
|
|
2859
|
+
length: Math.ceil((size - display) / scroll) + 1,
|
|
2860
|
+
});
|
|
2861
|
+
}, [loop, indicator]);
|
|
2862
|
+
const clearTimer = () => {
|
|
2863
|
+
clearTimeout(timerRef.current);
|
|
2864
|
+
timerRef.current = null;
|
|
2865
|
+
};
|
|
2866
|
+
const swipeTo = useCallback((i) => {
|
|
2867
|
+
if (!state.swipable || i === state.current)
|
|
2868
|
+
return;
|
|
2869
|
+
state.swipable = false;
|
|
2870
|
+
onBeforeSwipe?.(state.current);
|
|
2871
|
+
let reset = false;
|
|
2872
|
+
let next = i;
|
|
2873
|
+
const lastDisplay = size - display;
|
|
2874
|
+
if (loop) {
|
|
2875
|
+
if (i > lastDisplay) {
|
|
2876
|
+
reset = true;
|
|
2877
|
+
i = size;
|
|
2878
|
+
next = 0;
|
|
2879
|
+
}
|
|
2880
|
+
else if (i < 0) {
|
|
2881
|
+
reset = true;
|
|
2882
|
+
i = -display;
|
|
2883
|
+
next = lastDisplay;
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
else {
|
|
2887
|
+
next = clamp(next, 0, lastDisplay);
|
|
2888
|
+
i = next;
|
|
2889
|
+
}
|
|
2890
|
+
setTimeout(() => {
|
|
2891
|
+
state.swipable = true;
|
|
2892
|
+
}, duration + 32);
|
|
2893
|
+
if (type === "fade") {
|
|
2894
|
+
state.current = next;
|
|
2895
|
+
onAfterSwipe?.(next);
|
|
2896
|
+
return;
|
|
2897
|
+
}
|
|
2898
|
+
state.current = i;
|
|
2899
|
+
if (!reset) {
|
|
2900
|
+
if (autoplay) {
|
|
2901
|
+
timerRef.current = setTimeout(swipeNext, interval);
|
|
2902
|
+
}
|
|
2903
|
+
setTimeout(() => {
|
|
2904
|
+
onAfterSwipe?.(next);
|
|
2905
|
+
}, duration + 12);
|
|
2906
|
+
return;
|
|
2907
|
+
}
|
|
2908
|
+
setTimeout(() => {
|
|
2909
|
+
state.transition = "none";
|
|
2910
|
+
state.current = next;
|
|
2911
|
+
onAfterSwipe?.(next);
|
|
2912
|
+
if (autoplay) {
|
|
2913
|
+
timerRef.current = setTimeout(swipeNext, interval);
|
|
2914
|
+
}
|
|
2915
|
+
setTimeout(() => {
|
|
2916
|
+
state.transition = transition;
|
|
2917
|
+
}, 60);
|
|
2918
|
+
}, duration + 20);
|
|
2919
|
+
}, [duration, autoplay]);
|
|
2920
|
+
const swipeNext = () => {
|
|
2921
|
+
swipeTo(reverse ? state.current - scroll : state.current + scroll);
|
|
2922
|
+
};
|
|
2923
|
+
const swipePrev = () => {
|
|
2924
|
+
swipeTo(reverse ? state.current + scroll : state.current - scroll);
|
|
2925
|
+
};
|
|
2926
|
+
const handleMouseDown = useCallback((e) => {
|
|
2927
|
+
if (!draggable || !state.swipable || type === "fade")
|
|
2928
|
+
return;
|
|
2929
|
+
e.stopPropagation();
|
|
2930
|
+
Object.assign(state, {
|
|
2931
|
+
dragStart: vertical ? e.clientY : e.clientX,
|
|
2932
|
+
dragging: true,
|
|
2933
|
+
transition: "none",
|
|
2934
|
+
});
|
|
2935
|
+
}, [draggable, vertical]);
|
|
2936
|
+
const handleMouseMove = useCallback((e) => {
|
|
2937
|
+
if (!state.dragging || !listRef.current)
|
|
2938
|
+
return;
|
|
2939
|
+
e.preventDefault();
|
|
2940
|
+
const dragEnd = vertical ? e.clientY : e.clientX;
|
|
2941
|
+
const offset = ((dragEnd - state.dragStart) * 61.8) /
|
|
2942
|
+
listRef.current[vertical ? "offsetHeight" : "offsetWidth"] +
|
|
2943
|
+
offsetPercent;
|
|
2944
|
+
listRef.current.style.transform = `translate3d(${vertical ? `0, ${offset}%` : `${offset}%, 0`}, 0)`;
|
|
2945
|
+
}, [vertical, listRef.current, offsetPercent]);
|
|
2946
|
+
const handleMouseUp = useCallback((e) => {
|
|
2947
|
+
if (!state.dragging || !listRef.current)
|
|
2948
|
+
return;
|
|
2949
|
+
const dragEnd = vertical ? e.clientY : e.clientX;
|
|
2950
|
+
const part = listRef.current[vertical ? "offsetHeight" : "offsetWidth"] /
|
|
2951
|
+
total;
|
|
2952
|
+
const offset = (dragEnd - state.dragStart) * 0.618;
|
|
2953
|
+
const absOffset = Math.abs(offset);
|
|
2954
|
+
if (absOffset > dragOffset) {
|
|
2955
|
+
const base = Math.floor(absOffset / part);
|
|
2956
|
+
const mod = (absOffset % part) - dragOffset > 0 ? 1 : 0;
|
|
2957
|
+
const p = base + mod;
|
|
2958
|
+
let to = state.current + (offset > 0 ? -p : p);
|
|
2959
|
+
swipeTo(to);
|
|
2960
|
+
}
|
|
2961
|
+
listRef.current.style.transform = position || "";
|
|
2962
|
+
Object.assign(state, {
|
|
2963
|
+
dragging: false,
|
|
2964
|
+
transition,
|
|
2965
|
+
});
|
|
2966
|
+
}, [vertical, listRef.current, offsetPercent]);
|
|
2967
|
+
const handleMouseOver = () => {
|
|
2968
|
+
if (!pauseOnHover)
|
|
2969
|
+
return;
|
|
2970
|
+
clearTimer();
|
|
2971
|
+
};
|
|
2972
|
+
const handleMouseLeave = () => {
|
|
2973
|
+
if (!pauseOnHover)
|
|
2974
|
+
return;
|
|
2975
|
+
clearTimer();
|
|
2976
|
+
timerRef.current = setTimeout(swipeNext, interval);
|
|
2977
|
+
};
|
|
2978
|
+
useMouseMove(handleMouseMove);
|
|
2979
|
+
useMouseUp(handleMouseUp);
|
|
2980
|
+
useImperativeHandle(ref, () => ({
|
|
2981
|
+
swipeTo,
|
|
2982
|
+
swipeNext,
|
|
2983
|
+
swipePrev,
|
|
2984
|
+
}));
|
|
2985
|
+
useEffect(() => {
|
|
2986
|
+
if (!autoplay)
|
|
2987
|
+
return;
|
|
2988
|
+
timerRef.current = setTimeout(swipeNext, interval);
|
|
2989
|
+
return () => {
|
|
2990
|
+
clearTimeout(timerRef.current);
|
|
2991
|
+
timerRef.current = null;
|
|
2992
|
+
};
|
|
2993
|
+
}, [autoplay, interval]);
|
|
2994
|
+
return (jsxs("div", { style: style, className: classNames("i-swiper", {
|
|
2995
|
+
"i-swiper-vertical": vertical,
|
|
2996
|
+
"i-swiper-initialized": state.initialized,
|
|
2997
|
+
}, className), children: [jsxs("div", { className: 'i-swiper-track', style: trackStyle, onMouseOver: handleMouseOver, onMouseLeave: handleMouseLeave, children: [jsx("div", { ref: listRef, className: classNames("i-swiper-list", {
|
|
2998
|
+
"i-swiper-fade": type === "fade",
|
|
2999
|
+
}), style: {
|
|
3000
|
+
[vertical ? "height" : "width"]: listSize,
|
|
3001
|
+
transform: position,
|
|
3002
|
+
transition: state.transition,
|
|
3003
|
+
}, onMouseDown: handleMouseDown, children: displayItems.map((item, i) => {
|
|
3004
|
+
const { props: itemProps } = item;
|
|
3005
|
+
return (jsx(Item$1, { index: i, active: i - extra === state.current, type: type, gap: gap, transition: transition, itemHeight: itemHeight, vertical: vertical, ...itemProps }, i));
|
|
3006
|
+
}) }), arrow && (jsxs(Fragment, { children: [jsx("a", { className: 'i-swiper-arrow i-swiper-prev', onClick: swipePrev, children: prev }), jsx("a", { className: 'i-swiper-arrow i-swiper-next', onClick: swipeNext, children: next })] }))] }), indicator && (jsx("div", { className: 'i-swiper-indicators', children: indicatorsLoop.map((whatever, i) => {
|
|
3007
|
+
return (jsx("a", { className: classNames("i-swiper-indicator", {
|
|
3008
|
+
"i-indicator-active": i ===
|
|
3009
|
+
Math[loop ? "floor" : "ceil"](((state.current + size) % size) /
|
|
3010
|
+
scroll),
|
|
3011
|
+
}), onClick: () => swipeTo(i * scroll), children: renderIndicator?.(i) }, i));
|
|
3012
|
+
}) }))] }));
|
|
3013
|
+
});
|
|
3014
|
+
Swiper.Item = Item$1;
|
|
3015
|
+
|
|
3016
|
+
const Item = (props) => {
|
|
3017
|
+
return jsx(Fragment, {});
|
|
3018
|
+
};
|
|
3019
|
+
|
|
3020
|
+
const Tabs = forwardRef((props, ref) => {
|
|
3021
|
+
const { active, tabs: items, type = "default", prepend, append, children, className, vertical, toggable, bar = true, hideMore, barClass, renderMore = () => (jsx(Button, { flat: true, square: true, size: 'small', children: jsx(Icon, { icon: jsx(MoreHorizRound, {}) }) })), onTabChange, ...rest } = props;
|
|
3022
|
+
const navRefs = useRef([]);
|
|
3023
|
+
const barRef = useRef(null);
|
|
3024
|
+
const navsRef = useRef(null);
|
|
3025
|
+
const state = useReactive({
|
|
3026
|
+
active,
|
|
3027
|
+
prevActive: undefined,
|
|
3028
|
+
barStyle: {},
|
|
3029
|
+
cachedTabs: [],
|
|
3030
|
+
overflow: false,
|
|
3031
|
+
more: [],
|
|
3032
|
+
tabs: [],
|
|
3033
|
+
});
|
|
3034
|
+
const { observe, unobserve } = useIntersectionObserver();
|
|
3035
|
+
const size = useSize(navsRef);
|
|
3036
|
+
useEffect(() => {
|
|
3037
|
+
if (!items) {
|
|
3038
|
+
if (!children) {
|
|
3039
|
+
state.tabs = [];
|
|
3040
|
+
return;
|
|
3041
|
+
}
|
|
3042
|
+
state.tabs = Children.map(children, (node, i) => {
|
|
3043
|
+
const { key, props: nodeProps } = node;
|
|
3044
|
+
const { title, children, content, keepDOM } = nodeProps;
|
|
3045
|
+
const cloned = children
|
|
3046
|
+
? pick(children, ["props", "type", "$$typeof", "ref"])
|
|
3047
|
+
: content;
|
|
3048
|
+
return {
|
|
3049
|
+
key: key || String(i),
|
|
3050
|
+
title,
|
|
3051
|
+
content: cloned,
|
|
3052
|
+
keepDOM,
|
|
3053
|
+
};
|
|
3054
|
+
});
|
|
3055
|
+
return;
|
|
3056
|
+
}
|
|
3057
|
+
state.tabs = items.map((item, i) => {
|
|
3058
|
+
if (["string", "number"].includes(typeof item)) {
|
|
3059
|
+
return { key: item, title: item };
|
|
3060
|
+
}
|
|
3061
|
+
if (item.key === undefined) {
|
|
3062
|
+
item.key = i;
|
|
3063
|
+
}
|
|
3064
|
+
return item;
|
|
3065
|
+
});
|
|
3066
|
+
}, [children, items]);
|
|
3067
|
+
const add = (tab) => {
|
|
3068
|
+
const { key } = tab;
|
|
3069
|
+
const i = state.tabs.findIndex((t) => t.key === key);
|
|
3070
|
+
if (i > -1) {
|
|
3071
|
+
open(state.tabs[i].key ?? i);
|
|
3072
|
+
return;
|
|
3073
|
+
}
|
|
3074
|
+
const l = state.tabs.length;
|
|
3075
|
+
const tkey = tab.key ?? l;
|
|
3076
|
+
state.tabs.push({ ...tab, key: tkey });
|
|
3077
|
+
open(tkey);
|
|
3078
|
+
};
|
|
3079
|
+
const close = (key) => {
|
|
3080
|
+
const i = state.tabs.findIndex((t) => t.key === key);
|
|
3081
|
+
if (i < 0)
|
|
3082
|
+
return;
|
|
3083
|
+
state.tabs.splice(i, 1);
|
|
3084
|
+
if (state.active !== key)
|
|
3085
|
+
return;
|
|
3086
|
+
const next = state.tabs[i] || state.tabs[i - 1];
|
|
3087
|
+
open(state.prevActive ?? next?.key ?? "");
|
|
3088
|
+
};
|
|
3089
|
+
const open = (key) => {
|
|
3090
|
+
if (key === state.active) {
|
|
3091
|
+
if (!toggable)
|
|
3092
|
+
return;
|
|
3093
|
+
onTabChange?.(undefined, key);
|
|
3094
|
+
state.active = undefined;
|
|
3095
|
+
state.barStyle = {
|
|
3096
|
+
height: 0,
|
|
3097
|
+
width: 0,
|
|
3098
|
+
};
|
|
3099
|
+
return;
|
|
3100
|
+
}
|
|
3101
|
+
state.prevActive = state.active;
|
|
3102
|
+
onTabChange?.(key, state.active);
|
|
3103
|
+
state.active = key;
|
|
3104
|
+
};
|
|
3105
|
+
const handleMouseWheel = (e) => {
|
|
3106
|
+
e.stopPropagation();
|
|
3107
|
+
e.preventDefault();
|
|
3108
|
+
if (vertical)
|
|
3109
|
+
return;
|
|
3110
|
+
navsRef.current?.scrollBy({
|
|
3111
|
+
left: e.deltaY + e.deltaX,
|
|
3112
|
+
});
|
|
3113
|
+
};
|
|
3114
|
+
useEffect(() => {
|
|
3115
|
+
if (!size || hideMore)
|
|
3116
|
+
return;
|
|
3117
|
+
const { scrollHeight, scrollWidth } = navsRef.current;
|
|
3118
|
+
const { width, height } = size;
|
|
3119
|
+
state.overflow = scrollHeight > height || scrollWidth > width;
|
|
3120
|
+
if (!state.overflow)
|
|
3121
|
+
return;
|
|
3122
|
+
navRefs.current.map((nav, i) => {
|
|
3123
|
+
if (!nav)
|
|
3124
|
+
return;
|
|
3125
|
+
observe(nav, (tar, visible) => {
|
|
3126
|
+
if (!state.tabs[i])
|
|
3127
|
+
return;
|
|
3128
|
+
state.tabs[i].intersecting = visible;
|
|
3129
|
+
state.more = state.tabs.filter((tab) => !tab.intersecting);
|
|
3130
|
+
});
|
|
3131
|
+
});
|
|
3132
|
+
}, [size, hideMore, state.tabs.length]);
|
|
3133
|
+
useEffect(() => {
|
|
3134
|
+
if (!bar || type === "pane" || state.active === undefined) {
|
|
3135
|
+
return;
|
|
3136
|
+
}
|
|
3137
|
+
const index = state.tabs.findIndex((tab) => tab.key === state.active);
|
|
3138
|
+
setTimeout(() => {
|
|
3139
|
+
const nav = navRefs.current[index];
|
|
3140
|
+
if (!nav)
|
|
3141
|
+
return;
|
|
3142
|
+
if (state.tabs[index].keepDOM && state.active) {
|
|
3143
|
+
const i = state.cachedTabs.findIndex((k) => k === state.active);
|
|
3144
|
+
i < 0 && state.cachedTabs.unshift(state.active);
|
|
3145
|
+
}
|
|
3146
|
+
const { offsetHeight, offsetLeft, offsetTop, offsetWidth } = nav;
|
|
3147
|
+
const isLine = type === "line";
|
|
3148
|
+
state.barStyle = {
|
|
3149
|
+
height: !vertical && isLine ? ".25em" : offsetHeight,
|
|
3150
|
+
width: vertical && isLine ? ".25em" : offsetWidth,
|
|
3151
|
+
transform: `translate(${offsetLeft}px, ${offsetTop}px)`,
|
|
3152
|
+
};
|
|
3153
|
+
}, 16);
|
|
3154
|
+
}, [state.active, bar]);
|
|
3155
|
+
useEffect(() => {
|
|
3156
|
+
if (active === undefined || state.active === active)
|
|
3157
|
+
return;
|
|
3158
|
+
open(active);
|
|
3159
|
+
}, [active]);
|
|
3160
|
+
useEffect(() => {
|
|
3161
|
+
if (hideMore)
|
|
3162
|
+
return;
|
|
3163
|
+
return () => {
|
|
3164
|
+
navRefs.current?.map(unobserve);
|
|
3165
|
+
};
|
|
3166
|
+
}, [state.tabs.length]);
|
|
3167
|
+
useEffect(() => {
|
|
3168
|
+
if (!navsRef.current || vertical)
|
|
3169
|
+
return;
|
|
3170
|
+
navsRef.current.addEventListener("wheel", handleMouseWheel, {
|
|
3171
|
+
passive: false,
|
|
3172
|
+
});
|
|
3173
|
+
return () => {
|
|
3174
|
+
if (!navsRef.current)
|
|
3175
|
+
return;
|
|
3176
|
+
navsRef.current.removeEventListener("wheel", handleMouseWheel);
|
|
3177
|
+
};
|
|
3178
|
+
}, [navsRef.current]);
|
|
3179
|
+
useImperativeHandle(ref, () => ({
|
|
3180
|
+
open,
|
|
3181
|
+
close,
|
|
3182
|
+
add,
|
|
3183
|
+
navs: navsRef,
|
|
3184
|
+
}));
|
|
3185
|
+
return (jsxs("div", { className: classNames("i-tabs", { flex: vertical, [`i-tabs-${type}`]: type !== "default" }, className), ...rest, children: [jsxs("div", { className: classNames("i-tab-navs-container", {
|
|
3186
|
+
"i-tab-navs-vertical": vertical,
|
|
3187
|
+
}), children: [prepend, jsxs("div", { ref: navsRef, className: 'i-tab-navs', children: [state.tabs.map((tab, i) => {
|
|
3188
|
+
const { title, key = i, closable } = tab;
|
|
3189
|
+
return (jsxs("a", { ref: (ref) => (navRefs.current[i] =
|
|
3190
|
+
ref), className: classNames("i-tab-nav", {
|
|
3191
|
+
"i-tab-active": state.active === key,
|
|
3192
|
+
}), onClick: () => open(key), children: [title, closable && (jsx(Helpericon, { as: 'i', active: true, className: 'i-tab-nav-close', onClick: (e) => {
|
|
3193
|
+
e.stopPropagation();
|
|
3194
|
+
close(key);
|
|
3195
|
+
} }))] }, key));
|
|
3196
|
+
}), bar && (jsx("span", { ref: barRef, className: classNames("i-tab-navs-bar", barClass), style: state.barStyle }))] }), !hideMore && state.overflow && state.more.length > 0 && (jsx(Popup, { arrow: false, position: vertical ? "right" : "bottom", align: 'end', touchable: true, hideDelay: 500, content: jsx("div", { className: 'i-tabs-morelist pd-4', children: state.more.map((tab, i) => {
|
|
3197
|
+
const { key = i, title } = tab;
|
|
3198
|
+
const isActive = state.active === key;
|
|
3199
|
+
return (jsx("a", { className: classNames("i-tab-nav", {
|
|
3200
|
+
"i-tab-active": isActive,
|
|
3201
|
+
}), onClick: () => open(key), children: title }, key));
|
|
3202
|
+
}) }), children: renderMore(state.more) })), append] }), jsx("div", { className: 'i-tab-contents', children: state.tabs.map((tab, i) => {
|
|
3203
|
+
const { key = i, content } = tab;
|
|
3204
|
+
const isActive = state.active === key;
|
|
3205
|
+
const show = isActive ||
|
|
3206
|
+
(key !== undefined && state.cachedTabs.includes(key));
|
|
3207
|
+
return (show && (jsx("div", { className: classNames("i-tab-content", {
|
|
3208
|
+
"i-tab-active": isActive,
|
|
3209
|
+
}), children: content }, key)));
|
|
3210
|
+
}) })] }));
|
|
3211
|
+
});
|
|
3212
|
+
Tabs.Item = Item;
|
|
3213
|
+
|
|
3214
|
+
function TreeList(props) {
|
|
3215
|
+
const { data = [], depth = 0, round, style, className, parent, nodeProps, ...restProps } = props;
|
|
3216
|
+
const contents = data.map((item, i) => {
|
|
3217
|
+
const { type } = item;
|
|
3218
|
+
const title = item[nodeProps.title];
|
|
3219
|
+
const itemKey = item[nodeProps.key] ||
|
|
3220
|
+
(parent?.key !== undefined ? `${parent.key}-${i}` : `${i}`);
|
|
3221
|
+
item.key = itemKey;
|
|
3222
|
+
item.parent = parent;
|
|
3223
|
+
if (type === "title") {
|
|
3224
|
+
return (jsx("div", { className: 'i-tree-group-title', children: title }, i));
|
|
3225
|
+
}
|
|
3226
|
+
if (type && type !== "item") {
|
|
3227
|
+
return (jsx("div", { className: `i-tree-type-${type}`, children: title }, i));
|
|
3228
|
+
}
|
|
3229
|
+
return (jsx(TreeItem, { index: i, item: item, depth: depth, nodeProps: nodeProps, ...restProps }, itemKey));
|
|
3230
|
+
});
|
|
3231
|
+
if (depth > 0)
|
|
3232
|
+
return jsx(Fragment, { children: contents });
|
|
3233
|
+
return (jsx("div", { className: classNames("i-tree", className, {
|
|
3234
|
+
"i-tree-round": round,
|
|
3235
|
+
}), style: style, children: contents }));
|
|
3236
|
+
}
|
|
3237
|
+
const Header = (props) => {
|
|
3238
|
+
const { as: Tag = "a", href, selected, children, ...restProps } = props;
|
|
3239
|
+
const className = classNames("i-tree-item-header", {
|
|
3240
|
+
"i-tree-item-selected": selected,
|
|
3241
|
+
});
|
|
3242
|
+
if (typeof Tag === "string") {
|
|
3243
|
+
return (jsx(Tag, { href: href, className: className, ...restProps, children: children }));
|
|
3244
|
+
}
|
|
3245
|
+
return (jsx(Tag, { to: href || "", className: className, ...restProps, children: children }));
|
|
3246
|
+
};
|
|
3247
|
+
const TreeItem = (props) => {
|
|
3248
|
+
const { item, depth = 0, index, selected, checked = [], partofs = {}, checkable, nodeProps, renderExtra, onItemClick, onItemSelect, onItemCheck, ...restProps } = props;
|
|
3249
|
+
const { as, key = "", href, icon, title, expanded, disabled } = item;
|
|
3250
|
+
const children = item[nodeProps.children];
|
|
3251
|
+
const [expand, setExpand] = useState(expanded);
|
|
3252
|
+
const handleExpand = useMemoizedFn((e, fromToggle) => {
|
|
3253
|
+
if (fromToggle) {
|
|
3254
|
+
e.preventDefault();
|
|
3255
|
+
e.stopPropagation();
|
|
3256
|
+
}
|
|
3257
|
+
if (disabled || !children?.length)
|
|
3258
|
+
return;
|
|
3259
|
+
setExpand((v) => !v);
|
|
3260
|
+
});
|
|
3261
|
+
const handleItemClick = useMemoizedFn((e) => {
|
|
3262
|
+
if (disabled) {
|
|
3263
|
+
e.preventDefault();
|
|
3264
|
+
e.stopPropagation();
|
|
3265
|
+
return;
|
|
3266
|
+
}
|
|
3267
|
+
handleExpand(e);
|
|
3268
|
+
onItemClick?.(item, e);
|
|
3269
|
+
onItemSelect?.(key, item);
|
|
3270
|
+
});
|
|
3271
|
+
const handleItemCheck = (checked) => onItemCheck?.(item, checked, []);
|
|
3272
|
+
const itemChecked = checked.includes(key);
|
|
3273
|
+
return (jsxs("div", { className: classNames("i-tree-item", {
|
|
3274
|
+
"i-tree-expand": expand,
|
|
3275
|
+
}), children: [jsxs(Header, { as: as, href: href, style: { paddingLeft: `${depth * 1.5 + 0.5}em` }, selected: selected === key, onClick: handleItemClick, children: [checkable && (jsx(Checkbox.Item, { value: itemChecked, partof: !itemChecked && partofs[key], className: 'i-tree-checkbox', onChange: handleItemCheck, onClick: (e) => e.stopPropagation() })), icon && jsx("span", { className: 'i-tree-item-icon', children: icon }), jsx("span", { className: 'i-tree-item-title', children: title }), renderExtra?.(item), children && (jsx(Icon, { icon: jsx(KeyboardArrowDownRound, {}), className: 'i-tree-toggle', onClick: (e) => handleExpand(e, true) }))] }), children?.length && (jsx("div", { className: 'i-tree-item-content', children: jsx(TreeList, { data: children, depth: depth + 1, selected: selected, checkable: checkable, parent: item, partofs: partofs, checked: checked, nodeProps: nodeProps, renderExtra: renderExtra, onItemClick: onItemClick, onItemSelect: onItemSelect, onItemCheck: onItemCheck, ...restProps }) }))] }));
|
|
3276
|
+
};
|
|
3277
|
+
|
|
3278
|
+
const defaultNodeProps = {
|
|
3279
|
+
key: "key",
|
|
3280
|
+
title: "title",
|
|
3281
|
+
children: "children",
|
|
3282
|
+
};
|
|
3283
|
+
const Tree = forwardRef((props, ref) => {
|
|
3284
|
+
const { data = [], selected, checked = [], disabledRelated, nodeProps, onItemSelect, onItemCheck, ...restProps } = props;
|
|
3285
|
+
const state = useReactive({
|
|
3286
|
+
selected,
|
|
3287
|
+
checked,
|
|
3288
|
+
partofs: {},
|
|
3289
|
+
nodeMaps: new Map(),
|
|
3290
|
+
});
|
|
3291
|
+
const oNodeProps = Object.assign({}, defaultNodeProps, nodeProps);
|
|
3292
|
+
const isChecked = (key) => state.checked.includes(key || "");
|
|
3293
|
+
const checkItem = useMemoizedFn((item, checked, direction) => {
|
|
3294
|
+
const { key = "", parent, children } = item;
|
|
3295
|
+
const shouldChanged = { [key]: checked };
|
|
3296
|
+
const partofs = { [key]: false };
|
|
3297
|
+
if (disabledRelated)
|
|
3298
|
+
return [shouldChanged];
|
|
3299
|
+
if (checked) {
|
|
3300
|
+
if (parent && direction !== "leaf") {
|
|
3301
|
+
const hasUnchecked = parent.children?.some((o) => o.key !== key && !isChecked(o.key));
|
|
3302
|
+
const [changes, parts] = checkItem(parent, true, "root");
|
|
3303
|
+
if (!hasUnchecked) {
|
|
3304
|
+
Object.assign(shouldChanged, changes);
|
|
3305
|
+
}
|
|
3306
|
+
Object.assign(partofs, hasUnchecked ? parts : {}, {
|
|
3307
|
+
[parent.key]: true,
|
|
3308
|
+
});
|
|
3309
|
+
}
|
|
3310
|
+
if (children?.length && direction !== "root") {
|
|
3311
|
+
children.map((o) => {
|
|
3312
|
+
if (isChecked(o.key))
|
|
3313
|
+
return;
|
|
3314
|
+
const [changes] = checkItem(o, true, "leaf");
|
|
3315
|
+
Object.assign(shouldChanged, changes);
|
|
3316
|
+
partofs[o.key] = false;
|
|
3317
|
+
});
|
|
3318
|
+
}
|
|
3319
|
+
return [shouldChanged, partofs];
|
|
3320
|
+
}
|
|
3321
|
+
if (parent && direction !== "leaf") {
|
|
3322
|
+
const [changes, parts] = checkItem(parent, false, "root");
|
|
3323
|
+
Object.assign(shouldChanged, changes);
|
|
3324
|
+
const hasChecked = parent.children?.some((o) => isChecked(o.key) && o.key !== key);
|
|
3325
|
+
Object.assign(partofs, hasChecked ? {} : parts, {
|
|
3326
|
+
[parent.key]: hasChecked,
|
|
3327
|
+
[key]: false,
|
|
3328
|
+
});
|
|
3329
|
+
}
|
|
3330
|
+
if (children?.length && direction !== "root") {
|
|
3331
|
+
children.map((o) => {
|
|
3332
|
+
const [changes] = checkItem(o, false, "leaf");
|
|
3333
|
+
if (!isChecked(o.key))
|
|
3334
|
+
return;
|
|
3335
|
+
Object.assign(shouldChanged, changes);
|
|
3336
|
+
partofs[o.key] = false;
|
|
3337
|
+
});
|
|
3338
|
+
}
|
|
3339
|
+
return [shouldChanged, partofs];
|
|
3340
|
+
});
|
|
3341
|
+
const handleCheck = (item, checked) => {
|
|
3342
|
+
const [shouldChanged, partofs] = checkItem(item, checked);
|
|
3343
|
+
const changedKeys = Object.keys(shouldChanged);
|
|
3344
|
+
state.checked = checked
|
|
3345
|
+
? Array.from(new Set([...state.checked, ...changedKeys]))
|
|
3346
|
+
: state.checked.filter((k) => !changedKeys.includes(k));
|
|
3347
|
+
Object.assign(state.partofs, partofs);
|
|
3348
|
+
onItemCheck?.(item, checked, state.checked);
|
|
3349
|
+
};
|
|
3350
|
+
const handleSelect = (key, item) => {
|
|
3351
|
+
if (!props.selectable)
|
|
3352
|
+
return;
|
|
3353
|
+
state.selected = key;
|
|
3354
|
+
onItemSelect?.(key, item);
|
|
3355
|
+
};
|
|
3356
|
+
useEffect(() => {
|
|
3357
|
+
if (selected === undefined)
|
|
3358
|
+
return;
|
|
3359
|
+
state.selected = selected;
|
|
3360
|
+
}, [selected]);
|
|
3361
|
+
useEffect(() => {
|
|
3362
|
+
state.nodeMaps.clear();
|
|
3363
|
+
const { key, children } = oNodeProps;
|
|
3364
|
+
const recursive = (nodes) => {
|
|
3365
|
+
nodes.map((o) => {
|
|
3366
|
+
state.nodeMaps.set(o[key], o);
|
|
3367
|
+
o[children]?.length > 0 && recursive(o[children]);
|
|
3368
|
+
});
|
|
3369
|
+
};
|
|
3370
|
+
recursive(data);
|
|
3371
|
+
}, [data]);
|
|
3372
|
+
useImperativeHandle(ref, () => {
|
|
3373
|
+
return {
|
|
3374
|
+
getChecked: () => {
|
|
3375
|
+
const items = [];
|
|
3376
|
+
state.checked.map((k) => {
|
|
3377
|
+
const item = state.nodeMaps.get(k);
|
|
3378
|
+
items.push(item);
|
|
3379
|
+
});
|
|
3380
|
+
return [state.checked, items];
|
|
3381
|
+
},
|
|
3382
|
+
getSelected: () => {
|
|
3383
|
+
const item = state.nodeMaps.get(state.selected);
|
|
3384
|
+
return [state.selected, item];
|
|
3385
|
+
},
|
|
3386
|
+
getPartofs: () => {
|
|
3387
|
+
const items = [];
|
|
3388
|
+
const keys = Object.keys(state.partofs).filter((k) => {
|
|
3389
|
+
const indeterminate = state.partofs[k];
|
|
3390
|
+
if (indeterminate) {
|
|
3391
|
+
const item = state.nodeMaps.get(k);
|
|
3392
|
+
items.push(item);
|
|
3393
|
+
}
|
|
3394
|
+
return indeterminate;
|
|
3395
|
+
});
|
|
3396
|
+
return [keys, items];
|
|
3397
|
+
},
|
|
3398
|
+
};
|
|
3399
|
+
});
|
|
3400
|
+
return (jsx(TreeList, { data: data, selected: state.selected, checked: state.checked, partofs: state.partofs, nodeProps: oNodeProps, onItemCheck: handleCheck, onItemSelect: handleSelect, ...restProps }));
|
|
3401
|
+
});
|
|
3402
|
+
|
|
3403
|
+
function RenderFile(props) {
|
|
3404
|
+
const { mode, index, file, onRemove, onPreview } = props;
|
|
3405
|
+
if (!file)
|
|
3406
|
+
return "";
|
|
3407
|
+
const { name, size, url, src } = file;
|
|
3408
|
+
const type = getFileType(name, file.type);
|
|
3409
|
+
const CloseBtn = (jsx(Helpericon, { active: true, className: 'i-upload-delete', onClick: (e) => {
|
|
3410
|
+
e.stopPropagation();
|
|
3411
|
+
e.preventDefault();
|
|
3412
|
+
onRemove(index);
|
|
3413
|
+
} }));
|
|
3414
|
+
switch (mode) {
|
|
3415
|
+
case "card":
|
|
3416
|
+
let node = jsx(Fragment, {});
|
|
3417
|
+
switch (type) {
|
|
3418
|
+
case TFileType.IMAGE:
|
|
3419
|
+
node = (jsx(Image, { lazyload: true, src: url || src, fit: 'cover', usePreview: false }));
|
|
3420
|
+
break;
|
|
3421
|
+
case TFileType.VIDEO:
|
|
3422
|
+
node = jsx("video", { src: url || src, preload: 'none' });
|
|
3423
|
+
break;
|
|
3424
|
+
default:
|
|
3425
|
+
node = (jsxs(Fragment, { children: [jsx(Icon, { icon: jsx(ListAltRound, {}) }), jsx("span", { className: 'i-upload-file-name', children: title(name) })] }));
|
|
3426
|
+
break;
|
|
3427
|
+
}
|
|
3428
|
+
return (jsxs("div", { title: name, className: 'i-upload-item-card', onClick: () => onPreview?.(index), children: [node, CloseBtn] }));
|
|
3429
|
+
default:
|
|
3430
|
+
return (jsxs("div", { className: 'i-upload-item', onClick: () => onPreview?.(index), children: [jsx("span", { children: name }), jsx("i", { className: 'i-upload-size', children: formatBytes(size ?? 0) }), CloseBtn] }));
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
3433
|
+
|
|
3434
|
+
const Upload = forwardRef((props, ref) => {
|
|
3435
|
+
const { label, labelInline, value, files = [], placeholder, status = "normal", message, className, style, children, mode = "default", cardSize = "4em", disabled, limit = props.multiple ? Infinity : 1, multiple, renderItem = RenderFile, shouldUpload = () => true, uploader, onChange, onFilesChange, onUpload, ...restProps } = props;
|
|
3436
|
+
const state = useReactive({
|
|
3437
|
+
files,
|
|
3438
|
+
value,
|
|
3439
|
+
status,
|
|
3440
|
+
message,
|
|
3441
|
+
update: 0,
|
|
3442
|
+
});
|
|
3443
|
+
const inputRef = useRef(null);
|
|
3444
|
+
const preview = usePreview();
|
|
3445
|
+
const trigger = useMemo(() => {
|
|
3446
|
+
if (children)
|
|
3447
|
+
return children;
|
|
3448
|
+
switch (mode) {
|
|
3449
|
+
case "card":
|
|
3450
|
+
return (jsx(Button, { className: 'i-upload-card-btn color-5', square: true, flat: true, outline: true, disabled: disabled, children: jsx(Icon, { icon: jsx(PlusSharp, {}) }) }));
|
|
3451
|
+
default:
|
|
3452
|
+
return (jsxs(Button, { className: 'i-upload-btn', disabled: disabled, children: [jsx(Icon, { icon: jsx(CloudUploadTwotone, {}) }), " Upload"] }));
|
|
3453
|
+
}
|
|
3454
|
+
}, [mode, children]);
|
|
3455
|
+
const handleChange = (e) => {
|
|
3456
|
+
const files = Array.from(e.target.files || []);
|
|
3457
|
+
const { files: before } = state;
|
|
3458
|
+
const changed = [];
|
|
3459
|
+
files.map((f) => {
|
|
3460
|
+
const { name, size, type } = f;
|
|
3461
|
+
const same = before.find((pf) => {
|
|
3462
|
+
const { name: n, size: s, type: t } = pf;
|
|
3463
|
+
return n === name && s === size && t === type;
|
|
3464
|
+
});
|
|
3465
|
+
const src = URL.createObjectURL(f);
|
|
3466
|
+
f.src = src;
|
|
3467
|
+
state.update += 1;
|
|
3468
|
+
Object.assign(f, {
|
|
3469
|
+
uid: uid(7),
|
|
3470
|
+
src: f.src || f.name,
|
|
3471
|
+
});
|
|
3472
|
+
!same && changed.push(f);
|
|
3473
|
+
});
|
|
3474
|
+
const after = [...before, ...changed];
|
|
3475
|
+
Object.assign(state, {
|
|
3476
|
+
files: multiple ? after.slice(0, limit) : [after.at(-1)],
|
|
3477
|
+
status,
|
|
3478
|
+
message,
|
|
3479
|
+
});
|
|
3480
|
+
onFilesChange?.(state.files, changed, e);
|
|
3481
|
+
onChange?.(state.files, e);
|
|
3482
|
+
handleUpload(changed);
|
|
3483
|
+
inputRef.current && (inputRef.current.value = "");
|
|
3484
|
+
};
|
|
3485
|
+
const handleRemove = (i) => {
|
|
3486
|
+
const [...files] = state.files;
|
|
3487
|
+
const changed = files.splice(i, 1);
|
|
3488
|
+
URL.revokeObjectURL(changed[0]?.src || "");
|
|
3489
|
+
state.files = files;
|
|
3490
|
+
onFilesChange?.(files, changed);
|
|
3491
|
+
onChange?.(files);
|
|
3492
|
+
inputRef.current && (inputRef.current.value = "");
|
|
3493
|
+
};
|
|
3494
|
+
const handleUpload = async (files) => {
|
|
3495
|
+
if (!uploader)
|
|
3496
|
+
return;
|
|
3497
|
+
files.forEach(async (file) => {
|
|
3498
|
+
if (!shouldUpload(file))
|
|
3499
|
+
return;
|
|
3500
|
+
const result = await uploader(file);
|
|
3501
|
+
const i = state.files.findIndex((f) => f.uid === result.uid);
|
|
3502
|
+
i > -1 && (state.files[i] = result);
|
|
3503
|
+
result?.status === "completed" && onUpload?.(result);
|
|
3504
|
+
});
|
|
3505
|
+
};
|
|
3506
|
+
const handlePreview = (i) => {
|
|
3507
|
+
preview({ items: state.files, initial: i });
|
|
3508
|
+
};
|
|
3509
|
+
useEffect(() => {
|
|
3510
|
+
Object.assign(state, {
|
|
3511
|
+
status,
|
|
3512
|
+
message,
|
|
3513
|
+
});
|
|
3514
|
+
}, [status, message]);
|
|
3515
|
+
useEffect(() => {
|
|
3516
|
+
state.value = value;
|
|
3517
|
+
}, [value]);
|
|
3518
|
+
useImperativeHandle(ref, () => ({
|
|
3519
|
+
getFileList: () => state.files,
|
|
3520
|
+
}), []);
|
|
3521
|
+
const { message: msg, files: currentFiles } = state;
|
|
3522
|
+
return (jsxs(InputContainer, { label: label, labelInline: labelInline, className: classNames("i-input-label-file", className), style: style, children: [jsx("input", { ...restProps, disabled: disabled, ref: inputRef, type: 'file', className: 'i-input-file-hidden', multiple: multiple, onChange: handleChange }), jsxs("div", { className: classNames("i-upload-inner", {
|
|
3523
|
+
[`i-upload-${mode}`]: mode !== "default",
|
|
3524
|
+
}), style: { ["--upload-card-size"]: cardSize }, children: [jsx("div", { className: 'i-upload-list', onClick: (e) => {
|
|
3525
|
+
e.stopPropagation();
|
|
3526
|
+
e.preventDefault();
|
|
3527
|
+
}, children: currentFiles?.map((file, i) => (jsx(Fragment$1, { children: RenderFile({
|
|
3528
|
+
index: i,
|
|
3529
|
+
file,
|
|
3530
|
+
mode,
|
|
3531
|
+
onRemove: handleRemove,
|
|
3532
|
+
onPreview: handlePreview,
|
|
3533
|
+
}) }, i))) }), msg && jsx("span", { className: 'i-upload-message', children: msg }), currentFiles.length < limit && trigger] })] }));
|
|
3534
|
+
});
|
|
3535
|
+
|
|
3536
|
+
export { Affix, Badge, Button, Card, Checkbox, Collapse, Datagrid, Datepicker, Description, Drawer, Dropdown, Flex, Form, Icon, Image, Input, List$1 as List, Loading, message as Message, Modal, Pagination, Popconfirm, Popup, Progress, Radio, Select, Step, Swiper, Tabs, Tag, Text, Tree, Upload, Video, usePreview };
|
|
2
3537
|
//# sourceMappingURL=index.js.map
|