@stll/folio-core 0.74.0 → 0.76.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 (174) hide show
  1. package/dist/ai-edits/clean-text.d.ts +4 -1
  2. package/dist/ai-edits/clean-text.js +21 -7
  3. package/dist/ai-edits/headless.d.ts +7 -3
  4. package/dist/ai-edits/headless.js +36 -21
  5. package/dist/ai-edits/note-references.d.ts +1 -1
  6. package/dist/ai-edits/note-references.js +1 -1
  7. package/dist/ai-edits/pending-suggestions.d.ts +9 -7
  8. package/dist/ai-edits/pending-suggestions.js +135 -90
  9. package/dist/ai-edits/pendingJoin.d.ts +5 -1
  10. package/dist/ai-edits/pendingJoin.js +6 -2
  11. package/dist/ai-edits/read.js +9 -3
  12. package/dist/ai-edits/retired-comment-receipts.d.ts +2 -2
  13. package/dist/ai-edits/retired-comment-receipts.js +3 -18
  14. package/dist/ai-edits/tracked-batch-fidelity.d.ts +6 -10
  15. package/dist/ai-edits/tracked-batch-fidelity.js +3 -182
  16. package/dist/ai-edits/types.d.ts +9 -4
  17. package/dist/canonical/batchCommentReferences.js +2 -1
  18. package/dist/canonical/canonicalBatchReview.d.ts +4 -1
  19. package/dist/canonical/canonicalBatchReview.js +37 -22
  20. package/dist/canonical/canonicalComments.d.ts +6 -2
  21. package/dist/canonical/canonicalComments.js +16 -6
  22. package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
  23. package/dist/canonical/canonicalCompilerRefusal.js +20 -14
  24. package/dist/canonical/canonicalPublicOperations.js +231 -79
  25. package/dist/canonical/canonicalRefusalGrounds.d.ts +4 -0
  26. package/dist/canonical/canonicalRefusalGrounds.js +56 -0
  27. package/dist/canonical/canonicalSession.d.ts +12 -6
  28. package/dist/canonical/canonicalSession.js +119 -122
  29. package/dist/canonical/canonicalTrackedBatchFidelity.js +3 -3
  30. package/dist/compare/inline-atoms.d.ts +35 -41
  31. package/dist/compare/inline-atoms.js +2 -465
  32. package/dist/compare/section-boundary-properties.d.ts +3 -30
  33. package/dist/compare/section-boundary-properties.js +4 -72
  34. package/dist/controller/canonicalClipboard.d.ts +1 -1
  35. package/dist/controller/canonicalClipboard.js +110 -55
  36. package/dist/controller/canonicalComposition.d.ts +1 -1
  37. package/dist/controller/canonicalComposition.js +5 -5
  38. package/dist/controller/canonicalContentControlValue.js +7 -7
  39. package/dist/controller/canonicalInput.d.ts +4 -2
  40. package/dist/controller/canonicalInput.js +33 -16
  41. package/dist/controller/canonicalReview.d.ts +21 -0
  42. package/dist/controller/canonicalReview.js +44 -9
  43. package/dist/controller/canonicalStoryEditor.d.ts +2 -3
  44. package/dist/controller/canonicalStoryEditor.js +43 -25
  45. package/dist/controller/canonicalStructure.d.ts +19 -3
  46. package/dist/controller/canonicalStructure.js +182 -58
  47. package/dist/controller/deferredDisplayListPainter.d.ts +8 -0
  48. package/dist/controller/deferredDisplayListPainter.js +34 -0
  49. package/dist/controller/folioEditor.js +4 -2
  50. package/dist/controller/fontReadiness.js +50 -23
  51. package/dist/controller/headerFooterEditorManager.js +3 -17
  52. package/dist/controller/hiddenEditorApi.d.ts +24 -3
  53. package/dist/controller/hiddenEditorApi.js +2 -0
  54. package/dist/controller/hiddenEditorManager.js +135 -207
  55. package/dist/controller/layoutPipeline.d.ts +4 -86
  56. package/dist/controller/layoutPipeline.js +8 -727
  57. package/dist/controller/layoutPipelineExecution.d.ts +94 -0
  58. package/dist/controller/layoutPipelineExecution.js +730 -0
  59. package/dist/controller/noteEditorManager.js +3 -16
  60. package/dist/docx/blockContentParser.d.ts +1 -3
  61. package/dist/docx/blockContentParser.js +3 -10
  62. package/dist/docx/bulletMarkers.d.ts +8 -0
  63. package/dist/docx/bulletMarkers.js +9 -1
  64. package/dist/docx/canonicalSave.d.ts +4 -3
  65. package/dist/docx/canonicalSave.js +4 -3
  66. package/dist/docx/canonicalSessionInput.js +25 -11
  67. package/dist/docx/ensureParaIds.d.ts +31 -0
  68. package/dist/docx/ensureParaIds.js +57 -32
  69. package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
  70. package/dist/docx/ensureUniqueControlIds.js +47 -29
  71. package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
  72. package/dist/docx/ensureUniqueRevisionIds.js +52 -29
  73. package/dist/docx/listMarkerComputation.d.ts +24 -17
  74. package/dist/docx/listMarkerComputation.js +31 -60
  75. package/dist/docx/listModelNormalization.js +8 -15
  76. package/dist/docx/rezip.d.ts +16 -3
  77. package/dist/docx/rezip.js +35 -9
  78. package/dist/docx/selectiveSave.js +13 -5
  79. package/dist/docx/server/templatePlan/apply.js +96 -7
  80. package/dist/docx/server/templatePlan/blocks.d.ts +70 -3
  81. package/dist/docx/server/templatePlan/blocks.js +272 -10
  82. package/dist/docx/server/templatePlan/builders.d.ts +52 -2
  83. package/dist/docx/server/templatePlan/builders.js +224 -5
  84. package/dist/docx/server/templatePlan/effects.d.ts +27 -0
  85. package/dist/docx/server/templatePlan/effects.js +188 -0
  86. package/dist/docx/server/templatePlan/emit.d.ts +4 -1
  87. package/dist/docx/server/templatePlan/emit.js +46 -2
  88. package/dist/docx/server/templatePlan/inspect.js +39 -52
  89. package/dist/docx/server/templatePlan/labels.d.ts +7 -2
  90. package/dist/docx/server/templatePlan/labels.js +120 -23
  91. package/dist/docx/server/templatePlan/plan.d.ts +24 -3
  92. package/dist/docx/server/templatePlan/plan.js +54 -15
  93. package/dist/docx/server/templatePlan/planShape.js +76 -22
  94. package/dist/docx/server/templatePlan/revisions.d.ts +46 -0
  95. package/dist/docx/server/templatePlan/revisions.js +407 -0
  96. package/dist/docx/server/templatePlan/story.d.ts +23 -1
  97. package/dist/docx/server/templatePlan/story.js +60 -2
  98. package/dist/docx/server/templatePlan/types.d.ts +354 -16
  99. package/dist/docx/server/templatePlan/verify.js +164 -14
  100. package/dist/docx/server/templatePlan/xml.d.ts +3 -0
  101. package/dist/docx/server/templatePlan/xml.js +4 -1
  102. package/dist/i18n/messages/ar.gen.js +1 -0
  103. package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
  104. package/dist/i18n/messages/catalogs.gen.js +17 -0
  105. package/dist/i18n/messages/cs.gen.js +1 -0
  106. package/dist/i18n/messages/de.gen.js +1 -0
  107. package/dist/i18n/messages/en.gen.js +1 -0
  108. package/dist/i18n/messages/es.gen.js +1 -0
  109. package/dist/i18n/messages/et.gen.js +1 -0
  110. package/dist/i18n/messages/fr.gen.js +1 -0
  111. package/dist/i18n/messages/he.gen.js +1 -0
  112. package/dist/i18n/messages/hi.gen.js +1 -0
  113. package/dist/i18n/messages/hu.gen.js +1 -0
  114. package/dist/i18n/messages/lt.gen.js +1 -0
  115. package/dist/i18n/messages/lv.gen.js +1 -0
  116. package/dist/i18n/messages/messages.gen.d.ts +1 -0
  117. package/dist/i18n/messages/pl.gen.js +1 -0
  118. package/dist/i18n/messages/pt-BR.gen.js +1 -0
  119. package/dist/i18n/messages/sk.gen.js +1 -0
  120. package/dist/i18n/messages/tr.gen.js +1 -0
  121. package/dist/i18n/messages/zh-CN.gen.js +1 -0
  122. package/dist/internal/revisionResolutionStep.d.ts +2 -31
  123. package/dist/internal/revisionResolutionStep.js +2 -171
  124. package/dist/layout-bridge/convert/toFlowBlocks.js +0 -12
  125. package/dist/layout-bridge/convert/topLevelConversion.js +1 -10
  126. package/dist/prosemirror/commands/comments.d.ts +6 -234
  127. package/dist/prosemirror/commands/comments.js +5 -2464
  128. package/dist/prosemirror/commands/index.d.ts +4 -2
  129. package/dist/prosemirror/commands/index.js +4 -2
  130. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -11
  131. package/dist/prosemirror/commands/tableCellMergeResolution.js +3 -154
  132. package/dist/prosemirror/extensions/features/ImagePasteExtension.js +1 -1
  133. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
  134. package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
  135. package/dist/prosemirror/hyperlinkRemoval.js +24 -15
  136. package/dist/prosemirror/listMarker.d.ts +1 -6
  137. package/dist/prosemirror/listMarker.js +4 -56
  138. package/dist/prosemirror/paraIds.d.ts +1 -14
  139. package/dist/prosemirror/paraIds.js +1 -14
  140. package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
  141. package/dist/prosemirror/paragraphMarkJoin.js +3 -46
  142. package/dist/prosemirror/projectionReview.d.ts +49 -0
  143. package/dist/prosemirror/projectionReview.js +292 -0
  144. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
  145. package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
  146. package/dist/prosemirror/replacedAnnotations.d.ts +2 -5
  147. package/dist/prosemirror/replacedAnnotations.js +1 -10
  148. package/dist/prosemirror/revisionCarriers.d.ts +9 -1
  149. package/dist/prosemirror/revisionCarriers.js +15 -1
  150. package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
  151. package/dist/prosemirror/revisionRangeQueries.js +76 -0
  152. package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
  153. package/dist/prosemirror/runFormattingMarkNames.js +1 -1
  154. package/dist/prosemirror/suggestionQueries.d.ts +114 -0
  155. package/dist/prosemirror/suggestionQueries.js +320 -0
  156. package/dist/prosemirror/tableGridMutation.d.ts +1 -16
  157. package/dist/prosemirror/tableGridMutation.js +1 -78
  158. package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
  159. package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
  160. package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
  161. package/dist/server.d.ts +2 -2
  162. package/dist/types/canonicalCapabilities.d.ts +40 -69
  163. package/dist/types/canonicalCapabilities.js +51 -65
  164. package/dist/types/canonicalComments.d.ts +2 -2
  165. package/dist/types/canonicalSections.d.ts +2 -2
  166. package/dist/utils/clipboard.d.ts +2 -28
  167. package/dist/utils/clipboard.js +1 -96
  168. package/dist/utils/clipboardFiles.d.ts +27 -0
  169. package/dist/utils/clipboardFiles.js +98 -0
  170. package/dist/utils/rulerControl.d.ts +1 -0
  171. package/dist/utils/rulerControl.js +2 -1
  172. package/package.json +2 -2
  173. package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
  174. package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
