@payloadcms/ui 3.0.0-beta.53 → 3.0.0-beta.54
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/@types/assets.d.js.map +1 -1
- package/dist/assets/index.js.map +1 -1
- package/dist/elements/AppHeader/index.js.map +1 -1
- package/dist/elements/ArrayAction/index.js.map +1 -1
- package/dist/elements/Autosave/index.js.map +1 -1
- package/dist/elements/Banner/index.js.map +1 -1
- package/dist/elements/Button/index.js.map +1 -1
- package/dist/elements/Button/types.js.map +1 -1
- package/dist/elements/Card/index.js.map +1 -1
- package/dist/elements/CodeEditor/CodeEditor.js.map +1 -1
- package/dist/elements/CodeEditor/index.js.map +1 -1
- package/dist/elements/CodeEditor/types.js.map +1 -1
- package/dist/elements/Collapsible/index.js.map +1 -1
- package/dist/elements/Collapsible/provider.js.map +1 -1
- package/dist/elements/ColumnSelector/index.js.map +1 -1
- package/dist/elements/CopyToClipboard/index.js.map +1 -1
- package/dist/elements/DatePicker/DatePicker.js.map +1 -1
- package/dist/elements/DatePicker/getFormattedLocale.js.map +1 -1
- package/dist/elements/DatePicker/index.js.map +1 -1
- package/dist/elements/DatePicker/types.js.map +1 -1
- package/dist/elements/DeleteDocument/index.js.map +1 -1
- package/dist/elements/DeleteMany/index.js.map +1 -1
- package/dist/elements/DocumentControls/index.js.map +1 -1
- package/dist/elements/DocumentDrawer/DrawerContent.js +2 -2
- package/dist/elements/DocumentDrawer/DrawerContent.js.map +1 -1
- package/dist/elements/DocumentDrawer/index.js.map +1 -1
- package/dist/elements/DocumentDrawer/types.js.map +1 -1
- package/dist/elements/DocumentFields/index.js.map +1 -1
- package/dist/elements/DraggableSortable/DraggableSortableItem/index.js.map +1 -1
- package/dist/elements/DraggableSortable/DraggableSortableItem/types.js.map +1 -1
- package/dist/elements/DraggableSortable/index.js.map +1 -1
- package/dist/elements/DraggableSortable/types.js.map +1 -1
- package/dist/elements/DraggableSortable/useDraggableSortable/index.js.map +1 -1
- package/dist/elements/DraggableSortable/useDraggableSortable/types.js.map +1 -1
- package/dist/elements/Drawer/index.js.map +1 -1
- package/dist/elements/Drawer/types.js.map +1 -1
- package/dist/elements/Drawer/useDrawerSlug.js.map +1 -1
- package/dist/elements/Dropzone/index.js.map +1 -1
- package/dist/elements/DuplicateDocument/index.js.map +1 -1
- package/dist/elements/EditMany/index.js.map +1 -1
- package/dist/elements/EditUpload/index.d.ts.map +1 -1
- package/dist/elements/EditUpload/index.js +28 -11
- package/dist/elements/EditUpload/index.js.map +1 -1
- package/dist/elements/ErrorPill/index.js.map +1 -1
- package/dist/elements/FieldSelect/index.js.map +1 -1
- package/dist/elements/FileDetails/FileMeta/index.js.map +1 -1
- package/dist/elements/FileDetails/index.js.map +1 -1
- package/dist/elements/GenerateConfirmation/index.js.map +1 -1
- package/dist/elements/Gutter/index.js.map +1 -1
- package/dist/elements/Hamburger/index.js.map +1 -1
- package/dist/elements/HydrateClientUser/index.d.ts +0 -1
- package/dist/elements/HydrateClientUser/index.d.ts.map +1 -1
- package/dist/elements/HydrateClientUser/index.js.map +1 -1
- package/dist/elements/IDLabel/index.js.map +1 -1
- package/dist/elements/ListControls/getTextFieldsToBeSearched.d.ts.map +1 -1
- package/dist/elements/ListControls/getTextFieldsToBeSearched.js.map +1 -1
- package/dist/elements/ListControls/index.js.map +1 -1
- package/dist/elements/ListDrawer/DrawerContent.js.map +1 -1
- package/dist/elements/ListDrawer/index.js.map +1 -1
- package/dist/elements/ListDrawer/types.js.map +1 -1
- package/dist/elements/ListSelection/index.js.map +1 -1
- package/dist/elements/Loading/index.js.map +1 -1
- package/dist/elements/LoadingOverlay/index.js.map +1 -1
- package/dist/elements/LoadingOverlay/reducer.js.map +1 -1
- package/dist/elements/LoadingOverlay/types.js.map +1 -1
- package/dist/elements/Localizer/LocalizerLabel/index.js.map +1 -1
- package/dist/elements/Localizer/index.js.map +1 -1
- package/dist/elements/Logout/index.js.map +1 -1
- package/dist/elements/Modal/index.js.map +1 -1
- package/dist/elements/Nav/NavToggler/index.js.map +1 -1
- package/dist/elements/Nav/context.js.map +1 -1
- package/dist/elements/NavGroup/index.js.map +1 -1
- package/dist/elements/Pagination/ClickableArrow/index.js.map +1 -1
- package/dist/elements/Pagination/Page/index.js.map +1 -1
- package/dist/elements/Pagination/Separator/index.js.map +1 -1
- package/dist/elements/Pagination/index.js.map +1 -1
- package/dist/elements/PerPage/index.js.map +1 -1
- package/dist/elements/Pill/index.js.map +1 -1
- package/dist/elements/Popup/PopupButtonList/index.js.map +1 -1
- package/dist/elements/Popup/PopupTrigger/index.js.map +1 -1
- package/dist/elements/Popup/PopupTrigger/types.js.map +1 -1
- package/dist/elements/Popup/index.js.map +1 -1
- package/dist/elements/PreviewButton/index.js.map +1 -1
- package/dist/elements/PreviewButton/usePreviewURL.js.map +1 -1
- package/dist/elements/PreviewSizes/index.js.map +1 -1
- package/dist/elements/PublishButton/index.js.map +1 -1
- package/dist/elements/PublishMany/index.js.map +1 -1
- package/dist/elements/ReactSelect/ClearIndicator/index.js.map +1 -1
- package/dist/elements/ReactSelect/Control/index.js.map +1 -1
- package/dist/elements/ReactSelect/DropdownIndicator/index.js.map +1 -1
- package/dist/elements/ReactSelect/Input/index.js.map +1 -1
- package/dist/elements/ReactSelect/MultiValue/index.js.map +1 -1
- package/dist/elements/ReactSelect/MultiValueLabel/index.js.map +1 -1
- package/dist/elements/ReactSelect/MultiValueRemove/index.js.map +1 -1
- package/dist/elements/ReactSelect/SingleValue/index.js.map +1 -1
- package/dist/elements/ReactSelect/ValueContainer/index.js.map +1 -1
- package/dist/elements/ReactSelect/index.js.map +1 -1
- package/dist/elements/ReactSelect/types.d.ts +0 -1
- package/dist/elements/ReactSelect/types.d.ts.map +1 -1
- package/dist/elements/ReactSelect/types.js.map +1 -1
- package/dist/elements/RenderCustomClientComponent/index.js.map +1 -1
- package/dist/elements/RenderCustomComponent/index.js.map +1 -1
- package/dist/elements/RenderTitle/index.js.map +1 -1
- package/dist/elements/SaveButton/index.js.map +1 -1
- package/dist/elements/SaveDraftButton/index.js.map +1 -1
- package/dist/elements/SearchFilter/index.js.map +1 -1
- package/dist/elements/SelectAll/index.js.map +1 -1
- package/dist/elements/SelectRow/index.js.map +1 -1
- package/dist/elements/ShimmerEffect/index.js.map +1 -1
- package/dist/elements/SortColumn/index.js.map +1 -1
- package/dist/elements/SortComplex/index.js +2 -2
- package/dist/elements/SortComplex/index.js.map +1 -1
- package/dist/elements/Status/index.js.map +1 -1
- package/dist/elements/StayLoggedIn/index.js.map +1 -1
- package/dist/elements/StepNav/SetStepNav.d.ts +0 -1
- package/dist/elements/StepNav/SetStepNav.d.ts.map +1 -1
- package/dist/elements/StepNav/SetStepNav.js.map +1 -1
- package/dist/elements/StepNav/context.js.map +1 -1
- package/dist/elements/StepNav/index.js.map +1 -1
- package/dist/elements/StepNav/types.js.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/Array/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/Blocks/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/Checkbox/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/Code/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/Date/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/File/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/JSON/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/Relationship/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/Select/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/Textarea/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/index.d.ts +0 -1
- package/dist/elements/Table/DefaultCell/fields/index.d.ts.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/index.js.map +1 -1
- package/dist/elements/Table/RelationshipProvider/index.d.ts.map +1 -1
- package/dist/elements/Table/RelationshipProvider/index.js +11 -10
- package/dist/elements/Table/RelationshipProvider/index.js.map +1 -1
- package/dist/elements/Table/RelationshipProvider/reducer.js.map +1 -1
- package/dist/elements/Table/TableCellProvider/index.js.map +1 -1
- package/dist/elements/Table/index.js.map +1 -1
- package/dist/elements/TableColumns/buildColumnState.js.map +1 -1
- package/dist/elements/TableColumns/filterFields.d.ts.map +1 -1
- package/dist/elements/TableColumns/filterFields.js.map +1 -1
- package/dist/elements/TableColumns/getInitialColumns.d.ts.map +1 -1
- package/dist/elements/TableColumns/getInitialColumns.js.map +1 -1
- package/dist/elements/TableColumns/index.js.map +1 -1
- package/dist/elements/Thumbnail/index.js.map +1 -1
- package/dist/elements/ThumbnailCard/index.js.map +1 -1
- package/dist/elements/Tooltip/index.js.map +1 -1
- package/dist/elements/Translation/index.js.map +1 -1
- package/dist/elements/UnpublishMany/index.js.map +1 -1
- package/dist/elements/Upload/index.js.map +1 -1
- package/dist/elements/ViewDescription/index.js.map +1 -1
- package/dist/elements/ViewDescription/types.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/Date/index.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/Date/types.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/Number/index.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/Number/types.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/Relationship/index.d.ts.map +1 -1
- package/dist/elements/WhereBuilder/Condition/Relationship/index.js +8 -8
- package/dist/elements/WhereBuilder/Condition/Relationship/index.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/Relationship/optionsReducer.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/Relationship/types.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/Select/index.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/Select/types.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/Text/index.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/Text/types.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/index.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/types.js.map +1 -1
- package/dist/elements/WhereBuilder/field-types.js.map +1 -1
- package/dist/elements/WhereBuilder/index.js.map +1 -1
- package/dist/elements/WhereBuilder/reduceFieldMap.js.map +1 -1
- package/dist/elements/WhereBuilder/transformWhereQuery.js.map +1 -1
- package/dist/elements/WhereBuilder/types.js.map +1 -1
- package/dist/elements/WhereBuilder/validateWhereQuery.d.ts.map +1 -1
- package/dist/elements/WhereBuilder/validateWhereQuery.js.map +1 -1
- package/dist/elements/WindowInfo/index.js.map +1 -1
- package/dist/elements/WithServerSideProps/index.js.map +1 -1
- package/dist/elements/withMergedProps/index.js.map +1 -1
- package/dist/exports/client/index.d.ts +20 -21
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +6 -6
- package/dist/exports/client/index.js.map +4 -4
- package/dist/fields/Array/ArrayRow.js.map +1 -1
- package/dist/fields/Array/index.js.map +1 -1
- package/dist/fields/Blocks/BlockRow.js.map +1 -1
- package/dist/fields/Blocks/BlocksDrawer/BlockSearch/index.js.map +1 -1
- package/dist/fields/Blocks/BlocksDrawer/index.js.map +1 -1
- package/dist/fields/Blocks/RowActions.js.map +1 -1
- package/dist/fields/Blocks/SectionTitle/index.js.map +1 -1
- package/dist/fields/Blocks/index.js.map +1 -1
- package/dist/fields/Checkbox/Input.js.map +1 -1
- package/dist/fields/Checkbox/index.d.ts +1 -1
- package/dist/fields/Checkbox/index.d.ts.map +1 -1
- package/dist/fields/Checkbox/index.js +2 -2
- package/dist/fields/Checkbox/index.js.map +1 -1
- package/dist/fields/Checkbox/types.js.map +1 -1
- package/dist/fields/Code/index.d.ts +1 -1
- package/dist/fields/Code/index.d.ts.map +1 -1
- package/dist/fields/Code/index.js +2 -2
- package/dist/fields/Code/index.js.map +1 -1
- package/dist/fields/Collapsible/index.d.ts +1 -1
- package/dist/fields/Collapsible/index.d.ts.map +1 -1
- package/dist/fields/Collapsible/index.js +2 -2
- package/dist/fields/Collapsible/index.js.map +1 -1
- package/dist/fields/ConfirmPassword/index.d.ts +1 -1
- package/dist/fields/ConfirmPassword/index.d.ts.map +1 -1
- package/dist/fields/ConfirmPassword/index.js +1 -1
- package/dist/fields/ConfirmPassword/index.js.map +1 -1
- package/dist/fields/DateTime/index.d.ts +1 -1
- package/dist/fields/DateTime/index.d.ts.map +1 -1
- package/dist/fields/DateTime/index.js +2 -2
- package/dist/fields/DateTime/index.js.map +1 -1
- package/dist/fields/Email/index.d.ts +1 -1
- package/dist/fields/Email/index.d.ts.map +1 -1
- package/dist/fields/Email/index.js +2 -2
- package/dist/fields/Email/index.js.map +1 -1
- package/dist/fields/FieldDescription/index.js.map +1 -1
- package/dist/fields/FieldError/index.js.map +1 -1
- package/dist/fields/FieldLabel/index.js.map +1 -1
- package/dist/fields/Group/index.d.ts +2 -1
- package/dist/fields/Group/index.d.ts.map +1 -1
- package/dist/fields/Group/index.js +2 -2
- package/dist/fields/Group/index.js.map +1 -1
- package/dist/fields/Group/provider.js.map +1 -1
- package/dist/fields/{HiddenInput → Hidden}/index.d.ts +1 -1
- package/dist/fields/Hidden/index.d.ts.map +1 -0
- package/dist/fields/{HiddenInput → Hidden}/index.js +2 -2
- package/dist/fields/Hidden/index.js.map +1 -0
- package/dist/fields/JSON/index.d.ts.map +1 -1
- package/dist/fields/JSON/index.js +2 -2
- package/dist/fields/JSON/index.js.map +1 -1
- package/dist/fields/Number/index.d.ts.map +1 -1
- package/dist/fields/Number/index.js +2 -2
- package/dist/fields/Number/index.js.map +1 -1
- package/dist/fields/Password/index.d.ts +1 -1
- package/dist/fields/Password/index.d.ts.map +1 -1
- package/dist/fields/Password/index.js +2 -2
- package/dist/fields/Password/index.js.map +1 -1
- package/dist/fields/Point/index.d.ts +2 -1
- package/dist/fields/Point/index.d.ts.map +1 -1
- package/dist/fields/Point/index.js +2 -2
- package/dist/fields/Point/index.js.map +1 -1
- package/dist/fields/RadioGroup/Radio/index.js.map +1 -1
- package/dist/fields/RadioGroup/index.d.ts +1 -1
- package/dist/fields/RadioGroup/index.d.ts.map +1 -1
- package/dist/fields/RadioGroup/index.js +2 -2
- package/dist/fields/RadioGroup/index.js.map +1 -1
- package/dist/fields/Relationship/AddNew/index.js.map +1 -1
- package/dist/fields/Relationship/AddNew/types.js.map +1 -1
- package/dist/fields/Relationship/AddNew/useRelatedCollections.js.map +1 -1
- package/dist/fields/Relationship/createRelationMap.js.map +1 -1
- package/dist/fields/Relationship/findOptionsByValue.js.map +1 -1
- package/dist/fields/Relationship/index.d.ts +1 -1
- package/dist/fields/Relationship/index.d.ts.map +1 -1
- package/dist/fields/Relationship/index.js +2 -2
- package/dist/fields/Relationship/index.js.map +1 -1
- package/dist/fields/Relationship/optionsReducer.js.map +1 -1
- package/dist/fields/Relationship/select-components/MultiValueLabel/index.js.map +1 -1
- package/dist/fields/Relationship/select-components/SingleValue/index.js.map +1 -1
- package/dist/fields/Relationship/types.js.map +1 -1
- package/dist/fields/RichText/index.d.ts +1 -1
- package/dist/fields/RichText/index.d.ts.map +1 -1
- package/dist/fields/RichText/index.js +1 -1
- package/dist/fields/RichText/index.js.map +1 -1
- package/dist/fields/Row/index.d.ts +2 -1
- package/dist/fields/Row/index.d.ts.map +1 -1
- package/dist/fields/Row/index.js +2 -2
- package/dist/fields/Row/index.js.map +1 -1
- package/dist/fields/Row/provider.js.map +1 -1
- package/dist/fields/Row/types.js.map +1 -1
- package/dist/fields/Select/Input.js.map +1 -1
- package/dist/fields/Select/index.d.ts +1 -1
- package/dist/fields/Select/index.d.ts.map +1 -1
- package/dist/fields/Select/index.js +6 -4
- package/dist/fields/Select/index.js.map +1 -1
- package/dist/fields/Tabs/Tab/index.js.map +1 -1
- package/dist/fields/Tabs/index.d.ts +1 -1
- package/dist/fields/Tabs/index.d.ts.map +1 -1
- package/dist/fields/Tabs/index.js +2 -2
- package/dist/fields/Tabs/index.js.map +1 -1
- package/dist/fields/Tabs/provider.js.map +1 -1
- package/dist/fields/Text/Input.js.map +1 -1
- package/dist/fields/Text/index.d.ts +1 -1
- package/dist/fields/Text/index.d.ts.map +1 -1
- package/dist/fields/Text/index.js +2 -2
- package/dist/fields/Text/index.js.map +1 -1
- package/dist/fields/Text/types.js.map +1 -1
- package/dist/fields/Textarea/Input.js.map +1 -1
- package/dist/fields/Textarea/index.d.ts +1 -1
- package/dist/fields/Textarea/index.d.ts.map +1 -1
- package/dist/fields/Textarea/index.js +2 -2
- package/dist/fields/Textarea/index.js.map +1 -1
- package/dist/fields/Textarea/types.js.map +1 -1
- package/dist/fields/UI/index.d.ts +1 -1
- package/dist/fields/UI/index.d.ts.map +1 -1
- package/dist/fields/UI/index.js +1 -1
- package/dist/fields/UI/index.js.map +1 -1
- package/dist/fields/Upload/Input.js.map +1 -1
- package/dist/fields/Upload/index.d.ts +1 -1
- package/dist/fields/Upload/index.d.ts.map +1 -1
- package/dist/fields/Upload/index.js +1 -1
- package/dist/fields/Upload/index.js.map +1 -1
- package/dist/fields/Upload/types.js.map +1 -1
- package/dist/fields/index.js +48 -48
- package/dist/fields/index.js.map +1 -1
- package/dist/fields/shared/index.d.ts +0 -1
- package/dist/fields/shared/index.d.ts.map +1 -1
- package/dist/fields/shared/index.js.map +1 -1
- package/dist/forms/FieldPropsProvider/index.js.map +1 -1
- package/dist/forms/Form/context.d.ts +0 -1
- package/dist/forms/Form/context.d.ts.map +1 -1
- package/dist/forms/Form/context.js.map +1 -1
- package/dist/forms/Form/createNestedFieldPath.js.map +1 -1
- package/dist/forms/Form/errorMessages.js.map +1 -1
- package/dist/forms/Form/fieldReducer.js +2 -2
- package/dist/forms/Form/fieldReducer.js.map +1 -1
- package/dist/forms/Form/getDataByPath.d.ts.map +1 -1
- package/dist/forms/Form/getDataByPath.js.map +1 -1
- package/dist/forms/Form/getSiblingData.js.map +1 -1
- package/dist/forms/Form/index.js +5 -5
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/forms/Form/initContextState.js.map +1 -1
- package/dist/forms/Form/mergeErrorPaths.js.map +1 -1
- package/dist/forms/Form/mergeServerFormState.js +2 -2
- package/dist/forms/Form/mergeServerFormState.js.map +1 -1
- package/dist/forms/Form/rows.js.map +1 -1
- package/dist/forms/Form/types.js.map +1 -1
- package/dist/forms/NullifyField/index.js +2 -2
- package/dist/forms/NullifyField/index.js.map +1 -1
- package/dist/forms/RenderFields/RenderField.js +2 -2
- package/dist/forms/RenderFields/RenderField.js.map +1 -1
- package/dist/forms/RenderFields/index.js.map +1 -1
- package/dist/forms/RenderFields/types.js.map +1 -1
- package/dist/forms/RowLabel/Context/index.d.ts.map +1 -1
- package/dist/forms/RowLabel/Context/index.js.map +1 -1
- package/dist/forms/RowLabel/index.js.map +1 -1
- package/dist/forms/RowLabel/types.js.map +1 -1
- package/dist/forms/Submit/index.js.map +1 -1
- package/dist/forms/WatchChildErrors/buildPathSegments.d.ts.map +1 -1
- package/dist/forms/WatchChildErrors/buildPathSegments.js.map +1 -1
- package/dist/forms/WatchChildErrors/getFieldStateFromPaths.js.map +1 -1
- package/dist/forms/WatchChildErrors/getNestedFieldState.js.map +1 -1
- package/dist/forms/WatchChildErrors/index.js.map +1 -1
- package/dist/forms/buildStateFromSchema/addFieldStatePromise.d.ts.map +1 -1
- package/dist/forms/buildStateFromSchema/addFieldStatePromise.js.map +1 -1
- package/dist/forms/buildStateFromSchema/buildStateFromSchema.spec.js.map +1 -1
- package/dist/forms/buildStateFromSchema/calculateDefaultValues/index.d.ts.map +1 -1
- package/dist/forms/buildStateFromSchema/calculateDefaultValues/index.js.map +1 -1
- package/dist/forms/buildStateFromSchema/calculateDefaultValues/iterateFields.d.ts.map +1 -1
- package/dist/forms/buildStateFromSchema/calculateDefaultValues/iterateFields.js.map +1 -1
- package/dist/forms/buildStateFromSchema/calculateDefaultValues/promise.d.ts.map +1 -1
- package/dist/forms/buildStateFromSchema/calculateDefaultValues/promise.js.map +1 -1
- package/dist/forms/buildStateFromSchema/getFilterOptionsQuery.d.ts +1 -1
- package/dist/forms/buildStateFromSchema/getFilterOptionsQuery.d.ts.map +1 -1
- package/dist/forms/buildStateFromSchema/getFilterOptionsQuery.js.map +1 -1
- package/dist/forms/buildStateFromSchema/index.d.ts.map +1 -1
- package/dist/forms/buildStateFromSchema/index.js.map +1 -1
- package/dist/forms/buildStateFromSchema/iterateFields.d.ts.map +1 -1
- package/dist/forms/buildStateFromSchema/iterateFields.js.map +1 -1
- package/dist/forms/useField/index.d.ts.map +1 -1
- package/dist/forms/useField/index.js.map +1 -1
- package/dist/forms/useField/types.js.map +1 -1
- package/dist/forms/withCondition/WatchCondition.js.map +1 -1
- package/dist/forms/withCondition/index.d.ts.map +1 -1
- package/dist/forms/withCondition/index.js.map +1 -1
- package/dist/graphics/Account/Default/index.js.map +1 -1
- package/dist/graphics/Account/Gravatar/index.d.ts.map +1 -1
- package/dist/graphics/Account/Gravatar/index.js +4 -4
- package/dist/graphics/Account/Gravatar/index.js.map +1 -1
- package/dist/graphics/Account/index.js.map +1 -1
- package/dist/graphics/DefaultBlockImage/index.js.map +1 -1
- package/dist/graphics/ExternalLink/index.js.map +1 -1
- package/dist/graphics/File/index.js.map +1 -1
- package/dist/graphics/Icon/index.js.map +1 -1
- package/dist/graphics/Logo/index.js.map +1 -1
- package/dist/hooks/useDebounce.js.map +1 -1
- package/dist/hooks/useDebouncedCallback.js.map +1 -1
- package/dist/hooks/useDebouncedEffect.js.map +1 -1
- package/dist/hooks/useDelay.d.ts.map +1 -1
- package/dist/hooks/useDelay.js.map +1 -1
- package/dist/hooks/useDelayedRender.js.map +1 -1
- package/dist/hooks/useHotkey.js.map +1 -1
- package/dist/hooks/useIntersect.d.ts +0 -1
- package/dist/hooks/useIntersect.d.ts.map +1 -1
- package/dist/hooks/useIntersect.js.map +1 -1
- package/dist/hooks/usePayloadAPI.d.ts +0 -1
- package/dist/hooks/usePayloadAPI.d.ts.map +1 -1
- package/dist/hooks/usePayloadAPI.js +2 -2
- package/dist/hooks/usePayloadAPI.js.map +1 -1
- package/dist/hooks/useResize.js.map +1 -1
- package/dist/hooks/useThrottledEffect.d.ts +0 -1
- package/dist/hooks/useThrottledEffect.d.ts.map +1 -1
- package/dist/hooks/useThrottledEffect.js.map +1 -1
- package/dist/hooks/useUseAsTitle.d.ts.map +1 -1
- package/dist/hooks/useUseAsTitle.js.map +1 -1
- package/dist/icons/Calendar/index.js.map +1 -1
- package/dist/icons/Check/index.js.map +1 -1
- package/dist/icons/Chevron/index.js.map +1 -1
- package/dist/icons/CloseMenu/index.js.map +1 -1
- package/dist/icons/CodeBlock/index.js.map +1 -1
- package/dist/icons/Copy/index.js.map +1 -1
- package/dist/icons/DragHandle/index.js.map +1 -1
- package/dist/icons/Edit/index.js.map +1 -1
- package/dist/icons/Line/index.js.map +1 -1
- package/dist/icons/Link/index.js.map +1 -1
- package/dist/icons/LogOut/index.js.map +1 -1
- package/dist/icons/Menu/index.js.map +1 -1
- package/dist/icons/MinimizeMaximize/index.js.map +1 -1
- package/dist/icons/More/index.js.map +1 -1
- package/dist/icons/Plus/index.js.map +1 -1
- package/dist/icons/Search/index.js.map +1 -1
- package/dist/icons/Swap/index.js.map +1 -1
- package/dist/icons/X/index.js.map +1 -1
- package/dist/providers/Actions/SetViewActions/index.js.map +1 -1
- package/dist/providers/Actions/index.js.map +1 -1
- package/dist/providers/Auth/index.d.ts.map +1 -1
- package/dist/providers/Auth/index.js.map +1 -1
- package/dist/providers/ClientFunction/index.js.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/actions.js.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/collections.d.ts +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/collections.d.ts.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/collections.js.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/fields.d.ts.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/fields.js +2 -2
- package/dist/providers/ComponentMap/buildComponentMap/fields.js.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/globals.d.ts +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/globals.d.ts.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/globals.js.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/index.d.ts +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/index.d.ts.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/index.js.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/types.d.ts +1 -2
- package/dist/providers/ComponentMap/buildComponentMap/types.d.ts.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/types.js.map +1 -1
- package/dist/providers/ComponentMap/index.js.map +1 -1
- package/dist/providers/Config/index.js.map +1 -1
- package/dist/providers/DocumentEvents/index.js.map +1 -1
- package/dist/providers/DocumentInfo/index.js.map +1 -1
- package/dist/providers/DocumentInfo/types.js.map +1 -1
- package/dist/providers/EditDepth/index.js.map +1 -1
- package/dist/providers/EntityVisibility/index.js.map +1 -1
- package/dist/providers/FieldComponents/index.js.map +1 -1
- package/dist/providers/FormQueryParams/index.d.ts.map +1 -1
- package/dist/providers/FormQueryParams/index.js.map +1 -1
- package/dist/providers/FormQueryParams/types.js.map +1 -1
- package/dist/providers/ListInfo/index.js.map +1 -1
- package/dist/providers/ListQuery/index.js.map +1 -1
- package/dist/providers/Locale/index.js.map +1 -1
- package/dist/providers/Operation/index.js.map +1 -1
- package/dist/providers/Params/index.js.map +1 -1
- package/dist/providers/Preferences/index.js +3 -3
- package/dist/providers/Preferences/index.js.map +1 -1
- package/dist/providers/Root/index.js.map +1 -1
- package/dist/providers/RouteCache/index.js.map +1 -1
- package/dist/providers/ScrollInfo/index.d.ts +0 -1
- package/dist/providers/ScrollInfo/index.d.ts.map +1 -1
- package/dist/providers/ScrollInfo/index.js.map +1 -1
- package/dist/providers/SearchParams/index.js.map +1 -1
- package/dist/providers/Selection/index.js +2 -2
- package/dist/providers/Selection/index.js.map +1 -1
- package/dist/providers/Theme/index.js.map +1 -1
- package/dist/providers/ToastContainer/icons/Error.js.map +1 -1
- package/dist/providers/ToastContainer/icons/Info.js.map +1 -1
- package/dist/providers/ToastContainer/icons/Success.js.map +1 -1
- package/dist/providers/ToastContainer/icons/Warning.js.map +1 -1
- package/dist/providers/ToastContainer/index.js.map +1 -1
- package/dist/providers/Translation/index.d.ts.map +1 -1
- package/dist/providers/Translation/index.js.map +1 -1
- package/dist/providers/WindowInfo/index.d.ts +0 -1
- package/dist/providers/WindowInfo/index.d.ts.map +1 -1
- package/dist/providers/WindowInfo/index.js.map +1 -1
- package/dist/utilities/api.d.ts.map +1 -1
- package/dist/utilities/api.js.map +1 -1
- package/dist/utilities/arraysHaveSameStrings.js.map +1 -1
- package/dist/utilities/buildComponentMap.js.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/index.d.ts.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/index.js.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/traverseFields.js.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/types.js.map +1 -1
- package/dist/utilities/buildFormState.d.ts.map +1 -1
- package/dist/utilities/buildFormState.js.map +1 -1
- package/dist/utilities/canUseDOM.js.map +1 -1
- package/dist/utilities/dateLocales.js.map +1 -1
- package/dist/utilities/findLocaleFromCode.js.map +1 -1
- package/dist/utilities/flattenFieldMap.d.ts.map +1 -1
- package/dist/utilities/flattenFieldMap.js.map +1 -1
- package/dist/utilities/formatDate.js.map +1 -1
- package/dist/utilities/formatDocTitle.d.ts +1 -1
- package/dist/utilities/formatDocTitle.d.ts.map +1 -1
- package/dist/utilities/formatDocTitle.js.map +1 -1
- package/dist/utilities/formatFields.js.map +1 -1
- package/dist/utilities/generateFieldID.js.map +1 -1
- package/dist/utilities/getFormState.d.ts +2 -2
- package/dist/utilities/getFormState.d.ts.map +1 -1
- package/dist/utilities/getFormState.js.map +1 -1
- package/dist/utilities/getOffsetTop.js.map +1 -1
- package/dist/utilities/getRequestLanguage.js.map +1 -1
- package/dist/utilities/getSupportedMonacoLocale.js.map +1 -1
- package/dist/utilities/groupNavItems.js.map +1 -1
- package/dist/utilities/hasSavePermission.js.map +1 -1
- package/dist/utilities/isEditing.js.map +1 -1
- package/dist/utilities/reduceFieldsToValues.js.map +1 -1
- package/dist/utilities/reduceFieldsToValuesWithValidation.js.map +1 -1
- package/dist/utilities/scrollToID.js.map +1 -1
- package/dist/utilities/setsAreEqual.d.ts.map +1 -1
- package/dist/utilities/setsAreEqual.js.map +1 -1
- package/dist/utilities/unflatten.js.map +1 -1
- package/package.json +7 -7
- package/dist/fields/HiddenInput/index.d.ts.map +0 -1
- package/dist/fields/HiddenInput/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/shared/index.tsx"],"sourcesContent":["import type {\n DocumentPreferences,\n ErrorProps,\n FieldDescriptionProps,\n LabelProps,\n Locale,\n SanitizedLabelProps,\n SanitizedLocalizationConfig,\n User,\n Validate,\n} from 'payload'\n\nexport const fieldBaseClass = 'field-type'\n\nexport type FormFieldBase = {\n AfterInput?: React.ReactNode\n BeforeInput?: React.ReactNode\n CustomDescription?: React.ReactNode\n CustomError?: React.ReactNode\n CustomLabel?: React.ReactNode\n className?: string\n custom?: Record<string, any>\n descriptionProps?: FieldDescriptionProps\n disabled?: boolean\n docPreferences?: DocumentPreferences\n errorProps?: ErrorProps\n label?: LabelProps['label']\n labelProps?: SanitizedLabelProps\n locale?: Locale\n localized?: boolean\n path?: string\n readOnly?: boolean\n required?: boolean\n rtl?: boolean\n style?: React.CSSProperties\n user?: User\n validate?: Validate\n}\n\n/**\n * Determines whether a field should be displayed as right-to-left (RTL) based on its configuration, payload's localization configuration and the adming user's currently enabled locale.\n\n * @returns Whether the field should be displayed as RTL.\n */\nexport function isFieldRTL({\n fieldLocalized,\n fieldRTL,\n locale,\n localizationConfig,\n}: {\n fieldLocalized: boolean\n fieldRTL: boolean\n locale: Locale\n localizationConfig?: SanitizedLocalizationConfig\n}) {\n const hasMultipleLocales =\n locale &&\n localizationConfig &&\n localizationConfig.locales &&\n localizationConfig.locales.length > 1\n\n const isCurrentLocaleDefaultLocale = locale?.code === localizationConfig?.defaultLocale\n\n return (\n (fieldRTL !== false &&\n locale?.rtl === true &&\n (fieldLocalized ||\n (!fieldLocalized && !hasMultipleLocales) || // If there is only one locale which is also rtl, that field is rtl too\n (!fieldLocalized && isCurrentLocaleDefaultLocale))) || // If the current locale is the default locale, but the field is not localized, that field is rtl too\n fieldRTL === true\n ) // If fieldRTL is true. This should be useful for when no localization is set at all in the payload config, but you still want fields to be rtl.\n}\n"],"names":["fieldBaseClass","isFieldRTL","fieldLocalized","fieldRTL","locale","localizationConfig","hasMultipleLocales","locales","length","isCurrentLocaleDefaultLocale","code","defaultLocale","rtl"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/shared/index.tsx"],"sourcesContent":["import type {\n DocumentPreferences,\n ErrorProps,\n FieldDescriptionProps,\n LabelProps,\n Locale,\n SanitizedLabelProps,\n SanitizedLocalizationConfig,\n User,\n Validate,\n} from 'payload'\n\nexport const fieldBaseClass = 'field-type'\n\nexport type FormFieldBase = {\n AfterInput?: React.ReactNode\n BeforeInput?: React.ReactNode\n CustomDescription?: React.ReactNode\n CustomError?: React.ReactNode\n CustomLabel?: React.ReactNode\n className?: string\n custom?: Record<string, any>\n descriptionProps?: FieldDescriptionProps\n disabled?: boolean\n docPreferences?: DocumentPreferences\n errorProps?: ErrorProps\n label?: LabelProps['label']\n labelProps?: SanitizedLabelProps\n locale?: Locale\n localized?: boolean\n path?: string\n readOnly?: boolean\n required?: boolean\n rtl?: boolean\n style?: React.CSSProperties\n user?: User\n validate?: Validate\n}\n\n/**\n * Determines whether a field should be displayed as right-to-left (RTL) based on its configuration, payload's localization configuration and the adming user's currently enabled locale.\n\n * @returns Whether the field should be displayed as RTL.\n */\nexport function isFieldRTL({\n fieldLocalized,\n fieldRTL,\n locale,\n localizationConfig,\n}: {\n fieldLocalized: boolean\n fieldRTL: boolean\n locale: Locale\n localizationConfig?: SanitizedLocalizationConfig\n}) {\n const hasMultipleLocales =\n locale &&\n localizationConfig &&\n localizationConfig.locales &&\n localizationConfig.locales.length > 1\n\n const isCurrentLocaleDefaultLocale = locale?.code === localizationConfig?.defaultLocale\n\n return (\n (fieldRTL !== false &&\n locale?.rtl === true &&\n (fieldLocalized ||\n (!fieldLocalized && !hasMultipleLocales) || // If there is only one locale which is also rtl, that field is rtl too\n (!fieldLocalized && isCurrentLocaleDefaultLocale))) || // If the current locale is the default locale, but the field is not localized, that field is rtl too\n fieldRTL === true\n ) // If fieldRTL is true. This should be useful for when no localization is set at all in the payload config, but you still want fields to be rtl.\n}\n"],"names":["fieldBaseClass","isFieldRTL","fieldLocalized","fieldRTL","locale","localizationConfig","hasMultipleLocales","locales","length","isCurrentLocaleDefaultLocale","code","defaultLocale","rtl"],"mappings":"AAYA,OAAO,MAAMA,iBAAiB,aAAY;AA2B1C;;;;CAIC,GACD,OAAO,SAASC,WAAW,EACzBC,cAAc,EACdC,QAAQ,EACRC,MAAM,EACNC,kBAAkB,EAMnB;IACC,MAAMC,qBACJF,UACAC,sBACAA,mBAAmBE,OAAO,IAC1BF,mBAAmBE,OAAO,CAACC,MAAM,GAAG;IAEtC,MAAMC,+BAA+BL,QAAQM,SAASL,oBAAoBM;IAE1E,OACE,AAACR,aAAa,SACZC,QAAQQ,QAAQ,QACfV,CAAAA,kBACE,CAACA,kBAAkB,CAACI,sBAAuB,uEAAuE;IAClH,CAACJ,kBAAkBO,4BAA4B,KAAO,qGAAqG;IAChKN,aAAa,KACb,gJAAgJ;;AACpJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/forms/FieldPropsProvider/index.tsx"],"sourcesContent":["'use client'\nimport type { FieldPermissions, FieldTypes } from 'payload'\n\nimport React from 'react'\n\nexport type FieldPropsContextType = {\n custom?: Record<any, string>\n indexPath?: string\n path: string\n permissions?: FieldPermissions\n readOnly: boolean\n schemaPath: string\n siblingPermissions: {\n [fieldName: string]: FieldPermissions\n }\n type: keyof FieldTypes\n}\n\nconst FieldPropsContext = React.createContext<FieldPropsContextType>({\n type: undefined as keyof FieldTypes,\n custom: {},\n indexPath: undefined,\n path: undefined,\n permissions: {} as FieldPermissions,\n readOnly: false,\n schemaPath: undefined,\n siblingPermissions: {},\n})\n\nexport type Props = {\n children: React.ReactNode\n custom?: Record<any, string>\n indexPath?: string\n isForceRendered?: boolean\n path: string\n permissions?: FieldPermissions\n readOnly: boolean\n schemaPath: string\n siblingPermissions: {\n [fieldName: string]: FieldPermissions\n }\n type: keyof FieldTypes\n}\n\nexport const FieldPropsProvider: React.FC<Props> = ({\n type,\n children,\n custom,\n indexPath,\n path,\n permissions,\n readOnly,\n schemaPath,\n siblingPermissions,\n}) => {\n return (\n <FieldPropsContext.Provider\n value={{\n type,\n custom,\n indexPath,\n path,\n permissions,\n readOnly,\n schemaPath,\n siblingPermissions,\n }}\n >\n {children}\n </FieldPropsContext.Provider>\n )\n}\n\nexport const useFieldProps = () => {\n const props = React.useContext(FieldPropsContext)\n return props\n}\n"],"names":["React","FieldPropsContext","createContext","type","undefined","custom","indexPath","path","permissions","readOnly","schemaPath","siblingPermissions","FieldPropsProvider","children","Provider","value","useFieldProps","props","useContext"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/FieldPropsProvider/index.tsx"],"sourcesContent":["'use client'\nimport type { FieldPermissions, FieldTypes } from 'payload'\n\nimport React from 'react'\n\nexport type FieldPropsContextType = {\n custom?: Record<any, string>\n indexPath?: string\n path: string\n permissions?: FieldPermissions\n readOnly: boolean\n schemaPath: string\n siblingPermissions: {\n [fieldName: string]: FieldPermissions\n }\n type: keyof FieldTypes\n}\n\nconst FieldPropsContext = React.createContext<FieldPropsContextType>({\n type: undefined as keyof FieldTypes,\n custom: {},\n indexPath: undefined,\n path: undefined,\n permissions: {} as FieldPermissions,\n readOnly: false,\n schemaPath: undefined,\n siblingPermissions: {},\n})\n\nexport type Props = {\n children: React.ReactNode\n custom?: Record<any, string>\n indexPath?: string\n isForceRendered?: boolean\n path: string\n permissions?: FieldPermissions\n readOnly: boolean\n schemaPath: string\n siblingPermissions: {\n [fieldName: string]: FieldPermissions\n }\n type: keyof FieldTypes\n}\n\nexport const FieldPropsProvider: React.FC<Props> = ({\n type,\n children,\n custom,\n indexPath,\n path,\n permissions,\n readOnly,\n schemaPath,\n siblingPermissions,\n}) => {\n return (\n <FieldPropsContext.Provider\n value={{\n type,\n custom,\n indexPath,\n path,\n permissions,\n readOnly,\n schemaPath,\n siblingPermissions,\n }}\n >\n {children}\n </FieldPropsContext.Provider>\n )\n}\n\nexport const useFieldProps = () => {\n const props = React.useContext(FieldPropsContext)\n return props\n}\n"],"names":["React","FieldPropsContext","createContext","type","undefined","custom","indexPath","path","permissions","readOnly","schemaPath","siblingPermissions","FieldPropsProvider","children","Provider","value","useFieldProps","props","useContext"],"mappings":"AAAA;;AAGA,OAAOA,WAAW,QAAO;AAezB,MAAMC,kCAAoBD,MAAME,aAAa,CAAwB;IACnEC,MAAMC;IACNC,QAAQ,CAAC;IACTC,WAAWF;IACXG,MAAMH;IACNI,aAAa,CAAC;IACdC,UAAU;IACVC,YAAYN;IACZO,oBAAoB,CAAC;AACvB;AAiBA,OAAO,MAAMC,qBAAsC,CAAC,EAClDT,IAAI,EACJU,QAAQ,EACRR,MAAM,EACNC,SAAS,EACTC,IAAI,EACJC,WAAW,EACXC,QAAQ,EACRC,UAAU,EACVC,kBAAkB,EACnB;IACC,qBACE,KAACV,kBAAkBa,QAAQ;QACzBC,OAAO;YACLZ;YACAE;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;QACF;kBAECE;;AAGP,EAAC;AAED,OAAO,MAAMG,gBAAgB;IAC3B,MAAMC,QAAQjB,MAAMkB,UAAU,CAACjB;IAC/B,OAAOgB;AACT,EAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" resolution-mode="require"/>
|
|
2
1
|
import type { Context, FormFieldsContext as FormFieldsContextType } from './types.js';
|
|
3
2
|
declare const FormContext: import("react").Context<Context>;
|
|
4
3
|
declare const FormWatchContext: import("react").Context<Context>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/forms/Form/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/forms/Form/context.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,IAAI,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAErF,QAAA,MAAM,WAAW,kCAA+B,CAAA;AAChD,QAAA,MAAM,gBAAgB,kCAA+B,CAAA;AACrD,QAAA,MAAM,gBAAgB,kCAAuB,CAAA;AAC7C,QAAA,MAAM,iBAAiB,kCAAuB,CAAA;AAC9C,QAAA,MAAM,eAAe,kCAAuB,CAAA;AAC5C,QAAA,MAAM,mBAAmB,kCAAuB,CAAA;AAChD,QAAA,MAAM,iBAAiB,+DAAiE,CAAA;AAExF;;;;GAIG;AACH,QAAA,MAAM,OAAO,QAAO,OAAkC,CAAA;AACtD,QAAA,MAAM,YAAY,QAAO,OAAuC,CAAA;AAChE,QAAA,MAAM,gBAAgB,QAAO,OAAuC,CAAA;AACpE,QAAA,MAAM,iBAAiB,QAAO,OAAwC,CAAA;AACtE,QAAA,MAAM,eAAe,QAAO,OAAsC,CAAA;AAClE,QAAA,MAAM,mBAAmB,QAAO,OAA0C,CAAA;AAE1E;;;;GAIG;AACH,QAAA,MAAM,aAAa,GAAI,KAAK,sBAChB,CAAC,OAAO,EAAE,qBAAqB,KAAK,KAAK,KAClD,KAAwD,CAAA;AAE3D;;;;GAIG;AACH,QAAA,MAAM,gBAAgB,QAAO,qBAA0D,CAAA;AAEvF,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,OAAO,EACP,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,GACb,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/forms/Form/context.ts"],"sourcesContent":["'use client'\nimport { createContext, useContext } from 'react'\nimport {\n createContext as createSelectorContext,\n useContextSelector,\n useContext as useFullContext,\n} from 'use-context-selector'\n\nimport type { Context, FormFieldsContext as FormFieldsContextType } from './types.js'\n\nconst FormContext = createContext({} as Context)\nconst FormWatchContext = createContext({} as Context)\nconst SubmittedContext = createContext(false)\nconst ProcessingContext = createContext(false)\nconst ModifiedContext = createContext(false)\nconst InitializingContext = createContext(false)\nconst FormFieldsContext = createSelectorContext<FormFieldsContextType>([{}, () => null])\n\n/**\n * Get the state of the form, can be used to submit & validate the form.\n *\n * @see https://payloadcms.com/docs/admin/hooks#useform\n */\nconst useForm = (): Context => useContext(FormContext)\nconst useWatchForm = (): Context => useContext(FormWatchContext)\nconst useFormSubmitted = (): boolean => useContext(SubmittedContext)\nconst useFormProcessing = (): boolean => useContext(ProcessingContext)\nconst useFormModified = (): boolean => useContext(ModifiedContext)\nconst useFormInitializing = (): boolean => useContext(InitializingContext)\n\n/**\n * Get and set the value of a form field based on a selector\n *\n * @see https://payloadcms.com/docs/admin/hooks#useformfields\n */\nconst useFormFields = <Value = unknown>(\n selector: (context: FormFieldsContextType) => Value,\n): Value => useContextSelector(FormFieldsContext, selector)\n\n/**\n * Get the state of all form fields.\n *\n * @see https://payloadcms.com/docs/admin/hooks#useallformfields\n */\nconst useAllFormFields = (): FormFieldsContextType => useFullContext(FormFieldsContext)\n\nexport {\n FormContext,\n FormFieldsContext,\n FormWatchContext,\n InitializingContext,\n ModifiedContext,\n ProcessingContext,\n SubmittedContext,\n useAllFormFields,\n useForm,\n useFormFields,\n useFormInitializing,\n useFormModified,\n useFormProcessing,\n useFormSubmitted,\n useWatchForm,\n}\n"],"names":["createContext","useContext","createSelectorContext","useContextSelector","useFullContext","FormContext","FormWatchContext","SubmittedContext","ProcessingContext","ModifiedContext","InitializingContext","FormFieldsContext","useForm","useWatchForm","useFormSubmitted","useFormProcessing","useFormModified","useFormInitializing","useFormFields","selector","useAllFormFields"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/Form/context.ts"],"sourcesContent":["'use client'\nimport { createContext, useContext } from 'react'\nimport {\n createContext as createSelectorContext,\n useContextSelector,\n useContext as useFullContext,\n} from 'use-context-selector'\n\nimport type { Context, FormFieldsContext as FormFieldsContextType } from './types.js'\n\nconst FormContext = createContext({} as Context)\nconst FormWatchContext = createContext({} as Context)\nconst SubmittedContext = createContext(false)\nconst ProcessingContext = createContext(false)\nconst ModifiedContext = createContext(false)\nconst InitializingContext = createContext(false)\nconst FormFieldsContext = createSelectorContext<FormFieldsContextType>([{}, () => null])\n\n/**\n * Get the state of the form, can be used to submit & validate the form.\n *\n * @see https://payloadcms.com/docs/admin/hooks#useform\n */\nconst useForm = (): Context => useContext(FormContext)\nconst useWatchForm = (): Context => useContext(FormWatchContext)\nconst useFormSubmitted = (): boolean => useContext(SubmittedContext)\nconst useFormProcessing = (): boolean => useContext(ProcessingContext)\nconst useFormModified = (): boolean => useContext(ModifiedContext)\nconst useFormInitializing = (): boolean => useContext(InitializingContext)\n\n/**\n * Get and set the value of a form field based on a selector\n *\n * @see https://payloadcms.com/docs/admin/hooks#useformfields\n */\nconst useFormFields = <Value = unknown>(\n selector: (context: FormFieldsContextType) => Value,\n): Value => useContextSelector(FormFieldsContext, selector)\n\n/**\n * Get the state of all form fields.\n *\n * @see https://payloadcms.com/docs/admin/hooks#useallformfields\n */\nconst useAllFormFields = (): FormFieldsContextType => useFullContext(FormFieldsContext)\n\nexport {\n FormContext,\n FormFieldsContext,\n FormWatchContext,\n InitializingContext,\n ModifiedContext,\n ProcessingContext,\n SubmittedContext,\n useAllFormFields,\n useForm,\n useFormFields,\n useFormInitializing,\n useFormModified,\n useFormProcessing,\n useFormSubmitted,\n useWatchForm,\n}\n"],"names":["createContext","useContext","createSelectorContext","useContextSelector","useFullContext","FormContext","FormWatchContext","SubmittedContext","ProcessingContext","ModifiedContext","InitializingContext","FormFieldsContext","useForm","useWatchForm","useFormSubmitted","useFormProcessing","useFormModified","useFormInitializing","useFormFields","selector","useAllFormFields"],"mappings":"AAAA;AACA,SAASA,aAAa,EAAEC,UAAU,QAAQ,QAAO;AACjD,SACED,iBAAiBE,qBAAqB,EACtCC,kBAAkB,EAClBF,cAAcG,cAAc,QACvB,uBAAsB;AAI7B,MAAMC,cAAcL,cAAc,CAAC;AACnC,MAAMM,mBAAmBN,cAAc,CAAC;AACxC,MAAMO,mBAAmBP,cAAc;AACvC,MAAMQ,oBAAoBR,cAAc;AACxC,MAAMS,kBAAkBT,cAAc;AACtC,MAAMU,sBAAsBV,cAAc;AAC1C,MAAMW,oBAAoBT,sBAA6C;IAAC,CAAC;IAAG,IAAM;CAAK;AAEvF;;;;CAIC,GACD,MAAMU,UAAU,IAAeX,WAAWI;AAC1C,MAAMQ,eAAe,IAAeZ,WAAWK;AAC/C,MAAMQ,mBAAmB,IAAeb,WAAWM;AACnD,MAAMQ,oBAAoB,IAAed,WAAWO;AACpD,MAAMQ,kBAAkB,IAAef,WAAWQ;AAClD,MAAMQ,sBAAsB,IAAehB,WAAWS;AAEtD;;;;CAIC,GACD,MAAMQ,gBAAgB,CACpBC,WACUhB,mBAAmBQ,mBAAmBQ;AAElD;;;;CAIC,GACD,MAAMC,mBAAmB,IAA6BhB,eAAeO;AAErE,SACEN,WAAW,EACXM,iBAAiB,EACjBL,gBAAgB,EAChBI,mBAAmB,EACnBD,eAAe,EACfD,iBAAiB,EACjBD,gBAAgB,EAChBa,gBAAgB,EAChBR,OAAO,EACPM,aAAa,EACbD,mBAAmB,EACnBD,eAAe,EACfD,iBAAiB,EACjBD,gBAAgB,EAChBD,YAAY,KACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/forms/Form/createNestedFieldPath.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { fieldAffectsData } from 'payload/shared'\n\nimport type { MappedField } from '../../providers/ComponentMap/buildComponentMap/types.js'\n\nexport const createNestedFieldPath = (parentPath: string, field: Field): string => {\n if (parentPath) {\n if (fieldAffectsData(field)) {\n return `${parentPath}.${field.name}`\n }\n\n return parentPath\n }\n\n if (fieldAffectsData(field)) {\n return field.name\n }\n\n return ''\n}\n\nexport const createNestedClientFieldPath = (parentPath: string, field: MappedField): string => {\n if (parentPath) {\n if (field.isFieldAffectingData) {\n return `${parentPath}.${field.name}`\n }\n }\n\n if (field.isFieldAffectingData) {\n return field.name\n }\n\n return field.name\n}\n"],"names":["fieldAffectsData","createNestedFieldPath","parentPath","field","name","createNestedClientFieldPath","isFieldAffectingData"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/Form/createNestedFieldPath.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { fieldAffectsData } from 'payload/shared'\n\nimport type { MappedField } from '../../providers/ComponentMap/buildComponentMap/types.js'\n\nexport const createNestedFieldPath = (parentPath: string, field: Field): string => {\n if (parentPath) {\n if (fieldAffectsData(field)) {\n return `${parentPath}.${field.name}`\n }\n\n return parentPath\n }\n\n if (fieldAffectsData(field)) {\n return field.name\n }\n\n return ''\n}\n\nexport const createNestedClientFieldPath = (parentPath: string, field: MappedField): string => {\n if (parentPath) {\n if (field.isFieldAffectingData) {\n return `${parentPath}.${field.name}`\n }\n }\n\n if (field.isFieldAffectingData) {\n return field.name\n }\n\n return field.name\n}\n"],"names":["fieldAffectsData","createNestedFieldPath","parentPath","field","name","createNestedClientFieldPath","isFieldAffectingData"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,iBAAgB;AAIjD,OAAO,MAAMC,wBAAwB,CAACC,YAAoBC;IACxD,IAAID,YAAY;QACd,IAAIF,iBAAiBG,QAAQ;YAC3B,OAAO,CAAC,EAAED,WAAW,CAAC,EAAEC,MAAMC,IAAI,CAAC,CAAC;QACtC;QAEA,OAAOF;IACT;IAEA,IAAIF,iBAAiBG,QAAQ;QAC3B,OAAOA,MAAMC,IAAI;IACnB;IAEA,OAAO;AACT,EAAC;AAED,OAAO,MAAMC,8BAA8B,CAACH,YAAoBC;IAC9D,IAAID,YAAY;QACd,IAAIC,MAAMG,oBAAoB,EAAE;YAC9B,OAAO,CAAC,EAAEJ,WAAW,CAAC,EAAEC,MAAMC,IAAI,CAAC,CAAC;QACtC;IACF;IAEA,IAAID,MAAMG,oBAAoB,EAAE;QAC9B,OAAOH,MAAMC,IAAI;IACnB;IAEA,OAAOD,MAAMC,IAAI;AACnB,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/forms/Form/errorMessages.ts"],"sourcesContent":["export const errorMessages = {\n 413: 'Your request was too large to submit successfully.',\n}\n"],"names":["errorMessages"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/Form/errorMessages.ts"],"sourcesContent":["export const errorMessages = {\n 413: 'Your request was too large to submit successfully.',\n}\n"],"names":["errorMessages"],"mappings":"AAAA,OAAO,MAAMA,gBAAgB;IAC3B,KAAK;AACP,EAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ObjectIdImport from 'bson-objectid';
|
|
2
|
-
import
|
|
2
|
+
import { dequal } from 'dequal/lite'; // lite: no need for Map and Set support
|
|
3
3
|
import { deepCopyObject } from 'payload/shared';
|
|
4
4
|
import { flattenRows, separateRows } from './rows.js';
|
|
5
5
|
const ObjectId = ObjectIdImport.default || ObjectIdImport;
|
|
@@ -19,7 +19,7 @@ const ObjectId = ObjectIdImport.default || ObjectIdImport;
|
|
|
19
19
|
Object.entries(action.state).forEach(([path, field])=>{
|
|
20
20
|
const oldField = state[path];
|
|
21
21
|
const newField = field;
|
|
22
|
-
if (!
|
|
22
|
+
if (!dequal(oldField, newField)) {
|
|
23
23
|
newState[path] = newField;
|
|
24
24
|
} else if (oldField) {
|
|
25
25
|
newState[path] = oldField;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/forms/Form/fieldReducer.ts"],"sourcesContent":["import type { FormField, FormState, Row } from 'payload'\n\nimport ObjectIdImport from 'bson-objectid'\nimport equal from 'deep-equal'\nimport { deepCopyObject } from 'payload/shared'\n\nimport type { FieldAction } from './types.js'\n\nimport { flattenRows, separateRows } from './rows.js'\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\n/**\n * Reducer which modifies the form field state (all the current data of the fields in the form). When called using dispatch, it will return a new state object.\n */\nexport function fieldReducer(state: FormState, action: FieldAction): FormState {\n switch (action.type) {\n case 'REPLACE_STATE': {\n if (action.optimize !== false) {\n // Only update fields that have changed\n // by comparing old value / initialValue to new\n // ..\n // This is a performance enhancement for saving\n // large documents with hundreds of fields\n const newState = {}\n\n Object.entries(action.state).forEach(([path, field]) => {\n const oldField = state[path]\n const newField = field\n\n if (!equal(oldField, newField)) {\n newState[path] = newField\n } else if (oldField) {\n newState[path] = oldField\n }\n })\n return newState\n }\n // If we're not optimizing, just set the state to the new state\n return action.state\n }\n\n case 'REMOVE': {\n const newState = { ...state }\n if (newState[action.path]) delete newState[action.path]\n return newState\n }\n\n case 'ADD_SERVER_ERRORS': {\n let newState = { ...state }\n\n const errorPaths: { fieldErrorPath: string; parentPath: string }[] = []\n\n action.errors.forEach(({ field, message }) => {\n newState[field] = {\n ...(newState[field] || {\n initialValue: null,\n value: null,\n }),\n errorMessage: message,\n valid: false,\n }\n\n const segments = field.split('.')\n if (segments.length > 1) {\n errorPaths.push({\n fieldErrorPath: field,\n parentPath: segments.slice(0, segments.length - 1).join('.'),\n })\n }\n })\n\n newState = Object.entries(newState).reduce((acc, [path, fieldState]) => {\n const fieldErrorPaths = errorPaths.reduce((errorACC, { fieldErrorPath, parentPath }) => {\n if (parentPath.startsWith(path)) {\n errorACC.push(fieldErrorPath)\n }\n return errorACC\n }, [])\n\n let changed = false\n\n if (fieldErrorPaths.length > 0) {\n const newErrorPaths = Array.isArray(fieldState.errorPaths) ? fieldState.errorPaths : []\n\n fieldErrorPaths.forEach((fieldErrorPath) => {\n if (!newErrorPaths.includes(fieldErrorPath)) {\n newErrorPaths.push(fieldErrorPath)\n changed = true\n }\n })\n\n if (changed) {\n acc[path] = {\n ...fieldState,\n errorPaths: newErrorPaths,\n }\n }\n }\n\n if (!changed) {\n acc[path] = fieldState\n }\n\n return acc\n }, {})\n\n return newState\n }\n\n case 'UPDATE': {\n const newField = Object.entries(action).reduce(\n (field, [key, value]) => {\n if (\n [\n 'disableFormData',\n 'errorMessage',\n 'initialValue',\n 'rows',\n 'valid',\n 'validate',\n 'value',\n ].includes(key)\n ) {\n return {\n ...field,\n [key]: value,\n }\n }\n\n return field\n },\n state[action.path] || ({} as FormField),\n )\n\n const newState = {\n ...state,\n [action.path]: newField,\n }\n\n return newState\n }\n\n case 'REMOVE_ROW': {\n const { path, rowIndex } = action\n const { remainingFields, rows } = separateRows(path, state)\n const rowsMetadata = [...(state[path]?.rows || [])]\n\n rows.splice(rowIndex, 1)\n rowsMetadata.splice(rowIndex, 1)\n\n const newState: FormState = {\n ...remainingFields,\n [path]: {\n ...state[path],\n disableFormData: rows.length > 0,\n rows: rowsMetadata,\n value: rows.length,\n },\n ...flattenRows(path, rows),\n }\n\n return newState\n }\n\n case 'ADD_ROW': {\n const { blockType, path, rowIndex: rowIndexFromArgs, subFieldState = {} } = action\n\n const rowIndex =\n typeof rowIndexFromArgs === 'number' ? rowIndexFromArgs : state[path]?.rows?.length || 0\n\n const withNewRow = [...(state[path]?.rows || [])]\n\n const newRow: Row = {\n id: (subFieldState?.id?.value as string) || new ObjectId().toHexString(),\n blockType: blockType || undefined,\n collapsed: false,\n }\n\n withNewRow.splice(rowIndex, 0, newRow)\n\n if (blockType) {\n subFieldState.blockType = {\n initialValue: blockType,\n valid: true,\n value: blockType,\n }\n }\n\n // add new row to array _field state_\n const { remainingFields, rows: siblingRows } = separateRows(path, state)\n siblingRows.splice(rowIndex, 0, subFieldState)\n\n const newState: FormState = {\n ...remainingFields,\n ...flattenRows(path, siblingRows),\n [path]: {\n ...state[path],\n disableFormData: true,\n rows: withNewRow,\n value: siblingRows.length,\n },\n }\n\n return newState\n }\n\n case 'REPLACE_ROW': {\n const { blockType, path, rowIndex: rowIndexArg, subFieldState = {} } = action\n\n const { remainingFields, rows: siblingRows } = separateRows(path, state)\n const rowIndex = Math.max(0, Math.min(rowIndexArg, siblingRows?.length - 1 || 0))\n\n const rowsMetadata = [...(state[path]?.rows || [])]\n rowsMetadata[rowIndex] = {\n id: new ObjectId().toHexString(),\n blockType: blockType || undefined,\n collapsed: false,\n }\n\n if (blockType) {\n subFieldState.blockType = {\n initialValue: blockType,\n valid: true,\n value: blockType,\n }\n }\n\n // replace form _field state_\n siblingRows[rowIndex] = subFieldState\n\n const newState: FormState = {\n ...remainingFields,\n ...flattenRows(path, siblingRows),\n [path]: {\n ...state[path],\n disableFormData: true,\n rows: rowsMetadata,\n value: siblingRows.length,\n },\n }\n\n return newState\n }\n\n case 'DUPLICATE_ROW': {\n const { path, rowIndex } = action\n const { remainingFields, rows } = separateRows(path, state)\n const rowsMetadata = [...(state[path].rows || [])]\n\n const duplicateRowMetadata = deepCopyObject(rowsMetadata[rowIndex])\n if (duplicateRowMetadata.id) duplicateRowMetadata.id = new ObjectId().toHexString()\n\n const duplicateRowState = deepCopyObject(rows[rowIndex])\n if (duplicateRowState.id) duplicateRowState.id = new ObjectId().toHexString()\n\n // If there are subfields\n if (Object.keys(duplicateRowState).length > 0) {\n // Add new object containing subfield names to unflattenedRows array\n rows.splice(rowIndex + 1, 0, duplicateRowState)\n rowsMetadata.splice(rowIndex + 1, 0, duplicateRowMetadata)\n }\n\n const newState = {\n ...remainingFields,\n ...flattenRows(path, rows),\n [path]: {\n ...state[path],\n disableFormData: true,\n rows: rowsMetadata,\n value: rows.length,\n },\n }\n\n return newState\n }\n\n case 'MOVE_ROW': {\n const { moveFromIndex, moveToIndex, path } = action\n const { remainingFields, rows } = separateRows(path, state)\n\n // copy the row to move\n const copyOfMovingRow = rows[moveFromIndex]\n // delete the row by index\n rows.splice(moveFromIndex, 1)\n // insert row copyOfMovingRow back in\n rows.splice(moveToIndex, 0, copyOfMovingRow)\n\n // modify array/block internal row state (i.e. collapsed, blockType)\n const rowStateCopy = [...(state[path]?.rows || [])]\n const movingRowState = { ...rowStateCopy[moveFromIndex] }\n rowStateCopy.splice(moveFromIndex, 1)\n rowStateCopy.splice(moveToIndex, 0, movingRowState)\n\n const newState = {\n ...remainingFields,\n ...flattenRows(path, rows),\n [path]: {\n ...state[path],\n rows: rowStateCopy,\n },\n }\n\n return newState\n }\n\n case 'SET_ROW_COLLAPSED': {\n const { collapsed, path, rowID, setDocFieldPreferences } = action\n\n const arrayState = state[path]\n\n const { collapsedRowIDs, matchedIndex } = state[path].rows.reduce(\n (acc, row, index) => {\n const isMatchingRow = row.id === rowID\n if (isMatchingRow) acc.matchedIndex = index\n\n if (!isMatchingRow && row.collapsed) acc.collapsedRowIDs.push(row.id)\n else if (isMatchingRow && collapsed) acc.collapsedRowIDs.push(row.id)\n\n return acc\n },\n {\n collapsedRowIDs: [],\n matchedIndex: undefined,\n },\n )\n\n if (matchedIndex > -1) {\n arrayState.rows[matchedIndex].collapsed = collapsed\n setDocFieldPreferences(path, { collapsed: collapsedRowIDs })\n }\n\n const newState = {\n ...state,\n [path]: {\n ...arrayState,\n },\n }\n\n return newState\n }\n\n case 'SET_ALL_ROWS_COLLAPSED': {\n const { collapsed, path, setDocFieldPreferences } = action\n\n const { collapsedRowIDs, rows } = state[path].rows.reduce(\n (acc, row) => {\n if (collapsed) acc.collapsedRowIDs.push(row.id)\n\n acc.rows.push({\n ...row,\n collapsed,\n })\n\n return acc\n },\n {\n collapsedRowIDs: [],\n rows: [],\n },\n )\n\n setDocFieldPreferences(path, { collapsed: collapsedRowIDs })\n\n return {\n ...state,\n [path]: {\n ...state[path],\n rows,\n },\n }\n }\n\n default: {\n return state\n }\n }\n}\n"],"names":["ObjectIdImport","equal","deepCopyObject","flattenRows","separateRows","ObjectId","default","fieldReducer","state","action","type","optimize","newState","Object","entries","forEach","path","field","oldField","newField","errorPaths","errors","message","initialValue","value","errorMessage","valid","segments","split","length","push","fieldErrorPath","parentPath","slice","join","reduce","acc","fieldState","fieldErrorPaths","errorACC","startsWith","changed","newErrorPaths","Array","isArray","includes","key","rowIndex","remainingFields","rows","rowsMetadata","splice","disableFormData","blockType","rowIndexFromArgs","subFieldState","withNewRow","newRow","id","toHexString","undefined","collapsed","siblingRows","rowIndexArg","Math","max","min","duplicateRowMetadata","duplicateRowState","keys","moveFromIndex","moveToIndex","copyOfMovingRow","rowStateCopy","movingRowState","rowID","setDocFieldPreferences","arrayState","collapsedRowIDs","matchedIndex","row","index","isMatchingRow"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,oBAAoB,gBAAe;AAC1C,OAAOC,WAAW,aAAY;AAC9B,SAASC,cAAc,QAAQ,iBAAgB;AAI/C,SAASC,WAAW,EAAEC,YAAY,QAAQ,YAAW;AAErD,MAAMC,WAAYL,eAAeM,OAAO,IACtCN;AAEF;;CAEC,GACD,OAAO,SAASO,aAAaC,KAAgB,EAAEC,MAAmB;IAChE,OAAQA,OAAOC,IAAI;QACjB,KAAK;YAAiB;gBACpB,IAAID,OAAOE,QAAQ,KAAK,OAAO;oBAC7B,uCAAuC;oBACvC,+CAA+C;oBAC/C,KAAK;o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AAE;wBACN,GAAG6D,UAAU;oBACf;gBACF;gBAEA,OAAOjE;YACT;QAEA,KAAK;YAA0B;gBAC7B,MAAM,EAAEiD,SAAS,EAAE7C,IAAI,EAAE4D,sBAAsB,EAAE,GAAGnE;gBAEpD,MAAM,EAAEqE,eAAe,EAAE7B,IAAI,EAAE,GAAGzC,KAAK,CAACQ,KAAK,CAACiC,IAAI,CAACd,MAAM,CACvD,CAACC,KAAK4C;oBACJ,IAAInB,WAAWzB,IAAI0C,eAAe,CAAChD,IAAI,CAACkD,IAAItB,EAAE;oBAE9CtB,IAAIa,IAAI,CAACnB,IAAI,CAAC;wBACZ,GAAGkD,GAAG;wBACNnB;oBACF;oBAEA,OAAOzB;gBACT,GACA;oBACE0C,iBAAiB,EAAE;oBACnB7B,MAAM,EAAE;gBACV;gBAGF2B,uBAAuB5D,MAAM;oBAAE6C,WAAWiB;gBAAgB;gBAE1D,OAAO;oBACL,GAAGtE,KAAK;oBACR,CAACQ,KAAK,EAAE;wBACN,GAAGR,KAAK,CAACQ,KAAK;wBACdiC;oBACF;gBACF;YACF;QAEA;YAAS;gBACP,OAAOzC;YACT;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/Form/fieldReducer.ts"],"sourcesContent":["import type { FormField, FormState, Row } from 'payload'\n\nimport ObjectIdImport from 'bson-objectid'\nimport { dequal } from 'dequal/lite' // lite: no need for Map and Set support\nimport { deepCopyObject } from 'payload/shared'\n\nimport type { FieldAction } from './types.js'\n\nimport { flattenRows, separateRows } from './rows.js'\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\n/**\n * Reducer which modifies the form field state (all the current data of the fields in the form). When called using dispatch, it will return a new state object.\n */\nexport function fieldReducer(state: FormState, action: FieldAction): FormState {\n switch (action.type) {\n case 'REPLACE_STATE': {\n if (action.optimize !== false) {\n // Only update fields that have changed\n // by comparing old value / initialValue to new\n // ..\n // This is a performance enhancement for saving\n // large documents with hundreds of fields\n const newState = {}\n\n Object.entries(action.state).forEach(([path, field]) => {\n const oldField = state[path]\n const newField = field\n\n if (!dequal(oldField, newField)) {\n newState[path] = newField\n } else if (oldField) {\n newState[path] = oldField\n }\n })\n return newState\n }\n // If we're not optimizing, just set the state to the new state\n return action.state\n }\n\n case 'REMOVE': {\n const newState = { ...state }\n if (newState[action.path]) delete newState[action.path]\n return newState\n }\n\n case 'ADD_SERVER_ERRORS': {\n let newState = { ...state }\n\n const errorPaths: { fieldErrorPath: string; parentPath: string }[] = []\n\n action.errors.forEach(({ field, message }) => {\n newState[field] = {\n ...(newState[field] || {\n initialValue: null,\n value: null,\n }),\n errorMessage: message,\n valid: false,\n }\n\n const segments = field.split('.')\n if (segments.length > 1) {\n errorPaths.push({\n fieldErrorPath: field,\n parentPath: segments.slice(0, segments.length - 1).join('.'),\n })\n }\n })\n\n newState = Object.entries(newState).reduce((acc, [path, fieldState]) => {\n const fieldErrorPaths = errorPaths.reduce((errorACC, { fieldErrorPath, parentPath }) => {\n if (parentPath.startsWith(path)) {\n errorACC.push(fieldErrorPath)\n }\n return errorACC\n }, [])\n\n let changed = false\n\n if (fieldErrorPaths.length > 0) {\n const newErrorPaths = Array.isArray(fieldState.errorPaths) ? fieldState.errorPaths : []\n\n fieldErrorPaths.forEach((fieldErrorPath) => {\n if (!newErrorPaths.includes(fieldErrorPath)) {\n newErrorPaths.push(fieldErrorPath)\n changed = true\n }\n })\n\n if (changed) {\n acc[path] = {\n ...fieldState,\n errorPaths: newErrorPaths,\n }\n }\n }\n\n if (!changed) {\n acc[path] = fieldState\n }\n\n return acc\n }, {})\n\n return newState\n }\n\n case 'UPDATE': {\n const newField = Object.entries(action).reduce(\n (field, [key, value]) => {\n if (\n [\n 'disableFormData',\n 'errorMessage',\n 'initialValue',\n 'rows',\n 'valid',\n 'validate',\n 'value',\n ].includes(key)\n ) {\n return {\n ...field,\n [key]: value,\n }\n }\n\n return field\n },\n state[action.path] || ({} as FormField),\n )\n\n const newState = {\n ...state,\n [action.path]: newField,\n }\n\n return newState\n }\n\n case 'REMOVE_ROW': {\n const { path, rowIndex } = action\n const { remainingFields, rows } = separateRows(path, state)\n const rowsMetadata = [...(state[path]?.rows || [])]\n\n rows.splice(rowIndex, 1)\n rowsMetadata.splice(rowIndex, 1)\n\n const newState: FormState = {\n ...remainingFields,\n [path]: {\n ...state[path],\n disableFormData: rows.length > 0,\n rows: rowsMetadata,\n value: rows.length,\n },\n ...flattenRows(path, rows),\n }\n\n return newState\n }\n\n case 'ADD_ROW': {\n const { blockType, path, rowIndex: rowIndexFromArgs, subFieldState = {} } = action\n\n const rowIndex =\n typeof rowIndexFromArgs === 'number' ? rowIndexFromArgs : state[path]?.rows?.length || 0\n\n const withNewRow = [...(state[path]?.rows || [])]\n\n const newRow: Row = {\n id: (subFieldState?.id?.value as string) || new ObjectId().toHexString(),\n blockType: blockType || undefined,\n collapsed: false,\n }\n\n withNewRow.splice(rowIndex, 0, newRow)\n\n if (blockType) {\n subFieldState.blockType = {\n initialValue: blockType,\n valid: true,\n value: blockType,\n }\n }\n\n // add new row to array _field state_\n const { remainingFields, rows: siblingRows } = separateRows(path, state)\n siblingRows.splice(rowIndex, 0, subFieldState)\n\n const newState: FormState = {\n ...remainingFields,\n ...flattenRows(path, siblingRows),\n [path]: {\n ...state[path],\n disableFormData: true,\n rows: withNewRow,\n value: siblingRows.length,\n },\n }\n\n return newState\n }\n\n case 'REPLACE_ROW': {\n const { blockType, path, rowIndex: rowIndexArg, subFieldState = {} } = action\n\n const { remainingFields, rows: siblingRows } = separateRows(path, state)\n const rowIndex = Math.max(0, Math.min(rowIndexArg, siblingRows?.length - 1 || 0))\n\n const rowsMetadata = [...(state[path]?.rows || [])]\n rowsMetadata[rowIndex] = {\n id: new ObjectId().toHexString(),\n blockType: blockType || undefined,\n collapsed: false,\n }\n\n if (blockType) {\n subFieldState.blockType = {\n initialValue: blockType,\n valid: true,\n value: blockType,\n }\n }\n\n // replace form _field state_\n siblingRows[rowIndex] = subFieldState\n\n const newState: FormState = {\n ...remainingFields,\n ...flattenRows(path, siblingRows),\n [path]: {\n ...state[path],\n disableFormData: true,\n rows: rowsMetadata,\n value: siblingRows.length,\n },\n }\n\n return newState\n }\n\n case 'DUPLICATE_ROW': {\n const { path, rowIndex } = action\n const { remainingFields, rows } = separateRows(path, state)\n const rowsMetadata = [...(state[path].rows || [])]\n\n const duplicateRowMetadata = deepCopyObject(rowsMetadata[rowIndex])\n if (duplicateRowMetadata.id) duplicateRowMetadata.id = new ObjectId().toHexString()\n\n const duplicateRowState = deepCopyObject(rows[rowIndex])\n if (duplicateRowState.id) duplicateRowState.id = new ObjectId().toHexString()\n\n // If there are subfields\n if (Object.keys(duplicateRowState).length > 0) {\n // Add new object containing subfield names to unflattenedRows array\n rows.splice(rowIndex + 1, 0, duplicateRowState)\n rowsMetadata.splice(rowIndex + 1, 0, duplicateRowMetadata)\n }\n\n const newState = {\n ...remainingFields,\n ...flattenRows(path, rows),\n [path]: {\n ...state[path],\n disableFormData: true,\n rows: rowsMetadata,\n value: rows.length,\n },\n }\n\n return newState\n }\n\n case 'MOVE_ROW': {\n const { moveFromIndex, moveToIndex, path } = action\n const { remainingFields, rows } = separateRows(path, state)\n\n // copy the row to move\n const copyOfMovingRow = rows[moveFromIndex]\n // delete the row by index\n rows.splice(moveFromIndex, 1)\n // insert row copyOfMovingRow back in\n rows.splice(moveToIndex, 0, copyOfMovingRow)\n\n // modify array/block internal row state (i.e. collapsed, blockType)\n const rowStateCopy = [...(state[path]?.rows || [])]\n const movingRowState = { ...rowStateCopy[moveFromIndex] }\n rowStateCopy.splice(moveFromIndex, 1)\n rowStateCopy.splice(moveToIndex, 0, movingRowState)\n\n const newState = {\n ...remainingFields,\n ...flattenRows(path, rows),\n [path]: {\n ...state[path],\n rows: rowStateCopy,\n },\n }\n\n return newState\n }\n\n case 'SET_ROW_COLLAPSED': {\n const { collapsed, path, rowID, setDocFieldPreferences } = action\n\n const arrayState = state[path]\n\n const { collapsedRowIDs, matchedIndex } = state[path].rows.reduce(\n (acc, row, index) => {\n const isMatchingRow = row.id === rowID\n if (isMatchingRow) acc.matchedIndex = index\n\n if (!isMatchingRow && row.collapsed) acc.collapsedRowIDs.push(row.id)\n else if (isMatchingRow && collapsed) acc.collapsedRowIDs.push(row.id)\n\n return acc\n },\n {\n collapsedRowIDs: [],\n matchedIndex: undefined,\n },\n )\n\n if (matchedIndex > -1) {\n arrayState.rows[matchedIndex].collapsed = collapsed\n setDocFieldPreferences(path, { collapsed: collapsedRowIDs })\n }\n\n const newState = {\n ...state,\n [path]: {\n ...arrayState,\n },\n }\n\n return newState\n }\n\n case 'SET_ALL_ROWS_COLLAPSED': {\n const { collapsed, path, setDocFieldPreferences } = action\n\n const { collapsedRowIDs, rows } = state[path].rows.reduce(\n (acc, row) => {\n if (collapsed) acc.collapsedRowIDs.push(row.id)\n\n acc.rows.push({\n ...row,\n collapsed,\n })\n\n return acc\n },\n {\n collapsedRowIDs: [],\n rows: [],\n },\n )\n\n setDocFieldPreferences(path, { collapsed: collapsedRowIDs })\n\n return {\n ...state,\n [path]: {\n ...state[path],\n rows,\n },\n }\n }\n\n default: {\n return state\n }\n }\n}\n"],"names":["ObjectIdImport","dequal","deepCopyObject","flattenRows","separateRows","ObjectId","default","fieldReducer","state","action","type","optimize","newState","Object","entries","forEach","path","field","oldField","newField","errorPaths","errors","message","initialValue","value","errorMessage","valid","segments","split","length","push","fieldErrorPath","parentPath","slice","join","reduce","acc","fieldState","fieldErrorPaths","errorACC","startsWith","changed","newErrorPaths","Array","isArray","includes","key","rowIndex","remainingFields","rows","rowsMetadata","splice","disableFormData","blockType","rowIndexFromArgs","subFieldState","withNewRow","newRow","id","toHexString","undefined","collapsed","siblingRows","rowIndexArg","Math","max","min","duplicateRowMetadata","duplicateRowState","keys","moveFromIndex","moveToIndex","copyOfMovingRow","rowStateCopy","movingRowState","rowID","setDocFieldPreferences","arrayState","collapsedRowIDs","matchedIndex","row","index","isMatchingRow"],"mappings":"A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,IAAItB,EAAE;yBAC/D,IAAIwB,iBAAiBrB,WAAWzB,IAAI0C,eAAe,CAAChD,IAAI,CAACkD,IAAItB,EAAE;oBAEpE,OAAOtB;gBACT,GACA;oBACE0C,iBAAiB,EAAE;oBACnBC,cAAcnB;gBAChB;gBAGF,IAAImB,eAAe,CAAC,GAAG;oBACrBF,WAAW5B,IAAI,CAAC8B,aAAa,CAAClB,SAAS,GAAGA;oBAC1Ce,uBAAuB5D,MAAM;wBAAE6C,WAAWiB;oBAAgB;gBAC5D;gBAEA,MAAMlE,WAAW;oBACf,GAAGJ,KAAK;oBACR,CAACQ,KAAK,EAAE;wBACN,GAAG6D,UAAU;oBACf;gBACF;gBAEA,OAAOjE;YACT;QAEA,KAAK;YAA0B;gBAC7B,MAAM,EAAEiD,SAAS,EAAE7C,IAAI,EAAE4D,sBAAsB,EAAE,GAAGnE;gBAEpD,MAAM,EAAEqE,eAAe,EAAE7B,IAAI,EAAE,GAAGzC,KAAK,CAACQ,KAAK,CAACiC,IAAI,CAACd,MAAM,CACvD,CAACC,KAAK4C;oBACJ,IAAInB,WAAWzB,IAAI0C,eAAe,CAAChD,IAAI,CAACkD,IAAItB,EAAE;oBAE9CtB,IAAIa,IAAI,CAACnB,IAAI,CAAC;wBACZ,GAAGkD,GAAG;wBACNnB;oBACF;oBAEA,OAAOzB;gBACT,GACA;oBACE0C,iBAAiB,EAAE;oBACnB7B,MAAM,EAAE;gBACV;gBAGF2B,uBAAuB5D,MAAM;oBAAE6C,WAAWiB;gBAAgB;gBAE1D,OAAO;oBACL,GAAGtE,KAAK;oBACR,CAACQ,KAAK,EAAE;wBACN,GAAGR,KAAK,CAACQ,KAAK;wBACdiC;oBACF;gBACF;YACF;QAEA;YAAS;gBACP,OAAOzC;YACT;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDataByPath.d.ts","sourceRoot":"","sources":["../../../src/forms/Form/getDataByPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"getDataByPath.d.ts","sourceRoot":"","sources":["../../../src/forms/Form/getDataByPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,aAAa,GAAI,CAAC,oBAAoB,SAAS,QAAQ,MAAM,KAAG,CAkB5E,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/forms/Form/getDataByPath.ts"],"sourcesContent":["import type { FormState } from 'payload'\n\nimport { unflatten } from '../../utilities/unflatten.js'\n\nexport const getDataByPath = <T = unknown>(fields: FormState, path: string): T => {\n const pathPrefixToRemove = path.substring(0, path.lastIndexOf('.') + 1)\n const name = path.split('.').pop()\n\n const data = {}\n Object.keys(fields).forEach((key) => {\n if (!fields[key].disableFormData && (key.indexOf(`${path}.`) === 0 || key === path)) {\n data[key.replace(pathPrefixToRemove, '')] = fields[key].value\n\n if (fields[key]?.rows && fields[key].rows.length === 0) {\n data[key.replace(pathPrefixToRemove, '')] = []\n }\n }\n })\n\n const unflattenedData = unflatten(data)\n\n return unflattenedData?.[name]\n}\n"],"names":["unflatten","getDataByPath","fields","path","pathPrefixToRemove","substring","lastIndexOf","name","split","pop","data","Object","keys","forEach","key","disableFormData","indexOf","replace","value","rows","length","unflattenedData"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/Form/getDataByPath.ts"],"sourcesContent":["import type { FormState } from 'payload'\n\nimport { unflatten } from '../../utilities/unflatten.js'\n\nexport const getDataByPath = <T = unknown>(fields: FormState, path: string): T => {\n const pathPrefixToRemove = path.substring(0, path.lastIndexOf('.') + 1)\n const name = path.split('.').pop()\n\n const data = {}\n Object.keys(fields).forEach((key) => {\n if (!fields[key].disableFormData && (key.indexOf(`${path}.`) === 0 || key === path)) {\n data[key.replace(pathPrefixToRemove, '')] = fields[key].value\n\n if (fields[key]?.rows && fields[key].rows.length === 0) {\n data[key.replace(pathPrefixToRemove, '')] = []\n }\n }\n })\n\n const unflattenedData = unflatten(data)\n\n return unflattenedData?.[name]\n}\n"],"names":["unflatten","getDataByPath","fields","path","pathPrefixToRemove","substring","lastIndexOf","name","split","pop","data","Object","keys","forEach","key","disableFormData","indexOf","replace","value","rows","length","unflattenedData"],"mappings":"AAEA,SAASA,SAAS,QAAQ,+BAA8B;AAExD,OAAO,MAAMC,gBAAgB,CAAcC,QAAmBC;IAC5D,MAAMC,qBAAqBD,KAAKE,SAAS,CAAC,GAAGF,KAAKG,WAAW,CAAC,OAAO;IACrE,MAAMC,OAAOJ,KAAKK,KAAK,CAAC,KAAKC,GAAG;IAEhC,MAAMC,OAAO,CAAC;IACdC,OAAOC,IAAI,CAACV,QAAQW,OAAO,CAAC,CAACC;QAC3B,IAAI,CAACZ,MAAM,CAACY,IAAI,CAACC,eAAe,IAAKD,CAAAA,IAAIE,OAAO,CAAC,CAAC,EAAEb,KAAK,CAAC,CAAC,MAAM,KAAKW,QAAQX,IAAG,GAAI;YACnFO,IAAI,CAACI,IAAIG,OAAO,CAACb,oBAAoB,IAAI,GAAGF,MAAM,CAACY,IAAI,CAACI,KAAK;YAE7D,IAAIhB,MAAM,CAACY,IAAI,EAAEK,QAAQjB,MAAM,CAACY,IAAI,CAACK,IAAI,CAACC,MAAM,KAAK,GAAG;gBACtDV,IAAI,CAACI,IAAIG,OAAO,CAACb,oBAAoB,IAAI,GAAG,EAAE;YAChD;QACF;IACF;IAEA,MAAMiB,kBAAkBrB,UAAUU;IAElC,OAAOW,iBAAiB,CAACd,KAAK;AAChC,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/forms/Form/getSiblingData.ts"],"sourcesContent":["import type { Data, FormState } from 'payload'\n\nimport { reduceFieldsToValues } from '../../utilities/reduceFieldsToValues.js'\nimport { unflatten } from '../../utilities/unflatten.js'\n\nexport const getSiblingData = (fields: FormState, path: string): Data => {\n if (!fields) return null\n\n if (path.indexOf('.') === -1) {\n return reduceFieldsToValues(fields, true)\n }\n\n const siblingFields = {}\n\n // Determine if the last segment of the path is an array-based row\n const pathSegments = path.split('.')\n const lastSegment = pathSegments[pathSegments.length - 1]\n const lastSegmentIsRowIndex = !Number.isNaN(Number(lastSegment))\n\n let parentFieldPath: string\n\n if (lastSegmentIsRowIndex) {\n // If the last segment is a row index,\n // the sibling data is that row's contents\n // so create a parent field path that will\n // retrieve all contents of that row index only\n parentFieldPath = `${path}.`\n } else {\n // Otherwise, the last path segment is a field name\n // and it should be removed\n parentFieldPath = path.substring(0, path.lastIndexOf('.') + 1)\n }\n\n Object.keys(fields).forEach((fieldKey) => {\n if (!fields[fieldKey].disableFormData && fieldKey.indexOf(parentFieldPath) === 0) {\n siblingFields[fieldKey.replace(parentFieldPath, '')] = fields[fieldKey].value\n }\n })\n\n return unflatten(siblingFields)\n}\n"],"names":["reduceFieldsToValues","unflatten","getSiblingData","fields","path","indexOf","siblingFields","pathSegments","split","lastSegment","length","lastSegmentIsRowIndex","Number","isNaN","parentFieldPath","substring","lastIndexOf","Object","keys","forEach","fieldKey","disableFormData","replace","value"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/Form/getSiblingData.ts"],"sourcesContent":["import type { Data, FormState } from 'payload'\n\nimport { reduceFieldsToValues } from '../../utilities/reduceFieldsToValues.js'\nimport { unflatten } from '../../utilities/unflatten.js'\n\nexport const getSiblingData = (fields: FormState, path: string): Data => {\n if (!fields) return null\n\n if (path.indexOf('.') === -1) {\n return reduceFieldsToValues(fields, true)\n }\n\n const siblingFields = {}\n\n // Determine if the last segment of the path is an array-based row\n const pathSegments = path.split('.')\n const lastSegment = pathSegments[pathSegments.length - 1]\n const lastSegmentIsRowIndex = !Number.isNaN(Number(lastSegment))\n\n let parentFieldPath: string\n\n if (lastSegmentIsRowIndex) {\n // If the last segment is a row index,\n // the sibling data is that row's contents\n // so create a parent field path that will\n // retrieve all contents of that row index only\n parentFieldPath = `${path}.`\n } else {\n // Otherwise, the last path segment is a field name\n // and it should be removed\n parentFieldPath = path.substring(0, path.lastIndexOf('.') + 1)\n }\n\n Object.keys(fields).forEach((fieldKey) => {\n if (!fields[fieldKey].disableFormData && fieldKey.indexOf(parentFieldPath) === 0) {\n siblingFields[fieldKey.replace(parentFieldPath, '')] = fields[fieldKey].value\n }\n })\n\n return unflatten(siblingFields)\n}\n"],"names":["reduceFieldsToValues","unflatten","getSiblingData","fields","path","indexOf","siblingFields","pathSegments","split","lastSegment","length","lastSegmentIsRowIndex","Number","isNaN","parentFieldPath","substring","lastIndexOf","Object","keys","forEach","fieldKey","disableFormData","replace","value"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,0CAAyC;AAC9E,SAASC,SAAS,QAAQ,+BAA8B;AAExD,OAAO,MAAMC,iBAAiB,CAACC,QAAmBC;IAChD,IAAI,CAACD,QAAQ,OAAO;IAEpB,IAAIC,KAAKC,OAAO,CAAC,SAAS,CAAC,GAAG;QAC5B,OAAOL,qBAAqBG,QAAQ;IACtC;IAEA,MAAMG,gBAAgB,CAAC;IAEvB,kEAAkE;IAClE,MAAMC,eAAeH,KAAKI,KAAK,CAAC;IAChC,MAAMC,cAAcF,YAAY,CAACA,aAAaG,MAAM,GAAG,EAAE;IACzD,MAAMC,wBAAwB,CAACC,OAAOC,KAAK,CAACD,OAAOH;IAEnD,IAAIK;IAEJ,IAAIH,uBAAuB;QACzB,sCAAsC;QACtC,0CAA0C;QAC1C,0CAA0C;QAC1C,+CAA+C;QAC/CG,kBAAkB,CAAC,EAAEV,KAAK,CAAC,CAAC;IAC9B,OAAO;QACL,mDAAmD;QACnD,2BAA2B;QAC3BU,kBAAkBV,KAAKW,SAAS,CAAC,GAAGX,KAAKY,WAAW,CAAC,OAAO;IAC9D;IAEAC,OAAOC,IAAI,CAACf,QAAQgB,OAAO,CAAC,CAACC;QAC3B,IAAI,CAACjB,MAAM,CAACiB,SAAS,CAACC,eAAe,IAAID,SAASf,OAAO,CAACS,qBAAqB,GAAG;YAChFR,aAAa,CAACc,SAASE,OAAO,CAACR,iBAAiB,IAAI,GAAGX,MAAM,CAACiB,SAAS,CAACG,KAAK;QAC/E;IACF;IAEA,OAAOtB,UAAUK;AACnB,EAAC"}
|
package/dist/forms/Form/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ import
|
|
3
|
+
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ import { dequal } from 'dequal/lite'; // lite: no need for Map and Set support
|
|
4
4
|
import { useRouter } from 'next/navigation.js';
|
|
5
5
|
import { serialize } from 'object-to-formdata';
|
|
6
6
|
import { wait } from 'payload/shared';
|
|
7
|
-
import
|
|
7
|
+
import qs from 'qs';
|
|
8
8
|
import React, { useCallback, useEffect, useReducer, useRef, useState } from 'react';
|
|
9
9
|
import { toast } from 'sonner';
|
|
10
10
|
import { useDebouncedEffect } from '../../hooks/useDebouncedEffect.js';
|
|
@@ -92,7 +92,7 @@ export const Form = (props)=>{
|
|
|
92
92
|
validatedFieldState[path] = validatedField;
|
|
93
93
|
});
|
|
94
94
|
await Promise.all(validationPromises);
|
|
95
|
-
if (!
|
|
95
|
+
if (!dequal(contextRef.current.fields, validatedFieldState)) {
|
|
96
96
|
dispatchFields({
|
|
97
97
|
type: 'REPLACE_STATE',
|
|
98
98
|
state: validatedFieldState
|
|
@@ -194,7 +194,7 @@ export const Form = (props)=>{
|
|
|
194
194
|
const formData = contextRef.current.createFormData(overrides);
|
|
195
195
|
try {
|
|
196
196
|
let res;
|
|
197
|
-
const actionEndpoint = actionArg || (typeof action === 'string' ? `${action}${
|
|
197
|
+
const actionEndpoint = actionArg || (typeof action === 'string' ? `${action}${qs.stringify(formQueryParams, {
|
|
198
198
|
addQueryPrefix: true
|
|
199
199
|
})}` : null);
|
|
200
200
|
if (actionEndpoint) {
|
|
@@ -537,7 +537,7 @@ export const Form = (props)=>{
|
|
|
537
537
|
onChange,
|
|
538
538
|
modified
|
|
539
539
|
]);
|
|
540
|
-
const actionString = typeof action === 'string' ? `${action}${
|
|
540
|
+
const actionString = typeof action === 'string' ? `${action}${qs.stringify(formQueryParams, {
|
|
541
541
|
addQueryPrefix: true
|
|
542
542
|
})}` : '';
|
|
543
543
|
return /*#__PURE__*/ _jsx("form", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/forms/Form/index.tsx"],"sourcesContent":["'use client'\nimport type { FormState } from 'payload'\n\n/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */\nimport isDeepEqual from 'deep-equal'\nimport { useRouter } from 'next/navigation.js'\nimport { serialize } from 'object-to-formdata'\nimport { wait } from 'payload/shared'\nimport QueryString from 'qs'\nimport React, { useCallback, useEffect, useReducer, useRef, useState } from 'react'\nimport { toast } from 'sonner'\n\nimport type {\n Context as FormContextType,\n FormProps,\n GetDataByPath,\n SubmitOptions,\n} from './types.js'\n\nimport { useDebouncedEffect } from '../../hooks/useDebouncedEffect.js'\nimport { useThrottledEffect } from '../../hooks/useThrottledEffect.js'\nimport { useAuth } from '../../providers/Auth/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useFormQueryParams } from '../../providers/FormQueryParams/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useOperation } from '../../providers/Operation/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { requests } from '../../utilities/api.js'\nimport { getFormState } from '../../utilities/getFormState.js'\nimport { reduceFieldsToValues } from '../../utilities/reduceFieldsToValues.js'\nimport {\n FormContext,\n FormFieldsContext,\n FormWatchContext,\n InitializingContext,\n ModifiedContext,\n ProcessingContext,\n SubmittedContext,\n} from './context.js'\nimport { errorMessages } from './errorMessages.js'\nimport { fieldReducer } from './fieldReducer.js'\nimport { getDataByPath as getDataByPathFunc } from './getDataByPath.js'\nimport { getSiblingData as getSiblingDataFunc } from './getSiblingData.js'\nimport { initContextState } from './initContextState.js'\nimport { mergeServerFormState } from './mergeServerFormState.js'\n\nconst baseClass = 'form'\n\nexport const Form: React.FC<FormProps> = (props) => {\n const { id, collectionSlug, globalSlug } = useDocumentInfo()\n\n const {\n action,\n beforeSubmit,\n children,\n className,\n disableSuccessStatus,\n disableValidationOnSubmit,\n disabled: disabledFromProps,\n // fields: fieldsFromProps = collection?.fields || global?.fields,\n handleResponse,\n initialState, // fully formed initial field state\n isInitializing: initializingFromProps,\n onChange,\n onSubmit,\n onSuccess,\n redirect,\n submitted: submittedFromProps,\n uuid,\n waitForAutocomplete,\n } = props\n\n const method = 'method' in props ? props?.method : undefined\n\n const router = useRouter()\n\n const { code: locale } = useLocale()\n const { i18n, t } = useTranslation()\n const { refreshCookie, user } = useAuth()\n const operation = useOperation()\n const { formQueryParams } = useFormQueryParams()\n\n const config = useConfig()\n const {\n routes: { api: apiRoute },\n serverURL,\n } = config\n\n const [disabled, setDisabled] = useState(disabledFromProps || false)\n const [isMounted, setIsMounted] = useState(false)\n const [modified, setModified] = useState(false)\n const [initializing, setInitializing] = useState(initializingFromProps)\n const [processing, setProcessing] = useState(false)\n const [submitted, setSubmitted] = useState(false)\n const formRef = useRef<HTMLFormElement>(null)\n const contextRef = useRef({} as FormContextType)\n\n const fieldsReducer = useReducer(fieldReducer, {}, () => initialState)\n\n /**\n * `fields` is the current, up-to-date state/data of all fields in the form. It can be modified by using dispatchFields,\n * which calls the fieldReducer, which then updates the state.\n */\n const [fields, dispatchFields] = fieldsReducer\n\n contextRef.current.fields = fields\n\n const validateForm = useCallback(async () => {\n const validatedFieldState = {}\n let isValid = true\n\n const dataFromContext = contextRef.current.getData()\n const data = dataFromContext\n\n const validationPromises = Object.entries(contextRef.current.fields).map(\n async ([path, field]) => {\n const validatedField = field\n\n if (field.passesCondition !== false) {\n let validationResult: boolean | string = validatedField.valid\n\n if (typeof field.validate === 'function') {\n let valueToValidate = field.value\n\n if (field?.rows && Array.isArray(field.rows)) {\n valueToValidate = contextRef.current.getDataByPath(path)\n }\n\n validationResult = await field.validate(valueToValidate, {\n id,\n config,\n data,\n operation,\n siblingData: contextRef.current.getSiblingData(path),\n t,\n user,\n })\n\n if (typeof validationResult === 'string') {\n validatedField.errorMessage = validationResult\n validatedField.valid = false\n } else {\n validatedField.valid = true\n validatedField.errorMessage = undefined\n }\n }\n\n if (validatedField.valid === false) {\n isValid = false\n }\n }\n\n validatedFieldState[path] = validatedField\n },\n )\n\n await Promise.all(validationPromises)\n\n if (!isDeepEqual(contextRef.current.fields, validatedFieldState)) {\n dispatchFields({ type: 'REPLACE_STATE', state: validatedFieldState })\n }\n\n return isValid\n }, [id, user, operation, t, dispatchFields, config])\n\n const submit = useCallback(\n async (options: SubmitOptions = {}, e): Promise<void> => {\n const {\n action: actionArg,\n method: methodToUse = method,\n overrides = {},\n skipValidation,\n } = options\n\n if (disabled) {\n if (e) {\n e.preventDefault()\n }\n return\n }\n\n // create new toast promise which will resolve manually later\n let successToast, errorToast\n const promise = new Promise((resolve, reject) => {\n successToast = resolve\n errorToast = reject\n })\n\n const hasFormSubmitAction =\n actionArg || typeof action === 'string' || typeof action === 'function'\n\n if (redirect || disableSuccessStatus || !hasFormSubmitAction) {\n // Do not show submitting toast, as the promise toast may never disappear under these conditions.\n // Instead, make successToast() or errorToast() throw toast.success / toast.error\n successToast = (data) => toast.success(data)\n errorToast = (data) => toast.error(data)\n } else {\n toast.promise(promise, {\n error: (data) => {\n return data as string\n },\n loading: t('general:submitting'),\n success: (data) => {\n return data as string\n },\n })\n }\n\n if (e) {\n e.stopPropagation()\n e.preventDefault()\n }\n\n setProcessing(true)\n setDisabled(true)\n\n if (waitForAutocomplete) await wait(100)\n\n // Execute server side validations\n if (Array.isArray(beforeSubmit)) {\n let revalidatedFormState: FormState\n\n await beforeSubmit.reduce(async (priorOnChange, beforeSubmitFn) => {\n await priorOnChange\n\n const result = await beforeSubmitFn({\n formState: fields,\n })\n\n revalidatedFormState = result\n }, Promise.resolve())\n\n const isValid = Object.entries(revalidatedFormState).every(([, field]) => field.valid)\n\n if (!isValid) {\n setProcessing(false)\n setSubmitted(true)\n setDisabled(false)\n return dispatchFields({ type: 'REPLACE_STATE', state: revalidatedFormState })\n }\n }\n\n const isValid =\n skipValidation || disableValidationOnSubmit ? true : await contextRef.current.validateForm()\n\n // If not valid, prevent submission\n if (!isValid) {\n errorToast(t('error:correctInvalidFields'))\n setProcessing(false)\n setSubmitted(true)\n setDisabled(false)\n return\n }\n\n // If submit handler comes through via props, run that\n if (onSubmit) {\n const data = {\n ...reduceFieldsToValues(fields, true),\n ...overrides,\n }\n\n onSubmit(fields, data)\n }\n\n if (!hasFormSubmitAction) {\n // No action provided, so we should return. An example where this happens are lexical link drawers. Upon submitting the drawer, we\n // want to close it without submitting the form. Stuff like validation would be handled by lexical before this, through beforeSubmit\n setProcessing(false)\n setSubmitted(true)\n setDisabled(false)\n return\n }\n\n const formData = contextRef.current.createFormData(overrides)\n\n try {\n let res\n const actionEndpoint =\n actionArg ||\n (typeof action === 'string'\n ? `${action}${QueryString.stringify(formQueryParams, { addQueryPrefix: true })}`\n : null)\n\n if (actionEndpoint) {\n res = await requests[methodToUse.toLowerCase()](actionEndpoint, {\n body: formData,\n headers: {\n 'Accept-Language': i18n.language,\n },\n })\n } else if (typeof action === 'function') {\n res = await action(formData)\n }\n\n setModified(false)\n setDisabled(false)\n\n if (typeof handleResponse === 'function') {\n handleResponse(res, successToast, errorToast)\n return\n }\n\n const contentType = res.headers.get('content-type')\n const isJSON = contentType && contentType.indexOf('application/json') !== -1\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let json: Record<string, any> = {}\n\n if (isJSON) json = await res.json()\n if (res.status < 400) {\n if (typeof onSuccess === 'function') await onSuccess(json)\n setSubmitted(false)\n setProcessing(false)\n\n if (redirect) {\n router.push(redirect)\n } else if (!disableSuccessStatus) {\n successToast(json.message || t('general:submissionSuccessful'))\n }\n } else {\n setProcessing(false)\n setSubmitted(true)\n\n contextRef.current = { ...contextRef.current } // triggers rerender of all components that subscribe to form\n if (json.message) {\n errorToast(json.message)\n\n return\n }\n\n if (Array.isArray(json.errors)) {\n const [fieldErrors, nonFieldErrors] = json.errors.reduce(\n ([fieldErrs, nonFieldErrs], err) => {\n const newFieldErrs = []\n const newNonFieldErrs = []\n\n if (err?.message) {\n newNonFieldErrs.push(err)\n }\n\n if (Array.isArray(err?.data)) {\n err.data.forEach((dataError) => {\n if (dataError?.field) {\n newFieldErrs.push(dataError)\n } else {\n newNonFieldErrs.push(dataError)\n }\n })\n }\n\n return [\n [...fieldErrs, ...newFieldErrs],\n [...nonFieldErrs, ...newNonFieldErrs],\n ]\n },\n [[], []],\n )\n\n dispatchFields({\n type: 'ADD_SERVER_ERRORS',\n errors: fieldErrors,\n })\n\n nonFieldErrors.forEach((err) => {\n errorToast(err.message || t('error:unknown'))\n })\n\n return\n }\n\n const message = errorMessages?.[res.status] || res?.statusText || t('error:unknown')\n\n errorToast(message)\n }\n } catch (err) {\n console.error('Error submitting form', err)\n setProcessing(false)\n setSubmitted(true)\n setDisabled(false)\n\n errorToast(err.message)\n }\n },\n [\n beforeSubmit,\n action,\n disableSuccessStatus,\n disableValidationOnSubmit,\n disabled,\n dispatchFields,\n fields,\n handleResponse,\n method,\n onSubmit,\n onSuccess,\n redirect,\n router,\n t,\n i18n,\n waitForAutocomplete,\n formQueryParams,\n ],\n )\n\n const getFields = useCallback(() => contextRef.current.fields, [])\n\n const getField = useCallback((path: string) => contextRef.current.fields[path], [])\n\n const getData = useCallback(() => reduceFieldsToValues(contextRef.current.fields, true), [])\n\n const getSiblingData = useCallback(\n (path: string) => getSiblingDataFunc(contextRef.current.fields, path),\n [],\n )\n const getDataByPath = useCallback<GetDataByPath>(\n (path: string) => getDataByPathFunc(contextRef.current.fields, path),\n [],\n )\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const createFormData = useCallback((overrides: any = {}) => {\n const data = reduceFieldsToValues(contextRef.current.fields, true)\n\n const file = data?.file\n\n if (file) {\n delete data.file\n }\n\n const dataWithOverrides = {\n ...data,\n ...overrides,\n }\n\n const dataToSerialize = {\n _payload: JSON.stringify(dataWithOverrides),\n file,\n }\n\n // nullAsUndefineds is important to allow uploads and relationship fields to clear themselves\n const formData = serialize(dataToSerialize, { indices: true, nullsAsUndefineds: false })\n\n return formData\n }, [])\n\n const reset = useCallback(\n async (data: unknown) => {\n const newState = await getFormState({\n apiRoute,\n body: {\n id,\n collectionSlug,\n data,\n globalSlug,\n operation,\n schemaPath: collectionSlug || globalSlug,\n },\n serverURL,\n })\n\n contextRef.current = { ...initContextState } as FormContextType\n setModified(false)\n dispatchFields({ type: 'REPLACE_STATE', state: newState })\n },\n [apiRoute, collectionSlug, dispatchFields, globalSlug, id, operation, serverURL],\n )\n\n const replaceState = useCallback(\n (state: FormState) => {\n contextRef.current = { ...initContextState } as FormContextType\n setModified(false)\n dispatchFields({ type: 'REPLACE_STATE', state })\n },\n [dispatchFields],\n )\n\n const getFieldStateBySchemaPath = useCallback(\n async ({ data, schemaPath }) => {\n const fieldSchema = await getFormState({\n apiRoute,\n body: {\n collectionSlug,\n data,\n globalSlug,\n schemaPath,\n },\n serverURL,\n })\n return fieldSchema\n },\n [apiRoute, collectionSlug, globalSlug, serverURL],\n )\n\n const addFieldRow: FormContextType['addFieldRow'] = useCallback(\n async ({ data, path, rowIndex, schemaPath }) => {\n const subFieldState = await getFieldStateBySchemaPath({ data, schemaPath })\n\n dispatchFields({\n type: 'ADD_ROW',\n blockType: data?.blockType,\n path,\n rowIndex,\n subFieldState,\n })\n },\n [getFieldStateBySchemaPath, dispatchFields],\n )\n\n const removeFieldRow: FormContextType['removeFieldRow'] = useCallback(\n ({ path, rowIndex }) => {\n dispatchFields({ type: 'REMOVE_ROW', path, rowIndex })\n },\n [dispatchFields],\n )\n\n const replaceFieldRow: FormContextType['replaceFieldRow'] = useCallback(\n async ({ data, path, rowIndex, schemaPath }) => {\n const subFieldState = await getFieldStateBySchemaPath({ data, schemaPath })\n\n dispatchFields({\n type: 'REPLACE_ROW',\n blockType: data?.blockType,\n path,\n rowIndex,\n subFieldState,\n })\n },\n [getFieldStateBySchemaPath, dispatchFields],\n )\n\n useEffect(() => {\n if (initializingFromProps !== undefined) {\n setInitializing(initializingFromProps)\n }\n }, [initializingFromProps])\n\n contextRef.current.submit = submit\n contextRef.current.getFields = getFields\n contextRef.current.getField = getField\n contextRef.current.getData = getData\n contextRef.current.getSiblingData = getSiblingData\n contextRef.current.getDataByPath = getDataByPath\n contextRef.current.validateForm = validateForm\n contextRef.current.createFormData = createFormData\n contextRef.current.setModified = setModified\n contextRef.current.setProcessing = setProcessing\n contextRef.current.setSubmitted = setSubmitted\n contextRef.current.disabled = disabled\n contextRef.current.setDisabled = setDisabled\n contextRef.current.formRef = formRef\n contextRef.current.reset = reset\n contextRef.current.replaceState = replaceState\n contextRef.current.dispatchFields = dispatchFields\n contextRef.current.addFieldRow = addFieldRow\n contextRef.current.removeFieldRow = removeFieldRow\n contextRef.current.replaceFieldRow = replaceFieldRow\n contextRef.current.uuid = uuid\n contextRef.current.initializing = initializing\n\n useEffect(() => {\n setIsMounted(true)\n }, [])\n\n useEffect(() => {\n if (typeof disabledFromProps === 'boolean') setDisabled(disabledFromProps)\n }, [disabledFromProps])\n\n useEffect(() => {\n if (typeof submittedFromProps === 'boolean') setSubmitted(submittedFromProps)\n }, [submittedFromProps])\n\n useEffect(() => {\n if (initialState) {\n contextRef.current = { ...initContextState } as FormContextType\n dispatchFields({ type: 'REPLACE_STATE', optimize: false, state: initialState })\n }\n }, [initialState, dispatchFields])\n\n useThrottledEffect(\n () => {\n refreshCookie()\n },\n 15000,\n [fields],\n )\n\n useEffect(() => {\n contextRef.current = { ...contextRef.current } // triggers rerender of all components that subscribe to form\n setModified(false)\n }, [locale])\n\n const classes = [className, baseClass].filter(Boolean).join(' ')\n\n useDebouncedEffect(\n () => {\n const executeOnChange = async () => {\n if (Array.isArray(onChange)) {\n let revalidatedFormState: FormState = contextRef.current.fields\n\n for (const onChangeFn of onChange) {\n revalidatedFormState = await onChangeFn({\n formState: revalidatedFormState,\n })\n }\n\n const { changed, newState } = mergeServerFormState(\n contextRef.current.fields || {},\n revalidatedFormState,\n )\n\n if (changed) {\n dispatchFields({\n type: 'REPLACE_STATE',\n optimize: false,\n state: newState,\n })\n }\n }\n }\n\n if (modified) void executeOnChange()\n },\n 150,\n // Make sure we trigger this whenever modified changes (not just when `fields` changes), otherwise we will miss merging server form state for the first form update/onChange. Here's why:\n // `fields` updates before `modified`, because setModified is in a setTimeout. So on the first change, modified is false, so we don't trigger the effect even though we should.\n [contextRef.current.fields, dispatchFields, onChange, modified],\n )\n\n const actionString =\n typeof action === 'string'\n ? `${action}${QueryString.stringify(formQueryParams, { addQueryPrefix: true })}`\n : ''\n\n return (\n <form\n action={method ? actionString : (action as string)}\n className={classes}\n method={method}\n noValidate\n onSubmit={(e) => contextRef.current.submit({}, e)}\n ref={formRef}\n >\n <FormContext.Provider value={contextRef.current}>\n <FormWatchContext.Provider\n value={{\n fields,\n ...contextRef.current,\n }}\n >\n <SubmittedContext.Provider value={submitted}>\n <InitializingContext.Provider value={!isMounted || (isMounted && initializing)}>\n <ProcessingContext.Provider value={processing}>\n <ModifiedContext.Provider value={modified}>\n <FormFieldsContext.Provider value={fieldsReducer}>\n {children}\n </FormFieldsContext.Provider>\n </ModifiedContext.Provider>\n </ProcessingContext.Provider>\n </InitializingContext.Provider>\n </SubmittedContext.Provider>\n </FormWatchContext.Provider>\n </FormContext.Provider>\n </form>\n )\n}\n\nexport {\n FormContext,\n FormFieldsContext,\n FormWatchContext,\n ModifiedContext,\n ProcessingContext,\n SubmittedContext,\n useAllFormFields,\n useForm,\n useFormFields,\n useFormModified,\n useFormProcessing,\n useFormSubmitted,\n useWatchForm,\n} from './context.js'\n\nexport { FormProps }\n"],"names":["isDeepEqual","useRouter","serialize","wait","QueryString","React","useCallback","useEffect","useReducer","useRef","useState","toast","useDebouncedEffect","useThrottledEffect","useAuth","useConfig","useDocumentInfo","useFormQueryParams","useLocale","useOperation","useTranslation","requests","getFormState","reduceFieldsToValues","FormContext","FormFieldsContext","FormWatchContext","InitializingContext","ModifiedContext","ProcessingContext","SubmittedContext","errorMessages","fieldReducer","getDataByPath","getDataByPathFunc","getSiblingData","getSiblingDataFunc","initContextState","mergeServerFormState","baseClass","Form","props","id","collectionSlug","globalSlug","action","beforeSubmit","children","className","disableSuccessStatus","disableValidationOnSubmit","disabled","disabledFromProps","handleResponse","initialState","isInitializing","initializingFromProps","onChange","onSubmit","onSuccess","redirect","submitted","submittedFromProps","uuid","waitForAutocomplete","method","undefined","router","code","locale","i18n","t","refreshCookie","user","operation","formQueryParams","config","routes","api","apiRoute","serverURL","setDisabled","isMounted","setIsMounted","modified","setModified","initializing","setInitializing","processing","setProcessing","setSubmitted","formRef","contextRef","fieldsReducer","fields","dispatchFields","current","validateForm","validatedFieldState","isValid","dataFromContext","getData","data","validationPromises","Object","entries","map","path","field","validatedField","passesCondition","validationResult","valid","validate","valueToValidate","value","rows","Array","isArray","siblingData","errorMessage","Promise","all","type","state","submit","options","e","actionArg","methodToUse","overrides","skipValidation","preventDefault","successToast","errorToast","promise","resolve","reject","hasFormSubmitAction","success","error","loading","stopPropagation","revalidatedFormState","reduce","priorOnChange","beforeSubmitFn","result","formState","every","formData","createFormData","res","actionEndpoint","stringify","addQueryPrefix","toLowerCase","body","headers","language","contentType","get","isJSON","indexOf","json","status","push","message","errors","fieldErrors","nonFieldErrors","fieldErrs","nonFieldErrs","err","newFieldErrs","newNonFieldErrs","forEach","dataError","statusText","console","getFields","getField","file","dataWithOverrides","dataToSerialize","_payload","JSON","indices","nullsAsUndefineds","reset","newState","schemaPath","replaceState","getFieldStateBySchemaPath","fieldSchema","addFieldRow","rowIndex","subFieldState","blockType","removeFieldRow","replaceFieldRow","optimize","classes","filter","Boolean","join","executeOnChange","onChangeFn","changed","actionString","form","noValidate","ref","Provider","useAllFormFields","useForm","useFormFields","useFormModified","useFormProcessing","useFormSubmitted","useWatchForm"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAGA,kEAAkE,GAClE,OAAOA,iBAAiB,aAAY;AACpC,SAASC,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,IAAI,QAAQ,iBAAgB;AACrC,OAAOC,iBAAiB,KAAI;AAC5B,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AACnF,SAASC,KAAK,QAAQ,SAAQ;AAS9B,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,OAAO,QAAQ,gCAA+B;AAC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O,EAAEzC,YAAYsJ,SAAS,CAAC/E,iBAAiB;QAAEgF,gBAAgB;IAAK,GAAG,CAAC,GAC9E;IAEN,qBACE,KAACuD;QACCrK,QAAQoB,SAASgJ,eAAgBpK;QACjCG,WAAW0J;QACXzI,QAAQA;QACRkJ,UAAU;QACVzJ,UAAU,CAACqE,IAAMnC,WAAWI,OAAO,CAAC6B,MAAM,CAAC,CAAC,GAAGE;QAC/CqF,KAAKzH;kBAEL,cAAA,KAACnE,YAAY6L,QAAQ;YAAClG,OAAOvB,WAAWI,OAAO;sBAC7C,cAAA,KAACtE,iBAAiB2L,QAAQ;gBACxBlG,OAAO;oBACLrB;oBACA,GAAGF,WAAWI,OAAO;gBACvB;0BAEA,cAAA,KAAClE,iBAAiBuL,QAAQ;oBAAClG,OAAOtD;8BAChC,cAAA,KAAClC,oBAAoB0L,QAAQ;wBAAClG,OAAO,CAACjC,aAAcA,aAAaI;kCAC/D,cAAA,KAACzD,kBAAkBwL,QAAQ;4BAAClG,OAAO3B;sCACjC,cAAA,KAAC5D,gBAAgByL,QAAQ;gCAAClG,OAAO/B;0CAC/B,cAAA,KAAC3D,kBAAkB4L,QAAQ;oCAAClG,OAAOtB;8CAChC9C;;;;;;;;;AAUrB,EAAC;AAED,SACEvB,WAAW,EACXC,iBAAiB,EACjBC,gBAAgB,EAChBE,eAAe,EACfC,iBAAiB,EACjBC,gBAAgB,EAChBwL,gBAAgB,EAChBC,OAAO,EACPC,aAAa,EACbC,eAAe,EACfC,iBAAiB,EACjBC,gBAAgB,EAChBC,YAAY,QACP,eAAc"}
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/Form/index.tsx"],"sourcesContent":["'use client'\nimport type { FormState } from 'payload'\n\n/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */\nimport { dequal } from 'dequal/lite' // lite: no need for Map and Set support\nimport { useRouter } from 'next/navigation.js'\nimport { serialize } from 'object-to-formdata'\nimport { wait } from 'payload/shared'\nimport qs from 'qs'\nimport React, { useCallback, useEffect, useReducer, useRef, useState } from 'react'\nimport { toast } from 'sonner'\n\nimport type {\n Context as FormContextType,\n FormProps,\n GetDataByPath,\n SubmitOptions,\n} from './types.js'\n\nimport { useDebouncedEffect } from '../../hooks/useDebouncedEffect.js'\nimport { useThrottledEffect } from '../../hooks/useThrottledEffect.js'\nimport { useAuth } from '../../providers/Auth/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useFormQueryParams } from '../../providers/FormQueryParams/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useOperation } from '../../providers/Operation/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { requests } from '../../utilities/api.js'\nimport { getFormState } from '../../utilities/getFormState.js'\nimport { reduceFieldsToValues } from '../../utilities/reduceFieldsToValues.js'\nimport {\n FormContext,\n FormFieldsContext,\n FormWatchContext,\n InitializingContext,\n ModifiedContext,\n ProcessingContext,\n SubmittedContext,\n} from './context.js'\nimport { errorMessages } from './errorMessages.js'\nimport { fieldReducer } from './fieldReducer.js'\nimport { getDataByPath as getDataByPathFunc } from './getDataByPath.js'\nimport { getSiblingData as getSiblingDataFunc } from './getSiblingData.js'\nimport { initContextState } from './initContextState.js'\nimport { mergeServerFormState } from './mergeServerFormState.js'\n\nconst baseClass = 'form'\n\nexport const Form: React.FC<FormProps> = (props) => {\n const { id, collectionSlug, globalSlug } = useDocumentInfo()\n\n const {\n action,\n beforeSubmit,\n children,\n className,\n disableSuccessStatus,\n disableValidationOnSubmit,\n disabled: disabledFromProps,\n // fields: fieldsFromProps = collection?.fields || global?.fields,\n handleResponse,\n initialState, // fully formed initial field state\n isInitializing: initializingFromProps,\n onChange,\n onSubmit,\n onSuccess,\n redirect,\n submitted: submittedFromProps,\n uuid,\n waitForAutocomplete,\n } = props\n\n const method = 'method' in props ? props?.method : undefined\n\n const router = useRouter()\n\n const { code: locale } = useLocale()\n const { i18n, t } = useTranslation()\n const { refreshCookie, user } = useAuth()\n const operation = useOperation()\n const { formQueryParams } = useFormQueryParams()\n\n const config = useConfig()\n const {\n routes: { api: apiRoute },\n serverURL,\n } = config\n\n const [disabled, setDisabled] = useState(disabledFromProps || false)\n const [isMounted, setIsMounted] = useState(false)\n const [modified, setModified] = useState(false)\n const [initializing, setInitializing] = useState(initializingFromProps)\n const [processing, setProcessing] = useState(false)\n const [submitted, setSubmitted] = useState(false)\n const formRef = useRef<HTMLFormElement>(null)\n const contextRef = useRef({} as FormContextType)\n\n const fieldsReducer = useReducer(fieldReducer, {}, () => initialState)\n\n /**\n * `fields` is the current, up-to-date state/data of all fields in the form. It can be modified by using dispatchFields,\n * which calls the fieldReducer, which then updates the state.\n */\n const [fields, dispatchFields] = fieldsReducer\n\n contextRef.current.fields = fields\n\n const validateForm = useCallback(async () => {\n const validatedFieldState = {}\n let isValid = true\n\n const dataFromContext = contextRef.current.getData()\n const data = dataFromContext\n\n const validationPromises = Object.entries(contextRef.current.fields).map(\n async ([path, field]) => {\n const validatedField = field\n\n if (field.passesCondition !== false) {\n let validationResult: boolean | string = validatedField.valid\n\n if (typeof field.validate === 'function') {\n let valueToValidate = field.value\n\n if (field?.rows && Array.isArray(field.rows)) {\n valueToValidate = contextRef.current.getDataByPath(path)\n }\n\n validationResult = await field.validate(valueToValidate, {\n id,\n config,\n data,\n operation,\n siblingData: contextRef.current.getSiblingData(path),\n t,\n user,\n })\n\n if (typeof validationResult === 'string') {\n validatedField.errorMessage = validationResult\n validatedField.valid = false\n } else {\n validatedField.valid = true\n validatedField.errorMessage = undefined\n }\n }\n\n if (validatedField.valid === false) {\n isValid = false\n }\n }\n\n validatedFieldState[path] = validatedField\n },\n )\n\n await Promise.all(validationPromises)\n\n if (!dequal(contextRef.current.fields, validatedFieldState)) {\n dispatchFields({ type: 'REPLACE_STATE', state: validatedFieldState })\n }\n\n return isValid\n }, [id, user, operation, t, dispatchFields, config])\n\n const submit = useCallback(\n async (options: SubmitOptions = {}, e): Promise<void> => {\n const {\n action: actionArg,\n method: methodToUse = method,\n overrides = {},\n skipValidation,\n } = options\n\n if (disabled) {\n if (e) {\n e.preventDefault()\n }\n return\n }\n\n // create new toast promise which will resolve manually later\n let successToast, errorToast\n const promise = new Promise((resolve, reject) => {\n successToast = resolve\n errorToast = reject\n })\n\n const hasFormSubmitAction =\n actionArg || typeof action === 'string' || typeof action === 'function'\n\n if (redirect || disableSuccessStatus || !hasFormSubmitAction) {\n // Do not show submitting toast, as the promise toast may never disappear under these conditions.\n // Instead, make successToast() or errorToast() throw toast.success / toast.error\n successToast = (data) => toast.success(data)\n errorToast = (data) => toast.error(data)\n } else {\n toast.promise(promise, {\n error: (data) => {\n return data as string\n },\n loading: t('general:submitting'),\n success: (data) => {\n return data as string\n },\n })\n }\n\n if (e) {\n e.stopPropagation()\n e.preventDefault()\n }\n\n setProcessing(true)\n setDisabled(true)\n\n if (waitForAutocomplete) await wait(100)\n\n // Execute server side validations\n if (Array.isArray(beforeSubmit)) {\n let revalidatedFormState: FormState\n\n await beforeSubmit.reduce(async (priorOnChange, beforeSubmitFn) => {\n await priorOnChange\n\n const result = await beforeSubmitFn({\n formState: fields,\n })\n\n revalidatedFormState = result\n }, Promise.resolve())\n\n const isValid = Object.entries(revalidatedFormState).every(([, field]) => field.valid)\n\n if (!isValid) {\n setProcessing(false)\n setSubmitted(true)\n setDisabled(false)\n return dispatchFields({ type: 'REPLACE_STATE', state: revalidatedFormState })\n }\n }\n\n const isValid =\n skipValidation || disableValidationOnSubmit ? true : await contextRef.current.validateForm()\n\n // If not valid, prevent submission\n if (!isValid) {\n errorToast(t('error:correctInvalidFields'))\n setProcessing(false)\n setSubmitted(true)\n setDisabled(false)\n return\n }\n\n // If submit handler comes through via props, run that\n if (onSubmit) {\n const data = {\n ...reduceFieldsToValues(fields, true),\n ...overrides,\n }\n\n onSubmit(fields, data)\n }\n\n if (!hasFormSubmitAction) {\n // No action provided, so we should return. An example where this happens are lexical link drawers. Upon submitting the drawer, we\n // want to close it without submitting the form. Stuff like validation would be handled by lexical before this, through beforeSubmit\n setProcessing(false)\n setSubmitted(true)\n setDisabled(false)\n return\n }\n\n const formData = contextRef.current.createFormData(overrides)\n\n try {\n let res\n const actionEndpoint =\n actionArg ||\n (typeof action === 'string'\n ? `${action}${qs.stringify(formQueryParams, { addQueryPrefix: true })}`\n : null)\n\n if (actionEndpoint) {\n res = await requests[methodToUse.toLowerCase()](actionEndpoint, {\n body: formData,\n headers: {\n 'Accept-Language': i18n.language,\n },\n })\n } else if (typeof action === 'function') {\n res = await action(formData)\n }\n\n setModified(false)\n setDisabled(false)\n\n if (typeof handleResponse === 'function') {\n handleResponse(res, successToast, errorToast)\n return\n }\n\n const contentType = res.headers.get('content-type')\n const isJSON = contentType && contentType.indexOf('application/json') !== -1\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let json: Record<string, any> = {}\n\n if (isJSON) json = await res.json()\n if (res.status < 400) {\n if (typeof onSuccess === 'function') await onSuccess(json)\n setSubmitted(false)\n setProcessing(false)\n\n if (redirect) {\n router.push(redirect)\n } else if (!disableSuccessStatus) {\n successToast(json.message || t('general:submissionSuccessful'))\n }\n } else {\n setProcessing(false)\n setSubmitted(true)\n\n contextRef.current = { ...contextRef.current } // triggers rerender of all components that subscribe to form\n if (json.message) {\n errorToast(json.message)\n\n return\n }\n\n if (Array.isArray(json.errors)) {\n const [fieldErrors, nonFieldErrors] = json.errors.reduce(\n ([fieldErrs, nonFieldErrs], err) => {\n const newFieldErrs = []\n const newNonFieldErrs = []\n\n if (err?.message) {\n newNonFieldErrs.push(err)\n }\n\n if (Array.isArray(err?.data)) {\n err.data.forEach((dataError) => {\n if (dataError?.field) {\n newFieldErrs.push(dataError)\n } else {\n newNonFieldErrs.push(dataError)\n }\n })\n }\n\n return [\n [...fieldErrs, ...newFieldErrs],\n [...nonFieldErrs, ...newNonFieldErrs],\n ]\n },\n [[], []],\n )\n\n dispatchFields({\n type: 'ADD_SERVER_ERRORS',\n errors: fieldErrors,\n })\n\n nonFieldErrors.forEach((err) => {\n errorToast(err.message || t('error:unknown'))\n })\n\n return\n }\n\n const message = errorMessages?.[res.status] || res?.statusText || t('error:unknown')\n\n errorToast(message)\n }\n } catch (err) {\n console.error('Error submitting form', err)\n setProcessing(false)\n setSubmitted(true)\n setDisabled(false)\n\n errorToast(err.message)\n }\n },\n [\n beforeSubmit,\n action,\n disableSuccessStatus,\n disableValidationOnSubmit,\n disabled,\n dispatchFields,\n fields,\n handleResponse,\n method,\n onSubmit,\n onSuccess,\n redirect,\n router,\n t,\n i18n,\n waitForAutocomplete,\n formQueryParams,\n ],\n )\n\n const getFields = useCallback(() => contextRef.current.fields, [])\n\n const getField = useCallback((path: string) => contextRef.current.fields[path], [])\n\n const getData = useCallback(() => reduceFieldsToValues(contextRef.current.fields, true), [])\n\n const getSiblingData = useCallback(\n (path: string) => getSiblingDataFunc(contextRef.current.fields, path),\n [],\n )\n const getDataByPath = useCallback<GetDataByPath>(\n (path: string) => getDataByPathFunc(contextRef.current.fields, path),\n [],\n )\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const createFormData = useCallback((overrides: any = {}) => {\n const data = reduceFieldsToValues(contextRef.current.fields, true)\n\n const file = data?.file\n\n if (file) {\n delete data.file\n }\n\n const dataWithOverrides = {\n ...data,\n ...overrides,\n }\n\n const dataToSerialize = {\n _payload: JSON.stringify(dataWithOverrides),\n file,\n }\n\n // nullAsUndefineds is important to allow uploads and relationship fields to clear themselves\n const formData = serialize(dataToSerialize, { indices: true, nullsAsUndefineds: false })\n\n return formData\n }, [])\n\n const reset = useCallback(\n async (data: unknown) => {\n const newState = await getFormState({\n apiRoute,\n body: {\n id,\n collectionSlug,\n data,\n globalSlug,\n operation,\n schemaPath: collectionSlug || globalSlug,\n },\n serverURL,\n })\n\n contextRef.current = { ...initContextState } as FormContextType\n setModified(false)\n dispatchFields({ type: 'REPLACE_STATE', state: newState })\n },\n [apiRoute, collectionSlug, dispatchFields, globalSlug, id, operation, serverURL],\n )\n\n const replaceState = useCallback(\n (state: FormState) => {\n contextRef.current = { ...initContextState } as FormContextType\n setModified(false)\n dispatchFields({ type: 'REPLACE_STATE', state })\n },\n [dispatchFields],\n )\n\n const getFieldStateBySchemaPath = useCallback(\n async ({ data, schemaPath }) => {\n const fieldSchema = await getFormState({\n apiRoute,\n body: {\n collectionSlug,\n data,\n globalSlug,\n schemaPath,\n },\n serverURL,\n })\n return fieldSchema\n },\n [apiRoute, collectionSlug, globalSlug, serverURL],\n )\n\n const addFieldRow: FormContextType['addFieldRow'] = useCallback(\n async ({ data, path, rowIndex, schemaPath }) => {\n const subFieldState = await getFieldStateBySchemaPath({ data, schemaPath })\n\n dispatchFields({\n type: 'ADD_ROW',\n blockType: data?.blockType,\n path,\n rowIndex,\n subFieldState,\n })\n },\n [getFieldStateBySchemaPath, dispatchFields],\n )\n\n const removeFieldRow: FormContextType['removeFieldRow'] = useCallback(\n ({ path, rowIndex }) => {\n dispatchFields({ type: 'REMOVE_ROW', path, rowIndex })\n },\n [dispatchFields],\n )\n\n const replaceFieldRow: FormContextType['replaceFieldRow'] = useCallback(\n async ({ data, path, rowIndex, schemaPath }) => {\n const subFieldState = await getFieldStateBySchemaPath({ data, schemaPath })\n\n dispatchFields({\n type: 'REPLACE_ROW',\n blockType: data?.blockType,\n path,\n rowIndex,\n subFieldState,\n })\n },\n [getFieldStateBySchemaPath, dispatchFields],\n )\n\n useEffect(() => {\n if (initializingFromProps !== undefined) {\n setInitializing(initializingFromProps)\n }\n }, [initializingFromProps])\n\n contextRef.current.submit = submit\n contextRef.current.getFields = getFields\n contextRef.current.getField = getField\n contextRef.current.getData = getData\n contextRef.current.getSiblingData = getSiblingData\n contextRef.current.getDataByPath = getDataByPath\n contextRef.current.validateForm = validateForm\n contextRef.current.createFormData = createFormData\n contextRef.current.setModified = setModified\n contextRef.current.setProcessing = setProcessing\n contextRef.current.setSubmitted = setSubmitted\n contextRef.current.disabled = disabled\n contextRef.current.setDisabled = setDisabled\n contextRef.current.formRef = formRef\n contextRef.current.reset = reset\n contextRef.current.replaceState = replaceState\n contextRef.current.dispatchFields = dispatchFields\n contextRef.current.addFieldRow = addFieldRow\n contextRef.current.removeFieldRow = removeFieldRow\n contextRef.current.replaceFieldRow = replaceFieldRow\n contextRef.current.uuid = uuid\n contextRef.current.initializing = initializing\n\n useEffect(() => {\n setIsMounted(true)\n }, [])\n\n useEffect(() => {\n if (typeof disabledFromProps === 'boolean') setDisabled(disabledFromProps)\n }, [disabledFromProps])\n\n useEffect(() => {\n if (typeof submittedFromProps === 'boolean') setSubmitted(submittedFromProps)\n }, [submittedFromProps])\n\n useEffect(() => {\n if (initialState) {\n contextRef.current = { ...initContextState } as FormContextType\n dispatchFields({ type: 'REPLACE_STATE', optimize: false, state: initialState })\n }\n }, [initialState, dispatchFields])\n\n useThrottledEffect(\n () => {\n refreshCookie()\n },\n 15000,\n [fields],\n )\n\n useEffect(() => {\n contextRef.current = { ...contextRef.current } // triggers rerender of all components that subscribe to form\n setModified(false)\n }, [locale])\n\n const classes = [className, baseClass].filter(Boolean).join(' ')\n\n useDebouncedEffect(\n () => {\n const executeOnChange = async () => {\n if (Array.isArray(onChange)) {\n let revalidatedFormState: FormState = contextRef.current.fields\n\n for (const onChangeFn of onChange) {\n revalidatedFormState = await onChangeFn({\n formState: revalidatedFormState,\n })\n }\n\n const { changed, newState } = mergeServerFormState(\n contextRef.current.fields || {},\n revalidatedFormState,\n )\n\n if (changed) {\n dispatchFields({\n type: 'REPLACE_STATE',\n optimize: false,\n state: newState,\n })\n }\n }\n }\n\n if (modified) void executeOnChange()\n },\n 150,\n // Make sure we trigger this whenever modified changes (not just when `fields` changes), otherwise we will miss merging server form state for the first form update/onChange. Here's why:\n // `fields` updates before `modified`, because setModified is in a setTimeout. So on the first change, modified is false, so we don't trigger the effect even though we should.\n [contextRef.current.fields, dispatchFields, onChange, modified],\n )\n\n const actionString =\n typeof action === 'string'\n ? `${action}${qs.stringify(formQueryParams, { addQueryPrefix: true })}`\n : ''\n\n return (\n <form\n action={method ? actionString : (action as string)}\n className={classes}\n method={method}\n noValidate\n onSubmit={(e) => contextRef.current.submit({}, e)}\n ref={formRef}\n >\n <FormContext.Provider value={contextRef.current}>\n <FormWatchContext.Provider\n value={{\n fields,\n ...contextRef.current,\n }}\n >\n <SubmittedContext.Provider value={submitted}>\n <InitializingContext.Provider value={!isMounted || (isMounted && initializing)}>\n <ProcessingContext.Provider value={processing}>\n <ModifiedContext.Provider value={modified}>\n <FormFieldsContext.Provider value={fieldsReducer}>\n {children}\n </FormFieldsContext.Provider>\n </ModifiedContext.Provider>\n </ProcessingContext.Provider>\n </InitializingContext.Provider>\n </SubmittedContext.Provider>\n </FormWatchContext.Provider>\n </FormContext.Provider>\n </form>\n )\n}\n\nexport {\n FormContext,\n FormFieldsContext,\n FormWatchContext,\n ModifiedContext,\n ProcessingContext,\n SubmittedContext,\n useAllFormFields,\n useForm,\n useFormFields,\n useFormModified,\n useFormProcessing,\n useFormSubmitted,\n useWatchForm,\n} from './context.js'\n\nexport { FormProps }\n"],"names":["dequal","useRouter","serialize","wait","qs","React","useCallback","useEffect","useReducer","useRef","useState","toast","useDebouncedEffect","useThrottledEffect","useAuth","useConfig","useDocumentInfo","useFormQueryParams","useLocale","useOperation","useTranslation","requests","getFormState","reduceFieldsToValues","FormContext","FormFieldsContext","FormWatchContext","InitializingContext","ModifiedContext","ProcessingContext","SubmittedContext","errorMessages","fieldReducer","getDataByPath","getDataByPathFunc","getSiblingData","getSiblingDataFunc","initContextState","mergeServerFormState","baseClass","Form","props","id","collectionSlug","globalSlug","action","beforeSubmit","children","className","disableSuccessStatus","disableValidationOnSubmit","disabled","disabledFromProps","handleResponse","initialState","isInitializing","initializingFromProps","onChange","onSubmit","onSuccess","redirect","submitted","submittedFromProps","uuid","waitForAutocomplete","method","undefined","router","code","locale","i18n","t","refreshCookie","user","operation","formQueryParams","config","routes","api","apiRoute","serverURL","setDisabled","isMounted","setIsMounted","modified","setModified","initializing","setInitializing","processing","setProcessing","setSubmitted","formRef","contextRef","fieldsReducer","fields","dispatchFields","current","validateForm","validatedFieldState","isValid","dataFromContext","getData","data","validationPromises","Object","entries","map","path","field","validatedField","passesCondition","validationResult","valid","validate","valueToValidate","value","rows","Array","isArray","siblingData","errorMessage","Promise","all","type","state","submit","options","e","actionArg","methodToUse","overrides","skipValidation","preventDefault","successToast","errorToast","promise","resolve","reject","hasFormSubmitAction","success","error","loading","stopPropagation","revalidatedFormState","reduce","priorOnChange","beforeSubmitFn","result","formState","every","formData","createFormData","res","actionEndpoint","stringify","addQueryPrefix","toLowerCase","body","headers","language","contentType","get","isJSON","indexOf","json","status","push","message","errors","fieldErrors","nonFieldErrors","fieldErrs","nonFieldErrs","err","newFieldErrs","newNonFieldErrs","forEach","dataError","statusText","console","getFields","getField","file","dataWithOverrides","dataToSerialize","_payload","JSON","indices","nullsAsUndefineds","reset","newState","schemaPath","replaceState","getFieldStateBySchemaPath","fieldSchema","addFieldRow","rowIndex","subFieldState","blockType","removeFieldRow","replaceFieldRow","optimize","classes","filter","Boolean","join","executeOnChange","onChangeFn","changed","actionString","form","noValidate","ref","Provider","useAllFormFields","useForm","useFormFields","useFormModified","useFormProcessing","useFormSubmitted","useWatchForm"],"mappings":"AAAA;;AAGA,kEAAkE,GAClE,SAASA,MAAM,QAAQ,cAAa,CAAC,wCAAwC;AAC7E,SAASC,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,IAAI,QAAQ,iBAAgB;AACrC,OAAOC,QAAQ,KAAI;AACnB,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AACnF,SAASC,KAAK,QAAQ,SAAQ;AAS9B,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,OAAO,QAAQ,gCAA+B;AACvD,SAASC,SAAS,QAAQ,kCAAiC;AA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,iBAAiB;QAAEgF,gBAAgB;IAAK,GAAG,CAAC,GACrE;IAEN,qBACE,KAACuD;QACCrK,QAAQoB,SAASgJ,eAAgBpK;QACjCG,WAAW0J;QACXzI,QAAQA;QACRkJ,UAAU;QACVzJ,UAAU,CAACqE,IAAMnC,WAAWI,OAAO,CAAC6B,MAAM,CAAC,CAAC,GAAGE;QAC/CqF,KAAKzH;kBAEL,cAAA,KAACnE,YAAY6L,QAAQ;YAAClG,OAAOvB,WAAWI,OAAO;sBAC7C,cAAA,KAACtE,iBAAiB2L,QAAQ;gBACxBlG,OAAO;oBACLrB;oBACA,GAAGF,WAAWI,OAAO;gBACvB;0BAEA,cAAA,KAAClE,iBAAiBuL,QAAQ;oBAAClG,OAAOtD;8BAChC,cAAA,KAAClC,oBAAoB0L,QAAQ;wBAAClG,OAAO,CAACjC,aAAcA,aAAaI;kCAC/D,cAAA,KAACzD,kBAAkBwL,QAAQ;4BAAClG,OAAO3B;sCACjC,cAAA,KAAC5D,gBAAgByL,QAAQ;gCAAClG,OAAO/B;0CAC/B,cAAA,KAAC3D,kBAAkB4L,QAAQ;oCAAClG,OAAOtB;8CAChC9C;;;;;;;;;AAUrB,EAAC;AAED,SACEvB,WAAW,EACXC,iBAAiB,EACjBC,gBAAgB,EAChBE,eAAe,EACfC,iBAAiB,EACjBC,gBAAgB,EAChBwL,gBAAgB,EAChBC,OAAO,EACPC,aAAa,EACbC,eAAe,EACfC,iBAAiB,EACjBC,gBAAgB,EAChBC,YAAY,QACP,eAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/forms/Form/initContextState.ts"],"sourcesContent":["import type { Data, FormField, FormState } from 'payload'\n\nimport type {\n Context,\n CreateFormData,\n DispatchFields,\n GetSiblingData,\n Reset,\n SetModified,\n SetProcessing,\n SetSubmitted,\n Submit,\n ValidateForm,\n} from './types.js'\n\nconst submit: Submit = () => undefined\nconst getSiblingData: GetSiblingData = () => undefined\nconst dispatchFields: DispatchFields = () => undefined\nconst validateForm: ValidateForm = () => undefined\nconst createFormData: CreateFormData = () => undefined\n\nconst setModified: SetModified = () => undefined\nconst setProcessing: SetProcessing = () => undefined\nconst setSubmitted: SetSubmitted = () => undefined\nconst reset: Reset = () => undefined\n\nexport const initContextState: Context = {\n addFieldRow: () => undefined,\n buildRowErrors: () => undefined,\n createFormData,\n disabled: false,\n dispatchFields,\n fields: {},\n formRef: null,\n getData: (): Data => undefined,\n getDataByPath: () => undefined,\n getField: (): FormField => undefined,\n getFields: (): FormState => ({}),\n getSiblingData,\n initializing: undefined,\n removeFieldRow: () => undefined,\n replaceFieldRow: () => undefined,\n replaceState: () => undefined,\n reset,\n setDisabled: () => undefined,\n setModified,\n setProcessing,\n setSubmitted,\n submit,\n validateForm,\n}\n"],"names":["submit","undefined","getSiblingData","dispatchFields","validateForm","createFormData","setModified","setProcessing","setSubmitted","reset","initContextState","addFieldRow","buildRowErrors","disabled","fields","formRef","getData","getDataByPath","getField","getFields","initializing","removeFieldRow","replaceFieldRow","replaceState","setDisabled"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/Form/initContextState.ts"],"sourcesContent":["import type { Data, FormField, FormState } from 'payload'\n\nimport type {\n Context,\n CreateFormData,\n DispatchFields,\n GetSiblingData,\n Reset,\n SetModified,\n SetProcessing,\n SetSubmitted,\n Submit,\n ValidateForm,\n} from './types.js'\n\nconst submit: Submit = () => undefined\nconst getSiblingData: GetSiblingData = () => undefined\nconst dispatchFields: DispatchFields = () => undefined\nconst validateForm: ValidateForm = () => undefined\nconst createFormData: CreateFormData = () => undefined\n\nconst setModified: SetModified = () => undefined\nconst setProcessing: SetProcessing = () => undefined\nconst setSubmitted: SetSubmitted = () => undefined\nconst reset: Reset = () => undefined\n\nexport const initContextState: Context = {\n addFieldRow: () => undefined,\n buildRowErrors: () => undefined,\n createFormData,\n disabled: false,\n dispatchFields,\n fields: {},\n formRef: null,\n getData: (): Data => undefined,\n getDataByPath: () => undefined,\n getField: (): FormField => undefined,\n getFields: (): FormState => ({}),\n getSiblingData,\n initializing: undefined,\n removeFieldRow: () => undefined,\n replaceFieldRow: () => undefined,\n replaceState: () => undefined,\n reset,\n setDisabled: () => undefined,\n setModified,\n setProcessing,\n setSubmitted,\n submit,\n validateForm,\n}\n"],"names":["submit","undefined","getSiblingData","dispatchFields","validateForm","createFormData","setModified","setProcessing","setSubmitted","reset","initContextState","addFieldRow","buildRowErrors","disabled","fields","formRef","getData","getDataByPath","getField","getFields","initializing","removeFieldRow","replaceFieldRow","replaceState","setDisabled"],"mappings":"AAeA,MAAMA,SAAiB,IAAMC;AAC7B,MAAMC,iBAAiC,IAAMD;AAC7C,MAAME,iBAAiC,IAAMF;AAC7C,MAAMG,eAA6B,IAAMH;AACzC,MAAMI,iBAAiC,IAAMJ;AAE7C,MAAMK,cAA2B,IAAML;AACvC,MAAMM,gBAA+B,IAAMN;AAC3C,MAAMO,eAA6B,IAAMP;AACzC,MAAMQ,QAAe,IAAMR;AAE3B,OAAO,MAAMS,mBAA4B;IACvCC,aAAa,IAAMV;IACnBW,gBAAgB,IAAMX;IACtBI;IACAQ,UAAU;IACVV;IACAW,QAAQ,CAAC;IACTC,SAAS;IACTC,SAAS,IAAYf;IACrBgB,eAAe,IAAMhB;IACrBiB,UAAU,IAAiBjB;IAC3BkB,WAAW,IAAkB,CAAA,CAAC,CAAA;IAC9BjB;IACAkB,cAAcnB;IACdoB,gBAAgB,IAAMpB;IACtBqB,iBAAiB,IAAMrB;IACvBsB,cAAc,IAAMtB;IACpBQ;IACAe,aAAa,IAAMvB;IACnBK;IACAC;IACAC;IACAR;IACAI;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/forms/Form/mergeErrorPaths.ts"],"sourcesContent":["import { arraysHaveSameStrings } from '../../utilities/arraysHaveSameStrings.js'\n\nexport const mergeErrorPaths = (\n existing?: string[],\n incoming?: string[],\n): {\n changed: boolean\n result?: string[]\n} => {\n if (!existing) {\n return {\n changed: false,\n result: undefined,\n }\n }\n\n const existingErrorPaths: string[] = []\n const incomingErrorPaths: string[] = []\n\n if (Array.isArray(incoming) && incoming?.length) {\n incoming.forEach((path) => incomingErrorPaths.push(path))\n }\n\n if (Array.isArray(existing) && existing?.length) {\n existing.forEach((path) => existingErrorPaths.push(path))\n }\n\n if (!arraysHaveSameStrings(existingErrorPaths, incomingErrorPaths)) {\n return {\n changed: true,\n result: incomingErrorPaths,\n }\n }\n return {\n changed: false,\n result: existing,\n }\n}\n"],"names":["arraysHaveSameStrings","mergeErrorPaths","existing","incoming","changed","result","undefined","existingErrorPaths","incomingErrorPaths","Array","isArray","length","forEach","path","push"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/Form/mergeErrorPaths.ts"],"sourcesContent":["import { arraysHaveSameStrings } from '../../utilities/arraysHaveSameStrings.js'\n\nexport const mergeErrorPaths = (\n existing?: string[],\n incoming?: string[],\n): {\n changed: boolean\n result?: string[]\n} => {\n if (!existing) {\n return {\n changed: false,\n result: undefined,\n }\n }\n\n const existingErrorPaths: string[] = []\n const incomingErrorPaths: string[] = []\n\n if (Array.isArray(incoming) && incoming?.length) {\n incoming.forEach((path) => incomingErrorPaths.push(path))\n }\n\n if (Array.isArray(existing) && existing?.length) {\n existing.forEach((path) => existingErrorPaths.push(path))\n }\n\n if (!arraysHaveSameStrings(existingErrorPaths, incomingErrorPaths)) {\n return {\n changed: true,\n result: incomingErrorPaths,\n }\n }\n return {\n changed: false,\n result: existing,\n }\n}\n"],"names":["arraysHaveSameStrings","mergeErrorPaths","existing","incoming","changed","result","undefined","existingErrorPaths","incomingErrorPaths","Array","isArray","length","forEach","path","push"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,2CAA0C;AAEhF,OAAO,MAAMC,kBAAkB,CAC7BC,UACAC;IAKA,IAAI,CAACD,UAAU;QACb,OAAO;YACLE,SAAS;YACTC,QAAQC;QACV;IACF;IAEA,MAAMC,qBAA+B,EAAE;IACvC,MAAMC,qBAA+B,EAAE;IAEvC,IAAIC,MAAMC,OAAO,CAACP,aAAaA,UAAUQ,QAAQ;QAC/CR,SAASS,OAAO,CAAC,CAACC,OAASL,mBAAmBM,IAAI,CAACD;IACrD;IAEA,IAAIJ,MAAMC,OAAO,CAACR,aAAaA,UAAUS,QAAQ;QAC/CT,SAASU,OAAO,CAAC,CAACC,OAASN,mBAAmBO,IAAI,CAACD;IACrD;IAEA,IAAI,CAACb,sBAAsBO,oBAAoBC,qBAAqB;QAClE,OAAO;YACLJ,SAAS;YACTC,QAAQG;QACV;IACF;IACA,OAAO;QACLJ,SAAS;QACTC,QAAQH;IACV;AACF,EAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { dequal } from 'dequal/lite'; // lite: no need for Map and Set support
|
|
2
2
|
import { mergeErrorPaths } from './mergeErrorPaths.js';
|
|
3
3
|
const serverPropsToAccept = [
|
|
4
4
|
'passesCondition',
|
|
@@ -29,7 +29,7 @@ const serverPropsToAccept = [
|
|
|
29
29
|
/**
|
|
30
30
|
* Handle filterOptions
|
|
31
31
|
*/ if (incomingState[path]?.filterOptions || newFieldState.filterOptions) {
|
|
32
|
-
if (!
|
|
32
|
+
if (!dequal(incomingState[path]?.filterOptions, newFieldState.filterOptions)) {
|
|
33
33
|
changed = true;
|
|
34
34
|
newFieldState.filterOptions = incomingState[path].filterOptions;
|
|
35
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/forms/Form/mergeServerFormState.ts"],"sourcesContent":["import type { FormState } from 'payload'\n\nimport
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/Form/mergeServerFormState.ts"],"sourcesContent":["import type { FormState } from 'payload'\n\nimport { dequal } from 'dequal/lite' // lite: no need for Map and Set support\n\nimport { mergeErrorPaths } from './mergeErrorPaths.js'\n\nconst serverPropsToAccept = ['passesCondition', 'valid', 'errorMessage']\n\n/**\n * Merges certain properties from the server state into the client state. These do not include values,\n * as we do not want to update them on the client like that, which would cause flickering.\n *\n * We want to use this to update the error state, and other properties that are not user input, as the error state\n * is the thing we want to keep in sync with the server (where it's calculated) on the client.\n */\nexport const mergeServerFormState = (\n existingState: FormState,\n incomingState: FormState,\n): { changed: boolean; newState: FormState } => {\n let changed = false\n\n const newState = {}\n\n if (existingState) {\n Object.entries(existingState).forEach(([path, newFieldState]) => {\n if (!incomingState[path]) return\n\n /**\n * Handle error paths\n */\n\n const errorPathsResult = mergeErrorPaths(\n newFieldState.errorPaths,\n incomingState[path].errorPaths as unknown as string[],\n )\n if (errorPathsResult.result) {\n if (errorPathsResult.changed) {\n changed = errorPathsResult.changed\n }\n newFieldState.errorPaths = errorPathsResult.result\n }\n\n /**\n * Handle filterOptions\n */\n if (incomingState[path]?.filterOptions || newFieldState.filterOptions) {\n if (!dequal(incomingState[path]?.filterOptions, newFieldState.filterOptions)) {\n changed = true\n newFieldState.filterOptions = incomingState[path].filterOptions\n }\n }\n\n /**\n * Handle the rest which is in serverPropsToAccept\n */\n serverPropsToAccept.forEach((prop) => {\n if (incomingState[path]?.[prop] !== newFieldState[prop]) {\n changed = true\n if (!(prop in incomingState[path])) {\n delete newFieldState[prop]\n } else {\n newFieldState[prop] = incomingState[path][prop]\n }\n }\n })\n\n // Conditions don't work if we don't memcopy the new state, as the object references would otherwise be the same\n newState[path] = { ...newFieldState }\n })\n }\n\n return { changed, newState }\n}\n"],"names":["dequal","mergeErrorPaths","serverPropsToAccept","mergeServerFormState","existingState","incomingState","changed","newState","Object","entries","forEach","path","newFieldState","errorPathsResult","errorPaths","result","filterOptions","prop"],"mappings":"AAEA,SAASA,MAAM,QAAQ,cAAa,CAAC,wCAAwC;AAE7E,SAASC,eAAe,QAAQ,uBAAsB;AAEtD,MAAMC,sBAAsB;IAAC;IAAmB;IAAS;CAAe;AAExE;;;;;;CAMC,GACD,OAAO,MAAMC,uBAAuB,CAClCC,eACAC;IAEA,IAAIC,UAAU;IAEd,MAAMC,WAAW,CAAC;IAElB,IAAIH,eAAe;QACjBI,OAAOC,OAAO,CAACL,eAAeM,OAAO,CAAC,CAAC,CAACC,MAAMC,cAAc;YAC1D,IAAI,CAACP,aAAa,CAACM,KAAK,EAAE;YAE1B;;OAEC,GAED,MAAME,mBAAmBZ,gBACvBW,cAAcE,UAAU,EACxBT,aAAa,CAACM,KAAK,CAACG,UAAU;YAEhC,IAAID,iBAAiBE,MAAM,EAAE;gBAC3B,IAAIF,iBAAiBP,OAAO,EAAE;oBAC5BA,UAAUO,iBAAiBP,OAAO;gBACpC;gBACAM,cAAcE,UAAU,GAAGD,iBAAiBE,MAAM;YACpD;YAEA;;OAEC,GACD,IAAIV,aAAa,CAACM,KAAK,EAAEK,iBAAiBJ,cAAcI,aAAa,EAAE;gBACrE,IAAI,CAAChB,OAAOK,aAAa,CAACM,KAAK,EAAEK,eAAeJ,cAAcI,aAAa,GAAG;oBAC5EV,UAAU;oBACVM,cAAcI,aAAa,GAAGX,aAAa,CAACM,KAAK,CAACK,aAAa;gBACjE;YACF;YAEA;;OAEC,GACDd,oBAAoBQ,OAAO,CAAC,CAACO;gBAC3B,IAAIZ,aAAa,CAACM,KAAK,EAAE,CAACM,KAAK,KAAKL,aAAa,CAACK,KAAK,EAAE;oBACvDX,UAAU;oBACV,IAAI,CAAEW,CAAAA,QAAQZ,aAAa,CAACM,KAAK,AAAD,GAAI;wBAClC,OAAOC,aAAa,CAACK,KAAK;oBAC5B,OAAO;wBACLL,aAAa,CAACK,KAAK,GAAGZ,aAAa,CAACM,KAAK,CAACM,KAAK;oBACjD;gBACF;YACF;YAEA,gHAAgH;YAChHV,QAAQ,CAACI,KAAK,GAAG;gBAAE,GAAGC,aAAa;YAAC;QACtC;IACF;IAEA,OAAO;QAAEN;QAASC;IAAS;AAC7B,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/forms/Form/rows.ts"],"sourcesContent":["import type { FormState } from 'payload'\n\ntype Result = {\n remainingFields: FormState\n rows: FormState[]\n}\n\nexport const separateRows = (path: string, fields: FormState): Result => {\n const remainingFields: FormState = {}\n\n const rows = Object.entries(fields).reduce((incomingRows, [fieldPath, field]) => {\n const newRows = incomingRows\n\n if (fieldPath.indexOf(`${path}.`) === 0) {\n const [rowIndex] = fieldPath.replace(`${path}.`, '').split('.')\n if (!newRows[rowIndex]) newRows[rowIndex] = {}\n newRows[rowIndex][fieldPath.replace(`${path}.${String(rowIndex)}.`, '')] = { ...field }\n } else {\n remainingFields[fieldPath] = field\n }\n\n return newRows\n }, [])\n\n return {\n remainingFields,\n rows,\n }\n}\n\nexport const flattenRows = (path: string, rows: FormState[]): FormState => {\n return rows.reduce(\n (fields, row, i) => ({\n ...fields,\n ...Object.entries(row).reduce((subFields, [subPath, subField]) => {\n return {\n ...subFields,\n [`${path}.${i}.${subPath}`]: { ...subField },\n }\n }, {}),\n }),\n {},\n )\n}\n"],"names":["separateRows","path","fields","remainingFields","rows","Object","entries","reduce","incomingRows","fieldPath","field","newRows","indexOf","rowIndex","replace","split","String","flattenRows","row","i","subFields","subPath","subField"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/Form/rows.ts"],"sourcesContent":["import type { FormState } from 'payload'\n\ntype Result = {\n remainingFields: FormState\n rows: FormState[]\n}\n\nexport const separateRows = (path: string, fields: FormState): Result => {\n const remainingFields: FormState = {}\n\n const rows = Object.entries(fields).reduce((incomingRows, [fieldPath, field]) => {\n const newRows = incomingRows\n\n if (fieldPath.indexOf(`${path}.`) === 0) {\n const [rowIndex] = fieldPath.replace(`${path}.`, '').split('.')\n if (!newRows[rowIndex]) newRows[rowIndex] = {}\n newRows[rowIndex][fieldPath.replace(`${path}.${String(rowIndex)}.`, '')] = { ...field }\n } else {\n remainingFields[fieldPath] = field\n }\n\n return newRows\n }, [])\n\n return {\n remainingFields,\n rows,\n }\n}\n\nexport const flattenRows = (path: string, rows: FormState[]): FormState => {\n return rows.reduce(\n (fields, row, i) => ({\n ...fields,\n ...Object.entries(row).reduce((subFields, [subPath, subField]) => {\n return {\n ...subFields,\n [`${path}.${i}.${subPath}`]: { ...subField },\n }\n }, {}),\n }),\n {},\n )\n}\n"],"names":["separateRows","path","fields","remainingFields","rows","Object","entries","reduce","incomingRows","fieldPath","field","newRows","indexOf","rowIndex","replace","split","String","flattenRows","row","i","subFields","subPath","subField"],"mappings":"AAOA,OAAO,MAAMA,eAAe,CAACC,MAAcC;IACzC,MAAMC,kBAA6B,CAAC;IAEpC,MAAMC,OAAOC,OAAOC,OAAO,CAACJ,QAAQK,MAAM,CAAC,CAACC,cAAc,CAACC,WAAWC,MAAM;QAC1E,MAAMC,UAAUH;QAEhB,IAAIC,UAAUG,OAAO,CAAC,CAAC,EAAEX,KAAK,CAAC,CAAC,MAAM,GAAG;YACvC,MAAM,CAACY,SAAS,GAAGJ,UAAUK,OAAO,CAAC,CAAC,EAAEb,KAAK,CAAC,CAAC,EAAE,IAAIc,KAAK,CAAC;YAC3D,IAAI,CAACJ,OAAO,CAACE,SAAS,EAAEF,OAAO,CAACE,SAAS,GAAG,CAAC;YAC7CF,OAAO,CAACE,SAAS,CAACJ,UAAUK,OAAO,CAAC,CAAC,EAAEb,KAAK,CAAC,EAAEe,OAAOH,UAAU,CAAC,CAAC,EAAE,IAAI,GAAG;gBAAE,GAAGH,KAAK;YAAC;QACxF,OAAO;YACLP,eAAe,CAACM,UAAU,GAAGC;QAC/B;QAEA,OAAOC;IACT,GAAG,EAAE;IAEL,OAAO;QACLR;QACAC;IACF;AACF,EAAC;AAED,OAAO,MAAMa,cAAc,CAAChB,MAAcG;IACxC,OAAOA,KAAKG,MAAM,CAChB,CAACL,QAAQgB,KAAKC,IAAO,CAAA;YACnB,GAAGjB,MAAM;YACT,GAAGG,OAAOC,OAAO,CAACY,KAAKX,MAAM,CAAC,CAACa,WAAW,CAACC,SAASC,SAAS;gBAC3D,OAAO;oBACL,GAAGF,SAAS;oBACZ,CAAC,CAAC,EAAEnB,KAAK,CAAC,EAAEkB,EAAE,CAAC,EAAEE,QAAQ,CAAC,CAAC,EAAE;wBAAE,GAAGC,QAAQ;oBAAC;gBAC7C;YACF,GAAG,CAAC,EAAE;QACR,CAAA,GACA,CAAC;AAEL,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/forms/Form/types.ts"],"sourcesContent":["import type { Data, Field, FormField, FormState, User } from 'payload'\nimport type React from 'react'\nimport type { Dispatch } from 'react'\n\nexport type Preferences = {\n [key: string]: unknown\n}\n\nexport type FormProps = (\n | {\n action: (formData: FormData) => Promise<void>\n }\n | {\n action?: string\n method?: 'DELETE' | 'GET' | 'PATCH' | 'POST'\n }\n) & {\n beforeSubmit?: ((args: { formState: FormState }) => Promise<FormState>)[]\n children?: React.ReactNode\n className?: string\n disableSuccessStatus?: boolean\n /**\n * If you would like to solely leverage server-side validation on submit,\n * you can disable checks that the form makes before it submits\n */\n disableValidationOnSubmit?: boolean\n disabled?: boolean\n /**\n * By default, the form will get the field schema (not data) from the current document. If you pass this in, you can override that behavior.\n * This is very useful for sub-forms, where the form's field schema is not necessarily the field schema of the current document (e.g. for the Blocks\n * feature of the Lexical Rich Text field)\n */\n fields?: Field[]\n handleResponse?: (\n res: Response,\n successToast: (value: string) => void,\n errorToast: (value: string) => void,\n ) => void\n initialState?: FormState\n isInitializing?: boolean\n log?: boolean\n onChange?: ((args: { formState: FormState }) => Promise<FormState>)[]\n onSubmit?: (fields: FormState, data: Data) => void\n onSuccess?: (json: unknown) => Promise<void> | void\n redirect?: string\n submitted?: boolean\n uuid?: string\n validationOperation?: 'create' | 'update'\n waitForAutocomplete?: boolean\n}\n\nexport type SubmitOptions = {\n action?: string\n method?: string\n overrides?: Record<string, unknown>\n skipValidation?: boolean\n}\n\nexport type DispatchFields = React.Dispatch<any>\nexport type Submit = (\n options?: SubmitOptions,\n e?: React.FormEvent<HTMLFormElement>,\n) => Promise<void>\nexport type ValidateForm = () => Promise<boolean>\nexport type CreateFormData = (overrides?: any) => FormData\nexport type GetFields = () => FormState\nexport type GetField = (path: string) => FormField\nexport type GetData = () => Data\nexport type GetSiblingData = (path: string) => Data\nexport type GetDataByPath = <T = unknown>(path: string) => T\nexport type SetModified = (modified: boolean) => void\nexport type SetSubmitted = (submitted: boolean) => void\nexport type SetProcessing = (processing: boolean) => void\n\nexport type Reset = (data: unknown) => Promise<void>\n\nexport type REPLACE_STATE = {\n optimize?: boolean\n state: FormState\n type: 'REPLACE_STATE'\n}\n\nexport type REMOVE = {\n path: string\n type: 'REMOVE'\n}\n\nexport type MODIFY_CONDITION = {\n path: string\n result: boolean\n type: 'MODIFY_CONDITION'\n user: User\n}\n\nexport type UPDATE = {\n path: string\n type: 'UPDATE'\n} & Partial<FormField>\n\nexport type REMOVE_ROW = {\n path: string\n rowIndex: number\n type: 'REMOVE_ROW'\n}\n\nexport type ADD_ROW = {\n blockType?: string\n path: string\n rowIndex?: number\n subFieldState?: FormState\n type: 'ADD_ROW'\n}\n\nexport type REPLACE_ROW = {\n blockType?: string\n path: string\n rowIndex: number\n subFieldState?: FormState\n type: 'REPLACE_ROW'\n}\n\nexport type DUPLICATE_ROW = {\n path: string\n rowIndex: number\n type: 'DUPLICATE_ROW'\n}\n\nexport type MOVE_ROW = {\n moveFromIndex: number\n moveToIndex: number\n path: string\n type: 'MOVE_ROW'\n}\n\nexport type ADD_SERVER_ERRORS = {\n errors: {\n field: string\n message: string\n }[]\n type: 'ADD_SERVER_ERRORS'\n}\n\nexport type SET_ROW_COLLAPSED = {\n collapsed: boolean\n path: string\n rowID: string\n setDocFieldPreferences: (field: string, fieldPreferences: { [key: string]: unknown }) => void\n type: 'SET_ROW_COLLAPSED'\n}\n\nexport type SET_ALL_ROWS_COLLAPSED = {\n collapsed: boolean\n path: string\n setDocFieldPreferences: (field: string, fieldPreferences: { [key: string]: unknown }) => void\n type: 'SET_ALL_ROWS_COLLAPSED'\n}\n\nexport type FieldAction =\n | ADD_ROW\n | ADD_SERVER_ERRORS\n | DUPLICATE_ROW\n | MODIFY_CONDITION\n | MOVE_ROW\n | REMOVE\n | REMOVE_ROW\n | REPLACE_ROW\n | REPLACE_STATE\n | SET_ALL_ROWS_COLLAPSED\n | SET_ROW_COLLAPSED\n | UPDATE\n\nexport type FormFieldsContext = [FormState, Dispatch<FieldAction>]\n\nexport type Context = {\n addFieldRow: ({\n data,\n path,\n rowIndex,\n schemaPath,\n }: {\n data?: Data\n path: string\n /*\n * by default the new row will be added to the end of the list\n */\n rowIndex?: number\n schemaPath: string\n }) => Promise<void>\n buildRowErrors: () => void\n createFormData: CreateFormData\n disabled: boolean\n dispatchFields: Dispatch<FieldAction>\n /**\n * Form context fields may be outdated and should not be relied on. Instead, prefer `useFormFields`.\n */\n fields: FormState\n formRef: React.MutableRefObject<HTMLFormElement>\n getData: GetData\n getDataByPath: GetDataByPath\n getField: GetField\n getFields: GetFields\n getSiblingData: GetSiblingData\n initializing: boolean\n removeFieldRow: ({ path, rowIndex }: { path: string; rowIndex: number }) => void\n replaceFieldRow: ({\n data,\n path,\n rowIndex,\n schemaPath,\n }: {\n data?: Data\n path: string\n rowIndex: number\n schemaPath: string\n }) => Promise<void>\n replaceState: (state: FormState) => void\n reset: Reset\n setDisabled: (disabled: boolean) => void\n setModified: SetModified\n setProcessing: SetProcessing\n setSubmitted: SetSubmitted\n submit: Submit\n uuid?: string\n validateForm: ValidateForm\n}\n"],"names":[],"
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/Form/types.ts"],"sourcesContent":["import type { Data, Field, FormField, FormState, User } from 'payload'\nimport type React from 'react'\nimport type { Dispatch } from 'react'\n\nexport type Preferences = {\n [key: string]: unknown\n}\n\nexport type FormProps = (\n | {\n action: (formData: FormData) => Promise<void>\n }\n | {\n action?: string\n method?: 'DELETE' | 'GET' | 'PATCH' | 'POST'\n }\n) & {\n beforeSubmit?: ((args: { formState: FormState }) => Promise<FormState>)[]\n children?: React.ReactNode\n className?: string\n disableSuccessStatus?: boolean\n /**\n * If you would like to solely leverage server-side validation on submit,\n * you can disable checks that the form makes before it submits\n */\n disableValidationOnSubmit?: boolean\n disabled?: boolean\n /**\n * By default, the form will get the field schema (not data) from the current document. If you pass this in, you can override that behavior.\n * This is very useful for sub-forms, where the form's field schema is not necessarily the field schema of the current document (e.g. for the Blocks\n * feature of the Lexical Rich Text field)\n */\n fields?: Field[]\n handleResponse?: (\n res: Response,\n successToast: (value: string) => void,\n errorToast: (value: string) => void,\n ) => void\n initialState?: FormState\n isInitializing?: boolean\n log?: boolean\n onChange?: ((args: { formState: FormState }) => Promise<FormState>)[]\n onSubmit?: (fields: FormState, data: Data) => void\n onSuccess?: (json: unknown) => Promise<void> | void\n redirect?: string\n submitted?: boolean\n uuid?: string\n validationOperation?: 'create' | 'update'\n waitForAutocomplete?: boolean\n}\n\nexport type SubmitOptions = {\n action?: string\n method?: string\n overrides?: Record<string, unknown>\n skipValidation?: boolean\n}\n\nexport type DispatchFields = React.Dispatch<any>\nexport type Submit = (\n options?: SubmitOptions,\n e?: React.FormEvent<HTMLFormElement>,\n) => Promise<void>\nexport type ValidateForm = () => Promise<boolean>\nexport type CreateFormData = (overrides?: any) => FormData\nexport type GetFields = () => FormState\nexport type GetField = (path: string) => FormField\nexport type GetData = () => Data\nexport type GetSiblingData = (path: string) => Data\nexport type GetDataByPath = <T = unknown>(path: string) => T\nexport type SetModified = (modified: boolean) => void\nexport type SetSubmitted = (submitted: boolean) => void\nexport type SetProcessing = (processing: boolean) => void\n\nexport type Reset = (data: unknown) => Promise<void>\n\nexport type REPLACE_STATE = {\n optimize?: boolean\n state: FormState\n type: 'REPLACE_STATE'\n}\n\nexport type REMOVE = {\n path: string\n type: 'REMOVE'\n}\n\nexport type MODIFY_CONDITION = {\n path: string\n result: boolean\n type: 'MODIFY_CONDITION'\n user: User\n}\n\nexport type UPDATE = {\n path: string\n type: 'UPDATE'\n} & Partial<FormField>\n\nexport type REMOVE_ROW = {\n path: string\n rowIndex: number\n type: 'REMOVE_ROW'\n}\n\nexport type ADD_ROW = {\n blockType?: string\n path: string\n rowIndex?: number\n subFieldState?: FormState\n type: 'ADD_ROW'\n}\n\nexport type REPLACE_ROW = {\n blockType?: string\n path: string\n rowIndex: number\n subFieldState?: FormState\n type: 'REPLACE_ROW'\n}\n\nexport type DUPLICATE_ROW = {\n path: string\n rowIndex: number\n type: 'DUPLICATE_ROW'\n}\n\nexport type MOVE_ROW = {\n moveFromIndex: number\n moveToIndex: number\n path: string\n type: 'MOVE_ROW'\n}\n\nexport type ADD_SERVER_ERRORS = {\n errors: {\n field: string\n message: string\n }[]\n type: 'ADD_SERVER_ERRORS'\n}\n\nexport type SET_ROW_COLLAPSED = {\n collapsed: boolean\n path: string\n rowID: string\n setDocFieldPreferences: (field: string, fieldPreferences: { [key: string]: unknown }) => void\n type: 'SET_ROW_COLLAPSED'\n}\n\nexport type SET_ALL_ROWS_COLLAPSED = {\n collapsed: boolean\n path: string\n setDocFieldPreferences: (field: string, fieldPreferences: { [key: string]: unknown }) => void\n type: 'SET_ALL_ROWS_COLLAPSED'\n}\n\nexport type FieldAction =\n | ADD_ROW\n | ADD_SERVER_ERRORS\n | DUPLICATE_ROW\n | MODIFY_CONDITION\n | MOVE_ROW\n | REMOVE\n | REMOVE_ROW\n | REPLACE_ROW\n | REPLACE_STATE\n | SET_ALL_ROWS_COLLAPSED\n | SET_ROW_COLLAPSED\n | UPDATE\n\nexport type FormFieldsContext = [FormState, Dispatch<FieldAction>]\n\nexport type Context = {\n addFieldRow: ({\n data,\n path,\n rowIndex,\n schemaPath,\n }: {\n data?: Data\n path: string\n /*\n * by default the new row will be added to the end of the list\n */\n rowIndex?: number\n schemaPath: string\n }) => Promise<void>\n buildRowErrors: () => void\n createFormData: CreateFormData\n disabled: boolean\n dispatchFields: Dispatch<FieldAction>\n /**\n * Form context fields may be outdated and should not be relied on. Instead, prefer `useFormFields`.\n */\n fields: FormState\n formRef: React.MutableRefObject<HTMLFormElement>\n getData: GetData\n getDataByPath: GetDataByPath\n getField: GetField\n getFields: GetFields\n getSiblingData: GetSiblingData\n initializing: boolean\n removeFieldRow: ({ path, rowIndex }: { path: string; rowIndex: number }) => void\n replaceFieldRow: ({\n data,\n path,\n rowIndex,\n schemaPath,\n }: {\n data?: Data\n path: string\n rowIndex: number\n schemaPath: string\n }) => Promise<void>\n replaceState: (state: FormState) => void\n reset: Reset\n setDisabled: (disabled: boolean) => void\n setModified: SetModified\n setProcessing: SetProcessing\n setSubmitted: SetSubmitted\n submit: Submit\n uuid?: string\n validateForm: ValidateForm\n}\n"],"names":[],"mappings":"AA6KA,WAmDC"}
|