@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,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,30 @@
|
|
|
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";
|
|
7
|
+
import { OpStory } from "@stll/docx-core/ops";
|
|
6
8
|
export declare const CELL_SELECTION_PLACEMENT_REFUSAL = "A note or table of contents goes at a caret, not over selected cells.";
|
|
7
9
|
/** Whether a paragraph is in a list, by numbering of its own or its style's. */
|
|
8
10
|
export declare const isCanonicalListParagraph: (paragraph: document_d_exports.Paragraph | undefined) => boolean;
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Toolbar meanings enter the same operation journal as native input, in the
|
|
13
|
+
* story whose editor holds `state`: the body, or a header, footer or note.
|
|
14
|
+
*/
|
|
15
|
+
export declare const prepareCanonicalCommands: (session: CanonicalSession, state: EditorState, commands: readonly CanonicalCommandIntent[], story?: OpStory) => Result<CanonicalCommit, CanonicalSessionError>;
|
|
16
|
+
/**
|
|
17
|
+
* The structure edit a key asks for at the selection of the editor showing
|
|
18
|
+
* `story`, the body or a header, footer or note, as one commit: Enter splits
|
|
19
|
+
* the paragraph (or takes an empty list paragraph out of its list),
|
|
20
|
+
* Backspace and Delete at a paragraph's edge join it with its neighbour
|
|
21
|
+
* (Backspace first takes the paragraph out of its list or clears its
|
|
22
|
+
* indent), Tab and Shift+Tab change a list paragraph's level, and Tab, a line
|
|
23
|
+
* break and a page break go in as atoms. Over selected cells, each is
|
|
24
|
+
* cleared and the edit happens in the first. A table's deletion is the
|
|
25
|
+
* caller's: it runs the table command.
|
|
26
|
+
*/
|
|
27
|
+
export declare const prepareCanonicalStructure: (session: CanonicalSession, state: EditorState, story: OpStory, type: Exclude<CanonicalStructureInput, "deleteTable">) => Result<CanonicalCommit, CanonicalSessionError>;
|
|
11
28
|
type CanonicalAutoformatTrigger = {
|
|
12
29
|
from: number;
|
|
13
30
|
to: number;
|
|
@@ -8,7 +8,7 @@ import { listRequestsForMarker } from "../prosemirror/listAutoformatMarkers.js";
|
|
|
8
8
|
import { unusedListInstanceFor } from "../prosemirror/listNumbering.js";
|
|
9
9
|
import { effectiveParagraphNumbering, paragraphNumberingSourcesFromBoundary } from "../prosemirror/numberingAttr.js";
|
|
10
10
|
import { createStyleResolver } from "../prosemirror/styles/styleResolver.js";
|
|
11
|
-
import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
|
|
11
|
+
import { CANONICAL_CONDITION, CANONICAL_GAP } from "../types/canonicalCapabilities.js";
|
|
12
12
|
import { readModel } from "../types/documentModel.js";
|
|
13
13
|
import { maxOf } from "../utils/extremes.js";
|
|
14
14
|
import { collectHeadings } from "../utils/headingCollector.js";
|
|
@@ -42,7 +42,7 @@ const noChange = (message) => Result.err(new CanonicalSessionError({
|
|
|
42
42
|
message,
|
|
43
43
|
reason: "noChange"
|
|
44
44
|
}));
|
|
45
|
-
const selectedParagraphs = (
|
|
45
|
+
const selectedParagraphs = (projection, state, topLevelOnly = false) => {
|
|
46
46
|
const ids = /* @__PURE__ */ new Set();
|
|
47
47
|
const paragraphs = [];
|
|
48
48
|
state.doc.nodesBetween(state.selection.from, state.selection.to, (node, position) => {
|
|
@@ -51,7 +51,7 @@ const selectedParagraphs = (session, state, topLevelOnly = false) => {
|
|
|
51
51
|
const id = node.attrs["paraId"];
|
|
52
52
|
if (ids.has(id)) return;
|
|
53
53
|
ids.add(id);
|
|
54
|
-
const paragraph =
|
|
54
|
+
const paragraph = projection.paragraph(id)?.source;
|
|
55
55
|
if (paragraph !== void 0) paragraphs.push(paragraph);
|
|
56
56
|
});
|
|
57
57
|
return paragraphs;
|
|
@@ -73,11 +73,11 @@ const numberingRemoval = (session) => {
|
|
|
73
73
|
/** Whether a paragraph is in a list, by numbering of its own or its style's. */
|
|
74
74
|
const isCanonicalListParagraph = (paragraph) => effectiveNumbering(paragraph).kind === "reference";
|
|
75
75
|
/** Each selected paragraph with the block container that owns it. A list may run through several containers, such as table cells, as the editor applies it. */
|
|
76
|
-
const paragraphPositions = (
|
|
76
|
+
const paragraphPositions = (projection, paragraphs) => {
|
|
77
77
|
if (paragraphs.length === 0) return noChange("List changes require a paragraph selection.");
|
|
78
78
|
const positions = [];
|
|
79
79
|
for (const paragraph of paragraphs) {
|
|
80
|
-
const address =
|
|
80
|
+
const address = projection.paragraph(paragraph.paraId ?? "");
|
|
81
81
|
if (address === void 0) return refuse("A selected paragraph has no canonical address.");
|
|
82
82
|
const index = address.container.findIndex((item) => item === paragraph);
|
|
83
83
|
if (index < 0) return refuse("A selected paragraph is missing from its block container.");
|
|
@@ -119,7 +119,7 @@ const referencedNumIds = (document) => {
|
|
|
119
119
|
});
|
|
120
120
|
return referenced;
|
|
121
121
|
};
|
|
122
|
-
const numberingIntent = (session, positions, request) => {
|
|
122
|
+
const numberingIntent = (session, positions, request, story = OP_STORIES.MAIN) => {
|
|
123
123
|
const definitions = readModel(session.document).package.numbering;
|
|
124
124
|
const map = definitions === void 0 ? void 0 : getCachedNumberingMap(definitions);
|
|
125
125
|
const container = positions.at(0)?.container ?? [];
|
|
@@ -181,7 +181,7 @@ const numberingIntent = (session, positions, request) => {
|
|
|
181
181
|
target,
|
|
182
182
|
items: positions.map(({ paragraph }) => ({
|
|
183
183
|
at: {
|
|
184
|
-
story
|
|
184
|
+
story,
|
|
185
185
|
blockId: paragraph.paraId ?? "",
|
|
186
186
|
offset: 0
|
|
187
187
|
},
|
|
@@ -189,8 +189,19 @@ const numberingIntent = (session, positions, request) => {
|
|
|
189
189
|
}))
|
|
190
190
|
};
|
|
191
191
|
};
|
|
192
|
-
/**
|
|
193
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Toolbar meanings enter the same operation journal as native input, in the
|
|
194
|
+
* story whose editor holds `state`: the body, or a header, footer or note.
|
|
195
|
+
*/
|
|
196
|
+
const prepareCanonicalCommands = (session, state, commands, story = OP_STORIES.MAIN) => {
|
|
197
|
+
if (story !== OP_STORIES.MAIN && commands.some(({ type }) => type === "setSectionBreak" || type === "removeSectionBreak" || type === "insertNote" || type === "deleteNote" || type === "generateTOC")) return Result.err(new CanonicalSessionError({
|
|
198
|
+
ground: { condition: CANONICAL_CONDITION.invalidRequest },
|
|
199
|
+
message: "Section breaks, notes and tables of contents go in the main story.",
|
|
200
|
+
reason: "refused"
|
|
201
|
+
}));
|
|
202
|
+
const projected = session.projectStory(story);
|
|
203
|
+
if (projected.isErr()) return projected;
|
|
204
|
+
const projection = projected.value;
|
|
194
205
|
const replacements = commands.filter((command) => command.type === "replaceText");
|
|
195
206
|
if (replacements.length > 0) {
|
|
196
207
|
if (replacements.length !== commands.length) return refuse("A text replacement must be prepared on its own.");
|
|
@@ -198,14 +209,15 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
198
209
|
if (only !== void 0 && replacements.length === 1) return session.prepareReplace(state, {
|
|
199
210
|
from: only.from,
|
|
200
211
|
to: only.to,
|
|
201
|
-
text: only.text
|
|
212
|
+
text: only.text,
|
|
213
|
+
story
|
|
202
214
|
});
|
|
203
215
|
const intents = [];
|
|
204
216
|
for (const replacement of replacements) {
|
|
205
|
-
const edges =
|
|
206
|
-
const from =
|
|
217
|
+
const edges = projection.rangeEdgesAt(replacement.from, replacement.to);
|
|
218
|
+
const from = projection.inputAddressAt(replacement.from, edges.start);
|
|
207
219
|
if (from.isErr()) return from;
|
|
208
|
-
const to =
|
|
220
|
+
const to = projection.inputAddressAt(replacement.to, edges.end);
|
|
209
221
|
if (to.isErr()) return to;
|
|
210
222
|
intents.push({
|
|
211
223
|
type: "replaceText",
|
|
@@ -227,7 +239,7 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
227
239
|
const sectionCommands = commands.filter((command) => command.type === "setSectionBreak" || command.type === "removeSectionBreak");
|
|
228
240
|
if (sectionCommands.length > 0) {
|
|
229
241
|
if (sectionCommands.length !== commands.length || sectionCommands.length !== 1) return refuse("A section change must be prepared on its own.");
|
|
230
|
-
const paragraphs = selectedParagraphs(
|
|
242
|
+
const paragraphs = selectedParagraphs(projection, state, true);
|
|
231
243
|
if (paragraphs.length === 0) return refuse("Section breaks require a top-level document paragraph.");
|
|
232
244
|
const command = sectionCommands.at(0) ?? panic("A section command was counted.");
|
|
233
245
|
return session.prepareOperations(state, paragraphs.map((paragraph) => {
|
|
@@ -250,7 +262,7 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
250
262
|
};
|
|
251
263
|
}));
|
|
252
264
|
}
|
|
253
|
-
const paragraphs = selectedParagraphs(
|
|
265
|
+
const paragraphs = selectedParagraphs(projection, state);
|
|
254
266
|
const noteCommands = commands.filter((command) => command.type === "insertNote" || command.type === "deleteNote");
|
|
255
267
|
if (noteCommands.length > 0) {
|
|
256
268
|
if (noteCommands.length !== commands.length) return refuse("Note changes must be prepared on their own.");
|
|
@@ -260,7 +272,7 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
260
272
|
if (blockIdGroups.isErr()) return blockIdGroups;
|
|
261
273
|
for (const [commandIndex, command] of ordered.entries()) {
|
|
262
274
|
if (command.type === "deleteNote") {
|
|
263
|
-
const at =
|
|
275
|
+
const at = projection.addressAt(command.from);
|
|
264
276
|
if (at.isErr()) return at;
|
|
265
277
|
ops.push({
|
|
266
278
|
type: DOCUMENT_OP_TYPES.REMOVE_NOTE,
|
|
@@ -272,7 +284,7 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
272
284
|
});
|
|
273
285
|
continue;
|
|
274
286
|
}
|
|
275
|
-
const at =
|
|
287
|
+
const at = projection.addressAt(command.at);
|
|
276
288
|
if (at.isErr()) return at;
|
|
277
289
|
if (command.content.some((block) => block.type !== "paragraph")) return refuse("Canonical note insertion requires paragraph content.");
|
|
278
290
|
const blockIds = blockIdGroups.value[commandIndex] ?? panic("A fresh identity group was reserved per note.");
|
|
@@ -290,13 +302,13 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
290
302
|
}
|
|
291
303
|
for (const command of commands) switch (command.type) {
|
|
292
304
|
case "generateTOC": {
|
|
293
|
-
const at =
|
|
305
|
+
const at = projection.addressAt(command.at);
|
|
294
306
|
if (at.isErr()) return at;
|
|
295
307
|
const definitions = readModel(session.document).package.styles;
|
|
296
308
|
const styles = createBuiltInStyleIndex(definitions?.styles ?? [], definitions?.docDefaults);
|
|
297
309
|
const headings = [];
|
|
298
|
-
for (const heading of collectHeadings(
|
|
299
|
-
const address =
|
|
310
|
+
for (const heading of collectHeadings(projection.doc, styles)) {
|
|
311
|
+
const address = projection.addressAt(heading.pmPos + 1);
|
|
300
312
|
if (address.isErr()) return address;
|
|
301
313
|
const outline = headingOutlineLevel(heading.level);
|
|
302
314
|
if (outline?.kind !== "heading") return refuse("A TOC heading has an invalid outline level.");
|
|
@@ -325,9 +337,9 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
325
337
|
case "setHyperlink":
|
|
326
338
|
case "removeHyperlink":
|
|
327
339
|
case "insertHyperlink": {
|
|
328
|
-
const from =
|
|
340
|
+
const from = projection.addressAt(command.from);
|
|
329
341
|
if (from.isErr()) return from;
|
|
330
|
-
const to =
|
|
342
|
+
const to = projection.addressAt(command.to);
|
|
331
343
|
if (to.isErr()) return to;
|
|
332
344
|
intents.push({
|
|
333
345
|
...command,
|
|
@@ -338,7 +350,7 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
338
350
|
}
|
|
339
351
|
case "formatTable":
|
|
340
352
|
for (const target of command.targets) {
|
|
341
|
-
const at =
|
|
353
|
+
const at = projection.addressAt(target.at);
|
|
342
354
|
if (at.isErr()) return at;
|
|
343
355
|
const address = {
|
|
344
356
|
story: at.value.story,
|
|
@@ -380,7 +392,7 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
380
392
|
}
|
|
381
393
|
break;
|
|
382
394
|
case "editTableBlock": {
|
|
383
|
-
const at =
|
|
395
|
+
const at = projection.addressAt(command.at);
|
|
384
396
|
if (at.isErr()) return at;
|
|
385
397
|
intents.push({
|
|
386
398
|
type: "tableBlock",
|
|
@@ -393,7 +405,7 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
393
405
|
break;
|
|
394
406
|
}
|
|
395
407
|
case "editTableRow": {
|
|
396
|
-
const at =
|
|
408
|
+
const at = projection.addressAt(command.at);
|
|
397
409
|
if (at.isErr()) return at;
|
|
398
410
|
intents.push({
|
|
399
411
|
type: "tableRow",
|
|
@@ -406,7 +418,7 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
406
418
|
break;
|
|
407
419
|
}
|
|
408
420
|
case "editTable": {
|
|
409
|
-
const at =
|
|
421
|
+
const at = projection.addressAt(command.at);
|
|
410
422
|
if (at.isErr()) return at;
|
|
411
423
|
intents.push({
|
|
412
424
|
type: "table",
|
|
@@ -420,9 +432,9 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
420
432
|
}
|
|
421
433
|
case "selection": break;
|
|
422
434
|
case "insertBreak": {
|
|
423
|
-
const from =
|
|
435
|
+
const from = projection.addressAt(command.from);
|
|
424
436
|
if (from.isErr()) return from;
|
|
425
|
-
const to =
|
|
437
|
+
const to = projection.addressAt(command.to);
|
|
426
438
|
if (to.isErr()) return to;
|
|
427
439
|
intents.push({
|
|
428
440
|
type: "insertAtom",
|
|
@@ -442,9 +454,9 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
442
454
|
case "setContentControlValue": return panic("Control values are prepared before editor intents.");
|
|
443
455
|
case "replaceText": return panic("Text replacements are prepared before editor intents.");
|
|
444
456
|
case "formatRun": {
|
|
445
|
-
const from =
|
|
457
|
+
const from = projection.addressAt(command.from);
|
|
446
458
|
if (from.isErr()) return from;
|
|
447
|
-
const to =
|
|
459
|
+
const to = projection.addressAt(command.to);
|
|
448
460
|
if (to.isErr()) return to;
|
|
449
461
|
intents.push({
|
|
450
462
|
type: "formatRun",
|
|
@@ -455,7 +467,7 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
455
467
|
break;
|
|
456
468
|
}
|
|
457
469
|
case "formatParagraph": {
|
|
458
|
-
const at =
|
|
470
|
+
const at = projection.addressAt(command.at);
|
|
459
471
|
if (at.isErr()) return at;
|
|
460
472
|
intents.push({
|
|
461
473
|
type: "formatParagraph",
|
|
@@ -465,7 +477,7 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
465
477
|
break;
|
|
466
478
|
}
|
|
467
479
|
case "toggleList": {
|
|
468
|
-
const positions = paragraphPositions(
|
|
480
|
+
const positions = paragraphPositions(projection, paragraphs);
|
|
469
481
|
if (positions.isErr()) return positions;
|
|
470
482
|
const definitions = readModel(session.document).package.numbering;
|
|
471
483
|
const map = definitions === void 0 ? void 0 : getCachedNumberingMap(definitions);
|
|
@@ -473,14 +485,14 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
473
485
|
const numPr = effectiveNumbering(paragraph);
|
|
474
486
|
return numPr?.kind === "reference" && numberingLevelUsesBulletMarker(map?.getLevel(numPr.numId, numPr.ilvl ?? 0)) === (command.kind === "bullet");
|
|
475
487
|
}))) {
|
|
476
|
-
intents.push(numberingIntent(session, positions.value, { kind: command.kind === "bullet" ? "bullet" : "numbered" }));
|
|
488
|
+
intents.push(numberingIntent(session, positions.value, { kind: command.kind === "bullet" ? "bullet" : "numbered" }, story));
|
|
477
489
|
break;
|
|
478
490
|
}
|
|
479
491
|
const removed = numberingRemoval(session);
|
|
480
492
|
for (const paragraph of paragraphs) intents.push({
|
|
481
493
|
type: "formatParagraph",
|
|
482
494
|
at: {
|
|
483
|
-
story
|
|
495
|
+
story,
|
|
484
496
|
blockId: paragraph.paraId ?? "",
|
|
485
497
|
offset: 0
|
|
486
498
|
},
|
|
@@ -489,13 +501,13 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
489
501
|
break;
|
|
490
502
|
}
|
|
491
503
|
case "removeList": {
|
|
492
|
-
const positions = paragraphPositions(
|
|
504
|
+
const positions = paragraphPositions(projection, paragraphs);
|
|
493
505
|
if (positions.isErr()) return positions;
|
|
494
506
|
const removed = numberingRemoval(session);
|
|
495
507
|
for (const paragraph of paragraphs) intents.push({
|
|
496
508
|
type: "formatParagraph",
|
|
497
509
|
at: {
|
|
498
|
-
story
|
|
510
|
+
story,
|
|
499
511
|
blockId: paragraph.paraId ?? "",
|
|
500
512
|
offset: 0
|
|
501
513
|
},
|
|
@@ -504,14 +516,14 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
504
516
|
break;
|
|
505
517
|
}
|
|
506
518
|
case "changeListLevel": {
|
|
507
|
-
const positions = paragraphPositions(
|
|
519
|
+
const positions = paragraphPositions(projection, paragraphs);
|
|
508
520
|
if (positions.isErr()) return positions;
|
|
509
521
|
const removed = numberingRemoval(session);
|
|
510
522
|
for (const paragraph of paragraphs) {
|
|
511
523
|
const numPr = effectiveNumbering(paragraph);
|
|
512
524
|
if (numPr?.kind !== "reference") continue;
|
|
513
525
|
const at = {
|
|
514
|
-
story
|
|
526
|
+
story,
|
|
515
527
|
blockId: paragraph.paraId ?? "",
|
|
516
528
|
offset: 0
|
|
517
529
|
};
|
|
@@ -537,7 +549,7 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
537
549
|
}
|
|
538
550
|
case "restartNumbering":
|
|
539
551
|
case "continueNumbering": {
|
|
540
|
-
const positions = paragraphPositions(
|
|
552
|
+
const positions = paragraphPositions(projection, paragraphs);
|
|
541
553
|
if (positions.isErr()) return positions;
|
|
542
554
|
const source = paragraphs.at(0);
|
|
543
555
|
const numPr = effectiveNumbering(source);
|
|
@@ -593,7 +605,7 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
593
605
|
const effective = effectiveNumbering(paragraph);
|
|
594
606
|
return {
|
|
595
607
|
at: {
|
|
596
|
-
story
|
|
608
|
+
story,
|
|
597
609
|
blockId: paragraph.paraId ?? "",
|
|
598
610
|
offset: 0
|
|
599
611
|
},
|
|
@@ -608,6 +620,91 @@ const prepareCanonicalCommands = (session, state, commands) => {
|
|
|
608
620
|
return session.prepareIntents(state, { intents });
|
|
609
621
|
};
|
|
610
622
|
/**
|
|
623
|
+
* The structure edit a key asks for at the selection of the editor showing
|
|
624
|
+
* `story`, the body or a header, footer or note, as one commit: Enter splits
|
|
625
|
+
* the paragraph (or takes an empty list paragraph out of its list),
|
|
626
|
+
* Backspace and Delete at a paragraph's edge join it with its neighbour
|
|
627
|
+
* (Backspace first takes the paragraph out of its list or clears its
|
|
628
|
+
* indent), Tab and Shift+Tab change a list paragraph's level, and Tab, a line
|
|
629
|
+
* break and a page break go in as atoms. Over selected cells, each is
|
|
630
|
+
* cleared and the edit happens in the first. A table's deletion is the
|
|
631
|
+
* caller's: it runs the table command.
|
|
632
|
+
*/
|
|
633
|
+
const prepareCanonicalStructure = (session, state, story, type) => {
|
|
634
|
+
if (type === "pageBreak" && story !== OP_STORIES.MAIN) return Result.err(new CanonicalSessionError({
|
|
635
|
+
ground: { condition: CANONICAL_CONDITION.invalidRequest },
|
|
636
|
+
message: "A page break goes in the main story.",
|
|
637
|
+
reason: "refused"
|
|
638
|
+
}));
|
|
639
|
+
if (state.selection instanceof CellSelection && (type === "split" || type === "tab" || type === "lineBreak" || type === "pageBreak")) return session.prepareCellSelectionStructure(state, (at) => type === "split" ? {
|
|
640
|
+
type: "replaceFragment",
|
|
641
|
+
from: at,
|
|
642
|
+
to: at,
|
|
643
|
+
paragraphs: [{
|
|
644
|
+
type: "paragraph",
|
|
645
|
+
content: []
|
|
646
|
+
}, {
|
|
647
|
+
type: "paragraph",
|
|
648
|
+
content: []
|
|
649
|
+
}],
|
|
650
|
+
openStart: 1,
|
|
651
|
+
openEnd: 1
|
|
652
|
+
} : {
|
|
653
|
+
type: "insertAtom",
|
|
654
|
+
from: at,
|
|
655
|
+
to: at,
|
|
656
|
+
atom: type === "tab" ? { type: "tab" } : {
|
|
657
|
+
type: "break",
|
|
658
|
+
breakType: type === "pageBreak" ? "page" : "textWrapping"
|
|
659
|
+
}
|
|
660
|
+
}, { story });
|
|
661
|
+
const projected = session.projectStory(story);
|
|
662
|
+
if (projected.isErr()) return projected;
|
|
663
|
+
const projection = projected.value;
|
|
664
|
+
const selection = projection.selectionAt(state);
|
|
665
|
+
if (selection.isErr()) return selection;
|
|
666
|
+
const paragraph = projection.paragraph(selection.value.head.blockId)?.source;
|
|
667
|
+
switch (type) {
|
|
668
|
+
case "split": return isCanonicalListParagraph(paragraph) && state.selection.$from.parent.content.size === 0 ? prepareCanonicalCommands(session, state, [{ type: "removeList" }], story) : session.prepareSplit(state, story);
|
|
669
|
+
case "joinBackward":
|
|
670
|
+
if (isCanonicalListParagraph(paragraph)) return prepareCanonicalCommands(session, state, [{ type: "removeList" }], story);
|
|
671
|
+
if ((paragraph?.formatting?.indentLeft ?? 0) > 0 || (paragraph?.formatting?.indentFirstLine ?? 0) > 0) return session.prepareIntent(state, {
|
|
672
|
+
type: "formatParagraph",
|
|
673
|
+
at: selection.value.head,
|
|
674
|
+
patch: {
|
|
675
|
+
indentLeft: null,
|
|
676
|
+
indentFirstLine: null,
|
|
677
|
+
hangingIndent: null
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
return session.prepareJoin(state, "backward", story);
|
|
681
|
+
case "joinForward": return session.prepareJoin(state, "forward", story);
|
|
682
|
+
case "indent":
|
|
683
|
+
case "outdent": return prepareCanonicalCommands(session, state, [{
|
|
684
|
+
type: "changeListLevel",
|
|
685
|
+
direction: type === "indent" ? "increase" : "decrease"
|
|
686
|
+
}], story);
|
|
687
|
+
case "tab":
|
|
688
|
+
case "lineBreak":
|
|
689
|
+
case "pageBreak": {
|
|
690
|
+
const from = projection.addressAt(state.selection.from);
|
|
691
|
+
if (from.isErr()) return from;
|
|
692
|
+
const to = projection.addressAt(state.selection.to);
|
|
693
|
+
if (to.isErr()) return to;
|
|
694
|
+
return session.prepareIntent(state, {
|
|
695
|
+
type: "insertAtom",
|
|
696
|
+
from: from.value,
|
|
697
|
+
to: to.value,
|
|
698
|
+
atom: type === "tab" ? { type: "tab" } : {
|
|
699
|
+
type: "break",
|
|
700
|
+
breakType: type === "pageBreak" ? "page" : "textWrapping"
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
default: return type;
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
/**
|
|
611
708
|
* The rule that `typed`, already committed as typed, completes at the caret of
|
|
612
709
|
* `state`: the marker's removal and the paragraph change as one atomic edit.
|
|
613
710
|
*
|
|
@@ -645,7 +742,7 @@ const prepareCanonicalAutoformat = (session, state, typed) => {
|
|
|
645
742
|
patch: { styleId }
|
|
646
743
|
};
|
|
647
744
|
else {
|
|
648
|
-
const positions = paragraphPositions(session, [source]);
|
|
745
|
+
const positions = paragraphPositions(session.projection, [source]);
|
|
649
746
|
if (positions.isErr()) return void 0;
|
|
650
747
|
paragraphIntent = numberingIntent(session, positions.value, request);
|
|
651
748
|
}
|
|
@@ -656,4 +753,4 @@ const prepareCanonicalAutoformat = (session, state, typed) => {
|
|
|
656
753
|
text: ""
|
|
657
754
|
}, paragraphIntent] });
|
|
658
755
|
};
|
|
659
|
-
export { CELL_SELECTION_PLACEMENT_REFUSAL, isCanonicalListParagraph, prepareCanonicalAutoformat, prepareCanonicalCommands };
|
|
756
|
+
export { CELL_SELECTION_PLACEMENT_REFUSAL, isCanonicalListParagraph, prepareCanonicalAutoformat, prepareCanonicalCommands, prepareCanonicalStructure };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DisplayListPagePainterFactory } from "./layoutPipelineExecution.js";
|
|
2
|
+
type DisplayListPainterLoaderOptions = {
|
|
3
|
+
onReady: () => void;
|
|
4
|
+
onError: (error: Error) => void;
|
|
5
|
+
};
|
|
6
|
+
/** Notify an editor once per in-flight load, regardless of how many layouts requested it. */
|
|
7
|
+
export declare const createDisplayListPainterLoader: ({ onReady, onError }: DisplayListPainterLoaderOptions) => () => DisplayListPagePainterFactory | undefined;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Result } from "better-result";
|
|
2
|
+
// src/controller/deferredDisplayListPainter.ts
|
|
3
|
+
let painter;
|
|
4
|
+
let pending;
|
|
5
|
+
const loadPainter = () => {
|
|
6
|
+
pending ??= Result.tryPromise({
|
|
7
|
+
try: async () => {
|
|
8
|
+
const { createDisplayListPagePainter } = await import("../display-list/editor/displayListPagePainter.js");
|
|
9
|
+
painter = createDisplayListPagePainter;
|
|
10
|
+
return painter;
|
|
11
|
+
},
|
|
12
|
+
catch: (cause) => new Error("Could not load the display-list painter.", { cause })
|
|
13
|
+
}).then((result) => {
|
|
14
|
+
if (result.isErr()) pending = void 0;
|
|
15
|
+
return result;
|
|
16
|
+
});
|
|
17
|
+
return pending;
|
|
18
|
+
};
|
|
19
|
+
/** Notify an editor once per in-flight load, regardless of how many layouts requested it. */
|
|
20
|
+
const createDisplayListPainterLoader = ({ onReady, onError }) => {
|
|
21
|
+
let waiting = false;
|
|
22
|
+
return () => {
|
|
23
|
+
if (painter) return painter;
|
|
24
|
+
if (!waiting) {
|
|
25
|
+
waiting = true;
|
|
26
|
+
loadPainter().then((result) => {
|
|
27
|
+
waiting = false;
|
|
28
|
+
if (result.isOk()) onReady();
|
|
29
|
+
else onError(result.error);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export { createDisplayListPainterLoader };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { findPageNumberAtEditorPosition } from "../layout-engine/pmPageIndex.js";
|
|
2
|
-
import {
|
|
2
|
+
import { CANONICAL_CONDITION } from "../types/canonicalCapabilities.js";
|
|
3
3
|
import { FOLIO_DOCX_SERIALIZATION_MODE } from "../types/docxSerialization.js";
|
|
4
4
|
import { NO_ANONYMIZATION_HIGHLIGHTS } from "./anonymizationHighlights.js";
|
|
5
5
|
import { NO_AUTOCOMPLETE, delegateAutocomplete } from "./hiddenEditorApi.js";
|
|
@@ -24,7 +24,7 @@ const createFolioEditor = (deps) => {
|
|
|
24
24
|
const api = deps.getEditorApi();
|
|
25
25
|
if (!api) return {
|
|
26
26
|
status: "refused",
|
|
27
|
-
|
|
27
|
+
ground: { condition: CANONICAL_CONDITION.notReady },
|
|
28
28
|
message: "The editor is not ready for section changes."
|
|
29
29
|
};
|
|
30
30
|
return api.applyCanonicalSectionProperties(patch);
|
|
@@ -33,6 +33,8 @@ const createFolioEditor = (deps) => {
|
|
|
33
33
|
getCanonicalStorySelection: (story) => deps.getEditorApi()?.getCanonicalStorySelection(story) ?? null,
|
|
34
34
|
getCanonicalStoryProjection: (story) => deps.getEditorApi()?.getCanonicalStoryProjection(story) ?? null,
|
|
35
35
|
replaceCanonicalStoryText: (options) => deps.getEditorApi()?.replaceCanonicalStoryText(options) ?? false,
|
|
36
|
+
applyCanonicalStoryStructure: (options) => deps.getEditorApi()?.applyCanonicalStoryStructure(options) ?? false,
|
|
37
|
+
cutCanonicalStory: (options) => deps.getEditorApi()?.cutCanonicalStory(options) ?? false,
|
|
36
38
|
noteCanonicalStoryView: (options) => {
|
|
37
39
|
deps.getEditorApi()?.noteCanonicalStoryView(options);
|
|
38
40
|
},
|