vue-editify 0.1.40 → 0.1.42

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,57 @@ const getMenuConfig = function(editTrans, editLocale) {
18771
18756
  extends: {}
18772
18757
  };
18773
18758
  };
18774
- const getParsedomElementByElement = (element2, parsedom) => {
18759
+ const elementIsMatch = (element2, config) => {
18760
+ let isMatch = true;
18761
+ if (config.parsedom && element2.parsedom && config.parsedom != element2.parsedom) {
18762
+ isMatch = false;
18763
+ }
18764
+ if (config.marks) {
18765
+ const hasMarks = Object.keys(config.marks).every((key) => {
18766
+ return element2.hasMarks() && element2.marks[key] && element2.marks[key] == config.marks[key];
18767
+ });
18768
+ if (!hasMarks) {
18769
+ isMatch = false;
18770
+ }
18771
+ }
18772
+ if (config.styles) {
18773
+ const hasStyles = Object.keys(config.styles).every((key) => {
18774
+ return element2.hasStyles() && element2.styles[key] && element2.styles[key] == config.styles[key];
18775
+ });
18776
+ if (!hasStyles) {
18777
+ isMatch = false;
18778
+ }
18779
+ }
18780
+ return isMatch;
18781
+ };
18782
+ const getMatchElementByElement = (element2, config) => {
18775
18783
  if (element2.isBlock()) {
18776
- return element2.parsedom == parsedom ? element2 : null;
18784
+ return elementIsMatch(element2, config) ? element2 : null;
18777
18785
  }
18778
- if (!element2.isText() && element2.parsedom == parsedom) {
18786
+ if (elementIsMatch(element2, config)) {
18779
18787
  return element2;
18780
18788
  }
18781
- return getParsedomElementByElement(element2.parent, parsedom);
18789
+ return getMatchElementByElement(element2.parent, config);
18782
18790
  };
18783
- const getCurrentParsedomElement = (editor, dataRangeCaches, parsedom) => {
18791
+ const getMatchElementsByRange = (editor, dataRangeCaches, config) => {
18792
+ let elements = [];
18784
18793
  if (!editor.range) {
18785
- return null;
18794
+ return elements;
18786
18795
  }
18787
18796
  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;
18797
+ const element2 = getMatchElementByElement(editor.range.anchor.element, config);
18798
+ if (element2) {
18799
+ elements = [element2];
18807
18800
  }
18801
+ return elements;
18808
18802
  }
18809
- if (flag) {
18810
- return arr[0];
18811
- }
18812
- return null;
18803
+ dataRangeCaches.flatList.forEach((item) => {
18804
+ const element2 = getMatchElementByElement(item.element, config);
18805
+ if (element2 && !elements.some((el) => el.isEqual(element2))) {
18806
+ elements.push(element2);
18807
+ }
18808
+ });
18809
+ return elements;
18813
18810
  };
18814
18811
  const elementIsInList = (element2, ordered) => {
18815
18812
  if (isList(element2, ordered)) {
@@ -18846,10 +18843,10 @@ const hasPreInRange = (editor, dataRangeCaches) => {
18846
18843
  return false;
18847
18844
  }
18848
18845
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18849
- return !!getParsedomElementByElement(editor.range.anchor.element, "pre");
18846
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "pre" });
18850
18847
  }
18851
18848
  return dataRangeCaches.flatList.some((item) => {
18852
- return !!getParsedomElementByElement(item.element, "pre");
18849
+ return !!getMatchElementByElement(item.element, { parsedom: "pre" });
18853
18850
  });
18854
18851
  };
18855
18852
  const isRangeInPre = (editor, dataRangeCaches) => {
@@ -18857,10 +18854,10 @@ const isRangeInPre = (editor, dataRangeCaches) => {
18857
18854
  return false;
18858
18855
  }
18859
18856
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18860
- return !!getParsedomElementByElement(editor.range.anchor.element, "pre");
18857
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "pre" });
18861
18858
  }
18862
18859
  return dataRangeCaches.list.every((item) => {
18863
- return !!getParsedomElementByElement(item.element, "pre");
18860
+ return !!getMatchElementByElement(item.element, { parsedom: "pre" });
18864
18861
  });
18865
18862
  };
18866
18863
  const hasQuoteInRange = (editor, dataRangeCaches) => {
@@ -18868,10 +18865,10 @@ const hasQuoteInRange = (editor, dataRangeCaches) => {
18868
18865
  return false;
18869
18866
  }
18870
18867
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18871
- return !!getParsedomElementByElement(editor.range.anchor.element, "blockquote");
18868
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "blockquote" });
18872
18869
  }
