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.
Files changed (226) hide show
  1. package/LICENSE +162 -0
  2. package/README.md +139 -0
  3. package/dist/addons/cherry-code-block-card-plugin.js +1 -0
  4. package/dist/addons/cherry-code-block-echarts-plugin.js +1 -0
  5. package/dist/addons/cherry-code-block-mermaid-plugin.js +1 -0
  6. package/dist/cherry-markdown.core.common.js +1 -0
  7. package/dist/cherry-markdown.core.js +1 -0
  8. package/dist/cherry-markdown.css +4089 -0
  9. package/dist/cherry-markdown.engine.core.common.js +1 -0
  10. package/dist/cherry-markdown.engine.core.esm.js +1 -0
  11. package/dist/cherry-markdown.engine.core.js +1 -0
  12. package/dist/cherry-markdown.esm.js +1 -0
  13. package/dist/cherry-markdown.js +70837 -0
  14. package/dist/cherry-markdown.js.map +1 -0
  15. package/dist/cherry-markdown.min.css +1 -0
  16. package/dist/cherry-markdown.min.js +1 -0
  17. package/dist/stats.html +4838 -0
  18. package/examples/scripts/pinyin/README.md +53 -0
  19. package/package.json +167 -0
  20. package/src/Cherry.config.js +411 -0
  21. package/src/Cherry.js +788 -0
  22. package/src/CherryStatic.js +70 -0
  23. package/src/Editor.js +746 -0
  24. package/src/Engine.js +334 -0
  25. package/src/Event.js +74 -0
  26. package/src/Factory.js +180 -0
  27. package/src/Logger.js +31 -0
  28. package/src/Previewer.js +1147 -0
  29. package/src/Sanitizer.js +4 -0
  30. package/src/Sanitizer.node.js +7 -0
  31. package/src/Stats.js +101 -0
  32. package/src/Theme.js +46 -0
  33. package/src/UrlCache.js +98 -0
  34. package/src/addons/cherry-code-block-card-plugin.js +213 -0
  35. package/src/addons/cherry-code-block-echarts-plugin.js +161 -0
  36. package/src/addons/cherry-code-block-mermaid-plugin.js +118 -0
  37. package/src/core/HookCenter.js +303 -0
  38. package/src/core/HooksConfig.js +106 -0
  39. package/src/core/ParagraphBase.js +314 -0
  40. package/src/core/SentenceBase.js +65 -0
  41. package/src/core/SyntaxBase.js +197 -0
  42. package/src/core/hooks/AutoLink.js +251 -0
  43. package/src/core/hooks/BackgroundColor.js +46 -0
  44. package/src/core/hooks/Badge.js +100 -0
  45. package/src/core/hooks/Blockquote.js +113 -0
  46. package/src/core/hooks/Br.js +85 -0
  47. package/src/core/hooks/CodeBlock.js +876 -0
  48. package/src/core/hooks/Color.js +78 -0
  49. package/src/core/hooks/CommentReference.js +96 -0
  50. package/src/core/hooks/Detail.js +138 -0
  51. package/src/core/hooks/Emoji.config.js +9388 -0
  52. package/src/core/hooks/Emoji.js +223 -0
  53. package/src/core/hooks/Emphasis.js +113 -0
  54. package/src/core/hooks/Footnote.js +125 -0
  55. package/src/core/hooks/FrontMatter.js +52 -0
  56. package/src/core/hooks/FrontMatterVars.js +82 -0
  57. package/src/core/hooks/Header.js +229 -0
  58. package/src/core/hooks/HighLight.js +37 -0
  59. package/src/core/hooks/Hr.js +52 -0
  60. package/src/core/hooks/HtmlBlock.js +159 -0
  61. package/src/core/hooks/Iframe.js +80 -0
  62. package/src/core/hooks/Image.js +276 -0
  63. package/src/core/hooks/InlineCode.js +45 -0
  64. package/src/core/hooks/InlineMath.js +142 -0
  65. package/src/core/hooks/Link.js +169 -0
  66. package/src/core/hooks/List.js +260 -0
  67. package/src/core/hooks/Mark.js +55 -0
  68. package/src/core/hooks/MathBlock.js +97 -0
  69. package/src/core/hooks/Panel.js +170 -0
  70. package/src/core/hooks/Paragraph.js +84 -0
  71. package/src/core/hooks/Ruby.js +34 -0
  72. package/src/core/hooks/Size.js +84 -0
  73. package/src/core/hooks/Strikethrough.js +54 -0
  74. package/src/core/hooks/Sub.js +47 -0
  75. package/src/core/hooks/SuggestList.js +317 -0
  76. package/src/core/hooks/Suggester.js +759 -0
  77. package/src/core/hooks/Sup.js +47 -0
  78. package/src/core/hooks/Table.js +315 -0
  79. package/src/core/hooks/Toc.js +290 -0
  80. package/src/core/hooks/Transfer.js +47 -0
  81. package/src/core/hooks/Underline.js +37 -0
  82. package/src/index.core.js +29 -0
  83. package/src/index.engine.core.js +62 -0
  84. package/src/index.engine.js +30 -0
  85. package/src/index.js +28 -0
  86. package/src/locales/index.js +21 -0
  87. package/src/locales/zh_CN.js +170 -0
  88. package/src/sass/cherry.scss +122 -0
  89. package/src/sass/components/bubble.scss +122 -0
  90. package/src/sass/components/codemirror.scss +628 -0
  91. package/src/sass/components/dropdown.scss +37 -0
  92. package/src/sass/components/editor.scss +78 -0
  93. package/src/sass/components/preview.scss +71 -0
  94. package/src/sass/components/prism.scss +142 -0
  95. package/src/sass/components/stats.scss +32 -0
  96. package/src/sass/components/toc.scss +184 -0
  97. package/src/sass/components/toolbar.scss +117 -0
  98. package/src/sass/core/AutoLink.scss +20 -0
  99. package/src/sass/core/BackgroundColor.scss +0 -0
  100. package/src/sass/core/Badge.scss +116 -0
  101. package/src/sass/core/Blockquote.scss +12 -0
  102. package/src/sass/core/Br.scss +0 -0
  103. package/src/sass/core/Card.scss +219 -0
  104. package/src/sass/core/CodeBlock.scss +205 -0
  105. package/src/sass/core/Color.scss +37 -0
  106. package/src/sass/core/CommentReference.scss +0 -0
  107. package/src/sass/core/Detail.scss +107 -0
  108. package/src/sass/core/Emoji.scss +127 -0
  109. package/src/sass/core/Emphasis.scss +9 -0
  110. package/src/sass/core/Footnote.scss +21 -0
  111. package/src/sass/core/FrontMatterVars.scss +19 -0
  112. package/src/sass/core/Header.scss +103 -0
  113. package/src/sass/core/HighLight.scss +0 -0
  114. package/src/sass/core/Hr.scss +10 -0
  115. package/src/sass/core/HtmlBlock.scss +0 -0
  116. package/src/sass/core/Iframe.scss +36 -0
  117. package/src/sass/core/Image.scss +59 -0
  118. package/src/sass/core/InlineCode.scss +10 -0
  119. package/src/sass/core/InlineMath.scss +11 -0
  120. package/src/sass/core/Link.scss +16 -0
  121. package/src/sass/core/List.scss +61 -0
  122. package/src/sass/core/Mark.scss +15 -0
  123. package/src/sass/core/MathBlock.scss +0 -0
  124. package/src/sass/core/Panel.scss +150 -0
  125. package/src/sass/core/Paragraph.scss +6 -0
  126. package/src/sass/core/Ruby.scss +0 -0
  127. package/src/sass/core/Size.scss +8 -0
  128. package/src/sass/core/Strikethrough.scss +0 -0
  129. package/src/sass/core/Sub.scss +5 -0
  130. package/src/sass/core/Suggester.scss +62 -0
  131. package/src/sass/core/Sup.scss +5 -0
  132. package/src/sass/core/Table.scss +127 -0
  133. package/src/sass/core/Toc.scss +28 -0
  134. package/src/sass/core/Transfer.scss +0 -0
  135. package/src/sass/core/Underline.scss +0 -0
  136. package/src/sass/google-fonts.scss +34 -0
  137. package/src/sass/index.scss +3 -0
  138. package/src/sass/prism/dark.scss +131 -0
  139. package/src/sass/prism/light.scss +143 -0
  140. package/src/sass/variables/colors.scss +96 -0
  141. package/src/toolbars/Bubble.js +232 -0
  142. package/src/toolbars/BubbleTable.js +147 -0
  143. package/src/toolbars/HookCenter.js +185 -0
  144. package/src/toolbars/MenuBase.js +357 -0
  145. package/src/toolbars/PreviewerBubble.js +558 -0
  146. package/src/toolbars/Toc.js +246 -0
  147. package/src/toolbars/Toolbar.js +401 -0
  148. package/src/toolbars/hooks/Audio.js +53 -0
  149. package/src/toolbars/hooks/Badge.js +80 -0
  150. package/src/toolbars/hooks/BarTable.js +41 -0
  151. package/src/toolbars/hooks/Bold.js +70 -0
  152. package/src/toolbars/hooks/Br.js +34 -0
  153. package/src/toolbars/hooks/Card.js +64 -0
  154. package/src/toolbars/hooks/CheckList.js +41 -0
  155. package/src/toolbars/hooks/Code.js +46 -0
  156. package/src/toolbars/hooks/Color.js +285 -0
  157. package/src/toolbars/hooks/Copy.js +139 -0
  158. package/src/toolbars/hooks/Detail.js +70 -0
  159. package/src/toolbars/hooks/ECharts.js +303 -0
  160. package/src/toolbars/hooks/Emoji.js +303 -0
  161. package/src/toolbars/hooks/Export.js +47 -0
  162. package/src/toolbars/hooks/File.js +54 -0
  163. package/src/toolbars/hooks/Formula.js +36 -0
  164. package/src/toolbars/hooks/FullScreen.js +55 -0
  165. package/src/toolbars/hooks/Graph.js +281 -0
  166. package/src/toolbars/hooks/H1.js +71 -0
  167. package/src/toolbars/hooks/H2.js +71 -0
  168. package/src/toolbars/hooks/H3.js +71 -0
  169. package/src/toolbars/hooks/Header.js +100 -0
  170. package/src/toolbars/hooks/Hr.js +35 -0
  171. package/src/toolbars/hooks/Iframe.js +35 -0
  172. package/src/toolbars/hooks/Image.js +60 -0
  173. package/src/toolbars/hooks/Insert.js +36 -0
  174. package/src/toolbars/hooks/Italic.js +70 -0
  175. package/src/toolbars/hooks/LineTable.js +41 -0
  176. package/src/toolbars/hooks/Link.js +46 -0
  177. package/src/toolbars/hooks/List.js +55 -0
  178. package/src/toolbars/hooks/Ol.js +41 -0
  179. package/src/toolbars/hooks/Panel.js +155 -0
  180. package/src/toolbars/hooks/Quote.js +45 -0
  181. package/src/toolbars/hooks/Redo.js +33 -0
  182. package/src/toolbars/hooks/Ruby.js +59 -0
  183. package/src/toolbars/hooks/Size.js +100 -0
  184. package/src/toolbars/hooks/Split.js +37 -0
  185. package/src/toolbars/hooks/Strikethrough.js +65 -0
  186. package/src/toolbars/hooks/Sub.js +58 -0
  187. package/src/toolbars/hooks/Sup.js +58 -0
  188. package/src/toolbars/hooks/SwitchModel.js +78 -0
  189. package/src/toolbars/hooks/Table.js +56 -0
  190. package/src/toolbars/hooks/Toc.js +35 -0
  191. package/src/toolbars/hooks/TogglePreview.js +79 -0
  192. package/src/toolbars/hooks/Ul.js +41 -0
  193. package/src/toolbars/hooks/Underline.js +65 -0
  194. package/src/toolbars/hooks/Undo.js +30 -0
  195. package/src/toolbars/hooks/Video.js +53 -0
  196. package/src/utils/LazyLoadImg.js +341 -0
  197. package/src/utils/autoindent.js +58 -0
  198. package/src/utils/codeBlockContentHandler.js +351 -0
  199. package/src/utils/config.js +98 -0
  200. package/src/utils/copy.js +55 -0
  201. package/src/utils/dialog.js +196 -0
  202. package/src/utils/dom.js +162 -0
  203. package/src/utils/downloadUtil.js +23 -0
  204. package/src/utils/env.js +22 -0
  205. package/src/utils/error.js +61 -0
  206. package/src/utils/event.js +38 -0
  207. package/src/utils/export.js +115 -0
  208. package/src/utils/file.js +121 -0
  209. package/src/utils/formulaUtilsHandler.js +230 -0
  210. package/src/utils/htmlparser.js +977 -0
  211. package/src/utils/image.js +99 -0
  212. package/src/utils/imgSizeHandler.js +279 -0
  213. package/src/utils/jsonUtils.js +17 -0
  214. package/src/utils/lineFeed.js +49 -0
  215. package/src/utils/listContentHandler.js +227 -0
  216. package/src/utils/lookbehind-replace.js +81 -0
  217. package/src/utils/mathjax.js +89 -0
  218. package/src/utils/myersDiff.js +211 -0
  219. package/src/utils/pasteHelper.js +253 -0
  220. package/src/utils/recount-pos.js +59 -0
  221. package/src/utils/regexp.js +295 -0
  222. package/src/utils/sanitize.js +477 -0
  223. package/src/utils/selection.js +50 -0
  224. package/src/utils/svgUtils.js +96 -0
  225. package/src/utils/tableContentHandler.js +592 -0
  226. package/tools/README.md +3 -0
