@payloadcms/ui 3.35.0-internal.b3d367c → 3.35.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/dist/elements/BulkUpload/ActionsBar/index.scss +0 -4
- package/dist/elements/Button/index.scss +1 -1
- package/dist/elements/ColumnSelector/index.d.ts +1 -0
- package/dist/elements/ColumnSelector/index.d.ts.map +1 -1
- package/dist/elements/ColumnSelector/index.js +37 -34
- package/dist/elements/ColumnSelector/index.js.map +1 -1
- package/dist/elements/{PillSelector → ColumnSelector}/index.scss +5 -5
- package/dist/elements/FieldDiffLabel/index.scss +1 -1
- package/dist/elements/Localizer/LocalizerLabel/index.js +1 -2
- package/dist/elements/Localizer/LocalizerLabel/index.js.map +1 -1
- package/dist/elements/Localizer/LocalizerLabel/index.scss +1 -2
- package/dist/elements/PerPage/index.scss +0 -4
- package/dist/elements/Pill/index.scss +2 -1
- package/dist/elements/Popup/PopupTrigger/index.scss +3 -3
- package/dist/elements/QueryPresets/fields/ColumnsField/index.d.ts.map +1 -1
- package/dist/elements/QueryPresets/fields/ColumnsField/index.js +14 -24
- package/dist/elements/QueryPresets/fields/ColumnsField/index.js.map +1 -1
- package/dist/elements/QueryPresets/fields/WhereField/index.d.ts.map +1 -1
- package/dist/elements/QueryPresets/fields/WhereField/index.js +3 -15
- package/dist/elements/QueryPresets/fields/WhereField/index.js.map +1 -1
- package/dist/elements/ReactSelect/ValueContainer/index.d.ts.map +1 -1
- package/dist/elements/ReactSelect/ValueContainer/index.js +4 -7
- package/dist/elements/ReactSelect/ValueContainer/index.js.map +1 -1
- package/dist/elements/ReactSelect/ValueContainer/index.scss +0 -8
- package/dist/elements/ReactSelect/index.scss +0 -4
- package/dist/elements/ReactSelect/types.d.ts +0 -1
- package/dist/elements/ReactSelect/types.d.ts.map +1 -1
- package/dist/elements/ReactSelect/types.js.map +1 -1
- package/dist/elements/SortColumn/index.scss +1 -1
- package/dist/exports/client/index.d.ts +0 -4
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +11 -11
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/rsc/index.d.ts +0 -2
- package/dist/exports/rsc/index.d.ts.map +1 -1
- package/dist/exports/rsc/index.js +0 -2
- package/dist/exports/rsc/index.js.map +1 -1
- package/dist/fields/Array/index.d.ts.map +1 -1
- package/dist/fields/Array/index.js +5 -4
- package/dist/fields/Array/index.js.map +1 -1
- package/dist/fields/Blocks/index.d.ts.map +1 -1
- package/dist/fields/Blocks/index.js +5 -4
- package/dist/fields/Blocks/index.js.map +1 -1
- package/dist/fields/Checkbox/index.d.ts.map +1 -1
- package/dist/fields/Checkbox/index.js +3 -2
- package/dist/fields/Checkbox/index.js.map +1 -1
- package/dist/fields/Checkbox/index.scss +1 -1
- package/dist/fields/Code/index.d.ts.map +1 -1
- package/dist/fields/Code/index.js +3 -2
- package/dist/fields/Code/index.js.map +1 -1
- package/dist/fields/DateTime/index.d.ts.map +1 -1
- package/dist/fields/DateTime/index.js +3 -2
- package/dist/fields/DateTime/index.js.map +1 -1
- package/dist/fields/Email/index.d.ts.map +1 -1
- package/dist/fields/Email/index.js +4 -3
- package/dist/fields/Email/index.js.map +1 -1
- package/dist/fields/FieldLabel/index.d.ts.map +1 -1
- package/dist/fields/FieldLabel/index.js +1 -1
- package/dist/fields/FieldLabel/index.js.map +1 -1
- package/dist/fields/Hidden/index.d.ts.map +1 -1
- package/dist/fields/Hidden/index.js +6 -4
- package/dist/fields/Hidden/index.js.map +1 -1
- package/dist/fields/JSON/index.d.ts.map +1 -1
- package/dist/fields/JSON/index.js +3 -2
- package/dist/fields/JSON/index.js.map +1 -1
- package/dist/fields/Join/index.d.ts.map +1 -1
- package/dist/fields/Join/index.js +3 -2
- package/dist/fields/Join/index.js.map +1 -1
- package/dist/fields/Number/index.d.ts.map +1 -1
- package/dist/fields/Number/index.js +3 -2
- package/dist/fields/Number/index.js.map +1 -1
- package/dist/fields/Point/index.d.ts.map +1 -1
- package/dist/fields/Point/index.js +3 -2
- package/dist/fields/Point/index.js.map +1 -1
- package/dist/fields/RadioGroup/index.d.ts.map +1 -1
- package/dist/fields/RadioGroup/index.js +3 -2
- package/dist/fields/RadioGroup/index.js.map +1 -1
- package/dist/fields/Relationship/index.d.ts.map +1 -1
- package/dist/fields/Relationship/index.js +85 -22
- package/dist/fields/Relationship/index.js.map +1 -1
- package/dist/fields/Select/index.d.ts.map +1 -1
- package/dist/fields/Select/index.js +3 -2
- package/dist/fields/Select/index.js.map +1 -1
- package/dist/fields/Tabs/index.js +41 -51
- package/dist/fields/Tabs/index.js.map +1 -1
- package/dist/fields/Text/index.d.ts.map +1 -1
- package/dist/fields/Text/index.js +3 -2
- package/dist/fields/Text/index.js.map +1 -1
- package/dist/fields/Textarea/index.d.ts.map +1 -1
- package/dist/fields/Textarea/index.js +3 -2
- package/dist/fields/Textarea/index.js.map +1 -1
- package/dist/fields/Upload/index.d.ts.map +1 -1
- package/dist/fields/Upload/index.js +3 -2
- package/dist/fields/Upload/index.js.map +1 -1
- package/dist/forms/Form/fieldReducer.d.ts.map +1 -1
- package/dist/forms/Form/fieldReducer.js +3 -1
- package/dist/forms/Form/fieldReducer.js.map +1 -1
- package/dist/forms/RenderFields/context.d.ts +4 -0
- package/dist/forms/RenderFields/context.d.ts.map +1 -0
- package/dist/forms/RenderFields/context.js +11 -0
- package/dist/forms/RenderFields/context.js.map +1 -0
- package/dist/forms/RenderFields/index.d.ts.map +1 -1
- package/dist/forms/RenderFields/index.js +15 -11
- package/dist/forms/RenderFields/index.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js +1 -0
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/iterateFields.js +1 -0
- package/dist/forms/fieldSchemasToFormState/iterateFields.js.map +1 -1
- package/dist/forms/useField/index.d.ts +1 -1
- package/dist/forms/useField/index.d.ts.map +1 -1
- package/dist/forms/useField/index.js +128 -116
- package/dist/forms/useField/index.js.map +1 -1
- package/dist/forms/useField/types.d.ts +22 -1
- package/dist/forms/useField/types.d.ts.map +1 -1
- package/dist/forms/useField/types.js.map +1 -1
- package/dist/icons/Chevron/index.js +2 -2
- package/dist/icons/Chevron/index.js.map +1 -1
- package/dist/icons/Chevron/index.scss +4 -4
- package/dist/styles.css +1 -1
- package/package.json +4 -4
- package/dist/elements/FieldDiffContainer/index.d.ts +0 -15
- package/dist/elements/FieldDiffContainer/index.d.ts.map +0 -1
- package/dist/elements/FieldDiffContainer/index.js +0 -40
- package/dist/elements/FieldDiffContainer/index.js.map +0 -1
- package/dist/elements/FieldDiffContainer/index.scss +0 -42
- package/dist/elements/HTMLDiff/colors.scss +0 -35
- package/dist/elements/HTMLDiff/diff/index.d.ts +0 -75
- package/dist/elements/HTMLDiff/diff/index.d.ts.map +0 -1
- package/dist/elements/HTMLDiff/diff/index.js +0 -536
- package/dist/elements/HTMLDiff/diff/index.js.map +0 -1
- package/dist/elements/HTMLDiff/index.d.ts +0 -11
- package/dist/elements/HTMLDiff/index.d.ts.map +0 -1
- package/dist/elements/HTMLDiff/index.js +0 -32
- package/dist/elements/HTMLDiff/index.js.map +0 -1
- package/dist/elements/HTMLDiff/index.scss +0 -158
- package/dist/elements/PillSelector/index.d.ts +0 -26
- package/dist/elements/PillSelector/index.d.ts.map +0 -1
- package/dist/elements/PillSelector/index.js +0 -71
- package/dist/elements/PillSelector/index.js.map +0 -1
|
@@ -9,20 +9,32 @@ import { useDocumentInfo } from '../../providers/DocumentInfo/index.js';
|
|
|
9
9
|
import { useOperation } from '../../providers/Operation/index.js';
|
|
10
10
|
import { useTranslation } from '../../providers/Translation/index.js';
|
|
11
11
|
import { useDocumentForm, useForm, useFormFields, useFormInitializing, useFormModified, useFormProcessing, useFormSubmitted } from '../Form/context.js';
|
|
12
|
+
import { useFieldPath } from '../RenderFields/context.js';
|
|
12
13
|
/**
|
|
13
14
|
* Get and set the value of a form field.
|
|
14
15
|
*
|
|
15
16
|
* @see https://payloadcms.com/docs/admin/react-hooks#usefield
|
|
16
17
|
*/
|
|
17
18
|
export const useField = options => {
|
|
18
|
-
const $ = _c(
|
|
19
|
+
const $ = _c(64);
|
|
20
|
+
let t0;
|
|
21
|
+
if ($[0] !== options) {
|
|
22
|
+
t0 = options || {};
|
|
23
|
+
$[0] = options;
|
|
24
|
+
$[1] = t0;
|
|
25
|
+
} else {
|
|
26
|
+
t0 = $[1];
|
|
27
|
+
}
|
|
19
28
|
const {
|
|
20
|
-
disableFormData:
|
|
29
|
+
disableFormData: t1,
|
|
21
30
|
hasRows,
|
|
22
|
-
path,
|
|
31
|
+
path: pathFromOptions,
|
|
32
|
+
potentiallyStalePath,
|
|
23
33
|
validate
|
|
24
|
-
} =
|
|
25
|
-
const disableFormData =
|
|
34
|
+
} = t0;
|
|
35
|
+
const disableFormData = t1 === undefined ? false : t1;
|
|
36
|
+
const pathFromContext = useFieldPath();
|
|
37
|
+
const path = pathFromOptions || pathFromContext || potentiallyStalePath;
|
|
26
38
|
const submitted = useFormSubmitted();
|
|
27
39
|
const processing = useFormProcessing();
|
|
28
40
|
const initializing = useFormInitializing();
|
|
@@ -35,18 +47,18 @@ export const useField = options => {
|
|
|
35
47
|
} = useDocumentInfo();
|
|
36
48
|
const operation = useOperation();
|
|
37
49
|
const dispatchField = useFormFields(_temp);
|
|
38
|
-
let
|
|
39
|
-
if ($[
|
|
40
|
-
|
|
41
|
-
const [fields] =
|
|
50
|
+
let t2;
|
|
51
|
+
if ($[2] !== path) {
|
|
52
|
+
t2 = t3 => {
|
|
53
|
+
const [fields] = t3;
|
|
42
54
|
return fields && fields?.[path] || null;
|
|
43
55
|
};
|
|
44
|
-
$[
|
|
45
|
-
$[
|
|
56
|
+
$[2] = path;
|
|
57
|
+
$[3] = t2;
|
|
46
58
|
} else {
|
|
47
|
-
|
|
59
|
+
t2 = $[3];
|
|
48
60
|
}
|
|
49
|
-
const field = useFormFields(
|
|
61
|
+
const field = useFormFields(t2);
|
|
50
62
|
const {
|
|
51
63
|
t
|
|
52
64
|
} = useTranslation();
|
|
@@ -68,19 +80,19 @@ export const useField = options => {
|
|
|
68
80
|
const showError = valid === false && submitted;
|
|
69
81
|
const prevValid = useRef(valid);
|
|
70
82
|
const prevErrorMessage = useRef(field?.errorMessage);
|
|
71
|
-
let
|
|
72
|
-
if ($[
|
|
73
|
-
|
|
74
|
-
$[
|
|
75
|
-
$[
|
|
83
|
+
let t3;
|
|
84
|
+
if ($[4] !== path) {
|
|
85
|
+
t3 = path ? path.split(".") : [];
|
|
86
|
+
$[4] = path;
|
|
87
|
+
$[5] = t3;
|
|
76
88
|
} else {
|
|
77
|
-
|
|
89
|
+
t3 = $[5];
|
|
78
90
|
}
|
|
79
|
-
const pathSegments =
|
|
80
|
-
let
|
|
81
|
-
if ($[
|
|
82
|
-
|
|
83
|
-
const disableModifyingForm =
|
|
91
|
+
const pathSegments = t3;
|
|
92
|
+
let t4;
|
|
93
|
+
if ($[6] !== disableFormData || $[7] !== dispatchField || $[8] !== hasRows || $[9] !== modified || $[10] !== path || $[11] !== setModified) {
|
|
94
|
+
t4 = (e, t5) => {
|
|
95
|
+
const disableModifyingForm = t5 === undefined ? false : t5;
|
|
84
96
|
const val = e && e.target ? e.target.value : e;
|
|
85
97
|
dispatchField({
|
|
86
98
|
type: "UPDATE",
|
|
@@ -98,74 +110,74 @@ export const useField = options => {
|
|
|
98
110
|
}
|
|
99
111
|
}
|
|
100
112
|
};
|
|
101
|
-
$[
|
|
102
|
-
$[
|
|
103
|
-
$[
|
|
104
|
-
$[
|
|
105
|
-
$[
|
|
106
|
-
$[
|
|
107
|
-
$[
|
|
113
|
+
$[6] = disableFormData;
|
|
114
|
+
$[7] = dispatchField;
|
|
115
|
+
$[8] = hasRows;
|
|
116
|
+
$[9] = modified;
|
|
117
|
+
$[10] = path;
|
|
118
|
+
$[11] = setModified;
|
|
119
|
+
$[12] = t4;
|
|
108
120
|
} else {
|
|
109
|
-
|
|
121
|
+
t4 = $[12];
|
|
110
122
|
}
|
|
111
|
-
const setValue =
|
|
112
|
-
let
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
let
|
|
117
|
-
if ($[
|
|
118
|
-
|
|
119
|
-
$[
|
|
120
|
-
$[
|
|
123
|
+
const setValue = t4;
|
|
124
|
+
let t5;
|
|
125
|
+
const t6 = field?.customComponents;
|
|
126
|
+
const t7 = processing || initializing;
|
|
127
|
+
const t8 = field?.errorMessage;
|
|
128
|
+
let t9;
|
|
129
|
+
if ($[13] !== field?.errorPaths) {
|
|
130
|
+
t9 = field?.errorPaths || [];
|
|
131
|
+
$[13] = field?.errorPaths;
|
|
132
|
+
$[14] = t9;
|
|
121
133
|
} else {
|
|
122
|
-
|
|
134
|
+
t9 = $[14];
|
|
123
135
|
}
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
let
|
|
127
|
-
if ($[
|
|
128
|
-
|
|
129
|
-
customComponents:
|
|
130
|
-
disabled:
|
|
131
|
-
errorMessage:
|
|
132
|
-
errorPaths:
|
|
136
|
+
const t10 = field?.rows;
|
|
137
|
+
const t11 = field?.valid;
|
|
138
|
+
let t12;
|
|
139
|
+
if ($[15] !== filterOptions || $[16] !== initialValue || $[17] !== initializing || $[18] !== path || $[19] !== processing || $[20] !== setValue || $[21] !== showError || $[22] !== submitted || $[23] !== t10 || $[24] !== t11 || $[25] !== t6 || $[26] !== t7 || $[27] !== t8 || $[28] !== t9 || $[29] !== value) {
|
|
140
|
+
t12 = {
|
|
141
|
+
customComponents: t6,
|
|
142
|
+
disabled: t7,
|
|
143
|
+
errorMessage: t8,
|
|
144
|
+
errorPaths: t9,
|
|
133
145
|
filterOptions,
|
|
134
146
|
formInitializing: initializing,
|
|
135
147
|
formProcessing: processing,
|
|
136
148
|
formSubmitted: submitted,
|
|
137
149
|
initialValue,
|
|
138
150
|
path,
|
|
139
|
-
rows:
|
|
151
|
+
rows: t10,
|
|
140
152
|
setValue,
|
|
141
153
|
showError,
|
|
142
|
-
valid:
|
|
154
|
+
valid: t11,
|
|
143
155
|
value
|
|
144
156
|
};
|
|
145
|
-
$[
|
|
146
|
-
$[
|
|
147
|
-
$[
|
|
148
|
-
$[
|
|
149
|
-
$[
|
|
150
|
-
$[
|
|
151
|
-
$[
|
|
152
|
-
$[
|
|
153
|
-
$[
|
|
154
|
-
$[
|
|
155
|
-
$[
|
|
156
|
-
$[
|
|
157
|
-
$[
|
|
158
|
-
$[
|
|
159
|
-
$[
|
|
160
|
-
$[
|
|
157
|
+
$[15] = filterOptions;
|
|
158
|
+
$[16] = initialValue;
|
|
159
|
+
$[17] = initializing;
|
|
160
|
+
$[18] = path;
|
|
161
|
+
$[19] = processing;
|
|
162
|
+
$[20] = setValue;
|
|
163
|
+
$[21] = showError;
|
|
164
|
+
$[22] = submitted;
|
|
165
|
+
$[23] = t10;
|
|
166
|
+
$[24] = t11;
|
|
167
|
+
$[25] = t6;
|
|
168
|
+
$[26] = t7;
|
|
169
|
+
$[27] = t8;
|
|
170
|
+
$[28] = t9;
|
|
171
|
+
$[29] = value;
|
|
172
|
+
$[30] = t12;
|
|
161
173
|
} else {
|
|
162
|
-
|
|
174
|
+
t12 = $[30];
|
|
163
175
|
}
|
|
164
|
-
|
|
165
|
-
const result =
|
|
166
|
-
let
|
|
167
|
-
if ($[
|
|
168
|
-
|
|
176
|
+
t5 = t12;
|
|
177
|
+
const result = t5;
|
|
178
|
+
let t13;
|
|
179
|
+
if ($[31] !== collectionSlug || $[32] !== config || $[33] !== disableFormData || $[34] !== dispatchField || $[35] !== documentForm || $[36] !== field || $[37] !== getData || $[38] !== getDataByPath || $[39] !== getSiblingData || $[40] !== hasRows || $[41] !== id || $[42] !== operation || $[43] !== path || $[44] !== pathSegments || $[45] !== t || $[46] !== user || $[47] !== validate || $[48] !== value) {
|
|
180
|
+
t13 = () => {
|
|
169
181
|
const validateField = async () => {
|
|
170
182
|
let valueToValidate = value;
|
|
171
183
|
if (field?.rows && Array.isArray(field.rows)) {
|
|
@@ -223,50 +235,50 @@ export const useField = options => {
|
|
|
223
235
|
};
|
|
224
236
|
validateField();
|
|
225
237
|
};
|
|
226
|
-
$[
|
|
227
|
-
$[
|
|
228
|
-
$[
|
|
229
|
-
$[
|
|
230
|
-
$[
|
|
231
|
-
$[
|
|
232
|
-
$[
|
|
233
|
-
$[
|
|
234
|
-
$[
|
|
235
|
-
$[
|
|
236
|
-
$[
|
|
237
|
-
$[
|
|
238
|
-
$[
|
|
239
|
-
$[
|
|
240
|
-
$[
|
|
241
|
-
$[
|
|
242
|
-
$[
|
|
243
|
-
$[
|
|
244
|
-
$[
|
|
238
|
+
$[31] = collectionSlug;
|
|
239
|
+
$[32] = config;
|
|
240
|
+
$[33] = disableFormData;
|
|
241
|
+
$[34] = dispatchField;
|
|
242
|
+
$[35] = documentForm;
|
|
243
|
+
$[36] = field;
|
|
244
|
+
$[37] = getData;
|
|
245
|
+
$[38] = getDataByPath;
|
|
246
|
+
$[39] = getSiblingData;
|
|
247
|
+
$[40] = hasRows;
|
|
248
|
+
$[41] = id;
|
|
249
|
+
$[42] = operation;
|
|
250
|
+
$[43] = path;
|
|
251
|
+
$[44] = pathSegments;
|
|
252
|
+
$[45] = t;
|
|
253
|
+
$[46] = user;
|
|
254
|
+
$[47] = validate;
|
|
255
|
+
$[48] = value;
|
|
256
|
+
$[49] = t13;
|
|
245
257
|
} else {
|
|
246
|
-
|
|
258
|
+
t13 = $[49];
|
|
247
259
|
}
|
|
248
|
-
const
|
|
249
|
-
let
|
|
250
|
-
if ($[
|
|
251
|
-
|
|
252
|
-
$[
|
|
253
|
-
$[
|
|
254
|
-
$[
|
|
255
|
-
$[
|
|
256
|
-
$[
|
|
257
|
-
$[
|
|
258
|
-
$[
|
|
259
|
-
$[
|
|
260
|
-
$[
|
|
261
|
-
$[
|
|
262
|
-
$[
|
|
263
|
-
$[
|
|
264
|
-
$[
|
|
265
|
-
$[
|
|
260
|
+
const t14 = field?.rows;
|
|
261
|
+
let t15;
|
|
262
|
+
if ($[50] !== collectionSlug || $[51] !== disableFormData || $[52] !== dispatchField || $[53] !== getData || $[54] !== getDataByPath || $[55] !== getSiblingData || $[56] !== id || $[57] !== operation || $[58] !== path || $[59] !== t14 || $[60] !== user || $[61] !== validate || $[62] !== value) {
|
|
263
|
+
t15 = [value, disableFormData, dispatchField, getData, getSiblingData, getDataByPath, id, operation, path, user, validate, t14, collectionSlug];
|
|
264
|
+
$[50] = collectionSlug;
|
|
265
|
+
$[51] = disableFormData;
|
|
266
|
+
$[52] = dispatchField;
|
|
267
|
+
$[53] = getData;
|
|
268
|
+
$[54] = getDataByPath;
|
|
269
|
+
$[55] = getSiblingData;
|
|
270
|
+
$[56] = id;
|
|
271
|
+
$[57] = operation;
|
|
272
|
+
$[58] = path;
|
|
273
|
+
$[59] = t14;
|
|
274
|
+
$[60] = user;
|
|
275
|
+
$[61] = validate;
|
|
276
|
+
$[62] = value;
|
|
277
|
+
$[63] = t15;
|
|
266
278
|
} else {
|
|
267
|
-
|
|
279
|
+
t15 = $[63];
|
|
268
280
|
}
|
|
269
|
-
useThrottledEffect(
|
|
281
|
+
useThrottledEffect(t13, 150, t15);
|
|
270
282
|
return result;
|
|
271
283
|
};
|
|
272
284
|
function _temp(t0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","useCallback","useMemo","useRef","useThrottledEffect","useAuth","useConfig","useDocumentInfo","useOperation","useTranslation","useDocumentForm","useForm","useFormFields","useFormInitializing","useFormModified","useFormProcessing","useFormSubmitted","useField","options","$","disableFormData","t0","hasRows","path","validate","undefined","submitted","processing","initializing","user","id","collectionSlug","operation","dispatchField","_temp","t1","t2","fields","field","t","config","getData","getDataByPath","getSiblingData","setModified","documentForm","modified","filterOptions","value","initialValue","valid","showError","prevValid","prevErrorMessage","errorMessage","split","pathSegments","t3","e","t4","disableModifyingForm","val","target","type","setTimeout","setValue","t5","customComponents","t6","t7","t8","errorPaths","t9","rows","t10","t11","disabled","formInitializing","formProcessing","formSubmitted","result","t12","validateField","valueToValidate","Array","isArray","current","valid_0","data","isValid","blockData","event","preferences","req","payload","siblingData","update","t13","t14","dispatch"],"sources":["../../../src/forms/useField/index.tsx"],"sourcesContent":["'use client'\nimport type { PayloadRequest } from 'payload'\n\nimport { useCallback, useMemo, useRef } from 'react'\n\nimport type { UPDATE } from '../Form/types.js'\nimport type { FieldType, Options } from './types.js'\n\nexport type { FieldType, Options }\n\nimport { useThrottledEffect } from '../../hooks/useThrottledEffect.js'\nimport { useAuth } from '../../providers/Auth/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useOperation } from '../../providers/Operation/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport {\n useDocumentForm,\n useForm,\n useFormFields,\n useFormInitializing,\n useFormModified,\n useFormProcessing,\n useFormSubmitted,\n} from '../Form/context.js'\n\n/**\n * Get and set the value of a form field.\n *\n * @see https://payloadcms.com/docs/admin/react-hooks#usefield\n */\nexport const useField = <TValue,>(options: Options): FieldType<TValue> => {\n const { disableFormData = false, hasRows, path, validate } = options\n\n const submitted = useFormSubmitted()\n const processing = useFormProcessing()\n const initializing = useFormInitializing()\n const { user } = useAuth()\n const { id, collectionSlug } = useDocumentInfo()\n const operation = useOperation()\n\n const dispatchField = useFormFields(([_, dispatch]) => dispatch)\n const field = useFormFields(([fields]) => (fields && fields?.[path]) || null)\n\n const { t } = useTranslation()\n const { config } = useConfig()\n\n const { getData, getDataByPath, getSiblingData, setModified } = useForm()\n const documentForm = useDocumentForm()\n const modified = useFormModified()\n\n const filterOptions = field?.filterOptions\n const value = field?.value as TValue\n const initialValue = field?.initialValue as TValue\n const valid = typeof field?.valid === 'boolean' ? field.valid : true\n const showError = valid === false && submitted\n\n const prevValid = useRef(valid)\n const prevErrorMessage = useRef(field?.errorMessage)\n\n const pathSegments = path ? path.split('.') : []\n\n // Method to return from `useField`, used to\n // update field values from field component(s)\n const setValue = useCallback(\n (e, disableModifyingForm = false) => {\n const val = e && e.target ? e.target.value : e\n dispatchField({\n type: 'UPDATE',\n disableFormData: disableFormData || (hasRows && val > 0),\n path,\n value: val,\n })\n\n if (!disableModifyingForm) {\n if (typeof setModified === 'function') {\n // Only update setModified to true if the form is not already set to modified. Otherwise the following could happen:\n // 1. Text field: someone types in it in an unmodified form\n // 2. After setTimeout triggers setModified(true): form is set to modified. Save Button becomes available. Good!\n // 3. Type something in text field\n // 4. Click on save button before setTimeout in useField has finished (so setModified(true) has not been run yet)\n // 5. Form is saved, setModified(false) is set in the Form/index.tsx `submit` function, \"saved successfully\" toast appears\n // 6. setModified(true) inside the timeout is run, form is set to modified again, even though it was already saved and thus set to unmodified. Bad! This should have happened before the form is saved. Now the form should be unmodified and stay that way\n // until a NEW change happens. Due to this, the \"Leave without saving\" modal appears even though it should not when leaving the page fast immediately after saving the document.\n // This is only an issue for forms which have already been set to modified true, as that causes the save button to be enabled. If we prevent this setTimeout to be run\n // for already-modified forms first place (which is unnecessary), we can avoid this issue. As for unmodified forms, this race issue will not happen, because you cannot click the save button faster\n // than the timeout in useField is run. That's because the save button won't even be enabled for clicking until the setTimeout in useField has run.\n // This fixes e2e test flakes, as e2e tests were often so fast that they were saving the form before the timeout in useField has run.\n // Specifically, this fixes the 'should not warn about unsaved changes when navigating to lexical editor with blocks node and then leaving the page after making a change and saving' lexical e2e test.\n if (modified === false) {\n // Update modified state after field value comes back\n // to avoid cursor jump caused by state value / DOM mismatch\n setTimeout(() => {\n setModified(true)\n }, 10)\n }\n }\n }\n },\n [setModified, path, dispatchField, disableFormData, hasRows, modified],\n )\n\n // Store result from hook as ref\n // to prevent unnecessary rerenders\n const result: FieldType<TValue> = useMemo(\n () => ({\n customComponents: field?.customComponents,\n disabled: processing || initializing,\n errorMessage: field?.errorMessage,\n errorPaths: field?.errorPaths || [],\n filterOptions,\n formInitializing: initializing,\n formProcessing: processing,\n formSubmitted: submitted,\n initialValue,\n path,\n rows: field?.rows,\n setValue,\n showError,\n valid: field?.valid,\n value,\n }),\n [\n field,\n processing,\n setValue,\n showError,\n submitted,\n value,\n initialValue,\n path,\n filterOptions,\n initializing,\n ],\n )\n\n // Throttle the validate function\n useThrottledEffect(\n () => {\n const validateField = async () => {\n let valueToValidate = value\n\n if (field?.rows && Array.isArray(field.rows)) {\n valueToValidate = getDataByPath(path)\n }\n\n let errorMessage: string | undefined = prevErrorMessage.current\n let valid: boolean | string = prevValid.current\n\n const data = getData()\n const isValid =\n typeof validate === 'function'\n ? await validate(valueToValidate, {\n id,\n blockData: undefined, // Will be expensive to get - not worth to pass to client-side validation, as this can be obtained by the user using `useFormFields()`\n collectionSlug,\n data: documentForm?.getData ? documentForm.getData() : data,\n event: 'onChange',\n operation,\n path: pathSegments,\n preferences: {} as any,\n req: {\n payload: {\n config,\n },\n t,\n user,\n } as unknown as PayloadRequest,\n siblingData: getSiblingData(path),\n })\n : typeof prevErrorMessage.current === 'string'\n ? prevErrorMessage.current\n : prevValid.current\n\n if (typeof isValid === 'string') {\n valid = false\n errorMessage = isValid\n } else if (typeof isValid === 'boolean') {\n valid = isValid\n errorMessage = undefined\n }\n\n // Only dispatch if the validation result has changed\n // This will prevent unnecessary rerenders\n if (valid !== prevValid.current || errorMessage !== prevErrorMessage.current) {\n prevValid.current = valid\n prevErrorMessage.current = errorMessage\n\n const update: UPDATE = {\n type: 'UPDATE',\n errorMessage,\n path,\n rows: field?.rows,\n valid,\n validate,\n value,\n }\n\n if (disableFormData || (hasRows ? typeof value === 'number' && value > 0 : false)) {\n update.disableFormData = true\n }\n\n if (typeof dispatchField === 'function') {\n dispatchField(update)\n }\n }\n }\n\n void validateField()\n },\n 150,\n [\n value,\n disableFormData,\n dispatchField,\n getData,\n getSiblingData,\n getDataByPath,\n id,\n operation,\n path,\n user,\n valid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A;IAAAJ,CAAA,OAAA8E,GAAA;IAAA9E,CAAA,OAAAU,IAAA;IAAAV,CAAA,OAAAK,QAAA;IAAAL,CAAA,OAAA6B,KAAA;IAAA7B,CAAA,OAAA+E,GAAA;EAAA;IAAAA,GAAA,GAAA/E,CAAA;EAAA;EAxFHf,kBAAA,CACE6E,GAuEA,OAEAiB,GAcC;EAAA,OAGIlB,MAAA;AAAA,CACT;AAtMwB,SAAA9C,MAAAb,EAAA;EAUe,SAAA8E,QAAA,IAAA9E,EAAa;EAAA,OAAK8E,QAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","useCallback","useMemo","useRef","useThrottledEffect","useAuth","useConfig","useDocumentInfo","useOperation","useTranslation","useDocumentForm","useForm","useFormFields","useFormInitializing","useFormModified","useFormProcessing","useFormSubmitted","useFieldPath","useField","options","$","t0","disableFormData","t1","hasRows","path","pathFromOptions","potentiallyStalePath","validate","undefined","pathFromContext","submitted","processing","initializing","user","id","collectionSlug","operation","dispatchField","_temp","t2","t3","fields","field","t","config","getData","getDataByPath","getSiblingData","setModified","documentForm","modified","filterOptions","value","initialValue","valid","showError","prevValid","prevErrorMessage","errorMessage","split","pathSegments","t4","e","t5","disableModifyingForm","val","target","type","setTimeout","setValue","t6","customComponents","t7","t8","t9","errorPaths","t10","rows","t11","t12","disabled","formInitializing","formProcessing","formSubmitted","result","t13","validateField","valueToValidate","Array","isArray","current","valid_0","data","isValid","blockData","event","preferences","req","payload","siblingData","update","t14","t15","dispatch"],"sources":["../../../src/forms/useField/index.tsx"],"sourcesContent":["'use client'\nimport type { PayloadRequest } from 'payload'\n\nimport { useCallback, useMemo, useRef } from 'react'\n\nimport type { UPDATE } from '../Form/types.js'\nimport type { FieldType, Options } from './types.js'\n\nexport type { FieldType, Options }\n\nimport { useThrottledEffect } from '../../hooks/useThrottledEffect.js'\nimport { useAuth } from '../../providers/Auth/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useOperation } from '../../providers/Operation/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport {\n useDocumentForm,\n useForm,\n useFormFields,\n useFormInitializing,\n useFormModified,\n useFormProcessing,\n useFormSubmitted,\n} from '../Form/context.js'\nimport { useFieldPath } from '../RenderFields/context.js'\n\n/**\n * Get and set the value of a form field.\n *\n * @see https://payloadcms.com/docs/admin/react-hooks#usefield\n */\nexport const useField = <TValue,>(options?: Options): FieldType<TValue> => {\n const {\n disableFormData = false,\n hasRows,\n path: pathFromOptions,\n potentiallyStalePath,\n validate,\n } = options || {}\n\n const pathFromContext = useFieldPath()\n\n // This is a workaround for stale props given to server rendered components.\n // See the notes in the `potentiallyStalePath` type definition for more details.\n const path = pathFromOptions || pathFromContext || potentiallyStalePath\n\n const submitted = useFormSubmitted()\n const processing = useFormProcessing()\n const initializing = useFormInitializing()\n const { user } = useAuth()\n const { id, collectionSlug } = useDocumentInfo()\n const operation = useOperation()\n\n const dispatchField = useFormFields(([_, dispatch]) => dispatch)\n const field = useFormFields(([fields]) => (fields && fields?.[path]) || null)\n\n const { t } = useTranslation()\n const { config } = useConfig()\n\n const { getData, getDataByPath, getSiblingData, setModified } = useForm()\n const documentForm = useDocumentForm()\n const modified = useFormModified()\n\n const filterOptions = field?.filterOptions\n const value = field?.value as TValue\n const initialValue = field?.initialValue as TValue\n const valid = typeof field?.valid === 'boolean' ? field.valid : true\n const showError = valid === false && submitted\n\n const prevValid = useRef(valid)\n const prevErrorMessage = useRef(field?.errorMessage)\n\n const pathSegments = path ? path.split('.') : []\n\n // Method to return from `useField`, used to\n // update field values from field component(s)\n const setValue = useCallback(\n (e, disableModifyingForm = false) => {\n const val = e && e.target ? e.target.value : e\n dispatchField({\n type: 'UPDATE',\n disableFormData: disableFormData || (hasRows && val > 0),\n path,\n value: val,\n })\n\n if (!disableModifyingForm) {\n if (typeof setModified === 'function') {\n // Only update setModified to true if the form is not already set to modified. Otherwise the following could happen:\n // 1. Text field: someone types in it in an unmodified form\n // 2. After setTimeout triggers setModified(true): form is set to modified. Save Button becomes available. Good!\n // 3. Type something in text field\n // 4. Click on save button before setTimeout in useField has finished (so setModified(true) has not been run yet)\n // 5. Form is saved, setModified(false) is set in the Form/index.tsx `submit` function, \"saved successfully\" toast appears\n // 6. setModified(true) inside the timeout is run, form is set to modified again, even though it was already saved and thus set to unmodified. Bad! This should have happened before the form is saved. Now the form should be unmodified and stay that way\n // until a NEW change happens. Due to this, the \"Leave without saving\" modal appears even though it should not when leaving the page fast immediately after saving the document.\n // This is only an issue for forms which have already been set to modified true, as that causes the save button to be enabled. If we prevent this setTimeout to be run\n // for already-modified forms first place (which is unnecessary), we can avoid this issue. As for unmodified forms, this race issue will not happen, because you cannot click the save button faster\n // than the timeout in useField is run. That's because the save button won't even be enabled for clicking until the setTimeout in useField has run.\n // This fixes e2e test flakes, as e2e tests were often so fast that they were saving the form before the timeout in useField has run.\n // Specifically, this fixes the 'should not warn about unsaved changes when navigating to lexical editor with blocks node and then leaving the page after making a change and saving' lexical e2e test.\n if (modified === false) {\n // Update modified state after field value comes back\n // to avoid cursor jump caused by state value / DOM mismatch\n setTimeout(() => {\n setModified(true)\n }, 10)\n }\n }\n }\n },\n [setModified, path, dispatchField, disableFormData, hasRows, modified],\n )\n\n // Store result from hook as ref\n // to prevent unnecessary rerenders\n const result: FieldType<TValue> = useMemo(\n () => ({\n customComponents: field?.customComponents,\n disabled: processing || initializing,\n errorMessage: field?.errorMessage,\n errorPaths: field?.errorPaths || [],\n filterOptions,\n formInitializing: initializing,\n formProcessing: processing,\n formSubmitted: submitted,\n initialValue,\n path,\n rows: field?.rows,\n setValue,\n showError,\n valid: field?.valid,\n value,\n }),\n [\n field,\n processing,\n setValue,\n showError,\n submitted,\n value,\n initialValue,\n path,\n filterOptions,\n initializing,\n ],\n )\n\n // Throttle the validate function\n useThrottledEffect(\n () => {\n const validateField = async () => {\n let valueToValidate = value\n\n if (field?.rows && Array.isArray(field.rows)) {\n valueToValidate = getDataByPath(path)\n }\n\n let errorMessage: string | undefined = prevErrorMessage.current\n let valid: boolean | string = prevValid.current\n\n const data = getData()\n const isValid =\n typeof validate === 'function'\n ? await validate(valueToValidate, {\n id,\n blockData: undefined, // Will be expensive to get - not worth to pass to client-side validation, as this can be obtained by the user using `useFormFields()`\n collectionSlug,\n data: documentForm?.getData ? documentForm.getData() : data,\n event: 'onChange',\n operation,\n path: pathSegments,\n preferences: {} as any,\n req: {\n payload: {\n config,\n },\n t,\n user,\n } as unknown as PayloadRequest,\n siblingData: getSiblingData(path),\n })\n : typeof prevErrorMessage.current === 'string'\n ? prevErrorMessage.current\n : prevValid.current\n\n if (typeof isValid === 'string') {\n valid = false\n errorMessage = isValid\n } else if (typeof isValid === 'boolean') {\n valid = isValid\n errorMessage = undefined\n }\n\n // Only dispatch if the validation result has changed\n // This will prevent unnecessary rerenders\n if (valid !== prevValid.current || errorMessage !== prevErrorMessage.current) {\n prevValid.current = valid\n prevErrorMessage.current = errorMessage\n\n const update: UPDATE = {\n type: 'UPDATE',\n errorMessage,\n path,\n rows: field?.rows,\n valid,\n validate,\n value,\n }\n\n if (disableFormData || (hasRows ? typeof value === 'number' && value > 0 : false)) {\n update.disableFormData = true\n }\n\n if (typeof dispatchField === 'function') {\n dispatchField(update)\n }\n }\n }\n\n void validateField()\n },\n 150,\n [\n value,\n disableFormData,\n dispatchField,\n getData,\n getSiblingData,\n getDataByPath,\n id,\n operation,\n path,\n user,\n validate,\n field?.rows,\n collectionSlug,\n ],\n )\n\n return result\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAGA,SAASC,WAAW,EAAEC,OAAO,EAAEC,MAAM,QAAQ;AAO7C,SAASC,kBAAkB,QAAQ;AACnC,SAASC,OAAO,QAAQ;AACxB,SAASC,SAAS,QAAQ;AAC1B,SAASC,eAAe,QAAQ;AAChC,SAASC,YAAY,QAAQ;AAC7B,SAASC,cAAc,QAAQ;AAC/B,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IAAAf,CAAA,OAAAiB,SAAA;IAAAjB,CAAA,OAAAK,IAAA;IAAAL,CAAA,OAAAkF,GAAA;IAAAlF,CAAA,OAAAc,IAAA;IAAAd,CAAA,OAAAQ,QAAA;IAAAR,CAAA,OAAAiC,KAAA;IAAAjC,CAAA,OAAAmF,GAAA;EAAA;IAAAA,GAAA,GAAAnF,CAAA;EAAA;EAxFHhB,kBAAA,CACEkF,GAuEA,OAEAiB,GAcC;EAAA,OAGIlB,MAAA;AAAA,CACT;AAlNwB,SAAA9C,MAAAlB,EAAA;EAsBe,SAAAmF,QAAA,IAAAnF,EAAa;EAAA,OAAKmF,QAAA;AAAA","ignoreList":[]}
|
|
@@ -2,7 +2,27 @@ import type { FieldState, FilterOptionsResult, Row, Validate } from 'payload';
|
|
|
2
2
|
export type Options = {
|
|
3
3
|
disableFormData?: boolean;
|
|
4
4
|
hasRows?: boolean;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* If `path` is provided to this hook, it will be used outright. This is useful when calling this hook directly within a custom component.
|
|
7
|
+
* Otherwise, the field will attempt to get the path from the `FieldPathContext` via the `useFieldPath` hook.
|
|
8
|
+
* If still not found, the `potentiallyStalePath` arg will be used. See the note below about why this is important.
|
|
9
|
+
*/
|
|
10
|
+
path?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Custom server components receive a static `path` prop at render-time, leading to temporarily stale paths when re-ordering rows in form state.
|
|
13
|
+
* This is because when manipulating rows, field paths change in form state, but the prop remains the same until the component is re-rendered on the server.
|
|
14
|
+
* This causes the component to temporarily point to the wrong field in form state until the server responds with a freshly rendered component.
|
|
15
|
+
* To prevent this, fields are wrapped with a `FieldPathContext` which is guaranteed to be up-to-date.
|
|
16
|
+
* The `path` prop that Payload's default fields receive, then, are sent into this hook as the `potentiallyStalePath` arg.
|
|
17
|
+
* This ensures that:
|
|
18
|
+
* 1. Custom components that use this hook directly will still respect the `path` prop as top priority.
|
|
19
|
+
* 2. Custom server components that blindly spread their props into default Payload fields still prefer the dynamic path from context.
|
|
20
|
+
* 3. Components that render default Payload fields directly do not require a `FieldPathProvider`, e.g. the email field in the account view.
|
|
21
|
+
*/
|
|
22
|
+
potentiallyStalePath?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Client-side validation function fired when the form is submitted.
|
|
25
|
+
*/
|
|
6
26
|
validate?: Validate;
|
|
7
27
|
};
|
|
8
28
|
export type FieldType<T> = {
|
|
@@ -15,6 +35,7 @@ export type FieldType<T> = {
|
|
|
15
35
|
formProcessing: boolean;
|
|
16
36
|
formSubmitted: boolean;
|
|
17
37
|
initialValue?: T;
|
|
38
|
+
path: string;
|
|
18
39
|
readOnly?: boolean;
|
|
19
40
|
rows?: Row[];
|
|
20
41
|
setValue: (val: unknown, disableModifyingForm?: boolean) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/forms/useField/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAE7E,MAAM,MAAM,OAAO,GAAG;IACpB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/forms/useField/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAE7E,MAAM,MAAM,OAAO,GAAG;IACpB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;;;;;;;OAUG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,gBAAgB,CAAC,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAA;IACjD,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC,gBAAgB,EAAE,OAAO,CAAA;IACzB,cAAc,EAAE,OAAO,CAAA;IACvB,aAAa,EAAE,OAAO,CAAA;IACtB,YAAY,CAAC,EAAE,CAAC,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;IACZ,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,oBAAoB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IAChE,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,EAAE,CAAC,CAAA;CACT,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/forms/useField/types.ts"],"sourcesContent":["import type { FieldState, FilterOptionsResult, Row, Validate } from 'payload'\n\nexport type Options = {\n disableFormData?: boolean\n hasRows?: boolean\n path
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/forms/useField/types.ts"],"sourcesContent":["import type { FieldState, FilterOptionsResult, Row, Validate } from 'payload'\n\nexport type Options = {\n disableFormData?: boolean\n hasRows?: boolean\n /**\n * If `path` is provided to this hook, it will be used outright. This is useful when calling this hook directly within a custom component.\n * Otherwise, the field will attempt to get the path from the `FieldPathContext` via the `useFieldPath` hook.\n * If still not found, the `potentiallyStalePath` arg will be used. See the note below about why this is important.\n */\n path?: string\n /**\n * Custom server components receive a static `path` prop at render-time, leading to temporarily stale paths when re-ordering rows in form state.\n * This is because when manipulating rows, field paths change in form state, but the prop remains the same until the component is re-rendered on the server.\n * This causes the component to temporarily point to the wrong field in form state until the server responds with a freshly rendered component.\n * To prevent this, fields are wrapped with a `FieldPathContext` which is guaranteed to be up-to-date.\n * The `path` prop that Payload's default fields receive, then, are sent into this hook as the `potentiallyStalePath` arg.\n * This ensures that:\n * 1. Custom components that use this hook directly will still respect the `path` prop as top priority.\n * 2. Custom server components that blindly spread their props into default Payload fields still prefer the dynamic path from context.\n * 3. Components that render default Payload fields directly do not require a `FieldPathProvider`, e.g. the email field in the account view.\n */\n potentiallyStalePath?: string\n /**\n * Client-side validation function fired when the form is submitted.\n */\n validate?: Validate\n}\n\nexport type FieldType<T> = {\n customComponents?: FieldState['customComponents']\n disabled: boolean\n errorMessage?: string\n errorPaths?: string[]\n filterOptions?: FilterOptionsResult\n formInitializing: boolean\n formProcessing: boolean\n formSubmitted: boolean\n initialValue?: T\n path: string\n readOnly?: boolean\n rows?: Row[]\n setValue: (val: unknown, disableModifyingForm?: boolean) => void\n showError: boolean\n valid?: boolean\n value: T\n}\n"],"mappings":"AA6BA","ignoreList":[]}
|
|
@@ -13,12 +13,12 @@ export const ChevronIcon = ({
|
|
|
13
13
|
style: {
|
|
14
14
|
transform: direction === 'left' ? 'rotate(90deg)' : direction === 'right' ? 'rotate(-90deg)' : direction === 'up' ? 'rotate(180deg)' : undefined
|
|
15
15
|
},
|
|
16
|
-
viewBox: "0 0
|
|
16
|
+
viewBox: "0 0 20 20",
|
|
17
17
|
width: "100%",
|
|
18
18
|
xmlns: "http://www.w3.org/2000/svg",
|
|
19
19
|
children: /*#__PURE__*/_jsx("path", {
|
|
20
20
|
className: "stroke",
|
|
21
|
-
d: "
|
|
21
|
+
d: "M14 8L10 12L6 8",
|
|
22
22
|
strokeLinecap: "square"
|
|
23
23
|
})
|
|
24
24
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","ChevronIcon","ariaLabel","className","direction","size","_jsx","filter","Boolean","join","height","style","transform","undefined","viewBox","width","xmlns","d","strokeLinecap"],"sources":["../../../src/icons/Chevron/index.tsx"],"sourcesContent":["import React from 'react'\n\nimport './index.scss'\n\nexport const ChevronIcon: React.FC<{\n readonly ariaLabel?: string\n readonly className?: string\n readonly direction?: 'down' | 'left' | 'right' | 'up'\n readonly size?: 'large' | 'small'\n}> = ({ ariaLabel, className, direction, size }) => (\n <svg\n aria-label={ariaLabel}\n className={['icon icon--chevron', className, size && `icon--size-${size}`]\n .filter(Boolean)\n .join(' ')}\n height=\"100%\"\n style={{\n transform:\n direction === 'left'\n ? 'rotate(90deg)'\n : direction === 'right'\n ? 'rotate(-90deg)'\n : direction === 'up'\n ? 'rotate(180deg)'\n : undefined,\n }}\n viewBox=\"0 0
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","ChevronIcon","ariaLabel","className","direction","size","_jsx","filter","Boolean","join","height","style","transform","undefined","viewBox","width","xmlns","d","strokeLinecap"],"sources":["../../../src/icons/Chevron/index.tsx"],"sourcesContent":["import React from 'react'\n\nimport './index.scss'\n\nexport const ChevronIcon: React.FC<{\n readonly ariaLabel?: string\n readonly className?: string\n readonly direction?: 'down' | 'left' | 'right' | 'up'\n readonly size?: 'large' | 'small'\n}> = ({ ariaLabel, className, direction, size }) => (\n <svg\n aria-label={ariaLabel}\n className={['icon icon--chevron', className, size && `icon--size-${size}`]\n .filter(Boolean)\n .join(' ')}\n height=\"100%\"\n style={{\n transform:\n direction === 'left'\n ? 'rotate(90deg)'\n : direction === 'right'\n ? 'rotate(-90deg)'\n : direction === 'up'\n ? 'rotate(180deg)'\n : undefined,\n }}\n viewBox=\"0 0 20 20\"\n width=\"100%\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path className=\"stroke\" d=\"M14 8L10 12L6 8\" strokeLinecap=\"square\" />\n </svg>\n)\n"],"mappings":";AAAA,OAAOA,KAAA,MAAW;AAElB,OAAO;AAEP,OAAO,MAAMC,WAAA,GAKRA,CAAC;EAAEC,SAAS;EAAEC,SAAS;EAAEC,SAAS;EAAEC;AAAI,CAAE,kBAC7CC,IAAA,CAAC;EACC,cAAYJ,SAAA;EACZC,SAAA,EAAW,CAAC,sBAAsBA,SAAA,EAAWE,IAAA,IAAQ,cAAcA,IAAA,EAAM,CAAC,CACvEE,MAAM,CAACC,OAAA,EACPC,IAAI,CAAC;EACRC,MAAA,EAAO;EACPC,KAAA,EAAO;IACLC,SAAA,EACER,SAAA,KAAc,SACV,kBACAA,SAAA,KAAc,UACZ,mBACAA,SAAA,KAAc,OACZ,mBACAS;EACZ;EACAC,OAAA,EAAQ;EACRC,KAAA,EAAM;EACNC,KAAA,EAAM;YAEN,aAAAV,IAAA,CAAC;IAAKH,SAAA,EAAU;IAASc,CAAA,EAAE;IAAkBC,aAAA,EAAc","ignoreList":[]}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
@layer payload-default {
|
|
4
4
|
.icon--chevron {
|
|
5
|
-
height:
|
|
6
|
-
width:
|
|
5
|
+
height: var(--base);
|
|
6
|
+
width: var(--base);
|
|
7
7
|
|
|
8
8
|
.stroke {
|
|
9
9
|
fill: none;
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
&.icon--size-small {
|
|
21
|
-
height:
|
|
22
|
-
width:
|
|
21
|
+
height: 12px;
|
|
22
|
+
width: 12px;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|