@payloadcms/ui 3.27.0 → 3.28.0-canary.1
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/ThumbnailCard/index.scss +2 -1
- package/dist/elements/Toasts/fieldErrors.d.ts.map +1 -1
- package/dist/elements/Toasts/fieldErrors.js +2 -1
- package/dist/elements/Toasts/fieldErrors.js.map +1 -1
- package/dist/exports/client/index.js +11 -11
- package/dist/exports/client/index.js.map +4 -4
- package/dist/fields/Blocks/BlocksDrawer/index.js +5 -5
- package/dist/fields/Blocks/BlocksDrawer/index.js.map +1 -1
- package/dist/fields/Blocks/BlocksDrawer/index.scss +11 -2
- package/dist/fields/Collapsible/index.d.ts.map +1 -1
- package/dist/fields/Collapsible/index.js +2 -1
- package/dist/fields/Collapsible/index.js.map +1 -1
- package/dist/fields/Tabs/Tab/index.d.ts.map +1 -1
- package/dist/fields/Tabs/Tab/index.js +35 -61
- package/dist/fields/Tabs/Tab/index.js.map +1 -1
- package/dist/forms/Form/mergeServerFormState.d.ts.map +1 -1
- package/dist/forms/Form/mergeServerFormState.js +1 -1
- package/dist/forms/Form/mergeServerFormState.js.map +1 -1
- package/dist/forms/WatchChildErrors/buildPathSegments.d.ts +1 -1
- package/dist/forms/WatchChildErrors/buildPathSegments.d.ts.map +1 -1
- package/dist/forms/WatchChildErrors/buildPathSegments.js +8 -11
- package/dist/forms/WatchChildErrors/buildPathSegments.js.map +1 -1
- package/dist/forms/WatchChildErrors/index.d.ts +6 -0
- package/dist/forms/WatchChildErrors/index.d.ts.map +1 -1
- package/dist/forms/WatchChildErrors/index.js +29 -17
- package/dist/forms/WatchChildErrors/index.js.map +1 -1
- package/dist/graphics/DefaultBlockImage/index.d.ts.map +1 -1
- package/dist/graphics/DefaultBlockImage/index.js +54 -24
- package/dist/graphics/DefaultBlockImage/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +5 -5
- package/dist/forms/WatchChildErrors/getFieldStateFromPaths.d.ts +0 -9
- package/dist/forms/WatchChildErrors/getFieldStateFromPaths.d.ts.map +0 -1
- package/dist/forms/WatchChildErrors/getFieldStateFromPaths.js +0 -29
- package/dist/forms/WatchChildErrors/getFieldStateFromPaths.js.map +0 -1
- package/dist/forms/WatchChildErrors/getNestedFieldState.d.ts +0 -12
- package/dist/forms/WatchChildErrors/getNestedFieldState.d.ts.map +0 -1
- package/dist/forms/WatchChildErrors/getNestedFieldState.js +0 -24
- package/dist/forms/WatchChildErrors/getNestedFieldState.js.map +0 -1
|
@@ -113,12 +113,12 @@ export const BlocksDrawer = props => {
|
|
|
113
113
|
void addRow(addRowIndex, slug);
|
|
114
114
|
closeModal(drawerSlug);
|
|
115
115
|
},
|
|
116
|
-
thumbnail:
|
|
117
|
-
alt: imageAltText,
|
|
118
|
-
src: imageURL
|
|
119
|
-
}) : /*#__PURE__*/_jsx("div", {
|
|
116
|
+
thumbnail: /*#__PURE__*/_jsx("div", {
|
|
120
117
|
className: `${baseClass}__default-image`,
|
|
121
|
-
children: /*#__PURE__*/_jsx(
|
|
118
|
+
children: imageURL ? /*#__PURE__*/_jsx("img", {
|
|
119
|
+
alt: imageAltText,
|
|
120
|
+
src: imageURL
|
|
121
|
+
}) : /*#__PURE__*/_jsx(DefaultBlockImage, {})
|
|
122
122
|
})
|
|
123
123
|
})
|
|
124
124
|
}, index);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useModal","getTranslation","React","useEffect","useMemo","useState","Drawer","ThumbnailCard","DefaultBlockImage","useConfig","useTranslation","BlockSearch","baseClass","getBlockLabel","block","i18n","labels","singular","toLowerCase","BlocksDrawer","props","addRow","addRowIndex","blocks","drawerSlug","searchTerm","setSearchTerm","filteredBlocks","setFilteredBlocks","closeModal","isModalOpen","t","config","blockGroups","groups","_none","forEach","admin","group","label","Object","hasOwn","push","searchTermToUse","matchingBlocks","reduce","matchedBlocks","_block","blocksMap","blockLabel","includes","_jsxs","slug","title","_jsx","className","entries","map","groupLabel","groupBlocks","length","filter","Boolean","join","index","imageAltText","imageURL","blockLabels","alignLabel","onClick","thumbnail","alt","src"],"sources":["../../../../src/fields/Blocks/BlocksDrawer/index.tsx"],"sourcesContent":["'use client'\nimport type { I18nClient } from '@payloadcms/translations'\nimport type { ClientBlock, Labels } from 'payload'\n\nimport { useModal } from '@faceless-ui/modal'\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useEffect, useMemo, useState } from 'react'\n\nimport { Drawer } from '../../../elements/Drawer/index.js'\nimport { ThumbnailCard } from '../../../elements/ThumbnailCard/index.js'\nimport { DefaultBlockImage } from '../../../graphics/DefaultBlockImage/index.js'\nimport { useConfig } from '../../../providers/Config/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport './index.scss'\nimport { BlockSearch } from './BlockSearch/index.js'\n\nexport type Props = {\n readonly addRow: (index: number, blockType?: string) => Promise<void> | void\n readonly addRowIndex: number\n readonly blocks: (ClientBlock | string)[]\n readonly drawerSlug: string\n readonly labels: Labels\n}\n\nconst baseClass = 'blocks-drawer'\n\nconst getBlockLabel = (block: ClientBlock, i18n: I18nClient) => {\n if (typeof block.labels.singular === 'string') {\n return block.labels.singular.toLowerCase()\n }\n if (typeof block.labels.singular === 'object') {\n return getTranslation(block.labels.singular, i18n).toLowerCase()\n }\n return ''\n}\n\nexport const BlocksDrawer: React.FC<Props> = (props) => {\n const { addRow, addRowIndex, blocks, drawerSlug, labels } = props\n\n const [searchTerm, setSearchTerm] = useState('')\n const [filteredBlocks, setFilteredBlocks] = useState(blocks)\n const { closeModal, isModalOpen } = useModal()\n const { i18n, t } = useTranslation()\n const { config } = useConfig()\n\n const blockGroups = useMemo(() => {\n const groups: Record<string, (ClientBlock | string)[]> = {\n _none: [],\n }\n filteredBlocks.forEach((block) => {\n if (typeof block === 'object' && block.admin?.group) {\n const group = block.admin.group\n const label = typeof group === 'string' ? group : getTranslation(group, i18n)\n\n if (Object.hasOwn(groups, label)) {\n groups[label].push(block)\n } else {\n groups[label] = [block]\n }\n } else {\n groups._none.push(block)\n }\n })\n return groups\n }, [filteredBlocks, i18n])\n\n useEffect(() => {\n if (!isModalOpen(drawerSlug)) {\n setSearchTerm('')\n }\n }, [isModalOpen, drawerSlug])\n\n useEffect(() => {\n const searchTermToUse = searchTerm.toLowerCase()\n\n const matchingBlocks = blocks?.reduce((matchedBlocks, _block) => {\n const block = typeof _block === 'string' ? config.blocksMap[_block] : _block\n const blockLabel = getBlockLabel(block, i18n)\n if (blockLabel.includes(searchTermToUse)) {\n matchedBlocks.push(block)\n }\n return matchedBlocks\n }, [])\n\n setFilteredBlocks(matchingBlocks)\n }, [searchTerm, blocks, i18n, config.blocksMap])\n\n return (\n <Drawer\n slug={drawerSlug}\n title={t('fields:addLabel', { label: getTranslation(labels.singular, i18n) })}\n >\n <BlockSearch setSearchTerm={setSearchTerm} />\n <div className={`${baseClass}__blocks-wrapper`}>\n <ul className={`${baseClass}__block-groups`}>\n {Object.entries(blockGroups).map(([groupLabel, groupBlocks]) =>\n !groupBlocks.length ? null : (\n <li\n className={[\n `${baseClass}__block-group`,\n groupLabel === '_none' && `${baseClass}__block-group-none`,\n ]\n .filter(Boolean)\n .join(' ')}\n key={groupLabel}\n >\n {groupLabel !== '_none' && (\n <h3 className={`${baseClass}__block-group-label`}>{groupLabel}</h3>\n )}\n <ul className={`${baseClass}__blocks`}>\n {groupBlocks.map((_block, index) => {\n const block = typeof _block === 'string' ? config.blocksMap[_block] : _block\n\n const { slug, imageAltText, imageURL, labels: blockLabels } = block\n\n return (\n <li className={`${baseClass}__block`} key={index}>\n <ThumbnailCard\n alignLabel=\"center\"\n label={getTranslation(blockLabels?.singular, i18n)}\n onClick={() => {\n void addRow(addRowIndex, slug)\n closeModal(drawerSlug)\n }}\n thumbnail={\n imageURL ? (\n
|
|
1
|
+
{"version":3,"file":"index.js","names":["useModal","getTranslation","React","useEffect","useMemo","useState","Drawer","ThumbnailCard","DefaultBlockImage","useConfig","useTranslation","BlockSearch","baseClass","getBlockLabel","block","i18n","labels","singular","toLowerCase","BlocksDrawer","props","addRow","addRowIndex","blocks","drawerSlug","searchTerm","setSearchTerm","filteredBlocks","setFilteredBlocks","closeModal","isModalOpen","t","config","blockGroups","groups","_none","forEach","admin","group","label","Object","hasOwn","push","searchTermToUse","matchingBlocks","reduce","matchedBlocks","_block","blocksMap","blockLabel","includes","_jsxs","slug","title","_jsx","className","entries","map","groupLabel","groupBlocks","length","filter","Boolean","join","index","imageAltText","imageURL","blockLabels","alignLabel","onClick","thumbnail","alt","src"],"sources":["../../../../src/fields/Blocks/BlocksDrawer/index.tsx"],"sourcesContent":["'use client'\nimport type { I18nClient } from '@payloadcms/translations'\nimport type { ClientBlock, Labels } from 'payload'\n\nimport { useModal } from '@faceless-ui/modal'\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useEffect, useMemo, useState } from 'react'\n\nimport { Drawer } from '../../../elements/Drawer/index.js'\nimport { ThumbnailCard } from '../../../elements/ThumbnailCard/index.js'\nimport { DefaultBlockImage } from '../../../graphics/DefaultBlockImage/index.js'\nimport { useConfig } from '../../../providers/Config/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport './index.scss'\nimport { BlockSearch } from './BlockSearch/index.js'\n\nexport type Props = {\n readonly addRow: (index: number, blockType?: string) => Promise<void> | void\n readonly addRowIndex: number\n readonly blocks: (ClientBlock | string)[]\n readonly drawerSlug: string\n readonly labels: Labels\n}\n\nconst baseClass = 'blocks-drawer'\n\nconst getBlockLabel = (block: ClientBlock, i18n: I18nClient) => {\n if (typeof block.labels.singular === 'string') {\n return block.labels.singular.toLowerCase()\n }\n if (typeof block.labels.singular === 'object') {\n return getTranslation(block.labels.singular, i18n).toLowerCase()\n }\n return ''\n}\n\nexport const BlocksDrawer: React.FC<Props> = (props) => {\n const { addRow, addRowIndex, blocks, drawerSlug, labels } = props\n\n const [searchTerm, setSearchTerm] = useState('')\n const [filteredBlocks, setFilteredBlocks] = useState(blocks)\n const { closeModal, isModalOpen } = useModal()\n const { i18n, t } = useTranslation()\n const { config } = useConfig()\n\n const blockGroups = useMemo(() => {\n const groups: Record<string, (ClientBlock | string)[]> = {\n _none: [],\n }\n filteredBlocks.forEach((block) => {\n if (typeof block === 'object' && block.admin?.group) {\n const group = block.admin.group\n const label = typeof group === 'string' ? group : getTranslation(group, i18n)\n\n if (Object.hasOwn(groups, label)) {\n groups[label].push(block)\n } else {\n groups[label] = [block]\n }\n } else {\n groups._none.push(block)\n }\n })\n return groups\n }, [filteredBlocks, i18n])\n\n useEffect(() => {\n if (!isModalOpen(drawerSlug)) {\n setSearchTerm('')\n }\n }, [isModalOpen, drawerSlug])\n\n useEffect(() => {\n const searchTermToUse = searchTerm.toLowerCase()\n\n const matchingBlocks = blocks?.reduce((matchedBlocks, _block) => {\n const block = typeof _block === 'string' ? config.blocksMap[_block] : _block\n const blockLabel = getBlockLabel(block, i18n)\n if (blockLabel.includes(searchTermToUse)) {\n matchedBlocks.push(block)\n }\n return matchedBlocks\n }, [])\n\n setFilteredBlocks(matchingBlocks)\n }, [searchTerm, blocks, i18n, config.blocksMap])\n\n return (\n <Drawer\n slug={drawerSlug}\n title={t('fields:addLabel', { label: getTranslation(labels.singular, i18n) })}\n >\n <BlockSearch setSearchTerm={setSearchTerm} />\n <div className={`${baseClass}__blocks-wrapper`}>\n <ul className={`${baseClass}__block-groups`}>\n {Object.entries(blockGroups).map(([groupLabel, groupBlocks]) =>\n !groupBlocks.length ? null : (\n <li\n className={[\n `${baseClass}__block-group`,\n groupLabel === '_none' && `${baseClass}__block-group-none`,\n ]\n .filter(Boolean)\n .join(' ')}\n key={groupLabel}\n >\n {groupLabel !== '_none' && (\n <h3 className={`${baseClass}__block-group-label`}>{groupLabel}</h3>\n )}\n <ul className={`${baseClass}__blocks`}>\n {groupBlocks.map((_block, index) => {\n const block = typeof _block === 'string' ? config.blocksMap[_block] : _block\n\n const { slug, imageAltText, imageURL, labels: blockLabels } = block\n\n return (\n <li className={`${baseClass}__block`} key={index}>\n <ThumbnailCard\n alignLabel=\"center\"\n label={getTranslation(blockLabels?.singular, i18n)}\n onClick={() => {\n void addRow(addRowIndex, slug)\n closeModal(drawerSlug)\n }}\n thumbnail={\n <div className={`${baseClass}__default-image`}>\n {imageURL ? (\n <img alt={imageAltText} src={imageURL} />\n ) : (\n <DefaultBlockImage />\n )}\n </div>\n }\n />\n </li>\n )\n })}\n </ul>\n </li>\n ),\n )}\n </ul>\n </div>\n </Drawer>\n )\n}\n"],"mappings":"AAAA;;;AAIA,SAASA,QAAQ,QAAQ;AACzB,SAASC,cAAc,QAAQ;AAC/B,OAAOC,KAAA,IAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AAEpD,SAASC,MAAM,QAAQ;AACvB,SAASC,aAAa,QAAQ;AAC9B,SAASC,iBAAiB,QAAQ;AAClC,SAASC,SAAS,QAAQ;AAC1B,SAASC,cAAc,QAAQ;AAC/B,OAAO;AACP,SAASC,WAAW,QAAQ;AAU5B,MAAMC,SAAA,GAAY;AAElB,MAAMC,aAAA,GAAgBA,CAACC,KAAA,EAAoBC,IAAA;EACzC,IAAI,OAAOD,KAAA,CAAME,MAAM,CAACC,QAAQ,KAAK,UAAU;IAC7C,OAAOH,KAAA,CAAME,MAAM,CAACC,QAAQ,CAACC,WAAW;EAC1C;EACA,IAAI,OAAOJ,KAAA,CAAME,MAAM,CAACC,QAAQ,KAAK,UAAU;IAC7C,OAAOhB,cAAA,CAAea,KAAA,CAAME,MAAM,CAACC,QAAQ,EAAEF,IAAA,EAAMG,WAAW;EAChE;EACA,OAAO;AACT;AAEA,OAAO,MAAMC,YAAA,GAAiCC,KAAA;EAC5C,MAAM;IAAEC,MAAM;IAAEC,WAAW;IAAEC,MAAM;IAAEC,UAAU;IAAER;EAAM,CAAE,GAAGI,KAAA;EAE5D,MAAM,CAACK,UAAA,EAAYC,aAAA,CAAc,GAAGrB,QAAA,CAAS;EAC7C,MAAM,CAACsB,cAAA,EAAgBC,iBAAA,CA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AYF,GAAG,CAAC,CAACV,QAAA,EAAQiB,KAAA;cACxB,MAAMlD,OAAA,GAAQ,OAAOiC,QAAA,KAAW,WAAWf,MAAA,CAAOgB,SAAS,CAACD,QAAA,CAAO,GAAGA,QAAA;cAEtE,MAAM;gBAAEK,IAAI;gBAAEa,YAAY;gBAAEC,QAAQ;gBAAElD,MAAA,EAAQmD;cAAW,CAAE,GAAGrD,OAAA;cAE9D,oBACEwC,IAAA,CAAC;gBAAGC,SAAA,EAAW,GAAG3C,SAAA,SAAkB;0BAClC,aAAA0C,IAAA,CAAC/C,aAAA;kBACC6D,UAAA,EAAW;kBACX7B,KAAA,EAAOtC,cAAA,CAAekE,WAAA,EAAalD,QAAA,EAAUF,IAAA;kBAC7CsD,OAAA,EAASA,CAAA;oBACP,KAAKhD,MAAA,CAAOC,WAAA,EAAa8B,IAAA;oBACzBvB,UAAA,CAAWL,UAAA;kBACb;kBACA8C,SAAA,eACEhB,IAAA,CAAC;oBAAIC,SAAA,EAAW,GAAG3C,SAAA,iBAA0B;8BAC1CsD,QAAA,gBACCZ,IAAA,CAAC;sBAAIiB,GAAA,EAAKN,YAAA;sBAAcO,GAAA,EAAKN;sCAE7BZ,IAAA,CAAC9C,iBAAA;;;iBAbgCwD,KAAA;YAoB/C;;WAhCGN,UAAA;;;;AAyCrB","ignoreList":[]}
|
|
@@ -16,9 +16,19 @@
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
&__default-image {
|
|
19
|
+
display: flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
justify-content: center;
|
|
19
22
|
width: 100%;
|
|
23
|
+
aspect-ratio: 3 / 2;
|
|
20
24
|
overflow: hidden;
|
|
21
|
-
|
|
25
|
+
|
|
26
|
+
img,
|
|
27
|
+
svg {
|
|
28
|
+
width: 100%;
|
|
29
|
+
height: 100%;
|
|
30
|
+
object-fit: cover;
|
|
31
|
+
}
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
&__block-groups {
|
|
@@ -60,7 +70,6 @@
|
|
|
60
70
|
|
|
61
71
|
&__blocks {
|
|
62
72
|
grid-template-columns: repeat(3, 1fr);
|
|
63
|
-
gap: base(0.5);
|
|
64
73
|
}
|
|
65
74
|
|
|
66
75
|
&__block-groups {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Collapsible/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA8D,MAAM,OAAO,CAAA;AAelF,OAAO,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Collapsible/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA8D,MAAM,OAAO,CAAA;AAelF,OAAO,cAAc,CAAA;AA6IrB,eAAO,MAAM,gBAAgB;;+EAA2C,CAAA"}
|
|
@@ -110,7 +110,8 @@ const CollapsibleFieldComponent = props => {
|
|
|
110
110
|
return /*#__PURE__*/_jsxs(Fragment, {
|
|
111
111
|
children: [/*#__PURE__*/_jsx(WatchChildErrors, {
|
|
112
112
|
fields: fields,
|
|
113
|
-
path
|
|
113
|
+
// removes the 'collapsible' path segment, i.e. `_index-0`
|
|
114
|
+
path: path.split('.').slice(0, -1),
|
|
114
115
|
setErrorCount: setErrorCount
|
|
115
116
|
}), /*#__PURE__*/_jsxs("div", {
|
|
116
117
|
className: [fieldBaseClass, baseClass, className, fieldHasErrors ? `${baseClass}--has-error` : `${baseClass}--has-no-error`].filter(Boolean).join(' '),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["getTranslation","React","Fragment","useCallback","useEffect","useMemo","useState","Collapsible","CollapsibleElement","ErrorPill","RenderCustomComponent","FieldDescription","RenderFields","RowLabel","useField","WatchChildErrors","withCondition","useDocumentInfo","usePreferences","useTranslation","mergeFieldStyles","fieldBaseClass","baseClass","CollapsibleFieldComponent","props","field","admin","className","description","initCollapsed","fields","label","indexPath","parentPath","parentSchemaPath","path","permissions","readOnly","i18n","getPreference","setPreference","preferencesKey","collapsedOnMount","setCollapsedOnMount","fieldPreferencesKey","replace","errorCount","setErrorCount","fieldHasErrors","customComponents","AfterInput","BeforeInput","Description","Label","onToggle","newCollapsedState","existingPreferences","collapsed","fetchInitialState","preferences","specificPreference","undefined","Boolean","styles","_jsxs","_jsx","split","filter","join","id","style","collapsibleStyle","header","CustomComponent","count","withMessage","margins","parentIndexPath","Fallback","CollapsibleField"],"sources":["../../../src/fields/Collapsible/index.tsx"],"sourcesContent":["'use client'\nimport type { CollapsibleFieldClientComponent, DocumentPreferences } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { Fragment, useCallback, useEffect, useMemo, useState } from 'react'\n\nimport { Collapsible as CollapsibleElement } from '../../elements/Collapsible/index.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { RenderCustomComponent } from '../../elements/RenderCustomComponent/index.js'\nimport { FieldDescription } from '../../fields/FieldDescription/index.js'\nimport { RenderFields } from '../../forms/RenderFields/index.js'\nimport { RowLabel } from '../../forms/RowLabel/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { WatchChildErrors } from '../../forms/WatchChildErrors/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { mergeFieldStyles } from '../mergeFieldStyles.js'\nimport './index.scss'\nimport { fieldBaseClass } from '../shared/index.js'\n\nconst baseClass = 'collapsible-field'\n\nconst CollapsibleFieldComponent: CollapsibleFieldClientComponent = (props) => {\n const {\n field,\n field: { admin: { className, description, initCollapsed = false } = {}, fields, label } = {},\n indexPath,\n parentPath,\n parentSchemaPath,\n path,\n permissions,\n readOnly,\n } = props\n\n const { i18n } = useTranslation()\n const { getPreference, setPreference } = usePreferences()\n const { preferencesKey } = useDocumentInfo()\n const [collapsedOnMount, setCollapsedOnMount] = useState<boolean>()\n const fieldPreferencesKey = `collapsible-${path?.replace(/\\./g, '__')}`\n const [errorCount, setErrorCount] = useState(0)\n const fieldHasErrors = errorCount > 0\n\n const { customComponents: { AfterInput, BeforeInput, Description, Label } = {} } = useField({\n path,\n })\n\n const onToggle = useCallback(\n async (newCollapsedState: boolean): Promise<void> => {\n const existingPreferences: DocumentPreferences = await getPreference(preferencesKey)\n\n if (preferencesKey) {\n void setPreference(preferencesKey, {\n ...existingPreferences,\n ...(path\n ? {\n fields: {\n ...(existingPreferences?.fields || {}),\n [path]: {\n ...existingPreferences?.fields?.[path],\n collapsed: newCollapsedState,\n },\n },\n }\n : {\n fields: {\n ...(existingPreferences?.fields || {}),\n [fieldPreferencesKey]: {\n ...existingPreferences?.fields?.[fieldPreferencesKey],\n collapsed: newCollapsedState,\n },\n },\n }),\n })\n }\n },\n [preferencesKey, fieldPreferencesKey, getPreference, setPreference, path],\n )\n\n useEffect(() => {\n const fetchInitialState = async () => {\n if (preferencesKey) {\n const preferences = await getPreference(preferencesKey)\n const specificPreference = path\n ? preferences?.fields?.[path]?.collapsed\n : preferences?.fields?.[fieldPreferencesKey]?.collapsed\n\n if (specificPreference !== undefined) {\n setCollapsedOnMount(Boolean(specificPreference))\n } else {\n setCollapsedOnMount(typeof initCollapsed === 'boolean' ? initCollapsed : false)\n }\n } else {\n setCollapsedOnMount(typeof initCollapsed === 'boolean' ? initCollapsed : false)\n }\n }\n\n void fetchInitialState()\n }, [getPreference, preferencesKey, fieldPreferencesKey, initCollapsed, path])\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n if (typeof collapsedOnMount !== 'boolean') {\n return null\n }\n\n return (\n <Fragment>\n <WatchChildErrors fields={fields} path={path.split('.')} setErrorCount={setErrorCount} />\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n fieldHasErrors ? `${baseClass}--has-error` : `${baseClass}--has-no-error`,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${fieldPreferencesKey}`}\n style={styles}\n >\n {BeforeInput}\n <CollapsibleElement\n className={`${baseClass}__collapsible`}\n collapsibleStyle={fieldHasErrors ? 'error' : 'default'}\n header={\n <div className={`${baseClass}__row-label-wrap`}>\n <RowLabel CustomComponent={Label} label={getTranslation(label, i18n)} path={path} />\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n }\n initCollapsed={collapsedOnMount}\n onToggle={onToggle}\n >\n <RenderFields\n fields={fields}\n margins=\"small\"\n parentIndexPath={indexPath}\n parentPath={parentPath}\n parentSchemaPath={parentSchemaPath}\n permissions={permissions}\n readOnly={readOnly}\n />\n </CollapsibleElement>\n {AfterInput}\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n </Fragment>\n )\n}\n\nexport const CollapsibleField = withCondition(CollapsibleFieldComponent)\n"],"mappings":"AAAA;;;AAGA,SAASA,cAAc,QAAQ;AAC/B,OAAOC,KAAA,IAASC,QAAQ,EAAEC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AAE3E,SAASC,WAAA,IAAeC,kBAAkB,QAAQ;AAClD,SAASC,SAAS,QAAQ;AAC1B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,YAAY,QAAQ;AAC7B,SAASC,QAAQ,QAAQ;AACzB,SAASC,QAAQ,QAAQ;AACzB,SAASC,gBAAgB,QAAQ;AACjC,SAASC,aAAa,QAAQ;AAC9B,SAASC,eAAe,QAAQ;AAChC,SAASC,cAAc,QAAQ;AAC/B,SAASC,cAAc,QAAQ;AAC/B,SAASC,gBAAgB,QAAQ;AACjC,OAAO;AACP,SAASC,cAAc,QAAQ;AAE/B,MAAMC,SAAA,GAAY;AAElB,MAAMC,yBAAA,GAA8DC,KAAA;EAClE,MAAM;IACJC,KAAK;IACLA,KAAA,EAAO;MAAEC,KAAA,EAAO;QAAEC,SAAS;QAAEC,WAAW;QAAEC,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["getTranslation","React","Fragment","useCallback","useEffect","useMemo","useState","Collapsible","CollapsibleElement","ErrorPill","RenderCustomComponent","FieldDescription","RenderFields","RowLabel","useField","WatchChildErrors","withCondition","useDocumentInfo","usePreferences","useTranslation","mergeFieldStyles","fieldBaseClass","baseClass","CollapsibleFieldComponent","props","field","admin","className","description","initCollapsed","fields","label","indexPath","parentPath","parentSchemaPath","path","permissions","readOnly","i18n","getPreference","setPreference","preferencesKey","collapsedOnMount","setCollapsedOnMount","fieldPreferencesKey","replace","errorCount","setErrorCount","fieldHasErrors","customComponents","AfterInput","BeforeInput","Description","Label","onToggle","newCollapsedState","existingPreferences","collapsed","fetchInitialState","preferences","specificPreference","undefined","Boolean","styles","_jsxs","_jsx","split","slice","filter","join","id","style","collapsibleStyle","header","CustomComponent","count","withMessage","margins","parentIndexPath","Fallback","CollapsibleField"],"sources":["../../../src/fields/Collapsible/index.tsx"],"sourcesContent":["'use client'\nimport type { CollapsibleFieldClientComponent, DocumentPreferences } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { Fragment, useCallback, useEffect, useMemo, useState } from 'react'\n\nimport { Collapsible as CollapsibleElement } from '../../elements/Collapsible/index.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { RenderCustomComponent } from '../../elements/RenderCustomComponent/index.js'\nimport { FieldDescription } from '../../fields/FieldDescription/index.js'\nimport { RenderFields } from '../../forms/RenderFields/index.js'\nimport { RowLabel } from '../../forms/RowLabel/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { WatchChildErrors } from '../../forms/WatchChildErrors/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { mergeFieldStyles } from '../mergeFieldStyles.js'\nimport './index.scss'\nimport { fieldBaseClass } from '../shared/index.js'\n\nconst baseClass = 'collapsible-field'\n\nconst CollapsibleFieldComponent: CollapsibleFieldClientComponent = (props) => {\n const {\n field,\n field: { admin: { className, description, initCollapsed = false } = {}, fields, label } = {},\n indexPath,\n parentPath,\n parentSchemaPath,\n path,\n permissions,\n readOnly,\n } = props\n\n const { i18n } = useTranslation()\n const { getPreference, setPreference } = usePreferences()\n const { preferencesKey } = useDocumentInfo()\n const [collapsedOnMount, setCollapsedOnMount] = useState<boolean>()\n const fieldPreferencesKey = `collapsible-${path?.replace(/\\./g, '__')}`\n const [errorCount, setErrorCount] = useState(0)\n const fieldHasErrors = errorCount > 0\n\n const { customComponents: { AfterInput, BeforeInput, Description, Label } = {} } = useField({\n path,\n })\n\n const onToggle = useCallback(\n async (newCollapsedState: boolean): Promise<void> => {\n const existingPreferences: DocumentPreferences = await getPreference(preferencesKey)\n\n if (preferencesKey) {\n void setPreference(preferencesKey, {\n ...existingPreferences,\n ...(path\n ? {\n fields: {\n ...(existingPreferences?.fields || {}),\n [path]: {\n ...existingPreferences?.fields?.[path],\n collapsed: newCollapsedState,\n },\n },\n }\n : {\n fields: {\n ...(existingPreferences?.fields || {}),\n [fieldPreferencesKey]: {\n ...existingPreferences?.fields?.[fieldPreferencesKey],\n collapsed: newCollapsedState,\n },\n },\n }),\n })\n }\n },\n [preferencesKey, fieldPreferencesKey, getPreference, setPreference, path],\n )\n\n useEffect(() => {\n const fetchInitialState = async () => {\n if (preferencesKey) {\n const preferences = await getPreference(preferencesKey)\n const specificPreference = path\n ? preferences?.fields?.[path]?.collapsed\n : preferences?.fields?.[fieldPreferencesKey]?.collapsed\n\n if (specificPreference !== undefined) {\n setCollapsedOnMount(Boolean(specificPreference))\n } else {\n setCollapsedOnMount(typeof initCollapsed === 'boolean' ? initCollapsed : false)\n }\n } else {\n setCollapsedOnMount(typeof initCollapsed === 'boolean' ? initCollapsed : false)\n }\n }\n\n void fetchInitialState()\n }, [getPreference, preferencesKey, fieldPreferencesKey, initCollapsed, path])\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n if (typeof collapsedOnMount !== 'boolean') {\n return null\n }\n\n return (\n <Fragment>\n <WatchChildErrors\n fields={fields}\n // removes the 'collapsible' path segment, i.e. `_index-0`\n path={path.split('.').slice(0, -1)}\n setErrorCount={setErrorCount}\n />\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n fieldHasErrors ? `${baseClass}--has-error` : `${baseClass}--has-no-error`,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${fieldPreferencesKey}`}\n style={styles}\n >\n {BeforeInput}\n <CollapsibleElement\n className={`${baseClass}__collapsible`}\n collapsibleStyle={fieldHasErrors ? 'error' : 'default'}\n header={\n <div className={`${baseClass}__row-label-wrap`}>\n <RowLabel CustomComponent={Label} label={getTranslation(label, i18n)} path={path} />\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n }\n initCollapsed={collapsedOnMount}\n onToggle={onToggle}\n >\n <RenderFields\n fields={fields}\n margins=\"small\"\n parentIndexPath={indexPath}\n parentPath={parentPath}\n parentSchemaPath={parentSchemaPath}\n permissions={permissions}\n readOnly={readOnly}\n />\n </CollapsibleElement>\n {AfterInput}\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n </Fragment>\n )\n}\n\nexport const CollapsibleField = withCondition(CollapsibleFieldComponent)\n"],"mappings":"AAAA;;;AAGA,SAASA,cAAc,QAAQ;AAC/B,OAAOC,KAAA,IAASC,QAAQ,EAAEC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AAE3E,SAASC,WAAA,IAAeC,kBAAkB,QAAQ;AAClD,SAASC,SAAS,QAAQ;AAC1B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,YAAY,QAAQ;AAC7B,SAASC,QAAQ,QAAQ;AACzB,SAASC,QAAQ,QAAQ;AACzB,SAASC,gBAAgB,QAAQ;AACjC,SAASC,aAAa,QAAQ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AAkBA,gBAAA;UAClBE,WAAA,EAAaA,WAAA;UACbC,QAAA,EAAUA;;UAGba,UAAA,E,aACDe,IAAA,CAACvD,qBAAA;QACCgE,eAAA,EAAiBtB,WAAA;QACjB2B,QAAA,eAAUd,IAAA,CAACtD,gBAAA;UAAiBiB,WAAA,EAAaA,WAAA;UAAaO,IAAA,EAAMA;;;;;AAKtE;AAEA,OAAO,MAAM6C,gBAAA,GAAmBhE,aAAA,CAAcO,yBAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/Tabs/Tab/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,OAAO,KAAmB,MAAM,OAAO,CAAA;AAKvC,OAAO,cAAc,CAAA;AAIrB,KAAK,QAAQ,GAAG;IACd,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,IAAI,CAAA;IAChC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/Tabs/Tab/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,OAAO,KAAmB,MAAM,OAAO,CAAA;AAKvC,OAAO,cAAc,CAAA;AAIrB,KAAK,QAAQ,GAAG;IACd,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,IAAI,CAAA;IAChC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,CA+B3C,CAAA"}
|
|
@@ -11,7 +11,7 @@ import { useTranslation } from '../../../providers/Translation/index.js';
|
|
|
11
11
|
import './index.scss';
|
|
12
12
|
const baseClass = 'tabs-field__tab-button';
|
|
13
13
|
export const TabComponent = t0 => {
|
|
14
|
-
const $ = _c(
|
|
14
|
+
const $ = _c(13);
|
|
15
15
|
const {
|
|
16
16
|
isActive,
|
|
17
17
|
parentPath,
|
|
@@ -23,81 +23,55 @@ export const TabComponent = t0 => {
|
|
|
23
23
|
} = useTranslation();
|
|
24
24
|
const [errorCount, setErrorCount] = useState(undefined);
|
|
25
25
|
let t1;
|
|
26
|
-
if ($[0] !== parentPath) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} else {
|
|
31
|
-
t1 = $[1];
|
|
32
|
-
}
|
|
33
|
-
let t2;
|
|
34
|
-
if ($[2] !== tab) {
|
|
35
|
-
t2 = tabHasName(tab) ? [tab.name] : [];
|
|
36
|
-
$[2] = tab;
|
|
37
|
-
$[3] = t2;
|
|
38
|
-
} else {
|
|
39
|
-
t2 = $[3];
|
|
40
|
-
}
|
|
41
|
-
let t3;
|
|
42
|
-
if ($[4] !== t1 || $[5] !== t2) {
|
|
43
|
-
t3 = [...t1, ...t2];
|
|
44
|
-
$[4] = t1;
|
|
45
|
-
$[5] = t2;
|
|
46
|
-
$[6] = t3;
|
|
47
|
-
} else {
|
|
48
|
-
t3 = $[6];
|
|
49
|
-
}
|
|
50
|
-
const path = t3.join(".");
|
|
51
|
-
const fieldHasErrors = errorCount > 0;
|
|
52
|
-
let t4;
|
|
53
|
-
if ($[7] !== errorCount || $[8] !== fieldHasErrors || $[9] !== i18n || $[10] !== isActive || $[11] !== path || $[12] !== setIsActive || $[13] !== tab) {
|
|
54
|
-
const t5 = _jsx(WatchChildErrors, {
|
|
26
|
+
if ($[0] !== errorCount || $[1] !== i18n || $[2] !== isActive || $[3] !== parentPath || $[4] !== setIsActive || $[5] !== tab) {
|
|
27
|
+
const path = [...(parentPath ? parentPath.split(".").slice(0, -1) : []), ...(tabHasName(tab) ? [tab.name] : [])];
|
|
28
|
+
const fieldHasErrors = errorCount > 0;
|
|
29
|
+
const t2 = _jsx(WatchChildErrors, {
|
|
55
30
|
fields: tab.fields,
|
|
56
|
-
path
|
|
31
|
+
path,
|
|
57
32
|
setErrorCount
|
|
58
33
|
});
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
let
|
|
62
|
-
if ($[
|
|
63
|
-
|
|
64
|
-
$[
|
|
65
|
-
$[
|
|
66
|
-
$[
|
|
34
|
+
const t3 = fieldHasErrors && `${baseClass}--has-error`;
|
|
35
|
+
const t4 = isActive && `${baseClass}--active`;
|
|
36
|
+
let t5;
|
|
37
|
+
if ($[7] !== t3 || $[8] !== t4) {
|
|
38
|
+
t5 = [baseClass, t3, t4].filter(Boolean);
|
|
39
|
+
$[7] = t3;
|
|
40
|
+
$[8] = t4;
|
|
41
|
+
$[9] = t5;
|
|
67
42
|
} else {
|
|
68
|
-
|
|
43
|
+
t5 = $[9];
|
|
69
44
|
}
|
|
70
|
-
let
|
|
71
|
-
if ($[
|
|
72
|
-
|
|
73
|
-
$[
|
|
74
|
-
$[
|
|
75
|
-
$[
|
|
45
|
+
let t6;
|
|
46
|
+
if ($[10] !== i18n || $[11] !== tab) {
|
|
47
|
+
t6 = tab.label ? getTranslation(tab.label, i18n) : tabHasName(tab) ? tab.name : "";
|
|
48
|
+
$[10] = i18n;
|
|
49
|
+
$[11] = tab;
|
|
50
|
+
$[12] = t6;
|
|
76
51
|
} else {
|
|
77
|
-
|
|
52
|
+
t6 = $[12];
|
|
78
53
|
}
|
|
79
|
-
|
|
80
|
-
children: [
|
|
81
|
-
className:
|
|
54
|
+
t1 = _jsxs(React.Fragment, {
|
|
55
|
+
children: [t2, _jsxs("button", {
|
|
56
|
+
className: t5.join(" "),
|
|
82
57
|
onClick: setIsActive,
|
|
83
58
|
type: "button",
|
|
84
|
-
children: [
|
|
59
|
+
children: [t6, fieldHasErrors && _jsx(ErrorPill, {
|
|
85
60
|
count: errorCount,
|
|
86
61
|
i18n
|
|
87
62
|
})]
|
|
88
63
|
})]
|
|
89
64
|
});
|
|
90
|
-
$[
|
|
91
|
-
$[
|
|
92
|
-
$[
|
|
93
|
-
$[
|
|
94
|
-
$[
|
|
95
|
-
$[
|
|
96
|
-
$[
|
|
97
|
-
$[14] = t4;
|
|
65
|
+
$[0] = errorCount;
|
|
66
|
+
$[1] = i18n;
|
|
67
|
+
$[2] = isActive;
|
|
68
|
+
$[3] = parentPath;
|
|
69
|
+
$[4] = setIsActive;
|
|
70
|
+
$[5] = tab;
|
|
71
|
+
$[6] = t1;
|
|
98
72
|
} else {
|
|
99
|
-
|
|
73
|
+
t1 = $[6];
|
|
100
74
|
}
|
|
101
|
-
return
|
|
75
|
+
return t1;
|
|
102
76
|
};
|
|
103
77
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","getTranslation","tabHasName","React","useState","ErrorPill","WatchChildErrors","useTranslation","baseClass","TabComponent","t0","$","isActive","parentPath","setIsActive","tab","i18n","errorCount","setErrorCount","undefined","t1","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","getTranslation","tabHasName","React","useState","ErrorPill","WatchChildErrors","useTranslation","baseClass","TabComponent","t0","$","isActive","parentPath","setIsActive","tab","i18n","errorCount","setErrorCount","undefined","t1","path","split","slice","name","fieldHasErrors","t2","_jsx","fields","t3","t4","t5","filter","Boolean","t6","label","_jsxs","Fragment","children","className","join","onClick","type","count"],"sources":["../../../../src/fields/Tabs/Tab/index.tsx"],"sourcesContent":["'use client'\n\nimport type { ClientTab } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { tabHasName } from 'payload/shared'\nimport React, { useState } from 'react'\n\nimport { ErrorPill } from '../../../elements/ErrorPill/index.js'\nimport { WatchChildErrors } from '../../../forms/WatchChildErrors/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport './index.scss'\n\nconst baseClass = 'tabs-field__tab-button'\n\ntype TabProps = {\n readonly isActive?: boolean\n readonly parentPath: string\n readonly setIsActive: () => void\n readonly tab: ClientTab\n}\n\nexport const TabComponent: React.FC<TabProps> = ({ isActive, parentPath, setIsActive, tab }) => {\n const { i18n } = useTranslation()\n const [errorCount, setErrorCount] = useState(undefined)\n\n const path = [\n // removes parent 'tabs' path segment, i.e. `_index-0`\n ...(parentPath ? parentPath.split('.').slice(0, -1) : []),\n ...(tabHasName(tab) ? [tab.name] : []),\n ]\n\n const fieldHasErrors = errorCount > 0\n\n return (\n <React.Fragment>\n <WatchChildErrors fields={tab.fields} path={path} setErrorCount={setErrorCount} />\n <button\n className={[\n baseClass,\n fieldHasErrors && `${baseClass}--has-error`,\n isActive && `${baseClass}--active`,\n ]\n .filter(Boolean)\n .join(' ')}\n onClick={setIsActive}\n type=\"button\"\n >\n {tab.label ? getTranslation(tab.label, i18n) : tabHasName(tab) ? tab.name : ''}\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} />}\n </button>\n </React.Fragment>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,SAASC,cAAc,QAAQ;AAC/B,SAASC,UAAU,QAAQ;AAC3B,OAAOC,KAAA,IAASC,QAAQ,QAAQ;AAEhC,SAASC,SAAS,QAAQ;AAC1B,SAASC,gBAAgB,QAAQ;AACjC,SAASC,cAAc,QAAQ;AAC/B,OAAO;AAEP,MAAMC,SAAA,GAAY;AASlB,OAAO,MAAMC,YAAA,GAAmCC,EAAA;EAAA,MAAAC,CAAA,GAAAX,EAAA;EAAC;IAAAY,QAAA;IAAAC,UAAA;IAAAC,WAAA;IAAAC;EAAA,IAAAL,EAA0C;EACzF;IAAAM;EAAA,IAAiBT,cAAA;EACjB,OA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AA;MAAAL,CAAA,OAAAI,GAAA;MAAAJ,CAAA,OAAAuB,EAAA;IAAA;MAAAA,EAAA,GAAAvB,CAAA;IAAA;IAbhFS,EAAA,GAAAgB,KAAA,CAAAjC,KAAA,CAAAkC,QAAA;MAAAC,QAAA,GACEZ,E,EACAU,KAAA,CAAC;QAAAG,SAAA,EACYR,EAKD,CAAAS,IAAA,CACF;QAAAC,OAAA,EACC3B,WAAA;QAAA4B,IAAA,EACJ;QAAAJ,QAAA,GAEJJ,EAA2E,EAC3ET,cAAA,IAAkBE,IAAA,CAAAtB,SAAA;UAAAsC,KAAA,EAAkB1B,UAAA;UAAAD;QAAA,C;;;;;;;;;;;;;SAdzCI,E;CAkBJ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeServerFormState.d.ts","sourceRoot":"","sources":["../../../src/forms/Form/mergeServerFormState.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,KAAK,IAAI,GAAG;IACV,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,aAAa,EAAE,SAAS,CAAA;IACxB,aAAa,EAAE,SAAS,CAAA;CACzB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,oDAI9B,IAAI,KAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"mergeServerFormState.d.ts","sourceRoot":"","sources":["../../../src/forms/Form/mergeServerFormState.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,KAAK,IAAI,GAAG;IACV,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,aAAa,EAAE,SAAS,CAAA;IACxB,aAAa,EAAE,SAAS,CAAA;CACzB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,oDAI9B,IAAI,KAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CA+FhD,CAAA"}
|
|
@@ -17,7 +17,7 @@ export const mergeServerFormState = ({
|
|
|
17
17
|
let changed = false;
|
|
18
18
|
const newState = {};
|
|
19
19
|
if (existingState) {
|
|
20
|
-
const serverPropsToAccept = ['passesCondition', 'valid', 'errorMessage', 'rows', 'customComponents', 'requiresRender'];
|
|
20
|
+
const serverPropsToAccept = ['passesCondition', 'valid', 'errorMessage', 'errorPaths', 'rows', 'customComponents', 'requiresRender'];
|
|
21
21
|
if (acceptValues) {
|
|
22
22
|
serverPropsToAccept.push('value');
|
|
23
23
|
serverPropsToAccept.push('initialValue');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeServerFormState.js","names":["dequal","mergeErrorPaths","mergeServerFormState","acceptValues","existingState","incomingState","changed","newState","serverPropsToAccept","push","path","newFieldState","Object","entries","fieldChanged","errorPathsResult","errorPaths","result","filterOptions","forEach","prop","valid","passesCondition","field"],"sources":["../../../src/forms/Form/mergeServerFormState.ts"],"sourcesContent":["'use client'\nimport { dequal } from 'dequal/lite' // lite: no need for Map and Set support\nimport { type FormState } from 'payload'\n\nimport { mergeErrorPaths } from './mergeErrorPaths.js'\n\ntype Args = {\n acceptValues?: boolean\n existingState: FormState\n incomingState: FormState\n}\n\n/**\n * Merges certain properties from the server state into the client state. These do not include values,\n * as we do not want to update them on the client like that, which would cause flickering.\n *\n * We want to use this to update the error state, and other properties that are not user input, as the error state\n * is the thing we want to keep in sync with the server (where it's calculated) on the client.\n */\nexport const mergeServerFormState = ({\n acceptValues,\n existingState,\n incomingState,\n}: Args): { changed: boolean; newState: FormState } => {\n let changed = false\n\n const newState = {}\n\n if (existingState) {\n const serverPropsToAccept = [\n 'passesCondition',\n 'valid',\n 'errorMessage',\n 'rows',\n 'customComponents',\n 'requiresRender',\n ]\n\n if (acceptValues) {\n serverPropsToAccept.push('value')\n serverPropsToAccept.push('initialValue')\n }\n\n for (const [path, newFieldState] of Object.entries(existingState)) {\n if (!incomingState[path]) {\n continue\n }\n let fieldChanged = false\n\n /**\n * Handle error paths\n */\n const errorPathsResult = mergeErrorPaths(\n newFieldState.errorPaths,\n incomingState[path].errorPaths as unknown as string[],\n )\n if (errorPathsResult.result) {\n if (errorPathsResult.changed) {\n changed = errorPathsResult.changed\n }\n newFieldState.errorPaths = errorPathsResult.result\n }\n\n /**\n * Handle filterOptions\n */\n if (incomingState[path]?.filterOptions || newFieldState.filterOptions) {\n if (!dequal(incomingState[path]?.filterOptions, newFieldState.filterOptions)) {\n changed = true\n fieldChanged = true\n newFieldState.filterOptions = incomingState[path].filterOptions\n }\n }\n\n /**\n * Handle adding all the remaining props that should be updated in the local form state from the server form state\n */\n serverPropsToAccept.forEach((prop) => {\n if (!dequal(incomingState[path]?.[prop], newFieldState[prop])) {\n changed = true\n fieldChanged = true\n if (!(prop in incomingState[path])) {\n // Regarding excluding the customComponents prop from being deleted: the incoming state might not have been rendered, as rendering components for every form onchange is expensive.\n // Thus, we simply re-use the initial render state\n if (prop !== 'customComponents') {\n delete newFieldState[prop]\n }\n } else {\n newFieldState[prop] = incomingState[path][prop]\n }\n }\n })\n\n if (newFieldState.valid !== false) {\n newFieldState.valid = true\n }\n if (newFieldState.passesCondition !== false) {\n newFieldState.passesCondition = true\n }\n\n // Conditions don't work if we don't memcopy the new state, as the object references would otherwise be the same\n newState[path] = fieldChanged ? { ...newFieldState } : newFieldState\n }\n\n // Now loop over values that are part of incoming state but not part of existing state, and add them to the new state.\n // This can happen if a new array row was added. In our local state, we simply add out stubbed `array` and `array.[index].id` entries to the local form state.\n // However, all other array sub-fields are not added to the local state - those will be added by the server and may be incoming here.\n\n for (const [path, field] of Object.entries(incomingState)) {\n if (!existingState[path]) {\n changed = true\n newState[path] = field\n }\n }\n }\n\n return { changed, newState }\n}\n"],"mappings":"AAAA;;AACA,SAASA,MAAM,QAAQ,cAAa,CAAC;AAGrC,SAASC,eAAe,QA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,CAAOK,aAAa,CAACK,IAAA,CAAK,GAAGU,IAAA,CAAK,EAAET,aAAa,CAACS,IAAA,CAAK,GAAG;UAC7Dd,OAAA,GAAU;UACVQ,YAAA,GAAe;UACf,IAAI,EAAEM,IAAA,IAAQf,aAAa,CAACK,IAAA,CAAK,CAAD,EAAI;YAClC;YACA;YACA,IAAIU,IAAA,KAAS,oBAAoB;cAC/B,OAAOT,aAAa,CAACS,IAAA,CAAK;YAC5B;UACF,OAAO;YACLT,aAAa,CAACS,IAAA,CAAK,GAAGf,aAAa,CAACK,IAAA,CAAK,CAACU,IAAA,CAAK;UACjD;QACF;MACF;MAEA,IAAIT,aAAA,CAAcU,KAAK,KAAK,OAAO;QACjCV,aAAA,CAAcU,KAAK,GAAG;MACxB;MACA,IAAIV,aAAA,CAAcW,eAAe,KAAK,OAAO;QAC3CX,aAAA,CAAcW,eAAe,GAAG;MAClC;MAEA;MACAf,QAAQ,CAACG,IAAA,CAAK,GAAGI,YAAA,GAAe;QAAE,GAAGH;MAAc,IAAIA,aAAA;IACzD;IAEA;IACA;IACA;IAEA,KAAK,MAAM,CAACD,IAAA,EAAMa,KAAA,CAAM,IAAIX,MAAA,CAAOC,OAAO,CAACR,aAAA,GAAgB;MACzD,IAAI,CAACD,aAAa,CAACM,IAAA,CAAK,EAAE;QACxBJ,OAAA,GAAU;QACVC,QAAQ,CAACG,IAAA,CAAK,GAAGa,KAAA;MACnB;IACF;EACF;EAEA,OAAO;IAAEjB,OAAA;IAASC;EAAS;AAC7B","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"mergeServerFormState.js","names":["dequal","mergeErrorPaths","mergeServerFormState","acceptValues","existingState","incomingState","changed","newState","serverPropsToAccept","push","path","newFieldState","Object","entries","fieldChanged","errorPathsResult","errorPaths","result","filterOptions","forEach","prop","valid","passesCondition","field"],"sources":["../../../src/forms/Form/mergeServerFormState.ts"],"sourcesContent":["'use client'\nimport { dequal } from 'dequal/lite' // lite: no need for Map and Set support\nimport { type FormState } from 'payload'\n\nimport { mergeErrorPaths } from './mergeErrorPaths.js'\n\ntype Args = {\n acceptValues?: boolean\n existingState: FormState\n incomingState: FormState\n}\n\n/**\n * Merges certain properties from the server state into the client state. These do not include values,\n * as we do not want to update them on the client like that, which would cause flickering.\n *\n * We want to use this to update the error state, and other properties that are not user input, as the error state\n * is the thing we want to keep in sync with the server (where it's calculated) on the client.\n */\nexport const mergeServerFormState = ({\n acceptValues,\n existingState,\n incomingState,\n}: Args): { changed: boolean; newState: FormState } => {\n let changed = false\n\n const newState = {}\n\n if (existingState) {\n const serverPropsToAccept = [\n 'passesCondition',\n 'valid',\n 'errorMessage',\n 'errorPaths',\n 'rows',\n 'customComponents',\n 'requiresRender',\n ]\n\n if (acceptValues) {\n serverPropsToAccept.push('value')\n serverPropsToAccept.push('initialValue')\n }\n\n for (const [path, newFieldState] of Object.entries(existingState)) {\n if (!incomingState[path]) {\n continue\n }\n let fieldChanged = false\n\n /**\n * Handle error paths\n */\n const errorPathsResult = mergeErrorPaths(\n newFieldState.errorPaths,\n incomingState[path].errorPaths as unknown as string[],\n )\n if (errorPathsResult.result) {\n if (errorPathsResult.changed) {\n changed = errorPathsResult.changed\n }\n newFieldState.errorPaths = errorPathsResult.result\n }\n\n /**\n * Handle filterOptions\n */\n if (incomingState[path]?.filterOptions || newFieldState.filterOptions) {\n if (!dequal(incomingState[path]?.filterOptions, newFieldState.filterOptions)) {\n changed = true\n fieldChanged = true\n newFieldState.filterOptions = incomingState[path].filterOptions\n }\n }\n\n /**\n * Handle adding all the remaining props that should be updated in the local form state from the server form state\n */\n serverPropsToAccept.forEach((prop) => {\n if (!dequal(incomingState[path]?.[prop], newFieldState[prop])) {\n changed = true\n fieldChanged = true\n if (!(prop in incomingState[path])) {\n // Regarding excluding the customComponents prop from being deleted: the incoming state might not have been rendered, as rendering components for every form onchange is expensive.\n // Thus, we simply re-use the initial render state\n if (prop !== 'customComponents') {\n delete newFieldState[prop]\n }\n } else {\n newFieldState[prop] = incomingState[path][prop]\n }\n }\n })\n\n if (newFieldState.valid !== false) {\n newFieldState.valid = true\n }\n if (newFieldState.passesCondition !== false) {\n newFieldState.passesCondition = true\n }\n\n // Conditions don't work if we don't memcopy the new state, as the object references would otherwise be the same\n newState[path] = fieldChanged ? { ...newFieldState } : newFieldState\n }\n\n // Now loop over values that are part of incoming state but not part of existing state, and add them to the new state.\n // This can happen if a new array row was added. In our local state, we simply add out stubbed `array` and `array.[index].id` entries to the local form state.\n // However, all other array sub-fields are not added to the local state - those will be added by the server and may be incoming here.\n\n for (const [path, field] of Object.entries(incomingState)) {\n if (!existingState[path]) {\n changed = true\n newState[path] = field\n }\n }\n }\n\n return { changed, newState }\n}\n"],"mappings":"AAAA;;AACA,SAASA,MAAM,QAAQ,cAAa,CAAC;AAGrC,SAASC,eAAe,QAAQ;AAQhC;;;;;;;AAOA,OAAO,MAAMC,oBAAA,GAAuBA,CAAC;EACnCC,YAAY;EACZC,aAAa;EACbC;AAAa,CACR;EACL,IAAIC,OAAA,GAAU;EAEd,MAAMC,QAAA,GAAW,CAAC;EAElB,IAAIH,aAAA,EAAe;IACjB,MAAMI,mBAAA,GAAsB,CAC1B,mBACA,SACA,gBACA,cACA,QACA,oBACA,iBACD;IAED,IAAIL,YAAA,EAAc;MAChBK,mBAAA,CAAoBC,IAAI,CAAC;MACzBD,mBAAA,CAAoBC,IAAI,CAAC;IAC3B;IAEA,KAAK,MAAM,CAACC,IAAA,EAAMC,aAAA,CAAc,IAAIC,MAAA,CAAOC,OAAO,CAACT,aAAA,GAAgB;MACjE,IAAI,CAACC,aAAa,CAACK,IAAA,CAAK,EAAE;QACxB;MACF;MACA,IAAII,YAAA,GAAe;MAEnB;;;MAGA,MAAMC,gBAAA,GAAmBd,eAAA,CACvBU,aAAA,CAAcK,UAAU,EACxBX,aAAa,CAACK,IAAA,CAAK,CAACM,UAAU;MAEhC,IAAID,gBAAA,CAAiBE,MAAM,EAAE;QAC3B,IAAIF,gBAAA,CAAiBT,OAAO,EA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,MAAA,CAAOC,OAAO,CAACR,aAAA,GAAgB;MACzD,IAAI,CAACD,aAAa,CAACM,IAAA,CAAK,EAAE;QACxBJ,OAAA,GAAU;QACVC,QAAQ,CAACG,IAAA,CAAK,GAAGa,KAAA;MACnB;IACF;EACF;EAEA,OAAO;IAAEjB,OAAA;IAASC;EAAS;AAC7B","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ClientField } from 'payload';
|
|
2
|
-
export declare const buildPathSegments: (
|
|
2
|
+
export declare const buildPathSegments: (fields: ClientField[]) => (`${string}.` | string)[];
|
|
3
3
|
//# sourceMappingURL=buildPathSegments.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildPathSegments.d.ts","sourceRoot":"","sources":["../../../src/forms/WatchChildErrors/buildPathSegments.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAI1C,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"buildPathSegments.d.ts","sourceRoot":"","sources":["../../../src/forms/WatchChildErrors/buildPathSegments.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAI1C,eAAO,MAAM,iBAAiB,WAAY,WAAW,EAAE,KAAG,CAAC,GAAG,MAAM,GAAG,GAAG,MAAM,CAAC,EA8BhF,CAAA"}
|
|
@@ -1,36 +1,33 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { fieldAffectsData } from 'payload/shared';
|
|
4
|
-
export const buildPathSegments =
|
|
5
|
-
|
|
4
|
+
export const buildPathSegments = fields => {
|
|
5
|
+
return fields.reduce((acc, field) => {
|
|
6
6
|
const fields = 'fields' in field ? field.fields : undefined;
|
|
7
7
|
if (fields) {
|
|
8
8
|
if (fieldAffectsData(field)) {
|
|
9
9
|
// group, block, array
|
|
10
|
-
|
|
11
|
-
acc.push(...[...parentPath, name]);
|
|
10
|
+
acc.push(`${field.name}.`);
|
|
12
11
|
} else {
|
|
13
12
|
// rows, collapsibles, unnamed-tab
|
|
14
|
-
acc.push(...buildPathSegments(
|
|
13
|
+
acc.push(...buildPathSegments(fields));
|
|
15
14
|
}
|
|
16
15
|
} else if (field.type === 'tabs') {
|
|
17
16
|
// tabs
|
|
18
17
|
if ('tabs' in field) {
|
|
19
18
|
field.tabs?.forEach(tab => {
|
|
20
|
-
let tabPath = parentPath;
|
|
21
19
|
if ('name' in tab) {
|
|
22
|
-
|
|
20
|
+
acc.push(`${tab.name}.`);
|
|
21
|
+
} else {
|
|
22
|
+
acc.push(...buildPathSegments(tab.fields));
|
|
23
23
|
}
|
|
24
|
-
acc.push(...buildPathSegments(tabPath, tab.fields));
|
|
25
24
|
});
|
|
26
25
|
}
|
|
27
26
|
} else if (fieldAffectsData(field)) {
|
|
28
27
|
// text, number, date, etc.
|
|
29
|
-
|
|
30
|
-
acc.push(...[...parentPath, name]);
|
|
28
|
+
acc.push(field.name);
|
|
31
29
|
}
|
|
32
30
|
return acc;
|
|
33
31
|
}, []);
|
|
34
|
-
return pathNames;
|
|
35
32
|
};
|
|
36
33
|
//# sourceMappingURL=buildPathSegments.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildPathSegments.js","names":["fieldAffectsData","buildPathSegments","
|
|
1
|
+
{"version":3,"file":"buildPathSegments.js","names":["fieldAffectsData","buildPathSegments","fields","reduce","acc","field","undefined","push","name","type","tabs","forEach","tab"],"sources":["../../../src/forms/WatchChildErrors/buildPathSegments.ts"],"sourcesContent":["'use client'\nimport type { ClientField } from 'payload'\n\nimport { fieldAffectsData } from 'payload/shared'\n\nexport const buildPathSegments = (fields: ClientField[]): (`${string}.` | string)[] => {\n return fields.reduce((acc: (`${string}.` | string)[], field) => {\n const fields: ClientField[] = 'fields' in field ? field.fields : undefined\n\n if (fields) {\n if (fieldAffectsData(field)) {\n // group, block, array\n acc.push(`${field.name}.`)\n } else {\n // rows, collapsibles, unnamed-tab\n acc.push(...buildPathSegments(fields))\n }\n } else if (field.type === 'tabs') {\n // tabs\n if ('tabs' in field) {\n field.tabs?.forEach((tab) => {\n if ('name' in tab) {\n acc.push(`${tab.name}.`)\n } else {\n acc.push(...buildPathSegments(tab.fields))\n }\n })\n }\n } else if (fieldAffectsData(field)) {\n // text, number, date, etc.\n acc.push(field.name)\n }\n\n return acc\n }, [])\n}\n"],"mappings":"AAAA;;AAGA,SAASA,gBAAgB,QAAQ;AAEjC,OAAO,MAAMC,iBAAA,GAAqBC,MAAA;EAChC,OAAOA,MAAA,CAAOC,MAAM,CAAC,CAACC,GAAA,EAAgCC,KAAA;IACpD,MAAMH,MAAA,GAAwB,YAAYG,KAAA,GAAQA,KAAA,CAAMH,MAAM,GAAGI,SAAA;IAEjE,IAAIJ,MAAA,EAAQ;MACV,IAAIF,gBAAA,CAAiBK,KAAA,GAAQ;QAC3B;QACAD,GAAA,CAAIG,IAAI,CAAC,GAAGF,KAAA,CAAMG,IAAI,GAAG;MAC3B,OAAO;QACL;QACAJ,GAAA,CAAIG,IAAI,IAAIN,iBAAA,CAAkBC,MAAA;MAChC;IACF,OAAO,IAAIG,KAAA,CAAMI,IAAI,KAAK,QAAQ;MAChC;MACA,IAAI,UAAUJ,KAAA,EAAO;QACnBA,KAAA,CAAMK,IAAI,EAAEC,OAAA,CAASC,GAAA;UACnB,IAAI,UAAUA,GAAA,EAAK;YACjBR,GAAA,CAAIG,IAAI,CAAC,GAAGK,GAAA,CAAIJ,IAAI,GAAG;UACzB,OAAO;YACLJ,GAAA,CAAIG,IAAI,IAAIN,iBAAA,CAAkBW,GAAA,CAAIV,MAAM;UAC1C;QACF;MACF;IACF,OAAO,IAAIF,gBAAA,CAAiBK,KAAA,GAAQ;MAClC;MACAD,GAAA,CAAIG,IAAI,CAACF,KAAA,CAAMG,IAAI;IACrB;IAEA,OAAOJ,GAAA;EACT,GAAG,EAAE;AACP","ignoreList":[]}
|
|
@@ -2,6 +2,12 @@ import type { ClientField } from 'payload';
|
|
|
2
2
|
import type React from 'react';
|
|
3
3
|
type TrackSubSchemaErrorCountProps = {
|
|
4
4
|
fields?: ClientField[];
|
|
5
|
+
/**
|
|
6
|
+
* This path should only include path segments that affect data
|
|
7
|
+
* i.e. it should not include _index-0 type segments
|
|
8
|
+
*
|
|
9
|
+
* For collapsibles and tabs you can simply pass their parent path
|
|
10
|
+
*/
|
|
5
11
|
path: (number | string)[];
|
|
6
12
|
setErrorCount: (count: number) => void;
|
|
7
13
|
};
|
|
@@ -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;
|
|
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,CAwCpE,CAAA"}
|
|
@@ -4,42 +4,54 @@ import { c as _c } from "react/compiler-runtime";
|
|
|
4
4
|
import { useThrottledEffect } from '../../hooks/useThrottledEffect.js';
|
|
5
5
|
import { useAllFormFields, useFormSubmitted } from '../Form/context.js';
|
|
6
6
|
import { buildPathSegments } from './buildPathSegments.js';
|
|
7
|
-
import { getFieldStateFromPaths } from './getFieldStateFromPaths.js';
|
|
8
7
|
export const WatchChildErrors = t0 => {
|
|
9
8
|
const $ = _c(12);
|
|
10
9
|
const {
|
|
11
10
|
fields,
|
|
12
|
-
path,
|
|
11
|
+
path: parentPath,
|
|
13
12
|
setErrorCount
|
|
14
13
|
} = t0;
|
|
15
14
|
const [formState] = useAllFormFields();
|
|
16
15
|
const hasSubmitted = useFormSubmitted();
|
|
17
16
|
let t1;
|
|
18
|
-
if ($[0] !== fields
|
|
19
|
-
t1 = buildPathSegments(
|
|
17
|
+
if ($[0] !== fields) {
|
|
18
|
+
t1 = buildPathSegments(fields);
|
|
20
19
|
$[0] = fields;
|
|
21
|
-
$[1] =
|
|
22
|
-
$[2] = t1;
|
|
20
|
+
$[1] = t1;
|
|
23
21
|
} else {
|
|
24
|
-
t1 = $[
|
|
22
|
+
t1 = $[1];
|
|
25
23
|
}
|
|
26
|
-
const
|
|
24
|
+
const segmentsToMatch = t1;
|
|
27
25
|
let t2;
|
|
28
|
-
if ($[
|
|
26
|
+
if ($[2] !== formState || $[3] !== hasSubmitted || $[4] !== parentPath || $[5] !== segmentsToMatch || $[6] !== setErrorCount) {
|
|
29
27
|
t2 = () => {
|
|
30
28
|
if (hasSubmitted) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
let errorCount;
|
|
30
|
+
errorCount = 0;
|
|
31
|
+
Object.entries(formState).forEach(t3 => {
|
|
32
|
+
const [key] = t3;
|
|
33
|
+
const matchingSegment = segmentsToMatch?.some(segment => {
|
|
34
|
+
const segmentToMatch = [...parentPath, segment].join(".");
|
|
35
|
+
if (segmentToMatch.endsWith(".")) {
|
|
36
|
+
return key.startsWith(segmentToMatch);
|
|
37
|
+
}
|
|
38
|
+
return key === segmentToMatch;
|
|
39
|
+
});
|
|
40
|
+
if (matchingSegment) {
|
|
41
|
+
const pathState = formState[key];
|
|
42
|
+
if ("valid" in pathState && !pathState.valid) {
|
|
43
|
+
errorCount = errorCount + 1;
|
|
44
|
+
errorCount;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
36
47
|
});
|
|
37
48
|
setErrorCount(errorCount);
|
|
38
49
|
}
|
|
39
50
|
};
|
|
40
|
-
$[
|
|
41
|
-
$[
|
|
42
|
-
$[
|
|
51
|
+
$[2] = formState;
|
|
52
|
+
$[3] = hasSubmitted;
|
|
53
|
+
$[4] = parentPath;
|
|
54
|
+
$[5] = segmentsToMatch;
|
|
43
55
|
$[6] = setErrorCount;
|
|
44
56
|
$[7] = t2;
|
|
45
57
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","useThrottledEffect","useAllFormFields","useFormSubmitted","buildPathSegments","
|
|
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;QAAAA,UAAA;QACAC,MAAA,CAAAC,OAAA,CAAeP,SAAA,EAAAQ,OAAA,CAAAC,EAA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AO,KAAmB,MAAM,OAAO,CAAA;AAGvC,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/graphics/DefaultBlockImage/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAGvC,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAyCrC,CAAA"}
|