index.d.ts 26 KB

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