/** * This Source Code is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright (c) Infonomic Company Limited */ /** * Copy-to-Locale merge walker. * * Schema-aware, pure tree merge used by `copyToLocale` to decide, leaf by * leaf, whether to take the source locale's value or keep the target's. */ import { type FieldSet } from '../../@types/index.js'; /** * Result of merging source-locale and target-locale data trees for * `copyToLocale`. `data` is the payload to hand to * `createDocumentVersion`; `fieldsUpdated` counts every localized leaf * the merge rule chose to overwrite (used for UI toasts). */ export interface CopyToLocaleMergeResult { data: Record; fieldsUpdated: number; } /** * Build the payload `copyToLocale` will write into the target locale. * * Walks `definition.fields` and the two reconstructed data trees in * lockstep, applying the merge rule at every leaf: * * - **Localized leaf, `overwrite: true`** — take source's value (even * when source is empty; overwriting means overwriting). * - **Localized leaf, `overwrite: false`** — take source's value only * when target is empty AND source is non-empty. Otherwise keep * target's value. Empties under this rule are treated by * `isEmptyLeafValue` — `null` / `undefined` / `''`. * - **Non-localized leaf** — always keep target's value. Non-localized * fields live on `locale: 'all'` rows in storage and would be wiped * by the upcoming write if we did not pass them through verbatim. * * Structure (number of array items, blocks, etc.) follows the *target* * tree — copy-to-locale never restructures the document; it only fills * in localized leaves at positions the target already has. * * Pure: mutates nothing. The returned `data` is a fresh tree suitable * to pass to `createDocumentVersion`. */ export declare function mergeLocaleData(fields: FieldSet, sourceData: Record | null | undefined, targetData: Record | null | undefined, overwrite: boolean): CopyToLocaleMergeResult;