@payloadcms/ui 3.0.0-beta.0 → 3.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fields/Array/index.d.ts.map +1 -1
- package/dist/fields/Array/index.js +3 -2
- package/dist/fields/Array/index.js.map +1 -1
- package/dist/fields/Blocks/index.d.ts.map +1 -1
- package/dist/fields/Blocks/index.js +3 -2
- package/dist/fields/Blocks/index.js.map +1 -1
- package/dist/fields/Collapsible/index.d.ts.map +1 -1
- package/dist/fields/Collapsible/index.js +27 -21
- package/dist/fields/Collapsible/index.js.map +1 -1
- package/dist/fields/Tabs/index.d.ts.map +1 -1
- package/dist/fields/Tabs/index.js +27 -23
- package/dist/fields/Tabs/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Array/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,eAAe,CAAA;AAQjE,OAAO,KAAsB,MAAM,OAAO,CAAA;AAE1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yDAAyD,CAAA;AACvF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAiBvD,OAAO,cAAc,CAAA;AAIrB,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG;IAC5C,cAAc,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAChC,QAAQ,EAAE,QAAQ,CAAA;IAClB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,KAAK,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAA;IAC1B,MAAM,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAA;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AAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAsRjD,CAAA;AAED,eAAO,MAAM,UAAU,2BAA6B,CAAA"}
|
|
@@ -23,9 +23,10 @@ import { fieldBaseClass } from '../shared/index.js';
|
|
|
23
23
|
import { ArrayRow } from './ArrayRow.js';
|
|
24
24
|
const baseClass = 'array-field';
|
|
25
25
|
export const _ArrayField = (props)=>{
|
|
26
|
-
const { name, CustomDescription, CustomError, CustomLabel, CustomRowLabel, className, descriptionProps, errorProps, fieldMap, forceRender = false, label, labelProps, localized, maxRows, minRows, path: pathFromProps, permissions, readOnly: readOnlyFromProps, required, validate } = props;
|
|
26
|
+
const { name, CustomDescription, CustomError, CustomLabel, CustomRowLabel, className, descriptionProps, errorProps, fieldMap, forceRender = false, label, labelProps, localized, maxRows, minRows: minRowsProp, path: pathFromProps, permissions, readOnly: readOnlyFromProps, required, validate } = props;
|
|
27
27
|
const { indexPath, readOnly: readOnlyFromContext } = useFieldProps();
|
|
28
28
|
const readOnly = readOnlyFromProps || readOnlyFromContext;
|
|
29
|
+
const minRows = minRowsProp ?? required ? 1 : 0;
|
|
29
30
|
const { setDocFieldPreferences } = useDocumentInfo();
|
|
30
31
|
const { addFieldRow, dispatchFields, setModified } = useForm();
|
|
31
32
|
const submitted = useFormSubmitted();
|
|
@@ -252,7 +253,7 @@ export const _ArrayField = (props)=>{
|
|
|
252
253
|
type: "error"
|
|
253
254
|
}, t('validation:requiresAtLeast', {
|
|
254
255
|
count: minRows,
|
|
255
|
-
label: getTranslation(minRows ? labels.plural : labels.singular, i18n) || t(minRows > 1 ? 'general:row' : 'general:rows')
|
|
256
|
+
label: getTranslation(minRows > 1 ? labels.plural : labels.singular, i18n) || t(minRows > 1 ? 'general:row' : 'general:rows')
|
|
256
257
|
})))), !readOnly && !hasMaxRows && /*#__PURE__*/ React.createElement(Button, {
|
|
257
258
|
buttonStyle: "icon-label",
|
|
258
259
|
className: `${baseClass}__add-row`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/Array/index.tsx"],"sourcesContent":["'use client'\nimport type { FieldPermissions } from 'payload/auth'\nimport type { FieldBase } from 'payload/types'\nimport type { ArrayField as ArrayFieldType } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { FieldDescription } from '@payloadcms/ui/forms/FieldDescription'\nimport { FieldError } from '@payloadcms/ui/forms/FieldError'\nimport { FieldLabel } from '@payloadcms/ui/forms/FieldLabel'\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { withCondition } from '@payloadcms/ui/forms/withCondition'\nimport React, { useCallback } from 'react'\n\nimport type { FieldMap } from '../../providers/ComponentMap/buildComponentMap/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\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 { useForm, useFormSubmitted } from '../../forms/Form/context.js'\nimport { NullifyLocaleField } from '../../forms/NullifyField/index.js'\nimport { useField } from '../../forms/useField/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 { fieldBaseClass } from '../shared/index.js'\nimport { ArrayRow } from './ArrayRow.js'\nimport './index.scss'\n\nconst baseClass = 'array-field'\n\nexport type ArrayFieldProps = FormFieldBase & {\n CustomRowLabel?: React.ReactNode\n fieldMap: FieldMap\n forceRender?: boolean\n label?: FieldBase['label']\n labels?: ArrayFieldType['labels']\n maxRows?: ArrayFieldType['maxRows']\n minRows?: ArrayFieldType['minRows']\n name?: string\n permissions: FieldPermissions\n width?: string\n}\n\nexport const _ArrayField: React.FC<ArrayFieldProps> = (props) => {\n const {\n name,\n CustomDescription,\n CustomError,\n CustomLabel,\n CustomRowLabel,\n className,\n descriptionProps,\n errorProps,\n fieldMap,\n forceRender = false,\n label,\n labelProps,\n localized,\n maxRows,\n minRows,\n path: pathFromProps,\n permissions,\n readOnly: readOnlyFromProps,\n required,\n validate,\n } = props\n\n const { indexPath, readOnly: readOnlyFromContext } = useFieldProps()\n const readOnly = readOnlyFromProps || readOnlyFromContext\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 const { localization } = 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) => {\n if ('labels' in p && p?.labels) return p.labels\n if ('label' in p && p?.label) return { plural: undefined, singular: p.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 { path: pathFromContext } = useFieldProps()\n\n const {\n errorPaths,\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 addRow = useCallback(\n async (rowIndex: number) => {\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 dispatchFields({ type: 'SET_ALL_ROWS_COLLAPSED', collapsed, path, setDocFieldPreferences })\n },\n [dispatchFields, path, setDocFieldPreferences],\n )\n\n const setCollapse = useCallback(\n (rowID: string, collapsed: boolean) => {\n dispatchFields({ type: 'SET_ROW_COLLAPSED', collapsed, path, rowID, setDocFieldPreferences })\n },\n [dispatchFields, path, 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 = readOnly && 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 <div className={`${baseClass}__error-wrap`}>\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n </div>\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 CustomLabel={CustomLabel}\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 CustomDescription={CustomDescription} {...(descriptionProps || {})} />\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={readOnly} id={row.id} key={row.id}>\n {(draggableSortableItemProps) => (\n <ArrayRow\n {...draggableSortableItemProps}\n CustomRowLabel={CustomRowLabel}\n addRow={addRow}\n duplicateRow={duplicateRow}\n errorCount={rowErrorCount}\n fieldMap={fieldMap}\n forceRender={forceRender}\n hasMaxRows={hasMaxRows}\n indexPath={indexPath}\n labels={labels}\n moveRow={moveRow}\n path={path}\n permissions={permissions}\n readOnly={readOnly}\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 ? labels.plural : labels.singular, i18n) ||\n t(minRows > 1 ? 'general:row' : 'general:rows'),\n })}\n </Banner>\n )}\n </React.Fragment>\n )}\n </DraggableSortable>\n )}\n {!readOnly && !hasMaxRows && (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__add-row`}\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n onClick={() => addRow(value || 0)}\n >\n {t('fields:addLabel', { label: getTranslation(labels.singular, i18n) })}\n </Button>\n )}\n </div>\n )\n}\n\nexport const ArrayField = withCondition(_ArrayField)\n"],"names":["getTranslation","FieldDescription","FieldError","FieldLabel","useFieldProps","withCondition","React","useCallback","Banner","Button","DraggableSortableItem","DraggableSortable","ErrorPill","useForm","useFormSubmitted","NullifyLocaleField","useField","useConfig","useDocumentInfo","useLocale","useTranslation","scrollToID","fieldBaseClass","ArrayRow","baseClass","_ArrayField","props","name","CustomDescription","CustomError","CustomLabel","CustomRowLabel","className","descriptionProps","errorProps","fieldMap","forceRender","label","labelProps","localized","maxRows","minRows","path","pathFromProps","permissions","readOnly","readOnlyFromProps","required","validate","indexPath","readOnlyFromContext","setDocFieldPreferences","addFieldRow","dispatchFields","setModified","submitted","code","locale","i18n","t","localization","editingDefaultLocale","fallback","defaultLocale","getLabels","p","labels","plural","undefined","singular","memoizedValidate","value","options","pathFromContext","errorPaths","rows","schemaPath","showError","valid","hasRows","addRow","rowIndex","setTimeout","duplicateRow","type","removeRow","moveRow","moveFromIndex","moveToIndex","toggleCollapseAll","collapsed","setCollapse","rowID","hasMaxRows","length","fieldErrorCount","fieldHasErrors","showRequired","showMinRows","div","filter","Boolean","join","id","replace","header","h3","as","unstyled","count","withMessage","ul","li","button","onClick","fieldValue","ids","map","row","onDragEnd","i","rowErrorCount","errorPath","startsWith","disabled","key","draggableSortableItemProps","errorCount","rowCount","Fragment","buttonStyle","icon","iconPosition","iconStyle","ArrayField"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;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d4C,YAAYN;gBACZtF,UAAUA;gBACVC,aAAaA;gBACbyD,YAAYA;gBACZ5C,WAAWA;gBACXiB,QAAQA;gBACRoB,SAASA;gBACT5C,MAAMA;gBACNE,aAAaA;gBACbC,UAAUA;gBACVwC,WAAWA;gBACXiC,KAAKA;gBACLU,UAAUrD,KAAKmB,MAAM;gBACrBb,UAAUuC;gBACV5C,YAAYA;gBACZe,aAAaA;;IAKvB,IACC,CAACb,uBACA,oBAACxE,MAAM2H,QAAQ,QACZhC,8BACC,oBAACzF,cACEmD,EAAE,yBAAyB;QAAEtB,OAAOrC,eAAekE,OAAOC,MAAM,EAAET;IAAM,KAG5EwC,6BACC,oBAAC1F;QAAO4E,MAAK;OACVzB,EAAE,8BAA8B;QAC/BkD,OAAOpE;QACPJ,OACErC,eAAeyC,UAAUyB,OAAOC,MAAM,GAAGD,OAAOG,QAAQ,EAAEX,SAC1DC,EAAElB,UAAU,IAAI,gBAAgB;IACpC,OAOX,CAACI,YAAY,CAACgD,4BACb,oBAACpF;QACCyH,aAAY;QACZlG,WAAW,CAAC,EAAER,UAAU,SAAS,CAAC;QAClC2G,MAAK;QACLC,cAAa;QACbC,WAAU;QACVnB,SAAS,IAAMlC,OAAOT,SAAS;OAE9BZ,EAAE,mBAAmB;QAAEtB,OAAOrC,eAAekE,OAAOG,QAAQ,EAAEX;IAAM;AAK/E,EAAC;AAED,OAAO,MAAM4E,aAAajI,cAAcoB,aAAY"}
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/Array/index.tsx"],"sourcesContent":["'use client'\nimport type { FieldPermissions } from 'payload/auth'\nimport type { FieldBase } from 'payload/types'\nimport type { ArrayField as ArrayFieldType } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { FieldDescription } from '@payloadcms/ui/forms/FieldDescription'\nimport { FieldError } from '@payloadcms/ui/forms/FieldError'\nimport { FieldLabel } from '@payloadcms/ui/forms/FieldLabel'\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { withCondition } from '@payloadcms/ui/forms/withCondition'\nimport React, { useCallback } from 'react'\n\nimport type { FieldMap } from '../../providers/ComponentMap/buildComponentMap/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\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 { useForm, useFormSubmitted } from '../../forms/Form/context.js'\nimport { NullifyLocaleField } from '../../forms/NullifyField/index.js'\nimport { useField } from '../../forms/useField/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 { fieldBaseClass } from '../shared/index.js'\nimport { ArrayRow } from './ArrayRow.js'\nimport './index.scss'\n\nconst baseClass = 'array-field'\n\nexport type ArrayFieldProps = FormFieldBase & {\n CustomRowLabel?: React.ReactNode\n fieldMap: FieldMap\n forceRender?: boolean\n label?: FieldBase['label']\n labels?: ArrayFieldType['labels']\n maxRows?: ArrayFieldType['maxRows']\n minRows?: ArrayFieldType['minRows']\n name?: string\n permissions: FieldPermissions\n width?: string\n}\n\nexport const _ArrayField: React.FC<ArrayFieldProps> = (props) => {\n const {\n name,\n CustomDescription,\n CustomError,\n CustomLabel,\n CustomRowLabel,\n className,\n descriptionProps,\n errorProps,\n fieldMap,\n forceRender = false,\n label,\n labelProps,\n localized,\n maxRows,\n minRows: minRowsProp,\n path: pathFromProps,\n permissions,\n readOnly: readOnlyFromProps,\n required,\n validate,\n } = props\n\n const { indexPath, readOnly: readOnlyFromContext } = useFieldProps()\n const readOnly = readOnlyFromProps || readOnlyFromContext\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 const { localization } = 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) => {\n if ('labels' in p && p?.labels) return p.labels\n if ('label' in p && p?.label) return { plural: undefined, singular: p.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 { path: pathFromContext } = useFieldProps()\n\n const {\n errorPaths,\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 addRow = useCallback(\n async (rowIndex: number) => {\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 dispatchFields({ type: 'SET_ALL_ROWS_COLLAPSED', collapsed, path, setDocFieldPreferences })\n },\n [dispatchFields, path, setDocFieldPreferences],\n )\n\n const setCollapse = useCallback(\n (rowID: string, collapsed: boolean) => {\n dispatchFields({ type: 'SET_ROW_COLLAPSED', collapsed, path, rowID, setDocFieldPreferences })\n },\n [dispatchFields, path, 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 = readOnly && 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 <div className={`${baseClass}__error-wrap`}>\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n </div>\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 CustomLabel={CustomLabel}\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 CustomDescription={CustomDescription} {...(descriptionProps || {})} />\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={readOnly} id={row.id} key={row.id}>\n {(draggableSortableItemProps) => (\n <ArrayRow\n {...draggableSortableItemProps}\n CustomRowLabel={CustomRowLabel}\n addRow={addRow}\n duplicateRow={duplicateRow}\n errorCount={rowErrorCount}\n fieldMap={fieldMap}\n forceRender={forceRender}\n hasMaxRows={hasMaxRows}\n indexPath={indexPath}\n labels={labels}\n moveRow={moveRow}\n path={path}\n permissions={permissions}\n readOnly={readOnly}\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:row' : 'general:rows'),\n })}\n </Banner>\n )}\n </React.Fragment>\n )}\n </DraggableSortable>\n )}\n {!readOnly && !hasMaxRows && (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__add-row`}\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n onClick={() => addRow(value || 0)}\n >\n {t('fields:addLabel', { label: getTranslation(labels.singular, i18n) })}\n </Button>\n )}\n </div>\n )\n}\n\nexport const ArrayField = withCondition(_ArrayField)\n"],"names":["getTranslation","FieldDescription","FieldError","FieldLabel","useFieldProps","withCondition","React","useCallback","Banner","Button","DraggableSortableItem","DraggableSortable","ErrorPill","useForm","useFormSubmitted","NullifyLocaleField","useField","useConfig","useDocumentInfo","useLocale","useTranslation","scrollToID","fieldBaseClass","ArrayRow","baseClass","_ArrayField","props","name","CustomDescription","CustomError","CustomLabel","CustomRowLabel","className","descriptionProps","errorProps","fieldMap","forceRender","label","labelProps","localized","maxRows","minRows","minRowsProp","path","pathFromProps","permissions","readOnly","readOnlyFromProps","required","validate","indexPath","readOnlyFromContext","setDocFieldPreferences","addFieldRow","dispatchFields","setModified","submitted","code","locale","i18n","t","localization","editingDefaultLocale","fallback","defaultLocale","getLabels","p","labels","plural","undefined","singular","memoizedValidate","value","options","pathFromContext","errorPaths","rows","schemaPath","showError","valid","hasRows","addRow","rowIndex","setTimeout","duplicateRow","type","removeRow","moveRow","moveFromIndex","moveToIndex","toggleCollapseAll","collapsed","setCollapse","rowID","hasMaxRows","length","fieldErrorCount","fieldHasErrors","showRequired","showMinRows","div","filter","Boolean","join","id","replace","header","h3","as","unstyled","count","withMessage","ul","li","button","onClick","fieldValue","ids","map","row","onDragEnd","i","rowErrorCount","errorPath","startsWith","disabled","key","draggableSortableItemProps","errorCount","rowCount","Fragment","buttonStyle","icon","iconPosition","iconStyle","ArrayField"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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Props } from '@payloadcms/ui/forms/FieldPropsProvider';
|
|
|
27
27
|
import { withCondition } from '@payloadcms/ui/forms/withCondition';
|
|
28
28
|
const _BlocksField = (props)=>{
|
|
29
29
|
const { i18n, t } = useTranslation();
|
|
30
|
-
const { name, CustomDescription, CustomError, CustomLabel, blocks, className, descriptionProps, errorProps, forceRender = false, label, labelProps, labels: labelsFromProps, localized, maxRows, minRows, path: pathFromProps, readOnly: readOnlyFromProps, required, validate } = props;
|
|
30
|
+
const { name, CustomDescription, CustomError, CustomLabel, blocks, className, descriptionProps, errorProps, forceRender = false, label, labelProps, labels: labelsFromProps, localized, maxRows, minRows: minRowsProp, path: pathFromProps, readOnly: readOnlyFromProps, required, validate } = props;
|
|
31
31
|
const { indexPath, readOnly: readOnlyFromContext } = useFieldProps();
|
|
32
32
|
const readOnly = readOnlyFromProps || readOnlyFromContext;
|
|
33
|
+
const minRows = minRowsProp ?? required ? 1 : 0;
|
|
33
34
|
const { setDocFieldPreferences } = useDocumentInfo();
|
|
34
35
|
const { addFieldRow, dispatchFields, setModified } = useForm();
|
|
35
36
|
const { code: locale } = useLocale();
|
|
@@ -252,7 +253,7 @@ const _BlocksField = (props)=>{
|
|
|
252
253
|
type: "error"
|
|
253
254
|
}, t('validation:requiresAtLeast', {
|
|
254
255
|
count: minRows,
|
|
255
|
-
label: getTranslation(minRows
|
|
256
|
+
label: getTranslation(minRows > 1 ? labels.plural : labels.singular, i18n) || t(minRows > 1 ? 'general:row' : 'general:rows')
|
|
256
257
|
})), showRequired && /*#__PURE__*/ React.createElement(Banner, null, t('validation:fieldHasNo', {
|
|
257
258
|
label: getTranslation(labels.plural, i18n)
|
|
258
259
|
})))), !readOnly && !hasMaxRows && /*#__PURE__*/ React.createElement(Fragment, null, /*#__PURE__*/ React.createElement(DrawerToggler, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/Blocks/index.tsx"],"sourcesContent":["'use client'\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 { useForm, useFormSubmitted } from '../../forms/Form/context.js'\nimport { NullifyLocaleField } from '../../forms/NullifyField/index.js'\nimport { useField } from '../../forms/useField/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 { 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\nimport type { FieldPermissions } from 'payload/auth'\nimport type { BlockField, FieldBase } from 'payload/types'\n\nimport { FieldDescription } from '@payloadcms/ui/forms/FieldDescription'\nimport { FieldError } from '@payloadcms/ui/forms/FieldError'\nimport { FieldLabel } from '@payloadcms/ui/forms/FieldLabel'\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { withCondition } from '@payloadcms/ui/forms/withCondition'\n\nimport type { ReducedBlock } from '../../providers/ComponentMap/buildComponentMap/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\n\nexport type BlocksFieldProps = FormFieldBase & {\n blocks?: ReducedBlock[]\n forceRender?: boolean\n label?: FieldBase['label']\n labels?: BlockField['labels']\n maxRows?: number\n minRows?: number\n name?: string\n permissions: FieldPermissions\n slug?: string\n width?: string\n}\n\nconst _BlocksField: React.FC<BlocksFieldProps> = (props) => {\n const { i18n, t } = useTranslation()\n\n const {\n name,\n CustomDescription,\n CustomError,\n CustomLabel,\n blocks,\n className,\n descriptionProps,\n errorProps,\n forceRender = false,\n label,\n labelProps,\n labels: labelsFromProps,\n localized,\n maxRows,\n minRows,\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n required,\n validate,\n } = props\n\n const { indexPath, readOnly: readOnlyFromContext } = useFieldProps()\n const readOnly = readOnlyFromProps || readOnlyFromContext\n\n const { setDocFieldPreferences } = useDocumentInfo()\n const { addFieldRow, dispatchFields, setModified } = useForm()\n const { code: locale } = useLocale()\n const { localization } = 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 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 addRow = useCallback(\n async (rowIndex: number, blockType: string) => {\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 dispatchFields({ type: 'SET_ALL_ROWS_COLLAPSED', collapsed, path, setDocFieldPreferences })\n },\n [dispatchFields, path, setDocFieldPreferences],\n )\n\n const setCollapse = useCallback(\n (rowID: string, collapsed: boolean) => {\n dispatchFields({ type: 'SET_ROW_COLLAPSED', collapsed, path, rowID, setDocFieldPreferences })\n },\n [dispatchFields, path, 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 = readOnly && 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 <div className={`${baseClass}__error-wrap`}>\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n </div>\n )}\n <header className={`${baseClass}__header`}>\n <div className={`${baseClass}__header-wrap`}>\n <div className={`${baseClass}__heading-with-error`}>\n <h3>\n <FieldLabel\n CustomLabel={CustomLabel}\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 CustomDescription={CustomDescription} {...(descriptionProps || {})} />\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={readOnly} 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 labels={labels}\n moveRow={moveRow}\n path={path}\n permissions={permissions}\n readOnly={readOnly}\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: getTranslation(\n minRows === 1 || typeof minRows === 'undefined'\n ? labels.singular\n : labels.plural,\n i18n,\n ),\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 {!readOnly && !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(_BlocksField)\n"],"names":["getTranslation","React","Fragment","useCallback","Banner","Button","DraggableSortableItem","DraggableSortable","DrawerToggler","useDrawerSlug","ErrorPill","useForm","useFormSubmitted","NullifyLocaleField","useField","useConfig","useDocumentInfo","useLocale","useTranslation","scrollToID","fieldBaseClass","BlockRow","BlocksDrawer","baseClass","FieldDescription","FieldError","FieldLabel","useFieldProps","withCondition","_BlocksField","props","i18n","t","name","CustomDescription","CustomError","CustomLabel","blocks","className","descriptionProps","errorProps","forceRender","label","labelProps","labels","labelsFromProps","localized","maxRows","minRows","path","pathFromProps","readOnly","readOnlyFromProps","required","validate","indexPath","readOnlyFromContext","setDocFieldPreferences","addFieldRow","dispatchFields","setModified","code","locale","localization","drawerSlug","submitted","plural","singular","editingDefaultLocale","fallback","defaultLocale","memoizedValidate","value","options","pathFromContext","errorPaths","permissions","rows","schemaPath","showError","valid","hasRows","addRow","rowIndex","blockType","data","setTimeout","duplicateRow","type","removeRow","moveRow","moveFromIndex","moveToIndex","toggleCollapseAll","collapsed","setCollapse","rowID","hasMaxRows","length","fieldErrorCount","fieldHasErrors","showMinRows","showRequired","div","filter","Boolean","join","id","replace","header","h3","as","unstyled","count","withMessage","ul","li","button","onClick","fieldValue","ids","map","row","onDragEnd","i","blockToRender","find","block","slug","rowErrorCount","errorPath","startsWith","disabled","key","draggableSortableItemProps","errorCount","rowCount","buttonStyle","el","icon","iconPosition","iconStyle","addRowIndex","BlocksField"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AACA,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,SAASC,aAAa,QAAQ,yCAAwC;AACtE,SAASC,SAAS,QAAQ,oCAAmC;AAC7D,SAASC,OAAO,EAAEC,gBAAgB,QAAQ,8BAA6B;AACvE,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,UAAU,QAAQ,gCAA+B;AAC1D,SAASC,cAAc,QAAQ,qBAAoB;AACnD,SAASC,QAAQ,QAAQ,gBAAe;AACxC,SAASC,YAAY,QAAQ,0BAAyB;A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QAAQ,EAAEpC;IAAM,oBAGzE,oBAACT;QACC4D,QAAQA;QACR4D,aAAajE,MAAMqB,UAAU;QAC7B7D,QAAQA;QACR2B,YAAYA;QACZpB,QAAQA;;AAMpB;AAEA,OAAO,MAAMmG,cAAcnH,cAAcC,cAAa"}
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/Blocks/index.tsx"],"sourcesContent":["'use client'\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 { useForm, useFormSubmitted } from '../../forms/Form/context.js'\nimport { NullifyLocaleField } from '../../forms/NullifyField/index.js'\nimport { useField } from '../../forms/useField/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 { 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\nimport type { FieldPermissions } from 'payload/auth'\nimport type { BlockField, FieldBase } from 'payload/types'\n\nimport { FieldDescription } from '@payloadcms/ui/forms/FieldDescription'\nimport { FieldError } from '@payloadcms/ui/forms/FieldError'\nimport { FieldLabel } from '@payloadcms/ui/forms/FieldLabel'\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { withCondition } from '@payloadcms/ui/forms/withCondition'\n\nimport type { ReducedBlock } from '../../providers/ComponentMap/buildComponentMap/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\n\nexport type BlocksFieldProps = FormFieldBase & {\n blocks?: ReducedBlock[]\n forceRender?: boolean\n label?: FieldBase['label']\n labels?: BlockField['labels']\n maxRows?: number\n minRows?: number\n name?: string\n permissions: FieldPermissions\n slug?: string\n width?: string\n}\n\nconst _BlocksField: React.FC<BlocksFieldProps> = (props) => {\n const { i18n, t } = useTranslation()\n\n const {\n name,\n CustomDescription,\n CustomError,\n CustomLabel,\n blocks,\n className,\n descriptionProps,\n errorProps,\n forceRender = false,\n label,\n labelProps,\n labels: labelsFromProps,\n localized,\n maxRows,\n minRows: minRowsProp,\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n required,\n validate,\n } = props\n\n const { indexPath, readOnly: readOnlyFromContext } = useFieldProps()\n const readOnly = readOnlyFromProps || readOnlyFromContext\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 { localization } = 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 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 addRow = useCallback(\n async (rowIndex: number, blockType: string) => {\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 dispatchFields({ type: 'SET_ALL_ROWS_COLLAPSED', collapsed, path, setDocFieldPreferences })\n },\n [dispatchFields, path, setDocFieldPreferences],\n )\n\n const setCollapse = useCallback(\n (rowID: string, collapsed: boolean) => {\n dispatchFields({ type: 'SET_ROW_COLLAPSED', collapsed, path, rowID, setDocFieldPreferences })\n },\n [dispatchFields, path, 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 = readOnly && 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 <div className={`${baseClass}__error-wrap`}>\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n </div>\n )}\n <header className={`${baseClass}__header`}>\n <div className={`${baseClass}__header-wrap`}>\n <div className={`${baseClass}__heading-with-error`}>\n <h3>\n <FieldLabel\n CustomLabel={CustomLabel}\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 CustomDescription={CustomDescription} {...(descriptionProps || {})} />\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={readOnly} 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 labels={labels}\n moveRow={moveRow}\n path={path}\n permissions={permissions}\n readOnly={readOnly}\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 {!readOnly && !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(_BlocksField)\n"],"names":["getTranslation","React","Fragment","useCallback","Banner","Button","DraggableSortableItem","DraggableSortable","DrawerToggler","useDrawerSlug","ErrorPill","useForm","useFormSubmitted","NullifyLocaleField","useField","useConfig","useDocumentInfo","useLocale","useTranslation","scrollToID","fieldBaseClass","BlockRow","BlocksDrawer","baseClass","FieldDescription","FieldError","FieldLabel","useFieldProps","withCondition","_BlocksField","props","i18n","t","name","CustomDescription","CustomError","CustomLabel","blocks","className","descriptionProps","errorProps","forceRender","label","labelProps","labels","labelsFromProps","localized","maxRows","minRows","minRowsProp","path","pathFromProps","readOnly","readOnlyFromProps","required","validate","indexPath","readOnlyFromContext","setDocFieldPreferences","addFieldRow","dispatchFields","setModified","code","locale","localization","drawerSlug","submitted","plural","singular","editingDefaultLocale","fallback","defaultLocale","memoizedValidate","value","options","pathFromContext","errorPaths","permissions","rows","schemaPath","showError","valid","hasRows","addRow","rowIndex","blockType","data","setTimeout","duplicateRow","type","removeRow","moveRow","moveFromIndex","moveToIndex","toggleCollapseAll","collapsed","setCollapse","rowID","hasMaxRows","length","fieldErrorCount","fieldHasErrors","showMinRows","showRequired","div","filter","Boolean","join","id","replace","header","h3","as","unstyled","count","withMessage","ul","li","button","onClick","fieldValue","ids","map","row","onDragEnd","i","blockToRender","find","block","slug","rowErrorCount","errorPath","startsWith","disabled","key","draggableSortableItemProps","errorCount","rowCount","buttonStyle","el","icon","iconPosition","iconStyle","addRowIndex","BlocksField"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AACA,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,SAASC,aAAa,QAAQ,yCAAwC;AACtE,SAASC,SAAS,QAAQ,oCAAmC;AAC7D,SAASC,OAAO,EAAEC,gBAAgB,QAAQ,8BAA6B;AACvE,SAASC,kBAAk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":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Collapsible/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAuB,SAAS,EAAE,MAAM,eAAe,CAAA;AAEnE,OAAO,KAAqD,MAAM,OAAO,CAAA;AAazE,OAAO,cAAc,CAAA;AAIrB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAIpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yDAAyD,CAAA;AACvF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEvD,MAAM,MAAM,qBAAqB,GAAG,aAAa,GAAG;IAClD,QAAQ,EAAE,QAAQ,CAAA;IAClB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,KAAK,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAA;IAC1B,WAAW,EAAE,gBAAgB,CAAA;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAyID,eAAO,MAAM,WAAW,iCAAkC,CAAA"}
|
|
@@ -26,26 +26,28 @@ const CollapsibleField = (props)=>{
|
|
|
26
26
|
const fieldHasErrors = errorCount > 0;
|
|
27
27
|
const onToggle = useCallback(async (newCollapsedState)=>{
|
|
28
28
|
const existingPreferences = await getPreference(preferencesKey);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
if (preferencesKey) {
|
|
30
|
+
void setPreference(preferencesKey, {
|
|
31
|
+
...existingPreferences,
|
|
32
|
+
...path ? {
|
|
33
|
+
fields: {
|
|
34
|
+
...existingPreferences?.fields || {},
|
|
35
|
+
[path]: {
|
|
36
|
+
...existingPreferences?.fields?.[path],
|
|
37
|
+
collapsed: newCollapsedState
|
|
38
|
+
}
|
|
37
39
|
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
} : {
|
|
41
|
+
fields: {
|
|
42
|
+
...existingPreferences?.fields || {},
|
|
43
|
+
[fieldPreferencesKey]: {
|
|
44
|
+
...existingPreferences?.fields?.[fieldPreferencesKey],
|
|
45
|
+
collapsed: newCollapsedState
|
|
46
|
+
}
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
49
51
|
}, [
|
|
50
52
|
preferencesKey,
|
|
51
53
|
fieldPreferencesKey,
|
|
@@ -55,10 +57,14 @@ const CollapsibleField = (props)=>{
|
|
|
55
57
|
]);
|
|
56
58
|
useEffect(()=>{
|
|
57
59
|
const fetchInitialState = async ()=>{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
60
|
+
if (preferencesKey) {
|
|
61
|
+
const preferences = await getPreference(preferencesKey);
|
|
62
|
+
const specificPreference = path ? preferences?.fields?.[path]?.collapsed : preferences?.fields?.[fieldPreferencesKey]?.collapsed;
|
|
63
|
+
if (specificPreference !== undefined) {
|
|
64
|
+
setCollapsedOnMount(Boolean(specificPreference));
|
|
65
|
+
} else {
|
|
66
|
+
setCollapsedOnMount(typeof initCollapsed === 'boolean' ? initCollapsed : false);
|
|
67
|
+
}
|
|
62
68
|
} else {
|
|
63
69
|
setCollapsedOnMount(typeof initCollapsed === 'boolean' ? initCollapsed : false);
|
|
64
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/Collapsible/index.tsx"],"sourcesContent":["'use client'\nimport type { DocumentPreferences, FieldBase } from 'payload/types'\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 type { FieldPermissions } from 'payload/auth'\n\nimport { FieldDescription } from '@payloadcms/ui/forms/FieldDescription'\n\nimport type { FieldMap } from '../../providers/ComponentMap/buildComponentMap/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\n\nexport type CollapsibleFieldProps = FormFieldBase & {\n fieldMap: FieldMap\n initCollapsed?: boolean\n label?: FieldBase['label']\n permissions: FieldPermissions\n width?: string\n}\n\nconst CollapsibleField: React.FC<CollapsibleFieldProps> = (props) => {\n const {\n CustomDescription,\n CustomLabel,\n className,\n descriptionProps,\n fieldMap,\n initCollapsed = false,\n labelProps,\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n } = props\n\n const {\n indexPath,\n path: pathFromContext,\n readOnly: readOnlyFromContext,\n schemaPath,\n siblingPermissions,\n } = useFieldProps()\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) => {\n const existingPreferences: DocumentPreferences = await getPreference(preferencesKey)\n\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 [preferencesKey, fieldPreferencesKey, getPreference, setPreference, path],\n )\n\n useEffect(() => {\n const fetchInitialState = async () => {\n const preferences = await getPreference(preferencesKey)\n if (preferences) {\n const initCollapsedFromPref = path\n ? preferences?.fields?.[path]?.collapsed\n : preferences?.fields?.[fieldPreferencesKey]?.collapsed\n setCollapsedOnMount(Boolean(initCollapsedFromPref))\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 readOnly = readOnlyFromProps || readOnlyFromContext\n\n return (\n <Fragment>\n <WatchChildErrors fieldMap={fieldMap} 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 RowLabelComponent={CustomLabel}\n i18n={i18n}\n path={path}\n rowLabel={labelProps.label}\n />\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n }\n initCollapsed={collapsedOnMount}\n onToggle={onToggle}\n >\n <RenderFields\n fieldMap={fieldMap}\n forceRender\n indexPath={indexPath}\n margins=\"small\"\n path={path}\n permissions={siblingPermissions}\n readOnly={readOnly}\n schemaPath={schemaPath}\n />\n </CollapsibleElement>\n <FieldDescription CustomDescription={CustomDescription} {...(descriptionProps || {})} />\n </div>\n </Fragment>\n )\n}\n\nexport const Collapsible = withCondition(CollapsibleField)\n"],"names":["React","Fragment","useCallback","useEffect","useState","Collapsible","CollapsibleElement","ErrorPill","useFieldProps","RenderFields","RowLabel","WatchChildErrors","withCondition","useDocumentInfo","usePreferences","useTranslation","fieldBaseClass","baseClass","FieldDescription","CollapsibleField","props","CustomDescription","CustomLabel","className","descriptionProps","fieldMap","initCollapsed","labelProps","path","pathFromProps","readOnly","readOnlyFromProps","indexPath","pathFromContext","readOnlyFromContext","schemaPath","siblingPermissions","i18n","getPreference","setPreference","preferencesKey","collapsedOnMount","setCollapsedOnMount","fieldPreferencesKey","replace","errorCount","setErrorCount","fieldHasErrors","onToggle","newCollapsedState","existingPreferences","fields","collapsed","fetchInitialState","preferences","initCollapsedFromPref","Boolean","div","filter","join","id","collapsibleStyle","header","RowLabelComponent","rowLabel","label","count","withMessage","forceRender","margins","permissions"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","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;AAGnD,MAAMC,YAAY;AAIlB,SAASC,gBAAgB,QAAQ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C,WAAWA;QACXqC,SAAQ;QACRzC,MAAMA;QACN0C,aAAalC;QACbN,UAAUA;QACVK,YAAYA;uBAGhB,oBAACjB;QAAiBG,mBAAmBA;QAAoB,GAAIG,oBAAoB,CAAC,CAAC;;AAI3F;AAEA,OAAO,MAAMnB,cAAcO,cAAcO,kBAAiB"}
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/Collapsible/index.tsx"],"sourcesContent":["'use client'\nimport type { DocumentPreferences, FieldBase } from 'payload/types'\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 type { FieldPermissions } from 'payload/auth'\n\nimport { FieldDescription } from '@payloadcms/ui/forms/FieldDescription'\n\nimport type { FieldMap } from '../../providers/ComponentMap/buildComponentMap/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\n\nexport type CollapsibleFieldProps = FormFieldBase & {\n fieldMap: FieldMap\n initCollapsed?: boolean\n label?: FieldBase['label']\n permissions: FieldPermissions\n width?: string\n}\n\nconst CollapsibleField: React.FC<CollapsibleFieldProps> = (props) => {\n const {\n CustomDescription,\n CustomLabel,\n className,\n descriptionProps,\n fieldMap,\n initCollapsed = false,\n labelProps,\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n } = props\n\n const {\n indexPath,\n path: pathFromContext,\n readOnly: readOnlyFromContext,\n schemaPath,\n siblingPermissions,\n } = useFieldProps()\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) => {\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 readOnly = readOnlyFromProps || readOnlyFromContext\n\n return (\n <Fragment>\n <WatchChildErrors fieldMap={fieldMap} 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 RowLabelComponent={CustomLabel}\n i18n={i18n}\n path={path}\n rowLabel={labelProps.label}\n />\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n }\n initCollapsed={collapsedOnMount}\n onToggle={onToggle}\n >\n <RenderFields\n fieldMap={fieldMap}\n forceRender\n indexPath={indexPath}\n margins=\"small\"\n path={path}\n permissions={siblingPermissions}\n readOnly={readOnly}\n schemaPath={schemaPath}\n />\n </CollapsibleElement>\n <FieldDescription CustomDescription={CustomDescription} {...(descriptionProps || {})} />\n </div>\n </Fragment>\n )\n}\n\nexport const Collapsible = withCondition(CollapsibleField)\n"],"names":["React","Fragment","useCallback","useEffect","useState","Collapsible","CollapsibleElement","ErrorPill","useFieldProps","RenderFields","RowLabel","WatchChildErrors","withCondition","useDocumentInfo","usePreferences","useTranslation","fieldBaseClass","baseClass","FieldDescription","CollapsibleField","props","CustomDescription","CustomLabel","className","descriptionProps","fieldMap","initCollapsed","labelProps","path","pathFromProps","readOnly","readOnlyFromProps","indexPath","pathFromContext","readOnlyFromContext","schemaPath","siblingPermissions","i18n","getPreference","setPreference","preferencesKey","collapsedOnMount","setCollapsedOnMount","fieldPreferencesKey","replace","errorCount","setErrorCount","fieldHasErrors","onToggle","newCollapsedState","existingPreferences","fields","collapsed","fetchInitialState","preferences","specificPreference","undefined","Boolean","div","filter","join","id","collapsibleStyle","header","RowLabelComponent","rowLabel","label","count","withMessage","forceRender","margins","permissions"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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MAAM,oBAAoB,CAAA;AAWvD,OAAO,cAAc,CAAA;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAI5C,OAAO,EAAE,YAAY,EAAE,CAAA;AAEvB,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG;IAC3C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,gBAAgB,CAAA;IAC7B,IAAI,CAAC,EAAE,SAAS,EAAE,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Tabs/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAMpD,OAAO,KAA2C,MAAM,OAAO,CAAA;AAE/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yDAAyD,CAAA;AACxF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAWvD,OAAO,cAAc,CAAA;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAI5C,OAAO,EAAE,YAAY,EAAE,CAAA;AAEvB,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG;IAC3C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,gBAAgB,CAAA;IAC7B,IAAI,CAAC,EAAE,SAAS,EAAE,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAwJD,eAAO,MAAM,IAAI,0BAA2B,CAAA"}
|
|
@@ -27,12 +27,14 @@ const TabsField = (props)=>{
|
|
|
27
27
|
const [activeTabIndex, setActiveTabIndex] = useState(0);
|
|
28
28
|
const tabsPrefKey = `tabs-${indexPath}`;
|
|
29
29
|
useEffect(()=>{
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
if (preferencesKey) {
|
|
31
|
+
const getInitialPref = async ()=>{
|
|
32
|
+
const existingPreferences = await getPreference(preferencesKey);
|
|
33
|
+
const initialIndex = path ? existingPreferences?.fields?.[path]?.tabIndex : existingPreferences?.fields?.[tabsPrefKey]?.tabIndex;
|
|
34
|
+
setActiveTabIndex(initialIndex || 0);
|
|
35
|
+
};
|
|
36
|
+
void getInitialPref();
|
|
37
|
+
}
|
|
36
38
|
}, [
|
|
37
39
|
path,
|
|
38
40
|
getPreference,
|
|
@@ -42,26 +44,28 @@ const TabsField = (props)=>{
|
|
|
42
44
|
const handleTabChange = useCallback(async (incomingTabIndex)=>{
|
|
43
45
|
setActiveTabIndex(incomingTabIndex);
|
|
44
46
|
const existingPreferences = await getPreference(preferencesKey);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
if (preferencesKey) {
|
|
48
|
+
void setPreference(preferencesKey, {
|
|
49
|
+
...existingPreferences,
|
|
50
|
+
...path ? {
|
|
51
|
+
fields: {
|
|
52
|
+
...existingPreferences?.fields || {},
|
|
53
|
+
[path]: {
|
|
54
|
+
...existingPreferences?.fields?.[path],
|
|
55
|
+
tabIndex: incomingTabIndex
|
|
56
|
+
}
|
|
53
57
|
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
} : {
|
|
59
|
+
fields: {
|
|
60
|
+
...existingPreferences?.fields,
|
|
61
|
+
[tabsPrefKey]: {
|
|
62
|
+
...existingPreferences?.fields?.[tabsPrefKey],
|
|
63
|
+
tabIndex: incomingTabIndex
|
|
64
|
+
}
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
65
69
|
}, [
|
|
66
70
|
preferencesKey,
|
|
67
71
|
getPreference,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/Tabs/index.tsx"],"sourcesContent":["'use client'\nimport type { FieldPermissions } from 'payload/auth'\nimport type { DocumentPreferences } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { FieldDescription } from '@payloadcms/ui/forms/FieldDescription'\nimport { toKebabCase } from 'payload/utilities'\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport type { MappedTab } from '../../providers/ComponentMap/buildComponentMap/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { useCollapsible } from '../../elements/Collapsible/provider.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { RenderFields } from '../../forms/RenderFields/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 { TabComponent } from './Tab/index.js'\nimport './index.scss'\nimport { TabsProvider } from './provider.js'\n\nconst baseClass = 'tabs-field'\n\nexport { TabsProvider }\n\nexport type TabsFieldProps = FormFieldBase & {\n forceRender?: boolean\n name?: string\n path?: string\n permissions: FieldPermissions\n tabs?: MappedTab[]\n width?: string\n}\n\nconst TabsField: React.FC<TabsFieldProps> = (props) => {\n const {\n name,\n CustomDescription,\n className,\n descriptionProps,\n forceRender = false,\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n tabs = [],\n } = props\n\n const {\n indexPath,\n path: pathFromContext,\n permissions,\n readOnly: readOnlyFromContext,\n schemaPath,\n } = useFieldProps()\n const readOnly = readOnlyFromProps || readOnlyFromContext\n const path = pathFromContext || pathFromProps || name\n const { getPreference, setPreference } = usePreferences()\n const { preferencesKey } = useDocumentInfo()\n const { i18n } = useTranslation()\n const { isWithinCollapsible } = useCollapsible()\n const [activeTabIndex, setActiveTabIndex] = useState<number>(0)\n const tabsPrefKey = `tabs-${indexPath}`\n\n useEffect(() => {\n const getInitialPref = async () => {\n const existingPreferences: DocumentPreferences = await getPreference(preferencesKey)\n const initialIndex = path\n ? existingPreferences?.fields?.[path]?.tabIndex\n : existingPreferences?.fields?.[tabsPrefKey]?.tabIndex\n setActiveTabIndex(initialIndex || 0)\n }\n void getInitialPref()\n }, [path, getPreference, preferencesKey, tabsPrefKey])\n\n const handleTabChange = useCallback(\n async (incomingTabIndex: number) => {\n setActiveTabIndex(incomingTabIndex)\n\n const existingPreferences: DocumentPreferences = await getPreference(preferencesKey)\n\n void setPreference(preferencesKey, {\n ...existingPreferences,\n ...(path\n ? {\n fields: {\n ...(existingPreferences?.fields || {}),\n [path]: {\n ...existingPreferences?.fields?.[path],\n tabIndex: incomingTabIndex,\n },\n },\n }\n : {\n fields: {\n ...existingPreferences?.fields,\n [tabsPrefKey]: {\n ...existingPreferences?.fields?.[tabsPrefKey],\n tabIndex: incomingTabIndex,\n },\n },\n }),\n })\n },\n [preferencesKey, getPreference, setPreference, path, tabsPrefKey],\n )\n\n const activeTabConfig = tabs[activeTabIndex]\n\n return (\n <div\n className={[\n fieldBaseClass,\n className,\n baseClass,\n isWithinCollapsible && `${baseClass}--within-collapsible`,\n ]\n .filter(Boolean)\n .join(' ')}\n >\n <TabsProvider>\n <div className={`${baseClass}__tabs-wrap`}>\n <div className={`${baseClass}__tabs`}>\n {tabs.map((tab, tabIndex) => {\n return (\n <TabComponent\n isActive={activeTabIndex === tabIndex}\n key={tabIndex}\n parentPath={path}\n setIsActive={() => handleTabChange(tabIndex)}\n tab={tab}\n />\n )\n })}\n </div>\n </div>\n <div className={`${baseClass}__content-wrap`}>\n {activeTabConfig && (\n <React.Fragment>\n <div\n className={[\n `${baseClass}__tab`,\n activeTabConfig.label &&\n `${baseClass}__tabConfigLabel-${toKebabCase(\n getTranslation(activeTabConfig.label, i18n),\n )}`,\n ]\n .filter(Boolean)\n .join(' ')}\n >\n {CustomDescription ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n <RenderFields\n fieldMap={activeTabConfig.fieldMap}\n forceRender={forceRender}\n key={\n activeTabConfig.label\n ? getTranslation(activeTabConfig.label, i18n)\n : activeTabConfig['name']\n }\n margins=\"small\"\n path={`${path ? `${path}.` : ''}${activeTabConfig.name ? `${activeTabConfig.name}` : ''}`}\n permissions={\n 'name' in activeTabConfig && permissions?.fields?.[activeTabConfig.name]?.fields\n ? permissions?.fields?.[activeTabConfig.name]?.fields\n : permissions?.fields\n }\n readOnly={readOnly}\n schemaPath={`${schemaPath ? `${schemaPath}` : ''}${activeTabConfig.name ? `.${activeTabConfig.name}` : ''}`}\n />\n </div>\n </React.Fragment>\n )}\n </div>\n </TabsProvider>\n </div>\n )\n}\n\nexport const Tabs = withCondition(TabsField)\n"],"names":["getTranslation","FieldDescription","toKebabCase","React","useCallback","useEffect","useState","useCollapsible","useFieldProps","RenderFields","withCondition","useDocumentInfo","usePreferences","useTranslation","fieldBaseClass","TabComponent","TabsProvider","baseClass","TabsField","props","name","CustomDescription","className","descriptionProps","forceRender","path","pathFromProps","readOnly","readOnlyFromProps","tabs","indexPath","pathFromContext","permissions","readOnlyFromContext","schemaPath","getPreference","setPreference","preferencesKey","i18n","isWithinCollapsible","activeTabIndex","setActiveTabIndex","tabsPrefKey","getInitialPref","existingPreferences","initialIndex","fields","tabIndex","handleTabChange","incomingTabIndex","activeTabConfig","div","filter","Boolean","join","map","tab","isActive","key","parentPath","setIsActive","Fragment","label","fieldMap","margins","Tabs"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAA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client'\nimport type { FieldPermissions } from 'payload/auth'\nimport type { DocumentPreferences } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { FieldDescription } from '@payloadcms/ui/forms/FieldDescription'\nimport { toKebabCase } from 'payload/utilities'\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport type { MappedTab } from '../../providers/ComponentMap/buildComponentMap/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { useCollapsible } from '../../elements/Collapsible/provider.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { RenderFields } from '../../forms/RenderFields/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 { TabComponent } from './Tab/index.js'\nimport './index.scss'\nimport { TabsProvider } from './provider.js'\n\nconst baseClass = 'tabs-field'\n\nexport { TabsProvider }\n\nexport type TabsFieldProps = FormFieldBase & {\n forceRender?: boolean\n name?: string\n path?: string\n permissions: FieldPermissions\n tabs?: MappedTab[]\n width?: string\n}\n\nconst TabsField: React.FC<TabsFieldProps> = (props) => {\n const {\n name,\n CustomDescription,\n className,\n descriptionProps,\n forceRender = false,\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n tabs = [],\n } = props\n\n const {\n indexPath,\n path: pathFromContext,\n permissions,\n readOnly: readOnlyFromContext,\n schemaPath,\n } = useFieldProps()\n const readOnly = readOnlyFromProps || readOnlyFromContext\n const path = pathFromContext || pathFromProps || name\n const { getPreference, setPreference } = usePreferences()\n const { preferencesKey } = useDocumentInfo()\n const { i18n } = useTranslation()\n const { isWithinCollapsible } = useCollapsible()\n const [activeTabIndex, setActiveTabIndex] = useState<number>(0)\n const tabsPrefKey = `tabs-${indexPath}`\n\n useEffect(() => {\n if (preferencesKey) {\n const getInitialPref = async () => {\n const existingPreferences: DocumentPreferences = await getPreference(preferencesKey)\n const initialIndex = path\n ? existingPreferences?.fields?.[path]?.tabIndex\n : existingPreferences?.fields?.[tabsPrefKey]?.tabIndex\n setActiveTabIndex(initialIndex || 0)\n }\n void getInitialPref()\n }\n }, [path, getPreference, preferencesKey, tabsPrefKey])\n\n const handleTabChange = useCallback(\n async (incomingTabIndex: number) => {\n setActiveTabIndex(incomingTabIndex)\n\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 tabIndex: incomingTabIndex,\n },\n },\n }\n : {\n fields: {\n ...existingPreferences?.fields,\n [tabsPrefKey]: {\n ...existingPreferences?.fields?.[tabsPrefKey],\n tabIndex: incomingTabIndex,\n },\n },\n }),\n })\n }\n },\n [preferencesKey, getPreference, setPreference, path, tabsPrefKey],\n )\n\n const activeTabConfig = tabs[activeTabIndex]\n\n return (\n <div\n className={[\n fieldBaseClass,\n className,\n baseClass,\n isWithinCollapsible && `${baseClass}--within-collapsible`,\n ]\n .filter(Boolean)\n .join(' ')}\n >\n <TabsProvider>\n <div className={`${baseClass}__tabs-wrap`}>\n <div className={`${baseClass}__tabs`}>\n {tabs.map((tab, tabIndex) => {\n return (\n <TabComponent\n isActive={activeTabIndex === tabIndex}\n key={tabIndex}\n parentPath={path}\n setIsActive={() => handleTabChange(tabIndex)}\n tab={tab}\n />\n )\n })}\n </div>\n </div>\n <div className={`${baseClass}__content-wrap`}>\n {activeTabConfig && (\n <React.Fragment>\n <div\n className={[\n `${baseClass}__tab`,\n activeTabConfig.label &&\n `${baseClass}__tabConfigLabel-${toKebabCase(\n getTranslation(activeTabConfig.label, i18n),\n )}`,\n ]\n .filter(Boolean)\n .join(' ')}\n >\n {CustomDescription ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n <RenderFields\n fieldMap={activeTabConfig.fieldMap}\n forceRender={forceRender}\n key={\n activeTabConfig.label\n ? getTranslation(activeTabConfig.label, i18n)\n : activeTabConfig['name']\n }\n margins=\"small\"\n path={`${path ? `${path}.` : ''}${activeTabConfig.name ? `${activeTabConfig.name}` : ''}`}\n permissions={\n 'name' in activeTabConfig && permissions?.fields?.[activeTabConfig.name]?.fields\n ? permissions?.fields?.[activeTabConfig.name]?.fields\n : permissions?.fields\n }\n readOnly={readOnly}\n schemaPath={`${schemaPath ? `${schemaPath}` : ''}${activeTabConfig.name ? `.${activeTabConfig.name}` : ''}`}\n />\n </div>\n </React.Fragment>\n )}\n </div>\n </TabsProvider>\n </div>\n )\n}\n\nexport const Tabs = withCondition(TabsField)\n"],"names":["getTranslation","FieldDescription","toKebabCase","React","useCallback","useEffect","useState","useCollapsible","useFieldProps","RenderFields","withCondition","useDocumentInfo","usePreferences","useTranslation","fieldBaseClass","TabComponent","TabsProvider","baseClass","TabsField","props","name","CustomDescription","className","descriptionProps","forceRender","path","pathFromProps","readOnly","readOnlyFromProps","tabs","indexPath","pathFromContext","permissions","readOnlyFromContext","schemaPath","getPreference","setPreference","preferencesKey","i18n","isWithinCollapsible","activeTabIndex","setActiveTabIndex","tabsPrefKey","getInitialPref","existingPreferences","initialIndex","fields","tabIndex","handleTabChange","incomingTabIndex","activeTabConfig","div","filter","Boolean","join","map","tab","isActive","key","parentPath","setIsActive","Fragment","label","fieldMap","margins","Tabs"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAIA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,WAAW,QAAQ,oBAAmB;AAC/C,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;A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|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"webpack": "^5.78.0",
|
|
108
108
|
"webpack-cli": "^5.1.4",
|
|
109
109
|
"@payloadcms/eslint-config": "1.1.1",
|
|
110
|
-
"payload": "3.0.0-beta.
|
|
110
|
+
"payload": "3.0.0-beta.2"
|
|
111
111
|
},
|
|
112
112
|
"dependencies": {
|
|
113
113
|
"@dnd-kit/core": "6.0.8",
|
|
@@ -131,12 +131,12 @@
|
|
|
131
131
|
"react-toastify": "10.0.4",
|
|
132
132
|
"use-context-selector": "1.4.1",
|
|
133
133
|
"uuid": "9.0.1",
|
|
134
|
-
"@payloadcms/translations": "3.0.0-beta.
|
|
134
|
+
"@payloadcms/translations": "3.0.0-beta.2"
|
|
135
135
|
},
|
|
136
136
|
"peerDependencies": {
|
|
137
137
|
"next": "14.2.0-canary.23",
|
|
138
138
|
"react": "^18.0.0",
|
|
139
|
-
"payload": "3.0.0-beta.
|
|
139
|
+
"payload": "3.0.0-beta.2"
|
|
140
140
|
},
|
|
141
141
|
"engines": {
|
|
142
142
|
"node": ">=18.17.0"
|