@payloadcms/ui 3.76.0-canary.4 → 3.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/elements/Button/index.js +1 -1
- package/dist/elements/Button/index.js.map +1 -1
- package/dist/elements/Link/index.d.ts.map +1 -1
- package/dist/elements/ReactSelect/index.js +1 -1
- package/dist/elements/ReactSelect/index.js.map +1 -1
- package/dist/elements/Thumbnail/createThumbnail.js +2 -2
- package/dist/elements/Thumbnail/createThumbnail.js.map +1 -1
- package/dist/exports/client/{DatePicker-GT6CXMEH.js → DatePicker-YF5TBW3N.js} +2 -2
- package/dist/exports/client/chunk-ZPLD37T2.js +29 -0
- package/dist/exports/client/{chunk-USMS5YRL.js.map → chunk-ZPLD37T2.js.map} +4 -4
- package/dist/exports/client/index.js +2 -2
- package/dist/exports/client/index.js.map +3 -3
- package/dist/fields/Number/index.js +1 -1
- package/dist/fields/Number/index.js.map +1 -1
- package/dist/fields/Text/index.js +1 -1
- package/dist/fields/Text/index.js.map +1 -1
- package/dist/fields/shared/index.js +1 -1
- package/dist/fields/shared/index.js.map +1 -1
- package/dist/forms/Form/reduceToSerializableFields.js +1 -1
- package/dist/forms/Form/reduceToSerializableFields.js.map +1 -1
- package/dist/forms/WatchChildErrors/index.d.ts.map +1 -1
- package/dist/forms/WatchChildErrors/index.js +2 -1
- package/dist/forms/WatchChildErrors/index.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/isRowCollapsed.js +1 -1
- package/dist/forms/fieldSchemasToFormState/isRowCollapsed.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.js +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.js.map +1 -1
- package/dist/hooks/useQueue.js +1 -1
- package/dist/hooks/useQueue.js.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/index.js +2 -2
- package/dist/providers/TableColumns/buildColumnState/index.js.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/renderCell.js +1 -1
- package/dist/providers/TableColumns/buildColumnState/renderCell.js.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/traverseFields.js +1 -1
- package/dist/utilities/buildFieldSchemaMap/traverseFields.js.map +1 -1
- package/dist/utilities/getDisplayedFieldValue.js +3 -3
- package/dist/utilities/getDisplayedFieldValue.js.map +1 -1
- package/dist/utilities/isURLAllowed.js +2 -2
- package/dist/utilities/isURLAllowed.js.map +1 -1
- package/dist/views/Edit/index.js +2 -2
- package/dist/views/Edit/index.js.map +1 -1
- package/package.json +6 -6
- package/dist/exports/client/chunk-USMS5YRL.js +0 -29
- /package/dist/exports/client/{DatePicker-GT6CXMEH.js.map → DatePicker-YF5TBW3N.js.map} +0 -0
|
@@ -81,7 +81,7 @@ const NumberFieldComponent = props => {
|
|
|
81
81
|
setValue(newVal);
|
|
82
82
|
}, [onChangeFromProps, setValue]);
|
|
83
83
|
const [valueToRender, setValueToRender] = useState([]) // Only for hasMany
|
|
84
|
-
|
|
84
|
+
;
|
|
85
85
|
const handleHasManyChange = useCallback(selectedOption => {
|
|
86
86
|
if (!(readOnly || disabled)) {
|
|
87
87
|
let newValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["getTranslation","isNumber","React","useCallback","useEffect","useMemo","useState","ReactSelect","RenderCustomComponent","useField","withCondition","useTranslation","FieldDescription","FieldError","FieldLabel","mergeFieldStyles","fieldBaseClass","NumberFieldComponent","props","field","admin","className","description","placeholder","placeholderFromProps","step","hasMany","label","localized","max","Infinity","maxRows","min","required","onChange","onChangeFromProps","path","pathFromProps","readOnly","validate","i18n","t","memoizedValidate","value","options","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","setValue","showError","potentiallyStalePath","handleChange","e","val","parseFloat","target","newVal","Number","isNaN","valueToRender","setValueToRender","handleHasManyChange","selectedOption","newValue","Array","isArray","map","option","index","id","toString","styles","_jsxs","filter","Boolean","join","style","_jsx","CustomComponent","Fallback","replace","filterOption","_","rawInput","isOverHasMany","length","isClearable","isCreatable","isMulti","isSortable","noOptionsMessage","name","onWheel","blur","type","NumberField"],"sources":["../../../src/fields/Number/index.tsx"],"sourcesContent":["'use client'\nimport type { NumberFieldClientComponent, NumberFieldClientProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { isNumber } from 'payload/shared'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport type { Option } from '../../elements/ReactSelect/types.js'\n\nimport { ReactSelect } from '../../elements/ReactSelect/index.js'\nimport { RenderCustomComponent } from '../../elements/RenderCustomComponent/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { FieldError } from '../FieldError/index.js'\nimport { FieldLabel } from '../FieldLabel/index.js'\nimport { mergeFieldStyles } from '../mergeFieldStyles.js'\nimport './index.scss'\nimport { fieldBaseClass } from '../shared/index.js'\n\nconst NumberFieldComponent: NumberFieldClientComponent = (props) => {\n const {\n field,\n field: {\n admin: {\n className,\n description,\n placeholder: placeholderFromProps,\n step = 1,\n } = {} as NumberFieldClientProps['field']['admin'],\n hasMany = false,\n label,\n localized,\n max = Infinity,\n maxRows = Infinity,\n min = -Infinity,\n required,\n },\n onChange: onChangeFromProps,\n path: pathFromProps,\n readOnly,\n validate,\n } = props\n\n const { i18n, t } = useTranslation()\n\n const memoizedValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function') {\n return validate(value, { ...options, max, min, required })\n }\n },\n [validate, min, max, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled,\n path,\n setValue,\n showError,\n value,\n } = useField<number | number[]>({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const handleChange = useCallback(\n (e) => {\n const val = parseFloat(e.target.value)\n let newVal = val\n\n if (Number.isNaN(val)) {\n newVal = null\n }\n\n if (typeof onChangeFromProps === 'function') {\n onChangeFromProps(newVal)\n }\n\n setValue(newVal)\n },\n [onChangeFromProps, setValue],\n )\n\n const [valueToRender, setValueToRender] = useState<\n { id: string; label: string; value: { value: number } }[]\n >([]) // Only for hasMany\n\n const handleHasManyChange = useCallback(\n (selectedOption) => {\n if (!(readOnly || disabled)) {\n let newValue\n if (!selectedOption) {\n newValue = []\n } else if (Array.isArray(selectedOption)) {\n newValue = selectedOption.map((option) => Number(option.value?.value || option.value))\n } else {\n newValue = [Number(selectedOption.value?.value || selectedOption.value)]\n }\n\n setValue(newValue)\n }\n },\n [readOnly, disabled, setValue],\n )\n\n // useEffect update valueToRender:\n useEffect(() => {\n if (hasMany && Array.isArray(value)) {\n setValueToRender(\n value.map((val, index) => {\n return {\n id: `${val}${index}`, // append index to avoid duplicate keys but allow duplicate numbers\n label: `${val}`,\n value: {\n toString: () => `${val}${index}`,\n value: (val as unknown as Record<string, number>)?.value || val,\n }, // You're probably wondering, why the hell is this done that way? Well, React-select automatically uses \"label-value\" as a key, so we will get that react duplicate key warning if we just pass in the value as multiple values can be the same. So we need to append the index to the toString() of the value to avoid that warning, as it uses that as the key.\n }\n }),\n )\n }\n }, [value, hasMany])\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n const placeholder = getTranslation(placeholderFromProps, i18n)\n\n return (\n <div\n className={[\n fieldBaseClass,\n 'number',\n className,\n showError && 'error',\n (readOnly || disabled) && 'read-only',\n hasMany && 'has-many',\n ]\n .filter(Boolean)\n .join(' ')}\n style={styles}\n >\n <RenderCustomComponent\n CustomComponent={Label}\n Fallback={\n <FieldLabel label={label} localized={localized} path={path} required={required} />\n }\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n {BeforeInput}\n {hasMany ? (\n <ReactSelect\n className={`field-${path.replace(/\\./g, '__')}`}\n disabled={readOnly || disabled}\n filterOption={(_, rawInput) => {\n const isOverHasMany = Array.isArray(value) && value.length >= maxRows\n return isNumber(rawInput) && !isOverHasMany\n }}\n isClearable\n isCreatable\n isMulti\n isSortable\n noOptionsMessage={() => {\n const isOverHasMany = Array.isArray(value) && value.length >= maxRows\n if (isOverHasMany) {\n return t('validation:limitReached', { max: maxRows, value: value.length + 1 })\n }\n return null\n }}\n // numberOnly\n onChange={handleHasManyChange}\n options={[]}\n placeholder={placeholder}\n showError={showError}\n value={valueToRender as Option[]}\n />\n ) : (\n <div>\n <input\n disabled={readOnly || disabled}\n id={`field-${path.replace(/\\./g, '__')}`}\n max={max}\n min={min}\n name={path}\n onChange={handleChange}\n onWheel={(e) => {\n // @ts-expect-error\n e.target.blur()\n }}\n placeholder={placeholder}\n step={step}\n type=\"number\"\n value={typeof value === 'number' ? value : ''}\n />\n </div>\n )}\n {AfterInput}\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n </div>\n )\n}\n\nexport const NumberField = withCondition(NumberFieldComponent)\n"],"mappings":"AAAA;;;AAGA,SAASA,cAAc,QAAQ;AAC/B,SAASC,QAAQ,QAAQ;AACzB,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AAIjE,SAASC,WAAW,QAAQ;AAC5B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,QAAQ,QAAQ;AACzB,SAASC,aAAa,QAAQ;AAC9B,SAASC,cAAc,QAAQ;AAC/B,SAASC,gBAAgB,QAAQ;AACjC,SAASC,UAAU,QAAQ;AAC3B,SAASC,UAAU,QAAQ;AAC3B,SAASC,gBAAgB,QAAQ;AACjC,OAAO;AACP,SAASC,cAAc,QAAQ;AAE/B,MAAMC,oBAAA,GAAoDC,KAAA;EACxD,MAAM;IACJC,KAAK;IACLA,KAAA,EAAO;MACLC,KAAA,EAAO;QACLC,SAAS;QACTC,WAAW;QACXC,WAAA,EAAaC,oBAAoB;QACjCC,IAAA,GAAO;MAAC,CACT,GAAG,CA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AAO,CAAC1B,OAAA,KAAUA,OAAA,CAAM8C,MAAM,IAAI1D,OAAA;UAC9D,IAAIyD,eAAA,EAAe;YACjB,OAAO/C,CAAA,CAAE,2BAA2B;cAAEZ,GAAA,EAAKE,OAAA;cAASY,KAAA,EAAOA,OAAA,CAAM8C,MAAM,GAAG;YAAE;UAC9E;UACA,OAAO;QACT;QACA;QACAvD,QAAA,EAAU+B,mBAAA;QACVrB,OAAA,EAAS,EAAE;QACXrB,WAAA,EAAaA,WAAA;QACb8B,SAAA,EAAWA,SAAA;QACXV,KAAA,EAAOoB;wBAGTkB,IAAA,CAAC;kBACC,aAAAA,IAAA,CAAC;UACC9B,QAAA,EAAUb,QAAA,IAAYa,QAAA;UACtBsB,EAAA,EAAI,SAASrC,IAAA,CAAKgD,OAAO,CAAC,OAAO,OAAO;UACxCvD,GAAA,EAAKA,GAAA;UACLG,GAAA,EAAKA,GAAA;UACL+D,IAAA,EAAM3D,IAAA;UACNF,QAAA,EAAUqB,YAAA;UACVyC,OAAA,EAAUxC,GAAA;YACR;YACAA,GAAA,CAAEG,MAAM,CAACsC,IAAI;UACf;UACA1E,WAAA,EAAaA,WAAA;UACbE,IAAA,EAAMA,IAAA;UACNyE,IAAA,EAAK;UACLvD,KAAA,EAAO,OAAOA,OAAA,KAAU,WAAWA,OAAA,GAAQ;;UAIhDG,UAAA,E,aACDmC,IAAA,CAACzE,qBAAA;QACC0E,eAAA,EAAiBlC,WAAA;QACjBmC,QAAA,eAAUF,IAAA,CAACrE,gBAAA;UAAiBU,WAAA,EAAaA,WAAA;UAAac,IAAA,EAAMA;;;;;AAKtE;AAEA,OAAO,MAAM+D,WAAA,GAAczF,aAAA,CAAcO,oBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["getTranslation","isNumber","React","useCallback","useEffect","useMemo","useState","ReactSelect","RenderCustomComponent","useField","withCondition","useTranslation","FieldDescription","FieldError","FieldLabel","mergeFieldStyles","fieldBaseClass","NumberFieldComponent","props","field","admin","className","description","placeholder","placeholderFromProps","step","hasMany","label","localized","max","Infinity","maxRows","min","required","onChange","onChangeFromProps","path","pathFromProps","readOnly","validate","i18n","t","memoizedValidate","value","options","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","setValue","showError","potentiallyStalePath","handleChange","e","val","parseFloat","target","newVal","Number","isNaN","valueToRender","setValueToRender","handleHasManyChange","selectedOption","newValue","Array","isArray","map","option","index","id","toString","styles","_jsxs","filter","Boolean","join","style","_jsx","CustomComponent","Fallback","replace","filterOption","_","rawInput","isOverHasMany","length","isClearable","isCreatable","isMulti","isSortable","noOptionsMessage","name","onWheel","blur","type","NumberField"],"sources":["../../../src/fields/Number/index.tsx"],"sourcesContent":["'use client'\nimport type { NumberFieldClientComponent, NumberFieldClientProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { isNumber } from 'payload/shared'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport type { Option } from '../../elements/ReactSelect/types.js'\n\nimport { ReactSelect } from '../../elements/ReactSelect/index.js'\nimport { RenderCustomComponent } from '../../elements/RenderCustomComponent/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { FieldError } from '../FieldError/index.js'\nimport { FieldLabel } from '../FieldLabel/index.js'\nimport { mergeFieldStyles } from '../mergeFieldStyles.js'\nimport './index.scss'\nimport { fieldBaseClass } from '../shared/index.js'\n\nconst NumberFieldComponent: NumberFieldClientComponent = (props) => {\n const {\n field,\n field: {\n admin: {\n className,\n description,\n placeholder: placeholderFromProps,\n step = 1,\n } = {} as NumberFieldClientProps['field']['admin'],\n hasMany = false,\n label,\n localized,\n max = Infinity,\n maxRows = Infinity,\n min = -Infinity,\n required,\n },\n onChange: onChangeFromProps,\n path: pathFromProps,\n readOnly,\n validate,\n } = props\n\n const { i18n, t } = useTranslation()\n\n const memoizedValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function') {\n return validate(value, { ...options, max, min, required })\n }\n },\n [validate, min, max, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled,\n path,\n setValue,\n showError,\n value,\n } = useField<number | number[]>({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const handleChange = useCallback(\n (e) => {\n const val = parseFloat(e.target.value)\n let newVal = val\n\n if (Number.isNaN(val)) {\n newVal = null\n }\n\n if (typeof onChangeFromProps === 'function') {\n onChangeFromProps(newVal)\n }\n\n setValue(newVal)\n },\n [onChangeFromProps, setValue],\n )\n\n const [valueToRender, setValueToRender] = useState<\n { id: string; label: string; value: { value: number } }[]\n >([]) // Only for hasMany\n\n const handleHasManyChange = useCallback(\n (selectedOption) => {\n if (!(readOnly || disabled)) {\n let newValue\n if (!selectedOption) {\n newValue = []\n } else if (Array.isArray(selectedOption)) {\n newValue = selectedOption.map((option) => Number(option.value?.value || option.value))\n } else {\n newValue = [Number(selectedOption.value?.value || selectedOption.value)]\n }\n\n setValue(newValue)\n }\n },\n [readOnly, disabled, setValue],\n )\n\n // useEffect update valueToRender:\n useEffect(() => {\n if (hasMany && Array.isArray(value)) {\n setValueToRender(\n value.map((val, index) => {\n return {\n id: `${val}${index}`, // append index to avoid duplicate keys but allow duplicate numbers\n label: `${val}`,\n value: {\n toString: () => `${val}${index}`,\n value: (val as unknown as Record<string, number>)?.value || val,\n }, // You're probably wondering, why the hell is this done that way? Well, React-select automatically uses \"label-value\" as a key, so we will get that react duplicate key warning if we just pass in the value as multiple values can be the same. So we need to append the index to the toString() of the value to avoid that warning, as it uses that as the key.\n }\n }),\n )\n }\n }, [value, hasMany])\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n const placeholder = getTranslation(placeholderFromProps, i18n)\n\n return (\n <div\n className={[\n fieldBaseClass,\n 'number',\n className,\n showError && 'error',\n (readOnly || disabled) && 'read-only',\n hasMany && 'has-many',\n ]\n .filter(Boolean)\n .join(' ')}\n style={styles}\n >\n <RenderCustomComponent\n CustomComponent={Label}\n Fallback={\n <FieldLabel label={label} localized={localized} path={path} required={required} />\n }\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n {BeforeInput}\n {hasMany ? (\n <ReactSelect\n className={`field-${path.replace(/\\./g, '__')}`}\n disabled={readOnly || disabled}\n filterOption={(_, rawInput) => {\n const isOverHasMany = Array.isArray(value) && value.length >= maxRows\n return isNumber(rawInput) && !isOverHasMany\n }}\n isClearable\n isCreatable\n isMulti\n isSortable\n noOptionsMessage={() => {\n const isOverHasMany = Array.isArray(value) && value.length >= maxRows\n if (isOverHasMany) {\n return t('validation:limitReached', { max: maxRows, value: value.length + 1 })\n }\n return null\n }}\n // numberOnly\n onChange={handleHasManyChange}\n options={[]}\n placeholder={placeholder}\n showError={showError}\n value={valueToRender as Option[]}\n />\n ) : (\n <div>\n <input\n disabled={readOnly || disabled}\n id={`field-${path.replace(/\\./g, '__')}`}\n max={max}\n min={min}\n name={path}\n onChange={handleChange}\n onWheel={(e) => {\n // @ts-expect-error\n e.target.blur()\n }}\n placeholder={placeholder}\n step={step}\n type=\"number\"\n value={typeof value === 'number' ? value : ''}\n />\n </div>\n )}\n {AfterInput}\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n </div>\n )\n}\n\nexport const NumberField = withCondition(NumberFieldComponent)\n"],"mappings":"AAAA;;;AAGA,SAASA,cAAc,QAAQ;AAC/B,SAASC,QAAQ,QAAQ;AACzB,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AAIjE,SAASC,WAAW,QAAQ;AAC5B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,QAAQ,QAAQ;AACzB,SAASC,aAAa,QAAQ;AAC9B,SAASC,cAA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C,WAAA;QACjBmC,QAAA,eAAUF,IAAA,CAACrE,gBAAA;UAAiBU,WAAA,EAAaA,WAAA;UAAac,IAAA,EAAMA;;;;;AAKtE;AAEA,OAAO,MAAM+D,WAAA,GAAczF,aAAA,CAAcO,oBAAA","ignoreList":[]}
|
|
@@ -76,7 +76,7 @@ const TextFieldComponent = props => {
|
|
|
76
76
|
localizationConfig: localizationConfig || undefined
|
|
77
77
|
});
|
|
78
78
|
const [valueToRender, setValueToRender] = useState([]) // Only for hasMany
|
|
79
|
-
|
|
79
|
+
;
|
|
80
80
|
const handleHasManyChange = useCallback(selectedOption => {
|
|
81
81
|
if (!(readOnly || disabled)) {
|
|
82
82
|
let newValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","useCallback","useEffect","useMemo","useState","useField","withCondition","useConfig","useLocale","mergeFieldStyles","isFieldRTL","TextInput","TextFieldComponent","props","field","admin","autoComplete","className","description","placeholder","rtl","hasMany","label","localized","maxLength","maxRows","minLength","minRows","required","inputRef","path","pathFromProps","readOnly","validate","locale","config","localization","localizationConfig","memoizedValidate","value","options","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","setValue","showError","potentiallyStalePath","renderRTL","fieldLocalized","fieldRTL","undefined","valueToRender","setValueToRender","handleHasManyChange","selectedOption","newValue","Array","isArray","map","option","val","index","id","toString","styles","_jsx","htmlAttributes","onChange","e","target","style","TextField"],"sources":["../../../src/fields/Text/index.tsx"],"sourcesContent":["'use client'\nimport type { TextFieldClientComponent } from 'payload'\n\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport type { Option } from '../../elements/ReactSelect/types.js'\nimport type { TextInputProps } from './types.js'\n\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { mergeFieldStyles } from '../mergeFieldStyles.js'\nimport { isFieldRTL } from '../shared/index.js'\nimport { TextInput } from './Input.js'\nimport './index.scss'\n\nexport { TextInput, TextInputProps }\n\nconst TextFieldComponent: TextFieldClientComponent = (props) => {\n const {\n field,\n field: {\n admin: { autoComplete, className, description, placeholder, rtl } = {},\n hasMany,\n label,\n localized,\n maxLength,\n maxRows,\n minLength,\n minRows,\n required,\n },\n inputRef,\n path: pathFromProps,\n readOnly,\n validate,\n } = props\n\n const locale = useLocale()\n\n const {\n config: { localization: localizationConfig },\n } = useConfig()\n\n const memoizedValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function') {\n return validate(value, { ...options, maxLength, minLength, required })\n }\n },\n [validate, minLength, maxLength, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled,\n path,\n setValue,\n showError,\n value,\n } = useField({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const renderRTL = isFieldRTL({\n fieldLocalized: localized,\n fieldRTL: rtl,\n locale,\n localizationConfig: localizationConfig || undefined,\n })\n\n const [valueToRender, setValueToRender] = useState<\n { id: string; label: string; value: { value: number } }[]\n >([]) // Only for hasMany\n\n const handleHasManyChange = useCallback(\n (selectedOption) => {\n if (!(readOnly || disabled)) {\n let newValue\n if (!selectedOption) {\n newValue = []\n } else if (Array.isArray(selectedOption)) {\n newValue = selectedOption.map((option) => option.value?.value || option.value)\n } else {\n newValue = [selectedOption.value?.value || selectedOption.value]\n }\n\n setValue(newValue)\n }\n },\n [readOnly, setValue, disabled],\n )\n\n // useEffect update valueToRender:\n useEffect(() => {\n if (hasMany && Array.isArray(value)) {\n setValueToRender(\n value.map((val, index) => {\n return {\n id: `${val}${index}`, // append index to avoid duplicate keys but allow duplicate numbers\n label: `${val}`,\n value: {\n // React-select automatically uses \"label-value\" as a key, so we will get that react duplicate key warning if we just pass in the value as multiple values can be the same. So we need to append the index to the toString() of the value to avoid that warning, as it uses that as the key.\n toString: () => `${val}${index}`,\n value: val?.value || val,\n },\n }\n }),\n )\n }\n }, [value, hasMany])\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n return (\n <TextInput\n AfterInput={AfterInput}\n BeforeInput={BeforeInput}\n className={className}\n Description={Description}\n description={description}\n Error={Error}\n hasMany={hasMany}\n htmlAttributes={{\n autoComplete: autoComplete || undefined,\n }}\n inputRef={inputRef}\n Label={Label}\n label={label}\n localized={localized}\n maxRows={maxRows}\n minRows={minRows}\n onChange={\n hasMany\n ? handleHasManyChange\n : (e) => {\n setValue(e.target.value)\n }\n }\n path={path}\n placeholder={placeholder}\n readOnly={readOnly || disabled}\n required={required}\n rtl={renderRTL}\n showError={showError}\n style={styles}\n value={(value as string) || ''}\n valueToRender={valueToRender as Option[]}\n />\n )\n}\n\nexport const TextField = withCondition(TextFieldComponent)\n"],"mappings":"AAAA;;;AAGA,OAAOA,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AAKjE,SAASC,QAAQ,QAAQ;AACzB,SAASC,aAAa,QAAQ;AAC9B,SAASC,SAAS,QAAQ;AAC1B,SAASC,SAAS,QAAQ;AAC1B,SAASC,gBAAgB,QAAQ;AACjC,SAASC,UAAU,QAAQ;AAC3B,SAASC,SAAS,QAAQ;AAC1B,OAAO;AAEP,SAASA,SAAS;AAElB,MAAMC,kBAAA,GAAgDC,KAAA;EACpD,MAAM;IACJC,KAAK;IACLA,KAAA,EAAO;MACLC,KAAA,EAAO;QAAEC,YAAY;QAAEC,SAAS;QAAEC,WAAW;QAAEC,WAAW;QAAEC;MAAG,CAAE,GAAG,CAAC,CAAC;MACtEC,OAAO;MACPC,KAAK;MACLC,SAAS;MACTC,SAAS;MACTC,OAAO;MACPC,SAAS;MACTC,OAAO;MACPC;IAAQ,CACT;IACDC,QAAQ;IACRC,IAAA,EAAMC,aAAa;IACnBC,QAAQ;IACRC;EAAQ,CACT,GAAGpB,KAAA;EAEJ,MAAMqB,MAAA,GAAS1B,SAAA;EAEf,MAAM;IACJ2B,MAAA,EAAQ;MAAEC,YAAA,EAAcC;IAAkB;EAAE,CAC7C,GAAG9B,SAAA;EAEJ,MAAM+B,gBAAA,GAAmBrC,WAAA,CACvB,CAACsC,KAAA,EAAOC,OAAA;IACN,IAAI,OAAOP,QAAA,KAAa,YAAY;MAClC,OAAOA,QAAA,CAASM,KAAA,EAAO;QAAE,GAAGC,OAAO;QAAEhB,SAAA;QAAWE,SAAA;QAAWE;MAAS;IACtE;EACF,GACA,CAACK,QAAA,EAAUP,SAAA,EAAWF,SAAA,EAAWI,QAAA,CAAS;EAG5C,MAAM;IACJa,gBAAA,EAAkB;MAAEC,UAAU;MAAEC,WAAW;MAAEC,WAAW;MAAEC,KAAK;MAAEC;IAAK,CAAE,GAAG,CAAC,CAAC;IAC7EC,QAAQ;IACRjB,IAAI;IACJkB,QAAQ;IACRC,SAAS;IACTV,KAAK,EAALA;EAAK,CACN,GAAGlC,QAAA,CAAS;IACX6C,oBAAA,EAAsBnB,aAAA;IACtBE,QAAA,EAAUK;EACZ;EAEA,MAAMa,SAAA,GAAYzC,UAAA,CAAW;IAC3B0C,cAAA,EAAgB7B,SAAA;IAChB8B,QAAA,EAAUjC,GAAA;IACVc,MAAA;IACAG,kBAAA,EAAoBA,kBAAA,IAAsBiB;EAC5C;EAEA,MAAM,CAACC,aAAA,EAAeC,gBAAA,CAAiB,GAAGpD,QAAA,CAExC,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","useCallback","useEffect","useMemo","useState","useField","withCondition","useConfig","useLocale","mergeFieldStyles","isFieldRTL","TextInput","TextFieldComponent","props","field","admin","autoComplete","className","description","placeholder","rtl","hasMany","label","localized","maxLength","maxRows","minLength","minRows","required","inputRef","path","pathFromProps","readOnly","validate","locale","config","localization","localizationConfig","memoizedValidate","value","options","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","setValue","showError","potentiallyStalePath","renderRTL","fieldLocalized","fieldRTL","undefined","valueToRender","setValueToRender","handleHasManyChange","selectedOption","newValue","Array","isArray","map","option","val","index","id","toString","styles","_jsx","htmlAttributes","onChange","e","target","style","TextField"],"sources":["../../../src/fields/Text/index.tsx"],"sourcesContent":["'use client'\nimport type { TextFieldClientComponent } from 'payload'\n\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport type { Option } from '../../elements/ReactSelect/types.js'\nimport type { TextInputProps } from './types.js'\n\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { mergeFieldStyles } from '../mergeFieldStyles.js'\nimport { isFieldRTL } from '../shared/index.js'\nimport { TextInput } from './Input.js'\nimport './index.scss'\n\nexport { TextInput, TextInputProps }\n\nconst TextFieldComponent: TextFieldClientComponent = (props) => {\n const {\n field,\n field: {\n admin: { autoComplete, className, description, placeholder, rtl } = {},\n hasMany,\n label,\n localized,\n maxLength,\n maxRows,\n minLength,\n minRows,\n required,\n },\n inputRef,\n path: pathFromProps,\n readOnly,\n validate,\n } = props\n\n const locale = useLocale()\n\n const {\n config: { localization: localizationConfig },\n } = useConfig()\n\n const memoizedValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function') {\n return validate(value, { ...options, maxLength, minLength, required })\n }\n },\n [validate, minLength, maxLength, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled,\n path,\n setValue,\n showError,\n value,\n } = useField({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const renderRTL = isFieldRTL({\n fieldLocalized: localized,\n fieldRTL: rtl,\n locale,\n localizationConfig: localizationConfig || undefined,\n })\n\n const [valueToRender, setValueToRender] = useState<\n { id: string; label: string; value: { value: number } }[]\n >([]) // Only for hasMany\n\n const handleHasManyChange = useCallback(\n (selectedOption) => {\n if (!(readOnly || disabled)) {\n let newValue\n if (!selectedOption) {\n newValue = []\n } else if (Array.isArray(selectedOption)) {\n newValue = selectedOption.map((option) => option.value?.value || option.value)\n } else {\n newValue = [selectedOption.value?.value || selectedOption.value]\n }\n\n setValue(newValue)\n }\n },\n [readOnly, setValue, disabled],\n )\n\n // useEffect update valueToRender:\n useEffect(() => {\n if (hasMany && Array.isArray(value)) {\n setValueToRender(\n value.map((val, index) => {\n return {\n id: `${val}${index}`, // append index to avoid duplicate keys but allow duplicate numbers\n label: `${val}`,\n value: {\n // React-select automatically uses \"label-value\" as a key, so we will get that react duplicate key warning if we just pass in the value as multiple values can be the same. So we need to append the index to the toString() of the value to avoid that warning, as it uses that as the key.\n toString: () => `${val}${index}`,\n value: val?.value || val,\n },\n }\n }),\n )\n }\n }, [value, hasMany])\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n return (\n <TextInput\n AfterInput={AfterInput}\n BeforeInput={BeforeInput}\n className={className}\n Description={Description}\n description={description}\n Error={Error}\n hasMany={hasMany}\n htmlAttributes={{\n autoComplete: autoComplete || undefined,\n }}\n inputRef={inputRef}\n Label={Label}\n label={label}\n localized={localized}\n maxRows={maxRows}\n minRows={minRows}\n onChange={\n hasMany\n ? handleHasManyChange\n : (e) => {\n setValue(e.target.value)\n }\n }\n path={path}\n placeholder={placeholder}\n readOnly={readOnly || disabled}\n required={required}\n rtl={renderRTL}\n showError={showError}\n style={styles}\n value={(value as string) || ''}\n valueToRender={valueToRender as Option[]}\n />\n )\n}\n\nexport const TextField = withCondition(TextFieldComponent)\n"],"mappings":"AAAA;;;AAGA,OAAOA,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AAKjE,SAASC,QAAQ,QAAQ;AACzB,SAASC,aAAa,QAAQ;AAC9B,SAASC,SAAS,QAAQ;AAC1B,SAASC,SAAS,QAAQ;AAC1B,SAASC,gBAAgB,QAAQ;AACjC,SAASC,UAAU,QAAQ;AAC3B,SAASC,SAAS,QAAQ;AAC1B,OAAO;AAEP,SAASA,SAAS;AAElB,MAAMC,kBAAA,GAAgDC,KAAA;EACpD,M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,WAAA;IACb1B,SAAA,EAAWA,SAAA;IACX2B,WAAA,EAAaA,WAAA;IACb1B,WAAA,EAAaA,WAAA;IACb2B,KAAA,EAAOA,KAAA;IACPxB,OAAA,EAASA,OAAA;IACTiD,cAAA,EAAgB;MACdtD,YAAA,EAAcA,YAAA,IAAgBsC;IAChC;IACAzB,QAAA,EAAUA,QAAA;IACViB,KAAA,EAAOA,KAAA;IACPxB,KAAA,EAAOA,KAAA;IACPC,SAAA,EAAWA,SAAA;IACXE,OAAA,EAASA,OAAA;IACTE,OAAA,EAASA,OAAA;IACT4C,QAAA,EACElD,OAAA,GACIoC,mBAAA,GACCe,CAAA;MACCxB,QAAA,CAASwB,CAAA,CAAEC,MAAM,CAAClC,KAAK;IACzB;IAENT,IAAA,EAAMA,IAAA;IACNX,WAAA,EAAaA,WAAA;IACba,QAAA,EAAUA,QAAA,IAAYe,QAAA;IACtBnB,QAAA,EAAUA,QAAA;IACVR,GAAA,EAAK+B,SAAA;IACLF,SAAA,EAAWA,SAAA;IACXyB,KAAA,EAAON,MAAA;IACP7B,KAAA,EAAOA,OAAC,IAAoB;IAC5BgB,aAAA,EAAeA;;AAGrB;AAEA,OAAO,MAAMoB,SAAA,GAAYrE,aAAA,CAAcM,kBAAA","ignoreList":[]}
|
|
@@ -19,6 +19,6 @@ export function isFieldRTL({
|
|
|
19
19
|
!fieldLocalized && isCurrentLocaleDefaultLocale) ||
|
|
20
20
|
// If the current locale is the default locale, but the field is not localized, that field is rtl too
|
|
21
21
|
fieldRTL === true // If fieldRTL is true. This should be useful for when no localization is set at all in the payload config, but you still want fields to be rtl.
|
|
22
|
-
|
|
22
|
+
;
|
|
23
23
|
}
|
|
24
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fieldBaseClass","isFieldRTL","fieldLocalized","fieldRTL","locale","localizationConfig","hasMultipleLocales","locales","length","isCurrentLocaleDefaultLocale","code","defaultLocale","rtl"],"sources":["../../../src/fields/shared/index.tsx"],"sourcesContent":["'use client'\nimport type { Locale, SanitizedLocalizationConfig } from 'payload'\n\nexport const fieldBaseClass = 'field-type'\n\n/**\n * Determines whether a field should be displayed as right-to-left (RTL) based on its configuration, payload's localization configuration and the adming user's currently enabled locale.\n\n * @returns Whether the field should be displayed as RTL.\n */\nexport function isFieldRTL({\n fieldLocalized,\n fieldRTL,\n locale,\n localizationConfig,\n}: {\n fieldLocalized: boolean\n fieldRTL: boolean\n locale: Locale\n localizationConfig?: SanitizedLocalizationConfig\n}) {\n const hasMultipleLocales =\n locale &&\n localizationConfig &&\n localizationConfig.locales &&\n localizationConfig.locales.length > 1\n\n const isCurrentLocaleDefaultLocale = locale?.code === localizationConfig?.defaultLocale\n\n return (\n (fieldRTL !== false &&\n locale?.rtl === true &&\n (fieldLocalized ||\n (!fieldLocalized && !hasMultipleLocales) || // If there is only one locale which is also rtl, that field is rtl too\n (!fieldLocalized && isCurrentLocaleDefaultLocale))) || // If the current locale is the default locale, but the field is not localized, that field is rtl too\n fieldRTL === true\n ) // If fieldRTL is true. This should be useful for when no localization is set at all in the payload config, but you still want fields to be rtl.\n}\n"],"mappings":"AAAA;;AAGA,OAAO,MAAMA,cAAA,GAAiB;AAE9B;;;;;AAKA,OAAO,SAASC,WAAW;EACzBC,cAAc;EACdC,QAAQ;EACRC,MAAM;EACNC;AAAkB,CAMnB;EACC,MAAMC,kBAAA,GACJF,MAAA,IACAC,kBAAA,IACAA,kBAAA,CAAmBE,OAAO,IAC1BF,kBAAA,CAAmBE,OAAO,CAACC,MAAM,GAAG;EAEtC,MAAMC,4BAAA,GAA+BL,MAAA,EAAQM,IAAA,KAASL,kBAAA,EAAoBM,aAAA;EAE1E,OACER,QAAC,KAAa,SACZC,MAAA,EAAQQ,GAAA,KAAQ,SACfV,cAAA,IACE,CAACA,cAAA,IAAkB,CAACI,kBAAA;EAAuB;EAC3C,CAACJ,cAAA,IAAkBO,4BAA4B;EAAO;EAC3DN,QAAA,KAAa,KACb;
|
|
1
|
+
{"version":3,"file":"index.js","names":["fieldBaseClass","isFieldRTL","fieldLocalized","fieldRTL","locale","localizationConfig","hasMultipleLocales","locales","length","isCurrentLocaleDefaultLocale","code","defaultLocale","rtl"],"sources":["../../../src/fields/shared/index.tsx"],"sourcesContent":["'use client'\nimport type { Locale, SanitizedLocalizationConfig } from 'payload'\n\nexport const fieldBaseClass = 'field-type'\n\n/**\n * Determines whether a field should be displayed as right-to-left (RTL) based on its configuration, payload's localization configuration and the adming user's currently enabled locale.\n\n * @returns Whether the field should be displayed as RTL.\n */\nexport function isFieldRTL({\n fieldLocalized,\n fieldRTL,\n locale,\n localizationConfig,\n}: {\n fieldLocalized: boolean\n fieldRTL: boolean\n locale: Locale\n localizationConfig?: SanitizedLocalizationConfig\n}) {\n const hasMultipleLocales =\n locale &&\n localizationConfig &&\n localizationConfig.locales &&\n localizationConfig.locales.length > 1\n\n const isCurrentLocaleDefaultLocale = locale?.code === localizationConfig?.defaultLocale\n\n return (\n (fieldRTL !== false &&\n locale?.rtl === true &&\n (fieldLocalized ||\n (!fieldLocalized && !hasMultipleLocales) || // If there is only one locale which is also rtl, that field is rtl too\n (!fieldLocalized && isCurrentLocaleDefaultLocale))) || // If the current locale is the default locale, but the field is not localized, that field is rtl too\n fieldRTL === true\n ) // If fieldRTL is true. This should be useful for when no localization is set at all in the payload config, but you still want fields to be rtl.\n}\n"],"mappings":"AAAA;;AAGA,OAAO,MAAMA,cAAA,GAAiB;AAE9B;;;;;AAKA,OAAO,SAASC,WAAW;EACzBC,cAAc;EACdC,QAAQ;EACRC,MAAM;EACNC;AAAkB,CAMnB;EACC,MAAMC,kBAAA,GACJF,MAAA,IACAC,kBAAA,IACAA,kBAAA,CAAmBE,OAAO,IAC1BF,kBAAA,CAAmBE,OAAO,CAACC,MAAM,GAAG;EAEtC,MAAMC,4BAAA,GAA+BL,MAAA,EAAQM,IAAA,KAASL,kBAAA,EAAoBM,aAAA;EAE1E,OACER,QAAC,KAAa,SACZC,MAAA,EAAQQ,GAAA,KAAQ,SACfV,cAAA,IACE,CAACA,cAAA,IAAkB,CAACI,kBAAA;EAAuB;EAC3C,CAACJ,cAAA,IAAkBO,4BAA4B;EAAO;EAC3DN,QAAA,KAAa,KACb;AAAA;AACJ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reduceToSerializableFields.js","names":["blacklistedKeys","sanitizeField","incomingField","field","key","reduceToSerializableFields","fields","result"],"sources":["../../../src/forms/Form/reduceToSerializableFields.ts"],"sourcesContent":["import { type FormField, type FormState } from 'payload'\n\ntype BlacklistedKeys = 'customComponents' | 'validate'\nconst blacklistedKeys: BlacklistedKeys[] = ['validate', 'customComponents']\n\nconst sanitizeField = (incomingField: FormField): FormField => {\n const field = { ...incomingField } // shallow copy, as we only need to remove top-level keys\n\n for (const key of blacklistedKeys) {\n delete field[key]\n }\n\n return field\n}\n\n/**\n * Takes in FormState and removes fields that are not serializable.\n * Returns FormState without blacklisted keys.\n */\nexport const reduceToSerializableFields = (\n fields: FormState,\n): {\n [key: string]: Omit<FormField, BlacklistedKeys>\n} => {\n const result: Record<string, Omit<FormField, BlacklistedKeys>> = {}\n\n for (const key in fields) {\n result[key] = sanitizeField(fields[key])\n }\n\n return result\n}\n"],"mappings":"AAGA,MAAMA,eAAA,GAAqC,CAAC,YAAY,mBAAmB;AAE3E,MAAMC,aAAA,GAAiBC,aAAA;EACrB,MAAMC,KAAA,GAAQ;IAAE,GAAGD;EAAc,EAAE;
|
|
1
|
+
{"version":3,"file":"reduceToSerializableFields.js","names":["blacklistedKeys","sanitizeField","incomingField","field","key","reduceToSerializableFields","fields","result"],"sources":["../../../src/forms/Form/reduceToSerializableFields.ts"],"sourcesContent":["import { type FormField, type FormState } from 'payload'\n\ntype BlacklistedKeys = 'customComponents' | 'validate'\nconst blacklistedKeys: BlacklistedKeys[] = ['validate', 'customComponents']\n\nconst sanitizeField = (incomingField: FormField): FormField => {\n const field = { ...incomingField } // shallow copy, as we only need to remove top-level keys\n\n for (const key of blacklistedKeys) {\n delete field[key]\n }\n\n return field\n}\n\n/**\n * Takes in FormState and removes fields that are not serializable.\n * Returns FormState without blacklisted keys.\n */\nexport const reduceToSerializableFields = (\n fields: FormState,\n): {\n [key: string]: Omit<FormField, BlacklistedKeys>\n} => {\n const result: Record<string, Omit<FormField, BlacklistedKeys>> = {}\n\n for (const key in fields) {\n result[key] = sanitizeField(fields[key])\n }\n\n return result\n}\n"],"mappings":"AAGA,MAAMA,eAAA,GAAqC,CAAC,YAAY,mBAAmB;AAE3E,MAAMC,aAAA,GAAiBC,aAAA;EACrB,MAAMC,KAAA,GAAQ;IAAE,GAAGD;EAAc,EAAE;AAAA;EAEnC,KAAK,MAAME,GAAA,IAAOJ,eAAA,EAAiB;IACjC,OAAOG,KAAK,CAACC,GAAA,CAAI;EACnB;EAEA,OAAOD,KAAA;AACT;AAEA;;;;AAIA,OAAO,MAAME,0BAAA,GACXC,MAAA;EAIA,MAAMC,MAAA,GAA2D,CAAC;EAElE,KAAK,MAAMH,GAAA,IAAOE,MAAA,EAAQ;IACxBC,MAAM,CAACH,GAAA,CAAI,GAAGH,aAAA,CAAcK,MAAM,CAACF,GAAA,CAAI;EACzC;EAEA,OAAOG,MAAA;AACT","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/forms/WatchChildErrors/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAM9B,KAAK,6BAA6B,GAAG;IACnC,MAAM,CAAC,EAAE,WAAW,EAAE,CAAA;IACtB;;;;;OAKG;IACH,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IACzB,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACvC,CAAA;AACD,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,6BAA6B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/forms/WatchChildErrors/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAM9B,KAAK,6BAA6B,GAAG;IACnC,MAAM,CAAC,EAAE,WAAW,EAAE,CAAA;IACtB;;;;;OAKG;IACH,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IACzB,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACvC,CAAA;AACD,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,6BAA6B,CA2CpE,CAAA"}
|
|
@@ -32,7 +32,8 @@ export const WatchChildErrors = t0 => {
|
|
|
32
32
|
const matchingSegment = segmentsToMatch?.some(segment => {
|
|
33
33
|
const segmentToMatch = [...parentPath, segment].join(".");
|
|
34
34
|
if (segmentToMatch.endsWith(".")) {
|
|
35
|
-
|
|
35
|
+
const pathWithoutDot = segmentToMatch.slice(0, -1);
|
|
36
|
+
return key.startsWith(segmentToMatch) || key === pathWithoutDot;
|
|
36
37
|
}
|
|
37
38
|
return key === segmentToMatch;
|
|
38
39
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","useThrottledEffect","useAllFormFields","useFormSubmitted","buildPathSegments","WatchChildErrors","t0","$","fields","path","parentPath","setErrorCount","formState","hasSubmitted","t1","segmentsToMatch","t2","errorCount","Object","entries","forEach","t3","key","matchingSegment","some","segment","segmentToMatch","join","endsWith","startsWith","pathState","valid"],"sources":["../../../src/forms/WatchChildErrors/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientField } from 'payload'\nimport type React from 'react'\n\nimport { useThrottledEffect } from '../../hooks/useThrottledEffect.js'\nimport { useAllFormFields, useFormSubmitted } from '../Form/context.js'\nimport { buildPathSegments } from './buildPathSegments.js'\n\ntype TrackSubSchemaErrorCountProps = {\n fields?: ClientField[]\n /**\n * This path should only include path segments that affect data\n * i.e. it should not include _index-0 type segments\n *\n * For collapsibles and tabs you can simply pass their parent path\n */\n path: (number | string)[]\n setErrorCount: (count: number) => void\n}\nexport const WatchChildErrors: React.FC<TrackSubSchemaErrorCountProps> = ({\n fields,\n path: parentPath,\n setErrorCount,\n}) => {\n const [formState] = useAllFormFields()\n const hasSubmitted = useFormSubmitted()\n\n const segmentsToMatch = buildPathSegments(fields)\n\n useThrottledEffect(\n () => {\n if (hasSubmitted) {\n let errorCount = 0\n Object.entries(formState).forEach(([key]) => {\n const matchingSegment = segmentsToMatch?.some((segment) => {\n const segmentToMatch = [...parentPath, segment].join('.')\n // match fields with same parent path\n if (segmentToMatch.endsWith('.')) {\n return key.startsWith(segmentToMatch)\n }\n // match fields with same path\n return key === segmentToMatch\n })\n\n if (matchingSegment) {\n const pathState = formState[key]\n if ('valid' in pathState && !pathState.valid) {\n errorCount += 1\n }\n }\n })\n setErrorCount(errorCount)\n }\n },\n 250,\n [formState, hasSubmitted, fields],\n )\n\n return null\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAIA,SAASC,kBAAkB,QAAQ;AACnC,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ;AACnD,SAASC,iBAAiB,QAAQ;AAalC,OAAO,MAAMC,gBAAA,GAA4DC,EAAA;EAAA,MAAAC,CAAA,GAAAP,EAAA;EAAC;IAAAQ,MAAA;IAAAC,IAAA,EAAAC,UAAA;IAAAC;EAAA,IAAAL,EAIzE;EACC,OAAAM,SAAA,IAAoBV,gBAAA;EACpB,MAAAW,YAAA,GAAqBV,gBAAA;EAAA,IAAAW,EAAA;EAAA,IAAAP,CAAA,QAAAC,MAAA;IAEGM,EAAA,GAAAV,iBAAA,CAAkBI,MAAA;IAAAD,CAAA,MAAAC,MAAA;IAAAD,CAAA,MAAAO,EAAA;EAAA;IAAAA,EAAA,GAAAP,CAAA;EAAA;EAA1C,MAAAQ,eAAA,GAAwBD,EAAkB;EAAA,IAAAE,EAAA;EAAA,IAAAT,CAAA,QAAAK,SAAA,IAAAL,CAAA,QAAAM,YAAA,IAAAN,CAAA,QAAAG,UAAA,IAAAH,CAAA,QAAAQ,eAAA,IAAAR,CAAA,QAAAI,aAAA;IAGxCK,EAAA,GAAAA,CAAA;MAAA,IACMH,YAAA;QACF,IAAAI,UAAA;QACAC,MAAA,CAAAC,OAAA,CAAeP,SAAA,EAAAQ,OAAA,CAAAC,EAAA;UAAoB,OAAAC,GAAA,IAAAD,EAAK;UACtC,MAAAE,eAAA,GAAwBR,eAAA,EAAAS,IAAA,CAAAC,OAAA;YACtB,MAAAC,cAAA,GAAuB,IAAIhB,UAAA,EAAYe,OAAA,EAAAE,IAAA,CAAc;YAAA,IAEjDD,cAAA,CAAAE,QAAA,CAAwB;cAAA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","useThrottledEffect","useAllFormFields","useFormSubmitted","buildPathSegments","WatchChildErrors","t0","$","fields","path","parentPath","setErrorCount","formState","hasSubmitted","t1","segmentsToMatch","t2","errorCount","Object","entries","forEach","t3","key","matchingSegment","some","segment","segmentToMatch","join","endsWith","pathWithoutDot","slice","startsWith","pathState","valid"],"sources":["../../../src/forms/WatchChildErrors/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientField } from 'payload'\nimport type React from 'react'\n\nimport { useThrottledEffect } from '../../hooks/useThrottledEffect.js'\nimport { useAllFormFields, useFormSubmitted } from '../Form/context.js'\nimport { buildPathSegments } from './buildPathSegments.js'\n\ntype TrackSubSchemaErrorCountProps = {\n fields?: ClientField[]\n /**\n * This path should only include path segments that affect data\n * i.e. it should not include _index-0 type segments\n *\n * For collapsibles and tabs you can simply pass their parent path\n */\n path: (number | string)[]\n setErrorCount: (count: number) => void\n}\nexport const WatchChildErrors: React.FC<TrackSubSchemaErrorCountProps> = ({\n fields,\n path: parentPath,\n setErrorCount,\n}) => {\n const [formState] = useAllFormFields()\n const hasSubmitted = useFormSubmitted()\n\n const segmentsToMatch = buildPathSegments(fields)\n\n useThrottledEffect(\n () => {\n if (hasSubmitted) {\n let errorCount = 0\n Object.entries(formState).forEach(([key]) => {\n const matchingSegment = segmentsToMatch?.some((segment) => {\n const segmentToMatch = [...parentPath, segment].join('.')\n // match fields with same parent path\n if (segmentToMatch.endsWith('.')) {\n // Match both nested fields (key starts with segmentToMatch)\n // and the field itself (key equals segmentToMatch without trailing dot)\n const pathWithoutDot = segmentToMatch.slice(0, -1)\n return key.startsWith(segmentToMatch) || key === pathWithoutDot\n }\n // match fields with same path\n return key === segmentToMatch\n })\n\n if (matchingSegment) {\n const pathState = formState[key]\n if ('valid' in pathState && !pathState.valid) {\n errorCount += 1\n }\n }\n })\n setErrorCount(errorCount)\n }\n },\n 250,\n [formState, hasSubmitted, fields],\n )\n\n return null\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAIA,SAASC,kBAAkB,QAAQ;AACnC,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ;AACnD,SAASC,iBAAiB,QAAQ;AAalC,OAAO,MAAMC,gBAAA,GAA4DC,EAAA;EAAA,MAAAC,CAAA,GAAAP,EAAA;EAAC;IAAAQ,MAAA;IAAAC,IAAA,EAAAC,UAAA;IAAAC;EAAA,IAAAL,EAIzE;EACC,OAAAM,SAAA,IAAoBV,gBAAA;EACpB,MAAAW,YAAA,GAAqBV,gBAAA;EAAA,IAAAW,EAAA;EAAA,IAAAP,CAAA,QAAAC,MAAA;IAEGM,EAAA,GAAAV,iBAAA,CAAkBI,MAAA;IAAAD,CAAA,MAAAC,MAAA;IAAAD,CAAA,MAAAO,EAAA;EAAA;IAAAA,EAAA,GAAAP,CAAA;EAAA;EAA1C,MAAAQ,eAAA,GAAwBD,EAAkB;EAAA,IAAAE,EAAA;EAAA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;IAAOD,CAAA,MAAAC,MAAA;IAAAD,CAAA,MAAAK,SAAA;IAAAL,CAAA,OAAAM,YAAA;IAAAN,CAAA,OAAAc,EAAA;EAAA;IAAAA,EAAA,GAAAd,CAAA;EAAA;EA7BnCN,kBAAA,CACEe,EA0BA,OAEAK,EAAiC;EAAA;AAAA,CAIrC","ignoreList":[]}
|
|
@@ -10,7 +10,7 @@ export function isRowCollapsed({
|
|
|
10
10
|
// If previousFormState is `undefined`, check preferences
|
|
11
11
|
if (collapsedPrefs !== undefined) {
|
|
12
12
|
return collapsedPrefs.includes(row.id) // Check if collapsed in preferences
|
|
13
|
-
|
|
13
|
+
;
|
|
14
14
|
}
|
|
15
15
|
// If neither exists, fallback to `field.admin.initCollapsed`
|
|
16
16
|
return field.admin.initCollapsed;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isRowCollapsed.js","names":["isRowCollapsed","collapsedPrefs","field","previousRow","row","collapsed","undefined","includes","id","admin","initCollapsed"],"sources":["../../../src/forms/fieldSchemasToFormState/isRowCollapsed.ts"],"sourcesContent":["import type { ArrayField, BlocksField, CollapsedPreferences, Row } from 'payload'\n\nexport function isRowCollapsed({\n collapsedPrefs,\n field,\n previousRow,\n row,\n}: {\n collapsedPrefs: CollapsedPreferences\n field: ArrayField | BlocksField\n previousRow: Row | undefined\n row: Row\n}): boolean {\n if (previousRow && 'collapsed' in previousRow) {\n return previousRow.collapsed ?? false\n }\n\n // If previousFormState is `undefined`, check preferences\n if (collapsedPrefs !== undefined) {\n return collapsedPrefs.includes(row.id) // Check if collapsed in preferences\n }\n\n // If neither exists, fallback to `field.admin.initCollapsed`\n return field.admin.initCollapsed\n}\n"],"mappings":"AAEA,OAAO,SAASA,eAAe;EAC7BC,cAAc;EACdC,KAAK;EACLC,WAAW;EACXC;AAAG,CAMJ;EACC,IAAID,WAAA,IAAe,eAAeA,WAAA,EAAa;IAC7C,OAAOA,WAAA,CAAYE,SAAS,IAAI;EAClC;EAEA;EACA,IAAIJ,cAAA,KAAmBK,SAAA,EAAW;IAChC,OAAOL,cAAA,CAAeM,QAAQ,CAACH,GAAA,CAAII,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"isRowCollapsed.js","names":["isRowCollapsed","collapsedPrefs","field","previousRow","row","collapsed","undefined","includes","id","admin","initCollapsed"],"sources":["../../../src/forms/fieldSchemasToFormState/isRowCollapsed.ts"],"sourcesContent":["import type { ArrayField, BlocksField, CollapsedPreferences, Row } from 'payload'\n\nexport function isRowCollapsed({\n collapsedPrefs,\n field,\n previousRow,\n row,\n}: {\n collapsedPrefs: CollapsedPreferences\n field: ArrayField | BlocksField\n previousRow: Row | undefined\n row: Row\n}): boolean {\n if (previousRow && 'collapsed' in previousRow) {\n return previousRow.collapsed ?? false\n }\n\n // If previousFormState is `undefined`, check preferences\n if (collapsedPrefs !== undefined) {\n return collapsedPrefs.includes(row.id) // Check if collapsed in preferences\n }\n\n // If neither exists, fallback to `field.admin.initCollapsed`\n return field.admin.initCollapsed\n}\n"],"mappings":"AAEA,OAAO,SAASA,eAAe;EAC7BC,cAAc;EACdC,KAAK;EACLC,WAAW;EACXC;AAAG,CAMJ;EACC,IAAID,WAAA,IAAe,eAAeA,WAAA,EAAa;IAC7C,OAAOA,WAAA,CAAYE,SAAS,IAAI;EAClC;EAEA;EACA,IAAIJ,cAAA,KAAmBK,SAAA,EAAW;IAChC,OAAOL,cAAA,CAAeM,QAAQ,CAACH,GAAA,CAAII,EAAE,EAAE;AAAA;EACzC;EAEA;EACA,OAAON,KAAA,CAAMO,KAAK,CAACC,aAAa;AAClC","ignoreList":[]}
|
|
@@ -167,7 +167,7 @@ export const renderField = ({
|
|
|
167
167
|
{
|
|
168
168
|
if (!fieldConfig?.editor) {
|
|
169
169
|
throw new MissingEditorProp(fieldConfig) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor
|
|
170
|
-
|
|
170
|
+
;
|
|
171
171
|
}
|
|
172
172
|
if (typeof fieldConfig?.editor === 'function') {
|
|
173
173
|
throw new Error('Attempted to access unsanitized rich text editor.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderField.js","names":["getTranslation","createClientField","MissingEditorProp","fieldIsHiddenOrDisabled","RenderServerComponent","FieldDescription","WatchCondition","defaultUIFieldComponentKeys","renderField","id","clientFieldSchemaMap","collectionSlug","data","fieldConfig","fieldSchemaMap","fieldState","forceCreateClientField","formState","indexPath","lastRenderedPath","mockRSCs","operation","parentPath","parentSchemaPath","path","permissions","preferences","readOnly","readOnlyFromProps","renderAllFields","req","schemaPath","siblingData","hasBeforeOrAfterInput","admin","components","requiresRender","type","clientField","get","defaultIDType","payload","config","db","field","i18n","importMap","clientProps","customComponents","includes","serverProps","user","value","name","rows","forEach","row","rowIndex","rowLastRenderedPath","rowPath","rowRequiresRender","RowLabel","Component","key","rowLabel","labels","singular","String","padStart","rowNumber","blockTypeToMatch","blockType","blockConfig","blocks","blockReferences","find","block","slug","Label","Object","keys","length","description","editor","Error","Field","_jsx","FieldComponent","sanitizedEditorConfig","editorConfig","undefined","Description","t","AfterInput","afterInput","BeforeInput","beforeInput"],"sources":["../../../src/forms/fieldSchemasToFormState/renderField.tsx"],"sourcesContent":["import type {\n ClientComponentProps,\n ClientField,\n FieldPaths,\n FlattenedBlock,\n ServerComponentProps,\n} from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { createClientField, MissingEditorProp } from 'payload'\nimport { fieldIsHiddenOrDisabled } from 'payload/shared'\n\nimport type { RenderFieldMethod } from './types.js'\n\nimport { RenderServerComponent } from '../../elements/RenderServerComponent/index.js'\n\n// eslint-disable-next-line payload/no-imports-from-exports-dir -- MUST reference the exports dir: https://github.com/payloadcms/payload/issues/12002#issuecomment-2791493587\nimport { FieldDescription, WatchCondition } from '../../exports/client/index.js'\n\nconst defaultUIFieldComponentKeys: Array<'Cell' | 'Description' | 'Field' | 'Filter'> = [\n 'Cell',\n 'Description',\n 'Field',\n 'Filter',\n]\n\nexport const renderField: RenderFieldMethod = ({\n id,\n clientFieldSchemaMap,\n collectionSlug,\n data,\n fieldConfig,\n fieldSchemaMap,\n fieldState,\n forceCreateClientField,\n formState,\n indexPath,\n lastRenderedPath,\n mockRSCs,\n operation,\n parentPath,\n parentSchemaPath,\n path,\n permissions,\n preferences,\n readOnly: readOnlyFromProps,\n renderAllFields,\n req,\n schemaPath,\n siblingData,\n}) => {\n // Fields with beforeInput/afterInput need custom components created, so they require render\n const hasBeforeOrAfterInput =\n fieldConfig.admin?.components &&\n ('beforeInput' in fieldConfig.admin.components || 'afterInput' in fieldConfig.admin.components)\n\n const requiresRender =\n renderAllFields || !lastRenderedPath || lastRenderedPath !== path || hasBeforeOrAfterInput\n\n if (!requiresRender && fieldConfig.type !== 'array' && fieldConfig.type !== 'blocks') {\n return\n }\n\n const clientField =\n clientFieldSchemaMap && !forceCreateClientField\n ? (clientFieldSchemaMap.get(schemaPath) as ClientField)\n : createClientField({\n defaultIDType: req.payload.config.db.defaultIDType,\n field: fieldConfig,\n i18n: req.i18n,\n importMap: req.payload.importMap,\n })\n\n const clientProps: ClientComponentProps & Partial<FieldPaths> = {\n field: clientField,\n path,\n permissions,\n readOnly:\n readOnlyFromProps === true\n ? true\n : typeof permissions === 'boolean'\n ? !permissions\n : !permissions?.[operation],\n schemaPath,\n }\n\n if (fieldState?.customComponents) {\n clientProps.customComponents = fieldState.customComponents\n }\n\n // fields with subfields\n if (['array', 'blocks', 'collapsible', 'group', 'row', 'tabs'].includes(fieldConfig.type)) {\n clientProps.indexPath = indexPath\n clientProps.parentPath = parentPath\n clientProps.parentSchemaPath = parentSchemaPath\n }\n\n const serverProps: ServerComponentProps = {\n id,\n clientField,\n clientFieldSchemaMap,\n data,\n field: fieldConfig,\n fieldSchemaMap,\n permissions,\n // TODO: Should we pass explicit values? initialValue, value, valid\n // value and initialValue should be typed\n collectionSlug,\n formState,\n i18n: req.i18n,\n operation,\n payload: req.payload,\n preferences,\n req,\n siblingData,\n user: req.user,\n value: 'name' in fieldConfig && data?.[fieldConfig.name],\n }\n\n switch (fieldConfig.type) {\n case 'array': {\n fieldState?.rows?.forEach((row, rowIndex) => {\n const rowLastRenderedPath = row.lastRenderedPath\n\n const rowPath = `${path}.${rowIndex}`\n\n const rowRequiresRender =\n renderAllFields || !rowLastRenderedPath || rowLastRenderedPath !== rowPath\n\n if (!rowRequiresRender) {\n return\n }\n\n row.lastRenderedPath = rowPath\n\n if (fieldConfig.admin?.components && 'RowLabel' in fieldConfig.admin.components) {\n if (!row.customComponents) {\n row.customComponents = {}\n }\n\n row.customComponents.RowLabel = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.RowLabel,\n importMap: req.payload.importMap,\n key: `${rowIndex}`,\n serverProps: {\n ...serverProps,\n rowLabel: `${getTranslation(fieldConfig.labels.singular, req.i18n)} ${String(\n rowIndex + 1,\n ).padStart(2, '0')}`,\n rowNumber: rowIndex + 1,\n },\n })\n : 'Mock'\n }\n })\n\n break\n }\n\n case 'blocks': {\n fieldState?.rows?.forEach((row, rowIndex) => {\n const rowLastRenderedPath = row.lastRenderedPath\n\n const rowPath = `${path}.${rowIndex}`\n\n const rowRequiresRender =\n renderAllFields || !rowLastRenderedPath || rowLastRenderedPath !== rowPath\n\n if (!rowRequiresRender) {\n return\n }\n\n row.lastRenderedPath = rowPath\n\n const blockTypeToMatch: string = row.blockType\n\n const blockConfig =\n req.payload.blocks[blockTypeToMatch] ??\n ((fieldConfig.blockReferences ?? fieldConfig.blocks).find(\n (block) => typeof block !== 'string' && block.slug === blockTypeToMatch,\n ) as FlattenedBlock | undefined)\n\n if (blockConfig.admin?.components && 'Label' in blockConfig.admin.components) {\n if (!fieldState.rows[rowIndex]?.customComponents) {\n fieldState.rows[rowIndex].customComponents = {}\n }\n\n fieldState.rows[rowIndex].customComponents.RowLabel = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component: blockConfig.admin.components.Label,\n importMap: req.payload.importMap,\n key: `${rowIndex}`,\n serverProps: {\n ...serverProps,\n blockType: row.blockType,\n rowLabel: `${getTranslation(blockConfig.labels.singular, req.i18n)} ${String(\n rowIndex + 1,\n ).padStart(2, '0')}`,\n rowNumber: rowIndex + 1,\n },\n })\n : 'Mock'\n }\n })\n\n break\n }\n }\n\n if (!requiresRender) {\n return\n }\n\n /**\n * Set the `lastRenderedPath` equal to the new path of the field, this will prevent it from being rendered again\n */\n fieldState.lastRenderedPath = path\n\n if (fieldIsHiddenOrDisabled(clientField)) {\n return\n }\n\n /**\n * Only create the `customComponents` object if needed.\n * This will prevent unnecessary data from being transferred to the client.\n */\n if (fieldConfig.admin) {\n if (\n (Object.keys(fieldConfig.admin.components || {}).length > 0 ||\n fieldConfig.type === 'richText' ||\n ('description' in fieldConfig.admin &&\n typeof fieldConfig.admin.description === 'function')) &&\n !fieldState?.customComponents\n ) {\n fieldState.customComponents = {}\n }\n }\n\n switch (fieldConfig.type) {\n case 'richText': {\n if (!fieldConfig?.editor) {\n throw new MissingEditorProp(fieldConfig) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof fieldConfig?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n if (!fieldConfig.admin) {\n fieldConfig.admin = {}\n }\n\n if (!fieldConfig.admin.components) {\n fieldConfig.admin.components = {}\n }\n\n fieldState.customComponents.Field = !mockRSCs ? (\n <WatchCondition path={path}>\n {RenderServerComponent({\n clientProps,\n Component: fieldConfig.editor.FieldComponent,\n importMap: req.payload.importMap,\n serverProps: {\n ...serverProps,\n // Manually inject lexical-specific `sanitizedEditorConfig` server prop, in order to reduce the size of the field schema.\n // Otherwise, the editorConfig would be included twice - once on the top-level, and once as part of the `FieldComponent` server props.\n sanitizedEditorConfig:\n 'editorConfig' in fieldConfig.editor ? fieldConfig.editor.editorConfig : undefined,\n },\n })}\n </WatchCondition>\n ) : (\n 'Mock'\n )\n\n break\n }\n\n case 'ui': {\n if (fieldConfig?.admin?.components) {\n // Render any extra, untyped components\n for (const key in fieldConfig.admin.components) {\n if (key in defaultUIFieldComponentKeys) {\n continue\n }\n\n const Component = fieldConfig.admin.components[key]\n\n fieldState.customComponents[key] = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component,\n importMap: req.payload.importMap,\n key: `field.admin.components.${key}`,\n serverProps,\n })\n : 'Mock'\n }\n }\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldConfig.admin) {\n if (\n 'description' in fieldConfig.admin &&\n typeof fieldConfig.admin?.description === 'function'\n ) {\n fieldState.customComponents.Description = !mockRSCs ? (\n <FieldDescription\n description={fieldConfig.admin?.description({\n i18n: req.i18n,\n t: req.i18n.t,\n })}\n path={path}\n />\n ) : (\n 'Mock'\n )\n }\n\n if (fieldConfig.admin?.components) {\n if ('afterInput' in fieldConfig.admin.components) {\n fieldState.customComponents.AfterInput = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.afterInput,\n importMap: req.payload.importMap,\n key: `field.admin.components.afterInput.${path}`,\n serverProps,\n })\n : 'Mock'\n }\n\n if ('beforeInput' in fieldConfig.admin.components) {\n fieldState.customComponents.BeforeInput = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.beforeInput,\n importMap: req.payload.importMap,\n key: `field.admin.components.beforeInput.${path}`,\n serverProps,\n })\n : 'Mock'\n }\n\n if ('Description' in fieldConfig.admin.components) {\n fieldState.customComponents.Description = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Description,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Description',\n serverProps,\n })\n : 'Mock'\n }\n\n if ('Error' in fieldConfig.admin.components) {\n fieldState.customComponents.Error = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Error,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Error',\n serverProps,\n })\n : 'Mock'\n }\n\n if ('Label' in fieldConfig.admin.components) {\n fieldState.customComponents.Label = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Label,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Label',\n serverProps,\n })\n : 'Mock'\n }\n\n if ('Field' in fieldConfig.admin.components) {\n fieldState.customComponents.Field = !mockRSCs ? (\n <WatchCondition path={path}>\n {RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Field,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Field',\n serverProps,\n })}\n </WatchCondition>\n ) : (\n 'Mock'\n )\n }\n }\n }\n}\n"],"mappings":";AAQA,SAASA,cAAc,QAAQ;AAC/B,SAASC,iBAAiB,EAAEC,iBAAiB,QAAQ;AACrD,SAASC,uBAAuB,QAAQ;AAIxC,SAASC,qBAAqB,QAAQ;AAEtC;AACA,SAASC,gBAAgB,EAAEC,cAAc,QAAQ;AAEjD,MAAMC,2BAAA,GAAkF,CACtF,QACA,eACA,SACA,SACD;AAED,OAAO,MAAMC,WAAA,GAAiCA,CAAC;EAC7CC,EAAE;EACFC,oBAAoB;EACpBC,cAAc;EACdC,IAAI;EACJC,WAAW;EACXC,cAAc;EACdC,UAAU;EACVC,sBAAsB;EACtBC,SAAS;EACTC,SAAS;EACTC,gBAAgB;EAChBC,QAAQ;EACRC,SAAS;EACTC,UAAU;EACVC,gBAAgB;EAChBC,IAAI;EACJC,WAAW;EACXC,WAAW;EACXC,QAAA,EAAUC,iBAAiB;EAC3BC,eAAe;EACfC,GAAG;EACHC,UAAU;EACVC;AAAW,CACZ;EACC;EACA,MAAMC,qBAAA,GACJpB,WAAA,CAAYqB,KAAK,EAAEC,UAAA,KAClB,iBAAiBtB,WAAA,CAAYqB,KAAK,CAACC,UAAU,IAAI,gBAAgBtB,WAAA,CAAYqB,KAAK,CAACC,UAAU,CAAD;EAE/F,MAAMC,cAAA,GACJP,eAAA,IAAmB,CAACV,gBAAA,IAAoBA,gBAAA,KAAqBK,IAAA,IAAQS,qBAAA;EAEvE,IAAI,CAACG,cAAA,IAAkB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","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"renderField.js","names":["getTranslation","createClientField","MissingEditorProp","fieldIsHiddenOrDisabled","RenderServerComponent","FieldDescription","WatchCondition","defaultUIFieldComponentKeys","renderField","id","clientFieldSchemaMap","collectionSlug","data","fieldConfig","fieldSchemaMap","fieldState","forceCreateClientField","formState","indexPath","lastRenderedPath","mockRSCs","operation","parentPath","parentSchemaPath","path","permissions","preferences","readOnly","readOnlyFromProps","renderAllFields","req","schemaPath","siblingData","hasBeforeOrAfterInput","admin","components","requiresRender","type","clientField","get","defaultIDType","payload","config","db","field","i18n","importMap","clientProps","customComponents","includes","serverProps","user","value","name","rows","forEach","row","rowIndex","rowLastRenderedPath","rowPath","rowRequiresRender","RowLabel","Component","key","rowLabel","labels","singular","String","padStart","rowNumber","blockTypeToMatch","blockType","blockConfig","blocks","blockReferences","find","block","slug","Label","Object","keys","length","description","editor","Error","Field","_jsx","FieldComponent","sanitizedEditorConfig","editorConfig","undefined","Description","t","AfterInput","afterInput","BeforeInput","beforeInput"],"sources":["../../../src/forms/fieldSchemasToFormState/renderField.tsx"],"sourcesContent":["import type {\n ClientComponentProps,\n ClientField,\n FieldPaths,\n FlattenedBlock,\n ServerComponentProps,\n} from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { createClientField, MissingEditorProp } from 'payload'\nimport { fieldIsHiddenOrDisabled } from 'payload/shared'\n\nimport type { RenderFieldMethod } from './types.js'\n\nimport { RenderServerComponent } from '../../elements/RenderServerComponent/index.js'\n\n// eslint-disable-next-line payload/no-imports-from-exports-dir -- MUST reference the exports dir: https://github.com/payloadcms/payload/issues/12002#issuecomment-2791493587\nimport { FieldDescription, WatchCondition } from '../../exports/client/index.js'\n\nconst defaultUIFieldComponentKeys: Array<'Cell' | 'Description' | 'Field' | 'Filter'> = [\n 'Cell',\n 'Description',\n 'Field',\n 'Filter',\n]\n\nexport const renderField: RenderFieldMethod = ({\n id,\n clientFieldSchemaMap,\n collectionSlug,\n data,\n fieldConfig,\n fieldSchemaMap,\n fieldState,\n forceCreateClientField,\n formState,\n indexPath,\n lastRenderedPath,\n mockRSCs,\n operation,\n parentPath,\n parentSchemaPath,\n path,\n permissions,\n preferences,\n readOnly: readOnlyFromProps,\n renderAllFields,\n req,\n schemaPath,\n siblingData,\n}) => {\n // Fields with beforeInput/afterInput need custom components created, so they require render\n const hasBeforeOrAfterInput =\n fieldConfig.admin?.components &&\n ('beforeInput' in fieldConfig.admin.components || 'afterInput' in fieldConfig.admin.components)\n\n const requiresRender =\n renderAllFields || !lastRenderedPath || lastRenderedPath !== path || hasBeforeOrAfterInput\n\n if (!requiresRender && fieldConfig.type !== 'array' && fieldConfig.type !== 'blocks') {\n return\n }\n\n const clientField =\n clientFieldSchemaMap && !forceCreateClientField\n ? (clientFieldSchemaMap.get(schemaPath) as ClientField)\n : createClientField({\n defaultIDType: req.payload.config.db.defaultIDType,\n field: fieldConfig,\n i18n: req.i18n,\n importMap: req.payload.importMap,\n })\n\n const clientProps: ClientComponentProps & Partial<FieldPaths> = {\n field: clientField,\n path,\n permissions,\n readOnly:\n readOnlyFromProps === true\n ? true\n : typeof permissions === 'boolean'\n ? !permissions\n : !permissions?.[operation],\n schemaPath,\n }\n\n if (fieldState?.customComponents) {\n clientProps.customComponents = fieldState.customComponents\n }\n\n // fields with subfields\n if (['array', 'blocks', 'collapsible', 'group', 'row', 'tabs'].includes(fieldConfig.type)) {\n clientProps.indexPath = indexPath\n clientProps.parentPath = parentPath\n clientProps.parentSchemaPath = parentSchemaPath\n }\n\n const serverProps: ServerComponentProps = {\n id,\n clientField,\n clientFieldSchemaMap,\n data,\n field: fieldConfig,\n fieldSchemaMap,\n permissions,\n // TODO: Should we pass explicit values? initialValue, value, valid\n // value and initialValue should be typed\n collectionSlug,\n formState,\n i18n: req.i18n,\n operation,\n payload: req.payload,\n preferences,\n req,\n siblingData,\n user: req.user,\n value: 'name' in fieldConfig && data?.[fieldConfig.name],\n }\n\n switch (fieldConfig.type) {\n case 'array': {\n fieldState?.rows?.forEach((row, rowIndex) => {\n const rowLastRenderedPath = row.lastRenderedPath\n\n const rowPath = `${path}.${rowIndex}`\n\n const rowRequiresRender =\n renderAllFields || !rowLastRenderedPath || rowLastRenderedPath !== rowPath\n\n if (!rowRequiresRender) {\n return\n }\n\n row.lastRenderedPath = rowPath\n\n if (fieldConfig.admin?.components && 'RowLabel' in fieldConfig.admin.components) {\n if (!row.customComponents) {\n row.customComponents = {}\n }\n\n row.customComponents.RowLabel = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.RowLabel,\n importMap: req.payload.importMap,\n key: `${rowIndex}`,\n serverProps: {\n ...serverProps,\n rowLabel: `${getTranslation(fieldConfig.labels.singular, req.i18n)} ${String(\n rowIndex + 1,\n ).padStart(2, '0')}`,\n rowNumber: rowIndex + 1,\n },\n })\n : 'Mock'\n }\n })\n\n break\n }\n\n case 'blocks': {\n fieldState?.rows?.forEach((row, rowIndex) => {\n const rowLastRenderedPath = row.lastRenderedPath\n\n const rowPath = `${path}.${rowIndex}`\n\n const rowRequiresRender =\n renderAllFields || !rowLastRenderedPath || rowLastRenderedPath !== rowPath\n\n if (!rowRequiresRender) {\n return\n }\n\n row.lastRenderedPath = rowPath\n\n const blockTypeToMatch: string = row.blockType\n\n const blockConfig =\n req.payload.blocks[blockTypeToMatch] ??\n ((fieldConfig.blockReferences ?? fieldConfig.blocks).find(\n (block) => typeof block !== 'string' && block.slug === blockTypeToMatch,\n ) as FlattenedBlock | undefined)\n\n if (blockConfig.admin?.components && 'Label' in blockConfig.admin.components) {\n if (!fieldState.rows[rowIndex]?.customComponents) {\n fieldState.rows[rowIndex].customComponents = {}\n }\n\n fieldState.rows[rowIndex].customComponents.RowLabel = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component: blockConfig.admin.components.Label,\n importMap: req.payload.importMap,\n key: `${rowIndex}`,\n serverProps: {\n ...serverProps,\n blockType: row.blockType,\n rowLabel: `${getTranslation(blockConfig.labels.singular, req.i18n)} ${String(\n rowIndex + 1,\n ).padStart(2, '0')}`,\n rowNumber: rowIndex + 1,\n },\n })\n : 'Mock'\n }\n })\n\n break\n }\n }\n\n if (!requiresRender) {\n return\n }\n\n /**\n * Set the `lastRenderedPath` equal to the new path of the field, this will prevent it from being rendered again\n */\n fieldState.lastRenderedPath = path\n\n if (fieldIsHiddenOrDisabled(clientField)) {\n return\n }\n\n /**\n * Only create the `customComponents` object if needed.\n * This will prevent unnecessary data from being transferred to the client.\n */\n if (fieldConfig.admin) {\n if (\n (Object.keys(fieldConfig.admin.components || {}).length > 0 ||\n fieldConfig.type === 'richText' ||\n ('description' in fieldConfig.admin &&\n typeof fieldConfig.admin.description === 'function')) &&\n !fieldState?.customComponents\n ) {\n fieldState.customComponents = {}\n }\n }\n\n switch (fieldConfig.type) {\n case 'richText': {\n if (!fieldConfig?.editor) {\n throw new MissingEditorProp(fieldConfig) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof fieldConfig?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n if (!fieldConfig.admin) {\n fieldConfig.admin = {}\n }\n\n if (!fieldConfig.admin.components) {\n fieldConfig.admin.components = {}\n }\n\n fieldState.customComponents.Field = !mockRSCs ? (\n <WatchCondition path={path}>\n {RenderServerComponent({\n clientProps,\n Component: fieldConfig.editor.FieldComponent,\n importMap: req.payload.importMap,\n serverProps: {\n ...serverProps,\n // Manually inject lexical-specific `sanitizedEditorConfig` server prop, in order to reduce the size of the field schema.\n // Otherwise, the editorConfig would be included twice - once on the top-level, and once as part of the `FieldComponent` server props.\n sanitizedEditorConfig:\n 'editorConfig' in fieldConfig.editor ? fieldConfig.editor.editorConfig : undefined,\n },\n })}\n </WatchCondition>\n ) : (\n 'Mock'\n )\n\n break\n }\n\n case 'ui': {\n if (fieldConfig?.admin?.components) {\n // Render any extra, untyped components\n for (const key in fieldConfig.admin.components) {\n if (key in defaultUIFieldComponentKeys) {\n continue\n }\n\n const Component = fieldConfig.admin.components[key]\n\n fieldState.customComponents[key] = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component,\n importMap: req.payload.importMap,\n key: `field.admin.components.${key}`,\n serverProps,\n })\n : 'Mock'\n }\n }\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldConfig.admin) {\n if (\n 'description' in fieldConfig.admin &&\n typeof fieldConfig.admin?.description === 'function'\n ) {\n fieldState.customComponents.Description = !mockRSCs ? (\n <FieldDescription\n description={fieldConfig.admin?.description({\n i18n: req.i18n,\n t: req.i18n.t,\n })}\n path={path}\n />\n ) : (\n 'Mock'\n )\n }\n\n if (fieldConfig.admin?.components) {\n if ('afterInput' in fieldConfig.admin.components) {\n fieldState.customComponents.AfterInput = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.afterInput,\n importMap: req.payload.importMap,\n key: `field.admin.components.afterInput.${path}`,\n serverProps,\n })\n : 'Mock'\n }\n\n if ('beforeInput' in fieldConfig.admin.components) {\n fieldState.customComponents.BeforeInput = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.beforeInput,\n importMap: req.payload.importMap,\n key: `field.admin.components.beforeInput.${path}`,\n serverProps,\n })\n : 'Mock'\n }\n\n if ('Description' in fieldConfig.admin.components) {\n fieldState.customComponents.Description = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Description,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Description',\n serverProps,\n })\n : 'Mock'\n }\n\n if ('Error' in fieldConfig.admin.components) {\n fieldState.customComponents.Error = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Error,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Error',\n serverProps,\n })\n : 'Mock'\n }\n\n if ('Label' in fieldConfig.admin.components) {\n fieldState.customComponents.Label = !mockRSCs\n ? RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Label,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Label',\n serverProps,\n })\n : 'Mock'\n }\n\n if ('Field' in fieldConfig.admin.components) {\n fieldState.customComponents.Field = !mockRSCs ? (\n <WatchCondition path={path}>\n {RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Field,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Field',\n serverProps,\n })}\n </WatchCondition>\n ) : (\n 'Mock'\n )\n }\n }\n }\n}\n"],"mappings":";AAQA,SAASA,cAAc,QAAQ;AAC/B,SAASC,iBAAiB,EAAEC,iBAAiB,QAAQ;AACrD,SAASC,uBAAuB,QAAQ;AAIxC,SAASC,qBAAqB,QAAQ;AAEtC;AACA,SAASC,gBAAgB,EAAEC,cAAc,QAAQ;AAEjD,MAAMC,2BAAA,GAAkF,CACtF,QACA,eACA,SACA,SACD;AAED,OAAO,MAAMC,WAAA,GAAiCA,CAAC;EAC7CC,EAAE;EACFC,oBAAoB;EACpBC,cAAc;EACdC,IAAI;EACJC,WAAW;EACXC,cAAc;EACdC,UAAU;EACVC,sBAAsB;EACtBC,SAAS;EACTC,SAAS;EACTC,gBAAgB;EAChBC,QAAQ;EACRC,SAAS;EACTC,UAAU;EACVC,gBAAgB;EAChBC,IAAI;EACJC,WAAW;EACXC,WAAW;EACXC,QAAA,EAAUC,iBAAiB;EAC3BC,eAAe;EACfC,GAAG;EACHC,UAAU;EACVC;AAAW,CACZ;EACC;EACA,MAAMC,qBAAA,GACJpB,WAAA,CAAYqB,KAAK,EAAEC,UAAA,KAClB,iBAAiBtB,WAAA,CAAYqB,KAAK,CAACC,UAAU,IAAI,gBAAgBtB,WAAA,CAAYqB,KAAK,CAACC,UAAU,CAAD;EAE/F,MAAMC,cAAA,GACJP,eAAA,IAAmB,CAACV,gBAAA,IAAoBA,gBAAA,KAAqBK,IAAA,IAAQS,qBAAA;EAEvE,IAAI,CAACG,cAAA,IAAkBvB,WAAA,CAAYwB,IAAI,KAAK,WAAWxB,WAAA,CAAYwB,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1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueue.js","names":["useCallback","useRef","useQueue","queue","isProcessing","queueTask","fn","options","current","push","processQueue","beforeProcess","shouldContinue","length","latestTask","pop","err","console","error","afterProcess"],"sources":["../../src/hooks/useQueue.ts"],"sourcesContent":["import { useCallback, useRef } from 'react'\n\ntype QueuedFunction = () => Promise<void>\n\ntype QueuedTaskOptions = {\n /**\n * A function that is called after the queue has processed a function\n * Used to perform side effects after processing the queue\n * @returns {void}\n */\n afterProcess?: () => void\n /**\n * A function that can be used to prevent the queue from processing under certain conditions\n * Can also be used to perform side effects before processing the queue\n * @returns {boolean} If `false`, the queue will not process\n */\n beforeProcess?: () => boolean | void\n}\n\ntype QueueTask = (fn: QueuedFunction, options?: QueuedTaskOptions) => void\n\n/**\n * A React hook that allows you to queue up functions to be executed in order.\n * This is useful when you need to ensure long running networks requests are processed sequentially.\n * Builds up a \"queue\" of functions to be executed in order, only ever processing the last function in the queue.\n * This ensures that a long queue of tasks doesn't cause a backlog of tasks to be processed.\n * E.g. if you queue a task and it begins running, then you queue 9 more tasks:\n * 1. The currently task will finish\n * 2. The next task in the queue will run\n * 3. All remaining tasks will be discarded\n * @returns {queueTask} A function used to queue a function.\n * @example\n * const { queueTask } = useQueue()\n * queueTask(async () => {\n * await fetch('https://api.example.com')\n * })\n */\nexport function useQueue(): {\n queueTask: QueueTask\n} {\n const queue = useRef<QueuedFunction[]>([])\n\n const isProcessing = useRef(false)\n\n const queueTask = useCallback<QueueTask>((fn, options) => {\n queue.current.push(fn)\n\n async function processQueue() {\n if (isProcessing.current) {\n return\n }\n\n // Allow the consumer to prevent the queue from processing under certain conditions\n if (typeof options?.beforeProcess === 'function') {\n const shouldContinue = options.beforeProcess()\n\n if (shouldContinue === false) {\n return\n }\n }\n\n while (queue.current.length > 0) {\n const latestTask = queue.current.pop() // Only process the last task in the queue\n queue.current = [] // Discard all other tasks\n\n isProcessing.current = true\n\n try {\n await latestTask()\n } catch (err) {\n console.error('Error in queued function:', err) // eslint-disable-line no-console\n } finally {\n isProcessing.current = false\n\n if (typeof options?.afterProcess === 'function') {\n options.afterProcess()\n }\n }\n }\n }\n\n void processQueue()\n }, [])\n\n return { queueTask }\n}\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,MAAM,QAAQ;AAqBpC;;;;;;;;;;;;;;;;AAgBA,OAAO,SAASC,SAAA;EAGd,MAAMC,KAAA,GAAQF,MAAA,CAAyB,EAAE;EAEzC,MAAMG,YAAA,GAAeH,MAAA,CAAO;EAE5B,MAAMI,SAAA,GAAYL,WAAA,CAAuB,CAACM,EAAA,EAAIC,OAAA;IAC5CJ,KAAA,CAAMK,OAAO,CAACC,IAAI,CAACH,EAAA;IAEnB,eAAeI,aAAA;MACb,IAAIN,YAAA,CAAaI,OAAO,EAAE;QACxB;MACF;MAEA;MACA,IAAI,OAAOD,OAAA,EAASI,aAAA,KAAkB,YAAY;QAChD,MAAMC,cAAA,GAAiBL,OAAA,CAAQI,aAAa;QAE5C,IAAIC,cAAA,KAAmB,OAAO;UAC5B;QACF;MACF;MAEA,OAAOT,KAAA,CAAMK,OAAO,CAACK,MAAM,GAAG,GAAG;QAC/B,MAAMC,UAAA,GAAaX,KAAA,CAAMK,OAAO,CAACO,GAAG,GAAG;
|
|
1
|
+
{"version":3,"file":"useQueue.js","names":["useCallback","useRef","useQueue","queue","isProcessing","queueTask","fn","options","current","push","processQueue","beforeProcess","shouldContinue","length","latestTask","pop","err","console","error","afterProcess"],"sources":["../../src/hooks/useQueue.ts"],"sourcesContent":["import { useCallback, useRef } from 'react'\n\ntype QueuedFunction = () => Promise<void>\n\ntype QueuedTaskOptions = {\n /**\n * A function that is called after the queue has processed a function\n * Used to perform side effects after processing the queue\n * @returns {void}\n */\n afterProcess?: () => void\n /**\n * A function that can be used to prevent the queue from processing under certain conditions\n * Can also be used to perform side effects before processing the queue\n * @returns {boolean} If `false`, the queue will not process\n */\n beforeProcess?: () => boolean | void\n}\n\ntype QueueTask = (fn: QueuedFunction, options?: QueuedTaskOptions) => void\n\n/**\n * A React hook that allows you to queue up functions to be executed in order.\n * This is useful when you need to ensure long running networks requests are processed sequentially.\n * Builds up a \"queue\" of functions to be executed in order, only ever processing the last function in the queue.\n * This ensures that a long queue of tasks doesn't cause a backlog of tasks to be processed.\n * E.g. if you queue a task and it begins running, then you queue 9 more tasks:\n * 1. The currently task will finish\n * 2. The next task in the queue will run\n * 3. All remaining tasks will be discarded\n * @returns {queueTask} A function used to queue a function.\n * @example\n * const { queueTask } = useQueue()\n * queueTask(async () => {\n * await fetch('https://api.example.com')\n * })\n */\nexport function useQueue(): {\n queueTask: QueueTask\n} {\n const queue = useRef<QueuedFunction[]>([])\n\n const isProcessing = useRef(false)\n\n const queueTask = useCallback<QueueTask>((fn, options) => {\n queue.current.push(fn)\n\n async function processQueue() {\n if (isProcessing.current) {\n return\n }\n\n // Allow the consumer to prevent the queue from processing under certain conditions\n if (typeof options?.beforeProcess === 'function') {\n const shouldContinue = options.beforeProcess()\n\n if (shouldContinue === false) {\n return\n }\n }\n\n while (queue.current.length > 0) {\n const latestTask = queue.current.pop() // Only process the last task in the queue\n queue.current = [] // Discard all other tasks\n\n isProcessing.current = true\n\n try {\n await latestTask()\n } catch (err) {\n console.error('Error in queued function:', err) // eslint-disable-line no-console\n } finally {\n isProcessing.current = false\n\n if (typeof options?.afterProcess === 'function') {\n options.afterProcess()\n }\n }\n }\n }\n\n void processQueue()\n }, [])\n\n return { queueTask }\n}\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,MAAM,QAAQ;AAqBpC;;;;;;;;;;;;;;;;AAgBA,OAAO,SAASC,SAAA;EAGd,MAAMC,KAAA,GAAQF,MAAA,CAAyB,EAAE;EAEzC,MAAMG,YAAA,GAAeH,MAAA,CAAO;EAE5B,MAAMI,SAAA,GAAYL,WAAA,CAAuB,CAACM,EAAA,EAAIC,OAAA;IAC5CJ,KAAA,CAAMK,OAAO,CAACC,IAAI,CAACH,EAAA;IAEnB,eAAeI,aAAA;MACb,IAAIN,YAAA,CAAaI,OAAO,EAAE;QACxB;MACF;MAEA;MACA,IAAI,OAAOD,OAAA,EAASI,aAAA,KAAkB,YAAY;QAChD,MAAMC,cAAA,GAAiBL,OAAA,CAAQI,aAAa;QAE5C,IAAIC,cAAA,KAAmB,OAAO;UAC5B;QACF;MACF;MAEA,OAAOT,KAAA,CAAMK,OAAO,CAACK,MAAM,GAAG,GAAG;QAC/B,MAAMC,UAAA,GAAaX,KAAA,CAAMK,OAAO,CAACO,GAAG,GAAG;AAAA;QACvCZ,KAAA,CAAMK,OAAO,GAAG,EAAE,EAAC;QAEnBJ,YAAA,CAAaI,OAAO,GAAG;QAEvB,IAAI;UACF,MAAMM,UAAA;QACR,EAAE,OAAOE,GAAA,EAAK;UACZC,OAAA,CAAQC,KAAK,CAAC,6BAA6BF,GAAA,GAAK;QAClD,UAAU;UACRZ,YAAA,CAAaI,OAAO,GAAG;UAEvB,IAAI,OAAOD,OAAA,EAASY,YAAA,KAAiB,YAAY;YAC/CZ,OAAA,CAAQY,YAAY;UACtB;QACF;MACF;IACF;IAEA,KAAKT,YAAA;EACP,GAAG,EAAE;EAEL,OAAO;IAAEL;EAAU;AACrB","ignoreList":[]}
|
|
@@ -44,7 +44,7 @@ export const buildColumnState = args => {
|
|
|
44
44
|
keepPresentationalFields: true,
|
|
45
45
|
moveSubFieldsToTop: true
|
|
46
46
|
}) // TODO: think of a way to avoid this additional flatten
|
|
47
|
-
|
|
47
|
+
;
|
|
48
48
|
// place the `ID` field first, if it exists
|
|
49
49
|
// do the same for the `useAsTitle` field with precedence over the `ID` field
|
|
50
50
|
// then sort the rest of the fields based on the `defaultColumns` or `columns`
|
|
@@ -77,7 +77,7 @@ export const buildColumnState = args => {
|
|
|
77
77
|
const hasCustomCell = serverField?.admin && 'components' in serverField.admin && serverField.admin.components && 'Cell' in serverField.admin.components && serverField.admin.components.Cell;
|
|
78
78
|
if (serverField && serverField.type === 'group' && !hasCustomCell) {
|
|
79
79
|
return acc // skip any group without a custom cell
|
|
80
|
-
|
|
80
|
+
;
|
|
81
81
|
}
|
|
82
82
|
const columnPref = columns?.find(preference => clientField && 'name' in clientField && preference.accessor === accessor);
|
|
83
83
|
const isActive = isColumnActive({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fieldIsHiddenOrDisabled","fieldIsID","fieldIsPresentationalOnly","flattenTopLevelFields","React","RenderServerComponent","SortColumn","filterFieldsWithPermissions","isColumnActive","renderCell","sortFieldMap","buildColumnState","args","beforeRows","clientFields","collectionSlug","columns","customCellProps","dataType","docs","enableLinkedCell","enableRowSelections","fieldPermissions","i18n","payload","req","serverFields","sortColumnProps","useAsTitle","viewType","sortedFieldMap","fields","keepPresentationalFields","moveSubFieldsToTop","_sortedFieldMap","idFieldIndex","findIndex","field","idField","splice","unshift","useAsTitleFieldIndex","name","useAsTitleField","sortTo","activeColumnsIndices","sorted","reduce","acc","clientField","colIndex","accessor","undefined","serverField","find","f","fAccessor","hasCustomCell","admin","components","Cell","type","columnPref","preference","isActive","column","includes","push","CustomLabel","CustomLabelToRender","Label","clientProps","customLabelServerProps","Component","importMap","serverProps","fieldAffectsDataSubFields","label","labelWithPrefix","dotAccessor","replace","isVirtualField","virtual","Heading","_jsx","disable","active","renderedCells","map","doc","rowIndex","relationTo","columnIndex","value","isLinkedColumn"],"sources":["../../../../src/providers/TableColumns/buildColumnState/index.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n ClientComponentProps,\n ClientField,\n CollectionPreferences,\n CollectionSlug,\n Column,\n DefaultCellComponentProps,\n Document,\n Field,\n PaginatedDocs,\n Payload,\n PayloadRequest,\n SanitizedCollectionConfig,\n SanitizedFieldsPermissions,\n ServerComponentProps,\n StaticLabel,\n ViewTypes,\n} from 'payload'\n\nimport {\n fieldIsHiddenOrDisabled,\n fieldIsID,\n fieldIsPresentationalOnly,\n flattenTopLevelFields,\n} from 'payload/shared'\nimport React from 'react'\n\nimport type { SortColumnProps } from '../../../elements/SortColumn/index.js'\n\nimport { RenderServerComponent } from '../../../elements/RenderServerComponent/index.js'\nimport {\n SortColumn,\n // eslint-disable-next-line payload/no-imports-from-exports-dir -- MUST reference the exports dir: https://github.com/payloadcms/payload/issues/12002#issuecomment-2791493587\n} from '../../../exports/client/index.js'\nimport { filterFieldsWithPermissions } from './filterFieldsWithPermissions.js'\nimport { isColumnActive } from './isColumnActive.js'\nimport { renderCell } from './renderCell.js'\nimport { sortFieldMap } from './sortFieldMap.js'\n\nexport type BuildColumnStateArgs = {\n beforeRows?: Column[]\n clientFields: ClientField[]\n columns?: CollectionPreferences['columns']\n customCellProps: DefaultCellComponentProps['customCellProps']\n enableLinkedCell?: boolean\n enableRowSelections: boolean\n enableRowTypes?: boolean\n fieldPermissions?: SanitizedFieldsPermissions\n i18n: I18nClient\n payload: Payload\n req?: PayloadRequest\n serverFields: Field[]\n sortColumnProps?: Partial<SortColumnProps>\n useAsTitle: SanitizedCollectionConfig['admin']['useAsTitle']\n viewType?: ViewTypes\n} & (\n | {\n collectionSlug: CollectionSlug\n dataType: 'monomorphic'\n docs: PaginatedDocs['docs']\n }\n | {\n collectionSlug?: undefined\n dataType: 'polymorphic'\n docs: {\n relationTo: CollectionSlug\n value: Document\n }[]\n }\n)\n\nexport const buildColumnState = (args: BuildColumnStateArgs): Column[] => {\n const {\n beforeRows,\n clientFields,\n collectionSlug,\n columns,\n customCellProps,\n dataType,\n docs,\n enableLinkedCell = true,\n enableRowSelections,\n fieldPermissions,\n i18n,\n payload,\n req,\n serverFields,\n sortColumnProps,\n useAsTitle,\n viewType,\n } = args\n\n // clientFields contains the fake `id` column\n let sortedFieldMap = flattenTopLevelFields(\n filterFieldsWithPermissions({ fieldPermissions, fields: clientFields }),\n {\n i18n,\n keepPresentationalFields: true,\n moveSubFieldsToTop: true,\n },\n ) as ClientField[]\n\n let _sortedFieldMap = flattenTopLevelFields(\n filterFieldsWithPermissions({\n fieldPermissions,\n fields: serverFields,\n }),\n {\n i18n,\n keepPresentationalFields: true,\n moveSubFieldsToTop: true,\n },\n ) as Field[] // TODO: think of a way to avoid this additional flatten\n\n // place the `ID` field first, if it exists\n // do the same for the `useAsTitle` field with precedence over the `ID` field\n // then sort the rest of the fields based on the `defaultColumns` or `columns`\n const idFieldIndex = sortedFieldMap?.findIndex((field) => fieldIsID(field))\n\n if (idFieldIndex > -1) {\n const idField = sortedFieldMap.splice(idFieldIndex, 1)[0]\n sortedFieldMap.unshift(idField)\n }\n\n const useAsTitleFieldIndex = useAsTitle\n ? sortedFieldMap.findIndex((field) => 'name' in field && field.name === useAsTitle)\n : -1\n\n if (useAsTitleFieldIndex > -1) {\n const useAsTitleField = sortedFieldMap.splice(useAsTitleFieldIndex, 1)[0]\n sortedFieldMap.unshift(useAsTitleField)\n }\n\n const sortTo = columns\n\n if (sortTo) {\n // sort the fields to the order of `defaultColumns` or `columns`\n sortedFieldMap = sortFieldMap<ClientField>(sortedFieldMap, sortTo)\n _sortedFieldMap = sortFieldMap<Field>(_sortedFieldMap, sortTo) // TODO: think of a way to avoid this additional sort\n }\n\n const activeColumnsIndices = []\n\n const sorted: Column[] = sortedFieldMap?.reduce((acc, clientField, colIndex) => {\n if (fieldIsHiddenOrDisabled(clientField) && !fieldIsID(clientField)) {\n return acc\n }\n\n const accessor =\n (clientField as any).accessor ?? ('name' in clientField ? clientField.name : undefined)\n\n const serverField = _sortedFieldMap.find((f) => {\n const fAccessor = (f as any).accessor ?? ('name' in f ? f.name : undefined)\n return fAccessor === accessor\n })\n\n const hasCustomCell =\n serverField?.admin &&\n 'components' in serverField.admin &&\n serverField.admin.components &&\n 'Cell' in serverField.admin.components &&\n serverField.admin.components.Cell\n\n if (serverField && serverField.type === 'group' && !hasCustomCell) {\n return acc // skip any group without a custom cell\n }\n\n const columnPref = columns?.find(\n (preference) => clientField && 'name' in clientField && preference.accessor === accessor,\n )\n\n const isActive = isColumnActive({\n accessor,\n activeColumnsIndices,\n column: columnPref,\n columns,\n })\n\n if (isActive && !activeColumnsIndices.includes(colIndex)) {\n activeColumnsIndices.push(colIndex)\n }\n\n let CustomLabel = undefined\n\n if (dataType === 'monomorphic') {\n const CustomLabelToRender =\n serverField &&\n 'admin' in serverField &&\n 'components' in serverField.admin &&\n 'Label' in serverField.admin.components &&\n serverField.admin.components.Label !== undefined // let it return `null`\n ? serverField.admin.components.Label\n : undefined\n\n // TODO: customComponent will be optional in v4\n const clientProps: Omit<ClientComponentProps, 'customComponents'> = {\n field: clientField,\n }\n\n const customLabelServerProps: Pick<\n ServerComponentProps,\n 'clientField' | 'collectionSlug' | 'field' | 'i18n' | 'payload'\n > = {\n clientField,\n collectionSlug,\n field: serverField,\n i18n,\n payload,\n }\n\n CustomLabel = CustomLabelToRender\n ? RenderServerComponent({\n clientProps,\n Component: CustomLabelToRender,\n importMap: payload.importMap,\n serverProps: customLabelServerProps,\n })\n : undefined\n }\n\n const fieldAffectsDataSubFields =\n clientField &&\n clientField.type &&\n (clientField.type === 'array' ||\n clientField.type === 'group' ||\n clientField.type === 'blocks')\n\n const label =\n clientField && 'labelWithPrefix' in clientField && clientField.labelWithPrefix !== undefined\n ? clientField.labelWithPrefix\n : 'label' in clientField\n ? clientField.label\n : undefined\n\n // Convert accessor to dot notation specifically for SortColumn sorting behavior\n const dotAccessor = accessor?.replace(/-/g, '.')\n\n const isVirtualField = serverField && 'virtual' in serverField && serverField.virtual === true\n\n const Heading = (\n <SortColumn\n disable={\n fieldAffectsDataSubFields ||\n fieldIsPresentationalOnly(clientField) ||\n isVirtualField ||\n undefined\n }\n Label={CustomLabel}\n label={label as StaticLabel}\n name={dotAccessor}\n {...(sortColumnProps || {})}\n />\n )\n\n const column: Column = {\n accessor,\n active: isActive,\n CustomLabel,\n field: clientField,\n Heading,\n renderedCells: isActive\n ? docs.map((doc, rowIndex) => {\n return renderCell({\n clientField,\n collectionSlug: dataType === 'monomorphic' ? collectionSlug : doc.relationTo,\n columnIndex: colIndex,\n customCellProps,\n doc: dataType === 'monomorphic' ? doc : doc.value,\n enableRowSelections,\n i18n,\n isLinkedColumn: enableLinkedCell && colIndex === activeColumnsIndices[0],\n payload,\n req,\n rowIndex,\n serverField,\n viewType,\n })\n })\n : [],\n }\n\n acc.push(column)\n\n return acc\n }, [])\n\n if (beforeRows) {\n sorted.unshift(...beforeRows)\n }\n\n return sorted\n}\n"],"mappings":";AAoBA,SACEA,uBAAuB,EACvBC,SAAS,EACTC,yBAAyB,EACzBC,qBAAqB,QAChB;AACP,OAAOC,KAAA,MAAW;AAIlB,SAASC,qBAAqB,QAAQ;AACtC,SACEC,UAAU,QAEL;AACP,SAASC,2BAA2B,QAAQ;AAC5C,SAASC,cAAc,QAAQ;AAC/B,SAASC,UAAU,QAAQ;AAC3B,SAASC,YAAY,QAAQ;AAkC7B,OAAO,MAAMC,gBAAA,GAAoBC,IAAA;EAC/B,MAAM;IACJC,UAAU;IACVC,YAAY;IACZC,cAAc;IACdC,OAAO;IACPC,eAAe;IACfC,QAAQ;IACRC,IAAI;IACJC,gBAAA,GAAmB,IAAI;IACvBC,mBAAmB;IACnBC,gBAAgB;IAChBC,IAAI;IACJC,OAAO;IACPC,GAAG;IACHC,YAAY;IACZC,eAAe;IACfC,UAAU;IACVC;EAAQ,CACT,GAAGjB,IAAA;EAEJ;EACA,IAAIkB,cAAA,GAAiB3B,qBAAA,CACnBI,2BAAA,CAA4B;IAAEe,gBAAA;IAAkBS,MAAA,EAAQjB;EAAa,IACrE;IACES,IAAA;IACAS,wBAAA,EAA0B;IAC1BC,kBAAA,EAAoB;EACtB;EAGF,IAAIC,eAAA,GAAkB/B,qBAAA,CACpBI,2BAAA,CAA4B;IAC1Be,gBAAA;IACAS,MAAA,EAAQL;EACV,IACA;IACEH,IAAA;IACAS,wBAAA,EAA0B;IAC1BC,kBAAA,EAAoB;EACtB,EACW;EAAA;EAEb;EACA;EACA;EACA,MAAME,YAAA,GAAeL,cAAA,EAAgBM,SAAA,CAAWC,KAAA,IAAUpC,SAAA,CAAUoC,KA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AU;UAC5EC,WAAA,EAAa1C,QAAA;UACbjC,eAAA;UACAwE,GAAA,EAAKvE,QAAA,KAAa,gBAAgBuE,GAAA,GAAMA,GAAA,CAAII,KAAK;UACjDxE,mBAAA;UACAE,IAAA;UACAuE,cAAA,EAAgB1E,gBAAA,IAAoB8B,QAAA,KAAaL,oBAAoB,CAAC,EAAE;UACxErB,OAAA;UACAC,GAAA;UACAiE,QAAA;UACArC,WAAA;UACAxB;QACF;MACF,KACA;IACN;IAEAmB,GAAA,CAAImB,IAAI,CAACF,MAAA;IAET,OAAOjB,GAAA;EACT,GAAG,EAAE;EAEL,IAAInC,UAAA,EAAY;IACdiC,MAAA,CAAON,OAAO,IAAI3B,UAAA;EACpB;EAEA,OAAOiC,MAAA;AACT","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["fieldIsHiddenOrDisabled","fieldIsID","fieldIsPresentationalOnly","flattenTopLevelFields","React","RenderServerComponent","SortColumn","filterFieldsWithPermissions","isColumnActive","renderCell","sortFieldMap","buildColumnState","args","beforeRows","clientFields","collectionSlug","columns","customCellProps","dataType","docs","enableLinkedCell","enableRowSelections","fieldPermissions","i18n","payload","req","serverFields","sortColumnProps","useAsTitle","viewType","sortedFieldMap","fields","keepPresentationalFields","moveSubFieldsToTop","_sortedFieldMap","idFieldIndex","findIndex","field","idField","splice","unshift","useAsTitleFieldIndex","name","useAsTitleField","sortTo","activeColumnsIndices","sorted","reduce","acc","clientField","colIndex","accessor","undefined","serverField","find","f","fAccessor","hasCustomCell","admin","components","Cell","type","columnPref","preference","isActive","column","includes","push","CustomLabel","CustomLabelToRender","Label","clientProps","customLabelServerProps","Component","importMap","serverProps","fieldAffectsDataSubFields","label","labelWithPrefix","dotAccessor","replace","isVirtualField","virtual","Heading","_jsx","disable","active","renderedCells","map","doc","rowIndex","relationTo","columnIndex","value","isLinkedColumn"],"sources":["../../../../src/providers/TableColumns/buildColumnState/index.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n ClientComponentProps,\n ClientField,\n CollectionPreferences,\n CollectionSlug,\n Column,\n DefaultCellComponentProps,\n Document,\n Field,\n PaginatedDocs,\n Payload,\n PayloadRequest,\n SanitizedCollectionConfig,\n SanitizedFieldsPermissions,\n ServerComponentProps,\n StaticLabel,\n ViewTypes,\n} from 'payload'\n\nimport {\n fieldIsHiddenOrDisabled,\n fieldIsID,\n fieldIsPresentationalOnly,\n flattenTopLevelFields,\n} from 'payload/shared'\nimport React from 'react'\n\nimport type { SortColumnProps } from '../../../elements/SortColumn/index.js'\n\nimport { RenderServerComponent } from '../../../elements/RenderServerComponent/index.js'\nimport {\n SortColumn,\n // eslint-disable-next-line payload/no-imports-from-exports-dir -- MUST reference the exports dir: https://github.com/payloadcms/payload/issues/12002#issuecomment-2791493587\n} from '../../../exports/client/index.js'\nimport { filterFieldsWithPermissions } from './filterFieldsWithPermissions.js'\nimport { isColumnActive } from './isColumnActive.js'\nimport { renderCell } from './renderCell.js'\nimport { sortFieldMap } from './sortFieldMap.js'\n\nexport type BuildColumnStateArgs = {\n beforeRows?: Column[]\n clientFields: ClientField[]\n columns?: CollectionPreferences['columns']\n customCellProps: DefaultCellComponentProps['customCellProps']\n enableLinkedCell?: boolean\n enableRowSelections: boolean\n enableRowTypes?: boolean\n fieldPermissions?: SanitizedFieldsPermissions\n i18n: I18nClient\n payload: Payload\n req?: PayloadRequest\n serverFields: Field[]\n sortColumnProps?: Partial<SortColumnProps>\n useAsTitle: SanitizedCollectionConfig['admin']['useAsTitle']\n viewType?: ViewTypes\n} & (\n | {\n collectionSlug: CollectionSlug\n dataType: 'monomorphic'\n docs: PaginatedDocs['docs']\n }\n | {\n collectionSlug?: undefined\n dataType: 'polymorphic'\n docs: {\n relationTo: CollectionSlug\n value: Document\n }[]\n }\n)\n\nexport const buildColumnState = (args: BuildColumnStateArgs): Column[] => {\n const {\n beforeRows,\n clientFields,\n collectionSlug,\n columns,\n customCellProps,\n dataType,\n docs,\n enableLinkedCell = true,\n enableRowSelections,\n fieldPermissions,\n i18n,\n payload,\n req,\n serverFields,\n sortColumnProps,\n useAsTitle,\n viewType,\n } = args\n\n // clientFields contains the fake `id` column\n let sortedFieldMap = flattenTopLevelFields(\n filterFieldsWithPermissions({ fieldPermissions, fields: clientFields }),\n {\n i18n,\n keepPresentationalFields: true,\n moveSubFieldsToTop: true,\n },\n ) as ClientField[]\n\n let _sortedFieldMap = flattenTopLevelFields(\n filterFieldsWithPermissions({\n fieldPermissions,\n fields: serverFields,\n }),\n {\n i18n,\n keepPresentationalFields: true,\n moveSubFieldsToTop: true,\n },\n ) as Field[] // TODO: think of a way to avoid this additional flatten\n\n // place the `ID` field first, if it exists\n // do the same for the `useAsTitle` field with precedence over the `ID` field\n // then sort the rest of the fields based on the `defaultColumns` or `columns`\n const idFieldIndex = sortedFieldMap?.findIndex((field) => fieldIsID(field))\n\n if (idFieldIndex > -1) {\n const idField = sortedFieldMap.splice(idFieldIndex, 1)[0]\n sortedFieldMap.unshift(idField)\n }\n\n const useAsTitleFieldIndex = useAsTitle\n ? sortedFieldMap.findIndex((field) => 'name' in field && field.name === useAsTitle)\n : -1\n\n if (useAsTitleFieldIndex > -1) {\n const useAsTitleField = sortedFieldMap.splice(useAsTitleFieldIndex, 1)[0]\n sortedFieldMap.unshift(useAsTitleField)\n }\n\n const sortTo = columns\n\n if (sortTo) {\n // sort the fields to the order of `defaultColumns` or `columns`\n sortedFieldMap = sortFieldMap<ClientField>(sortedFieldMap, sortTo)\n _sortedFieldMap = sortFieldMap<Field>(_sortedFieldMap, sortTo) // TODO: think of a way to avoid this additional sort\n }\n\n const activeColumnsIndices = []\n\n const sorted: Column[] = sortedFieldMap?.reduce((acc, clientField, colIndex) => {\n if (fieldIsHiddenOrDisabled(clientField) && !fieldIsID(clientField)) {\n return acc\n }\n\n const accessor =\n (clientField as any).accessor ?? ('name' in clientField ? clientField.name : undefined)\n\n const serverField = _sortedFieldMap.find((f) => {\n const fAccessor = (f as any).accessor ?? ('name' in f ? f.name : undefined)\n return fAccessor === accessor\n })\n\n const hasCustomCell =\n serverField?.admin &&\n 'components' in serverField.admin &&\n serverField.admin.components &&\n 'Cell' in serverField.admin.components &&\n serverField.admin.components.Cell\n\n if (serverField && serverField.type === 'group' && !hasCustomCell) {\n return acc // skip any group without a custom cell\n }\n\n const columnPref = columns?.find(\n (preference) => clientField && 'name' in clientField && preference.accessor === accessor,\n )\n\n const isActive = isColumnActive({\n accessor,\n activeColumnsIndices,\n column: columnPref,\n columns,\n })\n\n if (isActive && !activeColumnsIndices.includes(colIndex)) {\n activeColumnsIndices.push(colIndex)\n }\n\n let CustomLabel = undefined\n\n if (dataType === 'monomorphic') {\n const CustomLabelToRender =\n serverField &&\n 'admin' in serverField &&\n 'components' in serverField.admin &&\n 'Label' in serverField.admin.components &&\n serverField.admin.components.Label !== undefined // let it return `null`\n ? serverField.admin.components.Label\n : undefined\n\n // TODO: customComponent will be optional in v4\n const clientProps: Omit<ClientComponentProps, 'customComponents'> = {\n field: clientField,\n }\n\n const customLabelServerProps: Pick<\n ServerComponentProps,\n 'clientField' | 'collectionSlug' | 'field' | 'i18n' | 'payload'\n > = {\n clientField,\n collectionSlug,\n field: serverField,\n i18n,\n payload,\n }\n\n CustomLabel = CustomLabelToRender\n ? RenderServerComponent({\n clientProps,\n Component: CustomLabelToRender,\n importMap: payload.importMap,\n serverProps: customLabelServerProps,\n })\n : undefined\n }\n\n const fieldAffectsDataSubFields =\n clientField &&\n clientField.type &&\n (clientField.type === 'array' ||\n clientField.type === 'group' ||\n clientField.type === 'blocks')\n\n const label =\n clientField && 'labelWithPrefix' in clientField && clientField.labelWithPrefix !== undefined\n ? clientField.labelWithPrefix\n : 'label' in clientField\n ? clientField.label\n : undefined\n\n // Convert accessor to dot notation specifically for SortColumn sorting behavior\n const dotAccessor = accessor?.replace(/-/g, '.')\n\n const isVirtualField = serverField && 'virtual' in serverField && serverField.virtual === true\n\n const Heading = (\n <SortColumn\n disable={\n fieldAffectsDataSubFields ||\n fieldIsPresentationalOnly(clientField) ||\n isVirtualField ||\n undefined\n }\n Label={CustomLabel}\n label={label as StaticLabel}\n name={dotAccessor}\n {...(sortColumnProps || {})}\n />\n )\n\n const column: Column = {\n accessor,\n active: isActive,\n CustomLabel,\n field: clientField,\n Heading,\n renderedCells: isActive\n ? docs.map((doc, rowIndex) => {\n return renderCell({\n clientField,\n collectionSlug: dataType === 'monomorphic' ? collectionSlug : doc.relationTo,\n columnIndex: colIndex,\n customCellProps,\n doc: dataType === 'monomorphic' ? doc : doc.value,\n enableRowSelections,\n i18n,\n isLinkedColumn: enableLinkedCell && colIndex === activeColumnsIndices[0],\n payload,\n req,\n rowIndex,\n serverField,\n viewType,\n })\n })\n : [],\n }\n\n acc.push(column)\n\n return acc\n }, [])\n\n if (beforeRows) {\n sorted.unshift(...beforeRows)\n }\n\n return sorted\n}\n"],"mappings":";AAoBA,SACEA,uBAAuB,EACvBC,SAAS,EACTC,yBAAyB,EACzBC,qBAAqB,QAChB;AACP,OAAOC,KAAA,MAAW;AAIlB,SAASC,qBAAqB,QAAQ;AACtC,SACEC,UAAU,QAEL;AACP,SAASC,2BAA2B,QAAQ;AAC5C,SAASC,cAAc,QAAQ;AAC/B,SAASC,UAAU,QAAQ;AAC3B,SAASC,YAAY,QAAQ;AAkC7B,OAAO,MAAMC,gBAAA,GAAoBC,IAAA;EAC/B,MAAM;IACJC,UAAU;IACVC,YAAY;IACZC,cAAc;IACdC,OAAO;IACPC,eAAe;IACfC,QAAQ;IACRC,IAAI;IACJC,gBAAA,GAAmB,IAAI;IACvBC,mBAAmB;IACnBC,gBAAgB;IAChBC,IAAI;IACJC,OAAO;IACPC,GAAG;IACHC,YAAY;IACZC,eAAe;IACfC,UAAU;IACVC;EAAQ,CACT,GAAGjB,IAAA;EAEJ;EACA,IAAIkB,cAAA,GAAiB3B,qBAAA,CACnBI,2BAAA,CAA4B;IAAEe,gBAAA;IAAkBS,MAAA,EAAQjB;EAAa,IACrE;IACES,IAAA;IACA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AI9B,MAAMsC,MAAA,GAAiB;MACrBd,QAAA;MACAmC,MAAA,EAAQtB,QAAA;MACRI,WAAA;MACA/B,KAAA,EAAOY,WAAA;MACPkC,OAAA;MACAI,aAAA,EAAevB,QAAA,GACX7C,IAAA,CAAKqE,GAAG,CAAC,CAACC,GAAA,EAAKC,QAAA;QACb,OAAOjF,UAAA,CAAW;UAChBwC,WAAA;UACAlC,cAAA,EAAgBG,QAAA,KAAa,gBAAgBH,cAAA,GAAiB0E,GAAA,CAAIE,UAAU;UAC5EC,WAAA,EAAa1C,QAAA;UACbjC,eAAA;UACAwE,GAAA,EAAKvE,QAAA,KAAa,gBAAgBuE,GAAA,GAAMA,GAAA,CAAII,KAAK;UACjDxE,mBAAA;UACAE,IAAA;UACAuE,cAAA,EAAgB1E,gBAAA,IAAoB8B,QAAA,KAAaL,oBAAoB,CAAC,EAAE;UACxErB,OAAA;UACAC,GAAA;UACAiE,QAAA;UACArC,WAAA;UACAxB;QACF;MACF,KACA;IACN;IAEAmB,GAAA,CAAImB,IAAI,CAACF,MAAA;IAET,OAAOjB,GAAA;EACT,GAAG,EAAE;EAEL,IAAInC,UAAA,EAAY;IACdiC,MAAA,CAAON,OAAO,IAAI3B,UAAA;EACpB;EAEA,OAAOiC,MAAA;AACT","ignoreList":[]}
|
|
@@ -107,7 +107,7 @@ export function renderCell({
|
|
|
107
107
|
if (serverField?.type === 'richText') {
|
|
108
108
|
if (!serverField?.editor) {
|
|
109
109
|
throw new MissingEditorProp(serverField) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor
|
|
110
|
-
|
|
110
|
+
;
|
|
111
111
|
}
|
|
112
112
|
if (typeof serverField?.editor === 'function') {
|
|
113
113
|
throw new Error('Attempted to access unsanitized rich text editor.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderCell.js","names":["MissingEditorProp","formatAdminURL","RenderCustomComponent","RenderServerComponent","DefaultCell","RenderDefaultCell","hasOptionLabelJSXElement","findValueFromPath","renderCell","clientField","collectionSlug","columnIndex","customCellProps","doc","enableRowSelections","i18n","isLinkedColumn","payload","req","rowIndex","serverField","viewType","baseCellClientProps","cellData","undefined","field","rowData","accessor","name","shouldLink","customLinkURL","collectionConfig","collections","config","formatDocURL","admin","adminRoute","routes","defaultURL","path","encodeURIComponent","String","id","customURL","_displayStatus","enrichedClientField","type","hasChangedOption","options","some","opt","value","label","t","cellClientProps","link","linkURL","cellServerProps","className","onClick","CustomCell","editor","Error","components","clientProps","Component","CellComponent","importMap","serverProps","CustomCellComponent","Cell","_jsx","CustomComponent","Fallback"],"sources":["../../../../src/providers/TableColumns/buildColumnState/renderCell.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n ClientField,\n DefaultCellComponentProps,\n DefaultServerCellComponentProps,\n Document,\n Field,\n Payload,\n PayloadRequest,\n ViewTypes,\n} from 'payload'\n\nimport { MissingEditorProp } from 'payload'\nimport { formatAdminURL } from 'payload/shared'\n\nimport { RenderCustomComponent } from '../../../elements/RenderCustomComponent/index.js'\nimport { RenderServerComponent } from '../../../elements/RenderServerComponent/index.js'\nimport {\n DefaultCell,\n RenderDefaultCell,\n // eslint-disable-next-line payload/no-imports-from-exports-dir -- MUST reference the exports dir: https://github.com/payloadcms/payload/issues/12002#issuecomment-2791493587\n} from '../../../exports/client/index.js'\nimport { hasOptionLabelJSXElement } from '../../../utilities/hasOptionLabelJSXElement.js'\nimport { findValueFromPath } from './findValueFromPath.js'\n\ntype RenderCellArgs = {\n readonly clientField: ClientField\n readonly collectionSlug: string\n readonly columnIndex: number\n readonly customCellProps: DefaultCellComponentProps['customCellProps']\n readonly doc: Document\n readonly enableRowSelections: boolean\n readonly i18n: I18nClient\n readonly isLinkedColumn: boolean\n readonly payload: Payload\n readonly req?: PayloadRequest\n readonly rowIndex: number\n readonly serverField: Field\n readonly viewType?: ViewTypes\n}\nexport function renderCell({\n clientField,\n collectionSlug,\n columnIndex,\n customCellProps,\n doc,\n enableRowSelections,\n i18n,\n isLinkedColumn,\n payload,\n req,\n rowIndex,\n serverField,\n viewType,\n}: RenderCellArgs) {\n const baseCellClientProps: DefaultCellComponentProps = {\n cellData: undefined,\n collectionSlug,\n customCellProps,\n field: clientField,\n rowData: undefined,\n viewType,\n }\n\n const accessor: string | undefined =\n ('accessor' in clientField ? (clientField.accessor as string) : undefined) ??\n ('name' in clientField ? clientField.name : undefined)\n\n // Check if there's a custom formatDocURL function for this linked column\n let shouldLink = isLinkedColumn\n let customLinkURL: string | undefined\n\n if (isLinkedColumn && req) {\n const collectionConfig = payload.collections[collectionSlug]?.config\n const formatDocURL = collectionConfig?.admin?.formatDocURL\n\n if (typeof formatDocURL === 'function') {\n // Generate the default URL that would normally be used\n const adminRoute = req.payload.config.routes?.admin || '/admin'\n const defaultURL = formatAdminURL({\n adminRoute,\n path: `/collections/${collectionSlug}${viewType === 'trash' ? '/trash' : ''}/${encodeURIComponent(String(doc.id))}`,\n })\n\n const customURL = formatDocURL({\n collectionSlug,\n defaultURL,\n doc,\n req,\n viewType,\n })\n\n if (customURL === null) {\n // formatDocURL returned null = disable linking entirely\n shouldLink = false\n } else if (typeof customURL === 'string') {\n // formatDocURL returned a string = use custom URL\n shouldLink = true\n customLinkURL = customURL\n } else {\n // formatDocURL returned unexpected type = disable linking for safety\n shouldLink = false\n }\n }\n }\n\n // For _status field, use _displayStatus if available (for showing \"changed\" status in list view)\n const cellData =\n 'name' in clientField && accessor === '_status' && '_displayStatus' in doc\n ? doc._displayStatus\n : 'name' in clientField\n ? findValueFromPath(doc, accessor)\n : undefined\n\n // For _status field, add 'changed' option for display purposes\n // The 'changed' status is computed at runtime\n let enrichedClientField = clientField\n if ('name' in clientField && accessor === '_status' && clientField.type === 'select') {\n const hasChangedOption = clientField.options?.some(\n (opt) => (typeof opt === 'object' ? opt.value : opt) === 'changed',\n )\n if (!hasChangedOption) {\n enrichedClientField = {\n ...clientField,\n options: [\n ...(clientField.options || []),\n {\n label: i18n.t('version:draftHasPublishedVersion'),\n value: 'changed',\n },\n ],\n }\n }\n }\n\n const cellClientProps: DefaultCellComponentProps = {\n ...baseCellClientProps,\n cellData,\n field: enrichedClientField,\n link: shouldLink,\n linkURL: customLinkURL,\n rowData: doc,\n }\n\n const cellServerProps: DefaultServerCellComponentProps = {\n cellData: cellClientProps.cellData,\n className: baseCellClientProps.className,\n collectionConfig: payload.collections[collectionSlug].config,\n collectionSlug,\n columnIndex,\n customCellProps: baseCellClientProps.customCellProps,\n field: serverField,\n i18n,\n link: shouldLink,\n linkURL: customLinkURL,\n onClick: baseCellClientProps.onClick,\n payload,\n rowData: doc,\n }\n\n let CustomCell = null\n\n if (serverField?.type === 'richText') {\n if (!serverField?.editor) {\n throw new MissingEditorProp(serverField) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof serverField?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n if (!serverField.admin) {\n serverField.admin = {}\n }\n\n if (!serverField.admin.components) {\n serverField.admin.components = {}\n }\n\n CustomCell = RenderServerComponent({\n clientProps: cellClientProps,\n Component: serverField.editor.CellComponent,\n importMap: payload.importMap,\n serverProps: cellServerProps,\n })\n } else {\n const CustomCellComponent = serverField?.admin?.components?.Cell\n\n if (CustomCellComponent) {\n CustomCell = RenderServerComponent({\n clientProps: cellClientProps,\n Component: CustomCellComponent,\n importMap: payload.importMap,\n serverProps: cellServerProps,\n })\n } else if (\n cellClientProps.cellData &&\n cellClientProps.field &&\n hasOptionLabelJSXElement(cellClientProps)\n ) {\n CustomCell = RenderServerComponent({\n clientProps: cellClientProps,\n Component: DefaultCell,\n importMap: payload.importMap,\n })\n } else {\n const CustomCellComponent = serverField?.admin?.components?.Cell\n\n if (CustomCellComponent) {\n CustomCell = RenderServerComponent({\n clientProps: cellClientProps,\n Component: CustomCellComponent,\n importMap: payload.importMap,\n serverProps: cellServerProps,\n })\n } else {\n CustomCell = undefined\n }\n }\n }\n\n return (\n <RenderCustomComponent\n CustomComponent={CustomCell}\n Fallback={\n <RenderDefaultCell\n clientProps={cellClientProps}\n columnIndex={columnIndex}\n enableRowSelections={enableRowSelections}\n isLinkedColumn={isLinkedColumn}\n />\n }\n key={`${rowIndex}-${columnIndex}`}\n />\n )\n}\n"],"mappings":";AAYA,SAASA,iBAAiB,QAAQ;AAClC,SAASC,cAAc,QAAQ;AAE/B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,qBAAqB,QAAQ;AACtC,SACEC,WAAW,EACXC,iBAAiB,QAEZ;AACP,SAASC,wBAAwB,QAAQ;AACzC,SAASC,iBAAiB,QAAQ;AAiBlC,OAAO,SAASC,WAAW;EACzBC,WAAW;EACXC,cAAc;EACdC,WAAW;EACXC,eAAe;EACfC,GAAG;EACHC,mBAAmB;EACnBC,IAAI;EACJC,cAAc;EACdC,OAAO;EACPC,GAAG;EACHC,QAAQ;EACRC,WAAW;EACXC;AAAQ,CACO;EACf,MAAMC,mBAAA,GAAiD;IACrDC,QAAA,EAAUC,SAAA;IACVd,cAAA;IACAE,eAAA;IACAa,KAAA,EAAOhB,WAAA;IACPiB,OAAA,EAASF,SAAA;IACTH;EACF;EAEA,MAAMM,QAAA,GACJ,CAAC,cAAclB,WAAA,GAAeA,WAAA,CAAYkB,QAAQ,GAAcH,SAAQ,MACvE,UAAUf,WAAA,GAAcA,WAAA,CAAYmB,IAAI,GAAGJ,SAAQ;EAEtD;EACA,IAAIK,UAAA,GAAab,cAAA;EACjB,IAAIc,aAAA;EAEJ,IAAId,cAAA,IAAkBE,GAAA,EAAK;IACzB,MAAMa,gBAAA,GAAmBd,OAAA,CAAQe,WAAW,CAACtB,cAAA,CAAe,EAAEuB,MAAA;IAC9D,MAAMC,YAAA,GAAeH,gBAAA,EAAkBI,KAAA,EAAOD,YAAA;IAE9C,IAAI,OAAOA,YAAA,KAAiB,YAAY;MACtC;MACA,MAAME,UAAA,GAAalB,GAAA,CAAID,OAAO,CAACgB,MAAM,CAACI,MAAM,EAAEF,KAAA,IAAS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ACf;EACF,OAAO;IACL,MAAMY,mBAAA,GAAsBjD,WAAA,EAAae,KAAA,EAAO4B,UAAA,EAAYO,IAAA;IAE5D,IAAID,mBAAA,EAAqB;MACvBT,UAAA,GAAazD,qBAAA,CAAsB;QACjC6D,WAAA,EAAaV,eAAA;QACbW,SAAA,EAAWI,mBAAA;QACXF,SAAA,EAAWlD,OAAA,CAAQkD,SAAS;QAC5BC,WAAA,EAAaX;MACf;IACF,OAAO,IACLH,eAAA,CAAgB/B,QAAQ,IACxB+B,eAAA,CAAgB7B,KAAK,IACrBnB,wBAAA,CAAyBgD,eAAA,GACzB;MACAM,UAAA,GAAazD,qBAAA,CAAsB;QACjC6D,WAAA,EAAaV,eAAA;QACbW,SAAA,EAAW7D,WAAA;QACX+D,SAAA,EAAWlD,OAAA,CAAQkD;MACrB;IACF,OAAO;MACL,MAAME,mBAAA,GAAsBjD,WAAA,EAAae,KAAA,EAAO4B,UAAA,EAAYO,IAAA;MAE5D,IAAID,mBAAA,EAAqB;QACvBT,UAAA,GAAazD,qBAAA,CAAsB;UACjC6D,WAAA,EAAaV,eAAA;UACbW,SAAA,EAAWI,mBAAA;UACXF,SAAA,EAAWlD,OAAA,CAAQkD,SAAS;UAC5BC,WAAA,EAAaX;QACf;MACF,OAAO;QACLG,UAAA,GAAapC,SAAA;MACf;IACF;EACF;EAEA,oBACE+C,IAAA,CAACrE,qBAAA;IACCsE,eAAA,EAAiBZ,UAAA;IACjBa,QAAA,eACEF,IAAA,CAAClE,iBAAA;MACC2D,WAAA,EAAaV,eAAA;MACb3C,WAAA,EAAaA,WAAA;MACbG,mBAAA,EAAqBA,mBAAA;MACrBE,cAAA,EAAgBA;;KAGf,GAAGG,QAAA,IAAYR,WAAA,EAAa;AAGvC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"renderCell.js","names":["MissingEditorProp","formatAdminURL","RenderCustomComponent","RenderServerComponent","DefaultCell","RenderDefaultCell","hasOptionLabelJSXElement","findValueFromPath","renderCell","clientField","collectionSlug","columnIndex","customCellProps","doc","enableRowSelections","i18n","isLinkedColumn","payload","req","rowIndex","serverField","viewType","baseCellClientProps","cellData","undefined","field","rowData","accessor","name","shouldLink","customLinkURL","collectionConfig","collections","config","formatDocURL","admin","adminRoute","routes","defaultURL","path","encodeURIComponent","String","id","customURL","_displayStatus","enrichedClientField","type","hasChangedOption","options","some","opt","value","label","t","cellClientProps","link","linkURL","cellServerProps","className","onClick","CustomCell","editor","Error","components","clientProps","Component","CellComponent","importMap","serverProps","CustomCellComponent","Cell","_jsx","CustomComponent","Fallback"],"sources":["../../../../src/providers/TableColumns/buildColumnState/renderCell.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n ClientField,\n DefaultCellComponentProps,\n DefaultServerCellComponentProps,\n Document,\n Field,\n Payload,\n PayloadRequest,\n ViewTypes,\n} from 'payload'\n\nimport { MissingEditorProp } from 'payload'\nimport { formatAdminURL } from 'payload/shared'\n\nimport { RenderCustomComponent } from '../../../elements/RenderCustomComponent/index.js'\nimport { RenderServerComponent } from '../../../elements/RenderServerComponent/index.js'\nimport {\n DefaultCell,\n RenderDefaultCell,\n // eslint-disable-next-line payload/no-imports-from-exports-dir -- MUST reference the exports dir: https://github.com/payloadcms/payload/issues/12002#issuecomment-2791493587\n} from '../../../exports/client/index.js'\nimport { hasOptionLabelJSXElement } from '../../../utilities/hasOptionLabelJSXElement.js'\nimport { findValueFromPath } from './findValueFromPath.js'\n\ntype RenderCellArgs = {\n readonly clientField: ClientField\n readonly collectionSlug: string\n readonly columnIndex: number\n readonly customCellProps: DefaultCellComponentProps['customCellProps']\n readonly doc: Document\n readonly enableRowSelections: boolean\n readonly i18n: I18nClient\n readonly isLinkedColumn: boolean\n readonly payload: Payload\n readonly req?: PayloadRequest\n readonly rowIndex: number\n readonly serverField: Field\n readonly viewType?: ViewTypes\n}\nexport function renderCell({\n clientField,\n collectionSlug,\n columnIndex,\n customCellProps,\n doc,\n enableRowSelections,\n i18n,\n isLinkedColumn,\n payload,\n req,\n rowIndex,\n serverField,\n viewType,\n}: RenderCellArgs) {\n const baseCellClientProps: DefaultCellComponentProps = {\n cellData: undefined,\n collectionSlug,\n customCellProps,\n field: clientField,\n rowData: undefined,\n viewType,\n }\n\n const accessor: string | undefined =\n ('accessor' in clientField ? (clientField.accessor as string) : undefined) ??\n ('name' in clientField ? clientField.name : undefined)\n\n // Check if there's a custom formatDocURL function for this linked column\n let shouldLink = isLinkedColumn\n let customLinkURL: string | undefined\n\n if (isLinkedColumn && req) {\n const collectionConfig = payload.collections[collectionSlug]?.config\n const formatDocURL = collectionConfig?.admin?.formatDocURL\n\n if (typeof formatDocURL === 'function') {\n // Generate the default URL that would normally be used\n const adminRoute = req.payload.config.routes?.admin || '/admin'\n const defaultURL = formatAdminURL({\n adminRoute,\n path: `/collections/${collectionSlug}${viewType === 'trash' ? '/trash' : ''}/${encodeURIComponent(String(doc.id))}`,\n })\n\n const customURL = formatDocURL({\n collectionSlug,\n defaultURL,\n doc,\n req,\n viewType,\n })\n\n if (customURL === null) {\n // formatDocURL returned null = disable linking entirely\n shouldLink = false\n } else if (typeof customURL === 'string') {\n // formatDocURL returned a string = use custom URL\n shouldLink = true\n customLinkURL = customURL\n } else {\n // formatDocURL returned unexpected type = disable linking for safety\n shouldLink = false\n }\n }\n }\n\n // For _status field, use _displayStatus if available (for showing \"changed\" status in list view)\n const cellData =\n 'name' in clientField && accessor === '_status' && '_displayStatus' in doc\n ? doc._displayStatus\n : 'name' in clientField\n ? findValueFromPath(doc, accessor)\n : undefined\n\n // For _status field, add 'changed' option for display purposes\n // The 'changed' status is computed at runtime\n let enrichedClientField = clientField\n if ('name' in clientField && accessor === '_status' && clientField.type === 'select') {\n const hasChangedOption = clientField.options?.some(\n (opt) => (typeof opt === 'object' ? opt.value : opt) === 'changed',\n )\n if (!hasChangedOption) {\n enrichedClientField = {\n ...clientField,\n options: [\n ...(clientField.options || []),\n {\n label: i18n.t('version:draftHasPublishedVersion'),\n value: 'changed',\n },\n ],\n }\n }\n }\n\n const cellClientProps: DefaultCellComponentProps = {\n ...baseCellClientProps,\n cellData,\n field: enrichedClientField,\n link: shouldLink,\n linkURL: customLinkURL,\n rowData: doc,\n }\n\n const cellServerProps: DefaultServerCellComponentProps = {\n cellData: cellClientProps.cellData,\n className: baseCellClientProps.className,\n collectionConfig: payload.collections[collectionSlug].config,\n collectionSlug,\n columnIndex,\n customCellProps: baseCellClientProps.customCellProps,\n field: serverField,\n i18n,\n link: shouldLink,\n linkURL: customLinkURL,\n onClick: baseCellClientProps.onClick,\n payload,\n rowData: doc,\n }\n\n let CustomCell = null\n\n if (serverField?.type === 'richText') {\n if (!serverField?.editor) {\n throw new MissingEditorProp(serverField) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof serverField?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n if (!serverField.admin) {\n serverField.admin = {}\n }\n\n if (!serverField.admin.components) {\n serverField.admin.components = {}\n }\n\n CustomCell = RenderServerComponent({\n clientProps: cellClientProps,\n Component: serverField.editor.CellComponent,\n importMap: payload.importMap,\n serverProps: cellServerProps,\n })\n } else {\n const CustomCellComponent = serverField?.admin?.components?.Cell\n\n if (CustomCellComponent) {\n CustomCell = RenderServerComponent({\n clientProps: cellClientProps,\n Component: CustomCellComponent,\n importMap: payload.importMap,\n serverProps: cellServerProps,\n })\n } else if (\n cellClientProps.cellData &&\n cellClientProps.field &&\n hasOptionLabelJSXElement(cellClientProps)\n ) {\n CustomCell = RenderServerComponent({\n clientProps: cellClientProps,\n Component: DefaultCell,\n importMap: payload.importMap,\n })\n } else {\n const CustomCellComponent = serverField?.admin?.components?.Cell\n\n if (CustomCellComponent) {\n CustomCell = RenderServerComponent({\n clientProps: cellClientProps,\n Component: CustomCellComponent,\n importMap: payload.importMap,\n serverProps: cellServerProps,\n })\n } else {\n CustomCell = undefined\n }\n }\n }\n\n return (\n <RenderCustomComponent\n CustomComponent={CustomCell}\n Fallback={\n <RenderDefaultCell\n clientProps={cellClientProps}\n columnIndex={columnIndex}\n enableRowSelections={enableRowSelections}\n isLinkedColumn={isLinkedColumn}\n />\n }\n key={`${rowIndex}-${columnIndex}`}\n />\n )\n}\n"],"mappings":";AAYA,SAASA,iBAAiB,QAAQ;AAClC,SAASC,cAAc,QAAQ;AAE/B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,qBAAqB,QAAQ;AACtC,SACEC,WAAW,EACXC,iBAAiB,QAEZ;AACP,SAASC,wBAAwB,QAAQ;AACzC,SAASC,iBAAiB,QAAQ;AAiBlC,OAAO,SAASC,WAAW;EACzBC,WAAW;EACXC,cAAc;EACdC,WAAW;EACXC,eAAe;EACfC,GAAG;EACHC,mBAAmB;EACnBC,IAAI;EACJC,cAAc;EACdC,OAAO;EACPC,GAAG;EACHC,QAAQ;EACRC,WAAW;EACXC;AAAQ,CACO;EACf,MAAMC,mBAAA,GAAiD;IACrDC,QAAA,EAAUC,SAAA;IACVd,cAAA;IACAE,eAAA;IACAa,KAAA,EAAOhB,WAAA;IACPiB,OAAA,EAASF,SAAA;IACTH;EACF;EAEA,MAAMM,QAAA,GACJ,CAAC,cAAclB,WAAA,GAAeA,WAAA,CAAYkB,QAAQ,GAAcH,SAAQ,MACvE,UAAUf,WAAA,GAAcA,WAAA,CAAYmB,IAAI,GAAGJ,SAAQ;EAEtD;EACA,IAAIK,UAAA,GAAab,cAAA;EACjB,IAAIc,aAAA;EAEJ,IAAId,cAAA,IAAkBE,GAAA,EAAK;IACzB,MAAMa,gBAAA,GAAmBd,OAAA,CAAQe,WAAW,CAACtB,cAAA,CAAe,EAAEuB,MAAA;IAC9D,MAAMC,YAAA,GAAeH,gBAAA,EAAkBI,KAAA,EAAOD,YAAA;IAE9C,IAAI,OAAOA,YAAA,KAAiB,YAAY;MACtC;MACA,MAAME,UAAA,GAAalB,GAAA,CAAID,OAAO,CAACgB,MAAM,CAACI,MAAM,EAAEF,KAAA,IAAS;MACvD,MAAMG,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