@keyblade/tinymce-editor-vue2 0.0.2 → 0.0.4

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
@@ -104,6 +104,8 @@ interface ComponentProps {
104
104
  imageMaxSize?: number;
105
105
  /** 图片允许的类型 */
106
106
  imageAllowedType?: string[];
107
+ /** 图片允许的类型 */
108
+ imageAllowedMineType?: string[];
107
109
  /** 图片最小宽度 */
108
110
  imageMinWidth?: number;
109
111
  /** 图片最小高度 */
@@ -1,6 +1,6 @@
1
1
  import { Editor, RawEditorOptions } from 'tinymce';
2
2
 
3
- declare const _default: import('vue-demi').DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
3
+ declare const _default: import('vue').DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
4
4
  /** vue2 v-model */
5
5
  value?: string | undefined;
6
6
  /** vue3 v-model */
@@ -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,18 +44,19 @@ 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;
48
51
  imageMaxHeight: number;
49
52
  options: () => {};
50
53
  }>, {
51
- insRef: import('vue-demi').Ref<HTMLElement | undefined>;
52
- editorRef: import('vue-demi').Ref<Editor | undefined>;
54
+ insRef: import('vue').Ref<HTMLElement | undefined>;
55
+ editorRef: import('vue').Ref<Editor | undefined>;
53
56
  }, {}, {}, {}, import('vue/types/v3-component-options').ComponentOptionsMixin, import('vue/types/v3-component-options').ComponentOptionsMixin, {
54
57
  input: (value: string) => void;
55
58
  "update:modelValue": (value: string) => void;
56
- }, string, Readonly<import('vue-demi').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
59
+ }, string, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
57
60
  /** vue2 v-model */
58
61
  value?: string | undefined;
59
62
  /** vue3 v-model */
@@ -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,8 @@
1
- import { defineComponent as O } from "vue";
2
- import { ref as w, computed as S, onMounted as N, onUnmounted as L, watch as q } from "vue-demi";
3
- import E from "compressorjs";
4
- import { conclude as x } from "vue-global-config";
5
- import G from "tinymce";
6
- import { addI18n as j } from "./langs/zh_CN.js";
1
+ import { defineComponent as F, ref as y, computed as W, onMounted as N, onUnmounted as j, watch as L } from "vue";
2
+ import q from "compressorjs";
3
+ import { conclude as _ } from "vue-global-config";
4
+ import E from "tinymce";
5
+ import { addI18n as G } from "./langs/zh_CN.js";
7
6
  import "tinymce/skins/ui/oxide/skin";
8
7
  import "tinymce/models/dom";
9
8
  import "tinymce/themes/silver";
@@ -32,14 +31,15 @@ import "tinymce/plugins/table";
32
31
  import "tinymce/plugins/visualblocks";
33
32
  import "tinymce/plugins/visualchars";
34
33
  import "tinymce/plugins/wordcount";
