vue-editify 0.1.24 → 0.1.25

Sign up to get free protection for your applications and to get access to all the features.
package/examples/App.vue CHANGED
@@ -21,7 +21,7 @@ const menuConfig = ref<MenuConfigType>({
21
21
 
22
22
  const plugins = ref<PluginType[]>([
23
23
  attachment({
24
- leftBorder: true
24
+ multiple: true
25
25
  })
26
26
  ])
27
27
  </script>
package/lib/editify.es.js CHANGED
@@ -2466,73 +2466,6 @@ const breakFormat = function(element2) {
2466
2466
  }
2467
2467
  }
2468
2468
  };
2469
- const mergeWithParentElement = function(element2) {
2470
- const canMerge = (parent, child) => {
2471
- if (child.isText() && parent.isInline()) {
2472
- return parent.parsedom == AlexElement.TEXT_NODE;
2473
- }
2474
- if (parent.isInline() && child.isInline() || parent.isInblock() && child.isInblock()) {
2475
- return parent.parsedom == child.parsedom;
2476
- }
2477
- return false;
2478
- };
2479
- const merge = (parent, child) => {
2480
- if (child.isText()) {
2481
- parent.type = "text";
2482
- parent.parsedom = null;
2483
- if (child.hasMarks()) {
2484
- if (parent.hasMarks()) {
2485
- Object.assign(parent.marks, cloneData$1(child.marks));
2486
- } else {
2487
- parent.marks = cloneData$1(child.marks);
2488
- }
2489
- }
2490
- if (child.hasStyles()) {
2491
- if (parent.hasStyles()) {
2492
- Object.assign(parent.styles, cloneData$1(child.styles));
2493
- } else {
2494
- parent.styles = cloneData$1(child.styles);
2495
- }
2496
- }
2497
- parent.textContent = child.textContent;
2498
- parent.children = null;
2499
- if (this.range && child.isContains(this.range.anchor.element)) {
2500
- this.range.anchor.element = parent;
2501
- }
2502
- if (this.range && child.isContains(this.range.focus.element)) {
2503
- this.range.focus.element = parent;
2504
- }
2505
- } else {
2506
- if (child.hasMarks()) {
2507
- if (parent.hasMarks()) {
2508
- Object.assign(parent.marks, cloneData$1(child.marks));
2509
- } else {
2510
- parent.marks = cloneData$1(child.marks);
2511
- }
2512
- }
2513
- if (child.hasStyles()) {
2514
- if (parent.hasStyles()) {
2515
- Object.assign(parent.styles, cloneData$1(child.styles));
2516
- } else {
2517
- parent.styles = cloneData$1(child.styles);
2518
- }
2519
- }
2520
- if (child.hasChildren()) {
2521
- parent.children = [...child.children];
2522
- parent.children.forEach((item) => {
2523
- item.parent = parent;
2524
- });
2525
- }
2526
- mergeElement(parent);
2527
- }
2528
- };
2529
- const mergeElement = (ele) => {
2530
- if (ele.hasChildren() && ele.children.length == 1 && ele.children[0] && canMerge(ele, ele.children[0])) {
2531
- merge(ele, ele.children[0]);
2532
- }
2533
- };
2534
- mergeElement(element2);
2535
- };
2536
2469
  const mergeWithBrotherElement = function(element2) {
2537
2470
  const canMerge = (pel, nel) => {
2538
2471
  if (pel.isEmpty() || nel.isEmpty()) {
@@ -2631,6 +2564,78 @@ const mergeWithBrotherElement = function(element2) {
2631
2564
  };
2632
2565
  mergeElement(element2);
2633
2566
  };
2567
+ const mergeWithParentElement = function(element2) {
2568
+ const canMerge = (parent, child) => {
2569
+ if (child.isText() && parent.isInline()) {
2570
+ return parent.parsedom == AlexElement.TEXT_NODE;
2571
+ }
2572
+ if (parent.isInline() && child.isInline() || parent.isInblock() && child.isInblock()) {
2573
+ return parent.parsedom == child.parsedom;
2574
+ }
2575
+ return false;
2576
+ };
2577
+ const merge = (parent, child) => {
2578
+ if (child.isText()) {
2579
+ parent.type = "text";
2580
+ parent.parsedom = null;
2581
+ if (child.hasMarks()) {
2582
+ if (parent.hasMarks()) {
2583
+ Object.assign(parent.marks, cloneData$1(child.marks));
2584
+ } else {
2585
+ parent.marks = cloneData$1(child.marks);
2586
+ }
2587
+ }
2588
+ if (child.hasStyles()) {
2589
+ if (parent.hasStyles()) {
2590
+ Object.assign(parent.styles, cloneData$1(child.styles));
2591
+ } else {
2592
+ parent.styles = cloneData$1(child.styles);
2593
+ }
2594
+ }
2595
+ parent.textContent = child.textContent;
2596
+ parent.children = null;
2597
+ if (this.range && child.isContains(this.range.anchor.element)) {
2598
+ this.range.anchor.element = parent;
2599
+ }
2600
+ if (this.range && child.isContains(this.range.focus.element)) {
2601
+ this.range.focus.element = parent;
2602
+ }
2603
+ } else {
2604
+ if (child.hasMarks()) {
2605
+ if (parent.hasMarks()) {
2606
+ Object.assign(parent.marks, cloneData$1(child.marks));
2607
+ } else {
2608
+ parent.marks = cloneData$1(child.marks);
2609
+ }
2610
+ }
2611
+ if (child.hasStyles()) {
2612
+ if (parent.hasStyles()) {
2613
+ Object.assign(parent.styles, cloneData$1(child.styles));
2614
+ } else {
2615
+ parent.styles = cloneData$1(child.styles);
2616
+ }
2617
+ }
2618
+ if (child.hasChildren()) {
2619
+ parent.children = [...child.children];
2620
+ parent.children.forEach((item) => {
2621
+ item.parent = parent;
2622
+ });
2623
+ }
2624
+ mergeElement(parent);
2625
+ }
2626
+ };
2627
+ const mergeElement = (ele) => {
2628
+ if (ele.hasChildren() && ele.children.length == 1 && ele.children[0] && canMerge(ele, ele.children[0])) {
2629
+ merge(ele, ele.children[0]);
2630
+ }
2631
+ };
2632
+ mergeElement(element2);
2633
+ };
2634
+ const mergeWithSpaceTextElement = function(element2) {
2635
+ if (element2.isText()) {
2636
+ element2.textContent = element2.textContent.replace(/[\uFEFF]+/, "\uFEFF");
2637
+ }
2638
+ };
2634
2639
  const { Mac } = platform.os();
2635
2640
  const isUndo = function(e) {
2636
2641
  if (Mac) {
@@ -3818,7 +3823,7 @@ class AlexEditor {
3818
3823
  let renderRules = this.renderRules.filter((fn) => {
3819
3824
  return typeof fn == "function";
3820
3825
  });
3821
- [handleNotStackBlock, handleInblockWithOther, handleInlineChildrenNotInblock, breakFormat, mergeWithParentElement, mergeWithBrotherElement, mergeWithParentElement, ...renderRules].forEach((fn) => {
3826
+ [handleNotStackBlock, handleInblockWithOther, handleInlineChildrenNotInblock, breakFormat, mergeWithParentElement, mergeWithBrotherElement, mergeWithParentElement, mergeWithSpaceTextElement, ...renderRules].forEach((fn) => {
3822
3827
  format(this.stack, fn, true);
3823
3828
  });
3824
3829
  handleStackEmpty.apply(this);
@@ -25625,6 +25630,10 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25625
25630
  }
25626
25631
  };
25627
25632
  const handleDeleteComplete = () => {
25633
+ const uneditable = editor.value.range.anchor.element.getUneditableElement();
25634
+ if (uneditable) {
25635
+ uneditable.toEmpty();
25636
+ }
25628
25637
  };
25629
25638
  const handleAfterRender = () => {
25630
25639
  setVideoHeight();
@@ -25817,7 +25826,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25817
25826
  };
25818
25827
  }
25819
25828
  });
25820
- const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-2e9e8fac"]]);
25829
+ const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-8737320e"]]);
25821
25830
  const InsertAttachmentProps = {
25822
25831
  //主题色
25823
25832
  color: {
@@ -26066,8 +26075,6 @@ const attachment = (options) => {
26066
26075
  options = {};
26067
26076
  }
26068
26077
  const plugin = (editifyInstance, color2, editTrans) => {
26069
- const editor = editifyInstance.exposed.editor.value;
26070
- const dataRangeCaches = editifyInstance.exposed.dataRangeCaches.value;
26071
26078
  return {
26072
26079
  //附件菜单项配置
26073
26080
  menu: {
@@ -26080,7 +26087,7 @@ const attachment = (options) => {
26080
26087
  title: options.title || editTrans("insertAttachment"),
26081
26088
  leftBorder: options.leftBorder,
26082
26089
  rightBorder: options.rightBorder,
26083
- disabled: editor ? hasPreInRange(editor, dataRangeCaches) : false,
26090
+ disabled: editifyInstance.exposed.editor.value ? hasPreInRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value) : false,
26084
26091
  default: () => h(Icon, { value: "attachment" }),
26085
26092
  layer: (_name, btnInstance) => h(InsertAttachment, {
26086
26093
  color: color2,
@@ -26095,10 +26102,20 @@ const attachment = (options) => {
26095
26102
  btnInstance.$refs.layerRef.setPosition();
26096
26103
  },
26097
26104
  onInsert: (url) => {
26098
- const attachmentElement = new AlexElement("closed", "span", { "data-attachment": url, contenteditable: "false" }, null, null);
26105
+ const marks = {
26106
+ "data-attachment": url,
26107
+ "data-attachment-name": editTrans("attachmentDownloadName"),
26108
+ contenteditable: "false"
26109
+ };
26110
+ const attachmentElement = new AlexElement("closed", "span", marks, null, null);
26111
+ const editor = editifyInstance.exposed.editor.value;
26099
26112
  editor.insertElement(attachmentElement);
26100
- editor.range.anchor.moveToEnd(attachmentElement);
26101
- editor.range.focus.moveToEnd(attachmentElement);
26113
+ const beforeText = AlexElement.getSpaceElement();
26114
+ const afterText = AlexElement.getSpaceElement();
26115
+ editor.addElementAfter(afterText, attachmentElement);
26116
+ editor.addElementBefore(beforeText, attachmentElement);
26117
+ editor.range.anchor.moveToStart(afterText);
26118
+ editor.range.focus.moveToStart(afterText);
26102
26119
  editor.formatElementStack();
26103
26120
  editor.domRender();
26104
26121
  editor.rangeRender();
@@ -26110,6 +26127,7 @@ const attachment = (options) => {
26110
26127
  },
26111
26128
  //找到附件元素点击下载
26112
26129
  updateView: () => {
26130
+ const editor = editifyInstance.exposed.editor.value;
26113
26131
  AlexElement.flatElements(editor.stack).forEach((el) => {
26114
26132
  if (el.parsedom == "span" && el.hasMarks() && el.marks["data-attachment"]) {
26115
26133
  event.off(el.elm, "click");
@@ -26132,12 +26150,24 @@ const attachment = (options) => {
26132
26150
  },
26133
26151
  //span元素粘贴保留data-attachment
26134
26152
  pasteKeepMarks: {
26135
- "data-attachment": ["span"]
26153
+ "data-attachment": ["span"],
26154
+ "data-attachment-name": ["span"]
26136
26155
  },
26137
- //设置元素的title属性标记
26156
+ //自定义渲染规范
26138
26157
  renderRule: (el) => {
26139
26158
  if (el.type == "closed" && el.hasMarks() && el.marks["data-attachment"]) {
26140
26159
  el.marks["title"] = editTrans("downloadAttachment");
26160
+ const editor = editifyInstance.exposed.editor.value;
26161
+ const previousElement = editor.getPreviousElement(el);
26162
+ const newTextElement = editor.getNextElement(el);
26163
+ if (!previousElement || !previousElement.isSpaceText()) {
26164
+ const spaceText = AlexElement.getSpaceElement();
26165
+ editor.addElementBefore(spaceText, el);
26166
+ }
26167
+ if (!newTextElement || !newTextElement.isSpaceText()) {
26168
+ const spaceText = AlexElement.getSpaceElement();
26169
+ editor.addElementAfter(spaceText, el);
26170
+ }
26141
26171
  }
26142
26172
  }
26143
26173
  };
@@ -26147,7 +26177,7 @@ const attachment = (options) => {
26147
26177
  const install = (app) => {
26148
26178
  app.component(Editify.name, Editify);
26149
26179
  };
26150
- const version = "0.1.24";
26180
+ const version = "0.1.25";
26151
26181
  export {
26152
26182
  AlexElement,
26153
26183
  Editify,