@stll/folio-core 0.76.0 → 0.77.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/headless.d.ts +6 -4
- package/dist/ai-edits/headless.js +32 -15
- package/dist/ai-edits/pending-suggestions.d.ts +9 -0
- package/dist/ai-edits/pending-suggestions.js +11 -0
- package/dist/ai-edits/read.js +24 -1
- package/dist/ai-edits/table-geometry.js +12 -4
- package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
- package/dist/canonical/canonicalInlineProjection.js +2 -2
- package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
- package/dist/canonical/canonicalPublicOperations.js +13 -38
- package/dist/canonical/canonicalSeedContent.d.ts +18 -3
- package/dist/canonical/canonicalSeedContent.js +28 -15
- package/dist/canonical/canonicalSession.d.ts +22 -12
- package/dist/canonical/canonicalSession.js +178 -186
- package/dist/controller/canonicalClipboard.d.ts +2 -1
- package/dist/controller/canonicalClipboard.js +312 -47
- package/dist/controller/canonicalComposition.js +67 -14
- package/dist/controller/canonicalStoryEditor.js +2 -0
- package/dist/controller/hiddenEditorManager.js +2 -0
- package/dist/docx/importedIdCollisions.js +29 -4
- package/dist/docx/server/templatePlan/apply.js +47 -2
- package/dist/docx/server/templatePlan/blocks.d.ts +27 -7
- package/dist/docx/server/templatePlan/blocks.js +103 -12
- package/dist/docx/server/templatePlan/builders.d.ts +6 -0
- package/dist/docx/server/templatePlan/builders.js +7 -1
- package/dist/docx/server/templatePlan/emit.d.ts +2 -0
- package/dist/docx/server/templatePlan/emit.js +108 -6
- package/dist/docx/server/templatePlan/plan.d.ts +24 -1
- package/dist/docx/server/templatePlan/plan.js +165 -12
- package/dist/docx/server/templatePlan/planShape.js +13 -2
- package/dist/docx/server/templatePlan/revisions.d.ts +55 -0
- package/dist/docx/server/templatePlan/revisions.js +276 -2
- package/dist/docx/server/templatePlan/story.d.ts +46 -1
- package/dist/docx/server/templatePlan/story.js +125 -11
- package/dist/docx/server/templatePlan/types.d.ts +97 -1
- package/dist/docx/server/templatePlan/verify.js +63 -9
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
- package/dist/docx/tableGridXml.d.ts +3 -7
- package/dist/docx/tableGridXml.js +5 -13
- package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
- package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
- package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
- package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +1 -3
- package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
- package/dist/prosemirror/conversion/markupViewSource.js +11 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +3 -0
- package/dist/prosemirror/conversion/toProseDoc.js +31 -14
- package/dist/prosemirror/independentMarkupProjection.d.ts +27 -0
- package/dist/prosemirror/independentMarkupProjection.js +147 -0
- package/dist/prosemirror/markupViewNotes.d.ts +1 -1
- package/dist/prosemirror/markupViewNotes.js +24 -27
- package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
- package/dist/prosemirror/markupViewPositionMap.js +316 -0
- package/dist/prosemirror/markupViewProjection.d.ts +3 -46
- package/dist/prosemirror/markupViewProjection.js +90 -17
- package/dist/prosemirror/replacedAnnotations.d.ts +4 -78
- package/dist/prosemirror/replacedAnnotations.js +11 -194
- package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
- package/dist/prosemirror/styles/styleResolver.js +4 -1
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +3 -10
- package/dist/types/canonicalCapabilities.js +3 -10
- package/package.json +2 -2
- package/dist/internal/revisionResolutionEdits.d.ts +0 -11
- package/dist/internal/revisionResolutionEdits.js +0 -18
- package/dist/internal/revisionResolutionInline.d.ts +0 -24
- package/dist/internal/revisionResolutionInline.js +0 -302
- package/dist/internal/revisionResolutionStep.d.ts +0 -3
- package/dist/internal/revisionResolutionStep.js +0 -113
- package/dist/internal/revisionResolutionTracking.d.ts +0 -9
- package/dist/internal/revisionResolutionTracking.js +0 -124
- package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
- package/dist/internal/wholeStoryRevisionResolution.js +0 -783
- package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
- package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -8
- package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -56
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
- package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
- package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
- package/dist/prosemirror/rejoinRunCarriers.js +0 -65
- package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
- package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { groundForDocumentOpRefusal } from "../canonical/canonicalRefusalGrounds.js";
|
|
2
2
|
import { CanonicalSessionError } from "../canonical/canonicalSession.js";
|
|
3
|
+
import { takeDrawingId, usedDrawingIds, withDrawingId } from "../docx/drawingIdNormalization.js";
|
|
3
4
|
import { createNumberingIdAllocator, numberingNumIdsTaken } from "../docx/numberingIds.js";
|
|
4
5
|
import { copyParagraphIndentationProjection } from "../docx/paragraphPropertySource.js";
|
|
5
6
|
import { visitInlineContentSlots, visitParagraphRuns } from "../docx/paragraphTraversal.js";
|
|
@@ -30,11 +31,10 @@ const refuse = (message, ground) => Result.err(new CanonicalSessionError({
|
|
|
30
31
|
/** Clipboard content the paste cannot read or resolve as given. */
|
|
31
32
|
const INVALID_CLIPBOARD = { condition: CANONICAL_CONDITION.invalidRequest };
|
|
32
33
|
/**
|
|
33
|
-
* The
|
|
34
|
-
*
|
|
35
|
-
* content the session cannot project.
|
|
34
|
+
* The ground of a clipboard block the paste cannot place: every block kind
|
|
35
|
+
* the editor shows pastes, so one it cannot place is a slice it cannot read.
|
|
36
36
|
*/
|
|
37
|
-
const UNPLACED_BLOCK =
|
|
37
|
+
const UNPLACED_BLOCK = INVALID_CLIPBOARD;
|
|
38
38
|
const tableRole = (node) => node?.type.spec["tableRole"];
|
|
39
39
|
/**
|
|
40
40
|
* A table the clipboard holds part of, opened `left` levels deep at its start
|
|
@@ -87,19 +87,126 @@ const withClosedTableEdges = (slice) => {
|
|
|
87
87
|
return new Slice(Fragment.from(blocks), opensTable ? 1 : slice.openStart, closesTable ? 1 : slice.openEnd);
|
|
88
88
|
};
|
|
89
89
|
/**
|
|
90
|
+
* The slice with each container it is open through at an edge given up for
|
|
91
|
+
* the content copied from it: a copy that starts or ends inside a block
|
|
92
|
+
* content control, custom XML element, text box or inline content control
|
|
93
|
+
* holds part of it, which pastes as that content, as a copy from inside a
|
|
94
|
+
* paragraph pastes as its text. A block wrapper open at an edge is given up
|
|
95
|
+
* however deep the slice opens through it, its first or last paragraph then
|
|
96
|
+
* pasting whole; a paragraph open only at depth one keeps its inline content.
|
|
97
|
+
*/
|
|
98
|
+
const withOpenContainersUnwrapped = (slice) => {
|
|
99
|
+
/**
|
|
100
|
+
* One edge unwrapped. A node the edge gives up that is also the other
|
|
101
|
+
* edge's, the only child where both edges run through it, takes a depth
|
|
102
|
+
* from the other edge too.
|
|
103
|
+
*/
|
|
104
|
+
const unwrapEdge = (fragment, open, other, edge) => {
|
|
105
|
+
let current = fragment;
|
|
106
|
+
let depth = open;
|
|
107
|
+
let otherDepth = other;
|
|
108
|
+
let shared = true;
|
|
109
|
+
while (depth > 0) {
|
|
110
|
+
const node = edge === "start" ? current.firstChild : current.lastChild;
|
|
111
|
+
if (node === null || node.type.name === "table") break;
|
|
112
|
+
const children = [];
|
|
113
|
+
current.forEach((child) => children.push(child));
|
|
114
|
+
if (node.type.name !== "paragraph") {
|
|
115
|
+
if (node.isTextblock || node.isLeaf || node.childCount === 0) break;
|
|
116
|
+
if (depth === 1 && node.isInline) break;
|
|
117
|
+
const inner = [];
|
|
118
|
+
node.forEach((child) => inner.push(child));
|
|
119
|
+
current = Fragment.from(edge === "start" ? [...inner, ...children.slice(1)] : [...children.slice(0, -1), ...inner]);
|
|
120
|
+
shared &&= children.length === 1 && otherDepth > 0;
|
|
121
|
+
if (shared) otherDepth -= 1;
|
|
122
|
+
depth -= 1;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (depth === 1) break;
|
|
126
|
+
const inline = edge === "start" ? node.content.firstChild : node.content.lastChild;
|
|
127
|
+
if (inline === null || inline.isText || inline.isLeaf) break;
|
|
128
|
+
const siblings = [];
|
|
129
|
+
node.content.forEach((child) => siblings.push(child));
|
|
130
|
+
const lifted = [];
|
|
131
|
+
inline.forEach((child) => lifted.push(child));
|
|
132
|
+
const paragraph = node.copy(Fragment.from(edge === "start" ? [...lifted, ...siblings.slice(1)] : [...siblings.slice(0, -1), ...lifted]));
|
|
133
|
+
current = Fragment.from(edge === "start" ? [paragraph, ...children.slice(1)] : [...children.slice(0, -1), paragraph]);
|
|
134
|
+
shared &&= children.length === 1 && siblings.length === 1 && otherDepth > 1;
|
|
135
|
+
if (shared) otherDepth -= 1;
|
|
136
|
+
depth -= 1;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
fragment: current,
|
|
140
|
+
open: depth,
|
|
141
|
+
other: otherDepth
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
const start = unwrapEdge(slice.content, slice.openStart, slice.openEnd, "start");
|
|
145
|
+
const end = unwrapEdge(start.fragment, start.other, start.open, "end");
|
|
146
|
+
return new Slice(end.fragment, end.other, end.open);
|
|
147
|
+
};
|
|
148
|
+
/** Range markers between blocks hold no text; a paste leaves them behind. */
|
|
149
|
+
const BETWEEN_BLOCK_MARKERS = /* @__PURE__ */ new Set([
|
|
150
|
+
"bookmarkStart",
|
|
151
|
+
"bookmarkEnd",
|
|
152
|
+
"commentRangeStart",
|
|
153
|
+
"commentRangeEnd",
|
|
154
|
+
"moveFromRangeStart",
|
|
155
|
+
"moveFromRangeEnd",
|
|
156
|
+
"moveToRangeStart",
|
|
157
|
+
"moveToRangeEnd"
|
|
158
|
+
]);
|
|
159
|
+
/** A converted clipboard block the paste places, or `undefined` for a marker it leaves. */
|
|
160
|
+
const pastedBlockOf = (block) => {
|
|
161
|
+
switch (block.type) {
|
|
162
|
+
case "paragraph":
|
|
163
|
+
case "table":
|
|
164
|
+
case "blockSdt":
|
|
165
|
+
case "blockCustomXml":
|
|
166
|
+
case "preservedBlock": return block;
|
|
167
|
+
default: return BETWEEN_BLOCK_MARKERS.has(block.type) ? void 0 : panic(`A clipboard block of kind ${block.type} has no placement.`);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
/** `blocks` without the range markers between them, at any depth. */
|
|
171
|
+
const withoutBlockMarkers = (blocks) => {
|
|
172
|
+
for (let index = blocks.length - 1; index >= 0; index -= 1) {
|
|
173
|
+
const block = blocks[index];
|
|
174
|
+
if (block === void 0) continue;
|
|
175
|
+
if (BETWEEN_BLOCK_MARKERS.has(block.type)) {
|
|
176
|
+
blocks.splice(index, 1);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (block.type === "blockSdt" || block.type === "blockCustomXml") withoutBlockMarkers(block.content);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
90
183
|
* A pasted block's paragraphs in document order, a table's cell paragraphs
|
|
91
|
-
* among them, each with the place it fills
|
|
92
|
-
* block other than a paragraph or a table.
|
|
184
|
+
* and a container's among them, each with the place it fills.
|
|
93
185
|
*/
|
|
94
186
|
const clipboardParagraphs = (block, replace = () => {}) => {
|
|
95
187
|
if (block.type === "paragraph") return [{
|
|
96
188
|
paragraph: block,
|
|
97
189
|
replace
|
|
98
190
|
}];
|
|
191
|
+
if (block.type === "preservedBlock") return [];
|
|
192
|
+
if (block.type === "blockSdt" || block.type === "blockCustomXml") {
|
|
193
|
+
const places = [];
|
|
194
|
+
for (const [index, inner] of block.content.entries()) {
|
|
195
|
+
const pasted = pastedBlockOf(inner);
|
|
196
|
+
if (pasted === void 0) continue;
|
|
197
|
+
const found = clipboardParagraphs(pasted, (next) => {
|
|
198
|
+
block.content[index] = next;
|
|
199
|
+
});
|
|
200
|
+
if (found === void 0) return void 0;
|
|
201
|
+
places.push(...found);
|
|
202
|
+
}
|
|
203
|
+
return places;
|
|
204
|
+
}
|
|
99
205
|
const places = [];
|
|
100
206
|
for (const row of block.rows) for (const cell of row.cells) for (const [index, inner] of cell.content.entries()) {
|
|
101
|
-
|
|
102
|
-
|
|
207
|
+
const pasted = pastedBlockOf(inner);
|
|
208
|
+
if (pasted === void 0) continue;
|
|
209
|
+
const found = clipboardParagraphs(pasted, (next) => {
|
|
103
210
|
cell.content[index] = next;
|
|
104
211
|
});
|
|
105
212
|
if (found === void 0) return void 0;
|
|
@@ -111,8 +218,26 @@ const clipboardParagraphs = (block, replace = () => {}) => {
|
|
|
111
218
|
* A table's verbatim captures describe the markup it was read from; a pasted
|
|
112
219
|
* copy is new content the serializer writes from its model.
|
|
113
220
|
*/
|
|
114
|
-
/** Every table among the blocks, those nested in cells included. */
|
|
115
|
-
const clipboardTables = (blocks) => blocks.flatMap((block) =>
|
|
221
|
+
/** Every table among the blocks, those nested in cells and containers included. */
|
|
222
|
+
const clipboardTables = (blocks) => blocks.flatMap((block) => {
|
|
223
|
+
switch (block.type) {
|
|
224
|
+
case "table": return [block, ...clipboardTables(block.rows.flatMap((row) => row.cells.flatMap((cell) => cell.content)))];
|
|
225
|
+
case "blockSdt":
|
|
226
|
+
case "blockCustomXml": return clipboardTables(block.content);
|
|
227
|
+
default: return [];
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
/** Every piece of kept block markup among the blocks, at any depth. */
|
|
231
|
+
const clipboardPreservedBlocks = (blocks) => blocks.flatMap((block) => {
|
|
232
|
+
switch (block.type) {
|
|
233
|
+
case "preservedBlock": return [block.xml];
|
|
234
|
+
case "table": return clipboardPreservedBlocks(block.rows.flatMap((row) => row.cells.flatMap((cell) => cell.content)));
|
|
235
|
+
case "blockSdt":
|
|
236
|
+
case "blockCustomXml": return clipboardPreservedBlocks(block.content);
|
|
237
|
+
default: return [];
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
/** A table's own captures; the tables in its cells are their own. */
|
|
116
241
|
const withoutTableCaptures = (table) => {
|
|
117
242
|
if (table.formatting !== void 0) {
|
|
118
243
|
delete table.formatting.sourceXml;
|
|
@@ -120,16 +245,21 @@ const withoutTableCaptures = (table) => {
|
|
|
120
245
|
}
|
|
121
246
|
for (const row of table.rows) {
|
|
122
247
|
if (row.formatting !== void 0) delete row.formatting.sourceXml;
|
|
123
|
-
for (const cell of row.cells)
|
|
124
|
-
if (cell.formatting !== void 0) delete cell.formatting.sourceXml;
|
|
125
|
-
for (const inner of cell.content) if (inner.type === "table") withoutTableCaptures(inner);
|
|
126
|
-
}
|
|
248
|
+
for (const cell of row.cells) if (cell.formatting !== void 0) delete cell.formatting.sourceXml;
|
|
127
249
|
}
|
|
128
250
|
};
|
|
251
|
+
/**
|
|
252
|
+
* Every table among the blocks freed of its verbatim captures, those nested
|
|
253
|
+
* in cells and containers, a container in a cell among them, included.
|
|
254
|
+
*/
|
|
255
|
+
const withoutContainedTableCaptures = (blocks) => {
|
|
256
|
+
for (const table of clipboardTables(blocks)) withoutTableCaptures(table);
|
|
257
|
+
};
|
|
129
258
|
/** A pasted block's own copy, each paragraph keeping its indentation provenance. */
|
|
130
259
|
const cloneClipboardBlock = (block) => {
|
|
131
260
|
const clone = structuredClone(block);
|
|
132
|
-
|
|
261
|
+
withoutContainedTableCaptures([clone]);
|
|
262
|
+
if (clone.type === "blockSdt" || clone.type === "blockCustomXml") withoutBlockMarkers(clone.content);
|
|
133
263
|
const sources = clipboardParagraphs(block) ?? [];
|
|
134
264
|
const targets = clipboardParagraphs(clone) ?? [];
|
|
135
265
|
for (const [index, { paragraph: target }] of targets.entries()) {
|
|
@@ -296,10 +426,39 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
|
|
|
296
426
|
});
|
|
297
427
|
};
|
|
298
428
|
/**
|
|
429
|
+
* The paragraphs without their comment markers, comment references and note
|
|
430
|
+
* references: their text stays, and nothing names a comment or note.
|
|
431
|
+
*/
|
|
432
|
+
const withoutAnnotationMarkers = (paragraphs) => {
|
|
433
|
+
for (const paragraph of paragraphs) {
|
|
434
|
+
const marked = [];
|
|
435
|
+
visitInlineContentSlots(paragraph, ({ content, index, item }) => {
|
|
436
|
+
if (item.type === "commentRangeStart" || item.type === "commentRangeEnd" || item.type === "commentReference") marked.push({
|
|
437
|
+
content,
|
|
438
|
+
index
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
for (const { content, index } of marked.toReversed()) content.splice(index, 1);
|
|
442
|
+
const emptied = [];
|
|
443
|
+
visitInlineContentSlots(paragraph, ({ content, index, item }) => {
|
|
444
|
+
if (item.type !== "run") return;
|
|
445
|
+
const kept = item.content.filter((child) => child.type !== "footnoteRef" && child.type !== "endnoteRef");
|
|
446
|
+
if (kept.length === item.content.length) return;
|
|
447
|
+
if (kept.length === 0) emptied.push({
|
|
448
|
+
content,
|
|
449
|
+
index
|
|
450
|
+
});
|
|
451
|
+
else item.content = kept;
|
|
452
|
+
});
|
|
453
|
+
for (const { content, index } of emptied.toReversed()) content.splice(index, 1);
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
299
457
|
* The notes and comments the clipboard's references and markers name, read
|
|
300
458
|
* from the document they were copied from; the paste copies each under a
|
|
301
459
|
* fresh id. Without that document the ids could name the destination's own
|
|
302
|
-
* notes and comments
|
|
460
|
+
* notes and comments: the paste keeps the text and leaves the markers and
|
|
461
|
+
* references out, as a copy made outside the editor holds no comment or note.
|
|
303
462
|
*/
|
|
304
463
|
const clipboardAnnotations = ({ paragraphs, source }) => {
|
|
305
464
|
const comments = /* @__PURE__ */ new Set();
|
|
@@ -313,19 +472,71 @@ const clipboardAnnotations = ({ paragraphs, source }) => {
|
|
|
313
472
|
});
|
|
314
473
|
}
|
|
315
474
|
if (comments.size === 0 && notes.size === 0) return Result.ok(void 0);
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}));
|
|
321
|
-
if (source === void 0) return refusal("Clipboard comments and note references require the document they were copied from.");
|
|
475
|
+
if (source === void 0) {
|
|
476
|
+
withoutAnnotationMarkers(paragraphs);
|
|
477
|
+
return Result.ok(void 0);
|
|
478
|
+
}
|
|
322
479
|
const annotations = {
|
|
323
480
|
notes: [...source.package.footnotes ?? [], ...source.package.endnotes ?? []].filter(({ type, id }) => notes.has(`${type}:${String(id)}`)),
|
|
324
481
|
comments: (source.package.document.comments ?? []).filter(({ id }) => comments.has(id))
|
|
325
482
|
};
|
|
326
|
-
if (annotations.notes.length !== notes.size || annotations.comments.length !== comments.size) return
|
|
483
|
+
if (annotations.notes.length !== notes.size || annotations.comments.length !== comments.size) return refuse("A clipboard comment or note reference names none in the document it was copied from.", INVALID_CLIPBOARD);
|
|
327
484
|
return Result.ok(annotations);
|
|
328
485
|
};
|
|
486
|
+
/** The relationship ids markup names, in any office relationship attribute. */
|
|
487
|
+
const relationshipIdsIn = (xml) => {
|
|
488
|
+
const parsed = Result.try({
|
|
489
|
+
try: () => parseXml(`<root>${xml}</root>`, OOXML_NAMESPACE_SCOPE),
|
|
490
|
+
catch: () => new CanonicalSessionError({
|
|
491
|
+
ground: INVALID_CLIPBOARD,
|
|
492
|
+
reason: "refused",
|
|
493
|
+
message: "The clipboard block markup is malformed."
|
|
494
|
+
})
|
|
495
|
+
});
|
|
496
|
+
if (parsed.isErr()) return parsed;
|
|
497
|
+
const ids = [];
|
|
498
|
+
const visit = (element) => {
|
|
499
|
+
for (const name of Object.keys(element.attributes ?? {})) {
|
|
500
|
+
const attribute = findAttributeByNamespaceUri(element, OFFICE_RELATIONSHIP_NAMESPACE_URIS, getLocalName(name));
|
|
501
|
+
if (attribute !== null && attribute.name === name) ids.push(attribute.value);
|
|
502
|
+
}
|
|
503
|
+
for (const child of element.elements ?? []) visit(child);
|
|
504
|
+
};
|
|
505
|
+
visit(parsed.value);
|
|
506
|
+
return Result.ok(ids);
|
|
507
|
+
};
|
|
508
|
+
/** Whether the paragraphs hold an image or an external link. */
|
|
509
|
+
const namesPartRelationships = (paragraphs) => paragraphs.some((paragraph) => {
|
|
510
|
+
let related = false;
|
|
511
|
+
visitInlineContentSlots(paragraph, ({ item }) => {
|
|
512
|
+
if (item.type === "hyperlink" && item.anchor === void 0) related = true;
|
|
513
|
+
});
|
|
514
|
+
visitParagraphRuns(paragraph, (run) => {
|
|
515
|
+
if (run.content.some((child) => child.type === "drawing")) related = true;
|
|
516
|
+
});
|
|
517
|
+
return related;
|
|
518
|
+
});
|
|
519
|
+
/** Whether two relationships name the same target in the same way. */
|
|
520
|
+
const sameRelationship = (left, right) => left !== void 0 && right !== void 0 && left.type === right.type && left.target === right.target && left.targetMode === right.targetMode;
|
|
521
|
+
/**
|
|
522
|
+
* The image relationship ids and the markup a range of the editor's own
|
|
523
|
+
* document holds. A move carries what it drags within the part whose
|
|
524
|
+
* relationships it names, so what this range holds stays that part's own.
|
|
525
|
+
*/
|
|
526
|
+
const rangeHoldings = (doc, { from, to }) => {
|
|
527
|
+
const relationshipIds = /* @__PURE__ */ new Set();
|
|
528
|
+
const markup = /* @__PURE__ */ new Set();
|
|
529
|
+
doc.nodesBetween(from, to, (node) => {
|
|
530
|
+
const rId = node.attrs["rId"];
|
|
531
|
+
if (node.type.name === "image" && typeof rId === "string") relationshipIds.add(rId);
|
|
532
|
+
for (const value of Object.values(node.attrs)) if (typeof value === "string" && value.startsWith("<")) markup.add(value);
|
|
533
|
+
return true;
|
|
534
|
+
});
|
|
535
|
+
return {
|
|
536
|
+
relationshipIds,
|
|
537
|
+
markup
|
|
538
|
+
};
|
|
539
|
+
};
|
|
329
540
|
const prepareCanonicalPaste = ({ session, state, slice: copied, plain = false, moveTarget, pasteTarget, sourceDocument, moveSource }) => {
|
|
330
541
|
if (session.isComposing) return refuse("Composition must finish before using the clipboard.", { condition: CANONICAL_CONDITION.composing });
|
|
331
542
|
if (copied.content.size === 0) return Result.err(new CanonicalSessionError({
|
|
@@ -333,21 +544,22 @@ const prepareCanonicalPaste = ({ session, state, slice: copied, plain = false, m
|
|
|
333
544
|
message: "The clipboard contains no content.",
|
|
334
545
|
reason: "noChange"
|
|
335
546
|
}));
|
|
336
|
-
const
|
|
547
|
+
const closed = withClosedTableEdges(copied);
|
|
548
|
+
if (closed === void 0) return refuse("The clipboard table holds no cells.", INVALID_CLIPBOARD);
|
|
549
|
+
const slice = withClosedTableEdges(withOpenContainersUnwrapped(closed));
|
|
337
550
|
if (slice === void 0) return refuse("The clipboard table holds no cells.", INVALID_CLIPBOARD);
|
|
338
551
|
if (slice.openStart > 1 || slice.openEnd > 1) return refuse("Clipboard tables and nested block containers require canonical table editing.", UNPLACED_BLOCK);
|
|
339
552
|
const paragraphType = state.schema.nodes["paragraph"];
|
|
340
553
|
if (paragraphType === void 0) return refuse("Clipboard input requires a paragraph schema.", { condition: CANONICAL_CONDITION.internal });
|
|
341
|
-
const tableType = state.schema.nodes["table"];
|
|
342
554
|
let inline = true;
|
|
343
555
|
let blocksOnly = true;
|
|
344
556
|
slice.content.forEach((node) => {
|
|
345
557
|
inline &&= node.isInline;
|
|
346
|
-
blocksOnly &&= node.
|
|
558
|
+
blocksOnly &&= node.isBlock;
|
|
347
559
|
});
|
|
348
560
|
if (!inline && !blocksOnly) return refuse("Clipboard tables and embedded blocks require canonical table editing.", UNPLACED_BLOCK);
|
|
349
561
|
const importedSlice = inline ? new Slice(Fragment.from(paragraphType.create(null, slice.content)), 1, 1) : slice;
|
|
350
|
-
const
|
|
562
|
+
const convertedBlocks = Result.try({
|
|
351
563
|
try: () => proseDocToBlocks(state.schema.topNodeType.create(null, importedSlice.content), []),
|
|
352
564
|
catch: (cause) => new CanonicalSessionError({
|
|
353
565
|
ground: INVALID_CLIPBOARD,
|
|
@@ -355,12 +567,20 @@ const prepareCanonicalPaste = ({ session, state, slice: copied, plain = false, m
|
|
|
355
567
|
message: `Clipboard normalization failed: ${cause instanceof Error ? cause.message : String(cause)}`
|
|
356
568
|
})
|
|
357
569
|
});
|
|
358
|
-
if (
|
|
570
|
+
if (convertedBlocks.isErr()) return convertedBlocks;
|
|
359
571
|
const blocks = [];
|
|
360
|
-
for (const
|
|
361
|
-
|
|
362
|
-
|
|
572
|
+
for (const converted of convertedBlocks.value) {
|
|
573
|
+
const block = pastedBlockOf(converted);
|
|
574
|
+
if (block === void 0) continue;
|
|
575
|
+
const clone = cloneClipboardBlock(block);
|
|
576
|
+
if (clipboardParagraphs(clone) === void 0) return refuse("The clipboard contains an unsupported block.", UNPLACED_BLOCK);
|
|
577
|
+
blocks.push(clone);
|
|
363
578
|
}
|
|
579
|
+
if (blocks.length === 0) return Result.err(new CanonicalSessionError({
|
|
580
|
+
ground: INVALID_CLIPBOARD,
|
|
581
|
+
message: "The clipboard contains no content.",
|
|
582
|
+
reason: "noChange"
|
|
583
|
+
}));
|
|
364
584
|
const places = blocks.flatMap((block, index) => clipboardParagraphs(block, (next) => {
|
|
365
585
|
blocks[index] = next;
|
|
366
586
|
}) ?? []);
|
|
@@ -403,16 +623,7 @@ const prepareCanonicalPaste = ({ session, state, slice: copied, plain = false, m
|
|
|
403
623
|
}
|
|
404
624
|
});
|
|
405
625
|
const annotationParagraphs = annotationBodies.map(({ paragraph }) => paragraph);
|
|
406
|
-
for (const
|
|
407
|
-
let related = false;
|
|
408
|
-
visitInlineContentSlots(paragraph, ({ item }) => {
|
|
409
|
-
if (item.type === "hyperlink" && item.anchor === void 0) related = true;
|
|
410
|
-
});
|
|
411
|
-
visitParagraphRuns(paragraph, (run) => {
|
|
412
|
-
if (run.content.some((child) => child.type === "drawing")) related = true;
|
|
413
|
-
});
|
|
414
|
-
if (related) return refuse("Copied notes and comments holding images or external links require their part's relationships.", { gap: CANONICAL_GAP.storyContentProjection });
|
|
415
|
-
}
|
|
626
|
+
for (const comment of annotations?.comments ?? []) if (namesPartRelationships(comment.content)) return refuse("Copied comments holding images or external links require their part's relationships.", { gap: CANONICAL_GAP.storyContentProjection });
|
|
416
627
|
const destination = readModel(session.document);
|
|
417
628
|
let styles = destination.package.styles;
|
|
418
629
|
let styleIds;
|
|
@@ -473,8 +684,9 @@ const prepareCanonicalPaste = ({ session, state, slice: copied, plain = false, m
|
|
|
473
684
|
let importedResource = false;
|
|
474
685
|
let imageIndex = 1;
|
|
475
686
|
let relationshipIndex = 1;
|
|
687
|
+
let sourceRelationships = sourceDocument?.package.relationships;
|
|
476
688
|
const importExternalLink = (href, previousId) => {
|
|
477
|
-
const source = previousId === void 0 ? void 0 :
|
|
689
|
+
const source = previousId === void 0 ? void 0 : sourceRelationships?.get(previousId);
|
|
478
690
|
let target = href;
|
|
479
691
|
if (target === void 0 || target.length === 0) target = source?.targetMode === "External" ? source.target : void 0;
|
|
480
692
|
if (target === void 0 || target.length === 0) return refuse("The clipboard hyperlink has no resolved target.", INVALID_CLIPBOARD);
|
|
@@ -526,7 +738,9 @@ const prepareCanonicalPaste = ({ session, state, slice: copied, plain = false, m
|
|
|
526
738
|
if (imported.isErr()) return imported;
|
|
527
739
|
return Result.ok((parsed.value.elements ?? []).map(captureVerbatimXml).join(""));
|
|
528
740
|
};
|
|
529
|
-
|
|
741
|
+
let drawingIds;
|
|
742
|
+
const moved = moveTarget === void 0 ? void 0 : rangeHoldings(state.doc, moveSource ?? selectionRange);
|
|
743
|
+
const importResources = (paragraph) => {
|
|
530
744
|
if (moveTarget === void 0) {
|
|
531
745
|
const links = [];
|
|
532
746
|
visitInlineContentSlots(paragraph, ({ item }) => {
|
|
@@ -547,9 +761,14 @@ const prepareCanonicalPaste = ({ session, state, slice: copied, plain = false, m
|
|
|
547
761
|
visitParagraphRuns(paragraph, (run) => runs.push(run));
|
|
548
762
|
for (const item of runs) {
|
|
549
763
|
if (plain) item.formatting = marksToTextFormatting(state.storedMarks ?? state.doc.resolve(pasteTarget ?? moveSource?.from ?? selectionRange.from).marks());
|
|
550
|
-
for (const child of item.content) {
|
|
764
|
+
for (const [index, child] of item.content.entries()) {
|
|
551
765
|
if (child.type !== "drawing") continue;
|
|
552
|
-
if (child.rawXmlMode !== void 0)
|
|
766
|
+
if (child.rawXmlMode !== void 0) {
|
|
767
|
+
const kept = keptOpaqueDrawing(child);
|
|
768
|
+
if (kept.isErr()) return kept;
|
|
769
|
+
item.content[index] = kept.value;
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
553
772
|
delete child.rawXml;
|
|
554
773
|
delete child.rawImageFingerprint;
|
|
555
774
|
const image = child.image;
|
|
@@ -580,11 +799,12 @@ const prepareCanonicalPaste = ({ session, state, slice: copied, plain = false, m
|
|
|
580
799
|
if (rebound.isErr()) return rebound;
|
|
581
800
|
image.hlinkHoverXml = rebound.value;
|
|
582
801
|
}
|
|
802
|
+
if (moved !== void 0 && image.rId !== void 0 && moved.relationshipIds.has(image.rId)) continue;
|
|
583
803
|
const relationship = image.rId === void 0 ? void 0 : relationships.get(image.rId);
|
|
584
804
|
const ownedPath = relationship?.target.startsWith("/") ? relationship.target.slice(1) : `word/${relationship?.target ?? ""}`;
|
|
585
|
-
const ownedMedia = relationship === void 0 ? void 0 : media.get(ownedPath);
|
|
805
|
+
const ownedMedia = relationship === void 0 || sourceRelationships === void 0 ? void 0 : media.get(ownedPath);
|
|
586
806
|
if (ownedMedia !== void 0 && (moveTarget !== void 0 || image.src !== void 0 && ownedMedia.dataUrl === image.src)) continue;
|
|
587
|
-
const sourceRelationship = image.rId === void 0 ? void 0 :
|
|
807
|
+
const sourceRelationship = image.rId === void 0 ? void 0 : sourceRelationships?.get(image.rId);
|
|
588
808
|
const sourcePath = sourceRelationship?.target.startsWith("/") ? sourceRelationship.target.slice(1) : `word/${sourceRelationship?.target ?? ""}`;
|
|
589
809
|
const sourceMedia = sourceDocument?.package.media?.get(sourcePath);
|
|
590
810
|
if (sourceMedia !== void 0 && sourceMedia.data.byteLength > MAX_CLIPBOARD_IMAGE_BYTES) return refuse("The clipboard image exceeds the import size limit.", INVALID_CLIPBOARD);
|
|
@@ -636,6 +856,51 @@ const prepareCanonicalPaste = ({ session, state, slice: copied, plain = false, m
|
|
|
636
856
|
importedResource = true;
|
|
637
857
|
}
|
|
638
858
|
}
|
|
859
|
+
return Result.ok(void 0);
|
|
860
|
+
};
|
|
861
|
+
/**
|
|
862
|
+
* An opaque drawing or embedded object, kept as its markup with a fresh
|
|
863
|
+
* drawing id: its parts (a chart, an embedding, a diagram) are carried by
|
|
864
|
+
* the package it was read from, not by the model, so it pastes only into
|
|
865
|
+
* that package, where every relationship it names is the one it named.
|
|
866
|
+
*/
|
|
867
|
+
const keptMarkupPlaced = (xml, message) => {
|
|
868
|
+
const referenced = relationshipIdsIn(xml);
|
|
869
|
+
if (referenced.isErr()) return referenced;
|
|
870
|
+
if (referenced.value.length === 0 || moved?.markup.has(xml) === true) return Result.ok(void 0);
|
|
871
|
+
if (!(sourceDocument !== void 0 && sourceDocument.originalBuffer !== void 0 && sourceDocument.originalBuffer === destination.originalBuffer) || referenced.value.some((id) => !sameRelationship(sourceRelationships?.get(id), relationships.get(id)))) return refuse(message, { gap: CANONICAL_GAP.storyContentProjection });
|
|
872
|
+
return Result.ok(void 0);
|
|
873
|
+
};
|
|
874
|
+
const keptOpaqueDrawing = (drawing) => {
|
|
875
|
+
const placed = keptMarkupPlaced(drawing.rawXml ?? "", "Opaque drawings and embedded objects paste only into the package holding their parts.");
|
|
876
|
+
if (placed.isErr()) return placed;
|
|
877
|
+
drawingIds ??= usedDrawingIds({
|
|
878
|
+
documentBody: destination.package.document,
|
|
879
|
+
headers: destination.package.headers,
|
|
880
|
+
footers: destination.package.footers,
|
|
881
|
+
footnotes: destination.package.footnotes,
|
|
882
|
+
endnotes: destination.package.endnotes
|
|
883
|
+
});
|
|
884
|
+
const id = takeDrawingId(drawingIds);
|
|
885
|
+
const kept = structuredClone(drawing);
|
|
886
|
+
kept.image.id = id;
|
|
887
|
+
const renumbered = withDrawingId(drawing, id).rawXml;
|
|
888
|
+
if (renumbered !== void 0) kept.rawXml = renumbered;
|
|
889
|
+
return Result.ok(kept);
|
|
890
|
+
};
|
|
891
|
+
for (const paragraph of paragraphs) {
|
|
892
|
+
const imported = importResources(paragraph);
|
|
893
|
+
if (imported.isErr()) return imported;
|
|
894
|
+
}
|
|
895
|
+
for (const xml of clipboardPreservedBlocks(blocks)) {
|
|
896
|
+
const placed = keptMarkupPlaced(xml, "Kept block markup naming package parts pastes only into the package holding them.");
|
|
897
|
+
if (placed.isErr()) return placed;
|
|
898
|
+
}
|
|
899
|
+
sourceRelationships = void 0;
|
|
900
|
+
for (const note of annotations?.notes ?? []) for (const block of note.content) {
|
|
901
|
+
if (block.type !== "paragraph") continue;
|
|
902
|
+
const imported = importResources(block);
|
|
903
|
+
if (imported.isErr()) return imported;
|
|
639
904
|
}
|
|
640
905
|
const resourceOps = [];
|
|
641
906
|
if (importedResource || numbering !== destination.package.numbering || styles !== destination.package.styles) {
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { splitsSurrogatePair } from "../ai-edits/character-boundaries.js";
|
|
2
2
|
import { CanonicalSessionError } from "../canonical/canonicalSession.js";
|
|
3
|
-
import { CANONICAL_CONDITION
|
|
3
|
+
import { CANONICAL_CONDITION } from "../types/canonicalCapabilities.js";
|
|
4
4
|
import { setCanonicalInputTimer } from "./canonicalInputTimer.js";
|
|
5
5
|
import { Result } from "better-result";
|
|
6
6
|
import { EditorState, TextSelection } from "prosemirror-state";
|
|
7
7
|
import { DOMParser, DOMSerializer, Fragment } from "prosemirror-model";
|
|
8
8
|
// src/controller/canonicalComposition.ts
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* A composition the browser's own input did not reduce to one text
|
|
11
|
+
* replacement, restored. The commit reads what native input changed from the
|
|
12
|
+
* view; where it changed an atom (an image, a field, a note reference) or
|
|
13
|
+
* more than one textblock, or a plugin rewrote more than text, the DOM states
|
|
14
|
+
* no edit the session can tell from noise. The user types the text again, as
|
|
15
|
+
* input outside a composition reaches the session as intents.
|
|
16
|
+
*/
|
|
17
|
+
const UNSUPPORTED_COMPOSITION = { condition: CANONICAL_CONDITION.invalidRequest };
|
|
11
18
|
const REVIEW_MARK_NAMES = /* @__PURE__ */ new Set(["insertion", "deletion"]);
|
|
12
19
|
const readBackCache = /* @__PURE__ */ new WeakMap();
|
|
13
20
|
/**
|
|
@@ -31,6 +38,35 @@ const readBack = (mark) => {
|
|
|
31
38
|
readBackCache.set(mark, read);
|
|
32
39
|
return read;
|
|
33
40
|
};
|
|
41
|
+
/** The depth of the innermost textblock holding `position`, if one does. */
|
|
42
|
+
const textblockDepth = (position) => {
|
|
43
|
+
for (let depth = position.depth; depth >= 0; depth -= 1) if (position.node(depth).isTextblock) return depth;
|
|
44
|
+
};
|
|
45
|
+
/** The child of `fragment` that `position` falls in, with its offset. */
|
|
46
|
+
const childAround = (fragment, position) => {
|
|
47
|
+
let found;
|
|
48
|
+
fragment.forEach((node, offset) => {
|
|
49
|
+
if (found === void 0 && position < offset + node.nodeSize) found = {
|
|
50
|
+
node,
|
|
51
|
+
offset
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
return found;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* One character for each position of `fragment`: a text node's own, the
|
|
58
|
+
* object replacement character for an inline atom, and a private-use
|
|
59
|
+
* character for each edge of an inline node holding content.
|
|
60
|
+
*/
|
|
61
|
+
const positionText = (fragment) => {
|
|
62
|
+
let text = "";
|
|
63
|
+
fragment.forEach((node) => {
|
|
64
|
+
if (node.isText) text += node.text ?? "";
|
|
65
|
+
else if (node.isLeaf) text += "".repeat(node.nodeSize);
|
|
66
|
+
else text += `\uE000${positionText(node.content)}\uE001`;
|
|
67
|
+
});
|
|
68
|
+
return text;
|
|
69
|
+
};
|
|
34
70
|
/**
|
|
35
71
|
* Whether a native proposal is one plain replacement. The commit is a text
|
|
36
72
|
* replacement over the captured model, so this only has to tell DOM noise from a
|
|
@@ -142,7 +178,9 @@ const createCanonicalComposition = (options) => {
|
|
|
142
178
|
};
|
|
143
179
|
const replacement = (baseline, proposed) => {
|
|
144
180
|
const { $from, $to } = baseline.selection;
|
|
145
|
-
|
|
181
|
+
const fromDepth = textblockDepth($from);
|
|
182
|
+
const toDepth = textblockDepth($to);
|
|
183
|
+
if (fromDepth === void 0 || toDepth === void 0) return null;
|
|
146
184
|
const selected = selectedReplacement(baseline, proposed);
|
|
147
185
|
if (selected) {
|
|
148
186
|
if ($from.sameParent($to) && selected.text === baseline.doc.textBetween(selected.from, selected.to, "", "")) return {
|
|
@@ -153,12 +191,12 @@ const createCanonicalComposition = (options) => {
|
|
|
153
191
|
};
|
|
154
192
|
return selected;
|
|
155
193
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const changedFrom =
|
|
194
|
+
const paragraphStart = $from.start(fromDepth);
|
|
195
|
+
if (paragraphStart !== $to.start(toDepth)) return null;
|
|
196
|
+
const textblock = $from.node(fromDepth);
|
|
197
|
+
const proposedParagraph = proposed.doc.nodeAt(paragraphStart - 1);
|
|
198
|
+
if (!proposedParagraph || proposedParagraph.type !== textblock.type) return null;
|
|
199
|
+
const changedFrom = textblock.content.findDiffStart(proposedParagraph.content);
|
|
162
200
|
if (changedFrom === null) {
|
|
163
201
|
if (!baseline.doc.eq(proposed.doc)) return null;
|
|
164
202
|
return {
|
|
@@ -168,7 +206,7 @@ const createCanonicalComposition = (options) => {
|
|
|
168
206
|
semantic: "composition"
|
|
169
207
|
};
|
|
170
208
|
}
|
|
171
|
-
const changedEnd =
|
|
209
|
+
const changedEnd = textblock.content.findDiffEnd(proposedParagraph.content);
|
|
172
210
|
if (changedEnd === null) return null;
|
|
173
211
|
let from = changedFrom;
|
|
174
212
|
let oldEnd = changedEnd.a;
|
|
@@ -178,8 +216,23 @@ const createCanonicalComposition = (options) => {
|
|
|
178
216
|
oldEnd += overlap;
|
|
179
217
|
newEnd += overlap;
|
|
180
218
|
}
|
|
181
|
-
|
|
182
|
-
|
|
219
|
+
let start = paragraphStart;
|
|
220
|
+
let previous = textblock.content;
|
|
221
|
+
let next = proposedParagraph.content;
|
|
222
|
+
for (;;) {
|
|
223
|
+
const held = childAround(previous, from);
|
|
224
|
+
const read = childAround(next, from);
|
|
225
|
+
if (held === void 0 || read === void 0 || held.node.isText || held.node.isLeaf || held.offset !== read.offset || !held.node.sameMarkup(read.node) || from <= held.offset || oldEnd >= held.offset + held.node.nodeSize || newEnd >= read.offset + read.node.nodeSize) break;
|
|
226
|
+
const inner = held.offset + 1;
|
|
227
|
+
start += inner;
|
|
228
|
+
from -= inner;
|
|
229
|
+
oldEnd -= inner;
|
|
230
|
+
newEnd -= inner;
|
|
231
|
+
previous = held.node.content;
|
|
232
|
+
next = read.node.content;
|
|
233
|
+
}
|
|
234
|
+
const before = positionText(previous);
|
|
235
|
+
const after = positionText(next);
|
|
183
236
|
while (from < oldEnd && from < newEnd && before[from] === after[from]) from++;
|
|
184
237
|
while (oldEnd > from && newEnd > from && before[oldEnd - 1] === after[newEnd - 1]) {
|
|
185
238
|
oldEnd--;
|
|
@@ -191,7 +244,7 @@ const createCanonicalComposition = (options) => {
|
|
|
191
244
|
newEnd++;
|
|
192
245
|
}
|
|
193
246
|
const removed = previous.cut(from, oldEnd);
|
|
194
|
-
const inserted = next.
|
|
247
|
+
const inserted = next.cut(from, newEnd);
|
|
195
248
|
const text = inserted.textBetween(0, inserted.size, "", "");
|
|
196
249
|
if (removed.textBetween(0, removed.size, "", "").length !== removed.size || text.length !== inserted.size) return null;
|
|
197
250
|
if (!matchesNativeReplacement({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CanonicalSessionError } from "../canonical/canonicalSession.js";
|
|
2
|
+
import { retainMarkupViewSource } from "../prosemirror/conversion/markupViewSource.js";
|
|
2
3
|
import { adoptNativeSelection, isCompositionKeyDown } from "../prosemirror/nativeSelection.js";
|
|
3
4
|
import { CANONICAL_CONDITION } from "../types/canonicalCapabilities.js";
|
|
4
5
|
import { createCanonicalInputBoundary, unclassifiedMutationMessage } from "./canonicalInput.js";
|
|
@@ -116,6 +117,7 @@ const createCanonicalStoryEditor = ({ story, getView, getApi, onRefusal, onSelec
|
|
|
116
117
|
view.updateState(view.state);
|
|
117
118
|
return;
|
|
118
119
|
}
|
|
120
|
+
retainMarkupViewSource(view.state, applied.state);
|
|
119
121
|
view.updateState(applied.state);
|
|
120
122
|
if (applied.transactions.some((step) => step.selectionSet)) {
|
|
121
123
|
getApi()?.noteCanonicalStoryView({
|
|
@@ -15,6 +15,7 @@ import { canonicalSelectionRange } from "../prosemirror/canonicalSelectionRange.
|
|
|
15
15
|
import { registerClipboardIntentHandler } from "../prosemirror/clipboardIntent.js";
|
|
16
16
|
import { pasteWithoutFormatting } from "../prosemirror/commands/pastePlainText.js";
|
|
17
17
|
import { createCommentRecordsPlugin, isCommentRecordsSync } from "../prosemirror/commentRecords.js";
|
|
18
|
+
import { retainMarkupViewSource } from "../prosemirror/conversion/markupViewSource.js";
|
|
18
19
|
import { createEmptyDoc, toProseDoc } from "../prosemirror/conversion/toProseDoc.js";
|
|
19
20
|
import { registerEditorCommandOwner } from "../prosemirror/executeEditorCommand.js";
|
|
20
21
|
import { ensureBaseDirectionInState } from "../prosemirror/extensions/features/AutoBidiDetectionExtension.js";
|
|
@@ -732,6 +733,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
732
733
|
return;
|
|
733
734
|
}
|
|
734
735
|
const documentEdits = applied.transactions.filter((appliedTransaction) => appliedTransaction.docChanged && !isCommentRecordsSync(appliedTransaction));
|
|
736
|
+
retainMarkupViewSource(view.state, applied.state);
|
|
735
737
|
view.updateState(applied.state);
|
|
736
738
|
const docChanged = documentEdits.length > 0;
|
|
737
739
|
const selectionChanged = applied.transactions.some((appliedTransaction) => appliedTransaction.selectionSet || appliedTransaction.docChanged && !isCommentRecordsSync(appliedTransaction));
|