18873
18870
  return dataRangeCaches.flatList.some((item) => {
18874
- return !!getParsedomElementByElement(item.element, "blockquote");
18871
+ return !!getMatchElementByElement(item.element, { parsedom: "blockquote" });
18875
18872
  });
18876
18873
  };
18877
18874
  const isRangeInQuote = (editor, dataRangeCaches) => {
@@ -18879,10 +18876,10 @@ const isRangeInQuote = (editor, dataRangeCaches) => {
18879
18876
  return false;
18880
18877
  }
18881
18878
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18882
- return !!getParsedomElementByElement(editor.range.anchor.element, "blockquote");
18879
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "blockquote" });
18883
18880
  }
18884
18881
  return dataRangeCaches.list.every((item) => {
18885
- return !!getParsedomElementByElement(item.element, "blockquote");
18882
+ return !!getMatchElementByElement(item.element, { parsedom: "blockquote" });
18886
18883
  });
18887
18884
  };
18888
18885
  const hasListInRange = (editor, dataRangeCaches, ordered = false) => {
@@ -18934,10 +18931,10 @@ const hasLinkInRange = (editor, dataRangeCaches) => {
18934
18931
  return false;
18935
18932
  }
18936
18933
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18937
- return !!getParsedomElementByElement(editor.range.anchor.element, "a");
18934
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "a" });
18938
18935
  }
18939
18936
  return dataRangeCaches.flatList.some((item) => {
18940
- return !!getParsedomElementByElement(item.element, "a");
18937
+ return !!getMatchElementByElement(item.element, { parsedom: "a" });
18941
18938
  });
18942
18939
  };
18943
18940
  const hasTableInRange = (editor, dataRangeCaches) => {
@@ -18945,10 +18942,10 @@ const hasTableInRange = (editor, dataRangeCaches) => {
18945
18942
  return false;
18946
18943
  }
18947
18944
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18948
- return !!getParsedomElementByElement(editor.range.anchor.element, "table");
18945
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "table" });
18949
18946
  }
18950
18947
  return dataRangeCaches.flatList.some((item) => {
18951
- return !!getParsedomElementByElement(item.element, "table");
18948
+ return !!getMatchElementByElement(item.element, { parsedom: "table" });
18952
18949
  });
18953
18950
  };
18954
18951
  const hasImageInRange = (editor, dataRangeCaches) => {
@@ -18956,10 +18953,10 @@ const hasImageInRange = (editor, dataRangeCaches) => {
18956
18953
  return false;
18957
18954
  }
18958
18955
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18959
- return !!getParsedomElementByElement(editor.range.anchor.element, "img");
18956
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "img" });
18960
18957
  }
18961
18958
  return dataRangeCaches.flatList.some((item) => {
18962
- return !!getParsedomElementByElement(item.element, "img");
18959
+ return !!getMatchElementByElement(item.element, { parsedom: "img" });
18963
18960
  });
18964
18961
  };
18965
18962
  const hasVideoInRange = (editor, dataRangeCaches) => {
@@ -18967,10 +18964,10 @@ const hasVideoInRange = (editor, dataRangeCaches) => {
18967
18964
  return false;
18968
18965
  }
18969
18966
  if (editor.range.anchor.isEqual(editor.range.focus)) {
18970
- return !!getParsedomElementByElement(editor.range.anchor.element, "video");
18967
+ return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: "video" });
18971
18968
  }
18972
18969
  return dataRangeCaches.flatList.some((item) => {
18973
- return !!getParsedomElementByElement(item.element, "video");
18970
+ return !!getMatchElementByElement(item.element, { parsedom: "video" });
18974
18971
  });
18975
18972
  };
