Files
klz-cables.com/.pnpm-store/v10/files/87/c2aa328fdac89f45c5d0ba974d98ce22567ead3025c6ece82bcef1a23c41dc02a4481c90771242bf851d41a1c524c2b78e3557b59e77af5cfc2cbb6ead59fa
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

1 line
18 KiB
Plaintext

{"version":3,"sources":["../../src/utilities/mergeLocalizedData.ts"],"sourcesContent":["import type { Block, Field, FlattenedBlock } from '../fields/config/types.js'\nimport type { SanitizedConfig } from '../index.js'\nimport type { JsonObject } from '../types/index.js'\n\nimport { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/config/types.js'\n\ntype MergeDataToSelectedLocalesArgs = {\n configBlockReferences: SanitizedConfig['blocks']\n dataWithLocales: JsonObject\n docWithLocales: JsonObject\n fields: Field[]\n parentIsLocalized?: boolean\n selectedLocales: string[]\n}\n\n/**\n * Merges data from dataWithLocales onto docWithLocales for specified locales.\n * For localized fields, merges only the specified locales while preserving others.\n * For non-localized fields, keeps existing values from docWithLocales unchanged.\n * Returns a new object without mutating the original.\n */\nexport function mergeLocalizedData({\n configBlockReferences,\n dataWithLocales,\n docWithLocales,\n fields,\n parentIsLocalized = false,\n selectedLocales,\n}: MergeDataToSelectedLocalesArgs): JsonObject {\n if (!docWithLocales || typeof docWithLocales !== 'object') {\n return dataWithLocales || docWithLocales\n }\n\n const result: JsonObject = { ...docWithLocales }\n\n for (const field of fields) {\n if (fieldAffectsData(field)) {\n // If the parent is localized, all children are inherently \"localized\"\n if (parentIsLocalized && dataWithLocales[field.name]) {\n result[field.name] = dataWithLocales[field.name]\n continue\n }\n\n const fieldIsLocalized = fieldShouldBeLocalized({ field, parentIsLocalized })\n\n switch (field.type) {\n case 'array': {\n if (field.name in dataWithLocales) {\n const newValue = dataWithLocales[field.name]\n const existingValue = docWithLocales[field.name]\n\n if (fieldIsLocalized) {\n // If localized, handle locale keys\n if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {\n const updatedArray: Record<string, unknown> = { ...(existingValue || {}) }\n\n for (const locale of selectedLocales) {\n if (locale in newValue) {\n updatedArray[locale] = newValue[locale]\n }\n }\n\n result[field.name] = updatedArray\n } else {\n // Preserve existing value if new value is not a valid object\n result[field.name] = existingValue\n }\n } else if (Array.isArray(newValue)) {\n // Non-localized array - still process children for any localized fields\n result[field.name] = newValue.map((newItem: JsonObject, index: number) => {\n const existingItem = existingValue?.[index] || {}\n\n return mergeLocalizedData({\n configBlockReferences,\n dataWithLocales: newItem,\n docWithLocales: existingItem,\n fields: field.fields,\n parentIsLocalized,\n selectedLocales,\n })\n })\n }\n }\n break\n }\n\n case 'blocks': {\n if (field.name in dataWithLocales) {\n const newValue = dataWithLocales[field.name]\n const existingValue = docWithLocales[field.name]\n\n if (fieldIsLocalized) {\n // If localized, handle locale keys\n if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {\n const updatedData: Record<string, unknown> = { ...(existingValue || {}) }\n\n for (const locale of selectedLocales) {\n if (locale in newValue) {\n updatedData[locale] = newValue[locale]\n }\n }\n\n result[field.name] = updatedData\n } else {\n // Preserve existing value if new value is not a valid object\n result[field.name] = existingValue\n }\n } else if (Array.isArray(newValue)) {\n // Non-localized blocks - still process children for any localized fields\n result[field.name] = newValue.map((newBlockData: JsonObject, index: number) => {\n let block: Block | FlattenedBlock | undefined\n if (configBlockReferences && field.blockReferences) {\n for (const blockOrReference of field.blockReferences) {\n if (typeof blockOrReference === 'string') {\n block = configBlockReferences.find((b) => b.slug === newBlockData.blockType)\n } else {\n block = blockOrReference\n }\n }\n } else if (field.blocks) {\n block = field.blocks.find((b) => b.slug === newBlockData.blockType)\n }\n\n if (block) {\n const blockData =\n Array.isArray(existingValue) && existingValue[index]\n ? (existingValue[index] as JsonObject)\n : {}\n\n return mergeLocalizedData({\n configBlockReferences,\n dataWithLocales: newBlockData,\n docWithLocales: blockData,\n fields: block?.fields || [],\n parentIsLocalized,\n selectedLocales,\n })\n }\n\n return newBlockData\n })\n }\n }\n break\n }\n\n case 'group': {\n if (fieldAffectsData(field) && field.name) {\n // Named groups create a nested data structure\n if (field.name in dataWithLocales) {\n const newValue = dataWithLocales[field.name]\n const existingValue = docWithLocales[field.name]\n\n if (fieldIsLocalized) {\n if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {\n const groupData: Record<string, unknown> = { ...(existingValue || {}) }\n\n for (const locale of selectedLocales) {\n if (locale in newValue && typeof newValue[locale] === 'object') {\n groupData[locale] = newValue[locale]\n }\n }\n\n result[field.name] = groupData\n } else {\n // Preserve existing value if new value is not a valid object\n result[field.name] = existingValue\n }\n } else if (typeof newValue === 'object' && !Array.isArray(newValue)) {\n // Non-localized group - still process children for any localized fields\n result[field.name] = mergeLocalizedData({\n configBlockReferences,\n dataWithLocales: newValue,\n docWithLocales: existingValue || {},\n fields: field.fields,\n parentIsLocalized,\n selectedLocales,\n })\n }\n }\n } else {\n // Unnamed groups pass through the same data level\n const merged = mergeLocalizedData({\n configBlockReferences,\n dataWithLocales,\n docWithLocales: result, // Use current result to avoid re-processing already-handled fields\n fields: field.fields,\n parentIsLocalized,\n selectedLocales,\n })\n Object.assign(result, merged)\n }\n break\n }\n\n default: {\n // For all other data-affecting fields (text, number, select, etc.)\n if (fieldIsLocalized) {\n if (field.name in dataWithLocales) {\n const newValue = dataWithLocales[field.name]\n const existingValue = docWithLocales[field.name] || {}\n\n // If localized, handle locale keys\n if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {\n const merged: Record<string, unknown> = { ...existingValue }\n\n for (const locale of selectedLocales) {\n if (locale in newValue) {\n merged[locale] = newValue[locale]\n }\n }\n\n result[field.name] = merged\n } else if (parentIsLocalized) {\n // Child of localized parent - replace with new value\n result[field.name] = newValue\n } else {\n // Preserve existing value if new value is not a valid object\n result[field.name] = existingValue\n }\n }\n } else if (parentIsLocalized) {\n result[field.name] = dataWithLocales[field.name]\n } else {\n result[field.name] =\n field.name in dataWithLocales\n ? dataWithLocales[field.name]\n : docWithLocales[field.name]\n }\n break\n }\n }\n } else {\n // Layout-only fields that don't affect data structure\n switch (field.type) {\n case 'collapsible':\n case 'row': {\n // These pass through the same data level\n const merged = mergeLocalizedData({\n configBlockReferences,\n dataWithLocales,\n docWithLocales: result, // Use current result to avoid re-processing already-handled fields\n fields: field.fields,\n parentIsLocalized,\n selectedLocales,\n })\n Object.assign(result, merged)\n break\n }\n\n case 'tabs': {\n for (const tab of field.tabs) {\n if (tabHasName(tab)) {\n // Named tabs create a nested data structure and can be localized\n const tabIsLocalized = fieldShouldBeLocalized({ field: tab, parentIsLocalized })\n\n if (tab.name in dataWithLocales) {\n const newValue = dataWithLocales[tab.name]\n const existingValue = docWithLocales[tab.name]\n\n if (tabIsLocalized) {\n if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {\n const merged: Record<string, unknown> = { ...(existingValue || {}) }\n\n for (const locale of selectedLocales) {\n if (locale in newValue && typeof newValue[locale] === 'object') {\n merged[locale] = newValue[locale]\n }\n }\n\n result[tab.name] = merged\n } else {\n // Preserve existing value if new value is not a valid object\n result[tab.name] = existingValue\n }\n } else if (typeof newValue === 'object' && !Array.isArray(newValue)) {\n // Non-localized tab - still process children for any localized fields\n result[tab.name] = mergeLocalizedData({\n configBlockReferences,\n dataWithLocales: newValue as JsonObject,\n docWithLocales: existingValue || {},\n fields: tab.fields,\n parentIsLocalized,\n selectedLocales,\n })\n }\n }\n } else {\n // Unnamed tabs pass through the same data level\n const merged = mergeLocalizedData({\n configBlockReferences,\n dataWithLocales,\n docWithLocales: result, // Use current result to avoid re-processing already-handled fields\n fields: tab.fields,\n parentIsLocalized,\n selectedLocales,\n })\n Object.assign(result, merged)\n }\n }\n break\n }\n }\n }\n }\n\n return result\n}\n"],"names":["fieldAffectsData","fieldShouldBeLocalized","tabHasName","mergeLocalizedData","configBlockReferences","dataWithLocales","docWithLocales","fields","parentIsLocalized","selectedLocales","result","field","name","fieldIsLocalized","type","newValue","existingValue","Array","isArray","updatedArray","locale","map","newItem","index","existingItem","updatedData","newBlockData","block","blockReferences","blockOrReference","find","b","slug","blockType","blocks","blockData","groupData","merged","Object","assign","tab","tabs","tabIsLocalized"],"mappings":"AAIA,SAASA,gBAAgB,EAAEC,sBAAsB,EAAEC,UAAU,QAAQ,4BAA2B;AAWhG;;;;;CAKC,GACD,OAAO,SAASC,mBAAmB,EACjCC,qBAAqB,EACrBC,eAAe,EACfC,cAAc,EACdC,MAAM,EACNC,oBAAoB,KAAK,EACzBC,eAAe,EACgB;IAC/B,IAAI,CAACH,kBAAkB,OAAOA,mBAAmB,UAAU;QACzD,OAAOD,mBAAmBC;IAC5B;IAEA,MAAMI,SAAqB;QAAE,GAAGJ,cAAc;IAAC;IAE/C,KAAK,MAAMK,SAASJ,OAAQ;QAC1B,IAAIP,iBAAiBW,QAAQ;YAC3B,sEAAsE;YACtE,IAAIH,qBAAqBH,eAAe,CAACM,MAAMC,IAAI,CAAC,EAAE;gBACpDF,MAAM,CAACC,MAAMC,IAAI,CAAC,GAAGP,eAAe,CAACM,MAAMC,IAAI,CAAC;gBAChD;YACF;YAEA,MAAMC,mBAAmBZ,uBAAuB;gBAAEU;gBAAOH;YAAkB;YAE3E,OAAQG,MAAMG,IAAI;gBAChB,KAAK;oBAAS;wBACZ,IAAIH,MAAMC,IAAI,IAAIP,iBAAiB;4BACjC,MAAMU,WAAWV,eAAe,CAACM,MAAMC,IAAI,CAAC;4BAC5C,MAAMI,gBAAgBV,cAAc,CAACK,MAAMC,IAAI,CAAC;4BAEhD,IAAIC,kBAAkB;gCACpB,mCAAmC;gCACnC,IAAIE,YAAY,OAAOA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