vue-editify 0.1.10 → 0.1.13

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