vue-editify 0.0.45 → 0.0.47

Sign up to get free protection for your applications and to get access to all the features.
package/src/Editify.vue CHANGED
@@ -61,8 +61,8 @@ export default {
61
61
  //类型
62
62
  type: 'text'
63
63
  },
64
- //toolbar显示延时器
65
- toolbarTime: null,
64
+ //rangeUpdate更新延时器
65
+ updateTimer: null,
66
66
  //菜单栏是否可以使用标识
67
67
  canUseMenu: false
68
68
  }
@@ -240,72 +240,67 @@ export default {
240
240
  if (this.disabled || this.isSourceView) {
241
241
  return
242
242
  }
243
- if (this.toolbarTime) {
244
- clearTimeout(this.toolbarTime)
245
- }
246
- this.toolbarTime = setTimeout(() => {
247
- this.hideToolbar()
248
- this.$nextTick(() => {
249
- const table = this.getCurrentParsedomElement('table')
250
- const pre = this.getCurrentParsedomElement('pre')
251
- const link = this.getCurrentParsedomElement('a')
252
- const image = this.getCurrentParsedomElement('img')
253
- const video = this.getCurrentParsedomElement('video')
254
- if (link) {
255
- this.toolbarOptions.type = 'link'
256
- this.toolbarOptions.node = `[data-editify-uid="${this.uid}"] [data-editify-element="${link.key}"]`
257
- if (this.toolbarOptions.show) {
258
- this.$refs.toolbar.$refs.layer.setPosition()
259
- } else {
260
- this.toolbarOptions.show = true
261
- }
262
- } else if (image) {
263
- this.toolbarOptions.type = 'image'
264
- this.toolbarOptions.node = `[data-editify-uid="${this.uid}"] [data-editify-element="${image.key}"]`
265
- if (this.toolbarOptions.show) {
266
- this.$refs.toolbar.$refs.layer.setPosition()
267
- } else {
268
- this.toolbarOptions.show = true
269
- }
270
- } else if (video) {
271
- this.toolbarOptions.type = 'video'
272
- this.toolbarOptions.node = `[data-editify-uid="${this.uid}"] [data-editify-element="${video.key}"]`
273
- if (this.toolbarOptions.show) {
274
- this.$refs.toolbar.$refs.layer.setPosition()
275
- } else {
276
- this.toolbarOptions.show = true
277
- }
278
- } else if (table) {
279
- this.toolbarOptions.type = 'table'
280
- this.toolbarOptions.node = `[data-editify-uid="${this.uid}"] [data-editify-element="${table.key}"]`
281
- if (this.toolbarOptions.show) {
282
- this.$refs.toolbar.$refs.layer.setPosition()
283
- } else {
284
- this.toolbarOptions.show = true
285
- }
286
- } else if (pre) {
287
- this.toolbarOptions.type = 'codeBlock'
288
- this.toolbarOptions.node = `[data-editify-uid="${this.uid}"] [data-editify-element="${pre.key}"]`
243
+ this.hideToolbar()
244
+ this.$nextTick(() => {
245
+ const table = this.getCurrentParsedomElement('table', true)
246
+ const pre = this.getCurrentParsedomElement('pre', true)
247
+ const link = this.getCurrentParsedomElement('a', true)
248
+ const image = this.getCurrentParsedomElement('img', true)
249
+ const video = this.getCurrentParsedomElement('video', true)
250
+ if (link) {
251
+ this.toolbarOptions.type = 'link'
252
+ this.toolbarOptions.node = `[data-editify-uid="${this.uid}"] [data-editify-element="${link.key}"]`
253
+ if (this.toolbarOptions.show) {
254
+ this.$refs.toolbar.$refs.layer.setPosition()
255
+ } else {
256
+ this.toolbarOptions.show = true
257
+ }
258
+ } else if (image) {
259
+ this.toolbarOptions.type = 'image'
260
+ this.toolbarOptions.node = `[data-editify-uid="${this.uid}"] [data-editify-element="${image.key}"]`
261
+ if (this.toolbarOptions.show) {
262
+ this.$refs.toolbar.$refs.layer.setPosition()
263
+ } else {
264
+ this.toolbarOptions.show = true
265
+ }
266
+ } else if (video) {
267
+ this.toolbarOptions.type = 'video'
268
+ this.toolbarOptions.node = `[data-editify-uid="${this.uid}"] [data-editify-element="${video.key}"]`
269
+ if (this.toolbarOptions.show) {
270
+ this.$refs.toolbar.$refs.layer.setPosition()
271
+ } else {
272
+ this.toolbarOptions.show = true
273
+ }
274
+ } else if (table) {
275
+ this.toolbarOptions.type = 'table'
276
+ this.toolbarOptions.node = `[data-editify-uid="${this.uid}"] [data-editify-element="${table.key}"]`
277
+ if (this.toolbarOptions.show) {
278
+ this.$refs.toolbar.$refs.layer.setPosition()
279
+ } else {
280
+ this.toolbarOptions.show = true
281
+ }
282
+ } else if (pre) {
283
+ this.toolbarOptions.type = 'codeBlock'
284
+ this.toolbarOptions.node = `[data-editify-uid="${this.uid}"] [data-editify-element="${pre.key}"]`
285
+ if (this.toolbarOptions.show) {
286
+ this.$refs.toolbar.$refs.layer.setPosition()
287
+ } else {
288
+ this.toolbarOptions.show = true
289
+ }
290
+ } else {
291
+ const result = this.editor.getElementsByRange(true, true, true).filter(item => {
292
+ return item.element.isText()
293
+ })
294
+ if (result.length && !this.hasTable(true) && !this.hasPreStyle(true) && !this.hasLink(true) && !this.hasImage(true) && !this.hasVideo(true)) {
295
+ this.toolbarOptions.type = 'text'
289
296
  if (this.toolbarOptions.show) {
290
297
  this.$refs.toolbar.$refs.layer.setPosition()
291
298
  } else {
292
299
  this.toolbarOptions.show = true
293
300
  }
294
- } else {
295
- const result = this.editor.getElementsByRange(true, true).filter(item => {
296
- return item.element.isText()
297
- })
298
- if (result.length && !this.hasTable() && !this.hasPreStyle() && !this.hasLink() && !this.hasImage() && !this.hasVideo()) {
299
- this.toolbarOptions.type = 'text'
300
- if (this.toolbarOptions.show) {
301
- this.$refs.toolbar.$refs.layer.setPosition()
302
- } else {
303
- this.toolbarOptions.show = true
304
- }
305
- }
306
301
  }
307
- })
308
- }, 200)
302
+ }
303
+ })
309
304
  },
310
305
  //重新定义编辑器合并元素的逻辑
311
306
  handleCustomMerge(ele, preEle) {
@@ -585,12 +580,24 @@ export default {
585
580
  if (this.disabled) {
586
581
  return
587
582
  }
588
- if (this.toolbarConfig.use) {
589
- this.handleToolbar()
590
- }
591
- if (this.menuConfig.use) {
592
- this.$refs.menu.handleRangeUpdate()
583
+ if (this.updateTimer) {
584
+ clearTimeout(this.updateTimer)
593
585
  }
586
+ this.updateTimer = setTimeout(() => {
587
+ //如果使用菜单栏或者工具条事先调用两次作数据缓存
588
+ if (this.toolbarConfig.use || this.menuConfig.use) {
589
+ this.editor.getElementsByRange(true, false)
590
+ this.editor.getElementsByRange(true, true)
591
+ }
592
+ //如果使用工具条
593
+ if (this.toolbarConfig.use) {
594
+ this.handleToolbar()
595
+ }
596
+ //如果使用菜单栏
597
+ if (this.menuConfig.use) {
598
+ this.$refs.menu.handleRangeUpdate()
599
+ }
600
+ }, 200)
594
601
  this.$emit('rangeupdate', this.value, range)
595
602
  },
596
603
  //编辑器复制
@@ -710,7 +717,7 @@ export default {
710
717
  return this.getParsedomElementByElement(element.parent, parsedom)
711
718
  },
712
719
  //api:获取光标是否在指定标签元素下,如果是返回该标签元素,否则返回null
713
- getCurrentParsedomElement(parsedom) {
720
+ getCurrentParsedomElement(parsedom, useCache = false) {
714
721
  if (this.disabled) {
715
722
  return null
716
723
  }
@@ -720,7 +727,7 @@ export default {
720
727
  if (this.editor.range.anchor.element.isEqual(this.editor.range.focus.element)) {
721
728
  return this.getParsedomElementByElement(this.editor.range.anchor.element, parsedom)
722
729
  }
723
- const arr = this.editor.getElementsByRange(true, false).map(item => {
730
+ const arr = this.editor.getElementsByRange(true, false, useCache).map(item => {
724
731
  return this.getParsedomElementByElement(item.element, parsedom)
725
732
  })
726
733
  let hasNull = arr.some(el => {
@@ -749,14 +756,14 @@ export default {
749
756
  return null
750
757
  },
751
758
  //api:删除光标所在的指定标签元素
752
- deleteByParsedom(parsedom, isRender = true) {
759
+ deleteByParsedom(parsedom, isRender = true, useCache = false) {
753
760
  if (this.disabled) {
754
761
  return
755
762
  }
756
763
  if (!this.editor.range) {
757
764
  return
758
765
  }
759
- const element = this.getCurrentParsedomElement(parsedom)
766
+ const element = this.getCurrentParsedomElement(parsedom, useCache)
760
767
  if (element) {
761
768
  element.toEmpty()
762
769
  if (isRender) {
@@ -767,14 +774,14 @@ export default {
767
774
  }
768
775
  },
769
776
  //api:当光标在链接上时可以移除链接
770
- removeLink(isRender = true) {
777
+ removeLink(isRender = true, useCache = false) {
771
778
  if (this.disabled) {
772
779
  return
773
780
  }
774
781
  if (!this.editor.range) {
775
782
  return
776
783
  }
777
- const link = this.getCurrentParsedomElement('a')
784
+ const link = this.getCurrentParsedomElement('a', useCache)
778
785
  if (link) {
779
786
  link.parsedom = AlexElement.TEXT_NODE
780
787
  delete link.marks.target
@@ -787,7 +794,7 @@ export default {
787
794
  }
788
795
  },
789
796
  //api:设置标题
790
- setHeading(parsedom, isRender = true) {
797
+ setHeading(parsedom, isRender = true, useCache = false) {
791
798
  if (this.disabled) {
792
799
  return
793
800
  }
@@ -807,7 +814,7 @@ export default {
807
814
  //设置标题
808
815
  block.parsedom = parsedom
809
816
  } else {
810
- const result = this.editor.getElementsByRange(true, false)
817
+ const result = this.editor.getElementsByRange(true, false, useCache)
811
818
  result.forEach(el => {
812
819
  if (el.element.isBlock()) {
813
820
  blockToParagraph(el.element)
@@ -826,7 +833,7 @@ export default {
826
833
  }
827
834
  },
828
835
  //api:插入有序列表 ordered为true表示有序列表
829
- setList(ordered, isRender = true) {
836
+ setList(ordered, isRender = true, useCache = false) {
830
837
  if (this.disabled) {
831
838
  return
832
839
  }
@@ -846,7 +853,7 @@ export default {
846
853
  //起点和终点不在一起
847
854
  else {
848
855
  let blocks = []
849
- const result = this.editor.getElementsByRange(true, false)
856
+ const result = this.editor.getElementsByRange(true, false, useCache)
850
857
  result.forEach(item => {
851
858
  const block = item.element.getBlock()
852
859
  const exist = blocks.some(el => block.isEqual(el))
@@ -870,7 +877,7 @@ export default {
870
877
  }
871
878
  },
872
879
  //api:插入任务列表
873
- setTask(isRender = true) {
880
+ setTask(isRender = true, useCache = false) {
874
881
  if (this.disabled) {
875
882
  return
876
883
  }
@@ -890,7 +897,7 @@ export default {
890
897
  //起点和终点不在一起
891
898
  else {
892
899
  let blocks = []
893
- const result = this.editor.getElementsByRange(true, false)
900
+ const result = this.editor.getElementsByRange(true, false, useCache)
894
901
  result.forEach(item => {
895
902
  const block = item.element.getBlock()
896
903
  const exist = blocks.some(el => block.isEqual(el))
@@ -914,20 +921,20 @@ export default {
914
921
  }
915
922
  },
916
923
  //api:设置样式
917
- setTextStyle(name, value, isRender = true) {
924
+ setTextStyle(name, value, isRender = true, useCache = false) {
918
925
  if (this.disabled) {
919
926
  return
920
927
  }
921
928
  if (!this.editor.range) {
922
929
  return
923
930
  }
924
- const active = this.queryTextStyle(name, value)
931
+ const active = this.queryTextStyle(name, value, useCache)
925
932
  if (active) {
926
- this.editor.removeTextStyle([name])
933
+ this.editor.removeTextStyle([name], useCache)
927
934
  } else {
928
935
  let styles = {}
929
936
  styles[name] = value
930
- this.editor.setTextStyle(styles)
937
+ this.editor.setTextStyle(styles, useCache)
931
938
  }
932
939
  if (isRender) {
933
940
  this.editor.formatElementStack()
@@ -936,24 +943,24 @@ export default {
936
943
  }
937
944
  },
938
945
  //api:查询是否具有某个样式
939
- queryTextStyle(name, value, useCache) {
946
+ queryTextStyle(name, value, useCache = false) {
940
947
  return this.editor.queryTextStyle(name, value, useCache)
941
948
  },
942
949
  //api:设置标记
943
- setTextMark(name, value, isRender = true) {
950
+ setTextMark(name, value, isRender = true, useCache = false) {
944
951
  if (this.disabled) {
945
952
  return
946
953
  }
947
954
  if (!this.editor.range) {
948
955
  return
949
956
  }
950
- const active = this.queryTextMark(name, value)
957
+ const active = this.queryTextMark(name, value, useCache)
951
958
  if (active) {
952
- this.editor.removeTextMark([name])
959
+ this.editor.removeTextMark([name], useCache)
953
960
  } else {
954
961
  let marks = {}
955
962
  marks[name] = value
956
- this.editor.setTextMark(marks)
963
+ this.editor.setTextMark(marks, useCache)
957
964
  }
958
965
  if (isRender) {
959
966
  this.editor.formatElementStack()
@@ -962,19 +969,19 @@ export default {
962
969
  }
963
970
  },
964
971
  //api:查询是否具有某个标记
965
- queryTextMark(name, value, useCache) {
972
+ queryTextMark(name, value, useCache = false) {
966
973
  return this.editor.queryTextMark(name, value, useCache)
967
974
  },
968
975
  //api:清除文本样式和标记
969
- formatText(isRender = true) {
976
+ formatText(isRender = true, useCache = false) {
970
977
  if (this.disabled) {
971
978
  return
972
979
  }
973
980
  if (!this.editor.range) {
974
981
  return
975
982
  }
976
- this.editor.removeTextStyle()
977
- this.editor.removeTextMark()
983
+ this.editor.removeTextStyle(null, useCache)
984
+ this.editor.removeTextMark(null, useCache)
978
985
  if (isRender) {
979
986
  this.editor.formatElementStack()
980
987
  this.editor.domRender()
@@ -982,7 +989,7 @@ export default {
982
989
  }
983
990
  },
984
991
  //api:设置对齐方式,参数取值justify/left/right/center
985
- setAlign(value, isRender = true) {
992
+ setAlign(value, isRender = true, useCache = false) {
986
993
  if (this.disabled) {
987
994
  return
988
995
  }
@@ -1010,7 +1017,7 @@ export default {
1010
1017
  }
1011
1018
  }
1012
1019
  } else {
1013
- const result = this.editor.getElementsByRange(true, false)
1020
+ const result = this.editor.getElementsByRange(true, false, useCache)
1014
1021
  result.forEach(el => {
1015
1022
  if (el.element.isBlock() || el.element.isInblock()) {
1016
1023
  if (el.element.hasStyles()) {
@@ -1080,7 +1087,7 @@ export default {
1080
1087
  }
1081
1088
  },
1082
1089
  //api:插入引用
1083
- setQuote(isRender = true) {
1090
+ setQuote(isRender = true, useCache = false) {
1084
1091
  if (this.disabled) {
1085
1092
  return
1086
1093
  }
@@ -1099,7 +1106,7 @@ export default {
1099
1106
  //起点和终点不在一起
1100
1107
  else {
1101
1108
  let blocks = []
1102
- const result = this.editor.getElementsByRange(true, false)
1109
+ const result = this.editor.getElementsByRange(true, false, useCache)
1103
1110
  result.forEach(item => {
1104
1111
  const block = item.element.getBlock()
1105
1112
  const exist = blocks.some(el => block.isEqual(el))
@@ -1122,7 +1129,7 @@ export default {
1122
1129
  }
1123
1130
  },
1124
1131
  //api:设置行高
1125
- setLineHeight(value, isRender = true) {
1132
+ setLineHeight(value, isRender = true, useCache = false) {
1126
1133
  if (this.disabled) {
1127
1134
  return
1128
1135
  }
@@ -1150,7 +1157,7 @@ export default {
1150
1157
  }
1151
1158
  }
1152
1159
  } else {
1153
- const result = this.editor.getElementsByRange(true, false)
1160
+ const result = this.editor.getElementsByRange(true, false, useCache)
1154
1161
  result.forEach(el => {
1155
1162
  if (el.element.isBlock() || el.element.isInblock()) {
1156
1163
  if (el.element.hasStyles()) {
@@ -1190,7 +1197,7 @@ export default {
1190
1197
  }
1191
1198
  },
1192
1199
  //api:增加缩进
1193
- setIndentIncrease(isRender = true) {
1200
+ setIndentIncrease(isRender = true, useCache = false) {
1194
1201
  if (this.disabled) {
1195
1202
  return
1196
1203
  }
@@ -1225,7 +1232,7 @@ export default {
1225
1232
  fn(block)
1226
1233
  }
1227
1234
  } else {
1228
- const result = this.editor.getElementsByRange(true, false)
1235
+ const result = this.editor.getElementsByRange(true, false, useCache)
1229
1236
  result.forEach(item => {
1230
1237
  const block = item.element.getBlock()
1231
1238
  const inblock = item.element.getInblock()
@@ -1243,7 +1250,7 @@ export default {
1243
1250
  }
1244
1251
  },
1245
1252
  //api:减少缩进
1246
- setIndentDecrease(isRender = true) {
1253
+ setIndentDecrease(isRender = true, useCache = false) {
1247
1254
  if (this.disabled) {
1248
1255
  return
1249
1256
  }
@@ -1270,7 +1277,7 @@ export default {
1270
1277
  fn(block)
1271
1278
  }
1272
1279
  } else {
1273
- const result = this.editor.getElementsByRange(true, false)
1280
+ const result = this.editor.getElementsByRange(true, false, useCache)
1274
1281
  result.forEach(item => {
1275
1282
  const block = item.element.getBlock()
1276
1283
  const inblock = item.element.getInblock()
@@ -1348,20 +1355,20 @@ export default {
1348
1355
  }
1349
1356
  },
1350
1357
  //api:选区是否含有代码块样式
1351
- hasPreStyle() {
1358
+ hasPreStyle(useCache = false) {
1352
1359
  if (!this.editor.range) {
1353
1360
  return false
1354
1361
  }
1355
1362
  if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
1356
1363
  return this.editor.range.anchor.element.isPreStyle()
1357
1364
  }
1358
- const result = this.editor.getElementsByRange(true, false)
1365
+ const result = this.editor.getElementsByRange(true, false, useCache)
1359
1366
  return result.some(item => {
1360
1367
  return item.element.isPreStyle()
1361
1368
  })
1362
1369
  },
1363
1370
  //api:选区是否含有引用
1364
- hasQuote() {
1371
+ hasQuote(useCache = false) {
1365
1372
  if (!this.editor.range) {
1366
1373
  return false
1367
1374
  }
@@ -1369,7 +1376,7 @@ export default {
1369
1376
  const block = this.editor.range.anchor.element.getBlock()
1370
1377
  return block.parsedom == 'blockquote'
1371
1378
  }
1372
- const result = this.editor.getElementsByRange(true, false)
1379
+ const result = this.editor.getElementsByRange(true, false, useCache)
1373
1380
  return result.some(item => {
1374
1381
  if (item.element.isBlock()) {
1375
1382
  return item.element.parsedom == 'blockquote'
@@ -1380,7 +1387,7 @@ export default {
1380
1387
  })
1381
1388
  },
1382
1389
  //api:选区是否含有列表
1383
- hasList(ordered = false) {
1390
+ hasList(ordered = false, useCache = false) {
1384
1391
  if (!this.editor.range) {
1385
1392
  return false
1386
1393
  }
@@ -1388,7 +1395,7 @@ export default {
1388
1395
  const block = this.editor.range.anchor.element.getBlock()
1389
1396
  return blockIsList(block, ordered)
1390
1397
  }
1391
- const result = this.editor.getElementsByRange(true, false)
1398
+ const result = this.editor.getElementsByRange(true, false, useCache)
1392
1399
  return result.some(item => {
1393
1400
  if (item.element.isBlock()) {
1394
1401
  return blockIsList(item.element, ordered)
@@ -1399,14 +1406,14 @@ export default {
1399
1406
  })
1400
1407
  },
1401
1408
  //api:选区是否含有链接
1402
- hasLink() {
1409
+ hasLink(useCache = false) {
1403
1410
  if (!this.editor.range) {
1404
1411
  return false
1405
1412
  }
1406
1413
  if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
1407
1414
  return !!this.getParsedomElementByElement(this.editor.range.anchor.element, 'a')
1408
1415
  }
1409
- const result = this.editor.getElementsByRange(true, true).filter(item => {
1416
+ const result = this.editor.getElementsByRange(true, true, useCache).filter(item => {
1410
1417
  return item.element.isText()
1411
1418
  })
1412
1419
  return result.some(item => {
@@ -1414,7 +1421,7 @@ export default {
1414
1421
  })
1415
1422
  },
1416
1423
  //api:选区是否含有表格
1417
- hasTable() {
1424
+ hasTable(useCache = false) {
1418
1425
  if (!this.editor.range) {
1419
1426
  return false
1420
1427
  }
@@ -1422,7 +1429,7 @@ export default {
1422
1429
  const block = this.editor.range.anchor.element.getBlock()
1423
1430
  return block.parsedom == 'table'
1424
1431
  }
1425
- const result = this.editor.getElementsByRange(true, false)
1432
+ const result = this.editor.getElementsByRange(true, false, useCache)
1426
1433
  return result.some(item => {
1427
1434
  if (item.element.isBlock()) {
1428
1435
  return item.element.parsedom == 'table'
@@ -1433,7 +1440,7 @@ export default {
1433
1440
  })
1434
1441
  },
1435
1442
  //api:选区是否含有任务列表
1436
- hasTask() {
1443
+ hasTask(useCache = false) {
1437
1444
  if (!this.editor.range) {
1438
1445
  return false
1439
1446
  }
@@ -1441,7 +1448,7 @@ export default {
1441
1448
  const block = this.editor.range.anchor.element.getBlock()
1442
1449
  return blockIsTask(block)
1443
1450
  }
1444
- const result = this.editor.getElementsByRange(true, false)
1451
+ const result = this.editor.getElementsByRange(true, false, useCache)
1445
1452
  return result.some(item => {
1446
1453
  if (item.element.isBlock()) {
1447
1454
  return blockIsTask(item.element)
@@ -1452,33 +1459,33 @@ export default {
1452
1459
  })
1453
1460
  },
1454
1461
  //api:选区是否含有图片
1455
- hasImage() {
1462
+ hasImage(useCache = false) {
1456
1463
  if (!this.editor.range) {
1457
1464
  return false
1458
1465
  }
1459
1466
  if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
1460
1467
  return this.editor.range.anchor.element.isClosed() && this.editor.range.anchor.element.parsedom == 'img'
1461
1468
  }
1462
- const result = this.editor.getElementsByRange(true, true)
1469
+ const result = this.editor.getElementsByRange(true, true, useCache)
1463
1470
  return result.some(item => {
1464
1471
  return item.element.isClosed() && item.element.parsedom == 'img'
1465
1472
  })
1466
1473
  },
1467
1474
  //api:选区是否含有视频
1468
- hasVideo() {
1475
+ hasVideo(useCache = false) {
1469
1476
  if (!this.editor.range) {
1470
1477
  return false
1471
1478
  }
1472
1479
  if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
1473
1480
  return this.editor.range.anchor.element.isClosed() && this.editor.range.anchor.element.parsedom == 'video'
1474
1481
  }
1475
- const result = this.editor.getElementsByRange(true, true)
1482
+ const result = this.editor.getElementsByRange(true, true, useCache)
1476
1483
  return result.some(item => {
1477
1484
  return item.element.isClosed() && item.element.parsedom == 'video'
1478
1485
  })
1479
1486
  },
1480
1487
  //api:选区是否全部在引用内
1481
- inQuote() {
1488
+ inQuote(useCache = false) {
1482
1489
  if (!this.editor.range) {
1483
1490
  return false
1484
1491
  }
@@ -1486,7 +1493,7 @@ export default {
1486
1493
  const block = this.editor.range.anchor.element.getBlock()
1487
1494
  return block.parsedom == 'blockquote'
1488
1495
  }
1489
- const result = this.editor.getElementsByRange(true, false)
1496
+ const result = this.editor.getElementsByRange(true, false, useCache)
1490
1497
  return result.every(item => {
1491
1498
  if (item.element.isBlock()) {
1492
1499
  return item.element.parsedom == 'blockquote'
@@ -1497,7 +1504,7 @@ export default {
1497
1504
  })
1498
1505
  },
1499
1506
  //api:选区是否全部在列表内
1500
- inList(ordered = false) {
1507
+ inList(ordered = false, useCache = false) {
1501
1508
  if (!this.editor.range) {
1502
1509
  return false
1503
1510
  }
@@ -1505,7 +1512,7 @@ export default {
1505
1512
  const block = this.editor.range.anchor.element.getBlock()
1506
1513
  return blockIsList(block, ordered)
1507
1514
  }
1508
- const result = this.editor.getElementsByRange(true, false)
1515
+ const result = this.editor.getElementsByRange(true, false, useCache)
1509
1516
  return result.every(item => {
1510
1517
  if (item.element.isBlock()) {
1511
1518
  return blockIsList(item.element, ordered)
@@ -1516,7 +1523,7 @@ export default {
1516
1523
  })
1517
1524
  },
1518
1525
  //api:选区是否全部在任务列表里
1519
- inTask() {
1526
+ inTask(useCache = false) {
1520
1527
  if (!this.editor.range) {
1521
1528
  return false
1522
1529
  }
@@ -1524,7 +1531,7 @@ export default {
1524
1531
  const block = this.editor.range.anchor.element.getBlock()
1525
1532
  return blockIsTask(block)
1526
1533
  }
1527
- const result = this.editor.getElementsByRange(true, false)
1534
+ const result = this.editor.getElementsByRange(true, false, useCache)
1528
1535
  return result.every(item => {
1529
1536
  if (item.element.isBlock()) {
1530
1537
  return blockIsTask(item.element)
@@ -1570,14 +1577,14 @@ export default {
1570
1577
  }
1571
1578
  },
1572
1579
  //api:插入代码块
1573
- insertCodeBlock(isRender = true) {
1580
+ insertCodeBlock(isRender = true, useCache = false) {
1574
1581
  if (this.disabled) {
1575
1582
  return
1576
1583
  }
1577
1584
  if (!this.editor.range) {
1578
1585
  return
1579
1586
  }
1580
- const pre = this.getCurrentParsedomElement('pre')
1587
+ const pre = this.getCurrentParsedomElement('pre', useCache)
1581
1588
  if (pre) {
1582
1589
  let content = ''
1583
1590
  AlexElement.flatElements(pre.children)
@@ -1608,10 +1615,10 @@ export default {
1608
1615
  }
1609
1616
  //起点和终点不在一起
1610
1617
  else {
1611
- let result = this.editor.getElementsByRange(true, false)
1618
+ let result = this.editor.getElementsByRange(true, false, useCache)
1612
1619
  this.editor.range.anchor.moveToStart(result[0].element.getBlock())
1613
1620
  this.editor.range.focus.moveToEnd(result[result.length - 1].element.getBlock())
1614
- const res = this.editor.getElementsByRange(true, true).filter(el => el.element.isText())
1621
+ const res = this.editor.getElementsByRange(true, true, useCache).filter(el => el.element.isText())
1615
1622
  const obj = {}
1616
1623
  res.forEach(el => {
1617
1624
  if (obj[el.element.getBlock().key]) {