import { n as ShikiOptions } from "./shiki-B4uMZbMY.mjs"; import { ComarkPlugin } from "comark"; import { AnyExtension, Extension, JSONContent, Mark, Node, NodeViewRenderer } from "@tiptap/core"; import { StarterKitOptions } from "@tiptap/starter-kit"; import { EditorState, Plugin, PluginKey, Transaction } from "@tiptap/pm/state"; import { DecorationSet } from "@tiptap/pm/view"; //#region src/editor/kit.d.ts interface ComarkKitOptions { /** * Passed to StarterKit. A collaborative editor turns `undoRedo` off, since Yjs keeps its own history. Comark has no * underline syntax, so `underline` is always off. */ starterKit?: Partial; /** * Draws block and inline components, such as `componentView()` from `comark-ui/editor/vue`. A node view only draws: * the schema and the Markdown stay the same, so a server's codec and its browsers share a room with or without it. */ componentView?: NodeViewRenderer; } /** Markdown's image, inline as Comark parses it, drawn as a player when comark-media would play it. */ declare const ComarkImage: Node; /** A block component, `::name`, or a block of raw HTML. Its children are blocks and its `#slot`s. */ declare const ComarkBlock: Node; /** A component's named slot, `#name`. */ declare const ComarkSlot: Node; /** An inline component, `:name[text]{props}`, or inline raw HTML. */ declare const ComarkInline: Node; /** An HTML comment between blocks. */ declare const ComarkComment: Node; /** A footnote reference, `[^label]`. */ declare const FootnoteReference: Node; /** A note written where it applies, `^[text]`. */ declare const InlineFootnote: Node; /** A footnote's text, `[^label]: text`, with the blocks indented under it. */ declare const FootnoteDefinition: Node; /** A definition list, `Term` then `: Definition`. */ declare const DefinitionList: Node; declare const DefinitionTerm: Node; declare const DefinitionDescription: Node; /** CriticMarkup's suggested insertion, `{++text++}`. */ declare const CriticInsertion: Mark; /** CriticMarkup's suggested deletion, `{--text--}`. */ declare const CriticDeletion: Mark; /** CriticMarkup's highlight, `{==text==}`. */ declare const CriticHighlight: Mark; /** CriticMarkup's comment, `{>>text<<}`. */ declare const CriticComment: Node; /** * The schema `fromMarkdown` and `toMarkdown` read and write: StarterKit's nodes and marks, task lists, inline images, * tables, footnotes, definition lists, CriticMarkup, and Comark's components, slots, and comments. It needs no DOM, so a server can load it to convert a document * for a collaborative room. */ declare const ComarkKit: Extension; //#endregion //#region src/editor/markdown.d.ts /** * How the page parses Markdown: the plugins it renders with, and `registerDefaultPlugins: false` when it leaves out * Comark's defaults. The editor reads and checks a document the same way, so a bare URL the page shows as text stays * text, rather than becoming a link that a save writes as ``. */ interface PageParser { plugins?: readonly ComarkPlugin[]; registerDefaultPlugins?: boolean; } interface EditorDocument { /** The document as Tiptap JSON, for `setContent` or a collaborative room. */ doc: JSONContent; /** The front matter, which stays outside the editor. A collaborative room keeps it beside the body, in its fields. */ frontmatter: Record; /** The Markdown holds something the editor can't keep, so writing it back would change more than the edit. */ lossy: boolean; } /** Reads Markdown into the editor's document, as a page that parses it with `page` reads it. */ declare function fromMarkdown(markdown: string, page?: PageParser): Promise; /** Writes the editor's document, such as `editor.getJSON()`, back to Markdown. */ declare function toMarkdown(doc: JSONContent, options?: { frontmatter?: Record; }): Promise; /** A Markdown file as a collaborative room holds it: the body the editor shows, and the frontmatter beside it. */ interface SplitMarkdown { body: string; fields: Record; } type MarkdownCheck = { editable: true; /** The Markdown as the editor writes it, which the first save produces. */ markdown: string; } | { editable: false; /** Why, when it's the frontmatter the editor can't keep. */ reason?: string; }; /** * Whether the editor can open this Markdown and save it without changing what readers see. Pass how the page parses * it, so syntax only its plugins read, such as footnote definitions, counts too, and the page's tree before and after a * save must match. */ declare function checkMarkdown(markdown: string, page?: PageParser): Promise; //#endregion //#region src/editor/upload.d.ts interface UploadOptions { /** * Sends one file and resolves with the URL the document links to. Call `progress` with a fraction from 0 to 1 as the * bytes go; `fetch` can't report them, so use XMLHttpRequest's `upload.onprogress`. Without it, nothing uploads. */ upload?: (file: File, progress: (fraction: number) => void) => Promise; /** Which files to take from a paste, a drop, or the file picker. Images, video, and audio by default. */ accept: (file: File) => boolean; /** The file types `chooseFiles()` offers in the file picker, as an `` value. Media by default. */ pick?: string; /** Called when `upload` rejects. The placeholder is gone by then. */ onError?: (error: unknown, file: File) => void; } /** What a placeholder shows while its file uploads. */ interface PendingUpload { id: number; file: File; /** From 0 to 1, or `null` until the first progress report. */ fraction: number | null; /** A `blob:` URL for an image or video's preview, for this browser only. */ preview?: string; } /** The state an editor view gives the plugin: a test can pass a plain object. */ interface View { readonly state: EditorState; dispatch(tr: Transaction): void; } declare const uploadKey: PluginKey; /** Where placeholder `id` sits now, after every edit since it was added. */ declare function findUpload(state: EditorState, id: number): number | undefined; /** The placeholder's styles, which the editor adds to the page with the first one. */ declare const uploadCss: string; /** * Uploads `files` into the document at `pos`. Each shows a placeholder there until its URL comes back, then becomes an * image node, which comark-media plays when its URL ends in a video or audio extension. The placeholder is a * decoration, so a collaborative room never sees a file that hasn't finished. */ declare function startUploads(view: View, files: File[], pos: number, options: UploadOptions): Promise[]; /** * Opens the file picker and uploads what's picked at the cursor, with the same placeholders as a paste. Returns false * without an `upload` callback. A "/" menu's Image item calls it through the `chooseFiles` command. */ declare function chooseFiles(view: View, options: UploadOptions): boolean; /** The plugin alone, for a ProseMirror editor without Tiptap. */ declare function uploadPlugin(options: UploadOptions): Plugin; declare module "@tiptap/core" { interface Commands { comarkUpload: { /** Uploads files at the cursor, as a paste would, such as the ones a file picker returns. */ uploadFiles: (files: File[]) => ReturnType; /** Opens the file picker and uploads the files picked at the cursor, as a "/" menu's Image item would. */ chooseFiles: () => ReturnType; }; } } /** Uploads pasted and dropped files, with a placeholder that shows the progress. Pass `upload` to turn it on. */ declare const Upload: Extension; //#endregion //#region src/editor/codec.d.ts /** * A schema and Markdown codec that a server and its browsers share, as a collaborative room needs: the server converts * the stored Markdown with it, and every editor that joins builds the same schema from `extensions()`. ViteHub * Realtime's `editor` option takes it as it is. * * A room holds the body as the editor's document and the frontmatter as its fields, a map of one value per key, so an * edit to the text never writes over the metadata. `split()` and `join()` convert between a stored file and the two. */ interface EditorCodec { extensions(): AnyExtension[]; /** Reads a room's body, without frontmatter. */ fromMarkdown(markdown: string): Promise; /** Writes a room's body, without frontmatter. */ toMarkdown(doc: JSONContent): Promise; /** * Splits a stored file into the room's body and fields. Frontmatter a save couldn't write back stays in the body, * where `verify()` says why the room can't save it. */ split(markdown: string): SplitMarkdown; /** Joins a room's body and fields into the file to store. */ join(document: SplitMarkdown): string; /** * Whether the room may save this body. `canonical` is what the first save writes for it unchanged, and `issues` says * why a body that still holds frontmatter can't be saved. The fields need no check: every JSON value survives YAML. */ verify(markdown: string): Promise<{ writable: boolean; canonical?: string; issues?: { message: string; }[]; }>; } /** * Pass how the page parses Markdown, `plugins` and `registerDefaultPlugins` as given to Comark's parser, so the room * reads a document as readers see it, and a document a save would change for them opens read-only. */ interface EditorCodecOptions extends PageParser { kit?: ComarkKitOptions; } declare function createEditorCodec(options?: EditorCodecOptions): EditorCodec; //#endregion //#region src/editor/highlight.d.ts /** The preset's `shiki` option: the editor colors code with the same highlighter and themes as the page. */ type CodeHighlightOptions = Pick; declare const codeHighlightKey: PluginKey; /** * Colors the editor's code blocks with the page's Shiki, as decorations, so the document and its Markdown stay plain * and a collaborative room never sees the colors. A language loads the first time a block uses it. One the highlighter * doesn't have, or whose grammar fails, stays plain until the editor is created again, rather than retry on each key. */ declare const CodeHighlight: Extension; //#endregion export { CriticComment as A, ComarkBlock as C, ComarkKit as D, ComarkInline as E, DefinitionList as F, DefinitionTerm as I, FootnoteDefinition as L, CriticHighlight as M, CriticInsertion as N, ComarkKitOptions as O, DefinitionDescription as P, FootnoteReference as R, toMarkdown as S, ComarkImage as T, MarkdownCheck as _, EditorCodecOptions as a, checkMarkdown as b, Upload as c, findUpload as d, startUploads as f, EditorDocument as g, uploadPlugin as h, EditorCodec as i, CriticDeletion as j, ComarkSlot as k, UploadOptions as l, uploadKey as m, CodeHighlightOptions as n, createEditorCodec as o, uploadCss as p, codeHighlightKey as r, PendingUpload as s, CodeHighlight as t, chooseFiles as u, PageParser as v, ComarkComment as w, fromMarkdown as x, SplitMarkdown as y, InlineFootnote as z };