@stll/folio-core 0.66.1 → 0.67.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 (170) hide show
  1. package/dist/ai-edits/apply.d.ts +13 -1
  2. package/dist/ai-edits/apply.js +572 -140
  3. package/dist/ai-edits/batch-claims.d.ts +26 -0
  4. package/dist/ai-edits/batch-claims.js +32 -5
  5. package/dist/ai-edits/clean-text.js +4 -1
  6. package/dist/ai-edits/headless.d.ts +6 -0
  7. package/dist/ai-edits/headless.js +25 -3
  8. package/dist/ai-edits/newListNumbering.d.ts +4 -1
  9. package/dist/ai-edits/newListNumbering.js +4 -2
  10. package/dist/ai-edits/read.js +6 -4
  11. package/dist/ai-edits/snapshot.js +24 -14
  12. package/dist/ai-edits/table-cell-mutations.js +3 -2
  13. package/dist/ai-edits/table-row-column-mutations.js +20 -6
  14. package/dist/ai-edits/types.d.ts +1 -1
  15. package/dist/controller/canonicalComposition.d.ts +1 -1
  16. package/dist/controller/canonicalComposition.js +76 -18
  17. package/dist/controller/canonicalInput.d.ts +0 -1
  18. package/dist/controller/canonicalInput.js +19 -1
  19. package/dist/controller/canonicalSession.js +1 -2
  20. package/dist/controller/hiddenEditorManager.d.ts +6 -0
  21. package/dist/controller/hiddenEditorManager.js +3 -1
  22. package/dist/controller/layoutPipeline.d.ts +2 -0
  23. package/dist/controller/layoutPipeline.js +7 -3
  24. package/dist/controller/layoutSession.d.ts +1 -0
  25. package/dist/display-list/build/tablePrimitives.d.ts +3 -1
  26. package/dist/display-list/build/tablePrimitives.js +29 -13
  27. package/dist/document-operations.d.ts +13 -1
  28. package/dist/document-operations.js +11 -4
  29. package/dist/docx/chartPreview.d.ts +4 -1
  30. package/dist/docx/chartPreview.js +26 -15
  31. package/dist/docx/listNumberingInstances.d.ts +6 -4
  32. package/dist/docx/listNumberingInstances.js +12 -11
  33. package/dist/docx/mainDocumentPart.d.ts +6 -0
  34. package/dist/docx/mainDocumentPart.js +65 -0
  35. package/dist/docx/numberingIds.d.ts +10 -0
  36. package/dist/docx/numberingIds.js +5 -1
  37. package/dist/docx/packageParts.d.ts +1 -1
  38. package/dist/docx/packageParts.js +10 -4
  39. package/dist/docx/paragraphParser.js +16 -3
  40. package/dist/docx/paragraphProperties.js +2 -1
  41. package/dist/docx/previewBudget.d.ts +6 -0
  42. package/dist/docx/previewBudget.js +7 -1
  43. package/dist/docx/rezip.js +4 -4
  44. package/dist/docx/serializer/paragraphSerializer.js +86 -66
  45. package/dist/docx/shapeAlternateContent.js +19 -0
  46. package/dist/docx/unzip.js +2 -0
  47. package/dist/i18n/messages/ar.gen.js +2 -0
  48. package/dist/i18n/messages/catalogs.gen.d.ts +34 -0
  49. package/dist/i18n/messages/catalogs.gen.js +34 -0
  50. package/dist/i18n/messages/cs.gen.js +2 -0
  51. package/dist/i18n/messages/de.gen.js +2 -0
  52. package/dist/i18n/messages/en.gen.js +2 -0
  53. package/dist/i18n/messages/es.gen.js +2 -0
  54. package/dist/i18n/messages/et.gen.js +2 -0
  55. package/dist/i18n/messages/fr.gen.js +2 -0
  56. package/dist/i18n/messages/he.gen.js +2 -0
  57. package/dist/i18n/messages/hi.gen.js +2 -0
  58. package/dist/i18n/messages/hu.gen.js +2 -0
  59. package/dist/i18n/messages/lt.gen.js +2 -0
  60. package/dist/i18n/messages/lv.gen.js +2 -0
  61. package/dist/i18n/messages/messages.gen.d.ts +2 -0
  62. package/dist/i18n/messages/pl.gen.js +2 -0
  63. package/dist/i18n/messages/pt-BR.gen.js +2 -0
  64. package/dist/i18n/messages/sk.gen.js +2 -0
  65. package/dist/i18n/messages/tr.gen.js +2 -0
  66. package/dist/i18n/messages/zh-CN.gen.js +2 -0
  67. package/dist/internal/wholeStoryRevisionResolution.d.ts +1 -1
  68. package/dist/internal/wholeStoryRevisionResolution.js +81 -21
  69. package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +10 -0
  70. package/dist/layout-bridge/convert/altChunkPlaceholder.js +70 -0
  71. package/dist/layout-bridge/convert/fixedTableColumnWidths.js +2 -1
  72. package/dist/layout-bridge/convert/flowConversionShared.d.ts +10 -0
  73. package/dist/layout-bridge/convert/flowConversionShared.js +11 -1
  74. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  75. package/dist/layout-bridge/convert/footnoteLayout.js +4 -1
  76. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  77. package/dist/layout-bridge/convert/headerFooterLayout.js +6 -1
  78. package/dist/layout-bridge/convert/runMarkFormatting.js +1 -0
  79. package/dist/layout-bridge/convert/tableConversion.js +6 -2
  80. package/dist/layout-bridge/convert/toFlowBlocks.js +4 -0
  81. package/dist/layout-bridge/engine/clickToPosition.js +5 -1
  82. package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
  83. package/dist/layout-engine/measure/tableCellFloating.js +1 -0
  84. package/dist/layout-engine/measure/tableVisibleBand.d.ts +16 -0
  85. package/dist/layout-engine/measure/tableVisibleBand.js +28 -0
  86. package/dist/layout-engine/tableLayout.js +7 -4
  87. package/dist/layout-engine/tableRowBreak.d.ts +10 -0
  88. package/dist/layout-engine/tableRowBreak.js +151 -36
  89. package/dist/layout-engine/types.d.ts +7 -2
  90. package/dist/layout-painter/previewSvg.d.ts +8 -0
  91. package/dist/layout-painter/previewSvg.js +47 -0
  92. package/dist/layout-painter/renderImage.js +2 -1
  93. package/dist/layout-painter/renderPage.d.ts +1 -0
  94. package/dist/layout-painter/renderPage.js +6 -3
  95. package/dist/layout-painter/renderParagraph.js +3 -2
  96. package/dist/layout-painter/renderTable.d.ts +5 -2
  97. package/dist/layout-painter/renderTable.js +33 -19
  98. package/dist/markdown/renderRuns.js +68 -12
  99. package/dist/prosemirror/anchoredTextBoxes.d.ts +2 -1
  100. package/dist/prosemirror/commands/comments.js +22 -7
  101. package/dist/prosemirror/commands/deleteBesideInlineAnchor.d.ts +9 -0
  102. package/dist/prosemirror/commands/deleteBesideInlineAnchor.js +36 -0
  103. package/dist/prosemirror/commands/pastePlainText.d.ts +6 -0
  104. package/dist/prosemirror/commands/pastePlainText.js +13 -3
  105. package/dist/prosemirror/commands/resolveAllTableChanges.js +30 -2
  106. package/dist/prosemirror/commands/resolveParagraphProperties.js +15 -2
  107. package/dist/prosemirror/commentReferenceIntegrity.d.ts +8 -2
  108. package/dist/prosemirror/commentReferenceIntegrity.js +19 -4
  109. package/dist/prosemirror/conversion/fromProseDoc.js +94 -22
  110. package/dist/prosemirror/conversion/hyphenTextCarriers.d.ts +23 -1
  111. package/dist/prosemirror/conversion/hyphenTextCarriers.js +46 -1
  112. package/dist/prosemirror/conversion/toProseDoc.js +21 -13
  113. package/dist/prosemirror/extensions/StarterKit.js +1 -1
  114. package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +3 -1
  115. package/dist/prosemirror/extensions/core/ParagraphExtension.js +8 -9
  116. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +46 -11
  117. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
  118. package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +2 -3
  119. package/dist/prosemirror/extensions/features/ListExtension.js +22 -1
  120. package/dist/prosemirror/extensions/features/pasteCleanup.js +6 -0
  121. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +2 -1
  122. package/dist/prosemirror/extensions/markRegistry.d.ts +3 -1
  123. package/dist/prosemirror/extensions/markRegistry.js +3 -0
  124. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +5 -0
  125. package/dist/prosemirror/extensions/marks/HyphenElementExtension.d.ts +6 -0
  126. package/dist/prosemirror/extensions/marks/HyphenElementExtension.js +54 -0
  127. package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
  128. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +8 -4
  129. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +5 -1
  130. package/dist/prosemirror/extensions/nodes/CommentRangeBoundaryExtension.js +2 -1
  131. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +4 -3
  132. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +2 -1
  133. package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +2 -1
  134. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +2 -1
  135. package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +2 -1
  136. package/dist/prosemirror/extensions/nodes/TableExtension.js +87 -7
  137. package/dist/prosemirror/extensions/nodes/inlineAnchorDom.d.ts +11 -0
  138. package/dist/prosemirror/extensions/nodes/inlineAnchorDom.js +21 -0
  139. package/dist/prosemirror/fieldRepresentation.js +2 -1
  140. package/dist/prosemirror/hyphenElementAttrs.d.ts +10 -0
  141. package/dist/prosemirror/hyphenElementAttrs.js +32 -0
  142. package/dist/prosemirror/keptRangeBoundaries.d.ts +2 -0
  143. package/dist/prosemirror/keptRangeBoundaries.js +1 -1
  144. package/dist/prosemirror/listNumbering.js +3 -2
  145. package/dist/prosemirror/paragraphIndentation.js +2 -1
  146. package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -14
  147. package/dist/prosemirror/paragraphPropertyCarry.js +4 -28
  148. package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -8
  149. package/dist/prosemirror/plugins/suggestionMode.js +194 -27
  150. package/dist/prosemirror/replacedAnnotations.d.ts +1 -0
  151. package/dist/prosemirror/replacedAnnotations.js +1 -0
  152. package/dist/prosemirror/rowGridOmissions.d.ts +11 -0
  153. package/dist/prosemirror/rowGridOmissions.js +21 -0
  154. package/dist/prosemirror/sectionCarrier.d.ts +8 -0
  155. package/dist/prosemirror/sectionCarrier.js +29 -1
  156. package/dist/prosemirror/styles/paragraphStyleCascade.d.ts +10 -0
  157. package/dist/prosemirror/styles/paragraphStyleCascade.js +12 -2
  158. package/dist/prosemirror/tableGridMutation.d.ts +19 -2
  159. package/dist/prosemirror/tableGridMutation.js +118 -15
  160. package/dist/prosemirror/tablePositionedBookmarks.d.ts +2 -0
  161. package/dist/prosemirror/tablePositionedBookmarks.js +80 -0
  162. package/dist/prosemirror/tableRunIn.d.ts +24 -9
  163. package/dist/prosemirror/tableRunIn.js +107 -21
  164. package/dist/prosemirror/textInput.js +3 -1
  165. package/dist/prosemirror/validation.js +7 -1
  166. package/dist/utils/createDocument.js +11 -8
  167. package/dist/utils/formatToStyle.js +2 -2
  168. package/dist/utils/units.d.ts +5 -0
  169. package/dist/utils/units.js +6 -1
  170. package/package.json +3 -3
