@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
@@ -148,17 +148,38 @@ function wrapFlanking(inner, mark, { before, after }) {
148
148
  }
149
149
  return units.slice(0, start).join("") + applyMarks(units.slice(start, end).join(""), start < end ? [mark] : []) + units.slice(end).join("");
150
150
  }
151
- /** Paragraph content that writes nothing to the line. */
152
- const SILENT_MARKERS = /* @__PURE__ */ new Set([
153
- "bookmarkStart",
154
- "bookmarkEnd",
155
- "moveFromRangeStart",
156
- "moveFromRangeEnd",
157
- "moveToRangeStart",
158
- "moveToRangeEnd"
159
- ]);
160
- /** Comment range markers, which write nothing when comments are stripped. */
161
- const COMMENT_MARKERS = /* @__PURE__ */ new Set(["commentRangeStart", "commentRangeEnd"]);
151
+ /**
152
+ * Whether paragraph content puts nothing on the line in this render. Left out
153
+ * of the content before runs group, so the runs on either side of it meet as
154
+ * they do on the line: emphasis closed and reopened around nothing reads as
155
+ * literal asterisks. Exhaustive, so new content decides here.
156
+ */
157
+ const writesNothing = (ctx, item) => {
158
+ switch (item.type) {
159
+ case "bookmarkStart":
160
+ case "bookmarkEnd":
161
+ case "moveFromRangeStart":
162
+ case "moveFromRangeEnd":
163
+ case "moveToRangeStart":
164
+ case "moveToRangeEnd":
165
+ case "preservedInline": return true;
166
+ case "commentRangeStart":
167
+ case "commentRangeEnd":
168
+ case "commentReference": return ctx.opts.comments === "strip";
169
+ case "mathEquation": return !item.plainText;
170
+ case "inlineSdt":
171
+ case "inlineWrapper": return item.content.every((child) => writesNothing(ctx, child));
172
+ case "run":
173
+ case "hyperlink":
174
+ case "simpleField":
175
+ case "complexField":
176
+ case "insertion":
177
+ case "deletion":
178
+ case "moveFrom":
179
+ case "moveTo": return false;
180
+ default: return item;
181
+ }
182
+ };
162
183
  /** The first character `piece` puts on the line, inside the marks `outer` already opened. */
163
184
  const pieceStart = (piece, outer, order) => {
164
185
  const first = piece.text.match(INLINE_UNIT)?.[0];
@@ -449,6 +470,40 @@ const cleanRevisionContent = (content) => content.flatMap((item) => {
449
470
  default: return [item];
450
471
  }
451
472
  });
473
+ const COMMENT_MARKER_TYPES = /* @__PURE__ */ new Set([
474
+ "commentRangeStart",
475
+ "commentRangeEnd",
476
+ "commentReference"
477
+ ]);
478
+ /**
479
+ * A comment marker bounds its comment wherever it stands; a save may write it
480
+ * inside the revision wrapper of the text it starts at, or beside it. Revision
481
+ * wrappers are split around their comment markers, so either reads the same.
482
+ */
483
+ const commentMarkersOutsideRevisions = (content) => content.flatMap((item) => {
484
+ switch (item.type) {
485
+ case "insertion":
486
+ case "deletion":
487
+ case "moveFrom":
488
+ case "moveTo": break;
489
+ default: return [item];
490
+ }
491
+ const parts = [];
492
+ let held = [];
493
+ const flush = () => {
494
+ if (held.length > 0) parts.push({
495
+ ...item,
496
+ content: held
497
+ });
498
+ held = [];
499
+ };
500
+ for (const child of commentMarkersOutsideRevisions(item.content)) if (COMMENT_MARKER_TYPES.has(child.type)) {
501
+ flush();
502
+ parts.push(child);
503
+ } else held.push(child);
504
+ flush();
505
+ return parts;
506
+ });
452
507
  /**
453
508
  * Render the full inline content of a paragraph, tracking comment-range
454
509
  * boundaries to apply the configured wrapper.
@@ -459,7 +514,8 @@ function renderParagraphInline(ctx, pkg, content, paraId, edges = {
459
514
  }) {
460
515
  let out = "";
461
516
  const openComments = [];
462
- const items = (ctx.opts.trackedChanges === "clean" ? cleanRevisionContent(content) : content).filter((item) => !SILENT_MARKERS.has(item.type) && !(ctx.opts.comments === "strip" && COMMENT_MARKERS.has(item.type)));
517
+ const hoistedContent = commentMarkersOutsideRevisions(content);
518
+ const items = (ctx.opts.trackedChanges === "clean" ? cleanRevisionContent(hoistedContent) : hoistedContent).filter((item) => !writesNothing(ctx, item));
463
519
  const around = (index) => {
464
520
  const next = items[index + 1];
465
521
  return {
@@ -1,5 +1,6 @@
1
1
  import { Node } from "prosemirror-model";
2
2
  import { Transaction } from "prosemirror-state";
3
+ import { Transform } from "prosemirror-transform";
3
4
  /** The id a text box anchor names, or `undefined` for anything else. */
