@payloadcms/ui 3.57.0-internal.266049e → 3.57.0-internal.2988185
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 +38 -74
- package/dist/elements/BulkUpload/FileSidebar/index.js.map +1 -1
- package/dist/elements/BulkUpload/FileSidebar/index.scss +1 -14
- package/dist/elements/BulkUpload/FormsManager/index.d.ts +1 -6
- package/dist/elements/BulkUpload/FormsManager/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/index.js +14 -52
- 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 +5 -30
- package/dist/elements/BulkUpload/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/index.js +28 -130
- 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 +0 -1
- 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 +33 -41
- 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 +19 -27
- 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 +0 -1
- 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 +0 -1
- package/dist/elements/FullscreenModal/index.js.map +1 -1
- package/dist/elements/LivePreview/IFrame/index.d.ts +7 -1
- package/dist/elements/LivePreview/IFrame/index.d.ts.map +1 -1
- package/dist/elements/LivePreview/IFrame/index.js +18 -39
- 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 +61 -135
- 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 +0 -4
- package/dist/elements/Status/index.d.ts.map +1 -1
- package/dist/elements/Status/index.js +1 -1
- 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 +14 -20
- package/dist/elements/Table/DefaultCell/index.js.map +1 -1
- package/dist/elements/Thumbnail/index.d.ts +2 -4
- package/dist/elements/Thumbnail/index.d.ts.map +1 -1
- package/dist/elements/Thumbnail/index.js +2 -6
- package/dist/elements/Thumbnail/index.js.map +1 -1
- package/dist/elements/Thumbnail/index.scss +9 -11
- 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 +0 -1
- package/dist/exports/rsc/index.d.ts.map +1 -1
- package/dist/exports/rsc/index.js +0 -1
- 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 +16 -36
- 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 +5 -1
- 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 +2 -1
- 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 +0 -8
- 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 +236 -223
- 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 +2 -33
- 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 +1 -2
- 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 +0 -2
- package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/types.d.ts +0 -6
- 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 +73 -76
- package/dist/forms/useField/index.js.map +1 -1
- package/dist/forms/useField/types.d.ts +9 -5
- 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 +2 -17
- package/dist/providers/LivePreview/context.d.ts.map +1 -1
- package/dist/providers/LivePreview/context.js +2 -3
- 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 +19 -33
- package/dist/providers/LivePreview/index.js.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/index.d.ts +1 -2
- package/dist/providers/TableColumns/buildColumnState/index.d.ts.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/index.js +0 -2
- package/dist/providers/TableColumns/buildColumnState/index.js.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/renderCell.d.ts +2 -3
- package/dist/providers/TableColumns/buildColumnState/renderCell.d.ts.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/renderCell.js +2 -39
- package/dist/providers/TableColumns/buildColumnState/renderCell.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/utilities/buildFormState.d.ts +0 -2
- package/dist/utilities/buildFormState.d.ts.map +1 -1
- package/dist/utilities/buildFormState.js +1 -20
- package/dist/utilities/buildFormState.js.map +1 -1
- package/dist/utilities/getFolderResultsComponentAndData.d.ts.map +1 -1
- package/dist/utilities/getFolderResultsComponentAndData.js +4 -0
- package/dist/utilities/getFolderResultsComponentAndData.js.map +1 -1
- package/dist/utilities/handleTakeOver.d.ts +4 -17
- package/dist/utilities/handleTakeOver.d.ts.map +1 -1
- package/dist/utilities/handleTakeOver.js +2 -18
- package/dist/utilities/handleTakeOver.js.map +1 -1
- package/dist/utilities/renderTable.d.ts +2 -3
- package/dist/utilities/renderTable.d.ts.map +1 -1
- package/dist/utilities/renderTable.js +0 -2
- package/dist/utilities/renderTable.js.map +1 -1
- package/dist/views/Edit/index.d.ts.map +1 -1
- package/dist/views/Edit/index.js +13 -48
- package/dist/views/Edit/index.js.map +1 -1
- package/package.json +5 -5
- package/dist/utilities/formatAbsoluteURL.d.ts +0 -8
- package/dist/utilities/formatAbsoluteURL.d.ts.map +0 -1
- package/dist/utilities/formatAbsoluteURL.js +0 -15
- package/dist/utilities/formatAbsoluteURL.js.map +0 -1
- package/dist/utilities/handleLivePreview.d.ts +0 -58
- package/dist/utilities/handleLivePreview.d.ts.map +0 -1
- package/dist/utilities/handleLivePreview.js +0 -96
- package/dist/utilities/handleLivePreview.js.map +0 -1
|
@@ -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(64);
|
|
15
15
|
let t0;
|
|
16
16
|
if ($[0] !== options) {
|
|
17
17
|
t0 = options || {};
|
|
@@ -109,40 +109,38 @@ 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
|
-
|
|
116
|
-
let t9;
|
|
112
|
+
const t5 = field?.customComponents;
|
|
113
|
+
const t6 = processing || initializing;
|
|
114
|
+
const t7 = field?.errorMessage;
|
|
115
|
+
let t8;
|
|
117
116
|
if ($[12] !== field?.errorPaths) {
|
|
118
|
-
|
|
117
|
+
t8 = field?.errorPaths || [];
|
|
119
118
|
$[12] = field?.errorPaths;
|
|
120
|
-
$[13] =
|
|
119
|
+
$[13] = t8;
|
|
121
120
|
} else {
|
|
122
|
-
|
|
121
|
+
t8 = $[13];
|
|
123
122
|
}
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
let
|
|
128
|
-
if ($[14] !== filterOptions || $[15] !== initialValue || $[16] !== initializing || $[17] !== path || $[18] !== processing || $[19] !== setValue || $[20] !== showError || $[21] !== submitted || $[22] !== t10 || $[23] !== t11 || $[24] !==
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
errorPaths: t9,
|
|
123
|
+
const t9 = field?.rows;
|
|
124
|
+
const t10 = field?.selectFilterOptions;
|
|
125
|
+
const t11 = field?.valid;
|
|
126
|
+
let t12;
|
|
127
|
+
if ($[14] !== filterOptions || $[15] !== initialValue || $[16] !== initializing || $[17] !== path || $[18] !== processing || $[19] !== setValue || $[20] !== showError || $[21] !== submitted || $[22] !== t10 || $[23] !== t11 || $[24] !== t5 || $[25] !== t6 || $[26] !== t7 || $[27] !== t8 || $[28] !== t9 || $[29] !== value) {
|
|
128
|
+
t12 = {
|
|
129
|
+
customComponents: t5,
|
|
130
|
+
disabled: t6,
|
|
131
|
+
errorMessage: t7,
|
|
132
|
+
errorPaths: t8,
|
|
135
133
|
filterOptions,
|
|
136
134
|
formInitializing: initializing,
|
|
137
135
|
formProcessing: processing,
|
|
138
136
|
formSubmitted: submitted,
|
|
139
137
|
initialValue,
|
|
140
138
|
path,
|
|
141
|
-
rows:
|
|
142
|
-
selectFilterOptions:
|
|
139
|
+
rows: t9,
|
|
140
|
+
selectFilterOptions: t10,
|
|
143
141
|
setValue,
|
|
144
142
|
showError,
|
|
145
|
-
valid:
|
|
143
|
+
valid: t11,
|
|
146
144
|
value
|
|
147
145
|
};
|
|
148
146
|
$[14] = filterOptions;
|
|
@@ -155,21 +153,20 @@ const useFieldInForm = options => {
|
|
|
155
153
|
$[21] = submitted;
|
|
156
154
|
$[22] = t10;
|
|
157
155
|
$[23] = t11;
|
|
158
|
-
$[24] =
|
|
159
|
-
$[25] =
|
|
160
|
-
$[26] =
|
|
161
|
-
$[27] =
|
|
162
|
-
$[28] =
|
|
163
|
-
$[29] =
|
|
164
|
-
$[30] =
|
|
165
|
-
$[31] = t13;
|
|
156
|
+
$[24] = t5;
|
|
157
|
+
$[25] = t6;
|
|
158
|
+
$[26] = t7;
|
|
159
|
+
$[27] = t8;
|
|
160
|
+
$[28] = t9;
|
|
161
|
+
$[29] = value;
|
|
162
|
+
$[30] = t12;
|
|
166
163
|
} else {
|
|
167
|
-
|
|
164
|
+
t12 = $[30];
|
|
168
165
|
}
|
|
169
|
-
const result =
|
|
170
|
-
let
|
|
171
|
-
if ($[
|
|
172
|
-
|
|
166
|
+
const result = t12;
|
|
167
|
+
let t13;
|
|
168
|
+
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) {
|
|
169
|
+
t13 = () => {
|
|
173
170
|
const validateField = async () => {
|
|
174
171
|
let valueToValidate = value;
|
|
175
172
|
if (field?.rows && Array.isArray(field.rows)) {
|
|
@@ -227,50 +224,50 @@ const useFieldInForm = options => {
|
|
|
227
224
|
};
|
|
228
225
|
validateField();
|
|
229
226
|
};
|
|
230
|
-
$[
|
|
231
|
-
$[
|
|
232
|
-
$[
|
|
233
|
-
$[
|
|
234
|
-
$[
|
|
235
|
-
$[
|
|
236
|
-
$[
|
|
237
|
-
$[
|
|
238
|
-
$[
|
|
239
|
-
$[
|
|
240
|
-
$[
|
|
241
|
-
$[
|
|
242
|
-
$[
|
|
243
|
-
$[
|
|
244
|
-
$[
|
|
245
|
-
$[
|
|
246
|
-
$[
|
|
247
|
-
$[
|
|
248
|
-
$[
|
|
227
|
+
$[31] = collectionSlug;
|
|
228
|
+
$[32] = config;
|
|
229
|
+
$[33] = disableFormData;
|
|
230
|
+
$[34] = dispatchField;
|
|
231
|
+
$[35] = documentForm;
|
|
232
|
+
$[36] = field;
|
|
233
|
+
$[37] = getData;
|
|
234
|
+
$[38] = getDataByPath;
|
|
235
|
+
$[39] = getSiblingData;
|
|
236
|
+
$[40] = hasRows;
|
|
237
|
+
$[41] = id;
|
|
238
|
+
$[42] = operation;
|
|
239
|
+
$[43] = path;
|
|
240
|
+
$[44] = pathSegments;
|
|
241
|
+
$[45] = t;
|
|
242
|
+
$[46] = user;
|
|
243
|
+
$[47] = validate;
|
|
244
|
+
$[48] = value;
|
|
245
|
+
$[49] = t13;
|
|
249
246
|
} else {
|
|
250
|
-
|
|
247
|
+
t13 = $[49];
|
|
251
248
|
}
|
|
252
|
-
const
|
|
253
|
-
let
|
|
254
|
-
if ($[
|
|
255
|
-
|
|
256
|
-
$[
|
|
257
|
-
$[
|
|
258
|
-
$[
|
|
259
|
-
$[
|
|
260
|
-
$[
|
|
261
|
-
$[
|
|
262
|
-
$[
|
|
263
|
-
$[
|
|
264
|
-
$[
|
|
265
|
-
$[
|
|
266
|
-
$[
|
|
267
|
-
$[
|
|
268
|
-
$[
|
|
269
|
-
$[
|
|
249
|
+
const t14 = field?.rows;
|
|
250
|
+
let t15;
|
|
251
|
+
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) {
|
|
252
|
+
t15 = [value, disableFormData, dispatchField, getData, getSiblingData, getDataByPath, id, operation, path, user, validate, t14, collectionSlug];
|
|
253
|
+
$[50] = collectionSlug;
|
|
254
|
+
$[51] = disableFormData;
|
|
255
|
+
$[52] = dispatchField;
|
|
256
|
+
$[53] = getData;
|
|
257
|
+
$[54] = getDataByPath;
|
|
258
|
+
$[55] = getSiblingData;
|
|
259
|
+
$[56] = id;
|
|
260
|
+
$[57] = operation;
|
|
261
|
+
$[58] = path;
|
|
262
|
+
$[59] = t14;
|
|
263
|
+
$[60] = user;
|
|
264
|
+
$[61] = validate;
|
|
265
|
+
$[62] = value;
|
|
266
|
+
$[63] = t15;
|
|
270
267
|
} else {
|
|
271
|
-
|
|
268
|
+
t15 = $[63];
|
|
272
269
|
}
|
|
273
|
-
useThrottledEffect(
|
|
270
|
+
useThrottledEffect(t13, 150, t15);
|
|
274
271
|
return result;
|
|
275
272
|
};
|
|
276
273
|
/**
|
|
@@ -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","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,QAA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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,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,C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,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,4 +1,4 @@
|
|
|
1
|
-
import type { FieldState, Validate } from 'payload';
|
|
1
|
+
import type { FieldState, FilterOptionsResult, Option, Row, Validate } from 'payload';
|
|
2
2
|
export type Options = {
|
|
3
3
|
disableFormData?: boolean;
|
|
4
4
|
hasRows?: boolean;
|
|
@@ -26,18 +26,22 @@ export type Options = {
|
|
|
26
26
|
validate?: Validate;
|
|
27
27
|
};
|
|
28
28
|
export type FieldType<T> = {
|
|
29
|
+
customComponents?: FieldState['customComponents'];
|
|
29
30
|
disabled: boolean;
|
|
31
|
+
errorMessage?: string;
|
|
32
|
+
errorPaths?: string[];
|
|
33
|
+
filterOptions?: FilterOptionsResult;
|
|
30
34
|
formInitializing: boolean;
|
|
31
35
|
formProcessing: boolean;
|
|
32
36
|
formSubmitted: boolean;
|
|
33
37
|
initialValue?: T;
|
|
34
38
|
path: string;
|
|
35
|
-
/**
|
|
36
|
-
* @deprecated - readOnly is no longer returned from useField. Remove this in 4.0.
|
|
37
|
-
*/
|
|
38
39
|
readOnly?: boolean;
|
|
40
|
+
rows?: Row[];
|
|
41
|
+
selectFilterOptions?: Option[];
|
|
39
42
|
setValue: (val: unknown, disableModifyingForm?: boolean) => void;
|
|
40
43
|
showError: boolean;
|
|
44
|
+
valid?: boolean;
|
|
41
45
|
value: T;
|
|
42
|
-
}
|
|
46
|
+
};
|
|
43
47
|
//# 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,QAAQ,EAAE,MAAM,SAAS,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,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAErF,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,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC9B,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, 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
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/forms/useField/types.ts"],"sourcesContent":["import type { FieldState, FilterOptionsResult, Option, 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 selectFilterOptions?: Option[]\n setValue: (val: unknown, disableModifyingForm?: boolean) => void\n showError: boolean\n valid?: boolean\n value: T\n}\n"],"mappings":"AA6BA","ignoreList":[]}
|
|
@@ -7,17 +7,12 @@ export interface LivePreviewContextType {
|
|
|
7
7
|
appIsReady: boolean;
|
|
8
8
|
breakpoint: LivePreviewConfig['breakpoints'][number]['name'];
|
|
9
9
|
breakpoints: LivePreviewConfig['breakpoints'];
|
|
10
|
+
iframeHasLoaded: boolean;
|
|
10
11
|
iframeRef: React.RefObject<HTMLIFrameElement | null>;
|
|
11
12
|
isLivePreviewEnabled: boolean;
|
|
12
13
|
isLivePreviewing: boolean;
|
|
13
14
|
isPopupOpen: boolean;
|
|
14
15
|
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;
|
|
21
16
|
measuredDeviceSize: {
|
|
22
17
|
height: number;
|
|
23
18
|
width: number;
|
|
@@ -28,8 +23,8 @@ export interface LivePreviewContextType {
|
|
|
28
23
|
setAppIsReady: (appIsReady: boolean) => void;
|
|
29
24
|
setBreakpoint: (breakpoint: LivePreviewConfig['breakpoints'][number]['name']) => void;
|
|
30
25
|
setHeight: (height: number) => void;
|
|
26
|
+
setIframeHasLoaded: (loaded: boolean) => void;
|
|
31
27
|
setIsLivePreviewing: (isLivePreviewing: boolean) => void;
|
|
32
|
-
setLoadedURL: (loadedURL: string) => void;
|
|
33
28
|
setMeasuredDeviceSize: (size: {
|
|
34
29
|
height: number;
|
|
35
30
|
width: number;
|
|
@@ -40,11 +35,6 @@ export interface LivePreviewContextType {
|
|
|
40
35
|
x: number;
|
|
41
36
|
y: number;
|
|
42
37
|
}) => 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;
|
|
48
38
|
setWidth: (width: number) => void;
|
|
49
39
|
setZoom: (zoom: number) => void;
|
|
50
40
|
size: {
|
|
@@ -55,11 +45,6 @@ export interface LivePreviewContextType {
|
|
|
55
45
|
x: number;
|
|
56
46
|
y: number;
|
|
57
47
|
};
|
|
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';
|
|
63
48
|
url: string | undefined;
|
|
64
49
|
zoom: number;
|
|
65
50
|
}
|
|
@@ -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,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEzD,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,OAAO,CAAA;IACnB,UAAU,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAA;IAC5D,WAAW,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAA;IAC7C,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,iBAAiB,GAAG,IAAI,C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reviewContext = createContext({
|
|
|
5
5
|
appIsReady: false,
|
|
6
6
|
breakpoint: undefined,
|
|
7
7
|
breakpoints: undefined,
|
|
8
|
+
iframeHasLoaded: false,
|
|
8
9
|
iframeRef: undefined,
|
|
9
10
|
isLivePreviewEnabled: undefined,
|
|
10
11
|
isLivePreviewing: false,
|
|
@@ -19,13 +20,12 @@ export const LivePreviewContext = createContext({
|
|
|
19
20
|
setAppIsReady: () => {},
|
|
20
21
|
setBreakpoint: () => {},
|
|
21
22
|
setHeight: () => {},
|
|
23
|
+
setIframeHasLoaded: () => {},
|
|
22
24
|
setIsLivePreviewing: () => {},
|
|
23
|
-
setLoadedURL: () => {},
|
|
24
25
|
setMeasuredDeviceSize: () => {},
|
|
25
26
|
setPreviewWindowType: () => {},
|
|
26
27
|
setSize: () => {},
|
|
27
28
|
setToolbarPosition: () => {},
|
|
28
|
-
setURL: () => {},
|
|
29
29
|
setWidth: () => {},
|
|
30
30
|
setZoom: () => {},
|
|
31
31
|
size: {
|
|
@@ -36,7 +36,6 @@ export const LivePreviewContext = createContext({
|
|
|
36
36
|
x: 0,
|
|
37
37
|
y: 0
|
|
38
38
|
},
|
|
39
|
-
typeofLivePreviewURL: undefined,
|
|
40
39
|
url: undefined,
|
|
41
40
|
zoom: 1
|
|
42
41
|
});
|
|
@@ -1 +1 @@
|
|
|
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","
|
|
1
|
+
{"version":3,"file":"context.js","names":["createContext","use","LivePreviewContext","appIsReady","breakpoint","undefined","breakpoints","iframeHasLoaded","iframeRef","isLivePreviewEnabled","isLivePreviewing","isPopupOpen","measuredDeviceSize","height","width","openPopupWindow","popupRef","previewWindowType","setAppIsReady","setBreakpoint","setHeight","setIframeHasLoaded","setIsLivePreviewing","setMeasuredDeviceSize","setPreviewWindowType","setSize","setToolbarPosition","setWidth","setZoom","size","toolbarPosition","x","y","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 iframeHasLoaded: boolean\n iframeRef: React.RefObject<HTMLIFrameElement | null>\n isLivePreviewEnabled: boolean\n isLivePreviewing: boolean\n isPopupOpen: boolean\n listeningForMessages?: boolean\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 setIframeHasLoaded: (loaded: boolean) => void\n setIsLivePreviewing: (isLivePreviewing: boolean) => 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 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 url: string | undefined\n zoom: number\n}\n\nexport const LivePreviewContext = createContext<LivePreviewContextType>({\n appIsReady: false,\n breakpoint: undefined,\n breakpoints: undefined,\n iframeHasLoaded: false,\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 setIframeHasLoaded: () => {},\n setIsLivePreviewing: () => {},\n setMeasuredDeviceSize: () => {},\n setPreviewWindowType: () => {},\n setSize: () => {},\n setToolbarPosition: () => {},\n setWidth: () => {},\n setZoom: () => {},\n size: {\n height: 0,\n width: 0,\n },\n toolbarPosition: {\n x: 0,\n y: 0,\n },\n url: undefined,\n zoom: 1,\n})\n\nexport const useLivePreviewContext = () => use(LivePreviewContext)\n"],"mappings":"AAAA;;AAKA,SAASA,aAAa,EAAEC,GAAG,QAAQ;AA6CnC,OAAO,MAAMC,kBAAA,GAAqBF,aAAA,CAAsC;EACtEG,UAAA,EAAY;EACZC,UAAA,EAAYC,SAAA;EACZC,WAAA,EAAaD,SAAA;EACbE,eAAA,EAAiB;EACjBC,SAAA,EAAWH,SAAA;EACXI,oBAAA,EAAsBJ,SAAA;EACtBK,gBAAA,EAAkB;EAClBC,WAAA,EAAa;EACbC,kBAAA,EAAoB;IAClBC,MAAA,EAAQ;IACRC,KAAA,EAAO;EACT;EACAC,eAAA,EAAiBA,CAAA,MAAO;EACxBC,QAAA,EAAUX,SAAA;EACVY,iBAAA,EAAmB;EACnBC,aAAA,EAAeA,CAAA,MAAO;EACtBC,aAAA,EAAeA,CAAA,MAAO;EACtBC,SAAA,EAAWA,CAAA,MAAO;EAClBC,kBAAA,EAAoBA,CAAA,MAAO;EAC3BC,mBAAA,EAAqBA,CAAA,MAAO;EAC5BC,qBAAA,EAAuBA,CAAA,MAAO;EAC9BC,oBAAA,EAAsBA,CAAA,MAAO;EAC7BC,OAAA,EAASA,CAAA,MAAO;EAChBC,kBAAA,EAAoBA,CAAA,MAAO;EAC3BC,QAAA,EAAUA,CAAA,MAAO;EACjBC,OAAA,EAASA,CAAA,MAAO;EAChBC,IAAA,EAAM;IACJhB,MAAA,EAAQ;IACRC,KAAA,EAAO;EACT;EACAgB,eAAA,EAAiB;IACfC,CAAA,EAAG;IACHC,CAAA,EAAG;EACL;EACAC,GAAA,EAAK5B,SAAA;EACL6B,IAAA,EAAM;AACR;AAEA,OAAO,MAAMC,qBAAA,GAAwBA,CAAA,KAAMlC,GAAA,CAAIC,kBAAA","ignoreList":[]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { LivePreviewConfig } from 'payload';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import type { LivePreviewContextType } from './context.js';
|
|
4
3
|
export type LivePreviewProviderProps = {
|
|
5
4
|
appIsReady?: boolean;
|
|
6
5
|
breakpoints?: LivePreviewConfig['breakpoints'];
|
|
@@ -11,6 +10,7 @@ export type LivePreviewProviderProps = {
|
|
|
11
10
|
};
|
|
12
11
|
isLivePreviewEnabled?: boolean;
|
|
13
12
|
isLivePreviewing: boolean;
|
|
14
|
-
|
|
13
|
+
url: string;
|
|
14
|
+
};
|
|
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;AAShF,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;IACzB,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAUD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CAgOlE,CAAA"}
|
|
@@ -6,17 +6,22 @@ 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';
|
|
10
9
|
import { customCollisionDetection } from './collisionDetection.js';
|
|
11
10
|
import { LivePreviewContext } from './context.js';
|
|
12
11
|
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
|
+
};
|
|
13
19
|
export const LivePreviewProvider = ({
|
|
14
20
|
breakpoints: incomingBreakpoints,
|
|
15
21
|
children,
|
|
16
22
|
isLivePreviewEnabled,
|
|
17
23
|
isLivePreviewing: incomingIsLivePreviewing,
|
|
18
|
-
|
|
19
|
-
url: urlFromProps
|
|
24
|
+
url: incomingUrl
|
|
20
25
|
}) => {
|
|
21
26
|
const [previewWindowType, setPreviewWindowType] = useState('iframe');
|
|
22
27
|
const [isLivePreviewing, setIsLivePreviewing] = useState(incomingIsLivePreviewing);
|
|
@@ -27,6 +32,10 @@ export const LivePreviewProvider = ({
|
|
|
27
32
|
width: '100%'
|
|
28
33
|
}], [incomingBreakpoints]);
|
|
29
34
|
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]);
|
|
30
39
|
const {
|
|
31
40
|
isPopupOpen,
|
|
32
41
|
openPopupWindow,
|
|
@@ -46,7 +55,7 @@ export const LivePreviewProvider = ({
|
|
|
46
55
|
setPreference
|
|
47
56
|
} = usePreferences();
|
|
48
57
|
const iframeRef = React.useRef(null);
|
|
49
|
-
const [
|
|
58
|
+
const [iframeHasLoaded, setIframeHasLoaded] = useState(false);
|
|
50
59
|
const [zoom, setZoom] = useState(1);
|
|
51
60
|
const [position, setPosition] = useState({
|
|
52
61
|
x: 0,
|
|
@@ -61,25 +70,6 @@ export const LivePreviewProvider = ({
|
|
|
61
70
|
width: 0
|
|
62
71
|
});
|
|
63
72
|
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]);
|
|
83
73
|
// The toolbar needs to freely drag and drop around the page
|
|
84
74
|
const handleDragEnd = ev => {
|
|
85
75
|
// only update position if the toolbar is completely within the preview area
|
|
@@ -121,12 +111,10 @@ export const LivePreviewProvider = ({
|
|
|
121
111
|
});
|
|
122
112
|
}
|
|
123
113
|
}, [breakpoint, breakpoints]);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
* Unlike iframe elements which have an `onLoad` handler, there is no way to access `window.open` on popups
|
|
129
|
-
*/
|
|
114
|
+
// Receive the `ready` message from the popup window
|
|
115
|
+
// This indicates that the app is ready to receive `window.postMessage` events
|
|
116
|
+
// This is also the only cross-origin way of detecting when a popup window has loaded
|
|
117
|
+
// Unlike iframe elements which have an `onLoad` handler, there is no way to access `window.open` on popups
|
|
130
118
|
useEffect(() => {
|
|
131
119
|
const handleMessage = event => {
|
|
132
120
|
if (url?.startsWith(event.origin) && event.data && typeof event.data === 'object' && event.data.type === 'payload-live-preview') {
|
|
@@ -170,12 +158,12 @@ export const LivePreviewProvider = ({
|
|
|
170
158
|
appIsReady,
|
|
171
159
|
breakpoint,
|
|
172
160
|
breakpoints,
|
|
161
|
+
iframeHasLoaded,
|
|
173
162
|
iframeRef,
|
|
174
163
|
isLivePreviewEnabled,
|
|
175
164
|
isLivePreviewing,
|
|
176
165
|
isPopupOpen,
|
|
177
166
|
listeningForMessages,
|
|
178
|
-
loadedURL,
|
|
179
167
|
measuredDeviceSize,
|
|
180
168
|
openPopupWindow,
|
|
181
169
|
popupRef,
|
|
@@ -183,18 +171,16 @@ export const LivePreviewProvider = ({
|
|
|
183
171
|
setAppIsReady,
|
|
184
172
|
setBreakpoint,
|
|
185
173
|
setHeight,
|
|
174
|
+
setIframeHasLoaded,
|
|
186
175
|
setIsLivePreviewing,
|
|
187
|
-
setLoadedURL,
|
|
188
176
|
setMeasuredDeviceSize,
|
|
189
177
|
setPreviewWindowType: handleWindowChange,
|
|
190
178
|
setSize,
|
|
191
179
|
setToolbarPosition: setPosition,
|
|
192
|
-
setURL: setLivePreviewURL,
|
|
193
180
|
setWidth,
|
|
194
181
|
setZoom,
|
|
195
182
|
size,
|
|
196
183
|
toolbarPosition: position,
|
|
197
|
-
typeofLivePreviewURL,
|
|
198
184
|
url,
|
|
199
185
|
zoom
|
|
200
186
|
},
|