UNPKG

amotify

Version:

UI Component for React,NextJS,esbuild

2 lines (1 loc) 1.82 kB
import{b as o,c as r,d as b}from"../../chunk-C5N2D3ZX.js";import{jsx as c}from"react/jsx-runtime";import{UUID as g}from"jmini";import{useState as h}from"react";import{OptionalInputWrapper as w,BoxWrapper as _,CoreEffects as s,DefaultBoxishStyles as B}from"./core";import{Box as k}from"../../atoms";function F(t){let{value:e,states:d}=t,{required:m}=d,n=[];return m&&!e&&n.push({type:"invalid",label:"\u5FC5\u9808\u9805\u76EE\u3067\u3059"}),{ok:!n.filter(({type:p})=>p=="invalid").length,notice:n}}const H=t=>{let T=t,{componentID:e,tone:d,required:m,form:n,value:p,enableFormSubmit:S,checkValidationAtFirst:C,onInput:f,onKeyDown:I,onValidate:L,onUpdateValue:M,onUpdateValidValue:U,children:D="",leftIndicator:W,rightIndicator:q,leftIcon:A,rightIcon:K,freeCSS:G,wrapStyles:N}=T,E=b(T,["componentID","tone","required","form","value","enableFormSubmit","checkValidationAtFirst","onInput","onKeyDown","onValidate","onUpdateValue","onUpdateValidValue","children","leftIndicator","rightIndicator","leftIcon","rightIcon","freeCSS","wrapStyles"]),[i,u]=h(s.DefaultStatus(e,p)),[l,y]=h({ok:!1,notice:[]});return s.CommonEffects({type:"contenteditable",states:t,val_status:i,set_status:u,val_validate:l,set_validate:y,SystemValidation:F}),c(_,{val_status:i,set_status:u,val_validate:l,states:t,children:c(k,r(o({contentEditable:!0,"data-show-validation":s.isShowValidation(l,i,!!C),"data-component-id":i.componentID,onKeyDown:a=>{I&&I(a),S&&s.SubmitForm(a,n)},onInput:a=>{let R=a.currentTarget,{innerHTML:O,innerText:V}=R;l.ok&&y({ok:!1,notice:[]}),u(x=>r(o({},x),{dataValue:V,eventType:"update",eventID:g()})),f&&f(a)}},E),{children:D}))})},v=t=>{t=r(o({rows:5},t),{freeCSS:o({whiteSpace:"pre-wrap"},t.freeCSS)});let e=B(t);return c(w,{componentID:t.componentID,children:H,states:e})};export{v as Contenteditable,v as default};