@@ -0,0 +1,114 @@
1
+ import { ParagraphPropertyChangeAttrs } from "./schema/nodes.js";
2
+ import { EditorState } from "prosemirror-state";
3
+ import { ParagraphMarkChange } from "@stll/docx-core/model";
4
+ import { Mark, Node } from "prosemirror-model";
5
+ export declare const isSuggestionMark: (mark: Mark) => boolean;
6
+ /**
7
+ * The suggestion a comment mark belongs to: a comment a suggestion proposed
8
+ * is pending with it, never saved, accepted and rejected with it.
9
+ */
10
+ export declare const suggestedCommentOf: (mark: Mark) => string | null;
11
+ /** The ids of the comments a pending suggestion proposes. */
12
+ export declare function suggestionCommentIds(state: EditorState, suggestionId: string): number[];
13
+ export type SuggestionKind = "insertion" | "deletion" | "formatting" | "insertBlock" | "insertTable" | "insertRow" | "deleteRow" | "insertColumn" | "deleteColumn" | "comment";
14
+ /**
15
+ * How a suggestion is applied when accepted:
16
+ * - `"tracked"` — converts to a normal OOXML tracked change (`w:ins`/`w:del`,
17
+ * paragraph-mark `w:ins`, row/cell `w:ins`/`w:del`);
18
+ * - `"direct"` — no OOXML tracked representation exists (a whole inserted
19
+ * table), so accepting applies it directly; a suggestion that only
20
+ * proposes a comment is accepted as an ordinary comment;
21
+ * - `"mixed"` — a heterogeneous group (one `suggestionId` spanning a whole
22
+ * inserted table AND other edits) whose parts apply both ways. Accept still
23
+ * resolves the whole group in one transaction; this flag lets the host
24
+ * message that some parts landed directly.
25
+ */
26
+ export type SuggestionAppliedAs = "tracked" | "direct" | "mixed";
27
+ export type FolioSuggestion = {
28
+ suggestionId: string;
29
+ /** Contiguous document ranges the suggestion covers, in document order. */
30
+ ranges: readonly {
31
+ from: number;
32
+ to: number;
33
+ }[];
34
+ /** Which kinds of change the suggestion contains (deduped, in a stable order). */
35
+ kinds: readonly SuggestionKind[];
36
+ /** How accepting this suggestion applies it (see {@link SuggestionAppliedAs}). */
37
+ appliedAs: SuggestionAppliedAs;
38
+ };
39
+ /**
40
+ * A node-attr (block/table) suggestion read off a single node: a whole-node
41
+ * `_suggestedInsert`, or a suggested `trIns`/`trDel`/`cellMarker`.
42
+ */
43
+ type StructuralSuggestion = {
44
+ suggestionId: string;
45
+ revisionId: number;
46
+ kind: SuggestionKind;
47
+ /** True for a whole-node insert (paragraph/table): rejected by node deletion. */
48
+ isNodeInsert: boolean;
49
+ };
50
+ export declare const readSuggestedMarker: (marker: unknown) => {
51
+ suggestionId: string;
52
+ revisionId: number;
53
+ } | null;
54
+ export declare const readSuggestedParagraphPropertyChange: (change: ParagraphPropertyChangeAttrs) => {
55
+ suggestionId: string;
56
+ revisionId: number;
57
+ } | null;
58
+ type SuggestedParagraphMark = {
59
+ suggestionId: string;
60
+ revisionId: number;
61
+ kind: SuggestionKind;
62
+ };
63
+ /** The suggestion one paragraph-mark record belongs to, read off its info. */
64
+ export declare const suggestionIdOfMarkRecord: (info: ParagraphMarkChange["info"]) => string | null;
65
+ /** The suggestion the paragraph mark's own record, its break's, belongs to. */
66
+ export declare const readSuggestedParagraphMark: (node: Node) => SuggestedParagraphMark | null;
67
+ export declare const readStructuralSuggestion: (node: Node) => StructuralSuggestion | null;
68
+ type SuggestionAccumulator = {
69
+ segments: {
70
+ from: number;
71
+ to: number;
72
+ }[];
73
+ kinds: Set<SuggestionKind>;
74
+ revisionIds: Set<number>;
75
+ /** The comments the suggestion proposes. */
76
+ commentIds: Set<number>;
77
+ };
78
+ export declare const collectSuggestions: (state: EditorState) => Map<string, SuggestionAccumulator>;
79
+ /** Merge sorted, possibly adjacent/overlapping segments into contiguous ranges. */
80
+ export declare const mergeSegments: (segments: readonly {
81
+ from: number;
82
+ to: number;
83
+ }[]) => {
84
+ from: number;
85
+ to: number;
86
+ }[];
87
+ /**
88
+ * List every suggestion in the document for host consumption: its id, the
89
+ * contiguous ranges it covers, which kinds of change it contains, and how
90
+ * accepting it applies (tracked vs direct).
91
+ */
92
+ export declare function getSuggestions(state: EditorState): FolioSuggestion[];
93
+ /** The disjoint projected ranges a single pending suggestion covers. */
94
+ export declare const getSuggestionRanges: (state: EditorState, suggestionId: string) => {
95
+ from: number;
96
+ to: number;
97
+ }[];
98
+ /** Physical revision IDs of every pending suggestion, in one document walk. */
99
+ export declare const pendingSuggestionRevisionIds: (state: EditorState) => ReadonlySet<number>;
100
+ /** The first owning suggestion for each physical revision, in source order. */
101
+ export declare const suggestionOwnersByRevision: (state: EditorState) => ReadonlyMap<number, string>;
102
+ /** The suggestion a revision belongs to, or `null` for an ordinary tracked change. */
103
+ export declare function suggestionIdOfRevision(state: EditorState, revisionId: number): string | null;
104
+ /**
105
+ * The document range covering every mark belonging to `suggestionId`, plus the
106
+ * revision ids those marks carry. Returns null when the suggestion is absent
107
+ * (already accepted/rejected, or never existed).
108
+ */
109
+ export declare function findSuggestionRange(state: EditorState, suggestionId: string): {
110
+ from: number;
111
+ to: number;
112
+ revisionIds: number[];
113
+ } | null;
114
+ export {};
@@ -0,0 +1,320 @@
1
+ import { expectCommentMarkAttrs, expectParagraphAttrs, expectRunPropertyChangeMarkAttrs, expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, expectTrackedChangeMarkAttrs } from "./attrs/index.js";
2
+ import { isPPrMarkAttr, paragraphMarkWasAdded } from "./revisionCarriers.js";
3
+ // src/prosemirror/suggestionQueries.ts
4
+ const SUGGESTION_MARK_NAMES = /* @__PURE__ */ new Set([
5
+ "insertion",
6
+ "deletion",
7
+ "runPropertyChange"
8
+ ]);
9
+ const isSuggestionMark = (mark) => mark.attrs["provenance"] === "suggested" && SUGGESTION_MARK_NAMES.has(mark.type.name);
10
+ /**
11
+ * The suggestion a comment mark belongs to: a comment a suggestion proposed
12
+ * is pending with it, never saved, accepted and rejected with it.
13
+ */
14
+ const suggestedCommentOf = (mark) => {
15
+ if (mark.type.name !== "comment") return null;
16
+ const suggestionId = mark.attrs["suggestionId"];
17
+ return typeof suggestionId === "string" && suggestionId.length > 0 ? suggestionId : null;
18
+ };
19
+ /** The ids of the comments a pending suggestion proposes. */
20
+ function suggestionCommentIds(state, suggestionId) {
21
+ return [...collectSuggestions(state).get(suggestionId)?.commentIds ?? []];
22
+ }
23
+ const suggestionKindOf = (mark) => {
24
+ if (mark.type.name === "insertion") return "insertion";
25
+ if (mark.type.name === "deletion") return "deletion";
26
+ return "formatting";
27
+ };
28
+ const readSuggestedMarker = (marker) => {
29
+ if (typeof marker !== "object" || marker === null || marker.provenance !== "suggested") return null;
30
+ const suggestionId = marker.suggestionId;
31
+ const revisionId = marker.revisionId;
32
+ if (typeof suggestionId !== "string" || typeof revisionId !== "number") return null;
33
+ return {
34
+ suggestionId,
35
+ revisionId
36
+ };
37
+ };
38
+ const readSuggestedParagraphPropertyChange = (change) => {
39
+ if (change.info.provenance !== "suggested" || typeof change.info.suggestionId !== "string") return null;
40
+ return {
41
+ suggestionId: change.info.suggestionId,
42
+ revisionId: change.info.id
43
+ };
44
+ };
45
+ /**
46
+ * The property changes a table, row or cell carries as the model holds them:
47
+ * a pending suggestion's names its suggestion in its info.
48
+ */
49
+ const tablePropertyChangesOf = (node) => {
50
+ switch (node.type.name) {
51
+ case "table": return expectTableAttrs(node).tblPrChange ?? [];
52
+ case "tableRow": return expectTableRowAttrs(node).trPrChange ?? [];
53
+ case "tableCell":
54
+ case "tableHeader": return expectTableCellAttrs(node).tcPrChange ?? [];
55
+ default: return [];
56
+ }
57
+ };
58
+ /** The suggestion one paragraph-mark record belongs to, read off its info. */
59
+ const suggestionIdOfMarkRecord = (info) => "provenance" in info && info.provenance === "suggested" && "suggestionId" in info && typeof info.suggestionId === "string" ? info.suggestionId : null;
60
+ const suggestedRecordOf = (info, kind) => {
61
+ const suggestionId = suggestionIdOfMarkRecord(info);
62
+ return suggestionId === null ? null : {
63
+ suggestionId,
64
+ revisionId: info.id,
65
+ kind
66
+ };
67
+ };
68
+ /** The suggestion the paragraph mark's own record, its break's, belongs to. */
69
+ const readSuggestedParagraphMark = (node) => {
70
+ if (node.type.name !== "paragraph") return null;
71
+ const mark = node.attrs["pPrMark"];
72
+ if (!isPPrMarkAttr(mark)) return null;
73
+ return suggestedRecordOf(mark.info, paragraphMarkWasAdded(mark.kind) ? "insertion" : "deletion");
74
+ };
75
+ /**
76
+ * Every suggested record of a paragraph's mark: its own, and the later
77
+ * deletion an added mark holds beside its insertion.
78
+ */
79
+ const readSuggestedParagraphMarkRecords = (node) => {
80
+ const own = readSuggestedParagraphMark(node);
81
+ const mark = node.attrs["pPrMark"];
82
+ return [own, node.type.name === "paragraph" && isPPrMarkAttr(mark) && mark.deletion !== void 0 ? suggestedRecordOf(mark.deletion.info, "deletion") : null].filter((record) => record !== null);
83
+ };
84
+ const readStructuralSuggestion = (node) => {
85
+ const attrs = node.attrs;
86
+ const name = node.type.name;
87
+ const insertMarker = attrs["_suggestedInsert"];
88
+ if ((name === "paragraph" || name === "table") && typeof insertMarker === "object" && insertMarker !== null) {
89
+ const suggestionId = insertMarker.suggestionId;
90
+ const revisionId = insertMarker.revisionId;
91
+ if (typeof suggestionId === "string" && typeof revisionId === "number") return {
92
+ suggestionId,
93
+ revisionId,
94
+ kind: name === "table" ? "insertTable" : "insertBlock",
95
+ isNodeInsert: true
96
+ };
97
+ }
98
+ if (node.type.name === "tableRow") {
99
+ const ins = readSuggestedMarker(attrs["trIns"]);
100
+ if (ins) return {
101
+ ...ins,
102
+ kind: "insertRow",
103
+ isNodeInsert: false
104
+ };
105
+ const del = readSuggestedMarker(attrs["trDel"]);
106
+ if (del) return {
107
+ ...del,
108
+ kind: "deleteRow",
109
+ isNodeInsert: false
110
+ };
111
+ }
112
+ if (node.type.name === "tableCell" || node.type.name === "tableHeader") {
113
+ const cellMarker = attrs["cellMarker"];
114
+ if (typeof cellMarker === "object" && cellMarker !== null) {
115
+ const markerKind = cellMarker.kind;
116
+ if (markerKind === "ins" || markerKind === "del") {
117
+ const marker = readSuggestedMarker(cellMarker.info);
118
+ if (marker) {
119
+ const kind = markerKind === "del" ? "deleteColumn" : "insertColumn";
120
+ return {
121
+ ...marker,
122
+ kind,
123
+ isNodeInsert: false
124
+ };
125
+ }
126
+ }
127
+ }
128
+ }
129
+ return null;
130
+ };
131
+ const collectSuggestions = (state) => {
132
+ const runPropertyChangeType = state.schema.marks["runPropertyChange"];
133
+ const bySuggestion = /* @__PURE__ */ new Map();
134
+ const entryFor = (suggestionId) => {
135
+ const existing = bySuggestion.get(suggestionId);
136
+ if (existing) return existing;
137
+ const created = {
138
+ segments: [],
139
+ kinds: /* @__PURE__ */ new Set(),
140
+ revisionIds: /* @__PURE__ */ new Set(),
141
+ commentIds: /* @__PURE__ */ new Set()
142
+ };
143
+ bySuggestion.set(suggestionId, created);
144
+ return created;
145
+ };
146
+ state.doc.descendants((node, pos) => {
147
+ const structural = readStructuralSuggestion(node);
148
+ if (structural) {
149
+ const entry = entryFor(structural.suggestionId);
150
+ entry.segments.push({
151
+ from: pos,
152
+ to: pos + node.nodeSize
153
+ });
154
+ entry.kinds.add(structural.kind);
155
+ entry.revisionIds.add(structural.revisionId);
156
+ }
157
+ for (const { info } of tablePropertyChangesOf(node)) {
158
+ if (info.suggestionId === void 0) continue;
159
+ const entry = entryFor(info.suggestionId);
160
+ entry.segments.push({
161
+ from: pos,
162
+ to: pos + node.nodeSize
163
+ });
164
+ entry.kinds.add("formatting");
165
+ entry.revisionIds.add(info.id);
166
+ }
167
+ if (node.type.name === "paragraph") {
168
+ for (const paragraphMark of readSuggestedParagraphMarkRecords(node)) {
169
+ const entry = entryFor(paragraphMark.suggestionId);
170
+ entry.segments.push({
171
+ from: pos,
172
+ to: pos + node.nodeSize
173
+ });
174
+ entry.kinds.add(paragraphMark.kind);
175
+ entry.revisionIds.add(paragraphMark.revisionId);
176
+ }
177
+ const propertyChanges = expectParagraphAttrs(node)._propertyChanges;
178
+ if (Array.isArray(propertyChanges)) for (const change of propertyChanges) {
179
+ const suggested = readSuggestedParagraphPropertyChange(change);
180
+ if (!suggested) continue;
181
+ const entry = entryFor(suggested.suggestionId);
182
+ entry.segments.push({
183
+ from: pos,
184
+ to: pos + node.nodeSize
185
+ });
186
+ entry.kinds.add("formatting");
187
+ entry.revisionIds.add(suggested.revisionId);
188
+ }
189
+ }
190
+ if (!node.isInline) return;
191
+ for (const mark of node.marks) {
192
+ const commentSuggestion = suggestedCommentOf(mark);
193
+ if (commentSuggestion !== null) {
194
+ const entry = entryFor(commentSuggestion);
195
+ entry.segments.push({
196
+ from: pos,
197
+ to: pos + node.nodeSize
198
+ });
199
+ entry.kinds.add("comment");
200
+ entry.commentIds.add(expectCommentMarkAttrs(mark).commentId);
201
+ continue;
202
+ }
203
+ if (mark.type.name === "insertion" || mark.type.name === "deletion") for (const ancestor of expectTrackedChangeMarkAttrs(mark)._docxRevisionAncestors ?? []) {
204
+ if (ancestor.suggestionId === void 0) continue;
205
+ const entry = entryFor(ancestor.suggestionId);
206
+ entry.segments.push({
207
+ from: pos,
208
+ to: pos + node.nodeSize
209
+ });
210
+ entry.kinds.add(ancestor.type === "insertion" || ancestor.type === "moveTo" ? "insertion" : "deletion");
211
+ entry.revisionIds.add(ancestor.revisionId);
212
+ }
213
+ if (!isSuggestionMark(mark)) continue;
214
+ const suggestionId = mark.attrs["suggestionId"];
215
+ if (typeof suggestionId !== "string" || suggestionId.length === 0) continue;
216
+ const entry = entryFor(suggestionId);
217
+ entry.segments.push({
218
+ from: pos,
219
+ to: pos + node.nodeSize
220
+ });
221
+ entry.kinds.add(suggestionKindOf(mark));
222
+ if (mark.type === runPropertyChangeType) for (const change of expectRunPropertyChangeMarkAttrs(mark).changes) entry.revisionIds.add(change.info.id);
223
+ else if (typeof mark.attrs["revisionId"] === "number") entry.revisionIds.add(mark.attrs["revisionId"]);
224
+ }
225
+ });
226
+ return bySuggestion;
227
+ };
228
+ /**
229
+ * A whole inserted table (`insertTable`) has no OOXML tracked representation and
230
+ * accepts directly; every other kind accepts as a tracked change. A group that
231
+ * mixes a table insert with any other kind (a caller stamping heterogeneous
232
+ * operations with one `suggestionId`) is `"mixed"`.
233
+ */
234
+ const suggestionAppliedAs = (kinds) => {
235
+ const changes = [...kinds].filter((kind) => kind !== "comment");
236
+ if (changes.length === 0) return "direct";
237
+ if (!kinds.has("insertTable")) return "tracked";
238
+ return changes.some((kind) => kind !== "insertTable") ? "mixed" : "direct";
239
+ };
240
+ /** Merge sorted, possibly adjacent/overlapping segments into contiguous ranges. */
241
+ const mergeSegments = (segments) => {
242
+ const sorted = [...segments].toSorted((a, b) => a.from - b.from || a.to - b.to);
243
+ const merged = [];
244
+ for (const segment of sorted) {
245
+ const last = merged.at(-1);
246
+ if (last && segment.from <= last.to) {
247
+ last.to = Math.max(last.to, segment.to);
248
+ continue;
249
+ }
250
+ merged.push({ ...segment });
251
+ }
252
+ return merged;
253
+ };
254
+ const SUGGESTION_KIND_ORDER = [
255
+ "insertion",
256
+ "deletion",
257
+ "formatting",
258
+ "insertBlock",
259
+ "insertTable",
260
+ "insertRow",
261
+ "deleteRow",
262
+ "insertColumn",
263
+ "deleteColumn",
264
+ "comment"
265
+ ];
266
+ /**
267
+ * List every suggestion in the document for host consumption: its id, the
268
+ * contiguous ranges it covers, which kinds of change it contains, and how
269
+ * accepting it applies (tracked vs direct).
270
+ */
271
+ function getSuggestions(state) {
272
+ const bySuggestion = collectSuggestions(state);
273
+ const suggestions = [];
274
+ for (const [suggestionId, entry] of bySuggestion) suggestions.push({
275
+ suggestionId,
276
+ ranges: mergeSegments(entry.segments),
277
+ kinds: SUGGESTION_KIND_ORDER.filter((kind) => entry.kinds.has(kind)),
278
+ appliedAs: suggestionAppliedAs(entry.kinds)
279
+ });
280
+ return suggestions.toSorted((a, b) => (a.ranges[0]?.from ?? 0) - (b.ranges[0]?.from ?? 0));
281
+ }
282
+ /** The disjoint projected ranges a single pending suggestion covers. */
283
+ const getSuggestionRanges = (state, suggestionId) => {
284
+ const entry = collectSuggestions(state).get(suggestionId);
285
+ return entry === void 0 ? [] : mergeSegments(entry.segments);
286
+ };
287
+ /** Physical revision IDs of every pending suggestion, in one document walk. */
288
+ const pendingSuggestionRevisionIds = (state) => {
289
+ const ids = /* @__PURE__ */ new Set();
290
+ for (const { revisionIds } of collectSuggestions(state).values()) for (const id of revisionIds) ids.add(id);
291
+ return ids;
292
+ };
293
+ /** The first owning suggestion for each physical revision, in source order. */
294
+ const suggestionOwnersByRevision = (state) => {
295
+ const owners = /* @__PURE__ */ new Map();
296
+ for (const [suggestionId, entry] of collectSuggestions(state)) for (const id of entry.revisionIds) if (!owners.has(id)) owners.set(id, suggestionId);
297
+ return owners;
298
+ };
299
+ /** The suggestion a revision belongs to, or `null` for an ordinary tracked change. */
300
+ function suggestionIdOfRevision(state, revisionId) {
301
+ for (const [suggestionId, entry] of collectSuggestions(state)) if (entry.revisionIds.has(revisionId)) return suggestionId;
302
+ return null;
303
+ }
304
+ /**
305
+ * The document range covering every mark belonging to `suggestionId`, plus the
306
+ * revision ids those marks carry. Returns null when the suggestion is absent
307
+ * (already accepted/rejected, or never existed).
308
+ */
309
+ function findSuggestionRange(state, suggestionId) {
310
+ const entry = collectSuggestions(state).get(suggestionId);
311
+ if (!entry || entry.segments.length === 0) return null;
312
+ const ranges = mergeSegments(entry.segments);
313
+ const from = ranges[0]?.from ?? 0;
314
+ return {
315
+ from,
316
+ to: ranges.at(-1)?.to ?? from,
317
+ revisionIds: [...entry.revisionIds]
318
+ };
319
+ }
320
+ export { collectSuggestions, findSuggestionRange, getSuggestionRanges, getSuggestions, isSuggestionMark, mergeSegments, pendingSuggestionRevisionIds, readStructuralSuggestion, readSuggestedMarker, readSuggestedParagraphMark, readSuggestedParagraphPropertyChange, suggestedCommentOf, suggestionCommentIds, suggestionIdOfMarkRecord, suggestionIdOfRevision, suggestionOwnersByRevision };
@@ -18,13 +18,6 @@ type RemoveTableRowOptions = {
18
18
  * and the table is left one row shorter than that merge.
19
19
  */
20
20
  export declare const removeTableRow: (tr: Transaction, { map, table, tableStart }: RemoveTableRowOptions, row: number) => void;
21
- /**
22
- * Remove the row at `rowPos` as rejecting its insertion does: through
23
- * `removeTableRow`, so the vertical merges crossing it stay whole, or, for a
24
- * table's only row, the table with it, leaving an empty paragraph where its
25
- * container must keep a block.
26
- */
27
- export declare const deleteTableRowAt: (tr: Transaction, rowPos: number) => void;
28
21
  /** A placeholder for an absent grid position is not a cell a row can keep. */
29
22
  export declare const rowHoldsNoCells: (row: Node, besides?: Node) => boolean;
30
23
  /**
@@ -43,6 +36,7 @@ export declare const reconcileOmittedGridSlots: (tr: Transaction, tablePosition:
43
36
  export type RowsEmptiedInBatch = {
44
37
  pending: boolean;
45
38
  };
39
+ export declare const ROW_CLEANUP_PENDING = "pending";
46
40
  type MarkRowEmptiedInBatchOptions = {
47
41
  tr: Transaction;
48
42
  rowPosition: number;
@@ -58,15 +52,6 @@ type MarkRowsEmptiedInBatchOptions = {
58
52
  };
59
53
  /** Column removal keeps row indices stable: mark only newly cell-less rows. */
60
54
  export declare const markRowsEmptiedInBatch: ({ tr, tablePosition, previousTable, emptied }: MarkRowsEmptiedInBatchOptions) => void;
61
- /** Sweep current tables in reverse so moves cannot invalidate cleanup targets. */
62
- export declare const removeRowsWithoutCellsAfterBatch: (tr: Transaction, emptied: RowsEmptiedInBatch) => void;
63
- type RemoveRowsWithoutCellsInRangeOptions = {
64
- tr: Transaction;
65
- from: number;
66
- to: number;
67
- };
68
- /** Close marked rows before their owning cell is captured into a continuation payload. */
69
- export declare const removeRowsWithoutCellsInRange: ({ tr, from, to }: RemoveRowsWithoutCellsInRangeOptions) => void;
70
55
  /**
71
56
  * Close the rows an immediate structural edit left without cells. A row written
72
57
  * with none is no row this edit emptied, and it stays.
@@ -45,37 +45,6 @@ const removeTableRow = (tr, { map, table, tableStart }, row) => {
45
45
  column += colspan;
46
46
  }
47
47
  };
48
- /**
49
- * Remove the row at `rowPos` as rejecting its insertion does: through
50
- * `removeTableRow`, so the vertical merges crossing it stay whole, or, for a
51
- * table's only row, the table with it, leaving an empty paragraph where its
52
- * container must keep a block.
53
- */
54
- const deleteTableRowAt = (tr, rowPos) => {
55
- const resolved = tr.doc.resolve(rowPos);
56
- const table = resolved.parent;
57
- if (table.type.spec["tableRole"] !== "table") return;
58
- const rowIndex = resolved.index();
59
- if (table.childCount > 1) {
60
- removeTableRow(tr, {
61
- map: TableMap.get(table),
62
- table,
63
- tableStart: resolved.start()
64
- }, rowIndex);
65
- return;
66
- }
67
- const tablePosition = resolved.start() - 1;
68
- const tableEnd = tablePosition + table.nodeSize;
69
- const outerResolved = tr.doc.resolve(tablePosition);
70
- const parent = outerResolved.parent;
71
- const tableIndex = outerResolved.index();
72
- if (parent.canReplace(tableIndex, tableIndex + 1)) {
73
- tr.delete(tablePosition, tableEnd);
74
- return;
75
- }
76
- const emptyParagraph = tr.doc.type.schema.nodes["paragraph"]?.createAndFill();
77
- if (emptyParagraph && parent.canReplaceWith(tableIndex, tableIndex + 1, emptyParagraph.type, emptyParagraph.marks)) tr.replaceWith(tablePosition, tableEnd, emptyParagraph);
78
- };
79
48
  /** A placeholder for an absent grid position is not a cell a row can keep. */
80
49
  const rowHoldsNoCells = (row, besides) => {
81
50
  let holdsCell = false;
@@ -176,52 +145,6 @@ const markRowsEmptiedInBatch = ({ tr, tablePosition, previousTable, emptied }) =
176
145
  });