@@ -49,6 +49,7 @@ import { directionToAuthoredBidi } from "../paragraphDirection.js";
49
49
  import { paragraphIndentationFromFormatting } from "../paragraphIndentation.js";
50
50
  import { directParagraphSpacing } from "../paragraphSpacing.js";
51
51
  import { expectRangeAnchorAttrs } from "../rangeAnchorAttrs.js";
52
+ import { rowGridOmissions } from "../rowGridOmissions.js";
52
53
  import { marksToTextFormatting, sameFormattingValue } from "../runFormattingFromMarks.js";
53
54
  import { RUN_FORMATTING_MARK_NAMES } from "../runFormattingMarkNames.js";
54
55
  import { RUN_IDENTITY_MARK_NAME } from "../runIdentity.js";
@@ -59,6 +60,7 @@ import { expectTextBoxAnchorAttrs } from "../textBoxAnchorAttrs.js";
59
60
  import { textBoxHostParagraph } from "../textBoxHostParagraph.js";
60
61
  import { enclosingInsertionAncestors, inlineWrapperStackOf, trackedRevisionLayerOf } from "../trackedRevisionPath.js";
61
62
  import { assertValidProseMirrorDocument } from "../validation.js";
63
+ import { hyphenElementRunContent } from "./hyphenTextCarriers.js";
62
64
  import { hasSinkChildren } from "./preservedSinkCarriers.js";
63
65
  import { decodeSdtListItems, sdtPropertiesFromAttrs, sdtPropertiesMatchAttrs } from "./sdtAttrs.js";
64
66
  import { TaggedError, panic } from "better-result";
@@ -1659,13 +1661,13 @@ function extractParagraphContent(originalParagraph, _documentCounts, emptyHyperl
1659
1661
  }));
1660
1662
  const ownerId = runIdentityId(node);
1661
1663
  const currentOwnerId = currentRun ? sourceRunOwners.get(currentRun) : void 0;
1662
- const currentRunIsPlainText = currentRun?.content.every((runContent) => runContent.type === "text");
1664
+ const currentRunIsPlainText = currentRun?.content.every(isTextLeafContent);
1663
1665
  const joinsOwnedSourceRun = ownerId !== void 0 && ownerId === currentOwnerId && currentRun !== null && runsShareProperties(currentRun, run);
1664
1666
  const joinsOrdinaryText = coalescePlainText && currentRun !== null && runsShareProperties(currentRun, run) && currentRunIsPlainText === true && currentMarksKey === marksKey;
