vue-editify 0.1.40 → 0.1.41

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/lib/editify.es.js CHANGED
@@ -17924,21 +17924,6 @@ const cloneData = function(data2) {
17924
17924
  }
17925
17925
  return data2;
17926
17926
  };
17927
- const getColNumbers = function(row) {
17928
- const children = row.children || [];
17929
- let num = 0;
17930
- children.forEach((td) => {
17931
- if (td.hasMarks() && td.marks.hasOwnProperty("colspan")) {
17932
- const span = Number(td.marks.colspan);
17933
- if (!isNaN(span)) {
17934
- num += span;
17935
- }
17936
- } else {
17937
- num += 1;
17938
- }
17939
- });
17940
- return num;
17941
- };
17942
17927
  const getButtonOptionsConfig = function(editTrans) {
17943
17928
  return {
17944
17929
  //标题配置
@@ -18372,7 +18357,7 @@ const getToolbarConfig = function(editTrans, editLocale) {
18372
18357
  rightBorder: false
18373
18358
  }
18374
18359
  },
18375
- //(只对文本工具条中的按钮生效)添加额外的按钮禁用判定,回调参数为name,this指向组件实例
18360
+ //(只对文本工具条中的按钮生效)添加额外的按钮禁用判定,回调参数为name
18376
18361
  extraDisabled: null
18377
18362
  };
18378
18363
  };
@@ -18384,7 +18369,7 @@ const getMenuConfig = function(editTrans, editLocale) {
18384
18369
  tooltip: true,
18385
18370
  //菜单栏显示模式,支持default/inner/fixed
18386
18371
  mode: "default",
18387
- //添加额外的按钮禁用判定,回调参数为name,this指向组件实例
18372
+ //添加额外的按钮禁用判定,回调参数为name
18388
18373
  extraDisabled: null,
18389
18374
  //菜单栏的样式自定义
18390
18375
  style: null,
@@ -18771,45 +18756,60 @@ const getMenuConfig = function(editTrans, editLocale) {
18771
18756
  extends: {}
18772
18757
  };
18773
18758
  };
18774
- const getParsedomElementByElement = (element2, parsedom) => {
18759
+ const elementIsMatch = (element2, config) => {
18760
+ if (element2.isText()) {
18761
+ return false;
18762
+ }
18763
+ let isMatch = true;
18764
+ if (config.parsedom && config.parsedom != element2.parsedom) {
18765
+ isMatch = false;
18766
+ }
18767
+ if (config.marks) {
18768
+ const hasMarks = Object.keys(config.marks).every((key) => {
18769
+ return element2.hasMarks() && element2.marks[key] && element2.marks[key] == config.marks[key];
18770
+ });
18771
+ if (!hasMarks) {
18772
+ isMatch = false;
18773
+ }
18774
+ }
18775
+ if (config.styles) {
18776
+ const hasStyles = Object.keys(config.styles).every((key) => {
18777
+ return element2.hasStyles() && element2.styles[key] && element2.styles[key] == config.styles[key];
18778
+ });
18779
+ if (!hasStyles) {
18780
+ isMatch = false;
18781
+ }
18782
+ }
18783
+ return isMatch;
18784
+ };
18785
+ const getMatchElementByElement = (element2, config) => {
18775
18786
  if (element2.isBlock()) {
18776
- return element2.parsedom == parsedom ? element2 : null;
18787
+ return elementIsMatch(element2, config) ? element2 : null;
18777
18788
  }
18778
- if (!element2.isText() && element2.parsedom == parsedom) {
18789
+ if (elementIsMatch(element2, config)) {
18779
18790
  return element2;
18780
18791
  }
18781
- return getParsedomElementByElement(element2.parent, parsedom);
18792
+ return getMatchElementByElement(element2.parent, config);
18782
18793
  };
18783
- const getCurrentParsedomElement = (editor, dataRangeCaches, parsedom) => {
18794
+ const getMatchElementsByRange = (editor, dataRangeCaches, config) => {
18795
+ let elements = [];
18784
18796
  if (!editor.range) {
18785
- return null;
18797
+ return elements;
18786
18798
  }
18787
18799
  if (editor.range.anchor.element.isEqual(editor.range.focus.element)) {
18788
- return getParsedomElementByElement(editor.range.anchor.element, parsedom);
18789
- }
18790
- const arr = dataRangeCaches.list.map((item) => {
18791
- return getParsedomElementByElement(item.element, parsedom);
18792
- });
18793
- let hasNull = arr.some((el) => {
18794
- return el == null;
18795
- });
18796
- if (hasNull) {
18797
- return null;
18798
- }
18799
- if (arr.length == 1) {
18800
- return arr[0];
18801
- }
18802
- let flag = true;
18803
- for (let i = 1; i < arr.length; i++) {
18804
- if (!arr[i].isEqual(arr[0])) {
18805
- flag = false;
18806
- break;
18800
+ const element2 = getMatchElementByElement(editor.range.anchor.element, config);
18801
+ if (element2) {
18802
+ elements = [element2];
18807
18803
  }
18804
+ return elements;
18808
18805
  }
18809
- if (flag) {
18810
- return arr[0];
18811
- }
18812
- return null;
18806
+ dataRangeCaches.flatList.forEach((item) => {
18807
+ const element2 = getMatchElementByElement(item.element, config);
18808
+ if (element2 && !elements.some((el) => el.isEqual(element2))) {
18809
+ elements.push(element2);
18810
+ }
18811
+ });
18812
+ return elements;
18813
18813
  };
18814
18814
  const elementIsInList = (element2, ordered) => {
18815
18815
  if (isList(element2, ordered)) {
@@ -18846,10 +18846,10 @@ const hasPreInRange = (editor, dataRangeCaches) => {
18846
18846
  return false;
18847
18847
  }
18848
18848
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18849
- return !!getParsedomElementByElement(editor.range.anchor.element, "pre");
18849
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "pre" });
18850
18850
  }
18851
18851
  return dataRangeCaches.flatList.some((item) => {
18852
- return !!getParsedomElementByElement(item.element, "pre");
18852
+ return !!getMatchElementByElement(item.element, { parsedom: "pre" });
18853
18853
  });
18854
18854
  };
18855
18855
  const isRangeInPre = (editor, dataRangeCaches) => {
@@ -18857,10 +18857,10 @@ const isRangeInPre = (editor, dataRangeCaches) => {
18857
18857
  return false;
18858
18858
  }
18859
18859
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18860
- return !!getParsedomElementByElement(editor.range.anchor.element, "pre");
18860
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "pre" });
18861
18861
  }
