@stll/folio-core 0.53.0 → 0.54.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/dist/ai-edits/apply.js +415 -166
  2. package/dist/ai-edits/batch-claims.d.ts +21 -6
  3. package/dist/ai-edits/batch-claims.js +47 -16
  4. package/dist/ai-edits/headless.d.ts +20 -0
  5. package/dist/ai-edits/headless.js +140 -11
  6. package/dist/ai-edits/pending-suggestions.js +1 -1
  7. package/dist/ai-edits/read.d.ts +5 -3
  8. package/dist/ai-edits/read.js +97 -47
  9. package/dist/ai-edits/revisionStretches.d.ts +17 -0
  10. package/dist/ai-edits/revisionStretches.js +80 -0
  11. package/dist/ai-edits/snapshot.js +3 -2
  12. package/dist/ai-edits/table-cell-mutations.d.ts +3 -1
  13. package/dist/ai-edits/table-cell-mutations.js +2 -1
  14. package/dist/ai-edits/table-row-column-mutations.d.ts +6 -1
  15. package/dist/ai-edits/table-row-column-mutations.js +27 -10
  16. package/dist/compare/content-alignment.d.ts +5 -1
  17. package/dist/compare/content-alignment.js +39 -32
  18. package/dist/compare/inline-provenance.js +1 -1
  19. package/dist/controller/layoutPipeline.js +3 -2
  20. package/dist/docx/archiveInflation.d.ts +127 -0
  21. package/dist/docx/archiveInflation.js +181 -0
  22. package/dist/docx/metadataPrivacy.js +24 -1
  23. package/dist/docx/noteReferenceMark.d.ts +15 -0
  24. package/dist/docx/noteReferenceMark.js +48 -0
  25. package/dist/docx/paragraphParser.js +5 -3
  26. package/dist/docx/paragraphPropertySource.d.ts +1 -1
  27. package/dist/docx/paragraphPropertySource.js +4 -2
  28. package/dist/docx/parser.js +2 -2
  29. package/dist/docx/rezip.js +4 -2
  30. package/dist/docx/selectiveXmlPatch.d.ts +3 -1
  31. package/dist/docx/selectiveXmlPatch.js +81 -3
  32. package/dist/docx/server/boundedArchive.d.ts +8 -13
  33. package/dist/docx/server/boundedArchive.js +70 -59
  34. package/dist/docx/server/extractDocxText.d.ts +8 -2
  35. package/dist/docx/server/extractDocxText.js +2 -2
  36. package/dist/docx/server/validateDocxConformance.d.ts +1 -1
  37. package/dist/docx/server/validateDocxConformance.js +1 -0
  38. package/dist/docx/unzip.d.ts +19 -2
  39. package/dist/docx/unzip.js +135 -24
  40. package/dist/docx/verticalMergeProjection.d.ts +17 -0
  41. package/dist/docx/verticalMergeProjection.js +120 -0
  42. package/dist/fonts/embeddedFonts.js +1 -1
  43. package/dist/i18n/messages/catalogs.gen.d.ts +34 -34
  44. package/dist/i18n/messages/catalogs.gen.js +34 -34
  45. package/dist/i18n/messages/messages.gen.d.ts +2 -2
  46. package/dist/internal/wholeStoryRevisionResolution.js +95 -25
  47. package/dist/layout-engine/measure/measureParagraph.js +2 -2
  48. package/dist/layout-engine/measure/paragraphMeasureShared.d.ts +12 -1
  49. package/dist/layout-engine/measure/paragraphMeasureShared.js +14 -1
  50. package/dist/markdown/escape.d.ts +2 -2
  51. package/dist/markdown/escape.js +4 -5
  52. package/dist/markdown/renderBlock.js +91 -25
  53. package/dist/markdown/renderRuns.d.ts +10 -1
  54. package/dist/markdown/renderRuns.js +320 -59
  55. package/dist/prosemirror/clearRunColor.d.ts +6 -0
  56. package/dist/prosemirror/clearRunColor.js +46 -0
  57. package/dist/prosemirror/commands/comments.js +62 -22
  58. package/dist/prosemirror/commands/formatPainter.js +1 -1
  59. package/dist/prosemirror/commands/hyperlink.js +2 -1
  60. package/dist/prosemirror/commands/propertyChangeScope.d.ts +3 -2
  61. package/dist/prosemirror/commands/propertyChangeScope.js +28 -4
  62. package/dist/prosemirror/commands/resolveAllTableChanges.js +40 -41
  63. package/dist/prosemirror/commands/resolveParagraphProperties.js +33 -8
  64. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +7 -1
  65. package/dist/prosemirror/commands/tableCellMergeResolution.js +39 -20
  66. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +61 -0
  67. package/dist/prosemirror/commands/tableMergeFoldDecisions.js +79 -0
  68. package/dist/prosemirror/containerFinalParagraph.d.ts +11 -5
  69. package/dist/prosemirror/containerFinalParagraph.js +7 -6
  70. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -13
  71. package/dist/prosemirror/conversion/fromProseDoc.js +12 -590
  72. package/dist/prosemirror/conversion/toProseDoc.d.ts +1 -13
  73. package/dist/prosemirror/conversion/toProseDoc.js +28 -262
  74. package/dist/prosemirror/documentSchema.d.ts +8 -0
  75. package/dist/prosemirror/documentSchema.js +18 -0
  76. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  77. package/dist/prosemirror/extensions/core/ParagraphExtension.js +104 -63
  78. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
  79. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +24 -3
  80. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +20 -0
  81. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.js +43 -0
  82. package/dist/prosemirror/extensions/features/ListExtension.js +10 -9
  83. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
  84. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +2 -4
  85. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +14 -8
  86. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +8 -4
  87. package/dist/prosemirror/extensions/marks/StrikeExtension.js +2 -2
  88. package/dist/prosemirror/extensions/marks/SubscriptExtension.js +2 -2
  89. package/dist/prosemirror/extensions/marks/SuperscriptExtension.js +2 -2
  90. package/dist/prosemirror/extensions/marks/TextColorExtension.js +4 -3
  91. package/dist/prosemirror/extensions/marks/markUtils.d.ts +8 -6
  92. package/dist/prosemirror/extensions/marks/markUtils.js +17 -8
  93. package/dist/prosemirror/extensions/marks/noteReferenceDeletion.d.ts +3 -1
  94. package/dist/prosemirror/extensions/marks/noteReferenceDeletion.js +12 -1
  95. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +2 -2
  96. package/dist/prosemirror/extensions/nodes/HardBreakExtension.js +5 -3
  97. package/dist/prosemirror/extensions/nodes/TableExtension.js +104 -210
  98. package/dist/prosemirror/extensions/types.d.ts +7 -0
  99. package/dist/prosemirror/hyperlinkRemoval.d.ts +9 -0
  100. package/dist/prosemirror/hyperlinkRemoval.js +129 -0
  101. package/dist/prosemirror/index.d.ts +2 -1
  102. package/dist/prosemirror/index.js +2 -1
  103. package/dist/prosemirror/listNumbering.d.ts +3 -21
  104. package/dist/prosemirror/listNumbering.js +24 -39
  105. package/dist/prosemirror/listRendering.d.ts +29 -0
  106. package/dist/prosemirror/listRendering.js +26 -0
  107. package/dist/prosemirror/markupViewNotes.d.ts +8 -0
  108. package/dist/prosemirror/markupViewNotes.js +49 -0
  109. package/dist/prosemirror/markupViewProjection.d.ts +3 -1
  110. package/dist/prosemirror/markupViewProjection.js +7 -2
  111. package/dist/prosemirror/noteReferenceReview.d.ts +77 -0
  112. package/dist/prosemirror/noteReferenceReview.js +332 -0
  113. package/dist/prosemirror/paragraphIndentation.js +5 -2
  114. package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -4
  115. package/dist/prosemirror/paragraphMarkJoin.js +21 -19
  116. package/dist/prosemirror/paragraphPropertyCarry.d.ts +64 -0
  117. package/dist/prosemirror/paragraphPropertyCarry.js +155 -0
  118. package/dist/prosemirror/plugins/documentStyleState.d.ts +26 -0
  119. package/dist/prosemirror/plugins/documentStyleState.js +32 -0
  120. package/dist/prosemirror/plugins/documentStyles.d.ts +2 -21
  121. package/dist/prosemirror/plugins/documentStyles.js +66 -29
  122. package/dist/prosemirror/plugins/index.d.ts +2 -1
  123. package/dist/prosemirror/plugins/index.js +2 -1
  124. package/dist/prosemirror/plugins/paragraphStyleResolution.d.ts +15 -0
  125. package/dist/prosemirror/plugins/paragraphStyleResolution.js +230 -0
  126. package/dist/prosemirror/plugins/suggestionMode.d.ts +12 -2
  127. package/dist/prosemirror/plugins/suggestionMode.js +387 -28
  128. package/dist/prosemirror/plugins/templateDirectives.d.ts +6 -0
  129. package/dist/prosemirror/plugins/templateDirectives.js +21 -7
  130. package/dist/prosemirror/plugins/templatePreviewValues.js +14 -21
  131. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +22 -2
  132. package/dist/prosemirror/rebaseParagraphRunFormatting.js +39 -13
  133. package/dist/prosemirror/rebaseParagraphRuns.d.ts +36 -0
  134. package/dist/prosemirror/rebaseParagraphRuns.js +99 -0
  135. package/dist/prosemirror/runFormattingFromMarks.d.ts +18 -0
  136. package/dist/prosemirror/runFormattingFromMarks.js +567 -0
  137. package/dist/prosemirror/runFormattingReconciliation.js +10 -9
  138. package/dist/prosemirror/schema/nodes.d.ts +2 -0
  139. package/dist/prosemirror/styles/paragraphStyleCascade.d.ts +59 -0
  140. package/dist/prosemirror/styles/paragraphStyleCascade.js +145 -0
  141. package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +21 -2
  142. package/dist/prosemirror/styles/resolvedStyleAttrs.js +38 -1
  143. package/dist/prosemirror/styles/tableStyleRegions.d.ts +31 -0
  144. package/dist/prosemirror/styles/tableStyleRegions.js +55 -0
  145. package/dist/prosemirror/tableCellPaste.d.ts +74 -0
  146. package/dist/prosemirror/tableCellPaste.js +525 -0
  147. package/dist/prosemirror/tableGridMutation.d.ts +53 -14
  148. package/dist/prosemirror/tableGridMutation.js +166 -18
  149. package/dist/prosemirror/tableRunIn.d.ts +51 -0
  150. package/dist/prosemirror/tableRunIn.js +165 -0
  151. package/dist/prosemirror/textInput.js +11 -2
  152. package/dist/prosemirror/trackedRevisionPath.d.ts +17 -0
  153. package/dist/prosemirror/trackedRevisionPath.js +32 -0
  154. package/dist/server.d.ts +2 -2
  155. package/package.json +6 -6
