payload 3.71.1 → 3.72.0-internal.3e70d4c

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.
Files changed (151) hide show
  1. package/dist/collections/config/sanitize.d.ts.map +1 -1
  2. package/dist/collections/config/sanitize.js +19 -4
  3. package/dist/collections/config/sanitize.js.map +1 -1
  4. package/dist/collections/endpoints/create.d.ts.map +1 -1
  5. package/dist/collections/endpoints/create.js +2 -1
  6. package/dist/collections/endpoints/create.js.map +1 -1
  7. package/dist/collections/endpoints/update.d.ts.map +1 -1
  8. package/dist/collections/endpoints/update.js +3 -1
  9. package/dist/collections/endpoints/update.js.map +1 -1
  10. package/dist/collections/endpoints/updateByID.d.ts.map +1 -1
  11. package/dist/collections/endpoints/updateByID.js +4 -2
  12. package/dist/collections/endpoints/updateByID.js.map +1 -1
  13. package/dist/collections/operations/create.d.ts +1 -0
  14. package/dist/collections/operations/create.d.ts.map +1 -1
  15. package/dist/collections/operations/create.js +23 -3
  16. package/dist/collections/operations/create.js.map +1 -1
  17. package/dist/collections/operations/local/create.d.ts +4 -0
  18. package/dist/collections/operations/local/create.d.ts.map +1 -1
  19. package/dist/collections/operations/local/create.js +2 -1
  20. package/dist/collections/operations/local/create.js.map +1 -1
  21. package/dist/collections/operations/local/update.d.ts +12 -0
  22. package/dist/collections/operations/local/update.d.ts.map +1 -1
  23. package/dist/collections/operations/local/update.js +3 -1
  24. package/dist/collections/operations/local/update.js.map +1 -1
  25. package/dist/collections/operations/update.d.ts +2 -0
  26. package/dist/collections/operations/update.d.ts.map +1 -1
  27. package/dist/collections/operations/update.js +4 -3
  28. package/dist/collections/operations/update.js.map +1 -1
  29. package/dist/collections/operations/updateByID.d.ts +2 -0
  30. package/dist/collections/operations/updateByID.d.ts.map +1 -1
  31. package/dist/collections/operations/updateByID.js +4 -3
  32. package/dist/collections/operations/updateByID.js.map +1 -1
  33. package/dist/collections/operations/utilities/update.d.ts +4 -3
  34. package/dist/collections/operations/utilities/update.d.ts.map +1 -1
  35. package/dist/collections/operations/utilities/update.js +81 -31
  36. package/dist/collections/operations/utilities/update.js.map +1 -1
  37. package/dist/config/types.d.ts +16 -0
  38. package/dist/config/types.d.ts.map +1 -1
  39. package/dist/config/types.js.map +1 -1
  40. package/dist/database/migrations/templates/localizeStatus.d.ts +10 -0
  41. package/dist/database/migrations/templates/localizeStatus.d.ts.map +1 -0
  42. package/dist/database/migrations/templates/localizeStatus.js +54 -0
  43. package/dist/database/migrations/templates/localizeStatus.js.map +1 -0
  44. package/dist/exports/migrations.d.ts +19 -0
  45. package/dist/exports/migrations.d.ts.map +1 -0
  46. package/dist/exports/migrations.js +19 -0
  47. package/dist/exports/migrations.js.map +1 -0
  48. package/dist/exports/shared.d.ts +1 -1
  49. package/dist/exports/shared.d.ts.map +1 -1
  50. package/dist/exports/shared.js +1 -1
  51. package/dist/exports/shared.js.map +1 -1
  52. package/dist/globals/config/sanitize.d.ts.map +1 -1
  53. package/dist/globals/config/sanitize.js +11 -1
  54. package/dist/globals/config/sanitize.js.map +1 -1
  55. package/dist/globals/endpoints/update.d.ts.map +1 -1
  56. package/dist/globals/endpoints/update.js +5 -1
  57. package/dist/globals/endpoints/update.js.map +1 -1
  58. package/dist/globals/operations/local/update.d.ts +10 -0
  59. package/dist/globals/operations/local/update.d.ts.map +1 -1
  60. package/dist/globals/operations/local/update.js +4 -2
  61. package/dist/globals/operations/local/update.js.map +1 -1
  62. package/dist/globals/operations/update.d.ts +2 -0
  63. package/dist/globals/operations/update.d.ts.map +1 -1
  64. package/dist/globals/operations/update.js +63 -15
  65. package/dist/globals/operations/update.js.map +1 -1
  66. package/dist/index.bundled.d.ts +102 -3
  67. package/dist/index.d.ts +2 -0
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +1 -0
  70. package/dist/index.js.map +1 -1
  71. package/dist/utilities/getVersionsConfig.d.ts +4 -0
  72. package/dist/utilities/getVersionsConfig.d.ts.map +1 -1
  73. package/dist/utilities/getVersionsConfig.js +7 -2
  74. package/dist/utilities/getVersionsConfig.js.map +1 -1
  75. package/dist/utilities/mergeLocalizedData.d.ts +20 -0
  76. package/dist/utilities/mergeLocalizedData.d.ts.map +1 -0
  77. package/dist/utilities/mergeLocalizedData.js +277 -0
  78. package/dist/utilities/mergeLocalizedData.js.map +1 -0
  79. package/dist/utilities/mergeLocalizedData.spec.js +784 -0
  80. package/dist/utilities/mergeLocalizedData.spec.js.map +1 -0
  81. package/dist/utilities/miniChalk.d.ts +15 -0
  82. package/dist/utilities/miniChalk.d.ts.map +1 -0
  83. package/dist/utilities/miniChalk.js +34 -0
  84. package/dist/utilities/miniChalk.js.map +1 -0
  85. package/dist/utilities/parseParams/index.d.ts +24 -20
  86. package/dist/utilities/parseParams/index.d.ts.map +1 -1
  87. package/dist/utilities/parseParams/index.js.map +1 -1
  88. package/dist/utilities/traverseForLocalizedFields.d.ts +3 -0
  89. package/dist/utilities/traverseForLocalizedFields.d.ts.map +1 -0
  90. package/dist/utilities/traverseForLocalizedFields.js +41 -0
  91. package/dist/utilities/traverseForLocalizedFields.js.map +1 -0
  92. package/dist/versions/baseFields.d.ts +3 -1
  93. package/dist/versions/baseFields.d.ts.map +1 -1
  94. package/dist/versions/baseFields.js +16 -15
  95. package/dist/versions/baseFields.js.map +1 -1
  96. package/dist/versions/drafts/replaceWithDraftIfAvailable.d.ts.map +1 -1
  97. package/dist/versions/drafts/replaceWithDraftIfAvailable.js +28 -2
  98. package/dist/versions/drafts/replaceWithDraftIfAvailable.js.map +1 -1
  99. package/dist/versions/migrations/localizeStatus/index.d.ts +12 -0
  100. package/dist/versions/migrations/localizeStatus/index.d.ts.map +1 -0
  101. package/dist/versions/migrations/localizeStatus/index.js +33 -0
  102. package/dist/versions/migrations/localizeStatus/index.js.map +1 -0
  103. package/dist/versions/migrations/localizeStatus/mongo/down.d.ts +9 -0
  104. package/dist/versions/migrations/localizeStatus/mongo/down.d.ts.map +1 -0
  105. package/dist/versions/migrations/localizeStatus/mongo/down.js +112 -0
  106. package/dist/versions/migrations/localizeStatus/mongo/down.js.map +1 -0
  107. package/dist/versions/migrations/localizeStatus/mongo/index.d.ts +8 -0
  108. package/dist/versions/migrations/localizeStatus/mongo/index.d.ts.map +1 -0
  109. package/dist/versions/migrations/localizeStatus/mongo/index.js +8 -0
  110. package/dist/versions/migrations/localizeStatus/mongo/index.js.map +1 -0
  111. package/dist/versions/migrations/localizeStatus/mongo/up.d.ts +9 -0
  112. package/dist/versions/migrations/localizeStatus/mongo/up.d.ts.map +1 -0
  113. package/dist/versions/migrations/localizeStatus/mongo/up.js +220 -0
  114. package/dist/versions/migrations/localizeStatus/mongo/up.js.map +1 -0
  115. package/dist/versions/migrations/localizeStatus/shared.d.ts +59 -0
  116. package/dist/versions/migrations/localizeStatus/shared.d.ts.map +1 -0
  117. package/dist/versions/migrations/localizeStatus/shared.js +122 -0
  118. package/dist/versions/migrations/localizeStatus/shared.js.map +1 -0
  119. package/dist/versions/migrations/localizeStatus/sql/down.d.ts +11 -0
  120. package/dist/versions/migrations/localizeStatus/sql/down.d.ts.map +1 -0
  121. package/dist/versions/migrations/localizeStatus/sql/down.js +213 -0
  122. package/dist/versions/migrations/localizeStatus/sql/down.js.map +1 -0
  123. package/dist/versions/migrations/localizeStatus/sql/index.d.ts +8 -0
  124. package/dist/versions/migrations/localizeStatus/sql/index.d.ts.map +1 -0
  125. package/dist/versions/migrations/localizeStatus/sql/index.js +8 -0
  126. package/dist/versions/migrations/localizeStatus/sql/index.js.map +1 -0
  127. package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.d.ts +13 -0
  128. package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.d.ts.map +1 -0
  129. package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.js +51 -0
  130. package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.js.map +1 -0
  131. package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.d.ts +13 -0
  132. package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.d.ts.map +1 -0
  133. package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.js +54 -0
  134. package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.js.map +1 -0
  135. package/dist/versions/migrations/localizeStatus/sql/up.d.ts +11 -0
  136. package/dist/versions/migrations/localizeStatus/sql/up.d.ts.map +1 -0
  137. package/dist/versions/migrations/localizeStatus/sql/up.js +277 -0
  138. package/dist/versions/migrations/localizeStatus/sql/up.js.map +1 -0
  139. package/dist/versions/saveSnapshot.d.ts.map +1 -1
  140. package/dist/versions/saveSnapshot.js +0 -1
  141. package/dist/versions/saveSnapshot.js.map +1 -1
  142. package/dist/versions/saveVersion.js +0 -3
  143. package/dist/versions/saveVersion.js.map +1 -1
  144. package/dist/versions/types.d.ts +18 -0
  145. package/dist/versions/types.d.ts.map +1 -1
  146. package/dist/versions/types.js.map +1 -1
  147. package/package.json +7 -2
  148. package/dist/uploads/imageResizer.d.ts +0 -40
  149. package/dist/uploads/imageResizer.d.ts.map +0 -1
  150. package/dist/uploads/imageResizer.js +0 -356
  151. package/dist/uploads/imageResizer.js.map +0 -1
