@mce/openxml 0.18.5 → 0.19.1
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/dist/index.js +136 -58
- package/dist/plugin.d.ts +5 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { definePlugin } from "mce";
|
|
2
|
-
import { docToPptx, pptxToDoc } from "modern-openxml";
|
|
2
|
+
import { docToDocx, docToPptx, docToXlsx, docxToDoc, pptxToDoc, xlsxToDoc } from "modern-openxml";
|
|
3
3
|
//#region src/plugin.ts
|
|
4
4
|
function plugin() {
|
|
5
5
|
return definePlugin((editor) => {
|
|
@@ -7,68 +7,146 @@ function plugin() {
|
|
|
7
7
|
const RE = /\.pptx$/i;
|
|
8
8
|
return {
|
|
9
9
|
name: "mce:openxml",
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
messages: {
|
|
11
|
+
en: {
|
|
12
|
+
"saveAs:pptx": "Save as PPTX",
|
|
13
|
+
"saveAs:xlsx": "Save as XLSX",
|
|
14
|
+
"saveAs:docx": "Save as DOCX"
|
|
15
|
+
},
|
|
16
|
+
zhHans: {
|
|
17
|
+
"saveAs:pptx": "另存为 PPTX",
|
|
18
|
+
"saveAs:xlsx": "另存为 XLSX",
|
|
19
|
+
"saveAs:docx": "另存为 DOCX"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
loaders: [
|
|
23
|
+
{
|
|
24
|
+
name: "pptx",
|
|
25
|
+
accept: ".pptx",
|
|
26
|
+
test: (source) => {
|
|
27
|
+
if (source instanceof Blob) {
|
|
28
|
+
if (source.type.startsWith("application/vnd.openxmlformats-officedocument.presentationml.presentation")) return true;
|
|
29
|
+
}
|
|
30
|
+
if (source instanceof File) {
|
|
31
|
+
if (RE.test(source.name)) return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
},
|
|
35
|
+
load: async (source) => {
|
|
36
|
+
const presetShapeDefinitions = await import("modern-openxml/presetShapeDefinitions").then((rep) => rep.default);
|
|
37
|
+
const doc = await pptxToDoc(await source.arrayBuffer(), {
|
|
38
|
+
presetShapeDefinitions,
|
|
39
|
+
upload: async (input, meta) => {
|
|
40
|
+
const filename = meta.image;
|
|
41
|
+
let mimeType = getMimeType(meta.image);
|
|
42
|
+
const arrayBuffer = base64ToArrayBuffer(input);
|
|
43
|
+
if (!mimeType) {
|
|
44
|
+
const ext = detectImageExt(arrayBuffer);
|
|
45
|
+
if (ext) mimeType = getMimeType(ext);
|
|
46
|
+
}
|
|
47
|
+
return await upload(new File([arrayBuffer], filename, { type: mimeType ?? void 0 }));
|
|
48
|
+
},
|
|
49
|
+
progress: (current, total, cached) => {
|
|
50
|
+
log("load pptx progress", `${current}/${total}`, cached ? "cached" : "");
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
doc.children?.forEach((child, index) => {
|
|
54
|
+
child.name = `Slide ${index + 1}`;
|
|
55
|
+
child.style ??= {};
|
|
56
|
+
child.style.left = 0;
|
|
57
|
+
child.style.top = Number(child.style.top);
|
|
58
|
+
child.style.overflow = "hidden";
|
|
59
|
+
child.meta.inEditorIs = "Frame";
|
|
60
|
+
});
|
|
61
|
+
doc.children.reverse();
|
|
62
|
+
doc.name = source.name;
|
|
63
|
+
doc.meta.inEditorIs = "Doc";
|
|
64
|
+
return doc;
|
|
16
65
|
}
|
|
17
|
-
|
|
18
|
-
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "xlsx",
|
|
69
|
+
accept: ".xlsx",
|
|
70
|
+
test: (source) => {
|
|
71
|
+
if (source instanceof Blob && source.type.includes("spreadsheetml.sheet")) return true;
|
|
72
|
+
if (source instanceof File && /\.xlsx$/i.test(source.name)) return true;
|
|
73
|
+
return false;
|
|
74
|
+
},
|
|
75
|
+
load: async (source) => {
|
|
76
|
+
const doc = await xlsxToDoc(await source.arrayBuffer());
|
|
77
|
+
doc.name = source.name;
|
|
78
|
+
doc.meta.inEditorIs = "Doc";
|
|
79
|
+
return doc;
|
|
19
80
|
}
|
|
20
|
-
return false;
|
|
21
81
|
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
progress: (current, total, cached) => {
|
|
37
|
-
log("load pptx progress", `${current}/${total}`, cached ? "cached" : "");
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
doc.children?.forEach((child, index) => {
|
|
41
|
-
child.name = `Slide ${index + 1}`;
|
|
42
|
-
child.style ??= {};
|
|
43
|
-
child.style.left = 0;
|
|
44
|
-
child.style.top = Number(child.style.top);
|
|
45
|
-
child.style.overflow = "hidden";
|
|
46
|
-
child.meta.inEditorIs = "Frame";
|
|
47
|
-
});
|
|
48
|
-
doc.children.reverse();
|
|
49
|
-
doc.name = source.name;
|
|
50
|
-
doc.meta.inEditorIs = "Doc";
|
|
51
|
-
return doc;
|
|
82
|
+
{
|
|
83
|
+
name: "docx",
|
|
84
|
+
accept: ".docx",
|
|
85
|
+
test: (source) => {
|
|
86
|
+
if (source instanceof Blob && source.type.includes("wordprocessingml.document")) return true;
|
|
87
|
+
if (source instanceof File && /\.docx$/i.test(source.name)) return true;
|
|
88
|
+
return false;
|
|
89
|
+
},
|
|
90
|
+
load: async (source) => {
|
|
91
|
+
const doc = await docxToDoc(await source.arrayBuffer());
|
|
92
|
+
doc.name = source.name;
|
|
93
|
+
doc.meta.inEditorIs = "Doc";
|
|
94
|
+
return doc;
|
|
95
|
+
}
|
|
52
96
|
}
|
|
53
|
-
|
|
54
|
-
exporters: [
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
97
|
+
],
|
|
98
|
+
exporters: [
|
|
99
|
+
{
|
|
100
|
+
name: "pptx",
|
|
101
|
+
saveAs: true,
|
|
102
|
+
handle: async (options) => {
|
|
103
|
+
const { pptx: pptxOptions, ...jsonOptions } = options;
|
|
104
|
+
const doc = await to("json", jsonOptions);
|
|
105
|
+
doc.children?.reverse();
|
|
106
|
+
const pptx = await docToPptx({
|
|
107
|
+
...doc,
|
|
108
|
+
fonts,
|
|
109
|
+
meta: {
|
|
110
|
+
...doc.meta,
|
|
111
|
+
...pptxOptions
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return new Blob([pptx], { type: "application/vnd.openxmlformats-officedocument.presentationml.presentation" });
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: "xlsx",
|
|
119
|
+
saveAs: true,
|
|
120
|
+
handle: async (options) => {
|
|
121
|
+
const { xlsx: xlsxOptions, ...jsonOptions } = options;
|
|
122
|
+
const doc = await to("json", jsonOptions);
|
|
123
|
+
const xlsx = await docToXlsx({
|
|
124
|
+
...doc,
|
|
125
|
+
meta: {
|
|
126
|
+
...doc.meta,
|
|
127
|
+
...xlsxOptions
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return new Blob([xlsx], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: "docx",
|
|
135
|
+
saveAs: true,
|
|
136
|
+
handle: async (options) => {
|
|
137
|
+
const { docx: docxOptions, ...jsonOptions } = options;
|
|
138
|
+
const doc = await to("json", jsonOptions);
|
|
139
|
+
const docx = await docToDocx({
|
|
140
|
+
...doc,
|
|
141
|
+
meta: {
|
|
142
|
+
...doc.meta,
|
|
143
|
+
...docxOptions
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return new Blob([docx], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" });
|
|
147
|
+
}
|
|
70
148
|
}
|
|
71
|
-
|
|
149
|
+
]
|
|
72
150
|
};
|
|
73
151
|
});
|
|
74
152
|
}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import type { PptxMeta } from 'modern-openxml';
|
|
1
|
+
import type { DocxMeta, PptxMeta, XlsxMeta } from 'modern-openxml';
|
|
2
2
|
declare global {
|
|
3
3
|
namespace Mce {
|
|
4
4
|
interface ExportOptions {
|
|
5
5
|
pptx?: Partial<PptxMeta>;
|
|
6
|
+
xlsx?: Partial<XlsxMeta>;
|
|
7
|
+
docx?: Partial<DocxMeta>;
|
|
6
8
|
}
|
|
7
9
|
interface Exporters {
|
|
8
10
|
pptx: Promise<Blob>;
|
|
11
|
+
xlsx: Promise<Blob>;
|
|
12
|
+
docx: Promise<Blob>;
|
|
9
13
|
}
|
|
10
14
|
}
|
|
11
15
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mce/openxml",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.19.1",
|
|
5
5
|
"description": "Openxml plugin for mce",
|
|
6
6
|
"author": "wxm",
|
|
7
7
|
"license": "MIT",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"dist"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"modern-openxml": "^1.
|
|
49
|
+
"modern-openxml": "^1.12.3"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"mce": "0.
|
|
52
|
+
"mce": "0.19.1"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"mce": "^0"
|