vue-editify 0.1.27 → 0.1.29

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
@@ -2622,7 +2622,23 @@ const mergeWithParentElement = function(element2) {
2622
2622
  };
2623
2623
  const mergeWithSpaceTextElement = function(element2) {
2624
2624
  if (element2.isText()) {
2625
- element2.textContent = element2.textContent.replace(/[\uFEFF]+/, "\uFEFF");
2625
+ let val = element2.textContent;
2626
+ let i = 0;
2627
+ while (i < val.length) {
2628
+ const chart = val.charAt(i);
2629
+ if (isSpaceText(chart) && i > 0 && isSpaceText(val.charAt(i - 1))) {
2630
+ if (this.range && this.range.anchor.element.isEqual(element2) && this.range.anchor.offset >= i + 1) {
2631
+ this.range.anchor.offset -= 1;
2632
+ }
2633
+ if (this.range && this.range.focus.element.isEqual(element2) && this.range.focus.offset >= i + 1) {
2634
+ this.range.focus.offset -= 1;
2635
+ }
2636
+ val = string$1.delete(val, i, 1);
2637
+ } else {
2638
+ i++;
2639
+ }
2640
+ }
2641
+ element2.textContent = val;
2626
2642
  }
2627
2643
  };
2628
2644
  const { Mac } = platform.os();
@@ -4496,7 +4512,7 @@ class AlexEditor {
4496
4512
  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");
4497
4513
  }
4498
4514
  }
4499
- const version$2 = "1.3.32";
4515
+ const version$2 = "1.3.33";
4500
4516
  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;");
