"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.MappedEditBuilder = void 0;
/**
 * An IDefaultEditBuilder implementation based on another IDefaultEditBuilder that uses a different content type for insertions.
 */
class MappedEditBuilder {
    constructor(baseBuilder, mapDelegate) {
        this.baseBuilder = baseBuilder;
        this.mapDelegate = mapDelegate;
    }
    buildRoots(content) {
        return this.baseBuilder.buildRoots(this.mapDelegate(content));
    }
    valueField(field) {
        const baseField = this.baseBuilder.valueField(field);
        return {
            set: (newContent) => {
                const mappedContent = this.mapDelegate(newContent);
                baseField.set(mappedContent);
            },
            attach: (content) => {
                baseField.attach(content);
            },
        };
    }
    optionalField(field) {
        const baseField = this.baseBuilder.optionalField(field);
        return {
            set: (newContent, wasEmpty) => {
                const mappedContent = newContent === undefined ? undefined : this.mapDelegate(newContent);
                baseField.set(mappedContent, wasEmpty);
            },
            attach: (content, wasEmpty) => {
                baseField.attach(content, wasEmpty);
            },
            clear(wasEmpty) {
                baseField.clear(wasEmpty);
            },
        };
    }
    sequenceField(field) {
        const baseField = this.baseBuilder.sequenceField(field);
        return {
            insert: (index, content) => {
                const mappedContent = this.mapDelegate(content);
                baseField.insert(index, mappedContent);
            },
            remove: (index, count) => {
                baseField.remove(index, count);
            },
            attach: (index, detachedContent) => {
                baseField.attach(index, detachedContent);
            },
        };
    }
    move(sourceField, sourceIndex, count, destinationField, destinationIndex) {
        this.baseBuilder.move(sourceField, sourceIndex, count, destinationField, destinationIndex);
    }
    addNodeExistsConstraint(path) {
        this.baseBuilder.addNodeExistsConstraint(path);
    }
    addNodeExistsConstraintOnRevert(path) {
        this.baseBuilder.addNodeExistsConstraintOnRevert(path);
    }
}
exports.MappedEditBuilder = MappedEditBuilder;
//# sourceMappingURL=mappedEditBuilder.js.map