@stll/folio-core 0.68.0 → 0.69.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 (177) hide show
  1. package/dist/ai-edits/headless.js +2 -2
  2. package/dist/ai-edits/newListNumbering.d.ts +14 -1
  3. package/dist/ai-edits/newListNumbering.js +24 -1
  4. package/dist/ai-edits/pending-suggestions.js +2 -2
  5. package/dist/controller/canonicalClipboard.js +2 -2
  6. package/dist/controller/canonicalComposition.js +34 -5
  7. package/dist/controller/canonicalInput.js +4 -6
  8. package/dist/controller/canonicalLockGuard.d.ts +17 -2
  9. package/dist/controller/canonicalLockGuard.js +46 -1
  10. package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
  11. package/dist/controller/canonicalProjectionBlocks.js +75 -0
  12. package/dist/controller/canonicalPublicOperations.js +476 -100
  13. package/dist/controller/canonicalSeedContent.d.ts +12 -0
  14. package/dist/controller/canonicalSeedContent.js +131 -0
  15. package/dist/controller/canonicalSession.d.ts +53 -21
  16. package/dist/controller/canonicalSession.js +489 -210
  17. package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
  18. package/dist/controller/canonicalSourceNormalization.js +148 -0
  19. package/dist/controller/canonicalStoryEditor.d.ts +1 -1
  20. package/dist/controller/canonicalStoryEditor.js +16 -12
  21. package/dist/controller/folioEditor.js +3 -0
  22. package/dist/controller/headerFooterEditorManager.d.ts +5 -0
  23. package/dist/controller/headerFooterEditorManager.js +7 -2
  24. package/dist/controller/hiddenEditorApi.d.ts +11 -2
  25. package/dist/controller/hiddenEditorApi.js +3 -0
  26. package/dist/controller/hiddenEditorManager.d.ts +7 -0
  27. package/dist/controller/hiddenEditorManager.js +66 -11
  28. package/dist/controller/layoutPipeline.js +2 -1
  29. package/dist/controller/layoutSession.d.ts +3 -0
  30. package/dist/controller/layoutSession.js +3 -1
  31. package/dist/controller/noteEditorManager.d.ts +5 -0
  32. package/dist/controller/noteEditorManager.js +7 -2
  33. package/dist/display-list/dom/renderDisplayListToDom.js +9 -7
  34. package/dist/document-operations.d.ts +1 -1
  35. package/dist/docx/canonicalSave.js +7 -2
  36. package/dist/docx/commentAnchorIndex.d.ts +19 -0
  37. package/dist/docx/commentAnchorIndex.js +55 -1
  38. package/dist/docx/containerChildren.js +1 -1
  39. package/dist/docx/contentTypeRegistry.js +1 -1
  40. package/dist/docx/hostCommentThreads.d.ts +11 -1
  41. package/dist/docx/hostCommentThreads.js +25 -2
  42. package/dist/docx/listModelNormalization.js +4 -5
  43. package/dist/docx/listNumberingInstances.d.ts +1 -1
  44. package/dist/docx/listNumberingInstances.js +2 -2
  45. package/dist/docx/numberingIds.d.ts +6 -0
  46. package/dist/docx/numberingIds.js +6 -1
  47. package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
  48. package/dist/docx/numberingReferenceNormalization.js +12 -2
  49. package/dist/docx/paragraphPropertySource.d.ts +22 -0
  50. package/dist/docx/paragraphPropertySource.js +85 -16
  51. package/dist/docx/parser.js +2 -0
  52. package/dist/docx/removeHeaderFooterParts.js +1 -1
  53. package/dist/docx/reviewResolutionProvenance.js +72 -19
  54. package/dist/docx/serializer/documentSerializer.js +2 -1
  55. package/dist/docx/serializer/partNamespaces.d.ts +1 -1
  56. package/dist/docx/serializer/partNamespaces.js +1 -1
  57. package/dist/docx/server/build.d.ts +1 -1
  58. package/dist/docx/storyBlockReplay.js +15 -2
  59. package/dist/docx/structuralXmlPatch.js +25 -4
  60. package/dist/docx/xmlParser.d.ts +1 -1
  61. package/dist/docx/xmlParser.js +2 -3
  62. package/dist/i18n/messages/ar.gen.js +1 -0
  63. package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
  64. package/dist/i18n/messages/catalogs.gen.js +17 -0
  65. package/dist/i18n/messages/cs.gen.js +1 -0
  66. package/dist/i18n/messages/de.gen.js +1 -0
  67. package/dist/i18n/messages/en.gen.js +1 -0
  68. package/dist/i18n/messages/es.gen.js +1 -0
  69. package/dist/i18n/messages/et.gen.js +1 -0
  70. package/dist/i18n/messages/fr.gen.js +1 -0
  71. package/dist/i18n/messages/he.gen.js +1 -0
  72. package/dist/i18n/messages/hi.gen.js +1 -0
  73. package/dist/i18n/messages/hu.gen.js +1 -0
  74. package/dist/i18n/messages/lt.gen.js +1 -0
  75. package/dist/i18n/messages/lv.gen.js +1 -0
  76. package/dist/i18n/messages/messages.gen.d.ts +1 -0
  77. package/dist/i18n/messages/pl.gen.js +1 -0
  78. package/dist/i18n/messages/pt-BR.gen.js +1 -0
  79. package/dist/i18n/messages/sk.gen.js +1 -0
  80. package/dist/i18n/messages/tr.gen.js +1 -0
  81. package/dist/i18n/messages/zh-CN.gen.js +1 -0
  82. package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
  83. package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
  84. package/dist/internal/subtreeHolds.d.ts +12 -0
  85. package/dist/internal/subtreeHolds.js +25 -0
  86. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  87. package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
  88. package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
  89. package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
  90. package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
  91. package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
  92. package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
  93. package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
  94. package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
  95. package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
  96. package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
  97. package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
  98. package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
  99. package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
  100. package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
  101. package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
  102. package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
  103. package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
  104. package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
  105. package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
  106. package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
  107. package/dist/layout-bridge/dom/textStreamDom.js +3 -2
  108. package/dist/layout-bridge/headerFooterLayout.js +12 -11
  109. package/dist/layout-bridge/tableInsertHover.js +2 -1
  110. package/dist/layout-engine/measure/cache.d.ts +2 -0
  111. package/dist/layout-engine/measure/cache.js +6 -1
  112. package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
  113. package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
  114. package/dist/layout-engine/types.d.ts +6 -0
  115. package/dist/layout-painter/imageLayout.js +2 -1
  116. package/dist/layout-painter/pageShellStyles.d.ts +10 -0
  117. package/dist/layout-painter/pageShellStyles.js +32 -0
  118. package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
  119. package/dist/layout-painter/reconcileRenderedContent.js +117 -0
  120. package/dist/layout-painter/renderFragment.js +4 -6
  121. package/dist/layout-painter/renderImage.js +2 -2
  122. package/dist/layout-painter/renderPage.js +8 -29
  123. package/dist/layout-painter/renderParagraph.js +3 -3
  124. package/dist/layout-painter/renderTable.js +9 -12
  125. package/dist/layout-painter/renderTextBox.js +2 -2
  126. package/dist/layout-painter/sdtBoundary.js +3 -2
  127. package/dist/paged-layout/blockGeometry.js +3 -2
  128. package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
  129. package/dist/paged-layout/editorScrollRoot.js +10 -1
  130. package/dist/paged-layout/rangeProjection.js +5 -4
  131. package/dist/paged-layout/scrollToPmPosition.js +3 -3
  132. package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
  133. package/dist/paged-layout/selectionViewportRect.js +8 -2
  134. package/dist/prosemirror/attrs/index.js +1 -0
  135. package/dist/prosemirror/commands/comments.d.ts +5 -2
  136. package/dist/prosemirror/commands/comments.js +88 -8
  137. package/dist/prosemirror/commentRecords.d.ts +137 -0
  138. package/dist/prosemirror/commentRecords.js +400 -0
  139. package/dist/prosemirror/conversion/fromProseDoc.js +9 -3
  140. package/dist/prosemirror/conversion/index.d.ts +1 -1
  141. package/dist/prosemirror/conversion/toProseDoc.d.ts +13 -4
  142. package/dist/prosemirror/conversion/toProseDoc.js +126 -38
  143. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +22 -0
  144. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
  145. package/dist/prosemirror/extensions/marks/CommentExtension.js +3 -1
  146. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
  147. package/dist/prosemirror/index.d.ts +1 -1
  148. package/dist/prosemirror/nativeSelection.d.ts +33 -0
  149. package/dist/prosemirror/nativeSelection.js +74 -0
  150. package/dist/prosemirror/numberedRefFields.d.ts +2 -0
  151. package/dist/prosemirror/numberedRefFields.js +16 -5
  152. package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
  153. package/dist/prosemirror/paragraphMarkJoin.js +155 -16
  154. package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
  155. package/dist/prosemirror/plugins/documentNumbering.js +33 -14
  156. package/dist/prosemirror/plugins/suggestionMode.js +13 -1
  157. package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
  158. package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
  159. package/dist/prosemirror/schema/marks.d.ts +7 -1
  160. package/dist/prosemirror/storyListNumbering.js +7 -2
  161. package/dist/prosemirror/tableResize.d.ts +10 -9
  162. package/dist/prosemirror/tableResize.js +60 -49
  163. package/dist/prosemirror/textInput.d.ts +30 -1
  164. package/dist/prosemirror/textInput.js +144 -17
  165. package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
  166. package/dist/prosemirror/validation.d.ts +19 -0
  167. package/dist/prosemirror/validation.js +78 -5
  168. package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
  169. package/dist/render-dom/RenderedDomContext.js +7 -6
  170. package/dist/types/canonicalCapabilities.d.ts +12 -11
  171. package/dist/types/canonicalCapabilities.js +12 -13
  172. package/dist/utils/findMatchView.js +4 -3
  173. package/dist/utils/formatToStyle.d.ts +1 -1
  174. package/dist/utils/mergeDocumentContent.js +2 -2
  175. package/dist/utils/paintedPositions.d.ts +60 -0
  176. package/dist/utils/paintedPositions.js +101 -0
  177. package/package.json +2 -3