4
5
  export declare const textBoxAnchorIdOf: (node: Node) => string | undefined;
5
6
  /** The anchor ids of the text boxes drawn in `node`. */
@@ -31,4 +32,4 @@ export declare const textBoxAnchorIdsBetween: (doc: Node, from: number, to: numb
31
32
  * boxes drawn in it, which stand between the two, past that paragraph, where
32
33
  * they follow the joined one. Returns whether any moved.
33
34
  */
34
- export declare const moveTextBoxesPastNextParagraph: (tr: Transaction, position: number) => boolean;
35
+ export declare const moveTextBoxesPastNextParagraph: (tr: Transform, position: number) => boolean;
@@ -29,9 +29,10 @@ import { getFolioNodeRevisionCarriers, nodePropertyRevisionSites } from "../revi
29
29
  import { RUN_FORMATTING_MARK_NAMES } from "../runFormattingMarkNames.js";
30
30
  import { reconstructRejectedRunFormattingMarks, restoreHistoricalRunFormatting } from "../runPropertyChangeResolution.js";
31
31
  import { paragraphRunStyleContextAt } from "../runStyleFormatting.js";
32
+ import { sectionRecordCopyPositions } from "../sectionCarrier.js";
32
33
  import { getTableCellMergeChange } from "../tableCellMergeRevision.js";
33
34
  import { isTableCellRetainedInReviewView } from "../tableCellRevisionVisibility.js";
34
- import { markRowEmptiedInBatch, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCellsAfterBatch, removeTableRow } from "../tableGridMutation.js";
35
+ import { markRowEmptiedInBatch, reconcileOmittedGridSlots, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCellsAfterBatch, removeTableRow, rowHoldsNoCells } from "../tableGridMutation.js";
35
36
  import { runInCellPending, runParagraphIntoTable } from "../tableRunIn.js";
36
37
  import { retainedTrackedRevisionMark, trackedRevisionPathOf } from "../trackedRevisionPath.js";
37
38
  import { extractTrackedChanges } from "../utils/extractTrackedChanges.js";
@@ -391,6 +392,7 @@ function resolveChange(from, to, mode, revisionIds) {
391
392
  if (node.type.spec["tableRole"] === "table" && runInCellPending(node)) pendingTables.push(position);
392
393
  return !node.isTextblock;
393
394
  });
395
+ if (pPrMarkOps.some(({ action }) => action !== "clear")) for (const position of sectionRecordCopyPositions(tr.doc)) tr.setNodeAttribute(position, "_sectionProperties", null);
394
396
  const joinSeams = [];