@@ -0,0 +1,303 @@
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 { gfmUnicode } from '@/core/hooks/Emoji.config';
18
+ import { getEmoji } from '@/core/hooks/Emoji';
19
+
20
+ /**
21
+ * 插入Emoji的按钮
22
+ */
23
+ export default class Emoji extends MenuBase {
24
+ constructor($cherry) {
25
+ super($cherry);
26
+ this.setName('emoji', 'mood');
27
+ // this.bubbleMenu = true;
28
+ this.bubbleEmoji = new BubbleEmoji($cherry);
29
+ }
30
+
31
+ /**
32
+ * 响应点击事件
33
+ * @param {string} selection 被用户选中的文本内容
34
+ * @param {string} shortKey 快捷键参数,本函数不处理这个参数
35
+ * @param {Event & {target:HTMLElement}} event 点击事件,用来从被点击的调色盘中获得对应的颜色
36
+ * @returns string
37
+ */
38
+ onClick(selection, shortKey = '', event) {
39
+ if (this.hasCacheOnce()) {
40
+ // @ts-ignore
41
+ const { emoji } = this.getAndCleanCacheOnce();
42
+ return `:${emoji}:`;
43
+ }
44
+
45
+ let top = 0;
46
+ let left = 0;
47
+ if (event.target.closest('.cherry-bubble')) {
48
+ const $emojiDom = /** @type {HTMLElement}*/ (event.target.closest('.cherry-bubble'));
49
+ const clientRect = $emojiDom.getBoundingClientRect();
50
+ top = clientRect.top + $emojiDom.offsetHeight;
51
+ left = /** @type {HTMLElement}*/ (event.target.closest('.cherry-toolbar-mood')).offsetLeft + clientRect.left;
52
+ } else {
53
+ const $emojiDom = /** @type {HTMLElement}*/ (event.target.closest('.cherry-toolbar-mood'));
54
+ const clientRect = $emojiDom.getBoundingClientRect();
55
+ top = clientRect.top + $emojiDom.offsetHeight;
56
+ left = clientRect.left;
57
+ }
58
+ this.updateMarkdown = false;
59
+ this.bubbleEmoji.show({
60
+ left,
61
+ top,
62
+ $emoji: this,
63
+ });
64
+ }
65
+ }
66
+
67
+ /**
68
+ * 调色盘
69
+ */
70
+ class BubbleEmoji {
71
+ constructor($cherry) {
72
+ this.editor = $cherry.editor;
73
+ this.$cherry = $cherry;
74
+ this.init();
75
+ this.initAction();
76
+ }
77
+
78
+ /**
79
+ * 用来暂存选中的内容
80
+ * @param {string} selection 编辑区选中的文本内容
81
+ */
82
+ setSelection(selection) {
83
+ this.selection = selection;
84
+ }
85
+
86
+ getEmojiDom() {
87
+ let htmlHeader = `<div class="cherry-emoji-header">`;
88
+ const htmlSearch = `<div class="cherry-emoji-search"><input type="text" placeholder="搜索表情" class="cherry-emoji-search-input"></div>`;
89
+ let htmlBody = `<div class="cherry-emoji-body">`;
90
+ const emojiStackDOM = Object.entries(this.categorizedEmojis)
91
+ .map(([category, emojis]) => {
92
+ let icon = '';
93
+ switch (category) {
94
+ case 'Smileys & Emotion':
95
+ icon = 'sentiment_satisfied';
96
+ break;
97
+ case 'People & Body':
98
+ icon = 'person';
99
+ break;
100
+ case 'Animals & Nature':
101
+ icon = 'pets';
102
+ break;
103
+ case 'Food & Drink':
104
+ icon = 'restaurant_menu';
105
+ break;
106
+ case 'Travel & Places':
107
+ icon = 'directions_car';
108
+ break;
109
+ case 'Activities':
110
+ icon = 'sports_basketball';
111
+ break;
112
+ case 'Objects':
113
+ icon = 'emoji_objects';
114
+ break;
115
+ case 'Symbols':
116
+ icon = 'favorite';
117
+ break;
118
+ case 'Flags':
119
+ icon = 'flag';
120
+ break;
121
+ default:
122
+ icon = 'sentiment_satisfied';
123
+ break;
124
+ }
125
+
126
+ htmlHeader += `<button class="cherry-emoji-item-btn cherry-emoji-item_${icon}" ><span class="material-symbols-outlined">
127
+ ${icon}
128
+ </span></button>`;
129
+
130
+ let html = `
131
+ <div class="cherry-emoji-panel cherry-emoji-item_${icon}">
132
+ <div class="cherry-emoji-category">${category}</div>
133
+ <div class="cherry-emoji-container">
134
+ `;
135
+ html += emojis
136
+ .map((emoji) => {
137
+ return `<span class="cherry-emoji-item" data-emoji="${emoji.e}" data-alias="${emoji.a[0]}">${getEmoji(
138
+ emoji.e,
139
+ this.$cherry.options.engine.syntax.emoji,
140
+ true,
141
+ )}</span>`;
142
+ })
143
+ .join('');
144
+
145
+ html += `
146
+ </div>
147
+ </div>
148
+ `;
149
+
150
+ return html;
151
+ })
152
+ .join('');
153
+ htmlHeader += `</div>`;
154
+ htmlBody += emojiStackDOM;
155
+ htmlBody += `<div class="cherry-emoji-panel cherry-emoji-item_search">
156
+ <div class="cherry-emoji-category">搜索</div>
157
+ <div class="cherry-emoji-container">`;
158
+
159
+ htmlBody += `</div></div>`;
160
+ return htmlHeader + htmlSearch + htmlBody;
161
+ }
162
+
163
+ getDom() {
164
+ const $colorWrap = document.createElement('div');
165
+ $colorWrap.classList.add('cherry-dropdown');
166
+ $colorWrap.classList.add('cherry-emoji-wrap');
167
+
168
+ const $textWrap = document.createElement('div');
169
+ $textWrap.innerHTML = this.getEmojiDom();
170
+ $colorWrap.appendChild($textWrap);
171
+
172
+ return $colorWrap;
173
+ }
174
+
175
+ init() {
176
+ // 使用reduce方法对数组进行分类
177
+ this.categorizedEmojis = gfmUnicode.emojis;
178
+ this.dom = this.getDom();
179
+ this.editor.options.wrapperDom.appendChild(this.dom);
180
+ this.setActive('.cherry-emoji-item_sentiment_satisfied');
181
+ }
182
+
183
+ onClick() {
184
+ return `:${this.emojiKey}:`;
185
+ }
186
+
187
+ removeAllActive() {
188
+ this.dom.querySelectorAll('.cherry-emoji-panel').forEach((item) => {
189
+ item.classList.remove('show');
190
+ });
191
+ this.dom.querySelectorAll('.cherry-emoji-item-btn').forEach((item) => {
192
+ item.classList.remove('show');
193
+ });
194
+ }
195
+
196
+ setActive(className) {
197
+ this.dom.querySelectorAll(className).forEach((item) => {
198
+ item.classList.add('show');
199
+ });
200
+ }
201
+
202
+ initAction() {
203
+ // const self = this;
204
+ this.dom.addEventListener(
205
+ 'click',
206
+ (evt) => {
207
+ const { target } = /** @type {MouseEvent & {target:HTMLElement}}*/ (evt);
208
+
209
+ // 点击emoji
210
+
211
+ let targetClassList = target.classList;
212
+ if (target.parentElement.classList.contains('cherry-emoji-item-btn')) {
213
+ targetClassList = target.parentElement.classList;
214
+ }
215
+
216
+ if (targetClassList.contains('cherry-emoji-item-btn')) {
217
+ this.removeAllActive();
218
+ for (let i = 0; i < targetClassList.length; i++) {
219
+ const item = targetClassList[i];
220
+ if (item.startsWith('cherry-emoji-item_')) {
221
+ const selector = `.${item}`;
222
+ this.setActive(selector);
223
+ break; // 退出循环
224
+ }
225
+ }
226
+ return false;
227
+ }
228
+
229
+ this.emojiValue = target.getAttribute('data-emoji');
230
+ this.emojiKey = target.getAttribute('data-alias');
231
+ if (!this.emojiValue || !this.emojiKey) {
232
+ return false;
233
+ }
234
+ this.$emoji.setCacheOnce({ emoji: this.emojiKey });
235
+ this.$emoji.fire(null);
236
+ },
237
+ true,
238
+ );
239
+ this.dom.addEventListener('EditorHideToolbarSubMenu', () => {
240
+ if (this.dom.style.display !== 'none') {
241
+ this.dom.style.display = 'none';
242
+ }
243
+ });
244
+ const input = this.dom.querySelector('.cherry-emoji-search-input');
245
+ input.addEventListener('focus', (evt) => {
246
+ this.removeAllActive();
247
+ this.setActive('.cherry-emoji-item_search');
248
+ });
249
+ input.addEventListener('input', (evt) => {
250
+ const { value } = input;
251
+ if (value === '') {
252
+ return;
253
+ }
254
+ const searchResult = this.searchEmoji(value);
255
+ const html = searchResult
256
+ .map((emoji) => {
257
+ return `<span class="cherry-emoji-item" data-emoji="${emoji.emoji}" data-alias="${
258
+ emoji.aliases[0]
259
+ }">${getEmoji(emoji.emoji, this.$cherry.options.engine.syntax.emoji, true)}</span>`;
260
+ })
261
+ .join('');
262
+ const searchPanel = this.dom.querySelector('.cherry-emoji-item_search .cherry-emoji-container');
263
+ searchPanel.innerHTML = html;
264
+ });
265
+ }
266
+ searchEmoji(value) {
267
+ const searchResult = [];
268
+ // gfmUnicode.emojis 是一个对象,而不是数组,需要使用 Object.values() 来遍历
269
+ Object.values(gfmUnicode.emojis).forEach((emojiGroup) => {
270
+ emojiGroup.forEach((emoji) => {
271
+ // 检查别名
272
+ if (emoji.a.some((alias) => alias.includes(value))) {
273
+ searchResult.push({
274
+ emoji: emoji.e,
275
+ aliases: emoji.a,
276
+ tags: emoji.t || [],
277
+ });
278
+ return;
279
+ }
280
+ // 检查标签
281
+ if ((emoji.t || []).some((tag) => tag.includes(value))) {
282
+ searchResult.push({
283
+ emoji: emoji.e,
284
+ aliases: emoji.a,
285
+ tags: emoji.t || [],
286
+ });
287
+ }
288
+ });
289
+ });
290
+ return searchResult;
291
+ }
292
+
293
+ /**
294
+ * 在对应的坐标展示调色盘
295
+ * @param {Object} 坐标
296
+ */
297
+ show({ left, top, $emoji }) {
298
+ this.dom.style.left = `${left}px`;
299
+ this.dom.style.top = `${top}px`;
300
+ this.dom.style.display = 'block';
301
+ this.$emoji = $emoji;
302
+ }
303
+ }
@@ -0,0 +1,47 @@
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', 'ios_share');
22
+ this.updateMarkdown = false;
23
+ this.subMenuConfig = [
24
+ { iconName: 'picture_as_pdf', name: 'exportToPdf', onclick: this.bindSubClick.bind(this, 'pdf') },
25
+ { iconName: 'markdown', name: 'exportMarkdownFile', onclick: this.bindSubClick.bind(this, 'markdown') },
26
+ { iconName: 'html', name: 'exportHTMLFile', onclick: this.bindSubClick.bind(this, 'html') },
27
+ ];
28
+ }
29
+
30
+ onClick(shortKey = '', type) {
31
+ if (document.querySelector('.cherry-dropdown[name=export]')) {
32
+ /** @type {HTMLElement}*/ (document.querySelector('.cherry-dropdown[name=export]')).style.display = 'none';
33
+ }
34
+ // 强制刷新一下预览区域的内容
35
+ const { previewer } = this.$cherry;
36
+ let html = '';
37
+ if (previewer.isPreviewerHidden()) {
38
+ html = previewer.options.previewerCache.html;
39
+ } else {
40
+ html = previewer.getDomContainer().innerHTML;
41
+ }
42
+ // 需要未加载的图片替换成原始图片
43
+ html = previewer.lazyLoadImg.changeDataSrc2Src(html);
44
+ previewer.refresh(html);
45
+ previewer.export(type);
46
+ }
47
+ }
@@ -0,0 +1,54 @@
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, handleParams, splitFileName } from '@/utils/file';
18
+ /**
19
+ * 插入文件
20
+ */
21
+ export default class Video extends MenuBase {
22
+ constructor($cherry) {
23
+ super($cherry);
24
+ this.setName('file', 'attach_file');
25
+ }
26
+
27
+ /**
28
+ * 响应点击事件
29
+ * @param {string} selection 被用户选中的文本内容
30
+ * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
31
+ */
32
+ onClick(selection, shortKey = '') {
33
+ if (this.hasCacheOnce()) {
34
+ // @ts-ignore
35
+ const { name, url, params } = this.getAndCleanCacheOnce();
36
+ const begin = '!file[';
37
+ const end = `](${url})`;
38
+ this.registerAfterClickCb(() => {
39
+ this.setLessSelection(begin, end);
40
+ });
41
+ const finalName = params.name ? params.name : name;
42
+ const { title, ext } = splitFileName(finalName);
43
+ return `${begin}${title}|${ext}${handleParams(params)}${end}`;
44
+ }
45
+ const accept = this.$cherry.options?.fileTypeLimitMap?.file ?? '*';
46
+ // 插入图片,调用上传文件逻辑
47
+ handleUpload(this.editor, 'file', accept, (name, url, params) => {
48
+ this.setCacheOnce({ name, url, params });
49
+ this.fire(null);
50
+ });
51
+ this.updateMarkdown = false;
52
+ return selection;
53
+ }
54
+ }
@@ -0,0 +1,36 @@
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 Formula extends MenuBase {
21
+ constructor($cherry) {
22
+ super($cherry);
23
+ this.setName('formula', 'function');
24
+ }
25
+
26
+ /**
27
+ * 响应点击事件
28
+ * @param {string} selection 被用户选中的文本内容
29
+ * @param {string} shortKey 快捷键参数
30
+ * @param {Function} [callback] 回调函数
31
+ * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
32
+ */
33
+ onClick(selection, shortKey = '', callback) {
34
+ return `${selection}\n\n$ e=mc^2 $\n\n`;
35
+ }
36
+ }
@@ -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
+ import MenuBase from '@/toolbars/MenuBase';
17
+ import { createElement } from '@/utils/dom';
18
+ /**
19
+ * 全屏按钮
20
+ */
21
+ export default class FullScreen extends MenuBase {
22
+ constructor($cherry) {
23
+ super($cherry);
24
+ this.updateMarkdown = false;
25
+ this.setName('fullScreen', 'fullscreen');
26
+ }
27
+
28
+ /**
29
+ * 响应点击事件
30
+ */
31
+ onClick() {
32
+ const cherryClass = this.editor.options.editorDom.parentElement.classList;
33
+ const cherryToolbarFullscreen = document.querySelector('.cherry-toolbar-fullscreen');
34
+
35
+ // 清空 cherryToolbarFullscreen 元素
36
+ while (cherryToolbarFullscreen.firstChild) {
37
+ cherryToolbarFullscreen.removeChild(cherryToolbarFullscreen.firstChild);
38
+ }
39
+
40
+ // 根据 cherryClass 中是否包含 'fullscreen' 类来决定创建哪种图标
41
+ if (cherryClass.contains('fullscreen')) {
42
+ const fullScreen = createElement('i', 'material-symbols-outlined');
43
+ fullScreen.innerText = 'fullscreen'; // 设置图标的文本
44
+ cherryToolbarFullscreen.appendChild(fullScreen);
45
+ cherryClass.remove('fullscreen');
46
+ } else {
47
+ const minScreen = createElement('i', 'material-symbols-outlined');
48
+ minScreen.innerText = 'close_fullscreen'; // 设置图标的文本
49
+ cherryToolbarFullscreen.appendChild(minScreen);
50
+ cherryClass.add('fullscreen');
51
+ }
52
+
53
+ this.editor.editor.refresh();
54
+ }
55
+ }