18976
18973
  const queryTextStyle = (editor, dataRangeCaches, name, value) => {
@@ -19653,10 +19650,10 @@ const insertCodeBlock = (editor, dataRangeCaches) => {
19653
19650
  if (!editor.range) {
19654
19651
  return;
19655
19652
  }
19656
- const pre = getCurrentParsedomElement(editor, dataRangeCaches, "pre");
19657
- if (pre) {
19653
+ const pres = getMatchElementsByRange(editor, dataRangeCaches, { parsedom: "pre" });
19654
+ if (pres.length == 1) {
19658
19655
  let content = "";
19659
- AlexElement.flatElements(pre.children).filter((item) => {
19656
+ AlexElement.flatElements(pres[0].children).filter((item) => {
19660
19657
  return item.isText();
19661
19658
  }).forEach((item) => {
19662
19659
  content += item.textContent;
@@ -19666,9 +19663,9 @@ const insertCodeBlock = (editor, dataRangeCaches) => {
19666
19663
  const paragraph = new AlexElement("block", AlexElement.BLOCK_NODE, null, null, null);
19667
19664
  const text2 = new AlexElement("text", null, null, null, item);
19668
19665
  editor.addElementTo(text2, paragraph);
19669
- editor.addElementBefore(paragraph, pre);
19666
+ editor.addElementBefore(paragraph, pres[0]);
19670
19667
  });
19671
- pre.toEmpty();
19668
+ pres[0].toEmpty();
19672
19669
  } else {
19673
19670
  if (editor.range.anchor.isEqual(editor.range.focus)) {
19674
19671
  const block = editor.range.anchor.element.getBlock();
@@ -19690,30 +19687,30 @@ const insertCodeBlock = (editor, dataRangeCaches) => {
19690
19687
  obj[el.element.getBlock().key] = [el.element.clone()];
19691
19688
  }
19692
19689
  });
19693
- const pre2 = new AlexElement("block", "pre", null, null, null);
19690
+ const pre = new AlexElement("block", "pre", null, null, null);
19694
19691
  Object.keys(obj).forEach((key, index) => {
19695
19692
  if (index > 0) {
19696
19693
  const text2 = new AlexElement("text", null, null, null, "\n");
19697
- if (pre2.hasChildren()) {
19698
- editor.addElementTo(text2, pre2, pre2.children.length);
19694
+ if (pre.hasChildren()) {
19695
+ editor.addElementTo(text2, pre, pre.children.length);
19699
19696
  } else {
19700
- editor.addElementTo(text2, pre2);
19697
+ editor.addElementTo(text2, pre);
19701
19698
  }
19702
19699
  }
19703
19700
  obj[key].forEach((el) => {
19704
- if (pre2.hasChildren()) {
19705
- editor.addElementTo(el, pre2, pre2.children.length);
19701
+ if (pre.hasChildren()) {
19702
+ editor.addElementTo(el, pre, pre.children.length);
19706
19703
  } else {
19707
- editor.addElementTo(el, pre2);
19704
+ editor.addElementTo(el, pre);
19708
19705
  }
19709
19706
  });
19710
19707
  });
19711
19708
  editor.delete();
19712
- editor.insertElement(pre2);
19709
+ editor.insertElement(pre);
19713
19710
  const paragraph = new AlexElement("block", AlexElement.BLOCK_NODE, null, null, null);
19714
19711
  const breakEl = new AlexElement("closed", "br", null, null, null);
19715
19712
  editor.addElementTo(breakEl, paragraph);
19716
- editor.addElementAfter(paragraph, pre2);
19713
+ editor.addElementAfter(paragraph, pre);
19717
19714
  }
19718
19715
  }
19719
19716
  };
@@ -19863,6 +19860,11 @@ const tableHandle = function(editor, element2) {
19863
19860
  let colgroup = elements.find((el) => {
19864
19861
  return el.parsedom == "colgroup";
19865
19862
  });
19863
+ const colNumber = Math.max(
19864
+ ...rows.map((row) => {
19865
+ return row.children.length;
19866
+ })
19867
+ );
19866
19868
  if (colgroup) {
19867
19869
  colgroup.children.forEach((col) => {
19868
19870
  if (!col.hasMarks()) {
@@ -19873,9 +19875,23 @@ const tableHandle = function(editor, element2) {
19873
19875
  col.marks["width"] = "auto";
19874
19876
  }
19875
19877
  });
19878
+ const length = colgroup.children.length;
19879
+ if (length < colNumber) {
19880
+ for (let i = 0; i < colNumber - length; i++) {
19881
+ const col = new AlexElement(
19882
+ "closed",
19883
+ "col",
19884
+ {
19885
+ width: "auto"
19886
+ },
19887
+ null,
19888
+ null
19889
+ );
19890
+ editor.addElementTo(col, colgroup, colgroup.children.length);
19891
+ }
19892
+ }
19876
19893
  } else {
19877
19894
  colgroup = new AlexElement("inblock", "colgroup", null, null, null);
19878
- const colNumber = getColNumbers(rows[0]);
19879
19895
  for (let i = colNumber - 1; i >= 0; i--) {
19880
19896
  const col = new AlexElement(
19881
19897
  "closed",
@@ -19892,6 +19908,15 @@ const tableHandle = function(editor, element2) {
19892
19908
  element2.children = [];
19893
19909
  const tbody = new AlexElement("inblock", "tbody", null, null, null);
19894
19910
  rows.reverse().forEach((row) => {
19911
+ const length = row.children.length;
19912
+ if (length < colNumber) {
19913
+ for (let i = 0; i < colNumber - length; i++) {
19914
+ const column = new AlexElement("inblock", "td", null, null, null);
19915
+ const breakElement = new AlexElement("closed", "br", null, null, null);
19916
+ editor.addElementTo(breakElement, column);
19917
+ editor.addElementTo(column, row, row.children.length);
19918
+ }
19919
+ }
19895
19920
  editor.addElementTo(row, tbody);
19896
19921
  });
19897
19922
  editor.addElementTo(tbody, element2);
@@ -19900,6 +19925,21 @@ const tableHandle = function(editor, element2) {
19900
19925
  if (element2.parsedom == "th") {
19901
19926
  element2.parsedom = "td";
19902
19927
  }
19928
+ if (element2.parsedom == "td") {
19929
+ if (element2.hasMarks()) {
19930
+ if (element2.marks["rowspan"]) {
19931
+ delete element2.marks["rowspan"];
19932
+ }
19933
+ if (element2.marks["colspan"]) {
19934
+ delete element2.marks["colspan"];
19935
+ }
19936
+ }
19937
+ if (element2.hasStyles()) {
19938
+ if (element2.styles["display"]) {
19939
+ delete element2.styles["display"];
19940
+ }
19941
+ }
19942
+ }
19903
19943
  };
19904
19944
  const preHandle = function(editor, element2, highlight2, languages2) {
19905
19945
  if (element2.parsedom == "pre") {
@@ -21753,34 +21793,34 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21753
21793
  if (!linkConfig.value.url) {
21754
21794
  return;
21755
21795
  }
21756
- const link = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "a");
21757
- if (link) {
21758
- link.marks.href = linkConfig.value.url;
21796
+ const links = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "a" });
21797
+ if (links.length == 1) {
21798
+ links[0].marks.href = linkConfig.value.url;
21759
21799
  if (linkConfig.value.newOpen) {
21760
- link.marks.target = "_blank";
21800
+ links[0].marks.target = "_blank";
21761
21801
  } else {
21762
- delete link.marks.target;
21802
+ delete links[0].marks.target;
21763
21803
  }
21804
+ editor.value.formatElementStack();
21805
+ editor.value.domRender();
21764
21806
  }
21765
- editor.value.formatElementStack();
21766
- editor.value.domRender();
21767
21807
  };
21768
21808
  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"];
21809
+ const links = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "a" });
21810
+ if (links.length == 1) {
21811
+ links[0].parsedom = AlexElement.TEXT_NODE;
21812
+ delete links[0].marks["target"];
21813
+ delete links[0].marks["href"];
21814
+ delete links[0].marks["data-editify-element"];
21815
+ editor.value.formatElementStack();
21816
+ editor.value.domRender();
21817
+ editor.value.rangeRender();
21775
21818
  }
21776
- editor.value.formatElementStack();
21777
- editor.value.domRender();
21778
- editor.value.rangeRender();
21779
21819
  };
21780
21820
  const selectLanguage = (_name, value) => {
21781
- const pre = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "pre");
21782
- if (pre) {
21783
- Object.assign(pre.marks, {
21821
+ const pres = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "pre" });
21822
+ if (pres.length == 1) {
21823
+ Object.assign(pres[0].marks, {
21784
21824
  "data-editify-hljs": value
21785
21825
  });
21786
21826
  editor.value.formatElementStack();
@@ -21793,15 +21833,15 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21793
21833
  editor.value.range.anchor.element = editor.value.range.focus.element;
21794
21834
  editor.value.range.anchor.offset = editor.value.range.focus.offset;
21795
21835
  }
21796
- const pre = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "pre");
21797
- if (pre) {
21836
+ const pres = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "pre" });
21837
+ if (pres.length == 1) {
21798
21838
  const paragraph = new AlexElement("block", AlexElement.BLOCK_NODE, null, null, null);
21799
21839
  const breakEl = new AlexElement("closed", "br", null, null, null);
21800
21840
  editor.value.addElementTo(breakEl, paragraph);
21801
21841
  if (type == "up") {
21802
- editor.value.addElementBefore(paragraph, pre);
21842
+ editor.value.addElementBefore(paragraph, pres[0]);
21803
21843
  } else {
21804
- editor.value.addElementAfter(paragraph, pre);
21844
+ editor.value.addElementAfter(paragraph, pres[0]);
21805
21845
  }
21806
21846
  editor.value.range.anchor.moveToEnd(paragraph);
21807
21847
  editor.value.range.focus.moveToEnd(paragraph);
@@ -21815,16 +21855,16 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21815
21855
  editor.value.range.anchor.element = editor.value.range.focus.element;
21816
21856
  editor.value.range.anchor.offset = editor.value.range.focus.offset;
21817
21857
  }
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);
21858
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
21859
+ const columns = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "td" });
21860
+ const tbodys = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "tbody" });
21861
+ if (tables.length == 1 && tbodys.length == 1 && columns.length == 1) {
21862
+ const rows = tbodys[0].children;
21863
+ const index = columns[0].parent.children.findIndex((item) => {
21864
+ return item.isEqual(columns[0]);
21825
21865
  });
21826
21866
  rows.forEach((row) => {
21827
- const newColumn = column.clone(false);
21867
+ const newColumn = columns[0].clone(false);
21828
21868
  const breakEl = new AlexElement("closed", "br", null, null, null);
21829
21869
  editor.value.addElementTo(breakEl, newColumn);
21830
21870
  if (type == "left") {
@@ -21833,7 +21873,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21833
21873
  editor.value.addElementTo(newColumn, row, index + 1);
21834
21874
  }
21835
21875
  });
21836
- const colgroup = table.children.find((item) => {
21876
+ const colgroup = tables[0].children.find((item) => {
21837
21877
  return item.parsedom == "colgroup";
21838
21878
  });
21839
21879
  const col = new AlexElement("closed", "col", null, null, null);
@@ -21844,11 +21884,11 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21844
21884
  }
21845
21885
  editor.value.formatElementStack();
21846
21886
  if (type == "left") {
21847
- const previousColumn = editor.value.getPreviousElement(column);
21887
+ const previousColumn = editor.value.getPreviousElement(columns[0]);
21848
21888
  editor.value.range.anchor.moveToStart(previousColumn);
21849
21889
  editor.value.range.focus.moveToStart(previousColumn);
21850
21890
  } else {
21851
- const nextColumn = editor.value.getNextElement(column);
21891
+ const nextColumn = editor.value.getNextElement(columns[0]);
21852
21892
  editor.value.range.anchor.moveToStart(nextColumn);
21853
21893
  editor.value.range.focus.moveToStart(nextColumn);
21854
21894
  }
@@ -21861,19 +21901,19 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21861
21901
  editor.value.range.anchor.element = editor.value.range.focus.element;
21862
21902
  editor.value.range.anchor.offset = editor.value.range.focus.offset;
21863
21903
  }
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();
21904
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
21905
+ const rows = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "tr" });
21906
+ if (tables.length == 1 && rows.length == 1) {
21907
+ const newRow = rows[0].clone();
21868
21908
  newRow.children.forEach((column) => {
21869
21909
  column.children = [];
21870
21910
  const breakEl = new AlexElement("closed", "br", null, null, null);
21871
21911
  editor.value.addElementTo(breakEl, column);
21872
21912
  });
21873
21913
  if (type == "up") {
21874
- editor.value.addElementBefore(newRow, row);
21914
+ editor.value.addElementBefore(newRow, rows[0]);
21875
21915
  } else {
21876
- editor.value.addElementAfter(newRow, row);
21916
+ editor.value.addElementAfter(newRow, rows[0]);
21877
21917
  }
21878
21918
  editor.value.formatElementStack();
21879
21919
  editor.value.range.anchor.moveToStart(newRow);
@@ -21886,15 +21926,15 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21886
21926
  }
