payload 0.13.3 → 0.13.4
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 -0
- package/dist/admin/components/elements/ReactSelect/types.d.ts +4 -3
- package/dist/admin/components/forms/field-types/Select/Input.d.ts +21 -0
- package/dist/admin/components/forms/field-types/Select/Input.js +26 -0
- package/dist/admin/components/forms/field-types/Select/index.d.ts +0 -1
- package/dist/admin/components/forms/field-types/Select/index.js +4 -22
- package/dist/admin/components/forms/field-types/Select/types.d.ts +0 -4
- package/dist/admin/components/forms/field-types/Text/Input.d.ts +19 -0
- package/dist/admin/components/forms/field-types/Text/Input.js +24 -0
- package/dist/admin/components/forms/field-types/Text/index.d.ts +0 -1
- package/dist/admin/components/forms/field-types/Text/index.js +8 -35
- package/dist/admin/components/forms/field-types/Textarea/Input.d.ts +20 -0
- package/dist/admin/components/forms/field-types/Textarea/Input.js +23 -0
- package/dist/admin/components/forms/field-types/Textarea/index.js +4 -17
- package/dist/admin/components/forms/field-types/Upload/Input.d.ts +25 -0
- package/dist/admin/components/forms/field-types/Upload/Input.js +83 -0
- package/dist/admin/components/forms/field-types/Upload/index.js +13 -94
- package/dist/admin/components/forms/useField/index.js +4 -3
- package/dist/fields/config/types.d.ts +0 -4
- package/dist/fields/config/types.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## [0.13.4](https://github.com/payloadcms/payload/compare/v0.13.3...v0.13.4) (2021-11-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* passes hasMany through select component ([c77bf3a](https://github.com/payloadcms/payload/commit/c77bf3aa42d76b7a0649b28fee3fe5d4bd06dcf6))
|
|
7
|
+
* prevents uncontrolled text field component ([f0fd859](https://github.com/payloadcms/payload/commit/f0fd859347804fdf0d79bbe566412abaeec6ff6a))
|
|
8
|
+
* select component types ([7e2b259](https://github.com/payloadcms/payload/commit/7e2b2598167dc59b8982f635cb95eacf247abb43))
|
|
9
|
+
* threads props through textarea component ([0b13eda](https://github.com/payloadcms/payload/commit/0b13eda1e55299f7d6dfac2854acc04cff459396))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* abstracts input from text component ([615e369](https://github.com/payloadcms/payload/commit/615e3695f2e62ce5d8a43ccb84192aca57770af8))
|
|
15
|
+
* abstracts select component ([fa67137](https://github.com/payloadcms/payload/commit/fa671378c7282cda1ed6f46340a53622e3bc96dc))
|
|
16
|
+
* abstracts textarea component and improves event typing ([86480b7](https://github.com/payloadcms/payload/commit/86480b7482b2b9413272ab0f9d0a82cd5e2920b8))
|
|
17
|
+
* abstracts upload component ([f234f68](https://github.com/payloadcms/payload/commit/f234f68019f122bd46cb2af2e8f62cf07cd53c1b))
|
|
18
|
+
|
|
1
19
|
## [0.13.3](https://github.com/payloadcms/payload/compare/v0.13.2...v0.13.3) (2021-11-29)
|
|
2
20
|
|
|
3
21
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { OptionsType, GroupedOptionsType } from 'react-select';
|
|
2
|
+
export declare type Options = OptionsType<Value> | GroupedOptionsType<Value>;
|
|
2
3
|
export declare type Value = {
|
|
3
4
|
label: string;
|
|
4
|
-
value:
|
|
5
|
-
options?:
|
|
5
|
+
value: string;
|
|
6
|
+
options?: Options;
|
|
6
7
|
};
|
|
7
8
|
export declare type Props = {
|
|
8
9
|
className?: string;
|
|
@@ -10,7 +11,7 @@ export declare type Props = {
|
|
|
10
11
|
onChange?: (value: any) => void;
|
|
11
12
|
disabled?: boolean;
|
|
12
13
|
showError?: boolean;
|
|
13
|
-
options:
|
|
14
|
+
options: Options;
|
|
14
15
|
isMulti?: boolean;
|
|
15
16
|
isDisabled?: boolean;
|
|
16
17
|
onInputChange?: (val: string) => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { OptionObject, SelectField } from '../../../../../fields/config/types';
|
|
3
|
+
import { Description } from '../../FieldDescription/types';
|
|
4
|
+
import { Value as ReactSelectValue } from '../../../elements/ReactSelect/types';
|
|
5
|
+
import './index.scss';
|
|
6
|
+
export declare type SelectInputProps = Omit<SelectField, 'type' | 'value' | 'options'> & {
|
|
7
|
+
showError: boolean;
|
|
8
|
+
errorMessage?: string;
|
|
9
|
+
readOnly?: boolean;
|
|
10
|
+
path?: string;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
value?: string;
|
|
13
|
+
description?: Description;
|
|
14
|
+
onChange?: (value: ReactSelectValue) => void;
|
|
15
|
+
style?: React.CSSProperties;
|
|
16
|
+
width?: string;
|
|
17
|
+
hasMany?: boolean;
|
|
18
|
+
options?: OptionObject[];
|
|
19
|
+
};
|
|
20
|
+
declare const SelectInput: React.FC<SelectInputProps>;
|
|
21
|
+
export default SelectInput;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Label from '../../Label';
|
|
3
|
+
import Error from '../../Error';
|
|
4
|
+
import FieldDescription from '../../FieldDescription';
|
|
5
|
+
import ReactSelect from '../../../elements/ReactSelect';
|
|
6
|
+
// import { FieldType } from '../../useField/types';
|
|
7
|
+
import './index.scss';
|
|
8
|
+
const SelectInput = (props) => {
|
|
9
|
+
const { showError, errorMessage, readOnly, path, label, required, value, onChange, description, style, width, options, hasMany, } = props;
|
|
10
|
+
const classes = [
|
|
11
|
+
'field-type',
|
|
12
|
+
'select',
|
|
13
|
+
showError && 'error',
|
|
14
|
+
readOnly && 'read-only',
|
|
15
|
+
].filter(Boolean).join(' ');
|
|
16
|
+
const selectedOption = options.find((option) => option.value === value);
|
|
17
|
+
return (React.createElement("div", { className: classes, style: {
|
|
18
|
+
...style,
|
|
19
|
+
width,
|
|
20
|
+
} },
|
|
21
|
+
React.createElement(Error, { showError: showError, message: errorMessage }),
|
|
22
|
+
React.createElement(Label, { htmlFor: path, label: label, required: required }),
|
|
23
|
+
React.createElement(ReactSelect, { onChange: onChange, value: selectedOption, showError: showError, isDisabled: readOnly, options: options, isMulti: hasMany }),
|
|
24
|
+
React.createElement(FieldDescription, { value: value, description: description })));
|
|
25
|
+
};
|
|
26
|
+
export default SelectInput;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import React, { useCallback, useState } from 'react';
|
|
2
2
|
import withCondition from '../../withCondition';
|
|
3
|
-
import ReactSelect from '../../../elements/ReactSelect';
|
|
4
3
|
import useField from '../../useField';
|
|
5
|
-
import Label from '../../Label';
|
|
6
|
-
import Error from '../../Error';
|
|
7
|
-
import FieldDescription from '../../FieldDescription';
|
|
8
4
|
import { select } from '../../../../../fields/validations';
|
|
9
|
-
import './
|
|
10
|
-
const baseClass = 'select';
|
|
5
|
+
import SelectInput from './Input';
|
|
11
6
|
const formatOptions = (options) => options.map((option) => {
|
|
12
7
|
if (typeof option === 'object' && option.value) {
|
|
13
8
|
return option;
|
|
@@ -18,7 +13,7 @@ const formatOptions = (options) => options.map((option) => {
|
|
|
18
13
|
};
|
|
19
14
|
});
|
|
20
15
|
const Select = (props) => {
|
|
21
|
-
const { path: pathFromProps, name, required, validate = select, label, options: optionsFromProps, hasMany, admin: { readOnly, style, width, description, condition, } = {}, value: valueFromProps, onChange: onChangeFromProps } = props;
|
|
16
|
+
const { path: pathFromProps, name, required, validate = select, label, options: optionsFromProps, hasMany, admin: { readOnly, style, width, description, condition, } = {}, value: valueFromProps, onChange: onChangeFromProps, } = props;
|
|
22
17
|
const path = pathFromProps || name;
|
|
23
18
|
const [options] = useState(formatOptions(optionsFromProps));
|
|
24
19
|
const memoizedValidate = useCallback((value) => {
|
|
@@ -55,14 +50,8 @@ const Select = (props) => {
|
|
|
55
50
|
readOnly,
|
|
56
51
|
hasMany,
|
|
57
52
|
onChangeFromProps,
|
|
58
|
-
setValue
|
|
53
|
+
setValue,
|
|
59
54
|
]);
|
|
60
|
-
const classes = [
|
|
61
|
-
'field-type',
|
|
62
|
-
baseClass,
|
|
63
|
-
showError && 'error',
|
|
64
|
-
readOnly && `${baseClass}--read-only`,
|
|
65
|
-
].filter(Boolean).join(' ');
|
|
66
55
|
let valueToRender;
|
|
67
56
|
const value = valueFromProps || valueFromContext || '';
|
|
68
57
|
if (hasMany && Array.isArray(value)) {
|
|
@@ -71,13 +60,6 @@ const Select = (props) => {
|
|
|
71
60
|
else {
|
|
72
61
|
valueToRender = options.find((option) => option.value === value);
|
|
73
62
|
}
|
|
74
|
-
return (React.createElement(
|
|
75
|
-
...style,
|
|
76
|
-
width,
|
|
77
|
-
} },
|
|
78
|
-
React.createElement(Error, { showError: showError, message: errorMessage }),
|
|
79
|
-
React.createElement(Label, { htmlFor: path, label: label, required: required }),
|
|
80
|
-
React.createElement(ReactSelect, { onChange: onChange, value: valueToRender, showError: showError, isDisabled: readOnly, options: options, isMulti: hasMany }),
|
|
81
|
-
React.createElement(FieldDescription, { value: value, description: description })));
|
|
63
|
+
return (React.createElement(SelectInput, { onChange: onChange, value: valueToRender, name: name, options: options, label: label, showError: showError, errorMessage: errorMessage, description: description, style: style, width: width, hasMany: hasMany }));
|
|
82
64
|
};
|
|
83
65
|
export default withCondition(Select);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { ChangeEvent } from 'react';
|
|
2
|
+
import { TextField } from '../../../../../fields/config/types';
|
|
3
|
+
import { Description } from '../../FieldDescription/types';
|
|
4
|
+
import './index.scss';
|
|
5
|
+
export declare type TextInputProps = Omit<TextField, 'type'> & {
|
|
6
|
+
showError: boolean;
|
|
7
|
+
errorMessage?: string;
|
|
8
|
+
readOnly?: boolean;
|
|
9
|
+
path?: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
value?: string;
|
|
12
|
+
description?: Description;
|
|
13
|
+
onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
style?: React.CSSProperties;
|
|
16
|
+
width?: string;
|
|
17
|
+
};
|
|
18
|
+
declare const TextInput: React.FC<TextInputProps>;
|
|
19
|
+
export default TextInput;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Label from '../../Label';
|
|
3
|
+
import Error from '../../Error';
|
|
4
|
+
import FieldDescription from '../../FieldDescription';
|
|
5
|
+
// import { FieldType } from '../../useField/types';
|
|
6
|
+
import './index.scss';
|
|
7
|
+
const TextInput = (props) => {
|
|
8
|
+
const { showError, errorMessage, placeholder, readOnly, path, label, required, value, onChange, description, style, width, } = props;
|
|
9
|
+
const classes = [
|
|
10
|
+
'field-type',
|
|
11
|
+
'text',
|
|
12
|
+
showError && 'error',
|
|
13
|
+
readOnly && 'read-only',
|
|
14
|
+
].filter(Boolean).join(' ');
|
|
15
|
+
return (React.createElement("div", { className: classes, style: {
|
|
16
|
+
...style,
|
|
17
|
+
width,
|
|
18
|
+
} },
|
|
19
|
+
React.createElement(Error, { showError: showError, message: errorMessage }),
|
|
20
|
+
React.createElement(Label, { htmlFor: path, label: label, required: required }),
|
|
21
|
+
React.createElement("input", { value: value || '', onChange: onChange, disabled: readOnly, placeholder: placeholder, type: "text", id: path, name: path }),
|
|
22
|
+
React.createElement(FieldDescription, { value: value, description: description })));
|
|
23
|
+
};
|
|
24
|
+
export default TextInput;
|
|
@@ -1,47 +1,20 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import useField from '../../useField';
|
|
3
3
|
import withCondition from '../../withCondition';
|
|
4
|
-
import Label from '../../Label';
|
|
5
|
-
import Error from '../../Error';
|
|
6
4
|
import { text } from '../../../../../fields/validations';
|
|
7
|
-
import
|
|
8
|
-
import './index.scss';
|
|
5
|
+
import TextInput from './Input';
|
|
9
6
|
const Text = (props) => {
|
|
10
|
-
const { path: pathFromProps, name, required, validate = text, label, admin: { placeholder, readOnly, style, width, description, condition, } = {},
|
|
7
|
+
const { path: pathFromProps, name, required, validate = text, label, admin: { placeholder, readOnly, style, width, description, condition, } = {}, } = props;
|
|
11
8
|
const path = pathFromProps || name;
|
|
12
|
-
const
|
|
9
|
+
const field = useField({
|
|
13
10
|
path,
|
|
14
11
|
validate,
|
|
15
12
|
enableDebouncedValue: true,
|
|
16
13
|
condition,
|
|
17
14
|
});
|
|
18
|
-
const { value
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
onChangeFromProps(incomingValue);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
setValue(e);
|
|
26
|
-
}
|
|
27
|
-
}, [
|
|
28
|
-
onChangeFromProps,
|
|
29
|
-
setValue,
|
|
30
|
-
]);
|
|
31
|
-
const classes = [
|
|
32
|
-
'field-type',
|
|
33
|
-
'text',
|
|
34
|
-
showError && 'error',
|
|
35
|
-
readOnly && 'read-only',
|
|
36
|
-
].filter(Boolean).join(' ');
|
|
37
|
-
const value = valueFromProps || valueFromContext || '';
|
|
38
|
-
return (React.createElement("div", { className: classes, style: {
|
|
39
|
-
...style,
|
|
40
|
-
width,
|
|
41
|
-
} },
|
|
42
|
-
React.createElement(Error, { showError: showError, message: errorMessage }),
|
|
43
|
-
React.createElement(Label, { htmlFor: path, label: label, required: required }),
|
|
44
|
-
React.createElement("input", { value: value, onChange: onChange, disabled: readOnly, placeholder: placeholder, type: "text", id: path, name: path }),
|
|
45
|
-
React.createElement(FieldDescription, { value: value, description: description })));
|
|
15
|
+
const { value, showError, setValue, errorMessage, } = field;
|
|
16
|
+
return (React.createElement(TextInput, { name: name, onChange: (e) => {
|
|
17
|
+
setValue(e.target.value);
|
|
18
|
+
}, showError: showError, errorMessage: errorMessage, required: required, label: label, value: value, placeholder: placeholder, readOnly: readOnly, style: style, width: width, description: description }));
|
|
46
19
|
};
|
|
47
20
|
export default withCondition(Text);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { ChangeEvent } from 'react';
|
|
2
|
+
import { TextareaField } from '../../../../../fields/config/types';
|
|
3
|
+
import { Description } from '../../FieldDescription/types';
|
|
4
|
+
import './index.scss';
|
|
5
|
+
export declare type TextAreaInputProps = Omit<TextareaField, 'type'> & {
|
|
6
|
+
showError: boolean;
|
|
7
|
+
errorMessage?: string;
|
|
8
|
+
readOnly?: boolean;
|
|
9
|
+
path?: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
value?: string;
|
|
12
|
+
description?: Description;
|
|
13
|
+
onChange?: (e: ChangeEvent<HTMLTextAreaElement>) => void;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
style?: React.CSSProperties;
|
|
16
|
+
width?: string;
|
|
17
|
+
rows?: number;
|
|
18
|
+
};
|
|
19
|
+
declare const TextareaInput: React.FC<TextAreaInputProps>;
|
|
20
|
+
export default TextareaInput;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Label from '../../Label';
|
|
3
|
+
import Error from '../../Error';
|
|
4
|
+
import FieldDescription from '../../FieldDescription';
|
|
5
|
+
import './index.scss';
|
|
6
|
+
const TextareaInput = (props) => {
|
|
7
|
+
const { path, required, readOnly, style, width, placeholder, description, label, showError, value, errorMessage, onChange, rows, } = props;
|
|
8
|
+
const classes = [
|
|
9
|
+
'field-type',
|
|
10
|
+
'textarea',
|
|
11
|
+
showError && 'error',
|
|
12
|
+
readOnly && 'read-only',
|
|
13
|
+
].filter(Boolean).join(' ');
|
|
14
|
+
return (React.createElement("div", { className: classes, style: {
|
|
15
|
+
...style,
|
|
16
|
+
width,
|
|
17
|
+
} },
|
|
18
|
+
React.createElement(Error, { showError: showError, message: errorMessage }),
|
|
19
|
+
React.createElement(Label, { htmlFor: path, label: label, required: required }),
|
|
20
|
+
React.createElement("textarea", { value: value || '', onChange: onChange, disabled: readOnly, placeholder: placeholder, id: path, name: path, rows: rows }),
|
|
21
|
+
React.createElement(FieldDescription, { value: value, description: description })));
|
|
22
|
+
};
|
|
23
|
+
export default TextareaInput;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
import useField from '../../useField';
|
|
3
3
|
import withCondition from '../../withCondition';
|
|
4
|
-
import Label from '../../Label';
|
|
5
|
-
import Error from '../../Error';
|
|
6
|
-
import FieldDescription from '../../FieldDescription';
|
|
7
4
|
import { textarea } from '../../../../../fields/validations';
|
|
8
5
|
import './index.scss';
|
|
6
|
+
import TextareaInput from './Input';
|
|
9
7
|
const Textarea = (props) => {
|
|
10
8
|
const { path: pathFromProps, name, required, validate = textarea, admin: { readOnly, style, width, placeholder, rows, description, condition, } = {}, label, minLength, maxLength, } = props;
|
|
11
9
|
const path = pathFromProps || name;
|
|
@@ -19,19 +17,8 @@ const Textarea = (props) => {
|
|
|
19
17
|
enableDebouncedValue: true,
|
|
20
18
|
condition,
|
|
21
19
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
showError && 'error',
|
|
26
|
-
readOnly && 'read-only',
|
|
27
|
-
].filter(Boolean).join(' ');
|
|
28
|
-
return (React.createElement("div", { className: classes, style: {
|
|
29
|
-
...style,
|
|
30
|
-
width,
|
|
31
|
-
} },
|
|
32
|
-
React.createElement(Error, { showError: showError, message: errorMessage }),
|
|
33
|
-
React.createElement(Label, { htmlFor: path, label: label, required: required }),
|
|
34
|
-
React.createElement("textarea", { value: value || '', onChange: setValue, disabled: readOnly, placeholder: placeholder, id: path, name: path, rows: rows }),
|
|
35
|
-
React.createElement(FieldDescription, { value: value, description: description })));
|
|
20
|
+
return (React.createElement(TextareaInput, { name: name, onChange: (e) => {
|
|
21
|
+
setValue(e.target.value);
|
|
22
|
+
}, showError: showError, errorMessage: errorMessage, required: required, label: label, value: value, placeholder: placeholder, readOnly: readOnly, style: style, width: width, description: description, rows: rows }));
|
|
36
23
|
};
|
|
37
24
|
export default withCondition(Textarea);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { UploadField } from '../../../../../fields/config/types';
|
|
3
|
+
import { Description } from '../../FieldDescription/types';
|
|
4
|
+
import { FieldTypes } from '..';
|
|
5
|
+
import { SanitizedCollectionConfig } from '../../../../../collections/config/types';
|
|
6
|
+
import './index.scss';
|
|
7
|
+
export declare type UploadInputProps = Omit<UploadField, 'type'> & {
|
|
8
|
+
showError: boolean;
|
|
9
|
+
errorMessage?: string;
|
|
10
|
+
readOnly?: boolean;
|
|
11
|
+
path?: string;
|
|
12
|
+
required?: boolean;
|
|
13
|
+
value?: string;
|
|
14
|
+
description?: Description;
|
|
15
|
+
onChange?: (e: any) => void;
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
style?: React.CSSProperties;
|
|
18
|
+
width?: string;
|
|
19
|
+
fieldTypes?: FieldTypes;
|
|
20
|
+
collection?: SanitizedCollectionConfig;
|
|
21
|
+
serverURL?: string;
|
|
22
|
+
api?: string;
|
|
23
|
+
};
|
|
24
|
+
declare const UploadInput: React.FC<UploadInputProps>;
|
|
25
|
+
export default UploadInput;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { useModal } from '@faceless-ui/modal';
|
|
3
|
+
import Button from '../../../elements/Button';
|
|
4
|
+
import Label from '../../Label';
|
|
5
|
+
import Error from '../../Error';
|
|
6
|
+
import FileDetails from '../../../elements/FileDetails';
|
|
7
|
+
import FieldDescription from '../../FieldDescription';
|
|
8
|
+
import AddModal from './Add';
|
|
9
|
+
import SelectExistingModal from './SelectExisting';
|
|
10
|
+
import './index.scss';
|
|
11
|
+
const baseClass = 'upload';
|
|
12
|
+
const UploadInput = (props) => {
|
|
13
|
+
const { path, required, readOnly, style, width, description, label, relationTo, fieldTypes, value, onChange, showError, serverURL = 'http://localhost:3000', api = '/api', collection, errorMessage, } = props;
|
|
14
|
+
const { toggle } = useModal();
|
|
15
|
+
const addModalSlug = `${path}-add`;
|
|
16
|
+
const selectExistingModalSlug = `${path}-select-existing`;
|
|
17
|
+
const [file, setFile] = useState(undefined);
|
|
18
|
+
const [missingFile, setMissingFile] = useState(false);
|
|
19
|
+
const classes = [
|
|
20
|
+
'field-type',
|
|
21
|
+
baseClass,
|
|
22
|
+
showError && 'error',
|
|
23
|
+
readOnly && 'read-only',
|
|
24
|
+
].filter(Boolean).join(' ');
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (typeof value === 'string' && value !== '') {
|
|
27
|
+
const fetchFile = async () => {
|
|
28
|
+
const response = await fetch(`${serverURL}${api}/${relationTo}/${value}`);
|
|
29
|
+
if (response.ok) {
|
|
30
|
+
const json = await response.json();
|
|
31
|
+
setFile(json);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
setMissingFile(true);
|
|
35
|
+
setFile(undefined);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
fetchFile();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
setFile(undefined);
|
|
42
|
+
}
|
|
43
|
+
}, [
|
|
44
|
+
value,
|
|
45
|
+
relationTo,
|
|
46
|
+
api,
|
|
47
|
+
serverURL,
|
|
48
|
+
]);
|
|
49
|
+
return (React.createElement("div", { className: classes, style: {
|
|
50
|
+
...style,
|
|
51
|
+
width,
|
|
52
|
+
} },
|
|
53
|
+
React.createElement(Error, { showError: showError, message: errorMessage }),
|
|
54
|
+
React.createElement(Label, { htmlFor: path, label: label, required: required }),
|
|
55
|
+
(collection === null || collection === void 0 ? void 0 : collection.upload) && (React.createElement(React.Fragment, null,
|
|
56
|
+
(file && !missingFile) && (React.createElement(FileDetails, { collection: collection, doc: file, handleRemove: () => {
|
|
57
|
+
onChange(null);
|
|
58
|
+
} })),
|
|
59
|
+
(!file || missingFile) && (React.createElement("div", { className: `${baseClass}__wrap` },
|
|
60
|
+
React.createElement(Button, { buttonStyle: "secondary", onClick: () => {
|
|
61
|
+
toggle(addModalSlug);
|
|
62
|
+
} },
|
|
63
|
+
"Upload new",
|
|
64
|
+
' ',
|
|
65
|
+
collection.labels.singular),
|
|
66
|
+
React.createElement(Button, { buttonStyle: "secondary", onClick: () => {
|
|
67
|
+
toggle(selectExistingModalSlug);
|
|
68
|
+
} }, "Choose from existing"))),
|
|
69
|
+
React.createElement(AddModal, { ...{
|
|
70
|
+
collection,
|
|
71
|
+
slug: addModalSlug,
|
|
72
|
+
fieldTypes,
|
|
73
|
+
setValue: onChange,
|
|
74
|
+
} }),
|
|
75
|
+
React.createElement(SelectExistingModal, { ...{
|
|
76
|
+
collection,
|
|
77
|
+
slug: selectExistingModalSlug,
|
|
78
|
+
setValue: onChange,
|
|
79
|
+
addModalSlug,
|
|
80
|
+
} }),
|
|
81
|
+
React.createElement(FieldDescription, { value: file, description: description })))));
|
|
82
|
+
};
|
|
83
|
+
export default UploadInput;
|
|
@@ -1,28 +1,15 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import { useModal } from '@faceless-ui/modal';
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
3
2
|
import { useConfig } from '@payloadcms/config-provider';
|
|
4
3
|
import useField from '../../useField';
|
|
5
4
|
import withCondition from '../../withCondition';
|
|
6
|
-
import Button from '../../../elements/Button';
|
|
7
|
-
import Label from '../../Label';
|
|
8
|
-
import Error from '../../Error';
|
|
9
5
|
import { upload } from '../../../../../fields/validations';
|
|
10
|
-
import
|
|
11
|
-
import AddModal from './Add';
|
|
12
|
-
import SelectExistingModal from './SelectExisting';
|
|
6
|
+
import UploadInput from './Input';
|
|
13
7
|
import './index.scss';
|
|
14
|
-
import FieldDescription from '../../FieldDescription';
|
|
15
|
-
const baseClass = 'upload';
|
|
16
8
|
const Upload = (props) => {
|
|
17
|
-
const {
|
|
18
|
-
const
|
|
19
|
-
const [missingFile, setMissingFile] = useState(false);
|
|
20
|
-
const { collections, serverURL, routes: { api } } = useConfig();
|
|
21
|
-
const { path: pathFromProps, name, required, admin: { readOnly, style, width, description, condition, } = {}, label, validate = upload, relationTo, fieldTypes, value: valueFromProps, onChange: onChangeFromProps, } = props;
|
|
9
|
+
const { collections, serverURL, routes: { api, }, } = useConfig();
|
|
10
|
+
const { path: pathFromProps, name, required, admin: { readOnly, style, width, description, condition, } = {}, label, validate = upload, relationTo, fieldTypes, } = props;
|
|
22
11
|
const collection = collections.find((coll) => coll.slug === relationTo);
|
|
23
12
|
const path = pathFromProps || name;
|
|
24
|
-
const addModalSlug = `${path}-add`;
|
|
25
|
-
const selectExistingModalSlug = `${path}-select-existing`;
|
|
26
13
|
const memoizedValidate = useCallback((value) => {
|
|
27
14
|
const validationResult = validate(value, { required });
|
|
28
15
|
return validationResult;
|
|
@@ -32,84 +19,16 @@ const Upload = (props) => {
|
|
|
32
19
|
validate: memoizedValidate,
|
|
33
20
|
condition,
|
|
34
21
|
});
|
|
35
|
-
const { value
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
baseClass,
|
|
40
|
-
showError && 'error',
|
|
41
|
-
readOnly && 'read-only',
|
|
42
|
-
].filter(Boolean).join(' ');
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (typeof value === 'string') {
|
|
45
|
-
const fetchFile = async () => {
|
|
46
|
-
const response = await fetch(`${serverURL}${api}/${relationTo}/${value}`);
|
|
47
|
-
if (response.ok) {
|
|
48
|
-
const json = await response.json();
|
|
49
|
-
setInternalValue(json);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
setInternalValue(undefined);
|
|
53
|
-
setMissingFile(true);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
fetchFile();
|
|
57
|
-
}
|
|
22
|
+
const { value, showError, setValue, errorMessage, } = fieldType;
|
|
23
|
+
const onChange = useCallback((incomingValue) => {
|
|
24
|
+
const incomingID = (incomingValue === null || incomingValue === void 0 ? void 0 : incomingValue.id) || incomingValue;
|
|
25
|
+
setValue(incomingID);
|
|
58
26
|
}, [
|
|
59
|
-
|
|
60
|
-
relationTo,
|
|
61
|
-
api,
|
|
62
|
-
serverURL,
|
|
63
|
-
setValue
|
|
27
|
+
setValue,
|
|
64
28
|
]);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
setValue(incomingID);
|
|
72
|
-
}
|
|
73
|
-
}, [internalValue]);
|
|
74
|
-
return (React.createElement("div", { className: classes, style: {
|
|
75
|
-
...style,
|
|
76
|
-
width,
|
|
77
|
-
} },
|
|
78
|
-
React.createElement(Error, { showError: showError, message: errorMessage }),
|
|
79
|
-
React.createElement(Label, { htmlFor: path, label: label, required: required }),
|
|
80
|
-
(collection === null || collection === void 0 ? void 0 : collection.upload) && (React.createElement(React.Fragment, null,
|
|
81
|
-
(internalValue && !missingFile) && (React.createElement(FileDetails, { collection: collection, doc: internalValue, handleRemove: () => {
|
|
82
|
-
setInternalValue(undefined);
|
|
83
|
-
setValue(null);
|
|
84
|
-
} })),
|
|
85
|
-
(!value || missingFile) && (React.createElement("div", { className: `${baseClass}__wrap` },
|
|
86
|
-
React.createElement(Button, { buttonStyle: "secondary", onClick: () => {
|
|
87
|
-
toggle(addModalSlug);
|
|
88
|
-
} },
|
|
89
|
-
"Upload new",
|
|
90
|
-
' ',
|
|
91
|
-
collection.labels.singular),
|
|
92
|
-
React.createElement(Button, { buttonStyle: "secondary", onClick: () => {
|
|
93
|
-
toggle(selectExistingModalSlug);
|
|
94
|
-
} }, "Choose from existing"))),
|
|
95
|
-
React.createElement(AddModal, { ...{
|
|
96
|
-
collection,
|
|
97
|
-
slug: addModalSlug,
|
|
98
|
-
fieldTypes,
|
|
99
|
-
setValue: (val) => {
|
|
100
|
-
setMissingFile(false);
|
|
101
|
-
setInternalValue(val);
|
|
102
|
-
},
|
|
103
|
-
} }),
|
|
104
|
-
React.createElement(SelectExistingModal, { ...{
|
|
105
|
-
collection,
|
|
106
|
-
slug: selectExistingModalSlug,
|
|
107
|
-
setValue: (val) => {
|
|
108
|
-
setMissingFile(false);
|
|
109
|
-
setInternalValue(val);
|
|
110
|
-
},
|
|
111
|
-
addModalSlug,
|
|
112
|
-
} }),
|
|
113
|
-
React.createElement(FieldDescription, { value: value, description: description })))));
|
|
29
|
+
if (collection.upload) {
|
|
30
|
+
return (React.createElement(UploadInput, { value: value, onChange: onChange, description: description, label: label, required: required, showError: showError, serverURL: serverURL, api: api, errorMessage: errorMessage, readOnly: readOnly, style: style, width: width, collection: collection, fieldTypes: fieldTypes, name: name, relationTo: relationTo }));
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
114
33
|
};
|
|
115
34
|
export default withCondition(Upload);
|
|
@@ -51,7 +51,7 @@ const useField = (options) => {
|
|
|
51
51
|
ignoreWhileFlattening,
|
|
52
52
|
initialValue,
|
|
53
53
|
stringify,
|
|
54
|
-
condition
|
|
54
|
+
condition,
|
|
55
55
|
]);
|
|
56
56
|
// Method to return from `useField`, used to
|
|
57
57
|
// update internal field values from field component(s)
|
|
@@ -67,7 +67,7 @@ const useField = (options) => {
|
|
|
67
67
|
}, [
|
|
68
68
|
setModified,
|
|
69
69
|
modified,
|
|
70
|
-
ignoreWhileFlattening
|
|
70
|
+
ignoreWhileFlattening,
|
|
71
71
|
]);
|
|
72
72
|
useEffect(() => {
|
|
73
73
|
setInternalValue(initialValue);
|
|
@@ -81,9 +81,10 @@ const useField = (options) => {
|
|
|
81
81
|
sendField(valueToSend);
|
|
82
82
|
}
|
|
83
83
|
}, [
|
|
84
|
+
path,
|
|
84
85
|
valueToSend,
|
|
85
86
|
sendField,
|
|
86
|
-
field
|
|
87
|
+
field,
|
|
87
88
|
]);
|
|
88
89
|
return {
|
|
89
90
|
...options,
|
|
@@ -86,8 +86,6 @@ export declare type TextField = FieldBase & {
|
|
|
86
86
|
placeholder?: string;
|
|
87
87
|
autoComplete?: string;
|
|
88
88
|
};
|
|
89
|
-
value?: string;
|
|
90
|
-
onChange?: (value: string) => void;
|
|
91
89
|
};
|
|
92
90
|
export declare type EmailField = FieldBase & {
|
|
93
91
|
type: 'email';
|
|
@@ -150,8 +148,6 @@ export declare type UploadField = FieldBase & {
|
|
|
150
148
|
type: 'upload';
|
|
151
149
|
relationTo: string;
|
|
152
150
|
maxDepth?: number;
|
|
153
|
-
value?: string;
|
|
154
|
-
onChange?: (value: string) => void;
|
|
155
151
|
};
|
|
156
152
|
declare type CodeAdmin = Admin & {
|
|
157
153
|
language?: string;
|
|
@@ -41,4 +41,4 @@ function fieldAffectsData(field) {
|
|
|
41
41
|
return 'name' in field && !fieldIsPresentationalOnly(field);
|
|
42
42
|
}
|
|
43
43
|
exports.fieldAffectsData = fieldAffectsData;
|
|
44
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
44
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvZmllbGRzL2NvbmZpZy90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFzVkEsU0FBZ0IsaUJBQWlCLENBQUMsS0FBWTtJQUM1QyxPQUFPLENBQUMsS0FBSyxDQUFDLElBQUksS0FBSyxPQUFPLElBQUksS0FBSyxDQUFDLElBQUksS0FBSyxPQUFPLElBQUksS0FBSyxDQUFDLElBQUksS0FBSyxLQUFLLENBQUMsQ0FBQztBQUNwRixDQUFDO0FBRkQsOENBRUM7QUFFRCxTQUFnQixnQkFBZ0IsQ0FBQyxLQUFZO0lBQzNDLE9BQU8sS0FBSyxDQUFDLElBQUksS0FBSyxPQUFPLENBQUM7QUFDaEMsQ0FBQztBQUZELDRDQUVDO0FBRUQsU0FBZ0IsZ0JBQWdCLENBQUMsS0FBWTtJQUMzQyxPQUFPLEtBQUssQ0FBQyxJQUFJLEtBQUssUUFBUSxDQUFDO0FBQ2pDLENBQUM7QUFGRCw0Q0FFQztBQUVELFNBQWdCLGNBQWMsQ0FBQyxNQUFjO0lBQzNDLE9BQU8sT0FBTyxNQUFNLEtBQUssUUFBUSxDQUFDO0FBQ3BDLENBQUM7QUFGRCx3Q0FFQztBQUVELFNBQWdCLGlCQUFpQixDQUFDLE9BQWlCO0lBQ2pELE9BQU8sS0FBSyxDQUFDLE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxPQUFPLENBQUEsT0FBTyxhQUFQLE9BQU8sdUJBQVAsT0FBTyxDQUFHLENBQUMsQ0FBQyxDQUFBLEtBQUssUUFBUSxDQUFDO0FBQ3BFLENBQUM7QUFGRCw4Q0FFQztBQUVELFNBQWdCLGFBQWEsQ0FBQyxNQUFjO0lBQzFDLE9BQU8sT0FBTyxNQUFNLEtBQUssUUFBUSxDQUFDO0FBQ3BDLENBQUM7QUFGRCxzQ0FFQztBQUVELFNBQWdCLGlCQUFpQixDQUFDLEtBQVk7SUFDNUMsT0FBTyxLQUFLLENBQUMsSUFBSSxLQUFLLFFBQVEsSUFBSSxLQUFLLENBQUMsSUFBSSxLQUFLLGNBQWMsQ0FBQztBQUNsRSxDQUFDO0FBRkQsOENBRUM7QUFFRCxTQUFnQixnQkFBZ0IsQ0FBQyxLQUFZO0lBQzNDLE9BQU8sQ0FBQyxLQUFLLENBQUMsSUFBSSxLQUFLLFFBQVEsSUFBSSxLQUFLLENBQUMsSUFBSSxLQUFLLGNBQWMsQ0FBQyxJQUFJLE9BQU8sS0FBSyxDQUFDLFFBQVEsS0FBSyxRQUFRLENBQUM7QUFDMUcsQ0FBQztBQUZELDRDQUVDO0FBRUQsU0FBZ0IseUJBQXlCLENBQUMsS0FBWTtJQUNwRCxPQUFPLEtBQUssQ0FBQyxJQUFJLEtBQUssSUFBSSxDQUFDO0FBQzdCLENBQUM7QUFGRCw4REFFQztBQUVELFNBQWdCLGdCQUFnQixDQUFDLEtBQVk7SUFDM0MsT0FBTyxNQUFNLElBQUksS0FBSyxJQUFJLENBQUMseUJBQXlCLENBQUMsS0FBSyxDQUFDLENBQUM7QUFDOUQsQ0FBQztBQUZELDRDQUVDIn0=
|