payload 0.12.13-beta.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -3
- package/components/forms.ts +2 -1
- package/dist/admin/components/elements/WhereBuilder/Condition/Relationship/types.d.ts +1 -1
- package/dist/admin/components/forms/DraggableSection/SectionTitle/index.js +2 -2
- package/dist/admin/components/forms/field-types/Array/Array.js +2 -2
- package/dist/admin/components/forms/field-types/Blocks/Blocks.js +2 -2
- package/dist/admin/components/forms/field-types/Checkbox/index.js +2 -2
- package/dist/admin/components/forms/field-types/Code/Code.js +2 -2
- package/dist/admin/components/forms/field-types/ConfirmPassword/index.js +2 -2
- package/dist/admin/components/forms/field-types/DateTime/index.js +2 -2
- package/dist/admin/components/forms/field-types/Email/index.js +2 -2
- package/dist/admin/components/forms/field-types/HiddenInput/index.js +2 -2
- package/dist/admin/components/forms/field-types/Number/index.js +2 -2
- package/dist/admin/components/forms/field-types/Password/index.js +2 -2
- package/dist/admin/components/forms/field-types/Point/index.js +2 -2
- package/dist/admin/components/forms/field-types/RadioGroup/index.js +2 -2
- package/dist/admin/components/forms/field-types/Relationship/index.js +2 -2
- package/dist/admin/components/forms/field-types/Relationship/types.d.ts +1 -1
- package/dist/admin/components/forms/field-types/RichText/RichText.js +2 -2
- package/dist/admin/components/forms/field-types/Select/index.js +32 -16
- package/dist/admin/components/forms/field-types/Text/index.js +19 -6
- package/dist/admin/components/forms/field-types/Textarea/index.js +2 -2
- package/dist/admin/components/forms/field-types/Upload/index.js +21 -8
- package/dist/admin/components/forms/useField/index.d.ts +3 -0
- package/dist/admin/components/forms/{useFieldType → useField}/index.js +30 -9
- package/dist/admin/components/forms/{useFieldType → useField}/types.d.ts +0 -0
- package/dist/admin/components/forms/{useFieldType → useField}/types.js +0 -0
- package/dist/admin/components/views/collections/Edit/Auth/APIKey.js +2 -2
- package/dist/admin/components/views/collections/Edit/Upload/index.js +2 -2
- package/dist/admin/components/views/collections/List/types.d.ts +1 -1
- package/dist/bin/generateTypes.js +5 -1
- package/dist/collections/config/types.d.ts +102 -39
- package/dist/collections/operations/create.d.ts +1 -0
- package/dist/collections/operations/create.js +12 -4
- package/dist/collections/operations/delete.js +5 -5
- package/dist/collections/operations/find.d.ts +2 -2
- package/dist/collections/operations/find.js +1 -1
- package/dist/collections/operations/findByID.d.ts +2 -3
- package/dist/collections/operations/findByID.js +1 -1
- package/dist/collections/operations/local/create.d.ts +1 -0
- package/dist/collections/operations/local/create.js +3 -2
- package/dist/collections/operations/local/delete.d.ts +2 -1
- package/dist/collections/operations/local/delete.js +1 -1
- package/dist/collections/operations/local/find.d.ts +2 -2
- package/dist/collections/operations/local/find.js +1 -1
- package/dist/collections/operations/local/findByID.d.ts +2 -1
- package/dist/collections/operations/local/findByID.js +1 -1
- package/dist/collections/operations/local/update.d.ts +2 -1
- package/dist/collections/operations/local/update.js +1 -1
- package/dist/collections/operations/update.js +11 -3
- package/dist/collections/requestHandlers/find.d.ts +2 -2
- package/dist/collections/requestHandlers/find.js +1 -1
- package/dist/config/types.d.ts +3 -0
- package/dist/fields/baseFields/getBaseUploadFields.js +2 -1
- package/dist/fields/config/types.d.ts +20 -15
- package/dist/fields/config/types.js +1 -1
- package/dist/fields/validations.d.ts +17 -17
- package/dist/index.d.ts +8 -9
- package/dist/index.js +1 -1
- package/dist/mongoose/buildQuery.js +6 -2
- package/dist/uploads/fileExists.d.ts +2 -2
- package/dist/uploads/fileExists.js +4 -3
- package/dist/uploads/fileOrDocExists.d.ts +3 -0
- package/dist/uploads/fileOrDocExists.js +22 -0
- package/dist/uploads/getSafeFilename.d.ts +2 -1
- package/dist/uploads/getSafeFilename.js +4 -4
- package/dist/uploads/imageResizer.d.ts +11 -1
- package/dist/uploads/imageResizer.js +2 -2
- package/dist/utilities/sanitizeInternalFields.d.ts +2 -1
- package/dist/utilities/sanitizeInternalFields.js +1 -1
- package/docs/admin/components.mdx +3 -3
- package/docs/fields/blocks.mdx +9 -0
- package/docs/fields/overview.mdx +12 -0
- package/docs/fields/rich-text.mdx +11 -0
- package/docs/hooks/collections.mdx +23 -0
- package/docs/hooks/fields.mdx +28 -0
- package/docs/hooks/globals.mdx +17 -0
- package/docs/typescript/generating-types.mdx +114 -0
- package/docs/typescript/overview.mdx +36 -0
- package/package.json +1 -1
- package/types.d.ts +18 -2
- package/dist/admin/components/forms/useFieldType/index.d.ts +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
# [0.13.0](https://github.com/payloadcms/payload/compare/v0.12.3...v0.13.0) (2021-11-26)
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
### Bug Fixes
|
|
5
5
|
|
|
6
6
|
* [#351](https://github.com/payloadcms/payload/issues/351) ([94c2b8d](https://github.com/payloadcms/payload/commit/94c2b8d80b046c067057d4ad089ed6a2edd656cf))
|
|
7
|
+
* [#358](https://github.com/payloadcms/payload/issues/358) - reuploading with existing filenames ([a0fb48c](https://github.com/payloadcms/payload/commit/a0fb48c9a37beceafc6f0638604e9946d0814635))
|
|
7
8
|
* allows sync or async preview urls ([da6e1df](https://github.com/payloadcms/payload/commit/da6e1df293ce46bc4d0c84645db61feea2881aa7))
|
|
8
9
|
* bug with relationship cell when no doc is available ([40b33d9](https://github.com/payloadcms/payload/commit/40b33d9f5e99285cb0de148dbe059259817fcad8))
|
|
9
10
|
* ensures 'like' query param remains functional in all cases ([20d4e72](https://github.com/payloadcms/payload/commit/20d4e72a951dfcbf1cc301d0938e5095932436b9))
|
|
10
11
|
* ensures buildQuery works with fields as well as simultaneous or / and ([72fc413](https://github.com/payloadcms/payload/commit/72fc413764c6c42ba64a45f01d99b68ad3bd46c4))
|
|
12
|
+
* ensures non-localized relationships with many relationTos can be queried ([7050b52](https://github.com/payloadcms/payload/commit/7050b5285e65a709a0bdfb68e8403839ef75151f))
|
|
11
13
|
* ensures relationship field search can return more than 10 options ([57c0346](https://github.com/payloadcms/payload/commit/57c0346a00286a3df695ea46e5c2630494183b5b))
|
|
12
14
|
* ensures richtext links retain proper formatting ([abf61d0](https://github.com/payloadcms/payload/commit/abf61d0734c09fd0fc5c5b827cb0631e11701f71))
|
|
13
15
|
* ensures tquerying by relationship subpaths works ([37b21b0](https://github.com/payloadcms/payload/commit/37b21b07628e892e85c2cf979d9e2c8af0d291f7))
|
|
14
16
|
* ensures uploads can be fetched with CORS ([96421b3](https://github.com/payloadcms/payload/commit/96421b3d59a87f8a3d781005c02344fe5d3a607f))
|
|
15
17
|
* issue with querying by id and using comma-separated values ([d9e1b5e](https://github.com/payloadcms/payload/commit/d9e1b5ede33616893f9ba6990eeccf5410b75ae1))
|
|
18
|
+
* typing for collection description ([bb18e82](https://github.com/payloadcms/payload/commit/bb18e8250c5742d9615e5780c1cd02d33ecca3d0))
|
|
16
19
|
* updates field description type to include react nodes ([291c193](https://github.com/payloadcms/payload/commit/291c193ad4a9ec8ce9310cc63c714eba10eca102))
|
|
17
20
|
|
|
18
21
|
|
|
@@ -26,13 +29,18 @@
|
|
|
26
29
|
* baseline type generation ([5a965d2](https://github.com/payloadcms/payload/commit/5a965d2263d1b246149c5220d039a6d97953d5e8))
|
|
27
30
|
* ensures update hooks have access to full original docs even in spite of access control ([b2c5b7e](https://github.com/payloadcms/payload/commit/b2c5b7e5752e829c7a53c054decceb43ec33065e))
|
|
28
31
|
* finishes typing all fields ([ed5a5eb](https://github.com/payloadcms/payload/commit/ed5a5ebe7e16d20577556ab233032a52bef6d2cb))
|
|
32
|
+
* further types field based functions ([6b150e0](https://github.com/payloadcms/payload/commit/6b150e01d306fde5686156a2fa6a8fa00aeffe0e))
|
|
29
33
|
* generates further field types ([2ca76ba](https://github.com/payloadcms/payload/commit/2ca76ba8ce6c61ee7b0a01a557b6f013ca483d6d))
|
|
30
34
|
* improves querying logic ([4c85747](https://github.com/payloadcms/payload/commit/4c8574784995b1cb1f939648f4d2158286089b3d))
|
|
31
35
|
* indexes filenames ([5d43262](https://github.com/payloadcms/payload/commit/5d43262f42e0529a44572f398aa1ec5fd7858286))
|
|
32
36
|
* migrates admin preview to async ([40ca3da](https://github.com/payloadcms/payload/commit/40ca3dae61f8ddf05363b6cad426deba4cde1e30))
|
|
37
|
+
* more typing of generics, better commenting of properties ([820b6ad](https://github.com/payloadcms/payload/commit/820b6ad4c777ff3197091f323ae0ba9993df28f5))
|
|
38
|
+
* renames useFieldType to useField ([0245747](https://github.com/payloadcms/payload/commit/0245747020c7c039b15d055f54a4548a364d047e))
|
|
39
|
+
* smarter generics ([b99eb8b](https://github.com/payloadcms/payload/commit/b99eb8ba739b903c7012ae69a51af6f77295cfa3))
|
|
40
|
+
* supports custom onChange handling in text, select, and upload fields ([4affdc3](https://github.com/payloadcms/payload/commit/4affdc3a9397d70f5baacdd12753c8fc8c7d8368))
|
|
41
|
+
* type payload operation calls with generics ([f258c59](https://github.com/payloadcms/payload/commit/f258c5904eb98db5784d4b6cdf1324736c1fe88d))
|
|
33
42
|
|
|
34
|
-
## [0.12.
|
|
35
|
-
|
|
43
|
+
## [0.12.13-beta.0](https://github.com/payloadcms/payload/compare/v0.12.3...v0.12.13-beta.0) (2021-11-24)
|
|
36
44
|
|
|
37
45
|
### Bug Fixes
|
|
38
46
|
|
|
@@ -56,6 +64,7 @@
|
|
|
56
64
|
* improves querying logic ([4c85747](https://github.com/payloadcms/payload/commit/4c8574784995b1cb1f939648f4d2158286089b3d))
|
|
57
65
|
* indexes filenames ([5d43262](https://github.com/payloadcms/payload/commit/5d43262f42e0529a44572f398aa1ec5fd7858286))
|
|
58
66
|
* migrates admin preview to async ([40ca3da](https://github.com/payloadcms/payload/commit/40ca3dae61f8ddf05363b6cad426deba4cde1e30))
|
|
67
|
+
* ensures uploads can be fetched with CORS ([96421b3](https://github.com/payloadcms/payload/commit/96421b3d59a87f8a3d781005c02344fe5d3a607f))
|
|
59
68
|
|
|
60
69
|
## [0.12.3](https://github.com/payloadcms/payload/compare/v0.12.2...v0.12.3) (2021-10-23)
|
|
61
70
|
|
package/components/forms.ts
CHANGED
|
@@ -6,7 +6,8 @@ export {
|
|
|
6
6
|
useFormModified,
|
|
7
7
|
} from '../dist/admin/components/forms/Form/context';
|
|
8
8
|
|
|
9
|
-
export { default as
|
|
9
|
+
export { default as useField } from '../dist/admin/components/forms/useField';
|
|
10
|
+
export { default as useFieldType } from '../dist/admin/components/forms/useField';
|
|
10
11
|
|
|
11
12
|
export { default as Form } from '../dist/admin/components/forms/Form';
|
|
12
13
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import useField from '../../useField';
|
|
3
3
|
import Pill from '../../../elements/Pill';
|
|
4
4
|
import './index.scss';
|
|
5
5
|
const baseClass = 'section-title';
|
|
6
6
|
const SectionTitle = (props) => {
|
|
7
7
|
const { label, path, readOnly } = props;
|
|
8
|
-
const { value, setValue } =
|
|
8
|
+
const { value, setValue } = useField({ path });
|
|
9
9
|
const classes = [
|
|
10
10
|
baseClass,
|
|
11
11
|
].filter(Boolean).join(' ');
|
|
@@ -6,7 +6,7 @@ import DraggableSection from '../../DraggableSection';
|
|
|
6
6
|
import reducer from '../rowReducer';
|
|
7
7
|
import { useForm } from '../../Form/context';
|
|
8
8
|
import buildStateFromSchema from '../../Form/buildStateFromSchema';
|
|
9
|
-
import
|
|
9
|
+
import useField from '../../useField';
|
|
10
10
|
import Error from '../../Error';
|
|
11
11
|
import { array } from '../../../../../fields/validations';
|
|
12
12
|
import Banner from '../../../elements/Banner';
|
|
@@ -36,7 +36,7 @@ const ArrayFieldType = (props) => {
|
|
|
36
36
|
return validationResult;
|
|
37
37
|
}, [validate, maxRows, minRows, required]);
|
|
38
38
|
const [disableFormData, setDisableFormData] = useState(false);
|
|
39
|
-
const { showError, errorMessage, value, setValue, } =
|
|
39
|
+
const { showError, errorMessage, value, setValue, } = useField({
|
|
40
40
|
path,
|
|
41
41
|
validate: memoizedValidate,
|
|
42
42
|
disableFormData,
|
|
@@ -9,7 +9,7 @@ import { useForm } from '../../Form/context';
|
|
|
9
9
|
import buildStateFromSchema from '../../Form/buildStateFromSchema';
|
|
10
10
|
import DraggableSection from '../../DraggableSection';
|
|
11
11
|
import Error from '../../Error';
|
|
12
|
-
import
|
|
12
|
+
import useField from '../../useField';
|
|
13
13
|
import Popup from '../../../elements/Popup';
|
|
14
14
|
import BlockSelector from './BlockSelector';
|
|
15
15
|
import { blocks as blocksValidator } from '../../../../../fields/validations';
|
|
@@ -36,7 +36,7 @@ const Blocks = (props) => {
|
|
|
36
36
|
return validationResult;
|
|
37
37
|
}, [validate, maxRows, minRows, labels, blocks, required]);
|
|
38
38
|
const [disableFormData, setDisableFormData] = useState(false);
|
|
39
|
-
const { showError, errorMessage, value, setValue, } =
|
|
39
|
+
const { showError, errorMessage, value, setValue, } = useField({
|
|
40
40
|
path,
|
|
41
41
|
validate: memoizedValidate,
|
|
42
42
|
disableFormData,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import useField from '../../useField';
|
|
3
3
|
import withCondition from '../../withCondition';
|
|
4
4
|
import Error from '../../Error';
|
|
5
5
|
import { checkbox } from '../../../../../fields/validations';
|
|
@@ -14,7 +14,7 @@ const Checkbox = (props) => {
|
|
|
14
14
|
const validationResult = validate(value, { required });
|
|
15
15
|
return validationResult;
|
|
16
16
|
}, [validate, required]);
|
|
17
|
-
const { value, showError, errorMessage, setValue, } =
|
|
17
|
+
const { value, showError, errorMessage, setValue, } = useField({
|
|
18
18
|
path,
|
|
19
19
|
validate: memoizedValidate,
|
|
20
20
|
disableFormData,
|
|
@@ -3,7 +3,7 @@ import Editor from 'react-simple-code-editor';
|
|
|
3
3
|
import { highlight, languages } from 'prismjs/components/prism-core';
|
|
4
4
|
import 'prismjs/components/prism-clike';
|
|
5
5
|
import 'prismjs/components/prism-javascript';
|
|
6
|
-
import
|
|
6
|
+
import useField from '../../useField';
|
|
7
7
|
import withCondition from '../../withCondition';
|
|
8
8
|
import Label from '../../Label';
|
|
9
9
|
import Error from '../../Error';
|
|
@@ -23,7 +23,7 @@ const Code = (props) => {
|
|
|
23
23
|
const validationResult = validate(value, { minLength, maxLength, required });
|
|
24
24
|
return validationResult;
|
|
25
25
|
}, [validate, maxLength, minLength, required]);
|
|
26
|
-
const { value, showError, setValue, errorMessage, } =
|
|
26
|
+
const { value, showError, setValue, errorMessage, } = useField({
|
|
27
27
|
path,
|
|
28
28
|
validate: memoizedValidate,
|
|
29
29
|
enableDebouncedValue: true,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import useField from '../../useField';
|
|
3
3
|
import Label from '../../Label';
|
|
4
4
|
import Error from '../../Error';
|
|
5
5
|
import { useWatchForm } from '../../Form/context';
|
|
@@ -13,7 +13,7 @@ const ConfirmPassword = () => {
|
|
|
13
13
|
}
|
|
14
14
|
return 'Passwords do not match.';
|
|
15
15
|
}, [password]);
|
|
16
|
-
const { value, showError, setValue, errorMessage, } =
|
|
16
|
+
const { value, showError, setValue, errorMessage, } = useField({
|
|
17
17
|
path: 'confirm-password',
|
|
18
18
|
disableFormData: true,
|
|
19
19
|
validate,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
import DatePicker from '../../../elements/DatePicker';
|
|
3
3
|
import withCondition from '../../withCondition';
|
|
4
|
-
import
|
|
4
|
+
import useField from '../../useField';
|
|
5
5
|
import Label from '../../Label';
|
|
6
6
|
import Error from '../../Error';
|
|
7
7
|
import FieldDescription from '../../FieldDescription';
|
|
@@ -15,7 +15,7 @@ const DateTime = (props) => {
|
|
|
15
15
|
const validationResult = validate(value, { required });
|
|
16
16
|
return validationResult;
|
|
17
17
|
}, [validate, required]);
|
|
18
|
-
const { value, showError, errorMessage, setValue, } =
|
|
18
|
+
const { value, showError, errorMessage, setValue, } = useField({
|
|
19
19
|
path,
|
|
20
20
|
validate: memoizedValidate,
|
|
21
21
|
condition,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
import withCondition from '../../withCondition';
|
|
3
|
-
import
|
|
3
|
+
import useField from '../../useField';
|
|
4
4
|
import Label from '../../Label';
|
|
5
5
|
import Error from '../../Error';
|
|
6
6
|
import FieldDescription from '../../FieldDescription';
|
|
@@ -13,7 +13,7 @@ const Email = (props) => {
|
|
|
13
13
|
const validationResult = validate(value, { required });
|
|
14
14
|
return validationResult;
|
|
15
15
|
}, [validate, required]);
|
|
16
|
-
const fieldType =
|
|
16
|
+
const fieldType = useField({
|
|
17
17
|
path,
|
|
18
18
|
validate: memoizedValidate,
|
|
19
19
|
enableDebouncedValue: true,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import useField from '../../useField';
|
|
3
3
|
import withCondition from '../../withCondition';
|
|
4
4
|
const HiddenInput = (props) => {
|
|
5
5
|
const { name, path: pathFromProps, value: valueFromProps, modifyForm = true, } = props;
|
|
6
6
|
const path = pathFromProps || name;
|
|
7
|
-
const { value, setValue } =
|
|
7
|
+
const { value, setValue } = useField({
|
|
8
8
|
path,
|
|
9
9
|
});
|
|
10
10
|
useEffect(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import useField from '../../useField';
|
|
3
3
|
import Label from '../../Label';
|
|
4
4
|
import Error from '../../Error';
|
|
5
5
|
import FieldDescription from '../../FieldDescription';
|
|
@@ -13,7 +13,7 @@ const NumberField = (props) => {
|
|
|
13
13
|
const validationResult = validate(value, { min, max, required });
|
|
14
14
|
return validationResult;
|
|
15
15
|
}, [validate, max, min, required]);
|
|
16
|
-
const { value, showError, setValue, errorMessage, } =
|
|
16
|
+
const { value, showError, setValue, errorMessage, } = useField({
|
|
17
17
|
path,
|
|
18
18
|
validate: memoizedValidate,
|
|
19
19
|
enableDebouncedValue: true,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import useField from '../../useField';
|
|
3
3
|
import Label from '../../Label';
|
|
4
4
|
import Error from '../../Error';
|
|
5
5
|
import withCondition from '../../withCondition';
|
|
@@ -12,7 +12,7 @@ const Password = (props) => {
|
|
|
12
12
|
const validationResult = validate(value, { required });
|
|
13
13
|
return validationResult;
|
|
14
14
|
}, [validate, required]);
|
|
15
|
-
const { value, showError, formProcessing, setValue, errorMessage, } =
|
|
15
|
+
const { value, showError, formProcessing, setValue, errorMessage, } = useField({
|
|
16
16
|
path,
|
|
17
17
|
validate: memoizedValidate,
|
|
18
18
|
enableDebouncedValue: true,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import useField from '../../useField';
|
|
3
3
|
import Label from '../../Label';
|
|
4
4
|
import Error from '../../Error';
|
|
5
5
|
import FieldDescription from '../../FieldDescription';
|
|
@@ -14,7 +14,7 @@ const PointField = (props) => {
|
|
|
14
14
|
const validationResult = validate(value, { required });
|
|
15
15
|
return validationResult;
|
|
16
16
|
}, [validate, required]);
|
|
17
|
-
const { value = [null, null], showError, setValue, errorMessage, } =
|
|
17
|
+
const { value = [null, null], showError, setValue, errorMessage, } = useField({
|
|
18
18
|
path,
|
|
19
19
|
validate: memoizedValidate,
|
|
20
20
|
enableDebouncedValue: true,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import useField from '../../useField';
|
|
3
3
|
import withCondition from '../../withCondition';
|
|
4
4
|
import Error from '../../Error';
|
|
5
5
|
import Label from '../../Label';
|
|
@@ -16,7 +16,7 @@ const RadioGroup = (props) => {
|
|
|
16
16
|
const validationResult = validate(value, { required, options });
|
|
17
17
|
return validationResult;
|
|
18
18
|
}, [validate, required, options]);
|
|
19
|
-
const { value, showError, errorMessage, setValue, } =
|
|
19
|
+
const { value, showError, errorMessage, setValue, } = useField({
|
|
20
20
|
path,
|
|
21
21
|
validate: memoizedValidate,
|
|
22
22
|
condition,
|
|
@@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useState, useReducer, } from 'react';
|
|
|
2
2
|
import { useConfig } from '@payloadcms/config-provider';
|
|
3
3
|
import withCondition from '../../withCondition';
|
|
4
4
|
import ReactSelect from '../../../elements/ReactSelect';
|
|
5
|
-
import
|
|
5
|
+
import useField from '../../useField';
|
|
6
6
|
import Label from '../../Label';
|
|
7
7
|
import Error from '../../Error';
|
|
8
8
|
import FieldDescription from '../../FieldDescription';
|
|
@@ -29,7 +29,7 @@ const Relationship = (props) => {
|
|
|
29
29
|
const validationResult = validate(value, { required });
|
|
30
30
|
return validationResult;
|
|
31
31
|
}, [validate, required]);
|
|
32
|
-
const { value, showError, errorMessage, setValue, } =
|
|
32
|
+
const { value, showError, errorMessage, setValue, } = useField({
|
|
33
33
|
path: path || name,
|
|
34
34
|
validate: memoizedValidate,
|
|
35
35
|
condition,
|
|
@@ -4,7 +4,7 @@ import { createEditor, Transforms, Node, Element as SlateElement, Text } from 's
|
|
|
4
4
|
import { Editable, withReact, Slate } from 'slate-react';
|
|
5
5
|
import { withHistory } from 'slate-history';
|
|
6
6
|
import { richText } from '../../../../../fields/validations';
|
|
7
|
-
import
|
|
7
|
+
import useField from '../../useField';
|
|
8
8
|
import withCondition from '../../withCondition';
|
|
9
9
|
import Label from '../../Label';
|
|
10
10
|
import Error from '../../Error';
|
|
@@ -53,7 +53,7 @@ const RichText = (props) => {
|
|
|
53
53
|
const validationResult = validate(value, { required });
|
|
54
54
|
return validationResult;
|
|
55
55
|
}, [validate, required]);
|
|
56
|
-
const fieldType =
|
|
56
|
+
const fieldType = useField({
|
|
57
57
|
path,
|
|
58
58
|
validate: memoizedValidate,
|
|
59
59
|
stringify: true,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useCallback, useState } from 'react';
|
|
2
2
|
import withCondition from '../../withCondition';
|
|
3
3
|
import ReactSelect from '../../../elements/ReactSelect';
|
|
4
|
-
import
|
|
4
|
+
import useField from '../../useField';
|
|
5
5
|
import Label from '../../Label';
|
|
6
6
|
import Error from '../../Error';
|
|
7
7
|
import FieldDescription from '../../FieldDescription';
|
|
@@ -18,18 +18,45 @@ const formatOptions = (options) => options.map((option) => {
|
|
|
18
18
|
};
|
|
19
19
|
});
|
|
20
20
|
const Select = (props) => {
|
|
21
|
-
const { path: pathFromProps, name, required, validate = select, label, options: optionsFromProps, hasMany, admin: { readOnly, style, width, description, condition, } = {}, } = props;
|
|
21
|
+
const { path: pathFromProps, name, required, validate = select, label, options: optionsFromProps, hasMany, admin: { readOnly, style, width, description, condition, } = {}, value: valueFromProps, onChange: onChangeFromProps } = props;
|
|
22
22
|
const path = pathFromProps || name;
|
|
23
23
|
const [options] = useState(formatOptions(optionsFromProps));
|
|
24
24
|
const memoizedValidate = useCallback((value) => {
|
|
25
25
|
const validationResult = validate(value, { required, options });
|
|
26
26
|
return validationResult;
|
|
27
27
|
}, [validate, required, options]);
|
|
28
|
-
const { value, showError, setValue, errorMessage, } =
|
|
28
|
+
const { value: valueFromContext, showError, setValue, errorMessage, } = useField({
|
|
29
29
|
path,
|
|
30
30
|
validate: memoizedValidate,
|
|
31
31
|
condition,
|
|
32
32
|
});
|
|
33
|
+
const onChange = useCallback((selectedOption) => {
|
|
34
|
+
if (!readOnly) {
|
|
35
|
+
let newValue;
|
|
36
|
+
if (hasMany) {
|
|
37
|
+
if (Array.isArray(selectedOption)) {
|
|
38
|
+
newValue = selectedOption.map((option) => option.value);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
newValue = [];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
newValue = selectedOption.value;
|
|
46
|
+
}
|
|
47
|
+
if (typeof onChangeFromProps === 'function') {
|
|
48
|
+
onChangeFromProps(newValue);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
setValue(newValue);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, [
|
|
55
|
+
readOnly,
|
|
56
|
+
hasMany,
|
|
57
|
+
onChangeFromProps,
|
|
58
|
+
setValue
|
|
59
|
+
]);
|
|
33
60
|
const classes = [
|
|
34
61
|
'field-type',
|
|
35
62
|
baseClass,
|
|
@@ -37,6 +64,7 @@ const Select = (props) => {
|
|
|
37
64
|
readOnly && `${baseClass}--read-only`,
|
|
38
65
|
].filter(Boolean).join(' ');
|
|
39
66
|
let valueToRender;
|
|
67
|
+
const value = valueFromProps || valueFromContext || '';
|
|
40
68
|
if (hasMany && Array.isArray(value)) {
|
|
41
69
|
valueToRender = value.map((val) => options.find((option) => option.value === val));
|
|
42
70
|
}
|
|
@@ -49,19 +77,7 @@ const Select = (props) => {
|
|
|
49
77
|
} },
|
|
50
78
|
React.createElement(Error, { showError: showError, message: errorMessage }),
|
|
51
79
|
React.createElement(Label, { htmlFor: path, label: label, required: required }),
|
|
52
|
-
React.createElement(ReactSelect, { onChange:
|
|
53
|
-
if (hasMany) {
|
|
54
|
-
if (Array.isArray(selectedOption)) {
|
|
55
|
-
setValue(selectedOption.map((option) => option.value));
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
setValue([]);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
setValue(selectedOption.value);
|
|
63
|
-
}
|
|
64
|
-
} : undefined, value: valueToRender, showError: showError, isDisabled: readOnly, options: options, isMulti: hasMany }),
|
|
80
|
+
React.createElement(ReactSelect, { onChange: onChange, value: valueToRender, showError: showError, isDisabled: readOnly, options: options, isMulti: hasMany }),
|
|
65
81
|
React.createElement(FieldDescription, { value: value, description: description })));
|
|
66
82
|
};
|
|
67
83
|
export default withCondition(Select);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import useField from '../../useField';
|
|
3
3
|
import withCondition from '../../withCondition';
|
|
4
4
|
import Label from '../../Label';
|
|
5
5
|
import Error from '../../Error';
|
|
@@ -7,28 +7,41 @@ import { text } from '../../../../../fields/validations';
|
|
|
7
7
|
import FieldDescription from '../../FieldDescription';
|
|
8
8
|
import './index.scss';
|
|
9
9
|
const Text = (props) => {
|
|
10
|
-
const { path: pathFromProps, name, required, validate = text, label, admin: { placeholder, readOnly, style, width, description, condition, } = {}, } = props;
|
|
10
|
+
const { path: pathFromProps, name, required, validate = text, label, admin: { placeholder, readOnly, style, width, description, condition, } = {}, value: valueFromProps, onChange: onChangeFromProps, } = props;
|
|
11
11
|
const path = pathFromProps || name;
|
|
12
|
-
const fieldType =
|
|
12
|
+
const fieldType = useField({
|
|
13
13
|
path,
|
|
14
14
|
validate,
|
|
15
15
|
enableDebouncedValue: true,
|
|
16
16
|
condition,
|
|
17
17
|
});
|
|
18
|
-
const { value, showError, setValue, errorMessage, } = fieldType;
|
|
18
|
+
const { value: valueFromContext, showError, setValue, errorMessage, } = fieldType;
|
|
19
|
+
const onChange = useCallback((e) => {
|
|
20
|
+
const { value: incomingValue } = e.target;
|
|
21
|
+
if (typeof onChangeFromProps === 'function') {
|
|
22
|
+
onChangeFromProps(incomingValue);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
setValue(e);
|
|
26
|
+
}
|
|
27
|
+
}, [
|
|
28
|
+
onChangeFromProps,
|
|
29
|
+
setValue,
|
|
30
|
+
]);
|
|
19
31
|
const classes = [
|
|
20
32
|
'field-type',
|
|
21
33
|
'text',
|
|
22
34
|
showError && 'error',
|
|
23
35
|
readOnly && 'read-only',
|
|
24
36
|
].filter(Boolean).join(' ');
|
|
37
|
+
const value = valueFromProps || valueFromContext || '';
|
|
25
38
|
return (React.createElement("div", { className: classes, style: {
|
|
26
39
|
...style,
|
|
27
40
|
width,
|
|
28
41
|
} },
|
|
29
42
|
React.createElement(Error, { showError: showError, message: errorMessage }),
|
|
30
43
|
React.createElement(Label, { htmlFor: path, label: label, required: required }),
|
|
31
|
-
React.createElement("input", { value: value
|
|
44
|
+
React.createElement("input", { value: value, onChange: onChange, disabled: readOnly, placeholder: placeholder, type: "text", id: path, name: path }),
|
|
32
45
|
React.createElement(FieldDescription, { value: value, description: description })));
|
|
33
46
|
};
|
|
34
47
|
export default withCondition(Text);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import useField from '../../useField';
|
|
3
3
|
import withCondition from '../../withCondition';
|
|
4
4
|
import Label from '../../Label';
|
|
5
5
|
import Error from '../../Error';
|
|
@@ -13,7 +13,7 @@ const Textarea = (props) => {
|
|
|
13
13
|
const validationResult = validate(value, { minLength, maxLength, required });
|
|
14
14
|
return validationResult;
|
|
15
15
|
}, [validate, maxLength, minLength, required]);
|
|
16
|
-
const { value, showError, setValue, errorMessage, } =
|
|
16
|
+
const { value, showError, setValue, errorMessage, } = useField({
|
|
17
17
|
path,
|
|
18
18
|
validate: memoizedValidate,
|
|
19
19
|
enableDebouncedValue: true,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useState, useEffect, useCallback } from 'react';
|
|
2
2
|
import { useModal } from '@faceless-ui/modal';
|
|
3
3
|
import { useConfig } from '@payloadcms/config-provider';
|
|
4
|
-
import
|
|
4
|
+
import useField from '../../useField';
|
|
5
5
|
import withCondition from '../../withCondition';
|
|
6
6
|
import Button from '../../../elements/Button';
|
|
7
7
|
import Label from '../../Label';
|
|
@@ -18,7 +18,7 @@ const Upload = (props) => {
|
|
|
18
18
|
const [internalValue, setInternalValue] = useState(undefined);
|
|
19
19
|
const [missingFile, setMissingFile] = useState(false);
|
|
20
20
|
const { collections, serverURL, routes: { api } } = useConfig();
|
|
21
|
-
const { path: pathFromProps, name, required, admin: { readOnly, style, width, description, condition, } = {}, label, validate = upload, relationTo, fieldTypes, } = props;
|
|
21
|
+
const { path: pathFromProps, name, required, admin: { readOnly, style, width, description, condition, } = {}, label, validate = upload, relationTo, fieldTypes, value: valueFromProps, onChange: onChangeFromProps, } = props;
|
|
22
22
|
const collection = collections.find((coll) => coll.slug === relationTo);
|
|
23
23
|
const path = pathFromProps || name;
|
|
24
24
|
const addModalSlug = `${path}-add`;
|
|
@@ -27,12 +27,13 @@ const Upload = (props) => {
|
|
|
27
27
|
const validationResult = validate(value, { required });
|
|
28
28
|
return validationResult;
|
|
29
29
|
}, [validate, required]);
|
|
30
|
-
const fieldType =
|
|
30
|
+
const fieldType = useField({
|
|
31
31
|
path,
|
|
32
32
|
validate: memoizedValidate,
|
|
33
33
|
condition,
|
|
34
34
|
});
|
|
35
|
-
const { value, showError, setValue, errorMessage, } = fieldType;
|
|
35
|
+
const { value: valueFromContext, showError, setValue, errorMessage, } = fieldType;
|
|
36
|
+
const value = valueFromProps || valueFromContext || '';
|
|
36
37
|
const classes = [
|
|
37
38
|
'field-type',
|
|
38
39
|
baseClass,
|
|
@@ -49,13 +50,27 @@ const Upload = (props) => {
|
|
|
49
50
|
}
|
|
50
51
|
else {
|
|
51
52
|
setInternalValue(undefined);
|
|
52
|
-
setValue(null);
|
|
53
53
|
setMissingFile(true);
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
fetchFile();
|
|
57
57
|
}
|
|
58
|
-
}, [
|
|
58
|
+
}, [
|
|
59
|
+
value,
|
|
60
|
+
relationTo,
|
|
61
|
+
api,
|
|
62
|
+
serverURL,
|
|
63
|
+
setValue
|
|
64
|
+
]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const { id: incomingID } = internalValue || {};
|
|
67
|
+
if (typeof onChangeFromProps === 'function') {
|
|
68
|
+
onChangeFromProps(incomingID);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
setValue(incomingID);
|
|
72
|
+
}
|
|
73
|
+
}, [internalValue]);
|
|
59
74
|
return (React.createElement("div", { className: classes, style: {
|
|
60
75
|
...style,
|
|
61
76
|
width,
|
|
@@ -83,7 +98,6 @@ const Upload = (props) => {
|
|
|
83
98
|
fieldTypes,
|
|
84
99
|
setValue: (val) => {
|
|
85
100
|
setMissingFile(false);
|
|
86
|
-
setValue(val.id);
|
|
87
101
|
setInternalValue(val);
|
|
88
102
|
},
|
|
89
103
|
} }),
|
|
@@ -92,7 +106,6 @@ const Upload = (props) => {
|
|
|
92
106
|
slug: selectExistingModalSlug,
|
|
93
107
|
setValue: (val) => {
|
|
94
108
|
setMissingFile(false);
|
|
95
|
-
setValue(val.id);
|
|
96
109
|
setInternalValue(val);
|
|
97
110
|
},
|
|
98
111
|
addModalSlug,
|