18862
18862
  return dataRangeCaches.list.every((item) => {
18863
- return !!getParsedomElementByElement(item.element, "pre");
18863
+ return !!getMatchElementByElement(item.element, { parsedom: "pre" });
18864
18864
  });
18865
18865
  };
18866
18866
  const hasQuoteInRange = (editor, dataRangeCaches) => {
@@ -18868,10 +18868,10 @@ const hasQuoteInRange = (editor, dataRangeCaches) => {
18868
18868
  return false;
18869
18869
  }
18870
18870
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18871
- return !!getParsedomElementByElement(editor.range.anchor.element, "blockquote");
18871
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "blockquote" });
18872
18872
  }
18873
18873
  return dataRangeCaches.flatList.some((item) => {
18874
- return !!getParsedomElementByElement(item.element, "blockquote");
18874
+ return !!getMatchElementByElement(item.element, { parsedom: "blockquote" });
18875
18875
  });
18876
18876
  };
18877
18877
  const isRangeInQuote = (editor, dataRangeCaches) => {
@@ -18879,10 +18879,10 @@ const isRangeInQuote = (editor, dataRangeCaches) => {
18879
18879
  return false;
18880
18880
  }
18881
18881
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18882
- return !!getParsedomElementByElement(editor.range.anchor.element, "blockquote");
18882
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "blockquote" });
18883
18883
  }
18884
18884
  return dataRangeCaches.list.every((item) => {
18885
- return !!getParsedomElementByElement(item.element, "blockquote");
18885
+ return !!getMatchElementByElement(item.element, { parsedom: "blockquote" });
18886
18886
  });
18887
18887
  };
18888
18888
  const hasListInRange = (editor, dataRangeCaches, ordered = false) => {
@@ -18934,10 +18934,10 @@ const hasLinkInRange = (editor, dataRangeCaches) => {
18934
18934
  return false;
18935
18935
  }
18936
18936
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18937
- return !!getParsedomElementByElement(editor.range.anchor.element, "a");
18937
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "a" });
18938
18938
  }
18939
18939
  return dataRangeCaches.flatList.some((item) => {
18940
- return !!getParsedomElementByElement(item.element, "a");
18940
+ return !!getMatchElementByElement(item.element, { parsedom: "a" });
18941
18941
  });
18942
18942
  };
18943
18943
  const hasTableInRange = (editor, dataRangeCaches) => {
@@ -18945,10 +18945,10 @@ const hasTableInRange = (editor, dataRangeCaches) => {
18945
18945
  return false;
18946
18946
  }
18947
18947
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18948
- return !!getParsedomElementByElement(editor.range.anchor.element, "table");
18948
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "table" });
18949
18949
  }
18950
18950
  return dataRangeCaches.flatList.some((item) => {
18951
- return !!getParsedomElementByElement(item.element, "table");
18951
+ return !!getMatchElementByElement(item.element, { parsedom: "table" });
18952
18952
  });
18953
18953
  };
18954
18954
  const hasImageInRange = (editor, dataRangeCaches) => {
@@ -18956,10 +18956,10 @@ const hasImageInRange = (editor, dataRangeCaches) => {
18956
18956
  return false;
18957
18957
  }
18958
18958
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18959
- return !!getParsedomElementByElement(editor.range.anchor.element, "img");
18959
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "img" });
18960
18960
  }
18961
18961
  return dataRangeCaches.flatList.some((item) => {
18962
- return !!getParsedomElementByElement(item.element, "img");
18962
+ return !!getMatchElementByElement(item.element, { parsedom: "img" });
18963
18963
  });
18964
18964
  };
18965
18965
  const hasVideoInRange = (editor, dataRangeCaches) => {
@@ -18967,10 +18967,10 @@ const hasVideoInRange = (editor, dataRangeCaches) => {
18967
18967
  return false;
18968
18968
  }
18969
18969
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18970
- return !!getParsedomElementByElement(editor.range.anchor.element, "video");
18970
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "video" });
18971
18971
  }
