vue-editify 0.1.26 → 0.1.29

Sign up to get free protection for your applications and to get access to all the features.
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();
@@ -2987,35 +3003,40 @@ const handleChineseInput = function(e) {
2987
3003
  }, 0);
2988
3004
  }
2989
3005
  };
2990
- const handleKeydown = function(e) {
3006
+ const handleKeyboard = function(e) {
2991
3007
  if (this.disabled) {
2992
3008
  return;
2993
3009
  }
2994
3010
  if (this.__isInputChinese) {
2995
3011
  return;
2996
3012
  }
2997
- if (isUndo(e)) {
2998
- e.preventDefault();
2999
- const historyRecord = this.history.get(-1);
3000
- if (historyRecord) {
3001
- this.history.current = historyRecord.current;
3002
- this.stack = historyRecord.stack;
3003
- this.range = historyRecord.range;
3004
- this.formatElementStack();
3005
- this.domRender(true);
3006
- this.rangeRender();
3007
- }
3008
- } else if (isRedo(e)) {
3009
- e.preventDefault();
3010
- const historyRecord = this.history.get(1);
3011
- if (historyRecord) {
3012
- this.history.current = historyRecord.current;
3013
- this.stack = historyRecord.stack;
3014
- this.range = historyRecord.range;
3015
- this.formatElementStack();
3016
- this.domRender(true);
3017
- this.rangeRender();
3013
+ if (e.type == "keydown") {
3014
+ if (isUndo(e)) {
3015
+ e.preventDefault();
3016
+ const historyRecord = this.history.get(-1);
3017
+ if (historyRecord) {
3018
+ this.history.current = historyRecord.current;
3019
+ this.stack = historyRecord.stack;
3020
+ this.range = historyRecord.range;
3021
+ this.formatElementStack();
3022
+ this.domRender(true);
3023
+ this.rangeRender();
3024
+ }
3025
+ } else if (isRedo(e)) {
3026
+ e.preventDefault();
3027
+ const historyRecord = this.history.get(1);
3028
+ if (historyRecord) {
3029
+ this.history.current = historyRecord.current;
3030
+ this.stack = historyRecord.stack;
3031
+ this.range = historyRecord.range;
3032
+ this.formatElementStack();
3033
+ this.domRender(true);
3034
+ this.rangeRender();
3035
+ }
3018
3036
  }
3037
+ this.emit("keydown", this.value, e);
3038
+ } else if (e.type == "keyup") {
3039
+ this.emit("keyup", this.value, e);
3019
3040
  }
3020
3041
  };
3021
3042
  const handleCopy = async function(e) {
@@ -3100,17 +3121,17 @@ const handleDragDrop = async function(e) {
3100
3121
  }
3101
3122
  }
3102
3123
  };
3103
- const handleFocus = function() {
3124
+ const handleFocus = function(e) {
3104
3125
  if (this.disabled) {
3105
3126
  return;
3106
3127
  }
3107
- this.emit("focus", this.value);
3128
+ this.emit("focus", this.value, e);
3108
3129
  };
3109
- const handleBlur = function() {
3130
+ const handleBlur = function(e) {
3110
3131
  if (this.disabled) {
3111
3132
  return;
3112
3133
  }
3113
- this.emit("blur", this.value);
3134
+ this.emit("blur", this.value, e);
3114
3135
  };
3115
3136
  class AlexEditor {
3116
3137
  constructor(node, opts) {
@@ -3160,7 +3181,7 @@ class AlexEditor {
3160
3181
  event$1.on(document, `selectionchange.alex_editor_${this.__guid}`, handleSelectionChange.bind(this));
3161
3182
  event$1.on(this.$el, "beforeinput.alex_editor", handleBeforeInput.bind(this));
3162
3183
  event$1.on(this.$el, "compositionstart.alex_editor compositionupdate.alex_editor compositionend.alex_editor", handleChineseInput.bind(this));
3163
- event$1.on(this.$el, "keydown.alex_editor", handleKeydown.bind(this));
3184
+ event$1.on(this.$el, "keydown.alex_editor keyup.alex_editor", handleKeyboard.bind(this));
3164
3185
  event$1.on(this.$el, "cut.alex_editor", handleCut.bind(this));
3165
3186
  event$1.on(this.$el, "paste.alex_editor", handlePaste.bind(this));
3166
3187
  event$1.on(this.$el, "copy.alex_editor", handleCopy.bind(this));
@@ -4491,6 +4512,8 @@ class AlexEditor {
4491
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");
4492
4513
  }
4493
4514
  }
4515
+ const version$2 = "1.3.33";
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;");
4494
4517
  const number = {
4495
4518
  /**
4496
4519
  * 数字格式化
@@ -23268,7 +23291,7 @@ const _hoisted_4$2 = [
23268
23291
  ];
23269
23292
  const _hoisted_5$1 = { class: "editify-table-footer" };
23270
23293
  const _hoisted_6$1 = { key: 0 };
23271
- const _hoisted_7 = { key: 1 };
23294
+ const _hoisted_7$1 = { key: 1 };
23272
23295
  const _sfc_main$3 = /* @__PURE__ */ defineComponent({
23273
23296
  ...{
23274
23297
  name: "InsertTable"
@@ -23344,7 +23367,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
23344
23367
  }), 256))
23345
23368
  ]),
23346
23369
  createElementVNode("div", _hoisted_5$1, [
23347
- specification.value ? (openBlock(), createElementBlock("span", _hoisted_6$1, toDisplayString(specification.value.x) + " x " + toDisplayString(specification.value.y), 1)) : (openBlock(), createElementBlock("span", _hoisted_7, toDisplayString(unref($editTrans)("insertTable")), 1))
23370
+ specification.value ? (openBlock(), createElementBlock("span", _hoisted_6$1, toDisplayString(specification.value.x) + " x " + toDisplayString(specification.value.y), 1)) : (openBlock(), createElementBlock("span", _hoisted_7$1, toDisplayString(unref($editTrans)("insertTable")), 1))
23348
23371
  ])
23349
23372
  ]);
23350
23373
  };
@@ -23372,6 +23395,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23372
23395
  props: MenuProps,
23373
23396
  setup(__props, { expose: __expose }) {
23374
23397
  const props = __props;
23398
+ const $editTrans = inject("$editTrans");
23375
23399
  const editify = inject("editify");
23376
23400
  const isSourceView = inject("isSourceView");
23377
23401
  const isFullScreen = inject("isFullScreen");
@@ -23379,7 +23403,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23379
23403
  const editor = inject("editor");
23380
23404
  const dataRangeCaches = inject("dataRangeCaches");
23381
23405
  const showBorder = inject("showBorder");
23382
- const $editTrans = inject("$editTrans");
23406
+ const pluginResultList = inject("pluginResultList");
23383
23407
  const undoConfig = ref({
23384
23408
  show: props.config.undo.show,
23385
23409
  leftBorder: props.config.undo.leftBorder,
@@ -23652,8 +23676,15 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23652
23676
  return editify.props.disabled || !canUseMenu.value;
23653
23677
  });
23654
23678
  const menuNames = computed(() => {
23655
- return Object.keys(props.config.sequence).sort((a, b) => {
23656
- 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]) {
23657
23688
  return 1;
23658
23689
  }
23659
23690
  return -1;
@@ -23681,6 +23712,15 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23681
23712
  }
23682
23713
  return showBorder.value;
23683
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
+ });
23684
23724
  const handleOperate = (name, val) => {
23685
23725
  if (disabled.value) {
23686
23726
  return;
@@ -23903,10 +23943,21 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
23903
23943
  const value_isRangeInUnorderList = isRangeInList(editor.value, dataRangeCaches.value, false);
23904
23944
  const value_isRangeInTask = isRangeInTask(editor.value, dataRangeCaches.value);
23905
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
+ }
23906
23957
  if (typeof props.config.extraDisabled == "function") {
23907
- return props.config.extraDisabled(name) || false;
23958
+ return props.config.extraDisabled(name) || pluginDisabled || false;
23908
23959
  }
23909
- return false;
23960
+ return pluginDisabled || false;
23910
23961
  };
23911
23962
  undoConfig.value.disabled = !editor.value.history.get(-1) || extraDisabled("undo");
23912
23963
  redoConfig.value.disabled = !editor.value.history.get(1) || extraDisabled("redo");
@@ -24607,8 +24658,8 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
24607
24658
  () => h(Icon, { value: "full-screen" })
24608
24659
  );
