@stll/folio-core 0.74.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 +18 -9
- 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 +6 -2
- 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/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/canonicalPublicOperations.js +29 -9
- package/dist/canonical/canonicalRefusalGrounds.d.ts +4 -0
- package/dist/canonical/canonicalRefusalGrounds.js +56 -0
- package/dist/canonical/canonicalSession.d.ts +12 -6
- package/dist/canonical/canonicalSession.js +116 -121
- 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/canonicalClipboard.js +43 -42
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +5 -5
- package/dist/controller/canonicalInput.d.ts +4 -2
- package/dist/controller/canonicalInput.js +33 -16
- 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 +139 -42
- 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 +2 -0
- package/dist/controller/hiddenEditorManager.js +132 -189
- 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/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/listMarkerComputation.d.ts +24 -17
- package/dist/docx/listMarkerComputation.js +31 -60
- package/dist/docx/listModelNormalization.js +8 -15
- package/dist/docx/rezip.d.ts +16 -3
- package/dist/docx/rezip.js +35 -9
- package/dist/docx/selectiveSave.js +13 -5
- package/dist/docx/server/templatePlan/apply.js +38 -3
- 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 +19 -52
- package/dist/docx/server/templatePlan/labels.d.ts +7 -2
- package/dist/docx/server/templatePlan/labels.js +104 -22
- package/dist/docx/server/templatePlan/plan.d.ts +13 -1
- package/dist/docx/server/templatePlan/plan.js +22 -7
- package/dist/docx/server/templatePlan/planShape.js +31 -2
- 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 +138 -16
- package/dist/docx/server/templatePlan/verify.js +50 -9
- 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/layout-bridge/convert/toFlowBlocks.js +0 -12
- package/dist/layout-bridge/convert/topLevelConversion.js +1 -10
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +1 -1
- package/dist/prosemirror/listMarker.d.ts +1 -6
- package/dist/prosemirror/listMarker.js +4 -56
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +40 -45
- package/dist/types/canonicalCapabilities.js +51 -43
- 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
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { CanonicalSessionError } from "../canonical/canonicalSession.js";
|
|
2
2
|
import { createNativeNavigationPlugin, createNativeSelectionRefreshPlugin } from "../prosemirror/nativeSelection.js";
|
|
3
|
-
import { noteReferenceTransactionIssue } from "../prosemirror/noteReferenceOccurrences.js";
|
|
4
3
|
import { createDocumentNumberingPlugin } from "../prosemirror/plugins/documentNumbering.js";
|
|
5
4
|
import { createDocumentStyleContextPlugin } from "../prosemirror/plugins/documentStyles.js";
|
|
6
|
-
import {
|
|
5
|
+
import { CANONICAL_CONDITION } from "../types/canonicalCapabilities.js";
|
|
7
6
|
import { readModel } from "../types/documentModel.js";
|
|
8
7
|
import { createCanonicalStoryEditor, refreshCanonicalStoryView } from "./canonicalStoryEditor.js";
|
|
9
8
|
import { OP_STORIES } from "@stll/docx-core/ops";
|
|
@@ -98,7 +97,6 @@ const createHeaderFooterEditorManager = (deps) => {
|
|
|
98
97
|
},
|
|
99
98
|
getView: () => view,
|
|
100
99
|
getApi: () => deps.getCanonicalApi?.() ?? null,
|
|
101
|
-
enabled: () => true,
|
|
102
100
|
onRefusal: deps.onSessionRefusal,
|
|
103
101
|
onSelectionChange: () => deps.onTransaction?.({
|
|
104
102
|
kind: part.kind,
|
|
@@ -131,19 +129,7 @@ const createHeaderFooterEditorManager = (deps) => {
|
|
|
131
129
|
}),
|
|
132
130
|
dispatchTransaction(transaction) {
|
|
133
131
|
if ((deps.getReadOnly?.() ?? false) && transaction.docChanged) return;
|
|
134
|
-
|
|
135
|
-
const nextState = view.state.apply(transaction);
|
|
136
|
-
const docChanged = !nextState.doc.eq(view.state.doc);
|
|
137
|
-
const noteIssue = noteReferenceTransactionIssue(transaction);
|
|
138
|
-
if (noteIssue) deps.onSessionRefusal?.(noteIssue.message, { gap: CANONICAL_GAP.dispatch }, noteIssue);
|
|
139
|
-
view.updateState(nextState);
|
|
140
|
-
deps.onTransaction?.({
|
|
141
|
-
docChanged,
|
|
142
|
-
kind: part.kind,
|
|
143
|
-
rId: part.rId,
|
|
144
|
-
selectionChanged: transaction.selectionSet,
|
|
145
|
-
view
|
|
146
|
-
});
|
|
132
|
+
canonical.dispatch(transaction);
|
|
147
133
|
}
|
|
148
134
|
});
|
|
149
135
|
mounted.set(part.rId, {
|
|
@@ -165,7 +151,7 @@ const createHeaderFooterEditorManager = (deps) => {
|
|
|
165
151
|
const canonical = deps.getCanonicalApi?.()?.getCanonicalDocument();
|
|
166
152
|
if (canonical) return canonical;
|
|
167
153
|
throw new CanonicalSessionError({
|
|
168
|
-
ground: {
|
|
154
|
+
ground: { condition: CANONICAL_CONDITION.notReady },
|
|
169
155
|
reason: "refused",
|
|
170
156
|
message: "Canonical story snapshot is unavailable."
|
|
171
157
|
});
|
|
@@ -19,7 +19,7 @@ import { ReadonlyDocument } from "../types/documentModel.js";
|
|
|
19
19
|
import { FolioDocxSerializationPath } from "../types/docxSerialization.js";
|
|
20
20
|
import { FolioFieldInsertion } from "../types/fields.js";
|
|
21
21
|
import { AnonymizationHighlightsView } from "./anonymizationHighlights.js";
|
|
22
|
-
import { createCanonicalInputBoundary } from "./canonicalInput.js";
|
|
22
|
+
import { CanonicalStructureInput, createCanonicalInputBoundary } from "./canonicalInput.js";
|
|
23
23
|
import { Command, EditorState, Transaction } from "prosemirror-state";
|
|
24
24
|
import { Node } from "prosemirror-model";
|
|
25
25
|
import { DocumentOp, FormattingPatch, OpStory, TextPosition } from "@stll/docx-core/ops";
|
|
@@ -47,6 +47,16 @@ type CanonicalStoryTextOptions = {
|
|
|
47
47
|
story: OpStory;
|
|
48
48
|
intent: Parameters<Parameters<typeof createCanonicalInputBoundary>[0]["replace"]>[0];
|
|
49
49
|
};
|
|
50
|
+
type CanonicalStoryStructureOptions = {
|
|
51
|
+
view: EditorView;
|
|
52
|
+
story: OpStory;
|
|
53
|
+
type: CanonicalStructureInput;
|
|
54
|
+
};
|
|
55
|
+
type CanonicalStoryCutOptions = {
|
|
56
|
+
view: EditorView;
|
|
57
|
+
story: OpStory;
|
|
58
|
+
event: ClipboardEvent;
|
|
59
|
+
};
|
|
50
60
|
/** The package a canonical save wrote, and whether it patched its baseline. */
|
|
51
61
|
export type CanonicalSavedPackage = {
|
|
52
62
|
buffer: ArrayBuffer;
|
|
@@ -99,7 +109,7 @@ export type HiddenEditorApi = {
|
|
|
99
109
|
applyCanonicalStoryHistory: (options: CanonicalStoryHistoryOptions) => boolean;
|
|
100
110
|
applyCanonicalOperations: (ops: readonly DocumentOp[]) => boolean;
|
|
101
111
|
applyCanonicalComment: (request: CanonicalCommentRequest) => CanonicalCommentResult | null;
|
|
102
|
-
/** Apply a final-section patch
|
|
112
|
+
/** Apply a final-section patch to the canonical session. */
|
|
103
113
|
applyCanonicalSectionProperties: (patch: FormattingPatch<document_d_exports.SectionProperties>) => CanonicalSectionPropertiesResult | null;
|
|
104
114
|
/**
|
|
105
115
|
* Where the editor of a header, footer or note shows its text selection in
|
|
@@ -113,6 +123,17 @@ export type HiddenEditorApi = {
|
|
|
113
123
|
} | null;
|
|
114
124
|
getCanonicalStoryProjection: (story: OpStory) => Node | null;
|
|
115
125
|
replaceCanonicalStoryText: (options: CanonicalStoryTextOptions) => boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Make the structure edit a key asks for in the editor of a header, footer
|
|
128
|
+
* or note, as the body's editor makes it: one journalled change.
|
|
129
|
+
*/
|
|
130
|
+
applyCanonicalStoryStructure: (options: CanonicalStoryStructureOptions) => boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Cut the selection of a header, footer or note editor: the clipboard takes
|
|
133
|
+
* it and the story loses it, as one journalled change. True when the editor
|
|
134
|
+
* handled the event.
|
|
135
|
+
*/
|
|
136
|
+
cutCanonicalStory: (options: CanonicalStoryCutOptions) => boolean;
|
|
116
137
|
/**
|
|
117
138
|
* The editor a person is working in for `story`: public operations on that
|
|
118
139
|
* story read its state, so its selection maps through them, and publish to
|
|
@@ -193,7 +214,7 @@ export type HiddenEditorApiDeps = {
|
|
|
193
214
|
resolveCanonicalSuggestion?: HiddenEditorApi["resolveCanonicalSuggestion"];
|
|
194
215
|
executeCanonicalCommand?: (command: Command) => boolean | undefined;
|
|
195
216
|
getCanonicalHistory?: () => Pick<HiddenEditorApi, "undo" | "redo" | "canUndo" | "canRedo"> | null;
|
|
196
|
-
canonicalOperations?: Pick<HiddenEditorApi, "updateCanonicalInputLifecycle" | "applyCanonicalOperations" | "applyCanonicalComment" | "applyCanonicalSectionProperties" | "getCanonicalStoryProjection" | "replaceCanonicalStoryText" | "noteCanonicalStoryView" | "applyCanonicalStoryHistory" | "getCanonicalStorySelection" | "applyCanonicalDocumentOperations" | "undoCanonicalDocumentOperations">;
|
|
217
|
+
canonicalOperations?: Pick<HiddenEditorApi, "updateCanonicalInputLifecycle" | "applyCanonicalOperations" | "applyCanonicalComment" | "applyCanonicalSectionProperties" | "getCanonicalStoryProjection" | "replaceCanonicalStoryText" | "applyCanonicalStoryStructure" | "cutCanonicalStory" | "noteCanonicalStoryView" | "applyCanonicalStoryHistory" | "getCanonicalStorySelection" | "applyCanonicalDocumentOperations" | "undoCanonicalDocumentOperations">;
|
|
197
218
|
isDestroying: () => boolean;
|
|
198
219
|
ensureView: () => void;
|
|
199
220
|
isViewRequested: () => boolean;
|
|
@@ -82,6 +82,8 @@ const createHiddenEditorApi = (deps) => {
|
|
|
82
82
|
getCanonicalStorySelection: (story) => deps.canonicalOperations?.getCanonicalStorySelection(story) ?? null,
|
|
83
83
|
getCanonicalStoryProjection: (story) => deps.canonicalOperations?.getCanonicalStoryProjection(story) ?? null,
|
|
84
84
|
replaceCanonicalStoryText: (options) => deps.canonicalOperations?.replaceCanonicalStoryText(options) ?? false,
|
|
85
|
+
applyCanonicalStoryStructure: (options) => deps.canonicalOperations?.applyCanonicalStoryStructure(options) ?? false,
|
|
86
|
+
cutCanonicalStory: (options) => deps.canonicalOperations?.cutCanonicalStory(options) ?? false,
|
|
85
87
|
noteCanonicalStoryView: (options) => {
|
|
86
88
|
deps.canonicalOperations?.noteCanonicalStoryView(options);
|
|
87
89
|
},
|
|
@@ -22,20 +22,20 @@ import { toggleMarkForAllScripts, toggleUnderlineMark } from "../prosemirror/ext
|
|
|
22
22
|
import { HyperlinkRemovalRefusal } from "../prosemirror/hyperlinkRemoval.js";
|
|
23
23
|
import { REVISION_MARK_NAMES } from "../prosemirror/keptRangeBoundaries.js";
|
|
24
24
|
import { adoptNativeSelection, createNativeNavigationPlugin, createNativeSelectionRefreshPlugin, isCompositionKeyDown } from "../prosemirror/nativeSelection.js";
|
|
25
|
-
import { noteReferenceTransactionIssue } from "../prosemirror/noteReferenceOccurrences.js";
|
|
25
|
+
import { NoteReferenceReplayDefect, noteReferenceTransactionIssue } from "../prosemirror/noteReferenceOccurrences.js";
|
|
26
26
|
import { ensureParaIdsInDoc } from "../prosemirror/paraIds.js";
|
|
27
27
|
import { createDocumentNumberingPlugin } from "../prosemirror/plugins/documentNumbering.js";
|
|
28
28
|
import { createDocumentStyleContextPlugin, createDocumentStylesPlugin } from "../prosemirror/plugins/documentStyles.js";
|
|
29
29
|
import { schema } from "../prosemirror/schema/index.js";
|
|
30
|
-
import { CANONICAL_GAP, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
|
|
30
|
+
import { CANONICAL_CONDITION, CANONICAL_GAP, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
|
|
31
31
|
import { readModel } from "../types/documentModel.js";
|
|
32
|
-
import { INTERNAL_CLIPBOARD_TYPE } from "../utils/
|
|
32
|
+
import { INTERNAL_CLIPBOARD_TYPE } from "../utils/clipboardFiles.js";
|
|
33
33
|
import { NO_ANONYMIZATION_TERMS, createAnonymizationHighlights } from "./anonymizationHighlights.js";
|
|
34
34
|
import { canTriggerAutocomplete, classifyAutocompleteEdit, createAutocompleteSuggestion, nextAutocompleteWord } from "./autocompleteSuggestion.js";
|
|
35
35
|
import { prepareCanonicalPaste } from "./canonicalClipboard.js";
|
|
36
36
|
import { createCanonicalInputBoundary, unclassifiedMutationMessage } from "./canonicalInput.js";
|
|
37
37
|
import { openCanonicalRoomEditor } from "./canonicalRoomEditor.js";
|
|
38
|
-
import {
|
|
38
|
+
import { prepareCanonicalAutoformat, prepareCanonicalCommands, prepareCanonicalStructure } from "./canonicalStructure.js";
|
|
39
39
|
import { createHiddenEditorApi } from "./hiddenEditorApi.js";
|
|
40
40
|
import { handleReadOnlySelectionKeyDown } from "./readOnlySelection.js";
|
|
41
41
|
import { Result, TaggedError } from "better-result";
|
|
@@ -186,7 +186,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
186
186
|
author: deps.getSuggestionAuthor?.() ?? "User"
|
|
187
187
|
} : { type: "editing" }));
|
|
188
188
|
};
|
|
189
|
-
const refuse = (reason, ground
|
|
189
|
+
const refuse = (reason, ground) => {
|
|
190
190
|
const message = reason;
|
|
191
191
|
if (deps.onSessionRefusal) deps.onSessionRefusal(message, ground);
|
|
192
192
|
else throw new CanonicalSessionRefusalError({
|
|
@@ -217,7 +217,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
217
217
|
reason,
|
|
218
218
|
documentIdentity
|
|
219
219
|
};
|
|
220
|
-
refuse(reason, {
|
|
220
|
+
refuse(reason, { condition: CANONICAL_CONDITION.notReady });
|
|
221
221
|
return false;
|
|
222
222
|
}
|
|
223
223
|
const result = createCanonicalSession(document, deps.getStyles());
|
|
@@ -335,7 +335,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
335
335
|
const { state } = view;
|
|
336
336
|
const { session } = editorSession;
|
|
337
337
|
if (state.selection instanceof CellSelection) {
|
|
338
|
-
refuse("A field goes in at a text selection, not over cells.");
|
|
338
|
+
refuse("A field goes in at a text selection, not over cells.", { condition: CANONICAL_CONDITION.invalidRequest });
|
|
339
339
|
return false;
|
|
340
340
|
}
|
|
341
341
|
const range = canonicalSelectionRange(state);
|
|
@@ -373,7 +373,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
373
373
|
*/
|
|
374
374
|
const publishRemote = (session, commit) => {
|
|
375
375
|
if (!view || isDestroying || editorSession.type !== "canonical" || editorSession.session !== session) return Result.err(new CanonicalSessionError({
|
|
376
|
-
ground: {
|
|
376
|
+
ground: { condition: CANONICAL_CONDITION.notReady },
|
|
377
377
|
message: "The editor showing the room is closed.",
|
|
378
378
|
reason: "refused"
|
|
379
379
|
}));
|
|
@@ -494,7 +494,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
494
494
|
const direction = getCanonicalHistoryDirection(command);
|
|
495
495
|
if (direction !== void 0) return history(direction);
|
|
496
496
|
if (editorSession.session.isComposing) {
|
|
497
|
-
refuse("Composition must finish before formatting.");
|
|
497
|
+
refuse("Composition must finish before formatting.", { condition: CANONICAL_CONDITION.composing });
|
|
498
498
|
return false;
|
|
499
499
|
}
|
|
500
500
|
const commandState = view.state;
|
|
@@ -544,6 +544,58 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
544
544
|
token
|
|
545
545
|
};
|
|
546
546
|
};
|
|
547
|
+
/**
|
|
548
|
+
* Cut the selection of the editor showing `story`: the clipboard takes it
|
|
549
|
+
* first, and the story loses it only once the clipboard holds it.
|
|
550
|
+
*/
|
|
551
|
+
const cutCanonical = (pmView, event, story) => {
|
|
552
|
+
event.preventDefault();
|
|
553
|
+
if (deps.getReadOnly()) {
|
|
554
|
+
deps.onReadOnlyEditAttempt();
|
|
555
|
+
return true;
|
|
556
|
+
}
|
|
557
|
+
deps.onCut?.();
|
|
558
|
+
if (editorSession.type !== "canonical" || pmView.state.selection.empty) return true;
|
|
559
|
+
if (event.clipboardData === null) {
|
|
560
|
+
refuse("The clipboard cannot receive the cut content.", { condition: CANONICAL_CONDITION.invalidRequest });
|
|
561
|
+
return true;
|
|
562
|
+
}
|
|
563
|
+
syncCanonicalMode();
|
|
564
|
+
const source = readModel(editorSession.session.document);
|
|
565
|
+
const session = editorSession.session;
|
|
566
|
+
const { from, to } = pmView.state.selection;
|
|
567
|
+
const prepared = session.prepareReplace(pmView.state, {
|
|
568
|
+
from,
|
|
569
|
+
to,
|
|
570
|
+
text: "",
|
|
571
|
+
semantic: "replacement",
|
|
572
|
+
story
|
|
573
|
+
});
|
|
574
|
+
if (prepared.isErr()) {
|
|
575
|
+
refuse(prepared.error.message, prepared.error.ground);
|
|
576
|
+
return true;
|
|
577
|
+
}
|
|
578
|
+
const data = event.clipboardData;
|
|
579
|
+
const copied = Result.try({
|
|
580
|
+
try: () => writeClipboard(pmView, data),
|
|
581
|
+
catch: () => new CanonicalSessionRefusalError({
|
|
582
|
+
ground: { condition: CANONICAL_CONDITION.invalidRequest },
|
|
583
|
+
message: "The clipboard could not receive the cut content."
|
|
584
|
+
})
|
|
585
|
+
});
|
|
586
|
+
if (copied.isErr()) {
|
|
587
|
+
refuse(copied.error.message, copied.error.ground);
|
|
588
|
+
return true;
|
|
589
|
+
}
|
|
590
|
+
clipboardCopy = {
|
|
591
|
+
type: "copied",
|
|
592
|
+
document: source,
|
|
593
|
+
...copied.value
|
|
594
|
+
};
|
|
595
|
+
if (story === OP_STORIES.MAIN) publishCommit(prepared.value);
|
|
596
|
+
else publishStoryCommit(pmView, prepared.value);
|
|
597
|
+
return true;
|
|
598
|
+
};
|
|
547
599
|
/** The copied document, when the pasted clipboard is the editor's own copy. */
|
|
548
600
|
const copiedSource = (event) => {
|
|
549
601
|
const data = event.clipboardData;
|
|
@@ -580,110 +632,12 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
580
632
|
}
|
|
581
633
|
const session = editorSession.session;
|
|
582
634
|
const state = view.state;
|
|
583
|
-
if (
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
from: at,
|
|
587
|
-
to: at,
|
|
588
|
-
paragraphs: [{
|
|
589
|
-
type: "paragraph",
|
|
590
|
-
content: []
|
|
591
|
-
}, {
|
|
592
|
-
type: "paragraph",
|
|
593
|
-
content: []
|
|
594
|
-
}],
|
|
595
|
-
openStart: 1,
|
|
596
|
-
openEnd: 1
|
|
597
|
-
} : {
|
|
598
|
-
type: "insertAtom",
|
|
599
|
-
from: at,
|
|
600
|
-
to: at,
|
|
601
|
-
atom: type === "tab" ? { type: "tab" } : {
|
|
602
|
-
type: "break",
|
|
603
|
-
breakType: type === "pageBreak" ? "page" : "textWrapping"
|
|
604
|
-
}
|
|
605
|
-
});
|
|
606
|
-
if (overCells.isErr()) {
|
|
607
|
-
if (overCells.error.reason !== "noChange") refuse(overCells.error.message, overCells.error.ground);
|
|
608
|
-
return;
|
|
609
|
-
}
|
|
610
|
-
publishCommit(overCells.value);
|
|
611
|
-
return;
|
|
612
|
-
}
|
|
613
|
-
const selection = session.projection.selectionAt(state);
|
|
614
|
-
if (selection.isErr()) {
|
|
615
|
-
refuse(selection.error.message, selection.error.ground);
|
|
635
|
+
if (type === "joinBackward" && lastInputRule?.session === session && lastInputRule.version === session.version && lastInputRule.caret === state.selection.head) {
|
|
636
|
+
lastInputRule = void 0;
|
|
637
|
+
history("undo");
|
|
616
638
|
return;
|
|
617
639
|
}
|
|
618
|
-
|
|
619
|
-
switch (type) {
|
|
620
|
-
case "split": {
|
|
621
|
-
const source = session.projection.paragraph(selection.value.head.blockId)?.source;
|
|
622
|
-
prepared = isCanonicalListParagraph(source) && state.selection.$from.parent.content.size === 0 ? prepareCanonicalCommands(session, state, [{ type: "removeList" }]) : session.prepareSplit(state);
|
|
623
|
-
break;
|
|
624
|
-
}
|
|
625
|
-
case "joinBackward": {
|
|
626
|
-
if (lastInputRule?.session === session && lastInputRule.version === session.version && lastInputRule.caret === state.selection.head) {
|
|
627
|
-
lastInputRule = void 0;
|
|
628
|
-
history("undo");
|
|
629
|
-
return;
|
|
630
|
-
}
|
|
631
|
-
const paragraph = session.projection.paragraph(selection.value.head.blockId)?.source;
|
|
632
|
-
if (isCanonicalListParagraph(paragraph)) {
|
|
633
|
-
prepared = prepareCanonicalCommands(session, state, [{ type: "removeList" }]);
|
|
634
|
-
break;
|
|
635
|
-
}
|
|
636
|
-
if ((paragraph?.formatting?.indentLeft ?? 0) > 0 || (paragraph?.formatting?.indentFirstLine ?? 0) > 0) {
|
|
637
|
-
prepared = session.prepareIntent(state, {
|
|
638
|
-
type: "formatParagraph",
|
|
639
|
-
at: selection.value.head,
|
|
640
|
-
patch: {
|
|
641
|
-
indentLeft: null,
|
|
642
|
-
indentFirstLine: null,
|
|
643
|
-
hangingIndent: null
|
|
644
|
-
}
|
|
645
|
-
});
|
|
646
|
-
break;
|
|
647
|
-
}
|
|
648
|
-
prepared = session.prepareJoin(state, "backward");
|
|
649
|
-
break;
|
|
650
|
-
}
|
|
651
|
-
case "joinForward":
|
|
652
|
-
prepared = session.prepareJoin(state, "forward");
|
|
653
|
-
break;
|
|
654
|
-
case "indent":
|
|
655
|
-
case "outdent":
|
|
656
|
-
prepared = prepareCanonicalCommands(session, state, [{
|
|
657
|
-
type: "changeListLevel",
|
|
658
|
-
direction: type === "indent" ? "increase" : "decrease"
|
|
659
|
-
}]);
|
|
660
|
-
break;
|
|
661
|
-
case "tab":
|
|
662
|
-
case "lineBreak":
|
|
663
|
-
case "pageBreak": {
|
|
664
|
-
const from = session.projection.addressAt(state.selection.from);
|
|
665
|
-
const to = session.projection.addressAt(state.selection.to);
|
|
666
|
-
if (from.isErr()) {
|
|
667
|
-
refuse(from.error.message, from.error.ground);
|
|
668
|
-
return;
|
|
669
|
-
}
|
|
670
|
-
if (to.isErr()) {
|
|
671
|
-
refuse(to.error.message, to.error.ground);
|
|
672
|
-
return;
|
|
673
|
-
}
|
|
674
|
-
prepared = session.prepareIntent(state, {
|
|
675
|
-
type: "insertAtom",
|
|
676
|
-
from: from.value,
|
|
677
|
-
to: to.value,
|
|
678
|
-
atom: type === "tab" ? { type: "tab" } : {
|
|
679
|
-
type: "break",
|
|
680
|
-
breakType: type === "pageBreak" ? "page" : "textWrapping"
|
|
681
|
-
}
|
|
682
|
-
});
|
|
683
|
-
break;
|
|
684
|
-
}
|
|
685
|
-
default: return type;
|
|
686
|
-
}
|
|
640
|
+
const prepared = prepareCanonicalStructure(session, state, OP_STORIES.MAIN, type);
|
|
687
641
|
if (prepared.isErr()) {
|
|
688
642
|
if (prepared.error.reason !== "noChange") refuse(prepared.error.message, prepared.error.ground);
|
|
689
643
|
return;
|
|
@@ -722,52 +676,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
722
676
|
}
|
|
723
677
|
pasteWithoutFormatting(pmView.state, (transaction) => pmView.dispatch(transaction), pmView);
|
|
724
678
|
},
|
|
725
|
-
cut: (pmView, event) =>
|
|
726
|
-
event.preventDefault();
|
|
727
|
-
if (deps.getReadOnly()) {
|
|
728
|
-
deps.onReadOnlyEditAttempt();
|
|
729
|
-
return true;
|
|
730
|
-
}
|
|
731
|
-
deps.onCut?.();
|
|
732
|
-
if (editorSession.type !== "canonical" || pmView.state.selection.empty) return true;
|
|
733
|
-
if (event.clipboardData === null) {
|
|
734
|
-
refuse("The clipboard cannot receive the cut content.");
|
|
735
|
-
return true;
|
|
736
|
-
}
|
|
737
|
-
syncCanonicalMode();
|
|
738
|
-
const source = readModel(editorSession.session.document);
|
|
739
|
-
const session = editorSession.session;
|
|
740
|
-
const { from, to } = pmView.state.selection;
|
|
741
|
-
const prepared = session.prepareReplace(pmView.state, {
|
|
742
|
-
from,
|
|
743
|
-
to,
|
|
744
|
-
text: "",
|
|
745
|
-
semantic: "replacement"
|
|
746
|
-
});
|
|
747
|
-
if (prepared.isErr()) {
|
|
748
|
-
refuse(prepared.error.message, prepared.error.ground);
|
|
749
|
-
return true;
|
|
750
|
-
}
|
|
751
|
-
const data = event.clipboardData;
|
|
752
|
-
const copied = Result.try({
|
|
753
|
-
try: () => writeClipboard(pmView, data),
|
|
754
|
-
catch: () => new CanonicalSessionRefusalError({
|
|
755
|
-
ground: { gap: CANONICAL_GAP.dispatch },
|
|
756
|
-
message: "The clipboard could not receive the cut content."
|
|
757
|
-
})
|
|
758
|
-
});
|
|
759
|
-
if (copied.isErr()) {
|
|
760
|
-
refuse(copied.error.message, copied.error.ground);
|
|
761
|
-
return true;
|
|
762
|
-
}
|
|
763
|
-
clipboardCopy = {
|
|
764
|
-
type: "copied",
|
|
765
|
-
document: source,
|
|
766
|
-
...copied.value
|
|
767
|
-
};
|
|
768
|
-
publishCommit(prepared.value);
|
|
769
|
-
return true;
|
|
770
|
-
},
|
|
679
|
+
cut: (pmView, event) => cutCanonical(pmView, event, OP_STORIES.MAIN),
|
|
771
680
|
...canonicalInputLifecycle,
|
|
772
681
|
...canonicalStructuralInput,
|
|
773
682
|
replace: (intent) => {
|
|
@@ -832,9 +741,9 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
832
741
|
}
|
|
833
742
|
const applied = view.state.applyTransaction(transaction);
|
|
834
743
|
const noteIssue = noteReferenceTransactionIssue(transaction);
|
|
835
|
-
if (noteIssue) deps.onSessionRefusal?.(noteIssue.message, {
|
|
744
|
+
if (noteIssue) deps.onSessionRefusal?.(noteIssue.message, { condition: noteIssue instanceof NoteReferenceReplayDefect ? CANONICAL_CONDITION.internal : CANONICAL_CONDITION.invalidRequest }, noteIssue);
|
|
836
745
|
if (!applied.state.doc.eq(view.state.doc)) {
|
|
837
|
-
refuse(unclassifiedMutationMessage(applied.transactions, "A plugin attempted an unclassified canonical document mutation."));
|
|
746
|
+
refuse(unclassifiedMutationMessage(applied.transactions, "A plugin attempted an unclassified canonical document mutation."), { condition: CANONICAL_CONDITION.hostTransaction });
|
|
838
747
|
return;
|
|
839
748
|
}
|
|
840
749
|
const documentEdits = applied.transactions.filter((appliedTransaction) => appliedTransaction.docChanged && !isCommentRecordsSync(appliedTransaction));
|
|
@@ -890,13 +799,13 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
890
799
|
top: event.clientY
|
|
891
800
|
})?.pos;
|
|
892
801
|
if (target === void 0) {
|
|
893
|
-
refuse("The drop has no document destination.");
|
|
802
|
+
refuse("The drop has no document destination.", { condition: CANONICAL_CONDITION.invalidRequest });
|
|
894
803
|
return true;
|
|
895
804
|
}
|
|
896
805
|
const captured = clipboardDrag;
|
|
897
806
|
clipboardDrag = { type: "idle" };
|
|
898
807
|
if (moved && (captured.type !== "dragging" || captured.session !== editorSession.session || captured.version !== editorSession.session.version)) {
|
|
899
|
-
refuse("The dragged content changed or has no captured source.");
|
|
808
|
+
refuse("The dragged content changed or has no captured source.", { condition: CANONICAL_CONDITION.stale });
|
|
900
809
|
return true;
|
|
901
810
|
}
|
|
902
811
|
const source = captured.type === "dragging" ? {
|
|
@@ -1096,14 +1005,14 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1096
1005
|
selection: commit.selection,
|
|
1097
1006
|
unavailable: { type: "refuse" }
|
|
1098
1007
|
})) {
|
|
1099
|
-
refuse("The canonical body history selection is unavailable.");
|
|
1008
|
+
refuse("The canonical body history selection is unavailable.", { condition: CANONICAL_CONDITION.internal });
|
|
1100
1009
|
return false;
|
|
1101
1010
|
}
|
|
1102
1011
|
}
|
|
1103
1012
|
bodyTransaction.setMeta("addToHistory", false);
|
|
1104
1013
|
const bodyStaged = Result.try(() => view?.state.applyTransaction(bodyTransaction));
|
|
1105
1014
|
if (bodyStaged.isErr() || !bodyStaged.value || !bodyStaged.value.transactions.includes(bodyTransaction) || !bodyStaged.value.state.doc.eq(commit.bodyProjection.doc) || bodyStaged.value.transactions.some((transaction) => transaction !== bodyTransaction && transaction.docChanged)) {
|
|
1106
|
-
refuse("A plugin refused or changed the canonical body projection.");
|
|
1015
|
+
refuse("A plugin refused or changed the canonical body projection.", { condition: CANONICAL_CONDITION.hostTransaction });
|
|
1107
1016
|
return false;
|
|
1108
1017
|
}
|
|
1109
1018
|
const staged = publishCanonicalProjection({
|
|
@@ -1269,25 +1178,30 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1269
1178
|
canonicalOperations: {
|
|
1270
1179
|
applyCanonicalSectionProperties: (patch) => {
|
|
1271
1180
|
ensureView();
|
|
1272
|
-
const fail = (message) => {
|
|
1273
|
-
refuse(message,
|
|
1181
|
+
const fail = (message, ground) => {
|
|
1182
|
+
refuse(message, ground);
|
|
1274
1183
|
return {
|
|
1275
1184
|
status: "refused",
|
|
1276
|
-
|
|
1185
|
+
ground,
|
|
1277
1186
|
message
|
|
1278
1187
|
};
|
|
1279
1188
|
};
|
|
1280
|
-
if (editorSession.type
|
|
1281
|
-
if (
|
|
1282
|
-
if (!view || deps.getReadOnly() || isDestroying) return fail("The document is not editable.");
|
|
1189
|
+
if (editorSession.type !== "canonical") return fail(editorSession.type === "refused" ? editorSession.reason : "The document is not ready for section changes.", { condition: CANONICAL_CONDITION.notReady });
|
|
1190
|
+
if (!view || deps.getReadOnly() || isDestroying) return fail("The document is not editable.", { condition: CANONICAL_CONDITION.notEditable });
|
|
1283
1191
|
const session = editorSession.session;
|
|
1284
|
-
if (session.isComposing) return fail("Section properties cannot change during composition.");
|
|
1192
|
+
if (session.isComposing) return fail("Section properties cannot change during composition.", { condition: CANONICAL_CONDITION.composing });
|
|
1285
1193
|
const prepared = session.prepareOperations(view.state, [createCanonicalSectionPropertiesOperation(readModel(session.document), patch)]);
|
|
1286
|
-
if (prepared.isErr()) return fail(prepared.error.message);
|
|
1287
|
-
let
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
}
|
|
1194
|
+
if (prepared.isErr()) return fail(prepared.error.message, prepared.error.ground);
|
|
1195
|
+
let failure = {
|
|
1196
|
+
message: "The section projection could not publish.",
|
|
1197
|
+
ground: { condition: CANONICAL_CONDITION.notReady }
|
|
1198
|
+
};
|
|
1199
|
+
if (!publishCommit(prepared.value, (message, ground) => {
|
|
1200
|
+
failure = {
|
|
1201
|
+
message,
|
|
1202
|
+
ground: ground ?? failure.ground
|
|
1203
|
+
};
|
|
1204
|
+
})) return fail(failure.message, failure.ground);
|
|
1291
1205
|
return {
|
|
1292
1206
|
status: "applied",
|
|
1293
1207
|
version: session.version
|
|
@@ -1295,29 +1209,28 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1295
1209
|
},
|
|
1296
1210
|
applyCanonicalComment: (request) => {
|
|
1297
1211
|
ensureView();
|
|
1298
|
-
const fail = (message, retry = "never") => {
|
|
1299
|
-
if (retry === "never") refuse(message,
|
|
1212
|
+
const fail = (message, ground, retry = "never") => {
|
|
1213
|
+
if (retry === "never") refuse(message, ground);
|
|
1300
1214
|
return {
|
|
1301
1215
|
status: "refused",
|
|
1302
|
-
|
|
1216
|
+
ground,
|
|
1303
1217
|
message,
|
|
1304
1218
|
retry
|
|
1305
1219
|
};
|
|
1306
1220
|
};
|
|
1307
|
-
if (editorSession.type
|
|
1308
|
-
if (
|
|
1309
|
-
if (!view || deps.getReadOnly()) return fail("The document is not editable.");
|
|
1221
|
+
if (editorSession.type !== "canonical") return fail(editorSession.type === "refused" ? editorSession.reason : "The document is not ready for comment changes.", { condition: CANONICAL_CONDITION.notReady });
|
|
1222
|
+
if (!view || deps.getReadOnly()) return fail("The document is not editable.", { condition: CANONICAL_CONDITION.notEditable });
|
|
1310
1223
|
const session = editorSession.session;
|
|
1311
|
-
if (session.isComposing) return fail("Comments cannot change during composition.", "afterComposition");
|
|
1224
|
+
if (session.isComposing) return fail("Comments cannot change during composition.", { condition: CANONICAL_CONDITION.composing }, "afterComposition");
|
|
1312
1225
|
let command;
|
|
1313
1226
|
if (request.type === "create") {
|
|
1314
1227
|
const id = freshCommentId(readModel(session.document), session.idLease);
|
|
1315
|
-
if (id.isErr()) return fail(id.
|
|
1228
|
+
if (id.isErr()) return fail("No comment id is free.", { condition: CANONICAL_CONDITION.idSpace });
|
|
1316
1229
|
let anchor;
|
|
1317
1230
|
switch (request.anchor.kind) {
|
|
1318
1231
|
case "selection": {
|
|
1319
1232
|
const projection = session.projectStory(request.anchor.story);
|
|
1320
|
-
if (projection.isErr()) return fail(projection.error.message);
|
|
1233
|
+
if (projection.isErr()) return fail(projection.error.message, projection.error.ground);
|
|
1321
1234
|
const { doc } = projection.value;
|
|
1322
1235
|
const textEdge = (position, bias) => {
|
|
1323
1236
|
if (position < 0 || position > doc.content.size) return position;
|
|
@@ -1330,8 +1243,8 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1330
1243
|
const collapsed = request.anchor.from === request.anchor.to;
|
|
1331
1244
|
const from = projection.value.addressAt(collapsed ? request.anchor.from : textEdge(request.anchor.from, 1));
|
|
1332
1245
|
const to = projection.value.addressAt(collapsed ? request.anchor.to : textEdge(request.anchor.to, -1));
|
|
1333
|
-
if (from.isErr()) return fail(from.error.message);
|
|
1334
|
-
if (to.isErr()) return fail(to.error.message);
|
|
1246
|
+
if (from.isErr()) return fail(from.error.message, from.error.ground);
|
|
1247
|
+
if (to.isErr()) return fail(to.error.message, to.error.ground);
|
|
1335
1248
|
anchor = request.anchor.from === request.anchor.to ? {
|
|
1336
1249
|
kind: "point",
|
|
1337
1250
|
at: from.value
|
|
@@ -1374,11 +1287,20 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1374
1287
|
command,
|
|
1375
1288
|
idLease: session.idLease
|
|
1376
1289
|
});
|
|
1377
|
-
if (compiled.isErr()) return fail(compiled.error.message);
|
|
1290
|
+
if (compiled.isErr()) return fail(compiled.error.message, compiled.error.ground);
|
|
1378
1291
|
if (compiled.value.ops.length > 0) {
|
|
1379
1292
|
const prepared = session.prepareOperations(view.state, compiled.value.ops);
|
|
1380
|
-
if (prepared.isErr()) return fail(prepared.error.message);
|
|
1381
|
-
|
|
1293
|
+
if (prepared.isErr()) return fail(prepared.error.message, prepared.error.ground);
|
|
1294
|
+
let failure = {
|
|
1295
|
+
message: "The comment projection could not publish.",
|
|
1296
|
+
ground: { condition: CANONICAL_CONDITION.notReady }
|
|
1297
|
+
};
|
|
1298
|
+
if (!publishCommit(prepared.value, (message, ground) => {
|
|
1299
|
+
failure = {
|
|
1300
|
+
message,
|
|
1301
|
+
ground: ground ?? failure.ground
|
|
1302
|
+
};
|
|
1303
|
+
})) return fail(failure.message, failure.ground);
|
|
1382
1304
|
}
|
|
1383
1305
|
return {
|
|
1384
1306
|
status: "applied",
|
|
@@ -1460,6 +1382,27 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1460
1382
|
});
|
|
1461
1383
|
if (editorSession.type === "canonical") editorSession.session.recordStorySelection(storyView.state, story);
|
|
1462
1384
|
},
|
|
1385
|
+
applyCanonicalStoryStructure: ({ view: storyView, story, type }) => {
|
|
1386
|
+
if (!view || editorSession.type !== "canonical" || deps.getReadOnly()) return false;
|
|
1387
|
+
syncCanonicalMode();
|
|
1388
|
+
const session = editorSession.session;
|
|
1389
|
+
let prepared;
|
|
1390
|
+
if (type === "deleteTable") {
|
|
1391
|
+
const command = deps.getExtensionManager()?.getCommand("deleteTable")?.();
|
|
1392
|
+
const intents = command === void 0 ? void 0 : getCanonicalCommandIntents(command, storyView.state);
|
|
1393
|
+
if (intents === void 0) {
|
|
1394
|
+
refuse("Deleting the table is unavailable.", { gap: CANONICAL_GAP.commands });
|
|
1395
|
+
return false;
|
|
1396
|
+
}
|
|
1397
|
+
prepared = prepareCanonicalCommands(session, storyView.state, intents, story);
|
|
1398
|
+
} else prepared = prepareCanonicalStructure(session, storyView.state, story, type);
|
|
1399
|
+
if (prepared.isErr()) {
|
|
1400
|
+
if (prepared.error.reason !== "noChange") refuse(prepared.error.message, prepared.error.ground);
|
|
1401
|
+
return false;
|
|
1402
|
+
}
|
|
1403
|
+
return publishStoryCommit(storyView, prepared.value);
|
|
1404
|
+
},
|
|
1405
|
+
cutCanonicalStory: ({ view: storyView, story, event }) => cutCanonical(storyView, event, story),
|
|
1463
1406
|
replaceCanonicalStoryText: ({ view: storyView, story, intent }) => {
|
|
1464
1407
|
if (!view || editorSession.type !== "canonical" || deps.getReadOnly()) return false;
|
|
1465
1408
|
syncCanonicalMode();
|