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