@stll/folio-core 0.53.0 → 0.54.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.
Files changed (148) hide show
  1. package/dist/ai-edits/apply.js +390 -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 +3 -1
  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/fonts/embeddedFonts.js +1 -1
  41. package/dist/i18n/messages/catalogs.gen.d.ts +34 -34
  42. package/dist/i18n/messages/catalogs.gen.js +34 -34
  43. package/dist/i18n/messages/messages.gen.d.ts +2 -2
  44. package/dist/internal/wholeStoryRevisionResolution.js +95 -25
  45. package/dist/layout-engine/measure/measureParagraph.js +2 -2
  46. package/dist/layout-engine/measure/paragraphMeasureShared.d.ts +12 -1
  47. package/dist/layout-engine/measure/paragraphMeasureShared.js +14 -1
  48. package/dist/markdown/escape.d.ts +2 -2
  49. package/dist/markdown/escape.js +4 -5
  50. package/dist/markdown/renderBlock.js +91 -25
  51. package/dist/markdown/renderRuns.d.ts +10 -1
  52. package/dist/markdown/renderRuns.js +320 -59
  53. package/dist/prosemirror/clearRunColor.d.ts +6 -0
  54. package/dist/prosemirror/clearRunColor.js +46 -0
  55. package/dist/prosemirror/commands/comments.js +56 -21
  56. package/dist/prosemirror/commands/formatPainter.js +1 -1
  57. package/dist/prosemirror/commands/hyperlink.js +2 -1
  58. package/dist/prosemirror/commands/propertyChangeScope.d.ts +3 -2
  59. package/dist/prosemirror/commands/propertyChangeScope.js +24 -3
  60. package/dist/prosemirror/commands/resolveAllTableChanges.js +46 -41
  61. package/dist/prosemirror/commands/resolveParagraphProperties.js +20 -6
  62. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +8 -1
  63. package/dist/prosemirror/commands/tableCellMergeResolution.js +23 -7
  64. package/dist/prosemirror/containerFinalParagraph.d.ts +11 -5
  65. package/dist/prosemirror/containerFinalParagraph.js +7 -6
  66. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -13
  67. package/dist/prosemirror/conversion/fromProseDoc.js +12 -590
  68. package/dist/prosemirror/conversion/toProseDoc.d.ts +4 -11
  69. package/dist/prosemirror/conversion/toProseDoc.js +31 -150
  70. package/dist/prosemirror/documentSchema.d.ts +8 -0
  71. package/dist/prosemirror/documentSchema.js +18 -0
  72. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  73. package/dist/prosemirror/extensions/core/ParagraphExtension.js +104 -63
  74. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
  75. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +24 -3
  76. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +20 -0
  77. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.js +43 -0
  78. package/dist/prosemirror/extensions/features/ListExtension.js +10 -9
  79. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
  80. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +2 -4
  81. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +14 -8
  82. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +8 -4
  83. package/dist/prosemirror/extensions/marks/StrikeExtension.js +2 -2
  84. package/dist/prosemirror/extensions/marks/SubscriptExtension.js +2 -2
  85. package/dist/prosemirror/extensions/marks/SuperscriptExtension.js +2 -2
  86. package/dist/prosemirror/extensions/marks/TextColorExtension.js +4 -3
  87. package/dist/prosemirror/extensions/marks/markUtils.d.ts +8 -6
  88. package/dist/prosemirror/extensions/marks/markUtils.js +17 -8
  89. package/dist/prosemirror/extensions/marks/noteReferenceDeletion.d.ts +3 -1
  90. package/dist/prosemirror/extensions/marks/noteReferenceDeletion.js +12 -1
  91. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +2 -2
  92. package/dist/prosemirror/extensions/nodes/HardBreakExtension.js +5 -3
  93. package/dist/prosemirror/extensions/nodes/TableExtension.js +104 -210
  94. package/dist/prosemirror/extensions/types.d.ts +7 -0
  95. package/dist/prosemirror/hyperlinkRemoval.d.ts +9 -0
  96. package/dist/prosemirror/hyperlinkRemoval.js +129 -0
  97. package/dist/prosemirror/index.d.ts +2 -1
  98. package/dist/prosemirror/index.js +2 -1
  99. package/dist/prosemirror/listNumbering.d.ts +3 -21
  100. package/dist/prosemirror/listNumbering.js +10 -25
  101. package/dist/prosemirror/listRendering.d.ts +27 -0
  102. package/dist/prosemirror/listRendering.js +27 -0
  103. package/dist/prosemirror/markupViewNotes.d.ts +8 -0
  104. package/dist/prosemirror/markupViewNotes.js +49 -0
  105. package/dist/prosemirror/markupViewProjection.d.ts +3 -1
  106. package/dist/prosemirror/markupViewProjection.js +7 -2
  107. package/dist/prosemirror/noteReferenceReview.d.ts +77 -0
  108. package/dist/prosemirror/noteReferenceReview.js +332 -0
  109. package/dist/prosemirror/paragraphIndentation.js +5 -2
  110. package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -4
  111. package/dist/prosemirror/paragraphMarkJoin.js +21 -19
  112. package/dist/prosemirror/paragraphPropertyCarry.d.ts +64 -0
  113. package/dist/prosemirror/paragraphPropertyCarry.js +158 -0
  114. package/dist/prosemirror/plugins/documentStyleState.d.ts +26 -0
  115. package/dist/prosemirror/plugins/documentStyleState.js +32 -0
  116. package/dist/prosemirror/plugins/documentStyles.d.ts +2 -21
  117. package/dist/prosemirror/plugins/documentStyles.js +66 -29
  118. package/dist/prosemirror/plugins/index.d.ts +2 -1
  119. package/dist/prosemirror/plugins/index.js +2 -1
  120. package/dist/prosemirror/plugins/paragraphStyleResolution.d.ts +15 -0
  121. package/dist/prosemirror/plugins/paragraphStyleResolution.js +230 -0
  122. package/dist/prosemirror/plugins/suggestionMode.d.ts +12 -2
  123. package/dist/prosemirror/plugins/suggestionMode.js +391 -28
  124. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +22 -2
  125. package/dist/prosemirror/rebaseParagraphRunFormatting.js +39 -13
  126. package/dist/prosemirror/rebaseParagraphRuns.d.ts +36 -0
  127. package/dist/prosemirror/rebaseParagraphRuns.js +99 -0
  128. package/dist/prosemirror/runFormattingFromMarks.d.ts +18 -0
  129. package/dist/prosemirror/runFormattingFromMarks.js +567 -0
  130. package/dist/prosemirror/runFormattingReconciliation.js +10 -9
  131. package/dist/prosemirror/schema/nodes.d.ts +2 -0
  132. package/dist/prosemirror/styles/paragraphStyleCascade.d.ts +59 -0
  133. package/dist/prosemirror/styles/paragraphStyleCascade.js +145 -0
  134. package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +21 -2
  135. package/dist/prosemirror/styles/resolvedStyleAttrs.js +38 -1
  136. package/dist/prosemirror/styles/tableStyleRegions.d.ts +31 -0
  137. package/dist/prosemirror/styles/tableStyleRegions.js +55 -0
  138. package/dist/prosemirror/tableCellPaste.d.ts +74 -0
  139. package/dist/prosemirror/tableCellPaste.js +525 -0
  140. package/dist/prosemirror/tableGridMutation.d.ts +53 -14
  141. package/dist/prosemirror/tableGridMutation.js +166 -18
  142. package/dist/prosemirror/tableRunIn.d.ts +51 -0
  143. package/dist/prosemirror/tableRunIn.js +165 -0
  144. package/dist/prosemirror/textInput.js +11 -2
  145. package/dist/prosemirror/trackedRevisionPath.d.ts +17 -0
  146. package/dist/prosemirror/trackedRevisionPath.js +32 -0
  147. package/dist/server.d.ts +2 -2
  148. package/package.json +5 -5
