"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.TreeBeta = void 0;
const index_js_1 = require("../../feature-libraries/index.js");
const index_js_2 = require("../../util/index.js");
const index_js_3 = require("../core/index.js");
const createContext_js_1 = require("../createContext.js");
const create_js_1 = require("./create.js");
const treeNodeApi_js_1 = require("./treeNodeApi.js");
/**
 * Extensions to {@link (Tree:variable)} which are not yet stable.
 * @see {@link (TreeBeta:interface)}.
 * @beta
 */
exports.TreeBeta = {
    on(node, eventName, listener) {
        return treeNodeApi_js_1.treeNodeApi.on(node, eventName, listener);
    },
    clone(node) {
        // The only non-TreeNode cases are {@link TreeLeafValue} and `undefined` (for an empty optional field) which can be returned as is.
        if (!(0, index_js_3.isTreeNode)(node)) {
            return node;
        }
        const kernel = (0, index_js_3.getKernel)(node);
        const cursor = kernel.getOrCreateInnerNode().borrowCursor();
        // To handle when the node transitively contains unknown optional fields,
        // derive the context from the source node's stored schema which has stored schema for any such fields and their contents.
        const flexContext = new index_js_3.UnhydratedContext(index_js_1.defaultSchemaPolicy, kernel.context.flexContext.schema);
        const context = new index_js_3.Context(flexContext, (0, createContext_js_1.getUnhydratedContext)(kernel.schema).schema);
        const fieldSchema = {
            kind: index_js_1.FieldKinds.required.identifier,
            types: new Set([(0, index_js_2.brand)(kernel.schema.identifier)]),
            persistedMetadata: undefined,
        };
        return (0, create_js_1.createFromCursor)(kernel.schema, cursor, fieldSchema, context);
    },
};
//# sourceMappingURL=treeBeta.js.map