vue-editify 0.1.9 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. package/examples/App.vue +22 -5644
  2. package/examples/main.ts +4 -0
  3. package/lib/components/button/button.vue.d.ts +143 -0
  4. package/lib/components/button/props.d.ts +73 -0
  5. package/lib/components/checkbox/checkbox.vue.d.ts +80 -0
  6. package/lib/components/checkbox/props.d.ts +36 -0
  7. package/lib/components/colors/colors.vue.d.ts +47 -0
  8. package/lib/components/colors/props.d.ts +22 -0
  9. package/lib/components/icon/icon.vue.d.ts +14 -0
  10. package/lib/components/icon/props.d.ts +9 -0
  11. package/lib/components/insertImage/insertImage.vue.d.ts +74 -0
  12. package/lib/components/insertImage/props.d.ts +34 -0
  13. package/lib/components/insertLink/insertLink.vue.d.ts +27 -0
  14. package/lib/components/insertLink/props.d.ts +13 -0
  15. package/lib/components/insertTable/insertTable.vue.d.ts +36 -0
  16. package/lib/components/insertTable/props.d.ts +22 -0
  17. package/lib/components/insertVideo/insertVideo.vue.d.ts +74 -0
  18. package/lib/components/insertVideo/props.d.ts +34 -0
  19. package/lib/components/layer/layer.vue.d.ts +129 -0
  20. package/lib/components/layer/props.d.ts +53 -0
  21. package/lib/components/menu/menu.vue.d.ts +25 -0
  22. package/lib/components/menu/props.d.ts +14 -0
  23. package/lib/components/toolbar/props.d.ts +27 -0
  24. package/lib/components/toolbar/toolbar.vue.d.ts +56 -0
  25. package/lib/components/tooltip/props.d.ts +17 -0
  26. package/lib/components/tooltip/tooltip.vue.d.ts +39 -0
  27. package/lib/components/triangle/props.d.ts +19 -0
  28. package/lib/components/triangle/triangle.vue.d.ts +34 -0
  29. package/lib/core/function.d.ts +45 -0
  30. package/lib/core/rule.d.ts +9 -0
  31. package/lib/core/tool.d.ts +185 -0
  32. package/lib/editify/editify.vue.d.ts +676 -0
  33. package/lib/editify/props.d.ts +110 -0
  34. package/lib/editify.es.js +5547 -5667
  35. package/lib/editify.umd.js +1 -1
  36. package/lib/hljs/index.d.ts +7 -0
  37. package/lib/index.d.ts +17 -0
  38. package/lib/locale/en_US.d.ts +3 -0
  39. package/lib/locale/index.d.ts +2 -0
  40. package/lib/locale/zh_CN.d.ts +3 -0
  41. package/lib/style.css +1 -1
  42. package/package.json +16 -8
  43. package/src/components/button/button.less +145 -0
  44. package/src/components/button/button.vue +197 -0
  45. package/src/components/button/props.ts +95 -0
  46. package/src/components/checkbox/checkbox.less +84 -0
  47. package/src/components/checkbox/checkbox.vue +68 -0
  48. package/src/components/checkbox/props.ts +49 -0
  49. package/src/components/colors/colors.less +75 -0
  50. package/src/components/colors/colors.vue +36 -0
  51. package/src/components/colors/props.ts +29 -0
  52. package/src/components/{base/Icon.vue → icon/icon.less} +0 -17
  53. package/src/components/icon/icon.vue +12 -0
  54. package/src/components/icon/props.ts +11 -0
  55. package/src/components/insertImage/insertImage.less +135 -0
  56. package/src/components/insertImage/insertImage.vue +146 -0
  57. package/src/components/insertImage/props.ts +43 -0
  58. package/src/components/insertLink/insertLink.less +64 -0
  59. package/src/components/insertLink/insertLink.vue +58 -0
  60. package/src/components/insertLink/props.ts +16 -0
  61. package/src/components/insertTable/insertTable.less +54 -0
  62. package/src/components/insertTable/insertTable.vue +85 -0
  63. package/src/components/insertTable/props.ts +27 -0
  64. package/src/components/insertVideo/insertVideo.less +135 -0
  65. package/src/components/insertVideo/insertVideo.vue +146 -0
  66. package/src/components/insertVideo/props.ts +43 -0
  67. package/src/components/layer/layer.less +49 -0
  68. package/src/components/layer/layer.vue +598 -0
  69. package/src/components/layer/props.ts +71 -0
  70. package/src/components/menu/menu.less +64 -0
  71. package/src/components/menu/menu.vue +1570 -0
  72. package/src/components/menu/props.ts +17 -0
  73. package/src/components/toolbar/props.ts +35 -0
  74. package/src/components/toolbar/toolbar.less +89 -0
  75. package/src/components/toolbar/toolbar.vue +1101 -0
  76. package/src/components/tooltip/props.ts +21 -0
  77. package/src/components/tooltip/tooltip.less +23 -0
  78. package/src/components/tooltip/tooltip.vue +37 -0
  79. package/src/components/triangle/props.ts +26 -0
  80. package/src/components/triangle/triangle.less +79 -0
  81. package/src/components/triangle/triangle.vue +65 -0
  82. package/src/core/{function.js → function.ts} +268 -267
  83. package/src/core/{rule.js → rule.ts} +33 -33
  84. package/src/core/{tool.js → tool.ts} +221 -145
  85. package/src/editify/editify.less +404 -0
  86. package/src/editify/editify.vue +805 -0
  87. package/src/editify/props.ts +141 -0
  88. package/src/hljs/{index.js → index.ts} +7 -4
  89. package/src/index.ts +32 -0
  90. package/src/locale/{en_US.js → en_US.ts} +3 -1
  91. package/src/locale/index.ts +12 -0
  92. package/src/locale/{zh_CN.js → zh_CN.ts} +3 -1
  93. package/tsconfig.json +27 -0
  94. package/tsconfig.node.json +11 -0
  95. package/vite-env.d.ts +1 -0
  96. package/vite.config.ts +39 -0
  97. package/examples/main.js +0 -4
  98. package/src/Editify.vue +0 -1184
  99. package/src/components/Menu.vue +0 -1623
  100. package/src/components/Toolbar.vue +0 -1215
  101. package/src/components/base/Button.vue +0 -450
  102. package/src/components/base/Checkbox.vue +0 -196
  103. package/src/components/base/Layer.vue +0 -713
  104. package/src/components/base/Tooltip.vue +0 -82
  105. package/src/components/base/Triangle.vue +0 -159
  106. package/src/components/common/Colors.vue +0 -138
  107. package/src/components/common/InsertImage.vue +0 -316
  108. package/src/components/common/InsertLink.vue +0 -136
  109. package/src/components/common/InsertTable.vue +0 -157
  110. package/src/components/common/InsertVideo.vue +0 -316
  111. package/src/index.js +0 -24
  112. package/src/locale/index.js +0 -14