1665
1667
  if (currentRun && (joinsOwnedSourceRun || joinsOrdinaryText)) {
1666
- if (joinsOrdinaryText) {
1667
- for (const runContent of run.content) if (runContent.type === "text") appendTextToRun(currentRun, runContent.text);
1668
- } else currentRun.content.push(...run.content);
1668
+ if (joinsOrdinaryText) for (const runContent of run.content) if (runContent.type === "text") appendTextToRun(currentRun, runContent.text);
1669
+ else currentRun.content.push(runContent);
1670
+ else currentRun.content.push(...run.content);
1669
1671
  return;
1670
1672
  }
1671
1673
  if (currentRun) content.push(currentRun);
@@ -2128,7 +2130,8 @@ function extractParagraphContent(originalParagraph, _documentCounts, emptyHyperl
2128
2130
  content.push(createNoteReferenceRun(noteRefMark, node.marks, formattingContext));
2129
2131
  return;
2130
2132
  }
2131
- if (linkMark) {
2133
+ const fieldUnderLink = node.type.name === "field" || node.type.name === "structuredField";
2134
+ if (linkMark && !fieldUnderLink) {
2132
2135
  const linkKey = getLinkKey(linkMark);
2133
2136
  if (currentHyperlink && currentHyperlinkKey === linkKey) {} else {
2134
2137
  flushCurrentInline();
@@ -2266,10 +2269,7 @@ function createTrackedChangeRun({ baseParagraphFormatting, inheritedFormatting,
2266
2269
  const formatting = marksToTextFormatting(marks, formattingContext);
2267
2270
  run = {
2268
2271
  type: "run",
2269
- content: node.text ? [{
2270
- type: "text",
2271
- text: node.text
2272
- }] : [],
2272
+ content: node.text ? textLeafRunContent(node.text, marks) : [],
2273
2273
  ...Object.keys(formatting).length > 0 ? { formatting } : {}
2274
2274
  };
2275
2275
  restoreRunRecord(run, marks);
@@ -2355,7 +2355,7 @@ function getLinkKey(mark) {
2355
2355
  * Create a unique key for a set of marks (excluding hyperlink)
2356
2356
  */
2357
2357
  function getMarksKey(marks) {
2358
- const nonLinkMarks = marks.filter((m) => m.type.name !== "hyperlink");
2358
+ const nonLinkMarks = marks.filter((m) => m.type.name !== "hyperlink" && m.type.name !== "hyphenElement");
2359
2359
  if (nonLinkMarks.length === 0) return "";
2360
2360
  return nonLinkMarks.map((m) => `${m.type.name}:${JSON.stringify(m.attrs)}`).toSorted().join("|");
2361
2361
  }
@@ -2526,6 +2526,23 @@ function createNoteReferenceRun(noteRefMark, marks, formattingContext) {
2526
2526
  restoreRunRecord(run, marks);
2527
2527
  return run;
2528
2528
  }
2529
+ /**
2530
+ * The run content one ProseMirror text leaf writes.
2531
+ *
2532
+ * Text by default; a leaf carrying the hyphen-element mark writes its
2533
+ * carriers back as the elements they were read from.
2534
+ */
2535
+ function textLeafRunContent(text, marks) {
2536
+ if (marks.some(({ type }) => type.name === "hyphenElement")) return hyphenElementRunContent(text);
2537
+ return [{
2538
+ type: "text",
2539
+ text
2540
+ }];
2541
+ }
2542
+ /** Content an ordinary text run may hold and still join the next text leaf. */
2543
+ function isTextLeafContent(content) {
2544
+ return content.type === "text" || content.type === "softHyphen" || content.type === "noBreakHyphen";
2545
+ }
2529
2546
  function createRunFromText({ baseParagraphFormatting, inheritedFormatting, marks, paragraphMarkFormatting, paragraphMarkPrecedesStyle, styleResolver, text }) {
2530
2547
  const formatting = getRunFormattingFromMarks(marks, {
2531
2548
  baseParagraphFormatting,
@@ -2536,10 +2553,7 @@ function createRunFromText({ baseParagraphFormatting, inheritedFormatting, marks
2536
2553
  });
2537
2554
  const run = {
2538
2555
  type: "run",
2539
- content: [{
2540
- type: "text",
2541
- text
2542
- }]
2556
+ content: textLeafRunContent(text, marks)
2543
2557
  };
2544
2558
  if (formatting) run.formatting = formatting;
2545
2559
  restoreRunRecord(run, marks);
@@ -2782,6 +2796,25 @@ function createTabRun(node, marks, formattingContext) {
2782
2796
  if (marks) restoreRunRecord(run, marks);
2783
2797
  return run;
2784
2798
  }
2799
+ const FIELD_WIDE_MARK_NAMES = /* @__PURE__ */ new Set([
2800
+ "comment",
2801
+ "deletion",
2802
+ "insertion",
2803
+ "moveFrom",
2804
+ "moveTo"
2805
+ ]);
2806
+ /**
2807
+ * A change or comment over a whole field marks its result as well; the field
2808
+ * as a whole is what writes them, so the result's runs do not repeat them.
2809
+ */
2810
+ const withoutTheFieldsOwnMarks = (node) => {
2811
+ if (node.marks.length === 0) return node;
2812
+ const children = [];
2813
+ node.forEach((child) => {
2814
+ children.push(child.mark(child.marks.filter((mark) => !FIELD_WIDE_MARK_NAMES.has(mark.type.name) || !mark.isInSet(node.marks))));
2815
+ });
2816
+ return recreateProseNodeWithParagraphPropertySource(node, { content: Fragment.fromArray(children) });
2817
+ };
2785
2818
  function createFieldFromNode(node, { baseParagraphFormatting, inheritedFormatting, marks, paragraphMarkFormatting, paragraphMarkPrecedesStyle, styleResolver, textBoxAnchorMarkers }) {
2786
2819
  const attrs = expectFieldAttrs(node);
2787
2820
  const formatting = marks && marks.length > 0 ? marksToTextFormatting(marks, {
@@ -2791,13 +2824,14 @@ function createFieldFromNode(node, { baseParagraphFormatting, inheritedFormattin
2791
2824
  paragraphMarkPrecedesStyle,
2792
2825
  styleResolver
2793
2826
  }) : void 0;
2794
- const extractedContent = extractParagraphContent(node, void 0, void 0, textBoxAnchorMarkers, false, {
2827
+ const fieldFormattingContext = {
2795
2828
  baseParagraphFormatting,
2796
2829
  inheritedFormatting,
2797
2830
  paragraphMarkFormatting,
2798
2831
  paragraphMarkPrecedesStyle: paragraphMarkPrecedesStyle ?? false,
2799
2832
  styleResolver: styleResolver ?? null
2800
- }).filter(isSimpleFieldContent);
2833
+ };
2834
+ const extractedContent = extractParagraphContent(withoutTheFieldsOwnMarks(node), void 0, void 0, textBoxAnchorMarkers, false, fieldFormattingContext).filter(isSimpleFieldContent);
2801
2835
  const displayText = attrs.displayText ?? "";
2802
2836
  const displayRun = {
2803
2837
  type: "run",
@@ -2876,11 +2910,37 @@ const reconcileEmptyFieldResultRuns = (runs, displayRun) => {
2876
2910
  }
2877
2911
  return reconciled;
2878
2912
  };
2879
- const synchronizeFieldDisplayText = (content, displayText, fallbackRun) => {
2880
- const currentText = getFindParagraphText({
2913
+ /**
2914
+ * A result without its hyphen elements, and without a run that held nothing
2915
+ * else. They are part of the text a new display text replaces.
2916
+ */
2917
+ const withoutHyphenElements = (items) => items.filter((item) => {
2918
+ switch (item.type) {
2919
+ case "run": {
2920
+ const kept = item.content.filter(({ type }) => type !== "softHyphen" && type !== "noBreakHyphen");
2921
+ if (kept.length === item.content.length) return true;
2922
+ item.content = kept;
2923
+ return kept.length > 0;
2924
+ }
2925
+ case "hyperlink":
2926
+ item.children = withoutHyphenElements(item.children);
2927
+ return true;
2928
+ case "inlineWrapper":
2929
+ case "insertion":
2930
+ case "deletion":
2931
+ case "moveFrom":
2932
+ case "moveTo":
2933
+ item.content = withoutHyphenElements(item.content);
2934
+ return true;
2935
+ default: return true;
2936
+ }
2937
+ });
2938
+ const synchronizeFieldDisplayText = (fieldContent, displayText, fallbackRun) => {
2939
+ if (getFindParagraphText({
2881
2940
  type: "paragraph",
2882
- content
2883
- });
2941
+ content: fieldContent
2942
+ }) === displayText) return fieldContent;
2943
+ const content = withoutHyphenElements(fieldContent);
2884
2944
  const visitRunsIn = (items, visit) => {
2885
2945
  for (const child of items) {
2886
2946
  if (child.type === "run") {
@@ -2893,7 +2953,6 @@ const synchronizeFieldDisplayText = (content, displayText, fallbackRun) => {
2893
2953
  const visitRuns = (visit) => {
2894
2954
  visitRunsIn(content, visit);
2895
2955
  };
2896
- if (currentText === displayText) return content;
2897
2956
  let replacedText = false;
2898
2957
  visitRuns((run) => {
2899
2958
  for (const runContent of run.content) {
@@ -3376,6 +3435,19 @@ function tableAttrsToFormatting(attrs) {
3376
3435
  /**
3377
3436
  * Convert a ProseMirror table row node to our TableRow type
3378
3437
  */
3438
+ /** What the row states it omits follows what column edits made of it. */
3439
+ const withOmittedGridSlots = (formatting, row) => {
3440
+ const statedBefore = formatting?.gridBefore ?? 0;
3441
+ const statedAfter = formatting?.gridAfter ?? 0;
3442
+ const { gridBefore, gridAfter } = rowGridOmissions(row, statedAfter);
3443
+ if (gridBefore === statedBefore && gridAfter === statedAfter) return formatting;
3444
+ const next = { ...formatting };
3445
+ if (gridBefore > 0) next.gridBefore = gridBefore;
3446
+ else delete next.gridBefore;
3447
+ if (gridAfter > 0) next.gridAfter = gridAfter;
3448
+ else delete next.gridAfter;
3449
+ return next;
3450
+ };
3379
3451
  function convertPMTableRow(node, documentCounts, activeVerticalMerges, styleResolver = null) {
3380
3452
  const attrs = expectTableRowAttrs(node);
3381
3453
  const cells = [];
@@ -3419,7 +3491,7 @@ function convertPMTableRow(node, documentCounts, activeVerticalMerges, styleReso
3419
3491
  type: "tableRow",
3420
3492
  cells
3421
3493
  };
3422
- const rowFormatting = tableRowAttrsToFormatting(attrs);
3494
+ const rowFormatting = withOmittedGridSlots(tableRowAttrsToFormatting(attrs), node);
3423
3495
  if (rowFormatting) row.formatting = rowFormatting;
3424
3496
  if (attrs._tablePropertyExceptions) row.tablePropertyExceptions = attrs._tablePropertyExceptions;
3425
3497
  if (Array.isArray(attrs.tblPrExChange) && attrs.tblPrExChange.length > 0) row.tablePropertyExceptionChanges = [...attrs.tblPrExChange];
@@ -1,5 +1,27 @@
1
+ import { document_d_exports } from "../../types/document.js";
1
2
  /** These source units render as native text while keeping one logical atom each. */
2
3
  export declare const HYPHEN_TEXT_CARRIERS: {
3
4
  readonly softHyphen: "­";
4
5
  readonly noBreakHyphen: "‑";
5
- };
6
+ };
7
+ /**
8
+ * The mark that tells a carrier written for `w:softHyphen` or
9
+ * `w:noBreakHyphen` apart from the same character authored inside `w:t`.
10
+ *
11
+ * Both render identically, so the text alone cannot say which one the source
12
+ * held; the save leg reads this mark to write each back as it was read.
13
+ */
14
+ export declare const HYPHEN_ELEMENT_MARK_NAME = "hyphenElement";
15
+ type HyphenElementRunContent = document_d_exports.TextContent | document_d_exports.SoftHyphenContent | document_d_exports.NoBreakHyphenContent;
16
+ /**
17
+ * The run content a leaf carrying {@link HYPHEN_ELEMENT_MARK_NAME} writes back.
18
+ *
19
+ * Each carrier becomes its element again and any other character stays text.
20
+ * Typing does not normally reach a marked leaf: the mark is not inclusive and
21
+ * neighbouring carriers hold different ids. Ids only repeat when a copy is pasted
22
+ * beside its source or two paragraphs join; a character typed exactly between
23
+ * two such carriers takes the mark, so a letter stays text here and a typed
24
+ * U+00AD or U+2011 saves as the element.
25
+ */
26
+ export declare const hyphenElementRunContent: (text: string) => HyphenElementRunContent[];
27
+ export {};
@@ -4,4 +4,49 @@ const HYPHEN_TEXT_CARRIERS = {
4
4
  softHyphen: "­",
5
5
  noBreakHyphen: "‑"
6
6
  };
7
- export { HYPHEN_TEXT_CARRIERS };
7
+ /**
8
+ * The mark that tells a carrier written for `w:softHyphen` or
9
+ * `w:noBreakHyphen` apart from the same character authored inside `w:t`.
10
+ *
11
+ * Both render identically, so the text alone cannot say which one the source
12
+ * held; the save leg reads this mark to write each back as it was read.
13
+ */
14
+ const HYPHEN_ELEMENT_MARK_NAME = "hyphenElement";
15
+ const isHyphenElementType = (key) => Object.hasOwn(HYPHEN_TEXT_CARRIERS, key);
16
+ /** The inverse of {@link HYPHEN_TEXT_CARRIERS}, derived so the two cannot drift. */
17
+ const HYPHEN_ELEMENT_BY_CARRIER = new Map(Object.keys(HYPHEN_TEXT_CARRIERS).filter(isHyphenElementType).map((type) => [HYPHEN_TEXT_CARRIERS[type], type]));
18
+ /**
19
+ * The run content a leaf carrying {@link HYPHEN_ELEMENT_MARK_NAME} writes back.
20
+ *
21
+ * Each carrier becomes its element again and any other character stays text.
22
+ * Typing does not normally reach a marked leaf: the mark is not inclusive and
23
+ * neighbouring carriers hold different ids. Ids only repeat when a copy is pasted
24
+ * beside its source or two paragraphs join; a character typed exactly between
25
+ * two such carriers takes the mark, so a letter stays text here and a typed
26
+ * U+00AD or U+2011 saves as the element.
27
+ */
28
+ const hyphenElementRunContent = (text) => {
29
+ const content = [];
30
+ let pending = "";
31
+ for (const char of text) {
32
+ const type = HYPHEN_ELEMENT_BY_CARRIER.get(char);
33
+ if (type === void 0) {
34
+ pending += char;
35
+ continue;
36
+ }
37
+ if (pending.length > 0) {
38
+ content.push({
39
+ type: "text",
40
+ text: pending
41
+ });
42
+ pending = "";
43
+ }
44
+ content.push({ type });
45
+ }
46
+ if (pending.length > 0) content.push({
47
+ type: "text",
48
+ text: pending
49
+ });
50
+ return content;
51
+ };
52
+ export { HYPHEN_ELEMENT_MARK_NAME, HYPHEN_TEXT_CARRIERS, hyphenElementRunContent };
@@ -50,17 +50,17 @@ import { lineSpacingProvenanceFromSpacing } from "../paragraphSpacing.js";
50
50
  import { isRunContentProjectionNode } from "../runContentProjection.js";
51
51
  import { RUN_IDENTITY_MARK_NAME, hasRunIdentityPayload, runIdentityAttrs } from "../runIdentity.js";
52
52
  import { continueSourceCarrierIdentitiesAcrossInsertedParagraphMarks, continueSourceCarrierIdentitiesAcrossRevisions } from "../runIdentityAcrossRevisions.js";
53
- import { getParagraphMarkSuppressionOverrides, hasDirectRunFormatting, isParagraphMarkSuppressionEligible, resolveParagraphInheritedRunFormatting, stripParagraphMarkFormattingForBodyRuns, stripParagraphMarkOnlyFormatting, suppressParagraphMarkFormatting } from "../runStyleFormatting.js";
53
+ import { getParagraphMarkSuppressionOverrides, hasDirectRunFormatting, isParagraphMarkSuppressionEligible, resolveParagraphInheritedRunFormatting, stripParagraphMarkOnlyFormatting, suppressParagraphMarkFormatting } from "../runStyleFormatting.js";
54
54
  import { schema } from "../schema/index.js";
55
55
  import { PRESERVED_XML_LEVELS } from "../schema/nodes.js";
56
- import { extractTableParagraphOverlay, paragraphStyleCascadeAttrs, resolveRunFormattingWithoutDefaults } from "../styles/paragraphStyleCascade.js";
56
+ import { extractTableParagraphOverlay, inheritableParagraphMarkFormatting, paragraphStyleCascadeAttrs, resolveRunFormattingWithoutDefaults } from "../styles/paragraphStyleCascade.js";
57
57
  import { listIndentationProvenancePatch } from "../styles/resolvedStyleAttrs.js";
58
58
  import { cascadeStyleTextFormatting } from "../styles/styleToggleCascade.js";
59
59
  import { tableCellStyleRegions, tableRowBand } from "../styles/tableStyleRegions.js";
60
60
  import { canCarryTrackedRunMark, trackedRunInlineAtomDisposition } from "../trackedRunInlineAtoms.js";
61
61
  import { assertValidProseMirrorDocument } from "../validation.js";
62
62
  import { resolveEffectiveTableCellFormatting } from "./effectiveTableCellFormatting.js";
63
- import { HYPHEN_TEXT_CARRIERS } from "./hyphenTextCarriers.js";
63
+ import { HYPHEN_ELEMENT_MARK_NAME, HYPHEN_TEXT_CARRIERS } from "./hyphenTextCarriers.js";
64
64
  import { createMarkInterner } from "./markInterner.js";
65
65
  import { hasSinkChildren } from "./preservedSinkCarriers.js";
66
66
  import { sdtAttrsFromProperties } from "./sdtAttrs.js";
@@ -425,8 +425,10 @@ const resolveListRendering = (numPr, context) => {
425
425
  function convertParagraph(paragraph, styleResolver, context, extraRunFormatting, tableParagraphOverlay, textBoxAnchors) {
426
426
  const { nextHyperlinkInstanceIndex, pairedBookmarkIds, pageBreakRunSourceDescendants, storyRangedCommentIds, openCommentIds } = context;
427
427
  let runIdentityId = 0;
428
+ let hyphenElementId = 0;
428
429
  const runScope = {
429
430
  nextRunIdentityId: () => runIdentityId++,
431
+ nextHyphenElementId: () => hyphenElementId++,
430
432
  nextNoteReferenceOccurrenceId: context.nextNoteReferenceOccurrenceId,
431
433
  createMark: context.createMark
432
434
  };
@@ -500,9 +502,11 @@ function convertParagraph(paragraph, styleResolver, context, extraRunFormatting,
500
502
  if (!node) return;
501
503
  emitInlineNodes([node]);
502
504
  };
503
- const paragraphRunFormatting = resolveRunFormattingWithoutDefaults(paragraph.formatting?.runProperties, styleResolver);
504
- let inheritableParagraphRunFormatting;
505
- if (paragraphRunFormatting && !isTocParagraph && paragraph.formatting?.styleId === void 0) inheritableParagraphRunFormatting = stripParagraphMarkFormattingForBodyRuns(paragraphRunFormatting);
505
+ const inheritableParagraphRunFormatting = isTocParagraph ? void 0 : inheritableParagraphMarkFormatting({
506
+ runProperties: paragraph.formatting?.runProperties,
507
+ styleId: paragraph.formatting?.styleId,
508
+ styleResolver
509
+ });
506
510
  const { baseFormatting: baseRunFormatting, baseToggleCascade: orderedToggleFormatting, defaultFormatting: ordinaryBaseWithDefaultCharacter, defaultToggleCascade: defaultCharacterStyleCascade, inheritedFormatting: defaultRunFormatting, inheritedToggleCascade: defaultToggleCascade } = resolveParagraphInheritedRunFormatting({
507
511
  styleId: paragraph.formatting?.styleId,
508
512
  tableRunFormatting: extraRunFormatting,
@@ -1096,10 +1100,11 @@ function convertTable(table, styleResolver, context) {
1096
1100
  const totalRows = table.rows.length;
1097
1101
  const gridColumnCount = columnWidths?.length ?? 0;
1098
1102
  const totalColumns = gridColumnCount > 0 ? gridColumnCount : countTableColumns(table.rows);
1103
+ const mapWidth = table.rows.some((row) => row.cells.length === 0) ? Math.max(countTableColumns(table.rows), totalColumns) : countTableColumns(table.rows);
1099
1104
  const rows = table.rows.map((row, rowIndex) => {
1100
1105
  const isFirstRowStyled = rowIndex === 0 && look.firstRow;
1101
1106
  const resolvedRowJustification = tableStyle?.trPr?.justification ?? fallbackTableStyle?.trPr?.justification;
1102
- return convertTableRow(row, styleResolver, context, isFirstRowStyled, columnWidths, totalWidth, conditionalStyles, tableRowBand(look, rowIndex, totalRows), look, resolvedTableBorders, rowIndex, totalRows, totalColumns, rowSpanMap, cellMarginsAttr, resolvedRowJustification);
1107
+ return convertTableRow(row, styleResolver, context, isFirstRowStyled, columnWidths, totalWidth, conditionalStyles, tableRowBand(look, rowIndex, totalRows), look, resolvedTableBorders, rowIndex, totalRows, totalColumns, mapWidth, rowSpanMap, cellMarginsAttr, resolvedRowJustification);
1103
1108
  });
1104
1109
  return schema.node("table", attrs, rows);
1105
1110
  }
@@ -1129,7 +1134,7 @@ function createOmittedGridSlotCell({ colspan, slot, columnWidths, totalWidth, st
1129
1134
  /**
1130
1135
  * Convert a TableRow to a ProseMirror table row node
1131
1136
  */
1132
- function convertTableRow(row, styleResolver, context, isHeaderRow, columnWidths, totalWidth, conditionalStyles, rowBand, tableLook, tableBorders, rowIndex, totalRows, totalColumns, rowSpanMap, defaultCellMargins, resolvedJustification) {
1137
+ function convertTableRow(row, styleResolver, context, isHeaderRow, columnWidths, totalWidth, conditionalStyles, rowBand, tableLook, tableBorders, rowIndex, totalRows, totalColumns, mapWidth, rowSpanMap, defaultCellMargins, resolvedJustification) {
1133
1138
  const attrsWithoutStructuralChange = { isHeader: !!row.formatting?.header };
1134
1139
  if (row.formatting?.height?.value !== void 0) attrsWithoutStructuralChange.height = row.formatting.height.value;
1135
1140
  if (row.formatting?.heightRule) attrsWithoutStructuralChange.heightRule = row.formatting.heightRule;
@@ -1249,8 +1254,9 @@ function convertTableRow(row, styleResolver, context, isHeaderRow, columnWidths,
1249
1254
  defaultCellMargins
1250
1255
  }));
1251
1256
  }
1252
- if (gridAfter > 0) cells.push(createOmittedGridSlotCell({
1253
- colspan: gridAfter,
1257
+ const omittedAfter = Math.max(gridAfter, (mapWidth ?? 0) - colIndex);
1258
+ if (omittedAfter > 0) cells.push(createOmittedGridSlotCell({
1259
+ colspan: omittedAfter,
1254
1260
  slot: "after",
1255
1261
  columnWidths,
1256
1262
  totalWidth,
@@ -1739,6 +1745,7 @@ function convertRun(run, resolvedStyleFormatting, runScope, styleResolver, textB
1739
1745
  formatting: mergedFormatting,
1740
1746
  textBoxAnchors,
1741
1747
  authoredFormatting: run.formatting,
1748
+ nextHyphenElementId: runScope.nextHyphenElementId,
1742
1749
  nextNoteReferenceOccurrenceId: runScope.nextNoteReferenceOccurrenceId
1743
1750
  });
1744
1751
  for (const node of contentNodes) if (!isRunContentProjectionNode(content.type, node.type.name)) panic(`Run content ${content.type} projected unsupported inline node ${node.type.name}`);
@@ -2147,7 +2154,7 @@ const noteReferenceVertAlign = (vertAlign) => {
2147
2154
  * run was authored with.
2148
2155
  */
2149
2156
  const carriedRunFormatting = (formatting) => formatting && Object.keys(formatting).length > 0 ? formatting : void 0;
2150
- function convertRunContent({ content, marks, formatting, textBoxAnchors, authoredFormatting, nextNoteReferenceOccurrenceId }) {
2157
+ function convertRunContent({ content, marks, formatting, textBoxAnchors, authoredFormatting, nextHyphenElementId, nextNoteReferenceOccurrenceId }) {
2151
2158
  switch (content.type) {
2152
2159
  case "noteMarker": return [schema.node("noteMarker", { kind: content.kind }).mark(marks)];
2153
2160
  case "text":
@@ -2214,8 +2221,8 @@ function convertRunContent({ content, marks, formatting, textBoxAnchors, authore
2214
2221
  text: content.text,
2215
2222
  level: PRESERVED_XML_LEVELS.run
2216
2223
  }).mark(marks)];
2217
- case "noBreakHyphen": return [schema.text(HYPHEN_TEXT_CARRIERS.noBreakHyphen, marks)];
2218
- case "softHyphen": return [schema.text(HYPHEN_TEXT_CARRIERS.softHyphen, marks)];
2224
+ case "noBreakHyphen":
2225
+ case "softHyphen": return [schema.text(HYPHEN_TEXT_CARRIERS[content.type], [...marks, schema.mark(HYPHEN_ELEMENT_MARK_NAME, { id: nextHyphenElementId() })])];
2219
2226
  case "symbol": return [schema.node("symbol", {
2220
2227
  font: content.font,
2221
2228
  char: content.char
@@ -2459,6 +2466,7 @@ function convertHyperlink(hyperlink, { getInheritedRunFormatting, styleResolver,
2459
2466
  formatting: mergedFormatting,
2460
2467
  textBoxAnchors,
2461
2468
  authoredFormatting: child.formatting,
2469
+ nextHyphenElementId: runScope.nextHyphenElementId,
2462
2470
  nextNoteReferenceOccurrenceId: runScope.nextNoteReferenceOccurrenceId
2463
2471
  }));
2464
2472
  break;
@@ -69,7 +69,7 @@ function createStarterKit(options = {}) {
69
69
  ...options.historyNewGroupDelay !== void 0 ? { newGroupDelay: options.historyNewGroupDelay } : {},
70
70
  ...options.historyShortcuts !== void 0 ? { shortcuts: options.historyShortcuts } : {}
71
71
  }));
72
- for (const name of MARK_NESTING_ORDER) add(name, MARK_EXTENSIONS[name]());
72
+ for (const name of MARK_NESTING_ORDER) add(name, MARK_EXTENSIONS[name]({ getInternalClipboardToken }));
73
73
  add("bookmarkBoundary", BookmarkBoundaryExtension({ getInternalClipboardToken }));
74
74
  add("blockBookmarkBoundary", BlockBookmarkBoundaryExtension({ getInternalClipboardToken }));
75
75
  add("blockMoveRangeBoundary", BlockMoveRangeBoundaryExtension({ getInternalClipboardToken }));
@@ -1,7 +1,7 @@
1
1
  import { document_d_exports } from "../../../types/document.js";
2
2
  import { NumberingMap } from "../../../docx/numberingParser.js";
3
3
  import { NodeExtension } from "../types.js";
4
- import { EditorState } from "prosemirror-state";
4
+ import { Command, EditorState } from "prosemirror-state";
5
5
  export type ResolvedStyleAttrs = {
6
6
  paragraphFormatting?: document_d_exports.ParagraphFormatting;
7
7
  runFormatting?: document_d_exports.TextFormatting;
@@ -33,4 +33,6 @@ export type GenerateTableOfContentsOptions = {
33
33
  /** Heading text for the table, in the document's language. */
34
34
  title: string;
35
35
  };
36
+ /** Set the selected paragraphs' writing direction. */
37
+ export declare const setParagraphDirection: (direction: "ltr" | "rtl") => Command;
36
38
  export declare const ParagraphExtension: (options?: Partial<Record<string, unknown>> | undefined) => NodeExtension;
@@ -660,6 +660,11 @@ function getParagraphBidi(state) {
660
660
  if (paragraph.type.name !== "paragraph") return false;
661
661
  return directionIsRtl(paragraph.attrs["direction"]);
662
662
  }
663
+ /** Set the selected paragraphs' writing direction. */
664
+ const setParagraphDirection = (direction) => withCanonicalParagraphFormatting(setParagraphAttr("direction", {
665
+ source: "manual",
666
+ value: direction
667
+ }), { bidi: direction === "rtl" });
663
668
  const ParagraphExtension = createNodeExtension({
664
669
  name: "paragraph",
665
670
  schemaNodeName: "paragraph",
@@ -829,14 +834,8 @@ const ParagraphExtension = createNodeExtension({
829
834
  return setParagraphAttr("direction", directionFor(paragraph))(state, dispatch);
830
835
  }, (paragraph) => ({ bidi: directionIsRtl(directionFor(paragraph)) }));
831
836
  },
832
- setRtl: () => withCanonicalParagraphFormatting(setParagraphAttr("direction", {
833
- source: "manual",
834
- value: "rtl"
835
- }), { bidi: true }),
836
- setLtr: () => withCanonicalParagraphFormatting(setParagraphAttr("direction", {
837
- source: "manual",
838
- value: "ltr"
839
- }), { bidi: false }),
837
+ setRtl: () => setParagraphDirection("rtl"),
838
+ setLtr: () => setParagraphDirection("ltr"),
840
839
  setTabs: (tabs) => withCanonicalParagraphFormatting(setParagraphAttr("tabs", tabs.length > 0 ? tabs : null), { tabs: tabs.length > 0 ? tabs : null }),
841
840
  addTabStop: (position, alignment = "left", leader = "none") => {
842
841
  const tabsFor = (paragraph) => [...(expectParagraphAttrs(paragraph).tabs ?? []).filter((tab) => tab.position !== position), {
@@ -864,4 +863,4 @@ const ParagraphExtension = createNodeExtension({
864
863
  } };
865
864
  }
866
865
  });
867
- export { ParagraphExtension, getParagraphAlignment, getParagraphBidi, getParagraphTabs, getStyleId };
866
+ export { ParagraphExtension, getParagraphAlignment, getParagraphBidi, getParagraphTabs, getStyleId, setParagraphDirection };
@@ -3,6 +3,7 @@ import { getTransactionDirtyRange } from "../../../paged-layout/transactionDirty
3
3
  import { detectBaseDirection } from "../../../utils/baseDirection.js";
4
4
  import { directionIsAutoManaged } from "../../paragraphDirection.js";
5
5
  import { createPluginKeyOwner } from "../../pluginKeyOwner.js";
6
+ import { afterNativeCompositionFlush } from "../../textInput.js";
6
7
  import { createExtension } from "../create.js";
7
8
  import { ignoreTrackedChanges } from "./ParagraphChangeTrackerExtension.js";
8
9
  import { Plugin } from "prosemirror-state";
@@ -130,17 +131,51 @@ const ensureBaseDirectionInState = (state) => {
130
131
  if (updates.length === 0) return state;
131
132
  return state.apply(applyBidiUpdates(state, updates));
132
133
  };
133
- const createAutoBidiDetectionPlugin = () => new Plugin({
134
- key: autoBidiDetectionKey.createKey(),
135
- appendTransaction(transactions, _oldState, newState) {
136
- if (!transactions.some((t) => t.docChanged)) return null;
137
- const [first, ...rest] = transactions;
138
- const range = first && rest.length === 0 ? getTransactionDirtyRange(first) : null;
139
- const updates = range ? collectBidiUpdatesInRange(newState.doc, range) : collectBidiUpdates(newState.doc);
140
- if (updates.length === 0) return null;
141
- return applyBidiUpdates(newState, updates);
142
- }
143
- });
134
+ const createAutoBidiDetectionPlugin = () => {
135
+ const composing = /* @__PURE__ */ new Set();
136
+ let deferred = false;
137
+ const finish = (view) => {
138
+ composing.delete(view);
139
+ if (!deferred || composing.size > 0 || view.isDestroyed) return;
140
+ deferred = false;
141
+ const updates = collectBidiUpdates(view.state.doc);
142
+ if (updates.length > 0) view.dispatch(applyBidiUpdates(view.state, updates));
143
+ };
144
+ return new Plugin({
145
+ key: autoBidiDetectionKey.createKey(),
146
+ view: (view) => ({ destroy: () => {
147
+ composing.delete(view);
148
+ } }),
149
+ props: { handleDOMEvents: {
150
+ compositionstart(view) {
151
+ composing.add(view);
152
+ return false;
153
+ },
154
+ compositionend(view) {
155
+ afterNativeCompositionFlush(() => {
156
+ finish(view);
157
+ });
158
+ return false;
159
+ },
160
+ blur(view) {
161
+ finish(view);
162
+ return false;
163
+ }
164
+ } },
165
+ appendTransaction(transactions, _oldState, newState) {
166
+ if (!transactions.some((t) => t.docChanged)) return null;
167
+ if (composing.size > 0) {
168
+ deferred = true;
169
+ return null;
170
+ }
171
+ const [first, ...rest] = transactions;
172
+ const range = first && rest.length === 0 ? getTransactionDirtyRange(first) : null;
173
+ const updates = range ? collectBidiUpdatesInRange(newState.doc, range) : collectBidiUpdates(newState.doc);
174
+ if (updates.length === 0) return null;
175
+ return applyBidiUpdates(newState, updates);
176
+ }
177
+ });
178
+ };
144
179
  const AutoBidiDetectionExtension = createExtension({
145
180
  name: "autoBidiDetection",
146
181
  defaultOptions: {},
@@ -1,6 +1,7 @@
1
1
  import { mergeTextFormatting } from "../../../utils/textFormattingMerge.js";
2
2
  import { expectCharacterStyleMarkAttrs, expectParagraphAttrs, expectRunFormattingOverrideMarkAttrs } from "../../attrs/index.js";
3
3
  import { clearIndentOnBackspace } from "../../commands/clearParagraphIndent.js";
4
+ import { deleteBesideInlineAnchor } from "../../commands/deleteBesideInlineAnchor.js";
4
5
  import { keepSectionBreaksOnSurvivingMarks } from "../../commands/sectionBreak.js";
5
6
  import { getDocumentStyleResolver } from "../../plugins/documentStyleState.js";
6
7
  import { RUN_FORMATTING_MARK_NAMES } from "../../runFormattingMarkNames.js";
@@ -232,8 +233,8 @@ const BaseKeymapExtension = createExtension({
232
233
  return { keyboardShortcuts: {
233
234
  ...baseKeymap,
234
235
  Enter: splitBlockClearBorders,
235
- Backspace: keepSectionBreaksOnSurvivingMarks(chainCommands(deleteSelection, clearIndentOnBackspace, joinBackward)),
236
- Delete: keepSectionBreaksOnSurvivingMarks(chainCommands(deleteSelection, joinForward)),
236
+ Backspace: keepSectionBreaksOnSurvivingMarks(chainCommands(deleteSelection, deleteBesideInlineAnchor(joinBackward, "backward"), clearIndentOnBackspace, joinBackward)),
237
+ Delete: keepSectionBreaksOnSurvivingMarks(chainCommands(deleteSelection, deleteBesideInlineAnchor(joinForward, "forward"), joinForward)),
237
238
  "Mod-a": selectAll,
238
239
  Escape: selectParentNode
239
240
  } };
@@ -1,4 +1,4 @@
1
- import { singletonManager } from "../../schema/index.js";
1
+ import { setParagraphDirection } from "../core/ParagraphExtension.js";
2
2
  import { createExtension } from "../create.js";
3
3
  import { Priority } from "../types.js";
4
4
  import { createBidiShortcutController } from "./bidiShortcutController.js";
@@ -27,8 +27,7 @@ const BidiShortcutExtension = createExtension({
27
27
  handleDOMEvents: { keyup(view, event) {
28
28
  const direction = controller.handleKeyUp(event);
29
29
  if (!direction) return false;
30
- const cmds = singletonManager.getCommands();
31
- (direction === "ltr" ? cmds["setLtr"] : cmds["setRtl"])?.()(view.state, view.dispatch);
30
+ setParagraphDirection(direction)(view.state, view.dispatch);
32
31
  return false;
33
32
  } }
34
33
  } })] };
@@ -383,6 +383,27 @@ const listAutoformatRule = () => new InputRule(LIST_MARKER_PATTERN, (state, matc
383
383
  requests
384
384
  }) ? tr : null;
385
385
  });
386
+ const liveText = (paragraph, end) => {
387
+ let text = "";
388
+ paragraph.forEach((node, offset) => {
389
+ if (offset < end && !node.marks.some(({ type }) => type.name === "deletion")) text += node.isText ? (node.text ?? "").slice(0, end - offset) : "";
390
+ });
391
+ return text;
392
+ };
393
+ /**
394
+ * The text before the caret once what is struck has gone: what typing over a
395
+ * selection leaves. A paragraph whose break is struck joins the one after it.
396
+ */
397
+ const textBeforeCaretLeft = ($head) => {
398
+ let text = liveText($head.parent, $head.parentOffset);
399
+ const container = $head.node($head.depth - 1);
400
+ for (let index = $head.index($head.depth - 1) - 1; index >= 0; index--) {
401
+ const before = container.child(index);
402
+ if (before.attrs["pPrMark"]?.kind !== "del") break;
403
+ text = liveText(before, before.content.size) + text;
404
+ }
405
+ return text;
406
+ };
386
407
  /**
387
408
  * List autoformat while suggesting. The suggestion plugin has already
388
409
  * recorded the typed space as a tracked insertion; this follows it with the
@@ -396,7 +417,7 @@ const suggestedListAutoformat = (autoformat) => new Plugin({ appendTransaction(t
396
417
  if (!transactions.some((tr) => tr.getMeta("suggestionModeTextInput") === " ")) return null;
397
418
  const { $head, empty } = state.selection;
398
419
  if (!empty || !makeRevisionInfo(state) || !acceptsListMarker($head.parent)) return null;
399
- const requests = listRequestsForMarker($head.parent.textBetween(0, $head.parentOffset, null, ""));
420
+ const requests = listRequestsForMarker(textBeforeCaretLeft($head));
400
421
  if (!requests) return null;
401
422
  const start = $head.start();
402
423
  const tr = state.tr;
@@ -124,6 +124,7 @@ const EMPTY_SPAN = new RegExp(`<span(?:\\s${TAG_TAIL})?><\\/span>`, "gi");
124
124
  const MAX_EMPTY_SPAN_PASSES = 5;
125
125
  const INTERNAL_CLIPBOARD_ATTR_PATTERN = /\s+data-docx-internal-clipboard(?:="([^"]*)"|='([^']*)'|=([^\s>]+))?/gi;
126
126
  const TEXTBOX_ANCHOR_ATTR = /\s+data-docx-textbox-anchor(?:="[^"]*"|='[^']*')?/gi;
127
+ const HYPHEN_ELEMENT_ATTR = /\s+data-docx-hyphen-element(?:="[^"]*"|='[^']*'|=[^\s>]+)?/gi;
127
128
  const BOOKMARK_BOUNDARY_ATTR = /\s+data-docx-bookmark-(?:boundary|id|name|col-first|col-last)(?:="[^"]*"|='[^']*'|=[^\s>]+)?/gi;
128
129
  const RANGE_ANCHOR_ATTR = /\s+data-docx-range-anchor(?:="[^"]*"|='[^']*'|=[^\s>]+)?/gi;
129
130
  const COMMENT_RANGE_BOUNDARY_ATTR = /\s+data-docx-comment-range-boundary(?:="[^"]*"|='[^']*'|=[^\s>]+)?/gi;
@@ -145,6 +146,10 @@ function stripForeignTextBoxAnchors(html, internal) {
145
146
  if (internal) return html;
146
147
  return html.replace(TEXTBOX_ANCHOR_ATTR, "");
147
148
  }
149
+ function stripForeignHyphenElements(html, internal) {
150
+ if (internal) return html;
151
+ return html.replace(HYPHEN_ELEMENT_ATTR, "");
152
+ }
148
153
  function stripForeignBookmarkBoundaries(html, internal) {
149
154
  if (internal) return html;
150
155
  return html.replace(BOOKMARK_BOUNDARY_ATTR, "");
@@ -187,6 +192,7 @@ function cleanPastedHtml(html, options = {}) {
187
192
  cleaned = stripMsoStyles(cleaned);
188
193
  cleaned = stripEmptySpans(cleaned, internal);
189
194
  cleaned = stripForeignTextBoxAnchors(cleaned, internal);
195
+ cleaned = stripForeignHyphenElements(cleaned, internal);
190
196
  cleaned = stripForeignBookmarkBoundaries(cleaned, internal);
191
197
  cleaned = stripForeignRangeCarriers(cleaned, internal);
192
198
  cleaned = stripForeignStructuredFields(cleaned, internal);