vue-editify 0.2.13 → 0.2.15

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 (190) hide show
  1. package/examples/App.vue +49 -67
  2. package/lib/components/button/button.vue.d.ts +62 -60
  3. package/lib/components/button/index.d.ts +4 -0
  4. package/lib/components/button/props.d.ts +12 -1
  5. package/lib/components/checkbox/checkbox.vue.d.ts +9 -9
  6. package/lib/components/checkbox/index.d.ts +4 -0
  7. package/lib/components/checkbox/props.d.ts +2 -2
  8. package/lib/components/colors/colors.vue.d.ts +4 -4
  9. package/lib/components/colors/index.d.ts +4 -0
  10. package/lib/components/colors/props.d.ts +2 -2
  11. package/lib/components/icon/index.d.ts +4 -0
  12. package/lib/components/insertAttachment/index.d.ts +4 -0
  13. package/lib/{plugins/attachment → components}/insertAttachment/insertAttachment.vue.d.ts +3 -3
  14. package/lib/{plugins/attachment → components}/insertAttachment/props.d.ts +1 -1
  15. package/lib/components/insertImage/index.d.ts +4 -0
  16. package/lib/components/insertImage/insertImage.vue.d.ts +3 -3
  17. package/lib/components/insertImage/props.d.ts +1 -1
  18. package/lib/components/insertLink/index.d.ts +4 -0
  19. package/lib/components/insertLink/insertLink.vue.d.ts +6 -6
  20. package/lib/components/insertLink/props.d.ts +3 -3
  21. package/lib/components/insertMathformula/index.d.ts +4 -0
  22. package/lib/{plugins/mathformula → components}/insertMathformula/insertMathformula.vue.d.ts +3 -3
  23. package/lib/{plugins/mathformula → components}/insertMathformula/props.d.ts +2 -2
  24. package/lib/components/insertTable/index.d.ts +4 -0
  25. package/lib/components/insertTable/insertTable.vue.d.ts +3 -3
  26. package/lib/components/insertTable/props.d.ts +2 -2
  27. package/lib/components/insertVideo/index.d.ts +4 -0
  28. package/lib/components/insertVideo/insertVideo.vue.d.ts +3 -3
  29. package/lib/components/insertVideo/props.d.ts +1 -1
  30. package/lib/components/layer/index.d.ts +4 -0
  31. package/lib/components/layer/layer.vue.d.ts +10 -8
  32. package/lib/components/tooltip/index.d.ts +4 -0
  33. package/lib/components/tooltip/tooltip.vue.d.ts +6 -4
  34. package/lib/components/triangle/index.d.ts +4 -0
  35. package/lib/components/triangle/triangle.vue.d.ts +1 -1
  36. package/lib/components/updateLink/index.d.ts +4 -0
  37. package/lib/components/updateLink/props.d.ts +17 -0
  38. package/lib/components/updateLink/updateLink.vue.d.ts +38 -0
  39. package/lib/core/function.d.ts +113 -36
  40. package/lib/core/rule.d.ts +20 -0
  41. package/lib/core/tool.d.ts +36 -34
  42. package/lib/editify/editify.vue.d.ts +86 -53
  43. package/lib/editify/menu/index.d.ts +4 -0
  44. package/lib/{components → editify}/menu/menu.vue.d.ts +3 -4
  45. package/lib/{components → editify}/menu/props.d.ts +1 -1
  46. package/lib/editify/props.d.ts +3 -7
  47. package/lib/editify/toolbar/index.d.ts +4 -0
  48. package/lib/{components → editify}/toolbar/props.d.ts +2 -2
  49. package/lib/{components → editify}/toolbar/toolbar.vue.d.ts +53 -53
  50. package/lib/editify.es.js +8879 -7668
  51. package/lib/editify.umd.js +2 -2
  52. package/lib/feature/align.d.ts +32 -0
  53. package/lib/feature/attachment.d.ts +18 -0
  54. package/lib/feature/backColor.d.ts +32 -0
  55. package/lib/feature/bold.d.ts +32 -0
  56. package/lib/feature/code.d.ts +32 -0
  57. package/lib/feature/codeBlock.d.ts +32 -0
  58. package/lib/feature/fontFamily.d.ts +32 -0
  59. package/lib/feature/fontSize.d.ts +32 -0
  60. package/lib/feature/foreColor.d.ts +32 -0
  61. package/lib/feature/formatClear.d.ts +32 -0
  62. package/lib/feature/fullScreen.d.ts +18 -0
  63. package/lib/feature/heading.d.ts +32 -0
  64. package/lib/feature/image.d.ts +32 -0
  65. package/lib/feature/indent.d.ts +18 -0
  66. package/lib/feature/infoBlock.d.ts +18 -0
  67. package/lib/feature/italic.d.ts +32 -0
  68. package/lib/feature/lineHeight.d.ts +32 -0
  69. package/lib/feature/link.d.ts +26 -0
  70. package/lib/feature/mathformula.d.ts +22 -0
  71. package/lib/feature/orderList.d.ts +32 -0
  72. package/lib/feature/panel.d.ts +18 -0
  73. package/lib/feature/quote.d.ts +18 -0
  74. package/lib/feature/redo.d.ts +18 -0
  75. package/lib/feature/separator.d.ts +18 -0
  76. package/lib/feature/sourceView.d.ts +18 -0
  77. package/lib/feature/strikethrough.d.ts +32 -0
  78. package/lib/feature/sub.d.ts +32 -0
  79. package/lib/feature/super.d.ts +32 -0
  80. package/lib/feature/table.d.ts +32 -0
  81. package/lib/feature/task.d.ts +32 -0
  82. package/lib/feature/underline.d.ts +32 -0
  83. package/lib/feature/undo.d.ts +18 -0
  84. package/lib/feature/unorderList.d.ts +32 -0
  85. package/lib/feature/video.d.ts +38 -0
  86. package/lib/index.d.ts +104 -69
  87. package/package.json +5 -5
  88. package/src/components/button/button.vue +21 -24
  89. package/src/components/button/index.ts +5 -0
  90. package/src/components/button/props.ts +14 -1
  91. package/src/components/checkbox/checkbox.vue +1 -1
  92. package/src/components/checkbox/index.ts +5 -0
  93. package/src/components/checkbox/props.ts +1 -1
  94. package/src/components/colors/colors.vue +3 -3
  95. package/src/components/colors/index.ts +5 -0
  96. package/src/components/colors/props.ts +2 -2
  97. package/src/components/icon/index.ts +5 -0
  98. package/src/components/insertAttachment/index.ts +5 -0
  99. package/src/{plugins/attachment → components}/insertAttachment/insertAttachment.vue +4 -2
  100. package/src/{plugins/attachment → components}/insertAttachment/props.ts +1 -1
  101. package/src/components/insertImage/index.ts +5 -0
  102. package/src/components/insertImage/insertImage.vue +5 -5
  103. package/src/components/insertImage/props.ts +1 -1
  104. package/src/components/insertLink/index.ts +5 -0
  105. package/src/components/insertLink/insertLink.vue +10 -10
  106. package/src/components/insertLink/props.ts +3 -3
  107. package/src/components/insertMathformula/index.ts +5 -0
  108. package/src/{plugins/mathformula → components}/insertMathformula/props.ts +2 -2
  109. package/src/components/insertTable/index.ts +5 -0
  110. package/src/components/insertTable/props.ts +2 -2
  111. package/src/components/insertVideo/index.ts +5 -0
  112. package/src/components/insertVideo/insertVideo.vue +2 -2
  113. package/src/components/insertVideo/props.ts +1 -1
  114. package/src/components/layer/index.ts +5 -0
  115. package/src/components/layer/layer.vue +42 -4
  116. package/src/components/tooltip/index.ts +5 -0
  117. package/src/components/tooltip/tooltip.vue +1 -1
  118. package/src/components/triangle/index.ts +5 -0
  119. package/src/components/triangle/triangle.vue +1 -1
  120. package/src/components/updateLink/index.ts +5 -0
  121. package/src/components/updateLink/props.ts +21 -0
  122. package/src/components/{toolbar/toolbar.less → updateLink/updateLink.less} +4 -20
  123. package/src/components/updateLink/updateLink.vue +74 -0
  124. package/src/core/function.ts +289 -97
  125. package/src/core/rule.ts +96 -7
  126. package/src/core/tool.ts +234 -78
  127. package/src/editify/editify.less +2 -0
  128. package/src/editify/editify.vue +182 -185
  129. package/src/editify/menu/index.ts +5 -0
  130. package/src/editify/menu/menu.vue +215 -0
  131. package/src/{components → editify}/menu/props.ts +1 -1
  132. package/src/editify/props.ts +7 -11
  133. package/src/editify/toolbar/index.ts +5 -0
  134. package/src/{components → editify}/toolbar/props.ts +1 -1
  135. package/src/editify/toolbar/toolbar.less +10 -0
  136. package/src/editify/toolbar/toolbar.vue +103 -0
  137. package/src/feature/align.ts +128 -0
  138. package/src/feature/attachment.ts +109 -0
  139. package/src/feature/backColor.ts +171 -0
  140. package/src/feature/bold.ts +136 -0
  141. package/src/feature/code.ts +136 -0
  142. package/src/feature/codeBlock.ts +204 -0
  143. package/src/feature/fontFamily.ts +140 -0
  144. package/src/feature/fontSize.ts +142 -0
  145. package/src/feature/foreColor.ts +173 -0
  146. package/src/feature/formatClear.ts +118 -0
  147. package/src/feature/fullScreen.ts +57 -0
  148. package/src/feature/heading.ts +154 -0
  149. package/src/feature/image.ts +225 -0
  150. package/src/feature/indent.ts +73 -0
  151. package/src/feature/infoBlock.ts +94 -0
  152. package/src/feature/italic.ts +136 -0
  153. package/src/feature/lineHeight.ts +165 -0
  154. package/src/feature/link.ts +149 -0
  155. package/src/feature/mathformula.ts +147 -0
  156. package/src/feature/orderList.ts +116 -0
  157. package/src/feature/panel.ts +108 -0
  158. package/src/feature/quote.ts +61 -0
  159. package/src/feature/redo.ts +56 -0
  160. package/src/feature/separator.ts +62 -0
  161. package/src/feature/sourceView.ts +59 -0
  162. package/src/feature/strikethrough.ts +136 -0
  163. package/src/feature/sub.ts +136 -0
  164. package/src/feature/super.ts +136 -0
  165. package/src/feature/table.ts +994 -0
  166. package/src/feature/task.ts +116 -0
  167. package/src/feature/underline.ts +136 -0
  168. package/src/feature/undo.ts +56 -0
  169. package/src/feature/unorderList.ts +116 -0
  170. package/src/feature/video.ts +339 -0
  171. package/src/hljs/index.ts +1 -1
  172. package/src/index.ts +69 -21
  173. package/src/locale/en_US.ts +3 -3
  174. package/src/locale/zh_CN.ts +3 -3
  175. package/lib/plugins/attachment/index.d.ts +0 -37
  176. package/lib/plugins/infoBlock/index.d.ts +0 -55
  177. package/lib/plugins/mathformula/index.d.ts +0 -49
  178. package/lib/plugins/panel/index.d.ts +0 -48
  179. package/src/components/menu/menu.vue +0 -1655
  180. package/src/components/toolbar/toolbar.vue +0 -1677
  181. package/src/plugins/attachment/index.ts +0 -237
  182. package/src/plugins/infoBlock/index.ts +0 -238
  183. package/src/plugins/mathformula/index.ts +0 -295
  184. package/src/plugins/panel/index.ts +0 -228
  185. package/tsconfig.json +0 -31
  186. package/tsconfig.node.json +0 -11
  187. /package/src/{plugins/attachment → components}/insertAttachment/insertAttachment.less +0 -0
  188. /package/src/{plugins/mathformula → components}/insertMathformula/insertMathformula.less +0 -0
  189. /package/src/{plugins/mathformula → components}/insertMathformula/insertMathformula.vue +0 -0
  190. /package/src/{components → editify}/menu/menu.less +0 -0
