1
0

index.d.ts 23 KB

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