@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
@@ -26,6 +26,12 @@ type PositionRange = {
26
26
  from: number;
27
27
  to: number;
28
28
  };
29
+ /** A paragraph before a deleted one that ends its container; see `paragraphsBefore`. */
30
+ type ParagraphBefore = {
31
+ block: number;
32
+ /** Its break is not already pending deletion. */
33
+ keepsBreak: boolean;
34
+ };
29
35
  /** The text an operation rewrites (`text`), only marks (`annotation`), or breaks (`split`). */
30
36
  type InlineClaim = {
31
37
  type: "text" | "annotation" | "split";
@@ -55,6 +61,17 @@ export type BatchClaim = InlineClaim |
55
61
  * any other does — see `followedByInsertion`.
56
62
  */
57
63
  keepsParagraph: boolean;
64
+ /** The paragraph ends its container, before anything the batch adds. */
65
+ endsContainer: boolean;
66
+ /**
67
+ * Tracked, the paragraphs before one that ends its container, nearest
68
+ * first, up to the container's start or a block that is not one. The
69
+ * nearest the batch keeps, when its break stays, is the one whose break
70
+ * the deletion retires: accepting runs it into this paragraph with its
71
+ * own properties, as applied directly this one goes. Empty applied
72
+ * directly, and for a paragraph that ends nothing.
73
+ */
74
+ paragraphsBefore: readonly ParagraphBefore[];
58
75
  } |
59
76
  /**
60
77
  * Joins `block` with the block starting at `next`, where `block` ends.
@@ -128,6 +145,15 @@ export declare class BatchClaims {
128
145
  private readonly columnInsertions;
129
146
  /** Accepted deletions that keep their paragraph, by where the paragraph starts and ends. */
130
147
  private readonly keptParagraphs;
148
+ /**
149
+ * Whether a tracked deletion of a paragraph that ends its container retires
150
+ * the break of the paragraph before, given the claims accepted so far: the
151
+ * nearest paragraph before it the batch does not delete keeps its break,
152
+ * and no merge of the batch deletes that break first.
153
+ */
154
+ private retiresBreakBefore;
155
+ /** `role` with what it takes from the batch's other claims settled. */
156
+ private settled;
131
157
  /** `claim`'s roles, given the insertions accepted so far. */
132
158
  private rolesOf;
133
159
  /**
@@ -43,7 +43,11 @@ const blockRolesOf = (claim) => {
43
43
  block: claim.block,
44
44
  role: {
45
45
  kind: "deleteBlock",
46
- keepsParagraph: claim.keepsParagraph
46
+ keepsParagraph: claim.keepsParagraph,
47
+ endsContainer: claim.endsContainer,
48
+ paragraphsBefore: claim.paragraphsBefore,
49
+ retiresBreakBefore: false,
50
+ everyParagraphBeforeGoes: false
47
51
  }
48
52
  }];
49
53
  case "merge": return [{
@@ -105,7 +109,7 @@ const rolesConflict = (left, right) => {
105
109
  if (ROLE_RANK[right.kind] > ROLE_RANK[left.kind]) return rolesConflict(right, left);
106
110
  switch (left.kind) {
107
111
  case "deleteBlock": switch (right.kind) {
108
- case "paragraphProperties": return !left.keepsParagraph;
112
+ case "paragraphProperties": return left.endsContainer && (!left.keepsParagraph || left.retiresBreakBefore || left.everyParagraphBeforeGoes);
109
113
  case "mergeNext": return false;
110
114
  default: return true;
111
115
  }
@@ -122,7 +126,7 @@ const rolesConflict = (left, right) => {
122
126
  case "mergeNext": return false;
123
127
  default: return true;
124
128
  }
125
- case "mergeNext": return right.kind === "paragraphProperties" && (left.joinsNow || left.setsProperties);
129
+ case "mergeNext": return right.kind === "paragraphProperties" && left.setsProperties;
126
130
  case "paragraphProperties": return right.kind === "split" || right.kind === "paragraphProperties";
127
131
  case "split":
128
132
  case "text":
@@ -155,6 +159,28 @@ var BatchClaims = class {
155
159
  columnInsertions = /* @__PURE__ */ new Map();
156
160
  /** Accepted deletions that keep their paragraph, by where the paragraph starts and ends. */
