Files
klz-cables.com/.pnpm-store/v10/files/79/71246da9bfda8d4f40c6986bb1dc6ae6ef1f10510eb8ddc0a538fc4843c5b4f89d561a048127f312140fc3375909006bebaf7698c2bb863c37ee6a6d9c6e12
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

126 lines
4.2 KiB
Plaintext

import { fieldAffectsData, tabHasName } from '../fields/config/types.js';
export const flattenBlock = ({ block })=>{
return {
...block,
flattenedFields: flattenAllFields({
fields: block.fields
})
};
};
const flattenedFieldsCache = new Map();
/**
* Flattens all fields in a collection, preserving the nested field structure.
* @param cache
* @param fields
*/ export const flattenAllFields = ({ cache, fields })=>{
if (cache) {
const maybeFields = flattenedFieldsCache.get(fields);
if (maybeFields) {
return maybeFields;
}
}
const result = [];
for (const field of fields){
switch(field.type){
case 'array':
case 'group':
{
if (fieldAffectsData(field)) {
result.push({
...field,
flattenedFields: flattenAllFields({
fields: field.fields
})
});
} else {
for (const nestedField of flattenAllFields({
fields: field.fields
})){
result.push(nestedField);
}
}
break;
}
case 'blocks':
{
const blocks = [];
let blockReferences = undefined;
if (field.blockReferences) {
blockReferences = [];
for (const block of field.blockReferences){
if (typeof block === 'string') {
blockReferences.push(block);
continue;
}
blockReferences.push(flattenBlock({
block
}));
}
} else {
for (const block of field.blocks){
if (typeof block === 'string') {
blocks.push(block);
continue;
}
blocks.push(flattenBlock({
block
}));
}
}
const resultField = {
...field,
blockReferences,
blocks
};
result.push(resultField);
break;
}
case 'collapsible':
case 'row':
{
for (const nestedField of flattenAllFields({
fields: field.fields
})){
result.push(nestedField);
}
break;
}
case 'join':
{
result.push(field);
break;
}
case 'tabs':
{
for (const tab of field.tabs){
if (!tabHasName(tab)) {
for (const nestedField of flattenAllFields({
fields: tab.fields
})){
result.push(nestedField);
}
} else {
result.push({
...tab,
type: 'tab',
flattenedFields: flattenAllFields({
fields: tab.fields
})
});
}
}
break;
}
default:
{
if (field.type !== 'ui') {
result.push(field);
}
}
}
}
flattenedFieldsCache.set(fields, result);
return result;
};
//# sourceMappingURL=flattenAllFields.js.map