vue-editify 0.0.50 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,16 +4,16 @@
4
4
  </div>
5
5
  </template>
6
6
  <script>
7
- import Icon from '../base/Icon'
8
- import Button from '../base/Button'
9
- import Colors from './Colors'
10
- import InsertLink from './InsertLink'
11
- import InsertImage from './InsertImage'
12
- import InsertVideo from './InsertVideo'
13
- import InsertTable from './InsertTable'
7
+ import Icon from './base/Icon'
8
+ import Button from './base/Button'
9
+ import Colors from './common/Colors'
10
+ import InsertLink from './common/InsertLink'
11
+ import InsertImage from './common/InsertImage'
12
+ import InsertVideo from './common/InsertVideo'
13
+ import InsertTable from './common/InsertTable'
14
14
  import { h, getCurrentInstance } from 'vue'
15
- import { AlexElement } from 'alex-editor'
16
- import Dap from 'dap-util'
15
+ import { common as DapCommon } from 'dap-util'
16
+ import { getLinkText, setHeading, setIndentIncrease, setIndentDecrease, setQuote, setAlign, setList, setTask, setTextStyle, setTextMark, removeTextStyle, removeTextMark, setLineHeight, insertLink, insertImage, insertVideo, insertTable, insertCodeBlock, hasPreInRange, hasTableInRange, hasQuoteInRange, hasLinkInRange, isRangeInQuote, isRangeInList, isRangeInTask, queryTextStyle, queryTextMark, getCurrentParsedomElement } from '../core/function'
17
17
  export default {
18
18
  name: 'Menu',
19
19
  props: {
@@ -22,11 +22,6 @@ export default {
22
22
  type: Object,
23
23
  default: null
24
24
  },
25
- //是否禁用整个菜单栏
26
- disabled: {
27
- type: Boolean,
28
- default: false
29
- },
30
25
  //主题色
31
26
  color: {
32
27
  type: String,
@@ -338,6 +333,10 @@ export default {
338
333
  }
339
334
  },
340
335
  computed: {
336
+ //整个菜单栏是否禁用
337
+ disabled() {
338
+ return this.$parent.disabled || !this.$parent.canUseMenu
339
+ },
341
340
  //菜单名称数组
342
341
  menuNames() {
343
342
  return Object.keys(this.config.sequence).sort((a, b) => {
@@ -816,18 +815,7 @@ export default {
816
815
  hideScroll: true,
817
816
  onLayerShow: () => {
818
817
  //存在选区的情况下预置链接文本值
819
- let text = ''
820
- const result = this.$parent.$parent.editor.getElementsByRange().flatIncludes
821
- result.forEach(item => {
822
- if (item.element.isText()) {
823
- if (item.offset) {
824
- text += item.element.textContent.substring(item.offset[0], item.offset[1])
825
- } else {
826
- text += item.element.textContent || ''
827
- }
828
- }
829
- })
830
- this.$parent.linkConfig.text = text
818
+ this.$parent.linkConfig.text = getLinkText(this.$parent.$parent)
831
819
  }
832
820
  },
833
821
  {
@@ -1016,7 +1004,7 @@ export default {
1016
1004
  }
1017
1005
 
1018
1006
  /** 下面是拓展菜单的配置 */
1019
- if (Dap.common.isObject(this.$parent.config.extends)) {
1007
+ if (DapCommon.isObject(this.$parent.config.extends)) {
1020
1008
  //获取菜单按钮的配置
1021
1009
  const configuration = this.$parent.config.extends[this.name]
1022
1010
  if (configuration) {
@@ -1082,9 +1070,14 @@ export default {
1082
1070
  methods: {
1083
1071
  //按钮操作触发函数
1084
1072
  handleOperate(name, val) {
1073
+ //菜单栏禁用
1085
1074
  if (this.disabled) {
1086
1075
  return
1087
1076
  }
1077
+ //没有获取焦点
1078
+ if (!this.$parent.editor.range) {
1079
+ return
1080
+ }
1088
1081
  //撤销
1089
1082
  if (name == 'undo') {
1090
1083
  this.$parent.undo()
@@ -1095,109 +1088,208 @@ export default {
1095
1088
  }
1096
1089
  //设置标题
1097
1090
  else if (name == 'heading') {
1098
- this.$parent.setHeading(val)
1091
+ setHeading(this.$parent, val)
1092
+ this.$parent.editor.formatElementStack()
1093
+ this.$parent.editor.domRender()
1094
+ this.$parent.editor.rangeRender()
1099
1095
  }
1100
1096
  //设置缩进
1101
1097
  else if (name == 'indent') {
1102
1098
  //增加缩进
1103
1099
  if (val == 'indent-increase') {
1104
- this.$parent.setIndentIncrease()
1100
+ setIndentIncrease(this.$parent)
1105
1101
  }
1106
1102
  //减少缩进
1107
1103
  else if (val == 'indent-decrease') {
1108
- this.$parent.setIndentDecrease()
1104
+ setIndentDecrease(this.$parent)
1109
1105
  }
1106
+ this.$parent.editor.formatElementStack()
1107
+ this.$parent.editor.domRender()
1108
+ this.$parent.editor.rangeRender()
1110
1109
  }
1111
1110
  //设置引用
1112
1111
  else if (name == 'quote') {
1113
- this.$parent.setQuote()
1112
+ setQuote(this.$parent)
1113
+ this.$parent.editor.formatElementStack()
1114
+ this.$parent.editor.domRender()
1115
+ this.$parent.editor.rangeRender()
1114
1116
  }
1115
1117
  //设置对齐方式
1116
1118
  else if (name == 'align') {
1117
- this.$parent.setAlign(val)
1119
+ setAlign(this.$parent, val)
1120
+ this.$parent.editor.formatElementStack()
1121
+ this.$parent.editor.domRender()
1122
+ this.$parent.editor.rangeRender()
1118
1123
  }
1119
1124
  //设置有序列表
1120
1125
  else if (name == 'orderList') {
1121
- this.$parent.setList(true)
1126
+ setList(this.$parent, true)
1127
+ this.$parent.editor.formatElementStack()
1128
+ this.$parent.editor.domRender()
1129
+ this.$parent.editor.rangeRender()
1122
1130
  }
1123
1131
  //设置无序列表
1124
1132
  else if (name == 'unorderList') {
1125
- this.$parent.setList(false)
1133
+ setList(this.$parent, false)
1134
+ this.$parent.editor.formatElementStack()
1135
+ this.$parent.editor.domRender()
1136
+ this.$parent.editor.rangeRender()
1126
1137
  }
1127
1138
  //设置任务列表
1128
1139
  else if (name == 'task') {
1129
- this.$parent.setTask()
1140
+ setTask(this.$parent)
1141
+ this.$parent.editor.formatElementStack()
1142
+ this.$parent.editor.domRender()
1143
+ this.$parent.editor.rangeRender()
1130
1144
  }
1131
1145
  //设置粗体
1132
1146
  else if (name == 'bold') {
1133
- this.$parent.setTextStyle('font-weight', 'bold')
1147
+ if (queryTextStyle(this.$parent, 'font-weight', 'bold') || queryTextStyle(this.$parent, 'font-weight', '700')) {
1148
+ removeTextStyle(this.$parent, ['font-weight'])
1149
+ } else {
1150
+ setTextStyle(this.$parent, {
1151
+ 'font-weight': 'bold'
1152
+ })
1153
+ }
1154
+ this.$parent.editor.formatElementStack()
1155
+ this.$parent.editor.domRender()
1156
+ this.$parent.editor.rangeRender()
1134
1157
  }
1135
1158
  //设置下划线
1136
1159
  else if (name == 'underline') {
1137
- this.$parent.setTextStyle('text-decoration', 'underline')
1160
+ if (queryTextStyle(this.$parent, 'text-decoration', 'underline') || queryTextStyle(this.$parent, 'text-decoration-line', 'underline')) {
1161
+ removeTextStyle(this.$parent, ['text-decoration', 'text-decoration-line'])
1162
+ } else {
1163
+ setTextStyle(this.$parent, {
1164
+ 'text-decoration': 'underline'
1165
+ })
1166
+ }
1167
+ this.$parent.editor.formatElementStack()
1168
+ this.$parent.editor.domRender()
1169
+ this.$parent.editor.rangeRender()
1138
1170
  }
1139
1171
  //设置斜体
1140
1172
  else if (name == 'italic') {
1141
- this.$parent.setTextStyle('font-style', 'italic')
1173
+ if (queryTextStyle(this.$parent, 'font-style', 'italic')) {
1174
+ removeTextStyle(this.$parent, ['font-style'])
1175
+ } else {
1176
+ setTextStyle(this.$parent, {
1177
+ 'font-style': 'italic'
1178
+ })
1179
+ }
1180
+ this.$parent.editor.formatElementStack()
1181
+ this.$parent.editor.domRender()
1182
+ this.$parent.editor.rangeRender()
1142
1183
  }
1143
1184
  //设置删除线
1144
1185
  else if (name == 'strikethrough') {
1145
- this.$parent.setTextStyle('text-decoration', 'line-through')
1186
+ if (queryTextStyle(this.$parent, 'text-decoration', 'line-through') || queryTextStyle(this.$parent, 'text-decoration-line', 'line-through')) {
1187
+ removeTextStyle(this.$parent, ['text-decoration', 'text-decoration-line'])
1188
+ } else {
1189
+ setTextStyle(this.$parent, {
1190
+ 'text-decoration': 'line-through'
1191
+ })
1192
+ }
1193
+ this.$parent.editor.formatElementStack()
1194
+ this.$parent.editor.domRender()
1195
+ this.$parent.editor.rangeRender()
1146
1196
  }
1147
1197
  //设置行内代码
1148
1198
  else if (name == 'code') {
1149
- this.$parent.setTextMark('data-editify-code', true)
1199
+ if (queryTextMark(this.$parent, 'data-editify-code')) {
1200
+ removeTextMark(this.$parent, ['data-editify-code'])
1201
+ } else {
1202
+ setTextMark(this.$parent, {
1203
+ 'data-editify-code': true
1204
+ })
1205
+ }
1206
+ this.$parent.editor.formatElementStack()
1207
+ this.$parent.editor.domRender()
1208
+ this.$parent.editor.rangeRender()
1150
1209
  }
1151
1210
  //设置上标
1152
1211
  else if (name == 'super') {
1153
- this.$parent.setTextStyle('vertical-align', 'super')
1212
+ if (queryTextStyle(this.$parent, 'vertical-align', 'super')) {
1213
+ removeTextStyle(this.$parent, ['vertical-align'])
1214
+ } else {
1215
+ setTextStyle(this.$parent, {
1216
+ 'vertical-align': 'super'
1217
+ })
1218
+ }
1219
+ this.$parent.editor.formatElementStack()
1220
+ this.$parent.editor.domRender()
1221
+ this.$parent.editor.rangeRender()
1154
1222
  }
1155
1223
  //设置下标
1156
1224
  else if (name == 'sub') {
1157
- this.$parent.setTextStyle('vertical-align', 'sub')
1225
+ if (queryTextStyle(this.$parent, 'vertical-align', 'sub')) {
1226
+ removeTextStyle(this.$parent, ['vertical-align'])
1227
+ } else {
1228
+ setTextStyle(this.$parent, {
1229
+ 'vertical-align': 'sub'
1230
+ })
1231
+ }
1232
+ this.$parent.editor.formatElementStack()
1233
+ this.$parent.editor.domRender()
1234
+ this.$parent.editor.rangeRender()
1158
1235
  }
1159
1236
  //清除格式
1160
1237
  else if (name == 'formatClear') {
1161
- this.$parent.formatText()
1238
+ removeTextStyle(this.$parent)
1239
+ removeTextMark(this.$parent)
1240
+ this.$parent.editor.formatElementStack()
1241
+ this.$parent.editor.domRender()
1242
+ this.$parent.editor.rangeRender()
1162
1243
  }
1163
1244
  //设置字号
1164
1245
  else if (name == 'fontSize') {
1165
- this.$parent.setTextStyle('font-size', val)
1246
+ setTextStyle(this.$parent, {
1247
+ 'font-size': val
1248
+ })
1249
+ this.$parent.editor.formatElementStack()
1250
+ this.$parent.editor.domRender()
1251
+ this.$parent.editor.rangeRender()
1166
1252
  }
1167
1253
  //设置字体
1168
1254
  else if (name == 'fontFamily') {
1169
- this.$parent.setTextStyle('font-family', val)
1255
+ setTextStyle(this.$parent, {
1256
+ 'font-family': val
1257
+ })
1258
+ this.$parent.editor.formatElementStack()
1259
+ this.$parent.editor.domRender()
1260
+ this.$parent.editor.rangeRender()
1170
1261
  }
1171
1262
  //设置行高
1172
1263
  else if (name == 'lineHeight') {
1173
- this.$parent.setLineHeight(val)
1264
+ setLineHeight(this.$parent, val)
1265
+ this.$parent.editor.formatElementStack()
1266
+ this.$parent.editor.domRender()
1267
+ this.$parent.editor.rangeRender()
1174
1268
  }
1175
1269
  //设置前景色
1176
1270
  else if (name == 'foreColor') {
1177
- this.$parent.setTextStyle('color', val)
1271
+ setTextStyle(this.$parent, {
1272
+ color: val
1273
+ })
1274
+ this.$parent.editor.formatElementStack()
1275
+ this.$parent.editor.domRender()
1276
+ this.$parent.editor.rangeRender()
1178
1277
  }
1179
1278
  //设置背景色
1180
1279
  else if (name == 'backColor') {
1181
- this.$parent.setTextStyle('background-color', val)
1280
+ setTextStyle(this.$parent, {
1281
+ 'background-color': val
1282
+ })
1283
+ this.$parent.editor.formatElementStack()
1284
+ this.$parent.editor.domRender()
1285
+ this.$parent.editor.rangeRender()
1182
1286
  }
1183
1287
  //插入链接
1184
1288
  else if (name == 'link') {
1185
1289
  if (!val.url) {
1186
1290
  return
1187
1291
  }
1188
- if (!val.text) {
1189
- text = url
1190
- }
1191
- const marks = {
1192
- href: val.url
1193
- }
1194
- if (val.newOpen) {
1195
- marks.target = '_blank'
1196
- }
1197
- const linkEle = new AlexElement('inline', 'a', marks, null, null)
1198
- const textEle = new AlexElement('text', null, null, null, val.text)
1199
- this.$parent.editor.addElementTo(textEle, linkEle)
1200
- this.$parent.editor.insertElement(linkEle)
1292
+ insertLink(this.$parent, val.text, val.url, val.newOpen)
1201
1293
  this.$parent.editor.formatElementStack()
1202
1294
  this.$parent.editor.domRender()
1203
1295
  this.$parent.editor.rangeRender()
@@ -1207,22 +1299,34 @@ export default {
1207
1299
  if (!val) {
1208
1300
  return
1209
1301
  }
1210
- this.$parent.insertImage(val)
1302
+ insertImage(this.$parent, val)
1303
+ this.$parent.editor.formatElementStack()
1304
+ this.$parent.editor.domRender()
1305
+ this.$parent.editor.rangeRender()
1211
1306
  }
1212
1307
  //插入视频
1213
1308
  else if (name == 'video') {
1214
1309
  if (!val) {
1215
1310
  return
1216
1311
  }
1217
- this.$parent.insertVideo(val)
1312
+ insertVideo(this.$parent, val)
1313
+ this.$parent.editor.formatElementStack()
1314
+ this.$parent.editor.domRender()
1315
+ this.$parent.editor.rangeRender()
1218
1316
  }
1219
1317
  //插入表格
1220
1318
  else if (name == 'table') {
1221
- this.$parent.insertTable(val.row, val.column)
1319
+ insertTable(this.$parent, val.row, val.column)
1320
+ this.$parent.editor.formatElementStack()
1321
+ this.$parent.editor.domRender()
1322
+ this.$parent.editor.rangeRender()
1222
1323
  }
1223
1324
  //插入代码块
1224
1325
  else if (name == 'codeBlock') {
1225
- this.$parent.insertCodeBlock()
1326
+ insertCodeBlock(this.$parent)
1327
+ this.$parent.editor.formatElementStack()
1328
+ this.$parent.editor.domRender()
1329
+ this.$parent.editor.rangeRender()
1226
1330
  }
1227
1331
  //代码视图
1228
1332
  else if (name == 'sourceView') {
@@ -1240,28 +1344,23 @@ export default {
1240
1344
  }
1241
1345
  },
1242
1346
  //处理光标更新
1243
- handleRangeUpdate(useCache = false) {
1244
- if (this.disabled) {
1245
- return
1246
- }
1247
- //获取选区的元素
1248
- const result = this.$parent.editor.getElementsByRange(useCache).includes
1249
- //选区是否含有代码块元素
1250
- const hasPreStyle = this.$parent.hasPreStyle(true)
1347
+ handleRangeUpdate() {
1348
+ //选区是否含有代码块
1349
+ const value_hasPreInRange = hasPreInRange(this.$parent)
1251
1350
  //选区是否含有表格元素
1252
- const hasTable = this.$parent.hasTable(true)
1351
+ const value_hasTableInRange = hasTableInRange(this.$parent)
1253
1352
  //选区是否含有引用元素
1254
- const hasQuote = this.$parent.hasQuote(true)
1353
+ const value_hasQuoteInRange = hasQuoteInRange(this.$parent)
1255
1354
  //选区是否都在引用元素内
1256
- const inQuote = this.$parent.inQuote(true)
1355
+ const value_isRangeInQuote = isRangeInQuote(this.$parent)
1257
1356
  //选区是否含有链接元素
1258
- const hasLink = this.$parent.hasLink(true)
1357
+ const value_hasLinkInRange = hasLinkInRange(this.$parent)
1259
1358
  //选区是否都在有序列表内
1260
- const inOrderList = this.$parent.inList(true, true)
1359
+ const value_isRangeInOrderList = isRangeInList(this.$parent, true)
1261
1360
  //选区是否都在无序列表内
1262
- const inUnorderList = this.$parent.inList(false, true)
1361
+ const value_isRangeInUnorderList = isRangeInList(this.$parent, false)
1263
1362
  //选区是否都在任务列表内
1264
- const inTask = this.$parent.inTask(true)
1363
+ const value_isRangeInTask = isRangeInTask(this.$parent)
1265
1364
  //额外禁用判定
1266
1365
  const extraDisabled = name => {
1267
1366
  if (typeof this.config.extraDisabled == 'function') {
@@ -1279,120 +1378,120 @@ export default {
1279
1378
  //显示已设置标题
1280
1379
  const findHeadingItem = this.headingConfig.displayConfig.options.find(item => {
1281
1380
  let val = item
1282
- if (Dap.common.isObject(item)) {
1381
+ if (DapCommon.isObject(item)) {
1283
1382
  val = item.value
1284
1383
  }
1285
1384
  if (this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
1286
1385
  return this.$parent.editor.range.anchor.element.getBlock().parsedom == val
1287
1386
  }
1288
- return result.every(el => {
1387
+ return this.$parent.dataRangeCaches.list.every(el => {
1289
1388
  if (el.element.isBlock()) {
1290
1389
  return el.element.parsedom == val
1291
1390
  }
1292
1391
  return el.element.getBlock().parsedom == val
1293
1392
  })
1294
1393
  })
1295
- this.headingConfig.displayConfig.value = findHeadingItem ? (Dap.common.isObject(findHeadingItem) ? findHeadingItem.value : findHeadingItem) : this.headingConfig.defaultValue
1394
+ this.headingConfig.displayConfig.value = findHeadingItem ? (DapCommon.isObject(findHeadingItem) ? findHeadingItem.value : findHeadingItem) : this.headingConfig.defaultValue
1296
1395
  //标题禁用
1297
- this.headingConfig.disabled = hasPreStyle || hasTable || extraDisabled('heading')
1396
+ this.headingConfig.disabled = value_hasPreInRange || value_hasTableInRange || extraDisabled('heading')
1298
1397
 
1299
1398
  //缩进禁用
1300
- this.indentConfig.disabled = hasPreStyle || hasTable || hasQuote || extraDisabled('indent')
1399
+ this.indentConfig.disabled = value_hasPreInRange || value_hasTableInRange || extraDisabled('indent')
1301
1400
 
1302
1401
  //引用按钮激活
1303
- this.quoteConfig.active = inQuote
1402
+ this.quoteConfig.active = value_isRangeInQuote
1304
1403
  //引用按钮禁用
1305
- this.quoteConfig.disabled = hasPreStyle || hasTable || extraDisabled('quote')
1404
+ this.quoteConfig.disabled = value_hasPreInRange || value_hasTableInRange || extraDisabled('quote')
1306
1405
 
1307
1406
  //对齐方式按钮禁用
1308
- this.alignConfig.disabled = hasPreStyle || extraDisabled('align')
1407
+ this.alignConfig.disabled = value_hasPreInRange || extraDisabled('align')
1309
1408
 
1310
1409
  //有序列表按钮激活
1311
- this.orderListConfig.active = inOrderList
1410
+ this.orderListConfig.active = value_isRangeInOrderList
1312
1411
  //有序列表禁用
1313
- this.orderListConfig.disabled = hasPreStyle || hasTable || extraDisabled('orderList')
1412
+ this.orderListConfig.disabled = value_hasPreInRange || value_hasTableInRange || extraDisabled('orderList')
1314
1413
 
1315
1414
  //无序列表按钮激活
1316
- this.unorderListConfig.active = inUnorderList
1415
+ this.unorderListConfig.active = value_isRangeInUnorderList
1317
1416
  //无序列表禁用
1318
- this.unorderListConfig.disabled = hasPreStyle || hasTable || extraDisabled('unorderList')
1417
+ this.unorderListConfig.disabled = value_hasPreInRange || value_hasTableInRange || extraDisabled('unorderList')
1319
1418
 
1320
1419
  //任务列表按钮激活
1321
- this.taskConfig.active = inTask
1420
+ this.taskConfig.active = value_isRangeInTask
1322
1421
  //任务列表禁用
1323
- this.taskConfig.disabled = hasPreStyle || hasTable || extraDisabled('task')
1422
+ this.taskConfig.disabled = value_hasPreInRange || value_hasTableInRange || extraDisabled('task')
1324
1423
 
1325
1424
  //粗体按钮激活
1326
- this.boldConfig.active = this.$parent.queryTextStyle('font-weight', 'bold', true)
1425
+ this.boldConfig.active = queryTextStyle(this.$parent, 'font-weight', 'bold') || queryTextStyle(this.$parent, 'font-weight', '700')
1327
1426
  //粗体按钮禁用
1328
- this.boldConfig.disabled = hasPreStyle || extraDisabled('bold')
1427
+ this.boldConfig.disabled = value_hasPreInRange || extraDisabled('bold')
1329
1428
 
1330
1429
  //下划线按钮激活
1331
- this.underlineConfig.active = this.$parent.queryTextStyle('text-decoration', 'underline', true)
1430
+ this.underlineConfig.active = queryTextStyle(this.$parent, 'text-decoration', 'underline') || queryTextStyle(this.$parent, 'text-decoration-line', 'underline')
1332
1431
  //下划线按钮禁用
1333
- this.underlineConfig.disabled = hasPreStyle || extraDisabled('underline')
1432
+ this.underlineConfig.disabled = value_hasPreInRange || extraDisabled('underline')
1334
1433
 
1335
1434
  //斜体按钮激活
1336
- this.italicConfig.active = this.$parent.queryTextStyle('font-style', 'italic', true)
1435
+ this.italicConfig.active = queryTextStyle(this.$parent, 'font-style', 'italic')
1337
1436
  //斜体按钮禁用
1338
- this.italicConfig.disabled = hasPreStyle || extraDisabled('italic')
1437
+ this.italicConfig.disabled = value_hasPreInRange || extraDisabled('italic')
1339
1438
 
1340
1439
  //删除线按钮激活
1341
- this.strikethroughConfig.active = this.$parent.queryTextStyle('text-decoration', 'line-through', true)
1440
+ this.strikethroughConfig.active = queryTextStyle(this.$parent, 'text-decoration', 'line-through') || queryTextStyle(this.$parent, 'text-decoration-line', 'line-through')
1342
1441
  //删除线按钮禁用
1343
- this.strikethroughConfig.disabled = hasPreStyle || extraDisabled('strikethrough')
1442
+ this.strikethroughConfig.disabled = value_hasPreInRange || extraDisabled('strikethrough')
1344
1443
 
1345
1444
  //行内代码按钮激活
1346
- this.codeConfig.active = this.$parent.queryTextMark('data-editify-code', null, true)
1445
+ this.codeConfig.active = queryTextMark(this.$parent, 'data-editify-code')
1347
1446
  //行内代码按钮禁用
1348
- this.codeConfig.disabled = hasPreStyle || extraDisabled('code')
1447
+ this.codeConfig.disabled = value_hasPreInRange || extraDisabled('code')
1349
1448
 
1350
1449
  //上标按钮激活
1351
- this.superConfig.active = this.$parent.queryTextStyle('vertical-align', 'super', true)
1450
+ this.superConfig.active = queryTextStyle(this.$parent, 'vertical-align', 'super')
1352
1451
  //上标按钮禁用
1353
- this.superConfig.disabled = hasPreStyle || extraDisabled('super')
1452
+ this.superConfig.disabled = value_hasPreInRange || extraDisabled('super')
1354
1453
 
1355
1454
  //下标按钮激活
1356
- this.subConfig.active = this.$parent.queryTextStyle('vertical-align', 'sub', true)
1455
+ this.subConfig.active = queryTextStyle(this.$parent, 'vertical-align', 'sub')
1357
1456
  //下标按钮禁用
1358
- this.subConfig.disabled = hasPreStyle || extraDisabled('sub')
1457
+ this.subConfig.disabled = value_hasPreInRange || extraDisabled('sub')
1359
1458
 
1360
1459
  //清除格式按钮禁用
1361
- this.formatClearConfig.disabled = hasPreStyle || extraDisabled('formatClear')
1460
+ this.formatClearConfig.disabled = value_hasPreInRange || extraDisabled('formatClear')
1362
1461
 
1363
1462
  //显示已选择字号
1364
1463
  const findFontItem = this.fontSizeConfig.displayConfig.options.find(item => {
1365
- if (Dap.common.isObject(item)) {
1366
- return this.$parent.queryTextStyle('font-size', item.value, true)
1464
+ if (DapCommon.isObject(item)) {
1465
+ return queryTextStyle(this.$parent, 'font-size', item.value)
1367
1466
  }
1368
- return this.$parent.queryTextStyle('font-size', item, true)
1467
+ return queryTextStyle(this.$parent, 'font-size', item)
1369
1468
  })
1370
- this.fontSizeConfig.displayConfig.value = findFontItem ? (Dap.common.isObject(findFontItem) ? findFontItem.value : findFontItem) : this.fontSizeConfig.defaultValue
1469
+ this.fontSizeConfig.displayConfig.value = findFontItem ? (DapCommon.isObject(findFontItem) ? findFontItem.value : findFontItem) : this.fontSizeConfig.defaultValue
1371
1470
  //字号按钮禁用
1372
- this.fontSizeConfig.disabled = hasPreStyle || extraDisabled('fontSize')
1471
+ this.fontSizeConfig.disabled = value_hasPreInRange || extraDisabled('fontSize')
1373
1472
 
1374
1473
  //显示已选择字体
1375
1474
  const findFamilyItem = this.fontFamilyConfig.displayConfig.options.find(item => {
1376
- if (Dap.common.isObject(item)) {
1377
- return this.$parent.queryTextStyle('font-family', item.value, true)
1475
+ if (DapCommon.isObject(item)) {
1476
+ return queryTextStyle(this.$parent, 'font-family', item.value)
1378
1477
  }
1379
- return this.$parent.queryTextStyle('font-family', item, true)
1478
+ return queryTextStyle(this.$parent, 'font-family', item)
1380
1479
  })
1381
- this.fontFamilyConfig.displayConfig.value = findFamilyItem ? (Dap.common.isObject(findFamilyItem) ? findFamilyItem.value : findFamilyItem) : this.fontFamilyConfig.defaultValue
1480
+ this.fontFamilyConfig.displayConfig.value = findFamilyItem ? (DapCommon.isObject(findFamilyItem) ? findFamilyItem.value : findFamilyItem) : this.fontFamilyConfig.defaultValue
1382
1481
  //字体按钮禁用
1383
- this.fontFamilyConfig.disabled = hasPreStyle || extraDisabled('fontFamily')
1482
+ this.fontFamilyConfig.disabled = value_hasPreInRange || extraDisabled('fontFamily')
1384
1483
 
1385
1484
  //显示已设置行高
1386
1485
  const findHeightItem = this.lineHeightConfig.displayConfig.options.find(item => {
1387
1486
  let val = item
1388
- if (Dap.common.isObject(item)) {
1487
+ if (DapCommon.isObject(item)) {
1389
1488
  val = item.value
1390
1489
  }
1391
1490
  if (this.$parent.editor.range.anchor.isEqual(this.$parent.editor.range.focus)) {
1392
1491
  const block = this.$parent.editor.range.anchor.element.getBlock()
1393
1492
  return block.hasStyles() && block.styles['line-height'] == val
1394
1493
  }
1395
- return result.every(el => {
1494
+ return this.$parent.dataRangeCaches.list.every(el => {
1396
1495
  if (el.element.isBlock() || el.element.isInblock()) {
1397
1496
  return el.element.hasStyles() && el.element.styles['line-height'] == val
1398
1497
  }
@@ -1404,48 +1503,48 @@ export default {
1404
1503
  return block.hasStyles() && block.styles['line-height'] == val
1405
1504
  })
1406
1505
  })
1407
- this.lineHeightConfig.displayConfig.value = findHeightItem ? (Dap.common.isObject(findHeightItem) ? findHeightItem.value : findHeightItem) : this.lineHeightConfig.defaultValue
1506
+ this.lineHeightConfig.displayConfig.value = findHeightItem ? (DapCommon.isObject(findHeightItem) ? findHeightItem.value : findHeightItem) : this.lineHeightConfig.defaultValue
1408
1507
  //行高按钮禁用
1409
- this.lineHeightConfig.disabled = hasPreStyle || extraDisabled('lineHeight')
1508
+ this.lineHeightConfig.disabled = value_hasPreInRange || extraDisabled('lineHeight')
1410
1509
 
1411
1510
  //显示已选择的前景色
1412
1511
  const findForeColorItem = this.foreColorConfig.selectConfig.options.find(item => {
1413
- if (Dap.common.isObject(item)) {
1414
- return this.$parent.queryTextStyle('color', item.value, true)
1512
+ if (DapCommon.isObject(item)) {
1513
+ return queryTextStyle(this.$parent, 'color', item.value)
1415
1514
  }
1416
- return this.$parent.queryTextStyle('color', item, true)
1515
+ return queryTextStyle(this.$parent, 'color', item)
1417
1516
  })
1418
- this.foreColorConfig.value = findForeColorItem ? (Dap.common.isObject(findForeColorItem) ? findForeColorItem.value : findForeColorItem) : ''
1517
+ this.foreColorConfig.value = findForeColorItem ? (DapCommon.isObject(findForeColorItem) ? findForeColorItem.value : findForeColorItem) : ''
1419
1518
  //前景色按钮禁用
1420
- this.foreColorConfig.disabled = hasPreStyle || extraDisabled('foreColor')
1519
+ this.foreColorConfig.disabled = value_hasPreInRange || extraDisabled('foreColor')
1421
1520
 
1422
1521
  //显示已选择的背景色
1423
1522
  const findBackColorItem = this.backColorConfig.selectConfig.options.find(item => {
1424
- if (Dap.common.isObject(item)) {
1425
- return this.$parent.queryTextStyle('background-color', item.value, true)
1523
+ if (DapCommon.isObject(item)) {
1524
+ return queryTextStyle(this.$parent, 'background-color', item.value)
1426
1525
  }
1427
- return this.$parent.queryTextStyle('background-color', item, true)
1526
+ return queryTextStyle(this.$parent, 'background-color', item)
1428
1527
  })
1429
- this.backColorConfig.value = findBackColorItem ? (Dap.common.isObject(findBackColorItem) ? findBackColorItem.value : findBackColorItem) : ''
1528
+ this.backColorConfig.value = findBackColorItem ? (DapCommon.isObject(findBackColorItem) ? findBackColorItem.value : findBackColorItem) : ''
1430
1529
  //背景色按钮禁用
1431
- this.backColorConfig.disabled = hasPreStyle || extraDisabled('backColor')
1530
+ this.backColorConfig.disabled = value_hasPreInRange || extraDisabled('backColor')
1432
1531
 
1433
1532
  //链接按钮禁用
1434
- this.linkConfig.disabled = hasLink || hasPreStyle || extraDisabled('link')
1533
+ this.linkConfig.disabled = value_hasLinkInRange || value_hasPreInRange || extraDisabled('link')
1435
1534
 
1436
1535
  //插入图片按钮禁用
1437
- this.imageConfig.disabled = hasPreStyle || extraDisabled('image')
1536
+ this.imageConfig.disabled = value_hasPreInRange || extraDisabled('image')
1438
1537
 
1439
1538
  //插入视频按钮禁用
1440
- this.videoConfig.disabled = hasPreStyle || extraDisabled('video')
1539
+ this.videoConfig.disabled = value_hasPreInRange || extraDisabled('video')
1441
1540
 
1442
1541
  //表格按钮禁用
1443
- this.tableConfig.disabled = hasPreStyle || hasTable || hasQuote || extraDisabled('table')
1542
+ this.tableConfig.disabled = value_hasPreInRange || value_hasTableInRange || value_hasQuoteInRange || extraDisabled('table')
1444
1543
 
1445
1544
  //代码块按钮激活
1446
- this.codeBlockConfig.active = !!this.$parent.getCurrentParsedomElement('pre', true)
1545
+ this.codeBlockConfig.active = !!getCurrentParsedomElement(this.$parent, 'pre')
1447
1546
  //代码块按钮禁用
1448
- this.codeBlockConfig.disabled = hasTable || hasQuote || extraDisabled('codeBlock')
1547
+ this.codeBlockConfig.disabled = value_hasTableInRange || value_hasQuoteInRange || extraDisabled('codeBlock')
1449
1548
 
1450
1549
  //代码视图按钮激活
1451
1550
  this.sourceViewConfig.active = this.$parent.isSourceView