payload 4.0.0-internal.293e026 → 4.0.0-internal.2fddfc0
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/admin/fields/Row.d.ts +2 -2
- package/dist/admin/fields/Row.d.ts.map +1 -1
- package/dist/admin/fields/Row.js.map +1 -1
- package/dist/admin/forms/Description.d.ts +2 -2
- package/dist/admin/forms/Description.d.ts.map +1 -1
- package/dist/admin/forms/Description.js.map +1 -1
- package/dist/admin/forms/Field.d.ts +1 -3
- package/dist/admin/forms/Field.d.ts.map +1 -1
- package/dist/admin/forms/Field.js.map +1 -1
- package/dist/admin/types.d.ts +1 -1
- package/dist/admin/types.d.ts.map +1 -1
- package/dist/admin/types.js.map +1 -1
- package/dist/admin/views/document.d.ts +0 -4
- package/dist/admin/views/document.d.ts.map +1 -1
- package/dist/admin/views/document.js.map +1 -1
- package/dist/admin/views/list.d.ts +5 -0
- package/dist/admin/views/list.d.ts.map +1 -1
- package/dist/admin/views/list.js.map +1 -1
- package/dist/auth/baseFields/apiKey.d.ts +10 -2
- package/dist/auth/baseFields/apiKey.d.ts.map +1 -1
- package/dist/auth/baseFields/apiKey.js +35 -24
- package/dist/auth/baseFields/apiKey.js.map +1 -1
- package/dist/auth/getAuthFields.js +2 -2
- package/dist/auth/getAuthFields.js.map +1 -1
- package/dist/bin/generateImportMap/iterateCollections.d.ts.map +1 -1
- package/dist/bin/generateImportMap/iterateCollections.js +1 -0
- package/dist/bin/generateImportMap/iterateCollections.js.map +1 -1
- package/dist/bin/generateImportMap/iterateConfig.d.ts.map +1 -1
- package/dist/bin/generateImportMap/iterateConfig.js +12 -0
- package/dist/bin/generateImportMap/iterateConfig.js.map +1 -1
- package/dist/collections/config/sanitize.d.ts.map +1 -1
- package/dist/collections/config/sanitize.js +1 -11
- package/dist/collections/config/sanitize.js.map +1 -1
- package/dist/collections/config/types.d.ts +1 -0
- package/dist/collections/config/types.d.ts.map +1 -1
- package/dist/collections/config/types.js.map +1 -1
- package/dist/collections/endpoints/create.d.ts.map +1 -1
- package/dist/collections/endpoints/create.js +0 -2
- package/dist/collections/endpoints/create.js.map +1 -1
- package/dist/collections/endpoints/updateByID.d.ts.map +1 -1
- package/dist/collections/endpoints/updateByID.js +1 -2
- package/dist/collections/endpoints/updateByID.js.map +1 -1
- package/dist/collections/operations/count.d.ts.map +1 -1
- package/dist/collections/operations/count.js +1 -0
- package/dist/collections/operations/count.js.map +1 -1
- package/dist/collections/operations/create.d.ts +0 -1
- package/dist/collections/operations/create.d.ts.map +1 -1
- package/dist/collections/operations/create.js +14 -6
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/collections/operations/local/update.d.ts +4 -8
- package/dist/collections/operations/local/update.d.ts.map +1 -1
- package/dist/collections/operations/local/update.js +1 -2
- package/dist/collections/operations/local/update.js.map +1 -1
- package/dist/collections/operations/update.d.ts +0 -1
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +8 -4
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/updateByID.d.ts +0 -1
- package/dist/collections/operations/updateByID.d.ts.map +1 -1
- package/dist/collections/operations/updateByID.js +1 -5
- package/dist/collections/operations/updateByID.js.map +1 -1
- package/dist/collections/operations/utilities/copyDataWithFreshRowIDs.d.ts +9 -0
- package/dist/collections/operations/utilities/copyDataWithFreshRowIDs.d.ts.map +1 -0
- package/dist/collections/operations/utilities/copyDataWithFreshRowIDs.js +170 -0
- package/dist/collections/operations/utilities/copyDataWithFreshRowIDs.js.map +1 -0
- package/dist/collections/operations/utilities/update.d.ts +1 -2
- package/dist/collections/operations/utilities/update.d.ts.map +1 -1
- package/dist/collections/operations/utilities/update.js +48 -57
- package/dist/collections/operations/utilities/update.js.map +1 -1
- package/dist/config/orderable/index.d.ts.map +1 -1
- package/dist/config/orderable/index.js +23 -0
- package/dist/config/orderable/index.js.map +1 -1
- package/dist/config/types.d.ts +14 -17
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js +1 -0
- package/dist/config/types.js.map +1 -1
- package/dist/errors/ValidationError.d.ts +1 -0
- package/dist/errors/ValidationError.d.ts.map +1 -1
- package/dist/errors/ValidationError.js.map +1 -1
- package/dist/exports/migrations.d.ts +5 -13
- package/dist/exports/migrations.d.ts.map +1 -1
- package/dist/exports/migrations.js +5 -13
- package/dist/exports/migrations.js.map +1 -1
- package/dist/exports/shared.d.ts +1 -1
- package/dist/exports/shared.d.ts.map +1 -1
- package/dist/exports/shared.js +1 -1
- package/dist/exports/shared.js.map +1 -1
- package/dist/fields/config/client.d.ts.map +1 -1
- package/dist/fields/config/client.js +10 -3
- package/dist/fields/config/client.js.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
- package/dist/globals/config/sanitize.d.ts.map +1 -1
- package/dist/globals/config/sanitize.js +1 -6
- package/dist/globals/config/sanitize.js.map +1 -1
- package/dist/globals/endpoints/update.d.ts.map +1 -1
- package/dist/globals/endpoints/update.js +0 -2
- package/dist/globals/endpoints/update.js.map +1 -1
- package/dist/globals/operations/local/update.d.ts +4 -6
- package/dist/globals/operations/local/update.d.ts.map +1 -1
- package/dist/globals/operations/local/update.js +1 -2
- package/dist/globals/operations/local/update.js.map +1 -1
- package/dist/globals/operations/update.d.ts +0 -1
- package/dist/globals/operations/update.d.ts.map +1 -1
- package/dist/globals/operations/update.js +52 -58
- package/dist/globals/operations/update.js.map +1 -1
- package/dist/index.bundled.d.ts +123 -107
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/query-presets/config.d.ts.map +1 -1
- package/dist/query-presets/config.js +73 -34
- package/dist/query-presets/config.js.map +1 -1
- package/dist/query-presets/constraints.d.ts.map +1 -1
- package/dist/query-presets/constraints.js +2 -1
- package/dist/query-presets/constraints.js.map +1 -1
- package/dist/utilities/deepCopyObject.d.ts.map +1 -1
- package/dist/utilities/deepCopyObject.js +8 -0
- package/dist/utilities/deepCopyObject.js.map +1 -1
- package/dist/utilities/getFieldByPath.d.ts.map +1 -1
- package/dist/utilities/getFieldByPath.js.map +1 -1
- package/dist/utilities/getVersionsConfig.js.map +1 -1
- package/dist/utilities/mergeLocalizedData.d.ts +14 -4
- package/dist/utilities/mergeLocalizedData.d.ts.map +1 -1
- package/dist/utilities/mergeLocalizedData.js +49 -34
- package/dist/utilities/mergeLocalizedData.js.map +1 -1
- package/dist/utilities/mergeLocalizedData.spec.js +23 -23
- package/dist/utilities/mergeLocalizedData.spec.js.map +1 -1
- package/dist/utilities/parseParams/index.d.ts +2 -5
- package/dist/utilities/parseParams/index.d.ts.map +1 -1
- package/dist/utilities/parseParams/index.js.map +1 -1
- package/dist/utilities/parseParams/index.spec.js +0 -9
- package/dist/utilities/parseParams/index.spec.js.map +1 -1
- package/dist/utilities/traverseFields.d.ts.map +1 -1
- package/dist/utilities/traverseFields.js.map +1 -1
- package/dist/versions/baseFields.d.ts +1 -2
- package/dist/versions/baseFields.d.ts.map +1 -1
- package/dist/versions/baseFields.js +0 -13
- package/dist/versions/baseFields.js.map +1 -1
- package/dist/versions/buildCollectionFields.d.ts.map +1 -1
- package/dist/versions/buildCollectionFields.js +0 -2
- package/dist/versions/buildCollectionFields.js.map +1 -1
- package/dist/versions/buildGlobalFields.d.ts.map +1 -1
- package/dist/versions/buildGlobalFields.js +0 -2
- package/dist/versions/buildGlobalFields.js.map +1 -1
- package/dist/versions/buildSingleLocalePublishData.d.ts +32 -0
- package/dist/versions/buildSingleLocalePublishData.d.ts.map +1 -0
- package/dist/versions/buildSingleLocalePublishData.js +37 -0
- package/dist/versions/buildSingleLocalePublishData.js.map +1 -0
- package/dist/versions/saveVersion.d.ts +0 -2
- package/dist/versions/saveVersion.d.ts.map +1 -1
- package/dist/versions/saveVersion.js +12 -17
- package/dist/versions/saveVersion.js.map +1 -1
- package/dist/versions/schedule/job.d.ts.map +1 -1
- package/dist/versions/schedule/job.js +2 -9
- package/dist/versions/schedule/job.js.map +1 -1
- package/dist/versions/types.d.ts +2 -15
- package/dist/versions/types.d.ts.map +1 -1
- package/dist/versions/types.js.map +1 -1
- package/package.json +2 -2
- package/dist/database/migrations/templates/localizeStatus.d.ts +0 -10
- package/dist/database/migrations/templates/localizeStatus.d.ts.map +0 -1
- package/dist/database/migrations/templates/localizeStatus.js +0 -54
- package/dist/database/migrations/templates/localizeStatus.js.map +0 -1
- package/dist/versions/migrations/localizeStatus/index.d.ts +0 -12
- package/dist/versions/migrations/localizeStatus/index.d.ts.map +0 -1
- package/dist/versions/migrations/localizeStatus/index.js +0 -33
- package/dist/versions/migrations/localizeStatus/index.js.map +0 -1
- package/dist/versions/migrations/localizeStatus/mongo/down.d.ts +0 -9
- package/dist/versions/migrations/localizeStatus/mongo/down.d.ts.map +0 -1
- package/dist/versions/migrations/localizeStatus/mongo/down.js +0 -112
- package/dist/versions/migrations/localizeStatus/mongo/down.js.map +0 -1
- package/dist/versions/migrations/localizeStatus/mongo/index.d.ts +0 -8
- package/dist/versions/migrations/localizeStatus/mongo/index.d.ts.map +0 -1
- package/dist/versions/migrations/localizeStatus/mongo/index.js +0 -8
- package/dist/versions/migrations/localizeStatus/mongo/index.js.map +0 -1
- package/dist/versions/migrations/localizeStatus/mongo/up.d.ts +0 -9
- package/dist/versions/migrations/localizeStatus/mongo/up.d.ts.map +0 -1
- package/dist/versions/migrations/localizeStatus/mongo/up.js +0 -220
- package/dist/versions/migrations/localizeStatus/mongo/up.js.map +0 -1
- package/dist/versions/migrations/localizeStatus/sql/down.d.ts +0 -11
- package/dist/versions/migrations/localizeStatus/sql/down.d.ts.map +0 -1
- package/dist/versions/migrations/localizeStatus/sql/down.js +0 -213
- package/dist/versions/migrations/localizeStatus/sql/down.js.map +0 -1
- package/dist/versions/migrations/localizeStatus/sql/index.d.ts +0 -8
- package/dist/versions/migrations/localizeStatus/sql/index.d.ts.map +0 -1
- package/dist/versions/migrations/localizeStatus/sql/index.js +0 -8
- package/dist/versions/migrations/localizeStatus/sql/index.js.map +0 -1
- package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.d.ts +0 -13
- package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.d.ts.map +0 -1
- package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.js +0 -51
- package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.js.map +0 -1
- package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.d.ts +0 -13
- package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.d.ts.map +0 -1
- package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.js +0 -54
- package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.js.map +0 -1
- package/dist/versions/migrations/localizeStatus/sql/up.d.ts +0 -11
- package/dist/versions/migrations/localizeStatus/sql/up.d.ts.map +0 -1
- package/dist/versions/migrations/localizeStatus/sql/up.js +0 -277
- package/dist/versions/migrations/localizeStatus/sql/up.js.map +0 -1
- package/dist/versions/saveSnapshot.d.ts +0 -18
- package/dist/versions/saveSnapshot.d.ts.map +0 -1
- package/dist/versions/saveSnapshot.js +0 -38
- package/dist/versions/saveSnapshot.js.map +0 -1
|
@@ -26,12 +26,31 @@ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/
|
|
|
26
26
|
}
|
|
27
27
|
return names;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns a copy of `existingValue` (a locale-keyed object) keeping only locales
|
|
31
|
+
* that are in `localesToPreserve` (when provided) or all locales (when not provided).
|
|
32
|
+
*/ function filterPreservedData(existingValue, localesToPreserve) {
|
|
33
|
+
const existing = existingValue && typeof existingValue === 'object' ? existingValue : {};
|
|
34
|
+
if (!localesToPreserve) {
|
|
35
|
+
return {
|
|
36
|
+
...existing
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const out = {};
|
|
40
|
+
for (const lc of localesToPreserve){
|
|
41
|
+
if (lc in existing) {
|
|
42
|
+
out[lc] = existing[lc];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
29
47
|
/**
|
|
30
48
|
* Merges data from dataWithLocales onto docWithLocales for specified locales.
|
|
31
|
-
* For localized fields, merges only the specified locales while preserving others
|
|
49
|
+
* For localized fields, merges only the specified locales while preserving others
|
|
50
|
+
* (or only `localesToPreserve` if supplied).
|
|
32
51
|
* For non-localized fields, keeps existing values from docWithLocales unchanged.
|
|
33
52
|
* Returns a new object without mutating the original.
|
|
34
|
-
*/ export function mergeLocalizedData({ configBlockReferences, dataWithLocales, docWithLocales, fields, parentIsLocalized = false
|
|
53
|
+
*/ export function mergeLocalizedData({ configBlockReferences, dataWithLocales, docWithLocales, fields, localesToPreserve, localesToUpdate, parentIsLocalized = false }) {
|
|
35
54
|
if (!docWithLocales || typeof docWithLocales !== 'object') {
|
|
36
55
|
return dataWithLocales || docWithLocales;
|
|
37
56
|
}
|
|
@@ -58,10 +77,8 @@ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/
|
|
|
58
77
|
if (fieldIsLocalized) {
|
|
59
78
|
// If localized, handle locale keys
|
|
60
79
|
if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {
|
|
61
|
-
const updatedArray =
|
|
62
|
-
|
|
63
|
-
};
|
|
64
|
-
for (const locale of selectedLocales){
|
|
80
|
+
const updatedArray = filterPreservedData(existingValue, localesToPreserve);
|
|
81
|
+
for (const locale of localesToUpdate){
|
|
65
82
|
if (locale in newValue) {
|
|
66
83
|
updatedArray[locale] = newValue[locale];
|
|
67
84
|
}
|
|
@@ -80,8 +97,9 @@ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/
|
|
|
80
97
|
dataWithLocales: newItem,
|
|
81
98
|
docWithLocales: existingItem,
|
|
82
99
|
fields: field.fields,
|
|
83
|
-
|
|
84
|
-
|
|
100
|
+
localesToPreserve,
|
|
101
|
+
localesToUpdate,
|
|
102
|
+
parentIsLocalized
|
|
85
103
|
});
|
|
86
104
|
});
|
|
87
105
|
}
|
|
@@ -96,10 +114,8 @@ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/
|
|
|
96
114
|
if (fieldIsLocalized) {
|
|
97
115
|
// If localized, handle locale keys
|
|
98
116
|
if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {
|
|
99
|
-
const updatedData =
|
|
100
|
-
|
|
101
|
-
};
|
|
102
|
-
for (const locale of selectedLocales){
|
|
117
|
+
const updatedData = filterPreservedData(existingValue, localesToPreserve);
|
|
118
|
+
for (const locale of localesToUpdate){
|
|
103
119
|
if (locale in newValue) {
|
|
104
120
|
updatedData[locale] = newValue[locale];
|
|
105
121
|
}
|
|
@@ -124,8 +140,9 @@ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/
|
|
|
124
140
|
dataWithLocales: newBlockData,
|
|
125
141
|
docWithLocales: blockData,
|
|
126
142
|
fields: block?.fields || [],
|
|
127
|
-
|
|
128
|
-
|
|
143
|
+
localesToPreserve,
|
|
144
|
+
localesToUpdate,
|
|
145
|
+
parentIsLocalized
|
|
129
146
|
});
|
|
130
147
|
// blockType, id, blockName are set by Payload internally
|
|
131
148
|
// and not part of block.fields, so they must be preserved explicitly
|
|
@@ -149,10 +166,8 @@ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/
|
|
|
149
166
|
const existingValue = docWithLocales[field.name];
|
|
150
167
|
if (fieldIsLocalized) {
|
|
151
168
|
if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {
|
|
152
|
-
const groupData =
|
|
153
|
-
|
|
154
|
-
};
|
|
155
|
-
for (const locale of selectedLocales){
|
|
169
|
+
const groupData = filterPreservedData(existingValue, localesToPreserve);
|
|
170
|
+
for (const locale of localesToUpdate){
|
|
156
171
|
if (locale in newValue && typeof newValue[locale] === 'object') {
|
|
157
172
|
groupData[locale] = newValue[locale];
|
|
158
173
|
}
|
|
@@ -169,8 +184,9 @@ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/
|
|
|
169
184
|
dataWithLocales: newValue,
|
|
170
185
|
docWithLocales: existingValue || {},
|
|
171
186
|
fields: field.fields,
|
|
172
|
-
|
|
173
|
-
|
|
187
|
+
localesToPreserve,
|
|
188
|
+
localesToUpdate,
|
|
189
|
+
parentIsLocalized
|
|
174
190
|
});
|
|
175
191
|
}
|
|
176
192
|
}
|
|
@@ -186,10 +202,8 @@ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/
|
|
|
186
202
|
const existingValue = docWithLocales[field.name] || {};
|
|
187
203
|
// If localized, handle locale keys
|
|
188
204
|
if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {
|
|
189
|
-
const merged =
|
|
190
|
-
|
|
191
|
-
};
|
|
192
|
-
for (const locale of selectedLocales){
|
|
205
|
+
const merged = filterPreservedData(existingValue, localesToPreserve);
|
|
206
|
+
for (const locale of localesToUpdate){
|
|
193
207
|
if (locale in newValue) {
|
|
194
208
|
merged[locale] = newValue[locale];
|
|
195
209
|
}
|
|
@@ -224,8 +238,9 @@ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/
|
|
|
224
238
|
dataWithLocales,
|
|
225
239
|
docWithLocales,
|
|
226
240
|
fields: field.fields,
|
|
227
|
-
|
|
228
|
-
|
|
241
|
+
localesToPreserve,
|
|
242
|
+
localesToUpdate,
|
|
243
|
+
parentIsLocalized
|
|
229
244
|
});
|
|
230
245
|
// Only copy fields that belong to this layout field to avoid overwriting already-processed fields
|
|
231
246
|
const fieldNames = collectFlattenedFieldNames(field.fields);
|
|
@@ -250,10 +265,8 @@ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/
|
|
|
250
265
|
const existingValue = docWithLocales[tab.name];
|
|
251
266
|
if (tabIsLocalized) {
|
|
252
267
|
if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {
|
|
253
|
-
const merged =
|
|
254
|
-
|
|
255
|
-
};
|
|
256
|
-
for (const locale of selectedLocales){
|
|
268
|
+
const merged = filterPreservedData(existingValue, localesToPreserve);
|
|
269
|
+
for (const locale of localesToUpdate){
|
|
257
270
|
if (locale in newValue && typeof newValue[locale] === 'object') {
|
|
258
271
|
merged[locale] = newValue[locale];
|
|
259
272
|
}
|
|
@@ -270,8 +283,9 @@ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/
|
|
|
270
283
|
dataWithLocales: newValue,
|
|
271
284
|
docWithLocales: existingValue || {},
|
|
272
285
|
fields: tab.fields,
|
|
273
|
-
|
|
274
|
-
|
|
286
|
+
localesToPreserve,
|
|
287
|
+
localesToUpdate,
|
|
288
|
+
parentIsLocalized
|
|
275
289
|
});
|
|
276
290
|
}
|
|
277
291
|
}
|
|
@@ -282,8 +296,9 @@ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/
|
|
|
282
296
|
dataWithLocales,
|
|
283
297
|
docWithLocales,
|
|
284
298
|
fields: tab.fields,
|
|
285
|
-
|
|
286
|
-
|
|
299
|
+
localesToPreserve,
|
|
300
|
+
localesToUpdate,
|
|
301
|
+
parentIsLocalized
|
|
287
302
|
});
|
|
288
303
|
// Only copy fields that belong to this tab to avoid overwriting already-processed fields
|
|
289
304
|
const tabFieldNames = collectFlattenedFieldNames(tab.fields);
|
|
@@ -1 +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\n/**\n * Collects field names at the current data level, recursing through pass-through fields\n * (row, collapsible, unnamed group, unnamed tab) but stopping at named fields.\n */\nfunction collectFlattenedFieldNames(fields: Field[]): Set<string> {\n const names = new Set<string>()\n for (const field of fields) {\n if (fieldAffectsData(field)) {\n names.add(field.name)\n } else if ('fields' in field && Array.isArray(field.fields)) {\n // Pass-through fields (row, collapsible, unnamed group)\n for (const name of collectFlattenedFieldNames(field.fields)) {\n names.add(name)\n }\n } else if (field.type === 'tabs') {\n for (const tab of field.tabs) {\n if (tabHasName(tab)) {\n names.add(tab.name)\n } else {\n for (const name of collectFlattenedFieldNames(tab.fields)) {\n names.add(name)\n }\n }\n }\n }\n }\n return names\n}\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 const blockOrSlug = field.blocks.find((b) => {\n const slug = typeof b === 'string' ? b : b.slug\n return slug === newBlockData.blockType\n })\n const block: Block | FlattenedBlock | undefined =\n typeof blockOrSlug === 'string'\n ? configBlockReferences?.find((b) => b.slug === blockOrSlug)\n : blockOrSlug\n\n if (block) {\n const blockData =\n Array.isArray(existingValue) && existingValue[index]\n ? (existingValue[index] as JsonObject)\n : {}\n\n const merged = mergeLocalizedData({\n configBlockReferences,\n dataWithLocales: newBlockData,\n docWithLocales: blockData,\n fields: block?.fields || [],\n parentIsLocalized,\n selectedLocales,\n })\n\n // blockType, id, blockName are set by Payload internally\n // and not part of block.fields, so they must be preserved explicitly\n merged.blockType = newBlockData.blockType\n merged.id = newBlockData.id\n merged.blockName = newBlockData.blockName\n\n return merged\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 }\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 'group':\n case 'row': {\n // These pass through the same data level\n const merged = mergeLocalizedData({\n configBlockReferences,\n dataWithLocales,\n docWithLocales,\n fields: field.fields,\n parentIsLocalized,\n selectedLocales,\n })\n // Only copy fields that belong to this layout field to avoid overwriting already-processed fields\n const fieldNames = collectFlattenedFieldNames(field.fields)\n for (const name of fieldNames) {\n if (name in merged) {\n result[name] = merged[name]\n }\n }\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,\n fields: tab.fields,\n parentIsLocalized,\n selectedLocales,\n })\n // Only copy fields that belong to this tab to avoid overwriting already-processed fields\n const tabFieldNames = collectFlattenedFieldNames(tab.fields)\n for (const name of tabFieldNames) {\n if (name in merged) {\n result[name] = merged[name]\n }\n }\n }\n }\n break\n }\n }\n }\n }\n\n return result\n}\n"],"names":["fieldAffectsData","fieldShouldBeLocalized","tabHasName","collectFlattenedFieldNames","fields","names","Set","field","add","name","Array","isArray","type","tab","tabs","mergeLocalizedData","configBlockReferences","dataWithLocales","docWithLocales","parentIsLocalized","selectedLocales","result","fieldIsLocalized","newValue","existingValue","updatedArray","locale","map","newItem","index","existingItem","updatedData","newBlockData","blockOrSlug","blocks","find","b","slug","blockType","block","blockData","merged","id","blockName","groupData","fieldNames","tabIsLocalized","tabFieldNames"],"mappings":"AAIA,SAASA,gBAAgB,EAAEC,sBAAsB,EAAEC,UAAU,QAAQ,4BAA2B;AAEhG;;;CAGC,GACD,SAASC,2BAA2BC,MAAe;IACjD,MAAMC,QAAQ,IAAIC;IAClB,KAAK,MAAMC,SAASH,OAAQ;QAC1B,IAAIJ,iBAAiBO,QAAQ;YAC3BF,MAAMG,GAAG,CAACD,MAAME,IAAI;QACtB,OAAO,IAAI,YAAYF,SAASG,MAAMC,OAAO,CAACJ,MAAMH,MAAM,GAAG;YAC3D,wDAAwD;YACxD,KAAK,MAAMK,QAAQN,2BAA2BI,MAAMH,MAAM,EAAG;gBAC3DC,MAAMG,GAAG,CAACC;YACZ;QACF,OAAO,IAAIF,MAAMK,IAAI,KAAK,QAAQ;YAChC,KAAK,MAAMC,OAAON,MAAMO,IAAI,CAAE;gBAC5B,IAAIZ,WAAWW,MAAM;oBACnBR,MAAMG,GAAG,CAACK,IAAIJ,IAAI;gBACpB,OAAO;oBACL,KAAK,MAAMA,QAAQN,2BAA2BU,IAAIT,MAAM,EAAG;wBACzDC,MAAMG,GAAG,CAACC;oBACZ;gBACF;YACF;QACF;IACF;IACA,OAAOJ;AACT;AAWA;;;;;CAKC,GACD,OAAO,SAASU,mBAAmB,EACjCC,qBAAqB,EACrBC,eAAe,EACfC,cAAc,EACdd,MAAM,EACNe,oBAAoB,KAAK,EACzBC,eAAe,EACgB;IAC/B,IAAI,CAACF,kBAAkB,OAAOA,mBAAmB,UAAU;QACzD,OAAOD,mBAAmBC;IAC5B;IAEA,MAAMG,SAAqB;QAAE,GAAGH,cAAc;IAAC;IAE/C,KAAK,MAAMX,SAASH,OAAQ;QAC1B,IAAIJ,iBAAiBO,QAAQ;YAC3B,sEAAsE;YACtE,IAAIY,qBAAqBF,eAAe,CAACV,MAAME,IAAI,CAAC,EAAE;gBACpDY,MAAM,CAACd,MAAME,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T,MAAM;oCAClBe;oCACAC;gCACF;gCACA,yFAAyF;gCACzF,MAAM2B,gBAAgB5C,2BAA2BU,IAAIT,MAAM;gCAC3D,KAAK,MAAMK,QAAQsC,cAAe;oCAChC,IAAItC,QAAQgC,QAAQ;wCAClBpB,MAAM,CAACZ,KAAK,GAAGgC,MAAM,CAAChC,KAAK;oCAC7B;gCACF;4BACF;wBACF;wBACA;oBACF;YACF;QACF;IACF;IAEA,OAAOY;AACT"}
|
|
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\n/**\n * Collects field names at the current data level, recursing through pass-through fields\n * (row, collapsible, unnamed group, unnamed tab) but stopping at named fields.\n */\nfunction collectFlattenedFieldNames(fields: Field[]): Set<string> {\n const names = new Set<string>()\n for (const field of fields) {\n if (fieldAffectsData(field)) {\n names.add(field.name)\n } else if ('fields' in field && Array.isArray(field.fields)) {\n // Pass-through fields (row, collapsible, unnamed group)\n for (const name of collectFlattenedFieldNames(field.fields)) {\n names.add(name)\n }\n } else if (field.type === 'tabs') {\n for (const tab of field.tabs) {\n if (tabHasName(tab)) {\n names.add(tab.name)\n } else {\n for (const name of collectFlattenedFieldNames(tab.fields)) {\n names.add(name)\n }\n }\n }\n }\n }\n return names\n}\n\n/**\n * Returns a copy of `existingValue` (a locale-keyed object) keeping only locales\n * that are in `localesToPreserve` (when provided) or all locales (when not provided).\n */\nfunction filterPreservedData(\n existingValue: unknown,\n localesToPreserve: string[] | undefined,\n): Record<string, unknown> {\n const existing = existingValue && typeof existingValue === 'object' ? existingValue : {}\n if (!localesToPreserve) {\n return { ...(existing as Record<string, unknown>) }\n }\n const out: Record<string, unknown> = {}\n for (const lc of localesToPreserve) {\n if (lc in (existing as Record<string, unknown>)) {\n out[lc] = (existing as Record<string, unknown>)[lc]\n }\n }\n return out\n}\n\ntype MergeLocalizedDataArgs = {\n configBlockReferences: SanitizedConfig['blocks']\n dataWithLocales: JsonObject\n docWithLocales: JsonObject\n fields: Field[]\n /**\n * Which locales from `docWithLocales` to retain in the output.\n * When omitted, all locales in `docWithLocales` are preserved (default behaviour).\n * Pass an explicit list (e.g. the currently-published locales) to discard locales\n * that should not be carried forward — for example, when publishing a single locale\n * you want to avoid leaking draft data that was written to the main doc by an earlier\n * create/update with `draft: true`.\n */\n localesToPreserve?: string[]\n localesToUpdate: string[]\n parentIsLocalized?: boolean\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 * (or only `localesToPreserve` if supplied).\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 localesToPreserve,\n localesToUpdate,\n parentIsLocalized = false,\n}: MergeLocalizedDataArgs): 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 = filterPreservedData(existingValue, localesToPreserve)\n\n for (const locale of localesToUpdate) {\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 localesToPreserve,\n localesToUpdate,\n parentIsLocalized,\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 = filterPreservedData(existingValue, localesToPreserve)\n\n for (const locale of localesToUpdate) {\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 const blockOrSlug = field.blocks.find((b) => {\n const slug = typeof b === 'string' ? b : b.slug\n return slug === newBlockData.blockType\n })\n const block: Block | FlattenedBlock | undefined =\n typeof blockOrSlug === 'string'\n ? configBlockReferences?.find((b) => b.slug === blockOrSlug)\n : blockOrSlug\n\n if (block) {\n const blockData =\n Array.isArray(existingValue) && existingValue[index]\n ? (existingValue[index] as JsonObject)\n : {}\n\n const merged = mergeLocalizedData({\n configBlockReferences,\n dataWithLocales: newBlockData,\n docWithLocales: blockData,\n fields: block?.fields || [],\n localesToPreserve,\n localesToUpdate,\n parentIsLocalized,\n })\n\n // blockType, id, blockName are set by Payload internally\n // and not part of block.fields, so they must be preserved explicitly\n merged.blockType = newBlockData.blockType\n merged.id = newBlockData.id\n merged.blockName = newBlockData.blockName\n\n return merged\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 = filterPreservedData(existingValue, localesToPreserve)\n\n for (const locale of localesToUpdate) {\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 localesToPreserve,\n localesToUpdate,\n parentIsLocalized,\n })\n }\n }\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 = filterPreservedData(existingValue, localesToPreserve)\n\n for (const locale of localesToUpdate) {\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 'group':\n case 'row': {\n // These pass through the same data level\n const merged = mergeLocalizedData({\n configBlockReferences,\n dataWithLocales,\n docWithLocales,\n fields: field.fields,\n localesToPreserve,\n localesToUpdate,\n parentIsLocalized,\n })\n // Only copy fields that belong to this layout field to avoid overwriting already-processed fields\n const fieldNames = collectFlattenedFieldNames(field.fields)\n for (const name of fieldNames) {\n if (name in merged) {\n result[name] = merged[name]\n }\n }\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 = filterPreservedData(existingValue, localesToPreserve)\n\n for (const locale of localesToUpdate) {\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 localesToPreserve,\n localesToUpdate,\n parentIsLocalized,\n })\n }\n }\n } else {\n // Unnamed tabs pass through the same data level\n const merged = mergeLocalizedData({\n configBlockReferences,\n dataWithLocales,\n docWithLocales,\n fields: tab.fields,\n localesToPreserve,\n localesToUpdate,\n parentIsLocalized,\n })\n // Only copy fields that belong to this tab to avoid overwriting already-processed fields\n const tabFieldNames = collectFlattenedFieldNames(tab.fields)\n for (const name of tabFieldNames) {\n if (name in merged) {\n result[name] = merged[name]\n }\n }\n }\n }\n break\n }\n }\n }\n }\n\n return result\n}\n"],"names":["fieldAffectsData","fieldShouldBeLocalized","tabHasName","collectFlattenedFieldNames","fields","names","Set","field","add","name","Array","isArray","type","tab","tabs","filterPreservedData","existingValue","localesToPreserve","existing","out","lc","mergeLocalizedData","configBlockReferences","dataWithLocales","docWithLocales","localesToUpdate","parentIsLocalized","result","fieldIsLocalized","newValue","updatedArray","locale","map","newItem","index","existingItem","updatedData","newBlockData","blockOrSlug","blocks","find","b","slug","blockType","block","blockData","merged","id","blockName","groupData","fieldNames","tabIsLocalized","tabFieldNames"],"mappings":"AAIA,SAASA,gBAAgB,EAAEC,sBAAsB,EAAEC,UAAU,QAAQ,4BAA2B;AAEhG;;;CAGC,GACD,SAASC,2BAA2BC,MAAe;IACjD,MAAMC,QAAQ,IAAIC;IAClB,KAAK,MAAMC,SAASH,OAAQ;QAC1B,IAAIJ,iBAAiBO,QAAQ;YAC3BF,MAAMG,GAAG,CAACD,MAAME,IAAI;QACtB,OAAO,IAAI,YAAYF,SAASG,MAAMC,OAAO,CAACJ,MAAMH,MAAM,GAAG;YAC3D,wDAAwD;YACxD,KAAK,MAAMK,QAAQN,2BAA2BI,MAAMH,MAAM,EAAG;gBAC3DC,MAAMG,GAAG,CAACC;YACZ;QACF,OAAO,IAAIF,MAAMK,IAAI,KAAK,QAAQ;YAChC,KAAK,MAAMC,OAAON,MAAMO,IAAI,CAAE;gBAC5B,IAAIZ,WAAWW,MAAM;oBACnBR,MAAMG,GAAG,CAACK,IAAIJ,IAAI;gBACpB,OAAO;oBACL,KAAK,MAAMA,QAAQN,2BAA2BU,IAAIT,MAAM,EAAG;wBACzDC,MAAMG,GAAG,CAACC;oBACZ;gBACF;YACF;QACF;IACF;IACA,OAAOJ;AACT;AAEA;;;CAGC,GACD,SAASU,oBACPC,aAAsB,EACtBC,iBAAuC;IAEvC,MAAMC,WAAWF,iBAAiB,OAAOA,kBAAkB,WAAWA,gBAAgB,CAAC;IACvF,IAAI,CAACC,mBAAmB;QACtB,OAAO;YAAE,GAAIC,QAAQ;QAA6B;IACpD;IACA,MAAMC,MAA+B,CAAC;IACtC,KAAK,MAAMC,MAAMH,kBAAmB;QAClC,IAAIG,MAAOF,UAAsC;YAC/CC,GAAG,CAACC,GAAG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EAJ,MAAM,CAACd,IAAIJ,IAAI,CAAC,GAAGqC;wCACrB,OAAO;4CACL,6DAA6D;4CAC7DnB,MAAM,CAACd,IAAIJ,IAAI,CAAC,GAAGO;wCACrB;oCACF,OAAO,IAAI,OAAOa,aAAa,YAAY,CAACnB,MAAMC,OAAO,CAACkB,WAAW;wCACnE,sEAAsE;wCACtEF,MAAM,CAACd,IAAIJ,IAAI,CAAC,GAAGY,mBAAmB;4CACpCC;4CACAC,iBAAiBM;4CACjBL,gBAAgBR,iBAAiB,CAAC;4CAClCZ,QAAQS,IAAIT,MAAM;4CAClBa;4CACAQ;4CACAC;wCACF;oCACF;gCACF;4BACF,OAAO;gCACL,gDAAgD;gCAChD,MAAMoB,SAASzB,mBAAmB;oCAChCC;oCACAC;oCACAC;oCACApB,QAAQS,IAAIT,MAAM;oCAClBa;oCACAQ;oCACAC;gCACF;gCACA,yFAAyF;gCACzF,MAAM0B,gBAAgBjD,2BAA2BU,IAAIT,MAAM;gCAC3D,KAAK,MAAMK,QAAQ2C,cAAe;oCAChC,IAAI3C,QAAQqC,QAAQ;wCAClBnB,MAAM,CAAClB,KAAK,GAAGqC,MAAM,CAACrC,KAAK;oCAC7B;gCACF;4BACF;wBACF;wBACA;oBACF;YACF;QACF;IACF;IAEA,OAAOkB;AACT"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { mergeLocalizedData } from './mergeLocalizedData.js';
|
|
3
3
|
describe('mergeLocalizedData', ()=>{
|
|
4
|
-
const
|
|
4
|
+
const localesToUpdate = [
|
|
5
5
|
'en'
|
|
6
6
|
];
|
|
7
7
|
const configBlockReferences = [];
|
|
@@ -32,7 +32,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
32
32
|
dataWithLocales,
|
|
33
33
|
docWithLocales,
|
|
34
34
|
fields,
|
|
35
|
-
|
|
35
|
+
localesToUpdate
|
|
36
36
|
});
|
|
37
37
|
expect(result.title).toEqual({
|
|
38
38
|
en: 'Updated English Title',
|
|
@@ -57,7 +57,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
57
57
|
title: 'Old Title'
|
|
58
58
|
},
|
|
59
59
|
fields,
|
|
60
|
-
|
|
60
|
+
localesToUpdate
|
|
61
61
|
});
|
|
62
62
|
expect(result.title).toBe('New Title');
|
|
63
63
|
const missingData = mergeLocalizedData({
|
|
@@ -67,7 +67,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
67
67
|
title: 'Old Title'
|
|
68
68
|
},
|
|
69
69
|
fields,
|
|
70
|
-
|
|
70
|
+
localesToUpdate
|
|
71
71
|
});
|
|
72
72
|
expect(missingData.title).toBe('Old Title');
|
|
73
73
|
const updatedData = mergeLocalizedData({
|
|
@@ -77,7 +77,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
77
77
|
},
|
|
78
78
|
docWithLocales: {},
|
|
79
79
|
fields,
|
|
80
|
-
|
|
80
|
+
localesToUpdate
|
|
81
81
|
});
|
|
82
82
|
expect(updatedData.title).toBe('Updated Title');
|
|
83
83
|
});
|
|
@@ -126,7 +126,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
126
126
|
dataWithLocales,
|
|
127
127
|
docWithLocales,
|
|
128
128
|
fields,
|
|
129
|
-
|
|
129
|
+
localesToUpdate
|
|
130
130
|
});
|
|
131
131
|
expect(result.meta).toEqual({
|
|
132
132
|
en: {
|
|
@@ -181,7 +181,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
181
181
|
dataWithLocales,
|
|
182
182
|
docWithLocales,
|
|
183
183
|
fields,
|
|
184
|
-
|
|
184
|
+
localesToUpdate
|
|
185
185
|
});
|
|
186
186
|
expect(result.meta).toEqual({
|
|
187
187
|
title: {
|
|
@@ -241,7 +241,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
241
241
|
dataWithLocales,
|
|
242
242
|
docWithLocales,
|
|
243
243
|
fields,
|
|
244
|
-
|
|
244
|
+
localesToUpdate
|
|
245
245
|
});
|
|
246
246
|
expect(result.items).toEqual({
|
|
247
247
|
en: [
|
|
@@ -309,7 +309,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
309
309
|
dataWithLocales,
|
|
310
310
|
docWithLocales,
|
|
311
311
|
fields,
|
|
312
|
-
|
|
312
|
+
localesToUpdate
|
|
313
313
|
});
|
|
314
314
|
expect(result.items).toEqual([
|
|
315
315
|
{
|
|
@@ -378,7 +378,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
378
378
|
dataWithLocales,
|
|
379
379
|
docWithLocales,
|
|
380
380
|
fields,
|
|
381
|
-
|
|
381
|
+
localesToUpdate
|
|
382
382
|
});
|
|
383
383
|
expect(result.content).toEqual({
|
|
384
384
|
en: [
|
|
@@ -463,7 +463,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
463
463
|
dataWithLocales,
|
|
464
464
|
docWithLocales,
|
|
465
465
|
fields,
|
|
466
|
-
|
|
466
|
+
localesToUpdate
|
|
467
467
|
});
|
|
468
468
|
expect(result.content).toEqual({
|
|
469
469
|
en: [
|
|
@@ -530,7 +530,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
530
530
|
dataWithLocales,
|
|
531
531
|
docWithLocales,
|
|
532
532
|
fields,
|
|
533
|
-
|
|
533
|
+
localesToUpdate
|
|
534
534
|
});
|
|
535
535
|
expect(result.meta).toEqual({
|
|
536
536
|
en: {
|
|
@@ -575,7 +575,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
575
575
|
dataWithLocales,
|
|
576
576
|
docWithLocales,
|
|
577
577
|
fields,
|
|
578
|
-
|
|
578
|
+
localesToUpdate
|
|
579
579
|
});
|
|
580
580
|
expect(result.title).toEqual({
|
|
581
581
|
en: 'Updated EN Title',
|
|
@@ -653,7 +653,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
653
653
|
dataWithLocales,
|
|
654
654
|
docWithLocales,
|
|
655
655
|
fields,
|
|
656
|
-
|
|
656
|
+
localesToUpdate
|
|
657
657
|
});
|
|
658
658
|
expect(result.outer).toEqual({
|
|
659
659
|
en: {
|
|
@@ -705,7 +705,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
705
705
|
dataWithLocales,
|
|
706
706
|
docWithLocales,
|
|
707
707
|
fields,
|
|
708
|
-
|
|
708
|
+
localesToUpdate: [
|
|
709
709
|
'en',
|
|
710
710
|
'es'
|
|
711
711
|
]
|
|
@@ -765,7 +765,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
765
765
|
dataWithLocales,
|
|
766
766
|
docWithLocales,
|
|
767
767
|
fields,
|
|
768
|
-
|
|
768
|
+
localesToUpdate: [
|
|
769
769
|
'es'
|
|
770
770
|
]
|
|
771
771
|
});
|
|
@@ -835,7 +835,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
835
835
|
dataWithLocales,
|
|
836
836
|
docWithLocales,
|
|
837
837
|
fields,
|
|
838
|
-
|
|
838
|
+
localesToUpdate: [
|
|
839
839
|
'en'
|
|
840
840
|
]
|
|
841
841
|
});
|
|
@@ -884,7 +884,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
884
884
|
dataWithLocales,
|
|
885
885
|
docWithLocales,
|
|
886
886
|
fields,
|
|
887
|
-
|
|
887
|
+
localesToUpdate: [
|
|
888
888
|
'en'
|
|
889
889
|
]
|
|
890
890
|
});
|
|
@@ -929,7 +929,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
929
929
|
dataWithLocales,
|
|
930
930
|
docWithLocales,
|
|
931
931
|
fields,
|
|
932
|
-
|
|
932
|
+
localesToUpdate: [
|
|
933
933
|
'en'
|
|
934
934
|
]
|
|
935
935
|
});
|
|
@@ -943,7 +943,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
943
943
|
describe('block metadata preservation', ()=>{
|
|
944
944
|
it('should preserve blockType, id, and blockName when existing doc has no blocks', ()=>{
|
|
945
945
|
// Reproduces the bug where autosave creates a doc without blocks,
|
|
946
|
-
// then blocks are added and
|
|
946
|
+
// then blocks are added and publishing a specific locale drops metadata
|
|
947
947
|
const fields = [
|
|
948
948
|
{
|
|
949
949
|
name: 'layout',
|
|
@@ -981,7 +981,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
981
981
|
dataWithLocales,
|
|
982
982
|
docWithLocales,
|
|
983
983
|
fields,
|
|
984
|
-
|
|
984
|
+
localesToUpdate: [
|
|
985
985
|
'en'
|
|
986
986
|
]
|
|
987
987
|
});
|
|
@@ -1030,7 +1030,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
1030
1030
|
dataWithLocales,
|
|
1031
1031
|
docWithLocales,
|
|
1032
1032
|
fields,
|
|
1033
|
-
|
|
1033
|
+
localesToUpdate: [
|
|
1034
1034
|
'en'
|
|
1035
1035
|
]
|
|
1036
1036
|
});
|
|
@@ -1090,7 +1090,7 @@ describe('mergeLocalizedData', ()=>{
|
|
|
1090
1090
|
dataWithLocales,
|
|
1091
1091
|
docWithLocales,
|
|
1092
1092
|
fields,
|
|
1093
|
-
|
|
1093
|
+
localesToUpdate: [
|
|
1094
1094
|
'en'
|
|
1095
1095
|
]
|
|
1096
1096
|
});
|