21887
21927
  };
21888
21928
  const insertParagraphWithTable = (type = "up") => {
21889
- const table = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "table");
21890
- if (table) {
21929
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
21930
+ if (tables.length == 1) {
21891
21931
  const paragraph = new AlexElement("block", AlexElement.BLOCK_NODE, null, null, null);
21892
21932
  const breakEl = new AlexElement("closed", "br", null, null, null);
21893
21933
  editor.value.addElementTo(breakEl, paragraph);
21894
21934
  if (type == "up") {
21895
- editor.value.addElementBefore(paragraph, table);
21935
+ editor.value.addElementBefore(paragraph, tables[0]);
21896
21936
  } else {
21897
- editor.value.addElementAfter(paragraph, table);
21937
+ editor.value.addElementAfter(paragraph, tables[0]);
21898
21938
  }
21899
21939
  editor.value.range.anchor.moveToEnd(paragraph);
21900
21940
  editor.value.range.focus.moveToEnd(paragraph);
@@ -21904,9 +21944,9 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21904
21944
  }
21905
21945
  };
21906
21946
  const deleteElement = (parsedom) => {
21907
- const element2 = getCurrentParsedomElement(editor.value, dataRangeCaches.value, parsedom);
21908
- if (element2) {
21909
- element2.toEmpty();
21947
+ const elements = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom });
21948
+ if (elements.length == 1) {
21949
+ elements[0].toEmpty();
21910
21950
  editor.value.formatElementStack();
21911
21951
  editor.value.domRender();
21912
21952
  editor.value.rangeRender();
@@ -21917,17 +21957,17 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21917
21957
  editor.value.range.anchor.element = editor.value.range.focus.element;
21918
21958
  editor.value.range.anchor.offset = editor.value.range.focus.offset;
21919
21959
  }
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;
21960
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
21961
+ const rows = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "tr" });
21962
+ if (tables.length == 1 && rows.length == 1) {
21963
+ const parent = rows[0].parent;
21924
21964
  if (parent.children.length == 1) {
21925
21965
  deleteElement("table");
21926
21966
  return;
21927
21967
  }
21928
- const previousRow = editor.value.getPreviousElement(row);
21929
- const nextRow = editor.value.getNextElement(row);
21930
- row.toEmpty();
21968
+ const previousRow = editor.value.getPreviousElement(rows[0]);
21969
+ const nextRow = editor.value.getNextElement(rows[0]);
21970
+ rows[0].toEmpty();
21931
21971
  editor.value.formatElementStack();
21932
21972
  if (previousRow) {
21933
21973
  editor.value.range.anchor.moveToEnd(previousRow.children[0]);
@@ -21948,25 +21988,25 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21948
21988
  editor.value.range.anchor.element = editor.value.range.focus.element;
21949
21989
  editor.value.range.anchor.offset = editor.value.range.focus.offset;
21950
21990
  }
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;
21991
+ const columns = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "td" });
21992
+ const tbodys = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "tbody" });
21993
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
21994
+ if (tables.length == 1 && tbodys.length == 1 && columns.length == 1) {
21995
+ const rows = tbodys[0].children;
21996
+ const parent = columns[0].parent;
21957
21997
  if (parent.children.length == 1) {
21958
21998
  deleteElement("table");
21959
21999
  return;
21960
22000
  }
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);
22001
+ const previousColumn = editor.value.getPreviousElement(columns[0]);
22002
+ const nextColumn = editor.value.getNextElement(columns[0]);
22003
+ const index = columns[0].parent.children.findIndex((item) => {
22004
+ return item.isEqual(columns[0]);
21965
22005
  });