18972
18972
  return dataRangeCaches.flatList.some((item) => {
18973
- return !!getParsedomElementByElement(item.element, "video");
18973
+ return !!getMatchElementByElement(item.element, { parsedom: "video" });
18974
18974
  });
18975
18975
  };
18976
18976
  const queryTextStyle = (editor, dataRangeCaches, name, value) => {
@@ -19653,10 +19653,10 @@ const insertCodeBlock = (editor, dataRangeCaches) => {
19653
19653
  if (!editor.range) {
19654
19654
  return;
19655
19655
  }
19656
- const pre = getCurrentParsedomElement(editor, dataRangeCaches, "pre");
19657
- if (pre) {
19656
+ const pres = getMatchElementsByRange(editor, dataRangeCaches, { parsedom: "pre" });
19657
+ if (pres.length == 1) {
19658
19658
  let content = "";
19659
- AlexElement.flatElements(pre.children).filter((item) => {
19659
+ AlexElement.flatElements(pres[0].children).filter((item) => {
19660
19660
  return item.isText();
19661
19661
  }).forEach((item) => {
19662
19662
  content += item.textContent;
@@ -19666,9 +19666,9 @@ const insertCodeBlock = (editor, dataRangeCaches) => {
19666
19666
  const paragraph = new AlexElement("block", AlexElement.BLOCK_NODE, null, null, null);
19667
19667
  const text2 = new AlexElement("text", null, null, null, item);
19668
19668
  editor.addElementTo(text2, paragraph);
19669
- editor.addElementBefore(paragraph, pre);
19669
+ editor.addElementBefore(paragraph, pres[0]);
19670
19670
  });
19671
- pre.toEmpty();
19671
+ pres[0].toEmpty();
19672
19672
  } else {
19673
19673
  if (editor.range.anchor.isEqual(editor.range.focus)) {
19674
19674
  const block = editor.range.anchor.element.getBlock();
@@ -19690,30 +19690,30 @@ const insertCodeBlock = (editor, dataRangeCaches) => {
19690
19690
  obj[el.element.getBlock().key] = [el.element.clone()];
19691
19691
  }
19692
19692
  });
19693
- const pre2 = new AlexElement("block", "pre", null, null, null);
19693
+ const pre = new AlexElement("block", "pre", null, null, null);
19694
19694
  Object.keys(obj).forEach((key, index) => {
19695
19695
  if (index > 0) {
19696
19696
  const text2 = new AlexElement("text", null, null, null, "\n");
19697
- if (pre2.hasChildren()) {
19698
- editor.addElementTo(text2, pre2, pre2.children.length);
19697
+ if (pre.hasChildren()) {
19698
+ editor.addElementTo(text2, pre, pre.children.length);
19699
19699
  } else {
19700
- editor.addElementTo(text2, pre2);
19700
+ editor.addElementTo(text2, pre);
19701
19701
  }
19702
19702
  }
19703
19703
  obj[key].forEach((el) => {
19704
- if (pre2.hasChildren()) {
19705
- editor.addElementTo(el, pre2, pre2.children.length);
19704
+ if (pre.hasChildren()) {
19705
+ editor.addElementTo(el, pre, pre.children.length);
19706
19706
  } else {
19707
- editor.addElementTo(el, pre2);
19707
+ editor.addElementTo(el, pre);
19708
19708
  }
19709
19709
  });
19710
19710
  });
19711
19711
  editor.delete();
19712
- editor.insertElement(pre2);
19712
+ editor.insertElement(pre);
19713
19713
  const paragraph = new AlexElement("block", AlexElement.BLOCK_NODE, null, null, null);
19714
19714
  const breakEl = new AlexElement("closed", "br", null, null, null);
19715
19715
  editor.addElementTo(breakEl, paragraph);
19716
- editor.addElementAfter(paragraph, pre2);
19716
+ editor.addElementAfter(paragraph, pre);
19717
19717
  }
19718
19718
  }
19719
19719
  };
@@ -19863,6 +19863,11 @@ const tableHandle = function(editor, element2) {
19863
19863
  let colgroup = elements.find((el) => {
19864
19864
  return el.parsedom == "colgroup";
19865
19865
  });
19866
+ const colNumber = Math.max(
19867
+ ...rows.map((row) => {
19868
+ return row.children.length;
19869
+ })
19870
+ );
19866
19871
  if (colgroup) {
19867
19872
  colgroup.children.forEach((col) => {
19868
19873
  if (!col.hasMarks()) {
@@ -19873,9 +19878,23 @@ const tableHandle = function(editor, element2) {
19873
19878
  col.marks["width"] = "auto";
19874
19879
  }
19875
19880
  });
19881
+ const length = colgroup.children.length;
19882
+ if (length < colNumber) {
19883
+ for (let i = 0; i < colNumber - length; i++) {
19884
+ const col = new AlexElement(
19885
+ "closed",
19886
+ "col",
19887
+ {
19888
+ width: "auto"
19889
+ },
19890
+ null,
19891
+ null
19892
+ );
19893
+ editor.addElementTo(col, colgroup, colgroup.children.length);
19894
+ }
19895
+ }
19876
19896
  } else {
19877
19897
  colgroup = new AlexElement("inblock", "colgroup", null, null, null);
19878
- const colNumber = getColNumbers(rows[0]);
19879
19898
  for (let i = colNumber - 1; i >= 0; i--) {
19880
19899
  const col = new AlexElement(
19881
19900
  "closed",
@@ -19892,6 +19911,15 @@ const tableHandle = function(editor, element2) {
19892
19911
  element2.children = [];
19893
19912
  const tbody = new AlexElement("inblock", "tbody", null, null, null);
19894
19913
  rows.reverse().forEach((row) => {
19914
+ const length = row.children.length;
19915
+ if (length < colNumber) {
19916
+ for (let i = 0; i < colNumber - length; i++) {
19917
+ const column = new AlexElement("inblock", "td", null, null, null);
19918
+ const breakElement = new AlexElement("closed", "br", null, null, null);
19919
+ editor.addElementTo(breakElement, column);
19920
+ editor.addElementTo(column, row, row.children.length);
19921
+ }
19922
+ }
19895
19923
  editor.addElementTo(row, tbody);
19896
19924
  });
19897
19925
  editor.addElementTo(tbody, element2);
@@ -19900,6 +19928,21 @@ const tableHandle = function(editor, element2) {
19900
19928
  if (element2.parsedom == "th") {
19901
19929
  element2.parsedom = "td";
19902
19930
  }
19931
+ if (element2.parsedom == "td") {
19932
+ if (element2.hasMarks()) {
19933
+ if (element2.marks["rowspan"]) {
19934
+ delete element2.marks["rowspan"];
19935
+ }
19936
+ if (element2.marks["colspan"]) {
19937
+ delete element2.marks["colspan"];
19938
+ }
19939
+ }
19940
+ if (element2.hasStyles()) {
19941
+ if (element2.styles["display"]) {
19942
+ delete element2.styles["display"];
19943
+ }
19944
+ }
19945
+ }
19903
19946
  };
19904
19947
  const preHandle = function(editor, element2, highlight2, languages2) {
19905
19948
  if (element2.parsedom == "pre") {
@@ -21753,34 +21796,34 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21753
21796
  if (!linkConfig.value.url) {
21754
21797
  return;
21755
21798
  }
21756
- const link = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "a");
21757
- if (link) {
21758
- link.marks.href = linkConfig.value.url;
21799
+ const links = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "a" });
21800
+ if (links.length == 1) {
21801
+ links[0].marks.href = linkConfig.value.url;
21759
21802
  if (linkConfig.value.newOpen) {
21760
- link.marks.target = "_blank";
21803
+ links[0].marks.target = "_blank";
21761
21804
  } else {
21762
- delete link.marks.target;
21805
+ delete links[0].marks.target;
21763
21806
  }
21807
+ editor.value.formatElementStack();
21808
+ editor.value.domRender();
21764
21809
  }
21765
- editor.value.formatElementStack();
21766
- editor.value.domRender();
21767
21810
  };
21768
21811
  const removeLink = () => {
21769
- const link = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "a");
21770
- if (link) {
21771
- link.parsedom = AlexElement.TEXT_NODE;
21772
- delete link.marks["target"];
21773
- delete link.marks["href"];
21774
- delete link.marks["data-editify-element"];
21812
+ const links = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "a" });
21813
+ if (links.length == 1) {
21814
+ links[0].parsedom = AlexElement.TEXT_NODE;
21815
+ delete links[0].marks["target"];
21816
+ delete links[0].marks["href"];
21817
+ delete links[0].marks["data-editify-element"];
21818
+ editor.value.formatElementStack();
21819
+ editor.value.domRender();
21820
+ editor.value.rangeRender();
21775
21821
  }
21776
- editor.value.formatElementStack();
21777
- editor.value.domRender();
21778
- editor.value.rangeRender();
21779
21822
  };
21780
21823
  const selectLanguage = (_name, value) => {
21781
- const pre = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "pre");
21782
- if (pre) {
21783
- Object.assign(pre.marks, {
21824
+ const pres = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "pre" });
21825
+ if (pres.length == 1) {
21826
+ Object.assign(pres[0].marks, {
21784
21827
  "data-editify-hljs": value
21785
21828
  });
21786
21829
  editor.value.formatElementStack();
@@ -21793,15 +21836,15 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21793
21836
  editor.value.range.anchor.element = editor.value.range.focus.element;
21794
21837
  editor.value.range.anchor.offset = editor.value.range.focus.offset;
21795
21838
  }
21796
- const pre = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "pre");
21797
- if (pre) {
21839
+ const pres = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "pre" });
21840
+ if (pres.length == 1) {
21798
21841
  const paragraph = new AlexElement("block", AlexElement.BLOCK_NODE, null, null, null);
21799
21842
  const breakEl = new AlexElement("closed", "br", null, null, null);
21800
21843
  editor.value.addElementTo(breakEl, paragraph);
21801
21844
  if (type == "up") {
21802
- editor.value.addElementBefore(paragraph, pre);
21845
+ editor.value.addElementBefore(paragraph, pres[0]);
21803
21846
  } else {
21804
- editor.value.addElementAfter(paragraph, pre);
21847
+ editor.value.addElementAfter(paragraph, pres[0]);
21805
21848
  }
21806
21849
  editor.value.range.anchor.moveToEnd(paragraph);
21807
21850
  editor.value.range.focus.moveToEnd(paragraph);
@@ -21815,16 +21858,16 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21815
21858
  editor.value.range.anchor.element = editor.value.range.focus.element;
21816
21859
  editor.value.range.anchor.offset = editor.value.range.focus.offset;
21817
21860
  }
21818
- const table = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "table");
21819
- const column = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "td");
21820
- const tbody = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "tbody");
21821
- if (column && table && tbody) {
21822
- const rows = tbody.children;
21823
- const index = column.parent.children.findIndex((item) => {
21824
- return item.isEqual(column);
21861
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
21862
+ const columns = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "td" });
21863
+ const tbodys = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "tbody" });
21864
+ if (tables.length == 1 && tbodys.length == 1 && columns.length == 1) {
21865
+ const rows = tbodys[0].children;
21866
+ const index = columns[0].parent.children.findIndex((item) => {
21867
+ return item.isEqual(columns[0]);
21825
21868
  });
21826
21869
  rows.forEach((row) => {
21827
- const newColumn = column.clone(false);
21870
+ const newColumn = columns[0].clone(false);
21828
21871
  const breakEl = new AlexElement("closed", "br", null, null, null);
21829
21872
  editor.value.addElementTo(breakEl, newColumn);
21830
21873
  if (type == "left") {
@@ -21833,7 +21876,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21833
21876
  editor.value.addElementTo(newColumn, row, index + 1);
21834
21877
  }
21835
21878
  });
21836
- const colgroup = table.children.find((item) => {
21879
+ const colgroup = tables[0].children.find((item) => {
21837
21880
  return item.parsedom == "colgroup";
21838
21881
  });
21839
21882
  const col = new AlexElement("closed", "col", null, null, null);
@@ -21844,11 +21887,11 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21844
21887
  }
21845
21888
  editor.value.formatElementStack();
21846
21889
  if (type == "left") {
21847
- const previousColumn = editor.value.getPreviousElement(column);
21890
+ const previousColumn = editor.value.getPreviousElement(columns[0]);
21848
21891
  editor.value.range.anchor.moveToStart(previousColumn);
21849
21892
  editor.value.range.focus.moveToStart(previousColumn);
21850
21893
  } else {
21851
- const nextColumn = editor.value.getNextElement(column);
21894
+ const nextColumn = editor.value.getNextElement(columns[0]);
21852
21895
  editor.value.range.anchor.moveToStart(nextColumn);
21853
21896
  editor.value.range.focus.moveToStart(nextColumn);
21854
21897
  }
@@ -21861,19 +21904,19 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21861
21904
  editor.value.range.anchor.element = editor.value.range.focus.element;
21862
21905
  editor.value.range.anchor.offset = editor.value.range.focus.offset;
21863
21906
  }
21864
- const table = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "table");
21865
- const row = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "tr");
21866
- if (table && row) {
21867
- const newRow = row.clone();
21907
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
21908
+ const rows = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "tr" });
21909
+ if (tables.length == 1 && rows.length == 1) {
21910
+ const newRow = rows[0].clone();
21868
21911
  newRow.children.forEach((column) => {
21869
21912
  column.children = [];
21870
21913
  const breakEl = new AlexElement("closed", "br", null, null, null);
21871
21914
  editor.value.addElementTo(breakEl, column);
21872
21915
  });
21873
21916
  if (type == "up") {
21874
- editor.value.addElementBefore(newRow, row);
21917
+ editor.value.addElementBefore(newRow, rows[0]);
21875
21918
  } else {
21876
- editor.value.addElementAfter(newRow, row);
21919
+ editor.value.addElementAfter(newRow, rows[0]);
21877
21920
  }
21878
21921
  editor.value.formatElementStack();
21879
21922
  editor.value.range.anchor.moveToStart(newRow);
@@ -21886,15 +21929,15 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21886
21929
  }
21887
21930
  };