4501
4517
  const number = {
4502
4518
  /**
@@ -23379,6 +23395,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23379
23395
  props: MenuProps,
23380
23396
  setup(__props, { expose: __expose }) {
23381
23397
  const props = __props;
23398
+ const $editTrans = inject("$editTrans");
23382
23399
  const editify = inject("editify");
23383
23400
  const isSourceView = inject("isSourceView");
23384
23401
  const isFullScreen = inject("isFullScreen");
@@ -23386,7 +23403,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23386
23403
  const editor = inject("editor");
23387
23404
  const dataRangeCaches = inject("dataRangeCaches");
23388
23405
  const showBorder = inject("showBorder");
23389
- const $editTrans = inject("$editTrans");
23406
+ const pluginResultList = inject("pluginResultList");
23390
23407
  const undoConfig = ref({
23391
23408
  show: props.config.undo.show,
23392
23409
  leftBorder: props.config.undo.leftBorder,
@@ -23659,8 +23676,15 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23659
23676
  return editify.props.disabled || !canUseMenu.value;
23660
23677
  });
23661
23678
  const menuNames = computed(() => {
23662
- return Object.keys(props.config.sequence).sort((a, b) => {
23663
- if (props.config.sequence[a] > props.config.sequence[b]) {
23679
+ let pluginSequence = {};
23680
+ pluginResultList.value.forEach((pluginResult) => {
23681
+ if (pluginResult.menu) {
23682
+ pluginSequence[pluginResult.name] = pluginResult.menu.sequence;
23683
+ }
23684
+ });
23685
+ pluginSequence = mergeObject(pluginSequence, props.config.sequence);
23686
+ return Object.keys(pluginSequence).sort((a, b) => {
23687
+ if (pluginSequence[a] > pluginSequence[b]) {
23664
23688
  return 1;
23665
23689
  }
23666
23690
  return -1;
@@ -23688,6 +23712,15 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23688
23712
  }
23689
23713
  return showBorder.value;
23690
23714
  });
23715
+ const menuExtends = computed(() => {
23716
+ let pluginExtends = {};
23717
+ pluginResultList.value.forEach((pluginResult) => {
23718
+ if (pluginResult.menu) {
23719
+ pluginExtends[pluginResult.name] = pluginResult.menu.extend;
23720
+ }
23721
+ });
23722
+ return mergeObject(pluginExtends, props.config.extends);
23723
+ });
23691
23724
  const handleOperate = (name, val) => {
23692
23725
  if (disabled.value) {
23693
23726
  return;
@@ -23910,10 +23943,21 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23910
23943
  const value_isRangeInUnorderList = isRangeInList(editor.value, dataRangeCaches.value, false);
23911
23944
  const value_isRangeInTask = isRangeInTask(editor.value, dataRangeCaches.value);
23912
23945
  const extraDisabled = (name) => {
23946
+ let pluginDisabled = false;
23947
+ let length = pluginResultList.value.length;
23948
+ for (let i = 0; i < length; i++) {
23949
+ const pluginResult = pluginResultList.value[i];
23950
+ if (pluginResult.menu && typeof pluginResult.menu.extraDisabled == "function") {
23951
+ pluginDisabled = pluginResult.menu.extraDisabled(name);
23952
+ if (pluginDisabled) {
23953
+ break;
23954
+ }
23955
+ }
23956
+ }
23913
23957
  if (typeof props.config.extraDisabled == "function") {
23914
- return props.config.extraDisabled(name) || false;
23958
+ return props.config.extraDisabled(name) || pluginDisabled || false;
23915
23959
  }
23916
- return false;
23960
+ return pluginDisabled || false;
23917
23961
  };
23918
23962
  undoConfig.value.disabled = !editor.value.history.get(-1) || extraDisabled("undo");
23919
23963
  redoConfig.value.disabled = !editor.value.history.get(1) || extraDisabled("redo");
@@ -24614,8 +24658,8 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
24614
24658
  () => h(Icon, { value: "full-screen" })
24615
24659
  );
24616
24660
  }
24617
- if (common.isObject(props.config.extends)) {
24618
- const configuration = props.config.extends[itemProps.name];
24661
+ if (common.isObject(menuExtends.value)) {
24662
+ const configuration = menuExtends.value[itemProps.name];
24619
24663
  if (configuration) {
24620
24664
  return h(
24621
24665
  Button,
@@ -24714,7 +24758,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
24714
24758
  };
24715
24759
  }
24716
24760
  });
24717
- const Menu = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-3a513730"]]);
24761
+ const Menu = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-b3e98aec"]]);
24718
24762
  const EditifyProps = {
24719
24763
  //国际化语言类型
24720
24764
  locale: {
@@ -25068,7 +25112,6 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25068
25112
  const props = __props;
25069
25113
  const emits = __emit;
25070
25114
  const $editTrans = trans(props.locale || "zh_CN");
25071
- provide("$editTrans", $editTrans);
25072
25115
  const isModelChange = ref(false);
25073
25116
  const isInputChinese = ref(false);
25074
25117
  const rangeUpdateTimer = ref(null);
@@ -25137,12 +25180,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25137
25180
  return pluginResultList2;
25138
25181
  });
25139
25182
  const menuConfig = computed(() => {
25140
- let menu = {};
25141
- pluginResultList.value.forEach((pluginResult) => {
25142
- menu = mergeObject(menu, pluginResult.menu || {});
25143
- });
25144
- menu = mergeObject(menu, props.menu || {});
25145
- return mergeObject(getMenuConfig($editTrans, props.locale), menu);
25183
+ return mergeObject(getMenuConfig($editTrans, props.locale), props.menu || {});
25146
25184
  });
25147
25185
  const internalModify = (val) => {
25148
25186
  isModelChange.value = true;
@@ -25732,6 +25770,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25732
25770
  event.off(window, `resize.editify_${instance.uid}`);
25733
25771
  editor.value.destroy();
25734
25772
  });
25773
+ provide("$editTrans", $editTrans);
25735
25774
  provide("editify", instance);
25736
25775
  provide("isSourceView", isSourceView);
25737
25776
  provide("isFullScreen", isFullScreen);
@@ -25739,6 +25778,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25739
25778
  provide("editor", editor);
25740
25779
  provide("dataRangeCaches", dataRangeCaches);
25741
25780
  provide("showBorder", showBorder);
25781
+ provide("pluginResultList", pluginResultList);
25742
25782
  __expose({
25743
25783
  editor,
25744
25784
  isSourceView,
@@ -25808,7 +25848,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25808
25848
  };
25809
25849
  }
25810
25850
  });
25811
- const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-3b2e5bbc"]]);
25851
+ const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-306d3e9a"]]);
25812
25852
  const InsertAttachmentProps = {
25813
25853
  //主题色
25814
25854
  color: {
@@ -26053,62 +26093,86 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
26053
26093
  }
26054
26094
  });
26055
26095
  const InsertAttachment = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-f995f4bd"]]);
26096
+ const isAttachment = (element2) => {
26097
+ if (element2.isEmpty()) {
26098
+ return false;
26099
+ }
26100
+ return element2.parsedom == "span" && element2.type == "closed" && element2.hasMarks() && element2.marks["data-attachment"];
26101
+ };
26102
+ const hasAttachmentInRange = (editor, dataRangeCaches) => {
26103
+ if (!editor.range) {
26104
+ return false;
26105
+ }
26106
+ if (editor.range.anchor.isEqual(editor.range.focus)) {
26107
+ return isAttachment(editor.range.anchor.element);
26108
+ }
26109
+ return dataRangeCaches.flatList.some((item) => {
26110
+ return isAttachment(item.element);
26111
+ });
26112
+ };
26056
26113
  const attachment = (options) => {
26057
26114
  if (!common.isObject(options)) {
26058
26115
  options = {};
26059
26116
  }
26060
26117
  const plugin = (editifyInstance, color2, editTrans) => {
26118
+ let isDisabled = false;
26119
+ if (editifyInstance.exposed.editor.value) {
26120
+ isDisabled = hasPreInRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value) || hasLinkInRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value) || hasQuoteInRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value);
26121
+ }
26061
26122
  return {
26123
+ name: "attachment",
26062
26124
  //附件菜单项配置
26063
26125
  menu: {
26064
- sequence: {
26065
- attachment: options.sequence || 100
26126
+ sequence: options.sequence || 100,
26127
+ extraDisabled: (name) => {
26128
+ if (name == "link" || name == "quote") {
26129
+ return hasAttachmentInRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value);
26130
+ }
26131
+ return false;
26066
26132
  },
26067
- extends: {
26068
- attachment: {
26069
- type: "select",
26070
- title: options.title || editTrans("insertAttachment"),
26071
- leftBorder: options.leftBorder,
26072
- rightBorder: options.rightBorder,
26073
- hideScroll: true,
26074
- disabled: editifyInstance.exposed.editor.value ? hasPreInRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value) : false,
26075
- default: () => h(Icon, { value: "attachment" }),
26076
- layer: (_name, btnInstance) => h(InsertAttachment, {
26077
- color: color2,
26078
- accept: options.accept,
26079
- allowedFileType: options.allowedFileType || [],
26080
- multiple: !!options.multiple,
26081
- maxSize: options.maxSize,
26082
- minSize: options.minSize,
26083
- customUpload: options.customUpload,
26084
- handleError: options.handleError,
26085
- onChange: () => {
26086
- btnInstance.$refs.layerRef.setPosition();
26087
- },
26088
- onInsert: (name, url) => {
26089
- if (url) {
26090
- const marks = {
26091
- "data-attachment": url,
26092
- "data-attachment-name": name || editTrans("attachmentDefaultName"),
26093
- contenteditable: "false"
26094
- };
26095
- const attachmentElement = new AlexElement("closed", "span", marks, null, null);
26096
- const editor = editifyInstance.exposed.editor.value;
26097
- editor.insertElement(attachmentElement);
26098
- const beforeText = AlexElement.getSpaceElement();
26099
- const afterText = AlexElement.getSpaceElement();
26100
- editor.addElementAfter(afterText, attachmentElement);
26101
- editor.addElementBefore(beforeText, attachmentElement);
26102
- editor.range.anchor.moveToStart(afterText);
26103
- editor.range.focus.moveToStart(afterText);
26104
- editor.formatElementStack();
26105
- editor.domRender();
26106
- editor.rangeRender();
26107
- }
26108
- btnInstance.show = false;
26133
+ extend: {
26134
+ type: "select",
26135
+ title: options.title || editTrans("insertAttachment"),
26136
+ leftBorder: options.leftBorder,
26137
+ rightBorder: options.rightBorder,
26138
+ hideScroll: true,
26139
+ disabled: isDisabled,
26140
+ default: () => h(Icon, { value: "attachment" }),
26141
+ layer: (_name, btnInstance) => h(InsertAttachment, {
26142
+ color: color2,
26143
+ accept: options.accept,
26144
+ allowedFileType: options.allowedFileType || [],
26145
+ multiple: !!options.multiple,
26146
+ maxSize: options.maxSize,
26147
+ minSize: options.minSize,
26148
+ customUpload: options.customUpload,
26149
+ handleError: options.handleError,
26150
+ onChange: () => {
26151
+ btnInstance.$refs.layerRef.setPosition();
26152
+ },
26153
+ onInsert: (name, url) => {
26154
+ if (url) {
26155
+ const marks = {
26156
+ "data-attachment": url,
26157
+ "data-attachment-name": name || editTrans("attachmentDefaultName"),
26158
+ contenteditable: "false"
26159
+ };
26160
+ const attachmentElement = new AlexElement("closed", "span", marks, null, null);
26161
+ const editor = editifyInstance.exposed.editor.value;
26162
+ editor.insertElement(attachmentElement);
26163
+ const beforeText = AlexElement.getSpaceElement();
26164
+ const afterText = AlexElement.getSpaceElement();
26165
+ editor.addElementAfter(afterText, attachmentElement);
26166
+ editor.addElementBefore(beforeText, attachmentElement);
26167
+ editor.range.anchor.moveToStart(afterText);
26168
+ editor.range.focus.moveToStart(afterText);
26169
+ editor.formatElementStack();
26170
+ editor.domRender();
26171
+ editor.rangeRender();
26109
26172
  }
26110
- })
26111
- }
26173
+ btnInstance.show = false;
26174
+ }
26175
+ })
26112
26176
  }
26113
26177
  },
26114
26178
  //找到附件元素点击下载
@@ -26168,7 +26232,7 @@ const attachment = (options) => {
26168
26232
  const install = (app) => {
26169
26233
  app.component(Editify.name, Editify);
26170
26234
  };
26171
- const version = "0.1.27";
26235
+ const version = "0.1.29";
26172
26236
  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;");
26173
26237
  export {
26174
26238
  AlexElement,