import { FC } from 'react'; import Vditor from 'vditor'; /** * https://github.com/Vanessa219/vditor#optionscache */ interface ICache { id?: string; enable?: boolean; after?(markdown: string): void; } /** * https://github.com/Vanessa219/vditor#optionsclasses */ interface IClasses { preview?: ""; } /** * ⚠️ 仅支持 wysiwyg 模式 * https://github.com/Vanessa219/vditor#optionscomment */ interface IComment { enable: boolean; add?(id: string, text: string, commentsData: ICommentData[]): void; remove?(ids: string[]): void; scroll?(top: number): void; adjustTop?(commentsData: ICommentData[]): void; } interface ICommentData { id: string; top: number; } /** * https://github.com/Vanessa219/vditor#optionscounter */ interface ICounterBase { enable: boolean; max?: number; type?: "markdown" | "text"; } interface ICounter extends ICounterBase { after?(length: number, counter?: ICounterBase): void; } interface IEvents { after?(): void; input?(value: string): void; focus?(value: string): void; blur?(value: string): void; esc?(value: string): void; ctrlEnter?(value: string): void; select?(value: string): void; } /** * https://github.com/Vanessa219/vditor#optionsfullscreen */ interface IFullscreen { index: number; } interface IObject { [key: string]: string; } /** * https://github.com/Vanessa219/vditor#optionshint */ interface IHint { parse?: boolean; delay?: number; /** * https://github.com/88250/lute/blob/master/parse/emoji_map.go */ emoji?: IObject; emojiTail?: string; emojiPath?: string; extend?: Array; } interface IHintExtend { key: string; hint?(value: string): Array<{ html: string; value: string; }>; } /** * https://github.com/Vanessa219/vditor/blob/master/types/index.d.ts#L233 */ interface ITips$1 { [index: string]: string; alignCenter: string; alignLeft: string; alignRight: string; alternateText: string; bold: string; both: string; check: string; close: string; code: string; "code-theme": string; column: string; comment: string; confirm: string; "content-theme": string; copied: string; copy: string; "delete-column": string; "delete-row": string; devtools: string; down: string; downloadTip: string; edit: string; "edit-mode": string; emoji: string; export: string; fileTypeError: string; footnoteRef: string; fullscreen: string; generate: string; headings: string; help: string; imageURL: string; indent: string; info: string; "inline-code": string; "insert-after": string; "insert-before": string; insertColumnLeft: string; insertColumnRight: string; insertRowAbove: string; insertRowBelow: string; instantRendering: string; italic: string; language: string; line: string; link: string; linkRef: string; list: string; more: string; nameEmpty: string; "ordered-list": string; outdent: string; outline: string; over: string; performanceTip: string; preview: string; quote: string; record: string; "record-tip": string; recording: string; redo: string; remove: string; row: string; spin: string; splitView: string; strike: string; table: string; textIsNotEmpty: string; title: string; tooltipText: string; undo: string; up: string; update: string; upload: string; uploadError: string; uploading: string; wysiwyg: string; } /** * https://github.com/Vanessa219/vditor#optionsoutline */ interface IOutline { enable: boolean; position: "left" | "right"; } /** * https://github.com/Vanessa219/vditor#optionspreview */ interface IPreview { delay?: number; maxWidth?: number; mode?: "both" | "editor"; url?: string; parse?: (element: HTMLElement) => void; transform?: (html: string) => string; hljs?: IPreviewHLJS; markdown?: IPreviewMarkdown; theme?: IPreviewTheme; math?: IPreviewMath; actions?: IPreviewActions; } /** * https://github.com/Vanessa219/vditor/blob/master/types/index.d.ts#L505 */ interface IPreviewOptions$1 { mode: "dark" | "light"; customEmoji?: IObject; lang?: keyof II18n; i18n?: ITips; lazyLoadImage?: string; emojiPath?: string; hljs?: IHljs; speech?: { enable?: boolean; }; anchor?: number; math?: IMath; cdn?: string; markdown?: IMarkdownConfig; renderers?: ILuteRender; theme?: IPreviewTheme; icon?: "ant" | "material" | undefined; transform?(html: string): string; after?(): void; } /** * https://github.com/Vanessa219/vditor#optionspreviewhljs */ interface IPreviewHLJS { enable?: boolean; style?: string; lineNumber?: boolean; } /** * https://github.com/Vanessa219/vditor#optionspreviewmarkdown */ interface IPreviewMarkdown { autoSpace?: boolean; fixTermTypo?: boolean; toc?: boolean; footnotes?: boolean; codeBlockPreview?: boolean; mathBlockPreview?: boolean; paragraphBeginningSpace?: boolean; sanitize?: boolean; listStyle?: boolean; linkBase?: string; linkPrefix?: string; mark?: boolean; } /** * https://github.com/Vanessa219/vditor#optionspreviewtheme */ interface IPreviewTheme { current: string; list?: IObject; path?: string; } /** * https://github.com/Vanessa219/vditor#optionspreviewmath */ interface IPreviewMath { inlineDigit?: boolean; macros?: object; engine?: "KaTeX" | "MathJax"; } /** * https://github.com/Vanessa219/vditor#optionspreviewactions-arrayipreviewaction--ipreviewactioncustom */ declare type IPreviewAction = "desktop" | "tablet" | "mobile" | "mp-wechat" | "zhihu"; interface IPreviewActionCustom { key: string; text: string; tooltip?: string; className?: string; click(key: string): void; } declare type IPreviewActions = Array; /** * https://github.com/Vanessa219/vditor#optionsresize */ interface IResize { enable?: boolean; position?: "top" | "bottom"; after?: (height: number) => void; } /** * https://github.com/Vanessa219/vditor#optionstoolbar */ declare type IToolbarItemEnumerated = "emoji" | "headings" | "bold" | "italic" | "strike" | "|" | "line" | "quote" | "list" | "ordered-list" | "check" | "outdent" | "indent" | "code" | "inline-code" | "insert-after" | "insert-before" | "undo" | "redo" | "upload" | "link" | "table" | "record" | "edit-mode" | "both" | "preview" | "fullscreen" | "outline" | "code-theme" | "content-theme" | "export" | "devtools" | "info" | "help" | "br"; interface IToolbarItemCustom { name: string; icon?: string; tip?: string; tipPosition?: "n" | "ne" | "nw" | "s" | "se" | "sw" | "w" | "e"; hotKey?: string; suffix?: string; prefix?: string; click?: (event: Event, vditor: any) => void; className?: string; toolbar?: IToolbar; } declare type IToolbarItem = IToolbarItemEnumerated | IToolbarItemCustom; declare type IToolbar = Array; /** * https://github.com/Vanessa219/vditor#optionstoolbarconfig */ interface IToolbarConfig { hide?: boolean; pin?: boolean; } /** * https://github.com/Vanessa219/vditor#optionsupload * * https://github.com/Vanessa219/vditor/blob/master/types/index.d.ts#L334 */ interface IUpload { /** 上传 url */ url?: string; /** 上传文件最大 Byte */ max?: number; /** 剪切板中包含图片地址时,使用此 url 重新上传 */ linkToImgUrl?: string; /** CORS 上传验证,头为 X-Upload-Token */ token?: string; /** 文件上传类型,同 [input accept](https://www.w3schools.com/tags/att_input_accept.asp) */ accept?: string; /** 跨站点访问控制。默认值: false */ withCredentials?: boolean; /** 请求头设置 */ headers?: IObject; /** 额外请求参数 */ extraData?: { [key: string]: string | Blob; }; /** 是否允许多文件上传。默认值:true */ multiple?: boolean; /** 上传字段名。默认值:file[] */ fieldName?: string; /** 每次上传前都会重新设置请求头 */ setHeaders?(): IObject; /** 上传成功回调 */ success?(editor: HTMLPreElement, msg: string): void; /** 上传失败回调 */ error?(msg: string): void; /** 文件名安全处理。 默认值: name => name.replace(/\W/g, '') */ filename?(name: string): string; /** 校验,成功时返回 true 否则返回错误信息 */ validate?(files: File[]): string | boolean; /** 自定义上传,当发生错误时返回错误信息 */ handler?(files: File[]): string | null; /** 对服务端返回的数据进行转换,以满足内置的数据结构 */ format?(files: File[], responseText: string): string; /** 对服务端返回的数据进行转换(对应linkToImgUrl),以满足内置的数据结构 */ linkToImgFormat?(responseText: string): string; /** 将上传的文件处理后再返回 */ file?(files: File[]): File[]; /** 图片地址上传后的回调 */ linkToImgCallback?(responseText: string): void; } declare type LangType = "zh_CN" | "en_US" | "ja_JP" | "ko_KR" | "ru_RU" | "zh_TW"; declare type ModeType = "ir" | "sv" | "wysiwyg"; declare type ThemeType = "classic" | "dark"; declare type IconType = "ant" | "material"; /** * https://github.com/Vanessa219/vditor#options * * https://github.com/Vanessa219/vditor/blob/328d39830e221cfa60b1cecb8cf0f579352c3e00/types/index.d.ts#L562 */ interface IOptions extends IEvents { _lutePath?: string; i18n?: ITips$1; undoDelay?: number; height?: number; minHeight?: number; width?: string; placeholder?: string; lang?: LangType; tab?: string; typewriterMode?: boolean; cdn?: string; mode?: ModeType; debugger?: boolean; value?: ""; theme?: ThemeType; icon?: IconType; toolbar?: IToolbar; toolbarConfig?: IToolbarConfig; counter?: ICounter; cache?: ICache; comment?: IComment; classes?: IClasses; fullscreen?: IFullscreen; hint?: IHint; outline?: IOutline; preview?: IPreview; resize?: IResize; upload?: IUpload; } declare const defaultOptions: IOptions; declare const defaultIROptions: IOptions; declare const defaultSVOptions: IOptions; declare const defaultWYSIWYGOptions: IOptions; interface IVditorEditorProps { keyID: string; options?: IOptions; bindVditor?(vditor: Vditor): void; } declare const VditorEditor: FC; interface IVditorIREditorProps extends IVditorEditorProps { } declare const VditorIREditor: FC; interface IVditorSVEditorProps extends IVditorEditorProps { } declare const VditorSVEditor: FC; interface IVditorWYSIWYGEditorProps extends IVditorEditorProps { } declare const VditorWYSIWYGEditor: FC; interface IVditorPreviewProps { markdown: string; options?: IPreviewOptions; customClass?: string; } declare const VditorPreview: FC; interface ILuteNode { TokensStr: () => string; __internal_object__: { Parent: { Type: number; }; HeadingLevel: string; }; } /** * https://github.com/Vanessa219/vditor/blob/328d39830e221cfa60b1cecb8cf0f579352c3e00/types/index.d.ts#L23 */ declare type ILuteRenderCallback = (node: ILuteNode, entering: boolean) => [string, number]; interface ILuteRender$1 { renderDocument?: ILuteRenderCallback; renderParagraph?: ILuteRenderCallback; renderText?: ILuteRenderCallback; renderCodeBlock?: ILuteRenderCallback; renderCodeBlockOpenMarker?: ILuteRenderCallback; renderCodeBlockInfoMarker?: ILuteRenderCallback; renderCodeBlockCode?: ILuteRenderCallback; renderCodeBlockCloseMarker?: ILuteRenderCallback; renderMathBlock?: ILuteRenderCallback; renderMathBlockOpenMarker?: ILuteRenderCallback; renderMathBlockContent?: ILuteRenderCallback; renderMathBlockCloseMarker?: ILuteRenderCallback; renderBlockquote?: ILuteRenderCallback; renderBlockquoteMarker?: ILuteRenderCallback; renderHeading?: ILuteRenderCallback; renderHeadingC8hMarker?: ILuteRenderCallback; renderList?: ILuteRenderCallback; renderListItem?: ILuteRenderCallback; renderTaskListItemMarker?: ILuteRenderCallback; renderThematicBreak?: ILuteRenderCallback; renderHTML?: ILuteRenderCallback; renderTable?: ILuteRenderCallback; renderTableHead?: ILuteRenderCallback; renderTableRow?: ILuteRenderCallback; renderTableCell?: ILuteRenderCallback; renderFootnotesDef?: ILuteRenderCallback; renderCodeSpan?: ILuteRenderCallback; renderCodeSpanOpenMarker?: ILuteRenderCallback; renderCodeSpanContent?: ILuteRenderCallback; renderCodeSpanCloseMarker?: ILuteRenderCallback; renderInlineMath?: ILuteRenderCallback; renderInlineMathOpenMarker?: ILuteRenderCallback; renderInlineMathContent?: ILuteRenderCallback; renderInlineMathCloseMarker?: ILuteRenderCallback; renderEmphasis?: ILuteRenderCallback; renderEmAsteriskOpenMarker?: ILuteRenderCallback; renderEmAsteriskCloseMarker?: ILuteRenderCallback; renderEmUnderscoreOpenMarker?: ILuteRenderCallback; renderEmUnderscoreCloseMarker?: ILuteRenderCallback; renderStrong?: ILuteRenderCallback; renderStrongA6kOpenMarker?: ILuteRenderCallback; renderStrongA6kCloseMarker?: ILuteRenderCallback; renderStrongU8eOpenMarker?: ILuteRenderCallback; renderStrongU8eCloseMarker?: ILuteRenderCallback; renderStrikethrough?: ILuteRenderCallback; renderStrikethrough1OpenMarker?: ILuteRenderCallback; renderStrikethrough1CloseMarker?: ILuteRenderCallback; renderStrikethrough2OpenMarker?: ILuteRenderCallback; renderStrikethrough2CloseMarker?: ILuteRenderCallback; renderHardBreak?: ILuteRenderCallback; renderSoftBreak?: ILuteRenderCallback; renderInlineHTML?: ILuteRenderCallback; renderLink?: ILuteRenderCallback; renderOpenBracket?: ILuteRenderCallback; renderCloseBracket?: ILuteRenderCallback; renderOpenParen?: ILuteRenderCallback; renderCloseParen?: ILuteRenderCallback; renderLinkText?: ILuteRenderCallback; renderLinkSpace?: ILuteRenderCallback; renderLinkDest?: ILuteRenderCallback; renderLinkTitle?: ILuteRenderCallback; renderImage?: ILuteRenderCallback; renderBang?: ILuteRenderCallback; renderEmoji?: ILuteRenderCallback; renderEmojiUnicode?: ILuteRenderCallback; renderEmojiImg?: ILuteRenderCallback; renderEmojiAlias?: ILuteRenderCallback; renderToC?: ILuteRenderCallback; renderFootnotesRef?: ILuteRenderCallback; renderBackslash?: ILuteRenderCallback; renderBackslashContent?: ILuteRenderCallback; } /** * https://github.com/Vanessa219/vditor/blob/328d39830e221cfa60b1cecb8cf0f579352c3e00/types/index.d.ts#L108 */ declare class Lute { static WalkStop: number; static WalkSkipChildren: number; static WalkContinue: number; static Version: string; static Caret: string; static New(): Lute; static GetHeadingID(node: ILuteNode): string; static NewNodeID(): string; private constructor(); SetJSRenderers(options?: { renderers: { HTML2VditorDOM?: ILuteRender$1; HTML2VditorIRDOM?: ILuteRender$1; HTML2Md?: ILuteRender$1; Md2HTML?: ILuteRender$1; Md2VditorDOM?: ILuteRender$1; Md2VditorIRDOM?: ILuteRender$1; Md2VditorSVDOM?: ILuteRender$1; }; }): void; SetChineseParagraphBeginningSpace(enable: boolean): void; SetHeadingID(enable: boolean): void; SetRenderListStyle(enable: boolean): void; SetLinkBase(url: string): void; SetVditorIR(enable: boolean): void; SetVditorSV(enable: boolean): void; SetVditorWYSIWYG(enable: boolean): void; SetLinkPrefix(url: string): void; SetMark(enable: boolean): void; SetSanitize(enable: boolean): void; SetHeadingAnchor(enable: boolean): void; SetImageLazyLoading(imagePath: string): void; SetInlineMathAllowDigitAfterOpenMarker(enable: boolean): void; SetToC(enable: boolean): void; SetFootnotes(enable: boolean): void; SetAutoSpace(enable: boolean): void; SetFixTermTypo(enable: boolean): void; SetEmojiSite(emojiSite: string): void; SetVditorCodeBlockPreview(enable: boolean): void; SetVditorMathBlockPreview(enable: boolean): void; PutEmojis(emojis: IObject): void; GetEmojis(): IObject; RenderEChartsJSON(text: string): string; Md2HTML(markdown: string): string; HTML2Md(html: string): string; VditorDOM2HTML(vhtml: string): string; SpinVditorDOM(html: string): string; HTML2VditorDOM(html: string): string; VditorDOM2Md(html: string): string; Md2VditorDOM(markdown: string): string; SpinVditorIRDOM(markdown: string): string; VditorIRDOM2Md(html: string): string; Md2VditorIRDOM(text: string): string; VditorIRDOM2HTML(html: string): string; HTML2VditorIRDOM(html: string): string; SpinVditorSVDOM(text: string): string; Md2VditorSVDOM(text: string): string; RenderJSON(markdown: string): string; } interface IVditorDevtools { element: HTMLDivElement; renderEcharts(vditor: IVditor): void; } interface IVditorOutline { element: HTMLElement; render(vditor: IVditor): string; toggle(vditor: IVditor, show?: boolean): void; } interface IVditorToolbar { elements?: { [key: string]: HTMLElement; }; element?: HTMLElement; } interface IVditorPreview { element: HTMLElement; render(vditor: IVditor, value?: string): void; } interface IVditorCounter { element: HTMLElement; render(vditor: IVditor, mdText?: string): void; } interface IVditorResize { element: HTMLElement; } interface IVditorHint { timeId: number; element: HTMLDivElement; recentLanguage: string; fillEmoji(element: HTMLElement, vditor: IVditor): void; render(vditor: IVditor): void; genHTML(data: { html: string; value: string; }, key: string, vditor: IVditor): void; select(event: KeyboardEvent, vditor: IVditor): boolean; } interface IVditorTip { element: HTMLElement; show(text: string, time?: number): void; hide(): void; } interface IVditorUpload { element: HTMLElement; isUploading: boolean; range: Range; } interface IVditorUndo { clearStack(vditor: IVditor): void; redo(vditor: IVditor): void; undo(vditor: IVditor): void; addToUndoStack(vditor: IVditor): void; recordFirstPostion(vditor: IVditor, event: KeyboardEvent): void; resetIcon(vditor: IVditor): void; } interface IVditorWYSIWYG { range: Range; element: HTMLPreElement; selectPopover: HTMLDivElement; popover: HTMLDivElement; afterRenderTimeoutId: number; hlToolbarTimeoutId: number; preventInput: boolean; composingLock: boolean; commentIds: string[]; getComments(vditor: IVditor, getData?: boolean): ICommentData; triggerRemoveComment(vditor: IVditor): void; showComment(): void; hideComment(): void; } interface IVditorIR { range: Range; element: HTMLPreElement; composingLock: boolean; preventInput: boolean; processTimeoutId: number; hlToolbarTimeoutId: number; } interface IVditorSV { range: Range; element: HTMLPreElement; processTimeoutId: number; hlToolbarTimeoutId: number; composingLock: boolean; preventInput: boolean; } /** * 声明 Vditor * * https://github.com/Vanessa219/vditor/blob/328d39830e221cfa60b1cecb8cf0f579352c3e00/types/index.d.ts#L676 */ interface IVditor { element: HTMLElement; options: IOptions; originalInnerHTML: string; lute: Lute; currentMode: ModeType; devtools?: IVditorDevtools; outline: IVditorOutline; toolbar?: IVditorToolbar; preview?: IVditorPreview; counter?: IVditorCounter; resize?: IVditorResize; hint: IVditorHint; tip: IVditorTip; upload?: IVditorUpload; undo?: IVditorUndo; wysiwyg?: IVditorWYSIWYG; ir?: IVditorIR; sv?: IVditorSV; } export { ICache, IClasses, IComment, ICommentData, ICounter, ICounterBase, IEvents, IFullscreen, IHint, IHintExtend, IOptions, IOutline, IPreview, IPreviewAction, IPreviewActionCustom, IPreviewActions, IPreviewHLJS, IPreviewMarkdown, IPreviewMath, IPreviewOptions$1 as IPreviewOptions, IPreviewTheme, IResize, IToolbar, IToolbarConfig, IToolbarItem, IToolbarItemCustom, IToolbarItemEnumerated, IVditor, IconType, LangType, ModeType, ThemeType, VditorEditor, VditorIREditor, VditorPreview, VditorSVEditor, VditorWYSIWYGEditor, defaultIROptions, defaultOptions, defaultSVOptions, defaultWYSIWYGOptions };