395
397
  for (const op of pPrMarkOps) {
396
398
  const mappedPos = tr.mapping.map(op.paragraphPos);
@@ -429,7 +431,7 @@ function resolveChange(from, to, mode, revisionIds) {
429
431
  follows,
430
432
  holdsContent: paragraphContentOf(paragraph),
431
433
  markWasAdded: op.markWasAdded,
432
- containerStillEndsWithParagraph: resolved.parent.maybeChild(resolved.index() - 1)?.type.name === "paragraph",
434
+ containerStillEndsWithParagraph: preceding?.type.name === "paragraph" || preceding !== void 0 && resolved.parent.type.name === "blockSdt",
433
435
  followingTableCanReceiveRunIn: follows === "table" && boundaries.length === 0 && !pendingTables.some((position) => tr.mapping.map(position) === nextPos) && !ownsSectionEndpoint(paragraph),
434
436
  needsFollowingCommentHost: follows === "table" && preceding?.type.name !== "paragraph" && retainedBoundaries.blocks.length === 0 && retainedBoundaries.comments.length > 0,
435
437
  removedSectionProperties: op.markWasAdded && sectionProperties != null,
@@ -574,10 +576,20 @@ const terminalTableDeletionIsPending = (tr) => {
574
576
  };
575
577
  /** Resolve the Folio-only receiver Word needs after a terminal deleted table. */
576
578
  const resolveTerminalTableReviewCarrier = (tr, mode) => {
577
- const carrier = tr.doc.lastChild;
579
+ let position = tr.doc.content.size;
580
+ let carrier = null;
581
+ for (let index = tr.doc.childCount - 1; index >= 0; index--) {
582
+ carrier = tr.doc.child(index);
583
+ position -= carrier.nodeSize;
584
+ if (carrier.type.name !== "textBox") break;
585
+ }
578
586
  if (carrier?.type.name !== "paragraph" || carrier.attrs["reviewCarrier"] !== REVIEW_CARRIERS.TERMINAL_TABLE) return;
579
- const position = tr.doc.content.size - carrier.nodeSize;
580
- if (mode === "accept") {
587
+ let pending = carrier.attrs["pPrMark"] != null;
588
+ carrier.forEach((child) => {
589
+ pending ||= child.marks.some(({ type }) => ["insertion", "deletion"].includes(type.name));
590
+ });
591
+ if (pending) return;
592
+ if (mode === "accept" || carrier.content.size > 0) {
581
593
  tr.setNodeAttribute(position, "reviewCarrier", void 0);
582
594
  return;
583
595
  }
@@ -737,13 +749,15 @@ function deleteTableCellAt(tr, cellPos, emptied) {
737
749
  const cellOffset = cellPos - resolved.start(tableDepth);
738
750
  const removedColumn = TableMap.get(table).findCell(cellOffset).left;
739
751
  const spansDown = Number(cell.attrs["rowspan"]) > 1;
740
- if (row.childCount > 1 || spansDown) {
741
- if (row.childCount === 1) markRowEmptiedInBatch({
752
+ const holdsOtherCells = !rowHoldsNoCells(row, cell);
753
+ if (holdsOtherCells || spansDown) {
754
+ if (!holdsOtherCells) markRowEmptiedInBatch({
742
755
  tr,
743
756
  rowPosition: resolved.start() - 1,
744
757
  emptied
745
758
  });
746
759
  tr.delete(cellPos, cellPos + cell.nodeSize);
760
+ reconcileOmittedGridSlots(tr, tablePosition, table, removedColumn);
747
761
  reconcileTableGridAfterColumnRemoval({
748
762
  tr,
749
763
  tablePosition,
@@ -757,6 +771,7 @@ function deleteTableCellAt(tr, cellPos, emptied) {
757
771
  return;
758
772
  }
759
773
  deleteTableRowAt(tr, resolved.start() - 1);
774
+ reconcileOmittedGridSlots(tr, tablePosition, table, removedColumn);
760
775
  reconcileTableGridAfterColumnRemoval({
761
776
  tr,
762
777
  tablePosition,
@@ -0,0 +1,9 @@
1
+ import { Command } from "prosemirror-state";
2
+ /**
3
+ * Delete what the caret reaches past the inline anchors beside it.
4
+ *
5
+ * Left to the browser, the key removes the anchor's element, and the next DOM
6
+ * read loses the node: a bookmark or comment range, with the other half of its
7
+ * pair, while the text stays. Suggesting mode tracks the key before it gets here.
8
+ */
9
+ export declare const deleteBesideInlineAnchor: (join: Command, direction: "backward" | "forward") => Command;
@@ -0,0 +1,36 @@
1
+ import { isInlineAnchor } from "../extensions/nodes/inlineAnchorDom.js";
2
+ import { EditorState, TextSelection } from "prosemirror-state";
3
+ // src/prosemirror/commands/deleteBesideInlineAnchor.ts
4
+ /** The length of the first or last user-perceived character of `text`. */
5
+ const characterLength = (text, backward) => {
6
+ const segments = [...new Intl.Segmenter().segment(text)];
7
+ return (backward ? segments.at(-1) : segments.at(0))?.segment.length ?? 1;
8
+ };
9
+ /**
10
+ * Delete what the caret reaches past the inline anchors beside it.
11
+ *
12
+ * Left to the browser, the key removes the anchor's element, and the next DOM
13
+ * read loses the node: a bookmark or comment range, with the other half of its
14
+ * pair, while the text stays. Suggesting mode tracks the key before it gets here.
15
+ */
16
+ const deleteBesideInlineAnchor = (join, direction) => (state, dispatch, view) => {
17
+ const { selection, doc } = state;
18
+ if (!(selection instanceof TextSelection) || !selection.empty) return false;
19
+ const backward = direction === "backward";
20
+ const adjacent = (position) => {
21
+ const $position = doc.resolve(position);
22
+ return backward ? $position.nodeBefore : $position.nodeAfter;
23
+ };
24
+ let cursor = selection.from;
25
+ for (let node = adjacent(cursor); node && isInlineAnchor(node); node = adjacent(cursor)) cursor += backward ? -node.nodeSize : node.nodeSize;
26
+ if (cursor === selection.from) return false;
27
+ const next = adjacent(cursor);
28
+ if (!next) return join(EditorState.create({
29
+ doc,
30
+ selection: TextSelection.create(doc, cursor)
31
+ }), dispatch, view);
32
+ const size = next.isText ? characterLength(next.text ?? "", backward) : next.nodeSize;
33
+ dispatch?.(state.tr.delete(backward ? cursor - size : cursor, backward ? cursor : cursor + size).scrollIntoView());
34
+ return true;
35
+ };
36
+ export { deleteBesideInlineAnchor };
@@ -1,5 +1,6 @@
1
1
  import { Schema, Slice } from "prosemirror-model";
2
2
  import { Command } from "prosemirror-state";
3
+ import { EditorView } from "prosemirror-view";
3
4
  /**
4
5
  * Dispatched on the editor view DOM when the clipboard read behind a
5
6
  * "paste without formatting" keystroke fails (e.g. clipboard-read permission
@@ -18,6 +19,11 @@ export declare const CLIPBOARD_READ_ERROR_EVENT = "folio:clipboard-read-error";
18
19
  * editor's default text paste flows into the current line.
19
20
  */
20
21
  export declare function buildPlainTextSlice(text: string, schema: Schema): Slice;
22
+ /**
23
+ * Put plain text in place of the selection: through the session that owns the
24
+ * view, or as a suggestion when suggesting, as a paste from the keyboard is.
25
+ */
26
+ export declare const pastePlainTextSlice: (view: EditorView, slice: Slice) => void;
21
27
  /**
22
28
  * Read the clipboard and insert it as unformatted text at the current selection.
23
29
  *
@@ -1,4 +1,5 @@
1
1
  import { dispatchClipboardIntent } from "../clipboardIntent.js";
2
+ import { handleSuggestionPaste, suggestionModeKey } from "../plugins/suggestionMode.js";
2
3
  import { Fragment, Slice } from "prosemirror-model";
3
4
  // src/prosemirror/commands/pastePlainText.ts
4
5
  /**
@@ -34,6 +35,16 @@ function buildPlainTextSlice(text, schema) {
34
35
  return Slice.maxOpen(Fragment.fromArray(paragraphs));
35
36
  }
36
37
  /**
38
+ * Put plain text in place of the selection: through the session that owns the
39
+ * view, or as a suggestion when suggesting, as a paste from the keyboard is.
40
+ */
41
+ const pastePlainTextSlice = (view, slice) => {
42
+ if (dispatchClipboardIntent(view, slice) !== void 0) return;
43
+ const suggesting = suggestionModeKey.getState(view.state);
44
+ if (suggesting?.active && handleSuggestionPaste(view, slice, suggesting)) return;
45
+ view.dispatch(view.state.tr.replaceSelection(slice).scrollIntoView());
46
+ };
47
+ /**
37
48
  * Read the clipboard and insert it as unformatted text at the current selection.
38
49
  *
39
50
  * Dry-runnable per the ProseMirror command convention: applicability does not
@@ -54,8 +65,7 @@ const pasteWithoutFormatting = (state, dispatch, view) => {
54
65
  const { schema } = state;
55
66
  navigator.clipboard.readText().then((text) => {
56
67
  if (!text || view.isDestroyed) return;
57
- const slice = buildPlainTextSlice(text, schema);
58
- if (dispatchClipboardIntent(view, slice) === void 0) view.dispatch(view.state.tr.replaceSelection(slice).scrollIntoView());
68
+ pastePlainTextSlice(view, buildPlainTextSlice(text, schema));
59
69
  }).catch((error) => {
60
70
  if (typeof CustomEvent === "function" && !view.isDestroyed) view.dom.dispatchEvent(new CustomEvent(CLIPBOARD_READ_ERROR_EVENT, {
61
71
  detail: { error },
@@ -64,4 +74,4 @@ const pasteWithoutFormatting = (state, dispatch, view) => {
64
74
  });
65
75
  return true;
66
76
  };
67
- export { CLIPBOARD_READ_ERROR_EVENT, buildPlainTextSlice, pasteWithoutFormatting };
77
+ export { CLIPBOARD_READ_ERROR_EVENT, buildPlainTextSlice, pastePlainTextSlice, pasteWithoutFormatting };
@@ -376,6 +376,7 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
376
376
  const widthRemovals = [];
377
377
  let currentWidth = map.width;
378
378
  let removedCell = false;
379
+ const removedColumns = [];
379
380
  const deletedRows = /* @__PURE__ */ new Set();
380
381
  const byPosition = /* @__PURE__ */ new Map();
381
382
  const ordered = [];
@@ -387,7 +388,7 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
387
388
  const node = row.child(cellIndex);
388
389
  const rectangle = cellRectangle(cellOffset);
389
390
  const left = rectangle.left;
390
- for (let coveredRow = rectangle.top; coveredRow < rectangle.bottom; coveredRow++) rowOccupancy[coveredRow] = elementAt(rowOccupancy, coveredRow) + (rectangle.right - rectangle.left);
391
+ for (let coveredRow = rectangle.top; coveredRow < rectangle.bottom && !node.attrs["_omittedGridSlot"]; coveredRow++) rowOccupancy[coveredRow] = elementAt(rowOccupancy, coveredRow) + (rectangle.right - rectangle.left);
391
392
  const initial = elementAt(elementAt(rowMetadata, rowIndex).cells, cellIndex);
392
393
  const entry = {
393
394
  node: mergeDecisions.origins.has(cellOffset) ? node.type.create(resolvedTableMergeOriginAttrs(node), node.content, node.marks) : node,
@@ -407,6 +408,9 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
407
408
  rowOffset += row.nodeSize;
408
409
  }
409
410
  for (const width of rowOccupancy) widthCounts.set(width, (widthCounts.get(width) ?? 0) + 1);
411
+ const spanOf = ({ node }) => Number(node.attrs["colspan"]) || 1;
412
+ const omittedIn = (rowIndex) => [...elementAt(rowCells, rowIndex).values()].filter(({ node }) => node.attrs["_omittedGridSlot"] != null);
413
+ currentWidth = Math.max(0, ...rowOccupancy);
410
414
  const changeRowWidth = (rowIndex, nextWidth) => {
411
415
  if (!elementAt(activeRows, rowIndex)) return;
412
416
  const previous = elementAt(rowOccupancy, rowIndex);
@@ -427,12 +431,13 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
427
431
  }, entry.node.content, entry.node.marks);
428
432
  } else {
429
433
  removedCell = true;
434
+ removedColumns.push(entry.left);
430
435
  const previousWidth = currentWidth;
431
436
  const rectangle = cellRectangle(entry.position);
432
437
  const colspan = rectangle.right - rectangle.left;
433
438
  for (let coveredRow = rectangle.top; coveredRow < rectangle.bottom; coveredRow++) changeRowWidth(coveredRow, elementAt(rowOccupancy, coveredRow) - colspan);
434
439
  elementAt(rowCells, entry.row).delete(entry.left);
435
- if (elementAt(rowCells, entry.row).size === 0) {
440
+ if ([...elementAt(rowCells, entry.row).values()].every(({ node }) => node.attrs["_omittedGridSlot"] != null)) {
436
441
  deletedRows.add(entry.row);
437
442
  activeRows[entry.row] = false;
438
443
  const rowWidth = elementAt(rowOccupancy, entry.row);
@@ -530,6 +535,29 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
530
535
  _docxVMergeContinuationCells: remaining.length > 0 ? remaining : null
531
536
  }, entry.node.content, entry.node.marks);
532
537
  }
538
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
539
+ if (deletedRows.has(rowIndex)) continue;
540
+ const slots = omittedIn(rowIndex);
541
+ let excess = elementAt(rowOccupancy, rowIndex) + slots.reduce((total, slot) => total + spanOf(slot), 0) - currentWidth;
542
+ const atRemoval = ({ left, node }) => removedColumns.some((column) => column >= left && column < left + (Number(node.attrs["colspan"]) || 1));
543
+ const order = [...slots.filter(atRemoval), ...slots.filter((slot) => !atRemoval(slot)).toReversed()];
544
+ for (const slot of order) {
545
+ if (excess <= 0) break;
546
+ const span = spanOf(slot);
547
+ if (span <= excess) {
548
+ elementAt(rowCells, rowIndex).delete(slot.left);
549
+ removedCell = true;
550
+ excess -= span;
551
+ continue;
552
+ }
553
+ slot.touched = true;
554
+ slot.node = slot.node.type.create({
555
+ ...slot.node.attrs,
556
+ colspan: span - excess
557
+ }, slot.node.content, slot.node.marks);
558
+ excess = 0;
559
+ }
560
+ }
533
561
  if (deletedRows.size === rows.length) return {
534
562
  node: null,
535
563
  changed: true,
@@ -3,7 +3,8 @@ import { expectParagraphAttrs } from "../attrs/index.js";
3
3
  import { rejectedListRenderingPatch } from "../listRendering.js";
4
4
  import { effectiveParagraphNumbering, paragraphNumberingAttr, paragraphNumberingSourcesFromBoundary } from "../numberingAttr.js";
5
5
  import { paragraphIndentationFromFormatting } from "../paragraphIndentation.js";
6
- import { resolveParagraphDefaultTextFormatting } from "../styles/paragraphStyleCascade.js";
6
+ import { resolveParagraphInheritedRunFormatting } from "../runStyleFormatting.js";
7
+ import { inheritableParagraphMarkFormatting, resolveParagraphDefaultTextFormatting } from "../styles/paragraphStyleCascade.js";
7
8
  import { listIndentationProvenancePatch } from "../styles/resolvedStyleAttrs.js";
8
9
  import { paragraphRejectAttrPatch, paragraphRejectOriginalFormatting, removeParagraphPropertyChanges, sectionRejectProperties } from "./propertyChangeScope.js";
9
10
  // src/prosemirror/commands/resolveParagraphProperties.ts
@@ -70,7 +71,19 @@ const resolveParagraphChangeAttrs = ({ node, boundaryCovered, mode, revisionSet,
70
71
  });
71
72
  Object.assign(nextAttrs, indentation);
72
73
  nextAttrs["_originalFormatting"] = restoredFormatting;
73
- if (styleResolver) nextAttrs["defaultTextFormatting"] = resolveParagraphDefaultTextFormatting(rejection.previousFormatting?.styleId, restoredFormatting ?? void 0, styleResolver) ?? null;
74
+ if (styleResolver) {
75
+ const styleId = rejection.previousFormatting?.styleId;
76
+ nextAttrs["defaultTextFormatting"] = (node.content.size === 0 ? resolveParagraphDefaultTextFormatting(styleId, restoredFormatting ?? void 0, styleResolver) : resolveParagraphInheritedRunFormatting({
77
+ styleId,
78
+ tableRunFormatting: expectParagraphAttrs(node)._tableRunFormatting,
79
+ styleResolver,
80
+ paragraphMarkFormatting: inheritableParagraphMarkFormatting({
81
+ runProperties: restoredFormatting?.runProperties,
82
+ styleId,
83
+ styleResolver
84
+ })
85
+ }).inheritedFormatting) ?? null;
86
+ }
74
87
  }
75
88
  }
76
89
  }
@@ -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);