vue-editify 0.1.25 → 0.1.27
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/editify.vue.d.ts +2 -9
- package/lib/editify.es.js +271 -279
- package/lib/editify.umd.js +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/plugins/attachment/index.d.ts +1 -1
- package/lib/plugins/attachment/insertAttachment/insertAttachment.vue.d.ts +3 -3
- package/lib/plugins/attachment/insertAttachment/props.d.ts +1 -1
- package/lib/style.css +1 -1
- package/package.json +2 -2
- package/src/components/insertImage/insertImage.less +1 -0
- package/src/components/insertVideo/insertVideo.less +1 -0
- package/src/editify/editify.vue +17 -6
- package/src/index.ts +6 -4
- package/src/locale/en_US.ts +3 -2
- package/src/locale/zh_CN.ts +4 -3
- package/src/plugins/attachment/index.ts +43 -29
- package/src/plugins/attachment/insertAttachment/insertAttachment.less +48 -19
- package/src/plugins/attachment/insertAttachment/insertAttachment.vue +26 -56
- package/src/plugins/attachment/insertAttachment/props.ts +1 -1
- package/vite.config.ts.timestamp-1714200628309-967ea10c27215.mjs +48 -0
- package/src/plugins/attachment/images/attachment.png +0 -0
package/lib/editify.es.js
CHANGED
@@ -1494,17 +1494,6 @@ const isContains = function(parentNode, childNode) {
|
|
1494
1494
|
}
|
1495
1495
|
return element$1.isContains(parentNode, childNode);
|
1496
1496
|
};
|
1497
|
-
const canUseClipboard = function() {
|
1498
|
-
if (!window.ClipboardItem) {
|
1499
|
-
console.warn("window.ClipboardItem must be obtained in a secure environment, such as localhost, 127.0.0.1, or https, so the editor's copy, paste, and cut functions cannot be used");
|
1500
|
-
return false;
|
1501
|
-
}
|
1502
|
-
if (!navigator.clipboard) {
|
1503
|
-
console.warn("navigator.clipboard must be obtained in a secure environment, such as localhost, 127.0.0.1, or https, so the editor's copy, paste, and cut functions cannot be used");
|
1504
|
-
return false;
|
1505
|
-
}
|
1506
|
-
return true;
|
1507
|
-
};
|
1508
1497
|
const initEditorNode = function(node) {
|
1509
1498
|
if (typeof node == "string" && node) {
|
1510
1499
|
node = document.body.querySelector(node);
|
@@ -2649,6 +2638,98 @@ const isRedo = function(e) {
|
|
2649
2638
|
}
|
2650
2639
|
return e.key == "z" && e.ctrlKey && !e.metaKey && !e.shiftKey && !e.altKey;
|
2651
2640
|
};
|
2641
|
+
const setClipboardData = function(data2, result) {
|
2642
|
+
let html = "";
|
2643
|
+
let text = "";
|
2644
|
+
result.forEach((item) => {
|
2645
|
+
const newEl = item.element.clone();
|
2646
|
+
if (item.offset) {
|
2647
|
+
newEl.textContent = newEl.textContent.substring(item.offset[0], item.offset[1]);
|
2648
|
+
}
|
2649
|
+
newEl.__render();
|
2650
|
+
html += newEl.elm.outerHTML;
|
2651
|
+
text += newEl.elm.innerText;
|
2652
|
+
});
|
2653
|
+
data2.setData("text/plain", text);
|
2654
|
+
data2.setData("text/html", html);
|
2655
|
+
return { html, text };
|
2656
|
+
};
|
2657
|
+
const doPaste = async function(html, text, files) {
|
2658
|
+
if (html) {
|
2659
|
+
if (this.allowPasteHtml) {
|
2660
|
+
const elements = this.parseHtml(html).filter((el) => {
|
2661
|
+
return !el.isEmpty();
|
2662
|
+
});
|
2663
|
+
if (typeof this.customHtmlPaste == "function") {
|
2664
|
+
await this.customHtmlPaste.apply(this, [elements, html]);
|
2665
|
+
} else {
|
2666
|
+
for (let i = 0; i < elements.length; i++) {
|
2667
|
+
this.insertElement(elements[i], false);
|
2668
|
+
}
|
2669
|
+
this.emit("pasteHtml", elements, html);
|
2670
|
+
}
|
2671
|
+
} else if (text) {
|
2672
|
+
if (typeof this.customTextPaste == "function") {
|
2673
|
+
await this.customTextPaste.apply(this, [text]);
|
2674
|
+
} else {
|
2675
|
+
this.insertText(text);
|
2676
|
+
this.emit("pasteText", text);
|
2677
|
+
}
|
2678
|
+
}
|
2679
|
+
} else {
|
2680
|
+
if (text) {
|
2681
|
+
if (typeof this.customTextPaste == "function") {
|
2682
|
+
await this.customTextPaste.apply(this, [text]);
|
2683
|
+
} else {
|
2684
|
+
this.insertText(text);
|
2685
|
+
this.emit("pasteText", text);
|
2686
|
+
}
|
2687
|
+
} else {
|
2688
|
+
let length = files.length;
|
2689
|
+
for (let i = 0; i < length; i++) {
|
2690
|
+
if (files[i].type.startsWith("image/")) {
|
2691
|
+
if (typeof this.customImagePaste == "function") {
|
2692
|
+
await this.customImagePaste.apply(this, [files[i]]);
|
2693
|
+
} else {
|
2694
|
+
const url = await file$1.dataFileToBase64(files[i]);
|
2695
|
+
const image = new AlexElement(
|
2696
|
+
"closed",
|
2697
|
+
"img",
|
2698
|
+
{
|
2699
|
+
src: url
|
2700
|
+
},
|
2701
|
+
null,
|
2702
|
+
null
|
2703
|
+
);
|
2704
|
+
this.insertElement(image);
|
2705
|
+
this.emit("pasteImage", url);
|
2706
|
+
}
|
2707
|
+
} else if (files[i].type.startsWith("video/")) {
|
2708
|
+
if (typeof this.customVideoPaste == "function") {
|
2709
|
+
await this.customVideoPaste.apply(this, [files[i]]);
|
2710
|
+
} else {
|
2711
|
+
const url = await file$1.dataFileToBase64(files[i]);
|
2712
|
+
const video = new AlexElement(
|
2713
|
+
"closed",
|
2714
|
+
"video",
|
2715
|
+
{
|
2716
|
+
src: url
|
2717
|
+
},
|
2718
|
+
null,
|
2719
|
+
null
|
2720
|
+
);
|
2721
|
+
this.insertElement(video);
|
2722
|
+
this.emit("pasteVideo", url);
|
2723
|
+
}
|
2724
|
+
} else {
|
2725
|
+
if (typeof this.customFilePaste == "function") {
|
2726
|
+
await this.customFilePaste.apply(this, [files[i]]);
|
2727
|
+
}
|
2728
|
+
}
|
2729
|
+
}
|
2730
|
+
}
|
2731
|
+
}
|
2732
|
+
};
|
2652
2733
|
const checkStack = function() {
|
2653
2734
|
const elements = AlexElement.flatElements(this.stack).filter((el) => {
|
2654
2735
|
return !el.isEmpty() && !AlexElement.VOID_NODES.includes(el.parsedom);
|
@@ -2906,124 +2987,76 @@ const handleChineseInput = function(e) {
|
|
2906
2987
|
}, 0);
|
2907
2988
|
}
|
2908
2989
|
};
|
2909
|
-
const
|
2990
|
+
const handleKeyboard = function(e) {
|
2910
2991
|
if (this.disabled) {
|
2911
2992
|
return;
|
2912
2993
|
}
|
2913
2994
|
if (this.__isInputChinese) {
|
2914
2995
|
return;
|
2915
2996
|
}
|
2916
|
-
if (
|
2917
|
-
e
|
2918
|
-
|
2919
|
-
|
2920
|
-
|
2921
|
-
|
2922
|
-
|
2923
|
-
|
2924
|
-
|
2925
|
-
|
2926
|
-
|
2927
|
-
|
2928
|
-
e
|
2929
|
-
|
2930
|
-
|
2931
|
-
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2936
|
-
|
2997
|
+
if (e.type == "keydown") {
|
2998
|
+
if (isUndo(e)) {
|
2999
|
+
e.preventDefault();
|
3000
|
+
const historyRecord = this.history.get(-1);
|
3001
|
+
if (historyRecord) {
|
3002
|
+
this.history.current = historyRecord.current;
|
3003
|
+
this.stack = historyRecord.stack;
|
3004
|
+
this.range = historyRecord.range;
|
3005
|
+
this.formatElementStack();
|
3006
|
+
this.domRender(true);
|
3007
|
+
this.rangeRender();
|
3008
|
+
}
|
3009
|
+
} else if (isRedo(e)) {
|
3010
|
+
e.preventDefault();
|
3011
|
+
const historyRecord = this.history.get(1);
|
3012
|
+
if (historyRecord) {
|
3013
|
+
this.history.current = historyRecord.current;
|
3014
|
+
this.stack = historyRecord.stack;
|
3015
|
+
this.range = historyRecord.range;
|
3016
|
+
this.formatElementStack();
|
3017
|
+
this.domRender(true);
|
3018
|
+
this.rangeRender();
|
3019
|
+
}
|
2937
3020
|
}
|
3021
|
+
this.emit("keydown", this.value, e);
|
3022
|
+
} else if (e.type == "keyup") {
|
3023
|
+
this.emit("keyup", this.value, e);
|
2938
3024
|
}
|
2939
3025
|
};
|
2940
3026
|
const handleCopy = async function(e) {
|
2941
3027
|
e.preventDefault();
|
2942
|
-
|
3028
|
+
if (!this.range) {
|
3029
|
+
return;
|
3030
|
+
}
|
3031
|
+
if (!this.allowCopy) {
|
3032
|
+
return;
|
3033
|
+
}
|
3034
|
+
const event2 = e;
|
3035
|
+
const result = this.getElementsByRange().list;
|
3036
|
+
if (event2.clipboardData && result.length) {
|
3037
|
+
const { text, html } = setClipboardData.apply(this, [event2.clipboardData, result]);
|
3038
|
+
this.emit("copy", text, html);
|
3039
|
+
}
|
2943
3040
|
};
|
2944
3041
|
const handleCut = async function(e) {
|
2945
3042
|
e.preventDefault();
|
2946
|
-
|
2947
|
-
|
2948
|
-
this.formatElementStack();
|
2949
|
-
this.domRender();
|
2950
|
-
this.rangeRender();
|
3043
|
+
if (!this.range) {
|
3044
|
+
return;
|
2951
3045
|
}
|
2952
|
-
|
2953
|
-
|
2954
|
-
|
2955
|
-
|
2956
|
-
|
2957
|
-
|
2958
|
-
|
2959
|
-
|
2960
|
-
|
2961
|
-
|
2962
|
-
|
2963
|
-
|
2964
|
-
}
|
2965
|
-
this.emit("pasteHtml", elements, html);
|
2966
|
-
}
|
2967
|
-
} else if (text) {
|
2968
|
-
if (typeof this.customTextPaste == "function") {
|
2969
|
-
await this.customTextPaste.apply(this, [text]);
|
2970
|
-
} else {
|
2971
|
-
this.insertText(text);
|
2972
|
-
this.emit("pasteText", text);
|
2973
|
-
}
|
2974
|
-
}
|
2975
|
-
} else {
|
2976
|
-
if (text) {
|
2977
|
-
if (typeof this.customTextPaste == "function") {
|
2978
|
-
await this.customTextPaste.apply(this, [text]);
|
2979
|
-
} else {
|
2980
|
-
this.insertText(text);
|
2981
|
-
this.emit("pasteText", text);
|
2982
|
-
}
|
2983
|
-
} else {
|
2984
|
-
let length = files.length;
|
2985
|
-
for (let i = 0; i < length; i++) {
|
2986
|
-
if (files[i].type.startsWith("image/")) {
|
2987
|
-
if (typeof this.customImagePaste == "function") {
|
2988
|
-
await this.customImagePaste.apply(this, [files[i]]);
|
2989
|
-
} else {
|
2990
|
-
const url = await file$1.dataFileToBase64(files[i]);
|
2991
|
-
const image = new AlexElement(
|
2992
|
-
"closed",
|
2993
|
-
"img",
|
2994
|
-
{
|
2995
|
-
src: url
|
2996
|
-
},
|
2997
|
-
null,
|
2998
|
-
null
|
2999
|
-
);
|
3000
|
-
this.insertElement(image);
|
3001
|
-
this.emit("pasteImage", url);
|
3002
|
-
}
|
3003
|
-
} else if (files[i].type.startsWith("video/")) {
|
3004
|
-
if (typeof this.customVideoPaste == "function") {
|
3005
|
-
await this.customVideoPaste.apply(this, [files[i]]);
|
3006
|
-
} else {
|
3007
|
-
const url = await file$1.dataFileToBase64(files[i]);
|
3008
|
-
const video = new AlexElement(
|
3009
|
-
"closed",
|
3010
|
-
"video",
|
3011
|
-
{
|
3012
|
-
src: url
|
3013
|
-
},
|
3014
|
-
null,
|
3015
|
-
null
|
3016
|
-
);
|
3017
|
-
this.insertElement(video);
|
3018
|
-
this.emit("pasteVideo", url);
|
3019
|
-
}
|
3020
|
-
} else {
|
3021
|
-
if (typeof this.customFilePaste == "function") {
|
3022
|
-
await this.customFilePaste.apply(this, [files[i]]);
|
3023
|
-
}
|
3024
|
-
}
|
3025
|
-
}
|
3046
|
+
if (!this.allowCut) {
|
3047
|
+
return;
|
3048
|
+
}
|
3049
|
+
const event2 = e;
|
3050
|
+
const result = this.getElementsByRange().list;
|
3051
|
+
if (event2.clipboardData && result.length) {
|
3052
|
+
const { text, html } = setClipboardData.apply(this, [event2.clipboardData, result]);
|
3053
|
+
if (!this.disabled) {
|
3054
|
+
this.delete();
|
3055
|
+
this.formatElementStack();
|
3056
|
+
this.domRender();
|
3057
|
+
this.rangeRender();
|
3026
3058
|
}
|
3059
|
+
this.emit("cut", text, html);
|
3027
3060
|
}
|
3028
3061
|
};
|
3029
3062
|
const handlePaste = async function(e) {
|
@@ -3072,17 +3105,17 @@ const handleDragDrop = async function(e) {
|
|
3072
3105
|
}
|
3073
3106
|
}
|
3074
3107
|
};
|
3075
|
-
const handleFocus = function() {
|
3108
|
+
const handleFocus = function(e) {
|
3076
3109
|
if (this.disabled) {
|
3077
3110
|
return;
|
3078
3111
|
}
|
3079
|
-
this.emit("focus", this.value);
|
3112
|
+
this.emit("focus", this.value, e);
|
3080
3113
|
};
|
3081
|
-
const handleBlur = function() {
|
3114
|
+
const handleBlur = function(e) {
|
3082
3115
|
if (this.disabled) {
|
3083
3116
|
return;
|
3084
3117
|
}
|
3085
|
-
this.emit("blur", this.value);
|
3118
|
+
this.emit("blur", this.value, e);
|
3086
3119
|
};
|
3087
3120
|
class AlexEditor {
|
3088
3121
|
constructor(node, opts) {
|
@@ -3101,7 +3134,6 @@ class AlexEditor {
|
|
3101
3134
|
__publicField(this, "customFilePaste");
|
3102
3135
|
__publicField(this, "customMerge");
|
3103
3136
|
__publicField(this, "customParseNode");
|
3104
|
-
__publicField(this, "useClipboard", canUseClipboard());
|
3105
3137
|
__publicField(this, "history", new AlexHistory());
|
3106
3138
|
__publicField(this, "stack");
|
3107
3139
|
__publicField(this, "range", null);
|
@@ -3133,7 +3165,7 @@ class AlexEditor {
|
|
3133
3165
|
event$1.on(document, `selectionchange.alex_editor_${this.__guid}`, handleSelectionChange.bind(this));
|
3134
3166
|
event$1.on(this.$el, "beforeinput.alex_editor", handleBeforeInput.bind(this));
|
3135
3167
|
event$1.on(this.$el, "compositionstart.alex_editor compositionupdate.alex_editor compositionend.alex_editor", handleChineseInput.bind(this));
|
3136
|
-
event$1.on(this.$el, "keydown.alex_editor",
|
3168
|
+
event$1.on(this.$el, "keydown.alex_editor keyup.alex_editor", handleKeyboard.bind(this));
|
3137
3169
|
event$1.on(this.$el, "cut.alex_editor", handleCut.bind(this));
|
3138
3170
|
event$1.on(this.$el, "paste.alex_editor", handlePaste.bind(this));
|
3139
3171
|
event$1.on(this.$el, "copy.alex_editor", handleCopy.bind(this));
|
@@ -3153,67 +3185,6 @@ class AlexEditor {
|
|
3153
3185
|
const focus = new AlexPoint(firstElement, 0);
|
3154
3186
|
this.range = new AlexRange(anchor, focus);
|
3155
3187
|
}
|
3156
|
-
/**
|
3157
|
-
* 根据光标执行复制操作
|
3158
|
-
* isCut表示是否在执行剪切操作,默认为false,这个参数仅在内部使用
|
3159
|
-
*/
|
3160
|
-
async copy(isCut = false) {
|
3161
|
-
if (!this.useClipboard) {
|
3162
|
-
return;
|
3163
|
-
}
|
3164
|
-
if (!this.range) {
|
3165
|
-
return;
|
3166
|
-
}
|
3167
|
-
if (!this.allowCopy) {
|
3168
|
-
return;
|
3169
|
-
}
|
3170
|
-
let result = this.getElementsByRange().list;
|
3171
|
-
if (result.length == 0) {
|
3172
|
-
return;
|
3173
|
-
}
|
3174
|
-
let html = "";
|
3175
|
-
let text = "";
|
3176
|
-
result.forEach((item) => {
|
3177
|
-
const newEl = item.element.clone();
|
3178
|
-
if (item.offset) {
|
3179
|
-
newEl.textContent = newEl.textContent.substring(item.offset[0], item.offset[1]);
|
3180
|
-
}
|
3181
|
-
newEl.__render();
|
3182
|
-
html += newEl.elm.outerHTML;
|
3183
|
-
text += newEl.elm.innerText;
|
3184
|
-
});
|
3185
|
-
const clipboardItem = new window.ClipboardItem({
|
3186
|
-
"text/html": new Blob([html], { type: "text/html" }),
|
3187
|
-
"text/plain": new Blob([text], { type: "text/plain" })
|
3188
|
-
});
|
3189
|
-
await navigator.clipboard.write([clipboardItem]);
|
3190
|
-
if (!isCut) {
|
3191
|
-
this.emit("copy", text, html);
|
3192
|
-
}
|
3193
|
-
return { text, html };
|
3194
|
-
}
|
3195
|
-
/**
|
3196
|
-
* 根据光标进行剪切操作
|
3197
|
-
*/
|
3198
|
-
async cut() {
|
3199
|
-
if (!this.useClipboard) {
|
3200
|
-
return;
|
3201
|
-
}
|
3202
|
-
if (!this.range) {
|
3203
|
-
return;
|
3204
|
-
}
|
3205
|
-
if (!this.allowCut) {
|
3206
|
-
return;
|
3207
|
-
}
|
3208
|
-
const result = await this.copy(true);
|
3209
|
-
if (result) {
|
3210
|
-
if (!this.disabled) {
|
3211
|
-
this.delete();
|
3212
|
-
}
|
3213
|
-
this.emit("cut", result.text, result.html);
|
3214
|
-
}
|
3215
|
-
return result;
|
3216
|
-
}
|
3217
3188
|
/**
|
3218
3189
|
* 根据光标进行删除操作
|
3219
3190
|
*/
|
@@ -4525,6 +4496,8 @@ class AlexEditor {
|
|
4525
4496
|
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");
|
4526
4497
|
}
|
4527
4498
|
}
|
4499
|
+
const version$2 = "1.3.32";
|
4500
|
+
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;");
|
4528
4501
|
const number = {
|
4529
4502
|
/**
|
4530
4503
|
* 数字格式化
|
@@ -23302,7 +23275,7 @@ const _hoisted_4$2 = [
|
|
23302
23275
|
];
|
23303
23276
|
const _hoisted_5$1 = { class: "editify-table-footer" };
|
23304
23277
|
const _hoisted_6$1 = { key: 0 };
|
23305
|
-
const _hoisted_7 = { key: 1 };
|
23278
|
+
const _hoisted_7$1 = { key: 1 };
|
23306
23279
|
const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
23307
23280
|
...{
|
23308
23281
|
name: "InsertTable"
|
@@ -23378,7 +23351,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
23378
23351
|
}), 256))
|
23379
23352
|
]),
|
23380
23353
|
createElementVNode("div", _hoisted_5$1, [
|
23381
|
-
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))
|
23354
|
+
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))
|
23382
23355
|
])
|
23383
23356
|
]);
|
23384
23357
|
};
|
@@ -24975,9 +24948,10 @@ const en_US = {
|
|
24975
24948
|
insertAttachment: "Insert attachment",
|
24976
24949
|
uploadAttachment: "Upload",
|
24977
24950
|
remoteAttachment: "Remote",
|
24951
|
+
attachmentNamePlaceholder: "Please enter the attachment name",
|
24978
24952
|
attachmentUrlPlaceholder: "Please enter the attachment address",
|
24979
|
-
|
24980
|
-
|
24953
|
+
attachmentDownloadTitle: "Click to download attachment",
|
24954
|
+
attachmentDefaultName: "attachment"
|
24981
24955
|
};
|
24982
24956
|
const zh_CN = {
|
24983
24957
|
textWrapUp: "向上换行",
|
@@ -25068,9 +25042,10 @@ const zh_CN = {
|
|
25068
25042
|
insertAttachment: "插入附件",
|
25069
25043
|
uploadAttachment: "上传附件",
|
25070
25044
|
remoteAttachment: "远程地址",
|
25071
|
-
|
25072
|
-
|
25073
|
-
|
25045
|
+
attachmentNamePlaceholder: "请输入附件名称",
|
25046
|
+
attachmentUrlPlaceholder: "请输入附件地址",
|
25047
|
+
attachmentDownloadTitle: "点击下载附件",
|
25048
|
+
attachmentDefaultName: "附件"
|
25074
25049
|
};
|
25075
25050
|
const trans = (locale) => {
|
25076
25051
|
return (key) => {
|
@@ -25087,7 +25062,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
25087
25062
|
},
|
25088
25063
|
__name: "editify",
|
25089
25064
|
props: EditifyProps,
|
25090
|
-
emits: ["update:modelValue", "focus", "blur", "change", "keydown", "insertparagraph", "rangeupdate", "updateview"],
|
25065
|
+
emits: ["update:modelValue", "focus", "blur", "change", "keydown", "keyup", "insertparagraph", "rangeupdate", "updateview"],
|
25091
25066
|
setup(__props, { expose: __expose, emit: __emit }) {
|
25092
25067
|
const instance = getCurrentInstance();
|
25093
25068
|
const props = __props;
|
@@ -25317,6 +25292,8 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
25317
25292
|
editor.value.on("change", handleEditorChange);
|
25318
25293
|
editor.value.on("focus", handleEditorFocus);
|
25319
25294
|
editor.value.on("blur", handleEditorBlur);
|
25295
|
+
editor.value.on("keydown", handleEditorKeydown);
|
25296
|
+
editor.value.on("keyup", handleEditorKeyup);
|
25320
25297
|
editor.value.on("insertParagraph", handleInsertParagraph);
|
25321
25298
|
editor.value.on("rangeUpdate", handleRangeUpdate);
|
25322
25299
|
editor.value.on("deleteInStart", handleDeleteInStart);
|
@@ -25509,7 +25486,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
25509
25486
|
}
|
25510
25487
|
return ele;
|
25511
25488
|
};
|
25512
|
-
const handleEditorKeydown = (e) => {
|
25489
|
+
const handleEditorKeydown = (val, e) => {
|
25513
25490
|
if (props.disabled) {
|
25514
25491
|
return;
|
25515
25492
|
}
|
@@ -25520,7 +25497,13 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
25520
25497
|
editor.value.domRender();
|
25521
25498
|
editor.value.rangeRender();
|
25522
25499
|
}
|
25523
|
-
emits("keydown", e);
|
25500
|
+
emits("keydown", val, e);
|
25501
|
+
};
|
25502
|
+
const handleEditorKeyup = (val, e) => {
|
25503
|
+
if (props.disabled) {
|
25504
|
+
return;
|
25505
|
+
}
|
25506
|
+
emits("keyup", val, e);
|
25524
25507
|
};
|
25525
25508
|
const handleEditorClick = (e) => {
|
25526
25509
|
if (props.disabled || isSourceView.value) {
|
@@ -25585,7 +25568,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
25585
25568
|
};
|
25586
25569
|
const handleInsertParagraph = (element2, previousElement) => {
|
25587
25570
|
if (!element2.isEqual(previousElement)) {
|
25588
|
-
if (previousElement.isOnlyHasBreak() && element2.isOnlyHasBreak()) {
|
25571
|
+
if (previousElement.isBlock() && element2.isBlock() && previousElement.isOnlyHasBreak() && element2.isOnlyHasBreak()) {
|
25589
25572
|
if (previousElement.parsedom != AlexElement.BLOCK_NODE) {
|
25590
25573
|
elementToParagraph(previousElement);
|
25591
25574
|
editor.value.range.anchor.moveToStart(previousElement);
|
@@ -25791,7 +25774,6 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
25791
25774
|
ref_key: "contentRef",
|
25792
25775
|
ref: contentRef,
|
25793
25776
|
class: normalizeClass(["editify-content", { "editify-placeholder": showPlaceholder.value, "editify-disabled": _ctx.disabled }]),
|
25794
|
-
onKeydown: handleEditorKeydown,
|
25795
25777
|
onClick: handleEditorClick,
|
25796
25778
|
onCompositionstart: _cache[0] || (_cache[0] = ($event) => isInputChinese.value = true),
|
25797
25779
|
onCompositionend: _cache[1] || (_cache[1] = ($event) => isInputChinese.value = false),
|
@@ -25826,7 +25808,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
25826
25808
|
};
|
25827
25809
|
}
|
25828
25810
|
});
|
25829
|
-
const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-
|
25811
|
+
const Editify = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-3b2e5bbc"]]);
|
25830
25812
|
const InsertAttachmentProps = {
|
25831
25813
|
//主题色
|
25832
25814
|
color: {
|
@@ -25876,11 +25858,13 @@ const _hoisted_3 = {
|
|
25876
25858
|
class: "editify-attachment-remote"
|
25877
25859
|
};
|
25878
25860
|
const _hoisted_4 = ["placeholder"];
|
25879
|
-
const _hoisted_5 =
|
25861
|
+
const _hoisted_5 = ["placeholder"];
|
25862
|
+
const _hoisted_6 = {
|
25880
25863
|
key: 1,
|
25881
25864
|
class: "editify-attachment-upload"
|
25882
25865
|
};
|
25883
|
-
const
|
25866
|
+
const _hoisted_7 = ["placeholder"];
|
25867
|
+
const _hoisted_8 = ["multiple", "accept"];
|
25884
25868
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
25885
25869
|
...{
|
25886
25870
|
name: "InsertAttachment"
|
@@ -25893,7 +25877,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
25893
25877
|
const emits = __emit;
|
25894
25878
|
const $editTrans = inject("$editTrans");
|
25895
25879
|
const current = ref("upload");
|
25896
|
-
const
|
25880
|
+
const attachmentName = ref("");
|
25881
|
+
const attachmentUrl = ref("");
|
25882
|
+
const fileInputRef = ref(null);
|
25897
25883
|
const activeStyle = computed(() => {
|
25898
25884
|
return (name) => {
|
25899
25885
|
if (current.value == name) {
|
@@ -25904,47 +25890,6 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
25904
25890
|
return {};
|
25905
25891
|
};
|
25906
25892
|
});
|
25907
|
-
const acceptValue = computed(() => {
|
25908
|
-
if (props.accept === "rar") {
|
25909
|
-
return "application/x-rar-compressed";
|
25910
|
-
}
|
25911
|
-
if (props.accept === "zip") {
|
25912
|
-
return "application/x-zip-compressed";
|
25913
|
-
}
|
25914
|
-
if (props.accept === "txt") {
|
25915
|
-
return "text/plain";
|
25916
|
-
}
|
25917
|
-
if (props.accept === "image") {
|
25918
|
-
return "image/*";
|
25919
|
-
}
|
25920
|
-
if (props.accept === "video") {
|
25921
|
-
return "video/*";
|
25922
|
-
}
|
25923
|
-
if (props.accept === "audio") {
|
25924
|
-
return "aduio/*";
|
25925
|
-
}
|
25926
|
-
if (props.accept === "html") {
|
25927
|
-
return "text/html";
|
25928
|
-
}
|
25929
|
-
if (props.accept === "doc") {
|
25930
|
-
return "application/msword";
|
25931
|
-
}
|
25932
|
-
if (props.accept === "xml") {
|
25933
|
-
return "text/xml";
|
25934
|
-
}
|
25935
|
-
if (props.accept === "js") {
|
25936
|
-
return "text/javascript";
|
25937
|
-
}
|
25938
|
-
if (props.accept === "json") {
|
25939
|
-
return "application/json";
|
25940
|
-
}
|
25941
|
-
if (props.accept === "ppt") {
|
25942
|
-
return "application/vnd.ms-powerpoint";
|
25943
|
-
}
|
25944
|
-
if (props.accept === "pdf") {
|
25945
|
-
return "application/pdf";
|
25946
|
-
}
|
25947
|
-
});
|
25948
25893
|
const getSuffix = (file2) => {
|
25949
25894
|
const index = file2.name.lastIndexOf(".");
|
25950
25895
|
if (index <= 0) {
|
@@ -25961,11 +25906,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
25961
25906
|
e.currentTarget.style.borderColor = "";
|
25962
25907
|
};
|
25963
25908
|
const insertRemoteAttachment = () => {
|
25964
|
-
emits("insert",
|
25909
|
+
emits("insert", attachmentName.value, attachmentUrl.value);
|
25965
25910
|
};
|
25966
|
-
const
|
25967
|
-
|
25968
|
-
|
25911
|
+
const triggerFileInput = () => {
|
25912
|
+
fileInputRef.value.click();
|
25913
|
+
};
|
25914
|
+
const selectFile = async () => {
|
25915
|
+
const files = fileInputRef.value.files;
|
25969
25916
|
if (!files || !files.length) {
|
25970
25917
|
return;
|
25971
25918
|
}
|
@@ -26007,10 +25954,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
26007
25954
|
}
|
26008
25955
|
}
|
26009
25956
|
attachments.forEach((url) => {
|
26010
|
-
emits("insert", url);
|
25957
|
+
emits("insert", attachmentName.value, url);
|
26011
25958
|
});
|
26012
25959
|
}
|
26013
|
-
|
25960
|
+
fileInputRef.value.value = "";
|
26014
25961
|
};
|
26015
25962
|
watch(
|
26016
25963
|
() => current.value,
|
@@ -26038,14 +25985,29 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
26038
25985
|
]),
|
26039
25986
|
current.value == "remote" ? (openBlock(), createElementBlock("div", _hoisted_3, [
|
26040
25987
|
withDirectives(createElementVNode("input", {
|
26041
|
-
"onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) =>
|
26042
|
-
placeholder: unref($editTrans)("
|
25988
|
+
"onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => attachmentName.value = $event),
|
25989
|
+
placeholder: unref($editTrans)("attachmentNamePlaceholder"),
|
26043
25990
|
onBlur: handleInputBlur,
|
26044
|
-
onFocus: handleInputFocus
|
25991
|
+
onFocus: handleInputFocus,
|
25992
|
+
type: "text"
|
26045
25993
|
}, null, 40, _hoisted_4), [
|
26046
25994
|
[
|
26047
25995
|
vModelText,
|
26048
|
-
|
25996
|
+
attachmentName.value,
|
25997
|
+
void 0,
|
25998
|
+
{ trim: true }
|
25999
|
+
]
|
26000
|
+
]),
|
26001
|
+
withDirectives(createElementVNode("input", {
|
26002
|
+
"onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => attachmentUrl.value = $event),
|
26003
|
+
placeholder: unref($editTrans)("attachmentUrlPlaceholder"),
|
26004
|
+
onBlur: handleInputBlur,
|
26005
|
+
onFocus: handleInputFocus,
|
26006
|
+
type: "url"
|
26007
|
+
}, null, 40, _hoisted_5), [
|
26008
|
+
[
|
26009
|
+
vModelText,
|
26010
|
+
attachmentUrl.value,
|
26049
26011
|
void 0,
|
26050
26012
|
{ trim: true }
|
26051
26013
|
]
|
@@ -26056,20 +26018,41 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
26056
26018
|
}, [
|
26057
26019
|
createElementVNode("span", { onClick: insertRemoteAttachment }, toDisplayString(unref($editTrans)("insert")), 1)
|
26058
26020
|
], 4)
|
26059
|
-
])) : (openBlock(), createElementBlock("div",
|
26060
|
-
|
26061
|
-
|
26062
|
-
|
26063
|
-
|
26064
|
-
|
26065
|
-
type: "
|
26066
|
-
}, null, 40,
|
26021
|
+
])) : (openBlock(), createElementBlock("div", _hoisted_6, [
|
26022
|
+
withDirectives(createElementVNode("input", {
|
26023
|
+
"onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => attachmentName.value = $event),
|
26024
|
+
placeholder: unref($editTrans)("attachmentNamePlaceholder"),
|
26025
|
+
onBlur: handleInputBlur,
|
26026
|
+
onFocus: handleInputFocus,
|
26027
|
+
type: "text"
|
26028
|
+
}, null, 40, _hoisted_7), [
|
26029
|
+
[
|
26030
|
+
vModelText,
|
26031
|
+
attachmentName.value,
|
26032
|
+
void 0,
|
26033
|
+
{ trim: true }
|
26034
|
+
]
|
26035
|
+
]),
|
26036
|
+
createElementVNode("div", {
|
26037
|
+
class: "editify-attachment-btn",
|
26038
|
+
onClick: triggerFileInput
|
26039
|
+
}, [
|
26040
|
+
createVNode(Icon, { value: "upload" }),
|
26041
|
+
createElementVNode("input", {
|
26042
|
+
ref_key: "fileInputRef",
|
26043
|
+
ref: fileInputRef,
|
26044
|
+
multiple: _ctx.multiple,
|
26045
|
+
accept: _ctx.accept,
|
26046
|
+
onChange: selectFile,
|
26047
|
+
type: "file"
|
26048
|
+
}, null, 40, _hoisted_8)
|
26049
|
+
])
|
26067
26050
|
]))
|
26068
26051
|
]);
|
26069
26052
|
};
|
26070
26053
|
}
|
26071
26054
|
});
|
26072
|
-
const InsertAttachment = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-
|
26055
|
+
const InsertAttachment = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-f995f4bd"]]);
|
26073
26056
|
const attachment = (options) => {
|
26074
26057
|
if (!common.isObject(options)) {
|
26075
26058
|
options = {};
|
@@ -26087,6 +26070,7 @@ const attachment = (options) => {
|
|
26087
26070
|
title: options.title || editTrans("insertAttachment"),
|
26088
26071
|
leftBorder: options.leftBorder,
|
26089
26072
|
rightBorder: options.rightBorder,
|
26073
|
+
hideScroll: true,
|
26090
26074
|
disabled: editifyInstance.exposed.editor.value ? hasPreInRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value) : false,
|
26091
26075
|
default: () => h(Icon, { value: "attachment" }),
|
26092
26076
|
layer: (_name, btnInstance) => h(InsertAttachment, {
|
@@ -26101,24 +26085,26 @@ const attachment = (options) => {
|
|
26101
26085
|
onChange: () => {
|
26102
26086
|
btnInstance.$refs.layerRef.setPosition();
|
26103
26087
|
},
|
26104
|
-
onInsert: (url) => {
|
26105
|
-
|
26106
|
-
|
26107
|
-
|
26108
|
-
|
26109
|
-
|
26110
|
-
|
26111
|
-
|
26112
|
-
|
26113
|
-
|
26114
|
-
|
26115
|
-
|
26116
|
-
|
26117
|
-
|
26118
|
-
|
26119
|
-
|
26120
|
-
|
26121
|
-
|
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
|
+
}
|
26122
26108
|
btnInstance.show = false;
|
26123
26109
|
}
|
26124
26110
|
})
|
@@ -26131,11 +26117,16 @@ const attachment = (options) => {
|
|
26131
26117
|
AlexElement.flatElements(editor.stack).forEach((el) => {
|
26132
26118
|
if (el.parsedom == "span" && el.hasMarks() && el.marks["data-attachment"]) {
|
26133
26119
|
event.off(el.elm, "click");
|
26134
|
-
event.on(el.elm, "click", () => {
|
26120
|
+
event.on(el.elm, "click", async () => {
|
26135
26121
|
const url = el.marks["data-attachment"];
|
26122
|
+
const res = await fetch(url, {
|
26123
|
+
method: "GET"
|
26124
|
+
});
|
26125
|
+
const blob = await res.blob();
|
26136
26126
|
const a = document.createElement("a");
|
26137
|
-
a.setAttribute("
|
26138
|
-
a.setAttribute("
|
26127
|
+
a.setAttribute("target", "_blank");
|
26128
|
+
a.setAttribute("href", URL.createObjectURL(blob));
|
26129
|
+
a.setAttribute("download", el.marks["data-attachment-name"]);
|
26139
26130
|
a.click();
|
26140
26131
|
});
|
26141
26132
|
}
|
@@ -26156,7 +26147,7 @@ const attachment = (options) => {
|
|
26156
26147
|
//自定义渲染规范
|
26157
26148
|
renderRule: (el) => {
|
26158
26149
|
if (el.type == "closed" && el.hasMarks() && el.marks["data-attachment"]) {
|
26159
|
-
el.marks["title"] = editTrans("
|
26150
|
+
el.marks["title"] = editTrans("attachmentDownloadTitle");
|
26160
26151
|
const editor = editifyInstance.exposed.editor.value;
|
26161
26152
|
const previousElement = editor.getPreviousElement(el);
|
26162
26153
|
const newTextElement = editor.getNextElement(el);
|
@@ -26177,7 +26168,8 @@ const attachment = (options) => {
|
|
26177
26168
|
const install = (app) => {
|
26178
26169
|
app.component(Editify.name, Editify);
|
26179
26170
|
};
|
26180
|
-
const version = "0.1.
|
26171
|
+
const version = "0.1.27";
|
26172
|
+
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;");
|
26181
26173
|
export {
|
26182
26174
|
AlexElement,
|
26183
26175
|
Editify,
|