vue-editify 0.0.23 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,1458 +1,1458 @@
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
- if (configuration) {
978
- //渲染函数
979
- return h(
980
- Button,
981
- {
982
- ...props,
983
- ref: 'btn',
984
- type: configuration.type || 'default',
985
- title: configuration.title || '',
986
- leftBorder: configuration.leftBorder || false,
987
- rightBorder: configuration.rightBorder || false,
988
- disabled: configuration.disabled || this.disabled || this.$parent.disabled,
989
- hideScroll: configuration.hideScroll || false,
990
- active: configuration.active || false,
991
- selectConfig: {
992
- width: configuration.width,
993
- maxHeight: configuration.maxHeight,
994
- options: configuration.options
995
- },
996
- displayConfig: {
997
- width: configuration.width,
998
- maxHeight: configuration.maxHeight,
999
- value: configuration.value,
1000
- options: configuration.options
1001
- },
1002
- color: this.$parent.color,
1003
- onLayerShow: () => {
1004
- if (typeof configuration.onLayerShow == 'function') {
1005
- configuration.onLayerShow.apply(this.$parent.$parent, [this.name, this.$refs.btn])
1006
- }
1007
- },
1008
- onLayerShown: () => {
1009
- if (typeof configuration.onLayerShown == 'function') {
1010
- configuration.onLayerShown.apply(this.$parent.$parent, [this.name, this.$refs.btn])
1011
- }
1012
- },
1013
- onLayerHidden: () => {
1014
- if (typeof configuration.onLayerHidden == 'function') {
1015
- configuration.onLayerHidden.apply(this.$parent.$parent, [this.name, this.$refs.btn])
1016
- }
1017
- },
1018
- onOperate: (name, val) => {
1019
- if (typeof configuration.onOperate == 'function') {
1020
- configuration.onOperate.apply(this.$parent.$parent, [name, val, this.$refs.btn])
1021
- }
1022
- }
1023
- },
1024
- {
1025
- default: configuration.default || null,
1026
- layer: configuration.layer || null,
1027
- option: configuration.option || null
1028
- }
1029
- )
1030
- }
1031
- }
1032
-
1033
- return null
1034
- }
1035
- }
1036
- },
1037
- methods: {
1038
- //按钮操作触发函数
1039
- handleOperate(name, val) {
1040
- if (this.disabled) {
1041
- return
1042
- }
1043
- //撤销
1044
- if (name == 'undo') {
1045
- this.$parent.undo()
1046
- }
1047
- //重做
1048
- else if (name == 'redo') {
1049
- this.$parent.redo()
1050
- }
1051
- //设置标题
1052
- else if (name == 'heading') {
1053
- this.$parent.setHeading(val)
1054
- }
1055
- //设置缩进
1056
- else if (name == 'indent') {
1057
- //增加缩进
1058
- if (val == 'indent-increase') {
1059
- this.$parent.setIndentIncrease()
1060
- }
1061
- //减少缩进
1062
- else if (val == 'indent-decrease') {
1063
- this.$parent.setIndentDecrease()
1064
- }
1065
- }
1066
- //设置引用
1067
- else if (name == 'quote') {
1068
- this.$parent.setQuote()
1069
- }
1070
- //设置对齐方式
1071
- else if (name == 'align') {
1072
- this.$parent.setAlign(val)
1073
- }
1074
- //设置有序列表
1075
- else if (name == 'orderList') {
1076
- this.$parent.setList(true)
1077
- }
1078
- //设置无序列表
1079
- else if (name == 'unorderList') {
1080
- this.$parent.setList(false)
1081
- }
1082
- //设置任务列表
1083
- else if (name == 'task') {
1084
- this.$parent.setTask()
1085
- }
1086
- //设置粗体
1087
- else if (name == 'bold') {
1088
- this.$parent.setTextStyle('font-weight', 'bold')
1089
- }
1090
- //设置下划线
1091
- else if (name == 'underline') {
1092
- this.$parent.setTextStyle('text-decoration', 'underline')
1093
- }
1094
- //设置斜体
1095
- else if (name == 'italic') {
1096
- this.$parent.setTextStyle('font-style', 'italic')
1097
- }
1098
- //设置删除线
1099
- else if (name == 'strikethrough') {
1100
- this.$parent.setTextStyle('text-decoration', 'line-through')
1101
- }
1102
- //设置行内代码
1103
- else if (name == 'code') {
1104
- this.$parent.setTextMark('data-editify-code', true)
1105
- }
1106
- //设置上标
1107
- else if (name == 'super') {
1108
- this.$parent.setTextStyle('vertical-align', 'super')
1109
- }
1110
- //设置下标
1111
- else if (name == 'sub') {
1112
- this.$parent.setTextStyle('vertical-align', 'sub')
1113
- }
1114
- //清除格式
1115
- else if (name == 'formatClear') {
1116
- this.$parent.formatText()
1117
- }
1118
- //设置字号
1119
- else if (name == 'fontSize') {
1120
- this.$parent.setTextStyle('font-size', val)
1121
- }
1122
- //设置字体
1123
- else if (name == 'fontFamily') {
1124
- this.$parent.setTextStyle('font-family', val)
1125
- }
1126
- //设置行高
1127
- else if (name == 'lineHeight') {
1128
- this.$parent.setLineHeight(val)
1129
- }
1130
- //设置前景色
1131
- else if (name == 'foreColor') {
1132
- this.$parent.setTextStyle('color', val)
1133
- }
1134
- //设置背景色
1135
- else if (name == 'backColor') {
1136
- this.$parent.setTextStyle('background-color', val)
1137
- }
1138
- //插入链接
1139
- else if (name == 'link') {
1140
- if (!val.url) {
1141
- return
1142
- }
1143
- if (!val.text) {
1144
- text = url
1145
- }
1146
- const marks = {
1147
- href: val.url
1148
- }
1149
- if (val.newOpen) {
1150
- marks.target = '_blank'
1151
- }
1152
- const linkEle = new AlexElement('inline', 'a', marks, null, null)
1153
- const textEle = new AlexElement('text', null, null, null, val.text)
1154
- this.$parent.editor.addElementTo(textEle, linkEle)
1155
- this.$parent.editor.insertElement(linkEle)
1156
- this.$parent.editor.formatElementStack()
1157
- this.$parent.editor.domRender()
1158
- this.$parent.editor.rangeRender()
1159
- }
1160
- //插入图片
1161
- else if (name == 'image') {
1162
- if (!val) {
1163
- return
1164
- }
1165
- this.$parent.insertImage(val)
1166
- }
1167
- //插入视频
1168
- else if (name == 'video') {
1169
- if (!val) {
1170
- return
1171
- }
1172
- this.$parent.insertVideo(val)
1173
- }
1174
- //插入表格
1175
- else if (name == 'table') {
1176
- this.$parent.insertTable(val.row, val.column)
1177
- }
1178
- //插入代码块
1179
- else if (name == 'codeBlock') {
1180
- this.$parent.insertCodeBlock()
1181
- }
1182
- //代码视图
1183
- else if (name == 'sourceView') {
1184
- this.$parent.isSourceView = !this.$parent.isSourceView
1185
- this.sourceViewConfig.active = this.$parent.isSourceView
1186
- if (!this.$parent.isSourceView) {
1187
- this.$parent.editor.rangeRender()
1188
- }
1189
- }
1190
- },
1191
- //处理光标更新
1192
- handleRangeUpdate() {
1193
- if (this.disabled) {
1194
- return
1195
- }
1196
- //获取选区的元素
1197
- const result = this.$parent.editor.getElementsByRange(true, false)
1198
- //选区是否含有代码块元素
1199
- const hasPreStyle = this.$parent.hasPreStyle()
1200
- //选区是否含有表格元素
1201
- const hasTable = this.$parent.hasTable()
1202
- //选区是否含有引用元素
1203
- const hasQuote = this.$parent.hasQuote()
1204
- //选区是否都在引用元素内
1205
- const inQuote = this.$parent.inQuote()
1206
- //选区是否含有链接元素
1207
- const hasLink = this.$parent.hasLink()
1208
- //选区是否都在有序列表内
1209
- const inOrderList = this.$parent.inList(true)
1210
- //选区是否都在无序列表内
1211
- const inUnorderList = this.$parent.inList(false)
1212
- //选区是否都在任务列表内
1213
- const inTask = this.$parent.inTask()
1214
- //额外禁用判定
1215
- const extraDisabled = name => {
1216
- if (typeof this.config.extraDisabled == 'function') {
1217
- return this.config.extraDisabled.apply(this.$parent, [name]) || false
1218
- }
1219
- return false
1220
- }
1221
-
1222
- //撤销按钮禁用
1223
- this.undoConfig.disabled = !this.$parent.editor.history.get(-1) || extraDisabled('undo')
1224
-
1225
- //重做按钮禁用
1226
- this.redoConfig.disabled = !this.$parent.editor.history.get(1) || extraDisabled('redo')
1227
-
1228
- //显示已设置标题
1229
- const findHeadingItem = this.headingConfig.displayConfig.options.find(item => {
1230
- let val = item
1231
- if (Dap.common.isObject(item)) {
1232
- val = item.value
1233
- }
1234
- if (this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
1235
- return this.$parent.editor.range.anchor.element.getBlock().parsedom == val
1236
- }
1237
- return result.every(el => {
1238
- if (el.element.isBlock()) {
1239
- return el.element.parsedom == val
1240
- }
1241
- return el.element.getBlock().parsedom == val
1242
- })
1243
- })
1244
- this.headingConfig.displayConfig.value = findHeadingItem ? (Dap.common.isObject(findHeadingItem) ? findHeadingItem.value : findHeadingItem) : this.headingConfig.defaultValue
1245
- //标题禁用
1246
- this.headingConfig.disabled = hasPreStyle || hasTable || extraDisabled('heading')
1247
-
1248
- //缩进禁用
1249
- this.indentConfig.disabled = hasPreStyle || hasTable || hasQuote || extraDisabled('indent')
1250
-
1251
- //引用按钮激活
1252
- this.quoteConfig.active = inQuote
1253
- //引用按钮禁用
1254
- this.quoteConfig.disabled = hasPreStyle || hasTable || extraDisabled('quote')
1255
-
1256
- //对齐方式按钮禁用
1257
- this.alignConfig.disabled = hasPreStyle || extraDisabled('align')
1258
-
1259
- //有序列表按钮激活
1260
- this.orderListConfig.active = inOrderList
1261
- //有序列表禁用
1262
- this.orderListConfig.disabled = hasPreStyle || hasTable || extraDisabled('orderList')
1263
-
1264
- //无序列表按钮激活
1265
- this.unorderListConfig.active = inUnorderList
1266
- //无序列表禁用
1267
- this.unorderListConfig.disabled = hasPreStyle || hasTable || extraDisabled('unorderList')
1268
-
1269
- //任务列表按钮激活
1270
- this.taskConfig.active = inTask
1271
- //任务列表禁用
1272
- this.taskConfig.disabled = hasPreStyle || hasTable || extraDisabled('task')
1273
-
1274
- //粗体按钮激活
1275
- this.boldConfig.active = this.$parent.queryTextStyle('font-weight', 'bold')
1276
- //粗体按钮禁用
1277
- this.boldConfig.disabled = hasPreStyle || extraDisabled('bold')
1278
-
1279
- //下划线按钮激活
1280
- this.underlineConfig.active = this.$parent.queryTextStyle('text-decoration', 'underline', true)
1281
- //下划线按钮禁用
1282
- this.underlineConfig.disabled = hasPreStyle || extraDisabled('underline')
1283
-
1284
- //斜体按钮激活
1285
- this.italicConfig.active = this.$parent.queryTextStyle('font-style', 'italic', true)
1286
- //斜体按钮禁用
1287
- this.italicConfig.disabled = hasPreStyle || extraDisabled('italic')
1288
-
1289
- //删除线按钮激活
1290
- this.strikethroughConfig.active = this.$parent.queryTextStyle('text-decoration', 'line-through', true)
1291
- //删除线按钮禁用
1292
- this.strikethroughConfig.disabled = hasPreStyle || extraDisabled('strikethrough')
1293
-
1294
- //行内代码按钮激活
1295
- this.codeConfig.active = this.$parent.queryTextMark('data-editify-code')
1296
- //行内代码按钮禁用
1297
- this.codeConfig.disabled = hasPreStyle || extraDisabled('code')
1298
-
1299
- //上标按钮激活
1300
- this.superConfig.active = this.$parent.queryTextStyle('vertical-align', 'super', true)
1301
- //上标按钮禁用
1302
- this.superConfig.disabled = hasPreStyle || extraDisabled('super')
1303
-
1304
- //下标按钮激活
1305
- this.subConfig.active = this.$parent.queryTextStyle('vertical-align', 'sub', true)
1306
- //下标按钮禁用
1307
- this.subConfig.disabled = hasPreStyle || extraDisabled('sub')
1308
-
1309
- //清除格式按钮禁用
1310
- this.formatClearConfig.disabled = hasPreStyle || extraDisabled('formatClear')
1311
-
1312
- //显示已选择字号
1313
- const findFontItem = this.fontSizeConfig.displayConfig.options.find(item => {
1314
- if (Dap.common.isObject(item)) {
1315
- return this.$parent.queryTextStyle('font-size', item.value, true)
1316
- }
1317
- return this.$parent.queryTextStyle('font-size', item, true)
1318
- })
1319
- this.fontSizeConfig.displayConfig.value = findFontItem ? (Dap.common.isObject(findFontItem) ? findFontItem.value : findFontItem) : this.fontSizeConfig.defaultValue
1320
- //字号按钮禁用
1321
- this.fontSizeConfig.disabled = hasPreStyle || extraDisabled('fontSize')
1322
-
1323
- //显示已选择字体
1324
- const findFamilyItem = this.fontFamilyConfig.displayConfig.options.find(item => {
1325
- if (Dap.common.isObject(item)) {
1326
- return this.$parent.queryTextStyle('font-family', item.value, true)
1327
- }
1328
- return this.$parent.queryTextStyle('font-family', item, true)
1329
- })
1330
- this.fontFamilyConfig.displayConfig.value = findFamilyItem ? (Dap.common.isObject(findFamilyItem) ? findFamilyItem.value : findFamilyItem) : this.fontFamilyConfig.defaultValue
1331
- //字体按钮禁用
1332
- this.fontFamilyConfig.disabled = hasPreStyle || extraDisabled('fontFamily')
1333
-
1334
- //显示已设置行高
1335
- const findHeightItem = this.lineHeightConfig.displayConfig.options.find(item => {
1336
- let val = item
1337
- if (Dap.common.isObject(item)) {
1338
- val = item.value
1339
- }
1340
- if (this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
1341
- const block = this.$parent.editor.range.anchor.element.getBlock()
1342
- return block.hasStyles() && block.styles['line-height'] == val
1343
- }
1344
- return result.every(el => {
1345
- if (el.element.isBlock() || el.element.isInblock()) {
1346
- return el.element.hasStyles() && el.element.styles['line-height'] == val
1347
- }
1348
- const block = el.element.getBlock()
1349
- const inblock = el.element.getInblock()
1350
- if (inblock) {
1351
- return inblock.hasStyles() && inblock.styles['line-height'] == val
1352
- }
1353
- return block.hasStyles() && block.styles['line-height'] == val
1354
- })
1355
- })
1356
- this.lineHeightConfig.displayConfig.value = findHeightItem ? (Dap.common.isObject(findHeightItem) ? findHeightItem.value : findHeightItem) : this.lineHeightConfig.defaultValue
1357
- //行高按钮禁用
1358
- this.lineHeightConfig.disabled = hasPreStyle || extraDisabled('lineHeight')
1359
-
1360
- //显示已选择的前景色
1361
- const findForeColorItem = this.foreColorConfig.selectConfig.options.find(item => {
1362
- if (Dap.common.isObject(item)) {
1363
- return this.$parent.queryTextStyle('color', item.value, true)
1364
- }
1365
- return this.$parent.queryTextStyle('color', item, true)
1366
- })
1367
- this.foreColorConfig.value = findForeColorItem ? (Dap.common.isObject(findForeColorItem) ? findForeColorItem.value : findForeColorItem) : ''
1368
- //前景色按钮禁用
1369
- this.foreColorConfig.disabled = hasPreStyle || extraDisabled('foreColor')
1370
-
1371
- //显示已选择的背景色
1372
- const findBackColorItem = this.backColorConfig.selectConfig.options.find(item => {
1373
- if (Dap.common.isObject(item)) {
1374
- return this.$parent.queryTextStyle('background-color', item.value, true)
1375
- }
1376
- return this.$parent.queryTextStyle('background-color', item, true)
1377
- })
1378
- this.backColorConfig.value = findBackColorItem ? (Dap.common.isObject(findBackColorItem) ? findBackColorItem.value : findBackColorItem) : ''
1379
- //背景色按钮禁用
1380
- this.backColorConfig.disabled = hasPreStyle || extraDisabled('backColor')
1381
-
1382
- //链接按钮禁用
1383
- this.linkConfig.disabled = hasLink || hasPreStyle || extraDisabled('link')
1384
-
1385
- //插入图片按钮禁用
1386
- this.imageConfig.disabled = hasPreStyle || extraDisabled('image')
1387
-
1388
- //插入视频按钮禁用
1389
- this.videoConfig.disabled = hasPreStyle || extraDisabled('video')
1390
-
1391
- //表格按钮禁用
1392
- this.tableConfig.disabled = hasPreStyle || hasTable || hasQuote || extraDisabled('table')
1393
-
1394
- //代码块按钮激活
1395
- this.codeBlockConfig.active = !!this.$parent.getCurrentParsedomElement('pre')
1396
- //代码块按钮禁用
1397
- this.codeBlockConfig.disabled = hasTable || hasQuote || extraDisabled('codeBlock')
1398
-
1399
- //代码视图按钮激活
1400
- this.sourceViewConfig.active = this.$parent.isSourceView
1401
- }
1402
- }
1403
- }
1404
- </script>
1405
- <style lang="less" scoped>
1406
- .editify-menu {
1407
- display: flex;
1408
- justify-content: flex-start;
1409
- flex-wrap: wrap;
1410
- width: 100%;
1411
- background-color: @background;
1412
- position: relative;
1413
- z-index: 5;
1414
-
1415
- &[data-editify-mode='default'] {
1416
- margin-bottom: 10px;
1417
- padding: 6px 10px;
1418
-
1419
- &.border {
1420
- border: 1px solid @border-color;
1421
- border-radius: 4px;
1422
- }
1423
- }
1424
-
1425
- &[data-editify-mode='inner'] {
1426
- padding: 10px;
1427
-
1428
- &.border {
1429
- border: 1px solid @border-color;
1430
- border-bottom: none;
1431
- border-radius: 4px 4px 0 0;
1432
- transition: all 500ms;
1433
-
1434
- &::before {
1435
- position: absolute;
1436
- content: '';
1437
- width: calc(100% - 20px);
1438
- height: 1px;
1439
- background-color: @border-color;
1440
- left: 50%;
1441
- transform: translateX(-50%);
1442
- bottom: 0;
1443
- }
1444
- }
1445
- }
1446
-
1447
- &[data-editify-mode='fixed'] {
1448
- padding: 6px 10px;
1449
- position: fixed;
1450
- left: 0;
1451
- top: 0;
1452
- z-index: 100;
1453
- width: 100%;
1454
- border-bottom: 1px solid @border-color;
1455
- box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
1456
- }
1457
- }
1458
- </style>
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
+ if (configuration) {
978
+ //渲染函数
979
+ return h(
980
+ Button,
981
+ {
982
+ ...props,
983
+ ref: 'btn',
984
+ type: configuration.type || 'default',
985
+ title: configuration.title || '',
986
+ leftBorder: configuration.leftBorder || false,
987
+ rightBorder: configuration.rightBorder || false,
988
+ disabled: configuration.disabled || this.disabled || this.$parent.disabled,
989
+ hideScroll: configuration.hideScroll || false,
990
+ active: configuration.active || false,
991
+ selectConfig: {
992
+ width: configuration.width,
993
+ maxHeight: configuration.maxHeight,
994
+ options: configuration.options
995
+ },
996
+ displayConfig: {
997
+ width: configuration.width,
998
+ maxHeight: configuration.maxHeight,
999
+ value: configuration.value,
1000
+ options: configuration.options
1001
+ },
1002
+ color: this.$parent.color,
1003
+ onLayerShow: () => {
1004
+ if (typeof configuration.onLayerShow == 'function') {
1005
+ configuration.onLayerShow.apply(this.$parent.$parent, [this.name, this.$refs.btn])
1006
+ }
1007
+ },
1008
+ onLayerShown: () => {
1009
+ if (typeof configuration.onLayerShown == 'function') {
1010
+ configuration.onLayerShown.apply(this.$parent.$parent, [this.name, this.$refs.btn])
1011
+ }
1012
+ },
1013
+ onLayerHidden: () => {
1014
+ if (typeof configuration.onLayerHidden == 'function') {
1015
+ configuration.onLayerHidden.apply(this.$parent.$parent, [this.name, this.$refs.btn])
1016
+ }
1017
+ },
1018
+ onOperate: (name, val) => {
1019
+ if (typeof configuration.onOperate == 'function') {
1020
+ configuration.onOperate.apply(this.$parent.$parent, [name, val, this.$refs.btn])
1021
+ }
1022
+ }
1023
+ },
1024
+ {
1025
+ default: configuration.default || null,
1026
+ layer: configuration.layer || null,
1027
+ option: configuration.option || null
1028
+ }
1029
+ )
1030
+ }
1031
+ }
1032
+
1033
+ return null
1034
+ }
1035
+ }
1036
+ },
1037
+ methods: {
1038
+ //按钮操作触发函数
1039
+ handleOperate(name, val) {
1040
+ if (this.disabled) {
1041
+ return
1042
+ }
1043
+ //撤销
1044
+ if (name == 'undo') {
1045
+ this.$parent.undo()
1046
+ }
1047
+ //重做
1048
+ else if (name == 'redo') {
1049
+ this.$parent.redo()
1050
+ }
1051
+ //设置标题
1052
+ else if (name == 'heading') {
1053
+ this.$parent.setHeading(val)
1054
+ }
1055
+ //设置缩进
1056
+ else if (name == 'indent') {
1057
+ //增加缩进
1058
+ if (val == 'indent-increase') {
1059
+ this.$parent.setIndentIncrease()
1060
+ }
1061
+ //减少缩进
1062
+ else if (val == 'indent-decrease') {
1063
+ this.$parent.setIndentDecrease()
1064
+ }
1065
+ }
1066
+ //设置引用
1067
+ else if (name == 'quote') {
1068
+ this.$parent.setQuote()
1069
+ }
1070
+ //设置对齐方式
1071
+ else if (name == 'align') {
1072
+ this.$parent.setAlign(val)
1073
+ }
1074
+ //设置有序列表
1075
+ else if (name == 'orderList') {
1076
+ this.$parent.setList(true)
1077
+ }
1078
+ //设置无序列表
1079
+ else if (name == 'unorderList') {
1080
+ this.$parent.setList(false)
1081
+ }
1082
+ //设置任务列表
1083
+ else if (name == 'task') {
1084
+ this.$parent.setTask()
1085
+ }
1086
+ //设置粗体
1087
+ else if (name == 'bold') {
1088
+ this.$parent.setTextStyle('font-weight', 'bold')
1089
+ }
1090
+ //设置下划线
1091
+ else if (name == 'underline') {
1092
+ this.$parent.setTextStyle('text-decoration', 'underline')
1093
+ }
1094
+ //设置斜体
1095
+ else if (name == 'italic') {
1096
+ this.$parent.setTextStyle('font-style', 'italic')
1097
+ }
1098
+ //设置删除线
1099
+ else if (name == 'strikethrough') {
1100
+ this.$parent.setTextStyle('text-decoration', 'line-through')
1101
+ }
1102
+ //设置行内代码
1103
+ else if (name == 'code') {
1104
+ this.$parent.setTextMark('data-editify-code', true)
1105
+ }
1106
+ //设置上标
1107
+ else if (name == 'super') {
1108
+ this.$parent.setTextStyle('vertical-align', 'super')
1109
+ }
1110
+ //设置下标
1111
+ else if (name == 'sub') {
1112
+ this.$parent.setTextStyle('vertical-align', 'sub')
1113
+ }
1114
+ //清除格式
1115
+ else if (name == 'formatClear') {
1116
+ this.$parent.formatText()
1117
+ }
1118
+ //设置字号
1119
+ else if (name == 'fontSize') {
1120
+ this.$parent.setTextStyle('font-size', val)
1121
+ }
1122
+ //设置字体
1123
+ else if (name == 'fontFamily') {
1124
+ this.$parent.setTextStyle('font-family', val)
1125
+ }
1126
+ //设置行高
1127
+ else if (name == 'lineHeight') {
1128
+ this.$parent.setLineHeight(val)
1129
+ }
1130
+ //设置前景色
1131
+ else if (name == 'foreColor') {
1132
+ this.$parent.setTextStyle('color', val)
1133
+ }
1134
+ //设置背景色
1135
+ else if (name == 'backColor') {
1136
+ this.$parent.setTextStyle('background-color', val)
1137
+ }
1138
+ //插入链接
1139
+ else if (name == 'link') {
1140
+ if (!val.url) {
1141
+ return
1142
+ }
1143
+ if (!val.text) {
1144
+ text = url
1145
+ }
1146
+ const marks = {
1147
+ href: val.url
1148
+ }
1149
+ if (val.newOpen) {
1150
+ marks.target = '_blank'
1151
+ }
1152
+ const linkEle = new AlexElement('inline', 'a', marks, null, null)
1153
+ const textEle = new AlexElement('text', null, null, null, val.text)
1154
+ this.$parent.editor.addElementTo(textEle, linkEle)
1155
+ this.$parent.editor.insertElement(linkEle)
1156
+ this.$parent.editor.formatElementStack()
1157
+ this.$parent.editor.domRender()
1158
+ this.$parent.editor.rangeRender()
1159
+ }
1160
+ //插入图片
1161
+ else if (name == 'image') {
1162
+ if (!val) {
1163
+ return
1164
+ }
1165
+ this.$parent.insertImage(val)
1166
+ }
1167
+ //插入视频
1168
+ else if (name == 'video') {
1169
+ if (!val) {
1170
+ return
1171
+ }
1172
+ this.$parent.insertVideo(val)
1173
+ }
1174
+ //插入表格
1175
+ else if (name == 'table') {
1176
+ this.$parent.insertTable(val.row, val.column)
1177
+ }
1178
+ //插入代码块
1179
+ else if (name == 'codeBlock') {
1180
+ this.$parent.insertCodeBlock()
1181
+ }
1182
+ //代码视图
1183
+ else if (name == 'sourceView') {
1184
+ this.$parent.isSourceView = !this.$parent.isSourceView
1185
+ this.sourceViewConfig.active = this.$parent.isSourceView
1186
+ if (!this.$parent.isSourceView) {
1187
+ this.$parent.editor.rangeRender()
1188
+ }
1189
+ }
1190
+ },
1191
+ //处理光标更新
1192
+ handleRangeUpdate() {
1193
+ if (this.disabled) {
1194
+ return
1195
+ }
1196
+ //获取选区的元素
1197
+ const result = this.$parent.editor.getElementsByRange(true, false)
1198
+ //选区是否含有代码块元素
1199
+ const hasPreStyle = this.$parent.hasPreStyle()
1200
+ //选区是否含有表格元素
1201
+ const hasTable = this.$parent.hasTable()
1202
+ //选区是否含有引用元素
1203
+ const hasQuote = this.$parent.hasQuote()
1204
+ //选区是否都在引用元素内
1205
+ const inQuote = this.$parent.inQuote()
1206
+ //选区是否含有链接元素
1207
+ const hasLink = this.$parent.hasLink()
1208
+ //选区是否都在有序列表内
1209
+ const inOrderList = this.$parent.inList(true)
1210
+ //选区是否都在无序列表内
1211
+ const inUnorderList = this.$parent.inList(false)
1212
+ //选区是否都在任务列表内
1213
+ const inTask = this.$parent.inTask()
1214
+ //额外禁用判定
1215
+ const extraDisabled = name => {
1216
+ if (typeof this.config.extraDisabled == 'function') {
1217
+ return this.config.extraDisabled.apply(this.$parent, [name]) || false
1218
+ }
1219
+ return false
1220
+ }
1221
+
1222
+ //撤销按钮禁用
1223
+ this.undoConfig.disabled = !this.$parent.editor.history.get(-1) || extraDisabled('undo')
1224
+
1225
+ //重做按钮禁用
1226
+ this.redoConfig.disabled = !this.$parent.editor.history.get(1) || extraDisabled('redo')
1227
+
1228
+ //显示已设置标题
1229
+ const findHeadingItem = this.headingConfig.displayConfig.options.find(item => {
1230
+ let val = item
1231
+ if (Dap.common.isObject(item)) {
1232
+ val = item.value
1233
+ }
1234
+ if (this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
1235
+ return this.$parent.editor.range.anchor.element.getBlock().parsedom == val
1236
+ }
1237
+ return result.every(el => {
1238
+ if (el.element.isBlock()) {
1239
+ return el.element.parsedom == val
1240
+ }
1241
+ return el.element.getBlock().parsedom == val
1242
+ })
1243
+ })
1244
+ this.headingConfig.displayConfig.value = findHeadingItem ? (Dap.common.isObject(findHeadingItem) ? findHeadingItem.value : findHeadingItem) : this.headingConfig.defaultValue
1245
+ //标题禁用
1246
+ this.headingConfig.disabled = hasPreStyle || hasTable || extraDisabled('heading')
1247
+
1248
+ //缩进禁用
1249
+ this.indentConfig.disabled = hasPreStyle || hasTable || hasQuote || extraDisabled('indent')
1250
+
1251
+ //引用按钮激活
1252
+ this.quoteConfig.active = inQuote
1253
+ //引用按钮禁用
1254
+ this.quoteConfig.disabled = hasPreStyle || hasTable || extraDisabled('quote')
1255
+
1256
+ //对齐方式按钮禁用
1257
+ this.alignConfig.disabled = hasPreStyle || extraDisabled('align')
1258
+
1259
+ //有序列表按钮激活
1260
+ this.orderListConfig.active = inOrderList
1261
+ //有序列表禁用
1262
+ this.orderListConfig.disabled = hasPreStyle || hasTable || extraDisabled('orderList')
1263
+
1264
+ //无序列表按钮激活
1265
+ this.unorderListConfig.active = inUnorderList
1266
+ //无序列表禁用
1267
+ this.unorderListConfig.disabled = hasPreStyle || hasTable || extraDisabled('unorderList')
1268
+
1269
+ //任务列表按钮激活
1270
+ this.taskConfig.active = inTask
1271
+ //任务列表禁用
1272
+ this.taskConfig.disabled = hasPreStyle || hasTable || extraDisabled('task')
1273
+
1274
+ //粗体按钮激活
1275
+ this.boldConfig.active = this.$parent.queryTextStyle('font-weight', 'bold')
1276
+ //粗体按钮禁用
1277
+ this.boldConfig.disabled = hasPreStyle || extraDisabled('bold')
1278
+
1279
+ //下划线按钮激活
1280
+ this.underlineConfig.active = this.$parent.queryTextStyle('text-decoration', 'underline', true)
1281
+ //下划线按钮禁用
1282
+ this.underlineConfig.disabled = hasPreStyle || extraDisabled('underline')
1283
+
1284
+ //斜体按钮激活
1285
+ this.italicConfig.active = this.$parent.queryTextStyle('font-style', 'italic', true)
1286
+ //斜体按钮禁用
1287
+ this.italicConfig.disabled = hasPreStyle || extraDisabled('italic')
1288
+
1289
+ //删除线按钮激活
1290
+ this.strikethroughConfig.active = this.$parent.queryTextStyle('text-decoration', 'line-through', true)
1291
+ //删除线按钮禁用
1292
+ this.strikethroughConfig.disabled = hasPreStyle || extraDisabled('strikethrough')
1293
+
1294
+ //行内代码按钮激活
1295
+ this.codeConfig.active = this.$parent.queryTextMark('data-editify-code')
1296
+ //行内代码按钮禁用
1297
+ this.codeConfig.disabled = hasPreStyle || extraDisabled('code')
1298
+
1299
+ //上标按钮激活
1300
+ this.superConfig.active = this.$parent.queryTextStyle('vertical-align', 'super', true)
1301
+ //上标按钮禁用
1302
+ this.superConfig.disabled = hasPreStyle || extraDisabled('super')
1303
+
1304
+ //下标按钮激活
1305
+ this.subConfig.active = this.$parent.queryTextStyle('vertical-align', 'sub', true)
1306
+ //下标按钮禁用
1307
+ this.subConfig.disabled = hasPreStyle || extraDisabled('sub')
1308
+
1309
+ //清除格式按钮禁用
1310
+ this.formatClearConfig.disabled = hasPreStyle || extraDisabled('formatClear')
1311
+
1312
+ //显示已选择字号
1313
+ const findFontItem = this.fontSizeConfig.displayConfig.options.find(item => {
1314
+ if (Dap.common.isObject(item)) {
1315
+ return this.$parent.queryTextStyle('font-size', item.value, true)
1316
+ }
1317
+ return this.$parent.queryTextStyle('font-size', item, true)
1318
+ })
1319
+ this.fontSizeConfig.displayConfig.value = findFontItem ? (Dap.common.isObject(findFontItem) ? findFontItem.value : findFontItem) : this.fontSizeConfig.defaultValue
1320
+ //字号按钮禁用
1321
+ this.fontSizeConfig.disabled = hasPreStyle || extraDisabled('fontSize')
1322
+
1323
+ //显示已选择字体
1324
+ const findFamilyItem = this.fontFamilyConfig.displayConfig.options.find(item => {
1325
+ if (Dap.common.isObject(item)) {
1326
+ return this.$parent.queryTextStyle('font-family', item.value, true)
1327
+ }
1328
+ return this.$parent.queryTextStyle('font-family', item, true)
1329
+ })
1330
+ this.fontFamilyConfig.displayConfig.value = findFamilyItem ? (Dap.common.isObject(findFamilyItem) ? findFamilyItem.value : findFamilyItem) : this.fontFamilyConfig.defaultValue
1331
+ //字体按钮禁用
1332
+ this.fontFamilyConfig.disabled = hasPreStyle || extraDisabled('fontFamily')
1333
+
1334
+ //显示已设置行高
1335
+ const findHeightItem = this.lineHeightConfig.displayConfig.options.find(item => {
1336
+ let val = item
1337
+ if (Dap.common.isObject(item)) {
1338
+ val = item.value
1339
+ }
1340
+ if (this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
1341
+ const block = this.$parent.editor.range.anchor.element.getBlock()
1342
+ return block.hasStyles() && block.styles['line-height'] == val
1343
+ }
1344
+ return result.every(el => {
1345
+ if (el.element.isBlock() || el.element.isInblock()) {
1346
+ return el.element.hasStyles() && el.element.styles['line-height'] == val
1347
+ }
1348
+ const block = el.element.getBlock()
1349
+ const inblock = el.element.getInblock()
1350
+ if (inblock) {
1351
+ return inblock.hasStyles() && inblock.styles['line-height'] == val
1352
+ }
1353
+ return block.hasStyles() && block.styles['line-height'] == val
1354
+ })
1355
+ })
1356
+ this.lineHeightConfig.displayConfig.value = findHeightItem ? (Dap.common.isObject(findHeightItem) ? findHeightItem.value : findHeightItem) : this.lineHeightConfig.defaultValue
1357
+ //行高按钮禁用
1358
+ this.lineHeightConfig.disabled = hasPreStyle || extraDisabled('lineHeight')
1359
+
1360
+ //显示已选择的前景色
1361
+ const findForeColorItem = this.foreColorConfig.selectConfig.options.find(item => {
1362
+ if (Dap.common.isObject(item)) {
1363
+ return this.$parent.queryTextStyle('color', item.value, true)
1364
+ }
1365
+ return this.$parent.queryTextStyle('color', item, true)
1366
+ })
1367
+ this.foreColorConfig.value = findForeColorItem ? (Dap.common.isObject(findForeColorItem) ? findForeColorItem.value : findForeColorItem) : ''
1368
+ //前景色按钮禁用
1369
+ this.foreColorConfig.disabled = hasPreStyle || extraDisabled('foreColor')
1370
+
1371
+ //显示已选择的背景色
1372
+ const findBackColorItem = this.backColorConfig.selectConfig.options.find(item => {
1373
+ if (Dap.common.isObject(item)) {
1374
+ return this.$parent.queryTextStyle('background-color', item.value, true)
1375
+ }
1376
+ return this.$parent.queryTextStyle('background-color', item, true)
1377
+ })
1378
+ this.backColorConfig.value = findBackColorItem ? (Dap.common.isObject(findBackColorItem) ? findBackColorItem.value : findBackColorItem) : ''
1379
+ //背景色按钮禁用
1380
+ this.backColorConfig.disabled = hasPreStyle || extraDisabled('backColor')
1381
+
1382
+ //链接按钮禁用
1383
+ this.linkConfig.disabled = hasLink || hasPreStyle || extraDisabled('link')
1384
+
1385
+ //插入图片按钮禁用
1386
+ this.imageConfig.disabled = hasPreStyle || extraDisabled('image')
1387
+
1388
+ //插入视频按钮禁用
1389
+ this.videoConfig.disabled = hasPreStyle || extraDisabled('video')
1390
+
1391
+ //表格按钮禁用
1392
+ this.tableConfig.disabled = hasPreStyle || hasTable || hasQuote || extraDisabled('table')
1393
+
1394
+ //代码块按钮激活
1395
+ this.codeBlockConfig.active = !!this.$parent.getCurrentParsedomElement('pre')
1396
+ //代码块按钮禁用
1397
+ this.codeBlockConfig.disabled = hasTable || hasQuote || extraDisabled('codeBlock')
1398
+
1399
+ //代码视图按钮激活
1400
+ this.sourceViewConfig.active = this.$parent.isSourceView
1401
+ }
1402
+ }
1403
+ }
1404
+ </script>
1405
+ <style lang="less" scoped>
1406
+ .editify-menu {
1407
+ display: flex;
1408
+ justify-content: flex-start;
1409
+ flex-wrap: wrap;
1410
+ width: 100%;
1411
+ background-color: @background;
1412
+ position: relative;
1413
+ z-index: 5;
1414
+
1415
+ &[data-editify-mode='default'] {
1416
+ margin-bottom: 10px;
1417
+ padding: 6px 10px;
1418
+
1419
+ &.border {
1420
+ border: 1px solid @border-color;
1421
+ border-radius: 4px;
1422
+ }
1423
+ }
1424
+
1425
+ &[data-editify-mode='inner'] {
1426
+ padding: 10px;
1427
+
1428
+ &.border {
1429
+ border: 1px solid @border-color;
1430
+ border-bottom: none;
1431
+ border-radius: 4px 4px 0 0;
1432
+ transition: all 500ms;
1433
+
1434
+ &::before {
1435
+ position: absolute;
1436
+ content: '';
1437
+ width: calc(100% - 20px);
1438
+ height: 1px;
1439
+ background-color: @border-color;
1440
+ left: 50%;
1441
+ transform: translateX(-50%);
1442
+ bottom: 0;
1443
+ }
1444
+ }
1445
+ }
1446
+
1447
+ &[data-editify-mode='fixed'] {
1448
+ padding: 6px 10px;
1449
+ position: fixed;
1450
+ left: 0;
1451
+ top: 0;
1452
+ z-index: 100;
1453
+ width: 100%;
1454
+ border-bottom: 1px solid @border-color;
1455
+ box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
1456
+ }
1457
+ }
1458
+ </style>