@payloadcms/ui 3.0.0-beta.79 → 3.0.0-beta.80

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.
Files changed (41) hide show
  1. package/dist/elements/Nav/context.d.ts +3 -0
  2. package/dist/elements/Nav/context.d.ts.map +1 -1
  3. package/dist/elements/Nav/context.js +16 -7
  4. package/dist/elements/Nav/context.js.map +1 -1
  5. package/dist/exports/client/index.js +7 -7
  6. package/dist/exports/client/index.js.map +3 -3
  7. package/dist/fields/Array/index.js +1 -1
  8. package/dist/fields/Array/index.js.map +1 -1
  9. package/dist/fields/Blocks/index.js +1 -1
  10. package/dist/fields/Blocks/index.js.map +1 -1
  11. package/dist/fields/Code/index.js +1 -1
  12. package/dist/fields/Code/index.js.map +1 -1
  13. package/dist/fields/Collapsible/index.js +1 -1
  14. package/dist/fields/Collapsible/index.js.map +1 -1
  15. package/dist/fields/DateTime/index.js +1 -1
  16. package/dist/fields/DateTime/index.js.map +1 -1
  17. package/dist/fields/Group/index.js +1 -1
  18. package/dist/fields/Group/index.js.map +1 -1
  19. package/dist/fields/JSON/index.d.ts.map +1 -1
  20. package/dist/fields/JSON/index.js +1 -1
  21. package/dist/fields/JSON/index.js.map +1 -1
  22. package/dist/fields/Point/index.js +1 -1
  23. package/dist/fields/Point/index.js.map +1 -1
  24. package/dist/fields/Relationship/index.js +1 -1
  25. package/dist/fields/Relationship/index.js.map +1 -1
  26. package/dist/fields/Row/index.d.ts.map +1 -1
  27. package/dist/fields/Row/index.js +1 -1
  28. package/dist/fields/Row/index.js.map +1 -1
  29. package/dist/fields/Tabs/index.js +1 -1
  30. package/dist/fields/Tabs/index.js.map +1 -1
  31. package/dist/fields/Text/index.js +1 -1
  32. package/dist/fields/Text/index.js.map +1 -1
  33. package/dist/fields/Textarea/index.js +1 -1
  34. package/dist/fields/Textarea/index.js.map +1 -1
  35. package/dist/fields/Upload/index.js +1 -1
  36. package/dist/fields/Upload/index.js.map +1 -1
  37. package/dist/providers/Root/index.d.ts +1 -0
  38. package/dist/providers/Root/index.d.ts.map +1 -1
  39. package/dist/providers/Root/index.js +2 -1
  40. package/dist/providers/Root/index.js.map +1 -1
  41. package/package.json +4 -4
@@ -26,7 +26,7 @@ import { ArrayRow } from './ArrayRow.js';
26
26
  import './index.scss';
27
27
  const baseClass = 'array-field';
