@docen/docx 0.3.1 → 0.3.3
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/converters/docx.d.mts +220 -1
- package/dist/converters/docx.mjs +1352 -1
- package/dist/converters/html.d.mts +28 -1
- package/dist/converters/html.mjs +103 -1
- package/dist/converters/markdown.d.mts +12 -1
- package/dist/converters/markdown.mjs +17 -1
- package/dist/converters/patch.d.mts +52 -1
- package/dist/converters/patch.mjs +35 -1
- package/dist/converters/prepare.d.mts +62 -1
- package/dist/converters/prepare.mjs +121 -1
- package/dist/converters/styles.d.mts +91 -2
- package/dist/converters/styles.mjs +308 -2
- package/dist/core-B8ba_FNi.mjs +717 -0
- package/dist/core-DRaLI8nd.d.mts +203 -0
- package/dist/core.d.mts +1 -1
- package/dist/core.mjs +1 -1
- package/dist/document-Cws7XTYL.d.mts +28 -0
- package/dist/editor.d.mts +20 -1
- package/dist/editor.mjs +20 -1
- package/dist/extensions/blockquote.d.mts +1 -1
- package/dist/extensions/blockquote.mjs +30 -2
- package/dist/extensions/code-block.d.mts +1 -1
- package/dist/extensions/code-block.mjs +22 -1
- package/dist/extensions/column-break.d.mts +1 -1
- package/dist/extensions/column-break.mjs +1 -1
- package/dist/extensions/details.d.mts +1 -1
- package/dist/extensions/details.mjs +17 -2
- package/dist/extensions/document.d.mts +1 -1
- package/dist/extensions/document.mjs +45 -1
- package/dist/extensions/extensions.d.mts +4 -5
- package/dist/extensions/extensions.mjs +13 -14
- package/dist/extensions/formatting-marks.d.mts +7 -1
- package/dist/extensions/formatting-marks.mjs +1 -1
- package/dist/extensions/heading.mjs +187 -1
- package/dist/extensions/image.d.mts +1 -1
- package/dist/extensions/image.mjs +395 -1
- package/dist/extensions/index.d.mts +4 -3
- package/dist/extensions/index.mjs +4 -3
- package/dist/extensions/mention.d.mts +1 -1
- package/dist/extensions/mention.mjs +43 -2
- package/dist/extensions/ordered-list.d.mts +1 -1
- package/dist/extensions/ordered-list.mjs +40 -2
- package/dist/extensions/page-break.d.mts +1 -33
- package/dist/extensions/page-break.mjs +1 -1
- package/dist/extensions/paragraph.mjs +145 -1
- package/dist/extensions/passthrough.d.mts +1 -1
- package/dist/extensions/passthrough.mjs +1 -1
- package/dist/extensions/section-break.d.mts +19 -2
- package/dist/extensions/section-break.mjs +1 -1
- package/dist/extensions/strike.mjs +45 -1
- package/dist/extensions/table-cell.mjs +106 -1
- package/dist/extensions/table-header.mjs +106 -1
- package/dist/extensions/table-row.mjs +78 -1
- package/dist/extensions/table.mjs +154 -1
- package/dist/extensions/task-item.d.mts +1 -1
- package/dist/extensions/task-item.mjs +36 -2
- package/dist/extensions/text-style.mjs +145 -1
- package/dist/extensions/tiptap.d.mts +2 -2
- package/dist/extensions/tiptap.mjs +31 -2
- package/dist/extensions/toc-field.d.mts +2 -0
- package/dist/extensions/toc-field.mjs +2 -0
- package/dist/extensions/utils.d.mts +2 -62
- package/dist/extensions/utils.mjs +508 -2
- package/dist/extensions/wpg-group.d.mts +2 -0
- package/dist/extensions/wpg-group.mjs +2 -0
- package/dist/extensions/wps-shape.d.mts +2 -0
- package/dist/extensions/wps-shape.mjs +2 -0
- package/dist/index.d.mts +101 -29
- package/dist/index.mjs +13 -10
- package/dist/{tiptap-TErPjuNJ.d.mts → tiptap-pZsNPsvV.d.mts} +1 -3
- package/dist/utils-BJwDQts7.d.mts +137 -0
- package/package.json +39 -40
- package/dist/blockquote-Ky9xD_Q-.mjs +0 -31
- package/dist/code-block-BgNjhADy.mjs +0 -23
- package/dist/core-DEqBHRzE.mjs +0 -406
- package/dist/core-fBMCCj4D.d.mts +0 -97
- package/dist/details-Dh8luWb2.mjs +0 -18
- package/dist/dist-B6B3HnVZ.mjs +0 -1838
- package/dist/document-BH1y4qHM.d.mts +0 -6
- package/dist/document-CvTym-FM.mjs +0 -50
- package/dist/docx-C5wyjI-0.d.mts +0 -200
- package/dist/docx-CONyAedl.mjs +0 -1231
- package/dist/editor-Bf3CxQnY.mjs +0 -21
- package/dist/editor-DReY3Rb9.d.mts +0 -21
- package/dist/emoji-BZ1dJD7d.d.mts +0 -17
- package/dist/emoji-C2OsTWR7.mjs +0 -27
- package/dist/extensions/emoji.d.mts +0 -2
- package/dist/extensions/emoji.mjs +0 -2
- package/dist/extensions/image-group.d.mts +0 -6
- package/dist/extensions/image-group.mjs +0 -2
- package/dist/heading-DAubgJJN.mjs +0 -166
- package/dist/html-DCC_DSHv.d.mts +0 -18
- package/dist/html-DedDWPoO.mjs +0 -66
- package/dist/image-CuEIXoZl.mjs +0 -334
- package/dist/markdown-BzJmRsBs.mjs +0 -18
- package/dist/markdown-D0k0sRYS.d.mts +0 -13
- package/dist/mention-C-dTR6MK.mjs +0 -44
- package/dist/ordered-list-V-3xFQmV.mjs +0 -41
- package/dist/paragraph-BrWH-BOV.mjs +0 -147
- package/dist/patch-Cdp5WKJz.d.mts +0 -53
- package/dist/patch-IZ13tXTu.mjs +0 -36
- package/dist/prepare-Bdk8Cjkf.mjs +0 -122
- package/dist/prepare-CPAvcv6q.d.mts +0 -63
- package/dist/strike-hWxShOgb.mjs +0 -50
- package/dist/styles-QSX3RhxK.mjs +0 -285
- package/dist/styles-ugspkrxz.d.mts +0 -85
- package/dist/table-DrA12lxX.mjs +0 -159
- package/dist/table-cell-DmkfYwDc.mjs +0 -112
- package/dist/table-header-Bwr5GKWg.mjs +0 -112
- package/dist/table-row-vew1y7WH.mjs +0 -84
- package/dist/task-item-BnlXGrIG.mjs +0 -37
- package/dist/text-style-tMeBq5XQ.mjs +0 -151
- package/dist/tiptap-D7pl4I5U.mjs +0 -33
- package/dist/utils-BPT4tjcn.mjs +0 -333
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { AnyExtension, Editor, Extension, Extensions, JSONContent as JSONContent$1, Mark, Node } from "@tiptap/core";
|
|
2
|
+
import { TextAlign } from "@tiptap/extension-text-align";
|
|
3
|
+
|
|
4
|
+
//#region src/extensions/image.d.ts
|
|
5
|
+
type CropRect = {
|
|
6
|
+
left?: number;
|
|
7
|
+
top?: number;
|
|
8
|
+
right?: number;
|
|
9
|
+
bottom?: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Tiptap JSON image node → CoreImageOptions-shaped object.
|
|
13
|
+
*
|
|
14
|
+
* Returns `{ image: ImageOptions }` (structural wrapper) or null when no
|
|
15
|
+
* embedded image data is available (external URLs need pre-fetching).
|
|
16
|
+
* rotation is carried via transformation.rotation (not dropped).
|
|
17
|
+
*/
|
|
18
|
+
declare function renderDocx(node: JSONContent$1): Record<string, unknown> | null;
|
|
19
|
+
/**
|
|
20
|
+
* ImageOptions-shaped object → Tiptap attrs.
|
|
21
|
+
*
|
|
22
|
+
* Near-identity unpack: transformation → width/height/rotation, altText → alt/title,
|
|
23
|
+
* floating/srcRect(→crop)/outline passed through verbatim. src is reconstructed by
|
|
24
|
+
* DocxManager from the image data bytes (kept out of parseDocx).
|
|
25
|
+
*/
|
|
26
|
+
declare function parseDocx(imageOpts: Record<string, unknown>): Record<string, unknown>;
|
|
27
|
+
/** Extent-box dimensions needed to size the inner <img> for a cropped image. */
|
|
28
|
+
interface CropRenderContext {
|
|
29
|
+
width?: number;
|
|
30
|
+
height?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Render crop as the inner <img> style for byte-accurate four-sided srcRect.
|
|
34
|
+
*
|
|
35
|
+
* object-fit:cover scales uniformly, so it only matches single-axis crops.
|
|
36
|
+
* Instead the inner <img> is sized to the un-cropped display size per axis
|
|
37
|
+
* (imgW = W/visibleW, imgH = H/visibleH) and translated so the visible srcRect
|
|
38
|
+
* region maps exactly onto the extent box; the outer box clips (overflow:hidden)
|
|
39
|
+
* the cropped-out left/top region. Mathematically equivalent to a
|
|
40
|
+
* background-size/background-position crop, but keeps a real <img> (alt,
|
|
41
|
+
* accessibility, semantics, drag-to-save).
|
|
42
|
+
*/
|
|
43
|
+
declare function renderCropAttrs(crop: Record<string, unknown> | CropRect, ctx?: CropRenderContext): {
|
|
44
|
+
style: string;
|
|
45
|
+
};
|
|
46
|
+
declare const Image: import("@tiptap/core").Node<import("@tiptap/extension-image").ImageOptions, any>;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/extensions/wpg-group.d.ts
|
|
49
|
+
interface FillColor {
|
|
50
|
+
value?: string;
|
|
51
|
+
}
|
|
52
|
+
interface Fill {
|
|
53
|
+
type?: string;
|
|
54
|
+
color?: FillColor;
|
|
55
|
+
}
|
|
56
|
+
interface Outline {
|
|
57
|
+
type?: string;
|
|
58
|
+
color?: FillColor;
|
|
59
|
+
width?: number;
|
|
60
|
+
dash?: string;
|
|
61
|
+
}
|
|
62
|
+
/** wps shape data (WpsShapeCoreOptions subset used for rendering). */
|
|
63
|
+
interface WpsBodyProperties {
|
|
64
|
+
rotation?: number;
|
|
65
|
+
lIns?: number;
|
|
66
|
+
tIns?: number;
|
|
67
|
+
rIns?: number;
|
|
68
|
+
bIns?: number;
|
|
69
|
+
vert?: string;
|
|
70
|
+
}
|
|
71
|
+
interface WpsData {
|
|
72
|
+
fill?: Fill;
|
|
73
|
+
outline?: Outline;
|
|
74
|
+
bodyProperties?: WpsBodyProperties & Record<string, unknown>;
|
|
75
|
+
children?: unknown[];
|
|
76
|
+
}
|
|
77
|
+
type Spec = ReadonlyArray<unknown>;
|
|
78
|
+
/** wps text-body paragraphs (office-open ParagraphOptions[]) → inline HTML runs
|
|
79
|
+
* so a text-box shape shows its text. Each paragraph's run defaults merge with
|
|
80
|
+
* each text run; renderRunStyles converts font/color/size/… to CSS. Advanced run
|
|
81
|
+
* props (shadow w14RawXml, kern) are carried in attrs but not rendered. */
|
|
82
|
+
declare function renderWpsText(children: unknown): Spec[];
|
|
83
|
+
/**
|
|
84
|
+
* Render a wps shape's interior (fill/outline/insets/rotation/writing-mode + text
|
|
85
|
+
* body) as a positioned div. Shared by the wpg group's inline wps children and
|
|
86
|
+
* the standalone wpsShape node, so a text-box shape renders identically whether
|
|
87
|
+
* it floats alone (wp:anchor > wps:wsp) or sits inside a group. `positionStyle`
|
|
88
|
+
* carries the placement — absolute group coords for a group child, the floating
|
|
89
|
+
* anchor CSS for a standalone shape. `opts.rotation` overrides bodyPr rotation
|
|
90
|
+
* (a group child's rotation may come from the group transform, not bodyPr).
|
|
91
|
+
*/
|
|
92
|
+
declare function renderWpsInterior(data: WpsData, positionStyle: string, opts?: {
|
|
93
|
+
rotation?: number;
|
|
94
|
+
attrs?: Record<string, string>;
|
|
95
|
+
}): Spec;
|
|
96
|
+
declare const WpgGroup: Node<any, any>;
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/extensions/wps-shape.d.ts
|
|
99
|
+
declare const WpsShape: Node<any, any>;
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/extensions/passthrough.d.ts
|
|
102
|
+
/**
|
|
103
|
+
* Passthrough — block atom carrying an opaque {@link SectionChild} that has
|
|
104
|
+
* no native Tiptap representation (rawXml, bookmarkStart/End, textbox,
|
|
105
|
+
* altChunk, subDoc, customXml).
|
|
106
|
+
*
|
|
107
|
+
* The full SectionChild is stored as JSON in `attrs.data` so the DOCX→JSON→DOCX
|
|
108
|
+
* round-trip stays byte-faithful: office-open's stringify handles the inner
|
|
109
|
+
* structure verbatim (including a textbox's nested children, which remain as
|
|
110
|
+
* structured ParagraphOptions inside the blob rather than editable Tiptap
|
|
111
|
+
* nodes). The node is not editable — it renders a read-only placeholder in HTML.
|
|
112
|
+
*
|
|
113
|
+
* DOCX serialization is inlined in DocxManager (compile/resolve read/write
|
|
114
|
+
* `attrs.data` directly), so no renderDocx/parseDocx is needed here.
|
|
115
|
+
*/
|
|
116
|
+
declare const Passthrough: Node<any, any>;
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/extensions/toc-field.d.ts
|
|
119
|
+
/**
|
|
120
|
+
* TOC field (`tocField`) — a block container representing a DOCX table of
|
|
121
|
+
* contents, with the rendered entries as editable `content` and the TOC field
|
|
122
|
+
* switches on `attrs.options`.
|
|
123
|
+
*
|
|
124
|
+
* Named `tocField` (not `tableOfContents`) to avoid colliding with the official
|
|
125
|
+
* `@tiptap/extension-table-of-contents`, which is an `Extension` (a live outline
|
|
126
|
+
* generator injected into the editor) that already owns the `tableOfContents`
|
|
127
|
+
* name. Same-name extensions dedupe in Tiptap, and since the official one is not
|
|
128
|
+
* a node it would erase this node type from the schema. The two coexist for
|
|
129
|
+
* different purposes: this node persists a DOCX's rendered TOC; the official
|
|
130
|
+
* extension drives the heading-outline pane.
|
|
131
|
+
*
|
|
132
|
+
* Structuring the TOC as a node (instead of opaque passthrough) is what fixes
|
|
133
|
+
* the export crash. Each entry paragraph's `w:hyperlink` wraps a HYPERLINK field
|
|
134
|
+
* whose content-less runs (fldChar begin/separate/end) office-open parses as
|
|
135
|
+
* `null`. As opaque passthrough those nulls survived verbatim to
|
|
136
|
+
* `generateDocument`, where office-open's `stringifyRunInline(null).break`
|
|
137
|
+
* crashed. Resolving the entries through `resolveParagraphChildren` drops the
|
|
138
|
+
* nulls (the existing `child !== null` guard), so compile rebuilds clean entries
|
|
139
|
+
* and the generate path never sees a null — no office-open change required.
|
|
140
|
+
*
|
|
141
|
+
* DOCX serialization is inlined in DocxManager (resolve/compile read/write
|
|
142
|
+
* `attrs.options` + the entry content directly), so no renderDocx/parseDocx is
|
|
143
|
+
* needed here — the same pattern as the details extension.
|
|
144
|
+
*/
|
|
145
|
+
declare const TocField: Node<any, any>;
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/extensions/extensions.d.ts
|
|
148
|
+
declare const tiptapNodeExtensions: AnyExtension[];
|
|
149
|
+
declare const tiptapMarkExtensions: AnyExtension[];
|
|
150
|
+
declare const docxExtensions: AnyExtension[];
|
|
151
|
+
interface DocxKitOptions {
|
|
152
|
+
bold?: Record<string, any> | false;
|
|
153
|
+
blockquote?: Record<string, any> | false;
|
|
154
|
+
bulletList?: Record<string, any> | false;
|
|
155
|
+
code?: Record<string, any> | false;
|
|
156
|
+
codeBlock?: Record<string, any> | false;
|
|
157
|
+
document?: false;
|
|
158
|
+
hardBreak?: Record<string, any> | false;
|
|
159
|
+
heading?: Record<string, any> | false;
|
|
160
|
+
horizontalRule?: Record<string, any> | false;
|
|
161
|
+
italic?: Record<string, any> | false;
|
|
162
|
+
listItem?: Record<string, any> | false;
|
|
163
|
+
link?: Record<string, any> | false;
|
|
164
|
+
orderedList?: Record<string, any> | false;
|
|
165
|
+
paragraph?: Record<string, any> | false;
|
|
166
|
+
strike?: Record<string, any> | false;
|
|
167
|
+
text?: false;
|
|
168
|
+
underline?: Record<string, any> | false;
|
|
169
|
+
}
|
|
170
|
+
declare const DocxKit: Extension<DocxKitOptions, any>;
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/extensions/page-break.d.ts
|
|
173
|
+
/**
|
|
174
|
+
* PageBreak — inline atom node for DOCX page breaks (`<w:br w:type="page"/>`).
|
|
175
|
+
*
|
|
176
|
+
* OOXML page breaks live inside a run (inline), so the Tiptap node is inline
|
|
177
|
+
* too (group "inline"). This keeps a break inside its paragraph on round-trip
|
|
178
|
+
* — a break mid-paragraph stays mid-paragraph instead of splitting the
|
|
179
|
+
* paragraph into separate blocks (which would lose the original structure).
|
|
180
|
+
* Sibling to HardBreak: both render `<w:br>`, differing only by type.
|
|
181
|
+
*
|
|
182
|
+
* The DOCX payload (`{ pageBreak: true }`) is inlined in DocxManager — a
|
|
183
|
+
* one-liner with no per-node variance, so no extension helper for it.
|
|
184
|
+
*
|
|
185
|
+
* Inserting a page break must also visually reflow (the C-route paginator only
|
|
186
|
+
* forces a new page after a block *containing* a pageBreak atom). So
|
|
187
|
+
* `setPageBreak` inserts the atom then splits the paragraph — the atom lands at
|
|
188
|
+
* the end of the first half, the trailing text becomes a fresh paragraph, and
|
|
189
|
+
* the paginator's `forcesPageBreakAfter` moves it to the next page (matching
|
|
190
|
+
* Word's Ctrl+Enter behavior).
|
|
191
|
+
*/
|
|
192
|
+
declare const PageBreak: Node<any, any>;
|
|
193
|
+
declare module "@tiptap/core" {
|
|
194
|
+
interface Commands<ReturnType> {
|
|
195
|
+
pageBreak: {
|
|
196
|
+
/** Insert a page break at the cursor and split the paragraph so the
|
|
197
|
+
* trailing content reflows to the next page. */
|
|
198
|
+
setPageBreak: () => ReturnType;
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
//#endregion
|
|
203
|
+
export { Image as C, renderDocx as E, CropRenderContext as S, renderCropAttrs as T, WpsShape as _, JSONContent$1 as a, renderWpsInterior as b, PageBreak as c, TextAlign as d, docxExtensions as f, Passthrough as g, TocField as h, Extensions as i, DocxKit as l, tiptapNodeExtensions as m, Editor as n, Mark as o, tiptapMarkExtensions as p, Extension as r, Node as s, AnyExtension as t, DocxKitOptions as u, WpgGroup as v, parseDocx as w, renderWpsText as x, WpsData as y };
|
package/dist/core.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as JSONContent,
|
|
1
|
+
import { a as JSONContent, f as docxExtensions, i as Extensions, n as Editor, o as Mark, r as Extension, s as Node, t as AnyExtension } from "./core-DRaLI8nd.mjs";
|
|
2
2
|
export { type AnyExtension, Editor, Extension, type Extensions, type JSONContent, Mark, Node, docxExtensions };
|
package/dist/core.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as Node, n as Extension, r as Mark, s as docxExtensions, t as Editor } from "./core-
|
|
1
|
+
import { i as Node, n as Extension, r as Mark, s as docxExtensions, t as Editor } from "./core-B8ba_FNi.mjs";
|
|
2
2
|
export { Editor, Extension, Mark, Node, docxExtensions };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/extensions/document.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Document extension carrying DOCX document-level data through the Tiptap JSON
|
|
4
|
+
* for lossless round-trip (declared as attrs so editor setContent → getJSON
|
|
5
|
+
* preserves them, not just the standalone converters):
|
|
6
|
+
*
|
|
7
|
+
* - `attrs.styles` — office-open `StylesOptions` (styles.xml: importedStyles /
|
|
8
|
+
* docDefaultsXml / latentStylesXml as raw XML).
|
|
9
|
+
* - `attrs.core` — docProps/core.xml properties (title/creator/description/…,
|
|
10
|
+
* see DocxCoreProperties in converters/docx.ts).
|
|
11
|
+
* - `attrs.sectionProperties` — the last section's page layout (page size/margin/
|
|
12
|
+
* orientation, columns, type, grid; intermediate sections carry theirs on
|
|
13
|
+
* sectionBreak nodes).
|
|
14
|
+
*
|
|
15
|
+
* None rendered to HTML — phase 2 applies styles via injected CSS.
|
|
16
|
+
*
|
|
17
|
+
* Factory form (`createDocument`): the editor layer needs a different top-level
|
|
18
|
+
* content expression (`doc > page+` for the C-route editing schema) but the SAME
|
|
19
|
+
* DOCX attrs. Building it via this factory keeps the Document definition in ONE
|
|
20
|
+
* place (here) — the editor parameterizes only `content`, instead of `.extend`-
|
|
21
|
+
* overriding this Document and re-stating the attrs. `Document` is the default
|
|
22
|
+
* flat `doc > block+` shape used by the docx package itself.
|
|
23
|
+
*/
|
|
24
|
+
declare function createDocument(content?: string): import("@tiptap/core").Node<any, any>;
|
|
25
|
+
/** Default flat Document (`doc > block+`) — the DOCX round-trip shape. */
|
|
26
|
+
declare const Document: import("@tiptap/core").Node<any, any>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { createDocument as n, Document as t };
|
package/dist/editor.d.mts
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { n as Editor, t as AnyExtension } from "./core-DRaLI8nd.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/editor.d.ts
|
|
4
|
+
interface DocxEditorOptions {
|
|
5
|
+
/** DOM element to mount the editor */
|
|
6
|
+
element: HTMLElement;
|
|
7
|
+
/** Additional Tiptap extensions */
|
|
8
|
+
extensions?: AnyExtension[];
|
|
9
|
+
/** Initial content (Tiptap JSON or HTML string) */
|
|
10
|
+
content?: Record<string, unknown> | string;
|
|
11
|
+
/** Enable spellcheck (disable for large documents) */
|
|
12
|
+
spellcheck?: boolean;
|
|
13
|
+
/** Editor is editable */
|
|
14
|
+
editable?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a Tiptap editor configured for DOCX editing.
|
|
18
|
+
*/
|
|
19
|
+
declare function createDocxEditor(options: DocxEditorOptions): Editor;
|
|
20
|
+
//#endregion
|
|
2
21
|
export { DocxEditorOptions, createDocxEditor };
|
package/dist/editor.mjs
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { s as docxExtensions, t as Editor } from "./core-B8ba_FNi.mjs";
|
|
2
|
+
//#region src/editor.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create a Tiptap editor configured for DOCX editing.
|
|
5
|
+
*/
|
|
6
|
+
function createDocxEditor(options) {
|
|
7
|
+
const { element, extensions: extraExtensions = [], content, spellcheck = true, editable = true } = options;
|
|
8
|
+
const extraNames = new Set(extraExtensions.map((e) => e.name).filter(Boolean));
|
|
9
|
+
return new Editor({
|
|
10
|
+
element,
|
|
11
|
+
extensions: [...docxExtensions.filter((e) => !extraNames.has(e.name)), ...extraExtensions],
|
|
12
|
+
content: content ?? {
|
|
13
|
+
type: "doc",
|
|
14
|
+
content: [{ type: "paragraph" }]
|
|
15
|
+
},
|
|
16
|
+
editable,
|
|
17
|
+
editorProps: { attributes: { spellcheck: spellcheck ? "true" : "false" } }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
2
21
|
export { createDocxEditor };
|
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Blockquote } from "./tiptap.mjs";
|
|
2
|
+
//#region src/extensions/blockquote.ts
|
|
3
|
+
/**
|
|
4
|
+
* Blockquote extension — owns the DOCX expression of a blockquote.
|
|
5
|
+
*
|
|
6
|
+
* DOCX has no blockquote element; the convention is a left indent plus a left
|
|
7
|
+
* border on each contained paragraph. This module owns that signature; the
|
|
8
|
+
* DocxManager walks the blockquote's child paragraphs and applies it to each.
|
|
9
|
+
*/
|
|
10
|
+
/** Left indent (twips, ~0.5 inch) marking a blockquote. */
|
|
11
|
+
const BLOCKQUOTE_INDENT_LEFT = 720;
|
|
12
|
+
/** Left border marking a blockquote. */
|
|
13
|
+
const BLOCKQUOTE_BORDER = {
|
|
14
|
+
style: "single",
|
|
15
|
+
size: 18,
|
|
16
|
+
space: 12,
|
|
17
|
+
color: "CCCCCC"
|
|
18
|
+
};
|
|
19
|
+
/** Apply the blockquote signature (left indent + left border) to paragraph opts. */
|
|
20
|
+
function applyBlockquoteStyle(paraObj) {
|
|
21
|
+
paraObj.indent = {
|
|
22
|
+
...paraObj.indent ?? {},
|
|
23
|
+
left: 720
|
|
24
|
+
};
|
|
25
|
+
paraObj.border = {
|
|
26
|
+
...paraObj.border ?? {},
|
|
27
|
+
left: BLOCKQUOTE_BORDER
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
3
31
|
export { BLOCKQUOTE_BORDER, BLOCKQUOTE_INDENT_LEFT, Blockquote, applyBlockquoteStyle };
|
|
@@ -1,2 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CodeBlockLowlight } from "./tiptap.mjs";
|
|
2
|
+
//#region src/extensions/code-block.ts
|
|
3
|
+
/**
|
|
4
|
+
* CodeBlock extension — CodeBlockLowlight with a DOCX renderDocx.
|
|
5
|
+
*
|
|
6
|
+
* DOCX has no dedicated code-block element. A code block maps to a single
|
|
7
|
+
* paragraph styled "Code" with a monospace run font. Inline marks (syntax-
|
|
8
|
+
* highlight tokens) and line breaks (`\n` → `<w:br/>`) are handled by
|
|
9
|
+
* DocxManager's shared inline-content compilation; resolveCodeBlock reassembles
|
|
10
|
+
* the text. This module owns only the paragraph-level style.
|
|
11
|
+
*
|
|
12
|
+
* `language` has no OOXML carrier and is intentionally dropped (known lossy).
|
|
13
|
+
*/
|
|
14
|
+
/** codeBlock node → paragraph properties (style "Code" + monospace font). */
|
|
15
|
+
function renderDocx(_node) {
|
|
16
|
+
return {
|
|
17
|
+
style: "Code",
|
|
18
|
+
run: { font: "Consolas" }
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const CodeBlock = CodeBlockLowlight.extend({ renderDocx });
|
|
22
|
+
//#endregion
|
|
2
23
|
export { CodeBlock, renderDocx };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { y as ColumnBreak } from "../core-B8ba_FNi.mjs";
|
|
2
2
|
export { ColumnBreak };
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Details, DetailsContent, DetailsSummary } from "./tiptap.mjs";
|
|
2
|
+
//#region src/extensions/details.ts
|
|
3
|
+
/**
|
|
4
|
+
* Details extension — owns the DOCX expression of a collapsible details block.
|
|
5
|
+
*
|
|
6
|
+
* DOCX has no native collapsible region, but a block-level group-SDT is a
|
|
7
|
+
* reversible container. The details maps to one group-SDT tagged "docen-
|
|
8
|
+
* details"; the summary paragraph is marked with a fixed style so resolve can
|
|
9
|
+
* split it back out from the content paragraphs. Structure round-trips fully
|
|
10
|
+
* (summary + content); Word shows it expanded (no collapse) — an inherent
|
|
11
|
+
* DOCX limitation, not data loss.
|
|
12
|
+
*/
|
|
13
|
+
/** SDT tag marking a details group content control. */
|
|
14
|
+
const DETAILS_TAG = "docen-details";
|
|
15
|
+
/** Paragraph style marking the summary line within a details group-SDT. */
|
|
16
|
+
const DETAILS_SUMMARY_STYLE = "DocenDetailsSummary";
|
|
17
|
+
//#endregion
|
|
3
18
|
export { DETAILS_SUMMARY_STYLE, DETAILS_TAG, Details, DetailsContent, DetailsSummary };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createDocument, t as Document } from "../document-
|
|
1
|
+
import { n as createDocument, t as Document } from "../document-Cws7XTYL.mjs";
|
|
2
2
|
export { Document, createDocument };
|
|
@@ -1,2 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Document as Document$1 } from "./tiptap.mjs";
|
|
2
|
+
import { attrNative } from "./utils.mjs";
|
|
3
|
+
//#region src/extensions/document.ts
|
|
4
|
+
/**
|
|
5
|
+
* Document extension carrying DOCX document-level data through the Tiptap JSON
|
|
6
|
+
* for lossless round-trip (declared as attrs so editor setContent → getJSON
|
|
7
|
+
* preserves them, not just the standalone converters):
|
|
8
|
+
*
|
|
9
|
+
* - `attrs.styles` — office-open `StylesOptions` (styles.xml: importedStyles /
|
|
10
|
+
* docDefaultsXml / latentStylesXml as raw XML).
|
|
11
|
+
* - `attrs.core` — docProps/core.xml properties (title/creator/description/…,
|
|
12
|
+
* see DocxCoreProperties in converters/docx.ts).
|
|
13
|
+
* - `attrs.sectionProperties` — the last section's page layout (page size/margin/
|
|
14
|
+
* orientation, columns, type, grid; intermediate sections carry theirs on
|
|
15
|
+
* sectionBreak nodes).
|
|
16
|
+
*
|
|
17
|
+
* None rendered to HTML — phase 2 applies styles via injected CSS.
|
|
18
|
+
*
|
|
19
|
+
* Factory form (`createDocument`): the editor layer needs a different top-level
|
|
20
|
+
* content expression (`doc > page+` for the C-route editing schema) but the SAME
|
|
21
|
+
* DOCX attrs. Building it via this factory keeps the Document definition in ONE
|
|
22
|
+
* place (here) — the editor parameterizes only `content`, instead of `.extend`-
|
|
23
|
+
* overriding this Document and re-stating the attrs. `Document` is the default
|
|
24
|
+
* flat `doc > block+` shape used by the docx package itself.
|
|
25
|
+
*/
|
|
26
|
+
function createDocument(content = "block+") {
|
|
27
|
+
return Document$1.extend({
|
|
28
|
+
content,
|
|
29
|
+
addAttributes() {
|
|
30
|
+
return {
|
|
31
|
+
...this.parent?.(),
|
|
32
|
+
styles: attrNative(),
|
|
33
|
+
core: attrNative(),
|
|
34
|
+
sectionProperties: attrNative(),
|
|
35
|
+
sectionHeaders: attrNative(),
|
|
36
|
+
sectionFooters: attrNative(),
|
|
37
|
+
background: attrNative(),
|
|
38
|
+
documentExtras: attrNative()
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/** Default flat Document (`doc > block+`) — the DOCX round-trip shape. */
|
|
44
|
+
const Document = createDocument();
|
|
45
|
+
//#endregion
|
|
2
46
|
export { Document, createDocument };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as Document } from "../document-
|
|
3
|
-
import { t as Emoji } from "../emoji-BZ1dJD7d.mjs";
|
|
1
|
+
import { A as TaskItem, F as Underline, M as Text, T as Superscript, _ as Link, a as CodeBlockLowlight, b as Mention, c as DetailsSummary, d as HardBreak, g as Italic, i as Code, j as TaskList, m as HorizontalRule, n as Bold, o as Details, p as Highlight, r as BulletList, s as DetailsContent, t as Blockquote, u as Emoji, v as ListItem, w as Subscript, x as OrderedList, y as Mathematics } from "../tiptap-pZsNPsvV.mjs";
|
|
2
|
+
import { t as Document } from "../document-Cws7XTYL.mjs";
|
|
4
3
|
import { t as Heading } from "../heading-BvqBD2zX.mjs";
|
|
5
|
-
import {
|
|
4
|
+
import { C as Image, _ as WpsShape, d as TextAlign, f as docxExtensions, g as Passthrough, h as TocField, l as DocxKit, m as tiptapNodeExtensions, p as tiptapMarkExtensions, u as DocxKitOptions, v as WpgGroup } from "../core-DRaLI8nd.mjs";
|
|
6
5
|
import { t as Paragraph } from "../paragraph-D8mpHo_o.mjs";
|
|
7
6
|
import { t as TableRow } from "../table-row-kgzYkZlW.mjs";
|
|
8
7
|
import { t as Table } from "../table-BFkfeRp9.mjs";
|
|
@@ -10,4 +9,4 @@ import { t as TableCell } from "../table-cell-D_FV4D2h.mjs";
|
|
|
10
9
|
import { t as TableHeader } from "../table-header-KGQ2aEkP.mjs";
|
|
11
10
|
import { t as Strike } from "../strike-BgWGvjKr.mjs";
|
|
12
11
|
import { t as TextStyle } from "../text-style-BHdtXkMb.mjs";
|
|
13
|
-
export { Blockquote, Bold, BulletList, Code, CodeBlockLowlight, Details, DetailsContent, DetailsSummary, Document, DocxKit, DocxKitOptions,
|
|
12
|
+
export { Blockquote, Bold, BulletList, Code, CodeBlockLowlight, Details, DetailsContent, DetailsSummary, Document, DocxKit, DocxKitOptions, Emoji, HardBreak, Heading, Highlight, HorizontalRule, Image, Italic, Link, ListItem, Mathematics, Mention, OrderedList, Paragraph, Passthrough, Strike, Subscript, Superscript, Table, TableCell, TableHeader, TableRow, TaskItem, TaskList, Text, TextAlign, TextStyle, TocField, Underline, WpgGroup, WpsShape, docxExtensions, tiptapMarkExtensions, tiptapNodeExtensions };
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as DocxKit, c as tiptapMarkExtensions, d as Passthrough, l as tiptapNodeExtensions, o as TextAlign, s as docxExtensions } from "../core-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
export { Blockquote, Bold, BulletList, Code, CodeBlockLowlight, Details, DetailsContent, DetailsSummary, Document, DocxKit, Dropcursor, Emoji, Gapcursor, HardBreak, Heading, Highlight, HorizontalRule, Image, Italic, Link, ListItem, ListKeymap, Mathematics, Mention, OrderedList, Paragraph, Passthrough, Strike, Subscript, Superscript, Table, TableCell, TableHeader, TableRow, TaskItem, TaskList, Text, TextAlign, TextStyle, TrailingNode, Underline, UndoRedo, docxExtensions, tiptapMarkExtensions, tiptapNodeExtensions };
|
|
1
|
+
import { Blockquote, Bold, BulletList, Code, CodeBlockLowlight, Details, DetailsContent, DetailsSummary, Emoji, HardBreak, Highlight, HorizontalRule, Italic, Link, ListItem, Mathematics, Mention, OrderedList, Subscript, Superscript, TaskItem, TaskList, Text, Underline } from "./tiptap.mjs";
|
|
2
|
+
import { a as DocxKit, c as tiptapMarkExtensions, d as WpgGroup, g as Passthrough, l as tiptapNodeExtensions, m as TocField, o as TextAlign, s as docxExtensions, u as WpsShape } from "../core-B8ba_FNi.mjs";
|
|
3
|
+
import { Document } from "./document.mjs";
|
|
4
|
+
import { Heading } from "./heading.mjs";
|
|
5
|
+
import { Image } from "./image.mjs";
|
|
6
|
+
import { Paragraph } from "./paragraph.mjs";
|
|
7
|
+
import { Strike } from "./strike.mjs";
|
|
8
|
+
import { Table } from "./table.mjs";
|
|
9
|
+
import { TableCell } from "./table-cell.mjs";
|
|
10
|
+
import { TableHeader } from "./table-header.mjs";
|
|
11
|
+
import { TableRow } from "./table-row.mjs";
|
|
12
|
+
import { TextStyle } from "./text-style.mjs";
|
|
13
|
+
export { Blockquote, Bold, BulletList, Code, CodeBlockLowlight, Details, DetailsContent, DetailsSummary, Document, DocxKit, Emoji, HardBreak, Heading, Highlight, HorizontalRule, Image, Italic, Link, ListItem, Mathematics, Mention, OrderedList, Paragraph, Passthrough, Strike, Subscript, Superscript, Table, TableCell, TableHeader, TableRow, TaskItem, TaskList, Text, TextAlign, TextStyle, TocField, Underline, WpgGroup, WpsShape, docxExtensions, tiptapMarkExtensions, tiptapNodeExtensions };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as Extension } from "../core-
|
|
1
|
+
import { r as Extension } from "../core-DRaLI8nd.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/extensions/formatting-marks.d.ts
|
|
4
4
|
/**
|
|
@@ -19,6 +19,12 @@ import { r as Extension } from "../core-fBMCCj4D.mjs";
|
|
|
19
19
|
* leftwards" — the Enter-key glyph). Word/WPS use the pilcrow ¶ for paragraph
|
|
20
20
|
* marks; that down-then-left arrow is Word's line-break glyph — adopted here as
|
|
21
21
|
* the paragraph mark per the project's visual preference.
|
|
22
|
+
*
|
|
23
|
+
* Performance: the widget set is cached in plugin state and rebuilt only on a
|
|
24
|
+
* doc change or a marks toggle — NOT on every selectionUpdate. Without the
|
|
25
|
+
* cache, each caret move / selection re-traverses the whole document (one
|
|
26
|
+
* widget per textblock) and rebuilds the set, which costs 200ms+ on 1000-page
|
|
27
|
+
* documents. Pure selection transactions now reuse the cached set in O(1).
|
|
22
28
|
*/
|
|
23
29
|
declare const FormattingMarks: Extension<any, any>;
|
|
24
30
|
declare module "@tiptap/core" {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v as FormattingMarks } from "../core-B8ba_FNi.mjs";
|
|
2
2
|
export { FormattingMarks };
|