21966
22006
  rows.forEach((row) => {
21967
22007
  row.children[index].toEmpty();
21968
22008
  });
21969
- const colgroup = table.children.find((item) => {
22009
+ const colgroup = tables[0].children.find((item) => {
21970
22010
  return item.parsedom == "colgroup";
21971
22011
  });
21972
22012
  colgroup.children[index].toEmpty();
@@ -21983,24 +22023,26 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
21983
22023
  }
21984
22024
  };
21985
22025
  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";
22026
+ if (props.type == "link") {
22027
+ const links = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "a" });
22028
+ if (links.length == 1) {
22029
+ linkConfig.value.url = links[0].marks["href"];
22030
+ linkConfig.value.newOpen = links[0].marks["target"] == "_blank";
21996
22031
  }
21997
22032
  } 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"];
22033
+ const videos = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "video" });
22034
+ if (videos.length == 1) {
22035
+ videoConfig.value.autoplay = !!videos[0].marks["autoplay"];
22036
+ videoConfig.value.loop = !!videos[0].marks["loop"];
22037
+ videoConfig.value.controls = !!videos[0].marks["controls"];
22038
+ videoConfig.value.muted = !!videos[0].marks["muted"];
22039
+ }
22040
+ } else if (props.type == "codeBlock") {
22041
+ const pres = getMatchElementsByRange(editor.value, dataRangeCaches.value, {
22042
+ parsedom: "pre"
22043
+ });
22044
+ if (pres.length == 1) {
22045
+ languageConfig.value.displayConfig.value = pres[0].marks["data-editify-hljs"] || "";
22004
22046
  }
22005
22047
  } else if (props.type == "text") {
22006
22048
  const extraDisabled = (name) => {
@@ -22437,6 +22479,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
22437
22479
  }, 8, ["title", "tooltip", "color"]),
