@saas-ui/forms 0.5.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +13 -0
- package/dist/array-field.d.ts +3 -3
- package/dist/array-field.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/step-form.d.ts +1 -1
- package/dist/step-form.d.ts.map +1 -1
- package/dist/use-array-field.d.ts +1 -1
- package/package.json +2 -1
- package/src/array-field.tsx +56 -45
- package/src/form.tsx +1 -1
- package/src/step-form.tsx +2 -1
- package/src/use-array-field.tsx +1 -1
- package/src/use-step-form.tsx +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# @saas-ui/forms
|
2
2
|
|
3
|
+
## 0.5.2
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 0f67f76: Fixed circular dependency
|
8
|
+
|
9
|
+
## 0.5.1
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- c610881: Fixed a type error
|
14
|
+
- a26aa7c: ArrayField context can now be accessed using ref.
|
15
|
+
|
3
16
|
## 0.5.0
|
4
17
|
|
5
18
|
### Minor Changes
|
package/dist/array-field.d.ts
CHANGED
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
2
2
|
import { ResponsiveValue } from '@chakra-ui/system';
|
3
3
|
import { ButtonProps } from '@saas-ui/button';
|
4
4
|
import { FieldProps } from './field';
|
5
|
-
import { ArrayFieldOptions } from './use-array-field';
|
5
|
+
import { ArrayFieldOptions, UseArrayFieldReturn } from './use-array-field';
|
6
6
|
interface ArrayField {
|
7
7
|
id: string;
|
8
8
|
[key: string]: unknown;
|
@@ -38,11 +38,11 @@ export declare const ArrayFieldRemoveButton: React.FC<ButtonProps>;
|
|
38
38
|
export declare const ArrayFieldAddButton: React.FC<ButtonProps>;
|
39
39
|
export interface ArrayFieldProps extends ArrayFieldOptions, Omit<FieldProps, 'defaultValue'> {
|
40
40
|
}
|
41
|
-
export declare const ArrayField: React.
|
41
|
+
export declare const ArrayField: React.ForwardRefExoticComponent<ArrayFieldProps & React.RefAttributes<UseArrayFieldReturn>>;
|
42
42
|
export interface ArrayFieldRowsProps {
|
43
43
|
children: (fields: ArrayField[]) => React.ReactElement | null;
|
44
44
|
}
|
45
45
|
export declare const ArrayFieldRows: ({ children, }: ArrayFieldRowsProps) => React.ReactElement | null;
|
46
|
-
export declare const ArrayFieldContainer: React.
|
46
|
+
export declare const ArrayFieldContainer: React.ForwardRefExoticComponent<ArrayFieldProps & React.RefAttributes<UseArrayFieldReturn>>;
|
47
47
|
export {};
|
48
48
|
//# sourceMappingURL=array-field.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"array-field.d.ts","sourceRoot":"","sources":["../src/array-field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAG3D,OAAO,EAAc,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAGzD,OAAO,EAAa,UAAU,EAAE,MAAM,SAAS,CAAA;AAI/C,OAAO,EAKL,iBAAiB,
|
1
|
+
{"version":3,"file":"array-field.d.ts","sourceRoot":"","sources":["../src/array-field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAG3D,OAAO,EAAc,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAGzD,OAAO,EAAa,UAAU,EAAE,MAAM,SAAS,CAAA;AAI/C,OAAO,EAKL,iBAAiB,EAKjB,mBAAmB,EACpB,MAAM,mBAAmB,CAAA;AAE1B,UAAU,UAAU;IAClB,EAAE,EAAE,MAAM,CAAA;IACV,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,UAAU,kBAAkB;IAC1B;;OAEG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAA;IACjC;;OAEG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;IAC1C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CActD,CAAA;AAED,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAA;IACjC;;OAEG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;CAC3C;AAED,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CAkBlE,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAmB/D,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CASxD,CAAA;AAED,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAUrD,CAAA;AAED,MAAM,WAAW,eACf,SAAQ,iBAAiB,EACvB,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC;CAAG;AAEvC,eAAO,MAAM,UAAU,6FAqBtB,CAAA;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;CAC9D;AAED,eAAO,MAAM,cAAc,kBAExB,mBAAmB,KAAG,MAAM,YAAY,GAAG,IAG7C,CAAA;AAED,eAAO,MAAM,mBAAmB,6FAgC/B,CAAA"}
|
package/dist/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
var e=require("react"),t=require("react-hook-form"),r=require("@chakra-ui/react"),n=require("@saas-ui/number-input"),a=require("@saas-ui/password-input"),o=require("@saas-ui/radio"),i=require("@saas-ui/pin-input"),l=require("@saas-ui/select"),u=require("yup"),s=require("@hookform/resolvers/yup"),c=require("@chakra-ui/system"),p=require("@chakra-ui/icons"),f=require("@saas-ui/button"),d=require("@chakra-ui/react-utils"),m=require("@saas-ui/react-utils"),v=require("@saas-ui/input-right-button");function h(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var y=/*#__PURE__*/h(e);function b(){return b=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},b.apply(this,arguments)}function _(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(a[r]=e[r]);return a}function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var g=["name","label","placeholder"],E=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null},S=["name","label","help","variant","hideLabel","children"],F=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],C=["name","rules"],j=["ref"],w=["name","rules"],A=["ref"],O=["label"],N=["label"],k={},I=function(e){var n=e.name,a=e.label,o=e.help,i=e.variant,l=e.hideLabel,u=e.children,s=_(e,S),c=function(e,r){return t.get(r.errors,e)}(n,t.useFormContext().formState);/*#__PURE__*/return y.createElement(r.FormControl,b({variant:i},s,{isInvalid:!!c}),a&&!l?/*#__PURE__*/y.createElement(r.FormLabel,{variant:i},a):null,/*#__PURE__*/y.createElement(r.Box,null,u,!o||null!=c&&c.message?null:/*#__PURE__*/y.createElement(r.FormHelperText,null,o),(null==c?void 0:c.message)&&/*#__PURE__*/y.createElement(r.FormErrorMessage,null,null==c?void 0:c.message)))},R=r.forwardRef(function(e,t){var r=e.type;/*#__PURE__*/return y.createElement(k[void 0===r?"text":r]||k.text,b({ref:t},e))}),P=function(e){return r.forwardRef(function(n,a){var o=n.name,i=n.rules,l=_(n,C),u=t.useFormContext();/*#__PURE__*/return y.createElement(t.Controller,{name:o,control:u.control,rules:i,render:function(t){var n=t.field,o=n.ref,i=_(n,j);/*#__PURE__*/return y.createElement(e,b({},i,l,{ref:r.useMergeRefs(a,o)}))}})})},L=function(e){return r.forwardRef(function(n,a){var o=n.name,i=n.rules,l=_(n,w),u=(0,t.useFormContext().register)(o,i),s=u.ref,c=_(u,A);/*#__PURE__*/return y.createElement(e,b({},c,l,{ref:r.useMergeRefs(a,s)}))})},V=function(e,t,n){var a=function(e,t){var n=t.displayName,a=t.hideLabel,o=t.BaseField,i=r.forwardRef(function(t,r){var n=t.name,i=t.label,l=t.help,u=t.isDisabled,s=t.isInvalid,c=t.isReadOnly,p=t.isRequired,f=t.rules,d=t.variant,m=_(t,F),v=b({required:p},f);/*#__PURE__*/return y.createElement(o,{name:n,label:i,help:l,hideLabel:a,isDisabled:u,isInvalid:s,isReadOnly:c,isRequired:p,variant:d},/*#__PURE__*/y.createElement(e,b({ref:r,name:n,label:i,rules:v},m)))});return i.displayName=n,i}(null!=n&&n.isControlled?P(t):L(t),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==n?void 0:n.hideLabel,BaseField:(null==n?void 0:n.BaseField)||I});return k[e]=a,a},B=V("text",r.Input),z=V("number",n.NumberInput,{isControlled:!0}),D=V("password",a.PasswordInput),q=V("textarea",r.Textarea),T=V("switch",r.forwardRef(function(e,t){var n=e.label,a=_(e,O);/*#__PURE__*/return y.createElement(r.Switch,b({ref:t},a),n)}),{isControlled:!0,hideLabel:!0}),M=V("select",l.Select,{isControlled:!0}),U=V("checkbox",r.forwardRef(function(e,t){var n=e.label,a=_(e,N);/*#__PURE__*/return y.createElement(r.Checkbox,b({ref:t},a),n)}),{hideLabel:!0}),$=V("radio",o.RadioInput,{isControlled:!0}),G=V("pin",i.PinInput,{isControlled:!0}),W=V("native-select",l.NativeSelect,{isControlled:!0}),H=function(e){var t;if(null!=(t=e.spec.meta)&&t.type)return e.spec.meta.type;switch(e.type){case"array":return"array";case"object":return"object";case"number":return"number";case"date":return"date";default:return"text"}},J=function(e,t){for(var r,n=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return x(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?x(e,t):void 0}}(e))){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e.tests);!(r=n()).done;){var a,o=r.value;if(null!=(a=o.OPTIONS)&&a.params[t])return o.OPTIONS.params[t]}},K=function(e){var t,r=[];for(var n in t="array"===e.type?e.innerType.fields:e.fields){var a=t[n],o={};"array"===a.type&&(o.min=J(a,"min"),o.max=J(a,"max")),r.push(b({name:n,label:a.spec.label||n,type:H(a)},o))}return r},Q=["children"],X=function(e){/*#__PURE__*/return y.createElement(r.chakra.div,null,e.children)},Y=function(e){var t,n,a,o=e.children,i=_(e,Q),l=b({},null!=(t=null==(n=r.useTheme().components)||null==(a=n.FormLayout)?void 0:a.defaultProps)?t:{spacing:4},i);/*#__PURE__*/return y.createElement(r.SimpleGrid,l,y.Children.map(o,function(e){return y.isValidElement(e)?/*#__PURE__*/y.createElement(X,null,e):e}))},Z=function(e,t){return y.Children.map(t,function(t){return y.isValidElement(t)&&t.props.name?y.cloneElement(t,b({},t.props,{name:e+"."+t.props.name})):t})},ee=d.createContext({name:"ArrayFieldContext"}),te=ee[0],re=ee[1],ne=d.createContext({name:"ArrayFieldRowContext"}),ae=ne[0],oe=ne[1],ie=function(e){var r=e.name,n=e.defaultValue,a=void 0===n?{}:n,o=e.keyName,i=e.min,l=e.max,u=t.useFormContext();return b({},t.useFieldArray({control:u.control,name:r,keyName:o}),{name:r,defaultValue:a,min:i,max:l})},le=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=re(),o=a.name,i=a.remove,l=a.fields;return y.useEffect(function(){n(o)},[]),{index:r,isFirst:0===r,isLast:r===l.length-1,name:o+"."+r,remove:y.useCallback(function(){n(o),i(r)},[r])}},ue=function(){var e=oe(),t=e.isFirst,r=e.remove,n=re(),a=n.min;return{onClick:function(){return r()},isDisabled:t&&!!(a&&n.fields.length<=a)}},se=function(){var e=re(),t=e.append,r=e.defaultValue,n=e.max;return{onClick:function(){return t(r,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},ce=["children","columns","spacing"],pe=["children"],fe=["name","defaultValue","keyName","min","max","children"],de=function(e){/*#__PURE__*/return y.createElement(ve,{index:e.index},/*#__PURE__*/y.createElement(me,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/y.createElement(he,null))},me=function(e){var t=e.children,r=e.columns,n=e.spacing,a=_(e,ce),o=oe().name;/*#__PURE__*/return y.createElement(Y,b({flex:"1",columns:r,gridGap:n,mr:"2"},a),Z(o,t))},ve=function(e){var t=e.children,r=le({index:e.index});/*#__PURE__*/return y.createElement(ae,{value:r},/*#__PURE__*/y.createElement(c.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))},he=function(e){/*#__PURE__*/return y.createElement(f.IconButton,b({icon:/*#__PURE__*/y.createElement(p.MinusIcon,null),"aria-label":"Remove row"},ue(),e))},ye=function(e){/*#__PURE__*/return y.createElement(f.IconButton,b({icon:/*#__PURE__*/y.createElement(p.AddIcon,null),"aria-label":"Add row",float:"right"},se(),e))},be=function(e){var t=e.children,r=_(e,pe);/*#__PURE__*/return y.createElement(xe,r,/*#__PURE__*/y.createElement(_e,null,function(e){/*#__PURE__*/return y.createElement(y.Fragment,null,e.map(function(e,r){/*#__PURE__*/return y.createElement(de,{key:e.id,index:r},t)}))}),/*#__PURE__*/y.createElement(ye,null))},_e=function(e){return(0,e.children)(re().fields)},xe=function(e){var t=e.name,r=e.defaultValue,n=e.keyName,a=e.min,o=e.max,i=e.children,l=_(e,fe),u=ie({name:t,defaultValue:r,keyName:n,min:a,max:o});/*#__PURE__*/return y.createElement(te,{value:u},/*#__PURE__*/y.createElement(I,b({name:t},l),i))},ge=["name","label","hideLabel","children","columns","spacing"],Ee=function(e){var t=r.useStyles();/*#__PURE__*/return y.createElement(r.FormLabel,b({as:"legend",sx:t.legend},e))},Se=function(e){var t=e.name,n=e.label,a=e.hideLabel,o=e.children,i=e.columns,l=e.spacing,u=_(e,ge);/*#__PURE__*/return y.createElement(r.FormControl,b({name:t,as:"fieldset"},u),/*#__PURE__*/y.createElement(Ee,{display:a?"none":"block"},n),/*#__PURE__*/y.createElement(Y,{columns:i,gridGap:l},Z(t,o)))},Fe=["name","type"],Ce=["schema"],je=["name","type","defaultValue"],we=function(e,t){return K(function(e,t){return u.reach(e,t)}(e,t)).map(function(e){var t=e.name,r=e.type,n=_(e,Fe);/*#__PURE__*/return y.createElement(R,b({key:t,name:t,type:r},n))})},Ae=function(e){var t=e.schema,r=_(e,Ce);/*#__PURE__*/return y.createElement(Y,r,K(t).map(function(e){var r=e.name,n=e.type,a=_(e,je);return"array"===n?/*#__PURE__*/y.createElement(be,b({name:r},a),we(t,r)):"object"===n?/*#__PURE__*/y.createElement(Se,b({name:r},a),we(t,r)):/*#__PURE__*/y.createElement(R,b({key:r,name:r,type:n},a))}))},Oe=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Ne=r.forwardRef(function(e,n){var a=e.mode,o=void 0===a?"all":a,i=e.resolver,l=e.reValidateMode,u=e.shouldFocusError,c=e.shouldUnregister,p=e.shouldUseNativeValidation,f=e.criteriaMode,d=e.delayError,m=e.schema,v=e.defaultValues,h=e.onSubmit,x=e.onError,g=e.formRef,E=e.children,S=_(e,Oe),F={mode:o,resolver:i,defaultValues:v,reValidateMode:l,shouldFocusError:u,shouldUnregister:c,shouldUseNativeValidation:p,criteriaMode:f,delayError:d};m&&(F.resolver=s.yupResolver(m));var C=t.useForm(F),j=C.handleSubmit;return y.useImperativeHandle(n,function(){return C},[n,C]),/*#__PURE__*/y.createElement(t.FormProvider,C,/*#__PURE__*/y.createElement(r.chakra.form,b({ref:g,onSubmit:j(h,x)},S),E))}),ke=["children","disableIfUntouched","disableIfInvalid"],Ie=c.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,o=e.disableIfInvalid,i=_(e,ke),l=t.useFormContext().formState;/*#__PURE__*/return y.createElement(f.Button,b({type:"submit",isLoading:l.isSubmitting,isPrimary:!0,ref:r,isDisabled:a&&!l.isDirty||o&&!l.isValid},i),n)});Ie.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};var Re,Pe,Le=["schema","submitLabel"],Ve=r.forwardRef(function(e,t){var r=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,o=_(e,Le);/*#__PURE__*/return y.createElement(Ne,b({},o,{schema:r,ref:t}),/*#__PURE__*/y.createElement(Y,null,/*#__PURE__*/y.createElement(Ae,{schema:r}),a&&/*#__PURE__*/y.createElement(Ie,{label:a})))}),Be="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ze(e){return"function"==typeof e}Re=function(e,t){var r="__lodash_hash_undefined__",n=9007199254740991,a="[object Arguments]",o="[object Function]",i="[object Object]",l=/^\[object .+?Constructor\]$/,u=/^(?:0|[1-9]\d*)$/,s={};s["[object Float32Array]"]=s["[object Float64Array]"]=s["[object Int8Array]"]=s["[object Int16Array]"]=s["[object Int32Array]"]=s["[object Uint8Array]"]=s["[object Uint8ClampedArray]"]=s["[object Uint16Array]"]=s["[object Uint32Array]"]=!0,s[a]=s["[object Array]"]=s["[object ArrayBuffer]"]=s["[object Boolean]"]=s["[object DataView]"]=s["[object Date]"]=s["[object Error]"]=s[o]=s["[object Map]"]=s["[object Number]"]=s[i]=s["[object RegExp]"]=s["[object Set]"]=s["[object String]"]=s["[object WeakMap]"]=!1;var c="object"==typeof Be&&Be&&Be.Object===Object&&Be,p="object"==typeof self&&self&&self.Object===Object&&self,f=c||p||Function("return this")(),d=t&&!t.nodeType&&t,m=d&&e&&!e.nodeType&&e,v=m&&m.exports===d,h=v&&c.process,y=function(){try{return m&&m.require&&m.require("util").types||h&&h.binding&&h.binding("util")}catch(e){}}(),b=y&&y.isTypedArray;function _(e,t,r){switch(r.length){case 0:return e.call(t);case 1:return e.call(t,r[0]);case 2:return e.call(t,r[0],r[1]);case 3:return e.call(t,r[0],r[1],r[2])}return e.apply(t,r)}var x,g,E,S=Array.prototype,F=Object.prototype,C=f["__core-js_shared__"],j=Function.prototype.toString,w=F.hasOwnProperty,A=(x=/[^.]+$/.exec(C&&C.keys&&C.keys.IE_PROTO||""))?"Symbol(src)_1."+x:"",O=F.toString,N=j.call(Object),k=RegExp("^"+j.call(w).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),I=v?f.Buffer:void 0,R=f.Symbol,P=f.Uint8Array,L=(g=Object.getPrototypeOf,E=Object,function(e){return g(E(e))}),V=Object.create,B=F.propertyIsEnumerable,z=S.splice,D=R?R.toStringTag:void 0,q=function(){try{var e=ie(Object,"defineProperty");return e({},"",{}),e}catch(e){}}(),T=I?I.isBuffer:void 0,M=Math.max,U=Date.now,$=ie(f,"Map"),G=ie(Object,"create"),W=function(){function e(){}return function(t){if(!be(t))return{};if(V)return V(t);e.prototype=t;var r=new e;return e.prototype=void 0,r}}();function H(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function J(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function K(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function Q(e){var t=this.__data__=new J(e);this.size=t.size}function X(e,t,r){(void 0!==r&&!pe(e[t],r)||void 0===r&&!(t in e))&&ee(e,t,r)}function Y(e,t,r){var n=e[t];w.call(e,t)&&pe(n,r)&&(void 0!==r||t in e)||ee(e,t,r)}function Z(e,t){for(var r=e.length;r--;)if(pe(e[r][0],t))return r;return-1}function ee(e,t,r){"__proto__"==t&&q?q(e,t,{configurable:!0,enumerable:!0,value:r,writable:!0}):e[t]=r}function te(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":D&&D in Object(e)?function(e){var t=w.call(e,D),r=e[D];try{e[D]=void 0;var n=!0}catch(e){}var a=O.call(e);return n&&(t?e[D]=r:delete e[D]),a}(e):function(e){return O.call(e)}(e)}function re(e){return _e(e)&&te(e)==a}function ne(e,t,r,n,a){e!==t&&function(e,t,r){for(var n=-1,a=Object(e),o=r(e),i=o.length;i--;){var l=o[++n];if(!1===t(a[l],l))break}}(t,function(o,l){if(a||(a=new Q),be(o))!function(e,t,r,n,a,o,l){var u=se(e,r),s=se(t,r),c=l.get(s);if(c)X(e,r,c);else{var p,f,d,m,v=o?o(u,s,r+"",e,t,l):void 0,h=void 0===v;if(h){var y=de(s),b=!y&&ve(s),_=!y&&!b&&xe(s);v=s,y||b||_?de(u)?v=u:_e(m=u)&&me(m)?v=function(e,t){var r=-1,n=e.length;for(t||(t=Array(n));++r<n;)t[r]=e[r];return t}(u):b?(h=!1,v=s.slice()):_?(h=!1,d=new(f=(p=s).buffer).constructor(f.byteLength),new P(d).set(new P(f)),v=new p.constructor(d,p.byteOffset,p.length)):v=[]:function(e){if(!_e(e)||te(e)!=i)return!1;var t=L(e);if(null===t)return!0;var r=w.call(t,"constructor")&&t.constructor;return"function"==typeof r&&r instanceof r&&j.call(r)==N}(s)||fe(s)?(v=u,fe(u)?v=function(e){return function(e,t,r,n){var a=!r;r||(r={});for(var o=-1,i=t.length;++o<i;){var l=t[o],u=void 0;void 0===u&&(u=e[l]),a?ee(r,l,u):Y(r,l,u)}return r}(e,ge(e))}(u):be(u)&&!he(u)||(v=function(e){return"function"!=typeof e.constructor||ue(e)?{}:W(L(e))}(s))):h=!1}h&&(l.set(s,v),a(v,s,n,o,l),l.delete(s)),X(e,r,v)}}(e,t,l,r,ne,n,a);else{var u=n?n(se(e,l),o,l+"",e,t,a):void 0;void 0===u&&(u=o),X(e,l,u)}},ge)}H.prototype.clear=function(){this.__data__=G?G(null):{},this.size=0},H.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},H.prototype.get=function(e){var t=this.__data__;if(G){var n=t[e];return n===r?void 0:n}return w.call(t,e)?t[e]:void 0},H.prototype.has=function(e){var t=this.__data__;return G?void 0!==t[e]:w.call(t,e)},H.prototype.set=function(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=G&&void 0===t?r:t,this},J.prototype.clear=function(){this.__data__=[],this.size=0},J.prototype.delete=function(e){var t=this.__data__,r=Z(t,e);return!(r<0||(r==t.length-1?t.pop():z.call(t,r,1),--this.size,0))},J.prototype.get=function(e){var t=this.__data__,r=Z(t,e);return r<0?void 0:t[r][1]},J.prototype.has=function(e){return Z(this.__data__,e)>-1},J.prototype.set=function(e,t){var r=this.__data__,n=Z(r,e);return n<0?(++this.size,r.push([e,t])):r[n][1]=t,this},K.prototype.clear=function(){this.size=0,this.__data__={hash:new H,map:new($||J),string:new H}},K.prototype.delete=function(e){var t=oe(this,e).delete(e);return this.size-=t?1:0,t},K.prototype.get=function(e){return oe(this,e).get(e)},K.prototype.has=function(e){return oe(this,e).has(e)},K.prototype.set=function(e,t){var r=oe(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this},Q.prototype.clear=function(){this.__data__=new J,this.size=0},Q.prototype.delete=function(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r},Q.prototype.get=function(e){return this.__data__.get(e)},Q.prototype.has=function(e){return this.__data__.has(e)},Q.prototype.set=function(e,t){var r=this.__data__;if(r instanceof J){var n=r.__data__;if(!$||n.length<199)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new K(n)}return r.set(e,t),this.size=r.size,this};var ae=q?function(e,t){return q(e,"toString",{configurable:!0,enumerable:!1,value:(r=t,function(){return r}),writable:!0});var r}:Fe;function oe(e,t){var r,n,a=e.__data__;return("string"==(n=typeof(r=t))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?a["string"==typeof t?"string":"hash"]:a.map}function ie(e,t){var r=function(e,t){return null==e?void 0:e[t]}(e,t);return function(e){return!(!be(e)||function(e){return!!A&&A in e}(e))&&(he(e)?k:l).test(function(e){if(null!=e){try{return j.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}(r)?r:void 0}function le(e,t){var r=typeof e;return!!(t=null==t?n:t)&&("number"==r||"symbol"!=r&&u.test(e))&&e>-1&&e%1==0&&e<t}function ue(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||F)}function se(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]}var ce=function(e){var t=0,r=0;return function(){var n=U(),a=16-(n-r);if(r=n,a>0){if(++t>=800)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}(ae);function pe(e,t){return e===t||e!=e&&t!=t}var fe=re(function(){return arguments}())?re:function(e){return _e(e)&&w.call(e,"callee")&&!B.call(e,"callee")},de=Array.isArray;function me(e){return null!=e&&ye(e.length)&&!he(e)}var ve=T||function(){return!1};function he(e){if(!be(e))return!1;var t=te(e);return t==o||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t}function ye(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=n}function be(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function _e(e){return null!=e&&"object"==typeof e}var xe=b?function(e){return function(t){return e(t)}}(b):function(e){return _e(e)&&ye(e.length)&&!!s[te(e)]};function ge(e){return me(e)?function(e,t){var r=de(e),n=!r&&fe(e),a=!r&&!n&&ve(e),o=!r&&!n&&!a&&xe(e),i=r||n||a||o,l=i?function(e,t){for(var r=-1,n=Array(e);++r<e;)n[r]=t(r);return n}(e.length,String):[],u=l.length;for(var s in e)i&&("length"==s||a&&("offset"==s||"parent"==s)||o&&("buffer"==s||"byteLength"==s||"byteOffset"==s)||le(s,u))||l.push(s);return l}(e):function(e){if(!be(e))return function(e){var t=[];if(null!=e)for(var r in Object(e))t.push(r);return t}(e);var t=ue(e),r=[];for(var n in e)("constructor"!=n||!t&&w.call(e,n))&&r.push(n);return r}(e)}var Ee,Se=(Ee=function(e,t,r,n){ne(e,t,r,n)},function(e,t){return ce(function(e,t,r){return t=M(void 0===t?e.length-1:t,0),function(){for(var n=arguments,a=-1,o=M(n.length-t,0),i=Array(o);++a<o;)i[a]=n[t+a];a=-1;for(var l=Array(t+1);++a<t;)l[a]=n[a];return l[t]=r(i),_(e,this,l)}}(e,void 0,Fe),e+"")}(function(e,t){var r=-1,n=t.length,a=n>1?t[n-1]:void 0,o=n>2?t[2]:void 0;for(a=Ee.length>3&&"function"==typeof a?(n--,a):void 0,o&&function(e,t,r){if(!be(r))return!1;var n=typeof t;return!!("number"==n?me(r)&&le(t,r.length):"string"==n&&t in r)&&pe(r[t],e)}(t[0],t[1],o)&&(a=n<3?void 0:a,n=1),e=Object(e);++r<n;){var i=t[r];i&&Ee(e,i,r,a)}return e}));function Fe(e){return e}e.exports=Se},Re(Pe={exports:{}},Pe.exports);var De="production"!==process.env.NODE_ENV;process;var qe=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.filter(Boolean).join(" ")};function Te(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(e){t.some(function(t){return null==t||t(e),null==e?void 0:e.defaultPrevented})}}Object.freeze(["base","sm","md","lg","xl","2xl"]);var Me="production"!==process.env.NODE_ENV;process;var Ue=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.filter(Boolean).join(" ")};function $e(){return $e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},$e.apply(this,arguments)}function Ge(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(a[r]=e[r]);return a}Object.freeze(["base","sm","md","lg","xl","2xl"]);var We=d.createContext({name:"StepperContext",errorMessage:"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`"}),He=We[0],Je=We[1];function Ke(e){var t=e.step,r=y.useState(-1),n=r[0],a=r[1],o=y.useRef([]),i=y.useState(Date.now())[1],l=y.useCallback(function(e){var t=[].concat(o.current);-1===t.indexOf(e)&&t.push(e),o.current=t,i(Date.now())},[o,i]),u=function(e){var t=o.current.indexOf(e);-1!==t&&a(t)};return y.useLayoutEffect(function(){"string"==typeof t?u(t):"number"==typeof t?a(t):-1===n&&a(0)},[t]),{stepsRef:o,activeStep:o.current[n],activeIndex:n,isFirstStep:0===n,isLastStep:n===o.current.length-1,isCompleted:n>=o.current.length,setIndex:a,setStep:u,nextStep:function(){a(n+1)},prevStep:function(){a(n-1)},registerStep:l,unregisterStep:function(e){o.current=o.current.slice(o.current.indexOf(e),1)}}}function Qe(e){var t=e.name,r=e.isActive,n=e.isCompleted,a=Je(),o=a.registerStep,i=a.unregisterStep,l=a.activeStep;return y.useEffect(function(){if(t)return o(t),function(){i(t)}},[]),{isActive:t?l===t:r,isCompleted:n}}var Xe=["children","orientation"],Ye=["children","orientation","stepComponent"],Ze=["children","isOpen"],et=["icon","isActive","isCompleted","className"],tt=["title","icon","isActive","isCompleted"],rt=["isActive"],nt=c.forwardRef(function(e,t){var r=c.useMultiStyleConfig("Stepper",e),n=c.omitThemingProps(e),a=n.children,o=n.orientation,i=Ge(n,Xe),l=Ke(e),u=$e({display:"flex",flexDirection:"column"},r.container);return y.createElement(c.StylesProvider,{value:r},/*#__PURE__*/y.createElement(He,{value:l},/*#__PURE__*/y.createElement(c.chakra.div,$e({ref:t,__css:u},i,{className:Ue("saas-stepper__container",e.className)}),/*#__PURE__*/y.createElement(at,{orientation:o},a))))});Me&&(nt.displayName="Stepper");var at=function(e){var t,r,n=e.children,a=e.orientation,o=e.stepComponent,i=Ge(e,Ye),l=c.useStyles(),u=Je().activeIndex,s=$e({display:"flex",flexDirection:"row",alignItems:"center"},l.steps),p="vertical"===a,f=o||lt,d=m.getChildrenOfType(n,f),v=d.reduce(function(e,t,r,n){return e.push(/*#__PURE__*/y.createElement(f,$e({key:r},t.props,{icon:t.props.icon||r+1,isActive:u===r,isCompleted:t.props.isCompleted||u>r}))),"vertical"===a&&e.push(/*#__PURE__*/y.createElement(ot,{isOpen:u===r},t.props.children)),r<n.length-1&&e.push(/*#__PURE__*/y.createElement(ut,{key:"separator-"+r,isActive:r<u})),e},[]),h=m.getChildOfType(n,ct),b=u>=d.length?h:p?null:null==(t=d[u])||null==(r=t.props)?void 0:r.children;return y.createElement(y.Fragment,null,/*#__PURE__*/y.createElement(c.chakra.div,$e({__css:s},i,{className:Ue("saas-stepper__steps",e.className)}),v),b&&/*#__PURE__*/y.createElement(ot,null,b))};Me&&(at.displayName="StepperSteps");var ot=function(e){var t=e.children,n=e.isOpen,a=void 0===n||n,o=Ge(e,Ze),i=c.useStyles();return y.createElement(c.chakra.div,$e({__css:i.content},o,{className:Ue("saas-stepper__content",e.className)}),/*#__PURE__*/y.createElement(r.Collapse,{in:a},t))};Me&&(ot.displayName="StepperContent");var it=function(e){var t,r=e.icon,n=e.isCompleted,a=e.className,o=Ge(e,et),i=$e({display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"full",fontSize:"1em",me:2},c.useStyles().icon);return t=n?/*#__PURE__*/y.createElement(p.Icon,{as:p.CheckIcon}):r,/*#__PURE__*/y.createElement(c.chakra.div,$e({__css:i},o,{className:Ue("saas-stepper__icon",a)}),t)};Me&&(it.displayName="StepperIcon");var lt=function(e){var t=e.title,r=e.icon,n=e.isActive,a=e.isCompleted,o=Ge(e,tt),i=Qe(e),l=$e({display:"flex",alignItems:"center",flexDirection:"row"},c.useStyles().step);return y.createElement(c.chakra.div,$e({__css:l,"data-active":i.isActive,"data-completed":i.isCompleted},o,{className:Ue("saas-stepper__step",e.className)}),/*#__PURE__*/y.createElement(it,{icon:r,isActive:n,isCompleted:a}),t&&/*#__PURE__*/y.createElement(st,null,t))};Me&&(lt.displayName="StepperStep");var ut=function(e){var t=e.isActive,r=Ge(e,rt),n=$e({flex:1,borderTopWidth:"1px",mx:2},c.useStyles().separator);return y.createElement(c.chakra.div,$e({"data-active":t},r,{className:Ue("saas-stepper__separator",e.className),__css:n}))};Me&&(ut.displayName="StepperSeparator");var st=function(e){var t=c.useStyles();return y.createElement(c.chakra.p,$e({},e,{__css:t.title,className:Ue("saas-stepper__title",e.className)}))};Me&&(st.displayName="StepperStepTitle");var ct=function(e){var t=c.useStyles();return y.createElement(c.chakra.div,$e({__css:t.completed},e,{className:Ue("saas-stepper__completed",e.className)}))};Me&&(ct.displayName="StepperCompleted");var pt=d.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),ft=pt[0],dt=pt[1];function mt(e){var t=Ke(e),r=t.activeStep,n=t.isLastStep,a=t.nextStep,o=y.useState({}),i=o[0],l=o[1],u=y.useCallback(function(t){try{return n?Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(t).then(function(){c(b({},i[r],{isCompleted:!0}))}).then(a)):(a(),Promise.resolve())}catch(e){return Promise.reject(e)}},[r,n]),s=y.useCallback(function(e){var t=i[r];return{onSubmit:u,schema:null==t?void 0:t.schema}},[i,u,r]),c=y.useCallback(function(e){l(function(t){var r;return b({},t,((r={})[e.name]=e,r))})},[i]);return b({getFormProps:s,updateStep:c,steps:i},t)}function vt(e){var t=e.name,r=e.schema,n=Qe({name:t}),a=dt(),o=a.steps,i=a.updateStep;return y.useEffect(function(){i({name:t,schema:r})},[t,r]),b({},n,o[t]||{})}var ht=["children","onSubmit"],yt=["getFormProps"],bt=["name","schema","children","className"],_t=["label","submitLabel"],xt=y.forwardRef(function(e,t){var r=e.children,n=_(e,ht),a=mt(e),o=a.getFormProps,i=_(a,yt),l=y.useMemo(function(){return i},[i]);/*#__PURE__*/return y.createElement(He,{value:l},/*#__PURE__*/y.createElement(ft,{value:l},/*#__PURE__*/y.createElement(Ne,b({ref:t},n,o(e)),function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return ze(e)?e.apply(void 0,r):e}(r,a))))}),gt=function(e){var t=e.name,r=e.schema,n=e.children,a=e.className,o=_(e,bt);return vt({name:t,schema:r}).isActive?/*#__PURE__*/y.createElement(c.chakra.div,b({},o,{className:qe("saas-form__step",a)}),n):null};De&&(gt.displayName="FormStep");var Et=function(e){var t=Je(),r=t.prevStep;/*#__PURE__*/return y.createElement(f.Button,b({isDisabled:t.isFirstStep||t.isCompleted,label:"Back"},e,{className:qe("saas-form__prev-button",e.className),onClick:Te(e.onClick,r)}))};De&&(Et.displayName="PrevButton");var St=function(e){var t=e.label,r=void 0===t?"Next":t,n=e.submitLabel,a=void 0===n?"Complete":n,o=_(e,_t),i=Je(),l=i.isCompleted;/*#__PURE__*/return y.createElement(Ie,b({isDisabled:l,label:i.isLastStep||l?a:r},o,{className:qe("saas-form__next-button",e.className)}))};De&&(St.displayName="NextButton"),exports.ArrayField=be,exports.ArrayFieldAddButton=ye,exports.ArrayFieldContainer=xe,exports.ArrayFieldProvider=te,exports.ArrayFieldRemoveButton=he,exports.ArrayFieldRow=de,exports.ArrayFieldRowContainer=ve,exports.ArrayFieldRowFields=me,exports.ArrayFieldRowProvider=ae,exports.ArrayFieldRows=_e,exports.AutoForm=Ve,exports.BaseField=I,exports.CheckboxField=U,exports.DisplayField=function(e){var t=e.name,n=e.label,a=_(e,g);/*#__PURE__*/return y.createElement(r.FormControl,a,n?/*#__PURE__*/y.createElement(r.FormLabel,{htmlFor:t},n):null,/*#__PURE__*/y.createElement(r.Text,{fontSize:"md"},/*#__PURE__*/y.createElement(E,{name:t})))},exports.DisplayIf=function(e){var r=e.children,n=e.condition;return(void 0===n?function(e){return!!e}:n)(t.useWatch({name:e.name,defaultValue:e.defaultValue,disabled:e.isDisabled,exact:e.isExact}),t.useFormContext())?r:null},exports.Field=R,exports.Fields=Ae,exports.Form=Ne,exports.FormLayout=Y,exports.FormLegend=Ee,exports.FormStep=gt,exports.FormStepper=function(e){var t=c.useMultiStyleConfig("Stepper",e),r=y.Children.map(e.children,function(e){if(y.isValidElement(e)&&(null==e?void 0:e.type)===gt){var t=vt(e.props);/*#__PURE__*/return y.createElement(lt,{name:e.props.name,title:e.props.title,isCompleted:t.isCompleted},e.props.children)}return e});/*#__PURE__*/return y.createElement(c.StylesProvider,{value:t},/*#__PURE__*/y.createElement(at,b({mb:"4"},e),r))},exports.FormValue=E,exports.InputField=B,exports.NativeSelectField=W,exports.NextButton=St,exports.NumberInputField=z,exports.ObjectField=Se,exports.PasswordInputFIeld=D,exports.PinField=G,exports.PrevButton=Et,exports.RadioField=$,exports.SelectField=M,exports.StepForm=xt,exports.StepFormProvider=ft,exports.SubmitButton=Ie,exports.SwitchField=T,exports.TextareaField=q,exports.registerFieldType=V,exports.useArrayField=ie,exports.useArrayFieldAddButton=se,exports.useArrayFieldContext=re,exports.useArrayFieldRemoveButton=ue,exports.useArrayFieldRow=le,exports.useArrayFieldRowContext=oe,exports.useFormStep=vt,exports.useStepForm=mt,exports.useStepFormContext=dt,exports.withControlledInput=P,exports.withUncontrolledInput=L,Object.keys(v).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return v[e]}})});
|
1
|
+
var e=require("react"),t=require("react-hook-form"),r=require("@chakra-ui/react"),n=require("@saas-ui/number-input"),a=require("@saas-ui/password-input"),l=require("@saas-ui/radio"),i=require("@saas-ui/pin-input"),o=require("@saas-ui/select"),s=require("yup"),u=require("@hookform/resolvers/yup"),c=require("@chakra-ui/system"),m=require("@chakra-ui/icons"),d=require("@saas-ui/button"),p=require("@chakra-ui/react-utils"),f=require("@chakra-ui/utils"),v=require("@saas-ui/react-utils"),h=require("@saas-ui/input-right-button");function x(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var y=/*#__PURE__*/x(e);function b(){return b=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},b.apply(this,arguments)}function E(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}function S(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var F=["name","label","placeholder"],_=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null},C=["name","label","help","variant","hideLabel","children"],g=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],N=["name","rules"],k=["ref"],w=["name","rules"],I=["ref"],A=["label"],R=["label"],O={},V=function(e){var n=e.name,a=e.label,l=e.help,i=e.variant,o=e.hideLabel,s=e.children,u=E(e,C),c=function(e,r){return t.get(r.errors,e)}(n,t.useFormContext().formState);/*#__PURE__*/return y.createElement(r.FormControl,b({variant:i},u,{isInvalid:!!c}),a&&!o?/*#__PURE__*/y.createElement(r.FormLabel,{variant:i},a):null,/*#__PURE__*/y.createElement(r.Box,null,s,!l||null!=c&&c.message?null:/*#__PURE__*/y.createElement(r.FormHelperText,null,l),(null==c?void 0:c.message)&&/*#__PURE__*/y.createElement(r.FormErrorMessage,null,null==c?void 0:c.message)))},D=r.forwardRef(function(e,t){var r=e.type;/*#__PURE__*/return y.createElement(O[void 0===r?"text":r]||O.text,b({ref:t},e))}),P=function(e){return r.forwardRef(function(n,a){var l=n.name,i=n.rules,o=E(n,N),s=t.useFormContext();/*#__PURE__*/return y.createElement(t.Controller,{name:l,control:s.control,rules:i,render:function(t){var n=t.field,l=n.ref,i=E(n,k);/*#__PURE__*/return y.createElement(e,b({},i,o,{ref:r.useMergeRefs(a,l)}))}})})},L=function(e){return r.forwardRef(function(n,a){var l=n.name,i=n.rules,o=E(n,w),s=(0,t.useFormContext().register)(l,i),u=s.ref,c=E(s,I);/*#__PURE__*/return y.createElement(e,b({},c,o,{ref:r.useMergeRefs(a,u)}))})},j=function(e,t,n){var a=function(e,t){var n=t.displayName,a=t.hideLabel,l=t.BaseField,i=r.forwardRef(function(t,r){var n=t.name,i=t.label,o=t.help,s=t.isDisabled,u=t.isInvalid,c=t.isReadOnly,m=t.isRequired,d=t.rules,p=t.variant,f=E(t,g),v=b({required:m},d);/*#__PURE__*/return y.createElement(l,{name:n,label:i,help:o,hideLabel:a,isDisabled:s,isInvalid:u,isReadOnly:c,isRequired:m,variant:p},/*#__PURE__*/y.createElement(e,b({ref:r,name:n,label:i,rules:v},f)))});return i.displayName=n,i}(null!=n&&n.isControlled?P(t):L(t),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==n?void 0:n.hideLabel,BaseField:(null==n?void 0:n.BaseField)||V});return O[e]=a,a},q=j("text",r.Input),B=j("number",n.NumberInput,{isControlled:!0}),M=j("password",a.PasswordInput),T=j("textarea",r.Textarea),U=j("switch",r.forwardRef(function(e,t){var n=e.label,a=E(e,A);/*#__PURE__*/return y.createElement(r.Switch,b({ref:t},a),n)}),{isControlled:!0,hideLabel:!0}),H=j("select",o.Select,{isControlled:!0}),G=j("checkbox",r.forwardRef(function(e,t){var n=e.label,a=E(e,R);/*#__PURE__*/return y.createElement(r.Checkbox,b({ref:t},a),n)}),{hideLabel:!0}),z=j("radio",l.RadioInput,{isControlled:!0}),W=j("pin",i.PinInput,{isControlled:!0}),$=j("native-select",o.NativeSelect,{isControlled:!0}),J=function(e){var t;if(null!=(t=e.spec.meta)&&t.type)return e.spec.meta.type;switch(e.type){case"array":return"array";case"object":return"object";case"number":return"number";case"date":return"date";default:return"text"}},K=function(e,t){for(var r,n=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return S(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?S(e,t):void 0}}(e))){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e.tests);!(r=n()).done;){var a,l=r.value;if(null!=(a=l.OPTIONS)&&a.params[t])return l.OPTIONS.params[t]}},Q=function(e){var t,r=[];for(var n in t="array"===e.type?e.innerType.fields:e.fields){var a=t[n],l={};"array"===a.type&&(l.min=K(a,"min"),l.max=K(a,"max")),r.push(b({name:n,label:a.spec.label||n,type:J(a)},l))}return r},X=["children"],Y=function(e){/*#__PURE__*/return y.createElement(r.chakra.div,null,e.children)},Z=function(e){var t,n,a,l=e.children,i=E(e,X),o=b({},null!=(t=null==(n=r.useTheme().components)||null==(a=n.FormLayout)?void 0:a.defaultProps)?t:{spacing:4},i);/*#__PURE__*/return y.createElement(r.SimpleGrid,o,y.Children.map(l,function(e){return y.isValidElement(e)?/*#__PURE__*/y.createElement(Y,null,e):e}))},ee=function(e,t){return y.Children.map(t,function(t){return y.isValidElement(t)&&t.props.name?y.cloneElement(t,b({},t.props,{name:e+"."+t.props.name})):t})},te=p.createContext({name:"ArrayFieldContext"}),re=te[0],ne=te[1],ae=p.createContext({name:"ArrayFieldRowContext"}),le=ae[0],ie=ae[1],oe=function(e){var r=e.name,n=e.defaultValue,a=void 0===n?{}:n,l=e.keyName,i=e.min,o=e.max,s=t.useFormContext();return b({},t.useFieldArray({control:s.control,name:r,keyName:l}),{name:r,defaultValue:a,min:i,max:o})},se=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=ne(),l=a.name,i=a.remove,o=a.fields;return y.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===o.length-1,name:l+"."+r,remove:y.useCallback(function(){n(l),i(r)},[r])}},ue=function(){var e=ie(),t=e.isFirst,r=e.remove,n=ne(),a=n.min;return{onClick:function(){return r()},isDisabled:t&&!!(a&&n.fields.length<=a)}},ce=function(){var e=ne(),t=e.append,r=e.defaultValue,n=e.max;return{onClick:function(){return t(r,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},me=["children","columns","spacing"],de=["children"],pe=["name","defaultValue","keyName","min","max","children"],fe=function(e){/*#__PURE__*/return y.createElement(he,{index:e.index},/*#__PURE__*/y.createElement(ve,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/y.createElement(xe,null))},ve=function(e){var t=e.children,r=e.columns,n=e.spacing,a=E(e,me),l=ie().name;/*#__PURE__*/return y.createElement(Z,b({flex:"1",columns:r,gridGap:n,mr:"2"},a),ee(l,t))},he=function(e){var t=e.children,r=se({index:e.index});/*#__PURE__*/return y.createElement(le,{value:r},/*#__PURE__*/y.createElement(c.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))},xe=function(e){/*#__PURE__*/return y.createElement(d.IconButton,b({icon:/*#__PURE__*/y.createElement(m.MinusIcon,null),"aria-label":"Remove row"},ue(),e))},ye=function(e){/*#__PURE__*/return y.createElement(d.IconButton,b({icon:/*#__PURE__*/y.createElement(m.AddIcon,null),"aria-label":"Add row",float:"right"},ce(),e))},be=y.forwardRef(function(e,t){var r=e.children,n=E(e,de);/*#__PURE__*/return y.createElement(Se,b({ref:t},n),/*#__PURE__*/y.createElement(Ee,null,function(e){/*#__PURE__*/return y.createElement(y.Fragment,null,e.map(function(e,t){/*#__PURE__*/return y.createElement(fe,{key:e.id,index:t},r)}))}),/*#__PURE__*/y.createElement(ye,null))}),Ee=function(e){return(0,e.children)(ne().fields)},Se=y.forwardRef(function(e,t){var r=e.name,n=e.defaultValue,a=e.keyName,l=e.min,i=e.max,o=e.children,s=E(e,pe),u=oe({name:r,defaultValue:n,keyName:a,min:l,max:i});return y.useImperativeHandle(t,function(){return u},[t,u]),/*#__PURE__*/y.createElement(re,{value:u},/*#__PURE__*/y.createElement(V,b({name:r},s),o))}),Fe=["name","label","hideLabel","children","columns","spacing"],_e=function(e){var t=r.useStyles();/*#__PURE__*/return y.createElement(r.FormLabel,b({as:"legend",sx:t.legend},e))},Ce=function(e){var t=e.name,n=e.label,a=e.hideLabel,l=e.children,i=e.columns,o=e.spacing,s=E(e,Fe);/*#__PURE__*/return y.createElement(r.FormControl,b({name:t,as:"fieldset"},s),/*#__PURE__*/y.createElement(_e,{display:a?"none":"block"},n),/*#__PURE__*/y.createElement(Z,{columns:i,gridGap:o},ee(t,l)))},ge=["name","type"],Ne=["schema"],ke=["name","type","defaultValue"],we=function(e,t){return Q(function(e,t){return s.reach(e,t)}(e,t)).map(function(e){var t=e.name,r=e.type,n=E(e,ge);/*#__PURE__*/return y.createElement(D,b({key:t,name:t,type:r},n))})},Ie=function(e){var t=e.schema,r=E(e,Ne);/*#__PURE__*/return y.createElement(Z,r,Q(t).map(function(e){var r=e.name,n=e.type,a=E(e,ke);return"array"===n?/*#__PURE__*/y.createElement(be,b({name:r},a),we(t,r)):"object"===n?/*#__PURE__*/y.createElement(Ce,b({name:r},a),we(t,r)):/*#__PURE__*/y.createElement(D,b({key:r,name:r,type:n},a))}))},Ae=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Re=r.forwardRef(function(e,n){var a=e.mode,l=void 0===a?"all":a,i=e.resolver,o=e.reValidateMode,s=e.shouldFocusError,c=e.shouldUnregister,m=e.shouldUseNativeValidation,d=e.criteriaMode,p=e.delayError,f=e.schema,v=e.defaultValues,h=e.onSubmit,x=e.onError,S=e.formRef,F=e.children,_=E(e,Ae),C={mode:l,resolver:i,defaultValues:v,reValidateMode:o,shouldFocusError:s,shouldUnregister:c,shouldUseNativeValidation:m,criteriaMode:d,delayError:p};f&&(C.resolver=u.yupResolver(f));var g=t.useForm(C),N=g.handleSubmit;return y.useImperativeHandle(n,function(){return g},[n,g]),/*#__PURE__*/y.createElement(t.FormProvider,g,/*#__PURE__*/y.createElement(r.chakra.form,b({ref:S,onSubmit:N(h,x)},_),F))}),Oe=["children","disableIfUntouched","disableIfInvalid"],Ve=c.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=E(e,Oe),o=t.useFormContext().formState;/*#__PURE__*/return y.createElement(d.Button,b({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:r,isDisabled:a&&!o.isDirty||l&&!o.isValid},i),n)});Ve.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};var De=["schema","submitLabel"],Pe=r.forwardRef(function(e,t){var r=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=E(e,De);/*#__PURE__*/return y.createElement(Re,b({},l,{schema:r,ref:t}),/*#__PURE__*/y.createElement(Z,null,/*#__PURE__*/y.createElement(Ie,{schema:r}),a&&/*#__PURE__*/y.createElement(Ve,{label:a})))});function Le(){return Le=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Le.apply(this,arguments)}function je(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var qe=p.createContext({name:"StepperContext",errorMessage:"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`"}),Be=qe[0],Me=qe[1];function Te(e){var t=e.step,r=y.useState(-1),n=r[0],a=r[1],l=y.useRef([]),i=y.useState(Date.now())[1],o=y.useCallback(function(e){var t=[].concat(l.current);-1===t.indexOf(e)&&t.push(e),l.current=t,i(Date.now())},[l,i]),s=function(e){var t=l.current.indexOf(e);-1!==t&&a(t)};return y.useLayoutEffect(function(){"string"==typeof t?s(t):"number"==typeof t?a(t):-1===n&&a(0)},[t]),{stepsRef:l,activeStep:l.current[n],activeIndex:n,isFirstStep:0===n,isLastStep:n===l.current.length-1,isCompleted:n>=l.current.length,setIndex:a,setStep:s,nextStep:function(){a(n+1)},prevStep:function(){a(n-1)},registerStep:o,unregisterStep:function(e){l.current=l.current.slice(l.current.indexOf(e),1)}}}function Ue(e){var t=e.name,r=e.isActive,n=e.isCompleted,a=Me(),l=a.registerStep,i=a.unregisterStep,o=a.activeStep;return y.useEffect(function(){if(t)return l(t),function(){i(t)}},[]),{isActive:t?o===t:r,isCompleted:n}}var He=["children","orientation"],Ge=["children","orientation","stepComponent"],ze=["children","isOpen"],We=["icon","isActive","isCompleted","className"],$e=["title","icon","isActive","isCompleted"],Je=["isActive"],Ke=c.forwardRef(function(e,t){var r=c.useMultiStyleConfig("Stepper",e),n=c.omitThemingProps(e),a=n.children,l=n.orientation,i=je(n,He),o=Te(e),s=Le({display:"flex",flexDirection:"column"},r.container);return y.createElement(c.StylesProvider,{value:r},/*#__PURE__*/y.createElement(Be,{value:o},/*#__PURE__*/y.createElement(c.chakra.div,Le({ref:t,__css:s},i,{className:f.cx("saas-stepper__container",e.className)}),/*#__PURE__*/y.createElement(Qe,{orientation:l},a))))});f.__DEV__&&(Ke.displayName="Stepper");var Qe=function(e){var t,r,n=e.children,a=e.orientation,l=e.stepComponent,i=je(e,Ge),o=c.useStyles(),s=Me().activeIndex,u=Le({display:"flex",flexDirection:"row",alignItems:"center"},o.steps),m="vertical"===a,d=l||Ze,p=v.getChildrenOfType(n,d),h=p.reduce(function(e,t,r,n){return e.push(/*#__PURE__*/y.createElement(d,Le({key:r},t.props,{icon:t.props.icon||r+1,isActive:s===r,isCompleted:t.props.isCompleted||s>r}))),"vertical"===a&&e.push(/*#__PURE__*/y.createElement(Xe,{isOpen:s===r},t.props.children)),r<n.length-1&&e.push(/*#__PURE__*/y.createElement(et,{key:"separator-"+r,isActive:r<s})),e},[]),x=v.getChildOfType(n,rt),b=s>=p.length?x:m?null:/*#__PURE__*/y.createElement(Xe,null,null==(t=p[s])||null==(r=t.props)?void 0:r.children);return y.createElement(y.Fragment,null,/*#__PURE__*/y.createElement(c.chakra.div,Le({__css:u},i,{className:f.cx("saas-stepper__steps",e.className)}),h),b)};f.__DEV__&&(Qe.displayName="StepperSteps");var Xe=function(e){var t=e.children,n=e.isOpen,a=void 0===n||n,l=je(e,ze),i=c.useStyles();return y.createElement(c.chakra.div,Le({__css:i.content},l,{className:f.cx("saas-stepper__content",e.className)}),/*#__PURE__*/y.createElement(r.Collapse,{in:a},t))};f.__DEV__&&(Xe.displayName="StepperContent");var Ye=function(e){var t,r=e.icon,n=e.isCompleted,a=e.className,l=je(e,We),i=Le({display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"full",fontSize:"1em",me:2},c.useStyles().icon);return t=n?/*#__PURE__*/y.createElement(m.Icon,{as:m.CheckIcon}):r,/*#__PURE__*/y.createElement(c.chakra.div,Le({__css:i},l,{className:f.cx("saas-stepper__icon",a)}),t)};f.__DEV__&&(Ye.displayName="StepperIcon");var Ze=function(e){var t=e.title,r=e.icon,n=e.isActive,a=e.isCompleted,l=je(e,$e),i=Ue(e),o=Le({display:"flex",alignItems:"center",flexDirection:"row"},c.useStyles().step);return y.createElement(c.chakra.div,Le({__css:o,"data-active":i.isActive,"data-completed":i.isCompleted},l,{className:f.cx("saas-stepper__step",e.className)}),/*#__PURE__*/y.createElement(Ye,{icon:r,isActive:n,isCompleted:a}),t&&/*#__PURE__*/y.createElement(tt,null,t))};f.__DEV__&&(Ze.displayName="StepperStep");var et=function(e){var t=e.isActive,r=je(e,Je),n=Le({flex:1,borderTopWidth:"1px",mx:2},c.useStyles().separator);return y.createElement(c.chakra.div,Le({"data-active":t},r,{className:f.cx("saas-stepper__separator",e.className),__css:n}))};f.__DEV__&&(et.displayName="StepperSeparator");var tt=function(e){var t=c.useStyles();return y.createElement(c.chakra.p,Le({},e,{__css:t.title,className:f.cx("saas-stepper__title",e.className)}))};f.__DEV__&&(tt.displayName="StepperStepTitle");var rt=function(e){var t=c.useStyles();return y.createElement(c.chakra.div,Le({__css:t.completed},e,{className:f.cx("saas-stepper__completed",e.className)}))};f.__DEV__&&(rt.displayName="StepperCompleted");var nt=p.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),at=nt[0],lt=nt[1];function it(e){var t=Te(e),r=t.activeStep,n=t.isLastStep,a=t.nextStep,l=y.useState({}),i=l[0],o=l[1],s=y.useCallback(function(t){try{return n?Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(t).then(function(){c(b({},i[r],{isCompleted:!0}))}).then(a)):(a(),Promise.resolve())}catch(e){return Promise.reject(e)}},[r,n]),u=y.useCallback(function(e){var t=i[r];return{onSubmit:s,schema:null==t?void 0:t.schema}},[i,s,r]),c=y.useCallback(function(e){o(function(t){var r;return b({},t,((r={})[e.name]=e,r))})},[i]);return b({getFormProps:u,updateStep:c,steps:i},t)}function ot(e){var t=e.name,r=e.schema,n=Ue({name:t}),a=lt(),l=a.steps,i=a.updateStep;return y.useEffect(function(){i({name:t,schema:r})},[t,r]),b({},n,l[t]||{name:t,schema:r})}var st=["children","onSubmit"],ut=["getFormProps"],ct=["name","schema","children","className"],mt=["label","submitLabel"],dt=y.forwardRef(function(e,t){var r=e.children,n=E(e,st),a=it(e),l=a.getFormProps,i=E(a,ut),o=y.useMemo(function(){return i},[i]);/*#__PURE__*/return y.createElement(Be,{value:o},/*#__PURE__*/y.createElement(at,{value:o},/*#__PURE__*/y.createElement(Re,b({ref:t},n,l(e)),f.runIfFn(r,a))))}),pt=function(e){var t=e.name,r=e.schema,n=e.children,a=e.className,l=E(e,ct);return ot({name:t,schema:r}).isActive?/*#__PURE__*/y.createElement(c.chakra.div,b({},l,{className:f.cx("saas-form__step",a)}),n):null};f.__DEV__&&(pt.displayName="FormStep");var ft=function(e){var t=Me(),r=t.prevStep;/*#__PURE__*/return y.createElement(d.Button,b({isDisabled:t.isFirstStep||t.isCompleted,label:"Back"},e,{className:f.cx("saas-form__prev-button",e.className),onClick:f.callAllHandlers(e.onClick,r)}))};f.__DEV__&&(ft.displayName="PrevButton");var vt=function(e){var t=e.label,r=void 0===t?"Next":t,n=e.submitLabel,a=void 0===n?"Complete":n,l=E(e,mt),i=Me(),o=i.isCompleted;/*#__PURE__*/return y.createElement(Ve,b({isDisabled:o,label:i.isLastStep||o?a:r},l,{className:f.cx("saas-form__next-button",e.className)}))};f.__DEV__&&(vt.displayName="NextButton"),exports.ArrayField=be,exports.ArrayFieldAddButton=ye,exports.ArrayFieldContainer=Se,exports.ArrayFieldProvider=re,exports.ArrayFieldRemoveButton=xe,exports.ArrayFieldRow=fe,exports.ArrayFieldRowContainer=he,exports.ArrayFieldRowFields=ve,exports.ArrayFieldRowProvider=le,exports.ArrayFieldRows=Ee,exports.AutoForm=Pe,exports.BaseField=V,exports.CheckboxField=G,exports.DisplayField=function(e){var t=e.name,n=e.label,a=E(e,F);/*#__PURE__*/return y.createElement(r.FormControl,a,n?/*#__PURE__*/y.createElement(r.FormLabel,{htmlFor:t},n):null,/*#__PURE__*/y.createElement(r.Text,{fontSize:"md"},/*#__PURE__*/y.createElement(_,{name:t})))},exports.DisplayIf=function(e){var r=e.children,n=e.condition;return(void 0===n?function(e){return!!e}:n)(t.useWatch({name:e.name,defaultValue:e.defaultValue,disabled:e.isDisabled,exact:e.isExact}),t.useFormContext())?r:null},exports.Field=D,exports.Fields=Ie,exports.Form=Re,exports.FormLayout=Z,exports.FormLegend=_e,exports.FormStep=pt,exports.FormStepper=function(e){var t=c.useMultiStyleConfig("Stepper",e),r=y.Children.map(e.children,function(e){if(y.isValidElement(e)&&(null==e?void 0:e.type)===pt){var t=ot(e.props);/*#__PURE__*/return y.createElement(Ze,{name:e.props.name,title:e.props.title,isCompleted:t.isCompleted},e.props.children)}return e});/*#__PURE__*/return y.createElement(c.StylesProvider,{value:t},/*#__PURE__*/y.createElement(Qe,b({mb:"4"},e),r))},exports.FormValue=_,exports.InputField=q,exports.NativeSelectField=$,exports.NextButton=vt,exports.NumberInputField=B,exports.ObjectField=Ce,exports.PasswordInputFIeld=M,exports.PinField=W,exports.PrevButton=ft,exports.RadioField=z,exports.SelectField=H,exports.StepForm=dt,exports.StepFormProvider=at,exports.SubmitButton=Ve,exports.SwitchField=U,exports.TextareaField=T,exports.registerFieldType=j,exports.useArrayField=oe,exports.useArrayFieldAddButton=ce,exports.useArrayFieldContext=ne,exports.useArrayFieldRemoveButton=ue,exports.useArrayFieldRow=se,exports.useArrayFieldRowContext=ie,exports.useFormStep=ot,exports.useStepForm=it,exports.useStepFormContext=lt,exports.withControlledInput=P,exports.withUncontrolledInput=L,Object.keys(h).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return h[e]}})});
|
2
2
|
//# sourceMappingURL=index.js.map
|