177
146
  });
178
147
  };
179
- const removeEmptyRows = ({ tr, tablePosition, shouldRemove }) => {
180
- for (;;) {
181
- const table = tr.doc.nodeAt(tablePosition);
182
- if (!table || table.type.spec["tableRole"] !== "table" || table.childCount < 2) return;
183
- let emptyRow = -1;
184
- table.forEach((row, _offset, index) => {
185
- if (emptyRow === -1 && rowHoldsNoCells(row) && shouldRemove(row)) emptyRow = index;
186
- });
187
- if (emptyRow === -1) return;
188
- removeTableRow(tr, {
189
- map: TableMap.get(table),
190
- table,
191
- tableStart: tablePosition + 1
192
- }, emptyRow);
193
- }
194
- };
195
- /** Remove only rows emptied by deletions in this transaction, then clear remaining markers. */
196
- const removeBatchRows = (tr, tablePosition) => {
197
- removeEmptyRows({
198
- tr,
199
- tablePosition,
200
- shouldRemove: (row) => row.attrs["_batchRowCleanup"] === ROW_CLEANUP_PENDING
201
- });
202
- tr.doc.nodeAt(tablePosition)?.forEach((row, offset) => {
203
- if (row.attrs["_batchRowCleanup"] === ROW_CLEANUP_PENDING) tr.setNodeAttribute(tablePosition + 1 + offset, "_batchRowCleanup", null);
204
- });
205
- };
206
- /** Sweep current tables in reverse so moves cannot invalidate cleanup targets. */
207
- const removeRowsWithoutCellsAfterBatch = (tr, emptied) => {
208
- if (!emptied.pending) return;
209
- const tables = [];
210
- tr.doc.descendants((node, position) => {
211
- if (node.type.spec["tableRole"] === "table") tables.push(position);
212
- return !node.isTextblock;
213
- });
214
- for (const position of tables.toReversed()) removeBatchRows(tr, position);
215
- };
216
- /** Close marked rows before their owning cell is captured into a continuation payload. */
217
- const removeRowsWithoutCellsInRange = ({ tr, from, to }) => {
218
- const tables = [];
219
- tr.doc.nodesBetween(from, to, (node, position) => {
220
- if (position >= from && node.type.spec["tableRole"] === "table") tables.push(position);
221
- return !node.isTextblock;
222
- });
223
- for (const position of tables.toReversed()) removeBatchRows(tr, position);
224
- };
225
148
  /**
226
149
  * Close the rows an immediate structural edit left without cells. A row written
227
150
  * with none is no row this edit emptied, and it stays.
@@ -414,4 +337,4 @@ const removeTableColumns = (tr, tablePosition, left, right) => {
414
337
  }
415
338
  removeRowsWithoutCells(tr, tablePosition, previousTable);
416
339
  };
417
- export { deleteTableRowAt, insertTableColumn, insertedColumnWidth, markRowEmptiedInBatch, markRowsEmptiedInBatch, omittedSlotTakingColumn, reconcileOmittedGridSlots, reconcileTableGridAfterColumnInsertion, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCells, removeRowsWithoutCellsAfterBatch, removeRowsWithoutCellsInRange, removeTableColumns, removeTableRow, rowHoldsNoCells };
340
+ export { ROW_CLEANUP_PENDING, insertTableColumn, insertedColumnWidth, markRowEmptiedInBatch, markRowsEmptiedInBatch, omittedSlotTakingColumn, reconcileOmittedGridSlots, reconcileTableGridAfterColumnInsertion, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCells, removeTableColumns, removeTableRow, rowHoldsNoCells };
@@ -0,0 +1,18 @@
1
+ type TableRowRevisionCompanionOptions = {
2
+ row: {
3
+ id: number;
4
+ author?: string | undefined;
5
+ date?: string | null | undefined;
6
+ };
7
+ candidate: {
8
+ id: unknown;
9
+ author: unknown;
10
+ date: unknown;
11
+ };
12
+ };
13
+ /**
14
+ * A row's structural and inline marks can share a revision id. Word can also
15
+ * mint separate ids for them, so a matching author and known date count too.
16
+ */
17
+ export declare const isTableRowRevisionCompanion: ({ row, candidate }: TableRowRevisionCompanionOptions) => boolean;
18
+ export {};
@@ -0,0 +1,7 @@
1
+ // src/prosemirror/tableRowRevisionOwnership.ts
2
+ /**
3
+ * A row's structural and inline marks can share a revision id. Word can also
4
+ * mint separate ids for them, so a matching author and known date count too.
5
+ */
6
+ const isTableRowRevisionCompanion = ({ row, candidate }) => candidate.id === row.id || row.author !== void 0 && candidate.author === row.author && typeof row.date === "string" && row.date.length > 0 && candidate.date === row.date;
7
+ export { isTableRowRevisionCompanion };
@@ -1,6 +1,7 @@
1
1
  import { expectRunPropertyChangeMarkAttrs, expectTrackedChangeMarkAttrs } from "../attrs/index.js";
