amotify 0.2.155 → 0.2.156

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 S,c as O,d as Q,e as Y}from"../../chunk-C5N2D3ZX.js";import{Fragment as X,jsx as l,jsxs as P}from"react/jsx-runtime";import{useState as I,useEffect as E,useRef as ne}from"react";import s,{UUID as W}from"jmini";import{ExtractStyles as ae}from"../../@utils";import{Box as x,Span as ie,FAI as M,Column as re}from"../../atoms";import{Literal as N,Row as q}from"../../mols";import{Button as Z}from"../Button";import{Loader as se}from"../Loader";import{Sheet as ue}from"../Sheet";import{OptionalInputWrapper as ce,BoxWrapper as pe,CoreEffects as z,DefaultBoxishStyles as de}from"./core";import{InputAutocompleteClasses as U}from"../../@styles/componentClasses";import{InputLabel as Se}from"./Label";import{RightIcon as ee}from".";function me(e){let{value:t,states:u}=e,{required:c,options:n,min:o,max:f}=u;o=o||0,f=f||65535;let v=[],p=t.filter(d=>d!==null).length;return c&&(p||v.push({type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"})),p<o&&v.push({type:"invalid",label:o+"\u500B\u4EE5\u4E0A\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044"}),p>f&&v.push({type:"invalid",label:f+"\u500B\u307E\u3067\u9078\u629E\u3067\u304D\u307E\u3059"}),{ok:!v.filter(({type:d})=>d=="invalid").length,notice:v}}const L={InitOptions:e=>{let t=[];return e.forEach(u=>{let{type:c,label:n,value:o,searchValue:f}=u,v=f||(s.is.string(n)?n:"")||(s.is.string(o)?o:"");s.is.nullish(n)&&(n=String(o)),t.push(O(S({},u),{searchValue:v,type:c||"selector",label:n,value:o}))}),t},FilterSelectableOptions:(e,t)=>{let u=e.val_options;if(t||(u=e.val_options.filter(c=>c.type!="label")),e.val_keyword){let c=e.val_keyword.toLower().replace(/ /g,"");u=u.filter(n=>(n.searchValue||"").toLower().replace(/ /g,"").includes(c))}return u}},B={Shallow:e=>{let{rootStates:t,val_status:u}=e,c=ae(t);return l(x,{position:"absolute",top:0,left:0,right:0,height:0,overflow:"hidden",opacity:"trans",freeCSS:{zIndex:3,pointerEvents:"none"},children:l(N.Description,O(S({className:t.className},c),{position:"absolute",width:1,freeCSS:O(S({},c.freeCSS),{color:"orange"}),"data-id":"shallow_"+u.componentID,children:l(x,{"data-input-value-shallow":u.componentID,children:"A"})}))})},Button:e=>{let{rootStates:t,val_keyword:u,set_keyword:c,val_optionFocused:n,set_optionFocused:o,val_options:f,set_options:v,val_optionsDict:p,set_optionsDict:d,val_preventOpenSelectorOnFocus:a,set_preventOpenSelectorOnFocus:m,val_selectorOpen:i,set_selectorOpen:r,val_status:y,set_status:w,val_validate:b,set_validate:C}=e,j=t,{tone:_,required:T,form:D,className:R,multiSelect:K,enableFormSubmit:V,checkValidationAtFirst:A,onValidate:$,onUpdateValue:J,onUpdateValidValue:H,value:fe="",options:ve,leftIndicator:ye,rightIndicator:he,leftIcon:_e,rightIcon:ge,componentID:be,status_id:Oe,wrapStyles:Ie,emptySelect:Ce,SearchInput:De,SearchInputPlaceholder:we,SelectedComponent:Ve,SelectorComponent:ke,SelectorStyles:Te,SelectorPosition:Re,DynamicOptionsOnSearch:xe}=j,g=Q(j,["tone","required","form","className","multiSelect","enableFormSubmit","checkValidationAtFirst","onValidate","onUpdateValue","onUpdateValidValue","value","options","leftIndicator","rightIndicator","leftIcon","rightIcon","componentID","status_id","wrapStyles","emptySelect","SearchInput","SearchInputPlaceholder","SelectedComponent","SelectorComponent","SelectorStyles","SelectorPosition","DynamicOptionsOnSearch"]);return E(()=>{var k,F;if(t.disabled||!i)return;let h=L.FilterSelectableOptions(e);o((F=(k=h[0])==null?void 0:k.value)!=null?F:null)},[u]),E(()=>{y.eventType!="init"&&(t.max==y.dataValue.length?(r(!1),m(!0),setTimeout(()=>{let h=s('[data-input-origin="'+t.componentID+'"]');h&&h.focus()},10)):s("#SearchInput_"+t.componentID).focus())},[y.dataValue]),E(()=>{let h="autocomplete-click-"+t.componentID;if(i){if(!s('[data-input-origin="'+t.componentID+'"]'))return;s("#SearchInput_"+t.componentID).focus(),s(document).addEvent({eventID:h,eventType:"mousedown",callback:F=>{let G=s(F.target),oe=!!s(G).parent("."+U("Core")).length,le=!!s(G).parent("."+U("Selector")).length;oe||le||(r(!1),F.preventDefault(),F.stopPropagation())},options:{passive:!1}})}else s(document).removeEvent([h]),c("")},[i]),P(X,{children:[l(x,O(S({tabIndex:0},g),{"data-disabled":t.disabled,"data-show-validation":z.isShowValidation(b,y,!!A),"data-component-id":y.componentID,"data-input-origin":y.componentID,"data-focus":!!i,className:[R,U("Core")].join(" "),onFocus:h=>{if(g!=null&&g.onFocus&&(g==null||g.onFocus(h)),!t.disabled){if(a)return m(!1);r(!0),h.preventDefault()}},onClick:h=>{g!=null&&g.onClick&&(g==null||g.onClick(h)),!t.disabled&&r(!0)},onKeyDown:h=>{let{key:k}=h;V&&z.SubmitForm(h,D),!i&&(k==" "||k=="ArrowDown"||k=="ArrowUp"||k=="Enter")&&r(!0)},children:P(q.Left,{flexWrap:!0,gap:"1/3",freeCSS:{letterSpacing:".5px"},children:[l(B.Selected,S({},e)),l(ie,{width:0,overflow:"hidden",opacity:"trans",children:"A"}),l(B.SearchInput,S({},e))]})})),i&&l(B.Selector,S({},e))]})},SearchInput:e=>{let{rootStates:t}=e,[u,c]=I(!1);return t.disabled||!e.val_selectorOpen?null:l(x,{id:"SearchInput_"+t.componentID,placeholder:t.SearchInputPlaceholder||"\u691C\u7D22...",opacity:e.val_selectorOpen?"max":"trans",transition:"middle",flexSizing:0,htmlTag:"input",border:"unset",backgroundColor:"trans",value:e.val_keyword,freeCSS:{outline:"none"},onCompositionStart:n=>{t.onCompositionStart&&t.onCompositionStart(n),c(!0)},onCompositionEnd:n=>{t.onCompositionEnd&&t.onCompositionEnd(n),c(!1)},onKeyDown:n=>{let{key:o,metaKey:f,ctrlKey:v}=n,p=f||v;o=="Escape"?(e.set_selectorOpen(!1),e.set_preventOpenSelectorOnFocus(!0),setTimeout(()=>{let d=s('[data-input-origin="'+t.componentID+'"]');d&&d.focus()},10)):o=="Tab"?e.set_selectorOpen(!1):o==" "?s.scope(()=>{e.val_selectorOpen||e.val_keyword||(n.preventDefault(),e.set_selectorOpen(!0))}):o=="Backspace"?s.scope(()=>{if(e.val_keyword)return;let d=[...e.val_status.dataValue];d.pop(),e.set_status(a=>O(S({},a),{dataValue:d,eventType:"update",eventID:W()}))}):o=="Enter"&&s.scope(()=>{if(u)return;if(!e.val_selectorOpen)return e.set_selectorOpen(!0);let d=e.val_options.find(m=>m.value==e.val_optionFocused);if(!d)return;let{value:a}=d;e.set_status(m=>{let i=[...m.dataValue];return s.scope(()=>{if(a===null)return i=[];m.dataValue.includes(a)?i=i.filter(y=>y!==a):t.multiSelect?i.push(a):i=[a]}),O(S({},m),{dataValue:i,eventType:"update",eventID:W()})}),e.set_keyword(""),e.set_preventDynamicSearchOnKeywordChange(!0)}),s.scope(()=>{if(!["ArrowDown","ArrowUp"].includes(o))return;if(n.preventDefault(),!e.val_selectorOpen)return e.set_selectorOpen(!0);let d=o=="ArrowDown"?1:-1,a=L.FilterSelectableOptions(e),m=a.length-1,i=null;s.scope(()=>{var y,w,b,C,_,T,D,R,K,V;let r=a.findIndex(A=>A.value==e.val_optionFocused);if(r==-1&&(r=0),d==1){if(i=(w=(y=a[0])==null?void 0:y.value)!=null?w:null,p){i=(b=a[m].value)!=null?b:null;return}if(r==-1||r==m)return;i=(_=(C=a[r+1])==null?void 0:C.value)!=null?_:null}else{if(i=(T=a[m].value)!=null?T:null,p){i=(R=(D=a[0])==null?void 0:D.value)!=null?R:null;return}if(r==-1||r==0)return;i=(V=(K=a[r-1])==null?void 0:K.value)!=null?V:null}}),e.set_optionFocused(i)}),t.enableFormSubmit&&z.SubmitForm(n,e.rootStates.form)},onChange:n=>{let f=n.target.value;e.set_keyword(f)}},"searchInput")},Selector:e=>{var d;let[t,u]=I("idle"),[c,n]=I("idle");E(()=>{if(!e.val_selectorOpen||!e.rootStates.DynamicOptionsOnSearch)return;if(e.val_preventDynamicSearchOnKeywordChange)return e.set_preventDynamicSearchOnKeywordChange(!1);if(t=="idle")return u("ok");n("fetch");let a="autocomplete-search-"+e.rootStates.componentID;s.interval.once(()=>Y(void 0,null,function*(){let m=yield e.rootStates.DynamicOptionsOnSearch(e.val_keyword);n("idle");let i=L.InitOptions(m||[]);e.set_options(i)}),300,a)},[e.val_keyword]);let o=[],f=L.FilterSelectableOptions(e,!0),v=L.FilterSelectableOptions(e);f.forEach((a,m)=>{let{type:i,value:r}=a,y=e.val_optionFocused==r,w=e.val_status.dataValue.includes(r),b=e.rootStates.SelectorComponent;o.push(l(b,{option:a,isFocused:y,isSelected:w,addCallback:()=>{e.set_status(C=>{let _=[...C.dataValue];return s.scope(()=>{if(r===null)return _=[];C.dataValue.includes(r)?_=_.filter(D=>D!==r):e.rootStates.multiSelect?_.push(r):_=[r]}),O(S({},C),{dataValue:_,eventType:"update",eventID:W()})})}},s.Stringify(r)||W()))}),v.length||(o=[l(N.Supplement,{padding:[0,1],fontColor:"4.thin",children:"\u5019\u88DC\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093"},"no-selector-notice")]),c=="fetch"&&(o=[P(q.Left,{padding:1,fontColor:"3.blur",children:[l(se.Theme.R,{showInitial:!0}),l(N.Supplement,{children:"Loading..."})]},"loader")]);let p={position:"absolute",minWidth:1,freeCSS:{zIndex:1e3}};switch(e.rootStates.SelectorPosition){case 1:p.bottom="100%",p.left=0,p.paddingBottom="1/3";break;case 2:p.bottom="100%",p.right=0,p.paddingBottom="1/3";break;case 3:p.top="100%",p.left=0,p.paddingTop="1/3";break;case 4:p.top="100%",p.right=0,p.paddingTop="1/3";break;default:break}return l(x,O(S({},p),{children:l(ue.Body,O(S({className:U("Selector"),borderRadius:"2.tone.secondary",ssCardBox:!0,boxShadow:"1.normal",overflow:"auto"},e.rootStates.SelectorStyles),{freeCSS:S({maxHeight:12*24},(d=e.rootStates.SelectorStyles)==null?void 0:d.freeCSS),children:l(re,{gap:"1/12",padding:[1,0],children:o})}))}))},Selected:e=>{let{rootStates:t,val_status:u,set_status:c,val_optionsDict:n}=e,o=[];return u.dataValue.forEach(f=>{let v=n[s.Stringify(f)];if(!v)return;let p=t.SelectedComponent,d=v.label;v.value===null&&(d=""),o.push(l(x,{className:U("SelectedCell"),children:l(p,{value:v.value,label:d,removeCallback:a=>{if(a.stopPropagation(),a.preventDefault(),t.disabled)return;let m=[...u.dataValue];m=m.filter(i=>i!==f),c(i=>O(S({},i),{dataValue:m,eventType:"update",eventID:W()}))}})},s.Stringify(v.value)))}),l(X,{children:o})},Core:e=>{var A;let{value:t}=e,[u,c]=I(!1),[n,o]=I(!1),[f,v]=I(!1),[p,d]=I(""),[a,m]=I(e.options),[i,r]=I((A=e.value[0])!=null?A:null),[y,w]=I({}),[b,C]=I(z.DefaultStatus(e.componentID,t)),[_,T]=I({ok:!1,notice:[]}),D=ne(!1);E(()=>{D.current?m(e.options):D.current=!0},[e.options]),E(()=>{if(!a.length)return;let $=[...a],J=S({},y);$.forEach(H=>{H.type!="label"&&(J[s.Stringify(H.value)]=H)}),w(J)},[a]);let R={rootStates:e,val_options:a,set_options:m,val_optionFocused:i,set_optionFocused:r,val_optionsDict:y,set_optionsDict:w,val_preventDynamicSearchOnKeywordChange:n,set_preventDynamicSearchOnKeywordChange:o,val_preventOpenSelectorOnFocus:u,set_preventOpenSelectorOnFocus:c,val_selectorOpen:f,set_selectorOpen:v,val_keyword:p,set_keyword:d,val_status:b,set_status:C,val_validate:_,set_validate:T},K=!!e.multiSelect;z.CommonEffects({type:K?"autocomplete.multi":"autocomplete.single",states:e,val_status:b,set_status:C,val_validate:_,set_validate:T,SystemValidation:me});let V=b.dataValue.length&&b.dataValue[0]!==null;return V=V||f,P(pe,{val_status:b,set_status:C,val_validate:_,states:e,children:[l(Se,{componentID:e.componentID,fontSize:e.fontSize,required:e.required,label:e.label,isActive:V}),l(B.Shallow,S({},R)),l(B.Button,S({},R))]})}},te=e=>{var u;let t=S({},e);return t=O(S({value:[],min:0,max:65535,multiSelect:!0,SearchInput:!0,emptySelect:!0,SelectorComponent:({option:c,isSelected:n,isFocused:o,addCallback:f})=>c.type=="selector"?l(Z.Sub.S,{color:"cloud",backgroundColor:"trans",borderRadius:0,fontColor:"2.normal",textAlign:"left",padding:["1/2",1.5],isActive:o,isActiveStyles:{backgroundColor:"cloud"},onClick:v=>{f()},children:P(q.Left,{gap:"1/2",children:[n&&l(M.Check,{fontColor:"theme"}),l(N.Supplement,{transition:"short",children:c.label})]})}):l(X,{children:c.label}),SelectedComponent:({value:c,label:n,removeCallback:o})=>P(q.Left,{ssCardBox:"cloud",borderRadius:"2.tone.secondary",fontSize:"1.mini",padding:"1/2",gap:0,children:[l(x,{padding:[0,"1/4"],children:n}),l(Z.Sub,{flexSizing:"none",color:"cloud",fontColor:"white",backgroundColor:"layer.5",isRounded:!0,padding:"1/4",onClick:o,freeCSS:{lineHeight:1,aspectRatio:"1/1"},children:l(M.Times,{ssSphere:1})})]}),SelectorPosition:3},t),{freeCSS:S({cursor:"pointer"},t.freeCSS)}),t.multiSelect||(t.min=0,t.max=1),t.options=t.options||[],t.emptySelect&&(t.options=[{value:null,label:l(N.Supplement,{fontColor:"4.thin",children:"\u9078\u629E\u3092\u89E3\u9664"})},...t.options]),t.value=s.flatArray((u=t.value)!=null?u:null),t.options=L.InitOptions(t.options),s.is.nullish(t.rightIcon)&&(t.rightIcon=l(ee,{ssSphere:2,children:l(M.Search,{})}),t.disabled&&(t.rightIcon=l(ee,{ssSphere:2,fontColor:"5.translucent",children:l(M.Ban,{})}))),t.rightIcon&&(t=S({paddingRight:3},t)),t.leftIcon&&(t=S({paddingLeft:3},t)),l(ce,{componentID:t.componentID,children:B.Core,states:de(t)})};export{te as Autocomplete,te as default};
1
+ import{b as S,c as O,d as Q,e as Y}from"../../chunk-C5N2D3ZX.js";import{Fragment as X,jsx as n,jsxs as B}from"react/jsx-runtime";import{useState as I,useEffect as F,useRef as ne}from"react";import s,{UUID as K}from"jmini";import{ExtractStyles as ae}from"../../@utils";import{Box as x,Span as ie,FAI as M,Column as re}from"../../atoms";import{Literal as W,Row as q}from"../../mols";import{Button as Z}from"../Button";import{Loader as se}from"../Loader";import{Sheet as ue}from"../Sheet";import{OptionalInputWrapper as ce,BoxWrapper as pe,CoreEffects as N,DefaultBoxishStyles as de}from"./core";import{InputAutocompleteClasses as z}from"../../@styles/componentClasses";import{InputLabel as Se}from"./Label";import{RightIcon as ee}from".";function me(e){let{value:t,states:p}=e,{required:u,options:a,min:o,max:d}=p;o=o||0,d=d||65535;let i=[],h=t.filter(c=>c!==null).length;return u&&(h||i.push({type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"})),h<o&&i.push({type:"invalid",label:o+"\u500B\u4EE5\u4E0A\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044"}),h>d&&i.push({type:"invalid",label:d+"\u500B\u307E\u3067\u9078\u629E\u3067\u304D\u307E\u3059"}),{ok:!i.filter(({type:c})=>c=="invalid").length,notice:i}}const U={InitOptions:e=>{let t=[];return e.forEach(p=>{let{type:u,label:a,value:o,searchValue:d}=p,i=d||(s.is.string(a)?a:"")||(s.is.string(o)?o:"");s.is.nullish(a)&&(a=String(o)),t.push(O(S({},p),{searchValue:i,type:u||"selector",label:a,value:o}))}),t},FilterSelectableOptions:(e,t,p)=>{let u=e;return p||(u=e.filter(a=>a.type!="label")),s.scope(()=>{if(!t)return;let a=t.toLower().replace(/ /g,"");u=u.filter(o=>(o.searchValue||"").toLower().replace(/ /g,"").includes(a))}),u}},L={Shallow:e=>{let{rootStates:t,val_status:p}=e,u=ae(t);return n(x,{position:"absolute",top:0,left:0,right:0,height:0,overflow:"hidden",opacity:"trans",freeCSS:{zIndex:3,pointerEvents:"none"},children:n(W.Description,O(S({className:t.className},u),{position:"absolute",width:1,freeCSS:O(S({},u.freeCSS),{color:"orange"}),"data-id":"shallow_"+p.componentID,children:n(x,{"data-input-value-shallow":p.componentID,children:"A"})}))})},Button:e=>{let{rootStates:t,val_keyword:p,set_keyword:u,val_optionFocused:a,set_optionFocused:o,val_options:d,set_options:i,val_optionsDict:h,set_optionsDict:c,val_preventOpenSelectorOnFocus:r,set_preventOpenSelectorOnFocus:m,val_selectorOpen:l,set_selectorOpen:f,val_status:v,set_status:C,val_validate:_,set_validate:g}=e,j=t,{tone:D,required:w,form:T,className:R,multiSelect:P,enableFormSubmit:V,checkValidationAtFirst:A,onValidate:$,onUpdateValue:J,onUpdateValidValue:H,value:fe="",options:ve,leftIndicator:ye,rightIndicator:he,leftIcon:_e,rightIcon:ge,componentID:be,status_id:Oe,wrapStyles:Ie,emptySelect:Ce,SearchInput:De,SearchInputPlaceholder:we,SelectedComponent:Ve,SelectorComponent:ke,SelectorStyles:Te,SelectorPosition:Re,DynamicOptionsOnSearch:xe}=j,b=Q(j,["tone","required","form","className","multiSelect","enableFormSubmit","checkValidationAtFirst","onValidate","onUpdateValue","onUpdateValidValue","value","options","leftIndicator","rightIndicator","leftIcon","rightIcon","componentID","status_id","wrapStyles","emptySelect","SearchInput","SearchInputPlaceholder","SelectedComponent","SelectorComponent","SelectorStyles","SelectorPosition","DynamicOptionsOnSearch"]);return F(()=>{var k,E;if(t.disabled||!l)return;let y=U.FilterSelectableOptions(e.val_options,p,!1);o((E=(k=y[0])==null?void 0:k.value)!=null?E:null)},[p]),F(()=>{v.eventType!="init"&&(t.max==v.dataValue.length?(f(!1),m(!0),setTimeout(()=>{let y=s('[data-input-origin="'+t.componentID+'"]');y&&y.focus()},10)):s("#SearchInput_"+t.componentID).focus())},[v.dataValue]),F(()=>{let y="autocomplete-click-"+t.componentID;if(l){if(!s('[data-input-origin="'+t.componentID+'"]'))return;s("#SearchInput_"+t.componentID).focus(),s(document).addEvent({eventID:y,eventType:"mousedown",callback:E=>{let G=s(E.target),oe=!!s(G).parent("."+z("Core")).length,le=!!s(G).parent("."+z("Selector")).length;oe||le||(f(!1),E.preventDefault(),E.stopPropagation())},options:{passive:!1}})}else s(document).removeEvent([y]),u("")},[l]),B(X,{children:[n(x,O(S({tabIndex:0},b),{"data-disabled":t.disabled,"data-show-validation":N.isShowValidation(_,v,!!A),"data-component-id":v.componentID,"data-input-origin":v.componentID,"data-focus":!!l,className:[R,z("Core")].join(" "),onFocus:y=>{if(b!=null&&b.onFocus&&(b==null||b.onFocus(y)),!t.disabled){if(r)return m(!1);f(!0),y.preventDefault()}},onClick:y=>{b!=null&&b.onClick&&(b==null||b.onClick(y)),!t.disabled&&f(!0)},onKeyDown:y=>{let{key:k}=y;V&&N.SubmitForm(y,T),!l&&(k==" "||k=="ArrowDown"||k=="ArrowUp"||k=="Enter")&&f(!0)},children:B(q.Left,{flexWrap:!0,gap:"1/3",freeCSS:{letterSpacing:".5px"},children:[n(L.Selected,S({},e)),n(ie,{width:0,overflow:"hidden",opacity:"trans",children:"A"}),n(L.SearchInput,S({},e))]})})),l&&n(L.Selector,S({},e))]})},SearchInput:e=>{let{rootStates:t}=e,[p,u]=I(!1);return t.disabled||!e.val_selectorOpen?null:n(x,{id:"SearchInput_"+t.componentID,placeholder:t.SearchInputPlaceholder||"\u691C\u7D22...",opacity:e.val_selectorOpen?"max":"trans",transition:"middle",flexSizing:0,htmlTag:"input",border:"unset",backgroundColor:"trans",value:e.val_keyword,freeCSS:{outline:"none"},onCompositionStart:a=>{t.onCompositionStart&&t.onCompositionStart(a),u(!0)},onCompositionEnd:a=>{t.onCompositionEnd&&t.onCompositionEnd(a),u(!1)},onKeyDown:a=>{let{key:o,metaKey:d,ctrlKey:i}=a,h=d||i;o=="Escape"?(e.set_selectorOpen(!1),e.set_preventOpenSelectorOnFocus(!0),setTimeout(()=>{let c=s('[data-input-origin="'+t.componentID+'"]');c&&c.focus()},10)):o=="Tab"?e.set_selectorOpen(!1):o==" "?s.scope(()=>{e.val_selectorOpen||e.val_keyword||(a.preventDefault(),e.set_selectorOpen(!0))}):o=="Backspace"?s.scope(()=>{if(e.val_keyword)return;let c=[...e.val_status.dataValue];c.pop(),e.set_status(r=>O(S({},r),{dataValue:c,eventType:"update",eventID:K()}))}):o=="Enter"&&s.scope(()=>{if(p)return;if(!e.val_selectorOpen)return e.set_selectorOpen(!0);let c=e.val_options.find(m=>m.value==e.val_optionFocused);if(!c)return;let{value:r}=c;e.set_status(m=>{let l=[...m.dataValue];return s.scope(()=>{if(r===null)return l=[];m.dataValue.includes(r)?l=l.filter(v=>v!==r):t.multiSelect?l.push(r):l=[r]}),O(S({},m),{dataValue:l,eventType:"update",eventID:K()})}),e.set_keyword(""),e.set_preventDynamicSearchOnKeywordChange(!0)}),s.scope(()=>{if(!["ArrowDown","ArrowUp"].includes(o))return;if(a.preventDefault(),!e.val_selectorOpen)return e.set_selectorOpen(!0);let c=o=="ArrowDown"?1:-1,r=U.FilterSelectableOptions(e.val_options,e.val_keyword,!1),m=r.length-1,l=null;s.scope(()=>{var v,C,_,g,D,w,T,R,P,V;let f=r.findIndex(A=>A.value==e.val_optionFocused);if(f==-1&&(f=0),c==1){if(l=(C=(v=r[0])==null?void 0:v.value)!=null?C:null,h){l=(_=r[m].value)!=null?_:null;return}if(f==-1||f==m)return;l=(D=(g=r[f+1])==null?void 0:g.value)!=null?D:null}else{if(l=(w=r[m].value)!=null?w:null,h){l=(R=(T=r[0])==null?void 0:T.value)!=null?R:null;return}if(f==-1||f==0)return;l=(V=(P=r[f-1])==null?void 0:P.value)!=null?V:null}}),e.set_optionFocused(l)}),t.enableFormSubmit&&N.SubmitForm(a,e.rootStates.form)},onChange:a=>{let d=a.target.value;e.set_keyword(d)}},"searchInput")},Selector:e=>{var h;let[t,p]=I("idle"),[u,a]=I("idle");F(()=>{if(!e.val_selectorOpen||!e.rootStates.DynamicOptionsOnSearch)return;if(e.val_preventDynamicSearchOnKeywordChange)return e.set_preventDynamicSearchOnKeywordChange(!1);if(t=="idle")return p("ok");a("fetch");let c="autocomplete-search-"+e.rootStates.componentID;s.interval.once(()=>Y(void 0,null,function*(){let r=yield e.rootStates.DynamicOptionsOnSearch(e.val_keyword);a("idle");let m=U.InitOptions(r||[]);e.set_options(m)}),300,c)},[e.val_keyword]);let o=[],d=U.FilterSelectableOptions(e.val_options,e.rootStates.DynamicOptionsOnSearch?"":e.val_keyword,!0);d.forEach((c,r)=>{let{type:m,value:l}=c,f=e.val_optionFocused==l,v=e.val_status.dataValue.includes(l),C=e.rootStates.SelectorComponent;o.push(n(C,{option:c,isFocused:f,isSelected:v,addCallback:()=>{e.set_status(_=>{let g=[..._.dataValue];return s.scope(()=>{if(l===null)return g=[];_.dataValue.includes(l)?g=g.filter(w=>w!==l):e.rootStates.multiSelect?g.push(l):g=[l]}),O(S({},_),{dataValue:g,eventType:"update",eventID:K()})})}},s.Stringify(l)||K()))}),d.length||(o=[n(W.Supplement,{padding:[0,1],fontColor:"4.thin",children:"\u5019\u88DC\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093"},"no-selector-notice")]),u=="fetch"&&(o=[B(q.Left,{padding:1,fontColor:"3.blur",children:[n(se.Theme.R,{showInitial:!0}),n(W.Supplement,{children:"Loading..."})]},"loader")]);let i={position:"absolute",minWidth:1,freeCSS:{zIndex:1e3}};switch(e.rootStates.SelectorPosition){case 1:i.bottom="100%",i.left=0,i.paddingBottom="1/3";break;case 2:i.bottom="100%",i.right=0,i.paddingBottom="1/3";break;case 3:i.top="100%",i.left=0,i.paddingTop="1/3";break;case 4:i.top="100%",i.right=0,i.paddingTop="1/3";break;default:break}return n(x,O(S({},i),{children:n(ue.Body,O(S({className:z("Selector"),borderRadius:"2.tone.secondary",ssCardBox:!0,boxShadow:"1.normal",overflow:"auto"},e.rootStates.SelectorStyles),{freeCSS:S({maxHeight:12*24},(h=e.rootStates.SelectorStyles)==null?void 0:h.freeCSS),children:n(re,{gap:"1/12",padding:[1,0],children:o})}))}))},Selected:e=>{let{rootStates:t,val_status:p,set_status:u,val_optionsDict:a}=e,o=[];return p.dataValue.forEach(d=>{let i=a[s.Stringify(d)];if(!i)return;let h=t.SelectedComponent,c=i.label;i.value===null&&(c=""),o.push(n(x,{className:z("SelectedCell"),children:n(h,{value:i.value,label:c,removeCallback:r=>{if(r.stopPropagation(),r.preventDefault(),t.disabled)return;let m=[...p.dataValue];m=m.filter(l=>l!==d),u(l=>O(S({},l),{dataValue:m,eventType:"update",eventID:K()}))}})},s.Stringify(i.value)))}),n(X,{children:o})},Core:e=>{var A;let{value:t}=e,[p,u]=I(!1),[a,o]=I(!1),[d,i]=I(!1),[h,c]=I(""),[r,m]=I(e.options),[l,f]=I((A=e.value[0])!=null?A:null),[v,C]=I({}),[_,g]=I(N.DefaultStatus(e.componentID,t)),[D,w]=I({ok:!1,notice:[]}),T=ne(!1);F(()=>{T.current?m(e.options):T.current=!0},[e.options]),F(()=>{if(!r.length)return;let $=[...r],J=S({},v);$.forEach(H=>{H.type!="label"&&(J[s.Stringify(H.value)]=H)}),C(J)},[r]);let R={rootStates:e,val_options:r,set_options:m,val_optionFocused:l,set_optionFocused:f,val_optionsDict:v,set_optionsDict:C,val_preventDynamicSearchOnKeywordChange:a,set_preventDynamicSearchOnKeywordChange:o,val_preventOpenSelectorOnFocus:p,set_preventOpenSelectorOnFocus:u,val_selectorOpen:d,set_selectorOpen:i,val_keyword:h,set_keyword:c,val_status:_,set_status:g,val_validate:D,set_validate:w},P=!!e.multiSelect;N.CommonEffects({type:P?"autocomplete.multi":"autocomplete.single",states:e,val_status:_,set_status:g,val_validate:D,set_validate:w,SystemValidation:me});let V=_.dataValue.length&&_.dataValue[0]!==null;return V=V||d,B(pe,{val_status:_,set_status:g,val_validate:D,states:e,children:[n(Se,{componentID:e.componentID,fontSize:e.fontSize,required:e.required,label:e.label,isActive:V}),n(L.Shallow,S({},R)),n(L.Button,S({},R))]})}},te=e=>{var p;let t=S({},e);return t=O(S({value:[],min:0,max:65535,multiSelect:!0,SearchInput:!0,emptySelect:!0,SelectorComponent:({option:u,isSelected:a,isFocused:o,addCallback:d})=>u.type=="selector"?n(Z.Sub.S,{color:"cloud",backgroundColor:"trans",borderRadius:0,fontColor:"2.normal",textAlign:"left",padding:["1/2",1.5],isActive:o,isActiveStyles:{backgroundColor:"cloud"},onClick:i=>{d()},children:B(q.Left,{gap:"1/2",children:[a&&n(M.Check,{fontColor:"theme"}),n(W.Supplement,{transition:"short",children:u.label})]})}):n(X,{children:u.label}),SelectedComponent:({value:u,label:a,removeCallback:o})=>B(q.Left,{ssCardBox:"cloud",borderRadius:"2.tone.secondary",fontSize:"1.mini",padding:"1/2",gap:0,children:[n(x,{padding:[0,"1/4"],children:a}),n(Z.Sub,{flexSizing:"none",color:"cloud",fontColor:"white",backgroundColor:"layer.5",isRounded:!0,padding:"1/4",onClick:o,freeCSS:{lineHeight:1,aspectRatio:"1/1"},children:n(M.Times,{ssSphere:1})})]}),SelectorPosition:3},t),{freeCSS:S({cursor:"pointer"},t.freeCSS)}),t.multiSelect||(t.min=0,t.max=1),t.options=t.options||[],t.emptySelect&&(t.options=[{value:null,label:n(W.Supplement,{fontColor:"4.thin",children:"\u9078\u629E\u3092\u89E3\u9664"})},...t.options]),t.value=s.flatArray((p=t.value)!=null?p:null),t.options=U.InitOptions(t.options),s.is.nullish(t.rightIcon)&&(t.rightIcon=n(ee,{ssSphere:2,children:n(M.Search,{})}),t.disabled&&(t.rightIcon=n(ee,{ssSphere:2,fontColor:"5.translucent",children:n(M.Ban,{})}))),t.rightIcon&&(t=S({paddingRight:3},t)),t.leftIcon&&(t=S({paddingLeft:3},t)),n(ce,{componentID:t.componentID,children:L.Core,states:de(t)})};export{te as Autocomplete,te as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amotify",
3
- "version": "0.2.155",
3
+ "version": "0.2.156",
4
4
  "description": "UI Component for React,NextJS,esbuild",
5
5
  "scripts": {
6
6
  "start": "run-p clean build:*",