cherry-muse 1.0.1
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/LICENSE +162 -0
- package/README.md +139 -0
- package/dist/addons/cherry-code-block-card-plugin.js +1 -0
- package/dist/addons/cherry-code-block-echarts-plugin.js +1 -0
- package/dist/addons/cherry-code-block-mermaid-plugin.js +1 -0
- package/dist/cherry-markdown.core.common.js +1 -0
- package/dist/cherry-markdown.core.js +1 -0
- package/dist/cherry-markdown.css +4089 -0
- package/dist/cherry-markdown.engine.core.common.js +1 -0
- package/dist/cherry-markdown.engine.core.esm.js +1 -0
- package/dist/cherry-markdown.engine.core.js +1 -0
- package/dist/cherry-markdown.esm.js +1 -0
- package/dist/cherry-markdown.js +70837 -0
- package/dist/cherry-markdown.js.map +1 -0
- package/dist/cherry-markdown.min.css +1 -0
- package/dist/cherry-markdown.min.js +1 -0
- package/dist/stats.html +4838 -0
- package/examples/scripts/pinyin/README.md +53 -0
- package/package.json +167 -0
- package/src/Cherry.config.js +411 -0
- package/src/Cherry.js +788 -0
- package/src/CherryStatic.js +70 -0
- package/src/Editor.js +746 -0
- package/src/Engine.js +334 -0
- package/src/Event.js +74 -0
- package/src/Factory.js +180 -0
- package/src/Logger.js +31 -0
- package/src/Previewer.js +1147 -0
- package/src/Sanitizer.js +4 -0
- package/src/Sanitizer.node.js +7 -0
- package/src/Stats.js +101 -0
- package/src/Theme.js +46 -0
- package/src/UrlCache.js +98 -0
- package/src/addons/cherry-code-block-card-plugin.js +213 -0
- package/src/addons/cherry-code-block-echarts-plugin.js +161 -0
- package/src/addons/cherry-code-block-mermaid-plugin.js +118 -0
- package/src/core/HookCenter.js +303 -0
- package/src/core/HooksConfig.js +106 -0
- package/src/core/ParagraphBase.js +314 -0
- package/src/core/SentenceBase.js +65 -0
- package/src/core/SyntaxBase.js +197 -0
- package/src/core/hooks/AutoLink.js +251 -0
- package/src/core/hooks/BackgroundColor.js +46 -0
- package/src/core/hooks/Badge.js +100 -0
- package/src/core/hooks/Blockquote.js +113 -0
- package/src/core/hooks/Br.js +85 -0
- package/src/core/hooks/CodeBlock.js +876 -0
- package/src/core/hooks/Color.js +78 -0
- package/src/core/hooks/CommentReference.js +96 -0
- package/src/core/hooks/Detail.js +138 -0
- package/src/core/hooks/Emoji.config.js +9388 -0
- package/src/core/hooks/Emoji.js +223 -0
- package/src/core/hooks/Emphasis.js +113 -0
- package/src/core/hooks/Footnote.js +125 -0
- package/src/core/hooks/FrontMatter.js +52 -0
- package/src/core/hooks/FrontMatterVars.js +82 -0
- package/src/core/hooks/Header.js +229 -0
- package/src/core/hooks/HighLight.js +37 -0
- package/src/core/hooks/Hr.js +52 -0
- package/src/core/hooks/HtmlBlock.js +159 -0
- package/src/core/hooks/Iframe.js +80 -0
- package/src/core/hooks/Image.js +276 -0
- package/src/core/hooks/InlineCode.js +45 -0
- package/src/core/hooks/InlineMath.js +142 -0
- package/src/core/hooks/Link.js +169 -0
- package/src/core/hooks/List.js +260 -0
- package/src/core/hooks/Mark.js +55 -0
- package/src/core/hooks/MathBlock.js +97 -0
- package/src/core/hooks/Panel.js +170 -0
- package/src/core/hooks/Paragraph.js +84 -0
- package/src/core/hooks/Ruby.js +34 -0
- package/src/core/hooks/Size.js +84 -0
- package/src/core/hooks/Strikethrough.js +54 -0
- package/src/core/hooks/Sub.js +47 -0
- package/src/core/hooks/SuggestList.js +317 -0
- package/src/core/hooks/Suggester.js +759 -0
- package/src/core/hooks/Sup.js +47 -0
- package/src/core/hooks/Table.js +315 -0
- package/src/core/hooks/Toc.js +290 -0
- package/src/core/hooks/Transfer.js +47 -0
- package/src/core/hooks/Underline.js +37 -0
- package/src/index.core.js +29 -0
- package/src/index.engine.core.js +62 -0
- package/src/index.engine.js +30 -0
- package/src/index.js +28 -0
- package/src/locales/index.js +21 -0
- package/src/locales/zh_CN.js +170 -0
- package/src/sass/cherry.scss +122 -0
- package/src/sass/components/bubble.scss +122 -0
- package/src/sass/components/codemirror.scss +628 -0
- package/src/sass/components/dropdown.scss +37 -0
- package/src/sass/components/editor.scss +78 -0
- package/src/sass/components/preview.scss +71 -0
- package/src/sass/components/prism.scss +142 -0
- package/src/sass/components/stats.scss +32 -0
- package/src/sass/components/toc.scss +184 -0
- package/src/sass/components/toolbar.scss +117 -0
- package/src/sass/core/AutoLink.scss +20 -0
- package/src/sass/core/BackgroundColor.scss +0 -0
- package/src/sass/core/Badge.scss +116 -0
- package/src/sass/core/Blockquote.scss +12 -0
- package/src/sass/core/Br.scss +0 -0
- package/src/sass/core/Card.scss +219 -0
- package/src/sass/core/CodeBlock.scss +205 -0
- package/src/sass/core/Color.scss +37 -0
- package/src/sass/core/CommentReference.scss +0 -0
- package/src/sass/core/Detail.scss +107 -0
- package/src/sass/core/Emoji.scss +127 -0
- package/src/sass/core/Emphasis.scss +9 -0
- package/src/sass/core/Footnote.scss +21 -0
- package/src/sass/core/FrontMatterVars.scss +19 -0
- package/src/sass/core/Header.scss +103 -0
- package/src/sass/core/HighLight.scss +0 -0
- package/src/sass/core/Hr.scss +10 -0
- package/src/sass/core/HtmlBlock.scss +0 -0
- package/src/sass/core/Iframe.scss +36 -0
- package/src/sass/core/Image.scss +59 -0
- package/src/sass/core/InlineCode.scss +10 -0
- package/src/sass/core/InlineMath.scss +11 -0
- package/src/sass/core/Link.scss +16 -0
- package/src/sass/core/List.scss +61 -0
- package/src/sass/core/Mark.scss +15 -0
- package/src/sass/core/MathBlock.scss +0 -0
- package/src/sass/core/Panel.scss +150 -0
- package/src/sass/core/Paragraph.scss +6 -0
- package/src/sass/core/Ruby.scss +0 -0
- package/src/sass/core/Size.scss +8 -0
- package/src/sass/core/Strikethrough.scss +0 -0
- package/src/sass/core/Sub.scss +5 -0
- package/src/sass/core/Suggester.scss +62 -0
- package/src/sass/core/Sup.scss +5 -0
- package/src/sass/core/Table.scss +127 -0
- package/src/sass/core/Toc.scss +28 -0
- package/src/sass/core/Transfer.scss +0 -0
- package/src/sass/core/Underline.scss +0 -0
- package/src/sass/google-fonts.scss +34 -0
- package/src/sass/index.scss +3 -0
- package/src/sass/prism/dark.scss +131 -0
- package/src/sass/prism/light.scss +143 -0
- package/src/sass/variables/colors.scss +96 -0
- package/src/toolbars/Bubble.js +232 -0
- package/src/toolbars/BubbleTable.js +147 -0
- package/src/toolbars/HookCenter.js +185 -0
- package/src/toolbars/MenuBase.js +357 -0
- package/src/toolbars/PreviewerBubble.js +558 -0
- package/src/toolbars/Toc.js +246 -0
- package/src/toolbars/Toolbar.js +401 -0
- package/src/toolbars/hooks/Audio.js +53 -0
- package/src/toolbars/hooks/Badge.js +80 -0
- package/src/toolbars/hooks/BarTable.js +41 -0
- package/src/toolbars/hooks/Bold.js +70 -0
- package/src/toolbars/hooks/Br.js +34 -0
- package/src/toolbars/hooks/Card.js +64 -0
- package/src/toolbars/hooks/CheckList.js +41 -0
- package/src/toolbars/hooks/Code.js +46 -0
- package/src/toolbars/hooks/Color.js +285 -0
- package/src/toolbars/hooks/Copy.js +139 -0
- package/src/toolbars/hooks/Detail.js +70 -0
- package/src/toolbars/hooks/ECharts.js +303 -0
- package/src/toolbars/hooks/Emoji.js +303 -0
- package/src/toolbars/hooks/Export.js +47 -0
- package/src/toolbars/hooks/File.js +54 -0
- package/src/toolbars/hooks/Formula.js +36 -0
- package/src/toolbars/hooks/FullScreen.js +55 -0
- package/src/toolbars/hooks/Graph.js +281 -0
- package/src/toolbars/hooks/H1.js +71 -0
- package/src/toolbars/hooks/H2.js +71 -0
- package/src/toolbars/hooks/H3.js +71 -0
- package/src/toolbars/hooks/Header.js +100 -0
- package/src/toolbars/hooks/Hr.js +35 -0
- package/src/toolbars/hooks/Iframe.js +35 -0
- package/src/toolbars/hooks/Image.js +60 -0
- package/src/toolbars/hooks/Insert.js +36 -0
- package/src/toolbars/hooks/Italic.js +70 -0
- package/src/toolbars/hooks/LineTable.js +41 -0
- package/src/toolbars/hooks/Link.js +46 -0
- package/src/toolbars/hooks/List.js +55 -0
- package/src/toolbars/hooks/Ol.js +41 -0
- package/src/toolbars/hooks/Panel.js +155 -0
- package/src/toolbars/hooks/Quote.js +45 -0
- package/src/toolbars/hooks/Redo.js +33 -0
- package/src/toolbars/hooks/Ruby.js +59 -0
- package/src/toolbars/hooks/Size.js +100 -0
- package/src/toolbars/hooks/Split.js +37 -0
- package/src/toolbars/hooks/Strikethrough.js +65 -0
- package/src/toolbars/hooks/Sub.js +58 -0
- package/src/toolbars/hooks/Sup.js +58 -0
- package/src/toolbars/hooks/SwitchModel.js +78 -0
- package/src/toolbars/hooks/Table.js +56 -0
- package/src/toolbars/hooks/Toc.js +35 -0
- package/src/toolbars/hooks/TogglePreview.js +79 -0
- package/src/toolbars/hooks/Ul.js +41 -0
- package/src/toolbars/hooks/Underline.js +65 -0
- package/src/toolbars/hooks/Undo.js +30 -0
- package/src/toolbars/hooks/Video.js +53 -0
- package/src/utils/LazyLoadImg.js +341 -0
- package/src/utils/autoindent.js +58 -0
- package/src/utils/codeBlockContentHandler.js +351 -0
- package/src/utils/config.js +98 -0
- package/src/utils/copy.js +55 -0
- package/src/utils/dialog.js +196 -0
- package/src/utils/dom.js +162 -0
- package/src/utils/downloadUtil.js +23 -0
- package/src/utils/env.js +22 -0
- package/src/utils/error.js +61 -0
- package/src/utils/event.js +38 -0
- package/src/utils/export.js +115 -0
- package/src/utils/file.js +121 -0
- package/src/utils/formulaUtilsHandler.js +230 -0
- package/src/utils/htmlparser.js +977 -0
- package/src/utils/image.js +99 -0
- package/src/utils/imgSizeHandler.js +279 -0
- package/src/utils/jsonUtils.js +17 -0
- package/src/utils/lineFeed.js +49 -0
- package/src/utils/listContentHandler.js +227 -0
- package/src/utils/lookbehind-replace.js +81 -0
- package/src/utils/mathjax.js +89 -0
- package/src/utils/myersDiff.js +211 -0
- package/src/utils/pasteHelper.js +253 -0
- package/src/utils/recount-pos.js +59 -0
- package/src/utils/regexp.js +295 -0
- package/src/utils/sanitize.js +477 -0
- package/src/utils/selection.js +50 -0
- package/src/utils/svgUtils.js +96 -0
- package/src/utils/tableContentHandler.js +592 -0
- package/tools/README.md +3 -0
|
@@ -0,0 +1,80 @@
|
|
|
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 Badge extends MenuBase {
|
|
22
|
+
constructor($cherry) {
|
|
23
|
+
super($cherry);
|
|
24
|
+
this.setName('badge', 'app_badging');
|
|
25
|
+
this.subMenuConfig = [
|
|
26
|
+
{
|
|
27
|
+
iconName: 'notification_important',
|
|
28
|
+
name: 'badgeImportant',
|
|
29
|
+
onclick: this.bindSubClick.bind(this, 'important'),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
iconName: 'info_i',
|
|
33
|
+
name: 'badgeInfo',
|
|
34
|
+
onclick: this.bindSubClick.bind(this, 'info'),
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
iconName: 'priority_high',
|
|
38
|
+
name: 'badgeWarn',
|
|
39
|
+
onclick: this.bindSubClick.bind(this, 'warning'),
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
iconName: 'close',
|
|
43
|
+
name: 'badgeDanger',
|
|
44
|
+
onclick: this.bindSubClick.bind(this, 'danger'),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
iconName: 'emoji_objects',
|
|
48
|
+
name: 'badgeTip',
|
|
49
|
+
onclick: this.bindSubClick.bind(this, 'tip'),
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
iconName: 'align_flex_start',
|
|
53
|
+
name: 'badgeTop',
|
|
54
|
+
onclick: this.bindSubClick.bind(this, ['info', 'top']),
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
iconName: 'align_center',
|
|
58
|
+
name: 'badgeCenter',
|
|
59
|
+
onclick: this.bindSubClick.bind(this, ['info', 'center']),
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
iconName: 'align_flex_end',
|
|
63
|
+
name: 'badgeBottom',
|
|
64
|
+
onclick: this.bindSubClick.bind(this, ['info', 'bottom']),
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 响应点击事件
|
|
71
|
+
* @param {string} selection 被用户选中的文本内容
|
|
72
|
+
* @param {string} shortKey 快捷键参数
|
|
73
|
+
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
74
|
+
*/
|
|
75
|
+
onClick(selection, shortKey = '') {
|
|
76
|
+
const keys = typeof shortKey === 'string' ? [shortKey] : shortKey;
|
|
77
|
+
const $selection = getSelection(this.editor.editor, selection, 'line', true) || '内容';
|
|
78
|
+
return `[[${$selection}:${keys[0]},${keys.length > 1 ? keys[1] : 'center'}]]`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
* 插入柱状图图+表格
|
|
19
|
+
*/
|
|
20
|
+
export default class BarTable extends MenuBase {
|
|
21
|
+
constructor($cherry) {
|
|
22
|
+
super($cherry);
|
|
23
|
+
this.setName('barTable', 'table_chart');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 响应点击事件
|
|
28
|
+
* @param {string} selection 被用户选中的文本内容
|
|
29
|
+
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
30
|
+
*/
|
|
31
|
+
onClick(selection, shortKey = '') {
|
|
32
|
+
// 插入带折线图的表格
|
|
33
|
+
return `${selection}\n\n${[
|
|
34
|
+
'| :bar: {x,y} | a | b | c |',
|
|
35
|
+
'| :-: | :-: | :-: | :-: |',
|
|
36
|
+
'| x | 1 | 2 | 3 |',
|
|
37
|
+
'| y | 2 | 4 | 6 |',
|
|
38
|
+
'| z | 7 | 5 | 3 |',
|
|
39
|
+
].join('\n')}\n\n`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
* 加粗按钮
|
|
19
|
+
*/
|
|
20
|
+
export default class Bold extends MenuBase {
|
|
21
|
+
constructor($cherry) {
|
|
22
|
+
super($cherry);
|
|
23
|
+
this.setName('bold', 'format_bold');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 是不是包含加粗语法
|
|
28
|
+
* @param {String} selection
|
|
29
|
+
* @returns {Boolean}
|
|
30
|
+
*/
|
|
31
|
+
$testIsBold(selection) {
|
|
32
|
+
return /^\s*(\*\*|__)[\s\S]+(\1)/.test(selection);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 响应点击事件
|
|
37
|
+
* @param {string} selection 被用户选中的文本内容
|
|
38
|
+
* @param {string} shortKey 快捷键参数,本函数不处理这个参数
|
|
39
|
+
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
40
|
+
*/
|
|
41
|
+
onClick(selection, shortKey = '') {
|
|
42
|
+
let $selection = this.getSelection(selection) || this.locale.bold;
|
|
43
|
+
// 如果是单选,并且选中内容的开始结束内没有加粗语法,则扩大选中范围
|
|
44
|
+
if (!this.isSelections && !this.$testIsBold($selection)) {
|
|
45
|
+
this.getMoreSelection('**', '**', () => {
|
|
46
|
+
const newSelection = this.editor.editor.getSelection();
|
|
47
|
+
const isBold = this.$testIsBold(newSelection);
|
|
48
|
+
if (isBold) {
|
|
49
|
+
$selection = newSelection;
|
|
50
|
+
}
|
|
51
|
+
return isBold;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
// 如果选中的文本中已经有加粗语法了,则去掉加粗语法
|
|
55
|
+
if (this.$testIsBold($selection)) {
|
|
56
|
+
return $selection.replace(/(^)(\s*)(\*\*|__)([^\n]+)(\3)(\s*)($)/gm, '$1$4$7');
|
|
57
|
+
}
|
|
58
|
+
this.registerAfterClickCb(() => {
|
|
59
|
+
this.setLessSelection('**', '**');
|
|
60
|
+
});
|
|
61
|
+
return $selection.replace(/(^)([^\n]+)($)/gm, '$1**$2**$3');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 声明绑定的快捷键,快捷键触发onClick
|
|
66
|
+
*/
|
|
67
|
+
get shortcutKeys() {
|
|
68
|
+
return ['Ctrl-b'];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
* 插入换行
|
|
19
|
+
*/
|
|
20
|
+
export default class Br extends MenuBase {
|
|
21
|
+
constructor($cherry) {
|
|
22
|
+
super($cherry);
|
|
23
|
+
this.setName('br', 'format_text_wrap');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 响应点击事件
|
|
28
|
+
* @param {string} selection 被用户选中的文本内容
|
|
29
|
+
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
30
|
+
*/
|
|
31
|
+
onClick(selection, shortKey = '') {
|
|
32
|
+
return `${selection}<br>`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
* 插入面板
|
|
19
|
+
*/
|
|
20
|
+
export default class Card extends MenuBase {
|
|
21
|
+
constructor($cherry) {
|
|
22
|
+
super($cherry);
|
|
23
|
+
this.setName('card', 'credit_card');
|
|
24
|
+
this.subMenuConfig = [
|
|
25
|
+
{
|
|
26
|
+
name: 'normalCard',
|
|
27
|
+
iconName: 'card_membership',
|
|
28
|
+
onclick: this.bindSubClick.bind(
|
|
29
|
+
this,
|
|
30
|
+
`
|
|
31
|
+
#list
|
|
32
|
+
[标题](链接) 描述
|
|
33
|
+
`,
|
|
34
|
+
),
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'noImageCard',
|
|
38
|
+
iconName: 'space_dashboard',
|
|
39
|
+
onclick: this.bindSubClick.bind(
|
|
40
|
+
this,
|
|
41
|
+
`
|
|
42
|
+
#list/1
|
|
43
|
+
[标题](链接) 描述
|
|
44
|
+
`,
|
|
45
|
+
),
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'imageCard',
|
|
49
|
+
iconName: 'badge',
|
|
50
|
+
onclick: this.bindSubClick.bind(
|
|
51
|
+
this,
|
|
52
|
+
`
|
|
53
|
+
#image/3
|
|
54
|
+
[查看详情](链接) 描述内容
|
|
55
|
+
`,
|
|
56
|
+
),
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
onClick(selection, shortKey) {
|
|
62
|
+
return `\`\`\`card${shortKey}\`\`\`\n`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
import { getListFromStr } from '@/utils/regexp';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 下标的按钮
|
|
22
|
+
**/
|
|
23
|
+
export default class Checklist extends MenuBase {
|
|
24
|
+
constructor($cherry) {
|
|
25
|
+
super($cherry);
|
|
26
|
+
this.setName('checklist', 'done_outline');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param {string} selection 被用户选中的文本内容
|
|
32
|
+
* @param {string} shortKey 快捷键参数,本函数不处理这个参数
|
|
33
|
+
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
34
|
+
*/
|
|
35
|
+
onClick(selection, shortKey = '') {
|
|
36
|
+
const $selection = getSelection(this.editor.editor, selection, 'line', true) || 'Item 1\n Item 1.1\nItem 2';
|
|
37
|
+
const [before] = $selection.match(/^\n*/);
|
|
38
|
+
const [after] = $selection.match(/\n*$/);
|
|
39
|
+
return `${before}${getListFromStr($selection, 'checklist')}${after}`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
* 插入代码块的按钮
|
|
19
|
+
*/
|
|
20
|
+
export default class Code extends MenuBase {
|
|
21
|
+
constructor($cherry) {
|
|
22
|
+
super($cherry);
|
|
23
|
+
this.setName('code', 'code');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 响应点击事件
|
|
28
|
+
* @param {string} selection 被用户选中的文本内容
|
|
29
|
+
* @param {string} shortKey 快捷键参数,本函数不处理这个参数
|
|
30
|
+
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
31
|
+
*/
|
|
32
|
+
onClick(selection, shortKey = '') {
|
|
33
|
+
const code = selection ? selection : 'code...';
|
|
34
|
+
this.registerAfterClickCb(() => {
|
|
35
|
+
this.setLessSelection(`\n\`\`\` \n`, `\n\`\`\`\n`);
|
|
36
|
+
});
|
|
37
|
+
return `\n\`\`\` \n${code}\n\`\`\`\n`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 声明绑定的快捷键,快捷键触发onClick
|
|
42
|
+
*/
|
|
43
|
+
get shortcutKeys() {
|
|
44
|
+
return ['Ctrl-k'];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
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
|
+
import Event from '@/Event';
|
|
19
|
+
/**
|
|
20
|
+
* 插入字体颜色或者字体背景颜色的按钮
|
|
21
|
+
*/
|
|
22
|
+
export default class Color extends MenuBase {
|
|
23
|
+
constructor($cherry) {
|
|
24
|
+
super($cherry);
|
|
25
|
+
this.setName('color', 'format_color_fill');
|
|
26
|
+
// this.bubbleMenu = true;
|
|
27
|
+
this.bubbleColor = new BubbleColor($cherry);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
$testIsColor(type, selection) {
|
|
31
|
+
const textReg = /^\s*!![^\s]+ [\s\S]+!!\s*$/;
|
|
32
|
+
const bgReg = /^\s*!!![^\s]+ [\s\S]+!!!\s*$/;
|
|
33
|
+
if (type === 'text') {
|
|
34
|
+
return textReg.test(selection) && !bgReg.test(selection);
|
|
35
|
+
}
|
|
36
|
+
return bgReg.test(selection);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 响应点击事件
|
|
41
|
+
* @param {string} selection 被用户选中的文本内容
|
|
42
|
+
* @param {string} shortKey 快捷键参数,本函数不处理这个参数
|
|
43
|
+
* @param {Event & {target:HTMLElement}} event 点击事件,用来从被点击的调色盘中获得对应的颜色
|
|
44
|
+
* @returns 回填到编辑器光标位置/选中文本区域的内容
|
|
45
|
+
*/
|
|
46
|
+
onClick(selection, shortKey = '', event) {
|
|
47
|
+
let $selection = getSelection(this.editor.editor, selection) || this.locale.color;
|
|
48
|
+
if (this.hasCacheOnce()) {
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
const { type, color } = this.getAndCleanCacheOnce();
|
|
51
|
+
const begin = type === 'text' ? `!!${color} ` : `!!!${color} `;
|
|
52
|
+
const end = type === 'text' ? '!!' : '!!!';
|
|
53
|
+
if (!this.isSelections && !this.$testIsColor(type, $selection)) {
|
|
54
|
+
this.getMoreSelection(begin, end, () => {
|
|
55
|
+
const newSelection = this.editor.editor.getSelection();
|
|
56
|
+
if (this.$testIsColor(type, newSelection)) {
|
|
57
|
+
$selection = newSelection;
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (this.$testIsColor(type, $selection)) {
|
|
64
|
+
const reg = new RegExp(`(^\\s*${end})([^\\s]+) ([\\s\\S]+${end}\\s*$)`, 'gm');
|
|
65
|
+
let needClean = true;
|
|
66
|
+
const tmp = $selection.replace(reg, (w, m1, m2, m3) => {
|
|
67
|
+
needClean = needClean ? m2 === color : false;
|
|
68
|
+
return `${m1}${color} ${m3}`;
|
|
69
|
+
});
|
|
70
|
+
if (needClean) {
|
|
71
|
+
return $selection.replace(reg, '$3').replace(/!+\s*$/gm, '');
|
|
72
|
+
}
|
|
73
|
+
this.registerAfterClickCb(() => {
|
|
74
|
+
this.setLessSelection(begin, end);
|
|
75
|
+
});
|
|
76
|
+
return tmp;
|
|
77
|
+
}
|
|
78
|
+
this.registerAfterClickCb(() => {
|
|
79
|
+
this.setLessSelection(begin, end);
|
|
80
|
+
});
|
|
81
|
+
return `${begin}${$selection}${end}`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 定位调色盘应该出现的位置
|
|
85
|
+
// 该按钮可能出现在顶部工具栏,
|
|
86
|
+
// 也可能出现在选中文字时出现的bubble工具栏,
|
|
87
|
+
// 也可能出现在新行出现的float工具栏
|
|
88
|
+
let top = 0;
|
|
89
|
+
let left = 0;
|
|
90
|
+
if (event.target.closest('.cherry-bubble')) {
|
|
91
|
+
const $colorDom = /** @type {HTMLElement}*/ (event.target.closest('.cherry-bubble'));
|
|
92
|
+
const clientRect = $colorDom.getBoundingClientRect();
|
|
93
|
+
top = clientRect.top + $colorDom.offsetHeight;
|
|
94
|
+
left =
|
|
95
|
+
/** @type {HTMLElement}*/ (event.target.closest('.cherry-toolbar-format_color_fill')).offsetLeft +
|
|
96
|
+
clientRect.left;
|
|
97
|
+
} else {
|
|
98
|
+
const $colorDom = /** @type {HTMLElement}*/ (event.target.closest('.cherry-toolbar-format_color_fill'));
|
|
99
|
+
const clientRect = $colorDom.getBoundingClientRect();
|
|
100
|
+
top = clientRect.top + $colorDom.offsetHeight;
|
|
101
|
+
left = clientRect.left;
|
|
102
|
+
}
|
|
103
|
+
this.updateMarkdown = false;
|
|
104
|
+
// 【TODO】需要增加getMoreSelection的逻辑
|
|
105
|
+
this.bubbleColor.show({
|
|
106
|
+
left,
|
|
107
|
+
top,
|
|
108
|
+
$color: this,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 调色盘
|
|
115
|
+
*/
|
|
116
|
+
class BubbleColor {
|
|
117
|
+
constructor($cherry) {
|
|
118
|
+
this.editor = $cherry.editor;
|
|
119
|
+
this.$cherry = $cherry;
|
|
120
|
+
this.init();
|
|
121
|
+
this.initAction();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 定义调色盘每个色块的颜色值
|
|
126
|
+
*/
|
|
127
|
+
colorStack = [
|
|
128
|
+
'#000000',
|
|
129
|
+
'#444444',
|
|
130
|
+
'#666666',
|
|
131
|
+
'#999999',
|
|
132
|
+
'#cccccc',
|
|
133
|
+
'#eeeeee',
|
|
134
|
+
'#f3f3f3',
|
|
135
|
+
'#ffffff',
|
|
136
|
+
'#ff0000',
|
|
137
|
+
'#ff9900',
|
|
138
|
+
'#ffff00',
|
|
139
|
+
'#00ff00',
|
|
140
|
+
'#00ffff',
|
|
141
|
+
'#0000ff',
|
|
142
|
+
'#9900ff',
|
|
143
|
+
'#ff00ff',
|
|
144
|
+
'#f4cccc',
|
|
145
|
+
'#fce5cd',
|
|
146
|
+
'#fff2cc',
|
|
147
|
+
'#d9ead3',
|
|
148
|
+
'#d0e0e3',
|
|
149
|
+
'#cfe2f3',
|
|
150
|
+
'#d9d2e9',
|
|
151
|
+
'#ead1dc',
|
|
152
|
+
'#ea9999',
|
|
153
|
+
'#f9cb9c',
|
|
154
|
+
'#ffe599',
|
|
155
|
+
'#b6d7a8',
|
|
156
|
+
'#a2c4c9',
|
|
157
|
+
'#9fc5e8',
|
|
158
|
+
'#b4a7d6',
|
|
159
|
+
'#d5a6bd',
|
|
160
|
+
'#e06666',
|
|
161
|
+
'#f6b26b',
|
|
162
|
+
'#ffd966',
|
|
163
|
+
'#93c47d',
|
|
164
|
+
'#76a5af',
|
|
165
|
+
'#6fa8dc',
|
|
166
|
+
'#8e7cc3',
|
|
167
|
+
'#c27ba0',
|
|
168
|
+
'#cc0000',
|
|
169
|
+
'#e69138',
|
|
170
|
+
'#f1c232',
|
|
171
|
+
'#6aa84f',
|
|
172
|
+
'#45818e',
|
|
173
|
+
'#3d85c6',
|
|
174
|
+
'#674ea7',
|
|
175
|
+
'#a64d79',
|
|
176
|
+
'#990000',
|
|
177
|
+
'#b45f06',
|
|
178
|
+
'#bf9000',
|
|
179
|
+
'#38761d',
|
|
180
|
+
'#134f5c',
|
|
181
|
+
'#0b5394',
|
|
182
|
+
'#351c75',
|
|
183
|
+
'#741b47',
|
|
184
|
+
'#660000',
|
|
185
|
+
'#783f04',
|
|
186
|
+
'#7f6000',
|
|
187
|
+
'#274e13',
|
|
188
|
+
'#0c343d',
|
|
189
|
+
'#073763',
|
|
190
|
+
'#20124d',
|
|
191
|
+
'#4c1130',
|
|
192
|
+
];
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 用来暂存选中的内容
|
|
196
|
+
* @param {string} selection 编辑区选中的文本内容
|
|
197
|
+
*/
|
|
198
|
+
setSelection(selection) {
|
|
199
|
+
this.selection = selection;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
getFontColorDom(title) {
|
|
203
|
+
const colorStackDOM = this.colorStack
|
|
204
|
+
.map(
|
|
205
|
+
(color) =>
|
|
206
|
+
`<span class="cherry-color-item cherry-color-item__${color.replace(
|
|
207
|
+
'#',
|
|
208
|
+
'',
|
|
209
|
+
)}" unselectable="on" data-val="${color}"
|
|
210
|
+
style="background-color:${color}"></span>`,
|
|
211
|
+
)
|
|
212
|
+
.join('');
|
|
213
|
+
return `<h3>${title}</h3>${colorStackDOM}`;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
getDom() {
|
|
217
|
+
const $colorWrap = document.createElement('div');
|
|
218
|
+
|
|
219
|
+
$colorWrap.classList.add('cherry-dropdown');
|
|
220
|
+
$colorWrap.classList.add('cherry-color-wrap');
|
|
221
|
+
const $textWrap = document.createElement('div');
|
|
222
|
+
$textWrap.classList.add('cherry-color-text');
|
|
223
|
+
$textWrap.innerHTML = this.getFontColorDom('文本颜色');
|
|
224
|
+
$colorWrap.appendChild($textWrap);
|
|
225
|
+
|
|
226
|
+
const $bgWrap = document.createElement('div');
|
|
227
|
+
$bgWrap.classList.add('cherry-color-bg');
|
|
228
|
+
$bgWrap.innerHTML = this.getFontColorDom('背景颜色');
|
|
229
|
+
$colorWrap.appendChild($bgWrap);
|
|
230
|
+
|
|
231
|
+
return $colorWrap;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
init() {
|
|
235
|
+
this.dom = this.getDom();
|
|
236
|
+
this.editor.options.wrapperDom.appendChild(this.dom);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
onClick() {
|
|
240
|
+
if (this.type === 'text') {
|
|
241
|
+
if (/^!!#\S+ [\s\S]+?!!/.test(this.selection)) {
|
|
242
|
+
return this.selection.replace(/^!!#\S+ ([\s\S]+?)!!/, `!!${this.colorValue} $1!!`);
|
|
243
|
+
}
|
|
244
|
+
return `!!${this.colorValue} ${this.selection}!!`;
|
|
245
|
+
}
|
|
246
|
+
if (/^!!!#\S+ [\s\S]+?!!!/.test(this.selection)) {
|
|
247
|
+
return this.selection.replace(/^!!!#\S+ ([\s\S]+?)!!!/, `!!!${this.colorValue} $1!!!`);
|
|
248
|
+
}
|
|
249
|
+
return `!!!${this.colorValue} ${this.selection}!!!`;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
initAction() {
|
|
253
|
+
// const self = this;
|
|
254
|
+
this.dom.addEventListener(
|
|
255
|
+
'click',
|
|
256
|
+
(evt) => {
|
|
257
|
+
const { target } = /** @type {MouseEvent & {target:HTMLElement}}*/ (evt);
|
|
258
|
+
this.colorValue = target.getAttribute('data-val');
|
|
259
|
+
if (!this.colorValue) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
this.type = target.closest('.cherry-color-text') ? 'text' : 'bg';
|
|
263
|
+
this.$color.setCacheOnce({ type: this.type, color: this.colorValue });
|
|
264
|
+
this.$color.fire(null);
|
|
265
|
+
},
|
|
266
|
+
false,
|
|
267
|
+
);
|
|
268
|
+
this.dom.addEventListener('EditorHideToolbarSubMenu', () => {
|
|
269
|
+
if (this.dom.style.display !== 'none') {
|
|
270
|
+
this.dom.style.display = 'none';
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* 在对应的坐标展示调色盘
|
|
277
|
+
* @param {Object} 坐标
|
|
278
|
+
*/
|
|
279
|
+
show({ left, top, $color }) {
|
|
280
|
+
this.dom.style.left = `${left}px`;
|
|
281
|
+
this.dom.style.top = `${top}px`;
|
|
282
|
+
this.dom.style.display = 'block';
|
|
283
|
+
this.$color = $color;
|
|
284
|
+
}
|
|
285
|
+
}
|