2
2
  import { nodePropertyRevisionSites, propertyRevisionMetadata, propertyRevisionRecords } from "../revisionCarriers.js";
3
3
  import { getTableCellMergeChange } from "../tableCellMergeRevision.js";
4
+ import { isTableRowRevisionCompanion } from "../tableRowRevisionOwnership.js";
4
5
  // src/prosemirror/utils/extractTrackedChanges.ts
5
6
  const EMPTY_RESULT = {
6
7
  entries: [],
@@ -8,14 +9,23 @@ const EMPTY_RESULT = {
8
9
  };
9
10
  /**
10
11
  * Fold a run's revision mark into the enclosing row's card when both halves
11
- * are the same change. Folio writes both under one revision id; Word mints a
12
- * fresh `w:id` per element, so an author + timestamp match counts too. Returns
13
- * false for a third party's edit inside the row, which keeps its own card.
12
+ * are the same change. An independent edit inside the row keeps its own card.
14
13
  */
15
14
  const foldIntoRowRevision = (scope, mark) => {
16
15
  if (!scope || mark.type !== scope.markType) return false;
17
16
  const revisionId = mark.attrs["revisionId"];
18
- if (!(revisionId === scope.entry.revisionId || mark.attrs["author"] === scope.entry.author && mark.attrs["date"] === scope.entry.date)) return false;
17
+ if (!isTableRowRevisionCompanion({
18
+ row: {
19
+ id: scope.entry.revisionId,
20
+ author: scope.entry.author,
21
+ date: scope.entry.date
22
+ },
23
+ candidate: {
24
+ id: revisionId,
25
+ author: mark.attrs["author"],
26
+ date: mark.attrs["date"]
27
+ }
28
+ })) return false;
19
29
  if (revisionId !== scope.entry.revisionId) {
20
30
  const ids = new Set(scope.entry.coalescedRevisionIds ?? []);
21
31
  ids.add(revisionId);