import MarkdownIt from "markdown-it"; import OrderedMap from "orderedmap"; import { MarkdownParser } from "prosemirror-markdown"; import type { MarkSpec, NodeSpec, Schema, SchemaSpec } from "prosemirror-model"; import type { Plugin } from "prosemirror-state"; import { EditorProps } from "prosemirror-view"; import { MarkdownSerializerMarks, MarkdownSerializerNodes } from "./markdown-serializer"; import { MenuBlock } from "./menu/helpers"; /** A more tightly scoped version of {@link SchemaSpec} so plugins can predictably update the schema */ interface PluginSchemaSpec extends SchemaSpec { nodes: OrderedMap; marks: OrderedMap; } /** * Describes the callback to extend a schema * @param schema The schema to extend * @returns The finalized, extended schema */ type AlterSchemaCallback = (schema: PluginSchemaSpec) => PluginSchemaSpec; /** * Describes the callback to extend markdown-it. * This method *mutates* the passed markdown-it instance, so it should be used with care * @param instance The markdown-it instance to alter */ type AlterMarkdownItCallback = (instance: MarkdownIt) => void; /** * Callback to add new menu entries to the editor's menu. * @param {Schema} schema The fully-initialized editor schema, including nodes from plugins * @param {MenuBlock} coreMenus Definition of the Core menus. MenuBlocks that share names are merged together. */ type AddMenuItemsCallback = (schema: Schema, coreMenus: MenuBlock[]) => MenuBlock[]; /** Describes the properties that can be used for extending commonmark support in the editor */ type MarkdownExtensionProps = { /** * Parsers for prosemirror-markdown * @see {@type import("prosemirror-markdown").MarkdownParser["tokens"]} */ parser: MarkdownParser["tokens"]; /** * Serializers for prosemirror-markdown * @see {@type import("prosemirror-markdown").MarkdownSerializer} */ serializers: { nodes: MarkdownSerializerNodes; marks: MarkdownSerializerMarks; }; }; /** * Complete spec for creating an editor plugin * @experimental */ export interface EditorPluginSpec { /** Rich-text editor extensions */ richText?: { /** * NodeViews to add to the rich-text editor * @see {@type {import("prosemirror-view").EditorProps["nodeViews"]}} */ nodeViews?: EditorProps["nodeViews"]; /** * ProseMirror plugins to add to the rich-text editor * @see {@type {import("prosemirror-state").EditorStateConfig["plugins"]}} */ plugins?: Plugin[]; }; /** Commonmark editor extensions */ commonmark?: { /** * ProseMirror plugins to add to the commonmark editor * @see {@type {import("prosemirror-state").EditorStateConfig["plugins"]}} */ plugins?: Plugin[]; }; /** {@inheritDoc AddMenuItemsCallback} */ menuItems?: AddMenuItemsCallback; /** Commonmark syntax and editor node parsing/serialization extensions */ markdown?: MarkdownExtensionProps & { alterMarkdownIt?: AlterMarkdownItCallback; }; /** Callback for extending the rich-text editor's schema */ extendSchema?: AlterSchemaCallback; } /** * A plugin that extends the editor based on the spec provided * @experimental */ export type EditorPlugin = (options: TOptions) => EditorPluginSpec; /** * Aggregates and provides plugins to consuming editors * @internal */ export interface IExternalPluginProvider { /** All aggregated plugins */ readonly plugins: { richText: Plugin[]; commonmark: Plugin[]; }; /** All aggregated markdownProps */ readonly markdownProps: MarkdownExtensionProps; /** All aggregated nodeViews */ readonly nodeViews: EditorProps["nodeViews"]; /** * Gets the final, aggregated schema * @param schema The schema to extend */ getFinalizedSchema(schema: SchemaSpec): PluginSchemaSpec; /** * Mutates the markdown-it instance to add any additional plugins * @param instance The markdown-it instance to alter */ alterMarkdownIt(instance: MarkdownIt): void; /** * Gets the final, aggregated menu * @param menu The menu to extend * @param editorType The current editor type * @param schema The finalized schema */ getFinalizedMenu(menu: MenuBlock[], schema: Schema): MenuBlock[]; } /** * {@inheritDoc IExternalPluginProvider} * @internal */ export declare class ExternalPluginProvider implements IExternalPluginProvider { private _plugins; private _markdownProps; private _nodeViews; /** {@inheritDoc IExternalPluginProvider.plugins} */ get plugins(): { richText: Plugin[]; commonmark: Plugin[]; }; /** {@inheritDoc IExternalPluginProvider.markdownProps} */ get markdownProps(): MarkdownExtensionProps; /** {@inheritDoc IExternalPluginProvider.nodeViews} */ get nodeViews(): { [node: string]: import("prosemirror-view").NodeViewConstructor; }; protected menuCallbacks: AddMenuItemsCallback[]; protected schemaCallbacks: AlterSchemaCallback[]; protected markdownItCallbacks: AlterMarkdownItCallback[]; constructor(plugins: EditorPlugin[], options: unknown); /** {@inheritDoc IExternalPluginProvider.getFinalizedSchema} */ getFinalizedSchema(schema: SchemaSpec): PluginSchemaSpec; /** {@inheritDoc IExternalPluginProvider.alterMarkdownIt} */ alterMarkdownIt(instance: MarkdownIt): void; /** {@inheritDoc IExternalPluginProvider.getFinalizedMenu} */ getFinalizedMenu(menu: MenuBlock[], schema: Schema): MenuBlock[]; /** Applies the config of a single plugin to this provider */ private applyConfig; /** Applies the markdownProps of a config to this provider */ private extendMarkdown; } export {};