28
28
  export const ArrayFieldComponent = (props)=>{
29
- const { descriptionProps, errorProps, field, field: { name, _path: pathFromProps, admin: { className, components: { RowLabel }, description, isSortable = true, readOnly: readOnlyFromAdmin }, fields, label, localized, maxRows, minRows: minRowsProp, required }, forceRender = false, labelProps, readOnly: readOnlyFromTopLevelProps, validate } = props;
29
+ const { descriptionProps, errorProps, field, field: { name, _path: pathFromProps, admin: { className, components: { RowLabel }, description, isSortable = true, readOnly: readOnlyFromAdmin } = {}, fields, label, localized, maxRows, minRows: minRowsProp, required }, forceRender = false, labelProps, readOnly: readOnlyFromTopLevelProps, validate } = props;
30
30
  const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin;
31
31
  const { indexPath, path: pathFromContext, permissions, readOnly: readOnlyFromContext } = useFieldProps();
32
32
  const minRows = minRowsProp ?? required ? 1 : 0;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/Array/index.tsx"],"sourcesContent":["'use client'\nimport type { ArrayFieldProps, ArrayField as ArrayFieldType } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useCallback } from 'react'\n\nimport { Banner } from '../../elements/Banner/index.js'\nimport { Button } from '../../elements/Button/index.js'\nimport { DraggableSortableItem } from '../../elements/DraggableSortable/DraggableSortableItem/index.js'\nimport { DraggableSortable } from '../../elements/DraggableSortable/index.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { useForm, useFormSubmitted } from '../../forms/Form/context.js'\nimport { extractRowsAndCollapsedIDs, toggleAllRows } from '../../forms/Form/rowHelpers.js'\nimport { NullifyLocaleField } from '../../forms/NullifyField/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { scrollToID } from '../../utilities/scrollToID.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { FieldError } from '../FieldError/index.js'\nimport { FieldLabel } from '../FieldLabel/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport { ArrayRow } from './ArrayRow.js'\nimport './index.scss'\n\nconst baseClass = 'array-field'\n\nexport const ArrayFieldComponent: React.FC<ArrayFieldProps> = (props) => {\n const {\n descriptionProps,\n errorProps,\n field,\n field: {\n name,\n _path: pathFromProps,\n admin: {\n className,\n components: { RowLabel },\n description,\n isSortable = true,\n readOnly: readOnlyFromAdmin,\n },\n fields,\n label,\n localized,\n maxRows,\n minRows: minRowsProp,\n required,\n },\n forceRender = false,\n labelProps,\n readOnly: readOnlyFromTopLevelProps,\n validate,\n } = props\n\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const {\n indexPath,\n path: pathFromContext,\n permissions,\n readOnly: readOnlyFromContext,\n } = useFieldProps()\n\n const minRows = minRowsProp ?? required ? 1 : 0\n\n const { setDocFieldPreferences } = useDocumentInfo()\n const { addFieldRow, dispatchFields, setModified } = useForm()\n const submitted = useFormSubmitted()\n const { code: locale } = useLocale()\n const { i18n, t } = useTranslation()\n\n const {\n config: { localization },\n } = useConfig()\n\n const editingDefaultLocale = (() => {\n if (localization && localization.fallback) {\n const defaultLocale = localization.defaultLocale || 'en'\n return locale === defaultLocale\n }\n\n return true\n })()\n\n // Handle labeling for Arrays, Global Arrays, and Blocks\n const getLabels = (p: ArrayFieldProps): Partial<ArrayFieldType['labels']> => {\n if ('labels' in p && p?.labels) return p.labels\n if ('label' in p.field && p.field.label) return { plural: undefined, singular: p.field.label }\n return { plural: t('general:rows'), singular: t('general:row') }\n }\n\n const labels = getLabels(props)\n\n const memoizedValidate = useCallback(\n (value, options) => {\n // alternative locales can be null\n if (!editingDefaultLocale && value === null) {\n return true\n }\n if (typeof validate === 'function') {\n return validate(value, { ...options, maxRows, minRows, required })\n }\n },\n [maxRows, minRows, required, validate, editingDefaultLocale],\n )\n\n const {\n errorPaths,\n formInitializing,\n formProcessing,\n path,\n rows = [],\n schemaPath,\n showError,\n valid,\n value,\n } = useField<number>({\n hasRows: true,\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const addRow = useCallback(\n async (rowIndex: number): Promise<void> => {\n await addFieldRow({ path, rowIndex, schemaPath })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex + 1}`)\n }, 0)\n },\n [addFieldRow, path, setModified, schemaPath],\n )\n\n const duplicateRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({ type: 'DUPLICATE_ROW', path, rowIndex })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex}`)\n }, 0)\n },\n [dispatchFields, path, setModified],\n )\n\n const removeRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({ type: 'REMOVE_ROW', path, rowIndex })\n setModified(true)\n },\n [dispatchFields, path, setModified],\n )\n\n const moveRow = useCallback(\n (moveFromIndex: number, moveToIndex: number) => {\n dispatchFields({ type: 'MOVE_ROW', moveFromIndex, moveToIndex, path })\n setModified(true)\n },\n [dispatchFields, path, setModified],\n )\n\n const toggleCollapseAll = useCallback(\n (collapsed: boolean) => {\n const { collapsedIDs, updatedRows } = toggleAllRows({\n collapsed,\n rows,\n })\n dispatchFields({ type: 'SET_ALL_ROWS_COLLAPSED', path, updatedRows })\n setDocFieldPreferences(path, { collapsed: collapsedIDs })\n },\n [dispatchFields, path, rows, setDocFieldPreferences],\n )\n\n const setCollapse = useCallback(\n (rowID: string, collapsed: boolean) => {\n const { collapsedIDs, updatedRows } = extractRowsAndCollapsedIDs({\n collapsed,\n rowID,\n rows,\n })\n dispatchFields({ type: 'SET_ROW_COLLAPSED', path, updatedRows })\n setDocFieldPreferences(path, { collapsed: collapsedIDs })\n },\n [dispatchFields, path, rows, setDocFieldPreferences],\n )\n\n const hasMaxRows = maxRows && rows.length >= maxRows\n\n const fieldErrorCount = errorPaths.length\n const fieldHasErrors = submitted && errorPaths.length > 0\n\n const showRequired = disabled && rows.length === 0\n const showMinRows = rows.length < minRows || (required && rows.length === 0)\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n fieldHasErrors ? `${baseClass}--has-error` : `${baseClass}--has-no-error`,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${path.replace(/\\./g, '__')}`}\n >\n {showError && (\n <FieldError\n CustomError={field?.admin?.components?.Error}\n path={path}\n {...(errorProps || {})}\n />\n )}\n <header className={`${baseClass}__header`}>\n <div className={`${baseClass}__header-wrap`}>\n <div className={`${baseClass}__header-content`}>\n <h3 className={`${baseClass}__title`}>\n <FieldLabel\n Label={field?.admin?.components?.Label}\n as=\"span\"\n label={label}\n required={required}\n unstyled\n {...(labelProps || {})}\n />\n </h3>\n {fieldHasErrors && fieldErrorCount > 0 && (\n <ErrorPill count={fieldErrorCount} i18n={i18n} withMessage />\n )}\n </div>\n {rows.length > 0 && (\n <ul className={`${baseClass}__header-actions`}>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(true)}\n type=\"button\"\n >\n {t('fields:collapseAll')}\n </button>\n </li>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(false)}\n type=\"button\"\n >\n {t('fields:showAll')}\n </button>\n </li>\n </ul>\n )}\n </div>\n <FieldDescription\n Description={field?.admin?.components?.Description}\n description={description}\n {...(descriptionProps || {})}\n />\n </header>\n <NullifyLocaleField fieldValue={value} localized={localized} path={path} />\n {(rows.length > 0 || (!valid && (showRequired || showMinRows))) && (\n <DraggableSortable\n className={`${baseClass}__draggable-rows`}\n ids={rows.map((row) => row.id)}\n onDragEnd={({ moveFromIndex, moveToIndex }) => moveRow(moveFromIndex, moveToIndex)}\n >\n {rows.map((row, i) => {\n const rowErrorCount = errorPaths?.filter((errorPath) =>\n errorPath.startsWith(`${path}.${i}.`),\n ).length\n return (\n <DraggableSortableItem disabled={disabled || !isSortable} id={row.id} key={row.id}>\n {(draggableSortableItemProps) => (\n <ArrayRow\n {...draggableSortableItemProps}\n RowLabel={RowLabel}\n addRow={addRow}\n duplicateRow={duplicateRow}\n errorCount={rowErrorCount}\n fields={fields}\n forceRender={forceRender}\n hasMaxRows={hasMaxRows}\n indexPath={indexPath}\n isSortable={isSortable}\n labels={labels}\n moveRow={moveRow}\n path={path}\n permissions={permissions}\n readOnly={disabled}\n removeRow={removeRow}\n row={row}\n rowCount={rows.length}\n rowIndex={i}\n schemaPath={schemaPath}\n setCollapse={setCollapse}\n />\n )}\n </DraggableSortableItem>\n )\n })}\n {!valid && (\n <React.Fragment>\n {showRequired && (\n <Banner>\n {t('validation:fieldHasNo', { label: getTranslation(labels.plural, i18n) })}\n </Banner>\n )}\n {showMinRows && (\n <Banner type=\"error\">\n {t('validation:requiresAtLeast', {\n count: minRows,\n label:\n getTranslation(minRows > 1 ? labels.plural : labels.singular, i18n) ||\n t(minRows > 1 ? 'general:rows' : 'general:row'),\n })}\n </Banner>\n )}\n </React.Fragment>\n )}\n </DraggableSortable>\n )}\n {!disabled && !hasMaxRows && (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__add-row`}\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n onClick={() => {\n void addRow(value || 0)\n }}\n >\n {t('fields:addLabel', { label: getTranslation(labels.singular, i18n) })}\n </Button>\n )}\n </div>\n )\n}\n\nexport const ArrayField = withCondition(ArrayFieldComponent)\n"],"names":["getTranslation","React","useCallback","Banner","Button","DraggableSortableItem","DraggableSortable","ErrorPill","useFieldProps","useForm","useFormSubmitted","extractRowsAndCollapsedIDs","toggleAllRows","NullifyLocaleField","useField","withCondition","useConfig","useDocumentInfo","useLocale","useTranslation","scrollToID","FieldDescription","FieldError","FieldLabel","fieldBaseClass","ArrayRow","baseClass","ArrayFieldComponent","props","descriptionProps","errorProps","field","name","_path","pathFromProps","admin","className","components","RowLabel","description","isSortable","readOnly","readOnlyFromAdmin","fields","label","localized","maxRows","minRows","minRowsProp","required","forceRender","labelProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","indexPath","path","pathFromContext","permissions","readOnlyFromContext","setDocFieldPreferences","addFieldRow","dispatchFields","setModified","submitted","code","locale","i18n","t","config","localization","editingDefaultLocale","fallback","defaultLocale","getLabels","p","labels","plural","undefined","singular","memoizedValidate","value","options","errorPaths","formInitializing","formProcessing","rows","schemaPath","showError","valid","hasRows","disabled","addRow","rowIndex","setTimeout","duplicateRow","type","removeRow","moveRow","moveFromIndex","moveToIndex","toggleCollapseAll","collapsed","collapsedIDs","updatedRows","setCollapse","rowID","hasMaxRows","length","fieldErrorCount","fieldHasErrors","showRequired","showMinRows","div","filter","Boolean","join","id","replace","CustomError","Error","header","h3","Label","as","unstyled","count","withMessage","ul","li","button","onClick","Description","fieldValue","ids","map","row","onDragEnd","i","rowErrorCount","errorPath","startsWith","draggableSortableItemProps","errorCount","rowCount","Fragment","buttonStyle","icon","iconPosition","iconStyle","ArrayField"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAE1C,SAASC,MAAM,QAAQ,iCAAgC;AACvD,SAASC,MAAM,QAAQ,iCAAgC;AACvD,SAASC,qBAAqB,QAAQ,kEAAiE;AACvG,SAASC,iBAAiB,QAAQ,4CAA2C;AAC7E,SAASC,SAAS,QAAQ,oCAAmC;AAC7D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,S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;oCACE,GAAGqH,0BAA0B;oCAC9BxG,UAAUA;oCACVsD,QAAQA;oCACRG,cAAcA;oCACdgD,YAAYJ;oCACZhG,QAAQA;oCACRO,aAAaA;oCACbyD,YAAYA;oCACZpD,WAAWA;oCACXf,YAAYA;oCACZoC,QAAQA;oCACRsB,SAASA;oCACT1C,MAAMA;oCACNE,aAAaA;oCACbjB,UAAUkD;oCACVM,WAAWA;oCACXuC,KAAKA;oCACLQ,UAAU1D,KAAKsB,MAAM;oCACrBf,UAAU6C;oCACVnD,YAAYA;oCACZkB,aAAaA;;2BAvBwD+B,IAAInB,EAAE;oBA4BrF;oBACC,CAAC5B,uBACA,MAACxF,MAAMgJ,QAAQ;;4BACZlC,8BACC,KAAC5G;0CACEiE,EAAE,yBAAyB;oCAAExB,OAAO5C,eAAe4E,OAAOC,MAAM,EAAEV;gCAAM;;4BAG5E6C,6BACC,KAAC7G;gCAAO6F,MAAK;0CACV5B,EAAE,8BAA8B;oCAC/B0D,OAAO/E;oCACPH,OACE5C,eAAe+C,UAAU,IAAI6B,OAAOC,MAAM,GAAGD,OAAOG,QAAQ,EAAEZ,SAC9DC,EAAErB,UAAU,IAAI,iBAAiB;gCACrC;;;;;;YAOX,CAAC4C,YAAY,CAACgB,4BACb,KAACvG;gBACC8I,aAAY;gBACZ9G,WAAW,CAAC,EAAEV,UAAU,SAAS,CAAC;gBAClCyH,MAAK;gBACLC,cAAa;gBACbC,WAAU;gBACVlB,SAAS;oBACP,KAAKvC,OAAOX,SAAS;gBACvB;0BAECb,EAAE,mBAAmB;oBAAExB,OAAO5C,eAAe4E,OAAOG,QAAQ,EAAEZ;gBAAM;;;;AAK/E,EAAC;AAED,OAAO,MAAMmF,aAAavI,cAAcY,qBAAoB"}
1
+ {"version":3,"sources":["../../../src/fields/Array/index.tsx"],"sourcesContent":["'use client'\nimport type { ArrayFieldProps, ArrayField as ArrayFieldType } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useCallback } from 'react'\n\nimport { Banner } from '../../elements/Banner/index.js'\nimport { Button } from '../../elements/Button/index.js'\nimport { DraggableSortableItem } from '../../elements/DraggableSortable/DraggableSortableItem/index.js'\nimport { DraggableSortable } from '../../elements/DraggableSortable/index.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { useForm, useFormSubmitted } from '../../forms/Form/context.js'\nimport { extractRowsAndCollapsedIDs, toggleAllRows } from '../../forms/Form/rowHelpers.js'\nimport { NullifyLocaleField } from '../../forms/NullifyField/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { scrollToID } from '../../utilities/scrollToID.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { FieldError } from '../FieldError/index.js'\nimport { FieldLabel } from '../FieldLabel/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport { ArrayRow } from './ArrayRow.js'\nimport './index.scss'\n\nconst baseClass = 'array-field'\n\nexport const ArrayFieldComponent: React.FC<ArrayFieldProps> = (props) => {\n const {\n descriptionProps,\n errorProps,\n field,\n field: {\n name,\n _path: pathFromProps,\n admin: {\n className,\n components: { RowLabel },\n description,\n isSortable = true,\n readOnly: readOnlyFromAdmin,\n } = {},\n fields,\n label,\n localized,\n maxRows,\n minRows: minRowsProp,\n required,\n },\n forceRender = false,\n labelProps,\n readOnly: readOnlyFromTopLevelProps,\n validate,\n } = props\n\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const {\n indexPath,\n path: pathFromContext,\n permissions,\n readOnly: readOnlyFromContext,\n } = useFieldProps()\n\n const minRows = minRowsProp ?? required ? 1 : 0\n\n const { setDocFieldPreferences } = useDocumentInfo()\n const { addFieldRow, dispatchFields, setModified } = useForm()\n const submitted = useFormSubmitted()\n const { code: locale } = useLocale()\n const { i18n, t } = useTranslation()\n\n const {\n config: { localization },\n } = useConfig()\n\n const editingDefaultLocale = (() => {\n if (localization && localization.fallback) {\n const defaultLocale = localization.defaultLocale || 'en'\n return locale === defaultLocale\n }\n\n return true\n })()\n\n // Handle labeling for Arrays, Global Arrays, and Blocks\n const getLabels = (p: ArrayFieldProps): Partial<ArrayFieldType['labels']> => {\n if ('labels' in p && p?.labels) return p.labels\n if ('label' in p.field && p.field.label) return { plural: undefined, singular: p.field.label }\n return { plural: t('general:rows'), singular: t('general:row') }\n }\n\n const labels = getLabels(props)\n\n const memoizedValidate = useCallback(\n (value, options) => {\n // alternative locales can be null\n if (!editingDefaultLocale && value === null) {\n return true\n }\n if (typeof validate === 'function') {\n return validate(value, { ...options, maxRows, minRows, required })\n }\n },\n [maxRows, minRows, required, validate, editingDefaultLocale],\n )\n\n const {\n errorPaths,\n formInitializing,\n formProcessing,\n path,\n rows = [],\n schemaPath,\n showError,\n valid,\n value,\n } = useField<number>({\n hasRows: true,\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const addRow = useCallback(\n async (rowIndex: number): Promise<void> => {\n await addFieldRow({ path, rowIndex, schemaPath })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex + 1}`)\n }, 0)\n },\n [addFieldRow, path, setModified, schemaPath],\n )\n\n const duplicateRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({ type: 'DUPLICATE_ROW', path, rowIndex })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex}`)\n }, 0)\n },\n [dispatchFields, path, setModified],\n )\n\n const removeRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({ type: 'REMOVE_ROW', path, rowIndex })\n setModified(true)\n },\n [dispatchFields, path, setModified],\n )\n\n const moveRow = useCallback(\n (moveFromIndex: number, moveToIndex: number) => {\n dispatchFields({ type: 'MOVE_ROW', moveFromIndex, moveToIndex, path })\n setModified(true)\n },\n [dispatchFields, path, setModified],\n )\n\n const toggleCollapseAll = useCallback(\n (collapsed: boolean) => {\n const { collapsedIDs, updatedRows } = toggleAllRows({\n collapsed,\n rows,\n })\n dispatchFields({ type: 'SET_ALL_ROWS_COLLAPSED', path, updatedRows })\n setDocFieldPreferences(path, { collapsed: collapsedIDs })\n },\n [dispatchFields, path, rows, setDocFieldPreferences],\n )\n\n const setCollapse = useCallback(\n (rowID: string, collapsed: boolean) => {\n const { collapsedIDs, updatedRows } = extractRowsAndCollapsedIDs({\n collapsed,\n rowID,\n rows,\n })\n dispatchFields({ type: 'SET_ROW_COLLAPSED', path, updatedRows })\n setDocFieldPreferences(path, { collapsed: collapsedIDs })\n },\n [dispatchFields, path, rows, setDocFieldPreferences],\n )\n\n const hasMaxRows = maxRows && rows.length >= maxRows\n\n const fieldErrorCount = errorPaths.length\n const fieldHasErrors = submitted && errorPaths.length > 0\n\n const showRequired = disabled && rows.length === 0\n const showMinRows = rows.length < minRows || (required && rows.length === 0)\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n fieldHasErrors ? `${baseClass}--has-error` : `${baseClass}--has-no-error`,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${path.replace(/\\./g, '__')}`}\n >\n {showError && (\n <FieldError\n CustomError={field?.admin?.components?.Error}\n path={path}\n {...(errorProps || {})}\n />\n )}\n <header className={`${baseClass}__header`}>\n <div className={`${baseClass}__header-wrap`}>\n <div className={`${baseClass}__header-content`}>\n <h3 className={`${baseClass}__title`}>\n <FieldLabel\n Label={field?.admin?.components?.Label}\n as=\"span\"\n label={label}\n required={required}\n unstyled\n {...(labelProps || {})}\n />\n </h3>\n {fieldHasErrors && fieldErrorCount > 0 && (\n <ErrorPill count={fieldErrorCount} i18n={i18n} withMessage />\n )}\n </div>\n {rows.length > 0 && (\n <ul className={`${baseClass}__header-actions`}>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(true)}\n type=\"button\"\n >\n {t('fields:collapseAll')}\n </button>\n </li>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(false)}\n type=\"button\"\n >\n {t('fields:showAll')}\n </button>\n </li>\n </ul>\n )}\n </div>\n <FieldDescription\n Description={field?.admin?.components?.Description}\n description={description}\n {...(descriptionProps || {})}\n />\n </header>\n <NullifyLocaleField fieldValue={value} localized={localized} path={path} />\n {(rows.length > 0 || (!valid && (showRequired || showMinRows))) && (\n <DraggableSortable\n className={`${baseClass}__draggable-rows`}\n ids={rows.map((row) => row.id)}\n onDragEnd={({ moveFromIndex, moveToIndex }) => moveRow(moveFromIndex, moveToIndex)}\n >\n {rows.map((row, i) => {\n const rowErrorCount = errorPaths?.filter((errorPath) =>\n errorPath.startsWith(`${path}.${i}.`),\n ).length\n return (\n <DraggableSortableItem disabled={disabled || !isSortable} id={row.id} key={row.id}>\n {(draggableSortableItemProps) => (\n <ArrayRow\n {...draggableSortableItemProps}\n RowLabel={RowLabel}\n addRow={addRow}\n duplicateRow={duplicateRow}\n errorCount={rowErrorCount}\n fields={fields}\n forceRender={forceRender}\n hasMaxRows={hasMaxRows}\n indexPath={indexPath}\n isSortable={isSortable}\n labels={labels}\n moveRow={moveRow}\n path={path}\n permissions={permissions}\n readOnly={disabled}\n removeRow={removeRow}\n row={row}\n rowCount={rows.length}\n rowIndex={i}\n schemaPath={schemaPath}\n setCollapse={setCollapse}\n />\n )}\n </DraggableSortableItem>\n )\n })}\n {!valid && (\n <React.Fragment>\n {showRequired && (\n <Banner>\n {t('validation:fieldHasNo', { label: getTranslation(labels.plural, i18n) })}\n </Banner>\n )}\n {showMinRows && (\n <Banner type=\"error\">\n {t('validation:requiresAtLeast', {\n count: minRows,\n label:\n getTranslation(minRows > 1 ? labels.plural : labels.singular, i18n) ||\n t(minRows > 1 ? 'general:rows' : 'general:row'),\n })}\n </Banner>\n )}\n </React.Fragment>\n )}\n </DraggableSortable>\n )}\n {!disabled && !hasMaxRows && (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__add-row`}\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n onClick={() => {\n void addRow(value || 0)\n }}\n >\n {t('fields:addLabel', { label: getTranslation(labels.singular, i18n) })}\n </Button>\n )}\n </div>\n )\n}\n\nexport const ArrayField = withCondition(ArrayFieldComponent)\n"],"names":["getTranslation","React","useCallback","Banner","Button","DraggableSortableItem","DraggableSortable","ErrorPill","useFieldProps","useForm","useFormSubmitted","extractRowsAndCollapsedIDs","toggleAllRows","NullifyLocaleField","useField","withCondition","useConfig","useDocumentInfo","useLocale","useTranslation","scrollToID","FieldDescription","FieldError","FieldLabel","fieldBaseClass","ArrayRow","baseClass","ArrayFieldComponent","props","descriptionProps","errorProps","field","name","_path","pathFromProps","admin","className","components","RowLabel","description","isSortable","readOnly","readOnlyFromAdmin","fields","label","localized","maxRows","minRows","minRowsProp","required","forceRender","labelProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","indexPath","path","pathFromContext","permissions","readOnlyFromContext","setDocFieldPreferences","addFieldRow","dispatchFields","setModified","submitted","code","locale","i18n","t","config","localization","editingDefaultLocale","fallback","defaultLocale","getLabels","p","labels","plural","undefined","singular","memoizedValidate","value","options","errorPaths","formInitializing","formProcessing","rows","schemaPath","showError","valid","hasRows","disabled","addRow","rowIndex","setTimeout","duplicateRow","type","removeRow","moveRow","moveFromIndex","moveToIndex","toggleCollapseAll","collapsed","collapsedIDs","updatedRows","setCollapse","rowID","hasMaxRows","length","fieldErrorCount","fieldHasErrors","showRequired","showMinRows","div","filter","Boolean","join","id","replace","CustomError","Error","header","h3","Label","as","unstyled","count","withMessage","ul","li","button","onClick","Description","fieldValue","ids","map","row","onDragEnd","i","rowErrorCount","errorPath","startsWith","draggableSortableItemProps","errorCount","rowCount","Fragment","buttonStyle","icon","iconPosition","i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lB,SAAS;oBACP,KAAKvC,OAAOX,SAAS;gBACvB;0BAECb,EAAE,mBAAmB;oBAAExB,OAAO5C,eAAe4E,OAAOG,QAAQ,EAAEZ;gBAAM;;;;AAK/E,EAAC;AAED,OAAO,MAAMmF,aAAavI,cAAcY,qBAAoB"}
@@ -30,7 +30,7 @@ import './index.scss';
30
30
  const baseClass = 'blocks-field';
31
31
  const BlocksFieldComponent = (props)=>{
32
32
  const { i18n, t } = useTranslation();
33
- const { descriptionProps, errorProps, field, field: { name, _path: pathFromProps, admin: { className, description, isSortable = true, readOnly: readOnlyFromAdmin }, blocks, label, labels: labelsFromProps, localized, maxRows, minRows: minRowsProp, required }, forceRender = false, labelProps, readOnly: readOnlyFromTopLevelProps, validate } = props;
33
+ const { descriptionProps, errorProps, field, field: { name, _path: pathFromProps, admin: { className, description, isSortable = true, readOnly: readOnlyFromAdmin } = {}, blocks, label, labels: labelsFromProps, localized, maxRows, minRows: minRowsProp, required }, forceRender = false, labelProps, readOnly: readOnlyFromTopLevelProps, validate } = props;
34
34
  const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin;
35
35
  const { indexPath, readOnly: readOnlyFromContext } = useFieldProps();
36
36
  const minRows = minRowsProp ?? required ? 1 : 0;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/Blocks/index.tsx"],"sourcesContent":["'use client'\nimport type { BlockFieldProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { Fragment, useCallback } from 'react'\n\nimport { Banner } from '../../elements/Banner/index.js'\nimport { Button } from '../../elements/Button/index.js'\nimport { DraggableSortableItem } from '../../elements/DraggableSortable/DraggableSortableItem/index.js'\nimport { DraggableSortable } from '../../elements/DraggableSortable/index.js'\nimport { DrawerToggler } from '../../elements/Drawer/index.js'\nimport { useDrawerSlug } from '../../elements/Drawer/useDrawerSlug.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { useForm, useFormSubmitted } from '../../forms/Form/context.js'\nimport { extractRowsAndCollapsedIDs, toggleAllRows } from '../../forms/Form/rowHelpers.js'\nimport { NullifyLocaleField } from '../../forms/NullifyField/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { scrollToID } from '../../utilities/scrollToID.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { FieldError } from '../FieldError/index.js'\nimport { FieldLabel } from '../FieldLabel/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport { BlockRow } from './BlockRow.js'\nimport { BlocksDrawer } from './BlocksDrawer/index.js'\nimport './index.scss'\n\nconst baseClass = 'blocks-field'\n\nconst BlocksFieldComponent: React.FC<BlockFieldProps> = (props) => {\n const { i18n, t } = useTranslation()\n\n const {\n descriptionProps,\n errorProps,\n field,\n field: {\n name,\n _path: pathFromProps,\n admin: { className, description, isSortable = true, readOnly: readOnlyFromAdmin },\n blocks,\n label,\n labels: labelsFromProps,\n localized,\n maxRows,\n minRows: minRowsProp,\n required,\n },\n forceRender = false,\n labelProps,\n readOnly: readOnlyFromTopLevelProps,\n validate,\n } = props\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const { indexPath, readOnly: readOnlyFromContext } = useFieldProps()\n const minRows = minRowsProp ?? required ? 1 : 0\n\n const { setDocFieldPreferences } = useDocumentInfo()\n const { addFieldRow, dispatchFields, setModified } = useForm()\n const { code: locale } = useLocale()\n const {\n config: { localization },\n } = useConfig()\n const drawerSlug = useDrawerSlug('blocks-drawer')\n const submitted = useFormSubmitted()\n\n const labels = {\n plural: t('fields:blocks'),\n singular: t('fields:block'),\n ...labelsFromProps,\n }\n\n const editingDefaultLocale = (() => {\n if (localization && localization.fallback) {\n const defaultLocale = localization.defaultLocale || 'en'\n return locale === defaultLocale\n }\n\n return true\n })()\n\n const memoizedValidate = useCallback(\n (value, options) => {\n // alternative locales can be null\n if (!editingDefaultLocale && value === null) {\n return true\n }\n if (typeof validate === 'function') {\n return validate(value, { ...options, maxRows, minRows, required })\n }\n },\n [maxRows, minRows, required, validate, editingDefaultLocale],\n )\n\n const { path: pathFromContext } = useFieldProps()\n\n const {\n errorPaths,\n formInitializing,\n formProcessing,\n path,\n permissions,\n rows = [],\n schemaPath,\n showError,\n valid,\n value,\n } = useField<number>({\n hasRows: true,\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const addRow = useCallback(\n async (rowIndex: number, blockType: string): Promise<void> => {\n await addFieldRow({\n data: { blockType },\n path,\n rowIndex,\n schemaPath: `${schemaPath}.${blockType}`,\n })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex + 1}`)\n }, 0)\n },\n [addFieldRow, path, setModified, schemaPath],\n )\n\n const duplicateRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({ type: 'DUPLICATE_ROW', path, rowIndex })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex + 1}`)\n }, 0)\n },\n [dispatchFields, path, setModified],\n )\n\n const removeRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({\n type: 'REMOVE_ROW',\n path,\n rowIndex,\n })\n\n setModified(true)\n },\n [path, dispatchFields, setModified],\n )\n\n const moveRow = useCallback(\n (moveFromIndex: number, moveToIndex: number) => {\n dispatchFields({ type: 'MOVE_ROW', moveFromIndex, moveToIndex, path })\n setModified(true)\n },\n [dispatchFields, path, setModified],\n )\n\n const toggleCollapseAll = useCallback(\n (collapsed: boolean) => {\n const { collapsedIDs, updatedRows } = toggleAllRows({\n collapsed,\n rows,\n })\n dispatchFields({ type: 'SET_ALL_ROWS_COLLAPSED', path, updatedRows })\n setDocFieldPreferences(path, { collapsed: collapsedIDs })\n },\n [dispatchFields, path, rows, setDocFieldPreferences],\n )\n\n const setCollapse = useCallback(\n (rowID: string, collapsed: boolean) => {\n const { collapsedIDs, updatedRows } = extractRowsAndCollapsedIDs({\n collapsed,\n rowID,\n rows,\n })\n dispatchFields({ type: 'SET_ROW_COLLAPSED', path, updatedRows })\n setDocFieldPreferences(path, { collapsed: collapsedIDs })\n },\n [dispatchFields, path, rows, setDocFieldPreferences],\n )\n\n const hasMaxRows = maxRows && rows.length >= maxRows\n\n const fieldErrorCount = errorPaths.length\n const fieldHasErrors = submitted && fieldErrorCount + (valid ? 0 : 1) > 0\n\n const showMinRows = rows.length < minRows || (required && rows.length === 0)\n const showRequired = disabled && rows.length === 0\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n fieldHasErrors ? `${baseClass}--has-error` : `${baseClass}--has-no-error`,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${path.replace(/\\./g, '__')}`}\n >\n {showError && (\n <FieldError\n CustomError={field?.admin?.components?.Error}\n path={path}\n {...(errorProps || {})}\n />\n )}\n <header className={`${baseClass}__header`}>\n <div className={`${baseClass}__header-wrap`}>\n <div className={`${baseClass}__heading-with-error`}>\n <h3>\n <FieldLabel\n Label={field?.admin?.components?.Description}\n as=\"span\"\n label={label}\n required={required}\n unstyled\n {...(labelProps || {})}\n />\n </h3>\n {fieldHasErrors && fieldErrorCount > 0 && (\n <ErrorPill count={fieldErrorCount} i18n={i18n} withMessage />\n )}\n </div>\n {rows.length > 0 && (\n <ul className={`${baseClass}__header-actions`}>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(true)}\n type=\"button\"\n >\n {t('fields:collapseAll')}\n </button>\n </li>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(false)}\n type=\"button\"\n >\n {t('fields:showAll')}\n </button>\n </li>\n </ul>\n )}\n </div>\n <FieldDescription\n Description={field?.admin?.components?.Description}\n description={description}\n {...(descriptionProps || {})}\n />\n </header>\n <NullifyLocaleField fieldValue={value} localized={localized} path={path} />\n {(rows.length > 0 || (!valid && (showRequired || showMinRows))) && (\n <DraggableSortable\n className={`${baseClass}__rows`}\n ids={rows.map((row) => row.id)}\n onDragEnd={({ moveFromIndex, moveToIndex }) => moveRow(moveFromIndex, moveToIndex)}\n >\n {rows.map((row, i) => {\n const { blockType } = row\n const blockToRender = blocks.find((block) => block.slug === blockType)\n\n if (blockToRender) {\n const rowErrorCount = errorPaths.filter((errorPath) =>\n errorPath.startsWith(`${path}.${i}`),\n ).length\n return (\n <DraggableSortableItem disabled={disabled || !isSortable} id={row.id} key={row.id}>\n {(draggableSortableItemProps) => (\n <BlockRow\n {...draggableSortableItemProps}\n addRow={addRow}\n block={blockToRender}\n blocks={blocks}\n duplicateRow={duplicateRow}\n errorCount={rowErrorCount}\n forceRender={forceRender}\n hasMaxRows={hasMaxRows}\n indexPath={indexPath}\n isSortable={isSortable}\n labels={labels}\n moveRow={moveRow}\n path={path}\n permissions={permissions}\n readOnly={disabled}\n removeRow={removeRow}\n row={row}\n rowCount={rows.length}\n rowIndex={i}\n schemaPath={schemaPath}\n setCollapse={setCollapse}\n />\n )}\n </DraggableSortableItem>\n )\n }\n\n return null\n })}\n {!editingDefaultLocale && (\n <React.Fragment>\n {showMinRows && (\n <Banner type=\"error\">\n {t('validation:requiresAtLeast', {\n count: minRows,\n label:\n getTranslation(minRows > 1 ? labels.plural : labels.singular, i18n) ||\n t(minRows > 1 ? 'general:row' : 'general:rows'),\n })}\n </Banner>\n )}\n {showRequired && (\n <Banner>\n {t('validation:fieldHasNo', { label: getTranslation(labels.plural, i18n) })}\n </Banner>\n )}\n </React.Fragment>\n )}\n </DraggableSortable>\n )}\n {!disabled && !hasMaxRows && (\n <Fragment>\n <DrawerToggler className={`${baseClass}__drawer-toggler`} slug={drawerSlug}>\n <Button\n buttonStyle=\"icon-label\"\n el=\"span\"\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n >\n {t('fields:addLabel', { label: getTranslation(labels.singular, i18n) })}\n </Button>\n </DrawerToggler>\n <BlocksDrawer\n addRow={addRow}\n addRowIndex={rows?.length || 0}\n blocks={blocks}\n drawerSlug={drawerSlug}\n labels={labels}\n />\n </Fragment>\n )}\n </div>\n )\n}\n\nexport const BlocksField = withCondition(BlocksFieldComponent)\n"],"names":["getTranslation","React","Fragment","useCallback","Banner","Button","DraggableSortableItem","DraggableSortable","DrawerToggler","useDrawerSlug","ErrorPill","useFieldProps","useForm","useFormSubmitted","extractRowsAndCollapsedIDs","toggleAllRows","NullifyLocaleField","useField","withCondition","useConfig","useDocumentInfo","useLocale","useTranslation","scrollToID","FieldDescription","FieldError","FieldLabel","fieldBaseClass","BlockRow","BlocksDrawer","baseClass","BlocksFieldComponent","props","i18n","t","descriptionProps","errorProps","field","name","_path","pathFromProps","admin","className","description","isSortable","readOnly","readOnlyFromAdmin","blocks","label","labels","labelsFromProps","localized","maxRows","minRows","minRowsProp","required","forceRender","labelProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","indexPath","readOnlyFromContext","setDocFieldPreferences","addFieldRow","dispatchFields","setModified","code","locale","config","localization","drawerSlug","submitted","plural","singular","editingDefaultLocale","fallback","defaultLocale","memoizedValidate","value","options","path","pathFromContext","errorPaths","formInitializing","formProcessing","permissions","rows","schemaPath","showError","valid","hasRows","disabled","addRow","rowIndex","blockType","data","setTimeout","duplicateRow","type","removeRow","moveRow","moveFromIndex","moveToIndex","toggleCollapseAll","collapsed","collapsedIDs","updatedRows","setCollapse","rowID","hasMaxRows","length","fieldErrorCount","fieldHasErrors","showMinRows","showRequired","div","filter","Boolean","join","id","replace","CustomError","components","Error","header","h3","Label","Description","as","unstyled","count","withMessage","ul","li","button","onClick","fieldValue","ids","map","row","onDragEnd","i","blockToRender","find","block","slug","rowErrorCount","errorPath","startsWith","draggableSortableItemProps","errorCount","rowCount","buttonStyle","el","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OpF,CAAC2D,YAAY,CAACkB,4BACb,MAAC5G;;kCACC,KAACM;wBAAckC,WAAW,CAAC,EAAEZ,UAAU,gBAAgB,CAAC;wBAAEoH,MAAM3E;kCAC9D,cAAA,KAAClE;4BACCoJ,aAAY;4BACZC,IAAG;4BACHC,MAAK;4BACLC,cAAa;4BACbC,WAAU;sCAET3H,EAAE,mBAAmB;gCAAEc,OAAOhD,eAAeiD,OAAOyB,QAAQ,EAAEzC;4BAAM;;;kCAGzE,KAACJ;wBACCgE,QAAQA;wBACRiE,aAAavE,MAAMwB,UAAU;wBAC7BhE,QAAQA;wBACRwB,YAAYA;wBACZtB,QAAQA;;;;;;AAMpB;AAEA,OAAO,MAAM8G,cAAc7I,cAAca,sBAAqB"}
1
+ {"version":3,"sources":["../../../src/fields/Blocks/index.tsx"],"sourcesContent":["'use client'\nimport type { BlockFieldProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { Fragment, useCallback } from 'react'\n\nimport { Banner } from '../../elements/Banner/index.js'\nimport { Button } from '../../elements/Button/index.js'\nimport { DraggableSortableItem } from '../../elements/DraggableSortable/DraggableSortableItem/index.js'\nimport { DraggableSortable } from '../../elements/DraggableSortable/index.js'\nimport { DrawerToggler } from '../../elements/Drawer/index.js'\nimport { useDrawerSlug } from '../../elements/Drawer/useDrawerSlug.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { useForm, useFormSubmitted } from '../../forms/Form/context.js'\nimport { extractRowsAndCollapsedIDs, toggleAllRows } from '../../forms/Form/rowHelpers.js'\nimport { NullifyLocaleField } from '../../forms/NullifyField/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { scrollToID } from '../../utilities/scrollToID.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { FieldError } from '../FieldError/index.js'\nimport { FieldLabel } from '../FieldLabel/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport { BlockRow } from './BlockRow.js'\nimport { BlocksDrawer } from './BlocksDrawer/index.js'\nimport './index.scss'\n\nconst baseClass = 'blocks-field'\n\nconst BlocksFieldComponent: React.FC<BlockFieldProps> = (props) => {\n const { i18n, t } = useTranslation()\n\n const {\n descriptionProps,\n errorProps,\n field,\n field: {\n name,\n _path: pathFromProps,\n admin: { className, description, isSortable = true, readOnly: readOnlyFromAdmin } = {},\n blocks,\n label,\n labels: labelsFromProps,\n localized,\n maxRows,\n minRows: minRowsProp,\n required,\n },\n forceRender = false,\n labelProps,\n readOnly: readOnlyFromTopLevelProps,\n validate,\n } = props\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const { indexPath, readOnly: readOnlyFromContext } = useFieldProps()\n const minRows = minRowsProp ?? required ? 1 : 0\n\n const { setDocFieldPreferences } = useDocumentInfo()\n const { addFieldRow, dispatchFields, setModified } = useForm()\n const { code: locale } = useLocale()\n const {\n config: { localization },\n } = useConfig()\n const drawerSlug = useDrawerSlug('blocks-drawer')\n const submitted = useFormSubmitted()\n\n const labels = {\n plural: t('fields:blocks'),\n singular: t('fields:block'),\n ...labelsFromProps,\n }\n\n const editingDefaultLocale = (() => {\n if (localization && localization.fallback) {\n const defaultLocale = localization.defaultLocale || 'en'\n return locale === defaultLocale\n }\n\n return true\n })()\n\n const memoizedValidate = useCallback(\n (value, options) => {\n // alternative locales can be null\n if (!editingDefaultLocale && value === null) {\n return true\n }\n if (typeof validate === 'function') {\n return validate(value, { ...options, maxRows, minRows, required })\n }\n },\n [maxRows, minRows, required, validate, editingDefaultLocale],\n )\n\n const { path: pathFromContext } = useFieldProps()\n\n const {\n errorPaths,\n formInitializing,\n formProcessing,\n path,\n permissions,\n rows = [],\n schemaPath,\n showError,\n valid,\n value,\n } = useField<number>({\n hasRows: true,\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const addRow = useCallback(\n async (rowIndex: number, blockType: string): Promise<void> => {\n await addFieldRow({\n data: { blockType },\n path,\n rowIndex,\n schemaPath: `${schemaPath}.${blockType}`,\n })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex + 1}`)\n }, 0)\n },\n [addFieldRow, path, setModified, schemaPath],\n )\n\n const duplicateRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({ type: 'DUPLICATE_ROW', path, rowIndex })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex + 1}`)\n }, 0)\n },\n [dispatchFields, path, setModified],\n )\n\n const removeRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({\n type: 'REMOVE_ROW',\n path,\n rowIndex,\n })\n\n setModified(true)\n },\n [path, dispatchFields, setModified],\n )\n\n const moveRow = useCallback(\n (moveFromIndex: number, moveToIndex: number) => {\n dispatchFields({ type: 'MOVE_ROW', moveFromIndex, moveToIndex, path })\n setModified(true)\n },\n [dispatchFields, path, setModified],\n )\n\n const toggleCollapseAll = useCallback(\n (collapsed: boolean) => {\n const { collapsedIDs, updatedRows } = toggleAllRows({\n collapsed,\n rows,\n })\n dispatchFields({ type: 'SET_ALL_ROWS_COLLAPSED', path, updatedRows })\n setDocFieldPreferences(path, { collapsed: collapsedIDs })\n },\n [dispatchFields, path, rows, setDocFieldPreferences],\n )\n\n const setCollapse = useCallback(\n (rowID: string, collapsed: boolean) => {\n const { collapsedIDs, updatedRows } = extractRowsAndCollapsedIDs({\n collapsed,\n rowID,\n rows,\n })\n dispatchFields({ type: 'SET_ROW_COLLAPSED', path, updatedRows })\n setDocFieldPreferences(path, { collapsed: collapsedIDs })\n },\n [dispatchFields, path, rows, setDocFieldPreferences],\n )\n\n const hasMaxRows = maxRows && rows.length >= maxRows\n\n const fieldErrorCount = errorPaths.length\n const fieldHasErrors = submitted && fieldErrorCount + (valid ? 0 : 1) > 0\n\n const showMinRows = rows.length < minRows || (required && rows.length === 0)\n const showRequired = disabled && rows.length === 0\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n fieldHasErrors ? `${baseClass}--has-error` : `${baseClass}--has-no-error`,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${path.replace(/\\./g, '__')}`}\n >\n {showError && (\n <FieldError\n CustomError={field?.admin?.components?.Error}\n path={path}\n {...(errorProps || {})}\n />\n )}\n <header className={`${baseClass}__header`}>\n <div className={`${baseClass}__header-wrap`}>\n <div className={`${baseClass}__heading-with-error`}>\n <h3>\n <FieldLabel\n Label={field?.admin?.components?.Description}\n as=\"span\"\n label={label}\n required={required}\n unstyled\n {...(labelProps || {})}\n />\n </h3>\n {fieldHasErrors && fieldErrorCount > 0 && (\n <ErrorPill count={fieldErrorCount} i18n={i18n} withMessage />\n )}\n </div>\n {rows.length > 0 && (\n <ul className={`${baseClass}__header-actions`}>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(true)}\n type=\"button\"\n >\n {t('fields:collapseAll')}\n </button>\n </li>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(false)}\n type=\"button\"\n >\n {t('fields:showAll')}\n </button>\n </li>\n </ul>\n )}\n </div>\n <FieldDescription\n Description={field?.admin?.components?.Description}\n description={description}\n {...(descriptionProps || {})}\n />\n </header>\n <NullifyLocaleField fieldValue={value} localized={localized} path={path} />\n {(rows.length > 0 || (!valid && (showRequired || showMinRows))) && (\n <DraggableSortable\n className={`${baseClass}__rows`}\n ids={rows.map((row) => row.id)}\n onDragEnd={({ moveFromIndex, moveToIndex }) => moveRow(moveFromIndex, moveToIndex)}\n >\n {rows.map((row, i) => {\n const { blockType } = row\n const blockToRender = blocks.find((block) => block.slug === blockType)\n\n if (blockToRender) {\n const rowErrorCount = errorPaths.filter((errorPath) =>\n errorPath.startsWith(`${path}.${i}`),\n ).length\n return (\n <DraggableSortableItem disabled={disabled || !isSortable} id={row.id} key={row.id}>\n {(draggableSortableItemProps) => (\n <BlockRow\n {...draggableSortableItemProps}\n addRow={addRow}\n block={blockToRender}\n blocks={blocks}\n duplicateRow={duplicateRow}\n errorCount={rowErrorCount}\n forceRender={forceRender}\n hasMaxRows={hasMaxRows}\n indexPath={indexPath}\n isSortable={isSortable}\n labels={labels}\n moveRow={moveRow}\n path={path}\n permissions={permissions}\n readOnly={disabled}\n removeRow={removeRow}\n row={row}\n rowCount={rows.length}\n rowIndex={i}\n schemaPath={schemaPath}\n setCollapse={setCollapse}\n />\n )}\n </DraggableSortableItem>\n )\n }\n\n return null\n })}\n {!editingDefaultLocale && (\n <React.Fragment>\n {showMinRows && (\n <Banner type=\"error\">\n {t('validation:requiresAtLeast', {\n count: minRows,\n label:\n getTranslation(minRows > 1 ? labels.plural : labels.singular, i18n) ||\n t(minRows > 1 ? 'general:row' : 'general:rows'),\n })}\n </Banner>\n )}\n {showRequired && (\n <Banner>\n {t('validation:fieldHasNo', { label: getTranslation(labels.plural, i18n) })}\n </Banner>\n )}\n </React.Fragment>\n )}\n </DraggableSortable>\n )}\n {!disabled && !hasMaxRows && (\n <Fragment>\n <DrawerToggler className={`${baseClass}__drawer-toggler`} slug={drawerSlug}>\n <Button\n buttonStyle=\"icon-label\"\n el=\"span\"\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n >\n {t('fields:addLabel', { label: getTranslation(labels.singular, i18n) })}\n </Button>\n </DrawerToggler>\n <BlocksDrawer\n addRow={addRow}\n addRowIndex={rows?.length || 0}\n blocks={blocks}\n drawerSlug={drawerSlug}\n labels={labels}\n />\n </Fragment>\n )}\n </div>\n )\n}\n\nexport const BlocksField = withCondition(BlocksFieldComponent)\n"],"names":["getTranslation","React","Fragment","useCallback","Banner","Button","DraggableSortableItem","DraggableSortable","DrawerToggler","useDrawerSlug","ErrorPill","useFieldProps","useForm","useFormSubmitted","extractRowsAndCollapsedIDs","toggleAllRows","NullifyLocaleField","useField","withCondition","useConfig","useDocumentInfo","useLocale","useTranslation","scrollToID","FieldDescription","FieldError","FieldLabel","fieldBaseClass","BlockRow","BlocksDrawer","baseClass","BlocksFieldComponent","props","i18n","t","descriptionProps","errorProps","field","name","_path","pathFromProps","admin","className","description","isSortable","readOnly","readOnlyFromAdmin","blocks","label","labels","labelsFromProps","localized","maxRows","minRows","minRowsProp","required","forceRender","labelProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","indexPath","readOnlyFromContext","setDocFieldPreferences","addFieldRow","dispatchFields","setModified","code","locale","config","localization","drawerSlug","submitted","plural","singular","editingDefaultLocale","fallback","defaultLocale","memoizedValidate","value","options","path","pathFromContext","errorPaths","formInitializing","formProcessing","permissions","rows","schemaPath","showError","valid","hasRows","disabled","addRow","rowIndex","blockType","data","setTimeout","duplicateRow","type","removeRow","moveRow","moveFromIndex","moveToIndex","toggleCollapseAll","collapsed","collapsedIDs","updatedRows","setCollapse","rowID","hasMaxRows","length","fieldErrorCount","fieldHasErrors","showMinRows","showRequired","div","filter","Boolean","join","id","replace","CustomError","components","Error","header","h3","Label","Description","as","unstyled","count","withMessage","ul","li","button","onClick","fieldValue","ids","map","row","onDragEnd","i","blockToRender","find","block","slug","rowErrorCount","errorPath","startsWith","draggableSortableItemProps","errorCount","rowCount","buttonStyle","el","icon","iconPosition","iconStyle","addRowIndex","BlocksField"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,SAASC,QAAQ,EAAEC,WAAW,QAAQ,QAAO;AAEpD,SAASC,MAAM,QAAQ,iCAAgC;AACvD,SAASC,MAAM,QAAQ,iCAAgC;AACvD,SAASC,qBAAqB,QAAQ,kEAAiE;AACvG,SAASC,iBAAiB,QAAQ,4CAA2C;AAC7E,SAASC,aAAa,QAAQ,iCAAgC;AAC9D,SAAS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ACJ;wBACCgE,QAAQA;wBACRiE,aAAavE,MAAMwB,UAAU;wBAC7BhE,QAAQA;wBACRwB,YAAYA;wBACZtB,QAAQA;;;;;;AAMpB;AAEA,OAAO,MAAM8G,cAAc7I,cAAca,sBAAqB"}
@@ -17,7 +17,7 @@ const prismToMonacoLanguageMap = {
17
17
  };
18
18
  const baseClass = 'code-field';
19
19
  const CodeFieldComponent = (props)=>{
20
- const { descriptionProps, errorProps, field, field: { name, _path: pathFromProps, admin: { className, description, editorOptions = {}, language = 'javascript', readOnly: readOnlyFromAdmin, style, width }, label, required }, labelProps, readOnly: readOnlyFromTopLevelProps, validate } = props;
20
+ const { descriptionProps, errorProps, field, field: { name, _path: pathFromProps, admin: { className, description, editorOptions = {}, language = 'javascript', readOnly: readOnlyFromAdmin, style, width } = {}, label, required }, labelProps, readOnly: readOnlyFromTopLevelProps, validate } = props;
21
21
  const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin;
22
22
  const memoizedValidate = useCallback((value, options)=>{
23
23
  if (typeof validate === 'function') {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/Code/index.tsx"],"sourcesContent":["'use client'\nimport type { CodeFieldProps } from 'payload'\n\nimport React, { useCallback } from 'react'\n\nimport { CodeEditor } from '../../elements/CodeEditor/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { RenderComponent } from '../../providers/Config/RenderComponent.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { FieldError } from '../FieldError/index.js'\nimport { FieldLabel } from '../FieldLabel/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst prismToMonacoLanguageMap = {\n js: 'javascript',\n ts: 'typescript',\n}\n\nconst baseClass = 'code-field'\n\nconst CodeFieldComponent: React.FC<CodeFieldProps> = (props) => {\n const {\n descriptionProps,\n errorProps,\n field,\n field: {\n name,\n _path: pathFromProps,\n admin: {\n className,\n description,\n editorOptions = {},\n language = 'javascript',\n readOnly: readOnlyFromAdmin,\n style,\n width,\n },\n label,\n required,\n },\n labelProps,\n readOnly: readOnlyFromTopLevelProps,\n\n validate,\n } = props\n\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const memoizedValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function') {\n return validate(value, { ...options, required })\n }\n },\n [validate, required],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const { formInitializing, formProcessing, path, setValue, showError, value } = useField({\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n showError && 'error',\n disabled && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n Label={field?.admin?.components?.Label}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <FieldError\n CustomError={field?.admin?.components?.Error}\n path={path}\n {...(errorProps || {})}\n />\n <RenderComponent mappedComponent={field?.admin?.components?.beforeInput} />\n <CodeEditor\n defaultLanguage={prismToMonacoLanguageMap[language] || language}\n onChange={disabled ? () => null : (val) => setValue(val)}\n options={editorOptions}\n readOnly={disabled}\n value={(value as string) || ''}\n />\n <RenderComponent mappedComponent={field?.admin?.components?.afterInput} />\n </div>\n <FieldDescription\n Description={field?.admin?.components?.Description}\n description={description}\n {...(descriptionProps || {})}\n />\n </div>\n )\n}\n\nexport const CodeField = withCondition(CodeFieldComponent)\n"],"names":["React","useCallback","CodeEditor","useFieldProps","useField","withCondition","RenderComponent","FieldDescription","FieldError","FieldLabel","fieldBaseClass","prismToMonacoLanguageMap","js","ts","baseClass","CodeFieldComponent","props","descriptionProps","errorProps","field","name","_path","pathFromProps","admin","className","description","editorOptions","language","readOnly","readOnlyFromAdmin","style","width","label","required","labelProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","memoizedValidate","value","options","path","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","setValue","showError","disabled","div","filter","Boolean","join","Label","components","CustomError","Error","mappedComponent","beforeInput","defaultLanguage","onChange","val","afterInput","Description","CodeField"],"mappings":"AAAA;;AAGA,OAAOA,SAASC,WAAW,QAAQ,QAAO;AAE1C,SAASC,UAAU,QAAQ,qCAAoC;AAC/D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,eAAe,QAAQ,4CAA2C;AAC3E,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,cAAc,QAAQ,qBAAoB;AACnD,OAAO,eAAc;AAErB,MAAMC,2BAA2B;IAC/BC,IAAI;IACJC,IAAI;AACN;AAEA,MAAMC,YAAY;AAElB,MAAMC,qBAA+C,CAACC;IACpD,MAAM,EACJC,gBAAgB,EAChBC,UAAU,EACVC,KAAK,EACLA,OAAO,EACLC,IAAI,EACJC,OAAOC,aAAa,EACpBC,OAAO,EACLC,SAAS,EACTC,WAAW,EACXC,gBAAgB,CAAC,CAAC,EAClBC,WAAW,YAAY,EACvBC,UAAUC,iBAAiB,EAC3BC,KAAK,EACLC,KAAK,EACN,EACDC,KAAK,EACLC,QAAQ,EACT,EACDC,UAAU,EACVN,UAAUO,yBAAyB,EAEnCC,QAAQ,EACT,GAAGpB;IAEJ,MAAMqB,oBAAoBF,6BAA6BN;IAEvD,MAAMS,mBAAmBrC,YACvB,CAACsC,OAAOC;QACN,IAAI,OAAOJ,aAAa,YAAY;YAClC,OAAOA,SAASG,OAAO;gBAAE,GAAGC,OAAO;gBAAEP;YAAS;QAChD;IACF,GACA;QAACG;QAAU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":["../../../src/fields/Code/index.tsx"],"sourcesContent":["'use client'\nimport type { CodeFieldProps } from 'payload'\n\nimport React, { useCallback } from 'react'\n\nimport { CodeEditor } from '../../elements/CodeEditor/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { RenderComponent } from '../../providers/Config/RenderComponent.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { FieldError } from '../FieldError/index.js'\nimport { FieldLabel } from '../FieldLabel/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst prismToMonacoLanguageMap = {\n js: 'javascript',\n ts: 'typescript',\n}\n\nconst baseClass = 'code-field'\n\nconst CodeFieldComponent: React.FC<CodeFieldProps> = (props) => {\n const {\n descriptionProps,\n errorProps,\n field,\n field: {\n name,\n _path: pathFromProps,\n admin: {\n className,\n description,\n editorOptions = {},\n language = 'javascript',\n readOnly: readOnlyFromAdmin,\n style,\n width,\n } = {},\n label,\n required,\n },\n labelProps,\n readOnly: readOnlyFromTopLevelProps,\n\n validate,\n } = props\n\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const memoizedValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function') {\n return validate(value, { ...options, required })\n }\n },\n [validate, required],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const { formInitializing, formProcessing, path, setValue, showError, value } = useField({\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n showError && 'error',\n disabled && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n Label={field?.admin?.components?.Label}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <FieldError\n CustomError={field?.admin?.components?.Error}\n path={path}\n {...(errorProps || {})}\n />\n <RenderComponent mappedComponent={field?.admin?.components?.beforeInput} />\n <CodeEditor\n defaultLanguage={prismToMonacoLanguageMap[language] || language}\n onChange={disabled ? () => null : (val) => setValue(val)}\n options={editorOptions}\n readOnly={disabled}\n value={(value as string) || ''}\n />\n <RenderComponent mappedComponent={field?.admin?.components?.afterInput} />\n </div>\n <FieldDescription\n Description={field?.admin?.components?.Description}\n description={description}\n {...(descriptionProps || {})}\n />\n </div>\n )\n}\n\nexport const CodeField = withCondition(CodeFieldComponent)\n"],"names":["React","useCallback","CodeEditor","useFieldProps","useField","withCondition","RenderComponent","FieldDescription","FieldError","FieldLabel","fieldBaseClass","prismToMonacoLanguageMap","js","ts","baseClass","CodeFieldComponent","props","descriptionProps","errorProps","field","name","_path","pathFromProps","admin","className","description","editorOptions","language","readOnly","readOnlyFromAdmin","style","width","label","required","labelProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","memoizedValidate","value","options","path","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","setValue","showError","disabled","div","filter","Boolean","join","Label","components","CustomError","Error","mappedComponent","beforeInput","defaultLanguage","onChange","val","afterInput","Description","CodeField"],"mappings":"AAAA;;AAGA,OAAOA,SAASC,WAAW,QAAQ,QAAO;AAE1C,SAASC,UAAU,QAAQ,qCAAoC;AAC/D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,eAAe,QAAQ,4CAA2C;AAC3E,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,cAAc,QAAQ,qBAAoB;AACnD,OAAO,eAAc;AAErB,MAAMC,2BAA2B;IAC/BC,IAAI;IACJC,IAAI;AACN;AAEA,MAAMC,YAA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wBACC+C,aAAapC,OAAOI,OAAO+B,YAAYE;wBACvCf,MAAMA;wBACL,GAAIvB,cAAc,CAAC,CAAC;;kCAEvB,KAACZ;wBAAgBmD,iBAAiBtC,OAAOI,OAAO+B,YAAYI;;kCAC5D,KAACxD;wBACCyD,iBAAiBhD,wBAAwB,CAACgB,SAAS,IAAIA;wBACvDiC,UAAUZ,WAAW,IAAM,OAAO,CAACa,MAAQf,SAASe;wBACpDrB,SAASd;wBACTE,UAAUoB;wBACVT,OAAO,AAACA,SAAoB;;kCAE9B,KAACjC;wBAAgBmD,iBAAiBtC,OAAOI,OAAO+B,YAAYQ;;;;0BAE9D,KAACvD;gBACCwD,aAAa5C,OAAOI,OAAO+B,YAAYS;gBACvCtC,aAAaA;gBACZ,GAAIR,oBAAoB,CAAC,CAAC;;;;AAInC;AAEA,OAAO,MAAM+C,YAAY3D,cAAcU,oBAAmB"}
@@ -17,7 +17,7 @@ const baseClass = 'collapsible-field';
17
17
  import { useFormInitializing, useFormProcessing } from '../../forms/Form/context.js';
18
18
  import { FieldDescription } from '../FieldDescription/index.js';
19
19
  const CollapsibleFieldComponent = (props)=>{
20
- const { descriptionProps, field, field: { _path: pathFromProps, admin: { className, description, initCollapsed = false, readOnly: readOnlyFromAdmin }, fields, label }, readOnly: readOnlyFromTopLevelProps } = props;
20
+ const { descriptionProps, field, field: { _path: pathFromProps, admin: { className, description, initCollapsed = false, readOnly: readOnlyFromAdmin } = {}, fields, label }, readOnly: readOnlyFromTopLevelProps } = props;
21
21
  const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin;
22
22
  const { indexPath, path: pathFromContext, readOnly: readOnlyFromContext, schemaPath, siblingPermissions } = useFieldProps();
23
23
  const formInitializing = useFormInitializing();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/Collapsible/index.tsx"],"sourcesContent":["'use client'\nimport type { CollapsibleFieldProps, DocumentPreferences } from 'payload'\n\nimport React, { Fragment, useCallback, useEffect, useState } from 'react'\n\nimport { Collapsible as CollapsibleElement } from '../../elements/Collapsible/index.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { RenderFields } from '../../forms/RenderFields/index.js'\nimport { RowLabel } from '../../forms/RowLabel/index.js'\nimport { WatchChildErrors } from '../../forms/WatchChildErrors/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst baseClass = 'collapsible-field'\n\nimport { useFormInitializing, useFormProcessing } from '../../forms/Form/context.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\n\nconst CollapsibleFieldComponent: React.FC<CollapsibleFieldProps> = (props) => {\n const {\n descriptionProps,\n field,\n field: {\n _path: pathFromProps,\n admin: { className, description, initCollapsed = false, readOnly: readOnlyFromAdmin },\n fields,\n label,\n },\n readOnly: readOnlyFromTopLevelProps,\n } = props\n\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const {\n indexPath,\n path: pathFromContext,\n readOnly: readOnlyFromContext,\n schemaPath,\n siblingPermissions,\n } = useFieldProps()\n\n const formInitializing = useFormInitializing()\n const formProcessing = useFormProcessing()\n\n const path = pathFromContext ?? pathFromProps\n\n const { i18n } = useTranslation()\n const { getPreference, setPreference } = usePreferences()\n const { preferencesKey } = useDocumentInfo()\n const [collapsedOnMount, setCollapsedOnMount] = useState<boolean>()\n const fieldPreferencesKey = `collapsible-${indexPath.replace(/\\./g, '__')}`\n const [errorCount, setErrorCount] = useState(0)\n const fieldHasErrors = errorCount > 0\n\n const onToggle = useCallback(\n async (newCollapsedState: boolean): Promise<void> => {\n const existingPreferences: DocumentPreferences = await getPreference(preferencesKey)\n\n if (preferencesKey) {\n void setPreference(preferencesKey, {\n ...existingPreferences,\n ...(path\n ? {\n fields: {\n ...(existingPreferences?.fields || {}),\n [path]: {\n ...existingPreferences?.fields?.[path],\n collapsed: newCollapsedState,\n },\n },\n }\n : {\n fields: {\n ...(existingPreferences?.fields || {}),\n [fieldPreferencesKey]: {\n ...existingPreferences?.fields?.[fieldPreferencesKey],\n collapsed: newCollapsedState,\n },\n },\n }),\n })\n }\n },\n [preferencesKey, fieldPreferencesKey, getPreference, setPreference, path],\n )\n\n useEffect(() => {\n const fetchInitialState = async () => {\n if (preferencesKey) {\n const preferences = await getPreference(preferencesKey)\n const specificPreference = path\n ? preferences?.fields?.[path]?.collapsed\n : preferences?.fields?.[fieldPreferencesKey]?.collapsed\n\n if (specificPreference !== undefined) {\n setCollapsedOnMount(Boolean(specificPreference))\n } else {\n setCollapsedOnMount(typeof initCollapsed === 'boolean' ? initCollapsed : false)\n }\n } else {\n setCollapsedOnMount(typeof initCollapsed === 'boolean' ? initCollapsed : false)\n }\n }\n\n void fetchInitialState()\n }, [getPreference, preferencesKey, fieldPreferencesKey, initCollapsed, path])\n\n if (typeof collapsedOnMount !== 'boolean') return null\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n return (\n <Fragment>\n <WatchChildErrors fields={fields} path={path} setErrorCount={setErrorCount} />\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n fieldHasErrors ? `${baseClass}--has-error` : `${baseClass}--has-no-error`,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${fieldPreferencesKey}${path ? `-${path.replace(/\\./g, '__')}` : ''}`}\n >\n <CollapsibleElement\n className={`${baseClass}__collapsible`}\n collapsibleStyle={fieldHasErrors ? 'error' : 'default'}\n header={\n <div className={`${baseClass}__row-label-wrap`}>\n <RowLabel\n RowLabel={\n field?.admin?.components && 'RowLabel' in field.admin.components\n ? field.admin.components.RowLabel\n : undefined\n }\n i18n={i18n}\n path={path}\n rowLabel={label}\n />\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n }\n initCollapsed={collapsedOnMount}\n onToggle={onToggle}\n >\n <RenderFields\n fields={fields}\n forceRender\n indexPath={indexPath}\n margins=\"small\"\n path={path}\n permissions={siblingPermissions}\n readOnly={disabled}\n schemaPath={schemaPath}\n />\n </CollapsibleElement>\n <FieldDescription\n Description={field?.admin?.components?.Description}\n description={description}\n {...(descriptionProps || {})}\n />\n </div>\n </Fragment>\n )\n}\n\nexport const CollapsibleField = withCondition(CollapsibleFieldComponent)\n"],"names":["React","Fragment","useCallback","useEffect","useState","Collapsible","CollapsibleElement","ErrorPill","useFieldProps","RenderFields","RowLabel","WatchChildErrors","withCondition","useDocumentInfo","usePreferences","useTranslation","fieldBaseClass","baseClass","useFormInitializing","useFormProcessing","FieldDescription","CollapsibleFieldComponent","props","descriptionProps","field","_path","pathFromProps","admin","className","description","initCollapsed","readOnly","readOnlyFromAdmin","fields","label","readOnlyFromTopLevelProps","readOnlyFromProps","indexPath","path","pathFromContext","readOnlyFromContext","schemaPath","siblingPermissions","formInitializing","formProcessing","i18n","getPreference","setPreference","preferencesKey","collapsedOnMount","setCollapsedOnMount","fieldPreferencesKey","replace","errorCount","setErrorCount","fieldHasErrors","onToggle","newCollapsedState","existingPreferences","collapsed","fetchInitialState","preferences","specificPreference","undefined","Boolean","disabled","div","filter","join","id","collapsibleStyle","header","components","rowLabel","count","withMessage","forceRender","margins","permissions","Description","CollapsibleField"],"mappings":"AAAA;;AAGA,OAAOA,SAASC,QAAQ,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAEzE,SAASC,eAAeC,kBAAkB,QAAQ,sCAAqC;AACvF,SAASC,SAAS,QAAQ,oCAAmC;AAC7D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,YAAY,QAAQ,oCAAmC;AAChE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,aAAa,QAAQ,qCAAoC;AAClE,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EkD,MAAM,CAACH,SACPI,IAAI,CAAC;gBACRC,IAAI,CAAC,MAAM,EAAElB,oBAAoB,EAAEb,OAAO,CAAC,CAAC,EAAEA,KAAKc,OAAO,CAAC,OAAO,MAAM,CAAC,GAAG,GAAG,CAAC;;kCAEhF,KAAC9C;wBACCsB,WAAW,CAAC,EAAEX,UAAU,aAAa,CAAC;wBACtCqD,kBAAkBf,iBAAiB,UAAU;wBAC7CgB,sBACE,MAACL;4BAAItC,WAAW,CAAC,EAAEX,UAAU,gBAAgB,CAAC;;8CAC5C,KAACP;oCACCA,UACEc,OAAOG,OAAO6C,cAAc,cAAchD,MAAMG,KAAK,CAAC6C,UAAU,GAC5DhD,MAAMG,KAAK,CAAC6C,UAAU,CAAC9D,QAAQ,GAC/BqD;oCAENlB,MAAMA;oCACNP,MAAMA;oCACNmC,UAAUvC;;gCAEXqB,gCAAkB,KAAChD;oCAAUmE,OAAOrB;oCAAYR,MAAMA;oCAAM8B,WAAW;;;;wBAG5E7C,eAAemB;wBACfO,UAAUA;kCAEV,cAAA,KAAC/C;4BACCwB,QAAQA;4BACR2C,WAAW;4BACXvC,WAAWA;4BACXwC,SAAQ;4BACRvC,MAAMA;4BACNwC,aAAapC;4BACbX,UAAUkC;4BACVxB,YAAYA;;;kCAGhB,KAACrB;wBACC2D,aAAavD,OAAOG,OAAO6C,YAAYO;wBACvClD,aAAaA;wBACZ,GAAIN,oBAAoB,CAAC,CAAC;;;;;;AAKrC;AAEA,OAAO,MAAMyD,mBAAmBpE,cAAcS,2BAA0B"}
1
+ {"version":3,"sources":["../../../src/fields/Collapsible/index.tsx"],"sourcesContent":["'use client'\nimport type { CollapsibleFieldProps, DocumentPreferences } from 'payload'\n\nimport React, { Fragment, useCallback, useEffect, useState } from 'react'\n\nimport { Collapsible as CollapsibleElement } from '../../elements/Collapsible/index.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { RenderFields } from '../../forms/RenderFields/index.js'\nimport { RowLabel } from '../../forms/RowLabel/index.js'\nimport { WatchChildErrors } from '../../forms/WatchChildErrors/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst baseClass = 'collapsible-field'\n\nimport { useFormInitializing, useFormProcessing } from '../../forms/Form/context.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\n\nconst CollapsibleFieldComponent: React.FC<CollapsibleFieldProps> = (props) => {\n const {\n descriptionProps,\n field,\n field: {\n _path: pathFromProps,\n admin: { className, description, initCollapsed = false, readOnly: readOnlyFromAdmin } = {},\n fields,\n label,\n },\n readOnly: readOnlyFromTopLevelProps,\n } = props\n\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const {\n indexPath,\n path: pathFromContext,\n readOnly: readOnlyFromContext,\n schemaPath,\n siblingPermissions,\n } = useFieldProps()\n\n const formInitializing = useFormInitializing()\n const formProcessing = useFormProcessing()\n\n const path = pathFromContext ?? pathFromProps\n\n const { i18n } = useTranslation()\n const { getPreference, setPreference } = usePreferences()\n const { preferencesKey } = useDocumentInfo()\n const [collapsedOnMount, setCollapsedOnMount] = useState<boolean>()\n const fieldPreferencesKey = `collapsible-${indexPath.replace(/\\./g, '__')}`\n const [errorCount, setErrorCount] = useState(0)\n const fieldHasErrors = errorCount > 0\n\n const onToggle = useCallback(\n async (newCollapsedState: boolean): Promise<void> => {\n const existingPreferences: DocumentPreferences = await getPreference(preferencesKey)\n\n if (preferencesKey) {\n void setPreference(preferencesKey, {\n ...existingPreferences,\n ...(path\n ? {\n fields: {\n ...(existingPreferences?.fields || {}),\n [path]: {\n ...existingPreferences?.fields?.[path],\n collapsed: newCollapsedState,\n },\n },\n }\n : {\n fields: {\n ...(existingPreferences?.fields || {}),\n [fieldPreferencesKey]: {\n ...existingPreferences?.fields?.[fieldPreferencesKey],\n collapsed: newCollapsedState,\n },\n },\n }),\n })\n }\n },\n [preferencesKey, fieldPreferencesKey, getPreference, setPreference, path],\n )\n\n useEffect(() => {\n const fetchInitialState = async () => {\n if (preferencesKey) {\n const preferences = await getPreference(preferencesKey)\n const specificPreference = path\n ? preferences?.fields?.[path]?.collapsed\n : preferences?.fields?.[fieldPreferencesKey]?.collapsed\n\n if (specificPreference !== undefined) {\n setCollapsedOnMount(Boolean(specificPreference))\n } else {\n setCollapsedOnMount(typeof initCollapsed === 'boolean' ? initCollapsed : false)\n }\n } else {\n setCollapsedOnMount(typeof initCollapsed === 'boolean' ? initCollapsed : false)\n }\n }\n\n void fetchInitialState()\n }, [getPreference, preferencesKey, fieldPreferencesKey, initCollapsed, path])\n\n if (typeof collapsedOnMount !== 'boolean') return null\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n return (\n <Fragment>\n <WatchChildErrors fields={fields} path={path} setErrorCount={setErrorCount} />\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n fieldHasErrors ? `${baseClass}--has-error` : `${baseClass}--has-no-error`,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${fieldPreferencesKey}${path ? `-${path.replace(/\\./g, '__')}` : ''}`}\n >\n <CollapsibleElement\n className={`${baseClass}__collapsible`}\n collapsibleStyle={fieldHasErrors ? 'error' : 'default'}\n header={\n <div className={`${baseClass}__row-label-wrap`}>\n <RowLabel\n RowLabel={\n field?.admin?.components && 'RowLabel' in field.admin.components\n ? field.admin.components.RowLabel\n : undefined\n }\n i18n={i18n}\n path={path}\n rowLabel={label}\n />\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n }\n initCollapsed={collapsedOnMount}\n onToggle={onToggle}\n >\n <RenderFields\n fields={fields}\n forceRender\n indexPath={indexPath}\n margins=\"small\"\n path={path}\n permissions={siblingPermissions}\n readOnly={disabled}\n schemaPath={schemaPath}\n />\n </CollapsibleElement>\n <FieldDescription\n Description={field?.admin?.components?.Description}\n description={description}\n {...(descriptionProps || {})}\n />\n </div>\n </Fragment>\n )\n}\n\nexport const CollapsibleField = withCondition(CollapsibleFieldComponent)\n"],"names":["React","Fragment","useCallback","useEffect","useState","Collapsible","CollapsibleElement","ErrorPill","useFieldProps","RenderFields","RowLabel","WatchChildErrors","withCondition","useDocumentInfo","usePreferences","useTranslation","fieldBaseClass","baseClass","useFormInitializing","useFormProcessing","FieldDescription","CollapsibleFieldComponent","props","descriptionProps","field","_path","pathFromProps","admin","className","description","initCollapsed","readOnly","readOnlyFromAdmin","fields","label","readOnlyFromTopLevelProps","readOnlyFromProps","indexPath","path","pathFromContext","readOnlyFromContext","schemaPath","siblingPermissions","formInitializing","formProcessing","i18n","getPreference","setPreference","preferencesKey","collapsedOnMount","setCollapsedOnMount","fieldPreferencesKey","replace","errorCount","setErrorCount","fieldHasErrors","onToggle","newCollapsedState","existingPreferences","collapsed","fetchInitialState","preferences","specificPreference","undefined","Boolean","disabled","div","filter","join","id","collapsibleStyle","header","components","rowLabel","count","withMessage","forceRender","margins","permissions","Description","CollapsibleField"],"mappings":"AAAA;;AAGA,OAAOA,SAASC,QAAQ,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAEzE,SAASC,eAAeC,kBAAkB,QAAQ,sCAAqC;AACvF,SAASC,SAAS,QAAQ,oCAAmC;AAC7D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,YAAY,QAAQ,oCAAmC;AAChE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,qBAAoB;AACnD,OA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AO,CAAC,OAAO,MAAM,CAAC,GAAG,GAAG,CAAC;;kCAEhF,KAAC9C;wBACCsB,WAAW,CAAC,EAAEX,UAAU,aAAa,CAAC;wBACtCqD,kBAAkBf,iBAAiB,UAAU;wBAC7CgB,sBACE,MAACL;4BAAItC,WAAW,CAAC,EAAEX,UAAU,gBAAgB,CAAC;;8CAC5C,KAACP;oCACCA,UACEc,OAAOG,OAAO6C,cAAc,cAAchD,MAAMG,KAAK,CAAC6C,UAAU,GAC5DhD,MAAMG,KAAK,CAAC6C,UAAU,CAAC9D,QAAQ,GAC/BqD;oCAENlB,MAAMA;oCACNP,MAAMA;oCACNmC,UAAUvC;;gCAEXqB,gCAAkB,KAAChD;oCAAUmE,OAAOrB;oCAAYR,MAAMA;oCAAM8B,WAAW;;;;wBAG5E7C,eAAemB;wBACfO,UAAUA;kCAEV,cAAA,KAAC/C;4BACCwB,QAAQA;4BACR2C,WAAW;4BACXvC,WAAWA;4BACXwC,SAAQ;4BACRvC,MAAMA;4BACNwC,aAAapC;4BACbX,UAAUkC;4BACVxB,YAAYA;;;kCAGhB,KAACrB;wBACC2D,aAAavD,OAAOG,OAAO6C,YAAYO;wBACvClD,aAAaA;wBACZ,GAAIN,oBAAoB,CAAC,CAAC;;;;;;AAKrC;AAEA,OAAO,MAAMyD,mBAAmBpE,cAAcS,2BAA0B"}
@@ -15,7 +15,7 @@ import { RenderComponent } from '../../providers/Config/RenderComponent.js';
15
15
  import { FieldDescription } from '../FieldDescription/index.js';
16
16
  import { FieldError } from '../FieldError/index.js';
17
17
  const DateTimeFieldComponent = (props)=>{
18
- const { descriptionProps, errorProps, field, field: { name, _path: pathFromProps, admin: { className, date: datePickerProps, description, placeholder, readOnly: readOnlyFromAdmin, style, width }, label, required }, labelProps, readOnly: readOnlyFromTopLevelProps, validate } = props;
18
+ const { descriptionProps, errorProps, field, field: { name, _path: pathFromProps, admin: { className, date: datePickerProps, description, placeholder, readOnly: readOnlyFromAdmin, style, width } = {}, label, required }, labelProps, readOnly: readOnlyFromTopLevelProps, validate } = props;
19
19
  const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin;
20
20
  const { i18n } = useTranslation();
21
21
  const memoizedValidate = useCallback((value, options)=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/DateTime/index.tsx"],"sourcesContent":["'use client'\nimport type { DateFieldProps, DateFieldValidation } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useCallback } from 'react'\n\nimport { DatePickerField } from '../../elements/DatePicker/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { FieldLabel } from '../FieldLabel/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst baseClass = 'date-time-field'\n\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { RenderComponent } from '../../providers/Config/RenderComponent.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { FieldError } from '../FieldError/index.js'\n\nconst DateTimeFieldComponent: React.FC<DateFieldProps> = (props) => {\n const {\n descriptionProps,\n errorProps,\n field,\n field: {\n name,\n _path: pathFromProps,\n admin: {\n className,\n date: datePickerProps,\n description,\n placeholder,\n readOnly: readOnlyFromAdmin,\n style,\n width,\n },\n label,\n required,\n },\n labelProps,\n readOnly: readOnlyFromTopLevelProps,\n validate,\n } = props\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const { i18n } = useTranslation()\n\n const memoizedValidate: DateFieldValidation = useCallback(\n (value, options) => {\n if (typeof validate === 'function') {\n return validate(value, { ...options, required })\n }\n },\n [validate, required],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const { formInitializing, formProcessing, path, setValue, showError, value } = useField<Date>({\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n showError && `${baseClass}--has-error`,\n disabled && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n Label={field?.admin?.components?.Label}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${fieldBaseClass}__wrap`} id={`field-${path.replace(/\\./g, '__')}`}>\n <FieldError\n CustomError={field?.admin?.components?.Error}\n path={path}\n {...(errorProps || {})}\n />\n <RenderComponent mappedComponent={field?.admin?.components?.beforeInput} />\n <DatePickerField\n {...datePickerProps}\n onChange={(incomingDate) => {\n if (!disabled) setValue(incomingDate?.toISOString() || null)\n }}\n placeholder={getTranslation(placeholder, i18n)}\n readOnly={disabled}\n value={value}\n />\n <RenderComponent mappedComponent={field?.admin?.components?.afterInput} />\n </div>\n <FieldDescription\n Description={field?.admin?.components?.Description}\n description={description}\n {...(descriptionProps || {})}\n />\n </div>\n )\n}\n\nexport const DateTimeField = withCondition(DateTimeFieldComponent)\n"],"names":["getTranslation","React","useCallback","DatePickerField","useField","useTranslation","FieldLabel","fieldBaseClass","baseClass","useFieldProps","withCondition","RenderComponent","FieldDescription","FieldError","DateTimeFieldComponent","props","descriptionProps","errorProps","field","name","_path","pathFromProps","admin","className","date","datePickerProps","description","placeholder","readOnly","readOnlyFromAdmin","style","width","label","required","labelProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","i18n","memoizedValidate","value","options","path","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","setValue","showError","disabled","div","filter","Boolean","join","Label","components","id","replace","CustomError","Error","mappedComponent","beforeInput","onChange","incomingDate","toISOString","afterInput","Description","DateTimeField"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAE1C,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,S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YACAe;YACAyB,aAAa,CAAC,EAAExC,UAAU,WAAW,CAAC;YACtCyC,YAAY;SACb,CACEE,MAAM,CAACC,SACPC,IAAI,CAAC;QACRvB,OAAO;YACL,GAAGA,KAAK;YACRC;QACF;;0BAEA,KAACzB;gBACCgD,OAAOpC,OAAOI,OAAOiC,YAAYD;gBACjCtB,OAAOA;gBACPC,UAAUA;gBACT,GAAIC,cAAc,CAAC,CAAC;;0BAEvB,MAACgB;gBAAI3B,WAAW,CAAC,EAAEhB,eAAe,MAAM,CAAC;gBAAEiD,IAAI,CAAC,MAAM,EAAEd,KAAKe,OAAO,CAAC,OAAO,MAAM,CAAC;;kCACjF,KAAC5C;wBACC6C,aAAaxC,OAAOI,OAAOiC,YAAYI;wBACvCjB,MAAMA;wBACL,GAAIzB,cAAc,CAAC,CAAC;;kCAEvB,KAACN;wBAAgBiD,iBAAiB1C,OAAOI,OAAOiC,YAAYM;;kCAC5D,KAAC1D;wBACE,GAAGsB,eAAe;wBACnBqC,UAAU,CAACC;4BACT,IAAI,CAACd,UAAUF,SAASgB,cAAcC,iBAAiB;wBACzD;wBACArC,aAAa3B,eAAe2B,aAAaW;wBACzCV,UAAUqB;wBACVT,OAAOA;;kCAET,KAAC7B;wBAAgBiD,iBAAiB1C,OAAOI,OAAOiC,YAAYU;;;;0BAE9D,KAACrD;gBACCsD,aAAahD,OAAOI,OAAOiC,YAAYW;gBACvCxC,aAAaA;gBACZ,GAAIV,oBAAoB,CAAC,CAAC;;;;AAInC;AAEA,OAAO,MAAMmD,gBAAgBzD,cAAcI,wBAAuB"}
1
+ {"version":3,"sources":["../../../src/fields/DateTime/index.tsx"],"sourcesContent":["'use client'\nimport type { DateFieldProps, DateFieldValidation } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useCallback } from 'react'\n\nimport { DatePickerField } from '../../elements/DatePicker/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { FieldLabel } from '../FieldLabel/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst baseClass = 'date-time-field'\n\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { RenderComponent } from '../../providers/Config/RenderComponent.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { FieldError } from '../FieldError/index.js'\n\nconst DateTimeFieldComponent: React.FC<DateFieldProps> = (props) => {\n const {\n descriptionProps,\n errorProps,\n field,\n field: {\n name,\n _path: pathFromProps,\n admin: {\n className,\n date: datePickerProps,\n description,\n placeholder,\n readOnly: readOnlyFromAdmin,\n style,\n width,\n } = {},\n label,\n required,\n },\n labelProps,\n readOnly: readOnlyFromTopLevelProps,\n validate,\n } = props\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const { i18n } = useTranslation()\n\n const memoizedValidate: DateFieldValidation = useCallback(\n (value, options) => {\n if (typeof validate === 'function') {\n return validate(value, { ...options, required })\n }\n },\n [validate, required],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const { formInitializing, formProcessing, path, setValue, showError, value } = useField<Date>({\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n showError && `${baseClass}--has-error`,\n disabled && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n Label={field?.admin?.components?.Label}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${fieldBaseClass}__wrap`} id={`field-${path.replace(/\\./g, '__')}`}>\n <FieldError\n CustomError={field?.admin?.components?.Error}\n path={path}\n {...(errorProps || {})}\n />\n <RenderComponent mappedComponent={field?.admin?.components?.beforeInput} />\n <DatePickerField\n {...datePickerProps}\n onChange={(incomingDate) => {\n if (!disabled) setValue(incomingDate?.toISOString() || null)\n }}\n placeholder={getTranslation(placeholder, i18n)}\n readOnly={disabled}\n value={value}\n />\n <RenderComponent mappedComponent={field?.admin?.components?.afterInput} />\n </div>\n <FieldDescription\n Description={field?.admin?.components?.Description}\n description={description}\n {...(descriptionProps || {})}\n />\n </div>\n )\n}\n\nexport const DateTimeField = withCondition(DateTimeFieldComponent)\n"],"names":["getTranslation","React","useCallback","DatePickerField","useField","useTranslation","FieldLabel","fieldBaseClass","baseClass","useFieldProps","withCondition","RenderComponent","FieldDescription","FieldError","DateTimeFieldComponent","props","descriptionProps","errorProps","field","name","_path","pathFromProps","admin","className","date","datePickerProps","description","placeholder","readOnly","readOnlyFromAdmin","style","width","label","required","labelProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","i18n","memoizedValidate","value","options","path","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","setValue","showError","disabled","div","filter","Boolean","join","Label","components","id","replace","CustomError","Error","mappedComponent","beforeInput","onChange","incomingDate","toISOString","afterInput","Description","DateTimeField"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAE1C,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,cAAc,QAAQ,qBAAoB;AACnD,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,eAAe,QAAQ,4CAA2C;AAC3E,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,UAAU,QAAQ,yBAAwB;AAEnD,MAAMC,yBAAmD,CAACC;IACxD,MAAM,EACJC,gBAAgB,EAChBC,UAAU,EACVC,KAAK,EACLA,OAAO,EACLC,IAAI,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MAAM,CAAC;;kCACjF,KAAC5C;wBACC6C,aAAaxC,OAAOI,OAAOiC,YAAYI;wBACvCjB,MAAMA;wBACL,GAAIzB,cAAc,CAAC,CAAC;;kCAEvB,KAACN;wBAAgBiD,iBAAiB1C,OAAOI,OAAOiC,YAAYM;;kCAC5D,KAAC1D;wBACE,GAAGsB,eAAe;wBACnBqC,UAAU,CAACC;4BACT,IAAI,CAACd,UAAUF,SAASgB,cAAcC,iBAAiB;wBACzD;wBACArC,aAAa3B,eAAe2B,aAAaW;wBACzCV,UAAUqB;wBACVT,OAAOA;;kCAET,KAAC7B;wBAAgBiD,iBAAiB1C,OAAOI,OAAOiC,YAAYU;;;;0BAE9D,KAACrD;gBACCsD,aAAahD,OAAOI,OAAOiC,YAAYW;gBACvCxC,aAAaA;gBACZ,GAAIV,oBAAoB,CAAC,CAAC;;;;AAInC;AAEA,OAAO,MAAMmD,gBAAgBzD,cAAcI,wBAAuB"}
@@ -19,7 +19,7 @@ import './index.scss';
19
19
  import { GroupProvider, useGroup } from './provider.js';
20
20
  const baseClass = 'group-field';
21
21
  export const GroupFieldComponent = (props)=>{
22
- const { descriptionProps, field, field: { admin: { className, description, hideGutter, readOnly: readOnlyFromAdmin, style, width }, fields, label }, readOnly: readOnlyFromTopLevelProps } = props;
22
+ const { descriptionProps, field, field: { admin: { className, description, hideGutter, readOnly: readOnlyFromAdmin, style, width } = {}, fields, label }, readOnly: readOnlyFromTopLevelProps } = props;
23
23
  const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin;
24
24
  const { path, permissions, readOnly: readOnlyFromContext, schemaPath } = useFieldProps();
25
25
  const { i18n } = useTranslation();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/Group/index.tsx"],"sourcesContent":["'use client'\n\nimport type { GroupFieldProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React from 'react'\n\nimport { useCollapsible } from '../../elements/Collapsible/provider.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport {\n useFormInitializing,\n useFormProcessing,\n useFormSubmitted,\n} from '../../forms/Form/context.js'\nimport { RenderFields } from '../../forms/RenderFields/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { RenderComponent } from '../../providers/Config/RenderComponent.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { useRow } from '../Row/provider.js'\nimport { useTabs } from '../Tabs/provider.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\nimport { GroupProvider, useGroup } from './provider.js'\n\nconst baseClass = 'group-field'\n\nexport const GroupFieldComponent: React.FC<GroupFieldProps> = (props) => {\n const {\n descriptionProps,\n field,\n field: {\n admin: { className, description, hideGutter, readOnly: readOnlyFromAdmin, style, width },\n fields,\n label,\n },\n readOnly: readOnlyFromTopLevelProps,\n } = props\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const { path, permissions, readOnly: readOnlyFromContext, schemaPath } = useFieldProps()\n const { i18n } = useTranslation()\n const { isWithinCollapsible } = useCollapsible()\n const isWithinGroup = useGroup()\n const isWithinRow = useRow()\n const isWithinTab = useTabs()\n const { errorPaths } = useField({ path })\n const formInitializing = useFormInitializing()\n const formProcessing = useFormProcessing()\n const submitted = useFormSubmitted()\n const errorCount = errorPaths.length\n const fieldHasErrors = submitted && errorCount > 0\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const isTopLevel = !(isWithinCollapsible || isWithinGroup || isWithinRow)\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n isTopLevel && `${baseClass}--top-level`,\n isWithinCollapsible && `${baseClass}--within-collapsible`,\n isWithinGroup && `${baseClass}--within-group`,\n isWithinRow && `${baseClass}--within-row`,\n isWithinTab && `${baseClass}--within-tab`,\n !hideGutter && isWithinGroup && `${baseClass}--gutter`,\n fieldHasErrors && `${baseClass}--has-error`,\n className,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${path?.replace(/\\./g, '__')}`}\n style={{\n ...style,\n width,\n }}\n >\n <GroupProvider>\n <div className={`${baseClass}__wrap`}>\n <div className={`${baseClass}__header`}>\n {(field?.admin?.components?.Label ||\n field?.admin?.components?.Description ||\n label) && (\n <header>\n {field?.admin?.components?.Label !== undefined ? (\n <RenderComponent\n clientProps={{ label }}\n mappedComponent={field?.admin?.components?.Label}\n />\n ) : label ? (\n <h3 className={`${baseClass}__title`}>{getTranslation(label, i18n)}</h3>\n ) : null}\n <FieldDescription\n Description={field?.admin?.components?.Description}\n description={description}\n {...(descriptionProps || {})}\n />\n </header>\n )}\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n <RenderFields\n fields={fields}\n margins=\"small\"\n path={path}\n permissions={permissions?.fields}\n readOnly={disabled}\n schemaPath={schemaPath}\n />\n </div>\n </GroupProvider>\n </div>\n )\n}\n\nexport { GroupProvider, useGroup }\n\nexport const GroupField = withCondition(GroupFieldComponent)\n"],"names":["getTranslation","React","useCollapsible","ErrorPill","useFieldProps","useFormInitializing","useFormProcessing","useFormSubmitted","RenderFields","useField","withCondition","RenderComponent","useTranslation","FieldDescription","useRow","useTabs","fieldBaseClass","GroupProvider","useGroup","baseClass","GroupFieldComponent","props","descriptionProps","field","admin","className","description","hideGutter","readOnly","readOnlyFromAdmin","style","width","fields","label","readOnlyFromTopLevelProps","readOnlyFromProps","path","permissions","readOnlyFromContext","schemaPath","i18n","isWithinCollapsible","isWithinGroup","isWithinRow","isWithinTab","errorPaths","formInitializing","formProcessing","submitted","errorCount","length","fieldHasErrors","disabled","isTopLevel","div","filter","Boolean","join","id","replace","components","Label","Description","header","undefined","clientProps","mappedComponent","h3","count","withMessage","margins","GroupField"],"mappings":"AAAA;;AAIA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,WAAW,QAAO;AAEz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C3B;wCACCiD,aAAavC,OAAOC,OAAOoC,YAAYE;wCACvCpC,aAAaA;wCACZ,GAAIJ,oBAAoB,CAAC,CAAC;;;;4BAIhC6B,gCAAkB,KAAChD;gCAAUiE,OAAOnB;gCAAYT,MAAMA;gCAAM6B,WAAW;;;;kCAE1E,KAAC7D;wBACCwB,QAAQA;wBACRsC,SAAQ;wBACRlC,MAAMA;wBACNC,aAAaA,aAAaL;wBAC1BJ,UAAUwB;wBACVb,YAAYA;;;;;;AAMxB,EAAC;AAED,SAAStB,aAAa,EAAEC,QAAQ,GAAE;AAElC,OAAO,MAAMqD,aAAa7D,cAAcU,qBAAoB"}
1
+ {"version":3,"sources":["../../../src/fields/Group/index.tsx"],"sourcesContent":["'use client'\n\nimport type { GroupFieldProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React from 'react'\n\nimport { useCollapsible } from '../../elements/Collapsible/provider.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport {\n useFormInitializing,\n useFormProcessing,\n useFormSubmitted,\n} from '../../forms/Form/context.js'\nimport { RenderFields } from '../../forms/RenderFields/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { RenderComponent } from '../../providers/Config/RenderComponent.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { useRow } from '../Row/provider.js'\nimport { useTabs } from '../Tabs/provider.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\nimport { GroupProvider, useGroup } from './provider.js'\n\nconst baseClass = 'group-field'\n\nexport const GroupFieldComponent: React.FC<GroupFieldProps> = (props) => {\n const {\n descriptionProps,\n field,\n field: {\n admin: { className, description, hideGutter, readOnly: readOnlyFromAdmin, style, width } = {},\n fields,\n label,\n },\n readOnly: readOnlyFromTopLevelProps,\n } = props\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const { path, permissions, readOnly: readOnlyFromContext, schemaPath } = useFieldProps()\n const { i18n } = useTranslation()\n const { isWithinCollapsible } = useCollapsible()\n const isWithinGroup = useGroup()\n const isWithinRow = useRow()\n const isWithinTab = useTabs()\n const { errorPaths } = useField({ path })\n const formInitializing = useFormInitializing()\n const formProcessing = useFormProcessing()\n const submitted = useFormSubmitted()\n const errorCount = errorPaths.length\n const fieldHasErrors = submitted && errorCount > 0\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const isTopLevel = !(isWithinCollapsible || isWithinGroup || isWithinRow)\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n isTopLevel && `${baseClass}--top-level`,\n isWithinCollapsible && `${baseClass}--within-collapsible`,\n isWithinGroup && `${baseClass}--within-group`,\n isWithinRow && `${baseClass}--within-row`,\n isWithinTab && `${baseClass}--within-tab`,\n !hideGutter && isWithinGroup && `${baseClass}--gutter`,\n fieldHasErrors && `${baseClass}--has-error`,\n className,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${path?.replace(/\\./g, '__')}`}\n style={{\n ...style,\n width,\n }}\n >\n <GroupProvider>\n <div className={`${baseClass}__wrap`}>\n <div className={`${baseClass}__header`}>\n {(field?.admin?.components?.Label ||\n field?.admin?.components?.Description ||\n label) && (\n <header>\n {field?.admin?.components?.Label !== undefined ? (\n <RenderComponent\n clientProps={{ label }}\n mappedComponent={field?.admin?.components?.Label}\n />\n ) : label ? (\n <h3 className={`${baseClass}__title`}>{getTranslation(label, i18n)}</h3>\n ) : null}\n <FieldDescription\n Description={field?.admin?.components?.Description}\n description={description}\n {...(descriptionProps || {})}\n />\n </header>\n )}\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n <RenderFields\n fields={fields}\n margins=\"small\"\n path={path}\n permissions={permissions?.fields}\n readOnly={disabled}\n schemaPath={schemaPath}\n />\n </div>\n </GroupProvider>\n </div>\n )\n}\n\nexport { GroupProvider, useGroup }\n\nexport const GroupField = withCondition(GroupFieldComponent)\n"],"names":["getTranslation","React","useCollapsible","ErrorPill","useFieldProps","useFormInitializing","useFormProcessing","useFormSubmitted","RenderFields","useField","withCondition","RenderComponent","useTranslation","FieldDescription","useRow","useTabs","fieldBaseClass","GroupProvider","useGroup","baseClass","GroupFieldComponent","props","descriptionProps","field","admin","className","description","hideGutter","readOnly","readOnlyFromAdmin","style","width","fields","label","readOnlyFromTopLevelProps","readOnlyFromProps","path","permissions","readOnlyFromContext","schemaPath","i18n","isWithinCollapsible","isWithinGroup","isWithinRow","isWithinTab","errorPaths","formInitializing","formProcessing","submitted","errorCount","length","fieldHasErrors","disabled","isTopLevel","div","filter","Boolean","join","id","replace","components","Label","Description","header","undefined","clientProps","mappedComponent","h3","count","withMessage","margins","GroupField"],"mappings":"AAAA;;AAIA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,WAAW,QAAO;AAEzB,SAASC,cAAc,QAAQ,yCAAwC;AACvE,SAASC,SAAS,QAAQ,oCAAmC;AAC7D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SACEC,mBAAmB,EACnBC,iBAAiB,EACjBC,gBAAgB,QACX,8BAA6B;AACpC,SAASC,YAAY,QAAQ,oCAAmC;AAChE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,eAAe,QAAQ,4CAA2C;AAC3E,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,MAAM,QAAQ,qBAAoB;AAC3C,SAASC,OAAO,QAAQ,sBAAqB;AAC7C,SAASC,cAAc,QAAQ,qBAAoB;AACnD,OAAO,eAAc;AACrB,SAASC,aAAa,EAAEC,QAAQ,QAAQ,gBAAe;AAEvD,MAAMC,YAAY;AAElB,OAAO,MAAMC,sBAAiD,CAACC;IAC7D,MAAM,EACJC,gBAAgB,EAChBC,KAAK,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B,eAAO,MAAM,SAAS,0BAAoC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/JSON/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAA2C,MAAM,OAAO,CAAA;AAO/D,OAAO,cAAc,CAAA;AAsJrB,eAAO,MAAM,SAAS,0BAAoC,CAAA"}
@@ -13,7 +13,7 @@ import { RenderComponent } from '../../providers/Config/RenderComponent.js';
13
13
  import { FieldDescription } from '../FieldDescription/index.js';
14
14
  import { FieldError } from '../FieldError/index.js';
15
15
  const JSONFieldComponent = (props)=>{
16
- const { descriptionProps, errorProps, field, field: { name, _path: pathFromProps, admin: { className, description, editorOptions, readOnly: readOnlyFromAdmin, style, width }, jsonSchema, label, required }, labelProps, readOnly: readOnlyFromTopLevelProps, validate } = props;
16
+ const { descriptionProps, errorProps, field, field: { name, _path: pathFromProps, admin: { className, description, editorOptions, readOnly: readOnlyFromAdmin, style, width } = {}, jsonSchema, label, required }, labelProps, readOnly: readOnlyFromTopLevelProps, validate } = props;
17
17
  const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin;
18
18
  const [stringValue, setStringValue] = useState();
19
19
  const [jsonError, setJsonError] = useState();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/JSON/index.tsx"],"sourcesContent":["'use client'\nimport type { JSONFieldProps } from 'payload'\n\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport { CodeEditor } from '../../elements/CodeEditor/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { FieldLabel } from '../FieldLabel/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst baseClass = 'json-field'\n\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { RenderComponent } from '../../providers/Config/RenderComponent.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { FieldError } from '../FieldError/index.js'\n\nconst JSONFieldComponent: React.FC<JSONFieldProps> = (props) => {\n const {\n descriptionProps,\n errorProps,\n field,\n field: {\n name,\n _path: pathFromProps,\n admin: { className, description, editorOptions, readOnly: readOnlyFromAdmin, style, width },\n jsonSchema,\n label,\n required,\n },\n labelProps,\n readOnly: readOnlyFromTopLevelProps,\n validate,\n } = props\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const [stringValue, setStringValue] = useState<string>()\n const [jsonError, setJsonError] = useState<string>()\n const [hasLoadedValue, setHasLoadedValue] = useState(false)\n\n const memoizedValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function')\n return validate(value, { ...options, jsonError, required })\n },\n [validate, required, jsonError],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const { formInitializing, formProcessing, initialValue, path, setValue, showError, value } =\n useField<string>({\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const handleMount = useCallback(\n (editor, monaco) => {\n if (!jsonSchema) return\n\n const existingSchemas = monaco.languages.json.jsonDefaults.diagnosticsOptions.schemas || []\n const modelUri = monaco.Uri.parse(jsonSchema.uri)\n\n const model = monaco.editor.createModel(JSON.stringify(value, null, 2), 'json', modelUri)\n monaco.languages.json.jsonDefaults.setDiagnosticsOptions({\n enableSchemaRequest: true,\n schemas: [...existingSchemas, jsonSchema],\n validate: true,\n })\n\n editor.setModel(model)\n },\n [jsonSchema, value],\n )\n\n const handleChange = useCallback(\n (val) => {\n if (disabled) return\n setStringValue(val)\n\n try {\n setValue(val ? JSON.parse(val) : null)\n setJsonError(undefined)\n } catch (e) {\n setValue(val ? val : null)\n setJsonError(e)\n }\n },\n [disabled, setValue, setStringValue],\n )\n\n useEffect(() => {\n if (hasLoadedValue || value === undefined) return\n\n setStringValue(\n value || initialValue ? JSON.stringify(value ? value : initialValue, null, 2) : '',\n )\n\n setHasLoadedValue(true)\n }, [initialValue, value, hasLoadedValue])\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n showError && 'error',\n disabled && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n Label={field?.admin?.components?.Label}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <FieldError\n CustomError={field?.admin?.components?.Error}\n path={path}\n {...(errorProps || {})}\n />\n <RenderComponent mappedComponent={field?.admin?.components?.beforeInput} />\n <CodeEditor\n defaultLanguage=\"json\"\n onChange={handleChange}\n onMount={handleMount}\n options={editorOptions}\n readOnly={disabled}\n value={stringValue}\n />\n <RenderComponent mappedComponent={field?.admin?.components?.afterInput} />\n </div>\n <FieldDescription\n Description={field?.admin?.components?.Description}\n description={description}\n {...(descriptionProps || {})}\n />\n </div>\n )\n}\n\nexport const JSONField = withCondition(JSONFieldComponent)\n"],"names":["React","useCallback","useEffect","useState","CodeEditor","useField","withCondition","FieldLabel","fieldBaseClass","baseClass","useFieldProps","RenderComponent","FieldDescription","FieldError","JSONFieldComponent","props","descriptionProps","errorProps","field","name","_path","pathFromProps","admin","className","description","editorOptions","readOnly","readOnlyFromAdmin","style","width","jsonSchema","label","required","labelProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","stringValue","setStringValue","jsonError","setJsonError","hasLoadedValue","setHasLoadedValue","memoizedValidate","value","options","path","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","initialValue","setValue","showError","disabled","handleMount","editor","monaco","existingSchemas","languages","json","jsonDefaults","diagnosticsOptions","schemas","modelUri","Uri","parse","uri","model","createModel","JSON","stringify","setDiagnosticsOptions","enableSchemaRequest","setModel","handleChange","val","undefined","e","div","filter","Boolean","join","Label","components","CustomError","Error","mappedComponent","beforeInput","defaultLanguage","onChange","onMount","afterInput","Description","JSONField"],"mappings":"AAAA;;AAGA,OA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ACb,CACE0B,MAAM,CAACC,SACPC,IAAI,CAAC;QACRtD,OAAO;YACL,GAAGA,KAAK;YACRC;QACF;;0BAEA,KAACtB;gBACC4E,OAAOjE,OAAOI,OAAO8D,YAAYD;gBACjCpD,OAAOA;gBACPC,UAAUA;gBACT,GAAIC,cAAc,CAAC,CAAC;;0BAEvB,MAAC8C;gBAAIxD,WAAW,CAAC,EAAEf,eAAe,MAAM,CAAC;;kCACvC,KAACK;wBACCwE,aAAanE,OAAOI,OAAO8D,YAAYE;wBACvCxC,MAAMA;wBACL,GAAI7B,cAAc,CAAC,CAAC;;kCAEvB,KAACN;wBAAgB4E,iBAAiBrE,OAAOI,OAAO8D,YAAYI;;kCAC5D,KAACpF;wBACCqF,iBAAgB;wBAChBC,UAAUf;wBACVgB,SAASpC;wBACTV,SAASpB;wBACTC,UAAU4B;wBACVV,OAAOP;;kCAET,KAAC1B;wBAAgB4E,iBAAiBrE,OAAOI,OAAO8D,YAAYQ;;;;0BAE9D,KAAChF;gBACCiF,aAAa3E,OAAOI,OAAO8D,YAAYS;gBACvCrE,aAAaA;gBACZ,GAAIR,oBAAoB,CAAC,CAAC;;;;AAInC;AAEA,OAAO,MAAM8E,YAAYxF,cAAcQ,oBAAmB"}
1
+ {"version":3,"sources":["../../../src/fields/JSON/index.tsx"],"sourcesContent":["'use client'\nimport type { JSONFieldProps } from 'payload'\n\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport { CodeEditor } from '../../elements/CodeEditor/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { FieldLabel } from '../FieldLabel/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst baseClass = 'json-field'\n\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { RenderComponent } from '../../providers/Config/RenderComponent.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { FieldError } from '../FieldError/index.js'\n\nconst JSONFieldComponent: React.FC<JSONFieldProps> = (props) => {\n const {\n descriptionProps,\n errorProps,\n field,\n field: {\n name,\n _path: pathFromProps,\n admin: {\n className,\n description,\n editorOptions,\n readOnly: readOnlyFromAdmin,\n style,\n width,\n } = {},\n jsonSchema,\n label,\n required,\n },\n labelProps,\n readOnly: readOnlyFromTopLevelProps,\n validate,\n } = props\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const [stringValue, setStringValue] = useState<string>()\n const [jsonError, setJsonError] = useState<string>()\n const [hasLoadedValue, setHasLoadedValue] = useState(false)\n\n const memoizedValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function')\n return validate(value, { ...options, jsonError, required })\n },\n [validate, required, jsonError],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const { formInitializing, formProcessing, initialValue, path, setValue, showError, value } =\n useField<string>({\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const handleMount = useCallback(\n (editor, monaco) => {\n if (!jsonSchema) return\n\n const existingSchemas = monaco.languages.json.jsonDefaults.diagnosticsOptions.schemas || []\n const modelUri = monaco.Uri.parse(jsonSchema.uri)\n\n const model = monaco.editor.createModel(JSON.stringify(value, null, 2), 'json', modelUri)\n monaco.languages.json.jsonDefaults.setDiagnosticsOptions({\n enableSchemaRequest: true,\n schemas: [...existingSchemas, jsonSchema],\n validate: true,\n })\n\n editor.setModel(model)\n },\n [jsonSchema, value],\n )\n\n const handleChange = useCallback(\n (val) => {\n if (disabled) return\n setStringValue(val)\n\n try {\n setValue(val ? JSON.parse(val) : null)\n setJsonError(undefined)\n } catch (e) {\n setValue(val ? val : null)\n setJsonError(e)\n }\n },\n [disabled, setValue, setStringValue],\n )\n\n useEffect(() => {\n if (hasLoadedValue || value === undefined) return\n\n setStringValue(\n value || initialValue ? JSON.stringify(value ? value : initialValue, null, 2) : '',\n )\n\n setHasLoadedValue(true)\n }, [initialValue, value, hasLoadedValue])\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n showError && 'error',\n disabled && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n Label={field?.admin?.components?.Label}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <FieldError\n CustomError={field?.admin?.components?.Error}\n path={path}\n {...(errorProps || {})}\n />\n <RenderComponent mappedComponent={field?.admin?.components?.beforeInput} />\n <CodeEditor\n defaultLanguage=\"json\"\n onChange={handleChange}\n onMount={handleMount}\n options={editorOptions}\n readOnly={disabled}\n value={stringValue}\n />\n <RenderComponent mappedComponent={field?.admin?.components?.afterInput} />\n </div>\n <FieldDescription\n Description={field?.admin?.components?.Description}\n description={description}\n {...(descriptionProps || {})}\n />\n </div>\n )\n}\n\nexport const JSONField = withCondition(JSONFieldComponent)\n"],"names":["React","useCallback","useEffect","useState","CodeEditor","useField","withCondition","FieldLabel","fieldBaseClass","baseClass","useFieldProps","RenderComponent","FieldDescription","FieldError","JSONFieldComponent","props","descriptionProps","errorProps","field","name","_path","pathFromProps","admin","className","description","editorOptions","readOnly","readOnlyFromAdmin","style","width","jsonSchema","label","required","labelProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","stringValue","setStringValue","jsonError","setJsonError","hasLoadedValue","setHasLoadedValue","memoizedValidate","value","options","path","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","initialValue","setValue","showError","disabled","handleMount","editor","monaco","existingSchemas","languages","json","jsonDefaults","diagnosticsOptions","schemas","modelUri","Uri","parse","uri","model","createModel","JSON","stringify","setDiagnosticsOptions","enableSchemaRequest","setModel","handleChange","val","undefined","e","div","filter","Boolean","join","Label","components","CustomError","Error","mappedComponent","beforeInput","defaultLanguage","onChange","onMount","afterInput","Description","JSONField"],"mappings":"AAAA;;AAGA,OAAOA,SAASC,WAAW,EAAEC,SAAS,EA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SACPC,IAAI,CAAC;QACRtD,OAAO;YACL,GAAGA,KAAK;YACRC;QACF;;0BAEA,KAACtB;gBACC4E,OAAOjE,OAAOI,OAAO8D,YAAYD;gBACjCpD,OAAOA;gBACPC,UAAUA;gBACT,GAAIC,cAAc,CAAC,CAAC;;0BAEvB,MAAC8C;gBAAIxD,WAAW,CAAC,EAAEf,eAAe,MAAM,CAAC;;kCACvC,KAACK;wBACCwE,aAAanE,OAAOI,OAAO8D,YAAYE;wBACvCxC,MAAMA;wBACL,GAAI7B,cAAc,CAAC,CAAC;;kCAEvB,KAACN;wBAAgB4E,iBAAiBrE,OAAOI,OAAO8D,YAAYI;;kCAC5D,KAACpF;wBACCqF,iBAAgB;wBAChBC,UAAUf;wBACVgB,SAASpC;wBACTV,SAASpB;wBACTC,UAAU4B;wBACVV,OAAOP;;kCAET,KAAC1B;wBAAgB4E,iBAAiBrE,OAAOI,OAAO8D,YAAYQ;;;;0BAE9D,KAAChF;gBACCiF,aAAa3E,OAAOI,OAAO8D,YAAYS;gBACvCrE,aAAaA;gBACZ,GAAIR,oBAAoB,CAAC,CAAC;;;;AAInC;AAEA,OAAO,MAAM8E,YAAYxF,cAAcQ,oBAAmB"}
@@ -14,7 +14,7 @@ import { FieldDescription } from '../FieldDescription/index.js';
14
14
  import { FieldError } from '../FieldError/index.js';
15
15
  import { FieldLabel } from '../FieldLabel/index.js';
16
16
  export const PointFieldComponent = (props)=>{
17
- const { descriptionProps, errorProps, field, field: { name, _path: pathFromProps, admin: { className, description, placeholder, readOnly: readOnlyFromAdmin, step, style, width }, label, required }, labelProps, readOnly: readOnlyFromTopLevelProps, validate } = props;
17
+ const { descriptionProps, errorProps, field, field: { name, _path: pathFromProps, admin: { className, description, placeholder, readOnly: readOnlyFromAdmin, step, style, width } = {}, label, required }, labelProps, readOnly: readOnlyFromTopLevelProps, validate } = props;
18
18
  const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin;
19
19
  const { i18n, t } = useTranslation();
20
20
  const memoizedValidate = useCallback((value, options)=>{