@stll/folio-core 0.74.0 → 0.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +7 -3
- package/dist/ai-edits/headless.js +36 -21
- 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 +135 -90
- package/dist/ai-edits/pendingJoin.d.ts +5 -1
- package/dist/ai-edits/pendingJoin.js +6 -2
- package/dist/ai-edits/read.js +9 -3
- 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/ai-edits/types.d.ts +9 -4
- package/dist/canonical/batchCommentReferences.js +2 -1
- package/dist/canonical/canonicalBatchReview.d.ts +4 -1
- package/dist/canonical/canonicalBatchReview.js +37 -22
- package/dist/canonical/canonicalComments.d.ts +6 -2
- package/dist/canonical/canonicalComments.js +16 -6
- package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
- package/dist/canonical/canonicalCompilerRefusal.js +20 -14
- package/dist/canonical/canonicalPublicOperations.js +231 -79
- 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 +119 -122
- 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.d.ts +1 -1
- package/dist/controller/canonicalClipboard.js +110 -55
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +5 -5
- package/dist/controller/canonicalContentControlValue.js +7 -7
- package/dist/controller/canonicalInput.d.ts +4 -2
- package/dist/controller/canonicalInput.js +33 -16
- package/dist/controller/canonicalReview.d.ts +21 -0
- package/dist/controller/canonicalReview.js +44 -9
- package/dist/controller/canonicalStoryEditor.d.ts +2 -3
- package/dist/controller/canonicalStoryEditor.js +43 -25
- package/dist/controller/canonicalStructure.d.ts +19 -3
- package/dist/controller/canonicalStructure.js +182 -58
- 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/fontReadiness.js +50 -23
- 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 +135 -207
- 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/bulletMarkers.d.ts +8 -0
- package/dist/docx/bulletMarkers.js +9 -1
- package/dist/docx/canonicalSave.d.ts +4 -3
- package/dist/docx/canonicalSave.js +4 -3
- package/dist/docx/canonicalSessionInput.js +25 -11
- package/dist/docx/ensureParaIds.d.ts +31 -0
- package/dist/docx/ensureParaIds.js +57 -32
- package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
- package/dist/docx/ensureUniqueControlIds.js +47 -29
- package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
- package/dist/docx/ensureUniqueRevisionIds.js +52 -29
- 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 +96 -7
- package/dist/docx/server/templatePlan/blocks.d.ts +70 -3
- package/dist/docx/server/templatePlan/blocks.js +272 -10
- package/dist/docx/server/templatePlan/builders.d.ts +52 -2
- package/dist/docx/server/templatePlan/builders.js +224 -5
- package/dist/docx/server/templatePlan/effects.d.ts +27 -0
- package/dist/docx/server/templatePlan/effects.js +188 -0
- package/dist/docx/server/templatePlan/emit.d.ts +4 -1
- package/dist/docx/server/templatePlan/emit.js +46 -2
- package/dist/docx/server/templatePlan/inspect.js +39 -52
- package/dist/docx/server/templatePlan/labels.d.ts +7 -2
- package/dist/docx/server/templatePlan/labels.js +120 -23
- package/dist/docx/server/templatePlan/plan.d.ts +24 -3
- package/dist/docx/server/templatePlan/plan.js +54 -15
- package/dist/docx/server/templatePlan/planShape.js +76 -22
- package/dist/docx/server/templatePlan/revisions.d.ts +46 -0
- package/dist/docx/server/templatePlan/revisions.js +407 -0
- package/dist/docx/server/templatePlan/story.d.ts +23 -1
- package/dist/docx/server/templatePlan/story.js +60 -2
- package/dist/docx/server/templatePlan/types.d.ts +354 -16
- package/dist/docx/server/templatePlan/verify.js +164 -14
- package/dist/docx/server/templatePlan/xml.d.ts +3 -0
- package/dist/docx/server/templatePlan/xml.js +4 -1
- 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/internal/revisionResolutionStep.d.ts +2 -31
- package/dist/internal/revisionResolutionStep.js +2 -171
- package/dist/layout-bridge/convert/toFlowBlocks.js +0 -12
- package/dist/layout-bridge/convert/topLevelConversion.js +1 -10
- package/dist/prosemirror/commands/comments.d.ts +6 -234
- package/dist/prosemirror/commands/comments.js +5 -2464
- package/dist/prosemirror/commands/index.d.ts +4 -2
- package/dist/prosemirror/commands/index.js +4 -2
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -11
- package/dist/prosemirror/commands/tableCellMergeResolution.js +3 -154
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +1 -1
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
- package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
- package/dist/prosemirror/hyperlinkRemoval.js +24 -15
- package/dist/prosemirror/listMarker.d.ts +1 -6
- package/dist/prosemirror/listMarker.js +4 -56
- package/dist/prosemirror/paraIds.d.ts +1 -14
- package/dist/prosemirror/paraIds.js +1 -14
- package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
- package/dist/prosemirror/paragraphMarkJoin.js +3 -46
- package/dist/prosemirror/projectionReview.d.ts +49 -0
- package/dist/prosemirror/projectionReview.js +292 -0
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
- package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
- package/dist/prosemirror/replacedAnnotations.d.ts +2 -5
- package/dist/prosemirror/replacedAnnotations.js +1 -10
- package/dist/prosemirror/revisionCarriers.d.ts +9 -1
- package/dist/prosemirror/revisionCarriers.js +15 -1
- package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
- package/dist/prosemirror/revisionRangeQueries.js +76 -0
- package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
- package/dist/prosemirror/runFormattingMarkNames.js +1 -1
- package/dist/prosemirror/suggestionQueries.d.ts +114 -0
- package/dist/prosemirror/suggestionQueries.js +320 -0
- package/dist/prosemirror/tableGridMutation.d.ts +1 -16
- package/dist/prosemirror/tableGridMutation.js +1 -78
- package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
- package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
- package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +40 -69
- package/dist/types/canonicalCapabilities.js +51 -65
- 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/internal/headlessRevisionResolutionGuard.d.ts +0 -3
- package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { deletionRange, isCanonicalJoinBoundary, measuredDeletionRange } from "../canonical/canonicalSession.js";
|
|
2
2
|
import { textCaretOf } from "../prosemirror/nativeSelection.js";
|
|
3
3
|
import { getEditorInputTargetRange, handleEditorBeforeInput } from "../prosemirror/textInput.js";
|
|
4
|
+
import { CANONICAL_CONDITION } from "../types/canonicalCapabilities.js";
|
|
4
5
|
import { createCanonicalComposition } from "./canonicalComposition.js";
|
|
5
6
|
import { Selection, TextSelection } from "prosemirror-state";
|
|
6
7
|
import { CellSelection } from "prosemirror-tables";
|
|
7
8
|
import { ReplaceStep } from "prosemirror-transform";
|
|
8
9
|
// src/controller/canonicalInput.ts
|
|
10
|
+
const INVALID_REQUEST = { condition: CANONICAL_CONDITION.invalidRequest };
|
|
11
|
+
const COMPOSING = { condition: CANONICAL_CONDITION.composing };
|
|
12
|
+
/**
|
|
13
|
+
* A boundary built without a structure or cut handler. Every editor folio
|
|
14
|
+
* builds, the body and each header, footer and note, gives it both; one built
|
|
15
|
+
* without them takes no such edit.
|
|
16
|
+
*/
|
|
17
|
+
const NO_HANDLER = INVALID_REQUEST;
|
|
9
18
|
/** Deletions whose extent the browser measures: by word or by line. */
|
|
10
19
|
const WORD_AND_LINE_DELETIONS = /* @__PURE__ */ new Set([
|
|
11
20
|
"deleteWordBackward",
|
|
@@ -54,6 +63,12 @@ const unclassifiedMutationMessage = (transactions, unnamed = "Unclassified nativ
|
|
|
54
63
|
const keys = [...new Set(transactions.filter(({ docChanged }) => docChanged).flatMap(transactionMetaKeys))];
|
|
55
64
|
return keys.length === 0 ? unnamed : `A transaction with meta ${keys.join(", ")} changed the document outside the session's operations; express the edit as document operations.`;
|
|
56
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* The ground of such a refusal: a transaction a plugin or a host named changed
|
|
68
|
+
* the document outside document operations; native text no classifier reads
|
|
69
|
+
* is not an input the session takes.
|
|
70
|
+
*/
|
|
71
|
+
const unclassifiedMutationGround = (transactions) => transactions.some((transaction) => transaction.docChanged && transactionMetaKeys(transaction).length > 0) ? { condition: CANONICAL_CONDITION.hostTransaction } : INVALID_REQUEST;
|
|
57
72
|
const CANONICAL_COMPOSITION_INPUT_TYPES = [
|
|
58
73
|
"insertCompositionText",
|
|
59
74
|
"insertFromComposition",
|
|
@@ -102,22 +117,24 @@ const createCanonicalInputBoundary = (options) => {
|
|
|
102
117
|
if (!view.isDestroyed) view.updateState(view.state);
|
|
103
118
|
});
|
|
104
119
|
};
|
|
105
|
-
const refuseEvent = (event, reason) => {
|
|
120
|
+
const refuseEvent = (event, reason, ground) => {
|
|
106
121
|
event.preventDefault();
|
|
107
122
|
closeGroup();
|
|
108
|
-
if (!composition.active && proposal.type !== "refused") options.refuse(reason);
|
|
123
|
+
if (!composition.active && proposal.type !== "refused") options.refuse(reason, ground);
|
|
109
124
|
if (!composition.active) proposal = { type: "refused" };
|
|
110
125
|
return true;
|
|
111
126
|
};
|
|
127
|
+
/** A clipboard gesture made while a composition is in progress. */
|
|
112
128
|
const refuseClipboardGesture = (event, reason) => {
|
|
113
129
|
event.preventDefault();
|
|
114
130
|
closeGroup();
|
|
115
|
-
options.refuse(reason);
|
|
131
|
+
options.refuse(reason, COMPOSING);
|
|
116
132
|
return true;
|
|
117
133
|
};
|
|
118
134
|
const refuseNativeMutation = (view, transaction) => {
|
|
119
135
|
if (!composition.active && proposal.type !== "refused") {
|
|
120
|
-
|
|
136
|
+
const transactions = transaction ? [transaction] : [];
|
|
137
|
+
options.refuse(unclassifiedMutationMessage(transactions), unclassifiedMutationGround(transactions));
|
|
121
138
|
proposal = { type: "refused" };
|
|
122
139
|
}
|
|
123
140
|
repaint(view);
|
|
@@ -242,10 +259,10 @@ const createCanonicalInputBoundary = (options) => {
|
|
|
242
259
|
return true;
|
|
243
260
|
}
|
|
244
261
|
if (event.key === "Enter") {
|
|
245
|
-
if (view.composing) return refuseEvent(event, "Paragraph structure edits are unavailable during composition.");
|
|
262
|
+
if (view.composing) return refuseEvent(event, "Paragraph structure edits are unavailable during composition.", COMPOSING);
|
|
246
263
|
event.preventDefault();
|
|
247
264
|
closeGroup();
|
|
248
|
-
if (options.structure === void 0) return refuseEvent(event, "Paragraph structure edits are unavailable in this session.");
|
|
265
|
+
if (options.structure === void 0) return refuseEvent(event, "Paragraph structure edits are unavailable in this session.", NO_HANDLER);
|
|
249
266
|
if (modifier) options.structure("pageBreak");
|
|
250
267
|
else options.structure(event.shiftKey ? "lineBreak" : "split");
|
|
251
268
|
return true;
|
|
@@ -260,7 +277,7 @@ const createCanonicalInputBoundary = (options) => {
|
|
|
260
277
|
if (view.composing || composition.active) {
|
|
261
278
|
event.preventDefault();
|
|
262
279
|
closeGroup();
|
|
263
|
-
if (!composition.active) options.refuse("Only plain character deletion is available in this session.");
|
|
280
|
+
if (!composition.active) options.refuse("Only plain character deletion is available in this session.", COMPOSING);
|
|
264
281
|
return true;
|
|
265
282
|
}
|
|
266
283
|
const selection = view.state.selection;
|
|
@@ -278,7 +295,7 @@ const createCanonicalInputBoundary = (options) => {
|
|
|
278
295
|
const range = deletionRange(view.state, event.key === "Backspace" ? "backward" : "forward");
|
|
279
296
|
if (range.isErr()) {
|
|
280
297
|
closeGroup();
|
|
281
|
-
options.refuse(range.error.message);
|
|
298
|
+
options.refuse(range.error.message, range.error.ground);
|
|
282
299
|
} else options.replace({
|
|
283
300
|
...range.value,
|
|
284
301
|
text: "",
|
|
@@ -333,7 +350,7 @@ const createCanonicalInputBoundary = (options) => {
|
|
|
333
350
|
return false;
|
|
334
351
|
}
|
|
335
352
|
if (event.inputType === "insertFromComposition" && composition.authorizeLateFinal(view, event.data)) return false;
|
|
336
|
-
return refuseEvent(event, "Composition has no captured canonical baseline.");
|
|
353
|
+
return refuseEvent(event, "Composition has no captured canonical baseline.", { condition: CANONICAL_CONDITION.internal });
|
|
337
354
|
}
|
|
338
355
|
if (composition.active) {
|
|
339
356
|
if (view.composing && (event.inputType === "deleteContentBackward" || event.inputType === "deleteContentForward")) {
|
|
@@ -376,12 +393,12 @@ const createCanonicalInputBoundary = (options) => {
|
|
|
376
393
|
};
|
|
377
394
|
try {
|
|
378
395
|
if (handleEditorBeforeInput(view, event)) return true;
|
|
379
|
-
return refuseEvent(event, "This native replacement cannot be addressed safely.");
|
|
396
|
+
return refuseEvent(event, "This native replacement cannot be addressed safely.", INVALID_REQUEST);
|
|
380
397
|
} finally {
|
|
381
398
|
authorizedInput = null;
|
|
382
399
|
}
|
|
383
400
|
}
|
|
384
|
-
if (event.inputType !== "insertText" || event.data === null) return refuseEvent(event, "This native replacement cannot be addressed safely.");
|
|
401
|
+
if (event.inputType !== "insertText" || event.data === null) return refuseEvent(event, "This native replacement cannot be addressed safely.", INVALID_REQUEST);
|
|
385
402
|
proposal = {
|
|
386
403
|
type: "replacement",
|
|
387
404
|
state: view.state,
|
|
@@ -410,7 +427,7 @@ const createCanonicalInputBoundary = (options) => {
|
|
|
410
427
|
return true;
|
|
411
428
|
}
|
|
412
429
|
const range = deletionRange(view.state, event.inputType === "deleteContentBackward" ? "backward" : "forward");
|
|
413
|
-
if (range.isErr()) return refuseEvent(event, range.error.message);
|
|
430
|
+
if (range.isErr()) return refuseEvent(event, range.error.message, range.error.ground);
|
|
414
431
|
const input = {
|
|
415
432
|
...range.value,
|
|
416
433
|
text: "",
|
|
@@ -430,9 +447,9 @@ const createCanonicalInputBoundary = (options) => {
|
|
|
430
447
|
}
|
|
431
448
|
if (WORD_AND_LINE_DELETIONS.has(event.inputType)) {
|
|
432
449
|
const measured = browserTargetRange(view, event);
|
|
433
|
-
if (measured === void 0) return refuseEvent(event, "The browser named no range for this deletion.");
|
|
450
|
+
if (measured === void 0) return refuseEvent(event, "The browser named no range for this deletion.", INVALID_REQUEST);
|
|
434
451
|
const range = measuredDeletionRange(view.state, measured);
|
|
435
|
-
if (range.isErr()) return refuseEvent(event, range.error.message);
|
|
452
|
+
if (range.isErr()) return refuseEvent(event, range.error.message, range.error.ground);
|
|
436
453
|
closeGroup();
|
|
437
454
|
if (range.value === null) {
|
|
438
455
|
event.preventDefault();
|
|
@@ -461,7 +478,7 @@ const createCanonicalInputBoundary = (options) => {
|
|
|
461
478
|
else options.redo();
|
|
462
479
|
return true;
|
|
463
480
|
}
|
|
464
|
-
return refuseEvent(event, `Input ${event.inputType} is unavailable in this session
|
|
481
|
+
return refuseEvent(event, `Input ${event.inputType} is unavailable in this session.`, INVALID_REQUEST);
|
|
465
482
|
},
|
|
466
483
|
input: (view) => {
|
|
467
484
|
if (composition.active || composition.pendingFinal) {
|
|
@@ -489,7 +506,7 @@ const createCanonicalInputBoundary = (options) => {
|
|
|
489
506
|
closeGroup();
|
|
490
507
|
return options.cut(view, event);
|
|
491
508
|
}
|
|
492
|
-
return refuseEvent(event, "The canonical clipboard owner is unavailable.");
|
|
509
|
+
return refuseEvent(event, "The canonical clipboard owner is unavailable.", NO_HANDLER);
|
|
493
510
|
},
|
|
494
511
|
drop: (_view, event) => {
|
|
495
512
|
beginGesture();
|
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
import { FolioEditor } from "./folioEditor.js";
|
|
2
|
+
import { EditorState } from "prosemirror-state";
|
|
3
|
+
import { OpStory } from "@stll/docx-core/ops";
|
|
4
|
+
export type ReviewRange = {
|
|
5
|
+
from: number;
|
|
6
|
+
to: number;
|
|
7
|
+
};
|
|
8
|
+
export type CanonicalReviewEditor = Pick<FolioEditor, "getCanonicalStoryProjection" | "getDocument">;
|
|
9
|
+
type CanonicalReviewLockOptions = {
|
|
10
|
+
editor: CanonicalReviewEditor | null | undefined;
|
|
11
|
+
state: EditorState;
|
|
12
|
+
story: OpStory;
|
|
13
|
+
target: ({
|
|
14
|
+
type: "range";
|
|
15
|
+
} & ReviewRange) | {
|
|
16
|
+
type: "revisions";
|
|
17
|
+
ids: readonly number[];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type HeldReviewRevisionIds = Record<"accept" | "reject", ReadonlySet<number>>;
|
|
21
|
+
/** Predict the session's lock decision for the groups its review will settle. */
|
|
22
|
+
export declare const canonicalReviewHeldRevisionIds: ({ editor, state, story, target }: CanonicalReviewLockOptions) => HeldReviewRevisionIds;
|
|
2
23
|
type ResolveCanonicalReviewRangeOptions = {
|
|
3
24
|
editor: Pick<FolioEditor, "getCanonicalDocument" | "getState" | "resolveCanonicalRevisions"> | null | undefined;
|
|
4
25
|
from: number;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { getTrackedChangeGroupIdsFromDoc, getTrackedChangesFromDoc } from "../ai-edits/read.js";
|
|
2
|
-
import {
|
|
1
|
+
import { getTrackedChangeGroupIdsFromDoc, getTrackedChangeGroupsForIds, getTrackedChangesFromDoc } from "../ai-edits/read.js";
|
|
2
|
+
import { hasLockedControls } from "../canonical/canonicalLockGuard.js";
|
|
3
|
+
import { canonicalRevisionLocks } from "../canonical/canonicalRevisionLocks.js";
|
|
4
|
+
import { findAIEditRevisionRange } from "../prosemirror/revisionRangeQueries.js";
|
|
5
|
+
import { readModel } from "../types/documentModel.js";
|
|
6
|
+
import { OP_STORIES } from "@stll/docx-core/ops";
|
|
3
7
|
// src/controller/canonicalReview.ts
|
|
4
|
-
|
|
5
|
-
const resolveCanonicalReviewRange = ({ editor, from, to, resolution }) => {
|
|
6
|
-
if (!editor?.getCanonicalDocument()) return null;
|
|
7
|
-
const state = editor.getState();
|
|
8
|
-
if (!state) return false;
|
|
8
|
+
const revisionIdsAtRange = (state, { from, to }) => {
|
|
9
9
|
const ids = /* @__PURE__ */ new Set();
|
|
10
10
|
for (const change of getTrackedChangesFromDoc(state.doc)) {
|
|
11
11
|
const groupIds = getTrackedChangeGroupIdsFromDoc(state.doc, change.id);
|
|
@@ -13,6 +13,41 @@ const resolveCanonicalReviewRange = ({ editor, from, to, resolution }) => {
|
|
|
13
13
|
if (!range) continue;
|
|
14
14
|
if (from === to ? range.from <= from && range.to >= to : range.from < to && range.to > from) for (const id of groupIds) ids.add(id);
|
|
15
15
|
}
|
|
16
|
-
return
|
|
16
|
+
return [...ids];
|
|
17
|
+
};
|
|
18
|
+
const NO_HELD_REVISIONS = {
|
|
19
|
+
accept: /* @__PURE__ */ new Set(),
|
|
20
|
+
reject: /* @__PURE__ */ new Set()
|
|
21
|
+
};
|
|
22
|
+
/** Predict the session's lock decision for the groups its review will settle. */
|
|
23
|
+
const canonicalReviewHeldRevisionIds = ({ editor, state, story, target }) => {
|
|
24
|
+
if (!editor?.getCanonicalStoryProjection(OP_STORIES.MAIN)) return NO_HELD_REVISIONS;
|
|
25
|
+
const model = editor.getDocument();
|
|
26
|
+
if (!model) return NO_HELD_REVISIONS;
|
|
27
|
+
const document = readModel(model);
|
|
28
|
+
if (!hasLockedControls(document)) return NO_HELD_REVISIONS;
|
|
29
|
+
const ids = target.type === "range" ? revisionIdsAtRange(state, target) : target.ids;
|
|
30
|
+
const groups = getTrackedChangeGroupsForIds(state.doc, ids);
|
|
31
|
+
const heldIds = (decision) => new Set(canonicalRevisionLocks({
|
|
32
|
+
document,
|
|
33
|
+
story,
|
|
34
|
+
groups,
|
|
35
|
+
decision
|
|
36
|
+
}).held.flatMap((group) => group.ids));
|
|
37
|
+
return {
|
|
38
|
+
accept: heldIds("accept"),
|
|
39
|
+
reject: heldIds("reject")
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/** Null when the editor holds no canonical session, which leaves the review as it is. */
|
|
43
|
+
const resolveCanonicalReviewRange = ({ editor, from, to, resolution }) => {
|
|
44
|
+
if (!editor?.getCanonicalDocument()) return null;
|
|
45
|
+
const state = editor.getState();
|
|
46
|
+
if (!state) return false;
|
|
47
|
+
const ids = revisionIdsAtRange(state, {
|
|
48
|
+
from,
|
|
49
|
+
to
|
|
50
|
+
});
|
|
51
|
+
return ids.length > 0 && editor.resolveCanonicalRevisions(ids, resolution);
|
|
17
52
|
};
|
|
18
|
-
export { resolveCanonicalReviewRange };
|
|
53
|
+
export { canonicalReviewHeldRevisionIds, resolveCanonicalReviewRange };
|
|
@@ -7,7 +7,6 @@ type CanonicalStoryEditorOptions = {
|
|
|
7
7
|
story: OpStory;
|
|
8
8
|
getView: () => EditorView;
|
|
9
9
|
getApi: () => HiddenEditorApi | null;
|
|
10
|
-
enabled: () => boolean;
|
|
11
10
|
onSelectionChange: () => void;
|
|
12
11
|
onRefusal: ((reason: string, ground: CanonicalRefusalGround) => void) | undefined;
|
|
13
12
|
};
|
|
@@ -24,8 +23,8 @@ export declare const refreshCanonicalStoryView: ({ view, story, api }: {
|
|
|
24
23
|
api: HiddenEditorApi | null | undefined;
|
|
25
24
|
}) => void;
|
|
26
25
|
/** Secondary views compile classified native input into the shared Document journal. */
|
|
27
|
-
export declare const createCanonicalStoryEditor: ({ story, getView, getApi,
|
|
28
|
-
dispatch: (transaction: Transaction) =>
|
|
26
|
+
export declare const createCanonicalStoryEditor: ({ story, getView, getApi, onRefusal, onSelectionChange }: CanonicalStoryEditorOptions) => {
|
|
27
|
+
dispatch: (transaction: Transaction) => void;
|
|
29
28
|
props: {
|
|
30
29
|
handleKeyDown: (view: EditorView, event: KeyboardEvent) => boolean;
|
|
31
30
|
handleTextInput: (view: EditorView, from: number, to: number, text: string) => boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CanonicalSessionError } from "../canonical/canonicalSession.js";
|
|
2
2
|
import { adoptNativeSelection, isCompositionKeyDown } from "../prosemirror/nativeSelection.js";
|
|
3
|
-
import {
|
|
3
|
+
import { CANONICAL_CONDITION } from "../types/canonicalCapabilities.js";
|
|
4
4
|
import { createCanonicalInputBoundary, unclassifiedMutationMessage } from "./canonicalInput.js";
|
|
5
5
|
import { TextSelection } from "prosemirror-state";
|
|
6
6
|
// src/controller/canonicalStoryEditor.ts
|
|
@@ -29,9 +29,8 @@ const refreshCanonicalStoryView = ({ view, story, api }) => {
|
|
|
29
29
|
view.updateState(view.state.apply(transaction));
|
|
30
30
|
};
|
|
31
31
|
/** Secondary views compile classified native input into the shared Document journal. */
|
|
32
|
-
const createCanonicalStoryEditor = ({ story, getView, getApi,
|
|
33
|
-
const refuse = (reason) => {
|
|
34
|
-
const ground = { gap: CANONICAL_GAP.dispatch };
|
|
32
|
+
const createCanonicalStoryEditor = ({ story, getView, getApi, onRefusal, onSelectionChange }) => {
|
|
33
|
+
const refuse = (reason, ground) => {
|
|
35
34
|
const message = reason;
|
|
36
35
|
if (onRefusal) onRefusal(message, ground);
|
|
37
36
|
else throw new CanonicalSessionError({
|
|
@@ -70,30 +69,52 @@ const createCanonicalStoryEditor = ({ story, getView, getApi, enabled, onRefusal
|
|
|
70
69
|
intent
|
|
71
70
|
}) && !view.isDestroyed) onSelectionChange();
|
|
72
71
|
},
|
|
72
|
+
structure: (type) => {
|
|
73
|
+
const view = getView();
|
|
74
|
+
if (getApi()?.applyCanonicalStoryStructure({
|
|
75
|
+
view,
|
|
76
|
+
story,
|
|
77
|
+
type
|
|
78
|
+
}) && !view.isDestroyed) onSelectionChange();
|
|
79
|
+
},
|
|
80
|
+
cut: (view, event) => {
|
|
81
|
+
const api = getApi();
|
|
82
|
+
if (!api) {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
refuse("The document is not ready for a cut.", { condition: CANONICAL_CONDITION.notReady });
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
const handled = api.cutCanonicalStory({
|
|
88
|
+
view,
|
|
89
|
+
story,
|
|
90
|
+
event
|
|
91
|
+
});
|
|
92
|
+
if (!view.isDestroyed) onSelectionChange();
|
|
93
|
+
return handled;
|
|
94
|
+
},
|
|
73
95
|
undo: () => history("undo"),
|
|
74
96
|
redo: () => history("redo"),
|
|
75
97
|
refuse
|
|
76
98
|
});
|
|
77
99
|
return {
|
|
78
100
|
dispatch: (transaction) => {
|
|
79
|
-
if (!enabled()) return false;
|
|
80
101
|
const view = getView();
|
|
81
102
|
getApi()?.noteCanonicalStoryView({
|
|
82
103
|
story,
|
|
83
104
|
view
|
|
84
105
|
});
|
|
85
106
|
if (transaction.docChanged) {
|
|
86
|
-
if (boundary.acceptComposition(view, transaction)) return
|
|
107
|
+
if (boundary.acceptComposition(view, transaction)) return;
|
|
87
108
|
if (!boundary.commitNativeProposal(view, transaction)) boundary.refuseNativeMutation(view, transaction);
|
|
88
109
|
view.updateState(view.state);
|
|
89
|
-
return
|
|
110
|
+
return;
|
|
90
111
|
}
|
|
91
112
|
if (transaction.selectionSet && !boundary.isComposing) getApi()?.updateCanonicalInputLifecycle("breakUndoGroup");
|
|
92
113
|
const applied = view.state.applyTransaction(transaction);
|
|
93
114
|
if (!applied.state.doc.eq(view.state.doc)) {
|
|
94
|
-
refuse(unclassifiedMutationMessage(applied.transactions, "A plugin attempted an unclassified canonical story mutation."));
|
|
115
|
+
refuse(unclassifiedMutationMessage(applied.transactions, "A plugin attempted an unclassified canonical story mutation."), { condition: CANONICAL_CONDITION.hostTransaction });
|
|
95
116
|
view.updateState(view.state);
|
|
96
|
-
return
|
|
117
|
+
return;
|
|
97
118
|
}
|
|
98
119
|
view.updateState(applied.state);
|
|
99
120
|
if (applied.transactions.some((step) => step.selectionSet)) {
|
|
@@ -103,39 +124,36 @@ const createCanonicalStoryEditor = ({ story, getView, getApi, enabled, onRefusal
|
|
|
103
124
|
});
|
|
104
125
|
onSelectionChange();
|
|
105
126
|
}
|
|
106
|
-
return true;
|
|
107
127
|
},
|
|
108
128
|
props: {
|
|
109
|
-
handleKeyDown: (view, event) =>
|
|
110
|
-
handleTextInput: (view, from, to, text) =>
|
|
111
|
-
handleKeyPress: (view, event) =>
|
|
129
|
+
handleKeyDown: (view, event) => boundary.handleKeyDown(view, event),
|
|
130
|
+
handleTextInput: (view, from, to, text) => boundary.handleTextInput(view, from, to, text),
|
|
131
|
+
handleKeyPress: (view, event) => boundary.handleKeyPress(view, event),
|
|
112
132
|
handleDOMEvents: {
|
|
113
133
|
keydown: (view, event) => {
|
|
114
|
-
if (!enabled()) return false;
|
|
115
134
|
if (!isCompositionKeyDown(event)) syncNativeSelection(view);
|
|
116
135
|
return boundary.handleDOMEvents.keydown(view, event);
|
|
117
136
|
},
|
|
118
137
|
keyup: (view, event) => {
|
|
119
|
-
if (
|
|
138
|
+
if (/^(?:Arrow|Home$|End$|Page)/u.test(event.key)) syncNativeSelection(view);
|
|
120
139
|
return false;
|
|
121
140
|
},
|
|
122
141
|
mouseup: (view) => {
|
|
123
|
-
|
|
142
|
+
syncNativeSelection(view);
|
|
124
143
|
return false;
|
|
125
144
|
},
|
|
126
145
|
beforeinput: (view, event) => {
|
|
127
|
-
if (!enabled()) return false;
|
|
128
146
|
if (!event.isComposing) syncNativeSelection(view);
|
|
129
147
|
return boundary.handleDOMEvents.beforeinput(view, event);
|
|
130
148
|
},
|
|
131
|
-
mousedown: (view) =>
|
|
132
|
-
compositionstart: (view) =>
|
|
133
|
-
compositionend: (view, event) =>
|
|
134
|
-
input: (view) =>
|
|
135
|
-
blur: (view) =>
|
|
136
|
-
paste: (view, event) =>
|
|
137
|
-
cut: (view, event) =>
|
|
138
|
-
drop: (view, event) =>
|
|
149
|
+
mousedown: (view) => boundary.handleDOMEvents.mousedown(view),
|
|
150
|
+
compositionstart: (view) => boundary.handleDOMEvents.compositionstart(view),
|
|
151
|
+
compositionend: (view, event) => boundary.handleDOMEvents.compositionend(view, event),
|
|
152
|
+
input: (view) => boundary.handleDOMEvents.input(view),
|
|
153
|
+
blur: (view) => boundary.handleDOMEvents.blur(view),
|
|
154
|
+
paste: (view, event) => boundary.handleDOMEvents.paste(view, event),
|
|
155
|
+
cut: (view, event) => boundary.handleDOMEvents.cut(view, event),
|
|
156
|
+
drop: (view, event) => boundary.handleDOMEvents.drop(view, event)
|
|
139
157
|
}
|
|
140
158
|
}
|
|
141
159
|
};
|
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
import { CanonicalCommit, CanonicalSession, CanonicalSessionError } from "../canonical/canonicalSession.js";
|
|
2
2
|
import { CanonicalCommandIntent } from "../prosemirror/canonicalCommands.js";
|
|
3
3
|
import { document_d_exports } from "../types/document.js";
|
|
4
|
+
import { CanonicalStructureInput } from "./canonicalInput.js";
|
|
4
5
|
import { Result } from "better-result";
|
|
5
6
|
import { EditorState } from "prosemirror-state";
|
|
6
|
-
|
|
7
|
+
import { OpStory } from "@stll/docx-core/ops";
|
|
7
8
|
/** Whether a paragraph is in a list, by numbering of its own or its style's. */
|
|
8
9
|
export declare const isCanonicalListParagraph: (paragraph: document_d_exports.Paragraph | undefined) => boolean;
|
|
9
|
-
/**
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Toolbar meanings enter the same operation journal as native input, in the
|
|
12
|
+
* story whose editor holds `state`: the body, or a header, footer or note.
|
|
13
|
+
*/
|
|
14
|
+
export declare const prepareCanonicalCommands: (session: CanonicalSession, state: EditorState, requested: readonly CanonicalCommandIntent[], story?: OpStory) => Result<CanonicalCommit, CanonicalSessionError>;
|
|
15
|
+
/**
|
|
16
|
+
* The structure edit a key asks for at the selection of the editor showing
|
|
17
|
+
* `story`, the body or a header, footer or note, as one commit: Enter splits
|
|
18
|
+
* the paragraph (or takes an empty list paragraph out of its list),
|
|
19
|
+
* Backspace and Delete at a paragraph's edge join it with its neighbour
|
|
20
|
+
* (Backspace first takes the paragraph out of its list or clears its
|
|
21
|
+
* indent), Tab and Shift+Tab change a list paragraph's level, and Tab, a line
|
|
22
|
+
* break and a page break go in as atoms. Over selected cells, each is
|
|
23
|
+
* cleared and the edit happens in the first. A table's deletion is the
|
|
24
|
+
* caller's: it runs the table command.
|
|
25
|
+
*/
|
|
26
|
+
export declare const prepareCanonicalStructure: (session: CanonicalSession, state: EditorState, story: OpStory, type: Exclude<CanonicalStructureInput, "deleteTable">) => Result<CanonicalCommit, CanonicalSessionError>;
|
|
11
27
|
type CanonicalAutoformatTrigger = {
|
|
12
28
|
from: number;
|
|
13
29
|
to: number;
|