@@ -1,1623 +0,0 @@
1
- <template>
2
- <div class="editify-menu" :class="{ border: menuShowBorder, source: $parent.isSourceView && menuMode == 'inner', fullscreen: $parent.isFullScreen }" :data-editify-mode="menuMode" :style="config.style || ''">
3
- <MenuItem v-for="item in menuNames" :name="item" :disabled="menuDisabled(item)"></MenuItem>
4
- </div>
5
- </template>
6
- <script>
7
- import Icon from './base/Icon'
8
- import Button from './base/Button'
9
- import Colors from './common/Colors'
10
- import InsertLink from './common/InsertLink'
11
- import InsertImage from './common/InsertImage'
12
- import InsertVideo from './common/InsertVideo'
13
- import InsertTable from './common/InsertTable'
14
- import { h, getCurrentInstance } from 'vue'
15
- import { common as DapCommon } from 'dap-util'
16
- import { getLinkText, setHeading, setIndentIncrease, setIndentDecrease, setQuote, setAlign, setList, setTask, setTextStyle, setTextMark, removeTextStyle, removeTextMark, setLineHeight, insertLink, insertImage, insertVideo, insertTable, insertCodeBlock, hasPreInRange, hasTableInRange, hasQuoteInRange, hasLinkInRange, isRangeInQuote, isRangeInList, isRangeInTask, queryTextStyle, queryTextMark, getCurrentParsedomElement } from '../core/function'
17
- export default {
18
- name: 'Menu',
19
- props: {
20
- //菜单栏配置
21
- config: {
22
- type: Object,
23
- default: null
24
- },
25
- //主题色
26
- color: {
27
- type: String,
28
- default: ''
29
- }
30
- },
31
- setup() {
32
- const instance = getCurrentInstance()
33
- return {
34
- uid: instance.uid
35
- }
36
- },
37
- data() {
38
- return {
39
- //撤销按钮配置
40
- undoConfig: {
41
- show: this.config.undo.show,
42
- leftBorder: this.config.undo.leftBorder,
43
- rightBorder: this.config.undo.rightBorder,
44
- active: false,
45
- disabled: false
46
- },
47
- //重做按钮配置
48
- redoConfig: {
49
- show: this.config.redo.show,
50
- leftBorder: this.config.redo.leftBorder,
51
- rightBorder: this.config.redo.rightBorder,
52
- active: false,
53
- disabled: false
54
- },
55
- //标题按钮配置
56
- headingConfig: {
57
- show: this.config.heading.show,
58
- displayConfig: {
59
- options: this.config.heading.options,
60
- value: '',
61
- width: this.config.heading.width,
62
- maxHeight: this.config.heading.maxHeight
63
- },
64
- defaultValue: this.config.heading.defaultValue,
65
- leftBorder: this.config.heading.leftBorder,
66
- rightBorder: this.config.heading.rightBorder,
67
- active: false,
68
- disabled: false
69
- },
70
- //缩进按钮配置
71
- indentConfig: {
72
- show: this.config.indent.show,
73
- selectConfig: {
74
- options: this.config.indent.options,
75
- value: '',
76
- width: this.config.indent.width,
77
- maxHeight: this.config.indent.maxHeight
78
- },
79
- leftBorder: this.config.indent.leftBorder,
80
- rightBorder: this.config.indent.rightBorder,
81
- active: false,
82
- disabled: false
83
- },
84
- //引用按钮配置
85
- quoteConfig: {
86
- show: this.config.quote.show,
87
- leftBorder: this.config.quote.leftBorder,
88
- rightBorder: this.config.quote.rightBorder,
89
- active: false,
90
- disabled: false
91
- },
92
- //对齐方式按钮配置
93
- alignConfig: {
94
- show: this.config.align.show,
95
- selectConfig: {
96
- options: this.config.align.options,
97
- width: this.config.align.width,
98
- maxHeight: this.config.align.maxHeight
99
- },
100
- leftBorder: this.config.align.leftBorder,
101
- rightBorder: this.config.align.rightBorder,
102
- active: false,
103
- disabled: false
104
- },
105
- //有序列表按钮配置
106
- orderListConfig: {
107
- show: this.config.orderList.show,
108
- leftBorder: this.config.orderList.leftBorder,
109
- rightBorder: this.config.orderList.rightBorder,
110
- active: false,
111
- disabled: false
112
- },
113
- //无序列表按钮配置
114
- unorderListConfig: {
115
- show: this.config.unorderList.show,
116
- leftBorder: this.config.unorderList.leftBorder,
117
- rightBorder: this.config.unorderList.rightBorder,
118
- active: false,
119
- disabled: false
120
- },
121
- //任务列表按钮配置
122
- taskConfig: {
123
- show: this.config.task.show,
124
- leftBorder: this.config.task.leftBorder,
125
- rightBorder: this.config.task.rightBorder,
126
- active: false,
127
- disabled: false
128
- },
129
- //粗体按钮配置
130
- boldConfig: {
131
- show: this.config.bold.show,
132
- leftBorder: this.config.bold.leftBorder,
133
- rightBorder: this.config.bold.rightBorder,
134
- active: false,
135
- disabled: false
136
- },
137
- //下划线按钮配置
138
- underlineConfig: {
139
- show: this.config.underline.show,
140
- leftBorder: this.config.underline.leftBorder,
141
- rightBorder: this.config.underline.rightBorder,
142
- active: false,
143
- disabled: false
144
- },
145
- //斜体按钮配置
146
- italicConfig: {
147
- show: this.config.italic.show,
148
- leftBorder: this.config.italic.leftBorder,
149
- rightBorder: this.config.italic.rightBorder,
150
- active: false,
151
- disabled: false
152
- },
153
- //删除线按钮配置
154
- strikethroughConfig: {
155
- show: this.config.strikethrough.show,
156
- leftBorder: this.config.strikethrough.leftBorder,
157
- rightBorder: this.config.strikethrough.rightBorder,
158
- active: false,
159
- disabled: false
160
- },
161
- //行内代码按钮配置
162
- codeConfig: {
163
- show: this.config.code.show,
164
- leftBorder: this.config.code.leftBorder,
165
- rightBorder: this.config.code.rightBorder,
166
- active: false,
167
- disabled: false
168
- },
169
- //上标按钮配置
170
- superConfig: {
171
- show: this.config.super.show,
172
- leftBorder: this.config.super.leftBorder,
173
- rightBorder: this.config.super.rightBorder,
174
- active: false,
175
- disabled: false
176
- },
177
- //下标按钮配置
178
- subConfig: {
179
- show: this.config.sub.show,
180
- leftBorder: this.config.sub.leftBorder,
181
- rightBorder: this.config.sub.rightBorder,
182
- active: false,
183
- disabled: false
184
- },
185
- //清除格式按钮配置
186
- formatClearConfig: {
187
- show: this.config.formatClear.show,
188
- leftBorder: this.config.formatClear.leftBorder,
189
- rightBorder: this.config.formatClear.rightBorder,
190
- active: false,
191
- disabled: false
192
- },
193
- //字号按钮配置
194
- fontSizeConfig: {
195
- show: this.config.fontSize.show,
196
- displayConfig: {
197
- options: this.config.fontSize.options,
198
- value: '',
199
- width: this.config.fontSize.width,
200
- maxHeight: this.config.fontSize.maxHeight
201
- },
202
- defaultValue: this.config.fontSize.defaultValue,
203
- leftBorder: this.config.fontSize.leftBorder,
204
- rightBorder: this.config.fontSize.rightBorder,
205
- active: false,
206
- disabled: false
207
- },
208
- //字体按钮配置
209
- fontFamilyConfig: {
210
- show: this.config.fontFamily.show,
211
- displayConfig: {
212
- options: this.config.fontFamily.options,
213
- value: '',
214
- width: this.config.fontFamily.width,
215
- maxHeight: this.config.fontFamily.maxHeight
216
- },
217
- defaultValue: this.config.fontFamily.defaultValue,
218
- leftBorder: this.config.fontFamily.leftBorder,
219
- rightBorder: this.config.fontFamily.rightBorder,
220
- active: false,
221
- disabled: false
222
- },
223
- //行高按钮配置
224
- lineHeightConfig: {
225
- show: this.config.lineHeight.show,
226
- displayConfig: {
227
- options: this.config.lineHeight.options,
228
- value: '',
229
- width: this.config.lineHeight.width,
230
- maxHeight: this.config.lineHeight.maxHeight
231
- },
232
- defaultValue: this.config.lineHeight.defaultValue,
233
- leftBorder: this.config.lineHeight.leftBorder,
234
- rightBorder: this.config.lineHeight.rightBorder,
235
- active: false,
236
- disabled: false
237
- },
238
- //前景颜色按钮配置
239
- foreColorConfig: {
240
- show: this.config.foreColor.show,
241
- selectConfig: {
242
- options: this.config.foreColor.options
243
- },
244
- leftBorder: this.config.foreColor.leftBorder,
245
- rightBorder: this.config.foreColor.rightBorder,
246
- value: '', //选择的颜色值
247
- active: false,
248
- disabled: false
249
- },
250
- //背景颜色按钮配置
251
- backColorConfig: {
252
- show: this.config.backColor.show,
253
- selectConfig: {
254
- options: this.config.backColor.options
255
- },
256
- leftBorder: this.config.backColor.leftBorder,
257
- rightBorder: this.config.backColor.rightBorder,
258
- value: '', //选择的颜色值
259
- active: false,
260
- disabled: false
261
- },
262
- //链接按钮配置
263
- linkConfig: {
264
- show: this.config.link.show,
265
- leftBorder: this.config.link.leftBorder,
266
- rightBorder: this.config.link.rightBorder,
267
- active: false,
268
- disabled: false,
269
- text: '' //链接的文本
270
- },
271
- //插入图片按钮配置
272
- imageConfig: {
273
- show: this.config.image.show,
274
- leftBorder: this.config.image.leftBorder,
275
- rightBorder: this.config.image.rightBorder,
276
- active: false,
277
- disabled: false,
278
- accept: this.config.image.accept,
279
- multiple: this.config.image.multiple,
280
- maxSize: this.config.image.maxSize,
281
- minSize: this.config.image.minSize,
282
- handleError: this.config.image.handleError,
283
- customUpload: this.config.image.customUpload
284
- },
285
- //插入视频按钮配置
286
- videoConfig: {
287
- show: this.config.video.show,
288
- leftBorder: this.config.video.leftBorder,
289
- rightBorder: this.config.video.rightBorder,
290
- active: false,
291
- disabled: false,
292
- accept: this.config.video.accept,
293
- multiple: this.config.video.multiple,
294
- maxSize: this.config.video.maxSize,
295
- minSize: this.config.video.minSize,
296
- handleError: this.config.video.handleError,
297
- customUpload: this.config.video.customUpload
298
- },
299
- //表格按钮配置
300
- tableConfig: {
301
- show: this.config.table.show,
302
- leftBorder: this.config.table.leftBorder,
303
- rightBorder: this.config.table.rightBorder,
304
- active: false,
305
- disabled: false,
306
- maxRows: this.config.table.maxRows,
307
- maxColumns: this.config.table.maxColumns
308
- },
309
- //代码块按钮配置
310
- codeBlockConfig: {
311
- show: this.config.codeBlock.show,
312
- leftBorder: this.config.codeBlock.leftBorder,
313
- rightBorder: this.config.codeBlock.rightBorder,
314
- active: false,
315
- disabled: false
316
- },
317
- //代码视图按钮配置
318
- sourceViewConfig: {
319
- show: this.config.sourceView.show,
320
- leftBorder: this.config.sourceView.leftBorder,
321
- rightBorder: this.config.sourceView.rightBorder,
322
- active: false,
323
- disabled: false
324
- },
325
- //全屏按钮配置
326
- fullScreenConfig: {
327
- show: this.config.fullScreen.show,
328
- leftBorder: this.config.fullScreen.leftBorder,
329
- rightBorder: this.config.fullScreen.rightBorder,
330
- active: false,
331
- disabled: false
332
- }
333
- }
334
- },
335
- computed: {
336
- //整个菜单栏是否禁用
337
- disabled() {
338
- return this.$parent.disabled || !this.$parent.canUseMenu
339
- },
340
- //菜单名称数组
341
- menuNames() {
342
- return Object.keys(this.config.sequence).sort((a, b) => {
343
- if (this.config.sequence[a] > this.config.sequence[b]) {
344
- return 1
345
- }
346
- return -1
347
- })
348
- },
349
- //菜单是否禁用
350
- menuDisabled() {
351
- return name => {
352
- if (name == 'sourceView' || name == 'fullScreen') {
353
- return false
354
- }
355
- return this.$parent.isSourceView
356
- }
357
- },
358
- //菜单模式
359
- menuMode() {
360
- //如果是全屏状态下或者高度自适应情况下
361
- if (this.$parent.isFullScreen || this.$parent.height === true) {
362
- //fixed模式改为默认模式
363
- if (this.config.mode == 'fixed') {
364
- return 'default'
365
- }
366
- }
367
- return this.config.mode
368
- },
369
- //菜单栏是否显示边框
370
- menuShowBorder() {
371
- //fixed模式下不显示边框
372
- if (this.menuMode == 'fixed') {
373
- return false
374
- }
375
- //由编辑器的border属性来决定
376
- return this.$parent.showBorder
377
- }
378
- },
379
- components: {
380
- MenuItem: {
381
- props: {
382
- name: String,
383
- disabled: Boolean
384
- },
385
- inject: ['$editTrans'],
386
- render: function () {
387
- //共同设置的属性
388
- const props = {
389
- tooltip: this.$parent.config.tooltip,
390
- name: this.name
391
- }
392
- //撤销按钮
393
- if (this.name == 'undo' && this.$parent.undoConfig.show) {
394
- return h(
395
- Button,
396
- {
397
- ...props,
398
- title: this.$editTrans('undo'),
399
- leftBorder: this.$parent.undoConfig.leftBorder,
400
- rightBorder: this.$parent.undoConfig.rightBorder,
401
- disabled: this.$parent.undoConfig.disabled || this.disabled || this.$parent.disabled,
402
- color: this.$parent.color,
403
- active: this.$parent.undoConfig.active,
404
- onOperate: this.$parent.handleOperate
405
- },
406
- () => h(Icon, { value: 'undo' })
407
- )
408
- }
409
- //重做按钮
410
- if (this.name == 'redo' && this.$parent.redoConfig.show) {
411
- return h(
412
- Button,
413
- {
414
- ...props,
415
- title: this.$editTrans('redo'),
416
- leftBorder: this.$parent.redoConfig.leftBorder,
417
- rightBorder: this.$parent.redoConfig.rightBorder,
418
- disabled: this.$parent.redoConfig.disabled || this.disabled || this.$parent.disabled,
419
- color: this.$parent.color,
420
- active: this.$parent.redoConfig.active,
421
- onOperate: this.$parent.handleOperate
422
- },
423
- () => h(Icon, { value: 'redo' })
424
- )
425
- }
426
- //标题按钮
427
- if (this.name == 'heading' && this.$parent.headingConfig.show) {
428
- return h(Button, {
429
- ...props,
430
- type: 'display',
431
- displayConfig: this.$parent.headingConfig.displayConfig,
432
- title: this.$editTrans('heading'),
433
- leftBorder: this.$parent.headingConfig.leftBorder,
434
- rightBorder: this.$parent.headingConfig.rightBorder,
435
- color: this.$parent.color,
436
- disabled: this.$parent.headingConfig.disabled || this.disabled || this.$parent.disabled,
437
- active: this.$parent.headingConfig.active,
438
- onOperate: this.$parent.handleOperate
439
- })
440
- }
441
- //缩进按钮
442
- if (this.name == 'indent' && this.$parent.indentConfig.show) {
443
- return h(
444
- Button,
445
- {
446
- ...props,
447
- type: 'select',
448
- selectConfig: this.$parent.indentConfig.selectConfig,
449
- title: this.$editTrans('indent'),
450
- leftBorder: this.$parent.indentConfig.leftBorder,
451
- rightBorder: this.$parent.indentConfig.rightBorder,
452
- color: this.$parent.color,
453
- disabled: this.$parent.indentConfig.disabled || this.disabled || this.$parent.disabled,
454
- active: this.$parent.indentConfig.active,
455
- onOperate: this.$parent.handleOperate
456
- },
457
- () => h(Icon, { value: 'indent-increase' })
458
- )
459
- }
460
- //引用按钮
461
- if (this.name == 'quote' && this.$parent.quoteConfig.show) {
462
- return h(
463
- Button,
464
- {
465
- ...props,
466
- title: this.$editTrans('quote'),
467
- leftBorder: this.$parent.quoteConfig.leftBorder,
468
- rightBorder: this.$parent.quoteConfig.rightBorder,
469
- color: this.$parent.color,
470
- disabled: this.$parent.quoteConfig.disabled || this.disabled || this.$parent.disabled,
471
- active: this.$parent.quoteConfig.active,
472
- onOperate: this.$parent.handleOperate
473
- },
474
- () => h(Icon, { value: 'quote' })
475
- )
476
- }
477
- //对齐方式按钮
478
- if (this.name == 'align' && this.$parent.alignConfig.show) {
479
- return h(
480
- Button,
481
- {
482
- ...props,
483
- type: 'select',
484
- selectConfig: this.$parent.alignConfig.selectConfig,
485
- title: this.$editTrans('align'),
486
- leftBorder: this.$parent.alignConfig.leftBorder,
487
- rightBorder: this.$parent.alignConfig.rightBorder,
488
- color: this.$parent.color,
489
- disabled: this.$parent.alignConfig.disabled || this.disabled || this.$parent.disabled,
490
- active: this.$parent.alignConfig.active,
491
- onOperate: this.$parent.handleOperate
492
- },
493
- () => h(Icon, { value: 'align-left' })
494
- )
495
- }
496
- //有序列表按钮
497
- if (this.name == 'orderList' && this.$parent.orderListConfig.show) {
498
- return h(
499
- Button,
500
- {
501
- ...props,
502
- title: this.$editTrans('orderList'),
503
- leftBorder: this.$parent.orderListConfig.leftBorder,
504
- rightBorder: this.$parent.orderListConfig.rightBorder,
505
- color: this.$parent.color,
506
- disabled: this.$parent.orderListConfig.disabled || this.disabled || this.$parent.disabled,
507
- active: this.$parent.orderListConfig.active,
508
- onOperate: this.$parent.handleOperate
509
- },
510
- () => h(Icon, { value: 'list-ordered' })
511
- )
512
- }
513
- //无序列表按钮
514
- if (this.name == 'unorderList' && this.$parent.unorderListConfig.show) {
515
- return h(
516
- Button,
517
- {
518
- ...props,
519
- title: this.$editTrans('unorderList'),
520
- leftBorder: this.$parent.unorderListConfig.leftBorder,
521
- rightBorder: this.$parent.unorderListConfig.rightBorder,
522
- color: this.$parent.color,
523
- disabled: this.$parent.unorderListConfig.disabled || this.disabled || this.$parent.disabled,
524
- active: this.$parent.unorderListConfig.active,
525
- onOperate: this.$parent.handleOperate
526
- },
527
- () => h(Icon, { value: 'list-unordered' })
528
- )
529
- }
530
- //任务列表按钮
531
- if (this.name == 'task' && this.$parent.taskConfig.show) {
532
- return h(
533
- Button,
534
- {
535
- ...props,
536
- title: this.$editTrans('task'),
537
- leftBorder: this.$parent.taskConfig.leftBorder,
538
- rightBorder: this.$parent.taskConfig.rightBorder,
539
- color: this.$parent.color,
540
- disabled: this.$parent.taskConfig.disabled || this.disabled || this.$parent.disabled,
541
- active: this.$parent.taskConfig.active,
542
- onOperate: this.$parent.handleOperate
543
- },
544
- () => h(Icon, { value: 'task' })
545
- )
546
- }
547
- //粗体按钮
548
- if (this.name == 'bold' && this.$parent.boldConfig.show) {
549
- return h(
550
- Button,
551
- {
552
- ...props,
553
- title: this.$editTrans('bold'),
554
- leftBorder: this.$parent.boldConfig.leftBorder,
555
- rightBorder: this.$parent.boldConfig.rightBorder,
556
- color: this.$parent.color,
557
- disabled: this.$parent.boldConfig.disabled || this.disabled || this.$parent.disabled,
558
- active: this.$parent.boldConfig.active,
559
- onOperate: this.$parent.handleOperate
560
- },
561
- () => h(Icon, { value: 'bold' })
562
- )
563
- }
564
- //下划线按钮
565
- if (this.name == 'underline' && this.$parent.underlineConfig.show) {
566
- return h(
567
- Button,
568
- {
569
- ...props,
570
- title: this.$editTrans('underline'),
571
- leftBorder: this.$parent.underlineConfig.leftBorder,
572
- rightBorder: this.$parent.underlineConfig.rightBorder,
573
- color: this.$parent.color,
574
- disabled: this.$parent.underlineConfig.disabled || this.disabled || this.$parent.disabled,
575
- active: this.$parent.underlineConfig.active,
576
- onOperate: this.$parent.handleOperate
577
- },
578
- () => h(Icon, { value: 'underline' })
579
- )
580
- }
581
- //斜体按钮
582
- if (this.name == 'italic' && this.$parent.italicConfig.show) {
583
- return h(
584
- Button,
585
- {
586
- ...props,
587
- title: this.$editTrans('italic'),
588
- leftBorder: this.$parent.italicConfig.leftBorder,
589
- rightBorder: this.$parent.italicConfig.rightBorder,
590
- color: this.$parent.color,
591
- disabled: this.$parent.italicConfig.disabled || this.disabled || this.$parent.disabled,
592
- active: this.$parent.italicConfig.active,
593
- onOperate: this.$parent.handleOperate
594
- },
595
- () => h(Icon, { value: 'italic' })
596
- )
597
- }
598
- //删除线按钮
599
- if (this.name == 'strikethrough' && this.$parent.strikethroughConfig.show) {
600
- return h(
601
- Button,
602
- {
603
- ...props,
604
- title: this.$editTrans('strikethrough'),
605
- leftBorder: this.$parent.strikethroughConfig.leftBorder,
606
- rightBorder: this.$parent.strikethroughConfig.rightBorder,
607
- color: this.$parent.color,
608
- disabled: this.$parent.strikethroughConfig.disabled || this.disabled || this.$parent.disabled,
609
- active: this.$parent.strikethroughConfig.active,
610
- onOperate: this.$parent.handleOperate
611
- },
612
- () => h(Icon, { value: 'strikethrough' })
613
- )
614
- }
615
- //行内代码按钮
616
- if (this.name == 'code' && this.$parent.codeConfig.show) {
617
- return h(
618
- Button,
619
- {
620
- ...props,
621
- title: this.$editTrans('code'),
622
- leftBorder: this.$parent.codeConfig.leftBorder,
623
- rightBorder: this.$parent.codeConfig.rightBorder,
624
- color: this.$parent.color,
625
- disabled: this.$parent.codeConfig.disabled || this.disabled || this.$parent.disabled,
626
- active: this.$parent.codeConfig.active,
627
- onOperate: this.$parent.handleOperate
628
- },
629
- () => h(Icon, { value: 'code' })
630
- )
631
- }
632
- //上标按钮
633
- if (this.name == 'super' && this.$parent.superConfig.show) {
634
- return h(
635
- Button,
636
- {
637
- ...props,
638
- title: this.$editTrans('superscript'),
639
- leftBorder: this.$parent.superConfig.leftBorder,
640
- rightBorder: this.$parent.superConfig.rightBorder,
641
- color: this.$parent.color,
642
- disabled: this.$parent.superConfig.disabled || this.disabled || this.$parent.disabled,
643
- active: this.$parent.superConfig.active,
644
- onOperate: this.$parent.handleOperate
645
- },
646
- () => h(Icon, { value: 'superscript' })
647
- )
648
- }
649
- //下标按钮
650
- if (this.name == 'sub' && this.$parent.subConfig.show) {
651
- return h(
652
- Button,
653
- {
654
- ...props,
655
- title: this.$editTrans('subscript'),
656
- leftBorder: this.$parent.subConfig.leftBorder,
657
- rightBorder: this.$parent.subConfig.rightBorder,
658
- color: this.$parent.color,
659
- disabled: this.$parent.subConfig.disabled || this.disabled || this.$parent.disabled,
660
- active: this.$parent.subConfig.active,
661
- onOperate: this.$parent.handleOperate
662
- },
663
- () => h(Icon, { value: 'subscript' })
664
- )
665
- }
666
- //清除格式按钮
667
- if (this.name == 'formatClear' && this.$parent.formatClearConfig.show) {
668
- return h(
669
- Button,
670
- {
671
- ...props,
672
- title: this.$editTrans('formatClear'),
673
- leftBorder: this.$parent.formatClearConfig.leftBorder,
674
- rightBorder: this.$parent.formatClearConfig.rightBorder,
675
- color: this.$parent.color,
676
- disabled: this.$parent.formatClearConfig.disabled || this.disabled || this.$parent.disabled,
677
- active: this.$parent.formatClearConfig.active,
678
- onOperate: this.$parent.handleOperate
679
- },
680
- () => h(Icon, { value: 'format-clear' })
681
- )
682
- }
683
- //字号按钮
684
- if (this.name == 'fontSize' && this.$parent.fontSizeConfig.show) {
685
- return h(Button, {
686
- ...props,
687
- type: 'display',
688
- displayConfig: this.$parent.fontSizeConfig.displayConfig,
689
- title: this.$editTrans('fontSize'),
690
- leftBorder: this.$parent.fontSizeConfig.leftBorder,
691
- rightBorder: this.$parent.fontSizeConfig.rightBorder,
692
- color: this.$parent.color,
693
- disabled: this.$parent.fontSizeConfig.disabled || this.disabled || this.$parent.disabled,
694
- active: this.$parent.fontSizeConfig.active,
695
- onOperate: this.$parent.handleOperate
696
- })
697
- }
698
- //字体按钮
699
- if (this.name == 'fontFamily' && this.$parent.fontFamilyConfig.show) {
700
- return h(Button, {
701
- ...props,
702
- type: 'display',
703
- displayConfig: this.$parent.fontFamilyConfig.displayConfig,
704
- title: this.$editTrans('fontFamily'),
705
- leftBorder: this.$parent.fontFamilyConfig.leftBorder,
706
- rightBorder: this.$parent.fontFamilyConfig.rightBorder,
707
- color: this.$parent.color,
708
- disabled: this.$parent.fontFamilyConfig.disabled || this.disabled || this.$parent.disabled,
709
- active: this.$parent.fontFamilyConfig.active,
710
- onOperate: this.$parent.handleOperate
711
- })
712
- }
713
- //行高按钮
714
- if (this.name == 'lineHeight' && this.$parent.lineHeightConfig.show) {
715
- return h(Button, {
716
- ...props,
717
- type: 'display',
718
- displayConfig: this.$parent.lineHeightConfig.displayConfig,
719
- title: this.$editTrans('lineHeight'),
720
- leftBorder: this.$parent.lineHeightConfig.leftBorder,
721
- rightBorder: this.$parent.lineHeightConfig.rightBorder,
722
- color: this.$parent.color,
723
- disabled: this.$parent.lineHeightConfig.disabled || this.disabled || this.$parent.disabled,
724
- active: this.$parent.lineHeightConfig.active,
725
- onOperate: this.$parent.handleOperate
726
- })
727
- }
728
- //前景色按钮
729
- if (this.name == 'foreColor' && this.$parent.foreColorConfig.show) {
730
- return h(
731
- Button,
732
- {
733
- ...props,
734
- ref: 'btn',
735
- type: 'select',
736
- selectConfig: this.$parent.foreColorConfig.selectConfig,
737
- title: this.$editTrans('foreColor'),
738
- leftBorder: this.$parent.foreColorConfig.leftBorder,
739
- rightBorder: this.$parent.foreColorConfig.rightBorder,
740
- color: this.$parent.color,
741
- disabled: this.$parent.foreColorConfig.disabled || this.disabled || this.$parent.disabled,
742
- active: this.$parent.foreColorConfig.active,
743
- hideScroll: true
744
- },
745
- {
746
- default: () =>
747
- h(Icon, {
748
- value: 'font-color'
749
- }),
750
- layer: data =>
751
- h(Colors, {
752
- tooltip: this.$parent.config.tooltip,
753
- value: this.$parent.foreColorConfig.value,
754
- data: data.options,
755
- color: this.$parent.color,
756
- onChange: val => {
757
- this.$parent.handleOperate.apply(this.$parent, ['foreColor', val])
758
- this.$refs.btn.hideLayer()
759
- }
760
- })
761
- }
762
- )
763
- }
764
- //背景色按钮
765
- if (this.name == 'backColor' && this.$parent.backColorConfig.show) {
766
- return h(
767
- Button,
768
- {
769
- ...props,
770
- type: 'select',
771
- ref: 'btn',
772
- selectConfig: this.$parent.backColorConfig.selectConfig,
773
- title: this.$editTrans('backColor'),
774
- leftBorder: this.$parent.backColorConfig.leftBorder,
775
- rightBorder: this.$parent.backColorConfig.rightBorder,
776
- color: this.$parent.color,
777
- disabled: this.$parent.backColorConfig.disabled || this.disabled || this.$parent.disabled,
778
- active: this.$parent.backColorConfig.active,
779
- onOperate: this.$parent.handleOperate,
780
- hideScroll: true
781
- },
782
- {
783
- default: () =>
784
- h(Icon, {
785
- value: 'brush'
786
- }),
787
- layer: data =>
788
- h(Colors, {
789
- tooltip: this.$parent.config.tooltip,
790
- value: this.$parent.backColorConfig.value,
791
- data: data.options,
792
- color: this.$parent.color,
793
- onChange: val => {
794
- this.$parent.handleOperate.apply(this.$parent, ['backColor', val])
795
- this.$refs.btn.hideLayer()
796
- }
797
- })
798
- }
799
- )
800
- }
801
- //链接按钮
802
- if (this.name == 'link' && this.$parent.linkConfig.show) {
803
- return h(
804
- Button,
805
- {
806
- ...props,
807
- type: 'select',
808
- ref: 'btn',
809
- title: this.$editTrans('insertLink'),
810
- leftBorder: this.$parent.linkConfig.leftBorder,
811
- rightBorder: this.$parent.linkConfig.rightBorder,
812
- color: this.$parent.color,
813
- disabled: this.$parent.linkConfig.disabled || this.disabled || this.$parent.disabled,
814
- active: this.$parent.linkConfig.active,
815
- hideScroll: true,
816
- onLayerShow: () => {
817
- //存在选区的情况下预置链接文本值
818
- this.$parent.linkConfig.text = getLinkText(this.$parent.$parent)
819
- }
820
- },
821
- {
822
- default: () =>
823
- h(Icon, {
824
- value: 'link'
825
- }),
826
- layer: () =>
827
- h(InsertLink, {
828
- color: this.$parent.color,
829
- text: this.$parent.linkConfig.text,
830
- onInsert: (text, url, newOpen) => {
831
- this.$parent.handleOperate.apply(this.$parent, ['link', { text, url, newOpen }])
832
- this.$refs.btn.hideLayer()
833
- }
834
- })
835
- }
836
- )
837
- }
838
- //图片按钮
839
- if (this.name == 'image' && this.$parent.imageConfig.show) {
840
- return h(
841
- Button,
842
- {
843
- ...props,
844
- type: 'select',
845
- ref: 'btn',
846
- title: this.$editTrans('insertImage'),
847
- leftBorder: this.$parent.imageConfig.leftBorder,
848
- rightBorder: this.$parent.imageConfig.rightBorder,
849
- color: this.$parent.color,
850
- disabled: this.$parent.imageConfig.disabled || this.disabled || this.$parent.disabled,
851
- active: this.$parent.imageConfig.active,
852
- hideScroll: true
853
- },
854
- {
855
- default: () =>
856
- h(Icon, {
857
- value: 'image'
858
- }),
859
- layer: () =>
860
- h(InsertImage, {
861
- color: this.$parent.color,
862
- accept: this.$parent.imageConfig.accept,
863
- multiple: this.$parent.imageConfig.multiple,
864
- maxSize: this.$parent.imageConfig.maxSize,
865
- minSize: this.$parent.imageConfig.minSize,
866
- customUpload: this.$parent.imageConfig.customUpload,
867
- handleError: this.$parent.imageConfig.handleError,
868
- onChange: () => {
869
- this.$refs.btn.$refs.layer.setPosition()
870
- },
871
- onInsert: url => {
872
- this.$parent.handleOperate.apply(this.$parent, ['image', url])
873
- this.$refs.btn.hideLayer()
874
- }
875
- })
876
- }
877
- )
878
- }
879
- //视频按钮
880
- if (this.name == 'video' && this.$parent.videoConfig.show) {
881
- return h(
882
- Button,
883
- {
884
- ...props,
885
- type: 'select',
886
- ref: 'btn',
887
- title: this.$editTrans('insertVideo'),
888
- leftBorder: this.$parent.videoConfig.leftBorder,
889
- rightBorder: this.$parent.videoConfig.rightBorder,
890
- color: this.$parent.color,
891
- disabled: this.$parent.videoConfig.disabled || this.disabled || this.$parent.disabled,
892
- active: this.$parent.videoConfig.active,
893
- hideScroll: true
894
- },
895
- {
896
- default: () =>
897
- h(Icon, {
898
- value: 'video'
899
- }),
900
- layer: () =>
901
- h(InsertVideo, {
902
- color: this.$parent.color,
903
- accept: this.$parent.videoConfig.accept,
904
- multiple: this.$parent.videoConfig.multiple,
905
- maxSize: this.$parent.videoConfig.maxSize,
906
- minSize: this.$parent.videoConfig.minSize,
907
- customUpload: this.$parent.videoConfig.customUpload,
908
- handleError: this.$parent.videoConfig.handleError,
909
- onChange: () => {
910
- this.$refs.btn.$refs.layer.setPosition()
911
- },
912
- onInsert: url => {
913
- this.$parent.handleOperate.apply(this.$parent, ['video', url])
914
- this.$refs.btn.hideLayer()
915
- }
916
- })
917
- }
918
- )
919
- }
920
- //表格按钮
921
- if (this.name == 'table' && this.$parent.tableConfig.show) {
922
- return h(
923
- Button,
924
- {
925
- ...props,
926
- type: 'select',
927
- ref: 'btn',
928
- title: this.$editTrans('insertTable'),
929
- leftBorder: this.$parent.tableConfig.leftBorder,
930
- rightBorder: this.$parent.tableConfig.rightBorder,
931
- color: this.$parent.color,
932
- disabled: this.$parent.tableConfig.disabled || this.disabled || this.$parent.disabled,
933
- active: this.$parent.tableConfig.active,
934
- hideScroll: true
935
- },
936
- {
937
- default: () =>
938
- h(Icon, {
939
- value: 'table'
940
- }),
941
- layer: () =>
942
- h(InsertTable, {
943
- color: this.$parent.color,
944
- maxRows: this.$parent.tableConfig.maxRows,
945
- maxColumns: this.$parent.tableConfig.maxColumns,
946
- onInsert: (row, column) => {
947
- this.$parent.handleOperate.apply(this.$parent, ['table', { row, column }])
948
- this.$refs.btn.hideLayer()
949
- }
950
- })
951
- }
952
- )
953
- }
954
- //代码块按钮
955
- if (this.name == 'codeBlock' && this.$parent.codeBlockConfig.show) {
956
- return h(
957
- Button,
958
- {
959
- ...props,
960
- title: this.$editTrans('inserCodeBlock'),
961
- leftBorder: this.$parent.codeBlockConfig.leftBorder,
962
- rightBorder: this.$parent.codeBlockConfig.rightBorder,
963
- color: this.$parent.color,
964
- disabled: this.$parent.codeBlockConfig.disabled || this.disabled || this.$parent.disabled,
965
- active: this.$parent.codeBlockConfig.active,
966
- onOperate: this.$parent.handleOperate
967
- },
968
- () => h(Icon, { value: 'code-block' })
969
- )
970
- }
971
- //代码视图按钮
972
- if (this.name == 'sourceView' && this.$parent.sourceViewConfig.show) {
973
- return h(
974
- Button,
975
- {
976
- ...props,
977
- title: this.$editTrans('sourceView'),
978
- leftBorder: this.$parent.sourceViewConfig.leftBorder,
979
- rightBorder: this.$parent.sourceViewConfig.rightBorder,
980
- color: this.$parent.color,
981
- disabled: this.$parent.sourceViewConfig.disabled || this.disabled || this.$parent.disabled,
982
- active: this.$parent.sourceViewConfig.active,
983
- onOperate: this.$parent.handleOperate
984
- },
985
- () => h(Icon, { value: 'source-view' })
986
- )
987
- }
988
- //全屏按钮
989
- if (this.name == 'fullScreen' && this.$parent.fullScreenConfig.show) {
990
- return h(
991
- Button,
992
- {
993
- ...props,
994
- title: this.$editTrans('fullScreen'),
995
- leftBorder: this.$parent.fullScreenConfig.leftBorder,
996
- rightBorder: this.$parent.fullScreenConfig.rightBorder,
997
- color: this.$parent.color,
998
- disabled: this.$parent.fullScreenConfig.disabled || this.disabled || this.$parent.disabled,
999
- active: this.$parent.fullScreenConfig.active,
1000
- onOperate: this.$parent.handleOperate
1001
- },
1002
- () => h(Icon, { value: 'full-screen' })
1003
- )
1004
- }
1005
-
1006
- /** 下面是拓展菜单的配置 */
1007
- if (DapCommon.isObject(this.$parent.config.extends)) {
1008
- //获取菜单按钮的配置
1009
- const configuration = this.$parent.config.extends[this.name]
1010
- if (configuration) {
1011
- //渲染函数
1012
- return h(
1013
- Button,
1014
- {
1015
- ...props,
1016
- ref: 'btn',
1017
- type: configuration.type || 'default',
1018
- title: configuration.title || '',
1019
- leftBorder: configuration.leftBorder || false,
1020
- rightBorder: configuration.rightBorder || false,
1021
- disabled: configuration.disabled || this.disabled || this.$parent.disabled,
1022
- hideScroll: configuration.hideScroll || false,
1023
- active: configuration.active || false,
1024
- selectConfig: {
1025
- width: configuration.width,
1026
- maxHeight: configuration.maxHeight,
1027
- options: configuration.options
1028
- },
1029
- displayConfig: {
1030
- width: configuration.width,
1031
- maxHeight: configuration.maxHeight,
1032
- value: configuration.value,
1033
- options: configuration.options
1034
- },
1035
- color: this.$parent.color,
1036
- onLayerShow: () => {
1037
- if (typeof configuration.onLayerShow == 'function') {
1038
- configuration.onLayerShow.apply(this.$parent.$parent, [this.name, this.$refs.btn])
1039
- }
1040
- },
1041
- onLayerShown: () => {
1042
- if (typeof configuration.onLayerShown == 'function') {
1043
- configuration.onLayerShown.apply(this.$parent.$parent, [this.name, this.$refs.btn])
1044
- }
1045
- },
1046
- onLayerHidden: () => {
1047
- if (typeof configuration.onLayerHidden == 'function') {
1048
- configuration.onLayerHidden.apply(this.$parent.$parent, [this.name, this.$refs.btn])
1049
- }
1050
- },
1051
- onOperate: (name, val) => {
1052
- if (typeof configuration.onOperate == 'function') {
1053
- configuration.onOperate.apply(this.$parent.$parent, [name, val, this.$refs.btn])
1054
- }
1055
- }
1056
- },
1057
- {
1058
- default: configuration.default || null,
1059
- layer: configuration.layer || null,
1060
- option: configuration.option || null
1061
- }
1062
- )
1063
- }
1064
- }
1065
-
1066
- return null
1067
- }
1068
- }
1069
- },
1070
- methods: {
1071
- //按钮操作触发函数
1072
- handleOperate(name, val) {
1073
- //菜单栏禁用
1074
- if (this.disabled) {
1075
- return
1076
- }
1077
- //没有获取焦点
1078
- if (!this.$parent.editor.range) {
1079
- return
1080
- }
1081
- //撤销
1082
- if (name == 'undo') {
1083
- this.$parent.undo()
1084
- }
1085
- //重做
1086
- else if (name == 'redo') {
1087
- this.$parent.redo()
1088
- }
1089
- //设置标题
1090
- else if (name == 'heading') {
1091
- setHeading(this.$parent, val)
1092
- this.$parent.editor.formatElementStack()
1093
- this.$parent.editor.domRender()
1094
- this.$parent.editor.rangeRender()
1095
- }
1096
- //设置缩进
1097
- else if (name == 'indent') {
1098
- //增加缩进
1099
- if (val == 'indent-increase') {
1100
- setIndentIncrease(this.$parent)
1101
- }
1102
- //减少缩进
1103
- else if (val == 'indent-decrease') {
1104
- setIndentDecrease(this.$parent)
1105
- }
1106
- this.$parent.editor.formatElementStack()
1107
- this.$parent.editor.domRender()
1108
- this.$parent.editor.rangeRender()
1109
- }
1110
- //设置引用
1111
- else if (name == 'quote') {
1112
- setQuote(this.$parent)
1113
- this.$parent.editor.formatElementStack()
1114
- this.$parent.editor.domRender()
1115
- this.$parent.editor.rangeRender()
1116
- }
1117
- //设置对齐方式
1118
- else if (name == 'align') {
1119
- setAlign(this.$parent, val)
1120
- this.$parent.editor.formatElementStack()
1121
- this.$parent.editor.domRender()
1122
- this.$parent.editor.rangeRender()
1123
- }
1124
- //设置有序列表
1125
- else if (name == 'orderList') {
1126
- setList(this.$parent, true)
1127
- this.$parent.editor.formatElementStack()
1128
- this.$parent.editor.domRender()
1129
- this.$parent.editor.rangeRender()
1130
- }
1131
- //设置无序列表
1132
- else if (name == 'unorderList') {
1133
- setList(this.$parent, false)
1134
- this.$parent.editor.formatElementStack()
1135
- this.$parent.editor.domRender()
1136
- this.$parent.editor.rangeRender()
1137
- }
1138
- //设置任务列表
1139
- else if (name == 'task') {
1140
- setTask(this.$parent)
1141
- this.$parent.editor.formatElementStack()
1142
- this.$parent.editor.domRender()
1143
- this.$parent.editor.rangeRender()
1144
- }
1145
- //设置粗体
1146
- else if (name == 'bold') {
1147
- if (queryTextStyle(this.$parent, 'font-weight', 'bold') || queryTextStyle(this.$parent, 'font-weight', '700')) {
1148
- removeTextStyle(this.$parent, ['font-weight'])
1149
- } else {
1150
- setTextStyle(this.$parent, {
1151
- 'font-weight': 'bold'
1152
- })
1153
- }
1154
- this.$parent.editor.formatElementStack()
1155
- this.$parent.editor.domRender()
1156
- this.$parent.editor.rangeRender()
1157
- }
1158
- //设置下划线
1159
- else if (name == 'underline') {
1160
- if (queryTextStyle(this.$parent, 'text-decoration', 'underline') || queryTextStyle(this.$parent, 'text-decoration-line', 'underline')) {
1161
- removeTextStyle(this.$parent, ['text-decoration', 'text-decoration-line'])
1162
- } else {
1163
- setTextStyle(this.$parent, {
1164
- 'text-decoration': 'underline'
1165
- })
1166
- }
1167
- this.$parent.editor.formatElementStack()
1168
- this.$parent.editor.domRender()
1169
- this.$parent.editor.rangeRender()
1170
- }
1171
- //设置斜体
1172
- else if (name == 'italic') {
1173
- if (queryTextStyle(this.$parent, 'font-style', 'italic')) {
1174
- removeTextStyle(this.$parent, ['font-style'])
1175
- } else {
1176
- setTextStyle(this.$parent, {
1177
- 'font-style': 'italic'
1178
- })
1179
- }
1180
- this.$parent.editor.formatElementStack()
1181
- this.$parent.editor.domRender()
1182
- this.$parent.editor.rangeRender()
1183
- }
1184
- //设置删除线
1185
- else if (name == 'strikethrough') {
1186
- if (queryTextStyle(this.$parent, 'text-decoration', 'line-through') || queryTextStyle(this.$parent, 'text-decoration-line', 'line-through')) {
1187
- removeTextStyle(this.$parent, ['text-decoration', 'text-decoration-line'])
1188
- } else {
1189
- setTextStyle(this.$parent, {
1190
- 'text-decoration': 'line-through'
1191
- })
1192
- }
1193
- this.$parent.editor.formatElementStack()
1194
- this.$parent.editor.domRender()
1195
- this.$parent.editor.rangeRender()
1196
- }
1197
- //设置行内代码
1198
- else if (name == 'code') {
1199
- if (queryTextMark(this.$parent, 'data-editify-code')) {
1200
- removeTextMark(this.$parent, ['data-editify-code'])
1201
- } else {
1202
- setTextMark(this.$parent, {
1203
- 'data-editify-code': true
1204
- })
1205
- }
1206
- this.$parent.editor.formatElementStack()
1207
- this.$parent.editor.domRender()
1208
- this.$parent.editor.rangeRender()
1209
- }
1210
- //设置上标
1211
- else if (name == 'super') {
1212
- if (queryTextStyle(this.$parent, 'vertical-align', 'super')) {
1213
- removeTextStyle(this.$parent, ['vertical-align'])
1214
- } else {
1215
- setTextStyle(this.$parent, {
1216
- 'vertical-align': 'super'
1217
- })
1218
- }
1219
- this.$parent.editor.formatElementStack()
1220
- this.$parent.editor.domRender()
1221
- this.$parent.editor.rangeRender()
1222
- }
1223
- //设置下标
1224
- else if (name == 'sub') {
1225
- if (queryTextStyle(this.$parent, 'vertical-align', 'sub')) {
1226
- removeTextStyle(this.$parent, ['vertical-align'])
1227
- } else {
1228
- setTextStyle(this.$parent, {
1229
- 'vertical-align': 'sub'
1230
- })
1231
- }
1232
- this.$parent.editor.formatElementStack()
1233
- this.$parent.editor.domRender()
1234
- this.$parent.editor.rangeRender()
1235
- }
1236
- //清除格式
1237
- else if (name == 'formatClear') {
1238
- removeTextStyle(this.$parent)
1239
- removeTextMark(this.$parent)
1240
- this.$parent.editor.formatElementStack()
1241
- this.$parent.editor.domRender()
1242
- this.$parent.editor.rangeRender()
1243
- }
1244
- //设置字号
1245
- else if (name == 'fontSize') {
1246
- setTextStyle(this.$parent, {
1247
- 'font-size': val
1248
- })
1249
- this.$parent.editor.formatElementStack()
1250
- this.$parent.editor.domRender()
1251
- this.$parent.editor.rangeRender()
1252
- }
1253
- //设置字体
1254
- else if (name == 'fontFamily') {
1255
- setTextStyle(this.$parent, {
1256
- 'font-family': val
1257
- })
1258
- this.$parent.editor.formatElementStack()
1259
- this.$parent.editor.domRender()
1260
- this.$parent.editor.rangeRender()
1261
- }
1262
- //设置行高
1263
- else if (name == 'lineHeight') {
1264
- setLineHeight(this.$parent, val)
1265
- this.$parent.editor.formatElementStack()
1266
- this.$parent.editor.domRender()
1267
- this.$parent.editor.rangeRender()
1268
- }
1269
- //设置前景色
1270
- else if (name == 'foreColor') {
1271
- setTextStyle(this.$parent, {
1272
- color: val
1273
- })
1274
- this.$parent.editor.formatElementStack()
1275
- this.$parent.editor.domRender()
1276
- this.$parent.editor.rangeRender()
1277
- }
1278
- //设置背景色
1279
- else if (name == 'backColor') {
1280
- setTextStyle(this.$parent, {
1281
- 'background-color': val
1282
- })
1283
- this.$parent.editor.formatElementStack()
1284
- this.$parent.editor.domRender()
1285
- this.$parent.editor.rangeRender()
1286
- }
1287
- //插入链接
1288
- else if (name == 'link') {
1289
- if (!val.url) {
1290
- return
1291
- }
1292
- insertLink(this.$parent, val.text, val.url, val.newOpen)
1293
- this.$parent.editor.formatElementStack()
1294
- this.$parent.editor.domRender()
1295
- this.$parent.editor.rangeRender()
1296
- }
1297
- //插入图片
1298
- else if (name == 'image') {
1299
- if (!val) {
1300
- return
1301
- }
1302
- insertImage(this.$parent, val)
1303
- this.$parent.editor.formatElementStack()
1304
- this.$parent.editor.domRender()
1305
- this.$parent.editor.rangeRender()
1306
- }
1307
- //插入视频
1308
- else if (name == 'video') {
1309
- if (!val) {
1310
- return
1311
- }
1312
- insertVideo(this.$parent, val)
1313
- this.$parent.editor.formatElementStack()
1314
- this.$parent.editor.domRender()
1315
- this.$parent.editor.rangeRender()
1316
- }
1317
- //插入表格
1318
- else if (name == 'table') {
1319
- insertTable(this.$parent, val.row, val.column)
1320
- this.$parent.editor.formatElementStack()
1321
- this.$parent.editor.domRender()
1322
- this.$parent.editor.rangeRender()
1323
- }
1324
- //插入代码块
1325
- else if (name == 'codeBlock') {
1326
- insertCodeBlock(this.$parent)
1327
- this.$parent.editor.formatElementStack()
1328
- this.$parent.editor.domRender()
1329
- this.$parent.editor.rangeRender()
1330
- }
1331
- //代码视图
1332
- else if (name == 'sourceView') {
1333
- this.$parent.isSourceView = !this.$parent.isSourceView
1334
- this.sourceViewConfig.active = this.$parent.isSourceView
1335
- if (!this.$parent.isSourceView) {
1336
- this.$parent.editor.rangeRender()
1337
- }
1338
- }
1339
- //全屏
1340
- else if (name == 'fullScreen') {
1341
- this.$parent.isFullScreen = !this.$parent.isFullScreen
1342
- this.fullScreenConfig.active = this.$parent.isFullScreen
1343
- this.$parent.editor.rangeRender()
1344
- }
1345
- },
1346
- //处理光标更新
1347
- handleRangeUpdate() {
1348
- //选区是否含有代码块
1349
- const value_hasPreInRange = hasPreInRange(this.$parent)
1350
- //选区是否含有表格元素
1351
- const value_hasTableInRange = hasTableInRange(this.$parent)
1352
- //选区是否含有引用元素
1353
- const value_hasQuoteInRange = hasQuoteInRange(this.$parent)
1354
- //选区是否都在引用元素内
1355
- const value_isRangeInQuote = isRangeInQuote(this.$parent)
1356
- //选区是否含有链接元素
1357
- const value_hasLinkInRange = hasLinkInRange(this.$parent)
1358
- //选区是否都在有序列表内
1359
- const value_isRangeInOrderList = isRangeInList(this.$parent, true)
1360
- //选区是否都在无序列表内
1361
- const value_isRangeInUnorderList = isRangeInList(this.$parent, false)
1362
- //选区是否都在任务列表内
1363
- const value_isRangeInTask = isRangeInTask(this.$parent)
1364
- //额外禁用判定
1365
- const extraDisabled = name => {
1366
- if (typeof this.config.extraDisabled == 'function') {
1367
- return this.config.extraDisabled.apply(this.$parent, [name]) || false
1368
- }
1369
- return false
1370
- }
1371
-
1372
- //撤销按钮禁用
1373
- this.undoConfig.disabled = !this.$parent.editor.history.get(-1) || extraDisabled('undo')
1374
-
1375
- //重做按钮禁用
1376
- this.redoConfig.disabled = !this.$parent.editor.history.get(1) || extraDisabled('redo')
1377
-
1378
- //显示已设置标题
1379
- const findHeadingItem = this.headingConfig.displayConfig.options.find(item => {
1380
- let val = item
1381
- if (DapCommon.isObject(item)) {
1382
- val = item.value
1383
- }
1384
- if (this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
1385
- return this.$parent.editor.range.anchor.element.getBlock().parsedom == val
1386
- }
1387
- return this.$parent.dataRangeCaches.list.every(el => {
1388
- if (el.element.isBlock()) {
1389
- return el.element.parsedom == val
1390
- }
1391
- return el.element.getBlock().parsedom == val
1392
- })
1393
- })
1394
- this.headingConfig.displayConfig.value = findHeadingItem ? (DapCommon.isObject(findHeadingItem) ? findHeadingItem.value : findHeadingItem) : this.headingConfig.defaultValue
1395
- //标题禁用
1396
- this.headingConfig.disabled = value_hasPreInRange || value_hasTableInRange || extraDisabled('heading')
1397
-
1398
- //缩进禁用
1399
- this.indentConfig.disabled = value_hasPreInRange || value_hasTableInRange || extraDisabled('indent')
1400
-
1401
- //引用按钮激活
1402
- this.quoteConfig.active = value_isRangeInQuote
1403
- //引用按钮禁用
1404
- this.quoteConfig.disabled = value_hasPreInRange || value_hasTableInRange || extraDisabled('quote')
1405
-
1406
- //对齐方式按钮禁用
1407
- this.alignConfig.disabled = value_hasPreInRange || extraDisabled('align')
1408
-
1409
- //有序列表按钮激活
1410
- this.orderListConfig.active = value_isRangeInOrderList
1411
- //有序列表禁用
1412
- this.orderListConfig.disabled = value_hasPreInRange || value_hasTableInRange || extraDisabled('orderList')
1413
-
1414
- //无序列表按钮激活
1415
- this.unorderListConfig.active = value_isRangeInUnorderList
1416
- //无序列表禁用
1417
- this.unorderListConfig.disabled = value_hasPreInRange || value_hasTableInRange || extraDisabled('unorderList')
1418
-
1419
- //任务列表按钮激活
1420
- this.taskConfig.active = value_isRangeInTask
1421
- //任务列表禁用
1422
- this.taskConfig.disabled = value_hasPreInRange || value_hasTableInRange || extraDisabled('task')
1423
-
1424
- //粗体按钮激活
1425
- this.boldConfig.active = queryTextStyle(this.$parent, 'font-weight', 'bold') || queryTextStyle(this.$parent, 'font-weight', '700')
1426
- //粗体按钮禁用
1427
- this.boldConfig.disabled = value_hasPreInRange || extraDisabled('bold')
1428
-
1429
- //下划线按钮激活
1430
- this.underlineConfig.active = queryTextStyle(this.$parent, 'text-decoration', 'underline') || queryTextStyle(this.$parent, 'text-decoration-line', 'underline')
1431
- //下划线按钮禁用
1432
- this.underlineConfig.disabled = value_hasPreInRange || extraDisabled('underline')
1433
-
1434
- //斜体按钮激活
1435
- this.italicConfig.active = queryTextStyle(this.$parent, 'font-style', 'italic')
1436
- //斜体按钮禁用
1437
- this.italicConfig.disabled = value_hasPreInRange || extraDisabled('italic')
1438
-
1439
- //删除线按钮激活
1440
- this.strikethroughConfig.active = queryTextStyle(this.$parent, 'text-decoration', 'line-through') || queryTextStyle(this.$parent, 'text-decoration-line', 'line-through')
1441
- //删除线按钮禁用
1442
- this.strikethroughConfig.disabled = value_hasPreInRange || extraDisabled('strikethrough')
1443
-
1444
- //行内代码按钮激活
1445
- this.codeConfig.active = queryTextMark(this.$parent, 'data-editify-code')
1446
- //行内代码按钮禁用
1447
- this.codeConfig.disabled = value_hasPreInRange || extraDisabled('code')
1448
-
1449
- //上标按钮激活
1450
- this.superConfig.active = queryTextStyle(this.$parent, 'vertical-align', 'super')
1451
- //上标按钮禁用
1452
- this.superConfig.disabled = value_hasPreInRange || extraDisabled('super')
1453
-
1454
- //下标按钮激活
1455
- this.subConfig.active = queryTextStyle(this.$parent, 'vertical-align', 'sub')
1456
- //下标按钮禁用
1457
- this.subConfig.disabled = value_hasPreInRange || extraDisabled('sub')
1458
-
1459
- //清除格式按钮禁用
1460
- this.formatClearConfig.disabled = value_hasPreInRange || extraDisabled('formatClear')
1461
-
1462
- //显示已选择字号
1463
- const findFontItem = this.fontSizeConfig.displayConfig.options.find(item => {
1464
- if (DapCommon.isObject(item)) {
1465
- return queryTextStyle(this.$parent, 'font-size', item.value)
1466
- }
1467
- return queryTextStyle(this.$parent, 'font-size', item)
1468
- })
1469
- this.fontSizeConfig.displayConfig.value = findFontItem ? (DapCommon.isObject(findFontItem) ? findFontItem.value : findFontItem) : this.fontSizeConfig.defaultValue
1470
- //字号按钮禁用
1471
- this.fontSizeConfig.disabled = value_hasPreInRange || extraDisabled('fontSize')
1472
-
1473
- //显示已选择字体
1474
- const findFamilyItem = this.fontFamilyConfig.displayConfig.options.find(item => {
1475
- if (DapCommon.isObject(item)) {
1476
- return queryTextStyle(this.$parent, 'font-family', item.value)
1477
- }
1478
- return queryTextStyle(this.$parent, 'font-family', item)
1479
- })
1480
- this.fontFamilyConfig.displayConfig.value = findFamilyItem ? (DapCommon.isObject(findFamilyItem) ? findFamilyItem.value : findFamilyItem) : this.fontFamilyConfig.defaultValue
1481
- //字体按钮禁用
1482
- this.fontFamilyConfig.disabled = value_hasPreInRange || extraDisabled('fontFamily')
1483
-
1484
- //显示已设置行高
1485
- const findHeightItem = this.lineHeightConfig.displayConfig.options.find(item => {
1486
- let val = item
1487
- if (DapCommon.isObject(item)) {
1488
- val = item.value
1489
- }
1490
- if (this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
1491
- const block = this.$parent.editor.range.anchor.element.getBlock()
1492
- return block.hasStyles() && block.styles['line-height'] == val
1493
- }
1494
- return this.$parent.dataRangeCaches.list.every(el => {
1495
- if (el.element.isBlock() || el.element.isInblock()) {
1496
- return el.element.hasStyles() && el.element.styles['line-height'] == val
1497
- }
1498
- const block = el.element.getBlock()
1499
- const inblock = el.element.getInblock()
1500
- if (inblock) {
1501
- return inblock.hasStyles() && inblock.styles['line-height'] == val
1502
- }
1503
- return block.hasStyles() && block.styles['line-height'] == val
1504
- })
1505
- })
1506
- this.lineHeightConfig.displayConfig.value = findHeightItem ? (DapCommon.isObject(findHeightItem) ? findHeightItem.value : findHeightItem) : this.lineHeightConfig.defaultValue
1507
- //行高按钮禁用
1508
- this.lineHeightConfig.disabled = value_hasPreInRange || extraDisabled('lineHeight')
1509
-
1510
- //显示已选择的前景色
1511
- const findForeColorItem = this.foreColorConfig.selectConfig.options.find(item => {
1512
- if (DapCommon.isObject(item)) {
1513
- return queryTextStyle(this.$parent, 'color', item.value)
1514
- }
1515
- return queryTextStyle(this.$parent, 'color', item)
1516
- })
1517
- this.foreColorConfig.value = findForeColorItem ? (DapCommon.isObject(findForeColorItem) ? findForeColorItem.value : findForeColorItem) : ''
1518
- //前景色按钮禁用
1519
- this.foreColorConfig.disabled = value_hasPreInRange || extraDisabled('foreColor')
1520
-
1521
- //显示已选择的背景色
1522
- const findBackColorItem = this.backColorConfig.selectConfig.options.find(item => {
1523
- if (DapCommon.isObject(item)) {
1524
- return queryTextStyle(this.$parent, 'background-color', item.value)
1525
- }
1526
- return queryTextStyle(this.$parent, 'background-color', item)
1527
- })
1528
- this.backColorConfig.value = findBackColorItem ? (DapCommon.isObject(findBackColorItem) ? findBackColorItem.value : findBackColorItem) : ''
1529
- //背景色按钮禁用
1530
- this.backColorConfig.disabled = value_hasPreInRange || extraDisabled('backColor')
1531
-
1532
- //链接按钮禁用
1533
- this.linkConfig.disabled = value_hasLinkInRange || value_hasPreInRange || extraDisabled('link')
1534
-
1535
- //插入图片按钮禁用
1536
- this.imageConfig.disabled = value_hasPreInRange || extraDisabled('image')
1537
-
1538
- //插入视频按钮禁用
1539
- this.videoConfig.disabled = value_hasPreInRange || extraDisabled('video')
1540
-
1541
- //表格按钮禁用
1542
- this.tableConfig.disabled = value_hasPreInRange || value_hasTableInRange || value_hasQuoteInRange || extraDisabled('table')
1543
-
1544
- //代码块按钮激活
1545
- this.codeBlockConfig.active = !!getCurrentParsedomElement(this.$parent, 'pre')
1546
- //代码块按钮禁用
1547
- this.codeBlockConfig.disabled = value_hasTableInRange || value_hasQuoteInRange || extraDisabled('codeBlock')
1548
-
1549
- //代码视图按钮激活
1550
- this.sourceViewConfig.active = this.$parent.isSourceView
1551
-
1552
- //全屏按钮激活
1553
- this.fullScreenConfig.active = this.$parent.isFullScreen
1554
- }
1555
- }
1556
- }
1557
- </script>
1558
- <style lang="less" scoped>
1559
- .editify-menu {
1560
- display: flex;
1561
- justify-content: flex-start;
1562
- flex-wrap: wrap;
1563
- width: 100%;
1564
- background-color: @background;
1565
- position: relative;
1566
- z-index: 2;
1567
-
1568
- //默认菜单模式
1569
- &[data-editify-mode='default'] {
1570
- margin-bottom: 10px;
1571
- padding: 6px 10px;
1572
-
1573
- //默认菜单模式显示边框,同时显示圆角
1574
- &.border {
1575
- border: 1px solid @border-color;
1576
- border-radius: 4px;
1577
- }
1578
-
1579
- //全屏模式下,默认菜单的边框失效,此时加一个下边框
1580
- &.fullscreen {
1581
- border-bottom: 1px solid @border-color;
1582
- }
1583
- }
1584
-
1585
- //inner菜单模式
1586
- &[data-editify-mode='inner'] {
1587
- padding: 10px;
1588
- margin-bottom: -20px;
1589
-
1590
- //inner菜单模式显示边框,同时显示圆角
1591
- &.border {
1592
- border: 1px solid @border-color;
1593
- border-bottom: none;
1594
- border-radius: 4px 4px 0 0;
1595
- transition: all 500ms;
1596
- }
1597
-
1598
- //inner菜单模式加一个下边框,此边框在代码视图下不显示
1599
- &:not(.source)::before {
1600
- position: absolute;
1601
- content: '';
1602
- width: calc(100% - 20px);
1603
- height: 1px;
1604
- background-color: @border-color;
1605
- left: 50%;
1606
- transform: translateX(-50%);
1607
- bottom: 0;
1608
- }
1609
- }
1610
-
1611
- //fixed菜单模式
1612
- &[data-editify-mode='fixed'] {
1613
- padding: 6px 10px;
1614
- position: fixed;
1615
- left: 0;
1616
- top: 0;
1617
- z-index: 100;
1618
- width: 100%;
1619
- border-bottom: 1px solid @border-color;
1620
- box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
1621
- }
1622
- }
1623
- </style>