21888
21931
  const insertParagraphWithTable = (type = "up") => {
21889
- const table = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "table");
21890
- if (table) {
21932
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
21933
+ if (tables.length == 1) {
21891
21934
  const paragraph = new AlexElement("block", AlexElement.BLOCK_NODE, null, null, null);
21892
21935
  const breakEl = new AlexElement("closed", "br", null, null, null);
21893
21936
  editor.value.addElementTo(breakEl, paragraph);
21894
21937
  if (type == "up") {
21895
- editor.value.addElementBefore(paragraph, table);
21938
+ editor.value.addElementBefore(paragraph, tables[0]);
21896
21939
  } else {
21897
- editor.value.addElementAfter(paragraph, table);
21940
+ editor.value.addElementAfter(paragraph, tables[0]);
21898
21941
  }
21899
21942
  editor.value.range.anchor.moveToEnd(paragraph);
21900
21943
  editor.value.range.focus.moveToEnd(paragraph);
@@ -21904,9 +21947,9 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21904
21947
  }
21905
21948
  };
21906
21949
  const deleteElement = (parsedom) => {
21907
- const element2 = getCurrentParsedomElement(editor.value, dataRangeCaches.value, parsedom);
21908
- if (element2) {
21909
- element2.toEmpty();
21950
+ const elements = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom });
21951
+ if (elements.length == 1) {
21952
+ elements[0].toEmpty();
21910
21953
  editor.value.formatElementStack();
21911
21954
  editor.value.domRender();
21912
21955
  editor.value.rangeRender();
@@ -21917,17 +21960,17 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21917
21960
  editor.value.range.anchor.element = editor.value.range.focus.element;
21918
21961
  editor.value.range.anchor.offset = editor.value.range.focus.offset;
21919
21962
  }
