payload 0.12.10-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 +28 -23
- package/components/forms.ts +2 -1
- package/dist/admin/components/elements/PreviewButton/index.js +19 -4
- 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/FieldDescription/types.d.ts +1 -2
- package/dist/admin/components/forms/FieldDescription/types.js +11 -3
- package/dist/admin/components/forms/field-types/Array/Array.js +2 -2
- package/dist/admin/components/forms/field-types/Array/types.d.ts +2 -1
- package/dist/admin/components/forms/field-types/Blocks/Blocks.js +2 -2
- package/dist/admin/components/forms/field-types/Blocks/types.d.ts +2 -1
- 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/Password/types.d.ts +2 -1
- 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/auth/getExecuteStaticAccess.d.ts +1 -1
- package/dist/auth/getExecuteStaticAccess.js +20 -4
- package/dist/bin/generateTypes.js +20 -10
- 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 +15 -8
- 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 +4 -1
- package/dist/express/static.js +2 -2
- package/dist/fields/baseFields/getBaseUploadFields.js +3 -1
- package/dist/fields/config/types.d.ts +21 -16
- 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 +14 -11
- package/dist/mongoose/buildSchema.js +6 -1
- package/dist/mongoose/sanitizeFormattedValue.js +18 -22
- 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/uploads/isImage.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,29 +1,46 @@
|
|
|
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))
|
|
8
|
+
* allows sync or async preview urls ([da6e1df](https://github.com/payloadcms/payload/commit/da6e1df293ce46bc4d0c84645db61feea2881aa7))
|
|
7
9
|
* bug with relationship cell when no doc is available ([40b33d9](https://github.com/payloadcms/payload/commit/40b33d9f5e99285cb0de148dbe059259817fcad8))
|
|
8
10
|
* ensures 'like' query param remains functional in all cases ([20d4e72](https://github.com/payloadcms/payload/commit/20d4e72a951dfcbf1cc301d0938e5095932436b9))
|
|
9
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))
|
|
10
13
|
* ensures relationship field search can return more than 10 options ([57c0346](https://github.com/payloadcms/payload/commit/57c0346a00286a3df695ea46e5c2630494183b5b))
|
|
11
14
|
* ensures richtext links retain proper formatting ([abf61d0](https://github.com/payloadcms/payload/commit/abf61d0734c09fd0fc5c5b827cb0631e11701f71))
|
|
12
15
|
* ensures tquerying by relationship subpaths works ([37b21b0](https://github.com/payloadcms/payload/commit/37b21b07628e892e85c2cf979d9e2c8af0d291f7))
|
|
16
|
+
* ensures uploads can be fetched with CORS ([96421b3](https://github.com/payloadcms/payload/commit/96421b3d59a87f8a3d781005c02344fe5d3a607f))
|
|
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))
|
|
19
|
+
* updates field description type to include react nodes ([291c193](https://github.com/payloadcms/payload/commit/291c193ad4a9ec8ce9310cc63c714eba10eca102))
|
|
13
20
|
|
|
14
21
|
|
|
15
22
|
### Features
|
|
16
23
|
|
|
24
|
+
* add id fields to generated types ([21a810c](https://github.com/payloadcms/payload/commit/21a810c38c16e6907069d9076abf55718e439497))
|
|
17
25
|
* adds field types to type generation ([6dd1b0e](https://github.com/payloadcms/payload/commit/6dd1b0e0339490bf9e500f03f47ed59381644d85))
|
|
18
26
|
* adds relationship filter field ([463c4e6](https://github.com/payloadcms/payload/commit/463c4e60de8e647fca6268b826d826f9c6e45412))
|
|
27
|
+
* applies upload access control to all auto-generated image sizes ([051b7d4](https://github.com/payloadcms/payload/commit/051b7d45befc331af3f73a669b2bb6467505902f))
|
|
28
|
+
* azure cosmos compatibility ([6fd5ac2](https://github.com/payloadcms/payload/commit/6fd5ac2c082a5a5e6f510d781b2a2e12b7b62cb9))
|
|
19
29
|
* baseline type generation ([5a965d2](https://github.com/payloadcms/payload/commit/5a965d2263d1b246149c5220d039a6d97953d5e8))
|
|
20
30
|
* ensures update hooks have access to full original docs even in spite of access control ([b2c5b7e](https://github.com/payloadcms/payload/commit/b2c5b7e5752e829c7a53c054decceb43ec33065e))
|
|
21
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))
|
|
22
33
|
* generates further field types ([2ca76ba](https://github.com/payloadcms/payload/commit/2ca76ba8ce6c61ee7b0a01a557b6f013ca483d6d))
|
|
23
34
|
* improves querying logic ([4c85747](https://github.com/payloadcms/payload/commit/4c8574784995b1cb1f939648f4d2158286089b3d))
|
|
35
|
+
* indexes filenames ([5d43262](https://github.com/payloadcms/payload/commit/5d43262f42e0529a44572f398aa1ec5fd7858286))
|
|
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))
|
|
24
42
|
|
|
25
|
-
## [0.12.
|
|
26
|
-
|
|
43
|
+
## [0.12.13-beta.0](https://github.com/payloadcms/payload/compare/v0.12.3...v0.12.13-beta.0) (2021-11-24)
|
|
27
44
|
|
|
28
45
|
### Bug Fixes
|
|
29
46
|
|
|
@@ -33,33 +50,21 @@
|
|
|
33
50
|
* ensures buildQuery works with fields as well as simultaneous or / and ([72fc413](https://github.com/payloadcms/payload/commit/72fc413764c6c42ba64a45f01d99b68ad3bd46c4))
|
|
34
51
|
* ensures relationship field search can return more than 10 options ([57c0346](https://github.com/payloadcms/payload/commit/57c0346a00286a3df695ea46e5c2630494183b5b))
|
|
35
52
|
* ensures richtext links retain proper formatting ([abf61d0](https://github.com/payloadcms/payload/commit/abf61d0734c09fd0fc5c5b827cb0631e11701f71))
|
|
36
|
-
* ensures
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
### Features
|
|
40
|
-
|
|
41
|
-
* adds field types to type generation ([6dd1b0e](https://github.com/payloadcms/payload/commit/6dd1b0e0339490bf9e500f03f47ed59381644d85))
|
|
42
|
-
* adds relationship filter field ([463c4e6](https://github.com/payloadcms/payload/commit/463c4e60de8e647fca6268b826d826f9c6e45412))
|
|
43
|
-
* baseline type generation ([5a965d2](https://github.com/payloadcms/payload/commit/5a965d2263d1b246149c5220d039a6d97953d5e8))
|
|
44
|
-
* ensures update hooks have access to full original docs even in spite of access control ([b2c5b7e](https://github.com/payloadcms/payload/commit/b2c5b7e5752e829c7a53c054decceb43ec33065e))
|
|
45
|
-
* finishes typing all fields ([ed5a5eb](https://github.com/payloadcms/payload/commit/ed5a5ebe7e16d20577556ab233032a52bef6d2cb))
|
|
46
|
-
* generates further field types ([2ca76ba](https://github.com/payloadcms/payload/commit/2ca76ba8ce6c61ee7b0a01a557b6f013ca483d6d))
|
|
47
|
-
* improves querying logic ([4c85747](https://github.com/payloadcms/payload/commit/4c8574784995b1cb1f939648f4d2158286089b3d))
|
|
48
|
-
|
|
49
|
-
## [0.12.8-beta.0](https://github.com/payloadcms/payload/compare/v0.12.3...v0.12.8-beta.0) (2021-11-10)
|
|
50
|
-
|
|
53
|
+
* ensures querying by relationship subpaths works ([37b21b0](https://github.com/payloadcms/payload/commit/37b21b07628e892e85c2cf979d9e2c8af0d291f7))
|
|
54
|
+
* issue with querying by id and using comma-separated values ([d9e1b5e](https://github.com/payloadcms/payload/commit/d9e1b5ede33616893f9ba6990eeccf5410b75ae1))
|
|
55
|
+
* updates field description type to include react nodes ([291c193](https://github.com/payloadcms/payload/commit/291c193ad4a9ec8ce9310cc63c714eba10eca102))
|
|
51
56
|
|
|
52
|
-
### Bug Fixes
|
|
53
|
-
|
|
54
|
-
* [#351](https://github.com/payloadcms/payload/issues/351) ([94c2b8d](https://github.com/payloadcms/payload/commit/94c2b8d80b046c067057d4ad089ed6a2edd656cf))
|
|
55
|
-
* bug with relationship cell when no doc is available ([40b33d9](https://github.com/payloadcms/payload/commit/40b33d9f5e99285cb0de148dbe059259817fcad8))
|
|
56
|
-
* ensures richtext links retain proper formatting ([abf61d0](https://github.com/payloadcms/payload/commit/abf61d0734c09fd0fc5c5b827cb0631e11701f71))
|
|
57
57
|
|
|
58
58
|
### Features
|
|
59
59
|
|
|
60
|
+
* :tada: builds a way to automatically generate types for collections and globals! docs coming soon.
|
|
60
61
|
* adds relationship filter field ([463c4e6](https://github.com/payloadcms/payload/commit/463c4e60de8e647fca6268b826d826f9c6e45412))
|
|
62
|
+
* azure cosmos compatibility ([6fd5ac2](https://github.com/payloadcms/payload/commit/6fd5ac2c082a5a5e6f510d781b2a2e12b7b62cb9))
|
|
61
63
|
* ensures update hooks have access to full original docs even in spite of access control ([b2c5b7e](https://github.com/payloadcms/payload/commit/b2c5b7e5752e829c7a53c054decceb43ec33065e))
|
|
62
64
|
* improves querying logic ([4c85747](https://github.com/payloadcms/payload/commit/4c8574784995b1cb1f939648f4d2158286089b3d))
|
|
65
|
+
* indexes filenames ([5d43262](https://github.com/payloadcms/payload/commit/5d43262f42e0529a44572f398aa1ec5fd7858286))
|
|
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))
|
|
63
68
|
|
|
64
69
|
## [0.12.3](https://github.com/payloadcms/payload/compare/v0.12.2...v0.12.3) (2021-10-23)
|
|
65
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,13 +1,28 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import { useAuth } from '@payloadcms/config-provider';
|
|
3
3
|
import Button from '../Button';
|
|
4
4
|
import { useLocale } from '../../utilities/Locale';
|
|
5
5
|
const baseClass = 'preview-btn';
|
|
6
|
-
const PreviewButton = (
|
|
6
|
+
const PreviewButton = (props) => {
|
|
7
|
+
const { generatePreviewURL, data } = props;
|
|
8
|
+
const [url, setUrl] = useState(undefined);
|
|
7
9
|
const locale = useLocale();
|
|
8
10
|
const { token } = useAuth();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (generatePreviewURL && typeof generatePreviewURL === 'function') {
|
|
13
|
+
const makeRequest = async () => {
|
|
14
|
+
const previewURL = await generatePreviewURL(data, { locale, token });
|
|
15
|
+
setUrl(previewURL);
|
|
16
|
+
};
|
|
17
|
+
makeRequest();
|
|
18
|
+
}
|
|
19
|
+
}, [
|
|
20
|
+
generatePreviewURL,
|
|
21
|
+
locale,
|
|
22
|
+
token,
|
|
23
|
+
data
|
|
24
|
+
]);
|
|
25
|
+
if (url) {
|
|
11
26
|
return (React.createElement(Button, { el: "anchor", className: baseClass, buttonStyle: "secondary", url: url, newTab: true }, "Preview"));
|
|
12
27
|
}
|
|
13
28
|
return null;
|
|
@@ -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(' ');
|
|
@@ -3,10 +3,9 @@ export declare type DescriptionFunction = (value: unknown) => string;
|
|
|
3
3
|
export declare type DescriptionComponent = React.ComponentType<{
|
|
4
4
|
value: unknown;
|
|
5
5
|
}>;
|
|
6
|
-
declare type Description = string | DescriptionFunction | DescriptionComponent;
|
|
6
|
+
export declare type Description = string | DescriptionFunction | DescriptionComponent;
|
|
7
7
|
export declare type Props = {
|
|
8
8
|
description?: Description;
|
|
9
9
|
value: unknown;
|
|
10
10
|
};
|
|
11
11
|
export declare function isComponent(description: Description): description is DescriptionComponent;
|
|
12
|
-
export {};
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isComponent = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
function isComponent(description) {
|
|
9
|
+
return react_1.default.isValidElement(description);
|
|
4
10
|
}
|
|
11
|
+
exports.isComponent = isComponent;
|
|
12
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvYWRtaW4vY29tcG9uZW50cy9mb3Jtcy9GaWVsZERlc2NyaXB0aW9uL3R5cGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUFBLGtEQUEwQjtBQWExQixTQUFnQixXQUFXLENBQUMsV0FBd0I7SUFDbEQsT0FBTyxlQUFLLENBQUMsY0FBYyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQzNDLENBQUM7QUFGRCxrQ0FFQyJ9
|
|
@@ -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,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Data } from '../../Form/types';
|
|
2
|
-
import { ArrayField, Labels, Field
|
|
2
|
+
import { ArrayField, Labels, Field } from '../../../../../fields/config/types';
|
|
3
3
|
import { FieldTypes } from '..';
|
|
4
4
|
import { FieldPermissions } from '../../../../../auth/types';
|
|
5
|
+
import { Description } from '../../FieldDescription/types';
|
|
5
6
|
export declare type Props = Omit<ArrayField, 'type'> & {
|
|
6
7
|
path?: string;
|
|
7
8
|
fieldTypes: FieldTypes;
|
|
@@ -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,7 +1,8 @@
|
|
|
1
1
|
import { Data } from '../../Form/types';
|
|
2
|
-
import { BlockField, Labels, Block
|
|
2
|
+
import { BlockField, Labels, Block } from '../../../../../fields/config/types';
|
|
3
3
|
import { FieldTypes } from '..';
|
|
4
4
|
import { FieldPermissions } from '../../../../../auth/types';
|
|
5
|
+
import { Description } from '../../FieldDescription/types';
|
|
5
6
|
export declare type Props = Omit<BlockField, 'type'> & {
|
|
6
7
|
path?: string;
|
|
7
8
|
fieldTypes: FieldTypes;
|
|
@@ -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,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Validate } from '../../../../../fields/config/types';
|
|
3
|
+
import { Description } from '../../FieldDescription/types';
|
|
3
4
|
export declare type Props = {
|
|
4
5
|
autoComplete?: string;
|
|
5
6
|
path?: string;
|
|
@@ -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);
|