amotify 0.2.169 → 0.2.170
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.
|
@@ -22,6 +22,7 @@ declare namespace Autocomplete {
|
|
|
22
22
|
SearchInput?: boolean;
|
|
23
23
|
SearchInputPlaceholder?: string;
|
|
24
24
|
DynamicOptionsOnSearch?: DynamicOptionsOnSearch<T>;
|
|
25
|
+
DynamicOptionsOnSearchDelay?: number;
|
|
25
26
|
SelectedComponent?: {
|
|
26
27
|
(p: SelectedComponentProps<T>): JSX.Element;
|
|
27
28
|
};
|
|
@@ -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 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.Stringify(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};
|
|
1
|
+
import{b as S,c as b,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.Stringify(o||"")||"";s.is.nullish(a)&&(a=String(o)),t.push(b(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,b(S({className:t.className},u),{position:"absolute",width:1,freeCSS:b(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:D,val_validate:_,set_validate:g}=e,j=t,{tone:C,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:Oe,status_id:be,wrapStyles:Ie,emptySelect:De,SearchInput:Ce,SearchInputPlaceholder:we,SelectedComponent:Ve,SelectorComponent:ke,SelectorStyles:Te,SelectorPosition:Re,DynamicOptionsOnSearch:xe,DynamicOptionsOnSearchDelay:Ae}=j,O=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","DynamicOptionsOnSearchDelay"]);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,b(S({tabIndex:0},O),{"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(O!=null&&O.onFocus&&(O==null||O.onFocus(y)),!t.disabled){if(r)return m(!1);f(!0),y.preventDefault()}},onClick:y=>{O!=null&&O.onClick&&(O==null||O.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=>b(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]}),b(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,D,_,g,C,w,T,R,P,V;let f=r.findIndex(A=>A.value==e.val_optionFocused);if(f==-1&&(f=0),c==1){if(l=(D=(v=r[0])==null?void 0:v.value)!=null?D:null,h){l=(_=r[m].value)!=null?_:null;return}if(f==-1||f==m)return;l=(C=(g=r[f+1])==null?void 0:g.value)!=null?C: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)}),e.rootStates.DynamicOptionsOnSearchDelay||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),D=e.rootStates.SelectorComponent;o.push(n(D,{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]}),b(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,b(S({},i),{children:n(ue.Body,b(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=>b(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,D]=I({}),[_,g]=I(N.DefaultStatus(e.componentID,t)),[C,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)}),D(J)},[r]);let R={rootStates:e,val_options:r,set_options:m,val_optionFocused:l,set_optionFocused:f,val_optionsDict:v,set_optionsDict:D,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:C,set_validate:w},P=!!e.multiSelect;N.CommonEffects({type:P?"autocomplete.multi":"autocomplete.single",states:e,val_status:_,set_status:g,val_validate:C,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:C,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=b(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.
|
|
3
|
+
"version": "0.2.170",
|
|
4
4
|
"description": "UI Component for React,NextJS,esbuild",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "run-p clean build:*",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"@fortawesome/free-solid-svg-icons": "^6.6.0",
|
|
91
91
|
"@fortawesome/react-fontawesome": "^0.2.0",
|
|
92
92
|
"dotenv": "^16.4.6",
|
|
93
|
-
"jmini": "^0.0.
|
|
93
|
+
"jmini": "^0.0.75",
|
|
94
94
|
"react": "^18.3.1"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|