@@ -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
@@ -26,15 +24,10 @@ type ToProseDocOptions = {
26
24
  */
27
25
  declare function toProseDoc(document: document_d_exports.Document, options?: ToProseDocOptions): Node;
28
26
  /**
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.
27
+ * Whether a cell carries content a vertical-merge continuation must not hide.
28
+ * The reader keeps such a continuation as a cell of its own.
32
29
  */
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;
30
+ declare function tableCellHasMeaningfulContent(cell: document_d_exports.TableCell): boolean;
38
31
  declare function standaloneTableCellToProseMirror(cell: document_d_exports.TableCell, nodeType: "tableCell" | "tableHeader"): Node;
39
32
  /**
40
33
  * Convert HeaderFooter content (array of Paragraph/Table blocks) to a ProseMirror document.
@@ -51,4 +44,4 @@ declare function footnoteToProseDoc(content: document_d_exports.BlockContent[],
51
44
  */
52
45
  declare function createEmptyDoc(): Node;
53
46
  //#endregion
54
- export { ToProseDocOptions, createEmptyDoc, footnoteToProseDoc, headerFooterToProseDoc, resolveParagraphDefaultTextFormatting, standaloneTableCellToProseMirror, toProseDoc };
47
+ export { ToProseDocOptions, createEmptyDoc, footnoteToProseDoc, headerFooterToProseDoc, standaloneTableCellToProseMirror, tableCellHasMeaningfulContent, toProseDoc };
@@ -1,7 +1,6 @@
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";
@@ -13,7 +12,7 @@ import { createStyleEngine } from "../../style-engine/styleEngine.js";
13
12
  import { outlineAttrForDash } from "../../types/documentEnumValues.js";
14
13
  import { cssBorderStyleForDash } from "../../utils/borderCss.js";
15
14
  import { normalizeHorizontalScalePercent } from "../../utils/horizontalScale.js";
16
- import { mergeParagraphFormatting, mergeParagraphTabStops } from "../../utils/paragraphFormattingMerge.js";
15
+ import { mergeParagraphFormatting } from "../../utils/paragraphFormattingMerge.js";
17
16
  import { tableOfContentsStyleLevel } from "../../utils/tableOfContentsStyle.js";
18
17
  import { mergeTextFormatting } from "../../utils/textFormattingMerge.js";
19
18
  import { emuToPixels, emuToStrokePixels } from "../../utils/units.js";
@@ -35,14 +34,15 @@ import { stampNumberedRefFieldBaselines } from "../numberedRefFields.js";
35
34
  import { paragraphNumberingAttr } from "../numberingAttr.js";
36
35
  import { pageBreakRunParagraphProjectionDispositionForFeatures } from "../pageBreakRunProjection.js";
37
36
  import { directionFromBidi } from "../paragraphDirection.js";
38
- import { styleResolvedParagraphFormatting } from "../paragraphFormattingProvenance.js";
39
37
  import { lineSpacingProvenanceFromSpacing } from "../paragraphSpacing.js";
40
38
  import { RUN_IDENTITY_MARK_NAME, hasRunIdentityPayload, runIdentityAttrs } from "../runIdentity.js";
41
39
  import { continueRunIdentitiesAcrossRevisions } from "../runIdentityAcrossRevisions.js";
42
40
  import { getParagraphMarkSuppressionOverrides, hasDirectRunFormatting, resolveParagraphBodyRunFormatting, stripParagraphMarkFormattingForBodyRuns, stripParagraphMarkOnlyFormatting, suppressParagraphMarkFormatting } from "../runStyleFormatting.js";
43
41
  import { schema } from "../schema/index.js";
44
42
  import { PRESERVED_XML_LEVELS } from "../schema/nodes.js";
43
+ import { extractTableParagraphOverlay, paragraphStyleCascadeAttrs, resolveRunFormattingWithoutDefaults } from "../styles/paragraphStyleCascade.js";
45
44
  import { cascadeStyleTextFormatting } from "../styles/styleToggleCascade.js";
45
+ import { tableCellStyleRegions, tableRowBand } from "../styles/tableStyleRegions.js";
46
46
  import { canCarryTrackedRunMark, trackedRunInlineAtomDisposition } from "../trackedRunInlineAtoms.js";
47
47
  import { assertValidProseMirrorDocument } from "../validation.js";
48
48
  import { resolveEffectiveTableCellFormatting } from "./effectiveTableCellFormatting.js";
@@ -772,54 +772,15 @@ function paragraphFormattingToAttrs(paragraph, styleResolver, tableParagraphOver
772
772
  };
773
773
  let stylePpr;
774
774
  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
- }
775
+ const cascade = paragraphStyleCascadeAttrs({
776
+ styleId,
777
+ formatting,
778
+ styleResolver,
779
+ tableParagraphOverlay,
780
+ includeParagraphMarkRunProperties: tableOfContentsLevel === void 0 && (styleId === void 0 || paragraph.content.length === 0)
781
+ });
782
+ stylePpr = cascade.stylePpr;
783
+ Object.assign(attrs, cascade.attrs);
823
784
  } else {
824
785
  set("alignment", formatting?.alignment);
825
786
  set("spaceBefore", formatting?.spaceBefore);
@@ -867,21 +828,6 @@ function paragraphFormattingToAttrs(paragraph, styleResolver, tableParagraphOver
867
828
  };
868
829
  }
