amotify 0.2.93 → 0.2.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import{b as l,c as s,d as q,e as ae}from"../../chunk-C5N2D3ZX.js";import{Fragment as le,jsx as o,jsxs as $}from"react/jsx-runtime";import w,{UUID as _}from"jmini";import{useState as L,useEffect as J}from"react";import{$$fromRoot as Ie,useStore as ve,ExtractStyles as Se}from"../../@utils";import{Box as V,FAI as Te}from"../../atoms";import{Text as Y}from"../../mols";import{Tips as ie,Button as Ce}from"..";import{faEye as Re}from"@fortawesome/free-solid-svg-icons/faEye";import{OptionalInputWrapper as ye,BoxWrapper as we,CoreEffects as M,DefaultBoxishStyles as Ve}from"./core";import{InputLabel as De}from"./Label";import{LeftIcon as ke,RightIcon as ne}from".";const Fe={number:{reg:/^-?[0-9\.]+$/g,exist:!0,reason:"\u534A\u89D2\u6570\u5B57\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},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"},digitNumber:{reg:/^-?[0-9\.]+$/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:$(le,{children:[o(V,{children:"\u25CB\u25CB\u25CB\u25CB@\u25CB\u25CB\u25CB\u25CB.\u25CB\u25CB\u25CB\u306E\u5F62\u5F0F\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}),o(V,{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:$(le,{children:[o(V,{children:"0\u304B\u3089\u59CB\u307E\u308B\u756A\u53F7\u306E\u307F\u5165\u529B\u53EF\u80FD\u3067\u3059"}),o(V,{children:"9~12\u6841\u306E\u6570\u5B57\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}),o(V,{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"}},D={setSelection:e=>{let{id:a,restrict:r,val_status:t}=e,n=Ie("#"+a)[0];if(n&&t.prevValue&&t.formatValue){let{formatValue:u,prevValue:c,caretFrom:i,caretTo:m}=t;if(r=="creditCard")u.length>=c.length&&i%5==0&&(i++,m++),n.setSelectionRange(i,m);else if(r=="postal")u.length==5&&c.length==3&&(i++,m++),n.setSelectionRange(i,m);else if(r=="digitNumber"){let h=u.length-c.length;h==2&&(i++,m++),h==-2&&(i--,m--),n.setSelectionRange(i,m)}}},Validation:{System:e=>{let{value:a,states:r}=e,{restrict:t="text",maxLength:n,multiline:u,required:c}=r,i=[];if(u||(n=n||255),w.is.exist(n)&&a.length>=Number(n)&&i.push({type:"invalid",label:n+"\u5B57\u4EE5\u5185\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}),a){let m=D.Validation.Text(a,t);m.ok||i.push({type:"invalid",label:m.body})}else c&&i.push({type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"});return{ok:!i.filter(({type:m})=>m=="invalid").length,notice:i}},Text:(e,a)=>{let r={ok:!0,body:""};return(()=>{let t=Fe[a];if(!t)return;let n=t.reason;if(t){let u=!!(+!!e.match(t.reg)^+!t.exist);r={ok:u,body:u?"":n}}})(),r},DataLeveling:e=>{let{restrict:a,value:r=""}=e,t=String(r),n=!1;if(["tel","number","digitNumber","test","postal","creditCard"].includes(a)&&(t=t.zen2hanNumber()),a=="katakana"&&(t=t.replace(/[^ァ-ヶー ヲ-゚ ]/ig,"")),a=="hankaku.katakana"&&(t=t.replace(/[^ヲ-゚ ]/ig,"")),["postal","creditCard"].includes(a)&&(t=t.removeLetters()),["number","number.zeroStart","digitNumber"].includes(a)){let c=t[0]=="0";if(t){if(t!="-")if(t=="0-")t="-";else{t[0]=="-"&&(n=!0),t=t.replace(/[^0-9\.]/ig,"");let i=Number(t);i===0&&(n=!1),n&&(i=-1*i),w.is.exist(e.min)&&(i=Math.max(i,Number(e.min))),w.is.exist(e.max)&&(i=Math.min(i,Number(e.max))),t=String(Math.abs(i))}c&&t!="0"&&a=="number.zeroStart"&&(t="0"+t)}}let u=t;if(a=="digitNumber"){if(t&&t!="-"){let c=[];for(let i=t.length-1;i>=0;i--){c.unshift(t[i]);let m=t.length-1-i+1;i!=0&&m%3==0&&c.unshift(",")}u=c.join("")}}else a=="postal"?t.length>=4&&(u=t.clip(0,3)+"-"+t.clip(3)):a=="creditCard"&&(u=t.replace(/.{4}(?=.)/g,"$& "));return["number","digitNumber"].includes(a)&&n&&(t="-"+t,u="-"+u),{formatValue:u,dataValue:t}}}},G={Shallow:e=>{let{rootStates:a,val_status:r}=e,t=r.dataValue||"";J(()=>{w.scope(()=>ae(void 0,null,function*(){if(!a.multiline)return;let h=w('[data-input-origin="'+r.componentID+'"]'),b=w('[data-input-shallow="'+r.componentID+'"]'),k=w('[data-input-min-height-value-shallow="'+r.componentID+'"]'),T=w('[data-input-max-height-value-shallow="'+r.componentID+'"]');if(!h[0]||!b[0]||!k[0]||!T[0])return;let d=b.position(),C=k.position(),A=T.position(),R=0;a.autoHeight&&(R=d.height),R=Math.max(R,C.height),R=Math.min(R,A.height),h[0].style.height=R+"px"}))},[t]);let n=t||"";(!!t.match(/\n$/)||!t)&&(n+="T");let c="",i="";if(a.multiline){let h=a.minRows||1,b=a.maxRows||100;c=`
|
|
2
2
|
T`.repeat(h-1),i=`
|
|
3
|
-
T`.repeat(b-1)}let m=Se(a);return $(V,{position:"absolute",top:0,left:0,right:0,height:0,overflow:"hidden",opacity:"trans",freeCSS:{zIndex:3,pointerEvents:"none"},children:[o(Y.Description,s(l({className:a.className},m),{position:"absolute",width:1,freeCSS:s(l({},m.freeCSS),{color:"orange"}),"data-input-shallow":r.componentID,children:o(V,{"data-input-value-shallow":r.componentID,children:n})})),o(Y.Description,s(l({className:a.className},m),{position:"absolute",left:0,freeCSS:s(l({},m.freeCSS),{backgroundColor:"transparent",color:"blue"}),"data-input-min-height-value-shallow":r.componentID,children:c})),o(Y.Description,s(l({className:a.className},m),{position:"absolute",right:0,freeCSS:s(l({},m.freeCSS),{backgroundColor:"transparent",color:"red"}),"data-input-max-height-value-shallow":r.componentID,children:i}))]})},InputBox:e=>{let{rootStates:a,val_validate:r,set_validate:t,val_status:n,set_status:u,val_focus:c,set_focus:i,val_isComposing:m,set_isComposing:h}=e;if(a.multiline)return null;let ee=a,{componentID:b,tone:k,required:T,restrict:d="text",form:C,autoComplete:A="off",autoCapitalize:R="off",minRows:oe,maxRows:re,multiline:X,autoHeight:se,enableFormSubmit:U,clearButton:P=!1,checkValidationAtFirst:B,onChange:K,onKeyDown:W,onValidate:ue,onUpdateValue:me,onUpdateValidValue:pe,value:ce="",leftIndicator:de,rightIndicator:fe,leftIcon:ge,rightIcon:x,maxLength:xe,min:E,max:I,label:j,isLabelActive:Q,wrapStyles:_e}=ee,p=q(ee,["componentID","tone","required","restrict","form","autoComplete","autoCapitalize","minRows","maxRows","multiline","autoHeight","enableFormSubmit","clearButton","checkValidationAtFirst","onChange","onKeyDown","onValidate","onUpdateValue","onUpdateValidValue","value","leftIndicator","rightIndicator","leftIcon","rightIcon","maxLength","min","max","label","isLabelActive","wrapStyles"]),he=d=="password"||d=="concealed"?"password":"text",be=["number","digitNumber","creditCard"].includes(d)?"numeric":d=="email"?"email":"text";return o(V,s(l({htmlTag:"input",type:he,inputMode:be,"data-disabled":a.disabled,"data-show-validation":M.isShowValidation(r,n,!!B),"data-component-id":n.componentID,"data-input-origin":n.componentID,value:n.formatValue,autoComplete:A,autoCapitalize:R,onKeyDown:f=>{let{key:v,target:F}=f;{let y=F,{selectionStart:N,selectionEnd:H}=y,z=Number(N),te=Number(H),Z=n.formatValue[Number(z)],O=n.formatValue[Number(z)-1];v=="Delete"&&(d=="creditCard"&&Z==" "||d=="postal"&&Z=="-"||d=="digitNumber"&&Z==",")&&(y.setSelectionRange(z+1,te+1),f.preventDefault()),v=="Backspace"&&(d=="creditCard"&&O==" "||d=="postal"&&O=="-"||d=="digitNumber"&&O==",")&&(y.setSelectionRange(z-1,te-1),f.preventDefault()),v=="Enter"||v=="Tab"}if(["number","digitNumber","creditCard"].includes(d)&&v=="Clear"&&u(y=>s(l({},y),{dataValue:"",formatValue:"",eventType:"update",eventID:_()})),["number","digitNumber"].includes(d)&&["ArrowUp","ArrowDown"].includes(v)){let y=+(v=="ArrowUp")*2-1,N=String(Number(n.dataValue)+y);r.ok&&t({ok:!1,notice:[]}),u(H=>s(l(l({},H),D.Validation.DataLeveling({min:E,max:I,restrict:d,value:N})),{eventType:"update",eventID:_()})),f.preventDefault()}W&&W(f),U&&M.SubmitForm(f,C)},onChange:f=>{let{value:v,selectionStart:F,selectionEnd:y}=f.target,N=D.Validation.DataLeveling({min:E,max:I,restrict:d,value:v});m&&(N.formatValue=v),N.formatValue!=n.formatValue&&(r.ok&&t({ok:!1,notice:[]}),u(H=>s(l(l({},H),N),{prevValue:n.formatValue,eventType:"update",eventID:_(),caretFrom:Number(F),caretTo:Number(y)})),K&&K(f))},width:1},p),{onFocus:f=>{p!=null&&p.onFocus&&(p==null||p.onFocus(f)),i(!0)},onBlur:f=>{p!=null&&p.onBlur&&(p==null||p.onBlur(f)),i(!1)},onCompositionStart:f=>{p!=null&&p.onCompositionStart&&(p==null||p.onCompositionStart(f)),h(!0)},onCompositionEnd:f=>{if(p!=null&&p.onCompositionEnd&&(p==null||p.onCompositionEnd(f)),d=="text")return;let v=D.Validation.DataLeveling({min:E,max:I,restrict:d,value:n.formatValue});u(F=>s(l(l({},F),v),{prevValue:F.formatValue,eventType:"update",eventID:_(),caretFrom:Number(F.formatValue.length+1),caretTo:Number(F.formatValue.length+1)})),h(!1)}}))},TextAreaBox:e=>{let{rootStates:a,val_focus:r,set_focus:t,val_validate:n,set_validate:u,val_status:c,set_status:i,isShallow:m}=e,E=a,{componentID:h,tone:b,required:k,form:T,label:d,isLabelActive:C,minRows:A,maxRows:R,multiline:oe,autoHeight:re,enableFormSubmit:X,maxLength:se,checkValidationAtFirst:U,onChange:P,onKeyDown:B,onValidate:K,onUpdateValue:W,onUpdateValidValue:ue,value:me="",leftIndicator:pe,rightIndicator:ce,leftIcon:de,rightIcon:fe,wrapStyles:ge}=E,x=q(E,["componentID","tone","required","form","label","isLabelActive","minRows","maxRows","multiline","autoHeight","enableFormSubmit","maxLength","checkValidationAtFirst","onChange","onKeyDown","onValidate","onUpdateValue","onUpdateValidValue","value","leftIndicator","rightIndicator","leftIcon","rightIcon","wrapStyles"]);return!a.multiline?null:o(V,s(l({htmlTag:"textarea","data-show-validation":M.isShowValidation(n,c,!!U),"data-input-origin":c.componentID,"data-component-id":c.componentID,value:c.dataValue,width:1},x),{onFocus:I=>{x!=null&&x.onFocus&&(x==null||x.onFocus(I)),t(!0)},onBlur:I=>{x!=null&&x.onBlur&&(x==null||x.onBlur(I)),t(!1)},onKeyDown:I=>{B&&B(I),X&&M.SubmitForm(I,T)},onChange:I=>{let{value:j}=I.target;n.ok&&u({ok:!1,notice:[]}),i(Q=>s(l({},Q),{dataValue:j,eventType:"update",eventID:_()})),P&&P(I)}}))}},Ne=e=>{let{componentID:a,restrict:r="text",value:t="",min:n,max:u}=e,[c,i]=L(!1),[m,h]=L(!1),[b,k]=L(s(l({componentID:a},D.Validation.DataLeveling({min:n,max:u,restrict:r,value:t})),{prevValue:"",eventType:"init",eventID:_(),caretFrom:null,caretTo:null})),[T,d]=L({ok:!1,notice:[]}),C={rootStates:e,val_focus:c,set_focus:i,val_isComposing:m,set_isComposing:h,val_status:b,set_status:k,val_validate:T,set_validate:d};return M.CommonEffects({type:"textfield",states:e,val_status:b,set_status:k,val_validate:T,set_validate:d,SystemValidation:D.Validation.System,ExtraOverrideStates:l({},D.Validation.DataLeveling({min:n,max:u,restrict:r,value:t}))}),J(()=>{D.setSelection({id:e.id,restrict:r,val_status:b})},[b]),$(we,{val_status:b,set_status:k,val_validate:T,states:C.rootStates,children:[o(De,{componentID:e.componentID,fontSize:e.fontSize,required:e.required,label:e.label,isActive:e.isLabelActive||c||!!b.dataValue}),o(G.Shallow,l({},C)),o(G.InputBox,l({},C)),o(G.TextAreaBox,l({},C))]})},S=e=>(e=l({autoHeight:!0,restrict:"text"},e),e.multiline?(e.minRows=e.minRows||5,e.maxRows=e.maxRows||20):(e.minRows=1,e.maxRows=1),o(ye,{componentID:e.componentID,children:Ne,states:Ve(e)})),g=S;g.Validate=D.Validation.Text,g.Katakana=e=>o(S,s(l({},e),{restrict:"katakana",multiline:!1,autoHeight:!1})),g.HankakuKatakana=e=>o(S,s(l({},e),{restrict:"hankaku.katakana",multiline:!1,autoHeight:!1})),g.CreditCard=e=>o(S,s(l({},e),{restrict:"creditCard",multiline:!1,autoHeight:!1})),g.Tel=e=>o(S,s(l({},e),{restrict:"tel",multiline:!1,autoHeight:!1})),g.Number=e=>o(S,s(l({},e),{restrict:"number",multiline:!1,autoHeight:!1})),g.DigitNumber=e=>o(S,s(l({},e),{restrict:"digitNumber",multiline:!1,autoHeight:!1})),g.Email=e=>o(S,s(l({},e),{restrict:"email",multiline:!1,autoHeight:!1})),g.Url=e=>o(S,s(l({},e),{restrict:"url",multiline:!1,autoHeight:!1})),g.Postal=e=>{let[a]=L(_());return J(()=>()=>{ve.delete(a)},[]),o(S,s(l({label:"\u90F5\u4FBF\u756A\u53F7"},e),{restrict:"postal",multiline:!1,autoHeight:!1,leftIcon:o(ke,{ssSphere:2,fontColor:"4.thin",children:"\u3012"})}))},g.Password=e=>o(S,s(l({label:"\u30D1\u30B9\u30EF\u30FC\u30C9",rightIcon:o(ne,{ssSphere:2,padding:0,freeCSS:{pointerEvents:"all"},children:o(Ce.Sub,{ssSphere:2,borderRadius:"3.tone.tertiary",fontColor:"theme",flexCenter:!0,height:1,ssEffectsOnActive:["expand"],onMouseOver:a=>{ie.open(a.currentTarget,"\u30C6\u30AD\u30B9\u30C8\u3092\u8868\u793A",24)},onMouseLeave:ie.abort,tabIndex:-1,onClick:a=>{w(a.target).parent().parent().find("input").callback(r=>{let t=r[0];t.type=t.type==="password"?"text":"password"})},children:o(Te,{icon:Re})})}),restrict:"password"},e),{multiline:!1,autoHeight:!1})),g.Concealed=e=>o(g.Password,s(l({label:"\u79D8\u5BC6\u9375"},e),{restrict:"concealed"})),g.Money={JPY:e=>o(g.DigitNumber,s(l({rightIcon:o(ne,{ssSphere:2,fontColor:"4.thin",children:"\u5186"})},e),{multiline:!1,autoHeight:!1}))};export{g as TextField,Ne as TextInput,g as default};
|
|
3
|
+
T`.repeat(b-1)}let m=Se(a);return $(V,{position:"absolute",top:0,left:0,right:0,height:0,overflow:"hidden",opacity:"trans",freeCSS:{zIndex:3,pointerEvents:"none"},children:[o(Y.Description,s(l({className:a.className},m),{position:"absolute",width:1,freeCSS:s(l({},m.freeCSS),{color:"orange"}),"data-input-shallow":r.componentID,children:o(V,{"data-input-value-shallow":r.componentID,children:n})})),o(Y.Description,s(l({className:a.className},m),{position:"absolute",left:0,freeCSS:s(l({},m.freeCSS),{backgroundColor:"transparent",color:"blue"}),"data-input-min-height-value-shallow":r.componentID,children:c})),o(Y.Description,s(l({className:a.className},m),{position:"absolute",right:0,freeCSS:s(l({},m.freeCSS),{backgroundColor:"transparent",color:"red"}),"data-input-max-height-value-shallow":r.componentID,children:i}))]})},InputBox:e=>{let{rootStates:a,val_validate:r,set_validate:t,val_status:n,set_status:u,val_focus:c,set_focus:i,val_isComposing:m,set_isComposing:h}=e;if(a.multiline)return null;let ee=a,{componentID:b,tone:k,required:T,restrict:d="text",form:C,autoComplete:A="off",autoCapitalize:R="off",minRows:oe,maxRows:re,multiline:X,autoHeight:se,enableFormSubmit:U,clearButton:P=!1,checkValidationAtFirst:B,onChange:K,onKeyDown:W,onValidate:ue,onUpdateValue:me,onUpdateValidValue:pe,value:ce="",leftIndicator:de,rightIndicator:fe,leftIcon:ge,rightIcon:x,maxLength:xe,min:E,max:I,label:j,isLabelActive:Q,wrapStyles:_e}=ee,p=q(ee,["componentID","tone","required","restrict","form","autoComplete","autoCapitalize","minRows","maxRows","multiline","autoHeight","enableFormSubmit","clearButton","checkValidationAtFirst","onChange","onKeyDown","onValidate","onUpdateValue","onUpdateValidValue","value","leftIndicator","rightIndicator","leftIcon","rightIcon","maxLength","min","max","label","isLabelActive","wrapStyles"]),he=d=="password"||d=="concealed"?"password":"text",be=["number","digitNumber","creditCard"].includes(d)?"numeric":d=="email"?"email":"text";return o(V,s(l({htmlTag:"input",type:he,inputMode:be,"data-disabled":a.disabled,"data-show-validation":M.isShowValidation(r,n,!!B),"data-component-id":n.componentID,"data-input-origin":n.componentID,value:n.formatValue,autoComplete:A,autoCapitalize:R,onKeyDown:f=>{let{key:v,target:F}=f;{let y=F,{selectionStart:N,selectionEnd:H}=y,z=Number(N),te=Number(H),Z=n.formatValue[Number(z)],O=n.formatValue[Number(z)-1];v=="Delete"&&(d=="creditCard"&&Z==" "||d=="postal"&&Z=="-"||d=="digitNumber"&&Z==",")&&(y.setSelectionRange(z+1,te+1),f.preventDefault()),v=="Backspace"&&(d=="creditCard"&&O==" "||d=="postal"&&O=="-"||d=="digitNumber"&&O==",")&&(y.setSelectionRange(z-1,te-1),f.preventDefault()),v=="Enter"||v=="Tab"}if(["number","digitNumber","creditCard"].includes(d)&&v=="Clear"&&u(y=>s(l({},y),{dataValue:"",formatValue:"",eventType:"update",eventID:_()})),["number","digitNumber"].includes(d)&&["ArrowUp","ArrowDown"].includes(v)){let y=+(v=="ArrowUp")*2-1,N=String(Number(n.dataValue)+y);r.ok&&t({ok:!1,notice:[]}),u(H=>s(l(l({},H),D.Validation.DataLeveling({min:E,max:I,restrict:d,value:N})),{eventType:"update",eventID:_()})),f.preventDefault()}W&&W(f),U&&M.SubmitForm(f,C)},onChange:f=>{let{value:v,selectionStart:F,selectionEnd:y}=f.target,N=D.Validation.DataLeveling({min:E,max:I,restrict:d,value:v});m&&(N.formatValue=v),N.formatValue!=n.formatValue&&(r.ok&&t({ok:!1,notice:[]}),u(H=>s(l(l({},H),N),{prevValue:n.formatValue,eventType:"update",eventID:_(),caretFrom:Number(F),caretTo:Number(y)})),K&&K(f))},width:1},p),{onFocus:f=>{p!=null&&p.onFocus&&(p==null||p.onFocus(f)),i(!0)},onBlur:f=>{p!=null&&p.onBlur&&(p==null||p.onBlur(f)),i(!1)},onCompositionStart:f=>{p!=null&&p.onCompositionStart&&(p==null||p.onCompositionStart(f)),h(!0)},onCompositionEnd:f=>{if(p!=null&&p.onCompositionEnd&&(p==null||p.onCompositionEnd(f)),d=="text")return;let v=D.Validation.DataLeveling({min:E,max:I,restrict:d,value:n.formatValue});u(F=>s(l(l({},F),v),{prevValue:F.formatValue,eventType:"update",eventID:_(),caretFrom:Number(F.formatValue.length+1),caretTo:Number(F.formatValue.length+1)})),h(!1)}}))},TextAreaBox:e=>{let{rootStates:a,val_focus:r,set_focus:t,val_validate:n,set_validate:u,val_status:c,set_status:i,isShallow:m}=e,E=a,{componentID:h,tone:b,required:k,form:T,label:d,isLabelActive:C,minRows:A,maxRows:R,multiline:oe,autoHeight:re,enableFormSubmit:X,maxLength:se,checkValidationAtFirst:U,onChange:P,onKeyDown:B,onValidate:K,onUpdateValue:W,onUpdateValidValue:ue,value:me="",leftIndicator:pe,rightIndicator:ce,leftIcon:de,rightIcon:fe,wrapStyles:ge}=E,x=q(E,["componentID","tone","required","form","label","isLabelActive","minRows","maxRows","multiline","autoHeight","enableFormSubmit","maxLength","checkValidationAtFirst","onChange","onKeyDown","onValidate","onUpdateValue","onUpdateValidValue","value","leftIndicator","rightIndicator","leftIcon","rightIcon","wrapStyles"]);return!a.multiline?null:o(V,s(l({htmlTag:"textarea","data-show-validation":M.isShowValidation(n,c,!!U),"data-input-origin":c.componentID,"data-component-id":c.componentID,value:c.dataValue,width:1},x),{onFocus:I=>{x!=null&&x.onFocus&&(x==null||x.onFocus(I)),t(!0)},onBlur:I=>{x!=null&&x.onBlur&&(x==null||x.onBlur(I)),t(!1)},onKeyDown:I=>{B&&B(I),X&&M.SubmitForm(I,T)},onChange:I=>{let{value:j}=I.target;n.ok&&u({ok:!1,notice:[]}),i(Q=>s(l({},Q),{dataValue:j,eventType:"update",eventID:_()})),P&&P(I)}}))}},Ne=e=>{let{componentID:a,restrict:r="text",value:t="",min:n,max:u}=e,[c,i]=L(!1),[m,h]=L(!1),[b,k]=L(s(l({componentID:a},D.Validation.DataLeveling({min:n,max:u,restrict:r,value:t})),{prevValue:"",eventType:"init",eventID:_(),caretFrom:null,caretTo:null})),[T,d]=L({ok:!1,notice:[]}),C={rootStates:e,val_focus:c,set_focus:i,val_isComposing:m,set_isComposing:h,val_status:b,set_status:k,val_validate:T,set_validate:d};return M.CommonEffects({type:"textfield",states:e,val_status:b,set_status:k,val_validate:T,set_validate:d,SystemValidation:D.Validation.System,ExtraOverrideStates:l({},D.Validation.DataLeveling({min:n,max:u,restrict:r,value:t}))}),J(()=>{D.setSelection({id:e.id,restrict:r,val_status:b})},[b]),$(we,{val_status:b,set_status:k,val_validate:T,states:C.rootStates,children:[o(De,{componentID:e.componentID,fontSize:e.fontSize,required:e.required,label:e.label,isActive:e.isLabelActive||c||!!b.dataValue}),o(G.Shallow,l({},C)),o(G.InputBox,l({},C)),o(G.TextAreaBox,l({},C))]})},S=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),o(ye,{componentID:e.componentID,children:Ne,states:Ve(e)})),g=S;g.Validate=D.Validation.Text,g.Katakana=e=>o(S,s(l({},e),{restrict:"katakana",multiline:!1,autoHeight:!1})),g.HankakuKatakana=e=>o(S,s(l({},e),{restrict:"hankaku.katakana",multiline:!1,autoHeight:!1})),g.CreditCard=e=>o(S,s(l({},e),{restrict:"creditCard",multiline:!1,autoHeight:!1})),g.Tel=e=>o(S,s(l({},e),{restrict:"tel",multiline:!1,autoHeight:!1})),g.Number=e=>o(S,s(l({},e),{restrict:"number",multiline:!1,autoHeight:!1})),g.DigitNumber=e=>o(S,s(l({},e),{restrict:"digitNumber",multiline:!1,autoHeight:!1})),g.Email=e=>o(S,s(l({},e),{restrict:"email",multiline:!1,autoHeight:!1})),g.Url=e=>o(S,s(l({},e),{restrict:"url",multiline:!1,autoHeight:!1})),g.Postal=e=>{let[a]=L(_());return J(()=>()=>{ve.delete(a)},[]),o(S,s(l({label:"\u90F5\u4FBF\u756A\u53F7"},e),{restrict:"postal",multiline:!1,autoHeight:!1,leftIcon:o(ke,{ssSphere:2,fontColor:"4.thin",children:"\u3012"})}))},g.Password=e=>o(S,s(l({label:"\u30D1\u30B9\u30EF\u30FC\u30C9",rightIcon:o(ne,{ssSphere:2,padding:0,freeCSS:{pointerEvents:"all"},children:o(Ce.Sub,{ssSphere:2,borderRadius:"3.tone.tertiary",fontColor:"theme",flexCenter:!0,height:1,ssEffectsOnActive:["expand"],onMouseOver:a=>{ie.open(a.currentTarget,"\u30C6\u30AD\u30B9\u30C8\u3092\u8868\u793A",24)},onMouseLeave:ie.abort,tabIndex:-1,onClick:a=>{w(a.target).parent().parent().find("input").callback(r=>{let t=r[0];t.type=t.type==="password"?"text":"password"})},children:o(Te,{icon:Re})})}),restrict:"password"},e),{multiline:!1,autoHeight:!1})),g.Concealed=e=>o(g.Password,s(l({label:"\u79D8\u5BC6\u9375"},e),{restrict:"concealed"})),g.Money={JPY:e=>o(g.DigitNumber,s(l({rightIcon:o(ne,{ssSphere:2,fontColor:"4.thin",children:"\u5186"})},e),{multiline:!1,autoHeight:!1}))};export{g as TextField,Ne as TextInput,g 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}from"jmini";import*as K from"jmini";import{useState as W,useEffect as Q,useRef as pe}from"react";import{$$fromRoot as ce,Config as re,useStore as L,ExtractStyles as ue}from"../../../@utils";import{Box as X,FAI as de}from"../../../atoms";import{Text 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 xe}from"..";import be 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,f=G.flatArray(D||""),{defaultValue:h,format:I,ranges:u,sets:r}=we[t],m=[],o=t=="clock"?":":"/";for(let i=0;i<f.length;i++)f[i]=String(f[i]).replace(/\D/ig,o);for(let i=0;i<r;i++){let d=f[i]||"";if(!d.match(I))f[i]="",m.push(h);else{let b=h;d.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)}b=b.replace(new RegExp("------------------".slice(0,E.length)),E)}),m.push(b)}}return{formatValue:m.join(F),dataValue:["dates","months"].includes(t)?f:f[0],ranges:u}},SystemValidation:e=>{let{states:t}=e,{restrict:D,min:a,max:f,required:h}=t,I=[],u=G.flatArray(e.value),r={empty:!1,escalated:1,filled:!0,correct:!0,prohibited:!1};(()=>{let m=D=="clock"?":":"/";for(let o=0;o<u.length;o++)u[o]=String(u[o]).replace(/\D/ig,m);for(let o=0;o<u.length;o++){let i=u[o],d=u[o-1];i.removeLetters()||(r.empty=!0),o>0&&(r.escalated&=+(i>=d))}r.escalated&&(r.empty||(D.match(/clock/)?u.forEach(o=>{let[i,d]=o.split(/\D+/);!i||!d?r.filled=!1:(Number(i)>23||Number(d)>59)&&(r.correct=!1)}):D.match(/date/)?u.forEach(o=>{let[i,d,b]=o.split(/\D+/);if(!i||!d||!b)r.filled=!1;else{let E=K.Time(o);(!E.validate||o!=E.toFormatYMD())&&(r.correct=!1)}}):D.match(/week/)?u.forEach(o=>{let[i,d]=o.split(/\D+/);if(!i||!d)r.filled=!1;else{let b=K.Time(i+"/01/01").weekday,R=K.Time(i+"/01/0"+(7-b+1)).addWeek(Number(d)-1);i!=String(R.year)&&(r.correct=!1)}}):D.match(/month/)?u.forEach(o=>{let[i,d]=o.split(/\D+/);!i||!d?r.filled=!1:K.Time([i,d,"01"].join("/")).validate||(r.correct=!1)}):D.match(/year/),r.filled&&r.correct&&u.forEach(o=>{{let i=Number(String(o).replace(/\D/ig,""));if(a&&Number(String(a).replace(/\D/ig,""))>i&&(r.prohibited=!0),f){let d=Number(String(f).replace(/\D/ig,""));i>d&&(r.prohibited=!0)}}})))})();{let{empty:m,escalated:o,filled:i,correct:d,prohibited:b}=r;m&&h&&(I=[{type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"}]),o||I.push({type:"invalid",label:"\u6642\u7CFB\u5217\u3092\u6B63\u3057\u304F\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}),d||I.push({type:"invalid",label:"\u7121\u52B9\u306A\u5024\u304C\u5165\u529B\u3055\u308C\u3066\u3044\u307E\u3059"}),i||I.push({type:"invalid",label:"\u6700\u5F8C\u307E\u3067\u5024\u3092\u57CB\u3081\u3066\u304F\u3060\u3055\u3044"}),b&&I.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","] ~ [",f||"\u4E0A\u9650\u7121\u3057","]"]})})}return{ok:!I.filter(({type:m})=>m=="invalid").length,notice:I}},KeyDownEvent:e=>{let{val_era:t,restrict:D,event:a,val_status:f,set_status:h,val_focus:I,set_focus:u}=e,{key:r,shiftKey:m,ctrlKey:o,metaKey:i}=a,d=o||i,{selectionStart:b,selectionEnd:E}=a.target,{index:R,prevIndex:S}=I,{ranges:$,formatValue:H}=f,C=$.length-1;if(["Tab","ArrowLeft","ArrowRight"].includes(r)){let v=0;if(r=="Tab"){let s=+!m*2-1;if(v=I.index+s,v<0||v>C)return}else{let s=r=="ArrowLeft"?-1:r=="ArrowRight"?1:0;d||b==0&&E==String(f.formatValue).length?v=s==1?C:0:v=Math.max(0,Math.min(R+s,C))}u(s=>k(l({},s),{index:v,prevIndex:R})),a.preventDefault()}if(["Backspace","ArrowUp","ArrowDown","0","1","2","3","4","5","6","7","8","9"].includes(r)){a.preventDefault();let v=R;v=Math.max(v,0),v=Math.min(v,C);let{type:s,from:B,length:Y}=$[v],_=H.slice(B,B+Y),c;if(r=="Backspace")c="------".slice(0,Y);else if(["ArrowUp","ArrowDown"].includes(r)){let w=r=="ArrowUp"?1:-1;_=_|0,c=_+w;let[n,p,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];c>p?c=n:c<n&&(c=p),c=Number(c).zeroEmbed(T)}else if(["0","1","2","3","4","5","6","7","8","9"].includes(r)){let w=_|0,n=r,p=`${w}${n}`;if(S!=R&&(w=0,p="0"+n),s=="year"||s=="dateWareki"&&t=="year")Number(p)>1e4?c=n:c=p,(c|0)>1e3&&v++;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;c=(p|0)>T?n:p,(Number(n)>Number(String(T)[0])||_=="0000".slice(0,String(T).length)&&(p!="0000".slice(0,String(T).length)||["minute","hour"].includes(s)&&S==R)||(p|0)>=ae(10,String(T).length-1))&&v++}s=="year"||s=="dateWareki"?c=(c|0).zeroEmbed(4):c=(c|0).zeroEmbed(2)}{let w=String(H).partReplace(B,String(c)),n=w.split(F).map(p=>p.replace(/(^\D|\D$)/,"").split(/\D+/).join(D=="clock"?":":"/").replace(/(^\D|\D$)/,""));if(D=="dateWareki"){let p=n[0].split(/\D/),[T,j,P]=p;p.length==3&&T&&(n=[[Number(T)-1+Number({year:1,reiwa:2019,heisei:1989,shouwa:1926,taisho:1912,meiji:1868}[t]),j,P].join("/")])}v=Math.max(v,0),v=Math.min(v,C),h(p=>k(l({},p),{dataValue:["dates","months"].includes(D)?n:n[0],formatValue:w,eventType:"update",eventID:N()})),u(p=>k(l({},p),{index:v,prevIndex:p.index}))}}}},ne={picker:{launch:e=>{let t=e.sheetID||N(),m=e,{onValueUpdate:D,min:a,max:f,era:h,restrict:I,defaultValue:u}=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:I,min:a,max:f,era:h,defaultValue:u,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:f,era:h,form:I,name:u,min:r,max:m,className:o,enableFormSubmit:i,checkValidationAtFirst:d,onKeyDown:b,onValidate:E,onUpdateValue:R,onUpdateValidValue:S,value:$="",leftIndicator:H,rightIndicator:C,leftIcon:v,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"]),[c,w]=W(h),[n,p]=W(k(l({componentID:e.componentID||""},O.DataLeveling({restrict:a,value:$,era:c})),{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:p,val_validate:T,set_validate:j,val_era:c,set_era:w,val_focus:P,set_focus:U};z.CommonEffects({type:"time",states:e,val_status:n,set_status:p,val_validate:T,set_validate:j,SystemValidation:O.SystemValidation,ExtraOverrideStates:l({},O.DataLeveling({restrict:a,value:$,era:c}))});const Z=pe(!1);return Q(()=>{if(Z.current){p(x=>l(l({},x),O.DataLeveling({restrict:a,value:x.dataValue,era:c})));let g=L.get("refreshEra_"+n.componentID);g&&g.refreshEra(c)}else Z.current=!0},[c]),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:c,onValueUpdate:(x,A)=>{p(M=>k(l(l({},M),O.DataLeveling({restrict:a,value:x,era:A})),{eventType:"update",eventID:N()})),w(A)}})},resetEra:g=>{w(g),p(x=>k(l(l({},x),O.DataLeveling({restrict:a,value:"",era:c})),{eventType:"update",eventID:N()}))}}}),Q(()=>{let{index:g,active:x}=P;if(x){g=Math.max(g,0),g=Math.min(g,n.ranges.length-1);let{from:A,length:M}=n.ranges[g],J=ce("#"+e.id)[0];J&&J.setSelectionRange(A,A+M)}},[P]),oe(Se,{val_status:n,set_status:p,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,!!d),"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 x=L.get(n.componentID);x&&x.openPicker(`[data-input-origin="${n.componentID}"]`),g.stopPropagation()}})):y(X,l({htmlTag:"input",type:"text",inputMode:"numeric","data-show-validation":z.isShowValidation(T,n,!!d),"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:c,val_status:n,set_status:p,val_focus:P,set_focus:U}),b&&b(g),i&&z.SubmitForm(g,I)},onKeyUp:g=>{g.key=="Tab"&&U(x=>k(l({},x),{active:!0}))},onClick:g=>{let x=g.target.selectionEnd,A=0;n.ranges.forEach((M,J)=>{let{from:te,length:se,region:me}=M;te<=x&&x<=te+(me||se)&&(A=J)}),U(M=>k(l({},M),{active:!0,index:A})),g.preventDefault()},onChange:()=>{}},_))]})},V={Origin:e=>{let t=l({},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(xe,{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 f=L.get(t.componentID);f&&f.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,f]=W((()=>{let h="year";if(D=="wareki"&&(h="reiwa",e.value)){let[I,u,r]=e.value.split(/\D/);if(I&&u&&r){let m=Number(I);m>=2019?(m-=2019,h="reiwa"):m>=1989?(m-=1989,h="heisei"):m>=1926?(m-=1926,h="shouwa"):m>=1912?(m-=1912,h="taisho"):m>=1868&&(m-=1868,h="meiji"),m+=1}}return h})());return Q(()=>{L.set({["refreshEra_"+t]:{refreshEra:h=>{f(h)}}})},[]),y(V.Origin,k(l({restrict:"dateWareki",leftIndicator:y(be,{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:({value:h,eventType:I})=>{f(h);let u=L.get(e.componentID);u&&u.resetEra&&u.resetEra(h)}})},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}from"jmini";import*as K from"jmini";import{useState as W,useEffect as Q,useRef as pe}from"react";import{$$fromRoot as ce,Config as re,useStore as L,ExtractStyles as ue}from"../../../@utils";import{Box as X,FAI as de}from"../../../atoms";import{Text 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 xe}from"..";import be 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,f=G.flatArray(D||""),{defaultValue:h,format:I,ranges:u,sets:r}=we[t],m=[],o=t=="clock"?":":"/";for(let i=0;i<f.length;i++)f[i]=String(f[i]).replace(/\D/ig,o);for(let i=0;i<r;i++){let d=f[i]||"";if(!d.match(I))f[i]="",m.push(h);else{let b=h;d.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)}b=b.replace(new RegExp("------------------".slice(0,E.length)),E)}),m.push(b)}}return{formatValue:m.join(F),dataValue:["dates","months"].includes(t)?f:f[0],ranges:u}},SystemValidation:e=>{let{states:t}=e,{restrict:D,min:a,max:f,required:h}=t,I=[],u=G.flatArray(e.value),r={empty:!1,escalated:1,filled:!0,correct:!0,prohibited:!1};(()=>{let m=D=="clock"?":":"/";for(let o=0;o<u.length;o++)u[o]=String(u[o]).replace(/\D/ig,m);for(let o=0;o<u.length;o++){let i=u[o],d=u[o-1];i.removeLetters()||(r.empty=!0),o>0&&(r.escalated&=+(i>=d))}r.escalated&&(r.empty||(D.match(/clock/)?u.forEach(o=>{let[i,d]=o.split(/\D+/);!i||!d?r.filled=!1:(Number(i)>23||Number(d)>59)&&(r.correct=!1)}):D.match(/date/)?u.forEach(o=>{let[i,d,b]=o.split(/\D+/);if(!i||!d||!b)r.filled=!1;else{let E=K.Time(o);(!E.validate||o!=E.toFormatYMD())&&(r.correct=!1)}}):D.match(/week/)?u.forEach(o=>{let[i,d]=o.split(/\D+/);if(!i||!d)r.filled=!1;else{let b=K.Time(i+"/01/01").weekday,R=K.Time(i+"/01/0"+(7-b+1)).addWeek(Number(d)-1);i!=String(R.year)&&(r.correct=!1)}}):D.match(/month/)?u.forEach(o=>{let[i,d]=o.split(/\D+/);!i||!d?r.filled=!1:K.Time([i,d,"01"].join("/")).validate||(r.correct=!1)}):D.match(/year/),r.filled&&r.correct&&u.forEach(o=>{{let i=Number(String(o).replace(/\D/ig,""));if(a&&Number(String(a).replace(/\D/ig,""))>i&&(r.prohibited=!0),f){let d=Number(String(f).replace(/\D/ig,""));i>d&&(r.prohibited=!0)}}})))})();{let{empty:m,escalated:o,filled:i,correct:d,prohibited:b}=r;m&&h&&(I=[{type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"}]),o||I.push({type:"invalid",label:"\u6642\u7CFB\u5217\u3092\u6B63\u3057\u304F\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}),d||I.push({type:"invalid",label:"\u7121\u52B9\u306A\u5024\u304C\u5165\u529B\u3055\u308C\u3066\u3044\u307E\u3059"}),i||I.push({type:"invalid",label:"\u6700\u5F8C\u307E\u3067\u5024\u3092\u57CB\u3081\u3066\u304F\u3060\u3055\u3044"}),b&&I.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","] ~ [",f||"\u4E0A\u9650\u7121\u3057","]"]})})}return{ok:!I.filter(({type:m})=>m=="invalid").length,notice:I}},KeyDownEvent:e=>{let{val_era:t,restrict:D,event:a,val_status:f,set_status:h,val_focus:I,set_focus:u}=e,{key:r,shiftKey:m,ctrlKey:o,metaKey:i}=a,d=o||i,{selectionStart:b,selectionEnd:E}=a.target,{index:R,prevIndex:S}=I,{ranges:$,formatValue:H}=f,C=$.length-1;if(["Tab","ArrowLeft","ArrowRight"].includes(r)){let v=0;if(r=="Tab"){let s=+!m*2-1;if(v=I.index+s,v<0||v>C)return}else{let s=r=="ArrowLeft"?-1:r=="ArrowRight"?1:0;d||b==0&&E==String(f.formatValue).length?v=s==1?C:0:v=Math.max(0,Math.min(R+s,C))}u(s=>k(l({},s),{index:v,prevIndex:R})),a.preventDefault()}if(["Backspace","ArrowUp","ArrowDown","0","1","2","3","4","5","6","7","8","9"].includes(r)){a.preventDefault();let v=R;v=Math.max(v,0),v=Math.min(v,C);let{type:s,from:B,length:Y}=$[v],_=H.slice(B,B+Y),c;if(r=="Backspace")c="------".slice(0,Y);else if(["ArrowUp","ArrowDown"].includes(r)){let w=r=="ArrowUp"?1:-1;_=_|0,c=_+w;let[n,p,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];c>p?c=n:c<n&&(c=p),c=Number(c).zeroEmbed(T)}else if(["0","1","2","3","4","5","6","7","8","9"].includes(r)){let w=_|0,n=r,p=`${w}${n}`;if(S!=R&&(w=0,p="0"+n),s=="year"||s=="dateWareki"&&t=="year")Number(p)>1e4?c=n:c=p,(c|0)>1e3&&v++;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;c=(p|0)>T?n:p,(Number(n)>Number(String(T)[0])||_=="0000".slice(0,String(T).length)&&(p!="0000".slice(0,String(T).length)||["minute","hour"].includes(s)&&S==R)||(p|0)>=ae(10,String(T).length-1))&&v++}s=="year"||s=="dateWareki"?c=(c|0).zeroEmbed(4):c=(c|0).zeroEmbed(2)}{let w=String(H).partReplace(B,String(c)),n=w.split(F).map(p=>p.replace(/(^\D|\D$)/,"").split(/\D+/).join(D=="clock"?":":"/").replace(/(^\D|\D$)/,""));if(D=="dateWareki"){let p=n[0].split(/\D/),[T,j,P]=p;p.length==3&&T&&(n=[[Number(T)-1+Number({year:1,reiwa:2019,heisei:1989,shouwa:1926,taisho:1912,meiji:1868}[t]),j,P].join("/")])}v=Math.max(v,0),v=Math.min(v,C),h(p=>k(l({},p),{dataValue:["dates","months"].includes(D)?n:n[0],formatValue:w,eventType:"update",eventID:N()})),u(p=>k(l({},p),{index:v,prevIndex:p.index}))}}}},ne={picker:{launch:e=>{let t=e.sheetID||N(),m=e,{onValueUpdate:D,min:a,max:f,era:h,restrict:I,defaultValue:u}=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:I,min:a,max:f,era:h,defaultValue:u,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:f,era:h,form:I,name:u,min:r,max:m,className:o,enableFormSubmit:i,checkValidationAtFirst:d,onKeyDown:b,onValidate:E,onUpdateValue:R,onUpdateValidValue:S,value:$="",leftIndicator:H,rightIndicator:C,leftIcon:v,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"]),[c,w]=W(h),[n,p]=W(k(l({componentID:e.componentID||""},O.DataLeveling({restrict:a,value:$,era:c})),{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:p,val_validate:T,set_validate:j,val_era:c,set_era:w,val_focus:P,set_focus:U};z.CommonEffects({type:"time",states:e,val_status:n,set_status:p,val_validate:T,set_validate:j,SystemValidation:O.SystemValidation,ExtraOverrideStates:l({},O.DataLeveling({restrict:a,value:$,era:c}))});const Z=pe(!1);return Q(()=>{if(Z.current){p(x=>l(l({},x),O.DataLeveling({restrict:a,value:x.dataValue,era:c})));let g=L.get("refreshEra_"+n.componentID);g&&g.refreshEra(c)}else Z.current=!0},[c]),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:c,onValueUpdate:(x,A)=>{p(M=>k(l(l({},M),O.DataLeveling({restrict:a,value:x,era:A})),{eventType:"update",eventID:N()})),w(A)}})},resetEra:g=>{w(g),p(x=>k(l(l({},x),O.DataLeveling({restrict:a,value:"",era:c})),{eventType:"update",eventID:N()}))}}}),Q(()=>{let{index:g,active:x}=P;if(x){g=Math.max(g,0),g=Math.min(g,n.ranges.length-1);let{from:A,length:M}=n.ranges[g],J=ce("#"+e.id)[0];J&&J.setSelectionRange(A,A+M)}},[P]),oe(Se,{val_status:n,set_status:p,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,!!d),"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 x=L.get(n.componentID);x&&x.openPicker(`[data-input-origin="${n.componentID}"]`),g.stopPropagation()}})):y(X,l({htmlTag:"input",type:"text",inputMode:"numeric","data-show-validation":z.isShowValidation(T,n,!!d),"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:c,val_status:n,set_status:p,val_focus:P,set_focus:U}),b&&b(g),i&&z.SubmitForm(g,I)},onKeyUp:g=>{g.key=="Tab"&&U(x=>k(l({},x),{active:!0}))},onClick:g=>{let x=g.target.selectionEnd,A=0;n.ranges.forEach((M,J)=>{let{from:te,length:se,region:me}=M;te<=x&&x<=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"},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(xe,{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 f=L.get(t.componentID);f&&f.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,f]=W((()=>{let h="year";if(D=="wareki"&&(h="reiwa",e.value)){let[I,u,r]=e.value.split(/\D/);if(I&&u&&r){let m=Number(I);m>=2019?(m-=2019,h="reiwa"):m>=1989?(m-=1989,h="heisei"):m>=1926?(m-=1926,h="shouwa"):m>=1912?(m-=1912,h="taisho"):m>=1868&&(m-=1868,h="meiji"),m+=1}}return h})());return Q(()=>{L.set({["refreshEra_"+t]:{refreshEra:h=>{f(h)}}})},[]),y(V.Origin,k(l({restrict:"dateWareki",leftIndicator:y(be,{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:({value:h,eventType:I})=>{f(h);let u=L.get(e.componentID);u&&u.resetEra&&u.resetEra(h)}})},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};
|