index.d.ts 25 KB

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