@jcoreio/zod-forms 1.0.0
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/FieldPath.d.ts +26 -0
- package/FieldPath.d.ts.map +1 -0
- package/FieldPath.js +155 -0
- package/FieldPath.js.map +1 -0
- package/FieldPath.mjs +138 -0
- package/FieldPath.mjs.map +1 -0
- package/FormAction.d.ts +15 -0
- package/FormAction.d.ts.map +1 -0
- package/FormAction.js +6 -0
- package/FormAction.js.map +1 -0
- package/FormAction.mjs +2 -0
- package/FormAction.mjs.map +1 -0
- package/FormContext.d.ts +39 -0
- package/FormContext.d.ts.map +1 -0
- package/FormContext.js +10 -0
- package/FormContext.js.map +1 -0
- package/FormContext.mjs +3 -0
- package/FormContext.mjs.map +1 -0
- package/FormState.d.ts +31 -0
- package/FormState.d.ts.map +1 -0
- package/FormState.js +6 -0
- package/FormState.js.map +1 -0
- package/FormState.mjs +2 -0
- package/FormState.mjs.map +1 -0
- package/FormStateContext.d.ts +8 -0
- package/FormStateContext.d.ts.map +1 -0
- package/FormStateContext.js +10 -0
- package/FormStateContext.js.map +1 -0
- package/FormStateContext.mjs +3 -0
- package/FormStateContext.mjs.map +1 -0
- package/LICENSE.md +21 -0
- package/README.md +154 -0
- package/actions/addHandlers.d.ts +15 -0
- package/actions/addHandlers.d.ts.map +1 -0
- package/actions/addHandlers.js +16 -0
- package/actions/addHandlers.js.map +1 -0
- package/actions/addHandlers.mjs +7 -0
- package/actions/addHandlers.mjs.map +1 -0
- package/actions/arrayActions.d.ts +113 -0
- package/actions/arrayActions.d.ts.map +1 -0
- package/actions/arrayActions.js +146 -0
- package/actions/arrayActions.js.map +1 -0
- package/actions/arrayActions.mjs +120 -0
- package/actions/arrayActions.mjs.map +1 -0
- package/actions/initialize.d.ts +13 -0
- package/actions/initialize.d.ts.map +1 -0
- package/actions/initialize.js +16 -0
- package/actions/initialize.js.map +1 -0
- package/actions/initialize.mjs +7 -0
- package/actions/initialize.mjs.map +1 -0
- package/actions/removeHandlers.d.ts +10 -0
- package/actions/removeHandlers.d.ts.map +1 -0
- package/actions/removeHandlers.js +16 -0
- package/actions/removeHandlers.js.map +1 -0
- package/actions/removeHandlers.mjs +7 -0
- package/actions/removeHandlers.mjs.map +1 -0
- package/actions/setMeta.d.ts +9 -0
- package/actions/setMeta.d.ts.map +1 -0
- package/actions/setMeta.js +14 -0
- package/actions/setMeta.js.map +1 -0
- package/actions/setMeta.mjs +8 -0
- package/actions/setMeta.mjs.map +1 -0
- package/actions/setMounted.d.ts +6 -0
- package/actions/setMounted.d.ts.map +1 -0
- package/actions/setMounted.js +13 -0
- package/actions/setMounted.js.map +1 -0
- package/actions/setMounted.mjs +7 -0
- package/actions/setMounted.mjs.map +1 -0
- package/actions/setRawValue.d.ts +9 -0
- package/actions/setRawValue.d.ts.map +1 -0
- package/actions/setRawValue.js +14 -0
- package/actions/setRawValue.js.map +1 -0
- package/actions/setRawValue.mjs +8 -0
- package/actions/setRawValue.mjs.map +1 -0
- package/actions/setSubmitStatus.d.ts +14 -0
- package/actions/setSubmitStatus.d.ts.map +1 -0
- package/actions/setSubmitStatus.js +16 -0
- package/actions/setSubmitStatus.js.map +1 -0
- package/actions/setSubmitStatus.mjs +7 -0
- package/actions/setSubmitStatus.mjs.map +1 -0
- package/actions/setValue.d.ts +12 -0
- package/actions/setValue.d.ts.map +1 -0
- package/actions/setValue.js +18 -0
- package/actions/setValue.js.map +1 -0
- package/actions/setValue.mjs +9 -0
- package/actions/setValue.mjs.map +1 -0
- package/actions/submit.d.ts +5 -0
- package/actions/submit.d.ts.map +1 -0
- package/actions/submit.js +12 -0
- package/actions/submit.js.map +1 -0
- package/actions/submit.mjs +6 -0
- package/actions/submit.mjs.map +1 -0
- package/actions/submitSucceeded.d.ts +5 -0
- package/actions/submitSucceeded.d.ts.map +1 -0
- package/actions/submitSucceeded.js +12 -0
- package/actions/submitSucceeded.js.map +1 -0
- package/actions/submitSucceeded.mjs +6 -0
- package/actions/submitSucceeded.mjs.map +1 -0
- package/createFormMiddleware.d.ts +6 -0
- package/createFormMiddleware.d.ts.map +1 -0
- package/createFormMiddleware.js +186 -0
- package/createFormMiddleware.js.map +1 -0
- package/createFormMiddleware.mjs +53 -0
- package/createFormMiddleware.mjs.map +1 -0
- package/createFormProvider.d.ts +7 -0
- package/createFormProvider.d.ts.map +1 -0
- package/createFormProvider.js +85 -0
- package/createFormProvider.js.map +1 -0
- package/createFormProvider.mjs +63 -0
- package/createFormProvider.mjs.map +1 -0
- package/createFormReducer.d.ts +9 -0
- package/createFormReducer.d.ts.map +1 -0
- package/createFormReducer.js +95 -0
- package/createFormReducer.js.map +1 -0
- package/createFormReducer.mjs +84 -0
- package/createFormReducer.mjs.map +1 -0
- package/createSelectFieldErrorMap.d.ts +32 -0
- package/createSelectFieldErrorMap.d.ts.map +1 -0
- package/createSelectFieldErrorMap.js +43 -0
- package/createSelectFieldErrorMap.js.map +1 -0
- package/createSelectFieldErrorMap.mjs +24 -0
- package/createSelectFieldErrorMap.mjs.map +1 -0
- package/createSelectFormStatus.d.ts +89 -0
- package/createSelectFormStatus.d.ts.map +1 -0
- package/createSelectFormStatus.js +54 -0
- package/createSelectFormStatus.js.map +1 -0
- package/createSelectFormStatus.mjs +28 -0
- package/createSelectFormStatus.mjs.map +1 -0
- package/createSelectFormValues.d.ts +45 -0
- package/createSelectFormValues.d.ts.map +1 -0
- package/createSelectFormValues.js +24 -0
- package/createSelectFormValues.js.map +1 -0
- package/createSelectFormValues.mjs +10 -0
- package/createSelectFormValues.mjs.map +1 -0
- package/createZodForm.d.ts +33 -0
- package/createZodForm.d.ts.map +1 -0
- package/createZodForm.js +51 -0
- package/createZodForm.js.map +1 -0
- package/createZodForm.mjs +46 -0
- package/createZodForm.mjs.map +1 -0
- package/index.d.ts +14 -0
- package/index.d.ts.map +1 -0
- package/index.js +76 -0
- package/index.js.map +1 -0
- package/index.mjs +11 -0
- package/index.mjs.map +1 -0
- package/initFormState.d.ts +4 -0
- package/initFormState.d.ts.map +1 -0
- package/initFormState.js +22 -0
- package/initFormState.js.map +1 -0
- package/initFormState.mjs +16 -0
- package/initFormState.mjs.map +1 -0
- package/package.json +49 -0
- package/reducers/addHandlers.d.ts +24 -0
- package/reducers/addHandlers.d.ts.map +1 -0
- package/reducers/addHandlers.js +24 -0
- package/reducers/addHandlers.js.map +1 -0
- package/reducers/addHandlers.mjs +21 -0
- package/reducers/addHandlers.mjs.map +1 -0
- package/reducers/arrayInsert.d.ts +7 -0
- package/reducers/arrayInsert.d.ts.map +1 -0
- package/reducers/arrayInsert.js +16 -0
- package/reducers/arrayInsert.js.map +1 -0
- package/reducers/arrayInsert.mjs +12 -0
- package/reducers/arrayInsert.mjs.map +1 -0
- package/reducers/arrayInsertRaw.d.ts +7 -0
- package/reducers/arrayInsertRaw.d.ts.map +1 -0
- package/reducers/arrayInsertRaw.js +22 -0
- package/reducers/arrayInsertRaw.js.map +1 -0
- package/reducers/arrayInsertRaw.mjs +14 -0
- package/reducers/arrayInsertRaw.mjs.map +1 -0
- package/reducers/arrayMove.d.ts +8 -0
- package/reducers/arrayMove.d.ts.map +1 -0
- package/reducers/arrayMove.js +25 -0
- package/reducers/arrayMove.js.map +1 -0
- package/reducers/arrayMove.mjs +16 -0
- package/reducers/arrayMove.mjs.map +1 -0
- package/reducers/arrayPop.d.ts +7 -0
- package/reducers/arrayPop.d.ts.map +1 -0
- package/reducers/arrayPop.js +13 -0
- package/reducers/arrayPop.js.map +1 -0
- package/reducers/arrayPop.mjs +5 -0
- package/reducers/arrayPop.mjs.map +1 -0
- package/reducers/arrayPush.d.ts +7 -0
- package/reducers/arrayPush.d.ts.map +1 -0
- package/reducers/arrayPush.js +15 -0
- package/reducers/arrayPush.js.map +1 -0
- package/reducers/arrayPush.mjs +11 -0
- package/reducers/arrayPush.mjs.map +1 -0
- package/reducers/arrayPushRaw.d.ts +7 -0
- package/reducers/arrayPushRaw.d.ts.map +1 -0
- package/reducers/arrayPushRaw.js +17 -0
- package/reducers/arrayPushRaw.js.map +1 -0
- package/reducers/arrayPushRaw.mjs +9 -0
- package/reducers/arrayPushRaw.mjs.map +1 -0
- package/reducers/arrayRemove.d.ts +7 -0
- package/reducers/arrayRemove.d.ts.map +1 -0
- package/reducers/arrayRemove.js +21 -0
- package/reducers/arrayRemove.js.map +1 -0
- package/reducers/arrayRemove.mjs +13 -0
- package/reducers/arrayRemove.mjs.map +1 -0
- package/reducers/arrayRemoveAll.d.ts +7 -0
- package/reducers/arrayRemoveAll.d.ts.map +1 -0
- package/reducers/arrayRemoveAll.js +14 -0
- package/reducers/arrayRemoveAll.js.map +1 -0
- package/reducers/arrayRemoveAll.mjs +8 -0
- package/reducers/arrayRemoveAll.mjs.map +1 -0
- package/reducers/arrayShift.d.ts +7 -0
- package/reducers/arrayShift.d.ts.map +1 -0
- package/reducers/arrayShift.js +14 -0
- package/reducers/arrayShift.js.map +1 -0
- package/reducers/arrayShift.mjs +8 -0
- package/reducers/arrayShift.mjs.map +1 -0
- package/reducers/arraySplice.d.ts +7 -0
- package/reducers/arraySplice.d.ts.map +1 -0
- package/reducers/arraySplice.js +20 -0
- package/reducers/arraySplice.js.map +1 -0
- package/reducers/arraySplice.mjs +14 -0
- package/reducers/arraySplice.mjs.map +1 -0
- package/reducers/arraySpliceRaw.d.ts +7 -0
- package/reducers/arraySpliceRaw.d.ts.map +1 -0
- package/reducers/arraySpliceRaw.js +26 -0
- package/reducers/arraySpliceRaw.js.map +1 -0
- package/reducers/arraySpliceRaw.mjs +18 -0
- package/reducers/arraySpliceRaw.mjs.map +1 -0
- package/reducers/arraySwap.d.ts +8 -0
- package/reducers/arraySwap.d.ts.map +1 -0
- package/reducers/arraySwap.js +27 -0
- package/reducers/arraySwap.js.map +1 -0
- package/reducers/arraySwap.mjs +18 -0
- package/reducers/arraySwap.mjs.map +1 -0
- package/reducers/arrayUnshift.d.ts +7 -0
- package/reducers/arrayUnshift.d.ts.map +1 -0
- package/reducers/arrayUnshift.js +15 -0
- package/reducers/arrayUnshift.js.map +1 -0
- package/reducers/arrayUnshift.mjs +11 -0
- package/reducers/arrayUnshift.mjs.map +1 -0
- package/reducers/arrayUnshiftRaw.d.ts +7 -0
- package/reducers/arrayUnshiftRaw.d.ts.map +1 -0
- package/reducers/arrayUnshiftRaw.js +17 -0
- package/reducers/arrayUnshiftRaw.js.map +1 -0
- package/reducers/arrayUnshiftRaw.mjs +9 -0
- package/reducers/arrayUnshiftRaw.mjs.map +1 -0
- package/reducers/initialize.d.ts +46 -0
- package/reducers/initialize.d.ts.map +1 -0
- package/reducers/initialize.js +46 -0
- package/reducers/initialize.js.map +1 -0
- package/reducers/initialize.mjs +38 -0
- package/reducers/initialize.mjs.map +1 -0
- package/reducers/removeHandlers.d.ts +24 -0
- package/reducers/removeHandlers.d.ts.map +1 -0
- package/reducers/removeHandlers.js +24 -0
- package/reducers/removeHandlers.js.map +1 -0
- package/reducers/removeHandlers.mjs +21 -0
- package/reducers/removeHandlers.mjs.map +1 -0
- package/reducers/setMeta.d.ts +6 -0
- package/reducers/setMeta.d.ts.map +1 -0
- package/reducers/setMeta.js +28 -0
- package/reducers/setMeta.js.map +1 -0
- package/reducers/setMeta.mjs +21 -0
- package/reducers/setMeta.mjs.map +1 -0
- package/reducers/setRawValue.d.ts +27 -0
- package/reducers/setRawValue.d.ts.map +1 -0
- package/reducers/setRawValue.js +35 -0
- package/reducers/setRawValue.js.map +1 -0
- package/reducers/setRawValue.mjs +26 -0
- package/reducers/setRawValue.mjs.map +1 -0
- package/reducers/setSubmitStatus.d.ts +24 -0
- package/reducers/setSubmitStatus.d.ts.map +1 -0
- package/reducers/setSubmitStatus.js +18 -0
- package/reducers/setSubmitStatus.js.map +1 -0
- package/reducers/setSubmitStatus.mjs +12 -0
- package/reducers/setSubmitStatus.mjs.map +1 -0
- package/reducers/setValue.d.ts +28 -0
- package/reducers/setValue.d.ts.map +1 -0
- package/reducers/setValue.js +41 -0
- package/reducers/setValue.js.map +1 -0
- package/reducers/setValue.mjs +32 -0
- package/reducers/setValue.mjs.map +1 -0
- package/reducers/submitSucceeded.d.ts +23 -0
- package/reducers/submitSucceeded.d.ts.map +1 -0
- package/reducers/submitSucceeded.js +22 -0
- package/reducers/submitSucceeded.js.map +1 -0
- package/reducers/submitSucceeded.mjs +13 -0
- package/reducers/submitSucceeded.mjs.map +1 -0
- package/reducers/util/getInverseArrayElementSchema.d.ts +3 -0
- package/reducers/util/getInverseArrayElementSchema.d.ts.map +1 -0
- package/reducers/util/getInverseArrayElementSchema.js +14 -0
- package/reducers/util/getInverseArrayElementSchema.js.map +1 -0
- package/reducers/util/getInverseArrayElementSchema.mjs +8 -0
- package/reducers/util/getInverseArrayElementSchema.mjs.map +1 -0
- package/reducers/util/updateRawArray.d.ts +7 -0
- package/reducers/util/updateRawArray.d.ts.map +1 -0
- package/reducers/util/updateRawArray.js +14 -0
- package/reducers/util/updateRawArray.js.map +1 -0
- package/reducers/util/updateRawArray.mjs +8 -0
- package/reducers/util/updateRawArray.mjs.map +1 -0
- package/src/FieldPath.ts +215 -0
- package/src/FormAction.ts +26 -0
- package/src/FormContext.ts +44 -0
- package/src/FormState.ts +36 -0
- package/src/FormStateContext.ts +13 -0
- package/src/actions/addHandlers.ts +23 -0
- package/src/actions/arrayActions.ts +183 -0
- package/src/actions/initialize.ts +16 -0
- package/src/actions/removeHandlers.ts +13 -0
- package/src/actions/setMeta.ts +17 -0
- package/src/actions/setMounted.ts +8 -0
- package/src/actions/setRawValue.ts +17 -0
- package/src/actions/setSubmitStatus.ts +26 -0
- package/src/actions/setValue.ts +21 -0
- package/src/actions/submit.ts +7 -0
- package/src/actions/submitSucceeded.ts +7 -0
- package/src/createFormMiddleware.ts +74 -0
- package/src/createFormProvider.tsx +101 -0
- package/src/createFormReducer.ts +91 -0
- package/src/createSelectFieldErrorMap.ts +47 -0
- package/src/createSelectFormStatus.ts +41 -0
- package/src/createSelectFormValues.ts +16 -0
- package/src/createZodForm.ts +57 -0
- package/src/index.ts +32 -0
- package/src/initFormState.ts +18 -0
- package/src/reducers/addHandlers.ts +21 -0
- package/src/reducers/arrayInsert.ts +19 -0
- package/src/reducers/arrayInsertRaw.ts +22 -0
- package/src/reducers/arrayMove.ts +36 -0
- package/src/reducers/arrayPop.ts +16 -0
- package/src/reducers/arrayPush.ts +20 -0
- package/src/reducers/arrayPushRaw.ts +18 -0
- package/src/reducers/arrayRemove.ts +22 -0
- package/src/reducers/arrayRemoveAll.ts +15 -0
- package/src/reducers/arrayShift.ts +15 -0
- package/src/reducers/arraySplice.ts +17 -0
- package/src/reducers/arraySpliceRaw.ts +30 -0
- package/src/reducers/arraySwap.ts +29 -0
- package/src/reducers/arrayUnshift.ts +16 -0
- package/src/reducers/arrayUnshiftRaw.ts +18 -0
- package/src/reducers/initialize.ts +47 -0
- package/src/reducers/removeHandlers.ts +21 -0
- package/src/reducers/setMeta.ts +26 -0
- package/src/reducers/setRawValue.ts +40 -0
- package/src/reducers/setSubmitStatus.ts +15 -0
- package/src/reducers/setValue.ts +49 -0
- package/src/reducers/submitSucceeded.ts +17 -0
- package/src/reducers/util/getInverseArrayElementSchema.ts +9 -0
- package/src/reducers/util/updateRawArray.ts +25 -0
- package/src/useArrayField.ts +161 -0
- package/src/useField.ts +152 -0
- package/src/useFormContext.ts +11 -0
- package/src/useFormDispatch.ts +13 -0
- package/src/useFormSelector.ts +9 -0
- package/src/useFormStatus.ts +14 -0
- package/src/useFormValues.ts +8 -0
- package/src/useHtmlField.ts +235 -0
- package/src/useInitialize.ts +14 -0
- package/src/useSubmit.ts +29 -0
- package/src/util/PathInSchema.ts +7 -0
- package/src/util/PathInType.ts +26 -0
- package/src/util/SchemaAt.ts +68 -0
- package/src/util/acceptsArray.ts +72 -0
- package/src/util/acceptsBigint.ts +71 -0
- package/src/util/acceptsNumber.ts +71 -0
- package/src/util/bindActionsToField.ts +22 -0
- package/src/util/get.ts +10 -0
- package/src/util/getArrayElementSchema.ts +74 -0
- package/src/util/maybeParse.ts +9 -0
- package/src/util/parsePathstring.ts +119 -0
- package/src/util/pathstring.ts +32 -0
- package/src/util/set.ts +25 -0
- package/src/util/setAdd.ts +6 -0
- package/src/util/setDelete.ts +6 -0
- package/useArrayField.d.ts +34 -0
- package/useArrayField.d.ts.map +1 -0
- package/useArrayField.js +99 -0
- package/useArrayField.js.map +1 -0
- package/useArrayField.mjs +75 -0
- package/useArrayField.mjs.map +1 -0
- package/useField.d.ts +34 -0
- package/useField.d.ts.map +1 -0
- package/useField.js +98 -0
- package/useField.js.map +1 -0
- package/useField.mjs +75 -0
- package/useField.mjs.map +1 -0
- package/useFormContext.d.ts +4 -0
- package/useFormContext.d.ts.map +1 -0
- package/useFormContext.js +17 -0
- package/useFormContext.js.map +1 -0
- package/useFormContext.mjs +10 -0
- package/useFormContext.mjs.map +1 -0
- package/useFormDispatch.d.ts +7 -0
- package/useFormDispatch.d.ts.map +1 -0
- package/useFormDispatch.js +10 -0
- package/useFormDispatch.js.map +1 -0
- package/useFormDispatch.mjs +4 -0
- package/useFormDispatch.mjs.map +1 -0
- package/useFormSelector.d.ts +6 -0
- package/useFormSelector.d.ts.map +1 -0
- package/useFormSelector.js +10 -0
- package/useFormSelector.js.map +1 -0
- package/useFormSelector.mjs +4 -0
- package/useFormSelector.mjs.map +1 -0
- package/useFormStatus.d.ts +13 -0
- package/useFormStatus.d.ts.map +1 -0
- package/useFormStatus.js +15 -0
- package/useFormStatus.js.map +1 -0
- package/useFormStatus.mjs +10 -0
- package/useFormStatus.mjs.map +1 -0
- package/useFormValues.d.ts +8 -0
- package/useFormValues.d.ts.map +1 -0
- package/useFormValues.js +14 -0
- package/useFormValues.js.map +1 -0
- package/useFormValues.mjs +9 -0
- package/useFormValues.mjs.map +1 -0
- package/useHtmlField.d.ts +41 -0
- package/useHtmlField.d.ts.map +1 -0
- package/useHtmlField.js +161 -0
- package/useHtmlField.js.map +1 -0
- package/useHtmlField.mjs +148 -0
- package/useHtmlField.mjs.map +1 -0
- package/useInitialize.d.ts +5 -0
- package/useInitialize.d.ts.map +1 -0
- package/useInitialize.js +18 -0
- package/useInitialize.js.map +1 -0
- package/useInitialize.mjs +11 -0
- package/useInitialize.mjs.map +1 -0
- package/useSubmit.d.ts +5 -0
- package/useSubmit.d.ts.map +1 -0
- package/useSubmit.js +53 -0
- package/useSubmit.js.map +1 -0
- package/useSubmit.mjs +39 -0
- package/useSubmit.mjs.map +1 -0
- package/util/PathInSchema.d.ts +5 -0
- package/util/PathInSchema.d.ts.map +1 -0
- package/util/PathInSchema.js +6 -0
- package/util/PathInSchema.js.map +1 -0
- package/util/PathInSchema.mjs +2 -0
- package/util/PathInSchema.mjs.map +1 -0
- package/util/PathInType.d.ts +11 -0
- package/util/PathInType.d.ts.map +1 -0
- package/util/PathInType.js +6 -0
- package/util/PathInType.js.map +1 -0
- package/util/PathInType.mjs +2 -0
- package/util/PathInType.mjs.map +1 -0
- package/util/SchemaAt.d.ts +5 -0
- package/util/SchemaAt.d.ts.map +1 -0
- package/util/SchemaAt.js +6 -0
- package/util/SchemaAt.js.map +1 -0
- package/util/SchemaAt.mjs +2 -0
- package/util/SchemaAt.mjs.map +1 -0
- package/util/acceptsArray.d.ts +3 -0
- package/util/acceptsArray.d.ts.map +1 -0
- package/util/acceptsArray.js +89 -0
- package/util/acceptsArray.js.map +1 -0
- package/util/acceptsArray.mjs +105 -0
- package/util/acceptsArray.mjs.map +1 -0
- package/util/acceptsBigint.d.ts +3 -0
- package/util/acceptsBigint.d.ts.map +1 -0
- package/util/acceptsBigint.js +88 -0
- package/util/acceptsBigint.js.map +1 -0
- package/util/acceptsBigint.mjs +104 -0
- package/util/acceptsBigint.mjs.map +1 -0
- package/util/acceptsNumber.d.ts +3 -0
- package/util/acceptsNumber.d.ts.map +1 -0
- package/util/acceptsNumber.js +88 -0
- package/util/acceptsNumber.js.map +1 -0
- package/util/acceptsNumber.mjs +104 -0
- package/util/acceptsNumber.mjs.map +1 -0
- package/util/bindActionsToField.d.ts +7 -0
- package/util/bindActionsToField.d.ts.map +1 -0
- package/util/bindActionsToField.js +22 -0
- package/util/bindActionsToField.js.map +1 -0
- package/util/bindActionsToField.mjs +4 -0
- package/util/bindActionsToField.mjs.map +1 -0
- package/util/get.d.ts +2 -0
- package/util/get.d.ts.map +1 -0
- package/util/get.js +12 -0
- package/util/get.js.map +1 -0
- package/util/get.mjs +4 -0
- package/util/get.mjs.map +1 -0
- package/util/getArrayElementSchema.d.ts +3 -0
- package/util/getArrayElementSchema.d.ts.map +1 -0
- package/util/getArrayElementSchema.js +87 -0
- package/util/getArrayElementSchema.js.map +1 -0
- package/util/getArrayElementSchema.mjs +102 -0
- package/util/getArrayElementSchema.mjs.map +1 -0
- package/util/maybeParse.d.ts +3 -0
- package/util/maybeParse.d.ts.map +1 -0
- package/util/maybeParse.js +11 -0
- package/util/maybeParse.js.map +1 -0
- package/util/maybeParse.mjs +5 -0
- package/util/maybeParse.mjs.map +1 -0
- package/util/parsePathstring.d.ts +40 -0
- package/util/parsePathstring.d.ts.map +1 -0
- package/util/parsePathstring.js +55 -0
- package/util/parsePathstring.js.map +1 -0
- package/util/parsePathstring.mjs +35 -0
- package/util/parsePathstring.mjs.map +1 -0
- package/util/pathstring.d.ts +13 -0
- package/util/pathstring.d.ts.map +1 -0
- package/util/pathstring.js +15 -0
- package/util/pathstring.js.map +1 -0
- package/util/pathstring.mjs +7 -0
- package/util/pathstring.mjs.map +1 -0
- package/util/set.d.ts +2 -0
- package/util/set.d.ts.map +1 -0
- package/util/set.js +33 -0
- package/util/set.js.map +1 -0
- package/util/set.mjs +23 -0
- package/util/set.mjs.map +1 -0
- package/util/setAdd.d.ts +2 -0
- package/util/setAdd.d.ts.map +1 -0
- package/util/setAdd.js +13 -0
- package/util/setAdd.js.map +1 -0
- package/util/setAdd.mjs +7 -0
- package/util/setAdd.mjs.map +1 -0
- package/util/setDelete.d.ts +2 -0
- package/util/setDelete.d.ts.map +1 -0
- package/util/setDelete.js +13 -0
- package/util/setDelete.js.map +1 -0
- package/util/setDelete.mjs +7 -0
- package/util/setDelete.mjs.map +1 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 JCore Systems
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# @jcoreio/zod-forms
|
|
2
|
+
|
|
3
|
+
A more seamless way to build React forms from Zod schemas
|
|
4
|
+
|
|
5
|
+
(not published yet)
|
|
6
|
+
|
|
7
|
+
[](https://circleci.com/gh/jcoreio/zod-forms)
|
|
8
|
+
[](https://codecov.io/gh/jcoreio/zod-forms)
|
|
9
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
10
|
+
[](http://commitizen.github.io/cz-cli/)
|
|
11
|
+
[](https://badge.fury.io/js/%40jcoreio%2Fzod-forms)
|
|
12
|
+
|
|
13
|
+
# Features
|
|
14
|
+
|
|
15
|
+
- 100% typesafe paths, input and output types for deeply nested fields
|
|
16
|
+
- Supports `z.string().optional()`, `z.string().nullable()`, `z.number()` etc in inputs out of the box
|
|
17
|
+
- Interprets blank inputs as `undefined` or `null` by default, depending on what the field schema
|
|
18
|
+
accepts
|
|
19
|
+
- Normalizes inputs on blur by default (e.g. with `z.string().blur()` you'll see the trim on blur)
|
|
20
|
+
- Supports Zod schemas with different input and output types (as long as you use
|
|
21
|
+
`zod-invertible` to specify how to format from output back to input)
|
|
22
|
+
- Allows you to programmatically set either input or output values
|
|
23
|
+
- Each step of a wizard form can declare its own submit handler independent from the enclosing
|
|
24
|
+
`<form>` element. This enables animated transitions between steps without a separate
|
|
25
|
+
`<form>`s or submit button for each step.
|
|
26
|
+
|
|
27
|
+
# Limitations
|
|
28
|
+
|
|
29
|
+
- Designed specifically for Zod and React only
|
|
30
|
+
- Not currently focused on high performance/large form state like `final-form` or `react-hooks-form`
|
|
31
|
+
|
|
32
|
+
# Quickstart
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pnpm i @jcoreio/zod-forms
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
or if you're using `npm`:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm i --save @jcoreio/zod-forms
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Create a form schema
|
|
47
|
+
|
|
48
|
+
In this example, we'll have a `url` field that must be a valid URL.
|
|
49
|
+
Using `.trim()` ensures that the submitted value will be trimmed.
|
|
50
|
+
The displayed value will also be trimmed whenever the field is blurred.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import z from 'zod'
|
|
54
|
+
|
|
55
|
+
const schema = z.object({
|
|
56
|
+
url: z.string().trim().url(),
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Create a form
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { createZodForm } from '@jcoreio/zod-form'
|
|
64
|
+
|
|
65
|
+
const {
|
|
66
|
+
FormProvider,
|
|
67
|
+
// all of the following hooks can also be imported from '@jcoreio/zod-form',
|
|
68
|
+
// but the ones returned from `createZodForm` are already bound to the schema type
|
|
69
|
+
useInitialize,
|
|
70
|
+
useSubmit,
|
|
71
|
+
useFormStatus,
|
|
72
|
+
useHtmlField,
|
|
73
|
+
} = createZodForm({ schema })
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Create a field component
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { FieldPathForRawValue } from '@jcoreio/zod-form'
|
|
80
|
+
|
|
81
|
+
function FormInput({
|
|
82
|
+
field,
|
|
83
|
+
type,
|
|
84
|
+
...props
|
|
85
|
+
}: Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type'> & {
|
|
86
|
+
type: HTMLInputTypeAttribute
|
|
87
|
+
// This ensures that only fields that accept string, null or undefined
|
|
88
|
+
// as input can be passed to <FormInput>
|
|
89
|
+
field: FieldPathForRawValue<string | null | undefined>
|
|
90
|
+
}) {
|
|
91
|
+
// This hook is designed to provide the smoothest integration with simple <input>s.
|
|
92
|
+
const { input, meta } = useHtmlField({ field, type })
|
|
93
|
+
|
|
94
|
+
const inputRef = React.createRef<HTMLInputElement>()
|
|
95
|
+
const error = meta.touched || meta.submitFailed ? meta.error : undefined
|
|
96
|
+
React.useEffect(() => {
|
|
97
|
+
inputRef.current?.setCustomValidity(error || '')
|
|
98
|
+
}, [error])
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<input
|
|
102
|
+
{...props}
|
|
103
|
+
// the `input` props from `useHtmlField` are designed to be spread here
|
|
104
|
+
{...input}
|
|
105
|
+
ref={inputRef}
|
|
106
|
+
/>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Create the form component
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
function MyForm() {
|
|
115
|
+
return (
|
|
116
|
+
// <FormProvider> wraps <MyFormContent> in a React Context through which the
|
|
117
|
+
// hooks and fields access form state
|
|
118
|
+
<FormProvider>
|
|
119
|
+
<MyFormContent />
|
|
120
|
+
</FormProvider>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function MyFormContent() {
|
|
125
|
+
// This hook initializes the form with the given values.
|
|
126
|
+
// The second argument is a dependency array -- the form will be reinitialized
|
|
127
|
+
// if any of the dependencies change, similar to React.useEffect.
|
|
128
|
+
useInitialize({ values: { url: 'http://localhost' } }, [])
|
|
129
|
+
|
|
130
|
+
// This hook sets your submit handler code, and returns an onSubmit handler to
|
|
131
|
+
// pass to a <form>
|
|
132
|
+
const onSubmit = useSubmit({
|
|
133
|
+
onSubmit: async ({ url }) => {
|
|
134
|
+
alert(`Submitted! url value: ${url}`)
|
|
135
|
+
},
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
const { submitting, pristine } = useFormStatus()
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<form onSubmit={onSubmit}>
|
|
142
|
+
<FormInput
|
|
143
|
+
// this is how we bind <FormInput> to the `url` field
|
|
144
|
+
field={myForm.get('url')}
|
|
145
|
+
type="text"
|
|
146
|
+
placeholder="URL"
|
|
147
|
+
/>
|
|
148
|
+
<button disabled={pristine || submitting} type="submit">
|
|
149
|
+
submit
|
|
150
|
+
</button>
|
|
151
|
+
</form>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import { SubmitFailedHandler, SubmitHandler, SubmitSuccededHandler } from '../FormState';
|
|
3
|
+
export type Handlers<T extends z.ZodTypeAny> = {
|
|
4
|
+
onSubmit?: SubmitHandler<T>;
|
|
5
|
+
onSubmitSucceeded?: SubmitSuccededHandler;
|
|
6
|
+
onSubmitFailed?: SubmitFailedHandler;
|
|
7
|
+
};
|
|
8
|
+
export type AddHandlersAction<T extends z.ZodTypeAny> = ReturnType<typeof addHandlers<T>>;
|
|
9
|
+
export declare function addHandlers<T extends z.ZodTypeAny>(handlers: Handlers<T>): {
|
|
10
|
+
readonly onSubmit?: SubmitHandler<T> | undefined;
|
|
11
|
+
readonly onSubmitSucceeded?: SubmitSuccededHandler;
|
|
12
|
+
readonly onSubmitFailed?: SubmitFailedHandler;
|
|
13
|
+
readonly type: "addHandlers";
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=addHandlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addHandlers.d.ts","sourceRoot":"","sources":["../../src/actions/addHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACtB,MAAM,cAAc,CAAA;AAErB,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,IAAI;IAC7C,QAAQ,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;IAC3B,iBAAiB,CAAC,EAAE,qBAAqB,CAAA;IACzC,cAAc,CAAC,EAAE,mBAAmB,CAAA;CACrC,CAAA;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,IAAI,UAAU,CAChE,OAAO,WAAW,CAAC,CAAC,CAAC,CACtB,CAAA;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;;iCARnD,qBAAqB;8BACxB,mBAAmB;;EAYrC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.addHandlers = addHandlers;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
function addHandlers(handlers) {
|
|
12
|
+
return _objectSpread({
|
|
13
|
+
type: 'addHandlers'
|
|
14
|
+
}, handlers);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=addHandlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addHandlers.js","names":["addHandlers","handlers","_objectSpread","type"],"sources":["../../src/actions/addHandlers.ts"],"sourcesContent":["import z from 'zod'\nimport {\n SubmitFailedHandler,\n SubmitHandler,\n SubmitSuccededHandler,\n} from '../FormState'\n\nexport type Handlers<T extends z.ZodTypeAny> = {\n onSubmit?: SubmitHandler<T>\n onSubmitSucceeded?: SubmitSuccededHandler\n onSubmitFailed?: SubmitFailedHandler\n}\n\nexport type AddHandlersAction<T extends z.ZodTypeAny> = ReturnType<\n typeof addHandlers<T>\n>\n\nexport function addHandlers<T extends z.ZodTypeAny>(handlers: Handlers<T>) {\n return {\n type: 'addHandlers',\n ...handlers,\n } as const\n}\n"],"mappings":";;;;;;;;;;AAiBO,SAASA,WAAWA,CAAyBC,QAAqB,EAAE;EACzE,OAAAC,aAAA;IACEC,IAAI,EAAE;EAAa,GAChBF,QAAQ;AAEf","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addHandlers.mjs","names":["addHandlers","handlers","type"],"sources":["../../src/actions/addHandlers.ts"],"sourcesContent":["import z from 'zod'\nimport {\n SubmitFailedHandler,\n SubmitHandler,\n SubmitSuccededHandler,\n} from '../FormState'\n\nexport type Handlers<T extends z.ZodTypeAny> = {\n onSubmit?: SubmitHandler<T>\n onSubmitSucceeded?: SubmitSuccededHandler\n onSubmitFailed?: SubmitFailedHandler\n}\n\nexport type AddHandlersAction<T extends z.ZodTypeAny> = ReturnType<\n typeof addHandlers<T>\n>\n\nexport function addHandlers<T extends z.ZodTypeAny>(handlers: Handlers<T>) {\n return {\n type: 'addHandlers',\n ...handlers,\n } as const\n}\n"],"mappings":"AAiBA,OAAO,SAASA,WAAWA,CAAyBC,QAAqB,EAAE;EACzE,OAAO;IACLC,IAAI,EAAE,aAAa;IACnB,GAAGD;EACL,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { FieldPathForValue } from '../FieldPath';
|
|
2
|
+
import z from 'zod';
|
|
3
|
+
export type ArrayFieldPath<V = any, R = any> = FieldPathForValue<V[] | null | undefined, R[] | null | undefined>;
|
|
4
|
+
type ValueFor<Field extends ArrayFieldPath> = NonNullable<z.output<Field['schema']>>[number];
|
|
5
|
+
type RawValueFor<Field extends ArrayFieldPath> = NonNullable<z.input<Field['schema']>>[number];
|
|
6
|
+
export type ArrayInsertAction<Field extends ArrayFieldPath = ArrayFieldPath> = ReturnType<typeof arrayInsert<Field>>;
|
|
7
|
+
export declare function arrayInsert<Field extends ArrayFieldPath>(field: Field, index: number, value: ValueFor<Field>): {
|
|
8
|
+
readonly type: "arrayInsert";
|
|
9
|
+
readonly field: Field;
|
|
10
|
+
readonly index: number;
|
|
11
|
+
readonly value: ValueFor<Field>;
|
|
12
|
+
};
|
|
13
|
+
export type ArrayInsertRawAction<Field extends ArrayFieldPath = ArrayFieldPath> = ReturnType<typeof arrayInsertRaw<Field>>;
|
|
14
|
+
export declare function arrayInsertRaw<Field extends ArrayFieldPath>(field: Field, index: number, rawValue: RawValueFor<Field>): {
|
|
15
|
+
readonly type: "arrayInsertRaw";
|
|
16
|
+
readonly field: Field;
|
|
17
|
+
readonly index: number;
|
|
18
|
+
readonly rawValue: RawValueFor<Field>;
|
|
19
|
+
};
|
|
20
|
+
export type ArrayMoveAction = ReturnType<typeof arrayMove>;
|
|
21
|
+
export declare function arrayMove(field: ArrayFieldPath, from: number, to: number): {
|
|
22
|
+
readonly type: "arrayMove";
|
|
23
|
+
readonly field: ArrayFieldPath<any, any>;
|
|
24
|
+
readonly from: number;
|
|
25
|
+
readonly to: number;
|
|
26
|
+
};
|
|
27
|
+
export type ArrayPopAction = ReturnType<typeof arrayPop>;
|
|
28
|
+
export declare function arrayPop(field: ArrayFieldPath): {
|
|
29
|
+
readonly type: "arrayPop";
|
|
30
|
+
readonly field: ArrayFieldPath<any, any>;
|
|
31
|
+
};
|
|
32
|
+
export type ArrayPushAction<Field extends ArrayFieldPath = ArrayFieldPath> = ReturnType<typeof arrayPush<Field>>;
|
|
33
|
+
export declare function arrayPush<Field extends ArrayFieldPath>(field: Field, value: ValueFor<Field>): {
|
|
34
|
+
readonly type: "arrayPush";
|
|
35
|
+
readonly field: Field;
|
|
36
|
+
readonly value: ValueFor<Field>;
|
|
37
|
+
};
|
|
38
|
+
export type ArrayPushRawAction<Field extends ArrayFieldPath = ArrayFieldPath> = ReturnType<typeof arrayPushRaw<Field>>;
|
|
39
|
+
export declare function arrayPushRaw<Field extends ArrayFieldPath>(field: Field, rawValue: RawValueFor<Field>): {
|
|
40
|
+
readonly type: "arrayPushRaw";
|
|
41
|
+
readonly field: Field;
|
|
42
|
+
readonly rawValue: RawValueFor<Field>;
|
|
43
|
+
};
|
|
44
|
+
export type ArrayRemoveAction = ReturnType<typeof arrayRemove>;
|
|
45
|
+
export declare function arrayRemove(field: ArrayFieldPath, index: number): {
|
|
46
|
+
readonly type: "arrayRemove";
|
|
47
|
+
readonly field: ArrayFieldPath<any, any>;
|
|
48
|
+
readonly index: number;
|
|
49
|
+
};
|
|
50
|
+
export type ArrayRemoveAllAction = ReturnType<typeof arrayRemoveAll>;
|
|
51
|
+
export declare function arrayRemoveAll(field: ArrayFieldPath): {
|
|
52
|
+
readonly type: "arrayRemoveAll";
|
|
53
|
+
readonly field: ArrayFieldPath<any, any>;
|
|
54
|
+
};
|
|
55
|
+
export type ArrayShiftAction = ReturnType<typeof arrayShift>;
|
|
56
|
+
export declare function arrayShift(field: ArrayFieldPath): {
|
|
57
|
+
readonly type: "arrayShift";
|
|
58
|
+
readonly field: ArrayFieldPath<any, any>;
|
|
59
|
+
};
|
|
60
|
+
export type ArraySpliceAction<Field extends ArrayFieldPath = ArrayFieldPath> = ReturnType<typeof arraySplice<Field>>;
|
|
61
|
+
export declare function arraySplice<Field extends ArrayFieldPath>(field: Field, index: number, deleteCount: number, ...values: ValueFor<Field>[]): {
|
|
62
|
+
readonly type: "arraySplice";
|
|
63
|
+
readonly field: Field;
|
|
64
|
+
readonly index: number;
|
|
65
|
+
readonly deleteCount: number;
|
|
66
|
+
readonly values: ValueFor<Field>[];
|
|
67
|
+
};
|
|
68
|
+
export type ArraySpliceRawAction<Field extends ArrayFieldPath = ArrayFieldPath> = ReturnType<typeof arraySpliceRaw<Field>>;
|
|
69
|
+
export declare function arraySpliceRaw<Field extends ArrayFieldPath>(field: Field, index: number, deleteCount: number, ...rawValues: RawValueFor<Field>[]): {
|
|
70
|
+
readonly type: "arraySpliceRaw";
|
|
71
|
+
readonly field: Field;
|
|
72
|
+
readonly index: number;
|
|
73
|
+
readonly deleteCount: number;
|
|
74
|
+
readonly rawValues: RawValueFor<Field>[];
|
|
75
|
+
};
|
|
76
|
+
export type ArraySwapAction = ReturnType<typeof arraySwap>;
|
|
77
|
+
export declare function arraySwap(field: ArrayFieldPath, indexA: number, indexB: number): {
|
|
78
|
+
readonly type: "arraySwap";
|
|
79
|
+
readonly field: ArrayFieldPath<any, any>;
|
|
80
|
+
readonly indexA: number;
|
|
81
|
+
readonly indexB: number;
|
|
82
|
+
};
|
|
83
|
+
export type ArrayUnshiftAction<Field extends ArrayFieldPath = ArrayFieldPath> = ReturnType<typeof arrayUnshift<Field>>;
|
|
84
|
+
export declare function arrayUnshift<Field extends ArrayFieldPath>(field: Field, value: ValueFor<Field>): {
|
|
85
|
+
readonly type: "arrayUnshift";
|
|
86
|
+
readonly field: Field;
|
|
87
|
+
readonly value: ValueFor<Field>;
|
|
88
|
+
};
|
|
89
|
+
export type ArrayUnshiftRawAction<Field extends ArrayFieldPath = ArrayFieldPath> = ReturnType<typeof arrayUnshiftRaw<Field>>;
|
|
90
|
+
export declare function arrayUnshiftRaw<Field extends ArrayFieldPath>(field: Field, rawValue: RawValueFor<Field>): {
|
|
91
|
+
readonly type: "arrayUnshiftRaw";
|
|
92
|
+
readonly field: Field;
|
|
93
|
+
readonly rawValue: RawValueFor<Field>;
|
|
94
|
+
};
|
|
95
|
+
export type ArrayAction<Field extends ArrayFieldPath = ArrayFieldPath> = ArrayInsertAction<Field> | ArrayInsertRawAction<Field> | ArrayMoveAction | ArrayPopAction | ArrayPushAction<Field> | ArrayPushRawAction<Field> | ArrayRemoveAction | ArrayRemoveAllAction | ArrayShiftAction | ArraySpliceAction<Field> | ArraySpliceRawAction<Field> | ArraySwapAction | ArrayUnshiftAction<Field> | ArrayUnshiftRawAction<Field>;
|
|
96
|
+
export declare const arrayActions: {
|
|
97
|
+
insert: typeof arrayInsert;
|
|
98
|
+
insertRaw: typeof arrayInsertRaw;
|
|
99
|
+
move: typeof arrayMove;
|
|
100
|
+
pop: typeof arrayPop;
|
|
101
|
+
push: typeof arrayPush;
|
|
102
|
+
pushRaw: typeof arrayPushRaw;
|
|
103
|
+
remove: typeof arrayRemove;
|
|
104
|
+
removeAll: typeof arrayRemoveAll;
|
|
105
|
+
shift: typeof arrayShift;
|
|
106
|
+
splice: typeof arraySplice;
|
|
107
|
+
spliceRaw: typeof arraySpliceRaw;
|
|
108
|
+
swap: typeof arraySwap;
|
|
109
|
+
unshift: typeof arrayUnshift;
|
|
110
|
+
unshiftRaw: typeof arrayUnshiftRaw;
|
|
111
|
+
};
|
|
112
|
+
export {};
|
|
113
|
+
//# sourceMappingURL=arrayActions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrayActions.d.ts","sourceRoot":"","sources":["../../src/actions/arrayActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI,iBAAiB,CAC9D,CAAC,EAAE,GAAG,IAAI,GAAG,SAAS,EACtB,CAAC,EAAE,GAAG,IAAI,GAAG,SAAS,CACvB,CAAA;AAED,KAAK,QAAQ,CAAC,KAAK,SAAS,cAAc,IAAI,WAAW,CACvD,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAC1B,CAAC,MAAM,CAAC,CAAA;AAET,KAAK,WAAW,CAAC,KAAK,SAAS,cAAc,IAAI,WAAW,CAC1D,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CACzB,CAAC,MAAM,CAAC,CAAA;AAET,MAAM,MAAM,iBAAiB,CAAC,KAAK,SAAS,cAAc,GAAG,cAAc,IACzE,UAAU,CAAC,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,CAAA;AAEvC,wBAAgB,WAAW,CAAC,KAAK,SAAS,cAAc,EACtD,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,MAAM,EACb,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K,EACZ,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC;;;;EAGvB;AAED,MAAM,MAAM,qBAAqB,CAC/B,KAAK,SAAS,cAAc,GAAG,cAAc,IAC3C,UAAU,CAAC,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC,CAAA;AAE7C,wBAAgB,eAAe,CAAC,KAAK,SAAS,cAAc,EAC1D,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC;;;;EAG7B;AAED,MAAM,MAAM,WAAW,CAAC,KAAK,SAAS,cAAc,GAAG,cAAc,IACjE,iBAAiB,CAAC,KAAK,CAAC,GACxB,oBAAoB,CAAC,KAAK,CAAC,GAC3B,eAAe,GACf,cAAc,GACd,eAAe,CAAC,KAAK,CAAC,GACtB,kBAAkB,CAAC,KAAK,CAAC,GACzB,iBAAiB,GACjB,oBAAoB,GACpB,gBAAgB,GAChB,iBAAiB,CAAC,KAAK,CAAC,GACxB,oBAAoB,CAAC,KAAK,CAAC,GAC3B,eAAe,GACf,kBAAkB,CAAC,KAAK,CAAC,GACzB,qBAAqB,CAAC,KAAK,CAAC,CAAA;AAEhC,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;CAexB,CAAA"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.arrayActions = void 0;
|
|
7
|
+
exports.arrayInsert = arrayInsert;
|
|
8
|
+
exports.arrayInsertRaw = arrayInsertRaw;
|
|
9
|
+
exports.arrayMove = arrayMove;
|
|
10
|
+
exports.arrayPop = arrayPop;
|
|
11
|
+
exports.arrayPush = arrayPush;
|
|
12
|
+
exports.arrayPushRaw = arrayPushRaw;
|
|
13
|
+
exports.arrayRemove = arrayRemove;
|
|
14
|
+
exports.arrayRemoveAll = arrayRemoveAll;
|
|
15
|
+
exports.arrayShift = arrayShift;
|
|
16
|
+
exports.arraySplice = arraySplice;
|
|
17
|
+
exports.arraySpliceRaw = arraySpliceRaw;
|
|
18
|
+
exports.arraySwap = arraySwap;
|
|
19
|
+
exports.arrayUnshift = arrayUnshift;
|
|
20
|
+
exports.arrayUnshiftRaw = arrayUnshiftRaw;
|
|
21
|
+
function arrayInsert(field, index, value) {
|
|
22
|
+
return {
|
|
23
|
+
type: 'arrayInsert',
|
|
24
|
+
field: field,
|
|
25
|
+
index: index,
|
|
26
|
+
value: value
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function arrayInsertRaw(field, index, rawValue) {
|
|
30
|
+
return {
|
|
31
|
+
type: 'arrayInsertRaw',
|
|
32
|
+
field: field,
|
|
33
|
+
index: index,
|
|
34
|
+
rawValue: rawValue
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function arrayMove(field, from, to) {
|
|
38
|
+
return {
|
|
39
|
+
type: 'arrayMove',
|
|
40
|
+
field: field,
|
|
41
|
+
from: from,
|
|
42
|
+
to: to
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function arrayPop(field) {
|
|
46
|
+
return {
|
|
47
|
+
type: 'arrayPop',
|
|
48
|
+
field: field
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function arrayPush(field, value) {
|
|
52
|
+
return {
|
|
53
|
+
type: 'arrayPush',
|
|
54
|
+
field: field,
|
|
55
|
+
value: value
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function arrayPushRaw(field, rawValue) {
|
|
59
|
+
return {
|
|
60
|
+
type: 'arrayPushRaw',
|
|
61
|
+
field: field,
|
|
62
|
+
rawValue: rawValue
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function arrayRemove(field, index) {
|
|
66
|
+
return {
|
|
67
|
+
type: 'arrayRemove',
|
|
68
|
+
field: field,
|
|
69
|
+
index: index
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function arrayRemoveAll(field) {
|
|
73
|
+
return {
|
|
74
|
+
type: 'arrayRemoveAll',
|
|
75
|
+
field: field
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function arrayShift(field) {
|
|
79
|
+
return {
|
|
80
|
+
type: 'arrayShift',
|
|
81
|
+
field: field
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function arraySplice(field, index, deleteCount) {
|
|
85
|
+
for (var _len = arguments.length, values = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
86
|
+
values[_key - 3] = arguments[_key];
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
type: 'arraySplice',
|
|
90
|
+
field: field,
|
|
91
|
+
index: index,
|
|
92
|
+
deleteCount: deleteCount,
|
|
93
|
+
values: values
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function arraySpliceRaw(field, index, deleteCount) {
|
|
97
|
+
for (var _len2 = arguments.length, rawValues = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
|
98
|
+
rawValues[_key2 - 3] = arguments[_key2];
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
type: 'arraySpliceRaw',
|
|
102
|
+
field: field,
|
|
103
|
+
index: index,
|
|
104
|
+
deleteCount: deleteCount,
|
|
105
|
+
rawValues: rawValues
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function arraySwap(field, indexA, indexB) {
|
|
109
|
+
return {
|
|
110
|
+
type: 'arraySwap',
|
|
111
|
+
field: field,
|
|
112
|
+
indexA: indexA,
|
|
113
|
+
indexB: indexB
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function arrayUnshift(field, value) {
|
|
117
|
+
return {
|
|
118
|
+
type: 'arrayUnshift',
|
|
119
|
+
field: field,
|
|
120
|
+
value: value
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function arrayUnshiftRaw(field, rawValue) {
|
|
124
|
+
return {
|
|
125
|
+
type: 'arrayUnshiftRaw',
|
|
126
|
+
field: field,
|
|
127
|
+
rawValue: rawValue
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
var arrayActions = exports.arrayActions = {
|
|
131
|
+
insert: arrayInsert,
|
|
132
|
+
insertRaw: arrayInsertRaw,
|
|
133
|
+
move: arrayMove,
|
|
134
|
+
pop: arrayPop,
|
|
135
|
+
push: arrayPush,
|
|
136
|
+
pushRaw: arrayPushRaw,
|
|
137
|
+
remove: arrayRemove,
|
|
138
|
+
removeAll: arrayRemoveAll,
|
|
139
|
+
shift: arrayShift,
|
|
140
|
+
splice: arraySplice,
|
|
141
|
+
spliceRaw: arraySpliceRaw,
|
|
142
|
+
swap: arraySwap,
|
|
143
|
+
unshift: arrayUnshift,
|
|
144
|
+
unshiftRaw: arrayUnshiftRaw
|
|
145
|
+
};
|
|
146
|
+
//# sourceMappingURL=arrayActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrayActions.js","names":["arrayInsert","field","index","value","type","arrayInsertRaw","rawValue","arrayMove","from","to","arrayPop","arrayPush","arrayPushRaw","arrayRemove","arrayRemoveAll","arrayShift","arraySplice","deleteCount","_len","arguments","length","values","Array","_key","arraySpliceRaw","_len2","rawValues","_key2","arraySwap","indexA","indexB","arrayUnshift","arrayUnshiftRaw","arrayActions","exports","insert","insertRaw","move","pop","push","pushRaw","remove","removeAll","shift","splice","spliceRaw","swap","unshift","unshiftRaw"],"sources":["../../src/actions/arrayActions.ts"],"sourcesContent":["import { FieldPathForValue } from '../FieldPath'\nimport z from 'zod'\n\nexport type ArrayFieldPath<V = any, R = any> = FieldPathForValue<\n V[] | null | undefined,\n R[] | null | undefined\n>\n\ntype ValueFor<Field extends ArrayFieldPath> = NonNullable<\n z.output<Field['schema']>\n>[number]\n\ntype RawValueFor<Field extends ArrayFieldPath> = NonNullable<\n z.input<Field['schema']>\n>[number]\n\nexport type ArrayInsertAction<Field extends ArrayFieldPath = ArrayFieldPath> =\n ReturnType<typeof arrayInsert<Field>>\n\nexport function arrayInsert<Field extends ArrayFieldPath>(\n field: Field,\n index: number,\n value: ValueFor<Field>\n) {\n return { type: 'arrayInsert', field, index, value } as const\n}\n\nexport type ArrayInsertRawAction<\n Field extends ArrayFieldPath = ArrayFieldPath\n> = ReturnType<typeof arrayInsertRaw<Field>>\n\nexport function arrayInsertRaw<Field extends ArrayFieldPath>(\n field: Field,\n index: number,\n rawValue: RawValueFor<Field>\n) {\n return { type: 'arrayInsertRaw', field, index, rawValue } as const\n}\n\nexport type ArrayMoveAction = ReturnType<typeof arrayMove>\n\nexport function arrayMove(field: ArrayFieldPath, from: number, to: number) {\n return { type: 'arrayMove', field, from, to } as const\n}\n\nexport type ArrayPopAction = ReturnType<typeof arrayPop>\n\nexport function arrayPop(field: ArrayFieldPath) {\n return { type: 'arrayPop', field } as const\n}\n\nexport type ArrayPushAction<Field extends ArrayFieldPath = ArrayFieldPath> =\n ReturnType<typeof arrayPush<Field>>\n\nexport function arrayPush<Field extends ArrayFieldPath>(\n field: Field,\n value: ValueFor<Field>\n) {\n return { type: 'arrayPush', field, value } as const\n}\n\nexport type ArrayPushRawAction<Field extends ArrayFieldPath = ArrayFieldPath> =\n ReturnType<typeof arrayPushRaw<Field>>\n\nexport function arrayPushRaw<Field extends ArrayFieldPath>(\n field: Field,\n rawValue: RawValueFor<Field>\n) {\n return { type: 'arrayPushRaw', field, rawValue } as const\n}\n\nexport type ArrayRemoveAction = ReturnType<typeof arrayRemove>\n\nexport function arrayRemove(field: ArrayFieldPath, index: number) {\n return { type: 'arrayRemove', field, index } as const\n}\n\nexport type ArrayRemoveAllAction = ReturnType<typeof arrayRemoveAll>\n\nexport function arrayRemoveAll(field: ArrayFieldPath) {\n return { type: 'arrayRemoveAll', field } as const\n}\n\nexport type ArrayShiftAction = ReturnType<typeof arrayShift>\n\nexport function arrayShift(field: ArrayFieldPath) {\n return { type: 'arrayShift', field } as const\n}\n\nexport type ArraySpliceAction<Field extends ArrayFieldPath = ArrayFieldPath> =\n ReturnType<typeof arraySplice<Field>>\n\nexport function arraySplice<Field extends ArrayFieldPath>(\n field: Field,\n index: number,\n deleteCount: number,\n ...values: ValueFor<Field>[]\n) {\n return { type: 'arraySplice', field, index, deleteCount, values } as const\n}\n\nexport type ArraySpliceRawAction<\n Field extends ArrayFieldPath = ArrayFieldPath\n> = ReturnType<typeof arraySpliceRaw<Field>>\n\nexport function arraySpliceRaw<Field extends ArrayFieldPath>(\n field: Field,\n index: number,\n deleteCount: number,\n ...rawValues: RawValueFor<Field>[]\n) {\n return {\n type: 'arraySpliceRaw',\n field,\n index,\n deleteCount,\n rawValues,\n } as const\n}\n\nexport type ArraySwapAction = ReturnType<typeof arraySwap>\n\nexport function arraySwap(\n field: ArrayFieldPath,\n indexA: number,\n indexB: number\n) {\n return { type: 'arraySwap', field, indexA, indexB } as const\n}\n\nexport type ArrayUnshiftAction<Field extends ArrayFieldPath = ArrayFieldPath> =\n ReturnType<typeof arrayUnshift<Field>>\n\nexport function arrayUnshift<Field extends ArrayFieldPath>(\n field: Field,\n value: ValueFor<Field>\n) {\n return { type: 'arrayUnshift', field, value } as const\n}\n\nexport type ArrayUnshiftRawAction<\n Field extends ArrayFieldPath = ArrayFieldPath\n> = ReturnType<typeof arrayUnshiftRaw<Field>>\n\nexport function arrayUnshiftRaw<Field extends ArrayFieldPath>(\n field: Field,\n rawValue: RawValueFor<Field>\n) {\n return { type: 'arrayUnshiftRaw', field, rawValue } as const\n}\n\nexport type ArrayAction<Field extends ArrayFieldPath = ArrayFieldPath> =\n | ArrayInsertAction<Field>\n | ArrayInsertRawAction<Field>\n | ArrayMoveAction\n | ArrayPopAction\n | ArrayPushAction<Field>\n | ArrayPushRawAction<Field>\n | ArrayRemoveAction\n | ArrayRemoveAllAction\n | ArrayShiftAction\n | ArraySpliceAction<Field>\n | ArraySpliceRawAction<Field>\n | ArraySwapAction\n | ArrayUnshiftAction<Field>\n | ArrayUnshiftRawAction<Field>\n\nexport const arrayActions = {\n insert: arrayInsert,\n insertRaw: arrayInsertRaw,\n move: arrayMove,\n pop: arrayPop,\n push: arrayPush,\n pushRaw: arrayPushRaw,\n remove: arrayRemove,\n removeAll: arrayRemoveAll,\n shift: arrayShift,\n splice: arraySplice,\n spliceRaw: arraySpliceRaw,\n swap: arraySwap,\n unshift: arrayUnshift,\n unshiftRaw: arrayUnshiftRaw,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBO,SAASA,WAAWA,CACzBC,KAAY,EACZC,KAAa,EACbC,KAAsB,EACtB;EACA,OAAO;IAAEC,IAAI,EAAE,aAAa;IAAEH,KAAK,EAALA,KAAK;IAAEC,KAAK,EAALA,KAAK;IAAEC,KAAK,EAALA;EAAM,CAAC;AACrD;AAMO,SAASE,cAAcA,CAC5BJ,KAAY,EACZC,KAAa,EACbI,QAA4B,EAC5B;EACA,OAAO;IAAEF,IAAI,EAAE,gBAAgB;IAAEH,KAAK,EAALA,KAAK;IAAEC,KAAK,EAALA,KAAK;IAAEI,QAAQ,EAARA;EAAS,CAAC;AAC3D;AAIO,SAASC,SAASA,CAACN,KAAqB,EAAEO,IAAY,EAAEC,EAAU,EAAE;EACzE,OAAO;IAAEL,IAAI,EAAE,WAAW;IAAEH,KAAK,EAALA,KAAK;IAAEO,IAAI,EAAJA,IAAI;IAAEC,EAAE,EAAFA;EAAG,CAAC;AAC/C;AAIO,SAASC,QAAQA,CAACT,KAAqB,EAAE;EAC9C,OAAO;IAAEG,IAAI,EAAE,UAAU;IAAEH,KAAK,EAALA;EAAM,CAAC;AACpC;AAKO,SAASU,SAASA,CACvBV,KAAY,EACZE,KAAsB,EACtB;EACA,OAAO;IAAEC,IAAI,EAAE,WAAW;IAAEH,KAAK,EAALA,KAAK;IAAEE,KAAK,EAALA;EAAM,CAAC;AAC5C;AAKO,SAASS,YAAYA,CAC1BX,KAAY,EACZK,QAA4B,EAC5B;EACA,OAAO;IAAEF,IAAI,EAAE,cAAc;IAAEH,KAAK,EAALA,KAAK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EAAXA,WAAW;IACXS,SAAS,EAATA;EACF,CAAC;AACH;AAIO,SAASE,SAASA,CACvB3B,KAAqB,EACrB4B,MAAc,EACdC,MAAc,EACd;EACA,OAAO;IAAE1B,IAAI,EAAE,WAAW;IAAEH,KAAK,EAALA,KAAK;IAAE4B,MAAM,EAANA,MAAM;IAAEC,MAAM,EAANA;EAAO,CAAC;AACrD;AAKO,SAASC,YAAYA,CAC1B9B,KAAY,EACZE,KAAsB,EACtB;EACA,OAAO;IAAEC,IAAI,EAAE,cAAc;IAAEH,KAAK,EAALA,KAAK;IAAEE,KAAK,EAALA;EAAM,CAAC;AAC/C;AAMO,SAAS6B,eAAeA,CAC7B/B,KAAY,EACZK,QAA4B,EAC5B;EACA,OAAO;IAAEF,IAAI,EAAE,iBAAiB;IAAEH,KAAK,EAALA,KAAK;IAAEK,QAAQ,EAARA;EAAS,CAAC;AACrD;AAkBO,IAAM2B,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG;EAC1BE,MAAM,EAAEnC,WAAW;EACnBoC,SAAS,EAAE/B,cAAc;EACzBgC,IAAI,EAAE9B,SAAS;EACf+B,GAAG,EAAE5B,QAAQ;EACb6B,IAAI,EAAE5B,SAAS;EACf6B,OAAO,EAAE5B,YAAY;EACrB6B,MAAM,EAAE5B,WAAW;EACnB6B,SAAS,EAAE5B,cAAc;EACzB6B,KAAK,EAAE5B,UAAU;EACjB6B,MAAM,EAAE5B,WAAW;EACnB6B,SAAS,EAAErB,cAAc;EACzBsB,IAAI,EAAElB,SAAS;EACfmB,OAAO,EAAEhB,YAAY;EACrBiB,UAAU,EAAEhB;AACd,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
export function arrayInsert(field, index, value) {
|
|
2
|
+
return {
|
|
3
|
+
type: 'arrayInsert',
|
|
4
|
+
field,
|
|
5
|
+
index,
|
|
6
|
+
value
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function arrayInsertRaw(field, index, rawValue) {
|
|
10
|
+
return {
|
|
11
|
+
type: 'arrayInsertRaw',
|
|
12
|
+
field,
|
|
13
|
+
index,
|
|
14
|
+
rawValue
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function arrayMove(field, from, to) {
|
|
18
|
+
return {
|
|
19
|
+
type: 'arrayMove',
|
|
20
|
+
field,
|
|
21
|
+
from,
|
|
22
|
+
to
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function arrayPop(field) {
|
|
26
|
+
return {
|
|
27
|
+
type: 'arrayPop',
|
|
28
|
+
field
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function arrayPush(field, value) {
|
|
32
|
+
return {
|
|
33
|
+
type: 'arrayPush',
|
|
34
|
+
field,
|
|
35
|
+
value
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function arrayPushRaw(field, rawValue) {
|
|
39
|
+
return {
|
|
40
|
+
type: 'arrayPushRaw',
|
|
41
|
+
field,
|
|
42
|
+
rawValue
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function arrayRemove(field, index) {
|
|
46
|
+
return {
|
|
47
|
+
type: 'arrayRemove',
|
|
48
|
+
field,
|
|
49
|
+
index
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export function arrayRemoveAll(field) {
|
|
53
|
+
return {
|
|
54
|
+
type: 'arrayRemoveAll',
|
|
55
|
+
field
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function arrayShift(field) {
|
|
59
|
+
return {
|
|
60
|
+
type: 'arrayShift',
|
|
61
|
+
field
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function arraySplice(field, index, deleteCount, ...values) {
|
|
65
|
+
return {
|
|
66
|
+
type: 'arraySplice',
|
|
67
|
+
field,
|
|
68
|
+
index,
|
|
69
|
+
deleteCount,
|
|
70
|
+
values
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function arraySpliceRaw(field, index, deleteCount, ...rawValues) {
|
|
74
|
+
return {
|
|
75
|
+
type: 'arraySpliceRaw',
|
|
76
|
+
field,
|
|
77
|
+
index,
|
|
78
|
+
deleteCount,
|
|
79
|
+
rawValues
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export function arraySwap(field, indexA, indexB) {
|
|
83
|
+
return {
|
|
84
|
+
type: 'arraySwap',
|
|
85
|
+
field,
|
|
86
|
+
indexA,
|
|
87
|
+
indexB
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export function arrayUnshift(field, value) {
|
|
91
|
+
return {
|
|
92
|
+
type: 'arrayUnshift',
|
|
93
|
+
field,
|
|
94
|
+
value
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export function arrayUnshiftRaw(field, rawValue) {
|
|
98
|
+
return {
|
|
99
|
+
type: 'arrayUnshiftRaw',
|
|
100
|
+
field,
|
|
101
|
+
rawValue
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export const arrayActions = {
|
|
105
|
+
insert: arrayInsert,
|
|
106
|
+
insertRaw: arrayInsertRaw,
|
|
107
|
+
move: arrayMove,
|
|
108
|
+
pop: arrayPop,
|
|
109
|
+
push: arrayPush,
|
|
110
|
+
pushRaw: arrayPushRaw,
|
|
111
|
+
remove: arrayRemove,
|
|
112
|
+
removeAll: arrayRemoveAll,
|
|
113
|
+
shift: arrayShift,
|
|
114
|
+
splice: arraySplice,
|
|
115
|
+
spliceRaw: arraySpliceRaw,
|
|
116
|
+
swap: arraySwap,
|
|
117
|
+
unshift: arrayUnshift,
|
|
118
|
+
unshiftRaw: arrayUnshiftRaw
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=arrayActions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrayActions.mjs","names":["arrayInsert","field","index","value","type","arrayInsertRaw","rawValue","arrayMove","from","to","arrayPop","arrayPush","arrayPushRaw","arrayRemove","arrayRemoveAll","arrayShift","arraySplice","deleteCount","values","arraySpliceRaw","rawValues","arraySwap","indexA","indexB","arrayUnshift","arrayUnshiftRaw","arrayActions","insert","insertRaw","move","pop","push","pushRaw","remove","removeAll","shift","splice","spliceRaw","swap","unshift","unshiftRaw"],"sources":["../../src/actions/arrayActions.ts"],"sourcesContent":["import { FieldPathForValue } from '../FieldPath'\nimport z from 'zod'\n\nexport type ArrayFieldPath<V = any, R = any> = FieldPathForValue<\n V[] | null | undefined,\n R[] | null | undefined\n>\n\ntype ValueFor<Field extends ArrayFieldPath> = NonNullable<\n z.output<Field['schema']>\n>[number]\n\ntype RawValueFor<Field extends ArrayFieldPath> = NonNullable<\n z.input<Field['schema']>\n>[number]\n\nexport type ArrayInsertAction<Field extends ArrayFieldPath = ArrayFieldPath> =\n ReturnType<typeof arrayInsert<Field>>\n\nexport function arrayInsert<Field extends ArrayFieldPath>(\n field: Field,\n index: number,\n value: ValueFor<Field>\n) {\n return { type: 'arrayInsert', field, index, value } as const\n}\n\nexport type ArrayInsertRawAction<\n Field extends ArrayFieldPath = ArrayFieldPath\n> = ReturnType<typeof arrayInsertRaw<Field>>\n\nexport function arrayInsertRaw<Field extends ArrayFieldPath>(\n field: Field,\n index: number,\n rawValue: RawValueFor<Field>\n) {\n return { type: 'arrayInsertRaw', field, index, rawValue } as const\n}\n\nexport type ArrayMoveAction = ReturnType<typeof arrayMove>\n\nexport function arrayMove(field: ArrayFieldPath, from: number, to: number) {\n return { type: 'arrayMove', field, from, to } as const\n}\n\nexport type ArrayPopAction = ReturnType<typeof arrayPop>\n\nexport function arrayPop(field: ArrayFieldPath) {\n return { type: 'arrayPop', field } as const\n}\n\nexport type ArrayPushAction<Field extends ArrayFieldPath = ArrayFieldPath> =\n ReturnType<typeof arrayPush<Field>>\n\nexport function arrayPush<Field extends ArrayFieldPath>(\n field: Field,\n value: ValueFor<Field>\n) {\n return { type: 'arrayPush', field, value } as const\n}\n\nexport type ArrayPushRawAction<Field extends ArrayFieldPath = ArrayFieldPath> =\n ReturnType<typeof arrayPushRaw<Field>>\n\nexport function arrayPushRaw<Field extends ArrayFieldPath>(\n field: Field,\n rawValue: RawValueFor<Field>\n) {\n return { type: 'arrayPushRaw', field, rawValue } as const\n}\n\nexport type ArrayRemoveAction = ReturnType<typeof arrayRemove>\n\nexport function arrayRemove(field: ArrayFieldPath, index: number) {\n return { type: 'arrayRemove', field, index } as const\n}\n\nexport type ArrayRemoveAllAction = ReturnType<typeof arrayRemoveAll>\n\nexport function arrayRemoveAll(field: ArrayFieldPath) {\n return { type: 'arrayRemoveAll', field } as const\n}\n\nexport type ArrayShiftAction = ReturnType<typeof arrayShift>\n\nexport function arrayShift(field: ArrayFieldPath) {\n return { type: 'arrayShift', field } as const\n}\n\nexport type ArraySpliceAction<Field extends ArrayFieldPath = ArrayFieldPath> =\n ReturnType<typeof arraySplice<Field>>\n\nexport function arraySplice<Field extends ArrayFieldPath>(\n field: Field,\n index: number,\n deleteCount: number,\n ...values: ValueFor<Field>[]\n) {\n return { type: 'arraySplice', field, index, deleteCount, values } as const\n}\n\nexport type ArraySpliceRawAction<\n Field extends ArrayFieldPath = ArrayFieldPath\n> = ReturnType<typeof arraySpliceRaw<Field>>\n\nexport function arraySpliceRaw<Field extends ArrayFieldPath>(\n field: Field,\n index: number,\n deleteCount: number,\n ...rawValues: RawValueFor<Field>[]\n) {\n return {\n type: 'arraySpliceRaw',\n field,\n index,\n deleteCount,\n rawValues,\n } as const\n}\n\nexport type ArraySwapAction = ReturnType<typeof arraySwap>\n\nexport function arraySwap(\n field: ArrayFieldPath,\n indexA: number,\n indexB: number\n) {\n return { type: 'arraySwap', field, indexA, indexB } as const\n}\n\nexport type ArrayUnshiftAction<Field extends ArrayFieldPath = ArrayFieldPath> =\n ReturnType<typeof arrayUnshift<Field>>\n\nexport function arrayUnshift<Field extends ArrayFieldPath>(\n field: Field,\n value: ValueFor<Field>\n) {\n return { type: 'arrayUnshift', field, value } as const\n}\n\nexport type ArrayUnshiftRawAction<\n Field extends ArrayFieldPath = ArrayFieldPath\n> = ReturnType<typeof arrayUnshiftRaw<Field>>\n\nexport function arrayUnshiftRaw<Field extends ArrayFieldPath>(\n field: Field,\n rawValue: RawValueFor<Field>\n) {\n return { type: 'arrayUnshiftRaw', field, rawValue } as const\n}\n\nexport type ArrayAction<Field extends ArrayFieldPath = ArrayFieldPath> =\n | ArrayInsertAction<Field>\n | ArrayInsertRawAction<Field>\n | ArrayMoveAction\n | ArrayPopAction\n | ArrayPushAction<Field>\n | ArrayPushRawAction<Field>\n | ArrayRemoveAction\n | ArrayRemoveAllAction\n | ArrayShiftAction\n | ArraySpliceAction<Field>\n | ArraySpliceRawAction<Field>\n | ArraySwapAction\n | ArrayUnshiftAction<Field>\n | ArrayUnshiftRawAction<Field>\n\nexport const arrayActions = {\n insert: arrayInsert,\n insertRaw: arrayInsertRaw,\n move: arrayMove,\n pop: arrayPop,\n push: arrayPush,\n pushRaw: arrayPushRaw,\n remove: arrayRemove,\n removeAll: arrayRemoveAll,\n shift: arrayShift,\n splice: arraySplice,\n spliceRaw: arraySpliceRaw,\n swap: arraySwap,\n unshift: arrayUnshift,\n unshiftRaw: arrayUnshiftRaw,\n}\n"],"mappings":"AAmBA,OAAO,SAASA,WAAWA,CACzBC,KAAY,EACZC,KAAa,EACbC,KAAsB,EACtB;EACA,OAAO;IAAEC,IAAI,EAAE,aAAa;IAAEH,KAAK;IAAEC,KAAK;IAAEC;EAAM,CAAC;AACrD;AAMA,OAAO,SAASE,cAAcA,CAC5BJ,KAAY,EACZC,KAAa,EACbI,QAA4B,EAC5B;EACA,OAAO;IAAEF,IAAI,EAAE,gBAAgB;IAAEH,KAAK;IAAEC,KAAK;IAAEI;EAAS,CAAC;AAC3D;AAIA,OAAO,SAASC,SAASA,CAACN,KAAqB,EAAEO,IAAY,EAAEC,EAAU,EAAE;EACzE,OAAO;IAAEL,IAAI,EAAE,WAAW;IAAEH,KAAK;IAAEO,IAAI;IAAEC;EAAG,CAAC;AAC/C;AAIA,OAAO,SAASC,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