index.d.ts 27 KB

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