vue-editify 0.1.25 → 0.1.26
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/editify/editify.vue.d.ts +0 -9
- package/lib/editify.es.js +120 -154
- package/lib/editify.umd.js +1 -1
- package/lib/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -1
@@ -128,7 +128,6 @@ declare const _default: import('vue').DefineComponent<{
|
|
128
128
|
customFilePaste: ((file: File) => void | Promise<void>) | null;
|
129
129
|
customMerge: ((mergeElement: AlexElement, targetElement: AlexElement) => void | Promise<void>) | null;
|
130
130
|
customParseNode: ((el: AlexElement) => AlexElement) | null;
|
131
|
-
useClipboard: boolean;
|
132
131
|
history: {
|
133
132
|
records: {
|
134
133
|
stack: {
|
@@ -419,14 +418,6 @@ declare const _default: import('vue').DefineComponent<{
|
|
419
418
|
__innerSelectionChange: boolean;
|
420
419
|
__chineseInputTimer: any;
|
421
420
|
initRange: () => void;
|
422
|
-
copy: (isCut?: boolean | undefined) => Promise<{
|
423
|
-
text: string;
|
424
|
-
html: string;
|
425
|
-
} | undefined>;
|
426
|
-
cut: () => Promise<{
|
427
|
-
text: string;
|
428
|
-
html: string;
|
429
|
-
} | undefined>;
|
430
421
|
delete: () => void;
|
431
422
|
insertText: (data: string) => void;
|
432
423
|
insertParagraph: () => void;
|
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);
|
@@ -2939,91 +3020,38 @@ const handleKeydown = function(e) {
|
|
2939
3020
|
};
|
2940
3021
|
const handleCopy = async function(e) {
|
2941
3022
|
e.preventDefault();
|
2942
|
-
|
3023
|
+
if (!this.range) {
|
3024
|
+
return;
|
3025
|
+
}
|
3026
|
+
if (!this.allowCopy) {
|
3027
|
+
return;
|
3028
|
+
}
|
3029
|
+
const event2 = e;
|
3030
|
+
const result = this.getElementsByRange().list;
|
3031
|
+
if (event2.clipboardData && result.length) {
|
3032
|
+
const { text, html } = setClipboardData.apply(this, [event2.clipboardData, result]);
|
3033
|
+
this.emit("copy", text, html);
|
3034
|
+
}
|
2943
3035
|
};
|
2944
3036
|
const handleCut = async function(e) {
|
2945
3037
|
e.preventDefault();
|
2946
|
-
|
2947
|
-
|
2948
|
-
this.formatElementStack();
|
2949
|
-
this.domRender();
|
2950
|
-
this.rangeRender();
|
3038
|
+
if (!this.range) {
|
3039
|
+
return;
|
2951
3040
|
}
|
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
|
-
}
|
3041
|
+
if (!this.allowCut) {
|
3042
|
+
return;
|
3043
|
+
}
|
3044
|
+
const event2 = e;
|
3045
|
+
const result = this.getElementsByRange().list;
|
3046
|
+
if (event2.clipboardData && result.length) {
|
3047
|
+
const { text, html } = setClipboardData.apply(this, [event2.clipboardData, result]);
|
3048
|
+
if (!this.disabled) {
|
3049
|
+
this.delete();
|
3050
|
+
this.formatElementStack();
|
3051
|
+
this.domRender();
|
3052
|
+
this.rangeRender();
|
3026
3053
|
}
|
3054
|
+
this.emit("cut", text, html);
|
3027
3055
|
}
|
3028
3056
|
};
|
3029
3057
|
const handlePaste = async function(e) {
|
@@ -3101,7 +3129,6 @@ class AlexEditor {
|
|
3101
3129
|
__publicField(this, "customFilePaste");
|
3102
3130
|
__publicField(this, "customMerge");
|
3103
3131
|
__publicField(this, "customParseNode");
|
3104
|
-
__publicField(this, "useClipboard", canUseClipboard());
|
3105
3132
|
__publicField(this, "history", new AlexHistory());
|
3106
3133
|
__publicField(this, "stack");
|
3107
3134
|
__publicField(this, "range", null);
|
@@ -3153,67 +3180,6 @@ class AlexEditor {
|
|
3153
3180
|
const focus = new AlexPoint(firstElement, 0);
|
3154
3181
|
this.range = new AlexRange(anchor, focus);
|
3155
3182
|
}
|
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
3183
|
/**
|
3218
3184
|
* 根据光标进行删除操作
|
3219
3185
|
*/
|
@@ -26177,7 +26143,7 @@ const attachment = (options) => {
|
|
26177
26143
|
const install = (app) => {
|
26178
26144
|
app.component(Editify.name, Editify);
|
26179
26145
|
};
|
26180
|
-
const version = "0.1.
|
26146
|
+
const version = "0.1.26";
|
26181
26147
|
export {
|
26182
26148
|
AlexElement,
|
26183
26149
|
Editify,
|