@@ -1,4 +1,4 @@
1
- import { getProseParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, markParagraphPropertySourceTransfers } from "../docx/paragraphPropertySource.js";
1
+ import { PARAGRAPH_SOURCE_JOIN_RULES, getProseParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, markParagraphPropertySourceTransfers } from "../docx/paragraphPropertySource.js";
2
2
  import { paragraphJoinAfter } from "./commands/paragraphBookmarkJoin.js";
3
3
  import { JOINED_RUNS_RESTYLED_META } from "./extensions/features/JoinedRunStyleExtension.js";
4
4
  import { rebaseParagraphRuns } from "./rebaseParagraphRunFormatting.js";
@@ -20,21 +20,160 @@ import { panic } from "better-result";
20
20
  * The first paragraph's runs keep their direct formatting; what its style
21
21
  * lent them is re-read in the next paragraph's style.
22
22
  */
23
+ const nextValue = (key) => (sides) => sides.next.attrs[key];
24
+ /** The paragraph-level records each side holds, in document order. */
25
+ const bothSides = (key, shift) => ({ paragraph, next, between }) => {
26
+ const left = paragraph.attrs[key];
27
+ const right = next.attrs[key];
28
+ const items = [...Array.isArray(left) ? left : [], ...Array.isArray(right) ? right.map((item) => shift(item, paragraph.content.size + between)) : []];
29
+ return items.length === 0 ? right : items;
30
+ };
31
+ /** The suggestion a paragraph's whole-paragraph insert marker names, if any. */
32
+ const suggestedInsertOf = (node) => {
33
+ const marker = node.attrs["_suggestedInsert"];
34
+ return typeof marker === "object" && marker !== null && typeof marker.suggestionId === "string" && typeof marker.revisionId === "number" ? marker : null;
35
+ };
23
36
  /**
24
- * The attrs the paragraph a join leaves takes: `next`'s, less the editing
25
- * sessions (`w:rsid*` attributes) it shares with the removed `paragraph`.
26
- *
27
- * A split copies the paragraph's attrs onto both halves, and a save writes
28
- * the sessions on the first half only, the first record in document order.
29
- * Rejecting the split removes that first half, so the paragraph left names
30
- * none of them, live as after a save.
37
+ * Whether the joined paragraph is still all one suggestion's insertion: only
38
+ * when both paragraphs were. A paragraph that held other words is not, so it
39
+ * keeps no whole-paragraph marker; the mark it ends with records the next
40
+ * paragraph's suggested insertion instead (`pPrMark`).
41
+ */
42
+ const stillWhollySuggested = ({ paragraph, next }) => {
43
+ const left = suggestedInsertOf(paragraph);
44
+ const right = suggestedInsertOf(next);
45
+ return left !== null && right !== null && left.suggestionId === right.suggestionId;
46
+ };
47
+ /**
48
+ * Every attribute of the joined paragraph, decided one by one. The mark that
49
+ * stays is the next paragraph's, so most come from it; what the paragraph
50
+ * holds as content (boundary bookmarks, empty hyperlinks) comes from both,
51
+ * and a suggestion's whole-paragraph marker survives only where the whole
52
+ * joined paragraph is still that suggestion's.
53
+ */
54
+ const JOINED_PARAGRAPH_ATTRS = {
55
+ paraId: "next",
56
+ textId: "next",
57
+ idStability: "next",
58
+ ...PARAGRAPH_SOURCE_JOIN_RULES,
59
+ reviewCarrier: "next",
60
+ alignment: "next",
61
+ alignmentFromStyle: "next",
62
+ kinsoku: "next",
63
+ autoSpaceDE: "next",
64
+ autoSpaceDN: "next",
65
+ overflowPunctuation: "next",
66
+ suppressAutoHyphens: "next",
67
+ spaceBefore: "next",
68
+ spaceAfter: "next",
69
+ lineSpacing: "next",
70
+ lineSpacingRule: "next",
71
+ lineSpacingExplicit: "next",
72
+ snapToGrid: "next",
73
+ spacingExplicit: "next",
74
+ spacingFromDocDefaults: "next",
75
+ spacingFromImplicitDefaultStyle: "next",
76
+ indentLeft: "next",
77
+ indentRight: "next",
78
+ indentFirstLine: "next",
79
+ hangingIndent: "next",
80
+ numPr: "next",
81
+ _pastedHtmlList: "next",
82
+ numPrFromStyle: "next",
83
+ listNumFmt: "next",
84
+ listIsBullet: "next",
85
+ listIsLegal: "next",
86
+ listMarker: "next",
87
+ listMarkerTemplate: "next",
88
+ listMarkerHidden: "next",
89
+ listMarkerFormatting: "next",
90
+ listMarkerAlignment: "next",
91
+ listMarkerSuffix: "next",
92
+ listMarkerAllCaps: "next",
93
+ listImplicitChildLevelAdvances: "next",
94
+ listFoldedMarkerSuffix: "next",
95
+ listMarkerSecondSlotOffsetTwips: "next",
96
+ listLevelNumFmts: "next",
97
+ listLevelStarts: "next",
98
+ listLevelTabs: "next",
99
+ listAbstractNumId: "next",
100
+ listStartOverride: "next",
101
+ styleId: "next",
102
+ _tableOfContentsLevel: "next",
103
+ borders: "next",
104
+ shading: "next",
105
+ tabs: "next",
106
+ pageBreakBefore: "next",
107
+ renderedPageBreakBefore: "next",
108
+ keepNext: "next",
109
+ keepLines: "next",
110
+ widowControl: "next",
111
+ contextualSpacing: "next",
112
+ runInWithNext: "next",
113
+ defaultTextFormatting: "next",
114
+ _tableRunFormatting: "next",
115
+ direction: "next",
116
+ outlineLevel: "next",
117
+ _originalFormatting: "next",
118
+ _resolvedFormatting: "next",
119
+ _styleResolvedFormatting: "next",
120
+ _autospacingBase: "next",
121
+ _detachedWatermarkHost: "next",
122
+ _sectionProperties: "next",
123
+ _propertyChanges: "next",
124
+ _trailingPageBreak: "next",
125
+ _pageBreakCarrier: (sides) => sides.paragraph.content.size === 0 ? sides.next.attrs["_pageBreakCarrier"] : null,
126
+ bookmarks: bothSides("bookmarks", (item) => item),
127
+ _emptyHyperlinks: bothSides("_emptyHyperlinks", (item, by) => typeof item === "object" && item !== null && "offset" in item ? {
128
+ ...item,
129
+ offset: Number(item.offset) + by
130
+ } : item),
131
+ _preservedAttributes: ({ paragraph, next }) => {
132
+ const sessions = next.attrs["_preservedAttributes"];
133
+ return typeof sessions === "object" && sessions !== null && sessions === paragraph.attrs["_preservedAttributes"] ? null : sessions;
134
+ },
135
+ pPrMark: (sides) => {
136
+ const own = sides.next.attrs["pPrMark"];
137
+ if (own != null || stillWhollySuggested(sides)) return own;
138
+ const suggested = suggestedInsertOf(sides.next);
139
+ return suggested === null ? own : {
140
+ kind: "ins",
141
+ info: {
142
+ id: suggested.revisionId,
143
+ author: suggested.author,
144
+ ...suggested.date == null ? {} : { date: suggested.date },
145
+ ...typeof suggested.initials === "string" ? { initials: suggested.initials } : {},
146
+ provenance: "suggested",
147
+ suggestionId: suggested.suggestionId
148
+ }
149
+ };
150
+ },
151
+ _suggestedInsert: (sides) => stillWhollySuggested(sides) ? sides.next.attrs["_suggestedInsert"] : null
152
+ };
153
+ /** The attributes a join decides, for a check that the schema adds none undecided. */
154
+ const JOINED_PARAGRAPH_ATTR_NAMES = Object.keys(JOINED_PARAGRAPH_ATTRS);
155
+ /**
156
+ * The attrs of the paragraph a join leaves, each by its rule in
157
+ * `JOINED_PARAGRAPH_ATTRS`. `between` is the inline size the join places
158
+ * between the two paragraphs' content.
31
159
  */