157
161
  keptParagraphs = /* @__PURE__ */ new Map();
162
+ /**
163
+ * Whether a tracked deletion of a paragraph that ends its container retires
164
+ * the break of the paragraph before, given the claims accepted so far: the
165
+ * nearest paragraph before it the batch does not delete keeps its break,
166
+ * and no merge of the batch deletes that break first.
167
+ */
168
+ retiresBreakBefore(role) {
169
+ for (const { block, keepsBreak } of role.paragraphsBefore) {
170
+ const entries = this.blocks.get(block) ?? [];
171
+ if (entries.some((entry) => entry.role.kind === "deleteBlock")) continue;
172
+ return keepsBreak && !entries.some((entry) => entry.role.kind === "mergeOwn");
173
+ }
174
+ return false;
175
+ }
176
+ /** `role` with what it takes from the batch's other claims settled. */
177
+ settled(role) {
178
+ return role.kind === "deleteBlock" ? {
179
+ ...role,
180
+ retiresBreakBefore: this.retiresBreakBefore(role),
181
+ everyParagraphBeforeGoes: role.paragraphsBefore.length > 0 && role.paragraphsBefore.every(({ block }) => (this.blocks.get(block) ?? []).some((entry) => entry.role.kind === "deleteBlock"))
182
+ } : role;
183
+ }
158
184
  /** `claim`'s roles, given the insertions accepted so far. */