24609
24660
  }
24610
- if (common.isObject(props.config.extends)) {
24611
- const configuration = props.config.extends[itemProps.name];
24661
+ if (common.isObject(menuExtends.value)) {
24662
+ const configuration = menuExtends.value[itemProps.name];
24612
24663
  if (configuration) {
24613
24664
  return h(
24614
24665
  Button,
@@ -24707,7 +24758,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
24707
24758
  };
24708
24759
  }
24709
24760
  });
24710
- 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"]]);
24711
24762
  const EditifyProps = {
24712
24763
  //国际化语言类型
24713
24764
  locale: {
@@ -24941,9 +24992,10 @@ const en_US = {
24941
24992
  insertAttachment: "Insert attachment",
24942
24993
  uploadAttachment: "Upload",
24943
24994
  remoteAttachment: "Remote",
24995
+ attachmentNamePlaceholder: "Please enter the attachment name",
24944
24996
  attachmentUrlPlaceholder: "Please enter the attachment address",
24945
- downloadAttachment: "Click to download attachment",
24946
- attachmentDownloadName: "attachment"
24997
+ attachmentDownloadTitle: "Click to download attachment",
24998
+ attachmentDefaultName: "attachment"
24947
24999
  };
24948
25000
  const zh_CN = {
24949
25001
  textWrapUp: "向上换行",
@@ -25034,9 +25086,10 @@ const zh_CN = {
25034
25086
  insertAttachment: "插入附件",
25035
25087
  uploadAttachment: "上传附件",
25036
25088
  remoteAttachment: "远程地址",
25037
- attachmentUrlPlaceholder: "请输入远程地址",
25038
- downloadAttachment: "点击下载附件",
25039
- attachmentDownloadName: "附件"
25089
+ attachmentNamePlaceholder: "请输入附件名称",
25090
+ attachmentUrlPlaceholder: "请输入附件地址",
25091
+ attachmentDownloadTitle: "点击下载附件",
25092
+ attachmentDefaultName: "附件"
25040
25093
  };
25041
25094
  const trans = (locale) => {
25042
25095
  return (key) => {
@@ -25053,13 +25106,12 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25053
25106
  },
25054
25107
  __name: "editify",
25055
25108
  props: EditifyProps,
25056
- emits: ["update:modelValue", "focus", "blur", "change", "keydown", "insertparagraph", "rangeupdate", "updateview"],
25109
+ emits: ["update:modelValue", "focus", "blur", "change", "keydown", "keyup", "insertparagraph", "rangeupdate", "updateview"],
25057
25110
  setup(__props, { expose: __expose, emit: __emit }) {
25058
25111
  const instance = getCurrentInstance();
25059
25112
  const props = __props;
25060
25113
  const emits = __emit;
25061
25114
  const $editTrans = trans(props.locale || "zh_CN");
25062
- provide("$editTrans", $editTrans);
25063
25115
  const isModelChange = ref(false);
25064
25116
  const isInputChinese = ref(false);
25065
25117
  const rangeUpdateTimer = ref(null);
@@ -25128,12 +25180,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25128
25180
  return pluginResultList2;
25129
25181
  });
25130
25182
  const menuConfig = computed(() => {
25131
- let menu = {};
25132
- pluginResultList.value.forEach((pluginResult) => {
25133
- menu = mergeObject(menu, pluginResult.menu || {});
25134
- });
25135
- menu = mergeObject(menu, props.menu || {});
25136
- return mergeObject(getMenuConfig($editTrans, props.locale), menu);
25183
+ return mergeObject(getMenuConfig($editTrans, props.locale), props.menu || {});
25137
25184
  });
25138
25185
  const internalModify = (val) => {
25139
25186
  isModelChange.value = true;
@@ -25283,6 +25330,8 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25283
25330
  editor.value.on("change", handleEditorChange);
25284
25331
  editor.value.on("focus", handleEditorFocus);
25285
25332
  editor.value.on("blur", handleEditorBlur);
25333
+ editor.value.on("keydown", handleEditorKeydown);
25334
+ editor.value.on("keyup", handleEditorKeyup);
25286
25335
  editor.value.on("insertParagraph", handleInsertParagraph);
25287
25336
  editor.value.on("rangeUpdate", handleRangeUpdate);
25288
25337
  editor.value.on("deleteInStart", handleDeleteInStart);
@@ -25475,7 +25524,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25475
25524
  }
25476
25525
  return ele;
25477
25526
  };
25478
- const handleEditorKeydown = (e) => {
25527
+ const handleEditorKeydown = (val, e) => {
25479
25528
  if (props.disabled) {
25480
25529
  return;
25481
25530
  }
@@ -25486,7 +25535,13 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25486
25535
  editor.value.domRender();
25487
25536
  editor.value.rangeRender();
25488
25537
  }
25489
- emits("keydown", e);
25538
+ emits("keydown", val, e);
25539
+ };
25540
+ const handleEditorKeyup = (val, e) => {
25541
+ if (props.disabled) {
25542
+ return;
25543
+ }
25544
+ emits("keyup", val, e);
25490
25545
  };
25491
25546
  const handleEditorClick = (e) => {
25492
25547
  if (props.disabled || isSourceView.value) {
@@ -25551,7 +25606,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25551
25606
  };
25552
25607
  const handleInsertParagraph = (element2, previousElement) => {
25553
25608
  if (!element2.isEqual(previousElement)) {
25554
- if (previousElement.isOnlyHasBreak() && element2.isOnlyHasBreak()) {
25609
+ if (previousElement.isBlock() && element2.isBlock() && previousElement.isOnlyHasBreak() && element2.isOnlyHasBreak()) {
25555
25610
  if (previousElement.parsedom != AlexElement.BLOCK_NODE) {
25556
25611
  elementToParagraph(previousElement);
25557
25612
  editor.value.range.anchor.moveToStart(previousElement);
@@ -25715,6 +25770,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25715
25770
  event.off(window, `resize.editify_${instance.uid}`);
25716
25771
  editor.value.destroy();
25717
25772
  });
25773
+ provide("$editTrans", $editTrans);
25718
25774
  provide("editify", instance);
25719
25775
  provide("isSourceView", isSourceView);
25720
25776
  provide("isFullScreen", isFullScreen);
@@ -25722,6 +25778,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25722
25778
  provide("editor", editor);
25723
25779
  provide("dataRangeCaches", dataRangeCaches);
25724
25780
  provide("showBorder", showBorder);
25781
+ provide("pluginResultList", pluginResultList);
25725
25782
  __expose({
25726
25783
  editor,
25727
25784
  isSourceView,
@@ -25757,7 +25814,6 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25757
25814
  ref_key: "contentRef",
25758
25815
  ref: contentRef,
25759
25816
  class: normalizeClass(["editify-content", { "editify-placeholder": showPlaceholder.value, "editify-disabled": _ctx.disabled }]),
25760
- onKeydown: handleEditorKeydown,
25761
25817
  onClick: handleEditorClick,
25762
25818
  onCompositionstart: _cache[0] || (_cache[0] = ($event) => isInputChinese.value = true),
25763
25819
  onCompositionend: _cache[1] || (_cache[1] = ($event) => isInputChinese.value = false),
@@ -25792,7 +25848,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
25792
25848
  };
25793
25849
  }
25794
25850
  });
25795
- const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-8737320e"]]);
25851
+ const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-306d3e9a"]]);
25796
25852
  const InsertAttachmentProps = {
25797
25853
  //主题色
25798
25854
  color: {
@@ -25842,11 +25898,13 @@ const _hoisted_3 = {
25842
25898
  class: "editify-attachment-remote"
25843
25899
  };
25844
25900
  const _hoisted_4 = ["placeholder"];
25845
- const _hoisted_5 = {
25901
+ const _hoisted_5 = ["placeholder"];
25902
+ const _hoisted_6 = {
25846
25903
  key: 1,
25847
25904
  class: "editify-attachment-upload"
25848
25905
  };
25849
- const _hoisted_6 = ["multiple", "accept"];
25906
+ const _hoisted_7 = ["placeholder"];
25907
+ const _hoisted_8 = ["multiple", "accept"];
25850
25908
  const _sfc_main = /* @__PURE__ */ defineComponent({
25851
25909
  ...{
25852
25910
  name: "InsertAttachment"
@@ -25859,7 +25917,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
25859
25917
  const emits = __emit;
25860
25918
  const $editTrans = inject("$editTrans");
25861
25919
  const current = ref("upload");
25862
- const remoteUrl = ref("");
25920
+ const attachmentName = ref("");
25921
+ const attachmentUrl = ref("");
25922
+ const fileInputRef = ref(null);
25863
25923
  const activeStyle = computed(() => {
25864
25924
  return (name) => {
25865
25925
  if (current.value == name) {
@@ -25870,47 +25930,6 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
25870
25930
  return {};
25871
25931
  };
25872
25932
  });
25873
- const acceptValue = computed(() => {
25874
- if (props.accept === "rar") {
25875
- return "application/x-rar-compressed";
25876
- }
25877
- if (props.accept === "zip") {
25878
- return "application/x-zip-compressed";
25879
- }
25880
- if (props.accept === "txt") {
25881
- return "text/plain";
25882
- }
25883
- if (props.accept === "image") {
25884
- return "image/*";
25885
- }
25886
- if (props.accept === "video") {
25887
- return "video/*";
25888
- }
25889
- if (props.accept === "audio") {
25890
- return "aduio/*";
25891
- }
25892
- if (props.accept === "html") {
25893
- return "text/html";
25894
- }
25895
- if (props.accept === "doc") {
25896
- return "application/msword";
25897
- }
25898
- if (props.accept === "xml") {
25899
- return "text/xml";
25900
- }
25901
- if (props.accept === "js") {
25902
- return "text/javascript";
25903
- }
25904
- if (props.accept === "json") {
25905
- return "application/json";
25906
- }
25907
- if (props.accept === "ppt") {
25908
- return "application/vnd.ms-powerpoint";
25909
- }
25910
- if (props.accept === "pdf") {
25911
- return "application/pdf";
25912
- }
25913
- });
25914
25933
  const getSuffix = (file2) => {
25915
25934
  const index = file2.name.lastIndexOf(".");
25916
25935
  if (index <= 0) {
@@ -25927,11 +25946,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
25927
25946
  e.currentTarget.style.borderColor = "";
25928
25947
  };
25929
25948
  const insertRemoteAttachment = () => {
25930
- emits("insert", remoteUrl.value);
25949
+ emits("insert", attachmentName.value, attachmentUrl.value);
25931
25950
  };
25932
- const selectFile = async (e) => {
25933
- const inputEle = e.currentTarget;
25934
- const files = inputEle.files;
25951
+ const triggerFileInput = () => {
25952
+ fileInputRef.value.click();
25953
+ };
25954
+ const selectFile = async () => {
25955
+ const files = fileInputRef.value.files;
25935
25956
  if (!files || !files.length) {
25936
25957
  return;
25937
25958
  }
@@ -25973,10 +25994,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
25973
25994
  }
25974
25995
  }
25975
25996
  attachments.forEach((url) => {
25976
- emits("insert", url);
25997
+ emits("insert", attachmentName.value, url);
25977
25998
  });
25978
25999
  }
25979
- inputEle.value = "";
26000
+ fileInputRef.value.value = "";
25980
26001
  };
25981
26002
  watch(
25982
26003
  () => current.value,
@@ -26004,14 +26025,29 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
26004
26025
  ]),
26005
26026
  current.value == "remote" ? (openBlock(), createElementBlock("div", _hoisted_3, [
26006
26027
  withDirectives(createElementVNode("input", {
26007
- "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => remoteUrl.value = $event),
26008
- placeholder: unref($editTrans)("attachmentUrlPlaceholder"),
26028
+ "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => attachmentName.value = $event),
26029
+ placeholder: unref($editTrans)("attachmentNamePlaceholder"),
26009
26030
  onBlur: handleInputBlur,
26010
- onFocus: handleInputFocus
26031
+ onFocus: handleInputFocus,
26032
+ type: "text"
26011
26033
  }, null, 40, _hoisted_4), [
26012
26034
  [
26013
26035
  vModelText,
26014
- remoteUrl.value,
26036
+ attachmentName.value,
26037
+ void 0,
26038
+ { trim: true }
26039
+ ]
26040
+ ]),
26041
+ withDirectives(createElementVNode("input", {
26042
+ "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => attachmentUrl.value = $event),
26043
+ placeholder: unref($editTrans)("attachmentUrlPlaceholder"),
26044
+ onBlur: handleInputBlur,
26045
+ onFocus: handleInputFocus,
26046
+ type: "url"
26047
+ }, null, 40, _hoisted_5), [
26048
+ [
26049
+ vModelText,
26050
+ attachmentUrl.value,
26015
26051
  void 0,
26016
26052
  { trim: true }
26017
26053
  ]
@@ -26022,55 +26058,103 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
26022
26058
  }, [
26023
26059
  createElementVNode("span", { onClick: insertRemoteAttachment }, toDisplayString(unref($editTrans)("insert")), 1)
26024
26060
  ], 4)
26025
- ])) : (openBlock(), createElementBlock("div", _hoisted_5, [
26026
- createVNode(Icon, { value: "upload" }),
26027
- createElementVNode("input", {
26028
- multiple: _ctx.multiple,
26029
- accept: acceptValue.value,
26030
- onChange: selectFile,
26031
- type: "file"
26032
- }, null, 40, _hoisted_6)
26061
+ ])) : (openBlock(), createElementBlock("div", _hoisted_6, [
26062
+ withDirectives(createElementVNode("input", {
26063
+ "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => attachmentName.value = $event),
26064
+ placeholder: unref($editTrans)("attachmentNamePlaceholder"),
26065
+ onBlur: handleInputBlur,
26066
+ onFocus: handleInputFocus,
26067
+ type: "text"
26068
+ }, null, 40, _hoisted_7), [
26069
+ [
26070
+ vModelText,
26071
+ attachmentName.value,
26072
+ void 0,
26073
+ { trim: true }
26074
+ ]
26075
+ ]),
26076
+ createElementVNode("div", {
26077
+ class: "editify-attachment-btn",
26078
+ onClick: triggerFileInput
26079
+ }, [
26080
+ createVNode(Icon, { value: "upload" }),
26081
+ createElementVNode("input", {
26082
+ ref_key: "fileInputRef",
26083
+ ref: fileInputRef,
26084
+ multiple: _ctx.multiple,
26085
+ accept: _ctx.accept,
26086
+ onChange: selectFile,
26087
+ type: "file"
26088
+ }, null, 40, _hoisted_8)
26089
+ ])
26033
26090
  ]))
26034
26091
  ]);
26035
26092
  };
26036
26093
  }
26037
26094
  });
26038
- const InsertAttachment = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-a2a6e2f3"]]);
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
+ };
26039
26113
  const attachment = (options) => {
26040
26114
  if (!common.isObject(options)) {
26041
26115
  options = {};
26042
26116
  }
26043
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
+ }
26044
26122
  return {
26123
+ name: "attachment",
26045
26124
  //附件菜单项配置
26046
26125
  menu: {
26047
- sequence: {
26048
- 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;
26049
26132
  },
26050
- extends: {
26051
- attachment: {
26052
- type: "select",
26053
- title: options.title || editTrans("insertAttachment"),
26054
- leftBorder: options.leftBorder,
26055
- rightBorder: options.rightBorder,
26056
- disabled: editifyInstance.exposed.editor.value ? hasPreInRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value) : false,
26057
- default: () => h(Icon, { value: "attachment" }),
26058
- layer: (_name, btnInstance) => h(InsertAttachment, {
26059
- color: color2,
26060
- accept: options.accept,
26061
- allowedFileType: options.allowedFileType || [],
26062
- multiple: !!options.multiple,
26063
- maxSize: options.maxSize,
26064
- minSize: options.minSize,
26065
- customUpload: options.customUpload,
26066
- handleError: options.handleError,
26067
- onChange: () => {
26068
- btnInstance.$refs.layerRef.setPosition();
26069
- },
26070
- onInsert: (url) => {
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) {
26071
26155
  const marks = {
26072
26156
  "data-attachment": url,
26073
- "data-attachment-name": editTrans("attachmentDownloadName"),
26157
+ "data-attachment-name": name || editTrans("attachmentDefaultName"),
26074
26158
  contenteditable: "false"
26075
26159
  };
26076
26160
  const attachmentElement = new AlexElement("closed", "span", marks, null, null);
@@ -26085,10 +26169,10 @@ const attachment = (options) => {
26085
26169
  editor.formatElementStack();
26086
26170
  editor.domRender();
26087
26171
  editor.rangeRender();
26088
- btnInstance.show = false;
26089
26172
  }
26090
- })
26091
- }
26173
+ btnInstance.show = false;
26174
+ }
26175
+ })
26092
26176
  }
26093
26177
  },
