@donotdev/crud 0.2.2 → 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 +17 -16
- package/dist/CrudService.bulk.d.ts.map +1 -1
- package/dist/CrudService.bulk.js +1 -1
- package/dist/CrudService.bulkAcross.d.ts +15 -8
- 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 +22 -3
- package/dist/CrudService.cache.d.ts.map +1 -1
- package/dist/CrudService.cache.js +1 -1
- package/dist/CrudService.d.ts +42 -11
- package/dist/CrudService.d.ts.map +1 -1
- package/dist/CrudService.internal.d.ts +3 -2
- package/dist/CrudService.internal.d.ts.map +1 -1
- package/dist/CrudService.internal.js +2 -2
- 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.queries.d.ts.map +1 -1
- package/dist/CrudService.queries.js +1 -1
- package/dist/CrudService.subscriptions.d.ts.map +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/CrudButton.js +1 -1
- package/dist/components/CrudCard.d.ts +2 -2
- 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/DisplayFieldRenderer.d.ts +5 -2
- package/dist/components/DisplayFieldRenderer.d.ts.map +1 -1
- package/dist/components/DisplayFieldRenderer.js +1 -1
- package/dist/components/DisplayThumbnail.d.ts.map +1 -1
- package/dist/components/DisplayThumbnail.js +1 -1
- package/dist/components/EntityFilters.d.ts +26 -4
- package/dist/components/EntityFilters.d.ts.map +1 -1
- package/dist/components/EntityFilters.js +1 -1
- package/dist/components/FormFieldRenderer.d.ts +21 -12
- 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/ControlledGeoPointField.d.ts.map +1 -1
- package/dist/components/controlled/complex/ControlledMapField.d.ts.map +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/ControlledRichTextField.d.ts.map +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 +48 -0
- package/dist/components/controlled/fieldOptions.d.ts.map +1 -0
- package/dist/components/controlled/fieldOptions.js +1 -0
- package/dist/components/controlled/file/ControlledDocumentField.js +1 -1
- package/dist/components/controlled/file/ControlledFileField.js +1 -1
- package/dist/components/controlled/file/ControlledImageField.d.ts.map +1 -1
- package/dist/components/controlled/file/ControlledImageField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiDocumentField.d.ts.map +1 -1
- package/dist/components/controlled/file/ControlledMultiDocumentField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiFileField.d.ts.map +1 -1
- package/dist/components/controlled/file/ControlledMultiFileField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiImageField.d.ts.map +1 -1
- package/dist/components/controlled/file/ControlledMultiImageField.js +1 -1
- package/dist/components/controlled/input/ControlledCheckboxField.d.ts.map +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.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledDurationField.js +1 -1
- package/dist/components/controlled/input/ControlledGdprConsentField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledGdprConsentField.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/ControlledRangeField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledRangeField.js +1 -1
- package/dist/components/controlled/input/ControlledRatingField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledRatingField.js +1 -1
- package/dist/components/controlled/input/ControlledSwitchField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledSwitchField.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/ControlledRadioField.d.ts.map +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/controlled/types.d.ts.map +1 -1
- package/dist/components/fields/display/AvatarFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/AvatarFieldDisplay.js +1 -1
- package/dist/components/fields/display/BadgeFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/ButtonFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/CheckboxFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/CheckboxFieldDisplay.js +1 -1
- package/dist/components/fields/display/DateFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/DateFieldDisplay.js +1 -1
- package/dist/components/fields/display/DropdownDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/FileFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/FileFieldDisplay.js +1 -1
- package/dist/components/fields/display/GeoPointFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/HiddenFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/ImageFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/LinkFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/LinkFieldDisplay.js +1 -1
- package/dist/components/fields/display/MapFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/MultiDropdownDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/MultiInputTextFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/NumberFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/NumberFieldDisplay.js +1 -1
- package/dist/components/fields/display/PasswordFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/PasswordFieldDisplay.js +1 -1
- package/dist/components/fields/display/PhoneNumberDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/RadioFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/RangeFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/ReferenceFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/ReferenceFieldDisplay.js +1 -1
- package/dist/components/fields/display/RichTextDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/TextAreaDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/TextAreaDisplay.js +1 -1
- package/dist/components/fields/display/TextFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/TextFieldDisplay.js +1 -1
- package/dist/components/fields/display/TimestampFieldDisplay.d.ts.map +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/AvatarFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/AvatarFieldComponent.js +1 -1
- package/dist/components/form/fields/BadgeFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/BadgeFieldComponent.js +1 -1
- package/dist/components/form/fields/ButtonFieldComponent.js +1 -1
- package/dist/components/form/fields/CheckboxFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/CheckboxFieldComponent.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/MapFieldComponent.d.ts.map +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/RatingFieldComponent.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/SwitchFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/SwitchFieldComponent.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/form/fields/internal/InlineFieldRow.d.ts +24 -0
- package/dist/components/form/fields/internal/InlineFieldRow.d.ts.map +1 -0
- package/dist/components/form/fields/internal/InlineFieldRow.js +1 -0
- package/dist/components/form/fields/internal/TiptapEditor.d.ts.map +1 -1
- package/dist/components/form/fields/internal/TiptapEditor.js +2 -2
- package/dist/components/form/internal/ImageViewerDialog.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/useController.js +1 -1
- 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/translateFieldLabel.d.ts +1 -9
- package/dist/forms/utils/translateFieldLabel.d.ts.map +1 -1
- package/dist/forms/utils/translateFieldLabel.js +1 -1
- package/dist/forms/utils/validateEntity.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/useCrudPageSize.js +1 -1
- package/dist/hooks/useEntityFavorites.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/useFileUpload.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/hooks/useRelatedItems.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 +4 -2
- 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 +40 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/useBaseCrudList.d.ts.map +1 -1
- package/dist/useBaseCrudList.js +1 -1
- package/dist/useCrud.d.ts +20 -9
- package/dist/useCrud.d.ts.map +1 -1
- package/dist/useCrud.js +1 -1
- package/dist/useCrudCardList.js +1 -1
- package/dist/useCrudDoc.d.ts.map +1 -1
- package/dist/useCrudDoc.js +1 -1
- package/dist/useCrudList.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/imageProcessing.js +1 -1
- 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/referenceEntity.d.ts +11 -0
- package/dist/utils/referenceEntity.d.ts.map +1 -0
- package/dist/utils/referenceEntity.js +1 -0
- package/dist/utils/uploadValidation.js +1 -1
- package/dist/utils/useRowTranslator.d.ts +21 -0
- package/dist/utils/useRowTranslator.d.ts.map +1 -0
- package/dist/utils/useRowTranslator.js +1 -0
- package/dist/workflows/defineWorkflow.js +1 -1
- package/dist/workflows/useEntityWorkflow.js +1 -1
- package/guidelines/COMPONENTS.md +87 -10
- package/guidelines/CRUD.md +336 -17
- package/guidelines/GOTCHAS.md +19 -1
- package/package.json +8 -8
- package/dist/builtinFieldTypes.d.ts +0 -23
- package/dist/builtinFieldTypes.d.ts.map +0 -1
- package/dist/builtinFieldTypes.js +0 -1
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":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC9D,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,qBAAqB,EACrB,SAAS,EACT,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,uBAAuB,EACvB,MAAM,EACN,WAAW,EACX,cAAc,EACd,SAAS,EACT,UAAU,EACV,cAAc,EACd,UAAU,EACV,QAAQ,EACR,eAAe,EACf,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGtD,YAAY,EACV,SAAS,EACT,MAAM,EACN,WAAW,EACX,SAAS,EACT,UAAU,EACV,QAAQ,EACR,eAAe,EACf,WAAW,EACX,eAAe,EACf,UAAU,GACX,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,SAAS,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;AAErE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,SAAS,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;AAEpE;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,SAAS,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;AAEhF;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,SAAS,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC;AAExE;;;;;;;;;;GAUG;AACH,MAAM,WAAW,oBAAoB,CACnC,CAAC,SAAS,SAAS,EACnB,EAAE,SAAS,cAAc,GAAG,cAAc,EAC1C,CAAC,SAAS,gBAAgB,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC;IAEjD;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,EAAE,CAAC;IAEf;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,uBAAuB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE/C;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,GAAG,KAAK,CAAC;IAEhE;;;;;;;OAOG;IACH,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;IAE/D;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;;;;;;;;OAYG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5B;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,CAAC,CAAC;CACZ;AAED,6DAA6D;AAC7D,MAAM,WAAW,uBAAuB;IACtC;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,sBAAsB,CAChC,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,WAAW,GAAG,CAAC,IACvB,CAAC,OAAO,GAAG,gBAAgB,EAC7B,OAAO,CAAC,EAAE,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC,EACnC,SAAS,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,EACjC,OAAO,CAAC,EAAE,uBAAuB,KAC9B,CAAC,KAAK,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;AAE3E;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,eAAe,CACzB,CAAC,SAAS,SAAS,EACnB,CAAC,SAAS,gBAAgB,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAC/C,UAAU,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,gBAAgB,CAC/B,CAAC,SAAS,SAAS,EACnB,EAAE,SAAS,cAAc,GAAG,cAAc,EAC1C,CAAC,SAAS,gBAAgB,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CACjD,SAAQ,aAAa,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3E;;;;;OAKG;IACH,YAAY,EAAE,sBAAsB,CAClC,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EACpB,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CACtB,CAAC;IAEF;;;;;;;;OAQG;IACH,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAEtC;;;OAGG;IACH,UAAU,EAAE,sBAAsB,CAAC;IAEnC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,aAAa,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,eAAe,EAAE,CAAC;IACtE;;;;OAIG;IACH,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B;;;OAGG;IACH,MAAM,EAAE,eAAe,EAAE,CAAC;IAE1B;;OAEG;IACH,SAAS,EAAE,EAAE,CAAC;IAEd;;OAEG;IACH,MAAM,EAAE,CAAC,CAAC;IAEV;;;OAGG;IACH,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;IAE9D;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAE3B;;;OAGG;IACH,UAAU,EAAE,UAAU,CAAC;IAEvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;IAEpB;;;OAGG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;IAEnB;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;;;OAIG;IACH,iBAAiB,EAAE,OAAO,CAAC;IAE3B;;;OAGG;IACH,SAAS,EAAE,MAAM,IAAI,CAAC;IAEtB;;;;OAIG;IACH,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;CAC3D;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB,CAChC,CAAC,SAAS,SAAS,EACnB,CAAC,SAAS,MAAM,eAAe,CAAC,CAAC,CAAC;IAElC;;OAEG;IACH,KAAK,EAAE,qBAAqB,CAC1B,eAAe,CAAC,CAAC,CAAC,EAClB,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAC9B,CAAC;IAEF;;OAEG;IACH,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;QAC1B,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IAEF;;OAEG;IACH,MAAM,EAAE,WAAW,CAAC;IAEpB;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,SAAS,EAAE,OAAO,CAAC;IAEnB;;;;;;;OAOG;IACH,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE;QAClB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB,KAAK,MAAM,GAAG,YAAY,CAAC;CAC7B"}
|
|
@@ -1,30 +1,45 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Initial values builders for CRUD forms
|
|
3
|
-
* @description
|
|
4
|
-
* - buildSchemaDefaults: compute create-mode defaults from entity definition only.
|
|
5
|
-
* - buildInitialFromRecord: overlay schema defaults with an existing DB record
|
|
6
|
-
* and apply type-specific normalizations (switch, price, etc.).
|
|
7
|
-
*
|
|
8
|
-
* These helpers provide a single, canonical "initialValues" snapshot that
|
|
9
|
-
* React Hook Form can use as its dirty baseline.
|
|
10
|
-
*/
|
|
11
1
|
import type { AnyEntity } from '@donotdev/core';
|
|
12
|
-
|
|
2
|
+
/** What the form state holds: the fields the form writes (`writableFields`). */
|
|
3
|
+
export interface FormProjection {
|
|
4
|
+
/** Field names the form writes, i18n companions included (`writableFields`) */
|
|
5
|
+
fields: ReadonlySet<string>;
|
|
6
|
+
/** Keep the record's `id` (edit of the record itself, not of an extension row) */
|
|
7
|
+
keepId?: boolean;
|
|
8
|
+
}
|
|
13
9
|
/**
|
|
14
|
-
* Build initial values for an existing DB record.
|
|
10
|
+
* Build initial values for an existing DB record, projected onto the form values.
|
|
15
11
|
*
|
|
16
|
-
* -
|
|
17
|
-
*
|
|
12
|
+
* - Keeps only the fields the form writes (`projection.fields`) and, with
|
|
13
|
+
* `keepId`, the record id: generated, technical, `editable: false` and
|
|
14
|
+
* role-denied values never enter form state, the local draft or the payload.
|
|
15
|
+
* - For each written field:
|
|
18
16
|
* - If the record has a non-null, non-undefined value, keep it.
|
|
19
17
|
* - Otherwise, apply the same type-specific defaults we use in forms.
|
|
18
|
+
*
|
|
19
|
+
* @param entity - Entity from `defineEntity()`
|
|
20
|
+
* @param record - Stored row (or create defaults), already filtered by the backend
|
|
21
|
+
* @param projection - Fields the form writes (`writableFields(entity, role, op)`)
|
|
22
|
+
* @returns The form values
|
|
23
|
+
*
|
|
24
|
+
* @version 0.2.0
|
|
25
|
+
* @since 0.0.1
|
|
26
|
+
* @author AMBROISE PARK Consulting
|
|
20
27
|
*/
|
|
21
|
-
export declare function buildInitialFromRecord
|
|
28
|
+
export declare function buildInitialFromRecord(entity: AnyEntity, record: Readonly<Record<string, unknown>>, projection: FormProjection): Record<string, unknown>;
|
|
22
29
|
/**
|
|
23
30
|
* Build schema defaults for create-mode forms.
|
|
24
31
|
*
|
|
25
32
|
* - Starts from an empty record and applies the same type-specific defaults as
|
|
26
|
-
* buildInitialFromRecord.
|
|
33
|
+
* buildInitialFromRecord, for the fields the form writes.
|
|
27
34
|
* - This represents "what a brand-new object would look like" before any user edits.
|
|
35
|
+
*
|
|
36
|
+
* @param entity - Entity from `defineEntity()`
|
|
37
|
+
* @param fields - Field names the form writes on create (`writableFields(entity, role, 'create')`)
|
|
38
|
+
* @returns The create defaults
|
|
39
|
+
*
|
|
40
|
+
* @version 0.2.0
|
|
41
|
+
* @since 0.0.1
|
|
42
|
+
* @author AMBROISE PARK Consulting
|
|
28
43
|
*/
|
|
29
|
-
export declare function buildSchemaDefaults
|
|
44
|
+
export declare function buildSchemaDefaults(entity: AnyEntity, fields: ReadonlySet<string>): Record<string, unknown>;
|
|
30
45
|
//# sourceMappingURL=buildInitialValues.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildInitialValues.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/buildInitialValues.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildInitialValues.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/buildInitialValues.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAgBhD,gFAAgF;AAChF,MAAM,WAAW,cAAc;IAC7B,+EAA+E;IAC/E,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5B,kFAAkF;IAClF,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACzC,UAAU,EAAE,cAAc,GACzB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoDzB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{createStatus as p}from"@donotdev/core";import{EMPTY_VALUE as d}from"./emptyValue";const b=new Set(["text","textarea","email","url","tel","iban","password","color"]);function a(s,i,c){const{fields:l,keepId:f=!1}=c,t=Object.fromEntries(Object.entries(i).filter(([e])=>l.has(e)||f&&e==="id"));return Object.entries(s.fields).forEach(([e,r])=>{if(!l.has(e))return;const n=t[e],o=!(e in t)||n===null||n===void 0;if(e==="status"&&o)t[e]=p(void 0);else if(b.has(r.type))(o||n==="")&&(t[e]=d);else if(r.type==="switch"){if(n==null){const u=r.options?.fieldSpecific;t[e]=u?.uncheckedValue??!1}}else o&&(r.type==="price"?t[e]=null:r.type==="checkbox"||r.type==="boolean"?t[e]=!1:(r.type==="number"||r.type==="range"||r.type==="rating")&&(t[e]=void 0))}),t}function h(s,i){return a(s,{},{fields:i})}export{a as buildInitialFromRecord,h as buildSchemaDefaults};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { FieldValues, Resolver } from 'react-hook-form';
|
|
2
|
+
import type { AnyEntity } from '@donotdev/core';
|
|
3
|
+
/** Evaluate only validation-relevant conditions against the complete retained form. */
|
|
4
|
+
export declare function getFormConditionStates(entity: AnyEntity, values: Record<string, unknown>): {
|
|
5
|
+
name: string;
|
|
6
|
+
visible: boolean;
|
|
7
|
+
required: boolean | undefined;
|
|
8
|
+
}[];
|
|
9
|
+
/**
|
|
10
|
+
* Form-only validation projection. Persistence schemas remain strict; inactive
|
|
11
|
+
* values are retained for drafts and domain normalization in the submit callback.
|
|
12
|
+
* Only the fields the form writes (`written`: `writableFields`) are validated and
|
|
13
|
+
* output: a field the viewer cannot write (a status editable by admins only, an
|
|
14
|
+
* `editable: false` field) is the writer's, not the form's.
|
|
15
|
+
* Schema and scope: the CRUD rules (core/schemas crud/), as the writers apply them.
|
|
16
|
+
* Create: the whole form (`draft` or `create` schema, `createStatus`). Edit
|
|
17
|
+
* (`updateCheck` on the base row): a draft, or leaving draft for a visible status,
|
|
18
|
+
* checks the whole form; any other edit checks only the fields that differ from the
|
|
19
|
+
* base row (rule 2: an update validates what changes).
|
|
20
|
+
*
|
|
21
|
+
* @template T - Form state the resolver reads
|
|
22
|
+
* @template TOutput - Values it outputs (`onValid`'s), `T` by default
|
|
23
|
+
* @param entity - Entity from `defineEntity()`
|
|
24
|
+
* @param operation - Form operation
|
|
25
|
+
* @param written - Field names the form writes (companions included)
|
|
26
|
+
* @param base - The row the form starts from: the stored row on edit, the caller's
|
|
27
|
+
* defaults on create (its status is read when form state has none)
|
|
28
|
+
* @returns React Hook Form resolver
|
|
29
|
+
*
|
|
30
|
+
* @version 0.4.0
|
|
31
|
+
* @since 0.2.4
|
|
32
|
+
* @author AMBROISE PARK Consulting
|
|
33
|
+
*/
|
|
34
|
+
export declare function createConditionAwareResolver<T extends FieldValues, TOutput = T>(entity: AnyEntity, operation: 'create' | 'edit', written: ReadonlySet<string>, base?: Readonly<Record<string, unknown>> | null): Resolver<T, unknown, TOutput>;
|
|
35
|
+
//# sourceMappingURL=conditionAwareResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditionAwareResolver.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/conditionAwareResolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAU7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,uFAAuF;AACvF,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;IAWxF;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,4BAA4B,CAC1C,CAAC,SAAS,WAAW,EACrB,OAAO,GAAG,CAAC,EAEX,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,QAAQ,GAAG,MAAM,EAC5B,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,EAC5B,IAAI,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,IAAI,GAC9C,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAkF/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{valibotResolver as K}from"@hookform/resolvers/valibot";import{createSchemas as q,evaluateFieldConditions as R,i18nFieldName as w,createStatus as x,statusCan as A,updateCheck as I}from"@donotdev/core";function S(d,u){return Object.entries(d.fields).filter(([,n])=>n.conditions?.visible||n.conditions?.required).map(([n,a])=>{const i=R(a.conditions,u);return{name:n,visible:i.visible,required:a.conditions?.required?i.required:a.validation?.required}})}function B(d,u,n,a){const i={...d,fields:Object.fromEntries(Object.entries(d.fields).filter(([s])=>n.has(s)))},k=q(i);let v,j,h=[];return async(s,E,g)=>{const m=S(i,s),p={...s,status:s.status??a?.status};let o,c=null;if(u==="edit"){const e=I(p,a);o=e.schemaKey,e.schemaKey==="update"&&!e.whole&&(c=Object.keys(i.fields).filter(l=>[l,w(l)].some(r=>JSON.stringify(s[r])!==JSON.stringify(a?.[r]))))}else o=A(x(p),"saveIncomplete")?"draft":"create";const y=JSON.stringify([o,m,c]);if(y!==v){const e=k[o];if(!("entries"in e)||typeof e.entries!="object"||e.entries===null)throw new Error("Expected an object write schema");const l=new Set(Object.keys(e.entries));h=m.filter(t=>!t.visible&&l.has(t.name)).flatMap(({name:t})=>i.fields[t]?.i18n===!0?[t,w(t)].filter(f=>l.has(f)):[t]);const r={...i.fields};if(c)for(const t of Object.keys(r))c.includes(t)||delete r[t];for(const[t,f]of Object.entries(r)){const O=m.find(J=>J.name===t);O&&(O.visible?f.conditions?.required&&(r[t]={...f,validation:{...f.validation,required:O.required}}):delete r[t])}const F=q({...i,fields:r})[o];j=K(F),v=y}const C=Object.fromEntries(h.filter(e=>Object.hasOwn(s,e)).map(e=>[e,s[e]])),b=await j(s,E,g);if(Object.keys(b.errors).length>0)return b;const N=c?Object.fromEntries(Object.entries(s).filter(([e])=>n.has(e))):{};return{errors:{},values:{...N,...C,...b.values}}}}export{B as createConditionAwareResolver,S as getFormConditionStates};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Empty value contract of entity forms
|
|
3
|
+
* @description One value means "not filled in" in form state, in validated data and in
|
|
4
|
+
* every adapter payload: `null`. It is native to Firestore, Postgres, REST and GraphQL,
|
|
5
|
+
* survives JSON (an `undefined` key is dropped, so a cleared field would never be
|
|
6
|
+
* written) and is what `v.nullish()` accepts for an optional field. `''` exists only
|
|
7
|
+
* inside the DOM input: fields display `value ?? ''` and report an emptied input
|
|
8
|
+
* through {@link fromInputValue}.
|
|
9
|
+
*
|
|
10
|
+
* @version 0.1.0
|
|
11
|
+
* @since 0.2.4
|
|
12
|
+
* @author AMBROISE PARK Consulting
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The form-state value of a field that is not filled in.
|
|
16
|
+
*
|
|
17
|
+
* @since 0.2.4
|
|
18
|
+
*/
|
|
19
|
+
export declare const EMPTY_VALUE: null;
|
|
20
|
+
/**
|
|
21
|
+
* Form-state value of a text input's DOM value: an emptied input is {@link EMPTY_VALUE}.
|
|
22
|
+
*
|
|
23
|
+
* @param value - The input's DOM value
|
|
24
|
+
* @returns The value to store in form state
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <Input value={field.value ?? ''} onChange={(e) => field.onChange(fromInputValue(e.target.value))} />
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @since 0.2.4
|
|
32
|
+
*/
|
|
33
|
+
export declare function fromInputValue(value: string): string | null;
|
|
34
|
+
//# sourceMappingURL=emptyValue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emptyValue.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/emptyValue.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AAEH;;;;GAIG;AACH,eAAO,MAAM,WAAW,MAAO,CAAC;AAEhC;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAE3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const n=null;function t(l){return l===""?null:l}export{n as EMPTY_VALUE,t as fromInputValue};
|
|
@@ -17,6 +17,20 @@ export interface RenderableField<T extends FieldType = FieldType> {
|
|
|
17
17
|
config: EntityField<T>;
|
|
18
18
|
/** Whether field is editable (input vs read-only) */
|
|
19
19
|
editable: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the form writes the field: an input (`editable`) or a derived
|
|
22
|
+
* (`editable: 'computed'`) field. Its value lives in form state; a field the form
|
|
23
|
+
* does not write (technical, `editable: false`, role-denied) is read from
|
|
24
|
+
* `form.record`.
|
|
25
|
+
* @since 0.2.5
|
|
26
|
+
*/
|
|
27
|
+
written: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Values the field's `conditions` read: the key of a 1:1 extension (`offer`)
|
|
30
|
+
* for its prefixed fields (`offer.priceExclVat`); omitted for the entity's own.
|
|
31
|
+
* @since 0.2.5
|
|
32
|
+
*/
|
|
33
|
+
scope?: string;
|
|
20
34
|
}
|
|
21
35
|
/** Options for field filtering */
|
|
22
36
|
export interface GetFieldsForOperationOptions {
|
|
@@ -32,42 +46,39 @@ export interface GetFieldsForOperationOptions {
|
|
|
32
46
|
availableFields?: string[];
|
|
33
47
|
}
|
|
34
48
|
/**
|
|
35
|
-
* Filters entity fields based on operation type and viewer role
|
|
49
|
+
* Filters entity fields based on operation type and viewer role, from the entity
|
|
50
|
+
* descriptor (`describeEntity`: write class, `editableFor`, visibility).
|
|
36
51
|
*
|
|
37
52
|
* Pure function, no React dependencies. Use for building custom form layouts.
|
|
38
53
|
*
|
|
39
|
-
*
|
|
40
|
-
* -
|
|
41
|
-
*
|
|
54
|
+
* Per write class (design 3.4):
|
|
55
|
+
* - `never` (hidden, `editable: 'generated'`, backend names): not shown, except
|
|
56
|
+
* technical fields on edit, shown read-only (`id`, `createdAt`, ...)
|
|
57
|
+
* - `program` (`editable: false`): shown read-only
|
|
58
|
+
* - `derived` (`editable: 'computed'`): shown read-only, written by the form
|
|
59
|
+
* - `user`: an input when `editableFor(viewerRole, operation)`, else read-only
|
|
42
60
|
*
|
|
43
|
-
* **
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* - If `availableFields` provided, only returns fields in that list (backend-filtered)
|
|
61
|
+
* **Create operation:** excludes `visibility: 'technical'` fields.
|
|
62
|
+
* **Edit operation:** if `availableFields` is provided, only returns those fields.
|
|
63
|
+
* Fields the viewer cannot see (`visibility` above the role, `hidden`) are left out.
|
|
47
64
|
*
|
|
48
|
-
* @param entity - Entity definition from defineEntity()
|
|
65
|
+
* @param entity - Entity definition from defineEntity(), or a field map
|
|
49
66
|
* @param options - Filtering options
|
|
50
67
|
* @returns Array of renderable fields with computed editability
|
|
68
|
+
* @throws When a field has a custom type and no value shape (`describeEntity`)
|
|
51
69
|
*
|
|
52
70
|
* @example
|
|
53
71
|
* ```typescript
|
|
54
72
|
* import { getFieldsForOperation } from '@donotdev/crud/forms';
|
|
55
73
|
* import { productEntity } from './entities/product';
|
|
56
74
|
*
|
|
57
|
-
* // Create form - excludes technical and hidden
|
|
58
|
-
* const createFields = getFieldsForOperation(productEntity, {
|
|
59
|
-
* operation: 'create',
|
|
60
|
-
* viewerRole: 'user'
|
|
61
|
-
* });
|
|
62
|
-
*
|
|
63
|
-
* // Edit form - uses backend-filtered fields
|
|
64
75
|
* const editFields = getFieldsForOperation(productEntity, {
|
|
65
76
|
* operation: 'edit',
|
|
66
77
|
* viewerRole: 'admin',
|
|
67
|
-
* availableFields: Object.keys(existingData)
|
|
68
78
|
* });
|
|
69
79
|
*
|
|
70
|
-
* //
|
|
80
|
+
* // Inputs for written editable fields; read-only display for the others
|
|
81
|
+
* // (`written`: from form state, else from form.record)
|
|
71
82
|
* editFields.map(({ name, config, editable }) => (
|
|
72
83
|
* editable
|
|
73
84
|
* ? <Input key={name} {...config} />
|
|
@@ -78,7 +89,7 @@ export interface GetFieldsForOperationOptions {
|
|
|
78
89
|
* @see {@link AnyEntity} for entity definition structure
|
|
79
90
|
* @see {@link RenderableField} for return type
|
|
80
91
|
*
|
|
81
|
-
* @version 0.
|
|
92
|
+
* @version 0.2.0
|
|
82
93
|
* @since 0.0.1
|
|
83
94
|
* @author AMBROISE PARK Consulting
|
|
84
95
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFieldsForOperation.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/getFieldsForOperation.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"getFieldsForOperation.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/getFieldsForOperation.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,WAAW,EAEhB,KAAK,SAAS,EACf,MAAM,gBAAgB,CAAC;AAExB,+EAA+E;AAC/E,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,SAAS,CAAC,QAAQ,CAAC,GACnB,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;AAE3C,oDAAoD;AACpD,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAC9D,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACvB,qDAAqD;IACrD,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,kCAAkC;AAClC,MAAM,WAAW,4BAA4B;IAC3C,0BAA0B;IAC1B,SAAS,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC7B,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAkCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE,4BAA4B,GACpC,eAAe,EAAE,CAuCnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{describeEntity as m,describeField as F,isFieldVisible as g}from"@donotdev/core";const f=new WeakMap;function v(t){if("fields"in t&&"name"in t&&typeof t.name=="string"){const i=t;return{fields:i.fields,descriptors:m(i).fields}}const s=t;let e=f.get(s);return e||(e=Object.fromEntries(Object.entries(s).map(([i,n])=>[i,F(i,n,"<fields>")])),f.set(s,e)),{fields:s,descriptors:e}}function w(t,s){const{operation:e,viewerRole:i,availableFields:n}=s,d=i??"guest",{fields:p,descriptors:b}=v(t),l=[];for(const[o,u]of Object.entries(p)){const r=b[o],c=r.visibleAt;if(!g(c,d)||e==="create"&&c==="technical"||r.write==="never"&&c!=="technical"||e==="edit"&&n&&!n.includes(o))continue;const a=r.editableFor(d,e);l.push({name:o,config:u,editable:a,written:a||r.write==="derived"})}return l}export{w as getFieldsForOperation};
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* @since 0.0.1
|
|
7
7
|
* @author AMBROISE PARK Consulting
|
|
8
8
|
*/
|
|
9
|
+
export { EMPTY_VALUE, fromInputValue } from './emptyValue';
|
|
9
10
|
export { isFieldEditable } from './isFieldEditable';
|
|
10
11
|
export type { ViewerRole } from './isFieldEditable';
|
|
11
12
|
export { getFieldsForOperation } from './getFieldsForOperation';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EACV,eAAe,EACf,4BAA4B,EAC5B,iBAAiB,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EACV,eAAe,EACf,4BAA4B,EAC5B,iBAAiB,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{EMPTY_VALUE as a,fromInputValue as t}from"./emptyValue";import{isFieldEditable as e}from"./isFieldEditable";import{getFieldsForOperation as s}from"./getFieldsForOperation";import{validateEntity as i}from"./validateEntity";import{translateFieldLabel as r,translateLabel as l}from"./translateFieldLabel";export{a as EMPTY_VALUE,t as fromInputValue,s as getFieldsForOperation,e as isFieldEditable,r as translateFieldLabel,l as translateLabel,i as validateEntity};
|