@docen/docx 0.3.2 → 0.3.4
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/blockquote-DY80QC06.d.mts +21 -0
- package/dist/bullet-list-DF60pnSL.d.mts +12 -0
- package/dist/converters/docx.d.mts +25 -4
- package/dist/converters/docx.mjs +217 -41
- package/dist/converters/html.d.mts +1 -1
- package/dist/converters/html.mjs +1 -1
- package/dist/converters/markdown.d.mts +1 -1
- package/dist/converters/markdown.mjs +1 -1
- package/dist/converters/patch.d.mts +1 -1
- package/dist/converters/prepare.d.mts +1 -1
- package/dist/converters/prepare.mjs +6 -9
- package/dist/converters/styles.d.mts +7 -1
- package/dist/converters/styles.mjs +31 -8
- package/dist/{core-DT9IrTzN.mjs → core-BnF8XhVE.mjs} +229 -33
- package/dist/core-DC0_-WcE.d.mts +387 -0
- package/dist/core.d.mts +1 -1
- package/dist/core.mjs +1 -1
- package/dist/details-Dd5MqqmR.d.mts +17 -0
- package/dist/document-Cws7XTYL.d.mts +28 -0
- package/dist/editor.d.mts +1 -1
- package/dist/editor.mjs +1 -1
- package/dist/extensions/blockquote.d.mts +2 -22
- package/dist/extensions/bullet-list.d.mts +2 -0
- package/dist/extensions/bullet-list.mjs +21 -0
- package/dist/extensions/code-block.d.mts +1 -18
- package/dist/extensions/column-break.d.mts +1 -30
- package/dist/extensions/column-break.mjs +1 -1
- package/dist/extensions/details.d.mts +2 -18
- package/dist/extensions/document.d.mts +1 -1
- package/dist/extensions/document.mjs +3 -6
- package/dist/extensions/extensions.d.mts +10 -6
- package/dist/extensions/extensions.mjs +9 -4
- package/dist/extensions/formatting-marks.d.mts +1 -37
- package/dist/extensions/formatting-marks.mjs +1 -1
- package/dist/extensions/heading.mjs +31 -9
- package/dist/extensions/image.d.mts +1 -1
- package/dist/extensions/image.mjs +20 -4
- package/dist/extensions/index.d.mts +17 -4
- package/dist/extensions/index.mjs +18 -3
- package/dist/extensions/link.d.mts +2 -0
- package/dist/extensions/link.mjs +56 -0
- package/dist/extensions/mention.d.mts +2 -24
- package/dist/extensions/ordered-list.d.mts +1 -24
- package/dist/extensions/ordered-list.mjs +10 -1
- package/dist/extensions/page-break.d.mts +1 -1
- package/dist/extensions/page-break.mjs +1 -1
- package/dist/extensions/paragraph.mjs +14 -6
- package/dist/extensions/passthrough.d.mts +2 -2
- package/dist/extensions/passthrough.mjs +2 -2
- package/dist/extensions/scroll.d.mts +2 -0
- package/dist/extensions/scroll.mjs +33 -0
- package/dist/extensions/section-break.d.mts +1 -43
- package/dist/extensions/section-break.mjs +1 -1
- package/dist/extensions/strike.mjs +1 -5
- package/dist/extensions/tab.d.mts +2 -0
- package/dist/extensions/tab.mjs +2 -0
- package/dist/extensions/table-cell.mjs +3 -8
- package/dist/extensions/table-header.mjs +1 -6
- package/dist/extensions/table-row.mjs +1 -6
- package/dist/extensions/table.mjs +1 -6
- package/dist/extensions/task-item.d.mts +2 -26
- package/dist/extensions/text-style.mjs +1 -6
- package/dist/extensions/tiptap.d.mts +1 -1
- package/dist/extensions/toc-field.d.mts +2 -0
- package/dist/extensions/toc-field.mjs +2 -0
- package/dist/extensions/utils.d.mts +2 -2
- package/dist/extensions/utils.mjs +10 -1
- package/dist/extensions/wpg-group.d.mts +2 -2
- package/dist/extensions/wpg-group.mjs +2 -2
- package/dist/extensions/wps-shape.d.mts +1 -1
- package/dist/extensions/wps-shape.mjs +1 -1
- package/dist/index.d.mts +48 -11
- package/dist/index.mjs +19 -4
- package/dist/link-BawPjQZR.d.mts +6 -0
- package/dist/mention-BGLzLVYw.d.mts +23 -0
- package/dist/ordered-list-DFAe-YEV.d.mts +25 -0
- package/dist/scroll-ZNeThJsJ.d.mts +18 -0
- package/dist/task-item-B0ntvQ1Y.d.mts +25 -0
- package/dist/{tiptap-pZsNPsvV.d.mts → tiptap-BKqn41uT.d.mts} +2 -2
- package/dist/{utils-D87vukzp.d.mts → utils-BJwDQts7.d.mts} +10 -1
- package/package.json +3 -3
- package/dist/core-C9VunJ8o.d.mts +0 -174
- package/dist/document-BH1y4qHM.d.mts +0 -6
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { Blockquote, Bold,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Blockquote, Bold, Code, CodeBlockLowlight, Details, DetailsContent, DetailsSummary, Emoji, HardBreak, Highlight, HorizontalRule, Italic, ListItem, Mathematics, Mention, Subscript, Superscript, TaskItem, TaskList, Text, TextAlign, Underline } from "./tiptap.mjs";
|
|
2
|
+
import { BulletList } from "./bullet-list.mjs";
|
|
3
|
+
import { CodeBlock } from "./code-block.mjs";
|
|
4
|
+
import { C as ColumnBreak, S as FormattingMarks, _ as Tab, a as DocxKit, b as Passthrough, c as tiptapNodeExtensions, g as TocField, h as wpsShapeStyles, l as WpsShape, o as docxExtensions, s as tiptapMarkExtensions, u as WpgGroup, v as SectionBreak, x as PageBreak, y as InlinePassthrough } from "../core-BnF8XhVE.mjs";
|
|
5
|
+
import { Document, createDocument } from "./document.mjs";
|
|
4
6
|
import { Heading } from "./heading.mjs";
|
|
5
7
|
import { Image } from "./image.mjs";
|
|
8
|
+
import { scrollCaretToTop, scrollContainerOf } from "./scroll.mjs";
|
|
9
|
+
import { Link } from "./link.mjs";
|
|
10
|
+
import { OrderedList } from "./ordered-list.mjs";
|
|
6
11
|
import { Paragraph } from "./paragraph.mjs";
|
|
7
12
|
import { Strike } from "./strike.mjs";
|
|
8
13
|
import { Table } from "./table.mjs";
|
|
@@ -10,4 +15,4 @@ import { TableCell } from "./table-cell.mjs";
|
|
|
10
15
|
import { TableHeader } from "./table-header.mjs";
|
|
11
16
|
import { TableRow } from "./table-row.mjs";
|
|
12
17
|
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, Underline, WpgGroup, WpsShape, docxExtensions, tiptapMarkExtensions, tiptapNodeExtensions };
|
|
18
|
+
export { Blockquote, Bold, BulletList, Code, CodeBlock, CodeBlockLowlight, ColumnBreak, Details, DetailsContent, DetailsSummary, Document, DocxKit, Emoji, FormattingMarks, HardBreak, Heading, Highlight, HorizontalRule, Image, InlinePassthrough, Italic, Link, ListItem, Mathematics, Mention, OrderedList, PageBreak, Paragraph, Passthrough, SectionBreak, Strike, Subscript, Superscript, Tab, Table, TableCell, TableHeader, TableRow, TaskItem, TaskList, Text, TextAlign, TextStyle, TocField, Underline, WpgGroup, WpsShape, createDocument, docxExtensions, scrollCaretToTop, scrollContainerOf, tiptapMarkExtensions, tiptapNodeExtensions, wpsShapeStyles };
|
|
@@ -1,38 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/extensions/formatting-marks.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* FormattingMarks — paints the non-printing paragraph mark via ProseMirror
|
|
6
|
-
* widget decorations.
|
|
7
|
-
*
|
|
8
|
-
* CSS `p::after { content: "…" }` does NOT work on a ProseMirror-managed
|
|
9
|
-
* paragraph: the view owns the DOM and the trailing-break kludge pushes the
|
|
10
|
-
* pseudo-element off the visible line, so the mark never appears (verified).
|
|
11
|
-
* Marijn Haverbeke endorses widget decorations for exactly this use case
|
|
12
|
-
* (https://discuss.prosemirror.net/t/1442). Each textblock gets a widget at its
|
|
13
|
-
* closing position (inside the textblock, so it stays on the content's line)
|
|
14
|
-
* holding a non-editable `<span class="docen-para-mark">`. `side: 1` keeps the
|
|
15
|
-
* mark to the right of a cursor resting at the paragraph end (the cursor always
|
|
16
|
-
* precedes its own paragraph mark).
|
|
17
|
-
*
|
|
18
|
-
* Glyph: a down-then-left return arrow (↲, U+21B2 "downwards arrow with tip
|
|
19
|
-
* leftwards" — the Enter-key glyph). Word/WPS use the pilcrow ¶ for paragraph
|
|
20
|
-
* marks; that down-then-left arrow is Word's line-break glyph — adopted here as
|
|
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).
|
|
28
|
-
*/
|
|
29
|
-
declare const FormattingMarks: Extension<any, any>;
|
|
30
|
-
declare module "@tiptap/core" {
|
|
31
|
-
interface Commands<ReturnType> {
|
|
32
|
-
formattingMarks: {
|
|
33
|
-
/** Toggle the non-printing paragraph marks on or off. */toggleFormattingMarks: () => ReturnType;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
//#endregion
|
|
1
|
+
import { O as FormattingMarks } from "../core-DC0_-WcE.mjs";
|
|
38
2
|
export { FormattingMarks };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as FormattingMarks } from "../core-BnF8XhVE.mjs";
|
|
2
2
|
export { FormattingMarks };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Heading as Heading$1 } from "./tiptap.mjs";
|
|
2
|
-
import { alignmentFromElement, bordersFromElement, indentFromElement, renderParagraphStyles, shadingFromElement, spacingFromElement } from "./utils.mjs";
|
|
2
|
+
import { alignmentFromElement, attrNative, bordersFromElement, indentFromElement, renderParagraphStyles, shadingFromElement, spacingFromElement } from "./utils.mjs";
|
|
3
3
|
//#region src/extensions/heading.ts
|
|
4
4
|
/**
|
|
5
5
|
* Heading extension with nested office-open attrs (mirrors Paragraph).
|
|
@@ -17,7 +17,10 @@ const HEADING_COMPILE_MAP = {
|
|
|
17
17
|
3: "Heading3",
|
|
18
18
|
4: "Heading4",
|
|
19
19
|
5: "Heading5",
|
|
20
|
-
6: "Heading6"
|
|
20
|
+
6: "Heading6",
|
|
21
|
+
7: "Heading7",
|
|
22
|
+
8: "Heading8",
|
|
23
|
+
9: "Heading9"
|
|
21
24
|
};
|
|
22
25
|
const HEADING_PARSE_MAP = {
|
|
23
26
|
Heading1: 1,
|
|
@@ -26,6 +29,9 @@ const HEADING_PARSE_MAP = {
|
|
|
26
29
|
Heading4: 4,
|
|
27
30
|
Heading5: 5,
|
|
28
31
|
Heading6: 6,
|
|
32
|
+
Heading7: 7,
|
|
33
|
+
Heading8: 8,
|
|
34
|
+
Heading9: 9,
|
|
29
35
|
Title: 1
|
|
30
36
|
};
|
|
31
37
|
/** Runtime-only attrs the TableOfContents extension injects on each heading
|
|
@@ -35,7 +41,7 @@ const TOC_RUNTIME_KEYS = new Set(["id", "data-toc-id"]);
|
|
|
35
41
|
function renderDocx(node) {
|
|
36
42
|
const attrs = node.attrs ?? {};
|
|
37
43
|
const opts = {};
|
|
38
|
-
const level = attrs.level;
|
|
44
|
+
const level = typeof attrs.level === "number" ? attrs.level : void 0;
|
|
39
45
|
const styleId = attrs.styleId;
|
|
40
46
|
if (styleId) opts.heading = styleId;
|
|
41
47
|
else if (level) opts.heading = HEADING_COMPILE_MAP[level] ?? "Heading1";
|
|
@@ -71,12 +77,26 @@ function parseDocx(opts) {
|
|
|
71
77
|
}
|
|
72
78
|
return attrs;
|
|
73
79
|
}
|
|
74
|
-
const attrNative = () => ({
|
|
75
|
-
default: null,
|
|
76
|
-
parseHTML: () => null,
|
|
77
|
-
rendered: false
|
|
78
|
-
});
|
|
79
80
|
const Heading = Heading$1.extend({
|
|
81
|
+
parseHTML() {
|
|
82
|
+
return [{
|
|
83
|
+
tag: "h6[data-heading-level]",
|
|
84
|
+
getAttrs: (el) => {
|
|
85
|
+
const level = Number(el.getAttribute("data-heading-level"));
|
|
86
|
+
return { level: Number.isInteger(level) && level >= 1 && level <= 9 ? level : 6 };
|
|
87
|
+
}
|
|
88
|
+
}, ...[
|
|
89
|
+
1,
|
|
90
|
+
2,
|
|
91
|
+
3,
|
|
92
|
+
4,
|
|
93
|
+
5,
|
|
94
|
+
6
|
|
95
|
+
].map((level) => ({
|
|
96
|
+
tag: `h${level}`,
|
|
97
|
+
attrs: { level }
|
|
98
|
+
}))];
|
|
99
|
+
},
|
|
80
100
|
addAttributes() {
|
|
81
101
|
return {
|
|
82
102
|
...this.parent?.(),
|
|
@@ -153,8 +173,10 @@ const Heading = Heading$1.extend({
|
|
|
153
173
|
const styleId = node.attrs.styleId;
|
|
154
174
|
if (styleId) attrs.class = `docx-style-${styleId}`;
|
|
155
175
|
if (styles.length > 0) attrs.style = styles.join(";");
|
|
176
|
+
const tag = level >= 1 && level <= 6 ? `h${level}` : "h6";
|
|
177
|
+
if (level >= 7) attrs["data-heading-level"] = String(level);
|
|
156
178
|
return [
|
|
157
|
-
|
|
179
|
+
tag,
|
|
158
180
|
attrs,
|
|
159
181
|
0
|
|
160
182
|
];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as Image, M as renderCropAttrs, N as renderDocx, j as parseDocx, k as CropRenderContext } from "../core-DC0_-WcE.mjs";
|
|
2
2
|
export { CropRenderContext, Image, parseDocx, renderCropAttrs, renderDocx };
|
|
@@ -54,8 +54,8 @@ function renderDocx(node) {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
if (!imageOpts.data) return null;
|
|
57
|
-
const width = attrs.width
|
|
58
|
-
const height = attrs.height
|
|
57
|
+
const width = Number.isFinite(attrs.width) ? attrs.width : 600;
|
|
58
|
+
const height = Number.isFinite(attrs.height) ? attrs.height : 400;
|
|
59
59
|
const transformation = {
|
|
60
60
|
width: `${width}px`,
|
|
61
61
|
height: `${height}px`
|
|
@@ -164,6 +164,18 @@ function renderImageStyles(attrs) {
|
|
|
164
164
|
function isVectorImage(src) {
|
|
165
165
|
return typeof src === "string" && /^data:image\/(?:x-)?(?:emf|wmf)/i.test(src);
|
|
166
166
|
}
|
|
167
|
+
/** Remote http(s) images are lazy-loaded + async-decoded in renderHTML; data
|
|
168
|
+
* URLs (the imported-DOCX majority) have no network to defer, so they stay
|
|
169
|
+
* eager — and their load event, awaited by the editor's cap path, is not
|
|
170
|
+
* delayed by `loading="lazy"`. */
|
|
171
|
+
function isRemoteImage(src) {
|
|
172
|
+
return typeof src === "string" && /^https?:/.test(src);
|
|
173
|
+
}
|
|
174
|
+
/** Render attrs applied only to remote images (see isRemoteImage). */
|
|
175
|
+
const REMOTE_IMG_ATTRS = {
|
|
176
|
+
loading: "lazy",
|
|
177
|
+
decoding: "async"
|
|
178
|
+
};
|
|
167
179
|
/**
|
|
168
180
|
* Stamp the nested office-open attrs onto an HTML attribute map as JSON
|
|
169
181
|
* data-* pairs. Shared by the cropped-div and plain-img render branches so the
|
|
@@ -315,7 +327,8 @@ const Image = Image$1.extend({
|
|
|
315
327
|
if (floatAnchor) boxAttrs["data-float-anchor"] = floatAnchor;
|
|
316
328
|
const imgAttrs = {
|
|
317
329
|
src: attrs.src,
|
|
318
|
-
style: crop.style
|
|
330
|
+
style: crop.style,
|
|
331
|
+
...isRemoteImage(attrs.src) ? REMOTE_IMG_ATTRS : {}
|
|
319
332
|
};
|
|
320
333
|
if (attrs.alt) imgAttrs.alt = attrs.alt;
|
|
321
334
|
if (attrs.title) imgAttrs.title = attrs.title;
|
|
@@ -325,7 +338,10 @@ const Image = Image$1.extend({
|
|
|
325
338
|
["img", imgAttrs]
|
|
326
339
|
];
|
|
327
340
|
}
|
|
328
|
-
const htmlAttrs = {
|
|
341
|
+
const htmlAttrs = {
|
|
342
|
+
...HTMLAttributes,
|
|
343
|
+
...isRemoteImage(attrs.src) ? REMOTE_IMG_ATTRS : {}
|
|
344
|
+
};
|
|
329
345
|
const styles = renderImageStyles(attrs);
|
|
330
346
|
if (styles.length > 0) htmlAttrs.style = styles.join(";");
|
|
331
347
|
attachRawAttrs(htmlAttrs, attrs);
|
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { A as TaskItem, F as Underline, M as Text, N as TextAlign, T as Superscript, 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, s as DetailsContent, t as Blockquote, u as Emoji, v as ListItem, w as Subscript, y as Mathematics } from "../tiptap-BKqn41uT.mjs";
|
|
2
|
+
import { n as createDocument, t as Document } from "../document-Cws7XTYL.mjs";
|
|
3
|
+
import { t as Paragraph } from "../paragraph-D8mpHo_o.mjs";
|
|
4
|
+
import { t as Heading } from "../heading-BvqBD2zX.mjs";
|
|
5
|
+
import { t as BulletList } from "../bullet-list-DF60pnSL.mjs";
|
|
6
|
+
import { r as OrderedList } from "../ordered-list-DFAe-YEV.mjs";
|
|
7
|
+
import { A as Image, D as PageBreak, E as wpsShapeStyles, F as ColumnBreak, I as CodeBlock, O as FormattingMarks, P as SectionBreak, _ as WpsShape, b as WpsShapeStandalone, c as DocxKit, d as tiptapMarkExtensions, f as tiptapNodeExtensions, g as Passthrough, h as InlinePassthrough, l as DocxKitOptions, m as TocField, p as Tab, u as docxExtensions, v as WpgGroup, x as WpsShapeStyles } from "../core-DC0_-WcE.mjs";
|
|
8
|
+
import { t as Table } from "../table-BFkfeRp9.mjs";
|
|
9
|
+
import { t as TableRow } from "../table-row-kgzYkZlW.mjs";
|
|
10
|
+
import { t as TableCell } from "../table-cell-D_FV4D2h.mjs";
|
|
11
|
+
import { t as TableHeader } from "../table-header-KGQ2aEkP.mjs";
|
|
12
|
+
import { t as Link } from "../link-BawPjQZR.mjs";
|
|
13
|
+
import { t as Strike } from "../strike-BgWGvjKr.mjs";
|
|
14
|
+
import { t as TextStyle } from "../text-style-BHdtXkMb.mjs";
|
|
15
|
+
import { n as scrollContainerOf, t as scrollCaretToTop } from "../scroll-ZNeThJsJ.mjs";
|
|
16
|
+
import { A as twipsToMm, S as sectionMarginCss, b as resolvePageSize, x as sectionLinePitchCss, y as resolveFontName } from "../utils-BJwDQts7.mjs";
|
|
17
|
+
export { Blockquote, Bold, BulletList, Code, CodeBlock, CodeBlockLowlight, ColumnBreak, Details, DetailsContent, DetailsSummary, Document, DocxKit, DocxKitOptions, Emoji, FormattingMarks, HardBreak, Heading, Highlight, HorizontalRule, Image, InlinePassthrough, Italic, Link, ListItem, Mathematics, Mention, OrderedList, PageBreak, Paragraph, Passthrough, SectionBreak, Strike, Subscript, Superscript, Tab, Table, TableCell, TableHeader, TableRow, TaskItem, TaskList, Text, TextAlign, TextStyle, TocField, Underline, WpgGroup, WpsShape, type WpsShapeStandalone, type WpsShapeStyles, createDocument, docxExtensions, resolveFontName, resolvePageSize, scrollCaretToTop, scrollContainerOf, sectionLinePitchCss, sectionMarginCss, tiptapMarkExtensions, tiptapNodeExtensions, twipsToMm, wpsShapeStyles };
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Blockquote, Bold, Code, CodeBlockLowlight, Details, DetailsContent, DetailsSummary, Emoji, HardBreak, Highlight, HorizontalRule, Italic, ListItem, Mathematics, Mention, Subscript, Superscript, TaskItem, TaskList, Text, TextAlign, Underline } from "./tiptap.mjs";
|
|
2
|
+
import { BulletList } from "./bullet-list.mjs";
|
|
3
|
+
import { CodeBlock } from "./code-block.mjs";
|
|
4
|
+
import { C as ColumnBreak, S as FormattingMarks, _ as Tab, a as DocxKit, b as Passthrough, c as tiptapNodeExtensions, g as TocField, h as wpsShapeStyles, l as WpsShape, o as docxExtensions, s as tiptapMarkExtensions, u as WpgGroup, v as SectionBreak, x as PageBreak, y as InlinePassthrough } from "../core-BnF8XhVE.mjs";
|
|
3
5
|
import { resolveFontName, resolvePageSize, sectionLinePitchCss, sectionMarginCss, twipsToMm } from "./utils.mjs";
|
|
4
|
-
|
|
6
|
+
import { Document, createDocument } from "./document.mjs";
|
|
7
|
+
import { Heading } from "./heading.mjs";
|
|
8
|
+
import { Image } from "./image.mjs";
|
|
9
|
+
import { scrollCaretToTop, scrollContainerOf } from "./scroll.mjs";
|
|
10
|
+
import { Link } from "./link.mjs";
|
|
11
|
+
import { OrderedList } from "./ordered-list.mjs";
|
|
12
|
+
import { Paragraph } from "./paragraph.mjs";
|
|
13
|
+
import { Strike } from "./strike.mjs";
|
|
14
|
+
import { Table } from "./table.mjs";
|
|
15
|
+
import { TableCell } from "./table-cell.mjs";
|
|
16
|
+
import { TableHeader } from "./table-header.mjs";
|
|
17
|
+
import { TableRow } from "./table-row.mjs";
|
|
18
|
+
import { TextStyle } from "./text-style.mjs";
|
|
19
|
+
export { Blockquote, Bold, BulletList, Code, CodeBlock, CodeBlockLowlight, ColumnBreak, Details, DetailsContent, DetailsSummary, Document, DocxKit, Emoji, FormattingMarks, HardBreak, Heading, Highlight, HorizontalRule, Image, InlinePassthrough, Italic, Link, ListItem, Mathematics, Mention, OrderedList, PageBreak, Paragraph, Passthrough, SectionBreak, Strike, Subscript, Superscript, Tab, Table, TableCell, TableHeader, TableRow, TaskItem, TaskList, Text, TextAlign, TextStyle, TocField, Underline, WpgGroup, WpsShape, createDocument, docxExtensions, resolveFontName, resolvePageSize, scrollCaretToTop, scrollContainerOf, sectionLinePitchCss, sectionMarginCss, tiptapMarkExtensions, tiptapNodeExtensions, twipsToMm, wpsShapeStyles };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { scrollCaretToTop } from "./scroll.mjs";
|
|
2
|
+
import { Link as Link$1 } from "@tiptap/extension-link";
|
|
3
|
+
import { Plugin, PluginKey, TextSelection } from "@tiptap/pm/state";
|
|
4
|
+
//#region src/extensions/link.ts
|
|
5
|
+
/**
|
|
6
|
+
* Link — overrides {@link LinkBase}'s click behavior to match MS Word: a plain
|
|
7
|
+
* click places the caret for editing; Ctrl/Cmd+Click follows the hyperlink
|
|
8
|
+
* (in-page scroll for a `#bookmark` anchor, a new tab for an external URL).
|
|
9
|
+
*
|
|
10
|
+
* The upstream extension defaults to `openOnClick: true`, which calls
|
|
11
|
+
* `window.open(href, target)` on every plain click — opening a new tab even for
|
|
12
|
+
* internal `#` anchors. That both breaks TOC navigation and diverges from
|
|
13
|
+
* Word's "click-to-edit / Ctrl+Click-to-follow" semantics.
|
|
14
|
+
*/
|
|
15
|
+
function docxLinkClickHandler() {
|
|
16
|
+
return new Plugin({
|
|
17
|
+
key: new PluginKey("docxLinkClick"),
|
|
18
|
+
props: { handleClick(view, _pos, event) {
|
|
19
|
+
const me = event;
|
|
20
|
+
if (me.button !== 0 || !(me.ctrlKey || me.metaKey)) return false;
|
|
21
|
+
const link = me.target?.closest?.("a");
|
|
22
|
+
if (!link || !view.dom.contains(link)) return false;
|
|
23
|
+
const href = link.getAttribute("href") ?? "";
|
|
24
|
+
me.preventDefault();
|
|
25
|
+
if (href.startsWith("#")) {
|
|
26
|
+
const id = href.slice(1);
|
|
27
|
+
if (id) {
|
|
28
|
+
const dest = view.dom.querySelector(`[id="${id.replace(/["\\]/g, "\\$&")}"]`);
|
|
29
|
+
if (dest) {
|
|
30
|
+
const p = view.posAtDOM(dest, 0);
|
|
31
|
+
const { state } = view;
|
|
32
|
+
view.dispatch(state.tr.setSelection(TextSelection.create(state.doc, p)));
|
|
33
|
+
scrollCaretToTop(view);
|
|
34
|
+
view.focus();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
if (href) window.open(href, "_blank");
|
|
40
|
+
return true;
|
|
41
|
+
} }
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const Link = Link$1.extend({
|
|
45
|
+
addOptions() {
|
|
46
|
+
return {
|
|
47
|
+
...this.parent?.(),
|
|
48
|
+
openOnClick: false
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
addProseMirrorPlugins() {
|
|
52
|
+
return [...this.parent?.() ?? [], docxLinkClickHandler()];
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
//#endregion
|
|
56
|
+
export { Link };
|
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
import { b as Mention } from "../tiptap-
|
|
2
|
-
|
|
3
|
-
//#region src/extensions/mention.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Mention extension — owns the DOCX expression of an inline mention.
|
|
6
|
-
*
|
|
7
|
-
* A mention is an atom node carrying `{ id, label }`. DOCX has no mention
|
|
8
|
-
* element, but an inline text-SDT (CT_SdtRun) is a reversible carrier: the
|
|
9
|
-
* `id` rides in the SDT alias, the `label` as the SDT's run text, and a fixed
|
|
10
|
-
* tag marks the type so resolve can recover the mention. (customXml would also
|
|
11
|
-
* carry the id but triggers Word's i4i patent warning; SDT does not.)
|
|
12
|
-
*/
|
|
13
|
-
/** SDT tag marking a mention content control. */
|
|
14
|
-
declare const MENTION_TAG = "docen-mention";
|
|
15
|
-
/** Inline text-SDT carrying a mention (id in alias, label as run text). */
|
|
16
|
-
declare function createMention(id: string, label: string): Record<string, unknown>;
|
|
17
|
-
/** True if an inline SDT child carries a mention. */
|
|
18
|
-
declare function isMention(child: unknown): boolean;
|
|
19
|
-
/** Read a mention SDT → `{ id, label }`. */
|
|
20
|
-
declare function readMention(child: unknown): {
|
|
21
|
-
id: string;
|
|
22
|
-
label: string;
|
|
23
|
-
};
|
|
24
|
-
//#endregion
|
|
1
|
+
import { b as Mention } from "../tiptap-BKqn41uT.mjs";
|
|
2
|
+
import { i as readMention, n as createMention, r as isMention, t as MENTION_TAG } from "../mention-BGLzLVYw.mjs";
|
|
25
3
|
export { MENTION_TAG, Mention, createMention, isMention, readMention };
|
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LevelsOptions } from "@office-open/docx";
|
|
3
|
-
|
|
4
|
-
//#region src/extensions/ordered-list.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* OrderedList extension — owns the DOCX expression of an ordered list.
|
|
7
|
-
*
|
|
8
|
-
* A Tiptap orderedList maps to a sequence of paragraphs referencing one
|
|
9
|
-
* abstractNum (decimal). The reference is keyed by `start` so lists with the
|
|
10
|
-
* same start share a definition; DocxManager gives each list its own instance
|
|
11
|
-
* for independent counting. This module owns that abstractNum shape; DocxManager
|
|
12
|
-
* owns the cross-paragraph tree walk, start recovery, and numbering-instance
|
|
13
|
-
* bookkeeping.
|
|
14
|
-
*/
|
|
15
|
-
/** Reference prefix for generated ordered-list abstractNum definitions. */
|
|
16
|
-
declare const ORDERED_REFERENCE_PREFIX = "docen-ordered";
|
|
17
|
-
/** lvlText per nesting depth (level 0 → "%1.", … level 8 → "%9."). */
|
|
18
|
-
declare const ORDERED_LEVEL_TEXT: string[];
|
|
19
|
-
/**
|
|
20
|
-
* Build nine decimal numbering levels for an ordered list. Level 0 carries
|
|
21
|
-
* `start`; deeper levels restart at 1 (Word convention).
|
|
22
|
-
*/
|
|
23
|
-
declare function buildOrderedLevels(start: number): LevelsOptions[];
|
|
24
|
-
//#endregion
|
|
1
|
+
import { i as buildOrderedLevels, n as ORDERED_REFERENCE_PREFIX, r as OrderedList, t as ORDERED_LEVEL_TEXT } from "../ordered-list-DFAe-YEV.mjs";
|
|
25
2
|
export { ORDERED_LEVEL_TEXT, ORDERED_REFERENCE_PREFIX, OrderedList, buildOrderedLevels };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OrderedList } from "./tiptap.mjs";
|
|
1
|
+
import { OrderedList as OrderedList$1 } from "./tiptap.mjs";
|
|
2
2
|
import { LevelFormat } from "@office-open/docx";
|
|
3
3
|
//#region src/extensions/ordered-list.ts
|
|
4
4
|
/**
|
|
@@ -37,5 +37,14 @@ function buildOrderedLevels(start) {
|
|
|
37
37
|
text: ORDERED_LEVEL_TEXT[level]
|
|
38
38
|
}));
|
|
39
39
|
}
|
|
40
|
+
const OrderedList = OrderedList$1.extend({ addAttributes() {
|
|
41
|
+
return {
|
|
42
|
+
...this.parent?.(),
|
|
43
|
+
numbering: {
|
|
44
|
+
default: null,
|
|
45
|
+
rendered: false
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
} });
|
|
40
49
|
//#endregion
|
|
41
50
|
export { ORDERED_LEVEL_TEXT, ORDERED_REFERENCE_PREFIX, OrderedList, buildOrderedLevels };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as PageBreak } from "../core-DC0_-WcE.mjs";
|
|
2
2
|
export { PageBreak };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { x as PageBreak } from "../core-BnF8XhVE.mjs";
|
|
2
2
|
export { PageBreak };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Paragraph as Paragraph$1 } from "./tiptap.mjs";
|
|
2
|
-
import { alignmentFromElement, bordersFromElement, indentFromElement, renderParagraphStyles, shadingFromElement, spacingFromElement } from "./utils.mjs";
|
|
2
|
+
import { alignmentFromElement, attrNative, bordersFromElement, indentFromElement, renderParagraphStyles, shadingFromElement, spacingFromElement } from "./utils.mjs";
|
|
3
3
|
//#region src/extensions/paragraph.ts
|
|
4
4
|
/**
|
|
5
5
|
* Paragraph extension with nested office-open attrs.
|
|
@@ -14,6 +14,18 @@ const SECTION_ATTR_KEYS = new Set([
|
|
|
14
14
|
"sectionHeaders",
|
|
15
15
|
"sectionFooters"
|
|
16
16
|
]);
|
|
17
|
+
/**
|
|
18
|
+
* Whether a paragraph's tabStops include a leader (dot/underscore/hyphen/…), e.g.
|
|
19
|
+
* a TOC entry's right tab. Signals dot-leader layout to the editor CSS.
|
|
20
|
+
*/
|
|
21
|
+
function hasLeaderTabStop(tabStops) {
|
|
22
|
+
if (!Array.isArray(tabStops)) return false;
|
|
23
|
+
return tabStops.some((t) => {
|
|
24
|
+
if (!t || typeof t !== "object") return false;
|
|
25
|
+
const leader = t.leader;
|
|
26
|
+
return typeof leader === "string" && leader !== "none" && leader.length > 0;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
17
29
|
function renderDocx(node) {
|
|
18
30
|
const attrs = node.attrs ?? {};
|
|
19
31
|
const opts = {};
|
|
@@ -53,11 +65,6 @@ function parseDocx(opts) {
|
|
|
53
65
|
}
|
|
54
66
|
return attrs;
|
|
55
67
|
}
|
|
56
|
-
const attrNative = () => ({
|
|
57
|
-
default: null,
|
|
58
|
-
parseHTML: () => null,
|
|
59
|
-
rendered: false
|
|
60
|
-
});
|
|
61
68
|
const Paragraph = Paragraph$1.extend({
|
|
62
69
|
addAttributes() {
|
|
63
70
|
return {
|
|
@@ -137,6 +144,7 @@ const Paragraph = Paragraph$1.extend({
|
|
|
137
144
|
const attrs = { ...HTMLAttributes };
|
|
138
145
|
const styleId = node.attrs.styleId;
|
|
139
146
|
attrs.class = styleId ? `docx-style-${styleId}` : "docx-default";
|
|
147
|
+
if (hasLeaderTabStop(node.attrs.tabStops)) attrs.class += " docx-tab-leader";
|
|
140
148
|
if (styles.length > 0) attrs.style = styles.join(";");
|
|
141
149
|
return [
|
|
142
150
|
"p",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { Passthrough };
|
|
1
|
+
import { g as Passthrough, h as InlinePassthrough } from "../core-DC0_-WcE.mjs";
|
|
2
|
+
export { InlinePassthrough, Passthrough };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { Passthrough };
|
|
1
|
+
import { b as Passthrough, y as InlinePassthrough } from "../core-BnF8XhVE.mjs";
|
|
2
|
+
export { InlinePassthrough, Passthrough };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/extensions/scroll.ts
|
|
2
|
+
/**
|
|
3
|
+
* Scroll helpers shared by the editor and the docx engine's link-click handler,
|
|
4
|
+
* so every "jump then scroll" path (outline heading, search result, find, TOC
|
|
5
|
+
* Ctrl+Click, post-reflow caret follow) scrolls the SAME way — to the top of the
|
|
6
|
+
* viewport, Word-style. ProseMirror's default `tr.scrollIntoView()` parks the
|
|
7
|
+
* caret at the bottom edge, which reads wrong for a page/heading/TOC jump.
|
|
8
|
+
*/
|
|
9
|
+
/** Nearest scrollable ancestor of the editor surface (e.g. the docen-canvas). */
|
|
10
|
+
function scrollContainerOf(view) {
|
|
11
|
+
let el = view.dom.parentElement;
|
|
12
|
+
while (el) {
|
|
13
|
+
if (el.clientHeight > 0 && el.scrollHeight > el.clientHeight) {
|
|
14
|
+
const overflowY = getComputedStyle(el).overflowY;
|
|
15
|
+
if (overflowY === "auto" || overflowY === "scroll") return el;
|
|
16
|
+
}
|
|
17
|
+
el = el.parentElement;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
/** Scroll the caret to the TOP of the viewport when it has left the visible area
|
|
22
|
+
* (Word-style page follow). No-op while the caret stays in view, so normal
|
|
23
|
+
* typing doesn't fight the user's scroll. Replaces PM's default scrollIntoView. */
|
|
24
|
+
function scrollCaretToTop(view) {
|
|
25
|
+
const scroller = scrollContainerOf(view);
|
|
26
|
+
if (!scroller) return;
|
|
27
|
+
const margin = 64;
|
|
28
|
+
const caretTop = view.coordsAtPos(view.state.selection.head).top;
|
|
29
|
+
const rect = scroller.getBoundingClientRect();
|
|
30
|
+
if (caretTop < rect.top + margin || caretTop > rect.bottom - margin) scroller.scrollTop += caretTop - rect.top - margin;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { scrollCaretToTop, scrollContainerOf };
|
|
@@ -1,44 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/extensions/section-break.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* SectionBreak — command extension that marks a paragraph as a section boundary.
|
|
6
|
-
*
|
|
7
|
-
* OOXML sections (sectPr) attach to a section's LAST paragraph's pPr, NOT a
|
|
8
|
-
* standalone node. So this extension provides only the `setSectionBreak`
|
|
9
|
-
* command (stamps sectionProperties on the current paragraph); the paragraph
|
|
10
|
-
* extension carries the sectionProperties/sectionHeaders/sectionFooters attrs,
|
|
11
|
-
* and DocxManager splits/merges sections in compile/resolve by reading them off
|
|
12
|
-
* the paragraph.
|
|
13
|
-
*
|
|
14
|
-
* The final section's sectPr rides on doc.attrs.sectionProperties (it lives at
|
|
15
|
-
* <w:body>'s end in OOXML). Single-section documents have no section-carrying
|
|
16
|
-
* paragraph at all.
|
|
17
|
-
*
|
|
18
|
-
* Next Page semantics: `setSectionBreak` stamps sectionProperties on the current
|
|
19
|
-
* paragraph (making it the section's last paragraph) AND inserts a fresh empty
|
|
20
|
-
* paragraph after it (the next section's first paragraph), then moves the
|
|
21
|
-
* selection into that new paragraph. The page-plugin's `forcesPageBreakAfter`
|
|
22
|
-
* treats a sectionProperties-bearing paragraph as a page break, so repaginate
|
|
23
|
-
* pushes the new paragraph onto the next page — and the caret follows. This
|
|
24
|
-
* mirrors Word's "Section Break (Next Page)".
|
|
25
|
-
*
|
|
26
|
-
* Split hygiene: pressing Enter inside a section-carrying paragraph must NOT
|
|
27
|
-
* split it. A split would place the new paragraph past the section boundary —
|
|
28
|
-
* forcesPageBreakAfter then pushes it onto the next page (next section), and
|
|
29
|
-
* splitBlock would copy sectionProperties onto it (a second break mark). Word
|
|
30
|
-
* instead inserts a fresh paragraph BEFORE the section's last paragraph, so the
|
|
31
|
-
* new paragraph stays in this section and the stamped paragraph remains last.
|
|
32
|
-
* The Enter shortcut does exactly that; non-section paragraphs fall through to
|
|
33
|
-
* the default Enter unchanged.
|
|
34
|
-
*/
|
|
35
|
-
declare const SectionBreak: Extension<any, any>;
|
|
36
|
-
declare module "@tiptap/core" {
|
|
37
|
-
interface Commands<ReturnType> {
|
|
38
|
-
sectionBreak: {
|
|
39
|
-
/** Insert a Next Page section break at the current paragraph. */setSectionBreak: () => ReturnType;
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
1
|
+
import { P as SectionBreak } from "../core-DC0_-WcE.mjs";
|
|
44
2
|
export { SectionBreak };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v as SectionBreak } from "../core-BnF8XhVE.mjs";
|
|
2
2
|
export { SectionBreak };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Strike as Strike$1 } from "./tiptap.mjs";
|
|
2
|
+
import { attrNative } from "./utils.mjs";
|
|
2
3
|
//#region src/extensions/strike.ts
|
|
3
4
|
/**
|
|
4
5
|
* Strike mark extension with nested office-open attrs.
|
|
@@ -31,11 +32,6 @@ function renderDocx(attrs) {
|
|
|
31
32
|
function parseDocx(runOpts) {
|
|
32
33
|
return { doubleStrike: runOpts.doubleStrike ?? null };
|
|
33
34
|
}
|
|
34
|
-
const attrNative = () => ({
|
|
35
|
-
default: null,
|
|
36
|
-
parseHTML: () => null,
|
|
37
|
-
rendered: false
|
|
38
|
-
});
|
|
39
35
|
const Strike = Strike$1.extend({
|
|
40
36
|
addAttributes() {
|
|
41
37
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TableCell as TableCell$1 } from "./tiptap.mjs";
|
|
2
|
-
import { bordersFromElement, renderTableCellStyles, shadingFromElement } from "./utils.mjs";
|
|
2
|
+
import { attrNative, bordersFromElement, renderTableCellStyles, shadingFromElement } from "./utils.mjs";
|
|
3
3
|
//#region src/extensions/table-cell.ts
|
|
4
4
|
/**
|
|
5
5
|
* Table cell extension with nested office-open attrs.
|
|
@@ -22,9 +22,9 @@ const SKIP_KEYS = new Set([
|
|
|
22
22
|
function renderDocx(node) {
|
|
23
23
|
const attrs = node.attrs ?? {};
|
|
24
24
|
const opts = {};
|
|
25
|
-
const colspan = attrs.colspan;
|
|
25
|
+
const colspan = typeof attrs.colspan === "number" ? attrs.colspan : void 0;
|
|
26
26
|
if (colspan && colspan > 1) opts.columnSpan = colspan;
|
|
27
|
-
const rowspan = attrs.rowspan;
|
|
27
|
+
const rowspan = typeof attrs.rowspan === "number" ? attrs.rowspan : void 0;
|
|
28
28
|
if (rowspan && rowspan > 1) opts.rowSpan = rowspan;
|
|
29
29
|
const colwidth = attrs.colwidth;
|
|
30
30
|
if (colwidth && colwidth.length > 0) {
|
|
@@ -55,11 +55,6 @@ function parseDocx(opts) {
|
|
|
55
55
|
}
|
|
56
56
|
return attrs;
|
|
57
57
|
}
|
|
58
|
-
const attrNative = () => ({
|
|
59
|
-
default: null,
|
|
60
|
-
parseHTML: () => null,
|
|
61
|
-
rendered: false
|
|
62
|
-
});
|
|
63
58
|
const TableCell = TableCell$1.extend({
|
|
64
59
|
addAttributes() {
|
|
65
60
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TableHeader as TableHeader$1 } from "./tiptap.mjs";
|
|
2
|
-
import { bordersFromElement, renderTableCellStyles, shadingFromElement } from "./utils.mjs";
|
|
2
|
+
import { attrNative, bordersFromElement, renderTableCellStyles, shadingFromElement } from "./utils.mjs";
|
|
3
3
|
//#region src/extensions/table-header.ts
|
|
4
4
|
/**
|
|
5
5
|
* Table header extension with nested office-open attrs (mirrors TableCell).
|
|
@@ -55,11 +55,6 @@ function parseDocx(opts) {
|
|
|
55
55
|
}
|
|
56
56
|
return attrs;
|
|
57
57
|
}
|
|
58
|
-
const attrNative = () => ({
|
|
59
|
-
default: null,
|
|
60
|
-
parseHTML: () => null,
|
|
61
|
-
rendered: false
|
|
62
|
-
});
|
|
63
58
|
const TableHeader = TableHeader$1.extend({
|
|
64
59
|
addAttributes() {
|
|
65
60
|
return {
|