/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { type FieldKey, type ForestEvents, type TreeFieldStoredSchema } from "../../core/index.js";
import type { Listenable } from "../../events/index.js";
import { type IDisposable, disposeSymbol } from "../../util/index.js";
import type { FieldGenerator } from "../fieldGenerator.js";
import type { NodeKeyManager } from "../node-key/index.js";
import type { FlexTreeSchema } from "../typed-schema/index.js";
import type { FlexTreeField } from "./flexTreeTypes.js";
import { type LazyEntity } from "./lazyEntity.js";
import type { ITreeCheckout } from "../../shared-tree/index.js";
/**
 * A common context of a "forest" of FlexTrees.
 * It handles group operations like transforming cursors into anchors for edits.
 * @internal
 */
export interface FlexTreeContext extends Listenable<ForestEvents> {
    /**
     * Gets the root field of the tree.
     */
    get root(): FlexTreeField;
    /**
     * Schema used within this context.
     * All data must conform to these schema.
     */
    readonly schema: FlexTreeSchema;
    readonly nodeKeyManager: NodeKeyManager;
    /**
     * The checkout object associated with this context.
     */
    readonly checkout: ITreeCheckout;
}
/**
 * Creating multiple flex tree contexts for the same branch, and thus with the same underlying AnchorSet does not work due to how TreeNode caching works.
 * This slot is used to detect if one already exists and error if creating a second.
 *
 * TODO:
 * 1. API docs need to reflect this limitation or the limitation has to be removed.
 */
export declare const ContextSlot: import("../../core/index.js").AnchorSlot<Context>;
/**
 * Implementation of `FlexTreeContext`.
 *
 * @remarks An editor is required to edit the FlexTree.
 */
export declare class Context implements FlexTreeContext, IDisposable {
    readonly schema: FlexTreeSchema;
    readonly checkout: ITreeCheckout;
    readonly nodeKeyManager: NodeKeyManager;
    readonly withCursors: Set<LazyEntity>;
    readonly withAnchors: Set<LazyEntity>;
    private readonly eventUnregister;
    private disposed;
    /**
     * @param schema - Schema to use when working with the  tree.
     * @param checkout - The checkout.
     * @param nodeKeyManager - An object which handles node key generation and conversion
     */
    constructor(schema: FlexTreeSchema, checkout: ITreeCheckout, nodeKeyManager: NodeKeyManager);
    /**
     * Called before editing.
     * Clears all cursors so editing can proceed.
     */
    private prepareForEdit;
    [disposeSymbol](): void;
    /**
     * Release any cursors and anchors held by tree entities created in this context.
     * Ensures the cashed references to those entities on the Anchors are also cleared.
     * The tree entities are invalid to use after this, but the context may still be used
     * to create new trees starting from the root.
     */
    clear(): void;
    get root(): FlexTreeField;
    on<K extends keyof ForestEvents>(eventName: K, listener: ForestEvents[K]): () => void;
    /**
     * FieldSource used to get a FieldGenerator to populate required fields during procedural contextual data generation.
     */
    fieldSource?(key: FieldKey, schema: TreeFieldStoredSchema): undefined | FieldGenerator;
}
/**
 * A simple API for a Forest to interact with the tree.
 *
 * @param forest - the Forest
 * @param editor - an editor that makes changes to the forest.
 * @param nodeKeyManager - an object which handles node key generation and conversion.
 * @returns {@link FlexTreeContext} which is used to manage the cursors and anchors within the FlexTrees:
 * This is necessary for supporting using this tree across edits to the forest, and not leaking memory.
 */
export declare function getTreeContext(schema: FlexTreeSchema, checkout: ITreeCheckout, nodeKeyManager: NodeKeyManager): Context;
//# sourceMappingURL=context.d.ts.map