@@ -1,6 +1,4 @@
1
1
  import { document_d_exports } from "../../types/document.js";
2
- import { StyleEngine } from "../../style-engine/styleEngine.js";
3
- import "../../style-engine/index.js";
4
2
  import { ParseContext } from "../../docx/parseContext.js";
5
3
  import { Node } from "prosemirror-model";
6
4
  //#region src/prosemirror/conversion/toProseDoc.d.ts
@@ -25,16 +23,6 @@ type ToProseDocOptions = {
25
23
  * @param options - Conversion options including style definitions
26
24
  */
27
25
  declare function toProseDoc(document: document_d_exports.Document, options?: ToProseDocOptions): Node;
28
- /**
29
- * Resolve an embedded character-style reference without importing
30
- * `docDefaults`. The caller already has the paragraph cascade, including
31
- * document defaults, and will layer these own properties over it.
32
- */
33
- type ParagraphDefaultFormattingResolver = Pick<StyleEngine, "getStyle" | "getDocDefaults" | "getDefaultParagraphStyle" | "getDefaultCharacterStyle" | "getRunStyleOwnProperties">;
34
- /** @internal Recompute a paragraph's inherited run defaults from authored package state. */
35
- declare function resolveParagraphDefaultTextFormatting(styleId: string | undefined, formatting: document_d_exports.Paragraph["formatting"] | undefined, styleResolver: ParagraphDefaultFormattingResolver, options?: {
36
- includeParagraphMarkRunProperties?: boolean;
37
- }): document_d_exports.TextFormatting | undefined;
38
26
  declare function standaloneTableCellToProseMirror(cell: document_d_exports.TableCell, nodeType: "tableCell" | "tableHeader"): Node;
39
27
  /**
40
28
  * Convert HeaderFooter content (array of Paragraph/Table blocks) to a ProseMirror document.
@@ -51,4 +39,4 @@ declare function footnoteToProseDoc(content: document_d_exports.BlockContent[],
51
39
  */
52
40
  declare function createEmptyDoc(): Node;
53
41
  //#endregion
54
- export { ToProseDocOptions, createEmptyDoc, footnoteToProseDoc, headerFooterToProseDoc, resolveParagraphDefaultTextFormatting, standaloneTableCellToProseMirror, toProseDoc };
42
+ export { ToProseDocOptions, createEmptyDoc, footnoteToProseDoc, headerFooterToProseDoc, standaloneTableCellToProseMirror, toProseDoc };
@@ -1,19 +1,19 @@
1
1
  import { rangedCommentIds } from "../../docx/commentAnchorIndex.js";
2
2
  import { resolveColorValueToHex } from "../../docx/drawingUtils.js";
3
3
  import { isInlineSdtContent, isTrackedChangeWrapperChild } from "../../docx/inlineWrapperContent.js";
4
- import { mergeParagraphNumbering as mergeParagraphNumbering$1, paragraphNumberingReferenceId as paragraphNumberingReferenceId$1 } from "../../docx/numberingReference.js";
5
4
  import { PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, createProseParagraphWithPropertySource, getDocumentParagraphPropertySourceContract, proseParagraphAttrsWithoutPropertySource, recreateProseNodeWithParagraphPropertySource, transportTableCellsWithParagraphPropertySources } from "../../docx/paragraphPropertySource.js";
6
5
  import { isBaselineVertAlign } from "../../docx/runParser.js";
7
6
  import { replayableShapeAlternateContent } from "../../docx/shapeAlternateContent.js";
8
7
  import { resolveTableLook } from "../../docx/tableLook.js";
9
8
  import { isCellMergeContinuation } from "../../docx/tableParser.js";
9
+ import { calculateRowSpans } from "../../docx/verticalMergeProjection.js";
10
10
  import { copiedWrapPolygon } from "../../docx/wrapPolygon.js";
11
11
  import { buildPageBreakRunSourceDescendantIndex } from "../../internal/pageBreakRunSourceDescendantIndex.js";
12
12
  import { createStyleEngine } from "../../style-engine/styleEngine.js";
13
13
  import { outlineAttrForDash } from "../../types/documentEnumValues.js";
14
14
  import { cssBorderStyleForDash } from "../../utils/borderCss.js";
15
15
  import { normalizeHorizontalScalePercent } from "../../utils/horizontalScale.js";
16
- import { mergeParagraphFormatting, mergeParagraphTabStops } from "../../utils/paragraphFormattingMerge.js";
16
+ import { mergeParagraphFormatting } from "../../utils/paragraphFormattingMerge.js";
17
17
  import { tableOfContentsStyleLevel } from "../../utils/tableOfContentsStyle.js";
18
18
  import { mergeTextFormatting } from "../../utils/textFormattingMerge.js";
19
19
  import { emuToPixels, emuToStrokePixels } from "../../utils/units.js";
@@ -35,14 +35,15 @@ import { stampNumberedRefFieldBaselines } from "../numberedRefFields.js";
35
35
  import { paragraphNumberingAttr } from "../numberingAttr.js";
36
36
  import { pageBreakRunParagraphProjectionDispositionForFeatures } from "../pageBreakRunProjection.js";
37
37
  import { directionFromBidi } from "../paragraphDirection.js";
38
- import { styleResolvedParagraphFormatting } from "../paragraphFormattingProvenance.js";
39
38
  import { lineSpacingProvenanceFromSpacing } from "../paragraphSpacing.js";
40
39
  import { RUN_IDENTITY_MARK_NAME, hasRunIdentityPayload, runIdentityAttrs } from "../runIdentity.js";
41
40
  import { continueRunIdentitiesAcrossRevisions } from "../runIdentityAcrossRevisions.js";
42
41
  import { getParagraphMarkSuppressionOverrides, hasDirectRunFormatting, resolveParagraphBodyRunFormatting, stripParagraphMarkFormattingForBodyRuns, stripParagraphMarkOnlyFormatting, suppressParagraphMarkFormatting } from "../runStyleFormatting.js";
43
42
  import { schema } from "../schema/index.js";
44
43
  import { PRESERVED_XML_LEVELS } from "../schema/nodes.js";
44
+ import { extractTableParagraphOverlay, paragraphStyleCascadeAttrs, resolveRunFormattingWithoutDefaults } from "../styles/paragraphStyleCascade.js";
45
45
  import { cascadeStyleTextFormatting } from "../styles/styleToggleCascade.js";
46
+ import { tableCellStyleRegions, tableRowBand } from "../styles/tableStyleRegions.js";
46
47
  import { canCarryTrackedRunMark, trackedRunInlineAtomDisposition } from "../trackedRunInlineAtoms.js";
47
48
  import { assertValidProseMirrorDocument } from "../validation.js";
48
49
  import { resolveEffectiveTableCellFormatting } from "./effectiveTableCellFormatting.js";
@@ -772,54 +773,15 @@ function paragraphFormattingToAttrs(paragraph, styleResolver, tableParagraphOver
772
773
  };
773
774
  let stylePpr;
774
775
  if (styleResolver) {
775
- stylePpr = styleResolver.resolveParagraphStyleInTable(styleId, tableParagraphOverlay).paragraphFormatting;
776
- const resolvedFormatting = styleResolvedParagraphFormatting(stylePpr);
777
- if (resolvedFormatting) attrs._resolvedFormatting = resolvedFormatting;
778
- set("alignment", formatting?.alignment ?? stylePpr?.alignment);
779
- set("alignmentFromStyle", stylePpr?.alignment);
780
- set("spaceBefore", formatting?.spaceBefore ?? stylePpr?.spaceBefore);
781
- set("spaceAfter", formatting?.spaceAfter ?? stylePpr?.spaceAfter);
782
- set("lineSpacing", formatting?.lineSpacing ?? stylePpr?.lineSpacing);
783
- set("lineSpacingRule", formatting?.lineSpacingRule ?? stylePpr?.lineSpacingRule);
784
- set("lineSpacingExplicit", lineSpacingProvenanceFromSpacing(formatting));
785
- set("snapToGrid", formatting?.snapToGrid ?? stylePpr?.snapToGrid);
786
- set("spacingExplicit", formatting?.spacingExplicit);
787
- const paragraphStyle = styleId ? styleResolver.getStyle(styleId) ?? styleResolver.getDefaultParagraphStyle() : styleResolver.getDefaultParagraphStyle();
788
- const docDefaultSpacing = styleResolver.getDocDefaults()?.pPr;
789
- const spacingFromStyle = {};
790
- if (formatting?.spaceBefore === void 0 && stylePpr?.spaceBefore !== void 0) spacingFromStyle.before = true;
791
- if (formatting?.spaceAfter === void 0 && stylePpr?.spaceAfter !== void 0) spacingFromStyle.after = true;
792
- if (spacingFromStyle.before || spacingFromStyle.after) attrs.spacingFromImplicitDefaultStyle = spacingFromStyle;
793
- const spacingFromDocDefaults = {};
794
- if (formatting?.spaceBefore === void 0 && tableParagraphOverlay?.spaceBefore === void 0 && paragraphStyle?.pPr?.spaceBefore === void 0 && docDefaultSpacing?.spaceBefore !== void 0) spacingFromDocDefaults.before = true;
795
- if (formatting?.spaceAfter === void 0 && tableParagraphOverlay?.spaceAfter === void 0 && paragraphStyle?.pPr?.spaceAfter === void 0 && docDefaultSpacing?.spaceAfter !== void 0) spacingFromDocDefaults.after = true;
796
- if (spacingFromDocDefaults.before || spacingFromDocDefaults.after) attrs.spacingFromDocDefaults = spacingFromDocDefaults;
797
- const effectiveIndent = mergeParagraphFormatting(formatting?.numPr?.kind === "none" && paragraphNumberingReferenceId$1(stylePpr?.numPr) !== void 0 ? void 0 : stylePpr, formatting);
798
- set("indentLeft", effectiveIndent?.indentLeft);
799
- set("indentRight", formatting?.indentRight ?? stylePpr?.indentRight);
800
- set("indentFirstLine", effectiveIndent?.indentFirstLine);
801
- set("hangingIndent", effectiveIndent?.hangingIndent);
802
- set("borders", formatting?.borders ?? stylePpr?.borders);
803
- set("shading", formatting?.shading ?? stylePpr?.shading);
804
- set("tabs", mergeParagraphTabStops(stylePpr?.tabs, formatting?.tabs));
805
- set("kinsoku", formatting?.kinsoku ?? stylePpr?.kinsoku);
806
- set("overflowPunctuation", formatting?.overflowPunctuation ?? stylePpr?.overflowPunctuation);
807
- set("suppressAutoHyphens", formatting?.suppressAutoHyphens ?? stylePpr?.suppressAutoHyphens);
808
- set("pageBreakBefore", formatting?.pageBreakBefore ?? stylePpr?.pageBreakBefore);
809
- set("keepNext", formatting?.keepNext ?? stylePpr?.keepNext);
810
- set("keepLines", formatting?.keepLines ?? stylePpr?.keepLines);
811
- set("widowControl", formatting?.widowControl ?? stylePpr?.widowControl);
812
- set("contextualSpacing", formatting?.contextualSpacing ?? stylePpr?.contextualSpacing);
813
- set("runInWithNext", formatting?.runInWithNext ?? stylePpr?.runInWithNext);
814
- set("outlineLevel", formatting?.outlineLevel ?? stylePpr?.outlineLevel);
815
- set("direction", directionFromBidi(formatting?.bidi ?? stylePpr?.bidi));
816
- set("defaultTextFormatting", resolveParagraphDefaultTextFormatting(styleId, formatting, styleResolver, { includeParagraphMarkRunProperties: tableOfContentsLevel === void 0 && (styleId === void 0 || paragraph.content.length === 0) }));
817
- const styleNumbering = stylePpr?.numPr;
818
- if (styleNumbering?.kind === "reference" && (formatting?.numPr === void 0 || formatting.numPr.kind === "levelOnly")) {
819
- const merged = mergeParagraphNumbering$1(styleNumbering, formatting?.numPr);
820
- if (merged !== void 0) attrs.numPr = paragraphNumberingAttr(merged);
821
- attrs.numPrFromStyle = paragraphNumberingAttr(styleNumbering);
822
- }
776
+ const cascade = paragraphStyleCascadeAttrs({
777
+ styleId,
778
+ formatting,
779
+ styleResolver,
780
+ tableParagraphOverlay,
781
+ includeParagraphMarkRunProperties: tableOfContentsLevel === void 0 && (styleId === void 0 || paragraph.content.length === 0)
782
+ });
783
+ stylePpr = cascade.stylePpr;
784
+ Object.assign(attrs, cascade.attrs);
823
785
  } else {
824
786
  set("alignment", formatting?.alignment);
825
787
  set("spaceBefore", formatting?.spaceBefore);
@@ -867,21 +829,6 @@ function paragraphFormattingToAttrs(paragraph, styleResolver, tableParagraphOver
867
829
  };
868
830
  }
869
831
  /**
870
- * Pick the modeled paragraph fields out of a table style's (or conditional
871
- * region's) `w:pPr` for use as the cell-paragraph cascade overlay.
872
- */
873
- function extractTableParagraphOverlay(pPr) {
874
- if (!pPr) return;
875
- const overlay = {};
876
- if (pPr.spaceBefore !== void 0) overlay.spaceBefore = pPr.spaceBefore;
877
- if (pPr.spaceAfter !== void 0) overlay.spaceAfter = pPr.spaceAfter;
878
- if (pPr.lineSpacing !== void 0) overlay.lineSpacing = pPr.lineSpacing;
879
- if (pPr.lineSpacingRule !== void 0) overlay.lineSpacingRule = pPr.lineSpacingRule;
880
- if (pPr.contextualSpacing !== void 0) overlay.contextualSpacing = pPr.contextualSpacing;
881
- if (pPr.frame !== void 0) overlay.frame = pPr.frame;
882
- return Object.keys(overlay).length > 0 ? overlay : void 0;
883
- }
884
- /**
885
832
  * Resolve table style conditional formatting
886
833
  */
887
834
  function resolveTableStyleConditional(styleResolver, tableStyleId, conditionType) {
@@ -947,157 +894,6 @@ function resolveTextFormatting(formatting, styleResolver) {
947
894
  if (!styleResolver) return formatting;
948
895
  return mergeTextFormatting(styleResolver.resolveRunStyle(formatting.styleId), formatting);
949
896
  }
950
- function resolveRunFormattingWithoutDefaults(formatting, styleResolver) {
951
- if (!formatting || !styleResolver) return formatting;
952
- return cascadeStyleTextFormatting([{
953
- formatting: formatting.styleId ? styleResolver.getRunStyleOwnProperties(formatting.styleId) : void 0,
954
- type: "style"
955
- }, {
956
- formatting,
957
- type: "direct"
958
- }]).formatting;
959
- }
960
- /** @internal Recompute a paragraph's inherited run defaults from authored package state. */
961
- function resolveParagraphDefaultTextFormatting(styleId, formatting, styleResolver, options = {}) {
962
- const style = styleId ? styleResolver.getStyle(styleId) ?? styleResolver.getDefaultParagraphStyle() : styleResolver.getDefaultParagraphStyle();
963
- const paragraphStyleRpr = style?.type === "paragraph" ? style.rPr : void 0;
964
- const rawParagraphMarkRpr = options.includeParagraphMarkRunProperties === false ? void 0 : formatting?.runProperties;
965
- const paragraphRunProperties = rawParagraphMarkRpr ? stripParagraphMarkOnlyFormatting(resolveRunFormattingWithoutDefaults(rawParagraphMarkRpr, styleResolver) ?? {}) : void 0;
966
- const orderedBodyToggleFormatting = cascadeStyleTextFormatting([
967
- {
968
- formatting: styleResolver.getDocDefaults()?.rPr,
969
- type: "defaults"
970
- },
971
- {
972
- formatting: paragraphStyleRpr,
973
- type: "style"
974
- },
975
- {
976
- formatting: styleResolver.getDefaultCharacterStyle()?.rPr,
977
- type: "style"
978
- }
979
- ], { ordinaryFormatting: mergeTextFormatting(mergeTextFormatting(styleResolver.getDocDefaults()?.rPr, styleResolver.getDefaultCharacterStyle()?.rPr), paragraphStyleRpr) });
980
- const bodyRunDefaults = orderedBodyToggleFormatting.formatting;
981
- return cascadeStyleTextFormatting([{
982
- cascade: orderedBodyToggleFormatting,
983
- type: "carried"
984
- }, {
985
- formatting: paragraphRunProperties,
986
- type: "direct"
987
- }], { ordinaryFormatting: mergeTextFormatting(bodyRunDefaults, paragraphRunProperties) }).formatting;
988
- }
989
- function calculateRowSpans(table) {
990
- const result = /* @__PURE__ */ new Map();
991
- const numRows = table.rows.length;
992
- const activeMerges = /* @__PURE__ */ new Map();
993
- for (let rowIndex = 0; rowIndex < numRows; rowIndex++) {
994
- const row = table.rows[rowIndex];
995
- if (row.cells.length === 0) {
996
- clearActiveVerticalMerges(activeMerges, result);
997
- continue;
998
- }
999
- let colIndex = row.formatting?.gridBefore ?? 0;
1000
- const rowCells = row.cells.map((cell) => {
1001
- const colspan = cell.formatting?.gridSpan ?? 1;
1002
- const vMerge = cell.formatting?.vMerge;
1003
- const isMergeContinuation = isCellMergeContinuation(cell);
1004
- const startRow = isMergeContinuation ? activeMerges.get(colIndex) : void 0;
1005
- const info = {
1006
- cell,
1007
- colIndex,
1008
- colspan,
1009
- vMerge,
1010
- isMergeContinuation,
1011
- startRow,
1012
- hasMeaningfulContent: tableCellHasMeaningfulContent(cell),
1013
- shouldSkip: isMergeContinuation && startRow !== void 0
1014
- };
1015
- colIndex += colspan;
1016
- return info;
1017
- });
1018
- const rowWouldBeEmpty = rowCells.length > 0 && rowCells.every((cell) => cell.shouldSkip);
1019
- for (const cellInfo of rowCells) {
1020
- const { colIndex: cellColIndex, vMerge, isMergeContinuation, startRow, hasMeaningfulContent } = cellInfo;
1021
- const key = `${rowIndex}-${cellColIndex}`;
1022
- if (vMerge === "restart") {
1023
- closeVerticalMerge(activeMerges, result, cellColIndex);
1024
- activeMerges.set(cellColIndex, rowIndex);
1025
- result.set(key, {
1026
- rowSpan: 1,
1027
- skip: false
1028
- });
1029
- } else if (isMergeContinuation) {
1030
- if (startRow === void 0 || rowWouldBeEmpty || hasMeaningfulContent) {
1031
- result.set(key, {
1032
- rowSpan: 1,
1033
- skip: false
1034
- });
1035
- if ((rowWouldBeEmpty || hasMeaningfulContent) && startRow !== void 0) {
1036
- const restartCell = result.get(`${startRow}-${cellColIndex}`);
1037
- if (restartCell) restartCell.preserveVMergeRestart = true;
1038
- activeMerges.delete(cellColIndex);
1039
- }
1040
- continue;
1041
- }
1042
- const startKey = `${startRow}-${cellColIndex}`;
1043
- const startCell = result.get(startKey);
1044
- if (startCell) {
1045
- startCell.rowSpan++;
1046
- startCell.continuationCells ??= [];
1047
- startCell.continuationCells.push(cellInfo.cell);
1048
- }
1049
- result.set(key, {
1050
- rowSpan: 1,
1051
- skip: true
1052
- });
1053
- } else {
1054
- closeVerticalMerge(activeMerges, result, cellColIndex);
1055
- result.set(key, {
1056
- rowSpan: 1,
1057
- skip: false
1058
- });
1059
- }
1060
- }
1061
- }
1062
- clearActiveVerticalMerges(activeMerges, result);
1063
- return result;
1064
- }
1065
- /**
1066
- * End the vertical merge active in one column.
1067
- *
1068
- * A `w:vMerge="restart"` is carried through the editor by its cell's rowspan,
1069
- * which only exists once a continuation joins it. A merge that closes with a
1070
- * rowspan of 1 — a restart with no continuation, one interrupted by a plain
1071
- * cell, one whose continuation is in a row a revision removed — has nothing
1072
- * but this flag to say the cell was a merge origin, and dropping it changes
1073
- * the table's visible structure.
1074
- */
1075
- function closeVerticalMerge(activeMerges, result, colIndex) {
1076
- const startRow = activeMerges.get(colIndex);
1077
- if (startRow === void 0) return;
1078
- const restartCell = result.get(`${startRow}-${colIndex}`);
1079
- if (restartCell && restartCell.rowSpan === 1) restartCell.preserveVMergeRestart = true;
1080
- activeMerges.delete(colIndex);
1081
- }
1082
- function clearActiveVerticalMerges(activeMerges, result) {
1083
- for (const colIndex of [...activeMerges.keys()]) closeVerticalMerge(activeMerges, result, colIndex);
1084
- }
1085
- function tableCellHasMeaningfulContent(cell) {
1086
- return cell.content.some(blockHasMeaningfulContent);
1087
- }
1088
- function blockHasMeaningfulContent(block) {
1089
- if (block.type === "preservedBlock") return true;
1090
- if (block.type === "bookmarkStart" || block.type === "bookmarkEnd") return true;
1091
- if (block.type === "table") return block.rows.some((row) => row.cells.some((cell) => tableCellHasMeaningfulContent(cell)));
1092
- if (block.type === "blockSdt" || block.type === "blockCustomXml") return true;
1093
- return block.content.some(paragraphContentHasMeaningfulContent);
1094
- }
1095
- function paragraphContentHasMeaningfulContent(content) {
1096
- if (content.type === "run") return content.content.length > 0;
1097
- if (content.type === "hyperlink") return content.children.some(paragraphContentHasMeaningfulContent);
1098
- if (content.type === "insertion" || content.type === "deletion" || content.type === "moveFrom" || content.type === "moveTo") return content.content.some(paragraphContentHasMeaningfulContent);
1099
- return true;
1100
- }
1101
897
  function convertTable(table, styleResolver, context) {
1102
898
  for (const row of table.rows) for (const cell of row.cells) {
1103
899
  if (isCellMergeContinuation(cell) && context.pageBreakRunSourceDescendants.containsPageBreakRun(cell.content)) {
@@ -1170,24 +966,13 @@ function convertTable(table, styleResolver, context) {
1170
966
  setCS("neCell", "neCell");
1171
967
  setCS("swCell", "swCell");
1172
968
  setCS("seCell", "seCell");
1173
- const bandingEnabledH = !look.noHBand;
1174
- const bandingEnabledV = !look.noVBand;
1175
- let dataRowIndex = 0;
1176
969
  const totalRows = table.rows.length;
1177
970
  const gridColumnCount = columnWidths?.length ?? 0;
1178
971
  const totalColumns = gridColumnCount > 0 ? gridColumnCount : countTableColumns(table.rows);
1179
972
  const rows = table.rows.map((row, rowIndex) => {
1180
973
  const isFirstRowStyled = rowIndex === 0 && look.firstRow;
1181
- const isLastRow = rowIndex === totalRows - 1 && look.lastRow;
1182
- const rowBandStyle = (() => {
1183
- if (bandingEnabledH && !isFirstRowStyled && !isLastRow) return (() => {
1184
- if (dataRowIndex % 2 === 0) return conditionalStyles.band1Horz;
1185
- return conditionalStyles.band2Horz;
1186
- })();
1187
- })();
1188
- if (bandingEnabledH && !isFirstRowStyled && !isLastRow) dataRowIndex++;
1189
974
  const resolvedRowJustification = tableStyle?.trPr?.justification ?? fallbackTableStyle?.trPr?.justification;
1190
- return convertTableRow(row, styleResolver, context, isFirstRowStyled, columnWidths, totalWidth, conditionalStyles, rowBandStyle, bandingEnabledV, look, resolvedTableBorders, rowIndex, totalRows, totalColumns, rowSpanMap, cellMarginsAttr, resolvedRowJustification);
975
+ return convertTableRow(row, styleResolver, context, isFirstRowStyled, columnWidths, totalWidth, conditionalStyles, tableRowBand(look, rowIndex, totalRows), look, resolvedTableBorders, rowIndex, totalRows, totalColumns, rowSpanMap, cellMarginsAttr, resolvedRowJustification);
1191
976
  });
1192
977
  return schema.node("table", attrs, rows);
1193
978
  }
@@ -1217,7 +1002,7 @@ function createOmittedGridSlotCell({ colspan, slot, columnWidths, totalWidth, st
1217
1002
  /**
1218
1003
  * Convert a TableRow to a ProseMirror table row node
1219
1004
  */
1220
- function convertTableRow(row, styleResolver, context, isHeaderRow, columnWidths, totalWidth, conditionalStyles, rowBandStyle, bandingEnabledV, tableLook, tableBorders, rowIndex, totalRows, totalColumns, rowSpanMap, defaultCellMargins, resolvedJustification) {
1005
+ function convertTableRow(row, styleResolver, context, isHeaderRow, columnWidths, totalWidth, conditionalStyles, rowBand, tableLook, tableBorders, rowIndex, totalRows, totalColumns, rowSpanMap, defaultCellMargins, resolvedJustification) {
1221
1006
  const attrsWithoutStructuralChange = { isHeader: !!row.formatting?.header };
1222
1007
  if (row.formatting?.height?.value !== void 0) attrsWithoutStructuralChange.height = row.formatting.height.value;
1223
1008
  if (row.formatting?.heightRule) attrsWithoutStructuralChange.heightRule = row.formatting.heightRule;
@@ -1267,8 +1052,6 @@ function convertTableRow(row, styleResolver, context, isHeaderRow, columnWidths,
1267
1052
  const isFirstRow = rowIndex === 0;
1268
1053
  const isLastRow = rowIndex === (totalRows ?? 1) - 1;
1269
1054
  const rowCnf = row.formatting?.conditionalFormat;
1270
- const rowIsFirstRow = rowCnf?.firstRow ?? isFirstRow;
1271
- const rowIsLastRow = rowCnf?.lastRow ?? isLastRow;
1272
1055
  const totalCols = totalColumns != null && totalColumns > 0 ? totalColumns : Math.max(numCells, 1);
1273
1056
  let effectiveCells = row.cells;
1274
1057
  const uncoveredColumns = Math.max(0, totalCols - gridBefore - gridAfter);
@@ -1307,35 +1090,18 @@ function convertTableRow(row, styleResolver, context, isHeaderRow, columnWidths,
1307
1090
  if (shouldSkip) continue;
1308
1091
  const isFirstCol = colIndex - colspan === 0;
1309
1092
  const isLastCol = colIndex === totalCols;
1310
- const cellCnf = cell.formatting?.conditionalFormat;
1311
- const cellIsFirstRow = cellCnf?.firstRow ?? rowIsFirstRow;
1312
- const cellIsLastRow = cellCnf?.lastRow ?? rowIsLastRow;
1313
- const cellIsFirstCol = cellCnf?.firstColumn ?? isFirstCol;
1314
- const cellIsLastCol = cellCnf?.lastColumn ?? isLastCol;
1315
- let vertBandStyle;
1316
- if (bandingEnabledV) {
1317
- const firstColOffset = tableLook?.firstColumn ? 1 : 0;
1318
- const bandColIndex = colIndex - colspan - firstColOffset;
1319
- if (bandColIndex >= 0 && !(tableLook?.lastColumn && cellIsLastCol) && !(tableLook?.firstColumn && cellIsFirstCol)) vertBandStyle = bandColIndex % 2 === 0 ? conditionalStyles?.band1Vert : conditionalStyles?.band2Vert;
1320
- }
1321
- if (cellCnf?.oddVBand) vertBandStyle = conditionalStyles?.band1Vert;
1322
- else if (cellCnf?.evenVBand) vertBandStyle = conditionalStyles?.band2Vert;
1323
- let effectiveRowBandStyle = rowBandStyle;
1324
- if (rowCnf?.oddHBand) effectiveRowBandStyle = conditionalStyles?.band1Horz;
1325
- else if (rowCnf?.evenHBand) effectiveRowBandStyle = conditionalStyles?.band2Horz;
1326
- if (cellCnf?.oddHBand) effectiveRowBandStyle = conditionalStyles?.band1Horz;
1327
- else if (cellCnf?.evenHBand) effectiveRowBandStyle = conditionalStyles?.band2Horz;
1328
- let cellConditionalStyle = conditionalStyles?.wholeTable;
1329
- cellConditionalStyle = mergeConditionalStyles(cellConditionalStyle, effectiveRowBandStyle);
1330
- cellConditionalStyle = mergeConditionalStyles(cellConditionalStyle, vertBandStyle);
1331
- if (cellIsFirstCol && (tableLook?.firstColumn || rowCnf?.firstColumn || cellCnf?.firstColumn)) cellConditionalStyle = mergeConditionalStyles(cellConditionalStyle, conditionalStyles?.firstCol);
1332
- if (cellIsLastCol && (tableLook?.lastColumn || rowCnf?.lastColumn || cellCnf?.lastColumn)) cellConditionalStyle = mergeConditionalStyles(cellConditionalStyle, conditionalStyles?.lastCol);
1333
- if (cellIsFirstRow && (tableLook?.firstRow || rowCnf?.firstRow || cellCnf?.firstRow)) cellConditionalStyle = mergeConditionalStyles(cellConditionalStyle, conditionalStyles?.firstRow);
1334
- if (cellIsLastRow && (tableLook?.lastRow || rowCnf?.lastRow || cellCnf?.lastRow)) cellConditionalStyle = mergeConditionalStyles(cellConditionalStyle, conditionalStyles?.lastRow);
1335
- if (cellIsFirstRow && cellIsFirstCol && (tableLook?.firstRow || rowCnf?.firstRow || cellCnf?.firstRow) && (tableLook?.firstColumn || rowCnf?.firstColumn || cellCnf?.firstColumn)) cellConditionalStyle = mergeConditionalStyles(cellConditionalStyle, conditionalStyles?.nwCell);
1336
- if (cellIsFirstRow && cellIsLastCol && (tableLook?.firstRow || rowCnf?.firstRow || cellCnf?.firstRow) && (tableLook?.lastColumn || rowCnf?.lastColumn || cellCnf?.lastColumn)) cellConditionalStyle = mergeConditionalStyles(cellConditionalStyle, conditionalStyles?.neCell);
1337
- if (cellIsLastRow && cellIsFirstCol && (tableLook?.lastRow || rowCnf?.lastRow || cellCnf?.lastRow) && (tableLook?.firstColumn || rowCnf?.firstColumn || cellCnf?.firstColumn)) cellConditionalStyle = mergeConditionalStyles(cellConditionalStyle, conditionalStyles?.swCell);
1338
- if (cellIsLastRow && cellIsLastCol && (tableLook?.lastRow || rowCnf?.lastRow || cellCnf?.lastRow) && (tableLook?.lastColumn || rowCnf?.lastColumn || cellCnf?.lastColumn)) cellConditionalStyle = mergeConditionalStyles(cellConditionalStyle, conditionalStyles?.seCell);
1093
+ let cellConditionalStyle;
1094
+ for (const region of tableCellStyleRegions({
1095
+ look: tableLook ?? resolveTableLook(void 0),
1096
+ rowIndex: rowIndex ?? 0,
1097
+ totalRows: totalRows ?? 1,
1098
+ column: colIndex - colspan,
1099
+ colspan,
1100
+ totalColumns: totalCols,
1101
+ rowBand,
1102
+ rowConditionalFormat: rowCnf,
1103
+ cellConditionalFormat: cell.formatting?.conditionalFormat
1104
+ })) cellConditionalStyle = mergeConditionalStyles(cellConditionalStyle, conditionalStyles?.[region]);
1339
1105
  cells.push(convertTableCell({
1340
1106
  cell,
1341
1107
  styleResolver,
@@ -2959,4 +2725,4 @@ function createEmptyDoc() {
2959
2725
  return schema.node("doc", null, [schema.node("paragraph", {}, [])]);
2960
2726
  }
2961
2727
  //#endregion
2962
- export { createEmptyDoc, footnoteToProseDoc, headerFooterToProseDoc, resolveParagraphDefaultTextFormatting, standaloneTableCellToProseMirror, toProseDoc };
2728
+ export { createEmptyDoc, footnoteToProseDoc, headerFooterToProseDoc, standaloneTableCellToProseMirror, toProseDoc };
@@ -0,0 +1,8 @@
1
+ import { MarkType, Schema } from "prosemirror-model";
2
+ //#region src/prosemirror/documentSchema.d.ts
3
+ /** `type`'s counterpart in the schema of `state`. */
4
+ declare const documentMarkType: (state: {
5
+ readonly schema: Schema;
6
+ }, type: MarkType) => MarkType;
7
+ //#endregion
8
+ export { documentMarkType };
@@ -0,0 +1,18 @@
1
+ import { panic } from "better-result";
2
+ //#region src/prosemirror/documentSchema.ts
3
+ /**
4
+ * The document's own mark types.
5
+ *
6
+ * An extension sees the schema its runtime was built with, but the editor it
7
+ * runs in may hold a document of another schema instance with the same specs:
8
+ * header, footer and note editors each build a runtime of their own, while
9
+ * every document is parsed into the shared schema. Marks made from the
10
+ * runtime's types do not belong to such a document, and a runtime type
11
+ * compared against the document's marks never matches. Commands therefore
12
+ * resolve the types they build with, and compare against, through the state
13
+ * they act on.
14
+ */
15
+ /** `type`'s counterpart in the schema of `state`. */
16
+ const documentMarkType = (state, type) => type.schema === state.schema ? type : state.schema.marks[type.name] ?? panic(`The document schema has no mark ${type.name}`);
17
+ //#endregion
18
+ export { documentMarkType };
@@ -11,6 +11,7 @@ import { EmptyParagraphFormatExtension } from "./features/EmptyParagraphFormatEx
11
11
  import { GapCursorExtension } from "./features/GapCursorExtension.js";
12
12
  import { ImageDragExtension } from "./features/ImageDragExtension.js";
13
13
  import { ImagePasteExtension } from "./features/ImagePasteExtension.js";
14
+ import { JoinedRunStyleExtension } from "./features/JoinedRunStyleExtension.js";
14
15
  import { ListExtension } from "./features/ListExtension.js";
15
16
  import { ParaIdAllocatorExtension } from "./features/ParaIdAllocatorExtension.js";
16
17
  import { ParagraphChangeTrackerExtension } from "./features/ParagraphChangeTrackerExtension.js";
@@ -100,6 +101,7 @@ function createStarterKit(options = {}) {
100
101
  add("list", ListExtension());
101
102
  add("baseKeymap", BaseKeymapExtension());
102
103
  add("emptyParagraphFormat", EmptyParagraphFormatExtension());
104
+ add("joinedRunStyle", JoinedRunStyleExtension());
103
105
  add("selectionTracker", options.onSelectionChange === void 0 ? SelectionTrackerExtension() : SelectionTrackerExtension({ onSelectionChange: options.onSelectionChange }));
104
106
  add("paraIdAllocator", ParaIdAllocatorExtension());
105
107
  add("paragraphChangeTracker", ParagraphChangeTrackerExtension());