vue-editify 0.1.44 → 0.1.46

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/examples/App.vue CHANGED
@@ -45,7 +45,7 @@
45
45
  <script setup lang="ts">
46
46
  import { h, ref } from 'vue'
47
47
  import { AlexElement, MenuConfigType, Editify, attachment, PluginType, mathformula, ToolbarConfigType, getMatchElementsByRange } from '../src/index'
48
- const val = ref<string>('<table><tbody><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr></tbody></table>')
48
+ const val = ref<string>('<img src="https://www.ling0523.cn/images/image_1_1701871044699.jpg" /><table><colgroup><col width="10000px" /><col/><col/><col/><col/></colgroup><tbody><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr></tbody></table>')
49
49
 
50
50
  const editify = ref<InstanceType<typeof Editify> | null>(null)
51
51
  const menuConfig = ref<MenuConfigType>({
@@ -3,7 +3,7 @@ import { PluginType, MenuConfigType, ObjectType, ToolbarConfigType } from '../co
3
3
  import { AlexElement } from 'alex-editor';
4
4
  import { LocaleType } from '../locale';
5
5
 
6
- export type EditifyTableColumnResizeParamsType = {
6
+ export type EditifyResizeParamsType = {
7
7
  element: AlexElement | null;
8
8
  start: number;
9
9
  };
package/lib/editify.es.js CHANGED
@@ -2786,17 +2786,17 @@ const setRecentlyPoint = function(point) {
2786
2786
  const nextElement = this.getNextElementOfPoint(point);
2787
2787
  const block = point.element.getBlock();
2788
2788
  const inblock = point.element.getInblock();
2789
- if (previousElement && !AlexElement.VOID_NODES.includes(previousElement.parsedom) && inblock && inblock.isContains(previousElement)) {
2789
+ if (previousElement && inblock && inblock.isContains(previousElement)) {
2790
2790
  point.moveToEnd(previousElement);
2791
- } else if (nextElement && !AlexElement.VOID_NODES.includes(nextElement.parsedom) && inblock && inblock.isContains(nextElement)) {
2791
+ } else if (nextElement && inblock && inblock.isContains(nextElement)) {
2792
2792
  point.moveToStart(nextElement);
2793
- } else if (previousElement && !AlexElement.VOID_NODES.includes(previousElement.parsedom) && block.isContains(previousElement)) {
2793
+ } else if (previousElement && block.isContains(previousElement)) {
2794
2794
  point.moveToEnd(previousElement);
2795
- } else if (nextElement && !AlexElement.VOID_NODES.includes(nextElement.parsedom) && block.isContains(nextElement)) {
2795
+ } else if (nextElement && block.isContains(nextElement)) {
2796
2796
  point.moveToStart(nextElement);
2797
- } else if (previousElement && !AlexElement.VOID_NODES.includes(previousElement.parsedom)) {
2797
+ } else if (previousElement) {
2798
2798
  point.moveToEnd(previousElement);
2799
- } else if (nextElement && !AlexElement.VOID_NODES.includes(nextElement.parsedom)) {
2799
+ } else if (nextElement) {
2800
2800
  point.moveToStart(nextElement);
2801
2801
  }
2802
2802
  };
@@ -4200,6 +4200,9 @@ class AlexEditor {
4200
4200
  if (child.isEmpty()) {
4201
4201
  continue;
4202
4202
  }
4203
+ if (!child.isText() && AlexElement.VOID_NODES.includes(child.parsedom)) {
4204
+ continue;
4205
+ }
4203
4206
  if (child.isText() || child.isClosed()) {
4204
4207
  el = child;
4205
4208
  break;
@@ -4217,6 +4220,9 @@ class AlexEditor {
4217
4220
  if (nextElement.isEmpty()) {
4218
4221
  return fn(nextElement);
4219
4222
  }
4223
+ if (!nextElement.isText() && AlexElement.VOID_NODES.includes(nextElement.parsedom)) {
4224
+ return fn(nextElement);
4225
+ }
4220
4226
  if (nextElement.isText() || nextElement.isClosed()) {
4221
4227
  return nextElement;
4222
4228
  }
@@ -4552,7 +4558,7 @@ class AlexEditor {
4552
4558
  event$1.off(this.$el, "beforeinput.alex_editor compositionstart.alex_editor compositionupdate.alex_editor compositionend.alex_editor keydown.alex_editor cut.alex_editor paste.alex_editor copy.alex_editor dragstart.alex_editor drop.alex_editor focus.alex_editor blur.alex_editor");
4553
4559
  }
4554
4560
  }
4555
- const version$2 = "1.4.7";
4561
+ const version$2 = "1.4.8";
4556
4562
  console.log(`%c alex-editor %c v${version$2} `, "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;");
4557
4563
  const number = {
4558
4564
  /**
@@ -25956,7 +25962,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
25956
25962
  const isModelChange = ref(false);
25957
25963
  const isInputChinese = ref(false);
25958
25964
  const rangeUpdateTimer = ref(null);
25959
- const tableColumnResizeParams = ref({
25965
+ const resizeParams = ref({
25960
25966
  element: null,
25961
25967
  //被拖拽的td
25962
25968
  start: 0
@@ -26210,25 +26216,34 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
26210
26216
  if (props.disabled) {
26211
26217
  return;
26212
26218
  }
26213
- if (element.isContains(contentRef.value, e.target)) {
26214
- const elm = e.target;
26219
+ const elm = e.target;
26220
+ const event2 = e;
26221
+ if (element.isContains(contentRef.value, elm)) {
26215
26222
  const key = data.get(elm, "data-alex-editor-key");
26216
26223
  if (key) {
26217
26224
  const element$12 = editor.value.getElementByKey(key);
26218
- if (element$12 && element$12.parsedom == "td") {
26219
- const length = element$12.parent.children.length;
26220
- if (element$12.parent.children[length - 1].isEqual(element$12)) {
26221
- return;
26222
- }
26223
- const rect = element.getElementBounding(elm);
26224
- if (e.pageX >= Math.abs(rect.left + elm.offsetWidth - 5) && e.pageX <= Math.abs(rect.left + elm.offsetWidth + 5)) {
26225
- tableColumnResizeParams.value.element = element$12;
26226
- tableColumnResizeParams.value.start = e.pageX;
26225
+ if (element$12) {
26226
+ if (element$12.parsedom == "td") {
26227
+ const length = element$12.parent.children.length;
26228
+ if (element$12.parent.children[length - 1].isEqual(element$12)) {
26229
+ return;
26230
+ }
26231
+ const rect = element.getElementBounding(elm);
26232
+ if (event2.pageX >= Math.abs(rect.left + elm.offsetWidth - 5) && event2.pageX <= Math.abs(rect.left + elm.offsetWidth + 5)) {
26233
+ resizeParams.value.element = element$12;
26234
+ resizeParams.value.start = event2.pageX;
26235
+ }
26236
+ } else if (["img", "video"].includes(element$12.parsedom)) {
26237
+ const rect = element.getElementBounding(elm);
26238
+ if (event2.pageX >= Math.abs(rect.left + elm.offsetWidth - 10) && event2.pageX <= Math.abs(rect.left + elm.offsetWidth)) {
26239
+ resizeParams.value.element = element$12;
26240
+ resizeParams.value.start = event2.pageX;
26241
+ }
26227
26242
  }
26228
26243
  }
26229
26244
  }
26230
26245
  }
26231
- if (!element.isContains(elRef.value, e.target) && !isSourceView.value) {
26246
+ if (!element.isContains(elRef.value, elm) && !isSourceView.value) {
26232
26247
  canUseMenu.value = false;
26233
26248
  }
26234
26249
  };
@@ -26236,63 +26251,108 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
26236
26251
  if (props.disabled) {
26237
26252
  return;
26238
26253
  }
26239
- if (!tableColumnResizeParams.value.element) {
26240
- return;
26254
+ const event2 = e;
26255
+ const elm = e.target;
26256
+ if (element.isContains(contentRef.value, elm) && ["img", "video"].includes(elm.tagName.toLocaleLowerCase())) {
26257
+ const rect = element.getElementBounding(elm);
26258
+ if (event2.pageX >= Math.abs(rect.left + elm.offsetWidth - 10) && event2.pageX <= Math.abs(rect.left + elm.offsetWidth)) {
26259
+ elm.style.cursor = "col-resize";
26260
+ } else {
26261
+ elm.style.cursor = "";
26262
+ }
26241
26263
  }
26242
- const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
26243
- if (tables.length != 1) {
26264
+ if (!resizeParams.value.element) {
26244
26265
  return;
26245
26266
  }
26246
- const colgroup = tables[0].children.find((item) => {
26247
- return item.parsedom == "colgroup";
26248
- });
26249
- const index = tableColumnResizeParams.value.element.parent.children.findIndex((el) => {
26250
- return el.isEqual(tableColumnResizeParams.value.element);
26251
- });
26252
- const width = `${tableColumnResizeParams.value.element.elm.offsetWidth + e.pageX - tableColumnResizeParams.value.start}`;
26253
- colgroup.children[index].marks["width"] = width;
26254
- colgroup.children[index].elm.setAttribute("width", width);
26255
- tableColumnResizeParams.value.start = e.pageX;
26267
+ if (resizeParams.value.element.parsedom == "td") {
26268
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
26269
+ if (tables.length != 1) {
26270
+ return;
26271
+ }
26272
+ const colgroup = tables[0].children.find((item) => {
26273
+ return item.parsedom == "colgroup";
26274
+ });
26275
+ const index = resizeParams.value.element.parent.children.findIndex((el) => {
26276
+ return el.isEqual(resizeParams.value.element);
26277
+ });
26278
+ const width = `${resizeParams.value.element.elm.offsetWidth + event2.pageX - resizeParams.value.start}`;
26279
+ colgroup.children[index].marks["width"] = width;
26280
+ colgroup.children[index].elm.setAttribute("width", width);
26281
+ resizeParams.value.start = event2.pageX;
26282
+ } else if (["img", "video"].includes(resizeParams.value.element.parsedom)) {
26283
+ const width = `${resizeParams.value.element.elm.offsetWidth + event2.pageX - resizeParams.value.start}px`;
26284
+ if (resizeParams.value.element.hasStyles()) {
26285
+ resizeParams.value.element.styles["width"] = width;
26286
+ } else {
26287
+ resizeParams.value.element.styles = {
26288
+ width
26289
+ };
26290
+ }
26291
+ resizeParams.value.element.elm.style.width = width;
26292
+ if (resizeParams.value.element.parsedom == "video") {
26293
+ setVideoHeight();
26294
+ }
26295
+ resizeParams.value.start = event2.pageX;
26296
+ }
26256
26297
  };
26257
26298
  const documentMouseUp = () => {
26258
26299
  if (props.disabled) {
26259
26300
  return;
26260
26301
  }
26261
- if (!tableColumnResizeParams.value.element) {
26262
- return;
26263
- }
26264
- const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
26265
- if (tables.length != 1) {
26302
+ if (!resizeParams.value.element) {
26266
26303
  return;
26267
26304
  }
26268
- const colgroup = tables[0].children.find((item) => {
26269
- return item.parsedom == "colgroup";
26270
- });
26271
- const index = tableColumnResizeParams.value.element.parent.children.findIndex((el) => {
26272
- return el.isEqual(tableColumnResizeParams.value.element);
26273
- });
26274
- const width = Number(colgroup.children[index].marks["width"]);
26275
- if (!isNaN(width)) {
26276
- colgroup.children[index].marks["width"] = `${Number((width / tableColumnResizeParams.value.element.parent.elm.offsetWidth * 100).toFixed(2))}%`;
26277
- editor.value.formatElementStack();
26278
- editor.value.domRender();
26279
- editor.value.rangeRender();
26305
+ if (resizeParams.value.element.parsedom == "td") {
26306
+ const tables = getMatchElementsByRange(editor.value, dataRangeCaches.value, { parsedom: "table" });
26307
+ if (tables.length != 1) {
26308
+ return;
26309
+ }
26310
+ const colgroup = tables[0].children.find((item) => {
26311
+ return item.parsedom == "colgroup";
26312
+ });
26313
+ const index = resizeParams.value.element.parent.children.findIndex((el) => {
26314
+ return el.isEqual(resizeParams.value.element);
26315
+ });
26316
+ const width = parseFloat(colgroup.children[index].marks["width"]);
26317
+ if (!isNaN(width)) {
26318
+ colgroup.children[index].marks["width"] = `${Number((width / resizeParams.value.element.parent.elm.offsetWidth * 100).toFixed(2))}%`;
26319
+ editor.value.formatElementStack();
26320
+ editor.value.domRender();
26321
+ editor.value.rangeRender();
26322
+ }
26323
+ resizeParams.value.element = null;
26324
+ resizeParams.value.start = 0;
26325
+ } else if (["img", "video"].includes(resizeParams.value.element.parsedom)) {
26326
+ const width = parseFloat(resizeParams.value.element.styles["width"]);
26327
+ if (!isNaN(width)) {
26328
+ if (resizeParams.value.element.hasStyles()) {
26329
+ resizeParams.value.element.styles["width"] = `${Number((width / element.width(contentRef.value) * 100).toFixed(2))}%`;
26330
+ } else {
26331
+ resizeParams.value.element.styles = {
26332
+ width: `${Number((width / element.width(contentRef.value) * 100).toFixed(2))}%`
26333
+ };
26334
+ }
26335
+ editor.value.formatElementStack();
26336
+ editor.value.domRender();
26337
+ editor.value.rangeRender();
26338
+ }
26339
+ resizeParams.value.element = null;
26340
+ resizeParams.value.start = 0;
26280
26341
  }
26281
- tableColumnResizeParams.value.element = null;
26282
- tableColumnResizeParams.value.start = 0;
26283
26342
  };
26284
26343
  const documentClick = (e) => {
26285
26344
  if (props.disabled) {
26286
26345
  return;
26287
26346
  }
26288
- if (element.isContains(contentRef.value, e.target)) {
26289
- const elm = e.target;
26347
+ const elm = e.target;
26348
+ const event2 = e;
26349
+ if (element.isContains(contentRef.value, elm)) {
26290
26350
  const key = data.get(elm, "data-alex-editor-key");
26291
26351
  if (key) {
26292
26352
  const element$12 = editor.value.getElementByKey(key);
26293
26353
  if (isTask(element$12)) {
26294
26354
  const rect = element.getElementBounding(elm);
26295
- if (e.pageX >= Math.abs(rect.left) && e.pageX <= Math.abs(rect.left + 16) && e.pageY >= Math.abs(rect.top + elm.offsetHeight / 2 - 8) && e.pageY <= Math.abs(rect.top + elm.offsetHeight / 2 + 8)) {
26355
+ if (event2.pageX >= Math.abs(rect.left) && event2.pageX <= Math.abs(rect.left + 16) && event2.pageY >= Math.abs(rect.top + elm.offsetHeight / 2 - 8) && event2.pageY <= Math.abs(rect.top + elm.offsetHeight / 2 + 8)) {
26296
26356
  if (element$12.marks["data-editify-task"] == "checked") {
26297
26357
  element$12.marks["data-editify-task"] = "uncheck";
26298
26358
  } else {
@@ -26326,6 +26386,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
26326
26386
  if (el.marks["disabled"]) {
26327
26387
  marks["disabled"] = el.marks["disabled"];
26328
26388
  }
26389
+ if (el.parsedom == "img" && el.marks["alt"]) {
26390
+ marks["alt"] = el.marks["alt"];
26391
+ }
26329
26392
  if (["img", "video"].includes(el.parsedom) && el.marks["src"]) {
26330
26393
  marks["src"] = el.marks["src"];
26331
26394
  }
@@ -26359,6 +26422,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
26359
26422
  if (el.parsedom == "div" && el.marks["data-editify-task"]) {
26360
26423
  marks["data-editify-task"] = el.marks["data-editify-task"];
26361
26424
  }
26425
+ if (el.parsedom == "col" && el.marks["width"]) {
26426
+ marks["width"] = el.marks["width"];
26427
+ }
26362
26428
  if (["td", "th"].includes(el.parsedom) && el.marks["colspan"]) {
26363
26429
  marks["colspan"] = el.marks["colspan"];
26364
26430
  }
@@ -26370,6 +26436,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
26370
26436
  }
26371
26437
  }
26372
26438
  if (el.hasStyles()) {
26439
+ if (["img", "video"].includes(el.parsedom) && el.styles["width"]) {
26440
+ styles2["width"] = el.styles["width"];
26441
+ }
26373
26442
  if ((el.isBlock() || el.isInblock()) && el.styles["text-indent"]) {
26374
26443
  styles2["text-indent"] = el.styles["text-indent"];
26375
26444
  }
@@ -26458,9 +26527,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
26458
26527
  if (props.disabled || isSourceView.value) {
26459
26528
  return;
26460
26529
  }
26461
- const node = e.target;
26462
- if (node.nodeName.toLocaleLowerCase() == "img" || node.nodeName.toLocaleLowerCase() == "video") {
26463
- const key = Number(node.getAttribute("data-editify-element"));
26530
+ const elm = e.target;
26531
+ if (elm.nodeName.toLocaleLowerCase() == "img" || elm.nodeName.toLocaleLowerCase() == "video") {
26532
+ const key = Number(elm.getAttribute("data-editify-element"));
26464
26533
  if (number.isNumber(key)) {
26465
26534
  const element2 = editor.value.getElementByKey(key);
26466
26535
  if (!editor.value.range) {
@@ -26759,7 +26828,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
26759
26828
  };
26760
26829
  }
26761
26830
  });
26762
- const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-57a3c1ea"]]);
26831
+ const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-b4790a4c"]]);
26763
26832
  const InsertAttachmentProps = {
26764
26833
  //主题色
26765
26834
  color: {
@@ -41883,7 +41952,7 @@ const attachment = (options) => {
41883
41952
  const install = (app) => {
41884
41953
  app.component(Editify.name, Editify);
41885
41954
  };
41886
- const version = "0.1.44";
41955
+ const version = "0.1.46";
41887
41956
  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;");
41888
41957
  export {
41889
41958
  AlexElement,