@stll/folio-core 0.66.2 → 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 (119) hide show
  1. package/dist/ai-edits/apply.js +45 -10
  2. package/dist/ai-edits/batch-claims.js +5 -3
  3. package/dist/ai-edits/clean-text.js +4 -1
  4. package/dist/ai-edits/read.js +6 -4
  5. package/dist/ai-edits/snapshot.js +24 -14
  6. package/dist/ai-edits/table-cell-mutations.js +3 -2
  7. package/dist/ai-edits/table-row-column-mutations.js +20 -6
  8. package/dist/controller/canonicalComposition.d.ts +1 -1
  9. package/dist/controller/canonicalComposition.js +76 -18
  10. package/dist/controller/canonicalInput.d.ts +0 -1
  11. package/dist/controller/canonicalInput.js +19 -1
  12. package/dist/controller/canonicalSession.js +1 -2
  13. package/dist/controller/hiddenEditorManager.d.ts +6 -0
  14. package/dist/controller/hiddenEditorManager.js +3 -1
  15. package/dist/controller/layoutPipeline.d.ts +2 -0
  16. package/dist/controller/layoutPipeline.js +7 -3
  17. package/dist/controller/layoutSession.d.ts +1 -0
  18. package/dist/display-list/build/tablePrimitives.d.ts +3 -1
  19. package/dist/display-list/build/tablePrimitives.js +29 -13
  20. package/dist/docx/chartPreview.d.ts +4 -1
  21. package/dist/docx/chartPreview.js +26 -15
  22. package/dist/docx/mainDocumentPart.d.ts +6 -0
  23. package/dist/docx/mainDocumentPart.js +65 -0
  24. package/dist/docx/packageParts.d.ts +1 -1
  25. package/dist/docx/packageParts.js +10 -4
  26. package/dist/docx/previewBudget.d.ts +6 -0
  27. package/dist/docx/previewBudget.js +7 -1
  28. package/dist/docx/rezip.js +4 -4
  29. package/dist/docx/shapeAlternateContent.js +19 -0
  30. package/dist/docx/unzip.js +2 -0
  31. package/dist/i18n/messages/ar.gen.js +1 -0
  32. package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
  33. package/dist/i18n/messages/catalogs.gen.js +17 -0
  34. package/dist/i18n/messages/cs.gen.js +1 -0
  35. package/dist/i18n/messages/de.gen.js +1 -0
  36. package/dist/i18n/messages/en.gen.js +1 -0
  37. package/dist/i18n/messages/es.gen.js +1 -0
  38. package/dist/i18n/messages/et.gen.js +1 -0
  39. package/dist/i18n/messages/fr.gen.js +1 -0
  40. package/dist/i18n/messages/he.gen.js +1 -0
  41. package/dist/i18n/messages/hi.gen.js +1 -0
  42. package/dist/i18n/messages/hu.gen.js +1 -0
  43. package/dist/i18n/messages/lt.gen.js +1 -0
  44. package/dist/i18n/messages/lv.gen.js +1 -0
  45. package/dist/i18n/messages/messages.gen.d.ts +1 -0
  46. package/dist/i18n/messages/pl.gen.js +1 -0
  47. package/dist/i18n/messages/pt-BR.gen.js +1 -0
  48. package/dist/i18n/messages/sk.gen.js +1 -0
  49. package/dist/i18n/messages/tr.gen.js +1 -0
  50. package/dist/i18n/messages/zh-CN.gen.js +1 -0
  51. package/dist/internal/wholeStoryRevisionResolution.js +57 -12
  52. package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +10 -0
  53. package/dist/layout-bridge/convert/altChunkPlaceholder.js +70 -0
  54. package/dist/layout-bridge/convert/fixedTableColumnWidths.js +2 -1
  55. package/dist/layout-bridge/convert/flowConversionShared.d.ts +10 -0
  56. package/dist/layout-bridge/convert/flowConversionShared.js +11 -1
  57. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  58. package/dist/layout-bridge/convert/footnoteLayout.js +4 -1
  59. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  60. package/dist/layout-bridge/convert/headerFooterLayout.js +6 -1
  61. package/dist/layout-bridge/convert/tableConversion.js +6 -2
  62. package/dist/layout-bridge/convert/toFlowBlocks.js +4 -0
  63. package/dist/layout-bridge/engine/clickToPosition.js +5 -1
  64. package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
  65. package/dist/layout-engine/measure/tableCellFloating.js +1 -0
  66. package/dist/layout-engine/measure/tableVisibleBand.d.ts +16 -0
  67. package/dist/layout-engine/measure/tableVisibleBand.js +28 -0
  68. package/dist/layout-engine/tableLayout.js +7 -4
  69. package/dist/layout-engine/tableRowBreak.d.ts +10 -0
  70. package/dist/layout-engine/tableRowBreak.js +151 -36
  71. package/dist/layout-engine/types.d.ts +7 -2
  72. package/dist/layout-painter/previewSvg.d.ts +8 -0
  73. package/dist/layout-painter/previewSvg.js +47 -0
  74. package/dist/layout-painter/renderImage.js +2 -1
  75. package/dist/layout-painter/renderPage.d.ts +1 -0
  76. package/dist/layout-painter/renderPage.js +6 -3
  77. package/dist/layout-painter/renderParagraph.js +3 -2
  78. package/dist/layout-painter/renderTable.d.ts +5 -2
  79. package/dist/layout-painter/renderTable.js +33 -19
  80. package/dist/prosemirror/anchoredTextBoxes.d.ts +2 -1
  81. package/dist/prosemirror/commands/comments.js +20 -7
  82. package/dist/prosemirror/commands/deleteBesideInlineAnchor.d.ts +9 -0
  83. package/dist/prosemirror/commands/deleteBesideInlineAnchor.js +36 -0
  84. package/dist/prosemirror/commands/pastePlainText.d.ts +6 -0
  85. package/dist/prosemirror/commands/pastePlainText.js +13 -3
  86. package/dist/prosemirror/commands/resolveAllTableChanges.js +30 -2
  87. package/dist/prosemirror/commentReferenceIntegrity.d.ts +8 -2
  88. package/dist/prosemirror/commentReferenceIntegrity.js +19 -4
  89. package/dist/prosemirror/conversion/fromProseDoc.js +39 -4
  90. package/dist/prosemirror/conversion/toProseDoc.js +6 -4
  91. package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +3 -1
  92. package/dist/prosemirror/extensions/core/ParagraphExtension.js +8 -9
  93. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +46 -11
  94. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
  95. package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +2 -3
  96. package/dist/prosemirror/extensions/features/ListExtension.js +22 -1
  97. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +5 -0
  98. package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
  99. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +8 -4
  100. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +5 -1
  101. package/dist/prosemirror/extensions/nodes/CommentRangeBoundaryExtension.js +2 -1
  102. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +4 -3
  103. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +2 -1
  104. package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +2 -1
  105. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +2 -1
  106. package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +2 -1
  107. package/dist/prosemirror/extensions/nodes/TableExtension.js +87 -7
  108. package/dist/prosemirror/extensions/nodes/inlineAnchorDom.d.ts +11 -0
  109. package/dist/prosemirror/extensions/nodes/inlineAnchorDom.js +21 -0
  110. package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -8
  111. package/dist/prosemirror/plugins/suggestionMode.js +175 -21
  112. package/dist/prosemirror/rowGridOmissions.d.ts +11 -0
  113. package/dist/prosemirror/rowGridOmissions.js +21 -0
  114. package/dist/prosemirror/tableGridMutation.d.ts +19 -2
  115. package/dist/prosemirror/tableGridMutation.js +118 -15
  116. package/dist/prosemirror/tablePositionedBookmarks.d.ts +2 -0
  117. package/dist/prosemirror/tablePositionedBookmarks.js +80 -0
  118. package/dist/prosemirror/validation.js +1 -1
  119. package/package.json +2 -2