21920
- const table = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "table");
21921
- const row = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "tr");
21922
- if (table && row) {
21923
- const parent = row.parent;
21963
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
21964
+ const rows = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "tr" });
21965
+ if (tables.length == 1 && rows.length == 1) {
21966
+ const parent = rows[0].parent;
21924
21967
  if (parent.children.length == 1) {
21925
21968
  deleteElement("table");
21926
21969
  return;
21927
21970
  }
21928
- const previousRow = editor.value.getPreviousElement(row);
21929
- const nextRow = editor.value.getNextElement(row);
21930
- row.toEmpty();
21971
+ const previousRow = editor.value.getPreviousElement(rows[0]);
21972
+ const nextRow = editor.value.getNextElement(rows[0]);
21973
+ rows[0].toEmpty();
21931
21974
  editor.value.formatElementStack();
21932
21975
  if (previousRow) {
21933
21976
  editor.value.range.anchor.moveToEnd(previousRow.children[0]);
@@ -21948,25 +21991,25 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21948
21991
  editor.value.range.anchor.element = editor.value.range.focus.element;
21949
21992
  editor.value.range.anchor.offset = editor.value.range.focus.offset;
21950
21993
  }
21951
- const column = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "td");
21952
- const tbody = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "tbody");
21953
- const table = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "table");
21954
- if (column && table && tbody) {
21955
- const rows = tbody.children;
21956
- const parent = column.parent;
21994
+ const columns = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "td" });
21995
+ const tbodys = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "tbody" });
21996
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
21997
+ if (tables.length == 1 && tbodys.length == 1 && columns.length == 1) {
21998
+ const rows = tbodys[0].children;
21999
+ const parent = columns[0].parent;
21957
22000
  if (parent.children.length == 1) {
21958
22001
  deleteElement("table");
21959
22002
  return;
21960
22003
  }
21961
- const previousColumn = editor.value.getPreviousElement(column);
21962
- const nextColumn = editor.value.getNextElement(column);
21963
- const index = column.parent.children.findIndex((item) => {
21964
- return item.isEqual(column);
22004
+ const previousColumn = editor.value.getPreviousElement(columns[0]);
22005
+ const nextColumn = editor.value.getNextElement(columns[0]);
22006
+ const index = columns[0].parent.children.findIndex((item) => {
22007
+ return item.isEqual(columns[0]);
21965
22008
  });
21966
22009
  rows.forEach((row) => {
21967
22010
  row.children[index].toEmpty();
21968
22011
  });
21969
- const colgroup = table.children.find((item) => {
22012
+ const colgroup = tables[0].children.find((item) => {
21970
22013
  return item.parsedom == "colgroup";
21971
22014
  });
21972
22015
  colgroup.children[index].toEmpty();
@@ -21983,24 +22026,26 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21983
22026
  }
21984
22027
  };
21985
22028
  const layerShow = () => {
21986
- if (props.type == "codeBlock") {
21987
- const pre = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "pre");
21988
- if (pre) {
21989
- languageConfig.value.displayConfig.value = pre.marks["data-editify-hljs"] || "";
21990
- }
21991
- } else if (props.type == "link") {
21992
- const link = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "a");
21993
- if (link) {
21994
- linkConfig.value.url = link.marks["href"];
21995
- linkConfig.value.newOpen = link.marks["target"] == "_blank";
22029
+ if (props.type == "link") {
22030
+ const links = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "a" });
22031
+ if (links.length == 1) {
22032
+ linkConfig.value.url = links[0].marks["href"];
22033
+ linkConfig.value.newOpen = links[0].marks["target"] == "_blank";
21996
22034
  }
21997
22035
  } else if (props.type == "video") {
21998
- const video = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "video");
21999
- if (video) {
22000
- videoConfig.value.autoplay = !!video.marks["autoplay"];
22001
- videoConfig.value.loop = !!video.marks["loop"];
22002
- videoConfig.value.controls = !!video.marks["controls"];
22003
- videoConfig.value.muted = !!video.marks["muted"];
22036
+ const videos = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "video" });
22037
+ if (videos.length == 1) {
22038
+ videoConfig.value.autoplay = !!videos[0].marks["autoplay"];
22039
+ videoConfig.value.loop = !!videos[0].marks["loop"];
22040
+ videoConfig.value.controls = !!videos[0].marks["controls"];
22041
+ videoConfig.value.muted = !!videos[0].marks["muted"];
22042
+ }
22043
+ } else if (props.type == "codeBlock") {
22044
+ const pres = getMatchElementsByRange(editor.value, dataRangeCaches.value, {
22045
+ parsedom: "pre"
22046
+ });
22047
+ if (pres.length == 1) {
22048
+ languageConfig.value.displayConfig.value = pres[0].marks["data-editify-hljs"] || "";
22004
22049
  }
22005
22050
  } else if (props.type == "text") {
22006
22051
  const extraDisabled = (name) => {
@@ -22437,6 +22482,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
22437
22482
  }, 8, ["title", "tooltip", "color"]),
