payload 0.12.11-beta.0 → 0.13.1
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 +18 -66
- package/components/forms.ts +2 -1
- package/components/index.js +2 -2
- package/dist/admin/components/elements/PreviewButton/index.js +19 -4
- package/dist/admin/components/elements/SearchFilter/index.js +6 -3
- 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/auth/getExecuteStaticAccess.d.ts +1 -1
- package/dist/auth/getExecuteStaticAccess.js +20 -4
- package/dist/bin/generateTypes.js +20 -9
- 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 +17 -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 +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 +14 -11
- package/dist/mongoose/buildSchema.js +6 -1
- package/dist/mongoose/sanitizeFormattedValue.js +2 -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
|
@@ -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,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState, } from 'react';
|
|
2
2
|
import { useFormProcessing, useFormSubmitted, useFormModified, useForm } from '../Form/context';
|
|
3
3
|
import useDebounce from '../../../hooks/useDebounce';
|
|
4
|
-
const
|
|
4
|
+
const useField = (options) => {
|
|
5
5
|
const { path, validate, enableDebouncedValue, disableFormData, ignoreWhileFlattening, stringify, condition, } = options;
|
|
6
6
|
const formContext = useForm();
|
|
7
7
|
const submitted = useFormSubmitted();
|
|
8
8
|
const processing = useFormProcessing();
|
|
9
9
|
const modified = useFormModified();
|
|
10
|
-
const { dispatchFields, getField, setModified, } = formContext;
|
|
10
|
+
const { dispatchFields, getField, setModified, } = formContext || {};
|
|
11
11
|
const [internalValue, setInternalValue] = useState(undefined);
|
|
12
12
|
// Debounce internal values to update form state only every 60ms
|
|
13
13
|
const debouncedValue = useDebounce(internalValue, 120);
|
|
@@ -40,18 +40,35 @@ const useFieldType = (options) => {
|
|
|
40
40
|
else {
|
|
41
41
|
fieldToDispatch.valid = validationResult;
|
|
42
42
|
}
|
|
43
|
-
dispatchFields
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if (typeof dispatchFields === 'function') {
|
|
44
|
+
dispatchFields(fieldToDispatch);
|
|
45
|
+
}
|
|
46
|
+
}, [
|
|
47
|
+
path,
|
|
48
|
+
dispatchFields,
|
|
49
|
+
validate,
|
|
50
|
+
disableFormData,
|
|
51
|
+
ignoreWhileFlattening,
|
|
52
|
+
initialValue,
|
|
53
|
+
stringify,
|
|
54
|
+
condition
|
|
55
|
+
]);
|
|
56
|
+
// Method to return from `useField`, used to
|
|
46
57
|
// update internal field values from field component(s)
|
|
47
58
|
// as fast as they arrive. NOTE - this method is NOT debounced
|
|
48
59
|
const setValue = useCallback((e, modifyForm = true) => {
|
|
49
60
|
const val = (e && e.target) ? e.target.value : e;
|
|
50
61
|
if ((!ignoreWhileFlattening && !modified) && modifyForm) {
|
|
51
|
-
setModified
|
|
62
|
+
if (typeof setModified === 'function') {
|
|
63
|
+
setModified(true);
|
|
64
|
+
}
|
|
52
65
|
}
|
|
53
66
|
setInternalValue(val);
|
|
54
|
-
}, [
|
|
67
|
+
}, [
|
|
68
|
+
setModified,
|
|
69
|
+
modified,
|
|
70
|
+
ignoreWhileFlattening
|
|
71
|
+
]);
|
|
55
72
|
useEffect(() => {
|
|
56
73
|
setInternalValue(initialValue);
|
|
57
74
|
}, [initialValue]);
|
|
@@ -63,7 +80,11 @@ const useFieldType = (options) => {
|
|
|
63
80
|
if ((field === null || field === void 0 ? void 0 : field.value) !== valueToSend && valueToSend !== undefined) {
|
|
64
81
|
sendField(valueToSend);
|
|
65
82
|
}
|
|
66
|
-
}, [
|
|
83
|
+
}, [
|
|
84
|
+
valueToSend,
|
|
85
|
+
sendField,
|
|
86
|
+
field
|
|
87
|
+
]);
|
|
67
88
|
return {
|
|
68
89
|
...options,
|
|
69
90
|
showError,
|
|
@@ -74,4 +95,4 @@ const useFieldType = (options) => {
|
|
|
74
95
|
setValue,
|
|
75
96
|
};
|
|
76
97
|
};
|
|
77
|
-
export default
|
|
98
|
+
export default useField;
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useMemo, useState, useEffect } from 'react';
|
|
2
2
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
-
import
|
|
3
|
+
import useField from '../../../../forms/useField';
|
|
4
4
|
import Label from '../../../../forms/Label';
|
|
5
5
|
import CopyToClipboard from '../../../../elements/CopyToClipboard';
|
|
6
6
|
import { text } from '../../../../../../fields/validations';
|
|
@@ -18,7 +18,7 @@ const APIKey = () => {
|
|
|
18
18
|
const APIKeyLabel = useMemo(() => (React.createElement("div", { className: `${baseClass}__label` },
|
|
19
19
|
React.createElement("span", null, "API Key"),
|
|
20
20
|
React.createElement(CopyToClipboard, { value: apiKeyValue }))), [apiKeyValue]);
|
|
21
|
-
const fieldType =
|
|
21
|
+
const fieldType = useField({
|
|
22
22
|
path: 'apiKey',
|
|
23
23
|
validate,
|
|
24
24
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useState, useRef, useEffect, useCallback, } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import useField from '../../../../forms/useField';
|
|
3
3
|
import Button from '../../../../elements/Button';
|
|
4
4
|
import FileDetails from '../../../../elements/FileDetails';
|
|
5
5
|
import Error from '../../../../forms/Error';
|
|
@@ -26,7 +26,7 @@ const Upload = (props) => {
|
|
|
26
26
|
const [replacingFile, setReplacingFile] = useState(false);
|
|
27
27
|
const { data = {}, collection, } = props;
|
|
28
28
|
const { filename } = data;
|
|
29
|
-
const { value, setValue, showError, errorMessage, } =
|
|
29
|
+
const { value, setValue, showError, errorMessage, } = useField({
|
|
30
30
|
path: 'file',
|
|
31
31
|
validate,
|
|
32
32
|
});
|
|
@@ -2,7 +2,7 @@ import { SanitizedCollectionConfig, PaginatedDocs } from '../../../../../collect
|
|
|
2
2
|
import { Column } from '../../../elements/Table/types';
|
|
3
3
|
export declare type Props = {
|
|
4
4
|
collection: SanitizedCollectionConfig;
|
|
5
|
-
data: PaginatedDocs
|
|
5
|
+
data: PaginatedDocs<any>;
|
|
6
6
|
newDocumentURL: string;
|
|
7
7
|
setListControls: (controls: unknown) => void;
|
|
8
8
|
setSort: (sort: string) => void;
|
|
@@ -3,5 +3,5 @@ import { PayloadRequest } from '../express/types';
|
|
|
3
3
|
declare const getExecuteStaticAccess: ({ config, Model }: {
|
|
4
4
|
config: any;
|
|
5
5
|
Model: any;
|
|
6
|
-
}) => (req: PayloadRequest, res: Response, next: NextFunction) => Promise<void
|
|
6
|
+
}) => (req: PayloadRequest, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
7
7
|
export default getExecuteStaticAccess;
|
|
@@ -6,6 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const executeAccess_1 = __importDefault(require("./executeAccess"));
|
|
7
7
|
const errors_1 = require("../errors");
|
|
8
8
|
const getExecuteStaticAccess = ({ config, Model }) => async (req, res, next) => {
|
|
9
|
+
if (req.method === 'OPTIONS') {
|
|
10
|
+
return res.sendStatus(200);
|
|
11
|
+
}
|
|
9
12
|
try {
|
|
10
13
|
if (req.path) {
|
|
11
14
|
const accessResult = await (0, executeAccess_1.default)({ req, isReadingStaticFile: true }, config.access.read);
|
|
@@ -15,14 +18,27 @@ const getExecuteStaticAccess = ({ config, Model }) => async (req, res, next) =>
|
|
|
15
18
|
where: {
|
|
16
19
|
and: [
|
|
17
20
|
{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
or: [
|
|
22
|
+
{
|
|
23
|
+
filename: {
|
|
24
|
+
equals: filename,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
],
|
|
21
28
|
},
|
|
22
29
|
accessResult,
|
|
23
30
|
],
|
|
24
31
|
},
|
|
25
32
|
};
|
|
33
|
+
if (config.upload.imageSizes) {
|
|
34
|
+
config.upload.imageSizes.forEach(({ name }) => {
|
|
35
|
+
queryToBuild.where.and[0].or.push({
|
|
36
|
+
[`sizes.${name}.filename`]: {
|
|
37
|
+
equals: filename,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
26
42
|
const query = await Model.buildQuery(queryToBuild, req.locale);
|
|
27
43
|
const doc = await Model.findOne(query);
|
|
28
44
|
if (!doc) {
|
|
@@ -37,4 +53,4 @@ const getExecuteStaticAccess = ({ config, Model }) => async (req, res, next) =>
|
|
|
37
53
|
}
|
|
38
54
|
};
|
|
39
55
|
exports.default = getExecuteStaticAccess;
|
|
40
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
56
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjoz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