@cherry-markdown/cherry-markdown-dev 0.9.0-dev.202504110650.834443a → 0.9.0-dev.202504160300.d23d141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/addons/advance/cherry-table-echarts-plugin.js +1 -1
- package/dist/addons/cherry-code-block-mermaid-plugin.js +1 -1
- package/dist/cherry-markdown.core.common.js +1 -1
- package/dist/cherry-markdown.core.js +1 -1
- package/dist/cherry-markdown.engine.core.common.js +1 -1
- package/dist/cherry-markdown.engine.core.esm.js +1 -1
- package/dist/cherry-markdown.engine.core.js +1 -1
- package/dist/cherry-markdown.esm.js +1 -1
- package/dist/cherry-markdown.js +1 -1
- package/dist/cherry-markdown.min.js +1 -1
- package/dist/fonts/ch-icon.eot +0 -0
- package/dist/fonts/ch-icon.ttf +0 -0
- package/dist/fonts/ch-icon.woff +0 -0
- package/dist/fonts/ch-icon.woff2 +0 -0
- package/package.json +1 -3
- package/src/Cherry.config.js +0 -634
- package/src/Cherry.js +0 -1104
- package/src/CherryStatic.js +0 -70
- package/src/Editor.js +0 -748
- package/src/Engine.js +0 -402
- package/src/Event.js +0 -140
- package/src/Factory.js +0 -180
- package/src/Logger.js +0 -31
- package/src/Previewer.js +0 -1192
- package/src/Sanitizer.js +0 -4
- package/src/Sanitizer.node.js +0 -7
- package/src/UrlCache.js +0 -98
- package/src/addons/advance/cherry-table-echarts-plugin.js +0 -170
- package/src/addons/cherry-code-block-mermaid-plugin.js +0 -158
- package/src/addons/cherry-code-block-plantuml-plugin.js +0 -106
- package/src/core/HookCenter.js +0 -297
- package/src/core/HooksConfig.js +0 -105
- package/src/core/ParagraphBase.js +0 -332
- package/src/core/SentenceBase.js +0 -65
- package/src/core/SyntaxBase.js +0 -194
- package/src/core/hooks/AutoLink.js +0 -232
- package/src/core/hooks/BackgroundColor.js +0 -46
- package/src/core/hooks/Blockquote.js +0 -70
- package/src/core/hooks/Br.js +0 -85
- package/src/core/hooks/CodeBlock.js +0 -456
- package/src/core/hooks/Color.js +0 -46
- package/src/core/hooks/CommentReference.js +0 -96
- package/src/core/hooks/Detail.js +0 -108
- package/src/core/hooks/Emoji.config.js +0 -1825
- package/src/core/hooks/Emoji.js +0 -119
- package/src/core/hooks/Emphasis.js +0 -113
- package/src/core/hooks/Footnote.js +0 -125
- package/src/core/hooks/FrontMatter.js +0 -51
- package/src/core/hooks/Header.js +0 -234
- package/src/core/hooks/HighLight.js +0 -37
- package/src/core/hooks/Hr.js +0 -52
- package/src/core/hooks/HtmlBlock.js +0 -199
- package/src/core/hooks/Image.js +0 -174
- package/src/core/hooks/InlineCode.js +0 -48
- package/src/core/hooks/InlineMath.js +0 -108
- package/src/core/hooks/Link.js +0 -160
- package/src/core/hooks/List.js +0 -264
- package/src/core/hooks/MathBlock.js +0 -104
- package/src/core/hooks/Panel.js +0 -145
- package/src/core/hooks/Paragraph.js +0 -84
- package/src/core/hooks/Ruby.js +0 -34
- package/src/core/hooks/Size.js +0 -51
- package/src/core/hooks/Strikethrough.js +0 -54
- package/src/core/hooks/Sub.js +0 -47
- package/src/core/hooks/SuggestList.js +0 -333
- package/src/core/hooks/Suggester.js +0 -707
- package/src/core/hooks/Sup.js +0 -47
- package/src/core/hooks/Table.js +0 -275
- package/src/core/hooks/Toc.js +0 -292
- package/src/core/hooks/Transfer.js +0 -47
- package/src/core/hooks/Underline.js +0 -37
- package/src/index.core.js +0 -29
- package/src/index.engine.core.js +0 -68
- package/src/index.engine.js +0 -28
- package/src/index.js +0 -32
- package/src/libs/mermaidAPI.8.4.8.js +0 -1
- package/src/libs/mermaidAPI.8.5.2.js +0 -42
- package/src/libs/rawdeflate.js +0 -1663
- package/src/locales/en_US.js +0 -139
- package/src/locales/index.js +0 -25
- package/src/locales/ru_RU.js +0 -139
- package/src/locales/zh_CN.js +0 -142
- package/src/sass/base.scss +0 -26
- package/src/sass/bubble_formula.scss +0 -166
- package/src/sass/ch-icon.scss +0 -118
- package/src/sass/cherry.scss +0 -1116
- package/src/sass/components/bubble.scss +0 -173
- package/src/sass/components/shortcut_key_config.scss +0 -108
- package/src/sass/formula_utils_bubble.scss +0 -82
- package/src/sass/icon_template.scss +0 -24
- package/src/sass/icons/uEA03-list.svg +0 -19
- package/src/sass/icons/uEA04-check.svg +0 -14
- package/src/sass/icons/uEA09-square.svg +0 -10
- package/src/sass/icons/uEA0A-bold.svg +0 -20
- package/src/sass/icons/uEA0B-code.svg +0 -18
- package/src/sass/icons/uEA0C-color.svg +0 -13
- package/src/sass/icons/uEA0D-header.svg +0 -8
- package/src/sass/icons/uEA0E-image.svg +0 -15
- package/src/sass/icons/uEA0F-italic.svg +0 -8
- package/src/sass/icons/uEA10-link.svg +0 -16
- package/src/sass/icons/uEA11-ol.svg +0 -21
- package/src/sass/icons/uEA12-size.svg +0 -11
- package/src/sass/icons/uEA13-strike.svg +0 -16
- package/src/sass/icons/uEA14-table.svg +0 -12
- package/src/sass/icons/uEA15-ul.svg +0 -17
- package/src/sass/icons/uEA16-underline.svg +0 -13
- package/src/sass/icons/uEA17-word.svg +0 -16
- package/src/sass/icons/uEA18-blockquote.svg +0 -11
- package/src/sass/icons/uEA19-font.svg +0 -10
- package/src/sass/icons/uEA1F-insertClass.svg +0 -39
- package/src/sass/icons/uEA20-insertFlow.svg +0 -8
- package/src/sass/icons/uEA21-insertFormula.svg +0 -23
- package/src/sass/icons/uEA22-insertGantt.svg +0 -13
- package/src/sass/icons/uEA23-insertGraph.svg +0 -13
- package/src/sass/icons/uEA24-insertPie.svg +0 -19
- package/src/sass/icons/uEA25-insertSeq.svg +0 -20
- package/src/sass/icons/uEA26-insertState.svg +0 -35
- package/src/sass/icons/uEA27-line.svg +0 -11
- package/src/sass/icons/uEA28-preview.svg +0 -18
- package/src/sass/icons/uEA29-previewClose.svg +0 -24
- package/src/sass/icons/uEA2A-toc.svg +0 -24
- package/src/sass/icons/uEA2D-sub.svg +0 -15
- package/src/sass/icons/uEA2E-sup.svg +0 -15
- package/src/sass/icons/uEA2F-h1.svg +0 -16
- package/src/sass/icons/uEA30-h2.svg +0 -20
- package/src/sass/icons/uEA31-h3.svg +0 -23
- package/src/sass/icons/uEA32-h4.svg +0 -16
- package/src/sass/icons/uEA33-h5.svg +0 -20
- package/src/sass/icons/uEA34-h6.svg +0 -17
- package/src/sass/icons/uEA35-video.svg +0 -20
- package/src/sass/icons/uEA36-insert.svg +0 -25
- package/src/sass/icons/uEA37-little_table.svg +0 -30
- package/src/sass/icons/uEA38-pdf.svg +0 -27
- package/src/sass/icons/uEA39-checklist.svg +0 -22
- package/src/sass/icons/uEA40-close.svg +0 -12
- package/src/sass/icons/uEA41-fullscreen.svg +0 -81
- package/src/sass/icons/uEA42-minscreen.svg +0 -77
- package/src/sass/icons/uEA43-insertChart.svg +0 -23
- package/src/sass/icons/uEA44-question.svg +0 -25
- package/src/sass/icons/uEA45-settings.svg +0 -32
- package/src/sass/icons/uEA46-ok.svg +0 -7
- package/src/sass/icons/uEA47-br.svg +0 -22
- package/src/sass/icons/uEA48-normal.svg +0 -15
- package/src/sass/icons/uEA49-undo.svg +0 -19
- package/src/sass/icons/uEA50-redo.svg +0 -21
- package/src/sass/icons/uEA51-copy.svg +0 -6
- package/src/sass/icons/uEA52-phone.svg +0 -5
- package/src/sass/icons/uEA53-cherry-table-delete.svg +0 -17
- package/src/sass/icons/uEA54-cherry-table-insert-bottom.svg +0 -16
- package/src/sass/icons/uEA55-cherry-table-insert-left.svg +0 -15
- package/src/sass/icons/uEA56-cherry-table-insert-right.svg +0 -16
- package/src/sass/icons/uEA57-cherry-table-insert-top.svg +0 -16
- package/src/sass/icons/uEA58-sort-s.svg +0 -13
- package/src/sass/icons/uEA59-pinyin.svg +0 -1
- package/src/sass/icons/uEA5A-create.svg +0 -24
- package/src/sass/icons/uEA5B-download.svg +0 -34
- package/src/sass/icons/uEA5C-edit.svg +0 -3
- package/src/sass/icons/uEA5D-export.svg +0 -53
- package/src/sass/icons/uEA5E-folder-open.svg +0 -3
- package/src/sass/icons/uEA5F-folder.svg +0 -3
- package/src/sass/icons/uEA60-help.svg +0 -5
- package/src/sass/icons/uEA61-pen-fill.svg +0 -13
- package/src/sass/icons/uEA62-pen.svg +0 -3
- package/src/sass/icons/uEA64-tips.svg +0 -5
- package/src/sass/icons/uEA65-warn.svg +0 -5
- package/src/sass/icons/uEA66-mistake.svg +0 -4
- package/src/sass/icons/uEA67-success.svg +0 -4
- package/src/sass/icons/uEA68-danger.svg +0 -4
- package/src/sass/icons/uEA69-info.svg +0 -5
- package/src/sass/icons/uEA6A-primary.svg +0 -5
- package/src/sass/icons/uEA6B-warning.svg +0 -5
- package/src/sass/icons/uEA6C-justify.svg +0 -19
- package/src/sass/icons/uEA6D-justifyCenter.svg +0 -19
- package/src/sass/icons/uEA6E-justifyLeft.svg +0 -19
- package/src/sass/icons/uEA6F-justifyRight.svg +0 -19
- package/src/sass/icons/uEA70-chevronsLeft.svg +0 -1
- package/src/sass/icons/uEA71-chevronsRight.svg +0 -1
- package/src/sass/icons/uEA72-trendingUp.svg +0 -1
- package/src/sass/icons/uEA74-codeBlock.svg +0 -1
- package/src/sass/icons/uEA75-expand.svg +0 -3
- package/src/sass/icons/uEA76-unExpand.svg +0 -3
- package/src/sass/icons/uEA77-swap-vert.svg +0 -1
- package/src/sass/icons/uEA78-swap.svg +0 -1
- package/src/sass/icons/uEA79-keyboard.svg +0 -1
- package/src/sass/icons/uEA7A-command.svg +0 -1
- package/src/sass/icons/uEA7B-search.svg +0 -1
- package/src/sass/index.scss +0 -3
- package/src/sass/markdown.scss +0 -668
- package/src/sass/markdown_pure.scss +0 -9
- package/src/sass/prettyprint/prettyprint.scss +0 -118
- package/src/sass/previewer.scss +0 -179
- package/src/sass/print.scss +0 -13
- package/src/sass/prism/coy.scss +0 -220
- package/src/sass/prism/dark.scss +0 -132
- package/src/sass/prism/default.scss +0 -143
- package/src/sass/prism/funky.scss +0 -133
- package/src/sass/prism/okaidia.scss +0 -126
- package/src/sass/prism/one-dark.scss +0 -440
- package/src/sass/prism/one-light.scss +0 -428
- package/src/sass/prism/solarized-light.scss +0 -153
- package/src/sass/prism/tomorrow-night.scss +0 -125
- package/src/sass/prism/twilight.scss +0 -202
- package/src/sass/prism/vs-dark.scss +0 -275
- package/src/sass/prism/vs-light.scss +0 -168
- package/src/sass/themes/blue.scss +0 -411
- package/src/sass/themes/dark.scss +0 -517
- package/src/sass/themes/default.scss +0 -255
- package/src/sass/themes/green.scss +0 -395
- package/src/sass/themes/light.scss +0 -368
- package/src/sass/themes/red.scss +0 -397
- package/src/sass/themes/violet.scss +0 -410
- package/src/sass/variable.scss +0 -84
- package/src/toolbars/Bubble.js +0 -234
- package/src/toolbars/BubbleFormula.js +0 -298
- package/src/toolbars/BubbleTable.js +0 -147
- package/src/toolbars/FloatMenu.js +0 -131
- package/src/toolbars/HiddenToolbar.js +0 -36
- package/src/toolbars/HookCenter.js +0 -231
- package/src/toolbars/MenuBase.js +0 -569
- package/src/toolbars/PreviewerBubble.js +0 -608
- package/src/toolbars/ShortcutKeyConfigPanel.js +0 -345
- package/src/toolbars/Sidebar.js +0 -36
- package/src/toolbars/Toc.js +0 -242
- package/src/toolbars/Toolbar.js +0 -449
- package/src/toolbars/ToolbarRight.js +0 -37
- package/src/toolbars/hooks/Audio.js +0 -79
- package/src/toolbars/hooks/BarTable.js +0 -41
- package/src/toolbars/hooks/Bold.js +0 -73
- package/src/toolbars/hooks/Br.js +0 -34
- package/src/toolbars/hooks/ChangeLocale.js +0 -62
- package/src/toolbars/hooks/ChatGpt.js +0 -182
- package/src/toolbars/hooks/CheckList.js +0 -41
- package/src/toolbars/hooks/Code.js +0 -49
- package/src/toolbars/hooks/CodeTheme.js +0 -66
- package/src/toolbars/hooks/Color.js +0 -298
- package/src/toolbars/hooks/Copy.js +0 -141
- package/src/toolbars/hooks/Detail.js +0 -69
- package/src/toolbars/hooks/DrawIo.js +0 -57
- package/src/toolbars/hooks/Export.js +0 -49
- package/src/toolbars/hooks/File.js +0 -79
- package/src/toolbars/hooks/Formula.js +0 -69
- package/src/toolbars/hooks/FullScreen.js +0 -50
- package/src/toolbars/hooks/Graph.js +0 -263
- package/src/toolbars/hooks/H1.js +0 -71
- package/src/toolbars/hooks/H2.js +0 -71
- package/src/toolbars/hooks/H3.js +0 -71
- package/src/toolbars/hooks/Header.js +0 -118
- package/src/toolbars/hooks/Hr.js +0 -35
- package/src/toolbars/hooks/Image.js +0 -91
- package/src/toolbars/hooks/InlineCode.js +0 -53
- package/src/toolbars/hooks/Insert.js +0 -193
- package/src/toolbars/hooks/Italic.js +0 -72
- package/src/toolbars/hooks/Justify.js +0 -49
- package/src/toolbars/hooks/LineTable.js +0 -41
- package/src/toolbars/hooks/Link.js +0 -49
- package/src/toolbars/hooks/List.js +0 -55
- package/src/toolbars/hooks/MobilePreview.js +0 -44
- package/src/toolbars/hooks/Ol.js +0 -41
- package/src/toolbars/hooks/Panel.js +0 -140
- package/src/toolbars/hooks/Pdf.js +0 -78
- package/src/toolbars/hooks/Publish.js +0 -123
- package/src/toolbars/hooks/QuickTable.js +0 -43
- package/src/toolbars/hooks/Quote.js +0 -45
- package/src/toolbars/hooks/Redo.js +0 -33
- package/src/toolbars/hooks/Ruby.js +0 -59
- package/src/toolbars/hooks/Search.js +0 -53
- package/src/toolbars/hooks/Settings.js +0 -220
- package/src/toolbars/hooks/ShortcutKey.js +0 -62
- package/src/toolbars/hooks/Size.js +0 -118
- package/src/toolbars/hooks/Split.js +0 -37
- package/src/toolbars/hooks/Strikethrough.js +0 -71
- package/src/toolbars/hooks/Sub.js +0 -58
- package/src/toolbars/hooks/Sup.js +0 -58
- package/src/toolbars/hooks/SwitchModel.js +0 -56
- package/src/toolbars/hooks/Table.js +0 -56
- package/src/toolbars/hooks/Theme.js +0 -62
- package/src/toolbars/hooks/Toc.js +0 -35
- package/src/toolbars/hooks/TogglePreview.js +0 -91
- package/src/toolbars/hooks/Ul.js +0 -41
- package/src/toolbars/hooks/Underline.js +0 -68
- package/src/toolbars/hooks/Undo.js +0 -30
- package/src/toolbars/hooks/Video.js +0 -79
- package/src/toolbars/hooks/Word.js +0 -78
- package/src/toolbars/hooks/WordCount.js +0 -106
- package/src/utils/autoindent.js +0 -58
- package/src/utils/cm-search-replace.js +0 -794
- package/src/utils/code-preview-language-setting.js +0 -180
- package/src/utils/codeBlockContentHandler.js +0 -400
- package/src/utils/config.js +0 -174
- package/src/utils/copy.js +0 -55
- package/src/utils/dialog.js +0 -214
- package/src/utils/dom.js +0 -163
- package/src/utils/downloadUtil.js +0 -23
- package/src/utils/env.js +0 -22
- package/src/utils/error.js +0 -61
- package/src/utils/event.js +0 -38
- package/src/utils/export.js +0 -166
- package/src/utils/file.js +0 -164
- package/src/utils/formulaUtilsHandler.js +0 -232
- package/src/utils/htmlparser.js +0 -976
- package/src/utils/image.js +0 -99
- package/src/utils/imgSizeHandler.js +0 -279
- package/src/utils/lazyLoadImg.js +0 -327
- package/src/utils/lineFeed.js +0 -49
- package/src/utils/listContentHandler.js +0 -227
- package/src/utils/lookbehind-replace.js +0 -81
- package/src/utils/mathjax.js +0 -89
- package/src/utils/myersDiff.js +0 -211
- package/src/utils/pasteHelper.js +0 -253
- package/src/utils/platformTransform.js +0 -71
- package/src/utils/recount-pos.js +0 -59
- package/src/utils/regexp.js +0 -295
- package/src/utils/sanitize.js +0 -477
- package/src/utils/selection.js +0 -50
- package/src/utils/shortcutKey.js +0 -291
- package/src/utils/svgUtils.js +0 -96
- package/src/utils/tableContentHandler.js +0 -876
- package/test/core/CommonMark.spec.ts +0 -62
- package/test/core/hooks/AutoLink.spec.ts +0 -28
- package/test/core/hooks/List.spec.ts +0 -79
- package/test/core/hooks/__snapshots__/List.spec.ts.snap +0 -11
- package/test/example.md +0 -778
- package/test/node.js +0 -10
- package/test/suites/commonmark.spec.json +0 -5218
- package/test/tsconfig.test.json +0 -6
- package/test/utils/regexp.spec.ts +0 -28
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import MenuBase from '@/toolbars/MenuBase';
|
|
17
|
-
import { getSelection } from '@/utils/selection';
|
|
18
|
-
/**
|
|
19
|
-
* 插入字体颜色或者字体背景颜色的按钮
|
|
20
|
-
*/
|
|
21
|
-
export default class Color extends MenuBase {
|
|
22
|
-
constructor($cherry) {
|
|
23
|
-
super($cherry);
|
|
24
|
-
this.setName('color', 'color');
|
|
25
|
-
// this.bubbleMenu = true;
|
|
26
|
-
this.bubbleColor = new BubbleColor($cherry);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
$testIsColor(type, selection) {
|
|
30
|
-
const textReg = /^\s*!![^\s]+ [\s\S]+!!\s*$/;
|
|
31
|
-
const bgReg = /^\s*!!![^\s]+ [\s\S]+!!!\s*$/;
|
|
32
|
-
if (type === 'text') {
|
|
33
|
-
return textReg.test(selection) && !bgReg.test(selection);
|
|
34
|
-
}
|
|
35
|
-
return bgReg.test(selection);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
$testIsShortKey(shortKey) {
|
|
39
|
-
return /(color|background-color)\s*:/.test(shortKey);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
$getTypeAndColor(shortKey) {
|
|
43
|
-
if (this.$testIsShortKey(shortKey)) {
|
|
44
|
-
const type = /background-color\s*:/.test(shortKey) ? 'background-color' : 'text';
|
|
45
|
-
const color = shortKey.replace(/(color|background-color)\s*:\s*([#0-9a-zA-Z]+)[^#0-9a-zA-Z]*$/, '$2').trim();
|
|
46
|
-
return { type, color };
|
|
47
|
-
}
|
|
48
|
-
return this.getAndCleanCacheOnce();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
hideOtherSubMenu(hideAllSubMenu) {
|
|
52
|
-
const lastDisplay = this.bubbleColor.dom.style.display || 'none';
|
|
53
|
-
hideAllSubMenu();
|
|
54
|
-
this.bubbleColor.dom.style.display = lastDisplay;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 响应点击事件
|
|
59
|
-
* @param {string} selection 被用户选中的文本内容
|
|
60
|
-
* @param {string} shortKey 快捷键参数,color: #000000 | background-color: #000000
|
|
61
|
-
* @param {Event & {target:HTMLElement}} event 点击事件,用来从被点击的调色盘中获得对应的颜色
|
|
62
|
-
* @returns 回填到编辑器光标位置/选中文本区域的内容
|
|
63
|
-
*/
|
|
64
|
-
onClick(selection, shortKey = '', event) {
|
|
65
|
-
if (this.hasCacheOnce() || this.$testIsShortKey(shortKey)) {
|
|
66
|
-
let $selection = getSelection(this.editor.editor, selection) || this.locale.color;
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
const { type, color } = this.$getTypeAndColor(shortKey);
|
|
69
|
-
const begin = type === 'text' ? `!!${color} ` : `!!!${color} `;
|
|
70
|
-
const end = type === 'text' ? '!!' : '!!!';
|
|
71
|
-
if (!this.isSelections && !this.$testIsColor(type, $selection)) {
|
|
72
|
-
this.getMoreSelection(begin, end, () => {
|
|
73
|
-
const newSelection = this.editor.editor.getSelection();
|
|
74
|
-
if (this.$testIsColor(type, newSelection)) {
|
|
75
|
-
$selection = newSelection;
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
return false;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
if (this.$testIsColor(type, $selection)) {
|
|
82
|
-
const reg = new RegExp(`(^\\s*${end})([^\\s]+) ([\\s\\S]+${end}\\s*$)`, 'gm');
|
|
83
|
-
let needClean = true;
|
|
84
|
-
const tmp = $selection.replace(reg, (w, m1, m2, m3) => {
|
|
85
|
-
needClean = needClean ? m2 === color : false;
|
|
86
|
-
return `${m1}${color} ${m3}`;
|
|
87
|
-
});
|
|
88
|
-
if (needClean) {
|
|
89
|
-
return $selection.replace(reg, '$3').replace(/!+\s*$/gm, '');
|
|
90
|
-
}
|
|
91
|
-
this.registerAfterClickCb(() => {
|
|
92
|
-
this.setLessSelection(begin, end);
|
|
93
|
-
});
|
|
94
|
-
return tmp;
|
|
95
|
-
}
|
|
96
|
-
this.registerAfterClickCb(() => {
|
|
97
|
-
this.setLessSelection(begin, end);
|
|
98
|
-
});
|
|
99
|
-
return `${begin}${$selection}${end}`;
|
|
100
|
-
}
|
|
101
|
-
// 定位调色盘应该出现的位置
|
|
102
|
-
// 该按钮可能出现在顶部工具栏,
|
|
103
|
-
// 也可能出现在选中文字时出现的bubble工具栏,
|
|
104
|
-
// 也可能出现在新行出现的float工具栏
|
|
105
|
-
let top = 0;
|
|
106
|
-
let left = 0;
|
|
107
|
-
if (event.target.closest('.cherry-bubble')) {
|
|
108
|
-
const $colorDom = /** @type {HTMLElement}*/ (event.target.closest('.cherry-bubble'));
|
|
109
|
-
const clientRect = $colorDom.getBoundingClientRect();
|
|
110
|
-
top = clientRect.top + $colorDom.offsetHeight;
|
|
111
|
-
left = /** @type {HTMLElement}*/ (event.target.closest('.cherry-toolbar-color')).offsetLeft + clientRect.left;
|
|
112
|
-
} else {
|
|
113
|
-
const $colorDom = /** @type {HTMLElement}*/ (event.target.closest('.cherry-toolbar-color'));
|
|
114
|
-
const clientRect = $colorDom.getBoundingClientRect();
|
|
115
|
-
top = clientRect.top + $colorDom.offsetHeight;
|
|
116
|
-
left = clientRect.left;
|
|
117
|
-
}
|
|
118
|
-
this.updateMarkdown = false;
|
|
119
|
-
// 【TODO】需要增加getMoreSelection的逻辑
|
|
120
|
-
this.bubbleColor.toggle({
|
|
121
|
-
left,
|
|
122
|
-
top,
|
|
123
|
-
$color: this,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* 调色盘
|
|
130
|
-
*/
|
|
131
|
-
class BubbleColor {
|
|
132
|
-
constructor($cherry) {
|
|
133
|
-
this.editor = $cherry.editor;
|
|
134
|
-
this.$cherry = $cherry;
|
|
135
|
-
this.init();
|
|
136
|
-
this.initAction();
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* 定义调色盘每个色块的颜色值
|
|
141
|
-
*/
|
|
142
|
-
colorStack = [
|
|
143
|
-
'#000000',
|
|
144
|
-
'#444444',
|
|
145
|
-
'#666666',
|
|
146
|
-
'#999999',
|
|
147
|
-
'#cccccc',
|
|
148
|
-
'#eeeeee',
|
|
149
|
-
'#f3f3f3',
|
|
150
|
-
'#ffffff',
|
|
151
|
-
'#ff0000',
|
|
152
|
-
'#ff9900',
|
|
153
|
-
'#ffff00',
|
|
154
|
-
'#00ff00',
|
|
155
|
-
'#00ffff',
|
|
156
|
-
'#0000ff',
|
|
157
|
-
'#9900ff',
|
|
158
|
-
'#ff00ff',
|
|
159
|
-
'#f4cccc',
|
|
160
|
-
'#fce5cd',
|
|
161
|
-
'#fff2cc',
|
|
162
|
-
'#d9ead3',
|
|
163
|
-
'#d0e0e3',
|
|
164
|
-
'#cfe2f3',
|
|
165
|
-
'#d9d2e9',
|
|
166
|
-
'#ead1dc',
|
|
167
|
-
'#ea9999',
|
|
168
|
-
'#f9cb9c',
|
|
169
|
-
'#ffe599',
|
|
170
|
-
'#b6d7a8',
|
|
171
|
-
'#a2c4c9',
|
|
172
|
-
'#9fc5e8',
|
|
173
|
-
'#b4a7d6',
|
|
174
|
-
'#d5a6bd',
|
|
175
|
-
'#e06666',
|
|
176
|
-
'#f6b26b',
|
|
177
|
-
'#ffd966',
|
|
178
|
-
'#93c47d',
|
|
179
|
-
'#76a5af',
|
|
180
|
-
'#6fa8dc',
|
|
181
|
-
'#8e7cc3',
|
|
182
|
-
'#c27ba0',
|
|
183
|
-
'#cc0000',
|
|
184
|
-
'#e69138',
|
|
185
|
-
'#f1c232',
|
|
186
|
-
'#6aa84f',
|
|
187
|
-
'#45818e',
|
|
188
|
-
'#3d85c6',
|
|
189
|
-
'#674ea7',
|
|
190
|
-
'#a64d79',
|
|
191
|
-
'#990000',
|
|
192
|
-
'#b45f06',
|
|
193
|
-
'#bf9000',
|
|
194
|
-
'#38761d',
|
|
195
|
-
'#134f5c',
|
|
196
|
-
'#0b5394',
|
|
197
|
-
'#351c75',
|
|
198
|
-
'#741b47',
|
|
199
|
-
'#660000',
|
|
200
|
-
'#783f04',
|
|
201
|
-
'#7f6000',
|
|
202
|
-
'#274e13',
|
|
203
|
-
'#0c343d',
|
|
204
|
-
'#073763',
|
|
205
|
-
'#20124d',
|
|
206
|
-
'#4c1130',
|
|
207
|
-
];
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* 用来暂存选中的内容
|
|
211
|
-
* @param {string} selection 编辑区选中的文本内容
|
|
212
|
-
*/
|
|
213
|
-
setSelection(selection) {
|
|
214
|
-
this.selection = selection;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
getFontColorDom(title) {
|
|
218
|
-
const colorStackDOM = this.colorStack
|
|
219
|
-
.map(
|
|
220
|
-
(color) =>
|
|
221
|
-
`<span class="cherry-color-item cherry-color-item__${color.replace(
|
|
222
|
-
'#',
|
|
223
|
-
'',
|
|
224
|
-
)}" unselectable="on" data-val="${color}"
|
|
225
|
-
style="background-color:${color}"></span>`,
|
|
226
|
-
)
|
|
227
|
-
.join('');
|
|
228
|
-
return `<h3>${title}</h3>${colorStackDOM}`;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
getDom() {
|
|
232
|
-
const $colorWrap = document.createElement('div');
|
|
233
|
-
$colorWrap.classList.add('cherry-color-wrap');
|
|
234
|
-
$colorWrap.classList.add('cherry-dropdown');
|
|
235
|
-
const $textWrap = document.createElement('div');
|
|
236
|
-
$textWrap.classList.add('cherry-color-text');
|
|
237
|
-
$textWrap.innerHTML = this.getFontColorDom(this.$cherry.locale.fontColor);
|
|
238
|
-
$colorWrap.appendChild($textWrap);
|
|
239
|
-
|
|
240
|
-
const $bgWrap = document.createElement('div');
|
|
241
|
-
$bgWrap.classList.add('cherry-color-bg');
|
|
242
|
-
$bgWrap.innerHTML = this.getFontColorDom(this.$cherry.locale.fontBgColor);
|
|
243
|
-
$colorWrap.appendChild($bgWrap);
|
|
244
|
-
|
|
245
|
-
return $colorWrap;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
init() {
|
|
249
|
-
this.dom = this.getDom();
|
|
250
|
-
this.editor.options.wrapperDom.appendChild(this.dom);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
onClick() {
|
|
254
|
-
if (this.type === 'text') {
|
|
255
|
-
if (/^!!#\S+ [\s\S]+?!!/.test(this.selection)) {
|
|
256
|
-
return this.selection.replace(/^!!#\S+ ([\s\S]+?)!!/, `!!${this.colorValue} $1!!`);
|
|
257
|
-
}
|
|
258
|
-
return `!!${this.colorValue} ${this.selection}!!`;
|
|
259
|
-
}
|
|
260
|
-
if (/^!!!#\S+ [\s\S]+?!!!/.test(this.selection)) {
|
|
261
|
-
return this.selection.replace(/^!!!#\S+ ([\s\S]+?)!!!/, `!!!${this.colorValue} $1!!!`);
|
|
262
|
-
}
|
|
263
|
-
return `!!!${this.colorValue} ${this.selection}!!!`;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
initAction() {
|
|
267
|
-
// const self = this;
|
|
268
|
-
this.dom.addEventListener(
|
|
269
|
-
'click',
|
|
270
|
-
(evt) => {
|
|
271
|
-
const { target } = /** @type {MouseEvent & {target:HTMLElement}}*/ (evt);
|
|
272
|
-
this.colorValue = target.getAttribute('data-val');
|
|
273
|
-
if (!this.colorValue) {
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
this.type = target.closest('.cherry-color-text') ? 'text' : 'bg';
|
|
277
|
-
this.$color.setCacheOnce({ type: this.type, color: this.colorValue });
|
|
278
|
-
this.$color.fire(null);
|
|
279
|
-
},
|
|
280
|
-
false,
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* 在对应的坐标展示/关闭调色盘
|
|
286
|
-
* @param {Object} 坐标
|
|
287
|
-
*/
|
|
288
|
-
toggle({ left, top, $color }) {
|
|
289
|
-
if (this.dom.style.display?.length > 0 && this.dom.style.display !== 'none') {
|
|
290
|
-
this.dom.style.display = 'none';
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
this.dom.style.left = `${left}px`;
|
|
294
|
-
this.dom.style.top = `${top}px`;
|
|
295
|
-
this.dom.style.display = 'block';
|
|
296
|
-
this.$color = $color;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
// import juice from 'juice';
|
|
17
|
-
import MenuBase from '@/toolbars/MenuBase';
|
|
18
|
-
import { copyToClip } from '@/utils/copy';
|
|
19
|
-
/**
|
|
20
|
-
* 复制按钮,用来复制预览区的html内容
|
|
21
|
-
* 该操作会将预览区的css样式以行内样式的形式插入到html内容里,从而保证粘贴时样式一致
|
|
22
|
-
*/
|
|
23
|
-
export default class Copy extends MenuBase {
|
|
24
|
-
constructor($cherry) {
|
|
25
|
-
super($cherry);
|
|
26
|
-
this.previewer = $cherry.previewer;
|
|
27
|
-
this.isLoading = false;
|
|
28
|
-
this.updateMarkdown = false;
|
|
29
|
-
this.setName('copy', 'copy');
|
|
30
|
-
this.lastIconOuterHtml = '';
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async adaptWechat(rawHtml) {
|
|
34
|
-
// 转化链接
|
|
35
|
-
// Array.from(document.querySelectorAll('a')).forEach((item) => {
|
|
36
|
-
// item.removeAttribute('href');
|
|
37
|
-
// });
|
|
38
|
-
// 防止echarts标签被转成p时丢失样式
|
|
39
|
-
const figureRegex = /(<figure data-lines=.+?<)div(.+?<\/)div(>.*?<\/figure>)/g;
|
|
40
|
-
const html = rawHtml.replace(figureRegex, (match, prefix, content, suffix) => {
|
|
41
|
-
return `${prefix}p${content}p${suffix}`;
|
|
42
|
-
});
|
|
43
|
-
// 图片转base64,防止无法自动上传
|
|
44
|
-
const imgRegex = /(<img.+?src=")(.+?)(".*?>)/g;
|
|
45
|
-
/** @type {(Promise<string>)[]} */
|
|
46
|
-
const promises = [];
|
|
47
|
-
html.replace(imgRegex, (match, prefix, src) => {
|
|
48
|
-
promises.push(convertImgToBase64(src));
|
|
49
|
-
});
|
|
50
|
-
const urls = await Promise.all(promises);
|
|
51
|
-
return html.replace(imgRegex, (match, prefix, src, suffix) => prefix + urls.shift() + suffix);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
getStyleFromSheets(keyword) {
|
|
55
|
-
const sheets = Array.from(document.styleSheets).filter(
|
|
56
|
-
(item) => item.cssRules[0] && item.cssRules[0].cssText.indexOf(keyword) > -1,
|
|
57
|
-
);
|
|
58
|
-
return `<style>${sheets.reduce((html, sheet) => {
|
|
59
|
-
return html + Array.from(sheet.cssRules).reduce((html, rule) => html + rule.cssText, '');
|
|
60
|
-
}, '')}</style>`;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
computeStyle() {
|
|
64
|
-
// 计算需要append进富文本的style
|
|
65
|
-
const mathStyle = this.getStyleFromSheets('mjx-container');
|
|
66
|
-
const cherryStyle = this.getStyleFromSheets('cherry');
|
|
67
|
-
const echartStyle =
|
|
68
|
-
'<style>figure>p{overflow:hidden;position:relative;width:500px;height:300px;background:transparent;}</style>';
|
|
69
|
-
return {
|
|
70
|
-
mathStyle,
|
|
71
|
-
echartStyle,
|
|
72
|
-
cherryStyle,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 由于复制操作会随着预览区域的内容增加而耗时变长,所以需要增加“正在复制”的状态回显
|
|
78
|
-
* 同时该状态也用于限频
|
|
79
|
-
*/
|
|
80
|
-
toggleLoading() {
|
|
81
|
-
// 切换loading状态
|
|
82
|
-
if (this.isLoading) {
|
|
83
|
-
this.dom.lastElementChild.outerHTML = this.lastIconOuterHtml;
|
|
84
|
-
this.lastIconOuterHtml = '';
|
|
85
|
-
} else {
|
|
86
|
-
this.lastIconOuterHtml = this.dom.lastElementChild.outerHTML;
|
|
87
|
-
this.dom.lastElementChild.outerHTML = '<div class="icon-loading loading"></div>';
|
|
88
|
-
}
|
|
89
|
-
this.isLoading = !this.isLoading;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* 响应点击事件
|
|
94
|
-
* 该按钮不会引发编辑区域的内容改动,所以不用处理用户在编辑区域的选中内容
|
|
95
|
-
* @param {Event} e 点击事件
|
|
96
|
-
*/
|
|
97
|
-
onClick(e) {
|
|
98
|
-
this.toggleLoading();
|
|
99
|
-
const inlineCodeTheme = document.querySelector('.cherry').getAttribute('data-inline-code-theme');
|
|
100
|
-
const codeBlockTheme = document.querySelector('.cherry').getAttribute('data-code-block-theme');
|
|
101
|
-
const { mathStyle, echartStyle, cherryStyle } = this.computeStyle();
|
|
102
|
-
const html = this.previewer.isPreviewerHidden()
|
|
103
|
-
? this.previewer.options.previewerCache.html
|
|
104
|
-
: this.previewer.getValue();
|
|
105
|
-
// 将css样式以行内样式的形式插入到html内容里
|
|
106
|
-
this.adaptWechat(html).then((html) => {
|
|
107
|
-
copyToClip(
|
|
108
|
-
`${mathStyle + echartStyle + cherryStyle}
|
|
109
|
-
<div data-inline-code-theme="${inlineCodeTheme}" data-code-block-theme="${codeBlockTheme}">
|
|
110
|
-
<div class="cherry-markdown">${html}</div>
|
|
111
|
-
</div>`,
|
|
112
|
-
);
|
|
113
|
-
this.toggleLoading();
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* 将图片转成base64,防止出现由于图片防盗链功能导致图裂的情况
|
|
120
|
-
* @param {string} url 图片的地址
|
|
121
|
-
* @param {Function} [callback] 回调函数,本函数不处理该参数
|
|
122
|
-
* @param {string} [outputFormat]
|
|
123
|
-
* @returns {Promise<string>} img node
|
|
124
|
-
*/
|
|
125
|
-
function convertImgToBase64(url, callback, outputFormat) {
|
|
126
|
-
return new Promise((resolve) => {
|
|
127
|
-
let canvas = /** @type {HTMLCanvasElement}*/ (document.createElement('CANVAS'));
|
|
128
|
-
const ctx = canvas.getContext('2d');
|
|
129
|
-
const img = new Image();
|
|
130
|
-
img.crossOrigin = 'Anonymous';
|
|
131
|
-
img.onload = function () {
|
|
132
|
-
canvas.height = img.height;
|
|
133
|
-
canvas.width = img.width;
|
|
134
|
-
ctx.drawImage(img, 0, 0);
|
|
135
|
-
const dataURL = canvas.toDataURL(outputFormat || 'image/png');
|
|
136
|
-
resolve(dataURL);
|
|
137
|
-
canvas = null;
|
|
138
|
-
};
|
|
139
|
-
img.src = url;
|
|
140
|
-
});
|
|
141
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import MenuBase from '@/toolbars/MenuBase';
|
|
17
|
-
import { getDetailRule } from '@/utils/regexp';
|
|
18
|
-
import { getSelection } from '@/utils/selection';
|
|
19
|
-
/**
|
|
20
|
-
* 插入手风琴
|
|
21
|
-
*/
|
|
22
|
-
export default class Detail extends MenuBase {
|
|
23
|
-
constructor($cherry) {
|
|
24
|
-
super($cherry);
|
|
25
|
-
this.setName('detail', 'insertFlow');
|
|
26
|
-
this.detailRule = getDetailRule().reg;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 响应点击事件
|
|
31
|
-
* @param {string} selection 被用户选中的文本内容
|
|
32
|
-
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
33
|
-
*/
|
|
34
|
-
onClick(selection) {
|
|
35
|
-
let $selection =
|
|
36
|
-
getSelection(this.editor.editor, selection, 'line', true) || this.$cherry.locale.detailDefaultContent;
|
|
37
|
-
this.detailRule.lastIndex = 0;
|
|
38
|
-
if (!this.detailRule.test($selection)) {
|
|
39
|
-
// 如果没有命中手风琴语法,则尝试扩大选区
|
|
40
|
-
this.getMoreSelection('+++ ', '\n', () => {
|
|
41
|
-
const newSelection = this.editor.editor.getSelection();
|
|
42
|
-
this.detailRule.lastIndex = 0;
|
|
43
|
-
const isMatch = this.detailRule.test(newSelection);
|
|
44
|
-
if (isMatch !== false) {
|
|
45
|
-
$selection = newSelection;
|
|
46
|
-
}
|
|
47
|
-
return isMatch !== false;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
this.detailRule.lastIndex = 0;
|
|
51
|
-
if (this.detailRule.test($selection)) {
|
|
52
|
-
// 如果命中了手风琴语法,则去掉手风琴语法
|
|
53
|
-
this.detailRule.lastIndex = 0;
|
|
54
|
-
return $selection.replace(this.detailRule, (match, preLines, isOpen, title, content) => {
|
|
55
|
-
return `${title}\n${content}`;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
// 去掉开头的空格
|
|
59
|
-
$selection = $selection.replace(/^\s+/, '');
|
|
60
|
-
// 如果选中的内容不包含换行,则强制增加一个换行
|
|
61
|
-
if (!/\n/.test($selection)) {
|
|
62
|
-
$selection = `${$selection}\n${$selection}`;
|
|
63
|
-
}
|
|
64
|
-
this.registerAfterClickCb(() => {
|
|
65
|
-
this.setLessSelection('+++ ', '\n');
|
|
66
|
-
});
|
|
67
|
-
return `+++ ${$selection}\n+++`.replace(/\n{2,}\+\+\+/g, '\n+++');
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import MenuBase from '@/toolbars/MenuBase';
|
|
17
|
-
import { drawioDialog } from '@/utils/dialog';
|
|
18
|
-
/**
|
|
19
|
-
* 打开draw.io画图对话框,点击确定后向编辑器插入图片语法
|
|
20
|
-
*/
|
|
21
|
-
export default class DrawIo extends MenuBase {
|
|
22
|
-
constructor($cherry) {
|
|
23
|
-
super($cherry);
|
|
24
|
-
this.setName('draw.io', 'draw.io');
|
|
25
|
-
this.noIcon = true;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 响应点击事件
|
|
30
|
-
* @param {string} selection 被用户选中的文本内容
|
|
31
|
-
* @param {string} shortKey 快捷键参数,本函数不处理这个参数
|
|
32
|
-
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
33
|
-
*/
|
|
34
|
-
onClick(selection, shortKey = '') {
|
|
35
|
-
if (!this.$cherry.options.drawioIframeUrl) {
|
|
36
|
-
// 如果没有配置drawio的编辑页URL,则直接失效
|
|
37
|
-
return selection;
|
|
38
|
-
}
|
|
39
|
-
if (this.hasCacheOnce()) {
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
const { xmlData, base64 } = this.getAndCleanCacheOnce();
|
|
42
|
-
const begin = '{data-type=drawio data-xml=${encodeURI(xmlData)}}`;
|
|
44
|
-
this.registerAfterClickCb(() => {
|
|
45
|
-
this.setLessSelection(begin, end);
|
|
46
|
-
});
|
|
47
|
-
return `${begin}在预览区点击图片重新编辑draw.io${end}`;
|
|
48
|
-
}
|
|
49
|
-
// 插入图片,调用上传文件逻辑
|
|
50
|
-
drawioDialog(this.$cherry.options.drawioIframeUrl, this.$cherry.options.drawioIframeStyle, '', (data) => {
|
|
51
|
-
this.setCacheOnce(data);
|
|
52
|
-
this.fire(null);
|
|
53
|
-
});
|
|
54
|
-
this.updateMarkdown = false;
|
|
55
|
-
return selection;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import MenuBase from '@/toolbars/MenuBase';
|
|
17
|
-
|
|
18
|
-
export default class Export extends MenuBase {
|
|
19
|
-
constructor($cherry) {
|
|
20
|
-
super($cherry);
|
|
21
|
-
this.setName('export');
|
|
22
|
-
this.noIcon = true;
|
|
23
|
-
this.updateMarkdown = false;
|
|
24
|
-
this.subMenuConfig = [
|
|
25
|
-
{ noIcon: true, name: 'exportToPdf', onclick: this.bindSubClick.bind(this, 'pdf') },
|
|
26
|
-
{ noIcon: true, name: 'exportScreenshot', onclick: this.bindSubClick.bind(this, 'screenShot') },
|
|
27
|
-
{ noIcon: true, name: 'exportMarkdownFile', onclick: this.bindSubClick.bind(this, 'markdown') },
|
|
28
|
-
{ noIcon: true, name: 'exportHTMLFile', onclick: this.bindSubClick.bind(this, 'html') },
|
|
29
|
-
];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
onClick(shortKey = '', type) {
|
|
33
|
-
if (document.querySelector('.cherry-dropdown[name=export]')) {
|
|
34
|
-
/** @type {HTMLElement}*/ (document.querySelector('.cherry-dropdown[name=export]')).style.display = 'none';
|
|
35
|
-
}
|
|
36
|
-
// 强制刷新一下预览区域的内容
|
|
37
|
-
const { previewer } = this.$cherry;
|
|
38
|
-
let html = '';
|
|
39
|
-
if (previewer.isPreviewerHidden()) {
|
|
40
|
-
html = previewer.options.previewerCache.html;
|
|
41
|
-
} else {
|
|
42
|
-
html = previewer.getDomContainer().innerHTML;
|
|
43
|
-
}
|
|
44
|
-
// 需要未加载的图片替换成原始图片
|
|
45
|
-
html = previewer.lazyLoadImg.changeDataSrc2Src(html);
|
|
46
|
-
previewer.refresh(html);
|
|
47
|
-
previewer.export(type);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import MenuBase from '@/toolbars/MenuBase';
|
|
17
|
-
import { handleUpload, handleUploadMulti } from '@/utils/file';
|
|
18
|
-
/**
|
|
19
|
-
* 插入pdf
|
|
20
|
-
*/
|
|
21
|
-
export default class File extends MenuBase {
|
|
22
|
-
constructor($cherry) {
|
|
23
|
-
super($cherry);
|
|
24
|
-
this.setName('file', 'phone');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 响应点击事件
|
|
29
|
-
* @param {string} selection 被用户选中的文本内容
|
|
30
|
-
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
31
|
-
*/
|
|
32
|
-
onClick(selection, shortKey = '') {
|
|
33
|
-
const accept = this.$cherry.options?.fileTypeLimitMap?.file ?? '*';
|
|
34
|
-
const multiple = this.$cherry?.options.multipleFileSelection?.file ?? false;
|
|
35
|
-
if (multiple) {
|
|
36
|
-
if (this.hasCacheOnce()) {
|
|
37
|
-
// @ts-ignore
|
|
38
|
-
const arr = this.getAndCleanCacheOnce();
|
|
39
|
-
let res = '';
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
for (const { url, params } of arr) {
|
|
42
|
-
const begin = '[';
|
|
43
|
-
const end = `](${url})`;
|
|
44
|
-
this.registerAfterClickCb(() => {
|
|
45
|
-
this.setLessSelection(begin, end);
|
|
46
|
-
});
|
|
47
|
-
const finalName = params.name ? params.name : name;
|
|
48
|
-
res += `${begin}${finalName}${end}\n`;
|
|
49
|
-
}
|
|
50
|
-
return res;
|
|
51
|
-
}
|
|
52
|
-
// 插入图片,调用上传文件逻辑
|
|
53
|
-
handleUploadMulti(this.editor, 'file', accept, (arr) => {
|
|
54
|
-
this.setCacheOnce(arr);
|
|
55
|
-
this.fire(null);
|
|
56
|
-
});
|
|
57
|
-
this.updateMarkdown = false;
|
|
58
|
-
return selection;
|
|
59
|
-
}
|
|
60
|
-
if (this.hasCacheOnce()) {
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
const { name, url, params } = this.getAndCleanCacheOnce();
|
|
63
|
-
const begin = '[';
|
|
64
|
-
const end = `](${url})`;
|
|
65
|
-
this.registerAfterClickCb(() => {
|
|
66
|
-
this.setLessSelection(begin, end);
|
|
67
|
-
});
|
|
68
|
-
const finalName = params.name ? params.name : name;
|
|
69
|
-
return `${begin}${finalName}${end}`;
|
|
70
|
-
}
|
|
71
|
-
// 插入图片,调用上传文件逻辑
|
|
72
|
-
handleUpload(this.editor, 'file', accept, (name, url, params) => {
|
|
73
|
-
this.setCacheOnce({ name, url, params });
|
|
74
|
-
this.fire(null);
|
|
75
|
-
});
|
|
76
|
-
this.updateMarkdown = false;
|
|
77
|
-
return selection;
|
|
78
|
-
}
|
|
79
|
-
}
|