@@ -1,295 +0,0 @@
1
- import { common as DapCommon } from 'dap-util'
2
- import { ComponentInternalInstance, h } from 'vue'
3
- import { AlexEditor, AlexElement, AlexElementsRangeType } from 'alex-editor'
4
- import { ObjectType, PluginType, cloneData } from '@/core/tool'
5
- import 'katex/dist/katex.css'
6
- import KaTex from 'katex'
7
- import Icon from '@/components/icon/icon.vue'
8
- import Button from '@/components/button/button.vue'
9
- import { hasLinkInRange, hasPreInRange } from '@/core/function'
10
- import InsertMathformula from './insertMathformula/insertMathformula.vue'
11
-
12
- export type MathformulaOptionsType = {
13
- //排序
14
- sequence?: number
15
- //工具提示内容
16
- title?: string
17
- //按钮是否显示左侧边框
18
- leftBorder?: boolean
19
- //按钮是否显示右侧边框
20
- rightBorder?: boolean
21
- //按钮是否禁用
22
- disabled?: boolean
23
- //公式异常处理
24
- handleError?: (error: Error) => void
25
- }
26
-
27
- /**
28
- * 是否公式元素
29
- * @param el
30
- * @returns
31
- */
32
- export const isMathformula = (el: AlexElement) => {
33
- return el.parsedom == 'span' && el.hasMarks() && el.marks!['data-editify-mathformula']
34
- }
35
-
36
- /**
37
- * 判断某个元素是否在公式元素内
38
- * @param el
39
- * @returns
40
- */
41
- export const isUnderMathformula = (el: AlexElement): boolean => {
42
- if (isMathformula(el)) {
43
- return true
44
- }
45
- if (el.parent) {
46
- return isUnderMathformula(el.parent)
47
- }
48
- return false
49
- }
50
-
51
- /**
52
- * 根据某个元素获取所在的公式元素,如果不在公式元素内则返回null
53
- * @param el
54
- * @returns
55
- */
56
- export const getMathformulaElement = (el: AlexElement): AlexElement | null => {
57
- if (isMathformula(el)) {
58
- return el
59
- }
60
- if (el.parent) {
61
- return getMathformulaElement(el.parent)
62
- }
63
- return null
64
- }
65
-
66
- /**
67
- * 选区是否含有公式元素
68
- * @param editor
69
- * @param dataRangeCaches
70
- * @returns
71
- */
72
- export const hasMathformulaInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
73
- if (!editor.range) {
74
- return false
75
- }
76
- if (editor.range.anchor.isEqual(editor.range.focus)) {
77
- return isUnderMathformula(editor.range.anchor.element)
78
- }
79
- return dataRangeCaches.flatList.some(item => {
80
- return isUnderMathformula(item.element)
81
- })
82
- }
83
-
84
- /**
85
- * 选区是否在某个公式元素下,如果是返回该公式元素否则返回null
86
- * @param editor
87
- * @param dataRangeCaches
88
- * @returns
89
- */
90
- export const getMathformulaElementByRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
91
- if (!editor.range) {
92
- return null
93
- }
94
- if (editor.range.anchor.element.isEqual(editor.range.focus.element)) {
95
- return getMathformulaElement(editor.range.anchor.element)
96
- }
97
- const arr = dataRangeCaches.list.map(item => {
98
- return getMathformulaElement(item.element)
99
- })
100
- let hasNull = arr.some(el => {
101
- return el == null
102
- })
103
- //如果存在null,则表示有的选区元素不在公式元素下,返回null
104
- if (hasNull) {
105
- return null
106
- }
107
- //如果只有一个元素,则返回该元素
108
- if (arr.length == 1) {
109
- return arr[0]!
110
- }
111
- //默认数组中的元素都相等
112
- let flag = true
113
- for (let i = 1; i < arr.length; i++) {
114
- if (!arr[i]!.isEqual(arr[0]!)) {
115
- flag = false
116
- break
117
- }
118
- }
119
- //如果相等,则返回该元素
120
- if (flag) {
121
- return arr[0]
122
- }
123
- return null
124
- }
125
-
126
- /**
127
- * 数学公式插件
128
- * @param options
129
- * @returns
130
- */
131
- export const mathformula = (options?: MathformulaOptionsType) => {
132
- if (!DapCommon.isObject(options)) {
133
- options = {}
134
- }
135
- const plugin: PluginType = (editifyInstance: ComponentInternalInstance, editTrans: (key: string) => any) => {
136
- let isDisabled: boolean = false
137
- //如果光标范围内有链接、代码块则禁用
138
- if (editifyInstance.exposed!.editor.value) {
139
- isDisabled = hasPreInRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value) || hasLinkInRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value)
140
- }
141
- //数学公式文本框内置LaTex文本内容
142
- let defaultLaTexContent: string = ''
143
- return {
144
- //插件名称
145
- name: 'mathformula',
146
- //菜单项配置
147
- menu: {
148
- sequence: options!.sequence || 101,
149
- extraDisabled: (name: string) => {
150
- //如果光标选区内有数学公式则禁用链接、图片、视频、表格和代码块菜单
151
- if (name == 'link' || name == 'image' || name == 'video' || name == 'table' || name == 'codeBlock') {
152
- return hasMathformulaInRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value)
153
- }
154
- return false
155
- },
156
- extend: {
157
- type: 'select',
158
- title: options!.title || editTrans('insertMathformula'),
159
- leftBorder: options!.leftBorder,
160
- rightBorder: options!.rightBorder,
161
- hideScroll: true,
162
- active: editifyInstance.exposed!.editor.value ? !!getMathformulaElementByRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value) : false,
163
- disabled: isDisabled || options!.disabled,
164
- //浮层展开时触发的事件
165
- onLayerShow() {
166
- //获取选区所在的数学公式元素
167
- const mathformulaElement = getMathformulaElementByRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value)
168
- //如果该元素存在,则设置默认的LaTex文本内容
169
- if (mathformulaElement) {
170
- defaultLaTexContent = mathformulaElement.marks!['data-editify-mathformula'] || ''
171
- }
172
- },
173
- default: () => h(Icon, { value: 'mathformula' }),
174
- layer: (_name: string, btnInstance: InstanceType<typeof Button>) => {
175
- return h(InsertMathformula, {
176
- color: <string | null>editifyInstance.props.color,
177
- defaultLaTexContent: defaultLaTexContent,
178
- onInsert: (content: string) => {
179
- //如果公式文本框有内容则进行下一步处理
180
- if (content) {
181
- //获取编辑器对象
182
- const editor = <AlexEditor>editifyInstance.exposed!.editor.value
183
- //获取选区所在的数学公式元素
184
- const mathformulaElement = getMathformulaElementByRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value)
185
- //如果在数学公式下
186
- if (mathformulaElement) {
187
- //清除该数学公式
188
- mathformulaElement.toEmpty()
189
- //移动光标到后一个元素上
190
- editor.range!.anchor.moveToStart(editor.getNextElement(mathformulaElement)!)
191
- editor.range!.focus.moveToStart(editor.getNextElement(mathformulaElement)!)
192
- }
193
- //定义转换后的mathml内容
194
- let mathml: string = ''
195
- try {
196
- //获取转换后的mathml
197
- mathml = KaTex.renderToString(content, {
198
- output: 'mathml',
199
- throwOnError: true
200
- })
201
- } catch (error) {
202
- mathml = ''
203
- if (typeof options!.handleError == 'function') {
204
- options!.handleError(error as Error)
205
- }
206
- }
207
- //如果mathml存在则表示数学公式渲染成功则插入到编辑器
208
- if (mathml) {
209
- //设置最终的html内容
210
- const html = `<span data-editify-mathformula="${content}" contenteditable="false">${mathml}</span>`
211
- //html内容转为元素数组
212
- const elements = editor.parseHtml(html)
213
- //插入编辑器
214
- editor.insertElement(elements[0])
215
- //移动光标到新插入的元素
216
- editor.range!.anchor.moveToEnd(elements[0])
217
- editor.range!.focus.moveToEnd(elements[0])
218
- //渲染
219
- editor.formatElementStack()
220
- editor.domRender()
221
- editor.rangeRender()
222
- }
223
- }
224
- //关闭浮层
225
- btnInstance.show = false
226
- }
227
- })
228
- }
229
- }
230
- },
231
- //额外保留的标签
232
- extraKeepTags: ['math', 'mrow', 'mi', 'mo', 'mn', 'msup', 'msub', 'mfrac', 'msqrt', 'mroot', 'munder', 'mover', 'munderover', 'mtable', 'mtr', 'mtd', 'mtext', 'mspace', 'mmultiscripts', 'menclose', 'mglyph', 'maction', 'maligngroup', 'malignmark', 'mprescripts', 'none', 'mpadded', 'ms', 'mphantom', 'mstyle', 'merror', 'mscarries', 'mscarry', 'msline', 'msgroup', 'msrow', 'mscolumn', 'mstack', 'mlongdiv', 'mlabeledtr', 'mlabeledmultiscripts', 'semantics', 'msubsup'],
233
- //粘贴保留的属性
234
- pasteKeepMarks: el => {
235
- let marks: ObjectType = {}
236
- if (isMathformula(el) || isUnderMathformula(el)) {
237
- marks = cloneData(el.marks!)
238
- }
239
- return marks
240
- },
241
- //粘贴保留的样式
242
- pasteKeepStyles: el => {
243
- let styles: ObjectType = {}
244
- if (isMathformula(el) || isUnderMathformula(el)) {
245
- styles = cloneData(el.styles!)
246
- }
247
- return styles
248
- },
249
- //node转元素的额外处理
250
- customParseNode: (el: AlexElement) => {
251
- if (el.parsedom == 'span' && el.hasMarks() && el.marks!['data-editify-mathformula']) {
252
- AlexElement.flatElements(el.children!).forEach(item => {
253
- //锁定元素防止合并
254
- item.locked = true
255
- //没有子元素的非文本元素设为自闭合元素
256
- if (!item.isText() && !item.hasChildren()) {
257
- item.type = 'closed'
258
- }
259
- })
260
- }
261
- return el
262
- },
263
- //自定义渲染规范
264
- renderRule: (el: AlexElement) => {
265
- //给元素设置两侧的空白字符
266
- if (el.parsedom == 'span' && el.hasMarks() && el.marks!['data-editify-mathformula']) {
267
- //获取editor对象
268
- const editor = <AlexEditor>editifyInstance.exposed!.editor.value
269
- //前一个元素
270
- const previousElement = editor.getPreviousElement(el)
271
- //后一个元素
272
- const newTextElement = editor.getNextElement(el)
273
- //如果不存在前一个元素或者前一个元素不是空白元素则设置空白元素
274
- if (!previousElement || !previousElement.isSpaceText()) {
275
- const spaceText = AlexElement.getSpaceElement()
276
- editor.addElementBefore(spaceText, el)
277
- }
278
- //如果不存在后一个元素或者后一个元素不是空白元素则设置空白元素
279
- if (!newTextElement || !newTextElement.isSpaceText()) {
280
- const spaceText = AlexElement.getSpaceElement()
281
- editor.addElementAfter(spaceText, el)
282
- }
283
- //如果光标在元素上则更新光标位置
284
- if (editor.range && el.isContains(editor.range.anchor.element)) {
285
- editor.range.anchor.moveToEnd(editor.getNextElement(el)!)
286
- }
287
- if (editor.range && el.isContains(editor.range.focus.element)) {
288
- editor.range.focus.moveToEnd(editor.getNextElement(el)!)
289
- }
290
- }
291
- }
292
- }
293
- }
294
- return plugin
295
- }
@@ -1,228 +0,0 @@
1
- import { common as DapCommon } from 'dap-util'
2
- import { ComponentInternalInstance, h } from 'vue'
3
- import { AlexEditor, AlexElement, AlexElementsRangeType } from 'alex-editor'
4
- import { PluginType } from '@/core/tool'
5
- import Icon from '@/components/icon/icon.vue'
6
- import { hasTableInRange } from '@/core/function'
7
- import { hasMathformulaInRange } from '@/plugins/mathformula'
8
-
9
- export type PanelOptionsType = {
10
- //排序
11
- sequence?: number
12
- //工具提示内容
13
- title?: string
14
- //按钮是否显示左侧边框
15
- leftBorder?: boolean
16
- //按钮是否显示右侧边框
17
- rightBorder?: boolean
18
- //按钮是否禁用
19
- disabled?: boolean
20
- }
21
-
22
- /**
23
- * 是否面板元素
24
- * @param el
25
- * @returns
26
- */
27
- export const isPanel = (el: AlexElement) => {
28
- return el.parsedom == 'div' && el.hasMarks() && el.marks!['data-editify-panel']
29
- }
30
-
31
- /**
32
- * 判断某个元素是否在面板元素内
33
- * @param el
34
- * @returns
35
- */
36
- export const isUnderPanel = (el: AlexElement): boolean => {
37
- if (isPanel(el)) {
38
- return true
39
- }
40
- if (el.parent) {
41
- return isUnderPanel(el.parent)
42
- }
43
- return false
44
- }
45
-
46
- /**
47
- * 根据某个元素获取所在的面板元素,如果不在面板元素内则返回null
48
- * @param el
49
- * @returns
50
- */
51
- export const getPanelElement = (el: AlexElement): AlexElement | null => {
52
- if (isPanel(el)) {
53
- return el
54
- }
55
- if (el.parent) {
56
- return getPanelElement(el.parent)
57
- }
58
- return null
59
- }
60
-
61
- /**
62
- * 选区是否含有面板元素
63
- * @param editor
64
- * @param dataRangeCaches
65
- * @returns
66
- */
67
- export const hasPanelInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
68
- if (!editor.range) {
69
- return false
70
- }
71
- if (editor.range.anchor.isEqual(editor.range.focus)) {
72
- return isUnderPanel(editor.range.anchor.element)
73
- }
74
- return dataRangeCaches.flatList.some(item => {
75
- return isUnderPanel(item.element)
76
- })
77
- }
78
-
79
- /**
80
- * 选区是否在某个面板元素下,如果是返回该面板元素否则返回null
81
- * @param editor
82
- * @param dataRangeCaches
83
- * @returns
84
- */
85
- export const getPanelElementByRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
86
- if (!editor.range) {
87
- return null
88
- }
89
- if (editor.range.anchor.element.isEqual(editor.range.focus.element)) {
90
- return getPanelElement(editor.range.anchor.element)
91
- }
92
- const arr = dataRangeCaches.list.map(item => {
93
- return getPanelElement(item.element)
94
- })
95
- let hasNull = arr.some(el => {
96
- return el == null
97
- })
98
- //如果存在null,则表示有的选区元素不在公式元素下,返回null
99
- if (hasNull) {
100
- return null
101
- }
102
- //如果只有一个元素,则返回该元素
103
- if (arr.length == 1) {
104
- return arr[0]!
105
- }
106
- //默认数组中的元素都相等
107
- let flag = true
108
- for (let i = 1; i < arr.length; i++) {
109
- if (!arr[i]!.isEqual(arr[0]!)) {
110
- flag = false
111
- break
112
- }
113
- }
114
- //如果相等,则返回该元素
115
- if (flag) {
116
- return arr[0]
117
- }
118
- return null
119
- }
120
-
121
- /**
122
- * 面板插件
123
- * @param options
124
- * @returns
125
- */
126
- export const panel = (options?: PanelOptionsType) => {
127
- if (!DapCommon.isObject(options)) {
128
- options = {}
129
- }
130
- const plugin: PluginType = (editifyInstance: ComponentInternalInstance, editTrans: (key: string) => any) => {
131
- let isDisabled: boolean = false
132
- //光标在表格、面板和数学公式下则禁用
133
- if (editifyInstance.exposed!.editor.value) {
134
- isDisabled = hasPanelInRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value) || hasTableInRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value) || hasMathformulaInRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value)
135
- }
136
- return {
137
- //插件名称
138
- name: 'panel',
139
- //菜单项配置
140
- menu: {
141
- sequence: options!.sequence || 102,
142
- extraDisabled: (name: string) => {
143
- //如果光标选区内有面板,则禁用有序列表、无需列表、任务列表、引用、代码块、表格和标题菜单
144
- if (name == 'orderList' || name == 'unorderList' || name == 'task' || name == 'quote' || name == 'codeBlock' || name == 'table' || name == 'heading') {
145
- return hasPanelInRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value)
146
- }
147
- return false
148
- },
149
- extend: {
150
- type: 'default',
151
- title: options!.title || editTrans('insertPanel'),
152
- leftBorder: options!.leftBorder,
153
- rightBorder: options!.rightBorder,
154
- hideScroll: true,
155
- active: false,
156
- disabled: isDisabled || options!.disabled,
157
- default: () => h(Icon, { value: 'panel' }),
158
- onOperate: () => {
159
- const panelElement = AlexElement.create({
160
- type: 'block',
161
- parsedom: 'div',
162
- marks: {
163
- 'data-editify-panel': 'true'
164
- },
165
- children: [
166
- {
167
- type: 'inblock',
168
- parsedom: 'div',
169
- behavior: 'block',
170
- children: [
171
- {
172
- type: 'text',
173
- textcontent: editTrans('panelTitle')
174
- }
175
- ]
176
- },
177
- {
178
- type: 'inblock',
179
- parsedom: 'div',
180
- behavior: 'block',
181
- children: [
182
- {
183
- type: 'text',
184
- textcontent: editTrans('panelContent')
185
- }
186
- ]
187
- }
188
- ]
189
- })
190
- //获取编辑器对象
191
- const editor = <AlexEditor>editifyInstance.exposed!.editor.value
192
- //插入编辑器
193
- editor.insertElement(panelElement)
194
- //面板后面插入段落
195
- const paragraph = AlexElement.create({
196
- type: 'block',
197
- parsedom: AlexElement.BLOCK_NODE,
198
- children: [
199
- {
200
- type: 'closed',
201
- parsedom: 'br'
202
- }
203
- ]
204
- })
205
- editor.addElementAfter(paragraph, panelElement)
206
- //移动光标到新插入的元素
207
- editor.range!.anchor.moveToEnd(panelElement.children![0])
208
- editor.range!.focus.moveToEnd(panelElement.children![0])
209
- //渲染
210
- editor.formatElementStack()
211
- editor.domRender()
212
- editor.rangeRender()
213
- }
214
- }
215
- },
216
- //粘贴保留的属性
217
- pasteKeepMarks: (element: AlexElement) => {
218
- if (isPanel(element)) {
219
- return {
220
- 'data-editify-panel': 'true'
221
- }
222
- }
223
- return {}
224
- }
225
- }
226
- }
227
- return plugin
228
- }
package/tsconfig.json DELETED
@@ -1,31 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "useDefineForClassFields": true,
5
- "module": "ESNext",
6
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
- "skipLibCheck": true,
8
- "allowSyntheticDefaultImports": true,
9
- "types": ["node"],
10
- "baseUrl": "./",
11
- "paths": {
12
- "@/*": ["src/*"]
13
- },
14
-
15
- /* Bundler mode */
16
- "moduleResolution": "bundler",
17
- "allowImportingTsExtensions": true,
18
- "resolveJsonModule": true,
19
- "isolatedModules": true,
20
- "noEmit": true,
21
- "jsx": "preserve",
22
-
23
- /* Linting */
24
- "strict": true,
25
- "noUnusedLocals": true,
26
- "noUnusedParameters": true,
27
- "noFallthroughCasesInSwitch": true
28
- },
29
- "include": ["src/**/*.ts", "src/**/*.vue", "vite-env.d.ts"],
30
- "references": [{ "path": "./tsconfig.node.json" }]
31
- }
@@ -1,11 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "composite": true,
4
- "skipLibCheck": true,
5
- "module": "ESNext",
6
- "moduleResolution": "bundler",
7
- "allowSyntheticDefaultImports": true,
8
- "strict": true
9
- },
10
- "include": ["vite.config.ts"]
11
- }
File without changes