@donotdev/crud 0.2.3 → 0.3.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/dist/CrudService.bulk.d.ts +13 -14
- package/dist/CrudService.bulk.d.ts.map +1 -1
- package/dist/CrudService.bulk.js +1 -1
- package/dist/CrudService.bulkAcross.d.ts +12 -7
- package/dist/CrudService.bulkAcross.d.ts.map +1 -1
- package/dist/CrudService.bulkAcross.js +1 -1
- package/dist/CrudService.bulkReconciliation.d.ts +4 -0
- package/dist/CrudService.bulkReconciliation.d.ts.map +1 -0
- package/dist/CrudService.bulkReconciliation.js +1 -0
- package/dist/CrudService.cache.d.ts +1 -1
- package/dist/CrudService.cache.d.ts.map +1 -1
- package/dist/CrudService.cache.js +1 -1
- package/dist/CrudService.d.ts +35 -6
- package/dist/CrudService.d.ts.map +1 -1
- package/dist/CrudService.js +1 -1
- package/dist/CrudService.mutations.d.ts +3 -3
- package/dist/CrudService.mutations.d.ts.map +1 -1
- package/dist/CrudService.mutations.js +1 -1
- package/dist/CrudService.optimistic.d.ts +2 -2
- package/dist/CrudService.optimistic.d.ts.map +1 -1
- package/dist/CrudService.optimistic.js +1 -1
- package/dist/CrudService.subscriptions.js +1 -1
- package/dist/CrudService.writeRules.d.ts +57 -0
- package/dist/CrudService.writeRules.d.ts.map +1 -0
- package/dist/CrudService.writeRules.js +1 -0
- package/dist/CrudService.writeSchema.d.ts +64 -0
- package/dist/CrudService.writeSchema.d.ts.map +1 -0
- package/dist/CrudService.writeSchema.js +1 -0
- package/dist/CrudStore.d.ts +10 -1
- package/dist/CrudStore.d.ts.map +1 -1
- package/dist/CrudStore.js +1 -1
- package/dist/FieldRegistry.d.ts +1 -1
- package/dist/FieldRegistry.d.ts.map +1 -1
- package/dist/adapters/FunctionsAdapter.d.ts +3 -3
- package/dist/adapters/FunctionsAdapter.d.ts.map +1 -1
- package/dist/adapters/FunctionsAdapter.js +1 -1
- package/dist/components/CrudButton.d.ts +3 -2
- package/dist/components/CrudButton.d.ts.map +1 -1
- package/dist/components/CrudCard.d.ts.map +1 -1
- package/dist/components/CrudCard.js +1 -1
- package/dist/components/DateFilter.js +1 -1
- package/dist/components/EntityFilters.d.ts +23 -4
- package/dist/components/EntityFilters.d.ts.map +1 -1
- package/dist/components/EntityFilters.js +1 -1
- package/dist/components/FormFieldRenderer.d.ts +21 -4
- package/dist/components/FormFieldRenderer.d.ts.map +1 -1
- package/dist/components/FormFieldRenderer.js +1 -1
- package/dist/components/FormLayout.d.ts.map +1 -1
- package/dist/components/FormLayout.js +1 -1
- package/dist/components/SortableCardList.d.ts +47 -0
- package/dist/components/SortableCardList.d.ts.map +1 -0
- package/dist/components/SortableCardList.js +1 -0
- package/dist/components/YearFilter.js +1 -1
- package/dist/components/controlled/complex/ControlledAddressField.d.ts.map +1 -1
- package/dist/components/controlled/complex/ControlledAddressField.js +1 -1
- package/dist/components/controlled/complex/ControlledDateField.d.ts.map +1 -1
- package/dist/components/controlled/complex/ControlledDateField.js +1 -1
- package/dist/components/controlled/complex/ControlledFieldArrayField.d.ts +9 -0
- package/dist/components/controlled/complex/ControlledFieldArrayField.d.ts.map +1 -1
- package/dist/components/controlled/complex/ControlledFieldArrayField.js +1 -1
- package/dist/components/controlled/complex/ControlledMultiInputField.d.ts.map +1 -1
- package/dist/components/controlled/complex/ControlledMultiInputField.js +1 -1
- package/dist/components/controlled/complex/ControlledTimestampField.d.ts.map +1 -1
- package/dist/components/controlled/complex/ControlledTimestampField.js +1 -1
- package/dist/components/controlled/fieldOptions.d.ts +9 -0
- package/dist/components/controlled/fieldOptions.d.ts.map +1 -1
- package/dist/components/controlled/fieldOptions.js +1 -1
- package/dist/components/controlled/file/ControlledImageField.js +1 -1
- package/dist/components/controlled/input/ControlledCurrencyField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledCurrencyField.js +1 -1
- package/dist/components/controlled/input/ControlledDurationField.js +1 -1
- package/dist/components/controlled/input/ControlledNumberField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledNumberField.js +1 -1
- package/dist/components/controlled/input/ControlledPasswordField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledPasswordField.js +1 -1
- package/dist/components/controlled/input/ControlledPhoneField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledPhoneField.js +1 -1
- package/dist/components/controlled/input/ControlledPriceField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledPriceField.js +1 -1
- package/dist/components/controlled/input/ControlledRatingField.js +1 -1
- package/dist/components/controlled/input/ControlledTextField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledTextField.js +1 -1
- package/dist/components/controlled/input/ControlledTextareaField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledTextareaField.js +1 -1
- package/dist/components/controlled/select/ControlledComboboxField.d.ts.map +1 -1
- package/dist/components/controlled/select/ControlledComboboxField.js +1 -1
- package/dist/components/controlled/select/ControlledDropdownField.d.ts.map +1 -1
- package/dist/components/controlled/select/ControlledDropdownField.js +1 -1
- package/dist/components/controlled/select/ControlledMultiDropdownField.d.ts.map +1 -1
- package/dist/components/controlled/select/ControlledMultiDropdownField.js +1 -1
- package/dist/components/controlled/select/ControlledReferenceField.d.ts.map +1 -1
- package/dist/components/controlled/select/ControlledReferenceField.js +1 -1
- package/dist/components/controlled/select/ControlledYearField.d.ts.map +1 -1
- package/dist/components/controlled/select/ControlledYearField.js +1 -1
- package/dist/components/fields/display/BadgeFieldDisplay.js +1 -1
- package/dist/components/fields/display/CheckboxFieldDisplay.js +1 -1
- package/dist/components/fields/display/MapFieldDisplay.js +1 -1
- package/dist/components/fields/display/NumberFieldDisplay.js +1 -1
- package/dist/components/fields/display/PasswordFieldDisplay.js +1 -1
- package/dist/components/fields/display/TextFieldDisplay.js +1 -1
- package/dist/components/form/fields/AddressFieldComponent.d.ts +3 -1
- package/dist/components/form/fields/AddressFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/AddressFieldComponent.js +1 -1
- package/dist/components/form/fields/ComboboxComponent.d.ts +2 -0
- package/dist/components/form/fields/ComboboxComponent.d.ts.map +1 -1
- package/dist/components/form/fields/ComboboxComponent.js +1 -1
- package/dist/components/form/fields/CurrencyFieldComponent.d.ts +2 -0
- package/dist/components/form/fields/CurrencyFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/CurrencyFieldComponent.js +1 -1
- package/dist/components/form/fields/DateFieldComponent.d.ts +2 -0
- package/dist/components/form/fields/DateFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/DateFieldComponent.js +1 -1
- package/dist/components/form/fields/DocumentFieldComponent.js +1 -1
- package/dist/components/form/fields/DropdownComponent.d.ts +2 -0
- package/dist/components/form/fields/DropdownComponent.d.ts.map +1 -1
- package/dist/components/form/fields/DropdownComponent.js +1 -1
- package/dist/components/form/fields/DurationFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/DurationFieldComponent.js +1 -1
- package/dist/components/form/fields/FileFieldComponent.js +1 -1
- package/dist/components/form/fields/GdprConsentFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/GdprConsentFieldComponent.js +1 -1
- package/dist/components/form/fields/GeoPointFieldComponent.js +1 -1
- package/dist/components/form/fields/ImageFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/ImageFieldComponent.js +1 -1
- package/dist/components/form/fields/MultiDropdownComponent.d.ts +2 -0
- package/dist/components/form/fields/MultiDropdownComponent.d.ts.map +1 -1
- package/dist/components/form/fields/MultiDropdownComponent.js +1 -1
- package/dist/components/form/fields/MultiInputTextFieldComponent.d.ts +2 -0
- package/dist/components/form/fields/MultiInputTextFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/MultiInputTextFieldComponent.js +1 -1
- package/dist/components/form/fields/NumberFieldComponent.d.ts +2 -0
- package/dist/components/form/fields/NumberFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/NumberFieldComponent.js +1 -1
- package/dist/components/form/fields/PasswordFieldComponent.d.ts +2 -0
- package/dist/components/form/fields/PasswordFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/PasswordFieldComponent.js +1 -1
- package/dist/components/form/fields/PhoneNumberComponent.d.ts +11 -1
- package/dist/components/form/fields/PhoneNumberComponent.d.ts.map +1 -1
- package/dist/components/form/fields/PhoneNumberComponent.js +1 -1
- package/dist/components/form/fields/PriceFieldComponent.d.ts +2 -0
- package/dist/components/form/fields/PriceFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/PriceFieldComponent.js +1 -1
- package/dist/components/form/fields/RangeFieldComponent.js +1 -1
- package/dist/components/form/fields/ReferenceFieldComponent.d.ts +3 -1
- package/dist/components/form/fields/ReferenceFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/ReferenceFieldComponent.js +1 -1
- package/dist/components/form/fields/RichTextComponent.js +1 -1
- package/dist/components/form/fields/TextAreaComponent.d.ts +2 -0
- package/dist/components/form/fields/TextAreaComponent.d.ts.map +1 -1
- package/dist/components/form/fields/TextAreaComponent.js +1 -1
- package/dist/components/form/fields/TextFieldComponent.d.ts +3 -1
- package/dist/components/form/fields/TextFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/TextFieldComponent.js +1 -1
- package/dist/components/form/fields/TimestampFieldComponent.d.ts +2 -0
- package/dist/components/form/fields/TimestampFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/TimestampFieldComponent.js +1 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/fieldTypeRegistry.d.ts +2 -2
- package/dist/fieldTypeRegistry.d.ts.map +1 -1
- package/dist/fieldTypeRegistry.js +1 -1
- package/dist/fieldTypeRegistry.store.d.ts +0 -2
- package/dist/fieldTypeRegistry.store.d.ts.map +1 -1
- package/dist/fieldTypeRegistry.store.js +1 -1
- package/dist/fieldTypeRegistry.types.d.ts +8 -9
- package/dist/fieldTypeRegistry.types.d.ts.map +1 -1
- package/dist/forms/FormNavigation.d.ts +24 -0
- package/dist/forms/FormNavigation.d.ts.map +1 -0
- package/dist/forms/FormNavigation.js +1 -0
- package/dist/forms/childRows.d.ts +184 -0
- package/dist/forms/childRows.d.ts.map +1 -0
- package/dist/forms/childRows.js +1 -0
- package/dist/forms/extend.d.ts +88 -0
- package/dist/forms/extend.d.ts.map +1 -0
- package/dist/forms/extend.js +1 -0
- package/dist/forms/hooks/useEntityField.d.ts +11 -5
- package/dist/forms/hooks/useEntityField.d.ts.map +1 -1
- package/dist/forms/hooks/useEntityField.js +1 -1
- package/dist/forms/hooks/useEntityForm.d.ts +50 -5
- package/dist/forms/hooks/useEntityForm.d.ts.map +1 -1
- package/dist/forms/hooks/useEntityForm.js +1 -1
- package/dist/forms/hooks/useFormDraftState.d.ts +53 -0
- package/dist/forms/hooks/useFormDraftState.d.ts.map +1 -0
- package/dist/forms/hooks/useFormDraftState.js +1 -0
- package/dist/forms/index.d.ts +6 -2
- package/dist/forms/index.d.ts.map +1 -1
- package/dist/forms/index.js +1 -1
- package/dist/forms/types.d.ts +171 -25
- package/dist/forms/types.d.ts.map +1 -1
- package/dist/forms/utils/buildInitialValues.d.ts +32 -17
- package/dist/forms/utils/buildInitialValues.d.ts.map +1 -1
- package/dist/forms/utils/buildInitialValues.js +1 -1
- package/dist/forms/utils/conditionAwareResolver.d.ts +35 -0
- package/dist/forms/utils/conditionAwareResolver.d.ts.map +1 -0
- package/dist/forms/utils/conditionAwareResolver.js +1 -0
- package/dist/forms/utils/emptyValue.d.ts +34 -0
- package/dist/forms/utils/emptyValue.d.ts.map +1 -0
- package/dist/forms/utils/emptyValue.js +1 -0
- package/dist/forms/utils/getFieldsForOperation.d.ts +30 -19
- package/dist/forms/utils/getFieldsForOperation.d.ts.map +1 -1
- package/dist/forms/utils/getFieldsForOperation.js +1 -1
- package/dist/forms/utils/index.d.ts +1 -0
- package/dist/forms/utils/index.d.ts.map +1 -1
- package/dist/forms/utils/index.js +1 -1
- package/dist/forms/utils/isFieldEditable.d.ts +21 -22
- package/dist/forms/utils/isFieldEditable.d.ts.map +1 -1
- package/dist/forms/utils/isFieldEditable.js +1 -1
- package/dist/forms/utils/writableFields.d.ts +19 -0
- package/dist/forms/utils/writableFields.d.ts.map +1 -0
- package/dist/forms/utils/writableFields.js +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useChildRows.d.ts +161 -0
- package/dist/hooks/useChildRows.d.ts.map +1 -0
- package/dist/hooks/useChildRows.js +1 -0
- package/dist/hooks/useCrudFilters.d.ts +21 -1
- package/dist/hooks/useCrudFilters.d.ts.map +1 -1
- package/dist/hooks/useCrudFilters.js +1 -1
- package/dist/hooks/useExtensionRows.d.ts +24 -0
- package/dist/hooks/useExtensionRows.d.ts.map +1 -0
- package/dist/hooks/useExtensionRows.js +1 -0
- package/dist/hooks/useFieldConditions.d.ts +2 -2
- package/dist/hooks/useFieldConditions.d.ts.map +1 -1
- package/dist/hooks/useFieldConditions.js +1 -1
- package/dist/hooks/useReferenceResolver.d.ts +4 -1
- package/dist/hooks/useReferenceResolver.d.ts.map +1 -1
- package/dist/hooks/useReferenceResolver.js +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/registerBuiltinFieldTypes.d.ts +2 -0
- package/dist/registerBuiltinFieldTypes.d.ts.map +1 -1
- package/dist/registerBuiltinFieldTypes.js +1 -1
- package/dist/stores/FormStore.d.ts +116 -5
- package/dist/stores/FormStore.d.ts.map +1 -1
- package/dist/stores/FormStore.js +1 -1
- package/dist/stores/UploadStore.js +1 -1
- package/dist/stores/index.d.ts +1 -1
- package/dist/stores/index.d.ts.map +1 -1
- package/dist/stores/index.js +1 -1
- package/dist/symbol-index.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +38 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/useCrud.d.ts +7 -5
- package/dist/useCrud.d.ts.map +1 -1
- package/dist/useCrud.js +1 -1
- package/dist/useCrudDoc.js +1 -1
- package/dist/utils/clientListProcessing.d.ts +9 -12
- package/dist/utils/clientListProcessing.d.ts.map +1 -1
- package/dist/utils/clientListProcessing.js +1 -1
- package/dist/utils/collections.d.ts.map +1 -1
- package/dist/utils/collections.js +1 -1
- package/dist/utils/filterUrl.d.ts +45 -0
- package/dist/utils/filterUrl.d.ts.map +1 -0
- package/dist/utils/filterUrl.js +1 -0
- package/dist/utils/matchesFilter.d.ts +27 -3
- package/dist/utils/matchesFilter.d.ts.map +1 -1
- package/dist/utils/matchesFilter.js +1 -1
- package/dist/utils/uploadValidation.js +1 -1
- package/dist/utils/useRowTranslator.js +1 -1
- package/guidelines/COMPONENTS.md +82 -11
- package/guidelines/CRUD.md +242 -7
- package/guidelines/GOTCHAS.md +17 -1
- package/package.json +3 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FieldPath } from 'react-hook-form';
|
|
2
|
+
import type { AnyEntity, EntityExtensions, FieldOperation } from '@donotdev/core';
|
|
2
3
|
import type { EntityFormReturn, InferEntityData, EntityFieldReturn } from '../types';
|
|
3
4
|
/**
|
|
4
5
|
* Granular hook for single field control within an entity form.
|
|
@@ -7,11 +8,16 @@ import type { EntityFormReturn, InferEntityData, EntityFieldReturn } from '../ty
|
|
|
7
8
|
* such as custom components, conditional logic, or complex layouts.
|
|
8
9
|
*
|
|
9
10
|
* Returns `{ field, meta, config, isEditable, isVisible, display }`.
|
|
10
|
-
* - `
|
|
11
|
+
* - `isEditable` / `isVisible`: as `form.fields` (entity descriptor, viewer role, operation).
|
|
12
|
+
* - `display(options?)` formats the value using the registered field type formatter:
|
|
13
|
+
* the form value for fields the form writes, `form.record` for the others
|
|
14
|
+
* (technical, `editable: false`, role-denied: not in form state).
|
|
11
15
|
*
|
|
12
16
|
* @template E - Entity type from defineEntity()
|
|
13
17
|
* @template K - Field key from entity
|
|
14
|
-
* @
|
|
18
|
+
* @template Op - The form's operation (inferred from `form`)
|
|
19
|
+
* @template X - The form's 1:1 extensions (inferred from `form`)
|
|
20
|
+
* @param form - Form instance from useEntityForm (any operation, any extensions)
|
|
15
21
|
* @param fieldName - Name of the field to control
|
|
16
22
|
* @returns Field state, config, editability info, and display formatter
|
|
17
23
|
*
|
|
@@ -50,9 +56,9 @@ import type { EntityFormReturn, InferEntityData, EntityFieldReturn } from '../ty
|
|
|
50
56
|
* @see {@link useEntityForm} for creating the form instance
|
|
51
57
|
* @see {@link EntityFieldReturn} for return type
|
|
52
58
|
*
|
|
53
|
-
* @version 0.
|
|
59
|
+
* @version 0.2.0
|
|
54
60
|
* @since 0.0.1
|
|
55
61
|
* @author AMBROISE PARK Consulting
|
|
56
62
|
*/
|
|
57
|
-
export declare function useEntityField<E extends AnyEntity, K extends keyof InferEntityData<E>>(form: EntityFormReturn<E>, fieldName: K): EntityFieldReturn<E, K>;
|
|
63
|
+
export declare function useEntityField<E extends AnyEntity, K extends string & keyof InferEntityData<E> & FieldPath<InferEntityData<E>>, Op extends FieldOperation = FieldOperation, X extends EntityExtensions = Record<never, never>>(form: EntityFormReturn<E, Op, X>, fieldName: K): EntityFieldReturn<E, K>;
|
|
58
64
|
//# sourceMappingURL=useEntityField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEntityField.d.ts","sourceRoot":"","sources":["../../../src/forms/hooks/useEntityField.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useEntityField.d.ts","sourceRoot":"","sources":["../../../src/forms/hooks/useEntityField.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAW,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAEhB,cAAc,EACf,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,wBAAgB,cAAc,CAC5B,CAAC,SAAS,SAAS,EACnB,CAAC,SAAS,MAAM,GAAG,MAAM,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAC3E,EAAE,SAAS,cAAc,GAAG,cAAc,EAC1C,CAAC,SAAS,gBAAgB,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACjD,IAAI,EAAE,gBAAgB,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,CAmEzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useMemo as
|
|
1
|
+
"use client";import{useMemo as l,useCallback as h}from"react";import{useController as p}from"./useController";import{formatValue as E}from"../../components/DisplayFieldRenderer";function D(r,e){const{entity:n,fields:d}=r,t=n.fields[e],o=l(()=>{if(!t)throw new Error(`useEntityField: entity "${n.name}" has no field "${e}".`);return{...t,name:t.name||e,label:t.label||e}},[e,t]),s=l(()=>d.find(a=>a.name===e),[d,e]),u=s!==void 0,c=s?.editable??!1,{field:m,fieldState:i}=p({name:e,control:r.control}),y=l(()=>({error:i.error?.message,touched:i.isTouched,isDirty:i.isDirty}),[i.error?.message,i.isTouched,i.isDirty]),f=s?.written?m.value:r.record?.[e],b=h(a=>E(f,o,r.t,a),[f,o,r.t]);return{field:m,meta:y,config:o,isEditable:c,isVisible:u,display:b}}export{D as useEntityField};
|
|
@@ -1,22 +1,67 @@
|
|
|
1
|
-
import type { AnyEntity } from '@donotdev/core';
|
|
1
|
+
import type { AnyEntity, EntityExtensions, FieldOperation } from '@donotdev/core';
|
|
2
2
|
import type { UseEntityFormOptions, EntityFormReturn } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Creates a type-safe form instance from an entity definition.
|
|
5
5
|
*
|
|
6
|
+
* Automatically binds translations to `[entity.namespace, 'crud']`, including
|
|
7
|
+
* language changes and the SSR request language. No `t` option is needed for
|
|
8
|
+
* normal framework usage; each entity form resolves its own namespace.
|
|
9
|
+
* Pass `options.t` only to override the default namespace resolution with your
|
|
10
|
+
* own translator. It replaces the default translator, rather than extending it.
|
|
11
|
+
* Pass the returned `form.t` to every FormFieldRenderer / DisplayFieldRenderer,
|
|
12
|
+
* including nested field-array fields. Do not duplicate entity labels in page locales.
|
|
13
|
+
* The viewer role is not inferred: pass the actual `viewerRole` (default: guest).
|
|
14
|
+
* Prefer EntityFormRenderer from @donotdev/ui when no custom layout is needed.
|
|
15
|
+
*
|
|
6
16
|
* Simple, predictable behavior:
|
|
7
|
-
* - Edit mode: defaultValues (DB object) is
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
17
|
+
* - Edit mode: defaultValues (DB object) is accepted as-is and becomes `form.record`;
|
|
18
|
+
* auto-save to FormStore
|
|
19
|
+
* - Create mode: schema/caller defaults, auto-save to FormStore
|
|
20
|
+
* - Draft restored on mount with dismissible toast (with the `form.record` it was
|
|
21
|
+
* saved with, so a concurrency token read from it stays the draft's base version)
|
|
22
|
+
*
|
|
23
|
+
* Form state, local draft and payload hold only the fields the form writes
|
|
24
|
+
* (entity descriptor, design 3.4): inputs editable for the viewer and operation,
|
|
25
|
+
* `editable: 'computed'` fields (shown read-only, written), their i18n companions,
|
|
26
|
+
* and `id` on edit. Generated, technical, `editable: false` and role-denied fields
|
|
27
|
+
* never enter them: read them from `form.record`. `handleSubmit(onValid)` passes
|
|
28
|
+
* `onValid` the resolver's output (`FormValues<E, Op, X>`; the extensions' values
|
|
29
|
+
* under their keys).
|
|
10
30
|
*
|
|
11
31
|
* When formId is provided:
|
|
12
32
|
* - Tracks form status (uploading/validating/submitting)
|
|
13
33
|
* - Orchestrates file uploads before validation
|
|
14
34
|
* - Provides cleanup function for unmount
|
|
15
35
|
*
|
|
36
|
+
* On a valid submit the page leaves for `successPath` (default: the previous
|
|
37
|
+
* breadcrumb) before the server answers, and returns on rejection. Pass
|
|
38
|
+
* `successPath: null` to stay.
|
|
39
|
+
*
|
|
40
|
+
* `handleSubmit()` without `onValid` uses the default writer: the record
|
|
41
|
+
* (update, or add on create) with the fields the form writes, plus the child
|
|
42
|
+
* rows joined to this form (`useChildRows` / a nested `EntityList`), in one
|
|
43
|
+
* `bulkAcross`. With `onValid`, write the joined rows from `form.pendingWrites()`
|
|
44
|
+
* (the submit fails explicitly when joined rows have edits and it was not read).
|
|
45
|
+
*
|
|
16
46
|
* @template E - Entity type from defineEntity()
|
|
47
|
+
* @template Op - Form operation (`options.operation`; both when not given)
|
|
48
|
+
* @template X - 1:1 extensions (`options.extend`), none by default
|
|
17
49
|
* @param entity - Entity definition from defineEntity()
|
|
18
50
|
* @param options - Form configuration options
|
|
19
51
|
* @returns Form instance with React Hook Form API plus entity-aware extensions
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* const viewerRole = useAuth('userRole');
|
|
56
|
+
* const form = useEntityForm(productEntity, {
|
|
57
|
+
* formId: 'product-create',
|
|
58
|
+
* operation: 'create',
|
|
59
|
+
* viewerRole,
|
|
60
|
+
* });
|
|
61
|
+
* // In the custom layout, for each editable field from form.fields:
|
|
62
|
+
* // <FormFieldRenderer name={field.name} config={field.config}
|
|
63
|
+
* // control={form.control} t={form.t} />
|
|
64
|
+
* ```
|
|
20
65
|
*/
|
|
21
|
-
export declare function useEntityForm<E extends AnyEntity
|
|
66
|
+
export declare function useEntityForm<E extends AnyEntity, Op extends FieldOperation = FieldOperation, const X extends EntityExtensions = Record<never, never>>(entity: E, options?: UseEntityFormOptions<E, Op, X>): EntityFormReturn<E, Op, X>;
|
|
22
67
|
//# sourceMappingURL=useEntityForm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEntityForm.d.ts","sourceRoot":"","sources":["../../../src/forms/hooks/useEntityForm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useEntityForm.d.ts","sourceRoot":"","sources":["../../../src/forms/hooks/useEntityForm.ts"],"names":[],"mappings":"AA0CA,OAAO,KAAK,EACV,SAAS,EAGT,gBAAgB,EAChB,cAAc,EAGf,MAAM,gBAAgB,CAAC;AAkCxB,OAAO,KAAK,EACV,oBAAoB,EAEpB,gBAAgB,EAGjB,MAAM,UAAU,CAAC;AA+GlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,wBAAgB,aAAa,CAC3B,CAAC,SAAS,SAAS,EACnB,EAAE,SAAS,cAAc,GAAG,cAAc,EAC1C,KAAK,CAAC,CAAC,SAAS,gBAAgB,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAEvD,MAAM,EAAE,CAAC,EACT,OAAO,GAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAM,GAC3C,gBAAgB,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAi0C5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{valibotResolver as B}from"@hookform/resolvers/valibot";import{useMemo as C,useEffect as O,useRef as y,createElement as ce}from"react";import{useForm as fe}from"react-hook-form";import{toast as G,ToastAction as de}from"@donotdev/components";import{BACKEND_GENERATED_FIELD_NAMES as me,createSchemas as ge}from"@donotdev/core";import{useFormStore as d,useFormStatus as pe,useUploadProgress as be}from"../../stores";import{useUploadStore as w}from"../../stores/UploadStore";import{checkForBlobUrls as Se,isStorageUrl as ye}from"../../utils/uploadValidation";import{getFieldsForOperation as he}from"../utils";import{buildInitialFromRecord as ve,buildSchemaDefaults as Ee}from"../utils/buildInitialValues";const je=t=>t;function K(t,f){const e={...t};for(const b of Object.keys(f)){const l=t[b],h=f[b];h!==null&&typeof h=="object"&&!Array.isArray(h)&&l!==null&&typeof l=="object"&&!Array.isArray(l)?e[b]=K(l,h):e[b]=h}return e}function L(t){if(t==null)return t;if(typeof t=="string")return t.startsWith("blob:")?null:t;if(Array.isArray(t)){const f=t.map(L).filter(e=>e!==null);return f.length>0?f:null}if(typeof t=="object"){const f=t;if("fullUrl"in f&&typeof f.fullUrl=="string")return ye(f.fullUrl)?f:null;const e={};for(const[b,l]of Object.entries(f))e[b]=L(l);return e}return t}function De(t,f={}){const{formId:e,operation:b,defaultValues:l,viewerRole:h,mode:W="onBlur",t:Y,loading:F=!1}=f,S=Y??je,N=h??"guest",c=b??(l?"edit":"create"),H=pe(e??""),J=be(e??""),T=C(()=>ge(t),[t.name]),Q=C(()=>{const r=B(T.create),o=B(T.draft),n=B(T.update);return async(a,s,i)=>c==="edit"?n(a,s,i):(a?.status??l?.status??"draft")==="draft"?o(a,s,i):r(a,s,i)},[T,c,l?.status]),A=C(()=>Ee(t),[t]),U=l,m=C(()=>{if(!F)return c==="edit"?U?ve(t,U):void 0:U?{...A,...U}:A},[F,c,A,t,U]),u=fe({defaultValues:c==="create"?m:void 0,mode:W,resolver:Q,shouldUnregister:!1,shouldFocusError:!0}),E=y(u);O(()=>{E.current=u},[u]);const I=y(null);O(()=>{if(c==="edit"&&m){const r=m.id??null;r&&r!==I.current?(E.current.reset(m),I.current=r):!r&&I.current===null&&(E.current.reset(m),I.current="initialized")}},[c,m]);const k=l?.id,x=`${t.name.toLowerCase()}-form-draft`,v=c==="create"?x:k?`${x}-${k}`:`${x}-edit`,j=y(!1),_=y(F);_.current&&!F&&(j.current=!1),_.current=F,O(()=>{if(j.current)return;const r=d.getState().loadDraft(v),o=n=>{const a=()=>{d.getState().clearDraft(v),n&&E.current.reset(n)};G({toastType:"info",title:S("draft.restored",{defaultValue:"Draft restored"}),description:S("draft.restoredDescription",{defaultValue:"Your unsaved changes were recovered"}),action:ce(de,{altText:S("draft.discard",{defaultValue:"Discard"}),onClick:a},S("draft.discard",{defaultValue:"Discard"})),duration:8e3})};if(c==="create"&&!l){r&&(u.reset(r.data),o(A)),j.current=!0;return}if(c==="edit"&&m){if(r){const n=K(m,r.data);u.reset(n),o(m)}j.current=!0}},[c,l,v,u,m,S,A]);const P=y(!1),V=y(null);O(()=>{const r=u.watch(o=>{P.current||!j.current||(V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{if(o&&Object.values(o).some(n=>n!=null&&n!=="")){const n=L(o);d.getState().saveDraft(v,n,t.name,k)}},3e3))});return()=>{r.unsubscribe(),V.current&&clearTimeout(V.current)}},[u,v,t.name,k]);const D=y(null),$=y(!1),X=async r=>{if(!e)return{};const o=w.getState(),n=d.getState();if(!o.hasPendingUploads(e))return{};const a=setInterval(()=>{const s=w.getState().getTotalProgress(e);d.getState().setUploading(e,s)},200);try{return n.setUploading(e,0),await o.uploadAll(e,r),r?.aborted?null:w.getState().getResults(e)}catch(s){const i=w.getState().uploads[e];i&&Object.entries(i).forEach(([g,R])=>{R.status==="error"&&R.error&&u.setError(g,{type:"upload",message:R.error})});const p=s instanceof Error?s.message:"File upload failed";return d.getState().setError(e,p),null}finally{clearInterval(a)}},Z=r=>c!=="create"?r:Object.fromEntries(Object.entries(r).filter(([o])=>!me.includes(o))),ee=(r,o)=>{const n={...o};for(const[a,s]of Object.entries(r.fields))if(s.type==="price"&&a in n){const i=n[a];(i==null||i.amount==null)&&(n[a]=null)}return n},te=r=>{if(typeof window>"u")return;const o=Object.keys(r).find(a=>a!=="root"&&r[a]);if(!o)return;const n=document.querySelector(`input[name="${o}"][aria-invalid="true"], textarea[name="${o}"][aria-invalid="true"], select[name="${o}"][aria-invalid="true"]`)??document.querySelector(`[name="${o}"]`);n&&(n.scrollIntoView({behavior:"smooth",block:"center"}),n.focus())},re=u.handleSubmit,ae=((r,o)=>async n=>{if(n?.preventDefault?.(),$.current)return;const a=e?d.getState():null;await re(async(s,i)=>{if($.current)return;$.current=!0,D.current?.abort();const p=new AbortController;D.current=p,P.current=!0;try{e&&a&&a.startSubmit(e);const g=await X(p.signal);if(g===null||p.signal.aborted)return;e&&a&&a.setSubmitting(e);const R={...s,...g},ue=Z(R),M=ee(t,ue),z=Se(M);if(z.length>0){const le=`Cannot save: blob URLs detected at ${z.join(", ")}. Re-upload the files.`;e&&a&&a.setError(e,le);return}if(p.signal.aborted)return;await r(M,i),d.getState().clearDraft(v),E.current.reset(E.current.getValues()),e&&a&&a.setSuccess(e)}catch(g){throw e&&a&&a.setError(e,g instanceof Error?g.message:"Submission failed"),g}finally{if(P.current=!1,$.current=!1,D.current===p&&(D.current=null),e){const g=d.getState().forms[e]?.status;(g==="uploading"||g==="validating"||g==="submitting")&&d.getState().reset(e)}}},s=>{const i=Object.keys(s).filter(p=>p!=="root"&&s[p]);G({toastType:"error",title:S("validation.failed",{defaultValue:"Validation failed"}),description:S("validation.fixErrorsCount",{count:i.length,fields:i.join(", "),defaultValue:`${i.length} field(s) need attention: ${i.join(", ")}`}),duration:8e3}),te(s),o?.(s)})(n)}),ne=()=>{d.getState().clearDraft(v),u.reset(m),j.current=!1},q=()=>{D.current?.abort(),e&&(d.getState().cleanup(e),w.getState().cleanup(e))};O(()=>q,[]);const oe=()=>{D.current?.abort(),e&&(w.getState().abortAll(e),d.getState().reset(e)),$.current=!1},se=he(t,{operation:c,viewerRole:N,availableFields:void 0}),ie=u.formState.isSubmitted||Object.keys(u.formState.touchedFields||{}).length>0;return{...u,handleSubmit:ae,fields:se,operation:c,entity:t,t:S,viewerRole:N,formId:e,formStatus:e?H:"idle",uploadProgress:e?J:0,cleanup:q,cancel:oe,isDirty:u.formState.isDirty,hasUserInteracted:ie,resetForm:ne,originalValues:m}}export{De as useEntityForm};
|
|
1
|
+
"use client";import{useMemo as H,useEffect as C,useId as Bt,useRef as w,useState as De,createElement as Kt}from"react";import{useForm as Ht}from"react-hook-form";import{toast as Re,ToastAction as Jt}from"@donotdev/components";import{createSchemas as Gt,statusOf as Qt,useTranslation as Xt}from"@donotdev/core";import{childRowsKey as Yt,extensionMintKey as nt,useFormStore as l,useFormStatus as Zt,useUploadProgress as _t}from"../../stores";import{useExtensionRows as er}from"../../hooks/useExtensionRows";import{getCrudServiceInstance as ie}from"../../useCrud";import{hasChildEdits as Z,mergeBatches as tr,pickFields as _,rebaseChildEdits as rr,schemasOf as nr,writableFields as or}from"../childRows";import{extensionFields as sr,extensionWritable as ot,extensionsSignature as ar,resolveExtensions as cr,setAtPath as ir,splitExtensionField as Ae,withoutLinkField as lr}from"../extend";import{useFormNavigation as ur}from"../FormNavigation";import{useUploadStore as J}from"../../stores/UploadStore";import{checkForBlobUrls as dr,isStorageUrl as fr}from"../../utils/uploadValidation";import{injectScope as Ie}from"../../utils/scopeUtils";import{getFieldsForOperation as mr,translateFieldLabel as gr}from"../utils";import{createConditionAwareResolver as st,getFormConditionStates as Ve}from"../utils/conditionAwareResolver";import{buildInitialFromRecord as at,buildSchemaDefaults as ct}from"../utils/buildInitialValues";const it="@childRows",xe="@record",pr=s=>new Set([...s].map(p=>Ae(p)?.[1]??p)),Ce=(s,p,a)=>pr(ot(s,p,a));function M(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function lt(s){return M(s)?s.updatedAt:void 0}function ut(s,p){const a={...s};for(const $ of Object.keys(p)){const E=s[$],T=p[$];T!==null&&typeof T=="object"&&!Array.isArray(T)&&E!==null&&typeof E=="object"&&!Array.isArray(E)?a[$]=ut(E,T):a[$]=T}return a}function le(s){if(s==null)return s;if(typeof s=="string")return s.startsWith("blob:")?null:s;if(Array.isArray(s)){const p=s.map(le).filter(a=>a!==null);return p.length>0?p:null}if(typeof s=="object"){const p=s;if("fullUrl"in p&&typeof p.fullUrl=="string")return fr(p.fullUrl)?p:null;const a={};for(const[$,E]of Object.entries(p))a[$]=le(E);return a}return s}function yr(s,p={}){const{formId:a,operation:$,defaultValues:E,viewerRole:T,mode:dt="onBlur",t:ft,loading:$e=!1,successPath:mt,extend:Ue}=p,G=ur(),h=T??"guest",gt=ar(Ue),g=H(()=>cr(s,Ue,h).filter(e=>e.readable),[s,gt,h]),{t:pt}=Xt([s.namespace,"crud",...g.map(e=>e.entity.namespace)]),b=ft??pt,u=$??(E?"edit":"create"),ee=E?.id,Me=er(g,u==="edit"&&ee?[ee]:[],!$e),ue=e=>ee?Me[e]?.byRecord.get(ee):void 0,P=e=>u==="edit"&&ue(e)?"edit":"create",te=g.map(e=>ue(e.key)),yt=g.map(e=>`${e.key}:${P(e.key)}`).join("|"),L=$e||Object.values(Me).some(e=>e.loading),ht=Zt(a??""),bt=_t(a??""),j=E,Te=Qt(j),I=H(()=>or(s,h,u),[s,h,u]),St=H(()=>{const e=st(s,u,I,j),r=(n,o,c)=>e(u==="edit"?n:Ie(n,s.scope),o,c);if(g.length===0)return r;const t=g.map(n=>({key:n.key,resolve:st(lr(n),P(n.key),Ce(n,h,P(n.key)))}));return async(n,o,c)=>{const i=await r(n,o,c),v={...i.errors},m={...i.values},y={criteriaMode:c.criteriaMode,fields:c.fields,shouldUseNativeValidation:c.shouldUseNativeValidation};for(const{key:N,resolve:O}of t){const B=n[N],S=await O(M(B)?B:{},o,y);Object.keys(S.errors).length>0?v[N]=S.errors:m[N]=S.values}return Object.keys(v).length>0?{values:{},errors:v}:{values:m,errors:{}}}},[s,u,I,j,g,yt,h]),re=H(()=>ct(s,I),[s,I]),k=H(()=>{if(L)return;const e=u==="edit"?j?at(s,j,{fields:I,keepId:!0}):void 0:j?_({...re,...j},I):re;if(!e||g.length===0)return e;const r={...e};return g.forEach((t,n)=>{const o=te[n],c=Ce(t,h,o?"edit":"create");r[t.key]=o?at(t.entity,o,{fields:c,keepId:!0}):ct(t.entity,c)}),r},[L,u,re,s,j,I,h,g,...te]),de=H(()=>{if(u!=="edit"||L||!j)return;const e={...j};return g.forEach((r,t)=>{const n=te[t];n&&(e[r.key]=n)}),e},[u,L,j,g,...te]),[wt,fe]=De(null),me=wt??de,ge=w(me);ge.current=me;const pe=e=>{const r=_(e,I);u==="edit"&&Object.hasOwn(e,"id")&&(r.id=e.id);for(const t of g){const n=e[t.key];if(!M(n))continue;const o=P(t.key),c=_(n,Ce(t,h,o));o==="edit"&&Object.hasOwn(n,"id")&&(c.id=n.id),r[t.key]=c}return r},d=Ht({defaultValues:u==="create"?k:void 0,mode:dt,resolver:St,shouldUnregister:!1,shouldFocusError:!1});C(()=>{let e=Ve(s,d.getValues()),r=!0,t=!1;const n=new Set,o=async()=>{if(!t){t=!0;try{for(;r&&n.size>0;){const i=[...n];if(n.clear(),await d.trigger(i),!r)return;for(const v of Ve(s,d.getValues()))v.visible||d.clearErrors(v.name)}}finally{t=!1}}},c=d.watch(()=>{const i=Ve(s,d.getValues()),v=i.filter((m,y)=>m.visible!==e[y]?.visible||m.required!==e[y]?.required);e=i;for(const m of v){const y=m.name;m.visible||d.clearErrors(y),n.add(y)}n.size>0&&o()});return()=>{r=!1,n.clear(),c.unsubscribe()}},[s,d]);const V=w(d);C(()=>{V.current=d},[d]);const ne=w(null);C(()=>{if(u==="edit"&&k){const e=k.id??null;e&&e!==ne.current?(V.current.reset(k),ne.current=e):!e&&ne.current===null&&(V.current.reset(k),ne.current="initialized")}},[u,k]);const D=E?.id,ye=`${s.name.toLowerCase()}-form-draft${a?`-${a}`:""}`,F=u==="create"?ye:D?`${ye}-${D}`:`${ye}-edit`,W=w(!1),x=Bt(),R=u==="edit"?D:void 0,Q=e=>R?Object.keys(e).flatMap(r=>{const[t,n,o,c]=r.split("\0");return t===x&&n===R&&o&&c?[[r,o,c]]:[]}):[],Pe=()=>{const{childEdits:e,childWriters:r}=l.getState();return Q(e).flatMap(([t,n,o])=>{const c=e[t];if(!Z(c))return[];const i=r[t];if(!i)throw new Error(`useEntityForm(${s.name}): joined rows ${n}.${o} have edits but no useChildRows registered how to write them.`);return[{key:t,collection:n,field:o,writer:i,edits:c}]})},Le=()=>{const{childEdits:e,childDrafts:r}=l.getState(),t={};for(const[n,o,c]of Q(r))t[o]={...t[o],[c]:r[n]};for(const[n,o,c]of Q(e)){const i=e[n];Z(i)&&(t[o]={...t[o],[c]:i})}return Object.keys(t).length>0?t:void 0},vt=e=>{if(!(e===void 0||!R)&&M(e)){for(const[r,t]of Object.entries(e))if(M(t))for(const[n,o]of Object.entries(t))l.getState().setChildDraft(Yt(x,R,r,n),o)}},U=w(new Map),oe=w(null),he=()=>{if(U.current.size===0)return;const e={};for(const[r,t]of U.current)e[r]=t.get();return e},We=(e=!0)=>{const r=he(),t=Le(),n=e&&u==="edit"?ge.current:void 0;return!t&&!n?r:{...r,...t&&{[it]:t},...n&&{[xe]:n}}},kt=e=>{e!==void 0&&(!M(e)||!R||e.id!==R||fe(e))},Et=()=>{const e=V.current;return Object.keys(e.getValues()).some(r=>e.getFieldState(r).isDirty)},Ne=()=>Et()||[...U.current.values()].some(e=>e.edited())||Le()!==void 0,Ft=e=>{if(oe.current=e??null,!!e){for(const[r,t]of U.current)r in e&&t.restore(e[r]);vt(e[it]),kt(e[xe])}},qe=()=>{oe.current=null,fe(null);for(const r of U.current.values())r.reset();const e=l.getState();for(const[r]of Q(e.childEdits))e.setChildEdits(r,null);for(const[r]of Q(e.childDrafts))e.setChildDraft(r,null)},se=w(()=>{}),[Ot]=De(()=>({register:(e,r)=>{U.current.set(e,r);const t=oe.current;return t&&e in t&&r.restore(t[e]),()=>{U.current.get(e)===r&&U.current.delete(e)}},changed:()=>se.current()})),ze=w(L);ze.current&&!L&&(W.current=!1),ze.current=L;const jt=e=>{l.getState().clearDraft(F),V.current.reset(e),qe()},[be,Be]=De(null);C(()=>{if(!be)return;Be(null);const{base:e,conflict:r}=be;if(!Ne()){l.getState().clearDraft(F),oe.current=null,fe(null);return}Re({toastType:r?"warning":"info",title:b(r?"crud:draft.conflict":"crud:draft.restored"),description:b(r?"crud:draft.conflictDescription":"crud:draft.restoredDescription"),action:Kt(Jt,{altText:b("crud:draft.discard"),onClick:()=>jt(e)},b("crud:draft.discard")),duration:r?1/0:8e3})},[be]),C(()=>{if(W.current)return;const e=l.getState().loadDraft(F),r=t=>{if(!e)return;const n=e.extras?.[xe];d.reset(t);const o=pe(ut(t,e.data));for(const[c,i]of Object.entries(o))d.setValue(c,i,{shouldDirty:!0});Ft(e.extras),Be({base:t,conflict:u==="edit"&&n!==void 0&<(n)!==lt(de)})};if(u==="create"&&k){e?r(k):d.reset(k),W.current=!0;return}u==="edit"&&k&&(r(k),W.current=!0)},[u,E,F,d,k,de,b,re]);const q=w(null),ae=()=>{q.current&&clearTimeout(q.current),q.current=null},Ke=()=>{if(!Ne()){l.getState().clearDraft(F);return}l.getState().saveDraft(F,le(pe(V.current.getValues())),s.name,D,We())},He=()=>{Ke()},Se=w(He);Se.current=He,se.current=()=>{W.current&&(ae(),q.current=setTimeout(()=>{q.current=null,Se.current()},3e3))},C(()=>{const e=d.watch(()=>se.current()),r=Se.current;return()=>{e.unsubscribe(),q.current&&(ae(),r())}},[d,F,s.name,D]);const Je=w(h);Je.current=h,C(()=>{if(R)return l.getState().openRecord({formKey:x,collection:s.collection,recordId:R,viewerRole:Je.current,submitting:!1,changed:()=>se.current()}),()=>l.getState().closeRecord(x)},[x,s.collection,R]),C(()=>{l.getState().updateOpenRecord(x,{viewerRole:h})},[x,h]);const z=w(null),X=w(!1),Dt=async e=>{if(!a)return{};const r=J.getState(),t=l.getState();if(!r.hasPendingUploads(a))return{};const n=setInterval(()=>{const o=J.getState().getTotalProgress(a);l.getState().setUploading(a,o)},200);try{return t.setUploading(a,0),await r.uploadAll(a,e),e?.aborted?null:J.getState().getResults(a)}catch(o){const c=J.getState().uploads[a];c&&Object.entries(c).forEach(([v,m])=>{m.status==="error"&&m.error&&d.setError(v,{type:"upload",message:m.error})});const i=o instanceof Error?o.message:b("crud:form.uploadFailed");return l.getState().setError(a,i),null}finally{clearInterval(n)}},Ge=(e,r)=>{let t={...e};for(const[n,o]of Object.entries(r)){const c=Ae(n);t=c&&g.some(i=>i.key===c[0])?ir(t,n,o):{...t,[n]:o}}return t},we=(e,r)=>{const t={...r};for(const[n,o]of Object.entries(e.fields))if(o.type==="price"&&n in t){const c=t[n];(c==null||c.amount==null)&&(t[n]=null)}return t},Rt=(e,r)=>{if(typeof HTMLFormElement>"u"||!(r instanceof HTMLFormElement))return;const t=Object.keys(e).filter(o=>o!=="root"),n=r.querySelectorAll("input, textarea, select, button, [tabindex]");for(const o of n){const c=o.getAttribute("name");if(!(!(o.getAttribute("aria-invalid")==="true"||c!==null&&t.some(i=>c===i||c.startsWith(`${i}.`)))||o.matches(':disabled, input[type="hidden"]')||o.closest('[hidden], [inert], [aria-hidden="true"]')||o.getClientRects().length===0)&&(o.focus(),o.ownerDocument.activeElement===o)){o.scrollIntoView({behavior:"smooth",block:"center"});return}}},ve=w(null),ke=w(null),Ee=w(!1),Fe=`record\0${F}`,Oe=()=>g.filter(e=>P(e.key)==="edit"?e.update:e.create),At=(e,r)=>Oe().map(t=>{const n=P(t.key),o=new Set([...ot(t,h,n)].map(y=>Ae(y)?.[1]??y)),c=e[t.key],i=we(t.entity,_(M(c)?c:{},o)),v=nr(t.entity),m=ue(t.key);if(m)return{collection:t.entity.collection,updates:[{id:m.id,patch:i,stored:m}],schemas:v};if(!r)throw new Error(`useEntityForm(${s.name}): inserting extension "${t.key}" on create needs the record id: pendingWrites({ recordId }) (pre-mint it).`);return{collection:t.entity.collection,inserts:[Ie({...i,id:l.getState().mintId(nt(t.entity.collection,r)),[t.field]:r},t.entity.scope)],schemas:v,...u==="create"&&{dependsOn:[s.collection]}}}),It=async()=>{const e=ie();if(!e)throw new Error(b("crud:form.saveFailed"));if(u!=="edit"||!D)throw new Error(`useEntityForm(${s.name}): remove() needs an edited record (defaultValues.id).`);await e.remove(s.collection,D),l.getState().clearDraft(F)},Qe=(e={})=>{Ee.current=!0;const r=ve.current??Pe(),t=ke.current??V.current.getValues();return tr([...At(t,R??e.recordId),...r.flatMap(({writer:n,edits:o})=>n.batches(o))])},Xe=e=>{let r=0;for(const{writer:n,edits:o}of e){const c=n.errors(o),i=Object.keys(c).length;i!==0&&(r+=i)}if(r===0)return!1;const t=b("crud:childRows.invalidRows",{count:r});return a?l.getState().setError(a,t):Re({toastType:"error",title:t,duration:8e3}),!0},Vt=()=>!I.has("status")&&Te!==null?{status:Te}:{},xt=async e=>{const r=ie();if(!r)throw new Error(b("crud:form.saveFailed"));const t=Gt(s),n=_(e,I);if(u==="edit"&&!D)throw new Error(`useEntityForm(${s.name}): the default writer needs defaultValues.id in edit mode.`);const o=u==="create"&&Oe().length>0?l.getState().mintId(Fe):void 0,c=u==="edit"&&D?{collection:s.collection,updates:[{id:D,patch:n,stored:ge.current}],schemas:t}:{collection:s.collection,inserts:[Ie({...n,...Vt(),...o&&{id:o}},s.scope)],schemas:t};return r.bulkAcross([c,...Qe({recordId:o})])},Ct=d.handleSubmit,$t=(e,r,t)=>async n=>{let o;n?.preventDefault?.();const c=n?.currentTarget;if(X.current)return;const i=a?l.getState():null,v=structuredClone(V.current.getValues()),m=Pe().filter(({edits:y})=>Z(y));return await Ct(async(y,N)=>{if(X.current||Xe(m))return;X.current=!0,z.current?.abort();const O=new AbortController;z.current=O;let B=null;try{a&&i&&i.startSubmit(a);const S=await Dt(O.signal);if(S===null||O.signal.aborted)return;a&&i&&i.setSubmitting(a);const Lt=Ge(y,S),K=we(s,Lt);for(const f of g){const A=K[f.key];M(A)&&(K[f.key]=we(f.entity,A))}if(dr(K).length>0){a&&i&&i.setError(a,b("crud:form.reuploadFiles"));return}if(O.signal.aborted)return;const Wt=Ge(v,structuredClone(S));W.current&&(ae(),Ke());const Nt=new Map(Object.entries(he()??{}).map(([f,A])=>[f,JSON.stringify(A)])),_e=t&&"successPath"in t?t.successPath:mt;if(G&&_e!==null){const f=G.currentPath(),A=_e??G.parentPath();A!==f&&(B=f,G.navigate(A))}if(ve.current=m,ke.current=K,Ee.current=!1,l.getState().updateOpenRecord(x,{submitting:!0}),o=e?await e(K,N):await xt(K),[...m.map(({collection:f})=>f),...Oe().map(f=>f.entity.collection)].length>0&&!Ee.current)throw new Error(b("crud:childRows.notSaved"));let et=!1;for(const{key:f,collection:A,edits:zt}of m){const rt=l.getState().childEdits[f],Y=rt?rr(rt,zt):null;et||=!!Y&&Z(Y),l.getState().setChildEdits(f,Y&&Z(Y)?Y:null),ie()?.invalidateCollection(A)}for(const f of g)ie()?.invalidateCollection(f.entity.collection);const qt=l.getState().mintedIds[Fe],tt=R??qt;l.getState().releaseMintedIds([Fe,...tt?g.map(f=>nt(f.entity.collection,tt)):[]]);const ce=V.current,je=ce.getValues();ce.reset(Wt,{keepValues:!0}),ce.reset(je,{keepDefaultValues:!0}),ae(),Object.keys(je).some(f=>ce.getFieldState(f).isDirty)||Object.entries(he()??{}).some(([f,A])=>Nt.get(f)!==JSON.stringify(A))||et?l.getState().saveDraft(F,le(pe(je)),s.name,D,We(!1)):l.getState().clearDraft(F),a&&i&&i.setSuccess(a)}catch(S){throw B!==null&&G?.navigate(B),a&&i&&i.setError(a,S instanceof Error?S.message:b("crud:form.saveFailed"),S),S}finally{if(X.current=!1,ve.current=null,ke.current=null,l.getState().updateOpenRecord(x,{submitting:!1}),z.current===O&&(z.current=null),a){const S=l.getState().forms[a]?.status;(S==="uploading"||S==="validating"||S==="submitting")&&l.getState().reset(a)}}},y=>{const N=Object.keys(y).filter(O=>O!=="root");Re({toastType:"error",title:b("crud:form.validationFailed"),description:b("crud:form.fixFields",{fields:N.map(O=>gr(O,s.fields[O],b)).join(", ")}),duration:8e3}),Xe(m),Rt(y,c),r?.(y)})(n),o},Ut=()=>{l.getState().clearDraft(F),qe(),d.reset(k),W.current=!1},Ye=()=>{z.current?.abort(),a&&(l.getState().cleanup(a),J.getState().cleanup(a))};C(()=>Ye,[]);const Mt=()=>{z.current?.abort(),a&&(J.getState().abortAll(a),l.getState().reset(a)),X.current=!1},Ze=mr(s,{operation:u,viewerRole:h,availableFields:void 0}),Tt=g.length===0?Ze:[...Ze,...g.flatMap(e=>sr(e,h,P(e.key)))],Pt=d.formState.isSubmitted||Object.keys(d.formState.touchedFields||{}).length>0;return{...d,handleSubmit:$t,fields:Tt,operation:u,record:me,entity:s,t:b,viewerRole:h,formId:a,formStatus:a?ht:"idle",uploadProgress:a?bt:0,cleanup:Ye,cancel:Mt,isDirty:d.formState.isDirty,hasUserInteracted:Pt,resetForm:Ut,originalValues:k,draftState:Ot,pendingWrites:Qe,remove:It}}export{yr as useEntityForm};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** One page-state slot as the form sees it. */
|
|
2
|
+
export interface FormDraftSlot {
|
|
3
|
+
/** Current value, read when the draft is saved. */
|
|
4
|
+
get: () => unknown;
|
|
5
|
+
/** True when the current value differs from the initial one (the slot holds an edit). */
|
|
6
|
+
edited: () => boolean;
|
|
7
|
+
/** Apply a value restored from the draft. */
|
|
8
|
+
restore: (value: unknown) => void;
|
|
9
|
+
/** Back to the initial value (Discard, resetForm). */
|
|
10
|
+
reset: () => void;
|
|
11
|
+
}
|
|
12
|
+
/** Slot registry exposed by `useEntityForm` as `form.draftState`. */
|
|
13
|
+
export interface FormDraftStateRegistry {
|
|
14
|
+
/** Register a slot; returns its unregister function. */
|
|
15
|
+
register: (key: string, slot: FormDraftSlot) => () => void;
|
|
16
|
+
/** A slot changed: schedule the form's draft autosave. */
|
|
17
|
+
changed: () => void;
|
|
18
|
+
}
|
|
19
|
+
/** Options for {@link useFormDraftState}. */
|
|
20
|
+
export interface UseFormDraftStateOptions<T> {
|
|
21
|
+
/**
|
|
22
|
+
* Validate a value read back from the draft (browser storage: untrusted, may
|
|
23
|
+
* come from an older page version) and adjust it before it is applied, e.g.
|
|
24
|
+
* drop table edits that already equal the loaded record. Throw to reject it;
|
|
25
|
+
* the slot then keeps `initial`.
|
|
26
|
+
*/
|
|
27
|
+
parse: (draft: unknown) => T;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Page state saved in the form's draft: autosaved with it, saved at submit,
|
|
31
|
+
* restored with it ("Draft restored" toast), reset by its Discard, cleared when
|
|
32
|
+
* the submit succeeds and kept when it fails. A value different from `initial`
|
|
33
|
+
* is an edit: it keeps the draft like a dirty field. Values must be JSON-serializable.
|
|
34
|
+
*
|
|
35
|
+
* @param form - The `useEntityForm` result that owns the page Save
|
|
36
|
+
* @param key - Slot name, unique within the form
|
|
37
|
+
* @param initial - Value when no draft exists (and after Discard)
|
|
38
|
+
* @param options - See {@link UseFormDraftStateOptions}
|
|
39
|
+
* @returns `[value, setValue]`, like `useState`
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* const form = useEntityForm(routineEntity, { formId: 'routine', operation: 'edit', defaultValues });
|
|
44
|
+
* const [productIds, setProductIds] = useFormDraftState(form, 'productIds', initialIds, {
|
|
45
|
+
* parse: (draft) => v.parse(v.array(v.string()), draft),
|
|
46
|
+
* });
|
|
47
|
+
* const save = form.handleSubmit((values) => saveRoutine(values, productIds));
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function useFormDraftState<T>(form: {
|
|
51
|
+
draftState: FormDraftStateRegistry;
|
|
52
|
+
}, key: string, initial: T, options: UseFormDraftStateOptions<T>): [T, (next: T | ((previous: T) => T)) => void];
|
|
53
|
+
//# sourceMappingURL=useFormDraftState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormDraftState.d.ts","sourceRoot":"","sources":["../../../src/forms/hooks/useFormDraftState.ts"],"names":[],"mappings":"AAiBA,+CAA+C;AAC/C,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,GAAG,EAAE,MAAM,OAAO,CAAC;IACnB,yFAAyF;IACzF,MAAM,EAAE,MAAM,OAAO,CAAC;IACtB,6CAA6C;IAC7C,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAClC,sDAAsD;IACtD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,qEAAqE;AACrE,MAAM,WAAW,sBAAsB;IACrC,wDAAwD;IACxD,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,KAAK,MAAM,IAAI,CAAC;IAC3D,0DAA0D;IAC1D,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,6CAA6C;AAC7C,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC;;;;;OAKG;IACH,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,IAAI,EAAE;IAAE,UAAU,EAAE,sBAAsB,CAAA;CAAE,EAC5C,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,EACV,OAAO,EAAE,wBAAwB,CAAC,CAAC,CAAC,GACnC,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC,CAmD/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{useEffect as p,useRef as a,useState as y}from"react";function d(S,i,n,f){const[o,u]=y(n),r=a(o),c=a(n),g=a(f.parse);p(()=>{c.current=n,g.current=f.parse});const{draftState:s}=S;return p(()=>s.register(i,{get:()=>r.current,edited:()=>JSON.stringify(r.current)!==JSON.stringify(c.current),restore:t=>{let e;try{e=g.current(t)}catch{return}r.current=e,u(e)},reset:()=>{r.current=c.current,u(c.current)}}),[s,i]),[o,t=>{const e=typeof t=="function"?t(r.current):t;r.current=e,u(e),s.changed()}]}export{d as useFormDraftState};
|
package/dist/forms/index.d.ts
CHANGED
|
@@ -30,10 +30,14 @@
|
|
|
30
30
|
* @author AMBROISE PARK Consulting
|
|
31
31
|
*/
|
|
32
32
|
export { useEntityForm } from './hooks/useEntityForm';
|
|
33
|
+
export { FormNavigationProvider, useFormNavigation } from './FormNavigation';
|
|
34
|
+
export { useFormDraftState } from './hooks/useFormDraftState';
|
|
35
|
+
export type { FormDraftSlot, FormDraftStateRegistry, UseFormDraftStateOptions, } from './hooks/useFormDraftState';
|
|
36
|
+
export type { FormNavigation } from './FormNavigation';
|
|
33
37
|
export { useEntityField } from './hooks/useEntityField';
|
|
34
38
|
export { useController } from './hooks/useController';
|
|
35
39
|
export type { UseControllerProps, UseControllerReturn, ControllerRenderProps, ControllerFieldState, } from './hooks/useController';
|
|
36
|
-
export { isFieldEditable, getFieldsForOperation, validateEntity, translateFieldLabel, translateLabel, } from './utils';
|
|
40
|
+
export { EMPTY_VALUE, fromInputValue, isFieldEditable, getFieldsForOperation, validateEntity, translateFieldLabel, translateLabel, } from './utils';
|
|
37
41
|
export type { ViewerRole, RenderableField, GetFieldsForOperationOptions, EntityFieldsInput, SchemaOperation, ValidationIssue, ValidationResult, } from './utils';
|
|
38
|
-
export type { InferEntityData, InferEntityCreate, InferEntityInput, InferEntityOutput, UseEntityFormOptions, EntityFormReturn, EntityFieldReturn, Entity, EntityField, FieldType, Visibility, Editable, ValidationRules, dndevSchema, } from './types';
|
|
42
|
+
export type { InferEntityData, InferEntityCreate, InferEntityInput, InferEntityOutput, UseEntityFormOptions, EntityFormReturn, EntityFormHandleSubmit, EntityFormState, EntityFormSubmitOptions, EntityFieldReturn, Entity, EntityField, FieldType, Visibility, Editable, ValidationRules, dndevSchema, } from './types';
|
|
39
43
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/forms/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,cAAc,GACf,MAAM,SAAS,CAAC;AAGjB,YAAY,EAEV,UAAU,EACV,eAAe,EACf,4BAA4B,EAC5B,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAEjB,YAAY,EAEV,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EAEjB,MAAM,EACN,WAAW,EACX,SAAS,EACT,UAAU,EACV,QAAQ,EACR,eAAe,EACf,WAAW,GACZ,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/forms/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,YAAY,EACV,aAAa,EACb,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,WAAW,EACX,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,cAAc,GACf,MAAM,SAAS,CAAC;AAGjB,YAAY,EAEV,UAAU,EACV,eAAe,EACf,4BAA4B,EAC5B,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAEjB,YAAY,EAEV,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EAEjB,MAAM,EACN,WAAW,EACX,SAAS,EACT,UAAU,EACV,QAAQ,EACR,eAAe,EACf,WAAW,GACZ,MAAM,SAAS,CAAC"}
|
package/dist/forms/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useEntityForm as a}from"./hooks/useEntityForm";import{
|
|
1
|
+
import{useEntityForm as a}from"./hooks/useEntityForm";import{FormNavigationProvider as t,useFormNavigation as s}from"./FormNavigation";import{useFormDraftState as e}from"./hooks/useFormDraftState";import{useEntityField as r}from"./hooks/useEntityField";import{useController as i}from"./hooks/useController";import{EMPTY_VALUE as o,fromInputValue as l,isFieldEditable as m,getFieldsForOperation as n,validateEntity as F,translateFieldLabel as d,translateLabel as u}from"./utils";export{o as EMPTY_VALUE,t as FormNavigationProvider,l as fromInputValue,n as getFieldsForOperation,m as isFieldEditable,d as translateFieldLabel,u as translateLabel,i as useController,r as useEntityField,a as useEntityForm,e as useFormDraftState,s as useFormNavigation,F as validateEntity};
|
package/dist/forms/types.d.ts
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
* @since 0.0.1
|
|
7
7
|
* @author AMBROISE PARK Consulting
|
|
8
8
|
*/
|
|
9
|
-
import type { ReactElement } from 'react';
|
|
10
|
-
import type { UseFormReturn, ControllerRenderProps, FieldPath } from 'react-hook-form';
|
|
11
|
-
import type {
|
|
9
|
+
import type { BaseSyntheticEvent, ReactElement } from 'react';
|
|
10
|
+
import type { UseFormReturn, SubmitHandler, SubmitErrorHandler, ControllerRenderProps, FieldPath, FieldValues } from 'react-hook-form';
|
|
11
|
+
import type { FormDraftStateRegistry } from './hooks/useFormDraftState';
|
|
12
|
+
import type { AnyEntity, BulkAcrossBatch, BulkAcrossResult, CreateInput, EntityExtensions, EntityFormDefaultValues, Entity, EntityField, FieldOperation, FieldType, FormValues, InferEntityRow, Visibility, Editable, ValidationRules, dndevSchema } from '@donotdev/core';
|
|
12
13
|
import type { RenderableField, ViewerRole } from './utils';
|
|
13
14
|
import type { FormStatus } from '../stores/FormStore';
|
|
14
15
|
export type { AnyEntity, Entity, EntityField, FieldType, Visibility, Editable, ValidationRules, dndevSchema, RenderableField, ViewerRole, };
|
|
@@ -41,15 +42,17 @@ export type { AnyEntity, Entity, EntityField, FieldType, Visibility, Editable, V
|
|
|
41
42
|
*/
|
|
42
43
|
export type InferEntityData<E extends AnyEntity> = InferEntityRow<E>;
|
|
43
44
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
45
|
+
* Create payload of an entity: {@link CreateInput} (`createSchemas(e).create`, from
|
|
46
|
+
* the entity descriptor). Written fields only (`user`, `derived`, `program` write
|
|
47
|
+
* classes); required → key required, value; optional / conditional → key optional,
|
|
48
|
+
* value or `null`.
|
|
46
49
|
*
|
|
47
50
|
* @template E - Entity from `defineEntity()`
|
|
48
51
|
*
|
|
49
|
-
* @version 0.
|
|
52
|
+
* @version 0.2.0
|
|
50
53
|
* @since 0.2.0
|
|
51
54
|
*/
|
|
52
|
-
export type InferEntityCreate<E extends AnyEntity> =
|
|
55
|
+
export type InferEntityCreate<E extends AnyEntity> = CreateInput<E>;
|
|
53
56
|
/**
|
|
54
57
|
* Infers form input type (values before validation).
|
|
55
58
|
* All fields are optional/partial since form may be incomplete.
|
|
@@ -76,16 +79,19 @@ export type InferEntityOutput<E extends AnyEntity> = InferEntityData<E>;
|
|
|
76
79
|
* Options for useEntityForm hook.
|
|
77
80
|
*
|
|
78
81
|
* @template E - Entity type from defineEntity()
|
|
82
|
+
* @template Op - Form operation (`operation`), both when not given
|
|
83
|
+
* @template X - 1:1 extensions (`extend`), none by default
|
|
79
84
|
*
|
|
80
|
-
* @version 0.
|
|
85
|
+
* @version 0.2.0
|
|
81
86
|
* @since 0.0.1
|
|
82
87
|
* @author AMBROISE PARK Consulting
|
|
83
88
|
*/
|
|
84
|
-
export interface UseEntityFormOptions<E extends AnyEntity
|
|
89
|
+
export interface UseEntityFormOptions<E extends AnyEntity, Op extends FieldOperation = FieldOperation, X extends EntityExtensions = Record<never, never>> {
|
|
85
90
|
/**
|
|
86
91
|
* Form ID for tracking form/upload state.
|
|
87
92
|
* Required for deferred file uploads and form status tracking.
|
|
88
|
-
*
|
|
93
|
+
* Also scopes the auto-saved draft: give each form on the same record its own
|
|
94
|
+
* stable formId (e.g. 'product-prices') so their drafts never overwrite each other.
|
|
89
95
|
*/
|
|
90
96
|
formId?: string;
|
|
91
97
|
/**
|
|
@@ -94,12 +100,16 @@ export interface UseEntityFormOptions<E extends AnyEntity> {
|
|
|
94
100
|
* - 'edit': Shows all fields from defaultValues, technical fields read-only
|
|
95
101
|
* @default 'create' (or 'edit' if defaultValues provided)
|
|
96
102
|
*/
|
|
97
|
-
operation?:
|
|
103
|
+
operation?: Op;
|
|
98
104
|
/**
|
|
99
|
-
* Initial form values.
|
|
100
|
-
*
|
|
105
|
+
* Initial form values ({@link EntityFormDefaultValues}).
|
|
106
|
+
* - edit: the stored row as read (already visibility-filtered), accepted as-is.
|
|
107
|
+
* It becomes `form.record`; form state holds only the fields the form writes.
|
|
108
|
+
* - create: create defaults (e.g. `status: 'draft'`, a parent reference).
|
|
109
|
+
* Fields the form does not write (generated, technical, `editable: false`,
|
|
110
|
+
* role-denied) never enter form state, the local draft or the payload.
|
|
101
111
|
*/
|
|
102
|
-
defaultValues?:
|
|
112
|
+
defaultValues?: EntityFormDefaultValues<E, Op>;
|
|
103
113
|
/**
|
|
104
114
|
* Viewer role for editability checks.
|
|
105
115
|
* Determines which fields render as inputs vs read-only.
|
|
@@ -113,8 +123,12 @@ export interface UseEntityFormOptions<E extends AnyEntity> {
|
|
|
113
123
|
*/
|
|
114
124
|
mode?: 'onBlur' | 'onChange' | 'onSubmit' | 'onTouched' | 'all';
|
|
115
125
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
126
|
+
* Optional override for labels, hints, options and nested field-array fields.
|
|
127
|
+
* Omit for normal usage: useEntityForm automatically uses
|
|
128
|
+
* `useTranslation([entity.namespace, 'crud'])` with language/SSR support.
|
|
129
|
+
* Supply your own translator only to bypass that namespace resolution; it
|
|
130
|
+
* replaces the default translator completely. Pass returned `form.t` to the
|
|
131
|
+
* field renderers in either case.
|
|
118
132
|
*/
|
|
119
133
|
t?: (key: string, options?: Record<string, unknown>) => string;
|
|
120
134
|
/**
|
|
@@ -124,19 +138,150 @@ export interface UseEntityFormOptions<E extends AnyEntity> {
|
|
|
124
138
|
* @default false
|
|
125
139
|
*/
|
|
126
140
|
loading?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Where the page goes once a submit passes validation and uploads.
|
|
143
|
+
* The form leaves right away, before the server answers (optimistic); if the
|
|
144
|
+
* write rejects, it returns to the page it left and the saved draft restores
|
|
145
|
+
* every edit.
|
|
146
|
+
* - omitted: the previous breadcrumb (nearest existing parent route, else `/`)
|
|
147
|
+
* - a path: that path
|
|
148
|
+
* - `null`: stay on the page (dialogs, wizards, settings, create flows that
|
|
149
|
+
* open the new record, pages holding other unsaved state, and every form of
|
|
150
|
+
* a nested submit: leaving would unmount the inner form and cancel its save)
|
|
151
|
+
*
|
|
152
|
+
* Needs the router access `@donotdev/ui` provides; without it the form stays.
|
|
153
|
+
*/
|
|
154
|
+
successPath?: string | null;
|
|
155
|
+
/**
|
|
156
|
+
* 1:1 extensions edited with the record (a record split across two tables,
|
|
157
|
+
* e.g. `{ offer: { entity: productOfferEntity, field: 'productId' } }`): their
|
|
158
|
+
* fields join `form.fields` prefixed `key.` (`offer.priceExclVat`; values under
|
|
159
|
+
* `values.offer`), with conditions, validation, draft and uploads. In edit mode
|
|
160
|
+
* the extension row is read (the form waits for it); the default writer and
|
|
161
|
+
* `pendingWrites()` update it, or insert it when missing (after the record on
|
|
162
|
+
* create). A viewer without read access to an extension entity gets none of it.
|
|
163
|
+
* Keep the same keys while mounted.
|
|
164
|
+
* @since 0.2.5
|
|
165
|
+
*/
|
|
166
|
+
extend?: X;
|
|
167
|
+
}
|
|
168
|
+
/** Per-submit options for {@link EntityFormHandleSubmit}. */
|
|
169
|
+
export interface EntityFormSubmitOptions {
|
|
170
|
+
/**
|
|
171
|
+
* Overrides the hook's `successPath` for this submit only, e.g. Save on a draft
|
|
172
|
+
* stays (`null`) while Publish on the same form leaves. When the key is present
|
|
173
|
+
* it wins, `undefined` included (= previous breadcrumb); when absent the hook
|
|
174
|
+
* option applies.
|
|
175
|
+
*/
|
|
176
|
+
successPath?: string | null;
|
|
127
177
|
}
|
|
128
178
|
/**
|
|
129
|
-
*
|
|
179
|
+
* React Hook Form's `handleSubmit` (resolves `onValid`'s result, `undefined` when
|
|
180
|
+
* the submit did not reach it) plus per-submit {@link EntityFormSubmitOptions}.
|
|
130
181
|
*
|
|
131
|
-
*
|
|
182
|
+
* `onValid` is optional: without it the default writer saves the record (update,
|
|
183
|
+
* or add on create) with the fields the entity allows, plus the child rows joined
|
|
184
|
+
* to the form, in one `bulkAcross`, and resolves its {@link BulkAcrossResult}.
|
|
185
|
+
* With it, the app writes; joined rows' writes come from `form.pendingWrites()`.
|
|
186
|
+
*
|
|
187
|
+
* @template T - What `onValid` receives (the resolver's output)
|
|
188
|
+
* @template S - Form state `onInvalid`'s errors are keyed by, `T` by default
|
|
189
|
+
*/
|
|
190
|
+
export type EntityFormHandleSubmit<T extends FieldValues, S extends FieldValues = T> = <TResult = BulkAcrossResult>(onValid?: SubmitHandler<T, TResult>, onInvalid?: SubmitErrorHandler<S>, options?: EntityFormSubmitOptions) => (event?: BaseSyntheticEvent) => Promise<Awaited<TResult> | undefined>;
|
|
191
|
+
/**
|
|
192
|
+
* Form state of an entity form (React Hook Form's `TFieldValues` in
|
|
193
|
+
* {@link EntityFormReturn}): {@link FormValues} for both operations. Not keyed by
|
|
194
|
+
* the operation: React Hook Form's types are invariant in their field values, so a
|
|
195
|
+
* state per operation would make a `create` / `edit` form unassignable to
|
|
196
|
+
* `EntityFormReturn<E>`. The operation keys what is submitted (`TTransformedValues`:
|
|
197
|
+
* `handleSubmit`'s `onValid`), in which they are covariant.
|
|
132
198
|
*
|
|
133
199
|
* @template E - Entity type from defineEntity()
|
|
200
|
+
* @template X - 1:1 extensions (`extend`), none by default
|
|
134
201
|
*
|
|
135
202
|
* @version 0.1.0
|
|
203
|
+
* @since 0.2.5
|
|
204
|
+
* @author AMBROISE PARK Consulting
|
|
205
|
+
*/
|
|
206
|
+
export type EntityFormState<E extends AnyEntity, X extends EntityExtensions = Record<never, never>> = FormValues<E, FieldOperation, X>;
|
|
207
|
+
/**
|
|
208
|
+
* Return type for useEntityForm hook.
|
|
209
|
+
*
|
|
210
|
+
* Extends React Hook Form's UseFormReturn with entity-aware additions. Form state
|
|
211
|
+
* ({@link EntityFormState}) is {@link FormValues} for both operations: the fields
|
|
212
|
+
* the form writes (inputs editable for the viewer, `editable: 'computed'` fields,
|
|
213
|
+
* i18n companions, `id` on edit). Other fields of the stored row are read from
|
|
214
|
+
* {@link EntityFormReturn.record}. `Op` keys `operation`, what `handleSubmit`'s
|
|
215
|
+
* `onValid` receives (React Hook Form's `TTransformedValues`) and `originalValues`; every form of `E` (any `Op`) is an
|
|
216
|
+
* `EntityFormReturn<E>`, so helpers typed `<E extends AnyEntity>(form:
|
|
217
|
+
* EntityFormReturn<E>)` take a `create` or `edit` form. A helper taking a form
|
|
218
|
+
* with 1:1 extensions declares `X` (`EntityFormReturn<E, FieldOperation, X>`).
|
|
219
|
+
*
|
|
220
|
+
* @template E - Entity type from defineEntity()
|
|
221
|
+
* @template Op - Form operation
|
|
222
|
+
* @template X - 1:1 extensions (`extend`), none by default
|
|
223
|
+
*
|
|
224
|
+
* @version 0.3.0
|
|
136
225
|
* @since 0.0.1
|
|
137
226
|
* @author AMBROISE PARK Consulting
|
|
138
227
|
*/
|
|
139
|
-
export interface EntityFormReturn<E extends AnyEntity
|
|
228
|
+
export interface EntityFormReturn<E extends AnyEntity, Op extends FieldOperation = FieldOperation, X extends EntityExtensions = Record<never, never>> extends UseFormReturn<EntityFormState<E, X>, unknown, FormValues<E, Op, X>> {
|
|
229
|
+
/**
|
|
230
|
+
* Validates, uploads, writes the draft, leaves for `successPath`, then calls
|
|
231
|
+
* `onValid` with the resolver's output ({@link FormValues} for `Op`: the fields
|
|
232
|
+
* the form writes); `onInvalid` gets the errors keyed by form state. Third
|
|
233
|
+
* argument: per-submit {@link EntityFormSubmitOptions}.
|
|
234
|
+
*/
|
|
235
|
+
handleSubmit: EntityFormHandleSubmit<FormValues<E, Op, X>, EntityFormState<E, X>>;
|
|
236
|
+
/**
|
|
237
|
+
* Stored row the edit started from (`defaultValues` on edit, 1:1 extension rows
|
|
238
|
+
* under their key), saved with the local draft and restored with it: a value read
|
|
239
|
+
* from it (a concurrency token such as `revision`) stays the base version of a
|
|
240
|
+
* restored draft. Read-only displays read fields the form does not write
|
|
241
|
+
* (technical, `editable: false`, role-denied) from it. `undefined` on create and
|
|
242
|
+
* while the record loads.
|
|
243
|
+
* @since 0.2.5
|
|
244
|
+
*/
|
|
245
|
+
record: InferEntityRow<E> | undefined;
|
|
246
|
+
/**
|
|
247
|
+
* Page-state slots kept in this form's draft. Pass the form to
|
|
248
|
+
* `useFormDraftState`; do not call it directly.
|
|
249
|
+
*/
|
|
250
|
+
draftState: FormDraftStateRegistry;
|
|
251
|
+
/**
|
|
252
|
+
* Writes besides the record itself: the 1:1 extensions (`extend`: update, or
|
|
253
|
+
* insert when missing) and the child rows joined to this form (`useChildRows`
|
|
254
|
+
* / a nested `EntityList` on this record), one `bulkAcross` batch per
|
|
255
|
+
* collection (inserts with pre-minted ids, updates, deletes, schemas). During
|
|
256
|
+
* a submit, what that submit carries. Call it in your `handleSubmit(onValid)`
|
|
257
|
+
* and add the batches to your write; if there is something to write and it
|
|
258
|
+
* was not read during the submit, the submit fails with an explicit error (no
|
|
259
|
+
* silent loss). Empty when nothing joined, no extension and no edits.
|
|
260
|
+
*
|
|
261
|
+
* On create, inserting an extension needs the record id: pre-mint it and pass
|
|
262
|
+
* `{ recordId }` (its batch depends on the record's collection, so include the
|
|
263
|
+
* record insert in the same call).
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```tsx
|
|
267
|
+
* const save = form.handleSubmit(async (values) => {
|
|
268
|
+
* await bulkAcross([
|
|
269
|
+
* { collection: 'campaigns', updates: [{ id, patch: toPatch(values) }], schemas: createSchemas(campaign) },
|
|
270
|
+
* ...form.pendingWrites(),
|
|
271
|
+
* ]);
|
|
272
|
+
* });
|
|
273
|
+
* ```
|
|
274
|
+
* @since 0.2.5
|
|
275
|
+
*/
|
|
276
|
+
pendingWrites: (options?: {
|
|
277
|
+
recordId?: string;
|
|
278
|
+
}) => BulkAcrossBatch[];
|
|
279
|
+
/**
|
|
280
|
+
* Logical delete of the open record (CRUD rule 3): `{ status: 'deleted' }` only, the
|
|
281
|
+
* form's values are not validated. Clears the local draft. Edit mode only.
|
|
282
|
+
* @since 0.3.0
|
|
283
|
+
*/
|
|
284
|
+
remove: () => Promise<void>;
|
|
140
285
|
/**
|
|
141
286
|
* Pre-filtered fields ready for rendering.
|
|
142
287
|
* Already filtered by operation and visibility.
|
|
@@ -145,13 +290,14 @@ export interface EntityFormReturn<E extends AnyEntity> extends UseFormReturn<Inf
|
|
|
145
290
|
/**
|
|
146
291
|
* Current operation type.
|
|
147
292
|
*/
|
|
148
|
-
operation:
|
|
293
|
+
operation: Op;
|
|
149
294
|
/**
|
|
150
295
|
* Original entity definition.
|
|
151
296
|
*/
|
|
152
297
|
entity: E;
|
|
153
298
|
/**
|
|
154
|
-
*
|
|
299
|
+
* Resolved entity + crud translator, or options.t when explicitly overridden.
|
|
300
|
+
* Pass it to FormFieldRenderer / DisplayFieldRenderer in custom layouts.
|
|
155
301
|
*/
|
|
156
302
|
t: (key: string, options?: Record<string, unknown>) => string;
|
|
157
303
|
/**
|
|
@@ -200,11 +346,11 @@ export interface EntityFormReturn<E extends AnyEntity> extends UseFormReturn<Inf
|
|
|
200
346
|
*/
|
|
201
347
|
resetForm: () => void;
|
|
202
348
|
/**
|
|
203
|
-
* Original values the form was initialized with.
|
|
204
|
-
* For create mode: schema-based defaults.
|
|
205
|
-
* For edit mode:
|
|
349
|
+
* Original values the form was initialized with (form state: the fields the form writes).
|
|
350
|
+
* For create mode: schema-based defaults with the caller's defaults.
|
|
351
|
+
* For edit mode: the DB record projected onto the written fields, type defaults for empty ones.
|
|
206
352
|
*/
|
|
207
|
-
originalValues: Partial<
|
|
353
|
+
originalValues: Partial<FormValues<E, Op, X>> | undefined;
|
|
208
354
|
}
|
|
209
355
|
/**
|
|
210
356
|
* Return type for useEntityField hook.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/forms/types.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/forms/types.ts"],"names":[],"mappings":"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"}
|