22438
22480
  createVNode(Button, {
22439
22481
  onOperate: _cache[18] || (_cache[18] = ($event) => deleteElement("table")),
22482
+ leftBorder: "",
22440
22483
  name: "deleteTable",
22441
22484
  title: unref($editTrans)("deleteTable"),
22442
22485
  tooltip: _ctx.config.tooltip,
@@ -22821,7 +22864,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
22821
22864
  };
22822
22865
  }
22823
22866
  });
22824
- const Toolbar = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["__scopeId", "data-v-357be052"]]);
22867
+ const Toolbar = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["__scopeId", "data-v-f6219d4c"]]);
22825
22868
  const InsertLinkProps = {
22826
22869
  //主题色
22827
22870
  color: {
@@ -24142,7 +24185,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
24142
24185
  imageConfig.value.disabled = value_hasPreInRange || extraDisabled("image");
24143
24186
  videoConfig.value.disabled = value_hasPreInRange || extraDisabled("video");
24144
24187
  tableConfig.value.disabled = value_hasPreInRange || value_hasTableInRange || value_hasQuoteInRange || extraDisabled("table");
24145
- codeBlockConfig.value.active = !!getCurrentParsedomElement(editor.value, dataRangeCaches.value, "pre");
24188
+ codeBlockConfig.value.active = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "pre" }).length == 1;
24146
24189
  codeBlockConfig.value.disabled = value_hasTableInRange || value_hasQuoteInRange || value_hasImageInRange || value_hasVideoInRange || extraDisabled("codeBlock");
