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,281 @@
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
+ * 本功能依赖[Mermaid.js](https://mermaid-js.github.io)组件,请保证调用CherryMarkdown前已加载mermaid.js组件
21
+ */
22
+ export default class Graph extends MenuBase {
23
+ constructor($cherry) {
24
+ super($cherry);
25
+ this.setName('graph', 'account_tree');
26
+ this.localeName = $cherry.options.locale;
27
+ this.subMenuConfig = [
28
+ // 流程图
29
+ // 访问[Mermaid 流程图](https://mermaid-js.github.io/mermaid/#/flowchart)参考具体使用方法。
30
+ {
31
+ iconName: 'device_hub',
32
+ name: 'insertFlow',
33
+ onclick: this.bindSubClick.bind(
34
+ this,
35
+ `flowchart TD
36
+ Start --> Stop
37
+ `,
38
+ ),
39
+ },
40
+ // 时序图
41
+ // 访问[Mermaid 时序图](https://mermaid-js.github.io/mermaid/#/sequenceDiagram)参考具体使用方法
42
+ {
43
+ iconName: 'pending_actions',
44
+ name: 'insertSeq',
45
+ onclick: this.bindSubClick.bind(
46
+ this,
47
+ `sequenceDiagram
48
+ Alice->>John: Hello John, how are you?
49
+ John-->>Alice: Great!
50
+ Alice-)John: See you later!
51
+ `,
52
+ ),
53
+ },
54
+ // 状态图
55
+ // 访问[Mermaid 状态图](https://mermaid-js.github.io/mermaid/#/stateDiagram)参考具体使用方法
56
+ {
57
+ iconName: 'location_away',
58
+ name: 'insertState',
59
+ onclick: this.bindSubClick.bind(
60
+ this,
61
+ `stateDiagram-v2
62
+ s1 --> s2: A transition`,
63
+ ),
64
+ },
65
+ // 类图
66
+ // 访问[Mermaid UML图](https://mermaid-js.github.io/mermaid/#/classDiagram)参考具体使用方法
67
+ {
68
+ iconName: 'code',
69
+ name: 'insertClass',
70
+ onclick: this.bindSubClick.bind(
71
+ this,
72
+ `classDiagram
73
+ class Animal
74
+ Vehicle <|-- Car`,
75
+ ),
76
+ },
77
+ // 饼图
78
+ // 访问[Mermaid 饼图](https://mermaid-js.github.io/mermaid/#/pie)参考具体使用方法
79
+ {
80
+ iconName: 'pie_chart',
81
+ name: 'insertPie',
82
+ onclick: this.bindSubClick.bind(
83
+ this,
84
+ `pie title Pets adopted by volunteers
85
+ "Dogs" : 386
86
+ "Cats" : 85
87
+ "Rats" : 15`,
88
+ ),
89
+ },
90
+ // 甘特图
91
+ {
92
+ iconName: 'view_timeline',
93
+ name: 'insertGantt',
94
+ onclick: this.bindSubClick.bind(
95
+ this,
96
+ `gantt
97
+ title A Gantt Diagram
98
+ dateFormat YYYY-MM-DD
99
+ section Section
100
+ A task :a1, 2014-01-01, 30d
101
+ Another task :after a1, 20d
102
+ section Another
103
+ Task in Another :2014-01-12, 12d
104
+ another task :24d`,
105
+ ),
106
+ },
107
+ {
108
+ iconName: 'schema',
109
+ name: 'insertErDiagram',
110
+ onclick: this.bindSubClick.bind(
111
+ this,
112
+ `---
113
+ title: Order example
114
+ ---
115
+ erDiagram
116
+ CUSTOMER ||--o{ ORDER : places
117
+ ORDER ||--|{ LINE-ITEM : contains
118
+ CUSTOMER }|..|{ DELIVERY-ADDRESS : uses`,
119
+ ),
120
+ },
121
+ {
122
+ iconName: 'waterfall_chart',
123
+ name: 'insertJourney',
124
+ onclick: this.bindSubClick.bind(
125
+ this,
126
+ `journey
127
+ title My working day
128
+ section Go to work
129
+ Make tea: 5: Me
130
+ Go upstairs: 3: Me
131
+ Do work: 1: Me, Cat
132
+ section Go home
133
+ Go downstairs: 5: Me
134
+ Sit down: 5: Me`,
135
+ ),
136
+ },
137
+ {
138
+ iconName: 'square',
139
+ name: 'insertQuadrantChart',
140
+ onclick: this.bindSubClick.bind(
141
+ this,
142
+ `quadrantChart
143
+ title Reach and engagement of campaigns
144
+ x-axis Low Reach --> High Reach
145
+ y-axis Low Engagement --> High Engagement
146
+ quadrant-1 We should expand
147
+ quadrant-2 Need to promote
148
+ quadrant-3 Re-evaluate
149
+ quadrant-4 May be improved
150
+ Campaign A: [0.3, 0.6]
151
+ Campaign B: [0.45, 0.23]
152
+ Campaign C: [0.57, 0.69]
153
+ Campaign D: [0.78, 0.34]
154
+ Campaign E: [0.40, 0.34]
155
+ Campaign F: [0.35, 0.78]`,
156
+ ),
157
+ },
158
+ {
159
+ iconName: 'flowsheet',
160
+ name: 'insertRequirementDiagram',
161
+ onclick: this.bindSubClick.bind(
162
+ this,
163
+ ` requirementDiagram
164
+
165
+ requirement test_req {
166
+ id: 1
167
+ text: the test text.
168
+ risk: high
169
+ verifymethod: test
170
+ }
171
+
172
+ element test_entity {
173
+ type: simulation
174
+ }
175
+
176
+ test_entity - satisfies -> test_req`,
177
+ ),
178
+ },
179
+ {
180
+ iconName: 'linked_services',
181
+ name: 'insertGitGraph',
182
+ onclick: this.bindSubClick.bind(
183
+ this,
184
+ ` gitGraph
185
+ commit
186
+ commit
187
+ commit`,
188
+ ),
189
+ },
190
+ {
191
+ iconName: 'bid_landscape',
192
+ name: 'insertC4Dynamic',
193
+ onclick: this.bindSubClick.bind(
194
+ this,
195
+ ` C4Dynamic
196
+ title Dynamic diagram for Internet Banking System - API Application
197
+
198
+ ContainerDb(c4, "Database", "Relational Database Schema", "Stores user registration information, hashed authentication credentials, access logs, etc.")
199
+ Container(c1, "Single-Page Application", "JavaScript and Angular", "Provides all of the Internet banking functionality to customers via their web browser.")
200
+ Container_Boundary(b, "API Application") {
201
+ Component(c3, "Security Component", "Spring Bean", "Provides functionality Related to signing in, changing passwords, etc.")
202
+ Component(c2, "Sign In Controller", "Spring MVC Rest Controller", "Allows users to sign in to the Internet Banking System.")
203
+ }
204
+ Rel(c1, c2, "Submits credentials to", "JSON/HTTPS")
205
+ Rel(c2, c3, "Calls isAuthenticated() on")
206
+ Rel(c3, c4, "select * from users where username = ?", "JDBC")
207
+
208
+ UpdateRelStyle(c1, c2, $textColor="red", $offsetY="-40")
209
+ UpdateRelStyle(c2, c3, $textColor="red", $offsetX="-40", $offsetY="60")
210
+ UpdateRelStyle(c3, c4, $textColor="red", $offsetY="-40", $offsetX="10")`,
211
+ ),
212
+ },
213
+ {
214
+ iconName: 'mindfulness',
215
+ name: 'insertMindmap',
216
+ onclick: this.bindSubClick.bind(
217
+ this,
218
+ `mindmap
219
+ Root
220
+ A
221
+ B
222
+ C`,
223
+ ),
224
+ },
225
+ {
226
+ iconName: 'chart_data',
227
+ name: 'insertXyChart',
228
+ onclick: this.bindSubClick.bind(
229
+ this,
230
+ `xychart-beta
231
+ title "Sales Revenue"
232
+ x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
233
+ y-axis "Revenue (in $)" 4000 --> 11000
234
+ bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
235
+ line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]`,
236
+ ),
237
+ },
238
+ {
239
+ iconName: 'view_timeline',
240
+ name: 'insertTimeline',
241
+ onclick: this.bindSubClick.bind(
242
+ this,
243
+ `timeline
244
+ title History of Social Media Platform
245
+ 2002 : LinkedIn
246
+ 2004 : Facebook
247
+ : Google
248
+ 2005 : Youtube
249
+ 2006 : Twitter`,
250
+ ),
251
+ },
252
+ {
253
+ iconName: 'full_stacked_bar_chart',
254
+ name: 'insertSankey',
255
+ onclick: this.bindSubClick.bind(
256
+ this,
257
+ `sankey-beta
258
+
259
+ %% source,target,value
260
+ Electricity grid,Over generation / exports,104.453
261
+ Electricity grid,Heating and cooling - homes,113.726
262
+ Electricity grid,H2 conversion,27.14`,
263
+ ),
264
+ },
265
+ ];
266
+ }
267
+
268
+ getSubMenuConfig() {
269
+ return this.subMenuConfig;
270
+ }
271
+
272
+ /**
273
+ * 响应点击事件
274
+ * @param {string} selection 被用户选中的文本内容,本函数不处理选中的内容,会直接清空用户选中的内容
275
+ * @param {1|2|3|4|5|6|'1'|'2'|'3'|'4'|'5'|'6'|'flow'|'sequence'|'state'|'class'|'pie'|'gantt'|''} shortKey 快捷键参数
276
+ * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
277
+ */
278
+ onClick(selection, shortKey = '') {
279
+ return `\n\`\`\`mermaid\n${shortKey.trim()}\n\`\`\`\n\n`;
280
+ }
281
+ }
@@ -0,0 +1,71 @@
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
+ * 插入1级标题
20
+ */
21
+ export default class H1 extends MenuBase {
22
+ constructor($cherry) {
23
+ super($cherry);
24
+ this.setName('h1', 'format_h1');
25
+ }
26
+
27
+ $testIsHead(selection) {
28
+ return /^\s*(#+)\s*.+/.test(selection);
29
+ }
30
+
31
+ /**
32
+ * 响应点击事件
33
+ * @param {string} selection 被用户选中的文本内容
34
+ * @param {string} shortKey 快捷键参数,本函数不处理这个参数
35
+ * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
36
+ */
37
+ onClick(selection, shortKey = '') {
38
+ let $selection = getSelection(this.editor.editor, selection, 'line', true) || this.locale.h1;
39
+ const header = '#';
40
+ if (!this.isSelections && !this.$testIsHead($selection)) {
41
+ this.getMoreSelection('\n', '', () => {
42
+ const newSelection = this.editor.editor.getSelection();
43
+ const isHead = this.$testIsHead(newSelection);
44
+ if (isHead) {
45
+ $selection = newSelection;
46
+ }
47
+ return isHead;
48
+ });
49
+ }
50
+ if (this.$testIsHead($selection)) {
51
+ // 如果选中的内容里有标题语法,并且标记级别与目标一致,则去掉标题语法
52
+ // 反之,修改标题级别与目标一致
53
+ let needClean = true;
54
+ const tmp = $selection.replace(/(^\s*)(#+)(\s*)(.+$)/gm, (w, m1, m2, m3, m4) => {
55
+ needClean = needClean ? m2.length === header.length : false;
56
+ return `${m1}${header}${m3}${m4}`;
57
+ });
58
+ if (needClean) {
59
+ return $selection.replace(/(^\s*)(#+)(\s*)(.+$)/gm, '$1$4');
60
+ }
61
+ this.registerAfterClickCb(() => {
62
+ this.setLessSelection(`${header} `, '');
63
+ });
64
+ return tmp;
65
+ }
66
+ this.registerAfterClickCb(() => {
67
+ this.setLessSelection(`${header} `, '');
68
+ });
69
+ return $selection.replace(/(^)([\s]*)([^\n]+)($)/gm, `$1${header} $3$4`);
70
+ }
71
+ }
@@ -0,0 +1,71 @@
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
+ * 插入2级标题
20
+ */
21
+ export default class H2 extends MenuBase {
22
+ constructor($cherry) {
23
+ super($cherry);
24
+ this.setName('h2', 'format_h2');
25
+ }
26
+
27
+ $testIsHead(selection) {
28
+ return /^\s*(#+)\s*.+/.test(selection);
29
+ }
30
+
31
+ /**
32
+ * 响应点击事件
33
+ * @param {string} selection 被用户选中的文本内容
34
+ * @param {string} shortKey 快捷键参数,本函数不处理这个参数
35
+ * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
36
+ */
37
+ onClick(selection, shortKey = '') {
38
+ let $selection = getSelection(this.editor.editor, selection, 'line', true) || this.locale.h2;
39
+ const header = '##';
40
+ if (!this.isSelections && !this.$testIsHead($selection)) {
41
+ this.getMoreSelection('\n', '', () => {
42
+ const newSelection = this.editor.editor.getSelection();
43
+ const isHead = this.$testIsHead(newSelection);
44
+ if (isHead) {
45
+ $selection = newSelection;
46
+ }
47
+ return isHead;
48
+ });
49
+ }
50
+ if (this.$testIsHead($selection)) {
51
+ // 如果选中的内容里有标题语法,并且标记级别与目标一致,则去掉标题语法
52
+ // 反之,修改标题级别与目标一致
53
+ let needClean = true;
54
+ const tmp = $selection.replace(/(^\s*)(#+)(\s*)(.+$)/gm, (w, m1, m2, m3, m4) => {
55
+ needClean = needClean ? m2.length === header.length : false;
56
+ return `${m1}${header}${m3}${m4}`;
57
+ });
58
+ if (needClean) {
59
+ return $selection.replace(/(^\s*)(#+)(\s*)(.+$)/gm, '$1$4');
60
+ }
61
+ this.registerAfterClickCb(() => {
62
+ this.setLessSelection(`${header} `, '');
63
+ });
64
+ return tmp;
65
+ }
66
+ this.registerAfterClickCb(() => {
67
+ this.setLessSelection(`${header} `, '');
68
+ });
69
+ return $selection.replace(/(^)([\s]*)([^\n]+)($)/gm, `$1${header} $3$4`);
70
+ }
71
+ }
@@ -0,0 +1,71 @@
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
+ * 插入3级标题
20
+ */
21
+ export default class H3 extends MenuBase {
22
+ constructor($cherry) {
23
+ super($cherry);
24
+ this.setName('h3', 'format_h3');
25
+ }
26
+
27
+ $testIsHead(selection) {
28
+ return /^\s*(#+)\s*.+/.test(selection);
29
+ }
30
+
31
+ /**
32
+ * 响应点击事件
33
+ * @param {string} selection 被用户选中的文本内容
34
+ * @param {string} shortKey 快捷键参数,本函数不处理这个参数
35
+ * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
36
+ */
37
+ onClick(selection, shortKey = '') {
38
+ let $selection = getSelection(this.editor.editor, selection, 'line', true) || this.locale.h3;
39
+ const header = '###';
40
+ if (!this.isSelections && !this.$testIsHead($selection)) {
41
+ this.getMoreSelection('\n', '', () => {
42
+ const newSelection = this.editor.editor.getSelection();
43
+ const isHead = this.$testIsHead(newSelection);
44
+ if (isHead) {
45
+ $selection = newSelection;
46
+ }
47
+ return isHead;
48
+ });
49
+ }
50
+ if (this.$testIsHead($selection)) {
51
+ // 如果选中的内容里有标题语法,并且标记级别与目标一致,则去掉标题语法
52
+ // 反之,修改标题级别与目标一致
53
+ let needClean = true;
54
+ const tmp = $selection.replace(/(^\s*)(#+)(\s*)(.+$)/gm, (w, m1, m2, m3, m4) => {
55
+ needClean = needClean ? m2.length === header.length : false;
56
+ return `${m1}${header}${m3}${m4}`;
57
+ });
58
+ if (needClean) {
59
+ return $selection.replace(/(^\s*)(#+)(\s*)(.+$)/gm, '$1$4');
60
+ }
61
+ this.registerAfterClickCb(() => {
62
+ this.setLessSelection(`${header} `, '');
63
+ });
64
+ return tmp;
65
+ }
66
+ this.registerAfterClickCb(() => {
67
+ this.setLessSelection(`${header} `, '');
68
+ });
69
+ return $selection.replace(/(^)([\s]*)([^\n]+)($)/gm, `$1${header} $3$4`);
70
+ }
71
+ }
@@ -0,0 +1,100 @@
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
+ * 插入1级~5级标题
20
+ */
21
+ export default class Header extends MenuBase {
22
+ constructor($cherry) {
23
+ super($cherry);
24
+ this.setName('header', 'title');
25
+ this.subMenuConfig = [
26
+ { iconName: 'format_h1', name: 'h1', onclick: this.bindSubClick.bind(this, '1') },
27
+ { iconName: 'format_h2', name: 'h2', onclick: this.bindSubClick.bind(this, '2') },
28
+ { iconName: 'format_h3', name: 'h3', onclick: this.bindSubClick.bind(this, '3') },
29
+ { iconName: 'format_h4', name: 'h4', onclick: this.bindSubClick.bind(this, '4') },
30
+ { iconName: 'format_h5', name: 'h5', onclick: this.bindSubClick.bind(this, '5') },
31
+ ];
32
+ }
33
+
34
+ getSubMenuConfig() {
35
+ return this.subMenuConfig;
36
+ }
37
+
38
+ /**
39
+ * 解析快捷键,判断插入的标题级别
40
+ * @param {string} shortKey 快捷键
41
+ * @returns
42
+ */
43
+ $getFlagStr(shortKey) {
44
+ const test = +(typeof shortKey === 'string' ? shortKey.replace(/[^0-9]+([0-9])/g, '$1') : shortKey);
45
+ return '#'.repeat(test ? test : 1);
46
+ }
47
+
48
+ $testIsHead(selection) {
49
+ return /^\s*(#+)\s*.+/.test(selection);
50
+ }
51
+
52
+ /**
53
+ * 响应点击事件
54
+ * @param {string} selection 被用户选中的文本内容
55
+ * @param {string} shortKey 快捷键参数
56
+ * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
57
+ */
58
+ onClick(selection, shortKey = '') {
59
+ let $selection = getSelection(this.editor.editor, selection, 'line', true) || this.locale.header;
60
+ const header = this.$getFlagStr(shortKey);
61
+ if (!this.isSelections && !this.$testIsHead($selection)) {
62
+ this.getMoreSelection('\n', '', () => {
63
+ const newSelection = this.editor.editor.getSelection();
64
+ const isHead = this.$testIsHead(newSelection);
65
+ if (isHead) {
66
+ $selection = newSelection;
67
+ }
68
+ return isHead;
69
+ });
70
+ }
71
+ if (this.$testIsHead($selection)) {
72
+ // 如果选中的内容里有标题语法,并且标记级别与目标一致,则去掉标题语法
73
+ // 反之,修改标题级别与目标一致
74
+ let needClean = true;
75
+ const tmp = $selection.replace(/(^\s*)(#+)(\s*)(.+$)/gm, (w, m1, m2, m3, m4) => {
76
+ needClean = needClean ? m2.length === header.length : false;
77
+ return `${m1}${header}${m3}${m4}`;
78
+ });
79
+ if (needClean) {
80
+ return $selection.replace(/(^\s*)(#+)(\s*)(.+$)/gm, '$1$4');
81
+ }
82
+ this.registerAfterClickCb(() => {
83
+ this.setLessSelection(`${header} `, '');
84
+ });
85
+ return tmp;
86
+ }
87
+ this.registerAfterClickCb(() => {
88
+ this.setLessSelection(`${header} `, '');
89
+ });
90
+ return $selection.replace(/(^)([\s]*)([^\n]+)($)/gm, `$1${header} $3$4`);
91
+ }
92
+
93
+ /**
94
+ * 获得监听的快捷键
95
+ * 在windows下是Ctrl+1,在mac下是cmd+1
96
+ */
97
+ get shortcutKeys() {
98
+ return ['Ctrl-1', 'Ctrl-2', 'Ctrl-3', 'Ctrl-4', 'Ctrl-5', 'Ctrl-6'];
99
+ }
100
+ }
@@ -0,0 +1,35 @@
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 Hr extends MenuBase {
21
+ constructor($cherry) {
22
+ super($cherry);
23
+ this.setName('hr', 'horizontal_rule');
24
+ }
25
+
26
+ /**
27
+ * 响应点击事件
28
+ * @param {string} selection 被用户选中的文本内容
29
+ * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
30
+ */
31
+ onClick(selection, shortKey = '') {
32
+ // 插入分割线
33
+ return `${selection}\n\n---\n`;
34
+ }
35
+ }
@@ -0,0 +1,35 @@
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 Iframe extends MenuBase {
21
+ constructor($cherry) {
22
+ super($cherry);
23
+ this.setName('iframe', 'iframe');
24
+ }
25
+
26
+ /**
27
+ * 响应点击事件
28
+ * @param {string} selection 被用户选中的文本内容
29
+ * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
30
+ */
31
+ onClick(selection, shortKey = '') {
32
+ // 插入目录
33
+ return `${selection}\n@@https://example.com\n`;
34
+ }
35
+ }