22438
22483
  createVNode(Button, {
22439
22484
  onOperate: _cache[18] || (_cache[18] = ($event) => deleteElement("table")),
22485
+ leftBorder: "",
22440
22486
  name: "deleteTable",
22441
22487
  title: unref($editTrans)("deleteTable"),
22442
22488
  tooltip: _ctx.config.tooltip,
@@ -22821,7 +22867,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
22821
22867
  };
22822
22868
  }
22823
22869
  });
22824
- const Toolbar = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["__scopeId", "data-v-357be052"]]);
22870
+ const Toolbar = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["__scopeId", "data-v-f6219d4c"]]);
22825
22871
  const InsertLinkProps = {
22826
22872
  //主题色
22827
22873
  color: {
@@ -24142,7 +24188,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
24142
24188
  imageConfig.value.disabled = value_hasPreInRange || extraDisabled("image");
24143
24189
  videoConfig.value.disabled = value_hasPreInRange || extraDisabled("video");
24144
24190
  tableConfig.value.disabled = value_hasPreInRange || value_hasTableInRange || value_hasQuoteInRange || extraDisabled("table");
24145
- codeBlockConfig.value.active = !!getCurrentParsedomElement(editor.value, dataRangeCaches.value, "pre");
24191
+ codeBlockConfig.value.active = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "pre" }).length == 1;
24146
24192
  codeBlockConfig.value.disabled = value_hasTableInRange || value_hasQuoteInRange || value_hasImageInRange || value_hasVideoInRange || extraDisabled("codeBlock");
