index.d.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. declare module "*.svg";
  2. declare module "*.png";
  3. interface Window {
  4. VditorI18n: ITips;
  5. }
  6. interface IObject {
  7. [key: string]: string;
  8. }
  9. interface ILuteNode {
  10. TokensStr: () => string;
  11. __internal_object__: {
  12. Parent: {
  13. Type: number,
  14. },
  15. HeadingLevel: string,
  16. };
  17. }
  18. type ILuteRenderCallback = (node: ILuteNode, entering: boolean) => [string, number];
  19. /** @link https://ld246.com/article/1588412297062 */
  20. interface ILuteRender {
  21. renderDocument?: ILuteRenderCallback;
  22. renderParagraph?: ILuteRenderCallback;
  23. renderText?: ILuteRenderCallback;
  24. renderCodeBlock?: ILuteRenderCallback;
  25. renderCodeBlockOpenMarker?: ILuteRenderCallback;
  26. renderCodeBlockInfoMarker?: ILuteRenderCallback;
  27. renderCodeBlockCode?: ILuteRenderCallback;
  28. renderCodeBlockCloseMarker?: ILuteRenderCallback;
  29. renderMathBlock?: ILuteRenderCallback;
  30. renderMathBlockOpenMarker?: ILuteRenderCallback;
  31. renderMathBlockContent?: ILuteRenderCallback;
  32. renderMathBlockCloseMarker?: ILuteRenderCallback;
  33. renderBlockquote?: ILuteRenderCallback;
  34. renderBlockquoteMarker?: ILuteRenderCallback;
  35. renderHeading?: ILuteRenderCallback;
  36. renderHeadingC8hMarker?: ILuteRenderCallback;
  37. renderList?: ILuteRenderCallback;
  38. renderListItem?: ILuteRenderCallback;
  39. renderTaskListItemMarker?: ILuteRenderCallback;
  40. renderThematicBreak?: ILuteRenderCallback;
  41. renderHTML?: ILuteRenderCallback;
  42. renderTable?: ILuteRenderCallback;
  43. renderTableHead?: ILuteRenderCallback;
  44. renderTableRow?: ILuteRenderCallback;
  45. renderTableCell?: ILuteRenderCallback;
  46. renderFootnotesDef?: ILuteRenderCallback;
  47. renderCodeSpan?: ILuteRenderCallback;
  48. renderCodeSpanOpenMarker?: ILuteRenderCallback;
  49. renderCodeSpanContent?: ILuteRenderCallback;
  50. renderCodeSpanCloseMarker?: ILuteRenderCallback;
  51. renderInlineMath?: ILuteRenderCallback;
  52. renderInlineMathOpenMarker?: ILuteRenderCallback;
  53. renderInlineMathContent?: ILuteRenderCallback;
  54. renderInlineMathCloseMarker?: ILuteRenderCallback;
  55. renderEmphasis?: ILuteRenderCallback;
  56. renderEmAsteriskOpenMarker?: ILuteRenderCallback;
  57. renderEmAsteriskCloseMarker?: ILuteRenderCallback;
  58. renderEmUnderscoreOpenMarker?: ILuteRenderCallback;
  59. renderEmUnderscoreCloseMarker?: ILuteRenderCallback;
  60. renderStrong?: ILuteRenderCallback;
  61. renderStrongA6kOpenMarker?: ILuteRenderCallback;
  62. renderStrongA6kCloseMarker?: ILuteRenderCallback;
  63. renderStrongU8eOpenMarker?: ILuteRenderCallback;
  64. renderStrongU8eCloseMarker?: ILuteRenderCallback;
  65. renderStrikethrough?: ILuteRenderCallback;
  66. renderStrikethrough1OpenMarker?: ILuteRenderCallback;
  67. renderStrikethrough1CloseMarker?: ILuteRenderCallback;
  68. renderStrikethrough2OpenMarker?: ILuteRenderCallback;
  69. renderStrikethrough2CloseMarker?: ILuteRenderCallback;
  70. renderHardBreak?: ILuteRenderCallback;
  71. renderSoftBreak?: ILuteRenderCallback;
  72. renderInlineHTML?: ILuteRenderCallback;
  73. renderLink?: ILuteRenderCallback;
  74. renderOpenBracket?: ILuteRenderCallback;
  75. renderCloseBracket?: ILuteRenderCallback;
  76. renderOpenParen?: ILuteRenderCallback;
  77. renderCloseParen?: ILuteRenderCallback;
  78. renderLinkText?: ILuteRenderCallback;
  79. renderLinkSpace?: ILuteRenderCallback;
  80. renderLinkDest?: ILuteRenderCallback;
  81. renderLinkTitle?: ILuteRenderCallback;
  82. renderImage?: ILuteRenderCallback;
  83. renderBang?: ILuteRenderCallback;
  84. renderEmoji?: ILuteRenderCallback;
  85. renderEmojiUnicode?: ILuteRenderCallback;
  86. renderEmojiImg?: ILuteRenderCallback;
  87. renderEmojiAlias?: ILuteRenderCallback;
  88. renderToC?: ILuteRenderCallback;
  89. renderFootnotesRef?: ILuteRenderCallback;
  90. renderBackslash?: ILuteRenderCallback;
  91. renderBackslashContent?: ILuteRenderCallback;
  92. }
  93. interface ILuteOptions extends IMarkdownConfig {
  94. emojis: IObject;
  95. emojiSite: string;
  96. headingAnchor: boolean;
  97. inlineMathDigit: boolean;
  98. lazyLoadImage?: string;
  99. }
  100. declare class Lute {
  101. public static WalkStop: number;
  102. public static WalkSkipChildren: number;
  103. public static WalkContinue: number;
  104. public static Version: string;
  105. public static Caret: string;
  106. public static New(): Lute;
  107. public static GetHeadingID(node: ILuteNode): string;
  108. public static NewNodeID(): string;
  109. public static Sanitize(html: string): string;
  110. private constructor();
  111. public SetJSRenderers(options?: {
  112. renderers: {
  113. HTML2VditorDOM?: ILuteRender,
  114. HTML2VditorIRDOM?: ILuteRender,
  115. HTML2Md?: ILuteRender,
  116. Md2HTML?: ILuteRender,
  117. Md2VditorDOM?: ILuteRender,
  118. Md2VditorIRDOM?: ILuteRender,
  119. Md2VditorSVDOM?: ILuteRender,
  120. },
  121. }): void;
  122. public SetChineseParagraphBeginningSpace(enable: boolean): void;
  123. public SetHeadingID(enable: boolean): void;
  124. public SetRenderListStyle(enable: boolean): void;
  125. public SetLinkBase(url: string): void;
  126. public SetVditorIR(enable: boolean): void;
  127. public SetVditorSV(enable: boolean): void;
  128. public SetVditorWYSIWYG(enable: boolean): void;
  129. public SetLinkPrefix(url: string): void;
  130. public SetMark(enable: boolean): void;
  131. public SetSanitize(enable: boolean): void;
  132. public SetHeadingAnchor(enable: boolean): void;
  133. public SetImageLazyLoading(imagePath: string): void;
  134. public SetInlineMathAllowDigitAfterOpenMarker(enable: boolean): void;
  135. public SetToC(enable: boolean): void;
  136. public SetFootnotes(enable: boolean): void;
  137. public SetAutoSpace(enable: boolean): void;
  138. public SetFixTermTypo(enable: boolean): void;
  139. public SetEmojiSite(emojiSite: string): void;
  140. public SetVditorCodeBlockPreview(enable: boolean): void;
  141. public SetVditorMathBlockPreview(enable: boolean): void;
  142. public PutEmojis(emojis: IObject): void;
  143. public GetEmojis(): IObject;
  144. // debugger md
  145. public RenderEChartsJSON(text: string): string;
  146. // md 转换为 html
  147. public Md2HTML(markdown: string): string;
  148. // 粘贴时将 html 转换为 md
  149. public HTML2Md(html: string): string;
  150. // wysiwyg 转换为 html
  151. public VditorDOM2HTML(vhtml: string): string;
  152. // wysiwyg 输入渲染
  153. public SpinVditorDOM(html: string): string;
  154. // 粘贴时将 html 转换为 wysiwyg
  155. public HTML2VditorDOM(html: string): string;
  156. // 将 wysiwyg 转换为 md
  157. public VditorDOM2Md(html: string): string;
  158. // 将 md 转换为 wysiwyg
  159. public Md2VditorDOM(markdown: string): string;
  160. // ir 输入渲染
  161. public SpinVditorIRDOM(markdown: string): string;
  162. // ir 获取 md
  163. public VditorIRDOM2Md(html: string): string;
  164. // md 转换为 ir
  165. public Md2VditorIRDOM(text: string): string;
  166. // 获取 HTML
  167. public VditorIRDOM2HTML(html: string): string;
  168. // 粘贴时将 html 转换为 sv
  169. public HTML2VditorIRDOM(html: string): string;
  170. // sv 输入渲染
  171. public SpinVditorSVDOM(text: string): string;
  172. // 粘贴是 md 转换为 sv
  173. public Md2VditorSVDOM(text: string): string;
  174. // 将markdown转化为JSON结构输出 https://github.com/88250/lute/issues/120
  175. public RenderJSON(markdown: string): string;
  176. }
  177. declare const webkitAudioContext: {
  178. prototype: AudioContext
  179. new(contextOptions?: AudioContextOptions): AudioContext,
  180. };
  181. interface ITips {
  182. [index: string]: string;
  183. alignCenter: string;
  184. alignLeft: string;
  185. alignRight: string;
  186. alternateText: string;
  187. bold: string;
  188. both: string;
  189. check: string;
  190. close: string;
  191. code: string;
  192. "code-theme": string;
  193. column: string;
  194. comment: string;
  195. confirm: string;
  196. "content-theme": string;
  197. copied: string;
  198. copy: string;
  199. "delete-column": string;
  200. "delete-row": string;
  201. devtools: string;
  202. down: string;
  203. downloadTip: string;
  204. edit: string;
  205. "edit-mode": string;
  206. emoji: string;
  207. export: string;
  208. fileTypeError: string;
  209. footnoteRef: string;
  210. fullscreen: string;
  211. generate: string;
  212. headings: string;
  213. help: string;
  214. imageURL: string;
  215. indent: string;
  216. info: string;
  217. "inline-code": string;
  218. "insert-after": string;
  219. "insert-before": string;
  220. insertColumnLeft: string;
  221. insertColumnRight: string;
  222. insertRowAbove: string;
  223. insertRowBelow: string;
  224. instantRendering: string;
  225. italic: string;
  226. language: string;
  227. line: string;
  228. link: string;
  229. linkRef: string;
  230. list: string;
  231. more: string;
  232. nameEmpty: string;
  233. "ordered-list": string;
  234. outdent: string;
  235. outline: string;
  236. over: string;
  237. performanceTip: string;
  238. preview: string;
  239. quote: string;
  240. record: string;
  241. "record-tip": string;
  242. recording: string;
  243. redo: string;
  244. remove: string;
  245. row: string;
  246. spin: string;
  247. splitView: string;
  248. strike: string;
  249. table: string;
  250. textIsNotEmpty: string;
  251. title: string;
  252. tooltipText: string;
  253. undo: string;
  254. up: string;
  255. update: string;
  256. upload: string;
  257. uploadError: string;
  258. uploading: string;
  259. wysiwyg: string;
  260. }
  261. interface II18n {
  262. en_US: ITips;
  263. ja_JP: ITips;
  264. ko_KR: ITips;
  265. ru_RU: ITips;
  266. zh_CN: ITips;
  267. zh_TW: ITips;
  268. }
  269. interface IClasses {
  270. preview?: string;
  271. }
  272. interface IPreviewTheme {
  273. current: string;
  274. list?: IObject;
  275. path?: string;
  276. }
  277. /** @link https://ld246.com/article/1549638745630#options-upload */
  278. interface IUpload {
  279. /** 上传 url */
  280. url?: string;
  281. /** 上传文件最大 Byte */
  282. max?: number;
  283. /** 剪切板中包含图片地址时,使用此 url 重新上传 */
  284. linkToImgUrl?: string;
  285. /** CORS 上传验证,头为 X-Upload-Token */
  286. token?: string;
  287. /** 文件上传类型,同 [input accept](https://www.w3schools.com/tags/att_input_accept.asp) */
  288. accept?: string;
  289. /** 跨站点访问控制。默认值: false */
  290. withCredentials?: boolean;
  291. /** 请求头设置 */
  292. headers?: IObject;
  293. /** 额外请求参数 */
  294. extraData?: { [key: string]: string | Blob };
  295. /** 是否允许多文件上传。默认值:true */
  296. multiple?: boolean;
  297. /** 上传字段名。默认值:file[] */
  298. fieldName?: string;
  299. /** 每次上传前都会重新设置请求头 */
  300. setHeaders?(): IObject;
  301. /** 上传成功回调 */
  302. success?(editor: HTMLPreElement, msg: string): void;
  303. /** 上传失败回调 */
  304. error?(msg: string): void;
  305. /** 文件名安全处理。 默认值: name => name.replace(/\W/g, '') */
  306. filename?(name: string): string;
  307. /** 校验,成功时返回 true 否则返回错误信息 */
  308. validate?(files: File[]): string | boolean;
  309. /** 自定义上传,当发生错误时返回错误信息 */
  310. handler?(files: File[]): string | null | Promise<string> | Promise<null>;
  311. /** 对服务端返回的数据进行转换,以满足内置的数据结构 */
  312. format?(files: File[], responseText: string): string;
  313. /** 对服务端返回的数据进行转换(对应linkToImgUrl),以满足内置的数据结构 */
  314. linkToImgFormat?(responseText: string): string;
  315. /** 将上传的文件处理后再返回 */
  316. file?(files: File[]): File[] | Promise<File[]>;
  317. /** 图片地址上传后的回调 */
  318. linkToImgCallback?(responseText: string): void;
  319. }
  320. /** @link https://ld246.com/article/1549638745630#options-toolbar */
  321. interface IMenuItem {
  322. /** 唯一标示 */
  323. name: string;
  324. /** svg 图标 HTML */
  325. icon?: string;
  326. /** 元素的样式名称 */
  327. className?: string;
  328. /** 提示 */
  329. tip?: string;
  330. /** 快捷键,支持⌘/ctrl-key 或 ⌘/ctrl-⇧/shift-key 格式的配置,不支持 wysiwyg 模式 */
  331. hotkey?: string;
  332. /** 插入编辑器中的后缀 */
  333. suffix?: string;
  334. /** 插入编辑器中的前缀 */
  335. prefix?: string;
  336. /** 提示位置:ne, nw */
  337. tipPosition?: string;
  338. /** 子菜单 */
  339. toolbar?: Array<string | IMenuItem>;
  340. /** 菜单层级,最大为 3,内部使用 */
  341. level?: number;
  342. /** 自定义按钮点击时触发的事件 */
  343. click?(event: Event, vditor: IVditor): void;
  344. }
  345. /** @link https://ld246.com/article/1549638745630#options-preview-hljs */
  346. interface IHljs {
  347. /** 是否启用行号。默认值: false */
  348. lineNumber?: boolean;
  349. /** 代码风格,可选值参见 [Chroma](https://xyproto.github.io/splash/docs/longer/all.html)。 默认值: 'github' */
  350. style?: string;
  351. /** 是否启用代码高亮。默认值: true */
  352. enable?: boolean;
  353. }
  354. /** @link https://ld246.com/article/1549638745630#options-preview-math */
  355. interface IMath {
  356. /** 内联数学公式起始 $ 后是否允许数字。默认值: false */
  357. inlineDigit?: boolean;
  358. /** 使用 MathJax 渲染时传入的宏定义。默认值: {} */
  359. macros?: object;
  360. /** 数学公式渲染引擎。默认值: 'KaTeX' */
  361. engine?: "KaTeX" | "MathJax";
  362. }
  363. /** @link https://ld246.com/article/1549638745630#options-preview-markdown */
  364. interface IMarkdownConfig {
  365. /** 自动空格。默认值: false */
  366. autoSpace?: boolean;
  367. /** 段落开头是否空两格。默认值: false */
  368. paragraphBeginningSpace?: boolean;
  369. /** 自动矫正术语。默认值: false */
  370. fixTermTypo?: boolean;
  371. /** 插入目录。默认值: false */
  372. toc?: boolean;
  373. /** 脚注。默认值: true */
  374. footnotes?: boolean;
  375. /** wysiwyg & ir 模式代码块是否渲染。默认值: true */
  376. codeBlockPreview?: boolean;
  377. /** wysiwyg & ir 模式数学公式块是否渲染。默认值: true */
  378. mathBlockPreview?: boolean;
  379. /** 是否启用过滤 XSS。默认值: true */
  380. sanitize?: boolean;
  381. /** 链接相对路径前缀。默认值:'' */
  382. linkBase?: string;
  383. /** 链接强制前缀。默认值:'' */
  384. linkPrefix?: string;
  385. /** 为列表添加标记,以便[自定义列表样式](https://github.com/Vanessa219/vditor/issues/390) 默认值:false */
  386. listStyle?: boolean;
  387. /** 支持 mark 标记 */
  388. mark?: boolean;
  389. }
  390. /** @link https://ld246.com/article/1549638745630#options-preview */
  391. interface IPreview {
  392. /** 预览 debounce 毫秒间隔。默认值: 1000 */
  393. delay?: number;
  394. /** 预览区域最大宽度。默认值: 768 */
  395. maxWidth?: number;
  396. /** 显示模式。默认值: 'both' */
  397. mode?: "both" | "editor";
  398. /** md 解析请求 */
  399. url?: string;
  400. /** @link https://ld246.com/article/1549638745630#options-preview-hljs */
  401. hljs?: IHljs;
  402. /** @link https://ld246.com/article/1549638745630#options-preview-math */
  403. math?: IMath;
  404. /** @link https://ld246.com/article/1549638745630#options-preview-markdown */
  405. markdown?: IMarkdownConfig;
  406. /** @link https://ld246.com/article/1549638745630#options-preview-theme */
  407. theme?: IPreviewTheme;
  408. /** @link https://ld246.com/article/1549638745630#options-preview-actions */
  409. actions?: Array<IPreviewAction | IPreviewActionCustom>;
  410. /** 预览回调 */
  411. parse?(element: HTMLElement): void;
  412. /** 渲染之前回调 */
  413. transform?(html: string): string;
  414. }
  415. type IPreviewAction = "desktop" | "tablet" | "mobile" | "mp-wechat" | "zhihu";
  416. interface IPreviewActionCustom {
  417. /** 键名 */
  418. key: string;
  419. /** 按钮文本 */
  420. text: string;
  421. /** 按钮 className 值 */
  422. className?: string;
  423. /** 按钮提示信息 */
  424. tooltip?: string;
  425. /** 点击回调 */
  426. click: (key: string) => void;
  427. }
  428. interface IPreviewOptions {
  429. mode: "dark" | "light";
  430. customEmoji?: IObject;
  431. lang?: (keyof II18n);
  432. i18n?: ITips;
  433. lazyLoadImage?: string;
  434. emojiPath?: string;
  435. hljs?: IHljs;
  436. speech?: {
  437. enable?: boolean,
  438. };
  439. anchor?: number; // 0: no render, 1: render left, 2: render right
  440. math?: IMath;
  441. cdn?: string;
  442. markdown?: IMarkdownConfig;
  443. renderers?: ILuteRender;
  444. theme?: IPreviewTheme;
  445. icon?: "ant" | "material" | undefined;
  446. transform?(html: string): string;
  447. after?(): void;
  448. }
  449. interface IHintData {
  450. html: string;
  451. value: string;
  452. }
  453. interface IHintExtend {
  454. key: string;
  455. hint?(value: string): IHintData[] | Promise<IHintData[]>;
  456. }
  457. /** @link https://ld246.com/article/1549638745630#options-hint */
  458. interface IHint {
  459. /** 提示内容是否进行 md 解析 */
  460. parse?: boolean;
  461. /** 常用表情提示 HTML */
  462. emojiTail?: string;
  463. /** 提示 debounce 毫秒间隔。默认值: 200 */
  464. delay?: number;
  465. /** 默认表情,可从 [lute/emoji_map](https://github.com/88250/lute/blob/master/parse/emoji_map.go#L32) 中选取,也可自定义 */
  466. emoji?: IObject;
  467. /** 表情图片地址。默认值: 'https://unpkg.com/vditor@${VDITOR_VERSION}/dist/images/emoji' */
  468. emojiPath?: string;
  469. extend?: IHintExtend[];
  470. }
  471. interface IResize {
  472. position?: string;
  473. enable?: boolean;
  474. after?(height: number): void;
  475. }
  476. /** @link https://ld246.com/article/1549638745630#options */
  477. interface IOptions {
  478. /** RTL */
  479. rtl?: boolean;
  480. /** 历史记录间隔 */
  481. undoDelay?: number;
  482. /** 内部调试时使用 */
  483. _lutePath?: string;
  484. /** 编辑器初始化值。默认值: '' */
  485. value?: string;
  486. /** 是否显示日志。默认值: false */
  487. debugger?: boolean;
  488. /** 是否启用打字机模式。默认值: false */
  489. typewriterMode?: boolean;
  490. /** 编辑器总高度。默认值: 'auto' */
  491. height?: number | string;
  492. /** 编辑器最小高度 */
  493. minHeight?: number;
  494. /** 编辑器总宽度,支持 %。默认值: 'auto' */
  495. width?: number | string;
  496. /** 输入区域为空时的提示。默认值: '' */
  497. placeholder?: string;
  498. /** 多语言。默认值: 'zh_CN' */
  499. lang?: (keyof II18n);
  500. /** 国际化, 自定义语言。优先级低于lang */
  501. i18n?: ITips;
  502. /** @link https://ld246.com/article/1549638745630#options-fullscreen */
  503. fullscreen?: {
  504. index: number;
  505. };
  506. /** @link https://ld246.com/article/1549638745630#options-toolbar */
  507. toolbar?: Array<string | IMenuItem>;
  508. /** @link https://ld246.com/article/1549638745630#options-resize */
  509. resize?: IResize;
  510. /** @link https://ld246.com/article/1549638745630#options-counter */
  511. counter?: {
  512. enable: boolean;
  513. max?: number;
  514. type?: "markdown" | "text";
  515. after?(length: number, counter: {
  516. enable: boolean;
  517. max?: number;
  518. type?: "markdown" | "text"
  519. }): void
  520. };
  521. /** @link https://ld246.com/article/1549638745630#options-cache */
  522. cache?: {
  523. id?: string;
  524. enable?: boolean;
  525. after?(markdown: string): void;
  526. };
  527. /** 编辑模式。默认值: 'wysiwyg' */
  528. mode?: "wysiwyg" | "sv" | "ir";
  529. /** @link https://ld246.com/article/1549638745630#options-preview */
  530. preview?: IPreview;
  531. /** @link https://ld246.com/article/1549638745630#options-hint */
  532. hint?: IHint;
  533. /** @link https://ld246.com/article/1549638745630#options-toolbarConfig */
  534. toolbarConfig?: {
  535. hide?: boolean,
  536. pin?: boolean,
  537. };
  538. /** 评论 */
  539. comment?: {
  540. enable: boolean
  541. add?(id: string, text: string, commentsData: ICommentsData[]): void
  542. remove?(ids: string[]): void;
  543. scroll?(top: number): void;
  544. adjustTop?(commentsData: ICommentsData[]): void;
  545. };
  546. /** 主题。默认值: 'classic' */
  547. theme?: "classic" | "dark";
  548. /** 图标。默认值: 'ant' */
  549. icon?: "ant" | "material";
  550. /** @link https://ld246.com/article/1549638745630#options-upload */
  551. upload?: IUpload;
  552. /** @link https://ld246.com/article/1549638745630#options-classes */
  553. classes?: IClasses;
  554. /** 配置自建 CDN 地址。默认值: 'https://unpkg.com/vditor@${VDITOR_VERSION}' */
  555. cdn?: string;
  556. /** tab 键操作字符串,支持 \t 及任意字符串 */
  557. tab?: string;
  558. /** @link https://ld246.com/article/1549638745630#options-outline */
  559. outline?: {
  560. enable: boolean,
  561. position: "left" | "right",
  562. };
  563. /** 编辑器异步渲染完成后的回调方法 */
  564. after?(): void;
  565. /** 输入后触发 */
  566. input?(value: string): void;
  567. /** 聚焦后触发 */
  568. focus?(value: string): void;
  569. /** 失焦后触发 */
  570. blur?(value: string): void;
  571. /** `esc` 按下后触发 */
  572. esc?(value: string): void;
  573. /** `⌘/ctrl+enter` 按下后触发 */
  574. ctrlEnter?(value: string): void;
  575. /** 编辑器中选中文字后触发 */
  576. select?(value: string): void;
  577. }
  578. interface IEChart {
  579. setOption(option: any): void;
  580. resize(): void;
  581. }
  582. interface IVditor {
  583. element: HTMLElement;
  584. options: IOptions;
  585. originalInnerHTML: string;
  586. lute: Lute;
  587. currentMode: "sv" | "wysiwyg" | "ir";
  588. devtools?: {
  589. element: HTMLDivElement,
  590. renderEchart(vditor: IVditor): void,
  591. };
  592. outline: {
  593. element: HTMLElement,
  594. render(vditor: IVditor): string,
  595. toggle(vditor: IVditor, show?: boolean): void,
  596. };
  597. toolbar?: {
  598. elements?: { [key: string]: HTMLElement },
  599. element?: HTMLElement,
  600. };
  601. preview?: {
  602. element: HTMLElement
  603. render(vditor: IVditor, value?: string): void,
  604. };
  605. counter?: {
  606. element: HTMLElement
  607. render(vditor: IVditor, mdText?: string): void,
  608. };
  609. resize?: {
  610. element: HTMLElement,
  611. };
  612. hint: {
  613. timeId: number
  614. element: HTMLDivElement
  615. recentLanguage: string
  616. fillEmoji(element: HTMLElement, vditor: IVditor): void
  617. render(vditor: IVditor): void,
  618. genHTML(data: IHintData[], key: string, vditor: IVditor): void
  619. select(event: KeyboardEvent, vditor: IVditor): boolean,
  620. };
  621. tip: {
  622. element: HTMLElement
  623. show(text: string, time?: number): void
  624. hide(): void,
  625. };
  626. upload?: {
  627. element: HTMLElement
  628. isUploading: boolean
  629. range: Range,
  630. };
  631. undo?: {
  632. clearStack(vditor: IVditor): void,
  633. redo(vditor: IVditor): void
  634. undo(vditor: IVditor): void
  635. addToUndoStack(vditor: IVditor): void
  636. recordFirstPosition(vditor: IVditor, event: KeyboardEvent): void,
  637. resetIcon(vditor: IVditor): void,
  638. };
  639. wysiwyg?: {
  640. range: Range,
  641. element: HTMLPreElement,
  642. selectPopover: HTMLDivElement,
  643. popover: HTMLDivElement,
  644. afterRenderTimeoutId: number,
  645. hlToolbarTimeoutId: number,
  646. preventInput: boolean,
  647. composingLock: boolean,
  648. commentIds: string[]
  649. getComments(vditor: IVditor, getData?: boolean): ICommentsData[],
  650. triggerRemoveComment(vditor: IVditor): void,
  651. showComment(): void,
  652. hideComment(): void,
  653. unbindListener(): void,
  654. };
  655. ir?: {
  656. range: Range,
  657. element: HTMLPreElement,
  658. composingLock: boolean,
  659. preventInput: boolean,
  660. processTimeoutId: number,
  661. hlToolbarTimeoutId: number,
  662. };
  663. sv?: {
  664. range: Range,
  665. element: HTMLPreElement,
  666. processTimeoutId: number,
  667. hlToolbarTimeoutId: number,
  668. composingLock: boolean,
  669. preventInput: boolean,
  670. };
  671. }
  672. interface ICommentsData {
  673. id: string;
  674. top: number;
  675. }