@4399ywkf/editor 0.2.0 → 0.3.0
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/{DocView-BPODKQ57.js → DocView-GDN5CZCJ.js} +3 -3
- package/dist/{DocView-BPODKQ57.js.map → DocView-GDN5CZCJ.js.map} +1 -1
- package/dist/{chunk-3GZSG6KH.js → chunk-ZRFOS52C.js} +79 -3
- package/dist/chunk-ZRFOS52C.js.map +1 -0
- package/dist/doc-runtime.d.ts +33 -0
- package/dist/doc-runtime.js +87 -0
- package/dist/doc-runtime.js.map +1 -1
- package/dist/doc.js +1 -1
- package/dist/docx.d.ts +121 -6
- package/dist/docx.js +421 -40
- package/dist/docx.js.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3GZSG6KH.js.map +0 -1
package/dist/docx.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { Node, Extension, JSONContent } from '@tiptap/core';
|
|
2
2
|
|
|
3
|
-
declare const DocxField: Node<any, any>;
|
|
4
|
-
|
|
5
|
-
declare const DocxInk: Node<any, any>;
|
|
6
|
-
|
|
7
3
|
/**
|
|
8
4
|
* OOXML → tiptap JSONContent。
|
|
9
5
|
*
|
|
@@ -43,6 +39,59 @@ interface ParseDocxOptions {
|
|
|
43
39
|
prosemirrorMarks?: Record<string, string>;
|
|
44
40
|
/** 抽取文档默认样式为 CSS 字符串,对齐官方 `cssStyles` */
|
|
45
41
|
cssStyles?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* 宿主正文列的宽度(px),用来把表格列宽从「Word 页面」换算到「编辑器版心」。
|
|
44
|
+
*
|
|
45
|
+
* Word 的列宽虽然是绝对磅值,但它是**相对页面文本宽度**定出来的:本文档的
|
|
46
|
+
* 表格 tblW=9026dxa,而页面文本宽度(pgSz − 左右 pgMar)也正好是 9026dxa ——
|
|
47
|
+
* 在 Word 里它铺满一行。照搬绝对值塞进更宽的编辑器版心,就成了缩在左边的窄表。
|
|
48
|
+
* 给了这个值就按比例重新落位:满宽的表继续满宽,半宽的表继续占一半。
|
|
49
|
+
* 不给则保持 Word 的绝对磅值(Node 侧无从测量时的默认)。
|
|
50
|
+
*/
|
|
51
|
+
contentWidthPx?: number;
|
|
52
|
+
/**
|
|
53
|
+
* 宿主表格扩展的 `cellMinWidth`(px)。
|
|
54
|
+
*
|
|
55
|
+
* tiptap 渲染列宽时会做 `Math.max(colwidth, cellMinWidth)`,但表格总宽仍按
|
|
56
|
+
* 原始 colwidth 算 —— 于是窄列被顶宽、表格撑破、列比例还变了形。
|
|
57
|
+
* 告诉我们这个下限,就能提前把宽度摊匀,不让读端去顶。
|
|
58
|
+
*/
|
|
59
|
+
minColumnWidthPx?: number;
|
|
60
|
+
}
|
|
61
|
+
interface DocxSectionRef {
|
|
62
|
+
kind: 'header' | 'footer';
|
|
63
|
+
/** `default` | `first` | `even` */
|
|
64
|
+
type: string;
|
|
65
|
+
/** 原 sectPr 里的 r:id */
|
|
66
|
+
rid: string;
|
|
67
|
+
/** 包内路径,如 `word/header1.xml` */
|
|
68
|
+
path: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 节属性(页眉页脚 + 页面几何),**原样**带出来。
|
|
72
|
+
*
|
|
73
|
+
* 为什么不解析成 JSONContent 再写回:编辑器没有页眉页脚这个概念,解析→重建
|
|
74
|
+
* 只会把我们看不懂的东西(域、图片、制表位、边框…)在往返中磨掉。这里存的是
|
|
75
|
+
* 原始字节和原始 XML,导出时塞回包里即可,磨不掉 —— 和 `docxInk` 存
|
|
76
|
+
* `strokesXml` 是同一个思路。
|
|
77
|
+
*/
|
|
78
|
+
interface DocxSection {
|
|
79
|
+
/**
|
|
80
|
+
* 原始 `<w:sectPr>` XML。导出时除了重写页眉页脚的 r:id,其余原样写回 ——
|
|
81
|
+
* 页面尺寸、页边距、页码格式、文档网格、首页不同都在里面。
|
|
82
|
+
*/
|
|
83
|
+
sectPrXml: string | null;
|
|
84
|
+
refs: DocxSectionRef[];
|
|
85
|
+
/** 页眉页脚部件本身 + 各自的 .rels + 它们引用到的媒体,键是包内路径 */
|
|
86
|
+
files: Record<string, Uint8Array>;
|
|
87
|
+
/**
|
|
88
|
+
* 原始 `word/settings.xml`。
|
|
89
|
+
*
|
|
90
|
+
* 和页眉直接相关:`evenAndOddHeaders` 决定奇偶页是否用不同页眉,丢了它
|
|
91
|
+
* 奇偶页眉就失效。另外 `compatSetting compatibilityMode` 缺失会让 Word
|
|
92
|
+
* 按兼容模式打开文档(标题栏挂「兼容模式」,排版规则也退回旧版)。
|
|
93
|
+
*/
|
|
94
|
+
settingsXml: string | null;
|
|
46
95
|
}
|
|
47
96
|
interface ParseDocxResult {
|
|
48
97
|
doc: Record<string, unknown>;
|
|
@@ -51,9 +100,19 @@ interface ParseDocxResult {
|
|
|
51
100
|
warnings: string[];
|
|
52
101
|
/** `cssStyles: true` 时给出的文档默认样式 */
|
|
53
102
|
css?: string;
|
|
103
|
+
/** 默认页眉的结构化内容(供宿主展示;往返靠的是 `section`,不是它) */
|
|
104
|
+
header: Record<string, unknown> | null;
|
|
105
|
+
/** 默认页脚的结构化内容,同上 */
|
|
106
|
+
footer: Record<string, unknown> | null;
|
|
107
|
+
/** 节属性原件,交给导出侧原样写回 */
|
|
108
|
+
section: DocxSection;
|
|
54
109
|
}
|
|
55
110
|
declare function parseDocx(entries: DocxEntries, opts: ParseDocxOptions): ParseDocxResult;
|
|
56
111
|
|
|
112
|
+
declare const DocxField: Node<any, any>;
|
|
113
|
+
|
|
114
|
+
declare const DocxInk: Node<any, any>;
|
|
115
|
+
|
|
57
116
|
/**
|
|
58
117
|
* tiptap JSONContent → .docx(OOXML)。
|
|
59
118
|
*
|
|
@@ -64,6 +123,7 @@ declare function parseDocx(entries: DocxEntries, opts: ParseDocxOptions): ParseD
|
|
|
64
123
|
* `docxInk` 写回 `w14:contentPart` + 位图回退 —— 这两样在导入时被保住,
|
|
65
124
|
* 导出时才有东西可写。
|
|
66
125
|
*/
|
|
126
|
+
|
|
67
127
|
interface SerializeOptions {
|
|
68
128
|
/** 把图片 src 换成字节。返回 null 则该图片跳过并记警告 */
|
|
69
129
|
resolveImage?: (src: string) => Uint8Array | null;
|
|
@@ -74,6 +134,25 @@ interface SerializeOptions {
|
|
|
74
134
|
};
|
|
75
135
|
/** 逐段落覆盖,对齐官方 paragraphOverrides */
|
|
76
136
|
paragraphOverrides?: (node: Node_) => Record<string, string> | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* 导入时带出来的节属性(`ParseDocxResult.section`),原样写回。
|
|
139
|
+
*
|
|
140
|
+
* 编辑器渲染不了页眉页脚,但只要把原始部件塞回包里,一趟往返就不会丢 ——
|
|
141
|
+
* 连同页面尺寸、页边距、页码格式、文档网格这些 sectPr 上的东西一起。
|
|
142
|
+
* 不给则退回默认的 A4 + 2.54cm 页边距,且没有页眉页脚。
|
|
143
|
+
*/
|
|
144
|
+
section?: DocxSection;
|
|
145
|
+
/**
|
|
146
|
+
* 列宽所依据的编辑器版心宽度(px)—— 导入侧 `contentWidthPx` 的**逆变换**。
|
|
147
|
+
*
|
|
148
|
+
* 导入把 Word 的列宽按「占页面文本宽度的比例」重新落到了版心上,导出必须按
|
|
149
|
+
* 同样的比例还回去。只做单向的后果:708px 的表格被当成 708×15 = 10620 dxa 写出去,
|
|
150
|
+
* 而 A4 的页面文本宽度只有 9026 —— 表格在 Word 里冲出右边距、最后一列被切掉。
|
|
151
|
+
*
|
|
152
|
+
* 不给的话按 96dpi 直译(1px = 15dxa),但会**兜底裁到页面文本宽度以内**,
|
|
153
|
+
* 保证再怎么样也不会溢出页面。
|
|
154
|
+
*/
|
|
155
|
+
contentWidthPx?: number;
|
|
77
156
|
}
|
|
78
157
|
interface SerializeResult {
|
|
79
158
|
/** docx 包内的所有条目,交给 zip 打包 */
|
|
@@ -85,8 +164,20 @@ type Node_ = Record<string, any>;
|
|
|
85
164
|
declare function serializeDocx(doc: Node_, opts?: SerializeOptions): SerializeResult;
|
|
86
165
|
|
|
87
166
|
type ExportType = 'blob' | 'buffer' | 'string';
|
|
167
|
+
/** 导出的伴随信息。官方回调只给结果本身,统计和警告拿不到 —— 这里作为第二个参数补上 */
|
|
168
|
+
interface ExportDocxMeta {
|
|
169
|
+
stats: Record<string, number>;
|
|
170
|
+
warnings: string[];
|
|
171
|
+
/** 未压缩的字节数 */
|
|
172
|
+
bytes: number;
|
|
173
|
+
}
|
|
88
174
|
interface ExportDocxOptions extends SerializeOptions {
|
|
89
|
-
|
|
175
|
+
/**
|
|
176
|
+
* 导出完成回调。第一个参数的形状由 `exportType` 决定,对齐官方。
|
|
177
|
+
* 第二个参数是本扩展多给的统计与警告 —— 官方回调只给结果,
|
|
178
|
+
* 调用方拿不到「导出时丢了什么」,而那恰恰是最该看的。
|
|
179
|
+
*/
|
|
180
|
+
onCompleteExport: ((result: Blob | Uint8Array | string, meta: ExportDocxMeta) => void) | null;
|
|
90
181
|
exportType: ExportType;
|
|
91
182
|
/** 诊断级别,同导入侧 */
|
|
92
183
|
verbose: number;
|
|
@@ -146,6 +237,19 @@ interface ImportDocxOptions {
|
|
|
146
237
|
preserveUnsupported: boolean;
|
|
147
238
|
/** 是否注入浮动定位所需样式,默认 true */
|
|
148
239
|
injectStyles: boolean;
|
|
240
|
+
/**
|
|
241
|
+
* 表格列宽的换算基准。
|
|
242
|
+
*
|
|
243
|
+
* Word 的列宽是相对**页面文本宽度**定的:铺满一行的表格,其 tblW 就等于
|
|
244
|
+
* 页宽减左右页边距。照搬这个绝对值塞进编辑器版心(往往更宽),表格就缩在
|
|
245
|
+
* 左边不铺满 —— 也就是「Word 里是自适应的,导进来却不是」。
|
|
246
|
+
*
|
|
247
|
+
* - `'auto'`(默认):导入时量一下编辑器正文列的实际宽度,按比例重新落位。
|
|
248
|
+
* 满宽的表继续满宽,半宽的表继续占一半。
|
|
249
|
+
* - 数字:直接用这个宽度(px)当基准,SSR / 测试等量不到 DOM 的场景用。
|
|
250
|
+
* - `null`:不换算,保留 Word 的绝对磅值。
|
|
251
|
+
*/
|
|
252
|
+
tableWidthBasis: number | 'auto' | null;
|
|
149
253
|
}
|
|
150
254
|
/** onImport 回调拿到的上下文,字段对齐官方 */
|
|
151
255
|
interface ImportDocxContext {
|
|
@@ -159,8 +263,19 @@ interface ImportDocxContext {
|
|
|
159
263
|
warnings: string[];
|
|
160
264
|
/** cssStyles:true 时的文档默认样式 */
|
|
161
265
|
css?: string;
|
|
266
|
+
/** 默认页眉的结构化内容。供宿主展示 —— 往返靠的是 `section`,不是它 */
|
|
162
267
|
header: JSONContent | null;
|
|
268
|
+
/** 默认页脚的结构化内容,同上 */
|
|
163
269
|
footer: JSONContent | null;
|
|
270
|
+
/**
|
|
271
|
+
* 节属性原件(页眉页脚部件 + 页面几何)。
|
|
272
|
+
*
|
|
273
|
+
* 编辑器渲染不了页眉页脚,所以它不进文档树;导出时把它交回
|
|
274
|
+
* `serializeDocx({ section })` 就能原样写回。同一个 editor 上同时挂了
|
|
275
|
+
* `ImportDocx` 和 `ExportDocx` 的话不用管 —— 导出侧会自动接上(见下)。
|
|
276
|
+
* 但它只活在内存里:刷新页面 / 换设备就没了,要跨会话往返得自己存。
|
|
277
|
+
*/
|
|
278
|
+
section: DocxSection;
|
|
164
279
|
footnotes: Record<string, JSONContent>;
|
|
165
280
|
endnotes: Record<string, JSONContent>;
|
|
166
281
|
}
|
|
@@ -181,4 +296,4 @@ declare module '@tiptap/core' {
|
|
|
181
296
|
}
|
|
182
297
|
declare const ImportDocx: Extension<ImportDocxOptions, any>;
|
|
183
298
|
|
|
184
|
-
export { type DocxEntries, DocxField, DocxInk, ExportDocx, type ExportDocxOptions, type ExportType, type ImageUploadConfig, ImportDocx, type ImportDocxCommandArgs, type ImportDocxContext, type ImportDocxOptions, type ParseDocxOptions, type ParseDocxResult, type SerializeOptions, type SerializeResult, docxFromJSON, downloadDocx, parseDocx, serializeDocx };
|
|
299
|
+
export { type DocxEntries, DocxField, DocxInk, type DocxSection, type DocxSectionRef, ExportDocx, type ExportDocxOptions, type ExportType, type ImageUploadConfig, ImportDocx, type ImportDocxCommandArgs, type ImportDocxContext, type ImportDocxOptions, type ParseDocxOptions, type ParseDocxResult, type SerializeOptions, type SerializeResult, docxFromJSON, downloadDocx, parseDocx, serializeDocx };
|