amotify 0.3.7 → 0.3.8
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as n,c as y,d as z,e as be}from"../../chunk-C5N2D3ZX.js";import{Fragment as Pe,jsx as l,jsxs as j}from"react/jsx-runtime";import p,{useStore as ae,UUID as ce}from"jmini";import me,{useState as xe,useEffect as ie}from"react";import{ExtractStyles as W,GenerateHTMLProps as Te,dragEffect as ge,useRemote as ne}from"../../@utils";import{faArrowUp as De}from"@fortawesome/free-solid-svg-icons/faArrowUp";import{faUpDown as we}from"@fortawesome/free-solid-svg-icons/faUpDown";import{Box as w,Flex as ke,FAI as v,Span as Ke}from"../../atoms";import{Literal as ye,Row as O,MarkerPen as he}from"../../mols";import{Button as de}from"../Button";import P from"../Input";import{TableClasses as Me}from"../../@styles/componentClasses";import{faGripVertical as Se}from"@fortawesome/free-solid-svg-icons/faGripVertical";import{Tips as Ce}from"../Tips";const f={reservedKeys:["row_id","onCheckerDisabled","onDraggerDisabled","columnIdx","isSelected","isFilterMatched","isVisible","draggerIndex","onRowClick"],toSafetyHeader:t=>{let e=!!t.some(o=>o.draggable);return(t==null?void 0:t.map((o,i)=>{var a;return p.isRecord(o)||(o={key:o}),p.isString(o.key)&&(o.key=o.key.replace(/[.\s]/g,"_")),e&&(o.sortable=0,o.filterable=!1),o.columnIdx=(a=o.columnIdx)!=null?a:i,o}).toASC("columnIdx"))||[]},toSafetyBody:t=>t==null?void 0:t.map((e,r)=>{var i;let o={};return Object.entries(e).forEach(([a,c])=>{var h,s;if(p.isOneOf(a,...f.reservedKeys))return;let d=c;p.isNullish(d)||(p.isRecord(d)||(d={data:d}),p.isString(a)&&(a=a.replace(/[.\s]/g,"_")),d.sortKey=(s=(h=d.sortKey)!=null?h:String(d.data))!=null?s:"",o[a]=d)}),o=y(n({},o),{row_id:(i=e.row_id)!=null?i:r,onRowClick:e.onRowClick,isSelected:!!e.isSelected,isFilterMatched:!0,isVisible:!0,onCheckerDisabled:e.onCheckerDisabled,onDraggerDisabled:e.onDraggerDisabled,draggerIndex:r}),o}),toSafetyData:t=>{var o,i;let{header:e=[]}=t,r={datagridID:t.datagridID||ce(),sessionID:ce(),body:f.toSafetyBody(t.body||[]),filter:{keyword:t.defaultSearchKey||"",current:[]},sort:{col:-1,dir:1},paging:{rows:t.maxRows||100,total:1,current:1},draggable:!!e.some(a=>a.draggable)};{let a=e==null?void 0:e.findIndex(c=>c.defSort);a!==-1&&(r.sort.col=a,r.sort.dir=(i=(o=e[a])==null?void 0:o.sortable)!=null?i:1)}return r.draggable&&(r.filter.keyword="",r.sort.col=-1,r.sort.dir=0),f.updateRowMeta(r,t)},updateRowMeta:(t,e)=>{let r=n({},t);if(r.sort.col>=0&&r.sort.dir){let o=e.header[r.sort.col].key;r.sort.dir==1?r.body.toASC(o+".sortKey"):r.body.toDESC(o+".sortKey")}{let o=String(r.filter.keyword)||"";r.body.forEach(i=>{if(i.isFilterMatched=!0,!o)return;let a=e.header.some(c=>{var s;let d=i[c.key];return!d||!d.sortKey?!1:!!((s=String(d.sortKey||d.data))!=null&&s.match(new RegExp(o.escapeRegExChar(),"i")))});i.isFilterMatched=a})}{let o=r.paging.rows;r.paging.total=Math.ceil(r.body.filter(d=>d.isFilterMatched).length/o);let i=o*(r.paging.current-1),a=i+o,c=0;r.body.forEach(d=>{d.isVisible=!1,d.isFilterMatched&&(d.isVisible=c>=i&&c<a,c++)})}return r.draggable&&r.body.toASC("draggerIndex"),r},index:t=>{var s,S,F,G;let[e,r]=xe(()=>f.toSafetyData(t));ie(()=>{ae.set({["reset-"+e.datagridID]:()=>{r(f.toSafetyData(t))},["refresh-"+e.datagridID]:()=>{r(g=>f.updateRowMeta(y(n({},g),{body:f.toSafetyBody(t.body)}),t))}})},[t]),ie(()=>{ae.set({["rows-"+e.datagridID]:e.body}),ne.bridge(e.datagridID,{val_config:e,remoteUpdate:{paging:g=>{r(u=>f.updateRowMeta(y(n({},u),{paging:y(n({},u.paging),{current:Math.max(1,Math.min(u.paging.total,g))})}),t))},maxRow:g=>{r(u=>f.updateRowMeta(y(n({},u),{paging:y(n({},u.paging),{rows:g,current:1})}),t))},searchKey:g=>{e.draggable||p.interval.once(()=>{r(u=>{let C=y(n({},u),{paging:y(n({},u.paging),{current:1}),filter:y(n({},u.filter),{keyword:String(g||"").trim()})});return f.updateRowMeta(C,t)})},300,"InputSearchTime")}}})},[e]);const o=me.useRef(!1);ie(()=>{if(t.onSelected){if(!o.current){o.current=!0;return}t.onSelected(e.body.filter(g=>g.isSelected))}},[(s=e==null?void 0:e.body)==null?void 0:s.filter(g=>g.isSelected).length]);const i=me.useRef(!1);ie(()=>{if(t.onSorted){if(!i.current){i.current=!0;return}t.onSorted(e.sort.col,e.sort.dir)}},[(S=e==null?void 0:e.sort)==null?void 0:S.col,(F=e==null?void 0:e.sort)==null?void 0:F.dir]);let a={input:t,val_config:e,set_config:r},{className:c,style:d}=Te(t),h=(G=t.colLength)!=null?G:t.header.length;return l(w,{className:c,style:d,children:l(T.Table,{className:Me("DataGrid"),borderRadius:"inherit",children:j(T.Body,{children:[l(f.Header,n({},a)),l(f.Body,n({},a)),l(f.Footer,n({},a))]})},[h,...t.header.map(g=>g.key),e.sessionID].join("."))})},Checker:t=>l(w,{flexCenter:!0,onClick:e=>{e.stopPropagation()},children:l(P.Checker,y(n({wrapStyles:{display:"inlineBlock"},cellStyles:{gap:0}},t),{label:!1}))}),Header:t=>{var h;let{input:e,val_config:r,set_config:o}=t;if(e.headerless)return null;let i="datagrid-dragger-"+r.datagridID,a=["datagrid",r.datagridID,""].join("-"),c=1+r.body.filter(s=>s.isVisible).length+ +!!e.footer,d=(h=e.colLength)!=null?h:e.header.length;return l(ge.DropArea,y(n({jsxElement:T.Row,id:a},e.rowStyles),{dragInfo:{type:i,id:a,idx:0,marker:"bottom"},children:e.header.toASC("columnIdx").map((s,S)=>{var Y,Z,ee,te,re,oe;let[F,G]=W(s),X=G,{isTH:g,key:u,label:C,onLabelRender:m,columnIdx:I,checkable:L,draggable:N,defSort:q,sortable:E,filterable:$,isHidden:J}=X,k=z(X,["isTH","key","label","onLabelRender","columnIdx","checkable","draggable","defSort","sortable","filterable","isHidden"]);if(J)return null;let R={rowIdx:0,colIdx:S,topIdx:0,leftIdx:S,rightIdx:d-S-1,bottomIdx:c-1,isHeader:!0,isBody:!1,isFooter:!1},H=N,A=E!=0,x=S==r.sort.col,_=p.deepMerge(p.deepCopy(e.cellStyles),pe(R,{}),(Y=e.cellStyles)==null?void 0:Y.onHeader,!R.leftIdx&&((Z=e.cellStyles)==null?void 0:Z.onLeft),!R.rightIdx&&((ee=e.cellStyles)==null?void 0:ee.onRight),!R.topIdx&&((te=e.cellStyles)==null?void 0:te.onTop),!R.bottomIdx&&((re=e.cellStyles)==null?void 0:re.onBottom),F);e.onCellStyles&&(_=e.onCellStyles(R,_||{}));let B=[],Q=[];if(H&&B.push(l(de.Clear.S,{ssSphere:2,fontColor:"theme",onMouseOver:b=>{Ce.open(b.currentTarget,j(ye.Mini,{children:[l(v,{icon:Se}),"\u30C9\u30E9\u30C3\u30B0\u3067\u5217\u306E\u9806\u756A\u3092\u5909\u66F4"]}),22)},onMouseLeave:b=>Ce.abort(),onClick:b=>{b.stopPropagation()},children:l(v.QuestionCircle,{})},"drag")),L){let b=l(f.Checker,{value:r.body.every(D=>D.isSelected),onUpdateValue:D=>{o(K=>{let M=n({},K);return M.body.forEach(V=>{V.isFilterMatched&&(V.isSelected=!!D)}),M})}},"check");L=="left"?B.push(b):Q.push(b)}return A&&B.push(l(v,{fontSize:"1.mini",fontColor:"theme",opacity:x?"max":"low",transition:"middle",xcss:{transform:x&&r.sort.dir==-1?"rotate(180deg)":"none"},icon:x?De:we},"sort")),l(T.Cell,y(n(n({isTH:!!g,ssPushable:!!E},W(_||{})[0]),k),{className:[e.cellClassName,k.className].join(" "),onClick:b=>{k.onClick&&k.onClick(b),e.onCellClick&&e.onCellClick(R,b),A&&o(D=>{let K=n({},D);return K.sort={col:S,dir:x?D.sort.dir*-1:E},f.updateRowMeta(K,e)})},children:j(O.Left,{gap:"1/3",height:1,children:[B,(oe=m==null?void 0:m(u))!=null?oe:l(w,{flexSizing:0,children:C!=null?C:u}),Q]})}),[S,s.key].join("/"))})}))},Body:t=>{var d,h;let{input:e,val_config:r,set_config:o}=t,i=r.body.filter(s=>s.isVisible),a=+!e.headerless+i.length+ +!!e.footer,c=(d=e.colLength)!=null?d:e.header.length;return i.length?l(Pe,{children:i.map((s,S)=>{let{onCheckerDisabled:F,onDraggerDisabled:G}=s,g=S;e.headerless||(g+=1);let u="datagrid-dragger-"+r.datagridID,C=["datagrid",r.datagridID,s.row_id].join("-");return l(ge.DropArea,y(n({jsxElement:T.Row,id:C,ssPushable:!!e.onRowClick||!!s.onRowClick},e.rowStyles),{onClick:m=>{s.onRowClick&&s.onRowClick(m),e.onRowClick&&e.onRowClick(s,m)},dragInfo:{type:u,id:C,idx:S+1,disabled:!r.draggable,marker:"bottom"},children:e.header.toASC("columnIdx").map((m,I)=>{var Y,Z,ee,te,re,oe;let L=m.draggable,N=s[m.key];if(!N)return null;let[q,E]=W(N),X=E,{isTH:$,sortKey:J,data:k,label:R,onLabelRender:H}=X,A=z(X,["isTH","sortKey","data","label","onLabelRender"]),x={rowIdx:g,colIdx:I,topIdx:g,leftIdx:I,rightIdx:c-I-1,bottomIdx:a-g-1,isHeader:!1,isBody:!0,isFooter:!1},_=p.deepMerge(p.deepCopy(e.cellStyles),pe(x,{}),(Y=e.cellStyles)==null?void 0:Y.onBody,!x.leftIdx&&((Z=e.cellStyles)==null?void 0:Z.onLeft),!x.rightIdx&&((ee=e.cellStyles)==null?void 0:ee.onRight),!x.topIdx&&((te=e.cellStyles)==null?void 0:te.onTop),!x.bottomIdx&&((re=e.cellStyles)==null?void 0:re.onBottom),q);e.onCellStyles&&(_=e.onCellStyles(x,_||{}));let B=[],Q=[];return p.scope(()=>{if(L){if(s.onDraggerDisabled){B.push(s.onDraggerDisabled());return}B.push(l(de.Clear.S,{tabIndex:-1,isRounded:!0,ssSphere:2.5,fontColor:"6.clear",onPointerDown:b=>{let D=p("#"+C)[0],K=D.cloneNode(!0);K.style.width=D.offsetWidth+"px",ge.Start(u,{dragElement:K,startEvent:b,originId:C,horizontal:!1},M=>be(void 0,null,function*(){if(!M.onDropArea)return;let V=S,U=Number(M.idx);if(p.isNullish(U)||U==-1||(U>V&&U--,V==U)||!M.end)return;let fe=r.paging.rows*(r.paging.current-1);V+=fe,U+=fe;let le=[...r.body||[]],Re=le.splice(V,1)[0];le.splice(U,0,Re),le.forEach((se,Ie)=>{se.draggerIndex=Ie+1}),e.onDragged&&e.onDragged(le),o(se=>y(n({},se),{body:le}))}))},children:l(O.Center,{gap:"1/4",children:l(v,{icon:Se})})},"drag"))}}),p.scope(()=>{if(!m.checkable)return;let b=l(f.Checker,{override:"force",value:!!s.isSelected,onUpdateValue:D=>{o(K=>y(n({},K),{body:K.body.map(M=>(M.row_id==s.row_id&&(M.isSelected=!!D),M))}))}},"check");s.onCheckerDisabled&&(b=s.onCheckerDisabled()),m.checkable=="left"?B.push(b):Q.push(b)}),l(T.Cell,y(n(n({isTH:!!$},W(_||{})[0]),A),{className:[e.cellClassName,A.className].join(" "),onClick:b=>{A.onClick&&A.onClick(b),e.onCellClick&&e.onCellClick(x,b)},children:j(O.Left,{gap:"1/3",height:1,children:[B,(oe=H==null?void 0:H(k))!=null?oe:l(w,{flexSizing:0,children:he(R!=null?R:String(k),r.filter.keyword)}),Q]})}),[I,m.key].join("/"))})}),[s.row_id,g].join("."))})}):l(T.Row,y(n({},e.rowStyles),{children:l(T.Cell,{colSpan:c,padding:1,children:(h=e.onNoRecordsRender)==null?void 0:h.call(e)})}))},Footer:t=>{var c;let{input:e,val_config:r,set_config:o}=t;if(!e.footer)return null;let i=+!e.headerless+r.body.filter(d=>d.isVisible).length+1,a=(c=e.colLength)!=null?c:e.header.length;return l(T.Row,y(n({},e.rowStyles),{children:e.header.toASC("columnIdx").map((d,h)=>{var q,E,$,J,k,R;let s=e.footer[d.key];if(!s)return null;p.isRecord(s)||(s={data:s});let[S,F]=W(s),N=F,{isTH:G,data:g,label:u,onLabelRender:C}=N,m=z(N,["isTH","data","label","onLabelRender"]),I={rowIdx:i-1,colIdx:h,topIdx:i-1,leftIdx:h,rightIdx:a-h-1,bottomIdx:0,isHeader:!1,isBody:!1,isFooter:!0},L=p.deepMerge(p.deepCopy(e.cellStyles),pe(I,{}),(q=e.cellStyles)==null?void 0:q.onBody,!I.leftIdx&&((E=e.cellStyles)==null?void 0:E.onLeft),!I.rightIdx&&(($=e.cellStyles)==null?void 0:$.onRight),!I.topIdx&&((J=e.cellStyles)==null?void 0:J.onTop),!I.bottomIdx&&((k=e.cellStyles)==null?void 0:k.onBottom),S);return e.onCellStyles&&(L=e.onCellStyles(I,L||{})),l(T.Cell,y(n(n({isTH:!!G},W(L||{})[0]),m),{className:[e.cellClassName,m.className].join(" "),onClick:H=>{m.onClick&&m.onClick(H),e.onCellClick&&e.onCellClick(I,H)},children:l(w,{flexSizing:0,children:(R=C==null?void 0:C(g))!=null?R:he(u!=null?u:String(g),r.filter.keyword)})}),[h,d.key].join("/"))})}))}},pe=(t,e)=>{let r=n({},e);return t.topIdx||(r.borderTop="unset"),t.bottomIdx||(r.borderBottom="unset"),t.rightIdx||(r.borderRight="unset"),t.leftIdx||(r.borderLeft="unset"),t.topIdx||(t.leftIdx||(r.borderTopLeftRadius="inherit"),t.rightIdx||(r.borderTopRightRadius="inherit")),t.bottomIdx||(t.leftIdx||(r.borderBottomLeftRadius="inherit"),t.rightIdx||(r.borderBottomRightRadius="inherit")),r},Be=t=>(t=n({datagridID:ce(),tone:"border",maxRows:100,onNoRecordsRender:()=>l(O.Center,{children:l(ye.Mini,{fontColor:"4.thin",children:"(\u30C7\u30FC\u30BF\u306A\u3057)"})})},t),t.rowStyles=n({backgroundColor:"layer.0"},t.rowStyles),t.cellStyles=n(y(n({},p.scope(()=>{if(!t.tone)return{};let e={};return p.isOneOf(t.tone,"border","border.horizontal")&&(e.borderBottom="2.normal"),p.isOneOf(t.tone,"border","border.vertical")&&(e.borderRight="2.normal"),e})),{position:"relative",padding:["1/3","2/3"],transition:"short"}),t.cellStyles),t.tone&&(t=n({border:!0,borderRadius:"2.tone.secondary",backgroundColor:"layer.1"},t)),t.header=f.toSafetyHeader(t.header||[]),t.header.forEach((e,r)=>{var o;e.sortable=(o=e.sortable)!=null?o:1,e.checkable===!0&&(e.checkable="left")}),l(f.index,n({},t))),ue={getBodyRows:t=>ae.get("rows-"+t)||[],toSafetyBody:f.toSafetyBody,reset:t=>{var e;(e=ae.get("reset-"+t))==null||e()},refreshBody:t=>{var e;(e=ae.get("refresh-"+t))==null||e()},reservedKeys:f.reservedKeys,Table:t=>l(w,y(n({htmlTag:"table",borderRadius:"inherit"},t),{border:t.border})),Head:t=>l(w,n({htmlTag:"thead",borderRadius:"inherit"},t)),Body:t=>l(w,n({htmlTag:"tbody",borderRadius:"inherit"},t)),Row:t=>l(w,n({htmlTag:"tr",borderRadius:"inherit"},t)),TH:t=>l(w,n({htmlTag:"th"},t)),TD:t=>l(w,n({htmlTag:"td"},t)),Cell:t=>{let o=t,{isTH:e}=o,r=z(o,["isTH"]);return e?l(ue.TH,n({},r)):l(ue.TD,n({},r))},RightIndicator:{data:"",label:l(O.Right,{children:l(v.AngleRight,{fontColor:"theme",fontSize:"3.paragraph"})})},SearchInput:t=>{let a=t,{datagridID:e}=a,r=z(a,["datagridID"]),o=ne.catch(t.datagridID);if(!o)return console.warn("[DataGrid] SearchInput must be used inside DataGrid."),null;let{val_config:i}=o;return l(P.TextField,y(n({label:"\u691C\u7D22...",clearButton:!0,padding:["1/2","2/3"],rightIcon:l(P.RightIcon,{ssSphere:2,fontColor:"5.translucent",right:"2/3",children:l(v.Search,{})}),value:i.filter.keyword},r),{onUpdateValidValue:(...c)=>{r.onUpdateValidValue&&r.onUpdateValidValue(...c),o.remoteUpdate.searchKey(c[0])}}))},Info:t=>{let e=ne.catch(t.datagridID);if(!e)return null;let{val_config:r}=e,o=t.totalCount||r.body.length,i=r.body.filter(c=>c.isFilterMatched).length,a=i.ratio(o,1)||0;return j(ke,{verticalAlign:"baseline",gap:"1/2",fontSize:"1.mini",fontColor:"3.blur",children:[l(Ke,{fontSize:"4.thirdTitle",fontColor:"theme",children:i.toLocaleString()}),"/ ",o.toLocaleString(),"\u4EF6 (",a,"%)"]})},Paging:t=>{let e=ne.catch(t.datagridID);if(!e)return null;let{val_config:r}=e,o=[];for(let a=0;a<r.paging.total;a++)o.push({value:a+1,label:(a+1).toString()});const i=a=>{let c=Math.min(Math.max(1,a),r.paging.total),d=n({},r);d.paging.current=c,e.remoteUpdate.paging(c)};return l(P.Select,{emptySelect:!1,padding:["1/3","2/3"],override:"force",gap:0,leftIcon:l(P.LeftIcon,{xcss:{left:2,pointerEvents:"all"},children:l(de.Sub.S,{color:"cloud",fontColor:"4.thin",ssSquare:2.5,unitWidth:2,onClick:()=>{if(r.paging.current==1){i(r.paging.total);return}i(r.paging.current-1)},children:l(v.ChevronLeft,{})})}),rightIcon:l(P.RightIcon,{xcss:{right:2,pointerEvents:"all"},children:l(de.Sub.S,{color:"cloud",fontColor:"4.thin",ssSquare:2.5,unitWidth:2,onClick:()=>{if(r.paging.current==r.paging.total){i(1);return}i(r.paging.current+1)},children:l(v.ChevronRight,{})})}),options:o.map(a=>({value:a.value||0,label:j(O.Left,{gap:"1/3",verticalAlign:"baseline",children:[a.label,j(ye.Micro,{fontColor:"4.thin",children:["/ ",r.paging.total]})]})})),value:r.paging.current,onUpdateValidValue:a=>{i(a)}})},RowCount:t=>{let e=ne.catch(t.datagridID);if(!e)return null;let{val_config:r}=e,o=r.body.filter(d=>d.isFilterMatched).length,i=r.paging.rows,a=0,c=t.options.map(d=>(a|=+(d==i),{value:d,label:d.toString()}));return a||c.push({value:i,label:i.toString()}),l(O.Center,{gap:"1/2",children:l(P.Select,{emptySelect:!1,override:"force",padding:"1/3",paddingLeft:3,paddingRight:2,pickerStyles:{xcss:{minWidth:12*9}},pickerPosition:4,leftIcon:l(P.LeftIcon,{fontSize:"0.xs",fontColor:"4.thin",xcss:{left:6},children:"\u8868\u793A"}),rightIcon:l(P.RightIcon,{fontSize:"0.xs",fontColor:"4.thin",xcss:{right:6},children:"\u4EF6"}),value:r.paging.rows,options:c.toASC("value"),onUpdateValidValue:d=>{e.remoteUpdate.maxRow(Number(d))}})})}},T=Object.assign(Be,ue);export{T as DataGrid,T as default,pe as onDefaultCellStyles};
|
|
1
|
+
import{b as n,c as y,d as z,e as be}from"../../chunk-C5N2D3ZX.js";import{Fragment as Pe,jsx as l,jsxs as j}from"react/jsx-runtime";import p,{useStore as ae,UUID as ce}from"jmini";import me,{useState as xe,useEffect as ie}from"react";import{ExtractStyles as W,GenerateHTMLProps as Te,dragEffect as ge,useRemote as ne}from"../../@utils";import{faArrowUp as De}from"@fortawesome/free-solid-svg-icons/faArrowUp";import{faUpDown as we}from"@fortawesome/free-solid-svg-icons/faUpDown";import{Box as w,Flex as ke,FAI as F,Span as Ke}from"../../atoms";import{Literal as ye,Row as O,MarkerPen as he}from"../../mols";import{Button as de}from"../Button";import P from"../Input";import{TableClasses as Me}from"../../@styles/componentClasses";import{faGripVertical as Se}from"@fortawesome/free-solid-svg-icons/faGripVertical";import{Tips as Ce}from"../Tips";const u={reservedKeys:["row_id","onCheckerDisabled","onDraggerDisabled","columnIdx","isSelected","isFilterMatched","isVisible","draggerIndex","onRowClick"],toSafetyHeader:t=>{let e=!!t.some(o=>o.draggable);return(t==null?void 0:t.map((o,i)=>{var a;return p.isRecord(o)||(o={key:o}),p.isString(o.key)&&(o.key=o.key.replace(/[.\s]/g,"_")),e&&(o.sortable=0,o.filterable=!1),o.columnIdx=(a=o.columnIdx)!=null?a:i,o}).toASC("columnIdx"))||[]},toSafetyBody:t=>t==null?void 0:t.map((e,r)=>{var i;let o={};return Object.entries(e).forEach(([a,c])=>{var h,s;if(p.isOneOf(a,...u.reservedKeys))return;let d=c;p.isNullish(d)||(p.isRecord(d)||(d={data:d}),p.isString(a)&&(a=a.replace(/[.\s]/g,"_")),d.sortKey=(s=(h=d.sortKey)!=null?h:String(d.data))!=null?s:"",o[a]=d)}),o=y(n({},o),{row_id:(i=e.row_id)!=null?i:r,onRowClick:e.onRowClick,isSelected:!!e.isSelected,isFilterMatched:!0,isVisible:!0,onCheckerDisabled:e.onCheckerDisabled,onDraggerDisabled:e.onDraggerDisabled,draggerIndex:r}),o}),toSafetyData:t=>{var o,i;let{header:e=[]}=t,r={datagridID:t.datagridID||ce(),sessionID:ce(),body:u.toSafetyBody(t.body||[]),filter:{keyword:t.defaultSearchKey||"",current:[]},sort:{col:-1,dir:1},paging:{rows:t.maxRows||100,total:1,current:1},draggable:!!e.some(a=>a.draggable)};{let a=e==null?void 0:e.findIndex(c=>c.defSort);a!==-1&&(r.sort.col=a,r.sort.dir=(i=(o=e[a])==null?void 0:o.sortable)!=null?i:1)}return r.draggable&&(r.filter.keyword="",r.sort.col=-1,r.sort.dir=0),u.updateRowMeta(r,t)},updateRowMeta:(t,e)=>{let r=n({},t);if(r.sort.col>=0&&r.sort.dir){let o=e.header[r.sort.col].key;r.sort.dir==1?r.body.toASC(o+".sortKey"):r.body.toDESC(o+".sortKey")}{let o=String(r.filter.keyword)||"";r.body.forEach(i=>{if(i.isFilterMatched=!0,!o)return;let a=e.header.some(c=>{var s;let d=i[c.key];return!d||!d.sortKey?!1:!!((s=String(d.sortKey||d.data))!=null&&s.match(new RegExp(o.escapeRegExChar(),"i")))});i.isFilterMatched=a})}{let o=r.paging.rows;r.paging.total=Math.ceil(r.body.filter(d=>d.isFilterMatched).length/o);let i=o*(r.paging.current-1),a=i+o,c=0;r.body.forEach(d=>{d.isVisible=!1,d.isFilterMatched&&(d.isVisible=c>=i&&c<a,c++)})}return r.draggable&&r.body.toASC("draggerIndex"),r},index:t=>{var s,S,G,N;let[e,r]=xe(()=>u.toSafetyData(t));ie(()=>{ae.set({["reset-"+e.datagridID]:()=>{r(u.toSafetyData(t))},["refresh-"+e.datagridID]:()=>{r(g=>u.updateRowMeta(y(n({},g),{body:u.toSafetyBody(t.body)}),t))}})},[t]),ie(()=>{ae.set({["rows-"+e.datagridID]:e.body}),ne.bridge(e.datagridID,{val_config:e,remoteUpdate:{paging:g=>{r(f=>u.updateRowMeta(y(n({},f),{paging:y(n({},f.paging),{current:Math.max(1,Math.min(f.paging.total,g))})}),t))},maxRow:g=>{r(f=>u.updateRowMeta(y(n({},f),{paging:y(n({},f.paging),{rows:g,current:1})}),t))},searchKey:g=>{e.draggable||p.interval.once(()=>{r(f=>{let C=y(n({},f),{paging:y(n({},f.paging),{current:1}),filter:y(n({},f.filter),{keyword:String(g||"").trim()})});return u.updateRowMeta(C,t)})},300,"InputSearchTime")}}})},[e]);const o=me.useRef(!1);ie(()=>{if(t.onSelected){if(!o.current){o.current=!0;return}t.onSelected(e.body.filter(g=>g.isSelected))}},[(s=e==null?void 0:e.body)==null?void 0:s.filter(g=>g.isSelected).length]);const i=me.useRef(!1);ie(()=>{if(t.onSorted){if(!i.current){i.current=!0;return}t.onSorted(e.sort.col,e.sort.dir)}},[(S=e==null?void 0:e.sort)==null?void 0:S.col,(G=e==null?void 0:e.sort)==null?void 0:G.dir]);let a={input:t,val_config:e,set_config:r},{className:c,style:d}=Te(t),h=(N=t.colLength)!=null?N:t.header.length;return l(w,{className:c,style:d,children:l(T.Table,{className:Me("DataGrid"),borderRadius:"inherit",children:j(T.Body,{children:[l(u.Header,n({},a)),l(u.Body,n({},a)),l(u.Footer,n({},a))]})},[h,...t.header.map(g=>g.key),e.sessionID].join("."))})},Checker:t=>l(w,{flexCenter:!0,onClick:e=>{e.stopPropagation()},children:l(P.Checker,y(n({wrapStyles:{display:"inlineBlock"},cellStyles:{gap:0}},t),{label:!1}))}),Header:t=>{var h;let{input:e,val_config:r,set_config:o}=t;if(e.headerless)return null;let i="datagrid-dragger-"+r.datagridID,a=["datagrid",r.datagridID,""].join("-"),c=1+r.body.filter(s=>s.isVisible).length+ +!!e.footer,d=(h=e.colLength)!=null?h:e.header.length;return l(ge.DropArea,y(n({jsxElement:T.Row,id:a},e.rowStyles),{dragInfo:{type:i,id:a,idx:0,marker:"bottom"},children:e.header.toASC("columnIdx").map((s,S)=>{var Y,Z,ee,te,re,oe;let[G,N]=W(s),X=N,{isTH:g,key:f,label:C,onLabelRender:m,columnIdx:I,checkable:L,draggable:A,defSort:q,sortable:E,filterable:$,isHidden:J}=X,k=z(X,["isTH","key","label","onLabelRender","columnIdx","checkable","draggable","defSort","sortable","filterable","isHidden"]);if(J)return null;let R={rowIdx:0,colIdx:S,topIdx:0,leftIdx:S,rightIdx:d-S-1,bottomIdx:c-1,isHeader:!0,isBody:!1,isFooter:!1},H=A,_=E!=0,x=S==r.sort.col,V=p.deepMerge(p.deepCopy(e.cellStyles),pe(R,{}),(Y=e.cellStyles)==null?void 0:Y.onHeader,!R.leftIdx&&((Z=e.cellStyles)==null?void 0:Z.onLeft),!R.rightIdx&&((ee=e.cellStyles)==null?void 0:ee.onRight),!R.topIdx&&((te=e.cellStyles)==null?void 0:te.onTop),!R.bottomIdx&&((re=e.cellStyles)==null?void 0:re.onBottom),G);e.onCellStyles&&(V=e.onCellStyles(R,V||{}));let B=[],Q=[];if(H&&B.push(l(de.Clear.S,{ssSphere:2,fontColor:"theme",onMouseOver:b=>{Ce.open(b.currentTarget,j(ye.Mini,{children:[l(F,{icon:Se}),"\u30C9\u30E9\u30C3\u30B0\u3067\u5217\u306E\u9806\u756A\u3092\u5909\u66F4"]}),22)},onMouseLeave:b=>Ce.abort(),onClick:b=>{b.stopPropagation()},children:l(F.QuestionCircle,{})},"drag")),L){let b=l(u.Checker,{value:r.body.every(D=>D.isSelected),onUpdateValue:D=>{o(K=>{let M=n({},K);return M.body.forEach(v=>{v.isFilterMatched&&(v.onCheckerDisabled||(v.isSelected=!!D))}),M})}},"check");L=="left"?B.push(b):Q.push(b)}return _&&B.push(l(F,{fontSize:"1.mini",fontColor:"theme",opacity:x?"max":"low",transition:"middle",xcss:{transform:x&&r.sort.dir==-1?"rotate(180deg)":"none"},icon:x?De:we},"sort")),l(T.Cell,y(n(n({isTH:!!g,ssPushable:!!E},W(V||{})[0]),k),{className:[e.cellClassName,k.className].join(" "),onClick:b=>{k.onClick&&k.onClick(b),e.onCellClick&&e.onCellClick(R,b),_&&o(D=>{let K=n({},D);return K.sort={col:S,dir:x?D.sort.dir*-1:E},u.updateRowMeta(K,e)})},children:j(O.Left,{gap:"1/3",height:1,children:[B,(oe=m==null?void 0:m(f))!=null?oe:l(w,{flexSizing:0,children:C!=null?C:f}),Q]})}),[S,s.key].join("/"))})}))},Body:t=>{var d,h;let{input:e,val_config:r,set_config:o}=t,i=r.body.filter(s=>s.isVisible),a=+!e.headerless+i.length+ +!!e.footer,c=(d=e.colLength)!=null?d:e.header.length;return i.length?l(Pe,{children:i.map((s,S)=>{let{onCheckerDisabled:G,onDraggerDisabled:N}=s,g=S;e.headerless||(g+=1);let f="datagrid-dragger-"+r.datagridID,C=["datagrid",r.datagridID,s.row_id].join("-");return l(ge.DropArea,y(n({jsxElement:T.Row,id:C,ssPushable:!!e.onRowClick||!!s.onRowClick},e.rowStyles),{onClick:m=>{s.onRowClick&&s.onRowClick(m),e.onRowClick&&e.onRowClick(s,m)},dragInfo:{type:f,id:C,idx:S+1,disabled:!r.draggable,marker:"bottom"},children:e.header.toASC("columnIdx").map((m,I)=>{var Y,Z,ee,te,re,oe;let L=m.draggable,A=s[m.key];if(!A)return null;let[q,E]=W(A),X=E,{isTH:$,sortKey:J,data:k,label:R,onLabelRender:H}=X,_=z(X,["isTH","sortKey","data","label","onLabelRender"]),x={rowIdx:g,colIdx:I,topIdx:g,leftIdx:I,rightIdx:c-I-1,bottomIdx:a-g-1,isHeader:!1,isBody:!0,isFooter:!1},V=p.deepMerge(p.deepCopy(e.cellStyles),pe(x,{}),(Y=e.cellStyles)==null?void 0:Y.onBody,!x.leftIdx&&((Z=e.cellStyles)==null?void 0:Z.onLeft),!x.rightIdx&&((ee=e.cellStyles)==null?void 0:ee.onRight),!x.topIdx&&((te=e.cellStyles)==null?void 0:te.onTop),!x.bottomIdx&&((re=e.cellStyles)==null?void 0:re.onBottom),q);e.onCellStyles&&(V=e.onCellStyles(x,V||{}));let B=[],Q=[];return p.scope(()=>{if(L){if(s.onDraggerDisabled){B.push(s.onDraggerDisabled());return}B.push(l(de.Clear.S,{tabIndex:-1,isRounded:!0,ssSphere:2.5,fontColor:"6.clear",onPointerDown:b=>{let D=p("#"+C)[0],K=D.cloneNode(!0);K.style.width=D.offsetWidth+"px",ge.Start(f,{dragElement:K,startEvent:b,originId:C,horizontal:!1},M=>be(void 0,null,function*(){if(!M.onDropArea)return;let v=S,U=Number(M.idx);if(p.isNullish(U)||U==-1||(U>v&&U--,v==U)||!M.end)return;let ue=r.paging.rows*(r.paging.current-1);v+=ue,U+=ue;let le=[...r.body||[]],Re=le.splice(v,1)[0];le.splice(U,0,Re),le.forEach((se,Ie)=>{se.draggerIndex=Ie+1}),e.onDragged&&e.onDragged(le),o(se=>y(n({},se),{body:le}))}))},children:l(O.Center,{gap:"1/4",children:l(F,{icon:Se})})},"drag"))}}),p.scope(()=>{if(!m.checkable)return;let b=l(u.Checker,{override:"force",value:!!s.isSelected,onUpdateValue:D=>{o(K=>y(n({},K),{body:K.body.map(M=>(M.row_id==s.row_id&&(M.isSelected=!!D),M))}))}},"check");s.onCheckerDisabled&&(b=s.onCheckerDisabled()),m.checkable=="left"?B.push(b):Q.push(b)}),l(T.Cell,y(n(n({isTH:!!$},W(V||{})[0]),_),{className:[e.cellClassName,_.className].join(" "),onClick:b=>{_.onClick&&_.onClick(b),e.onCellClick&&e.onCellClick(x,b)},children:j(O.Left,{gap:"1/3",height:1,children:[B,(oe=H==null?void 0:H(k))!=null?oe:l(w,{flexSizing:0,children:he(R!=null?R:String(k),r.filter.keyword)}),Q]})}),[I,m.key].join("/"))})}),[s.row_id,g].join("."))})}):l(T.Row,y(n({},e.rowStyles),{children:l(T.Cell,{colSpan:c,padding:1,children:(h=e.onNoRecordsRender)==null?void 0:h.call(e)})}))},Footer:t=>{var c;let{input:e,val_config:r,set_config:o}=t;if(!e.footer)return null;let i=+!e.headerless+r.body.filter(d=>d.isVisible).length+1,a=(c=e.colLength)!=null?c:e.header.length;return l(T.Row,y(n({},e.rowStyles),{children:e.header.toASC("columnIdx").map((d,h)=>{var q,E,$,J,k,R;let s=e.footer[d.key];if(!s)return null;p.isRecord(s)||(s={data:s});let[S,G]=W(s),A=G,{isTH:N,data:g,label:f,onLabelRender:C}=A,m=z(A,["isTH","data","label","onLabelRender"]),I={rowIdx:i-1,colIdx:h,topIdx:i-1,leftIdx:h,rightIdx:a-h-1,bottomIdx:0,isHeader:!1,isBody:!1,isFooter:!0},L=p.deepMerge(p.deepCopy(e.cellStyles),pe(I,{}),(q=e.cellStyles)==null?void 0:q.onBody,!I.leftIdx&&((E=e.cellStyles)==null?void 0:E.onLeft),!I.rightIdx&&(($=e.cellStyles)==null?void 0:$.onRight),!I.topIdx&&((J=e.cellStyles)==null?void 0:J.onTop),!I.bottomIdx&&((k=e.cellStyles)==null?void 0:k.onBottom),S);return e.onCellStyles&&(L=e.onCellStyles(I,L||{})),l(T.Cell,y(n(n({isTH:!!N},W(L||{})[0]),m),{className:[e.cellClassName,m.className].join(" "),onClick:H=>{m.onClick&&m.onClick(H),e.onCellClick&&e.onCellClick(I,H)},children:l(w,{flexSizing:0,children:(R=C==null?void 0:C(g))!=null?R:he(f!=null?f:String(g),r.filter.keyword)})}),[h,d.key].join("/"))})}))}},pe=(t,e)=>{let r=n({},e);return t.topIdx||(r.borderTop="unset"),t.bottomIdx||(r.borderBottom="unset"),t.rightIdx||(r.borderRight="unset"),t.leftIdx||(r.borderLeft="unset"),t.topIdx||(t.leftIdx||(r.borderTopLeftRadius="inherit"),t.rightIdx||(r.borderTopRightRadius="inherit")),t.bottomIdx||(t.leftIdx||(r.borderBottomLeftRadius="inherit"),t.rightIdx||(r.borderBottomRightRadius="inherit")),r},Be=t=>(t=n({datagridID:ce(),tone:"border",maxRows:100,onNoRecordsRender:()=>l(O.Center,{children:l(ye.Mini,{fontColor:"4.thin",children:"(\u30C7\u30FC\u30BF\u306A\u3057)"})})},t),t.rowStyles=n({backgroundColor:"layer.0"},t.rowStyles),t.cellStyles=n(y(n({},p.scope(()=>{if(!t.tone)return{};let e={};return p.isOneOf(t.tone,"border","border.horizontal")&&(e.borderBottom="2.normal"),p.isOneOf(t.tone,"border","border.vertical")&&(e.borderRight="2.normal"),e})),{position:"relative",padding:["1/3","2/3"],transition:"short"}),t.cellStyles),t.tone&&(t=n({border:!0,borderRadius:"2.tone.secondary",backgroundColor:"layer.1"},t)),t.header=u.toSafetyHeader(t.header||[]),t.header.forEach((e,r)=>{var o;e.sortable=(o=e.sortable)!=null?o:1,e.checkable===!0&&(e.checkable="left")}),l(u.index,n({},t))),fe={getBodyRows:t=>ae.get("rows-"+t)||[],toSafetyBody:u.toSafetyBody,reset:t=>{var e;(e=ae.get("reset-"+t))==null||e()},refreshBody:t=>{var e;(e=ae.get("refresh-"+t))==null||e()},reservedKeys:u.reservedKeys,Table:t=>l(w,y(n({htmlTag:"table",borderRadius:"inherit"},t),{border:t.border})),Head:t=>l(w,n({htmlTag:"thead",borderRadius:"inherit"},t)),Body:t=>l(w,n({htmlTag:"tbody",borderRadius:"inherit"},t)),Row:t=>l(w,n({htmlTag:"tr",borderRadius:"inherit"},t)),TH:t=>l(w,n({htmlTag:"th"},t)),TD:t=>l(w,n({htmlTag:"td"},t)),Cell:t=>{let o=t,{isTH:e}=o,r=z(o,["isTH"]);return e?l(fe.TH,n({},r)):l(fe.TD,n({},r))},RightIndicator:{data:"",label:l(O.Right,{children:l(F.AngleRight,{fontColor:"theme",fontSize:"3.paragraph"})})},SearchInput:t=>{let a=t,{datagridID:e}=a,r=z(a,["datagridID"]),o=ne.catch(t.datagridID);if(!o)return console.warn("[DataGrid] SearchInput must be used inside DataGrid."),null;let{val_config:i}=o;return l(P.TextField,y(n({label:"\u691C\u7D22...",clearButton:!0,padding:["1/2","2/3"],rightIcon:l(P.RightIcon,{ssSphere:2,fontColor:"5.translucent",right:"2/3",children:l(F.Search,{})}),value:i.filter.keyword},r),{onUpdateValidValue:(...c)=>{r.onUpdateValidValue&&r.onUpdateValidValue(...c),o.remoteUpdate.searchKey(c[0])}}))},Info:t=>{let e=ne.catch(t.datagridID);if(!e)return null;let{val_config:r}=e,o=t.totalCount||r.body.length,i=r.body.filter(c=>c.isFilterMatched).length,a=i.ratio(o,1)||0;return j(ke,{verticalAlign:"baseline",gap:"1/2",fontSize:"1.mini",fontColor:"3.blur",children:[l(Ke,{fontSize:"4.thirdTitle",fontColor:"theme",children:i.toLocaleString()}),"/ ",o.toLocaleString(),"\u4EF6 (",a,"%)"]})},Paging:t=>{let e=ne.catch(t.datagridID);if(!e)return null;let{val_config:r}=e,o=[];for(let a=0;a<r.paging.total;a++)o.push({value:a+1,label:(a+1).toString()});const i=a=>{let c=Math.min(Math.max(1,a),r.paging.total),d=n({},r);d.paging.current=c,e.remoteUpdate.paging(c)};return l(P.Select,{emptySelect:!1,padding:["1/3","2/3"],override:"force",gap:0,leftIcon:l(P.LeftIcon,{xcss:{left:2,pointerEvents:"all"},children:l(de.Sub.S,{color:"cloud",fontColor:"4.thin",ssSquare:2.5,unitWidth:2,onClick:()=>{if(r.paging.current==1){i(r.paging.total);return}i(r.paging.current-1)},children:l(F.ChevronLeft,{})})}),rightIcon:l(P.RightIcon,{xcss:{right:2,pointerEvents:"all"},children:l(de.Sub.S,{color:"cloud",fontColor:"4.thin",ssSquare:2.5,unitWidth:2,onClick:()=>{if(r.paging.current==r.paging.total){i(1);return}i(r.paging.current+1)},children:l(F.ChevronRight,{})})}),options:o.map(a=>({value:a.value||0,label:j(O.Left,{gap:"1/3",verticalAlign:"baseline",children:[a.label,j(ye.Micro,{fontColor:"4.thin",children:["/ ",r.paging.total]})]})})),value:r.paging.current,onUpdateValidValue:a=>{i(a)}})},RowCount:t=>{let e=ne.catch(t.datagridID);if(!e)return null;let{val_config:r}=e,o=r.body.filter(d=>d.isFilterMatched).length,i=r.paging.rows,a=0,c=t.options.map(d=>(a|=+(d==i),{value:d,label:d.toString()}));return a||c.push({value:i,label:i.toString()}),l(O.Center,{gap:"1/2",children:l(P.Select,{emptySelect:!1,override:"force",padding:"1/3",paddingLeft:3,paddingRight:2,pickerStyles:{xcss:{minWidth:12*9}},pickerPosition:4,leftIcon:l(P.LeftIcon,{fontSize:"0.xs",fontColor:"4.thin",xcss:{left:6},children:"\u8868\u793A"}),rightIcon:l(P.RightIcon,{fontSize:"0.xs",fontColor:"4.thin",xcss:{right:6},children:"\u4EF6"}),value:r.paging.rows,options:c.toASC("value"),onUpdateValidValue:d=>{e.remoteUpdate.maxRow(Number(d))}})})}},T=Object.assign(Be,fe);export{T as DataGrid,T as default,pe as onDefaultCellStyles};
|