@cyclone-ui/state 0.0.67 → 0.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/form/hooks/form-field-validations.cjs +1 -0
- package/dist/form/hooks/form-field-validations.d.cts +12 -0
- package/dist/form/hooks/form-field-validations.d.cts.map +1 -0
- package/dist/form/hooks/form-field-validations.d.mts +12 -0
- package/dist/form/hooks/form-field-validations.d.mts.map +1 -0
- package/dist/form/hooks/form-field-validations.mjs +2 -0
- package/dist/form/hooks/form-field-validations.mjs.map +1 -0
- package/dist/form/hooks/index.cjs +1 -1
- package/dist/form/hooks/index.d.cts +2 -1
- package/dist/form/hooks/index.d.mts +2 -1
- package/dist/form/hooks/index.mjs +1 -1
- package/dist/form/hooks/use-field-actions.cjs +1 -1
- package/dist/form/hooks/use-field-actions.d.cts.map +1 -1
- package/dist/form/hooks/use-field-actions.mjs +1 -1
- package/dist/form/hooks/use-field-actions.mjs.map +1 -1
- package/dist/form/hooks/use-form-actions.cjs +1 -1
- package/dist/form/hooks/use-form-actions.d.cts +2 -0
- package/dist/form/hooks/use-form-actions.d.cts.map +1 -1
- package/dist/form/hooks/use-form-actions.d.mts +2 -0
- package/dist/form/hooks/use-form-actions.mjs +1 -1
- package/dist/form/hooks/use-form-actions.mjs.map +1 -1
- package/dist/form/index.cjs +1 -1
- package/dist/form/index.d.cts +4 -2
- package/dist/form/index.d.mts +4 -2
- package/dist/form/index.mjs +1 -1
- package/dist/form/molecules/field-molecule.cjs +1 -1
- package/dist/form/molecules/field-molecule.mjs +1 -1
- package/dist/form/molecules/form-molecule.cjs +1 -1
- package/dist/form/molecules/form-molecule.d.cts.map +1 -1
- package/dist/form/molecules/form-molecule.mjs +1 -1
- package/dist/form/molecules/form-molecule.mjs.map +1 -1
- package/dist/form/providers/FieldProvider.cjs +1 -1
- package/dist/form/providers/FieldProvider.d.cts.map +1 -1
- package/dist/form/providers/FieldProvider.mjs +1 -1
- package/dist/form/providers/FieldProvider.mjs.map +1 -1
- package/dist/form/providers/FormProvider.cjs +1 -1
- package/dist/form/providers/FormProvider.d.cts.map +1 -1
- package/dist/form/providers/FormProvider.mjs +1 -1
- package/dist/form/providers/FormProvider.mjs.map +1 -1
- package/dist/form/types.d.cts +19 -3
- package/dist/form/types.d.cts.map +1 -1
- package/dist/form/types.d.mts +19 -3
- package/dist/form/utilities/index.cjs +1 -1
- package/dist/form/utilities/index.d.cts +2 -1
- package/dist/form/utilities/index.d.mts +2 -1
- package/dist/form/utilities/index.mjs +1 -1
- package/dist/form/utilities/server-errors.cjs +1 -0
- package/dist/form/utilities/server-errors.d.cts +29 -0
- package/dist/form/utilities/server-errors.d.cts.map +1 -0
- package/dist/form/utilities/server-errors.d.mts +29 -0
- package/dist/form/utilities/server-errors.d.mts.map +1 -0
- package/dist/form/utilities/server-errors.mjs +2 -0
- package/dist/form/utilities/server-errors.mjs.map +1 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog for Cyclone UI - State
|
|
4
4
|
|
|
5
|
+
## [0.0.68](https://github.com/storm-software/cyclone-ui/releases/tag/state%400.0.68) (11/10/2026)
|
|
6
|
+
|
|
7
|
+
### Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated **helpers** to **v0.3.66**
|
|
10
|
+
|
|
11
|
+
## [0.0.67](https://github.com/storm-software/cyclone-ui/releases/tag/state%400.0.67) (11/10/2026)
|
|
12
|
+
|
|
13
|
+
### Updated Dependencies
|
|
14
|
+
|
|
15
|
+
- Updated **helpers** to **v0.3.65**
|
|
16
|
+
|
|
5
17
|
## [0.0.66](https://github.com/storm-software/cyclone-ui/releases/tag/state%400.0.66) (11/09/2026)
|
|
6
18
|
|
|
7
19
|
### Updated Dependencies
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=(0,require("react").createContext)(null);exports.FormFieldValidationsContext=e;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs all of a field's validators against its current value. Synchronous
|
|
3
|
+
* validators store their results before the returned promise settles.
|
|
4
|
+
*/
|
|
5
|
+
type FieldValidation = () => Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* The validations of a form's mounted fields, which the form runs on submit
|
|
8
|
+
* (`null` outside of a `FormProvider`).
|
|
9
|
+
*/
|
|
10
|
+
declare const FormFieldValidationsContext: import("react").Context<Set<FieldValidation> | null>;
|
|
11
|
+
export { FieldValidation, FormFieldValidationsContext };
|
|
12
|
+
//# sourceMappingURL=form-field-validations.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-field-validations.d.cts","names":[],"sources":["../../../src/form/hooks/form-field-validations.ts"],"mappings":";;;;KAwBY,wBAAwB;;;;;cAMvB,6CAA2B,QAAA,IAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs all of a field's validators against its current value. Synchronous
|
|
3
|
+
* validators store their results before the returned promise settles.
|
|
4
|
+
*/
|
|
5
|
+
type FieldValidation = () => Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* The validations of a form's mounted fields, which the form runs on submit
|
|
8
|
+
* (`null` outside of a `FormProvider`).
|
|
9
|
+
*/
|
|
10
|
+
declare const FormFieldValidationsContext: import("react").Context<Set<FieldValidation> | null>;
|
|
11
|
+
export { FieldValidation, FormFieldValidationsContext };
|
|
12
|
+
//# sourceMappingURL=form-field-validations.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-field-validations.d.mts","names":[],"sources":["../../../src/form/hooks/form-field-validations.ts"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-field-validations.mjs","names":["FormFieldValidationsContext","createContext"],"sources":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("./use-field-actions.cjs"),
|
|
1
|
+
const e=require("./form-field-validations.cjs"),t=require("./use-field-actions.cjs"),n=require("./use-field-ref.cjs"),r=require("./use-form-actions.cjs");exports.FormFieldValidationsContext=e.FormFieldValidationsContext,exports.useFieldActions=t.useFieldActions,exports.useFieldRef=n.useFieldRef,exports.useFormActions=r.useFormActions;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { FieldValidation, FormFieldValidationsContext } from "./form-field-validations.cjs";
|
|
1
2
|
import { useFieldActions } from "./use-field-actions.cjs";
|
|
2
3
|
import { useFieldRef } from "./use-field-ref.cjs";
|
|
3
4
|
import { useFormActions } from "./use-form-actions.cjs";
|
|
4
|
-
export { useFieldActions, useFieldRef, useFormActions };
|
|
5
|
+
export { FieldValidation, FormFieldValidationsContext, useFieldActions, useFieldRef, useFormActions };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { FieldValidation, FormFieldValidationsContext } from "./form-field-validations.mjs";
|
|
1
2
|
import { useFieldActions } from "./use-field-actions.mjs";
|
|
2
3
|
import { useFieldRef } from "./use-field-ref.mjs";
|
|
3
4
|
import { useFormActions } from "./use-form-actions.mjs";
|
|
4
|
-
export { useFieldActions, useFieldRef, useFormActions };
|
|
5
|
+
export { FieldValidation, FormFieldValidationsContext, useFieldActions, useFieldRef, useFormActions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{FormFieldValidationsContext as e}from"./form-field-validations.mjs";import{useFieldActions as t}from"./use-field-actions.mjs";import{useFieldRef as n}from"./use-field-ref.mjs";import{useFormActions as r}from"./use-form-actions.mjs";export{e as FormFieldValidationsContext,t as useFieldActions,n as useFieldRef,r as useFormActions};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../molecules/field-molecule.cjs"),t=require("../types.cjs");let
|
|
1
|
+
const e=require("../molecules/field-molecule.cjs"),t=require("../types.cjs"),n=require("../utilities/server-errors.cjs");let r=require("jotai/utils"),i=require("react"),a=require("@stryke/type-checks/is-promise");const o={initialize:`onInitialize`,change:`onChange`,blur:`onBlur`,submit:`onSubmit`,server:`onServer`},s=()=>{let s=e.FieldApi.useMolecule(),c=(0,r.useAtomCallback)((0,i.useCallback)(async(e,n,r,i)=>{let c=e(s.options),l=c.validate?.[o[i]],u=c.validate?.[o.initialize];if(l&&l.length>0||u&&u.length>0){let o=e(s.previousValue),c=[];if(l&&l.length>0)for(let t of l)c.push(t(r,o,i,e,n));if(i!==t.ValidationCause.INITIALIZE&&u&&u.length>0)for(let t of u)c.push(t(r,o,i,e,n));let d=[],f=[];for(let e of c)e&&((0,a.isPromise)(e)?f.push(e):d.push(...e));if(f.length>0){n(s.validating,!0);for(let e of await Promise.all(f))e&&e.length>0&&d.push(...e);n(s.validating,!1)}n(s.validationResults,e=>({...e,[i]:d}))}},[])),l=(0,r.useAtomCallback)((0,i.useCallback)(async(e,t)=>{t(s.value,e(s.initialValue)),t(s.options,r.RESET)},[])),u=(0,r.useAtomCallback)((0,i.useCallback)(async(e,t,n,r=!0)=>{r&&e(s.dirty)||n!==e(s.initialValue)&&t(s.initialValue,n)},[])),d=(0,r.useAtomCallback)((0,i.useCallback)(async(e,t,r,i=!1)=>{if(!e(s.disabled)&&!e(s.readOnly)){!e(s.touched)&&i&&t(s.touched,i);let a=e(s.options),o=e(s.value),c=r;a.parse&&(c=a.parse(r)),a.isEqual(c,o)||(t(s.value,c),t(s.validationResults,n.clearServerErrors))}},[])),f=(0,r.useAtomCallback)((0,i.useCallback)(async(e,t)=>{e(s.disabled)||(e(s.touched)||t(s.touched,!0),t(s.focused,!0))},[])),p=(0,r.useAtomCallback)((0,i.useCallback)(async(e,t)=>{e(s.disabled)||(e(s.touched)||t(s.touched,!0),t(s.focused,!1),t(s.blurred,!0))},[])),m=(0,i.useCallback)(async e=>e?f():p(),[f,p]),h=(0,r.useAtomCallback)((0,i.useCallback)(async e=>m(!e(s.focused)),[m]));return{mount:(0,r.useAtomCallback)((0,i.useCallback)(async(e,t,n,r)=>{if(t(s.ref,()=>n),t(s.tabIndex,r??0),!e(s.initialValue)){let n=e(s.options);t(s.initialValue,n.defaultValue??null)}},[])),initialize:u,change:d,focus:f,blur:p,setFocused:m,toggleFocused:h,validate:c,reset:l}};exports.useFieldActions=s;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-field-actions.d.cts","names":[],"sources":["../../../src/form/hooks/use-field-actions.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"use-field-actions.d.cts","names":[],"sources":["../../../src/form/hooks/use-field-actions.ts"],"mappings":";;cAuCa,kBAAmB;;;;;;EAmKZ,aAAA,qBAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{FieldApi as e}from"../molecules/field-molecule.mjs";import{ValidationCause as t}from"../types.mjs";import{RESET as
|
|
1
|
+
import{FieldApi as e}from"../molecules/field-molecule.mjs";import{ValidationCause as t}from"../types.mjs";import{clearServerErrors as n}from"../utilities/server-errors.mjs";import{RESET as r,useAtomCallback as i}from"jotai/utils";import{useCallback as a}from"react";import{isPromise as o}from"@stryke/type-checks/is-promise";const s={initialize:`onInitialize`,change:`onChange`,blur:`onBlur`,submit:`onSubmit`,server:`onServer`},c=()=>{let c=e.useMolecule(),l=i(a(async(e,n,r,i)=>{let a=e(c.options),l=a.validate?.[s[i]],u=a.validate?.[s.initialize];if(l&&l.length>0||u&&u.length>0){let a=e(c.previousValue),s=[];if(l&&l.length>0)for(let t of l)s.push(t(r,a,i,e,n));if(i!==t.INITIALIZE&&u&&u.length>0)for(let t of u)s.push(t(r,a,i,e,n));let d=[],f=[];for(let e of s)e&&(o(e)?f.push(e):d.push(...e));if(f.length>0){n(c.validating,!0);for(let e of await Promise.all(f))e&&e.length>0&&d.push(...e);n(c.validating,!1)}n(c.validationResults,e=>({...e,[i]:d}))}},[])),u=i(a(async(e,t)=>{t(c.value,e(c.initialValue)),t(c.options,r)},[])),d=i(a(async(e,t,n,r=!0)=>{r&&e(c.dirty)||n!==e(c.initialValue)&&t(c.initialValue,n)},[])),f=i(a(async(e,t,r,i=!1)=>{if(!e(c.disabled)&&!e(c.readOnly)){!e(c.touched)&&i&&t(c.touched,i);let a=e(c.options),o=e(c.value),s=r;a.parse&&(s=a.parse(r)),a.isEqual(s,o)||(t(c.value,s),t(c.validationResults,n))}},[])),p=i(a(async(e,t)=>{e(c.disabled)||(e(c.touched)||t(c.touched,!0),t(c.focused,!0))},[])),m=i(a(async(e,t)=>{e(c.disabled)||(e(c.touched)||t(c.touched,!0),t(c.focused,!1),t(c.blurred,!0))},[])),h=a(async e=>e?p():m(),[p,m]),g=i(a(async e=>h(!e(c.focused)),[h]));return{mount:i(a(async(e,t,n,r)=>{if(t(c.ref,()=>n),t(c.tabIndex,r??0),!e(c.initialValue)){let n=e(c.options);t(c.initialValue,n.defaultValue??null)}},[])),initialize:d,change:f,focus:p,blur:m,setFocused:h,toggleFocused:g,validate:l,reset:u}};export{c as useFieldActions};
|
|
2
2
|
//# sourceMappingURL=use-field-actions.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-field-actions.mjs","names":["validationKey","useFieldActions","field","FieldApi","validate","useAtomCallback","useCallback","options","get","validators","cause","initializeValidators","previousValue","results","validator","nextValue","set","ValidationCause","messages","promises","result","isPromise","prev","reset","RESET","initialize","skipIfDirty","initialValue","change","touch","value","nextParsed","focus","blur","setFocused","focused","toggleFocused","ref","tabIndex"],"sources":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"use-field-actions.mjs","names":["validationKey","useFieldActions","field","FieldApi","validate","useAtomCallback","useCallback","options","get","validators","cause","initializeValidators","previousValue","results","validator","nextValue","set","ValidationCause","messages","promises","result","isPromise","prev","reset","RESET","initialize","skipIfDirty","initialValue","change","touch","value","nextParsed","clearServerErrors","focus","blur","setFocused","focused","toggleFocused","ref","tabIndex"],"sources":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../molecules/form-molecule.cjs"),t=require("../types.cjs");let
|
|
1
|
+
const e=require("../molecules/form-molecule.cjs"),t=require("../types.cjs"),n=require("./form-field-validations.cjs");let r=require("jotai/utils"),i=require("react"),a=require("@stryke/type-checks/is-promise");const o={initialize:`onInitialize`,change:`onChange`,blur:`onBlur`,submit:`onSubmit`,server:`onServer`},s=()=>{let s=e.FormApi.useMolecule(),c=(0,i.use)(n.FormFieldValidationsContext),l=(0,r.useAtomCallback)((0,i.useCallback)(async(e,t,n)=>{},[])),u=(0,r.useAtomCallback)((0,i.useCallback)(async(e,t,n)=>{},[])),d=(0,r.useAtomCallback)((0,i.useCallback)(async(e,n,r,i)=>{let c=e(s.options),l=c.validate?.[o[i]],u=c.validate?.[o.initialize];if(l&&l.length>0||u&&u.length>0){let o=e(s.previousValues),c=[];if(l&&l.length>0)for(let t of l)c.push(t(r,o,i,e,n));if(i!==t.ValidationCause.INITIALIZE&&u&&u.length>0)for(let t of u)c.push(t(r,o,i,e,n));let d=[],f=[];for(let e of c)e&&((0,a.isPromise)(e)?f.push(e):d.push(...e));if(f.length>0){n(s.formValidating,!0);for(let e of await Promise.all(f))e&&e.length>0&&d.push(...e);n(s.formValidating,!1)}n(s.validationResults,e=>({...e,[i]:d}))}},[])),f=(0,r.useAtomCallback)((0,i.useCallback)(async(e,t,n)=>{let r=e(s.options),i=e(s.values);r.isEqual(n,i)||t(s.values,n)},[])),p=(0,i.useCallback)(async()=>{await Promise.all(Array.from(c??[],async e=>e()))},[c]);return{initializeField:l,uninitializeField:u,validate:d,validateFields:p,isSubmittable:(0,r.useAtomCallback)((0,i.useCallback)(e=>e(s.canSubmit),[])),change:f,submit:(0,r.useAtomCallback)((0,i.useCallback)(async(e,n)=>{if(!(e(s.submitting)||e(s.disabled))&&(n(s.submitAttempts,e=>e+1),await Promise.all([p(),d(e(s.values),t.ValidationCause.SUBMIT)]),e(s.canSubmit))){n(s.submitting,!0);try{await e(s.options).onSubmit?.({get:e,set:n,atoms:s}),n(s.submitted,!0)}finally{n(s.submitting,!1)}}},[p,d])),reset:(0,r.useAtomCallback)((0,i.useCallback)((e,t)=>{t(s.values,r.RESET),t(s.validationResults,r.RESET),t(s.validationResultsFields,r.RESET),t(s.touchedFields,r.RESET),t(s.blurredFields,r.RESET),t(s.submitted,r.RESET),t(s.submitAttempts,r.RESET)},[s]))}};exports.useFormActions=s;
|
|
@@ -3,6 +3,8 @@ declare const useFormActions: <TFormValues extends Record<string, any> = Record<
|
|
|
3
3
|
initializeField: (_name: string) => Promise<void>;
|
|
4
4
|
uninitializeField: (_name: string) => Promise<void>;
|
|
5
5
|
validate: (nextValues: TFormValues, cause: ValidationCause) => Promise<void>;
|
|
6
|
+
validateFields: () => Promise<void>;
|
|
7
|
+
isSubmittable: () => boolean;
|
|
6
8
|
change: (nextValues: TFormValues) => Promise<void>;
|
|
7
9
|
submit: () => Promise<void>;
|
|
8
10
|
reset: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-form-actions.d.cts","names":[],"sources":["../../../src/form/hooks/use-form-actions.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"use-form-actions.d.cts","names":[],"sources":["../../../src/form/hooks/use-form-actions.ts"],"mappings":";cAsCa,iBACX,oBAAoB,sBAAsB"}
|
|
@@ -3,6 +3,8 @@ declare const useFormActions: <TFormValues extends Record<string, any> = Record<
|
|
|
3
3
|
initializeField: (_name: string) => Promise<void>;
|
|
4
4
|
uninitializeField: (_name: string) => Promise<void>;
|
|
5
5
|
validate: (nextValues: TFormValues, cause: ValidationCause) => Promise<void>;
|
|
6
|
+
validateFields: () => Promise<void>;
|
|
7
|
+
isSubmittable: () => boolean;
|
|
6
8
|
change: (nextValues: TFormValues) => Promise<void>;
|
|
7
9
|
submit: () => Promise<void>;
|
|
8
10
|
reset: () => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{FormApi as e}from"../molecules/form-molecule.mjs";import{ValidationCause as t}from"../types.mjs";import{
|
|
1
|
+
import{FormApi as e}from"../molecules/form-molecule.mjs";import{ValidationCause as t}from"../types.mjs";import{FormFieldValidationsContext as n}from"./form-field-validations.mjs";import{RESET as r,useAtomCallback as i}from"jotai/utils";import{use as a,useCallback as o}from"react";import{isPromise as s}from"@stryke/type-checks/is-promise";const c={initialize:`onInitialize`,change:`onChange`,blur:`onBlur`,submit:`onSubmit`,server:`onServer`},l=()=>{let l=e.useMolecule(),u=a(n),d=i(o(async(e,t,n)=>{},[])),f=i(o(async(e,t,n)=>{},[])),p=i(o(async(e,n,r,i)=>{let a=e(l.options),o=a.validate?.[c[i]],u=a.validate?.[c.initialize];if(o&&o.length>0||u&&u.length>0){let a=e(l.previousValues),c=[];if(o&&o.length>0)for(let t of o)c.push(t(r,a,i,e,n));if(i!==t.INITIALIZE&&u&&u.length>0)for(let t of u)c.push(t(r,a,i,e,n));let d=[],f=[];for(let e of c)e&&(s(e)?f.push(e):d.push(...e));if(f.length>0){n(l.formValidating,!0);for(let e of await Promise.all(f))e&&e.length>0&&d.push(...e);n(l.formValidating,!1)}n(l.validationResults,e=>({...e,[i]:d}))}},[])),m=i(o(async(e,t,n)=>{let r=e(l.options),i=e(l.values);r.isEqual(n,i)||t(l.values,n)},[])),h=o(async()=>{await Promise.all(Array.from(u??[],async e=>e()))},[u]);return{initializeField:d,uninitializeField:f,validate:p,validateFields:h,isSubmittable:i(o(e=>e(l.canSubmit),[])),change:m,submit:i(o(async(e,n)=>{if(!(e(l.submitting)||e(l.disabled))&&(n(l.submitAttempts,e=>e+1),await Promise.all([h(),p(e(l.values),t.SUBMIT)]),e(l.canSubmit))){n(l.submitting,!0);try{await e(l.options).onSubmit?.({get:e,set:n,atoms:l}),n(l.submitted,!0)}finally{n(l.submitting,!1)}}},[h,p])),reset:i(o((e,t)=>{t(l.values,r),t(l.validationResults,r),t(l.validationResultsFields,r),t(l.touchedFields,r),t(l.blurredFields,r),t(l.submitted,r),t(l.submitAttempts,r)},[l]))}};export{l as useFormActions};
|
|
2
2
|
//# sourceMappingURL=use-form-actions.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-form-actions.mjs","names":["validationKey","useFormActions","form","FormApi","useAtomCallback","useCallback","options","get","validators","cause","initializeValidators","previousValues","results","validator","nextValues","set","ValidationCause","messages","promises","result","isPromise","prev","values"],"sources":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"use-form-actions.mjs","names":["validationKey","useFormActions","form","FormApi","fieldValidations","use","FormFieldValidationsContext","initializeField","useAtomCallback","useCallback","uninitializeField","validate","options","get","validators","cause","initializeValidators","previousValues","results","validator","nextValues","set","ValidationCause","messages","promises","result","isPromise","prev","change","values","validateFields","validation","RESET"],"sources":[],"mappings":""}
|
package/dist/form/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utilities/is-validation-results.cjs"),
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./hooks/form-field-validations.cjs"),t=require("./utilities/is-validation-results.cjs"),n=require("./utilities/validators.cjs"),r=require("./utilities/server-errors.cjs"),i=require("./molecules/form-molecule.cjs"),a=require("./molecules/field-molecule.cjs");require("./hooks/index.cjs");const o=require("./hooks/use-field-actions.cjs"),s=require("./hooks/use-field-ref.cjs"),c=require("./hooks/use-form-actions.cjs");require("./molecules/index.cjs"),require("./providers/index.cjs");const l=require("./utilities/abort-error.cjs"),u=require("./providers/FieldProvider.cjs"),d=require("./providers/FormProvider.cjs"),f=require("./types.cjs");require("./utilities/index.cjs"),exports.AbortError=l.AbortError,exports.DEFAULT_FIELD_OPTIONS=a.DEFAULT_FIELD_OPTIONS,exports.DEFAULT_FORM_OPTIONS=i.DEFAULT_FORM_OPTIONS,exports.FieldApi=a.FieldApi,exports.FieldProvider=u.FieldProvider,exports.FormApi=i.FormApi,exports.FormFieldValidationsContext=e.FormFieldValidationsContext,exports.FormProvider=d.FormProvider,exports.SERVER_ERROR_CODE=r.SERVER_ERROR_CODE,exports.ValidationCause=f.ValidationCause,exports.applyServerErrors=r.applyServerErrors,exports.clearServerErrors=r.clearServerErrors,exports.hasServerErrors=r.hasServerErrors,exports.isValidationResults=t.isValidationResults,exports.requiredValidator=n.requiredValidator,exports.stripServerErrors=r.stripServerErrors,exports.useFieldActions=o.useFieldActions,exports.useFieldRef=s.useFieldRef,exports.useFormActions=c.useFormActions;
|
package/dist/form/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FieldValidation, FormFieldValidationsContext } from "./hooks/form-field-validations.cjs";
|
|
1
2
|
import "./hooks/index.cjs";
|
|
2
3
|
import { useFieldActions } from "./hooks/use-field-actions.cjs";
|
|
3
4
|
import { useFieldRef } from "./hooks/use-field-ref.cjs";
|
|
@@ -8,9 +9,10 @@ import { DEFAULT_FORM_OPTIONS, FormApi } from "./molecules/form-molecule.cjs";
|
|
|
8
9
|
import "./providers/index.cjs";
|
|
9
10
|
import { FieldProvider, FieldProviderOptions } from "./providers/FieldProvider.cjs";
|
|
10
11
|
import { FormProvider, FormProviderOptions } from "./providers/FormProvider.cjs";
|
|
11
|
-
import { CallbackContext, FieldAtoms, FieldChangeEventHandler, FieldOptions, FieldOptionsState, FieldStatus, FormAtoms, FormOptions, FormOptionsState, FormValuesState, InferFieldState, InferFormState, ValidationCause, ValidationResults, Validator } from "./types.cjs";
|
|
12
|
+
import { CallbackContext, FieldAtoms, FieldChangeEventHandler, FieldOptions, FieldOptionsState, FieldStatus, FormAtoms, FormErrors, FormOptions, FormOptionsState, FormValuesState, InferFieldState, InferFormState, ValidationCause, ValidationResults, Validator } from "./types.cjs";
|
|
12
13
|
import { AbortError } from "./utilities/abort-error.cjs";
|
|
13
14
|
import { isValidationResults } from "./utilities/is-validation-results.cjs";
|
|
15
|
+
import { SERVER_ERROR_CODE, applyServerErrors, clearServerErrors, hasServerErrors, stripServerErrors } from "./utilities/server-errors.cjs";
|
|
14
16
|
import { requiredValidator } from "./utilities/validators.cjs";
|
|
15
17
|
import "./utilities/index.cjs";
|
|
16
|
-
export { AbortError, CallbackContext, DEFAULT_FIELD_OPTIONS, DEFAULT_FORM_OPTIONS, FieldApi, FieldAtoms, FieldChangeEventHandler, FieldOptions, FieldOptionsState, FieldProvider, FieldProviderOptions, FieldStatus, FormApi, FormAtoms, FormOptions, FormOptionsState, FormProvider, FormProviderOptions, FormValuesState, InferFieldState, InferFormState, ValidationCause, ValidationResults, Validator, isValidationResults, requiredValidator, useFieldActions, useFieldRef, useFormActions };
|
|
18
|
+
export { AbortError, CallbackContext, DEFAULT_FIELD_OPTIONS, DEFAULT_FORM_OPTIONS, FieldApi, FieldAtoms, FieldChangeEventHandler, FieldOptions, FieldOptionsState, FieldProvider, FieldProviderOptions, FieldStatus, FieldValidation, FormApi, FormAtoms, FormErrors, FormFieldValidationsContext, FormOptions, FormOptionsState, FormProvider, FormProviderOptions, FormValuesState, InferFieldState, InferFormState, SERVER_ERROR_CODE, ValidationCause, ValidationResults, Validator, applyServerErrors, clearServerErrors, hasServerErrors, isValidationResults, requiredValidator, stripServerErrors, useFieldActions, useFieldRef, useFormActions };
|
package/dist/form/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FieldValidation, FormFieldValidationsContext } from "./hooks/form-field-validations.mjs";
|
|
1
2
|
import "./hooks/index.mjs";
|
|
2
3
|
import { useFieldActions } from "./hooks/use-field-actions.mjs";
|
|
3
4
|
import { useFieldRef } from "./hooks/use-field-ref.mjs";
|
|
@@ -8,9 +9,10 @@ import { DEFAULT_FORM_OPTIONS, FormApi } from "./molecules/form-molecule.mjs";
|
|
|
8
9
|
import "./providers/index.mjs";
|
|
9
10
|
import { FieldProvider, FieldProviderOptions } from "./providers/FieldProvider.mjs";
|
|
10
11
|
import { FormProvider, FormProviderOptions } from "./providers/FormProvider.mjs";
|
|
11
|
-
import { CallbackContext, FieldAtoms, FieldChangeEventHandler, FieldOptions, FieldOptionsState, FieldStatus, FormAtoms, FormOptions, FormOptionsState, FormValuesState, InferFieldState, InferFormState, ValidationCause, ValidationResults, Validator } from "./types.mjs";
|
|
12
|
+
import { CallbackContext, FieldAtoms, FieldChangeEventHandler, FieldOptions, FieldOptionsState, FieldStatus, FormAtoms, FormErrors, FormOptions, FormOptionsState, FormValuesState, InferFieldState, InferFormState, ValidationCause, ValidationResults, Validator } from "./types.mjs";
|
|
12
13
|
import { AbortError } from "./utilities/abort-error.mjs";
|
|
13
14
|
import { isValidationResults } from "./utilities/is-validation-results.mjs";
|
|
15
|
+
import { SERVER_ERROR_CODE, applyServerErrors, clearServerErrors, hasServerErrors, stripServerErrors } from "./utilities/server-errors.mjs";
|
|
14
16
|
import { requiredValidator } from "./utilities/validators.mjs";
|
|
15
17
|
import "./utilities/index.mjs";
|
|
16
|
-
export { AbortError, CallbackContext, DEFAULT_FIELD_OPTIONS, DEFAULT_FORM_OPTIONS, FieldApi, FieldAtoms, FieldChangeEventHandler, FieldOptions, FieldOptionsState, FieldProvider, FieldProviderOptions, FieldStatus, FormApi, FormAtoms, FormOptions, FormOptionsState, FormProvider, FormProviderOptions, FormValuesState, InferFieldState, InferFormState, ValidationCause, ValidationResults, Validator, isValidationResults, requiredValidator, useFieldActions, useFieldRef, useFormActions };
|
|
18
|
+
export { AbortError, CallbackContext, DEFAULT_FIELD_OPTIONS, DEFAULT_FORM_OPTIONS, FieldApi, FieldAtoms, FieldChangeEventHandler, FieldOptions, FieldOptionsState, FieldProvider, FieldProviderOptions, FieldStatus, FieldValidation, FormApi, FormAtoms, FormErrors, FormFieldValidationsContext, FormOptions, FormOptionsState, FormProvider, FormProviderOptions, FormValuesState, InferFieldState, InferFormState, SERVER_ERROR_CODE, ValidationCause, ValidationResults, Validator, applyServerErrors, clearServerErrors, hasServerErrors, isValidationResults, requiredValidator, stripServerErrors, useFieldActions, useFieldRef, useFormActions };
|
package/dist/form/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{FormFieldValidationsContext as e}from"./hooks/form-field-validations.mjs";import{isValidationResults as t}from"./utilities/is-validation-results.mjs";import{requiredValidator as n}from"./utilities/validators.mjs";import{SERVER_ERROR_CODE as r,applyServerErrors as i,clearServerErrors as a,hasServerErrors as o,stripServerErrors as s}from"./utilities/server-errors.mjs";import{DEFAULT_FORM_OPTIONS as c,FormApi as l}from"./molecules/form-molecule.mjs";import{DEFAULT_FIELD_OPTIONS as u,FieldApi as d}from"./molecules/field-molecule.mjs";import"./hooks/index.mjs";import{useFieldActions as f}from"./hooks/use-field-actions.mjs";import{useFieldRef as p}from"./hooks/use-field-ref.mjs";import{useFormActions as m}from"./hooks/use-form-actions.mjs";import"./molecules/index.mjs";import"./providers/index.mjs";import{AbortError as h}from"./utilities/abort-error.mjs";import{FieldProvider as g}from"./providers/FieldProvider.mjs";import{FormProvider as _}from"./providers/FormProvider.mjs";import{ValidationCause as v}from"./types.mjs";import"./utilities/index.mjs";export{h as AbortError,u as DEFAULT_FIELD_OPTIONS,c as DEFAULT_FORM_OPTIONS,d as FieldApi,g as FieldProvider,l as FormApi,e as FormFieldValidationsContext,_ as FormProvider,r as SERVER_ERROR_CODE,v as ValidationCause,i as applyServerErrors,a as clearServerErrors,o as hasServerErrors,t as isValidationResults,n as requiredValidator,s as stripServerErrors,f as useFieldActions,p as useFieldRef,m as useFormActions};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../../base/utilities/create-molecule.cjs");require("../../base/index.cjs");const t=require("../atoms/atom-with-field.cjs"),n=require("../atoms/atom-with-messages.cjs"),r=require("../utilities/validators.cjs"),i=require("./form-molecule.cjs");let ee=require("@stryke/type-checks/is-function"),a=require("jotai/utils"),o=require("@stryke/helpers/is-equal"),s=require("jotai"),
|
|
1
|
+
const e=require("../../base/utilities/create-molecule.cjs");require("../../base/index.cjs");const t=require("../atoms/atom-with-field.cjs"),n=require("../atoms/atom-with-messages.cjs"),r=require("../utilities/validators.cjs"),i=require("./form-molecule.cjs");let ee=require("@stryke/type-checks/is-function"),a=require("jotai/utils"),o=require("@stryke/helpers/is-equal"),s=require("jotai"),te=require("@stryke/type-checks/is-string"),c=require("@stryke/helpers/deep-merge"),l=require("@stryke/helpers/get-field"),u=require("@stryke/helpers/to-path"),d=require("@stryke/type-checks/is-set"),f=require("jotai-optics");const p={theme:`base`,size:`md`,debounceMs:100,isEqual:o.isEqual,required:!1,disabled:!1,readOnly:!1,clearable:!1,initialValue:null},m=e.createMoleculeApi(o=>{let m=e.use(i.FormApi.Scope),h=(0,s.atom)(()=>m),g=e.use(i.FormApi.Molecule),_=(0,s.atom)(p),v=(0,s.atom)(e=>{let t=e(g.options),n=e(_),i=(0,c.deepMerge)(t.defaultFieldOptions,n);return{...i,validate:{...i.validate,onBlur:[...i.required?[r.requiredValidator]:[],...i.validate?.onBlur??[]]}}},(e,t,n)=>{let r={};r=(0,ee.isFunction)(n)?n(e(_)):n===a.RESET?{}:n,t(_,(0,c.deepMerge)(p,r))}),y=`${m}-`,b=(0,u.toPath)(o.startsWith(y)?o.slice(y.length):o.includes(`-`)?o.slice(o.indexOf(`-`)+1):o),x=(0,s.atom)(()=>b),ne=(0,s.atom)(e=>e(x).slice(-1)[0]),re=(0,f.focusAtom)(g.focusedFields,e=>e.path(...b)),S=(0,f.focusAtom)(g.requiredFields,e=>e.path(...b)),C=(0,f.focusAtom)(g.disabledFields,e=>e.path(...b)),w=(0,f.focusAtom)(g.readOnlyFields,e=>e.path(...b)),ie=(0,s.atom)(e=>e(S)??e(v).required,(e,t,n)=>{t(S,n)}),T=(0,s.atom)(e=>e(C)??e(v).disabled,(e,t,n)=>{t(C,n)}),ae=(0,s.atom)(e=>e(w)??e(v).readOnly,(e,t,n)=>{t(w,n)}),E=(0,s.atom)(e=>e(v).clearable),D=(0,f.focusAtom)(g.touchedFields,e=>e.path(...b)),O=(0,f.focusAtom)(g.blurredFields,e=>e.path(...b)),oe=(0,f.focusAtom)(g.validatingFields,e=>e.path(...b)),k=(0,f.focusAtom)(g.validationResultsFields,e=>e.path(...b)),A=(0,f.focusAtom)(g.tabIndexes,e=>e.path(...b)),j=(0,f.focusAtom)(g.refs,e=>e.path(...b)),M=(0,f.focusAtom)(g.initialValues,e=>e.path(...b)),N=(0,f.focusAtom)(g.values,e=>e.path(...b)),P=(0,s.atom)(e=>e(v).isEqual(e(N),e(M))),F=(0,s.atom)(e=>!!e(v).showErrorsBeforeBlur||!!e(O)||e(g.submitAttempts)>0),I=n.atomWithFieldsMessageTypes(k,`danger`),L=(0,s.atom)(e=>e(F)?e(I):[]),R=n.atomWithFieldsMessageTypes(k,`warning`),z=n.atomWithFieldsMessageTypes(k,`info`),B=n.atomWithFieldsMessageTypes(k,`discovery`),V=n.atomWithFieldsMessageTypes(k,`success`),H=n.atomWithFieldsMessageTypes(k,`success`),U=n.atomWithFieldsMessageTypes(k,`danger`),W=n.atomWithFieldsMessageList(k,`danger`),G=(0,s.atom)(e=>e(F)?e(W):[]),K=n.atomWithFieldsMessageList(k,`warning`),q=n.atomWithFieldsMessageList(k,`info`),J=n.atomWithFieldsMessageList(k,`discovery`),Y=n.atomWithFieldsMessageList(k,`success`),X=n.atomWithFieldsMessageList(k,`success`),Z=n.atomWithFieldsMessageList(k,`danger`),Q=(0,s.atom)(e=>e(G).length>0),se=(0,s.atom)(e=>!e(Q)),ce=(0,s.atom)(e=>{let t=e(v),n=e(N),r;return r=t?.format?t.format(n):n,(0,d.isSet)(r)?(0,te.isString)(r)?r:String(r):``}),$=t.atomWithFieldItems(v,N,T),le=(0,a.splitAtom)($),ue=(0,a.atomWithDefault)(e=>e(v).size??`md`);return{options:v,form:h,name:ne,path:x,initialValue:M,previousValue:(0,s.atom)(e=>{let t=e(g.previousValues);return(0,l.getField)(t,e(x).join(`.`))??null}),value:N,formattedValue:ce,focused:re,required:ie,disabled:T,readOnly:ae,clearable:E,touched:D,blurred:O,validating:oe,validationResults:k,tabIndex:A,ref:j,pristine:(0,s.atom)(e=>!e(P)),dirty:P,items:$,itemsAtoms:le,size:ue,errors:L,warnings:R,info:z,discovery:B,success:V,positive:H,negative:U,dangerMessages:G,warningMessages:K,infoMessages:q,discoveryMessages:J,successMessages:Y,positiveMessages:X,negativeMessages:Z,theme:n.atomWithTheme(v,G,K,q,J,Y,X,Z),messages:n.atomWithMessages(G,K,q,J,Y,X,Z),invalid:Q,valid:se}},{type:`field`});exports.DEFAULT_FIELD_OPTIONS=p,exports.FieldApi=m;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createMoleculeApi as e,use as t}from"../../base/utilities/create-molecule.mjs";import"../../base/index.mjs";import{atomWithFieldItems as n}from"../atoms/atom-with-field.mjs";import{atomWithFieldsMessageList as r,atomWithFieldsMessageTypes as i,atomWithMessages as a,atomWithTheme as ee}from"../atoms/atom-with-messages.mjs";import{requiredValidator as te}from"../utilities/validators.mjs";import{FormApi as o}from"./form-molecule.mjs";import{isFunction as s}from"@stryke/type-checks/is-function";import{RESET as c,atomWithDefault as l,splitAtom as ne}from"jotai/utils";import{isEqual as u}from"@stryke/helpers/is-equal";import{atom as d}from"jotai";import{isString as f}from"@stryke/type-checks/is-string";import{deepMerge as p}from"@stryke/helpers/deep-merge";import{getField as re}from"@stryke/helpers/get-field";import{toPath as m}from"@stryke/helpers/to-path";import{isSet as ie}from"@stryke/type-checks/is-set";import{focusAtom as h}from"jotai-optics";const g={theme:`base`,size:`md`,debounceMs:100,isEqual:u,required:!1,disabled:!1,readOnly:!1,clearable:!1,initialValue:null},_=e(e=>{let u=t(o.Scope),_=d(()=>u),v=t(o.Molecule),y=d(g),b=d(e=>{let t=e(v.options),n=e(y),r=p(t.defaultFieldOptions,n);return
|
|
1
|
+
import{createMoleculeApi as e,use as t}from"../../base/utilities/create-molecule.mjs";import"../../base/index.mjs";import{atomWithFieldItems as n}from"../atoms/atom-with-field.mjs";import{atomWithFieldsMessageList as r,atomWithFieldsMessageTypes as i,atomWithMessages as a,atomWithTheme as ee}from"../atoms/atom-with-messages.mjs";import{requiredValidator as te}from"../utilities/validators.mjs";import{FormApi as o}from"./form-molecule.mjs";import{isFunction as s}from"@stryke/type-checks/is-function";import{RESET as c,atomWithDefault as l,splitAtom as ne}from"jotai/utils";import{isEqual as u}from"@stryke/helpers/is-equal";import{atom as d}from"jotai";import{isString as f}from"@stryke/type-checks/is-string";import{deepMerge as p}from"@stryke/helpers/deep-merge";import{getField as re}from"@stryke/helpers/get-field";import{toPath as m}from"@stryke/helpers/to-path";import{isSet as ie}from"@stryke/type-checks/is-set";import{focusAtom as h}from"jotai-optics";const g={theme:`base`,size:`md`,debounceMs:100,isEqual:u,required:!1,disabled:!1,readOnly:!1,clearable:!1,initialValue:null},_=e(e=>{let u=t(o.Scope),_=d(()=>u),v=t(o.Molecule),y=d(g),b=d(e=>{let t=e(v.options),n=e(y),r=p(t.defaultFieldOptions,n);return{...r,validate:{...r.validate,onBlur:[...r.required?[te]:[],...r.validate?.onBlur??[]]}}},(e,t,n)=>{let r={};r=s(n)?n(e(y)):n===c?{}:n,t(y,p(g,r))}),x=`${u}-`,S=m(e.startsWith(x)?e.slice(x.length):e.includes(`-`)?e.slice(e.indexOf(`-`)+1):e),C=d(()=>S),w=d(e=>e(C).slice(-1)[0]),T=h(v.focusedFields,e=>e.path(...S)),E=h(v.requiredFields,e=>e.path(...S)),D=h(v.disabledFields,e=>e.path(...S)),O=h(v.readOnlyFields,e=>e.path(...S)),ae=d(e=>e(E)??e(b).required,(e,t,n)=>{t(E,n)}),k=d(e=>e(D)??e(b).disabled,(e,t,n)=>{t(D,n)}),oe=d(e=>e(O)??e(b).readOnly,(e,t,n)=>{t(O,n)}),se=d(e=>e(b).clearable),ce=h(v.touchedFields,e=>e.path(...S)),A=h(v.blurredFields,e=>e.path(...S)),j=h(v.validatingFields,e=>e.path(...S)),M=h(v.validationResultsFields,e=>e.path(...S)),N=h(v.tabIndexes,e=>e.path(...S)),P=h(v.refs,e=>e.path(...S)),F=h(v.initialValues,e=>e.path(...S)),I=h(v.values,e=>e.path(...S)),L=d(e=>e(b).isEqual(e(I),e(F))),R=d(e=>!!e(b).showErrorsBeforeBlur||!!e(A)||e(v.submitAttempts)>0),z=i(M,`danger`),B=d(e=>e(R)?e(z):[]),V=i(M,`warning`),H=i(M,`info`),U=i(M,`discovery`),W=i(M,`success`),le=i(M,`success`),ue=i(M,`danger`),de=r(M,`danger`),G=d(e=>e(R)?e(de):[]),K=r(M,`warning`),q=r(M,`info`),J=r(M,`discovery`),Y=r(M,`success`),X=r(M,`success`),Z=r(M,`danger`),Q=d(e=>e(G).length>0),fe=d(e=>!e(Q)),pe=d(e=>{let t=e(b),n=e(I),r;return r=t?.format?t.format(n):n,ie(r)?f(r)?r:String(r):``}),$=n(b,I,k),me=ne($),he=l(e=>e(b).size??`md`);return{options:b,form:_,name:w,path:C,initialValue:F,previousValue:d(e=>{let t=e(v.previousValues);return re(t,e(C).join(`.`))??null}),value:I,formattedValue:pe,focused:T,required:ae,disabled:k,readOnly:oe,clearable:se,touched:ce,blurred:A,validating:j,validationResults:M,tabIndex:N,ref:P,pristine:d(e=>!e(L)),dirty:L,items:$,itemsAtoms:me,size:he,errors:B,warnings:V,info:H,discovery:U,success:W,positive:le,negative:ue,dangerMessages:G,warningMessages:K,infoMessages:q,discoveryMessages:J,successMessages:Y,positiveMessages:X,negativeMessages:Z,theme:ee(b,G,K,q,J,Y,X,Z),messages:a(G,K,q,J,Y,X,Z),invalid:Q,valid:fe}},{type:`field`});export{g as DEFAULT_FIELD_OPTIONS,_ as FieldApi};
|
|
2
2
|
//# sourceMappingURL=field-molecule.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../../base/utilities/create-molecule.cjs"),t=require("../atoms/atom-with-messages.cjs");let
|
|
1
|
+
const e=require("../../base/utilities/create-molecule.cjs"),t=require("../atoms/atom-with-messages.cjs"),n=require("../utilities/server-errors.cjs");let r=require("@stryke/type-checks/is-function"),i=require("jotai/utils"),a=require("@stryke/helpers/is-equal"),o=require("jotai"),s=require("@stryke/type-checks/is-string"),c=require("@stryke/helpers/deep-merge"),l=require("@stryke/helpers/flatten-object"),u=require("@stryke/helpers/set-field"),d=require("@stryke/type-checks/is-number");const f={theme:`base`,debounceMs:100,isEqual:a.isEqual,disabled:!1,initialValues:{},defaultFieldOptions:{}},p=e.createMoleculeApi(e=>{let a=(0,i.atomWithReset)(f),p=(0,o.atom)(e=>e(a),(e,t,n)=>{let o={};o=(0,r.isFunction)(n)?n(e(a)):n===i.RESET?{}:n,t(a,(0,c.deepMerge)(f,o))}),m=(0,o.atom)(e),h=(0,i.atomWithDefault)(e=>!!e(p).disabled),g=(0,i.atomWithReset)(!1),_=(0,i.atomWithReset)({}),ee=(0,o.atom)(e=>e(_),(e,t,n)=>{}),v=(0,i.atomWithDefault)(e=>e(p).initialValues),y=(0,i.atomWithDefault)(e=>e(p).initialValues),b=(0,o.atom)(e=>e(y),(e,t,n)=>{let i={};n&&(i=(0,r.isFunction)(n)?n(e(y)):n),t(_,e(y)),t(y,i)}),x=(0,i.atomWithReset)({initialize:[],change:[],blur:[],submit:[],server:[]}),S=(0,i.atomWithReset)(!1),C=(0,i.atomWithReset)(!1),w=(0,i.atomWithReset)(0),T=(0,i.atomWithReset)({}),E=(0,i.atomWithReset)({}),D=(0,i.atomWithReset)({}),O=(0,i.atomWithReset)({}),k=(0,i.atomWithReset)({}),A=(0,i.atomWithReset)({}),j=(0,i.atomWithReset)({}),M=(0,i.atomWithReset)({}),te=(0,i.atomWithReset)({}),N=(0,i.atomWithReset)({}),ne=(0,o.atom)(e=>e(N),(e,t,n)=>{let a={};if((0,r.isFunction)(n))a=n(e(N));else if(n===i.RESET)a={};else{let t=e(N);if(`field`in n&&n.field&&(0,s.isString)(n.field)){let e=n.tabIndex;if(!(0,d.isNumber)(e)||e>-1){let n=(0,l.flattenObject)(t),r=-1;for(let e in n)(0,d.isNumber)(n[e])&&n[e]>r&&(r=n[e]);e=r+1}a=(0,u.setField)(t,n.field,e)}else a=n}t(N,a)}),P=(0,o.atom)(e=>e(p).isEqual(e(b),e(v))),F=(0,o.atom)(e=>!e(P)),I=(0,o.atom)(e=>{let t=(0,l.flattenObject)(e(A));return Object.keys(t).some(e=>t[e])}),L=(0,o.atom)(e=>{let t=(0,l.flattenObject)(e(k));return Object.keys(t).some(e=>t[e])}),R=(0,o.atom)(e=>{if(e(g))return!0;let t=(0,l.flattenObject)(e(j));return Object.keys(t).some(e=>t[e])}),z=t.atomWithMessageTypes(x,`danger`),B=t.atomWithMessageTypes(x,`warning`),V=t.atomWithMessageTypes(x,`info`),H=t.atomWithMessageTypes(x,`discovery`),U=t.atomWithMessageTypes(x,`success`),W=t.atomWithMessageTypes(x,`success`),G=t.atomWithMessageTypes(x,`danger`),K=(0,o.atom)(e=>e(z).length>0),q=t.atomWithFieldsMessageTypes(M,`danger`),J=t.atomWithFieldsMessageTypes(M,`warning`),Y=t.atomWithFieldsMessageTypes(M,`info`),X=t.atomWithFieldsMessageTypes(M,`discovery`),re=t.atomWithFieldsMessageTypes(M,`success`),Z=t.atomWithFieldsMessageList(M,`danger`),ie=t.atomWithFieldsMessageList(M,`warning`),ae=t.atomWithFieldsMessageList(M,`info`),oe=t.atomWithFieldsMessageList(M,`discovery`),se=t.atomWithFieldsMessageList(M,`success`),Q=(0,o.atom)(e=>e(Z).length>0||e(K)),ce=(0,o.atom)(e=>!e(Q)),le=t.atomWithFieldsMessageList((0,o.atom)(e=>n.stripServerErrors(e(M))),`danger`),$=(0,o.atom)(e=>e(le).length===0&&!e(K)&&!e(R)&&!e(S)&&!e(h));return{options:p,name:m,disabled:h,formValidating:g,validationResults:x,submitting:S,submitted:C,submitAttempts:w,focusedFields:T,requiredFields:E,disabledFields:D,readOnlyFields:O,touchedFields:k,blurredFields:A,validatingFields:j,validationResultsFields:M,tabIndexes:ne,refs:te,dirty:P,pristine:F,blurred:I,touched:L,validating:R,previousValues:ee,initialValues:v,values:b,dangerMessages:z,warningMessages:B,infoMessages:V,discoveryMessages:H,successMessages:U,positiveMessages:W,negativeMessages:G,messages:t.atomWithMessages(z,B,V,H,U,W,G),dangerFields:q,warningFields:J,infoFields:Y,discoveryFields:X,successFields:re,fieldDangerMessages:Z,fieldWarningMessages:ie,fieldInfoMessages:ae,fieldHelpMessages:oe,fieldsSuccessMessages:se,valid:ce,invalid:Q,theme:t.atomWithTheme(p,z,B,V,H,U,W,G),canSubmit:$}},{type:`form`});exports.DEFAULT_FORM_OPTIONS=f,exports.FormApi=p;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-molecule.d.cts","names":["_$_____0.MoleculeApi"],"sources":["../../../src/form/molecules/form-molecule.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"form-molecule.d.cts","names":["_$_____0.MoleculeApi"],"sources":["../../../src/form/molecules/form-molecule.ts"],"mappings":";;;cA+Ca,sBAAsB;cAStB,SAAOA,YAAA,UAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createMoleculeApi as e}from"../../base/utilities/create-molecule.mjs";import{atomWithFieldsMessageList as t,atomWithFieldsMessageTypes as n,atomWithMessageTypes as r,atomWithMessages as i,atomWithTheme as
|
|
1
|
+
import{createMoleculeApi as e}from"../../base/utilities/create-molecule.mjs";import{atomWithFieldsMessageList as t,atomWithFieldsMessageTypes as n,atomWithMessageTypes as r,atomWithMessages as i,atomWithTheme as ee}from"../atoms/atom-with-messages.mjs";import{stripServerErrors as a}from"../utilities/server-errors.mjs";import{isFunction as o}from"@stryke/type-checks/is-function";import{RESET as s,atomWithDefault as c,atomWithReset as l}from"jotai/utils";import{isEqual as u}from"@stryke/helpers/is-equal";import{atom as d}from"jotai";import{isString as te}from"@stryke/type-checks/is-string";import{deepMerge as ne}from"@stryke/helpers/deep-merge";import{flattenObject as f}from"@stryke/helpers/flatten-object";import{setField as p}from"@stryke/helpers/set-field";import{isNumber as m}from"@stryke/type-checks/is-number";const h={theme:`base`,debounceMs:100,isEqual:u,disabled:!1,initialValues:{},defaultFieldOptions:{}},g=e(e=>{let u=l(h),g=d(e=>e(u),(e,t,n)=>{let r={};r=o(n)?n(e(u)):n===s?{}:n,t(u,ne(h,r))}),_=d(e),v=c(e=>!!e(g).disabled),y=l(!1),b=l({}),x=d(e=>e(b),(e,t,n)=>{}),S=c(e=>e(g).initialValues),C=c(e=>e(g).initialValues),w=d(e=>e(C),(e,t,n)=>{let r={};n&&(r=o(n)?n(e(C)):n),t(b,e(C)),t(C,r)}),T=l({initialize:[],change:[],blur:[],submit:[],server:[]}),E=l(!1),re=l(!1),D=l(0),O=l({}),k=l({}),A=l({}),j=l({}),M=l({}),N=l({}),P=l({}),F=l({}),I=l({}),L=l({}),R=d(e=>e(L),(e,t,n)=>{let r={};if(o(n))r=n(e(L));else if(n===s)r={};else{let t=e(L);if(`field`in n&&n.field&&te(n.field)){let e=n.tabIndex;if(!m(e)||e>-1){let n=f(t),r=-1;for(let e in n)m(n[e])&&n[e]>r&&(r=n[e]);e=r+1}r=p(t,n.field,e)}else r=n}t(L,r)}),z=d(e=>e(g).isEqual(e(w),e(S))),B=d(e=>!e(z)),V=d(e=>{let t=f(e(N));return Object.keys(t).some(e=>t[e])}),H=d(e=>{let t=f(e(M));return Object.keys(t).some(e=>t[e])}),U=d(e=>{if(e(y))return!0;let t=f(e(P));return Object.keys(t).some(e=>t[e])}),W=r(T,`danger`),G=r(T,`warning`),K=r(T,`info`),q=r(T,`discovery`),J=r(T,`success`),Y=r(T,`success`),X=r(T,`danger`),Z=d(e=>e(W).length>0),ie=n(F,`danger`),ae=n(F,`warning`),oe=n(F,`info`),se=n(F,`discovery`),ce=n(F,`success`),Q=t(F,`danger`),le=t(F,`warning`),ue=t(F,`info`),de=t(F,`discovery`),fe=t(F,`success`),$=d(e=>e(Q).length>0||e(Z)),pe=d(e=>!e($)),me=t(d(e=>a(e(F))),`danger`),he=d(e=>e(me).length===0&&!e(Z)&&!e(U)&&!e(E)&&!e(v));return{options:g,name:_,disabled:v,formValidating:y,validationResults:T,submitting:E,submitted:re,submitAttempts:D,focusedFields:O,requiredFields:k,disabledFields:A,readOnlyFields:j,touchedFields:M,blurredFields:N,validatingFields:P,validationResultsFields:F,tabIndexes:R,refs:I,dirty:z,pristine:B,blurred:V,touched:H,validating:U,previousValues:x,initialValues:S,values:w,dangerMessages:W,warningMessages:G,infoMessages:K,discoveryMessages:q,successMessages:J,positiveMessages:Y,negativeMessages:X,messages:i(W,G,K,q,J,Y,X),dangerFields:ie,warningFields:ae,infoFields:oe,discoveryFields:se,successFields:ce,fieldDangerMessages:Q,fieldWarningMessages:le,fieldInfoMessages:ue,fieldHelpMessages:de,fieldsSuccessMessages:fe,valid:pe,invalid:$,theme:ee(g,W,G,K,q,J,Y,X),canSubmit:he}},{type:`form`});export{h as DEFAULT_FORM_OPTIONS,g as FormApi};
|
|
2
2
|
//# sourceMappingURL=form-molecule.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-molecule.mjs","names":["DEFAULT_FORM_OPTIONS","FormApi","createMoleculeApi","optionsBaseAtom","atomWithReset","optionsAtom","atom","get","nextValue","isFunction","update","RESET","set","deepMerge","nameAtom","scope","disabledAtom","atomWithDefault","formValidatingAtom","previousValuesBaseAtom","previousValuesAtom","initialValuesAtom","valuesBaseAtom","valuesAtom","validationResultsAtom","submittingAtom","submittedAtom","submitAttemptsAtom","focusedFieldsAtom","requiredFieldsAtom","disabledFieldsAtom","readOnlyFieldsAtom","touchedFieldsAtom","blurredFieldsAtom","validatingFieldsAtom","validationResultsFieldsAtom","refsAtom","tabIndexesBaseAtom","tabIndexesAtom","tabIndexes","isString","tabIndex","isNumber","flat","flattenObject","lastIndex","key","setField","dirtyAtom","pristineAtom","blurredAtom","blurredFields","touchedAtom","touchedFields","validatingAtom","validatingFields","formErrorsAtom","atomWithMessageTypes","formWarningsAtom","formInfoAtom","formHelpAtom","formSuccessesAtom","formPositivesAtom","formNegativesAtom","isFormInvalidAtom","errorFieldsAtom","atomWithFieldsMessageTypes","warningFieldsAtom","infoFieldsAtom","helpFieldsAtom","successFieldsAtom","fieldErrorMessagesAtom","atomWithFieldsMessageList","fieldWarningMessagesAtom","fieldInfoMessagesAtom","fieldHelpMessagesAtom","fieldsSuccessMessagesAtom","invalidAtom","validAtom","canSubmitAtom","atomWithMessages","atomWithTheme"],"sources":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"form-molecule.mjs","names":["DEFAULT_FORM_OPTIONS","FormApi","createMoleculeApi","optionsBaseAtom","atomWithReset","optionsAtom","atom","get","nextValue","isFunction","update","RESET","set","deepMerge","nameAtom","scope","disabledAtom","atomWithDefault","formValidatingAtom","previousValuesBaseAtom","previousValuesAtom","initialValuesAtom","valuesBaseAtom","valuesAtom","validationResultsAtom","submittingAtom","submittedAtom","submitAttemptsAtom","focusedFieldsAtom","requiredFieldsAtom","disabledFieldsAtom","readOnlyFieldsAtom","touchedFieldsAtom","blurredFieldsAtom","validatingFieldsAtom","validationResultsFieldsAtom","refsAtom","tabIndexesBaseAtom","tabIndexesAtom","tabIndexes","isString","tabIndex","isNumber","flat","flattenObject","lastIndex","key","setField","dirtyAtom","pristineAtom","blurredAtom","blurredFields","touchedAtom","touchedFields","validatingAtom","validatingFields","formErrorsAtom","atomWithMessageTypes","formWarningsAtom","formInfoAtom","formHelpAtom","formSuccessesAtom","formPositivesAtom","formNegativesAtom","isFormInvalidAtom","errorFieldsAtom","atomWithFieldsMessageTypes","warningFieldsAtom","infoFieldsAtom","helpFieldsAtom","successFieldsAtom","fieldErrorMessagesAtom","atomWithFieldsMessageList","fieldWarningMessagesAtom","fieldInfoMessagesAtom","fieldHelpMessagesAtom","fieldsSuccessMessagesAtom","invalidAtom","validAtom","blockingFieldErrorMessagesAtom","stripServerErrors","canSubmitAtom","atomWithMessages","atomWithTheme"],"sources":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../../base/hooks/use-atom-effect.cjs"),t=require("../hooks/use-field-actions.cjs"),
|
|
1
|
+
const e=require("../../base/hooks/use-atom-effect.cjs"),t=require("../hooks/form-field-validations.cjs"),n=require("../hooks/use-field-actions.cjs"),r=require("../molecules/field-molecule.cjs"),i=require("../molecules/form-molecule.cjs"),a=require("../types.cjs"),o=require("../utilities/abort-error.cjs");let s=require("jotai/utils"),c=require("react"),l=require("react/jsx-runtime"),u=require("@tamagui/core"),d=require("@stryke/async"),f=require("@stryke/type-checks/is-boolean");function p(l){let{validate:u}=n.useFieldActions(),p=i.FormApi.useMolecule(),m=r.FieldApi.useMolecule(),h=(0,c.use)(t.FormFieldValidationsContext),g=(0,s.useAtomCallback)((0,c.useCallback)(async e=>{if(e(m.disabled))return;let t=e(m.value);await Promise.all([u(t,a.ValidationCause.CHANGE),u(t,a.ValidationCause.BLUR),u(t,a.ValidationCause.SUBMIT)])},[m,u]));return(0,c.useEffect)(()=>{if(h)return h.add(g),()=>{h.delete(g)}},[h,g]),e.useAtomEffect((e,t)=>{let n=e(m.value),r=new AbortController;return(async()=>{try{let i=e(m.options);await(0,d.delay)(i.debounceMs),r.signal.throwIfAborted(),i.onChange&&(await Promise.resolve(i.onChange({get:e,set:t,atoms:m})),r.signal.throwIfAborted());let o=[];o.push(u(n,a.ValidationCause.CHANGE)),e(m.blurred)&&o.push(u(n,a.ValidationCause.BLUR)),e(p.submitAttempts)>0&&o.push(u(n,a.ValidationCause.SUBMIT)),await Promise.all(o)}catch(e){e instanceof o.AbortError}})(),()=>{r.abort(new o.AbortError)}},[u]),e.useAtomEffect((e,t)=>{let n=e(m.focused),r=new AbortController;return(async()=>{try{let i=e(m.options);if(await(0,d.delay)(i.debounceMs),r.signal.throwIfAborted(),(0,f.isBoolean)(n)){if(e(m.touched)||t(m.touched,!0),n)i.onFocus&&(await Promise.resolve(i.onFocus({get:e,set:t,atoms:m})),r.signal.throwIfAborted());else{i.onBlur&&(await Promise.resolve(i.onBlur({get:e,set:t,atoms:m})),r.signal.throwIfAborted());let n=e(m.value),o=[];o.push(u(n,a.ValidationCause.BLUR)),e(p.submitAttempts)>0&&o.push(u(n,a.ValidationCause.SUBMIT)),await Promise.all(o)}}}catch(e){e instanceof o.AbortError}})(),()=>{r.abort(new o.AbortError)}},[u]),null}function m({children:e,name:t,...n}){let a=i.FormApi.use().name.get(),o=(0,u.useThemeName)();return/* @__PURE__ */ (0,l.jsxs)(r.FieldApi.Provider,{scope:`${a}-${t}`,initialState:{options:{theme:o,...n}},children:[/* @__PURE__ */ (0,l.jsx)(p,{...n}),e]})}exports.FieldProvider=m;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldProvider.d.cts","names":[],"sources":["../../../src/form/providers/FieldProvider.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"FieldProvider.d.cts","names":[],"sources":["../../../src/form/providers/FieldProvider.tsx"],"mappings":";;KAuUY,qBAAqB,qBAAqB,kBACpD,aAAa;EAAiB;;iBAGhB,cAAc,qBAC5B,UACA,SACG,SACF,qBAAqB,+BAAY,IAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useAtomEffect as e}from"../../base/hooks/use-atom-effect.mjs";import{
|
|
1
|
+
import{useAtomEffect as e}from"../../base/hooks/use-atom-effect.mjs";import{FormFieldValidationsContext as t}from"../hooks/form-field-validations.mjs";import{useFieldActions as n}from"../hooks/use-field-actions.mjs";import{FieldApi as r}from"../molecules/field-molecule.mjs";import{FormApi as i}from"../molecules/form-molecule.mjs";import{ValidationCause as a}from"../types.mjs";import{AbortError as o}from"../utilities/abort-error.mjs";import{useAtomCallback as s}from"jotai/utils";import{use as c,useCallback as l,useEffect as u}from"react";import{jsx as d,jsxs as f}from"react/jsx-runtime";import{useThemeName as p}from"@tamagui/core";import{delay as m}from"@stryke/async";import{isBoolean as h}from"@stryke/type-checks/is-boolean";function g(d){let{validate:f}=n(),p=i.useMolecule(),g=r.useMolecule(),_=c(t),v=s(l(async e=>{if(e(g.disabled))return;let t=e(g.value);await Promise.all([f(t,a.CHANGE),f(t,a.BLUR),f(t,a.SUBMIT)])},[g,f]));return u(()=>{if(_)return _.add(v),()=>{_.delete(v)}},[_,v]),e((e,t)=>{let n=e(g.value),r=new AbortController;return(async()=>{try{let i=e(g.options);await m(i.debounceMs),r.signal.throwIfAborted(),i.onChange&&(await Promise.resolve(i.onChange({get:e,set:t,atoms:g})),r.signal.throwIfAborted());let o=[];o.push(f(n,a.CHANGE)),e(g.blurred)&&o.push(f(n,a.BLUR)),e(p.submitAttempts)>0&&o.push(f(n,a.SUBMIT)),await Promise.all(o)}catch(e){e instanceof o}})(),()=>{r.abort(new o)}},[f]),e((e,t)=>{let n=e(g.focused),r=new AbortController;return(async()=>{try{let i=e(g.options);if(await m(i.debounceMs),r.signal.throwIfAborted(),h(n)){if(e(g.touched)||t(g.touched,!0),n)i.onFocus&&(await Promise.resolve(i.onFocus({get:e,set:t,atoms:g})),r.signal.throwIfAborted());else{i.onBlur&&(await Promise.resolve(i.onBlur({get:e,set:t,atoms:g})),r.signal.throwIfAborted());let n=e(g.value),o=[];o.push(f(n,a.BLUR)),e(p.submitAttempts)>0&&o.push(f(n,a.SUBMIT)),await Promise.all(o)}}}catch(e){e instanceof o}})(),()=>{r.abort(new o)}},[f]),null}function _({children:e,name:t,...n}){let a=i.use().name.get(),o=p();return/* @__PURE__ */ f(r.Provider,{scope:`${a}-${t}`,initialState:{options:{theme:o,...n}},children:[/* @__PURE__ */ d(g,{...n}),e]})}export{_ as FieldProvider};
|
|
2
2
|
//# sourceMappingURL=FieldProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldProvider.mjs","names":["FieldStateManager","useFieldActions","form","FormApi","field","FieldApi","
|
|
1
|
+
{"version":3,"file":"FieldProvider.mjs","names":["FieldStateManager","useFieldActions","form","FormApi","field","FieldApi","fieldValidations","use","FormFieldValidationsContext","validateAll","useAtomCallback","useCallback","get","value","validate","ValidationCause","useEffect","useAtomEffect","abortController","options","delay","promises","AbortError","focused","isBoolean","set","FieldProvider","props","formName","theme","useThemeName","name","children"],"sources":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../../base/hooks/use-atom-effect.cjs"),t=require("../hooks/use-form-actions.cjs"),
|
|
1
|
+
const e=require("../../base/hooks/use-atom-effect.cjs"),t=require("../hooks/form-field-validations.cjs"),n=require("../hooks/use-form-actions.cjs"),r=require("../molecules/form-molecule.cjs"),i=require("../types.cjs"),a=require("../utilities/abort-error.cjs"),o=require("../utilities/server-errors.cjs");let s=require("jotai/utils"),c=require("@stryke/helpers/is-equal"),l=require("react"),u=require("react/jsx-runtime"),d=require("@tamagui/core"),f=require("@stryke/async");const p=e=>{let t=r.FormApi.useMolecule(),n=r.FormApi.use().validationResultsFields.set(),i=r.FormApi.use().submitAttempts.set(),a=o.hasServerErrors(e);(0,s.useHydrateAtoms)(a?[[t.validationResultsFields,o.applyServerErrors({},e)],[t.submitAttempts,1]]:[]);let u=(0,l.useRef)(e);(0,l.useEffect)(()=>{(0,c.isEqual)(u.current,e)||(u.current=e,n(t=>o.applyServerErrors(t,e)),o.hasServerErrors(e)&&i(e=>Math.max(e,1)))},[e,n,i])};function m(t){let{validate:o}=n.useFormActions(),c=r.FormApi.useMolecule(),u=(0,d.useThemeName)(),m=r.FormApi.use().options.set();return(0,s.useHydrateAtoms)([[c.options,{theme:u,...t}]]),(0,l.useEffect)(()=>{m({theme:u,...t})},[m]),p(t.errors),e.useAtomEffect((e,t)=>{let n=e(c.values),r=e(c.options),s=new AbortController;return(async()=>{try{await(0,f.delay)(r.debounceMs),s.signal.throwIfAborted(),r.onChange&&(await Promise.resolve(r.onChange({get:e,set:t,atoms:c})),s.signal.throwIfAborted());let a=[];a.push(o(n,i.ValidationCause.CHANGE)),e(c.blurred)&&a.push(o(n,i.ValidationCause.BLUR)),e(c.submitAttempts)>0&&a.push(o(n,i.ValidationCause.SUBMIT)),await Promise.all(a)}catch(e){e instanceof a.AbortError}})(),()=>{s.abort(new a.AbortError)}},[o]),null}const h=({children:e,name:n,...i})=>{let[a]=(0,l.useState)(()=>/* @__PURE__ */ new Set);return/* @__PURE__ */ (0,u.jsx)(r.FormApi.Provider,{scope:n,children:/* @__PURE__ */ (0,u.jsxs)(t.FormFieldValidationsContext,{value:a,children:[/* @__PURE__ */ (0,u.jsx)(m,{...i}),e]})})};exports.FormProvider=h;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormProvider.d.cts","names":[],"sources":["../../../src/form/providers/FormProvider.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"FormProvider.d.cts","names":[],"sources":["../../../src/form/providers/FormProvider.tsx"],"mappings":";;KAuJY,oBACV,oBAAoB,sBAAsB,uBACxC,kBAAkB,YAAY;EAAiB;;cAEtC,eACX,oBAAoB,sBAAsB,uBAC1C,UAAA,SAAA,SAIC,oBAAoB,iCAAY,IAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useAtomEffect as e}from"../../base/hooks/use-atom-effect.mjs";import{
|
|
1
|
+
import{useAtomEffect as e}from"../../base/hooks/use-atom-effect.mjs";import{FormFieldValidationsContext as t}from"../hooks/form-field-validations.mjs";import{useFormActions as n}from"../hooks/use-form-actions.mjs";import{FormApi as r}from"../molecules/form-molecule.mjs";import{ValidationCause as i}from"../types.mjs";import{AbortError as a}from"../utilities/abort-error.mjs";import{applyServerErrors as o,hasServerErrors as s}from"../utilities/server-errors.mjs";import{useHydrateAtoms as c}from"jotai/utils";import{isEqual as l}from"@stryke/helpers/is-equal";import{useEffect as u,useRef as d,useState as f}from"react";import{jsx as p,jsxs as m}from"react/jsx-runtime";import{useThemeName as h}from"@tamagui/core";import{delay as g}from"@stryke/async";const _=e=>{let t=r.useMolecule(),n=r.use().validationResultsFields.set(),i=r.use().submitAttempts.set(),a=s(e);c(a?[[t.validationResultsFields,o({},e)],[t.submitAttempts,1]]:[]);let f=d(e);u(()=>{l(f.current,e)||(f.current=e,n(t=>o(t,e)),s(e)&&i(e=>Math.max(e,1)))},[e,n,i])};function v(t){let{validate:o}=n(),s=r.useMolecule(),l=h(),d=r.use().options.set();return c([[s.options,{theme:l,...t}]]),u(()=>{d({theme:l,...t})},[d]),_(t.errors),e((e,t)=>{let n=e(s.values),r=e(s.options),c=new AbortController;return(async()=>{try{await g(r.debounceMs),c.signal.throwIfAborted(),r.onChange&&(await Promise.resolve(r.onChange({get:e,set:t,atoms:s})),c.signal.throwIfAborted());let a=[];a.push(o(n,i.CHANGE)),e(s.blurred)&&a.push(o(n,i.BLUR)),e(s.submitAttempts)>0&&a.push(o(n,i.SUBMIT)),await Promise.all(a)}catch(e){e instanceof a}})(),()=>{c.abort(new a)}},[o]),null}const y=({children:e,name:n,...i})=>{let[a]=f(()=>/* @__PURE__ */ new Set);return/* @__PURE__ */ p(r.Provider,{scope:n,children:/* @__PURE__ */ m(t,{value:a,children:[/* @__PURE__ */ p(v,{...i}),e]})})};export{y as FormProvider};
|
|
2
2
|
//# sourceMappingURL=FormProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormProvider.mjs","names":["
|
|
1
|
+
{"version":3,"file":"FormProvider.mjs","names":["useServerErrors","molecule","FormApi","setResults","setSubmitAttempts","hasErrors","hasServerErrors","errors","useHydrateAtoms","applyServerErrors","appliedRef","useRef","useEffect","isEqual","previous","FormStateManager","useFormActions","theme","useThemeName","setOptions","props","useAtomEffect","values","get","options","abortController","delay","promises","validate","ValidationCause","AbortError","FormProvider","fieldValidations","useState","name","FormFieldValidationsContext","children"],"sources":[],"mappings":""}
|
package/dist/form/types.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MoleculeState } from "../base/utilities/create-molecule.cjs";
|
|
2
2
|
import { AtomRecordConstraint, SetStateActionWithReset, SplitAtomAction } from "../types.cjs";
|
|
3
3
|
import { Ref } from "react";
|
|
4
|
-
import { FormControlSize } from "@cyclone-ui/helpers";
|
|
4
|
+
import { FieldConstraints, FormControlSize } from "@cyclone-ui/helpers";
|
|
5
5
|
import { MaskitoOptions } from "@maskito/core";
|
|
6
6
|
import { MaybePromise } from "@stryke/types/base";
|
|
7
7
|
import { SelectOption, SelectOptionValue } from "@stryke/types/form";
|
|
@@ -30,6 +30,12 @@ type InferFieldState<TValues, TState> = IsPlainObject<TValues> extends true ? {
|
|
|
30
30
|
type InferFormState<TValues extends Record<string, any>, TState> = { [TKey in keyof TValues]: InferFieldState<TValues[TKey], TState>; };
|
|
31
31
|
type FormValuesState<TValues extends Record<string, any>> = TValues & { [TKey in keyof TValues]: IsPlainObject<TValues[TKey]> extends true ? FormValuesState<TValues[TKey]> : TValues[TKey] | null; };
|
|
32
32
|
type FieldChangeEventHandler<TFieldValue = any> = (event: CustomEvent<TFieldValue>) => any;
|
|
33
|
+
/**
|
|
34
|
+
* Error messages for a form's fields, keyed by field name: the shape of Zod's
|
|
35
|
+
* `flattenError(error).fieldErrors`, for example, as returned from a server
|
|
36
|
+
* action.
|
|
37
|
+
*/
|
|
38
|
+
type FormErrors = Record<string, string | readonly string[] | null | undefined>;
|
|
33
39
|
interface CallbackContext<TState extends AtomRecordConstraint<TState> = Record<string, Atom<unknown>>> {
|
|
34
40
|
get: Getter;
|
|
35
41
|
set: Setter;
|
|
@@ -57,6 +63,16 @@ interface FormOptions<TFormValues extends Record<string, any> = Record<string, a
|
|
|
57
63
|
* The validations to run on the form when certain events occur.
|
|
58
64
|
*/
|
|
59
65
|
validate?: Partial<Record<`on${Capitalize<ValidationCause>}`, Validator<FormValuesState<TFormValues>>[] | undefined>>;
|
|
66
|
+
/**
|
|
67
|
+
* Error messages to show on the form's fields, keyed by field name, such as
|
|
68
|
+
* those a server action returns through `useActionState`.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* They render on the first (server) render, count as a submit attempt (so
|
|
72
|
+
* every field shows its errors), don't disable submitting, and are removed
|
|
73
|
+
* from a field once the user edits it.
|
|
74
|
+
*/
|
|
75
|
+
errors?: FormErrors;
|
|
60
76
|
/**
|
|
61
77
|
* How long to debounce the `onChange` event and validation calls in milliseconds.
|
|
62
78
|
*
|
|
@@ -146,7 +162,7 @@ interface FormAtoms<TFormValues extends Record<string, any> = Record<string, any
|
|
|
146
162
|
/**
|
|
147
163
|
* The field options.
|
|
148
164
|
*/
|
|
149
|
-
interface FieldOptions<TFieldValue> {
|
|
165
|
+
interface FieldOptions<TFieldValue> extends FieldConstraints {
|
|
150
166
|
/**
|
|
151
167
|
* The default theme of the field.
|
|
152
168
|
*/
|
|
@@ -293,5 +309,5 @@ interface FieldAtoms<TFieldValue> {
|
|
|
293
309
|
invalid: Atom<boolean>;
|
|
294
310
|
valid: Atom<boolean>;
|
|
295
311
|
}
|
|
296
|
-
export { CallbackContext, FieldAtoms, FieldChangeEventHandler, FieldOptions, FieldOptionsState, FieldStatus, FormAtoms, FormOptions, FormOptionsState, FormValuesState, InferFieldState, InferFormState, ValidationCause, ValidationResults, Validator };
|
|
312
|
+
export { CallbackContext, FieldAtoms, FieldChangeEventHandler, FieldOptions, FieldOptionsState, FieldStatus, FormAtoms, FormErrors, FormOptions, FormOptionsState, FormValuesState, InferFieldState, InferFormState, ValidationCause, ValidationResults, Validator };
|
|
297
313
|
//# sourceMappingURL=types.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":["ValidationDetails","SetStateAction"],"sources":["../../src/form/types.ts"],"mappings":";;;;;;;;;;;;;;KA4CY;cAGC;EACiB,YAAA;EACR,QAAA;EACJ,MAAA;EACI,QAAA;EACA,QAAA;;KAGV,UAAU,iBACpB,OAAO,QACP,eAAe,QACf,OAAO,iBACP,KAAK,QACL,KAAK,WACF,aAAaA;KAEN,oBAAoB,QAC9B,OAAO,iBAAiBA;;;;KAMd;KA6BA,gBAAgB,SAAS,UACnC,cAAc,2BAEP,cAAc,UAAU,gBAAgB,QAAQ,OAAO,aAE1D;KAEM,eAAe,gBAAgB,qBAAqB,aAC7D,cAAc,UAAU,gBAAgB,QAAQ,OAAO;KAG9C,gBAAgB,gBAAgB,uBAAuB,aAChE,cAAc,UAAU,cAAc,QAAQ,sBAC3C,gBAAgB,QAAQ,SACxB,QAAQ;KAGF,wBAAwB,sBAClC,OAAO,YAAY;
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":["ValidationDetails","SetStateAction"],"sources":["../../src/form/types.ts"],"mappings":"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"}
|
package/dist/form/types.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { AtomRecordConstraint, SetStateActionWithReset, SplitAtomAction } from "
|
|
|
3
3
|
import { RESET } from "jotai/utils";
|
|
4
4
|
import { Atom, Getter, PrimitiveAtom, SetStateAction, Setter, WritableAtom } from "jotai";
|
|
5
5
|
import { Ref } from "react";
|
|
6
|
-
import { FormControlSize } from "@cyclone-ui/helpers";
|
|
6
|
+
import { FieldConstraints, FormControlSize } from "@cyclone-ui/helpers";
|
|
7
7
|
import { MaskitoOptions } from "@maskito/core";
|
|
8
8
|
import { MaybePromise } from "@stryke/types/base";
|
|
9
9
|
import { SelectOption, SelectOptionValue } from "@stryke/types/form";
|
|
@@ -30,6 +30,12 @@ type InferFieldState<TValues, TState> = IsPlainObject<TValues> extends true ? {
|
|
|
30
30
|
type InferFormState<TValues extends Record<string, any>, TState> = { [TKey in keyof TValues]: InferFieldState<TValues[TKey], TState>; };
|
|
31
31
|
type FormValuesState<TValues extends Record<string, any>> = TValues & { [TKey in keyof TValues]: IsPlainObject<TValues[TKey]> extends true ? FormValuesState<TValues[TKey]> : TValues[TKey] | null; };
|
|
32
32
|
type FieldChangeEventHandler<TFieldValue = any> = (event: CustomEvent<TFieldValue>) => any;
|
|
33
|
+
/**
|
|
34
|
+
* Error messages for a form's fields, keyed by field name: the shape of Zod's
|
|
35
|
+
* `flattenError(error).fieldErrors`, for example, as returned from a server
|
|
36
|
+
* action.
|
|
37
|
+
*/
|
|
38
|
+
type FormErrors = Record<string, string | readonly string[] | null | undefined>;
|
|
33
39
|
interface CallbackContext<TState extends AtomRecordConstraint<TState> = Record<string, Atom<unknown>>> {
|
|
34
40
|
get: Getter;
|
|
35
41
|
set: Setter;
|
|
@@ -57,6 +63,16 @@ interface FormOptions<TFormValues extends Record<string, any> = Record<string, a
|
|
|
57
63
|
* The validations to run on the form when certain events occur.
|
|
58
64
|
*/
|
|
59
65
|
validate?: Partial<Record<`on${Capitalize<ValidationCause>}`, Validator<FormValuesState<TFormValues>>[] | undefined>>;
|
|
66
|
+
/**
|
|
67
|
+
* Error messages to show on the form's fields, keyed by field name, such as
|
|
68
|
+
* those a server action returns through `useActionState`.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* They render on the first (server) render, count as a submit attempt (so
|
|
72
|
+
* every field shows its errors), don't disable submitting, and are removed
|
|
73
|
+
* from a field once the user edits it.
|
|
74
|
+
*/
|
|
75
|
+
errors?: FormErrors;
|
|
60
76
|
/**
|
|
61
77
|
* How long to debounce the `onChange` event and validation calls in milliseconds.
|
|
62
78
|
*
|
|
@@ -146,7 +162,7 @@ interface FormAtoms<TFormValues extends Record<string, any> = Record<string, any
|
|
|
146
162
|
/**
|
|
147
163
|
* The field options.
|
|
148
164
|
*/
|
|
149
|
-
interface FieldOptions<TFieldValue> {
|
|
165
|
+
interface FieldOptions<TFieldValue> extends FieldConstraints {
|
|
150
166
|
/**
|
|
151
167
|
* The default theme of the field.
|
|
152
168
|
*/
|
|
@@ -293,5 +309,5 @@ interface FieldAtoms<TFieldValue> {
|
|
|
293
309
|
invalid: Atom<boolean>;
|
|
294
310
|
valid: Atom<boolean>;
|
|
295
311
|
}
|
|
296
|
-
export { CallbackContext, FieldAtoms, FieldChangeEventHandler, FieldOptions, FieldOptionsState, FieldStatus, FormAtoms, FormOptions, FormOptionsState, FormValuesState, InferFieldState, InferFormState, ValidationCause, ValidationResults, Validator };
|
|
312
|
+
export { CallbackContext, FieldAtoms, FieldChangeEventHandler, FieldOptions, FieldOptionsState, FieldStatus, FormAtoms, FormErrors, FormOptions, FormOptionsState, FormValuesState, InferFieldState, InferFormState, ValidationCause, ValidationResults, Validator };
|
|
297
313
|
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("./is-validation-results.cjs"),t=require("./validators.cjs"),n=require("./abort-error.cjs");exports.AbortError=
|
|
1
|
+
const e=require("./is-validation-results.cjs"),t=require("./validators.cjs"),n=require("./server-errors.cjs"),r=require("./abort-error.cjs");exports.AbortError=r.AbortError,exports.SERVER_ERROR_CODE=n.SERVER_ERROR_CODE,exports.applyServerErrors=n.applyServerErrors,exports.clearServerErrors=n.clearServerErrors,exports.hasServerErrors=n.hasServerErrors,exports.isValidationResults=e.isValidationResults,exports.requiredValidator=t.requiredValidator,exports.stripServerErrors=n.stripServerErrors;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbortError } from "./abort-error.cjs";
|
|
2
2
|
import { isValidationResults } from "./is-validation-results.cjs";
|
|
3
|
+
import { SERVER_ERROR_CODE, applyServerErrors, clearServerErrors, hasServerErrors, stripServerErrors } from "./server-errors.cjs";
|
|
3
4
|
import { requiredValidator } from "./validators.cjs";
|
|
4
|
-
export { AbortError, isValidationResults, requiredValidator };
|
|
5
|
+
export { AbortError, SERVER_ERROR_CODE, applyServerErrors, clearServerErrors, hasServerErrors, isValidationResults, requiredValidator, stripServerErrors };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbortError } from "./abort-error.mjs";
|
|
2
2
|
import { isValidationResults } from "./is-validation-results.mjs";
|
|
3
|
+
import { SERVER_ERROR_CODE, applyServerErrors, clearServerErrors, hasServerErrors, stripServerErrors } from "./server-errors.mjs";
|
|
3
4
|
import { requiredValidator } from "./validators.mjs";
|
|
4
|
-
export { AbortError, isValidationResults, requiredValidator };
|
|
5
|
+
export { AbortError, SERVER_ERROR_CODE, applyServerErrors, clearServerErrors, hasServerErrors, isValidationResults, requiredValidator, stripServerErrors };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isValidationResults as e}from"./is-validation-results.mjs";import{requiredValidator as t}from"./validators.mjs";import{
|
|
1
|
+
import{isValidationResults as e}from"./is-validation-results.mjs";import{requiredValidator as t}from"./validators.mjs";import{SERVER_ERROR_CODE as n,applyServerErrors as r,clearServerErrors as i,hasServerErrors as a,stripServerErrors as o}from"./server-errors.mjs";import{AbortError as s}from"./abort-error.mjs";export{s as AbortError,n as SERVER_ERROR_CODE,r as applyServerErrors,i as clearServerErrors,a as hasServerErrors,e as isValidationResults,t as requiredValidator,o as stripServerErrors};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./is-validation-results.cjs");let t=require("@stryke/helpers/to-path"),n=require("@stryke/type-checks/is-set-object");const r=`server-error`,i=e=>e.code?.startsWith(`server-error`)??!1,a=e=>e?.server?.some(i)?{...e,server:e.server.filter(e=>!i(e))}:e,o=t=>e.isValidationResults(t)?a(t):(0,n.isSetObject)(t)?Object.fromEntries(Object.entries(t).map(([e,t])=>[e,o(t)])):t,s=(e,n)=>{let i={...o(e)};for(let[e,a]of Object.entries(n??{})){let n=(Array.isArray(a)?a:[a]).filter(e=>!!e);if(n.length===0)continue;let o=(0,t.toPath)(e),s=i;for(let e of o.slice(0,-1))s[e]={...s[e]},s=s[e];let c=o.at(-1),l=s[c]??{};s[c]={...l,server:[...l.server??[],...n.map((e,t)=>({type:`danger`,code:`${r}:${t}`,message:e}))]}}return i},c=e=>Object.values(e??{}).some(e=>Array.isArray(e)?e.some(Boolean):!!e);exports.SERVER_ERROR_CODE=r,exports.applyServerErrors=s,exports.clearServerErrors=a,exports.hasServerErrors=c,exports.stripServerErrors=o;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { FormErrors, ValidationResults } from "../types.cjs";
|
|
2
|
+
/** The code prefix of the messages seeded from a form's `errors` option. */
|
|
3
|
+
declare const SERVER_ERROR_CODE = "server-error";
|
|
4
|
+
/**
|
|
5
|
+
* Remove the messages seeded from the form's `errors` option from one field's
|
|
6
|
+
* validation results, such as once the user edits the field.
|
|
7
|
+
*/
|
|
8
|
+
declare const clearServerErrors: <TResults extends ValidationResults | undefined>(results: TResults) => TResults;
|
|
9
|
+
/**
|
|
10
|
+
* Remove the messages seeded from the form's `errors` option from a form's
|
|
11
|
+
* per-field validation results.
|
|
12
|
+
*/
|
|
13
|
+
declare const stripServerErrors: <TResults>(node: TResults) => TResults;
|
|
14
|
+
/**
|
|
15
|
+
* Replace the messages seeded from a form's `errors` option in its per-field
|
|
16
|
+
* validation results.
|
|
17
|
+
*
|
|
18
|
+
* @param results - The form's `validationResultsFields`.
|
|
19
|
+
* @param errors - Messages keyed by field name, such as Zod's
|
|
20
|
+
* `flattenError(error).fieldErrors` returned from a server action.
|
|
21
|
+
* @returns New results; `results` is not modified.
|
|
22
|
+
*/
|
|
23
|
+
declare const applyServerErrors: <TResults extends Record<string, any>>(results: TResults, errors: FormErrors | undefined) => TResults;
|
|
24
|
+
/**
|
|
25
|
+
* Whether a form's `errors` option holds at least one message.
|
|
26
|
+
*/
|
|
27
|
+
declare const hasServerErrors: (errors: FormErrors | undefined) => boolean;
|
|
28
|
+
export { SERVER_ERROR_CODE, applyServerErrors, clearServerErrors, hasServerErrors, stripServerErrors };
|
|
29
|
+
//# sourceMappingURL=server-errors.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-errors.d.cts","names":[],"sources":["../../../src/form/utilities/server-errors.ts"],"mappings":";;cAyBa;;;;;cASA,oBACX,iBAAiB,+BAEjB,SAAS,aACR;;;;;cAYU,oBAAqB,UAAU,MAAM,aAAW;;;;;;;;;;cAqBhD,oBAAqB,iBAAiB,qBACjD,SAAS,UACT,QAAQ,2BACP;;;;cAyCU,kBAAmB,QAAQ"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { FormErrors, ValidationResults } from "../types.mjs";
|
|
2
|
+
/** The code prefix of the messages seeded from a form's `errors` option. */
|
|
3
|
+
declare const SERVER_ERROR_CODE = "server-error";
|
|
4
|
+
/**
|
|
5
|
+
* Remove the messages seeded from the form's `errors` option from one field's
|
|
6
|
+
* validation results, such as once the user edits the field.
|
|
7
|
+
*/
|
|
8
|
+
declare const clearServerErrors: <TResults extends ValidationResults | undefined>(results: TResults) => TResults;
|
|
9
|
+
/**
|
|
10
|
+
* Remove the messages seeded from the form's `errors` option from a form's
|
|
11
|
+
* per-field validation results.
|
|
12
|
+
*/
|
|
13
|
+
declare const stripServerErrors: <TResults>(node: TResults) => TResults;
|
|
14
|
+
/**
|
|
15
|
+
* Replace the messages seeded from a form's `errors` option in its per-field
|
|
16
|
+
* validation results.
|
|
17
|
+
*
|
|
18
|
+
* @param results - The form's `validationResultsFields`.
|
|
19
|
+
* @param errors - Messages keyed by field name, such as Zod's
|
|
20
|
+
* `flattenError(error).fieldErrors` returned from a server action.
|
|
21
|
+
* @returns New results; `results` is not modified.
|
|
22
|
+
*/
|
|
23
|
+
declare const applyServerErrors: <TResults extends Record<string, any>>(results: TResults, errors: FormErrors | undefined) => TResults;
|
|
24
|
+
/**
|
|
25
|
+
* Whether a form's `errors` option holds at least one message.
|
|
26
|
+
*/
|
|
27
|
+
declare const hasServerErrors: (errors: FormErrors | undefined) => boolean;
|
|
28
|
+
export { SERVER_ERROR_CODE, applyServerErrors, clearServerErrors, hasServerErrors, stripServerErrors };
|
|
29
|
+
//# sourceMappingURL=server-errors.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-errors.d.mts","names":[],"sources":["../../../src/form/utilities/server-errors.ts"],"mappings":""}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{isValidationResults as e}from"./is-validation-results.mjs";import{toPath as t}from"@stryke/helpers/to-path";import{isSetObject as n}from"@stryke/type-checks/is-set-object";const r=`server-error`,i=e=>e.code?.startsWith(`server-error`)??!1,a=e=>e?.server?.some(i)?{...e,server:e.server.filter(e=>!i(e))}:e,o=t=>e(t)?a(t):n(t)?Object.fromEntries(Object.entries(t).map(([e,t])=>[e,o(t)])):t,s=(e,n)=>{let i={...o(e)};for(let[e,a]of Object.entries(n??{})){let n=(Array.isArray(a)?a:[a]).filter(e=>!!e);if(n.length===0)continue;let o=t(e),s=i;for(let e of o.slice(0,-1))s[e]={...s[e]},s=s[e];let c=o.at(-1),l=s[c]??{};s[c]={...l,server:[...l.server??[],...n.map((e,t)=>({type:`danger`,code:`${r}:${t}`,message:e}))]}}return i},c=e=>Object.values(e??{}).some(e=>Array.isArray(e)?e.some(Boolean):!!e);export{r as SERVER_ERROR_CODE,s as applyServerErrors,a as clearServerErrors,c as hasServerErrors,o as stripServerErrors};
|
|
2
|
+
//# sourceMappingURL=server-errors.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-errors.mjs","names":["SERVER_ERROR_CODE","isServerError","message","clearServerErrors","results","stripServerErrors","isValidationResults","node","isSetObject","key","value","applyServerErrors","next","name","errors","messages","path","toPath","parent","fieldResults","index","hasServerErrors"],"sources":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyclone-ui/state",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.69",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A state management package used to handle state in Storm Software applications.",
|
|
6
6
|
"repository": {
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"react-native": { "optional": true }
|
|
99
99
|
},
|
|
100
100
|
"dependencies": {
|
|
101
|
-
"@cyclone-ui/helpers": "0.3.
|
|
101
|
+
"@cyclone-ui/helpers": "0.3.67",
|
|
102
102
|
"@maskito/core": "^3.11.1",
|
|
103
103
|
"@maskito/react": "^3.11.1",
|
|
104
104
|
"@stryke/async": "^0.1.45",
|
|
@@ -108,8 +108,8 @@
|
|
|
108
108
|
"@stryke/json": "^0.15.41",
|
|
109
109
|
"@stryke/type-checks": "^0.6.50",
|
|
110
110
|
"@stryke/types": "^0.12.45",
|
|
111
|
-
"@tamagui/core": "3.2
|
|
112
|
-
"@tamagui/toast": "3.2
|
|
111
|
+
"@tamagui/core": "3.3.2",
|
|
112
|
+
"@tamagui/toast": "3.3.2",
|
|
113
113
|
"bunshi": "^2.2.0",
|
|
114
114
|
"jotai-optics": "^0.4.0",
|
|
115
115
|
"optics-ts": "^2.4.1"
|
|
@@ -123,5 +123,5 @@
|
|
|
123
123
|
},
|
|
124
124
|
"publishConfig": { "access": "public" },
|
|
125
125
|
"module": "./dist/index.mjs",
|
|
126
|
-
"gitHead": "
|
|
126
|
+
"gitHead": "9d8285075aa50693e5f907c6f5149b68e019d371"
|
|
127
127
|
}
|