vue-editify 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,1122 +1,1122 @@
1
- <template>
2
- <Layer v-model="show" ref="layer" :node="node" border placement="bottom-start" @show="layerShow" :useRange="type == 'text'">
3
- <div class="editify-toolbar" ref="toolbar" :style="config.style">
4
- <!-- 链接工具条 -->
5
- <template v-if="type == 'link'">
6
- <div class="editify-toolbar-link">
7
- <div class="editify-toolbar-link-label">{{ $editTrans('linkAddress') }}</div>
8
- <input @input="modifyLink" @focus="handleInputFocus" @blur="handleInputBlur" :placeholder="$editTrans('linkUrlEnterPlaceholder')" v-model.trim="linkConfig.url" type="url" />
9
- <div class="editify-toolbar-link-footer">
10
- <Checkbox @change="modifyLink" v-model="linkConfig.newOpen" :label="$editTrans('newWindowOpen')" :color="$parent.color" :size="10"></Checkbox>
11
- <div class="editify-toolbar-link-operations">
12
- <span @click="$parent.removeLink">{{ $editTrans('removeLink') }}</span>
13
- <a :href="linkConfig.url" target="_blank" :style="{ color: $parent.color }">{{ $editTrans('viewLink') }}</a>
14
- </div>
15
- </div>
16
- </div>
17
- </template>
18
- <!-- 图片工具条 -->
19
- <template v-else-if="type == 'image'">
20
- <!-- 设置宽度30% -->
21
- <Button @operate="setWidth('30%')" name="set30Width" :title="$editTrans('width30')" :tooltip="config.tooltip" :color="$parent.color"> 30% </Button>
22
- <!-- 设置宽度50% -->
23
- <Button @operate="setWidth('50%')" name="set50Width" :title="$editTrans('width50')" :tooltip="config.tooltip" :color="$parent.color"> 50% </Button>
24
- <!-- 设置宽度100% -->
25
- <Button rightBorder @operate="setWidth('100%')" name="set100Width" :title="$editTrans('width100')" :tooltip="config.tooltip" :color="$parent.color"> 100% </Button>
26
- <!-- 删除图片 -->
27
- <Button @operate="$parent.deleteByParsedom('img')" name="deleteImage" :title="$editTrans('deleteImage')" :tooltip="config.tooltip" :color="$parent.color">
28
- <Icon value="delete"></Icon>
29
- </Button>
30
- </template>
31
- <!-- 视频工具条 -->
32
- <template v-else-if="type == 'video'">
33
- <!-- 设置宽度30% -->
34
- <Button @operate="setWidth('30%')" name="set30Width" :title="$editTrans('width30')" :tooltip="config.tooltip" :color="$parent.color"> 30% </Button>
35
- <!-- 设置宽度50% -->
36
- <Button @operate="setWidth('50%')" name="set50Width" :title="$editTrans('width50')" :tooltip="config.tooltip" :color="$parent.color"> 50% </Button>
37
- <!-- 设置宽度100% -->
38
- <Button rightBorder @operate="setWidth('100%')" name="set100Width" :title="$editTrans('width100')" :tooltip="config.tooltip" :color="$parent.color"> 100% </Button>
39
- <!-- 自动播放 -->
40
- <Button @operate="setVideo" name="autoplay" :title="videoConfig.autoplay ? $editTrans('disabledAutoplay') : $editTrans('autoplay')" :tooltip="config.tooltip" :color="$parent.color">
41
- <Icon :value="videoConfig.autoplay ? 'autoplay' : 'stop'"></Icon>
42
- </Button>
43
- <!-- 循环播放 -->
44
- <Button @operate="setVideo" name="loop" :title="videoConfig.loop ? $editTrans('disabledLoop') : $editTrans('loop')" :tooltip="config.tooltip" :color="$parent.color">
45
- <Icon :value="videoConfig.loop ? 'loop' : 'single'"></Icon>
46
- </Button>
47
- <!-- 是否静音 -->
48
- <Button @operate="setVideo" name="muted" :title="videoConfig.muted ? $editTrans('unmuted') : $editTrans('muted')" :tooltip="config.tooltip" :color="$parent.color">
49
- <Icon :value="videoConfig.muted ? 'muted' : 'unmuted'"></Icon>
50
- </Button>
51
- <!-- 是否显示控制器 -->
52
- <Button leftBorder @operate="setVideo" name="controls" :title="$editTrans('controls')" :tooltip="config.tooltip" :color="$parent.color">
53
- <Icon value="controls"></Icon>
54
- </Button>
55
- <!-- 删除视频 -->
56
- <Button @operate="$parent.deleteByParsedom('video')" name="deleteVideo" :title="$editTrans('deleteVideo')" :tooltip="config.tooltip" :color="$parent.color">
57
- <Icon value="delete"></Icon>
58
- </Button>
59
- </template>
60
- <!-- 表格工具条 -->
61
- <template v-else-if="type == 'table'">
62
- <!-- 表格前插入段落 -->
63
- <Button @operate="insertParagraphWithTable('up')" name="textWrapUp" :title="$editTrans('textWrapUp')" :tooltip="config.tooltip" :color="$parent.color">
64
- <Icon value="text-wrap" class="editify-icon-rotate"></Icon>
65
- </Button>
66
- <!-- 表格后插入段落 -->
67
- <Button @operate="insertParagraphWithTable('down')" rightBorder name="textWrapDown" :title="$editTrans('textWrapDown')" :tooltip="config.tooltip" :color="$parent.color">
68
- <Icon value="text-wrap"></Icon>
69
- </Button>
70
- <!-- 向前插入行 -->
71
- <Button @operate="insertTableRow('up')" name="insertRowTop" :title="$editTrans('insertRowTop')" :tooltip="config.tooltip" :color="$parent.color">
72
- <Icon value="insert-row-top"></Icon>
73
- </Button>
74
- <!-- 向后插入行 -->
75
- <Button @operate="insertTableRow('down')" name="insertRowBottom" :title="$editTrans('insertRowBottom')" :tooltip="config.tooltip" :color="$parent.color">
76
- <Icon value="insert-row-bottom"></Icon>
77
- </Button>
78
- <!-- 删除行 -->
79
- <Button @operate="deleteTableRow" rightBorder name="deleteRow" :title="$editTrans('deleteRow')" :tooltip="config.tooltip" :color="$parent.color">
80
- <Icon value="delete-row"></Icon>
81
- </Button>
82
- <!-- 向前插入列 -->
83
- <Button @operate="insertTableColumn('left')" name="insertColumnLeft" :title="$editTrans('insertColumnLeft')" :tooltip="config.tooltip" :color="$parent.color">
84
- <Icon value="insert-column-left"></Icon>
85
- </Button>
86
- <!-- 向后插入列 -->
87
- <Button @operate="insertTableColumn('right')" name="insertColumnRight" :title="$editTrans('insertColumnRight')" :tooltip="config.tooltip" :color="$parent.color">
88
- <Icon value="insert-column-right"></Icon>
89
- </Button>
90
- <!-- 删除列 -->
91
- <Button @operate="deleteTableColumn" rightBorder name="deleteColumn" :title="$editTrans('deleteColumn')" :tooltip="config.tooltip" :color="$parent.color">
92
- <Icon value="delete-column"></Icon>
93
- </Button>
94
- <!-- 删除表格 -->
95
- <Button @operate="$parent.deleteByParsedom('table')" name="deleteTable" :title="$editTrans('deleteTable')" :tooltip="config.tooltip" :color="$parent.color">
96
- <Icon value="delete-table"></Icon>
97
- </Button>
98
- </template>
99
- <!-- 代码块工具条 -->
100
- <template v-if="type == 'codeBlock'">
101
- <!-- 代码块前插入段落 -->
102
- <Button @operate="insertParagraphWithPre('up')" name="textWrapUp" :title="$editTrans('textWrapUp')" :tooltip="config.tooltip" :color="$parent.color">
103
- <Icon value="text-wrap" class="editify-icon-rotate"></Icon>
104
- </Button>
105
- <!-- 代码块后插入段落 -->
106
- <Button @operate="insertParagraphWithPre('down')" name="textWrapDown" :title="$editTrans('textWrapDown')" :tooltip="config.tooltip" :color="$parent.color">
107
- <Icon value="text-wrap"></Icon>
108
- </Button>
109
- <!-- 代码块语言选择 -->
110
- <Button v-if="languageConfig.show" name="languages" type="display" :title="$editTrans('selectLanguages')" :tooltip="config.tooltip" :leftBorder="languageConfig.leftBorder" :rightBorder="languageConfig.rightBorder" :display-config="languageConfig.displayConfig" :color="$parent.color" :active="languageConfig.active" :disabled="languageConfig.disabled" @operate="selectLanguage"></Button>
111
- </template>
112
- <!-- 文本工具条 -->
113
- <template v-else-if="type == 'text'">
114
- <!-- 设置段落和标题 -->
115
- <Button v-if="headingConfig.show" name="heading" type="display" :title="$editTrans('heading')" :tooltip="config.tooltip" :display-config="headingConfig.displayConfig" :leftBorder="headingConfig.leftBorder" :rightBorder="headingConfig.rightBorder" :color="$parent.color" :active="headingConfig.active" :disabled="headingConfig.disabled" @operate="setHeading"></Button>
116
- <!-- 对齐方式 -->
117
- <Button v-if="alignConfig.show" name="align" type="select" :title="$editTrans('align')" :tooltip="config.tooltip" :select-config="alignConfig.selectConfig" :leftBorder="alignConfig.leftBorder" :rightBorder="alignConfig.rightBorder" :color="$parent.color" :active="alignConfig.active" :disabled="alignConfig.disabled" @operate="setAlign">
118
- <Icon value="align-left"></Icon>
119
- </Button>
120
- <!-- 有序列表 -->
121
- <Button v-if="orderListConfig.show" name="orderList" :title="$editTrans('orderList')" :tooltip="config.tooltip" :leftBorder="orderListConfig.leftBorder" :rightBorder="orderListConfig.rightBorder" :color="$parent.color" :active="orderListConfig.active" :disabled="orderListConfig.disabled" @operate="setList">
122
- <Icon value="list-ordered"></Icon>
123
- </Button>
124
- <!-- 无序列表 -->
125
- <Button v-if="unorderListConfig.show" name="unorderList" :title="$editTrans('unorderList')" :tooltip="config.tooltip" :leftBorder="unorderListConfig.leftBorder" :rightBorder="unorderListConfig.rightBorder" :color="$parent.color" :active="unorderListConfig.active" :disabled="unorderListConfig.disabled" @operate="setList">
126
- <Icon value="list-unordered"></Icon>
127
- </Button>
128
- <!-- 任务列表 -->
129
- <Button v-if="taskConfig.show" name="task" :title="$editTrans('task')" :tooltip="config.tooltip" :leftBorder="taskConfig.leftBorder" :rightBorder="taskConfig.rightBorder" :color="$parent.color" :active="taskConfig.active" :disabled="taskConfig.disabled" @operate="setTask">
130
- <Icon value="task"></Icon>
131
- </Button>
132
- <!-- 加粗 -->
133
- <Button v-if="boldConfig.show" name="bold" :title="$editTrans('bold')" :tooltip="config.tooltip" :leftBorder="boldConfig.leftBorder" :rightBorder="boldConfig.rightBorder" :color="$parent.color" :active="boldConfig.active" :disabled="boldConfig.disabled" @operate="setBold">
134
- <Icon value="bold"></Icon>
135
- </Button>
136
- <!-- 斜体 -->
137
- <Button v-if="italicConfig.show" name="italic" :title="$editTrans('italic')" :tooltip="config.tooltip" :leftBorder="italicConfig.leftBorder" :rightBorder="italicConfig.rightBorder" :color="$parent.color" :active="italicConfig.active" :disabled="italicConfig.disabled" @operate="setItalic">
138
- <Icon value="italic"></Icon>
139
- </Button>
140
- <!-- 删除线 -->
141
- <Button v-if="strikethroughConfig.show" name="strikethrough" :title="$editTrans('strikethrough')" :tooltip="config.tooltip" :leftBorder="strikethroughConfig.leftBorder" :rightBorder="strikethroughConfig.rightBorder" :color="$parent.color" :active="strikethroughConfig.active" :disabled="strikethroughConfig.disabled" @operate="setStrikethrough">
142
- <Icon value="strikethrough"></Icon>
143
- </Button>
144
- <!-- 下划线 -->
145
- <Button v-if="underlineConfig.show" name="underline" :title="$editTrans('underline')" :tooltip="config.tooltip" :leftBorder="underlineConfig.leftBorder" :rightBorder="underlineConfig.rightBorder" :color="$parent.color" :active="underlineConfig.active" :disabled="underlineConfig.disabled" @operate="setUnderline">
146
- <Icon value="underline"></Icon>
147
- </Button>
148
- <!-- 行内代码块 -->
149
- <Button v-if="codeConfig.show" name="code" :title="$editTrans('code')" :tooltip="config.tooltip" :leftBorder="codeConfig.leftBorder" :rightBorder="codeConfig.rightBorder" :color="$parent.color" :active="codeConfig.active" :disabled="codeConfig.disabled" @operate="setCodeStyle">
150
- <Icon value="code"></Icon>
151
- </Button>
152
- <!-- 上标 -->
153
- <Button v-if="superConfig.show" name="superscript" :title="$editTrans('superscript')" :tooltip="config.tooltip" :leftBorder="superConfig.leftBorder" :rightBorder="superConfig.rightBorder" :color="$parent.color" :active="superConfig.active" :disabled="superConfig.disabled" @operate="setSuperscript">
154
- <Icon value="superscript"></Icon>
155
- </Button>
156
- <!-- 下标 -->
157
- <Button v-if="subConfig.show" name="subscript" :title="$editTrans('subscript')" :tooltip="config.tooltip" :leftBorder="subConfig.leftBorder" :rightBorder="subConfig.rightBorder" :color="$parent.color" :active="subConfig.active" :disabled="subConfig.disabled" @operate="setSubscript">
158
- <Icon value="subscript"></Icon>
159
- </Button>
160
- <!-- 字号大小 -->
161
- <Button v-if="fontSizeConfig.show" name="fontSize" type="display" :title="$editTrans('fontSize')" :tooltip="config.tooltip" :display-config="fontSizeConfig.displayConfig" :leftBorder="fontSizeConfig.leftBorder" :rightBorder="fontSizeConfig.rightBorder" :color="$parent.color" :active="fontSizeConfig.active" :disabled="fontSizeConfig.disabled" @operate="setFontSize"></Button>
162
- <!-- 字体 -->
163
- <Button v-if="fontFamilyConfig.show" name="fontFamily" type="display" :title="$editTrans('fontFamily')" :tooltip="config.tooltip" :display-config="fontFamilyConfig.displayConfig" :leftBorder="fontFamilyConfig.leftBorder" :rightBorder="fontFamilyConfig.rightBorder" :color="$parent.color" :active="fontFamilyConfig.active" :disabled="fontFamilyConfig.disabled" @operate="setFontFamily"></Button>
164
- <!-- 行高 -->
165
- <Button v-if="lineHeightConfig.show" name="lineHeight" type="display" :title="$editTrans('lineHeight')" :tooltip="config.tooltip" :display-config="lineHeightConfig.displayConfig" :leftBorder="lineHeightConfig.leftBorder" :rightBorder="lineHeightConfig.rightBorder" :color="$parent.color" :active="lineHeightConfig.active" :disabled="lineHeightConfig.disabled" @operate="setLineHeight"></Button>
166
- <!-- 前景色 -->
167
- <Button v-if="foreColorConfig.show" name="foreColor" type="select" :title="$editTrans('foreColor')" :tooltip="config.tooltip" :select-config="foreColorConfig.selectConfig" :leftBorder="foreColorConfig.leftBorder" :rightBorder="foreColorConfig.rightBorder" :color="$parent.color" :active="foreColorConfig.active" :disabled="foreColorConfig.disabled" hideScroll ref="foreColor">
168
- <Icon value="font-color"></Icon>
169
- <template #layer="{ options }">
170
- <Colors :tooltip="config.tooltip" :color="$parent.color" :value="foreColorConfig.value" @change="setForeColor" :data="options"></Colors>
171
- </template>
172
- </Button>
173
- <!-- 背景色 -->
174
- <Button v-if="backColorConfig.show" name="backColor" type="select" :title="$editTrans('backColor')" :tooltip="config.tooltip" :select-config="backColorConfig.selectConfig" :leftBorder="backColorConfig.leftBorder" :rightBorder="backColorConfig.rightBorder" :color="$parent.color" :active="backColorConfig.active" :disabled="backColorConfig.disabled" hideScroll ref="backColor">
175
- <Icon value="brush"></Icon>
176
- <template #layer="{ options }">
177
- <Colors :tooltip="config.tooltip" :color="$parent.color" :value="backColorConfig.value" @change="setBackColor" :data="options"></Colors>
178
- </template>
179
- </Button>
180
- <!-- 清除样式 -->
181
- <Button v-if="formatClearConfig.show" name="formatClear" :title="$editTrans('formatClear')" :tooltip="config.tooltip" :leftBorder="formatClearConfig.leftBorder" :rightBorder="formatClearConfig.rightBorder" :color="$parent.color" :active="formatClearConfig.active" :disabled="formatClearConfig.disabled" @operate="clearFormat">
182
- <Icon value="format-clear"></Icon>
183
- </Button>
184
- </template>
185
- </div>
186
- </Layer>
187
- </template>
188
- <script>
189
- import Layer from '../base/Layer'
190
- import Tooltip from '../base/Tooltip'
191
- import Button from '../base/Button'
192
- import Icon from '../base/Icon'
193
- import Checkbox from '../base/Checkbox'
194
- import Colors from './Colors'
195
- import { AlexElement } from 'alex-editor'
196
- import Dap from 'dap-util'
197
- export default {
198
- name: 'Toolbar',
199
- emits: ['update:modelValue'],
200
- props: {
201
- //是否显示
202
- modelValue: {
203
- type: Boolean,
204
- default: false
205
- },
206
- //关联元素
207
- node: {
208
- type: [String, Node],
209
- default: null
210
- },
211
- //类型
212
- type: {
213
- type: String,
214
- default: 'text',
215
- validator(value) {
216
- return ['text', 'table', 'link', 'codeBlock', 'image', 'video'].includes(value)
217
- }
218
- },
219
- //工具条配置
220
- config: {
221
- type: Object,
222
- default: null
223
- }
224
- },
225
- data() {
226
- return {
227
- //链接参数配置
228
- linkConfig: {
229
- //链接地址
230
- url: '',
231
- //链接是否新窗口打开
232
- newOpen: false
233
- },
234
- //视频参数配置
235
- videoConfig: {
236
- //是否显示控制器
237
- controls: false,
238
- //是否循环
239
- loop: false,
240
- //是否自动播放
241
- autoplay: false,
242
- //是否静音
243
- muted: false
244
- },
245
- //代码块选择语言按钮配置
246
- languageConfig: {
247
- show: this.config.codeBlock.languages.show,
248
- displayConfig: {
249
- options: this.config.codeBlock.languages.options,
250
- value: '',
251
- width: this.config.codeBlock.languages.width,
252
- maxHeight: this.config.codeBlock.languages.maxHeight
253
- },
254
- leftBorder: this.config.codeBlock.languages.leftBorder,
255
- rightBorder: this.config.codeBlock.languages.rightBorder,
256
- active: false,
257
- disabled: false
258
- },
259
- //标题按钮配置
260
- headingConfig: {
261
- show: this.config.text.heading.show,
262
- displayConfig: {
263
- options: this.config.text.heading.options,
264
- value: '',
265
- width: this.config.text.heading.width,
266
- maxHeight: this.config.text.heading.maxHeight
267
- },
268
- defaultValue: this.config.text.heading.defaultValue,
269
- leftBorder: this.config.text.heading.leftBorder,
270
- rightBorder: this.config.text.heading.rightBorder,
271
- active: false,
272
- disabled: false
273
- },
274
- //对齐方式按钮配置
275
- alignConfig: {
276
- show: this.config.text.align.show,
277
- selectConfig: {
278
- options: this.config.text.align.options,
279
- width: this.config.text.align.width,
280
- maxHeight: this.config.text.align.maxHeight
281
- },
282
- leftBorder: this.config.text.align.leftBorder,
283
- rightBorder: this.config.text.align.rightBorder,
284
- active: false,
285
- disabled: false
286
- },
287
- //有序列表按钮配置
288
- orderListConfig: {
289
- show: this.config.text.orderList.show,
290
- leftBorder: this.config.text.orderList.leftBorder,
291
- rightBorder: this.config.text.orderList.rightBorder,
292
- active: false,
293
- disabled: false
294
- },
295
- //无序列表按钮配置
296
- unorderListConfig: {
297
- show: this.config.text.unorderList.show,
298
- leftBorder: this.config.text.unorderList.leftBorder,
299
- rightBorder: this.config.text.unorderList.rightBorder,
300
- active: false,
301
- disabled: false
302
- },
303
- //任务列表按钮配置
304
- taskConfig: {
305
- show: this.config.text.task.show,
306
- leftBorder: this.config.text.task.leftBorder,
307
- rightBorder: this.config.text.task.rightBorder,
308
- active: false,
309
- disabled: false
310
- },
311
- //粗体按钮配置
312
- boldConfig: {
313
- show: this.config.text.bold.show,
314
- leftBorder: this.config.text.bold.leftBorder,
315
- rightBorder: this.config.text.bold.rightBorder,
316
- active: false,
317
- disabled: false
318
- },
319
- //斜体按钮配置
320
- italicConfig: {
321
- show: this.config.text.italic.show,
322
- leftBorder: this.config.text.italic.leftBorder,
323
- rightBorder: this.config.text.italic.rightBorder,
324
- active: false,
325
- disabled: false
326
- },
327
- //删除线按钮配置
328
- strikethroughConfig: {
329
- show: this.config.text.strikethrough.show,
330
- leftBorder: this.config.text.strikethrough.leftBorder,
331
- rightBorder: this.config.text.strikethrough.rightBorder,
332
- active: false,
333
- disabled: false
334
- },
335
- //下划线按钮配置
336
- underlineConfig: {
337
- show: this.config.text.underline.show,
338
- leftBorder: this.config.text.underline.leftBorder,
339
- rightBorder: this.config.text.underline.rightBorder,
340
- active: false,
341
- disabled: false
342
- },
343
- //行内代码块按钮配置
344
- codeConfig: {
345
- show: this.config.text.code.show,
346
- leftBorder: this.config.text.code.leftBorder,
347
- rightBorder: this.config.text.code.rightBorder,
348
- active: false,
349
- disabled: false
350
- },
351
- //上标按钮配置
352
- superConfig: {
353
- show: this.config.text.super.show,
354
- leftBorder: this.config.text.super.leftBorder,
355
- rightBorder: this.config.text.super.rightBorder,
356
- active: false,
357
- disabled: false
358
- },
359
- //下标按钮配置
360
- subConfig: {
361
- show: this.config.text.sub.show,
362
- leftBorder: this.config.text.sub.leftBorder,
363
- rightBorder: this.config.text.sub.rightBorder,
364
- active: false,
365
- disabled: false
366
- },
367
- //字号按钮配置
368
- fontSizeConfig: {
369
- show: this.config.text.fontSize.show,
370
- displayConfig: {
371
- options: this.config.text.fontSize.options,
372
- value: '',
373
- width: this.config.text.fontSize.width,
374
- maxHeight: this.config.text.fontSize.maxHeight
375
- },
376
- defaultValue: this.config.text.fontSize.defaultValue,
377
- leftBorder: this.config.text.fontSize.leftBorder,
378
- rightBorder: this.config.text.fontSize.rightBorder,
379
- active: false,
380
- disabled: false
381
- },
382
- //字体按钮配置
383
- fontFamilyConfig: {
384
- show: this.config.text.fontFamily.show,
385
- displayConfig: {
386
- options: this.config.text.fontFamily.options,
387
- value: '',
388
- width: this.config.text.fontFamily.width,
389
- maxHeight: this.config.text.fontFamily.maxHeight
390
- },
391
- defaultValue: this.config.text.fontFamily.defaultValue,
392
- leftBorder: this.config.text.fontFamily.leftBorder,
393
- rightBorder: this.config.text.fontFamily.rightBorder,
394
- active: false,
395
- disabled: false
396
- },
397
- //行高按钮配置
398
- lineHeightConfig: {
399
- show: this.config.text.lineHeight.show,
400
- displayConfig: {
401
- options: this.config.text.lineHeight.options,
402
- value: '',
403
- width: this.config.text.lineHeight.width,
404
- maxHeight: this.config.text.lineHeight.maxHeight
405
- },
406
- defaultValue: this.config.text.lineHeight.defaultValue,
407
- leftBorder: this.config.text.lineHeight.leftBorder,
408
- rightBorder: this.config.text.lineHeight.rightBorder,
409
- active: false,
410
- disabled: false
411
- },
412
- //前景颜色按钮配置
413
- foreColorConfig: {
414
- show: this.config.text.foreColor.show,
415
- selectConfig: {
416
- options: this.config.text.foreColor.options
417
- },
418
- leftBorder: this.config.text.foreColor.leftBorder,
419
- rightBorder: this.config.text.foreColor.rightBorder,
420
- value: '', //选择的颜色值
421
- active: false,
422
- disabled: false
423
- },
424
- //背景颜色按钮配置
425
- backColorConfig: {
426
- show: this.config.text.backColor.show,
427
- selectConfig: {
428
- options: this.config.text.backColor.options
429
- },
430
- leftBorder: this.config.text.backColor.leftBorder,
431
- rightBorder: this.config.text.backColor.rightBorder,
432
- value: '', //选择的颜色值
433
- active: false,
434
- disabled: false
435
- },
436
- //清除格式按钮配置
437
- formatClearConfig: {
438
- show: this.config.text.formatClear.show,
439
- leftBorder: this.config.text.formatClear.leftBorder,
440
- rightBorder: this.config.text.formatClear.rightBorder,
441
- active: false,
442
- disabled: false
443
- }
444
- }
445
- },
446
- computed: {
447
- //是否显示
448
- show: {
449
- get() {
450
- return this.modelValue
451
- },
452
- set(val) {
453
- this.$emit('update:modelValue', val)
454
- }
455
- }
456
- },
457
- components: {
458
- Layer,
459
- Tooltip,
460
- Button,
461
- Icon,
462
- Checkbox,
463
- Colors
464
- },
465
- inject: ['$editTrans'],
466
- methods: {
467
- //清除格式
468
- clearFormat() {
469
- this.$parent.formatText()
470
- },
471
- //设置背景色
472
- setBackColor(value) {
473
- this.$parent.setTextStyle('background-color', value)
474
- this.$refs.backColor.hideLayer()
475
- },
476
- //设置前景色
477
- setForeColor(value) {
478
- this.$parent.setTextStyle('color', value)
479
- this.$refs.foreColor.hideLayer()
480
- },
481
- //设置行高
482
- setLineHeight(name, value) {
483
- this.$parent.setLineHeight(value)
484
- },
485
- //设置字体
486
- setFontFamily(name, value) {
487
- this.$parent.setTextStyle('font-family', value)
488
- },
489
- //设置字号
490
- setFontSize(name, value) {
491
- this.$parent.setTextStyle('font-size', value)
492
- },
493
- //设置上标
494
- setSuperscript() {
495
- this.$parent.setTextStyle('vertical-align', 'super')
496
- },
497
- //设置下标
498
- setSubscript() {
499
- this.$parent.setTextStyle('vertical-align', 'sub')
500
- },
501
- //设置行内代码样式
502
- setCodeStyle() {
503
- this.$parent.setTextMark('data-editify-code', true)
504
- },
505
- //设置下划线
506
- setUnderline() {
507
- this.$parent.setTextStyle('text-decoration', 'underline')
508
- },
509
- //设置删除线
510
- setStrikethrough() {
511
- this.$parent.setTextStyle('text-decoration', 'line-through')
512
- },
513
- //设置列表
514
- setList(name) {
515
- this.$parent.setList(name == 'orderList')
516
- },
517
- //设置任务列表
518
- setTask() {
519
- this.$parent.setTask()
520
- },
521
- //斜体
522
- setItalic() {
523
- this.$parent.setTextStyle('font-style', 'italic')
524
- },
525
- //加粗
526
- setBold() {
527
- this.$parent.setTextStyle('font-weight', 'bold')
528
- },
529
- //设置标题
530
- setHeading(name, value) {
531
- this.$parent.setHeading(value)
532
- },
533
- //设置对齐方式
534
- setAlign(name, value) {
535
- this.$parent.setAlign(value)
536
- },
537
- //设置视频
538
- setVideo(prop) {
539
- if (this.$parent.disabled) {
540
- return
541
- }
542
- const video = this.$parent.getCurrentParsedomElement('video')
543
- if (video) {
544
- //当前是拥有该属性
545
- if (this.videoConfig[prop]) {
546
- delete video.marks[prop]
547
- }
548
- //当前无该属性
549
- else {
550
- video.marks[prop] = true
551
- }
552
- this.videoConfig[prop] = !this.videoConfig[prop]
553
- this.$parent.editor.domRender()
554
- this.$parent.editor.rangeRender()
555
- }
556
- },
557
- //设置宽度
558
- setWidth(value) {
559
- if (this.$parent.disabled) {
560
- return
561
- }
562
- const element = this.$parent.getCurrentParsedomElement('img') || this.$parent.getCurrentParsedomElement('video')
563
- if (element) {
564
- const styles = {
565
- width: value
566
- }
567
- if (element.hasStyles()) {
568
- element.styles = Object.assign(element.styles, styles)
569
- } else {
570
- element.styles = styles
571
- }
572
- this.$parent.editor.formatElementStack()
573
- this.$parent.editor.domRender()
574
- this.$parent.editor.rangeRender()
575
- //更新工具条位置
576
- setTimeout(() => {
577
- this.$refs.layer.setPosition()
578
- }, 0)
579
- }
580
- },
581
- //修改链接
582
- modifyLink() {
583
- if (this.$parent.disabled) {
584
- return
585
- }
586
- if (!this.linkConfig.url) {
587
- return
588
- }
589
- const link = this.$parent.getCurrentParsedomElement('a')
590
- if (link) {
591
- link.marks.href = this.linkConfig.url
592
- if (this.linkConfig.newOpen) {
593
- link.marks.target = '_blank'
594
- } else {
595
- delete link.marks.target
596
- }
597
- }
598
- this.$parent.editor.formatElementStack()
599
- this.$parent.editor.domRender()
600
- },
601
- //输入框获取焦点
602
- handleInputFocus(e) {
603
- if (this.$parent.disabled) {
604
- return
605
- }
606
- if (this.$parent.color) {
607
- e.currentTarget.style.borderColor = this.$parent.color
608
- }
609
- },
610
- //输入框失去焦点
611
- handleInputBlur(e) {
612
- if (this.$parent.disabled) {
613
- return
614
- }
615
- e.currentTarget.style.borderColor = ''
616
- },
617
- //选择代码语言
618
- selectLanguage(name, value) {
619
- if (this.$parent.disabled) {
620
- return
621
- }
622
- const pre = this.$parent.getCurrentParsedomElement('pre')
623
- if (pre) {
624
- Object.assign(pre.marks, {
625
- 'data-editify-hljs': value
626
- })
627
- this.$parent.editor.formatElementStack()
628
- this.$parent.editor.domRender()
629
- this.$parent.editor.rangeRender()
630
- }
631
- },
632
- //代码块前后插入段落
633
- insertParagraphWithPre(type = 'up') {
634
- if (this.$parent.disabled) {
635
- return
636
- }
637
- if (!this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
638
- this.$parent.editor.range.anchor.element = this.$parent.editor.range.focus.element
639
- this.$parent.editor.range.anchor.offset = this.$parent.editor.range.focus.offset
640
- }
641
- const pre = this.$parent.getCurrentParsedomElement('pre')
642
- if (pre) {
643
- const paragraph = new AlexElement('block', AlexElement.BLOCK_NODE, null, null, null)
644
- const breakEl = new AlexElement('closed', 'br', null, null, null)
645
- this.$parent.editor.addElementTo(breakEl, paragraph)
646
- if (type == 'up') {
647
- this.$parent.editor.addElementBefore(paragraph, pre)
648
- } else {
649
- this.$parent.editor.addElementAfter(paragraph, pre)
650
- }
651
- this.$parent.editor.range.anchor.moveToEnd(paragraph)
652
- this.$parent.editor.range.focus.moveToEnd(paragraph)
653
- this.$parent.editor.formatElementStack()
654
- this.$parent.editor.domRender()
655
- this.$parent.editor.rangeRender()
656
- }
657
- },
658
- //表格前后插入列
659
- insertTableColumn(type = 'left') {
660
- if (this.$parent.disabled) {
661
- return
662
- }
663
- if (!this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
664
- this.$parent.editor.range.anchor.element = this.$parent.editor.range.focus.element
665
- this.$parent.editor.range.anchor.offset = this.$parent.editor.range.focus.offset
666
- }
667
- const table = this.$parent.getCurrentParsedomElement('table')
668
- const column = this.$parent.getCurrentParsedomElement('td')
669
- const tbody = this.$parent.getCurrentParsedomElement('tbody')
670
- if (column && table && tbody) {
671
- const rows = tbody.children
672
- const index = column.parent.children.findIndex(item => {
673
- return item.isEqual(column)
674
- })
675
- //插入列
676
- rows.forEach(row => {
677
- const newColumn = column.clone(false)
678
- const breakEl = new AlexElement('closed', 'br', null, null, null)
679
- this.$parent.editor.addElementTo(breakEl, newColumn)
680
- if (type == 'left') {
681
- this.$parent.editor.addElementTo(newColumn, row, index)
682
- } else {
683
- this.$parent.editor.addElementTo(newColumn, row, index + 1)
684
- }
685
- })
686
- //插入col
687
- const colgroup = table.children.find(item => {
688
- return item.parsedom == 'colgroup'
689
- })
690
- const col = new AlexElement('closed', 'col', null, null, null)
691
- if (type == 'left') {
692
- this.$parent.editor.addElementTo(col, colgroup, index)
693
- } else {
694
- this.$parent.editor.addElementTo(col, colgroup, index + 1)
695
- }
696
- //渲染
697
- this.$parent.editor.formatElementStack()
698
- if (type == 'left') {
699
- const previousColumn = this.$parent.editor.getPreviousElement(column)
700
- this.$parent.editor.range.anchor.moveToStart(previousColumn)
701
- this.$parent.editor.range.focus.moveToStart(previousColumn)
702
- } else {
703
- const nextColumn = this.$parent.editor.getNextElement(column)
704
- this.$parent.editor.range.anchor.moveToStart(nextColumn)
705
- this.$parent.editor.range.focus.moveToStart(nextColumn)
706
- }
707
- this.$parent.editor.domRender()
708
- this.$parent.editor.rangeRender()
709
- }
710
- },
711
- //表格插入前后插入行
712
- insertTableRow(type = 'up') {
713
- if (this.$parent.disabled) {
714
- return
715
- }
716
- if (!this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
717
- this.$parent.editor.range.anchor.element = this.$parent.editor.range.focus.element
718
- this.$parent.editor.range.anchor.offset = this.$parent.editor.range.focus.offset
719
- }
720
- const table = this.$parent.getCurrentParsedomElement('table')
721
- const row = this.$parent.getCurrentParsedomElement('tr')
722
- if (table && row) {
723
- const newRow = row.clone()
724
- newRow.children.forEach(column => {
725
- column.children = []
726
- const breakEl = new AlexElement('closed', 'br', null, null, null)
727
- this.$parent.editor.addElementTo(breakEl, column)
728
- })
729
- if (type == 'up') {
730
- this.$parent.editor.addElementBefore(newRow, row)
731
- } else {
732
- this.$parent.editor.addElementAfter(newRow, row)
733
- }
734
- this.$parent.editor.formatElementStack()
735
- this.$parent.editor.range.anchor.moveToStart(newRow)
736
- this.$parent.editor.range.focus.moveToStart(newRow)
737
- this.$parent.editor.domRender()
738
- this.$parent.editor.rangeRender()
739
- //更新工具条位置
740
- setTimeout(() => {
741
- this.$refs.layer.setPosition()
742
- }, 0)
743
- }
744
- },
745
- //表格前后插入段落
746
- insertParagraphWithTable(type = 'up') {
747
- if (this.$parent.disabled) {
748
- return
749
- }
750
- const table = this.$parent.getCurrentParsedomElement('table')
751
- if (table) {
752
- const paragraph = new AlexElement('block', AlexElement.BLOCK_NODE, null, null, null)
753
- const breakEl = new AlexElement('closed', 'br', null, null, null)
754
- this.$parent.editor.addElementTo(breakEl, paragraph)
755
- if (type == 'up') {
756
- this.$parent.editor.addElementBefore(paragraph, table)
757
- } else {
758
- this.$parent.editor.addElementAfter(paragraph, table)
759
- }
760
- this.$parent.editor.range.anchor.moveToEnd(paragraph)
761
- this.$parent.editor.range.focus.moveToEnd(paragraph)
762
- this.$parent.editor.formatElementStack()
763
- this.$parent.editor.domRender()
764
- this.$parent.editor.rangeRender()
765
- }
766
- },
767
- //删除表格行
768
- deleteTableRow() {
769
- if (this.$parent.disabled) {
770
- return
771
- }
772
- if (!this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
773
- this.$parent.editor.range.anchor.element = this.$parent.editor.range.focus.element
774
- this.$parent.editor.range.anchor.offset = this.$parent.editor.range.focus.offset
775
- }
776
- const table = this.$parent.getCurrentParsedomElement('table')
777
- const row = this.$parent.getCurrentParsedomElement('tr')
778
- if (table && row) {
779
- const parent = row.parent
780
- if (parent.children.length == 1) {
781
- this.$parent.deleteByParsedom('table')
782
- return
783
- }
784
- const previousRow = this.$parent.editor.getPreviousElement(row)
785
- const nextRow = this.$parent.editor.getNextElement(row)
786
- row.toEmpty()
787
- this.$parent.editor.formatElementStack()
788
- if (previousRow) {
789
- this.$parent.editor.range.anchor.moveToEnd(previousRow.children[0])
790
- this.$parent.editor.range.focus.moveToEnd(previousRow.children[0])
791
- } else {
792
- this.$parent.editor.range.anchor.moveToEnd(nextRow.children[0])
793
- this.$parent.editor.range.focus.moveToEnd(nextRow.children[0])
794
- }
795
- this.$parent.editor.domRender()
796
- this.$parent.editor.rangeRender()
797
- //更新工具条位置
798
- setTimeout(() => {
799
- this.$refs.layer.setPosition()
800
- }, 0)
801
- }
802
- },
803
- //删除表格列
804
- deleteTableColumn() {
805
- if (this.$parent.disabled) {
806
- return
807
- }
808
- if (!this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
809
- this.$parent.editor.range.anchor.element = this.$parent.editor.range.focus.element
810
- this.$parent.editor.range.anchor.offset = this.$parent.editor.range.focus.offset
811
- }
812
- const column = this.$parent.getCurrentParsedomElement('td')
813
- const tbody = this.$parent.getCurrentParsedomElement('tbody')
814
- const table = this.$parent.getCurrentParsedomElement('table')
815
- if (column && table && tbody) {
816
- const rows = tbody.children
817
- const parent = column.parent
818
- if (parent.children.length == 1) {
819
- this.$parent.deleteByParsedom('table')
820
- return
821
- }
822
- const previousColumn = this.$parent.editor.getPreviousElement(column)
823
- const nextColumn = this.$parent.editor.getNextElement(column)
824
- const index = column.parent.children.findIndex(item => {
825
- return item.isEqual(column)
826
- })
827
- //删除列
828
- rows.forEach(row => {
829
- row.children[index].toEmpty()
830
- })
831
- //删除col
832
- const colgroup = table.children.find(item => {
833
- return item.parsedom == 'colgroup'
834
- })
835
- colgroup.children[index].toEmpty()
836
- //渲染
837
- this.$parent.editor.formatElementStack()
838
- if (previousColumn) {
839
- this.$parent.editor.range.anchor.moveToEnd(previousColumn)
840
- this.$parent.editor.range.focus.moveToEnd(previousColumn)
841
- } else {
842
- this.$parent.editor.range.anchor.moveToEnd(nextColumn)
843
- this.$parent.editor.range.focus.moveToEnd(nextColumn)
844
- }
845
- this.$parent.editor.domRender()
846
- this.$parent.editor.rangeRender()
847
- }
848
- },
849
- //浮层显示时
850
- layerShow() {
851
- //代码块初始化展示设置
852
- if (this.type == 'codeBlock') {
853
- const pre = this.$parent.getCurrentParsedomElement('pre')
854
- if (pre) {
855
- this.languageConfig.displayConfig.value = pre.marks['data-editify-hljs'] || ''
856
- }
857
- }
858
- //链接初始化展示
859
- else if (this.type == 'link') {
860
- const link = this.$parent.getCurrentParsedomElement('a')
861
- if (link) {
862
- this.linkConfig.url = link.marks['href']
863
- this.linkConfig.newOpen = link.marks['target'] == '_blank'
864
- }
865
- }
866
- //视频初始化显示
867
- else if (this.type == 'video') {
868
- const video = this.$parent.getCurrentParsedomElement('video')
869
- if (video) {
870
- this.videoConfig.autoplay = !!video.marks['autoplay']
871
- this.videoConfig.loop = !!video.marks['loop']
872
- this.videoConfig.controls = !!video.marks['controls']
873
- this.videoConfig.muted = !!video.marks['muted']
874
- }
875
- }
876
- //文本工具条初始化显示
877
- else if (this.type == 'text') {
878
- //额外禁用判定
879
- const extraDisabled = name => {
880
- if (typeof this.config.extraDisabled == 'function') {
881
- return this.config.extraDisabled.apply(this.$parent, [name]) || false
882
- }
883
- return false
884
- }
885
-
886
- //获取选区的元素
887
- const result = this.$parent.editor.getElementsByRange(true, false)
888
-
889
- //显示已设置标题
890
- const findHeadingItem = this.headingConfig.displayConfig.options.find(item => {
891
- let val = item
892
- if (Dap.common.isObject(item)) {
893
- val = item.value
894
- }
895
- return result.every(el => {
896
- if (el.element.isBlock()) {
897
- return el.element.parsedom == val
898
- }
899
- return el.element.getBlock().parsedom == val
900
- })
901
- })
902
- this.headingConfig.displayConfig.value = findHeadingItem ? (Dap.common.isObject(findHeadingItem) ? findHeadingItem.value : findHeadingItem) : this.headingConfig.defaultValue
903
- //标题禁用
904
- this.headingConfig.disabled = extraDisabled('heading')
905
-
906
- //对齐方式禁用
907
- this.alignConfig.disabled = extraDisabled('align')
908
-
909
- //有序列表按钮激活
910
- this.orderListConfig.active = this.$parent.inList(true)
911
- //有序列表按钮禁用
912
- this.orderListConfig.disabled = extraDisabled('orderList')
913
-
914
- //无序列表按钮激活
915
- this.unorderListConfig.active = this.$parent.inList(false)
916
- //无序列表按钮禁用
917
- this.unorderListConfig.disabled = extraDisabled('unorderList')
918
-
919
- //任务列表按钮激活
920
- this.taskConfig.active = this.$parent.inTask()
921
- //任务列表按钮禁用
922
- this.taskConfig.disabled = extraDisabled('task')
923
-
924
- //粗体按钮激活
925
- this.boldConfig.active = this.$parent.queryTextStyle('font-weight', 'bold')
926
- //粗体按钮禁用
927
- this.boldConfig.disabled = extraDisabled('bold')
928
-
929
- //斜体按钮激活
930
- this.italicConfig.active = this.$parent.queryTextStyle('font-style', 'italic', true)
931
- //斜体按钮禁用
932
- this.italicConfig.disabled = extraDisabled('italic')
933
-
934
- //删除线按钮激活
935
- this.strikethroughConfig.active = this.$parent.queryTextStyle('text-decoration', 'line-through', true)
936
- //删除线按钮禁用
937
- this.strikethroughConfig.disabled = extraDisabled('strikethrough')
938
-
939
- //下划线按钮激活
940
- this.underlineConfig.active = this.$parent.queryTextStyle('text-decoration', 'underline', true)
941
- //下划线按钮禁用
942
- this.underlineConfig.disabled = extraDisabled('underline')
943
-
944
- //行内代码按钮激活
945
- this.codeConfig.active = this.$parent.queryTextMark('data-editify-code')
946
- //行内代码按钮禁用
947
- this.codeConfig.disabled = extraDisabled('code')
948
-
949
- //上标按钮激活
950
- this.superConfig.active = this.$parent.queryTextStyle('vertical-align', 'super', true)
951
- //上标按钮禁用
952
- this.superConfig.disabled = extraDisabled('super')
953
-
954
- //下标按钮激活
955
- this.subConfig.active = this.$parent.queryTextStyle('vertical-align', 'sub', true)
956
- //下标按钮禁用
957
- this.subConfig.disabled = extraDisabled('sub')
958
-
959
- //显示已选择字号
960
- const findFontItem = this.fontSizeConfig.displayConfig.options.find(item => {
961
- if (Dap.common.isObject(item)) {
962
- return this.$parent.queryTextStyle('font-size', item.value, true)
963
- }
964
- return this.$parent.queryTextStyle('font-size', item, true)
965
- })
966
- this.fontSizeConfig.displayConfig.value = findFontItem ? (Dap.common.isObject(findFontItem) ? findFontItem.value : findFontItem) : this.fontSizeConfig.defaultValue
967
- //字号按钮禁用
968
- this.fontSizeConfig.disabled = extraDisabled('fontSize')
969
-
970
- //显示已选择字体
971
- const findFamilyItem = this.fontFamilyConfig.displayConfig.options.find(item => {
972
- if (Dap.common.isObject(item)) {
973
- return this.$parent.queryTextStyle('font-family', item.value, true)
974
- }
975
- return this.$parent.queryTextStyle('font-family', item, true)
976
- })
977
- this.fontFamilyConfig.displayConfig.value = findFamilyItem ? (Dap.common.isObject(findFamilyItem) ? findFamilyItem.value : findFamilyItem) : this.fontFamilyConfig.defaultValue
978
- //字体按钮禁用
979
- this.fontFamilyConfig.disabled = extraDisabled('fontFamily')
980
-
981
- //显示已设置行高
982
- const findHeightItem = this.lineHeightConfig.displayConfig.options.find(item => {
983
- let val = item
984
- if (Dap.common.isObject(item)) {
985
- val = item.value
986
- }
987
- return result.every(el => {
988
- if (el.element.isBlock() || el.element.isInblock()) {
989
- return el.element.hasStyles() && el.element.styles['line-height'] == val
990
- }
991
- const block = el.element.getBlock()
992
- const inblock = el.element.getInblock()
993
- if (inblock) {
994
- return inblock.hasStyles() && inblock.styles['line-height'] == val
995
- }
996
- return block.hasStyles() && block.styles['line-height'] == val
997
- })
998
- })
999
- this.lineHeightConfig.displayConfig.value = findHeightItem ? (Dap.common.isObject(findHeightItem) ? findHeightItem.value : findHeightItem) : this.lineHeightConfig.defaultValue
1000
- //行高按钮禁用
1001
- this.lineHeightConfig.disabled = extraDisabled('lineHeight')
1002
-
1003
- //显示已选择的前景色
1004
- const findForeColorItem = this.foreColorConfig.selectConfig.options.find(item => {
1005
- if (Dap.common.isObject(item)) {
1006
- return this.$parent.queryTextStyle('color', item.value, true)
1007
- }
1008
- return this.$parent.queryTextStyle('color', item, true)
1009
- })
1010
- this.foreColorConfig.value = findForeColorItem ? (Dap.common.isObject(findForeColorItem) ? findForeColorItem.value : findForeColorItem) : ''
1011
- //前景色按钮禁用
1012
- this.foreColorConfig.disabled = extraDisabled('foreColor')
1013
-
1014
- //显示已选择的背景色
1015
- const findBackColorItem = this.backColorConfig.selectConfig.options.find(item => {
1016
- if (Dap.common.isObject(item)) {
1017
- return this.$parent.queryTextStyle('background-color', item.value, true)
1018
- }
1019
- return this.$parent.queryTextStyle('background-color', item, true)
1020
- })
1021
- this.backColorConfig.value = findBackColorItem ? (Dap.common.isObject(findBackColorItem) ? findBackColorItem.value : findBackColorItem) : ''
1022
- //背景色按钮禁用
1023
- this.backColorConfig.disabled = extraDisabled('backColor')
1024
-
1025
- //清除格式按钮禁用
1026
- this.formatClearConfig.disabled = extraDisabled('formatClear')
1027
- }
1028
- }
1029
- }
1030
- }
1031
- </script>
1032
- <style lang="less" scoped>
1033
- .editify-toolbar {
1034
- display: flex;
1035
- justify-content: flex-start;
1036
- align-items: center;
1037
- padding: 6px 10px;
1038
-
1039
- .editify-icon-rotate {
1040
- transform: rotate(180deg);
1041
- }
1042
- }
1043
-
1044
- .editify-toolbar-link {
1045
- display: block;
1046
- width: 280px;
1047
- padding: 4px;
1048
-
1049
- .editify-toolbar-link-label {
1050
- display: block;
1051
- text-align: left;
1052
- margin-bottom: 10px;
1053
- font-size: @font-size;
1054
- color: @font-color;
1055
- }
1056
-
1057
- input {
1058
- appearance: none;
1059
- -webkit-appearance: none;
1060
- -moz-appearance: none;
1061
- display: block;
1062
- width: 100%;
1063
- margin: 0 0 10px 0;
1064
- padding: 4px 2px;
1065
- border: none;
1066
- font-size: @font-size;
1067
- color: @font-color;
1068
- border-bottom: 1px solid @border-color;
1069
- line-height: 1.5;
1070
- transition: all 500ms;
1071
- background-color: transparent;
1072
- outline: none;
1073
-
1074
- &::-webkit-input-placeholder,
1075
- &::placeholder {
1076
- color: @font-color-disabled;
1077
- font-family: inherit;
1078
- font-size: inherit;
1079
- vertical-align: middle;
1080
- }
1081
-
1082
- &[disabled] {
1083
- background-color: transparent;
1084
- opacity: 0.6;
1085
- }
1086
- }
1087
-
1088
- .editify-toolbar-link-footer {
1089
- display: flex;
1090
- justify-content: space-between;
1091
- align-items: center;
1092
- width: 100%;
1093
- font-size: @font-size;
1094
- color: @font-color-light;
1095
-
1096
- .editify-toolbar-link-operations {
1097
- display: flex;
1098
- justify-content: flex-start;
1099
- align-items: center;
1100
-
1101
- & > span,
1102
- & > a {
1103
- cursor: pointer;
1104
- opacity: 0.8;
1105
- transition: all 200ms;
1106
-
1107
- &:hover {
1108
- opacity: 1;
1109
- }
1110
- }
1111
-
1112
- & > span {
1113
- margin-right: 15px;
1114
- }
1115
-
1116
- & > a {
1117
- text-decoration: none;
1118
- }
1119
- }
1120
- }
1121
- }
1122
- </style>
1
+ <template>
2
+ <Layer v-model="show" ref="layer" :node="node" border placement="bottom-start" @show="layerShow" :useRange="type == 'text'">
3
+ <div class="editify-toolbar" ref="toolbar" :style="config.style">
4
+ <!-- 链接工具条 -->
5
+ <template v-if="type == 'link'">
6
+ <div class="editify-toolbar-link">
7
+ <div class="editify-toolbar-link-label">{{ $editTrans('linkAddress') }}</div>
8
+ <input @input="modifyLink" @focus="handleInputFocus" @blur="handleInputBlur" :placeholder="$editTrans('linkUrlEnterPlaceholder')" v-model.trim="linkConfig.url" type="url" />
9
+ <div class="editify-toolbar-link-footer">
10
+ <Checkbox @change="modifyLink" v-model="linkConfig.newOpen" :label="$editTrans('newWindowOpen')" :color="$parent.color" :size="10"></Checkbox>
11
+ <div class="editify-toolbar-link-operations">
12
+ <span @click="$parent.removeLink">{{ $editTrans('removeLink') }}</span>
13
+ <a :href="linkConfig.url" target="_blank" :style="{ color: $parent.color }">{{ $editTrans('viewLink') }}</a>
14
+ </div>
15
+ </div>
16
+ </div>
17
+ </template>
18
+ <!-- 图片工具条 -->
19
+ <template v-else-if="type == 'image'">
20
+ <!-- 设置宽度30% -->
21
+ <Button @operate="setWidth('30%')" name="set30Width" :title="$editTrans('width30')" :tooltip="config.tooltip" :color="$parent.color"> 30% </Button>
22
+ <!-- 设置宽度50% -->
23
+ <Button @operate="setWidth('50%')" name="set50Width" :title="$editTrans('width50')" :tooltip="config.tooltip" :color="$parent.color"> 50% </Button>
24
+ <!-- 设置宽度100% -->
25
+ <Button rightBorder @operate="setWidth('100%')" name="set100Width" :title="$editTrans('width100')" :tooltip="config.tooltip" :color="$parent.color"> 100% </Button>
26
+ <!-- 删除图片 -->
27
+ <Button @operate="$parent.deleteByParsedom('img')" name="deleteImage" :title="$editTrans('deleteImage')" :tooltip="config.tooltip" :color="$parent.color">
28
+ <Icon value="delete"></Icon>
29
+ </Button>
30
+ </template>
31
+ <!-- 视频工具条 -->
32
+ <template v-else-if="type == 'video'">
33
+ <!-- 设置宽度30% -->
34
+ <Button @operate="setWidth('30%')" name="set30Width" :title="$editTrans('width30')" :tooltip="config.tooltip" :color="$parent.color"> 30% </Button>
35
+ <!-- 设置宽度50% -->
36
+ <Button @operate="setWidth('50%')" name="set50Width" :title="$editTrans('width50')" :tooltip="config.tooltip" :color="$parent.color"> 50% </Button>
37
+ <!-- 设置宽度100% -->
38
+ <Button rightBorder @operate="setWidth('100%')" name="set100Width" :title="$editTrans('width100')" :tooltip="config.tooltip" :color="$parent.color"> 100% </Button>
39
+ <!-- 自动播放 -->
40
+ <Button @operate="setVideo" name="autoplay" :title="videoConfig.autoplay ? $editTrans('disabledAutoplay') : $editTrans('autoplay')" :tooltip="config.tooltip" :color="$parent.color">
41
+ <Icon :value="videoConfig.autoplay ? 'autoplay' : 'stop'"></Icon>
42
+ </Button>
43
+ <!-- 循环播放 -->
44
+ <Button @operate="setVideo" name="loop" :title="videoConfig.loop ? $editTrans('disabledLoop') : $editTrans('loop')" :tooltip="config.tooltip" :color="$parent.color">
45
+ <Icon :value="videoConfig.loop ? 'loop' : 'single'"></Icon>
46
+ </Button>
47
+ <!-- 是否静音 -->
48
+ <Button @operate="setVideo" name="muted" :title="videoConfig.muted ? $editTrans('unmuted') : $editTrans('muted')" :tooltip="config.tooltip" :color="$parent.color">
49
+ <Icon :value="videoConfig.muted ? 'muted' : 'unmuted'"></Icon>
50
+ </Button>
51
+ <!-- 是否显示控制器 -->
52
+ <Button leftBorder @operate="setVideo" name="controls" :title="$editTrans('controls')" :tooltip="config.tooltip" :color="$parent.color">
53
+ <Icon value="controls"></Icon>
54
+ </Button>
55
+ <!-- 删除视频 -->
56
+ <Button @operate="$parent.deleteByParsedom('video')" name="deleteVideo" :title="$editTrans('deleteVideo')" :tooltip="config.tooltip" :color="$parent.color">
57
+ <Icon value="delete"></Icon>
58
+ </Button>
59
+ </template>
60
+ <!-- 表格工具条 -->
61
+ <template v-else-if="type == 'table'">
62
+ <!-- 表格前插入段落 -->
63
+ <Button @operate="insertParagraphWithTable('up')" name="textWrapUp" :title="$editTrans('textWrapUp')" :tooltip="config.tooltip" :color="$parent.color">
64
+ <Icon value="text-wrap" class="editify-icon-rotate"></Icon>
65
+ </Button>
66
+ <!-- 表格后插入段落 -->
67
+ <Button @operate="insertParagraphWithTable('down')" rightBorder name="textWrapDown" :title="$editTrans('textWrapDown')" :tooltip="config.tooltip" :color="$parent.color">
68
+ <Icon value="text-wrap"></Icon>
69
+ </Button>
70
+ <!-- 向前插入行 -->
71
+ <Button @operate="insertTableRow('up')" name="insertRowTop" :title="$editTrans('insertRowTop')" :tooltip="config.tooltip" :color="$parent.color">
72
+ <Icon value="insert-row-top"></Icon>
73
+ </Button>
74
+ <!-- 向后插入行 -->
75
+ <Button @operate="insertTableRow('down')" name="insertRowBottom" :title="$editTrans('insertRowBottom')" :tooltip="config.tooltip" :color="$parent.color">
76
+ <Icon value="insert-row-bottom"></Icon>
77
+ </Button>
78
+ <!-- 删除行 -->
79
+ <Button @operate="deleteTableRow" rightBorder name="deleteRow" :title="$editTrans('deleteRow')" :tooltip="config.tooltip" :color="$parent.color">
80
+ <Icon value="delete-row"></Icon>
81
+ </Button>
82
+ <!-- 向前插入列 -->
83
+ <Button @operate="insertTableColumn('left')" name="insertColumnLeft" :title="$editTrans('insertColumnLeft')" :tooltip="config.tooltip" :color="$parent.color">
84
+ <Icon value="insert-column-left"></Icon>
85
+ </Button>
86
+ <!-- 向后插入列 -->
87
+ <Button @operate="insertTableColumn('right')" name="insertColumnRight" :title="$editTrans('insertColumnRight')" :tooltip="config.tooltip" :color="$parent.color">
88
+ <Icon value="insert-column-right"></Icon>
89
+ </Button>
90
+ <!-- 删除列 -->
91
+ <Button @operate="deleteTableColumn" rightBorder name="deleteColumn" :title="$editTrans('deleteColumn')" :tooltip="config.tooltip" :color="$parent.color">
92
+ <Icon value="delete-column"></Icon>
93
+ </Button>
94
+ <!-- 删除表格 -->
95
+ <Button @operate="$parent.deleteByParsedom('table')" name="deleteTable" :title="$editTrans('deleteTable')" :tooltip="config.tooltip" :color="$parent.color">
96
+ <Icon value="delete-table"></Icon>
97
+ </Button>
98
+ </template>
99
+ <!-- 代码块工具条 -->
100
+ <template v-if="type == 'codeBlock'">
101
+ <!-- 代码块前插入段落 -->
102
+ <Button @operate="insertParagraphWithPre('up')" name="textWrapUp" :title="$editTrans('textWrapUp')" :tooltip="config.tooltip" :color="$parent.color">
103
+ <Icon value="text-wrap" class="editify-icon-rotate"></Icon>
104
+ </Button>
105
+ <!-- 代码块后插入段落 -->
106
+ <Button @operate="insertParagraphWithPre('down')" name="textWrapDown" :title="$editTrans('textWrapDown')" :tooltip="config.tooltip" :color="$parent.color">
107
+ <Icon value="text-wrap"></Icon>
108
+ </Button>
109
+ <!-- 代码块语言选择 -->
110
+ <Button v-if="languageConfig.show" name="languages" type="display" :title="$editTrans('selectLanguages')" :tooltip="config.tooltip" :leftBorder="languageConfig.leftBorder" :rightBorder="languageConfig.rightBorder" :display-config="languageConfig.displayConfig" :color="$parent.color" :active="languageConfig.active" :disabled="languageConfig.disabled" @operate="selectLanguage"></Button>
111
+ </template>
112
+ <!-- 文本工具条 -->
113
+ <template v-else-if="type == 'text'">
114
+ <!-- 设置段落和标题 -->
115
+ <Button v-if="headingConfig.show" name="heading" type="display" :title="$editTrans('heading')" :tooltip="config.tooltip" :display-config="headingConfig.displayConfig" :leftBorder="headingConfig.leftBorder" :rightBorder="headingConfig.rightBorder" :color="$parent.color" :active="headingConfig.active" :disabled="headingConfig.disabled" @operate="setHeading"></Button>
116
+ <!-- 对齐方式 -->
117
+ <Button v-if="alignConfig.show" name="align" type="select" :title="$editTrans('align')" :tooltip="config.tooltip" :select-config="alignConfig.selectConfig" :leftBorder="alignConfig.leftBorder" :rightBorder="alignConfig.rightBorder" :color="$parent.color" :active="alignConfig.active" :disabled="alignConfig.disabled" @operate="setAlign">
118
+ <Icon value="align-left"></Icon>
119
+ </Button>
120
+ <!-- 有序列表 -->
121
+ <Button v-if="orderListConfig.show" name="orderList" :title="$editTrans('orderList')" :tooltip="config.tooltip" :leftBorder="orderListConfig.leftBorder" :rightBorder="orderListConfig.rightBorder" :color="$parent.color" :active="orderListConfig.active" :disabled="orderListConfig.disabled" @operate="setList">
122
+ <Icon value="list-ordered"></Icon>
123
+ </Button>
124
+ <!-- 无序列表 -->
125
+ <Button v-if="unorderListConfig.show" name="unorderList" :title="$editTrans('unorderList')" :tooltip="config.tooltip" :leftBorder="unorderListConfig.leftBorder" :rightBorder="unorderListConfig.rightBorder" :color="$parent.color" :active="unorderListConfig.active" :disabled="unorderListConfig.disabled" @operate="setList">
126
+ <Icon value="list-unordered"></Icon>
127
+ </Button>
128
+ <!-- 任务列表 -->
129
+ <Button v-if="taskConfig.show" name="task" :title="$editTrans('task')" :tooltip="config.tooltip" :leftBorder="taskConfig.leftBorder" :rightBorder="taskConfig.rightBorder" :color="$parent.color" :active="taskConfig.active" :disabled="taskConfig.disabled" @operate="setTask">
130
+ <Icon value="task"></Icon>
131
+ </Button>
132
+ <!-- 加粗 -->
133
+ <Button v-if="boldConfig.show" name="bold" :title="$editTrans('bold')" :tooltip="config.tooltip" :leftBorder="boldConfig.leftBorder" :rightBorder="boldConfig.rightBorder" :color="$parent.color" :active="boldConfig.active" :disabled="boldConfig.disabled" @operate="setBold">
134
+ <Icon value="bold"></Icon>
135
+ </Button>
136
+ <!-- 斜体 -->
137
+ <Button v-if="italicConfig.show" name="italic" :title="$editTrans('italic')" :tooltip="config.tooltip" :leftBorder="italicConfig.leftBorder" :rightBorder="italicConfig.rightBorder" :color="$parent.color" :active="italicConfig.active" :disabled="italicConfig.disabled" @operate="setItalic">
138
+ <Icon value="italic"></Icon>
139
+ </Button>
140
+ <!-- 删除线 -->
141
+ <Button v-if="strikethroughConfig.show" name="strikethrough" :title="$editTrans('strikethrough')" :tooltip="config.tooltip" :leftBorder="strikethroughConfig.leftBorder" :rightBorder="strikethroughConfig.rightBorder" :color="$parent.color" :active="strikethroughConfig.active" :disabled="strikethroughConfig.disabled" @operate="setStrikethrough">
142
+ <Icon value="strikethrough"></Icon>
143
+ </Button>
144
+ <!-- 下划线 -->
145
+ <Button v-if="underlineConfig.show" name="underline" :title="$editTrans('underline')" :tooltip="config.tooltip" :leftBorder="underlineConfig.leftBorder" :rightBorder="underlineConfig.rightBorder" :color="$parent.color" :active="underlineConfig.active" :disabled="underlineConfig.disabled" @operate="setUnderline">
146
+ <Icon value="underline"></Icon>
147
+ </Button>
148
+ <!-- 行内代码块 -->
149
+ <Button v-if="codeConfig.show" name="code" :title="$editTrans('code')" :tooltip="config.tooltip" :leftBorder="codeConfig.leftBorder" :rightBorder="codeConfig.rightBorder" :color="$parent.color" :active="codeConfig.active" :disabled="codeConfig.disabled" @operate="setCodeStyle">
150
+ <Icon value="code"></Icon>
151
+ </Button>
152
+ <!-- 上标 -->
153
+ <Button v-if="superConfig.show" name="superscript" :title="$editTrans('superscript')" :tooltip="config.tooltip" :leftBorder="superConfig.leftBorder" :rightBorder="superConfig.rightBorder" :color="$parent.color" :active="superConfig.active" :disabled="superConfig.disabled" @operate="setSuperscript">
154
+ <Icon value="superscript"></Icon>
155
+ </Button>
156
+ <!-- 下标 -->
157
+ <Button v-if="subConfig.show" name="subscript" :title="$editTrans('subscript')" :tooltip="config.tooltip" :leftBorder="subConfig.leftBorder" :rightBorder="subConfig.rightBorder" :color="$parent.color" :active="subConfig.active" :disabled="subConfig.disabled" @operate="setSubscript">
158
+ <Icon value="subscript"></Icon>
159
+ </Button>
160
+ <!-- 字号大小 -->
161
+ <Button v-if="fontSizeConfig.show" name="fontSize" type="display" :title="$editTrans('fontSize')" :tooltip="config.tooltip" :display-config="fontSizeConfig.displayConfig" :leftBorder="fontSizeConfig.leftBorder" :rightBorder="fontSizeConfig.rightBorder" :color="$parent.color" :active="fontSizeConfig.active" :disabled="fontSizeConfig.disabled" @operate="setFontSize"></Button>
162
+ <!-- 字体 -->
163
+ <Button v-if="fontFamilyConfig.show" name="fontFamily" type="display" :title="$editTrans('fontFamily')" :tooltip="config.tooltip" :display-config="fontFamilyConfig.displayConfig" :leftBorder="fontFamilyConfig.leftBorder" :rightBorder="fontFamilyConfig.rightBorder" :color="$parent.color" :active="fontFamilyConfig.active" :disabled="fontFamilyConfig.disabled" @operate="setFontFamily"></Button>
164
+ <!-- 行高 -->
165
+ <Button v-if="lineHeightConfig.show" name="lineHeight" type="display" :title="$editTrans('lineHeight')" :tooltip="config.tooltip" :display-config="lineHeightConfig.displayConfig" :leftBorder="lineHeightConfig.leftBorder" :rightBorder="lineHeightConfig.rightBorder" :color="$parent.color" :active="lineHeightConfig.active" :disabled="lineHeightConfig.disabled" @operate="setLineHeight"></Button>
166
+ <!-- 前景色 -->
167
+ <Button v-if="foreColorConfig.show" name="foreColor" type="select" :title="$editTrans('foreColor')" :tooltip="config.tooltip" :select-config="foreColorConfig.selectConfig" :leftBorder="foreColorConfig.leftBorder" :rightBorder="foreColorConfig.rightBorder" :color="$parent.color" :active="foreColorConfig.active" :disabled="foreColorConfig.disabled" hideScroll ref="foreColor">
168
+ <Icon value="font-color"></Icon>
169
+ <template #layer="{ options }">
170
+ <Colors :tooltip="config.tooltip" :color="$parent.color" :value="foreColorConfig.value" @change="setForeColor" :data="options"></Colors>
171
+ </template>
172
+ </Button>
173
+ <!-- 背景色 -->
174
+ <Button v-if="backColorConfig.show" name="backColor" type="select" :title="$editTrans('backColor')" :tooltip="config.tooltip" :select-config="backColorConfig.selectConfig" :leftBorder="backColorConfig.leftBorder" :rightBorder="backColorConfig.rightBorder" :color="$parent.color" :active="backColorConfig.active" :disabled="backColorConfig.disabled" hideScroll ref="backColor">
175
+ <Icon value="brush"></Icon>
176
+ <template #layer="{ options }">
177
+ <Colors :tooltip="config.tooltip" :color="$parent.color" :value="backColorConfig.value" @change="setBackColor" :data="options"></Colors>
178
+ </template>
179
+ </Button>
180
+ <!-- 清除样式 -->
181
+ <Button v-if="formatClearConfig.show" name="formatClear" :title="$editTrans('formatClear')" :tooltip="config.tooltip" :leftBorder="formatClearConfig.leftBorder" :rightBorder="formatClearConfig.rightBorder" :color="$parent.color" :active="formatClearConfig.active" :disabled="formatClearConfig.disabled" @operate="clearFormat">
182
+ <Icon value="format-clear"></Icon>
183
+ </Button>
184
+ </template>
185
+ </div>
186
+ </Layer>
187
+ </template>
188
+ <script>
189
+ import Layer from '../base/Layer'
190
+ import Tooltip from '../base/Tooltip'
191
+ import Button from '../base/Button'
192
+ import Icon from '../base/Icon'
193
+ import Checkbox from '../base/Checkbox'
194
+ import Colors from './Colors'
195
+ import { AlexElement } from 'alex-editor'
196
+ import Dap from 'dap-util'
197
+ export default {
198
+ name: 'Toolbar',
199
+ emits: ['update:modelValue'],
200
+ props: {
201
+ //是否显示
202
+ modelValue: {
203
+ type: Boolean,
204
+ default: false
205
+ },
206
+ //关联元素
207
+ node: {
208
+ type: [String, Node],
209
+ default: null
210
+ },
211
+ //类型
212
+ type: {
213
+ type: String,
214
+ default: 'text',
215
+ validator(value) {
216
+ return ['text', 'table', 'link', 'codeBlock', 'image', 'video'].includes(value)
217
+ }
218
+ },
219
+ //工具条配置
220
+ config: {
221
+ type: Object,
222
+ default: null
223
+ }
224
+ },
225
+ data() {
226
+ return {
227
+ //链接参数配置
228
+ linkConfig: {
229
+ //链接地址
230
+ url: '',
231
+ //链接是否新窗口打开
232
+ newOpen: false
233
+ },
234
+ //视频参数配置
235
+ videoConfig: {
236
+ //是否显示控制器
237
+ controls: false,
238
+ //是否循环
239
+ loop: false,
240
+ //是否自动播放
241
+ autoplay: false,
242
+ //是否静音
243
+ muted: false
244
+ },
245
+ //代码块选择语言按钮配置
246
+ languageConfig: {
247
+ show: this.config.codeBlock.languages.show,
248
+ displayConfig: {
249
+ options: this.config.codeBlock.languages.options,
250
+ value: '',
251
+ width: this.config.codeBlock.languages.width,
252
+ maxHeight: this.config.codeBlock.languages.maxHeight
253
+ },
254
+ leftBorder: this.config.codeBlock.languages.leftBorder,
255
+ rightBorder: this.config.codeBlock.languages.rightBorder,
256
+ active: false,
257
+ disabled: false
258
+ },
259
+ //标题按钮配置
260
+ headingConfig: {
261
+ show: this.config.text.heading.show,
262
+ displayConfig: {
263
+ options: this.config.text.heading.options,
264
+ value: '',
265
+ width: this.config.text.heading.width,
266
+ maxHeight: this.config.text.heading.maxHeight
267
+ },
268
+ defaultValue: this.config.text.heading.defaultValue,
269
+ leftBorder: this.config.text.heading.leftBorder,
270
+ rightBorder: this.config.text.heading.rightBorder,
271
+ active: false,
272
+ disabled: false
273
+ },
274
+ //对齐方式按钮配置
275
+ alignConfig: {
276
+ show: this.config.text.align.show,
277
+ selectConfig: {
278
+ options: this.config.text.align.options,
279
+ width: this.config.text.align.width,
280
+ maxHeight: this.config.text.align.maxHeight
281
+ },
282
+ leftBorder: this.config.text.align.leftBorder,
283
+ rightBorder: this.config.text.align.rightBorder,
284
+ active: false,
285
+ disabled: false
286
+ },
287
+ //有序列表按钮配置
288
+ orderListConfig: {
289
+ show: this.config.text.orderList.show,
290
+ leftBorder: this.config.text.orderList.leftBorder,
291
+ rightBorder: this.config.text.orderList.rightBorder,
292
+ active: false,
293
+ disabled: false
294
+ },
295
+ //无序列表按钮配置
296
+ unorderListConfig: {
297
+ show: this.config.text.unorderList.show,
298
+ leftBorder: this.config.text.unorderList.leftBorder,
299
+ rightBorder: this.config.text.unorderList.rightBorder,
300
+ active: false,
301
+ disabled: false
302
+ },
303
+ //任务列表按钮配置
304
+ taskConfig: {
305
+ show: this.config.text.task.show,
306
+ leftBorder: this.config.text.task.leftBorder,
307
+ rightBorder: this.config.text.task.rightBorder,
308
+ active: false,
309
+ disabled: false
310
+ },
311
+ //粗体按钮配置
312
+ boldConfig: {
313
+ show: this.config.text.bold.show,
314
+ leftBorder: this.config.text.bold.leftBorder,
315
+ rightBorder: this.config.text.bold.rightBorder,
316
+ active: false,
317
+ disabled: false
318
+ },
319
+ //斜体按钮配置
320
+ italicConfig: {
321
+ show: this.config.text.italic.show,
322
+ leftBorder: this.config.text.italic.leftBorder,
323
+ rightBorder: this.config.text.italic.rightBorder,
324
+ active: false,
325
+ disabled: false
326
+ },
327
+ //删除线按钮配置
328
+ strikethroughConfig: {
329
+ show: this.config.text.strikethrough.show,
330
+ leftBorder: this.config.text.strikethrough.leftBorder,
331
+ rightBorder: this.config.text.strikethrough.rightBorder,
332
+ active: false,
333
+ disabled: false
334
+ },
335
+ //下划线按钮配置
336
+ underlineConfig: {
337
+ show: this.config.text.underline.show,
338
+ leftBorder: this.config.text.underline.leftBorder,
339
+ rightBorder: this.config.text.underline.rightBorder,
340
+ active: false,
341
+ disabled: false
342
+ },
343
+ //行内代码块按钮配置
344
+ codeConfig: {
345
+ show: this.config.text.code.show,
346
+ leftBorder: this.config.text.code.leftBorder,
347
+ rightBorder: this.config.text.code.rightBorder,
348
+ active: false,
349
+ disabled: false
350
+ },
351
+ //上标按钮配置
352
+ superConfig: {
353
+ show: this.config.text.super.show,
354
+ leftBorder: this.config.text.super.leftBorder,
355
+ rightBorder: this.config.text.super.rightBorder,
356
+ active: false,
357
+ disabled: false
358
+ },
359
+ //下标按钮配置
360
+ subConfig: {
361
+ show: this.config.text.sub.show,
362
+ leftBorder: this.config.text.sub.leftBorder,
363
+ rightBorder: this.config.text.sub.rightBorder,
364
+ active: false,
365
+ disabled: false
366
+ },
367
+ //字号按钮配置
368
+ fontSizeConfig: {
369
+ show: this.config.text.fontSize.show,
370
+ displayConfig: {
371
+ options: this.config.text.fontSize.options,
372
+ value: '',
373
+ width: this.config.text.fontSize.width,
374
+ maxHeight: this.config.text.fontSize.maxHeight
375
+ },
376
+ defaultValue: this.config.text.fontSize.defaultValue,
377
+ leftBorder: this.config.text.fontSize.leftBorder,
378
+ rightBorder: this.config.text.fontSize.rightBorder,
379
+ active: false,
380
+ disabled: false
381
+ },
382
+ //字体按钮配置
383
+ fontFamilyConfig: {
384
+ show: this.config.text.fontFamily.show,
385
+ displayConfig: {
386
+ options: this.config.text.fontFamily.options,
387
+ value: '',
388
+ width: this.config.text.fontFamily.width,
389
+ maxHeight: this.config.text.fontFamily.maxHeight
390
+ },
391
+ defaultValue: this.config.text.fontFamily.defaultValue,
392
+ leftBorder: this.config.text.fontFamily.leftBorder,
393
+ rightBorder: this.config.text.fontFamily.rightBorder,
394
+ active: false,
395
+ disabled: false
396
+ },
397
+ //行高按钮配置
398
+ lineHeightConfig: {
399
+ show: this.config.text.lineHeight.show,
400
+ displayConfig: {
401
+ options: this.config.text.lineHeight.options,
402
+ value: '',
403
+ width: this.config.text.lineHeight.width,
404
+ maxHeight: this.config.text.lineHeight.maxHeight
405
+ },
406
+ defaultValue: this.config.text.lineHeight.defaultValue,
407
+ leftBorder: this.config.text.lineHeight.leftBorder,
408
+ rightBorder: this.config.text.lineHeight.rightBorder,
409
+ active: false,
410
+ disabled: false
411
+ },
412
+ //前景颜色按钮配置
413
+ foreColorConfig: {
414
+ show: this.config.text.foreColor.show,
415
+ selectConfig: {
416
+ options: this.config.text.foreColor.options
417
+ },
418
+ leftBorder: this.config.text.foreColor.leftBorder,
419
+ rightBorder: this.config.text.foreColor.rightBorder,
420
+ value: '', //选择的颜色值
421
+ active: false,
422
+ disabled: false
423
+ },
424
+ //背景颜色按钮配置
425
+ backColorConfig: {
426
+ show: this.config.text.backColor.show,
427
+ selectConfig: {
428
+ options: this.config.text.backColor.options
429
+ },
430
+ leftBorder: this.config.text.backColor.leftBorder,
431
+ rightBorder: this.config.text.backColor.rightBorder,
432
+ value: '', //选择的颜色值
433
+ active: false,
434
+ disabled: false
435
+ },
436
+ //清除格式按钮配置
437
+ formatClearConfig: {
438
+ show: this.config.text.formatClear.show,
439
+ leftBorder: this.config.text.formatClear.leftBorder,
440
+ rightBorder: this.config.text.formatClear.rightBorder,
441
+ active: false,
442
+ disabled: false
443
+ }
444
+ }
445
+ },
446
+ computed: {
447
+ //是否显示
448
+ show: {
449
+ get() {
450
+ return this.modelValue
451
+ },
452
+ set(val) {
453
+ this.$emit('update:modelValue', val)
454
+ }
455
+ }
456
+ },
457
+ components: {
458
+ Layer,
459
+ Tooltip,
460
+ Button,
461
+ Icon,
462
+ Checkbox,
463
+ Colors
464
+ },
465
+ inject: ['$editTrans'],
466
+ methods: {
467
+ //清除格式
468
+ clearFormat() {
469
+ this.$parent.formatText()
470
+ },
471
+ //设置背景色
472
+ setBackColor(value) {
473
+ this.$parent.setTextStyle('background-color', value)
474
+ this.$refs.backColor.hideLayer()
475
+ },
476
+ //设置前景色
477
+ setForeColor(value) {
478
+ this.$parent.setTextStyle('color', value)
479
+ this.$refs.foreColor.hideLayer()
480
+ },
481
+ //设置行高
482
+ setLineHeight(name, value) {
483
+ this.$parent.setLineHeight(value)
484
+ },
485
+ //设置字体
486
+ setFontFamily(name, value) {
487
+ this.$parent.setTextStyle('font-family', value)
488
+ },
489
+ //设置字号
490
+ setFontSize(name, value) {
491
+ this.$parent.setTextStyle('font-size', value)
492
+ },
493
+ //设置上标
494
+ setSuperscript() {
495
+ this.$parent.setTextStyle('vertical-align', 'super')
496
+ },
497
+ //设置下标
498
+ setSubscript() {
499
+ this.$parent.setTextStyle('vertical-align', 'sub')
500
+ },
501
+ //设置行内代码样式
502
+ setCodeStyle() {
503
+ this.$parent.setTextMark('data-editify-code', true)
504
+ },
505
+ //设置下划线
506
+ setUnderline() {
507
+ this.$parent.setTextStyle('text-decoration', 'underline')
508
+ },
509
+ //设置删除线
510
+ setStrikethrough() {
511
+ this.$parent.setTextStyle('text-decoration', 'line-through')
512
+ },
513
+ //设置列表
514
+ setList(name) {
515
+ this.$parent.setList(name == 'orderList')
516
+ },
517
+ //设置任务列表
518
+ setTask() {
519
+ this.$parent.setTask()
520
+ },
521
+ //斜体
522
+ setItalic() {
523
+ this.$parent.setTextStyle('font-style', 'italic')
524
+ },
525
+ //加粗
526
+ setBold() {
527
+ this.$parent.setTextStyle('font-weight', 'bold')
528
+ },
529
+ //设置标题
530
+ setHeading(name, value) {
531
+ this.$parent.setHeading(value)
532
+ },
533
+ //设置对齐方式
534
+ setAlign(name, value) {
535
+ this.$parent.setAlign(value)
536
+ },
537
+ //设置视频
538
+ setVideo(prop) {
539
+ if (this.$parent.disabled) {
540
+ return
541
+ }
542
+ const video = this.$parent.getCurrentParsedomElement('video')
543
+ if (video) {
544
+ //当前是拥有该属性
545
+ if (this.videoConfig[prop]) {
546
+ delete video.marks[prop]
547
+ }
548
+ //当前无该属性
549
+ else {
550
+ video.marks[prop] = true
551
+ }
552
+ this.videoConfig[prop] = !this.videoConfig[prop]
553
+ this.$parent.editor.domRender()
554
+ this.$parent.editor.rangeRender()
555
+ }
556
+ },
557
+ //设置宽度
558
+ setWidth(value) {
559
+ if (this.$parent.disabled) {
560
+ return
561
+ }
562
+ const element = this.$parent.getCurrentParsedomElement('img') || this.$parent.getCurrentParsedomElement('video')
563
+ if (element) {
564
+ const styles = {
565
+ width: value
566
+ }
567
+ if (element.hasStyles()) {
568
+ element.styles = Object.assign(element.styles, styles)
569
+ } else {
570
+ element.styles = styles
571
+ }
572
+ this.$parent.editor.formatElementStack()
573
+ this.$parent.editor.domRender()
574
+ this.$parent.editor.rangeRender()
575
+ //更新工具条位置
576
+ setTimeout(() => {
577
+ this.$refs.layer.setPosition()
578
+ }, 0)
579
+ }
580
+ },
581
+ //修改链接
582
+ modifyLink() {
583
+ if (this.$parent.disabled) {
584
+ return
585
+ }
586
+ if (!this.linkConfig.url) {
587
+ return
588
+ }
589
+ const link = this.$parent.getCurrentParsedomElement('a')
590
+ if (link) {
591
+ link.marks.href = this.linkConfig.url
592
+ if (this.linkConfig.newOpen) {
593
+ link.marks.target = '_blank'
594
+ } else {
595
+ delete link.marks.target
596
+ }
597
+ }
598
+ this.$parent.editor.formatElementStack()
599
+ this.$parent.editor.domRender()
600
+ },
601
+ //输入框获取焦点
602
+ handleInputFocus(e) {
603
+ if (this.$parent.disabled) {
604
+ return
605
+ }
606
+ if (this.$parent.color) {
607
+ e.currentTarget.style.borderColor = this.$parent.color
608
+ }
609
+ },
610
+ //输入框失去焦点
611
+ handleInputBlur(e) {
612
+ if (this.$parent.disabled) {
613
+ return
614
+ }
615
+ e.currentTarget.style.borderColor = ''
616
+ },
617
+ //选择代码语言
618
+ selectLanguage(name, value) {
619
+ if (this.$parent.disabled) {
620
+ return
621
+ }
622
+ const pre = this.$parent.getCurrentParsedomElement('pre')
623
+ if (pre) {
624
+ Object.assign(pre.marks, {
625
+ 'data-editify-hljs': value
626
+ })
627
+ this.$parent.editor.formatElementStack()
628
+ this.$parent.editor.domRender()
629
+ this.$parent.editor.rangeRender()
630
+ }
631
+ },
632
+ //代码块前后插入段落
633
+ insertParagraphWithPre(type = 'up') {
634
+ if (this.$parent.disabled) {
635
+ return
636
+ }
637
+ if (!this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
638
+ this.$parent.editor.range.anchor.element = this.$parent.editor.range.focus.element
639
+ this.$parent.editor.range.anchor.offset = this.$parent.editor.range.focus.offset
640
+ }
641
+ const pre = this.$parent.getCurrentParsedomElement('pre')
642
+ if (pre) {
643
+ const paragraph = new AlexElement('block', AlexElement.BLOCK_NODE, null, null, null)
644
+ const breakEl = new AlexElement('closed', 'br', null, null, null)
645
+ this.$parent.editor.addElementTo(breakEl, paragraph)
646
+ if (type == 'up') {
647
+ this.$parent.editor.addElementBefore(paragraph, pre)
648
+ } else {
649
+ this.$parent.editor.addElementAfter(paragraph, pre)
650
+ }
651
+ this.$parent.editor.range.anchor.moveToEnd(paragraph)
652
+ this.$parent.editor.range.focus.moveToEnd(paragraph)
653
+ this.$parent.editor.formatElementStack()
654
+ this.$parent.editor.domRender()
655
+ this.$parent.editor.rangeRender()
656
+ }
657
+ },
658
+ //表格前后插入列
659
+ insertTableColumn(type = 'left') {
660
+ if (this.$parent.disabled) {
661
+ return
662
+ }
663
+ if (!this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
664
+ this.$parent.editor.range.anchor.element = this.$parent.editor.range.focus.element
665
+ this.$parent.editor.range.anchor.offset = this.$parent.editor.range.focus.offset
666
+ }
667
+ const table = this.$parent.getCurrentParsedomElement('table')
668
+ const column = this.$parent.getCurrentParsedomElement('td')
669
+ const tbody = this.$parent.getCurrentParsedomElement('tbody')
670
+ if (column && table && tbody) {
671
+ const rows = tbody.children
672
+ const index = column.parent.children.findIndex(item => {
673
+ return item.isEqual(column)
674
+ })
675
+ //插入列
676
+ rows.forEach(row => {
677
+ const newColumn = column.clone(false)
678
+ const breakEl = new AlexElement('closed', 'br', null, null, null)
679
+ this.$parent.editor.addElementTo(breakEl, newColumn)
680
+ if (type == 'left') {
681
+ this.$parent.editor.addElementTo(newColumn, row, index)
682
+ } else {
683
+ this.$parent.editor.addElementTo(newColumn, row, index + 1)
684
+ }
685
+ })
686
+ //插入col
687
+ const colgroup = table.children.find(item => {
688
+ return item.parsedom == 'colgroup'
689
+ })
690
+ const col = new AlexElement('closed', 'col', null, null, null)
691
+ if (type == 'left') {
692
+ this.$parent.editor.addElementTo(col, colgroup, index)
693
+ } else {
694
+ this.$parent.editor.addElementTo(col, colgroup, index + 1)
695
+ }
696
+ //渲染
697
+ this.$parent.editor.formatElementStack()
698
+ if (type == 'left') {
699
+ const previousColumn = this.$parent.editor.getPreviousElement(column)
700
+ this.$parent.editor.range.anchor.moveToStart(previousColumn)
701
+ this.$parent.editor.range.focus.moveToStart(previousColumn)
702
+ } else {
703
+ const nextColumn = this.$parent.editor.getNextElement(column)
704
+ this.$parent.editor.range.anchor.moveToStart(nextColumn)
705
+ this.$parent.editor.range.focus.moveToStart(nextColumn)
706
+ }
707
+ this.$parent.editor.domRender()
708
+ this.$parent.editor.rangeRender()
709
+ }
710
+ },
711
+ //表格插入前后插入行
712
+ insertTableRow(type = 'up') {
713
+ if (this.$parent.disabled) {
714
+ return
715
+ }
716
+ if (!this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
717
+ this.$parent.editor.range.anchor.element = this.$parent.editor.range.focus.element
718
+ this.$parent.editor.range.anchor.offset = this.$parent.editor.range.focus.offset
719
+ }
720
+ const table = this.$parent.getCurrentParsedomElement('table')
721
+ const row = this.$parent.getCurrentParsedomElement('tr')
722
+ if (table && row) {
723
+ const newRow = row.clone()
724
+ newRow.children.forEach(column => {
725
+ column.children = []
726
+ const breakEl = new AlexElement('closed', 'br', null, null, null)
727
+ this.$parent.editor.addElementTo(breakEl, column)
728
+ })
729
+ if (type == 'up') {
730
+ this.$parent.editor.addElementBefore(newRow, row)
731
+ } else {
732
+ this.$parent.editor.addElementAfter(newRow, row)
733
+ }
734
+ this.$parent.editor.formatElementStack()
735
+ this.$parent.editor.range.anchor.moveToStart(newRow)
736
+ this.$parent.editor.range.focus.moveToStart(newRow)
737
+ this.$parent.editor.domRender()
738
+ this.$parent.editor.rangeRender()
739
+ //更新工具条位置
740
+ setTimeout(() => {
741
+ this.$refs.layer.setPosition()
742
+ }, 0)
743
+ }
744
+ },
745
+ //表格前后插入段落
746
+ insertParagraphWithTable(type = 'up') {
747
+ if (this.$parent.disabled) {
748
+ return
749
+ }
750
+ const table = this.$parent.getCurrentParsedomElement('table')
751
+ if (table) {
752
+ const paragraph = new AlexElement('block', AlexElement.BLOCK_NODE, null, null, null)
753
+ const breakEl = new AlexElement('closed', 'br', null, null, null)
754
+ this.$parent.editor.addElementTo(breakEl, paragraph)
755
+ if (type == 'up') {
756
+ this.$parent.editor.addElementBefore(paragraph, table)
757
+ } else {
758
+ this.$parent.editor.addElementAfter(paragraph, table)
759
+ }
760
+ this.$parent.editor.range.anchor.moveToEnd(paragraph)
761
+ this.$parent.editor.range.focus.moveToEnd(paragraph)
762
+ this.$parent.editor.formatElementStack()
763
+ this.$parent.editor.domRender()
764
+ this.$parent.editor.rangeRender()
765
+ }
766
+ },
767
+ //删除表格行
768
+ deleteTableRow() {
769
+ if (this.$parent.disabled) {
770
+ return
771
+ }
772
+ if (!this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
773
+ this.$parent.editor.range.anchor.element = this.$parent.editor.range.focus.element
774
+ this.$parent.editor.range.anchor.offset = this.$parent.editor.range.focus.offset
775
+ }
776
+ const table = this.$parent.getCurrentParsedomElement('table')
777
+ const row = this.$parent.getCurrentParsedomElement('tr')
778
+ if (table && row) {
779
+ const parent = row.parent
780
+ if (parent.children.length == 1) {
781
+ this.$parent.deleteByParsedom('table')
782
+ return
783
+ }
784
+ const previousRow = this.$parent.editor.getPreviousElement(row)
785
+ const nextRow = this.$parent.editor.getNextElement(row)
786
+ row.toEmpty()
787
+ this.$parent.editor.formatElementStack()
788
+ if (previousRow) {
789
+ this.$parent.editor.range.anchor.moveToEnd(previousRow.children[0])
790
+ this.$parent.editor.range.focus.moveToEnd(previousRow.children[0])
791
+ } else {
792
+ this.$parent.editor.range.anchor.moveToEnd(nextRow.children[0])
793
+ this.$parent.editor.range.focus.moveToEnd(nextRow.children[0])
794
+ }
795
+ this.$parent.editor.domRender()
796
+ this.$parent.editor.rangeRender()
797
+ //更新工具条位置
798
+ setTimeout(() => {
799
+ this.$refs.layer.setPosition()
800
+ }, 0)
801
+ }
802
+ },
803
+ //删除表格列
804
+ deleteTableColumn() {
805
+ if (this.$parent.disabled) {
806
+ return
807
+ }
808
+ if (!this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
809
+ this.$parent.editor.range.anchor.element = this.$parent.editor.range.focus.element
810
+ this.$parent.editor.range.anchor.offset = this.$parent.editor.range.focus.offset
811
+ }
812
+ const column = this.$parent.getCurrentParsedomElement('td')
813
+ const tbody = this.$parent.getCurrentParsedomElement('tbody')
814
+ const table = this.$parent.getCurrentParsedomElement('table')
815
+ if (column && table && tbody) {
816
+ const rows = tbody.children
817
+ const parent = column.parent
818
+ if (parent.children.length == 1) {
819
+ this.$parent.deleteByParsedom('table')
820
+ return
821
+ }
822
+ const previousColumn = this.$parent.editor.getPreviousElement(column)
823
+ const nextColumn = this.$parent.editor.getNextElement(column)
824
+ const index = column.parent.children.findIndex(item => {
825
+ return item.isEqual(column)
826
+ })
827
+ //删除列
828
+ rows.forEach(row => {
829
+ row.children[index].toEmpty()
830
+ })
831
+ //删除col
832
+ const colgroup = table.children.find(item => {
833
+ return item.parsedom == 'colgroup'
834
+ })
835
+ colgroup.children[index].toEmpty()
836
+ //渲染
837
+ this.$parent.editor.formatElementStack()
838
+ if (previousColumn) {
839
+ this.$parent.editor.range.anchor.moveToEnd(previousColumn)
840
+ this.$parent.editor.range.focus.moveToEnd(previousColumn)
841
+ } else {
842
+ this.$parent.editor.range.anchor.moveToEnd(nextColumn)
843
+ this.$parent.editor.range.focus.moveToEnd(nextColumn)
844
+ }
845
+ this.$parent.editor.domRender()
846
+ this.$parent.editor.rangeRender()
847
+ }
848
+ },
849
+ //浮层显示时
850
+ layerShow() {
851
+ //代码块初始化展示设置
852
+ if (this.type == 'codeBlock') {
853
+ const pre = this.$parent.getCurrentParsedomElement('pre')
854
+ if (pre) {
855
+ this.languageConfig.displayConfig.value = pre.marks['data-editify-hljs'] || ''
856
+ }
857
+ }
858
+ //链接初始化展示
859
+ else if (this.type == 'link') {
860
+ const link = this.$parent.getCurrentParsedomElement('a')
861
+ if (link) {
862
+ this.linkConfig.url = link.marks['href']
863
+ this.linkConfig.newOpen = link.marks['target'] == '_blank'
864
+ }
865
+ }
866
+ //视频初始化显示
867
+ else if (this.type == 'video') {
868
+ const video = this.$parent.getCurrentParsedomElement('video')
869
+ if (video) {
870
+ this.videoConfig.autoplay = !!video.marks['autoplay']
871
+ this.videoConfig.loop = !!video.marks['loop']
872
+ this.videoConfig.controls = !!video.marks['controls']
873
+ this.videoConfig.muted = !!video.marks['muted']
874
+ }
875
+ }
876
+ //文本工具条初始化显示
877
+ else if (this.type == 'text') {
878
+ //额外禁用判定
879
+ const extraDisabled = name => {
880
+ if (typeof this.config.extraDisabled == 'function') {
881
+ return this.config.extraDisabled.apply(this.$parent, [name]) || false
882
+ }
883
+ return false
884
+ }
885
+
886
+ //获取选区的元素
887
+ const result = this.$parent.editor.getElementsByRange(true, false)
888
+
889
+ //显示已设置标题
890
+ const findHeadingItem = this.headingConfig.displayConfig.options.find(item => {
891
+ let val = item
892
+ if (Dap.common.isObject(item)) {
893
+ val = item.value
894
+ }
895
+ return result.every(el => {
896
+ if (el.element.isBlock()) {
897
+ return el.element.parsedom == val
898
+ }
899
+ return el.element.getBlock().parsedom == val
900
+ })
901
+ })
902
+ this.headingConfig.displayConfig.value = findHeadingItem ? (Dap.common.isObject(findHeadingItem) ? findHeadingItem.value : findHeadingItem) : this.headingConfig.defaultValue
903
+ //标题禁用
904
+ this.headingConfig.disabled = extraDisabled('heading')
905
+
906
+ //对齐方式禁用
907
+ this.alignConfig.disabled = extraDisabled('align')
908
+
909
+ //有序列表按钮激活
910
+ this.orderListConfig.active = this.$parent.inList(true)
911
+ //有序列表按钮禁用
912
+ this.orderListConfig.disabled = extraDisabled('orderList')
913
+
914
+ //无序列表按钮激活
915
+ this.unorderListConfig.active = this.$parent.inList(false)
916
+ //无序列表按钮禁用
917
+ this.unorderListConfig.disabled = extraDisabled('unorderList')
918
+
919
+ //任务列表按钮激活
920
+ this.taskConfig.active = this.$parent.inTask()
921
+ //任务列表按钮禁用
922
+ this.taskConfig.disabled = extraDisabled('task')
923
+
924
+ //粗体按钮激活
925
+ this.boldConfig.active = this.$parent.queryTextStyle('font-weight', 'bold')
926
+ //粗体按钮禁用
927
+ this.boldConfig.disabled = extraDisabled('bold')
928
+
929
+ //斜体按钮激活
930
+ this.italicConfig.active = this.$parent.queryTextStyle('font-style', 'italic', true)
931
+ //斜体按钮禁用
932
+ this.italicConfig.disabled = extraDisabled('italic')
933
+
934
+ //删除线按钮激活
935
+ this.strikethroughConfig.active = this.$parent.queryTextStyle('text-decoration', 'line-through', true)
936
+ //删除线按钮禁用
937
+ this.strikethroughConfig.disabled = extraDisabled('strikethrough')
938
+
939
+ //下划线按钮激活
940
+ this.underlineConfig.active = this.$parent.queryTextStyle('text-decoration', 'underline', true)
941
+ //下划线按钮禁用
942
+ this.underlineConfig.disabled = extraDisabled('underline')
943
+
944
+ //行内代码按钮激活
945
+ this.codeConfig.active = this.$parent.queryTextMark('data-editify-code')
946
+ //行内代码按钮禁用
947
+ this.codeConfig.disabled = extraDisabled('code')
948
+
949
+ //上标按钮激活
950
+ this.superConfig.active = this.$parent.queryTextStyle('vertical-align', 'super', true)
951
+ //上标按钮禁用
952
+ this.superConfig.disabled = extraDisabled('super')
953
+
954
+ //下标按钮激活
955
+ this.subConfig.active = this.$parent.queryTextStyle('vertical-align', 'sub', true)
956
+ //下标按钮禁用
957
+ this.subConfig.disabled = extraDisabled('sub')
958
+
959
+ //显示已选择字号
960
+ const findFontItem = this.fontSizeConfig.displayConfig.options.find(item => {
961
+ if (Dap.common.isObject(item)) {
962
+ return this.$parent.queryTextStyle('font-size', item.value, true)
963
+ }
964
+ return this.$parent.queryTextStyle('font-size', item, true)
965
+ })
966
+ this.fontSizeConfig.displayConfig.value = findFontItem ? (Dap.common.isObject(findFontItem) ? findFontItem.value : findFontItem) : this.fontSizeConfig.defaultValue
967
+ //字号按钮禁用
968
+ this.fontSizeConfig.disabled = extraDisabled('fontSize')
969
+
970
+ //显示已选择字体
971
+ const findFamilyItem = this.fontFamilyConfig.displayConfig.options.find(item => {
972
+ if (Dap.common.isObject(item)) {
973
+ return this.$parent.queryTextStyle('font-family', item.value, true)
974
+ }
975
+ return this.$parent.queryTextStyle('font-family', item, true)
976
+ })
977
+ this.fontFamilyConfig.displayConfig.value = findFamilyItem ? (Dap.common.isObject(findFamilyItem) ? findFamilyItem.value : findFamilyItem) : this.fontFamilyConfig.defaultValue
978
+ //字体按钮禁用
979
+ this.fontFamilyConfig.disabled = extraDisabled('fontFamily')
980
+
981
+ //显示已设置行高
982
+ const findHeightItem = this.lineHeightConfig.displayConfig.options.find(item => {
983
+ let val = item
984
+ if (Dap.common.isObject(item)) {
985
+ val = item.value
986
+ }
987
+ return result.every(el => {
988
+ if (el.element.isBlock() || el.element.isInblock()) {
989
+ return el.element.hasStyles() && el.element.styles['line-height'] == val
990
+ }
991
+ const block = el.element.getBlock()
992
+ const inblock = el.element.getInblock()
993
+ if (inblock) {
994
+ return inblock.hasStyles() && inblock.styles['line-height'] == val
995
+ }
996
+ return block.hasStyles() && block.styles['line-height'] == val
997
+ })
998
+ })
999
+ this.lineHeightConfig.displayConfig.value = findHeightItem ? (Dap.common.isObject(findHeightItem) ? findHeightItem.value : findHeightItem) : this.lineHeightConfig.defaultValue
1000
+ //行高按钮禁用
1001
+ this.lineHeightConfig.disabled = extraDisabled('lineHeight')
1002
+
1003
+ //显示已选择的前景色
1004
+ const findForeColorItem = this.foreColorConfig.selectConfig.options.find(item => {
1005
+ if (Dap.common.isObject(item)) {
1006
+ return this.$parent.queryTextStyle('color', item.value, true)
1007
+ }
1008
+ return this.$parent.queryTextStyle('color', item, true)
1009
+ })
1010
+ this.foreColorConfig.value = findForeColorItem ? (Dap.common.isObject(findForeColorItem) ? findForeColorItem.value : findForeColorItem) : ''
1011
+ //前景色按钮禁用
1012
+ this.foreColorConfig.disabled = extraDisabled('foreColor')
1013
+
1014
+ //显示已选择的背景色
1015
+ const findBackColorItem = this.backColorConfig.selectConfig.options.find(item => {
1016
+ if (Dap.common.isObject(item)) {
1017
+ return this.$parent.queryTextStyle('background-color', item.value, true)
1018
+ }
1019
+ return this.$parent.queryTextStyle('background-color', item, true)
1020
+ })
1021
+ this.backColorConfig.value = findBackColorItem ? (Dap.common.isObject(findBackColorItem) ? findBackColorItem.value : findBackColorItem) : ''
1022
+ //背景色按钮禁用
1023
+ this.backColorConfig.disabled = extraDisabled('backColor')
1024
+
1025
+ //清除格式按钮禁用
1026
+ this.formatClearConfig.disabled = extraDisabled('formatClear')
1027
+ }
1028
+ }
1029
+ }
1030
+ }
1031
+ </script>
1032
+ <style lang="less" scoped>
1033
+ .editify-toolbar {
1034
+ display: flex;
1035
+ justify-content: flex-start;
1036
+ align-items: center;
1037
+ padding: 6px 10px;
1038
+
1039
+ .editify-icon-rotate {
1040
+ transform: rotate(180deg);
1041
+ }
1042
+ }
1043
+
1044
+ .editify-toolbar-link {
1045
+ display: block;
1046
+ width: 280px;
1047
+ padding: 4px;
1048
+
1049
+ .editify-toolbar-link-label {
1050
+ display: block;
1051
+ text-align: left;
1052
+ margin-bottom: 10px;
1053
+ font-size: @font-size;
1054
+ color: @font-color;
1055
+ }
1056
+
1057
+ input {
1058
+ appearance: none;
1059
+ -webkit-appearance: none;
1060
+ -moz-appearance: none;
1061
+ display: block;
1062
+ width: 100%;
1063
+ margin: 0 0 10px 0;
1064
+ padding: 4px 2px;
1065
+ border: none;
1066
+ font-size: @font-size;
1067
+ color: @font-color;
1068
+ border-bottom: 1px solid @border-color;
1069
+ line-height: 1.5;
1070
+ transition: all 500ms;
1071
+ background-color: transparent;
1072
+ outline: none;
1073
+
1074
+ &::-webkit-input-placeholder,
1075
+ &::placeholder {
1076
+ color: @font-color-disabled;
1077
+ font-family: inherit;
1078
+ font-size: inherit;
1079
+ vertical-align: middle;
1080
+ }
1081
+
1082
+ &[disabled] {
1083
+ background-color: transparent;
1084
+ opacity: 0.6;
1085
+ }
1086
+ }
1087
+
1088
+ .editify-toolbar-link-footer {
1089
+ display: flex;
1090
+ justify-content: space-between;
1091
+ align-items: center;
1092
+ width: 100%;
1093
+ font-size: @font-size;
1094
+ color: @font-color-light;
1095
+
1096
+ .editify-toolbar-link-operations {
1097
+ display: flex;
1098
+ justify-content: flex-start;
1099
+ align-items: center;
1100
+
1101
+ & > span,
1102
+ & > a {
1103
+ cursor: pointer;
1104
+ opacity: 0.8;
1105
+ transition: all 200ms;
1106
+
1107
+ &:hover {
1108
+ opacity: 1;
1109
+ }
1110
+ }
1111
+
1112
+ & > span {
1113
+ margin-right: 15px;
1114
+ }
1115
+
1116
+ & > a {
1117
+ text-decoration: none;
1118
+ }
1119
+ }
1120
+ }
1121
+ }
1122
+ </style>