index.d.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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. /** 预览回调 */
  427. parse?(element: HTMLElement): void;
  428. /** 渲染之前回调 */
  429. transform?(html: string): string;
  430. }
  431. type IPreviewAction = "desktop" | "tablet" | "mobile" | "mp-wechat" | "zhihu";
  432. interface IPreviewActionCustom {
  433. /** 键名 */
  434. key: string;
  435. /** 按钮文本 */
  436. text: string;
  437. /** 按钮 className 值 */
  438. className?: string;
  439. /** 按钮提示信息 */
  440. tooltip?: string;
  441. /** 点击回调 */
  442. click: (key: string) => void;
  443. }
  444. interface IPreviewOptions {
  445. mode: "dark" | "light";
  446. customEmoji?: IObject;
  447. lang?: (keyof II18n);
  448. i18n?: ITips;
  449. lazyLoadImage?: string;
  450. emojiPath?: string;
  451. hljs?: IHljs;
  452. speech?: {
  453. enable?: boolean,
  454. };
  455. anchor?: number; // 0: no render, 1: render left, 2: render right
  456. math?: IMath;
  457. cdn?: string;
  458. markdown?: IMarkdownConfig;
  459. renderers?: ILuteRender;
  460. theme?: IPreviewTheme;
  461. icon?: "ant" | "material" | undefined;
  462. transform?(html: string): string;
  463. after?(): void;
  464. }
  465. interface IHintData {
  466. html: string;
  467. value: string;
  468. }
  469. interface IHintExtend {
  470. key: string;
  471. hint?(value: string): IHintData[] | Promise<IHintData[]>;
  472. }
  473. /** @link https://ld246.com/article/1549638745630#options-hint */
  474. interface IHint {
  475. /** 提示内容是否进行 md 解析 */
  476. parse?: boolean;
  477. /** 常用表情提示 HTML */
  478. emojiTail?: string;
  479. /** 提示 debounce 毫秒间隔。默认值: 200 */
  480. delay?: number;
  481. /** 默认表情,可从 [lute/emoji_map](https://github.com/88250/lute/blob/master/parse/emoji_map.go#L32) 中选取,也可自定义 */
  482. emoji?: IObject;
  483. /** 表情图片地址。默认值: 'https://unpkg.com/vditor@${VDITOR_VERSION}/dist/images/emoji' */
  484. emojiPath?: string;
  485. extend?: IHintExtend[];
  486. }
  487. /** @link https://ld246.com/article/1549638745630#options-toolbarConfig */
  488. interface IToolbarConfig {
  489. /** 是否隐藏工具栏。默认值: false */
  490. hide?: boolean;
  491. /** 是否固定工具栏。默认值: false */
  492. pin?: boolean;
  493. }
  494. /** @link https://ld246.com/article/1549638745630#options-comment */
  495. interface IComment {
  496. /** 是否启用评论模式。默认值: false */
  497. enable: boolean;
  498. /** 添加评论回调 */
  499. add?(id: string, text: string, commentsData: ICommentsData[]): void;
  500. /** 删除评论回调 */
  501. remove?(ids: string[]): void;
  502. /** 滚动回调 */
  503. scroll?(top: number): void;
  504. /** 文档修改时,适配评论高度 */
  505. adjustTop?(commentsData: ICommentsData[]): void;
  506. }
  507. /** @link https://ld246.com/article/1549638745630#options-outline */
  508. interface IOutline {
  509. /** 初始化是否展现大纲。默认值: false */
  510. enable: boolean;
  511. /** 大纲位置:'left', 'right'。默认值: 'left' */
  512. position: "left" | "right";
  513. }
  514. interface IResize {
  515. position?: string;
  516. enable?: boolean;
  517. after?(height: number): void;
  518. }
  519. /** @link https://ld246.com/article/1549638745630#options */
  520. interface IOptions {
  521. /** RTL */
  522. rtl?: boolean;
  523. /** 历史记录间隔 */
  524. undoDelay?: number;
  525. /** 内部调试时使用 */
  526. _lutePath?: string;
  527. /** 编辑器初始化值。默认值: '' */
  528. value?: string;
  529. /** 是否显示日志。默认值: false */
  530. debugger?: boolean;
  531. /** 是否启用打字机模式。默认值: false */
  532. typewriterMode?: boolean;
  533. /** 编辑器总高度。默认值: 'auto' */
  534. height?: number | string;
  535. /** 编辑器最小高度 */
  536. minHeight?: number;
  537. /** 编辑器总宽度,支持 %。默认值: 'auto' */
  538. width?: number | string;
  539. /** 输入区域为空时的提示。默认值: '' */
  540. placeholder?: string;
  541. /** 多语言。默认值: 'zh_CN' */
  542. lang?: (keyof II18n);
  543. /** 国际化, 自定义语言。优先级低于lang */
  544. i18n?: ITips;
  545. /** @link https://ld246.com/article/1549638745630#options-fullscreen */
  546. fullscreen?: {
  547. /** 全屏层级。默认值: 90 */
  548. index: number;
  549. };
  550. /** @link https://ld246.com/article/1549638745630#options-toolbar */
  551. toolbar?: Array<string | IMenuItem>;
  552. /** @link https://ld246.com/article/1549638745630#options-resize */
  553. resize?: IResize;
  554. /** @link https://ld246.com/article/1549638745630#options-counter */
  555. counter?: {
  556. /** 是否启用计数器。默认值: false */
  557. enable: boolean;
  558. /** 允许输入的最大值 */
  559. max?: number;
  560. /** 统计类型。默认值: 'markdown' */
  561. type?: "markdown" | "text";
  562. /** 字数统计回调。 */
  563. after?(length: number, counter: {
  564. /** 是否启用计数器。默认值: false */
  565. enable: boolean;
  566. /** 允许输入的最大值 */
  567. max?: number;
  568. /** 统计类型。默认值: 'markdown' */
  569. type?: "markdown" | "text"
  570. }): void
  571. };
  572. /** @link https://ld246.com/article/1549638745630#options-cache */
  573. cache?: {
  574. /** 缓存 key,第一个参数为元素且启用缓存时必填 */
  575. id?: string;
  576. /** 是否使用 localStorage 进行缓存。默认值: true */
  577. enable?: boolean;
  578. /** 缓存后的回调 */
  579. after?(markdown: string): void;
  580. };
  581. /** 编辑模式。默认值: 'wysiwyg'
  582. *
  583. * wysiwyg: 所见即所得
  584. *
  585. * ir: 即时渲染
  586. *
  587. * sv: 分屏预览
  588. */
  589. mode?: "wysiwyg" | "sv" | "ir";
  590. /** @link https://ld246.com/article/1549638745630#options-preview */
  591. preview?: IPreview;
  592. /** @link https://ld246.com/article/1549638745630#options-link */
  593. link?: {
  594. /** 是否打开链接地址。默认值: true */
  595. isOpen?: boolean;
  596. /** 点击链接事件 */
  597. click?: (bom: Element) => void;
  598. },
  599. /** @link https://ld246.com/article/1549638745630#options-image */
  600. image?: {
  601. /** 是否预览图片。默认值: true */
  602. isPreview?: boolean;
  603. /** 图片预览处理 */
  604. preview?: (bom: Element) => void;
  605. },
  606. /** @link https://ld246.com/article/1549638745630#options-hint */
  607. hint?: IHint;
  608. /** @link https://ld246.com/article/1549638745630#options-toolbarConfig */
  609. toolbarConfig?: IToolbarConfig;
  610. /** 评论
  611. * @link https://ld246.com/article/1549638745630#options-comment
  612. */
  613. comment?: IComment;
  614. /** 主题。默认值: 'classic' */
  615. theme?: "classic" | "dark";
  616. /** 图标。默认值: 'ant' */
  617. icon?: "ant" | "material";
  618. /** @link https://ld246.com/article/1549638745630#options-upload */
  619. upload?: IUpload;
  620. /** @link https://ld246.com/article/1549638745630#options-classes */
  621. classes?: IClasses;
  622. /** 配置自建 CDN 地址。默认值: 'https://unpkg.com/vditor@${VDITOR_VERSION}' */
  623. cdn?: string;
  624. /** tab 键操作字符串,支持 \t 及任意字符串 */
  625. tab?: string;
  626. /** @link https://ld246.com/article/1549638745630#options-outline */
  627. outline?: IOutline;
  628. customRenders?: {
  629. language: string,
  630. render: (element: HTMLElement, vditor: IVditor) => void
  631. }[],
  632. /** 编辑器异步渲染完成后的回调方法 */
  633. after?(): void;
  634. /** 输入后触发 */
  635. input?(value: string): void;
  636. /** 聚焦后触发 */
  637. focus?(value: string): void;
  638. /** 失焦后触发 */
  639. blur?(value: string): void;
  640. /** 按下键盘触发 */
  641. keydown?(event: KeyboardEvent): void;
  642. /** `esc` 按下后触发 */
  643. esc?(value: string): void;
  644. /** `⌘/ctrl+enter` 按下后触发 */
  645. ctrlEnter?(value: string): void;
  646. /** 编辑器中选中文字后触发 */
  647. select?(value: string): void;
  648. }
  649. interface IEChart {
  650. setOption(option: any): void;
  651. resize(): void;
  652. }
  653. interface IVditor {
  654. element: HTMLElement;
  655. options: IOptions;
  656. originalInnerHTML: string;
  657. lute: Lute;
  658. currentMode: "sv" | "wysiwyg" | "ir";
  659. devtools?: {
  660. element: HTMLDivElement,
  661. renderEchart(vditor: IVditor): void,
  662. };
  663. outline: {
  664. element: HTMLElement,
  665. render(vditor: IVditor): string,
  666. toggle(vditor: IVditor, show?: boolean, focus?: boolean): void,
  667. };
  668. toolbar?: {
  669. elements?: { [key: string]: HTMLElement },
  670. element?: HTMLElement,
  671. };
  672. preview?: {
  673. element: HTMLElement,
  674. previewElement: HTMLElement,
  675. render(vditor: IVditor, value?: string): void,
  676. };
  677. counter?: {
  678. element: HTMLElement
  679. render(vditor: IVditor, mdText?: string): void,
  680. };
  681. resize?: {
  682. element: HTMLElement,
  683. };
  684. hint: {
  685. timeId: number
  686. element: HTMLDivElement
  687. recentLanguage: string
  688. fillEmoji(element: HTMLElement, vditor: IVditor): void
  689. render(vditor: IVditor): void,
  690. genHTML(data: IHintData[], key: string, vditor: IVditor): void
  691. select(event: KeyboardEvent, vditor: IVditor): boolean,
  692. };
  693. tip: {
  694. element: HTMLElement
  695. show(text: string, time?: number): void
  696. hide(): void,
  697. };
  698. upload?: {
  699. element: HTMLElement
  700. isUploading: boolean
  701. range: Range,
  702. };
  703. undo?: {
  704. clearStack(vditor: IVditor): void,
  705. redo(vditor: IVditor): void
  706. undo(vditor: IVditor): void
  707. addToUndoStack(vditor: IVditor): void
  708. recordFirstPosition(vditor: IVditor, event: KeyboardEvent): void,
  709. resetIcon(vditor: IVditor): void,
  710. };
  711. wysiwyg?: {
  712. range: Range,
  713. element: HTMLPreElement,
  714. selectPopover: HTMLDivElement,
  715. popover: HTMLDivElement,
  716. afterRenderTimeoutId: number,
  717. hlToolbarTimeoutId: number,
  718. preventInput: boolean,
  719. composingLock: boolean,
  720. commentIds: string[]
  721. getComments(vditor: IVditor, getData?: boolean): ICommentsData[],
  722. triggerRemoveComment(vditor: IVditor): void,
  723. showComment(): void,
  724. hideComment(): void,
  725. unbindListener(): void,
  726. };
  727. ir?: {
  728. range: Range,
  729. element: HTMLPreElement,
  730. composingLock: boolean,
  731. preventInput: boolean,
  732. processTimeoutId: number,
  733. hlToolbarTimeoutId: number,
  734. };
  735. sv?: {
  736. range: Range,
  737. element: HTMLPreElement,
  738. processTimeoutId: number,
  739. hlToolbarTimeoutId: number,
  740. composingLock: boolean,
  741. preventInput: boolean,
  742. };
  743. }
  744. interface ICommentsData {
  745. id: string;
  746. top: number;
  747. }