Files
klz-cables.com/.pnpm-store/v10/files/b6/4e4abe95b10271610e10f32fc423acd97ac4a36148c05bb6ec0976e23aa2f7785ccdf819cc521046f0cabce23ec68ce2a0b3fa113796e5f0dae171c48db4e4
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

133 lines
3.5 KiB
Plaintext

import { MissingEditorProp } from 'payload';
import { fieldAffectsData, getFieldPaths, tabHasName } from 'payload/shared';
export const traverseFields = ({
config,
fields,
i18n,
parentIndexPath,
parentSchemaPath,
schemaMap
}) => {
for (const [index, field] of fields.entries()) {
const {
indexPath,
schemaPath
} = getFieldPaths({
field,
index,
parentIndexPath,
parentSchemaPath
});
schemaMap.set(schemaPath, field);
switch (field.type) {
case 'array':
traverseFields({
config,
fields: field.fields,
i18n,
parentIndexPath: '',
parentSchemaPath: schemaPath,
schemaMap
});
break;
case 'blocks':
;
(field.blockReferences ?? field.blocks).map(_block => {
// TODO: iterate over blocks mapped to block slug in v4, or pass through payload.blocks
const block = typeof _block === 'string' ? config.blocks.find(b => b.slug === _block) : _block;
const blockSchemaPath = `${schemaPath}.${block.slug}`;
schemaMap.set(blockSchemaPath, block);
traverseFields({
config,
fields: block.fields,
i18n,
parentIndexPath: '',
parentSchemaPath: schemaPath + '.' + block.slug,
schemaMap
});
});
break;
case 'collapsible':
case 'row':
traverseFields({
config,
fields: field.fields,
i18n,
parentIndexPath: indexPath,
parentSchemaPath: schemaPath,
schemaMap
});
break;
case 'group':
if (fieldAffectsData(field)) {
traverseFields({
config,
fields: field.fields,
i18n,
parentIndexPath: '',
parentSchemaPath: schemaPath,
schemaMap
});
} else {
traverseFields({
config,
fields: field.fields,
i18n,
parentIndexPath: indexPath,
parentSchemaPath: schemaPath,
schemaMap
});
}
break;
case 'richText':
{
if (!field?.editor) {
throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor
;
}
if (typeof field.editor === 'function') {
throw new Error('Attempted to access unsanitized rich text editor.');
}
if (typeof field.editor.generateSchemaMap === 'function') {
field.editor.generateSchemaMap({
config,
field,
i18n,
schemaMap,
schemaPath
});
}
break;
}
case 'tab':
{
const isNamedTab = tabHasName(field);
traverseFields({
config,
fields: field.fields,
i18n,
parentIndexPath: isNamedTab ? '' : indexPath,
parentSchemaPath: schemaPath,
schemaMap
});
break;
}
case 'tabs':
{
traverseFields({
config,
fields: field.tabs.map(tab => ({
...tab,
type: 'tab'
})),
i18n,
parentIndexPath: indexPath,
parentSchemaPath: schemaPath,
schemaMap
});
break;
}
}
}
};
//# sourceMappingURL=traverseFields.js.map