vue-editify 0.1.17 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- package/examples/App.vue +13 -5
- package/lib/editify/editify.vue.d.ts +30 -12
- package/lib/editify/props.d.ts +11 -3
- package/lib/editify.es.js +50 -31
- package/lib/editify.umd.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/style.css +1 -1
- package/package.json +2 -2
- package/src/editify/editify.vue +38 -27
- package/src/editify/props.ts +13 -3
- package/src/index.ts +1 -1
package/examples/App.vue
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
<template>
|
2
2
|
<div style="padding: 80px 10px 10px 10px; height: 100%; box-sizing: border-box">
|
3
|
-
<Editify ref="editify" border v-model="val" :menu="menuConfig" style="height: 100%" placeholder="Please Enter Text..." locale="zh_CN" allowPasteHtml :
|
3
|
+
<Editify ref="editify" border v-model="val" :menu="menuConfig" style="height: 100%" placeholder="Please Enter Text..." locale="zh_CN" allowPasteHtml :customHtmlPaste="customHtmlPaste"></Editify>
|
4
4
|
</div>
|
5
5
|
</template>
|
6
6
|
<script setup lang="ts">
|
7
7
|
import { ref } from 'vue'
|
8
|
-
import { Editify, insertImage, insertVideo } from '../src/index'
|
8
|
+
import { AlexElement, Editify, insertImage, insertVideo } from '../src/index'
|
9
9
|
import { MenuConfigType } from '../src/index'
|
10
10
|
const val = ref<string>('<p><br></p>')
|
11
11
|
const editify = ref<InstanceType<typeof Editify> | null>(null)
|
@@ -22,9 +22,17 @@ const menuConfig = ref<MenuConfigType>({
|
|
22
22
|
show: true
|
23
23
|
}
|
24
24
|
})
|
25
|
-
const
|
26
|
-
|
27
|
-
|
25
|
+
const customHtmlPaste = function (elements) {
|
26
|
+
for (let i = 0; i < elements.length; i++) {
|
27
|
+
if (elements[i].hasMarks()) {
|
28
|
+
elements[i].marks['data-paste'] = 'true'
|
29
|
+
} else {
|
30
|
+
elements[i].marks = {
|
31
|
+
'data-paste': 'true'
|
32
|
+
}
|
33
|
+
}
|
34
|
+
editify.value!.editor!.insertElement(elements[i], false)
|
35
|
+
}
|
28
36
|
}
|
29
37
|
</script>
|
30
38
|
<style lang="less">
|
@@ -59,16 +59,24 @@ declare const _default: import('vue').DefineComponent<{
|
|
59
59
|
type: BooleanConstructor;
|
60
60
|
default: boolean;
|
61
61
|
};
|
62
|
+
customTextPaste: {
|
63
|
+
type: import("vue").PropType<(data: string) => void | Promise<void>>;
|
64
|
+
default: null;
|
65
|
+
};
|
66
|
+
customHtmlPaste: {
|
67
|
+
type: import("vue").PropType<(elements: AlexElement[]) => void | Promise<void>>;
|
68
|
+
default: null;
|
69
|
+
};
|
62
70
|
customImagePaste: {
|
63
|
-
type: import("vue").PropType<(
|
71
|
+
type: import("vue").PropType<(file: File) => void | Promise<void>>;
|
64
72
|
default: null;
|
65
73
|
};
|
66
74
|
customVideoPaste: {
|
67
|
-
type: import("vue").PropType<(
|
75
|
+
type: import("vue").PropType<(file: File) => void | Promise<void>>;
|
68
76
|
default: null;
|
69
77
|
};
|
70
78
|
customFilePaste: {
|
71
|
-
type: import("vue").PropType<(
|
79
|
+
type: import("vue").PropType<(file: File) => void | Promise<void>>;
|
72
80
|
default: null;
|
73
81
|
};
|
74
82
|
menu: {
|
@@ -111,9 +119,9 @@ declare const _default: import('vue').DefineComponent<{
|
|
111
119
|
allowPasteHtml: boolean;
|
112
120
|
customTextPaste: ((text: string) => void | Promise<void>) | null;
|
113
121
|
customHtmlPaste: ((AlexElements: AlexElement[], html: string) => void | Promise<void>) | null;
|
114
|
-
customImagePaste: ((
|
115
|
-
customVideoPaste: ((
|
116
|
-
customFilePaste: ((
|
122
|
+
customImagePaste: ((file: File) => void | Promise<void>) | null;
|
123
|
+
customVideoPaste: ((file: File) => void | Promise<void>) | null;
|
124
|
+
customFilePaste: ((file: File) => void | Promise<void>) | null;
|
117
125
|
customMerge: ((mergeElement: AlexElement, targetElement: AlexElement) => void | Promise<void>) | null;
|
118
126
|
customParseNode: ((el: AlexElement) => AlexElement) | null;
|
119
127
|
useClipboard: boolean;
|
@@ -607,16 +615,24 @@ declare const _default: import('vue').DefineComponent<{
|
|
607
615
|
type: BooleanConstructor;
|
608
616
|
default: boolean;
|
609
617
|
};
|
618
|
+
customTextPaste: {
|
619
|
+
type: import("vue").PropType<(data: string) => void | Promise<void>>;
|
620
|
+
default: null;
|
621
|
+
};
|
622
|
+
customHtmlPaste: {
|
623
|
+
type: import("vue").PropType<(elements: AlexElement[]) => void | Promise<void>>;
|
624
|
+
default: null;
|
625
|
+
};
|
610
626
|
customImagePaste: {
|
611
|
-
type: import("vue").PropType<(
|
627
|
+
type: import("vue").PropType<(file: File) => void | Promise<void>>;
|
612
628
|
default: null;
|
613
629
|
};
|
614
630
|
customVideoPaste: {
|
615
|
-
type: import("vue").PropType<(
|
631
|
+
type: import("vue").PropType<(file: File) => void | Promise<void>>;
|
616
632
|
default: null;
|
617
633
|
};
|
618
634
|
customFilePaste: {
|
619
|
-
type: import("vue").PropType<(
|
635
|
+
type: import("vue").PropType<(file: File) => void | Promise<void>>;
|
620
636
|
default: null;
|
621
637
|
};
|
622
638
|
menu: {
|
@@ -673,9 +689,11 @@ declare const _default: import('vue').DefineComponent<{
|
|
673
689
|
allowPasteHtml: boolean;
|
674
690
|
videoRatio: number;
|
675
691
|
showWordLength: boolean;
|
676
|
-
|
677
|
-
|
678
|
-
|
692
|
+
customTextPaste: (data: string) => void | Promise<void>;
|
693
|
+
customHtmlPaste: (elements: AlexElement[]) => void | Promise<void>;
|
694
|
+
customImagePaste: (file: File) => void | Promise<void>;
|
695
|
+
customVideoPaste: (file: File) => void | Promise<void>;
|
696
|
+
customFilePaste: (file: File) => void | Promise<void>;
|
679
697
|
pasteKeepMarks: ObjectType;
|
680
698
|
pasteKeepStyles: ObjectType;
|
681
699
|
customParseNode: (el: AlexElement) => AlexElement;
|
package/lib/editify/props.d.ts
CHANGED
@@ -70,16 +70,24 @@ export declare const EditifyProps: {
|
|
70
70
|
type: BooleanConstructor;
|
71
71
|
default: boolean;
|
72
72
|
};
|
73
|
+
customTextPaste: {
|
74
|
+
type: PropType<(data: string) => void | Promise<void>>;
|
75
|
+
default: null;
|
76
|
+
};
|
77
|
+
customHtmlPaste: {
|
78
|
+
type: PropType<(elements: AlexElement[]) => void | Promise<void>>;
|
79
|
+
default: null;
|
80
|
+
};
|
73
81
|
customImagePaste: {
|
74
|
-
type: PropType<(
|
82
|
+
type: PropType<(file: File) => void | Promise<void>>;
|
75
83
|
default: null;
|
76
84
|
};
|
77
85
|
customVideoPaste: {
|
78
|
-
type: PropType<(
|
86
|
+
type: PropType<(file: File) => void | Promise<void>>;
|
79
87
|
default: null;
|
80
88
|
};
|
81
89
|
customFilePaste: {
|
82
|
-
type: PropType<(
|
90
|
+
type: PropType<(file: File) => void | Promise<void>>;
|
83
91
|
default: null;
|
84
92
|
};
|
85
93
|
menu: {
|
package/lib/editify.es.js
CHANGED
@@ -2978,11 +2978,11 @@ const doPaste = async function(html, text, files) {
|
|
2978
2978
|
} else {
|
2979
2979
|
let length = files.length;
|
2980
2980
|
for (let i = 0; i < length; i++) {
|
2981
|
-
const url = await file$1.dataFileToBase64(files[i]);
|
2982
2981
|
if (files[i].type.startsWith("image/")) {
|
2983
2982
|
if (typeof this.customImagePaste == "function") {
|
2984
|
-
await this.customImagePaste.apply(this, [
|
2983
|
+
await this.customImagePaste.apply(this, [files[i]]);
|
2985
2984
|
} else {
|
2985
|
+
const url = await file$1.dataFileToBase64(files[i]);
|
2986
2986
|
const image = new AlexElement(
|
2987
2987
|
"closed",
|
2988
2988
|
"img",
|
@@ -2997,8 +2997,9 @@ const doPaste = async function(html, text, files) {
|
|
2997
2997
|
}
|
2998
2998
|
} else if (files[i].type.startsWith("video/")) {
|
2999
2999
|
if (typeof this.customVideoPaste == "function") {
|
3000
|
-
await this.customVideoPaste.apply(this, [
|
3000
|
+
await this.customVideoPaste.apply(this, [files[i]]);
|
3001
3001
|
} else {
|
3002
|
+
const url = await file$1.dataFileToBase64(files[i]);
|
3002
3003
|
const video = new AlexElement(
|
3003
3004
|
"closed",
|
3004
3005
|
"video",
|
@@ -3013,7 +3014,7 @@ const doPaste = async function(html, text, files) {
|
|
3013
3014
|
}
|
3014
3015
|
} else {
|
3015
3016
|
if (typeof this.customFilePaste == "function") {
|
3016
|
-
await this.customFilePaste.apply(this, [
|
3017
|
+
await this.customFilePaste.apply(this, [files[i]]);
|
3017
3018
|
}
|
3018
3019
|
}
|
3019
3020
|
}
|
@@ -24789,6 +24790,16 @@ const EditifyProps = {
|
|
24789
24790
|
type: Boolean,
|
24790
24791
|
default: false
|
24791
24792
|
},
|
24793
|
+
//自定义粘贴纯文字
|
24794
|
+
customTextPaste: {
|
24795
|
+
type: Function,
|
24796
|
+
default: null
|
24797
|
+
},
|
24798
|
+
//自定义粘贴html
|
24799
|
+
customHtmlPaste: {
|
24800
|
+
type: Function,
|
24801
|
+
default: null
|
24802
|
+
},
|
24792
24803
|
//自定义粘贴图片
|
24793
24804
|
customImagePaste: {
|
24794
24805
|
type: Function,
|
@@ -25227,9 +25238,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
25227
25238
|
allowPaste: props.allowPaste,
|
25228
25239
|
allowCut: props.allowCut,
|
25229
25240
|
allowPasteHtml: props.allowPasteHtml,
|
25241
|
+
customTextPaste: props.customTextPaste,
|
25230
25242
|
customImagePaste: props.customImagePaste,
|
25231
25243
|
customVideoPaste: props.customVideoPaste,
|
25232
25244
|
customFilePaste: props.customFilePaste,
|
25245
|
+
customHtmlPaste: handleCustomHtmlPaste,
|
25233
25246
|
customMerge: handleCustomMerge,
|
25234
25247
|
customParseNode: handleCustomParseNode
|
25235
25248
|
});
|
@@ -25239,7 +25252,6 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
25239
25252
|
editor.value.on("blur", handleEditorBlur);
|
25240
25253
|
editor.value.on("insertParagraph", handleInsertParagraph);
|
25241
25254
|
editor.value.on("rangeUpdate", handleRangeUpdate);
|
25242
|
-
editor.value.on("pasteHtml", handlePasteHtml);
|
25243
25255
|
editor.value.on("deleteInStart", handleDeleteInStart);
|
25244
25256
|
editor.value.on("deleteComplete", handleDeleteComplete);
|
25245
25257
|
editor.value.on("afterRender", handleAfterRender);
|
@@ -25359,6 +25371,37 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
25359
25371
|
}
|
25360
25372
|
}
|
25361
25373
|
};
|
25374
|
+
const handleCustomHtmlPaste = async (elements) => {
|
25375
|
+
const keepStyles = Object.assign(pasteKeepData.styles, props.pasteKeepStyles || {});
|
25376
|
+
const keepMarks = Object.assign(pasteKeepData.marks, props.pasteKeepMarks || {});
|
25377
|
+
AlexElement.flatElements(elements).forEach((el) => {
|
25378
|
+
let marks = {};
|
25379
|
+
let styles = {};
|
25380
|
+
if (el.hasMarks()) {
|
25381
|
+
for (let key in keepMarks) {
|
25382
|
+
if (el.marks.hasOwnProperty(key) && (Array.isArray(keepMarks[key]) && keepMarks[key].includes(el.parsedom) || keepMarks[key] == "*")) {
|
25383
|
+
marks[key] = el.marks[key];
|
25384
|
+
}
|
25385
|
+
}
|
25386
|
+
el.marks = marks;
|
25387
|
+
}
|
25388
|
+
if (el.hasStyles() && !el.isText()) {
|
25389
|
+
for (let key in keepStyles) {
|
25390
|
+
if (el.styles.hasOwnProperty(key) && (Array.isArray(keepStyles[key]) && keepStyles[key].includes(el.parsedom) || keepStyles[key] == "*")) {
|
25391
|
+
styles[key] = el.styles[key];
|
25392
|
+
}
|
25393
|
+
}
|
25394
|
+
el.styles = styles;
|
25395
|
+
}
|
25396
|
+
});
|
25397
|
+
if (typeof props.customHtmlPaste == "function") {
|
25398
|
+
await props.customHtmlPaste.apply(this, [elements]);
|
25399
|
+
} else {
|
25400
|
+
for (let i = 0; i < elements.length; i++) {
|
25401
|
+
editor.value.insertElement(elements[i], false);
|
25402
|
+
}
|
25403
|
+
}
|
25404
|
+
};
|
25362
25405
|
const handleCustomMerge = (ele, preEle) => {
|
25363
25406
|
const uneditable = preEle.getUneditableElement();
|
25364
25407
|
if (uneditable) {
|
@@ -25498,30 +25541,6 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
25498
25541
|
}, 200);
|
25499
25542
|
emits("rangeupdate");
|
25500
25543
|
};
|
25501
|
-
const handlePasteHtml = (elements) => {
|
25502
|
-
const keepStyles = Object.assign(pasteKeepData.styles, props.pasteKeepStyles || {});
|
25503
|
-
const keepMarks = Object.assign(pasteKeepData.marks, props.pasteKeepMarks || {});
|
25504
|
-
AlexElement.flatElements(elements).forEach((el) => {
|
25505
|
-
let marks = {};
|
25506
|
-
let styles = {};
|
25507
|
-
if (el.hasMarks()) {
|
25508
|
-
for (let key in keepMarks) {
|
25509
|
-
if (el.marks.hasOwnProperty(key) && (Array.isArray(keepMarks[key]) && keepMarks[key].includes(el.parsedom) || keepMarks[key] == "*")) {
|
25510
|
-
marks[key] = el.marks[key];
|
25511
|
-
}
|
25512
|
-
}
|
25513
|
-
el.marks = marks;
|
25514
|
-
}
|
25515
|
-
if (el.hasStyles() && !el.isText()) {
|
25516
|
-
for (let key in keepStyles) {
|
25517
|
-
if (el.styles.hasOwnProperty(key) && (Array.isArray(keepStyles[key]) && keepStyles[key].includes(el.parsedom) || keepStyles[key] == "*")) {
|
25518
|
-
styles[key] = el.styles[key];
|
25519
|
-
}
|
25520
|
-
}
|
25521
|
-
el.styles = styles;
|
25522
|
-
}
|
25523
|
-
});
|
25524
|
-
};
|
25525
25544
|
const handleDeleteInStart = (element2) => {
|
25526
25545
|
if (element2.isBlock()) {
|
25527
25546
|
elementToParagraph(element2);
|
@@ -25719,8 +25738,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
25719
25738
|
};
|
25720
25739
|
}
|
25721
25740
|
});
|
25722
|
-
const Editify = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-
|
25723
|
-
const version = "0.1.
|
25741
|
+
const Editify = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-c0db2307"]]);
|
25742
|
+
const version = "0.1.18";
|
25724
25743
|
const install = (app) => {
|
25725
25744
|
app.component(Editify.name, Editify);
|
25726
25745
|
};
|