@viveeditor/docx 0.0.0-stage → 1.0.0-rc.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/LICENSE +21 -0
- package/README.md +29 -2
- package/dist/index.d.ts +86 -0
- package/dist/index.js +1986 -0
- package/dist/index.js.map +1 -0
- package/package.json +88 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 viveEditor contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @viveeditor/docx
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Word (.docx) import and export for viveEditor, with limits for untrusted files.
|
|
4
|
+
|
|
5
|
+
Part of [viveEditor](https://github.com/mtvrkan/viveeditor#readme), a free, open-source rich text editor.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @viveeditor/docx @viveeditor/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { exportDocx, importDocx } from '@viveeditor/docx'
|
|
17
|
+
|
|
18
|
+
const { html, warnings } = await importDocx(file, { upload })
|
|
19
|
+
editor.commands.replaceContent(html)
|
|
20
|
+
|
|
21
|
+
const blob = await exportDocx(editor, { title: 'Report' })
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Word fonts are kept only when they match an entry of the editor's font list. If you configured `FontFamily` with your own `fontFamilies`, pass the same list to `importDocx(file, { fontFamilies })`.
|
|
25
|
+
|
|
26
|
+
Files over 20 MB, password-protected files and files that unpack too large or too deep are refused with a `DocxError`. See [Word (.docx)](https://github.com/mtvrkan/viveeditor#word-docx) for what is kept.
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ImageSourcePolicy, ImageUploader } from "@viveeditor/ext-image";
|
|
2
|
+
import { Schema } from "prosemirror-model";
|
|
3
|
+
type DocxErrorCode = "TOO_LARGE" | "NOT_DOCX" | "ENCRYPTED" | "UNSUPPORTED" | "DAMAGED" | "TOO_COMPLEX" | "ABORTED";
|
|
4
|
+
export declare class DocxError extends Error {
|
|
5
|
+
readonly code: DocxErrorCode;
|
|
6
|
+
constructor(code: DocxErrorCode, message: string);
|
|
7
|
+
}
|
|
8
|
+
interface ImportLimits {
|
|
9
|
+
fileBytes: number;
|
|
10
|
+
totalBytes: number;
|
|
11
|
+
documentBytes: number;
|
|
12
|
+
partBytes: number;
|
|
13
|
+
imageBytes: number;
|
|
14
|
+
images: number;
|
|
15
|
+
imagePixels: number;
|
|
16
|
+
elements: number;
|
|
17
|
+
cells: number;
|
|
18
|
+
}
|
|
19
|
+
interface ImportOptions {
|
|
20
|
+
upload?: ImageUploader | null;
|
|
21
|
+
allowBase64?: boolean;
|
|
22
|
+
imagePolicy?: Partial<ImageSourcePolicy>;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
limits?: Partial<ImportLimits>;
|
|
25
|
+
fontFamilies?: readonly string[];
|
|
26
|
+
comments?: boolean;
|
|
27
|
+
trackedChanges?: "accept" | "keep";
|
|
28
|
+
}
|
|
29
|
+
type ImportWarningCode = "HIDDEN_TEXT" | "IMAGE_DROPPED" | "LINK_DROPPED" | "OBJECT_DROPPED" | "NESTING_FLATTENED";
|
|
30
|
+
interface ImportWarning {
|
|
31
|
+
code: ImportWarningCode;
|
|
32
|
+
count: number;
|
|
33
|
+
}
|
|
34
|
+
interface ImportedComment {
|
|
35
|
+
id: string;
|
|
36
|
+
author: {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
};
|
|
40
|
+
body: string;
|
|
41
|
+
created: string;
|
|
42
|
+
}
|
|
43
|
+
interface ImportedThread {
|
|
44
|
+
id: string;
|
|
45
|
+
resolved: boolean;
|
|
46
|
+
comments: ImportedComment[];
|
|
47
|
+
}
|
|
48
|
+
interface DocxImport {
|
|
49
|
+
html: string;
|
|
50
|
+
warnings: ImportWarning[];
|
|
51
|
+
threads: ImportedThread[];
|
|
52
|
+
}
|
|
53
|
+
export declare const DEFAULT_IMPORT_LIMITS: Readonly<ImportLimits>;
|
|
54
|
+
export declare function importDocx(file: Blob, options?: ImportOptions): Promise<DocxImport>;
|
|
55
|
+
interface ExportSource {
|
|
56
|
+
readonly schema: Schema;
|
|
57
|
+
getJSON(): unknown;
|
|
58
|
+
}
|
|
59
|
+
interface ExportComment {
|
|
60
|
+
readonly author: {
|
|
61
|
+
readonly name: string;
|
|
62
|
+
};
|
|
63
|
+
readonly body: string;
|
|
64
|
+
readonly created: string;
|
|
65
|
+
}
|
|
66
|
+
interface ExportThread {
|
|
67
|
+
readonly id: string;
|
|
68
|
+
readonly resolved?: boolean;
|
|
69
|
+
readonly comments: readonly ExportComment[];
|
|
70
|
+
}
|
|
71
|
+
interface ExportOptions {
|
|
72
|
+
title?: string;
|
|
73
|
+
threads?: readonly ExportThread[];
|
|
74
|
+
fetchImages?: boolean;
|
|
75
|
+
signal?: AbortSignal;
|
|
76
|
+
limits?: Partial<ExportLimits>;
|
|
77
|
+
}
|
|
78
|
+
interface ExportLimits {
|
|
79
|
+
imageBytes: number;
|
|
80
|
+
images: number;
|
|
81
|
+
timeout: number;
|
|
82
|
+
}
|
|
83
|
+
export declare const DOCX_MIME = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
84
|
+
export declare function exportDocx(source: ExportSource, options?: ExportOptions): Promise<Blob>;
|
|
85
|
+
export type { DocxErrorCode, DocxImport, ExportComment, ExportLimits, ExportOptions, ExportSource, ExportThread, ImportLimits, ImportOptions, ImportWarning, ImportWarningCode, ImportedComment, ImportedThread };
|
|
86
|
+
//# sourceMappingURL=index.d.ts.map
|