@keyblade/tinymce-editor-vue2 0.0.12-alpha.45 → 0.0.12-alpha.47

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 CHANGED
@@ -42,6 +42,17 @@ Vue.use(TinymceEditor, {
42
42
  })
43
43
  }, 1000)
44
44
  })
45
+ },
46
+ // 网络图片,将URL传给后端,让后端下载后校验、转换、压缩等操作
47
+ handleRequestByUrl: (url: string, parameters: { extParameters: Record<string, any> }) => {
48
+ return new Promise((resolve) => {
49
+ setTimeout(() => {
50
+ resolve({
51
+ success: true,
52
+ url: 'https://object.gcongo.com.cn/onecode-travel/nonClassic/8cefe379c03b5f39cd8ef725293a3c02/2024/5/1715995588295/d0b5bb458b694130be0c63e2f1d0090b.png'
53
+ })
54
+ }, 1000)
55
+ })
45
56
  }
46
57
  },
47
58
  // 音频
@@ -173,6 +184,10 @@ export interface ImageUploadOptions {
173
184
  handleRequest?: (file: File, filename: string, options?: {
174
185
  extParameters?: Record<string, any>
175
186
  }) => Promise<{success: boolean; url?: string; errorMessage?: string}>;
187
+ /** 图片URL上传请求处理(前端跨域,交给后端处理) */
188
+ handleRequestByUrl?: (url: string, options?: {
189
+ extParameters?: Record<string, any>
190
+ }) => Promise<{success: boolean; url?: string; errorMessage?: string}>;
176
191
  }
