vue-editify 0.0.46 → 0.0.48

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.
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
  }
@@ -236,76 +236,71 @@ export default {
236
236
  removeScroll(this.$refs.content)
237
237
  },
238
238
  //工具条显示判断
239
- handleToolbar() {
239
+ handleToolbar(useCache = false) {
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', useCache)
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).flatIncludes.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) {
@@ -581,17 +576,29 @@ export default {
581
576
  this.$emit('insertparagraph', this.value)
582
577
  },
583
578
  //编辑器焦点更新
584
- handleRangeUpdate(range) {
579
+ handleRangeUpdate() {
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()
593
- }
594
- this.$emit('rangeupdate', this.value, range)
583
+ if (this.updateTimer) {
584
+ clearTimeout(this.updateTimer)
585
+ }
586
+ this.updateTimer = setTimeout(() => {
587
+ //如果使用工具条或者菜单栏
588
+ if (this.toolbarConfig.use || this.menuConfig.use) {
589
+ //先获取选区内的元素设置内部缓存
590
+ this.editor.getElementsByRange()
591
+ //如果使用工具条
592
+ if (this.toolbarConfig.use) {
593
+ this.handleToolbar(true)
594
+ }
595
+ //如果使用菜单栏
596
+ if (this.menuConfig.use) {
597
+ this.$refs.menu.handleRangeUpdate(true)
598
+ }
599
+ }
600
+ }, 200)
601
+ this.$emit('rangeupdate', this.value)
595
602
  },
596
603
  //编辑器复制
597
604
  handleCopy(text, html) {
@@ -606,7 +613,7 @@ export default {
606
613
  this.$emit('paste-text', data)
607
614
  },
608
615
  //编辑器粘贴html
609
- handlePasteHtml(elements, data) {
616
+ handlePasteHtml(elements) {
610
617
  const keepStyles = Object.assign(pasteKeepData.styles, this.pasteKeepStyles || {})
611
618
  const keepMarks = Object.assign(pasteKeepData.marks, this.pasteKeepMarks || {})
612
619
  //粘贴html时过滤元素的样式和属性
@@ -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(useCache).includes.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(useCache).includes
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(useCache).includes
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(useCache).includes
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], true)
927
934
  } else {
928
935
  let styles = {}
929
936
  styles[name] = value
930
- this.editor.setTextStyle(styles)
937
+ this.editor.setTextStyle(styles, true)
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], true)
953
960
  } else {
954
961
  let marks = {}
955
962
  marks[name] = value
956
- this.editor.setTextMark(marks)
963
+ this.editor.setTextMark(marks, true)
957
964
  }
