@stll/folio-core 0.73.0 → 0.75.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/clean-text.d.ts +4 -1
- package/dist/ai-edits/clean-text.js +21 -7
- package/dist/ai-edits/headless.d.ts +5 -2
- package/dist/ai-edits/headless.js +20 -14
- package/dist/ai-edits/note-references.d.ts +1 -1
- package/dist/ai-edits/note-references.js +1 -1
- package/dist/ai-edits/pending-suggestions.d.ts +9 -7
- package/dist/ai-edits/pending-suggestions.js +134 -88
- package/dist/ai-edits/pendingJoin.d.ts +5 -1
- package/dist/ai-edits/pendingJoin.js +12 -3
- package/dist/ai-edits/result-validation.js +1 -1
- package/dist/ai-edits/retired-comment-receipts.d.ts +2 -2
- package/dist/ai-edits/retired-comment-receipts.js +3 -18
- package/dist/ai-edits/snapshot.js +1 -1
- package/dist/ai-edits/table-cell-mutations.js +1 -1
- package/dist/ai-edits/tracked-batch-fidelity.d.ts +6 -10
- package/dist/ai-edits/tracked-batch-fidelity.js +3 -182
- package/dist/canonical/canonicalBatchReview.d.ts +4 -1
- package/dist/canonical/canonicalBatchReview.js +32 -14
- package/dist/canonical/canonicalComments.d.ts +6 -2
- package/dist/canonical/canonicalComments.js +8 -4
- package/dist/canonical/canonicalInlineGaps.d.ts +56 -0
- package/dist/canonical/canonicalInlineGaps.js +118 -0
- package/dist/canonical/canonicalInlineProjection.d.ts +4 -13
- package/dist/canonical/canonicalInlineProjection.js +6 -28
- package/dist/canonical/canonicalProjectionBlocks.d.ts +4 -4
- package/dist/canonical/canonicalPublicOperations.js +99 -36
- package/dist/canonical/canonicalRefusalGrounds.d.ts +4 -0
- package/dist/canonical/canonicalRefusalGrounds.js +56 -0
- package/dist/canonical/canonicalSelection.js +1 -1
- package/dist/canonical/canonicalSession.d.ts +12 -6
- package/dist/canonical/canonicalSession.js +129 -141
- package/dist/canonical/canonicalTrackedBatchFidelity.js +3 -3
- package/dist/compare/inline-atoms.d.ts +35 -41
- package/dist/compare/inline-atoms.js +2 -465
- package/dist/compare/section-boundary-properties.d.ts +3 -30
- package/dist/compare/section-boundary-properties.js +4 -72
- package/dist/controller/autocompleteSuggestion.js +1 -1
- package/dist/controller/canonicalClipboard.js +45 -44
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +6 -6
- package/dist/controller/canonicalInput.d.ts +4 -2
- package/dist/controller/canonicalInput.js +34 -17
- package/dist/controller/canonicalPresence.js +1 -1
- package/dist/controller/canonicalRoomAuthority.js +1 -1
- package/dist/controller/canonicalRoomWire.js +1 -1
- package/dist/controller/canonicalStoryEditor.d.ts +2 -3
- package/dist/controller/canonicalStoryEditor.js +43 -25
- package/dist/controller/canonicalStructure.d.ts +19 -2
- package/dist/controller/canonicalStructure.js +140 -43
- package/dist/controller/canonicalTabRoom.js +1 -1
- package/dist/controller/canonicalYjsRoom.js +1 -1
- package/dist/controller/deferredDisplayListPainter.d.ts +8 -0
- package/dist/controller/deferredDisplayListPainter.js +34 -0
- package/dist/controller/folioEditor.js +4 -2
- package/dist/controller/headerFooterEditorManager.js +3 -17
- package/dist/controller/hiddenEditorApi.d.ts +24 -3
- package/dist/controller/hiddenEditorApi.js +4 -17
- package/dist/controller/hiddenEditorManager.js +136 -197
- package/dist/controller/layoutPipeline.d.ts +4 -86
- package/dist/controller/layoutPipeline.js +8 -727
- package/dist/controller/layoutPipelineExecution.d.ts +94 -0
- package/dist/controller/layoutPipelineExecution.js +730 -0
- package/dist/controller/noteEditorManager.js +3 -16
- package/dist/document-operations.js +1 -1
- package/dist/docx/blockContentParser.d.ts +1 -3
- package/dist/docx/blockContentParser.js +3 -10
- package/dist/docx/canonicalSave.d.ts +4 -3
- package/dist/docx/canonicalSave.js +4 -3
- package/dist/docx/canonicalSessionInput.js +1 -1
- package/dist/docx/containerChildren.js +1 -1
- package/dist/docx/createDocx.d.ts +4 -0
- package/dist/docx/createDocx.js +6 -0
- package/dist/docx/listMarkerComputation.d.ts +24 -17
- package/dist/docx/listMarkerComputation.js +31 -60
- package/dist/docx/listModelNormalization.js +8 -15
- package/dist/docx/modelValidation.js +1 -1
- package/dist/docx/parser.js +1 -1
- package/dist/docx/reviewResolutionProvenance.js +1 -1
- package/dist/docx/rezip.d.ts +16 -3
- package/dist/docx/rezip.js +36 -10
- package/dist/docx/selectiveSave.js +13 -5
- package/dist/docx/serializer/borderSerializer.js +1 -1
- package/dist/docx/serializer/commentSerializer.js +1 -1
- package/dist/docx/serializer/documentSerializer.js +1 -1
- package/dist/docx/serializer/paragraphSerializer.js +3 -3
- package/dist/docx/serializer/runSerializer.js +1 -1
- package/dist/docx/serializer/sectionPropertiesSerializer.js +1 -1
- package/dist/docx/serializer/tableSerializer.js +1 -1
- package/dist/docx/serializer/textFormattingSerializer.js +1 -1
- package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
- package/dist/docx/server/templatePlan/apply.js +107 -14
- package/dist/docx/server/templatePlan/blocks.d.ts +16 -1
- package/dist/docx/server/templatePlan/blocks.js +93 -7
- package/dist/docx/server/templatePlan/builders.d.ts +37 -2
- package/dist/docx/server/templatePlan/builders.js +196 -5
- package/dist/docx/server/templatePlan/emit.d.ts +2 -0
- package/dist/docx/server/templatePlan/emit.js +2 -0
- package/dist/docx/server/templatePlan/inspect.js +81 -61
- package/dist/docx/server/templatePlan/labels.d.ts +16 -2
- package/dist/docx/server/templatePlan/labels.js +131 -20
- package/dist/docx/server/templatePlan/plan.d.ts +15 -1
- package/dist/docx/server/templatePlan/plan.js +62 -13
- package/dist/docx/server/templatePlan/planShape.js +52 -4
- package/dist/docx/server/templatePlan/story.d.ts +8 -0
- package/dist/docx/server/templatePlan/story.js +11 -1
- package/dist/docx/server/templatePlan/types.d.ts +176 -18
- package/dist/docx/server/templatePlan/types.js +1 -0
- package/dist/docx/server/templatePlan/verify.js +60 -11
- package/dist/docx/server/templatePlan/xml.d.ts +5 -0
- package/dist/docx/server/templatePlan/xml.js +7 -1
- package/dist/docx/storyBlockReplay.js +1 -1
- package/dist/docx/xmlParser.js +1 -1
- package/dist/i18n/loadMessages.d.ts +5 -0
- package/dist/i18n/loadMessages.js +46 -0
- package/dist/i18n/locales.d.ts +3 -0
- package/dist/i18n/locales.js +17 -0
- package/dist/i18n/messages/ar.gen.js +1 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
- package/dist/i18n/messages/catalogs.gen.js +17 -0
- package/dist/i18n/messages/cs.gen.js +1 -0
- package/dist/i18n/messages/de.gen.js +1 -0
- package/dist/i18n/messages/en.gen.js +1 -0
- package/dist/i18n/messages/es.gen.js +1 -0
- package/dist/i18n/messages/et.gen.js +1 -0
- package/dist/i18n/messages/fr.gen.js +1 -0
- package/dist/i18n/messages/he.gen.js +1 -0
- package/dist/i18n/messages/hi.gen.js +1 -0
- package/dist/i18n/messages/hu.gen.js +1 -0
- package/dist/i18n/messages/lt.gen.js +1 -0
- package/dist/i18n/messages/lv.gen.js +1 -0
- package/dist/i18n/messages/messages.gen.d.ts +1 -0
- package/dist/i18n/messages/pl.gen.js +1 -0
- package/dist/i18n/messages/pt-BR.gen.js +1 -0
- package/dist/i18n/messages/sk.gen.js +1 -0
- package/dist/i18n/messages/tr.gen.js +1 -0
- package/dist/i18n/messages/zh-CN.gen.js +1 -0
- package/dist/i18n/messages.d.ts +3 -2
- package/dist/i18n/messages.js +4 -16
- package/dist/internal/clipboardTransformPlugin.d.ts +3 -0
- package/dist/internal/clipboardTransformPlugin.js +13 -0
- package/dist/internal/extensionRuntime.d.ts +7 -0
- package/dist/internal/extensionRuntime.js +28 -0
- package/dist/internal/paragraphFormattingSerialization.js +1 -1
- package/dist/internal/starterKitExtensions.d.ts +20 -0
- package/dist/internal/starterKitExtensions.js +123 -0
- package/dist/internal/wholeStoryRevisionResolution.js +2 -2
- package/dist/layout-bridge/convert/toFlowBlocks.js +0 -12
- package/dist/layout-bridge/convert/topLevelConversion.js +1 -10
- package/dist/prosemirror/attrs/index.js +1 -1
- package/dist/prosemirror/canonicalSelectionRange.js +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +1 -1
- package/dist/prosemirror/commands/comments.js +3 -3
- package/dist/prosemirror/commands/contentControls.js +1 -1
- package/dist/prosemirror/commands/pastePlainText.js +2 -3
- package/dist/prosemirror/commands/replaceRangeText.js +1 -1
- package/dist/prosemirror/commentRecords.js +2 -2
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +0 -5
- package/dist/prosemirror/conversion/fromProseDoc.js +2 -9
- package/dist/prosemirror/conversion/index.d.ts +2 -2
- package/dist/prosemirror/conversion/index.js +2 -2
- package/dist/prosemirror/extensions/ExtensionManager.js +4 -22
- package/dist/prosemirror/extensions/StarterKit.d.ts +4 -27
- package/dist/prosemirror/extensions/StarterKit.js +29 -115
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +2 -2
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +1 -1
- package/dist/prosemirror/extensions/features/ListExtension.js +7 -2
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
- package/dist/prosemirror/extensions/index.d.ts +2 -1
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +8 -3
- package/dist/prosemirror/extensions/nodes/TableExtension.js +7 -40
- package/dist/prosemirror/hyperlinkRemoval.js +7 -2
- package/dist/prosemirror/index.d.ts +2 -2
- package/dist/prosemirror/index.js +2 -2
- package/dist/prosemirror/keptRangeBoundaries.js +1 -1
- package/dist/prosemirror/listMarker.d.ts +1 -6
- package/dist/prosemirror/listMarker.js +4 -56
- package/dist/prosemirror/listNumbering.js +1 -1
- package/dist/prosemirror/noteReferenceOccurrences.js +1 -1
- package/dist/prosemirror/noteReferenceReview.d.ts +2 -56
- package/dist/prosemirror/noteReferenceReview.js +2 -243
- package/dist/prosemirror/pastedCommentCopies.js +1 -1
- package/dist/prosemirror/plugins/documentNumbering.js +1 -1
- package/dist/prosemirror/plugins/documentStyles.js +1 -1
- package/dist/prosemirror/replacedAnnotations.js +1 -1
- package/dist/prosemirror/suggestionCommands.d.ts +47 -0
- package/dist/prosemirror/suggestionCommands.js +31 -0
- package/dist/prosemirror/tableCellPaste.js +1 -1
- package/dist/prosemirror/tableRunIn.js +1 -1
- package/dist/prosemirror/textInput.js +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +42 -93
- package/dist/types/canonicalCapabilities.js +53 -91
- package/dist/types/canonicalComments.d.ts +2 -2
- package/dist/types/canonicalSections.d.ts +2 -2
- package/dist/utils/clipboard.d.ts +2 -28
- package/dist/utils/clipboard.js +1 -96
- package/dist/utils/clipboardFiles.d.ts +27 -0
- package/dist/utils/clipboardFiles.js +98 -0
- package/dist/utils/rulerControl.d.ts +1 -0
- package/dist/utils/rulerControl.js +2 -1
- package/package.json +2 -2
- package/dist/ai-edits/apply.d.ts +0 -94
- package/dist/ai-edits/apply.js +0 -6637
- package/dist/ai-edits/note-story-inventory.d.ts +0 -5
- package/dist/ai-edits/note-story-inventory.js +0 -10
- package/dist/ai-edits/revisionStretches.d.ts +0 -32
- package/dist/ai-edits/revisionStretches.js +0 -147
- package/dist/document-operations-apply.d.ts +0 -15
- package/dist/document-operations-apply.js +0 -280
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +0 -12
- package/dist/prosemirror/extensions/core/HistoryExtension.js +0 -114
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +0 -23
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +0 -270
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +0 -51
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +0 -411
- package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -92
- package/dist/prosemirror/plugins/suggestionMode.js +0 -1515
- package/dist/prosemirror/tablePositionedBookmarks.d.ts +0 -8
- package/dist/prosemirror/tablePositionedBookmarks.js +0 -80
|
@@ -158,7 +158,11 @@ export type PendingMarkEditOptions = {
|
|
|
158
158
|
/** The paragraph's accepted reading. */
|
|
159
159
|
cleanText: string;
|
|
160
160
|
};
|
|
161
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
* The shared property boundary, independent of the paragraph's
|
|
163
|
+
* representation: any mark accepting removes, including one added and then
|
|
164
|
+
* deleted by another author, takes the edited properties with it.
|
|
165
|
+
*/
|
|
162
166
|
export declare const pendingParagraphPropertiesRefusal: (mark: unknown) => PendingRefusal | undefined;
|
|
163
167
|
/**
|
|
164
168
|
* The refusal an operation that places no block meets on a paragraph whose
|
|
@@ -8,6 +8,11 @@ import { buildCleanBlockText } from "./clean-text.js";
|
|
|
8
8
|
// src/ai-edits/pendingJoin.ts
|
|
9
9
|
/** A paragraph mark that is a pending deletion, or a relocation's source. */
|
|
10
10
|
const isDeletedPPrMark = (value) => typeof value === "object" && value !== null && "kind" in value && (value.kind === "del" || value.kind === "moveFrom");
|
|
11
|
+
/**
|
|
12
|
+
* A paragraph mark accepting removes: a deleted one, or an added one another
|
|
13
|
+
* author deleted after (`deletion`), as docx-core's `markGoes` reads it.
|
|
14
|
+
*/
|
|
15
|
+
const markGoesWhenAccepted = (value) => isDeletedPPrMark(value) || typeof value === "object" && value !== null && "deletion" in value && value.deletion !== void 0 && value.deletion !== null;
|
|
11
16
|
/** A table row's or cell's revision record. */
|
|
12
17
|
const hasRevisionMarker = (value) => typeof value === "object" && value !== null && "revisionId" in value;
|
|
13
18
|
/** Whether a table cell is pending deletion. */
|
|
@@ -28,7 +33,7 @@ const isDeletedCell = (cell) => {
|
|
|
28
33
|
* rejecting the deletion, which is the reviewer's call, not a side effect.
|
|
29
34
|
*/
|
|
30
35
|
const isPendingDeletion = (doc, blockFrom, paragraph, cleanText) => {
|
|
31
|
-
if (cleanText.length === 0 &&
|
|
36
|
+
if (cleanText.length === 0 && markGoesWhenAccepted(paragraph.attrs["pPrMark"])) return true;
|
|
32
37
|
const $block = doc.resolve(blockFrom);
|
|
33
38
|
for (let depth = $block.depth; depth > 0; depth -= 1) {
|
|
34
39
|
const ancestor = $block.node(depth);
|
|
@@ -257,8 +262,12 @@ const pendingMarkEditOf = (type) => {
|
|
|
257
262
|
if (type === "replaceBlock") return "wholeText";
|
|
258
263
|
return "inline";
|
|
259
264
|
};
|
|
260
|
-
/**
|
|
261
|
-
|
|
265
|
+
/**
|
|
266
|
+
* The shared property boundary, independent of the paragraph's
|
|
267
|
+
* representation: any mark accepting removes, including one added and then
|
|
268
|
+
* deleted by another author, takes the edited properties with it.
|
|
269
|
+
*/
|
|
270
|
+
const pendingParagraphPropertiesRefusal = (mark) => markGoesWhenAccepted(mark) ? PENDING_PARAGRAPH_MARK_PROPERTY_REFUSAL : void 0;
|
|
262
271
|
/**
|
|
263
272
|
* The refusal an operation that places no block meets on a paragraph whose
|
|
264
273
|
* mark is pending deletion, by the rules the default engine applies: its
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { proseDocToBlocks } from "../prosemirror/conversion/fromProseDoc.js";
|
|
2
2
|
import { sectionPropertiesOf } from "../prosemirror/sectionCarrier.js";
|
|
3
3
|
import { anchoredCommentIdsInProseDoc } from "./comment-lifecycle.js";
|
|
4
|
-
import { Fragment } from "prosemirror-model";
|
|
5
4
|
import { validateDocumentModel } from "@stll/docx-core";
|
|
5
|
+
import { Fragment } from "prosemirror-model";
|
|
6
6
|
// src/ai-edits/result-validation.ts
|
|
7
7
|
/**
|
|
8
8
|
* The check an operation batch's result passes before it is committed.
|
|
@@ -12,8 +12,8 @@ type RetiredCommentReceiptsOptions = {
|
|
|
12
12
|
operations: readonly Pick<FolioAIEditOperation, "id" | "type">[];
|
|
13
13
|
/** Canonical inline changes can relocate markers before later steps run. */
|
|
14
14
|
sourceRanges?: ReadonlyMap<string, readonly TextSpan[]>;
|
|
15
|
-
/**
|
|
16
|
-
acceptedCommentIds
|
|
15
|
+
/** Anchors in the accepted story on either side of the batch. */
|
|
16
|
+
acceptedCommentIds: (side: "before" | "after") => ReadonlySet<number> | null;
|
|
17
17
|
};
|
|
18
18
|
/** Report full anchor removal only where one operation owns the deletion. */
|
|
19
19
|
export declare const addRetiredCommentReceipts: ({ before, after, applied, operations, sourceRanges, acceptedCommentIds }: RetiredCommentReceiptsOptions) => void;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import { acceptAllChanges, rejectEverySuggestion } from "../prosemirror/commands/comments.js";
|
|
2
|
-
import { createDocumentNumberingPlugin, getStatedDocumentNumbering } from "../prosemirror/plugins/documentNumbering.js";
|
|
3
|
-
import { getDocumentStyleResolver } from "../prosemirror/plugins/documentStyleState.js";
|
|
4
|
-
import { createDocumentStyleContextPlugin } from "../prosemirror/plugins/documentStyles.js";
|
|
5
1
|
import { isZeroWidthAnchor } from "../prosemirror/zeroWidthAnchors.js";
|
|
6
|
-
import {
|
|
2
|
+
import { commentAnchorIdsForNode, coveredCommentIdsInProseDoc, isCommentAnchorCarrier } from "./comment-lifecycle.js";
|
|
7
3
|
import { comparisonApplying } from "./note-references.js";
|
|
8
|
-
import { EditorState } from "prosemirror-state";
|
|
9
4
|
// src/ai-edits/retired-comment-receipts.ts
|
|
10
5
|
const deletionOperations = /* @__PURE__ */ new Set([
|
|
11
6
|
"deleteBlock",
|
|
@@ -26,16 +21,6 @@ const deletedParagraphMark = (node) => {
|
|
|
26
21
|
const marker = node.attrs["pPrMark"];
|
|
27
22
|
return objectAttr(marker, "kind") === "del" ? objectAttr(marker, "info") : void 0;
|
|
28
23
|
};
|
|
29
|
-
const acceptedComments = (before, doc) => {
|
|
30
|
-
const state = rejectEverySuggestion(EditorState.create({
|
|
31
|
-
doc,
|
|
32
|
-
plugins: [createDocumentNumberingPlugin(getStatedDocumentNumbering(before)), createDocumentStyleContextPlugin(getDocumentStyleResolver(before))]
|
|
33
|
-
}));
|
|
34
|
-
let accepted = state.doc;
|
|
35
|
-
return acceptAllChanges()(state, (transaction) => {
|
|
36
|
-
accepted = transaction.doc;
|
|
37
|
-
}) ? anchoredCommentIdsInProseDoc(accepted) : null;
|
|
38
|
-
};
|
|
39
24
|
const candidatesOf = (coverage) => [...coverage].flatMap(([commentId, owner]) => owner === null ? [] : [{
|
|
40
25
|
commentId,
|
|
41
26
|
owner
|
|
@@ -147,8 +132,8 @@ const addRetiredCommentReceipts = ({ before, after, applied, operations, sourceR
|
|
|
147
132
|
const covering = candidates.filter(({ commentId, owner }) => ownsOriginalCoverage(commentId, owner));
|
|
148
133
|
const owned = covering.filter(({ commentId }) => !foldedComments.has(commentId) || covering.filter((candidate) => candidate.commentId === commentId).length === 1);
|
|
149
134
|
if (owned.length === 0) return;
|
|
150
|
-
const originallyAccepted = acceptedCommentIds
|
|
151
|
-
const finallyAccepted = acceptedCommentIds
|
|
135
|
+
const originallyAccepted = acceptedCommentIds("before");
|
|
136
|
+
const finallyAccepted = acceptedCommentIds("after");
|
|
152
137
|
if (originallyAccepted === null || finallyAccepted === null) return;
|
|
153
138
|
const byOperation = /* @__PURE__ */ new Map();
|
|
154
139
|
for (const { commentId, owner } of owned) {
|
|
@@ -21,8 +21,8 @@ import { splitsSurrogatePair } from "./character-boundaries.js";
|
|
|
21
21
|
import { buildCleanBlockText } from "./clean-text.js";
|
|
22
22
|
import { createNoteReferenceLabeler } from "./note-references.js";
|
|
23
23
|
import { panic } from "better-result";
|
|
24
|
-
import { Fragment } from "prosemirror-model";
|
|
25
24
|
import { TableMap } from "prosemirror-tables";
|
|
25
|
+
import { Fragment } from "prosemirror-model";
|
|
26
26
|
// src/ai-edits/snapshot.ts
|
|
27
27
|
const metadataBySnapshot = /* @__PURE__ */ new WeakMap();
|
|
28
28
|
const metadataOf = (snapshot) => metadataBySnapshot.get(snapshot) ?? panic("Metadata was requested for a snapshot that did not record it");
|
|
@@ -7,8 +7,8 @@ import { removeRowsWithoutCells } from "../prosemirror/tableGridMutation.js";
|
|
|
7
7
|
import { tableRectanglesEqual } from "./table-mutation-plan.js";
|
|
8
8
|
import { tableRectangleCutsMergedCell } from "./table-targets.js";
|
|
9
9
|
import { Result } from "better-result";
|
|
10
|
-
import { Fragment } from "prosemirror-model";
|
|
11
10
|
import { TableMap } from "prosemirror-tables";
|
|
11
|
+
import { Fragment } from "prosemirror-model";
|
|
12
12
|
// src/ai-edits/table-cell-mutations.ts
|
|
13
13
|
const mergeTableRectangle = ({ tr, tablePosition, table, rectangle }) => {
|
|
14
14
|
const map = TableMap.get(table);
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
|
-
import { EditorState } from "prosemirror-state";
|
|
3
|
-
import { Node } from "prosemirror-model";
|
|
4
|
-
type TrackedBatchFidelityOptions = {
|
|
5
|
-
before: EditorState;
|
|
6
|
-
after: Node;
|
|
7
|
-
createdCommentIds: readonly number[];
|
|
8
|
-
retiredCommentIds?: readonly number[];
|
|
9
|
-
};
|
|
10
2
|
declare const protectionKinds: readonly ["note", "drawing", "field", "comment"];
|
|
11
3
|
type ProtectionKind = (typeof protectionKinds)[number];
|
|
12
4
|
export type Inventory = Record<ProtectionKind, Map<string, number>>;
|
|
5
|
+
/**
|
|
6
|
+
* The protected content `after` holds as a pending deletion and `before` did
|
|
7
|
+
* not: an edit the reviewer sees as deleted, which Accept All may remove.
|
|
8
|
+
*/
|
|
9
|
+
export declare const newlyDeletedProtectedContent: (before: Inventory, after: Inventory) => Inventory;
|
|
10
|
+
export declare const missingProtectedContent: (expected: Inventory, actual: Inventory, retiredCommentIds: readonly number[], deleted?: Inventory) => ProtectionKind | null;
|
|
13
11
|
export declare const sameOriginalBlocks: (before: readonly document_d_exports.BlockContent[], after: readonly document_d_exports.BlockContent[], addedCommentIds: ReadonlySet<number>) => boolean;
|
|
14
12
|
/**
|
|
15
13
|
* The protected content the edited blocks hold as a new tracked deletion,
|
|
@@ -18,6 +16,4 @@ export declare const sameOriginalBlocks: (before: readonly document_d_exports.Bl
|
|
|
18
16
|
export declare const newlyDeletedProtectedBlocks: (before: readonly document_d_exports.BlockContent[], after: readonly document_d_exports.BlockContent[]) => Inventory;
|
|
19
17
|
/** The kind of protected content missing from the accepted blocks. */
|
|
20
18
|
export declare const missingProtectedBlockKind: (before: readonly document_d_exports.BlockContent[], after: readonly document_d_exports.BlockContent[], retiredCommentIds?: readonly number[], deleted?: Inventory) => ProtectionKind | null;
|
|
21
|
-
/** Check both clean readings before any tracked batch can publish its changes. */
|
|
22
|
-
export declare const trackedBatchFidelityError: (options: TrackedBatchFidelityOptions) => string | null;
|
|
23
19
|
export {};
|
|
@@ -4,92 +4,8 @@ import { BLOCK_TREE_DESCENT, visitBlockTreeRecords, visitInlineContentSlots, vis
|
|
|
4
4
|
import { consolidateParagraphContent, formattingEquals } from "../docx/runConsolidator.js";
|
|
5
5
|
import { serializeDocumentPart } from "../docx/serializer/documentSerializer.js";
|
|
6
6
|
import { WORDPROCESSINGML_NAMESPACE_URIS } from "../docx/xmlParser.js";
|
|
7
|
-
import { pluginsForHeadlessRevisionResolution } from "../internal/headlessRevisionResolutionGuard.js";
|
|
8
|
-
import { getSuggestions, projectAllChangesInHeadlessState, rejectEverySuggestion } from "../prosemirror/commands/comments.js";
|
|
9
|
-
import { proseDocToBlocks } from "../prosemirror/conversion/fromProseDoc.js";
|
|
10
|
-
import { isBlockBoundaryNode } from "../prosemirror/keptRangeBoundaries.js";
|
|
11
|
-
import { readRangeAnchorAttrs } from "../prosemirror/rangeAnchorAttrs.js";
|
|
12
|
-
import { commentAnchorIdsForNode, ownCommentAnchorIds } from "./comment-lifecycle.js";
|
|
13
|
-
import { comparisonApplying, noteReferenceOf } from "./note-references.js";
|
|
14
|
-
import { changedTopLevelWindow } from "./result-validation.js";
|
|
15
|
-
import { Result } from "better-result";
|
|
16
|
-
import { Fragment } from "prosemirror-model";
|
|
17
7
|
import { mergeRunContent } from "@stll/docx-core/ops";
|
|
18
|
-
import { EditorState } from "prosemirror-state";
|
|
19
8
|
// src/ai-edits/tracked-batch-fidelity.ts
|
|
20
|
-
const copyRange = (doc, from, to) => {
|
|
21
|
-
if (from === 0 && to === doc.childCount) return doc;
|
|
22
|
-
const nodes = [];
|
|
23
|
-
for (let index = from; index < to; index++) nodes.push(doc.child(index));
|
|
24
|
-
return doc.copy(Fragment.fromArray(nodes));
|
|
25
|
-
};
|
|
26
|
-
const hasStoryBoundary = (doc) => {
|
|
27
|
-
let found = false;
|
|
28
|
-
doc.descendants((node) => {
|
|
29
|
-
found ||= isBlockBoundaryNode(node) || node.type.name === "rangeAnchor" || node.type.name === "bookmarkBoundary" || node.type.name === "moveRangeBoundary" || node.attrs["_sectionProperties"] != null || noteReferenceOf(node) !== null || commentAnchorIdsForNode(node).length > 0;
|
|
30
|
-
return !found;
|
|
31
|
-
});
|
|
32
|
-
return found;
|
|
33
|
-
};
|
|
34
|
-
const isStableBoundary = (node) => node.type.name === "paragraph" && node.attrs["pPrMark"] == null;
|
|
35
|
-
const hasParagraphMark = (node) => node.type.name === "paragraph" && node.attrs["pPrMark"] != null;
|
|
36
|
-
/** Include the neighbors a paragraph join or boundary relocation may reach. */
|
|
37
|
-
const resolutionWindow = (before, after) => {
|
|
38
|
-
const window = changedTopLevelWindow(before, after);
|
|
39
|
-
if (window === null) return null;
|
|
40
|
-
let { from, beforeTo, afterTo } = window;
|
|
41
|
-
while (from > 0) {
|
|
42
|
-
from--;
|
|
43
|
-
if (isStableBoundary(before.child(from))) {
|
|
44
|
-
const predecessor = before.maybeChild(from - 1);
|
|
45
|
-
if (predecessor === null || !hasParagraphMark(predecessor) && !isBlockBoundaryNode(predecessor)) break;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
while (beforeTo < before.childCount && afterTo < after.childCount) {
|
|
49
|
-
const boundary = before.child(beforeTo);
|
|
50
|
-
beforeTo++;
|
|
51
|
-
afterTo++;
|
|
52
|
-
if (isStableBoundary(boundary)) break;
|
|
53
|
-
}
|
|
54
|
-
const beforeWindow = copyRange(before, from, beforeTo);
|
|
55
|
-
const afterWindow = copyRange(after, from, afterTo);
|
|
56
|
-
if (hasStoryBoundary(beforeWindow) || hasStoryBoundary(afterWindow)) return {
|
|
57
|
-
before,
|
|
58
|
-
after
|
|
59
|
-
};
|
|
60
|
-
return {
|
|
61
|
-
before: beforeWindow,
|
|
62
|
-
after: afterWindow
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Comments added by an edit batch also exist outside its tracked revisions.
|
|
67
|
-
* Only the added comments' own anchors go; an older comment's reference
|
|
68
|
-
* inside an added comment's range stays, without the added comment's mark.
|
|
69
|
-
*/
|
|
70
|
-
const withoutAddedComments = (node, added) => {
|
|
71
|
-
const name = node.type.name;
|
|
72
|
-
if ((name === "commentReference" || name === "commentRangeBoundary") && ownCommentAnchorIds(node).some((id) => added.has(id))) return null;
|
|
73
|
-
if (name === "rangeAnchor") {
|
|
74
|
-
const parsed = readRangeAnchorAttrs(node);
|
|
75
|
-
if (parsed.ok) {
|
|
76
|
-
const markers = parsed.value.markers.filter((marker) => marker.type !== "commentRangeStart" && marker.type !== "commentRangeEnd" || !added.has(marker.id));
|
|
77
|
-
if (markers.length === 0) return null;
|
|
78
|
-
if (markers.length !== parsed.value.markers.length) return node.type.create({
|
|
79
|
-
...node.attrs,
|
|
80
|
-
markers
|
|
81
|
-
}, null, node.marks);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
const marks = node.marks.filter((mark) => mark.type.name !== "comment" || !added.has(mark.attrs["commentId"]));
|
|
85
|
-
if (node.isLeaf) return node.mark(marks);
|
|
86
|
-
const children = [];
|
|
87
|
-
node.forEach((child) => {
|
|
88
|
-
const kept = withoutAddedComments(child, added);
|
|
89
|
-
if (kept !== null) children.push(kept);
|
|
90
|
-
});
|
|
91
|
-
return node.copy(Fragment.fromArray(children)).mark(marks);
|
|
92
|
-
};
|
|
93
9
|
const protectionKinds = [
|
|
94
10
|
"note",
|
|
95
11
|
"drawing",
|
|
@@ -99,61 +15,11 @@ const protectionKinds = [
|
|
|
99
15
|
const add = (items, key) => {
|
|
100
16
|
items.set(key, (items.get(key) ?? 0) + 1);
|
|
101
17
|
};
|
|
102
|
-
const isTrackedDeletion = (node) => node.marks.some(({ type }) => type.name === "deletion");
|
|
103
|
-
/**
|
|
104
|
-
* The protected content of `doc`; with `deletedOnly`, only the notes,
|
|
105
|
-
* drawings and fields that are themselves pending deletion, which Accept All
|
|
106
|
-
* removes as the reviewer sees it.
|
|
107
|
-
*/
|
|
108
|
-
const protectedContent = (doc, deletedOnly = false) => {
|
|
109
|
-
const inventory = {
|
|
110
|
-
note: /* @__PURE__ */ new Map(),
|
|
111
|
-
drawing: /* @__PURE__ */ new Map(),
|
|
112
|
-
field: /* @__PURE__ */ new Map(),
|
|
113
|
-
comment: /* @__PURE__ */ new Map()
|
|
114
|
-
};
|
|
115
|
-
const comments = /* @__PURE__ */ new Set();
|
|
116
|
-
let hasComment = false;
|
|
117
|
-
doc.descendants((node) => {
|
|
118
|
-
if (deletedOnly && !isTrackedDeletion(node)) return true;
|
|
119
|
-
if (deletedOnly && node.type.name === "textBoxAnchor") add(inventory.drawing, JSON.stringify(["textBox", node.attrs["anchorId"]]));
|
|
120
|
-
const note = noteReferenceOf(node);
|
|
121
|
-
if (note !== null) inventory.note.set(JSON.stringify([note.noteType, note.noteId]), 1);
|
|
122
|
-
switch (node.type.name) {
|
|
123
|
-
case "image":
|
|
124
|
-
add(inventory.drawing, JSON.stringify([
|
|
125
|
-
"image",
|
|
126
|
-
node.attrs["rId"] ?? node.attrs["src"],
|
|
127
|
-
node.attrs["docPrId"]
|
|
128
|
-
]));
|
|
129
|
-
break;
|
|
130
|
-
case "shape":
|
|
131
|
-
add(inventory.drawing, JSON.stringify(["shape", node.attrs["shapeId"]]));
|
|
132
|
-
break;
|
|
133
|
-
case "textBox":
|
|
134
|
-
add(inventory.drawing, JSON.stringify(["textBox", node.attrs["_docxAnchorId"]]));
|
|
135
|
-
break;
|
|
136
|
-
case "field":
|
|
137
|
-
case "structuredField": add(inventory.field, String(node.attrs["instruction"]));
|
|
138
|
-
}
|
|
139
|
-
if (deletedOnly) return true;
|
|
140
|
-
for (const id of commentAnchorIdsForNode(node)) {
|
|
141
|
-
comments.add(id);
|
|
142
|
-
hasComment = true;
|
|
143
|
-
}
|
|
144
|
-
return true;
|
|
145
|
-
});
|
|
146
|
-
for (const id of comments) add(inventory.comment, String(id));
|
|
147
|
-
if (hasComment) visitCommentMarkers(proseDocToBlocks(doc, []), ({ item }) => {
|
|
148
|
-
if (item.type === "commentReference") add(inventory.comment, `reference:${String(item.id)}`);
|
|
149
|
-
});
|
|
150
|
-
return inventory;
|
|
151
|
-
};
|
|
152
18
|
/**
|
|
153
19
|
* The protected content `after` holds as a pending deletion and `before` did
|
|
154
20
|
* not: an edit the reviewer sees as deleted, which Accept All may remove.
|
|
155
21
|
*/
|
|
156
|
-
const
|
|
22
|
+
const newlyDeletedProtectedContent = (before, after) => {
|
|
157
23
|
const inventory = {
|
|
158
24
|
note: /* @__PURE__ */ new Map(),
|
|
159
25
|
drawing: /* @__PURE__ */ new Map(),
|
|
@@ -240,7 +106,6 @@ const sameOriginalBlocks = (before, after, addedCommentIds) => {
|
|
|
240
106
|
return other !== void 0 && (block === other || authoredBlock(block) === authoredBlock(other));
|
|
241
107
|
});
|
|
242
108
|
};
|
|
243
|
-
const sameOriginal = (before, after) => before.content.eq(after.content) || sameOriginalBlocks(proseDocToBlocks(before, []), proseDocToBlocks(after, []), /* @__PURE__ */ new Set());
|
|
244
109
|
const modelInventory = (blocks) => {
|
|
245
110
|
const inventory = {
|
|
246
111
|
note: /* @__PURE__ */ new Map(),
|
|
@@ -307,51 +172,7 @@ const deletedModelInventory = (blocks) => {
|
|
|
307
172
|
* The protected content the edited blocks hold as a new tracked deletion,
|
|
308
173
|
* which Accept All removes as the reviewer sees it.
|
|
309
174
|
*/
|
|
310
|
-
const newlyDeletedProtectedBlocks = (before, after) =>
|
|
175
|
+
const newlyDeletedProtectedBlocks = (before, after) => newlyDeletedProtectedContent(deletedModelInventory(before), deletedModelInventory(after));
|
|
311
176
|
/** The kind of protected content missing from the accepted blocks. */
|
|
312
177
|
const missingProtectedBlockKind = (before, after, retiredCommentIds = [], deleted) => missingProtectedContent(modelInventory(before), modelInventory(after), retiredCommentIds, deleted);
|
|
313
|
-
|
|
314
|
-
if (comparisonApplying()) return null;
|
|
315
|
-
const window = resolutionWindow(before.doc, after);
|
|
316
|
-
if (window === null) return null;
|
|
317
|
-
const plugins = pluginsForHeadlessRevisionResolution(before.plugins);
|
|
318
|
-
let original = EditorState.create({
|
|
319
|
-
doc: window.before,
|
|
320
|
-
plugins
|
|
321
|
-
});
|
|
322
|
-
let candidate = EditorState.create({
|
|
323
|
-
doc: window.after,
|
|
324
|
-
plugins
|
|
325
|
-
});
|
|
326
|
-
if (window.before !== before.doc && (getSuggestions(original).length > 0 || getSuggestions(candidate).length > 0)) {
|
|
327
|
-
original = EditorState.create({
|
|
328
|
-
doc: before.doc,
|
|
329
|
-
plugins
|
|
330
|
-
});
|
|
331
|
-
candidate = EditorState.create({
|
|
332
|
-
doc: after,
|
|
333
|
-
plugins
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
original = rejectEverySuggestion(original);
|
|
337
|
-
candidate = rejectEverySuggestion(candidate);
|
|
338
|
-
const rejectedBefore = projectAllChangesInHeadlessState(original, "reject");
|
|
339
|
-
const rejectedAfter = projectAllChangesInHeadlessState(candidate, "reject");
|
|
340
|
-
if (rejectedBefore === null || rejectedAfter === null) return "Reject All could not resolve the tracked result.";
|
|
341
|
-
const rejected = createdCommentIds.length === 0 ? rejectedAfter.doc : withoutAddedComments(rejectedAfter.doc, new Set(createdCommentIds));
|
|
342
|
-
if (rejected === null || !sameOriginal(rejectedBefore.doc, rejected)) return "Reject All would change the original content or formatting.";
|
|
343
|
-
const acceptedBefore = projectAllChangesInHeadlessState(original, "accept");
|
|
344
|
-
const acceptedAfter = projectAllChangesInHeadlessState(candidate, "accept");
|
|
345
|
-
if (acceptedBefore === null || acceptedAfter === null) return "Accept All could not resolve the tracked result.";
|
|
346
|
-
const lost = missingProtectedContent(protectedContent(acceptedBefore.doc), protectedContent(acceptedAfter.doc), retiredCommentIds, newlyDeleted(protectedContent(original.doc, true), protectedContent(candidate.doc, true)));
|
|
347
|
-
return lost === null ? null : `Accept All would lose a ${lost}.`;
|
|
348
|
-
};
|
|
349
|
-
/** Check both clean readings before any tracked batch can publish its changes. */
|
|
350
|
-
const trackedBatchFidelityError = (options) => {
|
|
351
|
-
const verdict = Result.try({
|
|
352
|
-
try: () => checkTrackedBatchFidelity(options),
|
|
353
|
-
catch: () => "The tracked result could not be verified."
|
|
354
|
-
});
|
|
355
|
-
return verdict.isOk() ? verdict.value : verdict.error;
|
|
356
|
-
};
|
|
357
|
-
export { missingProtectedBlockKind, newlyDeletedProtectedBlocks, sameOriginalBlocks, trackedBatchFidelityError };
|
|
178
|
+
export { missingProtectedBlockKind, missingProtectedContent, newlyDeletedProtectedBlocks, newlyDeletedProtectedContent, sameOriginalBlocks };
|
|
@@ -19,7 +19,10 @@ export declare const createCanonicalBatchReview: ({ before, after, story }: Cano
|
|
|
19
19
|
original: readonly document_d_exports.BlockContent[];
|
|
20
20
|
edited: readonly document_d_exports.BlockContent[];
|
|
21
21
|
} | null;
|
|
22
|
-
reject
|
|
22
|
+
reject: () => {
|
|
23
|
+
original: readonly document_d_exports.BlockContent[];
|
|
24
|
+
edited: readonly document_d_exports.BlockContent[];
|
|
25
|
+
} | null;
|
|
23
26
|
acceptedCommentIds(side: "before" | "after"): Set<number> | null;
|
|
24
27
|
};
|
|
25
28
|
export {};
|
|
@@ -60,7 +60,14 @@ const resolveStory = ({ version: { document, projection }, story, ids, decision,
|
|
|
60
60
|
indentation: "restore"
|
|
61
61
|
}));
|
|
62
62
|
};
|
|
63
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Both sides of a batch resolved the same way. A revision the document held
|
|
65
|
+
* before the batch that blocks its own resolution, alone and the same way on
|
|
66
|
+
* both sides, stays pending on both: the proof is about what the batch
|
|
67
|
+
* changes, and a blocker the batch did not make must not refuse every edit
|
|
68
|
+
* of a document that holds one.
|
|
69
|
+
*/
|
|
70
|
+
const resolveStoryPair = ({ before, after, story, decision, restores }) => {
|
|
64
71
|
let beforeIds = before.ids;
|
|
65
72
|
let afterIds = after.ids;
|
|
66
73
|
while (true) {
|
|
@@ -68,13 +75,14 @@ const acceptStoryPair = ({ before, after, story }) => {
|
|
|
68
75
|
version: before.version,
|
|
69
76
|
story,
|
|
70
77
|
ids: beforeIds,
|
|
71
|
-
decision
|
|
78
|
+
decision
|
|
72
79
|
});
|
|
73
80
|
const edited = resolveStory({
|
|
74
81
|
version: after.version,
|
|
75
82
|
story,
|
|
76
83
|
ids: afterIds,
|
|
77
|
-
decision
|
|
84
|
+
decision,
|
|
85
|
+
...restores === void 0 ? {} : { restores }
|
|
78
86
|
});
|
|
79
87
|
if (original?.type === "resolved" && edited?.type === "resolved") return {
|
|
80
88
|
original: original.content,
|
|
@@ -95,8 +103,9 @@ const createCanonicalBatchReview = ({ before, after, story }) => {
|
|
|
95
103
|
let accepted;
|
|
96
104
|
const accept = () => {
|
|
97
105
|
if (accepted !== void 0) return accepted;
|
|
98
|
-
accepted =
|
|
106
|
+
accepted = resolveStoryPair({
|
|
99
107
|
story,
|
|
108
|
+
decision: "accept",
|
|
100
109
|
before: {
|
|
101
110
|
version: before,
|
|
102
111
|
ids: revisions("before").ordinary
|
|
@@ -108,21 +117,30 @@ const createCanonicalBatchReview = ({ before, after, story }) => {
|
|
|
108
117
|
}) ?? null;
|
|
109
118
|
return accepted;
|
|
110
119
|
};
|
|
120
|
+
let rejected;
|
|
121
|
+
const reject = () => {
|
|
122
|
+
if (rejected !== void 0) return rejected;
|
|
123
|
+
rejected = resolveStoryPair({
|
|
124
|
+
story,
|
|
125
|
+
decision: "reject",
|
|
126
|
+
before: {
|
|
127
|
+
version: before,
|
|
128
|
+
ids: revisions("before").all
|
|
129
|
+
},
|
|
130
|
+
after: {
|
|
131
|
+
version: after,
|
|
132
|
+
ids: revisions("after").all
|
|
133
|
+
},
|
|
134
|
+
restores: before.document
|
|
135
|
+
}) ?? null;
|
|
136
|
+
return rejected;
|
|
137
|
+
};
|
|
111
138
|
return {
|
|
112
139
|
story,
|
|
113
140
|
before: before.document,
|
|
114
141
|
after: after.document,
|
|
115
142
|
accept,
|
|
116
|
-
reject
|
|
117
|
-
const rejected = resolveStory({
|
|
118
|
-
version: side === "before" ? before : after,
|
|
119
|
-
story,
|
|
120
|
-
ids: revisions(side).all,
|
|
121
|
-
decision: "reject",
|
|
122
|
-
...side === "after" ? { restores: before.document } : {}
|
|
123
|
-
});
|
|
124
|
-
return rejected?.type === "resolved" ? rejected.content : void 0;
|
|
125
|
-
},
|
|
143
|
+
reject,
|
|
126
144
|
acceptedCommentIds(side) {
|
|
127
145
|
const pair = accept();
|
|
128
146
|
return pair === null ? null : anchoredCommentIdsInBlocks(side === "before" ? pair.original : pair.edited);
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
/** The one semantic compiler for canonical sidebar, controlled and public comments. */
|
|
2
|
-
import {
|
|
2
|
+
import { CanonicalRefusalGround } from "../types/canonicalCapabilities.js";
|
|
3
3
|
import { Comment } from "../types/content.js";
|
|
4
4
|
import { document_d_exports } from "../types/document.js";
|
|
5
5
|
import { Err, Ok, TaggedErrorClass } from "better-result";
|
|
6
6
|
import { CreateCommentOp, DocumentOp, IdLease } from "@stll/docx-core/ops";
|
|
7
7
|
declare const CanonicalCommentErrorBase: TaggedErrorClass<"CanonicalCommentError">;
|
|
8
|
+
/**
|
|
9
|
+
* A comment command the document does not allow, such as a reply to a missing
|
|
10
|
+
* thread, or one no id is left to mint for.
|
|
11
|
+
*/
|
|
8
12
|
export declare class CanonicalCommentError extends CanonicalCommentErrorBase<{
|
|
9
13
|
message: string;
|
|
10
|
-
|
|
14
|
+
ground: CanonicalRefusalGround;
|
|
11
15
|
}> {}
|
|
12
16
|
export type CanonicalCommentCommand = {
|
|
13
17
|
type: "create";
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { commentThreadParaId } from "../docx/commentThreadKey.js";
|
|
2
2
|
import { cloneParagraphWithPropertySource } from "../docx/paragraphPropertySource.js";
|
|
3
3
|
import { threadedCommentIds } from "../docx/serializer/commentSerializer.js";
|
|
4
|
-
import {
|
|
4
|
+
import { CANONICAL_CONDITION } from "../types/canonicalCapabilities.js";
|
|
5
5
|
import { canonicalJson } from "../utils/canonicalJson.js";
|
|
6
6
|
import { Result, TaggedError } from "better-result";
|
|
7
7
|
import { DOCUMENT_OP_TYPES, ID_KIND_LIMITS, ID_LEASE_KINDS, allocateCommentAnchorIds, applyDocumentOps, formatParaId, freshLeasedIds, packageParagraphIds } from "@stll/docx-core/ops";
|
|
8
8
|
// src/canonical/canonicalComments.ts
|
|
9
9
|
/** The one semantic compiler for canonical sidebar, controlled and public comments. */
|
|
10
10
|
const CanonicalCommentErrorBase = TaggedError("CanonicalCommentError");
|
|
11
|
+
/**
|
|
12
|
+
* A comment command the document does not allow, such as a reply to a missing
|
|
13
|
+
* thread, or one no id is left to mint for.
|
|
14
|
+
*/
|
|
11
15
|
var CanonicalCommentError = class extends CanonicalCommentErrorBase {};
|
|
12
|
-
const refuse = (message) => Result.err(new CanonicalCommentError({
|
|
16
|
+
const refuse = (message, condition = CANONICAL_CONDITION.invalidRequest) => Result.err(new CanonicalCommentError({
|
|
13
17
|
message,
|
|
14
|
-
|
|
18
|
+
ground: { condition }
|
|
15
19
|
}));
|
|
16
20
|
const compileCanonicalComments = ({ document, command, idLease }) => {
|
|
17
21
|
const current = document.package.document.comments ?? [];
|
|
@@ -139,7 +143,7 @@ const compileCanonicalComments = ({ document, command, idLease }) => {
|
|
|
139
143
|
const last = content.at(-1);
|
|
140
144
|
if (!threaded.has(comment.id) || last === void 0 || commentThreadParaId(content.map(({ paraId }) => paraId)) !== void 0) continue;
|
|
141
145
|
const paraId = canonicalCommentBody(draft, "", idLease).at(0)?.paraId;
|
|
142
|
-
if (paraId === void 0) return refuse("No paragraph id is free.");
|
|
146
|
+
if (paraId === void 0) return refuse("No paragraph id is free.", CANONICAL_CONDITION.idSpace);
|
|
143
147
|
const op = {
|
|
144
148
|
type: DOCUMENT_OP_TYPES.UPDATE_COMMENT_CONTENT,
|
|
145
149
|
id: comment.id,
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The source gaps of one paragraph's logical text, by offset.
|
|
3
|
+
*
|
|
4
|
+
* Each offset of the text (`0` to `text.length`) has one or more gaps: an
|
|
5
|
+
* editor position, relative to the paragraph, that stands for it, the
|
|
6
|
+
* zero-width source ordinal that position names, and the ordinals its seam
|
|
7
|
+
* covers (`first` to `last`). Gaps at one offset keep the order they were
|
|
8
|
+
* added in.
|
|
9
|
+
*
|
|
10
|
+
* Nearly every offset has exactly one gap, so the first gap of each offset is
|
|
11
|
+
* held flat, four integers per offset in one `Int32Array`, and only the rare
|
|
12
|
+
* further gaps (zero-width markers at one offset that several editor positions
|
|
13
|
+
* reach) go to a side map. A paragraph's gaps then cost about sixteen bytes
|
|
14
|
+
* per character, not two arrays and two objects per character; a canonical
|
|
15
|
+
* session keeps them for every paragraph of the story.
|
|
16
|
+
*/
|
|
17
|
+
/** An editor position (relative to its paragraph) and the source ordinal it names. */
|
|
18
|
+
export type CanonicalInlineGap = {
|
|
19
|
+
position: number;
|
|
20
|
+
zeroWidthBefore: number;
|
|
21
|
+
};
|
|
22
|
+
/** The source ordinals one editor position stands for: from `first` to `last`. */
|
|
23
|
+
export type CanonicalSeamExtent = {
|
|
24
|
+
first: number;
|
|
25
|
+
last: number;
|
|
26
|
+
};
|
|
27
|
+
/** One gap with its seam. */
|
|
28
|
+
export type CanonicalGapEntry = CanonicalInlineGap & CanonicalSeamExtent;
|
|
29
|
+
export declare class CanonicalInlineGaps {
|
|
30
|
+
/** The first gap of each offset: position, zeroWidthBefore, first, last. */
|
|
31
|
+
private readonly flat;
|
|
32
|
+
/** The second and later gaps of an offset, in the order they were added. */
|
|
33
|
+
private readonly more;
|
|
34
|
+
/** Room for `offsets` offsets (`text.length + 1`), none holding a gap yet. */
|
|
35
|
+
constructor(offsets: number);
|
|
36
|
+
/** How many offsets the table holds: the text's length plus one. */
|
|
37
|
+
get offsets(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Record a gap at `offset`. A gap at an editor position the offset already
|
|
40
|
+
* has widens that gap's seam to the ordinal, and the gap then names the
|
|
41
|
+
* ordinal of the two that is nearer to `preferred()` (asked only then); a
|
|
42
|
+
* tie keeps the earlier one. Returns false when the offset is outside the
|
|
43
|
+
* text.
|
|
44
|
+
*/
|
|
45
|
+
add(offset: number, position: number, zeroWidthBefore: number, preferred: () => number): boolean;
|
|
46
|
+
/** Whether some offset has no gap. */
|
|
47
|
+
hasEmptyOffset(): boolean;
|
|
48
|
+
/** The gaps at `offset` with their seams, in order; undefined outside the text. */
|
|
49
|
+
at(offset: number): readonly CanonicalGapEntry[] | undefined;
|
|
50
|
+
/** The first offset with a gap at editor `position`, or -1. */
|
|
51
|
+
offsetOf(position: number): number;
|
|
52
|
+
/** Every offset's gaps, without their seams. */
|
|
53
|
+
toBoundaries(): CanonicalInlineGap[][];
|
|
54
|
+
/** Every offset's seams, parallel to {@link toBoundaries}. */
|
|
55
|
+
toSeams(): CanonicalSeamExtent[][];
|
|
56
|
+
}
|