amotify 0.3.12 → 0.3.14

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 Q,e as be}from"../../chunk-C5N2D3ZX.js";import{Fragment as Be,jsx as l,jsxs as q}from"react/jsx-runtime";import p,{useStore as ne,UUID as ge}from"jmini";import me,{useState as Ie,useEffect as se}from"react";import{ExtractStyles as X,GenerateHTMLProps as xe,dragEffect as ye,useRemote as ie}from"../../@utils";import{faArrowUp as Te}from"@fortawesome/free-solid-svg-icons/faArrowUp";import{faUpDown as De}from"@fortawesome/free-solid-svg-icons/faUpDown";import{Box as k,Flex as we,FAI as G,Span as ke}from"../../atoms";import{Literal as pe,Row as W,MarkerPen as he}from"../../mols";import{Button as ce}from"../Button";import E from"../Input";import{TableClasses as Ke}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 m,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=(m=d.sortKey)!=null?m: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||ge(),sessionID:ge(),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.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,K,H,I;let[e,r]=Ie(()=>f.toSafetyData(t));se(()=>{ne.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]),se(()=>{ne.set({["rows-"+e.datagridID]:e.body}),ie.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=>{p.interval.once(()=>{r(u=>{let D=y(n({},u),{paging:y(n({},u.paging),{current:1}),filter:y(n({},u.filter),{keyword:String(g||"").trim()})});return f.updateRowMeta(D,t)})},300,"InputSearchTime")}}})},[e]);const o=me.useRef(!1);se(()=>{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);se(()=>{if(t.onSorted){if(!i.current){i.current=!0;return}t.onSorted(e.sort.col,e.sort.dir)}},[(K=e==null?void 0:e.sort)==null?void 0:K.col,(H=e==null?void 0:e.sort)==null?void 0:H.dir]);let a={input:t,val_config:e,set_config:r},{className:c,style:d}=xe(t),m=(I=t.colLength)!=null?I:t.header.length;return l(k,{className:c,style:d,children:l(T.Table,{className:Ke("DataGrid"),borderRadius:"inherit",children:q(T.Body,{children:[l(f.Header,n({},a)),l(f.Body,n({},a)),l(f.Footer,n({},a))]})},[m,...t.header.map(g=>g.key),e.sessionID].join("."))})},Checker:t=>l(k,{flexCenter:!0,onClick:e=>{e.stopPropagation()},children:l(E.Checker,y(n({wrapStyles:{display:"inlineBlock"},cellStyles:{gap:0}},t),{label:!1}))}),Header:t=>{var m,s,K,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(I=>I.isVisible).length+ +!!e.footer,d=(m=e.colLength)!=null?m:e.header.length;return l(ye.DropArea,y(n({jsxElement:T.Row,id:a},e.rowStyles),{dragInfo:{type:i,id:String(((H=(K=(s=r.body)==null?void 0:s.filter(I=>I.isFilterMatched))==null?void 0:K[0])==null?void 0:H.draggerIndex)||0),marker:"bottom"},children:e.header.toASC("columnIdx").map((I,g)=>{var re,oe,le,w,O,F;let[u,D]=X(I),te=D,{isTH:h,key:S,label:M,onLabelRender:B,columnIdx:Y,checkable:_,draggable:$,defSort:de,sortable:P,filterable:N,isHidden:v}=te,x=Q(te,["isTH","key","label","onLabelRender","columnIdx","checkable","draggable","defSort","sortable","filterable","isHidden"]);if(v)return null;let C={rowIdx:0,colIdx:g,topIdx:0,leftIdx:g,rightIdx:d-g-1,bottomIdx:c-1,isHeader:!0,isBody:!1,isFooter:!1},Z=$,A=P!=0,V=g==r.sort.col,J=p.deepMerge(p.deepCopy(e.cellStyles),fe(C,{}),(re=e.cellStyles)==null?void 0:re.onHeader,!C.leftIdx&&((oe=e.cellStyles)==null?void 0:oe.onLeft),!C.rightIdx&&((le=e.cellStyles)==null?void 0:le.onRight),!C.topIdx&&((w=e.cellStyles)==null?void 0:w.onTop),!C.bottomIdx&&((O=e.cellStyles)==null?void 0:O.onBottom),u);e.onCellStyles&&(J=e.onCellStyles(C,J||{}));let U=[],ee=[];if(Z&&U.push(l(ce.Clear.S,{ssSphere:2.5,fontColor:"theme",onMouseOver:b=>{Ce.open(b.currentTarget,q(pe.Mini,{children:[l(G,{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(G.QuestionCircle,{})},"drag")),_){let b=l(f.Checker,{value:r.body.every(R=>R.isSelected),onUpdateValue:R=>{o(L=>{let j=n({},L);return j.body.forEach(ae=>{ae.isFilterMatched&&(ae.onCheckerDisabled||(ae.isSelected=!!R))}),j})}},"check");_=="left"?U.push(b):ee.push(b)}return A&&U.push(l(G,{fontSize:"1.mini",fontColor:"theme",opacity:V?"max":"low",transition:"middle",xcss:{transform:V&&r.sort.dir==-1?"rotate(180deg)":"none"},icon:V?Te:De},"sort")),l(T.Cell,y(n(n({isTH:!!h,ssPushable:!!P},X(J||{})[0]),x),{className:[e.cellClassName,x.className].join(" "),onClick:b=>{x.onClick&&x.onClick(b),e.onCellClick&&e.onCellClick(C,b),A&&o(R=>{let L=n({},R);return L.sort={col:g,dir:V?R.sort.dir*-1:P},f.updateRowMeta(L,e)})},children:q(W.Left,{gap:"1/3",height:1,children:[U,(F=B==null?void 0:B(S))!=null?F:l(k,{flexSizing:0,children:M!=null?M:S}),ee]})}),[g,I.key].join("/"))})}))},Body:t=>{var d,m;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(Be,{children:i.map((s,K)=>{let{onCheckerDisabled:H,onDraggerDisabled:I}=s,g=K;e.headerless||(g+=1);let u="datagrid-dragger-"+r.datagridID,D=["datagrid",r.datagridID,s.row_id].join("-");return l(ye.DropArea,y(n({jsxElement:T.Row,id:D,ssPushable:!!e.onRowClick||!!s.onRowClick},e.rowStyles),{onClick:h=>{s.onRowClick&&s.onRowClick(h),e.onRowClick&&e.onRowClick(s,h)},dragInfo:{type:u,id:String(s.row_id||""),disabled:!r.draggable,marker:"bottom"},children:e.header.toASC("columnIdx").map((h,S)=>{var U,ee,te,re,oe,le;let M=h.draggable,B=s[h.key];if(!B)return null;let[Y,_]=X(B),J=_,{isTH:$,sortKey:de,data:P,label:N,onLabelRender:v}=J,x=Q(J,["isTH","sortKey","data","label","onLabelRender"]),C={rowIdx:g,colIdx:S,topIdx:g,leftIdx:S,rightIdx:c-S-1,bottomIdx:a-g-1,isHeader:!1,isBody:!0,isFooter:!1},Z=p.deepMerge(p.deepCopy(e.cellStyles),fe(C,{}),(U=e.cellStyles)==null?void 0:U.onBody,!C.leftIdx&&((ee=e.cellStyles)==null?void 0:ee.onLeft),!C.rightIdx&&((te=e.cellStyles)==null?void 0:te.onRight),!C.topIdx&&((re=e.cellStyles)==null?void 0:re.onTop),!C.bottomIdx&&((oe=e.cellStyles)==null?void 0:oe.onBottom),Y);e.onCellStyles&&(Z=e.onCellStyles(C,Z||{}));let A=[],V=[];return p.scope(()=>{if(M){if(s.onDraggerDisabled){A.push(s.onDraggerDisabled());return}A.push(l(ce.Clear.S,{tabIndex:-1,isRounded:!0,ssSphere:2.5,fontColor:"6.clear",onPointerDown:w=>{let O=p("#"+D)[0],F=O.cloneNode(!0);F.style.width=O.offsetWidth+"px",ye.Start(u,{dragElement:F,startEvent:w,originId:D,horizontal:!1},b=>be(void 0,null,function*(){if(!b.end||!b.onDropArea)return;let R=p.deepCopy(r.body),L=R.findIndex(z=>z.row_id==s.row_id);if(L==-1)return;let j=R.findIndex(z=>z.row_id==b.id);if(j<L&&j++,L==j)return;let ae=R.splice(L,1)[0];R.splice(j,0,ae),R.forEach((z,Re)=>{z.draggerIndex=Re}),e.onDragged&&e.onDragged(R),o(z=>y(n({},z),{body:R}))}))},children:l(W.Center,{gap:"1/4",children:l(G,{icon:Se})})},"drag"))}}),p.scope(()=>{if(!h.checkable)return;let w=l(f.Checker,{override:"force",value:!!s.isSelected,onUpdateValue:O=>{o(F=>y(n({},F),{body:F.body.map(b=>(b.row_id==s.row_id&&(b.isSelected=!!O),b))}))}},"check");s.onCheckerDisabled&&(w=s.onCheckerDisabled()),h.checkable=="left"?A.push(w):V.push(w)}),l(T.Cell,y(n(n({isTH:!!$},X(Z||{})[0]),x),{className:[e.cellClassName,x.className].join(" "),onClick:w=>{x.onClick&&x.onClick(w),e.onCellClick&&e.onCellClick(C,w)},children:q(W.Left,{gap:"1/3",height:1,children:[A,(le=v==null?void 0:v(P))!=null?le:l(k,{flexSizing:0,children:he(N!=null?N:String(P),r.filter.keyword)}),V]})}),[S,h.key].join("/"))})}),[s.row_id,g].join("."))})}):l(T.Row,y(n({},e.rowStyles),{children:l(T.Cell,{colSpan:c,padding:1,children:(m=e.onNoRecordsRender)==null?void 0:m.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,m)=>{var Y,_,$,de,P,N,v;let s=e.footer[d.key];if(!s)return null;p.isRecord(s)||(s={data:s});let[K,H]=X(s),B=H,{isTH:I,data:g,label:u,onLabelRender:D}=B,h=Q(B,["isTH","data","label","onLabelRender"]),S={rowIdx:i-1,colIdx:m,topIdx:i-1,leftIdx:m,rightIdx:a-m-1,bottomIdx:0,isHeader:!1,isBody:!1,isFooter:!0},M=p.deepMerge(p.deepCopy(e.cellStyles),fe(S,{}),(Y=e.cellStyles)==null?void 0:Y.onBody,(_=e.cellStyles)==null?void 0:_.onFooter,!S.leftIdx&&(($=e.cellStyles)==null?void 0:$.onLeft),!S.rightIdx&&((de=e.cellStyles)==null?void 0:de.onRight),!S.topIdx&&((P=e.cellStyles)==null?void 0:P.onTop),!S.bottomIdx&&((N=e.cellStyles)==null?void 0:N.onBottom),K);return e.onCellStyles&&(M=e.onCellStyles(S,M||{})),l(T.Cell,y(n(n({isTH:!!I},X(M||{})[0]),h),{className:[e.cellClassName,h.className].join(" "),onClick:x=>{h.onClick&&h.onClick(x),e.onCellClick&&e.onCellClick(S,x)},children:l(k,{flexSizing:0,children:(v=D==null?void 0:D(g))!=null?v:he(u!=null?u:String(g),r.filter.keyword)})}),[m,d.key].join("/"))})}))}},fe=(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},Me=t=>(t=n({datagridID:ge(),tone:"border",maxRows:100,onNoRecordsRender:()=>l(W.Center,{children:l(pe.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=>ne.get("rows-"+t)||[],toSafetyBody:f.toSafetyBody,reset:t=>{var e;(e=ne.get("reset-"+t))==null||e()},refreshBody:t=>{var e;(e=ne.get("refresh-"+t))==null||e()},reservedKeys:f.reservedKeys,Table:t=>l(k,y(n({htmlTag:"table",borderRadius:"inherit"},t),{border:t.border})),Head:t=>l(k,n({htmlTag:"thead",borderRadius:"inherit"},t)),Body:t=>l(k,n({htmlTag:"tbody",borderRadius:"inherit"},t)),Row:t=>l(k,n({htmlTag:"tr",borderRadius:"inherit"},t)),TH:t=>l(k,n({htmlTag:"th"},t)),TD:t=>l(k,n({htmlTag:"td"},t)),Cell:t=>{let o=t,{isTH:e}=o,r=Q(o,["isTH"]);return e?l(ue.TH,n({},r)):l(ue.TD,n({},r))},RightIndicator:{data:"",label:l(W.Right,{children:l(G.AngleRight,{fontColor:"theme",fontSize:"3.paragraph"})})},SearchInput:t=>{let a=t,{datagridID:e}=a,r=Q(a,["datagridID"]),o=ie.catch(t.datagridID);if(!o)return console.warn("[DataGrid] SearchInput must be used inside DataGrid."),null;let{val_config:i}=o;return l(E.TextField,y(n({label:"\u691C\u7D22...",clearButton:!0,padding:["1/2","2/3"],rightIcon:l(E.RightIcon,{ssSphere:2,fontColor:"5.translucent",right:"2/3",children:l(G.Search,{})}),value:i.filter.keyword},r),{onUpdateValidValue:(...c)=>{r.onUpdateValidValue&&r.onUpdateValidValue(...c),o.remoteUpdate.searchKey(c[0])}}))},Info:t=>{let e=ie.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 q(we,{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=ie.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(E.Select,{emptySelect:!1,padding:["1/3","2/3"],override:"force",gap:0,leftIcon:l(E.LeftIcon,{xcss:{left:2,pointerEvents:"all"},children:l(ce.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(G.ChevronLeft,{})})}),rightIcon:l(E.RightIcon,{xcss:{right:2,pointerEvents:"all"},children:l(ce.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(G.ChevronRight,{})})}),options:o.map(a=>({value:a.value||0,label:q(W.Left,{gap:"1/3",verticalAlign:"baseline",children:[a.label,q(pe.Micro,{fontColor:"4.thin",children:["/ ",r.paging.total]})]})})),value:r.paging.current,onUpdateValidValue:a=>{i(a)}})},RowCount:t=>{let e=ie.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(W.Center,{gap:"1/2",children:l(E.Select,{emptySelect:!1,override:"force",padding:"1/3",paddingLeft:3,paddingRight:2,pickerStyles:{xcss:{minWidth:12*9}},pickerPosition:4,leftIcon:l(E.LeftIcon,{fontSize:"0.xs",fontColor:"4.thin",xcss:{left:6},children:"\u8868\u793A"}),rightIcon:l(E.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(Me,ue);export{T as DataGrid,T as default,fe as onDefaultCellStyles};
1
+ import{b as n,c as y,d as Q,e as be}from"../../chunk-C5N2D3ZX.js";import{Fragment as Be,jsx as l,jsxs as q}from"react/jsx-runtime";import p,{useStore as ne,UUID as ge}from"jmini";import me,{useState as Ie,useEffect as se}from"react";import{ExtractStyles as X,GenerateHTMLProps as xe,dragEffect as ye,useRemote as ie}from"../../@utils";import{faArrowUp as Te}from"@fortawesome/free-solid-svg-icons/faArrowUp";import{faUpDown as De}from"@fortawesome/free-solid-svg-icons/faUpDown";import{Box as k,Flex as we,FAI as G,Span as ke}from"../../atoms";import{Literal as pe,Row as W,MarkerPen as he}from"../../mols";import{Button as ce}from"../Button";import E from"../Input";import{TableClasses as Ke}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 m,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=(m=d.sortKey)!=null?m: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||ge(),sessionID:ge(),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.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,K,H,I;let[e,r]=Ie(()=>f.toSafetyData(t));se(()=>{ne.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]),se(()=>{ne.set({["rows-"+e.datagridID]:e.body}),ie.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=>{p.interval.once(()=>{r(u=>{let D=y(n({},u),{paging:y(n({},u.paging),{current:1}),filter:y(n({},u.filter),{keyword:String(g||"").trim()})});return f.updateRowMeta(D,t)})},300,"InputSearchTime")}}})},[e]);const o=me.useRef(!1);se(()=>{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);se(()=>{if(t.onSorted){if(!i.current){i.current=!0;return}t.onSorted(e.sort.col,e.sort.dir)}},[(K=e==null?void 0:e.sort)==null?void 0:K.col,(H=e==null?void 0:e.sort)==null?void 0:H.dir]);let a={input:t,val_config:e,set_config:r},{className:c,style:d}=xe(t),m=(I=t.colLength)!=null?I:t.header.length;return l(k,{className:c,style:d,children:l(T.Table,{className:Ke("DataGrid"),borderRadius:"inherit",children:q(T.Body,{children:[l(f.Header,n({},a)),l(f.Body,n({},a)),l(f.Footer,n({},a))]})},[m,...t.header.map(g=>g.key),e.sessionID].join("."))})},Checker:t=>l(k,{flexCenter:!0,onClick:e=>{e.stopPropagation()},children:l(E.Checker,y(n({wrapStyles:{display:"inlineBlock"},cellStyles:{gap:0}},t),{label:!1}))}),Header:t=>{var m,s,K,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(I=>I.isVisible).length+ +!!e.footer,d=(m=e.colLength)!=null?m:e.header.length;return l(ye.DropArea,y(n({jsxElement:T.Row,id:a},e.rowStyles),{dragInfo:{type:i,id:String(((H=(K=(s=r.body)==null?void 0:s.filter(I=>I.isFilterMatched))==null?void 0:K[0])==null?void 0:H.draggerIndex)||0),marker:"bottom"},children:e.header.toASC("columnIdx").map((I,g)=>{var re,oe,le,w,O,F;let[u,D]=X(I),te=D,{isTH:h,key:S,label:M,onLabelRender:B,columnIdx:Y,checkable:_,draggable:$,defSort:de,sortable:P,filterable:N,isHidden:v}=te,x=Q(te,["isTH","key","label","onLabelRender","columnIdx","checkable","draggable","defSort","sortable","filterable","isHidden"]);if(v)return null;let C={rowIdx:0,colIdx:g,topIdx:0,leftIdx:g,rightIdx:d-g-1,bottomIdx:c-1,isHeader:!0,isBody:!1,isFooter:!1},Z=$,A=P!=0,V=g==r.sort.col,J=p.deepMerge(p.deepCopy(e.cellStyles),fe(C,{}),(re=e.cellStyles)==null?void 0:re.onHeader,!C.leftIdx&&((oe=e.cellStyles)==null?void 0:oe.onLeft),!C.rightIdx&&((le=e.cellStyles)==null?void 0:le.onRight),!C.topIdx&&((w=e.cellStyles)==null?void 0:w.onTop),!C.bottomIdx&&((O=e.cellStyles)==null?void 0:O.onBottom),u);e.onCellStyles&&(J=e.onCellStyles(C,J||{}));let U=[],ee=[];if(Z&&U.push(l(ce.Clear.S,{ssSphere:2.5,fontColor:"theme",onMouseOver:b=>{Ce.open(b.currentTarget,q(pe.Mini,{children:[l(G,{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(G.QuestionCircle,{})},"drag")),_){let b=l(f.Checker,{value:r.body.every(R=>R.isSelected),onUpdateValue:R=>{o(L=>{let j=n({},L);return j.body.forEach(ae=>{ae.isFilterMatched&&(ae.onCheckerDisabled||(ae.isSelected=!!R))}),j})}},"check");_=="left"?U.push(b):ee.push(b)}return A&&U.push(l(G,{fontSize:"1.mini",fontColor:"theme",opacity:V?"max":"low",transition:"middle",xcss:{transform:V&&r.sort.dir==-1?"rotate(180deg)":"none"},icon:V?Te:De},"sort")),l(T.Cell,y(n(n({isTH:!!h,ssPushable:!!P},X(J||{})[0]),x),{className:[e.cellClassName,x.className].join(" "),onClick:b=>{x.onClick&&x.onClick(b),e.onCellClick&&e.onCellClick(C,b),A&&o(R=>{let L=n({},R);return L.sort={col:g,dir:V?R.sort.dir*-1:P},f.updateRowMeta(L,e)})},children:q(W.Left,{gap:"1/3",height:1,children:[U,(F=B==null?void 0:B(S))!=null?F:l(k,{flexSizing:0,children:M!=null?M:S}),ee]})}),[g,I.key].join("/"))})}))},Body:t=>{var d,m;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(Be,{children:i.map((s,K)=>{let{onCheckerDisabled:H,onDraggerDisabled:I}=s,g=K;e.headerless||(g+=1);let u="datagrid-dragger-"+r.datagridID,D=["datagrid",r.datagridID,s.row_id].join("-");return l(ye.DropArea,y(n({jsxElement:T.Row,id:D,ssPushable:!!e.onRowClick||!!s.onRowClick},e.rowStyles),{onClick:h=>{s.onRowClick&&s.onRowClick(h),e.onRowClick&&e.onRowClick(s,h)},dragInfo:{type:u,id:String(s.row_id||""),disabled:!r.draggable,marker:"bottom"},children:e.header.toASC("columnIdx").map((h,S)=>{var U,ee,te,re,oe,le;let M=h.draggable,B=s[h.key];if(!B)return null;let[Y,_]=X(B),J=_,{isTH:$,sortKey:de,data:P,label:N,onLabelRender:v}=J,x=Q(J,["isTH","sortKey","data","label","onLabelRender"]),C={rowIdx:g,colIdx:S,topIdx:g,leftIdx:S,rightIdx:c-S-1,bottomIdx:a-g-1,isHeader:!1,isBody:!0,isFooter:!1},Z=p.deepMerge(p.deepCopy(e.cellStyles),fe(C,{}),(U=e.cellStyles)==null?void 0:U.onBody,!C.leftIdx&&((ee=e.cellStyles)==null?void 0:ee.onLeft),!C.rightIdx&&((te=e.cellStyles)==null?void 0:te.onRight),!C.topIdx&&((re=e.cellStyles)==null?void 0:re.onTop),!C.bottomIdx&&((oe=e.cellStyles)==null?void 0:oe.onBottom),Y);e.onCellStyles&&(Z=e.onCellStyles(C,Z||{}));let A=[],V=[];return p.scope(()=>{if(M){if(s.onDraggerDisabled){A.push(s.onDraggerDisabled());return}A.push(l(ce.Clear.S,{tabIndex:-1,isRounded:!0,ssSphere:2.5,fontColor:"6.clear",onPointerDown:w=>{let O=p("#"+D)[0],F=O.cloneNode(!0);F.style.width=O.offsetWidth+"px",ye.Start(u,{dragElement:F,startEvent:w,originId:D,horizontal:!1},b=>be(void 0,null,function*(){if(!b.end||!b.onDropArea)return;let R=[...r.body],L=R.findIndex(z=>z.row_id==s.row_id);if(L==-1)return;let j=R.findIndex(z=>z.row_id==b.id);if(j<L&&j++,L==j)return;let ae=R.splice(L,1)[0];R.splice(j,0,ae),R.forEach((z,Re)=>{z.draggerIndex=Re}),e.onDragged&&e.onDragged(R),o(z=>y(n({},z),{body:R}))}))},children:l(W.Center,{gap:"1/4",children:l(G,{icon:Se})})},"drag"))}}),p.scope(()=>{if(!h.checkable)return;let w=l(f.Checker,{override:"force",value:!!s.isSelected,onUpdateValue:O=>{o(F=>y(n({},F),{body:F.body.map(b=>(b.row_id==s.row_id&&(b.isSelected=!!O),b))}))}},"check");s.onCheckerDisabled&&(w=s.onCheckerDisabled()),h.checkable=="left"?A.push(w):V.push(w)}),l(T.Cell,y(n(n({isTH:!!$},X(Z||{})[0]),x),{className:[e.cellClassName,x.className].join(" "),onClick:w=>{x.onClick&&x.onClick(w),e.onCellClick&&e.onCellClick(C,w)},children:q(W.Left,{gap:"1/3",height:1,children:[A,(le=v==null?void 0:v(P))!=null?le:l(k,{flexSizing:0,children:he(N!=null?N:String(P),r.filter.keyword)}),V]})}),[S,h.key].join("/"))})}),[s.row_id,g].join("."))})}):l(T.Row,y(n({},e.rowStyles),{children:l(T.Cell,{colSpan:c,padding:1,children:(m=e.onNoRecordsRender)==null?void 0:m.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,m)=>{var Y,_,$,de,P,N,v;let s=e.footer[d.key];if(!s)return null;p.isRecord(s)||(s={data:s});let[K,H]=X(s),B=H,{isTH:I,data:g,label:u,onLabelRender:D}=B,h=Q(B,["isTH","data","label","onLabelRender"]),S={rowIdx:i-1,colIdx:m,topIdx:i-1,leftIdx:m,rightIdx:a-m-1,bottomIdx:0,isHeader:!1,isBody:!1,isFooter:!0},M=p.deepMerge(p.deepCopy(e.cellStyles),fe(S,{}),(Y=e.cellStyles)==null?void 0:Y.onBody,(_=e.cellStyles)==null?void 0:_.onFooter,!S.leftIdx&&(($=e.cellStyles)==null?void 0:$.onLeft),!S.rightIdx&&((de=e.cellStyles)==null?void 0:de.onRight),!S.topIdx&&((P=e.cellStyles)==null?void 0:P.onTop),!S.bottomIdx&&((N=e.cellStyles)==null?void 0:N.onBottom),K);return e.onCellStyles&&(M=e.onCellStyles(S,M||{})),l(T.Cell,y(n(n({isTH:!!I},X(M||{})[0]),h),{className:[e.cellClassName,h.className].join(" "),onClick:x=>{h.onClick&&h.onClick(x),e.onCellClick&&e.onCellClick(S,x)},children:l(k,{flexSizing:0,children:(v=D==null?void 0:D(g))!=null?v:he(u!=null?u:String(g),r.filter.keyword)})}),[m,d.key].join("/"))})}))}},fe=(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},Me=t=>(t=n({datagridID:ge(),tone:"border",maxRows:100,onNoRecordsRender:()=>l(W.Center,{children:l(pe.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=>ne.get("rows-"+t)||[],toSafetyBody:f.toSafetyBody,reset:t=>{var e;(e=ne.get("reset-"+t))==null||e()},refreshBody:t=>{var e;(e=ne.get("refresh-"+t))==null||e()},reservedKeys:f.reservedKeys,Table:t=>l(k,y(n({htmlTag:"table",borderRadius:"inherit"},t),{border:t.border})),Head:t=>l(k,n({htmlTag:"thead",borderRadius:"inherit"},t)),Body:t=>l(k,n({htmlTag:"tbody",borderRadius:"inherit"},t)),Row:t=>l(k,n({htmlTag:"tr",borderRadius:"inherit"},t)),TH:t=>l(k,n({htmlTag:"th"},t)),TD:t=>l(k,n({htmlTag:"td"},t)),Cell:t=>{let o=t,{isTH:e}=o,r=Q(o,["isTH"]);return e?l(ue.TH,n({},r)):l(ue.TD,n({},r))},RightIndicator:{data:"",label:l(W.Right,{children:l(G.AngleRight,{fontColor:"theme",fontSize:"3.paragraph"})})},SearchInput:t=>{let a=t,{datagridID:e}=a,r=Q(a,["datagridID"]),o=ie.catch(t.datagridID);if(!o)return console.warn("[DataGrid] SearchInput must be used inside DataGrid."),null;let{val_config:i}=o;return l(E.TextField,y(n({label:"\u691C\u7D22...",clearButton:!0,padding:["1/2","2/3"],rightIcon:l(E.RightIcon,{ssSphere:2,fontColor:"5.translucent",right:"2/3",children:l(G.Search,{})}),value:i.filter.keyword},r),{onUpdateValidValue:(...c)=>{r.onUpdateValidValue&&r.onUpdateValidValue(...c),o.remoteUpdate.searchKey(c[0])}}))},Info:t=>{let e=ie.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 q(we,{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=ie.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(E.Select,{emptySelect:!1,padding:["1/3","2/3"],override:"force",gap:0,leftIcon:l(E.LeftIcon,{xcss:{left:2,pointerEvents:"all"},children:l(ce.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(G.ChevronLeft,{})})}),rightIcon:l(E.RightIcon,{xcss:{right:2,pointerEvents:"all"},children:l(ce.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(G.ChevronRight,{})})}),options:o.map(a=>({value:a.value||0,label:q(W.Left,{gap:"1/3",verticalAlign:"baseline",children:[a.label,q(pe.Micro,{fontColor:"4.thin",children:["/ ",r.paging.total]})]})})),value:r.paging.current,onUpdateValidValue:a=>{i(a)}})},RowCount:t=>{let e=ie.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(W.Center,{gap:"1/2",children:l(E.Select,{emptySelect:!1,override:"force",padding:"1/3",paddingLeft:3,paddingRight:2,pickerStyles:{xcss:{minWidth:12*9}},pickerPosition:4,leftIcon:l(E.LeftIcon,{fontSize:"0.xs",fontColor:"4.thin",xcss:{left:6},children:"\u8868\u793A"}),rightIcon:l(E.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(Me,ue);export{T as DataGrid,T as default,fe as onDefaultCellStyles};
@@ -1 +1 @@
1
- import{b as l,c as m,d as Z,e as H}from"../../chunk-C5N2D3ZX.js";import{Fragment as N,jsx as s,jsxs as V}from"react/jsx-runtime";import{useState as A,useEffect as P,useRef as ne}from"react";import a,{UUID as v}from"jmini";import{Config as oe}from"../../@utils";import{Box as X,Span as ie,FAI as B,Column as q}from"../../atoms";import{Literal as K,Row as M}from"../../mols";import{Button as $}from"../Button";import{Loader as le}from"../Loader";import{Sheet as ae}from"../Sheet";import{OptionalInputWrapper as re,BoxWrapper as se,CoreEffects as z,DefaultBoxishStyles as ue}from"./core";import{InputAutocompleteClasses as L}from"../../@styles/componentClasses";import{InputLabel as ce}from"./Label";import{RightIcon as G}from".";function pe(t){let{value:e,states:i}=t,{required:r,options:f,min:S,max:n}=i;S=S||0,n=n||65535;let o=[],c=e.filter(h=>h!==null).length;return r&&(c||o.push({type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"})),c<S&&o.push({type:"invalid",label:S+"\u500B\u4EE5\u4E0A\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044"}),c>n&&o.push({type:"invalid",label:n+"\u500B\u307E\u3067\u9078\u629E\u3067\u304D\u307E\u3059"}),{ok:!o.filter(({type:h})=>h=="invalid").length,notice:o}}const R={InitOptions:t=>{let e=[];return t.forEach(i=>{if(!i)return;let{type:r,label:f,value:S,searchValue:n}=i,o=n||a.isString(f)&&f||""||a.isString(S)&&S||a.Stringify(S||"")||"";a.isNullish(f)&&(f=String(S)),e.push(m(l({id:v(8)},i),{searchValue:o,type:r||"selector",label:f,value:S}))}),e},FilterSelectableOptions:(t,e,i)=>{let r=t;return i||(r=t.filter(f=>(f==null?void 0:f.type)!="label")),a.scope(()=>{if(!e)return;let f=e.toLower().replace(/ /g,"");r=r.filter(S=>(S.searchValue||"").toLower().replace(/ /g,"").includes(f))}),r},Button:t=>{let{rootStates:e,val_keyword:i,set_keyword:r,val_optionFocused:f,set_optionFocused:S,val_status:n,set_status:o}=t,J=e,{tone:c,required:h,form:O,className:u,multiSelect:p,enableFormSubmit:I,showInitValidation:g,onValidate:d,onValidateDelay:y,onUpdateValue:x,onUpdateValidValue:C,onUserAction:F,value:E="",options:w,leftIndicator:D,rightIndicator:_,leftIcon:de,rightIcon:fe,componentId:me,status_id:Se,wrapStyles:ve,emptySelect:ye,searchInputPlaceholder:he,onSelectedRender:ge,onSelectorRender:Ie,pickerStyles:be,pickerPosition:Oe,onDynamicSearchOptions:_e,onDynamicSearchOptionsDelay:we}=J,T=Z(J,["tone","required","form","className","multiSelect","enableFormSubmit","showInitValidation","onValidate","onValidateDelay","onUpdateValue","onUpdateValidValue","onUserAction","value","options","leftIndicator","rightIndicator","leftIcon","rightIcon","componentId","status_id","wrapStyles","emptySelect","searchInputPlaceholder","onSelectedRender","onSelectorRender","pickerStyles","pickerPosition","onDynamicSearchOptions","onDynamicSearchOptionsDelay"]),W="SearchInput_"+e.componentId;return P(()=>{var b;if(e.disabled||!n.isPickerOpen||a.isExist(f))return;let k=R.FilterSelectableOptions(t.val_options,i,!1);S(((b=k[0])==null?void 0:b.id)||"")},[i]),P(()=>{if(n.eventType!="init"&&n.eventType!="override"&&e.max==n.rawValue.length){r(""),o(k=>m(l({},k),{eventID:v(8),isPickerOpen:!1}));return}},[n.rawValue]),P(()=>{let k="autocomplete-click-"+e.componentId;if(!n.isPickerOpen){a(document).removeEvent([k]);return}a('[data-input-origin="'+e.componentId+'"]')&&a(document).onEvent("mousedown",U=>{let j=a(U.target),Y=!!a(j).parent("."+L("Core")).length,ee=!!a(j).parent("."+L("Selector")).length;Y||ee||o(te=>m(l({},te),{eventID:v(8),isFocusing:!1,isPickerOpen:!1}))},{eventID:k,passive:!1})},[n.isPickerOpen]),V(N,{children:[s(X,m(l({tabIndex:-1},T),{"data-disabled":e.disabled,"data-show-validation":z.isShowValidation(n,!!g),"data-component-id":n.componentId,"data-input-origin":n.componentId,"data-focus":n.isFocusing||n.isPickerOpen,className:[u,L("Core")].join(" "),onClick:k=>{if(T!=null&&T.onClick&&(T==null||T.onClick(k)),e.disabled)return;let b=document.activeElement;(b==null?void 0:b.id)!=W&&(oe.get().isTouchDevice||a("#"+W).focus()),o(U=>m(l({},U),{eventID:v(8),isPickerOpen:!0,isFocusing:!0}))},onKeyDown:k=>{let b=document.activeElement;(b==null?void 0:b.id)!=W&&(k.preventDefault(),a("#"+W).focus())},children:V(M.Left,{gap:0,children:[s(ie,{"data-input-value-shallow":n.componentId,width:0,overflow:"hidden",opacity:"trans",children:"A"}),V(M.Left,{flexWrap:!0,flexSizing:0,gap:"1/4",verticalAlign:"unset",xcss:{letterSpacing:".5px"},children:[s(R.Selected,l({},t)),s(R.SearchInput,l({},t))]}),n.rawValue.length>1&&s($.Clear,{tabIndex:-1,color:"nega",fontColor:"4.thin",ssSphere:2,onClick:k=>{o(b=>m(l({},b),{eventType:"update",eventID:v(8),rawValue:[]}))},children:s(B.X,{})})]})})),s(R.Picker,l({},t))]})},SearchInput:t=>{let{rootStates:e,val_status:i,set_status:r}=t;if(e.disabled)return null;let f=!!i.isFocusing||!!i.isPickerOpen||!!i.rawValue.length;i.isFocusing||e.multiSelect||i.rawValue.length&&(f=!1);let S=e.searchInputPlaceholder||"\u691C\u7D22...";return s(X,{htmlTag:"input",id:"SearchInput_"+e.componentId,placeholder:S,opacity:f?"max":"trans",transition:"middle",flexSizing:0,fontSize:"inherit",border:"0.trans",backgroundColor:"trans",isRounded:!0,padding:[0,"2/3"],value:t.val_keyword,className:[L("SearchInput"),f&&L("isActive")].join(" "),xcss:{outline:"none",minWidth:12*4},onFocus:n=>{r(o=>m(l({},o),{eventID:v(8),isFocusing:!0,isPickerOpen:!0}))},onBlur:n=>H(void 0,null,function*(){r(o=>m(l({},o),{eventID:v(8),isFocusing:!1}))}),onCompositionStart:n=>{r(o=>m(l({},o),{eventID:v(8),isComposing:!0}))},onCompositionEnd:n=>{r(o=>m(l({},o),{eventID:v(8),isComposing:!1}))},onKeyDown:n=>{let{key:o,metaKey:c,ctrlKey:h}=n,O=c||h;if(o=="Escape")r(u=>m(l({},u),{eventID:v(12),isPickerOpen:!1}));else if(o=="Tab")r(u=>m(l({},u),{eventID:v(8),isFocusing:!1,isPickerOpen:!1}));else if(o==" ")a.scope(()=>{i.isPickerOpen||t.val_keyword||(n.preventDefault(),r(u=>m(l({},u),{eventID:v(8),isPickerOpen:!0})))});else if(o=="Backspace")a.scope(()=>{if(t.val_keyword)return;let u=[...t.val_status.rawValue];u.pop(),O&&(u=[]),r(p=>m(l({},p),{rawValue:u,eventType:"update",eventID:v(8),isInspected:!1}))});else if(o=="Enter"&&a.scope(()=>{if(i.isComposing||(n==null?void 0:n.keyCode)===229)return;if(!i.isPickerOpen){r(d=>m(l({},d),{eventID:v(8),isPickerOpen:!0}));return}if(!t.val_optionFocused)return;let p=t.val_options.find(d=>(d==null?void 0:d.id)==t.val_optionFocused);if(!p)return;let{value:I}=p;if(!i.rawValue.includes(I))return r(d=>{let y=[...d.rawValue];return a.scope(()=>{if(I===null)return y=[];e.multiSelect?y.push(I):y=[I]}),m(l({},d),{rawValue:y,eventType:"update",eventID:v(8),isInspected:!1})}),t.set_optionsModified(!0),t.set_keyword(""),!0})){n.preventDefault();return}a.scope(()=>{if(!a.isOneOf(o,"ArrowDown","ArrowUp"))return;if(n.preventDefault(),!i.isPickerOpen){r(d=>m(l({},d),{eventID:v(8),isPickerOpen:!0}));return}let u=o=="ArrowDown"?1:-1,p=R.FilterSelectableOptions(t.val_options,t.val_keyword),I=p.length-1,g=null;a.scope(()=>{var y,x,C,F,E,w,D;let d=p.findIndex(_=>(_==null?void 0:_.id)==t.val_optionFocused);if(d==-1){g=(y=p[0])==null?void 0:y.id;return}if(u==1){if(g=(x=p[0])==null?void 0:x.id,O){g=(C=p[I])==null?void 0:C.id;return}if(d==-1||d==I)return;g=(F=p[d+1])==null?void 0:F.id}else{if(g=(E=p[I])==null?void 0:E.id,O){g=(w=p[0])==null?void 0:w.id;return}if(d==-1||d==0)return;g=(D=p[d-1])==null?void 0:D.id}}),t.set_optionFocused(g)}),e.enableFormSubmit&&z.SubmitForm(n,t.rootStates.form)},onChange:n=>{let c=n.target.value;t.set_keyword(c),t.set_optionFocused(""),c&&r(h=>m(l({},h),{eventID:v(8),isPickerOpen:!0}))}},"searchInput")},Picker:t=>{var o;let{rootStates:e,val_status:i}=t,[r,f]=A("idle");P(()=>{if(!e.onDynamicSearchOptions||!i.isPickerOpen)return;if(t.val_optionsModified)return t.set_optionsModified(!1);if(i.isComposing)return;f("fetch");let c="autocomplete-search-"+e.componentId;t.set_optionFocused(""),a.interval.once(()=>H(void 0,null,function*(){var u;let h=yield e.onDynamicSearchOptions(t.val_keyword);f("idle");let O=R.InitOptions(h||[]);t.set_options(O),t.set_optionFocused(((u=O[0])==null?void 0:u.id)||"")}),e.onDynamicSearchOptionsDelay||500,c)},[t.val_keyword,i.isComposing]),P(()=>{let c=a(`[data-selector-id="${i.componentId}"]`)[0];if(!c)return;let h=a(`[data-autocomplete-input-value="${t.val_optionFocused}"]`)[0];h&&(c.scrollTop=h.offsetTop-24)},[t.val_optionFocused]);let S=R.FilterSelectableOptions(t.val_options,e.onDynamicSearchOptions?"":t.val_keyword,!0),n={};{let c=e.pickerPosition||0;a.isOneOf(c,1,2)?n.bottom="100%":a.isOneOf(c,3,4)&&(n.top="100%"),a.isOneOf(c,1,3)?n.left=0:a.isOneOf(c,2,4)&&(n.right=0)}return i.isPickerOpen?s(X,m(l({position:"absolute",ssZIndex:1e3,padding:"1/3"},n),{xcss:l({minWidth:"75%"},n.xcss),children:s(ae.Body,m(l({className:L("Selector"),borderRadius:"2.tone.secondary",ssCardBox:!0,tabIndex:-1,boxShadow:"1.normal",overflow:"auto","data-selector-id":i.componentId},e.pickerStyles),{xcss:l({maxHeight:12*24},(o=e.pickerStyles)==null?void 0:o.xcss),children:V(q,{gap:"1/12",padding:[1,0],children:[r=="fetch"&&s(M.Center,{padding:"1/2",children:s(le.Theme.R,{showInitial:!0})}),r!="fetch"&&V(N,{children:[!S.length&&s(K.Mini,{padding:[0,1],fontColor:"4.thin",children:"\u5019\u88DC\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093"}),S.map((c,h)=>{if(!c)return null;let{type:O,value:u}=c,p=t.val_optionFocused==c.id,I=i.rawValue.includes(u),g=e.onSelectorRender;return s(q,{"data-autocomplete-input-value":c.id,children:s(g,{option:c,isFocused:p,isSelected:I,onAdd:()=>{t.set_status(d=>{let y=[...d.rawValue];return a.scope(()=>{if(u===null)return y=[];if(d.rawValue.includes(u)){y=y.filter(C=>C!==u);return}e.multiSelect?y.push(u):y=[u]}),m(l({},d),{rawValue:y,eventType:"update",eventID:v(8),isFocusing:e.max!=y.length,isInspected:!1})})},onKeyDown:d=>{let{key:y}=d;y=="Tab"&&(t.set_optionFocused(""),t.set_status(x=>m(l({},x),{eventID:v(8),isPickerOpen:!1,isFocusing:!1})))}})},c.id)})]})]})}))})):null},Selected:t=>{let{rootStates:e,val_status:i,set_status:r,val_optionsDict:f}=t,S=[];return i.rawValue.forEach(n=>{let o=f[a.Stringify(n)];if(!o)return;let c=e.onSelectedRender,h=(o==null?void 0:o.selectedLabel)||(o==null?void 0:o.label);(o==null?void 0:o.value)===null&&(h=""),S.push(s(q,{position:"relative",flexCenter:!0,xcss:{userSelect:"none"},children:s(c,{value:o==null?void 0:o.value,label:h,onRemove:O=>{if(e.disabled)return;let u=[...i.rawValue];u=u.filter(p=>p!==n),r(p=>m(l({},p),{rawValue:u,eventType:"update",eventID:v(8),isInspected:!1,isFocusing:e.max!=u.length,isPickerOpen:!0}))}})},a.Stringify(o==null?void 0:o.value)||v(8)))}),s(N,{children:S})},Core:t=>{var C,F,E;let{value:e}=t,[i,r]=A(!1),[f,S]=A(""),[n,o]=A(t.options),[c,h]=A(((C=t.options.find(w=>{var D;return(w==null?void 0:w.value)===((D=t.value)==null?void 0:D[0])}))==null?void 0:C.id)||((F=t.options[0])==null?void 0:F.id)||""),[O,u]=A({}),[p,I]=A(z.DefaultStatus(t.componentId,e)),g=ne(!1);P(()=>{i||(g.current?o(t.options):g.current=!0)},[a.Stringify((E=t.options)==null?void 0:E.map(w=>w.value))]),P(()=>{if(!n.length)return;let w=[...n],D=l({},O);w.forEach(_=>{(_==null?void 0:_.type)!="label"&&(D[a.Stringify(_==null?void 0:_.value)]=_)}),u(D)},[n]);let d={rootStates:t,val_options:n,set_options:o,val_optionFocused:c,set_optionFocused:h,val_optionsDict:O,set_optionsDict:u,val_optionsModified:i,set_optionsModified:r,val_keyword:f,set_keyword:S,val_status:p,set_status:I},y=!!t.multiSelect;z.CommonEffects({type:y?"autocomplete.multi":"autocomplete.single",states:t,val_status:p,set_status:I,SystemValidation:pe});let x=p.rawValue.length&&p.rawValue[0]!==null||p.isPickerOpen||p.isFocusing;return V(se,{val_status:p,set_status:I,states:t,children:[s(ce,{componentId:t.componentId,fontSize:t.fontSize,required:t.required,label:t.label,isActive:x,val_status:p}),s(R.Button,l({},d))]})}},Q=t=>{let e=l({},t);return e=m(l({value:[],min:0,max:65535,multiSelect:!0,emptySelect:!0,onSelectorRender:i=>{var r;return i.option?((r=i.option)==null?void 0:r.type)=="label"?s(N,{children:i.option.label}):s($.Sub.S,{color:"cloud",tabIndex:-1,backgroundColor:"trans",borderRadius:0,fontColor:"2.normal",textAlign:"left",padding:["2/3",1.5],isActive:i.isFocused,isActiveStyles:{backgroundColor:"cloud"},onClick:i.onAdd,onKeyDown:i.onKeyDown,children:V(M.Left,{gap:"1/2",children:[i.isSelected&&s(B.Check,{fontColor:"theme"}),s(K.Mini,{transition:"short",children:i.option.label})]})}):null},onSelectedRender:i=>V(M.Left,{ssCardBox:!0,borderRadius:"1.tone.primary",fontSize:"1.mini",padding:"1/3",gap:0,children:[s(K,{padding:[0,"1/2"],children:i.label}),s($.Clear,{flexSizing:"none",color:"nega",fontColor:"4.thin",tabIndex:-1,ssSphere:2,onClick:i.onRemove,xcss:{lineHeight:1,aspectRatio:"1/1"},children:s(B.X,{})})]}),pickerPosition:3},e),{xcss:l({cursor:"pointer"},e.xcss)}),e.multiSelect||(e.min=0,e.max=1),e.options=e.options||[],e.emptySelect&&(e.options=[{value:null,label:s(K.Mini,{fontColor:"4.thin",children:"\u9078\u629E\u3092\u89E3\u9664"})},...e.options]),e.value=a.Arrayify(e.value),e.options=R.InitOptions(e.options),a.isNullish(e.rightIcon)&&(e.rightIcon=s(G,{children:s(B.Search,{})}),e.disabled&&(e.rightIcon=s(G,{fontColor:"5.translucent",children:s(B.Ban,{})}))),e.rightIcon&&(e=l({paddingRight:3},e)),e.leftIcon&&(e=l({paddingLeft:3},e)),s(re,{componentId:e.componentId,children:R.Core,states:ue(e)})};export{Q as Autocomplete,Q as default};
1
+ import{b as l,c as m,d as Z,e as H}from"../../chunk-C5N2D3ZX.js";import{Fragment as N,jsx as s,jsxs as V}from"react/jsx-runtime";import{useState as A,useEffect as P,useRef as ne}from"react";import a,{UUID as v}from"jmini";import{Config as ie}from"../../@utils";import{Box as X,Span as oe,FAI as B,Column as q}from"../../atoms";import{Literal as K,Row as M}from"../../mols";import{Button as $}from"../Button";import{Loader as le}from"../Loader";import{Sheet as ae}from"../Sheet";import{OptionalInputWrapper as re,BoxWrapper as se,CoreEffects as z,DefaultBoxishStyles as ue}from"./core";import{InputAutocompleteClasses as L}from"../../@styles/componentClasses";import{InputLabel as ce}from"./Label";import{RightIcon as G}from".";function pe(t){let{value:e,states:o}=t,{required:r,options:f,min:S,max:n}=o;S=S||0,n=n||65535;let i=[],c=e.filter(h=>h!==null).length;return r&&(c||i.push({type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"})),c<S&&i.push({type:"invalid",label:S+"\u500B\u4EE5\u4E0A\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044"}),c>n&&i.push({type:"invalid",label:n+"\u500B\u307E\u3067\u9078\u629E\u3067\u304D\u307E\u3059"}),{ok:!i.filter(({type:h})=>h=="invalid").length,notice:i}}const R={InitOptions:t=>{let e=[];return t.forEach(o=>{if(!o)return;let{type:r,label:f,value:S,searchValue:n}=o,i=n||a.isString(f)&&f||""||a.isString(S)&&S||a.Stringify(S||"")||"";a.isNullish(f)&&(f=String(S)),e.push(m(l({id:v(8)},o),{searchValue:i,type:r||"selector",label:f,value:S}))}),e},FilterSelectableOptions:(t,e,o)=>{let r=t;return o||(r=t.filter(f=>(f==null?void 0:f.type)!="label")),a.scope(()=>{if(!e)return;let f=e.toLower().replace(/ /g,"");r=r.filter(S=>(S.searchValue||"").toLower().replace(/ /g,"").includes(f))}),r},Button:t=>{let{rootStates:e,val_keyword:o,set_keyword:r,val_optionFocused:f,set_optionFocused:S,val_status:n,set_status:i}=t,J=e,{tone:c,required:h,form:O,className:u,multiSelect:p,enableFormSubmit:I,showInitValidation:g,onValidate:d,onValidateDelay:y,onUpdateValue:x,onUpdateValidValue:C,onUserAction:F,value:E="",options:w,leftIndicator:D,rightIndicator:_,leftIcon:de,rightIcon:fe,componentId:me,status_id:Se,wrapStyles:ve,emptySelect:ye,searchInputPlaceholder:he,onSelectedRender:ge,onSelectorRender:Ie,pickerStyles:be,pickerPosition:Oe,onDynamicSearchOptions:_e,onDynamicSearchOptionsDelay:we}=J,T=Z(J,["tone","required","form","className","multiSelect","enableFormSubmit","showInitValidation","onValidate","onValidateDelay","onUpdateValue","onUpdateValidValue","onUserAction","value","options","leftIndicator","rightIndicator","leftIcon","rightIcon","componentId","status_id","wrapStyles","emptySelect","searchInputPlaceholder","onSelectedRender","onSelectorRender","pickerStyles","pickerPosition","onDynamicSearchOptions","onDynamicSearchOptionsDelay"]),W="SearchInput_"+e.componentId;return P(()=>{var b;if(e.disabled||!n.isPickerOpen||a.isExist(f))return;let k=R.FilterSelectableOptions(t.val_options,o,!1);S(((b=k[0])==null?void 0:b.id)||"")},[o]),P(()=>{if(n.eventType!="init"&&n.eventType!="override"&&e.max==n.rawValue.length){r(""),i(k=>m(l({},k),{eventID:v(8),isPickerOpen:!1}));return}},[n.rawValue]),P(()=>{let k="autocomplete-click-"+e.componentId;if(!n.isPickerOpen){a(document).removeEvent([k]);return}a('[data-input-origin="'+e.componentId+'"]')&&a(document).onEvent("mousedown",U=>{let j=a(U.target),Y=!!a(j).parent("."+L("Core")).length,ee=!!a(j).parent("."+L("Selector")).length;Y||ee||i(te=>m(l({},te),{eventID:v(8),isFocusing:!1,isPickerOpen:!1}))},{eventID:k,passive:!1})},[n.isPickerOpen]),V(N,{children:[s(X,m(l({tabIndex:-1},T),{"data-disabled":e.disabled,"data-show-validation":z.isShowValidation(n,!!g),"data-component-id":n.componentId,"data-input-origin":n.componentId,"data-focus":n.isFocusing||n.isPickerOpen,className:[u,L("Core")].join(" "),onClick:k=>{if(T!=null&&T.onClick&&(T==null||T.onClick(k)),e.disabled)return;let b=document.activeElement;(b==null?void 0:b.id)!=W&&(ie.get().isTouchDevice||a("#"+W).focus()),i(U=>m(l({},U),{eventID:v(8),isPickerOpen:!0,isFocusing:!0}))},onKeyDown:k=>{let b=document.activeElement;(b==null?void 0:b.id)!=W&&(k.preventDefault(),a("#"+W).focus())},children:V(M.Left,{gap:0,children:[s(oe,{"data-input-value-shallow":n.componentId,width:0,overflow:"hidden",opacity:"trans",children:"A"}),V(M.Left,{flexWrap:!0,flexSizing:0,gap:"1/4",verticalAlign:"unset",xcss:{letterSpacing:".5px"},children:[s(R.Selected,l({},t)),s(R.SearchInput,l({},t))]}),n.rawValue.length>1&&s($.Clear,{tabIndex:-1,color:"nega",fontColor:"4.thin",ssSphere:2,onClick:k=>{i(b=>m(l({},b),{eventType:"update",eventID:v(8),rawValue:[]}))},children:s(B.X,{})})]})})),s(R.Picker,l({},t))]})},SearchInput:t=>{let{rootStates:e,val_status:o,set_status:r}=t;if(e.disabled)return null;let f=!!o.isFocusing||!!o.isPickerOpen||!!o.rawValue.length;o.isFocusing||e.multiSelect||o.rawValue.length&&(f=!1);let S=e.searchInputPlaceholder||"\u691C\u7D22...";return s(X,{htmlTag:"input",id:"SearchInput_"+e.componentId,placeholder:S,opacity:f?"max":"trans",transition:"middle",flexSizing:0,width:0,fontSize:"inherit",border:"0.trans",backgroundColor:"trans",isRounded:!0,padding:[0,"2/3"],value:t.val_keyword,className:[L("SearchInput"),f&&L("isActive")].join(" "),xcss:{outline:"none",minWidth:12*4},onFocus:n=>{r(i=>m(l({},i),{eventID:v(8),isFocusing:!0,isPickerOpen:!0}))},onBlur:n=>H(void 0,null,function*(){r(i=>m(l({},i),{eventID:v(8),isFocusing:!1}))}),onCompositionStart:n=>{r(i=>m(l({},i),{eventID:v(8),isComposing:!0}))},onCompositionEnd:n=>{r(i=>m(l({},i),{eventID:v(8),isComposing:!1}))},onKeyDown:n=>{let{key:i,metaKey:c,ctrlKey:h}=n,O=c||h;if(i=="Escape")r(u=>m(l({},u),{eventID:v(12),isPickerOpen:!1}));else if(i=="Tab")r(u=>m(l({},u),{eventID:v(8),isFocusing:!1,isPickerOpen:!1}));else if(i==" ")a.scope(()=>{o.isPickerOpen||t.val_keyword||(n.preventDefault(),r(u=>m(l({},u),{eventID:v(8),isPickerOpen:!0})))});else if(i=="Backspace")a.scope(()=>{if(t.val_keyword)return;let u=[...t.val_status.rawValue];u.pop(),O&&(u=[]),r(p=>m(l({},p),{rawValue:u,eventType:"update",eventID:v(8),isInspected:!1}))});else if(i=="Enter"&&a.scope(()=>{if(o.isComposing||(n==null?void 0:n.keyCode)===229)return;if(!o.isPickerOpen){r(d=>m(l({},d),{eventID:v(8),isPickerOpen:!0}));return}if(!t.val_optionFocused)return;let p=t.val_options.find(d=>(d==null?void 0:d.id)==t.val_optionFocused);if(!p)return;let{value:I}=p;if(!o.rawValue.includes(I))return r(d=>{let y=[...d.rawValue];return a.scope(()=>{if(I===null)return y=[];e.multiSelect?y.push(I):y=[I]}),m(l({},d),{rawValue:y,eventType:"update",eventID:v(8),isInspected:!1})}),t.set_optionsModified(!0),t.set_keyword(""),!0})){n.preventDefault();return}a.scope(()=>{if(!a.isOneOf(i,"ArrowDown","ArrowUp"))return;if(n.preventDefault(),!o.isPickerOpen){r(d=>m(l({},d),{eventID:v(8),isPickerOpen:!0}));return}let u=i=="ArrowDown"?1:-1,p=R.FilterSelectableOptions(t.val_options,t.val_keyword),I=p.length-1,g=null;a.scope(()=>{var y,x,C,F,E,w,D;let d=p.findIndex(_=>(_==null?void 0:_.id)==t.val_optionFocused);if(d==-1){g=(y=p[0])==null?void 0:y.id;return}if(u==1){if(g=(x=p[0])==null?void 0:x.id,O){g=(C=p[I])==null?void 0:C.id;return}if(d==-1||d==I)return;g=(F=p[d+1])==null?void 0:F.id}else{if(g=(E=p[I])==null?void 0:E.id,O){g=(w=p[0])==null?void 0:w.id;return}if(d==-1||d==0)return;g=(D=p[d-1])==null?void 0:D.id}}),t.set_optionFocused(g)}),e.enableFormSubmit&&z.SubmitForm(n,t.rootStates.form)},onChange:n=>{let c=n.target.value;t.set_keyword(c),t.set_optionFocused(""),c&&r(h=>m(l({},h),{eventID:v(8),isPickerOpen:!0}))}},"searchInput")},Picker:t=>{var i;let{rootStates:e,val_status:o}=t,[r,f]=A("idle");P(()=>{if(!e.onDynamicSearchOptions||!o.isPickerOpen)return;if(t.val_optionsModified)return t.set_optionsModified(!1);if(o.isComposing)return;f("fetch");let c="autocomplete-search-"+e.componentId;t.set_optionFocused(""),a.interval.once(()=>H(void 0,null,function*(){var u;let h=yield e.onDynamicSearchOptions(t.val_keyword);f("idle");let O=R.InitOptions(h||[]);t.set_options(O),t.set_optionFocused(((u=O[0])==null?void 0:u.id)||"")}),e.onDynamicSearchOptionsDelay||500,c)},[t.val_keyword,o.isComposing]),P(()=>{let c=a(`[data-selector-id="${o.componentId}"]`)[0];if(!c)return;let h=a(`[data-autocomplete-input-value="${t.val_optionFocused}"]`)[0];h&&(c.scrollTop=h.offsetTop-24)},[t.val_optionFocused]);let S=R.FilterSelectableOptions(t.val_options,e.onDynamicSearchOptions?"":t.val_keyword,!0),n={};{let c=e.pickerPosition||0;a.isOneOf(c,1,2)?n.bottom="100%":a.isOneOf(c,3,4)&&(n.top="100%"),a.isOneOf(c,1,3)?n.left=0:a.isOneOf(c,2,4)&&(n.right=0)}return o.isPickerOpen?s(X,m(l({position:"absolute",ssZIndex:1e3,padding:"1/3"},n),{xcss:l({minWidth:"75%"},n.xcss),children:s(ae.Body,m(l({className:L("Selector"),borderRadius:"2.tone.secondary",ssCardBox:!0,tabIndex:-1,boxShadow:"1.normal",overflow:"auto","data-selector-id":o.componentId},e.pickerStyles),{xcss:l({maxHeight:12*24},(i=e.pickerStyles)==null?void 0:i.xcss),children:V(q,{gap:"1/12",padding:[1,0],children:[r=="fetch"&&s(M.Center,{padding:"1/2",children:s(le.Theme.R,{showInitial:!0})}),r!="fetch"&&V(N,{children:[!S.length&&s(K.Mini,{padding:[0,1],fontColor:"4.thin",children:"\u5019\u88DC\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093"}),S.map((c,h)=>{if(!c)return null;let{type:O,value:u}=c,p=t.val_optionFocused==c.id,I=o.rawValue.includes(u),g=e.onSelectorRender;return s(q,{"data-autocomplete-input-value":c.id,children:s(g,{option:c,isFocused:p,isSelected:I,onAdd:()=>{t.set_status(d=>{let y=[...d.rawValue];return a.scope(()=>{if(u===null)return y=[];if(d.rawValue.includes(u)){y=y.filter(C=>C!==u);return}e.multiSelect?y.push(u):y=[u]}),m(l({},d),{rawValue:y,eventType:"update",eventID:v(8),isFocusing:e.max!=y.length,isInspected:!1})})},onKeyDown:d=>{let{key:y}=d;y=="Tab"&&(t.set_optionFocused(""),t.set_status(x=>m(l({},x),{eventID:v(8),isPickerOpen:!1,isFocusing:!1})))}})},c.id)})]})]})}))})):null},Selected:t=>{let{rootStates:e,val_status:o,set_status:r,val_optionsDict:f}=t,S=[];return o.rawValue.forEach(n=>{let i=f[a.Stringify(n)];if(!i)return;let c=e.onSelectedRender,h=(i==null?void 0:i.selectedLabel)||(i==null?void 0:i.label);(i==null?void 0:i.value)===null&&(h=""),S.push(s(q,{position:"relative",flexCenter:!0,xcss:{userSelect:"none"},children:s(c,{value:i==null?void 0:i.value,label:h,onRemove:O=>{if(e.disabled)return;let u=[...o.rawValue];u=u.filter(p=>p!==n),r(p=>m(l({},p),{rawValue:u,eventType:"update",eventID:v(8),isInspected:!1,isFocusing:e.max!=u.length,isPickerOpen:!0}))}})},a.Stringify(i==null?void 0:i.value)||v(8)))}),s(N,{children:S})},Core:t=>{var C,F,E;let{value:e}=t,[o,r]=A(!1),[f,S]=A(""),[n,i]=A(t.options),[c,h]=A(((C=t.options.find(w=>{var D;return(w==null?void 0:w.value)===((D=t.value)==null?void 0:D[0])}))==null?void 0:C.id)||((F=t.options[0])==null?void 0:F.id)||""),[O,u]=A({}),[p,I]=A(z.DefaultStatus(t.componentId,e)),g=ne(!1);P(()=>{o||(g.current?i(t.options):g.current=!0)},[a.Stringify((E=t.options)==null?void 0:E.map(w=>w.value))]),P(()=>{if(!n.length)return;let w=[...n],D=l({},O);w.forEach(_=>{(_==null?void 0:_.type)!="label"&&(D[a.Stringify(_==null?void 0:_.value)]=_)}),u(D)},[n]);let d={rootStates:t,val_options:n,set_options:i,val_optionFocused:c,set_optionFocused:h,val_optionsDict:O,set_optionsDict:u,val_optionsModified:o,set_optionsModified:r,val_keyword:f,set_keyword:S,val_status:p,set_status:I},y=!!t.multiSelect;z.CommonEffects({type:y?"autocomplete.multi":"autocomplete.single",states:t,val_status:p,set_status:I,SystemValidation:pe});let x=p.rawValue.length&&p.rawValue[0]!==null||p.isPickerOpen||p.isFocusing;return V(se,{val_status:p,set_status:I,states:t,children:[s(ce,{componentId:t.componentId,fontSize:t.fontSize,required:t.required,label:t.label,isActive:x,val_status:p}),s(R.Button,l({},d))]})}},Q=t=>{let e=l({},t);return e=m(l({value:[],min:0,max:65535,multiSelect:!0,emptySelect:!0,onSelectorRender:o=>{var r;return o.option?((r=o.option)==null?void 0:r.type)=="label"?s(N,{children:o.option.label}):s($.Sub.S,{color:"cloud",tabIndex:-1,backgroundColor:"trans",borderRadius:0,fontColor:"2.normal",textAlign:"left",padding:["2/3",1.5],isActive:o.isFocused,isActiveStyles:{backgroundColor:"cloud"},onClick:o.onAdd,onKeyDown:o.onKeyDown,children:V(M.Left,{gap:"1/2",children:[o.isSelected&&s(B.Check,{fontColor:"theme"}),s(K.Mini,{transition:"short",children:o.option.label})]})}):null},onSelectedRender:o=>V(M.Left,{ssCardBox:!0,borderRadius:"1.tone.primary",fontSize:"1.mini",padding:"1/3",gap:0,children:[s(K,{padding:[0,"1/2"],children:o.label}),s($.Clear,{flexSizing:"none",color:"nega",fontColor:"4.thin",tabIndex:-1,ssSphere:2,onClick:o.onRemove,xcss:{lineHeight:1,aspectRatio:"1/1"},children:s(B.X,{})})]}),pickerPosition:3},e),{xcss:l({cursor:"pointer"},e.xcss)}),e.multiSelect||(e.min=0,e.max=1),e.options=e.options||[],e.emptySelect&&(e.options=[{value:null,label:s(K.Mini,{fontColor:"4.thin",children:"\u9078\u629E\u3092\u89E3\u9664"})},...e.options]),e.value=a.Arrayify(e.value),e.options=R.InitOptions(e.options),a.isNullish(e.rightIcon)&&(e.rightIcon=s(G,{children:s(B.Search,{})}),e.disabled&&(e.rightIcon=s(G,{fontColor:"5.translucent",children:s(B.Ban,{})}))),e.rightIcon&&(e=l({paddingRight:3},e)),e.leftIcon&&(e=l({paddingLeft:3},e)),s(re,{componentId:e.componentId,children:R.Core,states:ue(e)})};export{Q as Autocomplete,Q as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amotify",
3
- "version": "0.3.12",
3
+ "version": "0.3.14",
4
4
  "description": "UI Component for React,NextJS,esbuild",
5
5
  "scripts": {
6
6
  "start": "run-p clean build:*",