159
185
  rolesOf(claim) {
160
186
  return blockRolesOf(claim).map(({ block, role }) => role.kind === "deleteBlock" && role.keepsParagraph && claim.type === "deleteBlock" && (this.insertions.has(claim.end) || this.insertions.has(claim.block)) ? {
@@ -184,8 +210,9 @@ var BatchClaims = class {
184
210
  * conflicts with none.
185
211
  */
186
212
  conflictOf(claim) {
187
- for (const { block, role } of this.rolesOf(claim)) {
188
- for (const entry of this.blocks.get(block) ?? []) if (rolesConflict(entry.role, role)) return entry.operationId;
213
+ for (const { block, role: claimed } of this.rolesOf(claim)) {
214
+ const role = this.settled(claimed);
215
+ for (const entry of this.blocks.get(block) ?? []) if (rolesConflict(this.settled(entry.role), role)) return entry.operationId;
189
216
  const fold = this.foldAt(block);
190
217
  if (fold !== null) return fold;
191
218
  if (role.kind === "deleteBlock") continue;
@@ -104,7 +104,10 @@ const buildCleanBlockText = (blockNode, blockFrom, { fieldResults, noteReference
104
104
  });
105
105
  return false;
106
106
  }
107
- const atomText = fieldResults === "omitted" ? runFormattingInlineControlCharacter(node) : runFormattingInlineAtomCleanText(node);
107
+ let atomText;
108
+ if (fieldResults === "omitted") atomText = runFormattingInlineControlCharacter(node);
109
+ else if (node.type.name === "structuredField") atomText = node.textContent;
110
+ else atomText = runFormattingInlineAtomCleanText(node);
108
111
  if (atomText !== null) {
109
112
  if (isOmittedFromCleanView(node)) return false;
110
113
  const startPos = blockFrom + 1 + pos;
@@ -383,6 +383,12 @@ export declare class FolioDocxReviewer {
383
383
  * the anchor map the apply layer resolves operations against.
384
384
  */
385
385
  snapshot(): FolioAIEditSnapshot;
386
+ /**
387
+ * The numbering ids every story but `story` defines: the package's and the
388
+ * lists each story started. Numbering ids are package-wide, while a story's
389
+ * state completes its numbering from its own paragraphs only.
390
+ */
391
+ private numberingIdsOutside;
386
392
  /** Every suggestion id the document's stories still carry. */
387
393
  private activeSuggestionIds;
388
394
  /** Export staged AI operations for storage by the host, outside the DOCX. */
@@ -2,7 +2,7 @@ import { matchInlineAtoms } from "../compare/inline-atoms.js";
2
2
  import { matchInlineProvenance } from "../compare/inline-provenance.js";
3
3
  import { stageSectionBoundaryProperties } from "../compare/section-boundary-properties.js";
4
4
  import { importReferencedStyleDefinitions, styleClosureNumberingReferences } from "../compare/style-resources.js";
5
- import { applyFolioDocumentOperations } from "../document-operations.js";
5
+ import { applyFolioDocumentOperationsInPackage } from "../document-operations.js";
6
6
  import { removeCommentMarkers } from "../docx/commentAnchorIndex.js";
7
7
  import { applyReplyThreadMarkers } from "../docx/commentReplyMarkers.js";
8
8
  import { commentTextParagraph } from "../docx/commentTextParagraph.js";
@@ -620,6 +620,26 @@ var FolioDocxReviewer = class FolioDocxReviewer {
620
620
  snapshot() {
621
621
  return createStateSnapshot(this.state);
622
622
  }
623
+ /**
624
+ * The numbering ids every story but `story` defines: the package's and the
625
+ * lists each story started. Numbering ids are package-wide, while a story's
626
+ * state completes its numbering from its own paragraphs only.
627
+ */
628
+ numberingIdsOutside(story) {
629
+ const key = editableStoryKey(story);
630
+ const states = [...story.type === "main" ? [] : [this.state], ...[...this.secondaryStoryStates.values()].filter(({ handle }) => editableStoryKey(handle) !== key).map(({ state }) => state)];
631
+ const numIds = /* @__PURE__ */ new Set();
632
+ const abstractNumIds = /* @__PURE__ */ new Set();
633
+ for (const state of states) {
634
+ const definitions = getDocumentNumbering(state)?.definitions;
635
+ for (const { numId } of definitions?.nums ?? []) numIds.add(numId);
636
+ for (const { abstractNumId } of definitions?.abstractNums ?? []) abstractNumIds.add(abstractNumId);
637
+ }
638
+ return {
639
+ numIds,
640
+ abstractNumIds
641
+ };
642
+ }
623
643
  /** Every suggestion id the document's stories still carry. */
624
644
  activeSuggestionIds() {
625
645
  const active = new Set(getSuggestions(this.state).map(({ suggestionId }) => suggestionId));
@@ -904,7 +924,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
904
924
  view.state = view.state.apply(transaction);
905
925
  }
906
926
  };
907
- const result = applyFolioDocumentOperations({
927
+ const result = applyFolioDocumentOperationsInPackage({
908
928
  view,
909
929
  snapshot: sourceSnapshot,
910
930
  batch,
@@ -915,6 +935,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
915
935
  ...tableTemplates !== void 0 && { tableTemplates },
916
936
  ...replacementBackground !== void 0 && { replacementBackground },
917
937
  undefinedReferences,
938
+ numberingIdsElsewhere: this.numberingIdsOutside(story),
918
939
  ...restagesSuggestions === true ? { restagesSuggestions } : { pendingSuggestionIds: this.activeSuggestionIds() },
919
940
  createCommentId: (text) => {
920
941
  const comment = createReviewerComment({
@@ -1577,9 +1598,10 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1577
1598
  view.state = view.state.apply(transaction);
1578
1599
  }
1579
1600
  };
1580
- const applied = applyFolioDocumentOperations({
1601
+ const applied = applyFolioDocumentOperationsInPackage({
1581
1602
  undefinedReferences: "refuse",
1582
1603
  restagesSuggestions: true,
1604
+ numberingIdsElsewhere: this.numberingIdsOutside(story),
1583
1605
  view,
1584
1606
  snapshot,
1585
1607
  batch: {
@@ -1,3 +1,4 @@
1
+ import { NumberingIdsInUse } from "../docx/numberingIds.js";
1
2
  import { FolioContentStatedNumbering } from "../compare/content-types.js";
2
3
  import { ListKind } from "../docx/listNumberingInstances.js";
3
4
  import { FolioAIEditOperation, FolioAIListNumbering, FolioAINewListReference, FolioAIResolvedEditOperation } from "./types.js";
@@ -23,6 +24,8 @@ export declare const stageNewListOperations: (operations: readonly FolioAIEditOp
23
24
  * Replace every new-list request with a reference to an instance minted for
24
25
  * its operation: one instance per operation and kind. `numbering` is the map
25
26
  * the batch applies against; the result's map adds the minted instances.
27
+ * `elsewhere` holds the ids the package's other stories define, which no
28
+ * minted instance takes.
26
29
  */
27
- export declare const resolveNewListOperations: (operations: readonly FolioAIStagedEditOperation[], numbering: NumberingMap | null) => ResolvedNewLists;
30
+ export declare const resolveNewListOperations: (operations: readonly FolioAIStagedEditOperation[], numbering: NumberingMap | null, elsewhere: NumberingIdsInUse) => ResolvedNewLists;
28
31
  export {};
@@ -82,8 +82,10 @@ const stageNewListOperations = (operations) => deferNewListRequests(operations);
82
82
  * Replace every new-list request with a reference to an instance minted for
83
83
  * its operation: one instance per operation and kind. `numbering` is the map
84
84
  * the batch applies against; the result's map adds the minted instances.
85
+ * `elsewhere` holds the ids the package's other stories define, which no
86
+ * minted instance takes.
85
87
  */
86
- const resolveNewListOperations = (operations, numbering) => {
88
+ const resolveNewListOperations = (operations, numbering, elsewhere) => {
87
89
  let definitions = numbering?.definitions;
88
90
  let minted = false;
89
91
  return {
@@ -94,7 +96,7 @@ const resolveNewListOperations = (operations, numbering) => {
94
96
  if (value.kind !== "deferredNewList") return value;
95
97
  let numId = instances.get(value.allocation);
96
98
  if (numId === void 0) {
97
- const instance = mintListInstance(definitions, { kind: value.allocation.format });
99
+ const instance = mintListInstance(definitions, { kind: value.allocation.format }, elsewhere);
98
100
  definitions = instance.definitions;
99
101
  minted = true;
100
102
  numId = instance.numId;
@@ -1,6 +1,6 @@
1
1
  import { expectRunPropertyChangeMarkAttrs, expectTrackedChangeMarkAttrs } from "../prosemirror/attrs/index.js";
2
2
  import { getFolioNodeRevisionCarriers } from "../prosemirror/revisionCarriers.js";
3
- import { expandRunFormattingCarrier, runFormattingCarrierReviewText, runFormattingInlineAtomDisposition } from "../prosemirror/runFormattingInlineCarriers.js";
3
+ import { expandRunFormattingCarrier, runFormattingCarrierReviewText, runFormattingInlineAtomDisposition, runFormattingInlineAtomResultText } from "../prosemirror/runFormattingInlineCarriers.js";
4
4
  import { getTableCellMergeChange } from "../prosemirror/tableCellMergeRevision.js";
5
5
  import { enclosingInsertionAncestors, trackedRevisionLayerOf } from "../prosemirror/trackedRevisionPath.js";
6
6
  import { commentAnchorIdsForNode } from "./comment-lifecycle.js";
@@ -356,8 +356,10 @@ const getCommentAnchorsFromDoc = (doc) => {
356
356
  start: bodyText.length,
357
357
  end: bodyText.length
358
358
  });
359
- if (!node.isInline || node.text === void 0) return;
360
- const text = readerTextOf(node, noteReferences);
359
+ const isStructuredField = node.type.name === "structuredField";
360
+ const fieldText = isStructuredField ? node.textContent : runFormattingInlineAtomResultText(node);
361
+ if (!node.isInline || node.text === void 0 && fieldText === null) return;
362
+ const text = node.text === void 0 ? fieldText ?? "" : readerTextOf(node, noteReferences);
361
363
  const end = bodyText.length + text.length;
362
364
  for (const mark of node.marks) {
363
365
  if (mark.type !== commentType || typeof mark.attrs["commentId"] !== "number") continue;
@@ -372,7 +374,7 @@ const getCommentAnchorsFromDoc = (doc) => {
372
374
  end
373
375
  });
374
376
  }
375
- bodyText += text;
377
+ if (!isStructuredField) bodyText += text;
376
378
  });
377
379
  return [...ranges].map(([commentId, { blockId, start, end }]) => ({
378
380
  commentId,
@@ -368,7 +368,7 @@ const STORY_TABLE_HIDDEN_SUBTREE = "hidden-subtree";
368
368
  const STORY_TABLE = "table";
369
369
  /** Shared visibility and table-role rule for both story projection walks. */
370
370
  const classifyNonTextblockStoryTableNode = (node) => {
371
- if (isHiddenTableRow(node)) return STORY_TABLE_HIDDEN_SUBTREE;
371
+ if (isHiddenTableRow(node) || node.attrs["_omittedGridSlot"]) return STORY_TABLE_HIDDEN_SUBTREE;
372
372
  return node.type.spec["tableRole"] === TABLE_ROLE_TABLE ? STORY_TABLE : STORY_TABLE_CONTAINER;
373
373
  };
374
374
  /**
@@ -704,18 +704,7 @@ const getPreviewRuns = ({ node, nodeFrom, cleanBlock, styleResolver }) => {
704
704
  const defaultStyle = getDefaultPreviewRunStyle(node, styleResolver);
705
705
  let paragraphStyleContext;
706
706
  let cleanOffset = 0;
707
- node.descendants((child, relativePosition) => {
708
- const start = nodeFrom + 1 + relativePosition;
709
- const noteReference = cleanBlock.structuralBoundaries.find((boundary) => boundary.type === "noteReference" && boundary.from === start);
710
- let text;
711
- if (noteReference !== void 0) text = cleanBlock.text.slice(noteReference.offset, noteReference.offset + noteReference.length);
712
- else text = child.isText ? child.text : runFormattingInlineAtomCleanText(child);
713
- if (text === void 0 || text === null || text.length === 0) return true;
714
- if (child.marks.some((mark) => mark.type.name === DELETION_MARK || mark.type.name === HIDDEN_MARK)) return false;
715
- while ((cleanBlock.offsets[cleanOffset] ?? Number.POSITIVE_INFINITY) < start) cleanOffset++;
716
- const lastCharacterPosition = child.isText && noteReference === void 0 ? start + text.length - 1 : start;
717
- if (cleanBlock.offsets[cleanOffset] !== start || cleanBlock.offsets[cleanOffset + text.length - 1] !== lastCharacterPosition) return false;
718
- cleanOffset += text.length;
707
+ const pushRun = (child, text) => {
719
708
  const style = getPreviewRunStyle(child.marks, defaultStyle);
720
709
  const hasAuthorshipCarrier = child.marks.some(({ type }) => type.name === RUN_FORMATTING_OVERRIDE_MARK || type.name === CHARACTER_STYLE_MARK);
721
710
  let directFormatting;
@@ -734,13 +723,34 @@ const getPreviewRuns = ({ node, nodeFrom, cleanBlock, styleResolver }) => {
734
723
  const previous = runs.at(-1);
735
724
  if (previous && samePreviewRunStyle(previous, style) && sameDirectFormatting(previous.directFormatting, directFormatting)) {
736
725
  previous.text += text;
737
- return false;
726
+ return;
738
727
  }
739
728
  runs.push({
740
729
  text,
741
730
  ...style,
742
731
  ...!isEmptyPreviewRunStyle(directFormatting) && { directFormatting }
743
732
  });
733
+ };
734
+ node.descendants((child, relativePosition) => {
735
+ const start = nodeFrom + 1 + relativePosition;
736
+ const noteReference = cleanBlock.structuralBoundaries.find((boundary) => boundary.type === "noteReference" && boundary.from === start);
737
+ let text;
738
+ if (noteReference !== void 0) text = cleanBlock.text.slice(noteReference.offset, noteReference.offset + noteReference.length);
739
+ else if (child.type.name === "structuredField") text = child.textContent;
740
+ else text = child.isText ? child.text : runFormattingInlineAtomCleanText(child);
741
+ if (text === void 0 || text === null || text.length === 0) return true;
742
+ if (child.marks.some((mark) => mark.type.name === DELETION_MARK || mark.type.name === HIDDEN_MARK)) return false;
743
+ while ((cleanBlock.offsets[cleanOffset] ?? Number.POSITIVE_INFINITY) < start) cleanOffset++;
744
+ const lastCharacterPosition = child.isText && noteReference === void 0 ? start + text.length - 1 : start;
745
+ if (cleanBlock.offsets[cleanOffset] !== start || cleanBlock.offsets[cleanOffset + text.length - 1] !== lastCharacterPosition) return false;
746
+ cleanOffset += text.length;
747
+ if (child.type.name === "structuredField") {
748
+ child.forEach((run) => {
749
+ if (run.isText && run.text) pushRun(run, run.text);
750
+ });
751
+ return false;
752
+ }
753
+ pushRun(child, text);
744
754
  return false;
745
755
  });
746
756
  if (runs.every(isUnstyledPreviewRun)) return;
@@ -22,7 +22,7 @@ const mergeTableRectangle = ({ tr, tablePosition, table, rectangle }) => {
22
22
  const cellPosition = map.map[row * map.width + column];
23
23
  if (cellPosition === void 0 || seen.has(cellPosition)) continue;
24
24
  const cell = table.nodeAt(cellPosition);
25
- if (!cell) return null;
25
+ if (!cell || cell.attrs["_omittedGridSlot"]) return null;
26
26
  seen.add(cellPosition);
27
27
  cells.push({
28
28
  position: cellPosition,
@@ -63,7 +63,7 @@ const mergeTableRectangle = ({ tr, tablePosition, table, rectangle }) => {
63
63
  const contentStart = isEmptyTableCell(merged.cell) ? absoluteMergedPosition + 1 : contentEnd;
64
64
  tr = tr.replaceWith(contentStart, contentEnd, appendedContent);
65
65
  }
66
- removeRowsWithoutCells(tr, tablePosition);
66
+ removeRowsWithoutCells(tr, tablePosition, table);
67
67
  return tr;
68
68
  };
69
69
  const mergeTopRowColwidths = (cells, mergedColspan) => {
@@ -109,6 +109,7 @@ const mergeTrackedVerticalTableCells = ({ tr, tablePosition, table, rectangle, r
109
109
  const position = map.map[row * map.width + rectangle.left];
110
110
  if (position === void 0) return null;
111
111
  const cell = table.nodeAt(position);
112
+ if (cell?.attrs["_omittedGridSlot"]) return null;
112
113
  if (!cell || !tableRectanglesEqual(map.findCell(position), {
113
114
  left: rectangle.left,
114
115
  top: row,
@@ -1,6 +1,6 @@
1
1
  import { addTrackedDeletionMark } from "../prosemirror/addTrackedDeletionMark.js";
2
2
  import { markStructuralChange } from "../prosemirror/extensions/features/ParagraphChangeTrackerExtension.js";
3
- import { markRowsEmptiedInBatch, reconcileTableGridAfterColumnInsertion, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCells, removeTableRow } from "../prosemirror/tableGridMutation.js";
3
+ import { markRowsEmptiedInBatch, omittedSlotTakingColumn, reconcileTableGridAfterColumnInsertion, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCells, removeTableRow } from "../prosemirror/tableGridMutation.js";
4
4
  import { sliceText } from "../utils/sliceText.js";
5
5
  import { stripBlockIdentityAttrs } from "./block-identity.js";
6
6
  import { findEnclosingTableCell, findEnclosingTableRow } from "./table-targets.js";
@@ -177,7 +177,7 @@ const applyTableColumnInsertion = ({ tr, insertion, cellTexts, revision }) => {
177
177
  if (insertion.columnIndex >= 0 && insertion.columnIndex <= map.width) {
178
178
  const overflow = describeUnplacedCellTexts({
179
179
  cellTexts,
180
- capacity: getInsertedPhysicalColumnRows(map, insertion.columnIndex).length,
180
+ capacity: getInsertedPhysicalColumnRows(map, table, insertion.columnIndex).length,
181
181
  target: "column"
182
182
  });
183
183
  if (overflow !== null) return {
@@ -200,6 +200,10 @@ const applyTableColumnInsertion = ({ tr, insertion, cellTexts, revision }) => {
200
200
  tr.setNodeMarkup(position, void 0, action.attrs);
201
201
  continue;
202
202
  }
203
+ if (action.type === "growOmittedSlot") {
204
+ tr.setNodeAttribute(position, "colspan", action.colspan);
205
+ continue;
206
+ }
203
207
  const cell = revision ? action.cell.type.create({
204
208
  ...action.cell.attrs,
205
209
  cellMarker: {
@@ -267,7 +271,7 @@ const applyTableColumnDeletion = ({ tr, deletion, insertedColumnCount, revision,
267
271
  previousTable: table,
268
272
  emptied: emptiedRows
269
273
  });
270
- else removeRowsWithoutCells(tr, tablePosition);
274
+ else removeRowsWithoutCells(tr, tablePosition, table);
271
275
  return applied(tr, null);
272
276
  };
273
277
  const applyTableRowDeletion = ({ tr, deletion, revision }) => {
@@ -391,11 +395,11 @@ const populateTableRow = (row, cellTexts) => {
391
395
  });
392
396
  return row.type.create(row.attrs, cells);
393
397
  };
394
- const getInsertedPhysicalColumnRows = (map, columnIndex) => {
398
+ const getInsertedPhysicalColumnRows = (map, table, columnIndex) => {
395
399
  const rows = [];
396
400
  for (let row = 0; row < map.height; row++) {
397
401
  const index = row * map.width + columnIndex;
398
- if (!(columnIndex > 0 && columnIndex < map.width && map.map[index - 1] === map.map[index])) rows.push(row);
402
+ if (!(columnIndex > 0 && columnIndex < map.width && map.map[index - 1] === map.map[index]) && omittedSlotTakingColumn(map, table, row, columnIndex) === null) rows.push(row);
399
403
  }
400
404
  return rows;
401
405
  };
@@ -423,7 +427,7 @@ const populateTableCell = (cell, text) => {
423
427
  };
424
428
  const buildTableColumnInsertionActions = ({ map, table, columnIndex, cellTexts }) => {
425
429
  if (columnIndex < 0 || columnIndex > map.width) return null;
426
- const physicalRows = getInsertedPhysicalColumnRows(map, columnIndex);
430
+ const physicalRows = getInsertedPhysicalColumnRows(map, table, columnIndex);
427
431
  if ((cellTexts?.length ?? 0) > physicalRows.length) return null;
428
432
  let referenceColumn = columnIndex > 0 ? -1 : 0;
429
433
  if (columnIsHeader(map, table, columnIndex + referenceColumn)) referenceColumn = columnIndex === 0 || columnIndex === map.width ? null : 0;
@@ -431,6 +435,15 @@ const buildTableColumnInsertionActions = ({ map, table, columnIndex, cellTexts }
431
435
  let physicalCellIndex = 0;
432
436
  for (let row = 0; row < map.height; row++) {
433
437
  const index = row * map.width + columnIndex;
438
+ const omitted = omittedSlotTakingColumn(map, table, row, columnIndex);
439
+ if (omitted !== null) {
440
+ actions.push({
441
+ type: "growOmittedSlot",
442
+ position: omitted,
443
+ colspan: (Number(table.nodeAt(omitted)?.attrs["colspan"]) || 1) + 1
444
+ });
445
+ continue;
446
+ }
434
447
  if (columnIndex > 0 && columnIndex < map.width && map.map[index - 1] === map.map[index]) {
435
448
  const position = map.map[index];
436
449
  if (position === void 0) return null;
@@ -468,6 +481,7 @@ const getTableColumnDeletionCellPositions = ({ map, table, columnIndex }) => {
468
481
  const position = map.map[row * map.width + columnIndex];
469
482
  if (position === void 0) return null;
470
483
  const cell = table.nodeAt(position);
484
+ if (cell?.attrs["_omittedGridSlot"]) continue;
471
485
  const tableRole = cell?.type.spec["tableRole"];
472
486
  if (!cell || tableRole !== "cell" && tableRole !== "header_cell" || cell.attrs["colspan"] !== 1 || cell.attrs["cellMarker"] != null) return null;
473
487
  positions.add(position);
@@ -654,7 +654,7 @@ export type FolioAIEditSkipReason = "missingBlock" | "changedBlock" | "ambiguous
654
654
  * next to it.
655
655
  */
656
656
  "pendingDeletion" |
657
- /** Resolve the removed paragraph mark before editing its properties separately. */
657
+ /** Resolve the removed paragraph mark before editing its properties separately, or before inserting a paragraph between it and a table. */
658
658
  "pendingParagraphMarkDeletion";
659
659
  export type FolioAIEditAppliedOperation = {
660
660
  id: string;
@@ -54,7 +54,7 @@ export declare const createCanonicalComposition: (options: CompositionOptions) =
54
54
  forgetCompleted: () => void;
55
55
  readonly pendingFinal: boolean;
56
56
  authorizeLateFinal: (view: EditorView, text: string | null) => boolean;
57
- authorizeNative: (view: EditorView, completion: CompositionCompletionEvidence) => void;
57
+ authorizeNative: (view: EditorView, completion: CompositionCompletionEvidence, finalText?: string | null) => void;
58
58
  flushed: (view: EditorView) => void;
59
59
  recover: (view: EditorView) => CompositionFinish;
60
60
  cancel: (view: EditorView) => CompositionFinish;