@keyblade/tinymce-editor-vue2 0.0.2 → 0.0.3
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/README.md +2 -0
- package/es/editor.vue.d.ts +7 -0
- package/es/editor.vue2.js +80 -78
- package/es/index.d.ts +26 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/es/editor.vue.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ declare const _default: import('vue-demi').DefineComponent<__VLS_WithDefaults<__
|
|
|
9
9
|
imageMaxSize?: number | undefined;
|
|
10
10
|
/** 图片允许的类型 */
|
|
11
11
|
imageAllowedType?: string[] | undefined;
|
|
12
|
+
/** 图片允许的类型 */
|
|
13
|
+
imageAllowedMineType?: string[] | undefined;
|
|
12
14
|
/** 图片最小宽度 */
|
|
13
15
|
imageMinWidth?: number | undefined;
|
|
14
16
|
/** 图片最小高度 */
|
|
@@ -42,6 +44,7 @@ declare const _default: import('vue-demi').DefineComponent<__VLS_WithDefaults<__
|
|
|
42
44
|
modelValue: string;
|
|
43
45
|
imageMaxSize: number;
|
|
44
46
|
imageAllowedType: () => string[];
|
|
47
|
+
imageAllowedMineType: () => string[];
|
|
45
48
|
imageMinWidth: number;
|
|
46
49
|
imageMinHeight: number;
|
|
47
50
|
imageMaxWidth: number;
|
|
@@ -62,6 +65,8 @@ declare const _default: import('vue-demi').DefineComponent<__VLS_WithDefaults<__
|
|
|
62
65
|
imageMaxSize?: number | undefined;
|
|
63
66
|
/** 图片允许的类型 */
|
|
64
67
|
imageAllowedType?: string[] | undefined;
|
|
68
|
+
/** 图片允许的类型 */
|
|
69
|
+
imageAllowedMineType?: string[] | undefined;
|
|
65
70
|
/** 图片最小宽度 */
|
|
66
71
|
imageMinWidth?: number | undefined;
|
|
67
72
|
/** 图片最小高度 */
|
|
@@ -95,6 +100,7 @@ declare const _default: import('vue-demi').DefineComponent<__VLS_WithDefaults<__
|
|
|
95
100
|
modelValue: string;
|
|
96
101
|
imageMaxSize: number;
|
|
97
102
|
imageAllowedType: () => string[];
|
|
103
|
+
imageAllowedMineType: () => string[];
|
|
98
104
|
imageMinWidth: number;
|
|
99
105
|
imageMinHeight: number;
|
|
100
106
|
imageMaxWidth: number;
|
|
@@ -105,6 +111,7 @@ declare const _default: import('vue-demi').DefineComponent<__VLS_WithDefaults<__
|
|
|
105
111
|
modelValue: string;
|
|
106
112
|
imageMaxSize: number;
|
|
107
113
|
imageAllowedType: string[];
|
|
114
|
+
imageAllowedMineType: string[];
|
|
108
115
|
imageMinWidth: number;
|
|
109
116
|
imageMinHeight: number;
|
|
110
117
|
imageMaxWidth: number;
|
package/es/editor.vue2.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { ref as
|
|
3
|
-
import
|
|
4
|
-
import { conclude as
|
|
5
|
-
import
|
|
6
|
-
import { addI18n as
|
|
1
|
+
import { defineComponent as F } from "vue";
|
|
2
|
+
import { ref as y, computed as W, onMounted as N, onUnmounted as j, watch as L } from "vue-demi";
|
|
3
|
+
import q from "compressorjs";
|
|
4
|
+
import { conclude as _ } from "vue-global-config";
|
|
5
|
+
import E from "tinymce";
|
|
6
|
+
import { addI18n as G } from "./langs/zh_CN.js";
|
|
7
7
|
import "tinymce/skins/ui/oxide/skin";
|
|
8
8
|
import "tinymce/models/dom";
|
|
9
9
|
import "tinymce/themes/silver";
|
|
@@ -32,14 +32,15 @@ import "tinymce/plugins/table";
|
|
|
32
32
|
import "tinymce/plugins/visualblocks";
|
|
33
33
|
import "tinymce/plugins/visualchars";
|
|
34
34
|
import "tinymce/plugins/wordcount";
|
|
35
|
-
import { globalProps as
|
|
36
|
-
const
|
|
35
|
+
import { globalProps as d } from "./index.js";
|
|
36
|
+
const ze = /* @__PURE__ */ F({
|
|
37
37
|
__name: "editor",
|
|
38
38
|
props: {
|
|
39
39
|
value: { default: "" },
|
|
40
40
|
modelValue: { default: "" },
|
|
41
41
|
imageMaxSize: { default: 30 },
|
|
42
42
|
imageAllowedType: { default: () => ["jpg", "jpeg", "png", "bmp", "heif", "gif", "webp"] },
|
|
43
|
+
imageAllowedMineType: { default: () => ["image/jpg", "image/jpeg", "image/png", "image/bmp", "image/heif", "image/heic", "image/gif", "image/webp"] },
|
|
43
44
|
imageMinWidth: { default: 60 },
|
|
44
45
|
imageMinHeight: { default: 60 },
|
|
45
46
|
imageMaxWidth: { default: 6e3 },
|
|
@@ -51,50 +52,50 @@ const He = /* @__PURE__ */ O({
|
|
|
51
52
|
options: { default: () => ({}) }
|
|
52
53
|
},
|
|
53
54
|
emits: ["input", "update:modelValue"],
|
|
54
|
-
setup(
|
|
55
|
-
const a =
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
async function
|
|
55
|
+
setup(O, { expose: R, emit: b }) {
|
|
56
|
+
const a = O;
|
|
57
|
+
G();
|
|
58
|
+
const M = y(), m = y(), g = y(!1), f = y(!1);
|
|
59
|
+
async function A(n) {
|
|
59
60
|
var o, e;
|
|
60
|
-
const
|
|
61
|
-
for (let i of
|
|
61
|
+
const s = n.getElementsByTagName("img");
|
|
62
|
+
for (let i of s) {
|
|
62
63
|
const t = i.src;
|
|
63
64
|
if (t.startsWith("http://") || t.startsWith("https://")) {
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
65
|
+
const r = await C(t);
|
|
66
|
+
if (r.width < a.imageMinWidth && r.height < a.imageMinHeight || r.width > a.imageMaxWidth && r.height > a.imageMaxHeight) {
|
|
66
67
|
(o = i == null ? void 0 : i.remove) == null || o.call(i);
|
|
67
68
|
return;
|
|
68
69
|
}
|
|
69
|
-
const
|
|
70
|
-
if (!a.imageAllowedType.includes(
|
|
70
|
+
const w = t.split("."), S = w[w.length - 1].toLowerCase();
|
|
71
|
+
if (!a.imageAllowedType.includes(S)) {
|
|
71
72
|
(e = i == null ? void 0 : i.remove) == null || e.call(i);
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
|
-
const
|
|
78
|
-
const
|
|
78
|
+
const H = (n) => {
|
|
79
|
+
const s = n.split(","), o = s[0].match(/:(.*?);/)[1], e = atob(s[1]);
|
|
79
80
|
let i = e.length;
|
|
80
81
|
const t = new Uint8Array(i);
|
|
81
82
|
for (; i--; )
|
|
82
83
|
t[i] = e.charCodeAt(i);
|
|
83
84
|
return new Blob([t], { type: o });
|
|
84
85
|
};
|
|
85
|
-
function
|
|
86
|
-
return new Promise((
|
|
86
|
+
function C(n) {
|
|
87
|
+
return new Promise((s) => {
|
|
87
88
|
const o = new Image();
|
|
88
89
|
o.onload = function() {
|
|
89
|
-
|
|
90
|
+
s({ width: o.width, height: o.height, image: o });
|
|
90
91
|
}, o.src = n;
|
|
91
92
|
});
|
|
92
93
|
}
|
|
93
|
-
function
|
|
94
|
+
function T(n, s) {
|
|
94
95
|
return new Promise((o) => {
|
|
95
|
-
new
|
|
96
|
-
...
|
|
97
|
-
success(e) {
|
|
96
|
+
new q(n, {
|
|
97
|
+
...s,
|
|
98
|
+
success: async (e) => {
|
|
98
99
|
o({ success: !0, file: e });
|
|
99
100
|
},
|
|
100
101
|
error(e) {
|
|
@@ -103,16 +104,16 @@ const He = /* @__PURE__ */ O({
|
|
|
103
104
|
});
|
|
104
105
|
});
|
|
105
106
|
}
|
|
106
|
-
const
|
|
107
|
-
() =>
|
|
107
|
+
const h = W(
|
|
108
|
+
() => _([a.paste_preprocess, d.paste_preprocess], {
|
|
108
109
|
type: Function
|
|
109
110
|
})
|
|
110
|
-
),
|
|
111
|
-
() =>
|
|
111
|
+
), v = W(
|
|
112
|
+
() => _([a.paste_postprocess, d.paste_postprocess], {
|
|
112
113
|
type: Function
|
|
113
114
|
})
|
|
114
|
-
), c =
|
|
115
|
-
() =>
|
|
115
|
+
), c = W(
|
|
116
|
+
() => _([a.imageUploadHandle, d.imageUploadHandle], {
|
|
116
117
|
type: Function
|
|
117
118
|
})
|
|
118
119
|
);
|
|
@@ -124,7 +125,7 @@ const He = /* @__PURE__ */ O({
|
|
|
124
125
|
language: "zh_CN",
|
|
125
126
|
/** 需要配置到外部 */
|
|
126
127
|
// 实例
|
|
127
|
-
target:
|
|
128
|
+
target: M.value,
|
|
128
129
|
// 隐藏品牌
|
|
129
130
|
branding: !1,
|
|
130
131
|
// 隐藏右上角升级按钮
|
|
@@ -189,48 +190,49 @@ const He = /* @__PURE__ */ O({
|
|
|
189
190
|
// 粘贴前处理
|
|
190
191
|
paste_preprocess(o, e) {
|
|
191
192
|
var i;
|
|
192
|
-
e.content = e.content.replace(/<video[^>]*(?:\/>|>[\s\S]*?<\/video>)/g, ""), e.content = e.content.replace(/<audio[^>]*(?:\/>|>[\s\S]*?<\/audio>)/g, ""), e.content = e.content.replace(/<nav/g, "<div").replace(/<\/nav>/g, "</div>"), e.content = e.content.replace(/<header/g, "<div").replace(/<\/header>/g, "</div>"), e.content = e.content.replace(/<footer/g, "<div").replace(/<\/footer>/g, "</div>"), e.content = e.content.replace(/<aside/g, "<div").replace(/<\/aside>/g, "</div>"), e.content = e.content.replace(/<section/g, "<div").replace(/<\/section>/g, "</div>"), e.content = e.content.replace(/<main/g, "<div").replace(/<\/main>/g, "</div>"), e.content = e.content.replace(/<article/g, "<div").replace(/<\/article>/g, "</div>"), e.content = e.content.replace(/<details/g, "<div").replace(/<\/details>/g, "</div>"), (i =
|
|
193
|
+
e.content = e.content.replace(/<video[^>]*(?:\/>|>[\s\S]*?<\/video>)/g, ""), e.content = e.content.replace(/<audio[^>]*(?:\/>|>[\s\S]*?<\/audio>)/g, ""), e.content = e.content.replace(/<nav/g, "<div").replace(/<\/nav>/g, "</div>"), e.content = e.content.replace(/<header/g, "<div").replace(/<\/header>/g, "</div>"), e.content = e.content.replace(/<footer/g, "<div").replace(/<\/footer>/g, "</div>"), e.content = e.content.replace(/<aside/g, "<div").replace(/<\/aside>/g, "</div>"), e.content = e.content.replace(/<section/g, "<div").replace(/<\/section>/g, "</div>"), e.content = e.content.replace(/<main/g, "<div").replace(/<\/main>/g, "</div>"), e.content = e.content.replace(/<article/g, "<div").replace(/<\/article>/g, "</div>"), e.content = e.content.replace(/<details/g, "<div").replace(/<\/details>/g, "</div>"), (i = h.value) == null || i.call(h, o, e);
|
|
193
194
|
},
|
|
194
195
|
// 粘贴后处理(处理异步操作)
|
|
195
196
|
paste_postprocess(o, e) {
|
|
196
197
|
var t;
|
|
197
198
|
const i = e.node;
|
|
198
|
-
|
|
199
|
+
A(i), (t = v.value) == null || t.call(v, o, e);
|
|
199
200
|
},
|
|
200
201
|
images_upload_handler(o) {
|
|
201
202
|
return new Promise(async (e, i) => {
|
|
202
|
-
var
|
|
203
|
-
const t = (
|
|
204
|
-
let
|
|
205
|
-
const
|
|
206
|
-
if (
|
|
203
|
+
var x, V, B;
|
|
204
|
+
const t = (V = (x = d.message) == null ? void 0 : x.loading) == null ? void 0 : V.call(x);
|
|
205
|
+
let r = o.blob();
|
|
206
|
+
const w = o.base64(), S = o.filename(), P = r.name.split("."), $ = P[P.length - 1].toLowerCase();
|
|
207
|
+
if (r.size > a.imageMaxSize * 1024 * 1024)
|
|
207
208
|
return t == null || t.close(), i({ message: `请上传大小不超过${a.imageMaxSize}M的图片`, remove: !0 });
|
|
208
|
-
if (!a.
|
|
209
|
-
return t == null || t.close(), i({ message: `请上传格式为${a.imageAllowedType.map((
|
|
210
|
-
const
|
|
211
|
-
if (
|
|
209
|
+
if (!a.imageAllowedMineType.includes(r.type))
|
|
210
|
+
return t == null || t.close(), i({ message: `请上传格式为${a.imageAllowedType.map((u) => u.toUpperCase()).join("、")}的图片`, remove: !0 });
|
|
211
|
+
const U = "data:" + r.type + ";base64," + w, p = await C(U);
|
|
212
|
+
if (p.width < a.imageMinWidth && p.height < a.imageMinHeight || p.width > a.imageMaxWidth && p.height > a.imageMaxHeight)
|
|
212
213
|
return t == null || t.close(), i({ message: `请上传像素不低于${a.imageMinWidth}*${a.imageMinHeight}且像素不高于${a.imageMaxWidth}*${a.imageMaxHeight}的图片`, remove: !0 });
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
214
|
+
const l = {};
|
|
215
|
+
["image/heif", "image/heic", "image/webp"].includes($) && (l.convertTypes = [r.type], l.convertSize = 0);
|
|
216
|
+
const k = 5 * 1024 * 1024;
|
|
217
|
+
if (r.size > k && (l.convertTypes = [r.type], l.convertSize = k, l.maxWidth = p.width * (k / r.size)), Object.keys(l).length > 0) {
|
|
218
|
+
const u = await T(H(U), l);
|
|
219
|
+
if (u.success)
|
|
220
|
+
r = u.file;
|
|
221
|
+
else
|
|
222
|
+
return t == null || t.close(), i({ message: u.error, remove: !0 });
|
|
223
|
+
}
|
|
222
224
|
if (!c.value)
|
|
223
225
|
return t == null || t.close(), i({ message: "缺少图片上传配置", remove: !0 });
|
|
224
|
-
const
|
|
225
|
-
if (!
|
|
226
|
-
return t == null || t.close(), i({ message:
|
|
227
|
-
t == null || t.close(), e(
|
|
226
|
+
const z = await ((B = c.value) == null ? void 0 : B.call(c, r, S));
|
|
227
|
+
if (!z.success)
|
|
228
|
+
return t == null || t.close(), i({ message: z.errorMessage, remove: !0 });
|
|
229
|
+
t == null || t.close(), e(z.url);
|
|
228
230
|
});
|
|
229
231
|
}
|
|
230
|
-
},
|
|
232
|
+
}, s = _(
|
|
231
233
|
[
|
|
232
234
|
a.options,
|
|
233
|
-
|
|
235
|
+
d.tinymceOptions,
|
|
234
236
|
n
|
|
235
237
|
],
|
|
236
238
|
{
|
|
@@ -240,36 +242,36 @@ const He = /* @__PURE__ */ O({
|
|
|
240
242
|
type: Object
|
|
241
243
|
}
|
|
242
244
|
);
|
|
243
|
-
|
|
245
|
+
E.init(s).then(([o]) => {
|
|
244
246
|
var e;
|
|
245
247
|
o.on("change input Redo Undo SetContent", () => {
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
+
if (f.value) {
|
|
249
|
+
f.value = !1;
|
|
248
250
|
return;
|
|
249
251
|
}
|
|
250
|
-
|
|
251
|
-
}),
|
|
252
|
+
g.value = !0, b("input", o.getContent()), b("update:modelValue", o.getContent());
|
|
253
|
+
}), m.value = o, (e = a.initComplete) == null || e.call(a);
|
|
252
254
|
});
|
|
253
|
-
}),
|
|
255
|
+
}), j(() => {
|
|
254
256
|
var n;
|
|
255
|
-
(n =
|
|
256
|
-
}),
|
|
257
|
-
() => [a.value, a.modelValue,
|
|
257
|
+
(n = m.value) == null || n.destroy();
|
|
258
|
+
}), L(
|
|
259
|
+
() => [a.value, a.modelValue, m.value],
|
|
258
260
|
() => {
|
|
259
261
|
var n;
|
|
260
|
-
if (
|
|
261
|
-
|
|
262
|
+
if (g.value) {
|
|
263
|
+
g.value = !1;
|
|
262
264
|
return;
|
|
263
265
|
}
|
|
264
|
-
|
|
266
|
+
f.value = !0, (n = m.value) == null || n.setContent(a.value ?? a.modelValue ?? "");
|
|
265
267
|
},
|
|
266
268
|
{ immediate: !0 }
|
|
267
|
-
),
|
|
268
|
-
insRef:
|
|
269
|
-
editorRef:
|
|
270
|
-
}), { __sfc: !0, insRef:
|
|
269
|
+
), R({
|
|
270
|
+
insRef: M,
|
|
271
|
+
editorRef: m
|
|
272
|
+
}), { __sfc: !0, insRef: M, editorRef: m, preventSettingContent: g, preventUpdatingModelValue: f, props: a, emits: b, processPastedImage: A, dataURLtoBlob: H, getImagePixel: C, compressorImage: T, paste_preprocess: h, paste_postprocess: v, imageUploadHandle: c };
|
|
271
273
|
}
|
|
272
274
|
});
|
|
273
275
|
export {
|
|
274
|
-
|
|
276
|
+
ze as default
|
|
275
277
|
};
|
package/es/index.d.ts
CHANGED
|
@@ -45,6 +45,10 @@ declare const TinymceEditor: import('vue/types/v3-component-public-instance').Co
|
|
|
45
45
|
type: import('vue').PropType<string[]>;
|
|
46
46
|
default: () => string[];
|
|
47
47
|
};
|
|
48
|
+
imageAllowedMineType: {
|
|
49
|
+
type: import('vue').PropType<string[]>;
|
|
50
|
+
default: () => string[];
|
|
51
|
+
};
|
|
48
52
|
imageMinWidth: {
|
|
49
53
|
type: import('vue').PropType<number>;
|
|
50
54
|
default: number;
|
|
@@ -104,6 +108,10 @@ declare const TinymceEditor: import('vue/types/v3-component-public-instance').Co
|
|
|
104
108
|
type: import('vue').PropType<string[]>;
|
|
105
109
|
default: () => string[];
|
|
106
110
|
};
|
|
111
|
+
imageAllowedMineType: {
|
|
112
|
+
type: import('vue').PropType<string[]>;
|
|
113
|
+
default: () => string[];
|
|
114
|
+
};
|
|
107
115
|
imageMinWidth: {
|
|
108
116
|
type: import('vue').PropType<number>;
|
|
109
117
|
default: number;
|
|
@@ -154,6 +162,7 @@ declare const TinymceEditor: import('vue/types/v3-component-public-instance').Co
|
|
|
154
162
|
modelValue: string;
|
|
155
163
|
imageMaxSize: number;
|
|
156
164
|
imageAllowedType: string[];
|
|
165
|
+
imageAllowedMineType: string[];
|
|
157
166
|
imageMinWidth: number;
|
|
158
167
|
imageMinHeight: number;
|
|
159
168
|
imageMaxWidth: number;
|
|
@@ -176,6 +185,10 @@ declare const TinymceEditor: import('vue/types/v3-component-public-instance').Co
|
|
|
176
185
|
type: import('vue').PropType<string[]>;
|
|
177
186
|
default: () => string[];
|
|
178
187
|
};
|
|
188
|
+
imageAllowedMineType: {
|
|
189
|
+
type: import('vue').PropType<string[]>;
|
|
190
|
+
default: () => string[];
|
|
191
|
+
};
|
|
179
192
|
imageMinWidth: {
|
|
180
193
|
type: import('vue').PropType<number>;
|
|
181
194
|
default: number;
|
|
@@ -238,6 +251,10 @@ declare const TinymceEditor: import('vue/types/v3-component-public-instance').Co
|
|
|
238
251
|
type: import('vue').PropType<string[]>;
|
|
239
252
|
default: () => string[];
|
|
240
253
|
};
|
|
254
|
+
imageAllowedMineType: {
|
|
255
|
+
type: import('vue').PropType<string[]>;
|
|
256
|
+
default: () => string[];
|
|
257
|
+
};
|
|
241
258
|
imageMinWidth: {
|
|
242
259
|
type: import('vue').PropType<number>;
|
|
243
260
|
default: number;
|
|
@@ -297,6 +314,10 @@ declare const TinymceEditor: import('vue/types/v3-component-public-instance').Co
|
|
|
297
314
|
type: import('vue').PropType<string[]>;
|
|
298
315
|
default: () => string[];
|
|
299
316
|
};
|
|
317
|
+
imageAllowedMineType: {
|
|
318
|
+
type: import('vue').PropType<string[]>;
|
|
319
|
+
default: () => string[];
|
|
320
|
+
};
|
|
300
321
|
imageMinWidth: {
|
|
301
322
|
type: import('vue').PropType<number>;
|
|
302
323
|
default: number;
|
|
@@ -350,6 +371,7 @@ declare const TinymceEditor: import('vue/types/v3-component-public-instance').Co
|
|
|
350
371
|
modelValue: string;
|
|
351
372
|
imageMaxSize: number;
|
|
352
373
|
imageAllowedType: string[];
|
|
374
|
+
imageAllowedMineType: string[];
|
|
353
375
|
imageMinWidth: number;
|
|
354
376
|
imageMinHeight: number;
|
|
355
377
|
imageMaxWidth: number;
|
|
@@ -373,6 +395,10 @@ declare const TinymceEditor: import('vue/types/v3-component-public-instance').Co
|
|
|
373
395
|
type: import('vue').PropType<string[]>;
|
|
374
396
|
default: () => string[];
|
|
375
397
|
};
|
|
398
|
+
imageAllowedMineType: {
|
|
399
|
+
type: import('vue').PropType<string[]>;
|
|
400
|
+
default: () => string[];
|
|
401
|
+
};
|
|
376
402
|
imageMinWidth: {
|
|
377
403
|
type: import('vue').PropType<number>;
|
|
378
404
|
default: number;
|
package/package.json
CHANGED