import type { Node } from "prosemirror-model"; import type { EditorView } from "prosemirror-view"; import { EditorPlugin } from "./editor-plugin"; import type { ImageUploadOptions } from "./prosemirror-plugins/image-upload"; /** Describes each distinct editor type the StacksEditor handles */ export declare enum EditorType { RichText = 0, Commonmark = 1 } /** Describes the options that are common to all view types */ export interface CommonViewOptions { /** The classes to add to the editor target */ classList?: string[]; /** * Attributes to add to the editor target element; * attributes with a value of `true` will be set without a value; * likewise, attributes with a value of `false` will not be set at all; * camelCased keys will be translated to kebab-case * e.g. "dataFooBar" will become "data-foo-bar" */ elementAttributes?: Record; /** The url to where the "Help" button should lead to */ editorHelpLink?: string; /** The features to allow/disallow on the markdown parser */ parserFeatures?: CommonmarkParserFeatures; /** The placeholder text for an empty editor */ placeholderText?: string; /** * Function to get the container to place the menu bar; * defaults to returning this editor's target's parentNode */ menuParentContainer?: (view: EditorView) => Element; /** * TODO need both this AND menuParentContainer? * Function to get the container to place any floating plugins; * defaults to returning this editor's target's parentNode */ pluginParentContainer?: (view: EditorView) => Element; /** Image uploader options */ imageUpload?: ImageUploadOptions; /** Externally written plugins to add to the editor */ editorPlugins?: EditorPlugin[]; } /** Configuration options for parsing and rendering [tag:*] and [meta-tag:*] syntax */ /** @typedef {Object} TagLinkInfo * @property {string} link - Destination URL for the tag link * @property {Array.} additionalClasses - CSS classes to specify on the link element in addition to .s-tag * @property {string} linkTitle - Text to be placed in the 'title' attribute on the rendered link */ export interface TagLinkOptions { /** Disables meta tag support entirely, removing entries from the menu and skipping calls to validate */ disableMetaTags?: boolean; /** * Callback to check if a tagname is valid; a return value of false fails the token parsing * @param tagName The name of the tag being validated * @param isMetaTag Whether the tag is a meta tag; may not be passed depending on the calling context * @param totalMarkup The full parsed markup of the tag link; may not be passed depending on the calling context */ validate?: (tagName: string, isMetaTag?: boolean, totalMarkup?: string) => boolean; /** Provide the necessary information to render the parsed tag as a link * @param tagName - the name of the tag * @param isMetaTag - whether the tag was specified via [meta-tag:*] or not * @return {TagLinkInfo} */ render?: (tagName: string, isMetaTag: boolean) => { link: string; additionalClasses: string[]; linkTitle: string; }; } /** The features to enable/disable on the commonmark parser */ export interface CommonmarkParserFeatures { /** Enable Stack Snippets */ snippets?: boolean; /** Enable HTML parsing (with sanitization) */ html?: boolean; /** * Enables support for Markdig's ExtraEmphasis plugin; * ~~strikethrough~~, ~subscript, ^superscript, * inserted, marked * TODO only strikethrough is currently supported */ extraEmphasis?: boolean; /** Enable tables according to GitHub-flavored markdown */ tables?: boolean; tagLinks?: TagLinkOptions; /** The method used to validate links; defaults to Stack Overflow's link validation */ validateLink?: (url: string) => boolean; } export declare const defaultParserFeatures: Required; export interface View { readonly dom: Element; readonly editorView: EditorView; readonly readonly: boolean; content: string; focus(): void; destroy(): void; } /** Abstract class that contains shared functionality for implementing View */ export declare abstract class BaseView implements View { editorView: EditorView; get document(): Node; get dom(): Element; get readonly(): boolean; focus(): void; destroy(): void; get content(): string; set content(value: string); /** Adds the specified content to a new node at the end of the document */ appendContent(value: string): void; /** * Sets all attributes on the target contenteditable element * @param el The node to set the attributes on * @param options The options passed to the editor */ protected setTargetNodeAttributes(el: HTMLElement, options: CommonViewOptions): void; /** * Parses a string containing markdown into a Node * @param content The markdown string to parse */ abstract parseContent(content: string): Node; /** * Serializes the current document's contents into a markdown string */ abstract serializeContent(): string; }