import { EditorState, PluginView, Transaction } from "prosemirror-state"; import { EditorView } from "prosemirror-view"; import { StatefulPlugin, StatefulPluginKey } from "./plugin-extensions"; /** * The required state properties for a plugin that provides an interface */ interface ManagedInterfaceState { /** Whether the plugin's interface should be showing */ shouldShow: boolean; } /** The state of the interface manager meta-plugin */ interface InterfaceManagerState { dom: HTMLElement; /** The currently shown interface or null if no interface is shown */ currentlyShown: ManagedInterfaceKey | null; /** Getter to fetch the plugin container from the view's DOM */ containerGetter: (view: EditorView) => Element; } /** The data properties that can be passed into show/hideInterface for state overriding */ type InterfaceData = Partial>; /** * Public PluginKey implementation for plugins that want to expose an interface. * Contains helper methods for showing/hiding the interface that ensure that the manager * handles the state changes across all interface-enabled plugins. */ export declare class ManagedInterfaceKey extends StatefulPluginKey { readonly name: string; constructor(name: string); /** * Gets the container element that the plugin's interface should be rendered into * @param view The current editor view */ getContainer(view: EditorView): Element; /** * Shows the interface for this plugin, optionally overriding the metadata passed to the transaction * @param view The current editor view * @param data Optional data to attach to the transaction's metadata * @returns True if the interface was shown, false if there was no state change */ showInterfaceTr(state: EditorState, data?: InterfaceData): Transaction; /** * Hides the interface for this plugin, optionally overriding the metadata passed to the transaction * @param view The current editor view * @param data Optional data to attach to the transaction's metadata * @returns True if the interface was hidden, false if there was no state change */ hideInterfaceTr(state: EditorState, data?: InterfaceData): Transaction; } /** * Main plugin for coordinating the use of the interface container for all interface-enabled plugins. * This plugin is *required* for any interface-enabled plugin to work. This plugin also adds a listener to hide the interface * if the ESC key is pressed or if the text editor gains focus. * @param containerGetter The method for getting the container element for the interface; falls back to the editor view's DOM's parentElement if not provided */ export declare function interfaceManagerPlugin(containerGetter: InterfaceManagerState["containerGetter"]): StatefulPlugin; /** * PluginView that ensures that the build/destroyInterface methods are called only at the appropriate times. * **WARNING**: The plugin that uses this must also ensure that it forwards the `shouldShow` value from any * apply transaction's metadata to the plugin's state. Failing to do so will result in the interface never being shown. */ export declare abstract class PluginInterfaceView> implements PluginView { protected key: TKey; protected isShown: boolean; constructor(key: TKey); /** * Method that is called when the plugin's interface is shown. * This should append any DOM elements that should be shown to the user. * @param container The element to render the interface into */ abstract buildInterface(container: Element): void; /** * Method that is called when the plugin's interface is hidden. * Typically, this should completely clear out the container's contents that were added in buildInterface * and clean up any other resources such as events that were attached to document. * @param container The element the interface was rendered into */ abstract destroyInterface(container: Element): void; /** * Pre-implemented update override that ensures that the interface is shown/hidden appropriately. * If you need to do additional work, you should override this method, making sure to call `super.update(view)` * in the overridden method _after_ the additional setup has been done. * @param view The current editor view */ update(view: EditorView): void; /** Helper wrapper around this key's @see {@link ManagedInterfaceKey.showInterface} */ protected tryShowInterfaceTr(state: EditorState, data?: InterfaceData): Transaction; /** Helper wrapper around this key's @see {@link ManagedInterfaceKey.hideInterface} */ protected tryHideInterfaceTr(state: EditorState, data?: InterfaceData): Transaction; } export {};