@stll/folio-core 0.72.0 → 0.73.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/README.md +12 -6
- package/dist/ai-edits/apply.d.ts +6 -114
- package/dist/ai-edits/apply.js +9 -131
- package/dist/ai-edits/applyTypes.d.ts +85 -0
- package/dist/ai-edits/applyTypes.js +24 -0
- package/dist/ai-edits/clean-text.d.ts +7 -1
- package/dist/ai-edits/clean-text.js +23 -2
- package/dist/ai-edits/finalSectionReview.d.ts +1 -1
- package/dist/ai-edits/headless.d.ts +29 -147
- package/dist/ai-edits/headless.js +213 -1634
- package/dist/ai-edits/index.d.ts +3 -3
- package/dist/ai-edits/index.js +2 -3
- package/dist/ai-edits/pending-suggestions.d.ts +14 -4
- package/dist/ai-edits/pending-suggestions.js +183 -90
- package/dist/ai-edits/result-validation.js +1 -1
- package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
- package/dist/ai-edits/snapshot.js +8 -3
- package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
- package/dist/ai-edits/table-cell-mutations.js +1 -1
- package/dist/ai-edits/table-geometry.d.ts +1 -1
- package/dist/ai-edits/table-geometry.js +1 -1
- package/dist/ai-edits/table-row-column-mutations.d.ts +1 -1
- package/dist/ai-edits/table-row-column-mutations.js +1 -1
- package/dist/ai-edits/tableNodes.d.ts +38 -0
- package/dist/ai-edits/tableNodes.js +86 -0
- package/dist/ai-edits/tracked-batch-fidelity.d.ts +1 -1
- package/dist/ai-edits/undefinedReferences.d.ts +7 -0
- package/dist/canonical/batchCommentReferences.js +1 -0
- package/dist/canonical/canonicalInlineProjection.js +1 -1
- package/dist/canonical/canonicalPublicOperations.js +228 -64
- package/dist/canonical/canonicalSession.d.ts +9 -1
- package/dist/canonical/canonicalSession.js +95 -15
- package/dist/compare/compare.d.ts +1 -1
- package/dist/compare/inline-atoms-model.d.ts +1 -1
- package/dist/compare/inline-atoms.d.ts +2 -2
- package/dist/compare/inline-provenance-model.d.ts +1 -1
- package/dist/compare/inline-provenance.d.ts +2 -2
- package/dist/compat/eigenpal.d.ts +3 -3
- package/dist/compat/eigenpal.js +2 -3
- package/dist/controller/canonicalClipboard.d.ts +13 -3
- package/dist/controller/canonicalClipboard.js +185 -49
- package/dist/controller/canonicalClipboardResources.d.ts +9 -1
- package/dist/controller/canonicalClipboardResources.js +22 -2
- package/dist/controller/canonicalReview.d.ts +1 -1
- package/dist/controller/canonicalReview.js +1 -1
- package/dist/controller/canonicalStructure.js +1 -1
- package/dist/controller/canonicalWatermark.d.ts +10 -0
- package/dist/controller/canonicalWatermark.js +37 -0
- package/dist/controller/hiddenEditorApi.d.ts +1 -1
- package/dist/controller/hiddenEditorManager.d.ts +4 -3
- package/dist/controller/hiddenEditorManager.js +75 -15
- package/dist/document-operations-apply.d.ts +15 -0
- package/dist/document-operations-apply.js +280 -0
- package/dist/document-operations.d.ts +1 -14
- package/dist/document-operations.js +2 -279
- package/dist/docx/modelValidation.js +1 -1
- package/dist/docx/paragraphParser.js +2 -2
- package/dist/docx/paragraphPropertySource.d.ts +1 -1
- package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
- package/dist/docx/reviewResolutionProvenance.js +32 -9
- package/dist/docx/revisionIdNormalization.js +30 -7
- package/dist/docx/rezip.js +1 -1
- 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 +5 -37
- package/dist/docx/serializer/textFormattingSerializer.js +1 -1
- package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
- package/dist/docx/server/templatePlan/apply.d.ts +15 -0
- package/dist/docx/server/templatePlan/apply.js +600 -0
- package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
- package/dist/docx/server/templatePlan/blocks.js +355 -0
- package/dist/docx/server/templatePlan/builders.d.ts +72 -0
- package/dist/docx/server/templatePlan/builders.js +237 -0
- package/dist/docx/server/templatePlan/emit.d.ts +118 -0
- package/dist/docx/server/templatePlan/emit.js +466 -0
- package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
- package/dist/docx/server/templatePlan/emphasis.js +173 -0
- package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
- package/dist/docx/server/templatePlan/inspect.js +177 -0
- package/dist/docx/server/templatePlan/labels.d.ts +36 -0
- package/dist/docx/server/templatePlan/labels.js +126 -0
- package/dist/docx/server/templatePlan/package.d.ts +34 -0
- package/dist/docx/server/templatePlan/package.js +99 -0
- package/dist/docx/server/templatePlan/plan.d.ts +143 -0
- package/dist/docx/server/templatePlan/plan.js +841 -0
- package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
- package/dist/docx/server/templatePlan/planShape.js +161 -0
- package/dist/docx/server/templatePlan/resources.d.ts +41 -0
- package/dist/docx/server/templatePlan/resources.js +136 -0
- package/dist/docx/server/templatePlan/story.d.ts +128 -0
- package/dist/docx/server/templatePlan/story.js +440 -0
- package/dist/docx/server/templatePlan/types.d.ts +406 -0
- package/dist/docx/server/templatePlan/types.js +28 -0
- package/dist/docx/server/templatePlan/verify.d.ts +40 -0
- package/dist/docx/server/templatePlan/verify.js +968 -0
- package/dist/docx/server/templatePlan/xml.d.ts +69 -0
- package/dist/docx/server/templatePlan/xml.js +119 -0
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
- package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
- package/dist/docx/storyBlockReplay.js +1 -1
- package/dist/docx/structuralXmlPatch.js +9 -1
- package/dist/docx/tableGridXml.d.ts +30 -0
- package/dist/docx/tableGridXml.js +54 -0
- package/dist/docx/tableParser.js +7 -0
- package/dist/docx/xmlParser.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -3
- package/dist/internal/paragraphFormattingSerialization.js +1 -1
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/managers/ContextMenuManager.js +2 -1
- package/dist/managers/editorShortcuts.d.ts +1 -1
- package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
- package/dist/prosemirror/canonicalCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +2 -2
- package/dist/prosemirror/commands/comments.js +3 -3
- package/dist/prosemirror/commands/contentControls.d.ts +1 -1
- package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
- package/dist/prosemirror/commands/sectionBreak.js +1 -1
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
- package/dist/prosemirror/commentRecords.d.ts +1 -1
- package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
- package/dist/prosemirror/conversion/fromProseDoc.js +1 -1
- package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
- package/dist/prosemirror/documentStructureCounts.js +76 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
- package/dist/prosemirror/extensions/StarterKit.d.ts +1 -1
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +1 -7
- package/dist/prosemirror/extensions/core/HistoryExtension.js +5 -13
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
- package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
- package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +2 -35
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +4 -142
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +3 -87
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +7 -162
- package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +2 -2
- package/dist/prosemirror/extensions/types.d.ts +1 -1
- package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
- package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
- package/dist/prosemirror/index.d.ts +1 -1
- package/dist/prosemirror/index.js +1 -1
- package/dist/prosemirror/insertionGaps.d.ts +1 -1
- package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
- package/dist/prosemirror/listNumbering.d.ts +1 -1
- package/dist/prosemirror/lockedControls.d.ts +1 -1
- package/dist/prosemirror/markupViewProjection.d.ts +1 -1
- package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
- package/dist/prosemirror/noteReferenceReview.js +1 -1
- package/dist/prosemirror/paraIds.d.ts +46 -0
- package/dist/prosemirror/paraIds.js +152 -0
- package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
- package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
- package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
- package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
- package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
- package/dist/prosemirror/pastedCommentCopies.js +1 -1
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
- package/dist/prosemirror/plugins/suggestionMode.d.ts +1 -1
- package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
- package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
- package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.js +16 -1
- package/dist/prosemirror/revisionCarriers.d.ts +1 -1
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
- package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
- package/dist/prosemirror/selectionBounds.d.ts +10 -0
- package/dist/prosemirror/selectionBounds.js +22 -0
- package/dist/prosemirror/storyListNumbering.d.ts +1 -1
- package/dist/prosemirror/tableCellPaste.d.ts +1 -1
- package/dist/prosemirror/tableGridMutation.d.ts +1 -1
- package/dist/prosemirror/textInput.d.ts +1 -1
- package/dist/server.d.ts +7 -2
- package/dist/server.js +6 -1
- package/dist/types/canonicalCapabilities.d.ts +8 -41
- package/dist/types/canonicalCapabilities.js +6 -34
- package/package.json +4 -4
|
@@ -17,18 +17,18 @@ import { createCommentRecordsPlugin, isCommentRecordsSync } from "../prosemirror
|
|
|
17
17
|
import { createEmptyDoc, toProseDoc } from "../prosemirror/conversion/toProseDoc.js";
|
|
18
18
|
import { registerEditorCommandOwner } from "../prosemirror/executeEditorCommand.js";
|
|
19
19
|
import { ensureBaseDirectionInState } from "../prosemirror/extensions/features/AutoBidiDetectionExtension.js";
|
|
20
|
-
import { ensureParaIdsInDoc } from "../prosemirror/extensions/features/ParaIdAllocatorExtension.js";
|
|
21
20
|
import { toggleMarkForAllScripts, toggleUnderlineMark } from "../prosemirror/extensions/marks/markUtils.js";
|
|
22
21
|
import { HyperlinkRemovalRefusal } from "../prosemirror/hyperlinkRemoval.js";
|
|
23
22
|
import { REVISION_MARK_NAMES } from "../prosemirror/keptRangeBoundaries.js";
|
|
24
23
|
import { adoptNativeSelection, createNativeNavigationPlugin, createNativeSelectionRefreshPlugin, isCompositionKeyDown } from "../prosemirror/nativeSelection.js";
|
|
25
24
|
import { noteReferenceTransactionIssue } from "../prosemirror/noteReferenceOccurrences.js";
|
|
25
|
+
import { ensureParaIdsInDoc } from "../prosemirror/paraIds.js";
|
|
26
26
|
import { createDocumentNumberingPlugin } from "../prosemirror/plugins/documentNumbering.js";
|
|
27
27
|
import { createDocumentStyleContextPlugin, createDocumentStylesPlugin } from "../prosemirror/plugins/documentStyles.js";
|
|
28
28
|
import { schema } from "../prosemirror/schema/index.js";
|
|
29
|
-
import { createTextInputPlugin } from "../prosemirror/textInput.js";
|
|
30
29
|
import { CANONICAL_GAP, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
|
|
31
30
|
import { readModel } from "../types/documentModel.js";
|
|
31
|
+
import { INTERNAL_CLIPBOARD_TYPE } from "../utils/clipboard.js";
|
|
32
32
|
import { NO_ANONYMIZATION_TERMS, createAnonymizationHighlights } from "./anonymizationHighlights.js";
|
|
33
33
|
import { canTriggerAutocomplete, classifyAutocompleteEdit, createAutocompleteSuggestion, nextAutocompleteWord } from "./autocompleteSuggestion.js";
|
|
34
34
|
import { prepareCanonicalPaste } from "./canonicalClipboard.js";
|
|
@@ -41,7 +41,7 @@ import { Result, TaggedError } from "better-result";
|
|
|
41
41
|
import { DOMParser, DOMSerializer } from "prosemirror-model";
|
|
42
42
|
import { CellSelection } from "prosemirror-tables";
|
|
43
43
|
import { OP_STORIES, documentStories, freshCommentId, sameStory } from "@stll/docx-core/ops";
|
|
44
|
-
import { EditorState, Plugin } from "prosemirror-state";
|
|
44
|
+
import { EditorState, Plugin, Selection } from "prosemirror-state";
|
|
45
45
|
import { EditorView } from "prosemirror-view";
|
|
46
46
|
// src/controller/hiddenEditorManager.ts
|
|
47
47
|
/**
|
|
@@ -107,7 +107,6 @@ function createHiddenEditorState(options) {
|
|
|
107
107
|
createDocumentNumberingPlugin(document?.package.numbering),
|
|
108
108
|
createCommentRecordsPlugin(document?.package.document.comments ?? []),
|
|
109
109
|
...externalPlugins,
|
|
110
|
-
...manager?.getPlugins() ?? [createTextInputPlugin()],
|
|
111
110
|
styleResolverPlugin
|
|
112
111
|
];
|
|
113
112
|
const startedAt = performance.now();
|
|
@@ -532,6 +531,29 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
532
531
|
return publishCommit(prepared.value);
|
|
533
532
|
};
|
|
534
533
|
let clipboardDrag = { type: "idle" };
|
|
534
|
+
let clipboardCopy = { type: "none" };
|
|
535
|
+
/**
|
|
536
|
+
* Write the selection to the clipboard once, under a token minted for this
|
|
537
|
+
* copy alone, and return what was written.
|
|
538
|
+
*/
|
|
539
|
+
const writeClipboard = (pmView, data) => {
|
|
540
|
+
const serialized = pmView.serializeForClipboard(pmView.state.selection.content());
|
|
541
|
+
const html = serialized.dom.innerHTML;
|
|
542
|
+
const token = crypto.randomUUID();
|
|
543
|
+
data.setData("text/html", html);
|
|
544
|
+
data.setData("text/plain", serialized.text);
|
|
545
|
+
data.setData(INTERNAL_CLIPBOARD_TYPE, token);
|
|
546
|
+
return {
|
|
547
|
+
html,
|
|
548
|
+
token
|
|
549
|
+
};
|
|
550
|
+
};
|
|
551
|
+
/** The copied document, when the pasted clipboard is the editor's own copy. */
|
|
552
|
+
const copiedSource = (event) => {
|
|
553
|
+
const data = event.clipboardData;
|
|
554
|
+
if (clipboardCopy.type !== "copied" || data === null) return {};
|
|
555
|
+
return data.getData("application/x-stella-folio") === clipboardCopy.token && data.getData("text/html").includes(clipboardCopy.html) ? { sourceDocument: clipboardCopy.document } : {};
|
|
556
|
+
};
|
|
535
557
|
let lastInputRule;
|
|
536
558
|
const canonicalStructuralInput = {
|
|
537
559
|
command: (name) => {
|
|
@@ -717,6 +739,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
717
739
|
return true;
|
|
718
740
|
}
|
|
719
741
|
syncCanonicalMode();
|
|
742
|
+
const source = readModel(editorSession.session.document);
|
|
720
743
|
const session = editorSession.session;
|
|
721
744
|
const { from, to } = pmView.state.selection;
|
|
722
745
|
const prepared = session.prepareReplace(pmView.state, {
|
|
@@ -729,19 +752,24 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
729
752
|
refuse(prepared.error.message, prepared.error.ground);
|
|
730
753
|
return true;
|
|
731
754
|
}
|
|
755
|
+
const data = event.clipboardData;
|
|
732
756
|
const copied = Result.try({
|
|
733
|
-
try: () =>
|
|
734
|
-
const serialized = pmView.serializeForClipboard(pmView.state.selection.content());
|
|
735
|
-
event.clipboardData?.setData("text/html", serialized.dom.innerHTML);
|
|
736
|
-
event.clipboardData?.setData("text/plain", serialized.text);
|
|
737
|
-
},
|
|
757
|
+
try: () => writeClipboard(pmView, data),
|
|
738
758
|
catch: () => new CanonicalSessionRefusalError({
|
|
739
759
|
ground: { gap: CANONICAL_GAP.dispatch },
|
|
740
760
|
message: "The clipboard could not receive the cut content."
|
|
741
761
|
})
|
|
742
762
|
});
|
|
743
|
-
if (copied.isErr())
|
|
744
|
-
|
|
763
|
+
if (copied.isErr()) {
|
|
764
|
+
refuse(copied.error.message, copied.error.ground);
|
|
765
|
+
return true;
|
|
766
|
+
}
|
|
767
|
+
clipboardCopy = {
|
|
768
|
+
type: "copied",
|
|
769
|
+
document: source,
|
|
770
|
+
...copied.value
|
|
771
|
+
};
|
|
772
|
+
publishCommit(prepared.value);
|
|
745
773
|
return true;
|
|
746
774
|
},
|
|
747
775
|
...canonicalInputLifecycle,
|
|
@@ -837,7 +865,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
837
865
|
},
|
|
838
866
|
handleTextInput: (pmView, from, to, text) => editorSession.type === "canonical" ? input.handleTextInput(pmView, from, to, text) : false,
|
|
839
867
|
handleKeyPress: (pmView, event) => editorSession.type === "canonical" && !deps.getReadOnly() && input.handleKeyPress(pmView, event),
|
|
840
|
-
handlePaste: (pmView,
|
|
868
|
+
handlePaste: (pmView, event, slice) => {
|
|
841
869
|
if (editorSession.type !== "canonical") return false;
|
|
842
870
|
if (deps.getReadOnly()) {
|
|
843
871
|
deps.onReadOnlyEditAttempt();
|
|
@@ -847,7 +875,8 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
847
875
|
const prepared = prepareCanonicalPaste({
|
|
848
876
|
session: editorSession.session,
|
|
849
877
|
state: pmView.state,
|
|
850
|
-
slice
|
|
878
|
+
slice,
|
|
879
|
+
...copiedSource(event)
|
|
851
880
|
});
|
|
852
881
|
if (prepared.isErr()) {
|
|
853
882
|
if (prepared.error.reason !== "noChange") refuse(prepared.error.message, prepared.error.ground);
|
|
@@ -906,6 +935,27 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
906
935
|
focus: () => false,
|
|
907
936
|
blur: (pmView) => editorSession.type === "canonical" ? input.handleDOMEvents.blur(pmView) : false,
|
|
908
937
|
...createHiddenEditorClipboardHandlers(deps),
|
|
938
|
+
copy: (pmView, event) => {
|
|
939
|
+
const data = event.clipboardData;
|
|
940
|
+
if (editorSession.type !== "canonical" || data === null || pmView.state.selection.empty) {
|
|
941
|
+
clipboardCopy = { type: "none" };
|
|
942
|
+
return createHiddenEditorClipboardHandlers(deps).copy();
|
|
943
|
+
}
|
|
944
|
+
const source = readModel(editorSession.session.document);
|
|
945
|
+
const written = Result.try(() => writeClipboard(pmView, data));
|
|
946
|
+
if (written.isErr()) {
|
|
947
|
+
clipboardCopy = { type: "none" };
|
|
948
|
+
return createHiddenEditorClipboardHandlers(deps).copy();
|
|
949
|
+
}
|
|
950
|
+
event.preventDefault();
|
|
951
|
+
clipboardCopy = {
|
|
952
|
+
type: "copied",
|
|
953
|
+
document: source,
|
|
954
|
+
...written.value
|
|
955
|
+
};
|
|
956
|
+
deps.onCopy?.();
|
|
957
|
+
return true;
|
|
958
|
+
},
|
|
909
959
|
compositionstart: (pmView) => editorSession.type === "canonical" ? input.handleDOMEvents.compositionstart(pmView) : false,
|
|
910
960
|
compositionend: (pmView, event) => editorSession.type === "canonical" ? input.handleDOMEvents.compositionend(pmView, event) : false,
|
|
911
961
|
input: (pmView) => editorSession.type === "canonical" ? input.handleDOMEvents.input(pmView) : false,
|
|
@@ -1272,8 +1322,18 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1272
1322
|
case "selection": {
|
|
1273
1323
|
const projection = session.projectStory(request.anchor.story);
|
|
1274
1324
|
if (projection.isErr()) return fail(projection.error.message);
|
|
1275
|
-
const
|
|
1276
|
-
const
|
|
1325
|
+
const { doc } = projection.value;
|
|
1326
|
+
const textEdge = (position, bias) => {
|
|
1327
|
+
if (position < 0 || position > doc.content.size) return position;
|
|
1328
|
+
const resolved = doc.resolve(position);
|
|
1329
|
+
if (resolved.parent.isTextblock) return position;
|
|
1330
|
+
const found = Selection.findFrom(resolved, bias, true);
|
|
1331
|
+
if (found === null) return position;
|
|
1332
|
+
return bias > 0 ? found.from : found.to;
|
|
1333
|
+
};
|
|
1334
|
+
const collapsed = request.anchor.from === request.anchor.to;
|
|
1335
|
+
const from = projection.value.addressAt(collapsed ? request.anchor.from : textEdge(request.anchor.from, 1));
|
|
1336
|
+
const to = projection.value.addressAt(collapsed ? request.anchor.to : textEdge(request.anchor.to, -1));
|
|
1277
1337
|
if (from.isErr()) return fail(from.error.message);
|
|
1278
1338
|
if (to.isErr()) return fail(to.error.message);
|
|
1279
1339
|
anchor = request.anchor.from === request.anchor.to ? {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ApplyFolioDocumentOperationsOptions, FolioDocumentOperationResult } from "./document-operations.js";
|
|
2
|
+
import { NumberingIdsInUse } from "./docx/numberingIds.js";
|
|
3
|
+
export declare const applyFolioDocumentOperations: (input: ApplyFolioDocumentOperationsOptions) => FolioDocumentOperationResult;
|
|
4
|
+
/**
|
|
5
|
+
* Options of a caller that holds every story of the package: the numbering
|
|
6
|
+
* ids (`w:num`, `w:abstractNum`) the other stories define. A list the batch
|
|
7
|
+
* starts takes none of them, so its id names it in every story and survives a
|
|
8
|
+
* save.
|
|
9
|
+
*/
|
|
10
|
+
type ApplyFolioDocumentOperationsInPackageOptions = ApplyFolioDocumentOperationsOptions & {
|
|
11
|
+
numberingIdsElsewhere: NumberingIdsInUse;
|
|
12
|
+
};
|
|
13
|
+
/** {@link applyFolioDocumentOperations} for a caller holding every story. Internal. */
|
|
14
|
+
export declare const applyFolioDocumentOperationsInPackage: ({ view, snapshot, batch, story, author, createCommentId, createUndoHandle, revisionStamp, wordDiff, tableTemplates, replacementBackground, undefinedReferences, pendingSuggestionIds, numberingIdsElsewhere, restagesSuggestions }: ApplyFolioDocumentOperationsInPackageOptions) => FolioDocumentOperationResult;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { applyFolioAIEditOperationsInPackage, previewFolioAIEditOperationsWithResult } from "./ai-edits/apply.js";
|
|
2
|
+
import { describeModelError, findIntroducedModelErrors } from "./ai-edits/result-validation.js";
|
|
3
|
+
import { trackedBatchFidelityError } from "./ai-edits/tracked-batch-fidelity.js";
|
|
4
|
+
import { getFolioDocumentOperationIssues, getFolioDocumentOperationReceiptsForStory, parseFolioDocumentOperationBatch, withDistinctSuggestionIds } from "./document-operations.js";
|
|
5
|
+
import { NO_NUMBERING_IDS_IN_USE } from "./docx/numberingIds.js";
|
|
6
|
+
import { getSuggestions } from "./prosemirror/commands/comments.js";
|
|
7
|
+
import { completeNumberingForDoc } from "./prosemirror/listInstanceReferences.js";
|
|
8
|
+
import { getStatedDocumentNumbering } from "./prosemirror/plugins/documentNumbering.js";
|
|
9
|
+
// src/document-operations-apply.ts
|
|
10
|
+
const NO_COMMIT = () => {};
|
|
11
|
+
/** Skips reported in the order of the operations they belong to. */
|
|
12
|
+
const inOperationOrder = (operations, skipped) => {
|
|
13
|
+
const indexById = new Map(operations.map(({ id }, index) => [id, index]));
|
|
14
|
+
return [...skipped].sort((left, right) => (indexById.get(left.id) ?? -1) - (indexById.get(right.id) ?? -1));
|
|
15
|
+
};
|
|
16
|
+
const applyFolioDocumentOperations = (input) => applyFolioDocumentOperationsInPackage({
|
|
17
|
+
...input,
|
|
18
|
+
numberingIdsElsewhere: NO_NUMBERING_IDS_IN_USE
|
|
19
|
+
});
|
|
20
|
+
/** {@link applyFolioDocumentOperations} for a caller holding every story. Internal. */
|
|
21
|
+
const applyFolioDocumentOperationsInPackage = ({ view, snapshot, batch, story = "main", author, createCommentId, createUndoHandle, revisionStamp, wordDiff, tableTemplates, replacementBackground, undefinedReferences, pendingSuggestionIds, numberingIdsElsewhere, restagesSuggestions }) => {
|
|
22
|
+
const validatedBatch = parseFolioDocumentOperationBatch(batch);
|
|
23
|
+
const parsedBatch = restagesSuggestions === true ? validatedBatch : withDistinctSuggestionIds(validatedBatch, /* @__PURE__ */ new Set([...getSuggestions(view.state).map(({ suggestionId }) => suggestionId), ...pendingSuggestionIds ?? []]));
|
|
24
|
+
const isAtomic = parsedBatch.atomic === true;
|
|
25
|
+
const beforeDoc = view.state.doc;
|
|
26
|
+
const packageNumbering = getStatedDocumentNumbering(view.state);
|
|
27
|
+
const attempt = (operations, preview) => {
|
|
28
|
+
const common = {
|
|
29
|
+
snapshot,
|
|
30
|
+
operations,
|
|
31
|
+
mode: parsedBatch.mode ?? "tracked-changes",
|
|
32
|
+
...parsedBatch.existingRevisions === "refuse-cross-author" && { refuseCrossAuthorRevisions: true },
|
|
33
|
+
...author !== void 0 && { author },
|
|
34
|
+
...revisionStamp !== void 0 && { revisionStamp },
|
|
35
|
+
...wordDiff !== void 0 && { wordDiff },
|
|
36
|
+
...tableTemplates !== void 0 && { tableTemplates },
|
|
37
|
+
...replacementBackground !== void 0 && { replacementBackground },
|
|
38
|
+
numberingIdsElsewhere,
|
|
39
|
+
undefinedReferences
|
|
40
|
+
};
|
|
41
|
+
if (preview) return {
|
|
42
|
+
...previewFolioAIEditOperationsWithResult({
|
|
43
|
+
...common,
|
|
44
|
+
view,
|
|
45
|
+
...createCommentId !== void 0 && { createCommentId }
|
|
46
|
+
}, parsedBatch.dryRun && common.mode === "tracked-changes" ? "bounded" : "coarse"),
|
|
47
|
+
commit: NO_COMMIT
|
|
48
|
+
};
|
|
49
|
+
const held = {};
|
|
50
|
+
const commentIds = [];
|
|
51
|
+
return {
|
|
52
|
+
outcome: applyFolioAIEditOperationsInPackage({
|
|
53
|
+
...common,
|
|
54
|
+
view: {
|
|
55
|
+
state: view.state,
|
|
56
|
+
dispatch: (transaction) => {
|
|
57
|
+
held.transaction = transaction;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
...createCommentId !== void 0 && { createCommentId: (text) => {
|
|
61
|
+
const id = createCommentId(text);
|
|
62
|
+
commentIds.push(id);
|
|
63
|
+
return id;
|
|
64
|
+
} }
|
|
65
|
+
}),
|
|
66
|
+
doc: held.transaction?.doc ?? null,
|
|
67
|
+
commentIds,
|
|
68
|
+
commit: () => {
|
|
69
|
+
if (held.transaction !== void 0) view.dispatch(held.transaction);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
const introducedErrors = (run) => {
|
|
74
|
+
if (run.doc === null || run.outcome.applied.length === 0) return [];
|
|
75
|
+
const numbering = packageNumbering === void 0 ? void 0 : completeNumberingForDoc(packageNumbering ?? void 0, run.doc) ?? null;
|
|
76
|
+
return findIntroducedModelErrors(beforeDoc, run.doc, {
|
|
77
|
+
numbering,
|
|
78
|
+
createdCommentIds: run.commentIds,
|
|
79
|
+
...author !== void 0 && { commentAuthor: author }
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* An attempt on the refusal path, where the applier runs on subsets of the
|
|
84
|
+
* batch it was not asked to apply: a throw there is one more reason to
|
|
85
|
+
* refuse, never a reason to fail a batch the first run could apply.
|
|
86
|
+
*/
|
|
87
|
+
const checkedAttempt = (operations, preview) => {
|
|
88
|
+
try {
|
|
89
|
+
const run = attempt(operations, preview);
|
|
90
|
+
return {
|
|
91
|
+
run,
|
|
92
|
+
error: introducedErrors(run)[0]
|
|
93
|
+
};
|
|
94
|
+
} catch (error) {
|
|
95
|
+
return {
|
|
96
|
+
run: null,
|
|
97
|
+
error: {
|
|
98
|
+
path: "package.document",
|
|
99
|
+
message: `the operation could not be applied (${error instanceof Error ? error.message : String(error)}).`,
|
|
100
|
+
severity: "error"
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Which applied operations produced the unsaveable result: each one is
|
|
107
|
+
* previewed alone against the unchanged story. When none fails alone, the
|
|
108
|
+
* failure is their combination, and every one of them is refused.
|
|
109
|
+
*/
|
|
110
|
+
const refuseInvalidResult = (run, firstError) => {
|
|
111
|
+
const operationsById = new Map(parsedBatch.operations.map((operation) => [operation.id, operation]));
|
|
112
|
+
const refused = [];
|
|
113
|
+
for (const { id } of run.outcome.applied) {
|
|
114
|
+
const operation = operationsById.get(id);
|
|
115
|
+
if (operation === void 0) continue;
|
|
116
|
+
const alone = checkedAttempt([operation], true).error;
|
|
117
|
+
if (alone !== void 0) refused.push({
|
|
118
|
+
id,
|
|
119
|
+
reason: "invalidResult",
|
|
120
|
+
message: describeModelError(alone)
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (refused.length > 0) return refused;
|
|
124
|
+
return run.outcome.applied.map(({ id }) => ({
|
|
125
|
+
id,
|
|
126
|
+
reason: "invalidResult",
|
|
127
|
+
message: describeModelError(firstError)
|
|
128
|
+
}));
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* A fidelity failure invalidates the batch. Preserve the refusal details
|
|
132
|
+
* for operations already skipped by the applier or save-time validator.
|
|
133
|
+
*/
|
|
134
|
+
const refuseFidelityLoss = (run, skipped = []) => {
|
|
135
|
+
if (run.doc === null || parsedBatch.mode === "direct" || parsedBatch.mode === "suggested") return null;
|
|
136
|
+
const message = trackedBatchFidelityError({
|
|
137
|
+
before: view.state,
|
|
138
|
+
after: run.doc,
|
|
139
|
+
createdCommentIds: run.commentIds,
|
|
140
|
+
retiredCommentIds: run.outcome.applied.flatMap(({ retiredCommentIds }) => retiredCommentIds ?? [])
|
|
141
|
+
});
|
|
142
|
+
if (message === null) return null;
|
|
143
|
+
return {
|
|
144
|
+
fidelityRefused: true,
|
|
145
|
+
outcome: {
|
|
146
|
+
...run.outcome,
|
|
147
|
+
applied: [],
|
|
148
|
+
skipped: inOperationOrder(parsedBatch.operations, [
|
|
149
|
+
...run.outcome.skipped,
|
|
150
|
+
...skipped,
|
|
151
|
+
...run.outcome.applied.map(({ id }) => ({
|
|
152
|
+
id,
|
|
153
|
+
reason: "invalidResult",
|
|
154
|
+
message
|
|
155
|
+
}))
|
|
156
|
+
])
|
|
157
|
+
},
|
|
158
|
+
commit: NO_COMMIT
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
/** Check the held result before dispatching any operation to the caller. */
|
|
162
|
+
const guardedAttempt = (preview) => {
|
|
163
|
+
const first = attempt(parsedBatch.operations, preview);
|
|
164
|
+
const [firstError] = introducedErrors(first);
|
|
165
|
+
if (firstError === void 0) {
|
|
166
|
+
const fidelity = preview && !parsedBatch.dryRun ? null : refuseFidelityLoss(first);
|
|
167
|
+
if (fidelity !== null) return fidelity;
|
|
168
|
+
return {
|
|
169
|
+
outcome: {
|
|
170
|
+
...first.outcome,
|
|
171
|
+
skipped: inOperationOrder(parsedBatch.operations, first.outcome.skipped)
|
|
172
|
+
},
|
|
173
|
+
commit: first.commit
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
const refused = refuseInvalidResult(first, firstError);
|
|
177
|
+
const refusedIds = new Set(refused.map(({ id }) => id));
|
|
178
|
+
if (isAtomic) return {
|
|
179
|
+
outcome: {
|
|
180
|
+
...first.outcome,
|
|
181
|
+
applied: [],
|
|
182
|
+
skipped: inOperationOrder(parsedBatch.operations, [...first.outcome.skipped, ...refused])
|
|
183
|
+
},
|
|
184
|
+
commit: NO_COMMIT
|
|
185
|
+
};
|
|
186
|
+
const second = checkedAttempt(parsedBatch.operations.filter(({ id }) => !refusedIds.has(id)), preview);
|
|
187
|
+
if (second.run === null || second.error !== void 0) {
|
|
188
|
+
const reported = second.run?.outcome ?? first.outcome;
|
|
189
|
+
return {
|
|
190
|
+
outcome: {
|
|
191
|
+
...reported,
|
|
192
|
+
applied: [],
|
|
193
|
+
skipped: inOperationOrder(parsedBatch.operations, [
|
|
194
|
+
...reported.skipped.filter(({ id }) => !refusedIds.has(id)),
|
|
195
|
+
...refused,
|
|
196
|
+
...reported.applied.filter(({ id }) => !refusedIds.has(id)).map(({ id }) => ({
|
|
197
|
+
id,
|
|
198
|
+
reason: "invalidResult",
|
|
199
|
+
message: describeModelError(second.error ?? firstError)
|
|
200
|
+
}))
|
|
201
|
+
])
|
|
202
|
+
},
|
|
203
|
+
commit: NO_COMMIT
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const fidelity = refuseFidelityLoss(second.run, refused);
|
|
207
|
+
if (fidelity !== null) return fidelity;
|
|
208
|
+
return {
|
|
209
|
+
outcome: {
|
|
210
|
+
...second.run.outcome,
|
|
211
|
+
skipped: inOperationOrder(parsedBatch.operations, [...second.run.outcome.skipped, ...refused])
|
|
212
|
+
},
|
|
213
|
+
commit: second.run.commit
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
const preview = () => guardedAttempt(true).outcome;
|
|
217
|
+
const atomicResult = (previewResult, status) => {
|
|
218
|
+
const skippedById = new Map(previewResult.skipped.map((operation) => [operation.id, operation]));
|
|
219
|
+
const skipped = parsedBatch.operations.map(({ id }) => skippedById.get(id) ?? {
|
|
220
|
+
id,
|
|
221
|
+
reason: "atomicBatchRejected"
|
|
222
|
+
});
|
|
223
|
+
return {
|
|
224
|
+
version: 1,
|
|
225
|
+
status,
|
|
226
|
+
applied: [],
|
|
227
|
+
skipped,
|
|
228
|
+
issues: getFolioDocumentOperationIssues(parsedBatch.operations, skipped),
|
|
229
|
+
receipts: [],
|
|
230
|
+
...previewResult.normalizations !== void 0 && { normalizations: previewResult.normalizations },
|
|
231
|
+
undoHandle: null,
|
|
232
|
+
nextRevisionId: previewResult.nextRevisionId
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
if (parsedBatch.dryRun === true) {
|
|
236
|
+
const previewResult = preview();
|
|
237
|
+
if (isAtomic && previewResult.skipped.length > 0) return atomicResult(previewResult, "previewed");
|
|
238
|
+
return {
|
|
239
|
+
version: 1,
|
|
240
|
+
status: "previewed",
|
|
241
|
+
applied: previewResult.applied.map(({ id, paragraphIdentity, retiredCommentIds }) => ({
|
|
242
|
+
id,
|
|
243
|
+
...paragraphIdentity === void 0 ? {} : { paragraphIdentity },
|
|
244
|
+
...retiredCommentIds === void 0 ? {} : { retiredCommentIds }
|
|
245
|
+
})),
|
|
246
|
+
skipped: previewResult.skipped,
|
|
247
|
+
issues: getFolioDocumentOperationIssues(parsedBatch.operations, previewResult.skipped),
|
|
248
|
+
receipts: getFolioDocumentOperationReceiptsForStory({
|
|
249
|
+
operations: parsedBatch.operations,
|
|
250
|
+
applied: previewResult.applied,
|
|
251
|
+
story
|
|
252
|
+
}),
|
|
253
|
+
...previewResult.normalizations !== void 0 && { normalizations: previewResult.normalizations },
|
|
254
|
+
undoHandle: null,
|
|
255
|
+
nextRevisionId: previewResult.nextRevisionId
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
if (isAtomic) {
|
|
259
|
+
const previewResult = preview();
|
|
260
|
+
if (previewResult.skipped.length > 0) return atomicResult(previewResult, "rejected");
|
|
261
|
+
}
|
|
262
|
+
const guarded = guardedAttempt(false);
|
|
263
|
+
const { heldRevisionConflict, ...result } = guarded.outcome;
|
|
264
|
+
if (heldRevisionConflict) return atomicResult(result, "rejected");
|
|
265
|
+
if (guarded.fidelityRefused === true || isAtomic && result.skipped.some(({ reason }) => reason === "invalidResult")) return atomicResult(result, "rejected");
|
|
266
|
+
guarded.commit();
|
|
267
|
+
return {
|
|
268
|
+
version: 1,
|
|
269
|
+
status: "committed",
|
|
270
|
+
...result,
|
|
271
|
+
issues: getFolioDocumentOperationIssues(parsedBatch.operations, result.skipped),
|
|
272
|
+
receipts: getFolioDocumentOperationReceiptsForStory({
|
|
273
|
+
operations: parsedBatch.operations,
|
|
274
|
+
applied: result.applied,
|
|
275
|
+
story
|
|
276
|
+
}),
|
|
277
|
+
undoHandle: result.applied.length > 0 && createUndoHandle !== void 0 ? createUndoHandle() : null
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
export { applyFolioDocumentOperations, applyFolioDocumentOperationsInPackage };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { FolioAIEditView, FolioReplacementBackground, FolioRevisionStamp, FolioWordDiffOptions } from "./ai-edits/
|
|
1
|
+
import { FolioAIEditView, FolioReplacementBackground, FolioRevisionStamp, FolioWordDiffOptions } from "./ai-edits/applyTypes.js";
|
|
2
2
|
import { FolioTableTemplates } from "./ai-edits/table-template.js";
|
|
3
3
|
import { FolioAIEditAppliedOperation, FolioAIEditApplyMode, FolioAIEditNormalization, FolioAIEditOperation, FolioAIEditPrecondition, FolioAIEditSkippedOperation, FolioAIEditSnapshot, FolioAINewListReference, FolioAITextRangeHandle } from "./ai-edits/types.js";
|
|
4
4
|
import { FolioUndefinedReferencePolicy } from "./ai-edits/undefinedReferences.js";
|
|
5
|
-
import { NumberingIdsInUse } from "./docx/numberingIds.js";
|
|
6
5
|
import { document_d_exports } from "./types/document.js";
|
|
7
6
|
import { TaggedErrorClass } from "better-result";
|
|
8
7
|
export declare const FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION: 1;
|
|
@@ -352,16 +351,4 @@ export type ApplyFolioDocumentOperationsOptions = {
|
|
|
352
351
|
* by that id follows it.
|
|
353
352
|
*/
|
|
354
353
|
export declare const withDistinctSuggestionIds: (batch: FolioDocumentOperationBatch, pending: ReadonlySet<string>) => FolioDocumentOperationBatch;
|
|
355
|
-
export declare const applyFolioDocumentOperations: (input: ApplyFolioDocumentOperationsOptions) => FolioDocumentOperationResult;
|
|
356
|
-
/**
|
|
357
|
-
* Options of a caller that holds every story of the package: the numbering
|
|
358
|
-
* ids (`w:num`, `w:abstractNum`) the other stories define. A list the batch
|
|
359
|
-
* starts takes none of them, so its id names it in every story and survives a
|
|
360
|
-
* save.
|
|
361
|
-
*/
|
|
362
|
-
type ApplyFolioDocumentOperationsInPackageOptions = ApplyFolioDocumentOperationsOptions & {
|
|
363
|
-
numberingIdsElsewhere: NumberingIdsInUse;
|
|
364
|
-
};
|
|
365
|
-
/** {@link applyFolioDocumentOperations} for a caller holding every story. Internal. */
|
|
366
|
-
export declare const applyFolioDocumentOperationsInPackage: ({ view, snapshot, batch, story, author, createCommentId, createUndoHandle, revisionStamp, wordDiff, tableTemplates, replacementBackground, undefinedReferences, pendingSuggestionIds, numberingIdsElsewhere, restagesSuggestions }: ApplyFolioDocumentOperationsInPackageOptions) => FolioDocumentOperationResult;
|
|
367
354
|
export {};
|