amotify 0.2.285 → 0.2.287

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.
@@ -10,7 +10,8 @@ declare namespace DataGrid {
10
10
  type TR = StyleProps.BasicElement & React.HTMLAttributes<HTMLTableRowElement>;
11
11
  type TableCell = StyleProps.BasicElement & React.ThHTMLAttributes<HTMLTableCellElement>;
12
12
  type RowID = string | number;
13
- type Keytype = string | number;
13
+ type KeyType = string | number;
14
+ type DataType = string | number | boolean;
14
15
  /**
15
16
  * -1: descending
16
17
  * 0: disabled
@@ -35,7 +36,7 @@ declare namespace DataGrid {
35
36
  label?: ReactElement;
36
37
  };
37
38
  namespace Cell {
38
- type Header<K extends Keytype = Keytype> = Cell & {
39
+ type Header<K extends KeyType = KeyType> = Cell & {
39
40
  key: K;
40
41
  /**
41
42
  * default 0
@@ -50,19 +51,19 @@ declare namespace DataGrid {
50
51
  draggable?: boolean;
51
52
  isHidden?: boolean;
52
53
  };
53
- type Body<T = Keytype> = Cell & {
54
+ type Body<T = DataType> = Cell & {
54
55
  data: T;
55
56
  sortKey?: string | number;
56
57
  onLabelRender?(value: T): ReactElement;
57
58
  };
58
- type Footer<T = Keytype> = Cell & {
59
+ type Footer<T = DataType> = Cell & {
59
60
  data: T;
60
61
  onLabelRender?(value: T): ReactElement;
61
62
  };
62
63
  }
63
- type Header<K extends Keytype = any> = Cell.Header<K>[];
64
+ type Header<K extends KeyType = KeyType> = Cell.Header<K>[];
64
65
  namespace Body {
65
- type RowMeta = {
66
+ type MetaRecord = {
66
67
  row_id?: RowID;
67
68
  /**
68
69
  * for checker
@@ -70,14 +71,17 @@ declare namespace DataGrid {
70
71
  isSelected?: boolean;
71
72
  isFilterMatched?: boolean;
72
73
  isVisible?: boolean;
73
- searchKey?: string;
74
+ searchKey?: string | number;
75
+ draggerIndex?: number;
74
76
  onRowClick?(event: React.MouseEvent<HTMLTableRowElement, MouseEvent>): void;
75
77
  };
76
- type Row<K extends Keytype = Keytype, T = Keytype> = RowMeta & Partial<Record<K, Cell.Body<T> | RowID | boolean | Function>>;
78
+ type Row<K extends KeyType = KeyType, T = DataType> = MetaRecord & Partial<Record<K, Cell.Body<T> | KeyType | boolean | Function>>;
79
+ type StrictRow<K extends KeyType = KeyType, T = DataType> = MetaRecord & Partial<Record<K, Cell.Body<T>>>;
77
80
  }
78
- type Body<K extends Keytype = Keytype> = Body.Row<K>[];
79
- type Footer<K extends Keytype = Keytype, T = Keytype> = Partial<Record<K, Cell.Footer<T> | RowID>>;
80
- type Input<K extends Keytype = Keytype> = {
81
+ type Body<K extends KeyType = KeyType> = Body.Row<K>[];
82
+ type StrictBody<K extends KeyType = KeyType> = Body.StrictRow<K>[];
83
+ type Footer<K extends KeyType = KeyType, T = DataType> = Partial<Record<K, Cell.Footer<T> | RowID>>;
84
+ type Input<K extends KeyType = KeyType> = {
81
85
  tone?: Tones;
82
86
  datagridID?: string;
83
87
  props?: Records;
@@ -91,7 +95,7 @@ declare namespace DataGrid {
91
95
  */
92
96
  headerless?: boolean;
93
97
  header: Header<K>;
94
- body: Body<K>;
98
+ body: Body<K> | StrictBody<K>;
95
99
  footer?: Footer<K>;
96
100
  defaultSearchKey?: string;
97
101
  rowStyles?: StyleProps.StyleProps;
@@ -110,10 +114,10 @@ declare namespace DataGrid {
110
114
  onRowClick?(row: Body.Row, event: React.MouseEvent<HTMLTableRowElement, MouseEvent>): void;
111
115
  onCellClick?(opt: CellInfo, event: React.MouseEvent<HTMLTableCellElement, MouseEvent>): void;
112
116
  onSorted?(col: number, sort: SortType): void;
113
- onSelected?(rows: Body.Row[]): void;
114
- onDragged?(rows: Body.Row[]): void;
117
+ onSelected?(rows: Body.StrictRow<K>[]): void;
118
+ onDragged?(rows: Body.StrictRow<K>[]): void;
115
119
  } & StyleProps.States;
116
- type Component = <K extends string = string>(props: DataGrid.Input<K>) => ReactElement;
120
+ type Component = <K extends KeyType = KeyType>(props: DataGrid.Input<K>) => ReactElement;
117
121
  type FNs = {
118
122
  getBodyRows(datagridID: string): Body[];
119
123
  Table: React.FC<Table>;
@@ -1 +1 @@
1
- import{b as a,c as y,d as A,e as se}from"../../chunk-C5N2D3ZX.js";import{Fragment as De,jsx as r,jsxs as U}from"react/jsx-runtime";import b,{useStore as ce,UUID as ge}from"jmini";import re,{useState as me,useEffect as Z,useMemo as he}from"react";import{ExtractStyles as _,GenerateHTMLProps as Se,DragEffect as le,useRemote as Y}from"../../@utils";import{faArrowUp as Ce}from"@fortawesome/free-solid-svg-icons/faArrowUp";import{faUpDown as Re}from"@fortawesome/free-solid-svg-icons/faUpDown";import{Box as k,Flex as Ie,FAI as v,Span as xe}from"../../atoms";import{Literal as ae,Row as G,MarkerPen as pe}from"../../mols";import{Button as ee}from"../Button";import K from"../Input";import{TableClasses as Te}from"../../@styles/componentClasses";import{faGripVertical as ye}from"@fortawesome/free-solid-svg-icons/faGripVertical";import{Tips as ue}from"../Tips";const I={toSafetyData:o=>{var d,s,n;let{header:e=[]}=o,t={datagridID:o.datagridID||ge(),colLength:o.colLength||e.length||0,body:o.body||[],header:e,filter:{keyword:o.defaultSearchKey||"",current:[]},sort:{col:-1,dir:1},paging:{rows:o.maxRows||100,total:1,current:1},draggable:!!e.some(l=>l.draggable)};t.body.forEach((l,i)=>{var m;l.row_id=(m=l.row_id)!=null?m:i,l.isFilterMatched=!0,l.isVisible=!0,l.draggerIndex=i+1,l.searchKey="",e.forEach((x,M)=>{var c;let p=l[x.key];b.isNullish(p)||(b.isRecord(p)||(p={data:p}),p.sortKey=(c=p.sortKey)!=null?c:String(p.data),l.searchKey+=String(p.sortKey)+" ",l[x.key]=p)})});{let l=(d=e==null?void 0:e.filter(i=>i.defSort))==null?void 0:d[0];l&&(t.sort.col=(s=e.indexOf(l))!=null?s:-1,t.sort.dir=(n=l==null?void 0:l.sortable)!=null?n:1)}return t.draggable&&(t.filter.keyword="",t.sort.col=-1,t.sort.dir=0,t.header.forEach(l=>{l.sortable=0,l.filterable=!1})),I.updateRowMeta(t)},updateRowMeta:o=>{let e=a({},o);if(e.sort.col>=0&&e.sort.dir){let t=e.header[e.sort.col].key;e.sort.dir==1?e.body.toASC(t+".data"):e.body.toDESC(t+".data")}{let t=String(e.filter.keyword)||"";e.body.forEach(d=>{var n;if(d.isFilterMatched=!0,!t)return;let s=!!((n=d.searchKey)!=null&&n.match(new RegExp(t.escapeRegExChar(),"i")));d.isFilterMatched=s})}{let t=e.paging.rows;e.paging.total=Math.ceil(e.body.filter(l=>l.isFilterMatched).length/t);let d=t*(e.paging.current-1),s=d+t,n=0;e.body.forEach(l=>{l.isVisible=!1,l.isFilterMatched&&(l.isVisible=n>=d&&n<s,n++)})}return e.draggable&&e.body.toASC("draggerIndex"),e},index:o=>{var x,M,p;let[e,t]=me(()=>I.toSafetyData(o));const d=re.useRef(!1);Z(()=>{if(e){if(!d.current){d.current=!0;return}t(I.toSafetyData(o))}},[he(()=>o.props,[o.props])]),Z(()=>{e&&(ce.set({["rows-"+e.datagridID]:e.body}),Y.bridge(e.datagridID,{val_config:e,remoteUpdate:{paging:c=>{e.draggable||t(g=>I.updateRowMeta(y(a({},g),{paging:y(a({},g.paging),{current:Math.max(1,Math.min(g.paging.total,c))})})))},maxRow:c=>{e.draggable||t(g=>I.updateRowMeta(y(a({},g),{paging:y(a({},g.paging),{rows:c,current:1})})))},searchKey:c=>{e.draggable||b.interval.once(()=>{t(g=>{let D=y(a({},g),{paging:y(a({},g.paging),{current:1}),filter:y(a({},g.filter),{keyword:String(c||"").trim()})});return I.updateRowMeta(D)})},300,"InputSearchTime")}}}))},[e]);const s=re.useRef(!1);Z(()=>{if(e&&o.onSelected){if(!s.current){s.current=!0;return}o.onSelected(e.body.filter(c=>c.isSelected))}},[(x=e==null?void 0:e.body)==null?void 0:x.filter(c=>c.isSelected).length]);const n=re.useRef(!1);Z(()=>{if(e&&o.onSorted){if(!n.current){n.current=!0;return}o.onSorted(e.sort.col,e.sort.dir)}},[(M=e==null?void 0:e.sort)==null?void 0:M.col,(p=e==null?void 0:e.sort)==null?void 0:p.dir]);let l={input:o,val_config:e,set_config:t},{className:i,style:m}=Se(o);return r(k,{className:i,style:m,children:r(w.Table,{className:Te("DataGrid"),borderRadius:"inherit",children:U(w.Body,{children:[r(I.Header,a({},l)),r(I.Body,a({},l)),r(I.Footer,a({},l))]})})})},Checker:o=>r(k,{onClick:e=>{e.stopPropagation()},children:r(K.Checker,y(a({wrapStyles:{display:"inlineBlock"},cellStyles:{gap:0}},o),{label:!1}))}),Header:o=>{let{input:e,val_config:t,set_config:d}=o;if(e.headerless)return null;let s="datagrid-dragger-"+t.datagridID,n=["datagrid",t.datagridID,""].join("-"),l=1+t.body.filter(i=>i.isVisible).length+ +!!e.footer;return r(le.DropArea,y(a({component:w.Row,id:n},e.rowStyles),{dragInfo:{type:s,id:n,idx:0,marker:"bottom"},children:t.header.map((i,m)=>{var W,q,$,Q,J;let[x,M]=_(i),j=M,{isTH:p,key:c,label:g,checkable:D,draggable:S,defSort:N,sortable:E,filterable:z,isHidden:O}=j,P=A(j,["isTH","key","label","checkable","draggable","defSort","sortable","filterable","isHidden"]);if(O)return null;let T={rowIdx:0,colIdx:m,topIdx:0,leftIdx:m,rightIdx:t.colLength-m-1,bottomIdx:l-1,isHeader:!0,isBody:!1,isFooter:!1},H=S,L=E!=0,C=m==t.sort.col,F=b.deepMerge(b.deepCopy(e.cellStyles),ne(T,{}),(W=e.cellStyles)==null?void 0:W.onHeader,!T.leftIdx&&((q=e.cellStyles)==null?void 0:q.onLeft),!T.rightIdx&&(($=e.cellStyles)==null?void 0:$.onRight),!T.topIdx&&((Q=e.cellStyles)==null?void 0:Q.onTop),!T.bottomIdx&&((J=e.cellStyles)==null?void 0:J.onBottom),x);e.onCellStyles&&(F=e.onCellStyles(T,F||{}));let B=[r(k,{flexSizing:0,children:g!=null?g:c},"data")];return L&&B.unshift(r(v,{fontSize:"1.mini",opacity:C?"max":"low",transition:"middle",xcss:{transform:C&&t.sort.dir==-1?"rotate(180deg)":"none"},icon:C?Ce:Re},"sort")),D=="left"&&B.unshift(r(I.Checker,{value:t.body.every(u=>u.isSelected),onUpdateValue:u=>{d(R=>{let f=a({},R);return f.body.forEach(h=>{h.isFilterMatched&&(h.isSelected=!!u)}),f})}},"check")),H&&B.unshift(r(ee.Clear.S,{ssSphere:2,fontColor:"theme",onMouseOver:u=>{ue.open(u.currentTarget,U(ae.Supplement,{children:[r(v,{icon:ye}),"\u30C9\u30E9\u30C3\u30B0\u3067\u5217\u306E\u9806\u756A\u3092\u5909\u66F4"]}),22)},onMouseLeave:u=>ue.abort(),onClick:u=>{u.stopPropagation()},children:r(v.QuestionCircle,{})},"drag")),D=="right"&&B.push(r(I.Checker,{value:t.body.every(u=>u.isSelected),onUpdateValue:u=>{d(R=>{let f=a({},R);return f.body.forEach(h=>{h.isFilterMatched&&(h.isSelected=!!u)}),f})}},"check")),r(w.Cell,y(a(a({isTH:!!p,ssPushable:!!E},_(F||{})[0]),P),{className:[e.cellClassName,P.className].join(" "),onClick:u=>{P.onClick&&P.onClick(u),e.onCellClick&&e.onCellClick(T,u),L&&d(R=>{let f=a({},R);return f.sort={col:m,dir:C?R.sort.dir*-1:E},I.updateRowMeta(f)})},children:r(G.Left,{gap:"1/3",children:B})}),m)})}))},Body:o=>{var l;let{input:e,val_config:t,set_config:d}=o,s=t.body.filter(i=>i.isVisible),n=+!e.headerless+s.length+ +!!e.footer;return U(De,{children:[!s.length&&r(w.Row,y(a({},e.rowStyles),{children:r(w.Cell,{colSpan:t.colLength,padding:1,children:(l=e.onNoRecordsRender)==null?void 0:l.call(e)})})),s.map((i,m)=>{let x=m;e.headerless||(x+=1);let M="datagrid-dragger-"+t.datagridID,p=["datagrid",t.datagridID,i.row_id].join("-");return r(le.DropArea,y(a({component:w.Row,id:p,ssPushable:!!e.onRowClick||!!i.onRowClick},e.rowStyles),{onClick:c=>{i.onRowClick&&i.onRowClick(c),e.onRowClick&&e.onRowClick(i,c)},dragInfo:{type:M,id:p,idx:i.draggerIndex,disabled:!t.draggable,marker:"bottom"},children:t.header.map((c,g)=>{var W,q,$,Q,J,u;let D=c.draggable,S=i[c.key];if(!S)return null;b.isRecord(S)||(S={data:S});let[N,E]=_(S),j=E,{isTH:z,sortKey:O,data:P,label:T,onLabelRender:H}=j,L=A(j,["isTH","sortKey","data","label","onLabelRender"]),C={rowIdx:x,colIdx:g,topIdx:x,leftIdx:g,rightIdx:t.colLength-g-1,bottomIdx:n-x-1,isHeader:!1,isBody:!0,isFooter:!1},F=b.deepMerge(b.deepCopy(e.cellStyles),ne(C,{}),(W=e.cellStyles)==null?void 0:W.onBody,!C.leftIdx&&((q=e.cellStyles)==null?void 0:q.onLeft),!C.rightIdx&&(($=e.cellStyles)==null?void 0:$.onRight),!C.topIdx&&((Q=e.cellStyles)==null?void 0:Q.onTop),!C.bottomIdx&&((J=e.cellStyles)==null?void 0:J.onBottom),N);e.onCellStyles&&(F=e.onCellStyles(C,F||{}));let B=[r(k,{flexSizing:0,children:(u=H==null?void 0:H(P))!=null?u:pe(T!=null?T:String(P),t.filter.keyword)},"data")];return c.checkable=="left"&&B.unshift(r(I.Checker,{override:"force",value:!!i.isSelected,onUpdateValue:R=>{d(f=>y(a({},f),{body:f.body.map(h=>(h.row_id==i.row_id&&(h.isSelected=!!R),h))}))}},"check")),D&&B.unshift(r(ee.Clear.S,{tabIndex:-1,isRounded:!0,ssSphere:2.5,fontColor:"6.clear",onPointerDown:R=>{let f=b("#"+p)[0],h=f.cloneNode(!0);h.style.width=f.offsetWidth+"px",le.Start(M,{dragElement:h,startEvent:R,originId:p,horizontal:!1,allowPrevDataOnDropend:!1},de=>se(void 0,null,function*(){let te=m,V=Number(de.idx);if(b.isNullish(V)||V==-1||(V>te&&V--,te==V)||!de.end)return;let X=b.deepCopy(t.body||[]),fe=X.splice(te,1)[0];X.splice(V,0,fe),X.forEach((oe,be)=>{oe.draggerIndex=be+1}),e.onDragged&&e.onDragged(X),d(oe=>y(a({},oe),{body:X}))}))},children:r(G.Center,{gap:"1/4",children:r(v,{icon:ye})})},"drag")),c.checkable=="right"&&B.push(r(I.Checker,{override:"force",value:!!i.isSelected,onUpdateValue:R=>{d(f=>y(a({},f),{body:f.body.map(h=>(h.row_id==i.row_id&&(h.isSelected=!!R),h))}))}},"check")),r(w.Cell,y(a(a({isTH:!!z},_(F||{})[0]),L),{className:[e.cellClassName,L.className].join(" "),onClick:R=>{L.onClick&&L.onClick(R),e.onCellClick&&e.onCellClick(C,R)},children:r(G.Left,{gap:"1/3",children:B})}),g)})}),String(i.row_id))})]})},Footer:o=>{let{input:e,val_config:t,set_config:d}=o;if(!e.footer)return null;let s=+!e.headerless+t.body.filter(n=>n.isVisible).length+1;return r(w.Row,y(a({},e.rowStyles),{children:t.header.map((n,l)=>{var z,O,P,T,H,L;let i=e.footer[n.key];if(!i)return null;b.isRecord(i)||(i={data:i});let[m,x]=_(i),E=x,{isTH:M,data:p,label:c,onLabelRender:g}=E,D=A(E,["isTH","data","label","onLabelRender"]),S={rowIdx:s-1,colIdx:l,topIdx:s-1,leftIdx:l,rightIdx:t.colLength-l-1,bottomIdx:0,isHeader:!1,isBody:!1,isFooter:!0},N=b.deepMerge(b.deepCopy(e.cellStyles),ne(S,{}),(z=e.cellStyles)==null?void 0:z.onBody,!S.leftIdx&&((O=e.cellStyles)==null?void 0:O.onLeft),!S.rightIdx&&((P=e.cellStyles)==null?void 0:P.onRight),!S.topIdx&&((T=e.cellStyles)==null?void 0:T.onTop),!S.bottomIdx&&((H=e.cellStyles)==null?void 0:H.onBottom),m);return e.onCellStyles&&(N=e.onCellStyles(S,N||{})),r(w.Cell,y(a(a({isTH:!!M},_(N||{})[0]),D),{className:[e.cellClassName,D.className].join(" "),onClick:C=>{D.onClick&&D.onClick(C),e.onCellClick&&e.onCellClick(S,C)},children:r(k,{flexSizing:0,children:(L=g==null?void 0:g(p))!=null?L:pe(c!=null?c:String(p),t.filter.keyword)})}),l)})}))}},ne=(o,e)=>{let t=a({},e);return o.topIdx||(t.borderTop="unset"),o.bottomIdx||(t.borderBottom="unset"),o.rightIdx||(t.borderRight="unset"),o.leftIdx||(t.borderLeft="unset"),o.topIdx||(o.leftIdx||(t.borderTopLeftRadius="inherit"),o.rightIdx||(t.borderTopRightRadius="inherit")),o.bottomIdx||(o.leftIdx||(t.borderBottomLeftRadius="inherit"),o.rightIdx||(t.borderBottomRightRadius="inherit")),t},we=o=>(o=a({datagridID:ge(),tone:"border",colLength:0,maxRows:100,onNoRecordsRender:()=>r(G.Center,{children:r(ae.Supplement,{fontColor:"4.thin",children:"(\u30C7\u30FC\u30BF\u306A\u3057)"})})},o),o.rowStyles=a({backgroundColor:"layer.0"},o.rowStyles),o.cellStyles=a(y(a({},b.scope(()=>{if(!o.tone)return{};let e={};return b.isOneOf(o.tone,"border","border.horizontal")&&(e.borderBottom="2.normal"),b.isOneOf(o.tone,"border","border.vertical")&&(e.borderRight="2.normal"),e})),{padding:"1/3",transition:"short"}),o.cellStyles),o.tone&&(o=a({border:!0,borderRadius:"2.tone.secondary",backgroundColor:"layer.1"},o)),o.header=o.header||[],o.header.forEach((e,t)=>{var d;e.sortable=(d=e.sortable)!=null?d:1,e.checkable===!0&&(e.checkable="left")}),r(I.index,a({},o))),ie={getBodyRows:o=>ce.get("rows-"+o)||[],Table:o=>r(k,y(a({htmlTag:"table",borderRadius:"inherit"},o),{border:o.border})),Head:o=>r(k,a({htmlTag:"thead",borderRadius:"inherit"},o)),Body:o=>r(k,a({htmlTag:"tbody",borderRadius:"inherit"},o)),Row:o=>r(k,a({htmlTag:"tr",borderRadius:"inherit"},o)),TH:o=>r(k,a({htmlTag:"th"},o)),TD:o=>r(k,a({htmlTag:"td"},o)),Cell:o=>{let d=o,{isTH:e}=d,t=A(d,["isTH"]);return e?r(ie.TH,a({},t)):r(ie.TD,a({},t))},RightIndicator:{data:"",label:r(G.Right,{children:r(v.AngleRight,{fontColor:"theme",fontSize:"3.paragraph"})})},SearchInput:o=>{let n=o,{datagridID:e}=n,t=A(n,["datagridID"]),d=Y.catch(o.datagridID);if(!d)return console.warn("[DataGrid] SearchInput must be used inside DataGrid."),null;let{val_config:s}=d;return r(K.TextField,y(a({label:"\u691C\u7D22...",clearButton:!0,padding:["1/2","2/3"],rightIcon:r(K.RightIcon,{ssSphere:2,fontColor:"5.translucent",right:"2/3",children:r(v.Search,{})}),value:s.filter.keyword},t),{onUpdateValidValue:(...l)=>{t.onUpdateValidValue&&t.onUpdateValidValue(...l),d.remoteUpdate.searchKey(l[0])}}))},Info:o=>{let e=Y.catch(o.datagridID);if(!e)return null;let{val_config:t}=e,d=t.body.length,s=t.body.filter(l=>l.isFilterMatched).length,n=s.ratio(d)||0;return U(Ie,{verticalAlign:"baseline",gap:"1/2",fontSize:"1.mini",fontColor:"3.blur",children:[r(xe,{fontSize:"4.thirdTitle",fontColor:"theme",children:s.toLocaleString()}),"/ ",d.toLocaleString(),"\u4EF6 (",n,"%)"]})},Paging:o=>{let e=Y.catch(o.datagridID);if(!e)return null;let{val_config:t}=e,d=[];for(let n=0;n<t.paging.total;n++)d.push({value:n+1,label:(n+1).toString()});const s=n=>{let l=Math.min(Math.max(1,n),t.paging.total),i=a({},t);i.paging.current=l,e.remoteUpdate.paging(l)};return r(K.Select,{emptySelect:!1,padding:["1/3","2/3"],override:"force",gap:0,leftIcon:r(K.LeftIcon,{xcss:{left:2,pointerEvents:"all"},children:r(ee.Sub.S,{color:"cloud",fontColor:"4.thin",ssSquare:2.5,unitWidth:2,onClick:()=>{if(t.paging.current==1){s(t.paging.total);return}s(t.paging.current-1)},children:r(v.ChevronLeft,{})})}),rightIcon:r(K.RightIcon,{xcss:{right:2,pointerEvents:"all"},children:r(ee.Sub.S,{color:"cloud",fontColor:"4.thin",ssSquare:2.5,unitWidth:2,onClick:()=>{if(t.paging.current==t.paging.total){s(1);return}s(t.paging.current+1)},children:r(v.ChevronRight,{})})}),options:d.map(n=>({value:n.value||0,label:U(G.Left,{gap:"1/3",verticalAlign:"baseline",children:[n.label,U(ae,{fontColor:"4.thin",fontSize:"0.xs",children:["/ ",t.paging.total]})]})})),value:t.paging.current,onUpdateValidValue:n=>{s(n)}})},RowCount:o=>{let e=Y.catch(o.datagridID);if(!e)return null;let{val_config:t}=e,d=t.body.filter(i=>i.isFilterMatched).length,s=t.paging.rows,n=0,l=o.options.map(i=>(n|=+(i==s),{value:i,label:i.toString()}));return n||l.push({value:s,label:s.toString()}),r(G.Center,{gap:"1/2",children:r(K.Select,{emptySelect:!1,override:"force",padding:"1/3",paddingLeft:3,paddingRight:2,pickerStyles:{xcss:{minWidth:12*9}},pickerPosition:4,leftIcon:r(K.LeftIcon,{fontSize:"0.xs",fontColor:"4.thin",xcss:{left:6},children:"\u8868\u793A"}),rightIcon:r(K.RightIcon,{fontSize:"0.xs",fontColor:"4.thin",xcss:{right:6},children:"\u4EF6"}),value:t.paging.rows,options:l.toASC("value"),onUpdateValidValue:i=>{e.remoteUpdate.maxRow(Number(i))}})})}},w=Object.assign(we,ie);export{w as DataGrid,w as default,ne as onDefaultCellStyles};
1
+ import{b as a,c as y,d as A,e as se}from"../../chunk-C5N2D3ZX.js";import{Fragment as we,jsx as o,jsxs as U}from"react/jsx-runtime";import b,{useStore as ce,UUID as pe}from"jmini";import oe,{useState as me,useEffect as Z,useMemo as he}from"react";import{ExtractStyles as _,GenerateHTMLProps as Se,DragEffect as le,useRemote as Y}from"../../@utils";import{faArrowUp as Ce}from"@fortawesome/free-solid-svg-icons/faArrowUp";import{faUpDown as Re}from"@fortawesome/free-solid-svg-icons/faUpDown";import{Box as k,Flex as Ie,FAI as v,Span as xe}from"../../atoms";import{Literal as ae,Row as G,MarkerPen as ge}from"../../mols";import{Button as ee}from"../Button";import L from"../Input";import{TableClasses as Te}from"../../@styles/componentClasses";import{faGripVertical as ye}from"@fortawesome/free-solid-svg-icons/faGripVertical";import{Tips as ue}from"../Tips";const R={toSafetyData:r=>{var d,s,i;let{header:e=[]}=r,t={datagridID:r.datagridID||pe(),colLength:r.colLength||e.length||0,body:r.body||[],header:e,filter:{keyword:r.defaultSearchKey||"",current:[]},sort:{col:-1,dir:1},paging:{rows:r.maxRows||100,total:1,current:1},draggable:!!e.some(l=>l.draggable)};t.header.forEach((l,n)=>{b.isRecord(l)||(l={key:l})}),t.body.forEach((l,n)=>{var m;l.row_id=(m=l.row_id)!=null?m:n,l.isFilterMatched=!0,l.isVisible=!0,l.draggerIndex=n+1,l.searchKey="",e.forEach((I,K)=>{var c;let g=l[I.key];b.isNullish(g)||(b.isRecord(g)||(g={data:g}),g.sortKey=(c=g.sortKey)!=null?c:String(g.data),l.searchKey+=String(g.sortKey)+" ",l[I.key]=g)})});{let l=(d=e==null?void 0:e.filter(n=>n.defSort))==null?void 0:d[0];l&&(t.sort.col=(s=e.indexOf(l))!=null?s:-1,t.sort.dir=(i=l==null?void 0:l.sortable)!=null?i:1)}return t.draggable&&(t.filter.keyword="",t.sort.col=-1,t.sort.dir=0,t.header.forEach(l=>{l.sortable=0,l.filterable=!1})),R.updateRowMeta(t)},updateRowMeta:r=>{let e=a({},r);if(e.sort.col>=0&&e.sort.dir){let t=e.header[e.sort.col].key;e.sort.dir==1?e.body.toASC(t+".data"):e.body.toDESC(t+".data")}{let t=String(e.filter.keyword)||"";e.body.forEach(d=>{var i;if(d.isFilterMatched=!0,!t)return;let s=!!((i=String(d.searchKey))!=null&&i.match(new RegExp(t.escapeRegExChar(),"i")));d.isFilterMatched=s})}{let t=e.paging.rows;e.paging.total=Math.ceil(e.body.filter(l=>l.isFilterMatched).length/t);let d=t*(e.paging.current-1),s=d+t,i=0;e.body.forEach(l=>{l.isVisible=!1,l.isFilterMatched&&(l.isVisible=i>=d&&i<s,i++)})}return e.draggable&&e.body.toASC("draggerIndex"),e},index:r=>{var I,K,g;let[e,t]=me(()=>R.toSafetyData(r));const d=oe.useRef(!1);Z(()=>{if(e){if(!d.current){d.current=!0;return}t(R.toSafetyData(r))}},[he(()=>r.props,[r.props])]),Z(()=>{e&&(ce.set({["rows-"+e.datagridID]:e.body}),Y.bridge(e.datagridID,{val_config:e,remoteUpdate:{paging:c=>{e.draggable||t(p=>R.updateRowMeta(y(a({},p),{paging:y(a({},p.paging),{current:Math.max(1,Math.min(p.paging.total,c))})})))},maxRow:c=>{e.draggable||t(p=>R.updateRowMeta(y(a({},p),{paging:y(a({},p.paging),{rows:c,current:1})})))},searchKey:c=>{e.draggable||b.interval.once(()=>{t(p=>{let w=y(a({},p),{paging:y(a({},p.paging),{current:1}),filter:y(a({},p.filter),{keyword:String(c||"").trim()})});return R.updateRowMeta(w)})},300,"InputSearchTime")}}}))},[e]);const s=oe.useRef(!1);Z(()=>{if(e&&r.onSelected){if(!s.current){s.current=!0;return}r.onSelected(e.body.filter(c=>c.isSelected))}},[(I=e==null?void 0:e.body)==null?void 0:I.filter(c=>c.isSelected).length]);const i=oe.useRef(!1);Z(()=>{if(e&&r.onSorted){if(!i.current){i.current=!0;return}r.onSorted(e.sort.col,e.sort.dir)}},[(K=e==null?void 0:e.sort)==null?void 0:K.col,(g=e==null?void 0:e.sort)==null?void 0:g.dir]);let l={input:r,val_config:e,set_config:t},{className:n,style:m}=Se(r);return o(k,{className:n,style:m,children:o(D.Table,{className:Te("DataGrid"),borderRadius:"inherit",children:U(D.Body,{children:[o(R.Header,a({},l)),o(R.Body,a({},l)),o(R.Footer,a({},l))]})})})},Checker:r=>o(k,{onClick:e=>{e.stopPropagation()},children:o(L.Checker,y(a({wrapStyles:{display:"inlineBlock"},cellStyles:{gap:0}},r),{label:!1}))}),Header:r=>{let{input:e,val_config:t,set_config:d}=r;if(e.headerless)return null;let s="datagrid-dragger-"+t.datagridID,i=["datagrid",t.datagridID,""].join("-"),l=1+t.body.filter(n=>n.isVisible).length+ +!!e.footer;return o(le.DropArea,y(a({component:D.Row,id:i},e.rowStyles),{dragInfo:{type:s,id:i,idx:0,marker:"bottom"},children:t.header.map((n,m)=>{var W,q,$,Q,J;let[I,K]=_(n),j=K,{isTH:g,key:c,label:p,checkable:w,draggable:T,defSort:N,sortable:E,filterable:z,isHidden:O}=j,M=A(j,["isTH","key","label","checkable","draggable","defSort","sortable","filterable","isHidden"]);if(O)return null;let x={rowIdx:0,colIdx:m,topIdx:0,leftIdx:m,rightIdx:t.colLength-m-1,bottomIdx:l-1,isHeader:!0,isBody:!1,isFooter:!1},H=T,B=E!=0,S=m==t.sort.col,F=b.deepMerge(b.deepCopy(e.cellStyles),ne(x,{}),(W=e.cellStyles)==null?void 0:W.onHeader,!x.leftIdx&&((q=e.cellStyles)==null?void 0:q.onLeft),!x.rightIdx&&(($=e.cellStyles)==null?void 0:$.onRight),!x.topIdx&&((Q=e.cellStyles)==null?void 0:Q.onTop),!x.bottomIdx&&((J=e.cellStyles)==null?void 0:J.onBottom),I);e.onCellStyles&&(F=e.onCellStyles(x,F||{}));let P=[o(k,{flexSizing:0,children:p!=null?p:c},"data")];return B&&P.unshift(o(v,{fontSize:"1.mini",opacity:S?"max":"low",transition:"middle",xcss:{transform:S&&t.sort.dir==-1?"rotate(180deg)":"none"},icon:S?Ce:Re},"sort")),w=="left"&&P.unshift(o(R.Checker,{value:t.body.every(u=>u.isSelected),onUpdateValue:u=>{d(C=>{let f=a({},C);return f.body.forEach(h=>{h.isFilterMatched&&(h.isSelected=!!u)}),f})}},"check")),H&&P.unshift(o(ee.Clear.S,{ssSphere:2,fontColor:"theme",onMouseOver:u=>{ue.open(u.currentTarget,U(ae.Supplement,{children:[o(v,{icon:ye}),"\u30C9\u30E9\u30C3\u30B0\u3067\u5217\u306E\u9806\u756A\u3092\u5909\u66F4"]}),22)},onMouseLeave:u=>ue.abort(),onClick:u=>{u.stopPropagation()},children:o(v.QuestionCircle,{})},"drag")),w=="right"&&P.push(o(R.Checker,{value:t.body.every(u=>u.isSelected),onUpdateValue:u=>{d(C=>{let f=a({},C);return f.body.forEach(h=>{h.isFilterMatched&&(h.isSelected=!!u)}),f})}},"check")),o(D.Cell,y(a(a({isTH:!!g,ssPushable:!!E},_(F||{})[0]),M),{className:[e.cellClassName,M.className].join(" "),onClick:u=>{M.onClick&&M.onClick(u),e.onCellClick&&e.onCellClick(x,u),B&&d(C=>{let f=a({},C);return f.sort={col:m,dir:S?C.sort.dir*-1:E},R.updateRowMeta(f)})},children:o(G.Left,{gap:"1/3",children:P})}),m)})}))},Body:r=>{var l;let{input:e,val_config:t,set_config:d}=r,s=t.body.filter(n=>n.isVisible),i=+!e.headerless+s.length+ +!!e.footer;return U(we,{children:[!s.length&&o(D.Row,y(a({},e.rowStyles),{children:o(D.Cell,{colSpan:t.colLength,padding:1,children:(l=e.onNoRecordsRender)==null?void 0:l.call(e)})})),s.map((n,m)=>{let I=m;e.headerless||(I+=1);let K="datagrid-dragger-"+t.datagridID,g=["datagrid",t.datagridID,n.row_id].join("-");return o(le.DropArea,y(a({component:D.Row,id:g,ssPushable:!!e.onRowClick||!!n.onRowClick},e.rowStyles),{onClick:c=>{n.onRowClick&&n.onRowClick(c),e.onRowClick&&e.onRowClick(n,c)},dragInfo:{type:K,id:g,idx:n.draggerIndex,disabled:!t.draggable,marker:"bottom"},children:t.header.map((c,p)=>{var W,q,$,Q,J,u;let w=c.draggable,T=n[c.key];if(!T)return null;let[N,E]=_(T),j=E,{isTH:z,sortKey:O,data:M,label:x,onLabelRender:H}=j,B=A(j,["isTH","sortKey","data","label","onLabelRender"]),S={rowIdx:I,colIdx:p,topIdx:I,leftIdx:p,rightIdx:t.colLength-p-1,bottomIdx:i-I-1,isHeader:!1,isBody:!0,isFooter:!1},F=b.deepMerge(b.deepCopy(e.cellStyles),ne(S,{}),(W=e.cellStyles)==null?void 0:W.onBody,!S.leftIdx&&((q=e.cellStyles)==null?void 0:q.onLeft),!S.rightIdx&&(($=e.cellStyles)==null?void 0:$.onRight),!S.topIdx&&((Q=e.cellStyles)==null?void 0:Q.onTop),!S.bottomIdx&&((J=e.cellStyles)==null?void 0:J.onBottom),N);e.onCellStyles&&(F=e.onCellStyles(S,F||{}));let P=[o(k,{flexSizing:0,children:(u=H==null?void 0:H(M))!=null?u:ge(x!=null?x:String(M),t.filter.keyword)},"data")];return c.checkable=="left"&&P.unshift(o(R.Checker,{override:"force",value:!!n.isSelected,onUpdateValue:C=>{d(f=>y(a({},f),{body:f.body.map(h=>(h.row_id==n.row_id&&(h.isSelected=!!C),h))}))}},"check")),w&&P.unshift(o(ee.Clear.S,{tabIndex:-1,isRounded:!0,ssSphere:2.5,fontColor:"6.clear",onPointerDown:C=>{let f=b("#"+g)[0],h=f.cloneNode(!0);h.style.width=f.offsetWidth+"px",le.Start(K,{dragElement:h,startEvent:C,originId:g,horizontal:!1,allowPrevDataOnDropend:!1},de=>se(void 0,null,function*(){let te=m,V=Number(de.idx);if(b.isNullish(V)||V==-1||(V>te&&V--,te==V)||!de.end)return;let X=b.deepCopy(t.body||[]),fe=X.splice(te,1)[0];X.splice(V,0,fe),X.forEach((re,be)=>{re.draggerIndex=be+1}),e.onDragged&&e.onDragged(X),d(re=>y(a({},re),{body:X}))}))},children:o(G.Center,{gap:"1/4",children:o(v,{icon:ye})})},"drag")),c.checkable=="right"&&P.push(o(R.Checker,{override:"force",value:!!n.isSelected,onUpdateValue:C=>{d(f=>y(a({},f),{body:f.body.map(h=>(h.row_id==n.row_id&&(h.isSelected=!!C),h))}))}},"check")),o(D.Cell,y(a(a({isTH:!!z},_(F||{})[0]),B),{className:[e.cellClassName,B.className].join(" "),onClick:C=>{B.onClick&&B.onClick(C),e.onCellClick&&e.onCellClick(S,C)},children:o(G.Left,{gap:"1/3",children:P})}),p)})}),String(n.row_id))})]})},Footer:r=>{let{input:e,val_config:t,set_config:d}=r;if(!e.footer)return null;let s=+!e.headerless+t.body.filter(i=>i.isVisible).length+1;return o(D.Row,y(a({},e.rowStyles),{children:t.header.map((i,l)=>{var z,O,M,x,H,B;let n=e.footer[i.key];if(!n)return null;b.isRecord(n)||(n={data:n});let[m,I]=_(n),E=I,{isTH:K,data:g,label:c,onLabelRender:p}=E,w=A(E,["isTH","data","label","onLabelRender"]),T={rowIdx:s-1,colIdx:l,topIdx:s-1,leftIdx:l,rightIdx:t.colLength-l-1,bottomIdx:0,isHeader:!1,isBody:!1,isFooter:!0},N=b.deepMerge(b.deepCopy(e.cellStyles),ne(T,{}),(z=e.cellStyles)==null?void 0:z.onBody,!T.leftIdx&&((O=e.cellStyles)==null?void 0:O.onLeft),!T.rightIdx&&((M=e.cellStyles)==null?void 0:M.onRight),!T.topIdx&&((x=e.cellStyles)==null?void 0:x.onTop),!T.bottomIdx&&((H=e.cellStyles)==null?void 0:H.onBottom),m);return e.onCellStyles&&(N=e.onCellStyles(T,N||{})),o(D.Cell,y(a(a({isTH:!!K},_(N||{})[0]),w),{className:[e.cellClassName,w.className].join(" "),onClick:S=>{w.onClick&&w.onClick(S),e.onCellClick&&e.onCellClick(T,S)},children:o(k,{flexSizing:0,children:(B=p==null?void 0:p(g))!=null?B:ge(c!=null?c:String(g),t.filter.keyword)})}),l)})}))}},ne=(r,e)=>{let t=a({},e);return r.topIdx||(t.borderTop="unset"),r.bottomIdx||(t.borderBottom="unset"),r.rightIdx||(t.borderRight="unset"),r.leftIdx||(t.borderLeft="unset"),r.topIdx||(r.leftIdx||(t.borderTopLeftRadius="inherit"),r.rightIdx||(t.borderTopRightRadius="inherit")),r.bottomIdx||(r.leftIdx||(t.borderBottomLeftRadius="inherit"),r.rightIdx||(t.borderBottomRightRadius="inherit")),t},De=r=>(r=a({datagridID:pe(),tone:"border",colLength:0,maxRows:100,onNoRecordsRender:()=>o(G.Center,{children:o(ae.Supplement,{fontColor:"4.thin",children:"(\u30C7\u30FC\u30BF\u306A\u3057)"})})},r),r.rowStyles=a({backgroundColor:"layer.0"},r.rowStyles),r.cellStyles=a(y(a({},b.scope(()=>{if(!r.tone)return{};let e={};return b.isOneOf(r.tone,"border","border.horizontal")&&(e.borderBottom="2.normal"),b.isOneOf(r.tone,"border","border.vertical")&&(e.borderRight="2.normal"),e})),{padding:"1/3",transition:"short"}),r.cellStyles),r.tone&&(r=a({border:!0,borderRadius:"2.tone.secondary",backgroundColor:"layer.1"},r)),r.header=r.header||[],r.header.forEach((e,t)=>{var d;e.sortable=(d=e.sortable)!=null?d:1,e.checkable===!0&&(e.checkable="left")}),o(R.index,a({},r))),ie={getBodyRows:r=>ce.get("rows-"+r)||[],Table:r=>o(k,y(a({htmlTag:"table",borderRadius:"inherit"},r),{border:r.border})),Head:r=>o(k,a({htmlTag:"thead",borderRadius:"inherit"},r)),Body:r=>o(k,a({htmlTag:"tbody",borderRadius:"inherit"},r)),Row:r=>o(k,a({htmlTag:"tr",borderRadius:"inherit"},r)),TH:r=>o(k,a({htmlTag:"th"},r)),TD:r=>o(k,a({htmlTag:"td"},r)),Cell:r=>{let d=r,{isTH:e}=d,t=A(d,["isTH"]);return e?o(ie.TH,a({},t)):o(ie.TD,a({},t))},RightIndicator:{data:"",label:o(G.Right,{children:o(v.AngleRight,{fontColor:"theme",fontSize:"3.paragraph"})})},SearchInput:r=>{let i=r,{datagridID:e}=i,t=A(i,["datagridID"]),d=Y.catch(r.datagridID);if(!d)return console.warn("[DataGrid] SearchInput must be used inside DataGrid."),null;let{val_config:s}=d;return o(L.TextField,y(a({label:"\u691C\u7D22...",clearButton:!0,padding:["1/2","2/3"],rightIcon:o(L.RightIcon,{ssSphere:2,fontColor:"5.translucent",right:"2/3",children:o(v.Search,{})}),value:s.filter.keyword},t),{onUpdateValidValue:(...l)=>{t.onUpdateValidValue&&t.onUpdateValidValue(...l),d.remoteUpdate.searchKey(l[0])}}))},Info:r=>{let e=Y.catch(r.datagridID);if(!e)return null;let{val_config:t}=e,d=t.body.length,s=t.body.filter(l=>l.isFilterMatched).length,i=s.ratio(d)||0;return U(Ie,{verticalAlign:"baseline",gap:"1/2",fontSize:"1.mini",fontColor:"3.blur",children:[o(xe,{fontSize:"4.thirdTitle",fontColor:"theme",children:s.toLocaleString()}),"/ ",d.toLocaleString(),"\u4EF6 (",i,"%)"]})},Paging:r=>{let e=Y.catch(r.datagridID);if(!e)return null;let{val_config:t}=e,d=[];for(let i=0;i<t.paging.total;i++)d.push({value:i+1,label:(i+1).toString()});const s=i=>{let l=Math.min(Math.max(1,i),t.paging.total),n=a({},t);n.paging.current=l,e.remoteUpdate.paging(l)};return o(L.Select,{emptySelect:!1,padding:["1/3","2/3"],override:"force",gap:0,leftIcon:o(L.LeftIcon,{xcss:{left:2,pointerEvents:"all"},children:o(ee.Sub.S,{color:"cloud",fontColor:"4.thin",ssSquare:2.5,unitWidth:2,onClick:()=>{if(t.paging.current==1){s(t.paging.total);return}s(t.paging.current-1)},children:o(v.ChevronLeft,{})})}),rightIcon:o(L.RightIcon,{xcss:{right:2,pointerEvents:"all"},children:o(ee.Sub.S,{color:"cloud",fontColor:"4.thin",ssSquare:2.5,unitWidth:2,onClick:()=>{if(t.paging.current==t.paging.total){s(1);return}s(t.paging.current+1)},children:o(v.ChevronRight,{})})}),options:d.map(i=>({value:i.value||0,label:U(G.Left,{gap:"1/3",verticalAlign:"baseline",children:[i.label,U(ae,{fontColor:"4.thin",fontSize:"0.xs",children:["/ ",t.paging.total]})]})})),value:t.paging.current,onUpdateValidValue:i=>{s(i)}})},RowCount:r=>{let e=Y.catch(r.datagridID);if(!e)return null;let{val_config:t}=e,d=t.body.filter(n=>n.isFilterMatched).length,s=t.paging.rows,i=0,l=r.options.map(n=>(i|=+(n==s),{value:n,label:n.toString()}));return i||l.push({value:s,label:s.toString()}),o(G.Center,{gap:"1/2",children:o(L.Select,{emptySelect:!1,override:"force",padding:"1/3",paddingLeft:3,paddingRight:2,pickerStyles:{xcss:{minWidth:12*9}},pickerPosition:4,leftIcon:o(L.LeftIcon,{fontSize:"0.xs",fontColor:"4.thin",xcss:{left:6},children:"\u8868\u793A"}),rightIcon:o(L.RightIcon,{fontSize:"0.xs",fontColor:"4.thin",xcss:{right:6},children:"\u4EF6"}),value:t.paging.rows,options:l.toASC("value"),onUpdateValidValue:n=>{e.remoteUpdate.maxRow(Number(n))}})})}},D=Object.assign(De,ie);export{D as DataGrid,D as default,ne as onDefaultCellStyles};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amotify",
3
- "version": "0.2.285",
3
+ "version": "0.2.287",
4
4
  "description": "UI Component for React,NextJS,esbuild",
5
5
  "scripts": {
6
6
  "start": "run-p clean build:*",