amotify 0.2.121 → 0.2.122
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.
- package/dist/fn/Input/Select.js +1 -1
- package/package.json +1 -1
package/dist/fn/Input/Select.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as n,c as
|
|
1
|
+
import{b as n,c as p,d as j}from"../../chunk-C5N2D3ZX.js";import{Fragment as ee,jsx as l,jsxs as E}from"react/jsx-runtime";import f,{UUID as R}from"jmini";import{useState as x,useEffect as G}from"react";import{ExtractStyles as re}from"../../@utils";import{Box as h,Span as se,FAI as Q,Column as ie}from"../../atoms";import{Text as F,Row as Y}from"../../mols";import{Button as ue}from"../Button";import{Sheet as ce}from"../Sheet";import{OptionalInputWrapper as pe,BoxWrapper as Se,CoreEffects as k,DefaultBoxishStyles as de}from"./core";import{InputAutocompleteClasses as w}from"../../@styles/componentClasses";import{InputLabel as fe}from"./Label";import{RightIcon as me}from".";function ve(e){let{value:t,states:a}=e,{required:r,options:o}=a,S=[];return r&&t===null&&S.push({type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"}),{ok:!S.filter(({type:m})=>m=="invalid").length,notice:S}}const P={FilterSelectableOptions:(e,t)=>{let a=e.rootStates.options;return t||(a=a.filter(r=>r.type!="label")),a}},T={Shallow:e=>{let{rootStates:t,val_status:a}=e,r=re(t);return l(h,{position:"absolute",top:0,left:0,right:0,height:0,overflow:"hidden",opacity:"trans",freeCSS:{zIndex:3,pointerEvents:"none"},children:l(F.Description,p(n({className:t.className},r),{position:"absolute",width:1,freeCSS:p(n({},r.freeCSS),{color:"orange"}),children:l(h,{"data-input-value-shallow":a.componentID,children:"A"})}))})},Button:e=>{let{rootStates:t,val_preventOpenSelectorOnFocus:a,set_preventOpenSelectorOnFocus:r,val_optionFocused:o,set_optionFocused:S,val_validate:m,set_validate:A,val_status:v,set_status:y,val_selectorOpen:c,set_selectorOpen:u}=e,L=t,{tone:D,required:_,form:te,className:le,label:ye,isLabelActive:be,placeholder:Ie,enableFormSubmit:ae,emptySelect:ge,checkValidationAtFirst:oe,onValidate:he,onUpdateValue:Ce,onUpdateValidValue:Te,value:_e="",options:xe,leftIndicator:De,rightIndicator:Oe,leftIcon:Ve,rightIcon:Re,componentID:Fe,status_id:ke,wrapStyles:we,SelectedCellStyles:Ee,SelectorCellStyles:Ae,SelectorStyles:Be,SelectorPosition:We}=L,s=j(L,["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","SelectorStyles","SelectorPosition"]);return G(()=>{if(t.disabled)return;let i="select-click-"+t.componentID;if(c){if(!f('[data-input-origin="'+t.componentID+'"]'))return;f(document).addEvent({eventID:i,eventType:"click",callback:B=>{let O=f(B.target),V=!!f(O).parent("."+w("Core")).length;f(O).parent("."+w("Selector")).length||V||u(!1)}})}else f(document).removeEvent([i])},[c]),G(()=>{if(v.eventType=="init"||!c)return;let i=f('[data-input-origin="'+t.componentID+'"]');i&&i.focus()},[v.dataValue]),E(ee,{children:[l(h,p(n({tabIndex:0},s),{"data-disabled":t.disabled,"data-show-validation":k.isShowValidation(m,v,!!oe),"data-component-id":v.componentID,"data-input-origin":v.componentID,className:[le,w("Core")].join(" "),onFocus:i=>{if(s!=null&&s.onFocus&&(s==null||s.onFocus(i)),!t.disabled){if(a)return r(!1);u(!0)}},onClick:i=>{s!=null&&s.onClick&&(s==null||s.onClick(i)),!t.disabled&&u(!0)},onKeyDown:i=>{let{key:b,metaKey:B,ctrlKey:O}=i,V=B||O;if(s!=null&&s.onKeyDown&&(s==null||s.onKeyDown(i)),ae&&k.SubmitForm(i,te),!t.disabled){if(f.scope(()=>{if(!["ArrowDown","ArrowUp"].includes(b))return;if(i.preventDefault(),!c)return u(!0);let I=b=="ArrowDown"?1:-1,d=P.FilterSelectableOptions(e),W=d.length-1,g=null;f.scope(()=>{var N,K,q,z,U,H,M,$,J,X;let C=d.findIndex(ne=>ne.value==o);if(I==1){if(g=(K=(N=d[0])==null?void 0:N.value)!=null?K:null,V){g=(q=d[W].value)!=null?q:null;return}if(C==-1||C==W)return;g=(U=(z=d[C+1])==null?void 0:z.value)!=null?U:null}else{if(g=(H=d[W].value)!=null?H:null,V){g=($=(M=d[0])==null?void 0:M.value)!=null?$:null;return}if(C==-1||C==0)return;g=(X=(J=d[C-1])==null?void 0:J.value)!=null?X:null}}),S(g)}),b=="Escape")u(!1);else if(b=="Tab")u(!1);else if(b=="Backspace")y(I=>p(n({},I),{dataValue:null,eventType:"update",eventID:R()}));else if(b==" ")i.preventDefault(),u(!0);else if(b=="Enter"){if(!c)return u(!0);i.preventDefault();let I=t.options.find(d=>d.value==o);if(!I)return;y(d=>p(n({},d),{dataValue:I.value,eventType:"update",eventID:R()})),u(!1)}}},children:E(Y.Left,{flexWrap:!0,gap:"1/3",freeCSS:{letterSpacing:".5px"},children:[l(T.Placeholder,n({},e)),l(T.Selected,n({},e)),l(se,{width:0,overflow:"hidden",opacity:"trans",children:"A"})]})})),c&&l(T.Selector,n({},e))]})},Placeholder:e=>!e.rootStates.placeholder||e.val_status.dataValue!==null?null:l(h,{position:"absolute",opacity:"middle",fontColor:"3.blur",children:e.rootStates.placeholder||""}),Selector:e=>{var S;let t=[],a=P.FilterSelectableOptions(e,!0),r=P.FilterSelectableOptions(e);a.forEach((m,A)=>{let{type:v,value:y}=m,c=e.val_optionFocused==y,u=e.val_status.dataValue===y;if(v=="selector"){t.push(l(ue.Sub.S,p(n({color:"cloud",backgroundColor:"trans",borderRadius:0,fontColor:"2.normal",textAlign:"left",padding:["1/2",1],isActive:u||c,isActiveStyles:c?{backgroundColor:"cloud"}:{backgroundColor:"theme.opa.few",fontColor:"theme"}},e.rootStates.SelectorCellStyles),{onClick:D=>{e.set_status(_=>p(n({},_),{dataValue:y,eventType:"update",eventID:R()})),e.set_selectorOpen(!1),e.set_preventOpenSelectorOnFocus(!0)},children:E(Y.Left,{gap:"1/2",children:[u&&l(Q.Check,{fontColor:"theme"}),l(F.Supplement,{transition:"short",flexSizing:0,children:m.label})]})}),String(y)));return}t.push(l(h,{children:m.label},R()))}),r.length||(t=[l(F.Supplement,{padding:[0,1],fontColor:"4.thin",children:"\u5019\u88DC\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093"},"no-selector-notice")]);let o={position:"absolute",minWidth:1,freeCSS:{zIndex:1e3}};switch(e.rootStates.SelectorPosition){case 1:o.bottom="100%",o.left=0,o.paddingBottom="1/3";break;case 2:o.bottom="100%",o.right=0,o.paddingBottom="1/3";break;case 3:o.top="100%",o.left=0,o.paddingTop="1/3";break;case 4:o.top="100%",o.right=0,o.paddingTop="1/3";break;default:break}return l(h,p(n({},o),{children:l(ce.Body,p(n({className:w("Selector"),ssCardBox:!0,borderRadius:"2.tone.secondary",boxShadow:"1.normal",overflow:"auto"},e.rootStates.SelectorStyles),{freeCSS:n({minWidth:12*6,maxHeight:12*24},(S=e.rootStates.SelectorStyles)==null?void 0:S.freeCSS),children:l(ie,{gap:"1/12",padding:[1,0],children:t})}))}))},Selected:e=>{let t=[];return e.val_status.dataValue!==null&&f.scope(()=>{let a=e.rootStates.options.find(r=>f.is.equal(r.value,e.val_status.dataValue));a&&t.push(l(h,p(n({},e.rootStates.SelectedCellStyles),{children:a.label}),String(a.value)))}),l(ee,{children:t})},Core:e=>{var _;let{value:t}=e,[a,r]=x(k.DefaultStatus(e.componentID,t)),[o,S]=x(!1),[m,A]=x(!1),[v,y]=x((_=e.value)!=null?_:null),[c,u]=x({ok:!1,notice:[]}),D={rootStates:e,val_preventOpenSelectorOnFocus:o,set_preventOpenSelectorOnFocus:S,val_optionFocused:v,set_optionFocused:y,val_selectorOpen:m,set_selectorOpen:A,val_status:a,set_status:r,val_validate:c,set_validate:u};return k.CommonEffects({type:"select",states:e,val_status:a,set_status:r,val_validate:c,set_validate:u,SystemValidation:ve}),E(Se,{val_status:a,set_status:r,val_validate:c,states:e,children:[l(fe,{componentID:e.componentID,fontSize:e.fontSize,required:e.required,label:e.label,isActive:e.isLabelActive||a.dataValue!==null}),l(T.Shallow,n({},D)),l(T.Button,n({},D))]})}},Z=e=>{var a;let t=n({},e);return t=p(n({emptySelect:!0,SelectorPosition:3},t),{freeCSS:n({cursor:"pointer"},t.freeCSS)}),t.emptySelect&&(t.options=[{value:null,label:l(F.Supplement,{fontColor:"4.thin",children:"\u672A\u9078\u629E"})},...t.options]),t.value=(a=t.value)!=null?a:null,t.options.forEach((r,o)=>{let{type:S,value:m}=r;t.options[o]=p(n({},r),{value:m,type:S||"selector"})}),f.is.nullish(t.rightIcon)&&(t.rightIcon=l(me,{ssSphere:2,children:l(Q.AngleDown,{})})),l(pe,{componentID:t.componentID,children:T.Core,states:de(t)})};export{Z as Select,Z as default};
|