@stll/docx-core 0.46.0 → 0.48.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/{document-BKejiFuk.d.ts → document-BOzPxEBT.d.ts} +5 -1
- package/dist/{document-BuoCvTcR.js → document-d_O4GWz3.js} +14 -1
- package/dist/docx_kernel_bg.wasm +0 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/{listItems-bPpOKnLB.js → listItems-BM4hecVF.js} +1 -1
- package/dist/model/document.d.ts +2 -2
- package/dist/model/document.js +1 -1
- package/dist/ops/documentOps.d.ts +121 -65
- package/dist/ops/documentOps.js +1253 -419
- package/package.json +1 -1
package/dist/ops/documentOps.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as PARAGRAPH_ALIGNMENTS, X as preservedChildGap, at as isNumberingReference, c as MAX_REVISION_ID, d as REVIEW_CARRIERS,
|
|
2
|
-
import { a as preservedCommentRangeMarkersAt, i as preservedCommentRangeMarker, n as sanitizeExternalUrl, o as withPreservedCommentRangeId, s as maxOf, t as itemBefore } from "../listItems-
|
|
1
|
+
import { At as gridColumnsInRows, N as PARAGRAPH_ALIGNMENTS, X as preservedChildGap, at as isNumberingReference, c as MAX_REVISION_ID, d as REVIEW_CARRIERS, jt as getSingularRunPropertyChange, kt as MAX_TABLE_GRID_COLUMNS, lt as paragraphNumberingReference, nt as isNumberingLevel, o as HELD_PARAGRAPH_JOINS, s as INSERTION_SEAM_POLICIES, t as COMMENT_PART_RELATIONSHIPS, vt as finalizeParagraphFormatting, xt as setDocumentBodyComments } from "../document-d_O4GWz3.js";
|
|
2
|
+
import { a as preservedCommentRangeMarkersAt, i as preservedCommentRangeMarker, n as sanitizeExternalUrl, o as withPreservedCommentRangeId, s as maxOf, t as itemBefore } from "../listItems-BM4hecVF.js";
|
|
3
3
|
import { g as hasIllegalXmlCharacters } from "../streamingXmlParser-BqnCIEZd.js";
|
|
4
4
|
import { Result, TaggedError, panic } from "better-result";
|
|
5
5
|
import { encodeUtf8 } from "@stll/utf8-boundaries";
|
|
@@ -381,16 +381,16 @@ const ROOT_CONTEXT = {
|
|
|
381
381
|
ownerType: void 0
|
|
382
382
|
};
|
|
383
383
|
const censusWalker = (ownKeys, sharing) => {
|
|
384
|
-
const known = /* @__PURE__ */ new
|
|
384
|
+
const known = /* @__PURE__ */ new Map();
|
|
385
385
|
const remembered = (value, key, census) => {
|
|
386
386
|
if (key === void 0 || !census.shareable) return census;
|
|
387
|
-
const keys = census.keys
|
|
388
|
-
let
|
|
389
|
-
if (
|
|
390
|
-
|
|
391
|
-
known.set(
|
|
387
|
+
const keys = Object.isFrozen(census.keys) ? census.keys : Object.freeze([...census.keys]);
|
|
388
|
+
let byRecord = known.get(key);
|
|
389
|
+
if (byRecord === void 0) {
|
|
390
|
+
byRecord = /* @__PURE__ */ new WeakMap();
|
|
391
|
+
known.set(key, byRecord);
|
|
392
392
|
}
|
|
393
|
-
|
|
393
|
+
byRecord.set(value, keys);
|
|
394
394
|
return {
|
|
395
395
|
keys,
|
|
396
396
|
shareable: true
|
|
@@ -401,7 +401,7 @@ const censusWalker = (ownKeys, sharing) => {
|
|
|
401
401
|
const isList = Array.isArray(value) || value instanceof Map;
|
|
402
402
|
if (!isList && !isPlainRecord$1(value)) return EMPTY_CENSUS;
|
|
403
403
|
const key = sharing === "full" ? void 0 : contextKey(context);
|
|
404
|
-
const cached = key === void 0 ? void 0 : known.get(
|
|
404
|
+
const cached = key === void 0 ? void 0 : known.get(key)?.get(value);
|
|
405
405
|
if (cached !== void 0) return {
|
|
406
406
|
keys: cached,
|
|
407
407
|
shareable: true
|
|
@@ -1382,6 +1382,35 @@ const withFieldResult = (field, result) => field.type === "simpleField" ? {
|
|
|
1382
1382
|
* this, not {@link childNodes}, which keeps a field one unit.
|
|
1383
1383
|
*/
|
|
1384
1384
|
const nestedRecords = (node) => childNodes(node) ?? fieldResultOf(node);
|
|
1385
|
+
const FIELD_HELD_CHANGE_TYPES = /* @__PURE__ */ new Set([
|
|
1386
|
+
"insertion",
|
|
1387
|
+
"deletion",
|
|
1388
|
+
"moveFrom",
|
|
1389
|
+
"moveTo"
|
|
1390
|
+
]);
|
|
1391
|
+
const isFieldHeldChange = (node) => FIELD_HELD_CHANGE_TYPES.has(node.type);
|
|
1392
|
+
/**
|
|
1393
|
+
* The ids of the tracked changes a field's result holds at any depth:
|
|
1394
|
+
* `CT_SimpleField` is `EG_PContent`, so `w:fldSimple` may hold `w:ins`,
|
|
1395
|
+
* `w:del`, `w:moveFrom` and `w:moveTo` around the runs that show it. Only a
|
|
1396
|
+
* change whose content the field can hold in its place is listed: resolving
|
|
1397
|
+
* one keeps or drops its content where it stood, inside the field's one
|
|
1398
|
+
* unit, so no offset or seam outside the field moves. A complex field's
|
|
1399
|
+
* result holds runs alone; one whose result carries a change is read as its
|
|
1400
|
+
* field characters, which stand in the paragraph.
|
|
1401
|
+
*/
|
|
1402
|
+
const fieldHeldChangeIds = (node) => {
|
|
1403
|
+
const out = [];
|
|
1404
|
+
const holdable = (nodes) => nodes.every(isSimpleFieldContent);
|
|
1405
|
+
const visit = (nodes) => {
|
|
1406
|
+
for (const child of nodes) {
|
|
1407
|
+
if (isFieldHeldChange(child) && holdable(child.content)) out.push(child.info.id);
|
|
1408
|
+
visit(childNodes(child) ?? []);
|
|
1409
|
+
}
|
|
1410
|
+
};
|
|
1411
|
+
visit(fieldResultOf(node) ?? []);
|
|
1412
|
+
return out;
|
|
1413
|
+
};
|
|
1385
1414
|
/** The same record holding other {@link nestedRecords}. */
|
|
1386
1415
|
const withNestedRecords = (node, children) => node.type === "simpleField" || node.type === "complexField" ? withFieldResult(node, children) : rebuildNode(node, children);
|
|
1387
1416
|
/**
|
|
@@ -2087,8 +2116,10 @@ const DOCUMENT_OP_REFUSAL_REASONS = Object.freeze({
|
|
|
2087
2116
|
INSIDE_INLINE_CONTROL: "insideInlineControl",
|
|
2088
2117
|
/**
|
|
2089
2118
|
* No tracked change can record the edit, or no resolution op can carry it
|
|
2090
|
-
* out yet:
|
|
2091
|
-
*
|
|
2119
|
+
* out yet: the paragraph mark's run properties, a deleted paragraph whose
|
|
2120
|
+
* hyperlink or content control holds a comment anchor, a section-ending
|
|
2121
|
+
* mark resolved across a standing range boundary, a change inside a
|
|
2122
|
+
* simple field holding content the field cannot hold.
|
|
2092
2123
|
*/
|
|
2093
2124
|
UNTRACKABLE: "untrackable",
|
|
2094
2125
|
/** A second tracked column insertion beside a pending grid change. */
|
|
@@ -3483,11 +3514,11 @@ const restoreCommentBoundaries = (document, boundaries) => {
|
|
|
3483
3514
|
};
|
|
3484
3515
|
// src/ops/blockListCheck.ts
|
|
3485
3516
|
/**
|
|
3486
|
-
* Whether a block list or a container in it holds what
|
|
3517
|
+
* Whether a block list or a container in it holds what the checks look for,
|
|
3487
3518
|
* reusing unchanged lists: operation documents and their block lists are
|
|
3488
3519
|
* immutable once validated.
|
|
3489
3520
|
*/
|
|
3490
|
-
const blockListCheck = ({ paragraph, cell }) => {
|
|
3521
|
+
const blockListCheck = ({ paragraph, table, cell }) => {
|
|
3491
3522
|
const checked = /* @__PURE__ */ new WeakMap();
|
|
3492
3523
|
const holds = (blocks) => {
|
|
3493
3524
|
const key = listKey(blocks);
|
|
@@ -3497,7 +3528,7 @@ const blockListCheck = ({ paragraph, cell }) => {
|
|
|
3497
3528
|
const found = (splice !== void 0 && checked.get(splice.previous) === false ? blocks.slice(splice.start, splice.end) : blocks).some((block) => {
|
|
3498
3529
|
switch (block.type) {
|
|
3499
3530
|
case "paragraph": return paragraph(block);
|
|
3500
|
-
case "table": return block.rows.some((row) => row.cells.some(({ content }) => (cell ?? holds)(content)));
|
|
3531
|
+
case "table": return table?.(block) === true || block.rows.some((row) => row.cells.some(({ content }) => (cell ?? holds)(content)));
|
|
3501
3532
|
case "blockSdt":
|
|
3502
3533
|
case "blockCustomXml": return holds(block.content);
|
|
3503
3534
|
case "preservedBlock":
|
|
@@ -4285,6 +4316,8 @@ const spanningAction = (node, kind, stamp) => {
|
|
|
4285
4316
|
if (isRemovedRevisionNode(node)) return kind === WRAP_KINDS.DELETION ? "keep" : "refuse";
|
|
4286
4317
|
return "cut";
|
|
4287
4318
|
};
|
|
4319
|
+
/** Whether the wrap takes this comment reference in ({@link WrapOptions.takenReferences}). */
|
|
4320
|
+
const takesReference = (node, state) => node.type === "commentReference" && state.commentAnchorsStand && state.takenReferences.has(node.id);
|
|
4288
4321
|
/** Whether a record holds a comment anchor at any depth. */
|
|
4289
4322
|
const holdsCommentAnchor = (node) => (childNodes(node) ?? []).some((child) => isCommentAnchor(child) || holdsCommentAnchor(child));
|
|
4290
4323
|
/**
|
|
@@ -4303,7 +4336,10 @@ const holdsCommentAnchor = (node) => (childNodes(node) ?? []).some((child) => is
|
|
|
4303
4336
|
* boundary it held.
|
|
4304
4337
|
*/
|
|
4305
4338
|
const coveredAction = (node, state) => {
|
|
4306
|
-
if (isCommentAnchor(node))
|
|
4339
|
+
if (isCommentAnchor(node)) {
|
|
4340
|
+
if (takesReference(node, state)) return "wrap";
|
|
4341
|
+
return state.commentAnchorsStand ? "skip" : "refuse";
|
|
4342
|
+
}
|
|
4307
4343
|
if (state.kind === WRAP_KINDS.DELETION) {
|
|
4308
4344
|
if (isRemovedRevisionNode(node)) return "skip";
|
|
4309
4345
|
if (isAddedRevision(node)) return "descend";
|
|
@@ -4413,7 +4449,7 @@ const mergeWithStampedNeighbour = (out, index, state) => {
|
|
|
4413
4449
|
const trackedContent$1 = (nodes, state) => {
|
|
4414
4450
|
const out = [];
|
|
4415
4451
|
for (const node of nodes) {
|
|
4416
|
-
if (!isParagraphContent(node) || !isTrackedChild(node) || node.type === "commentReference") {
|
|
4452
|
+
if (!isParagraphContent(node) || !isTrackedChild(node) || node.type === "commentReference" && !takesReference(node, state)) {
|
|
4417
4453
|
state.refusal = DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE;
|
|
4418
4454
|
return;
|
|
4419
4455
|
}
|
|
@@ -4610,7 +4646,7 @@ const wrapList = (nodes, cursor, state) => {
|
|
|
4610
4646
|
* `unchanged` when there is nothing to record: every leaf is already
|
|
4611
4647
|
* deleted, or an insertion sits inside a wrapper carrying the same stamp.
|
|
4612
4648
|
*/
|
|
4613
|
-
const wrapTracked = ({ items, from, to, kind, stamp, resolutionJoin, startJoin = 0, acceptance, copiedBoundaries, commentAnchors }) => {
|
|
4649
|
+
const wrapTracked = ({ items, from, to, kind, stamp, resolutionJoin, startJoin = 0, acceptance, copiedBoundaries, commentAnchors, takenReferences = /* @__PURE__ */ new Set() }) => {
|
|
4614
4650
|
const state = {
|
|
4615
4651
|
gaps: [from, to],
|
|
4616
4652
|
resolutionJoin,
|
|
@@ -4625,7 +4661,8 @@ const wrapTracked = ({ items, from, to, kind, stamp, resolutionJoin, startJoin =
|
|
|
4625
4661
|
recorded: false,
|
|
4626
4662
|
recordedContent: false,
|
|
4627
4663
|
refusal: void 0,
|
|
4628
|
-
commentAnchorsStand: commentAnchors === "stand"
|
|
4664
|
+
commentAnchorsStand: commentAnchors === "stand",
|
|
4665
|
+
takenReferences
|
|
4629
4666
|
};
|
|
4630
4667
|
const content = wrapList(items, startCursor(), state);
|
|
4631
4668
|
if (content === void 0) return {
|
|
@@ -5959,6 +5996,7 @@ const removedNoteStories = (before, after) => {
|
|
|
5959
5996
|
* - no revision id (tracked changes, property changes) or content-control id
|
|
5960
5997
|
* repeats, so the one record carrying an id is the one it names;
|
|
5961
5998
|
* - the body's section view says what its blocks say;
|
|
5999
|
+
* - table grids and their snapshots fit the supported model width;
|
|
5962
6000
|
* - each editable story holds no empty run, text node, or revision wrapper.
|
|
5963
6001
|
*
|
|
5964
6002
|
* Headers, footers and notes are independently addressable stories. Text-box
|
|
@@ -5973,6 +6011,10 @@ const DocumentOpsContractErrorBase = TaggedError("DocumentOpsContractError");
|
|
|
5973
6011
|
var DocumentOpsContractError = class extends DocumentOpsContractErrorBase {};
|
|
5974
6012
|
const holdsEmptyRecord$1 = (nodes) => nodes.some((node) => isEmptyRecord(node) || holdsEmptyRecord$1(childNodes(node) ?? []));
|
|
5975
6013
|
const blocksHaveMultiplePropertyChanges = blockListCheck({ paragraph: ({ propertyChanges }) => (propertyChanges?.length ?? 0) > 1 });
|
|
6014
|
+
const blocksHaveOversizedTableGrid = blockListCheck({
|
|
6015
|
+
paragraph: () => false,
|
|
6016
|
+
table: ({ rows, columnWidths, formatting }) => gridColumnsInRows(rows) > 4096 || (columnWidths?.length ?? 0) > 4096 || (formatting?.gridChange?.columnWidths?.length ?? 0) > 4096
|
|
6017
|
+
});
|
|
5976
6018
|
/** Check every editable story and nested block container, reusing unchanged lists. */
|
|
5977
6019
|
const hasMultipleParagraphPropertyChanges = (document, boxes = []) => [...documentStories(document), ...boxes].some((story) => blocksHaveMultiplePropertyChanges(storyBody$1(document, story).content));
|
|
5978
6020
|
/**
|
|
@@ -5994,6 +6036,10 @@ const violation = (document) => {
|
|
|
5994
6036
|
reason: DOCUMENT_OP_REFUSAL_REASONS.STRUCTURE_MISMATCH,
|
|
5995
6037
|
message: "A paragraph cannot carry more than one property change."
|
|
5996
6038
|
});
|
|
6039
|
+
if (documentStories(document).some((story) => blocksHaveOversizedTableGrid(storyBody$1(document, story).content))) return new DocumentOpsContractError({
|
|
6040
|
+
reason: DOCUMENT_OP_REFUSAL_REASONS.STRUCTURE_MISMATCH,
|
|
6041
|
+
message: `A table grid can hold at most ${MAX_TABLE_GRID_COLUMNS} columns.`
|
|
6042
|
+
});
|
|
5997
6043
|
const body = document.package.document;
|
|
5998
6044
|
const paragraphs = documentStories(document).flatMap((story) => storyParagraphs(storyBody$1(document, story)));
|
|
5999
6045
|
if (paragraphs.some(({ paragraph }) => paragraph.paraId === void 0)) return new DocumentOpsContractError({
|
|
@@ -8984,10 +9030,6 @@ const recordedOnlyBy = (value, owner) => {
|
|
|
8984
9030
|
* document.
|
|
8985
9031
|
*/
|
|
8986
9032
|
const deletedContent = (paragraph, stamp, rangedComments) => {
|
|
8987
|
-
if (!liveReferencesAreRanged(paragraph.content, rangedComments)) return {
|
|
8988
|
-
kind: "refused",
|
|
8989
|
-
reason: DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE
|
|
8990
|
-
};
|
|
8991
9033
|
const wrapped = wrapTracked({
|
|
8992
9034
|
items: paragraph.content,
|
|
8993
9035
|
from: {
|
|
@@ -9000,7 +9042,8 @@ const deletedContent = (paragraph, stamp, rangedComments) => {
|
|
|
9000
9042
|
},
|
|
9001
9043
|
kind: WRAP_KINDS.DELETION,
|
|
9002
9044
|
stamp,
|
|
9003
|
-
commentAnchors: "stand"
|
|
9045
|
+
commentAnchors: "stand",
|
|
9046
|
+
takenReferences: pointReferenceIds(paragraph.content, rangedComments)
|
|
9004
9047
|
});
|
|
9005
9048
|
if (wrapped.kind === "refused") return wrapped;
|
|
9006
9049
|
if (wrapped.kind === "unchanged") return {
|
|
@@ -9093,15 +9136,21 @@ const takenOverBreakRecords = ({ broken, paragraphs, owner, held }) => {
|
|
|
9093
9136
|
*/
|
|
9094
9137
|
const holdsRangeBoundary = (nodes, held = /* @__PURE__ */ new Set()) => nodes.some((node) => isBoundary(node) && !isHeldAnchor(node, held) || holdsRangeBoundary(childNodes(node) ?? [], held));
|
|
9095
9138
|
/**
|
|
9096
|
-
*
|
|
9097
|
-
*
|
|
9098
|
-
*
|
|
9139
|
+
* The ids of the comment references in `nodes` whose comment has no range
|
|
9140
|
+
* (`rangedComments` names those that do): a point comment, whose reference
|
|
9141
|
+
* is its only anchor.
|
|
9099
9142
|
*/
|
|
9100
|
-
const
|
|
9101
|
-
|
|
9102
|
-
|
|
9103
|
-
|
|
9104
|
-
|
|
9143
|
+
const pointReferenceIds = (nodes, rangedComments) => {
|
|
9144
|
+
const ids = /* @__PURE__ */ new Set();
|
|
9145
|
+
const visit = (items) => {
|
|
9146
|
+
for (const node of items) {
|
|
9147
|
+
if (node.type === "commentReference" && !rangedComments.has(node.id)) ids.add(node.id);
|
|
9148
|
+
visit(childNodes(node) ?? []);
|
|
9149
|
+
}
|
|
9150
|
+
};
|
|
9151
|
+
visit(nodes);
|
|
9152
|
+
return ids;
|
|
9153
|
+
};
|
|
9105
9154
|
/** The ids of the comments whose range ends somewhere in `value`. */
|
|
9106
9155
|
const rangeEndIdsIn = (value, ids = /* @__PURE__ */ new Set()) => {
|
|
9107
9156
|
if (Array.isArray(value)) {
|
|
@@ -14079,6 +14128,54 @@ const edgeChainPastRemoved = (chain, index, edge) => {
|
|
|
14079
14128
|
return [...chain.slice(0, index), ...edgeChain(next, edge)];
|
|
14080
14129
|
};
|
|
14081
14130
|
// src/ops/positionedMarkers.ts
|
|
14131
|
+
const carriers = (item) => item?.carrierStack ?? (item?.contentControls ?? []).map((properties) => ({
|
|
14132
|
+
type: "sdt",
|
|
14133
|
+
properties
|
|
14134
|
+
}));
|
|
14135
|
+
const sameCarrier = (left, right) => left.type === "customXml" ? right.type === "customXml" && left.wrapper.id === right.wrapper.id : right.type === "sdt" && structurallyEqual(left.properties, right.properties);
|
|
14136
|
+
const sharedDepth = (left, right) => {
|
|
14137
|
+
let depth = 0;
|
|
14138
|
+
for (const [index, carrier] of left.entries()) {
|
|
14139
|
+
const peer = right[index];
|
|
14140
|
+
if (peer === void 0 || !sameCarrier(carrier, peer)) break;
|
|
14141
|
+
depth += 1;
|
|
14142
|
+
}
|
|
14143
|
+
return depth;
|
|
14144
|
+
};
|
|
14145
|
+
/** A new sibling between two members of one wrapper stays inside it. */
|
|
14146
|
+
const inheritCarriers = (siblings, origins) => {
|
|
14147
|
+
if (!origins.includes(null)) return siblings;
|
|
14148
|
+
let changed = false;
|
|
14149
|
+
const next = [...siblings];
|
|
14150
|
+
for (let start = 0; start < siblings.length; start++) {
|
|
14151
|
+
if (origins[start] !== null) continue;
|
|
14152
|
+
const left = carriers(siblings[start - 1]);
|
|
14153
|
+
let end = start + 1;
|
|
14154
|
+
while (origins[end] === null) end += 1;
|
|
14155
|
+
const right = carriers(siblings[end]);
|
|
14156
|
+
const depth = sharedDepth(left, right);
|
|
14157
|
+
if (depth > 0) {
|
|
14158
|
+
const inherited = left.slice(0, depth);
|
|
14159
|
+
for (let index = start; index < end; index++) {
|
|
14160
|
+
const sibling = siblings[index];
|
|
14161
|
+
if (sibling === void 0) continue;
|
|
14162
|
+
const existing = carriers(sibling);
|
|
14163
|
+
const shared = sharedDepth(inherited, existing);
|
|
14164
|
+
if (shared === inherited.length) continue;
|
|
14165
|
+
const carrierStack = [...inherited, ...existing.slice(shared)];
|
|
14166
|
+
const contentControls = carrierStack.flatMap((carrier) => carrier.type === "sdt" ? [carrier.properties] : []);
|
|
14167
|
+
changed = true;
|
|
14168
|
+
next[index] = {
|
|
14169
|
+
...sibling,
|
|
14170
|
+
...contentControls.length === 0 ? {} : { contentControls },
|
|
14171
|
+
...sibling.carrierStack === void 0 && siblings[start - 1]?.carrierStack === void 0 && siblings[end]?.carrierStack === void 0 ? {} : { carrierStack }
|
|
14172
|
+
};
|
|
14173
|
+
}
|
|
14174
|
+
}
|
|
14175
|
+
start = end - 1;
|
|
14176
|
+
}
|
|
14177
|
+
return changed ? next : siblings;
|
|
14178
|
+
};
|
|
14082
14179
|
/**
|
|
14083
14180
|
* For each sibling after an edit, the index of the sibling before it that it
|
|
14084
14181
|
* continues, or `null` for a new one. A sibling continues the latest one
|
|
@@ -14097,51 +14194,102 @@ const originsOf = (before, after) => {
|
|
|
14097
14194
|
return origin;
|
|
14098
14195
|
});
|
|
14099
14196
|
};
|
|
14197
|
+
const beforeFollowingSibling = (index, origins) => {
|
|
14198
|
+
const following = origins.findIndex((origin) => origin !== null && origin >= index);
|
|
14199
|
+
return following === -1 ? origins.length : following;
|
|
14200
|
+
};
|
|
14201
|
+
/** Keep positioned children beside siblings that share their wrapper. */
|
|
14202
|
+
const relocatedIndex = (item, { origins, siblings }, sticksLeft) => {
|
|
14203
|
+
const { index } = item;
|
|
14204
|
+
const right = beforeFollowingSibling(index, origins);
|
|
14205
|
+
const left = origins.findLastIndex((origin) => origin !== null && origin < index) + 1;
|
|
14206
|
+
if (left === right) return left;
|
|
14207
|
+
const wrapper = carriers(item);
|
|
14208
|
+
if (wrapper.length > 0) {
|
|
14209
|
+
const leftDepth = sharedDepth(wrapper, carriers(siblings[left - 1]));
|
|
14210
|
+
const rightDepth = sharedDepth(wrapper, carriers(siblings[right]));
|
|
14211
|
+
if (leftDepth !== rightDepth) return leftDepth > rightDepth ? left : right;
|
|
14212
|
+
}
|
|
14213
|
+
return sticksLeft ? left : right;
|
|
14214
|
+
};
|
|
14100
14215
|
/** `markers`, indexed among the siblings `origins` describes. */
|
|
14101
|
-
const relocated = (markers,
|
|
14102
|
-
|
|
14103
|
-
|
|
14104
|
-
|
|
14105
|
-
|
|
14106
|
-
|
|
14107
|
-
|
|
14108
|
-
|
|
14109
|
-
|
|
14110
|
-
|
|
14111
|
-
};
|
|
14112
|
-
|
|
14113
|
-
|
|
14216
|
+
const relocated = (markers, destinations) => {
|
|
14217
|
+
let changed = false;
|
|
14218
|
+
const nextMarkers = markers.map((positioned) => {
|
|
14219
|
+
const next = relocatedIndex(positioned, destinations, positioned.marker.type === "bookmarkEnd");
|
|
14220
|
+
if (next === positioned.index) return positioned;
|
|
14221
|
+
changed = true;
|
|
14222
|
+
return {
|
|
14223
|
+
...positioned,
|
|
14224
|
+
index: next
|
|
14225
|
+
};
|
|
14226
|
+
});
|
|
14227
|
+
return changed ? nextMarkers : markers;
|
|
14228
|
+
};
|
|
14229
|
+
/** Preserve a captured child's gap before the next surviving sibling. */
|
|
14230
|
+
const relocateCaptured = (preserved, destinations) => {
|
|
14231
|
+
if (preserved.children === void 0) return preserved;
|
|
14232
|
+
let changed = false;
|
|
14233
|
+
const children = preserved.children.map((child) => {
|
|
14234
|
+
const index = relocatedIndex(child, destinations, false);
|
|
14235
|
+
if (index === child.index) return child;
|
|
14236
|
+
changed = true;
|
|
14237
|
+
return {
|
|
14238
|
+
...child,
|
|
14239
|
+
index
|
|
14240
|
+
};
|
|
14241
|
+
});
|
|
14242
|
+
return changed ? {
|
|
14243
|
+
...preserved,
|
|
14244
|
+
children
|
|
14245
|
+
} : preserved;
|
|
14246
|
+
};
|
|
14114
14247
|
/**
|
|
14115
|
-
* `after`,
|
|
14116
|
-
*
|
|
14117
|
-
* cells, moved to where the edit leaves them.
|
|
14248
|
+
* `after`, with its bookmark markers and captured XML moved to the gaps
|
|
14249
|
+
* where the edit leaves them beside table rows and row cells.
|
|
14118
14250
|
*/
|
|
14119
14251
|
const relocatePositionedMarkers = (before, after) => {
|
|
14120
14252
|
const rowOrigins = originsOf(before.rows, after.rows);
|
|
14121
|
-
|
|
14122
|
-
|
|
14253
|
+
const wrappedRows = inheritCarriers(after.rows, rowOrigins);
|
|
14254
|
+
let rowsChanged = wrappedRows !== after.rows;
|
|
14255
|
+
const rows = [...wrappedRows];
|
|
14256
|
+
for (const [index, row] of wrappedRows.entries()) {
|
|
14123
14257
|
const origin = rowOrigins[index] ?? null;
|
|
14124
14258
|
const source = origin === null ? void 0 : before.rows[origin];
|
|
14125
|
-
if (row.bookmarks === void 0
|
|
14126
|
-
const
|
|
14127
|
-
|
|
14259
|
+
if (source === void 0 || row.bookmarks === void 0 && row.preserved === void 0 && !row.cells.some((cell) => cell.contentControls !== void 0 || cell.carrierStack !== void 0)) continue;
|
|
14260
|
+
const cellOrigins = originsOf(source.cells, row.cells);
|
|
14261
|
+
const cells = inheritCarriers(row.cells, cellOrigins);
|
|
14262
|
+
const destinations = {
|
|
14263
|
+
origins: cellOrigins,
|
|
14264
|
+
siblings: cells
|
|
14265
|
+
};
|
|
14266
|
+
const markers = row.bookmarks !== void 0 && structurallyEqual(row.bookmarks, source.bookmarks) ? relocated(row.bookmarks, destinations) : row.bookmarks;
|
|
14267
|
+
const preserved = row.preserved !== void 0 && structurallyEqual(row.preserved, source.preserved) ? relocateCaptured(row.preserved, destinations) : row.preserved;
|
|
14268
|
+
if (preserved === row.preserved && markers === row.bookmarks && cells === row.cells) continue;
|
|
14128
14269
|
rowsChanged = true;
|
|
14129
|
-
|
|
14270
|
+
rows[index] = {
|
|
14130
14271
|
...row,
|
|
14131
|
-
|
|
14272
|
+
cells,
|
|
14273
|
+
...markers === void 0 ? {} : { bookmarks: markers },
|
|
14274
|
+
...preserved === void 0 ? {} : { preserved }
|
|
14132
14275
|
};
|
|
14133
|
-
}
|
|
14134
|
-
const
|
|
14135
|
-
|
|
14136
|
-
|
|
14276
|
+
}
|
|
14277
|
+
const destinations = {
|
|
14278
|
+
origins: rowOrigins,
|
|
14279
|
+
siblings: rows
|
|
14280
|
+
};
|
|
14281
|
+
const tableMarkers = after.bookmarks === void 0 ? void 0 : relocated(after.bookmarks, destinations);
|
|
14282
|
+
const preserved = after.preserved === void 0 ? void 0 : relocateCaptured(after.preserved, destinations);
|
|
14283
|
+
if (!rowsChanged && tableMarkers === after.bookmarks && preserved === after.preserved) return after;
|
|
14137
14284
|
return {
|
|
14138
14285
|
...after,
|
|
14139
14286
|
rows,
|
|
14140
|
-
...tableMarkers === void 0 ? {} : { bookmarks: tableMarkers }
|
|
14287
|
+
...tableMarkers === void 0 ? {} : { bookmarks: tableMarkers },
|
|
14288
|
+
...preserved === void 0 ? {} : { preserved }
|
|
14141
14289
|
};
|
|
14142
14290
|
};
|
|
14143
|
-
/** Whether
|
|
14144
|
-
const
|
|
14291
|
+
/** Whether the inverse needs the original row and cell gaps. */
|
|
14292
|
+
const holdsPositionedMarkup = (table) => table.preserved?.children !== void 0 || table.bookmarks !== void 0 || table.rows.some((row) => row.bookmarks !== void 0 || row.preserved?.children !== void 0 || row.contentControls !== void 0 || row.carrierStack !== void 0 || row.cells.some((cell) => cell.contentControls !== void 0 || cell.carrierStack !== void 0));
|
|
14145
14293
|
// src/model/tableCellVerticalMerge.ts
|
|
14146
14294
|
const TABLE_CELL_VERTICAL_MERGES = {
|
|
14147
14295
|
NONE: "none",
|
|
@@ -14202,7 +14350,7 @@ const tableGrid = (table, opType) => {
|
|
|
14202
14350
|
for (const cell of cells) previous.set(cell.start, cell);
|
|
14203
14351
|
}
|
|
14204
14352
|
const width = maxOf(covered, table.columnWidths?.length ?? 0);
|
|
14205
|
-
if (width === 0) return refuse();
|
|
14353
|
+
if (width === 0 || width > 4096) return refuse();
|
|
14206
14354
|
const stated = covered.every((columns) => columns === width) && (table.columnWidths === void 0 || table.columnWidths.length === width);
|
|
14207
14355
|
return Result.ok({
|
|
14208
14356
|
width,
|
|
@@ -14320,9 +14468,67 @@ const withMergesEnded = (table, rowIndex) => {
|
|
|
14320
14468
|
cells
|
|
14321
14469
|
};
|
|
14322
14470
|
};
|
|
14471
|
+
const BOUNDARIES = rangeBoundaryDefinitions();
|
|
14472
|
+
/** Every range boundary and comment reference in `value`, at any depth, in source order. */
|
|
14473
|
+
const boundariesIn = (value, out = []) => {
|
|
14474
|
+
if (typeof value !== "object" || value === null) return out;
|
|
14475
|
+
const type = Reflect.get(value, "type");
|
|
14476
|
+
if (typeof type === "string" && (Object.hasOwn(BOUNDARIES, type) || type === "commentReference")) out.push(value);
|
|
14477
|
+
else for (const field of Object.values(value)) boundariesIn(field, out);
|
|
14478
|
+
return out;
|
|
14479
|
+
};
|
|
14480
|
+
/**
|
|
14481
|
+
* The range boundaries in `removed`, other than those `kept` still holds,
|
|
14482
|
+
* whose other end stands outside it. Removed content takes its words, not
|
|
14483
|
+
* the end of a range reaching past it: these ends stay where it was, and a
|
|
14484
|
+
* comment's reference stays beside its range's end. A range wholly inside
|
|
14485
|
+
* goes with it.
|
|
14486
|
+
*/
|
|
14487
|
+
const rangeEndsReachingPast = (removed, kept) => {
|
|
14488
|
+
const keeps = new Set(boundariesIn(kept));
|
|
14489
|
+
const lost = boundariesIn(removed).filter((node) => !keeps.has(node));
|
|
14490
|
+
const key = ({ type, id }) => type === "commentReference" ? "" : `${BOUNDARIES[type].family}:${id}`;
|
|
14491
|
+
const reaching = lost.filter((node) => key(node) !== "" && lost.filter((other) => key(other) === key(node)).length === 1);
|
|
14492
|
+
return lost.filter((node) => reaching.includes(node) || node.type === "commentReference" && reaching.some(({ type, id }) => type === "commentRangeEnd" && id === node.id));
|
|
14493
|
+
};
|
|
14494
|
+
/**
|
|
14495
|
+
* `rows` with the ends of ranges reaching past the removed row
|
|
14496
|
+
* ({@link rangeEndsReachingPast}) where the row was: at the start of the row
|
|
14497
|
+
* after it, else at the end of the row before. With no row left the table
|
|
14498
|
+
* goes, and its removal keeps them.
|
|
14499
|
+
*/
|
|
14500
|
+
const withRangeEndsKept = (removed, rows, rowIndex) => {
|
|
14501
|
+
const ends = rangeEndsReachingPast(removed, rows[rowIndex]);
|
|
14502
|
+
const after = rowIndex < rows.length;
|
|
14503
|
+
const at = after ? rowIndex : rowIndex - 1;
|
|
14504
|
+
const row = rows[at];
|
|
14505
|
+
const cellAt = after ? 0 : (row?.cells.length ?? 0) - 1;
|
|
14506
|
+
const cell = row?.cells[cellAt];
|
|
14507
|
+
if (ends.length === 0 || row === void 0 || cell === void 0) return rows;
|
|
14508
|
+
const content = [...cell.content];
|
|
14509
|
+
const index = after ? content.findIndex((block) => block.type === "paragraph") : content.findLastIndex((block) => block.type === "paragraph");
|
|
14510
|
+
const paragraph = content[index];
|
|
14511
|
+
if (paragraph?.type !== "paragraph") return rows;
|
|
14512
|
+
content[index] = {
|
|
14513
|
+
...paragraph,
|
|
14514
|
+
content: after ? [...ends, ...paragraph.content] : [...paragraph.content, ...ends]
|
|
14515
|
+
};
|
|
14516
|
+
const cells = [...row.cells];
|
|
14517
|
+
cells[cellAt] = {
|
|
14518
|
+
...cell,
|
|
14519
|
+
content
|
|
14520
|
+
};
|
|
14521
|
+
const out = [...rows];
|
|
14522
|
+
out[at] = {
|
|
14523
|
+
...row,
|
|
14524
|
+
cells
|
|
14525
|
+
};
|
|
14526
|
+
return out;
|
|
14527
|
+
};
|
|
14323
14528
|
/**
|
|
14324
14529
|
* The table's rows without row `rowIndex`: the merges it starts handed on,
|
|
14325
|
-
*
|
|
14530
|
+
* those it alone continues ended, and the ends of ranges reaching past it
|
|
14531
|
+
* kept.
|
|
14326
14532
|
*/
|
|
14327
14533
|
const rowsWithoutRow = (table, rowIndex) => {
|
|
14328
14534
|
const rows = [...table.rows];
|
|
@@ -14331,12 +14537,75 @@ const rowsWithoutRow = (table, rowIndex) => {
|
|
|
14331
14537
|
const next = withMergesHandedOn(table, rowIndex);
|
|
14332
14538
|
if (next === void 0) rows.splice(rowIndex, 1);
|
|
14333
14539
|
else rows.splice(rowIndex, 2, next);
|
|
14334
|
-
|
|
14540
|
+
const removed = table.rows[rowIndex];
|
|
14541
|
+
return removed === void 0 ? rows : withRangeEndsKept(removed, rows, rowIndex);
|
|
14542
|
+
};
|
|
14543
|
+
const VERTICAL = TABLE_CELL_VERTICAL_MERGES;
|
|
14544
|
+
const spansOf = (row) => {
|
|
14545
|
+
let at = row?.formatting?.gridBefore ?? 0;
|
|
14546
|
+
return (row?.cells ?? []).map((cell) => {
|
|
14547
|
+
const start = at;
|
|
14548
|
+
at += cell.formatting?.gridSpan ?? 1;
|
|
14549
|
+
return {
|
|
14550
|
+
cell,
|
|
14551
|
+
key: `${start}:${at}`
|
|
14552
|
+
};
|
|
14553
|
+
});
|
|
14554
|
+
};
|
|
14555
|
+
const withVerticalMerge = (cell, vMerge) => {
|
|
14556
|
+
const { vMerge: _vMerge, sourceXml: _sourceXml, ...formatting } = cell.formatting ?? {};
|
|
14557
|
+
if (vMerge !== void 0) return {
|
|
14558
|
+
...cell,
|
|
14559
|
+
formatting: {
|
|
14560
|
+
...formatting,
|
|
14561
|
+
vMerge
|
|
14562
|
+
}
|
|
14563
|
+
};
|
|
14564
|
+
if (Object.keys(formatting).length > 0) return {
|
|
14565
|
+
...cell,
|
|
14566
|
+
formatting
|
|
14567
|
+
};
|
|
14568
|
+
const { formatting: _formatting, ...plain } = cell;
|
|
14569
|
+
return plain;
|
|
14570
|
+
};
|
|
14571
|
+
/**
|
|
14572
|
+
* The table's rows with `row` put in at `at`, its vertical merges matched to
|
|
14573
|
+
* the rows it lands between, which the batch may have changed since the row
|
|
14574
|
+
* was built. A cell under a merge the row below continues continues it too; a
|
|
14575
|
+
* continuation goes on a merge of its span above, making the cell above start
|
|
14576
|
+
* one when the removal of the merge's last row ended it; with no cell of its
|
|
14577
|
+
* span above, it is a cell of its own.
|
|
14578
|
+
*/
|
|
14579
|
+
const rowsWithRow = (rows, at, row) => {
|
|
14580
|
+
const above = spansOf(rows[at - 1]);
|
|
14581
|
+
const below = spansOf(rows[at]);
|
|
14582
|
+
const restarted = /* @__PURE__ */ new Set();
|
|
14583
|
+
const cells = spansOf(row).map(({ cell, key }) => {
|
|
14584
|
+
const over = above.find((entry) => entry.key === key)?.cell;
|
|
14585
|
+
const merge = tableCellVerticalMerge(cell.formatting?.vMerge);
|
|
14586
|
+
if (over !== void 0 && below.some((entry) => entry.key === key && tableCellVerticalMerge(entry.cell.formatting?.vMerge) === VERTICAL.CONTINUE)) return withVerticalMerge(cell, VERTICAL.CONTINUE);
|
|
14587
|
+
if (merge !== VERTICAL.CONTINUE) return cell;
|
|
14588
|
+
if (over === void 0) return withVerticalMerge(cell, void 0);
|
|
14589
|
+
if (tableCellVerticalMerge(over.formatting?.vMerge) === VERTICAL.NONE) restarted.add(over);
|
|
14590
|
+
return cell;
|
|
14591
|
+
});
|
|
14592
|
+
const out = [...rows];
|
|
14593
|
+
const previous = rows[at - 1];
|
|
14594
|
+
if (previous !== void 0 && restarted.size > 0) out[at - 1] = {
|
|
14595
|
+
...previous,
|
|
14596
|
+
cells: previous.cells.map((cell) => restarted.has(cell) ? withVerticalMerge(cell, VERTICAL.RESTART) : cell)
|
|
14597
|
+
};
|
|
14598
|
+
out.splice(at, 0, {
|
|
14599
|
+
...row,
|
|
14600
|
+
cells
|
|
14601
|
+
});
|
|
14602
|
+
return out;
|
|
14335
14603
|
};
|
|
14336
14604
|
/**
|
|
14337
|
-
* Whether
|
|
14338
|
-
*
|
|
14339
|
-
*
|
|
14605
|
+
* Whether a row edit left a vertical merge without the cell that starts it:
|
|
14606
|
+
* rows that covered one grid before must still cover one after, or a merged
|
|
14607
|
+
* cell's content went with a row that only continued elsewhere, or an
|
|
14608
|
+
* inserted row continues a merge that is not there.
|
|
14340
14609
|
*/
|
|
14341
14610
|
const removalOrphansAMerge = (before, rows) => rows.length > 0 && tableGrid(before, DOCUMENT_OP_TYPES.DELETE_ROW).isOk() && tableGrid({
|
|
14342
14611
|
...before,
|
|
@@ -15111,6 +15380,22 @@ const runParagraphIntoTable = (paragraph, target) => {
|
|
|
15111
15380
|
if (replacement.type !== "table") panic("A table receiver has a nonempty table path.");
|
|
15112
15381
|
return replacement;
|
|
15113
15382
|
};
|
|
15383
|
+
/** A rejected deletion keeps its receiver. Other pending structures block it. */
|
|
15384
|
+
const authoredTableReceiverIsPending = ({ table, decision, selected }) => {
|
|
15385
|
+
const deletionStays = (id) => decision === REVISION_DECISIONS.REJECT && selected.has(id);
|
|
15386
|
+
let current = table;
|
|
15387
|
+
for (;;) {
|
|
15388
|
+
const row = current.rows.at(0);
|
|
15389
|
+
const rowChange = row?.structuralChange;
|
|
15390
|
+
if (rowChange?.type === "tableRowInsertion" || rowChange?.type === "tableRowDeletion" && !deletionStays(rowChange.info.id)) return true;
|
|
15391
|
+
const cell = row?.cells.at(0);
|
|
15392
|
+
const cellChange = cell?.structuralChange;
|
|
15393
|
+
if (cellChange?.type === "tableCellInsertion" || cellChange?.type === "tableCellMerge" || cellChange?.type === "tableCellDeletion" && !deletionStays(cellChange.info.id)) return true;
|
|
15394
|
+
const first = cell?.content.at(0);
|
|
15395
|
+
if (first?.type !== "table") return false;
|
|
15396
|
+
current = first;
|
|
15397
|
+
}
|
|
15398
|
+
};
|
|
15114
15399
|
const NO_COMMENT_RANGES = /* @__PURE__ */ new Set();
|
|
15115
15400
|
const NO_BOUNDARY_PATHS = /* @__PURE__ */ new Set();
|
|
15116
15401
|
/** Whether a decision removes the content of a tracked change of this kind. */
|
|
@@ -15288,29 +15573,47 @@ const resolveRun = (run, { ids, decision }) => {
|
|
|
15288
15573
|
else delete next.propertyChanges;
|
|
15289
15574
|
return next;
|
|
15290
15575
|
};
|
|
15291
|
-
/**
|
|
15292
|
-
|
|
15576
|
+
/**
|
|
15577
|
+
* A field's result with the records it holds resolved: the run property
|
|
15578
|
+
* changes on its runs, and the tracked changes `w:fldSimple` holds around
|
|
15579
|
+
* them ({@link fieldHeldChangeIds}). The result is the field's one unit, so
|
|
15580
|
+
* a resolved change keeps or drops its content where it stood and no seam
|
|
15581
|
+
* outside the field moves. A container that resolving empties goes, as
|
|
15582
|
+
* resolution leaves no emptied record.
|
|
15583
|
+
*/
|
|
15584
|
+
const resolveFieldResult = (nodes, resolution, held) => {
|
|
15293
15585
|
let changed = false;
|
|
15294
|
-
const out =
|
|
15586
|
+
const out = [];
|
|
15587
|
+
for (const node of nodes) {
|
|
15588
|
+
if (isTrackedWrapper(node) && held.has(node.info.id) && resolution.ids.has(node.info.id)) {
|
|
15589
|
+
changed = true;
|
|
15590
|
+
if (!removesContent(node, resolution.decision)) out.push(...resolveFieldResult(node.content, resolution, held));
|
|
15591
|
+
continue;
|
|
15592
|
+
}
|
|
15295
15593
|
let next = node;
|
|
15594
|
+
const children = node.type === "run" ? void 0 : childNodes(node);
|
|
15296
15595
|
if (node.type === "run") next = resolveRun(node, resolution);
|
|
15297
|
-
else {
|
|
15298
|
-
const
|
|
15299
|
-
|
|
15300
|
-
|
|
15596
|
+
else if (children !== void 0) {
|
|
15597
|
+
const inner = resolveFieldResult(children, resolution, held);
|
|
15598
|
+
if (inner !== children) {
|
|
15599
|
+
changed = true;
|
|
15600
|
+
if (inner.length === 0 && children.length > 0) continue;
|
|
15601
|
+
next = rebuildNode(node, inner);
|
|
15602
|
+
}
|
|
15301
15603
|
}
|
|
15302
15604
|
if (next !== node) changed = true;
|
|
15303
|
-
|
|
15304
|
-
}
|
|
15605
|
+
out.push(next);
|
|
15606
|
+
}
|
|
15305
15607
|
return changed ? out : nodes;
|
|
15306
15608
|
};
|
|
15307
15609
|
/**
|
|
15308
|
-
* A field with the
|
|
15309
|
-
* a run property patch over the field records
|
|
15610
|
+
* A field with the records of its result resolved: the run property changes
|
|
15611
|
+
* a run property patch over the field records there, and the tracked changes
|
|
15612
|
+
* a `w:fldSimple` holds.
|
|
15310
15613
|
*/
|
|
15311
15614
|
const resolveFieldRuns = (field, resolution) => {
|
|
15312
15615
|
const result = fieldResultOf(field) ?? [];
|
|
15313
|
-
const next =
|
|
15616
|
+
const next = resolveFieldResult(result, resolution, new Set(fieldHeldChangeIds(field)));
|
|
15314
15617
|
return next === result ? field : withFieldResult(field, next);
|
|
15315
15618
|
};
|
|
15316
15619
|
const emptyPieceOf = ({ empty, other, emptied }) => {
|
|
@@ -16288,7 +16591,7 @@ const withRejoinedBlockers = ({ nodes, retired, resolution }) => {
|
|
|
16288
16591
|
}
|
|
16289
16592
|
}
|
|
16290
16593
|
if (children === void 0) next = withKeptCutHoldersRenamed(next, successor);
|
|
16291
|
-
if (next !== node) carryResolutionState(resolution, node, next);
|
|
16594
|
+
if (next !== node && resolution !== void 0) carryResolutionState(resolution, node, next);
|
|
16292
16595
|
return next;
|
|
16293
16596
|
};
|
|
16294
16597
|
return nodes.map(rewrite);
|
|
@@ -16363,7 +16666,11 @@ const cutReach = ({ before, after, depth, spanning, resolution }) => {
|
|
|
16363
16666
|
const node = chains[side][index];
|
|
16364
16667
|
if (node === void 0 || !isTrackedWrapper(node) || !resolution.ids.has(node.info.id) || !removesContent(node, resolution.decision)) return false;
|
|
16365
16668
|
const chain = edgeChainPastRemoved(chains[side], index, side === "before" ? "end" : "start");
|
|
16366
|
-
if (chain === void 0)
|
|
16669
|
+
if (chain === void 0) {
|
|
16670
|
+
const parent = chains[side][index - 1];
|
|
16671
|
+
if (parent !== void 0 && childNodes(parent)?.length === 1) reach.gone = true;
|
|
16672
|
+
return false;
|
|
16673
|
+
}
|
|
16367
16674
|
chains[side] = chain;
|
|
16368
16675
|
return true;
|
|
16369
16676
|
};
|
|
@@ -17852,6 +18159,14 @@ const resolveList = ({ nodes: listed, resolution, path }) => {
|
|
|
17852
18159
|
if (inner.edges.first !== void 0) edges.first = inner.edges.first + 1;
|
|
17853
18160
|
if (inner.edges.last !== void 0) edges.last = inner.edges.last + 1;
|
|
17854
18161
|
resolution.cutEdges.set(rebuilt, edges);
|
|
18162
|
+
if ((rebuilt.type === "deletion" || rebuilt.type === "moveFrom") && rebuilt.resolutionJoins !== void 0) {
|
|
18163
|
+
const joins = rebuilt.resolutionJoins;
|
|
18164
|
+
rebuilt = Object.assign({}, rebuilt, { resolutionJoins: Object.assign({}, joins, {
|
|
18165
|
+
before: Math.max(joins.before, inner.edges.first ?? 0),
|
|
18166
|
+
after: Math.max(joins.after, inner.edges.last ?? 0)
|
|
18167
|
+
}) });
|
|
18168
|
+
resolution.cutEdges.set(rebuilt, edges);
|
|
18169
|
+
}
|
|
17855
18170
|
}
|
|
17856
18171
|
appendSource(rebuilt, index);
|
|
17857
18172
|
}
|
|
@@ -18653,6 +18968,7 @@ const reachableIds = (paragraph) => {
|
|
|
18653
18968
|
for (const node of nodes) {
|
|
18654
18969
|
if (isTrackedWrapper(node)) out.add(node.info.id);
|
|
18655
18970
|
for (const change of ownRunPropertyChanges(node)) out.add(change.info.id);
|
|
18971
|
+
for (const id of fieldHeldChangeIds(node)) out.add(id);
|
|
18656
18972
|
visit(childNodes(node) ?? []);
|
|
18657
18973
|
}
|
|
18658
18974
|
};
|
|
@@ -18936,7 +19252,7 @@ const opensSectionBeforeTrailingBoundaries = (blocks, index) => {
|
|
|
18936
19252
|
const before = blocks.findLast((block, at) => at < index && !isBlockBoundary(block));
|
|
18937
19253
|
return before?.type === "paragraph" && before.sectionProperties !== void 0;
|
|
18938
19254
|
};
|
|
18939
|
-
const joinOps = (document, { op, story, paraId, revisionId, added, depth, holders }, ends, ranInto = /* @__PURE__ */ new Set(), joinsBefore = /* @__PURE__ */ new Set(), rejoined = /* @__PURE__ */ new Map()) => {
|
|
19255
|
+
const joinOps = (document, { op, story, paraId, revisionId, added, depth, holders, pendingReceiverTableIds }, ends, ranInto = /* @__PURE__ */ new Set(), joinsBefore = /* @__PURE__ */ new Set(), rejoined = /* @__PURE__ */ new Map()) => {
|
|
18940
19256
|
const body = storyBody$1(document, story);
|
|
18941
19257
|
const location = findStoryParagraph(body, paraId);
|
|
18942
19258
|
if (location === void 0) return Result.err(refusal$3(op, DOCUMENT_OP_REFUSAL_REASONS.BLOCK_NOT_FOUND, `No paragraph is ${paraId}.`));
|
|
@@ -19033,7 +19349,10 @@ const joinOps = (document, { op, story, paraId, revisionId, added, depth, holder
|
|
|
19033
19349
|
})) rejoined.set(id, into);
|
|
19034
19350
|
const keepsFirst = paragraph.pPrMark?.survivor === "first";
|
|
19035
19351
|
ends.set(keepsFirst ? idKey(paraId) : nextId, emptiedEndsOf(merged, emptied));
|
|
19036
|
-
const mergedContent = asParagraphContent(
|
|
19352
|
+
const mergedContent = asParagraphContent(withRejoinedBlockers({
|
|
19353
|
+
nodes: merged,
|
|
19354
|
+
retired: rejoined
|
|
19355
|
+
}));
|
|
19037
19356
|
let survivor;
|
|
19038
19357
|
if (keepsFirst) survivor = joinedKeepingFirst(paragraph, next, mergedContent);
|
|
19039
19358
|
else if (structurallyEqual(mergedContent, next.content)) survivor = next;
|
|
@@ -19085,7 +19404,8 @@ const joinOps = (document, { op, story, paraId, revisionId, added, depth, holder
|
|
|
19085
19404
|
const containerFinal = endsItsContainer(body, location);
|
|
19086
19405
|
const endsBeforeBoundaries = added && next === void 0 && standing.length > 0 && opensSectionBeforeTrailingBoundaries(blocks, location.index);
|
|
19087
19406
|
const tableBoundary = next?.type === "table" ? paragraphTableRunInBoundary(paragraph, next) : void 0;
|
|
19088
|
-
const
|
|
19407
|
+
const stillPendingReceiver = pendingReceiverTableIds !== void 0 && next?.type === "table" && storyParagraphs({ content: [next] }).some(({ paragraph: { paraId: receiverId } }) => receiverId !== void 0 && pendingReceiverTableIds.has(idKey(receiverId)));
|
|
19408
|
+
const tableTarget = tableBoundary?.type === "receiver" && !stillPendingReceiver ? tableBoundary.target : void 0;
|
|
19089
19409
|
const blockTarget = next !== void 0 && followsBlock ? paragraphBlockRunInTarget(paragraph, next) : void 0;
|
|
19090
19410
|
const runInReceiver = tableTarget?.receiver ?? blockTarget?.receiver;
|
|
19091
19411
|
const remains = paragraphRemains(paragraph.content);
|
|
@@ -19551,26 +19871,26 @@ const withBelongingPropertyChanges = (document, op) => {
|
|
|
19551
19871
|
* Resolve tracked changes by revision id, applied as the primitive
|
|
19552
19872
|
* operations it expands to. An id no record in the story carries is
|
|
19553
19873
|
* skipped; one carried by a record resolution does not reach yet (a table,
|
|
19554
|
-
* cell or section change, a
|
|
19874
|
+
* cell or section change, or a change inside a simple field holding content
|
|
19875
|
+
* the field cannot hold) is refused.
|
|
19555
19876
|
*/
|
|
19556
19877
|
const planRevisionResolution = (options) => {
|
|
19557
19878
|
const { document, applyOps } = options;
|
|
19558
19879
|
const op = withBelongingPropertyChanges(document, options.op);
|
|
19559
19880
|
const sections = settleSectionRecords(document, op);
|
|
19560
19881
|
if (sections.ops.length === 0) return planMarkResolution({
|
|
19561
|
-
|
|
19562
|
-
op
|
|
19563
|
-
applyOps
|
|
19882
|
+
...options,
|
|
19883
|
+
op
|
|
19564
19884
|
});
|
|
19565
19885
|
const settled = applyOps(document, sections.ops);
|
|
19566
19886
|
if (settled.isErr()) return Result.err(settled.error);
|
|
19567
19887
|
const rest = planMarkResolution({
|
|
19888
|
+
...options,
|
|
19568
19889
|
document: settled.value.document,
|
|
19569
19890
|
op: {
|
|
19570
19891
|
...op,
|
|
19571
19892
|
revisionIds: sections.ids
|
|
19572
|
-
}
|
|
19573
|
-
applyOps
|
|
19893
|
+
}
|
|
19574
19894
|
});
|
|
19575
19895
|
if (rest.isErr()) return Result.err(rest.error);
|
|
19576
19896
|
return Result.ok({
|
|
@@ -19684,12 +20004,12 @@ const planMarkResolution = (options) => {
|
|
|
19684
20004
|
const marks = applyOps(document, settled.ops);
|
|
19685
20005
|
if (marks.isErr()) return Result.err(marks.error);
|
|
19686
20006
|
const rest = planSingleRecordResolution({
|
|
20007
|
+
...options,
|
|
19687
20008
|
document: marks.value.document,
|
|
19688
20009
|
op: {
|
|
19689
20010
|
...op,
|
|
19690
20011
|
revisionIds: settled.ids
|
|
19691
|
-
}
|
|
19692
|
-
applyOps
|
|
20012
|
+
}
|
|
19693
20013
|
}, storyParagraphs(storyBody$1(marks.value.document, op.story)));
|
|
19694
20014
|
if (rest.isErr()) return Result.err(rest.error);
|
|
19695
20015
|
return Result.ok({
|
|
@@ -19697,7 +20017,7 @@ const planMarkResolution = (options) => {
|
|
|
19697
20017
|
receiverEffects: rest.value.receiverEffects
|
|
19698
20018
|
});
|
|
19699
20019
|
};
|
|
19700
|
-
const planSingleRecordResolution = ({ document, op, applyOps }, paragraphs) => {
|
|
20020
|
+
const planSingleRecordResolution = ({ document, op, applyOps, purpose }, paragraphs) => {
|
|
19701
20021
|
if (!Object.values(REVISION_DECISIONS).includes(op.decision)) return Result.err(refusal$3(op, DOCUMENT_OP_REFUSAL_REASONS.STRUCTURE_MISMATCH, "A decision accepts or rejects."));
|
|
19702
20022
|
if (!op.revisionIds.every((id) => Number.isInteger(id))) return Result.err(refusal$3(op, DOCUMENT_OP_REFUSAL_REASONS.INVALID_NEW_ID, "A revision id is an integer."));
|
|
19703
20023
|
const finalSectionRevision = storyBody$1(document, op.story).finalSectionProperties?.propertyChanges?.find(({ info }) => op.revisionIds.includes(info.id));
|
|
@@ -19906,7 +20226,7 @@ const planSingleRecordResolution = ({ document, op, applyOps }, paragraphs) => {
|
|
|
19906
20226
|
const key = idKey(candidate.paraId ?? "");
|
|
19907
20227
|
const firstCut = resolvedCutEdges.get(key)?.first ?? 0;
|
|
19908
20228
|
const mark = candidate.pPrMark;
|
|
19909
|
-
if ((resolvedContents.get(key)
|
|
20229
|
+
if (!(resolvedContents.get(key) ?? []).every(isKeptBoundaryCarrier) || mark === void 0 || !markWasAdded(mark.kind)) {
|
|
19910
20230
|
suffix = {
|
|
19911
20231
|
leadingCut: firstCut,
|
|
19912
20232
|
chainCut: 0
|
|
@@ -19996,8 +20316,15 @@ const planSingleRecordResolution = ({ document, op, applyOps }, paragraphs) => {
|
|
|
19996
20316
|
const keepsBreak = markResolved && added === (op.decision === REVISION_DECISIONS.ACCEPT);
|
|
19997
20317
|
if (markResolved && !keepsBreak) {
|
|
19998
20318
|
let depth = retiredCutDepths.get(idKey(paraId)) ?? mark.resolutionJoin;
|
|
20319
|
+
const blocks = blockListAt(body.content, location.list);
|
|
20320
|
+
const following = purpose === "markup-view" ? blockFollower(blocks, location.index).block : void 0;
|
|
20321
|
+
const pendingReceiverTableIds = following?.type === "table" && authoredTableReceiverIsPending({
|
|
20322
|
+
table: following,
|
|
20323
|
+
decision: op.decision,
|
|
20324
|
+
selected: ids
|
|
20325
|
+
}) ? new Set(storyParagraphs({ content: [following] }).flatMap(({ paragraph: { paraId: receiverId } }) => receiverId === void 0 ? [] : [idKey(receiverId)])) : void 0;
|
|
19999
20326
|
if (added && depth !== void 0 && op.decision === REVISION_DECISIONS.REJECT) {
|
|
20000
|
-
const next =
|
|
20327
|
+
const next = blocks.at(location.index + 1);
|
|
20001
20328
|
depth = Math.max(depth, resolvedCutEdges.get(idKey(paraId))?.last ?? 0, next?.type === "paragraph" ? resolvedCutEdges.get(idKey(next.paraId ?? ""))?.first ?? 0 : 0);
|
|
20002
20329
|
}
|
|
20003
20330
|
joins.push({
|
|
@@ -20007,7 +20334,8 @@ const planSingleRecordResolution = ({ document, op, applyOps }, paragraphs) => {
|
|
|
20007
20334
|
revisionId: mark.info.id,
|
|
20008
20335
|
added,
|
|
20009
20336
|
depth,
|
|
20010
|
-
holders
|
|
20337
|
+
holders,
|
|
20338
|
+
...pendingReceiverTableIds === void 0 ? {} : { pendingReceiverTableIds }
|
|
20011
20339
|
});
|
|
20012
20340
|
}
|
|
20013
20341
|
let review = resolveParagraphReview(paragraph, resolution, keepsBreak);
|
|
@@ -20273,11 +20601,88 @@ const rejoinedRevisions = ({ rejoined, present }) => {
|
|
|
20273
20601
|
}
|
|
20274
20602
|
return absorptions;
|
|
20275
20603
|
};
|
|
20276
|
-
|
|
20277
|
-
|
|
20278
|
-
|
|
20279
|
-
|
|
20280
|
-
|
|
20604
|
+
/**
|
|
20605
|
+
* Resolve an independent text story with the same inline planner. With no
|
|
20606
|
+
* structural records, anchors or cut provenance, a paragraph's resolution
|
|
20607
|
+
* cannot change the next one. A view can keep every unchanged block and skip
|
|
20608
|
+
* building write operations and inverses for the parallel replacements.
|
|
20609
|
+
*/
|
|
20610
|
+
const resolveIndependentTextParagraphs = (body, decision) => {
|
|
20611
|
+
if ((body.finalSectionProperties?.propertyChanges?.length ?? 0) > 0) return void 0;
|
|
20612
|
+
const revised = [];
|
|
20613
|
+
const plainRunWidth = (node) => {
|
|
20614
|
+
if (node.type !== "run" || (node.propertyChanges?.length ?? 0) > 0) return 0;
|
|
20615
|
+
let width = 0;
|
|
20616
|
+
for (const leaf of node.content) {
|
|
20617
|
+
if (leaf.type !== "text" || leaf.text.length === 0) return 0;
|
|
20618
|
+
width += leaf.text.length;
|
|
20619
|
+
}
|
|
20620
|
+
return width;
|
|
20621
|
+
};
|
|
20622
|
+
for (const [index, paragraph] of body.content.entries()) {
|
|
20623
|
+
if (paragraph.type !== "paragraph" || paragraph.reviewCarrier !== void 0 || paragraph.pPrMark !== void 0 || (paragraph.propertyChanges?.length ?? 0) > 0 || (paragraph.sectionProperties?.propertyChanges?.length ?? 0) > 0) return void 0;
|
|
20624
|
+
let ids;
|
|
20625
|
+
let omitted;
|
|
20626
|
+
let sourceLength = 0;
|
|
20627
|
+
for (const inline of paragraph.content) {
|
|
20628
|
+
if (inline.type === "run") {
|
|
20629
|
+
const width = plainRunWidth(inline);
|
|
20630
|
+
if (width === 0) return void 0;
|
|
20631
|
+
sourceLength += width;
|
|
20632
|
+
continue;
|
|
20633
|
+
}
|
|
20634
|
+
if (inline.type !== "insertion" && inline.type !== "deletion" || inline.resolutionJoins !== void 0 || !isRevisionId(inline.info.id) || inline.content.length === 0) return void 0;
|
|
20635
|
+
const from = sourceLength;
|
|
20636
|
+
for (const run of inline.content) {
|
|
20637
|
+
const width = plainRunWidth(run);
|
|
20638
|
+
if (width === 0) return void 0;
|
|
20639
|
+
sourceLength += width;
|
|
20640
|
+
}
|
|
20641
|
+
if (removesContent(inline, decision)) (omitted ??= []).push({
|
|
20642
|
+
from,
|
|
20643
|
+
to: sourceLength
|
|
20644
|
+
});
|
|
20645
|
+
(ids ??= /* @__PURE__ */ new Set()).add(inline.info.id);
|
|
20646
|
+
}
|
|
20647
|
+
if (ids !== void 0) revised.push({
|
|
20648
|
+
paragraph,
|
|
20649
|
+
ids,
|
|
20650
|
+
change: {
|
|
20651
|
+
index,
|
|
20652
|
+
sourceLength,
|
|
20653
|
+
omitted: omitted ?? []
|
|
20654
|
+
}
|
|
20655
|
+
});
|
|
20656
|
+
}
|
|
20657
|
+
if (revised.length === 0) return {
|
|
20658
|
+
body,
|
|
20659
|
+
changes: []
|
|
20660
|
+
};
|
|
20661
|
+
const content = [...body.content];
|
|
20662
|
+
for (const { paragraph, ids, change } of revised) {
|
|
20663
|
+
const resolved = resolveList({
|
|
20664
|
+
nodes: paragraph.content,
|
|
20665
|
+
resolution: createResolution(ids, decision),
|
|
20666
|
+
path: []
|
|
20667
|
+
});
|
|
20668
|
+
const resolvedContent = asParagraphContent(resolved.nodes);
|
|
20669
|
+
if (textsIn(resolvedContent).some(hasIllegalXmlCharacters)) return void 0;
|
|
20670
|
+
const target = {
|
|
20671
|
+
...paragraph,
|
|
20672
|
+
content: resolvedContent
|
|
20673
|
+
};
|
|
20674
|
+
transferParagraphPropertySnapshot({
|
|
20675
|
+
source: paragraph,
|
|
20676
|
+
target
|
|
20677
|
+
});
|
|
20678
|
+
content[change.index] = target;
|
|
20679
|
+
}
|
|
20680
|
+
return {
|
|
20681
|
+
body: withBodyContent(body, content),
|
|
20682
|
+
changes: revised.map(({ change }) => change)
|
|
20683
|
+
};
|
|
20684
|
+
};
|
|
20685
|
+
const resolveRevision = (options) => planRevisionResolution(options).map(({ edit }) => edit);
|
|
20281
20686
|
// src/ops/revisionInfo.ts
|
|
20282
20687
|
const refuse$5 = (reason, message) => Result.err(new DocumentOpRefusal({
|
|
20283
20688
|
reason,
|
|
@@ -20478,9 +20883,9 @@ const tableEditBoundaryRefusal = (op) => {
|
|
|
20478
20883
|
// src/ops/tableEditDependencies.ts
|
|
20479
20884
|
/**
|
|
20480
20885
|
* Records a removed column cell cannot take with it: comments and moves pair
|
|
20481
|
-
* with records outside the cell, and captured markup is opaque.
|
|
20482
|
-
*
|
|
20483
|
-
* words go with the cell
|
|
20886
|
+
* with records outside the cell, and captured markup is opaque. Bookmarks
|
|
20887
|
+
* wholly in the cell, content controls and the review records of the cell's
|
|
20888
|
+
* own words go with the cell.
|
|
20484
20889
|
*/
|
|
20485
20890
|
const REACHING_TYPES = /* @__PURE__ */ new Set([
|
|
20486
20891
|
"commentRangeStart",
|
|
@@ -20650,7 +21055,7 @@ const trackTableRows = ({ document, op, rows, revision, newIds, kind, survivingC
|
|
|
20650
21055
|
reason: pendingParagraphMarkReason(reviewedFinalMark),
|
|
20651
21056
|
message: "A cell's final paragraph already carries a mark revision."
|
|
20652
21057
|
});
|
|
20653
|
-
if (missingFinalParagraph || rows.some((row) => row.
|
|
21058
|
+
if (missingFinalParagraph || rows.some((row) => row.cells.some((cell) => cell.structuralChange !== void 0 || (cell.propertyChanges?.length ?? 0) > 0 || !survivingCells.has(cell) && !trackableBlocks(cell.content)))) return refused$1({
|
|
20654
21059
|
op,
|
|
20655
21060
|
reason: DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE,
|
|
20656
21061
|
message: rows.some((row) => row.cells.some((cell) => holdsTable(cell.content))) ? "A suggestion cannot record a nested table that holds captured markup or review records." : "The rows contain an unsupported tracked structure."
|
|
@@ -20894,6 +21299,12 @@ const validStructure = (blocks) => blocks.every((block) => {
|
|
|
20894
21299
|
default: return block;
|
|
20895
21300
|
}
|
|
20896
21301
|
});
|
|
21302
|
+
/** Whether `shorter` is `longer` with some of its blocks left out, in order. */
|
|
21303
|
+
const isSubsequence = (shorter, longer) => {
|
|
21304
|
+
let index = 0;
|
|
21305
|
+
for (const block of longer) if (index < shorter.length && structurallyEqual(shorter[index], block)) index += 1;
|
|
21306
|
+
return index === shorter.length;
|
|
21307
|
+
};
|
|
20897
21308
|
const commitBlocks = ({ document, op, anchor, blocks }) => {
|
|
20898
21309
|
const body = storyBody$1(document, op.story);
|
|
20899
21310
|
const before = blockListAt(body.content, anchor.list);
|
|
@@ -20920,7 +21331,7 @@ const commitBlocks = ({ document, op, anchor, blocks }) => {
|
|
|
20920
21331
|
message: "A table has rows and cells; each cell and the story retain a final paragraph."
|
|
20921
21332
|
});
|
|
20922
21333
|
const fixedBlocks = (items) => items.filter((block) => block.type !== "table" && block.type !== "paragraph" && !isBlockBoundary(block));
|
|
20923
|
-
if (!structurallyEqual(fixedBlocks(before), fixedBlocks(blocks))) return refuse$4({
|
|
21334
|
+
if (!(op.type === DOCUMENT_OP_TYPES.SET_CONTAINER_BLOCKS ? isSubsequence(fixedBlocks(before), fixedBlocks(blocks)) || isSubsequence(fixedBlocks(blocks), fixedBlocks(before)) : structurallyEqual(fixedBlocks(before), fixedBlocks(blocks)))) return refuse$4({
|
|
20924
21335
|
op,
|
|
20925
21336
|
reason: DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE,
|
|
20926
21337
|
message: "A table structural inverse preserves surrounding block wrappers and markers."
|
|
@@ -21278,8 +21689,17 @@ const applyTableOp = (document, op) => {
|
|
|
21278
21689
|
message: "Removing a table requires a surviving paragraph in its block list."
|
|
21279
21690
|
});
|
|
21280
21691
|
const blocks = [...blockListAt(body.content, location.list)];
|
|
21281
|
-
if (op.revision === void 0)
|
|
21282
|
-
|
|
21692
|
+
if (op.revision === void 0) {
|
|
21693
|
+
blocks.splice(location.index, 1);
|
|
21694
|
+
const ends = rangeEndsReachingPast(location.table);
|
|
21695
|
+
const before = blocks[location.index - 1]?.type === "paragraph";
|
|
21696
|
+
const at = before ? location.index - 1 : blocks.findIndex((block, index) => index >= location.index && block.type === "paragraph");
|
|
21697
|
+
const host = blocks[at];
|
|
21698
|
+
if (ends.length > 0 && host?.type === "paragraph") blocks[at] = {
|
|
21699
|
+
...host,
|
|
21700
|
+
content: before ? [...host.content, ...ends] : [...ends, ...host.content]
|
|
21701
|
+
};
|
|
21702
|
+
} else {
|
|
21283
21703
|
if (location.table.preserved !== void 0 || location.table.bookmarks !== void 0 || location.table.carrierStack !== void 0 || (location.table.propertyChanges?.length ?? 0) > 0) return refuse$4({
|
|
21284
21704
|
op,
|
|
21285
21705
|
reason: DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE,
|
|
@@ -21594,7 +22014,11 @@ const withOmission = (row, side, value) => {
|
|
|
21594
22014
|
formatting
|
|
21595
22015
|
};
|
|
21596
22016
|
};
|
|
21597
|
-
|
|
22017
|
+
/** Captures and cells inside the same wrapper must move as one group. */
|
|
22018
|
+
const hasWrappedCellMarkup = (table) => {
|
|
22019
|
+
const wrapped = ({ contentControls, carrierStack }) => contentControls !== void 0 || carrierStack !== void 0;
|
|
22020
|
+
return table.rows.some((row) => row.preserved?.children !== void 0 && (row.preserved.children.some(wrapped) || row.cells.some(wrapped)));
|
|
22021
|
+
};
|
|
21598
22022
|
/** A cell holding one paragraph with nothing in it. */
|
|
21599
22023
|
const isEmptyCell = (cell) => cell.content.length === 1 && cell.content[0]?.type === "paragraph" && cell.content[0].content.length === 0;
|
|
21600
22024
|
const hasReview = (table) => table.formatting?.gridChange !== void 0 || table.propertyChanges !== void 0 || table.rows.some((row) => row.structuralChange !== void 0 || row.propertyChanges !== void 0 || row.cells.some((cell) => cell.structuralChange !== void 0 || cell.propertyChanges !== void 0));
|
|
@@ -22186,14 +22610,10 @@ const columnEdit = ({ document, op, table, grid }) => {
|
|
|
22186
22610
|
const insert = op.type === DOCUMENT_OP_TYPES.INSERT_COLUMN;
|
|
22187
22611
|
const count = op.type === DOCUMENT_OP_TYPES.INSERT_COLUMN ? op.count ?? 1 : 1;
|
|
22188
22612
|
if (!Number.isSafeInteger(count) || count < 1) return mismatch(op, "A column insertion inserts at least one column.");
|
|
22613
|
+
if (insert && count > 4096 - grid.width) return mismatch(op, `A table grid can hold at most ${MAX_TABLE_GRID_COLUMNS} columns.`);
|
|
22189
22614
|
if (!Number.isSafeInteger(op.column) || op.column < 0 || op.column >= grid.width + (insert ? 1 : 0)) return mismatch(op, "Column is outside the logical grid.");
|
|
22190
22615
|
if (!insert && grid.width === 1) return mismatch(op, "Deleting the final column requires deleting the table.");
|
|
22191
22616
|
if (insert && (!Number.isSafeInteger(op.width) || op.width <= 0)) return mismatch(op, "A column width must be a positive twip count.");
|
|
22192
|
-
if (hasStructuralMarkup(table)) return refuse$3({
|
|
22193
|
-
op,
|
|
22194
|
-
reason: DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE,
|
|
22195
|
-
message: "Indexed table markup must be relocated before changing columns."
|
|
22196
|
-
});
|
|
22197
22617
|
if (insert && op.revision !== void 0 && table.formatting?.gridChange !== void 0) return refuse$3({
|
|
22198
22618
|
op,
|
|
22199
22619
|
reason: DOCUMENT_OP_REFUSAL_REASONS.PENDING_GRID_CHANGE,
|
|
@@ -22234,7 +22654,7 @@ const columnEdit = ({ document, op, table, grid }) => {
|
|
|
22234
22654
|
count: boundaryRows * count
|
|
22235
22655
|
}) : Result.ok([]);
|
|
22236
22656
|
if (fresh.isErr()) return Result.err(fresh.error);
|
|
22237
|
-
const trackedDeletion =
|
|
22657
|
+
const trackedDeletion = suggestedDeletion && removedCells.length > 0;
|
|
22238
22658
|
const leavesRow = (rowIndex) => {
|
|
22239
22659
|
const { before, end } = rowExtent(table, grid, rowIndex);
|
|
22240
22660
|
if (trackedDeletion) return op.column < before || op.column >= end;
|
|
@@ -22254,11 +22674,6 @@ const columnEdit = ({ document, op, table, grid }) => {
|
|
|
22254
22674
|
stampedRows.set(rowIndex, rowStamps);
|
|
22255
22675
|
rowStamps += takesNewCells(rowIndex) ? count : 1;
|
|
22256
22676
|
}
|
|
22257
|
-
if (trackedDeletion && stampedRows.size === 0) return refuse$3({
|
|
22258
|
-
op,
|
|
22259
|
-
reason: DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE,
|
|
22260
|
-
message: "A suggested column deletion needs a cell in the column to mark."
|
|
22261
|
-
});
|
|
22262
22677
|
const stamps = stampsFor(op, trackedDeletion ? rowStamps : rowStamps + 2);
|
|
22263
22678
|
if (stamps.isErr()) return Result.err(stamps.error);
|
|
22264
22679
|
const rowStamp = (rowIndex, cell = 0) => {
|
|
@@ -22760,10 +23175,10 @@ const reviewedMergeContent = ({ document, op, changes, words }) => {
|
|
|
22760
23175
|
}
|
|
22761
23176
|
};
|
|
22762
23177
|
const merge = ({ document, op, table, grid }) => {
|
|
22763
|
-
if (
|
|
23178
|
+
if (hasWrappedCellMarkup(table)) return refuse$3({
|
|
22764
23179
|
op,
|
|
22765
23180
|
reason: DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE,
|
|
22766
|
-
message: "
|
|
23181
|
+
message: "Captures inside cell wrappers need a shared destination."
|
|
22767
23182
|
});
|
|
22768
23183
|
if (op.revision !== void 0 && hasReviewBlockingMerge({
|
|
22769
23184
|
table,
|
|
@@ -22948,10 +23363,10 @@ const split = ({ document, op, table, grid, location }) => {
|
|
|
22948
23363
|
const target = grid.rows[location.rowIndex]?.find((entry) => entry.index === location.cellIndex);
|
|
22949
23364
|
if (!target) return mismatch(op, "The addressed cell is absent.");
|
|
22950
23365
|
if (target.row !== target.ownerRow || target.index !== target.ownerIndex) return mismatch(op, "A vertical merge continuation must be addressed through its owner cell.");
|
|
22951
|
-
if (
|
|
23366
|
+
if (hasWrappedCellMarkup(table)) return refuse$3({
|
|
22952
23367
|
op,
|
|
22953
23368
|
reason: DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE,
|
|
22954
|
-
message: "
|
|
23369
|
+
message: "Captures inside cell wrappers need a shared destination."
|
|
22955
23370
|
});
|
|
22956
23371
|
if (op.revision !== void 0 && hasReview(table)) return refuse$3({
|
|
22957
23372
|
op,
|
|
@@ -23090,6 +23505,7 @@ const tableEditParagraphDemand = (location, op) => {
|
|
|
23090
23505
|
if (grid.isErr()) return Result.err(grid.error);
|
|
23091
23506
|
switch (op.type) {
|
|
23092
23507
|
case DOCUMENT_OP_TYPES.INSERT_COLUMN: {
|
|
23508
|
+
if ((op.count ?? 1) > 4096 - grid.value.width) return mismatch(op, `A table grid can hold at most ${MAX_TABLE_GRID_COLUMNS} columns.`);
|
|
23093
23509
|
const plans = recordsPlaceColumnsApart(table, grid.value) ? columnPlanAcrossRecords({
|
|
23094
23510
|
table,
|
|
23095
23511
|
grid: grid.value,
|
|
@@ -23334,11 +23750,6 @@ const applyTableEdit = (document, op) => {
|
|
|
23334
23750
|
reason: DOCUMENT_OP_REFUSAL_REASONS.PENDING_TABLE_CHANGE,
|
|
23335
23751
|
message: "Resolve the existing grid revision before resizing."
|
|
23336
23752
|
});
|
|
23337
|
-
if (op.revision !== void 0 && table.columnWidths === void 0) return refuse$3({
|
|
23338
|
-
op,
|
|
23339
|
-
reason: DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE,
|
|
23340
|
-
message: "A grid revision requires an explicit previous grid."
|
|
23341
|
-
});
|
|
23342
23753
|
if (table.propertyChanges !== void 0) return refuse$3({
|
|
23343
23754
|
op,
|
|
23344
23755
|
reason: DOCUMENT_OP_REFUSAL_REASONS.PENDING_TABLE_CHANGE,
|
|
@@ -23358,7 +23769,7 @@ const applyTableEdit = (document, op) => {
|
|
|
23358
23769
|
...table.formatting,
|
|
23359
23770
|
gridChange: {
|
|
23360
23771
|
id: gridStamp.id,
|
|
23361
|
-
columnWidths:
|
|
23772
|
+
columnWidths: table.columnWidths === void 0 ? Array.from({ length: grid.value.width }, () => void 0) : [...table.columnWidths]
|
|
23362
23773
|
}
|
|
23363
23774
|
};
|
|
23364
23775
|
next.propertyChanges = [{
|
|
@@ -23429,12 +23840,6 @@ const paragraphsIn$1 = (rows) => storyParagraphs({ content: [{
|
|
|
23429
23840
|
type: "table",
|
|
23430
23841
|
rows: [...rows]
|
|
23431
23842
|
}] }).map(({ paragraph }) => paragraph);
|
|
23432
|
-
/**
|
|
23433
|
-
* Indexed markup and shared row wrappers need a structural table operation.
|
|
23434
|
-
* Bookmark markers beside the rows move with them
|
|
23435
|
-
* ({@link relocatePositionedMarkers}).
|
|
23436
|
-
*/
|
|
23437
|
-
const needsTableEdit = (table) => table.preserved !== void 0 || table.carrierStack !== void 0 || table.rows.some((row) => row.contentControls !== void 0 || row.carrierStack !== void 0);
|
|
23438
23843
|
const withTable = ({ document, story, location, table }) => {
|
|
23439
23844
|
const body = storyBody$1(document, story);
|
|
23440
23845
|
const content = updateBlockList(body.content, location.list, (blocks) => {
|
|
@@ -23475,10 +23880,10 @@ const commitRows = ({ document, op, location, rows }) => {
|
|
|
23475
23880
|
reason: DOCUMENT_OP_REFUSAL_REASONS.STRUCTURE_MISMATCH,
|
|
23476
23881
|
message: "Every row has cells, and every cell has a paragraph."
|
|
23477
23882
|
});
|
|
23478
|
-
if (op.type
|
|
23883
|
+
if (op.type !== DOCUMENT_OP_TYPES.SET_TABLE_ROWS && removalOrphansAMerge(location.table, rows)) return refused({
|
|
23479
23884
|
op,
|
|
23480
23885
|
reason: DOCUMENT_OP_REFUSAL_REASONS.STRUCTURE_MISMATCH,
|
|
23481
|
-
message: "A
|
|
23886
|
+
message: "A row edit keeps every vertical merge under the cell that starts it."
|
|
23482
23887
|
});
|
|
23483
23888
|
if (afterParagraphs.some(({ content }) => textsIn(content).some(hasIllegalXmlCharacters))) return refused({
|
|
23484
23889
|
op,
|
|
@@ -23515,18 +23920,18 @@ const commitRows = ({ document, op, location, rows }) => {
|
|
|
23515
23920
|
reason: DOCUMENT_OP_REFUSAL_REASONS.ID_COLLISION,
|
|
23516
23921
|
message: "A row paragraph id is already used in the package."
|
|
23517
23922
|
});
|
|
23923
|
+
const table = relocatePositionedMarkers(location.table, {
|
|
23924
|
+
...location.table,
|
|
23925
|
+
rows
|
|
23926
|
+
});
|
|
23518
23927
|
const remainingRecords = countKeys(packageIdentityKeys(document.package));
|
|
23519
|
-
for (const key of identityKeysIn(
|
|
23520
|
-
const incomingRecords = identityKeysIn(
|
|
23928
|
+
for (const key of identityKeysIn(location.table)) remainingRecords.set(key, (remainingRecords.get(key) ?? 1) - 1);
|
|
23929
|
+
const incomingRecords = identityKeysIn(table);
|
|
23521
23930
|
if (incomingRecords.some((key) => (remainingRecords.get(key) ?? 0) > 0) || new Set(incomingRecords).size !== incomingRecords.length) return refused({
|
|
23522
23931
|
op,
|
|
23523
23932
|
reason: DOCUMENT_OP_REFUSAL_REASONS.ID_COLLISION,
|
|
23524
23933
|
message: "A row revision or content-control id is already used in the package."
|
|
23525
23934
|
});
|
|
23526
|
-
const table = relocatePositionedMarkers(location.table, {
|
|
23527
|
-
...location.table,
|
|
23528
|
-
rows
|
|
23529
|
-
});
|
|
23530
23935
|
const next = withTable({
|
|
23531
23936
|
document,
|
|
23532
23937
|
story: op.story,
|
|
@@ -23551,7 +23956,7 @@ const commitRows = ({ document, op, location, rows }) => {
|
|
|
23551
23956
|
});
|
|
23552
23957
|
return Result.ok({
|
|
23553
23958
|
document: next,
|
|
23554
|
-
inverse: [
|
|
23959
|
+
inverse: [holdsPositionedMarkup(location.table) ? {
|
|
23555
23960
|
type: DOCUMENT_OP_TYPES.SET_TABLE,
|
|
23556
23961
|
story: op.story,
|
|
23557
23962
|
blockId: anchor,
|
|
@@ -23561,7 +23966,7 @@ const commitRows = ({ document, op, location, rows }) => {
|
|
|
23561
23966
|
type: DOCUMENT_OP_TYPES.SET_TABLE_ROWS,
|
|
23562
23967
|
story: op.story,
|
|
23563
23968
|
blockId: anchor,
|
|
23564
|
-
expected: rows,
|
|
23969
|
+
expected: table.rows,
|
|
23565
23970
|
rows: before
|
|
23566
23971
|
}],
|
|
23567
23972
|
touched: {
|
|
@@ -23586,11 +23991,6 @@ const applyRowOp = (document, op) => {
|
|
|
23586
23991
|
reason: DOCUMENT_OP_REFUSAL_REASONS.INVALID_OFFSET,
|
|
23587
23992
|
message: "The row index is outside the table."
|
|
23588
23993
|
});
|
|
23589
|
-
if (needsTableEdit(location.table)) return refused({
|
|
23590
|
-
op,
|
|
23591
|
-
reason: DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE,
|
|
23592
|
-
message: "Indexed table markup or shared row wrappers require a table operation."
|
|
23593
|
-
});
|
|
23594
23994
|
const incoming = cloneModel(op.row);
|
|
23595
23995
|
if (paragraphIdsIn(incoming).some((id) => paragraphIdsIn(before).some((existing) => idKey(existing) === idKey(id)))) return refused({
|
|
23596
23996
|
op,
|
|
@@ -23607,12 +24007,11 @@ const applyRowOp = (document, op) => {
|
|
|
23607
24007
|
});
|
|
23608
24008
|
if (tracked.isErr()) return Result.err(tracked.error);
|
|
23609
24009
|
const row = tracked.value.at(0) ?? panic("A tracked insertion lost its row.");
|
|
23610
|
-
rows.splice(op.at, 0, row);
|
|
23611
24010
|
return commitRows({
|
|
23612
24011
|
document,
|
|
23613
24012
|
op,
|
|
23614
24013
|
location,
|
|
23615
|
-
rows
|
|
24014
|
+
rows: rowsWithRow(rows, op.at, row)
|
|
23616
24015
|
});
|
|
23617
24016
|
}
|
|
23618
24017
|
case DOCUMENT_OP_TYPES.DELETE_ROW: {
|
|
@@ -23630,11 +24029,6 @@ const applyRowOp = (document, op) => {
|
|
|
23630
24029
|
location,
|
|
23631
24030
|
rows: []
|
|
23632
24031
|
});
|
|
23633
|
-
if (needsTableEdit(location.table)) return refused({
|
|
23634
|
-
op,
|
|
23635
|
-
reason: DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE,
|
|
23636
|
-
message: "Indexed table markup or shared row wrappers require a table operation."
|
|
23637
|
-
});
|
|
23638
24032
|
if (removesOutright || op.revision === void 0) return commitRows({
|
|
23639
24033
|
document,
|
|
23640
24034
|
op,
|
|
@@ -23665,11 +24059,6 @@ const applyRowOp = (document, op) => {
|
|
|
23665
24059
|
reason: DOCUMENT_OP_REFUSAL_REASONS.STALE,
|
|
23666
24060
|
message: "The table rows have changed."
|
|
23667
24061
|
});
|
|
23668
|
-
if (op.rows.length > 0 && op.rows.length !== before.length && needsTableEdit(location.table)) return refused({
|
|
23669
|
-
op,
|
|
23670
|
-
reason: DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE,
|
|
23671
|
-
message: "Indexed table markup or shared row wrappers require a table operation."
|
|
23672
|
-
});
|
|
23673
24062
|
const replacement = op.rows.map((row) => before.find((existing) => structurallyEqual(existing, row)) ?? cloneModel(row));
|
|
23674
24063
|
return commitRows({
|
|
23675
24064
|
document,
|
|
@@ -25182,7 +25571,12 @@ const dispatchCore = ({ document, op, purpose }) => {
|
|
|
25182
25571
|
case DOCUMENT_OP_TYPES.REPLACE_BLOCKS: return replaceBlocks(document, op);
|
|
25183
25572
|
case DOCUMENT_OP_TYPES.SET_PARAGRAPH_REVIEW:
|
|
25184
25573
|
case DOCUMENT_OP_TYPES.REPLACE_INLINE: return applyParagraphPrimitive(document, op);
|
|
25185
|
-
case DOCUMENT_OP_TYPES.RESOLVE_REVISION: return resolveRevision(
|
|
25574
|
+
case DOCUMENT_OP_TYPES.RESOLVE_REVISION: return resolveRevision({
|
|
25575
|
+
document,
|
|
25576
|
+
op,
|
|
25577
|
+
applyOps,
|
|
25578
|
+
purpose
|
|
25579
|
+
});
|
|
25186
25580
|
case DOCUMENT_OP_TYPES.SET_REVISION_INFO: return setRevisionInfo(document, op);
|
|
25187
25581
|
case DOCUMENT_OP_TYPES.DELETE_TABLE: {
|
|
25188
25582
|
const pending = ownPendingTableInsertion(document, op);
|
|
@@ -25544,7 +25938,7 @@ const applyAddressedOp = ({ document, op, purpose, boxes }) => {
|
|
|
25544
25938
|
}
|
|
25545
25939
|
}
|
|
25546
25940
|
if (hasMultipleParagraphPropertyChanges(edit.document, boxes)) return Result.err(refusal$2(op, DOCUMENT_OP_REFUSAL_REASONS.STRUCTURE_MISMATCH, "A paragraph cannot carry more than one property change."));
|
|
25547
|
-
if (purpose
|
|
25941
|
+
if (purpose !== "inspect-inverse" && gainsSectionInTableCell(document, edit.document)) return Result.err(refusal$2(op, DOCUMENT_OP_REFUSAL_REASONS.SECTION_BOUNDARY, "A section cannot end inside a table cell."));
|
|
25548
25942
|
const repeatedId = repeatedParagraphId(edit.document);
|
|
25549
25943
|
if (repeatedId !== void 0) return Result.err(refusal$2(op, repeatedId.reason, repeatedId.message));
|
|
25550
25944
|
meetsContract(edit.document);
|
|
@@ -25656,6 +26050,12 @@ const applyDocumentOps = (document, ops) => applyDocumentOpsForPurpose({
|
|
|
25656
26050
|
ops,
|
|
25657
26051
|
purpose: "apply"
|
|
25658
26052
|
});
|
|
26053
|
+
/** Resolve revisions for a markup view through the same operation engine. */
|
|
26054
|
+
const applyMarkupViewOps = (document, ops) => applyDocumentOpsForPurpose({
|
|
26055
|
+
document,
|
|
26056
|
+
ops,
|
|
26057
|
+
purpose: "markup-view"
|
|
26058
|
+
});
|
|
25659
26059
|
/**
|
|
25660
26060
|
* Apply operations to read what they leave, as a rebase takes back a pending
|
|
25661
26061
|
* edit by its recorded inverse: an inverse that as an operation of its own
|
|
@@ -25733,20 +26133,28 @@ const withoutPendingSuggestions = (document, { commentIds, onAbsorptions } = {})
|
|
|
25733
26133
|
for (const { story, absorbed } of receipts) onAbsorptions?.(story, absorbed);
|
|
25734
26134
|
return Result.ok(current);
|
|
25735
26135
|
};
|
|
25736
|
-
|
|
25737
|
-
|
|
25738
|
-
|
|
25739
|
-
|
|
26136
|
+
const visitStorySuggestionRevisions = (body, visit) => {
|
|
26137
|
+
visitSuggestionRevisions(body.content, (info) => visit(info, info.suggestionId));
|
|
26138
|
+
for (const { info } of body.finalSectionProperties?.propertyChanges ?? []) if (info.suggestionId !== void 0) visit(info, info.suggestionId);
|
|
26139
|
+
};
|
|
26140
|
+
/** Revisions of one pending suggestion, one info per ID in document order. */
|
|
25740
26141
|
const suggestionRevisionInfos = (document, story, suggestionId) => {
|
|
25741
26142
|
const out = /* @__PURE__ */ new Map();
|
|
25742
|
-
|
|
25743
|
-
|
|
25744
|
-
|
|
25745
|
-
};
|
|
25746
|
-
visitSuggestionRevisions(body.content, add);
|
|
25747
|
-
for (const { info } of body.finalSectionProperties?.propertyChanges ?? []) add(info);
|
|
26143
|
+
visitStorySuggestionRevisions(storyBody$1(document, story), (info, owner) => {
|
|
26144
|
+
if (owner === suggestionId && !out.has(info.id)) out.set(info.id, info);
|
|
26145
|
+
});
|
|
25748
26146
|
return [...out.values()];
|
|
25749
26147
|
};
|
|
26148
|
+
/** The first proposal owning each physical revision ID in this story. */
|
|
26149
|
+
const suggestionOwnersInStory = (document, story) => {
|
|
26150
|
+
const owners = /* @__PURE__ */ new Map();
|
|
26151
|
+
const body = findStoryBody$1(document, story);
|
|
26152
|
+
if (body === void 0) return owners;
|
|
26153
|
+
visitStorySuggestionRevisions(body, ({ id }, suggestionId) => {
|
|
26154
|
+
if (!owners.has(id)) owners.set(id, suggestionId);
|
|
26155
|
+
});
|
|
26156
|
+
return owners;
|
|
26157
|
+
};
|
|
25750
26158
|
/**
|
|
25751
26159
|
* The ids of every pending suggestion in a document, in every story, and of
|
|
25752
26160
|
* every suggestion that proposes a comment.
|
|
@@ -25754,11 +26162,7 @@ const suggestionRevisionInfos = (document, story, suggestionId) => {
|
|
|
25754
26162
|
const pendingSuggestionIdsIn = (document) => {
|
|
25755
26163
|
const out = /* @__PURE__ */ new Set();
|
|
25756
26164
|
for (const comment of document.package.document.comments ?? []) if (comment.suggestionId !== void 0) out.add(comment.suggestionId);
|
|
25757
|
-
for (const story of documentStories(document))
|
|
25758
|
-
const body = storyBody$1(document, story);
|
|
25759
|
-
visitSuggestionRevisions(body.content, ({ suggestionId }) => out.add(suggestionId));
|
|
25760
|
-
for (const { info } of body.finalSectionProperties?.propertyChanges ?? []) if (info.suggestionId !== void 0) out.add(info.suggestionId);
|
|
25761
|
-
}
|
|
26165
|
+
for (const story of documentStories(document)) visitStorySuggestionRevisions(storyBody$1(document, story), (_info, suggestionId) => out.add(suggestionId));
|
|
25762
26166
|
return out;
|
|
25763
26167
|
};
|
|
25764
26168
|
// src/ops/compoundIntent.ts
|
|
@@ -27644,6 +28048,67 @@ const compileHyperlinkIntent = (document, { intent: sourceIntent, mode, compileI
|
|
|
27644
28048
|
selection: intent.to
|
|
27645
28049
|
});
|
|
27646
28050
|
};
|
|
28051
|
+
// src/ops/pastedBlocks.ts
|
|
28052
|
+
/**
|
|
28053
|
+
* `block` with every paragraph it holds, at any depth, as `paragraph` gives
|
|
28054
|
+
* it, visited in document order: a table's cells and a container's blocks
|
|
28055
|
+
* are descended into, and every other block is kept.
|
|
28056
|
+
*/
|
|
28057
|
+
const mapBlockParagraphs = (block, paragraph) => {
|
|
28058
|
+
switch (block.type) {
|
|
28059
|
+
case "paragraph": return paragraph(block);
|
|
28060
|
+
case "table": return {
|
|
28061
|
+
...block,
|
|
28062
|
+
rows: block.rows.map((row) => ({
|
|
28063
|
+
...row,
|
|
28064
|
+
cells: row.cells.map((cell) => ({
|
|
28065
|
+
...cell,
|
|
28066
|
+
content: cell.content.map((inner) => mapBlockParagraphs(inner, paragraph))
|
|
28067
|
+
}))
|
|
28068
|
+
}))
|
|
28069
|
+
};
|
|
28070
|
+
case "blockSdt":
|
|
28071
|
+
case "blockCustomXml": return {
|
|
28072
|
+
...block,
|
|
28073
|
+
content: block.content.map((inner) => mapBlockParagraphs(inner, paragraph))
|
|
28074
|
+
};
|
|
28075
|
+
default: return block;
|
|
28076
|
+
}
|
|
28077
|
+
};
|
|
28078
|
+
/** {@link mapBlockParagraphs} of a pasted block, which stays the kind it was. */
|
|
28079
|
+
const mapPastedBlockParagraphs = (block, paragraph) => {
|
|
28080
|
+
switch (block.type) {
|
|
28081
|
+
case "paragraph": return paragraph(block);
|
|
28082
|
+
case "table": return {
|
|
28083
|
+
...block,
|
|
28084
|
+
rows: block.rows.map((row) => ({
|
|
28085
|
+
...row,
|
|
28086
|
+
cells: row.cells.map((cell) => ({
|
|
28087
|
+
...cell,
|
|
28088
|
+
content: cell.content.map((inner) => mapBlockParagraphs(inner, paragraph))
|
|
28089
|
+
}))
|
|
28090
|
+
}))
|
|
28091
|
+
};
|
|
28092
|
+
case "blockSdt":
|
|
28093
|
+
case "blockCustomXml": return {
|
|
28094
|
+
...block,
|
|
28095
|
+
content: block.content.map((inner) => mapBlockParagraphs(inner, paragraph))
|
|
28096
|
+
};
|
|
28097
|
+
case "preservedBlock": return block;
|
|
28098
|
+
default: return block;
|
|
28099
|
+
}
|
|
28100
|
+
};
|
|
28101
|
+
/** Whether `block` is one a paste places. */
|
|
28102
|
+
const isPastedBlock = (block) => block.type === "paragraph" || block.type === "table" || block.type === "blockSdt" || block.type === "blockCustomXml" || block.type === "preservedBlock";
|
|
28103
|
+
/** Every paragraph `block` holds, at any depth, in document order. */
|
|
28104
|
+
const blockParagraphsOf = (block) => {
|
|
28105
|
+
const paragraphs = [];
|
|
28106
|
+
mapBlockParagraphs(block, (paragraph) => {
|
|
28107
|
+
paragraphs.push(paragraph);
|
|
28108
|
+
return paragraph;
|
|
28109
|
+
});
|
|
28110
|
+
return paragraphs;
|
|
28111
|
+
};
|
|
27647
28112
|
// src/ops/pasteAnchors.ts
|
|
27648
28113
|
const PLACEHOLDER_STEM = "_folioPasteAnchor";
|
|
27649
28114
|
/** Where placeholder ids start; an id a bookmark already holds is skipped. */
|
|
@@ -27759,20 +28224,10 @@ const withPasteAnchors = (blocks, destination = {
|
|
|
27759
28224
|
}
|
|
27760
28225
|
return out;
|
|
27761
28226
|
};
|
|
27762
|
-
const
|
|
27763
|
-
...
|
|
27764
|
-
content: inline(
|
|
27765
|
-
}
|
|
27766
|
-
...each,
|
|
27767
|
-
rows: each.rows.map((row) => ({
|
|
27768
|
-
...row,
|
|
27769
|
-
cells: row.cells.map((cell) => ({
|
|
27770
|
-
...cell,
|
|
27771
|
-
content: cell.content.map((inner) => inner.type === "paragraph" || inner.type === "table" ? block(inner) : inner)
|
|
27772
|
-
}))
|
|
27773
|
-
}))
|
|
27774
|
-
};
|
|
27775
|
-
const anchoredBlocks = blocks.map(block);
|
|
28227
|
+
const anchoredBlocks = blocks.map((each) => mapPastedBlockParagraphs(each, (paragraph) => ({
|
|
28228
|
+
...paragraph,
|
|
28229
|
+
content: inline(paragraph.content)
|
|
28230
|
+
})));
|
|
27776
28231
|
return {
|
|
27777
28232
|
prefix,
|
|
27778
28233
|
ids,
|
|
@@ -27854,6 +28309,27 @@ const placedPasteAnchors = ({ paragraphs, prefix, count }) => {
|
|
|
27854
28309
|
/** Tracked replacement fragments share deletion's validation and physical-id pool. */
|
|
27855
28310
|
const rangeParagraph = (body, blockId) => blockId === "" ? storyParagraphs(body).find(({ paragraph }) => (paragraph.paraId ?? "") === "") : findStoryParagraph(body, blockId);
|
|
27856
28311
|
/**
|
|
28312
|
+
* Where a text replacement leaves the comment anchors it reaches. The direct
|
|
28313
|
+
* edit and the accepted suggestion give the same answer, so a comment's fate
|
|
28314
|
+
* never depends on the mode:
|
|
28315
|
+
*
|
|
28316
|
+
* - A comment marker (range start, range end or reference) inside the
|
|
28317
|
+
* replaced stretch is not deleted with the words. It stays, in its order,
|
|
28318
|
+
* and the new words follow it (this gap). A comment straddling an edge
|
|
28319
|
+
* keeps its outer marker: one ending inside now ends where the new words
|
|
28320
|
+
* start, one starting inside now covers the new words and the rest of its
|
|
28321
|
+
* own.
|
|
28322
|
+
* - A ranged comment whose every word went has nothing left to cover, and
|
|
28323
|
+
* its thread goes, replies included, directly and once the suggestion is
|
|
28324
|
+
* accepted (`newlyExhaustedCommentIds`). A point comment, or a range that
|
|
28325
|
+
* covered nothing before, keeps its thread and stands where the new words
|
|
28326
|
+
* start.
|
|
28327
|
+
* - Tracked, the struck words keep every marker among them
|
|
28328
|
+
* (`replacementDeletionSegments` ends a stretch at each), so rejecting
|
|
28329
|
+
* restores each anchor exactly and accepting leaves the direct result.
|
|
28330
|
+
* - A replacement across paragraphs joins them: the markers of every
|
|
28331
|
+
* paragraph it reaches gather, in order, before the new words.
|
|
28332
|
+
*
|
|
27857
28333
|
* The gap just after a range deletion, where what replaces the range goes:
|
|
27858
28334
|
* after the struck content in a redline, and after whatever a deletion keeps
|
|
27859
28335
|
* in place, so that accepting a tracked replacement gives the direct one.
|
|
@@ -28385,6 +28861,7 @@ const intentEndpoints = (intent) => {
|
|
|
28385
28861
|
case "replaceFragment":
|
|
28386
28862
|
case "pasteBlocks":
|
|
28387
28863
|
case "moveFragment":
|
|
28864
|
+
case "moveBlocks":
|
|
28388
28865
|
case "replaceText":
|
|
28389
28866
|
case "insertAtom":
|
|
28390
28867
|
case "formatRun": return {
|
|
@@ -28515,10 +28992,11 @@ const createEditorIntentIdAllocator = ({ reservedBlockIds } = {}) => {
|
|
|
28515
28992
|
for (const span of leafSpans(paragraph.content)) demand += 4 * (1 + span.ancestors.length);
|
|
28516
28993
|
}
|
|
28517
28994
|
if (incoming.length > 0) demand += 8;
|
|
28518
|
-
if (intent.type === "pasteBlocks") {
|
|
28995
|
+
if (intent.type === "pasteBlocks" || intent.type === "moveBlocks") {
|
|
28519
28996
|
demand += 11;
|
|
28520
28997
|
for (const block of intent.blocks) {
|
|
28521
|
-
|
|
28998
|
+
if (intent.type === "moveBlocks" && block.type === "table") demand += 2 + block.rows.length;
|
|
28999
|
+
const paragraphs = blockParagraphs(block);
|
|
28522
29000
|
if (block.type === "table") demand += 2 + block.rows.length;
|
|
28523
29001
|
for (const paragraph of paragraphs) {
|
|
28524
29002
|
demand += PARAGRAPH_REVISION_DEMAND;
|
|
@@ -28530,7 +29008,7 @@ const createEditorIntentIdAllocator = ({ reservedBlockIds } = {}) => {
|
|
|
28530
29008
|
demand += 4;
|
|
28531
29009
|
continue;
|
|
28532
29010
|
}
|
|
28533
|
-
const note = intent.annotations?.notes.find(({ type, id }) => type === anchor.note && id === anchor.id);
|
|
29011
|
+
const note = (intent.type === "pasteBlocks" ? intent.annotations : void 0)?.notes.find(({ type, id }) => type === anchor.note && id === anchor.id);
|
|
28534
29012
|
demand += 4;
|
|
28535
29013
|
for (const block of note?.content ?? []) {
|
|
28536
29014
|
if (block.type !== "paragraph") continue;
|
|
@@ -28541,7 +29019,7 @@ const createEditorIntentIdAllocator = ({ reservedBlockIds } = {}) => {
|
|
|
28541
29019
|
}
|
|
28542
29020
|
if (intent.type === "setHyperlink" || intent.type === "removeHyperlink" || intent.type === "insertHyperlink") demand = 2 * demand + 8;
|
|
28543
29021
|
if (intent.type === "generateTOC") demand += 8 + (intent.headings.length + 1) * (PARAGRAPH_REVISION_DEMAND + 4 * leafRevisionDemand(3));
|
|
28544
|
-
if (intent.type === "moveFragment") {
|
|
29022
|
+
if (intent.type === "moveFragment" || intent.type === "moveBlocks") {
|
|
28545
29023
|
const target = storyParagraphs(storyBody$1(document, intent.target.story)).find(({ paragraph }) => idKey(paragraph.paraId ?? "") === idKey(intent.target.blockId));
|
|
28546
29024
|
if (target !== void 0) {
|
|
28547
29025
|
demand += 3;
|
|
@@ -28836,12 +29314,53 @@ const bookmarkIdsIn = (items) => items.flatMap((item) => {
|
|
|
28836
29314
|
});
|
|
28837
29315
|
/** Whether a pasted table, or one nested in it, holds bookmarks or records of its own. */
|
|
28838
29316
|
const holdsTableLevelIdentities = (block) => {
|
|
29317
|
+
if (block.type === "blockSdt" || block.type === "blockCustomXml") return block.content.some(holdsTableLevelIdentities);
|
|
28839
29318
|
if (block.type !== "table") return false;
|
|
28840
29319
|
if ((block.bookmarks?.length ?? 0) > 0 || (block.propertyChanges?.length ?? 0) > 0 || (block.carrierStack?.length ?? 0) > 0) return true;
|
|
28841
|
-
return block.rows.some((row) => (row.bookmarks?.length ?? 0) > 0 || (row.propertyChanges?.length ?? 0) > 0 || (row.carrierStack?.length ?? 0) > 0 || row.cells.some((cell) => (cell.propertyChanges?.length ?? 0) > 0 || (cell.carrierStack?.length ?? 0) > 0 || cell.content.some(
|
|
29320
|
+
return block.rows.some((row) => (row.bookmarks?.length ?? 0) > 0 || (row.propertyChanges?.length ?? 0) > 0 || (row.carrierStack?.length ?? 0) > 0 || row.cells.some((cell) => (cell.propertyChanges?.length ?? 0) > 0 || (cell.carrierStack?.length ?? 0) > 0 || cell.content.some(holdsTableLevelIdentities)));
|
|
28842
29321
|
};
|
|
28843
|
-
/**
|
|
28844
|
-
|
|
29322
|
+
/**
|
|
29323
|
+
* A pasted block's paragraphs in document order, a table's cells' and a
|
|
29324
|
+
* container's among them.
|
|
29325
|
+
*/
|
|
29326
|
+
const blockParagraphs = (block) => blockParagraphsOf(block);
|
|
29327
|
+
/** The properties of every block content control `blocks` hold, at any depth. */
|
|
29328
|
+
const blockControlsOf = (blocks) => blocks.flatMap((block) => {
|
|
29329
|
+
switch (block.type) {
|
|
29330
|
+
case "blockSdt": return [block.properties, ...blockControlsOf(block.content)];
|
|
29331
|
+
case "blockCustomXml": return blockControlsOf(block.content);
|
|
29332
|
+
case "table": return block.rows.flatMap((row) => row.cells.flatMap((cell) => blockControlsOf(cell.content)));
|
|
29333
|
+
default: return [];
|
|
29334
|
+
}
|
|
29335
|
+
});
|
|
29336
|
+
/** `blocks` with their block content controls' properties, in order, from `controls`. */
|
|
29337
|
+
const withBlockControls = (blocks, controls) => blocks.map((block) => {
|
|
29338
|
+
switch (block.type) {
|
|
29339
|
+
case "blockSdt": {
|
|
29340
|
+
const properties = controls.shift() ?? panic("An identified control is missing.");
|
|
29341
|
+
return {
|
|
29342
|
+
...block,
|
|
29343
|
+
properties,
|
|
29344
|
+
content: withBlockControls(block.content, controls)
|
|
29345
|
+
};
|
|
29346
|
+
}
|
|
29347
|
+
case "blockCustomXml": return {
|
|
29348
|
+
...block,
|
|
29349
|
+
content: withBlockControls(block.content, controls)
|
|
29350
|
+
};
|
|
29351
|
+
case "table": return {
|
|
29352
|
+
...block,
|
|
29353
|
+
rows: block.rows.map((row) => ({
|
|
29354
|
+
...row,
|
|
29355
|
+
cells: row.cells.map((cell) => ({
|
|
29356
|
+
...cell,
|
|
29357
|
+
content: withBlockControls(cell.content, controls)
|
|
29358
|
+
}))
|
|
29359
|
+
}))
|
|
29360
|
+
};
|
|
29361
|
+
default: return block;
|
|
29362
|
+
}
|
|
29363
|
+
});
|
|
28845
29364
|
/**
|
|
28846
29365
|
* Clipboard blocks placed: once with their placeholders, to find where each
|
|
28847
29366
|
* lands, and once without, for the operations and the document they leave.
|
|
@@ -28934,10 +29453,10 @@ const placeAnchoredBlocks = (document, { intent, plain, prefix, ids, count, mode
|
|
|
28934
29453
|
* latest place first so that no copy moves the place of another. A comment
|
|
28935
29454
|
* whose range the clipboard holds only part of is copied as a point.
|
|
28936
29455
|
*/
|
|
28937
|
-
const compileBlockPaste = (document, { intent, mode, firstBlockId }) => {
|
|
29456
|
+
const compileBlockPaste = (document, { intent, mode, firstBlockId, moved }) => {
|
|
28938
29457
|
const { annotations, ...placement } = intent;
|
|
28939
29458
|
const anchored = withPasteAnchors(intent.blocks, bookmarksIn(document.package));
|
|
28940
|
-
if (anchored.anchors.length === 0) return compileBlockPlacement(document, {
|
|
29459
|
+
if (anchored.anchors.length === 0 || moved === true) return compileBlockPlacement(document, {
|
|
28941
29460
|
intent: placement,
|
|
28942
29461
|
mode,
|
|
28943
29462
|
firstBlockId
|
|
@@ -29150,10 +29669,76 @@ const compileBlockPaste = (document, { intent, mode, firstBlockId }) => {
|
|
|
29150
29669
|
});
|
|
29151
29670
|
};
|
|
29152
29671
|
/**
|
|
29153
|
-
*
|
|
29154
|
-
*
|
|
29155
|
-
*
|
|
29672
|
+
* A block content control, custom XML element or kept block markup put in
|
|
29673
|
+
* before `anchor`, in the block list holding it, as its exact list. Neither
|
|
29674
|
+
* has a tracked record of its own: Word records a control's insertion on the
|
|
29675
|
+
* runs inside it, and kept markup is not read, so a suggestion refuses.
|
|
29156
29676
|
*/
|
|
29677
|
+
const placeContainerBlock = ({ document, story, anchor, block, mode }) => {
|
|
29678
|
+
if (mode.type === "suggesting") return Result.err(new DocumentOpRefusal({
|
|
29679
|
+
reason: DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE,
|
|
29680
|
+
message: "A suggested paste cannot record a block content control, custom XML element or kept block markup.",
|
|
29681
|
+
opType: DOCUMENT_OP_TYPES.SET_CONTAINER_BLOCKS
|
|
29682
|
+
}));
|
|
29683
|
+
const body = storyBody$1(document, story);
|
|
29684
|
+
const located = storyParagraphs(body).find(({ paragraph }) => idKey(paragraph.paraId ?? "") === idKey(anchor));
|
|
29685
|
+
if (located === void 0) return Result.err(new DocumentOpRefusal({
|
|
29686
|
+
reason: DOCUMENT_OP_REFUSAL_REASONS.BLOCK_NOT_FOUND,
|
|
29687
|
+
message: "The clipboard destination paragraph does not exist.",
|
|
29688
|
+
opType: DOCUMENT_OP_TYPES.SET_CONTAINER_BLOCKS
|
|
29689
|
+
}));
|
|
29690
|
+
const expected = blockListAt(body.content, located.list);
|
|
29691
|
+
const op = {
|
|
29692
|
+
type: DOCUMENT_OP_TYPES.SET_CONTAINER_BLOCKS,
|
|
29693
|
+
story,
|
|
29694
|
+
blockId: anchor,
|
|
29695
|
+
expected,
|
|
29696
|
+
blocks: [
|
|
29697
|
+
...expected.slice(0, located.index),
|
|
29698
|
+
block,
|
|
29699
|
+
...expected.slice(located.index)
|
|
29700
|
+
]
|
|
29701
|
+
};
|
|
29702
|
+
const applied = applyDocumentOps(document, [op]);
|
|
29703
|
+
if (applied.isErr()) return Result.err(applied.error);
|
|
29704
|
+
return Result.ok({
|
|
29705
|
+
op,
|
|
29706
|
+
document: applied.value.document
|
|
29707
|
+
});
|
|
29708
|
+
};
|
|
29709
|
+
/**
|
|
29710
|
+
* A block content control, custom XML element or kept block markup taken out
|
|
29711
|
+
* of the block list holding `anchor`, as its exact list; a suggestion has no
|
|
29712
|
+
* record for it and refuses.
|
|
29713
|
+
*/
|
|
29714
|
+
const removeContainerBlock = ({ document, story, anchor, block, mode }) => {
|
|
29715
|
+
const refuse = (reason, message) => Result.err(new DocumentOpRefusal({
|
|
29716
|
+
reason,
|
|
29717
|
+
message,
|
|
29718
|
+
opType: DOCUMENT_OP_TYPES.SET_CONTAINER_BLOCKS
|
|
29719
|
+
}));
|
|
29720
|
+
if (mode.type === "suggesting") return refuse(DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE, "A suggested move cannot record a block content control, custom XML element or kept block markup.");
|
|
29721
|
+
const body = storyBody$1(document, story);
|
|
29722
|
+
const located = storyParagraphs(body).find(({ paragraph }) => idKey(paragraph.paraId ?? "") === idKey(anchor));
|
|
29723
|
+
if (located === void 0) return refuse(DOCUMENT_OP_REFUSAL_REASONS.BLOCK_NOT_FOUND, "The moved range names a paragraph the story does not hold.");
|
|
29724
|
+
const expected = blockListAt(body.content, located.list);
|
|
29725
|
+
const index = expected.indexOf(block);
|
|
29726
|
+
if (index < 0) return refuse(DOCUMENT_OP_REFUSAL_REASONS.STALE, "The moved block is no longer where the range found it.");
|
|
29727
|
+
const op = {
|
|
29728
|
+
type: DOCUMENT_OP_TYPES.SET_CONTAINER_BLOCKS,
|
|
29729
|
+
story,
|
|
29730
|
+
blockId: anchor,
|
|
29731
|
+
expected,
|
|
29732
|
+
blocks: [...expected.slice(0, index), ...expected.slice(index + 1)]
|
|
29733
|
+
};
|
|
29734
|
+
const applied = applyDocumentOps(document, [op]);
|
|
29735
|
+
if (applied.isErr()) return Result.err(applied.error);
|
|
29736
|
+
return Result.ok({
|
|
29737
|
+
op,
|
|
29738
|
+
document: applied.value.document,
|
|
29739
|
+
inverse: applied.value.inverse
|
|
29740
|
+
});
|
|
29741
|
+
};
|
|
29157
29742
|
const compileBlockPlacement = (document, { intent, mode, firstBlockId }) => {
|
|
29158
29743
|
const { from, to, openStart, openEnd } = intent;
|
|
29159
29744
|
const paragraphs = intent.blocks.filter((block) => block.type === "paragraph");
|
|
@@ -29169,26 +29754,25 @@ const compileBlockPlacement = (document, { intent, mode, firstBlockId }) => {
|
|
|
29169
29754
|
mode,
|
|
29170
29755
|
...firstBlockId === void 0 ? {} : { firstBlockId }
|
|
29171
29756
|
});
|
|
29172
|
-
const
|
|
29757
|
+
const lastBlock = intent.blocks.at(-1);
|
|
29758
|
+
const identified = identifyClipboardContent({
|
|
29173
29759
|
document,
|
|
29174
29760
|
paragraphs: intent.blocks.flatMap(blockParagraphs),
|
|
29761
|
+
controls: blockControlsOf(intent.blocks),
|
|
29762
|
+
identifyLast: lastBlock?.type !== "paragraph" && lastBlock?.type !== "table",
|
|
29175
29763
|
mode,
|
|
29176
29764
|
firstBlockId
|
|
29177
29765
|
});
|
|
29178
29766
|
if (identified.isErr()) return Result.err(identified.error);
|
|
29179
29767
|
let next = 0;
|
|
29180
|
-
const take = () => identified.value[next++] ?? panic("An identified clipboard paragraph is missing.");
|
|
29181
|
-
const
|
|
29182
|
-
|
|
29183
|
-
|
|
29184
|
-
|
|
29185
|
-
|
|
29186
|
-
|
|
29187
|
-
|
|
29188
|
-
}))
|
|
29189
|
-
}))
|
|
29190
|
-
};
|
|
29191
|
-
const blocks = intent.blocks.map(rebuilt);
|
|
29768
|
+
const take = () => identified.value.paragraphs[next++] ?? panic("An identified clipboard paragraph is missing.");
|
|
29769
|
+
const controls = [...identified.value.controls];
|
|
29770
|
+
const blocks = intent.blocks.map((block) => {
|
|
29771
|
+
const placed = mapPastedBlockParagraphs(block, take);
|
|
29772
|
+
if (placed.type === "paragraph" || placed.type === "preservedBlock") return placed;
|
|
29773
|
+
const [withControls] = withBlockControls([placed], controls);
|
|
29774
|
+
return withControls !== void 0 && isPastedBlock(withControls) ? withControls : panic("A pasted block lost its kind.");
|
|
29775
|
+
});
|
|
29192
29776
|
const refuseIdentities = (message) => Result.err(new DocumentOpRefusal({
|
|
29193
29777
|
reason: DOCUMENT_OP_REFUSAL_REASONS.INVALID_OPERATION,
|
|
29194
29778
|
message,
|
|
@@ -29282,9 +29866,11 @@ const compileBlockPlacement = (document, { intent, mode, firstBlockId }) => {
|
|
|
29282
29866
|
from: 0,
|
|
29283
29867
|
to: caret.offset
|
|
29284
29868
|
})) {
|
|
29869
|
+
const reserved = new Set(mode.reservedBlockIds);
|
|
29870
|
+
for (const block of blocks) for (const { paraId } of blockParagraphs(block)) if (paraId !== void 0) reserved.add(paraId);
|
|
29285
29871
|
const fresh = freshParagraphIds({
|
|
29286
29872
|
document: current,
|
|
29287
|
-
reserved
|
|
29873
|
+
reserved,
|
|
29288
29874
|
lease: mode.idLease,
|
|
29289
29875
|
count: 1,
|
|
29290
29876
|
opType: DOCUMENT_OP_TYPES.SPLIT_BLOCK
|
|
@@ -29300,6 +29886,19 @@ const compileBlockPlacement = (document, { intent, mode, firstBlockId }) => {
|
|
|
29300
29886
|
}
|
|
29301
29887
|
const anchor = caret.blockId;
|
|
29302
29888
|
for (const block of blocks) {
|
|
29889
|
+
if (block.type === "blockSdt" || block.type === "blockCustomXml" || block.type === "preservedBlock") {
|
|
29890
|
+
const placed = placeContainerBlock({
|
|
29891
|
+
document: current,
|
|
29892
|
+
story: caret.story,
|
|
29893
|
+
anchor,
|
|
29894
|
+
block,
|
|
29895
|
+
mode
|
|
29896
|
+
});
|
|
29897
|
+
if (placed.isErr()) return Result.err(placed.error);
|
|
29898
|
+
ops.push(placed.value.op);
|
|
29899
|
+
current = placed.value.document;
|
|
29900
|
+
continue;
|
|
29901
|
+
}
|
|
29303
29902
|
const placed = step(block.type === "paragraph" ? {
|
|
29304
29903
|
type: "insertParagraphs",
|
|
29305
29904
|
story: caret.story,
|
|
@@ -29550,8 +30149,14 @@ const withoutMoveAnchors = (nodes) => {
|
|
|
29550
30149
|
}
|
|
29551
30150
|
return out;
|
|
29552
30151
|
};
|
|
29553
|
-
const identifyClipboardParagraphs = (
|
|
30152
|
+
const identifyClipboardParagraphs = (options) => identifyClipboardContent({
|
|
30153
|
+
...options,
|
|
30154
|
+
controls: [],
|
|
30155
|
+
identifyLast: false
|
|
30156
|
+
}).map(({ paragraphs }) => paragraphs);
|
|
30157
|
+
const identifyClipboardContent = ({ document, paragraphs, controls, identifyLast, mode, firstBlockId }) => {
|
|
29554
30158
|
const copy = cloneModel([...paragraphs]);
|
|
30159
|
+
const controlCopies = cloneModel([...controls]);
|
|
29555
30160
|
let occupancy;
|
|
29556
30161
|
const packageOccupancy = () => occupancy ??= packageIdOccupancy(document.package);
|
|
29557
30162
|
const assignedIds = {
|
|
@@ -29615,7 +30220,7 @@ const identifyClipboardParagraphs = ({ document, paragraphs, mode, firstBlockId
|
|
|
29615
30220
|
from: nextBlock,
|
|
29616
30221
|
taken: (candidate) => {
|
|
29617
30222
|
const key = formatParaId(candidate);
|
|
29618
|
-
return blockIds.has(key) || packageOccupancy().paragraphs.has(key);
|
|
30223
|
+
return blockIds.has(key) || packageOccupancy().paragraphs.has(key) || (mode.reservedBlockIds?.has(key) ?? false);
|
|
29619
30224
|
}
|
|
29620
30225
|
}).at(0);
|
|
29621
30226
|
if (fresh === void 0) return void 0;
|
|
@@ -29651,7 +30256,7 @@ const identifyClipboardParagraphs = ({ document, paragraphs, mode, firstBlockId
|
|
|
29651
30256
|
};
|
|
29652
30257
|
const remintedControls = /* @__PURE__ */ new WeakSet();
|
|
29653
30258
|
const keptMarkers = [];
|
|
29654
|
-
visit(copy, (value) => {
|
|
30259
|
+
visit([copy, controlCopies], (value) => {
|
|
29655
30260
|
if ("keptCut" in value) keptMarkers.push(value);
|
|
29656
30261
|
if ("type" in value && value.type === "inlineSdt" && "properties" in value && typeof value.properties === "object" && value.properties !== null && "id" in value.properties && typeof value.properties.id === "number") {
|
|
29657
30262
|
value.properties.id = freshId(IDENTITY_SPACES.CONTROL, value.properties.id);
|
|
@@ -29680,7 +30285,7 @@ const identifyClipboardParagraphs = ({ document, paragraphs, mode, firstBlockId
|
|
|
29680
30285
|
}));
|
|
29681
30286
|
for (const [index, paragraph] of copy.entries()) {
|
|
29682
30287
|
delete paragraph.paraId;
|
|
29683
|
-
if (index === copy.length - 1) continue;
|
|
30288
|
+
if (index === copy.length - 1 && !identifyLast) continue;
|
|
29684
30289
|
const id = freshBlock();
|
|
29685
30290
|
if (id === void 0) return Result.err(new DocumentOpRefusal({
|
|
29686
30291
|
reason: DOCUMENT_OP_REFUSAL_REASONS.INVALID_BLOCK_ID,
|
|
@@ -29689,7 +30294,10 @@ const identifyClipboardParagraphs = ({ document, paragraphs, mode, firstBlockId
|
|
|
29689
30294
|
}));
|
|
29690
30295
|
paragraph.paraId = id;
|
|
29691
30296
|
}
|
|
29692
|
-
return Result.ok(
|
|
30297
|
+
return Result.ok({
|
|
30298
|
+
paragraphs: copy,
|
|
30299
|
+
controls: controlCopies
|
|
30300
|
+
});
|
|
29693
30301
|
};
|
|
29694
30302
|
/**
|
|
29695
30303
|
* Direct and tracked joins choose paragraph properties from the same
|
|
@@ -29907,6 +30515,339 @@ const gapWithoutLeaves = (content, at, removed) => {
|
|
|
29907
30515
|
zeroWidthBefore
|
|
29908
30516
|
};
|
|
29909
30517
|
};
|
|
30518
|
+
/**
|
|
30519
|
+
* A move of the text between `from` and `to`: the range is deleted, as
|
|
30520
|
+
* `replaceText` with no text deletes it (a suggestion records the
|
|
30521
|
+
* deletion), and the moved content goes in where the target stands once
|
|
30522
|
+
* the deletion is made. A target inside the range moves nothing.
|
|
30523
|
+
*/
|
|
30524
|
+
/**
|
|
30525
|
+
* The note bodies a direct deletion pruned as it took their references away,
|
|
30526
|
+
* from its inverse: a move puts the references back at its target, so it
|
|
30527
|
+
* restores the bodies the deletion removed.
|
|
30528
|
+
*/
|
|
30529
|
+
const noteBodyRestorations = (inverse) => inverse.flatMap((op) => op.type === DOCUMENT_OP_TYPES.RESTORE_STORY_PARTS && (op.parts.footnotes !== void 0 || op.parts.endnotes !== void 0) ? [{
|
|
30530
|
+
type: DOCUMENT_OP_TYPES.RESTORE_STORY_PARTS,
|
|
30531
|
+
expected: {
|
|
30532
|
+
...op.expected.footnotes === void 0 ? {} : { footnotes: op.expected.footnotes },
|
|
30533
|
+
...op.expected.endnotes === void 0 ? {} : { endnotes: op.expected.endnotes }
|
|
30534
|
+
},
|
|
30535
|
+
parts: {
|
|
30536
|
+
...op.parts.footnotes === void 0 ? {} : { footnotes: op.parts.footnotes },
|
|
30537
|
+
...op.parts.endnotes === void 0 ? {} : { endnotes: op.parts.endnotes }
|
|
30538
|
+
}
|
|
30539
|
+
}] : []);
|
|
30540
|
+
/**
|
|
30541
|
+
* The document with the note bodies of `restorations` back, and the ops that
|
|
30542
|
+
* put them back. Each restoration expects the note parts its own deletion
|
|
30543
|
+
* left, so they undo the deletions newest first.
|
|
30544
|
+
*/
|
|
30545
|
+
const withNoteBodiesRestored = (document, restorations) => {
|
|
30546
|
+
if (restorations.length === 0) return Result.ok({
|
|
30547
|
+
document,
|
|
30548
|
+
ops: []
|
|
30549
|
+
});
|
|
30550
|
+
const ops = restorations.toReversed();
|
|
30551
|
+
const restored = applyDocumentOps(document, ops);
|
|
30552
|
+
if (restored.isErr()) return Result.err(restored.error);
|
|
30553
|
+
return Result.ok({
|
|
30554
|
+
document: restored.value.document,
|
|
30555
|
+
ops
|
|
30556
|
+
});
|
|
30557
|
+
};
|
|
30558
|
+
const compileRangeMove = (document, { intent, mode, insert }) => {
|
|
30559
|
+
const range = selectedParagraphRuns(document, intent.from, intent.to);
|
|
30560
|
+
if (range.isErr()) return Result.err(range.error);
|
|
30561
|
+
const sourceParagraph = paragraphAt(document, intent.from);
|
|
30562
|
+
const fromGap = intent.from.zeroWidthBefore ?? (sourceParagraph === void 0 ? 0 : zeroWidthLeavesAt(sourceParagraph.content, intent.from.offset).length);
|
|
30563
|
+
const toGap = intent.to.zeroWidthBefore ?? 0;
|
|
30564
|
+
if (idKey(intent.from.blockId) === idKey(intent.to.blockId) && intent.from.offset === intent.to.offset && fromGap >= toGap) {
|
|
30565
|
+
if (fromGap > toGap && (intent.from.zeroWidthBefore !== void 0 || intent.to.zeroWidthBefore !== void 0)) return Result.err(new DocumentOpRefusal({
|
|
30566
|
+
reason: DOCUMENT_OP_REFUSAL_REASONS.INVALID_OFFSET,
|
|
30567
|
+
message: "The move source marker gaps are reversed.",
|
|
30568
|
+
opType: DOCUMENT_OP_TYPES.DELETE_RANGE
|
|
30569
|
+
}));
|
|
30570
|
+
return Result.ok({
|
|
30571
|
+
ops: [],
|
|
30572
|
+
selection: intent.target
|
|
30573
|
+
});
|
|
30574
|
+
}
|
|
30575
|
+
const locations = storyParagraphs(storyBody$1(document, intent.from.story));
|
|
30576
|
+
const indexOf = (at) => locations.findIndex(({ paragraph }) => idKey(paragraph.paraId ?? "") === idKey(at.blockId));
|
|
30577
|
+
const first = indexOf(intent.from);
|
|
30578
|
+
const last = indexOf(intent.to);
|
|
30579
|
+
const targetIndex = indexOf(intent.target);
|
|
30580
|
+
const targetGap = intent.target.zeroWidthBefore ?? defaultInsertionGap(paragraphAt(document, intent.target)?.content ?? [], intent.target.offset).zeroWidthBefore;
|
|
30581
|
+
const targetPosition = {
|
|
30582
|
+
offset: intent.target.offset,
|
|
30583
|
+
zeroWidthBefore: targetGap
|
|
30584
|
+
};
|
|
30585
|
+
if (intent.target.story === intent.from.story && targetIndex >= first && targetIndex <= last && (targetIndex !== first || compareGaps(targetPosition, {
|
|
30586
|
+
offset: intent.from.offset,
|
|
30587
|
+
zeroWidthBefore: fromGap
|
|
30588
|
+
}) >= 0) && (targetIndex !== last || compareGaps(targetPosition, {
|
|
30589
|
+
offset: intent.to.offset,
|
|
30590
|
+
zeroWidthBefore: toGap
|
|
30591
|
+
}) <= 0)) return Result.ok({
|
|
30592
|
+
ops: [],
|
|
30593
|
+
selection: intent.target
|
|
30594
|
+
});
|
|
30595
|
+
const anchorDeletions = [];
|
|
30596
|
+
const sourceAnchors = mode.type === "editing" ? range.value.flat() : [];
|
|
30597
|
+
for (const { paragraph } of sourceAnchors) {
|
|
30598
|
+
const blockId = paragraph.paraId ?? "";
|
|
30599
|
+
const from = idKey(blockId) === idKey(intent.from.blockId) ? {
|
|
30600
|
+
offset: intent.from.offset,
|
|
30601
|
+
zeroWidthBefore: fromGap
|
|
30602
|
+
} : {
|
|
30603
|
+
offset: 0,
|
|
30604
|
+
zeroWidthBefore: 0
|
|
30605
|
+
};
|
|
30606
|
+
const to = idKey(blockId) === idKey(intent.to.blockId) ? {
|
|
30607
|
+
offset: intent.to.offset,
|
|
30608
|
+
zeroWidthBefore: toGap
|
|
30609
|
+
} : {
|
|
30610
|
+
offset: paragraphLength(paragraph),
|
|
30611
|
+
zeroWidthBefore: zeroWidthLeavesAt(paragraph.content, paragraphLength(paragraph)).length
|
|
30612
|
+
};
|
|
30613
|
+
for (const span of leafSpans(paragraph.content)) {
|
|
30614
|
+
if (!isMoveAnchor(span.node) || span.ancestors.some(isRemovedRevisionNode) || compareGaps(span.before, from) < 0 || compareGaps(span.after, to) > 0) continue;
|
|
30615
|
+
anchorDeletions.push({
|
|
30616
|
+
type: DOCUMENT_OP_TYPES.DELETE_RANGE,
|
|
30617
|
+
from: {
|
|
30618
|
+
story: intent.from.story,
|
|
30619
|
+
blockId,
|
|
30620
|
+
...span.before
|
|
30621
|
+
},
|
|
30622
|
+
to: {
|
|
30623
|
+
story: intent.from.story,
|
|
30624
|
+
blockId,
|
|
30625
|
+
...span.after
|
|
30626
|
+
}
|
|
30627
|
+
});
|
|
30628
|
+
}
|
|
30629
|
+
}
|
|
30630
|
+
const deleted = compileEditorIntent(document, {
|
|
30631
|
+
intent: {
|
|
30632
|
+
type: "replaceText",
|
|
30633
|
+
from: intent.from,
|
|
30634
|
+
to: intent.to,
|
|
30635
|
+
text: ""
|
|
30636
|
+
},
|
|
30637
|
+
mode
|
|
30638
|
+
});
|
|
30639
|
+
if (deleted.isErr()) return deleted;
|
|
30640
|
+
const logicalDeletions = anchorDeletions.length === 0 ? deleted.value.ops : [...deleted.value.ops.filter((op) => op.type === DOCUMENT_OP_TYPES.DELETE_RANGE).concat(anchorDeletions).sort((left, right) => indexOf(right.from) - indexOf(left.from) || compareGaps({
|
|
30641
|
+
offset: right.from.offset,
|
|
30642
|
+
zeroWidthBefore: right.from.zeroWidthBefore ?? 0
|
|
30643
|
+
}, {
|
|
30644
|
+
offset: left.from.offset,
|
|
30645
|
+
zeroWidthBefore: left.from.zeroWidthBefore ?? 0
|
|
30646
|
+
})), ...deleted.value.ops.filter((op) => op.type !== DOCUMENT_OP_TYPES.DELETE_RANGE)];
|
|
30647
|
+
const anchors = new Set(anchorDeletions);
|
|
30648
|
+
const deletionOps = [];
|
|
30649
|
+
const movedNoteBodies = [];
|
|
30650
|
+
let afterDeletion = document;
|
|
30651
|
+
for (const planned of logicalDeletions) {
|
|
30652
|
+
let op = planned;
|
|
30653
|
+
if (planned.type === DOCUMENT_OP_TYPES.DELETE_RANGE && anchors.has(planned)) {
|
|
30654
|
+
const paragraph = paragraphAt(afterDeletion, planned.from);
|
|
30655
|
+
if (paragraph === void 0) panic("A move anchor lost its selected paragraph.");
|
|
30656
|
+
op = {
|
|
30657
|
+
type: DOCUMENT_OP_TYPES.REPLACE_INLINE,
|
|
30658
|
+
story: planned.from.story,
|
|
30659
|
+
blockId: planned.from.blockId,
|
|
30660
|
+
expected: paragraph.content,
|
|
30661
|
+
content: deleteBetween(paragraph.content, {
|
|
30662
|
+
offset: planned.from.offset,
|
|
30663
|
+
zeroWidthBefore: planned.from.zeroWidthBefore ?? 0
|
|
30664
|
+
}, {
|
|
30665
|
+
offset: planned.to.offset,
|
|
30666
|
+
zeroWidthBefore: planned.to.zeroWidthBefore ?? 0
|
|
30667
|
+
}).content
|
|
30668
|
+
};
|
|
30669
|
+
}
|
|
30670
|
+
const applied = applyDocumentOps(afterDeletion, [op]);
|
|
30671
|
+
if (applied.isErr()) return Result.err(applied.error);
|
|
30672
|
+
afterDeletion = applied.value.document;
|
|
30673
|
+
deletionOps.push(op);
|
|
30674
|
+
movedNoteBodies.push(...noteBodyRestorations(applied.value.inverse));
|
|
30675
|
+
}
|
|
30676
|
+
const restored = withNoteBodiesRestored(afterDeletion, movedNoteBodies);
|
|
30677
|
+
if (restored.isErr()) return Result.err(restored.error);
|
|
30678
|
+
afterDeletion = restored.value.document;
|
|
30679
|
+
deletionOps.push(...restored.value.ops);
|
|
30680
|
+
let target = intent.target;
|
|
30681
|
+
for (const op of logicalDeletions) {
|
|
30682
|
+
if (op.type === DOCUMENT_OP_TYPES.DELETE_RANGE && op.revision === void 0 && idKey(target.blockId) === idKey(op.from.blockId) && target.story === op.from.story && target.offset >= op.to.offset) {
|
|
30683
|
+
const source = paragraphAt(document, op.from);
|
|
30684
|
+
const deletionFromGap = op.from.zeroWidthBefore ?? zeroWidthLeavesAt(source?.content ?? [], op.from.offset).length;
|
|
30685
|
+
const deletionToGap = op.to.zeroWidthBefore ?? 0;
|
|
30686
|
+
const deletionTargetGap = target.zeroWidthBefore ?? defaultInsertionGap(source?.content ?? [], target.offset).zeroWidthBefore;
|
|
30687
|
+
const rebased = Object.assign({}, target, { offset: target.offset - (op.to.offset - op.from.offset) });
|
|
30688
|
+
if (target.offset === op.to.offset) rebased.zeroWidthBefore = deletionFromGap + deletionTargetGap - deletionToGap;
|
|
30689
|
+
target = rebased;
|
|
30690
|
+
}
|
|
30691
|
+
if (op.type === DOCUMENT_OP_TYPES.JOIN_BLOCKS && op.revision === void 0 && idKey(target.blockId) === idKey(op.blockId) && target.story === op.story) target = Object.assign({}, target, { blockId: op.nextBlockId });
|
|
30692
|
+
else if (op.type === DOCUMENT_OP_TYPES.JOIN_BLOCKS && op.revision === void 0 && idKey(target.blockId) === idKey(op.nextBlockId) && target.story === op.story) {
|
|
30693
|
+
const prefix = paragraphAt(document, {
|
|
30694
|
+
story: op.story,
|
|
30695
|
+
blockId: op.blockId,
|
|
30696
|
+
offset: 0
|
|
30697
|
+
});
|
|
30698
|
+
const remaining = idKey(op.blockId) === idKey(intent.from.blockId) ? intent.from.offset : 0;
|
|
30699
|
+
if (prefix !== void 0) {
|
|
30700
|
+
const rebased = Object.assign({}, target, { offset: target.offset + remaining });
|
|
30701
|
+
if (target.offset === 0 && idKey(op.blockId) === idKey(intent.from.blockId)) rebased.zeroWidthBefore = fromGap + (target.zeroWidthBefore ?? 0);
|
|
30702
|
+
target = rebased;
|
|
30703
|
+
}
|
|
30704
|
+
}
|
|
30705
|
+
}
|
|
30706
|
+
const inserted = insert(afterDeletion, target, modeAfterOps(afterDeletion, mode));
|
|
30707
|
+
if (inserted.isErr()) return inserted;
|
|
30708
|
+
return Result.ok({
|
|
30709
|
+
ops: [...deletionOps, ...inserted.value.ops],
|
|
30710
|
+
selection: inserted.value.selection
|
|
30711
|
+
});
|
|
30712
|
+
};
|
|
30713
|
+
/**
|
|
30714
|
+
* A paragraph without the move range markers it carried: a suggested move is
|
|
30715
|
+
* recorded as a deletion and an insertion, and a copied marker would pair
|
|
30716
|
+
* with no range.
|
|
30717
|
+
*/
|
|
30718
|
+
const withoutParagraphMoveAnchors = (paragraph) => Object.assign({}, paragraph, { content: asParagraphContent(withoutMoveAnchors(paragraph.content)) });
|
|
30719
|
+
/**
|
|
30720
|
+
* A block without move range markers, a table's cell paragraphs and a
|
|
30721
|
+
* container's among them.
|
|
30722
|
+
*/
|
|
30723
|
+
const withoutBlockMoveAnchors = (block) => mapPastedBlockParagraphs(block, withoutParagraphMoveAnchors);
|
|
30724
|
+
/**
|
|
30725
|
+
* Blocks, tables among them, moved from a range to a target. The tables
|
|
30726
|
+
* standing wholly between the range's paragraphs are removed, the latest
|
|
30727
|
+
* first, or in suggesting mode recorded as deleted; the range's text is then
|
|
30728
|
+
* deleted and the blocks placed at the rebased target as a paste places them.
|
|
30729
|
+
* A suggestion records the move as the deletion of its source and the
|
|
30730
|
+
* insertion of its copy, as a moved paragraph is recorded. A target inside
|
|
30731
|
+
* the range, a moved table's cell among them, moves nothing.
|
|
30732
|
+
*/
|
|
30733
|
+
const compileBlockMove = (document, { intent, mode, firstBlockId }) => {
|
|
30734
|
+
const { blocks, ...range } = intent;
|
|
30735
|
+
const paragraphs = blocks.filter((block) => block.type === "paragraph");
|
|
30736
|
+
if (paragraphs.length === blocks.length) return compileEditorIntent(document, {
|
|
30737
|
+
intent: {
|
|
30738
|
+
...range,
|
|
30739
|
+
type: "moveFragment",
|
|
30740
|
+
paragraphs
|
|
30741
|
+
},
|
|
30742
|
+
mode,
|
|
30743
|
+
...firstBlockId === void 0 ? {} : { firstBlockId }
|
|
30744
|
+
});
|
|
30745
|
+
const story = intent.from.story;
|
|
30746
|
+
const body = storyBody$1(document, story);
|
|
30747
|
+
const locations = storyParagraphs(body);
|
|
30748
|
+
const indexOf = (at) => locations.findIndex(({ paragraph }) => idKey(paragraph.paraId ?? "") === idKey(at.blockId));
|
|
30749
|
+
const first = indexOf(intent.from);
|
|
30750
|
+
const last = indexOf(intent.to);
|
|
30751
|
+
const start = locations[first];
|
|
30752
|
+
const end = locations[last];
|
|
30753
|
+
if (start === void 0 || end === void 0 || intent.to.story !== story) return Result.err(new DocumentOpRefusal({
|
|
30754
|
+
reason: DOCUMENT_OP_REFUSAL_REASONS.BLOCK_NOT_FOUND,
|
|
30755
|
+
message: "The moved range names a paragraph the story does not hold.",
|
|
30756
|
+
opType: DOCUMENT_OP_TYPES.DELETE_RANGE
|
|
30757
|
+
}));
|
|
30758
|
+
if (!sameBlockList(start.list, end.list) || last < first) return Result.err(new DocumentOpRefusal({
|
|
30759
|
+
reason: DOCUMENT_OP_REFUSAL_REASONS.INVALID_OPERATION,
|
|
30760
|
+
message: "Moved blocks start and end in one block list.",
|
|
30761
|
+
opType: DOCUMENT_OP_TYPES.DELETE_RANGE
|
|
30762
|
+
}));
|
|
30763
|
+
const target = indexOf(intent.target);
|
|
30764
|
+
if (intent.target.story === story && target > first && target < last) return Result.ok({
|
|
30765
|
+
ops: [],
|
|
30766
|
+
selection: intent.target
|
|
30767
|
+
});
|
|
30768
|
+
const covered = blockListAt(body.content, start.list).slice(start.index + 1, end.index).filter((block) => block.type === "table" || block.type === "blockSdt" || block.type === "blockCustomXml" || block.type === "preservedBlock");
|
|
30769
|
+
const reserved = mode.reservedBlockIds === void 0 ? {} : { reservedBlockIds: mode.reservedBlockIds };
|
|
30770
|
+
const ops = [];
|
|
30771
|
+
let current = document;
|
|
30772
|
+
let currentMode = mode;
|
|
30773
|
+
const movedNoteBodies = [];
|
|
30774
|
+
for (const table of covered.toReversed()) {
|
|
30775
|
+
if (table.type !== "table") {
|
|
30776
|
+
const removed = removeContainerBlock({
|
|
30777
|
+
document: current,
|
|
30778
|
+
story,
|
|
30779
|
+
anchor: start.paragraph.paraId ?? "",
|
|
30780
|
+
block: table,
|
|
30781
|
+
mode: currentMode
|
|
30782
|
+
});
|
|
30783
|
+
if (removed.isErr()) return removed;
|
|
30784
|
+
ops.push(removed.value.op);
|
|
30785
|
+
current = removed.value.document;
|
|
30786
|
+
movedNoteBodies.push(...noteBodyRestorations(removed.value.inverse));
|
|
30787
|
+
continue;
|
|
30788
|
+
}
|
|
30789
|
+
const blockId = storyParagraphs({ content: [table] }).at(0)?.paragraph.paraId;
|
|
30790
|
+
if (blockId === void 0) return Result.err(new DocumentOpRefusal({
|
|
30791
|
+
reason: DOCUMENT_OP_REFUSAL_REASONS.MISSING_BLOCK_ID,
|
|
30792
|
+
message: "A moved table holds no paragraph that addresses it.",
|
|
30793
|
+
opType: DOCUMENT_OP_TYPES.DELETE_TABLE
|
|
30794
|
+
}));
|
|
30795
|
+
const removed = compileEditorIntent(current, {
|
|
30796
|
+
intent: {
|
|
30797
|
+
type: "tableBlock",
|
|
30798
|
+
operation: {
|
|
30799
|
+
type: DOCUMENT_OP_TYPES.DELETE_TABLE,
|
|
30800
|
+
story,
|
|
30801
|
+
blockId
|
|
30802
|
+
}
|
|
30803
|
+
},
|
|
30804
|
+
mode: currentMode
|
|
30805
|
+
});
|
|
30806
|
+
if (removed.isErr()) return removed;
|
|
30807
|
+
const applied = applyDocumentOps(current, removed.value.ops);
|
|
30808
|
+
if (applied.isErr()) return Result.err(applied.error);
|
|
30809
|
+
ops.push(...removed.value.ops);
|
|
30810
|
+
current = applied.value.document;
|
|
30811
|
+
if (mode.type === "editing") movedNoteBodies.push(...noteBodyRestorations(applied.value.inverse));
|
|
30812
|
+
currentMode = {
|
|
30813
|
+
...modeAfterOps(current, currentMode),
|
|
30814
|
+
...reserved
|
|
30815
|
+
};
|
|
30816
|
+
}
|
|
30817
|
+
const restored = withNoteBodiesRestored(current, movedNoteBodies);
|
|
30818
|
+
if (restored.isErr()) return Result.err(restored.error);
|
|
30819
|
+
current = restored.value.document;
|
|
30820
|
+
ops.push(...restored.value.ops);
|
|
30821
|
+
const moved = compileRangeMove(current, {
|
|
30822
|
+
intent: range,
|
|
30823
|
+
mode: currentMode,
|
|
30824
|
+
insert: (afterDeletion, at, insertMode) => compileEditorIntent(afterDeletion, {
|
|
30825
|
+
intent: {
|
|
30826
|
+
type: "pasteBlocks",
|
|
30827
|
+
from: at,
|
|
30828
|
+
to: at,
|
|
30829
|
+
blocks: mode.type === "suggesting" ? blocks.map(withoutBlockMoveAnchors) : blocks,
|
|
30830
|
+
openStart: intent.openStart,
|
|
30831
|
+
openEnd: intent.openEnd
|
|
30832
|
+
},
|
|
30833
|
+
mode: {
|
|
30834
|
+
...insertMode,
|
|
30835
|
+
...reserved
|
|
30836
|
+
},
|
|
30837
|
+
...firstBlockId === void 0 ? {} : { firstBlockId },
|
|
30838
|
+
...mode.type === "editing" ? { moved: true } : {}
|
|
30839
|
+
})
|
|
30840
|
+
});
|
|
30841
|
+
if (moved.isErr()) return moved;
|
|
30842
|
+
if (moved.value.ops.length === 0) return Result.ok({
|
|
30843
|
+
ops: [],
|
|
30844
|
+
selection: intent.target
|
|
30845
|
+
});
|
|
30846
|
+
return Result.ok({
|
|
30847
|
+
ops: [...ops, ...moved.value.ops],
|
|
30848
|
+
selection: moved.value.selection
|
|
30849
|
+
});
|
|
30850
|
+
};
|
|
29910
30851
|
/** Compile one batch; the caller applies it atomically and journals its exact inverse. */
|
|
29911
30852
|
const compileEditorIntent = (document, input) => {
|
|
29912
30853
|
const routed = textBoxOfIntent(document, input.intent);
|
|
@@ -29993,7 +30934,7 @@ const beginTrackedInsertionCompilation = ({ document, count, reservedBlockIds })
|
|
|
29993
30934
|
}
|
|
29994
30935
|
};
|
|
29995
30936
|
};
|
|
29996
|
-
const compileInStory = (document, { intent, mode, firstBlockId, typedFormatting = TYPED_TEXT_FORMATTING.CARET, replacementFormattingDocument }) => {
|
|
30937
|
+
const compileInStory = (document, { intent, mode, firstBlockId, typedFormatting = TYPED_TEXT_FORMATTING.CARET, replacementFormattingDocument, moved }) => {
|
|
29997
30938
|
if (firstBlockId !== void 0 && (!Number.isInteger(firstBlockId) || firstBlockId < 1 || firstBlockId > 2147483648)) return Result.err(new DocumentOpRefusal({
|
|
29998
30939
|
reason: DOCUMENT_OP_REFUSAL_REASONS.INVALID_BLOCK_ID,
|
|
29999
30940
|
message: "The pasted block identity allocator is exhausted or invalid.",
|
|
@@ -30034,7 +30975,8 @@ const compileInStory = (document, { intent, mode, firstBlockId, typedFormatting
|
|
|
30034
30975
|
case "pasteBlocks": return compileBlockPaste(document, {
|
|
30035
30976
|
intent,
|
|
30036
30977
|
mode,
|
|
30037
|
-
...firstBlockId === void 0 ? {} : { firstBlockId }
|
|
30978
|
+
...firstBlockId === void 0 ? {} : { firstBlockId },
|
|
30979
|
+
...moved === void 0 ? {} : { moved }
|
|
30038
30980
|
});
|
|
30039
30981
|
case "replaceFragment": {
|
|
30040
30982
|
if (intent.paragraphs.length === 0) return compileEditorIntent(document, {
|
|
@@ -30343,182 +31285,36 @@ const compileInStory = (document, { intent, mode, firstBlockId, typedFormatting
|
|
|
30343
31285
|
break;
|
|
30344
31286
|
}
|
|
30345
31287
|
case "moveFragment": {
|
|
30346
|
-
const
|
|
30347
|
-
|
|
30348
|
-
|
|
30349
|
-
|
|
30350
|
-
|
|
30351
|
-
|
|
30352
|
-
|
|
30353
|
-
|
|
30354
|
-
|
|
30355
|
-
|
|
30356
|
-
|
|
30357
|
-
return Result.ok({
|
|
30358
|
-
ops: [],
|
|
30359
|
-
selection: intent.target
|
|
30360
|
-
});
|
|
30361
|
-
}
|
|
30362
|
-
const locations = storyParagraphs(storyBody$1(document, intent.from.story));
|
|
30363
|
-
const indexOf = (at) => locations.findIndex(({ paragraph }) => idKey(paragraph.paraId ?? "") === idKey(at.blockId));
|
|
30364
|
-
const first = indexOf(intent.from);
|
|
30365
|
-
const last = indexOf(intent.to);
|
|
30366
|
-
const targetIndex = indexOf(intent.target);
|
|
30367
|
-
const targetGap = intent.target.zeroWidthBefore ?? defaultInsertionGap(paragraphAt(document, intent.target)?.content ?? [], intent.target.offset).zeroWidthBefore;
|
|
30368
|
-
const targetPosition = {
|
|
30369
|
-
offset: intent.target.offset,
|
|
30370
|
-
zeroWidthBefore: targetGap
|
|
30371
|
-
};
|
|
30372
|
-
if (intent.target.story === intent.from.story && targetIndex >= first && targetIndex <= last && (targetIndex !== first || compareGaps(targetPosition, {
|
|
30373
|
-
offset: intent.from.offset,
|
|
30374
|
-
zeroWidthBefore: fromGap
|
|
30375
|
-
}) >= 0) && (targetIndex !== last || compareGaps(targetPosition, {
|
|
30376
|
-
offset: intent.to.offset,
|
|
30377
|
-
zeroWidthBefore: toGap
|
|
30378
|
-
}) <= 0)) return Result.ok({
|
|
30379
|
-
ops: [],
|
|
30380
|
-
selection: intent.target
|
|
30381
|
-
});
|
|
30382
|
-
const anchorDeletions = [];
|
|
30383
|
-
const sourceAnchors = mode.type === "editing" ? range.value.flat() : [];
|
|
30384
|
-
for (const { paragraph } of sourceAnchors) {
|
|
30385
|
-
const blockId = paragraph.paraId ?? "";
|
|
30386
|
-
const from = idKey(blockId) === idKey(intent.from.blockId) ? {
|
|
30387
|
-
offset: intent.from.offset,
|
|
30388
|
-
zeroWidthBefore: fromGap
|
|
30389
|
-
} : {
|
|
30390
|
-
offset: 0,
|
|
30391
|
-
zeroWidthBefore: 0
|
|
30392
|
-
};
|
|
30393
|
-
const to = idKey(blockId) === idKey(intent.to.blockId) ? {
|
|
30394
|
-
offset: intent.to.offset,
|
|
30395
|
-
zeroWidthBefore: toGap
|
|
30396
|
-
} : {
|
|
30397
|
-
offset: paragraphLength(paragraph),
|
|
30398
|
-
zeroWidthBefore: zeroWidthLeavesAt(paragraph.content, paragraphLength(paragraph)).length
|
|
30399
|
-
};
|
|
30400
|
-
for (const span of leafSpans(paragraph.content)) {
|
|
30401
|
-
if (!isMoveAnchor(span.node) || span.ancestors.some(isRemovedRevisionNode) || compareGaps(span.before, from) < 0 || compareGaps(span.after, to) > 0) continue;
|
|
30402
|
-
anchorDeletions.push({
|
|
30403
|
-
type: DOCUMENT_OP_TYPES.DELETE_RANGE,
|
|
30404
|
-
from: {
|
|
30405
|
-
story: intent.from.story,
|
|
30406
|
-
blockId,
|
|
30407
|
-
...span.before
|
|
30408
|
-
},
|
|
30409
|
-
to: {
|
|
30410
|
-
story: intent.from.story,
|
|
30411
|
-
blockId,
|
|
30412
|
-
...span.after
|
|
30413
|
-
}
|
|
30414
|
-
});
|
|
30415
|
-
}
|
|
30416
|
-
}
|
|
30417
|
-
const deleted = compileEditorIntent(document, {
|
|
30418
|
-
intent: {
|
|
30419
|
-
type: "replaceText",
|
|
30420
|
-
from: intent.from,
|
|
30421
|
-
to: intent.to,
|
|
30422
|
-
text: ""
|
|
30423
|
-
},
|
|
30424
|
-
mode
|
|
30425
|
-
});
|
|
30426
|
-
if (deleted.isErr()) return deleted;
|
|
30427
|
-
const logicalDeletions = anchorDeletions.length === 0 ? deleted.value.ops : [...deleted.value.ops.filter((op) => op.type === DOCUMENT_OP_TYPES.DELETE_RANGE).concat(anchorDeletions).sort((left, right) => indexOf(right.from) - indexOf(left.from) || compareGaps({
|
|
30428
|
-
offset: right.from.offset,
|
|
30429
|
-
zeroWidthBefore: right.from.zeroWidthBefore ?? 0
|
|
30430
|
-
}, {
|
|
30431
|
-
offset: left.from.offset,
|
|
30432
|
-
zeroWidthBefore: left.from.zeroWidthBefore ?? 0
|
|
30433
|
-
})), ...deleted.value.ops.filter((op) => op.type !== DOCUMENT_OP_TYPES.DELETE_RANGE)];
|
|
30434
|
-
const anchors = new Set(anchorDeletions);
|
|
30435
|
-
const deletionOps = [];
|
|
30436
|
-
const movedNoteBodies = [];
|
|
30437
|
-
let afterDeletion = document;
|
|
30438
|
-
for (const planned of logicalDeletions) {
|
|
30439
|
-
let op = planned;
|
|
30440
|
-
if (planned.type === DOCUMENT_OP_TYPES.DELETE_RANGE && anchors.has(planned)) {
|
|
30441
|
-
const paragraph = paragraphAt(afterDeletion, planned.from);
|
|
30442
|
-
if (paragraph === void 0) panic("A move anchor lost its selected paragraph.");
|
|
30443
|
-
op = {
|
|
30444
|
-
type: DOCUMENT_OP_TYPES.REPLACE_INLINE,
|
|
30445
|
-
story: planned.from.story,
|
|
30446
|
-
blockId: planned.from.blockId,
|
|
30447
|
-
expected: paragraph.content,
|
|
30448
|
-
content: deleteBetween(paragraph.content, {
|
|
30449
|
-
offset: planned.from.offset,
|
|
30450
|
-
zeroWidthBefore: planned.from.zeroWidthBefore ?? 0
|
|
30451
|
-
}, {
|
|
30452
|
-
offset: planned.to.offset,
|
|
30453
|
-
zeroWidthBefore: planned.to.zeroWidthBefore ?? 0
|
|
30454
|
-
}).content
|
|
30455
|
-
};
|
|
30456
|
-
}
|
|
30457
|
-
const applied = applyDocumentOps(afterDeletion, [op]);
|
|
30458
|
-
if (applied.isErr()) return Result.err(applied.error);
|
|
30459
|
-
afterDeletion = applied.value.document;
|
|
30460
|
-
deletionOps.push(op);
|
|
30461
|
-
for (const inverse of applied.value.inverse) if (inverse.type === DOCUMENT_OP_TYPES.RESTORE_STORY_PARTS && (inverse.parts.footnotes !== void 0 || inverse.parts.endnotes !== void 0)) movedNoteBodies.push({
|
|
30462
|
-
type: DOCUMENT_OP_TYPES.RESTORE_STORY_PARTS,
|
|
30463
|
-
expected: {
|
|
30464
|
-
...inverse.expected.footnotes === void 0 ? {} : { footnotes: inverse.expected.footnotes },
|
|
30465
|
-
...inverse.expected.endnotes === void 0 ? {} : { endnotes: inverse.expected.endnotes }
|
|
31288
|
+
const compiled = compileRangeMove(document, {
|
|
31289
|
+
intent,
|
|
31290
|
+
mode,
|
|
31291
|
+
insert: (afterDeletion, target, insertMode) => compileEditorIntent(afterDeletion, {
|
|
31292
|
+
intent: {
|
|
31293
|
+
type: "replaceFragment",
|
|
31294
|
+
from: target,
|
|
31295
|
+
to: target,
|
|
31296
|
+
paragraphs: mode.type === "suggesting" ? intent.paragraphs.map(withoutParagraphMoveAnchors) : intent.paragraphs,
|
|
31297
|
+
openStart: intent.openStart,
|
|
31298
|
+
openEnd: intent.openEnd
|
|
30466
31299
|
},
|
|
30467
|
-
|
|
30468
|
-
|
|
30469
|
-
|
|
30470
|
-
|
|
30471
|
-
|
|
30472
|
-
|
|
30473
|
-
|
|
30474
|
-
|
|
30475
|
-
|
|
30476
|
-
|
|
30477
|
-
|
|
30478
|
-
|
|
30479
|
-
|
|
30480
|
-
let target = intent.target;
|
|
30481
|
-
for (const op of logicalDeletions) {
|
|
30482
|
-
if (op.type === DOCUMENT_OP_TYPES.DELETE_RANGE && op.revision === void 0 && idKey(target.blockId) === idKey(op.from.blockId) && target.story === op.from.story && target.offset >= op.to.offset) {
|
|
30483
|
-
const source = paragraphAt(document, op.from);
|
|
30484
|
-
const deletionFromGap = op.from.zeroWidthBefore ?? zeroWidthLeavesAt(source?.content ?? [], op.from.offset).length;
|
|
30485
|
-
const deletionToGap = op.to.zeroWidthBefore ?? 0;
|
|
30486
|
-
const deletionTargetGap = target.zeroWidthBefore ?? defaultInsertionGap(source?.content ?? [], target.offset).zeroWidthBefore;
|
|
30487
|
-
const rebased = Object.assign({}, target, { offset: target.offset - (op.to.offset - op.from.offset) });
|
|
30488
|
-
if (target.offset === op.to.offset) rebased.zeroWidthBefore = deletionFromGap + deletionTargetGap - deletionToGap;
|
|
30489
|
-
target = rebased;
|
|
30490
|
-
}
|
|
30491
|
-
if (op.type === DOCUMENT_OP_TYPES.JOIN_BLOCKS && op.revision === void 0 && idKey(target.blockId) === idKey(op.blockId) && target.story === op.story) target = Object.assign({}, target, { blockId: op.nextBlockId });
|
|
30492
|
-
else if (op.type === DOCUMENT_OP_TYPES.JOIN_BLOCKS && op.revision === void 0 && idKey(target.blockId) === idKey(op.nextBlockId) && target.story === op.story) {
|
|
30493
|
-
const prefix = paragraphAt(document, {
|
|
30494
|
-
story: op.story,
|
|
30495
|
-
blockId: op.blockId,
|
|
30496
|
-
offset: 0
|
|
30497
|
-
});
|
|
30498
|
-
const remaining = idKey(op.blockId) === idKey(intent.from.blockId) ? intent.from.offset : 0;
|
|
30499
|
-
if (prefix !== void 0) {
|
|
30500
|
-
const rebased = Object.assign({}, target, { offset: target.offset + remaining });
|
|
30501
|
-
if (target.offset === 0 && idKey(op.blockId) === idKey(intent.from.blockId)) rebased.zeroWidthBefore = fromGap + (target.zeroWidthBefore ?? 0);
|
|
30502
|
-
target = rebased;
|
|
30503
|
-
}
|
|
30504
|
-
}
|
|
30505
|
-
}
|
|
30506
|
-
const paragraphs = mode.type === "suggesting" ? intent.paragraphs.map((paragraph) => Object.assign({}, paragraph, { content: asParagraphContent(withoutMoveAnchors(paragraph.content)) })) : intent.paragraphs;
|
|
30507
|
-
const inserted = compileEditorIntent(afterDeletion, {
|
|
30508
|
-
intent: {
|
|
30509
|
-
type: "replaceFragment",
|
|
30510
|
-
from: target,
|
|
30511
|
-
to: target,
|
|
30512
|
-
paragraphs,
|
|
30513
|
-
openStart: intent.openStart,
|
|
30514
|
-
openEnd: intent.openEnd
|
|
30515
|
-
},
|
|
30516
|
-
mode: modeAfterOps(afterDeletion, mode),
|
|
31300
|
+
mode: insertMode,
|
|
31301
|
+
...firstBlockId === void 0 ? {} : { firstBlockId }
|
|
31302
|
+
})
|
|
31303
|
+
});
|
|
31304
|
+
if (compiled.isErr()) return compiled;
|
|
31305
|
+
ops = compiled.value.ops;
|
|
31306
|
+
selection = compiled.value.selection;
|
|
31307
|
+
break;
|
|
31308
|
+
}
|
|
31309
|
+
case "moveBlocks": {
|
|
31310
|
+
const compiled = compileBlockMove(document, {
|
|
31311
|
+
intent,
|
|
31312
|
+
mode,
|
|
30517
31313
|
...firstBlockId === void 0 ? {} : { firstBlockId }
|
|
30518
31314
|
});
|
|
30519
|
-
if (
|
|
30520
|
-
ops =
|
|
30521
|
-
selection =
|
|
31315
|
+
if (compiled.isErr()) return compiled;
|
|
31316
|
+
ops = compiled.value.ops;
|
|
31317
|
+
selection = compiled.value.selection;
|
|
30522
31318
|
break;
|
|
30523
31319
|
}
|
|
30524
31320
|
case "table": {
|
|
@@ -36750,12 +37546,6 @@ const groupInsertionRuns = (operations, insertionPositionOf, keepsGap = () => fa
|
|
|
36750
37546
|
* the document agree on every paragraph, table and note it keeps.
|
|
36751
37547
|
*/
|
|
36752
37548
|
const REVISION_KEY_PREFIX = `${IDENTITY_SPACES.REVISION}:`;
|
|
36753
|
-
/** Every revision id a story's content carries, in document order. */
|
|
36754
|
-
const storyRevisionIds = (document, story) => {
|
|
36755
|
-
const body = findStoryBody$1(document, story);
|
|
36756
|
-
if (body === void 0) return [];
|
|
36757
|
-
return [...new Set(identityKeysIn(body.content).flatMap((key) => key.startsWith(REVISION_KEY_PREFIX) ? [Number(key.slice(REVISION_KEY_PREFIX.length))] : []))];
|
|
36758
|
-
};
|
|
36759
37549
|
const isPlainRecord = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
|
|
36760
37550
|
/**
|
|
36761
37551
|
* `value` with `edit` applied to every plain record, bottom up, copying only
|
|
@@ -36984,26 +37774,54 @@ const withoutParagraphIds = (document, minted) => {
|
|
|
36984
37774
|
package: pkg
|
|
36985
37775
|
};
|
|
36986
37776
|
};
|
|
36987
|
-
|
|
36988
|
-
|
|
36989
|
-
|
|
36990
|
-
|
|
36991
|
-
|
|
36992
|
-
const
|
|
37777
|
+
const readResolvedDocument = ({ document, decision, purpose }) => {
|
|
37778
|
+
const pkg = document.package;
|
|
37779
|
+
const body = pkg.document;
|
|
37780
|
+
const known = purpose === "markup-view" && knownToMeetContract(document);
|
|
37781
|
+
if (purpose === "markup-view" && (decision === REVISION_DECISIONS.ACCEPT || decision === REVISION_DECISIONS.REJECT) && (known || body.sections === void 0) && (body.comments?.length ?? 0) === 0 && (pkg.headers?.size ?? 0) === 0 && (pkg.footnotes?.length ?? 0) === 0 && (pkg.footers?.size ?? 0) === 0 && (pkg.endnotes?.length ?? 0) === 0) {
|
|
37782
|
+
const view = resolveIndependentTextParagraphs(body, decision);
|
|
37783
|
+
if (view !== void 0) return {
|
|
37784
|
+
document: view.body === body ? document : {
|
|
37785
|
+
...document,
|
|
37786
|
+
package: {
|
|
37787
|
+
...pkg,
|
|
37788
|
+
document: view.body
|
|
37789
|
+
}
|
|
37790
|
+
},
|
|
37791
|
+
...view.changes.length > 0 ? { independentInline: view.changes } : {},
|
|
37792
|
+
unresolved: []
|
|
37793
|
+
};
|
|
37794
|
+
}
|
|
37795
|
+
const revisionIdsByContent = /* @__PURE__ */ new Map();
|
|
37796
|
+
const storyRevisionIds = (current, story) => {
|
|
37797
|
+
const content = findStoryBody$1(current, story)?.content;
|
|
37798
|
+
if (content === void 0) return [];
|
|
37799
|
+
const cached = revisionIdsByContent.get(content);
|
|
37800
|
+
if (cached !== void 0) return cached;
|
|
37801
|
+
const ids = /* @__PURE__ */ new Set();
|
|
37802
|
+
for (const key of identityKeysIn(content)) if (key.startsWith(REVISION_KEY_PREFIX)) ids.add(Number(key.slice(REVISION_KEY_PREFIX.length)));
|
|
37803
|
+
const revisionIds = [...ids];
|
|
37804
|
+
revisionIdsByContent.set(content, revisionIds);
|
|
37805
|
+
return revisionIds;
|
|
37806
|
+
};
|
|
36993
37807
|
const stories = documentStories(document);
|
|
36994
37808
|
const revised = stories.filter((story) => storyRevisionIds(document, story).length > 0);
|
|
36995
37809
|
if (revised.length === 0) return {
|
|
36996
37810
|
document,
|
|
36997
37811
|
unresolved: []
|
|
36998
37812
|
};
|
|
36999
|
-
const identified =
|
|
37813
|
+
const identified = known ? {
|
|
37814
|
+
document,
|
|
37815
|
+
minted: /* @__PURE__ */ new Map()
|
|
37816
|
+
} : withParagraphIds(withDistinctRevisionIds(document));
|
|
37000
37817
|
const closed = withClosingParagraphs(identified.document, revised);
|
|
37001
37818
|
let current = closed.document;
|
|
37002
37819
|
const unresolved = [];
|
|
37820
|
+
const applyOps = purpose === "markup-view" ? applyMarkupViewOps : applyDocumentOps;
|
|
37003
37821
|
for (const story of stories) {
|
|
37004
37822
|
const revisionIds = storyRevisionIds(current, story);
|
|
37005
37823
|
if (revisionIds.length === 0) continue;
|
|
37006
|
-
const resolved =
|
|
37824
|
+
const resolved = applyOps(current, [{
|
|
37007
37825
|
type: DOCUMENT_OP_TYPES.RESOLVE_REVISION,
|
|
37008
37826
|
story,
|
|
37009
37827
|
revisionIds,
|
|
@@ -37020,11 +37838,11 @@ const resolvedDocumentView = (document, decision) => {
|
|
|
37020
37838
|
for (const paraId of closed.closing.keys()) minted.set(paraId, void 0);
|
|
37021
37839
|
let resolvedDocument = withoutParagraphIds(withoutBareClosingParagraphs(current, closed.closing), minted);
|
|
37022
37840
|
for (const story of unresolved) {
|
|
37023
|
-
const
|
|
37024
|
-
if (
|
|
37841
|
+
const authored = findStoryBody$1(document, story);
|
|
37842
|
+
if (authored !== void 0) resolvedDocument = replaceStoryBody({
|
|
37025
37843
|
document: resolvedDocument,
|
|
37026
37844
|
story,
|
|
37027
|
-
body
|
|
37845
|
+
body: authored
|
|
37028
37846
|
});
|
|
37029
37847
|
}
|
|
37030
37848
|
return {
|
|
@@ -37032,8 +37850,24 @@ const resolvedDocumentView = (document, decision) => {
|
|
|
37032
37850
|
unresolved
|
|
37033
37851
|
};
|
|
37034
37852
|
};
|
|
37853
|
+
/**
|
|
37854
|
+
* `document` with every revision resolved by `decision`, story by story. A
|
|
37855
|
+
* story the resolution of an earlier one removed (a note whose every
|
|
37856
|
+
* reference went) is not read again.
|
|
37857
|
+
*/
|
|
37858
|
+
const resolvedDocumentView = (document, decision) => readResolvedDocument({
|
|
37859
|
+
document,
|
|
37860
|
+
decision,
|
|
37861
|
+
purpose: "apply"
|
|
37862
|
+
});
|
|
37863
|
+
/** Resolve a markup display, keeping paragraphs before pending table receivers. */
|
|
37864
|
+
const resolvedMarkupDocumentView = (document, decision) => readResolvedDocument({
|
|
37865
|
+
document,
|
|
37866
|
+
decision,
|
|
37867
|
+
purpose: "markup-view"
|
|
37868
|
+
});
|
|
37035
37869
|
// src/ops/documentOps.ts
|
|
37036
37870
|
const storyBody = storyBody$1;
|
|
37037
37871
|
const findStoryBody = findStoryBody$1;
|
|
37038
37872
|
const sameStory = sameStory$2;
|
|
37039
|
-
export { BATCH_ANNOTATION_KINDS, BATCH_REJECTION_REASONS, BATCH_WIRE_OP_TYPES, BatchRejection, DEFAULT_ID_BLOCK_SIZES, DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_SCHEMA_VERSION, DOCUMENT_OP_TYPES, DocumentOpRefusal, DocumentOpsContractError, EMPTY_PROPERTY_SETS, EXCLUSIVE_PARTS, ID_KIND_LIMITS, ID_LEASE_KINDS, ID_LEASE_REFUSAL_REASONS, INHERIT_RUN_PROPS, IdLeaseRefusal, MAX_BATCH_WIRE_BYTES, OBJECT_REPLACEMENT_CHARACTER, OP_STORIES, PARAGRAPH_MARK_FORMATTING_KEYS, PROPERTY_REVIEW_POLICIES, REVISION_DECISIONS, SPLIT_HALVES, TYPED_TEXT_FORMATTING, acceptCopyOriginAncestors, addCopyOriginAncestor, allocateCommentAnchorIds, applyBatch, applyDocumentOp, applyDocumentOpEnvelope, applyDocumentOps, beginTrackedInsertionCompilation, blockControlHolding, captureDocumentOp, captureStoryParts, combineEditEffects, combineEdits, combineRecordedRevisions, commentAnchorSequence, commentDocumentIssue, commentReferenceOffsets, compareBatchOrder, compareGaps, compileEditorIntent, contentRank, createClient, createEditorIntentIdAllocator, createSequencer, defaultInsertionGap, deletionRemovesBlock, documentStories, editorParagraphGroups, editorParagraphGroupsThroughTextBoxes, editorPositionAtPhysicalPosition, finalBreakCarrier, findStoryBody, formatParaId, formattingEquals, freshCommentId, freshLeasedIds, groupInsertionRuns, idKey, idLeaseHolds, idLeaseRemaining, inlineLeafSpans, introducedDocumentIds, introducedIds, inverseMeetingDocument, isBlockBoundary, isCommentAnchorCarrierType, isCommentExhausted, isCopyOriginAncestors, isKeptCut, isKeptCutPiece, isTextOnlyRun, joinPropertyChangeLink, leasedIdCensus, locateParagraphInBlockList, locateParagraphThroughTextBoxes, mapTocBookmarkPosition, mergeRunContent, normalizeForOps, noteDeletionOps, noteUsesCustomMark, orderAddressingBeforeRemoval, orderBatchOperations, orphanRootCommentIds, packageParagraphIds, packageResourcesOpOf, paragraphContentVerdict, paragraphHoldsContent, paragraphHoldsContentOnceAccepted, paragraphIdsIn, paragraphKeptCutsFromChanges, paragraphLength, paragraphLogicalText, paragraphMarkOutcome, paragraphPropertySnapshotToken, paragraphStatesItsFormatting, paragraphVisibleText, paragraphsThroughTextBoxes, parseDocumentBatch, pendingSuggestionIdsIn, physicalOffsetAtVisibleOffset, physicalPositionAtEditorOffset, planTrackedDeletion, planTrackedReplace, planWellFormedRanges, planWholeParagraphReplacement, preservedCommentRangeMarkersAt, reconcileDocumentPartRelationships, recordsCopyOrigin, registerParagraphPropertySnapshot, registerStatedParagraphFormatting, rejectCopyOriginAncestors, replaceStoryBody, resolveSectionChange, resolveSectionChanges, resolvedDocumentView, reviewFieldsOf, revisionIdDemand, revisionSpan, runsMergeable, sameStory, sectionPropertiesAt, sectionRejectProperties, sectionResolutionPatch, shiftCopyOriginAncestors, storyBody, storyLacksClosingParagraph, storyParagraphs, storyPartsOpOf, suggestedCommentIds, suggestionRevisionInfos, survivingComments, textBoxContentsIn, toOpEnvelope, transferParagraphPropertySnapshot, transformBatch, transformPosition, trimIdLease, tryTrackedInsertionGroup, validateDocumentBatch, validateOpsDocument, validateSequencedBatch, withBodyContent, withParagraphCopies, withParagraphRenderings, withTextBoxesClosed, withoutCommentThreads, withoutPendingSuggestions, zeroWidthLeavesAt };
|
|
37873
|
+
export { BATCH_ANNOTATION_KINDS, BATCH_REJECTION_REASONS, BATCH_WIRE_OP_TYPES, BatchRejection, DEFAULT_ID_BLOCK_SIZES, DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_SCHEMA_VERSION, DOCUMENT_OP_TYPES, DocumentOpRefusal, DocumentOpsContractError, EMPTY_PROPERTY_SETS, EXCLUSIVE_PARTS, ID_KIND_LIMITS, ID_LEASE_KINDS, ID_LEASE_REFUSAL_REASONS, INHERIT_RUN_PROPS, IdLeaseRefusal, MAX_BATCH_WIRE_BYTES, OBJECT_REPLACEMENT_CHARACTER, OP_STORIES, PARAGRAPH_MARK_FORMATTING_KEYS, PROPERTY_REVIEW_POLICIES, REVISION_DECISIONS, SPLIT_HALVES, TYPED_TEXT_FORMATTING, acceptCopyOriginAncestors, addCopyOriginAncestor, allocateCommentAnchorIds, applyBatch, applyDocumentOp, applyDocumentOpEnvelope, applyDocumentOps, beginTrackedInsertionCompilation, blockControlHolding, captureDocumentOp, captureStoryParts, combineEditEffects, combineEdits, combineRecordedRevisions, commentAnchorSequence, commentDocumentIssue, commentReferenceOffsets, compareBatchOrder, compareGaps, compileEditorIntent, contentRank, createClient, createEditorIntentIdAllocator, createSequencer, defaultInsertionGap, deletionRemovesBlock, documentStories, editorParagraphGroups, editorParagraphGroupsThroughTextBoxes, editorPositionAtPhysicalPosition, finalBreakCarrier, findStoryBody, formatParaId, formattingEquals, freshCommentId, freshLeasedIds, groupInsertionRuns, idKey, idLeaseHolds, idLeaseRemaining, inlineLeafSpans, introducedDocumentIds, introducedIds, inverseMeetingDocument, isBlockBoundary, isCommentAnchorCarrierType, isCommentExhausted, isCopyOriginAncestors, isKeptCut, isKeptCutPiece, isTextOnlyRun, joinPropertyChangeLink, leasedIdCensus, locateParagraphInBlockList, locateParagraphThroughTextBoxes, mapTocBookmarkPosition, mergeRunContent, normalizeForOps, noteDeletionOps, noteUsesCustomMark, orderAddressingBeforeRemoval, orderBatchOperations, orphanRootCommentIds, packageParagraphIds, packageResourcesOpOf, paragraphContentVerdict, paragraphHoldsContent, paragraphHoldsContentOnceAccepted, paragraphIdsIn, paragraphKeptCutsFromChanges, paragraphLength, paragraphLogicalText, paragraphMarkOutcome, paragraphPropertySnapshotToken, paragraphStatesItsFormatting, paragraphVisibleText, paragraphsThroughTextBoxes, parseDocumentBatch, pendingSuggestionIdsIn, physicalOffsetAtVisibleOffset, physicalPositionAtEditorOffset, planTrackedDeletion, planTrackedReplace, planWellFormedRanges, planWholeParagraphReplacement, preservedCommentRangeMarkersAt, reconcileDocumentPartRelationships, recordsCopyOrigin, registerParagraphPropertySnapshot, registerStatedParagraphFormatting, rejectCopyOriginAncestors, replaceStoryBody, resolveSectionChange, resolveSectionChanges, resolvedDocumentView, resolvedMarkupDocumentView, reviewFieldsOf, revisionIdDemand, revisionSpan, runsMergeable, sameStory, sectionPropertiesAt, sectionRejectProperties, sectionResolutionPatch, shiftCopyOriginAncestors, storyBody, storyLacksClosingParagraph, storyParagraphs, storyPartsOpOf, suggestedCommentIds, suggestionOwnersInStory, suggestionRevisionInfos, survivingComments, textBoxContentsIn, toOpEnvelope, transferParagraphPropertySnapshot, transformBatch, transformPosition, trimIdLease, tryTrackedInsertionGroup, validateDocumentBatch, validateOpsDocument, validateSequencedBatch, withBodyContent, withParagraphCopies, withParagraphRenderings, withTextBoxesClosed, withoutCommentThreads, withoutPendingSuggestions, zeroWidthLeavesAt };
|