diff --git a/dist/addons/cherry-code-block-mermaid-plugin.js b/dist/addons/cherry-code-block-mermaid-plugin.js index d69cd229..77170ede 100644 --- a/dist/addons/cherry-code-block-mermaid-plugin.js +++ b/dist/addons/cherry-code-block-mermaid-plugin.js @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:83db89a733ecf59476b8b5c629e3b30942371931c4cde47e3388339ac67e3d1b -size 44474 +oid sha256:7ed1a118a36ae4efbb69a49d343cdffc433f96353783dd86c59d7a80bddfc95b +size 44413 diff --git a/dist/addons/cherry-code-block-plantuml-plugin.js b/dist/addons/cherry-code-block-plantuml-plugin.js index 87efd084..9753521f 100644 --- a/dist/addons/cherry-code-block-plantuml-plugin.js +++ b/dist/addons/cherry-code-block-plantuml-plugin.js @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:47bbd3256d974105723d64faea3a42b033d75ef7533dc21e6a8f10d7b195e32d -size 48531 +oid sha256:dcd579c453d04b51ffa857109514e22c8d4a4353e3660bbcabfcdee9e3b1ea45 +size 48586 diff --git a/dist/cherry-markdown.core.common.js b/dist/cherry-markdown.core.common.js index 4b96f6fb..abd7228c 100644 --- a/dist/cherry-markdown.core.common.js +++ b/dist/cherry-markdown.core.common.js @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1dada3506ed45414033ffbcff4f8a9f391993a7d10b47b8c2029a671e80347fc -size 1575295 +oid sha256:d67ab021caac32f7960ad3f72a60cc38af3a74ce9bc104a6d0acf03b1f200329 +size 1575161 diff --git a/dist/cherry-markdown.core.js b/dist/cherry-markdown.core.js index a248dbe2..6d41441e 100644 --- a/dist/cherry-markdown.core.js +++ b/dist/cherry-markdown.core.js @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a6be1a2a6c73624994812e05e9ea8e71ac3a7cd9452e1e552b969d3170114945 -size 1575624 +oid sha256:d69facb980be99481812e0c01eac7e1ac387c72d900f827eff9a3c851dbea276 +size 1575490 diff --git a/dist/cherry-markdown.engine.core.common.js b/dist/cherry-markdown.engine.core.common.js index 319818cf..9fb4d4af 100644 --- a/dist/cherry-markdown.engine.core.common.js +++ b/dist/cherry-markdown.engine.core.common.js @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f90b8f5050f56c09373eaaef4634680e8a7aa10d11871680811b76a201a4dfb2 -size 364942 +oid sha256:d7c4907be0d12689c1152deb0111d943f374e2843b32daee162be1a5d805619f +size 364934 diff --git a/dist/cherry-markdown.engine.core.esm.js b/dist/cherry-markdown.engine.core.esm.js index f5cabb73..a310183c 100644 --- a/dist/cherry-markdown.engine.core.esm.js +++ b/dist/cherry-markdown.engine.core.esm.js @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:97919f34eafb43ba7d098f5ee55883d752c024ba6ae176ff1181cea180773749 -size 364820 +oid sha256:d060f788d726a3eabd6ad387c0717f96ff72c371d31c37333bba95288750a928 +size 364812 diff --git a/dist/cherry-markdown.engine.core.js b/dist/cherry-markdown.engine.core.js index e2b851f3..bf189413 100644 --- a/dist/cherry-markdown.engine.core.js +++ b/dist/cherry-markdown.engine.core.js @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6078ddd25d4315ff8a8e072b17400c889b82447998d102f583aea6ab7507eebe -size 365205 +oid sha256:7ba202100766f6e49527151f5850aeec0bc487e3fca4cc8cd59f751ad9ed9617 +size 365197 diff --git a/dist/cherry-markdown.esm.js b/dist/cherry-markdown.esm.js index 9cf53d06..865f074e 100644 --- a/dist/cherry-markdown.esm.js +++ b/dist/cherry-markdown.esm.js @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:77cc4efbabe8b31021e503ab70e4c5c39788eb95ca9873f8d8133f290cf4c84b -size 4334698 +oid sha256:a115227fd87c06323d79caf56dc4d834c53cb7998beb073e5d78588ddff56510 +size 4334559 diff --git a/dist/cherry-markdown.js b/dist/cherry-markdown.js index aad497b0..0ef84caf 100644 --- a/dist/cherry-markdown.js +++ b/dist/cherry-markdown.js @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d2aa14073ce86146bb08b4d658a61c22b636bfb11724992e3b1c42d77286465f -size 8428174 +oid sha256:651b7dfc7055cd5f8f8faeaebf67b5e4c916347e9a1b512ac90f067a292a208a +size 8430018 diff --git a/dist/cherry-markdown.js.map b/dist/cherry-markdown.js.map index 1f38f1da..a778137b 100644 --- a/dist/cherry-markdown.js.map +++ b/dist/cherry-markdown.js.map @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c7bca8628a77bf81c8e7cc1ed4ad6ac8f6c1d35496f7591099c93559ef7c2cbe -size 19749989 +oid sha256:57c4497d26f8661ee97c976028694caaefa9c4338223999b7406950c92214ed8 +size 19751414 diff --git a/dist/cherry-markdown.min.js b/dist/cherry-markdown.min.js index a1ceb9c3..2cb8d23a 100644 --- a/dist/cherry-markdown.min.js +++ b/dist/cherry-markdown.min.js @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e08874052b94b69b97bc6f8a9f778e9ea6d93df5c1c45ee5933486222df32b10 -size 4335066 +oid sha256:cfce64297bca74fc6c6ad30fea5b5e81551c35dfeecde1f31df7fca08d841e22 +size 4334929 diff --git a/dist/fonts/ch-icon.eot b/dist/fonts/ch-icon.eot index c4f04873..6179920f 100644 --- a/dist/fonts/ch-icon.eot +++ b/dist/fonts/ch-icon.eot @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:17f56ccad170950d44a2f531ba466f72d32a7d291e7754f97a8ec2042351f71b +oid sha256:3a26eaeae7edd3afd7f4ebcb6528512773464b8f46442f73cefb7d4365f248b2 size 20200 diff --git a/dist/fonts/ch-icon.ttf b/dist/fonts/ch-icon.ttf index b057c5ee..de45f865 100644 --- a/dist/fonts/ch-icon.ttf +++ b/dist/fonts/ch-icon.ttf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6fcea7ad3f5c4b91311e796e2e66afec6dad8d782bfa0b3618973b73a2202b10 +oid sha256:21210da09e5b3edfb425f9b3c9bceac6ac8aa8ddb9a1aa281b79f972da68c7fd size 20036 diff --git a/dist/fonts/ch-icon.woff b/dist/fonts/ch-icon.woff index 6ffca72c..023b9f23 100644 --- a/dist/fonts/ch-icon.woff +++ b/dist/fonts/ch-icon.woff @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a10b446d67efa2480c08287027a22655a401f0435c9225d97934f91dcb10613d +oid sha256:9123623ddfab6a7af91ff1da5b06d3869d6e7be65df0f30c758345ed1cdb1131 size 11652 diff --git a/dist/fonts/ch-icon.woff2 b/dist/fonts/ch-icon.woff2 index 6fa635bf..d796b26f 100644 --- a/dist/fonts/ch-icon.woff2 +++ b/dist/fonts/ch-icon.woff2 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:67696a1b9be48f89eed484e3566afa7e66dbf0eb145aa33b8ba66a6919d1bec7 -size 9912 +oid sha256:9b6ffab7ae61665974c7fccf91d10e8b280703119f1a73d2c7a27a5467a3cfdf +size 9948 diff --git a/src/Cherry.js b/src/Cherry.js index c93408a2..112c9db1 100644 --- a/src/Cherry.js +++ b/src/Cherry.js @@ -191,10 +191,8 @@ export default class Cherry extends CherryStatic { /** * 切换编辑模式 - * @param {'edit&preview'|'editOnly'|'previewOnly'} model 模式类型 + * @param {'edit&preview'|'editOnly'|'previewOnly'} [model=edit&preview] 模式类型 * 一般纯预览模式和纯编辑模式适合在屏幕较小的终端使用,比如手机移动端 - * - * @returns */ switchModel(model = 'edit&preview') { switch (model) { @@ -249,15 +247,15 @@ export default class Cherry extends CherryStatic { /** * 获取编辑区内的markdown源码内容 - * @returns markdown源码内容 + * @returns {string} markdown源码内容 */ getMarkdown() { return this.getValue(); } /** - * 获取CodeMirror实例 - * @returns CodeMirror实例 + * 获取CodeMirror 实例 + * @returns { CodeMirror.Editor } CodeMirror实例 */ getCodeMirror() { return this.editor.editor; @@ -265,20 +263,28 @@ export default class Cherry extends CherryStatic { /** * 获取预览区内的html内容 - * @param {boolean} wrapTheme 是否在外层包裹主题class - * @returns html内容 + * @param {boolean} [wrapTheme=true] 是否在外层包裹主题class + * @returns {string} html内容 */ getHtml(wrapTheme = true) { return this.previewer.getValue(wrapTheme); } - + /** + * 获取Previewer 预览实例 + * @returns {Previewer} Previewer 预览实例 + */ getPreviewer() { return this.previewer; } /** + * @typedef {{ + * level: number; + * id: string; + * text: string; + * }[]} HeaderList * 获取目录,目录由head1~6组成 - * @returns 标题head数组 + * @returns {HeaderList} 标题head数组 */ getToc() { const str = this.getHtml(); @@ -296,7 +302,6 @@ export default class Cherry extends CherryStatic { * 覆盖编辑区的内容 * @param {string} content markdown内容 * @param {boolean} keepCursor 是否保持光标位置 - * @returns */ setValue(content, keepCursor = false) { if (keepCursor === false) { @@ -306,10 +311,9 @@ export default class Cherry extends CherryStatic { const old = this.getValue(); const pos = codemirror.getDoc().indexFromPos(codemirror.getCursor()); const newPos = getPosBydiffs(pos, old, content); - const ret = codemirror.setValue(content); + codemirror.setValue(content); const cursor = codemirror.getDoc().posFromIndex(newPos); codemirror.setCursor(cursor); - return ret; } /** @@ -318,15 +322,13 @@ export default class Cherry extends CherryStatic { * @param {boolean} [isSelect=false] 是否选中刚插入的内容 * @param {[number, number]|false} [anchor=false] [x,y] 代表x+1行,y+1字符偏移量,默认false 会从光标处插入 * @param {boolean} [focus=true] 保持编辑器处于focus状态 - * @returns */ insert(content, isSelect = false, anchor = false, focus = true) { if (anchor) { this.editor.editor.setSelection({ line: anchor[0], ch: anchor[1] }, { line: anchor[0], ch: anchor[1] }); } - const ret = this.editor.editor.replaceSelection(content, isSelect ? 'around' : 'end'); + this.editor.editor.replaceSelection(content, isSelect ? 'around' : 'end'); focus && this.editor.editor.focus(); - return ret; } /** @@ -357,8 +359,7 @@ export default class Cherry extends CherryStatic { /** * 覆盖编辑区的内容 * @param {string} content markdown内容 - * @param {boolean} keepCursor 是否保持光标位置 - * @returns + * @param {boolean} [keepCursor=false] 是否保持光标位置 */ setMarkdown(content, keepCursor = false) { return this.setValue(content, keepCursor); @@ -628,7 +629,7 @@ export default class Cherry extends CherryStatic { * @public * @param {'pdf' | 'img' | 'markdown' | 'html'} [type='pdf'] * 'pdf':导出成pdf文件; 'img':导出成png图片; 'markdown':导出成markdown文件; 'html':导出成html文件; - * @param {string} [fileName] 导出文件名 + * @param {string} [fileName] 导出文件名(默认为当前第一行内容|'cherry-export') */ export(type = 'pdf', fileName = '') { this.previewer.export(type, fileName); diff --git a/src/Engine.js b/src/Engine.js index df7b9597..7fa08b22 100644 --- a/src/Engine.js +++ b/src/Engine.js @@ -192,6 +192,10 @@ export default class Engine { return this.$fireHookAction(md, 'paragraph', 'makeHtml', this.$dealSentenceByCache.bind(this)); } + /** + * @param {string} md md字符串 + * @returns {string} 获取html + */ makeHtml(md) { let $md = this.$beforeMakeHtml(md); $md = this.$dealParagraph($md); @@ -205,6 +209,10 @@ export default class Engine { // UrlCache.clear(); } + /** + * @param {string} html html字符串 + * @returns {string} 获取markdown + */ makeMarkdown(html) { return htmlParser.run(html); } diff --git a/src/toolbars/Toolbar.js b/src/toolbars/Toolbar.js index 45e65837..53075997 100644 --- a/src/toolbars/Toolbar.js +++ b/src/toolbars/Toolbar.js @@ -19,9 +19,51 @@ import Event from '@/Event'; import { createElement } from '@/utils/dom'; import Logger from '@/Logger'; +/** + * @typedef {()=>void} Bold 向cherry编辑器中插入粗体语法 + * @typedef {()=>void} Italic 向cherry编辑器中插入斜体语法 + * @typedef {(level:1|2|3|4|5|'1'|'2'|'3'|'4'|'5')=>void} Header 向cherry编辑器中插入标题语法 + * - level 标题等级 1~5 + * @typedef {()=>void} Strikethrough 向cherry编辑器中插入删除线语法 + * @typedef {(type:'ol'|'ul'|'checklist'|1|2|3|'1'|'2'|'3')=>void} List 向cherry编辑器中插入有序、无序列表或者checklist语法 + * - ol(1)有序 + * - ul(2)无序列表 + * - checklist(3)checklist + * @typedef {(insert:'hr'|'br'|'code'|'formula'|'checklist'|'toc'|'link'|'image'|'video'|'audio'|'normal-table'|'normal-table-row*col')=>void} Insert 向cherry编辑器中插入特定语法 + * - hr 水平分割线 + * - br 换行 + * - code 代码块 + * - formula 公式 + * - checklist 检查项 + * - toc 目录 + * - link 链接 + * - image 图片 + * - video 视频 + * - audio 音频 + * - normal-table 插入3行5列的表格 + * - normal-table-row*col 如normal-table-2*4插入2行(包含表头是3行)4列的表格 + * @typedef {(type:'1'|'2'|'3'|'4'|'5'|'6'|1|2|3|4|5|6|'flow'|'sequence'|'state'|'class'|'pie'|'gantt')=>void} Graph 向cherry编辑器中插入画图语法 + * - flow(1) 流程图 + * - sequence(2) 时序图 + * - state(3)状态图 + * - class(4)类图 + * - pie(5)饼图 + * - gantt(6)甘特图 + */ + export default class Toolbar { /** - * @type {Record} 外部获取 toolbarHandler + * @typedef {{ + * bold?:Bold; + * italic?:Italic; + * header?:Header; + * strikethrough?:Strikethrough; + * list?:List; + * insert?:Insert; + * graph?:Graph; + * [key:string]:any; + * }} ToolbarHandlers + * @type ToolbarHandlers 外部获取 toolbarHandlers 的部分功能 */ toolbarHandlers = {}; diff --git a/src/toolbars/hooks/Graph.js b/src/toolbars/hooks/Graph.js index bf1ad196..3e56bb40 100644 --- a/src/toolbars/hooks/Graph.js +++ b/src/toolbars/hooks/Graph.js @@ -143,12 +143,12 @@ export default class Graph extends MenuBase { /** * 响应点击事件 * @param {string} selection 被用户选中的文本内容,本函数不处理选中的内容,会直接清空用户选中的内容 - * @param {string} shortKey 快捷键参数 + * @param {'1'|'2'|'3'|'4'|'5'|'6'|1|2|3|4|5|6|'flow'|'sequence'|'state'|'class'|'pie'|'gantt'|''} shortKey 快捷键参数 * @returns {string} 回填到编辑器光标位置/选中文本区域的内容 */ onClick(selection, shortKey = '') { const shortcut = `${shortKey}`; - const shortcutKeyMap = [, 'flow', 'sequence', 'state', 'class', 'pie', 'gantt']; + const shortcutKeyMap = [null, 'flow', 'sequence', 'state', 'class', 'pie', 'gantt']; const selectedExample = shortcutKeyMap[+shortcut]; if (!shortcutKeyMap[+shortcut]) { return; diff --git a/src/toolbars/hooks/List.js b/src/toolbars/hooks/List.js index f8dbd36d..c4e89c4a 100644 --- a/src/toolbars/hooks/List.js +++ b/src/toolbars/hooks/List.js @@ -37,10 +37,13 @@ export default class List extends MenuBase { /** * 响应点击事件 * @param {string} selection 编辑区选中的文本内容 - * @param {string} shortKey 快捷键:ol 有序列表,ul 无序列表,checklist 检查项 + * @param {'ol'|'ul'|'checklist'|1|2|3|'1'|'2'|'3'|''} [shortKey] 快捷键:ol(1)有序列表,ul(2)无序列表,checklist(3) 检查项 * @returns 对应markdown的源码 */ onClick(selection, shortKey = '') { + /** + * @type {['', 'ol', 'ul', 'checklist']} + */ const listType = [null, 'ol', 'ul', 'checklist']; // 下标1, 2, 3生效 const $selection = getSelection(this.editor.editor, selection, 'line', true); const [before] = $selection.match(/^\n*/);