869
830
  /**
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
831
  * Resolve table style conditional formatting
886
832
  */
887
833
  function resolveTableStyleConditional(styleResolver, tableStyleId, conditionType) {
@@ -947,45 +893,6 @@ function resolveTextFormatting(formatting, styleResolver) {
947
893
  if (!styleResolver) return formatting;
948
894
  return mergeTextFormatting(styleResolver.resolveRunStyle(formatting.styleId), formatting);
949
895
  }
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
896
  function calculateRowSpans(table) {
990
897
  const result = /* @__PURE__ */ new Map();
991
898
  const numRows = table.rows.length;
@@ -1082,6 +989,10 @@ function closeVerticalMerge(activeMerges, result, colIndex) {
1082
989
  function clearActiveVerticalMerges(activeMerges, result) {
1083
990
  for (const colIndex of [...activeMerges.keys()]) closeVerticalMerge(activeMerges, result, colIndex);
1084
991
  }
992
+ /**
993
+ * Whether a cell carries content a vertical-merge continuation must not hide.
994
+ * The reader keeps such a continuation as a cell of its own.
995
+ */
1085
996
  function tableCellHasMeaningfulContent(cell) {
1086
997
  return cell.content.some(blockHasMeaningfulContent);
1087
998
  }
@@ -1170,24 +1081,13 @@ function convertTable(table, styleResolver, context) {
1170
1081
  setCS("neCell", "neCell");
1171
1082
  setCS("swCell", "swCell");
1172
1083
  setCS("seCell", "seCell");
1173
- const bandingEnabledH = !look.noHBand;
1174
- const bandingEnabledV = !look.noVBand;
1175
- let dataRowIndex = 0;
1176
1084
  const totalRows = table.rows.length;
1177
1085
  const gridColumnCount = columnWidths?.length ?? 0;
1178
1086
  const totalColumns = gridColumnCount > 0 ? gridColumnCount : countTableColumns(table.rows);
1179
1087
  const rows = table.rows.map((row, rowIndex) => {
1180
1088
  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
1089
  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);
1090
+ return convertTableRow(row, styleResolver, context, isFirstRowStyled, columnWidths, totalWidth, conditionalStyles, tableRowBand(look, rowIndex, totalRows), look, resolvedTableBorders, rowIndex, totalRows, totalColumns, rowSpanMap, cellMarginsAttr, resolvedRowJustification);
1191
1091
  });
1192
1092
  return schema.node("table", attrs, rows);
1193
1093
  }
@@ -1217,7 +1117,7 @@ function createOmittedGridSlotCell({ colspan, slot, columnWidths, totalWidth, st
1217
1117
  /**
1218
1118
  * Convert a TableRow to a ProseMirror table row node
1219
1119
  */
1220
- function convertTableRow(row, styleResolver, context, isHeaderRow, columnWidths, totalWidth, conditionalStyles, rowBandStyle, bandingEnabledV, tableLook, tableBorders, rowIndex, totalRows, totalColumns, rowSpanMap, defaultCellMargins, resolvedJustification) {
1120
+ function convertTableRow(row, styleResolver, context, isHeaderRow, columnWidths, totalWidth, conditionalStyles, rowBand, tableLook, tableBorders, rowIndex, totalRows, totalColumns, rowSpanMap, defaultCellMargins, resolvedJustification) {
1221
1121
  const attrsWithoutStructuralChange = { isHeader: !!row.formatting?.header };
1222
1122
  if (row.formatting?.height?.value !== void 0) attrsWithoutStructuralChange.height = row.formatting.height.value;
1223
1123
  if (row.formatting?.heightRule) attrsWithoutStructuralChange.heightRule = row.formatting.heightRule;
@@ -1267,8 +1167,6 @@ function convertTableRow(row, styleResolver, context, isHeaderRow, columnWidths,
1267
1167
  const isFirstRow = rowIndex === 0;
1268
1168
  const isLastRow = rowIndex === (totalRows ?? 1) - 1;
1269
1169
  const rowCnf = row.formatting?.conditionalFormat;
1270
- const rowIsFirstRow = rowCnf?.firstRow ?? isFirstRow;
1271
- const rowIsLastRow = rowCnf?.lastRow ?? isLastRow;
1272
1170
  const totalCols = totalColumns != null && totalColumns > 0 ? totalColumns : Math.max(numCells, 1);
1273
1171
  let effectiveCells = row.cells;
1274
1172
  const uncoveredColumns = Math.max(0, totalCols - gridBefore - gridAfter);
@@ -1307,35 +1205,18 @@ function convertTableRow(row, styleResolver, context, isHeaderRow, columnWidths,
1307
1205
  if (shouldSkip) continue;
1308
1206
  const isFirstCol = colIndex - colspan === 0;
1309
1207
  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);
1208
+ let cellConditionalStyle;
1209
+ for (const region of tableCellStyleRegions({
1210
+ look: tableLook ?? resolveTableLook(void 0),
1211
+ rowIndex: rowIndex ?? 0,
1212
+ totalRows: totalRows ?? 1,
1213
+ column: colIndex - colspan,
1214
+ colspan,
1215
+ totalColumns: totalCols,
1216
+ rowBand,
1217
+ rowConditionalFormat: rowCnf,
1218
+ cellConditionalFormat: cell.formatting?.conditionalFormat
1219
+ })) cellConditionalStyle = mergeConditionalStyles(cellConditionalStyle, conditionalStyles?.[region]);
1339
1220
  cells.push(convertTableCell({
1340
1221
  cell,
1341
1222
  styleResolver,
@@ -2959,4 +2840,4 @@ function createEmptyDoc() {
2959
2840
  return schema.node("doc", null, [schema.node("paragraph", {}, [])]);
2960
2841
  }
2961
2842
  //#endregion
2962
- export { createEmptyDoc, footnoteToProseDoc, headerFooterToProseDoc, resolveParagraphDefaultTextFormatting, standaloneTableCellToProseMirror, toProseDoc };
2843
+ export { createEmptyDoc, footnoteToProseDoc, headerFooterToProseDoc, standaloneTableCellToProseMirror, tableCellHasMeaningfulContent, 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());
@@ -1,5 +1,6 @@
1
1
  import { BUILT_IN_STYLE_NAME } from "../../../docx/builtInStyles.js";
2
2
  import { PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR } from "../../../docx/paragraphPropertySource.js";
3
+ import { isStyleSourcedParagraphNumbering } from "../../../internal/paragraphFormattingSerialization.js";
3
4
  import { PARAGRAPH_ALIGNMENT_VALUES } from "../../../types/documentEnumValues.js";
4
5
  import { paragraphToStyle } from "../../../utils/formatToStyle.js";
5
6
  import { collectHeadings } from "../../../utils/headingCollector.js";
@@ -7,12 +8,16 @@ import { tableOfContentsStyleLevel } from "../../../utils/tableOfContentsStyle.j
7
8
  import { expectParagraphAttrs } from "../../attrs/index.js";
8
9
  import { autospacingMatchesBase } from "../../autospacingBase.js";
9
10
  import { removeSectionBreakAtSelection, setSectionBreakType } from "../../commands/sectionBreak.js";
11
+ import { CLEARED_LIST_RENDERING_ATTRS } from "../../listMarker.js";
10
12
  import { directParagraphAlignment } from "../../paragraphAlignment.js";
11
13
  import { directionIsRtl } from "../../paragraphDirection.js";
12
- import { withDirectParagraphSpacing } from "../../paragraphSpacing.js";
13
- import { getDocumentBuiltInStyles } from "../../plugins/documentStyles.js";
14
+ import { directParagraphIndentation } from "../../paragraphIndentation.js";
15
+ import { directParagraphSpacing, withDirectParagraphSpacing } from "../../paragraphSpacing.js";
16
+ import { getDocumentNumbering } from "../../plugins/documentNumbering.js";
17
+ import { getDocumentBuiltInStyles, getDocumentStyleResolver } from "../../plugins/documentStyleState.js";
18
+ import { rebaseParagraphRuns } from "../../rebaseParagraphRuns.js";
14
19
  import { mintSectionProperties, parseSectionBreakType, sectionBreakTypeOf } from "../../sectionCarrier.js";
15
- import { listAttrsFromResolvedStyle, paragraphAttrsFromResolvedStyle } from "../../styles/resolvedStyleAttrs.js";
20
+ import { listAttrsFromResolvedStyle, listLevelIndentAttrPatch, paragraphAttrsFromResolvedStyle } from "../../styles/resolvedStyleAttrs.js";
16
21
  import { createNodeExtension } from "../create.js";
17
22
  import { headingOutlineLevel, paragraphNumberingLevel, paragraphNumberingReferenceId } from "@stll/docx-core/model";
18
23
  import { Fragment } from "prosemirror-model";
@@ -399,6 +404,51 @@ function setParagraphSpacingAttr(side, twips) {
399
404
  return true;
400
405
  };
401
406
  }
407
+ const DIRECT_PARAGRAPH_TOGGLES = [
408
+ "outlineLevel",
409
+ "borders",
410
+ "shading",
411
+ "tabs",
412
+ "keepNext",
413
+ "keepLines",
414
+ "widowControl",
415
+ "pageBreakBefore",
416
+ "contextualSpacing"
417
+ ];
418
+ /** The attrs a paragraph states itself, over whatever style it reads. */
419
+ function directParagraphAttrs(attrs) {
420
+ const direct = {};
421
+ const alignment = directParagraphAlignment(attrs);
422
+ if (alignment !== void 0) direct["alignment"] = alignment;
423
+ const spacing = directParagraphSpacing(attrs);
424
+ for (const key of [
425
+ "spaceBefore",
426
+ "spaceAfter",
427
+ "lineSpacing",
428
+ "lineSpacingRule"
429
+ ]) if (spacing?.[key] !== void 0) direct[key] = spacing[key];
430
+ const indentation = directParagraphIndentation(attrs);
431
+ if (indentation?.indentLeft !== void 0) direct["indentLeft"] = indentation.indentLeft;
432
+ if (indentation?.indentRight !== void 0) direct["indentRight"] = indentation.indentRight;
433
+ if (indentation?.indentFirstLine !== void 0) {
434
+ direct["indentFirstLine"] = Math.abs(indentation.indentFirstLine);
435
+ direct["hangingIndent"] = indentation.hangingIndent === true;
436
+ }
437
+ const original = attrs._originalFormatting;
438
+ for (const key of DIRECT_PARAGRAPH_TOGGLES) if (original?.[key] !== void 0) direct[key] = attrs[key];
439
+ return direct;
440
+ }
441
+ /**
442
+ * The indentation a restyled paragraph still states itself: a field its
443
+ * source stated that the new style's attrs keep a value for. Every other
444
+ * field now reads the style's value, which a save leaves to the style.
445
+ */
446
+ function restyledIndentation(styleAttrs, originalFormatting) {
447
+ const stated = {};
448
+ if (originalFormatting?.indentLeft !== void 0 && typeof styleAttrs.indentLeft === "number") stated.indentLeft = styleAttrs.indentLeft;
449
+ if (originalFormatting?.indentFirstLine !== void 0 && typeof styleAttrs.indentFirstLine === "number") stated.indentFirstLine = styleAttrs.indentFirstLine;
450
+ return stated;
451
+ }
402
452
  function setParagraphAttrsCmd(attrs) {
403
453
  return (state, dispatch) => {
404
454
  const { $from, $to } = state.selection;
@@ -479,9 +529,10 @@ function makeDecreaseIndent(amount = 720) {
479
529
  seen.add(pos);
480
530
  const currentIndent = node.attrs["indentLeft"] || 0;
481
531
  const newIndent = Math.max(0, currentIndent - amount);
532
+ const numbered = paragraphNumberingReferenceId(expectParagraphAttrs(node).numPr ?? void 0) !== void 0;
482
533
  tr = tr.setNodeMarkup(pos, void 0, {
483
534
  ...node.attrs,
484
- indentLeft: newIndent > 0 ? newIndent : null
535
+ indentLeft: newIndent > 0 || numbered ? newIndent : null
485
536
  });
486
537
  }
487
538
  });
@@ -489,79 +540,61 @@ function makeDecreaseIndent(amount = 720) {
489
540
  return true;
490
541
  };
491
542
  }
492
- function makeApplyStyle(schema) {
543
+ function makeApplyStyle() {
493
544
  return (styleId, resolvedAttrs) => (state, dispatch) => {
494
545
  const { $from, $to } = state.selection;
495
546
  if (!dispatch) return true;
496
547
  let tr = state.tr;
497
548
  const seen = /* @__PURE__ */ new Set();
498
- const styleMarks = [];
499
- if (resolvedAttrs?.runFormatting) {
500
- const rpr = resolvedAttrs.runFormatting;
501
- if (rpr.bold && schema.marks["bold"]) styleMarks.push(schema.marks["bold"].create());
502
- if (rpr.italic && schema.marks["italic"]) styleMarks.push(schema.marks["italic"].create());
503
- if (rpr.fontSize && schema.marks["fontSize"]) styleMarks.push(schema.marks["fontSize"].create({ size: rpr.fontSize }));
504
- if (rpr.fontFamily && schema.marks["fontFamily"]) styleMarks.push(schema.marks["fontFamily"].create({
505
- ascii: rpr.fontFamily.ascii,
506
- hAnsi: rpr.fontFamily.hAnsi,
507
- asciiTheme: rpr.fontFamily.asciiTheme
508
- }));
509
- if (rpr.color && !rpr.color.auto && schema.marks["textColor"]) styleMarks.push(schema.marks["textColor"].create({
510
- rgb: rpr.color.rgb,
511
- themeColor: rpr.color.themeColor,
512
- themeTint: rpr.color.themeTint,
513
- themeShade: rpr.color.themeShade
514
- }));
515
- if (rpr.underline && rpr.underline.style !== "none" && schema.marks["underline"]) styleMarks.push(schema.marks["underline"].create({
516
- style: rpr.underline.style,
517
- color: rpr.underline.color
518
- }));
519
- if ((rpr.strike || rpr.doubleStrike) && schema.marks["strike"]) styleMarks.push(schema.marks["strike"].create({ double: rpr.doubleStrike || false }));
520
- }
521
- const styleControlledMarks = [
522
- schema.marks["bold"],
523
- schema.marks["italic"],
524
- schema.marks["fontSize"],
525
- schema.marks["fontFamily"],
526
- schema.marks["textColor"],
527
- schema.marks["underline"],
528
- schema.marks["strike"]
529
- ].filter(Boolean);
530
549
  state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
531
550
  if (node.type.name === "paragraph" && !seen.has(pos)) {
532
551
  seen.add(pos);
533
552
  const newAttrs = {
534
553
  ...node.attrs,
535
554
  styleId,
536
- _tableOfContentsLevel: tableOfContentsStyleLevel({ styleId }) ?? null
555
+ _tableOfContentsLevel: styleId ? tableOfContentsStyleLevel({ styleId }) ?? null : null
537
556
  };
538
557
  if (resolvedAttrs) {
539
- Object.assign(newAttrs, paragraphAttrsFromResolvedStyle(resolvedAttrs, {
540
- styleId,
558
+ const current = expectParagraphAttrs(node);
559
+ const styleAttrs = paragraphAttrsFromResolvedStyle(resolvedAttrs, {
560
+ styleId: styleId ?? "",
541
561
  ...resolvedAttrs.styleName ? { styleName: resolvedAttrs.styleName } : {}
542
- }));
543
- const originalFormatting = {
544
- ...expectParagraphAttrs(node)._originalFormatting,
545
- styleId
546
- };
547
- Reflect.deleteProperty(originalFormatting, "alignment");
548
- newAttrs["_originalFormatting"] = withDirectParagraphSpacing(originalFormatting, void 0);
549
- newAttrs["spacingExplicit"] = null;
562
+ });
563
+ Object.assign(newAttrs, styleAttrs);
564
+ if (!styleId) newAttrs["_tableOfContentsLevel"] = null;
565
+ const originalFormatting = { ...current._originalFormatting };
566
+ if (styleId) originalFormatting.styleId = styleId;
567
+ else Reflect.deleteProperty(originalFormatting, "styleId");
568
+ let restyledOriginal = originalFormatting;
569
+ if (styleId) {
570
+ Reflect.deleteProperty(originalFormatting, "alignment");
571
+ Reflect.deleteProperty(originalFormatting, "outlineLevel");
572
+ restyledOriginal = withDirectParagraphSpacing(originalFormatting, void 0);
573
+ newAttrs["spacingExplicit"] = null;
574
+ } else Object.assign(newAttrs, directParagraphAttrs(current));
575
+ newAttrs["_originalFormatting"] = restyledOriginal ?? null;
550
576
  const listAttrs = listAttrsFromResolvedStyle(resolvedAttrs, resolvedAttrs.numbering);
577
+ const directNumId = current.numPrFromStyle == null ? paragraphNumberingReferenceId(current.numPr ?? void 0) : void 0;
551
578
  if (listAttrs) Object.assign(newAttrs, listAttrs);
579
+ else if (isStyleSourcedParagraphNumbering(current.numPr, current.numPrFromStyle)) Object.assign(newAttrs, CLEARED_LIST_RENDERING_ATTRS, {
580
+ numPr: null,
581
+ numPrFromStyle: null
582
+ });
583
+ else if (directNumId !== void 0) Object.assign(newAttrs, listLevelIndentAttrPatch(restyledIndentation(styleAttrs, restyledOriginal), {
584
+ numId: directNumId,
585
+ ilvl: paragraphNumberingLevel(current.numPr ?? void 0) ?? 0
586
+ }, resolvedAttrs.numbering ?? getDocumentNumbering(state)));
552
587
  }
553
588
  tr = tr.setNodeMarkup(pos, void 0, newAttrs);
554
- if (resolvedAttrs) {
555
- const paragraphStart = pos + 1;
556
- const paragraphEnd = pos + node.nodeSize - 1;
557
- if (paragraphEnd > paragraphStart) {
558
- for (const markType of styleControlledMarks) tr = tr.removeMark(paragraphStart, paragraphEnd, markType);
559
- for (const mark of styleMarks) tr = tr.addMark(paragraphStart, paragraphEnd, mark);
560
- }
561
- }
589
+ rebaseParagraphRuns({
590
+ tr,
591
+ position: pos,
592
+ previous: node,
593
+ styleResolver: getDocumentStyleResolver(state),
594
+ storedMarks: state.storedMarks ?? state.selection.$from.marks()
595
+ });
562
596
  }
563
597
  });
564
- if (styleMarks.length > 0) tr = tr.setStoredMarks(styleMarks);
565
598
  dispatch(tr.scrollIntoView());
566
599
  return true;
567
600
  };
@@ -594,8 +627,8 @@ const ParagraphExtension = createNodeExtension({
594
627
  name: "paragraph",
595
628
  schemaNodeName: "paragraph",
596
629
  nodeSpec: paragraphNodeSpec,
597
- onSchemaReady(ctx) {
598
- const applyStyleFn = makeApplyStyle(ctx.schema);
630
+ onSchemaReady() {
631
+ const applyStyleFn = makeApplyStyle();
599
632
  return { commands: {
600
633
  setAlignment: (alignment) => makeSetAlignment(alignment),
601
634
  alignLeft: () => makeSetAlignment("left"),
@@ -617,10 +650,18 @@ const ParagraphExtension = createNodeExtension({
617
650
  hangingIndent: hanging ?? false
618
651
  }),
619
652
  applyStyle: (styleId, resolvedAttrs) => applyStyleFn(styleId, resolvedAttrs),
620
- clearStyle: () => setParagraphAttrsCmd({
621
- styleId: null,
622
- _tableOfContentsLevel: null
623
- }),
653
+ clearStyle: () => (state, dispatch) => {
654
+ const resolver = getDocumentStyleResolver(state);
655
+ if (!resolver) return applyStyleFn(null)(state, dispatch);
656
+ const resolved = resolver.resolveParagraphStyle(null);
657
+ const styleName = resolver.getDefaultParagraphStyle()?.name;
658
+ return applyStyleFn(null, {
659
+ ...resolved.paragraphFormatting && { paragraphFormatting: resolved.paragraphFormatting },
660
+ ...resolved.runFormatting && { runFormatting: resolved.runFormatting },
661
+ ...styleName && { styleName },
662
+ numbering: getDocumentNumbering(state)
663
+ })(state, dispatch);
664
+ },
624
665
  insertSectionBreak: (breakType) => setSectionBreakType(breakType),
625
666
  removeSectionBreak: () => removeSectionBreakAtSelection,
626
667
  generateTOC: ({ title }) => (state, dispatch) => {
@@ -1,7 +1,7 @@
1
1
  import { mergeTextFormatting } from "../../../utils/textFormattingMerge.js";
2
2
  import { expectCharacterStyleMarkAttrs, expectRunFormattingOverrideMarkAttrs } from "../../attrs/index.js";
3
3
  import { keepSectionBreaksOnSurvivingMarks } from "../../commands/sectionBreak.js";
4
- import { getDocumentStyleResolver } from "../../plugins/documentStyles.js";
4
+ import { getDocumentStyleResolver } from "../../plugins/documentStyleState.js";
5
5
  import { RUN_FORMATTING_MARK_NAMES } from "../../runFormattingMarkNames.js";
6
6
  import { authoredRunFormattingFromAttrs } from "../../runFormattingProvenance.js";
7
7
  import { paragraphAttrsFromResolvedStyle } from "../../styles/resolvedStyleAttrs.js";