@tutim/headless
Version:
form infrastructure for web applications
27 lines (24 loc) • 50.7 kB
JavaScript
(function(O,E){typeof exports=="object"&&typeof module<"u"?E(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],E):(O=typeof globalThis<"u"?globalThis:O||self,E(O.headless={},O.React))})(this,function(O,E){"use strict";var or={},Gt={get exports(){return or},set exports(e){or=e}},Le={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var qr;function Yt(){if(qr)return Le;qr=1;var e=E,t=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,s=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function u(l,d,h){var _,w={},b=null,F=null;h!==void 0&&(b=""+h),d.key!==void 0&&(b=""+d.key),d.ref!==void 0&&(F=d.ref);for(_ in d)n.call(d,_)&&!a.hasOwnProperty(_)&&(w[_]=d[_]);if(l&&l.defaultProps)for(_ in d=l.defaultProps,d)w[_]===void 0&&(w[_]=d[_]);return{$$typeof:t,type:l,key:b,ref:F,props:w,_owner:s.current}}return Le.Fragment=r,Le.jsx=u,Le.jsxs=u,Le}var Ie={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var Gr;function Kt(){return Gr||(Gr=1,process.env.NODE_ENV!=="production"&&function(){var e=E,t=Symbol.for("react.element"),r=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),l=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),h=Symbol.for("react.suspense"),_=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),F=Symbol.for("react.offscreen"),M=Symbol.iterator,G="@@iterator";function Y(i){if(i===null||typeof i!="object")return null;var y=M&&i[M]||i[G];return typeof y=="function"?y:null}var K=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function V(i){{for(var y=arguments.length,m=new Array(y>1?y-1:0),k=1;k<y;k++)m[k-1]=arguments[k];H("error",i,m)}}function H(i,y,m){{var k=K.ReactDebugCurrentFrame,I=k.getStackAddendum();I!==""&&(y+="%s",m=m.concat([I]));var N=m.map(function(j){return String(j)});N.unshift("Warning: "+y),Function.prototype.apply.call(console[i],console,N)}}var U=!1,C=!1,x=!1,T=!1,B=!1,Q;Q=Symbol.for("react.module.reference");function ve(i){return!!(typeof i=="string"||typeof i=="function"||i===n||i===a||B||i===s||i===h||i===_||T||i===F||U||C||x||typeof i=="object"&&i!==null&&(i.$$typeof===b||i.$$typeof===w||i.$$typeof===u||i.$$typeof===l||i.$$typeof===d||i.$$typeof===Q||i.getModuleId!==void 0))}function D(i,y,m){var k=i.displayName;if(k)return k;var I=y.displayName||y.name||"";return I!==""?m+"("+I+")":m}function L(i){return i.displayName||"Context"}function P(i){if(i==null)return null;if(typeof i.tag=="number"&&V("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof i=="function")return i.displayName||i.name||null;if(typeof i=="string")return i;switch(i){case n:return"Fragment";case r:return"Portal";case a:return"Profiler";case s:return"StrictMode";case h:return"Suspense";case _:return"SuspenseList"}if(typeof i=="object")switch(i.$$typeof){case l:var y=i;return L(y)+".Consumer";case u:var m=i;return L(m._context)+".Provider";case d:return D(i,i.render,"ForwardRef");case w:var k=i.displayName||null;return k!==null?k:P(i.type)||"Memo";case b:{var I=i,N=I._payload,j=I._init;try{return P(j(N))}catch{return null}}}return null}var q=Object.assign,te=0,ie,_e,ge,Ae,De,Ne,We;function sr(){}sr.__reactDisabledLog=!0;function Lr(){{if(te===0){ie=console.log,_e=console.info,ge=console.warn,Ae=console.error,De=console.group,Ne=console.groupCollapsed,We=console.groupEnd;var i={configurable:!0,enumerable:!0,value:sr,writable:!0};Object.defineProperties(console,{info:i,log:i,warn:i,error:i,group:i,groupCollapsed:i,groupEnd:i})}te++}}function Ir(){{if(te--,te===0){var i={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:q({},i,{value:ie}),info:q({},i,{value:_e}),warn:q({},i,{value:ge}),error:q({},i,{value:Ae}),group:q({},i,{value:De}),groupCollapsed:q({},i,{value:Ne}),groupEnd:q({},i,{value:We})})}te<0&&V("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Ee=K.ReactCurrentDispatcher,Se;function we(i,y,m){{if(Se===void 0)try{throw Error()}catch(I){var k=I.stack.trim().match(/\n( *(at )?)/);Se=k&&k[1]||""}return`
`+Se+i}}var $e=!1,Te;{var nr=typeof WeakMap=="function"?WeakMap:Map;Te=new nr}function Be(i,y){if(!i||$e)return"";{var m=Te.get(i);if(m!==void 0)return m}var k;$e=!0;var I=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var N;N=Ee.current,Ee.current=null,Lr();try{if(y){var j=function(){throw Error()};if(Object.defineProperty(j.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(j,[])}catch(me){k=me}Reflect.construct(i,[],j)}else{try{j.call()}catch(me){k=me}i.call(j.prototype)}}else{try{throw Error()}catch(me){k=me}i()}}catch(me){if(me&&k&&typeof me.stack=="string"){for(var R=me.stack.split(`
`),ne=k.stack.split(`
`),X=R.length-1,Z=ne.length-1;X>=1&&Z>=0&&R[X]!==ne[Z];)Z--;for(;X>=1&&Z>=0;X--,Z--)if(R[X]!==ne[Z]){if(X!==1||Z!==1)do if(X--,Z--,Z<0||R[X]!==ne[Z]){var ce=`
`+R[X].replace(" at new "," at ");return i.displayName&&ce.includes("<anonymous>")&&(ce=ce.replace("<anonymous>",i.displayName)),typeof i=="function"&&Te.set(i,ce),ce}while(X>=1&&Z>=0);break}}}finally{$e=!1,Ee.current=N,Ir(),Error.prepareStackTrace=I}var je=i?i.displayName||i.name:"",qt=je?we(je):"";return typeof i=="function"&&Te.set(i,qt),qt}function Mr(i,y,m){return Be(i,!1)}function o(i){var y=i.prototype;return!!(y&&y.isReactComponent)}function c(i,y,m){if(i==null)return"";if(typeof i=="function")return Be(i,o(i));if(typeof i=="string")return we(i);switch(i){case h:return we("Suspense");case _:return we("SuspenseList")}if(typeof i=="object")switch(i.$$typeof){case d:return Mr(i.render);case w:return c(i.type,y,m);case b:{var k=i,I=k._payload,N=k._init;try{return c(N(I),y,m)}catch{}}}return""}var f=Object.prototype.hasOwnProperty,p={},A=K.ReactDebugCurrentFrame;function g(i){if(i){var y=i._owner,m=c(i.type,i._source,y?y.type:null);A.setExtraStackFrame(m)}else A.setExtraStackFrame(null)}function S(i,y,m,k,I){{var N=Function.call.bind(f);for(var j in i)if(N(i,j)){var R=void 0;try{if(typeof i[j]!="function"){var ne=Error((k||"React class")+": "+m+" type `"+j+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof i[j]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw ne.name="Invariant Violation",ne}R=i[j](y,j,k,m,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(X){R=X}R&&!(R instanceof Error)&&(g(I),V("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",k||"React class",m,j,typeof R),g(null)),R instanceof Error&&!(R.message in p)&&(p[R.message]=!0,g(I),V("Failed %s type: %s",m,R.message),g(null))}}}var J=Array.isArray;function W(i){return J(i)}function Ur(i){{var y=typeof Symbol=="function"&&Symbol.toStringTag,m=y&&i[Symbol.toStringTag]||i.constructor.name||"Object";return m}}function ze(i){try{return Re(i),!1}catch{return!0}}function Re(i){return""+i}function ir(i){if(ze(i))return V("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ur(i)),Re(i)}var be=K.ReactCurrentOwner,Nr={key:!0,ref:!0,__self:!0,__source:!0},qe,Mt,Wr;Wr={};function Bs(i){if(f.call(i,"ref")){var y=Object.getOwnPropertyDescriptor(i,"ref").get;if(y&&y.isReactWarning)return!1}return i.ref!==void 0}function zs(i){if(f.call(i,"key")){var y=Object.getOwnPropertyDescriptor(i,"key").get;if(y&&y.isReactWarning)return!1}return i.key!==void 0}function qs(i,y){if(typeof i.ref=="string"&&be.current&&y&&be.current.stateNode!==y){var m=P(be.current.type);Wr[m]||(V('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',P(be.current.type),i.ref),Wr[m]=!0)}}function Gs(i,y){{var m=function(){qe||(qe=!0,V("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",y))};m.isReactWarning=!0,Object.defineProperty(i,"key",{get:m,configurable:!0})}}function Ys(i,y){{var m=function(){Mt||(Mt=!0,V("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",y))};m.isReactWarning=!0,Object.defineProperty(i,"ref",{get:m,configurable:!0})}}var Ks=function(i,y,m,k,I,N,j){var R={$$typeof:t,type:i,key:y,ref:m,props:j,_owner:N};return R._store={},Object.defineProperty(R._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(R,"_self",{configurable:!1,enumerable:!1,writable:!1,value:k}),Object.defineProperty(R,"_source",{configurable:!1,enumerable:!1,writable:!1,value:I}),Object.freeze&&(Object.freeze(R.props),Object.freeze(R)),R};function Hs(i,y,m,k,I){{var N,j={},R=null,ne=null;m!==void 0&&(ir(m),R=""+m),zs(y)&&(ir(y.key),R=""+y.key),Bs(y)&&(ne=y.ref,qs(y,I));for(N in y)f.call(y,N)&&!Nr.hasOwnProperty(N)&&(j[N]=y[N]);if(i&&i.defaultProps){var X=i.defaultProps;for(N in X)j[N]===void 0&&(j[N]=X[N])}if(R||ne){var Z=typeof i=="function"?i.displayName||i.name||"Unknown":i;R&&Gs(j,Z),ne&&Ys(j,Z)}return Ks(i,R,ne,I,k,be.current,j)}}var $r=K.ReactCurrentOwner,Ut=K.ReactDebugCurrentFrame;function Pe(i){if(i){var y=i._owner,m=c(i.type,i._source,y?y.type:null);Ut.setExtraStackFrame(m)}else Ut.setExtraStackFrame(null)}var Br;Br=!1;function zr(i){return typeof i=="object"&&i!==null&&i.$$typeof===t}function Nt(){{if($r.current){var i=P($r.current.type);if(i)return`
Check the render method of \``+i+"`."}return""}}function Js(i){{if(i!==void 0){var y=i.fileName.replace(/^.*[\\\/]/,""),m=i.lineNumber;return`
Check your code at `+y+":"+m+"."}return""}}var Wt={};function Xs(i){{var y=Nt();if(!y){var m=typeof i=="string"?i:i.displayName||i.name;m&&(y=`
Check the top-level render call using <`+m+">.")}return y}}function $t(i,y){{if(!i._store||i._store.validated||i.key!=null)return;i._store.validated=!0;var m=Xs(y);if(Wt[m])return;Wt[m]=!0;var k="";i&&i._owner&&i._owner!==$r.current&&(k=" It was passed a child from "+P(i._owner.type)+"."),Pe(i),V('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',m,k),Pe(null)}}function Bt(i,y){{if(typeof i!="object")return;if(W(i))for(var m=0;m<i.length;m++){var k=i[m];zr(k)&&$t(k,y)}else if(zr(i))i._store&&(i._store.validated=!0);else if(i){var I=Y(i);if(typeof I=="function"&&I!==i.entries)for(var N=I.call(i),j;!(j=N.next()).done;)zr(j.value)&&$t(j.value,y)}}}function Qs(i){{var y=i.type;if(y==null||typeof y=="string")return;var m;if(typeof y=="function")m=y.propTypes;else if(typeof y=="object"&&(y.$$typeof===d||y.$$typeof===w))m=y.propTypes;else return;if(m){var k=P(y);S(m,i.props,"prop",k,i)}else if(y.PropTypes!==void 0&&!Br){Br=!0;var I=P(y);V("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",I||"Unknown")}typeof y.getDefaultProps=="function"&&!y.getDefaultProps.isReactClassApproved&&V("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Zs(i){{for(var y=Object.keys(i.props),m=0;m<y.length;m++){var k=y[m];if(k!=="children"&&k!=="key"){Pe(i),V("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",k),Pe(null);break}}i.ref!==null&&(Pe(i),V("Invalid attribute `ref` supplied to `React.Fragment`."),Pe(null))}}function zt(i,y,m,k,I,N){{var j=ve(i);if(!j){var R="";(i===void 0||typeof i=="object"&&i!==null&&Object.keys(i).length===0)&&(R+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var ne=Js(I);ne?R+=ne:R+=Nt();var X;i===null?X="null":W(i)?X="array":i!==void 0&&i.$$typeof===t?(X="<"+(P(i.type)||"Unknown")+" />",R=" Did you accidentally export a JSX literal instead of a component?"):X=typeof i,V("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",X,R)}var Z=Hs(i,y,m,I,N);if(Z==null)return Z;if(j){var ce=y.children;if(ce!==void 0)if(k)if(W(ce)){for(var je=0;je<ce.length;je++)Bt(ce[je],i);Object.freeze&&Object.freeze(ce)}else V("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Bt(ce,i)}return i===n?Zs(Z):Qs(Z),Z}}function en(i,y,m){return zt(i,y,m,!0)}function rn(i,y,m){return zt(i,y,m,!1)}var tn=rn,sn=en;Ie.Fragment=n,Ie.jsx=tn,Ie.jsxs=sn}()),Ie}(function(e){process.env.NODE_ENV==="production"?e.exports=Yt():e.exports=Kt()})(Gt);const fe=or.jsx;var Me=e=>e.type==="checkbox",Ce=e=>e instanceof Date,se=e=>e==null;const Yr=e=>typeof e=="object";var ee=e=>!se(e)&&!Array.isArray(e)&&Yr(e)&&!Ce(e),Kr=e=>ee(e)&&e.target?Me(e.target)?e.target.checked:e.target.value:e,Ht=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,Hr=(e,t)=>e.has(Ht(t)),xe=e=>Array.isArray(e)?e.filter(Boolean):[],z=e=>e===void 0,v=(e,t,r)=>{if(!t||!ee(e))return r;const n=xe(t.split(/[,[\].]+?/)).reduce((s,a)=>se(s)?s:s[a],e);return z(n)||n===e?z(e[t])?r:e[t]:n};const Ge={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},le={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},he={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},Jt=E.createContext(null),Ye=()=>E.useContext(Jt);var Jr=(e,t,r,n=!0)=>{const s={defaultValues:t._defaultValues};for(const a in e)Object.defineProperty(s,a,{get:()=>{const u=a;return t._proxyFormState[u]!==le.all&&(t._proxyFormState[u]=!n||le.all),r&&(r[u]=!0),e[u]}});return s},oe=e=>ee(e)&&!Object.keys(e).length,Xr=(e,t,r)=>{const{name:n,...s}=e;return oe(s)||Object.keys(s).length>=Object.keys(t).length||Object.keys(s).find(a=>t[a]===(!r||le.all))},ae=e=>Array.isArray(e)?e:[e],Qr=(e,t,r)=>r&&t?e===t:!e||!t||e===t||ae(e).some(n=>n&&(n.startsWith(t)||t.startsWith(n)));function Ke(e){const t=E.useRef(e);t.current=e,E.useEffect(()=>{const r=!e.disabled&&t.current.subject.subscribe({next:t.current.next});return()=>{r&&r.unsubscribe()}},[e.disabled])}function Xt(e){const t=Ye(),{control:r=t.control,disabled:n,name:s,exact:a}=e||{},[u,l]=E.useState(r._formState),d=E.useRef(!0),h=E.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1}),_=E.useRef(s);return _.current=s,Ke({disabled:n,next:w=>d.current&&Qr(_.current,w.name,a)&&Xr(w,h.current)&&l({...r._formState,...w}),subject:r._subjects.state}),E.useEffect(()=>{d.current=!0;const w=r._proxyFormState.isDirty&&r._getDirty();return w!==r._formState.isDirty&&r._subjects.state.next({isDirty:w}),r._updateValid(),()=>{d.current=!1}},[r]),Jr(u,r,h.current,!1)}var de=e=>typeof e=="string",Zr=(e,t,r,n,s)=>de(e)?(n&&t.watch.add(e),v(r,e,s)):Array.isArray(e)?e.map(a=>(n&&t.watch.add(a),v(r,a))):(n&&(t.watchAll=!0),r),Qt=e=>{const t=e.constructor&&e.constructor.prototype;return ee(t)&&t.hasOwnProperty("isPrototypeOf")},ar=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function ue(e){let t;const r=Array.isArray(e);if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else if(!(ar&&(e instanceof Blob||e instanceof FileList))&&(r||ee(e)))if(t=r?[]:{},!Array.isArray(e)&&!Qt(e))t=e;else for(const n in e)t[n]=ue(e[n]);else return e;return t}function et(e){const t=Ye(),{control:r=t.control,name:n,defaultValue:s,disabled:a,exact:u}=e||{},l=E.useRef(n);l.current=n,Ke({disabled:a,subject:r._subjects.watch,next:_=>{Qr(l.current,_.name,u)&&h(ue(Zr(l.current,r._names,_.values||r._formValues,!1,s)))}});const[d,h]=E.useState(r._getWatch(n,s));return E.useEffect(()=>r._removeUnmounted()),d}function Zt(e){const t=Ye(),{name:r,control:n=t.control,shouldUnregister:s}=e,a=Hr(n._names.array,r),u=et({control:n,name:r,defaultValue:v(n._formValues,r,v(n._defaultValues,r,e.defaultValue)),exact:!0}),l=Xt({control:n,name:r}),d=E.useRef(n.register(r,{...e.rules,value:u}));return E.useEffect(()=>{const h=(_,w)=>{const b=v(n._fields,_);b&&(b._f.mount=w)};return h(r,!0),()=>{const _=n._options.shouldUnregister||s;(a?_&&!n._stateFlags.action:_)?n.unregister(r):h(r,!1)}},[r,n,a,s]),{field:{name:r,value:u,onChange:E.useCallback(h=>d.current.onChange({target:{value:Kr(h),name:r},type:Ge.CHANGE}),[r]),onBlur:E.useCallback(()=>d.current.onBlur({target:{value:v(n._formValues,r),name:r},type:Ge.BLUR}),[r,n]),ref:h=>{const _=v(n._fields,r);_&&h&&(_._f.ref={focus:()=>h.focus(),select:()=>h.select(),setCustomValidity:w=>h.setCustomValidity(w),reportValidity:()=>h.reportValidity()})}},formState:l,fieldState:Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!v(l.errors,r)},isDirty:{enumerable:!0,get:()=>!!v(l.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!v(l.touchedFields,r)},error:{enumerable:!0,get:()=>v(l.errors,r)}})}}const es=e=>e.render(Zt(e));var rs=(e,t,r,n,s)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[n]:s||!0}}:{},ur=e=>/^\w*$/.test(e),rt=e=>xe(e.replace(/["|']|\]/g,"").split(/\.|\[/));function $(e,t,r){let n=-1;const s=ur(t)?[t]:rt(t),a=s.length,u=a-1;for(;++n<a;){const l=s[n];let d=r;if(n!==u){const h=e[l];d=ee(h)||Array.isArray(h)?h:isNaN(+s[n+1])?{}:[]}e[l]=d,e=e[l]}return e}const He=(e,t,r)=>{for(const n of r||Object.keys(e)){const s=v(e,n);if(s){const{_f:a,...u}=s;if(a&&t(a.name)){if(a.ref.focus){a.ref.focus();break}else if(a.refs&&a.refs[0].focus){a.refs[0].focus();break}}else ee(u)&&He(u,t)}}};var pe=()=>{const e=typeof performance>"u"?Date.now():performance.now()*1e3;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const r=(Math.random()*16+e)%16|0;return(t=="x"?r:r&3|8).toString(16)})},lr=(e,t,r={})=>r.shouldFocus||z(r.shouldFocus)?r.focusName||`${e}.${z(r.focusIndex)?t:r.focusIndex}.`:"",cr=e=>({isOnSubmit:!e||e===le.onSubmit,isOnBlur:e===le.onBlur,isOnChange:e===le.onChange,isOnAll:e===le.all,isOnTouch:e===le.onTouched}),fr=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some(n=>e.startsWith(n)&&/^\.\w+/.test(e.slice(n.length)))),tt=(e,t,r)=>{const n=xe(v(e,r));return $(n,"root",t[r]),$(e,r,n),e},ke=e=>typeof e=="boolean",dr=e=>e.type==="file",Ve=e=>typeof e=="function",Je=e=>{if(!ar)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Xe=e=>de(e)||E.isValidElement(e),yr=e=>e.type==="radio",Qe=e=>e instanceof RegExp;const st={value:!1,isValid:!1},nt={value:!0,isValid:!0};var it=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(r=>r&&r.checked&&!r.disabled).map(r=>r.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!z(e[0].attributes.value)?z(e[0].value)||e[0].value===""?nt:{value:e[0].value,isValid:!0}:nt:st}return st};const ot={isValid:!1,value:null};var at=e=>Array.isArray(e)?e.reduce((t,r)=>r&&r.checked&&!r.disabled?{isValid:!0,value:r.value}:t,ot):ot;function ut(e,t,r="validate"){if(Xe(e)||Array.isArray(e)&&e.every(Xe)||ke(e)&&!e)return{type:r,message:Xe(e)?e:"",ref:t}}var Oe=e=>ee(e)&&!Qe(e)?e:{value:e,message:""},gr=async(e,t,r,n,s)=>{const{ref:a,refs:u,required:l,maxLength:d,minLength:h,min:_,max:w,pattern:b,validate:F,name:M,valueAsNumber:G,mount:Y,disabled:K}=e._f;if(!Y||K)return{};const V=u?u[0]:a,H=D=>{n&&V.reportValidity&&(V.setCustomValidity(ke(D)?"":D||""),V.reportValidity())},U={},C=yr(a),x=Me(a),T=C||x,B=(G||dr(a))&&z(a.value)&&z(t)||Je(a)&&a.value===""||t===""||Array.isArray(t)&&!t.length,Q=rs.bind(null,M,r,U),ve=(D,L,P,q=he.maxLength,te=he.minLength)=>{const ie=D?L:P;U[M]={type:D?q:te,message:ie,ref:a,...Q(D?q:te,ie)}};if(s?!Array.isArray(t)||!t.length:l&&(!T&&(B||se(t))||ke(t)&&!t||x&&!it(u).isValid||C&&!at(u).isValid)){const{value:D,message:L}=Xe(l)?{value:!!l,message:l}:Oe(l);if(D&&(U[M]={type:he.required,message:L,ref:V,...Q(he.required,L)},!r))return H(L),U}if(!B&&(!se(_)||!se(w))){let D,L;const P=Oe(w),q=Oe(_);if(!se(t)&&!isNaN(t)){const te=a.valueAsNumber||t&&+t;se(P.value)||(D=te>P.value),se(q.value)||(L=te<q.value)}else{const te=a.valueAsDate||new Date(t),ie=Ae=>new Date(new Date().toDateString()+" "+Ae),_e=a.type=="time",ge=a.type=="week";de(P.value)&&t&&(D=_e?ie(t)>ie(P.value):ge?t>P.value:te>new Date(P.value)),de(q.value)&&t&&(L=_e?ie(t)<ie(q.value):ge?t<q.value:te<new Date(q.value))}if((D||L)&&(ve(!!D,P.message,q.message,he.max,he.min),!r))return H(U[M].message),U}if((d||h)&&!B&&(de(t)||s&&Array.isArray(t))){const D=Oe(d),L=Oe(h),P=!se(D.value)&&t.length>D.value,q=!se(L.value)&&t.length<L.value;if((P||q)&&(ve(P,D.message,L.message),!r))return H(U[M].message),U}if(b&&!B&&de(t)){const{value:D,message:L}=Oe(b);if(Qe(D)&&!t.match(D)&&(U[M]={type:he.pattern,message:L,ref:a,...Q(he.pattern,L)},!r))return H(L),U}if(F){if(Ve(F)){const D=await F(t),L=ut(D,V);if(L&&(U[M]={...L,...Q(he.validate,L.message)},!r))return H(L.message),U}else if(ee(F)){let D={};for(const L in F){if(!oe(D)&&!r)break;const P=ut(await F[L](t),V,L);P&&(D={...P,...Q(L,P.message)},H(P.message),r&&(U[M]=D))}if(!oe(D)&&(U[M]={ref:V,...D},!r))return U}}return H(!0),U};function hr(e,t){return[...e,...ae(t)]}var vr=e=>Array.isArray(e)?e.map(()=>{}):void 0;function mr(e,t,r){return[...e.slice(0,t),...ae(r),...e.slice(t)]}var pr=(e,t,r)=>Array.isArray(e)?(z(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[];function _r(e,t){return[...ae(t),...ae(e)]}function ts(e,t){let r=0;const n=[...e];for(const s of t)n.splice(s-r,1),r++;return xe(n).length?n:[]}var br=(e,t)=>z(t)?[]:ts(e,ae(t).sort((r,n)=>r-n)),Fr=(e,t,r)=>{e[t]=[e[r],e[r]=e[t]][0]};function ss(e,t){const r=t.slice(0,-1).length;let n=0;for(;n<r;)e=z(e)?n++:e[t[n++]];return e}function ns(e){for(const t in e)if(!z(e[t]))return!1;return!0}function re(e,t){const r=ur(t)?[t]:rt(t),n=r.length==1?e:ss(e,r),s=r[r.length-1];let a;n&&delete n[s];for(let u=0;u<r.slice(0,-1).length;u++){let l=-1,d;const h=r.slice(0,-(u+1)),_=h.length-1;for(u>0&&(a=e);++l<h.length;){const w=h[l];d=d?d[w]:e[w],_===l&&(ee(d)&&oe(d)||Array.isArray(d)&&ns(d))&&(a?delete a[w]:delete e[w]),a=d}}return e}var lt=(e,t,r)=>(e[t]=r,e);function is(e){const t=Ye(),{control:r=t.control,name:n,keyName:s="id",shouldUnregister:a}=e,[u,l]=E.useState(r._getFieldArray(n)),d=E.useRef(r._getFieldArray(n).map(pe)),h=E.useRef(u),_=E.useRef(n),w=E.useRef(!1);_.current=n,h.current=u,r._names.array.add(n),e.rules&&r.register(n,e.rules),Ke({next:({values:C,name:x})=>{if(x===_.current||!x){const T=v(C,_.current);Array.isArray(T)&&(l(T),d.current=T.map(pe))}},subject:r._subjects.array});const b=E.useCallback(C=>{w.current=!0,r._updateFieldArray(n,C)},[r,n]),F=(C,x)=>{const T=ae(ue(C)),B=hr(r._getFieldArray(n),T);r._names.focus=lr(n,B.length-1,x),d.current=hr(d.current,T.map(pe)),b(B),l(B),r._updateFieldArray(n,B,hr,{argA:vr(C)})},M=(C,x)=>{const T=ae(ue(C)),B=_r(r._getFieldArray(n),T);r._names.focus=lr(n,0,x),d.current=_r(d.current,T.map(pe)),b(B),l(B),r._updateFieldArray(n,B,_r,{argA:vr(C)})},G=C=>{const x=br(r._getFieldArray(n),C);d.current=br(d.current,C),b(x),l(x),r._updateFieldArray(n,x,br,{argA:C})},Y=(C,x,T)=>{const B=ae(ue(x)),Q=mr(r._getFieldArray(n),C,B);r._names.focus=lr(n,C,T),d.current=mr(d.current,C,B.map(pe)),b(Q),l(Q),r._updateFieldArray(n,Q,mr,{argA:C,argB:vr(x)})},K=(C,x)=>{const T=r._getFieldArray(n);Fr(T,C,x),Fr(d.current,C,x),b(T),l(T),r._updateFieldArray(n,T,Fr,{argA:C,argB:x},!1)},V=(C,x)=>{const T=r._getFieldArray(n);pr(T,C,x),pr(d.current,C,x),b(T),l(T),r._updateFieldArray(n,T,pr,{argA:C,argB:x},!1)},H=(C,x)=>{const T=ue(x),B=lt(r._getFieldArray(n),C,T);d.current=[...B].map((Q,ve)=>!Q||ve===C?pe():d.current[ve]),b(B),l([...B]),r._updateFieldArray(n,B,lt,{argA:C,argB:T},!0,!1)},U=C=>{const x=ae(ue(C));d.current=x.map(pe),b([...x]),l([...x]),r._updateFieldArray(n,[...x],T=>T,{},!0,!1)};return E.useEffect(()=>{if(r._stateFlags.action=!1,fr(n,r._names)&&r._subjects.state.next({}),w.current&&(!cr(r._options.mode).isOnSubmit||r._formState.isSubmitted))if(r._options.resolver)r._executeSchema([n]).then(C=>{const x=v(C.errors,n),T=v(r._formState.errors,n);(T?!x&&T.type:x&&x.type)&&(x?$(r._formState.errors,n,x):re(r._formState.errors,n),r._subjects.state.next({errors:r._formState.errors}))});else{const C=v(r._fields,n);C&&C._f&&gr(C,v(r._formValues,n),r._options.criteriaMode===le.all,r._options.shouldUseNativeValidation,!0).then(x=>!oe(x)&&r._subjects.state.next({errors:tt(r._formState.errors,x,n)}))}r._subjects.watch.next({name:n,values:r._formValues}),r._names.focus&&He(r._fields,C=>!!C&&C.startsWith(r._names.focus||"")),r._names.focus="",r._proxyFormState.isValid&&r._updateValid()},[u,n,r]),E.useEffect(()=>(!v(r._formValues,n)&&r._updateFieldArray(n),()=>{(r._options.shouldUnregister||a)&&r.unregister(n)}),[n,r,s,a]),{swap:E.useCallback(K,[b,n,r]),move:E.useCallback(V,[b,n,r]),prepend:E.useCallback(M,[b,n,r]),append:E.useCallback(F,[b,n,r]),remove:E.useCallback(G,[b,n,r]),insert:E.useCallback(Y,[b,n,r]),update:E.useCallback(H,[b,n,r]),replace:E.useCallback(U,[b,n,r]),fields:E.useMemo(()=>u.map((C,x)=>({...C,[s]:d.current[x]||pe()})),[u,s])}}function Ar(){let e=[];return{get observers(){return e},next:s=>{for(const a of e)a.next(s)},subscribe:s=>(e.push(s),{unsubscribe:()=>{e=e.filter(a=>a!==s)}}),unsubscribe:()=>{e=[]}}}var Ze=e=>se(e)||!Yr(e);function Fe(e,t){if(Ze(e)||Ze(t))return e===t;if(Ce(e)&&Ce(t))return e.getTime()===t.getTime();const r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(const s of r){const a=e[s];if(!n.includes(s))return!1;if(s!=="ref"){const u=t[s];if(Ce(a)&&Ce(u)||ee(a)&&ee(u)||Array.isArray(a)&&Array.isArray(u)?!Fe(a,u):a!==u)return!1}}return!0}var ct=e=>e.type==="select-multiple",os=e=>yr(e)||Me(e),Er=e=>Je(e)&&e.isConnected,ft=e=>{for(const t in e)if(Ve(e[t]))return!0;return!1};function er(e,t={}){const r=Array.isArray(e);if(ee(e)||r)for(const n in e)Array.isArray(e[n])||ee(e[n])&&!ft(e[n])?(t[n]=Array.isArray(e[n])?[]:{},er(e[n],t[n])):se(e[n])||(t[n]=!0);return t}function dt(e,t,r){const n=Array.isArray(e);if(ee(e)||n)for(const s in e)Array.isArray(e[s])||ee(e[s])&&!ft(e[s])?z(t)||Ze(r[s])?r[s]=Array.isArray(e[s])?er(e[s],[]):{...er(e[s])}:dt(e[s],se(t)?{}:t[s],r[s]):Fe(e[s],t[s])?delete r[s]:r[s]=!0;return r}var Sr=(e,t)=>dt(e,t,er(t)),yt=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:n})=>z(e)?e:t?e===""?NaN:e&&+e:r&&de(e)?new Date(e):n?n(e):e;function wr(e){const t=e.ref;if(!(e.refs?e.refs.every(r=>r.disabled):t.disabled))return dr(t)?t.files:yr(t)?at(e.refs).value:ct(t)?[...t.selectedOptions].map(({value:r})=>r):Me(t)?it(e.refs).value:yt(z(t.value)?e.ref.value:t.value,e)}var as=(e,t,r,n)=>{const s={};for(const a of e){const u=v(t,a);u&&$(s,a,u._f)}return{criteriaMode:r,names:[...e],fields:s,shouldUseNativeValidation:n}},Ue=e=>z(e)?e:Qe(e)?e.source:ee(e)?Qe(e.value)?e.value.source:e.value:e,us=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function gt(e,t,r){const n=v(e,r);if(n||ur(r))return{error:n,name:r};const s=r.split(".");for(;s.length;){const a=s.join("."),u=v(t,a),l=v(e,a);if(u&&!Array.isArray(u)&&r!==a)return{name:r};if(l&&l.type)return{name:a,error:l};s.pop()}return{name:r}}var ls=(e,t,r,n,s)=>s.isOnAll?!1:!r&&s.isOnTouch?!(t||e):(r?n.isOnBlur:s.isOnBlur)?!e:(r?n.isOnChange:s.isOnChange)?e:!0,cs=(e,t)=>!xe(v(e,t)).length&&re(e,t);const fs={mode:le.onSubmit,reValidateMode:le.onChange,shouldFocusError:!0};function ds(e={},t){let r={...fs,...e};const n=e.resetOptions&&e.resetOptions.keepDirtyValues;let s={submitCount:0,isDirty:!1,isLoading:!0,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{}},a={},u=ee(r.defaultValues)?ue(r.defaultValues)||{}:{},l=r.shouldUnregister?{}:ue(u),d={action:!1,mount:!1,watch:!1},h={mount:new Set,unMount:new Set,array:new Set,watch:new Set},_,w=0;const b={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},F={watch:Ar(),array:Ar(),state:Ar()},M=cr(r.mode),G=cr(r.reValidateMode),Y=r.criteriaMode===le.all,K=o=>c=>{clearTimeout(w),w=window.setTimeout(o,c)},V=async()=>{if(b.isValid){const o=r.resolver?oe((await Q()).errors):await D(a,!0);o!==s.isValid&&(s.isValid=o,F.state.next({isValid:o}))}},H=o=>b.isValidating&&F.state.next({isValidating:o}),U=(o,c=[],f,p,A=!0,g=!0)=>{if(p&&f){if(d.action=!0,g&&Array.isArray(v(a,o))){const S=f(v(a,o),p.argA,p.argB);A&&$(a,o,S)}if(g&&Array.isArray(v(s.errors,o))){const S=f(v(s.errors,o),p.argA,p.argB);A&&$(s.errors,o,S),cs(s.errors,o)}if(b.touchedFields&&g&&Array.isArray(v(s.touchedFields,o))){const S=f(v(s.touchedFields,o),p.argA,p.argB);A&&$(s.touchedFields,o,S)}b.dirtyFields&&(s.dirtyFields=Sr(u,l)),F.state.next({name:o,isDirty:P(o,c),dirtyFields:s.dirtyFields,errors:s.errors,isValid:s.isValid})}else $(l,o,c)},C=(o,c)=>{$(s.errors,o,c),F.state.next({errors:s.errors})},x=(o,c,f,p)=>{const A=v(a,o);if(A){const g=v(l,o,z(f)?v(u,o):f);z(g)||p&&p.defaultChecked||c?$(l,o,c?g:wr(A._f)):ie(o,g),d.mount&&V()}},T=(o,c,f,p,A)=>{let g=!1,S=!1;const J={name:o};if(!f||p){b.isDirty&&(S=s.isDirty,s.isDirty=J.isDirty=P(),g=S!==J.isDirty);const W=Fe(v(u,o),c);S=v(s.dirtyFields,o),W?re(s.dirtyFields,o):$(s.dirtyFields,o,!0),J.dirtyFields=s.dirtyFields,g=g||b.dirtyFields&&S!==!W}if(f){const W=v(s.touchedFields,o);W||($(s.touchedFields,o,f),J.touchedFields=s.touchedFields,g=g||b.touchedFields&&W!==f)}return g&&A&&F.state.next(J),g?J:{}},B=(o,c,f,p)=>{const A=v(s.errors,o),g=b.isValid&&ke(c)&&s.isValid!==c;if(e.delayError&&f?(_=K(()=>C(o,f)),_(e.delayError)):(clearTimeout(w),_=null,f?$(s.errors,o,f):re(s.errors,o)),(f?!Fe(A,f):A)||!oe(p)||g){const S={...p,...g&&ke(c)?{isValid:c}:{},errors:s.errors,name:o};s={...s,...S},F.state.next(S)}H(!1)},Q=async o=>await r.resolver(l,r.context,as(o||h.mount,a,r.criteriaMode,r.shouldUseNativeValidation)),ve=async o=>{const{errors:c}=await Q();if(o)for(const f of o){const p=v(c,f);p?$(s.errors,f,p):re(s.errors,f)}else s.errors=c;return c},D=async(o,c,f={valid:!0})=>{for(const p in o){const A=o[p];if(A){const{_f:g,...S}=A;if(g){const J=h.array.has(g.name),W=await gr(A,v(l,g.name),Y,r.shouldUseNativeValidation,J);if(W[g.name]&&(f.valid=!1,c))break;!c&&(v(W,g.name)?J?tt(s.errors,W,g.name):$(s.errors,g.name,W[g.name]):re(s.errors,g.name))}S&&await D(S,c,f)}}return f.valid},L=()=>{for(const o of h.unMount){const c=v(a,o);c&&(c._f.refs?c._f.refs.every(f=>!Er(f)):!Er(c._f.ref))&&Ee(o)}h.unMount=new Set},P=(o,c)=>(o&&c&&$(l,o,c),!Fe(Ne(),u)),q=(o,c,f)=>Zr(o,h,{...d.mount?l:z(c)?u:de(o)?{[o]:c}:c},f,c),te=o=>xe(v(d.mount?l:u,o,e.shouldUnregister?v(u,o,[]):[])),ie=(o,c,f={})=>{const p=v(a,o);let A=c;if(p){const g=p._f;g&&(!g.disabled&&$(l,o,yt(c,g)),A=Je(g.ref)&&se(c)?"":c,ct(g.ref)?[...g.ref.options].forEach(S=>S.selected=A.includes(S.value)):g.refs?Me(g.ref)?g.refs.length>1?g.refs.forEach(S=>(!S.defaultChecked||!S.disabled)&&(S.checked=Array.isArray(A)?!!A.find(J=>J===S.value):A===S.value)):g.refs[0]&&(g.refs[0].checked=!!A):g.refs.forEach(S=>S.checked=S.value===A):dr(g.ref)?g.ref.value="":(g.ref.value=A,g.ref.type||F.watch.next({name:o})))}(f.shouldDirty||f.shouldTouch)&&T(o,A,f.shouldTouch,f.shouldDirty,!0),f.shouldValidate&&De(o)},_e=(o,c,f)=>{for(const p in c){const A=c[p],g=`${o}.${p}`,S=v(a,g);(h.array.has(o)||!Ze(A)||S&&!S._f)&&!Ce(A)?_e(g,A,f):ie(g,A,f)}},ge=(o,c,f={})=>{const p=v(a,o),A=h.array.has(o),g=ue(c);$(l,o,g),A?(F.array.next({name:o,values:l}),(b.isDirty||b.dirtyFields)&&f.shouldDirty&&(s.dirtyFields=Sr(u,l),F.state.next({name:o,dirtyFields:s.dirtyFields,isDirty:P(o,g)}))):p&&!p._f&&!se(g)?_e(o,g,f):ie(o,g,f),fr(o,h)&&F.state.next({}),F.watch.next({name:o}),!d.mount&&t()},Ae=async o=>{const c=o.target;let f=c.name;const p=v(a,f),A=()=>c.type?wr(p._f):Kr(o);if(p){let g,S;const J=A(),W=o.type===Ge.BLUR||o.type===Ge.FOCUS_OUT,Ur=!us(p._f)&&!r.resolver&&!v(s.errors,f)&&!p._f.deps||ls(W,v(s.touchedFields,f),s.isSubmitted,G,M),ze=fr(f,h,W);$(l,f,J),W?(p._f.onBlur&&p._f.onBlur(o),_&&_(0)):p._f.onChange&&p._f.onChange(o);const Re=T(f,J,W,!1),ir=!oe(Re)||ze;if(!W&&F.watch.next({name:f,type:o.type}),Ur)return b.isValid&&V(),ir&&F.state.next({name:f,...ze?{}:Re});if(!W&&ze&&F.state.next({}),H(!0),r.resolver){const{errors:be}=await Q([f]),Nr=gt(s.errors,a,f),qe=gt(be,a,Nr.name||f);g=qe.error,f=qe.name,S=oe(be)}else g=(await gr(p,v(l,f),Y,r.shouldUseNativeValidation))[f],g?S=!1:b.isValid&&(S=await D(a,!0));p._f.deps&&De(p._f.deps),B(f,S,g,Re)}},De=async(o,c={})=>{let f,p;const A=ae(o);if(H(!0),r.resolver){const g=await ve(z(o)?o:A);f=oe(g),p=o?!A.some(S=>v(g,S)):f}else o?(p=(await Promise.all(A.map(async g=>{const S=v(a,g);return await D(S&&S._f?{[g]:S}:S)}))).every(Boolean),!(!p&&!s.isValid)&&V()):p=f=await D(a);return F.state.next({...!de(o)||b.isValid&&f!==s.isValid?{}:{name:o},...r.resolver||!o?{isValid:f}:{},errors:s.errors,isValidating:!1}),c.shouldFocus&&!p&&He(a,g=>g&&v(s.errors,g),o?A:h.mount),p},Ne=o=>{const c={...u,...d.mount?l:{}};return z(o)?c:de(o)?v(c,o):o.map(f=>v(c,f))},We=(o,c)=>({invalid:!!v((c||s).errors,o),isDirty:!!v((c||s).dirtyFields,o),isTouched:!!v((c||s).touchedFields,o),error:v((c||s).errors,o)}),sr=o=>{o?ae(o).forEach(c=>re(s.errors,c)):s.errors={},F.state.next({errors:s.errors})},Lr=(o,c,f)=>{const p=(v(a,o,{_f:{}})._f||{}).ref;$(s.errors,o,{...c,ref:p}),F.state.next({name:o,errors:s.errors,isValid:!1}),f&&f.shouldFocus&&p&&p.focus&&p.focus()},Ir=(o,c)=>Ve(o)?F.watch.subscribe({next:f=>o(q(void 0,c),f)}):q(o,c,!0),Ee=(o,c={})=>{for(const f of o?ae(o):h.mount)h.mount.delete(f),h.array.delete(f),v(a,f)&&(c.keepValue||(re(a,f),re(l,f)),!c.keepError&&re(s.errors,f),!c.keepDirty&&re(s.dirtyFields,f),!c.keepTouched&&re(s.touchedFields,f),!r.shouldUnregister&&!c.keepDefaultValue&&re(u,f));F.watch.next({}),F.state.next({...s,...c.keepDirty?{isDirty:P()}:{}}),!c.keepIsValid&&V()},Se=(o,c={})=>{let f=v(a,o);const p=ke(c.disabled);return $(a,o,{...f||{},_f:{...f&&f._f?f._f:{ref:{name:o}},name:o,mount:!0,...c}}),h.mount.add(o),f?p&&$(l,o,c.disabled?void 0:v(l,o,wr(f._f))):x(o,!0,c.value),{...p?{disabled:c.disabled}:{},...r.shouldUseNativeValidation?{required:!!c.required,min:Ue(c.min),max:Ue(c.max),minLength:Ue(c.minLength),maxLength:Ue(c.maxLength),pattern:Ue(c.pattern)}:{},name:o,onChange:Ae,onBlur:Ae,ref:A=>{if(A){Se(o,c),f=v(a,o);const g=z(A.value)&&A.querySelectorAll&&A.querySelectorAll("input,select,textarea")[0]||A,S=os(g),J=f._f.refs||[];if(S?J.find(W=>W===g):g===f._f.ref)return;$(a,o,{_f:{...f._f,...S?{refs:[...J.filter(Er),g,...Array.isArray(v(u,o))?[{}]:[]],ref:{type:g.type,name:o}}:{ref:g}}}),x(o,!1,void 0,g)}else f=v(a,o,{}),f._f&&(f._f.mount=!1),(r.shouldUnregister||c.shouldUnregister)&&!(Hr(h.array,o)&&d.action)&&h.unMount.add(o)}}},we=()=>r.shouldFocusError&&He(a,o=>o&&v(s.errors,o),h.mount),$e=(o,c)=>async f=>{f&&(f.preventDefault&&f.preventDefault(),f.persist&&f.persist());let p=!0,A=ue(l);F.state.next({isSubmitting:!0});try{if(r.resolver){const{errors:g,values:S}=await Q();s.errors=g,A=S}else await D(a);oe(s.errors)?(F.state.next({errors:{},isSubmitting:!0}),await o(A,f)):(c&&await c({...s.errors},f),we())}catch(g){throw p=!1,g}finally{s.isSubmitted=!0,F.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:oe(s.errors)&&p,submitCount:s.submitCount+1,errors:s.errors})}},Te=(o,c={})=>{v(a,o)&&(z(c.defaultValue)?ge(o,v(u,o)):(ge(o,c.defaultValue),$(u,o,c.defaultValue)),c.keepTouched||re(s.touchedFields,o),c.keepDirty||(re(s.dirtyFields,o),s.isDirty=c.defaultValue?P(o,v(u,o)):P()),c.keepError||(re(s.errors,o),b.isValid&&V()),F.state.next({...s}))},nr=(o,c={})=>{const f=o||u,p=ue(f),A=o&&!oe(o)?p:u;if(c.keepDefaultValues||(u=f),!c.keepValues){if(c.keepDirtyValues||n)for(const g of h.mount)v(s.dirtyFields,g)?$(A,g,v(l,g)):ge(g,v(A,g));else{if(ar&&z(o))for(const g of h.mount){const S=v(a,g);if(S&&S._f){const J=Array.isArray(S._f.refs)?S._f.refs[0]:S._f.ref;if(Je(J)){const W=J.closest("form");if(W){W.reset();break}}}}a={}}l=e.shouldUnregister?c.keepDefaultValues?ue(u):{}:p,F.array.next({values:A}),F.watch.next({values:A})}h={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!d.mount&&t(),d.mount=!b.isValid||!!c.keepIsValid,d.watch=!!e.shouldUnregister,F.state.next({submitCount:c.keepSubmitCount?s.submitCount:0,isDirty:c.keepDirty||c.keepDirtyValues?s.isDirty:!!(c.keepDefaultValues&&!Fe(o,u)),isSubmitted:c.keepIsSubmitted?s.isSubmitted:!1,dirtyFields:c.keepDirty||c.keepDirtyValues?s.dirtyFields:c.keepDefaultValues&&o?Sr(u,o):{},touchedFields:c.keepTouched?s.touchedFields:{},errors:c.keepErrors?s.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})},Be=(o,c)=>nr(Ve(o)?o(l):o,c),Mr=(o,c={})=>{const f=v(a,o),p=f&&f._f;if(p){const A=p.refs?p.refs[0]:p.ref;A.focus&&(A.focus(),c.shouldSelect&&A.select())}};return Ve(r.defaultValues)&&r.defaultValues().then(o=>{Be(o,r.resetOptions),F.state.next({isLoading:!1})}),{control:{register:Se,unregister:Ee,getFieldState:We,_executeSchema:Q,_focusError:we,_getWatch:q,_getDirty:P,_updateValid:V,_removeUnmounted:L,_updateFieldArray:U,_getFieldArray:te,_reset:nr,_subjects:F,_proxyFormState:b,get _fields(){return a},get _formValues(){return l},get _stateFlags(){return d},set _stateFlags(o){d=o},get _defaultValues(){return u},get _names(){return h},set _names(o){h=o},get _formState(){return s},set _formState(o){s=o},get _options(){return r},set _options(o){r={...r,...o}}},trigger:De,register:Se,handleSubmit:$e,watch:Ir,setValue:ge,getValues:Ne,reset:Be,resetField:Te,clearErrors:sr,unregister:Ee,setError:Lr,setFocus:Mr,getFieldState:We}}function ys(e={}){const t=E.useRef(),[r,n]=E.useState({isDirty:!1,isValidating:!1,isLoading:!0,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},defaultValues:Ve(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...ds(e,()=>n(a=>({...a}))),formState:r});const s=t.current.control;return s._options=e,Ke({subject:s._subjects.state,next:a=>{Xr(a,s._proxyFormState,!0)&&(s._formState={...s._formState,...a},n({...s._formState}))}}),E.useEffect(()=>{s._stateFlags.mount||(s._proxyFormState.isValid&&s._updateValid(),s._stateFlags.mount=!0),s._stateFlags.watch&&(s._stateFlags.watch=!1,s._subjects.state.next({})),s._removeUnmounted()}),E.useEffect(()=>{e.values&&!Fe(e.values,s._defaultValues)&&s._reset(e.values,s._options.resetOptions)},[e.values,s]),E.useEffect(()=>{r.submitCount&&s._focusError()},[s,r.submitCount]),t.current.formState=Jr(r,s),t.current}const gs=e=>{try{return typeof(e==null?void 0:e.value)=="string"?{value:new RegExp(e.value),message:e.message??"Invalid pattern"}:void 0}catch{return}},hs=(e,t={})=>{const r=gs(t.pattern);return{...t,required:{value:e,message:"field is required"},pattern:r}},ht=(e,t)=>r=>{const{key:n,isRequired:s=!1,validations:a}=r,u=hs(s,a);return fe(es,{name:n,control:e,rules:u,render:({field:l,fieldState:d})=>{const h=r.Field||t[r.type];return fe(vs,{control:e,fieldKey:r.key,children:fe(h,{fieldConfig:r,inputProps:l,fieldState:d})})}},n)},vs=({control:e,fieldKey:t,children:r})=>(E.useEffect(()=>()=>e.unregister(t),[]),r),ms=e=>typeof e=="object"&&e!==null&&e.$$typeof,Cr=e=>Object.values(e).reduce((r,n)=>(ms(n)?r.push(n):r.push(...Cr(n)),r),[]),vt=e=>{if(!e.children)throw new Error("Not children");return Object.values(e.children.fields).map(({key:r,...n})=>({...n,key:`${e.key}.${r}`}))},ps=e=>!isNaN(Number(e)),mt=e=>e.split(".").map(n=>ps(n)?"$":n),pt=e=>t=>{const[r,n]=E.useState(!1),s=()=>{t().then(a=>{n(!0),a&&Object.entries(a).forEach(([u,l])=>e(u,l))})};return E.useEffect(s,[]),r};var ye=(e=>(e.Text="text",e.Select="select",e.Radio="radio",e.Switch="switch",e.Checkbox="checkbox",e.Number="number",e.Date="date",e.Password="password",e.TextArea="text-area",e.Json="json",e.MultiText="multi-text",e.MultiSelect="multi-select",e.MultiCheckbox="multi-checkbox",e.Object="object",e.Array="array",e.Custom="custom",e))(ye||{}),xr=(e=>(e.MultiStepWizard="multi-step-wizard",e.SingleStepForm="single-step-form",e))(xr||{}),kr=(e=>(e.EQUAL="equal",e.IN="in",e))(kr||{});const _t=(e,t)=>{const{fieldsLogic:r={}}=t.logic||{},n=s=>{var u;const a=(u=r[s])==null?void 0:u.displayIf;a&&e(a.field)};Object.keys(r).forEach(s=>n(s))},Vr=e=>{const t=r=>{const n=bt(e),s=(u,l)=>{var w,b,F,M,G;const d=l?`${l}.${u.key}`:u.key,h=(F=(b=(w=r.logic)==null?void 0:w.fieldsLogic)==null?void 0:b[d])==null?void 0:F.displayIf;if(!n(h))return null;if(!u.children)return u;if(u.type===ye.Array){const Y=(G=(M=r.logic)==null?void 0:M.arrayFieldsLogic)==null?void 0:G[d],K=t({fields:u.children.fields,logic:{fieldsLogic:Y}}),V={...u.children,fields:K};return{...u,children:V}}const _={...u.children,fields:u.children.fields.map(Y=>s(Y,d)).filter(Boolean)};return{...u,children:_}};return r.fields.map(u=>s(u)).filter(Boolean)};return t},bt=e=>t=>{var h,_,w;if(!t)return!0;const{field:r,operator:n,value:s}=t,[a,u,l]=r.split(".");if(a==="$")return!0;const d=l?(_=(h=e[a])==null?void 0:h[u])==null?void 0:_[l]:u?(w=e[a])==null?void 0:w[u]:e[a];return n===kr.EQUAL?s===d:n===kr.IN&&Array.isArray(s)?s.includes(d):!1},_s=(e=[])=>e.reduce((t,r)=>(t[r]=!0,t),{}),bs="https://api.tutim.io/api/v0/pb",Fs=async e=>{try{return await e.json()}catch{return{error:{status:e.status,message:"response parse error"}}}},As=async e=>{var r;const t=await Fs(e);if(((r=t==null?void 0:t.error)==null?void 0:r.status)>300)throw new Error(t.error);return t},Es=async({clientId:e,url:t,method:r="GET"})=>{const n=await fetch(`${bs}/${e}/${t}`,{headers:{Accept:"application/json","Content-Type":"application/json"},method:r});return await As(n)},Ss=({options:e,setOptions:t})=>{const{clientId:r}=e;E.useEffect(()=>{r&&Es({clientId:r,url:"schemas"}).then(t).catch(()=>console.error("failed to fetch remote schemas"))},[r])},Or=E.createContext({}),Dr=()=>E.useContext(Or),Tr={options:{forms:{}},setOptions:()=>null},Rr=E.createContext(Tr),Ft=()=>E.useContext(Rr),ws=(e,t)=>{const r={...e.forms,...t.forms},n=t.clientId||e.clientId;return{...e,forms:r,clientId:n}},Cs=({fieldComponents:e={},options:t=Tr.options,children:r})=>{const[n,s]=E.useState(t),a=l=>s(ws(n,l)),u={options:{...Tr.options,...n},setOptions:a};return Ss(u),E.useEffect(()=>{a({clientId:t.clientId})},[t.clientId]),fe(Or.Provider,{value:e,children:fe(Rr.Provider,{value:u,children:r})})},At=e=>{const{options:t}=Ft();return typeof e=="string"?t.forms[e]||{fields:[]}:e},Et=e=>{const t=s=>({type:s.type||ye.Text,label:s.label??s.key,...s});return e.map(t).map(s=>{if(!s.children)return s;const a={...s.children,fields:s.children.fields.map(t)};return{...s,children:a}})},St=(e,t)=>{const r=t.reduce((l,d)=>(l[d.key]=d,l),{}),n=_s(e.map(l=>l.key)),s=e.map(l=>r[l.key]?{...l,...r[l.key]}:l),a=Object.values(t).filter(l=>!n[l.key]);return[...s,...a]},wt=(e,t)=>{const r=St(e,t);return Et(r)},rr=e=>e.reduce((t,{key:r,defaultValue:n,children:s,type:a})=>(a===ye.Array?t[r]=[]:a===ye.Object&&s?t[r]=rr(s.fields):t[r]=n,t),{}),Ct=e=>e.type===ye.Object,tr=({key:e,label:t,children:r,type:n})=>{if(!r||n===ye.Array)return{key:e,fields:[e]};const s=r.fields.map(l=>`${e}.${l.key}`),a=r.fields.filter(Ct).map(l=>({...l,key:`${e}.${l.key}`})),u=a.length?{groups:a.map(tr)}:void 0;return{key:e,title:t,fields:s,subGroups:u}},xs=e=>{const{groups:t=[],layout:r={}}=e,n=u=>u.map(l=>({...l,layout:l.layout||r[l.key]}));return{groups:n(t).map(u=>{var h;const l=(h=u.subGroups)==null?void 0:h.groups;if(!l)return u;const d=n(l);return{...u,subGroups:{groups:d}}})}},ks=e=>t=>{if(t.fields.find(s=>s.includes(".")))throw new Error(`Invalid group: ${t.key}, top level groups can't include object field i.e '.'`);const n=t.fields.map(s=>e.find(a=>a.key===s)).filter(Boolean);if(n.length===1)return tr(n[0]);if(n.length>1){const s=n.filter(Ct).map(tr),a=n.map(d=>d.key),u=s.length?{groups:s}:void 0;return{...t,fields:a,subGroups:u}}return t},xt=({fields:e,layout:t})=>{const{groupConfigs:r}=t||{},{groups:n=[]}=r||{},s=n.reduce((d,h)=>(h.fields.forEach(_=>d[_]=_),d),{}),a=e.filter(d=>!s[d.key]),u=n.map(ks(e)),l=a.map(tr);return[...u,...l]},Vs=({fields:e,layout:t})=>{var s;const r=xt({fields:e,layout:t});return xs({groups:r,layout:(s=t==null?void 0:t.groupConfigs)==null?void 0:s.layout})},Pr=e=>{const t=Vs(e);return{...e.layout,groupConfigs:t}},kt=e=>{const[t,r]=e.split(".");if(t==="$"&&r)return r},Os=e=>e?Object.values(e).reduce((r,{displayIf:n}={})=>{if(!n)return r;const s=kt(n.field);return s&&r.push(s),r},[]):[],Ds=e=>e?Object.entries(e).reduce((r,[n,s])=>{if(!(s!=null&&s.displayIf))return r;const a=kt(s.displayIf.field);if(a){const u={...s,displayIf:{...s.displayIf,field:a}};r[n]=u}return r},{}):{},Ts=(e,t,r)=>{if(!e.children)return{fields:[]};const n=Ds(r);return{fields:Vr(t)({fields:e.children.fields,logic:{fieldsLogic:n}})}},Rs=(e,t)=>Os(t).length?[e.key]:[],Vt=({parentConfig:e,control:t,configsToMap:r,layoutConfig:n,logic:s={}})=>{if(!e.children)throw new Error("Only supports multi object fields");const{fields:a,append:u,remove:l}=is({control:t,name:e.key}),{error:d}=t.getFieldState(e.key),h=Rs(e,s),[_]=et({control:t,name:h,defaultValue:[{}]}),w=Pr({layout:n,fields:e.children.fields}),b=()=>{if(!e.children)return;const G=rr(e.children.fields);return u(G)},F=G=>()=>l(G),M=a.map((G,Y)=>{if(!e.children)return;const V=Ts(e,(_==null?void 0:_[Y])||{},s).fields.map(U=>({...U,key:`${e.key}.${Y}.${U.key}`})),H=r(V);return{id:G.id,fieldsByKey:H,onDelete:F(Y)}});return{onAdd:b,arrayFields:M,layout:w,error:d}},Ot=e=>fe(Dt,{...e},e.parentConfig.key),Dt=({parentConfig:e,control:t,configsToMap:r,layoutConfig:n,UiFieldArray:s,logic:a})=>{const u=Vt({parentConfig:e,control:t,configsToMap:r,layoutConfig:n,logic:a});return fe(s,{multiProps:u,fieldConfig:e},e.key)},Tt=e=>e.reduce((r,n)=>{if(n.type===ye.Object){const s=vt(n),a=Tt(s);r.push(...a)}else r.push(n);return r},[]),Rt=(e,t,r)=>{const n=Dr(),s=ht(e,n);if(!s)throw new Error("fieldComponents is required, use `<TutimProvider fieldComponents={...}`");const a=h=>Tt(h).reduce((w,b)=>(w[b.key]=u(b),w),{}),u=h=>{var _,w,b,F;if(h.type===ye.Array){const M=n[ye.Array]||h.Field,G=mt(h.key).join("."),Y=(w=(_=t.layout)==null?void 0:_.arrayConfigs)==null?void 0:w[G],K=(F=(b=t.logic)==null?void 0:b.arrayFieldsLogic)==null?void 0:F[G];return Ot({parentConfig:h,configsToMap:a,control:e,layoutConfig:Y,logic:K,UiFieldArray:M})}return s(h)},l=Vr(r)(t);return a(l)},Pt=(e,t)=>{try{const r=wt(e.fields,[]),n={...e,fields:r},s=rr(r),{control:a,setValue:u,watch:l,getValues:d,handleSubmit:h,..._}=ys({...t,defaultValues:s});_t(l,n);const w=E.useMemo(()=>pt(u),[u]),b=V=>h(H=>V({data:H,schema:n})),F=Rt(a,n,d()),M=Cr(F),G=Pr(n),Y=n.logic||{},K=n.meta||{};return{..._,control:a,setValue:u,watch:l,getValues:d,handleSubmit:h,fields:M,fieldsByKey:F,layout:G,logic:Y,meta:K,schema:n,useFormInit:w,nativeSubmit:b}}catch(r){return console.error(r),{error:r}}},Ps={config:{fields:[]},activeStep:0,goToStep:()=>null,wizardValues:{},setWizardValues:()=>null,onStepSubmit:()=>null},jr=E.createContext(Ps),jt=()=>E.useContext(jr),Lt=({initialValues:e={},onSubmit:t,config:r,wizardContext:n=void 0})=>{var w,b;if(n)return n;const[s,a]=E.useState(0),[u,l]=E.useState(e),d=((b=(w=r.wizard)==null?void 0:w.steps)==null?void 0:b.length)||0;return{config:r,stepCount:d,activeStep:s,wizardValues:u,goToStep:F=>{if(F<0||F>d)return;d===F||a(F)},setWizardValues:l,onStepSubmit:(F,M=!1)=>{l(G=>{var K,V;const Y={...G,...F};if(M){const H=(V=(K=r.logic)==null?void 0:K.webhook)==null?void 0:V.endpoint,U={data:Y,schema:r};t(U),H&&Ls(H,U)}return Y})}}},js=({children:e,...t})=>{const r=Lt(t.wizardContext?{wizardContext:t.wizardContext}:t);return fe(jr.Provider,{value:r,children:e})},Ls=async(e,t)=>await fetch(e,{headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST",body:JSON.stringify(t)}),It=(e,t)=>{const{wizard:r}=e,{steps:n}=r||{};return n?n[t].fields.map(u=>e.fields.find(l=>l.key===u)).filter(Boolean):[]},Is=(e,t,r)=>It(e,t).reduce((a,u)=>{const{key:l}=u,d=r[l];return{...a,[l]:d}},{}),Ms={submit:{display:!1}},Us={title:void 0},Ns=()=>{var F;const{config:e,activeStep:t,wizardValues:r,goToStep:n,onStepSubmit:s}=jt(),a=It(e,t),u=Is(e,t,r),l={...e,fields:a,layout:{...e.layout,...Ms},meta:{...e.meta,...Us}},d=Pt(l);E.useEffect(()=>{d.reset(u)},[t]);const h=t+1===((F=e==null?void 0:e.wizard)==null?void 0:F.steps.length);return{form:d,goBack:()=>{d.formState.isValid&&s(d.getValues(),!1),n(t-1)},goNext:()=>{d.formState.isValid&&s(d.getValues(),h),n(t+1)},isLastStep:h,isFirstStep:t===0}},Ws=({formId:e,config:t,onSubmit:r,initialValues:n,wizardContext:s})=>{var h,_;const a=At(t||e||""),u=(_=(h=a.wizard)==null?void 0:h.steps)==null?void 0:_.length;if(!a.fields.length)return fe("p",{children:"No Fields"});const l=Dr(),d=u?l[xr.MultiStepWizard]:l[xr.SingleStepForm];return u?fe(d,{onSubmit:r,config:a,initialValues:n,wizardContext:s}):fe(d,{onSubmit:r,formId:e,config:a,initialValues:n})},$s