/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { IEditableForest, ForestEvents, FieldStoredSchema, FieldKey } from "../../core";
import { ISubscribable } from "../../events";
import { DefaultEditBuilder } from "../default-field-kinds";
import { NodeKeyManager } from "../node-key";
import { FieldGenerator } from "../contextuallyTyped";
import { TypedSchemaCollection } from "../typed-schema";
import { disposeSymbol, IDisposable } from "../../util";
import { UntypedField } from "./editableTreeTypes";
import { LazyEntity } from "./lazyEntity";
/**
 * A common context of a "forest" of EditableTrees.
 * It handles group operations like transforming cursors into anchors for edits.
 * @public
 */
export interface TreeContext extends ISubscribable<ForestEvents> {
    /**
     * Gets the root field of the tree.
     */
    get root(): UntypedField;
    /**
     * Schema used within this context.
     * All data must conform to these schema.
     */
    readonly schema: TypedSchemaCollection;
}
/**
 * Implementation of `EditableTreeContext`.
 *
 * @remarks An editor is required to edit the EditableTrees.
 */
export declare class Context implements TreeContext, IDisposable {
    readonly schema: TypedSchemaCollection;
    readonly forest: IEditableForest;
    readonly editor: DefaultEditBuilder;
    readonly nodeKeys: NodeKeyManager;
    readonly nodeKeyFieldKey?: FieldKey | undefined;
    readonly withCursors: Set<LazyEntity>;
    readonly withAnchors: Set<LazyEntity>;
    private readonly eventUnregister;
    /**
     * @param forest - the Forest
     * @param editor - an editor that makes changes to the forest.
     * @param nodeKeys - an object which handles node key generation and conversion
     * @param nodeKeyFieldKey - an optional field key under which node keys are stored in this tree.
     * If present, clients may query the {@link LocalNodeKey} of a node directly via the {@link localNodeKeySymbol}.
     */
    constructor(schema: TypedSchemaCollection, forest: IEditableForest, editor: DefaultEditBuilder, nodeKeys: NodeKeyManager, nodeKeyFieldKey?: FieldKey | undefined);
    /**
     * Called before editing.
     * Clears all cursors so editing can proceed.
     */
    private prepareForEdit;
    [disposeSymbol](): void;
    /**
     * Release any cursors and anchors held by EditableTrees created in this context.
     * The EditableTrees 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(): UntypedField;
    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: FieldStoredSchema): 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
 * @param nodeKeyFieldKey - an optional field key under which node keys are stored in this tree.
 * If present, clients may query the {@link LocalNodeKey} of a node directly via the {@link localNodeKeySymbol}.
 * @returns {@link EditableTreeContext} which is used to manage the cursors and anchors within the EditableTrees:
 * This is necessary for supporting using this tree across edits to the forest, and not leaking memory.
 */
export declare function getTreeContext(schema: TypedSchemaCollection, forest: IEditableForest, editor: DefaultEditBuilder, nodeKeyManager: NodeKeyManager, nodeKeyFieldKey?: FieldKey): TreeContext;
//# sourceMappingURL=context.d.ts.map