amotify 0.2.158 → 0.2.160

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.
@@ -0,0 +1 @@
1
+ import { } from 'amotify'
@@ -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 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 +1 @@
1
- import{b as n,c as u,d as z}from"../../chunk-C5N2D3ZX.js";import{Fragment as H,jsx as a,jsxs as w}from"react/jsx-runtime";import c,{UUID as R}from"jmini";import{useState as k,useEffect as oe}from"react";import{ExtractStyles as Te}from"../../@utils";import{Box as I,Span as xe,FAI as ne,Column as Fe}from"../../atoms";import{Literal as B,Row as re}from"../../mols";import{Button as we}from"../Button";import{Sheet as Re}from"../Sheet";import{OptionalInputWrapper as ke,BoxWrapper as Ae,CoreEffects as F,DefaultBoxishStyles as Ee}from"./core";import{InputAutocompleteClasses as A}from"../../@styles/componentClasses";import{InputLabel as Be}from"./Label";import{RightIcon as Le}from".";function We(e){let{value:t,states:o}=e,{required:l,options:y}=o,p=[];return l&&t===null&&p.push({type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"}),{ok:!p.filter(({type:S})=>S=="invalid").length,notice:p}}const se={FilterSelectableOptions:(e,t)=>{let o=e.rootStates.options;return t||(o=o.filter(l=>l.type!="label")),o}},C={Shallow:e=>{let{rootStates:t,val_status:o}=e,l=Te(t);return a(I,{position:"absolute",top:0,left:0,right:0,height:0,overflow:"hidden",opacity:"trans",freeCSS:{zIndex:3,pointerEvents:"none"},children:a(B.Description,u(n({className:t.className},l),{position:"absolute",width:1,freeCSS:u(n({},l.freeCSS),{color:"orange"}),children:a(I,{"data-input-value-shallow":o.componentID,children:"A"})}))})},Button:e=>w(H,{children:[a(C.LegacySelector,n({},e)),a(C.Original,n({},e))]}),Placeholder:e=>!e.rootStates.placeholder||e.val_status.dataValue!==null?null:a(I,{position:"absolute",opacity:"middle",fontColor:"3.blur",children:e.rootStates.placeholder||""}),Original:e=>{let{rootStates:t,val_preventOpenSelectorOnFocus:o,set_preventOpenSelectorOnFocus:l,val_optionFocused:y,set_optionFocused:p,val_validate:S,set_validate:h,val_status:s,set_status:g,val_selectorOpen:d,set_selectorOpen:f}=e,U=t,{tone:D,required:E,form:L,className:W,label:ue,isLabelActive:ce,placeholder:pe,enableFormSubmit:P,emptySelect:$,checkValidationAtFirst:M,onValidate:Se,onUpdateValue:de,onUpdateValidValue:fe,value:N="",options:K,leftIndicator:me,rightIndicator:j,leftIcon:ve,rightIcon:ye,componentID:be,status_id:ge,wrapStyles:he,SelectedCellStyles:Ie,SelectorCellStyles:Ce,SelectorMode:_e,SelectorStyles:Ve,SelectorPosition:De}=U,r=z(U,["tone","required","form","className","label","isLabelActive","placeholder","enableFormSubmit","emptySelect","checkValidationAtFirst","onValidate","onUpdateValue","onUpdateValidValue","value","options","leftIndicator","rightIndicator","leftIcon","rightIcon","componentID","status_id","wrapStyles","SelectedCellStyles","SelectorCellStyles","SelectorMode","SelectorStyles","SelectorPosition"]);return oe(()=>{if(e.rootStates.SelectorMode!="original"||t.disabled)return;let i="select-click-"+t.componentID;if(d){if(!c('[data-input-origin="'+t.componentID+'"]'))return;c(document).addEvent({eventID:i,eventType:"click",callback:m=>{let O=c(m.target),T=!!c(O).parent("."+A("Core")).length;c(O).parent("."+A("Selector")).length||T||f(!1)}})}else c(document).removeEvent([i])},[d]),oe(()=>{if(e.rootStates.SelectorMode!="original"||s.eventType=="init"||!d)return;let i=c('[data-input-origin="'+t.componentID+'"]');i&&i.focus()},[s.dataValue]),e.rootStates.SelectorMode!="original"?null:w(H,{children:[a(I,u(n({tabIndex:0},r),{"data-disabled":t.disabled,"data-show-validation":F.isShowValidation(S,s,!!M),"data-component-id":s.componentID,"data-input-origin":s.componentID,className:[W,A("Core")].join(" "),onFocus:i=>{if(r!=null&&r.onFocus&&(r==null||r.onFocus(i)),!t.disabled){if(o)return l(!1);f(!0)}},onClick:i=>{r!=null&&r.onClick&&(r==null||r.onClick(i)),!t.disabled&&f(!0)},onKeyDown:i=>{let{key:b,metaKey:m,ctrlKey:O}=i,T=m||O;if(r!=null&&r.onKeyDown&&(r==null||r.onKeyDown(i)),P&&F.SubmitForm(i,L),!t.disabled){if(c.scope(()=>{if(!["ArrowDown","ArrowUp"].includes(b))return;if(i.preventDefault(),!d)return f(!0);let _=b=="ArrowDown"?1:-1,v=se.FilterSelectableOptions(e),q=v.length-1,V=null;c.scope(()=>{var J,X,G,Q,Y,Z,ee,te,le,ae;let x=v.findIndex(Oe=>Oe.value==y);if(_==1){if(V=(X=(J=v[0])==null?void 0:J.value)!=null?X:null,T){V=(G=v[q].value)!=null?G:null;return}if(x==-1||x==q)return;V=(Y=(Q=v[x+1])==null?void 0:Q.value)!=null?Y:null}else{if(V=(Z=v[q].value)!=null?Z:null,T){V=(te=(ee=v[0])==null?void 0:ee.value)!=null?te:null;return}if(x==-1||x==0)return;V=(ae=(le=v[x-1])==null?void 0:le.value)!=null?ae:null}}),p(V)}),b=="Escape")f(!1);else if(b=="Tab")f(!1);else if(b=="Backspace")g(_=>u(n({},_),{dataValue:null,eventType:"update",eventID:R()}));else if(b==" ")i.preventDefault(),f(!0);else if(b=="Enter"){if(!d)return f(!0);i.preventDefault();let _=t.options.find(v=>v.value==y);if(!_)return;g(v=>u(n({},v),{dataValue:_.value,eventType:"update",eventID:R()})),f(!1)}}},children:w(re.Left,{flexWrap:!0,gap:"1/3",freeCSS:{letterSpacing:".5px"},children:[a(C.Placeholder,n({},e)),a(C.Selected,n({},e)),a(xe,{width:0,overflow:"hidden",opacity:"trans",children:"A"})]})})),d&&a(C.Selector,n({},e))]})},LegacySelector:e=>{let{rootStates:t,val_preventOpenSelectorOnFocus:o,set_preventOpenSelectorOnFocus:l,val_optionFocused:y,set_optionFocused:p,val_validate:S,set_validate:h,val_status:s,set_status:g,val_selectorOpen:d,set_selectorOpen:f}=e,b=t,{tone:D,required:E,form:L,className:W,label:ue,isLabelActive:ce,placeholder:pe,enableFormSubmit:P,emptySelect:$,checkValidationAtFirst:M,onValidate:Se,onUpdateValue:de,onUpdateValidValue:fe,onKeyDown:N,onChange:K,value:me="",options:j,leftIndicator:ve,rightIndicator:ye,leftIcon:be,rightIcon:ge,componentID:he,status_id:Ie,wrapStyles:Ce,SelectedCellStyles:_e,SelectorCellStyles:Ve,SelectorMode:De,SelectorStyles:r,SelectorPosition:U}=b,i=z(b,["tone","required","form","className","label","isLabelActive","placeholder","enableFormSubmit","emptySelect","checkValidationAtFirst","onValidate","onUpdateValue","onUpdateValidValue","onKeyDown","onChange","value","options","leftIndicator","rightIndicator","leftIcon","rightIcon","componentID","status_id","wrapStyles","SelectedCellStyles","SelectorCellStyles","SelectorMode","SelectorStyles","SelectorPosition"]);return e.rootStates.SelectorMode!="legacy"?null:w(I,u(n({htmlTag:"select",tabIndex:0},i),{"data-disabled":t.disabled,"data-show-validation":F.isShowValidation(S,s,!!M),"data-component-id":s.componentID,"data-input-origin":s.componentID,className:[W,A("Core")].join(" "),onKeyDown:m=>{N&&N(m),P&&F.SubmitForm(m,L)},onChange:m=>{let{value:O}=m.target;S.ok&&h({ok:!1,notice:[]}),g(T=>u(n({},T),{dataValue:O,eventType:"update",eventID:R()})),K&&K(m)},children:[!!$&&a("option",{value:"null",children:"\u9078\u629E"}),j.map(m=>c.is.nullish(m.value)?null:a("option",{value:m.value,children:m.label},String(m.value)))]}))},Selector:e=>{var y;let t=[],o=se.FilterSelectableOptions(e,!0);o.forEach((p,S)=>{let{type:h,value:s}=p,g=e.val_optionFocused==s,d=e.val_status.dataValue===s;if(h=="selector"){t.push(a(we.Sub.S,u(n({color:"cloud",backgroundColor:"trans",borderRadius:0,fontColor:"2.normal",textAlign:"left",padding:["1/2",1],isActive:d||g,isActiveStyles:g?{backgroundColor:"cloud"}:{backgroundColor:"theme.opa.few",fontColor:"theme"}},e.rootStates.SelectorCellStyles),{onClick:f=>{e.set_status(D=>u(n({},D),{dataValue:s,eventType:"update",eventID:R()})),e.set_selectorOpen(!1),e.set_preventOpenSelectorOnFocus(!0)},children:w(re.Left,{gap:"1/2",children:[d&&a(ne.Check,{fontColor:"theme"}),a(B.Supplement,{transition:"short",flexSizing:0,children:p.label})]})}),String(s)));return}t.push(a(I,{children:p.label},R()))}),o.length||(t=[a(B.Supplement,{padding:[0,1],fontColor:"4.thin",children:"\u5019\u88DC\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093"},"no-selector-notice")]);let l={position:"absolute",minWidth:1,freeCSS:{zIndex:1e3}};switch(e.rootStates.SelectorPosition){case 1:l.bottom="100%",l.left=0,l.paddingBottom="1/3";break;case 2:l.bottom="100%",l.right=0,l.paddingBottom="1/3";break;case 3:l.top="100%",l.left=0,l.paddingTop="1/3";break;case 4:l.top="100%",l.right=0,l.paddingTop="1/3";break;default:break}return a(I,u(n({},l),{children:a(Re.Body,u(n({className:A("Selector"),ssCardBox:!0,borderRadius:"2.tone.secondary",boxShadow:"1.normal",overflow:"auto"},e.rootStates.SelectorStyles),{freeCSS:n({minWidth:12*6,maxHeight:12*24},(y=e.rootStates.SelectorStyles)==null?void 0:y.freeCSS),children:a(Fe,{gap:"1/12",padding:[1,0],children:t})}))}))},Selected:e=>{let t=[];return e.val_status.dataValue!==null&&c.scope(()=>{let o=e.rootStates.options.find(l=>c.is.equal(l.value,e.val_status.dataValue));o&&t.push(a(I,u(n({},e.rootStates.SelectedCellStyles),{children:o.label}),String(o.value)))}),a(H,{children:t})},Core:e=>{var E;let{value:t}=e,[o,l]=k(F.DefaultStatus(e.componentID,t)),[y,p]=k(!1),[S,h]=k(!1),[s,g]=k((E=e.value)!=null?E:null),[d,f]=k({ok:!1,notice:[]}),D={rootStates:e,val_preventOpenSelectorOnFocus:y,set_preventOpenSelectorOnFocus:p,val_optionFocused:s,set_optionFocused:g,val_selectorOpen:S,set_selectorOpen:h,val_status:o,set_status:l,val_validate:d,set_validate:f};return F.CommonEffects({type:"select",states:e,val_status:o,set_status:l,val_validate:d,set_validate:f,SystemValidation:We}),w(Ae,{val_status:o,set_status:l,val_validate:d,states:e,children:[a(Be,{componentID:e.componentID,fontSize:e.fontSize,required:e.required,label:e.label,isActive:e.isLabelActive||o.dataValue!==null}),a(C.Shallow,n({},D)),a(C.Button,n({},D))]})}},ie=e=>{var o;let t=n({},e);return t=u(n({emptySelect:!0,SelectorMode:"original",SelectorPosition:3},t),{freeCSS:n({cursor:"pointer"},t.freeCSS)}),t.emptySelect&&(t.options=[{value:null,label:a(B.Supplement,{fontColor:"4.thin",children:"\u672A\u9078\u629E"})},...t.options]),t.value=(o=t.value)!=null?o:null,t.options.forEach((l,y)=>{let{type:p,value:S,searchValue:h}=l,s=h||c.is.string(S)&&S||c.Stringify(S||"");t.options[y]=u(n({},l),{value:S,searchValue:s,type:p||"selector"})}),c.is.nullish(t.rightIcon)&&(t.rightIcon=a(Le,{ssSphere:2,children:a(ne.AngleDown,{})})),a(ke,{componentID:t.componentID,children:C.Core,states:Ee(t)})};export{ie as Select,ie as default};
1
+ import{b as n,c as u,d as z}from"../../chunk-C5N2D3ZX.js";import{Fragment as H,jsx as a,jsxs as w}from"react/jsx-runtime";import c,{UUID as R}from"jmini";import{useState as k,useEffect as oe}from"react";import{ExtractStyles as Te}from"../../@utils";import{Box as I,Span as xe,FAI as ne,Column as Fe}from"../../atoms";import{Literal as B,Row as re}from"../../mols";import{Button as we}from"../Button";import{Sheet as Re}from"../Sheet";import{OptionalInputWrapper as ke,BoxWrapper as Ae,CoreEffects as F,DefaultBoxishStyles as Ee}from"./core";import{InputAutocompleteClasses as A}from"../../@styles/componentClasses";import{InputLabel as Be}from"./Label";import{RightIcon as Le}from".";function We(e){let{value:t,states:o}=e,{required:l,options:y}=o,p=[];return l&&t===null&&p.push({type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"}),{ok:!p.filter(({type:S})=>S=="invalid").length,notice:p}}const se={FilterSelectableOptions:(e,t)=>{let o=e.rootStates.options;return t||(o=o.filter(l=>l.type!="label")),o}},C={Shallow:e=>{let{rootStates:t,val_status:o}=e,l=Te(t);return a(I,{position:"absolute",top:0,left:0,right:0,height:0,overflow:"hidden",opacity:"trans",freeCSS:{zIndex:3,pointerEvents:"none"},children:a(B.Description,u(n({className:t.className},l),{position:"absolute",width:1,freeCSS:u(n({},l.freeCSS),{color:"orange"}),children:a(I,{"data-input-value-shallow":o.componentID,children:"A"})}))})},Button:e=>w(H,{children:[a(C.LegacySelector,n({},e)),a(C.Original,n({},e))]}),Placeholder:e=>!e.rootStates.placeholder||e.val_status.dataValue!==null?null:a(I,{position:"absolute",opacity:"middle",fontColor:"3.blur",children:e.rootStates.placeholder||""}),Original:e=>{let{rootStates:t,val_preventOpenSelectorOnFocus:o,set_preventOpenSelectorOnFocus:l,val_optionFocused:y,set_optionFocused:p,val_validate:S,set_validate:h,val_status:s,set_status:g,val_selectorOpen:d,set_selectorOpen:f}=e,U=t,{tone:D,required:E,form:L,className:W,label:ue,isLabelActive:ce,placeholder:pe,enableFormSubmit:P,emptySelect:$,checkValidationAtFirst:M,onValidate:Se,onUpdateValue:de,onUpdateValidValue:fe,value:N="",options:K,leftIndicator:me,rightIndicator:j,leftIcon:ve,rightIcon:ye,componentID:be,status_id:ge,wrapStyles:he,SelectedCellStyles:Ie,SelectorCellStyles:Ce,SelectorMode:_e,SelectorStyles:Ve,SelectorPosition:De}=U,r=z(U,["tone","required","form","className","label","isLabelActive","placeholder","enableFormSubmit","emptySelect","checkValidationAtFirst","onValidate","onUpdateValue","onUpdateValidValue","value","options","leftIndicator","rightIndicator","leftIcon","rightIcon","componentID","status_id","wrapStyles","SelectedCellStyles","SelectorCellStyles","SelectorMode","SelectorStyles","SelectorPosition"]);return oe(()=>{if(e.rootStates.SelectorMode!="original"||t.disabled)return;let i="select-click-"+t.componentID;if(d){if(!c('[data-input-origin="'+t.componentID+'"]'))return;c(document).addEvent({eventID:i,eventType:"click",callback:m=>{let O=c(m.target),T=!!c(O).parent("."+A("Core")).length;c(O).parent("."+A("Selector")).length||T||f(!1)}})}else c(document).removeEvent([i])},[d]),oe(()=>{if(e.rootStates.SelectorMode!="original"||s.eventType=="init"||!d)return;let i=c('[data-input-origin="'+t.componentID+'"]');i&&i.focus()},[s.dataValue]),e.rootStates.SelectorMode!="original"?null:w(H,{children:[a(I,u(n({tabIndex:0},r),{"data-disabled":t.disabled,"data-show-validation":F.isShowValidation(S,s,!!M),"data-component-id":s.componentID,"data-input-origin":s.componentID,className:[W,A("Core")].join(" "),onFocus:i=>{if(r!=null&&r.onFocus&&(r==null||r.onFocus(i)),!t.disabled){if(o)return l(!1);f(!0)}},onClick:i=>{r!=null&&r.onClick&&(r==null||r.onClick(i)),!t.disabled&&f(!0)},onKeyDown:i=>{let{key:b,metaKey:m,ctrlKey:O}=i,T=m||O;if(r!=null&&r.onKeyDown&&(r==null||r.onKeyDown(i)),P&&F.SubmitForm(i,L),!t.disabled){if(c.scope(()=>{if(!["ArrowDown","ArrowUp"].includes(b))return;if(i.preventDefault(),!d)return f(!0);let _=b=="ArrowDown"?1:-1,v=se.FilterSelectableOptions(e),q=v.length-1,V=null;c.scope(()=>{var J,X,G,Q,Y,Z,ee,te,le,ae;let x=v.findIndex(Oe=>Oe.value==y);if(_==1){if(V=(X=(J=v[0])==null?void 0:J.value)!=null?X:null,T){V=(G=v[q].value)!=null?G:null;return}if(x==-1||x==q)return;V=(Y=(Q=v[x+1])==null?void 0:Q.value)!=null?Y:null}else{if(V=(Z=v[q].value)!=null?Z:null,T){V=(te=(ee=v[0])==null?void 0:ee.value)!=null?te:null;return}if(x==-1||x==0)return;V=(ae=(le=v[x-1])==null?void 0:le.value)!=null?ae:null}}),p(V)}),b=="Escape")f(!1);else if(b=="Tab")f(!1);else if(b=="Backspace")g(_=>u(n({},_),{dataValue:null,eventType:"update",eventID:R()}));else if(b==" ")i.preventDefault(),f(!0);else if(b=="Enter"){if(!d)return f(!0);i.preventDefault();let _=t.options.find(v=>v.value==y);if(!_)return;g(v=>u(n({},v),{dataValue:_.value,eventType:"update",eventID:R()})),f(!1)}}},children:w(re.Left,{flexWrap:!0,gap:"1/3",freeCSS:{letterSpacing:".5px"},children:[a(C.Placeholder,n({},e)),a(C.Selected,n({},e)),a(xe,{width:0,overflow:"hidden",opacity:"trans",children:"A"})]})})),d&&a(C.Selector,n({},e))]})},LegacySelector:e=>{let{rootStates:t,val_preventOpenSelectorOnFocus:o,set_preventOpenSelectorOnFocus:l,val_optionFocused:y,set_optionFocused:p,val_validate:S,set_validate:h,val_status:s,set_status:g,val_selectorOpen:d,set_selectorOpen:f}=e,b=t,{tone:D,required:E,form:L,className:W,label:ue,isLabelActive:ce,placeholder:pe,enableFormSubmit:P,emptySelect:$,checkValidationAtFirst:M,onValidate:Se,onUpdateValue:de,onUpdateValidValue:fe,onKeyDown:N,onChange:K,value:me="",options:j,leftIndicator:ve,rightIndicator:ye,leftIcon:be,rightIcon:ge,componentID:he,status_id:Ie,wrapStyles:Ce,SelectedCellStyles:_e,SelectorCellStyles:Ve,SelectorMode:De,SelectorStyles:r,SelectorPosition:U}=b,i=z(b,["tone","required","form","className","label","isLabelActive","placeholder","enableFormSubmit","emptySelect","checkValidationAtFirst","onValidate","onUpdateValue","onUpdateValidValue","onKeyDown","onChange","value","options","leftIndicator","rightIndicator","leftIcon","rightIcon","componentID","status_id","wrapStyles","SelectedCellStyles","SelectorCellStyles","SelectorMode","SelectorStyles","SelectorPosition"]);return e.rootStates.SelectorMode!="legacy"?null:w(I,u(n({htmlTag:"select",tabIndex:0},i),{"data-disabled":t.disabled,"data-show-validation":F.isShowValidation(S,s,!!M),"data-component-id":s.componentID,"data-input-origin":s.componentID,className:[W,A("Core")].join(" "),onKeyDown:m=>{N&&N(m),P&&F.SubmitForm(m,L)},onChange:m=>{let{value:O}=m.target;S.ok&&h({ok:!1,notice:[]}),g(T=>u(n({},T),{dataValue:O,eventType:"update",eventID:R()})),K&&K(m)},children:[!!$&&a("option",{value:"null",children:"\u9078\u629E"}),j.map(m=>c.is.nullish(m.value)?null:a("option",{value:m.value,children:m.label},String(m.value)))]}))},Selector:e=>{var y;let t=[],o=se.FilterSelectableOptions(e,!0);o.forEach((p,S)=>{let{type:h,value:s}=p,g=e.val_optionFocused==s,d=e.val_status.dataValue===s;if(h=="selector"){t.push(a(we.Sub.S,u(n({color:"cloud",backgroundColor:"trans",borderRadius:0,fontColor:"2.normal",textAlign:"left",padding:["1/2",1],isActive:d||g,isActiveStyles:g?{backgroundColor:"cloud"}:{backgroundColor:"theme.opa.few",fontColor:"theme"}},e.rootStates.SelectorCellStyles),{onClick:f=>{e.set_status(D=>u(n({},D),{dataValue:s,eventType:"update",eventID:R()})),e.set_selectorOpen(!1),e.set_preventOpenSelectorOnFocus(!0)},children:w(re.Left,{gap:"1/2",children:[d&&a(ne.Check,{fontColor:"theme"}),a(B.Supplement,{transition:"short",flexSizing:0,children:p.label})]})}),String(s)));return}t.push(a(I,{children:p.label},R()))}),o.length||(t=[a(B.Supplement,{padding:[0,1],fontColor:"4.thin",children:"\u5019\u88DC\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093"},"no-selector-notice")]);let l={position:"absolute",minWidth:1,freeCSS:{zIndex:1e3}};switch(e.rootStates.SelectorPosition){case 1:l.bottom="100%",l.left=0,l.paddingBottom="1/3";break;case 2:l.bottom="100%",l.right=0,l.paddingBottom="1/3";break;case 3:l.top="100%",l.left=0,l.paddingTop="1/3";break;case 4:l.top="100%",l.right=0,l.paddingTop="1/3";break;default:break}return a(I,u(n({},l),{children:a(Re.Body,u(n({className:A("Selector"),ssCardBox:!0,borderRadius:"2.tone.secondary",boxShadow:"1.normal",overflow:"auto"},e.rootStates.SelectorStyles),{freeCSS:n({minWidth:12*6,maxHeight:12*24},(y=e.rootStates.SelectorStyles)==null?void 0:y.freeCSS),children:a(Fe,{gap:"1/12",padding:[1,0],children:t})}))}))},Selected:e=>{let t=[];return e.val_status.dataValue!==null&&c.scope(()=>{let o=e.rootStates.options.find(l=>c.is.equal(l.value,e.val_status.dataValue));o&&t.push(a(I,u(n({},e.rootStates.SelectedCellStyles),{children:o.label}),String(o.value)))}),a(H,{children:t})},Core:e=>{var E;let{value:t}=e,[o,l]=k(F.DefaultStatus(e.componentID,t)),[y,p]=k(!1),[S,h]=k(!1),[s,g]=k((E=e.value)!=null?E:null),[d,f]=k({ok:!1,notice:[]}),D={rootStates:e,val_preventOpenSelectorOnFocus:y,set_preventOpenSelectorOnFocus:p,val_optionFocused:s,set_optionFocused:g,val_selectorOpen:S,set_selectorOpen:h,val_status:o,set_status:l,val_validate:d,set_validate:f};return F.CommonEffects({type:"select",states:e,val_status:o,set_status:l,val_validate:d,set_validate:f,SystemValidation:We}),w(Ae,{val_status:o,set_status:l,val_validate:d,states:e,children:[a(Be,{componentID:e.componentID,fontSize:e.fontSize,required:e.required,label:e.label,isActive:e.isLabelActive||o.dataValue!==null}),a(C.Shallow,n({},D)),a(C.Button,n({},D))]})}},ie=e=>{var o;let t=n({},e);return t=u(n({emptySelect:!0,SelectorMode:"original",SelectorPosition:3},t),{freeCSS:n({cursor:"pointer"},t.freeCSS)}),t.emptySelect&&(t.options=[{value:null,label:a(B.Supplement,{fontColor:"4.thin",children:"\u672A\u9078\u629E"})},...t.options]),t.value=(o=t.value)!=null?o:null,t.options.forEach((l,y)=>{let{type:p,value:S,searchValue:h}=l,s=h||c.is.string(S)&&S||c.Stringify(S||"")||"";t.options[y]=u(n({},l),{value:S,searchValue:s,type:p||"selector"})}),c.is.nullish(t.rightIcon)&&(t.rightIcon=a(Le,{ssSphere:2,children:a(ne.AngleDown,{})})),a(ke,{componentID:t.componentID,children:C.Core,states:Ee(t)})};export{ie as Select,ie as default};
@@ -29,6 +29,11 @@ declare namespace TextField {
29
29
  rightIndicator?: ReactElement | false;
30
30
  leftIcon?: ReactElement | false;
31
31
  rightIcon?: ReactElement | false;
32
+ defaultValidation?: {
33
+ reg: RegExp;
34
+ reason: ReactElement;
35
+ exist: boolean;
36
+ };
32
37
  };
33
38
  type WrapperStates = {
34
39
  rootStates: Input;
@@ -1,3 +1,3 @@
1
- import{b as l,c as m,d as Y,e as te}from"../../chunk-C5N2D3ZX.js";import{Fragment as le,jsx as n,jsxs as K}from"react/jsx-runtime";import b,{UUID as M,useStore as Ie}from"jmini";import{useState as Z,useEffect as G}from"react";import{$$fromRoot as ve,ExtractStyles as Ce}from"../../@utils";import{Box as F,FAI as Te}from"../../atoms";import{Literal as X}from"../../mols";import{Tips as ae,Button as we}from"..";import{faEye as Re}from"@fortawesome/free-solid-svg-icons/faEye";import{OptionalInputWrapper as ye,BoxWrapper as Ve,CoreEffects as U,DefaultBoxishStyles as De}from"./core";import{InputLabel as ke}from"./Label";import{LeftIcon as Ne,RightIcon as ie}from".";const Fe={katakana:{reg:/^[ァ-ヶー  ヲ-゚  ]*$/g,exist:!0,reason:"\u30AB\u30BF\u30AB\u30CA\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},"hankaku.katakana":{reg:/^[ヲ-゚  ]*$/g,exist:!0,reason:"\u534A\u89D2\u30AB\u30BF\u30AB\u30CA\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},number:{reg:/^-?[0-9\.]{0,}[0-9]{1,}$/g,exist:!0,reason:"\u534A\u89D2\u6570\u5B57\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},digitNumber:{reg:/^-?[0-9\,\.]{0,}[0-9]{1,}$/g,exist:!0,reason:"\u534A\u89D2\u6570\u5B57\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},fileName:{reg:/[¥\/:*\?\"\'\|\.\s\n\r\<\>]/g,exist:!1,reason:"\u7A7A\u767D\u307E\u305F\u306F\u4E00\u90E8\u306E\u7279\u6B8A\u6587\u5B57\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093"},creditCard:{reg:/^\d{14,16}$/g,exist:!0,reason:"14~16\u6841\u306E\u6570\u5B57\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},email:{reg:/^[A-Za-z0-9]{1}[A-Za-z0-9_.-]*@{1}[A-Za-z0-9_.-]+\.[A-Za-z0-9]+$/,exist:!0,reason:K(le,{children:[n(F,{children:"\u25CB\u25CB\u25CB\u25CB@\u25CB\u25CB\u25CB\u25CB.\u25CB\u25CB\u25CB\u306E\u5F62\u5F0F\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}),n(F,{children:"\u6700\u5F8C\u306E\u6587\u5B57\u306B.(\u30C9\u30C3\u30C8)\u3092\u5165\u308C\u308B\u3053\u3068\u306F\u3067\u304D\u307E\u305B\u3093"})]})},password:{reg:/^(?=[^A-Z]*[A-Z])(?=[^a-z]*[a-z])(?=[^0-9]*[0-9]).{8,}$/,exist:!0,reason:"8\u6587\u5B57\u4EE5\u4E0A\u3001\u534A\u89D2\u82F1\u6570\u5927\u5C0F\u6587\u5B57\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},tel:{reg:/.*$/g,exist:!0,reason:K(le,{children:[n(F,{children:"0\u304B\u3089\u59CB\u307E\u308B\u756A\u53F7\u306E\u307F\u5165\u529B\u53EF\u80FD\u3067\u3059"}),n(F,{children:"9~12\u6841\u306E\u6570\u5B57\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}),n(F,{children:"\u6570\u5B57\u306E\u307F\u5165\u529B\u53EF\u80FD\u3067\u3059"})]})},url:{reg:/^https?:\/\/[^\n\s]+(\.|\:)[^\n\s\.\:]+$/,exist:!0,reason:"URL\u5F62\u5F0F : http(s)://\u25EF\u25EF\u25EF\u25EF"},postal:{reg:/^\d{7}$/g,exist:!0,reason:"7\u6841\u306E\u6570\u5B57\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}},R={setSelection:e=>{let{id:a,restrict:o,val_status:r}=e,i=ve("#"+a)[0];if(i&&r.prevValue&&r.formatValue){let{formatValue:t,prevValue:d,caretFrom:u,caretTo:s}=r;if(o=="creditCard")t.length>=d.length&&u%5==0&&(u++,s++),i.setSelectionRange(u,s);else if(o=="postal")t.length==5&&d.length==3&&(u++,s++),i.setSelectionRange(u,s);else if(o=="digitNumber"){let g=t.length-d.length;g==2&&(u++,s++),g==-2&&(u--,s--),i.setSelectionRange(u,s)}}},Validation:{System:e=>{let{value:a,states:o}=e,{restrict:r="text",maxLength:i,multiline:t,required:d}=o,u=[];if(t||(i=i||255),b.is.exist(i)&&a.length>=Number(i)&&u.push({type:"invalid",label:i+"\u5B57\u4EE5\u5185\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}),a){let s=R.Validation.Text(a,r);s.ok||u.push({type:"invalid",label:s.body})}else d&&u.push({type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"});return{ok:!u.filter(({type:s})=>s=="invalid").length,notice:u}},Text:(e,a)=>{let o={ok:!0,body:""};return(()=>{let r=Fe[a];if(!r)return;let i=r.reason;if(r){let t=!!(+!!e.match(r.reg)^+!r.exist);o={ok:t,body:t?"":i}}})(),o},DataLeveling:e=>{let{restrict:a,allowDecimals:o,allowZeroStart:r,value:i=""}=e,t=String(i);["tel","number","digitNumber","test","postal","creditCard"].includes(a)&&(t=t.zen2hanNumber()),a=="katakana",a=="hankaku.katakana",["postal","creditCard"].includes(a)&&(t=t.removeLetters()),b.scope(()=>{if(!["number","digitNumber"].includes(a))return;t=t.replace(/(\.\d+)\..*/g,"$1").replace(/\.+/g,".").replace(/[^0-9.-]/g,"");let u=Number(t)<0||t[0]=="-";t=t.replace(/[^0-9.]/g,""),u&&(t="-"+t),o||(t=t.replace(/\.\d?/g,"")),b.scope(()=>{a=="number"&&(r||(t=t.replace(/^0(\d+)/g,"$1").replace(/^-0(\d+)/g,"-$1")))}),b.scope(()=>{let s=t.slice(-1);t&&s!="."&&s!="-"&&(b.is.exist(e.min)&&(t=String(Math.max(Number(t),Number(e.min)))),b.is.exist(e.max)&&(t=String(Math.min(Number(t),Number(e.max)))))}),b.scope(()=>{if(!t||t=="-"||a!="digitNumber")return;let s=Number(t)<0,g=String(Math.abs(Math.round(Number(t)))),C=t.split("."),V=[];for(let f=g.length-1;f>=0;f--){V.unshift(g[f]);let c=g.length-1-f+1;f!=0&&c%3==0&&V.unshift(",")}t=V.join(""),s&&(t="-"+t),(C==null?void 0:C.length)==2&&(t+="."+C[1]||"")})});let d=t;return a=="digitNumber"||(a=="postal"?t.length>=4&&(d=t.clip(0,3)+"-"+t.clip(3)):a=="creditCard"&&(d=t.replace(/.{4}(?=.)/g,"$& "))),t=t.replace(/,/g,""),{formatValue:d,dataValue:t}}},Shallow:e=>{let{rootStates:a,val_status:o}=e,r=o.dataValue||"";G(()=>{b.scope(()=>te(void 0,null,function*(){if(!a.multiline)return;let g=b('[data-input-origin="'+o.componentID+'"]'),C=b('[data-input-shallow="'+o.componentID+'"]'),V=b('[data-input-min-height-value-shallow="'+o.componentID+'"]'),f=b('[data-input-max-height-value-shallow="'+o.componentID+'"]');if(!g[0]||!C[0]||!V[0]||!f[0])return;let c=C.position(),_=V.position(),L=f.position(),S=0;a.autoHeight&&(S=c.height),S=Math.max(S,_.height),S=Math.min(S,L.height),g[0].style.height=S+"px"}))},[r]);let i=r||"";(!!r.match(/\n$/)||!r)&&(i+="T");let d="",u="";if(a.multiline){let g=a.minRows||1,C=a.maxRows||100;d=`
2
- T`.repeat(g-1),u=`
3
- T`.repeat(C-1)}let s=Ce(a);return K(F,{position:"absolute",top:0,left:0,right:0,height:0,overflow:"hidden",opacity:"trans",freeCSS:{zIndex:3,pointerEvents:"none"},children:[n(X.Description,m(l({className:a.className},s),{position:"absolute",width:1,freeCSS:m(l({},s.freeCSS),{color:"orange"}),"data-input-shallow":o.componentID,children:n(F,{"data-input-value-shallow":o.componentID,children:i})})),n(X.Description,m(l({className:a.className},s),{position:"absolute",left:0,freeCSS:m(l({},s.freeCSS),{backgroundColor:"transparent",color:"blue"}),"data-input-min-height-value-shallow":o.componentID,children:d})),n(X.Description,m(l({className:a.className},s),{position:"absolute",right:0,freeCSS:m(l({},s.freeCSS),{backgroundColor:"transparent",color:"red"}),"data-input-max-height-value-shallow":o.componentID,children:u}))]})},InputBox:e=>{let{rootStates:a,val_validate:o,set_validate:r,val_status:i,set_status:t,val_focus:d,set_focus:u,val_isComposing:s,set_isComposing:g}=e;if(a.multiline)return null;let ee=a,{componentID:C,tone:V,required:f,restrict:c="text",form:_,autoComplete:L="off",autoCapitalize:S="off",minRows:ne,maxRows:oe,multiline:re,autoHeight:se,enableFormSubmit:W,clearButton:ue=!1,allowDecimals:$,allowZeroStart:H,checkValidationAtFirst:P,onChange:O,onKeyDown:q,onValidate:me,onUpdateValue:ce,onUpdateValidValue:pe,value:de="",leftIndicator:fe,rightIndicator:ge,leftIcon:he,rightIcon:I,maxLength:xe,min:B,max:T,label:j,isLabelActive:Q,wrapStyles:Ee}=ee,p=Y(ee,["componentID","tone","required","restrict","form","autoComplete","autoCapitalize","minRows","maxRows","multiline","autoHeight","enableFormSubmit","clearButton","allowDecimals","allowZeroStart","checkValidationAtFirst","onChange","onKeyDown","onValidate","onUpdateValue","onUpdateValidValue","value","leftIndicator","rightIndicator","leftIcon","rightIcon","maxLength","min","max","label","isLabelActive","wrapStyles"]),be=c=="password"||c=="concealed"?"password":"text",Se=["number","digitNumber","creditCard"].includes(c)?"numeric":c=="email"?"email":"text";return n(F,m(l({htmlTag:"input",type:be,inputMode:Se,"data-disabled":a.disabled,"data-show-validation":U.isShowValidation(o,i,!!P),"data-component-id":i.componentID,"data-input-origin":i.componentID,value:i.formatValue,autoComplete:L,autoCapitalize:S,onKeyDown:h=>{let{key:w,target:E}=h;{let D=E,{selectionStart:k,selectionEnd:v}=D,A=Number(k),z=Number(v),N=i.formatValue[Number(A)],J=i.formatValue[Number(A)-1];w=="Delete"&&(c=="creditCard"&&N==" "||c=="postal"&&N=="-"||c=="digitNumber"&&N==",")&&(D.setSelectionRange(A+1,z+1),h.preventDefault()),w=="Backspace"&&(c=="creditCard"&&J==" "||c=="postal"&&J=="-"||c=="digitNumber"&&J==",")&&(D.setSelectionRange(A-1,z-1),h.preventDefault()),w=="Enter"||w=="Tab"}b.scope(()=>{["number","digitNumber","creditCard"].includes(c)&&w=="Clear"&&t(D=>m(l({},D),{dataValue:"",formatValue:"",eventType:"update",eventID:M()}))}),b.scope(()=>{var z;if(!["number","digitNumber"].includes(c)||!["ArrowUp","ArrowDown"].includes(w))return;let D=+(w=="ArrowUp")*2-1,k=i.dataValue.slice(-1),v=i.dataValue,A=((z=i.dataValue.split(".")[1])==null?void 0:z.length)||0;if(!k)v+="0";else if(k=="-")v+="0";else if(k==".")v+="0";else if(A){let N=Number(k)+D;v=v.slice(0,-1),N<0?v+="9":N>9?v+="0":v+=String(N)}else v=String(Number(i.dataValue.replace(/,/g,""))+D);o.ok&&r({ok:!1,notice:[]}),t(N=>m(l(l({},N),R.Validation.DataLeveling({allowDecimals:$,allowZeroStart:H,min:B,max:T,restrict:c,value:v})),{eventType:"update",eventID:M()})),h.preventDefault()}),q&&q(h),W&&U.SubmitForm(h,_)},onChange:h=>{let{value:w,selectionStart:E,selectionEnd:D}=h.target,k=R.Validation.DataLeveling({allowDecimals:$,allowZeroStart:H,min:B,max:T,restrict:c,value:w});s&&(k.formatValue=w),k.formatValue!=i.formatValue&&(o.ok&&r({ok:!1,notice:[]}),t(v=>m(l(l({},v),k),{prevValue:i.formatValue,eventType:"update",eventID:M(),caretFrom:Number(E),caretTo:Number(D)})),O&&O(h))},width:1},p),{onFocus:h=>{p!=null&&p.onFocus&&(p==null||p.onFocus(h)),u(!0)},onBlur:h=>{p!=null&&p.onBlur&&(p==null||p.onBlur(h)),u(!1)},onCompositionStart:h=>{p!=null&&p.onCompositionStart&&(p==null||p.onCompositionStart(h)),g(!0)},onCompositionEnd:h=>{if(p!=null&&p.onCompositionEnd&&(p==null||p.onCompositionEnd(h)),c=="text")return;let w=R.Validation.DataLeveling({allowDecimals:$,allowZeroStart:H,min:B,max:T,restrict:c,value:i.formatValue});t(E=>m(l(l({},E),w),{prevValue:E.formatValue,eventType:"update",eventID:M(),caretFrom:Number(E.formatValue.length+1),caretTo:Number(E.formatValue.length+1)})),g(!1)}}))},TextAreaBox:e=>{let{rootStates:a,val_focus:o,set_focus:r,val_validate:i,set_validate:t,val_status:d,set_status:u,isShallow:s}=e,B=a,{componentID:g,tone:C,required:V,form:f,label:c,isLabelActive:_,minRows:L,maxRows:S,multiline:ne,autoHeight:oe,allowDecimals:re,allowZeroStart:se,enableFormSubmit:W,maxLength:ue,checkValidationAtFirst:$,onChange:H,onKeyDown:P,onValidate:O,onUpdateValue:q,onUpdateValidValue:me,value:ce="",leftIndicator:pe,rightIndicator:de,leftIcon:fe,rightIcon:ge,wrapStyles:he}=B,I=Y(B,["componentID","tone","required","form","label","isLabelActive","minRows","maxRows","multiline","autoHeight","allowDecimals","allowZeroStart","enableFormSubmit","maxLength","checkValidationAtFirst","onChange","onKeyDown","onValidate","onUpdateValue","onUpdateValidValue","value","leftIndicator","rightIndicator","leftIcon","rightIcon","wrapStyles"]);return!a.multiline?null:n(F,m(l({htmlTag:"textarea","data-show-validation":U.isShowValidation(i,d,!!$),"data-input-origin":d.componentID,"data-component-id":d.componentID,value:d.dataValue,width:1},I),{onFocus:T=>{I!=null&&I.onFocus&&(I==null||I.onFocus(T)),r(!0)},onBlur:T=>{I!=null&&I.onBlur&&(I==null||I.onBlur(T)),r(!1)},onKeyDown:T=>{P&&P(T),W&&U.SubmitForm(T,f)},onChange:T=>{let{value:j}=T.target;i.ok&&t({ok:!1,notice:[]}),u(Q=>m(l({},Q),{dataValue:j,eventType:"update",eventID:M()})),H&&H(T)}}))}},_e=e=>{let{componentID:a,restrict:o="text",value:r="",min:i,max:t,allowDecimals:d,allowZeroStart:u}=e,[s,g]=Z(!1),[C,V]=Z(!1),[f,c]=Z(m(l({componentID:a},R.Validation.DataLeveling({allowDecimals:d,allowZeroStart:u,min:i,max:t,restrict:o,value:r})),{prevValue:"",eventType:"init",eventID:M(),caretFrom:null,caretTo:null})),[_,L]=Z({ok:!1,notice:[]}),S={rootStates:e,val_focus:s,set_focus:g,val_isComposing:C,set_isComposing:V,val_status:f,set_status:c,val_validate:_,set_validate:L};return U.CommonEffects({type:"textfield",states:e,val_status:f,set_status:c,val_validate:_,set_validate:L,SystemValidation:R.Validation.System,ExtraOverrideStates:l({},R.Validation.DataLeveling({allowDecimals:d,allowZeroStart:u,min:i,max:t,restrict:o,value:r}))}),G(()=>{R.setSelection({id:e.id,restrict:o,val_status:f})},[f]),K(Ve,{val_status:f,set_status:c,val_validate:_,states:S.rootStates,children:[n(ke,{componentID:e.componentID,fontSize:e.fontSize,required:e.required,label:e.label,isActive:e.isLabelActive||s||!!f.dataValue}),n(R.Shallow,l({},S)),n(R.InputBox,l({},S)),n(R.TextAreaBox,l({},S))]})},y=e=>(e=l({autoHeight:!0,restrict:"text",fontSize:"inherit"},e),e.multiline?(e.minRows=e.minRows||5,e.maxRows=e.maxRows||20):(e.minRows=1,e.maxRows=1),n(ye,{componentID:e.componentID,children:_e,states:De(e)})),x=y;x.Validate=R.Validation.Text,x.Katakana=e=>n(y,m(l({},e),{restrict:"katakana",multiline:!1,autoHeight:!1})),x.HankakuKatakana=e=>n(y,m(l({},e),{restrict:"hankaku.katakana",multiline:!1,autoHeight:!1})),x.CreditCard=e=>n(y,m(l({},e),{restrict:"creditCard",multiline:!1,autoHeight:!1})),x.Tel=e=>n(y,m(l({},e),{restrict:"tel",multiline:!1,autoHeight:!1})),x.Number=e=>n(y,m(l({},e),{restrict:"number",multiline:!1,autoHeight:!1})),x.DigitNumber=e=>n(y,m(l({},e),{restrict:"digitNumber",multiline:!1,autoHeight:!1})),x.Email=e=>n(y,m(l({},e),{restrict:"email",multiline:!1,autoHeight:!1})),x.Url=e=>n(y,m(l({},e),{restrict:"url",multiline:!1,autoHeight:!1})),x.Postal=e=>{let[a]=Z(M());return G(()=>()=>{Ie.delete(a)},[]),n(y,m(l({label:"\u90F5\u4FBF\u756A\u53F7"},e),{restrict:"postal",multiline:!1,autoHeight:!1,leftIcon:n(Ne,{ssSphere:2,fontColor:"4.thin",children:"\u3012"})}))},x.Password=e=>n(y,m(l({label:"\u30D1\u30B9\u30EF\u30FC\u30C9",rightIcon:n(ie,{ssSphere:2,padding:0,freeCSS:{pointerEvents:"all"},children:n(we.Sub,{ssSphere:2,borderRadius:"3.tone.tertiary",fontColor:"theme",flexCenter:!0,height:1,ssEffectsOnActive:["expand"],onMouseOver:a=>{ae.open(a.currentTarget,"\u30C6\u30AD\u30B9\u30C8\u3092\u8868\u793A",24)},onMouseLeave:ae.abort,tabIndex:-1,onClick:a=>{b(a.target).parent().parent().find("input").callback(o=>{let r=o[0];r.type=r.type==="password"?"text":"password"})},children:n(Te,{icon:Re})})}),restrict:"password"},e),{multiline:!1,autoHeight:!1})),x.Concealed=e=>n(x.Password,m(l({label:"\u79D8\u5BC6\u9375"},e),{restrict:"concealed"})),x.Money={JPY:e=>n(x.DigitNumber,m(l({rightIcon:n(ie,{ssSphere:2,fontColor:"4.thin",children:"\u5186"})},e),{multiline:!1,autoHeight:!1}))};export{x as TextField,_e as TextInput,x as default};
1
+ import{b as i,c as u,d as G,e as ae}from"../../chunk-C5N2D3ZX.js";import{Fragment as ne,jsx as n,jsxs as W}from"react/jsx-runtime";import b,{UUID as M,useStore as ve}from"jmini";import{useState as Z,useEffect as X}from"react";import{$$fromRoot as Ce,ExtractStyles as Te}from"../../@utils";import{Box as F,FAI as Re}from"../../atoms";import{Literal as j}from"../../mols";import{Tips as le,Button as we}from"..";import{faEye as ye}from"@fortawesome/free-solid-svg-icons/faEye";import{OptionalInputWrapper as Ve,BoxWrapper as De,CoreEffects as U,DefaultBoxishStyles as ke}from"./core";import{InputLabel as Ne}from"./Label";import{LeftIcon as Fe,RightIcon as ie}from".";const _e={katakana:{reg:/^[ァ-ヶー  ヲ-゚  ]*$/g,exist:!0,reason:"\u30AB\u30BF\u30AB\u30CA\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},"hankaku.katakana":{reg:/^[ヲ-゚  ]*$/g,exist:!0,reason:"\u534A\u89D2\u30AB\u30BF\u30AB\u30CA\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},number:{reg:/^-?[0-9\.]{0,}[0-9]{1,}$/g,exist:!0,reason:"\u534A\u89D2\u6570\u5B57\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},digitNumber:{reg:/^-?[0-9\,\.]{0,}[0-9]{1,}$/g,exist:!0,reason:"\u534A\u89D2\u6570\u5B57\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},fileName:{reg:/[¥\/:*\?\"\'\|\.\s\n\r\<\>]/g,exist:!1,reason:"\u7A7A\u767D\u307E\u305F\u306F\u4E00\u90E8\u306E\u7279\u6B8A\u6587\u5B57\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093"},creditCard:{reg:/^\d{14,16}$/g,exist:!0,reason:"14~16\u6841\u306E\u6570\u5B57\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},email:{reg:/^[A-Za-z0-9]{1}[A-Za-z0-9_.-]*@{1}[A-Za-z0-9_.-]+\.[A-Za-z0-9]+$/,exist:!0,reason:W(ne,{children:[n(F,{children:"\u25CB\u25CB\u25CB\u25CB@\u25CB\u25CB\u25CB\u25CB.\u25CB\u25CB\u25CB\u306E\u5F62\u5F0F\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}),n(F,{children:"\u6700\u5F8C\u306E\u6587\u5B57\u306B.(\u30C9\u30C3\u30C8)\u3092\u5165\u308C\u308B\u3053\u3068\u306F\u3067\u304D\u307E\u305B\u3093"})]})},password:{reg:/^(?=[^A-Z]*[A-Z])(?=[^a-z]*[a-z])(?=[^0-9]*[0-9]).{8,}$/,exist:!0,reason:"8\u6587\u5B57\u4EE5\u4E0A\u3001\u534A\u89D2\u82F1\u6570\u5927\u5C0F\u6587\u5B57\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},tel:{reg:/.*$/g,exist:!0,reason:W(ne,{children:[n(F,{children:"0\u304B\u3089\u59CB\u307E\u308B\u756A\u53F7\u306E\u307F\u5165\u529B\u53EF\u80FD\u3067\u3059"}),n(F,{children:"9~12\u6841\u306E\u6570\u5B57\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}),n(F,{children:"\u6570\u5B57\u306E\u307F\u5165\u529B\u53EF\u80FD\u3067\u3059"})]})},url:{reg:/^https?:\/\/[^\n\s]+(\.|\:)[^\n\s\.\:]+$/,exist:!0,reason:"URL\u5F62\u5F0F : http(s)://\u25EF\u25EF\u25EF\u25EF"},postal:{reg:/^\d{7}$/g,exist:!0,reason:"7\u6841\u306E\u6570\u5B57\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}},R={setSelection:e=>{let{id:a,restrict:r,val_status:s}=e,l=Ce("#"+a)[0];if(l&&s.prevValue&&s.formatValue){let{formatValue:t,prevValue:p,caretFrom:d,caretTo:o}=s;if(r=="creditCard")t.length>=p.length&&d%5==0&&(d++,o++),l.setSelectionRange(d,o);else if(r=="postal")t.length==5&&p.length==3&&(d++,o++),l.setSelectionRange(d,o);else if(r=="digitNumber"){let f=t.length-p.length;f==2&&(d++,o++),f==-2&&(d--,o--),l.setSelectionRange(d,o)}}},Validation:{System:e=>{let{value:a,states:r}=e,{restrict:s="text",defaultValidation:l,maxLength:t,multiline:p,required:d}=r,o=[];if(p||(t=t||255),b.is.exist(t)&&a.length>=Number(t)&&o.push({type:"invalid",label:t+"\u5B57\u4EE5\u5185\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}),a){let f=R.Validation.Text(a,s,l);f.ok||o.push({type:"invalid",label:f.body})}else d&&o.push({type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"});return{ok:!o.filter(({type:f})=>f=="invalid").length,notice:o}},Text:(e,a,r)=>{let s={ok:!0,body:""};return(()=>{let l=r||_e[a];if(!l)return;let t=l.reason;if(l){let p=!!(+!!e.match(l.reg)^+!l.exist);s={ok:p,body:p?"":t}}})(),s},DataLeveling:e=>{let{restrict:a,allowDecimals:r,allowZeroStart:s,value:l=""}=e,t=String(l);["tel","number","digitNumber","test","postal","creditCard"].includes(a)&&(t=t.zen2hanNumber()),a=="katakana",a=="hankaku.katakana",["postal","creditCard"].includes(a)&&(t=t.removeLetters()),b.scope(()=>{if(!["number","digitNumber"].includes(a))return;t=t.replace(/(\.\d+)\..*/g,"$1").replace(/\.+/g,".").replace(/[^0-9.-]/g,"");let d=Number(t)<0||t[0]=="-";t=t.replace(/[^0-9.]/g,""),d&&(t="-"+t),r||(t=t.replace(/\.\d?/g,"")),b.scope(()=>{a=="number"&&(s||(t=t.replace(/^0(\d+)/g,"$1").replace(/^-0(\d+)/g,"-$1")))}),b.scope(()=>{let o=t.slice(-1);t&&o!="."&&o!="-"&&(b.is.exist(e.min)&&(t=String(Math.max(Number(t),Number(e.min)))),b.is.exist(e.max)&&(t=String(Math.min(Number(t),Number(e.max)))))}),b.scope(()=>{if(!t||t=="-"||a!="digitNumber")return;let o=Number(t)<0,f=String(Math.abs(Math.round(Number(t)))),C=t.split("."),y=[];for(let g=f.length-1;g>=0;g--){y.unshift(f[g]);let m=f.length-1-g+1;g!=0&&m%3==0&&y.unshift(",")}t=y.join(""),o&&(t="-"+t),(C==null?void 0:C.length)==2&&(t+="."+C[1]||"")})});let p=t;return a=="digitNumber"||(a=="postal"?t.length>=4&&(p=t.clip(0,3)+"-"+t.clip(3)):a=="creditCard"&&(p=t.replace(/.{4}(?=.)/g,"$& "))),t=t.replace(/,/g,""),{formatValue:p,dataValue:t}}},Shallow:e=>{let{rootStates:a,val_status:r}=e,s=r.dataValue||"";X(()=>{b.scope(()=>ae(void 0,null,function*(){if(!a.multiline)return;let f=b('[data-input-origin="'+r.componentID+'"]'),C=b('[data-input-shallow="'+r.componentID+'"]'),y=b('[data-input-min-height-value-shallow="'+r.componentID+'"]'),g=b('[data-input-max-height-value-shallow="'+r.componentID+'"]');if(!f[0]||!C[0]||!y[0]||!g[0])return;let m=C.position(),_=y.position(),L=g.position(),S=0;a.autoHeight&&(S=m.height),S=Math.max(S,_.height),S=Math.min(S,L.height),f[0].style.height=S+"px"}))},[s]);let l=s||"";(!!s.match(/\n$/)||!s)&&(l+="T");let p="",d="";if(a.multiline){let f=a.minRows||1,C=a.maxRows||100;p=`
2
+ T`.repeat(f-1),d=`
3
+ T`.repeat(C-1)}let o=Te(a);return W(F,{position:"absolute",top:0,left:0,right:0,height:0,overflow:"hidden",opacity:"trans",freeCSS:{zIndex:3,pointerEvents:"none"},children:[n(j.Description,u(i({className:a.className},o),{position:"absolute",width:1,freeCSS:u(i({},o.freeCSS),{color:"orange"}),"data-input-shallow":r.componentID,children:n(F,{"data-input-value-shallow":r.componentID,children:l})})),n(j.Description,u(i({className:a.className},o),{position:"absolute",left:0,freeCSS:u(i({},o.freeCSS),{backgroundColor:"transparent",color:"blue"}),"data-input-min-height-value-shallow":r.componentID,children:p})),n(j.Description,u(i({className:a.className},o),{position:"absolute",right:0,freeCSS:u(i({},o.freeCSS),{backgroundColor:"transparent",color:"red"}),"data-input-max-height-value-shallow":r.componentID,children:d}))]})},InputBox:e=>{let{rootStates:a,val_validate:r,set_validate:s,val_status:l,set_status:t,val_focus:p,set_focus:d,val_isComposing:o,set_isComposing:f}=e;if(a.multiline)return null;let te=a,{componentID:C,tone:y,required:g,restrict:m="text",form:_,autoComplete:L="off",autoCapitalize:S="off",minRows:oe,maxRows:re,multiline:se,autoHeight:ue,enableFormSubmit:O,clearButton:me=!1,allowDecimals:$,allowZeroStart:H,checkValidationAtFirst:P,onChange:q,onKeyDown:J,onValidate:ce,onUpdateValue:pe,onUpdateValidValue:de,value:fe="",leftIndicator:ge,rightIndicator:xe,leftIcon:he,rightIcon:be,maxLength:I,min:K,max:B,label:V,isLabelActive:Q,defaultValidation:ee,wrapStyles:Le}=te,c=G(te,["componentID","tone","required","restrict","form","autoComplete","autoCapitalize","minRows","maxRows","multiline","autoHeight","enableFormSubmit","clearButton","allowDecimals","allowZeroStart","checkValidationAtFirst","onChange","onKeyDown","onValidate","onUpdateValue","onUpdateValidValue","value","leftIndicator","rightIndicator","leftIcon","rightIcon","maxLength","min","max","label","isLabelActive","defaultValidation","wrapStyles"]),Se=m=="password"||m=="concealed"?"password":"text",Ie=["number","digitNumber","creditCard"].includes(m)?"numeric":m=="email"?"email":"text";return n(F,u(i({htmlTag:"input",type:Se,inputMode:Ie,"data-disabled":a.disabled,"data-show-validation":U.isShowValidation(r,l,!!P),"data-component-id":l.componentID,"data-input-origin":l.componentID,value:l.formatValue,autoComplete:L,autoCapitalize:S,onKeyDown:x=>{let{key:T,target:E}=x;{let D=E,{selectionStart:k,selectionEnd:v}=D,A=Number(k),z=Number(v),N=l.formatValue[Number(A)],Y=l.formatValue[Number(A)-1];T=="Delete"&&(m=="creditCard"&&N==" "||m=="postal"&&N=="-"||m=="digitNumber"&&N==",")&&(D.setSelectionRange(A+1,z+1),x.preventDefault()),T=="Backspace"&&(m=="creditCard"&&Y==" "||m=="postal"&&Y=="-"||m=="digitNumber"&&Y==",")&&(D.setSelectionRange(A-1,z-1),x.preventDefault()),T=="Enter"||T=="Tab"}b.scope(()=>{["number","digitNumber","creditCard"].includes(m)&&T=="Clear"&&t(D=>u(i({},D),{dataValue:"",formatValue:"",eventType:"update",eventID:M()}))}),b.scope(()=>{var z;if(!["number","digitNumber"].includes(m)||!["ArrowUp","ArrowDown"].includes(T))return;let D=+(T=="ArrowUp")*2-1,k=l.dataValue.slice(-1),v=l.dataValue,A=((z=l.dataValue.split(".")[1])==null?void 0:z.length)||0;if(!k)v+="0";else if(k=="-")v+="0";else if(k==".")v+="0";else if(A){let N=Number(k)+D;v=v.slice(0,-1),N<0?v+="9":N>9?v+="0":v+=String(N)}else v=String(Number(l.dataValue.replace(/,/g,""))+D);r.ok&&s({ok:!1,notice:[]}),t(N=>u(i(i({},N),R.Validation.DataLeveling({allowDecimals:$,allowZeroStart:H,min:K,max:B,restrict:m,value:v})),{eventType:"update",eventID:M()})),x.preventDefault()}),J&&J(x),O&&U.SubmitForm(x,_)},onChange:x=>{let{value:T,selectionStart:E,selectionEnd:D}=x.target,k=R.Validation.DataLeveling({allowDecimals:$,allowZeroStart:H,min:K,max:B,restrict:m,value:T});o&&(k.formatValue=T),k.formatValue!=l.formatValue&&(r.ok&&s({ok:!1,notice:[]}),t(v=>u(i(i({},v),k),{prevValue:l.formatValue,eventType:"update",eventID:M(),caretFrom:Number(E),caretTo:Number(D)})),q&&q(x))},width:1},c),{onFocus:x=>{c!=null&&c.onFocus&&(c==null||c.onFocus(x)),d(!0)},onBlur:x=>{c!=null&&c.onBlur&&(c==null||c.onBlur(x)),d(!1)},onCompositionStart:x=>{c!=null&&c.onCompositionStart&&(c==null||c.onCompositionStart(x)),f(!0)},onCompositionEnd:x=>{if(c!=null&&c.onCompositionEnd&&(c==null||c.onCompositionEnd(x)),m=="text")return;let T=R.Validation.DataLeveling({allowDecimals:$,allowZeroStart:H,min:K,max:B,restrict:m,value:l.formatValue});t(E=>u(i(i({},E),T),{prevValue:E.formatValue,eventType:"update",eventID:M(),caretFrom:Number(E.formatValue.length+1),caretTo:Number(E.formatValue.length+1)})),f(!1)}}))},TextAreaBox:e=>{let{rootStates:a,val_focus:r,set_focus:s,val_validate:l,set_validate:t,val_status:p,set_status:d,isShallow:o}=e,B=a,{componentID:f,tone:C,required:y,form:g,label:m,isLabelActive:_,minRows:L,maxRows:S,multiline:oe,autoHeight:re,allowDecimals:se,allowZeroStart:ue,enableFormSubmit:O,maxLength:me,checkValidationAtFirst:$,onChange:H,onKeyDown:P,onValidate:q,onUpdateValue:J,onUpdateValidValue:ce,value:pe="",leftIndicator:de,rightIndicator:fe,leftIcon:ge,rightIcon:xe,defaultValidation:he,wrapStyles:be}=B,I=G(B,["componentID","tone","required","form","label","isLabelActive","minRows","maxRows","multiline","autoHeight","allowDecimals","allowZeroStart","enableFormSubmit","maxLength","checkValidationAtFirst","onChange","onKeyDown","onValidate","onUpdateValue","onUpdateValidValue","value","leftIndicator","rightIndicator","leftIcon","rightIcon","defaultValidation","wrapStyles"]);return!a.multiline?null:n(F,u(i({htmlTag:"textarea","data-show-validation":U.isShowValidation(l,p,!!$),"data-input-origin":p.componentID,"data-component-id":p.componentID,value:p.dataValue,width:1},I),{onFocus:V=>{I!=null&&I.onFocus&&(I==null||I.onFocus(V)),s(!0)},onBlur:V=>{I!=null&&I.onBlur&&(I==null||I.onBlur(V)),s(!1)},onKeyDown:V=>{P&&P(V),O&&U.SubmitForm(V,g)},onChange:V=>{let{value:Q}=V.target;l.ok&&t({ok:!1,notice:[]}),d(ee=>u(i({},ee),{dataValue:Q,eventType:"update",eventID:M()})),H&&H(V)}}))}},Ee=e=>{let{componentID:a,restrict:r="text",value:s="",min:l,max:t,allowDecimals:p,allowZeroStart:d}=e,[o,f]=Z(!1),[C,y]=Z(!1),[g,m]=Z(u(i({componentID:a},R.Validation.DataLeveling({allowDecimals:p,allowZeroStart:d,min:l,max:t,restrict:r,value:s})),{prevValue:"",eventType:"init",eventID:M(),caretFrom:null,caretTo:null})),[_,L]=Z({ok:!1,notice:[]}),S={rootStates:e,val_focus:o,set_focus:f,val_isComposing:C,set_isComposing:y,val_status:g,set_status:m,val_validate:_,set_validate:L};return U.CommonEffects({type:"textfield",states:e,val_status:g,set_status:m,val_validate:_,set_validate:L,SystemValidation:R.Validation.System,ExtraOverrideStates:i({},R.Validation.DataLeveling({allowDecimals:p,allowZeroStart:d,min:l,max:t,restrict:r,value:s}))}),X(()=>{R.setSelection({id:e.id,restrict:r,val_status:g})},[g]),W(De,{val_status:g,set_status:m,val_validate:_,states:S.rootStates,children:[n(Ne,{componentID:e.componentID,fontSize:e.fontSize,required:e.required,label:e.label,isActive:e.isLabelActive||o||!!g.dataValue}),n(R.Shallow,i({},S)),n(R.InputBox,i({},S)),n(R.TextAreaBox,i({},S))]})},w=e=>(e=i({autoHeight:!0,restrict:"text",fontSize:"inherit"},e),e.multiline?(e.minRows=e.minRows||5,e.maxRows=e.maxRows||20):(e.minRows=1,e.maxRows=1),n(Ve,{componentID:e.componentID,children:Ee,states:ke(e)})),h=w;h.Validate=R.Validation.Text,h.Katakana=e=>n(w,u(i({},e),{restrict:"katakana",multiline:!1,autoHeight:!1})),h.HankakuKatakana=e=>n(w,u(i({},e),{restrict:"hankaku.katakana",multiline:!1,autoHeight:!1})),h.CreditCard=e=>n(w,u(i({},e),{restrict:"creditCard",multiline:!1,autoHeight:!1})),h.Tel=e=>n(w,u(i({},e),{restrict:"tel",multiline:!1,autoHeight:!1})),h.Number=e=>n(w,u(i({},e),{restrict:"number",multiline:!1,autoHeight:!1})),h.DigitNumber=e=>n(w,u(i({},e),{restrict:"digitNumber",multiline:!1,autoHeight:!1})),h.Email=e=>n(w,u(i({},e),{restrict:"email",multiline:!1,autoHeight:!1})),h.Url=e=>n(w,u(i({},e),{restrict:"url",multiline:!1,autoHeight:!1})),h.Postal=e=>{let[a]=Z(M());return X(()=>()=>{ve.delete(a)},[]),n(w,u(i({label:"\u90F5\u4FBF\u756A\u53F7"},e),{restrict:"postal",multiline:!1,autoHeight:!1,leftIcon:n(Fe,{ssSphere:2,fontColor:"4.thin",children:"\u3012"})}))},h.Password=e=>n(w,u(i({label:"\u30D1\u30B9\u30EF\u30FC\u30C9",rightIcon:n(ie,{ssSphere:2,padding:0,freeCSS:{pointerEvents:"all"},children:n(we.Sub,{ssSphere:2,borderRadius:"3.tone.tertiary",fontColor:"theme",flexCenter:!0,height:1,ssEffectsOnActive:["expand"],onMouseOver:a=>{le.open(a.currentTarget,"\u30C6\u30AD\u30B9\u30C8\u3092\u8868\u793A",24)},onMouseLeave:le.abort,tabIndex:-1,onClick:a=>{b(a.target).parent().parent().find("input").callback(r=>{let s=r[0];s.type=s.type==="password"?"text":"password"})},children:n(Re,{icon:ye})})}),restrict:"password"},e),{multiline:!1,autoHeight:!1})),h.Concealed=e=>n(h.Password,u(i({label:"\u79D8\u5BC6\u9375"},e),{restrict:"concealed"})),h.Money={JPY:e=>n(h.DigitNumber,u(i({rightIcon:n(ie,{ssSphere:2,fontColor:"4.thin",children:"\u5186"})},e),{multiline:!1,autoHeight:!1}))};export{h as TextField,Ee as TextInput,h as default};
@@ -1 +1 @@
1
- import{a as ae,b as l,c as k,d as q}from"../../../chunk-C5N2D3ZX.js";import{Fragment as _e,jsx as y,jsxs as oe}from"react/jsx-runtime";import G,{UUID as N,useStore as L}from"jmini";import*as K from"jmini";import{useState as W,useEffect as Q,useRef as ce}from"react";import{$$fromRoot as pe,Config as re,ExtractStyles as ue}from"../../../@utils";import{Box as X,FAI as de}from"../../../atoms";import{Literal as fe,Row as he}from"../../../mols";import{Button as ie}from"../../Button";import ge from"../../Tooltips";import ye from"../../Sheet";import{faClock as De}from"@fortawesome/free-solid-svg-icons/faClock";import{faCalendarAlt as ve}from"@fortawesome/free-solid-svg-icons/faCalendarAlt";import{OptionalInputWrapper as Ie,BoxWrapper as Se,CoreEffects as z,DefaultBoxishStyles as Te}from"../core";import{RightIcon as be}from"..";import xe from"../Select";import{InputLabel as ke}from"../Label";import Ee from"./Picker";const F=" ~ ",we={clock:{defaultValue:"--:--",format:/^\d{2}\D\d{2}$/,ranges:[{type:"hour",from:0,length:2},{type:"minute",from:3,length:2}],sets:1},date:{defaultValue:"----/--/--",format:/^\d{4}\D\d{2}\D\d{2}$/,ranges:[{type:"year",from:0,length:4},{type:"month",from:5,length:2},{type:"date",from:8,length:2}],sets:1},week:{defaultValue:"----\u5E74\u7B2C--\u9031",format:/^\d{4}\D\d{2}$/,ranges:[{type:"year",from:0,length:4,region:6},{type:"week",from:6,length:2,region:3}],sets:1},month:{defaultValue:"----\u5E74--\u6708",format:/^\d{4}\D\d{2}$/,ranges:[{type:"year",from:0,length:4},{type:"month",from:5,length:2,region:3}],sets:1},year:{defaultValue:"----\u5E74",format:/^\d{4}$/,ranges:[{type:"year",from:0,length:4,region:5}],sets:1},dates:{defaultValue:"----/--/--",format:/^\d{4}\D\d{2}\D\d{2}$/,ranges:[{type:"year",from:0,length:4},{type:"month",from:5,length:2},{type:"date",from:8,length:2,region:5},{type:"year",from:10+F.length,length:4},{type:"month",from:15+F.length,length:2},{type:"date",from:18+F.length,length:2}],sets:2},months:{defaultValue:"----\u5E74--\u6708",format:/^\d{4}\D\d{2}$/,ranges:[{type:"year",from:0,length:4},{type:"month",from:5,length:2,region:6},{type:"year",from:8+F.length,length:4},{type:"month",from:13+F.length,length:2,region:3}],sets:2},dateWareki:{defaultValue:"----\u5E74--\u6708--\u65E5",format:/^\d{4}\D\d{2}\D\d{2}$/,ranges:[{type:"dateWareki",from:0,length:4,region:5},{type:"month",from:5,length:2,region:3},{type:"date",from:8,length:2,region:3}],sets:1}},O={PeriodMargin:" ~ ",DataLeveling:e=>{let{restrict:t,value:D,era:a}=e,d=G.flatArray(D||""),{defaultValue:f,format:h,ranges:v,sets:r}=we[t],m=[],o=t=="clock"?":":"/";for(let i=0;i<d.length;i++)d[i]=String(d[i]).replace(/\D/ig,o);for(let i=0;i<r;i++){let u=d[i]||"";if(!u.match(h))d[i]="",m.push(f);else{let x=f;u.split(/\D/).forEach((E,R)=>{if(R==0&&t=="dateWareki"){let S=Number(E);a!="year"&&(S>=2019?a=="reiwa"?S-=2018:a=="heisei"&&(S=31):S>=1989?a=="heisei"?S-=1988:a=="shouwa"&&(S=64):S>=1926?a=="shouwa"?S-=1925:a=="taisho"&&(S=15):S>=1912?a=="taisho"?S-=1911:a=="meiji"&&(S=45):S>=1868&&(S-=1867)),E=S.zeroEmbed(4)}x=x.replace(new RegExp("------------------".slice(0,E.length)),E)}),m.push(x)}}return{formatValue:m.join(F),dataValue:["dates","months"].includes(t)?d:d[0],ranges:v}},SystemValidation:e=>{let{states:t}=e,{restrict:D,min:a,max:d,required:f}=t,h=[],v=G.flatArray(e.value),r={empty:!1,escalated:1,filled:!0,correct:!0,prohibited:!1};(()=>{let m=D=="clock"?":":"/";for(let o=0;o<v.length;o++)v[o]=String(v[o]).replace(/\D/ig,m);for(let o=0;o<v.length;o++){let i=v[o],u=v[o-1];i.removeLetters()||(r.empty=!0),o>0&&(r.escalated&=+(i>=u))}r.escalated&&(r.empty||(D.match(/clock/)?v.forEach(o=>{let[i,u]=o.split(/\D+/);!i||!u?r.filled=!1:(Number(i)>23||Number(u)>59)&&(r.correct=!1)}):D.match(/date/)?v.forEach(o=>{let[i,u,x]=o.split(/\D+/);if(!i||!u||!x)r.filled=!1;else{let E=K.Time(o);(!E.validate||o!=E.toFormatYMD())&&(r.correct=!1)}}):D.match(/week/)?v.forEach(o=>{let[i,u]=o.split(/\D+/);if(!i||!u)r.filled=!1;else{let x=K.Time(i+"/01/01").weekday,R=K.Time(i+"/01/0"+(7-x+1)).addWeek(Number(u)-1);i!=String(R.year)&&(r.correct=!1)}}):D.match(/month/)?v.forEach(o=>{let[i,u]=o.split(/\D+/);!i||!u?r.filled=!1:K.Time([i,u,"01"].join("/")).validate||(r.correct=!1)}):D.match(/year/),r.filled&&r.correct&&v.forEach(o=>{{let i=Number(String(o).replace(/\D/ig,""));if(a&&Number(String(a).replace(/\D/ig,""))>i&&(r.prohibited=!0),d){let u=Number(String(d).replace(/\D/ig,""));i>u&&(r.prohibited=!0)}}})))})();{let{empty:m,escalated:o,filled:i,correct:u,prohibited:x}=r;m&&f&&(h=[{type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"}]),o||h.push({type:"invalid",label:"\u6642\u7CFB\u5217\u3092\u6B63\u3057\u304F\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}),u||h.push({type:"invalid",label:"\u7121\u52B9\u306A\u5024\u304C\u5165\u529B\u3055\u308C\u3066\u3044\u307E\u3059"}),i||h.push({type:"invalid",label:"\u6700\u5F8C\u307E\u3067\u5024\u3092\u57CB\u3081\u3066\u304F\u3060\u3055\u3044"}),x&&h.push({type:"invalid",label:oe(_e,{children:[y(X,{children:"\u5165\u529B\u7BC4\u56F2\u304C\u5236\u9650\u3055\u308C\u3066\u3044\u307E\u3059"}),"[",a||"\u4E0B\u9650\u7121\u3057","] ~ [",d||"\u4E0A\u9650\u7121\u3057","]"]})})}return{ok:!h.filter(({type:m})=>m=="invalid").length,notice:h}},KeyDownEvent:e=>{let{val_era:t,restrict:D,event:a,val_status:d,set_status:f,val_focus:h,set_focus:v}=e,{key:r,shiftKey:m,ctrlKey:o,metaKey:i}=a,u=o||i,{selectionStart:x,selectionEnd:E}=a.target,{index:R,prevIndex:S}=h,{ranges:$,formatValue:H}=d,C=$.length-1;if(["Tab","ArrowLeft","ArrowRight"].includes(r)){let I=0;if(r=="Tab"){let s=+!m*2-1;if(I=h.index+s,I<0||I>C)return}else{let s=r=="ArrowLeft"?-1:r=="ArrowRight"?1:0;u||x==0&&E==String(d.formatValue).length?I=s==1?C:0:I=Math.max(0,Math.min(R+s,C))}v(s=>k(l({},s),{index:I,prevIndex:R})),a.preventDefault()}if(["Backspace","ArrowUp","ArrowDown","0","1","2","3","4","5","6","7","8","9"].includes(r)){a.preventDefault();let I=R;I=Math.max(I,0),I=Math.min(I,C);let{type:s,from:B,length:Y}=$[I],_=H.slice(B,B+Y),p;if(r=="Backspace")p="------".slice(0,Y);else if(["ArrowUp","ArrowDown"].includes(r)){let w=r=="ArrowUp"?1:-1;_=_|0,p=_+w;let[n,c,T]=s=="dateWareki"?t=="year"?[0,2999,4]:t=="reiwa"?[1,2999,4]:t=="heisei"?[1,31,4]:t=="shouwa"?[1,64,4]:t=="taisho"?[1,15,4]:t=="meiji"?[1,45,4]:[0,0,0]:s=="minute"?[0,59,2]:s=="hour"?[0,23,2]:s=="date"?[1,31,2]:s=="week"?[1,53,2]:s=="month"?[1,12,2]:s=="year"?[0,2999,4]:[0,0,0];p>c?p=n:p<n&&(p=c),p=Number(p).zeroEmbed(T)}else if(["0","1","2","3","4","5","6","7","8","9"].includes(r)){let w=_|0,n=r,c=`${w}${n}`;if(S!=R&&(w=0,c="0"+n),s=="year"||s=="dateWareki"&&t=="year")Number(c)>1e4?p=n:p=c,(p|0)>1e3&&I++;else if(["hour","minute","date","week","month"].includes(s)||s=="dateWareki"&&t!="year"){let T=s=="dateWareki"?t=="reiwa"?100:t=="heisei"?31:t=="shouwa"?64:t=="taisho"?15:t=="meiji"?45:0:s=="minute"?59:s=="hour"?23:s=="date"?31:s=="week"?53:s=="month"?12:0;p=(c|0)>T?n:c,(Number(n)>Number(String(T)[0])||_=="0000".slice(0,String(T).length)&&(c!="0000".slice(0,String(T).length)||["minute","hour"].includes(s)&&S==R)||(c|0)>=ae(10,String(T).length-1))&&I++}s=="year"||s=="dateWareki"?p=(p|0).zeroEmbed(4):p=(p|0).zeroEmbed(2)}{let w=String(H).partReplace(B,String(p)),n=w.split(F).map(c=>c.replace(/(^\D|\D$)/,"").split(/\D+/).join(D=="clock"?":":"/").replace(/(^\D|\D$)/,""));if(D=="dateWareki"){let c=n[0].split(/\D/),[T,j,P]=c;c.length==3&&T&&(n=[[Number(T)-1+Number({year:1,reiwa:2019,heisei:1989,shouwa:1926,taisho:1912,meiji:1868}[t]),j,P].join("/")])}I=Math.max(I,0),I=Math.min(I,C),f(c=>k(l({},c),{dataValue:["dates","months"].includes(D)?n:n[0],formatValue:w,eventType:"update",eventID:N()})),v(c=>k(l({},c),{index:I,prevIndex:c.index}))}}}},ne={picker:{launch:e=>{let t=e.sheetID||N(),m=e,{onValueUpdate:D,min:a,max:d,era:f,restrict:h,defaultValue:v}=m,r=q(m,["onValueUpdate","min","max","era","restrict","defaultValue"]);ye.open(k(l({sheetID:t,type:"normal.middleCenter",size:"S",padding:0,closeAtAroundClick:!0,closeAtParentBlur:!1},r),{content:y(he.Center,{children:y(Ee,{restrict:h,min:a,max:d,era:f,defaultValue:v,sheetID:t,onValueUpdate:(o,i)=>{D(o,i)}})})}))},remove:e=>{ge.close(e)}}},Re={Shallow:e=>{let{rootStates:t,val_status:D}=e,a=ue(t);return y(X,{position:"absolute",top:0,left:0,right:0,height:0,overflow:"hidden",opacity:"trans",freeCSS:{zIndex:3,pointerEvents:"none"},children:y(fe.Description,k(l({className:t.className},a),{position:"absolute",width:1,freeCSS:k(l({},a.freeCSS),{color:"orange"}),children:y(X,{"data-input-value-shallow":D.componentID,children:"A"})}))})}},Ve=e=>{let ee=e,{tone:t,required:D,restrict:a="clock",componentID:d,era:f,form:h,name:v,min:r,max:m,className:o,enableFormSubmit:i,checkValidationAtFirst:u,onKeyDown:x,onValidate:E,onUpdateValue:R,onUpdateValidValue:S,value:$="",leftIndicator:H,rightIndicator:C,leftIcon:I,rightIcon:s,freeCSS:B,wrapStyles:Y}=ee,_=q(ee,["tone","required","restrict","componentID","era","form","name","min","max","className","enableFormSubmit","checkValidationAtFirst","onKeyDown","onValidate","onUpdateValue","onUpdateValidValue","value","leftIndicator","rightIndicator","leftIcon","rightIcon","freeCSS","wrapStyles"]),[p,w]=W(f),[n,c]=W(k(l({componentID:e.componentID||""},O.DataLeveling({restrict:a,value:$,era:p})),{eventType:"init",eventID:N()})),[T,j]=W({ok:!1,notice:[]}),[P,U]=W({active:!1,index:0,prevIndex:-1}),le={rootStates:e,val_status:n,set_status:c,val_validate:T,set_validate:j,val_era:p,set_era:w,val_focus:P,set_focus:U};z.CommonEffects({type:"time",states:e,val_status:n,set_status:c,val_validate:T,set_validate:j,SystemValidation:O.SystemValidation,ExtraOverrideStates:l({},O.DataLeveling({restrict:a,value:$,era:p}))});const Z=ce(!1);return Q(()=>{if(Z.current){c(b=>l(l({},b),O.DataLeveling({restrict:a,value:b.dataValue,era:p})));let g=L.get("refreshEra_"+n.componentID);g&&g.refreshEra(p)}else Z.current=!0},[p]),L.update({[n.componentID]:{openPicker:g=>{e.disabled||ne.picker.launch({parent:g,sheetID:"PickerTips-"+n.componentID,restrict:a,min:r,max:m,defaultValue:n.dataValue,era:p,onValueUpdate:(b,A)=>{c(M=>k(l(l({},M),O.DataLeveling({restrict:a,value:b,era:A})),{eventType:"update",eventID:N()})),w(A)}})},resetEra:g=>{w(g),c(b=>k(l(l({},b),O.DataLeveling({restrict:a,value:"",era:p})),{eventType:"update",eventID:N()}))}}}),Q(()=>{let{index:g,active:b}=P;if(b){g=Math.max(g,0),g=Math.min(g,n.ranges.length-1);let{from:A,length:M}=n.ranges[g],J=pe("#"+e.id)[0];J&&J.setSelectionRange(A,A+M)}},[P]),oe(Se,{val_status:n,set_status:c,val_validate:T,states:e,children:[y(Re.Shallow,l({},le)),y(ke,{componentID:e.componentID,fontSize:e.fontSize,required:e.required,label:e.label,isActive:!0}),re.get().isTouchDevice?y(ie.Plain,k(l({"data-show-validation":z.isShowValidation(T,n,!!u),"data-component-id":n.componentID,"data-input-origin":n.componentID,"data-disabled":e.disabled,className:o,freeCSS:{textAlign:"left"}},_),{children:n.formatValue,onClick:g=>{let b=L.get(n.componentID);b&&b.openPicker(`[data-input-origin="${n.componentID}"]`),g.stopPropagation()}})):y(X,l({htmlTag:"input",type:"text",inputMode:"numeric","data-show-validation":z.isShowValidation(T,n,!!u),"data-input-origin":n.componentID,"data-disabled":e.disabled,value:n.formatValue,className:o,tabIndex:re.get().isTouchDevice?-1:0,onKeyDown:g=>{O.KeyDownEvent({restrict:a,event:g,val_era:p,val_status:n,set_status:c,val_focus:P,set_focus:U}),x&&x(g),i&&z.SubmitForm(g,h)},onKeyUp:g=>{g.key=="Tab"&&U(b=>k(l({},b),{active:!0}))},onClick:g=>{let b=g.target.selectionEnd,A=0;n.ranges.forEach((M,J)=>{let{from:te,length:se,region:me}=M;te<=b&&b<=te+(me||se)&&(A=J)}),U(M=>k(l({},M),{active:!0,index:A})),g.preventDefault()},onChange:()=>{}},_))]})},V={Origin:e=>{let t=l({fontSize:"inherit",width:1},e),[D]=W(e.componentID||N());if(t.componentID=D,G.is.nullish(t.rightIcon)){let a=(e.restrict||"").match(/clock/)?De:ve;t.rightIcon=y(be,{ssSphere:2,freeCSS:{pointerEvents:"all"},children:y(ie.Sub,{color:"cloud",border:"unset",ssSphere:2,fontColor:"theme",boxShadow:"0.normal",borderRadius:"3.tone.tertiary",flexCenter:!0,ssEffectsOnActive:"push",tabIndex:-1,id:"Picker-"+t.componentID,onClick:()=>{let d=L.get(t.componentID);d&&d.openPicker("#Picker-"+t.componentID)},children:y(de,{icon:a})})})}return y(Ie,{componentID:t.componentID,children:Ve,states:Te(t)})},Clock:e=>y(V.Origin,l({restrict:"clock",era:"clock"},e)),Date:e=>y(V.Origin,l({restrict:"date"},e)),Week:e=>y(V.Origin,l({restrict:"week"},e)),Month:e=>y(V.Origin,l({restrict:"month"},e)),Year:e=>y(V.Origin,l({restrict:"year"},e)),DateWareki:e=>{e=l({},e);let[t]=W(e.componentID||N());e.componentID=t;let{defaultEra:D="wareki"}=e,[a,d]=W((()=>{let f="year";if(D=="wareki"&&(f="reiwa",e.value)){let[h,v,r]=e.value.split(/\D/);if(h&&v&&r){let m=Number(h);m>=2019?(m-=2019,f="reiwa"):m>=1989?(m-=1989,f="heisei"):m>=1926?(m-=1926,f="shouwa"):m>=1912?(m-=1912,f="taisho"):m>=1868&&(m-=1868,f="meiji"),m+=1}}return f})());return Q(()=>{L.set({["refreshEra_"+t]:{refreshEra:f=>{d(f)}}})},[]),y(V.Origin,k(l({restrict:"dateWareki",leftIndicator:y(xe,{label:"\u5143\u53F7",emptySelect:!1,value:a,tone:e.tone||"border",override:"force",flexCenter:!0,borderTopRightRadius:"2/3",borderBottomRightRadius:"2/3",height:1,freeCSS:{whiteSpace:"nowrap"},options:[{value:"year",label:"\u897F\u66A6"},{value:"reiwa",label:"\u4EE4\u548C"},{value:"heisei",label:"\u5E73\u6210"},{value:"shouwa",label:"\u662D\u548C"},{value:"taisho",label:"\u5927\u6B63"},{value:"meiji",label:"\u660E\u6CBB"}],onUpdateValidValue:f=>{d(f);let h=L.get(e.componentID);h&&h.resetEra&&h.resetEra(f)}})},e),{era:a}))},Periods:{Date:e=>y(V.Origin,l({restrict:"dates"},e)),Month:e=>y(V.Origin,l({restrict:"months"},e))},fn:ne};export{V as Time,V as default};
1
+ import{a as ae,b as l,c as k,d as q}from"../../../chunk-C5N2D3ZX.js";import{Fragment as _e,jsx as y,jsxs as oe}from"react/jsx-runtime";import G,{UUID as N,useStore as L}from"jmini";import*as K from"jmini";import{useState as W,useEffect as Q,useRef as ce}from"react";import{$$fromRoot as pe,Config as re,ExtractStyles as ue}from"../../../@utils";import{Box as X,FAI as de}from"../../../atoms";import{Literal as fe,Row as he}from"../../../mols";import{Button as ie}from"../../Button";import ge from"../../Tooltips";import ye from"../../Sheet";import{faClock as De}from"@fortawesome/free-solid-svg-icons/faClock";import{faCalendarAlt as ve}from"@fortawesome/free-solid-svg-icons/faCalendarAlt";import{OptionalInputWrapper as Ie,BoxWrapper as Se,CoreEffects as z,DefaultBoxishStyles as Te}from"../core";import{RightIcon as be}from"..";import xe from"../Select";import{InputLabel as ke}from"../Label";import Ee from"./Picker";const F=" ~ ",we={clock:{defaultValue:"--:--",format:/^\d{2}\D\d{2}$/,ranges:[{type:"hour",from:0,length:2},{type:"minute",from:3,length:2}],sets:1},date:{defaultValue:"----/--/--",format:/^\d{4}\D\d{2}\D\d{2}$/,ranges:[{type:"year",from:0,length:4},{type:"month",from:5,length:2},{type:"date",from:8,length:2}],sets:1},week:{defaultValue:"----\u5E74\u7B2C--\u9031",format:/^\d{4}\D\d{2}$/,ranges:[{type:"year",from:0,length:4,region:6},{type:"week",from:6,length:2,region:3}],sets:1},month:{defaultValue:"----\u5E74--\u6708",format:/^\d{4}\D\d{2}$/,ranges:[{type:"year",from:0,length:4},{type:"month",from:5,length:2,region:3}],sets:1},year:{defaultValue:"----\u5E74",format:/^\d{4}$/,ranges:[{type:"year",from:0,length:4,region:5}],sets:1},dates:{defaultValue:"----/--/--",format:/^\d{4}\D\d{2}\D\d{2}$/,ranges:[{type:"year",from:0,length:4},{type:"month",from:5,length:2},{type:"date",from:8,length:2,region:5},{type:"year",from:10+F.length,length:4},{type:"month",from:15+F.length,length:2},{type:"date",from:18+F.length,length:2}],sets:2},months:{defaultValue:"----\u5E74--\u6708",format:/^\d{4}\D\d{2}$/,ranges:[{type:"year",from:0,length:4},{type:"month",from:5,length:2,region:6},{type:"year",from:8+F.length,length:4},{type:"month",from:13+F.length,length:2,region:3}],sets:2},dateWareki:{defaultValue:"----\u5E74--\u6708--\u65E5",format:/^\d{4}\D\d{2}\D\d{2}$/,ranges:[{type:"dateWareki",from:0,length:4,region:5},{type:"month",from:5,length:2,region:3},{type:"date",from:8,length:2,region:3}],sets:1}},O={PeriodMargin:" ~ ",DataLeveling:e=>{let{restrict:t,value:D,era:a}=e,d=G.flatArray(D||""),{defaultValue:f,format:h,ranges:v,sets:r}=we[t],m=[],o=t=="clock"&&":"||"/";for(let i=0;i<d.length;i++)d[i]=String(d[i]).replace(/\D/ig,o);for(let i=0;i<r;i++){let u=d[i]||"";if(!u.match(h))d[i]="",m.push(f);else{let x=f;u.split(/\D/).forEach((E,R)=>{if(R==0&&t=="dateWareki"){let S=Number(E);a!="year"&&(S>=2019?a=="reiwa"?S-=2018:a=="heisei"&&(S=31):S>=1989?a=="heisei"?S-=1988:a=="shouwa"&&(S=64):S>=1926?a=="shouwa"?S-=1925:a=="taisho"&&(S=15):S>=1912?a=="taisho"?S-=1911:a=="meiji"&&(S=45):S>=1868&&(S-=1867)),E=S.zeroEmbed(4)}x=x.replace(new RegExp("------------------".slice(0,E.length)),E)}),m.push(x)}}return{formatValue:m.join(F),dataValue:["dates","months"].includes(t)?d:d[0],ranges:v}},SystemValidation:e=>{let{states:t}=e,{restrict:D,min:a,max:d,required:f}=t,h=[],v=G.flatArray(e.value),r={empty:!1,escalated:1,filled:!0,correct:!0,prohibited:!1};(()=>{let m=D=="clock"&&":"||"/";for(let o=0;o<v.length;o++)v[o]=String(v[o]).replace(/\D/ig,m);for(let o=0;o<v.length;o++){let i=v[o],u=v[o-1];i.removeLetters()||(r.empty=!0),o>0&&(r.escalated&=+(i>=u))}r.escalated&&(r.empty||(D.match(/clock/)?v.forEach(o=>{let[i,u]=o.split(/\D+/);!i||!u?r.filled=!1:(Number(i)>23||Number(u)>59)&&(r.correct=!1)}):D.match(/date/)?v.forEach(o=>{let[i,u,x]=o.split(/\D+/);if(!i||!u||!x)r.filled=!1;else{let E=K.Time(o);(!E.validate||o!=E.toFormatYMD())&&(r.correct=!1)}}):D.match(/week/)?v.forEach(o=>{let[i,u]=o.split(/\D+/);if(!i||!u)r.filled=!1;else{let x=K.Time(i+"/01/01").weekday,R=K.Time(i+"/01/0"+(7-x+1)).addWeek(Number(u)-1);i!=String(R.year)&&(r.correct=!1)}}):D.match(/month/)?v.forEach(o=>{let[i,u]=o.split(/\D+/);!i||!u?r.filled=!1:K.Time([i,u,"01"].join("/")).validate||(r.correct=!1)}):D.match(/year/),r.filled&&r.correct&&v.forEach(o=>{{let i=Number(String(o).replace(/\D/ig,""));if(a&&Number(String(a).replace(/\D/ig,""))>i&&(r.prohibited=!0),d){let u=Number(String(d).replace(/\D/ig,""));i>u&&(r.prohibited=!0)}}})))})();{let{empty:m,escalated:o,filled:i,correct:u,prohibited:x}=r;m&&f&&(h=[{type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"}]),o||h.push({type:"invalid",label:"\u6642\u7CFB\u5217\u3092\u6B63\u3057\u304F\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}),u||h.push({type:"invalid",label:"\u7121\u52B9\u306A\u5024\u304C\u5165\u529B\u3055\u308C\u3066\u3044\u307E\u3059"}),i||h.push({type:"invalid",label:"\u6700\u5F8C\u307E\u3067\u5024\u3092\u57CB\u3081\u3066\u304F\u3060\u3055\u3044"}),x&&h.push({type:"invalid",label:oe(_e,{children:[y(X,{children:"\u5165\u529B\u7BC4\u56F2\u304C\u5236\u9650\u3055\u308C\u3066\u3044\u307E\u3059"}),"[",a||"\u4E0B\u9650\u7121\u3057","] ~ [",d||"\u4E0A\u9650\u7121\u3057","]"]})})}return{ok:!h.filter(({type:m})=>m=="invalid").length,notice:h}},KeyDownEvent:e=>{let{val_era:t,restrict:D,event:a,val_status:d,set_status:f,val_focus:h,set_focus:v}=e,{key:r,shiftKey:m,ctrlKey:o,metaKey:i}=a,u=o||i,{selectionStart:x,selectionEnd:E}=a.target,{index:R,prevIndex:S}=h,{ranges:$,formatValue:H}=d,C=$.length-1;if(["Tab","ArrowLeft","ArrowRight"].includes(r)){let I=0;if(r=="Tab"){let s=+!m*2-1;if(I=h.index+s,I<0||I>C)return}else{let s=r=="ArrowLeft"?-1:r=="ArrowRight"?1:0;u||x==0&&E==String(d.formatValue).length?I=s==1?C:0:I=Math.max(0,Math.min(R+s,C))}v(s=>k(l({},s),{index:I,prevIndex:R})),a.preventDefault()}if(["Backspace","ArrowUp","ArrowDown","0","1","2","3","4","5","6","7","8","9"].includes(r)){a.preventDefault();let I=R;I=Math.max(I,0),I=Math.min(I,C);let{type:s,from:B,length:Y}=$[I],_=H.slice(B,B+Y),p;if(r=="Backspace")p="------".slice(0,Y);else if(["ArrowUp","ArrowDown"].includes(r)){let w=r=="ArrowUp"?1:-1;_=_|0,p=_+w;let[n,c,T]=s=="dateWareki"?t=="year"?[0,2999,4]:t=="reiwa"?[1,2999,4]:t=="heisei"?[1,31,4]:t=="shouwa"?[1,64,4]:t=="taisho"?[1,15,4]:t=="meiji"?[1,45,4]:[0,0,0]:s=="minute"?[0,59,2]:s=="hour"?[0,23,2]:s=="date"?[1,31,2]:s=="week"?[1,53,2]:s=="month"?[1,12,2]:s=="year"?[0,2999,4]:[0,0,0];p>c?p=n:p<n&&(p=c),p=Number(p).zeroEmbed(T)}else if(["0","1","2","3","4","5","6","7","8","9"].includes(r)){let w=_|0,n=r,c=`${w}${n}`;if(S!=R&&(w=0,c="0"+n),s=="year"||s=="dateWareki"&&t=="year")Number(c)>1e4?p=n:p=c,(p|0)>1e3&&I++;else if(["hour","minute","date","week","month"].includes(s)||s=="dateWareki"&&t!="year"){let T=s=="dateWareki"?t=="reiwa"?100:t=="heisei"?31:t=="shouwa"?64:t=="taisho"?15:t=="meiji"?45:0:s=="minute"?59:s=="hour"?23:s=="date"?31:s=="week"?53:s=="month"?12:0;p=(c|0)>T?n:c,(Number(n)>Number(String(T)[0])||_=="0000".slice(0,String(T).length)&&(c!="0000".slice(0,String(T).length)||["minute","hour"].includes(s)&&S==R)||(c|0)>=ae(10,String(T).length-1))&&I++}s=="year"||s=="dateWareki"?p=(p|0).zeroEmbed(4):p=(p|0).zeroEmbed(2)}{let w=String(H).partReplace(B,String(p)),n=w.split(F).map(c=>c.replace(/(^\D|\D$)/,"").split(/\D+/).join(D=="clock"&&":"||"/").replace(/(^\D|\D$)/,""));if(D=="dateWareki"){let c=n[0].split(/\D/),[T,j,P]=c;c.length==3&&T&&(n=[[Number(T)-1+Number({year:1,reiwa:2019,heisei:1989,shouwa:1926,taisho:1912,meiji:1868}[t]),j,P].join("/")])}I=Math.max(I,0),I=Math.min(I,C),f(c=>k(l({},c),{dataValue:["dates","months"].includes(D)?n:n[0],formatValue:w,eventType:"update",eventID:N()})),v(c=>k(l({},c),{index:I,prevIndex:c.index}))}}}},ne={picker:{launch:e=>{let t=e.sheetID||N(),m=e,{onValueUpdate:D,min:a,max:d,era:f,restrict:h,defaultValue:v}=m,r=q(m,["onValueUpdate","min","max","era","restrict","defaultValue"]);ye.open(k(l({sheetID:t,type:"normal.middleCenter",size:"S",padding:0,closeAtAroundClick:!0,closeAtParentBlur:!1},r),{content:y(he.Center,{children:y(Ee,{restrict:h,min:a,max:d,era:f,defaultValue:v,sheetID:t,onValueUpdate:(o,i)=>{D(o,i)}})})}))},remove:e=>{ge.close(e)}}},Re={Shallow:e=>{let{rootStates:t,val_status:D}=e,a=ue(t);return y(X,{position:"absolute",top:0,left:0,right:0,height:0,overflow:"hidden",opacity:"trans",freeCSS:{zIndex:3,pointerEvents:"none"},children:y(fe.Description,k(l({className:t.className},a),{position:"absolute",width:1,freeCSS:k(l({},a.freeCSS),{color:"orange"}),children:y(X,{"data-input-value-shallow":D.componentID,children:"A"})}))})}},Ve=e=>{let ee=e,{tone:t,required:D,restrict:a="clock",componentID:d,era:f,form:h,name:v,min:r,max:m,className:o,enableFormSubmit:i,checkValidationAtFirst:u,onKeyDown:x,onValidate:E,onUpdateValue:R,onUpdateValidValue:S,value:$="",leftIndicator:H,rightIndicator:C,leftIcon:I,rightIcon:s,freeCSS:B,wrapStyles:Y}=ee,_=q(ee,["tone","required","restrict","componentID","era","form","name","min","max","className","enableFormSubmit","checkValidationAtFirst","onKeyDown","onValidate","onUpdateValue","onUpdateValidValue","value","leftIndicator","rightIndicator","leftIcon","rightIcon","freeCSS","wrapStyles"]),[p,w]=W(f),[n,c]=W(k(l({componentID:e.componentID||""},O.DataLeveling({restrict:a,value:$,era:p})),{eventType:"init",eventID:N()})),[T,j]=W({ok:!1,notice:[]}),[P,U]=W({active:!1,index:0,prevIndex:-1}),le={rootStates:e,val_status:n,set_status:c,val_validate:T,set_validate:j,val_era:p,set_era:w,val_focus:P,set_focus:U};z.CommonEffects({type:"time",states:e,val_status:n,set_status:c,val_validate:T,set_validate:j,SystemValidation:O.SystemValidation,ExtraOverrideStates:l({},O.DataLeveling({restrict:a,value:$,era:p}))});const Z=ce(!1);return Q(()=>{if(Z.current){c(b=>l(l({},b),O.DataLeveling({restrict:a,value:b.dataValue,era:p})));let g=L.get("refreshEra_"+n.componentID);g&&g.refreshEra(p)}else Z.current=!0},[p]),L.update({[n.componentID]:{openPicker:g=>{e.disabled||ne.picker.launch({parent:g,sheetID:"PickerTips-"+n.componentID,restrict:a,min:r,max:m,defaultValue:n.dataValue,era:p,onValueUpdate:(b,A)=>{c(M=>k(l(l({},M),O.DataLeveling({restrict:a,value:b,era:A})),{eventType:"update",eventID:N()})),w(A)}})},resetEra:g=>{w(g),c(b=>k(l(l({},b),O.DataLeveling({restrict:a,value:"",era:p})),{eventType:"update",eventID:N()}))}}}),Q(()=>{let{index:g,active:b}=P;if(b){g=Math.max(g,0),g=Math.min(g,n.ranges.length-1);let{from:A,length:M}=n.ranges[g],J=pe("#"+e.id)[0];J&&J.setSelectionRange(A,A+M)}},[P]),oe(Se,{val_status:n,set_status:c,val_validate:T,states:e,children:[y(Re.Shallow,l({},le)),y(ke,{componentID:e.componentID,fontSize:e.fontSize,required:e.required,label:e.label,isActive:!0}),re.get().isTouchDevice?y(ie.Plain,k(l({"data-show-validation":z.isShowValidation(T,n,!!u),"data-component-id":n.componentID,"data-input-origin":n.componentID,"data-disabled":e.disabled,className:o,freeCSS:{textAlign:"left"}},_),{children:n.formatValue,onClick:g=>{let b=L.get(n.componentID);b&&b.openPicker(`[data-input-origin="${n.componentID}"]`),g.stopPropagation()}})):y(X,l({htmlTag:"input",type:"text",inputMode:"numeric","data-show-validation":z.isShowValidation(T,n,!!u),"data-input-origin":n.componentID,"data-disabled":e.disabled,value:n.formatValue,className:o,tabIndex:re.get().isTouchDevice?-1:0,onKeyDown:g=>{O.KeyDownEvent({restrict:a,event:g,val_era:p,val_status:n,set_status:c,val_focus:P,set_focus:U}),x&&x(g),i&&z.SubmitForm(g,h)},onKeyUp:g=>{g.key=="Tab"&&U(b=>k(l({},b),{active:!0}))},onClick:g=>{let b=g.target.selectionEnd,A=0;n.ranges.forEach((M,J)=>{let{from:te,length:se,region:me}=M;te<=b&&b<=te+(me||se)&&(A=J)}),U(M=>k(l({},M),{active:!0,index:A})),g.preventDefault()},onChange:()=>{}},_))]})},V={Origin:e=>{let t=l({fontSize:"inherit",width:1},e),[D]=W(e.componentID||N());if(t.componentID=D,G.is.nullish(t.rightIcon)){let a=(e.restrict||"").match(/clock/)?De:ve;t.rightIcon=y(be,{ssSphere:2,freeCSS:{pointerEvents:"all"},children:y(ie.Sub,{color:"cloud",border:"unset",ssSphere:2,fontColor:"theme",boxShadow:"0.normal",borderRadius:"3.tone.tertiary",flexCenter:!0,ssEffectsOnActive:"push",tabIndex:-1,id:"Picker-"+t.componentID,onClick:()=>{let d=L.get(t.componentID);d&&d.openPicker("#Picker-"+t.componentID)},children:y(de,{icon:a})})})}return y(Ie,{componentID:t.componentID,children:Ve,states:Te(t)})},Clock:e=>y(V.Origin,l({restrict:"clock",era:"clock"},e)),Date:e=>y(V.Origin,l({restrict:"date"},e)),Week:e=>y(V.Origin,l({restrict:"week"},e)),Month:e=>y(V.Origin,l({restrict:"month"},e)),Year:e=>y(V.Origin,l({restrict:"year"},e)),DateWareki:e=>{e=l({},e);let[t]=W(e.componentID||N());e.componentID=t;let{defaultEra:D="wareki"}=e,[a,d]=W((()=>{let f="year";if(D=="wareki"&&(f="reiwa",e.value)){let[h,v,r]=e.value.split(/\D/);if(h&&v&&r){let m=Number(h);m>=2019?(m-=2019,f="reiwa"):m>=1989?(m-=1989,f="heisei"):m>=1926?(m-=1926,f="shouwa"):m>=1912?(m-=1912,f="taisho"):m>=1868&&(m-=1868,f="meiji"),m+=1}}return f})());return Q(()=>{L.set({["refreshEra_"+t]:{refreshEra:f=>{d(f)}}})},[]),y(V.Origin,k(l({restrict:"dateWareki",leftIndicator:y(xe,{label:"\u5143\u53F7",emptySelect:!1,value:a,tone:e.tone||"border",override:"force",flexCenter:!0,borderTopRightRadius:"2/3",borderBottomRightRadius:"2/3",height:1,freeCSS:{whiteSpace:"nowrap"},options:[{value:"year",label:"\u897F\u66A6"},{value:"reiwa",label:"\u4EE4\u548C"},{value:"heisei",label:"\u5E73\u6210"},{value:"shouwa",label:"\u662D\u548C"},{value:"taisho",label:"\u5927\u6B63"},{value:"meiji",label:"\u660E\u6CBB"}],onUpdateValidValue:f=>{d(f);let h=L.get(e.componentID);h&&h.resetEra&&h.resetEra(f)}})},e),{era:a}))},Periods:{Date:e=>y(V.Origin,l({restrict:"dates"},e)),Month:e=>y(V.Origin,l({restrict:"months"},e))},fn:ne};export{V as Time,V as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amotify",
3
- "version": "0.2.158",
3
+ "version": "0.2.160",
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.46",
93
+ "jmini": "^0.0.56",
94
94
  "react": "^18.3.1"
95
95
  },
96
96
  "devDependencies": {
@@ -113,4 +113,4 @@
113
113
  "tsc-alias": "^1.8.8",
114
114
  "typescript": "^5.4.5"
115
115
  }
116
- }
116
+ }