35
- import { globalProps as m } from "./index.js";
36
- const He = /* @__PURE__ */ O({
34
+ import { globalProps as d } from "./index.js";
35
+ const ke = /* @__PURE__ */ F({
37
36
  __name: "editor",
38
37
  props: {
39
38
  value: { default: "" },
40
39
  modelValue: { default: "" },
41
40
  imageMaxSize: { default: 30 },
42
41
  imageAllowedType: { default: () => ["jpg", "jpeg", "png", "bmp", "heif", "gif", "webp"] },
42
+ imageAllowedMineType: { default: () => ["image/jpg", "image/jpeg", "image/png", "image/bmp", "image/heif", "image/heic", "image/gif", "image/webp"] },
43
43
  imageMinWidth: { default: 60 },
44
44
  imageMinHeight: { default: 60 },
45
45
  imageMaxWidth: { default: 6e3 },
@@ -51,50 +51,50 @@ const He = /* @__PURE__ */ O({
51
51
  options: { default: () => ({}) }
52
52
  },
53
53
  emits: ["input", "update:modelValue"],
54
- setup(V, { expose: B, emit: _ }) {
55
- const a = V;
56
- j();
57
- const y = w(), l = w(), p = w(!1), u = w(!1);
58
- async function H(n) {
54
+ setup(O, { expose: R, emit: b }) {
55
+ const a = O;
56
+ G();
57
+ const M = y(), m = y(), g = y(!1), f = y(!1);
58
+ async function A(n) {
59
59
  var o, e;
60
- const r = n.getElementsByTagName("img");
61
- for (let i of r) {
60
+ const s = n.getElementsByTagName("img");
61
+ for (let i of s) {
62
62
  const t = i.src;
63
63
  if (t.startsWith("http://") || t.startsWith("https://")) {
64
- const s = await b(t);
65
- if (s.width < a.imageMinWidth && s.height < a.imageMinHeight || s.width > a.imageMaxWidth && s.height > a.imageMaxHeight) {
64
+ const r = await C(t);
65
+ if (r.width < a.imageMinWidth && r.height < a.imageMinHeight || r.width > a.imageMaxWidth && r.height > a.imageMaxHeight) {
66
66
  (o = i == null ? void 0 : i.remove) == null || o.call(i);
67
67
  return;
68
68
  }
69
- const f = t.split("."), M = f[f.length - 1].toLowerCase();
70
- if (!a.imageAllowedType.includes(M)) {
69
+ const w = t.split("."), S = w[w.length - 1].toLowerCase();
70
+ if (!a.imageAllowedType.includes(S)) {
71
71
  (e = i == null ? void 0 : i.remove) == null || e.call(i);
72
72
  return;
73
73
  }
74
74
  }
75
75
  }
76
76
  }
77
- const W = (n) => {
78
- const r = n.split(","), o = r[0].match(/:(.*?);/)[1], e = atob(r[1]);
77
+ const H = (n) => {
78
+ const s = n.split(","), o = s[0].match(/:(.*?);/)[1], e = atob(s[1]);
79
79
  let i = e.length;
80
80
  const t = new Uint8Array(i);
81
81
  for (; i--; )
82
82
  t[i] = e.charCodeAt(i);
83
83
  return new Blob([t], { type: o });
84
84
  };
85
- function b(n) {
86
- return new Promise((r) => {
85
+ function C(n) {
86
+ return new Promise((s) => {
87
87
  const o = new Image();
88
88
  o.onload = function() {
89
- r({ width: o.width, height: o.height, image: o });
89
+ s({ width: o.width, height: o.height, image: o });
90
90
  }, o.src = n;
91
91
  });
92
92
  }
93
- function A(n, r) {
93
+ function T(n, s) {
94
94
  return new Promise((o) => {
95
- new E(n, {
96
- ...r,
97
- success(e) {
95
+ new q(n, {
96
+ ...s,
97
+ success: async (e) => {
98
98
  o({ success: !0, file: e });
99
99
  },
100
100
  error(e) {
@@ -103,16 +103,16 @@ const He = /* @__PURE__ */ O({
103
103
  });
104
104
  });
105
105
  }
106
- const d = S(
107
- () => x([a.paste_preprocess, m.paste_preprocess], {
106
+ const h = W(
107
+ () => _([a.paste_preprocess, d.paste_preprocess], {
108
108
  type: Function
109
109
  })
110
- ), g = S(
111
- () => x([a.paste_postprocess, m.paste_postprocess], {
110
+ ), v = W(
111
+ () => _([a.paste_postprocess, d.paste_postprocess], {
112
112
  type: Function
113
113
  })
114
- ), c = S(
115
- () => x([a.imageUploadHandle, m.imageUploadHandle], {
114
+ ), c = W(
115
+ () => _([a.imageUploadHandle, d.imageUploadHandle], {
116
116
  type: Function
117
117
  })
118
118
  );
@@ -124,7 +124,7 @@ const He = /* @__PURE__ */ O({
124
124
  language: "zh_CN",
125
125
  /** 需要配置到外部 */
126
126
  // 实例
127
- target: y.value,
127
+ target: M.value,
128
128
  // 隐藏品牌
129
129
  branding: !1,
130
130
  // 隐藏右上角升级按钮
@@ -189,48 +189,49 @@ const He = /* @__PURE__ */ O({
189
189
  // 粘贴前处理
190
190
  paste_preprocess(o, e) {
191
191
  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 = d.value) == null || i.call(d, o, e);
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 = h.value) == null || i.call(h, o, e);
193
193
  },
194
194
  // 粘贴后处理(处理异步操作)
195
195
  paste_postprocess(o, e) {
196
196
  var t;
197
197
  const i = e.node;
198
- H(i), (t = g.value) == null || t.call(g, o, e);
198
+ A(i), (t = v.value) == null || t.call(v, o, e);
199
199
  },
200
200
  images_upload_handler(o) {
201
201
  return new Promise(async (e, i) => {
202
- var v, P, U;
203
- const t = (P = (v = m.message) == null ? void 0 : v.loading) == null ? void 0 : P.call(v);
204
- let s = o.blob();
205
- const f = o.base64(), M = o.filename(), z = s.name.split("."), R = z[z.length - 1].toLowerCase();
206
- if (s.size > a.imageMaxSize * 1024 * 1024)
202
+ var x, V, B;
203
+ const t = (V = (x = d.message) == null ? void 0 : x.loading) == null ? void 0 : V.call(x);
204
+ let r = o.blob();
205
+ const w = o.base64(), S = o.filename(), P = r.name.split("."), $ = P[P.length - 1].toLowerCase();
206
+ if (r.size > a.imageMaxSize * 1024 * 1024)
207
207
  return t == null || t.close(), i({ message: `请上传大小不超过${a.imageMaxSize}M的图片`, remove: !0 });
208
- if (!a.imageAllowedType.includes(R))
209
- return t == null || t.close(), i({ message: `请上传格式为${a.imageAllowedType.map((F) => F.toUpperCase()).join("、")}的图片`, remove: !0 });
210
- const T = "data:" + s.type + ";base64," + f, h = await b(T);
211
- if (h.width < a.imageMinWidth && h.height < a.imageMinHeight || h.width > a.imageMaxWidth && h.height > a.imageMaxHeight)
208
+ if (!a.imageAllowedMineType.includes(r.type))
209
+ return t == null || t.close(), i({ message: `请上传格式为${a.imageAllowedType.map((u) => u.toUpperCase()).join("、")}的图片`, remove: !0 });
210
+ const U = "data:" + r.type + ";base64," + w, p = await C(U);
211
+ if (p.width < a.imageMinWidth && p.height < a.imageMinHeight || p.width > a.imageMaxWidth && p.height > a.imageMaxHeight)
212
212
  return t == null || t.close(), i({ message: `请上传像素不低于${a.imageMinWidth}*${a.imageMinHeight}且像素不高于${a.imageMaxWidth}*${a.imageMaxHeight}的图片`, remove: !0 });
213
- const $ = {
214
- // 满足这两种条件会自动转换为JPEG格式
215
- convertTypes: ["image/heif", "image/heic", "image/webp"],
216
- convertSize: 5e6
217
- }, C = await A(W(T), $);
218
- if (C.success)
219
- s = C.file;
220
- else
221
- return t == null || t.close(), i({ message: C.error, remove: !0 });
213
+ const l = {};
214
+ ["image/heif", "image/heic", "image/webp"].includes($) && (l.convertTypes = [r.type], l.convertSize = 0);
215
+ const k = 5 * 1024 * 1024;
216
+ if (r.size > k && (l.convertTypes = [r.type], l.convertSize = k, l.maxWidth = p.width * (k / r.size)), Object.keys(l).length > 0) {
217
+ const u = await T(H(U), l);
218
+ if (u.success)
219
+ r = u.file;
220
+ else
221
+ return t == null || t.close(), i({ message: u.error, remove: !0 });
222
+ }
222
223
  if (!c.value)
223
224
  return t == null || t.close(), i({ message: "缺少图片上传配置", remove: !0 });
224
- const k = await ((U = c.value) == null ? void 0 : U.call(c, s, M));
225
- if (!k.success)
226
- return t == null || t.close(), i({ message: k.errorMessage, remove: !0 });
227
- t == null || t.close(), e(k.url);
225
+ const z = await ((B = c.value) == null ? void 0 : B.call(c, r, S));
226
+ if (!z.success)
227
+ return t == null || t.close(), i({ message: z.errorMessage, remove: !0 });
228
+ t == null || t.close(), e(z.url);
228
229
  });
229
230
  }
230
- }, r = x(
231
+ }, s = _(
231
232
  [
232
233
  a.options,
233
- m.tinymceOptions,
234
+ d.tinymceOptions,
234
235
  n
235
236
  ],
236
237
  {
@@ -240,36 +241,36 @@ const He = /* @__PURE__ */ O({
240
241
  type: Object
241
242
  }
242
243
  );
243
- G.init(r).then(([o]) => {
244
+ E.init(s).then(([o]) => {
244
245
  var e;
245
246
  o.on("change input Redo Undo SetContent", () => {
246
- if (u.value) {
247
- u.value = !1;
247
+ if (f.value) {
248
+ f.value = !1;
248
249
  return;
249
250
  }
250
- p.value = !0, _("input", o.getContent()), _("update:modelValue", o.getContent());
251
- }), l.value = o, (e = a.initComplete) == null || e.call(a);
251
+ g.value = !0, b("input", o.getContent()), b("update:modelValue", o.getContent());
252
+ }), m.value = o, (e = a.initComplete) == null || e.call(a);
252
253
  });
253
- }), L(() => {
254
+ }), j(() => {
254
255
  var n;
255
- (n = l.value) == null || n.destroy();
256
- }), q(
257
- () => [a.value, a.modelValue, l.value],
256
+ (n = m.value) == null || n.destroy();
257
+ }), L(
258
+ () => [a.value, a.modelValue, m.value],
258
259
  () => {
259
260
  var n;
260
- if (p.value) {
261
- p.value = !1;
261
+ if (g.value) {
262
+ g.value = !1;
262
263
  return;
263
264
  }
264
- u.value = !0, (n = l.value) == null || n.setContent(a.value ?? a.modelValue ?? "");
265
+ f.value = !0, (n = m.value) == null || n.setContent(a.value ?? a.modelValue ?? "");
265
266
  },
266
267
  { immediate: !0 }
267
- ), B({
268
- insRef: y,
269
- editorRef: l
270
- }), { __sfc: !0, insRef: y, editorRef: l, preventSettingContent: p, preventUpdatingModelValue: u, props: a, emits: _, processPastedImage: H, dataURLtoBlob: W, getImagePixel: b, compressorImage: A, paste_preprocess: d, paste_postprocess: g, imageUploadHandle: c };
268
+ ), R({
269
+ insRef: M,
270
+ editorRef: m
271
+ }), { __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
272
  }
272
273
  });
273
274
  export {
274
- He as default
275
+ ke as default
275
276
  };
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
@@ -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.2",
5
+ "version": "0.0.4",
6
6
  "private": false,
7
7
  "type": "module",
8
8
  "main": "es/index.js",
@@ -22,18 +22,11 @@
22
22
  "dependencies": {
23
23
  "compressorjs": "^1.2.1",
24
24
  "vue-global-config": "^0.6.1",
25
- "tinymce": "^7.1.0",
26
- "vue-demi": "^0.14.7"
25
+ "tinymce": "^7.1.0"
27
26
  },
28
27
  "devDependencies": {},
29
28
  "peerDependencies": {
30
- "@vue/composition-api": "^1.7.2",
31
- "vue": "^2.0.0 || >=3.3.4"
32
- },
33
- "peerDependenciesMeta": {
34
- "@vue/composition-api": {
35
- "optional": true
36
- }
29
+ "vue": "^2.7.0"
37
30
  },
38
31
  "scripts": {
39
32
  "build": "vite build",