@stll/folio-core 0.72.0 → 0.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -6
- package/dist/ai-edits/apply.d.ts +6 -114
- package/dist/ai-edits/apply.js +9 -131
- package/dist/ai-edits/applyTypes.d.ts +85 -0
- package/dist/ai-edits/applyTypes.js +24 -0
- package/dist/ai-edits/clean-text.d.ts +7 -1
- package/dist/ai-edits/clean-text.js +23 -2
- package/dist/ai-edits/finalSectionReview.d.ts +1 -1
- package/dist/ai-edits/headless.d.ts +29 -147
- package/dist/ai-edits/headless.js +213 -1634
- package/dist/ai-edits/index.d.ts +3 -3
- package/dist/ai-edits/index.js +2 -3
- package/dist/ai-edits/pending-suggestions.d.ts +14 -4
- package/dist/ai-edits/pending-suggestions.js +183 -90
- package/dist/ai-edits/result-validation.js +1 -1
- package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
- package/dist/ai-edits/snapshot.js +8 -3
- package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
- package/dist/ai-edits/table-cell-mutations.js +1 -1
- package/dist/ai-edits/table-geometry.d.ts +1 -1
- package/dist/ai-edits/table-geometry.js +1 -1
- package/dist/ai-edits/table-row-column-mutations.d.ts +1 -1
- package/dist/ai-edits/table-row-column-mutations.js +1 -1
- package/dist/ai-edits/tableNodes.d.ts +38 -0
- package/dist/ai-edits/tableNodes.js +86 -0
- package/dist/ai-edits/tracked-batch-fidelity.d.ts +1 -1
- package/dist/ai-edits/undefinedReferences.d.ts +7 -0
- package/dist/canonical/batchCommentReferences.js +1 -0
- package/dist/canonical/canonicalInlineProjection.js +1 -1
- package/dist/canonical/canonicalPublicOperations.js +228 -64
- package/dist/canonical/canonicalSession.d.ts +9 -1
- package/dist/canonical/canonicalSession.js +95 -15
- package/dist/compare/compare.d.ts +1 -1
- package/dist/compare/inline-atoms-model.d.ts +1 -1
- package/dist/compare/inline-atoms.d.ts +2 -2
- package/dist/compare/inline-provenance-model.d.ts +1 -1
- package/dist/compare/inline-provenance.d.ts +2 -2
- package/dist/compat/eigenpal.d.ts +3 -3
- package/dist/compat/eigenpal.js +2 -3
- package/dist/controller/canonicalClipboard.d.ts +13 -3
- package/dist/controller/canonicalClipboard.js +185 -49
- package/dist/controller/canonicalClipboardResources.d.ts +9 -1
- package/dist/controller/canonicalClipboardResources.js +22 -2
- package/dist/controller/canonicalReview.d.ts +1 -1
- package/dist/controller/canonicalReview.js +1 -1
- package/dist/controller/canonicalStructure.js +1 -1
- package/dist/controller/canonicalWatermark.d.ts +10 -0
- package/dist/controller/canonicalWatermark.js +37 -0
- package/dist/controller/hiddenEditorApi.d.ts +1 -1
- package/dist/controller/hiddenEditorManager.d.ts +4 -3
- package/dist/controller/hiddenEditorManager.js +75 -15
- package/dist/document-operations-apply.d.ts +15 -0
- package/dist/document-operations-apply.js +280 -0
- package/dist/document-operations.d.ts +1 -14
- package/dist/document-operations.js +2 -279
- package/dist/docx/modelValidation.js +1 -1
- package/dist/docx/paragraphParser.js +2 -2
- package/dist/docx/paragraphPropertySource.d.ts +1 -1
- package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
- package/dist/docx/reviewResolutionProvenance.js +32 -9
- package/dist/docx/revisionIdNormalization.js +30 -7
- package/dist/docx/rezip.js +1 -1
- package/dist/docx/serializer/borderSerializer.js +1 -1
- package/dist/docx/serializer/commentSerializer.js +1 -1
- package/dist/docx/serializer/documentSerializer.js +1 -1
- package/dist/docx/serializer/paragraphSerializer.js +3 -3
- package/dist/docx/serializer/runSerializer.js +1 -1
- package/dist/docx/serializer/sectionPropertiesSerializer.js +1 -1
- package/dist/docx/serializer/tableSerializer.js +5 -37
- package/dist/docx/serializer/textFormattingSerializer.js +1 -1
- package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
- package/dist/docx/server/templatePlan/apply.d.ts +15 -0
- package/dist/docx/server/templatePlan/apply.js +600 -0
- package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
- package/dist/docx/server/templatePlan/blocks.js +355 -0
- package/dist/docx/server/templatePlan/builders.d.ts +72 -0
- package/dist/docx/server/templatePlan/builders.js +237 -0
- package/dist/docx/server/templatePlan/emit.d.ts +118 -0
- package/dist/docx/server/templatePlan/emit.js +466 -0
- package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
- package/dist/docx/server/templatePlan/emphasis.js +173 -0
- package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
- package/dist/docx/server/templatePlan/inspect.js +177 -0
- package/dist/docx/server/templatePlan/labels.d.ts +36 -0
- package/dist/docx/server/templatePlan/labels.js +126 -0
- package/dist/docx/server/templatePlan/package.d.ts +34 -0
- package/dist/docx/server/templatePlan/package.js +99 -0
- package/dist/docx/server/templatePlan/plan.d.ts +143 -0
- package/dist/docx/server/templatePlan/plan.js +841 -0
- package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
- package/dist/docx/server/templatePlan/planShape.js +161 -0
- package/dist/docx/server/templatePlan/resources.d.ts +41 -0
- package/dist/docx/server/templatePlan/resources.js +136 -0
- package/dist/docx/server/templatePlan/story.d.ts +128 -0
- package/dist/docx/server/templatePlan/story.js +440 -0
- package/dist/docx/server/templatePlan/types.d.ts +406 -0
- package/dist/docx/server/templatePlan/types.js +28 -0
- package/dist/docx/server/templatePlan/verify.d.ts +40 -0
- package/dist/docx/server/templatePlan/verify.js +968 -0
- package/dist/docx/server/templatePlan/xml.d.ts +69 -0
- package/dist/docx/server/templatePlan/xml.js +119 -0
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
- package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
- package/dist/docx/storyBlockReplay.js +1 -1
- package/dist/docx/structuralXmlPatch.js +9 -1
- package/dist/docx/tableGridXml.d.ts +30 -0
- package/dist/docx/tableGridXml.js +54 -0
- package/dist/docx/tableParser.js +7 -0
- package/dist/docx/xmlParser.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -3
- package/dist/internal/paragraphFormattingSerialization.js +1 -1
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/managers/ContextMenuManager.js +2 -1
- package/dist/managers/editorShortcuts.d.ts +1 -1
- package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
- package/dist/prosemirror/canonicalCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +2 -2
- package/dist/prosemirror/commands/comments.js +3 -3
- package/dist/prosemirror/commands/contentControls.d.ts +1 -1
- package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
- package/dist/prosemirror/commands/sectionBreak.js +1 -1
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
- package/dist/prosemirror/commentRecords.d.ts +1 -1
- package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
- package/dist/prosemirror/conversion/fromProseDoc.js +1 -1
- package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
- package/dist/prosemirror/documentStructureCounts.js +76 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
- package/dist/prosemirror/extensions/StarterKit.d.ts +1 -1
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +1 -7
- package/dist/prosemirror/extensions/core/HistoryExtension.js +5 -13
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
- package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
- package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +2 -35
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +4 -142
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +3 -87
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +7 -162
- package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +2 -2
- package/dist/prosemirror/extensions/types.d.ts +1 -1
- package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
- package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
- package/dist/prosemirror/index.d.ts +1 -1
- package/dist/prosemirror/index.js +1 -1
- package/dist/prosemirror/insertionGaps.d.ts +1 -1
- package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
- package/dist/prosemirror/listNumbering.d.ts +1 -1
- package/dist/prosemirror/lockedControls.d.ts +1 -1
- package/dist/prosemirror/markupViewProjection.d.ts +1 -1
- package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
- package/dist/prosemirror/noteReferenceReview.js +1 -1
- package/dist/prosemirror/paraIds.d.ts +46 -0
- package/dist/prosemirror/paraIds.js +152 -0
- package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
- package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
- package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
- package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
- package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
- package/dist/prosemirror/pastedCommentCopies.js +1 -1
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
- package/dist/prosemirror/plugins/suggestionMode.d.ts +1 -1
- package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
- package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
- package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.js +16 -1
- package/dist/prosemirror/revisionCarriers.d.ts +1 -1
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
- package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
- package/dist/prosemirror/selectionBounds.d.ts +10 -0
- package/dist/prosemirror/selectionBounds.js +22 -0
- package/dist/prosemirror/storyListNumbering.d.ts +1 -1
- package/dist/prosemirror/tableCellPaste.d.ts +1 -1
- package/dist/prosemirror/tableGridMutation.d.ts +1 -1
- package/dist/prosemirror/textInput.d.ts +1 -1
- package/dist/server.d.ts +7 -2
- package/dist/server.js +6 -1
- package/dist/types/canonicalCapabilities.d.ts +8 -41
- package/dist/types/canonicalCapabilities.js +6 -34
- package/package.json +4 -4
|
@@ -13,10 +13,10 @@ import { readModel } from "../types/documentModel.js";
|
|
|
13
13
|
import { bytesToDataUrl } from "../utils/base64.js";
|
|
14
14
|
import { base64ToBytes } from "../utils/textEncoding.js";
|
|
15
15
|
import { flattenClipboardStyleReferences, importClipboardStyles } from "./canonicalClipboardResources.js";
|
|
16
|
-
import { Result } from "better-result";
|
|
17
|
-
import { NUMBER_FORMATS, paragraphNumberingReference, relationshipIdOf } from "@stll/docx-core/model";
|
|
16
|
+
import { Result, panic } from "better-result";
|
|
18
17
|
import { Fragment, Slice } from "prosemirror-model";
|
|
19
18
|
import { CellSelection } from "prosemirror-tables";
|
|
19
|
+
import { NUMBER_FORMATS, paragraphNumberingReference, relationshipIdOf } from "@stll/docx-core/model";
|
|
20
20
|
import { packageResourcesOpOf } from "@stll/docx-core/ops";
|
|
21
21
|
// src/controller/canonicalClipboard.ts
|
|
22
22
|
const refuse = (message) => Result.err(new CanonicalSessionError({
|
|
@@ -42,6 +42,61 @@ const unplacedBlockGround = (slice) => {
|
|
|
42
42
|
});
|
|
43
43
|
return { gap: table ? CANONICAL_GAP.trackedTableStructure : CANONICAL_GAP.storyContentProjection };
|
|
44
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* A pasted block's paragraphs in document order, a table's cell paragraphs
|
|
47
|
+
* among them, each with the place it fills; undefined when a cell holds a
|
|
48
|
+
* block other than a paragraph or a table.
|
|
49
|
+
*/
|
|
50
|
+
const clipboardParagraphs = (block, replace = () => {}) => {
|
|
51
|
+
if (block.type === "paragraph") return [{
|
|
52
|
+
paragraph: block,
|
|
53
|
+
replace
|
|
54
|
+
}];
|
|
55
|
+
const places = [];
|
|
56
|
+
for (const row of block.rows) for (const cell of row.cells) for (const [index, inner] of cell.content.entries()) {
|
|
57
|
+
if (inner.type !== "paragraph" && inner.type !== "table") return void 0;
|
|
58
|
+
const found = clipboardParagraphs(inner, (next) => {
|
|
59
|
+
cell.content[index] = next;
|
|
60
|
+
});
|
|
61
|
+
if (found === void 0) return void 0;
|
|
62
|
+
places.push(...found);
|
|
63
|
+
}
|
|
64
|
+
return places;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* A table's verbatim captures describe the markup it was read from; a pasted
|
|
68
|
+
* copy is new content the serializer writes from its model.
|
|
69
|
+
*/
|
|
70
|
+
/** Every table among the blocks, those nested in cells included. */
|
|
71
|
+
const clipboardTables = (blocks) => blocks.flatMap((block) => block.type === "table" ? [block, ...clipboardTables(block.rows.flatMap((row) => row.cells.flatMap((cell) => cell.content.filter((inner) => inner.type === "paragraph" || inner.type === "table"))))] : []);
|
|
72
|
+
const withoutTableCaptures = (table) => {
|
|
73
|
+
if (table.formatting !== void 0) {
|
|
74
|
+
delete table.formatting.sourceXml;
|
|
75
|
+
delete table.formatting.gridSourceXml;
|
|
76
|
+
}
|
|
77
|
+
for (const row of table.rows) {
|
|
78
|
+
if (row.formatting !== void 0) delete row.formatting.sourceXml;
|
|
79
|
+
for (const cell of row.cells) {
|
|
80
|
+
if (cell.formatting !== void 0) delete cell.formatting.sourceXml;
|
|
81
|
+
for (const inner of cell.content) if (inner.type === "table") withoutTableCaptures(inner);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
/** A pasted block's own copy, each paragraph keeping its indentation provenance. */
|
|
86
|
+
const cloneClipboardBlock = (block) => {
|
|
87
|
+
const clone = structuredClone(block);
|
|
88
|
+
if (clone.type === "table") withoutTableCaptures(clone);
|
|
89
|
+
const sources = clipboardParagraphs(block) ?? [];
|
|
90
|
+
const targets = clipboardParagraphs(clone) ?? [];
|
|
91
|
+
for (const [index, { paragraph: target }] of targets.entries()) {
|
|
92
|
+
const source = sources[index]?.paragraph;
|
|
93
|
+
if (source !== void 0) copyParagraphIndentationProjection({
|
|
94
|
+
target,
|
|
95
|
+
source
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return clone;
|
|
99
|
+
};
|
|
45
100
|
const IMAGE_RELATIONSHIP = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
|
|
46
101
|
const HYPERLINK_RELATIONSHIP = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
|
|
47
102
|
const MAX_CLIPBOARD_IMAGE_BYTES = 16777216;
|
|
@@ -196,21 +251,36 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
|
|
|
196
251
|
numIds: nums
|
|
197
252
|
});
|
|
198
253
|
};
|
|
199
|
-
/**
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
254
|
+
/**
|
|
255
|
+
* The notes and comments the clipboard's references and markers name, read
|
|
256
|
+
* from the document they were copied from; the paste copies each under a
|
|
257
|
+
* fresh id. Without that document the ids could name the destination's own
|
|
258
|
+
* notes and comments, so the paste refuses.
|
|
259
|
+
*/
|
|
260
|
+
const clipboardAnnotations = ({ paragraphs, source }) => {
|
|
261
|
+
const comments = /* @__PURE__ */ new Set();
|
|
262
|
+
const notes = /* @__PURE__ */ new Set();
|
|
263
|
+
for (const paragraph of paragraphs) {
|
|
264
|
+
visitInlineContentSlots(paragraph, ({ item }) => {
|
|
265
|
+
if (item.type === "commentRangeStart" || item.type === "commentRangeEnd" || item.type === "commentReference") comments.add(item.id);
|
|
266
|
+
});
|
|
267
|
+
visitParagraphRuns(paragraph, (run) => {
|
|
268
|
+
for (const item of run.content) if (item.type === "footnoteRef" || item.type === "endnoteRef") notes.add(`${item.type === "footnoteRef" ? "footnote" : "endnote"}:${String(item.id)}`);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
if (comments.size === 0 && notes.size === 0) return Result.ok(void 0);
|
|
272
|
+
const refusal = (message) => Result.err(new CanonicalSessionError({
|
|
210
273
|
ground: { gap: CANONICAL_GAP.storyContentProjection },
|
|
211
274
|
reason: "refused",
|
|
212
|
-
message
|
|
213
|
-
});
|
|
275
|
+
message
|
|
276
|
+
}));
|
|
277
|
+
if (source === void 0) return refusal("Clipboard comments and note references require the document they were copied from.");
|
|
278
|
+
const annotations = {
|
|
279
|
+
notes: [...source.package.footnotes ?? [], ...source.package.endnotes ?? []].filter(({ type, id }) => notes.has(`${type}:${String(id)}`)),
|
|
280
|
+
comments: (source.package.document.comments ?? []).filter(({ id }) => comments.has(id))
|
|
281
|
+
};
|
|
282
|
+
if (annotations.notes.length !== notes.size || annotations.comments.length !== comments.size) return refusal("A clipboard comment or note reference names none in the document it was copied from.");
|
|
283
|
+
return Result.ok(annotations);
|
|
214
284
|
};
|
|
215
285
|
const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarget, pasteTarget, sourceDocument, moveSource }) => {
|
|
216
286
|
if (session.isComposing) return refuse("Composition must finish before using the clipboard.");
|
|
@@ -222,13 +292,14 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
|
|
|
222
292
|
if (slice.openStart > 1 || slice.openEnd > 1) return refuseUnder(unplacedBlockGround(slice), "Clipboard tables and nested block containers require canonical table editing.");
|
|
223
293
|
const paragraphType = state.schema.nodes["paragraph"];
|
|
224
294
|
if (paragraphType === void 0) return refuse("Clipboard input requires a paragraph schema.");
|
|
295
|
+
const tableType = state.schema.nodes["table"];
|
|
225
296
|
let inline = true;
|
|
226
|
-
let
|
|
297
|
+
let blocksOnly = true;
|
|
227
298
|
slice.content.forEach((node) => {
|
|
228
299
|
inline &&= node.isInline;
|
|
229
|
-
|
|
300
|
+
blocksOnly &&= node.type === paragraphType || node.type === tableType;
|
|
230
301
|
});
|
|
231
|
-
if (!inline && !
|
|
302
|
+
if (!inline && !blocksOnly) return refuseUnder(unplacedBlockGround(slice), "Clipboard tables and embedded blocks require canonical table editing.");
|
|
232
303
|
const importedSlice = inline ? new Slice(Fragment.from(paragraphType.create(null, slice.content)), 1, 1) : slice;
|
|
233
304
|
const converted = Result.try({
|
|
234
305
|
try: () => proseDocToBlocks(state.schema.topNodeType.create(null, importedSlice.content), []),
|
|
@@ -239,17 +310,20 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
|
|
|
239
310
|
})
|
|
240
311
|
});
|
|
241
312
|
if (converted.isErr()) return converted;
|
|
242
|
-
const
|
|
313
|
+
const blocks = [];
|
|
243
314
|
for (const block of converted.value) {
|
|
244
|
-
if (block.type !== "paragraph") return refuseUnder(unplacedBlockGround(slice), "The clipboard contains an unsupported block.");
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
315
|
+
if (block.type !== "paragraph" && block.type !== "table" || clipboardParagraphs(block) === void 0) return refuseUnder(unplacedBlockGround(slice), "The clipboard contains an unsupported block.");
|
|
316
|
+
blocks.push(cloneClipboardBlock(block));
|
|
317
|
+
}
|
|
318
|
+
const places = blocks.flatMap((block, index) => clipboardParagraphs(block, (next) => {
|
|
319
|
+
blocks[index] = next;
|
|
320
|
+
}) ?? []);
|
|
321
|
+
const paragraphs = places.map(({ paragraph }) => paragraph);
|
|
322
|
+
const tables = clipboardTables(blocks);
|
|
323
|
+
if (moveTarget === void 0 && (plain || sourceDocument === void 0)) {
|
|
324
|
+
flattenClipboardStyleReferences(paragraphs);
|
|
325
|
+
for (const table of tables) delete table.formatting?.styleId;
|
|
251
326
|
}
|
|
252
|
-
if (moveTarget === void 0 && (plain || sourceDocument === void 0)) flattenClipboardStyleReferences(paragraphs);
|
|
253
327
|
const overCells = state.selection instanceof CellSelection && pasteTarget === void 0 && moveSource === void 0 && moveTarget === void 0;
|
|
254
328
|
if (state.selection instanceof CellSelection && !overCells) return refuse("Pasting over selected cells requires a per-cell paste operation.");
|
|
255
329
|
const selectionRange = overCells ? {
|
|
@@ -260,6 +334,39 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
|
|
|
260
334
|
if (from.isErr()) return from;
|
|
261
335
|
const to = overCells ? Result.ok(void 0) : session.projection.addressAt(pasteTarget ?? moveSource?.to ?? selectionRange.to);
|
|
262
336
|
if (to.isErr()) return to;
|
|
337
|
+
const named = moveTarget === void 0 ? clipboardAnnotations({
|
|
338
|
+
paragraphs,
|
|
339
|
+
source: sourceDocument
|
|
340
|
+
}) : Result.ok(void 0);
|
|
341
|
+
if (named.isErr()) return named;
|
|
342
|
+
const annotations = named.value === void 0 ? void 0 : {
|
|
343
|
+
notes: structuredClone([...named.value.notes]),
|
|
344
|
+
comments: structuredClone([...named.value.comments])
|
|
345
|
+
};
|
|
346
|
+
const annotationBodies = [];
|
|
347
|
+
for (const note of annotations?.notes ?? []) for (const [index, block] of note.content.entries()) if (block.type === "paragraph") annotationBodies.push({
|
|
348
|
+
paragraph: block,
|
|
349
|
+
replace: (next) => {
|
|
350
|
+
note.content[index] = next;
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
for (const comment of annotations?.comments ?? []) for (const [index, paragraph] of comment.content.entries()) annotationBodies.push({
|
|
354
|
+
paragraph,
|
|
355
|
+
replace: (next) => {
|
|
356
|
+
comment.content[index] = next;
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
const annotationParagraphs = annotationBodies.map(({ paragraph }) => paragraph);
|
|
360
|
+
for (const paragraph of annotationParagraphs) {
|
|
361
|
+
let related = false;
|
|
362
|
+
visitInlineContentSlots(paragraph, ({ item }) => {
|
|
363
|
+
if (item.type === "hyperlink" && item.anchor === void 0) related = true;
|
|
364
|
+
});
|
|
365
|
+
visitParagraphRuns(paragraph, (run) => {
|
|
366
|
+
if (run.content.some((child) => child.type === "drawing")) related = true;
|
|
367
|
+
});
|
|
368
|
+
if (related) return refuse("Copied notes and comments holding images or external links require their part's relationships.");
|
|
369
|
+
}
|
|
263
370
|
const destination = readModel(session.document);
|
|
264
371
|
let styles = destination.package.styles;
|
|
265
372
|
let styleIds;
|
|
@@ -268,19 +375,31 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
|
|
|
268
375
|
const importedStyles = importClipboardStyles({
|
|
269
376
|
destination,
|
|
270
377
|
source: sourceDocument,
|
|
271
|
-
paragraphs
|
|
378
|
+
paragraphs,
|
|
379
|
+
annotationParagraphs,
|
|
380
|
+
tableStyleIds: tables.flatMap(({ formatting }) => formatting?.styleId === void 0 ? [] : [formatting.styleId])
|
|
272
381
|
});
|
|
273
382
|
if (importedStyles.isErr()) return refuse(importedStyles.error.message);
|
|
274
383
|
styles = importedStyles.value.styles;
|
|
275
|
-
|
|
384
|
+
for (const [index, place] of places.entries()) {
|
|
385
|
+
const imported = importedStyles.value.paragraphs[index] ?? panic("An imported clipboard paragraph is missing.");
|
|
386
|
+
place.replace(imported);
|
|
387
|
+
paragraphs[index] = imported;
|
|
388
|
+
}
|
|
389
|
+
for (const [offset, body] of annotationBodies.entries()) {
|
|
390
|
+
const imported = importedStyles.value.annotationParagraphs[offset] ?? panic("An imported copied note or comment paragraph is missing.");
|
|
391
|
+
body.replace(imported);
|
|
392
|
+
annotationParagraphs[offset] = imported;
|
|
393
|
+
}
|
|
276
394
|
styleIds = importedStyles.value.styleIds;
|
|
277
395
|
extraIds = importedStyles.value.numberingIds;
|
|
396
|
+
for (const { formatting } of tables) if (formatting?.styleId !== void 0) formatting.styleId = importedStyles.value.styleIds.get(formatting.styleId) ?? panic("An imported table style has no destination identity.");
|
|
278
397
|
}
|
|
279
398
|
const sourceNumbering = sourceDocument?.package.numbering ?? completeNumberingForDoc(void 0, state.schema.topNodeType.create(null, importedSlice.content));
|
|
280
399
|
const importedNumbering = importNumbering({
|
|
281
400
|
destination: destination.package.numbering,
|
|
282
401
|
source: sourceNumbering,
|
|
283
|
-
paragraphs,
|
|
402
|
+
paragraphs: [...paragraphs, ...annotationParagraphs],
|
|
284
403
|
mode: moveTarget === void 0 ? "copy" : "move",
|
|
285
404
|
sourceKind: sourceDocument === void 0 ? "normalizedSlice" : "package",
|
|
286
405
|
...extraIds === void 0 ? {} : { extraIds },
|
|
@@ -360,8 +479,6 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
|
|
|
360
479
|
};
|
|
361
480
|
for (const paragraph of paragraphs) {
|
|
362
481
|
if (moveTarget === void 0) {
|
|
363
|
-
const storyPartRefusal = canonicalClipboardStoryPartRefusal(paragraph);
|
|
364
|
-
if (storyPartRefusal !== void 0) return Result.err(storyPartRefusal);
|
|
365
482
|
const links = [];
|
|
366
483
|
visitInlineContentSlots(paragraph, ({ item }) => {
|
|
367
484
|
if (item.type === "hyperlink") links.push(item);
|
|
@@ -492,42 +609,61 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
|
|
|
492
609
|
}
|
|
493
610
|
const openStart = importedSlice.openStart === 0 ? 0 : 1;
|
|
494
611
|
const openEnd = importedSlice.openEnd === 0 ? 0 : 1;
|
|
495
|
-
|
|
496
|
-
|
|
612
|
+
const topParagraphs = blocks.filter((block) => block.type === "paragraph");
|
|
613
|
+
const pasted = (range) => {
|
|
614
|
+
if (annotations !== void 0) return {
|
|
615
|
+
type: "pasteBlocks",
|
|
616
|
+
...range,
|
|
617
|
+
blocks,
|
|
618
|
+
openStart,
|
|
619
|
+
openEnd,
|
|
620
|
+
annotations
|
|
621
|
+
};
|
|
622
|
+
if (topParagraphs.length === blocks.length) return {
|
|
623
|
+
type: "replaceFragment",
|
|
624
|
+
...range,
|
|
625
|
+
paragraphs: topParagraphs,
|
|
626
|
+
openStart,
|
|
627
|
+
openEnd
|
|
628
|
+
};
|
|
629
|
+
return {
|
|
630
|
+
type: "pasteBlocks",
|
|
631
|
+
...range,
|
|
632
|
+
blocks,
|
|
633
|
+
openStart,
|
|
634
|
+
openEnd
|
|
635
|
+
};
|
|
636
|
+
};
|
|
637
|
+
if (from.value === void 0 || to.value === void 0) return session.prepareCellSelectionStructure(state, (at) => pasted({
|
|
497
638
|
from: at,
|
|
498
|
-
to: at
|
|
499
|
-
paragraphs,
|
|
500
|
-
openStart,
|
|
501
|
-
openEnd
|
|
639
|
+
to: at
|
|
502
640
|
}), {
|
|
503
641
|
resourceOps,
|
|
504
642
|
semantic: "paste"
|
|
505
643
|
});
|
|
506
|
-
const
|
|
644
|
+
const range = {
|
|
507
645
|
from: from.value,
|
|
508
|
-
to: to.value
|
|
509
|
-
paragraphs,
|
|
510
|
-
openStart,
|
|
511
|
-
openEnd
|
|
646
|
+
to: to.value
|
|
512
647
|
};
|
|
513
648
|
if (moveTarget === void 0) return session.prepareIntents(state, {
|
|
514
|
-
intents: [
|
|
515
|
-
type: "replaceFragment",
|
|
516
|
-
...fragment
|
|
517
|
-
}],
|
|
649
|
+
intents: [pasted(range)],
|
|
518
650
|
resourceOps,
|
|
519
651
|
semantic: "paste"
|
|
520
652
|
});
|
|
653
|
+
if (topParagraphs.length !== blocks.length) return refuseUnder({ gap: CANONICAL_GAP.trackedTableStructure }, "Moving a table by dragging requires a table move operation.");
|
|
521
654
|
const target = session.projection.addressAt(moveTarget);
|
|
522
655
|
if (target.isErr()) return target;
|
|
523
656
|
return session.prepareIntents(state, {
|
|
524
657
|
intents: [{
|
|
525
658
|
type: "moveFragment",
|
|
526
659
|
target: target.value,
|
|
527
|
-
...
|
|
660
|
+
...range,
|
|
661
|
+
paragraphs: topParagraphs,
|
|
662
|
+
openStart,
|
|
663
|
+
openEnd
|
|
528
664
|
}],
|
|
529
665
|
resourceOps,
|
|
530
666
|
semantic: "paste"
|
|
531
667
|
});
|
|
532
668
|
};
|
|
533
|
-
export {
|
|
669
|
+
export { clipboardAnnotations, prepareCanonicalPaste };
|
|
@@ -7,13 +7,21 @@ type ImportClipboardStylesOptions = {
|
|
|
7
7
|
destination: document_d_exports.Document;
|
|
8
8
|
source: document_d_exports.Document;
|
|
9
9
|
paragraphs: readonly document_d_exports.Paragraph[];
|
|
10
|
+
/** Styles pasted tables name, imported with their dependencies. */
|
|
11
|
+
tableStyleIds?: readonly string[];
|
|
12
|
+
/**
|
|
13
|
+
* Bodies of copied notes and comments: a style they name that the source
|
|
14
|
+
* does not define (a built-in reference style, say) is left as it is.
|
|
15
|
+
*/
|
|
16
|
+
annotationParagraphs?: readonly document_d_exports.Paragraph[];
|
|
10
17
|
};
|
|
11
18
|
type ImportedClipboardStyles = {
|
|
12
19
|
styles: document_d_exports.StyleDefinitions | undefined;
|
|
13
20
|
paragraphs: document_d_exports.Paragraph[];
|
|
21
|
+
annotationParagraphs: document_d_exports.Paragraph[];
|
|
14
22
|
styleIds: ReadonlyMap<string, string>;
|
|
15
23
|
numberingIds: ReadonlySet<number>;
|
|
16
24
|
};
|
|
17
25
|
/** Import the transitive style/numbering dependencies of the clipboard, retaining destination defaults. */
|
|
18
|
-
export declare const importClipboardStyles: ({ destination, source, paragraphs }: ImportClipboardStylesOptions) => Result<ImportedClipboardStyles, DocumentOpRefusal>;
|
|
26
|
+
export declare const importClipboardStyles: ({ destination, source, paragraphs, tableStyleIds, annotationParagraphs }: ImportClipboardStylesOptions) => Result<ImportedClipboardStyles, DocumentOpRefusal>;
|
|
19
27
|
export {};
|
|
@@ -267,12 +267,13 @@ const materializeClipboardDefaults = ({ source, destination, paragraphs }) => {
|
|
|
267
267
|
return unavailable === void 0 ? Result.ok(void 0) : refused(unavailable);
|
|
268
268
|
};
|
|
269
269
|
/** Import the transitive style/numbering dependencies of the clipboard, retaining destination defaults. */
|
|
270
|
-
const importClipboardStyles = ({ destination, source, paragraphs }) => {
|
|
270
|
+
const importClipboardStyles = ({ destination, source, paragraphs, tableStyleIds = [], annotationParagraphs = [] }) => {
|
|
271
271
|
const clonedParagraphs = structuredClone([...paragraphs]);
|
|
272
|
+
const clonedAnnotations = structuredClone([...annotationParagraphs]);
|
|
272
273
|
const materialized = materializeClipboardDefaults({
|
|
273
274
|
source,
|
|
274
275
|
destination,
|
|
275
|
-
paragraphs: clonedParagraphs
|
|
276
|
+
paragraphs: [...clonedParagraphs, ...clonedAnnotations]
|
|
276
277
|
});
|
|
277
278
|
if (materialized.isErr()) return materialized;
|
|
278
279
|
const sourceStyles = /* @__PURE__ */ new Map();
|
|
@@ -295,6 +296,12 @@ const importClipboardStyles = ({ destination, source, paragraphs }) => {
|
|
|
295
296
|
}
|
|
296
297
|
};
|
|
297
298
|
for (const paragraph of clonedParagraphs) visitReferences(paragraph, selectReferences);
|
|
299
|
+
for (const styleId of tableStyleIds) selectReferences("styleId", styleId, {});
|
|
300
|
+
const selectDefinedReferences = (key, value, owner) => {
|
|
301
|
+
if (STYLE_REFERENCE_FIELDS.has(key) && typeof value === "string" && !sourceStyles.has(value)) return;
|
|
302
|
+
selectReferences(key, value, owner);
|
|
303
|
+
};
|
|
304
|
+
for (const paragraph of clonedAnnotations) visitReferences(paragraph, selectDefinedReferences);
|
|
298
305
|
const sourceNums = source.package.numbering?.nums ?? [];
|
|
299
306
|
const sourceAbstracts = source.package.numbering?.abstractNums ?? [];
|
|
300
307
|
const nums = new Map(sourceNums.map((num) => [num.numId, num]));
|
|
@@ -372,6 +379,18 @@ const importClipboardStyles = ({ destination, source, paragraphs }) => {
|
|
|
372
379
|
});
|
|
373
380
|
if (lowered.isErr()) return lowered;
|
|
374
381
|
}
|
|
382
|
+
const remapDefined = (key, value, owner) => {
|
|
383
|
+
if (STYLE_REFERENCE_FIELDS.has(key) && typeof value === "string" && !styleIds.has(value)) return;
|
|
384
|
+
remap(key, value, owner);
|
|
385
|
+
};
|
|
386
|
+
for (const paragraph of clonedAnnotations) {
|
|
387
|
+
visitReferences(paragraph, remapDefined);
|
|
388
|
+
const lowered = lowerSourceTheme({
|
|
389
|
+
value: paragraph,
|
|
390
|
+
source
|
|
391
|
+
});
|
|
392
|
+
if (lowered.isErr()) return lowered;
|
|
393
|
+
}
|
|
375
394
|
const prior = destination.package.styles;
|
|
376
395
|
const styles = importedStyles.length === 0 ? prior : {
|
|
377
396
|
...prior,
|
|
@@ -380,6 +399,7 @@ const importClipboardStyles = ({ destination, source, paragraphs }) => {
|
|
|
380
399
|
return Result.ok({
|
|
381
400
|
styles,
|
|
382
401
|
paragraphs: clonedParagraphs,
|
|
402
|
+
annotationParagraphs: clonedAnnotations,
|
|
383
403
|
styleIds,
|
|
384
404
|
numberingIds
|
|
385
405
|
});
|
|
@@ -5,6 +5,6 @@ type ResolveCanonicalReviewRangeOptions = {
|
|
|
5
5
|
to: number;
|
|
6
6
|
resolution: "accept" | "reject";
|
|
7
7
|
};
|
|
8
|
-
/** Null
|
|
8
|
+
/** Null when the editor holds no canonical session, which leaves the review as it is. */
|
|
9
9
|
export declare const resolveCanonicalReviewRange: ({ editor, from, to, resolution }: ResolveCanonicalReviewRangeOptions) => boolean | null;
|
|
10
10
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getTrackedChangeGroupIdsFromDoc, getTrackedChangesFromDoc } from "../ai-edits/read.js";
|
|
2
2
|
import { findAIEditRevisionRange } from "../prosemirror/commands/comments.js";
|
|
3
3
|
// src/controller/canonicalReview.ts
|
|
4
|
-
/** Null
|
|
4
|
+
/** Null when the editor holds no canonical session, which leaves the review as it is. */
|
|
5
5
|
const resolveCanonicalReviewRange = ({ editor, from, to, resolution }) => {
|
|
6
6
|
if (!editor?.getCanonicalDocument()) return null;
|
|
7
7
|
const state = editor.getState();
|
|
@@ -15,8 +15,8 @@ import { collectHeadings } from "../utils/headingCollector.js";
|
|
|
15
15
|
import { itemBefore } from "../utils/listItems.js";
|
|
16
16
|
import { prepareContentControlValue } from "./canonicalContentControlValue.js";
|
|
17
17
|
import { Result, panic } from "better-result";
|
|
18
|
-
import { NO_PARAGRAPH_NUMBERING, headingOutlineLevel, paragraphNumberingReference, resolveParagraphNumbering } from "@stll/docx-core/model";
|
|
19
18
|
import { CellSelection } from "prosemirror-tables";
|
|
19
|
+
import { NO_PARAGRAPH_NUMBERING, headingOutlineLevel, paragraphNumberingReference, resolveParagraphNumbering } from "@stll/docx-core/model";
|
|
20
20
|
import { DOCUMENT_OP_TYPES, OP_STORIES, editorParagraphGroups, editorPositionAtPhysicalPosition, physicalPositionAtEditorOffset } from "@stll/docx-core/ops";
|
|
21
21
|
// src/controller/canonicalStructure.ts
|
|
22
22
|
const DEFAULT_TOC_PAGE_WIDTH_TWIPS = 12240;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
import { DocumentOp } from "@stll/docx-core/ops";
|
|
3
|
+
/**
|
|
4
|
+
* The canonical operation that sets (or clears) the document's watermark: the
|
|
5
|
+
* header parts and section references {@link setDocumentWatermark} changes,
|
|
6
|
+
* stale-checked against `doc`, so the edit journals and undoes like any other.
|
|
7
|
+
* A header it creates holds one empty paragraph with a fresh id, as every
|
|
8
|
+
* canonical story does.
|
|
9
|
+
*/
|
|
10
|
+
export declare const watermarkOperations: (doc: document_d_exports.Document, watermark: document_d_exports.Watermark | undefined) => DocumentOp[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { withCanonicalParagraphIds } from "../canonical/canonicalOperations.js";
|
|
2
|
+
import { setDocumentWatermark } from "../watermark/index.js";
|
|
3
|
+
import { storyPartsOpOf } from "@stll/docx-core/ops";
|
|
4
|
+
// src/controller/canonicalWatermark.ts
|
|
5
|
+
/**
|
|
6
|
+
* The canonical operation that sets (or clears) the document's watermark: the
|
|
7
|
+
* header parts and section references {@link setDocumentWatermark} changes,
|
|
8
|
+
* stale-checked against `doc`, so the edit journals and undoes like any other.
|
|
9
|
+
* A header it creates holds one empty paragraph with a fresh id, as every
|
|
10
|
+
* canonical story does.
|
|
11
|
+
*/
|
|
12
|
+
const watermarkOperations = (doc, watermark) => {
|
|
13
|
+
const marked = setDocumentWatermark(doc, watermark);
|
|
14
|
+
const headers = new Map(marked.package.headers);
|
|
15
|
+
const after = {
|
|
16
|
+
...marked,
|
|
17
|
+
package: {
|
|
18
|
+
...marked.package,
|
|
19
|
+
headers
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
for (const [rId, header] of headers) {
|
|
23
|
+
if (header.content.length > 0) continue;
|
|
24
|
+
headers.set(rId, {
|
|
25
|
+
...header,
|
|
26
|
+
content: withCanonicalParagraphIds([{
|
|
27
|
+
type: "paragraph",
|
|
28
|
+
content: []
|
|
29
|
+
}], after)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return [storyPartsOpOf({
|
|
33
|
+
before: doc,
|
|
34
|
+
after
|
|
35
|
+
})];
|
|
36
|
+
};
|
|
37
|
+
export { watermarkOperations };
|
|
@@ -20,8 +20,8 @@ import { FolioDocxSerializationPath } from "../types/docxSerialization.js";
|
|
|
20
20
|
import { FolioFieldInsertion } from "../types/fields.js";
|
|
21
21
|
import { AnonymizationHighlightsView } from "./anonymizationHighlights.js";
|
|
22
22
|
import { createCanonicalInputBoundary } from "./canonicalInput.js";
|
|
23
|
-
import { Node } from "prosemirror-model";
|
|
24
23
|
import { Command, EditorState, Transaction } from "prosemirror-state";
|
|
24
|
+
import { Node } from "prosemirror-model";
|
|
25
25
|
import { DocumentOp, FormattingPatch, OpStory, TextPosition } from "@stll/docx-core/ops";
|
|
26
26
|
import { EditorView } from "prosemirror-view";
|
|
27
27
|
/** The inline suggestion, and what painting it needs. */
|
|
@@ -2,7 +2,7 @@ import { CanonicalHistoryDrop, CanonicalHistoryEffect } from "../canonical/canon
|
|
|
2
2
|
import { HiddenEditorStateReason } from "../layout-engine/layoutInstrumentation.js";
|
|
3
3
|
import { EditorMode } from "../managers/EditorModeManager.js";
|
|
4
4
|
import { ExtensionManager } from "../prosemirror/extensions/ExtensionManager.js";
|
|
5
|
-
import { HistoryShortcutOwner } from "../prosemirror/extensions/core/
|
|
5
|
+
import { HistoryShortcutOwner } from "../prosemirror/extensions/core/historyCommands.js";
|
|
6
6
|
import { FolioAnonymizationTerm } from "../types/anonymization.js";
|
|
7
7
|
import { CanonicalRefusalGround } from "../types/canonicalCapabilities.js";
|
|
8
8
|
import { document_d_exports } from "../types/document.js";
|
|
@@ -25,8 +25,9 @@ export type HiddenProseMirrorRemoteSelection = RemoteSelection;
|
|
|
25
25
|
/**
|
|
26
26
|
* Create ProseMirror state from document
|
|
27
27
|
*
|
|
28
|
-
* When an ExtensionManager is provided, it supplies the schema
|
|
29
|
-
*
|
|
28
|
+
* When an ExtensionManager is provided, it supplies the schema. The state
|
|
29
|
+
* paints the document before the canonical session's state replaces it, so it
|
|
30
|
+
* carries none of the extensions' editing plugins.
|
|
30
31
|
*/
|
|
31
32
|
export type CreateHiddenEditorStateOptions = {
|
|
32
33
|
/** The model; the editor state is built from it through `readModel`. */
|