vue-editify 0.0.50 → 0.0.51

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
@@ -1938,8 +1938,13 @@ const getNewFlatData = function(arr) {
1938
1938
  newArr.unshift(arr[i]);
1939
1939
  }
1940
1940
  }
1941
- for (let i = 0; i < newArr.length; i++) {
1941
+ let newLength = newArr.length;
1942
+ let handledElementKeys = [];
1943
+ for (let i = 0; i < newLength; i++) {
1942
1944
  const element2 = newArr[i].element;
1945
+ if (handledElementKeys.includes(element2.key)) {
1946
+ continue;
1947
+ }
1943
1948
  if (!element2.offset && element2.parent) {
1944
1949
  const selfIn = newArr.some((item) => {
1945
1950
  return item.element.isEqual(element2.parent);
@@ -1954,7 +1959,9 @@ const getNewFlatData = function(arr) {
1954
1959
  element: element2.parent,
1955
1960
  offset: false
1956
1961
  });
1957
- i++;
1962
+ newLength += 1;
1963
+ handledElementKeys.push(element2.key);
1964
+ i--;
1958
1965
  }
1959
1966
  }
1960
1967
  }
@@ -3477,7 +3484,7 @@ class AlexEditor {
3477
3484
  /**
3478
3485
  * 根据光标进行剪切操作
3479
3486
  */
3480
- async cut() {
3487
+ async cut(useCache = false) {
3481
3488
  if (!this.useClipboard) {
3482
3489
  return;
3483
3490
  }
@@ -3487,7 +3494,7 @@ class AlexEditor {
3487
3494
  if (!this.allowCut) {
3488
3495
  return;
3489
3496
  }
3490
- const result = await this.copy(true);
3497
+ const result = await this.copy(useCache, true);
3491
3498
  if (result) {
3492
3499
  if (!this.disabled) {
3493
3500
  this.delete(true);
@@ -3500,7 +3507,7 @@ class AlexEditor {
3500
3507
  * 根据光标执行复制操作
3501
3508
  * isCut表示是否在执行剪切操作,默认为false,这个参数仅在内部使用
3502
3509
  */
3503
- async copy(isCut = false) {
3510
+ async copy(useCache = false, isCut = false) {
3504
3511
  if (!this.useClipboard) {
3505
3512
  return;
3506
3513
  }
@@ -3510,7 +3517,7 @@ class AlexEditor {
3510
3517
  if (!this.allowCopy) {
3511
3518
  return;
3512
3519
  }
3513
- let result = this.getElementsByRange().includes;
3520
+ let result = this.getElementsByRange(useCache).includes;
3514
3521
  if (result.length == 0) {
3515
3522
  return;
3516
3523
  }
@@ -4196,35 +4203,35 @@ class AlexEditor {
4196
4203
  if (this.disabled) {
4197
4204
  return;
4198
4205
  }
4199
- if (!this.range) {
4200
- const selection2 = window.getSelection();
4201
- selection2.removeAllRanges();
4202
- return;
4206
+ if (this.range) {
4207
+ const handler = (point) => {
4208
+ let node = null;
4209
+ let offset = null;
4210
+ if (point.element.isText()) {
4211
+ node = point.element.elm.childNodes[0];
4212
+ offset = point.offset;
4213
+ } else {
4214
+ node = point.element.parent.elm;
4215
+ const index = point.element.parent.children.findIndex((item) => {
4216
+ return point.element.isEqual(item);
4217
+ });
4218
+ offset = point.offset + index;
4219
+ }
4220
+ return { node, offset };
4221
+ };
4222
+ this.__innerSelectionChange = true;
4223
+ const anchorResult = handler(this.range.anchor);
4224
+ const focusResult = handler(this.range.focus);
4225
+ const selection = window.getSelection();
4226
+ selection.removeAllRanges();
4227
+ const range = document.createRange();
4228
+ range.setStart(anchorResult.node, anchorResult.offset);
4229
+ range.setEnd(focusResult.node, focusResult.offset);
4230
+ selection.addRange(range);
4231
+ } else {
4232
+ const selection = window.getSelection();
4233
+ selection.removeAllRanges();
4203
4234
  }
4204
- const handler = (point) => {
4205
- let node = null;
4206
- let offset = null;
4207
- if (point.element.isText()) {
4208
- node = point.element.elm.childNodes[0];
4209
- offset = point.offset;
4210
- } else {
4211
- node = point.element.parent.elm;
4212
- const index = point.element.parent.children.findIndex((item) => {
4213
- return point.element.isEqual(item);
4214
- });
4215
- offset = point.offset + index;
4216
- }
4217
- return { node, offset };
4218
- };
4219
- this.__innerSelectionChange = true;
4220
- const anchorResult = handler(this.range.anchor);
4221
- const focusResult = handler(this.range.focus);
4222
- const selection = window.getSelection();
4223
- selection.removeAllRanges();
4224
- const range = document.createRange();
4225
- range.setStart(anchorResult.node, anchorResult.offset);
4226
- range.setEnd(focusResult.node, focusResult.offset);
4227
- selection.addRange(range);
4228
4235
  setTimeout(() => {
4229
4236
  setRangeInVisible.apply(this);
4230
4237
  this.__innerSelectionChange = false;
@@ -20043,7 +20050,7 @@ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
20043
20050
  ]);
20044
20051
  }
20045
20052
  const InsertTable = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$2], ["__scopeId", "data-v-227ede65"]]);
20046
- const Menu_vue_vue_type_style_index_0_scoped_c952b6ed_lang = "";
20053
+ const Menu_vue_vue_type_style_index_0_scoped_ad482303_lang = "";
20047
20054
  const _sfc_main$1 = {
20048
20055
  name: "Menu",
20049
20056
  props: {
@@ -21066,6 +21073,9 @@ const _sfc_main$1 = {
21066
21073
  if (this.disabled) {
21067
21074
  return;
21068
21075
  }
21076
+ if (!this.$parent.editor.range) {
21077
+ return;
21078
+ }
21069
21079
  if (name == "undo") {
21070
21080
  this.$parent.undo();
21071
21081
  } else if (name == "redo") {
@@ -21165,6 +21175,9 @@ const _sfc_main$1 = {
21165
21175
  if (this.disabled) {
21166
21176
  return;
21167
21177
  }
21178
+ if (!this.$parent.editor.range) {
21179
+ return;
21180
+ }
21168
21181
  const result = this.$parent.editor.getElementsByRange(useCache).includes;
21169
21182
  const hasPreStyle = this.$parent.hasPreStyle(true);
21170
21183
  const hasTable = this.$parent.hasTable(true);
@@ -21306,8 +21319,8 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
21306
21319
  }), 256))
21307
21320
  ], 14, _hoisted_1$1);
21308
21321
  }
21309
- const Menu = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__scopeId", "data-v-c952b6ed"]]);
21310
- const Editify_vue_vue_type_style_index_0_scoped_ede8b39b_lang = "";
21322
+ const Menu = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__scopeId", "data-v-ad482303"]]);
21323
+ const Editify_vue_vue_type_style_index_0_scoped_80d8535a_lang = "";
21311
21324
  const _sfc_main = {
21312
21325
  name: "editify",
21313
21326
  props: { ...editorProps },
@@ -21420,6 +21433,7 @@ const _sfc_main = {
21420
21433
  this.editor.formatElementStack();
21421
21434
  this.editor.domRender();
21422
21435
  this.editor.rangeRender();
21436
+ this.$refs.content.blur();
21423
21437
  },
21424
21438
  //代码视图切换
21425
21439
  isSourceView(newValue) {
@@ -21850,6 +21864,10 @@ const _sfc_main = {
21850
21864
  if (this.disabled) {
21851
21865
  return;
21852
21866
  }
21867
+ this.canUseMenu = !!this.editor.range;
21868
+ if (!this.editor.range) {
21869
+ return;
21870
+ }
21853
21871
  if (this.updateTimer) {
21854
21872
  clearTimeout(this.updateTimer);
21855
21873
  }
@@ -23013,7 +23031,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
23013
23031
  ], 2)) : createCommentVNode("", true)
23014
23032
  ], 2);
23015
23033
  }
23016
- const Editify = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-ede8b39b"]]);
23034
+ const Editify = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-80d8535a"]]);
23017
23035
  const iconfont = "";
23018
23036
  const en_US = {
23019
23037
  textWrapUp: "Up feed",
@@ -23196,7 +23214,7 @@ const i18n = (locale) => {
23196
23214
  return translations[locale][key];
23197
23215
  };
23198
23216
  };
23199
- const version = "0.0.50";
23217
+ const version = "0.0.51";
23200
23218
  const install = (app, props) => {
23201
23219
  const locale = (props ? props.locale : "zh_CN") || "zh_CN";
23202
23220
  app.provide("$editTrans", i18n(locale));