32
- const joinedParagraphAttrs = (paragraph, next) => {
33
- const sessions = next.attrs["_preservedAttributes"];
34
- return typeof sessions === "object" && sessions !== null && sessions === paragraph.attrs["_preservedAttributes"] ? {
35
- ...next.attrs,
36
- _preservedAttributes: null
37
- } : next.attrs;
160
+ const joinedParagraphAttrs = (paragraph, next, between = 0) => {
161
+ const sides = {
162
+ paragraph,
163
+ next,
164
+ between
165
+ };
166
+ const rules = JOINED_PARAGRAPH_ATTRS;
167
+ const attrs = {};
168
+ let changed = false;
169
+ for (const key of Object.keys(next.attrs)) {
170
+ const rule = rules[key];
171
+ if (rule === void 0) panic(`A paragraph attribute has no join rule: ${key}`);
172
+ const value = (rule === "next" ? nextValue(key) : rule)(sides);
173
+ attrs[key] = value;
174
+ if (value !== next.attrs[key]) changed = true;
175
+ }
176
+ return changed ? attrs : next.attrs;
38
177
  };
39
178
  const joinAtParagraphMark = ({ tr, paragraphPos, paragraph, next, styleResolver }) => {
40
179
  const boundary = paragraphPos + paragraph.nodeSize;
@@ -44,7 +183,7 @@ const joinAtParagraphMark = ({ tr, paragraphPos, paragraph, next, styleResolver
44
183
  const leftToken = getProseParagraphPropertySourceToken(paragraph);
45
184
  const rightToken = getProseParagraphPropertySourceToken(next);
46
185
  tr.replaceWith(boundary - 1, join.nextPosition + 1, join.inlineBookmarks);
47
- tr.setNodeMarkup(paragraphPos, void 0, joinedParagraphAttrs(paragraph, next));
186
+ tr.setNodeMarkup(paragraphPos, void 0, joinedParagraphAttrs(paragraph, next, join.inlineBookmarks.reduce((size, node) => size + node.nodeSize, 0)));
48
187
  markParagraphPropertySourceTransfers(tr, [{
49
188
  displacedToken: typeof leftToken === "string" ? leftToken : null,
50
189
  selectedToken: typeof rightToken === "string" ? rightToken : null
@@ -67,4 +206,4 @@ const joinAtParagraphMark = ({ tr, paragraphPos, paragraph, next, styleResolver
67
206
  });
68
207
  tr.setMeta(JOINED_RUNS_RESTYLED_META, true);
69
208
  };
70
- export { joinAtParagraphMark, joinedParagraphAttrs };
209
+ export { JOINED_PARAGRAPH_ATTR_NAMES, joinAtParagraphMark, joinedParagraphAttrs };
@@ -1,4 +1,5 @@
1
1
  import { ContentControlBoundError, ContentControlLockedError, ContentControlTypeError } from "../../content-controls/errors.js";
2
+ import { readPaintedContentControlKey } from "../../utils/paintedPositions.js";
2
3
  import { findBlockSdtMatch, setContentControlValueTr } from "../commands/contentControls.js";
3
4
  import { createPluginKeyOwner } from "../pluginKeyOwner.js";
4
5
  import { selectLockedInlineControl } from "./lockedControlKeyHandling.js";
@@ -32,7 +33,6 @@ const CONTENT_CONTROL_WIDGET_EVENT_NAME = "folio:content-control-widget";
32
33
  const SDT_DATASET_KEY = {
33
34
  checked: "sdtChecked",
34
35
  listItems: "sdtListItems",
35
- pmPos: "sdtPmPos",
36
36
  tag: "sdtTag",
37
37
  type: "sdtType"
38
38
  };
@@ -65,7 +65,7 @@ const handleContentControlWidgetClick = ({ event, onEvent, view }) => {
65
65
  if (!anchor) return false;
66
66
  const tag = anchor.dataset[SDT_DATASET_KEY.tag] ?? "";
67
67
  const sdtType = anchor.dataset[SDT_DATASET_KEY.type];
68
- const pmPosRaw = anchor.dataset[SDT_DATASET_KEY.pmPos];
68
+ const pmPosRaw = readPaintedContentControlKey(anchor);
69
69
  const pmPos = pmPosRaw ? Number.parseInt(pmPosRaw, 10) : NaN;
70
70
  if (!sdtType || Number.isNaN(pmPos)) return false;
71
71
  try {
@@ -16,43 +16,62 @@ const completedState = (definitions, doc) => {
16
16
  };
17
17
  const isReplace = (step) => step instanceof ReplaceStep || step instanceof ReplaceAroundStep;
18
18
  const leavesNumberingUnchanged = (step) => step instanceof AddMarkStep || step instanceof RemoveMarkStep || step instanceof DocAttrStep;
19
- const containsNumberedParagraph = (node, from, to) => {
19
+ /** The instances a package's numbering part defines, by its definitions object. */
20
+ const definedInstances = /* @__PURE__ */ new WeakMap();
21
+ const instancesDefinedBy = (definitions) => {
22
+ if (definitions === null) return /* @__PURE__ */ new Set();
23
+ let defined = definedInstances.get(definitions);
24
+ if (defined === void 0) {
25
+ defined = new Set((definitions.nums ?? []).map(({ numId }) => numId));
26
+ definedInstances.set(definitions, defined);
27
+ }
28
+ return defined;
29
+ };
30
+ /**
31
+ * Whether a paragraph names an instance the package does not define: only
32
+ * those reach the completed numbering, which adds an instance for each.
33
+ */
34
+ const namesUndefinedInstance = (node, defined) => paragraphListReferences(node).some((numId) => !defined.has(numId));
35
+ const containsUndefinedReference = (node, from, to, defined) => {
20
36
  let found = false;
21
37
  node.nodesBetween(from, to, (child, pos) => {
22
- if (child.type.name !== "paragraph" || pos < from || pos + child.nodeSize > to || paragraphListReferences(child).length === 0) return !found;
38
+ if (child.type.name !== "paragraph" || pos < from || pos + child.nodeSize > to || !namesUndefinedInstance(child, defined)) return !found;
23
39
  found = true;
24
40
  return false;
25
41
  });
26
42
  return found;
27
43
  };
28
44
  /**
29
- * Whether a transaction can change a paragraph-level numbering source. Text
30
- * and mark edits do not; paragraph attrs and structural replacements do. The
31
- * latter are inspected in the step-local document rather than by walking the
32
- * completed document.
45
+ * Whether a transaction can change the completed numbering: the instances the
46
+ * document names that the package does not define. Text and mark edits do
47
+ * not; paragraph attrs can. A structural replacement can only when a
48
+ * paragraph it inserts, removes or joins names such an instance, so typing in
49
+ * a list whose instances the package defines leaves the numbering as it is.
50
+ * Replacements are inspected in the step-local document rather than by
51
+ * walking the completed document.
33
52
  */
34
- const changesNumberingInputs = (tr) => tr.steps.some((step, index) => {
53
+ const changesNumberingInputs = (tr, defined) => tr.steps.some((step, index) => {
35
54
  if (leavesNumberingUnchanged(step)) return false;
36
55
  if (!isReplace(step)) return true;
37
- let insertsNumberedParagraph = false;
56
+ let insertsUndefinedReference = false;
38
57
  step.slice.content.descendants((node) => {
39
- if (paragraphListReferences(node).length === 0) return !insertsNumberedParagraph;
40
- insertsNumberedParagraph = true;
58
+ if (!namesUndefinedInstance(node, defined)) return !insertsUndefinedReference;
59
+ insertsUndefinedReference = true;
41
60
  return false;
42
61
  });
43
- if (insertsNumberedParagraph) return true;
62
+ if (insertsUndefinedReference) return true;
44
63
  const before = tr.docs[index];
45
64
  if (before === void 0) return true;
46
65
  const fromParent = before.resolve(step.from).parent;
47
66
  const toParent = before.resolve(step.to).parent;
48
- if (fromParent !== toParent && (paragraphListReferences(fromParent).length > 0 || paragraphListReferences(toParent).length > 0)) return true;
49
- return containsNumberedParagraph(before, step.from, step.to);
67
+ if (fromParent !== toParent && (namesUndefinedInstance(fromParent, defined) || namesUndefinedInstance(toParent, defined))) return true;
68
+ return containsUndefinedReference(before, step.from, step.to, defined);
50
69
  });
51
70
  const createDocumentNumberingPlugin = (definitions) => new Plugin({
52
71
  key: documentNumberingKey.createKey(),
53
72
  state: {
54
73
  init: (_config, state) => completedState(definitions ?? null, state.doc),
55
- apply: (tr, current, _oldState, state) => tr.docChanged && changesNumberingInputs(tr) ? completedState(current.definitions, state.doc) : current
74
+ apply: (tr, current, _oldState, state) => tr.docChanged && changesNumberingInputs(tr, instancesDefinedBy(current.definitions)) ? completedState(current.definitions, state.doc) : current
56
75
  }
57
76
  });
58
77
  /** Numbering for states without the plugin, one per document node. */
@@ -14,7 +14,7 @@ import { rebaseParagraphRuns } from "../rebaseParagraphRunFormatting.js";
14
14
  import { RUN_FORMATTING_MARK_NAMES } from "../runFormattingMarkNames.js";
15
15
  import { paragraphRunStyleContext } from "../runStyleFormatting.js";
16
16
  import { cellPasteRange, pasteTableCells } from "../tableCellPaste.js";
17
- import { afterNativeCompositionFlush, formattingMarksBesideLockedControl, handleEditorBeforeInput } from "../textInput.js";
17
+ import { afterNativeCompositionFlush, formattingMarksBesideLockedControl, handleEditorBeforeInput, keepTypedTextInComments } from "../textInput.js";
18
18
  import { canCarryTrackedRunMark } from "../trackedRunInlineAtoms.js";
19
19
  import { getDocumentNumbering } from "./documentNumbering.js";
20
20
  import { documentStylesKey, getDocumentStyleResolver } from "./documentStyleState.js";
@@ -612,6 +612,18 @@ function applySuggestionInsert(view, from, to, text, pluginState) {
612
612
  }
613
613
  separateSplitStretch(tr, typedFrom, typedTo, insertAttrs.revisionId);
614
614
  if (typesOverSelection) tr.setSelection(TextSelection.create(tr.doc, typedTo));
615
+ keepTypedTextInComments({
616
+ state: view.state,
617
+ tr,
618
+ replaced: {
619
+ from,
620
+ to
621
+ },
622
+ typed: {
623
+ from: typedFrom,
624
+ to: typedTo
625
+ }
626
+ });
615
627
  view.dispatch(tr.scrollIntoView());
616
628
  return true;
617
629
  }
@@ -14,4 +14,26 @@ export declare const continueSourceCarrierIdentitiesAcrossRevisions: (nodes: rea
14
14
  * A deleted paragraph mark joined two source paragraphs, whose carriers were
15
15
  * always separate, so it is not crossed.
16
16
  */
17
- export declare const continueSourceCarrierIdentitiesAcrossInsertedParagraphMarks: (blocks: readonly Node[]) => readonly Node[];
17
+ export declare const continueSourceCarrierIdentitiesAcrossInsertedParagraphMarks: (blocks: readonly Node[]) => readonly Node[];
18
+ /** One pass of the continuation over a story's top-level blocks. */
19
+ export type ContinuedBlocks = {
20
+ blocks: readonly Node[];
21
+ continued: readonly Node[];
22
+ };
23
+ /**
24
+ * Kept across passes over one story: the last pass and each container
25
+ * continued inside, so a container a pass left is not walked again.
26
+ */
27
+ export declare class CarrierContinuationCache {
28
+ last: ContinuedBlocks | undefined;
29
+ readonly containers: WeakMap<Node, Node>;
30
+ }
31
+ /**
32
+ * {@link continueSourceCarrierIdentitiesAcrossInsertedParagraphMarks} over a
33
+ * story's top-level blocks, keeping what the last pass gave the blocks it
34
+ * left. A block's continuation reads only the block and the one continued
35
+ * before it, so the run of blocks from the start that the last pass was given
36
+ * keeps its result, and a block of the run to the end keeps its result once
37
+ * the block before it continued to what it did then.
38
+ */
39
+ export declare const continueSourceCarrierIdentitiesKeeping: (blocks: readonly Node[], cache: CarrierContinuationCache) => readonly Node[];
@@ -1,6 +1,7 @@
1
1
  import { expectHyperlinkMarkAttrs, expectRunIdentityMarkAttrs } from "./attrs/index.js";
2
2
  import "./extensions/nodes/SdtExtension.js";
3
3
  import { RUN_IDENTITY_MARK_NAME } from "./runIdentity.js";
4
+ import { panic } from "better-result";
4
5
  import { Fragment, Mark } from "prosemirror-model";
5
6
  // src/prosemirror/runIdentityAcrossRevisions.ts
6
7
  /**
@@ -161,17 +162,65 @@ const continueSourceCarrierIdentitiesAcrossInsertedParagraphMarks = (blocks) =>
161
162
  let changed = false;
162
163
  const result = [];
163
164
  for (const block of blocks) {
164
- let next = block;
165
- if (!block.isTextblock && !block.isLeaf && !block.inlineContent) {
165
+ const next = continuedBlock(result.at(-1), block);
166
+ changed ||= next !== block;
167
+ result.push(next);
168
+ }
169
+ return changed ? result : blocks;
170
+ };
171
+ /** `block` as it stands after `previous`, the block before it as continued. */
172
+ const continuedBlock = (previous, block, containers) => {
173
+ let next = block;
174
+ if (!block.isTextblock && !block.isLeaf && !block.inlineContent) {
175
+ const known = containers?.get(block);
176
+ if (known === void 0) {
166
177
  const children = childrenOf(block);
167
178
  const continued = continueSourceCarrierIdentitiesAcrossInsertedParagraphMarks(children);
168
179
  if (continued !== children) next = block.copy(Fragment.fromArray([...continued]));
180
+ containers?.set(block, next);
181
+ } else next = known;
182
+ }
183
+ if (previous !== void 0 && next.type.name === "paragraph" && endsWithInsertedMark(previous)) next = continueAcrossInsertedMark(previous, next);
184
+ return next;
185
+ };
186
+ /**
187
+ * Kept across passes over one story: the last pass and each container
188
+ * continued inside, so a container a pass left is not walked again.
189
+ */
190
+ var CarrierContinuationCache = class {
191
+ last;
192
+ containers = /* @__PURE__ */ new WeakMap();
193
+ };
194
+ /**
195
+ * {@link continueSourceCarrierIdentitiesAcrossInsertedParagraphMarks} over a
196
+ * story's top-level blocks, keeping what the last pass gave the blocks it
197
+ * left. A block's continuation reads only the block and the one continued
198
+ * before it, so the run of blocks from the start that the last pass was given
199
+ * keeps its result, and a block of the run to the end keeps its result once
200
+ * the block before it continued to what it did then.
201
+ */
202
+ const continueSourceCarrierIdentitiesKeeping = (blocks, cache) => {
203
+ const last = cache.last;
204
+ const before = last?.blocks ?? [];
205
+ const kept = last?.continued ?? [];
206
+ let start = 0;
207
+ while (start < blocks.length && start < before.length && blocks[start] === before[start]) start += 1;
208
+ let after = 0;
209
+ while (after < blocks.length - start && after < before.length - start && blocks[blocks.length - 1 - after] === before[before.length - 1 - after]) after += 1;
210
+ const shift = before.length - blocks.length;
211
+ const continued = kept.slice(0, start);
212
+ for (let index = start; index < blocks.length; index += 1) {
213
+ const at = index + shift;
214
+ if (index >= blocks.length - after && continued[index - 1] === (at === 0 ? void 0 : kept[at - 1])) {
215
+ for (let rest = at; rest < kept.length; rest += 1) continued.push(kept[rest] ?? panic("Missing continued block"));
216
+ break;
169
217
  }
170
- const previous = result.at(-1);
171
- if (previous !== void 0 && next.type.name === "paragraph" && endsWithInsertedMark(previous)) next = continueAcrossInsertedMark(previous, next);
172
- changed ||= next !== block;
173
- result.push(next);
218
+ continued.push(continuedBlock(continued[index - 1], blocks[index] ?? panic("Missing block"), cache.containers));
174
219
  }
175
- return changed ? result : blocks;
220
+ cache.last = {
221
+ blocks,
222
+ continued
223
+ };
224
+ return continued;
176
225
  };
177
- export { SOURCE_CARRIER_MARK_NAMES, continueSourceCarrierIdentitiesAcrossInsertedParagraphMarks, continueSourceCarrierIdentitiesAcrossRevisions };
226
+ export { CarrierContinuationCache, SOURCE_CARRIER_MARK_NAMES, continueSourceCarrierIdentitiesAcrossInsertedParagraphMarks, continueSourceCarrierIdentitiesAcrossRevisions, continueSourceCarrierIdentitiesKeeping };
@@ -1,5 +1,5 @@
1
- import { ShadingProperties } from "../../types/colors.js";
2
1
  import { document_d_exports } from "../../types/document.js";
2
+ import { ShadingProperties } from "../../types/colors.js";
3
3
  import { TrackedCommentBoundary } from "../commentBoundaryOwnership.js";
4
4
  /**
5
5
  * Text color mark attributes
@@ -92,6 +92,12 @@ export type CommentAttrs = {
92
92
  * as long as its reference does, and saves as a point again.
93
93
  */
94
94
  point?: boolean;
95
+ /**
96
+ * The pending suggestion that proposed this comment. A proposed comment
97
+ * is never saved: it is accepted with its suggestion, which clears this,
98
+ * or removed when the suggestion is rejected.
99
+ */
100
+ suggestionId?: string;
95
101
  };
96
102
  /**
97
103
  * Provenance of a tracked change.
@@ -1,4 +1,4 @@
1
- import { createNumberingIdAllocator } from "../docx/numberingIds.js";
1
+ import { createNumberingIdAllocator, numberingNumIdsTaken } from "../docx/numberingIds.js";
2
2
  import { getCachedNumberingMap, isBulletLevel } from "../docx/numberingParser.js";
3
3
  import { paragraphNumberingReference } from "../docx/numberingReference.js";
4
4
  import { expectParagraphAttrs } from "./attrs/index.js";
@@ -57,7 +57,12 @@ const storyListNumbering = (state, numbering) => {
57
57
  doc: state.doc,
58
58
  numbering: completeNumberingForDoc(numbering, state.doc)
59
59
  };
60
- const existingNumIds = [...defined, ...referenced];
60
+ const existingNumIds = [
61
+ ...defined,
62
+ ...referenced,
63
+ ...numberingNumIdsTaken(numbering),
64
+ ...numberingNumIdsTaken(packageDefinitions)
65
+ ];
61
66
  const numIds = createNumberingIdAllocator("num", existingNumIds);
62
67
  const remap = {
63
68
  numIds: new Map([...colliding].map((numId) => [numId, numIds.next()])),
@@ -1,3 +1,4 @@
1
+ import { Command } from "prosemirror-state";
1
2
  import { EditorView } from "prosemirror-view";
2
3
  /** 1px ≈ 15 twips at 96dpi (20 twips/pt × 72pt/in ÷ 96px/in). */
3
4
  export declare const TWIPS_PER_PIXEL = 15;
@@ -24,23 +25,23 @@ export declare function readColumnWidths(view: EditorView, pmStart: number, colI
24
25
  export declare function readRowHeight(view: EditorView, pmStart: number, rowIndex: number): number | null;
25
26
  /** Read the last-column width (the one being resized from the table's right edge). */
26
27
  export declare function readColumnWidthAt(view: EditorView, pmStart: number, colIndex: number): number | null;
27
- /** Commit a column-pair resize, preserving each spanning cell's full grid width. */
28
- export declare function commitColumnResize(view: EditorView, opts: {
28
+ /** A column-pair resize, preserving each spanning cell's full grid width. */
29
+ export declare const columnResizeCommand: (opts: {
29
30
  pmStart: number;
30
31
  colIdx: number;
31
32
  newLeft: number;
32
33
  newRight: number;
33
- }): void;
34
- /** Bake a row-resize into the PM doc: update the target row's `height` + `heightRule`. */
35
- export declare function commitRowResize(view: EditorView, opts: {
34
+ }) => Command;
35
+ /** A row resize: the row's `height`, at least that tall. */
36
+ export declare const rowResizeCommand: (opts: {
36
37
  pmStart: number;
37
38
  rowIdx: number;
38
39
  newHeight: number;
39
- }): void;
40
- /** Commit a right-edge resize, including cells that span the resized column. */
41
- export declare function commitRightEdgeResize(view: EditorView, opts: {
40
+ }) => Command;
41
+ /** A right-edge resize, including cells that span the resized column. */
42
+ export declare const rightEdgeResizeCommand: (opts: {
42
43
  pmStart: number;
43
44
  colIdx: number;
44
45
  newWidth: number;
45
- }): void;
46
+ }) => Command;
46
47
  export {};