@@ -40,6 +40,8 @@ export type CommentReferenceRepair = {
40
40
  type CommentReferenceRepairInput = {
41
41
  references: readonly CommentReferenceOccurrence[];
42
42
  markExtents: readonly CommentMarkExtent[];
43
+ /** Comments anchored by their reference alone, covering nothing before too. */
44
+ pointIds?: ReadonlySet<number>;
43
45
  };
44
46
  export declare const COMMENT_REFERENCE_NODE_NAME = "commentReference";
45
47
  /**
@@ -48,11 +50,15 @@ export declare const COMMENT_REFERENCE_NODE_NAME = "commentReference";
48
50
  * without mapping; the insertions that follow still carry pre-repair positions
49
51
  * and the applier maps them through the transaction.
50
52
  */
51
- export declare const planCommentReferenceRepairs: ({ references, markExtents }: CommentReferenceRepairInput) => readonly CommentReferenceRepair[];
53
+ export declare const planCommentReferenceRepairs: ({ references, markExtents, pointIds }: CommentReferenceRepairInput) => readonly CommentReferenceRepair[];
52
54
  type CommentReferenceResolution = {
53
55
  doc: Node;
54
56
  steps: Step[];
55
57
  positionMaps: readonly StepMap[];
56
58
  };
57
- export declare const resolveCommentReferences: (doc: Node) => CommentReferenceResolution | null;
59
+ /**
60
+ * Repair `doc`. `previous` is the document it was changed from: only a change
61
+ * can orphan a reference, so what stood alone there still stands.
62
+ */
63
+ export declare const resolveCommentReferences: (doc: Node, previous?: Node) => CommentReferenceResolution | null;
58
64
  export {};
@@ -76,7 +76,7 @@ const surveyCommentReferences = (doc) => {
76
76
  * without mapping; the insertions that follow still carry pre-repair positions
77
77
  * and the applier maps them through the transaction.
78
78
  */
79
- const planCommentReferenceRepairs = ({ references, markExtents }) => {
79
+ const planCommentReferenceRepairs = ({ references, markExtents, pointIds }) => {
80
80
  const markedIds = new Set(markExtents.map(({ commentId }) => commentId));
81
81
  const deletions = [];
82
82
  const keptIds = /* @__PURE__ */ new Set();
@@ -89,7 +89,7 @@ const planCommentReferenceRepairs = ({ references, markExtents }) => {
89
89
  });
90
90
  continue;
91
91
  }
92
- if (!markedIds.has(reference.commentId)) {
92
+ if (!markedIds.has(reference.commentId) && !(pointIds?.has(reference.commentId) && !keptIds.has(reference.commentId))) {
93
93
  deletions.push({
94
94
  type: "delete",
95
95
  position: reference.position,
@@ -118,9 +118,24 @@ const planCommentReferenceRepairs = ({ references, markExtents }) => {
118
118
  }
119
119
  return [...deletions.toSorted((first, second) => second.position - first.position), ...insertions.toSorted((first, second) => second.position - first.position)];
120
120
  };
121
- const resolveCommentReferences = (doc) => {
121
+ /** Comments in `doc` with a reference and no content or range to cover. */
122
+ const pointCommentIds = ({ references, markExtents }) => {
123
+ const marked = new Set(markExtents.map(({ commentId }) => commentId));
124
+ const ids = /* @__PURE__ */ new Set();
125
+ for (const reference of references) if (reference.status === "valid" && !marked.has(reference.commentId)) ids.add(reference.commentId);
126
+ return ids;
127
+ };
128
+ /**
129
+ * Repair `doc`. `previous` is the document it was changed from: only a change
130
+ * can orphan a reference, so what stood alone there still stands.
131
+ */
132
+ const resolveCommentReferences = (doc, previous) => {
122
133
  const survey = surveyCommentReferences(doc);
123
- const repairs = planCommentReferenceRepairs(survey);
134
+ const orphans = pointCommentIds(survey);
135
+ const repairs = planCommentReferenceRepairs({
136
+ ...survey,
137
+ ...previous && orphans.size > 0 ? { pointIds: pointCommentIds(surveyCommentReferences(previous)) } : {}
138
+ });
124
139
  if (repairs.length === 0 && survey.unanchoredMarks.length === 0) return null;
125
140
  const transform = new Transform(doc);
126
141
  for (const { position, size, mark } of survey.unanchoredMarks) transform.removeMark(position, position + size, mark);
@@ -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";
@@ -2129,7 +2130,8 @@ function extractParagraphContent(originalParagraph, _documentCounts, emptyHyperl
2129
2130
  content.push(createNoteReferenceRun(noteRefMark, node.marks, formattingContext));
2130
2131
  return;
2131
2132
  }
2132
- if (linkMark) {
2133
+ const fieldUnderLink = node.type.name === "field" || node.type.name === "structuredField";
2134
+ if (linkMark && !fieldUnderLink) {
2133
2135
  const linkKey = getLinkKey(linkMark);
2134
2136
  if (currentHyperlink && currentHyperlinkKey === linkKey) {} else {
2135
2137
  flushCurrentInline();
@@ -2794,6 +2796,25 @@ function createTabRun(node, marks, formattingContext) {
2794
2796
  if (marks) restoreRunRecord(run, marks);
2795
2797
  return run;
2796
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
+ };
2797
2818
  function createFieldFromNode(node, { baseParagraphFormatting, inheritedFormatting, marks, paragraphMarkFormatting, paragraphMarkPrecedesStyle, styleResolver, textBoxAnchorMarkers }) {
2798
2819
  const attrs = expectFieldAttrs(node);
2799
2820
  const formatting = marks && marks.length > 0 ? marksToTextFormatting(marks, {
@@ -2803,13 +2824,14 @@ function createFieldFromNode(node, { baseParagraphFormatting, inheritedFormattin
2803
2824
  paragraphMarkPrecedesStyle,
2804
2825
  styleResolver
2805
2826
  }) : void 0;
2806
- const extractedContent = extractParagraphContent(node, void 0, void 0, textBoxAnchorMarkers, false, {
2827
+ const fieldFormattingContext = {
2807
2828
  baseParagraphFormatting,
2808
2829
  inheritedFormatting,
2809
2830
  paragraphMarkFormatting,
2810
2831
  paragraphMarkPrecedesStyle: paragraphMarkPrecedesStyle ?? false,
2811
2832
  styleResolver: styleResolver ?? null
2812
- }).filter(isSimpleFieldContent);
2833
+ };
2834
+ const extractedContent = extractParagraphContent(withoutTheFieldsOwnMarks(node), void 0, void 0, textBoxAnchorMarkers, false, fieldFormattingContext).filter(isSimpleFieldContent);
2813
2835
  const displayText = attrs.displayText ?? "";
2814
2836
  const displayRun = {
2815
2837
  type: "run",
@@ -3413,6 +3435,19 @@ function tableAttrsToFormatting(attrs) {
3413
3435
  /**
3414
3436
  * Convert a ProseMirror table row node to our TableRow type
3415
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
+ };
3416
3451
  function convertPMTableRow(node, documentCounts, activeVerticalMerges, styleResolver = null) {
3417
3452
  const attrs = expectTableRowAttrs(node);
3418
3453
  const cells = [];
@@ -3456,7 +3491,7 @@ function convertPMTableRow(node, documentCounts, activeVerticalMerges, styleReso
3456
3491
  type: "tableRow",
3457
3492
  cells
3458
3493
  };
3459
- const rowFormatting = tableRowAttrsToFormatting(attrs);
3494
+ const rowFormatting = withOmittedGridSlots(tableRowAttrsToFormatting(attrs), node);
3460
3495
  if (rowFormatting) row.formatting = rowFormatting;
3461
3496
  if (attrs._tablePropertyExceptions) row.tablePropertyExceptions = attrs._tablePropertyExceptions;
3462
3497
  if (Array.isArray(attrs.tblPrExChange) && attrs.tblPrExChange.length > 0) row.tablePropertyExceptionChanges = [...attrs.tblPrExChange];
@@ -1100,10 +1100,11 @@ function convertTable(table, styleResolver, context) {
1100
1100
  const totalRows = table.rows.length;
1101
1101
  const gridColumnCount = columnWidths?.length ?? 0;
1102
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);
1103
1104
  const rows = table.rows.map((row, rowIndex) => {
1104
1105
  const isFirstRowStyled = rowIndex === 0 && look.firstRow;
1105
1106
  const resolvedRowJustification = tableStyle?.trPr?.justification ?? fallbackTableStyle?.trPr?.justification;
1106
- 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);
1107
1108
  });
1108
1109
  return schema.node("table", attrs, rows);
1109
1110
  }
@@ -1133,7 +1134,7 @@ function createOmittedGridSlotCell({ colspan, slot, columnWidths, totalWidth, st
1133
1134
  /**
1134
1135
  * Convert a TableRow to a ProseMirror table row node
1135
1136
  */
1136
- 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) {
1137
1138
  const attrsWithoutStructuralChange = { isHeader: !!row.formatting?.header };
1138
1139
  if (row.formatting?.height?.value !== void 0) attrsWithoutStructuralChange.height = row.formatting.height.value;
1139
1140
  if (row.formatting?.heightRule) attrsWithoutStructuralChange.heightRule = row.formatting.heightRule;
@@ -1253,8 +1254,9 @@ function convertTableRow(row, styleResolver, context, isHeaderRow, columnWidths,
1253
1254
  defaultCellMargins
1254
1255
  }));
1255
1256
  }
1256
- if (gridAfter > 0) cells.push(createOmittedGridSlotCell({
1257
- colspan: gridAfter,
1257
+ const omittedAfter = Math.max(gridAfter, (mapWidth ?? 0) - colIndex);
1258
+ if (omittedAfter > 0) cells.push(createOmittedGridSlotCell({
1259
+ colspan: omittedAfter,
1258
1260
  slot: "after",
1259
1261
  columnWidths,
1260
1262
  totalWidth,
@@ -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;
@@ -140,6 +140,11 @@ const HyperlinkExtension = createMarkExtension({
140
140
  tooltip: tooltip || null
141
141
  });
142
142
  let tr = state.tr.addMark(from, to, mark);
143
+ state.doc.nodesBetween(from, to, (node, position) => {
144
+ if (node.type.name !== "field" && node.type.name !== "structuredField") return true;
145
+ tr = tr.removeMark(position, position + node.nodeSize, hlType);
146
+ return false;
147
+ });
143
148
  const textColorType = state.schema.marks["textColor"];
144
149
  if (textColorType) tr = tr.removeMark(from, to, textColorType);
145
150
  dispatch(tr.scrollIntoView());
@@ -22,7 +22,7 @@ const TextColorExtension = createMarkExtension({
22
22
  parseDOM: [{
23
23
  style: "color",
24
24
  getAttrs: (value) => {
25
- const hexMatch = /#(?<hex>[0-9a-fA-F]{6}|[0-9a-fA-F]{3})/u.exec(value);
25
+ const hexMatch = /^#(?<hex>[0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/u.exec(value);
26
26
  if (hexMatch) return { rgb: (hexMatch.groups?.["hex"] ?? "").toUpperCase() };
27
27
  return false;
28
28
  }
@@ -16,9 +16,13 @@ import { authorFromClipboardRevision } from "../features/clipboardTrackedRevisio
16
16
  * ProseMirror toDOM runs before the layout painter, so we set the
17
17
  * decoration here for correct rendering in both the layout-painter
18
18
  * path and the ProseMirror DOM path.
19
+ *
20
+ * The line is a longhand because the underline and strike parse rules read the
21
+ * `text-decoration` shorthand. A review mark's presentation is not run
22
+ * formatting, and ProseMirror reads this DOM back on every native edit.
19
23
  */
20
- const insertionStyle = (color) => `color: ${color}; text-decoration: underline; text-decoration-color: ${color};`;
21
- const deletionStyle = (color) => `color: ${color}; text-decoration: line-through; text-decoration-color: ${color};`;
24
+ const insertionStyle = (color) => `color: ${color}; text-decoration-line: underline; text-decoration-color: ${color};`;
25
+ const deletionStyle = (color) => `color: ${color}; text-decoration-line: line-through; text-decoration-color: ${color};`;
22
26
  /**
23
27
  * Suggested (AI-proposed) tracked changes reuse the insertion/deletion visual
24
28
  * grammar but with a DOTTED stroke and a dedicated suggestion hue, kept
@@ -31,8 +35,8 @@ const deletionStyle = (color) => `color: ${color}; text-decoration: line-through
31
35
  const SUGGESTION_COLOR = "var(--suggestion-color, #6d3bd6)";
32
36
  const SUGGESTION_TINT = "var(--suggestion-bg, color-mix(in oklch, #6d3bd6 12%, transparent))";
33
37
  const SUGGESTION_TINT_LAYER = `linear-gradient(${SUGGESTION_TINT}, ${SUGGESTION_TINT})`;
34
- const suggestedInsertionStyle = () => `color: ${SUGGESTION_COLOR}; text-decoration: underline; text-decoration-style: dotted; text-decoration-color: ${SUGGESTION_COLOR}; background-image: ${SUGGESTION_TINT_LAYER};`;
35
- const suggestedDeletionStyle = () => `color: ${SUGGESTION_COLOR}; text-decoration: line-through; text-decoration-style: dotted; text-decoration-color: ${SUGGESTION_COLOR}; background-image: ${SUGGESTION_TINT_LAYER};`;
38
+ const suggestedInsertionStyle = () => `color: ${SUGGESTION_COLOR}; text-decoration-line: underline; text-decoration-style: dotted; text-decoration-color: ${SUGGESTION_COLOR}; background-image: ${SUGGESTION_TINT_LAYER};`;
39
+ const suggestedDeletionStyle = () => `color: ${SUGGESTION_COLOR}; text-decoration-line: line-through; text-decoration-style: dotted; text-decoration-color: ${SUGGESTION_COLOR}; background-image: ${SUGGESTION_TINT_LAYER};`;
36
40
  const revisionAncestorsFromDom = (serialized) => {
37
41
  if (serialized === void 0) return null;
38
42
  try {
@@ -4,6 +4,7 @@ import { findInvalidBookmarkBoundaryIds } from "../../bookmarkBoundaryIntegrity.
4
4
  import { createNodeExtension } from "../create.js";
5
5
  import { BLOCK_BOOKMARK_BOUNDARY_NODE_NAME } from "./BlockBookmarkBoundaryExtension.js";
6
6
  import { bookmarkBoundaryAttrSpec, bookmarkBoundaryDomAttributes, parseBookmarkBoundaryDom } from "./bookmarkBoundaryDom.js";
7
+ import { INLINE_ANCHOR_DOM_STYLE } from "./inlineAnchorDom.js";
7
8
  import { Plugin } from "prosemirror-state";
8
9
  // src/prosemirror/extensions/nodes/BookmarkBoundaryExtension.ts
9
10
  /** The node name, for callers asking whether a paragraph holds any content. */
@@ -73,7 +74,10 @@ const BookmarkBoundaryExtension = createNodeExtension({
73
74
  getAttrs: (dom) => parseBookmarkBoundaryDom(dom, options.getInternalClipboardToken?.())
74
75
  }],
75
76
  toDOM(node) {
76
- return ["span", bookmarkBoundaryDomAttributes(node, options.getInternalClipboardToken?.())];
77
+ return ["span", {
78
+ ...bookmarkBoundaryDomAttributes(node, options.getInternalClipboardToken?.()),
79
+ style: INLINE_ANCHOR_DOM_STYLE
80
+ }];
77
81
  }
78
82
  }),
79
83
  onSchemaReady: () => ({ plugins: [new Plugin({ appendTransaction(transactions, _oldState, newState) {
@@ -1,5 +1,6 @@
1
1
  import { expectCommentRangeBoundaryAttrs, readCommentRangeBoundaryMarker } from "../../commentRangeBoundaryAttrs.js";
2
2
  import { createNodeExtension } from "../create.js";
3
+ import { INLINE_ANCHOR_DOM_STYLE } from "./inlineAnchorDom.js";
3
4
  // src/prosemirror/extensions/nodes/CommentRangeBoundaryExtension.ts
4
5
  const COMMENT_RANGE_BOUNDARY_NODE_NAME = "commentRangeBoundary";
5
6
  const COMMENT_RANGE_BOUNDARY_DOM_ATTRIBUTE = "data-docx-comment-range-boundary";
@@ -33,7 +34,7 @@ const CommentRangeBoundaryExtension = createNodeExtension({
33
34
  [COMMENT_RANGE_BOUNDARY_DOM_ATTRIBUTE]: JSON.stringify(marker),
34
35
  "aria-hidden": "true",
35
36
  contenteditable: "false",
36
- style: "display: none;",
37
+ style: INLINE_ANCHOR_DOM_STYLE,
37
38
  ...options.getInternalClipboardToken ? { "data-docx-internal-clipboard": options.getInternalClipboardToken() } : {}
38
39
  }];
39
40
  }
@@ -1,6 +1,7 @@
1
1
  import { readCommentReferenceAttrs } from "../../commentReferenceAttrs.js";
2
2
  import { COMMENT_REFERENCE_NODE_NAME, resolveCommentReferences } from "../../commentReferenceIntegrity.js";
3
3
  import { createNodeExtension } from "../create.js";
4
+ import { INLINE_ANCHOR_DOM_STYLE } from "./inlineAnchorDom.js";
4
5
  import { Plugin } from "prosemirror-state";
5
6
  // src/prosemirror/extensions/nodes/CommentReferenceExtension.ts
6
7
  /** Zero-width `w:commentReference`: where a comment's visible mark is painted. */
@@ -29,14 +30,14 @@ const CommentReferenceExtension = createNodeExtension({
29
30
  "data-docx-comment-reference": String(attrs.ok ? attrs.value.commentId : ""),
30
31
  "aria-hidden": "true",
31
32
  contenteditable: "false",
32
- style: "display: none;",
33
+ style: INLINE_ANCHOR_DOM_STYLE,
33
34
  ...options.getInternalClipboardToken ? { "data-docx-internal-clipboard": options.getInternalClipboardToken() } : {}
34
35
  }];
35
36
  }
36
37
  }),
37
- onSchemaReady: () => ({ plugins: [new Plugin({ appendTransaction(transactions, _oldState, newState) {
38
+ onSchemaReady: () => ({ plugins: [new Plugin({ appendTransaction(transactions, oldState, newState) {
38
39
  if (!transactions.some(({ docChanged }) => docChanged)) return null;
39
- const resolution = resolveCommentReferences(newState.doc);
40
+ const resolution = resolveCommentReferences(newState.doc, oldState.doc);
40
41
  if (!resolution) return null;
41
42
  const transaction = newState.tr;
42
43
  for (const step of resolution.steps) transaction.step(step);
@@ -1,6 +1,7 @@
1
1
  import { INTERNAL_CLIPBOARD_TOKEN_ATTRIBUTE, isInternalClipboardDom } from "../../copyOriginDom.js";
2
2
  import { expectMoveRangeBoundaryAttrs, moveRangeMarkerForDom, readMoveRangeMarker, withoutUntrustedCopyOrigin } from "../../moveRangeBoundaryAttrs.js";
3
3
  import { createNodeExtension } from "../create.js";
4
+ import { INLINE_ANCHOR_DOM_STYLE } from "./inlineAnchorDom.js";
4
5
  // src/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.ts
5
6
  /** Hidden boundary for one non-empty tracked-move range. */
6
7
  const MOVE_RANGE_BOUNDARY_NODE_NAME = "moveRangeBoundary";
@@ -37,7 +38,7 @@ const MoveRangeBoundaryExtension = createNodeExtension({
37
38
  [MOVE_RANGE_BOUNDARY_DOM_ATTRIBUTE]: JSON.stringify(marker),
38
39
  "aria-hidden": "true",
39
40
  contenteditable: "false",
40
- style: "display: none;",
41
+ style: INLINE_ANCHOR_DOM_STYLE,
41
42
  ...internalClipboardToken ? { [INTERNAL_CLIPBOARD_TOKEN_ATTRIBUTE]: internalClipboardToken } : {}
42
43
  }];
43
44
  }
@@ -1,5 +1,6 @@
1
1
  import { expectNoteMarkerAttrs } from "../../../internal/noteMarkerAttrs.js";
2
2
  import { createNodeExtension } from "../create.js";
3
+ import { INLINE_ANCHOR_DOM_STYLE } from "./inlineAnchorDom.js";
3
4
  // src/prosemirror/extensions/nodes/NoteMarkerExtension.ts
4
5
  /** An authored automatic note mark: invisible, but retained through PM JSON and edits. */
5
6
  const NOTE_MARKER_NODE_NAME = "noteMarker";
@@ -27,7 +28,7 @@ const NoteMarkerExtension = createNodeExtension({
27
28
  "data-docx-note-marker": kind,
28
29
  "aria-hidden": "true",
29
30
  contenteditable: "false",
30
- style: "display: none;"
31
+ style: INLINE_ANCHOR_DOM_STYLE
31
32
  }];
32
33
  }
33
34
  }
@@ -3,6 +3,7 @@ import { INTERNAL_CLIPBOARD_TOKEN_ATTRIBUTE, isInternalClipboardDom } from "../.
3
3
  import { withoutUntrustedCopyOrigin } from "../../moveRangeBoundaryAttrs.js";
4
4
  import { readRangeAnchorAttrs, readRangeAnchorValues } from "../../rangeAnchorAttrs.js";
5
5
  import { createNodeExtension } from "../create.js";
6
+ import { INLINE_ANCHOR_DOM_STYLE } from "./inlineAnchorDom.js";
6
7
  // src/prosemirror/extensions/nodes/RangeAnchorExtension.ts
7
8
  /** Zero-width comment or tracked-move range that spans no content. */
8
9
  /** The node name, for callers asking whether a paragraph holds any content. */
@@ -52,7 +53,7 @@ const RangeAnchorExtension = createNodeExtension({
52
53
  [RANGE_ANCHOR_DOM_ATTRIBUTE]: serializedMarkers,
53
54
  "aria-hidden": "true",
54
55
  contenteditable: "false",
55
- style: "display: none;",
56
+ style: INLINE_ANCHOR_DOM_STYLE,
56
57
  ...internalClipboardToken ? { [INTERNAL_CLIPBOARD_TOKEN_ATTRIBUTE]: internalClipboardToken } : {}
57
58
  }];
58
59
  }
@@ -1,4 +1,5 @@
1
1
  import { createNodeExtension } from "../create.js";
2
+ import { INLINE_ANCHOR_DOM_STYLE } from "./inlineAnchorDom.js";
2
3
  // src/prosemirror/extensions/nodes/RenderedPageBreakExtension.ts
3
4
  /** Zero-width cached pagination boundary preserved from DOCX. */
4
5
  /**
@@ -19,7 +20,7 @@ const RenderedPageBreakExtension = createNodeExtension({
19
20
  toDOM() {
20
21
  return ["span", {
21
22
  "data-docx-rendered-page-break": "true",
22
- style: "display: none;"
23
+ style: INLINE_ANCHOR_DOM_STYLE
23
24
  }];
24
25
  }
25
26
  }