177
192
  ```
178
193
 
package/es/editor.vue2.js CHANGED
@@ -1,11 +1,11 @@
1
- import { defineComponent as xe, ref as x, computed as A, watch as U, onMounted as we, onUnmounted as be } from "vue";
2
- import { oneTravelImgPondBeforeAddFile as J, oneTravelImageCheckAndTransform as ye, oneTravelImageCompressor as K } from "@keyblade/one-travel";
3
- import { blobToFile as Q, getFileExtension as X, generateUUID as _e, getImagePixel as Te } from "./util.js";
1
+ import { defineComponent as De, ref as y, computed as T, watch as k, onMounted as Ae, onUnmounted as Te } from "vue";
2
+ import { oneTravelImgPondBeforeAddFile as K, oneTravelImageCompressor as Q, oneTravelImageCheckAndTransform as Ce } from "@keyblade/one-travel";
3
+ import { blobToFile as Y, generateUUID as Pe, getImagePixel as Z, getFileExtension as ee } from "./util.js";
4
4
  import "./style.less.js";
5
- import Ae from "imgpond";
5
+ import Me from "imgpond";
6
6
  import { conclude as C } from "vue-global-config";
7
- import Y from "tinymce";
8
- import Ce from "./langs/zh_CN.js";
7
+ import ae from "tinymce";
8
+ import Se from "./langs/zh_CN.js";
9
9
  import "tinymce/skins/ui/oxide/skin";
10
10
  import "tinymce/models/dom";
11
11
  import "tinymce/themes/silver";
@@ -34,9 +34,9 @@ import "tinymce/plugins/table";
34
34
  import "tinymce/plugins/visualblocks";
35
35
  import "tinymce/plugins/visualchars";
36
36
  import "tinymce/plugins/wordcount";
37
- import { globalProps as D } from "./index.js";
38
- import { Message as y } from "element-ui";
39
- const ma = /* @__PURE__ */ xe({
37
+ import { globalProps as P } from "./index.js";
38
+ import { Message as f } from "element-ui";
39
+ const va = /* @__PURE__ */ De({
40
40
  __name: "editor",
41
41
  props: {
42
42
  value: { default: "" },
@@ -50,88 +50,87 @@ const ma = /* @__PURE__ */ xe({
50
50
  initComplete: null
51
51
  },
52
52
  emits: ["input"],
53
- setup(Z, { emit: H }) {
54
- const m = Z;
55
- Y.addI18n("zh_CN", Ce);
56
- const V = {
53
+ setup(te, { emit: z }) {
54
+ const m = te;
55
+ ae.addI18n("zh_CN", Se);
56
+ const B = {
57
57
  maxCount: 10,
58
58
  tipText: "上传",
59
59
  maxSize: 30,
60
60
  allowedType: ["jpg", "jpeg", "png", "bmp", "heif", "heic", "gif", "webp"],
61
- // allowedMineType: ['image/jpg', 'image/jpeg', 'image/png', 'image/bmp', 'image/heif', 'image/heic', 'image/gif', 'image/webp']
62
61
  minWidth: 50,
63
62
  minHeight: 50,
64
63
  maxWidth: 6e3,
65
64
  maxHeight: 6e3
66
- }, B = {
65
+ }, j = {
67
66
  enable: !0,
68
67
  maxSize: 300,
69
68
  allowedType: ["mp4", "3gp"],
70
69
  accept: "video/mp4,video/3gpp"
71
- }, W = {
70
+ }, q = {
72
71
  enable: !0,
73
72
  maxSize: 200,
74
73
  allowedType: ["mp3", "m4a", "wav", "aac"],
75
74
  accept: "audio/mp3,audio/wav,audio/aac,audio/x-m4a"
76
- }, $ = x(), f = x(), P = x(!1), M = x(!1), g = x({
75
+ }, E = y(), h = y(), M = y(!1), S = y(!1), v = y({
77
76
  show: !1,
78
77
  text: "图片上传中,请稍等"
79
- }), d = A(() => C([m.imageUploadOptions, D.imageUploadOptions, V]) || {}), c = A(() => C([m.videoUploadOptions, D.videoUploadOptions, B]) || {}), h = A(() => C([m.audioUploadOptions, D.audioUploadOptions, W]) || {}), z = A(() => C([m.imgPondOptions, D.imgPondOptions]) || {}), ee = A(() => {
80
- var e, t;
81
- return ((t = (e = d == null ? void 0 : d.value) == null ? void 0 : e.allowedType) == null ? void 0 : t.map((i) => `.${i}`).join(",")) || "";
82
- }), k = x();
83
- U(() => k.value, () => {
84
- k.value && J(k.value, {
78
+ }), r = T(() => C([m.imageUploadOptions, P.imageUploadOptions, B]) || {}), c = T(() => C([m.videoUploadOptions, P.videoUploadOptions, j]) || {}), w = T(() => C([m.audioUploadOptions, P.audioUploadOptions, q]) || {}), H = T(() => C([m.imgPondOptions, P.imgPondOptions]) || {}), oe = T(() => {
79
+ var e, a;
80
+ return ((a = (e = r == null ? void 0 : r.value) == null ? void 0 : e.allowedType) == null ? void 0 : a.map((t) => `.${t}`).join(",")) || "";
81
+ }), U = y();
82
+ k(() => U.value, () => {
83
+ U.value && K(U.value, {
85
84
  onStart: () => {
86
- g.value = {
85
+ v.value = {
87
86
  show: !0,
88
87
  text: "图片加载中,请稍等"
89
88
  };
90
89
  },
91
90
  onSuccess: () => {
92
- g.value.show = !1;
91
+ v.value.show = !1;
93
92
  },
94
93
  onError: (e) => {
95
- g.value.show = !1, y.error(e);
94
+ v.value.show = !1, f.error(e);
96
95
  }
97
96
  });
98
97
  }, { immediate: !0 });
99
- const I = x();
100
- U(() => I.value, () => {
101
- I.value && J(I.value, {
98
+ const I = y();
99
+ k(() => I.value, () => {
100
+ I.value && K(I.value, {
102
101
  onStart: () => {
103
- g.value = {
102
+ v.value = {
104
103
  show: !0,
105
104
  text: "图片加载中,请稍等"
106
105
  };
107
106
  },
108
107
  onSuccess: () => {
109
- g.value.show = !1;
108
+ v.value.show = !1;
110
109
  },
111
110
  onError: (e) => {
112
- g.value.show = !1, y.error(e);
111
+ v.value.show = !1, f.error(e);
113
112
  }
114
113
  });
115
114
  }, { immediate: !0 });
116
- const T = x({
115
+ const A = y({
117
116
  dialogVisible: !1,
118
117
  formData: {
119
118
  images: []
120
119
  }
121
- }), E = x(), R = () => {
122
- T.value.dialogVisible = !1, T.value.formData = {
120
+ }), $ = y(), R = () => {
121
+ A.value.dialogVisible = !1, A.value.formData = {
123
122
  images: []
124
123
  };
125
- }, ae = () => {
124
+ }, ie = () => {
126
125
  var e;
127
- (e = E.value) == null || e.validate((t) => {
128
- t && (T.value.formData.images.forEach((i) => {
129
- var o;
130
- let a = i;
131
- z.value.srcAt && (a = (i == null ? void 0 : i[z.value.srcAt]) || ""), (o = f.value) == null || o.insertContent(`<img src=${a} alt="" />`);
126
+ (e = $.value) == null || e.validate((a) => {
127
+ a && (A.value.formData.images.forEach((t) => {
128
+ var l;
129
+ let o = t;
130
+ H.value.srcAt && (o = (t == null ? void 0 : t[H.value.srcAt]) || ""), (l = h.value) == null || l.insertContent(`<img src=${o} alt="" />`);
132
131
  }), R());
133
132
  });
134
- }, v = x({
133
+ }, x = y({
135
134
  dialogVisible: !1,
136
135
  formData: {
137
136
  // 名称
@@ -143,19 +142,19 @@ const ma = /* @__PURE__ */ xe({
143
142
  },
144
143
  // 用于临时保存上传前的参数 { file: File }
145
144
  additionalData: {}
146
- }), j = x(), q = () => {
147
- v.value.dialogVisible = !1, v.value.formData = {
145
+ }), F = y(), N = () => {
146
+ x.value.dialogVisible = !1, x.value.formData = {
148
147
  name: "",
149
148
  cover: [],
150
149
  file: []
151
- }, v.value.additionalData = {};
152
- }, oe = () => {
150
+ }, x.value.additionalData = {};
151
+ }, le = () => {
153
152
  var e;
154
- (e = j.value) == null || e.validate((t) => {
155
- var i, a;
156
- t && ((a = f.value) == null || a.insertContent(`<audio controls controlslist="nodownload noplaybackrate" data-name="${v.value.formData.name}" data-poster="${v.value.formData.cover[0]}" src="${(i = v.value.formData.file[0]) == null ? void 0 : i.url}"></audio>`), q());
153
+ (e = F.value) == null || e.validate((a) => {
154
+ var t, o;
155
+ a && ((o = h.value) == null || o.insertContent(`<audio controls controlslist="nodownload noplaybackrate" data-name="${x.value.formData.name}" data-poster="${x.value.formData.cover[0]}" src="${(t = x.value.formData.file[0]) == null ? void 0 : t.url}"></audio>`), N());
157
156
  });
158
- }, w = x({
157
+ }, _ = y({
159
158
  dialogVisible: !1,
160
159
  formData: {
161
160
  // 文件
@@ -163,83 +162,175 @@ const ma = /* @__PURE__ */ xe({
163
162
  },
164
163
  // 用于临时保存上传前的参数 { file: File }
165
164
  additionalData: {}
166
- }), N = x(), F = () => {
167
- w.value.dialogVisible = !1, w.value.formData = {
165
+ }), O = y(), L = () => {
166
+ _.value.dialogVisible = !1, _.value.formData = {
168
167
  file: []
169
- }, w.value.additionalData = {};
170
- }, te = () => {
168
+ }, _.value.additionalData = {};
169
+ }, ne = () => {
171
170
  var e;
172
- (e = N.value) == null || e.validate((t) => {
173
- var i, a;
174
- t && ((a = f.value) == null || a.insertContent(`<video width="auto" height="auto" controls src="${(i = w.value.formData.file[0]) == null ? void 0 : i.url}"></video>`), F());
171
+ (e = O.value) == null || e.validate((a) => {
172
+ var t, o;
173
+ a && ((o = h.value) == null || o.insertContent(`<video width="auto" height="auto" controls src="${(t = _.value.formData.file[0]) == null ? void 0 : t.url}"></video>`), L());
175
174
  });
176
- }, ie = () => {
175
+ }, re = () => {
177
176
  document.querySelectorAll(".swal2-container .swal2-title").forEach((e) => {
178
- e && (e.innerHTML = `单次最多可选择${d.value.maxCount}张图片`);
177
+ e && (e.innerHTML = `单次最多可选择${r.value.maxCount}张图片`);
179
178
  });
180
- }, le = (e, t) => new Promise(async (i, a) => {
181
- var r, n;
182
- const o = await K(e);
183
- if (!o.success) {
184
- a(), setTimeout(() => {
185
- t.onError(o.errorMessage);
179
+ }, se = (e, a) => new Promise(async (t, o) => {
180
+ var d, n;
181
+ const l = await Q(e);
182
+ if (!l.success) {
183
+ o(), setTimeout(() => {
184
+ a.onError(l.errorMessage);
186
185
  });
187
186
  return;
188
187
  }
189
- const l = await ((n = (r = d.value).handleRequest) == null ? void 0 : n.call(r, Q(o.file, e.name), e.name, { extParameters: m.extParameters }));
190
- if (!l || !(l != null && l.success)) {
191
- a(), setTimeout(() => {
192
- t.onError(l == null ? void 0 : l.errorMessage);
188
+ const i = await ((n = (d = r.value).handleRequest) == null ? void 0 : n.call(d, Y(l.file, e.name), e.name, { extParameters: m.extParameters }));
189
+ if (!i || !(i != null && i.success)) {
190
+ o(), setTimeout(() => {
191
+ a.onError(i == null ? void 0 : i.errorMessage);
193
192
  });
194
193
  return;
195
194
  }
196
- i(l.url);
195
+ t(i.url);
197
196
  });
198
- async function L(e, t) {
199
- const a = t.node.getElementsByTagName("img"), o = [];
200
- for (let l = a.length - 1; l >= 0; l--) {
201
- const r = a[l], n = "img-" + _e();
202
- r.classList.add(n), o.push(n);
197
+ async function ue(e, a) {
198
+ const o = a.node.getElementsByTagName("img"), l = [];
199
+ for (let i = o.length - 1; i >= 0; i--) {
200
+ const d = o[i], n = "img-" + Pe();
201
+ d.classList.add(n), l.push(n);
203
202
  }
204
203
  setTimeout(async () => {
205
- var l, r;
206
- for (let n = o.length - 1; n >= 0; n--) {
207
- const s = e.dom.select(`.${o[n]}`);
208
- if (s.length === 0)
204
+ var i, d;
205
+ for (let n = l.length - 1; n >= 0; n--) {
206
+ const u = e.dom.select(`.${l[n]}`);
207
+ if (u.length === 0)
209
208
  continue;
210
- const u = s[0], p = u.src;
209
+ const s = u[0], p = s.src;
211
210
  if (p.startsWith("data:image")) {
212
- e.dom.remove(u);
211
+ e.dom.remove(s);
213
212
  continue;
214
213
  } else if (p.startsWith("http://") || p.startsWith("https://")) {
215
- const b = await Te(p);
216
- if (b && (b.width < (d.value.minWidth || 0) && b.height < (d.value.minHeight || 0) || b.width > (d.value.maxWidth || 0) && b.height > (d.value.maxHeight || 0))) {
217
- e.dom.remove(u);
214
+ const b = await Z(p);
215
+ if (b && (b.width < (r.value.minWidth || 0) && b.height < (r.value.minHeight || 0) || b.width > (r.value.maxWidth || 0) && b.height > (r.value.maxHeight || 0))) {
216
+ e.dom.remove(s);
218
217
  continue;
219
218
  }
220
- const S = X(p);
221
- if (!((r = (l = d.value) == null ? void 0 : l.allowedType) != null && r.includes(S.toLowerCase()))) {
222
- e.dom.remove(u);
219
+ const W = ee(p);
220
+ if (!((d = (i = r.value) == null ? void 0 : i.allowedType) != null && d.includes(W.toLowerCase()))) {
221
+ e.dom.remove(s);
223
222
  continue;
224
223
  }
225
224
  }
226
225
  }
227
226
  });
228
227
  }
229
- const _ = () => {
230
- setTimeout(() => {
231
- var t;
232
- const e = document.querySelector(".tox-notifications-container");
233
- (t = e == null ? void 0 : e.remove) == null || t.call(e);
234
- }, 2e3);
228
+ async function G(e) {
229
+ var d, n, u;
230
+ let a = e;
231
+ if (!((d = r.value) != null && d.handleRequest)) {
232
+ f.error("缺少图片上传配置");
233
+ return;
234
+ }
235
+ v.value = {
236
+ show: !0,
237
+ text: "图片上传中,请稍等"
238
+ };
239
+ let t = a.name ? a.name : "";
240
+ if (!(a != null && a.name) && !(a != null && a.lastModified) && a.type === "image/png") {
241
+ v.value.show = !1, f.error("不允许粘贴");
242
+ return;
243
+ }
244
+ const o = await Ce(a, t, {
245
+ imageMaxSize: r.value.maxSize,
246
+ imageAllowedType: r.value.allowedType,
247
+ // imageAllowedMineType: mergeImageUploadOptions.value.allowedMineType,
248
+ imageMinWidth: r.value.minWidth,
249
+ imageMinHeight: r.value.minHeight,
250
+ imageMaxWidth: r.value.maxWidth,
251
+ imageMaxHeight: r.value.maxHeight
252
+ });
253
+ if (!o.success) {
254
+ v.value.show = !1, f.error((o == null ? void 0 : o.errorMessage) || "");
255
+ return;
256
+ }
257
+ if (o.hasTransform) {
258
+ a = o.file;
259
+ const s = t == null ? void 0 : t.split(".");
260
+ s.pop(), t = `${s.join(",")}.jpg`;
261
+ }
262
+ const l = await Q(a);
263
+ if (!l.success) {
264
+ v.value.show = !1, f.error((l == null ? void 0 : l.errorMessage) || "压缩失败");
265
+ return;
266
+ }
267
+ const i = await ((u = (n = r.value).handleRequest) == null ? void 0 : u.call(n, Y(l.file, t), t, { extParameters: m.extParameters }));
268
+ if (!i || !i.success) {
269
+ v.value.show = !1, f.error((i == null ? void 0 : i.errorMessage) || "");
270
+ return;
271
+ }
272
+ return v.value.show = !1, i.url;
273
+ }
274
+ const V = async (e) => {
275
+ var l, i, d;
276
+ const a = h.value, t = e.types;
277
+ if (t.includes("text/html")) {
278
+ const n = e.getData("text/html"), s = new DOMParser().parseFromString(n, "text/html"), p = Array.from(s.body.querySelectorAll("img")), b = Array.from(s.body.querySelectorAll("audio")), W = Array.from(s.body.querySelectorAll("video"));
279
+ p.length > 0 && (v.value = {
280
+ show: !0,
281
+ text: "图片加载中,请稍等"
282
+ });
283
+ for (const D of [...b, ...W])
284
+ D == null || D.remove();
285
+ for await (const D of [...p])
286
+ if (D.removeAttribute("crossorigin"), D.src.startsWith("http"))
287
+ if ((l = r.value) != null && l.handleRequestByUrl) {
288
+ const g = await ((i = r.value) == null ? void 0 : i.handleRequestByUrl(D.src, { extParameters: m.extParameters }));
289
+ g != null && g.success && (g != null && g.url) ? D.src = g == null ? void 0 : g.url : D.remove();
290
+ } else {
291
+ const g = await Z(D.src);
292
+ g && (g.width < (r.value.minWidth || 0) && g.height < (r.value.minHeight || 0) || g.width > (r.value.maxWidth || 0) && g.height > (r.value.maxHeight || 0)) && D.remove();
293
+ }
294
+ else
295
+ D.remove(), f.error("不支持Word中批量复制图片或视频,请改为单个复制,或者从工具栏中手动插入上传");
296
+ v.value.show = !1;
297
+ const _e = new XMLSerializer().serializeToString(s.body);
298
+ a.insertContent(_e);
299
+ } else
300
+ t.includes("text/plain") && a.insertContent(e.getData("text/plain"));
301
+ const o = Array.from(e.items);
302
+ for await (const n of o) {
303
+ const u = n.getAsFile();
304
+ if (!u)
305
+ continue;
306
+ const s = ee(u.name);
307
+ if (u.type.indexOf("image") > -1 || (d = r.value.allowedType) != null && d.includes(s.toLowerCase())) {
308
+ const p = await G(u);
309
+ if (p) {
310
+ const b = `<img src="${p}" alt="" />`;
311
+ a.insertContent(b);
312
+ }
313
+ }
314
+ }
315
+ z("input", a.getContent());
316
+ }, X = (e) => {
317
+ var t;
318
+ e.preventDefault();
319
+ const a = e.clipboardData || ((t = e == null ? void 0 : e.originalEvent) == null ? void 0 : t.clipboardData);
320
+ V(a);
321
+ }, J = (e) => {
322
+ var t;
323
+ e.preventDefault();
324
+ const a = e.dataTransfer || ((t = e == null ? void 0 : e.originalEvent) == null ? void 0 : t.dataTransfer);
325
+ V(a);
235
326
  };
236
- we(() => {
237
- var i;
327
+ Ae(() => {
328
+ var t;
238
329
  const e = {
239
330
  // 设置语言
240
331
  language: "zh_CN",
241
332
  // 实例
242
- target: $.value,
333
+ target: E.value,
243
334
  // 隐藏品牌
244
335
  branding: !1,
245
336
  // 隐藏右上角升级按钮
@@ -316,213 +407,242 @@ const ma = /* @__PURE__ */ xe({
316
407
  relative_urls: !1,
317
408
  convert_urls: !1,
318
409
  paste_webkit_styles: "all",
319
- paste_data_images: !0,
320
- images_file_types: ((i = d.value.allowedType) == null ? void 0 : i.join(",")) || "jpeg,jpg,jpe,jfi,jif,jfif,png,gif,bmp,webp",
410
+ paste_data_images: !1,
411
+ images_file_types: ((t = r.value.allowedType) == null ? void 0 : t.join(",")) || "jpeg,jpg,jpe,jfi,jif,jfif,png,gif,bmp,webp",
321
412
  // 粘贴前处理
322
- paste_preprocess(a, o) {
323
- o.content = o.content.replace(/<video[^>]*(?:\/>|>[\s\S]*?<\/video>)/g, ""), o.content = o.content.replace(/<audio[^>]*(?:\/>|>[\s\S]*?<\/audio>)/g, ""), o.content = o.content.replace(/<nav/g, "<div").replace(/<\/nav>/g, "</div>"), o.content = o.content.replace(/<header/g, "<div").replace(/<\/header>/g, "</div>"), o.content = o.content.replace(/<footer/g, "<div").replace(/<\/footer>/g, "</div>"), o.content = o.content.replace(/<aside/g, "<div").replace(/<\/aside>/g, "</div>"), o.content = o.content.replace(/<section/g, "<div").replace(/<\/section>/g, "</div>"), o.content = o.content.replace(/<main/g, "<div").replace(/<\/main>/g, "</div>"), o.content = o.content.replace(/<article/g, "<div").replace(/<\/article>/g, "</div>"), o.content = o.content.replace(/<details/g, "<div").replace(/<\/details>/g, "</div>");
413
+ paste_preprocess(o, l) {
414
+ l == null || l.preventDefault();
324
415
  },
325
- // 粘贴后处理(处理异步操作)
326
- paste_postprocess(a, o) {
327
- L(a, o);
328
- },
329
- images_upload_handler(a) {
330
- return new Promise(async (o, l) => {
331
- var b, S, O;
332
- if (!((b = d.value) != null && b.handleRequest))
333
- return _(), l({ message: "缺少图片上传配置", remove: !0 });
334
- g.value = {
335
- show: !0,
336
- text: "图片上传中,请稍等"
337
- };
338
- let r = a.blob(), n = r.name ? r.name : a.filename();
339
- if (!(r != null && r.name) && !(r != null && r.lastModified) && r.type === "image/png")
340
- return g.value.show = !1, _(), l({ message: "不允许粘贴", remove: !0 });
341
- const s = await ye(r, n, {
342
- imageMaxSize: d.value.maxSize,
343
- imageAllowedType: d.value.allowedType,
344
- // imageAllowedMineType: mergeImageUploadOptions.value.allowedMineType,
345
- imageMinWidth: d.value.minWidth,
346
- imageMinHeight: d.value.minHeight,
347
- imageMaxWidth: d.value.maxWidth,
348
- imageMaxHeight: d.value.maxHeight
349
- });
350
- if (!s.success)
351
- return g.value.show = !1, _(), l({ message: (s == null ? void 0 : s.errorMessage) || "", remove: !0 });
352
- if (s.hasTransform) {
353
- r = s.file;
354
- const G = n == null ? void 0 : n.split(".");
355
- G.pop(), n = `${G.join(",")}.jpg`;
356
- }
357
- const u = await K(r);
358
- if (!u.success)
359
- return g.value.show = !1, _(), l({ message: u == null ? void 0 : u.errorMessage, remove: !0 });
360
- const p = await ((O = (S = d.value).handleRequest) == null ? void 0 : O.call(S, Q(u.file, n), n, { extParameters: m.extParameters }));
361
- if (!p || !p.success)
362
- return g.value.show = !1, _(), l({ message: p.errorMessage, remove: !0 });
363
- g.value.show = !1, o(p.url);
364
- });
365
- },
366
- setup(a) {
367
- var l, r;
368
- const o = () => {
369
- T.value.dialogVisible = !0, setTimeout(() => {
370
- var s, u;
371
- const n = (s = document == null ? void 0 : document.querySelector) == null ? void 0 : s.call(document, ".tinymce-editor-upload-image-dialog .el-upload__text > div");
372
- n && (n.innerHTML = ((u = d.value) == null ? void 0 : u.tipText) || "上传");
416
+ // // 粘贴后处理(处理异步操作)
417
+ // paste_postprocess(editor, args) {
418
+ // // 处理图片
419
+ // processPastedImage(editor, args)
420
+ // },
421
+ // images_upload_handler(blobInfo) {
422
+ // // eslint-disable-next-line no-async-promise-executor
423
+ // return new Promise(async (resolve, reject) => {
424
+ // // 校验图片配置
425
+ // if (!mergeImageUploadOptions.value?.handleRequest) {
426
+ // removeNotification()
427
+ // return reject({ message: '缺少图片上传配置', remove: true })
428
+ // }
429
+ //
430
+ // uploadLoadingConfig.value = {
431
+ // show: true,
432
+ // text: '图片上传中,请稍等'
433
+ // }
434
+ //
435
+ // // 获取文件 blob 数据
436
+ // // 1.从本地复制图片都是 File 对象,chrome 复制非图片文件,都是 blob,且为 png
437
+ // let file = blobInfo.blob()
438
+ // // 有名称,则取真实名称
439
+ // let filename = (file as File).name ? (file as File).name : blobInfo.filename()
440
+ // if (!(file as File)?.name && !(file as File)?.lastModified && file.type === 'image/png') {// chrome 复制非图片格式
441
+ // uploadLoadingConfig.value.show = false
442
+ // removeNotification()
443
+ // return reject({ message: '不允许粘贴', remove: true })
444
+ // }
445
+ //
446
+ // // 图片校验
447
+ // const checkRes = await oneTravelImageCheckAndTransform(file, filename, {
448
+ // imageMaxSize: mergeImageUploadOptions.value.maxSize,
449
+ // imageAllowedType: mergeImageUploadOptions.value.allowedType,
450
+ // imageMinWidth: mergeImageUploadOptions.value.minWidth,
451
+ // imageMinHeight: mergeImageUploadOptions.value.minHeight,
452
+ // imageMaxWidth: mergeImageUploadOptions.value.maxWidth,
453
+ // imageMaxHeight: mergeImageUploadOptions.value.maxHeight
454
+ // })
455
+ // if (!checkRes.success) {
456
+ // uploadLoadingConfig.value.show = false
457
+ // removeNotification()
458
+ // return reject({ message: checkRes?.errorMessage || '', remove: true })
459
+ // }
460
+ // if (checkRes.hasTransform) {// 被转换
461
+ // // 修改文件
462
+ // file = checkRes.file!
463
+ //
464
+ // // 修改名称
465
+ // const arr = filename?.split('.')
466
+ // arr.pop()
467
+ // const prefix = arr.join(',')
468
+ // filename = `${prefix}.jpg`
469
+ // }
470
+ //
471
+ // // 图片压缩
472
+ // const compressorRes = await oneTravelImageCompressor(file)
473
+ // if (!compressorRes.success) {
474
+ // uploadLoadingConfig.value.show = false
475
+ // removeNotification()
476
+ // return reject({ message: compressorRes?.errorMessage, remove: true })
477
+ // }
478
+ //
479
+ // // 上传图片
480
+ // const uploadRes = await mergeImageUploadOptions.value.handleRequest?.(blobToFile(compressorRes.file, filename), filename, { extParameters: props.extParameters })
481
+ // if (!uploadRes || !uploadRes.success) {
482
+ // uploadLoadingConfig.value.show = false
483
+ // removeNotification()
484
+ // return reject({ message: uploadRes.errorMessage, remove: true })
485
+ // }
486
+ //
487
+ // uploadLoadingConfig.value.show = false
488
+ // resolve(uploadRes.url!)
489
+ // })
490
+ // },
491
+ setup(o) {
492
+ var i, d;
493
+ const l = () => {
494
+ A.value.dialogVisible = !0, setTimeout(() => {
495
+ var u, s;
496
+ const n = (u = document == null ? void 0 : document.querySelector) == null ? void 0 : u.call(document, ".tinymce-editor-upload-image-dialog .el-upload__text > div");
497
+ n && (n.innerHTML = ((s = r.value) == null ? void 0 : s.tipText) || "上传");
373
498
  });
374
499
  };
375
- if (a.ui.registry.addMenuItem("localImage", {
500
+ if (o.ui.registry.addMenuItem("localImage", {
376
501
  text: "图片",
377
502
  icon: "image",
378
- onAction: () => o()
379
- }), a.ui.registry.addButton("localImage", {
503
+ onAction: () => l()
504
+ }), o.ui.registry.addButton("localImage", {
380
505
  icon: "image",
381
506
  tooltip: "图片",
382
- onAction: () => o()
383
- }), (l = h == null ? void 0 : h.value) != null && l.enable) {
507
+ onAction: () => l()
508
+ }), (i = w == null ? void 0 : w.value) != null && i.enable) {
384
509
  const n = () => {
385
- v.value.dialogVisible = !0, setTimeout(() => {
386
- var u, p;
387
- const s = (u = document == null ? void 0 : document.querySelector) == null ? void 0 : u.call(document, ".tinymce-editor-upload-audio-dialog .el-upload__text > div");
388
- s && (s.innerHTML = ((p = d.value) == null ? void 0 : p.tipText) || "上传");
510
+ x.value.dialogVisible = !0, setTimeout(() => {
511
+ var s, p;
512
+ const u = (s = document == null ? void 0 : document.querySelector) == null ? void 0 : s.call(document, ".tinymce-editor-upload-audio-dialog .el-upload__text > div");
513
+ u && (u.innerHTML = ((p = r.value) == null ? void 0 : p.tipText) || "上传");
389
514
  });
390
515
  };
391
- a.ui.registry.addMenuItem("localAudio", {
516
+ o.ui.registry.addMenuItem("localAudio", {
392
517
  text: "音频",
393
518
  icon: "arrow-right",
394
519
  onAction: () => n()
395
- }), a.ui.registry.addButton("localAudio", {
520
+ }), o.ui.registry.addButton("localAudio", {
396
521
  icon: "arrow-right",
397
522
  tooltip: "音频",
398
523
  onAction: () => n()
399
524
  });
400
525
  }
401
- if ((r = c == null ? void 0 : c.value) != null && r.enable) {
526
+ if ((d = c == null ? void 0 : c.value) != null && d.enable) {
402
527
  const n = () => {
403
- w.value.dialogVisible = !0;
528
+ _.value.dialogVisible = !0;
404
529
  };
405
- a.ui.registry.addMenuItem("localVideo", {
530
+ o.ui.registry.addMenuItem("localVideo", {
406
531
  text: "视频",
407
532
  icon: "embed",
408
533
  onAction: () => n()
409
- }), a.ui.registry.addButton("localVideo", {
534
+ }), o.ui.registry.addButton("localVideo", {
410
535
  icon: "embed",
411
536
  tooltip: "视频",
412
537
  onAction: () => n()
413
538
  });
414
539
  }
415
540
  }
416
- }, t = C(
541
+ }, a = C(
417
542
  [
418
543
  m.options,
419
- D.options,
544
+ P.options,
420
545
  e
421
546
  ],
422
547
  {
423
- mergeFunction: (a, o) => (...l) => {
424
- a(...l), o(...l);
548
+ mergeFunction: (o, l) => (...i) => {
549
+ o(...i), l(...i);
425
550
  },
426
551
  type: Object
427
552
  }
428
553
  );
429
- Y.init(t).then(([a]) => {
430
- var o;
431
- a && (a.customProps = { ...m }, a.on("input", () => {
432
- if (M.value) {
433
- M.value = !1;
554
+ ae.init(a).then(([o]) => {
555
+ var l;
556
+ o && (o.customProps = { ...m }, o.on("input", () => {
557
+ if (S.value) {
558
+ S.value = !1;
434
559
  return;
435
560
  }
436
- P.value = !0, H("input", a.getContent());
437
- }), a.on("paste", (l) => {
438
- var n, s;
439
- const r = ((n = l.clipboardData) == null ? void 0 : n.files) || [];
440
- for (let u of r) {
441
- const p = X(u.name) || "";
442
- (s = d.value.allowedType) != null && s.includes(p.toLowerCase()) || l.preventDefault();
443
- }
444
- }), a.on("drop", () => {
445
- _();
446
- }), (o = m.initComplete) == null || o.call(m, { editorIns: a }), f.value = a);
561
+ M.value = !0, z("input", o.getContent());
562
+ }), o.on("paste", (i) => {
563
+ X(i);
564
+ }), o.on("drop", (i) => {
565
+ J(i);
566
+ }), (l = m.initComplete) == null || l.call(m, { editorIns: o }), h.value = o);
447
567
  });
448
- }), be(() => {
449
- var e, t, i, a;
450
- (e = f.value) == null || e.off("input"), (t = f.value) == null || t.off("paste"), (i = f.value) == null || i.off("drop"), (a = f.value) == null || a.destroy();
568
+ }), Te(() => {
569
+ var e, a, t, o;
570
+ (e = h.value) == null || e.off("input"), (a = h.value) == null || a.off("paste"), (t = h.value) == null || t.off("drop"), (o = h.value) == null || o.destroy();
451
571
  });
452
- const ne = () => {
453
- var t, i;
454
- const e = { ...v.value.additionalData || {} };
455
- return ((i = (t = h.value) == null ? void 0 : t.data) == null ? void 0 : i.call(t, { ...e, extParameters: m.extParameters })) || {};
456
- }, re = () => {
457
- var t, i;
458
- const e = { ...v.value.additionalData || {} };
459
- return ((i = (t = h.value) == null ? void 0 : t.headers) == null ? void 0 : i.call(t, { ...e, extParameters: m.extParameters })) || {};
460
- }, se = (e, t, i) => {
461
- var o, l;
462
- const a = (l = (o = h == null ? void 0 : h.value) == null ? void 0 : o.handlerResponse) == null ? void 0 : l.call(o, e);
463
- a != null && a.url ? i[i.length - 1].url = a.url : a != null && a.errorMessage && (y.error(a.errorMessage), i.splice(i.length - 1, 1)), v.value.formData.file = i;
464
- }, ue = (e, t) => new Promise((i, a) => {
465
- var l, r, n, s, u, p;
466
- const o = e.name.split(".").filter(Boolean).pop() ? e.name.split(".").filter(Boolean).pop() : "";
467
- if (!((r = (l = h.value) == null ? void 0 : l.allowedType) != null && r.includes(o.toLowerCase()))) {
468
- y.error(`请上传格式为${(s = (n = h.value) == null ? void 0 : n.allowedType) == null ? void 0 : s.map((b) => b.toUpperCase()).join("、")}的音频`), a();
572
+ const me = () => {
573
+ var a, t;
574
+ const e = { ...x.value.additionalData || {} };
575
+ return ((t = (a = w.value) == null ? void 0 : a.data) == null ? void 0 : t.call(a, { ...e, extParameters: m.extParameters })) || {};
576
+ }, de = () => {
577
+ var a, t;
578
+ const e = { ...x.value.additionalData || {} };
579
+ return ((t = (a = w.value) == null ? void 0 : a.headers) == null ? void 0 : t.call(a, { ...e, extParameters: m.extParameters })) || {};
580
+ }, ce = (e, a, t) => {
581
+ var l, i;
582
+ const o = (i = (l = w == null ? void 0 : w.value) == null ? void 0 : l.handlerResponse) == null ? void 0 : i.call(l, e);
583
+ o != null && o.url ? t[t.length - 1].url = o.url : o != null && o.errorMessage && (f.error(o.errorMessage), t.splice(t.length - 1, 1)), x.value.formData.file = t;
584
+ }, pe = (e, a) => new Promise((t, o) => {
585
+ var i, d, n, u, s, p;
586
+ const l = e.name.split(".").filter(Boolean).pop() ? e.name.split(".").filter(Boolean).pop() : "";
587
+ if (!((d = (i = w.value) == null ? void 0 : i.allowedType) != null && d.includes(l.toLowerCase()))) {
588
+ f.error(`请上传格式为${(u = (n = w.value) == null ? void 0 : n.allowedType) == null ? void 0 : u.map((b) => b.toUpperCase()).join("、")}的音频`), o();
469
589
  return;
470
590
  }
471
- if (e.size > (((u = h.value) == null ? void 0 : u.maxSize) || 0) * 1024 * 1024) {
472
- y.error(`请上传${((p = h.value) == null ? void 0 : p.maxSize) || 0}M内的音频`), a();
591
+ if (e.size > (((s = w.value) == null ? void 0 : s.maxSize) || 0) * 1024 * 1024) {
592
+ f.error(`请上传${((p = w.value) == null ? void 0 : p.maxSize) || 0}M内的音频`), o();
473
593
  return;
474
594
  }
475
- v.value.additionalData = { file: e }, i(!0);
476
- }), de = (e, t) => {
477
- v.value.formData.file = t;
478
- }, me = (e, t, i) => {
479
- y.error("上传发生错误,请重试!"), v.value.formData.file = i;
480
- }, ce = () => {
481
- var t, i;
482
- const e = { ...w.value.additionalData || {} };
483
- return ((i = (t = c.value) == null ? void 0 : t.data) == null ? void 0 : i.call(t, { ...e, extParameters: m.extParameters })) || {};
484
- }, pe = () => {
485
- var t, i;
486
- const e = { ...w.value.additionalData || {} };
487
- return ((i = (t = c.value) == null ? void 0 : t.headers) == null ? void 0 : i.call(t, { ...e, extParameters: m.extParameters })) || {};
488
- }, ve = (e, t, i) => {
489
- var o, l;
490
- const a = (l = (o = c == null ? void 0 : c.value) == null ? void 0 : o.handlerResponse) == null ? void 0 : l.call(o, e);
491
- a != null && a.url ? i[i.length - 1].url = a.url : a != null && a.errorMessage && (y.error(a.errorMessage), i.splice(i.length - 1, 1)), w.value.formData.file = i;
492
- }, fe = (e, t) => new Promise((i, a) => {
493
- var l, r, n, s, u, p;
494
- const o = e.name.split(".").filter(Boolean).pop() ? e.name.split(".").filter(Boolean).pop() : "";
495
- if (!((r = (l = c == null ? void 0 : c.value) == null ? void 0 : l.allowedType) != null && r.includes(o.toLowerCase()))) {
496
- y.error(`请上传格式为${(s = (n = c == null ? void 0 : c.value) == null ? void 0 : n.allowedType) == null ? void 0 : s.map((b) => b.toUpperCase()).join("、")}的视频`), a();
595
+ x.value.additionalData = { file: e }, t(!0);
596
+ }), fe = (e, a) => {
597
+ x.value.formData.file = a;
598
+ }, ve = (e, a, t) => {
599
+ f.error("上传发生错误,请重试!"), x.value.formData.file = t;
600
+ }, ge = () => {
601
+ var a, t;
602
+ const e = { ..._.value.additionalData || {} };
603
+ return ((t = (a = c.value) == null ? void 0 : a.data) == null ? void 0 : t.call(a, { ...e, extParameters: m.extParameters })) || {};
604
+ }, he = () => {
605
+ var a, t;
606
+ const e = { ..._.value.additionalData || {} };
607
+ return ((t = (a = c.value) == null ? void 0 : a.headers) == null ? void 0 : t.call(a, { ...e, extParameters: m.extParameters })) || {};
608
+ }, xe = (e, a, t) => {
609
+ var l, i;
610
+ const o = (i = (l = c == null ? void 0 : c.value) == null ? void 0 : l.handlerResponse) == null ? void 0 : i.call(l, e);
611
+ o != null && o.url ? t[t.length - 1].url = o.url : o != null && o.errorMessage && (f.error(o.errorMessage), t.splice(t.length - 1, 1)), _.value.formData.file = t;
612
+ }, we = (e, a) => new Promise((t, o) => {
613
+ var i, d, n, u, s, p;
614
+ const l = e.name.split(".").filter(Boolean).pop() ? e.name.split(".").filter(Boolean).pop() : "";
615
+ if (!((d = (i = c == null ? void 0 : c.value) == null ? void 0 : i.allowedType) != null && d.includes(l.toLowerCase()))) {
616
+ f.error(`请上传格式为${(u = (n = c == null ? void 0 : c.value) == null ? void 0 : n.allowedType) == null ? void 0 : u.map((b) => b.toUpperCase()).join("、")}的视频`), o();
497
617
  return;
498
618
  }
499
- if (e.size > (((u = c == null ? void 0 : c.value) == null ? void 0 : u.maxSize) || 0) * 1024 * 1024) {
500
- y.error(`请上传${((p = c == null ? void 0 : c.value) == null ? void 0 : p.maxSize) || 0}M内的视频`), a();
619
+ if (e.size > (((s = c == null ? void 0 : c.value) == null ? void 0 : s.maxSize) || 0) * 1024 * 1024) {
620
+ f.error(`请上传${((p = c == null ? void 0 : c.value) == null ? void 0 : p.maxSize) || 0}M内的视频`), o();
501
621
  return;
502
622
  }
503
- w.value.additionalData = { file: e }, i(!0);
504
- }), ge = (e, t) => {
505
- w.value.formData.file = t;
506
- }, he = (e, t, i) => {
507
- y.error("上传发生错误,请重试!"), w.value.formData.file = i;
623
+ _.value.additionalData = { file: e }, t(!0);
624
+ }), be = (e, a) => {
625
+ _.value.formData.file = a;
626
+ }, ye = (e, a, t) => {
627
+ f.error("上传发生错误,请重试!"), _.value.formData.file = t;
508
628
  };
509
- return U(() => [m.disabled, f.value], () => {
510
- var e, t;
511
- (t = (e = f.value) == null ? void 0 : e.mode) == null || t.set(m.disabled ? "readonly" : "design");
512
- }, { immediate: !0 }), U(
513
- () => [m.value, f.value],
629
+ return k(() => [m.disabled, h.value], () => {
630
+ var e, a;
631
+ (a = (e = h.value) == null ? void 0 : e.mode) == null || a.set(m.disabled ? "readonly" : "design");
632
+ }, { immediate: !0 }), k(
633
+ () => [m.value, h.value],
514
634
  () => {
515
635
  var e;
516
- if (P.value) {
517
- P.value = !1;
636
+ if (M.value) {
637
+ M.value = !1;
518
638
  return;
519
639
  }
520
- M.value = !0, (e = f.value) == null || e.setContent(m.value ? m.value : "");
640
+ S.value = !0, (e = h.value) == null || e.setContent(m.value ? m.value : "");
521
641
  },
522
642
  { immediate: !0 }
523
- ), { __sfc: !0, defaultImageUploadOptions: V, defaultVideoUploadOptions: B, defaultAudioUploadOptions: W, props: m, emits: H, insRef: $, editorRef: f, preventSettingContent: P, preventUpdatingModelValue: M, uploadLoadingConfig: g, mergeImageUploadOptions: d, mergeVideoUploadOptions: c, mergeAudioUploadOptions: h, mergeImgPondOptions: z, imgPondAccept: ee, uploadImageImgPondRef: k, audioImageImgPondRef: I, uploadImage: T, uploadImageFormRef: E, onUploadImageClose: R, onUploadImageConfirm: ae, uploadAudio: v, uploadAudioFormRef: j, onUploadAudioClose: q, onUploadAudioConfirm: oe, uploadVideo: w, uploadVideoFormRef: N, onUploadVideoClose: F, onUploadVideoConfirm: te, onImageUploadUploadExceed: ie, onImageUploadUpload: le, processPastedImage: L, removeNotification: _, getUploadAudioData: ne, getUploadAudioHeaders: re, onUploadAudioSuccess: se, onUploadAudioBeforeUpload: ue, onUploadAudioRemove: de, onUploadAudioError: me, getUploadVideoData: ce, getUploadVideoHeaders: pe, onUploadVideoSuccess: ve, onUploadVideoBeforeUpload: fe, onUploadVideoRemove: ge, onUploadVideoError: he, ImgPond: Ae };
643
+ ), { __sfc: !0, defaultImageUploadOptions: B, defaultVideoUploadOptions: j, defaultAudioUploadOptions: q, props: m, emits: z, insRef: E, editorRef: h, preventSettingContent: M, preventUpdatingModelValue: S, uploadLoadingConfig: v, mergeImageUploadOptions: r, mergeVideoUploadOptions: c, mergeAudioUploadOptions: w, mergeImgPondOptions: H, imgPondAccept: oe, uploadImageImgPondRef: U, audioImageImgPondRef: I, uploadImage: A, uploadImageFormRef: $, onUploadImageClose: R, onUploadImageConfirm: ie, uploadAudio: x, uploadAudioFormRef: F, onUploadAudioClose: N, onUploadAudioConfirm: le, uploadVideo: _, uploadVideoFormRef: O, onUploadVideoClose: L, onUploadVideoConfirm: ne, onImageUploadUploadExceed: re, onImageUploadUpload: se, processPastedImage: ue, uploadPasteOrDropFile: G, handleDataTransfer: V, onValuePaste: X, onValueDrop: J, getUploadAudioData: me, getUploadAudioHeaders: de, onUploadAudioSuccess: ce, onUploadAudioBeforeUpload: pe, onUploadAudioRemove: fe, onUploadAudioError: ve, getUploadVideoData: ge, getUploadVideoHeaders: he, onUploadVideoSuccess: xe, onUploadVideoBeforeUpload: we, onUploadVideoRemove: be, onUploadVideoError: ye, ImgPond: Me };
524
644
  }
525
645
  });
526
646
  export {
527
- ma as default
647
+ va as default
528
648
  };
package/es/types.d.ts CHANGED
@@ -24,6 +24,14 @@ export interface ImageUploadOptions {
24
24
  url?: string;
25
25
  errorMessage?: string;
26
26
  }>;
27
+ /** 图片URL上传请求处理(前端跨域,交给后端处理) */
28
+ handleRequestByUrl?: (url: string, options?: {
29
+ extParameters?: Record<string, any>;
30
+ }) => Promise<{
31
+ success: boolean;
32
+ url?: string;
33
+ errorMessage?: string;
34
+ }>;
27
35
  }
28
36
  /** 视频选项 */
29
37
  export interface VideoUploadOptions {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@keyblade/tinymce-editor-vue2",
3
3
  "description": "KeyBlade Tinymce Editor Vue2",
4
4
  "author": "yangshuai <704807396@qq.com>",
5
- "version": "0.0.12-alpha.45",
5
+ "version": "0.0.12-alpha.47",
6
6
  "private": false,
7
7
  "type": "module",
8
8
  "main": "es/index.js",
@@ -23,7 +23,7 @@
23
23
  "vue-global-config": "^0.2.6",
24
24
  "tinymce": "^7.1.0",
25
25
  "element-ui": "^2.15.14",
26
- "@keyblade/one-travel": "^2.0.11"
26
+ "@keyblade/one-travel": "^2.0.13"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "vue": "^2.7.0",