@stll/folio-core 0.76.0 → 0.77.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.
- package/dist/ai-edits/headless.d.ts +6 -4
- package/dist/ai-edits/headless.js +32 -15
- package/dist/ai-edits/pending-suggestions.d.ts +9 -0
- package/dist/ai-edits/pending-suggestions.js +11 -0
- package/dist/ai-edits/read.js +24 -1
- package/dist/ai-edits/table-geometry.js +12 -4
- package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
- package/dist/canonical/canonicalInlineProjection.js +2 -2
- package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
- package/dist/canonical/canonicalPublicOperations.js +13 -38
- package/dist/canonical/canonicalSeedContent.d.ts +18 -3
- package/dist/canonical/canonicalSeedContent.js +28 -15
- package/dist/canonical/canonicalSession.d.ts +22 -12
- package/dist/canonical/canonicalSession.js +178 -186
- package/dist/controller/canonicalClipboard.d.ts +2 -1
- package/dist/controller/canonicalClipboard.js +312 -47
- package/dist/controller/canonicalComposition.js +67 -14
- package/dist/controller/canonicalStoryEditor.js +2 -0
- package/dist/controller/hiddenEditorManager.js +2 -0
- package/dist/docx/importedIdCollisions.js +29 -4
- package/dist/docx/server/templatePlan/apply.js +47 -2
- package/dist/docx/server/templatePlan/blocks.d.ts +27 -7
- package/dist/docx/server/templatePlan/blocks.js +103 -12
- package/dist/docx/server/templatePlan/builders.d.ts +6 -0
- package/dist/docx/server/templatePlan/builders.js +7 -1
- package/dist/docx/server/templatePlan/emit.d.ts +2 -0
- package/dist/docx/server/templatePlan/emit.js +108 -6
- package/dist/docx/server/templatePlan/plan.d.ts +24 -1
- package/dist/docx/server/templatePlan/plan.js +165 -12
- package/dist/docx/server/templatePlan/planShape.js +13 -2
- package/dist/docx/server/templatePlan/revisions.d.ts +55 -0
- package/dist/docx/server/templatePlan/revisions.js +276 -2
- package/dist/docx/server/templatePlan/story.d.ts +46 -1
- package/dist/docx/server/templatePlan/story.js +125 -11
- package/dist/docx/server/templatePlan/types.d.ts +97 -1
- package/dist/docx/server/templatePlan/verify.js +63 -9
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
- package/dist/docx/tableGridXml.d.ts +3 -7
- package/dist/docx/tableGridXml.js +5 -13
- package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
- package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
- package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
- package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +1 -3
- package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
- package/dist/prosemirror/conversion/markupViewSource.js +11 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +3 -0
- package/dist/prosemirror/conversion/toProseDoc.js +31 -14
- package/dist/prosemirror/independentMarkupProjection.d.ts +27 -0
- package/dist/prosemirror/independentMarkupProjection.js +147 -0
- package/dist/prosemirror/markupViewNotes.d.ts +1 -1
- package/dist/prosemirror/markupViewNotes.js +24 -27
- package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
- package/dist/prosemirror/markupViewPositionMap.js +316 -0
- package/dist/prosemirror/markupViewProjection.d.ts +3 -46
- package/dist/prosemirror/markupViewProjection.js +90 -17
- package/dist/prosemirror/replacedAnnotations.d.ts +4 -78
- package/dist/prosemirror/replacedAnnotations.js +11 -194
- package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
- package/dist/prosemirror/styles/styleResolver.js +4 -1
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +3 -10
- package/dist/types/canonicalCapabilities.js +3 -10
- package/package.json +2 -2
- package/dist/internal/revisionResolutionEdits.d.ts +0 -11
- package/dist/internal/revisionResolutionEdits.js +0 -18
- package/dist/internal/revisionResolutionInline.d.ts +0 -24
- package/dist/internal/revisionResolutionInline.js +0 -302
- package/dist/internal/revisionResolutionStep.d.ts +0 -3
- package/dist/internal/revisionResolutionStep.js +0 -113
- package/dist/internal/revisionResolutionTracking.d.ts +0 -9
- package/dist/internal/revisionResolutionTracking.js +0 -124
- package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
- package/dist/internal/wholeStoryRevisionResolution.js +0 -783
- package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
- package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -8
- package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -56
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
- package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
- package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
- package/dist/prosemirror/rejoinRunCarriers.js +0 -65
- package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
- package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
|
@@ -545,7 +545,8 @@ export declare class FolioDocxReviewer {
|
|
|
545
545
|
/**
|
|
546
546
|
* Resolve one editable story to its original or final state, its staged
|
|
547
547
|
* suggestions with its other changes. A suggestion that reaches another
|
|
548
|
-
* story resolves only
|
|
548
|
+
* story resolves only in this one: its part in the others stays pending,
|
|
549
|
+
* for their own story resolution or the suggestion methods. A lock that
|
|
549
550
|
* prevents any target change from resolving refuses before mutation.
|
|
550
551
|
*/
|
|
551
552
|
resolveReviewedStory({ story, view }: FolioResolveReviewedStoryOptions): boolean;
|
|
@@ -722,7 +723,8 @@ export declare class FolioDocxReviewer {
|
|
|
722
723
|
/**
|
|
723
724
|
* One pending suggestion through the session's suggestion intent: rejected
|
|
724
725
|
* with the comments it proposes, or adopted as ordinary tracked changes by
|
|
725
|
-
* `author`. All stories belonging to the proposal publish together
|
|
726
|
+
* `author`. All stories belonging to the proposal publish together, or
|
|
727
|
+
* only its part in `story`.
|
|
726
728
|
*/
|
|
727
729
|
private resolveSuggestionOnSession;
|
|
728
730
|
/**
|
|
@@ -764,8 +766,8 @@ export declare class FolioDocxReviewer {
|
|
|
764
766
|
* A story holding staged suggestions resolved to `view`: its suggestions
|
|
765
767
|
* resolve with its other changes, on a fork, and the fork's operations
|
|
766
768
|
* land here as one commit, so a refusal leaves this reviewer as it was. A
|
|
767
|
-
* suggestion that reaches another story resolves only
|
|
768
|
-
*
|
|
769
|
+
* suggestion that reaches another story resolves here only in this story:
|
|
770
|
+
* its records in the others stay pending.
|
|
769
771
|
*/
|
|
770
772
|
private resolveStoryWithSuggestions;
|
|
771
773
|
/**
|
|
@@ -31,7 +31,7 @@ import { getFolioNodeRevisionCarriers } from "../prosemirror/revisionCarriers.js
|
|
|
31
31
|
import { schema } from "../prosemirror/schema/index.js";
|
|
32
32
|
import { sectionPropertiesOf } from "../prosemirror/sectionCarrier.js";
|
|
33
33
|
import { getSuggestions } from "../prosemirror/suggestionQueries.js";
|
|
34
|
-
import { CANONICAL_GAP, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
|
|
34
|
+
import { CANONICAL_CONDITION, CANONICAL_GAP, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
|
|
35
35
|
import { readModel } from "../types/documentModel.js";
|
|
36
36
|
import { canonicalJson } from "../utils/canonicalJson.js";
|
|
37
37
|
import { buildAnnotatedBlockTextWithNoteReferences } from "./clean-text.js";
|
|
@@ -123,12 +123,21 @@ const canonicalOpStory = (story) => {
|
|
|
123
123
|
default: return panic("Unknown reviewer story", { story });
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
|
-
/**
|
|
126
|
+
/**
|
|
127
|
+
* The refusal of a canonical reviewer for a staged suggestion the session
|
|
128
|
+
* left pending: the suggestion's resolution refused without stating why.
|
|
129
|
+
*/
|
|
127
130
|
const canonicalReviewerRefusal = (action) => new CanonicalSessionError({
|
|
128
131
|
ground: { gap: CANONICAL_GAP.publicHeadlessSession },
|
|
129
132
|
reason: "refused",
|
|
130
133
|
message: `A canonical headless reviewer cannot ${action} yet.`
|
|
131
134
|
});
|
|
135
|
+
/** A reviewer request under one of the session's conditions. */
|
|
136
|
+
const canonicalReviewerConditionRefusal = (condition, message) => new CanonicalSessionError({
|
|
137
|
+
ground: { condition },
|
|
138
|
+
reason: "refused",
|
|
139
|
+
message
|
|
140
|
+
});
|
|
132
141
|
const FOLIO_REVIEWED_VIEWS = Object.freeze([
|
|
133
142
|
"original",
|
|
134
143
|
"current-markup",
|
|
@@ -775,8 +784,8 @@ var FolioDocxReviewer = class FolioDocxReviewer {
|
|
|
775
784
|
return copy;
|
|
776
785
|
}
|
|
777
786
|
canonicalComparisonAccess() {
|
|
778
|
-
const
|
|
779
|
-
throw
|
|
787
|
+
const missingNoteLabels = () => {
|
|
788
|
+
throw canonicalReviewerConditionRefusal(CANONICAL_CONDITION.invalidRequest, "Inline atoms are matched with the comparison's note reference labels.");
|
|
780
789
|
};
|
|
781
790
|
return Object.freeze({
|
|
782
791
|
stageTerminalTableReviewCarrier: () => false,
|
|
@@ -792,7 +801,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
|
|
|
792
801
|
story: canonicalOpStory(targetStory),
|
|
793
802
|
snapshot: targetSnapshot
|
|
794
803
|
},
|
|
795
|
-
noteReferenceLabels: noteReferenceLabels ??
|
|
804
|
+
noteReferenceLabels: noteReferenceLabels ?? missingNoteLabels(),
|
|
796
805
|
author: this.author
|
|
797
806
|
});
|
|
798
807
|
if (result.status !== "matched") return result;
|
|
@@ -1336,7 +1345,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
|
|
|
1336
1345
|
idSeed: revisionStamp.idSeed
|
|
1337
1346
|
}
|
|
1338
1347
|
});
|
|
1339
|
-
if (matched.status === "unaddressable") throw
|
|
1348
|
+
if (matched.status === "unaddressable") throw canonicalReviewerConditionRefusal(CANONICAL_CONDITION.internal, "A paired table cell holds no paragraph to address it by.");
|
|
1340
1349
|
if (matched.operations.length > 0) this.commitOpsOnSession(matched.operations);
|
|
1341
1350
|
return matched.nextRevisionId;
|
|
1342
1351
|
}
|
|
@@ -1364,7 +1373,8 @@ var FolioDocxReviewer = class FolioDocxReviewer {
|
|
|
1364
1373
|
/**
|
|
1365
1374
|
* Resolve one editable story to its original or final state, its staged
|
|
1366
1375
|
* suggestions with its other changes. A suggestion that reaches another
|
|
1367
|
-
* story resolves only
|
|
1376
|
+
* story resolves only in this one: its part in the others stays pending,
|
|
1377
|
+
* for their own story resolution or the suggestion methods. A lock that
|
|
1368
1378
|
* prevents any target change from resolving refuses before mutation.
|
|
1369
1379
|
*/
|
|
1370
1380
|
resolveReviewedStory({ story = MAIN_STORY, view }) {
|
|
@@ -1691,7 +1701,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
|
|
|
1691
1701
|
const document = readModel(session.document);
|
|
1692
1702
|
if (!(document.package.document.comments ?? []).some(({ id }) => id === parentId)) return null;
|
|
1693
1703
|
const id = freshCommentId(document, session.idLease);
|
|
1694
|
-
if (id.isErr()) throw
|
|
1704
|
+
if (id.isErr()) throw canonicalReviewerConditionRefusal(CANONICAL_CONDITION.idSpace, "No comment id is left to give the reply.");
|
|
1695
1705
|
const author = input.author ?? this.author;
|
|
1696
1706
|
const date = input.date ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
1697
1707
|
this.commitCommentOnSession(session, {
|
|
@@ -1840,15 +1850,17 @@ var FolioDocxReviewer = class FolioDocxReviewer {
|
|
|
1840
1850
|
/**
|
|
1841
1851
|
* One pending suggestion through the session's suggestion intent: rejected
|
|
1842
1852
|
* with the comments it proposes, or adopted as ordinary tracked changes by
|
|
1843
|
-
* `author`. All stories belonging to the proposal publish together
|
|
1853
|
+
* `author`. All stories belonging to the proposal publish together, or
|
|
1854
|
+
* only its part in `story`.
|
|
1844
1855
|
*/
|
|
1845
|
-
resolveSuggestionOnSession(session, suggestionId, resolution, author) {
|
|
1856
|
+
resolveSuggestionOnSession(session, suggestionId, resolution, author, story) {
|
|
1846
1857
|
if (!this.activeSuggestionIds().has(suggestionId)) return false;
|
|
1847
1858
|
const prepared = session.prepareSuggestion(this.state, {
|
|
1848
1859
|
suggestionId,
|
|
1849
1860
|
resolution,
|
|
1850
1861
|
author,
|
|
1851
|
-
date: (/* @__PURE__ */ new Date()).toISOString()
|
|
1862
|
+
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1863
|
+
...story === void 0 ? {} : { story }
|
|
1852
1864
|
});
|
|
1853
1865
|
if (prepared.isErr() && prepared.error.reason === "refused") return false;
|
|
1854
1866
|
return this.resolveOnSession(prepared).resolved;
|
|
@@ -1982,15 +1994,16 @@ var FolioDocxReviewer = class FolioDocxReviewer {
|
|
|
1982
1994
|
* A story holding staged suggestions resolved to `view`: its suggestions
|
|
1983
1995
|
* resolve with its other changes, on a fork, and the fork's operations
|
|
1984
1996
|
* land here as one commit, so a refusal leaves this reviewer as it was. A
|
|
1985
|
-
* suggestion that reaches another story resolves only
|
|
1986
|
-
*
|
|
1997
|
+
* suggestion that reaches another story resolves here only in this story:
|
|
1998
|
+
* its records in the others stay pending.
|
|
1987
1999
|
*/
|
|
1988
2000
|
resolveStoryWithSuggestions({ story, view, staged }) {
|
|
1989
2001
|
const key = editableStoryKey(story);
|
|
2002
|
+
const reaching = /* @__PURE__ */ new Set();
|
|
1990
2003
|
for (const handle of this.listStoryHandlesInternal()) {
|
|
1991
2004
|
if (editableStoryKey(handle) === key) continue;
|
|
1992
2005
|
const other = this.getEditableStoryState(handle);
|
|
1993
|
-
|
|
2006
|
+
for (const suggestionId of other ? this.pendingSuggestionIdsForStory(handle, other) : []) if (staged.has(suggestionId)) reaching.add(suggestionId);
|
|
1994
2007
|
}
|
|
1995
2008
|
const copy = this.fork();
|
|
1996
2009
|
const { session } = copy.engine;
|
|
@@ -1998,7 +2011,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
|
|
|
1998
2011
|
const unsubscribe = session.onCommitted(({ ops }) => operations.push(...ops));
|
|
1999
2012
|
let resolved;
|
|
2000
2013
|
try {
|
|
2001
|
-
for (const suggestionId of staged) copy.resolveSuggestionOnSession(session, suggestionId, view === "final" ? "accept" : "reject", this.author);
|
|
2014
|
+
for (const suggestionId of staged) copy.resolveSuggestionOnSession(session, suggestionId, view === "final" ? "accept" : "reject", this.author, reaching.has(suggestionId) ? canonicalOpStory(story) : void 0);
|
|
2002
2015
|
const after = copy.getEditableStoryState(story);
|
|
2003
2016
|
if (after && copy.pendingSuggestionIdsForStory(story, after).size > 0) throw canonicalReviewerRefusal("resolve a story holding a suggestion the session will not resolve");
|
|
2004
2017
|
resolved = copy.resolveStoryOnSession(session, story, view);
|
|
@@ -2006,6 +2019,10 @@ var FolioDocxReviewer = class FolioDocxReviewer {
|
|
|
2006
2019
|
unsubscribe();
|
|
2007
2020
|
}
|
|
2008
2021
|
if (operations.length > 0) this.commitOpsOnSession(operations);
|
|
2022
|
+
this.pendingSuggestions.forgetStoryRecords({
|
|
2023
|
+
story,
|
|
2024
|
+
suggestionIds: reaching
|
|
2025
|
+
});
|
|
2009
2026
|
return resolved;
|
|
2010
2027
|
}
|
|
2011
2028
|
/**
|
|
@@ -99,6 +99,15 @@ export declare class FolioPendingSuggestionRegistry {
|
|
|
99
99
|
clone(): FolioPendingSuggestionRegistry;
|
|
100
100
|
/** Every suggestion id a record names. */
|
|
101
101
|
suggestionIds(): Set<string>;
|
|
102
|
+
/**
|
|
103
|
+
* Forget a story's records of suggestions resolved in that story alone.
|
|
104
|
+
* Their records in other stories stay, and so does a record that is the
|
|
105
|
+
* last one its suggestion has.
|
|
106
|
+
*/
|
|
107
|
+
forgetStoryRecords({ story, suggestionIds }: {
|
|
108
|
+
story: FolioDocumentStoryHandle;
|
|
109
|
+
suggestionIds: ReadonlySet<string>;
|
|
110
|
+
}): void;
|
|
102
111
|
/**
|
|
103
112
|
* Anchor every live record whose paragraph is gone from its story, a
|
|
104
113
|
* resolution or an edit having removed it, where a save keeps its
|
|
@@ -562,6 +562,17 @@ var FolioPendingSuggestionRegistry = class FolioPendingSuggestionRegistry {
|
|
|
562
562
|
return new Set([...this.records.values()].map(({ suggestionId }) => suggestionId));
|
|
563
563
|
}
|
|
564
564
|
/**
|
|
565
|
+
* Forget a story's records of suggestions resolved in that story alone.
|
|
566
|
+
* Their records in other stories stay, and so does a record that is the
|
|
567
|
+
* last one its suggestion has.
|
|
568
|
+
*/
|
|
569
|
+
forgetStoryRecords({ story, suggestionIds }) {
|
|
570
|
+
const storyKey = canonicalJson(story);
|
|
571
|
+
const recordedElsewhere = new Set([...this.records.values()].flatMap(({ suggestionId, story: other }) => canonicalJson(other) === storyKey ? [] : [suggestionId]));
|
|
572
|
+
for (const [key, record] of this.records) if (canonicalJson(record.story) === storyKey && suggestionIds.has(record.suggestionId) && recordedElsewhere.has(record.suggestionId)) this.records.delete(key);
|
|
573
|
+
if (![...this.records.values()].some((record) => canonicalJson(record.story) === storyKey)) this.sourceFingerprints.delete(storyKey);
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
565
576
|
* Anchor every live record whose paragraph is gone from its story, a
|
|
566
577
|
* resolution or an edit having removed it, where a save keeps its
|
|
567
578
|
* suggestion: a split at its own paragraph mark, text proposals over the
|
package/dist/ai-edits/read.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expectParagraphAttrs, expectRunPropertyChangeMarkAttrs, expectTrackedChangeMarkAttrs } from "../prosemirror/attrs/index.js";
|
|
2
|
-
import { getFolioNodeRevisionCarriers } from "../prosemirror/revisionCarriers.js";
|
|
2
|
+
import { getFolioNodeRevisionCarriers, propertyRevisionMetadata } from "../prosemirror/revisionCarriers.js";
|
|
3
3
|
import { expandRunFormattingCarrier, runFormattingCarrierReviewText, runFormattingInlineAtomCleanText, runFormattingInlineAtomDisposition, runFormattingInlineAtomResultText } from "../prosemirror/runFormattingInlineCarriers.js";
|
|
4
4
|
import { getTableCellMergeChange } from "../prosemirror/tableCellMergeRevision.js";
|
|
5
5
|
import { isTableRowRevisionCompanion } from "../prosemirror/tableRowRevisionOwnership.js";
|
|
@@ -323,6 +323,29 @@ const getTrackedChangeGroupsFromProjectedDoc = (doc, blockStarts, revisionRanges
|
|
|
323
323
|
const change = getTableCellMergeChange(continuationCell);
|
|
324
324
|
if (!change) {
|
|
325
325
|
if (!isRecord(continuationCell)) continue;
|
|
326
|
+
const properties = continuationCell["propertyChanges"];
|
|
327
|
+
if (Array.isArray(properties)) for (const property of properties) {
|
|
328
|
+
if (!isRecord(property)) continue;
|
|
329
|
+
const metadata = propertyRevisionMetadata(property["info"]);
|
|
330
|
+
if (metadata === null || continuationRevisionsOwnedByRows.has(metadata.id)) continue;
|
|
331
|
+
const type = "cellPropertiesChanged";
|
|
332
|
+
revisionRanges?.push({
|
|
333
|
+
type,
|
|
334
|
+
author: metadata.author,
|
|
335
|
+
from: pos,
|
|
336
|
+
to: pos + node.nodeSize
|
|
337
|
+
});
|
|
338
|
+
grouped.set(`continuation:${String(pos)}:${metadata.id}`, {
|
|
339
|
+
...metadata,
|
|
340
|
+
type,
|
|
341
|
+
text: "",
|
|
342
|
+
blockId: firstBlockIdWithin({
|
|
343
|
+
node,
|
|
344
|
+
nodePos: pos,
|
|
345
|
+
blockStarts
|
|
346
|
+
})
|
|
347
|
+
});
|
|
348
|
+
}
|
|
326
349
|
const structuralChange = continuationCell["structuralChange"];
|
|
327
350
|
if (!isRecord(structuralChange)) continue;
|
|
328
351
|
const kind = structuralChange["type"];
|
|
@@ -176,12 +176,20 @@ const propertyChangeFor = ({ base, target, position, scope, anchorParaId }) => {
|
|
|
176
176
|
anchorParaId
|
|
177
177
|
};
|
|
178
178
|
};
|
|
179
|
-
/**
|
|
179
|
+
/**
|
|
180
|
+
* The paragraph id of the last paragraph in a cell, through the block content
|
|
181
|
+
* controls and other wrappers around it but outside any nested table: a
|
|
182
|
+
* table operation addressed by a paragraph selects the innermost table that
|
|
183
|
+
* holds it, even through block wrappers.
|
|
184
|
+
*/
|
|
180
185
|
const cellAnchorParaId = (cell) => {
|
|
181
186
|
let paraId;
|
|
182
|
-
cell.
|
|
183
|
-
|
|
184
|
-
if (
|
|
187
|
+
cell.descendants((node) => {
|
|
188
|
+
if (node.type.name === "table") return false;
|
|
189
|
+
if (node.type.name !== "paragraph") return true;
|
|
190
|
+
const id = node.attrs["paraId"];
|
|
191
|
+
if (typeof id === "string") paraId = id;
|
|
192
|
+
return false;
|
|
185
193
|
});
|
|
186
194
|
return paraId;
|
|
187
195
|
};
|
|
@@ -63,7 +63,7 @@ export declare const CANONICAL_NATIVE_INLINE_POLICIES: {
|
|
|
63
63
|
readonly sdt: "control";
|
|
64
64
|
};
|
|
65
65
|
declare const InlineProjectionErrorBase: TaggedErrorClass<"InlineProjectionError">;
|
|
66
|
-
declare class InlineProjectionError extends InlineProjectionErrorBase<{
|
|
66
|
+
export declare class InlineProjectionError extends InlineProjectionErrorBase<{
|
|
67
67
|
message: string;
|
|
68
68
|
}> {}
|
|
69
69
|
/** Every source variant makes a decision before conversion can discard its positions. */
|
|
@@ -109,7 +109,7 @@ export type CanonicalInlineCommentContext = {
|
|
|
109
109
|
/** The comment ranges open where the paragraph starts. */
|
|
110
110
|
openIds: ReadonlySet<number>;
|
|
111
111
|
};
|
|
112
|
-
type CanonicalInlineProjectionArgs = {
|
|
112
|
+
export type CanonicalInlineProjectionArgs = {
|
|
113
113
|
source: document_d_exports.Paragraph;
|
|
114
114
|
paragraph: Node;
|
|
115
115
|
pairedBookmarkIds: StoryIdMembership;
|
|
@@ -359,7 +359,7 @@ const commentMarkTransitions = ({ source, paragraph, commentContext, explicitCom
|
|
|
359
359
|
previous = current;
|
|
360
360
|
};
|
|
361
361
|
const visit = (node, position) => {
|
|
362
|
-
if (issue !== void 0) return;
|
|
362
|
+
if (issue !== void 0 || node.type.name === "commentRangeBoundary") return;
|
|
363
363
|
if (nativePolicies.get(node.type.name) === "control" && node.childCount > 0) {
|
|
364
364
|
node.forEach((child, offset) => visit(child, position + 1 + offset));
|
|
365
365
|
return;
|
|
@@ -666,4 +666,4 @@ var InlineProjectionCache = class {
|
|
|
666
666
|
return projected;
|
|
667
667
|
}
|
|
668
668
|
};
|
|
669
|
-
export { CANONICAL_NATIVE_INLINE_POLICIES, CANONICAL_SOURCE_INLINE_POLICIES, InlineProjectionCache, canonicalInlineSourceIssue, canonicalNativeCells, projectCanonicalInline };
|
|
669
|
+
export { CANONICAL_NATIVE_INLINE_POLICIES, CANONICAL_SOURCE_INLINE_POLICIES, InlineProjectionCache, InlineProjectionError, canonicalInlineSourceIssue, canonicalNativeCells, projectCanonicalInline };
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { ParagraphCommentMarkers } from "../docx/commentAnchorIndex.js";
|
|
12
12
|
import { document_d_exports } from "../types/document.js";
|
|
13
13
|
import { CanonicalInlineGaps } from "./canonicalInlineGaps.js";
|
|
14
|
+
import { Result } from "better-result";
|
|
14
15
|
import { Node } from "prosemirror-model";
|
|
15
16
|
export type ParagraphAddress = {
|
|
16
17
|
blockId: string;
|
|
@@ -22,6 +23,8 @@ export type ParagraphAddress = {
|
|
|
22
23
|
node: Node;
|
|
23
24
|
source: document_d_exports.Paragraph;
|
|
24
25
|
};
|
|
26
|
+
/** A paragraph's text and the editor positions of each of its offsets. */
|
|
27
|
+
export type ParagraphInline = Pick<ParagraphAddress, "text" | "gaps">;
|
|
25
28
|
/** A paragraph as the top-level block holding it projects it. */
|
|
26
29
|
export type BlockParagraph = {
|
|
27
30
|
blockId: string;
|
|
@@ -29,7 +32,13 @@ export type BlockParagraph = {
|
|
|
29
32
|
container: readonly document_d_exports.BlockContent[] | undefined;
|
|
30
33
|
/** From the start of the top-level node holding it. */
|
|
31
34
|
offset: number;
|
|
32
|
-
|
|
35
|
+
/**
|
|
36
|
+
* The paragraph's text and gaps, worked out on the first call: a
|
|
37
|
+
* projection that opens a story aligns each paragraph's source with its
|
|
38
|
+
* editor node only when the paragraph is first addressed. The message
|
|
39
|
+
* says why the two do not align.
|
|
40
|
+
*/
|
|
41
|
+
inline: () => Result<ParagraphInline, string>;
|
|
33
42
|
node: Node;
|
|
34
43
|
source: document_d_exports.Paragraph;
|
|
35
44
|
};
|
|
@@ -31,11 +31,11 @@ import { standaloneTableRowsFromProseMirror, tableAttrsToFormatting } from "../p
|
|
|
31
31
|
import { insertionGap } from "../prosemirror/insertionGaps.js";
|
|
32
32
|
import { ensureParaIdsInDoc } from "../prosemirror/paraIds.js";
|
|
33
33
|
import { forEachAnnotationIdInDoc } from "../prosemirror/plugins/revisionIds.js";
|
|
34
|
-
import {
|
|
34
|
+
import { surveyAcceptedReplacedAnnotations } from "../prosemirror/replacedAnnotations.js";
|
|
35
35
|
import { createStyleResolver } from "../prosemirror/styles/styleResolver.js";
|
|
36
36
|
import { insertedColumnWidth, omittedSlotTakingColumn } from "../prosemirror/tableGridMutation.js";
|
|
37
37
|
import { paragraphGoes, tableGoes } from "../prosemirror/tableRunIn.js";
|
|
38
|
-
import { CANONICAL_CONDITION,
|
|
38
|
+
import { CANONICAL_CONDITION, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
|
|
39
39
|
import { readModel } from "../types/documentModel.js";
|
|
40
40
|
import { batchCommentReferenceShift, mapIntentPositions } from "./batchCommentReferences.js";
|
|
41
41
|
import { createCanonicalBatchReview } from "./canonicalBatchReview.js";
|
|
@@ -2107,10 +2107,14 @@ const resolveTableStructure = ({ operation, paragraph, projection, story, refusa
|
|
|
2107
2107
|
left: cell.leftColumnIndex,
|
|
2108
2108
|
right: cell.leftColumnIndex + 1
|
|
2109
2109
|
};
|
|
2110
|
-
if (tracked
|
|
2111
|
-
const
|
|
2112
|
-
|
|
2113
|
-
|
|
2110
|
+
if (tracked) {
|
|
2111
|
+
const spans = Array.from({ length: map.height }, (_, rowIndex) => {
|
|
2112
|
+
const position = map.map[rowIndex * map.width + column.left];
|
|
2113
|
+
const node = position === void 0 ? null : row.table.nodeAt(position);
|
|
2114
|
+
return node === null || node.attrs["_omittedGridSlot"] != null ? 0 : Number(node.attrs["colspan"] ?? 1);
|
|
2115
|
+
});
|
|
2116
|
+
if (spans.includes(1) && spans.some((span) => span > 1)) return skipTracked("A suggested column deletion cannot narrow a cell that spans other columns.");
|
|
2117
|
+
}
|
|
2114
2118
|
const at = tableAnchor({
|
|
2115
2119
|
map,
|
|
2116
2120
|
table: row.table,
|
|
@@ -2129,7 +2133,7 @@ const resolveTableStructure = ({ operation, paragraph, projection, story, refusa
|
|
|
2129
2133
|
deleted,
|
|
2130
2134
|
skipsCell: (cellPosition) => {
|
|
2131
2135
|
const rect = map.findCell(cellPosition - row.tableStart);
|
|
2132
|
-
return rect.left
|
|
2136
|
+
return rect.left >= column.left && rect.right <= column.right;
|
|
2133
2137
|
}
|
|
2134
2138
|
}) ?? address.blockId : address.blockId;
|
|
2135
2139
|
return resolved({
|
|
@@ -4885,8 +4889,7 @@ var CanonicalPublicOperations = class {
|
|
|
4885
4889
|
placed.push({
|
|
4886
4890
|
...change,
|
|
4887
4891
|
from: gap.from,
|
|
4888
|
-
to: afterLast === void 0 ? gap.to : Math.max(gap.from, Math.min(gap.to, afterLast))
|
|
4889
|
-
markers: "retained"
|
|
4892
|
+
to: afterLast === void 0 ? gap.to : Math.max(gap.from, Math.min(gap.to, afterLast))
|
|
4890
4893
|
});
|
|
4891
4894
|
}
|
|
4892
4895
|
return placed;
|
|
@@ -4908,35 +4911,6 @@ var CanonicalPublicOperations = class {
|
|
|
4908
4911
|
if (whole === void 0) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
4909
4912
|
replacementChanges = whole;
|
|
4910
4913
|
}
|
|
4911
|
-
const comments = readModel(this.options.session.document).package.document.comments ?? [];
|
|
4912
|
-
let retiredCommentIds;
|
|
4913
|
-
if (!tracked) {
|
|
4914
|
-
const split = splitAtKeptCommentBoundaries({
|
|
4915
|
-
doc: state.doc,
|
|
4916
|
-
changes: replacementChanges,
|
|
4917
|
-
comments
|
|
4918
|
-
});
|
|
4919
|
-
replacementChanges = split.changes;
|
|
4920
|
-
retiredCommentIds = split.retiredCommentIds;
|
|
4921
|
-
}
|
|
4922
|
-
if (!preservesReplacementCommentAlignment({
|
|
4923
|
-
doc: state.doc,
|
|
4924
|
-
source: {
|
|
4925
|
-
from: paragraph.start,
|
|
4926
|
-
to: paragraph.start + paragraph.node.content.size
|
|
4927
|
-
},
|
|
4928
|
-
changes: replacementChanges,
|
|
4929
|
-
retiredCommentIds,
|
|
4930
|
-
removal: tracked ? { type: suggested ? "suggested" : "tracked" } : {
|
|
4931
|
-
type: "direct",
|
|
4932
|
-
comments
|
|
4933
|
-
}
|
|
4934
|
-
})) return Result.err(new CanonicalPublicOperationResolutionError({
|
|
4935
|
-
reason: "unsupportedBlock",
|
|
4936
|
-
ground: { gap: CANONICAL_GAP.commentReplacementAlignment },
|
|
4937
|
-
message: "Canonical replacement cannot preserve the aligned comment ranges.",
|
|
4938
|
-
detail: "Canonical replacement cannot preserve the aligned comment ranges."
|
|
4939
|
-
}));
|
|
4940
4914
|
if (tracked && !suggested) deletionSpans = replacementChanges.filter((span) => span.from < span.to);
|
|
4941
4915
|
if (intent.runPropsPatch !== void 0) {
|
|
4942
4916
|
const nodeAtCharacter = (index) => {
|
|
@@ -5134,6 +5108,7 @@ var CanonicalPublicOperations = class {
|
|
|
5134
5108
|
}));
|
|
5135
5109
|
} else intents.push(intent);
|
|
5136
5110
|
const nextParagraph = operation.type === "mergeBlockWithNext" && intent.type === "joinParagraphs" ? projection.value.paragraph(intent.nextBlockId) : void 0;
|
|
5111
|
+
if (operation.type === "mergeBlockWithNext" && intent.type === "joinParagraphs" && nextParagraph === void 0) return refusal("unsupportedBlock", void 0, INVALID_REQUEST);
|
|
5137
5112
|
let claimedTo = range.to;
|
|
5138
5113
|
if (operation.type === "mergeBlockWithNext") claimedTo = paragraph.start + paragraph.node.content.size;
|
|
5139
5114
|
if (nextParagraph) claimedTo = nextParagraph.start + nextParagraph.node.content.size;
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
2
|
import { OpStory } from "@stll/docx-core/ops";
|
|
3
|
+
/**
|
|
4
|
+
* What makes a story one the session cannot hold:
|
|
5
|
+
*
|
|
6
|
+
* - `comments`: the comments and their anchors are not a valid set, as
|
|
7
|
+
* `commentDocumentIssue` judges them;
|
|
8
|
+
* - `emptyStory`: a story holds no block;
|
|
9
|
+
* - `content`: a block or inline item no document operation writes, such as
|
|
10
|
+
* unstructured field characters or text holding a tab or a line feed. The
|
|
11
|
+
* reader keeps loose field markup as preserved XML, so only a document
|
|
12
|
+
* built by hand holds one.
|
|
13
|
+
*/
|
|
14
|
+
export type CanonicalSeedIssue = {
|
|
15
|
+
kind: "comments" | "emptyStory" | "content";
|
|
16
|
+
message: string;
|
|
17
|
+
};
|
|
3
18
|
/**
|
|
4
19
|
* Why the session cannot hold these stories of `document`, or `null`: the
|
|
5
20
|
* first block it cannot hold, else the first paragraph whose content it
|
|
6
21
|
* cannot hold, in each story in turn.
|
|
7
22
|
*/
|
|
8
|
-
export declare const unsupportedSeedReason: (document: document_d_exports.Document, stories?: OpStory[]) =>
|
|
23
|
+
export declare const unsupportedSeedReason: (document: document_d_exports.Document, stories?: OpStory[]) => CanonicalSeedIssue | null;
|
|
9
24
|
/** The blocks of a story an edit replaced, and the ones it put in their place. */
|
|
10
25
|
export declare const changedWindow: (before: readonly document_d_exports.BlockContent[], after: readonly document_d_exports.BlockContent[]) => {
|
|
11
26
|
removed: readonly document_d_exports.BlockContent[];
|
|
@@ -27,10 +42,10 @@ type UnsupportedEditOptions = {
|
|
|
27
42
|
* and the stories are the ones `previous` had and each story's replaced
|
|
28
43
|
* blocks carried the anchors its new blocks carry, it stays as it was.
|
|
29
44
|
*/
|
|
30
|
-
export declare const unsupportedEditReason: ({ previous, document, stories }: UnsupportedEditOptions) =>
|
|
45
|
+
export declare const unsupportedEditReason: ({ previous, document, stories }: UnsupportedEditOptions) => CanonicalSeedIssue | null;
|
|
31
46
|
/**
|
|
32
47
|
* The same verdict from one walk of every story, judging nothing once: the
|
|
33
48
|
* reference the block judgments above must equal.
|
|
34
49
|
*/
|
|
35
|
-
export declare const unsupportedSeedReasonWholeDocument: (document: document_d_exports.Document, stories?: OpStory[]) =>
|
|
50
|
+
export declare const unsupportedSeedReasonWholeDocument: (document: document_d_exports.Document, stories?: OpStory[]) => CanonicalSeedIssue | null;
|
|
36
51
|
export {};
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import { canonicalInlineSourceIssue } from "./canonicalInlineProjection.js";
|
|
2
2
|
import { OP_STORIES, commentAnchorSequence, commentDocumentIssue, documentStories, findStoryBody } from "@stll/docx-core/ops";
|
|
3
3
|
// src/canonical/canonicalSeedContent.ts
|
|
4
|
-
const STRUCTURE_ISSUE =
|
|
5
|
-
|
|
4
|
+
const STRUCTURE_ISSUE = {
|
|
5
|
+
kind: "content",
|
|
6
|
+
message: "Canonical sessions currently require paragraphs, tables and supported inline atoms."
|
|
7
|
+
};
|
|
8
|
+
const EMPTY_STORY_ISSUE = {
|
|
9
|
+
kind: "emptyStory",
|
|
10
|
+
message: "Canonical sessions require a nonempty paragraph story."
|
|
11
|
+
};
|
|
12
|
+
const contentIssue = (message) => message === null ? null : {
|
|
13
|
+
kind: "content",
|
|
14
|
+
message
|
|
15
|
+
};
|
|
16
|
+
const commentIssueOf = (message) => message === void 0 ? null : {
|
|
17
|
+
kind: "comments",
|
|
18
|
+
message
|
|
19
|
+
};
|
|
6
20
|
/** Range markers may open or close between blocks; they hold no text. */
|
|
7
21
|
const BETWEEN_BLOCK_MARKERS = /* @__PURE__ */ new Set([
|
|
8
22
|
"commentRangeStart",
|
|
@@ -40,7 +54,7 @@ const issuesIn = (block) => {
|
|
|
40
54
|
const structure = collect([block]);
|
|
41
55
|
let paragraph = null;
|
|
42
56
|
for (const candidate of paragraphs) {
|
|
43
|
-
paragraph =
|
|
57
|
+
paragraph = contentIssue(canonicalInlineSourceIssue(candidate.content));
|
|
44
58
|
if (paragraph !== null) break;
|
|
45
59
|
}
|
|
46
60
|
return {
|
|
@@ -63,8 +77,8 @@ const issuesOf = (block) => {
|
|
|
63
77
|
* cannot hold, in each story in turn.
|
|
64
78
|
*/
|
|
65
79
|
const unsupportedSeedReason = (document, stories = documentStories(document)) => {
|
|
66
|
-
const commentIssue = commentDocumentIssue(document, "all");
|
|
67
|
-
if (commentIssue !==
|
|
80
|
+
const commentIssue = commentIssueOf(commentDocumentIssue(document, "all"));
|
|
81
|
+
if (commentIssue !== null) return commentIssue;
|
|
68
82
|
for (const story of stories) {
|
|
69
83
|
const body = findStoryBody(document, story);
|
|
70
84
|
if (story !== OP_STORIES.MAIN && (story.kind === "footnote" || story.kind === "endnote")) {
|
|
@@ -72,7 +86,7 @@ const unsupportedSeedReason = (document, stories = documentStories(document)) =>
|
|
|
72
86
|
if (note?.noteType !== void 0 && note.noteType !== "normal") continue;
|
|
73
87
|
}
|
|
74
88
|
const content = body?.content;
|
|
75
|
-
if (!content || content.length === 0) return
|
|
89
|
+
if (!content || content.length === 0) return EMPTY_STORY_ISSUE;
|
|
76
90
|
const issues = content.map(issuesOf);
|
|
77
91
|
const structure = issues.find((issue) => issue.structure !== null);
|
|
78
92
|
if (structure !== void 0) return structure.structure;
|
|
@@ -115,12 +129,12 @@ const unsupportedEditReason = ({ previous, document, stories }) => {
|
|
|
115
129
|
...changedWindow(findStoryBody(previous, story)?.content ?? [], findStoryBody(document, story)?.content ?? [])
|
|
116
130
|
}));
|
|
117
131
|
if (!(document.package.document.comments === previous.package.document.comments && documentStories(document).length === documentStories(previous).length && windows.every(({ removed, added }) => sameSequence(commentAnchorSequence(removed), commentAnchorSequence(added))))) {
|
|
118
|
-
const commentIssue = commentDocumentIssue(document, "all");
|
|
119
|
-
if (commentIssue !==
|
|
132
|
+
const commentIssue = commentIssueOf(commentDocumentIssue(document, "all"));
|
|
133
|
+
if (commentIssue !== null) return commentIssue;
|
|
120
134
|
}
|
|
121
135
|
for (const { story, content, added } of windows) {
|
|
122
136
|
if (skippedNote(document, story)) continue;
|
|
123
|
-
if (!content || content.length === 0) return
|
|
137
|
+
if (!content || content.length === 0) return EMPTY_STORY_ISSUE;
|
|
124
138
|
const issues = added.map(issuesOf);
|
|
125
139
|
const structure = issues.find((issue) => issue.structure !== null);
|
|
126
140
|
if (structure !== void 0) return structure.structure;
|
|
@@ -134,8 +148,8 @@ const unsupportedEditReason = ({ previous, document, stories }) => {
|
|
|
134
148
|
* reference the block judgments above must equal.
|
|
135
149
|
*/
|
|
136
150
|
const unsupportedSeedReasonWholeDocument = (document, stories = documentStories(document)) => {
|
|
137
|
-
const commentIssue = commentDocumentIssue(document, "all");
|
|
138
|
-
if (commentIssue !==
|
|
151
|
+
const commentIssue = commentIssueOf(commentDocumentIssue(document, "all"));
|
|
152
|
+
if (commentIssue !== null) return commentIssue;
|
|
139
153
|
for (const story of stories) {
|
|
140
154
|
const body = findStoryBody(document, story);
|
|
141
155
|
if (story !== OP_STORIES.MAIN && (story.kind === "footnote" || story.kind === "endnote")) {
|
|
@@ -143,7 +157,7 @@ const unsupportedSeedReasonWholeDocument = (document, stories = documentStories(
|
|
|
143
157
|
if (note?.noteType !== void 0 && note.noteType !== "normal") continue;
|
|
144
158
|
}
|
|
145
159
|
const content = body?.content;
|
|
146
|
-
if (!content || content.length === 0) return
|
|
160
|
+
if (!content || content.length === 0) return EMPTY_STORY_ISSUE;
|
|
147
161
|
const paragraphs = [];
|
|
148
162
|
const collect = (blocks) => {
|
|
149
163
|
for (const block of blocks) {
|
|
@@ -158,7 +172,7 @@ const unsupportedSeedReasonWholeDocument = (document, stories = documentStories(
|
|
|
158
172
|
if (issue !== null) return issue;
|
|
159
173
|
continue;
|
|
160
174
|
}
|
|
161
|
-
if (block.type !== "table") return
|
|
175
|
+
if (block.type !== "table") return STRUCTURE_ISSUE;
|
|
162
176
|
for (const row of block.rows) for (const cell of row.cells) {
|
|
163
177
|
const issue = collect(cell.content);
|
|
164
178
|
if (issue !== null) return issue;
|
|
@@ -169,8 +183,7 @@ const unsupportedSeedReasonWholeDocument = (document, stories = documentStories(
|
|
|
169
183
|
const blockIssue = collect(content);
|
|
170
184
|
if (blockIssue !== null) return blockIssue;
|
|
171
185
|
for (const paragraph of paragraphs) {
|
|
172
|
-
|
|
173
|
-
const issue = canonicalInlineSourceIssue(paragraph.content);
|
|
186
|
+
const issue = contentIssue(canonicalInlineSourceIssue(paragraph.content));
|
|
174
187
|
if (issue !== null) return issue;
|
|
175
188
|
}
|
|
176
189
|
}
|