@stll/docx-core 0.45.0 → 0.45.1
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/{archive-yBR7X-Qc.js → archive-D5kFLipm.js} +1 -1
- package/dist/{format-DXPXB02u.js → format-DKTCMfac.js} +36 -10
- package/dist/index.js +4 -141
- package/dist/ops/documentOps.d.ts +18 -0
- package/dist/ops/documentOps.js +173 -48
- package/dist/schemaAttributes-e8whSQjO.js +142 -0
- package/dist/zip/archive.js +2 -2
- package/dist/zip/stream.js +1 -1
- package/package.json +1 -1
|
@@ -2752,6 +2752,24 @@ type SequencedOpEffect = {
|
|
|
2752
2752
|
to: Gap;
|
|
2753
2753
|
keptMark?: Gap;
|
|
2754
2754
|
}[];
|
|
2755
|
+
} | {
|
|
2756
|
+
type: "insertBlocks";
|
|
2757
|
+
/**
|
|
2758
|
+
* For an insertion before or after a paragraph: the revisions of the
|
|
2759
|
+
* marks of that paragraph and of the paragraph before it in reading
|
|
2760
|
+
* order (the mark itself, a deletion it holds, and the mark it took
|
|
2761
|
+
* over), and of the table rows and cells holding it. Resolving one
|
|
2762
|
+
* joins or removes a paragraph beside the insertion, or the row or
|
|
2763
|
+
* cell around it, which comes out differently with and without the
|
|
2764
|
+
* inserted paragraphs; a concurrent decision naming none passes a
|
|
2765
|
+
* direct insertion.
|
|
2766
|
+
*
|
|
2767
|
+
* Compatibility: a journal sequenced before this effect recorded
|
|
2768
|
+
* {@link NO_SEQUENCED_EFFECT} for such an insertion, which still reads
|
|
2769
|
+
* and replays; a decision rebased over one is refused, since it names
|
|
2770
|
+
* no bordering revisions.
|
|
2771
|
+
*/
|
|
2772
|
+
borderingRevisionIds: readonly number[];
|
|
2755
2773
|
} | {
|
|
2756
2774
|
type: "touchedBlocks";
|
|
2757
2775
|
/** Paragraphs the operation changed, inserted or removed. */
|
package/dist/ops/documentOps.js
CHANGED
|
@@ -7253,18 +7253,44 @@ const coveredCommentIds = (document) => {
|
|
|
7253
7253
|
}
|
|
7254
7254
|
return covered;
|
|
7255
7255
|
};
|
|
7256
|
+
/** Read coverage once per anchor kind for the requested roots in a document. */
|
|
7257
|
+
const commentExhaustionIn = (document) => {
|
|
7258
|
+
let covered;
|
|
7259
|
+
let anchored;
|
|
7260
|
+
return ({ anchorKind, id, parentId }) => {
|
|
7261
|
+
if (parentId !== void 0) return false;
|
|
7262
|
+
switch (anchorKind) {
|
|
7263
|
+
case "range":
|
|
7264
|
+
covered ??= coveredCommentIds(document);
|
|
7265
|
+
return !covered.has(id);
|
|
7266
|
+
case "point":
|
|
7267
|
+
anchored ??= sourceCommentAnchorIds(document);
|
|
7268
|
+
return !anchored.has(id);
|
|
7269
|
+
default: return false;
|
|
7270
|
+
}
|
|
7271
|
+
};
|
|
7272
|
+
};
|
|
7256
7273
|
/** Whether a known range lost its content or a known point lost its anchor. */
|
|
7257
7274
|
const isCommentExhausted = (input) => {
|
|
7258
7275
|
if (input.type === "coverage") return input.anchorKind === "range" && !input.survivingNonCarrierContent;
|
|
7259
7276
|
const { document, id } = input;
|
|
7260
7277
|
const comment = document.package.document.comments?.find((entry) => entry.id === id);
|
|
7261
|
-
|
|
7262
|
-
|
|
7263
|
-
|
|
7264
|
-
|
|
7265
|
-
|
|
7266
|
-
|
|
7267
|
-
|
|
7278
|
+
return comment !== void 0 && commentExhaustionIn(document)(comment);
|
|
7279
|
+
};
|
|
7280
|
+
/** Root comment threads that still had coverage before an edit consumed it. */
|
|
7281
|
+
const newlyExhaustedCommentIds = (before, after) => {
|
|
7282
|
+
const previous = before.package.document.comments ?? [];
|
|
7283
|
+
if (previous.length === 0) return [];
|
|
7284
|
+
const current = new Map((after.package.document.comments ?? []).map((comment) => [comment.id, comment]));
|
|
7285
|
+
const wasExhausted = commentExhaustionIn(before);
|
|
7286
|
+
const isExhausted = commentExhaustionIn(after);
|
|
7287
|
+
const exhausted = [];
|
|
7288
|
+
for (const source of previous) {
|
|
7289
|
+
if (source.parentId !== void 0) continue;
|
|
7290
|
+
const target = current.get(source.id);
|
|
7291
|
+
if (target !== void 0 && isExhausted(target) && !wasExhausted(source)) exhausted.push(source.id);
|
|
7292
|
+
}
|
|
7293
|
+
return exhausted;
|
|
7268
7294
|
};
|
|
7269
7295
|
/**
|
|
7270
7296
|
* Hyperlinks that held nothing but markers of the threads a retirement
|
|
@@ -9230,15 +9256,7 @@ const paragraphMarkOutcome = ({ follows, holdsContent, markWasAdded, containerSt
|
|
|
9230
9256
|
* that still covered something `before` it.
|
|
9231
9257
|
*/
|
|
9232
9258
|
const withExhaustedCommentsRetired = ({ before, edit, applyOps }) => {
|
|
9233
|
-
const exhaustedCommentIds = (before.
|
|
9234
|
-
type: "document",
|
|
9235
|
-
document: before,
|
|
9236
|
-
id
|
|
9237
|
-
}) && isCommentExhausted({
|
|
9238
|
-
type: "document",
|
|
9239
|
-
document: edit.document,
|
|
9240
|
-
id
|
|
9241
|
-
}) ? [id] : []);
|
|
9259
|
+
const exhaustedCommentIds = newlyExhaustedCommentIds(before, edit.document);
|
|
9242
9260
|
if (exhaustedCommentIds.length === 0) return Result.ok({
|
|
9243
9261
|
edit,
|
|
9244
9262
|
modified: []
|
|
@@ -9303,6 +9321,19 @@ const breakRetiredBefore = (list, index) => {
|
|
|
9303
9321
|
return candidate !== index - 1 && list[candidate]?.type === "paragraph" ? candidate : index - 1;
|
|
9304
9322
|
};
|
|
9305
9323
|
/**
|
|
9324
|
+
* A table pending deletion still blocks a tracked paragraph join, but it
|
|
9325
|
+
* does not supply properties to the closing paragraph. Look past such
|
|
9326
|
+
* tables for the paragraph that supplies them in the accepted document.
|
|
9327
|
+
*/
|
|
9328
|
+
const terminalPropertySource = (list, index) => {
|
|
9329
|
+
let candidate = index;
|
|
9330
|
+
for (;;) {
|
|
9331
|
+
const block = list[candidate];
|
|
9332
|
+
if (block?.type !== "table" || block.rows.length === 0 || !block.rows.every((row) => row.structuralChange?.type === "tableRowDeletion")) return candidate;
|
|
9333
|
+
candidate = breakRetiredBefore(list, candidate);
|
|
9334
|
+
}
|
|
9335
|
+
};
|
|
9336
|
+
/**
|
|
9306
9337
|
* Whether accepting leaves nothing of `blocks`, a container's last blocks:
|
|
9307
9338
|
* paragraphs that keep no content once accepted, each before the last with
|
|
9308
9339
|
* its break pending deletion, and no section break among them.
|
|
@@ -9566,8 +9597,10 @@ const deleteBlocks = ({ document, op, applyOps }) => {
|
|
|
9566
9597
|
...sectionBoundaries
|
|
9567
9598
|
};
|
|
9568
9599
|
const finalReview = reviewFieldsOf(last.paragraph);
|
|
9569
|
-
|
|
9570
|
-
|
|
9600
|
+
const formattingSourceIndex = terminal && op.revision !== void 0 ? terminalPropertySource(list, previousIndex) : previousIndex;
|
|
9601
|
+
const formattingSource = list[formattingSourceIndex];
|
|
9602
|
+
if (terminal && formattingSource?.type === "paragraph" && givesProperties(list, formattingSourceIndex)) {
|
|
9603
|
+
const formatting = withMarkFormatting(paragraphPropertiesOf(formattingSource.formatting), last.paragraph.formatting);
|
|
9571
9604
|
delete finalReview.formatting;
|
|
9572
9605
|
if (formatting !== void 0) finalReview.formatting = formatting;
|
|
9573
9606
|
}
|
|
@@ -17584,7 +17617,11 @@ const resolveList = ({ nodes: listed, resolution, path }) => {
|
|
|
17584
17617
|
});
|
|
17585
17618
|
} else {
|
|
17586
17619
|
const around = floating.has(out.length) ? enclosingRecordCut(node, index) : void 0;
|
|
17587
|
-
const
|
|
17620
|
+
const after = pending.at(index + 1);
|
|
17621
|
+
const before = itemBefore(out, keptStart)?.node;
|
|
17622
|
+
const crossesKeptCut = before !== void 0 && standsInKeptCut(before) || after !== void 0 && standsInKeptCut(after);
|
|
17623
|
+
const carriedJoin = (path.length > 0 && before === void 0 !== (after === void 0) || crossesKeptCut) && joins !== void 0 && joins.remove === 0 && kept.length === 0 && resolution.decision === REVISION_DECISIONS.REJECT && isAddedRevision(node) ? Math.min(recordJoin(joins, "before"), recordJoin(joins, "after")) : 0;
|
|
17624
|
+
const removalCut = Math.max(cutLevelsOnceResolved(node, index), carriedJoin, around?.side === void 0 ? around?.depth ?? 0 : 0);
|
|
17588
17625
|
if (around?.side !== void 0) folds.push(out.length);
|
|
17589
17626
|
recordSourceSeam(out.length, removalCut);
|
|
17590
17627
|
if (removalCut > 0) removalSeams.add(out.length);
|
|
@@ -17595,7 +17632,8 @@ const resolveList = ({ nodes: listed, resolution, path }) => {
|
|
|
17595
17632
|
if (known === void 0 || made < known) removalDates.set(out.length, made);
|
|
17596
17633
|
if (joins !== void 0) removalJoins.set(out.length, {
|
|
17597
17634
|
before: recordJoin(joins, "before"),
|
|
17598
|
-
after: recordJoin(joins, "after")
|
|
17635
|
+
after: recordJoin(joins, "after"),
|
|
17636
|
+
type: carriedJoin > 0 ? "carriedJoin" : "cut"
|
|
17599
17637
|
});
|
|
17600
17638
|
}
|
|
17601
17639
|
const faced = removalCut === 0 ? facedAcross : {
|
|
@@ -18138,7 +18176,8 @@ const resolveList = ({ nodes: listed, resolution, path }) => {
|
|
|
18138
18176
|
const pieceOnly = kept?.piece !== void 0 && (kept.piece === "after" ? right : left) !== void 0;
|
|
18139
18177
|
if (count === 0 || (left === void 0 || right === void 0) && !pieceOnly) continue;
|
|
18140
18178
|
if (kept === void 0 && resolution.decision === REVISION_DECISIONS.ACCEPT && keptJoinSeams.has(recorded) && passesJoinOn(seam, seam - count - 1, depth)) continue;
|
|
18141
|
-
|
|
18179
|
+
const carriedJoinMeetsPiece = removalJoins.get(recorded)?.type === "carriedJoin" && alikeDepth(recordAt(left?.node, "end"), recordAt(right?.node, "start")) > 0;
|
|
18180
|
+
if (kept === void 0 && (left === void 0 || right === void 0 || !sameOwnFields(left.node, right.node) && !carriedJoinMeetsPiece)) continue;
|
|
18142
18181
|
exactSeams.delete(recorded);
|
|
18143
18182
|
exactSeams.set(seam, Math.max(exactSeams.get(seam) ?? 0, depth));
|
|
18144
18183
|
if (floating.has(seam)) continue;
|
|
@@ -18728,7 +18767,7 @@ const deferSplitSeam = ({ left, right, depth }) => {
|
|
|
18728
18767
|
};
|
|
18729
18768
|
/**
|
|
18730
18769
|
* Whether the paragraph stands only for its pending insertions: rejecting
|
|
18731
|
-
* its added mark
|
|
18770
|
+
* its added mark left it in place until its content is resolved.
|
|
18732
18771
|
*/
|
|
18733
18772
|
const standsForInsertions = (paragraph) => paragraph.content.some((node) => node.type === "insertion" && node.resolutionJoins?.holdsParagraph !== void 0);
|
|
18734
18773
|
/**
|
|
@@ -18882,6 +18921,17 @@ const cutGoesOn = ({ mark, depth, onto }) => {
|
|
|
18882
18921
|
const laterAt = splitDateOf(onto);
|
|
18883
18922
|
return madeAt !== void 0 && laterAt !== void 0 && laterAt > madeAt && depth !== void 0 && depth > (onto.resolutionJoin ?? 0);
|
|
18884
18923
|
};
|
|
18924
|
+
/**
|
|
18925
|
+
* An added paragraph that opens a section before trailing range boundaries
|
|
18926
|
+
* can disappear on rejection. The original section break and the trailing
|
|
18927
|
+
* boundaries keep the same placement.
|
|
18928
|
+
*/
|
|
18929
|
+
const opensSectionBeforeTrailingBoundaries = (blocks, index) => {
|
|
18930
|
+
const follower = blockFollower(blocks, index);
|
|
18931
|
+
if (follower.block !== void 0 || follower.standing.length === 0) return false;
|
|
18932
|
+
const before = blocks.findLast((block, at) => at < index && !isBlockBoundary(block));
|
|
18933
|
+
return before?.type === "paragraph" && before.sectionProperties !== void 0;
|
|
18934
|
+
};
|
|
18885
18935
|
const joinOps = (document, { op, story, paraId, revisionId, added, depth, holders }, ends, ranInto = /* @__PURE__ */ new Set(), joinsBefore = /* @__PURE__ */ new Set(), rejoined = /* @__PURE__ */ new Map()) => {
|
|
18886
18936
|
const body = storyBody$1(document, story);
|
|
18887
18937
|
const location = findStoryParagraph(body, paraId);
|
|
@@ -19029,6 +19079,7 @@ const joinOps = (document, { op, story, paraId, revisionId, added, depth, holder
|
|
|
19029
19079
|
}));
|
|
19030
19080
|
const followsBlock = isOpaqueFollower(next);
|
|
19031
19081
|
const containerFinal = endsItsContainer(body, location);
|
|
19082
|
+
const endsBeforeBoundaries = added && next === void 0 && standing.length > 0 && opensSectionBeforeTrailingBoundaries(blocks, location.index);
|
|
19032
19083
|
const tableBoundary = next?.type === "table" ? paragraphTableRunInBoundary(paragraph, next) : void 0;
|
|
19033
19084
|
const tableTarget = tableBoundary?.type === "receiver" ? tableBoundary.target : void 0;
|
|
19034
19085
|
const blockTarget = next !== void 0 && followsBlock ? paragraphBlockRunInTarget(paragraph, next) : void 0;
|
|
@@ -19057,7 +19108,7 @@ const joinOps = (document, { op, story, paraId, revisionId, added, depth, holder
|
|
|
19057
19108
|
follows,
|
|
19058
19109
|
holdsContent: paragraphHoldsContent(chained),
|
|
19059
19110
|
markWasAdded: added,
|
|
19060
|
-
containerStillEndsWithParagraph: follows !== "nothing" ? follows === "table" && blockListEndsInParagraph(blocks) || goesBeforeBlock || lastBlockPastBoundaries(blocks)?.type === "paragraph" : containerFinal && itemBefore(blocks, location.index)?.type === "paragraph" || endsControl && standsAfterBlock,
|
|
19111
|
+
containerStillEndsWithParagraph: follows !== "nothing" ? follows === "table" && blockListEndsInParagraph(blocks) || goesBeforeBlock || lastBlockPastBoundaries(blocks)?.type === "paragraph" : containerFinal && itemBefore(blocks, location.index)?.type === "paragraph" || endsBeforeBoundaries || endsControl && standsAfterBlock,
|
|
19061
19112
|
followingTableCanReceiveRunIn: tableTarget !== void 0,
|
|
19062
19113
|
holdsContentOnceAccepted: paragraphHoldsContentOnceAccepted(chained),
|
|
19063
19114
|
followingBlockCanReceiveRunIn: blockTarget !== void 0,
|
|
@@ -19168,7 +19219,7 @@ const joinOps = (document, { op, story, paraId, revisionId, added, depth, holder
|
|
|
19168
19219
|
expected: reviewFieldsOf(paragraph),
|
|
19169
19220
|
review
|
|
19170
19221
|
}];
|
|
19171
|
-
const leavesHolder = added && op.decision === REVISION_DECISIONS.REJECT && (endsControl && standsAfterBlock || goesBeforeBlock);
|
|
19222
|
+
const leavesHolder = added && op.decision === REVISION_DECISIONS.REJECT && (endsControl && standsAfterBlock || goesBeforeBlock || endsBeforeBoundaries);
|
|
19172
19223
|
const held = leavesHolder ? holdingParagraph(paragraph.content) : void 0;
|
|
19173
19224
|
if (held !== void 0) markOps.push({
|
|
19174
19225
|
type: DOCUMENT_OP_TYPES.REPLACE_INLINE,
|
|
@@ -19234,7 +19285,8 @@ const absorbControlFollower = ({ document, story, paraId, applyOps }) => {
|
|
|
19234
19285
|
* them, as rejecting its mark with them at once does: only while it still
|
|
19235
19286
|
* ends its block content control short of the container's end, with a block
|
|
19236
19287
|
* before it, so the control keeps ending with that block, or still stands
|
|
19237
|
-
* before a block in a list that ends with a paragraph
|
|
19288
|
+
* before a block in a list that ends with a paragraph, or opens a section
|
|
19289
|
+
* before trailing range boundaries.
|
|
19238
19290
|
*/
|
|
19239
19291
|
const removeEmptiedHolder = ({ document, story, paraId, applyOps }) => {
|
|
19240
19292
|
const body = storyBody$1(document, story);
|
|
@@ -19246,7 +19298,7 @@ const removeEmptiedHolder = ({ document, story, paraId, applyOps }) => {
|
|
|
19246
19298
|
const anchor = blocks.find((block, position) => position !== index && block.type === "paragraph");
|
|
19247
19299
|
const endsControl = index > 0 && index === blocks.length - 1 && list.at(-1)?.kind === "blockSdt" && !endsItsContainer(body, location);
|
|
19248
19300
|
const standsBeforeBlock = anchor !== void 0 && isOpaqueFollower(blockFollower(blocks, index).block) && blockListEndsInParagraph(blocks.filter((block) => !isBlockBoundary(block)));
|
|
19249
|
-
if (!endsControl && !standsBeforeBlock) return Result.ok(void 0);
|
|
19301
|
+
if (!endsControl && !standsBeforeBlock && !opensSectionBeforeTrailingBoundaries(blocks, index)) return Result.ok(void 0);
|
|
19250
19302
|
const removed = applyOps(document, [anchor === void 0 ? {
|
|
19251
19303
|
type: DOCUMENT_OP_TYPES.REPLACE_BLOCKS,
|
|
19252
19304
|
story,
|
|
@@ -20139,17 +20191,9 @@ const planSingleRecordResolution = ({ document, op, applyOps }, paragraphs) => {
|
|
|
20139
20191
|
current = restored.value.document;
|
|
20140
20192
|
}
|
|
20141
20193
|
}
|
|
20142
|
-
const exhausted = (document
|
|
20143
|
-
type: "document",
|
|
20144
|
-
document,
|
|
20145
|
-
id
|
|
20146
|
-
}) && isCommentExhausted({
|
|
20147
|
-
type: "document",
|
|
20148
|
-
document: current,
|
|
20149
|
-
id
|
|
20150
|
-
}));
|
|
20194
|
+
const exhausted = newlyExhaustedCommentIds(document, current);
|
|
20151
20195
|
const beforeRetirement = current;
|
|
20152
|
-
for (const
|
|
20196
|
+
for (const id of exhausted) {
|
|
20153
20197
|
const retired = applyOps(current, [{
|
|
20154
20198
|
type: DOCUMENT_OP_TYPES.DELETE_COMMENT,
|
|
20155
20199
|
id,
|
|
@@ -20163,7 +20207,7 @@ const planSingleRecordResolution = ({ document, op, applyOps }, paragraphs) => {
|
|
|
20163
20207
|
before: beforeRetirement,
|
|
20164
20208
|
after: current,
|
|
20165
20209
|
story: op.story,
|
|
20166
|
-
retired: new Set(exhausted
|
|
20210
|
+
retired: new Set(exhausted)
|
|
20167
20211
|
});
|
|
20168
20212
|
if (emptiedLinks.length > 0) {
|
|
20169
20213
|
const removed = applyOps(current, emptiedLinks);
|
|
@@ -28064,6 +28108,11 @@ const planTrackedReplacement = (document, options) => {
|
|
|
28064
28108
|
});
|
|
28065
28109
|
if (inserted.isErr()) return Result.err(inserted.error);
|
|
28066
28110
|
}
|
|
28111
|
+
if (plan.ops.some((op) => op.type === DOCUMENT_OP_TYPES.DELETE_RANGE && op.revision === void 0)) for (const id of newlyExhaustedCommentIds(document, plan.document())) plan.ops.push({
|
|
28112
|
+
type: DOCUMENT_OP_TYPES.DELETE_COMMENT,
|
|
28113
|
+
id,
|
|
28114
|
+
scope: "thread"
|
|
28115
|
+
});
|
|
28067
28116
|
return Result.ok(plan.ops);
|
|
28068
28117
|
};
|
|
28069
28118
|
/** Plan a same-list range deletion followed by tracked replacement insertions. */
|
|
@@ -32859,7 +32908,7 @@ const SEQUENCED_EFFECT_TYPES = Object.freeze({
|
|
|
32859
32908
|
deleteRange: "deleteRange",
|
|
32860
32909
|
setRunProps: "setRunProps",
|
|
32861
32910
|
setParagraphProps: NO_SEQUENCED_EFFECT,
|
|
32862
|
-
insertBlocks:
|
|
32911
|
+
insertBlocks: "insertBlocks",
|
|
32863
32912
|
splitBlock: "splitBlock",
|
|
32864
32913
|
joinBlocks: "joinBlocks",
|
|
32865
32914
|
resolveRevision: "touchedBlocks",
|
|
@@ -32907,7 +32956,7 @@ const SEQUENCED_EFFECT_TYPES = Object.freeze({
|
|
|
32907
32956
|
const sequencedEffectType = (op) => {
|
|
32908
32957
|
if (op.type === DOCUMENT_OP_TYPES.INSERT_BLOCKS) switch (op.at.type) {
|
|
32909
32958
|
case "before":
|
|
32910
|
-
case "after": return
|
|
32959
|
+
case "after": return DOCUMENT_OP_TYPES.INSERT_BLOCKS;
|
|
32911
32960
|
case "beforeTable":
|
|
32912
32961
|
case "afterTable":
|
|
32913
32962
|
case "containerStart": return "touchedBlocks";
|
|
@@ -32917,6 +32966,15 @@ const sequencedEffectType = (op) => {
|
|
|
32917
32966
|
}
|
|
32918
32967
|
return SEQUENCED_EFFECT_TYPES[op.type];
|
|
32919
32968
|
};
|
|
32969
|
+
/**
|
|
32970
|
+
* Whether a sequenced effect of `type` is one `op` may carry: the effect it
|
|
32971
|
+
* records, or the one a journal sequenced before that effect existed
|
|
32972
|
+
* recorded for it.
|
|
32973
|
+
*/
|
|
32974
|
+
const acceptsSequencedEffect = (op, type) => {
|
|
32975
|
+
const recorded = sequencedEffectType(op);
|
|
32976
|
+
return type === recorded || recorded === DOCUMENT_OP_TYPES.INSERT_BLOCKS && type === "none";
|
|
32977
|
+
};
|
|
32920
32978
|
const commonOperationFields = { undefinedFields: optional(array(array(nonemptyString))) };
|
|
32921
32979
|
const position = object({
|
|
32922
32980
|
story: isOpStory,
|
|
@@ -33457,6 +33515,10 @@ const isDocumentBatch = (value) => object({
|
|
|
33457
33515
|
type: literal("joinBlocks"),
|
|
33458
33516
|
firstLength: natural
|
|
33459
33517
|
})(effect);
|
|
33518
|
+
case "insertBlocks": return object({
|
|
33519
|
+
type: literal("insertBlocks"),
|
|
33520
|
+
borderingRevisionIds: array(natural)
|
|
33521
|
+
})(effect);
|
|
33460
33522
|
case "insertContent": return object({
|
|
33461
33523
|
type: literal("insertContent"),
|
|
33462
33524
|
cutIdentified: boolean
|
|
@@ -33546,7 +33608,7 @@ const decodeDocumentBatch = (value) => {
|
|
|
33546
33608
|
if (!natural(value.revision) || !Array.isArray(effects) || effects.length !== value.ops.length || !effects.every((effect, index) => {
|
|
33547
33609
|
if (!isRecord(effect)) return false;
|
|
33548
33610
|
const op = value.ops.at(index);
|
|
33549
|
-
return op !== void 0 && effect["type"]
|
|
33611
|
+
return op !== void 0 && acceptsSequencedEffect(op, effect["type"]);
|
|
33550
33612
|
})) return Result.err(new BatchRejection({
|
|
33551
33613
|
reason: BATCH_REJECTION_REASONS.INVALID_BATCH,
|
|
33552
33614
|
message: "Sequenced effects must match their operation indexes"
|
|
@@ -33978,6 +34040,11 @@ const transformCommentPair = ({ op, over, effect }) => {
|
|
|
33978
34040
|
}
|
|
33979
34041
|
return Result.ok([op]);
|
|
33980
34042
|
};
|
|
34043
|
+
// src/ops/sequencing/heldRevisions.ts
|
|
34044
|
+
/** The tracked changes a piece of content holds, by revision id. */
|
|
34045
|
+
const REVISION_KEY_PREFIX$1 = `${IDENTITY_SPACES.REVISION}:`;
|
|
34046
|
+
/** The ids of the revisions held in `content`, as the revisions part keys them. */
|
|
34047
|
+
const heldRevisionIds = (content) => identityKeysIn(content).flatMap((key) => key.startsWith(REVISION_KEY_PREFIX$1) ? [key.slice(REVISION_KEY_PREFIX$1.length)] : []);
|
|
33981
34048
|
// src/ops/sequencing/inlineTransform.ts
|
|
33982
34049
|
/**
|
|
33983
34050
|
* Sequencing of inline insertions and of inline record splits and joins.
|
|
@@ -34311,11 +34378,6 @@ const transformInlinePair = (pair) => {
|
|
|
34311
34378
|
}
|
|
34312
34379
|
}
|
|
34313
34380
|
};
|
|
34314
|
-
// src/ops/sequencing/heldRevisions.ts
|
|
34315
|
-
/** The tracked changes a piece of content holds, by revision id. */
|
|
34316
|
-
const REVISION_KEY_PREFIX$1 = `${IDENTITY_SPACES.REVISION}:`;
|
|
34317
|
-
/** The ids of the revisions held in `content`, as the revisions part keys them. */
|
|
34318
|
-
const heldRevisionIds = (content) => identityKeysIn(content).flatMap((key) => key.startsWith(REVISION_KEY_PREFIX$1) ? [key.slice(REVISION_KEY_PREFIX$1.length)] : []);
|
|
34319
34381
|
// src/ops/sequencing/restoreTransform.ts
|
|
34320
34382
|
/**
|
|
34321
34383
|
* Paragraph restorations against concurrent edits of the same paragraph.
|
|
@@ -35115,10 +35177,12 @@ const rejoinedOverFormat = ({ op, over, effect }) => {
|
|
|
35115
35177
|
* comment anchor: it decides the same revisions after the edit, unless the
|
|
35116
35178
|
* edit cut a revision record in two and gave its second half a new id, or is
|
|
35117
35179
|
* a tracked edit whose records may continue a decided revision: one order
|
|
35118
|
-
* decides those and the other does not, so the decision is refused.
|
|
35180
|
+
* decides those and the other does not, so the decision is refused. Over a
|
|
35181
|
+
* direct paragraph insertion it passes unless it decides a revision the
|
|
35182
|
+
* insertion's sequenced effect names as bordering it.
|
|
35119
35183
|
* Undefined for every other pair.
|
|
35120
35184
|
*/
|
|
35121
|
-
const decisionOverEdit = (op, over) => {
|
|
35185
|
+
const decisionOverEdit = (op, over, effect) => {
|
|
35122
35186
|
if (op.type !== DOCUMENT_OP_TYPES.RESOLVE_REVISION) return void 0;
|
|
35123
35187
|
switch (over.type) {
|
|
35124
35188
|
case DOCUMENT_OP_TYPES.INSERT_TEXT:
|
|
@@ -35137,6 +35201,13 @@ const decisionOverEdit = (op, over) => {
|
|
|
35137
35201
|
case DOCUMENT_OP_TYPES.CREATE_COMMENT:
|
|
35138
35202
|
if (!isAnchoredComment(over)) return void 0;
|
|
35139
35203
|
break;
|
|
35204
|
+
case DOCUMENT_OP_TYPES.INSERT_BLOCKS:
|
|
35205
|
+
if (over.at.type !== "before" && over.at.type !== "after") return void 0;
|
|
35206
|
+
if (over.revision !== void 0) break;
|
|
35207
|
+
if (effect?.type !== DOCUMENT_OP_TYPES.INSERT_BLOCKS) return refusal(op, over, "A concurrent paragraph insertion records no revisions it borders.");
|
|
35208
|
+
if (op.revisionIds.some((id) => effect.borderingRevisionIds.includes(id))) return refusal(op, over, "A concurrent paragraph insertion borders a paragraph mark this decision resolves.");
|
|
35209
|
+
if (heldRevisionIds(over.blocks).some((id) => op.revisionIds.some((decided) => String(decided) === id))) return refusal(op, over, "A concurrent paragraph insertion holds a copy of a revision this decision resolves.");
|
|
35210
|
+
return Result.ok([op]);
|
|
35140
35211
|
default: return;
|
|
35141
35212
|
}
|
|
35142
35213
|
if ("revision" in over && over.revision !== void 0) return refusal(op, over, "A concurrent tracked edit may continue a revision this decision resolves.");
|
|
@@ -35156,7 +35227,7 @@ const transformRestoredOp = ({ op, over, effect, order }) => {
|
|
|
35156
35227
|
if (story === void 0 || overStory === void 0) return refusal(op, over, "Package resources, numbering and section metadata require an exclusive edit.");
|
|
35157
35228
|
if (!sameStory$1(story, overStory)) return Result.ok([op]);
|
|
35158
35229
|
if (independent(op, over)) return Result.ok([op]);
|
|
35159
|
-
const decided = decisionOverEdit(op, over);
|
|
35230
|
+
const decided = decisionOverEdit(op, over, effect);
|
|
35160
35231
|
if (decided !== void 0) return decided;
|
|
35161
35232
|
if (isAnchoredComment(op)) return moveCommentAnchor({
|
|
35162
35233
|
op,
|
|
@@ -35665,6 +35736,56 @@ const inspectBatch = (document, ops) => batchWith(inspectDocumentOps, document,
|
|
|
35665
35736
|
document: left,
|
|
35666
35737
|
effects
|
|
35667
35738
|
}));
|
|
35739
|
+
/** The revisions a paragraph's mark records: the mark, its deletion, the one it took over. */
|
|
35740
|
+
const markRevisionIds = (paragraph) => {
|
|
35741
|
+
const mark = paragraph?.pPrMark;
|
|
35742
|
+
if (mark === void 0) return [];
|
|
35743
|
+
return [
|
|
35744
|
+
mark.info.id,
|
|
35745
|
+
...mark.deletion === void 0 ? [] : [mark.deletion.info.id],
|
|
35746
|
+
...mark.takenOverMark === void 0 ? [] : [mark.takenOverMark]
|
|
35747
|
+
];
|
|
35748
|
+
};
|
|
35749
|
+
/** The row and cell revisions of the tables on the way down to a paragraph. */
|
|
35750
|
+
const holdingTableRevisionIds = (blocks, location) => {
|
|
35751
|
+
const ids = [];
|
|
35752
|
+
const change = (info) => {
|
|
35753
|
+
if (info !== void 0) ids.push(info.info.id);
|
|
35754
|
+
};
|
|
35755
|
+
let list = blocks;
|
|
35756
|
+
for (const step of location.list) {
|
|
35757
|
+
const block = list.at(step.block);
|
|
35758
|
+
if (step.kind === "tableCell" && block?.type === "table") {
|
|
35759
|
+
const row = block.rows.at(step.row);
|
|
35760
|
+
const cell = row?.cells.at(step.cell);
|
|
35761
|
+
change(row?.structuralChange);
|
|
35762
|
+
change(cell?.structuralChange);
|
|
35763
|
+
list = cell?.content ?? [];
|
|
35764
|
+
} else if (step.kind === "blockSdt" && block?.type === "blockSdt" || step.kind === "blockCustomXml" && block?.type === "blockCustomXml") list = block.content;
|
|
35765
|
+
else return ids;
|
|
35766
|
+
}
|
|
35767
|
+
return ids;
|
|
35768
|
+
};
|
|
35769
|
+
/**
|
|
35770
|
+
* The revisions a direct insertion before or after a paragraph borders: see
|
|
35771
|
+
* the `insertBlocks` sequenced effect. A tracked insertion records them too;
|
|
35772
|
+
* its own revision refuses a concurrent decision first.
|
|
35773
|
+
*/
|
|
35774
|
+
const borderingRevisionIds = (document, op) => {
|
|
35775
|
+
if (op.at.type !== "before" && op.at.type !== "after") return [];
|
|
35776
|
+
const anchorId = idKey(op.at.blockId);
|
|
35777
|
+
const body = storyBody$1(document, op.story);
|
|
35778
|
+
const paragraphs = storyParagraphs(body);
|
|
35779
|
+
const index = paragraphs.findIndex(({ paragraph }) => paragraph.paraId !== void 0 && idKey(paragraph.paraId) === anchorId);
|
|
35780
|
+
const anchor = paragraphs.at(index);
|
|
35781
|
+
if (index < 0 || anchor === void 0) return [];
|
|
35782
|
+
const before = itemBefore(paragraphs, index)?.paragraph;
|
|
35783
|
+
return [.../* @__PURE__ */ new Set([
|
|
35784
|
+
...markRevisionIds(anchor.paragraph),
|
|
35785
|
+
...markRevisionIds(before),
|
|
35786
|
+
...holdingTableRevisionIds(body.content, anchor)
|
|
35787
|
+
])].sort((left, right) => left - right);
|
|
35788
|
+
};
|
|
35668
35789
|
const batchWith = (applyOps, document, ops) => {
|
|
35669
35790
|
let current = document;
|
|
35670
35791
|
const inverses = [];
|
|
@@ -35685,6 +35806,10 @@ const batchWith = (applyOps, document, ops) => {
|
|
|
35685
35806
|
firstLength: paragraphLength(paragraph)
|
|
35686
35807
|
};
|
|
35687
35808
|
}
|
|
35809
|
+
if (op.type === DOCUMENT_OP_TYPES.INSERT_BLOCKS && sequencedEffectType(op) === DOCUMENT_OP_TYPES.INSERT_BLOCKS) effect = {
|
|
35810
|
+
type: DOCUMENT_OP_TYPES.INSERT_BLOCKS,
|
|
35811
|
+
borderingRevisionIds: borderingRevisionIds(current, op)
|
|
35812
|
+
};
|
|
35688
35813
|
const applied = applyOps(current, [op]);
|
|
35689
35814
|
if (applied.isErr()) return Result.err(applied.error);
|
|
35690
35815
|
if (op.type === DOCUMENT_OP_TYPES.INSERT_CONTENT) effect = {
|