@stll/folio-core 0.43.0 → 0.44.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/ai-edits/headless.js +6 -5
- package/dist/ai-edits/index.d.ts +2 -2
- package/dist/ai-edits/index.js +2 -2
- package/dist/ai-edits/snapshot.js +13 -9
- package/dist/compare/content-alignment.js +16 -1
- package/dist/compare/inline-atoms.js +1 -1
- package/dist/compare/style-resources.js +6 -0
- package/dist/docx/appVersionNormalization.d.ts +0 -18
- package/dist/docx/blockContentParser.js +8 -0
- package/dist/docx/blockRangeMarkers.d.ts +36 -0
- package/dist/docx/blockRangeMarkers.js +59 -0
- package/dist/docx/bookmarkParser.d.ts +2 -20
- package/dist/docx/bookmarkParser.js +6 -30
- package/dist/docx/borderParser.d.ts +13 -0
- package/dist/docx/borderParser.js +71 -0
- package/dist/docx/builtInStyles.d.ts +165 -0
- package/dist/docx/builtInStyles.js +239 -0
- package/dist/docx/commentIdNormalization.d.ts +3 -1
- package/dist/docx/commentIdNormalization.js +18 -1
- package/dist/docx/commentParser.d.ts +2 -1
- package/dist/docx/commentParser.js +34 -7
- package/dist/docx/commentReferenceNormalization.d.ts +4 -1
- package/dist/docx/commentReferenceNormalization.js +23 -14
- package/dist/docx/danglingRelationshipReferences.d.ts +15 -0
- package/dist/docx/danglingRelationshipReferences.js +30 -0
- package/dist/docx/defaultParagraphStyle.d.ts +18 -1
- package/dist/docx/defaultParagraphStyle.js +23 -1
- package/dist/docx/documentParser.d.ts +2 -1
- package/dist/docx/documentParser.js +2 -2
- package/dist/docx/drawingUtils.d.ts +8 -1
- package/dist/docx/drawingUtils.js +12 -3
- package/dist/docx/fieldParser.js +3 -5
- package/dist/docx/footnoteParser.d.ts +3 -2
- package/dist/docx/footnoteParser.js +19 -4
- package/dist/docx/groupDrawingParser.js +1 -1
- package/dist/docx/headerFooterRefParser.d.ts +4 -3
- package/dist/docx/headerFooterRefParser.js +42 -12
- package/dist/docx/headerFooterReferenceNormalization.d.ts +4 -1
- package/dist/docx/headerFooterReferenceNormalization.js +5 -1
- package/dist/docx/hyperlinkParser.js +11 -15
- package/dist/docx/imageParser.d.ts +1 -1
- package/dist/docx/imageParser.js +22 -18
- package/dist/docx/imageRawXml.js +5 -5
- package/dist/docx/markupRangeMarker.d.ts +15 -0
- package/dist/docx/markupRangeMarker.js +44 -0
- package/dist/docx/noteReferenceStyles.d.ts +29 -0
- package/dist/docx/noteReferenceStyles.js +70 -0
- package/dist/docx/numberingReferenceNormalization.d.ts +4 -1
- package/dist/docx/numberingReferenceNormalization.js +20 -1
- package/dist/docx/paraIdRangeNormalization.d.ts +0 -19
- package/dist/docx/paragraphParser.js +66 -99
- package/dist/docx/paragraphPropertySource.js +1 -0
- package/dist/docx/paragraphTraversal.d.ts +37 -1
- package/dist/docx/paragraphTraversal.js +84 -1
- package/dist/docx/parseContext.d.ts +37 -0
- package/dist/docx/parseContext.js +67 -0
- package/dist/docx/parseWarningMessage.d.ts +6 -0
- package/dist/docx/parseWarningMessage.js +44 -0
- package/dist/docx/parser.js +81 -27
- package/dist/docx/relsParser.d.ts +28 -11
- package/dist/docx/relsParser.js +26 -13
- package/dist/docx/revisionIdNormalization.js +81 -7
- package/dist/docx/rezip.js +63 -22
- package/dist/docx/runConsolidator.js +1 -2
- package/dist/docx/runParser.d.ts +8 -1
- package/dist/docx/runParser.js +30 -48
- package/dist/docx/sectionParser.d.ts +2 -1
- package/dist/docx/sectionParser.js +21 -65
- package/dist/docx/serializer/borderSerializer.d.ts +1 -2
- package/dist/docx/serializer/commentSerializer.js +22 -9
- package/dist/docx/serializer/documentSerializer.d.ts +1 -5
- package/dist/docx/serializer/documentSerializer.js +6 -16
- package/dist/docx/serializer/headerFooterSerializer.js +5 -0
- package/dist/docx/serializer/markupRangeAttributes.d.ts +8 -0
- package/dist/docx/serializer/markupRangeAttributes.js +24 -0
- package/dist/docx/serializer/noteSerializer.js +5 -0
- package/dist/docx/serializer/paragraphSerializer.d.ts +1 -5
- package/dist/docx/serializer/paragraphSerializer.js +29 -35
- package/dist/docx/serializer/runSerializer.js +13 -7
- package/dist/docx/serializer/tableSerializer.js +28 -13
- package/dist/docx/serializer/textFormattingSerializer.d.ts +2 -3
- package/dist/docx/server/build.js +8 -1
- package/dist/docx/server/createBilingualDocument.js +10 -18
- package/dist/docx/server/extractDocxText.js +3 -4
- package/dist/docx/shadingParser.d.ts +6 -0
- package/dist/docx/shadingParser.js +32 -0
- package/dist/docx/shapeParser.js +3 -3
- package/dist/docx/styleParser.js +13 -87
- package/dist/docx/styleReferenceResolution.d.ts +36 -0
- package/dist/docx/styleReferenceResolution.js +51 -0
- package/dist/docx/tableLook.d.ts +57 -0
- package/dist/docx/tableLook.js +63 -0
- package/dist/docx/tableParser.d.ts +7 -9
- package/dist/docx/tableParser.js +64 -110
- package/dist/docx/textBoxParser.js +4 -4
- package/dist/docx/trackedMoveRangeNormalization.d.ts +3 -1
- package/dist/docx/trackedMoveRangeNormalization.js +11 -21
- package/dist/docx/transitionalSpelling.d.ts +13 -2
- package/dist/docx/transitionalSpelling.js +23 -1
- package/dist/docx/verbatimCapture.js +4 -11
- package/dist/docx/vmlImageParser.js +2 -2
- package/dist/docx/watermarkParser.js +2 -2
- package/dist/docx/xmlParser.d.ts +22 -32
- package/dist/docx/xmlParser.js +36 -21
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +2 -1
- package/dist/internal/paragraphFormattingSerialization.d.ts +2 -3
- package/dist/internal/paragraphFormattingSerialization.js +26 -6
- package/dist/layout-bridge/convert/footnoteLayout.js +2 -7
- package/dist/layout-engine/index.d.ts +2 -2
- package/dist/layout-engine/index.js +2 -2
- package/dist/layout-engine/measure/measureBlocks.js +1 -6
- package/dist/layout-engine/types.d.ts +8 -2
- package/dist/layout-engine/types.js +35 -2
- package/dist/markdown/index.js +1 -1
- package/dist/markdown/internals.d.ts +6 -1
- package/dist/markdown/internals.js +14 -1
- package/dist/markdown/renderBlock.js +35 -21
- package/dist/markdown/renderParagraph.js +14 -5
- package/dist/markdown/renderRuns.js +4 -3
- package/dist/markdown/renderTable.js +4 -3
- package/dist/markdown/trailers.js +41 -7
- package/dist/markdown/types.d.ts +3 -7
- package/dist/prosemirror/attrs/index.js +2 -5
- package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +11 -1
- package/dist/prosemirror/bookmarkBoundaryAttrs.js +18 -3
- package/dist/prosemirror/commands/index.d.ts +3 -3
- package/dist/prosemirror/commands/index.js +2 -2
- package/dist/prosemirror/commands/paragraph.d.ts +3 -3
- package/dist/prosemirror/commands/paragraph.js +2 -2
- package/dist/prosemirror/commentIdAllocator.js +2 -7
- package/dist/prosemirror/conversion/fromProseDoc.js +129 -40
- package/dist/prosemirror/conversion/toProseDoc.d.ts +1 -14
- package/dist/prosemirror/conversion/toProseDoc.js +375 -316
- package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +14 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +11 -6
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +3 -3
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +4 -1
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +6 -2
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.d.ts +7 -0
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +74 -0
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +11 -3
- package/dist/prosemirror/extensions/marks/markUtils.js +98 -19
- package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +7 -3
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/ShapeExtension.js +1 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.js +15 -1
- package/dist/prosemirror/extensions/types.d.ts +2 -2
- package/dist/prosemirror/index.d.ts +3 -3
- package/dist/prosemirror/index.js +3 -3
- package/dist/prosemirror/insertOperations.d.ts +9 -2
- package/dist/prosemirror/insertOperations.js +9 -4
- package/dist/prosemirror/paragraphFormattingProvenance.d.ts +159 -0
- package/dist/prosemirror/paragraphFormattingProvenance.js +106 -0
- package/dist/prosemirror/plugins/documentStyles.d.ts +9 -1
- package/dist/prosemirror/plugins/documentStyles.js +11 -1
- package/dist/prosemirror/plugins/index.d.ts +2 -2
- package/dist/prosemirror/plugins/index.js +2 -2
- package/dist/prosemirror/plugins/revisionIds.d.ts +11 -2
- package/dist/prosemirror/plugins/revisionIds.js +21 -6
- package/dist/prosemirror/runFormattingReconciliation.js +3 -2
- package/dist/prosemirror/runStyleFormatting.d.ts +1 -1
- package/dist/prosemirror/schema/nodes.d.ts +31 -0
- package/dist/prosemirror/styles/resolvedStyleAttrs.js +2 -0
- package/dist/prosemirror/styles/styleResolver.d.ts +9 -0
- package/dist/prosemirror/styles/styleResolver.js +12 -0
- package/dist/style-engine/styleEngine.d.ts +3 -0
- package/dist/style-engine/styleEngine.js +3 -0
- package/dist/style-sets/extract.js +1 -23
- package/dist/style-sets/stellaStyle.js +46 -39
- package/dist/style-sets/styleSetNormalization.d.ts +19 -0
- package/dist/style-sets/styleSetNormalization.js +99 -0
- package/dist/types/content.d.ts +2 -2
- package/dist/utils/createDocument.js +145 -20
- package/dist/utils/headingCollector.d.ts +8 -5
- package/dist/utils/headingCollector.js +23 -25
- package/dist/utils/tableOfContentsStyle.js +9 -2
- package/package.json +2 -2
- package/dist/docx/textWhitespace.d.ts +0 -4
- package/dist/docx/textWhitespace.js +0 -4
- package/dist/layout-bridge/engine/tableWidthUtils.d.ts +0 -6
- package/dist/layout-bridge/engine/tableWidthUtils.js +0 -25
- package/dist/markdown/headings.d.ts +0 -13
- package/dist/markdown/headings.js +0 -20
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { escapeLinkUrl } from "./escape.js";
|
|
2
2
|
import { renderBlocks } from "./renderBlock.js";
|
|
3
|
+
import { panic } from "better-result";
|
|
3
4
|
//#region src/markdown/trailers.ts
|
|
4
5
|
/**
|
|
6
|
+
* Trailer sections appended after the document body: footnote definitions, the
|
|
7
|
+
* hyperlink reference list (`hyperlinks: "reference"`), and the comments
|
|
8
|
+
* sidecar (`comments: "sidecar"`). Split out of `internals` so the renderers
|
|
9
|
+
* can import `pushWarning` without pulling in `renderBlock` (which would form an
|
|
10
|
+
* import cycle). Ported from eigenpal/docx-editor PR #595.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
5
13
|
* Append footnote definitions, the hyperlink reference list (for
|
|
6
14
|
* `hyperlinks: "reference"`), and the comments sidecar block (for
|
|
7
15
|
* `comments: "sidecar"`). Each section is emitted only when its corresponding
|
|
@@ -41,13 +49,39 @@ function runText(run) {
|
|
|
41
49
|
/** Flatten paragraph inline content to plain text, recursing through wrappers. */
|
|
42
50
|
function inlineText(content) {
|
|
43
51
|
let out = "";
|
|
44
|
-
for (const item of content)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
for (const item of content) switch (item.type) {
|
|
53
|
+
case "run":
|
|
54
|
+
out += runText(item);
|
|
55
|
+
break;
|
|
56
|
+
case "hyperlink":
|
|
57
|
+
for (const child of item.children) if (child.type === "run") out += runText(child);
|
|
58
|
+
break;
|
|
59
|
+
case "complexField":
|
|
60
|
+
out += inlineText(item.fieldResult);
|
|
61
|
+
break;
|
|
62
|
+
case "simpleField":
|
|
63
|
+
case "insertion":
|
|
64
|
+
case "deletion":
|
|
65
|
+
case "moveFrom":
|
|
66
|
+
case "moveTo":
|
|
67
|
+
case "inlineSdt":
|
|
68
|
+
case "bidiWrapper":
|
|
69
|
+
out += inlineText(item.content);
|
|
70
|
+
break;
|
|
71
|
+
case "mathEquation":
|
|
72
|
+
out += item.plainText ?? "";
|
|
73
|
+
break;
|
|
74
|
+
case "bookmarkStart":
|
|
75
|
+
case "bookmarkEnd":
|
|
76
|
+
case "commentRangeStart":
|
|
77
|
+
case "commentRangeEnd":
|
|
78
|
+
case "commentReference":
|
|
79
|
+
case "moveFromRangeStart":
|
|
80
|
+
case "moveFromRangeEnd":
|
|
81
|
+
case "moveToRangeStart":
|
|
82
|
+
case "moveToRangeEnd": break;
|
|
83
|
+
default: panic(`Unsupported paragraph content in trailer text: ${JSON.stringify(item)}`);
|
|
84
|
+
}
|
|
51
85
|
return out;
|
|
52
86
|
}
|
|
53
87
|
//#endregion
|
package/dist/markdown/types.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
+
import { BuiltInStyleIndex } from "../docx/builtInStyles.js";
|
|
1
2
|
//#region src/markdown/types.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Types for the DOCX-document → Markdown converter (ported from eigenpal
|
|
4
|
-
* /docx-editor PR #595). This is folio's v1 surface: the synchronous,
|
|
5
|
-
* continuous (non-paged) `toMarkdown(Document)` path. The paged + async +
|
|
6
|
-
* image-handler variants from upstream are not ported (skills bodies have no
|
|
7
|
-
* images today); they can be added later if needed.
|
|
8
|
-
*/
|
|
9
3
|
/**
|
|
10
4
|
* Metadata describing a single image registration. Owned by the markdown
|
|
11
5
|
* module so its public surface is independent of the docx model's drawing
|
|
@@ -134,6 +128,8 @@ type RenderContext = {
|
|
|
134
128
|
listCounters: Map<number, number[]>;
|
|
135
129
|
/** `numId:level` pairs already seen, so a start override applies once. */
|
|
136
130
|
listSeenLevels: Set<string>;
|
|
131
|
+
/** The document's styles indexed by the built-in they are; classifies headings and quotes. */
|
|
132
|
+
builtInStyles: BuiltInStyleIndex;
|
|
137
133
|
};
|
|
138
134
|
//#endregion
|
|
139
135
|
export { ImageMeta, ImageRef, MarkdownOptions, MarkdownResult, RenderContext, ResolvedOptions };
|
|
@@ -292,11 +292,7 @@ const readSymbolAttrs = (node) => {
|
|
|
292
292
|
expectNodeType(node, "symbol", issues);
|
|
293
293
|
requiredString(attrs, "font", "symbol.attrs.font", issues);
|
|
294
294
|
requiredString(attrs, "char", "symbol.attrs.char", issues);
|
|
295
|
-
if (typeof attrs["
|
|
296
|
-
path: "symbol.attrs.font",
|
|
297
|
-
message: "Expected a non-empty font name."
|
|
298
|
-
});
|
|
299
|
-
if (typeof attrs["char"] === "string" && !isOoxmlSymbolCharacter(attrs["char"])) issues.push({
|
|
295
|
+
if (typeof attrs["char"] === "string" && attrs["char"] !== "" && !isOoxmlSymbolCharacter(attrs["char"])) issues.push({
|
|
300
296
|
path: "symbol.attrs.char",
|
|
301
297
|
message: "Expected exactly four hexadecimal digits."
|
|
302
298
|
});
|
|
@@ -1645,6 +1641,7 @@ const validateParagraphFormatting = (value, path, issues) => {
|
|
|
1645
1641
|
]) optionalNumber(value, key, `${path}.${key}`, issues);
|
|
1646
1642
|
optionalOneOf(value, "lineSpacingRule", `${path}.lineSpacingRule`, issues, LINE_SPACING_RULE_VALUES);
|
|
1647
1643
|
optionalString(value, "styleId", `${path}.styleId`, issues);
|
|
1644
|
+
optionalString(value, "numberingChangeXml", `${path}.numberingChangeXml`, issues);
|
|
1648
1645
|
optionalOneOf(value, "listNumFmt", `${path}.listNumFmt`, issues, NUMBER_FORMAT_VALUES);
|
|
1649
1646
|
optionalString(value, "listMarker", `${path}.listMarker`, issues);
|
|
1650
1647
|
optionalString(value, "listMarkerTemplate", `${path}.listMarkerTemplate`, issues);
|
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
import { document_d_exports } from "../types/document.js";
|
|
1
2
|
import { BookmarkBoundaryAttrs } from "./schema/nodes.js";
|
|
2
3
|
import { ReadProseMirrorAttrsResult } from "./attrs/index.js";
|
|
3
4
|
import { Node } from "prosemirror-model";
|
|
4
5
|
//#region src/prosemirror/bookmarkBoundaryAttrs.d.ts
|
|
6
|
+
declare const isDisplacedByCustomXml: (value: unknown) => value is document_d_exports.DisplacedByCustomXml;
|
|
7
|
+
/**
|
|
8
|
+
* A boundary's `w:displacedByCustomXml`, as a fragment to spread into the model
|
|
9
|
+
* content it rebuilds. Both a start and an end may carry it, so the callers
|
|
10
|
+
* that build either one share this rather than each remembering the attribute.
|
|
11
|
+
*/
|
|
12
|
+
declare const bookmarkBoundaryDisplacement: (attrs: BookmarkBoundaryAttrs) => {
|
|
13
|
+
displacedByCustomXml?: document_d_exports.DisplacedByCustomXml;
|
|
14
|
+
};
|
|
5
15
|
declare const readBookmarkBoundaryAttrs: (node: Node) => ReadProseMirrorAttrsResult<BookmarkBoundaryAttrs>;
|
|
6
16
|
declare const expectBookmarkBoundaryAttrs: (node: Node) => BookmarkBoundaryAttrs;
|
|
7
17
|
//#endregion
|
|
8
|
-
export { expectBookmarkBoundaryAttrs, readBookmarkBoundaryAttrs };
|
|
18
|
+
export { bookmarkBoundaryDisplacement, expectBookmarkBoundaryAttrs, isDisplacedByCustomXml, readBookmarkBoundaryAttrs };
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { panic } from "better-result";
|
|
2
2
|
//#region src/prosemirror/bookmarkBoundaryAttrs.ts
|
|
3
|
+
const isDisplacedByCustomXml = (value) => value === "next" || value === "prev";
|
|
3
4
|
const attrsCache = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
/**
|
|
6
|
+
* A boundary's `w:displacedByCustomXml`, as a fragment to spread into the model
|
|
7
|
+
* content it rebuilds. Both a start and an end may carry it, so the callers
|
|
8
|
+
* that build either one share this rather than each remembering the attribute.
|
|
9
|
+
*/
|
|
10
|
+
const bookmarkBoundaryDisplacement = (attrs) => attrs.displacedByCustomXml === void 0 ? {} : { displacedByCustomXml: attrs.displacedByCustomXml };
|
|
4
11
|
const readBookmarkBoundaryAttrs = (node) => {
|
|
5
12
|
const issues = [];
|
|
6
13
|
if (node.type.name !== "bookmarkBoundary") issues.push({
|
|
@@ -32,10 +39,16 @@ const readBookmarkBoundaryAttrs = (node) => {
|
|
|
32
39
|
path: "bookmarkBoundary.attrs.colLast",
|
|
33
40
|
message: "Expected a non-negative integer."
|
|
34
41
|
});
|
|
42
|
+
const displaced = node.attrs["displacedByCustomXml"];
|
|
43
|
+
if (displaced !== void 0 && displaced !== null && !isDisplacedByCustomXml(displaced)) issues.push({
|
|
44
|
+
path: "bookmarkBoundary.attrs.displacedByCustomXml",
|
|
45
|
+
message: "Expected \"next\" or \"prev\"."
|
|
46
|
+
});
|
|
35
47
|
if (issues.length > 0 || typeof id !== "number") return {
|
|
36
48
|
ok: false,
|
|
37
49
|
issues
|
|
38
50
|
};
|
|
51
|
+
const displacement = isDisplacedByCustomXml(displaced) ? { displacedByCustomXml: displaced } : {};
|
|
39
52
|
if (type === "start" && typeof name === "string") return {
|
|
40
53
|
ok: true,
|
|
41
54
|
value: {
|
|
@@ -43,14 +56,16 @@ const readBookmarkBoundaryAttrs = (node) => {
|
|
|
43
56
|
id,
|
|
44
57
|
name,
|
|
45
58
|
...typeof colFirst === "number" ? { colFirst } : {},
|
|
46
|
-
...typeof colLast === "number" ? { colLast } : {}
|
|
59
|
+
...typeof colLast === "number" ? { colLast } : {},
|
|
60
|
+
...displacement
|
|
47
61
|
}
|
|
48
62
|
};
|
|
49
63
|
return {
|
|
50
64
|
ok: true,
|
|
51
65
|
value: {
|
|
52
66
|
type: "end",
|
|
53
|
-
id
|
|
67
|
+
id,
|
|
68
|
+
...displacement
|
|
54
69
|
}
|
|
55
70
|
};
|
|
56
71
|
};
|
|
@@ -63,4 +78,4 @@ const expectBookmarkBoundaryAttrs = (node) => {
|
|
|
63
78
|
return result.value;
|
|
64
79
|
};
|
|
65
80
|
//#endregion
|
|
66
|
-
export { expectBookmarkBoundaryAttrs, readBookmarkBoundaryAttrs };
|
|
81
|
+
export { bookmarkBoundaryDisplacement, expectBookmarkBoundaryAttrs, isDisplacedByCustomXml, readBookmarkBoundaryAttrs };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResolvedStyleAttrs, getParagraphAlignment, getParagraphBidi, getStyleId } from "../extensions/core/ParagraphExtension.js";
|
|
1
|
+
import { GenerateTableOfContentsOptions, ResolvedStyleAttrs, getParagraphAlignment, getParagraphBidi, getStyleId } from "../extensions/core/ParagraphExtension.js";
|
|
2
2
|
import { BorderPreset, TableBorderPreset, TableContextInfo, getTableContext, isInTable as isInTableCell } from "../extensions/nodes/TableExtension.js";
|
|
3
3
|
import { AcceptSuggestionOptions, FolioSuggestion, SuggestionAppliedAs, SuggestionKind, acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addCommentMark, findAIEditRevisionRange, findNextChange, findPreviousChange, findSuggestionRange, getSuggestions, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark } from "./comments.js";
|
|
4
4
|
import { CapturedTextFormatting, PAINTABLE_MARK_NAMES, applyFormatMarks, captureFormatMarks } from "./formatPainter.js";
|
|
@@ -6,8 +6,8 @@ import { clearFormatting, createRemoveMarkCommand, createSetMarkCommand, getMark
|
|
|
6
6
|
import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "../extensions/marks/HyperlinkExtension.js";
|
|
7
7
|
import { clearFontFamily, clearFontSize, clearHighlight, clearTextColor, insertHyperlink, removeHyperlink, setFontFamily, setFontSize, setHighlight, setHyperlink, setTextColor, setUnderlineStyle, toggleBold, toggleItalic, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline } from "./formatting.js";
|
|
8
8
|
import { getListInfo, isInList } from "../extensions/features/ListExtension.js";
|
|
9
|
-
import { addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyle, clearStyle, decreaseIndent, decreaseListLevel, doubleSpacing,
|
|
9
|
+
import { addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyle, clearStyle, decreaseIndent, decreaseListLevel, doubleSpacing, generateTableOfContents, increaseIndent, increaseListLevel, oneAndHalfSpacing, removeList, removeTabStop, setAlignment, setIndentFirstLine, setIndentLeft, setIndentRight, setLineSpacing, setLtr, setRtl, setSpaceAfter, setSpaceBefore, singleSpacing, toggleBidi, toggleBulletList, toggleNumberedList } from "./paragraph.js";
|
|
10
10
|
import { addColumnLeft, addColumnRight, addRowAbove, addRowBelow, applyTableStyle, autoFitContents, deleteColumn, deleteRow, deleteTable, distributeColumns, insertTable, mergeCells, removeTableBorders, selectColumn, selectRow, selectTable, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setInsideTableBorders, setOutsideTableBorders, setRowHeight, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, splitCell, toggleHeaderRow, toggleNoWrap } from "./table.js";
|
|
11
11
|
import { insertPageBreak } from "./pageBreak.js";
|
|
12
12
|
import { CLIPBOARD_READ_ERROR_EVENT, buildPlainTextSlice, pasteWithoutFormatting } from "./pastePlainText.js";
|
|
13
|
-
export { type AcceptSuggestionOptions, type BorderPreset, CLIPBOARD_READ_ERROR_EVENT, type CapturedTextFormatting, type FolioSuggestion, PAINTABLE_MARK_NAMES, type ResolvedStyleAttrs, type SuggestionAppliedAs, type SuggestionKind, type TableBorderPreset, type TableContextInfo, acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addColumnLeft, addColumnRight, addCommentMark, addRowAbove, addRowBelow, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyFormatMarks, applyStyle, applyTableStyle, autoFitContents, buildPlainTextSlice, captureFormatMarks, clearFontFamily, clearFontSize, clearFormatting, clearHighlight, clearStyle, clearTextColor, createRemoveMarkCommand, createSetMarkCommand, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, doubleSpacing, findAIEditRevisionRange, findNextChange, findPreviousChange, findSuggestionRange,
|
|
13
|
+
export { type AcceptSuggestionOptions, type BorderPreset, CLIPBOARD_READ_ERROR_EVENT, type CapturedTextFormatting, type FolioSuggestion, type GenerateTableOfContentsOptions, PAINTABLE_MARK_NAMES, type ResolvedStyleAttrs, type SuggestionAppliedAs, type SuggestionKind, type TableBorderPreset, type TableContextInfo, acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addColumnLeft, addColumnRight, addCommentMark, addRowAbove, addRowBelow, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyFormatMarks, applyStyle, applyTableStyle, autoFitContents, buildPlainTextSlice, captureFormatMarks, clearFontFamily, clearFontSize, clearFormatting, clearHighlight, clearStyle, clearTextColor, createRemoveMarkCommand, createSetMarkCommand, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, doubleSpacing, findAIEditRevisionRange, findNextChange, findPreviousChange, findSuggestionRange, generateTableOfContents, getHyperlinkAttrs, getListInfo, getMarkAttr, getParagraphAlignment, getParagraphBidi, getSelectedText, getStyleId, getSuggestions, getTableContext, increaseIndent, increaseListLevel, insertHyperlink, insertPageBreak, insertTable, isHyperlinkActive, isInList, isInTableCell as isInTable, isMarkActive, mergeCells, oneAndHalfSpacing, pasteWithoutFormatting, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark, removeHyperlink, removeList, removeTabStop, removeTableBorders, selectColumn, selectRow, selectTable, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setHyperlink, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setOutsideTableBorders, setRowHeight, setRtl, setSpaceAfter, setSpaceBefore, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, setTextColor, setUnderlineStyle, singleSpacing, splitCell, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline };
|
|
@@ -7,7 +7,7 @@ import { acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptCha
|
|
|
7
7
|
import { PAINTABLE_MARK_NAMES, applyFormatMarks, captureFormatMarks } from "./formatPainter.js";
|
|
8
8
|
import { clearFontFamily, clearFontSize, clearHighlight, clearTextColor, insertHyperlink, removeHyperlink, setFontFamily, setFontSize, setHighlight, setHyperlink, setTextColor, setUnderlineStyle, toggleBold, toggleItalic, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline } from "./formatting.js";
|
|
9
9
|
import { insertPageBreak } from "./pageBreak.js";
|
|
10
|
-
import { addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyle, clearStyle, decreaseIndent, decreaseListLevel, doubleSpacing,
|
|
10
|
+
import { addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyle, clearStyle, decreaseIndent, decreaseListLevel, doubleSpacing, generateTableOfContents, increaseIndent, increaseListLevel, oneAndHalfSpacing, removeList, removeTabStop, setAlignment, setIndentFirstLine, setIndentLeft, setIndentRight, setLineSpacing, setLtr, setRtl, setSpaceAfter, setSpaceBefore, singleSpacing, toggleBidi, toggleBulletList, toggleNumberedList } from "./paragraph.js";
|
|
11
11
|
import { CLIPBOARD_READ_ERROR_EVENT, buildPlainTextSlice, pasteWithoutFormatting } from "./pastePlainText.js";
|
|
12
12
|
import { addColumnLeft, addColumnRight, addRowAbove, addRowBelow, applyTableStyle, autoFitContents, deleteColumn, deleteRow, deleteTable, distributeColumns, insertTable, mergeCells, removeTableBorders, selectColumn, selectRow, selectTable, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setInsideTableBorders, setOutsideTableBorders, setRowHeight, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, splitCell, toggleHeaderRow, toggleNoWrap } from "./table.js";
|
|
13
|
-
export { CLIPBOARD_READ_ERROR_EVENT, PAINTABLE_MARK_NAMES, acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addColumnLeft, addColumnRight, addCommentMark, addRowAbove, addRowBelow, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyFormatMarks, applyStyle, applyTableStyle, autoFitContents, buildPlainTextSlice, captureFormatMarks, clearFontFamily, clearFontSize, clearFormatting, clearHighlight, clearStyle, clearTextColor, createRemoveMarkCommand, createSetMarkCommand, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, doubleSpacing, findAIEditRevisionRange, findNextChange, findPreviousChange, findSuggestionRange,
|
|
13
|
+
export { CLIPBOARD_READ_ERROR_EVENT, PAINTABLE_MARK_NAMES, acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addColumnLeft, addColumnRight, addCommentMark, addRowAbove, addRowBelow, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyFormatMarks, applyStyle, applyTableStyle, autoFitContents, buildPlainTextSlice, captureFormatMarks, clearFontFamily, clearFontSize, clearFormatting, clearHighlight, clearStyle, clearTextColor, createRemoveMarkCommand, createSetMarkCommand, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, doubleSpacing, findAIEditRevisionRange, findNextChange, findPreviousChange, findSuggestionRange, generateTableOfContents, getHyperlinkAttrs, getListInfo, getMarkAttr, getParagraphAlignment, getParagraphBidi, getSelectedText, getStyleId, getSuggestions, getTableContext, increaseIndent, increaseListLevel, insertHyperlink, insertPageBreak, insertTable, isHyperlinkActive, isInList, isInTableCell as isInTable, isMarkActive, mergeCells, oneAndHalfSpacing, pasteWithoutFormatting, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark, removeHyperlink, removeList, removeTabStop, removeTableBorders, selectColumn, selectRow, selectTable, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setHyperlink, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setOutsideTableBorders, setRowHeight, setRtl, setSpaceAfter, setSpaceBefore, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, setTextColor, setUnderlineStyle, singleSpacing, splitCell, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { document_d_exports } from "../../types/document.js";
|
|
2
|
-
import { ResolvedStyleAttrs, getParagraphAlignment, getParagraphBidi, getParagraphTabs, getStyleId } from "../extensions/core/ParagraphExtension.js";
|
|
2
|
+
import { GenerateTableOfContentsOptions, ResolvedStyleAttrs, getParagraphAlignment, getParagraphBidi, getParagraphTabs, getStyleId } from "../extensions/core/ParagraphExtension.js";
|
|
3
3
|
import { getListInfo, isInList } from "../extensions/features/ListExtension.js";
|
|
4
4
|
import { Command } from "prosemirror-state";
|
|
5
5
|
//#region src/prosemirror/commands/paragraph.d.ts
|
|
@@ -33,6 +33,6 @@ declare function removeTabStop(position: number): Command;
|
|
|
33
33
|
declare const toggleBidi: Command;
|
|
34
34
|
declare const setRtl: Command;
|
|
35
35
|
declare const setLtr: Command;
|
|
36
|
-
declare const
|
|
36
|
+
declare const generateTableOfContents: (options: GenerateTableOfContentsOptions) => Command;
|
|
37
37
|
//#endregion
|
|
38
|
-
export { type ResolvedStyleAttrs, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyle, clearStyle, decreaseIndent, decreaseListLevel, doubleSpacing,
|
|
38
|
+
export { type GenerateTableOfContentsOptions, type ResolvedStyleAttrs, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyle, clearStyle, decreaseIndent, decreaseListLevel, doubleSpacing, generateTableOfContents, getListInfo, getParagraphAlignment, getParagraphBidi, getParagraphTabs, getStyleId, increaseIndent, increaseListLevel, insertSectionBreak, isInList, oneAndHalfSpacing, removeList, removeSectionBreak, removeTabStop, setAlignment, setIndentFirstLine, setIndentLeft, setIndentRight, setLineSpacing, setLtr, setRtl, setSpaceAfter, setSpaceBefore, singleSpacing, toggleBidi, toggleBulletList, toggleNumberedList };
|
|
@@ -59,6 +59,6 @@ function removeTabStop(position) {
|
|
|
59
59
|
const toggleBidi = cmds.requireCommand("toggleBidi")();
|
|
60
60
|
const setRtl = cmds.requireCommand("setRtl")();
|
|
61
61
|
const setLtr = cmds.requireCommand("setLtr")();
|
|
62
|
-
const
|
|
62
|
+
const generateTableOfContents = (options) => cmds.requireCommand("generateTOC")(options);
|
|
63
63
|
//#endregion
|
|
64
|
-
export { addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyle, clearStyle, decreaseIndent, decreaseListLevel, doubleSpacing,
|
|
64
|
+
export { addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyle, clearStyle, decreaseIndent, decreaseListLevel, doubleSpacing, generateTableOfContents, getListInfo, getParagraphAlignment, getParagraphBidi, getParagraphTabs, getStyleId, increaseIndent, increaseListLevel, insertSectionBreak, isInList, oneAndHalfSpacing, removeList, removeSectionBreak, removeTabStop, setAlignment, setIndentFirstLine, setIndentLeft, setIndentRight, setLineSpacing, setLtr, setRtl, setSpaceAfter, setSpaceBefore, singleSpacing, toggleBidi, toggleBulletList, toggleNumberedList };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { seedRevisionIdsAbove } from "./plugins/revisionIds.js";
|
|
1
|
+
import { maxAnnotationIdInDoc, seedRevisionIdsAbove } from "./plugins/revisionIds.js";
|
|
2
2
|
import { MAX_REVISION_ID } from "@stll/docx-core/model";
|
|
3
3
|
//#region src/prosemirror/commentIdAllocator.ts
|
|
4
4
|
/** Sentinel ID for a comment that hasn't been persisted yet (anchored to selection). */
|
|
@@ -32,12 +32,7 @@ function createCommentIdAllocator() {
|
|
|
32
32
|
function seedCommentAllocator(allocator, comments, view) {
|
|
33
33
|
let max = 0;
|
|
34
34
|
for (const comment of comments ?? []) if (Number.isInteger(comment.id) && comment.id > max && comment.id <= MAX_REVISION_ID) max = comment.id;
|
|
35
|
-
if (view) view.state.doc
|
|
36
|
-
for (const mark of node.marks) {
|
|
37
|
-
const revisionId = mark.attrs["revisionId"];
|
|
38
|
-
if (typeof revisionId === "number" && Number.isInteger(revisionId) && revisionId > max && revisionId <= MAX_REVISION_ID) max = revisionId;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
35
|
+
if (view) max = Math.max(max, maxAnnotationIdInDoc(view.state.doc));
|
|
41
36
|
allocator.seedAbove(max);
|
|
42
37
|
seedRevisionIdsAbove(max);
|
|
43
38
|
}
|
|
@@ -13,9 +13,10 @@ import { mergeTextFormatting } from "../../utils/textFormattingMerge.js";
|
|
|
13
13
|
import { pixelsToEmu } from "../../utils/units.js";
|
|
14
14
|
import { expectBlockSdtAttrs, expectCharacterSpacingMarkAttrs, expectCharacterStyleMarkAttrs, expectCommentMarkAttrs, expectEmphasisMarkAttrs, expectFieldAttrs, expectFontFamilyMarkAttrs, expectFontSizeMarkAttrs, expectFootnoteRefMarkAttrs, expectHardBreakAttrs, expectHighlightMarkAttrs, expectHyperlinkMarkAttrs, expectImageAttrs, expectLanguageMarkAttrs, expectMathAttrs, expectPageBreakRunAttrs, expectPageBreakRunOwnerMarkAttrs, expectParagraphAttrs, expectRunFormattingOverrideMarkAttrs, expectRunPropertyChangeMarkAttrs, expectRunShadingMarkAttrs, expectSdtAttrs, expectShapeAttrs, expectStrikeMarkAttrs, expectSymbolAttrs, expectTabAttrs, expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, expectTextBoxAttrs, expectTextColorMarkAttrs, expectTextEffectMarkAttrs, expectTrackedChangeMarkAttrs, expectUnderlineMarkAttrs } from "../attrs/index.js";
|
|
15
15
|
import { autospacingMatchesBase, hasAutospacingBaseSide } from "../autospacingBase.js";
|
|
16
|
-
import { expectBookmarkBoundaryAttrs } from "../bookmarkBoundaryAttrs.js";
|
|
16
|
+
import { bookmarkBoundaryDisplacement, expectBookmarkBoundaryAttrs } from "../bookmarkBoundaryAttrs.js";
|
|
17
17
|
import { paragraphRejectAttrPatch, paragraphRejectOriginalFormatting, removeParagraphPropertyChanges } from "../commands/propertyChangeScope.js";
|
|
18
18
|
import { applyRunFormattingOverrideAttrs, buildRunFormattingOverrideAttrs } from "../extensions/marks/RunFormattingOverrideExtension.js";
|
|
19
|
+
import { textFormattingToMarks } from "../extensions/marks/markUtils.js";
|
|
19
20
|
import { listRenderingFromAttrs as listRenderingFromAttrs$1 } from "../listRenderingAttrs.js";
|
|
20
21
|
import { resolveNumberedRefFields } from "../numberedRefFields.js";
|
|
21
22
|
import { directParagraphAlignment } from "../paragraphAlignment.js";
|
|
@@ -24,12 +25,12 @@ import { directParagraphSpacing } from "../paragraphSpacing.js";
|
|
|
24
25
|
import { RUN_FORMATTING_MARK_NAMES } from "../runFormattingMarkNames.js";
|
|
25
26
|
import { authoredRunFormattingFromAttrs, hasAuthoredRunFormattingProvenance } from "../runFormattingProvenance.js";
|
|
26
27
|
import { paragraphFormattingForRun, paragraphRunStyleContext, resolveEffectiveRunStyleFormatting, suppressParagraphMarkFormatting } from "../runStyleFormatting.js";
|
|
28
|
+
import { schema } from "../schema/index.js";
|
|
27
29
|
import { parseShapeGeometryAdjustments } from "../shapeGeometryAdjustments.js";
|
|
28
30
|
import { expectTextBoxAnchorAttrs } from "../textBoxAnchorAttrs.js";
|
|
29
31
|
import { assertValidProseMirrorDocument } from "../validation.js";
|
|
30
32
|
import { runShadingAttrsToShading, shadingToRunShadingAttrs } from "./runShadingMark.js";
|
|
31
33
|
import { decodeSdtListItems, sdtPropertiesFromAttrs, sdtPropertiesMatchAttrs } from "./sdtAttrs.js";
|
|
32
|
-
import { textFormattingToMarks } from "./toProseDoc.js";
|
|
33
34
|
import { panic } from "better-result";
|
|
34
35
|
import { Fragment } from "prosemirror-model";
|
|
35
36
|
import { DRAWING_RAW_XML_MODES } from "@stll/docx-core/model";
|
|
@@ -271,7 +272,7 @@ function stripSuggestedInlineMarks(marks, { baseParagraphFormatting, inheritedFo
|
|
|
271
272
|
styleResolver
|
|
272
273
|
}) : paragraphFormatting, previousFormatting);
|
|
273
274
|
next = next.filter((mark) => !RUN_FORMATTING_MARK_NAMES.has(mark.type.name));
|
|
274
|
-
for (const restored of textFormattingToMarks(effectivePreviousFormatting, {
|
|
275
|
+
for (const restored of textFormattingToMarks(effectivePreviousFormatting, schema, {
|
|
275
276
|
overrideFormatting: previousFormatting,
|
|
276
277
|
directFormatting: previousFormatting
|
|
277
278
|
})) next = restored.addToSet(next);
|
|
@@ -645,17 +646,47 @@ function replaceTextBoxAnchorInBlocks(blocks, marker, textBoxRun) {
|
|
|
645
646
|
}
|
|
646
647
|
return false;
|
|
647
648
|
}
|
|
649
|
+
/**
|
|
650
|
+
* The inline list a text-box anchor run can be spliced out of, or nothing when
|
|
651
|
+
* the item holds no such list.
|
|
652
|
+
*
|
|
653
|
+
* A complex field keeps its runs in `fieldCode`/`fieldResult`, two arrays
|
|
654
|
+
* rather than one, and an anchor has never been placed in either; splicing one
|
|
655
|
+
* would have to pick a side. The marker stays where it is and
|
|
656
|
+
* `removeUnresolvedTextBoxAnchors` leaves it, as before.
|
|
657
|
+
*/
|
|
658
|
+
const textBoxAnchorHost = (item) => {
|
|
659
|
+
switch (item.type) {
|
|
660
|
+
case "hyperlink": return item.children;
|
|
661
|
+
case "simpleField": return item.content;
|
|
662
|
+
case "inlineSdt":
|
|
663
|
+
case "insertion":
|
|
664
|
+
case "deletion":
|
|
665
|
+
case "moveFrom":
|
|
666
|
+
case "moveTo":
|
|
667
|
+
case "bidiWrapper": return item.content;
|
|
668
|
+
case "run":
|
|
669
|
+
case "complexField":
|
|
670
|
+
case "bookmarkStart":
|
|
671
|
+
case "bookmarkEnd":
|
|
672
|
+
case "commentRangeStart":
|
|
673
|
+
case "commentRangeEnd":
|
|
674
|
+
case "commentReference":
|
|
675
|
+
case "moveFromRangeStart":
|
|
676
|
+
case "moveFromRangeEnd":
|
|
677
|
+
case "moveToRangeStart":
|
|
678
|
+
case "moveToRangeEnd":
|
|
679
|
+
case "mathEquation": return;
|
|
680
|
+
default: panic(`Unsupported paragraph content: ${JSON.stringify(item)}`);
|
|
681
|
+
}
|
|
682
|
+
};
|
|
648
683
|
function editTextBoxAnchorInContent(content, marker, replacement) {
|
|
649
|
-
for (
|
|
650
|
-
const item = content[index];
|
|
684
|
+
for (const [index, item] of content.entries()) {
|
|
651
685
|
if (item === marker) {
|
|
652
686
|
content.splice(index, 1, ...replacement ? [replacement] : []);
|
|
653
687
|
return true;
|
|
654
688
|
}
|
|
655
|
-
|
|
656
|
-
if (item?.type === "hyperlink") nestedContent = item.children;
|
|
657
|
-
else if (item?.type === "simpleField") nestedContent = item.content;
|
|
658
|
-
else if (item?.type === "inlineSdt" || item?.type === "insertion" || item?.type === "deletion" || item?.type === "moveFrom" || item?.type === "moveTo") nestedContent = item.content;
|
|
689
|
+
const nestedContent = textBoxAnchorHost(item);
|
|
659
690
|
if (!nestedContent) continue;
|
|
660
691
|
const hadContent = nestedContent.length > 0;
|
|
661
692
|
if (editTextBoxAnchorInContent(nestedContent, marker, replacement)) {
|
|
@@ -800,8 +831,23 @@ const propertyChangeFromAttrs = (change) => {
|
|
|
800
831
|
...currentFormatting !== void 0 && { currentFormatting }
|
|
801
832
|
};
|
|
802
833
|
};
|
|
834
|
+
/**
|
|
835
|
+
* What the paragraph states itself for one `w:pPr` field, as opposed to what
|
|
836
|
+
* the style cascade resolved into the same attr.
|
|
837
|
+
*
|
|
838
|
+
* `undefined` means the paragraph states nothing and the field must stay
|
|
839
|
+
* absent: a materialised value is a direct override that outranks the style it
|
|
840
|
+
* was read from, and a later edit to that style no longer reaches the
|
|
841
|
+
* paragraph. A value the source stated directly is always authored, even when
|
|
842
|
+
* it happens to equal the style's.
|
|
843
|
+
*/
|
|
844
|
+
const authoredParagraphValue = (field, value, orig, resolved) => {
|
|
845
|
+
if (value === void 0) return;
|
|
846
|
+
if (orig?.[field] !== void 0) return value;
|
|
847
|
+
return sameResolvedValue(value, resolved?.[field]) ? void 0 : value;
|
|
848
|
+
};
|
|
803
849
|
function assignBooleanToggle(result, attrs, orig, key) {
|
|
804
|
-
const value = attrs[key] ?? void 0;
|
|
850
|
+
const value = authoredParagraphValue(key, attrs[key] ?? void 0, orig, attrs._resolvedFormatting);
|
|
805
851
|
if (value === (orig[key] ?? void 0)) return;
|
|
806
852
|
if (value === void 0) Reflect.deleteProperty(result, key);
|
|
807
853
|
else result[key] = value;
|
|
@@ -866,14 +912,29 @@ function paragraphAttrsToFormatting(attrs) {
|
|
|
866
912
|
assignBooleanToggle(result, attrs, orig, "suppressAutoHyphens");
|
|
867
913
|
if (attrs.spacingExplicit !== orig.spacingExplicit) if (attrs.spacingExplicit) result.spacingExplicit = attrs.spacingExplicit;
|
|
868
914
|
else delete result.spacingExplicit;
|
|
869
|
-
const bidi = directionToBidi(attrs.direction);
|
|
915
|
+
const bidi = authoredParagraphValue("bidi", directionToBidi(attrs.direction), orig, attrs._resolvedFormatting);
|
|
870
916
|
if (bidi !== (orig.bidi ?? void 0)) if (bidi === void 0) delete result.bidi;
|
|
871
917
|
else result.bidi = bidi;
|
|
872
918
|
return result;
|
|
873
919
|
}
|
|
874
|
-
const
|
|
875
|
-
const
|
|
876
|
-
|
|
920
|
+
const resolved = attrs._resolvedFormatting;
|
|
921
|
+
const authored = (field, value) => authoredParagraphValue(field, value ?? void 0, void 0, resolved);
|
|
922
|
+
const outlineLevel = authored("outlineLevel", Reflect.get(attrs, "outlineLevel"));
|
|
923
|
+
const bidi = authored("bidi", directionToBidi(attrs.direction));
|
|
924
|
+
const snapToGrid = authored("snapToGrid", attrs.snapToGrid);
|
|
925
|
+
const indentLeft = authored("indentLeft", attrs.indentLeft);
|
|
926
|
+
const indentRight = authored("indentRight", attrs.indentRight);
|
|
927
|
+
const indentFirstLine = authored("indentFirstLine", attrs.indentFirstLine);
|
|
928
|
+
const borders = authored("borders", attrs.borders);
|
|
929
|
+
const shading = authored("shading", attrs.shading);
|
|
930
|
+
const tabs = authored("tabs", attrs.tabs);
|
|
931
|
+
const contextualSpacing = authored("contextualSpacing", attrs.contextualSpacing);
|
|
932
|
+
const pageBreakBefore = authored("pageBreakBefore", attrs.pageBreakBefore);
|
|
933
|
+
const widowControl = authored("widowControl", attrs.widowControl);
|
|
934
|
+
const kinsoku = authored("kinsoku", attrs.kinsoku);
|
|
935
|
+
const overflowPunctuation = authored("overflowPunctuation", attrs.overflowPunctuation);
|
|
936
|
+
const suppressAutoHyphens = authored("suppressAutoHyphens", attrs.suppressAutoHyphens);
|
|
937
|
+
if (!(directAlignment !== void 0 || shouldSerializeSpaceBefore || shouldSerializeSpaceAfter || beforeAutospacingEdited || afterAutospacingEdited || hasDirectLineSpacing || hasDirectLineSpacingRule || snapToGrid != null || indentLeft || indentRight || indentFirstLine || attrs.numPr || attrs.styleId || borders || shading || tabs || typeof outlineLevel === "number" || contextualSpacing || attrs.spacingExplicit || bidi != null || pageBreakBefore != null || widowControl != null || kinsoku != null || overflowPunctuation != null || suppressAutoHyphens != null)) return;
|
|
877
938
|
const f = {};
|
|
878
939
|
if (directAlignment !== void 0) f.alignment = directAlignment;
|
|
879
940
|
if (shouldSerializeSpaceBefore) f.spaceBefore = spaceBefore;
|
|
@@ -882,25 +943,25 @@ function paragraphAttrsToFormatting(attrs) {
|
|
|
882
943
|
if (afterAutospacingEdited) f.afterAutospacing = false;
|
|
883
944
|
if (hasDirectLineSpacing && typeof attrs.lineSpacing === "number") f.lineSpacing = attrs.lineSpacing;
|
|
884
945
|
if (hasDirectLineSpacingRule && attrs.lineSpacingRule) f.lineSpacingRule = attrs.lineSpacingRule;
|
|
885
|
-
if (
|
|
946
|
+
if (snapToGrid != null) f.snapToGrid = snapToGrid;
|
|
886
947
|
if (attrs.spacingExplicit) f.spacingExplicit = attrs.spacingExplicit;
|
|
887
|
-
if (
|
|
888
|
-
if (
|
|
889
|
-
if (
|
|
890
|
-
if (attrs.hangingIndent) f.hangingIndent = attrs.hangingIndent;
|
|
948
|
+
if (indentLeft) f.indentLeft = indentLeft;
|
|
949
|
+
if (indentRight) f.indentRight = indentRight;
|
|
950
|
+
if (indentFirstLine) f.indentFirstLine = indentFirstLine;
|
|
951
|
+
if (attrs.hangingIndent && indentFirstLine) f.hangingIndent = attrs.hangingIndent;
|
|
891
952
|
if (attrs.numPr && !isStyleSourcedParagraphNumbering(attrs.numPr, attrs.numPrFromStyle)) f.numPr = attrs.numPr;
|
|
892
953
|
if (attrs.styleId) f.styleId = attrs.styleId;
|
|
893
|
-
if (
|
|
894
|
-
if (
|
|
895
|
-
if (
|
|
954
|
+
if (borders) f.borders = borders;
|
|
955
|
+
if (shading) f.shading = shading;
|
|
956
|
+
if (tabs) f.tabs = tabs;
|
|
896
957
|
if (typeof outlineLevel === "number") f.outlineLevel = outlineLevel;
|
|
897
|
-
if (
|
|
958
|
+
if (contextualSpacing) f.contextualSpacing = contextualSpacing;
|
|
898
959
|
if (bidi != null) f.bidi = bidi;
|
|
899
|
-
if (
|
|
900
|
-
if (
|
|
901
|
-
if (
|
|
902
|
-
if (
|
|
903
|
-
if (
|
|
960
|
+
if (pageBreakBefore != null) f.pageBreakBefore = pageBreakBefore;
|
|
961
|
+
if (widowControl != null) f.widowControl = widowControl;
|
|
962
|
+
if (kinsoku != null) f.kinsoku = kinsoku;
|
|
963
|
+
if (overflowPunctuation != null) f.overflowPunctuation = overflowPunctuation;
|
|
964
|
+
if (suppressAutoHyphens != null) f.suppressAutoHyphens = suppressAutoHyphens;
|
|
904
965
|
return f;
|
|
905
966
|
}
|
|
906
967
|
function createTrackedRunWrapper(type, info, child) {
|
|
@@ -1143,10 +1204,12 @@ function extractParagraphContent(paragraph, _documentCounts, emptyHyperlinks, te
|
|
|
1143
1204
|
id: attrs.id,
|
|
1144
1205
|
name: attrs.name,
|
|
1145
1206
|
...attrs.colFirst !== void 0 ? { colFirst: attrs.colFirst } : {},
|
|
1146
|
-
...attrs.colLast !== void 0 ? { colLast: attrs.colLast } : {}
|
|
1207
|
+
...attrs.colLast !== void 0 ? { colLast: attrs.colLast } : {},
|
|
1208
|
+
...bookmarkBoundaryDisplacement(attrs)
|
|
1147
1209
|
} : {
|
|
1148
1210
|
type: "bookmarkEnd",
|
|
1149
|
-
id: attrs.id
|
|
1211
|
+
id: attrs.id,
|
|
1212
|
+
...bookmarkBoundaryDisplacement(attrs)
|
|
1150
1213
|
};
|
|
1151
1214
|
currentTrackedChange.wrapper.content.push(boundary);
|
|
1152
1215
|
return;
|
|
@@ -1209,11 +1272,13 @@ function extractParagraphContent(paragraph, _documentCounts, emptyHyperlinks, te
|
|
|
1209
1272
|
id: attrs.id,
|
|
1210
1273
|
name: attrs.name,
|
|
1211
1274
|
...attrs.colFirst !== void 0 ? { colFirst: attrs.colFirst } : {},
|
|
1212
|
-
...attrs.colLast !== void 0 ? { colLast: attrs.colLast } : {}
|
|
1275
|
+
...attrs.colLast !== void 0 ? { colLast: attrs.colLast } : {},
|
|
1276
|
+
...bookmarkBoundaryDisplacement(attrs)
|
|
1213
1277
|
});
|
|
1214
1278
|
else content.push({
|
|
1215
1279
|
type: "bookmarkEnd",
|
|
1216
|
-
id: attrs.id
|
|
1280
|
+
id: attrs.id,
|
|
1281
|
+
...bookmarkBoundaryDisplacement(attrs)
|
|
1217
1282
|
});
|
|
1218
1283
|
} else if (node.isText) appendDirectRun(node, createRunFromText({
|
|
1219
1284
|
...formattingContext,
|
|
@@ -1426,11 +1491,13 @@ function addNodeToHyperlink({ baseParagraphFormatting, hyperlink, inheritedForma
|
|
|
1426
1491
|
id: attrs.id,
|
|
1427
1492
|
name: attrs.name,
|
|
1428
1493
|
...attrs.colFirst !== void 0 ? { colFirst: attrs.colFirst } : {},
|
|
1429
|
-
...attrs.colLast !== void 0 ? { colLast: attrs.colLast } : {}
|
|
1494
|
+
...attrs.colLast !== void 0 ? { colLast: attrs.colLast } : {},
|
|
1495
|
+
...bookmarkBoundaryDisplacement(attrs)
|
|
1430
1496
|
});
|
|
1431
1497
|
else hyperlink.children.push({
|
|
1432
1498
|
type: "bookmarkEnd",
|
|
1433
|
-
id: attrs.id
|
|
1499
|
+
id: attrs.id,
|
|
1500
|
+
...bookmarkBoundaryDisplacement(attrs)
|
|
1434
1501
|
});
|
|
1435
1502
|
return;
|
|
1436
1503
|
}
|
|
@@ -1818,6 +1885,14 @@ function createInlineSdtFromNode(node, textBoxAnchorMarkers, formattingContext)
|
|
|
1818
1885
|
/**
|
|
1819
1886
|
* Create a Run containing an image
|
|
1820
1887
|
*/
|
|
1888
|
+
/**
|
|
1889
|
+
* Restore the `w:rPr` an inline atom carried from its source run.
|
|
1890
|
+
*
|
|
1891
|
+
* Image and shape nodes do not hold the run's formatting marks
|
|
1892
|
+
* (`withRunBoundaryMarks` in toProseDoc keeps them off), so the run rebuilt
|
|
1893
|
+
* around one has no other record of the properties it was authored with.
|
|
1894
|
+
*/
|
|
1895
|
+
const carriedRunFormatting = (formatting) => formatting && Object.keys(formatting).length > 0 ? { formatting } : {};
|
|
1821
1896
|
function createImageRun(node) {
|
|
1822
1897
|
const attrs = expectImageAttrs(node);
|
|
1823
1898
|
const wrap = { type: attrs.wrapType || "inline" };
|
|
@@ -1888,6 +1963,7 @@ function createImageRun(node) {
|
|
|
1888
1963
|
}
|
|
1889
1964
|
return {
|
|
1890
1965
|
type: "run",
|
|
1966
|
+
...carriedRunFormatting(attrs._docxRunFormatting),
|
|
1891
1967
|
content: [drawingFromImageAttrs(image, attrs)]
|
|
1892
1968
|
};
|
|
1893
1969
|
}
|
|
@@ -1984,12 +2060,14 @@ function createShapeRun(node) {
|
|
|
1984
2060
|
if (attrs.outlineColor) shapeOutline.color = attrs.outlineColorValue ?? { rgb: attrs.outlineColor.replace("#", "") };
|
|
1985
2061
|
shape.outline = shapeOutline;
|
|
1986
2062
|
}
|
|
2063
|
+
const shapeContent = {
|
|
2064
|
+
type: "shape",
|
|
2065
|
+
shape
|
|
2066
|
+
};
|
|
1987
2067
|
return {
|
|
1988
2068
|
type: "run",
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
shape
|
|
1992
|
-
}]
|
|
2069
|
+
...carriedRunFormatting(attrs._docxRunFormatting),
|
|
2070
|
+
content: [shapeContent]
|
|
1993
2071
|
};
|
|
1994
2072
|
}
|
|
1995
2073
|
const RUN_FORMATTING_VISUAL_GROUPS = {
|
|
@@ -2550,6 +2628,17 @@ function marksToTextFormatting(marks, options) {
|
|
|
2550
2628
|
/**
|
|
2551
2629
|
* Convert a ProseMirror table node to our Table type
|
|
2552
2630
|
*/
|
|
2631
|
+
/**
|
|
2632
|
+
* A table the editor created carries no `w:tblPr`, so the borders its cells
|
|
2633
|
+
* were built with are the only record of what the table looks like. Lift the
|
|
2634
|
+
* first bordered cell's set to the table.
|
|
2635
|
+
*
|
|
2636
|
+
* Only for such a table: a table read from a package states its own
|
|
2637
|
+
* `w:tblBorders` or deliberately states none, and its cells' borders may be
|
|
2638
|
+
* the table style's rather than their own. Inferring there invents a
|
|
2639
|
+
* `w:tblBorders` the source never had, and it outranks the table style on
|
|
2640
|
+
* reload (`formatting.borders: absent became object` in the corpus census).
|
|
2641
|
+
*/
|
|
2553
2642
|
function inferTableBorders(rows) {
|
|
2554
2643
|
for (const row of rows) for (const cell of row.cells) {
|
|
2555
2644
|
const borders = cell.formatting?.borders;
|
|
@@ -2571,7 +2660,7 @@ function convertPMTable(node, documentCounts, styleResolver = null) {
|
|
|
2571
2660
|
const attrs = expectTableAttrs(node);
|
|
2572
2661
|
const rows = convertPMTableRows(node, documentCounts, styleResolver);
|
|
2573
2662
|
const formatting = tableAttrsToFormatting(attrs) || void 0;
|
|
2574
|
-
if (!formatting?.borders) {
|
|
2663
|
+
if (!formatting?.borders && !attrs._originalFormatting) {
|
|
2575
2664
|
const inferredBorders = inferTableBorders(rows);
|
|
2576
2665
|
if (inferredBorders) if (formatting) formatting.borders = inferredBorders;
|
|
2577
2666
|
else {
|
|
@@ -2590,7 +2679,7 @@ function convertPMTable(node, documentCounts, styleResolver = null) {
|
|
|
2590
2679
|
rows
|
|
2591
2680
|
};
|
|
2592
2681
|
if (attrs.columnWidths) table.columnWidths = attrs.columnWidths;
|
|
2593
|
-
if (formatting) table.formatting = formatting;
|
|
2682
|
+
if (formatting && Object.keys(formatting).length > 0) table.formatting = formatting;
|
|
2594
2683
|
restoreTablePropertyChanges(table, attrs);
|
|
2595
2684
|
return table;
|
|
2596
2685
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { document_d_exports } from "../../types/document.js";
|
|
2
2
|
import { StyleEngine } from "../../style-engine/styleEngine.js";
|
|
3
3
|
import "../../style-engine/index.js";
|
|
4
|
-
import { schema } from "../schema/index.js";
|
|
5
4
|
import { Node } from "prosemirror-model";
|
|
6
5
|
//#region src/prosemirror/conversion/toProseDoc.d.ts
|
|
7
6
|
type UnsupportedDocxToProseMirrorOwner = "complex-field-instruction" | "field-result" | "page-break-bearing-run" | "paragraph-borders" | "paragraph-frame" | "paragraph-outline" | "paragraph-text-box-anchor" | "table-cell" | "text-box";
|
|
@@ -39,18 +38,6 @@ declare function resolveParagraphDefaultTextFormatting(styleId: string | undefin
|
|
|
39
38
|
includeParagraphMarkRunProperties?: boolean;
|
|
40
39
|
}): document_d_exports.TextFormatting | undefined;
|
|
41
40
|
declare function standaloneTableCellToProseMirror(cell: document_d_exports.TableCell, nodeType: "tableCell" | "tableHeader"): Node;
|
|
42
|
-
type AuthoredRunFormattingCarrier = "preserve" | "reconstruct";
|
|
43
|
-
/**
|
|
44
|
-
* Convert TextFormatting to ProseMirror marks
|
|
45
|
-
*/
|
|
46
|
-
type TextFormattingToMarksOptions = {
|
|
47
|
-
overrideFormatting: document_d_exports.TextFormatting | undefined;
|
|
48
|
-
/** Direct standard font properties whose authored provenance must survive. */
|
|
49
|
-
directFormatting?: document_d_exports.TextFormatting | undefined;
|
|
50
|
-
/** Whether direct authorship is reconstructible from structural marks and the style context. */
|
|
51
|
-
authoredCarrier?: AuthoredRunFormattingCarrier;
|
|
52
|
-
};
|
|
53
|
-
declare function textFormattingToMarks(formatting: document_d_exports.TextFormatting | undefined, options?: TextFormattingToMarksOptions): ReturnType<typeof schema.mark>[];
|
|
54
41
|
/**
|
|
55
42
|
* Convert HeaderFooter content (array of Paragraph/Table blocks) to a ProseMirror document.
|
|
56
43
|
* Used for editing headers/footers in their own ProseMirror editor and for
|
|
@@ -66,4 +53,4 @@ declare function footnoteToProseDoc(content: document_d_exports.BlockContent[],
|
|
|
66
53
|
*/
|
|
67
54
|
declare function createEmptyDoc(): Node;
|
|
68
55
|
//#endregion
|
|
69
|
-
export { ToProseDocOptions, UnsupportedDocxToProseMirrorConversionError, createEmptyDoc, footnoteToProseDoc, headerFooterToProseDoc, resolveParagraphDefaultTextFormatting, standaloneTableCellToProseMirror,
|
|
56
|
+
export { ToProseDocOptions, UnsupportedDocxToProseMirrorConversionError, createEmptyDoc, footnoteToProseDoc, headerFooterToProseDoc, resolveParagraphDefaultTextFormatting, standaloneTableCellToProseMirror, toProseDoc };
|