@@ -0,0 +1,277 @@
1
+ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/config/types.js';
2
+ /**
3
+ * Merges data from dataWithLocales onto docWithLocales for specified locales.
4
+ * For localized fields, merges only the specified locales while preserving others.
5
+ * For non-localized fields, keeps existing values from docWithLocales unchanged.
6
+ * Returns a new object without mutating the original.
7
+ */ export function mergeLocalizedData({ configBlockReferences, dataWithLocales, docWithLocales, fields, parentIsLocalized = false, selectedLocales }) {
8
+ if (!docWithLocales || typeof docWithLocales !== 'object') {
9
+ return dataWithLocales || docWithLocales;
10
+ }
11
+ const result = {
12
+ ...docWithLocales
13
+ };
14
+ for (const field of fields){
15
+ if (fieldAffectsData(field)) {
16
+ // If the parent is localized, all children are inherently "localized"
17
+ if (parentIsLocalized && dataWithLocales[field.name]) {
18
+ result[field.name] = dataWithLocales[field.name];
19
+ continue;
20
+ }
21
+ const fieldIsLocalized = fieldShouldBeLocalized({
22
+ field,
23
+ parentIsLocalized
24
+ });
25
+ switch(field.type){
26
+ case 'array':
27
+ {
28
+ if (field.name in dataWithLocales) {
29
+ const newValue = dataWithLocales[field.name];
30
+ const existingValue = docWithLocales[field.name];
31
+ if (fieldIsLocalized) {
32
+ // If localized, handle locale keys
33
+ if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {
34
+ const updatedArray = {
35
+ ...existingValue || {}
36
+ };
37
+ for (const locale of selectedLocales){
38
+ if (locale in newValue) {
39
+ updatedArray[locale] = newValue[locale];
40
+ }
41
+ }
42
+ result[field.name] = updatedArray;
43
+ } else {
44
+ // Preserve existing value if new value is not a valid object
45
+ result[field.name] = existingValue;
46
+ }
47
+ } else if (Array.isArray(newValue)) {
48
+ // Non-localized array - still process children for any localized fields
49
+ result[field.name] = newValue.map((newItem, index)=>{
50
+ const existingItem = existingValue?.[index] || {};
51
+ return mergeLocalizedData({
52
+ configBlockReferences,
53
+ dataWithLocales: newItem,
54
+ docWithLocales: existingItem,
55
+ fields: field.fields,
56
+ parentIsLocalized,
57
+ selectedLocales
58
+ });
59
+ });
60
+ }
61
+ }
62
+ break;
63
+ }
64
+ case 'blocks':
65
+ {
66
+ if (field.name in dataWithLocales) {
67
+ const newValue = dataWithLocales[field.name];
68
+ const existingValue = docWithLocales[field.name];
69
+ if (fieldIsLocalized) {
70
+ // If localized, handle locale keys
71
+ if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {
72
+ const updatedData = {
73
+ ...existingValue || {}
74
+ };
75
+ for (const locale of selectedLocales){
76
+ if (locale in newValue) {
77
+ updatedData[locale] = newValue[locale];
78
+ }
79
+ }
80
+ result[field.name] = updatedData;
81
+ } else {
82
+ // Preserve existing value if new value is not a valid object
83
+ result[field.name] = existingValue;
84
+ }
85
+ } else if (Array.isArray(newValue)) {
86
+ // Non-localized blocks - still process children for any localized fields
87
+ result[field.name] = newValue.map((newBlockData, index)=>{
88
+ let block;
89
+ if (configBlockReferences && field.blockReferences) {
90
+ for (const blockOrReference of field.blockReferences){
91
+ if (typeof blockOrReference === 'string') {
92
+ block = configBlockReferences.find((b)=>b.slug === newBlockData.blockType);
93
+ } else {
94
+ block = blockOrReference;
95
+ }
96
+ }
97
+ } else if (field.blocks) {
98
+ block = field.blocks.find((b)=>b.slug === newBlockData.blockType);
99
+ }
100
+ if (block) {
101
+ const blockData = Array.isArray(existingValue) && existingValue[index] ? existingValue[index] : {};
102
+ return mergeLocalizedData({
103
+ configBlockReferences,
104
+ dataWithLocales: newBlockData,
105
+ docWithLocales: blockData,
106
+ fields: block?.fields || [],
107
+ parentIsLocalized,
108
+ selectedLocales
109
+ });
110
+ }
111
+ return newBlockData;
112
+ });
113
+ }
114
+ }
115
+ break;
116
+ }
117
+ case 'group':
118
+ {
119
+ if (fieldAffectsData(field) && field.name) {
120
+ // Named groups create a nested data structure
121
+ if (field.name in dataWithLocales) {
122
+ const newValue = dataWithLocales[field.name];
123
+ const existingValue = docWithLocales[field.name];
124
+ if (fieldIsLocalized) {
125
+ if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {
126
+ const groupData = {
127
+ ...existingValue || {}
128
+ };
129
+ for (const locale of selectedLocales){
130
+ if (locale in newValue && typeof newValue[locale] === 'object') {
131
+ groupData[locale] = newValue[locale];
132
+ }
133
+ }
134
+ result[field.name] = groupData;
135
+ } else {
136
+ // Preserve existing value if new value is not a valid object
137
+ result[field.name] = existingValue;
138
+ }
139
+ } else if (typeof newValue === 'object' && !Array.isArray(newValue)) {
140
+ // Non-localized group - still process children for any localized fields
141
+ result[field.name] = mergeLocalizedData({
142
+ configBlockReferences,
143
+ dataWithLocales: newValue,
144
+ docWithLocales: existingValue || {},
145
+ fields: field.fields,
146
+ parentIsLocalized,
147
+ selectedLocales
148
+ });
149
+ }
150
+ }
151
+ } else {
152
+ // Unnamed groups pass through the same data level
153
+ const merged = mergeLocalizedData({
154
+ configBlockReferences,
155
+ dataWithLocales,
156
+ docWithLocales: result,
157
+ fields: field.fields,
158
+ parentIsLocalized,
159
+ selectedLocales
160
+ });
161
+ Object.assign(result, merged);
162
+ }
163
+ break;
164
+ }
165
+ default:
166
+ {
167
+ // For all other data-affecting fields (text, number, select, etc.)
168
+ if (fieldIsLocalized) {
169
+ if (field.name in dataWithLocales) {
170
+ const newValue = dataWithLocales[field.name];
171
+ const existingValue = docWithLocales[field.name] || {};
172
+ // If localized, handle locale keys
173
+ if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {
174
+ const merged = {
175
+ ...existingValue
176
+ };
177
+ for (const locale of selectedLocales){
178
+ if (locale in newValue) {
179
+ merged[locale] = newValue[locale];
180
+ }
181
+ }
182
+ result[field.name] = merged;
183
+ } else if (parentIsLocalized) {
184
+ // Child of localized parent - replace with new value
185
+ result[field.name] = newValue;
186
+ } else {
187
+ // Preserve existing value if new value is not a valid object
188
+ result[field.name] = existingValue;
189
+ }
190
+ }
191
+ } else if (parentIsLocalized) {
192
+ result[field.name] = dataWithLocales[field.name];
193
+ } else {
194
+ result[field.name] = field.name in dataWithLocales ? dataWithLocales[field.name] : docWithLocales[field.name];
195
+ }
196
+ break;
197
+ }
198
+ }
199
+ } else {
200
+ // Layout-only fields that don't affect data structure
201
+ switch(field.type){
202
+ case 'collapsible':
203
+ case 'row':
204
+ {
205
+ // These pass through the same data level
206
+ const merged = mergeLocalizedData({
207
+ configBlockReferences,
208
+ dataWithLocales,
209
+ docWithLocales: result,
210
+ fields: field.fields,
211
+ parentIsLocalized,
212
+ selectedLocales
213
+ });
214
+ Object.assign(result, merged);
215
+ break;
216
+ }
217
+ case 'tabs':
218
+ {
219
+ for (const tab of field.tabs){
220
+ if (tabHasName(tab)) {
221
+ // Named tabs create a nested data structure and can be localized
222
+ const tabIsLocalized = fieldShouldBeLocalized({
223
+ field: tab,
224
+ parentIsLocalized
225
+ });
226
+ if (tab.name in dataWithLocales) {
227
+ const newValue = dataWithLocales[tab.name];
228
+ const existingValue = docWithLocales[tab.name];
229
+ if (tabIsLocalized) {
230
+ if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {
231
+ const merged = {
232
+ ...existingValue || {}
233
+ };
234
+ for (const locale of selectedLocales){
235
+ if (locale in newValue && typeof newValue[locale] === 'object') {
236
+ merged[locale] = newValue[locale];
237
+ }
238
+ }
239
+ result[tab.name] = merged;
240
+ } else {
241
+ // Preserve existing value if new value is not a valid object
242
+ result[tab.name] = existingValue;
243
+ }
244
+ } else if (typeof newValue === 'object' && !Array.isArray(newValue)) {
245
+ // Non-localized tab - still process children for any localized fields
246
+ result[tab.name] = mergeLocalizedData({
247
+ configBlockReferences,
248
+ dataWithLocales: newValue,
249
+ docWithLocales: existingValue || {},
250
+ fields: tab.fields,
251
+ parentIsLocalized,
252
+ selectedLocales
253
+ });
254
+ }
255
+ }
256
+ } else {
257
+ // Unnamed tabs pass through the same data level
258
+ const merged = mergeLocalizedData({
259
+ configBlockReferences,
260
+ dataWithLocales,
261
+ docWithLocales: result,
262
+ fields: tab.fields,
263
+ parentIsLocalized,
264
+ selectedLocales
265
+ });
266
+ Object.assign(result, merged);
267
+ }
268
+ }
269
+ break;
270
+ }
271
+ }
272
+ }
273
+ }
274
+ return result;
275
+ }
276
+
277
+ //# sourceMappingURL=mergeLocalizedData.js.map
@@ -0,0 +1 @@
1
+ {"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,GA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