@payloadcms/ui 3.57.0-internal.f26caed → 3.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/elements/BulkUpload/FileSidebar/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FileSidebar/index.js +74 -38
- package/dist/elements/BulkUpload/FileSidebar/index.js.map +1 -1
- package/dist/elements/BulkUpload/FileSidebar/index.scss +14 -1
- package/dist/elements/BulkUpload/FormsManager/index.d.ts +6 -1
- package/dist/elements/BulkUpload/FormsManager/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/index.js +52 -14
- package/dist/elements/BulkUpload/FormsManager/index.js.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/reducer.d.ts +2 -2
- package/dist/elements/BulkUpload/FormsManager/reducer.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/reducer.js +5 -5
- package/dist/elements/BulkUpload/FormsManager/reducer.js.map +1 -1
- package/dist/elements/BulkUpload/index.d.ts +30 -5
- package/dist/elements/BulkUpload/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/index.js +130 -28
- package/dist/elements/BulkUpload/index.js.map +1 -1
- package/dist/elements/ConfirmationModal/index.d.ts.map +1 -1
- package/dist/elements/ConfirmationModal/index.js +1 -0
- package/dist/elements/ConfirmationModal/index.js.map +1 -1
- package/dist/elements/DocumentLocked/index.d.ts.map +1 -1
- package/dist/elements/DocumentLocked/index.js +41 -33
- package/dist/elements/DocumentLocked/index.js.map +1 -1
- package/dist/elements/DocumentTakeOver/index.d.ts.map +1 -1
- package/dist/elements/DocumentTakeOver/index.js +27 -19
- package/dist/elements/DocumentTakeOver/index.js.map +1 -1
- package/dist/elements/Drawer/index.d.ts.map +1 -1
- package/dist/elements/Drawer/index.js +1 -0
- package/dist/elements/Drawer/index.js.map +1 -1
- package/dist/elements/FullscreenModal/index.d.ts.map +1 -1
- package/dist/elements/FullscreenModal/index.js +1 -0
- package/dist/elements/FullscreenModal/index.js.map +1 -1
- package/dist/elements/LivePreview/IFrame/index.d.ts +1 -7
- package/dist/elements/LivePreview/IFrame/index.d.ts.map +1 -1
- package/dist/elements/LivePreview/IFrame/index.js +39 -18
- package/dist/elements/LivePreview/IFrame/index.js.map +1 -1
- package/dist/elements/LivePreview/Window/index.d.ts.map +1 -1
- package/dist/elements/LivePreview/Window/index.js +135 -61
- package/dist/elements/LivePreview/Window/index.js.map +1 -1
- package/dist/elements/PublishButton/index.js +1 -1
- package/dist/elements/PublishButton/index.js.map +1 -1
- package/dist/elements/SearchBar/index.scss +4 -0
- package/dist/elements/Status/index.d.ts.map +1 -1
- package/dist/elements/Status/index.js +9 -19
- package/dist/elements/Status/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/index.d.ts.map +1 -1
- package/dist/elements/Table/DefaultCell/index.js +20 -14
- package/dist/elements/Table/DefaultCell/index.js.map +1 -1
- package/dist/elements/Thumbnail/index.d.ts +4 -2
- package/dist/elements/Thumbnail/index.d.ts.map +1 -1
- package/dist/elements/Thumbnail/index.js +6 -2
- package/dist/elements/Thumbnail/index.js.map +1 -1
- package/dist/elements/Thumbnail/index.scss +11 -9
- package/dist/elements/Toasts/fieldErrors.js +1 -1
- package/dist/elements/Toasts/fieldErrors.js.map +1 -1
- package/dist/exports/client/index.js +24 -24
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/rsc/index.d.ts +1 -0
- package/dist/exports/rsc/index.d.ts.map +1 -1
- package/dist/exports/rsc/index.js +1 -0
- package/dist/exports/rsc/index.js.map +1 -1
- package/dist/exports/shared/index.js +2 -2
- package/dist/exports/shared/index.js.map +3 -3
- package/dist/fields/Blocks/index.d.ts.map +1 -1
- package/dist/fields/Blocks/index.js +36 -16
- package/dist/fields/Blocks/index.js.map +1 -1
- package/dist/fields/Relationship/Input.d.ts.map +1 -1
- package/dist/fields/Relationship/Input.js +1 -5
- package/dist/fields/Relationship/Input.js.map +1 -1
- package/dist/fields/Upload/Input.js +20 -20
- package/dist/fields/Upload/Input.js.map +1 -1
- package/dist/forms/Form/index.js +1 -2
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/forms/Form/mergeServerFormState.d.ts.map +1 -1
- package/dist/forms/Form/mergeServerFormState.js +8 -0
- package/dist/forms/Form/mergeServerFormState.js.map +1 -1
- package/dist/forms/Form/types.d.ts +2 -2
- package/dist/forms/Form/types.d.ts.map +1 -1
- package/dist/forms/Form/types.js.map +1 -1
- package/dist/forms/RenderFields/RenderField.js +223 -236
- package/dist/forms/RenderFields/RenderField.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js +33 -2
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.js +2 -1
- package/dist/forms/fieldSchemasToFormState/renderField.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.js +2 -0
- package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/types.d.ts +6 -0
- package/dist/forms/fieldSchemasToFormState/types.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/types.js.map +1 -1
- package/dist/forms/useField/index.d.ts.map +1 -1
- package/dist/forms/useField/index.js +76 -73
- package/dist/forms/useField/index.js.map +1 -1
- package/dist/forms/useField/types.d.ts +5 -9
- package/dist/forms/useField/types.d.ts.map +1 -1
- package/dist/forms/useField/types.js.map +1 -1
- package/dist/providers/LivePreview/context.d.ts +17 -2
- package/dist/providers/LivePreview/context.d.ts.map +1 -1
- package/dist/providers/LivePreview/context.js +3 -2
- package/dist/providers/LivePreview/context.js.map +1 -1
- package/dist/providers/LivePreview/index.d.ts +2 -2
- package/dist/providers/LivePreview/index.d.ts.map +1 -1
- package/dist/providers/LivePreview/index.js +33 -19
- package/dist/providers/LivePreview/index.js.map +1 -1
- package/dist/providers/RouteCache/index.d.ts.map +1 -1
- package/dist/providers/RouteCache/index.js +62 -25
- package/dist/providers/RouteCache/index.js.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/index.d.ts +2 -1
- package/dist/providers/TableColumns/buildColumnState/index.d.ts.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/index.js +2 -0
- package/dist/providers/TableColumns/buildColumnState/index.js.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/renderCell.d.ts +3 -2
- package/dist/providers/TableColumns/buildColumnState/renderCell.d.ts.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/renderCell.js +39 -2
- package/dist/providers/TableColumns/buildColumnState/renderCell.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/utilities/buildFormState.d.ts +2 -0
- package/dist/utilities/buildFormState.d.ts.map +1 -1
- package/dist/utilities/buildFormState.js +20 -1
- package/dist/utilities/buildFormState.js.map +1 -1
- package/dist/utilities/formatAbsoluteURL.d.ts +8 -0
- package/dist/utilities/formatAbsoluteURL.d.ts.map +1 -0
- package/dist/utilities/formatAbsoluteURL.js +15 -0
- package/dist/utilities/formatAbsoluteURL.js.map +1 -0
- package/dist/utilities/getFolderResultsComponentAndData.d.ts.map +1 -1
- package/dist/utilities/getFolderResultsComponentAndData.js +0 -4
- package/dist/utilities/getFolderResultsComponentAndData.js.map +1 -1
- package/dist/utilities/handleLivePreview.d.ts +58 -0
- package/dist/utilities/handleLivePreview.d.ts.map +1 -0
- package/dist/utilities/handleLivePreview.js +96 -0
- package/dist/utilities/handleLivePreview.js.map +1 -0
- package/dist/utilities/handleTakeOver.d.ts +17 -4
- package/dist/utilities/handleTakeOver.d.ts.map +1 -1
- package/dist/utilities/handleTakeOver.js +18 -2
- package/dist/utilities/handleTakeOver.js.map +1 -1
- package/dist/utilities/renderTable.d.ts +3 -2
- package/dist/utilities/renderTable.d.ts.map +1 -1
- package/dist/utilities/renderTable.js +2 -0
- package/dist/utilities/renderTable.js.map +1 -1
- package/dist/views/Edit/index.d.ts.map +1 -1
- package/dist/views/Edit/index.js +48 -13
- package/dist/views/Edit/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -11,7 +11,7 @@ import { useTranslation } from '../../providers/Translation/index.js';
|
|
|
11
11
|
import { useDocumentForm, useForm, useFormFields, useFormInitializing, useFormProcessing, useFormSubmitted } from '../Form/context.js';
|
|
12
12
|
import { useFieldPath } from '../RenderFields/context.js';
|
|
13
13
|
const useFieldInForm = options => {
|
|
14
|
-
const $ = _c(
|
|
14
|
+
const $ = _c(65);
|
|
15
15
|
let t0;
|
|
16
16
|
if ($[0] !== options) {
|
|
17
17
|
t0 = options || {};
|
|
@@ -109,38 +109,40 @@ const useFieldInForm = options => {
|
|
|
109
109
|
t4 = $[11];
|
|
110
110
|
}
|
|
111
111
|
const setValue = t4;
|
|
112
|
-
const t5 = field?.
|
|
113
|
-
const t6 =
|
|
114
|
-
const t7 =
|
|
115
|
-
|
|
112
|
+
const t5 = field?.blocksFilterOptions;
|
|
113
|
+
const t6 = field?.customComponents;
|
|
114
|
+
const t7 = processing || initializing;
|
|
115
|
+
const t8 = field?.errorMessage;
|
|
116
|
+
let t9;
|
|
116
117
|
if ($[12] !== field?.errorPaths) {
|
|
117
|
-
|
|
118
|
+
t9 = field?.errorPaths || [];
|
|
118
119
|
$[12] = field?.errorPaths;
|
|
119
|
-
$[13] =
|
|
120
|
+
$[13] = t9;
|
|
120
121
|
} else {
|
|
121
|
-
|
|
122
|
+
t9 = $[13];
|
|
122
123
|
}
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
let
|
|
127
|
-
if ($[14] !== filterOptions || $[15] !== initialValue || $[16] !== initializing || $[17] !== path || $[18] !== processing || $[19] !== setValue || $[20] !== showError || $[21] !== submitted || $[22] !== t10 || $[23] !== t11 || $[24] !==
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
const t10 = field?.rows;
|
|
125
|
+
const t11 = field?.selectFilterOptions;
|
|
126
|
+
const t12 = field?.valid;
|
|
127
|
+
let t13;
|
|
128
|
+
if ($[14] !== filterOptions || $[15] !== initialValue || $[16] !== initializing || $[17] !== path || $[18] !== processing || $[19] !== setValue || $[20] !== showError || $[21] !== submitted || $[22] !== t10 || $[23] !== t11 || $[24] !== t12 || $[25] !== t5 || $[26] !== t6 || $[27] !== t7 || $[28] !== t8 || $[29] !== t9 || $[30] !== value) {
|
|
129
|
+
t13 = {
|
|
130
|
+
blocksFilterOptions: t5,
|
|
131
|
+
customComponents: t6,
|
|
132
|
+
disabled: t7,
|
|
133
|
+
errorMessage: t8,
|
|
134
|
+
errorPaths: t9,
|
|
133
135
|
filterOptions,
|
|
134
136
|
formInitializing: initializing,
|
|
135
137
|
formProcessing: processing,
|
|
136
138
|
formSubmitted: submitted,
|
|
137
139
|
initialValue,
|
|
138
140
|
path,
|
|
139
|
-
rows:
|
|
140
|
-
selectFilterOptions:
|
|
141
|
+
rows: t10,
|
|
142
|
+
selectFilterOptions: t11,
|
|
141
143
|
setValue,
|
|
142
144
|
showError,
|
|
143
|
-
valid:
|
|
145
|
+
valid: t12,
|
|
144
146
|
value
|
|
145
147
|
};
|
|
146
148
|
$[14] = filterOptions;
|
|
@@ -153,20 +155,21 @@ const useFieldInForm = options => {
|
|
|
153
155
|
$[21] = submitted;
|
|
154
156
|
$[22] = t10;
|
|
155
157
|
$[23] = t11;
|
|
156
|
-
$[24] =
|
|
157
|
-
$[25] =
|
|
158
|
-
$[26] =
|
|
159
|
-
$[27] =
|
|
160
|
-
$[28] =
|
|
161
|
-
$[29] =
|
|
162
|
-
$[30] =
|
|
158
|
+
$[24] = t12;
|
|
159
|
+
$[25] = t5;
|
|
160
|
+
$[26] = t6;
|
|
161
|
+
$[27] = t7;
|
|
162
|
+
$[28] = t8;
|
|
163
|
+
$[29] = t9;
|
|
164
|
+
$[30] = value;
|
|
165
|
+
$[31] = t13;
|
|
163
166
|
} else {
|
|
164
|
-
|
|
167
|
+
t13 = $[31];
|
|
165
168
|
}
|
|
166
|
-
const result =
|
|
167
|
-
let
|
|
168
|
-
if ($[
|
|
169
|
-
|
|
169
|
+
const result = t13;
|
|
170
|
+
let t14;
|
|
171
|
+
if ($[32] !== collectionSlug || $[33] !== config || $[34] !== disableFormData || $[35] !== dispatchField || $[36] !== documentForm || $[37] !== field || $[38] !== getData || $[39] !== getDataByPath || $[40] !== getSiblingData || $[41] !== hasRows || $[42] !== id || $[43] !== operation || $[44] !== path || $[45] !== pathSegments || $[46] !== t || $[47] !== user || $[48] !== validate || $[49] !== value) {
|
|
172
|
+
t14 = () => {
|
|
170
173
|
const validateField = async () => {
|
|
171
174
|
let valueToValidate = value;
|
|
172
175
|
if (field?.rows && Array.isArray(field.rows)) {
|
|
@@ -224,50 +227,50 @@ const useFieldInForm = options => {
|
|
|
224
227
|
};
|
|
225
228
|
validateField();
|
|
226
229
|
};
|
|
227
|
-
$[
|
|
228
|
-
$[
|
|
229
|
-
$[
|
|
230
|
-
$[
|
|
231
|
-
$[
|
|
232
|
-
$[
|
|
233
|
-
$[
|
|
234
|
-
$[
|
|
235
|
-
$[
|
|
236
|
-
$[
|
|
237
|
-
$[
|
|
238
|
-
$[
|
|
239
|
-
$[
|
|
240
|
-
$[
|
|
241
|
-
$[
|
|
242
|
-
$[
|
|
243
|
-
$[
|
|
244
|
-
$[
|
|
245
|
-
$[
|
|
230
|
+
$[32] = collectionSlug;
|
|
231
|
+
$[33] = config;
|
|
232
|
+
$[34] = disableFormData;
|
|
233
|
+
$[35] = dispatchField;
|
|
234
|
+
$[36] = documentForm;
|
|
235
|
+
$[37] = field;
|
|
236
|
+
$[38] = getData;
|
|
237
|
+
$[39] = getDataByPath;
|
|
238
|
+
$[40] = getSiblingData;
|
|
239
|
+
$[41] = hasRows;
|
|
240
|
+
$[42] = id;
|
|
241
|
+
$[43] = operation;
|
|
242
|
+
$[44] = path;
|
|
243
|
+
$[45] = pathSegments;
|
|
244
|
+
$[46] = t;
|
|
245
|
+
$[47] = user;
|
|
246
|
+
$[48] = validate;
|
|
247
|
+
$[49] = value;
|
|
248
|
+
$[50] = t14;
|
|
246
249
|
} else {
|
|
247
|
-
|
|
250
|
+
t14 = $[50];
|
|
248
251
|
}
|
|
249
|
-
const
|
|
250
|
-
let
|
|
251
|
-
if ($[
|
|
252
|
-
|
|
253
|
-
$[
|
|
254
|
-
$[
|
|
255
|
-
$[
|
|
256
|
-
$[
|
|
257
|
-
$[
|
|
258
|
-
$[
|
|
259
|
-
$[
|
|
260
|
-
$[
|
|
261
|
-
$[
|
|
262
|
-
$[
|
|
263
|
-
$[
|
|
264
|
-
$[
|
|
265
|
-
$[
|
|
266
|
-
$[
|
|
252
|
+
const t15 = field?.rows;
|
|
253
|
+
let t16;
|
|
254
|
+
if ($[51] !== collectionSlug || $[52] !== disableFormData || $[53] !== dispatchField || $[54] !== getData || $[55] !== getDataByPath || $[56] !== getSiblingData || $[57] !== id || $[58] !== operation || $[59] !== path || $[60] !== t15 || $[61] !== user || $[62] !== validate || $[63] !== value) {
|
|
255
|
+
t16 = [value, disableFormData, dispatchField, getData, getSiblingData, getDataByPath, id, operation, path, user, validate, t15, collectionSlug];
|
|
256
|
+
$[51] = collectionSlug;
|
|
257
|
+
$[52] = disableFormData;
|
|
258
|
+
$[53] = dispatchField;
|
|
259
|
+
$[54] = getData;
|
|
260
|
+
$[55] = getDataByPath;
|
|
261
|
+
$[56] = getSiblingData;
|
|
262
|
+
$[57] = id;
|
|
263
|
+
$[58] = operation;
|
|
264
|
+
$[59] = path;
|
|
265
|
+
$[60] = t15;
|
|
266
|
+
$[61] = user;
|
|
267
|
+
$[62] = validate;
|
|
268
|
+
$[63] = value;
|
|
269
|
+
$[64] = t16;
|
|
267
270
|
} else {
|
|
268
|
-
|
|
271
|
+
t16 = $[64];
|
|
269
272
|
}
|
|
270
|
-
useThrottledEffect(
|
|
273
|
+
useThrottledEffect(t14, 150, t16);
|
|
271
274
|
return result;
|
|
272
275
|
};
|
|
273
276
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","React","useCallback","useMemo","useRef","useThrottledEffect","useAuth","useConfig","useDocumentInfo","useOperation","useTranslation","useDocumentForm","useForm","useFormFields","useFormInitializing","useFormProcessing","useFormSubmitted","useFieldPath","useFieldInForm","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","filterOptions","value","initialValue","valid","showError","prevValid","prevErrorMessage","errorMessage","split","pathSegments","t4","e","t5","disableModifyingForm","isEvent","preventDefault","stopPropagation","val","target","type","setValue","customComponents","t6","t7","t8","errorPaths","t9","rows","t10","selectFilterOptions","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","FieldContext","createContext","useField","fieldContext","use","hasFieldContext","currentPath","Error","dispatch"],"sources":["../../../src/forms/useField/index.tsx"],"sourcesContent":["'use client'\nimport type { PayloadRequest } from 'payload'\n\nimport React, { 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 useFormProcessing,\n useFormSubmitted,\n} from '../Form/context.js'\nimport { useFieldPath } from '../RenderFields/context.js'\n\nconst useFieldInForm = <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\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 // TODO:\n // There are no built-in fields that pass events into `e`.\n // Remove this check in the next major version.\n const isEvent =\n e &&\n typeof e === 'object' &&\n typeof e.preventDefault === 'function' &&\n typeof e.stopPropagation === 'function'\n\n const val = isEvent ? e.target.value : e\n\n dispatchField({\n type: 'UPDATE',\n disableFormData: disableFormData || (hasRows && val > 0),\n path,\n value: val,\n })\n\n if (!disableModifyingForm) {\n setModified(true)\n }\n },\n [setModified, path, dispatchField, disableFormData, hasRows],\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 selectFilterOptions: field?.selectFilterOptions,\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\n/**\n * Context to allow providing useField value for fields directly, if managed outside the Form\n *\n * @experimental\n */\nexport const FieldContext = React.createContext<FieldType<unknown> | undefined>(undefined)\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 pathFromContext = useFieldPath()\n\n const fieldContext = React.use(FieldContext) as FieldType<TValue> | undefined\n\n // Lock the mode on first render so hook order is stable forever. This ensures\n // that hooks are called in the same order each time a component renders => should\n // not break the rule of hooks.\n const hasFieldContext = React.useRef<false | null | true>(null)\n if (hasFieldContext.current === null) {\n // Use field context, if a field context exists **and** the path matches. If the path\n // does not match, this could be the field context of a parent field => there likely is\n // a nested <Form /> we should use instead => 'form'\n const currentPath = options?.path || pathFromContext || options.potentiallyStalePath\n\n hasFieldContext.current =\n fieldContext && currentPath && fieldContext.path === currentPath ? true : false\n }\n\n if (hasFieldContext.current === true) {\n if (!fieldContext) {\n // Provider was removed after mount. That violates hook guarantees.\n throw new Error('FieldContext was removed after mount. This breaks hook ordering.')\n }\n return fieldContext\n }\n\n // We intentionally guard this hook call with a mode that is fixed on first render.\n // The order is consistent across renders. Silence the linter’s false positive.\n\n // eslint-disable-next-line react-compiler/react-compiler\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useFieldInForm<TValue>(options)\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAGA,OAAOC,KAAA,IAASC,WAAW,EAAEC,OAAO,EAAEC,MAAM,QAAQ;AAOpD,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,SACEC,eAAe,EACfC,OAAO,EACPC,a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AoF,GAAA;IAAApF,CAAA,OAAAc,IAAA;IAAAd,CAAA,OAAAQ,QAAA;IAAAR,CAAA,OAAAgC,KAAA;IAAAhC,CAAA,OAAAqF,GAAA;EAAA;IAAAA,GAAA,GAAArF,CAAA;EAAA;EAxFHf,kBAAA,CACEmF,GAuEA,OAEAiB,GAcC;EAAA,OAGIlB,MAAA;AAAA,CACT;AAEA;;;;;AAKA,OAAO,MAAMmB,YAAA,gBAAezG,KAAA,CAAM0G,aAAa,CAAiC9E,SAAA;AAEhF;;;;;AAKA,OAAO,MAAM+E,QAAA,GAAqBzF,OAAA;EAChC,MAAMW,eAAA,GAAkBb,YAAA;EAExB,MAAM4F,YAAA,GAAe5G,KAAA,CAAM6G,GAAG,CAACJ,YAAA;EAE/B;EACA;EACA;EACA,MAAMK,eAAA,GAAkB9G,KAAA,CAAMG,MAAM,CAAsB;EAC1D,IAAI2G,eAAA,CAAgBlB,OAAO,KAAK,MAAM;IACpC;IACA;IACA;IACA,MAAMmB,WAAA,GAAc7F,OAAA,EAASM,IAAA,IAAQK,eAAA,IAAmBX,OAAA,CAAQQ,oBAAoB;IAEpFoF,eAAA,CAAgBlB,OAAO,GACrBgB,YAAA,IAAgBG,WAAA,IAAeH,YAAA,CAAapF,IAAI,KAAKuF,WAAA,GAAc,OAAO;EAC9E;EAEA,IAAID,eAAA,CAAgBlB,OAAO,KAAK,MAAM;IACpC,IAAI,CAACgB,YAAA,EAAc;MACjB;MACA,MAAM,IAAII,KAAA,CAAM;IAClB;IACA,OAAOJ,YAAA;EACT;EAEA;EACA;EAEA;EACA;EACA,OAAO3F,cAAA,CAAuBC,OAAA;AAChC;AAtPuB,SAAAoB,MAAAlB,EAAA;EAsBgB,SAAA6F,QAAA,IAAA7F,EAAa;EAAA,OAAK6F,QAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","React","useCallback","useMemo","useRef","useThrottledEffect","useAuth","useConfig","useDocumentInfo","useOperation","useTranslation","useDocumentForm","useForm","useFormFields","useFormInitializing","useFormProcessing","useFormSubmitted","useFieldPath","useFieldInForm","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","filterOptions","value","initialValue","valid","showError","prevValid","prevErrorMessage","errorMessage","split","pathSegments","t4","e","t5","disableModifyingForm","isEvent","preventDefault","stopPropagation","val","target","type","setValue","blocksFilterOptions","t6","customComponents","t7","t8","t9","errorPaths","t10","rows","t11","selectFilterOptions","t12","t13","disabled","formInitializing","formProcessing","formSubmitted","result","t14","validateField","valueToValidate","Array","isArray","current","valid_0","data","isValid","blockData","event","preferences","req","payload","siblingData","update","t15","t16","FieldContext","createContext","useField","fieldContext","use","hasFieldContext","currentPath","Error","dispatch"],"sources":["../../../src/forms/useField/index.tsx"],"sourcesContent":["'use client'\nimport type { PayloadRequest } from 'payload'\n\nimport React, { 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 useFormProcessing,\n useFormSubmitted,\n} from '../Form/context.js'\nimport { useFieldPath } from '../RenderFields/context.js'\n\nconst useFieldInForm = <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\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 // TODO:\n // There are no built-in fields that pass events into `e`.\n // Remove this check in the next major version.\n const isEvent =\n e &&\n typeof e === 'object' &&\n typeof e.preventDefault === 'function' &&\n typeof e.stopPropagation === 'function'\n\n const val = isEvent ? e.target.value : e\n\n dispatchField({\n type: 'UPDATE',\n disableFormData: disableFormData || (hasRows && val > 0),\n path,\n value: val,\n })\n\n if (!disableModifyingForm) {\n setModified(true)\n }\n },\n [setModified, path, dispatchField, disableFormData, hasRows],\n )\n\n // Store result from hook as ref\n // to prevent unnecessary rerenders\n const result: FieldType<TValue> = useMemo(\n () => ({\n blocksFilterOptions: field?.blocksFilterOptions,\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 selectFilterOptions: field?.selectFilterOptions,\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\n/**\n * Context to allow providing useField value for fields directly, if managed outside the Form\n *\n * @experimental\n */\nexport const FieldContext = React.createContext<FieldType<unknown> | undefined>(undefined)\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 pathFromContext = useFieldPath()\n\n const fieldContext = React.use(FieldContext) as FieldType<TValue> | undefined\n\n // Lock the mode on first render so hook order is stable forever. This ensures\n // that hooks are called in the same order each time a component renders => should\n // not break the rule of hooks.\n const hasFieldContext = React.useRef<false | null | true>(null)\n if (hasFieldContext.current === null) {\n // Use field context, if a field context exists **and** the path matches. If the path\n // does not match, this could be the field context of a parent field => there likely is\n // a nested <Form /> we should use instead => 'form'\n const currentPath = options?.path || pathFromContext || options.potentiallyStalePath\n\n hasFieldContext.current =\n fieldContext && currentPath && fieldContext.path === currentPath ? true : false\n }\n\n if (hasFieldContext.current === true) {\n if (!fieldContext) {\n // Provider was removed after mount. That violates hook guarantees.\n throw new Error('FieldContext was removed after mount. This breaks hook ordering.')\n }\n return fieldContext\n }\n\n // We intentionally guard this hook call with a mode that is fixed on first render.\n // The order is consistent across renders. Silence the linter’s false positive.\n\n // eslint-disable-next-line react-compiler/react-compiler\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useFieldInForm<TValue>(options)\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAGA,OAAOC,KAAA,IAASC,WAAW,EAAEC,OAAO,EAAEC,MAAM,QAAQ;AAOpD,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,SACEC,eAAe,EACfC,OAAO,EACPC,aAAa,EACbC,mBAAmB,EACnBC,iBAAiB,EACjBC,gBAAgB,QACX;AACP,SAASC,YAAY,QAAQ;AAE7B,MAAMC,cAAA,GAAiBC,OAAA;EAAA,MAAAC,CAAA,GAAApB,EAAA;EAAA,IAAAqB,EAAA;EAAA,IAAAD,CAAA,QAAAD,OAAA;IAOjBE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AA;IAAAR,CAAA,OAAAgC,KAAA;IAAAhC,CAAA,OAAAuF,GAAA;EAAA;IAAAA,GAAA,GAAAvF,CAAA;EAAA;EAxFHf,kBAAA,CACEqF,GAuEA,OAEAiB,GAcC;EAAA,OAGIlB,MAAA;AAAA,CACT;AAEA;;;;;AAKA,OAAO,MAAMmB,YAAA,gBAAe3G,KAAA,CAAM4G,aAAa,CAAiChF,SAAA;AAEhF;;;;;AAKA,OAAO,MAAMiF,QAAA,GAAqB3F,OAAA;EAChC,MAAMW,eAAA,GAAkBb,YAAA;EAExB,MAAM8F,YAAA,GAAe9G,KAAA,CAAM+G,GAAG,CAACJ,YAAA;EAE/B;EACA;EACA;EACA,MAAMK,eAAA,GAAkBhH,KAAA,CAAMG,MAAM,CAAsB;EAC1D,IAAI6G,eAAA,CAAgBlB,OAAO,KAAK,MAAM;IACpC;IACA;IACA;IACA,MAAMmB,WAAA,GAAc/F,OAAA,EAASM,IAAA,IAAQK,eAAA,IAAmBX,OAAA,CAAQQ,oBAAoB;IAEpFsF,eAAA,CAAgBlB,OAAO,GACrBgB,YAAA,IAAgBG,WAAA,IAAeH,YAAA,CAAatF,IAAI,KAAKyF,WAAA,GAAc,OAAO;EAC9E;EAEA,IAAID,eAAA,CAAgBlB,OAAO,KAAK,MAAM;IACpC,IAAI,CAACgB,YAAA,EAAc;MACjB;MACA,MAAM,IAAII,KAAA,CAAM;IAClB;IACA,OAAOJ,YAAA;EACT;EAEA;EACA;EAEA;EACA;EACA,OAAO7F,cAAA,CAAuBC,OAAA;AAChC;AAvPuB,SAAAoB,MAAAlB,EAAA;EAsBgB,SAAA+F,QAAA,IAAA/F,EAAa;EAAA,OAAK+F,QAAA;AAAA","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FieldState,
|
|
1
|
+
import type { FieldState, Validate } from 'payload';
|
|
2
2
|
export type Options = {
|
|
3
3
|
disableFormData?: boolean;
|
|
4
4
|
hasRows?: boolean;
|
|
@@ -26,22 +26,18 @@ export type Options = {
|
|
|
26
26
|
validate?: Validate;
|
|
27
27
|
};
|
|
28
28
|
export type FieldType<T> = {
|
|
29
|
-
customComponents?: FieldState['customComponents'];
|
|
30
29
|
disabled: boolean;
|
|
31
|
-
errorMessage?: string;
|
|
32
|
-
errorPaths?: string[];
|
|
33
|
-
filterOptions?: FilterOptionsResult;
|
|
34
30
|
formInitializing: boolean;
|
|
35
31
|
formProcessing: boolean;
|
|
36
32
|
formSubmitted: boolean;
|
|
37
33
|
initialValue?: T;
|
|
38
34
|
path: string;
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated - readOnly is no longer returned from useField. Remove this in 4.0.
|
|
37
|
+
*/
|
|
39
38
|
readOnly?: boolean;
|
|
40
|
-
rows?: Row[];
|
|
41
|
-
selectFilterOptions?: Option[];
|
|
42
39
|
setValue: (val: unknown, disableModifyingForm?: boolean) => void;
|
|
43
40
|
showError: boolean;
|
|
44
|
-
valid?: boolean;
|
|
45
41
|
value: T;
|
|
46
|
-
}
|
|
42
|
+
} & Pick<FieldState, 'blocksFilterOptions' | 'customComponents' | 'errorMessage' | 'errorPaths' | 'filterOptions' | 'rows' | 'selectFilterOptions' | 'valid'>;
|
|
47
43
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/forms/useField/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/forms/useField/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEnD,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,QAAQ,EAAE,OAAO,CAAA;IACjB,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;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,oBAAoB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IAChE,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,CAAC,CAAA;CACT,GAAG,IAAI,CACN,UAAU,EACR,qBAAqB,GACrB,kBAAkB,GAClB,cAAc,GACd,YAAY,GACZ,eAAe,GACf,MAAM,GACN,qBAAqB,GACrB,OAAO,CACV,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/forms/useField/types.ts"],"sourcesContent":["import type { FieldState,
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/forms/useField/types.ts"],"sourcesContent":["import type { FieldState, 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 disabled: boolean\n formInitializing: boolean\n formProcessing: boolean\n formSubmitted: boolean\n initialValue?: T\n path: string\n /**\n * @deprecated - readOnly is no longer returned from useField. Remove this in 4.0.\n */\n readOnly?: boolean\n setValue: (val: unknown, disableModifyingForm?: boolean) => void\n showError: boolean\n value: T\n} & Pick<\n FieldState,\n | 'blocksFilterOptions'\n | 'customComponents'\n | 'errorMessage'\n | 'errorPaths'\n | 'filterOptions'\n | 'rows'\n | 'selectFilterOptions'\n | 'valid'\n>\n"],"mappings":"AA6BA","ignoreList":[]}
|
|
@@ -7,12 +7,17 @@ export interface LivePreviewContextType {
|
|
|
7
7
|
appIsReady: boolean;
|
|
8
8
|
breakpoint: LivePreviewConfig['breakpoints'][number]['name'];
|
|
9
9
|
breakpoints: LivePreviewConfig['breakpoints'];
|
|
10
|
-
iframeHasLoaded: boolean;
|
|
11
10
|
iframeRef: React.RefObject<HTMLIFrameElement | null>;
|
|
12
11
|
isLivePreviewEnabled: boolean;
|
|
13
12
|
isLivePreviewing: boolean;
|
|
14
13
|
isPopupOpen: boolean;
|
|
15
14
|
listeningForMessages?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The URL that has finished loading in the iframe or popup.
|
|
17
|
+
* For example, if you set the `url`, it will begin to load into the iframe,
|
|
18
|
+
* but `loadedURL` will not be set until the iframe's `onLoad` event fires.
|
|
19
|
+
*/
|
|
20
|
+
loadedURL?: string;
|
|
16
21
|
measuredDeviceSize: {
|
|
17
22
|
height: number;
|
|
18
23
|
width: number;
|
|
@@ -23,8 +28,8 @@ export interface LivePreviewContextType {
|
|
|
23
28
|
setAppIsReady: (appIsReady: boolean) => void;
|
|
24
29
|
setBreakpoint: (breakpoint: LivePreviewConfig['breakpoints'][number]['name']) => void;
|
|
25
30
|
setHeight: (height: number) => void;
|
|
26
|
-
setIframeHasLoaded: (loaded: boolean) => void;
|
|
27
31
|
setIsLivePreviewing: (isLivePreviewing: boolean) => void;
|
|
32
|
+
setLoadedURL: (loadedURL: string) => void;
|
|
28
33
|
setMeasuredDeviceSize: (size: {
|
|
29
34
|
height: number;
|
|
30
35
|
width: number;
|
|
@@ -35,6 +40,11 @@ export interface LivePreviewContextType {
|
|
|
35
40
|
x: number;
|
|
36
41
|
y: number;
|
|
37
42
|
}) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Sets the URL of the preview (either iframe or popup).
|
|
45
|
+
* Will trigger a reload of the window.
|
|
46
|
+
*/
|
|
47
|
+
setURL: (url: string) => void;
|
|
38
48
|
setWidth: (width: number) => void;
|
|
39
49
|
setZoom: (zoom: number) => void;
|
|
40
50
|
size: {
|
|
@@ -45,6 +55,11 @@ export interface LivePreviewContextType {
|
|
|
45
55
|
x: number;
|
|
46
56
|
y: number;
|
|
47
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* The live preview url property can be either a string or a function that returns a string.
|
|
60
|
+
* It is important to know which one it is, so that we can opt in/out of certain behaviors, e.g. calling the server to get the URL.
|
|
61
|
+
*/
|
|
62
|
+
typeofLivePreviewURL?: 'function' | 'string';
|
|
48
63
|
url: string | undefined;
|
|
49
64
|
zoom: number;
|
|
50
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/providers/LivePreview/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,KAAK,EAA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M,EAAE,MAAM,CAAA;QACd,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,eAAe,EAAE;QACf,CAAC,EAAE,MAAM,CAAA;QACT,CAAC,EAAE,MAAM,CAAA;KACV,CAAA;IACD;;;OAGG;IACH,oBAAoB,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAA;IAC5C,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;CACb;AAED,eAAO,MAAM,kBAAkB,uCAsC7B,CAAA;AAEF,eAAO,MAAM,qBAAqB,8BAAgC,CAAA"}
|
|
@@ -5,7 +5,6 @@ export const LivePreviewContext = createContext({
|
|
|
5
5
|
appIsReady: false,
|
|
6
6
|
breakpoint: undefined,
|
|
7
7
|
breakpoints: undefined,
|
|
8
|
-
iframeHasLoaded: false,
|
|
9
8
|
iframeRef: undefined,
|
|
10
9
|
isLivePreviewEnabled: undefined,
|
|
11
10
|
isLivePreviewing: false,
|
|
@@ -20,12 +19,13 @@ export const LivePreviewContext = createContext({
|
|
|
20
19
|
setAppIsReady: () => {},
|
|
21
20
|
setBreakpoint: () => {},
|
|
22
21
|
setHeight: () => {},
|
|
23
|
-
setIframeHasLoaded: () => {},
|
|
24
22
|
setIsLivePreviewing: () => {},
|
|
23
|
+
setLoadedURL: () => {},
|
|
25
24
|
setMeasuredDeviceSize: () => {},
|
|
26
25
|
setPreviewWindowType: () => {},
|
|
27
26
|
setSize: () => {},
|
|
28
27
|
setToolbarPosition: () => {},
|
|
28
|
+
setURL: () => {},
|
|
29
29
|
setWidth: () => {},
|
|
30
30
|
setZoom: () => {},
|
|
31
31
|
size: {
|
|
@@ -36,6 +36,7 @@ export const LivePreviewContext = createContext({
|
|
|
36
36
|
x: 0,
|
|
37
37
|
y: 0
|
|
38
38
|
},
|
|
39
|
+
typeofLivePreviewURL: undefined,
|
|
39
40
|
url: undefined,
|
|
40
41
|
zoom: 1
|
|
41
42
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":["createContext","use","LivePreviewContext","appIsReady","breakpoint","undefined","breakpoints","
|
|
1
|
+
{"version":3,"file":"context.js","names":["createContext","use","LivePreviewContext","appIsReady","breakpoint","undefined","breakpoints","iframeRef","isLivePreviewEnabled","isLivePreviewing","isPopupOpen","measuredDeviceSize","height","width","openPopupWindow","popupRef","previewWindowType","setAppIsReady","setBreakpoint","setHeight","setIsLivePreviewing","setLoadedURL","setMeasuredDeviceSize","setPreviewWindowType","setSize","setToolbarPosition","setURL","setWidth","setZoom","size","toolbarPosition","x","y","typeofLivePreviewURL","url","zoom","useLivePreviewContext"],"sources":["../../../src/providers/LivePreview/context.ts"],"sourcesContent":["'use client'\nimport type { LivePreviewConfig } from 'payload'\nimport type { Dispatch } from 'react'\nimport type React from 'react'\n\nimport { createContext, use } from 'react'\n\nimport type { usePopupWindow } from '../../hooks/usePopupWindow.js'\nimport type { SizeReducerAction } from './sizeReducer.js'\n\nexport interface LivePreviewContextType {\n appIsReady: boolean\n breakpoint: LivePreviewConfig['breakpoints'][number]['name']\n breakpoints: LivePreviewConfig['breakpoints']\n iframeRef: React.RefObject<HTMLIFrameElement | null>\n isLivePreviewEnabled: boolean\n isLivePreviewing: boolean\n isPopupOpen: boolean\n listeningForMessages?: boolean\n /**\n * The URL that has finished loading in the iframe or popup.\n * For example, if you set the `url`, it will begin to load into the iframe,\n * but `loadedURL` will not be set until the iframe's `onLoad` event fires.\n */\n loadedURL?: string\n measuredDeviceSize: {\n height: number\n width: number\n }\n openPopupWindow: ReturnType<typeof usePopupWindow>['openPopupWindow']\n popupRef?: React.RefObject<null | Window>\n previewWindowType: 'iframe' | 'popup'\n setAppIsReady: (appIsReady: boolean) => void\n setBreakpoint: (breakpoint: LivePreviewConfig['breakpoints'][number]['name']) => void\n setHeight: (height: number) => void\n setIsLivePreviewing: (isLivePreviewing: boolean) => void\n setLoadedURL: (loadedURL: string) => void\n setMeasuredDeviceSize: (size: { height: number; width: number }) => void\n setPreviewWindowType: (previewWindowType: 'iframe' | 'popup') => void\n setSize: Dispatch<SizeReducerAction>\n setToolbarPosition: (position: { x: number; y: number }) => void\n /**\n * Sets the URL of the preview (either iframe or popup).\n * Will trigger a reload of the window.\n */\n setURL: (url: string) => void\n setWidth: (width: number) => void\n setZoom: (zoom: number) => void\n size: {\n height: number\n width: number\n }\n toolbarPosition: {\n x: number\n y: number\n }\n /**\n * The live preview url property can be either a string or a function that returns a string.\n * It is important to know which one it is, so that we can opt in/out of certain behaviors, e.g. calling the server to get the URL.\n */\n typeofLivePreviewURL?: 'function' | 'string'\n url: string | undefined\n zoom: number\n}\n\nexport const LivePreviewContext = createContext<LivePreviewContextType>({\n appIsReady: false,\n breakpoint: undefined,\n breakpoints: undefined,\n iframeRef: undefined,\n isLivePreviewEnabled: undefined,\n isLivePreviewing: false,\n isPopupOpen: false,\n measuredDeviceSize: {\n height: 0,\n width: 0,\n },\n openPopupWindow: () => {},\n popupRef: undefined,\n previewWindowType: 'iframe',\n setAppIsReady: () => {},\n setBreakpoint: () => {},\n setHeight: () => {},\n setIsLivePreviewing: () => {},\n setLoadedURL: () => {},\n setMeasuredDeviceSize: () => {},\n setPreviewWindowType: () => {},\n setSize: () => {},\n setToolbarPosition: () => {},\n setURL: () => {},\n setWidth: () => {},\n setZoom: () => {},\n size: {\n height: 0,\n width: 0,\n },\n toolbarPosition: {\n x: 0,\n y: 0,\n },\n typeofLivePreviewURL: undefined,\n url: undefined,\n zoom: 1,\n})\n\nexport const useLivePreviewContext = () => use(LivePreviewContext)\n"],"mappings":"AAAA;;AAKA,SAASA,aAAa,EAAEC,GAAG,QAAQ;AA4DnC,OAAO,MAAMC,kBAAA,GAAqBF,aAAA,CAAsC;EACtEG,UAAA,EAAY;EACZC,UAAA,EAAYC,SAAA;EACZC,WAAA,EAAaD,SAAA;EACbE,SAAA,EAAWF,SAAA;EACXG,oBAAA,EAAsBH,SAAA;EACtBI,gBAAA,EAAkB;EAClBC,WAAA,EAAa;EACbC,kBAAA,EAAoB;IAClBC,MAAA,EAAQ;IACRC,KAAA,EAAO;EACT;EACAC,eAAA,EAAiBA,CAAA,MAAO;EACxBC,QAAA,EAAUV,SAAA;EACVW,iBAAA,EAAmB;EACnBC,aAAA,EAAeA,CAAA,MAAO;EACtBC,aAAA,EAAeA,CAAA,MAAO;EACtBC,SAAA,EAAWA,CAAA,MAAO;EAClBC,mBAAA,EAAqBA,CAAA,MAAO;EAC5BC,YAAA,EAAcA,CAAA,MAAO;EACrBC,qBAAA,EAAuBA,CAAA,MAAO;EAC9BC,oBAAA,EAAsBA,CAAA,MAAO;EAC7BC,OAAA,EAASA,CAAA,MAAO;EAChBC,kBAAA,EAAoBA,CAAA,MAAO;EAC3BC,MAAA,EAAQA,CAAA,MAAO;EACfC,QAAA,EAAUA,CAAA,MAAO;EACjBC,OAAA,EAASA,CAAA,MAAO;EAChBC,IAAA,EAAM;IACJjB,MAAA,EAAQ;IACRC,KAAA,EAAO;EACT;EACAiB,eAAA,EAAiB;IACfC,CAAA,EAAG;IACHC,CAAA,EAAG;EACL;EACAC,oBAAA,EAAsB5B,SAAA;EACtB6B,GAAA,EAAK7B,SAAA;EACL8B,IAAA,EAAM;AACR;AAEA,OAAO,MAAMC,qBAAA,GAAwBA,CAAA,KAAMnC,GAAA,CAAIC,kBAAA","ignoreList":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { LivePreviewConfig } from 'payload';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import type { LivePreviewContextType } from './context.js';
|
|
3
4
|
export type LivePreviewProviderProps = {
|
|
4
5
|
appIsReady?: boolean;
|
|
5
6
|
breakpoints?: LivePreviewConfig['breakpoints'];
|
|
@@ -10,7 +11,6 @@ export type LivePreviewProviderProps = {
|
|
|
10
11
|
};
|
|
11
12
|
isLivePreviewEnabled?: boolean;
|
|
12
13
|
isLivePreviewing: boolean;
|
|
13
|
-
|
|
14
|
-
};
|
|
14
|
+
} & Pick<LivePreviewContextType, 'typeofLivePreviewURL' | 'url'>;
|
|
15
15
|
export declare const LivePreviewProvider: React.FC<LivePreviewProviderProps>;
|
|
16
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/LivePreview/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyB,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAGvE,OAAO,KAA4D,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/LivePreview/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyB,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAGvE,OAAO,KAA4D,MAAM,OAAO,CAAA;AAEhF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAU1D,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,WAAW,CAAC,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAA;IAC9C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,UAAU,CAAC,EAAE;QACX,MAAM,EAAE,MAAM,CAAA;QACd,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,gBAAgB,EAAE,OAAO,CAAA;CAC1B,GAAG,IAAI,CAAC,sBAAsB,EAAE,sBAAsB,GAAG,KAAK,CAAC,CAAA;AAEhE,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CAiPlE,CAAA"}
|
|
@@ -6,22 +6,17 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
|
6
6
|
import { usePopupWindow } from '../../hooks/usePopupWindow.js';
|
|
7
7
|
import { useDocumentInfo } from '../../providers/DocumentInfo/index.js';
|
|
8
8
|
import { usePreferences } from '../../providers/Preferences/index.js';
|
|
9
|
+
import { formatAbsoluteURL } from '../../utilities/formatAbsoluteURL.js';
|
|
9
10
|
import { customCollisionDetection } from './collisionDetection.js';
|
|
10
11
|
import { LivePreviewContext } from './context.js';
|
|
11
12
|
import { sizeReducer } from './sizeReducer.js';
|
|
12
|
-
const getAbsoluteUrl = url => {
|
|
13
|
-
try {
|
|
14
|
-
return new URL(url, window.location.origin).href;
|
|
15
|
-
} catch {
|
|
16
|
-
return url;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
13
|
export const LivePreviewProvider = ({
|
|
20
14
|
breakpoints: incomingBreakpoints,
|
|
21
15
|
children,
|
|
22
16
|
isLivePreviewEnabled,
|
|
23
17
|
isLivePreviewing: incomingIsLivePreviewing,
|
|
24
|
-
|
|
18
|
+
typeofLivePreviewURL,
|
|
19
|
+
url: urlFromProps
|
|
25
20
|
}) => {
|
|
26
21
|
const [previewWindowType, setPreviewWindowType] = useState('iframe');
|
|
27
22
|
const [isLivePreviewing, setIsLivePreviewing] = useState(incomingIsLivePreviewing);
|
|
@@ -32,10 +27,6 @@ export const LivePreviewProvider = ({
|
|
|
32
27
|
width: '100%'
|
|
33
28
|
}], [incomingBreakpoints]);
|
|
34
29
|
const [url, setURL] = useState('');
|
|
35
|
-
// This needs to be done in a useEffect to prevent hydration issues
|
|
36
|
-
// as the URL may not be absolute when passed in as a prop,
|
|
37
|
-
// and getAbsoluteUrl requires the window object to be available
|
|
38
|
-
useEffect(() => setURL(incomingUrl?.startsWith('http://') || incomingUrl?.startsWith('https://') ? incomingUrl : getAbsoluteUrl(incomingUrl)), [incomingUrl]);
|
|
39
30
|
const {
|
|
40
31
|
isPopupOpen,
|
|
41
32
|
openPopupWindow,
|
|
@@ -55,7 +46,7 @@ export const LivePreviewProvider = ({
|
|
|
55
46
|
setPreference
|
|
56
47
|
} = usePreferences();
|
|
57
48
|
const iframeRef = React.useRef(null);
|
|
58
|
-
const [
|
|
49
|
+
const [loadedURL, setLoadedURL] = useState();
|
|
59
50
|
const [zoom, setZoom] = useState(1);
|
|
60
51
|
const [position, setPosition] = useState({
|
|
61
52
|
x: 0,
|
|
@@ -70,6 +61,25 @@ export const LivePreviewProvider = ({
|
|
|
70
61
|
width: 0
|
|
71
62
|
});
|
|
72
63
|
const [breakpoint, setBreakpoint] = React.useState('responsive');
|
|
64
|
+
/**
|
|
65
|
+
* A "middleware" callback fn that does some additional work before `setURL`.
|
|
66
|
+
* This is what we provide through context, bc it:
|
|
67
|
+
* - ensures the URL is absolute
|
|
68
|
+
* - resets `appIsReady` to `false` while the new URL is loading
|
|
69
|
+
*/
|
|
70
|
+
const setLivePreviewURL = useCallback(_incomingURL => {
|
|
71
|
+
const incomingURL = formatAbsoluteURL(_incomingURL);
|
|
72
|
+
if (incomingURL !== url) {
|
|
73
|
+
setAppIsReady(false);
|
|
74
|
+
setURL(incomingURL);
|
|
75
|
+
}
|
|
76
|
+
}, [url]);
|
|
77
|
+
/**
|
|
78
|
+
* `url` needs to be relative to the window, which cannot be done on initial render.
|
|
79
|
+
*/
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
setURL(formatAbsoluteURL(urlFromProps));
|
|
82
|
+
}, [urlFromProps]);
|
|
73
83
|
// The toolbar needs to freely drag and drop around the page
|
|
74
84
|
const handleDragEnd = ev => {
|
|
75
85
|
// only update position if the toolbar is completely within the preview area
|
|
@@ -111,10 +121,12 @@ export const LivePreviewProvider = ({
|
|
|
111
121
|
});
|
|
112
122
|
}
|
|
113
123
|
}, [breakpoint, breakpoints]);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Receive the `ready` message from the popup window
|
|
126
|
+
* This indicates that the app is ready to receive `window.postMessage` events
|
|
127
|
+
* This is also the only cross-origin way of detecting when a popup window has loaded
|
|
128
|
+
* Unlike iframe elements which have an `onLoad` handler, there is no way to access `window.open` on popups
|
|
129
|
+
*/
|
|
118
130
|
useEffect(() => {
|
|
119
131
|
const handleMessage = event => {
|
|
120
132
|
if (url?.startsWith(event.origin) && event.data && typeof event.data === 'object' && event.data.type === 'payload-live-preview') {
|
|
@@ -158,12 +170,12 @@ export const LivePreviewProvider = ({
|
|
|
158
170
|
appIsReady,
|
|
159
171
|
breakpoint,
|
|
160
172
|
breakpoints,
|
|
161
|
-
iframeHasLoaded,
|
|
162
173
|
iframeRef,
|
|
163
174
|
isLivePreviewEnabled,
|
|
164
175
|
isLivePreviewing,
|
|
165
176
|
isPopupOpen,
|
|
166
177
|
listeningForMessages,
|
|
178
|
+
loadedURL,
|
|
167
179
|
measuredDeviceSize,
|
|
168
180
|
openPopupWindow,
|
|
169
181
|
popupRef,
|
|
@@ -171,16 +183,18 @@ export const LivePreviewProvider = ({
|
|
|
171
183
|
setAppIsReady,
|
|
172
184
|
setBreakpoint,
|
|
173
185
|
setHeight,
|
|
174
|
-
setIframeHasLoaded,
|
|
175
186
|
setIsLivePreviewing,
|
|
187
|
+
setLoadedURL,
|
|
176
188
|
setMeasuredDeviceSize,
|
|
177
189
|
setPreviewWindowType: handleWindowChange,
|
|
178
190
|
setSize,
|
|
179
191
|
setToolbarPosition: setPosition,
|
|
192
|
+
setURL: setLivePreviewURL,
|
|
180
193
|
setWidth,
|
|
181
194
|
setZoom,
|
|
182
195
|
size,
|
|
183
196
|
toolbarPosition: position,
|
|
197
|
+
typeofLivePreviewURL,
|
|
184
198
|
url,
|
|
185
199
|
zoom
|
|
186
200
|
},
|