vue-editify 0.1.27 → 0.1.30

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
  /**
@@ -19874,6 +19890,14 @@ const preHandle = function(editor, element2, highlight2, languages2) {
19874
19890
  newEl.parent = element2;
19875
19891
  });
19876
19892
  updateRangeInPre(editor, element2, originalTextElements, newElements);
19893
+ } else {
19894
+ const breakElement = new AlexElement("closed", "br", null, null, null);
19895
+ element2.children = [breakElement];
19896
+ breakElement.parent = element2;
19897
+ if (editor.range) {
19898
+ editor.range.anchor.moveToStart(breakElement);
19899
+ editor.range.focus.moveToStart(breakElement);
19900
+ }
19877
19901
  }
19878
19902
  }
19879
19903
  }
@@ -23379,6 +23403,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23379
23403
  props: MenuProps,
23380
23404
  setup(__props, { expose: __expose }) {
23381
23405
  const props = __props;
23406
+ const $editTrans = inject("$editTrans");
23382
23407
  const editify = inject("editify");
23383
23408
  const isSourceView = inject("isSourceView");
23384
23409
  const isFullScreen = inject("isFullScreen");
@@ -23386,7 +23411,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23386
23411
  const editor = inject("editor");
23387
23412
  const dataRangeCaches = inject("dataRangeCaches");
23388
23413
  const showBorder = inject("showBorder");
23389
- const $editTrans = inject("$editTrans");
23414
+ const pluginResultList = inject("pluginResultList");
23390
23415
  const undoConfig = ref({
23391
23416
  show: props.config.undo.show,
23392
23417
  leftBorder: props.config.undo.leftBorder,
@@ -23659,8 +23684,15 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23659
23684
  return editify.props.disabled || !canUseMenu.value;
23660
23685
  });
23661
23686
  const menuNames = computed(() => {
23662
- return Object.keys(props.config.sequence).sort((a, b) => {
23663
- if (props.config.sequence[a] > props.config.sequence[b]) {
23687
+ let pluginSequence = {};
23688
+ pluginResultList.value.forEach((pluginResult) => {
23689
+ if (pluginResult.menu) {
23690
+ pluginSequence[pluginResult.name] = pluginResult.menu.sequence;
23691
+ }
23692
+ });
23693
+ pluginSequence = mergeObject(pluginSequence, props.config.sequence);
23694
+ return Object.keys(pluginSequence).sort((a, b) => {
23695
+ if (pluginSequence[a] > pluginSequence[b]) {
23664
23696
  return 1;
23665
23697
  }
23666
23698
  return -1;
@@ -23688,6 +23720,15 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23688
23720
  }
23689
23721
  return showBorder.value;
23690
23722
  });
23723
+ const menuExtends = computed(() => {
23724
+ let pluginExtends = {};
23725
+ pluginResultList.value.forEach((pluginResult) => {
23726
+ if (pluginResult.menu) {
23727
+ pluginExtends[pluginResult.name] = pluginResult.menu.extend;
23728
+ }
23729
+ });
23730
+ return mergeObject(pluginExtends, props.config.extends);
23731
+ });
23691
23732
  const handleOperate = (name, val) => {
23692
23733
  if (disabled.value) {
23693
23734
  return;
@@ -23909,11 +23950,24 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23909
23950
  const value_isRangeInOrderList = isRangeInList(editor.value, dataRangeCaches.value, true);
23910
23951
  const value_isRangeInUnorderList = isRangeInList(editor.value, dataRangeCaches.value, false);
23911
23952
  const value_isRangeInTask = isRangeInTask(editor.value, dataRangeCaches.value);
23953
+ const value_hasImageInRange = hasImageInRange(editor.value, dataRangeCaches.value);
23954
+ const value_hasVideoInRange = hasVideoInRange(editor.value, dataRangeCaches.value);
23912
23955
  const extraDisabled = (name) => {
23956
+ let pluginDisabled = false;
23957
+ let length = pluginResultList.value.length;
23958
+ for (let i = 0; i < length; i++) {
23959
+ const pluginResult = pluginResultList.value[i];
23960
+ if (pluginResult.menu && typeof pluginResult.menu.extraDisabled == "function") {
23961
+ pluginDisabled = pluginResult.menu.extraDisabled(name);
23962
+ if (pluginDisabled) {
23963
+ break;
23964
+ }
23965
+ }
23966
+ }
23913
23967
  if (typeof props.config.extraDisabled == "function") {
23914
- return props.config.extraDisabled(name) || false;
23968
+ return props.config.extraDisabled(name) || pluginDisabled || false;
23915
23969
  }
23916
- return false;
23970
+ return pluginDisabled || false;
23917
23971
  };
23918
23972
  undoConfig.value.disabled = !editor.value.history.get(-1) || extraDisabled("undo");
23919
23973
  redoConfig.value.disabled = !editor.value.history.get(1) || extraDisabled("redo");
@@ -24019,7 +24073,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
24019
24073
  videoConfig.value.disabled = value_hasPreInRange || extraDisabled("video");
24020
24074
  tableConfig.value.disabled = value_hasPreInRange || value_hasTableInRange || value_hasQuoteInRange || extraDisabled("table");
24021
24075
  codeBlockConfig.value.active = !!getCurrentParsedomElement(editor.value, dataRangeCaches.value, "pre");
24022
- codeBlockConfig.value.disabled = value_hasTableInRange || value_hasQuoteInRange || extraDisabled("codeBlock");
24076
+ codeBlockConfig.value.disabled = value_hasTableInRange || value_hasQuoteInRange || value_hasImageInRange || value_hasVideoInRange || extraDisabled("codeBlock");
24023
24077
  sourceViewConfig.value.active = isSourceView.value;
24024
24078
  fullScreenConfig.value.active = isFullScreen.value;
24025
24079
  };
@@ -24614,8 +24668,8 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
24614
24668
  () => h(Icon, { value: "full-screen" })
24615
24669
  );
24616
24670
  }
24617
- if (common.isObject(props.config.extends)) {
24618
- const configuration = props.config.extends[itemProps.name];
24671
+ if (common.isObject(menuExtends.value)) {
24672
+ const configuration = menuExtends.value[itemProps.name];
24619
24673
  if (configuration) {
24620
24674
  return h(
24621
24675
  Button,
@@ -24714,7 +24768,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
24714
24768
  };
24715
24769
  }
24716
24770
  });
24717
- const Menu = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-3a513730"]]);
24771
+ const Menu = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-fbf50ae5"]]);
24718
24772
  const EditifyProps = {
24719
24773
  //国际化语言类型
24720
24774
  locale: {
@@ -25068,7 +25122,6 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25068
25122
  const props = __props;
25069
25123
  const emits = __emit;
25070
25124
  const $editTrans = trans(props.locale || "zh_CN");
25071
- provide("$editTrans", $editTrans);
25072
25125
  const isModelChange = ref(false);
25073
25126
  const isInputChinese = ref(false);
25074
25127
  const rangeUpdateTimer = ref(null);
@@ -25137,12 +25190,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25137
25190
  return pluginResultList2;
25138
25191
  });
25139
25192
  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);
25193
+ return mergeObject(getMenuConfig($editTrans, props.locale), props.menu || {});
25146
25194
  });
25147
25195
  const internalModify = (val) => {
25148
25196
  isModelChange.value = true;
@@ -25732,6 +25780,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25732
25780
  event.off(window, `resize.editify_${instance.uid}`);
25733
25781
  editor.value.destroy();
25734
25782
  });
25783
+ provide("$editTrans", $editTrans);
25735
25784
  provide("editify", instance);
25736
25785
  provide("isSourceView", isSourceView);
25737
25786
  provide("isFullScreen", isFullScreen);
@@ -25739,6 +25788,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25739
25788
  provide("editor", editor);
25740
25789
  provide("dataRangeCaches", dataRangeCaches);
25741
25790
  provide("showBorder", showBorder);
25791
+ provide("pluginResultList", pluginResultList);
25742
25792
  __expose({
25743
25793
  editor,
25744
25794
  isSourceView,
@@ -25808,7 +25858,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25808
25858
  };
25809
25859
  }
25810
25860
  });
25811
- const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-3b2e5bbc"]]);
25861
+ const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-306d3e9a"]]);
25812
25862
  const InsertAttachmentProps = {
25813
25863
  //主题色
25814
25864
  color: {
@@ -26053,62 +26103,86 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
26053
26103
  }
26054
26104
  });
26055
26105
  const InsertAttachment = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-f995f4bd"]]);
26106
+ const isAttachment = (element2) => {
26107
+ if (element2.isEmpty()) {
26108
+ return false;
26109
+ }
26110
+ return element2.parsedom == "span" && element2.type == "closed" && element2.hasMarks() && element2.marks["data-attachment"];
26111
+ };
26112
+ const hasAttachmentInRange = (editor, dataRangeCaches) => {
26113
+ if (!editor.range) {
26114
+ return false;
26115
+ }
26116
+ if (editor.range.anchor.isEqual(editor.range.focus)) {
26117
+ return isAttachment(editor.range.anchor.element);
26118
+ }
26119
+ return dataRangeCaches.flatList.some((item) => {
26120
+ return isAttachment(item.element);
26121
+ });
26122
+ };
26056
26123
  const attachment = (options) => {
26057
26124
  if (!common.isObject(options)) {
26058
26125
  options = {};
26059
26126
  }
26060
26127
  const plugin = (editifyInstance, color2, editTrans) => {
26128
+ let isDisabled = false;
26129
+ if (editifyInstance.exposed.editor.value) {
26130
+ 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);
26131
+ }
26061
26132
  return {
26133
+ name: "attachment",
26062
26134
  //附件菜单项配置
26063
26135
  menu: {
26064
- sequence: {
26065
- attachment: options.sequence || 100
26136
+ sequence: options.sequence || 100,
26137
+ extraDisabled: (name) => {
26138
+ if (name == "link" || name == "quote" || name == "codeBlock") {
26139
+ return hasAttachmentInRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value);
26140
+ }
26141
+ return false;
26066
26142
  },
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;
26143
+ extend: {
26144
+ type: "select",
26145
+ title: options.title || editTrans("insertAttachment"),
26146
+ leftBorder: options.leftBorder,
26147
+ rightBorder: options.rightBorder,
26148
+ hideScroll: true,
26149
+ disabled: isDisabled,
26150
+ default: () => h(Icon, { value: "attachment" }),
26151
+ layer: (_name, btnInstance) => h(InsertAttachment, {
26152
+ color: color2,
26153
+ accept: options.accept,
26154
+ allowedFileType: options.allowedFileType || [],
26155
+ multiple: !!options.multiple,
26156
+ maxSize: options.maxSize,
26157
+ minSize: options.minSize,
26158
+ customUpload: options.customUpload,
26159
+ handleError: options.handleError,
26160
+ onChange: () => {
26161
+ btnInstance.$refs.layerRef.setPosition();
26162
+ },
26163
+ onInsert: (name, url) => {
26164
+ if (url) {
26165
+ const marks = {
26166
+ "data-attachment": url,
26167
+ "data-attachment-name": name || editTrans("attachmentDefaultName"),
26168
+ contenteditable: "false"
26169
+ };
26170
+ const attachmentElement = new AlexElement("closed", "span", marks, null, null);
26171
+ const editor = editifyInstance.exposed.editor.value;
26172
+ editor.insertElement(attachmentElement);
26173
+ const beforeText = AlexElement.getSpaceElement();
26174
+ const afterText = AlexElement.getSpaceElement();
26175
+ editor.addElementAfter(afterText, attachmentElement);
26176
+ editor.addElementBefore(beforeText, attachmentElement);
26177
+ editor.range.anchor.moveToStart(afterText);
26178
+ editor.range.focus.moveToStart(afterText);
26179
+ editor.formatElementStack();
26180
+ editor.domRender();
26181
+ editor.rangeRender();
26109
26182
  }
26110
- })
26111
- }
26183
+ btnInstance.show = false;
26184
+ }
26185
+ })
26112
26186
  }
26113
26187
  },
26114
26188
  //找到附件元素点击下载
@@ -26168,7 +26242,7 @@ const attachment = (options) => {
26168
26242
  const install = (app) => {
26169
26243
  app.component(Editify.name, Editify);
26170
26244
  };
26171
- const version = "0.1.27";
26245
+ const version = "0.1.30";
26172
26246
  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
26247
  export {
26174
26248
  AlexElement,