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,351 @@
|
|
|
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 { getCodeBlockRule } from '@/utils/regexp';
|
|
17
|
+
import codemirror from 'codemirror';
|
|
18
|
+
import { copyToClip } from '@/utils/copy';
|
|
19
|
+
import 'codemirror/keymap/sublime';
|
|
20
|
+
|
|
21
|
+
export default class CodeBlockHandler {
|
|
22
|
+
/**
|
|
23
|
+
* 用来存放所有的数据
|
|
24
|
+
*/
|
|
25
|
+
codeBlockEditor = {
|
|
26
|
+
info: {}, // 当前点击的预览区域code的相关信息
|
|
27
|
+
editorDom: {}, // 编辑器容器
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
constructor(trigger, target, container, previewerDom, codeMirror, parent) {
|
|
31
|
+
// 触发方式 click / hover
|
|
32
|
+
this.trigger = trigger;
|
|
33
|
+
this.target = target;
|
|
34
|
+
this.previewerDom = previewerDom;
|
|
35
|
+
this.container = container;
|
|
36
|
+
this.codeMirror = codeMirror;
|
|
37
|
+
this.$cherry = parent.previewer.$cherry;
|
|
38
|
+
this.parent = parent;
|
|
39
|
+
this.$initReg();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
$initReg() {
|
|
43
|
+
this.codeBlockReg = this.codeBlockReg ? this.codeBlockReg : getCodeBlockRule().reg;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
emit(type, event = {}, callback = () => {}) {
|
|
47
|
+
switch (type) {
|
|
48
|
+
case 'remove':
|
|
49
|
+
return this.$remove();
|
|
50
|
+
case 'scroll':
|
|
51
|
+
return this.$updateContainerPosition();
|
|
52
|
+
case 'previewUpdate':
|
|
53
|
+
this.$updateContainerPosition();
|
|
54
|
+
this.editing && this.$setInputOffset();
|
|
55
|
+
return;
|
|
56
|
+
case 'mouseup':
|
|
57
|
+
return this.$tryRemoveMe(event, callback);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
$remove() {
|
|
61
|
+
this.codeBlockEditor = { info: {}, codeBlockCodes: [], editorDom: {} };
|
|
62
|
+
}
|
|
63
|
+
$tryRemoveMe(event, callback) {
|
|
64
|
+
const dom = this.codeBlockEditor.editorDom.inputDiv;
|
|
65
|
+
if (this.editing && dom && !dom.contains(event.target)) {
|
|
66
|
+
this.editing = false;
|
|
67
|
+
this.$remove();
|
|
68
|
+
callback();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 定位代码块源代码在左侧Editor的位置
|
|
73
|
+
*/
|
|
74
|
+
$findCodeInEditor(selectLang = false) {
|
|
75
|
+
this.$collectCodeBlockDom();
|
|
76
|
+
this.$collectCodeBlockCode();
|
|
77
|
+
if (selectLang) {
|
|
78
|
+
this.$setLangSelection(this.codeBlockEditor.info.codeBlockIndex);
|
|
79
|
+
} else {
|
|
80
|
+
this.$setBlockSelection(this.codeBlockEditor.info.codeBlockIndex);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 找到预览区被点击编辑按钮的代码块,并记录这个代码块在预览区域所有代码块中的顺位
|
|
85
|
+
*/
|
|
86
|
+
$collectCodeBlockDom() {
|
|
87
|
+
const list = Array.from(this.previewerDom.querySelectorAll('[data-type="codeBlock"]'));
|
|
88
|
+
this.codeBlockEditor.info = {
|
|
89
|
+
codeBlockNode: this.target,
|
|
90
|
+
codeBlockIndex: list.indexOf(this.target),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
$collectCodeBlockCode() {
|
|
94
|
+
const codeBlockCodes = [];
|
|
95
|
+
this.codeMirror.getValue().replace(this.codeBlockReg, function (whole, ...args) {
|
|
96
|
+
const match = whole.replace(/^\n*/, '');
|
|
97
|
+
const offsetBegin = args[args.length - 2] + whole.match(/^\n*/)[0].length;
|
|
98
|
+
if (!match.startsWith('```mermaid')) {
|
|
99
|
+
codeBlockCodes.push({
|
|
100
|
+
code: match,
|
|
101
|
+
offset: offsetBegin,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
this.codeBlockEditor.codeBlockCodes = codeBlockCodes;
|
|
106
|
+
}
|
|
107
|
+
$setBlockSelection(index) {
|
|
108
|
+
const codeBlockCode = this.codeBlockEditor.codeBlockCodes[index];
|
|
109
|
+
const whole = this.codeMirror.getValue();
|
|
110
|
+
const beginLine = whole.slice(0, codeBlockCode.offset).match(/\n/g)?.length ?? 0;
|
|
111
|
+
const endLine = beginLine + codeBlockCode.code.match(/\n/g).length;
|
|
112
|
+
const endCh = codeBlockCode.code.slice(0, -3).match(/[^\n]+\n*$/)[0].length;
|
|
113
|
+
// 从下往上选中内容,这样当代码块内容很多时,选中整个代码块不会触发滚动条滚动
|
|
114
|
+
this.codeBlockEditor.info.selection = [
|
|
115
|
+
{ line: endLine - 1, ch: endCh },
|
|
116
|
+
{ line: beginLine + 1, ch: 0 },
|
|
117
|
+
];
|
|
118
|
+
this.codeMirror.setSelection(...this.codeBlockEditor.info.selection);
|
|
119
|
+
}
|
|
120
|
+
$setLangSelection(index) {
|
|
121
|
+
const codeBlockCode = this.codeBlockEditor.codeBlockCodes[index];
|
|
122
|
+
const whole = this.codeMirror.getValue();
|
|
123
|
+
const beginLine = whole.slice(0, codeBlockCode.offset).match(/\n/g)?.length ?? 0;
|
|
124
|
+
const firstLine = codeBlockCode.code.match(/```\s*[^\n]+/)[0] ?? '```';
|
|
125
|
+
const beginCh = 3;
|
|
126
|
+
const endLine = firstLine.length;
|
|
127
|
+
this.codeBlockEditor.info.selection = [
|
|
128
|
+
{ line: beginLine, ch: beginCh },
|
|
129
|
+
{ line: beginLine, ch: endLine },
|
|
130
|
+
];
|
|
131
|
+
this.codeMirror.setSelection(...this.codeBlockEditor.info.selection);
|
|
132
|
+
}
|
|
133
|
+
showBubble(isEnableBubbleAndEditorShow = true) {
|
|
134
|
+
this.$updateContainerPosition();
|
|
135
|
+
if (this.trigger === 'hover') {
|
|
136
|
+
this.$showBtn(isEnableBubbleAndEditorShow);
|
|
137
|
+
}
|
|
138
|
+
if (this.trigger === 'click') {
|
|
139
|
+
this.$showContentEditor();
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* 把代码块操作相关元素上的鼠标滚动事件同步到预览区
|
|
143
|
+
*/
|
|
144
|
+
this.container.addEventListener('wheel', (e) => {
|
|
145
|
+
e.stopPropagation();
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
this.previewerDom.scrollTop += e.deltaY / 3; // 降低滚动的速度,懒得加动画了
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 展示代码块编辑区的编辑器
|
|
152
|
+
*/
|
|
153
|
+
$showContentEditor() {
|
|
154
|
+
this.editing = true;
|
|
155
|
+
this.$findCodeInEditor();
|
|
156
|
+
this.$drawEditor();
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 展示代码块区域的按钮
|
|
160
|
+
*/
|
|
161
|
+
$showBtn(isEnableBubbleAndEditorShow) {
|
|
162
|
+
const { editCode, copyCode, expandCode } = this.target.dataset;
|
|
163
|
+
this.container.innerHTML = '';
|
|
164
|
+
if (editCode === 'true' && isEnableBubbleAndEditorShow) {
|
|
165
|
+
// 添加编辑btn
|
|
166
|
+
const editDom = document.createElement('div');
|
|
167
|
+
editDom.className = 'cherry-edit-code-block';
|
|
168
|
+
editDom.innerHTML = '<span class="material-symbols-outlined">edit</span>';
|
|
169
|
+
this.container.appendChild(editDom);
|
|
170
|
+
editDom.addEventListener('click', (e) => {
|
|
171
|
+
e.preventDefault();
|
|
172
|
+
e.stopPropagation();
|
|
173
|
+
this.$hideAllBtn();
|
|
174
|
+
this.$expandCodeBlock(true);
|
|
175
|
+
this.parent.$removeAllPreviewerBubbles('click');
|
|
176
|
+
this.parent.showCodeBlockPreviewerBubbles('click', this.target);
|
|
177
|
+
});
|
|
178
|
+
this.editDom = editDom;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (copyCode === 'true') {
|
|
182
|
+
// 添加复制btn
|
|
183
|
+
const copyDom = document.createElement('div');
|
|
184
|
+
copyDom.className = 'cherry-copy-code-block';
|
|
185
|
+
copyDom.innerHTML = '<span class="material-symbols-outlined">content_copy</span>';
|
|
186
|
+
this.container.appendChild(copyDom);
|
|
187
|
+
copyDom.addEventListener('click', (e) => {
|
|
188
|
+
e.preventDefault();
|
|
189
|
+
e.stopPropagation();
|
|
190
|
+
this.parent.$removeAllPreviewerBubbles('click');
|
|
191
|
+
this.$copyCodeBlock();
|
|
192
|
+
});
|
|
193
|
+
this.copyDom = copyDom;
|
|
194
|
+
}
|
|
195
|
+
if (expandCode === 'true') {
|
|
196
|
+
const isExpand = this.target.classList.contains('cherry-code-expand');
|
|
197
|
+
const maskDom = this.target.querySelector('.cherry-mask-code-block');
|
|
198
|
+
// 添加缩起btn
|
|
199
|
+
const unExpandDom = document.createElement('div');
|
|
200
|
+
unExpandDom.className = 'cherry-unExpand-code-block';
|
|
201
|
+
unExpandDom.innerHTML = '<span class=" expand-btn material-symbols-outlined">keyboard_arrow_up</span>';
|
|
202
|
+
if (!isExpand || !maskDom) {
|
|
203
|
+
unExpandDom.classList.add('hidden');
|
|
204
|
+
}
|
|
205
|
+
this.container.appendChild(unExpandDom);
|
|
206
|
+
unExpandDom.addEventListener('click', (e) => {
|
|
207
|
+
e.preventDefault();
|
|
208
|
+
e.stopPropagation();
|
|
209
|
+
this.parent.$removeAllPreviewerBubbles('click');
|
|
210
|
+
this.$expandCodeBlock(false);
|
|
211
|
+
});
|
|
212
|
+
this.unExpandDom = unExpandDom;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// 隐藏所有按钮(切换语言、编辑、复制)
|
|
216
|
+
$hideAllBtn() {
|
|
217
|
+
if (this.editDom?.style?.display) {
|
|
218
|
+
this.editDom.style.display = 'none';
|
|
219
|
+
}
|
|
220
|
+
if (this.copyDom?.style?.display) {
|
|
221
|
+
this.copyDom.style.display = 'none';
|
|
222
|
+
}
|
|
223
|
+
if (this.unExpandDom?.style?.display) {
|
|
224
|
+
this.unExpandDom.style.display = 'none';
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
$drawEditor() {
|
|
229
|
+
const dom = document.createElement('div');
|
|
230
|
+
dom.className = 'cherry-previewer-codeBlock-content-handler__input';
|
|
231
|
+
const input = document.createElement('textarea');
|
|
232
|
+
input.id = 'codeMirrorEditor';
|
|
233
|
+
dom.appendChild(input);
|
|
234
|
+
const editorInstance = codemirror.fromTextArea(input, {
|
|
235
|
+
mode: '',
|
|
236
|
+
theme: 'default',
|
|
237
|
+
scrollbarStyle: 'null', // 取消滚动动画
|
|
238
|
+
lineNumbers: true, // 显示行号
|
|
239
|
+
autofocus: true, // 自动对焦
|
|
240
|
+
lineWrapping: true, // 自动换行
|
|
241
|
+
cursorHeight: 0.85, // 光标高度,0.85好看一些
|
|
242
|
+
indentUnit: 4, // 缩进单位为4
|
|
243
|
+
tabSize: 4, // 一个tab转换成的空格数量
|
|
244
|
+
keyMap: 'sublime',
|
|
245
|
+
});
|
|
246
|
+
const editor = this.codeMirror;
|
|
247
|
+
editorInstance.on('change', () => {
|
|
248
|
+
editor.replaceSelection(editorInstance.getValue(), 'around');
|
|
249
|
+
});
|
|
250
|
+
this.codeBlockEditor.editorDom.inputDiv = dom;
|
|
251
|
+
this.codeBlockEditor.editorDom.inputDom = editorInstance;
|
|
252
|
+
this.$updateEditorPosition();
|
|
253
|
+
this.container.appendChild(this.codeBlockEditor.editorDom.inputDiv);
|
|
254
|
+
this.codeBlockEditor.editorDom.inputDom.focus();
|
|
255
|
+
this.codeBlockEditor.editorDom.inputDom.refresh();
|
|
256
|
+
editorInstance.setValue(this.codeMirror.getSelection());
|
|
257
|
+
// 去掉下面的逻辑,因为在代码块比较高时,强制让光标定位在最后会让页面出现跳跃的情况
|
|
258
|
+
// editorInstance.setCursor(Number.MAX_VALUE, Number.MAX_VALUE); // 指针设置至CodeBlock末尾
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* 处理扩展、缩起代码块的操作
|
|
263
|
+
*/
|
|
264
|
+
$expandCodeBlock(isExpand = true) {
|
|
265
|
+
if (!this.unExpandDom) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
this.target.classList.remove('cherry-code-unExpand');
|
|
269
|
+
this.target.classList.remove('cherry-code-expand');
|
|
270
|
+
this.unExpandDom.classList.remove('hidden');
|
|
271
|
+
if (isExpand) {
|
|
272
|
+
this.target.classList.add('cherry-code-expand');
|
|
273
|
+
} else {
|
|
274
|
+
this.unExpandDom.classList.add('hidden');
|
|
275
|
+
this.target.classList.add('cherry-code-unExpand');
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* 处理复制代码块的操作
|
|
280
|
+
*/
|
|
281
|
+
$copyCodeBlock() {
|
|
282
|
+
const codeContent = this.target.querySelector('pre').innerText;
|
|
283
|
+
const final = this.$cherry.options.callback.onCopyCode({ target: this.target }, codeContent);
|
|
284
|
+
if (final === false) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
const iconNode = this.copyDom.querySelector('span');
|
|
288
|
+
if (iconNode) {
|
|
289
|
+
iconNode.textContent = iconNode.textContent.replace('content_copy', 'done');
|
|
290
|
+
setTimeout(() => {
|
|
291
|
+
iconNode.textContent = iconNode.textContent.replace('done', 'content_copy');
|
|
292
|
+
}, 1000);
|
|
293
|
+
}
|
|
294
|
+
copyToClip(final);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* 更新代码块复制、编辑等按钮的位置
|
|
299
|
+
*/
|
|
300
|
+
$updateContainerPosition() {
|
|
301
|
+
this.codeBlockEditor.info.codeBlockNode = this.target;
|
|
302
|
+
const codeBlockInfo = this.$getPosition();
|
|
303
|
+
this.setStyle(this.container, 'width', `${codeBlockInfo.width}px`);
|
|
304
|
+
this.setStyle(this.container, 'top', `${codeBlockInfo.top}px`);
|
|
305
|
+
this.setStyle(this.container, 'left', `${codeBlockInfo.left}px`);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* 更新编辑器的位置(尺寸和位置)
|
|
310
|
+
*/
|
|
311
|
+
$updateEditorPosition() {
|
|
312
|
+
this.$setInputOffset();
|
|
313
|
+
const spanStyle = getComputedStyle(this.codeBlockEditor.info.codeBlockNode);
|
|
314
|
+
const editorWrapper = this.codeBlockEditor.editorDom.inputDom.getWrapperElement();
|
|
315
|
+
this.setStyle(editorWrapper, 'fontSize', spanStyle.fontSize || '16px');
|
|
316
|
+
this.setStyle(editorWrapper, 'fontFamily', spanStyle.fontFamily);
|
|
317
|
+
this.setStyle(editorWrapper, 'lineHeight', '1.8em');
|
|
318
|
+
this.setStyle(editorWrapper, 'zIndex', '1');
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* 设置codemirror偏移
|
|
323
|
+
*/
|
|
324
|
+
$setInputOffset() {
|
|
325
|
+
const codeBlockInfo = this.$getPosition();
|
|
326
|
+
const { inputDiv } = this.codeBlockEditor.editorDom;
|
|
327
|
+
// 设置文本框的大小
|
|
328
|
+
this.setStyle(inputDiv, 'width', `${codeBlockInfo.width}px`);
|
|
329
|
+
this.setStyle(inputDiv, 'height', `${codeBlockInfo.height + 10}px`);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
setStyle(element, property, value) {
|
|
333
|
+
const info = element.getBoundingClientRect();
|
|
334
|
+
if (info[property] !== value) {
|
|
335
|
+
element.style[property] = value;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
$getPosition() {
|
|
340
|
+
const node = this.codeBlockEditor.info.codeBlockNode;
|
|
341
|
+
const position = node.getBoundingClientRect();
|
|
342
|
+
const editorPosition = this.previewerDom.parentNode.getBoundingClientRect();
|
|
343
|
+
return {
|
|
344
|
+
top: position.top - editorPosition.top,
|
|
345
|
+
height: position.height,
|
|
346
|
+
width: position.width,
|
|
347
|
+
left: position.left - editorPosition.left,
|
|
348
|
+
maxHeight: editorPosition.height,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 用于lodash.mergeWith的customizer
|
|
19
|
+
* @param {any} objValue
|
|
20
|
+
* @param {any} srcValue
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export function customizer(objValue, srcValue) {
|
|
24
|
+
if (Array.isArray(srcValue)) {
|
|
25
|
+
return srcValue;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 检查本地有没有值
|
|
31
|
+
* @param {string} key
|
|
32
|
+
*/
|
|
33
|
+
export function testKeyInLocal(key) {
|
|
34
|
+
if (typeof localStorage !== 'undefined') {
|
|
35
|
+
return localStorage.getItem(`cherry-${key}`) !== null;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 保存是否经典换行
|
|
42
|
+
* @param {boolean} isClassicBr
|
|
43
|
+
*/
|
|
44
|
+
export function saveIsClassicBrToLocal(isClassicBr) {
|
|
45
|
+
if (typeof localStorage !== 'undefined') {
|
|
46
|
+
localStorage.setItem('cherry-classicBr', isClassicBr ? 'true' : 'false');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 是否经典换行
|
|
52
|
+
*/
|
|
53
|
+
export function getIsClassicBrFromLocal() {
|
|
54
|
+
let ret = 'false';
|
|
55
|
+
if (typeof localStorage !== 'undefined') {
|
|
56
|
+
ret = localStorage.getItem('cherry-classicBr');
|
|
57
|
+
}
|
|
58
|
+
return ret === 'true';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 保存当前主题
|
|
63
|
+
* @param {string} theme
|
|
64
|
+
*/
|
|
65
|
+
function saveThemeToLocal(theme) {
|
|
66
|
+
if (typeof localStorage !== 'undefined') {
|
|
67
|
+
localStorage.setItem('cherry-theme', theme);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 获取当前主题
|
|
73
|
+
* @returns {string} 主题名
|
|
74
|
+
*/
|
|
75
|
+
export function getThemeFromLocal(fullClass = false) {
|
|
76
|
+
let ret = 'default';
|
|
77
|
+
if (typeof localStorage !== 'undefined') {
|
|
78
|
+
const localTheme = localStorage.getItem('cherry-theme');
|
|
79
|
+
if (localTheme) {
|
|
80
|
+
ret = localTheme;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return fullClass ? `theme__${ret}` : ret;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 修改主题
|
|
88
|
+
* @param {object} $cherry
|
|
89
|
+
* @param {string} theme 如果没有传theme,则从本地缓存里取
|
|
90
|
+
*/
|
|
91
|
+
export function changeTheme($cherry, theme = '') {
|
|
92
|
+
const newTheme = (theme ? theme : getThemeFromLocal()).replace(/^.*theme__/, ' ');
|
|
93
|
+
const newClass = ` theme__${newTheme}`;
|
|
94
|
+
$cherry.wrapperDom.className = $cherry.wrapperDom.className.replace(/ theme__[^ $]+?( |$)/g, ' ') + newClass;
|
|
95
|
+
$cherry.previewer.getDomContainer().className =
|
|
96
|
+
$cherry.previewer.getDomContainer().className.replace(/ theme__[^ $]+?( |$)/g, ' ') + newClass;
|
|
97
|
+
saveThemeToLocal(newTheme);
|
|
98
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
/**
|
|
17
|
+
* 复制内容到剪贴板
|
|
18
|
+
* @returns null
|
|
19
|
+
*/
|
|
20
|
+
export function copyToClip(str) {
|
|
21
|
+
function listener(e) {
|
|
22
|
+
e.clipboardData.setData('text/html', str);
|
|
23
|
+
e.clipboardData.setData('text/plain', str);
|
|
24
|
+
e.preventDefault();
|
|
25
|
+
}
|
|
26
|
+
document.addEventListener('copy', listener);
|
|
27
|
+
document.execCommand('copy');
|
|
28
|
+
document.removeEventListener('copy', listener);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 复制文本内容到剪贴板
|
|
33
|
+
* @param {string} str 复制文本
|
|
34
|
+
*/
|
|
35
|
+
export function copyByInput(str) {
|
|
36
|
+
const input = document.createElement('input');
|
|
37
|
+
input.value = str;
|
|
38
|
+
document.body.appendChild(input);
|
|
39
|
+
input.select();
|
|
40
|
+
document.execCommand('copy');
|
|
41
|
+
document.body.removeChild(input);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 复制文本
|
|
46
|
+
* @param {string} str 复制文本
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
export async function copyTextByClipboard(str) {
|
|
50
|
+
if (!navigator.clipboard) {
|
|
51
|
+
copyByInput(str);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
return await navigator.clipboard.writeText(str);
|
|
55
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
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
|
+
|
|
17
|
+
import { createElement } from './dom';
|
|
18
|
+
|
|
19
|
+
const clamp = (num, min, max) => {
|
|
20
|
+
return Math.min(Math.max(num, min), max);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 对话框基操集合
|
|
25
|
+
*/
|
|
26
|
+
const dialog = {
|
|
27
|
+
open() {
|
|
28
|
+
this.resetStyle();
|
|
29
|
+
this.dom.style.display = 'block';
|
|
30
|
+
this.postMessage('ready?');
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
close() {
|
|
34
|
+
this.dom.style.display = 'none';
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
postMessage(messageName, value = '') {
|
|
38
|
+
this.iframeDom?.contentWindow?.postMessage({ eventName: messageName, value }, '*');
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
resetStyle() {
|
|
42
|
+
const { dom } = this;
|
|
43
|
+
dom.style.left = '10%';
|
|
44
|
+
dom.style.top = '10%';
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
bindEvents() {
|
|
48
|
+
this.bindClickEvents();
|
|
49
|
+
this.bindDNDEvents();
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
bindClickEvents() {
|
|
53
|
+
this.headCloseButton.addEventListener('click', () => {
|
|
54
|
+
this.close();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
this.footSureButton.addEventListener('click', () => {
|
|
58
|
+
this.postMessage('getData');
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
bindDNDEvents() {
|
|
63
|
+
const { dom, head, body } = this;
|
|
64
|
+
|
|
65
|
+
let offsetX;
|
|
66
|
+
let offsetY;
|
|
67
|
+
|
|
68
|
+
const handleMouseMove = function (e) {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
const left = clamp(e.clientX - offsetX, 0, window.innerWidth - 16);
|
|
71
|
+
const top = clamp(e.clientY - offsetY, 0, window.innerHeight - 16);
|
|
72
|
+
dom.style.left = `${left}px`;
|
|
73
|
+
dom.style.top = `${top}px`;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const handleMouseUp = function (e) {
|
|
77
|
+
head.style.cursor = 'grab';
|
|
78
|
+
body.style.pointerEvents = null;
|
|
79
|
+
|
|
80
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
81
|
+
document.removeEventListener('mousemove', handleMouseUp);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
head.addEventListener('mousedown', function (e) {
|
|
85
|
+
if (e.target.classList.contains('cherry-dialog--close')) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
offsetX = e.clientX - dom.offsetLeft;
|
|
89
|
+
offsetY = e.clientY - dom.offsetTop;
|
|
90
|
+
head.style.cursor = 'grabbing';
|
|
91
|
+
body.style.pointerEvents = 'none';
|
|
92
|
+
|
|
93
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
94
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
draw(params, onReady, onSubmit) {
|
|
99
|
+
const { iframeSrc, title } = params;
|
|
100
|
+
this.onSubmit = onSubmit;
|
|
101
|
+
this.onReady = onReady;
|
|
102
|
+
|
|
103
|
+
if (this.dom) {
|
|
104
|
+
const test = new RegExp(`${iframeSrc}$`, 'i');
|
|
105
|
+
if (!test.test(this.iframeDom.src)) {
|
|
106
|
+
this.iframeDom.src = iframeSrc;
|
|
107
|
+
}
|
|
108
|
+
this.open();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
// 添加通信事件
|
|
112
|
+
window.addEventListener('message', (event) => {
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
if (!event.data || !event.data.eventName) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
switch (event.data.eventName) {
|
|
119
|
+
case 'getData:success':
|
|
120
|
+
// @ts-ignore
|
|
121
|
+
this.onSubmit(event.data.value);
|
|
122
|
+
this.close();
|
|
123
|
+
case 'ready':
|
|
124
|
+
this.onReady();
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
// 构造页面元素
|
|
128
|
+
this.iframeDom = createElement('iframe', 'cherry-dialog-iframe', { src: iframeSrc, style: 'border: none;' });
|
|
129
|
+
this.dom = createElement('div', 'cherry-dialog', {
|
|
130
|
+
style: [
|
|
131
|
+
'z-index:9999',
|
|
132
|
+
'display: block',
|
|
133
|
+
'position: absolute',
|
|
134
|
+
'top: 10%;left: 10%;width: 80%;height: 80%;',
|
|
135
|
+
'background-color: #FFF',
|
|
136
|
+
'box-shadow: 0px 50px 100px -12px rgba(0,0,0,.05),0px 30px 60px -30px rgba(0,0,0,.1)',
|
|
137
|
+
'border-radius: 6px',
|
|
138
|
+
'border: 1px solid #ddd;',
|
|
139
|
+
].join(';'),
|
|
140
|
+
});
|
|
141
|
+
this.head = createElement('div', 'cherry-dialog--head', {
|
|
142
|
+
style: ['height: 30px', 'line-height: 30px', 'padding-left: 10px', 'padding-right: 10px', 'cursor: grab;'].join(
|
|
143
|
+
';',
|
|
144
|
+
),
|
|
145
|
+
});
|
|
146
|
+
this.body = createElement('div', 'cherry-dialog--body', {
|
|
147
|
+
style: ['position: absolute', 'bottom: 30px', 'top: 30px', 'left: 0', 'right: 0', 'overflow: hidden'].join(';'),
|
|
148
|
+
});
|
|
149
|
+
this.foot = createElement('div', 'cherry-dialog--foot', {
|
|
150
|
+
style: [
|
|
151
|
+
'height: 30px',
|
|
152
|
+
'line-height: 30px',
|
|
153
|
+
'padding-left: 10px',
|
|
154
|
+
'padding-right: 10px',
|
|
155
|
+
'position: absolute',
|
|
156
|
+
'bottom: 0',
|
|
157
|
+
'left: 0',
|
|
158
|
+
'right: 0',
|
|
159
|
+
].join(';'),
|
|
160
|
+
});
|
|
161
|
+
this.headTitle = createElement('span', 'cherry-dialog--title', { style: 'user-select:none;' });
|
|
162
|
+
this.headCloseButton = createElement('i', 'cherry-dialog--close ch-icon ch-icon-close', {
|
|
163
|
+
style: 'float: right;font-size: 12px;cursor: pointer;',
|
|
164
|
+
});
|
|
165
|
+
this.footSureButton = createElement('button', 'cherry-dialog--sure', {
|
|
166
|
+
style: [
|
|
167
|
+
'float: right',
|
|
168
|
+
'cursor: pointer',
|
|
169
|
+
'margin: 3px',
|
|
170
|
+
'background-color: #4d90fe',
|
|
171
|
+
'color: #FFF',
|
|
172
|
+
'border: 1px solid #4d90fe',
|
|
173
|
+
'border-radius: 2px',
|
|
174
|
+
'padding: 2px 15px',
|
|
175
|
+
'user-select:none',
|
|
176
|
+
].join(';'),
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
this.headCloseButton.title = '关闭';
|
|
180
|
+
this.footSureButton.textContent = '确定';
|
|
181
|
+
|
|
182
|
+
this.headTitle.textContent = title;
|
|
183
|
+
this.head.appendChild(this.headTitle);
|
|
184
|
+
this.head.appendChild(this.headCloseButton);
|
|
185
|
+
this.foot.appendChild(this.footSureButton);
|
|
186
|
+
|
|
187
|
+
this.body.appendChild(this.iframeDom);
|
|
188
|
+
this.dom.appendChild(this.head);
|
|
189
|
+
this.dom.appendChild(this.body);
|
|
190
|
+
this.dom.appendChild(this.foot);
|
|
191
|
+
|
|
192
|
+
this.bindEvents();
|
|
193
|
+
|
|
194
|
+
document.body.appendChild(this.dom);
|
|
195
|
+
},
|
|
196
|
+
};
|