958
965
  if (isRender) {
959
966
  this.editor.formatElementStack()
@@ -962,19 +969,20 @@ 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
+ //这里不能使用缓存,因为removeTextStyle会更新光标位置
985
+ this.editor.removeTextMark(null)
978
986
  if (isRender) {
979
987
  this.editor.formatElementStack()
980
988
  this.editor.domRender()
@@ -982,7 +990,7 @@ export default {
982
990
  }
983
991
  },
984
992
  //api:设置对齐方式,参数取值justify/left/right/center
985
- setAlign(value, isRender = true) {
993
+ setAlign(value, isRender = true, useCache = false) {
986
994
  if (this.disabled) {
987
995
  return
988
996
  }
@@ -1010,7 +1018,7 @@ export default {
1010
1018
  }
1011
1019
  }
1012
1020
  } else {
1013
- const result = this.editor.getElementsByRange(true, false)
1021
+ const result = this.editor.getElementsByRange(useCache).includes
1014
1022
  result.forEach(el => {
1015
1023
  if (el.element.isBlock() || el.element.isInblock()) {
1016
1024
  if (el.element.hasStyles()) {
@@ -1080,7 +1088,7 @@ export default {
1080
1088
  }
1081
1089
  },
1082
1090
  //api:插入引用
1083
- setQuote(isRender = true) {
1091
+ setQuote(isRender = true, useCache = false) {
1084
1092
  if (this.disabled) {
1085
1093
  return
1086
1094
  }
@@ -1099,7 +1107,7 @@ export default {
1099
1107
  //起点和终点不在一起
1100
1108
  else {
1101
1109
  let blocks = []
1102
- const result = this.editor.getElementsByRange(true, false)
1110
+ const result = this.editor.getElementsByRange(useCache).includes
1103
1111
  result.forEach(item => {
1104
1112
  const block = item.element.getBlock()
1105
1113
  const exist = blocks.some(el => block.isEqual(el))
@@ -1122,7 +1130,7 @@ export default {
1122
1130
  }
1123
1131
  },
1124
1132
  //api:设置行高
1125
- setLineHeight(value, isRender = true) {
1133
+ setLineHeight(value, isRender = true, useCache = false) {
1126
1134
  if (this.disabled) {
1127
1135
  return
1128
1136
  }
@@ -1150,7 +1158,7 @@ export default {
1150
1158
  }
1151
1159
  }
1152
1160
  } else {
1153
- const result = this.editor.getElementsByRange(true, false)
1161
+ const result = this.editor.getElementsByRange(useCache).includes
1154
1162
  result.forEach(el => {
1155
1163
  if (el.element.isBlock() || el.element.isInblock()) {
1156
1164
  if (el.element.hasStyles()) {
@@ -1190,7 +1198,7 @@ export default {
1190
1198
  }
1191
1199
  },
1192
1200
  //api:增加缩进
1193
- setIndentIncrease(isRender = true) {
1201
+ setIndentIncrease(isRender = true, useCache = false) {
1194
1202
  if (this.disabled) {
1195
1203
  return
1196
1204
  }
@@ -1225,7 +1233,7 @@ export default {
1225
1233
  fn(block)
1226
1234
  }
1227
1235
  } else {
1228
- const result = this.editor.getElementsByRange(true, false)
1236
+ const result = this.editor.getElementsByRange(useCache).includes
1229
1237
  result.forEach(item => {
1230
1238
  const block = item.element.getBlock()
1231
1239
  const inblock = item.element.getInblock()
@@ -1243,7 +1251,7 @@ export default {
1243
1251
  }
1244
1252
  },
1245
1253
  //api:减少缩进
1246
- setIndentDecrease(isRender = true) {
1254
+ setIndentDecrease(isRender = true, useCache = false) {
1247
1255
  if (this.disabled) {
1248
1256
  return
1249
1257
  }
@@ -1270,7 +1278,7 @@ export default {
1270
1278
  fn(block)
1271
1279
  }
1272
1280
  } else {
1273
- const result = this.editor.getElementsByRange(true, false)
1281
+ const result = this.editor.getElementsByRange(useCache).includes
1274
1282
  result.forEach(item => {
1275
1283
  const block = item.element.getBlock()
1276
1284
  const inblock = item.element.getInblock()
@@ -1288,7 +1296,7 @@ export default {
1288
1296
  }
1289
1297
  },
1290
1298
  //api:插入图片
1291
- insertImage(url, isRender = true) {
1299
+ insertImage(url, isRender = true, useCache = false) {
1292
1300
  if (this.disabled) {
1293
1301
  return
1294
1302
  }
@@ -1307,7 +1315,7 @@ export default {
1307
1315
  null,
1308
1316
  null
1309
1317
  )
1310
- this.editor.insertElement(image)
1318
+ this.editor.insertElement(image, true, useCache)
1311
1319
  if (isRender) {
1312
1320
  this.editor.formatElementStack()
1313
1321
  this.editor.domRender()
@@ -1315,7 +1323,7 @@ export default {
1315
1323
  }
1316
1324
  },
1317
1325
  //api:插入视频
1318
- insertVideo(url, isRender = true) {
1326
+ insertVideo(url, isRender = true, useCache = false) {
1319
1327
  if (this.disabled) {
1320
1328
  return
1321
1329
  }
@@ -1334,7 +1342,7 @@ export default {
1334
1342
  null,
1335
1343
  null
1336
1344
  )
1337
- this.editor.insertElement(video)
1345
+ this.editor.insertElement(video, true, useCache)
1338
1346
  const leftSpace = AlexElement.getSpaceElement()
1339
1347
  const rightSpace = AlexElement.getSpaceElement()
1340
1348
  this.editor.addElementAfter(rightSpace, video)
@@ -1348,20 +1356,20 @@ export default {
1348
1356
  }
1349
1357
  },
1350
1358
  //api:选区是否含有代码块样式
1351
- hasPreStyle() {
1359
+ hasPreStyle(useCache = false) {
1352
1360
  if (!this.editor.range) {
1353
1361
  return false
1354
1362
  }
1355
1363
  if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
1356
1364
  return this.editor.range.anchor.element.isPreStyle()
1357
1365
  }
1358
- const result = this.editor.getElementsByRange(true, false)
1366
+ const result = this.editor.getElementsByRange(useCache).includes
1359
1367
  return result.some(item => {
1360
1368
  return item.element.isPreStyle()
1361
1369
  })
1362
1370
  },
1363
1371
  //api:选区是否含有引用
1364
- hasQuote() {
1372
+ hasQuote(useCache = false) {
1365
1373
  if (!this.editor.range) {
1366
1374
  return false
1367
1375
  }
@@ -1369,7 +1377,7 @@ export default {
1369
1377
  const block = this.editor.range.anchor.element.getBlock()
1370
1378
  return block.parsedom == 'blockquote'
1371
1379
  }
1372
- const result = this.editor.getElementsByRange(true, false)
1380
+ const result = this.editor.getElementsByRange(useCache).includes
1373
1381
  return result.some(item => {
1374
1382
  if (item.element.isBlock()) {
1375
1383
  return item.element.parsedom == 'blockquote'
@@ -1380,7 +1388,7 @@ export default {
1380
1388
  })
1381
1389
  },
1382
1390
  //api:选区是否含有列表
1383
- hasList(ordered = false) {
1391
+ hasList(ordered = false, useCache = false) {
1384
1392
  if (!this.editor.range) {
1385
1393
  return false
1386
1394
  }
@@ -1388,7 +1396,7 @@ export default {
1388
1396
  const block = this.editor.range.anchor.element.getBlock()
1389
1397
  return blockIsList(block, ordered)
1390
1398
  }
1391
- const result = this.editor.getElementsByRange(true, false)
1399
+ const result = this.editor.getElementsByRange(useCache).includes
1392
1400
  return result.some(item => {
1393
1401
  if (item.element.isBlock()) {
1394
1402
  return blockIsList(item.element, ordered)
@@ -1399,14 +1407,14 @@ export default {
1399
1407
  })
1400
1408
  },
1401
1409
  //api:选区是否含有链接
1402
- hasLink() {
1410
+ hasLink(useCache = false) {
1403
1411
  if (!this.editor.range) {
1404
1412
  return false
1405
1413
  }
1406
1414
  if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
1407
1415
  return !!this.getParsedomElementByElement(this.editor.range.anchor.element, 'a')
1408
1416
  }
1409
- const result = this.editor.getElementsByRange(true, true).filter(item => {
1417
+ const result = this.editor.getElementsByRange(useCache).flatIncludes.filter(item => {
1410
1418
  return item.element.isText()
1411
1419
  })
1412
1420
  return result.some(item => {
@@ -1414,7 +1422,7 @@ export default {
1414
1422
  })
1415
1423
  },
1416
1424
  //api:选区是否含有表格
1417
- hasTable() {
1425
+ hasTable(useCache = false) {
1418
1426
  if (!this.editor.range) {
1419
1427
  return false
1420
1428
  }
@@ -1422,7 +1430,7 @@ export default {
1422
1430
  const block = this.editor.range.anchor.element.getBlock()
1423
1431
  return block.parsedom == 'table'
1424
1432
  }
1425
- const result = this.editor.getElementsByRange(true, false)
1433
+ const result = this.editor.getElementsByRange(useCache).includes
1426
1434
  return result.some(item => {
1427
1435
  if (item.element.isBlock()) {
1428
1436
  return item.element.parsedom == 'table'
@@ -1433,7 +1441,7 @@ export default {
1433
1441
  })
1434
1442
  },
1435
1443
  //api:选区是否含有任务列表
1436
- hasTask() {
1444
+ hasTask(useCache = false) {
1437
1445
  if (!this.editor.range) {
1438
1446
  return false
1439
1447
  }
@@ -1441,7 +1449,7 @@ export default {
1441
1449
  const block = this.editor.range.anchor.element.getBlock()
1442
1450
  return blockIsTask(block)
1443
1451
  }
1444
- const result = this.editor.getElementsByRange(true, false)
1452
+ const result = this.editor.getElementsByRange(useCache).includes
1445
1453
  return result.some(item => {
1446
1454
  if (item.element.isBlock()) {
1447
1455
  return blockIsTask(item.element)
@@ -1452,33 +1460,33 @@ export default {
1452
1460
  })
1453
1461
  },
1454
1462
  //api:选区是否含有图片
1455
- hasImage() {
1463
+ hasImage(useCache = false) {
1456
1464
  if (!this.editor.range) {
1457
1465
  return false
1458
1466
  }
1459
1467
  if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
1460
1468
  return this.editor.range.anchor.element.isClosed() && this.editor.range.anchor.element.parsedom == 'img'
1461
1469
  }
1462
- const result = this.editor.getElementsByRange(true, true)
1470
+ const result = this.editor.getElementsByRange(useCache).flatIncludes
1463
1471
  return result.some(item => {
1464
1472
  return item.element.isClosed() && item.element.parsedom == 'img'
1465
1473
  })
1466
1474
  },
1467
1475
  //api:选区是否含有视频
1468
- hasVideo() {
1476
+ hasVideo(useCache = false) {
1469
1477
  if (!this.editor.range) {
1470
1478
  return false
1471
1479
  }
1472
1480
  if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
1473
1481
  return this.editor.range.anchor.element.isClosed() && this.editor.range.anchor.element.parsedom == 'video'
1474
1482
  }
1475
- const result = this.editor.getElementsByRange(true, true)
1483
+ const result = this.editor.getElementsByRange(useCache).flatIncludes
1476
1484
  return result.some(item => {
1477
1485
  return item.element.isClosed() && item.element.parsedom == 'video'
1478
1486
  })
1479
1487
  },
1480
1488
  //api:选区是否全部在引用内
1481
- inQuote() {
1489
+ inQuote(useCache = false) {
1482
1490
  if (!this.editor.range) {
1483
1491
  return false
1484
1492
  }
@@ -1486,7 +1494,7 @@ export default {
1486
1494
  const block = this.editor.range.anchor.element.getBlock()
1487
1495
  return block.parsedom == 'blockquote'
1488
1496
  }
1489
- const result = this.editor.getElementsByRange(true, false)
1497
+ const result = this.editor.getElementsByRange(useCache).includes
1490
1498
  return result.every(item => {
1491
1499
  if (item.element.isBlock()) {
1492
1500
  return item.element.parsedom == 'blockquote'
@@ -1497,7 +1505,7 @@ export default {
1497
1505
  })
1498
1506
  },
1499
1507
  //api:选区是否全部在列表内
1500
- inList(ordered = false) {
1508
+ inList(ordered = false, useCache = false) {
1501
1509
  if (!this.editor.range) {
1502
1510
  return false
1503
1511
  }
@@ -1505,7 +1513,7 @@ export default {
1505
1513
  const block = this.editor.range.anchor.element.getBlock()
1506
1514
  return blockIsList(block, ordered)
1507
1515
  }
1508
- const result = this.editor.getElementsByRange(true, false)
1516
+ const result = this.editor.getElementsByRange(useCache).includes
1509
1517
  return result.every(item => {
1510
1518
  if (item.element.isBlock()) {
1511
1519
  return blockIsList(item.element, ordered)
@@ -1516,7 +1524,7 @@ export default {
1516
1524
  })
1517
1525
  },
1518
1526
  //api:选区是否全部在任务列表里
1519
- inTask() {
1527
+ inTask(useCache = false) {
1520
1528
  if (!this.editor.range) {
1521
1529
  return false
1522
1530
  }
@@ -1524,7 +1532,7 @@ export default {
1524
1532
  const block = this.editor.range.anchor.element.getBlock()
1525
1533
  return blockIsTask(block)
1526
1534
  }
1527
- const result = this.editor.getElementsByRange(true, false)
1535
+ const result = this.editor.getElementsByRange(useCache).includes
1528
1536
  return result.every(item => {
1529
1537
  if (item.element.isBlock()) {
1530
1538
  return blockIsTask(item.element)
@@ -1535,7 +1543,7 @@ export default {
1535
1543
  })
1536
1544
  },
1537
1545
  //api:创建一个空的表格
1538
- insertTable(rowLength, colLength, isRender = true) {
1546
+ insertTable(rowLength, colLength, isRender = true, useCache = false) {
1539
1547
  if (this.disabled) {
1540
1548
  return
1541
1549
  }
@@ -1555,7 +1563,7 @@ export default {
1555
1563
  }
1556
1564
  this.editor.addElementTo(row, tbody)
1557
1565
  }
1558
- this.editor.insertElement(table)
1566
+ this.editor.insertElement(table, true, useCache)
1559
1567
  //在表格后创建一个段落
1560
1568
  const paragraph = new AlexElement('block', AlexElement.BLOCK_NODE, null, null, null)
1561
1569
  const breakEl = new AlexElement('closed', 'br', null, null, null)
@@ -1570,14 +1578,14 @@ export default {
1570
1578
  }
1571
1579
  },
1572
1580
  //api:插入代码块
1573
- insertCodeBlock(isRender = true) {
1581
+ insertCodeBlock(isRender = true, useCache = false) {
1574
1582
  if (this.disabled) {
1575
1583
  return
1576
1584
  }
1577
1585
  if (!this.editor.range) {
1578
1586
  return
1579
1587
  }
1580
- const pre = this.getCurrentParsedomElement('pre')
1588
+ const pre = this.getCurrentParsedomElement('pre', useCache)
1581
1589
  if (pre) {
1582
1590
  let content = ''
1583
1591
  AlexElement.flatElements(pre.children)
@@ -1608,10 +1616,10 @@ export default {
1608
1616
  }
1609
1617
  //起点和终点不在一起
1610
1618
  else {
1611
- let result = this.editor.getElementsByRange(true, false)
1619
+ let result = this.editor.getElementsByRange(true).includes
1612
1620
  this.editor.range.anchor.moveToStart(result[0].element.getBlock())
1613
1621
  this.editor.range.focus.moveToEnd(result[result.length - 1].element.getBlock())
1614
- const res = this.editor.getElementsByRange(true, true).filter(el => el.element.isText())
1622
+ const res = this.editor.getElementsByRange(true).flatIncludes.filter(el => el.element.isText())
1615
1623
  const obj = {}
1616
1624
  res.forEach(el => {
1617
1625
  if (obj[el.element.getBlock().key]) {
@@ -1653,14 +1661,14 @@ export default {
1653
1661
  }
1654
1662
  },
1655
1663
  //api:插入文本
1656
- insertText(text, isRender = true) {
1664
+ insertText(text, isRender = true, useCache = false) {
1657
1665
  if (this.disabled) {
1658
1666
  return
1659
1667
  }
1660
1668
  if (!this.editor.range) {
1661
1669
  return
1662
1670
  }
1663
- this.editor.insertText(text)
1671
+ this.editor.insertText(text, useCache)
1664
1672
  if (isRender) {
1665
1673
  this.editor.formatElementStack()
1666
1674
  this.editor.domRender()
@@ -1668,7 +1676,7 @@ export default {
1668
1676
  }
1669
1677
  },
1670
1678
  //api:插入html
1671
- insertHtml(html, isRender = true) {
1679
+ insertHtml(html, isRender = true, useCache = false) {
1672
1680
  if (this.disabled) {
1673
1681
  return
1674
1682
  }
@@ -1677,7 +1685,7 @@ export default {
1677
1685
  }
1678
1686
  const elements = this.editor.parseHtml(html)
1679
1687
  for (let i = 0; i < elements.length; i++) {
1680
- this.editor.insertElement(elements[i], false)
1688
+ this.editor.insertElement(elements[i], false, i == 0 ? useCache : false)
1681
1689
  }
1682
1690
  if (isRender) {
1683
1691
  this.editor.formatElementStack()