26094
26178
  //找到附件元素点击下载
@@ -26097,11 +26181,16 @@ const attachment = (options) => {
26097
26181
  AlexElement.flatElements(editor.stack).forEach((el) => {
26098
26182
  if (el.parsedom == "span" && el.hasMarks() && el.marks["data-attachment"]) {
26099
26183
  event.off(el.elm, "click");
26100
- event.on(el.elm, "click", () => {
26184
+ event.on(el.elm, "click", async () => {
26101
26185
  const url = el.marks["data-attachment"];
26186
+ const res = await fetch(url, {
26187
+ method: "GET"
26188
+ });
26189
+ const blob = await res.blob();
26102
26190
  const a = document.createElement("a");
26103
- a.setAttribute("href", url);
26104
- a.setAttribute("download", editTrans("attachmentDownloadName"));
26191
+ a.setAttribute("target", "_blank");
26192
+ a.setAttribute("href", URL.createObjectURL(blob));
26193
+ a.setAttribute("download", el.marks["data-attachment-name"]);
26105
26194
  a.click();
26106
26195
  });
26107
26196
  }
@@ -26122,7 +26211,7 @@ const attachment = (options) => {
26122
26211
  //自定义渲染规范
26123
26212
  renderRule: (el) => {
26124
26213
  if (el.type == "closed" && el.hasMarks() && el.marks["data-attachment"]) {
26125
- el.marks["title"] = editTrans("downloadAttachment");
26214
+ el.marks["title"] = editTrans("attachmentDownloadTitle");
26126
26215
  const editor = editifyInstance.exposed.editor.value;
26127
26216
  const previousElement = editor.getPreviousElement(el);
26128
26217
  const newTextElement = editor.getNextElement(el);
@@ -26143,7 +26232,8 @@ const attachment = (options) => {
26143
26232
  const install = (app) => {
26144
26233
  app.component(Editify.name, Editify);
26145
26234
  };
26146
- const version = "0.1.26";
26235
+ const version = "0.1.29";
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;");
26147
26237
  export {
26148
26238
  AlexElement,
26149
26239
  Editify,