@keyblade/tinymce-editor-vue2 0.0.12-alpha.16 → 0.0.12-alpha.18

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
@@ -99,88 +99,6 @@ onMounted(() => {
99
99
  </script>
100
100
  ```
101
101
 
102
- ### 3.使用工具类(单独使用图片上传组件的,可使用以下工具类自行处理)
103
- ```typescript
104
- import { oneTravelImageCheck, oneTravelImageCompressor, interceptImgPondBeforeAddFile } from '@keyblade/tinymce-editor-vue2'
105
-
106
- // oneTravelImageCheck: 一码游图片检测工具
107
- // oneTravelImageCompressor: 一码游图片压缩工具
108
- // interceptImgPondBeforeAddFile 统一处理拦截ImgPond方法,内部包含heif格式转换
109
- ```
110
-
111
- #### interceptImgPondBeforeAddFile
112
- 如果项目中单独有使用ImgPond组件,需要对内部方法进行拦截,否则上传 heif 格式的图片不能正常显示,以下是示例,使用组合式 Api 语法,选项式 Api 请自行替换
113
-
114
- 1.绑定 ref 对象
115
- ```html
116
- <ImgPond
117
- ref="audioImageImgPondRef"
118
- v-model="uploadAudio.formData.cover"
119
- >
120
- </ImgPond>
121
- ```
122
-
123
- 2.拦截
124
- ```typescript
125
- const uploadImageImgPondRef = ref()
126
- watch(() => uploadImageImgPondRef.value, () => {
127
- if (uploadImageImgPondRef.value) {
128
- let loadingIns: ElLoadingComponent
129
- interceptImgPondBeforeAddFile(uploadImageImgPondRef.value, {
130
- onStart: () => {
131
- loadingIns = Loading.service({text: '加载中...', fullscreen: true, customClass: 'tinymce-loading' })
132
- },
133
- onEnd: () => {
134
- loadingIns?.close()
135
- }
136
- })
137
- }
138
- }, { immediate: true })
139
- ```
140
-
141
-
142
- #### 工具类Api
143
-
144
- ```typescript
145
- export async function oneTravelImageCheck(data: File | Blob, options?: {
146
- imageMaxSize?: number;
147
- imageAllowedType?: string[];
148
- imageAllowedMineType?: string[]
149
- imageMinWidth?: number;
150
- imageMinHeight?: number;
151
- imageMaxWidth?: number;
152
- imageMaxHeight?: number;
153
- }): Promise<{
154
- /** 是否成功 */
155
- success: boolean;
156
- /** 处理完成的文件(有可能不需要处理) */
157
- file?: File | Blob;
158
- /** 失败 */
159
- error?: {
160
- size?: boolean;
161
- format?: boolean;
162
- pixel?: boolean;
163
- message?: string
164
- },
165
- /** 错误消息 */
166
- errorMessage?: string;
167
- }> {}
168
-
169
- export async function oneTravelImageCompressor(data: File | Blob): Promise<{
170
- // 文件
171
- file: File | Blob,
172
- // 是否经过处理(没有处理的话,会返回原 file 对象)
173
- hasConversion: boolean;
174
- success: boolean;
175
- errorMessage?: string
176
- }>{}
177
-
178
- export async function interceptImgPondBeforeAddFile(imgPondIns: any, options?: {
179
- onStart?: () => void,
180
- onEnd?: () => void,
181
- }) {}
182
- ```
183
-
184
102
  ## 三、Api
185
103
  ### 1.全局属性
186
104
  ```typescript
package/es/editor.vue2.js CHANGED
@@ -1,9 +1,10 @@
1
- import { defineComponent as he, ref as d, watch as k, computed as M, onMounted as Me, onUnmounted as xe } from "vue";
2
- import { interceptImgPondBeforeAddFile as G, oneTravelImageCheck as L, oneTravelImageCompressor as J, getImagePixel as ye } from "./util.js";
3
- import be from "imgpond";
1
+ import { defineComponent as me, ref as d, watch as D, computed as h, onMounted as ce, onUnmounted as pe } from "vue";
2
+ import { oneTravelImgPondBeforeAddFile as $, oneTravelImageCheckAndTransform as fe, oneTravelImageCompressor as F } from "@keyblade/one-travel";
3
+ import { getImagePixel as ge } from "./util.js";
4
+ import ve from "imgpond";
4
5
  import { conclude as x } from "vue-global-config";
5
- import K from "tinymce";
6
- import _e from "./langs/zh_CN.js";
6
+ import j from "tinymce";
7
+ import he from "./langs/zh_CN.js";
7
8
  import "tinymce/skins/ui/oxide/skin";
8
9
  import "tinymce/models/dom";
9
10
  import "tinymce/themes/silver";
@@ -32,9 +33,9 @@ import "tinymce/plugins/table";
32
33
  import "tinymce/plugins/visualblocks";
33
34
  import "tinymce/plugins/visualchars";
34
35
  import "tinymce/plugins/wordcount";
35
- import { globalProps as y } from "./index.js";
36
- import { Loading as W, Message as h } from "element-ui";
37
- const la = /* @__PURE__ */ he({
36
+ import { globalProps as b } from "./index.js";
37
+ import { Loading as z, Message as c } from "element-ui";
38
+ const oa = /* @__PURE__ */ me({
38
39
  __name: "editor",
39
40
  props: {
40
41
  value: { default: "" },
@@ -66,55 +67,61 @@ const la = /* @__PURE__ */ he({
66
67
  imgPondOptions: null
67
68
  },
68
69
  emits: ["input", "update:modelValue"],
69
- setup(Q, { emit: z }) {
70
- const o = Q;
71
- K.addI18n("zh_CN", _e);
72
- const R = d(), u = d(), U = d(!1), C = d(!1), V = d();
73
- k(() => V.value, () => {
74
- if (V.value) {
70
+ setup(q, { emit: C }) {
71
+ const i = q;
72
+ j.addI18n("zh_CN", he);
73
+ const B = d(), u = d(), A = d(!1), w = d(!1), T = d();
74
+ D(() => T.value, () => {
75
+ if (T.value) {
75
76
  let a;
76
- G(V.value, {
77
+ $(T.value, {
77
78
  onStart: () => {
78
- a = W.service({ text: "加载中...", fullscreen: !0, customClass: "tinymce-loading" });
79
+ a = z.service({ text: "加载中...", fullscreen: !0, customClass: "tinymce-loading" });
79
80
  },
80
- onEnd: () => {
81
+ onSuccess: () => {
81
82
  a == null || a.close();
83
+ },
84
+ onError: (l) => {
85
+ a == null || a.close(), c.error(l);
82
86
  }
83
87
  });
84
88
  }
85
89
  }, { immediate: !0 });
86
- const P = d();
87
- k(() => P.value, () => {
88
- if (P.value) {
90
+ const U = d();
91
+ D(() => U.value, () => {
92
+ if (U.value) {
89
93
  let a;
90
- G(P.value, {
94
+ $(U.value, {
91
95
  onStart: () => {
92
- a = W.service({ text: "加载中", fullscreen: !0, customClass: "tinymce-loading" });
96
+ a = z.service({ text: "加载中", fullscreen: !0, customClass: "tinymce-loading" });
93
97
  },
94
- onEnd: () => {
98
+ onSuccess: () => {
95
99
  a == null || a.close();
100
+ },
101
+ onError: (l) => {
102
+ a == null || a.close(), c.error(l);
96
103
  }
97
104
  });
98
105
  }
99
106
  }, { immediate: !0 });
100
- const g = d({
107
+ const p = d({
101
108
  dialogVisible: !1,
102
109
  formData: {
103
110
  images: []
104
111
  }
105
- }), B = d(), X = () => {
106
- g.value.dialogVisible = !1, g.value.formData = {
112
+ }), H = d(), N = () => {
113
+ p.value.dialogVisible = !1, p.value.formData = {
107
114
  images: []
108
115
  };
109
- }, Y = () => {
116
+ }, G = () => {
110
117
  var a;
111
- (a = B.value) == null || a.validate((l) => {
112
- l && (g.value.formData.images.forEach((i) => {
118
+ (a = H.value) == null || a.validate((l) => {
119
+ l && (p.value.formData.images.forEach((o) => {
113
120
  var e, t;
114
- if (H.value.srcAt)
115
- return (e = u.value) == null ? void 0 : e.insertContent(`<img src=${i == null ? void 0 : i[H.value.srcAt]} alt="" />`);
116
- (t = u.value) == null || t.insertContent(`<img src=${i} alt="" />`);
117
- }), g.value.dialogVisible = !1, g.value.formData.images = []);
121
+ if (S.value.srcAt)
122
+ return (e = u.value) == null ? void 0 : e.insertContent(`<img src=${o == null ? void 0 : o[S.value.srcAt]} alt="" />`);
123
+ (t = u.value) == null || t.insertContent(`<img src=${o} alt="" />`);
124
+ }), p.value.dialogVisible = !1, p.value.formData.images = []);
118
125
  });
119
126
  }, r = d({
120
127
  dialogVisible: !1,
@@ -128,17 +135,17 @@ const la = /* @__PURE__ */ he({
128
135
  },
129
136
  // 用于临时保存上传前的参数 { file: File }
130
137
  additionalData: {}
131
- }), E = d(), Z = () => {
138
+ }), R = d(), L = () => {
132
139
  var a;
133
- (a = E.value) == null || a.validate((l) => {
134
- var i, e;
135
- l && ((e = u.value) == null || e.insertContent(`<audio controls data-name="${r.value.formData.name}" data-poster="${r.value.formData.cover[0]}" src="${(i = r.value.formData.file[0]) == null ? void 0 : i.url}"></audio>`), r.value.dialogVisible = !1, r.value.formData = {
140
+ (a = R.value) == null || a.validate((l) => {
141
+ var o, e;
142
+ l && ((e = u.value) == null || e.insertContent(`<audio controls data-name="${r.value.formData.name}" data-poster="${r.value.formData.cover[0]}" src="${(o = r.value.formData.file[0]) == null ? void 0 : o.url}"></audio>`), r.value.dialogVisible = !1, r.value.formData = {
136
143
  name: "",
137
144
  cover: [],
138
145
  file: []
139
146
  }, r.value.additionalData = {});
140
147
  });
141
- }, ee = () => {
148
+ }, J = () => {
142
149
  r.value.dialogVisible = !1, r.value.formData = {
143
150
  name: "",
144
151
  cover: [],
@@ -152,92 +159,74 @@ const la = /* @__PURE__ */ he({
152
159
  },
153
160
  // 用于临时保存上传前的参数 { file: File }
154
161
  additionalData: {}
155
- }), I = d(), ae = () => {
162
+ }), W = d(), K = () => {
156
163
  var a;
157
- (a = I.value) == null || a.validate((l) => {
158
- var i, e;
159
- l && ((e = u.value) == null || e.insertContent(`<video controls controlslist="nodownload" src="${(i = s.value.formData.file[0]) == null ? void 0 : i.url}"></video>`), s.value.dialogVisible = !1, s.value.formData = {
164
+ (a = W.value) == null || a.validate((l) => {
165
+ var o, e;
166
+ l && ((e = u.value) == null || e.insertContent(`<video controls controlslist="nodownload" src="${(o = s.value.formData.file[0]) == null ? void 0 : o.url}"></video>`), s.value.dialogVisible = !1, s.value.formData = {
160
167
  file: []
161
168
  }, s.value.additionalData = {});
162
169
  });
163
- }, oe = () => {
170
+ }, Q = () => {
164
171
  s.value.dialogVisible = !1, s.value.formData = {
165
172
  file: []
166
173
  }, s.value.additionalData = {};
167
- }, ie = (a, l) => new Promise(async (i, e) => {
168
- var p, c;
169
- const t = await L(a, {
170
- imageMaxSize: o.imageMaxSize,
171
- imageAllowedType: o.imageAllowedType,
172
- imageAllowedMineType: o.imageAllowedMineType,
173
- imageMinWidth: o.imageMinWidth,
174
- imageMinHeight: o.imageMinHeight,
175
- imageMaxWidth: o.imageMaxWidth,
176
- imageMaxHeight: o.imageMaxHeight
177
- });
174
+ }, X = (a, l) => new Promise(async (o, e) => {
175
+ var m;
176
+ const t = await F(a);
178
177
  if (!t.success) {
179
178
  e(), setTimeout(() => {
180
- var A, w, T;
181
- (A = t.error) != null && A.size ? l.onError(`请上传大小不超过${o.imageMaxSize}M的图片`) : (w = t.error) != null && w.format ? l.onError(`请上传格式为${o.imageAllowedType.map(($) => $.toUpperCase()).join("、")}的图片`) : (T = t.error) != null && T.pixel && l.onError(`请上传像素不低于${o.imageMinWidth}*${o.imageMinHeight}且像素不高于${o.imageMaxWidth}*${o.imageMaxHeight}的图片`);
179
+ l.onError(t.errorMessage);
182
180
  });
183
181
  return;
184
182
  }
185
- const n = await J(a);
183
+ const n = await ((m = f.value) == null ? void 0 : m.call(f, t.file, a.name, { extParameters: i.extParameters }));
186
184
  if (!n.success) {
187
185
  e(), setTimeout(() => {
188
186
  l.onError(n.errorMessage);
189
187
  });
190
188
  return;
191
189
  }
192
- let m = a.name;
193
- n.hasConversion && (m = `${(p = m.split(".")) == null ? void 0 : p[0]}.jpeg`);
194
- const v = await ((c = f.value) == null ? void 0 : c.call(f, n.file, m, { extParameters: o.extParameters }));
195
- if (!v.success) {
196
- e(), setTimeout(() => {
197
- l.onError(v.errorMessage);
198
- });
199
- return;
200
- }
201
- i(v.url);
202
- }), te = M(() => o.imageAllowedMineType.map((a) => `.${a.split("/")[1]}`).join(",") || "");
203
- async function O(a) {
204
- var i, e;
190
+ o(n.url);
191
+ }), Y = h(() => i.imageAllowedMineType.map((a) => `.${a.split("/")[1]}`).join(",") || "");
192
+ async function E(a) {
193
+ var o, e;
205
194
  const l = a.getElementsByTagName("img");
206
195
  for (let t of l) {
207
196
  const n = t.src;
208
197
  if (n.startsWith("http://") || n.startsWith("https://")) {
209
- const m = await ye(n);
210
- if (m.width < o.imageMinWidth && m.height < o.imageMinHeight || m.width > o.imageMaxWidth && m.height > o.imageMaxHeight) {
211
- (i = t == null ? void 0 : t.remove) == null || i.call(t);
198
+ const m = await ge(n);
199
+ if (m.width < i.imageMinWidth && m.height < i.imageMinHeight || m.width > i.imageMaxWidth && m.height > i.imageMaxHeight) {
200
+ (o = t == null ? void 0 : t.remove) == null || o.call(t);
212
201
  return;
213
202
  }
214
- const v = n.split("."), p = v[v.length - 1].toLowerCase();
215
- if (!o.imageAllowedType.includes(p)) {
203
+ const g = n.split("."), v = g[g.length - 1].toLowerCase();
204
+ if (!i.imageAllowedType.includes(v)) {
216
205
  (e = t == null ? void 0 : t.remove) == null || e.call(t);
217
206
  return;
218
207
  }
219
208
  }
220
209
  }
221
210
  }
222
- const b = M(() => x([o.videoUploadOptions, y.videoUploadOptions]) || {}), _ = M(() => x([o.audioUploadOptions, y.audioUploadOptions]) || {}), H = M(() => x([o.imgPondOptions, y.imgPondOptions]) || {}), D = M(
223
- () => x([o.paste_preprocess, y.paste_preprocess], {
211
+ const y = h(() => x([i.videoUploadOptions, b.videoUploadOptions]) || {}), M = h(() => x([i.audioUploadOptions, b.audioUploadOptions]) || {}), S = h(() => x([i.imgPondOptions, b.imgPondOptions]) || {}), V = h(
212
+ () => x([i.paste_preprocess, b.paste_preprocess], {
224
213
  type: Function
225
214
  })
226
- ), S = M(
227
- () => x([o.paste_postprocess, y.paste_postprocess], {
215
+ ), P = h(
216
+ () => x([i.paste_postprocess, b.paste_postprocess], {
228
217
  type: Function
229
218
  })
230
- ), f = M(
231
- () => x([o.imageUploadHandle, y.imageUploadHandle], {
219
+ ), f = h(
220
+ () => x([i.imageUploadHandle, b.imageUploadHandle], {
232
221
  type: Function
233
222
  })
234
223
  );
235
- Me(() => {
224
+ ce(() => {
236
225
  const a = {
237
226
  // 设置语言
238
227
  language: "zh_CN",
239
228
  // 实例
240
- target: R.value,
229
+ target: B.value,
241
230
  // 隐藏品牌
242
231
  branding: !1,
243
232
  // 隐藏右上角升级按钮
@@ -313,99 +302,93 @@ const la = /* @__PURE__ */ he({
313
302
  paste_webkit_styles: "all",
314
303
  paste_data_images: !0,
315
304
  // 粘贴前处理
316
- paste_preprocess(i, e) {
305
+ paste_preprocess(o, e) {
317
306
  var t;
318
- 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>"), (t = D.value) == null || t.call(D, i, e);
307
+ 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>"), (t = V.value) == null || t.call(V, o, e);
319
308
  },
320
309
  // 粘贴后处理(处理异步操作)
321
- paste_postprocess(i, e) {
310
+ paste_postprocess(o, e) {
322
311
  var n;
323
312
  const t = e.node;
324
- O(t), (n = S.value) == null || n.call(S, i, e);
313
+ E(t), (n = P.value) == null || n.call(P, o, e);
325
314
  },
326
- images_upload_handler(i) {
315
+ images_upload_handler(o) {
327
316
  return new Promise(async (e, t) => {
328
- var T, $, F, N, q;
329
- const n = W.service({ text: "上传中" });
330
- let m = i.blob();
331
- const v = i.filename(), p = await L(m, {
332
- imageMaxSize: o.imageMaxSize,
333
- imageAllowedType: o.imageAllowedType,
334
- imageAllowedMineType: o.imageAllowedMineType,
335
- imageMinWidth: o.imageMinWidth,
336
- imageMinHeight: o.imageMinHeight,
337
- imageMaxWidth: o.imageMaxWidth,
338
- imageMaxHeight: o.imageMaxHeight
317
+ var I;
318
+ if (!f.value)
319
+ return t({ message: "缺少图片上传配置", remove: !0 });
320
+ const n = z.service({ text: "上传中" });
321
+ let m = o.blob(), g = o.filename();
322
+ const v = await fe(m, {
323
+ imageMaxSize: i.imageMaxSize,
324
+ imageAllowedType: i.imageAllowedType,
325
+ imageAllowedMineType: i.imageAllowedMineType,
326
+ imageMinWidth: i.imageMinWidth,
327
+ imageMinHeight: i.imageMinHeight,
328
+ imageMaxWidth: i.imageMaxWidth,
329
+ imageMaxHeight: i.imageMaxHeight
339
330
  });
340
- if (!p.success) {
341
- if (n == null || n.close(), (T = p.error) != null && T.size)
342
- return t({ message: `请上传大小不超过${o.imageMaxSize}M的图片`, remove: !0 });
343
- if (($ = p.error) != null && $.format)
344
- return t({ message: `请上传格式为${o.imageAllowedType.map((j) => j.toUpperCase()).join("、")}的图片`, remove: !0 });
345
- if ((F = p.error) != null && F.pixel)
346
- return t({ message: `请上传像素不低于${o.imageMinWidth}*${o.imageMinHeight}且像素不高于${o.imageMaxWidth}*${o.imageMaxHeight}的图片`, remove: !0 });
331
+ if (v.success || (n == null || n.close(), t({ message: (v == null ? void 0 : v.errorMessage) || "", remove: !0 })), v.hasTransform) {
332
+ const O = g == null ? void 0 : g.split(".");
333
+ O.pop(), g = `${O.join(",")}.jpeg`;
347
334
  }
348
- const c = await J(m);
349
- if (!c.success)
350
- return n == null || n.close(), t({ message: c == null ? void 0 : c.errorMessage, remove: !0 });
351
- if (!f.value)
352
- return n == null || n.close(), t({ message: "缺少图片上传配置", remove: !0 });
353
- let A = i.filename();
354
- c.hasConversion && (A = `${(N = v.split(".")) == null ? void 0 : N[0]}.jpeg`);
355
- const w = await ((q = f.value) == null ? void 0 : q.call(f, c.file, A, { extParameters: o.extParameters }));
356
- if (!w.success)
357
- return n == null || n.close(), t({ message: w.errorMessage, remove: !0 });
358
- n == null || n.close(), e(w.url);
335
+ const _ = await F(m);
336
+ if (!_.success)
337
+ return n == null || n.close(), t({ message: _ == null ? void 0 : _.errorMessage, remove: !0 });
338
+ const k = await ((I = f.value) == null ? void 0 : I.call(f, _.file, g, { extParameters: i.extParameters }));
339
+ if (!k.success)
340
+ return n == null || n.close(), t({ message: k.errorMessage, remove: !0 });
341
+ n == null || n.close(), e(k.url);
359
342
  });
360
343
  },
361
- setup(i) {
362
- i.ui.registry.addMenuItem("localImage", {
344
+ setup(o) {
345
+ o.ui.registry.addMenuItem("localImage", {
363
346
  text: "图片",
364
347
  icon: "image",
365
348
  onAction: () => {
366
- g.value.dialogVisible = !0, setTimeout(() => {
349
+ p.value.dialogVisible = !0, setTimeout(() => {
367
350
  var t;
368
351
  const e = (t = document == null ? void 0 : document.querySelector) == null ? void 0 : t.call(document, ".tinymce-editor-upload-image-dialog .el-upload__text > div");
369
- e && (e.innerHTML = o.imageUploadTip || "上传");
352
+ e && (e.innerHTML = i.imageUploadTip || "上传");
370
353
  });
371
354
  }
372
- }), i.ui.registry.addButton("localImage", {
355
+ }), o.ui.registry.addButton("localImage", {
373
356
  icon: "image",
374
357
  tooltip: "图片",
375
358
  onAction: () => {
376
- g.value.dialogVisible = !0, setTimeout(() => {
359
+ p.value.dialogVisible = !0, setTimeout(() => {
377
360
  var t;
378
361
  const e = (t = document == null ? void 0 : document.querySelector) == null ? void 0 : t.call(document, ".tinymce-editor-upload-image-dialog .el-upload__text > div");
379
- e && (e.innerHTML = o.imageUploadTip || "上传");
362
+ e && (e.innerHTML = i.imageUploadTip || "上传");
380
363
  });
381
364
  }
382
- }), o.audioEnable && (i.ui.registry.addMenuItem("localAudio", {
365
+ }), i.audioEnable && (o.ui.registry.addMenuItem("localAudio", {
383
366
  text: "音频",
384
367
  icon: "arrow-right",
385
368
  onAction: () => {
386
369
  r.value.dialogVisible = !0, setTimeout(() => {
387
370
  var t;
388
371
  const e = (t = document == null ? void 0 : document.querySelector) == null ? void 0 : t.call(document, ".tinymce-editor-upload-audio-dialog .el-upload__text > div");
389
- e && (e.innerHTML = o.imageUploadTip || "上传");
372
+ e && (e.innerHTML = i.imageUploadTip || "上传");
390
373
  });
391
374
  }
392
- }), i.ui.registry.addButton("localAudio", {
375
+ }), o.ui.registry.addButton("localAudio", {
393
376
  icon: "arrow-right",
394
377
  tooltip: "音频",
395
378
  onAction: () => {
396
379
  r.value.dialogVisible = !0, setTimeout(() => {
397
380
  var t;
398
381
  const e = (t = document == null ? void 0 : document.querySelector) == null ? void 0 : t.call(document, ".tinymce-editor-upload-audio-dialog .el-upload__text > div");
399
- e && (e.innerHTML = o.imageUploadTip || "上传");
382
+ e && (e.innerHTML = i.imageUploadTip || "上传");
400
383
  });
401
384
  }
402
- })), o.videoEnable && (i.ui.registry.addMenuItem("localVideo", {
385
+ })), i.videoEnable && (o.ui.registry.addMenuItem("localVideo", {
403
386
  text: "视频",
404
387
  icon: "embed",
405
388
  onAction: () => {
406
389
  s.value.dialogVisible = !0;
407
390
  }
408
- }), i.ui.registry.addButton("localVideo", {
391
+ }), o.ui.registry.addButton("localVideo", {
409
392
  icon: "embed",
410
393
  tooltip: "视频",
411
394
  onAction: () => {
@@ -415,99 +398,99 @@ const la = /* @__PURE__ */ he({
415
398
  }
416
399
  }, l = x(
417
400
  [
418
- o.options,
419
- y.tinymceOptions,
401
+ i.options,
402
+ b.tinymceOptions,
420
403
  a
421
404
  ],
422
405
  {
423
- mergeFunction: (i, e) => (...t) => {
424
- i(...t), e(...t);
406
+ mergeFunction: (o, e) => (...t) => {
407
+ o(...t), e(...t);
425
408
  },
426
409
  type: Object
427
410
  }
428
411
  );
429
- K.init(l).then(([i]) => {
412
+ j.init(l).then(([o]) => {
430
413
  var e;
431
- i && (i.customProps = { ...o }, i.on("change input Redo Undo SetContent", () => {
432
- if (C.value) {
433
- C.value = !1;
414
+ o && (o.customProps = { ...i }, o.on("change input Redo Undo SetContent", () => {
415
+ if (w.value) {
416
+ w.value = !1;
434
417
  return;
435
418
  }
436
- U.value = !0, z("input", i.getContent()), z("update:modelValue", i.getContent());
437
- }), (e = o.initComplete) == null || e.call(o, { editorIns: i }), u.value = i);
419
+ A.value = !0, C("input", o.getContent()), C("update:modelValue", o.getContent());
420
+ }), (e = i.initComplete) == null || e.call(i, { editorIns: o }), u.value = o);
438
421
  });
439
422
  });
440
- const le = () => {
423
+ const Z = () => {
441
424
  var a, l;
442
- return ((l = (a = _.value) == null ? void 0 : a.data) == null ? void 0 : l.call(a, { ...r.value.additionalData || {}, extParameters: o.extParameters })) || {};
443
- }, ne = () => {
425
+ return ((l = (a = M.value) == null ? void 0 : a.data) == null ? void 0 : l.call(a, { ...r.value.additionalData || {}, extParameters: i.extParameters })) || {};
426
+ }, ee = () => {
444
427
  var a, l;
445
- return ((l = (a = _.value) == null ? void 0 : a.headers) == null ? void 0 : l.call(a, { ...r.value.additionalData || {}, extParameters: o.extParameters })) || {};
446
- }, re = (a, l, i) => {
428
+ return ((l = (a = M.value) == null ? void 0 : a.headers) == null ? void 0 : l.call(a, { ...r.value.additionalData || {}, extParameters: i.extParameters })) || {};
429
+ }, ae = (a, l, o) => {
447
430
  var t, n;
448
- const e = (n = (t = _ == null ? void 0 : _.value) == null ? void 0 : t.handlerResponse) == null ? void 0 : n.call(t, a);
449
- e != null && e.url ? i[i.length - 1].url = e.url : e != null && e.errorMessage && (h.error(e.errorMessage), i.splice(i.length - 1, 1)), r.value.formData.file = i;
450
- }, se = (a, l) => new Promise((i, e) => {
431
+ const e = (n = (t = M == null ? void 0 : M.value) == null ? void 0 : t.handlerResponse) == null ? void 0 : n.call(t, a);
432
+ e != null && e.url ? o[o.length - 1].url = e.url : e != null && e.errorMessage && (c.error(e.errorMessage), o.splice(o.length - 1, 1)), r.value.formData.file = o;
433
+ }, oe = (a, l) => new Promise((o, e) => {
451
434
  const t = a.name.split(".").filter(Boolean).pop() ? a.name.split(".").filter(Boolean).pop() : "";
452
- if (!o.audioAllowedType.includes(t.toUpperCase())) {
453
- h.info(`请上传格式为${o.audioAllowedType.join("、")}的音频`), e();
435
+ if (!i.audioAllowedType.includes(t.toUpperCase())) {
436
+ c.info(`请上传格式为${i.audioAllowedType.join("、")}的音频`), e();
454
437
  return;
455
438
  }
456
- if (a.size > o.audioMaxSize * 1024 * 1024) {
457
- h.info(`请上传${o.audioMaxSize}M内的音频`), e();
439
+ if (a.size > i.audioMaxSize * 1024 * 1024) {
440
+ c.info(`请上传${i.audioMaxSize}M内的音频`), e();
458
441
  return;
459
442
  }
460
- r.value.additionalData = { file: a }, i(!0);
461
- }), de = (a, l) => {
443
+ r.value.additionalData = { file: a }, o(!0);
444
+ }), te = (a, l) => {
462
445
  r.value.formData.file = l;
463
- }, ue = (a, l, i) => {
464
- h.error("上传发生错误,请重试!"), r.value.formData.file = i;
465
- }, me = () => {
446
+ }, ie = (a, l, o) => {
447
+ c.error("上传发生错误,请重试!"), r.value.formData.file = o;
448
+ }, le = () => {
466
449
  var a, l;
467
- return ((l = (a = b.value) == null ? void 0 : a.data) == null ? void 0 : l.call(a, { ...s.value.additionalData || {}, extParameters: o.extParameters })) || {};
468
- }, pe = () => {
450
+ return ((l = (a = y.value) == null ? void 0 : a.data) == null ? void 0 : l.call(a, { ...s.value.additionalData || {}, extParameters: i.extParameters })) || {};
451
+ }, ne = () => {
469
452
  var a, l;
470
- return ((l = (a = b.value) == null ? void 0 : a.headers) == null ? void 0 : l.call(a, { ...s.value.additionalData || {}, extParameters: o.extParameters })) || {};
471
- }, ce = (a, l, i) => {
453
+ return ((l = (a = y.value) == null ? void 0 : a.headers) == null ? void 0 : l.call(a, { ...s.value.additionalData || {}, extParameters: i.extParameters })) || {};
454
+ }, re = (a, l, o) => {
472
455
  var t, n;
473
- const e = (n = (t = b == null ? void 0 : b.value) == null ? void 0 : t.handlerResponse) == null ? void 0 : n.call(t, a);
474
- e != null && e.url ? i[i.length - 1].url = e.url : e != null && e.errorMessage && (h.error(e.errorMessage), i.splice(i.length - 1, 1)), s.value.formData.file = i;
475
- }, ge = (a, l) => new Promise((i, e) => {
456
+ const e = (n = (t = y == null ? void 0 : y.value) == null ? void 0 : t.handlerResponse) == null ? void 0 : n.call(t, a);
457
+ e != null && e.url ? o[o.length - 1].url = e.url : e != null && e.errorMessage && (c.error(e.errorMessage), o.splice(o.length - 1, 1)), s.value.formData.file = o;
458
+ }, se = (a, l) => new Promise((o, e) => {
476
459
  const t = a.name.split(".").filter(Boolean).pop() ? a.name.split(".").filter(Boolean).pop() : "";
477
- if (!o.videoAllowedType.includes(t.toUpperCase())) {
478
- h.info(`请上传格式为${o.videoAllowedType.join("、")}的视频`), e();
460
+ if (!i.videoAllowedType.includes(t.toUpperCase())) {
461
+ c.info(`请上传格式为${i.videoAllowedType.join("、")}的视频`), e();
479
462
  return;
480
463
  }
481
- if (a.size > o.videoMaxSize * 1024 * 1024) {
482
- h.info(`请上传${o.videoMaxSize}M内的视频`), e();
464
+ if (a.size > i.videoMaxSize * 1024 * 1024) {
465
+ c.info(`请上传${i.videoMaxSize}M内的视频`), e();
483
466
  return;
484
467
  }
485
- s.value.additionalData = { file: a }, i(!0);
486
- }), fe = (a, l) => {
468
+ s.value.additionalData = { file: a }, o(!0);
469
+ }), de = (a, l) => {
487
470
  s.value.formData.file = l;
488
- }, ve = (a, l, i) => {
489
- h.error("上传发生错误,请重试!"), s.value.formData.file = i;
471
+ }, ue = (a, l, o) => {
472
+ c.error("上传发生错误,请重试!"), s.value.formData.file = o;
490
473
  };
491
- return xe(() => {
474
+ return pe(() => {
492
475
  var a;
493
476
  (a = u.value) == null || a.destroy();
494
- }), k(() => [o.disabled, u.value], () => {
477
+ }), D(() => [i.disabled, u.value], () => {
495
478
  var a, l;
496
- (l = (a = u.value) == null ? void 0 : a.mode) == null || l.set(o.disabled ? "readonly" : "design");
497
- }, { immediate: !0 }), k(
498
- () => [o.value, o.modelValue, u.value],
479
+ (l = (a = u.value) == null ? void 0 : a.mode) == null || l.set(i.disabled ? "readonly" : "design");
480
+ }, { immediate: !0 }), D(
481
+ () => [i.value, i.modelValue, u.value],
499
482
  () => {
500
483
  var a;
501
- if (U.value) {
502
- U.value = !1;
484
+ if (A.value) {
485
+ A.value = !1;
503
486
  return;
504
487
  }
505
- C.value = !0, (a = u.value) == null || a.setContent(o.value ? o.value : o.modelValue ? o.modelValue : "");
488
+ w.value = !0, (a = u.value) == null || a.setContent(i.value ? i.value : i.modelValue ? i.modelValue : "");
506
489
  },
507
490
  { immediate: !0 }
508
- ), { __sfc: !0, insRef: R, editorRef: u, preventSettingContent: U, preventUpdatingModelValue: C, uploadImageImgPondRef: V, audioImageImgPondRef: P, uploadImage: g, uploadImageFormRef: B, onUploadImageClose: X, onUploadImageConfirm: Y, uploadAudio: r, uploadAudioFormRef: E, onUploadAudioConfirm: Z, onUploadAudioClose: ee, uploadVideo: s, uploadVideoFormRef: I, onUploadVideoConfirm: ae, onUploadVideoClose: oe, onImageUploadUpload: ie, props: o, emits: z, imgPondAccept: te, processPastedImage: O, mergeVideoUploadOptions: b, mergeAudioUploadOptions: _, mergeImgPondOptions: H, paste_preprocess: D, paste_postprocess: S, imageUploadHandle: f, getUploadAudioData: le, getUploadAudioHeaders: ne, onUploadAudioSuccess: re, onUploadAudioBeforeUpload: se, onUploadAudioRemove: de, onUploadAudioError: ue, getUploadVideoData: me, getUploadVideoHeaders: pe, onUploadVideoSuccess: ce, onUploadVideoBeforeUpload: ge, onUploadVideoRemove: fe, onUploadVideoError: ve, ImgPond: be };
491
+ ), { __sfc: !0, insRef: B, editorRef: u, preventSettingContent: A, preventUpdatingModelValue: w, uploadImageImgPondRef: T, audioImageImgPondRef: U, uploadImage: p, uploadImageFormRef: H, onUploadImageClose: N, onUploadImageConfirm: G, uploadAudio: r, uploadAudioFormRef: R, onUploadAudioConfirm: L, onUploadAudioClose: J, uploadVideo: s, uploadVideoFormRef: W, onUploadVideoConfirm: K, onUploadVideoClose: Q, onImageUploadUpload: X, props: i, emits: C, imgPondAccept: Y, processPastedImage: E, mergeVideoUploadOptions: y, mergeAudioUploadOptions: M, mergeImgPondOptions: S, paste_preprocess: V, paste_postprocess: P, imageUploadHandle: f, getUploadAudioData: Z, getUploadAudioHeaders: ee, onUploadAudioSuccess: ae, onUploadAudioBeforeUpload: oe, onUploadAudioRemove: te, onUploadAudioError: ie, getUploadVideoData: le, getUploadVideoHeaders: ne, onUploadVideoSuccess: re, onUploadVideoBeforeUpload: se, onUploadVideoRemove: de, onUploadVideoError: ue, ImgPond: ve };
509
492
  }
510
493
  });
511
494
  export {
512
- la as default
495
+ oa as default
513
496
  };
package/es/index.js CHANGED
@@ -1,18 +1,15 @@
1
1
  import './style.css';
2
2
  import o from "./editor.vue.js";
3
- import { Button as r, Slider as s, Dialog as m, Upload as n, Tag as i, Form as u, FormItem as l, ButtonGroup as g, InputNumber as c, Loading as d } from "element-ui";
4
- import { getImagePixel as y, interceptImgPondBeforeAddFile as B, oneTravelImageCheck as E, oneTravelImageCompressor as F } from "./util.js";
5
- const I = {}, b = Object.assign(o, {
3
+ import { Button as s, Slider as r, Dialog as u, Upload as i, Tag as m, Form as n, FormItem as l, ButtonGroup as c, InputNumber as g, Loading as d } from "element-ui";
4
+ import { getImagePixel as I } from "./util.js";
5
+ const b = {}, x = Object.assign(o, {
6
6
  install: (e, t) => {
7
- Object.assign(I, t || {}), e.use(r), e.use(s), e.use(m), e.use(n), e.use(i), e.use(u), e.use(l), e.use(g), e.use(c), e.use(d), e.component("KbTinymceEditor", o);
7
+ Object.assign(b, t || {}), e.use(s), e.use(r), e.use(u), e.use(i), e.use(m), e.use(n), e.use(l), e.use(c), e.use(g), e.use(d), e.component("KbTinymceEditor", o);
8
8
  }
9
9
  });
10
10
  export {
11
- b as TinymceEditor,
12
- b as default,
13
- y as getImagePixel,
14
- I as globalProps,
15
- B as interceptImgPondBeforeAddFile,
16
- E as oneTravelImageCheck,
17
- F as oneTravelImageCompressor
11
+ x as TinymceEditor,
12
+ x as default,
13
+ I as getImagePixel,
14
+ b as globalProps
18
15
  };
package/es/util.d.ts CHANGED
@@ -1,38 +1,3 @@
1
- /**
2
- * 一码游图片检测
3
- */
4
- export declare function oneTravelImageCheck(data: File | Blob, options?: {
5
- imageMaxSize?: number;
6
- imageAllowedType?: string[];
7
- imageAllowedMineType?: string[];
8
- imageMinWidth?: number;
9
- imageMinHeight?: number;
10
- imageMaxWidth?: number;
11
- imageMaxHeight?: number;
12
- }): Promise<{
13
- /** 是否成功 */
14
- success: boolean;
15
- /** 处理完成的文件(有可能不需要处理) */
16
- file?: File | Blob;
17
- /** 失败 */
18
- error?: {
19
- size?: boolean;
20
- format?: boolean;
21
- pixel?: boolean;
22
- message?: string;
23
- };
24
- /** 错误消息 */
25
- errorMessage?: string;
26
- }>;
27
- /**
28
- * 一码游图片压缩
29
- */
30
- export declare function oneTravelImageCompressor(data: File | Blob): Promise<{
31
- file: File | Blob;
32
- hasConversion: boolean;
33
- success: boolean;
34
- errorMessage?: string;
35
- }>;
36
1
  /**
37
2
  * 获取图片像素
38
3
  * @param src url或 base64
@@ -42,7 +7,3 @@ export declare function getImagePixel(src: string): Promise<{
42
7
  height: number;
43
8
  image: HTMLImageElement;
44
9
  }>;
45
- export declare function interceptImgPondBeforeAddFile(imgPondIns: any, options?: {
46
- onStart?: () => void;
47
- onEnd?: () => void;
48
- }): Promise<void>;
package/es/util.js CHANGED
@@ -1,127 +1,11 @@
1
- import { compressAccurately as b } from "image-conversion";
2
- import x from "compressorjs";
3
- import A from "image-resizor";
4
- async function S(c, e) {
5
- const {
6
- imageMaxSize: i = 30,
7
- imageAllowedType: a = ["jpg", "jpeg", "png", "bmp", "heif", "gif", "webp"],
8
- imageAllowedMineType: r = ["image/jpg", "image/jpeg", "image/png", "image/bmp", "image/heif", "image/heic", "image/gif", "image/webp"],
9
- imageMinWidth: t = 60,
10
- imageMinHeight: g = 60,
11
- imageMaxWidth: s = 6e3,
12
- imageMaxHeight: l = 6e3
13
- } = e || {}, f = c, n = await y(f);
14
- if (f.size > i * 1024 * 1024)
15
- return { success: !1, error: { size: !0 }, errorMessage: `请上传大小不超过${i}M的图片` };
16
- if (!r.includes(f.type))
17
- return { success: !1, error: { format: !0 }, errorMessage: `请上传格式为${a.map((u) => u.toUpperCase()).join("、")}的图片` };
18
- const m = await d(n);
19
- return m.width < t && m.height < g || m.width > s && m.height > l ? { success: !1, error: { pixel: !0 }, errorMessage: `请上传像素不低于${t}*${g}且像素不高于${s}*${l}的图片` } : { success: !0, file: f };
20
- }
21
- async function $(c) {
22
- var l;
23
- let e = c;
24
- const i = await y(e);
25
- let a = !1;
26
- const r = {};
27
- let t = "image-conversion", g = e.type;
28
- ["image/heif", "image/heic", "image/webp"].includes(e.type) && (t = "compressor", r.convertTypes = [e.type], r.convertSize = 0, r.quality = 1, g = "image/jpeg", a = !0);
29
- const s = 5 * 1024 * 1024;
30
- if (e.size > s)
31
- if (a) {
32
- const f = await d(i);
33
- t = "compressor", r.convertTypes = [e.type], r.convertSize = s, r.maxWidth = f.width * (s / e.size), r.quality = 0.92;
34
- } else
35
- t = "image-conversion", r.type = g, r.size = 5 * 1024;
36
- if (Object.keys(r).length > 0) {
37
- const f = await M(j(i), r, t);
38
- if (f.success)
39
- e = f.file;
40
- else
41
- return { file: e, success: !1, hasConversion: a, errorMessage: (l = f.error) == null ? void 0 : l.message };
42
- }
43
- return { file: e, hasConversion: a, success: !0 };
44
- }
45
- function M(c, e = {}, i) {
46
- return new Promise((a) => {
47
- i === "compressor" ? new x(c, {
48
- ...e,
49
- success: async (r) => {
50
- a({ success: !0, file: r });
51
- },
52
- error(r) {
53
- a({ success: !1, error: r });
54
- }
55
- }) : b(c, e).then((r) => {
56
- a({ success: !0, file: r });
57
- }).catch((r) => {
58
- a({ success: !1, error: (r == null ? void 0 : r.message) || "" });
59
- });
60
- });
61
- }
62
- function d(c) {
63
- return new Promise((e) => {
64
- const i = new Image();
65
- i.onload = function() {
66
- e({ width: i.width, height: i.height, image: i });
67
- }, i.src = c;
1
+ function n(i) {
2
+ return new Promise((t) => {
3
+ const e = new Image();
4
+ e.onload = function() {
5
+ t({ width: e.width, height: e.height, image: e });
6
+ }, e.src = i;
68
7
  });
69
8
  }
70
- function j(c) {
71
- const e = c.split(","), i = e[0].match(/:(.*?);/)[1], a = atob(e[1]);
72
- let r = a.length;
73
- const t = new Uint8Array(r);
74
- for (; r--; )
75
- t[r] = a.charCodeAt(r);
76
- return new Blob([t], { type: i });
77
- }
78
- function y(c) {
79
- return new Promise((e, i) => {
80
- const a = new FileReader();
81
- a.onloadend = () => {
82
- const r = a.result;
83
- e(r);
84
- }, a.onerror = i, a.readAsDataURL(c);
85
- });
86
- }
87
- async function C(c, e) {
88
- const i = c == null ? void 0 : c.beforeAddFile;
89
- c.beforeAddFile = (a) => {
90
- var r;
91
- return e != null && e.onStart && ((r = e == null ? void 0 : e.onStart) == null || r.call(e)), new Promise(async (t) => {
92
- var g;
93
- if (a.file.type === "image/heic" || a.file.type === "image/heif") {
94
- const s = a.file.name, l = s == null ? void 0 : s.split(".");
95
- l.pop();
96
- const f = l.join(",");
97
- new A(a.file, {
98
- outputType: "image/jpeg",
99
- quality: 0.9,
100
- maxWidth: 1 / 0,
101
- maxHeight: 1 / 0
102
- }).init().then(async (n) => {
103
- var h;
104
- const m = await n.toBlob();
105
- if (!m)
106
- return t(!1);
107
- const u = new File([m], `${f}.jpeg`, { type: m == null ? void 0 : m.type });
108
- a.file = u, a.fileList[a.fileList.length - 1].raw = u;
109
- const w = await i(a);
110
- t(w), e != null && e.onEnd && ((h = e == null ? void 0 : e.onEnd) == null || h.call(e));
111
- }).catch(() => {
112
- var n;
113
- t(!1), e != null && e.onEnd && ((n = e == null ? void 0 : e.onEnd) == null || n.call(e));
114
- });
115
- } else {
116
- const s = await i(a);
117
- t(s), e != null && e.onEnd && ((g = e == null ? void 0 : e.onEnd) == null || g.call(e));
118
- }
119
- });
120
- };
121
- }
122
9
  export {
123
- d as getImagePixel,
124
- C as interceptImgPondBeforeAddFile,
125
- S as oneTravelImageCheck,
126
- $ as oneTravelImageCompressor
10
+ n as getImagePixel
127
11
  };
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.16",
5
+ "version": "0.0.12-alpha.18",
6
6
  "private": false,
7
7
  "type": "module",
8
8
  "main": "es/index.js",
@@ -20,12 +20,10 @@
20
20
  "*.css"
21
21
  ],
22
22
  "dependencies": {
23
- "image-resizor": "^1.1.3",
24
- "compressorjs": "^1.2.1",
25
- "image-conversion": "^2.1.1",
26
23
  "vue-global-config": "^0.2.6",
27
24
  "tinymce": "^7.1.0",
28
- "element-ui": "^2.15.14"
25
+ "element-ui": "^2.15.14",
26
+ "@keyblade/one-travel": "^2.0.0"
29
27
  },
30
28
  "peerDependencies": {
31
29
  "vue": "^2.7.0",