vue-editify 0.0.1

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