24147
24190
  sourceViewConfig.value.active = isSourceView.value;
24148
24191
  fullScreenConfig.value.active = isFullScreen.value;
@@ -24854,7 +24897,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
24854
24897
  };
24855
24898
  }
24856
24899
  });
24857
- const Menu = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-13b11735"]]);
24900
+ const Menu = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-6c75ad6c"]]);
24858
24901
  const EditifyProps = {
24859
24902
  //国际化语言类型
24860
24903
  locale: {
@@ -25103,6 +25146,7 @@ const en_US = {
25103
25146
  attachmentDefaultName: "attachment",
25104
25147
  //数学公式插件语言配置
25105
25148
  insertMathformula: "Insert mathematical formula",
25149
+ editMathformula: "Edit mathematical formula",
25106
25150
  mathformulaPlaceholder: "Please enter LaTex syntax"
25107
25151
  };
25108
25152
  const zh_CN = {
@@ -25202,6 +25246,7 @@ const zh_CN = {
25202
25246
  attachmentDefaultName: "附件",
25203
25247
  //数学公式插件语言配置
25204
25248
  insertMathformula: "插入数学公式",
25249
+ editMathformula: "编辑数学公式",
25205
25250
  mathformulaPlaceholder: "请输入LaTex语法"
25206
25251
  };
25207
25252
  const trans = (locale) => {
@@ -25334,46 +25379,46 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
25334
25379
  }
25335
25380
  hideToolbar();
25336
25381
  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) {
25382
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
25383
+ const pres = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "pre" });
25384
+ const links = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "a" });
25385
+ const images = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "img" });
25386
+ const videos = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "video" });
25387
+ if (links.length == 1) {
25343
25388
  toolbarOptions.value.type = "link";
25344
- toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${link.key}"]`;
25389
+ toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${links[0].key}"]`;
25345
25390
  if (toolbarOptions.value.show) {
25346
25391
  toolbarRef.value.$refs.layerRef.setPosition();
25347
25392
  } else {
25348
25393
  toolbarOptions.value.show = true;
25349
25394
  }
25350
- } else if (image) {
25395
+ } else if (images.length == 1) {
25351
25396
  toolbarOptions.value.type = "image";
25352
- toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${image.key}"]`;
25397
+ toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${images[0].key}"]`;
25353
25398
  if (toolbarOptions.value.show) {
25354
25399
  toolbarRef.value.$refs.layerRef.setPosition();
25355
25400
  } else {
25356
25401
  toolbarOptions.value.show = true;
25357
25402
  }
25358
- } else if (video) {
25403
+ } else if (videos.length == 1) {
25359
25404
  toolbarOptions.value.type = "video";
25360
- toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${video.key}"]`;
25405
+ toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${videos[0].key}"]`;
25361
25406
  if (toolbarOptions.value.show) {
25362
25407
  toolbarRef.value.$refs.layerRef.setPosition();
25363
25408
  } else {
25364
25409
  toolbarOptions.value.show = true;
25365
25410
  }
25366
- } else if (table) {
25411
+ } else if (tables.length == 1) {
25367
25412
  toolbarOptions.value.type = "table";
25368
- toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${table.key}"]`;
25413
+ toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${tables[0].key}"]`;
25369
25414
  if (toolbarOptions.value.show) {
25370
25415
  toolbarRef.value.$refs.layerRef.setPosition();
25371
25416
  } else {
25372
25417
  toolbarOptions.value.show = true;
25373
25418
  }
25374
- } else if (pre) {
25419
+ } else if (pres.length == 1) {
25375
25420
  toolbarOptions.value.type = "codeBlock";
25376
- toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${pre.key}"]`;
25421
+ toolbarOptions.value.node = `[data-editify-uid="${instance.uid}"] [data-editify-element="${pres[0].key}"]`;
25377
25422
  if (toolbarOptions.value.show) {
25378
25423
  toolbarRef.value.$refs.layerRef.setPosition();
25379
25424
  } else {
@@ -25505,11 +25550,11 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
25505
25550
  if (!tableColumnResizeParams.value.element) {
25506
25551
  return;
25507
25552
  }
25508
- const table = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "table");
25509
- if (!table) {
25553
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
25554
+ if (tables.length != 1) {
25510
25555
  return;
25511
25556
  }
25512
- const colgroup = table.children.find((item) => {
25557
+ const colgroup = tables[0].children.find((item) => {
25513
25558
  return item.parsedom == "colgroup";
25514
25559
  });
25515
25560
  const index = tableColumnResizeParams.value.element.parent.children.findIndex((el) => {
@@ -25527,11 +25572,11 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
25527
25572
  if (!tableColumnResizeParams.value.element) {
25528
25573
  return;
25529
25574
  }
25530
- const table = getCurrentParsedomElement(editor.value, dataRangeCaches.value, "table");
25531
- if (!table) {
25575
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
25576
+ if (tables.length != 1) {
25532
25577
  return;
25533
25578
  }
25534
- const colgroup = table.children.find((item) => {
25579
+ const colgroup = tables[0].children.find((item) => {
25535
25580
  return item.parsedom == "colgroup";
25536
25581
  });
25537
25582
  const index = tableColumnResizeParams.value.element.parent.children.findIndex((el) => {
@@ -25592,9 +25637,6 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
25592
25637
  if (el.marks["disabled"]) {
25593
25638
  marks["disabled"] = el.marks["disabled"];
25594
25639
  }
25595
- if (el.parsedom == "td" && el.marks["colspan"]) {
25596
- marks["colspan"] = el.marks["colspan"];
25597
- }
25598
25640
  if (["img", "video"].includes(el.parsedom) && el.marks["src"]) {
25599
25641
  marks["src"] = el.marks["src"];
25600
25642
  }
@@ -25651,12 +25693,10 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
25651
25693
  }
25652
25694
  });
25653
25695
  if (typeof props.pasteKeepMarks == "function") {
25654
- const keepMarks = props.pasteKeepMarks(el);
25655
- marks = mergeObject(marks, keepMarks);
25696
+ marks = mergeObject(marks, props.pasteKeepMarks(el));
25656
25697
  }
25657
25698
  if (typeof props.pasteKeepStyles == "function") {
25658
- const keepStyles = props.pasteKeepStyles(el);
25659
- styles2 = mergeObject(styles2, keepStyles);
25699
+ styles2 = mergeObject(styles2, props.pasteKeepStyles(el));
25660
25700
  }
25661
25701
  el.marks = marks;
25662
25702
  el.styles = styles2;
@@ -26021,7 +26061,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
26021
26061
  };
26022
26062
  }
26023
26063
  });
26024
- const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-20ab798b"]]);
26064
+ const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-fcc910d9"]]);
26025
26065
  const InsertAttachmentProps = {
26026
26066
  //主题色
26027
26067
  color: {
@@ -40765,7 +40805,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
40765
40805
  );
40766
40806
  return (_ctx, _cache) => {
40767
40807
  return openBlock(), createElementBlock("div", _hoisted_1, [
40768
- createElementVNode("div", _hoisted_2, toDisplayString(unref($editTrans)("insertMathformula")), 1),
40808
+ createElementVNode("div", _hoisted_2, toDisplayString(props.defaultLaTexContent ? unref($editTrans)("editMathformula") : unref($editTrans)("insertMathformula")), 1),
40769
40809
  withDirectives(createElementVNode("textarea", {
40770
40810
  class: "editify-mathformula-textarea",
40771
40811
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => latexContent.value = $event),
@@ -40790,7 +40830,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
40790
40830
  };
40791
40831
  }
40792
40832
  });
40793
- const InsertMathformula = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-ed1761a7"]]);
40833
+ const InsertMathformula = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-980bdb1d"]]);
40794
40834
  const isMathformula = (el) => {
40795
40835
  return el.parsedom == "span" && el.hasMarks() && el.marks["data-editify-mathformula"];
40796
40836
  };
@@ -41145,7 +41185,7 @@ const attachment = (options) => {
41145
41185
  const install = (app) => {
41146
41186
  app.component(Editify.name, Editify);
41147
41187
  };
41148
- const version = "0.1.40";
41188
+ const version = "0.1.42";
41149
41189
  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
41190
  export {
41151
41191
  AlexElement,
@@ -41154,10 +41194,11 @@ export {
41154
41194
  install as default,
41155
41195
  elementIsInList,
41156
41196
  elementIsInTask,
41157
- getCurrentParsedomElement,
41197
+ elementIsMatch,
41198
+ getMatchElementByElement,
41199
+ getMatchElementsByRange,
41158
41200
  getMathformulaElement,
41159
41201
  getMathformulaElementByRange,
41160
- getParsedomElementByElement,
41161
41202
  getRangeText,
41162
41203
  hasAttachmentInRange,
41163
41204
  hasImageInRange,