24147
24193
  sourceViewConfig.value.active = isSourceView.value;
24148
24194
  fullScreenConfig.value.active = isFullScreen.value;
@@ -24854,7 +24900,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
24854
24900
  };
24855
24901
  }
24856
24902
  });
24857
- const Menu = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-13b11735"]]);
24903
+ const Menu = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-6c75ad6c"]]);
24858
24904
  const EditifyProps = {
24859
24905
  //国际化语言类型
24860
24906
  locale: {
@@ -25103,6 +25149,7 @@ const en_US = {
25103
25149
  attachmentDefaultName: "attachment",
25104
25150
  //数学公式插件语言配置
25105
25151
  insertMathformula: "Insert mathematical formula",
25152
+ editMathformula: "Edit mathematical formula",
25106
25153
  mathformulaPlaceholder: "Please enter LaTex syntax"
25107
25154
  };
25108
25155
  const zh_CN = {
@@ -25202,6 +25249,7 @@ const zh_CN = {
25202
25249
  attachmentDefaultName: "附件",
25203
25250
  //数学公式插件语言配置
25204
25251
  insertMathformula: "插入数学公式",
25252
+ editMathformula: "编辑数学公式",
25205
25253
  mathformulaPlaceholder: "请输入LaTex语法"
25206
25254
  };
25207
25255
  const trans = (locale) => {
@@ -25334,46 +25382,46 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
25334
25382
  }
25335
25383
  hideToolbar();
25336
25384
  nextTick(() => {
25337
- const table = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "table");
25338
- const pre = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "pre");
25339
- const link = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "a");
25340
- const image = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "img");
25341
- const video = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "video");
25342
- if (link) {
25385
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
25386
+ const pres = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "pre" });
25387
+ const links = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "a" });
25388
+ const images = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "img" });
25389
+ const videos = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "video" });
25390
+ if (links.length == 1) {
25343
25391
  toolbarOptions.value.type = "link";
25344
- toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${link.key}"]`;
25392
+ toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${links[0].key}"]`;
25345
25393
  if (toolbarOptions.value.show) {
25346
25394
  toolbarRef.value.$refs.layerRef.setPosition();
25347
25395
  } else {
25348
25396
  toolbarOptions.value.show = true;
25349
25397
  }
25350
- } else if (image) {
25398
+ } else if (images.length == 1) {
25351
25399
  toolbarOptions.value.type = "image";
25352
- toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${image.key}"]`;
25400
+ toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${images[0].key}"]`;
25353
25401
  if (toolbarOptions.value.show) {
25354
25402
  toolbarRef.value.$refs.layerRef.setPosition();
25355
25403
  } else {
25356
25404
  toolbarOptions.value.show = true;
25357
25405
  }
25358
- } else if (video) {
25406
+ } else if (videos.length == 1) {
25359
25407
  toolbarOptions.value.type = "video";
25360
- toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${video.key}"]`;
25408
+ toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${videos[0].key}"]`;
25361
25409
  if (toolbarOptions.value.show) {
25362
25410
  toolbarRef.value.$refs.layerRef.setPosition();
25363
25411
  } else {
25364
25412
  toolbarOptions.value.show = true;
25365
25413
  }
25366
- } else if (table) {
25414
+ } else if (tables.length == 1) {
25367
25415
  toolbarOptions.value.type = "table";
25368
- toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${table.key}"]`;
25416
+ toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${tables[0].key}"]`;
25369
25417
  if (toolbarOptions.value.show) {
25370
25418
  toolbarRef.value.$refs.layerRef.setPosition();
25371
25419
  } else {
25372
25420
  toolbarOptions.value.show = true;
25373
25421
  }
25374
- } else if (pre) {
25422
+ } else if (pres.length == 1) {
25375
25423
  toolbarOptions.value.type = "codeBlock";
25376
- toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${pre.key}"]`;
25424
+ toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${pres[0].key}"]`;
25377
25425
  if (toolbarOptions.value.show) {
25378
25426
  toolbarRef.value.$refs.layerRef.setPosition();
25379
25427
  } else {
@@ -25505,11 +25553,11 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
25505
25553
  if (!tableColumnResizeParams.value.element) {
25506
25554
  return;
25507
25555
  }
25508
- const table = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "table");
25509
- if (!table) {
25556
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
25557
+ if (tables.length != 1) {
25510
25558
  return;
25511
25559
  }
25512
- const colgroup = table.children.find((item) => {
25560
+ const colgroup = tables[0].children.find((item) => {
25513
25561
  return item.parsedom == "colgroup";
25514
25562
  });
25515
25563
  const index = tableColumnResizeParams.value.element.parent.children.findIndex((el) => {
@@ -25527,11 +25575,11 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
25527
25575
  if (!tableColumnResizeParams.value.element) {
25528
25576
  return;
25529
25577
  }
25530
- const table = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "table");
25531
- if (!table) {
25578
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
25579
+ if (tables.length != 1) {
25532
25580
  return;
25533
25581
  }
25534
- const colgroup = table.children.find((item) => {
25582
+ const colgroup = tables[0].children.find((item) => {
25535
25583
  return item.parsedom == "colgroup";
25536
25584
  });
25537
25585
  const index = tableColumnResizeParams.value.element.parent.children.findIndex((el) => {
@@ -25592,9 +25640,6 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
25592
25640
  if (el.marks["disabled"]) {
25593
25641
  marks["disabled"] = el.marks["disabled"];
25594
25642
  }
25595
- if (el.parsedom == "td" && el.marks["colspan"]) {
25596
- marks["colspan"] = el.marks["colspan"];
25597
- }
25598
25643
  if (["img", "video"].includes(el.parsedom) && el.marks["src"]) {
25599
25644
  marks["src"] = el.marks["src"];
25600
25645
  }
@@ -25651,12 +25696,10 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
25651
25696
  }
25652
25697
  });
25653
25698
  if (typeof props.pasteKeepMarks == "function") {
25654
- const keepMarks = props.pasteKeepMarks(el);
25655
- marks = mergeObject(marks, keepMarks);
25699
+ marks = mergeObject(marks, props.pasteKeepMarks(el));
25656
25700
  }
25657
25701
  if (typeof props.pasteKeepStyles == "function") {
25658
- const keepStyles = props.pasteKeepStyles(el);
25659
- styles2 = mergeObject(styles2, keepStyles);
25702
+ styles2 = mergeObject(styles2, props.pasteKeepStyles(el));
25660
25703
  }
25661
25704
  el.marks = marks;
25662
25705
  el.styles = styles2;
@@ -26021,7 +26064,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
26021
26064
  };
26022
26065
  }
26023
26066
  });
26024
- const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-20ab798b"]]);
26067
+ const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-fcc910d9"]]);
26025
26068
  const InsertAttachmentProps = {
26026
26069
  //主题色
26027
26070
  color: {
@@ -40765,7 +40808,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
40765
40808
  );
40766
40809
  return (_ctx, _cache) => {
40767
40810
  return openBlock(), createElementBlock("div", _hoisted_1, [
40768
- createElementVNode("div", _hoisted_2, toDisplayString(unref($editTrans)("insertMathformula")), 1),
40811
+ createElementVNode("div", _hoisted_2, toDisplayString(props.defaultLaTexContent ? unref($editTrans)("editMathformula") : unref($editTrans)("insertMathformula")), 1),
40769
40812
  withDirectives(createElementVNode("textarea", {
40770
40813
  class: "editify-mathformula-textarea",
40771
40814
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => latexContent.value = $event),
@@ -40790,7 +40833,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
40790
40833
  };
40791
40834
  }
40792
40835
  });
40793
- const InsertMathformula = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-ed1761a7"]]);
40836
+ const InsertMathformula = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-980bdb1d"]]);
40794
40837
  const isMathformula = (el) => {
40795
40838
  return el.parsedom == "span" && el.hasMarks() && el.marks["data-editify-mathformula"];
40796
40839
  };
@@ -41145,7 +41188,7 @@ const attachment = (options) => {
41145
41188
  const install = (app) => {
41146
41189
  app.component(Editify.name, Editify);
41147
41190
  };
41148
- const version = "0.1.40";
41191
+ const version = "0.1.41";
41149
41192
  console.log(`%c vue-editify %c v${version} `, "padding: 2px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #606060; font-weight: bold;", "padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e; font-weight: bold;");
41150
41193
  export {
41151
41194
  AlexElement,
@@ -41154,10 +41197,11 @@ export {
41154
41197
  install as default,
41155
41198
  elementIsInList,
41156
41199
  elementIsInTask,
41157
- getCurrentParsedomElement,
41200
+ elementIsMatch,
41201
+ getMatchElementByElement,
41202
+ getMatchElementsByRange,
41158
41203
  getMathformulaElement,
41159
41204
  getMathformulaElementByRange,
41160
- getParsedomElementByElement,
41161
41205
  getRangeText,
41162
41206
  hasAttachmentInRange,
41163
41207
  hasImageInRange,