@keyblade/tinymce-editor-vue2 0.0.10 → 0.0.12-alpha.10
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 +129 -38
- package/es/editor.vue.d.ts +127 -3
- package/es/editor.vue.js +18 -11
- package/es/editor.vue2.js +332 -126
- package/es/index.d.ts +543 -86
- package/es/index.js +11 -6
- package/es/style.css +1 -1
- package/es/util.d.ts +41 -0
- package/es/util.js +77 -0
- package/package.json +6 -3
- package/src/index.ts +35 -12
package/es/index.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import './style.css';
|
|
2
2
|
import o from "./editor.vue.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { Button as t, Slider as r, Dialog as m, Upload as i, Tag as n, Form as u, FormItem as l, ButtonGroup as g, Loading as c } from "element-ui";
|
|
4
|
+
import { getImagePixel as x, oneTravelImageCheck as y, oneTravelImageCompressor as E } from "./util.js";
|
|
5
|
+
const d = {}, b = Object.assign(o, {
|
|
6
|
+
install: (e, s) => {
|
|
7
|
+
Object.assign(d, s || {}), e.use(t), e.use(r), e.use(m), e.use(i), e.use(n), e.use(u), e.use(l), e.use(g), e.use(c), e.component("KbTinymceEditor", o);
|
|
6
8
|
}
|
|
7
9
|
});
|
|
8
10
|
export {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
b as TinymceEditor,
|
|
12
|
+
b as default,
|
|
13
|
+
x as getImagePixel,
|
|
14
|
+
d as globalProps,
|
|
15
|
+
y as oneTravelImageCheck,
|
|
16
|
+
E as oneTravelImageCompressor
|
|
12
17
|
};
|
package/es/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.tox-tinymce-aux{z-index:10000!important}.tox-statusbar__branding{display:none!important}
|
|
1
|
+
.tox-tinymce-aux{z-index:10000!important}.tox-statusbar__branding{display:none!important}.tinymce-editor-dialog .el-dialog{min-width:600px}.tinymce-editor-upload-image-dialog .uploadImageForm{display:flex;align-content:center}.tinymce-editor-upload-image-dialog .uploadImageForm .tips{margin-left:20px;display:flex;flex-direction:column}.tinymce-editor-upload-image-dialog .uploadImageForm .tips>span{margin-bottom:16px}.tinymce-editor-dialog .upload-hide .el-upload,.tinymce-editor-dialog .upload-hide .el-upload__tip{display:none}
|
package/es/util.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 一码游图片检测
|
|
3
|
+
*/
|
|
4
|
+
export declare function oneTravelImageCheck(data: File | Blob, options?: {
|
|
5
|
+
imageMaxSize?: number;
|
|
6
|
+
imageAllowedMineType?: string[];
|
|
7
|
+
imageMinWidth?: number;
|
|
8
|
+
imageMinHeight?: number;
|
|
9
|
+
imageMaxWidth?: number;
|
|
10
|
+
imageMaxHeight?: number;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
/** 是否成功 */
|
|
13
|
+
success: boolean;
|
|
14
|
+
/** 处理完成的文件(有可能不需要处理) */
|
|
15
|
+
file?: File | Blob;
|
|
16
|
+
/** 失败 */
|
|
17
|
+
error?: {
|
|
18
|
+
size?: boolean;
|
|
19
|
+
format?: boolean;
|
|
20
|
+
pixel?: boolean;
|
|
21
|
+
message?: string;
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* 一码游图片压缩
|
|
26
|
+
*/
|
|
27
|
+
export declare function oneTravelImageCompressor(data: File | Blob): Promise<{
|
|
28
|
+
file: File | Blob;
|
|
29
|
+
hasConversion: boolean;
|
|
30
|
+
success: boolean;
|
|
31
|
+
errorMessage?: string;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* 获取图片像素
|
|
35
|
+
* @param src url或 base64
|
|
36
|
+
*/
|
|
37
|
+
export declare function getImagePixel(src: string): Promise<{
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
image: HTMLImageElement;
|
|
41
|
+
}>;
|
package/es/util.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import f from "compressorjs";
|
|
2
|
+
async function d(n, e) {
|
|
3
|
+
const {
|
|
4
|
+
imageMaxSize: i = 30,
|
|
5
|
+
imageAllowedMineType: s = ["image/jpg", "image/jpeg", "image/png", "image/bmp", "image/heif", "image/heic", "image/gif", "image/webp"],
|
|
6
|
+
imageMinWidth: t = 60,
|
|
7
|
+
imageMinHeight: r = 60,
|
|
8
|
+
imageMaxWidth: o = 6e3,
|
|
9
|
+
imageMaxHeight: c = 6e3
|
|
10
|
+
} = e || {}, a = n, l = await u(a);
|
|
11
|
+
if (a.size > i * 1024 * 1024)
|
|
12
|
+
return { success: !1, error: { size: !0 } };
|
|
13
|
+
if (!s.includes(a.type))
|
|
14
|
+
return { success: !1, error: { format: !0 } };
|
|
15
|
+
const m = await g(l);
|
|
16
|
+
return m.width < t && m.height < r || m.width > o && m.height > c ? { success: !1, error: { pixel: !0 } } : { success: !0, file: a };
|
|
17
|
+
}
|
|
18
|
+
async function y(n) {
|
|
19
|
+
var c;
|
|
20
|
+
let e = n;
|
|
21
|
+
const i = await u(e), s = await g(i);
|
|
22
|
+
let t = !1;
|
|
23
|
+
const r = {};
|
|
24
|
+
["image/heif", "image/heic", "image/webp"].includes(e.type) && (r.convertTypes = [e.type], r.convertSize = 0, t = !0);
|
|
25
|
+
const o = 5 * 1024 * 1024;
|
|
26
|
+
if (e.size > o && (r.convertTypes = [e.type], r.convertSize = o, r.maxWidth = s.width * (o / e.size), t = !0), Object.keys(r).length > 0) {
|
|
27
|
+
const a = await h(p(i), r);
|
|
28
|
+
if (a.success)
|
|
29
|
+
e = a.file;
|
|
30
|
+
else
|
|
31
|
+
return { file: e, success: !1, hasConversion: t, errorMessage: (c = a.error) == null ? void 0 : c.message };
|
|
32
|
+
}
|
|
33
|
+
return { file: e, hasConversion: t, success: !0 };
|
|
34
|
+
}
|
|
35
|
+
function h(n, e) {
|
|
36
|
+
return new Promise((i) => {
|
|
37
|
+
new f(n, {
|
|
38
|
+
...e,
|
|
39
|
+
success: async (s) => {
|
|
40
|
+
i({ success: !0, file: s });
|
|
41
|
+
},
|
|
42
|
+
error(s) {
|
|
43
|
+
i({ success: !1, error: s });
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function g(n) {
|
|
49
|
+
return new Promise((e) => {
|
|
50
|
+
const i = new Image();
|
|
51
|
+
i.onload = function() {
|
|
52
|
+
e({ width: i.width, height: i.height, image: i });
|
|
53
|
+
}, i.src = n;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function p(n) {
|
|
57
|
+
const e = n.split(","), i = e[0].match(/:(.*?);/)[1], s = atob(e[1]);
|
|
58
|
+
let t = s.length;
|
|
59
|
+
const r = new Uint8Array(t);
|
|
60
|
+
for (; t--; )
|
|
61
|
+
r[t] = s.charCodeAt(t);
|
|
62
|
+
return new Blob([r], { type: i });
|
|
63
|
+
}
|
|
64
|
+
function u(n) {
|
|
65
|
+
return new Promise((e, i) => {
|
|
66
|
+
const s = new FileReader();
|
|
67
|
+
s.onloadend = () => {
|
|
68
|
+
const t = s.result;
|
|
69
|
+
e(t);
|
|
70
|
+
}, s.onerror = i, s.readAsDataURL(n);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
g as getImagePixel,
|
|
75
|
+
d as oneTravelImageCheck,
|
|
76
|
+
y as oneTravelImageCompressor
|
|
77
|
+
};
|
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.10",
|
|
5
|
+
"version": "0.0.12-alpha.10",
|
|
6
6
|
"private": false,
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "es/index.js",
|
|
@@ -22,10 +22,13 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"compressorjs": "^1.2.1",
|
|
24
24
|
"vue-global-config": "^0.2.6",
|
|
25
|
-
"tinymce": "^7.1.0"
|
|
25
|
+
"tinymce": "^7.1.0",
|
|
26
|
+
"element-ui": "^2.15.14"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
|
-
"vue": "^2.7.0"
|
|
29
|
+
"vue": "^2.7.0",
|
|
30
|
+
"pic-viewer": "^0.5.1",
|
|
31
|
+
"imgpond": "^0.6.2"
|
|
29
32
|
},
|
|
30
33
|
"scripts": {
|
|
31
34
|
"build": "vite build",
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import type { Editor, RawEditorOptions } from 'tinymce'
|
|
2
2
|
import _TinymceEditor from './editor.vue'
|
|
3
3
|
|
|
4
|
+
// 导入 ElementUI
|
|
5
|
+
import { Button, Slider, Dialog, Upload, Tag, Form, FormItem, ButtonGroup, Loading } from 'element-ui'
|
|
6
|
+
|
|
4
7
|
interface TinymceEditorGlobalOptions {
|
|
5
|
-
// 消息方法实例
|
|
6
|
-
message?: {
|
|
7
|
-
// 加载中
|
|
8
|
-
loading?: (message?: string) => { close: () => void }
|
|
9
|
-
// 成功
|
|
10
|
-
success?: (message?: string) => void
|
|
11
|
-
// 错误提示
|
|
12
|
-
error?: (message?: string) => void
|
|
13
|
-
// 销毁
|
|
14
|
-
destroy?: () => void
|
|
15
|
-
}
|
|
16
8
|
/** 图片上传请求处理,需要返回图片地址 */
|
|
17
9
|
imageUploadHandle?: (file: File | Blob, filename: string, options?: {
|
|
18
10
|
extParameters?: Record<string, any>
|
|
@@ -27,7 +19,23 @@ interface TinymceEditorGlobalOptions {
|
|
|
27
19
|
node: HTMLElement;
|
|
28
20
|
readonly internal: boolean;
|
|
29
21
|
}) => void;
|
|
30
|
-
tinymceOptions?: RawEditorOptions
|
|
22
|
+
tinymceOptions?: RawEditorOptions;
|
|
23
|
+
/** imgPond 选项 */
|
|
24
|
+
imgPondOptions?: Record<string, any>
|
|
25
|
+
/** 音频上传选项 */
|
|
26
|
+
audioUploadOptions?: {
|
|
27
|
+
action: string;
|
|
28
|
+
handlerResponse: (response: any) => { url?: string; errorMessage?: string }
|
|
29
|
+
headers?: (parameters: { file: File | Blob, extParameters: Record<string, any> }) => Record<string, any>;
|
|
30
|
+
data?: (parameters: { file: File | Blob, extParameters: Record<string, any> }) => Record<string, any>;
|
|
31
|
+
},
|
|
32
|
+
/** 视频上传选项 */
|
|
33
|
+
videoUploadOptions?: {
|
|
34
|
+
action: string;
|
|
35
|
+
handlerResponse: (response: any) => { url?: string; errorMessage?: string }
|
|
36
|
+
headers?: (parameters: { file: File | Blob, extParameters: Record<string, any> }) => Record<string, any>;
|
|
37
|
+
data?: (parameters: { file: File | Blob, extParameters: Record<string, any> }) => Record<string, any>;
|
|
38
|
+
}
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
// 全局属性
|
|
@@ -37,6 +45,18 @@ const TinymceEditor = Object.assign(_TinymceEditor, {
|
|
|
37
45
|
install: (app: any, options?: TinymceEditorGlobalOptions) => {
|
|
38
46
|
// 合并
|
|
39
47
|
Object.assign(globalProps, (options || {}))
|
|
48
|
+
|
|
49
|
+
// 注入element-ui
|
|
50
|
+
app.use(Button)
|
|
51
|
+
app.use(Slider)
|
|
52
|
+
app.use(Dialog)
|
|
53
|
+
app.use(Upload)
|
|
54
|
+
app.use(Tag)
|
|
55
|
+
app.use(Form)
|
|
56
|
+
app.use(FormItem)
|
|
57
|
+
app.use(ButtonGroup)
|
|
58
|
+
app.use(Loading)
|
|
59
|
+
|
|
40
60
|
// 注册组件
|
|
41
61
|
app.component('KbTinymceEditor', _TinymceEditor)
|
|
42
62
|
}
|
|
@@ -45,5 +65,8 @@ const TinymceEditor = Object.assign(_TinymceEditor, {
|
|
|
45
65
|
export { TinymceEditor, globalProps, type TinymceEditorGlobalOptions }
|
|
46
66
|
export default TinymceEditor
|
|
47
67
|
|
|
68
|
+
// 导出工具类
|
|
69
|
+
export * from './util'
|
|
70
|
+
|
|
48
71
|
// components.d.ts
|
|
49
72
|
export type {} from './components'
|